"use strict";(globalThis.webpackChunk_jbrowse_web=globalThis.webpackChunk_jbrowse_web||[]).push([[8397],{18397:(e,t,n)=>{function s(e){const t=new Uint8Array(function(e){let t=0;for(const n of e)t+=n.length;return t}(e));let n=0;for(const s of e)t.set(s,n),n+=s.length;return t}n.r(t),n.d(t,{default:()=>h});class r{ixxFile;ixFile;maxResults;constructor(e,t,n=20){this.ixxFile=e,this.ixFile=t,this.maxResults=n}async search(e,t){let n=[];const r=e.split(" ")[0].toLowerCase(),i=await this._getBuffer(r,t);if(!i)return[];let{end:o,buffer:a}=i,l=!1;const c=new TextDecoder("utf8");for(;!l;){let e=!1;const i=c.decode(a),u=i.slice(0,i.lastIndexOf("\n")).split("\n").filter((e=>!!e)),h=[];for(const t of u){const n=t.split(" ")[0],s=n.startsWith(r);!e&&s&&(e=!0),n.slice(0,r.length)>r&&(l=!0),s&&h.push(t)}const f=h.flatMap((e=>{const[t,...n]=e.split(" ");return n.map((e=>[t,e.split(",")[0]]))}));if(n.length+f.length<this.maxResults&&!l){const e=await this.ixFile.read(65536,o,t);if(0===e.length){n=n.concat(f);break}a=s([a,e]),o+=65536}else if(n.length+f.length>=this.maxResults||l){n=n.concat(f);break}}return function(e){const t=new Set;return e.filter((e=>{const n=e[1];return!t.has(n)&&t.add(n)}))}(n).slice(0,this.maxResults)}async getIndex(e){return(await this.ixxFile.readFile({encoding:"utf8",...e})).split("\n").filter((e=>!!e)).map((e=>{const t=e.length-10,n=e.slice(0,t),s=e.slice(t);return[n,Number.parseInt(s,16)]}))}async _getBuffer(e,t){let n=0,s=65536;const r=await this.getIndex(t);for(const[t,i]of r)t.slice(0,e.length)<e&&(n=i,s=i+65536);const i=s-n;if(!(i<0))return{buffer:await this.ixFile.read(i,n,t),end:s}}}var i=n(8656),o=n(68584),a=n(46377),l=n(99834);function c(e){try{return decodeURIComponent(e)}catch(t){return e}}function u(e,t,n=15){const s=e.toLowerCase().indexOf(t);return e.length<40?e:(Math.max(0,s-n)>0?"...":"")+e.slice(Math.max(0,s-n),s+t.length+n).trim()+(s+t.length<e.length?"...":"")}class h extends a.BaseAdapter{constructor(e,t,n){super(e,t,n);const s=(0,o.readConfObject)(e,"ixFilePath"),i=(0,o.readConfObject)(e,"ixxFilePath");if(!s)throw new Error("must provide out.ix");if(!i)throw new Error("must provide out.ixx");this.trixJs=new r((0,l.openLocation)(i,n),(0,l.openLocation)(s,n),1500)}async searchIndex(e){const t=e.queryString.toLowerCase(),n=t.split(" "),s=(await this.trixJs.search(t)).filter((([,e])=>n.every((t=>c(e).toLowerCase().includes(t))))).map((([e,t])=>{const n=JSON.parse(t.replaceAll("|",",")),[s,r,...o]=n.map((e=>c(e))),a=o.findIndex((e=>!!e)),l=o.map((e=>e.toLowerCase())).findIndex((t=>t.includes(e.toLowerCase()))),h=o[a],f=o[l],d=-1!==l?u(f,e):void 0,x=u(h,e),p=d&&x.toLowerCase()!==d.toLowerCase()?`${x} (${d})`:x;return new i.A({locString:s,label:h,displayString:p,matchedObject:n.map((e=>decodeURIComponent(e))),trackId:r})}));return"exact"===e.searchType?s.filter((t=>t.getLabel().toLowerCase()===e.queryString.toLowerCase())):s}}}}]);
//# sourceMappingURL=8397.696965da.chunk.js.map