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