@ohos-ports/advanced-mark.js 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ /*!***************************************************
2
+ * advanced-mark.js v3.0.0
3
+ * https://github.com/angezid/advanced-mark.js
4
+ * MIT licensed
5
+ * Copyright (c) 2022–2026, angezid
6
+ * Based on 'mark.js', license https://git.io/vwTVl
7
+ *****************************************************/
8
+ class t{constructor(t,e){this.ctx=t,this.opt=e,this.map=new Map}static matches(t,e){if(!e||!e.length)return!1;const s="string"==typeof e?[e]:e,r=t.matches;return r&&s.some((e=>r.call(t,e)))}getContexts(){let t=this.ctx,e=this.opt.window,s=!1;if(!t)return[];Array.isArray(t)?s=!0:"string"==typeof t?t=e.document.querySelectorAll(t):void 0===t.length&&(t=[t]);const r=[];for(let e=0;e<t.length;e++)r.includes(t[e])||r.some((s=>s.contains(t[e])))||r.push(t[e]);return s&&r.sort(((t,s)=>(t.compareDocumentPosition(s)&e.Node.DOCUMENT_POSITION_FOLLOWING)>0?-1:1)),r}getIframeContents(t,e,s){try{const s=t.contentWindow.document;s&&(this.map.set(t,"ready"),e({iframe:t,context:s}))}catch(e){s({iframe:t,error:e})}}observeIframeLoad(t,e,s){if(this.map.has(t))return;let r=null;const o=()=>{clearTimeout(r),t.removeEventListener("load",o),this.getIframeContents(t,e,s)};t.addEventListener("load",o),this.map.set(t,!0),r=setTimeout(o,this.opt.iframesTimeout)}onIframeReady(t,e,s){const r="about:blank",o=t.getAttribute("src"),n=t.contentWindow;try{"complete"!==n.document.readyState||o&&o.trim()!==r&&n.location.href===r?this.observeIframeLoad(t,e,s):this.getIframeContents(t,e,s)}catch(t){s(t)}}waitForIframes(t,e){const s=this.opt.shadowDOM;let r,o,n=0,i=0;const a=t=>{const e=this.createIterator(t,this.opt.window.NodeFilter.SHOW_ELEMENT);for(;o=e.nextNode();)this.isIframe(o)&&!this.map.has(o)&&(r.push(o),i++),s&&o.shadowRoot&&"open"===o.shadowRoot.mode&&a(o.shadowRoot)},h=t=>{r=[],t.iframe&&"about:blank"===t.context.location.href||(a(t.context),t.iframe||r.length)?r.length?r.forEach((t=>{this.onIframeReady(t,(t=>{n++,h(t)}),(t=>{this.opt.debug&&console.log(t.error||t),++n===i&&e()}))})):n===i&&e():e()};h({context:t})}createIterator(t,e){const s=this.opt.window;return s.document.createNodeIterator(t,e,(()=>s.NodeFilter.FILTER_ACCEPT),!1)}addRemoveStyle(t,e,s){if(s&&!e)return;let r=t.querySelector("style[data-markjs]");s?(r||(r=this.opt.window.document.createElement("style"),r.setAttribute("data-markjs","true"),t.appendChild(r)),r.textContent=e):r&&t.removeChild(r)}isIframe(e){return"IFRAME"===e.tagName&&!t.matches(e,this.opt.exclude)}iterateThroughNodes(t,e,s,r,o){const n=this.opt.window.NodeFilter,i=this.opt.shadowDOM,a=this.opt.iframes;if(a||i){const o=(e&n.SHOW_ELEMENT)>0,h=(e&n.SHOW_TEXT)>0,c=t=>{let l,d=this.createIterator(t,e|n.SHOW_ELEMENT);for(;t=d.nextNode();)if(1===t.nodeType){if(o&&s(t)&&r(t),a&&this.isIframe(t)&&"ready"===this.map.get(t)){const e=t.contentWindow.document;e&&(this.opt.highlight&&h&&t.contentWindow.CSS.highlights.set(this.opt.highlightName,this.opt.highlight),this.addRemoveStyle(e.head,a.style,h),c(e))}i&&(l=t.shadowRoot)&&"open"===l.mode&&(this.addRemoveStyle(l,i.style,h),c(l))}else h&&3===t.nodeType&&s(t)&&r(t)};c(t)}else{const o=this.createIterator(t,e);let n;for(;n=o.nextNode();)s(n)&&r(n)}o()}forEachNode(t,e,s,r=(()=>{})){const o=this.getContexts();let n=o.length;n||r();const i=()=>{o.forEach((o=>{this.iterateThroughNodes(o,t,s,e,(()=>{--n<=0&&r()}))}))};if(this.opt.iframes){let t=n;o.forEach((e=>{this.waitForIframes(e,(()=>{--t<=0&&i()}))}))}else i()}}class e{constructor(t){this.opt=Object.assign({},{diacritics:!0,synonyms:{},accuracy:"partially",caseSensitive:!1,ignoreJoiners:!1,ignorePunctuation:[],wildcards:"disabled"},t)}get chars(){return this._chars||(this._chars=[],["aàáảãạăằắẳẵặâầấẩẫậäåāą","cçćč","dđď","eèéẻẽẹêềếểễệëěēę","iìíỉĩịîïī","lł","nñňń","oòóỏõọôồốổỗộơởỡớờợöøōő","rř","sšśșş","tťțţ","uùúủũụưừứửữựûüůūű","yýỳỷỹỵÿ","zžżź"].forEach((t=>{this._chars.push(t,t.toUpperCase())}))),this._chars}create(t){const e="g"+(this.opt.caseSensitive?"":"i");t=t.map((t=>"("+this.createPattern(t,e)+")"));const s=this.createAccuracy(t.join("|"));return new RegExp(`${s.lookbehind}(${s.pattern})${s.lookahead}`,e)}createPattern(t,e){t=this.checkWildcardsEscape(t),t=this.createSynonyms(t,e);const s=this.getJoinersPunctuation();return s&&(t=this.setupIgnoreJoiners(t)),this.opt.diacritics&&(t=this.createDiacritics(t)),t=t.replace(/\s+/g,"[\\s]+"),s&&(t=this.createJoiners(t,s)),"disabled"!==this.opt.wildcards&&(t=this.createWildcards(t)),t}escape(t){return t.replace(/[[\]/{}()*+?.\\^$|]/g,"\\$&")}preprocess(t){return t&&t.length?this.distinct("string"==typeof t?t.split(""):t).join("").replace(/[-^\]\\]/g,"\\$&"):""}distinct(t){const e=[];return t.forEach((t=>{t.trim()&&!e.includes(t)&&e.push(t)})),e}createSynonyms(t,e){const s=this.opt.synonyms;for(const r in s)if(s.hasOwnProperty(r)){let o=Array.isArray(s[r])?s[r]:[s[r]];if(o.unshift(r),o=this.distinct(o),o.length>1){o.sort(((t,e)=>e.length-t.length)),o=o.map((t=>this.checkWildcardsEscape(t)));const s=o.map((t=>this.escape(t))).join("|");t=t.replace(new RegExp(s,e),`(?:${o.join("|")})`)}}return t}checkWildcardsEscape(t){return"disabled"!==this.opt.wildcards&&(t=t.replace(/(\\.)+|[?*]/g,((t,e)=>e?t:"?"===t?"":"")).replace(/\\(?=[?*\x01\x02])/g,"")),this.escape(t)}createWildcards(t){const e="withSpaces"===this.opt.wildcards,s=this.opt.blockElementsBoundary,r=`[^${e&&s?"":""}]*?`;return t.replace(/\x01/g,e?"[^]?":"\\S?").replace(/\x02/g,e?r:"\\S*")}setupIgnoreJoiners(t){return t.replace(/((?:\\\\)+|\x02|\(\?:|\|)|\\?(?:[\uD800-\uDBFF][\uDC00-\uDFFF]|.)(?=([|)\x02]|$)|.)/g,((t,e,s)=>e||void 0!==s?t:t+"\0"))}createJoiners(t,e){return t.split(/\x00+/).join(`[${e}]*`)}getJoinersPunctuation(){let t=this.preprocess(this.opt.ignorePunctuation),e=t||"";return this.opt.ignoreJoiners&&(e+="\\u00ad\\u200b\\u200c\\u200d"),e}createDiacritics(t){const e=this.chars;return t.split("").map((t=>{for(let s=0;s<e.length;s+=2){const r=e[s].includes(t);if(this.opt.caseSensitive){if(r)return"["+e[s]+"]";if(e[s+1].includes(t))return"["+e[s+1]+"]"}else if(r||e[s+1].includes(t))return"["+e[s]+e[s+1]+"]"}return t})).join("")}createAccuracy(t){let e,s=this.opt.accuracy,r="()",o=t,n="";if("partially"!==s)if("string"!=typeof s&&(e=this.preprocess(s.limiters),s=s.value),"exactly"===s){const t=e?"[\\s"+e+"]":"\\s";r=`(^|${t})`,n=`(?=$|${t})`}else{const n=e||"!-/:-@[-`{-~¡¿",i=`[^\\s${n}]*`;o=`(?:${t})`,"complementary"===s?o=i+o+i:"startsWith"===s&&(r=`(^|[\\s${n}])`,o=o.split(/\[\\s\]\+/).join(i+"[\\s]+")+i)}return{lookbehind:r,pattern:o,lookahead:n}}}class s{constructor(t){this.ctx=t,this.nodeNames=["script","style","title","head","html"]}set opt(t){if(!(t&&t.window&&t.window.document)&&"undefined"==typeof window)throw new Error("Mark.js: please provide a window object as an option.");const e=t&&t.window||window,s=t&&t.highlight&&t.highlight instanceof Highlight;this._opt=Object.assign({},{window:e,element:"",className:"",exclude:[],iframes:!1,iframesTimeout:5e3,separateWordSearch:!0,staticRanges:!0,rangeAcrossElements:!0,acrossElements:!1,ignoreGroups:0,each:()=>{},noMatch:()=>{},filter:()=>!0,done:()=>{},debug:!1,log:e.console},t),this._opt.element||(this._opt.element="mark"),this.filter=e.NodeFilter,this.empty=e.document.createTextNode(""),this._opt.highlightName||(this._opt.highlightName="advanced-markjs"),s?this.rangeArray=[]:this._opt.highlight=null}get opt(){return this._opt}get iterator(){return new t(this.ctx,this.opt)}log(t,e="debug"){if(this.opt.debug){const s=this.opt.log;"object"==typeof s&&"function"==typeof s[e]&&s[e](`mark.js: ${t}`)}}report(t){t.forEach((t=>{this.log(`${t.text} ${JSON.stringify(t.obj)}`,t.level||"debug"),t.skip||this.opt.noMatch(t.obj)}))}getSeachTerms(t){const e="string"==typeof t?[t]:t,s=this.opt.separateWordSearch,r=[],o={},n=t=>{t.split(/ +/).forEach((t=>i(t)))},i=t=>{t.trim()&&!r.includes(t)&&(r.push(t),o[t]=0)};return e.forEach((t=>{s?"preserveTerms"===s?t.split(/"("*[^"]+"*)"/).forEach(((t,e)=>{e%2>0?i(t):n(t)})):n(t):i(t)})),r.sort(((t,e)=>e.length-t.length)),{terms:r,termStats:o}}isNumeric(t){return Number(parseFloat(t))==t}checkRanges(t,e,s,r){const o="error",n=t.filter((t=>!!(this.isNumeric(t.start)&&this.isNumeric(t.length)&&(t.start=parseInt(t.start),t.length=parseInt(t.length),t.start>=s&&t.start<r&&t.length>0))||(e.push({text:"Invalid range: ",obj:t,level:o}),!1))).sort(((t,e)=>t.start-e.start));if(this.opt.wrapAllRanges)return n;let i,a=0;return n.filter((t=>(i=t.start+t.length,t.start>=a?(a=i,!0):(e.push({text:(i<a?"Nest":"Overlapp")+"ing range: ",obj:t,level:o}),!1))))}setType(t,e){const s=Array.isArray(e.tagNames)&&e.tagNames.length;if(s&&e.tagNames.forEach((e=>t[e.toLowerCase()]=2)),!s||e.extend)for(const e in t)t[e]=2;t.br=3}getTextNodesAcross(t){const e={div:1,p:1,li:1,td:1,tr:1,th:1,ul:1,ol:1,dd:1,dl:1,dt:1,h1:1,h2:1,h3:1,h4:1,h5:1,h6:1,hr:1,blockquote:1,figcaption:1,figure:1,pre:1,table:1,thead:1,tbody:1,tfoot:1,input:1,img:1,nav:1,details:1,label:1,form:1,select:1,menu:1,br:3,menuitem:1,main:1,section:1,article:1,aside:1,picture:1,output:1,button:1,header:1,footer:1,address:1,area:1,canvas:1,map:1,fieldset:1,textarea:1,track:1,video:1,audio:1,body:1,iframe:1,meter:1,object:1,svg:1},s=[],r=this.opt.blockElementsBoundary,o=r?2:1;let n,i,a,h="";r&&(this.setType(e,r),r.char&&(h=r.char.charAt(0)));const c={text:"",regex:/\s/,tags:e,boundary:r,str:"",ch:h};this.iterator.forEachNode(this.filter.SHOW_ELEMENT|this.filter.SHOW_TEXT,(t=>{a&&s.push(this.getNodeInfo(a,t,i,c)),i=null,a=t}),(t=>1===t.nodeType?(n=e[t.nodeName.toLowerCase()],3===n&&(c.str+="\n"),i&&n!==o||(i=n),!1):!this.excluded(t.parentNode)),(()=>{a&&s.push(this.getNodeInfo(a,null,i,c)),t({text:c.text,nodes:s,lastIndex:0})}))}getNodeInfo(t,e,s,r){const o=r.text.length,n=r.ch;let i=0,a=r.str,h=t.textContent;if(e){const o=r.regex.test(e.textContent[0]),i=o&&r.regex.test(h[h.length-1]);if(r.boundary||!i){let h=s;if(!s){let o=t.parentNode;for(;o;){if(s=r.tags[o.nodeName.toLowerCase()]){h=!(o===e.parentNode||o.contains(e));break}o=o.parentNode}}h&&(i?2===s&&(a+=i?n:o?" "+n:n+" "):a+=1===s?" ":2===s?" "+n+" ":"")}}return a&&(h+=a,i=a.length,r.str=""),r.text+=h,this.createInfo(t,o,r.text.length-i,i)}getRangesTextNodes(t,e){const s=[],r=/\n/g,o=[0],n=this.filter.SHOW_TEXT|(e?this.filter.SHOW_ELEMENT:0);let i,a="",h=0;this.iterator.forEachNode(n,(t=>{if(e)for(;null!==(i=r.exec(t.textContent));)o.push(h+i.index);a+=t.textContent,s.push({start:h,end:h=a.length,offset:0,node:t})}),(t=>e&&1===t.nodeType?("br"===t.tagName.toLowerCase()&&o.push(h),!1):!this.excluded(t.parentNode)),(()=>{const r={text:a,nodes:s,lastIndex:0};e&&(o.push(h),r.newLines=o),t(r)}))}getTextNodes(t){const e=[];let s=0;this.iterator.forEachNode(this.filter.SHOW_TEXT,(t=>{e.push({node:t,start:s}),s+=t.textContent.length}),(t=>!this.excluded(t.parentNode)),(()=>{t({nodes:e,lastIndex:0})}))}excluded(e){return this.nodeNames.includes(e.nodeName.toLowerCase())||t.matches(e,this.opt.exclude)}wrapRangeInsert(t,e,s,r,o,n){const i=r===e.node.textContent.length,a=e.end;let h=1,c=r,l=e.node;0!==s?(l=l.splitText(s),c=r-s,h=i?2:3):i&&(h=0);const d=i?this.empty:l.splitText(c),p=this.createElement(l),g=p.childNodes[0],u=this.createInfo(d,0===h||2===h?a:e.start+r,a,e.offset);if(0===h)return e.node=g,{mark:p,nodeInfo:u,increment:0};const f=this.createInfo(g,1===h?e.start:o,e.start+r,0);return 1===h?t.nodes.splice(n,1,f,u):(2===h?t.nodes.splice(n+1,0,f):t.nodes.splice(n+1,0,f,u),e.end=o,e.offset=0),{mark:p,nodeInfo:u,increment:h<3?1:2}}createInfo(t,e,s,r){return{node:t,start:e,end:s,offset:r}}wrapRange(t,e,s,r){let o,n=t.node;if(this.rangeArray)this.createRange(n,e,n,s,t.start+e,r),o=n;else{let t=s===n.textContent.length,i=s;0!==e&&(n=n.splitText(e),i=s-e),o=t?this.empty:n.splitText(i),r(this.createElement(n))}return o}createRange(t,e,s,r,o,n){let i;this.opt.staticRanges?i=new StaticRange({startContainer:t,startOffset:e,endContainer:s,endOffset:r}):(i=new Range,i.setStart(t,e),i.setEnd(s,r)),i.absoluteOffset=o,n(i,!0),i&&this.rangeArray.push(i)}createElement(t){let e=this.opt.window.document.createElement(this.opt.element);return e.setAttribute("data-markjs","true"),this.opt.className&&e.setAttribute("class",this.opt.className),e.textContent=t.textContent,t.parentNode.replaceChild(e,t),e}wrapRangeAcross(t,e,s,r,o){let n,i,a=t.lastIndex,h=!0,c=[];const l=this.opt.wrapAllRanges,d=!!this.opt.highlight,p=d&&this.opt.rangeAcrossElements;if(l)for(;a>0&&t.nodes[a].start>e;)a--;for(;a<t.nodes.length;a++)if(a+1===t.nodes.length||t.nodes[a+1].start>e){let g=t.nodes[a];if(p)c.push(g.node);else if(!r(g.node))break;const u=e-g.start;if(i=(s>g.end?g.end:s)-g.start,u>=0&&i>u){if(p)h&&(n=[g.node,u,g.start+u]);else if(!d&&l){const s=this.wrapRangeInsert(t,g,u,i,e,a);g=s.nodeInfo,o(s.mark,h)}else g.node=this.wrapRange(g,u,i,(t=>{o(t,h)})),d||(g.start+=i);h=!1}if(!(s>g.end)){n&&r(c)&&this.createRange(n[0],n[1],g.node,i,n[2],o);break}e=g.end+g.offset}t.lastIndex=a}wrapGroups(t,e,s,r,o){let n,i,a=0,h=0,c=0,l=this.opt.highlight,d=!1,p=0;for(;++c<e.length;)n=e[c],n&&(i=e.indices[c][0],i>=a&&(p=e.indices[c][1],r(t.node,n,c)&&(t.node=this.wrapRange(t,i-h,p-h,(t=>{o(t)})),p>a&&(a=p),l||(h=p),d=!0)));d?l||(s.lastIndex=0):0===e[0].length&&this.setLastIndex(s,p)}wrapGroupsAcross(t,e,s,r,o){let n,i,a,h=0,c=0,l=0;for(;++c<e.length;)i=e[c],i&&(n=e.indices[c][0],(this.opt.wrapAllRanges||n>=h)&&(l=e.indices[c][1],a=!1,this.wrapRangeAcross(t,n,l,(t=>r(t,i,c)),((t,e)=>{a=!0,o(t,e)})),a&&l>h&&(h=l)));0===e[0].length&&this.setLastIndex(s,l)}setLastIndex(t,e){const s=t.lastIndex;t.lastIndex=e>s?e:e>0?s+1:1/0}processGroups(t,e,s,r,o,n){let i,a,h,c=s.count;this.getTextNodes((e=>{e.nodes.every((e=>{for(;null!==(i=t.exec(e.node.textContent))&&(s.match=i,a=h=!0,this.wrapGroups(e,i,t,((t,e,o)=>(s.matchStart=a,s.groupIndex=o,a=!1,r(t,e,s))),(t=>{h&&c++,s.count=c,s.matchStart=h,h=!1,o(t,s)})),!s.abort););return!s.abort})),n(c)}))}processGroupsAcross(t,e,s,r,o,n){let i,a,h,c=s.count;this.getTextNodesAcross((e=>{for(;null!==(i=t.exec(e.text))&&(s.match=i,a=h=!0,this.wrapGroupsAcross(e,i,t,((t,e,o)=>(s.groupStart=void 0,s.matchStart=a,s.groupIndex=o,a=!1,r(t,e,s))),((t,e)=>{h&&c++,s.count=c,s.matchStart=h,s.groupStart=e,o(t,s),h=!1})),!s.abort););n(c)}))}processMatches(t,e,s,r,o,n){const i=0===e?0:e+1;let a,h,c=s.count;this.getTextNodes((e=>{e.nodes.every((e=>{for(;null!==(a=t.exec(e.node.textContent));){if(""===(h=a[i])){t.lastIndex++;continue}if(s.match=a,!r(e.node,h,s))continue;let n=0,l=a.index;for(;++n<i;)a[n]&&(l+=a[n].length);if(e.node=this.wrapRange(e,l,l+h.length,(t=>{s.count=++c,o(t,s)})),this.opt.highlight||(t.lastIndex=0),s.abort)break}return!s.abort})),n(c)}))}processMatchesAcross(t,e,s,r,o,n){const i=0===e?0:e+1;let a,h,c,l=s.count;this.getTextNodesAcross((e=>{for(;null!==(a=t.exec(e.text));){if(""===(h=a[i])){t.lastIndex++;continue}s.match=a,c=!0;let n=0,d=a.index;for(;++n<i;)a[n]&&(d+=a[n].length);if(this.wrapRangeAcross(e,d,d+h.length,(t=>(s.matchStart=c,c=!1,r(t,h,s))),((t,e)=>{e&&l++,s.count=l,s.matchStart=e,o(t,s)})),s.abort)break}n(l)}))}processRanges(t,e,s,r){const o=this.opt.markLines,n=[],i=[],a="warn";let h=0;this.getRangesTextNodes((c=>{const l=o?c.newLines.length:c.text.length,d=this.checkRanges(t,n,o?1:0,l);d.forEach(((t,r)=>{let d=t.start,p=d+t.length;p>l&&(n.push({text:`Range was limited to: ${l}`,obj:t,skip:!0,level:a}),p=l),o&&(d=c.newLines[d-1],"\n"===c.text[d]&&d++,p=c.newLines[p-1]);const g=c.text.slice(d,p);g.trim()?this.wrapRangeAcross(c,d,p,(s=>e(s,t,g,r)),((e,r)=>{r&&h++,s(e,t,{matchStart:r,count:h})})):(n.push({text:"Skipping whitespace only range: ",obj:t,level:a}),i.push(t))})),this.log(`Valid ranges: ${JSON.stringify(d.filter((t=>!i.includes(t))))}`),r(h,n)}),o)}unwrapMatches(t){const e=t.parentNode,s=t.firstChild;if(1===t.childNodes.length)if(3===s.nodeType){const r=t.previousSibling,o=t.nextSibling;if(r&&3===r.nodeType)o&&3===o.nodeType?(r.nodeValue+=s.nodeValue+o.nodeValue,e.removeChild(o)):r.nodeValue+=s.nodeValue;else{if(!o||3!==o.nodeType)return void e.replaceChild(t.firstChild,t);o.nodeValue=s.nodeValue+o.nodeValue}e.removeChild(t)}else e.replaceChild(t.firstChild,t);else{if(s){let s=this.opt.window.document.createDocumentFragment();for(;t.firstChild;)s.appendChild(t.removeChild(t.firstChild));e.replaceChild(s,t)}else e.removeChild(t);e.normalize()}}markRegExp(t,e){this.opt=e;let s=0,r=0,o=this.opt.acrossElements,n="processMatches";if(this.opt.separateGroups){if(!t.hasIndices)throw new Error("Mark.js: RegExp must have a `d` flag");n=o?"processGroupsAcross":"processGroups"}else o&&(n="processMatchesAcross");if(!t.global&&!t.sticky){let e=t.toString().split("/");t=new RegExp(t.source,"g"+e[e.length-1]),this.log("RegExp is recompiled - it must have a `g` flag","warn")}this.log(`RegExp "${t}"`),this[n](t,this.opt.ignoreGroups,{count:0,abort:!1},((t,e,s)=>this.opt.filter(t,e,r,s)),((t,e)=>{r=e.count,s++,this.opt.each(t,e)}),(e=>{0===e&&this.opt.noMatch(t),this.registerHighlight(),this.opt.done(s,e)}))}mark(t,e){this.opt=e;const{terms:s,termStats:r}=this.getSeachTerms(t);if(!s.length)return void this.opt.done(0,0,r);let o,n=0,i=0,a=0;const h=this.opt.acrossElements,c=h?"processMatchesAcross":"processMatches",l=this.getRegExps(s),d={count:0,abort:!1},p=({regex:t,regTerms:e})=>{this.log(`RegExp ${t}`),this[c](t,1,d,((t,s,n)=>(h&&!n.matchStart||(o=this.getCurrentTerm(n.match,e)),this.opt.filter(t,o,a,r[o],n))),((t,e)=>{i++,a=e.count,h&&!e.matchStart||(r[o]+=1),this.opt.each(t,e)}),(t=>{const s=e.filter((t=>0===r[t]));s.length&&this.opt.noMatch(s),!d.abort&&++n<l.length?p(l[n]):(this.registerHighlight(),this.opt.done(i,t,r))}))};p(l[0])}getCurrentTerm(t,e){let s=t.length;for(;--s>2;)if(t[s])return e[s-3];return" "}getRegExps(t){const s=new e(this.opt),r=this.opt.combineBy||this.opt.combinePatterns,o=t.length,n=[];let i,a=100;r===1/0?a=o:!isNaN(+r)&&(i=parseInt(r))>0&&(a=i);for(let e=0;e<o;e+=a){const r=t.slice(e,Math.min(e+a,o));n.push({regex:s.create(r),regTerms:r})}return n}markRanges(t,e){if(this.opt=e,Array.isArray(t)){let e=0;this.processRanges(t,((t,e,s,r)=>this.opt.filter(t,e,s,r)),((t,s,r)=>{e++,this.opt.each(t,s,r)}),((t,s)=>{this.report(s),this.registerHighlight(),this.opt.done(e,t)}))}else this.report([{text:"markRanges() accept an array of objects: ",obj:t,level:"error"}]),this.opt.done(0,0)}unmark(e){this.opt=e;const s=CSS.highlights,r=this.opt.exclude&&this.opt.exclude.length;if(s){let t,e=this.opt.highlightName;"string"==typeof e&&(e=[e]),e.forEach((e=>{(t=s.get(e))&&t.size&&(s.delete(e),r?t.forEach((e=>{let s=e.startContainer;3===s.nodeType&&(s=s.parentNode),this.excluded(s)||t.delete(e)})):t.clear(),t.size&&s.set(e,t))}))}if(this.opt.highlight)return void this.opt.done();let o=this.opt.element+"[data-markjs]";this.opt.className&&(o+=`.${this.opt.className}`),this.log(`Removal selector "${o}"`),this.iterator.forEachNode(this.filter.SHOW_ELEMENT,(t=>{this.unwrapMatches(t)}),(e=>t.matches(e,o)&&!(r&&this.excluded(e))),this.opt.done)}registerHighlight(){const t=this.opt.highlight;if(t){const e=this.opt.highlightName,s=CSS.highlights;this.rangeArray.length&&(s.delete(e),t.size&&(t.forEach((t=>{this.rangeArray.push(t)})),t.clear()),this.rangeArray.sort(((t,e)=>t.absoluteOffset-e.absoluteOffset)),this.rangeArray.forEach((e=>{t.add(e)})),this.rangeArray=[]),t.size&&s.set(e,t)}}}$.fn.mark=function(t,e){return new s(this.get()).mark(t,e),this},$.fn.markRegExp=function(t,e){return new s(this.get()).markRegExp(t,e),this},$.fn.markRanges=function(t,e){return new s(this.get()).markRanges(t,e),this},$.fn.unmark=function(t){return new s(this.get()).unmark(t),this},$.fn.getVersion=function(){return"3.0.0"};var r=$;export{r as default};