/**
 * @name string-strip-html
 * @fileoverview Strip HTML tags from strings. No parser, accepts mixed sources.
 * @version 13.5.3
 * @author Roy Revelt
 * @license MIT
 * {@link https://codsen.com/os/string-strip-html/}
 */

import{isPlainObject as se,hasOwnProp as me}from"codsen-utils";import{trim as oe,without as ce}from"lodash-es";import{decode as ie}from"html-entities";import{rApply as be}from"ranges-apply";import{Ranges as pe}from"ranges-push";import{right as O}from"string-left-right";function ee(t){return/[-_A-Za-z0-9]/.test(t)}function G(t,m){if(!t)return[];if(Array.isArray(t))return t.filter(T=>typeof T=="string"&&T.trim());if(typeof t=="string")return t.trim()?[t]:[];throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_05] ${m} must be array containing zero or more strings or something falsey. Currently it's equal to: ${t}, that a type of ${typeof t}.`)}function j(t,m,T,c){for(let f=m,b=t.length;f<b;f++){if(t.startsWith(T,f))return!0;if(t.startsWith(c,f))return!1}return!1}function Y(t,m,T){let c=!t?.quotes,f=!!t?.quotes?.value&&!j(m,T+1,t.quotes.value,">"),b=t?.quotes?.next!==-1,$=!j(m,t?.quotes?.next-1,t?.quotes?.value,">");return!t?.quotes||!j(m,T+1,t.quotes.value,">")&&t?.quotes?.next!==-1&&j(m,t?.quotes?.next-1,t?.quotes?.value,">")}function ne(t,m){return(m.match(new RegExp(t,"g"))||[]).length}var P=new Set(["!doctype","abbr","address","area","article","aside","audio","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","doctype","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","iframe","img","input","ins","kbd","keygen","label","legend","li","link","main","map","mark","math","menu","menuitem","meta","meter","nav","noscript","object","ol","optgroup","option","output","param","picture","pre","progress","rb","rp","rt","rtc","ruby","samp","script","section","select","slot","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","ul","var","video","wbr","xml"]),x=new Set(["a","b","i","p","q","s","u"]),q=new Set([".",",",";","!","?"]),Q=new Set([".",",","?",";",")","\u2026",'"',"\xBB"]),te=new Set(["a","abbr","acronym","audio","b","bdi","bdo","big","button","canvas","cite","code","data","datalist","del","dfn","em","embed","i","iframe","input","ins","kbd","label","map","mark","meter","noscript","object","output","picture","progress","q","ruby","s","samp","select","slot","small","span","strong","sub","sup","svg","template","textarea","time","u","tt","var","video","wbr"]);var le="13.5.3";var Ne=le,ae={ignoreTags:[],ignoreTagsWithTheirContents:[],onlyStripTags:[],stripTogetherWithTheirContents:["script","style","xml"],skipHtmlDecoding:!1,trimOnlySpaces:!1,stripRecognisedHTMLOnly:!1,dumpLinkHrefsNearby:{enabled:!1,putOnNewLine:!1,wrapHeads:"",wrapTails:""},ignoreIndentations:!1,cb:null,reportProgressFunc:null,reportProgressFuncFrom:0,reportProgressFuncTo:100};function fe(t,m){let T=Date.now(),c=[],f=[],b=[],$=[],n={};function re(){n={attributes:[]}}re();let D=null,w=null,N=null,J=!1,o={},d={tagName:"",hrefValue:"",openingTagEnds:void 0},E="",C=!1,B=null,F=!0;function v(e,s,a){if(Array.isArray(s.stripTogetherWithTheirContents)&&(s.stripTogetherWithTheirContents.includes(n.name)||s.stripTogetherWithTheirContents.includes("*")))if(n.slashPresent&&Array.isArray(c)&&c.some(i=>i.name===n.name)){for(let i=c.length;i--;)if(c[i].name===n.name){$=$.filter(([u,p])=>(u<c[i].lastOpeningBracketAt||u>=e+1)&&(p<=c[i].lastOpeningBracketAt||p>e+1));let g=e+1;n.lastClosingBracketAt&&(g=n.lastClosingBracketAt+1),$.push([c[i].lastOpeningBracketAt,g]),Q.has(t[e])&&s.cb?s.cb({tag:n,deleteFrom:c[i].lastOpeningBracketAt,deleteTo:e+1,insert:null,rangesArr:a,proposedReturn:[c[i].lastOpeningBracketAt,e,null]}):s.cb&&s.cb({tag:n,deleteFrom:c[i].lastOpeningBracketAt,deleteTo:e,insert:"",rangesArr:a,proposedReturn:[c[i].lastOpeningBracketAt,e,""]}),c.splice(i,1);break}}else n.slashPresent||c.push(n);else Array.isArray(s.ignoreTagsWithTheirContents)&&M(e,s,n)&&(F=!1)}function L(e,s,a,i,g,u){if(Array.isArray(r.current())&&typeof a=="number"&&r.current()[0][0]===0&&r.current()[0][1]>=a)return"";if(t.length===i&&u&&!l?.dumpLinkHrefsNearby?.enabled)return null;let p="";if(Number.isInteger(a)&&a<g&&(p+=e.slice(a,g)),Number.isInteger(i)&&i>u+1){let S=e.slice(u+1,i);i&&!O(t,i-1)&&(S=S.trimEnd()),S.includes(`
`)&&y(i,e)?p+=" ":p+=S}let W=!Q.has(e[s]),Z=e[i-1]!==">"||!e[a].trim(),X=!['"',"("].includes(e[g-1]),ge=![";",".",":","!"].includes(e[s]);if((W||Z&&X&&ge)&&(Z||X)&&e[s]!=="!"&&(!te.has(n.name)||typeof a=="number"&&a<g||typeof i=="number"&&i>u+1)){let S=p.match(/\n/g);return Array.isArray(S)&&S.length?S.length===1?`
`:S.length===2?`

`:`


`:" "}return""}function U(e,s){if(e.dumpLinkHrefsNearby?.enabled&&d.tagName&&d.tagName===n.name&&n.lastOpeningBracketAt&&(d.openingTagEnds&&n.lastOpeningBracketAt>d.openingTagEnds||!d.openingTagEnds)&&(C=!0),C){let a=e.dumpLinkHrefsNearby?.putOnNewLine?`

`:"";E=`${a}${d.hrefValue}`,(typeof s!="number"||O(t,s-1))&&(E+=a)}}function y(e,s){return s?s[e]==="<"&&s[e+1]!=="%":t[e]==="<"&&t[e+1]!=="%"}function V(e){return t[e]===">"&&t[e-1]!=="%"}function M(e,s,a){if(s.ignoreTagsWithTheirContents.includes("*"))return!0;let i=t.indexOf(`<${a.name}`,e),g=t.indexOf(`</${a.name}`,e);return!a.slashPresent&&g===-1||a.slashPresent&&!f.some(u=>u.name===a.name)||g>-1&&i>-1&&i<g?!1:s.ignoreTagsWithTheirContents.includes(a.name)}if(typeof t!="string")throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_01] Input must be string! Currently it's: ${(typeof t).toLowerCase()}, equal to:
${JSON.stringify(t,null,4)}`);if(m)if(se(m)){if(m.reportProgressFunc&&typeof m.reportProgressFunc!="function")throw new Error(`string-strip-html/stripHtml(): [THROW_ID_03] The Optional Options Object's key reportProgressFunc, callback function, should be a function but it was given as type ${typeof m.reportProgressFunc}, equal to ${JSON.stringify(m.reportProgressFunc,null,4)}`);if(typeof m.dumpLinkHrefsNearby=="boolean"&&m.dumpLinkHrefsNearby!=null)throw new Error(`string-strip-html/stripHtml(): [THROW_ID_04] The Optional Options Object's key should be a plain object but it was given as type ${typeof m.dumpLinkHrefsNearby}, equal to ${JSON.stringify(m.dumpLinkHrefsNearby,null,4)}`)}else throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_02] Optional Options Object must be a plain object! Currently it's: ${(typeof m).toLowerCase()}, equal to:
${JSON.stringify(m,null,4)}`);function _(){C&&(d={tagName:"",hrefValue:"",openingTagEnds:void 0},C=!1)}let l={...ae,...m,dumpLinkHrefsNearby:Object.assign({},ae.dumpLinkHrefsNearby,m?.dumpLinkHrefsNearby)};if(me(l,"returnRangesOnly"))throw new TypeError("string-strip-html/stripHtml(): [THROW_ID_05] The Optional Options Object's key returnRangesOnly has been removed from the API since v.5 release.");if(l.reportProgressFunc){if(typeof l.reportProgressFuncFrom!="number")throw new Error(`string-strip-html/stripHtml(): [THROW_ID_06] The Optional Options Object's key reportProgressFuncFrom, callback function's "from" range, should be a number but it was given as type ${typeof l.reportProgressFuncFrom}, equal to ${JSON.stringify(l.reportProgressFuncFrom,null,4)}`);if(typeof l.reportProgressFuncTo!="number")throw new Error(`string-strip-html/stripHtml(): [THROW_ID_07] The Optional Options Object's key reportProgressFuncTo, callback function's "to" range, should be a number but it was given as type ${typeof l.reportProgressFuncTo}, equal to ${JSON.stringify(l.reportProgressFuncTo,null,4)}`)}l.ignoreTags=G(l.ignoreTags,"resolvedOpts.ignoreTags"),l.onlyStripTags=G(l.onlyStripTags,"resolvedOpts.onlyStripTags");let z=!!l.onlyStripTags.length;l.onlyStripTags.length&&l.ignoreTags.length&&(l.onlyStripTags=ce(l.onlyStripTags,...l.ignoreTags)),l.stripTogetherWithTheirContents?typeof l.stripTogetherWithTheirContents=="string"&&l.stripTogetherWithTheirContents.length&&(l.stripTogetherWithTheirContents=[l.stripTogetherWithTheirContents]):l.stripTogetherWithTheirContents=[];let I={};if(l.stripTogetherWithTheirContents&&Array.isArray(l.stripTogetherWithTheirContents)&&l.stripTogetherWithTheirContents.length&&!l.stripTogetherWithTheirContents.every((e,s)=>typeof e!="string"?(I.el=e,I.i=s,!1):!0))throw new TypeError(`string-strip-html/stripHtml(): [THROW_ID_08] Optional Options Object's key stripTogetherWithTheirContents was set to contain not just string elements! For example, element at index ${I.i} has a value ${I.el} which is not string but ${(typeof I.el).toLowerCase()}.`);l.cb||(l.cb=({rangesArr:e,proposedReturn:s})=>{s&&e.push(...s)});let r=new pe({limitToBeAddedWhitespace:!0,limitLinebreaksCount:2});if(!l.skipHtmlDecoding)for(;t!==ie(t,{scope:"strict"});)t=ie(t,{scope:"strict"});let R=!1,A=!1,H=0,K=0,h=t.length,ue=Math.floor(h/2);for(let e=0;e<h;e++){if(l.reportProgressFunc&&(h>1e3&&h<2e3?e===ue&&l.reportProgressFunc(Math.floor((l.reportProgressFuncTo-l.reportProgressFuncFrom)/2)):h>=2e3&&(H=l.reportProgressFuncFrom+Math.floor(e/h*(l.reportProgressFuncTo-l.reportProgressFuncFrom)),H!==K&&(K=H,l.reportProgressFunc(H)))),Object.keys(n).length>1&&n.lastClosingBracketAt&&n.lastClosingBracketAt<e&&t[e]!==" "&&B===null&&(B=e),!R&&t[e]==="%"&&t[e-1]==="{"&&t.includes("%}",e+1)){N=null;let s=t.indexOf("%}",e)-1;if(s>e){e=s;continue}}if(!R&&V(e)&&(!n||Object.keys(n).length<2)&&e>1){for(let s=e;s--;)if(t[s-1]===void 0||V(s)){let a=t[s-1]===void 0?s:s+1,i=t.slice(a,e+1)||"";if((i.includes("/>")||i.includes("/ >")||i.includes('="')||i.includes("='"))&&t!==`<${oe(i.trim(),"/>")}>`&&[...P].some(g=>oe(i.trim().split(/\s+/).filter(u=>u.trim()).filter((u,p)=>p===0),"/>").toLowerCase()===g)&&fe(`<${i.trim()}>`,l).result===""){(!b.length||b[b.length-1][0]!==n.lastOpeningBracketAt)&&b.push([a,e+1]),(!$.length||$[$.length-1][0]!==n.lastOpeningBracketAt)&&$.push([a,e+1]);let g=L(t,e,a,e+1,a,e+1),u=e+1;if(t[u]&&!t[u].trim()){for(let p=u;p<h;p++)if(t[p].trim()){u=p;break}}l.cb({tag:n,deleteFrom:a,deleteTo:u,insert:g,rangesArr:r,proposedReturn:[a,u,g]})}break}}if(!A&&t[e]==="/"&&!n.quotes?.value&&Number.isInteger(n.lastOpeningBracketAt)&&!Number.isInteger(n.lastClosingBracketAt)&&(n.slashPresent=e),t[e]==='"'||t[e]==="'")if(!A&&n.nameStarts&&n?.quotes?.value===t[e])if(o.valueStarts===void 0)o={},delete n.quotes;else{o.valueEnds=e,o.value=t.slice(o.valueStarts,e),n.attributes.push(o),o={},delete n.quotes;let s;l.dumpLinkHrefsNearby?.enabled&&!c.length&&n.attributes.some(a=>{if(typeof a.name=="string"&&a.name.toLowerCase()==="href")return s=`${l.dumpLinkHrefsNearby?.wrapHeads||""}${a.value}${l.dumpLinkHrefsNearby?.wrapTails||""}`,!0})&&(d={tagName:n.name,hrefValue:s,openingTagEnds:void 0})}else!A&&!n.quotes&&n.nameStarts&&(n.quotes={},n.quotes.value=t[e],n.quotes.start=e,n.quotes.next=t.indexOf(t[e],e+1),o.nameStarts&&o.nameEnds&&o.nameEnds<e&&o.nameStarts<e&&!o.valueStarts&&(o.name=t.slice(o.nameStarts,o.nameEnds)));if(n.nameStarts!==void 0&&n.nameEnds===void 0&&(!t[e].trim()||!ee(t[e]))){if(n.nameEnds=e,n.name=t.slice(n.nameStarts,n.nameEnds+(!V(e)&&t[e]!=="/"&&t[e+1]===void 0?1:0)),t[n.nameStarts-1]!=="!"&&!n.name.replace(/-/g,"").length||/^\d+$/.test(n.name[0])){n={};continue}if(typeof n.name=="string"&&n.name.toLowerCase()==="doctype"&&(A=!0),y(e)){U(l);let s=L(t,e,n.leftOuterWhitespace,e,n.lastOpeningBracketAt,e);(l.stripTogetherWithTheirContents.includes(n.name)||l.stripTogetherWithTheirContents.includes("*"))&&($=$.filter(([a,i])=>!(a===n.leftOuterWhitespace&&i===e))),l.cb({tag:n,deleteFrom:n.leftOuterWhitespace,deleteTo:e,insert:`${s}${E}${s}`,rangesArr:r,proposedReturn:[n.leftOuterWhitespace,e,`${s}${E}${s}`]}),_(),v(e,l,r)}}if(n.quotes?.start&&n.quotes.start<e&&!n.quotes.end&&o.nameEnds&&o.equalsAt&&!o.valueStarts&&(o.valueStarts=e),!n.quotes&&o.nameEnds&&t[e]==="="&&!o.valueStarts&&!o.equalsAt&&(o.equalsAt=e),!n.quotes&&o.nameStarts&&o.nameEnds&&!o.valueStarts&&t[e].trim()&&t[e]!=="="&&(n.attributes.push(o),o={}),!n.quotes&&o.nameStarts&&!o.nameEnds&&(A&&`'"`.includes(t[o.nameStarts])?o.nameStarts<e&&t[e]===t[o.nameStarts]&&(o.nameEnds=e+1,o.name=t.slice(o.nameStarts,o.nameEnds)):t[e].trim()?t[e]==="="?o.equalsAt||(o.nameEnds=e,o.equalsAt=e,o.name=t.slice(o.nameStarts,o.nameEnds)):t[e]==="/"||V(e)?(o.nameEnds=e,o.name=t.slice(o.nameStarts,o.nameEnds),n.attributes.push(o),o={}):y(e)&&(o.nameEnds=e,o.name=t.slice(o.nameStarts,o.nameEnds),n.attributes.push(o),o={}):(o.nameEnds=e,o.name=t.slice(o.nameStarts,o.nameEnds))),!n.quotes&&n.nameEnds<e&&!t[e-1].trim()&&t[e].trim()&&!"<>/!".includes(t[e])&&!o.nameStarts&&!n.lastClosingBracketAt&&(o.nameStarts=e),n.lastOpeningBracketAt!==null&&n.lastOpeningBracketAt<e&&t[e]==="/"&&n.onlyPlausible&&(n.onlyPlausible=!1),n.lastOpeningBracketAt!==null&&n.lastOpeningBracketAt<e&&t[e]!=="/"&&(n.onlyPlausible===void 0&&((!t[e].trim()||y(e))&&!n.slashPresent?n.onlyPlausible=!0:n.onlyPlausible=!1),t[e].trim()&&n.nameStarts===void 0&&!y(e)&&t[e]!=="/"&&!V(e)&&t[e]!=="!"&&(n.nameStarts=e,n.nameContainsLetters=!1)),n.nameStarts&&!n.quotes&&typeof t[e]=="string"&&t[e].toLowerCase()!==t[e].toUpperCase()&&(n.nameContainsLetters=!0),V(e)&&(Y(n,t,e)||n.quotes.value&&typeof n.lastOpeningBracketAt=="number"&&ne(n.quotes.value,t.slice(n.lastOpeningBracketAt,e))%2===1&&!t.slice(n.lastOpeningBracketAt+1,e).includes("<")&&!t.slice(n.lastOpeningBracketAt+1,e).includes(">"))&&n.lastOpeningBracketAt!==void 0&&(n.lastClosingBracketAt=e,B=null,Object.keys(o).length&&(n.attributes.push(o),o={}),l.dumpLinkHrefsNearby?.enabled&&d.tagName&&!d.openingTagEnds&&(d.openingTagEnds=e)),(!A||t[e]===">")&&n.lastOpeningBracketAt!==void 0){if(n.lastClosingBracketAt===void 0){if(n.lastOpeningBracketAt<e&&!y(e)&&(t[e+1]===void 0||y(e+1)&&!n?.quotes?.value)&&n.nameContainsLetters&&typeof n.nameStarts=="number"){if(n.name=t.slice(n.nameStarts,n.nameEnds||e+1).toLowerCase(),(!b.length||b[b.length-1][0]!==n.lastOpeningBracketAt)&&b.push([n.lastOpeningBracketAt,e+1]),l.ignoreTags.includes(n.name)||M(e,l,n)||!P.has(n.name)&&(n.onlyPlausible||l.stripRecognisedHTMLOnly)){n={},o={};continue}if((P.has(n.name)||x.has(n.name))&&(n.onlyPlausible===!1||n.onlyPlausible===!0&&n.attributes.length)||t[e+1]===void 0){U(l);let s=L(t,e,n.leftOuterWhitespace,e+1,n.lastOpeningBracketAt,n.lastClosingBracketAt);R&&n.name==="script"&&n.slashPresent&&(R=!1);let a;s===null||E===null?a=null:a=`${s}${E}${s}`,l.cb({tag:n,deleteFrom:n.leftOuterWhitespace,deleteTo:e+1,insert:a,rangesArr:r,proposedReturn:[n.leftOuterWhitespace,e+1,a]}),_(),v(e,l,r)}if(!$.length||$[$.length-1][0]!==n.lastOpeningBracketAt&&$[$.length-1][1]!==e+1)if(l.stripTogetherWithTheirContents.includes(n.name)||l.stripTogetherWithTheirContents.includes("*")){let s;for(let a=c.length;a--;)c[a].name===n.name&&(s=c[a]);s?($=$.filter(([a])=>a!==s.lastOpeningBracketAt),$.push([s.lastOpeningBracketAt,e+1])):$.push([n.lastOpeningBracketAt,e+1])}else $.push([n.lastOpeningBracketAt,e+1])}}else if(e>n.lastClosingBracketAt&&t[e].trim()||t[e+1]===void 0||l.ignoreIndentations&&`\r
`.includes(t[e])){let s=n.lastClosingBracketAt===e?e+1:e;l.trimOnlySpaces&&s===h-1&&B!==null&&B<e&&(s=B),(!b.length||b[b.length-1][0]!==n.lastOpeningBracketAt)&&b.push([n.lastOpeningBracketAt,n.lastClosingBracketAt+1]);let a=l.ignoreTags.includes(n.name),i=M(e,l,n);if(!F||l.stripRecognisedHTMLOnly&&typeof n.name=="string"&&!P.has(n.name.toLowerCase())&&!x.has(n.name.toLowerCase())||!z&&(a||i)||z&&!l.onlyStripTags.includes(n.name)||l.ignoreTagsWithTheirContents.includes(n.name)){if(i)if(n.slashPresent){for(let g=f.length;g--;)if(f[g].name===n.name){f.splice(g,1);break}f.length||(F=!0)}else F&&(F=!1),f.push(n);l.cb({tag:n,deleteFrom:null,deleteTo:null,insert:null,rangesArr:r,proposedReturn:null}),n={},o={}}else if(!n.onlyPlausible||n.attributes.length===0&&n.name&&(P.has(n.name.toLowerCase())||x.has(n.name.toLowerCase()))||n.attributes?.some(g=>g.equalsAt)){(!$.length||$[$.length-1][0]!==n.lastOpeningBracketAt)&&$.push([n.lastOpeningBracketAt,n.lastClosingBracketAt+1]);let g=L(t,e,n.leftOuterWhitespace,s,n.lastOpeningBracketAt,n.lastClosingBracketAt);E="",C=!1,U(l,s);let u;typeof E=="string"&&E.length?(u=`${g}${E}${g===`

`?`
`:g}`,s===n.lastClosingBracketAt+1&&(!t[s]||!q.has(t[s]))&&(u+=" "),n.leftOuterWhitespace===n.lastOpeningBracketAt&&r.last()&&r.last()[1]<n.lastOpeningBracketAt&&(!l?.dumpLinkHrefsNearby?.putOnNewLine||!q.has(t[s]))&&(u=" "+u)):u=g,u!==null&&(n.leftOuterWhitespace===0||!O(t,s-1))&&(!l.dumpLinkHrefsNearby?.enabled||n.name!=="a")&&(u=void 0);let p=0;if(C&&q.has(t[s])){l.dumpLinkHrefsNearby?.putOnNewLine&&(u=`${t[s]}${u||""}`);let W=O(t,s);W&&u?.endsWith(`
`)?p+=W-e:(!W||W>e)&&p++}l.cb({tag:n,deleteFrom:n.leftOuterWhitespace,deleteTo:s+p,insert:u,rangesArr:r,proposedReturn:[n.leftOuterWhitespace,s+p,u]}),_(),v(e,l,r)}else n={};V(e)||(n={})}A&&(A=!1)}if((!R||t[e]==="<"&&O(t,O(t,e))&&t[O(t,e)]==="/"&&t.startsWith("script",O(t,O(t,e))))&&y(e)&&!y(e-1)&&!`'"`.includes(t[e+1])&&(!`'"`.includes(t[e+2])||/\w/.test(t[e+1]))&&!(t[e+1]==="c"&&t[e+2]===":")&&!(t[e+1]==="f"&&t[e+2]==="m"&&t[e+3]==="t"&&t[e+4]===":")&&!(t[e+1]==="s"&&t[e+2]==="q"&&t[e+3]==="l"&&t[e+4]===":")&&!(t[e+1]==="x"&&t[e+2]===":")&&!(t[e+1]==="f"&&t[e+2]==="n"&&t[e+3]===":")&&Y(n,t,e)){if(V(O(t,e)))continue;if(n.nameEnds&&n.nameEnds<e&&!n.lastClosingBracketAt&&(n.onlyPlausible===!0&&n.attributes?.length||n.onlyPlausible===!1)){let s=L(t,e,n.leftOuterWhitespace,e,n.lastOpeningBracketAt,e);l.cb({tag:n,deleteFrom:n.leftOuterWhitespace,deleteTo:e,insert:s,rangesArr:r,proposedReturn:[n.leftOuterWhitespace,e,s]}),v(e,l,r),n={},o={}}if(n.lastOpeningBracketAt!==void 0&&n.onlyPlausible&&n.name&&!n.quotes&&(n.lastOpeningBracketAt=void 0,n.name=void 0,n.onlyPlausible=!1),(n.lastOpeningBracketAt===void 0||!n.onlyPlausible)&&!n.quotes&&(n.lastOpeningBracketAt=e,n.slashPresent=!1,n.attributes=[],D===null?n.leftOuterWhitespace=e:l.trimOnlySpaces&&D===0?n.leftOuterWhitespace=w||e:n.leftOuterWhitespace=D,`${t[e+1]}${t[e+2]}${t[e+3]}`=="!--"||`${t[e+1]}${t[e+2]}${t[e+3]}${t[e+4]}${t[e+5]}${t[e+6]}${t[e+7]}${t[e+8]}`=="![CDATA[")){let s=!0;t[e+2]==="-"&&(s=!1);let a;for(let i=e;i<h;i++)if((!a&&s&&`${t[i-2]}${t[i-1]}${t[i]}`=="]]>"||!s&&`${t[i-2]}${t[i-1]}${t[i]}`=="-->")&&(a=i),a&&(a<i&&t[i].trim()||t[i+1]===void 0)){let g=i;(t[i+1]===void 0&&!t[i].trim()||t[i]===">")&&(g+=1),(!b.length||b[b.length-1][0]!==n.lastOpeningBracketAt)&&b.push([n.lastOpeningBracketAt,a+1]),(!$.length||$[$.length-1][0]!==n.lastOpeningBracketAt)&&$.push([n.lastOpeningBracketAt,a+1]);let u=L(t,i,n.leftOuterWhitespace,g,n.lastOpeningBracketAt,a);l.cb({tag:n,deleteFrom:n.leftOuterWhitespace,deleteTo:g,insert:u,rangesArr:r,proposedReturn:[n.leftOuterWhitespace,g,u]}),e=i-1,t[i]===">"&&(e=i),n={},o={};break}}}!t[e].trim()||t[e].charCodeAt(0)===847?(D===null&&(D=e,n.lastOpeningBracketAt!==void 0&&n.lastOpeningBracketAt<e&&n.nameStarts&&n.nameStarts<n.lastOpeningBracketAt&&e===n.lastOpeningBracketAt+1&&!c.some(s=>s.name===n.name)&&(n.onlyPlausible=!0,n.name=void 0,n.nameStarts=void 0)),(t[e]===`
`||t[e]==="\r")&&(N=e,J&&(J=!1))):(D!==null&&(!n.quotes&&o.equalsAt>D-1&&o.nameEnds&&o.equalsAt>o.nameEnds&&t[e]!=='"'&&t[e]!=="'"&&(se(o)&&n.attributes.push(o),o={},n.equalsSpottedAt=void 0),D=null),J||(J=!0,F&&!R&&typeof N=="number"&&e&&N<e-1&&(t.slice(N+1,e).trim()?N=null:l.ignoreIndentations||r.push([N+1,e])))),t[e]===" "?w===null&&(w=e):w!==null&&(w=null),n.name==="script"&&(R=!n.slashPresent)}if(t&&!l.ignoreIndentations&&(l.trimOnlySpaces&&t[0]===" "||!l.trimOnlySpaces&&!t[0].trim()))for(let e=0;e<h;e++)if(l.trimOnlySpaces&&t[e]!==" "||!l.trimOnlySpaces&&t[e].trim()){r.push([0,e]);break}else t[e+1]||r.push([0,e+1]);if(t&&(l.trimOnlySpaces&&t[~-t.length]===" "||!l.trimOnlySpaces&&!t[~-t.length].trim())){for(let e=t.length;e--;)if(l.trimOnlySpaces&&t[e]!==" "||!l.trimOnlySpaces&&t[e].trim()){r.push([e+1,h]);break}}let k=r.current();if(!m?.cb&&k){if(k[0]&&!k[0][0]){let e=k[0][1];r.ranges[0]=[r.ranges[0][0],r.ranges[0][1]]}if(k[k.length-1]?.[1]===t.length){let e=k[k.length-1][0];if(r.ranges){let s=r.ranges[r.ranges.length-1][0];t[s-1]&&(l.trimOnlySpaces&&t[s-1]===" "||!l.trimOnlySpaces&&!t[s-1].trim())&&(s-=1);let a=r.ranges[r.ranges.length-1][2];r.ranges[r.ranges.length-1]=[s,r.ranges[r.ranges.length-1][1]],a?.trim()&&r.ranges[r.ranges.length-1].push(a.trimEnd())}}}return{log:{timeTakenInMilliseconds:Date.now()-T},result:be(t,r.current()),ranges:r.current(),allTagLocations:b,filteredTagLocations:$}}export{ae as defaults,fe as stripHtml,Ne as version};
