import{f as M,u as H,a9 as N}from"./index-Bm2SqMk3.js";/*!
 * isobject <https://github.com/jonschlinkert/isobject>
 *
 * Copyright (c) 2014-2017, Jon Schlinkert.
 * Released under the MIT License.
 */var F,V;function D(){return V||(V=1,F=function(t){return t!=null&&typeof t=="object"&&Array.isArray(t)===!1}),F}/*!
 * get-value <https://github.com/jonschlinkert/get-value>
 *
 * Copyright (c) 2014-2018, Jon Schlinkert.
 * Released under the MIT License.
 */var A,_;function X(){if(_)return A;_=1;const e=D();A=function(i,c,u){if(e(u)||(u={default:u}),!n(i))return typeof u.default<"u"?u.default:i;typeof c=="number"&&(c=String(c));const y=Array.isArray(c),d=typeof c=="string",h=u.separator||".",p=u.joinChar||(typeof h=="string"?h:".");if(!d&&!y)return i;if(d&&c in i)return s(c,i,u)?i[c]:u.default;let l=y?c:r(c,h,u),a=l.length,o=0;do{let f=l[o];for(typeof f=="number"&&(f=String(f));f&&f.slice(-1)==="\\";)f=t([f.slice(0,-1),l[++o]||""],p,u);if(f in i){if(!s(f,i,u))return u.default;i=i[f]}else{let S=!1,w=o+1;for(;w<a;)if(f=t([f,l[w++]],p,u),S=f in i){if(!s(f,i,u))return u.default;i=i[f],o=w-1;break}if(!S)return u.default}}while(++o<a&&n(i));return o===a?i:u.default};function t(i,c,u){return typeof u.join=="function"?u.join(i):i[0]+c+i[1]}function r(i,c,u){return typeof u.split=="function"?u.split(i):i.split(c)}function s(i,c,u){return typeof u.isValid=="function"?u.isValid(i,c):!0}function n(i){return e(i)||Array.isArray(i)||typeof i=="function"}return A}var Y=X();const W=M(Y);/*!
 * is-primitive <https://github.com/jonschlinkert/is-primitive>
 *
 * Copyright (c) 2014-present, Jon Schlinkert.
 * Released under the MIT License.
 */var x,g;function Q(){return g||(g=1,x=function(t){return typeof t=="object"?t===null:typeof t!="function"}),x}/*!
 * is-plain-object <https://github.com/jonschlinkert/is-plain-object>
 *
 * Copyright (c) 2014-2017, Jon Schlinkert.
 * Released under the MIT License.
 */var E,L;function Z(){if(L)return E;L=1;var e=D();function t(r){return e(r)===!0&&Object.prototype.toString.call(r)==="[object Object]"}return E=function(s){var n,i;return!(t(s)===!1||(n=s.constructor,typeof n!="function")||(i=n.prototype,t(i)===!1)||i.hasOwnProperty("isPrototypeOf")===!1)},E}/*!
 * set-value <https://github.com/jonschlinkert/set-value>
 *
 * Copyright (c) Jon Schlinkert (https://github.com/jonschlinkert).
 * Released under the MIT License.
 */var O,I;function C(){if(I)return O;I=1;const{deleteProperty:e}=Reflect,t=Q(),r=Z(),s=a=>typeof a=="object"&&a!==null||typeof a=="function",n=a=>a==="__proto__"||a==="constructor"||a==="prototype",i=a=>{if(!t(a))throw new TypeError("Object keys must be strings or symbols");if(n(a))throw new Error(`Cannot set unsafe key: "${a}"`)},c=a=>Array.isArray(a)?a.flat().map(String).join(","):a,u=(a,o)=>{if(typeof a!="string"||!o)return a;let f=a+";";return o.arrays!==void 0&&(f+=`arrays=${o.arrays};`),o.separator!==void 0&&(f+=`separator=${o.separator};`),o.split!==void 0&&(f+=`split=${o.split};`),o.merge!==void 0&&(f+=`merge=${o.merge};`),o.preservePaths!==void 0&&(f+=`preservePaths=${o.preservePaths};`),f},y=(a,o,f)=>{const S=c(o?u(a,o):a);i(S);const w=l.cache.get(S)||f();return l.cache.set(S,w),w},d=(a,o={})=>{const f=o.separator||".",S=f==="/"?!1:o.preservePaths;if(typeof a=="string"&&S!==!1&&/\//.test(a))return[a];const w=[];let b="";const B=m=>{let j;m.trim()!==""&&Number.isInteger(j=Number(m))?w.push(j):w.push(m)};for(let m=0;m<a.length;m++){const j=a[m];if(j==="\\"){b+=a[++m];continue}if(j===f){B(b),b="";continue}b+=j}return b&&B(b),w},h=(a,o)=>o&&typeof o.split=="function"?o.split(a):typeof a=="symbol"?[a]:Array.isArray(a)?a:y(a,o,()=>d(a,o)),p=(a,o,f,S)=>{if(i(o),f===void 0)e(a,o);else if(S&&S.merge){const w=S.merge==="function"?S.merge:Object.assign;w&&r(a[o])&&r(f)?a[o]=w(a[o],f):a[o]=f}else a[o]=f;return a},l=(a,o,f,S)=>{if(!o||!s(a))return a;const w=h(o,S);let b=a;for(let B=0;B<w.length;B++){const m=w[B],j=w[B+1];if(i(m),j===void 0){p(b,m,f,S);break}if(typeof j=="number"&&!Array.isArray(b[m])){b=b[m]=[];continue}s(b[m])||(b[m]={}),b=b[m]}return a};return l.split=h,l.cache=new Map,l.clear=()=>{l.cache=new Map},O=l,O}var ee=C();const re=M(ee);function T(e){return(e==null?void 0:e.label)&&typeof e.label=="string"}function te(e){return(e==null?void 0:e.url)&&typeof e.url=="string"}function k(e,t){for(const r of Object.keys(t))r in e&&typeof t[r]=="object"&&typeof e[r]=="object"?k(e[r],t[r]):(e[r]===void 0||t[r]!==void 0)&&(e[r]=t[r]);return e}function se(e,t){return e.replaceAll(/{([\s\w.]+)}/g,(r,s)=>{s=s.replaceAll(/\s+/g,"");const n=W(t,s);if(n!==void 0)return typeof n=="function"?n(s):n;if(t.callback){const i=t.callback.call(this,s);if(i!==void 0)return i}return r})}function ie(e,t){if(typeof e=="string"){let r;try{r=JSON.parse(e)}catch(s){throw new Error(`${s} when parsing configuration.`)}return $(r,t)}return $(e,t)}function ne(e,t){let r;try{r=oe(e,t)}catch(s){throw new Error(`${s} when parsing configuration.`)}return $(r,t)}function ae(e){return e==="include"}function oe(e,t){let r=[],s,n,i;const c={tracks:{}};let u;function y(){if(i!==void 0){let d;try{const h=/^json:(.+)/i.exec(i);if(h?d=JSON.parse(h[1]):/^[+-]?[\d.,]+([eE][-+]?\d+)?$/.test(i)?d=Number.parseFloat(i.replaceAll(",","")):d=i,!s)throw new Error(`Error parsing in section ${r.join(" - ")}`);const p=[...r,...s].join(".");if(n==="+="){let l=W(c,p);l?Array.isArray(l)||(l=[l]):l=[],l.push(d),d=l}d==="true"&&(d=!0),d==="false"&&(d=!1),re(c,p,d)}catch{throw new Error(`syntax error${t?` in ${t}`:""}${u?` at line ${u-1}`:""}`)}}}return e.split(/\n|\r\n|\r/).forEach((d,h)=>{u=h+1;const p=d.replace(/^\s*#.+/,"");let l;if(l=/^\s*\[([^\]]+)/.exec(p))y(),s=void 0,i=void 0,r=l[1].trim().split(/\s*\.\s*/),r.length===1&&r[0].toLowerCase()==="general"&&(r=[]);else if(l=p.match(i===void 0?/^([^+=]+)(\+?=)(.*)/:/^(\S[^+=]+)(\+?=)(.*)/))y(),s=l[1].trim().split(/\s*\.\s*/),[,,n]=l,ae([...r,...s].join("."))&&(n="+="),i=l[3].trim();else if(s!==void 0&&(l=/^\s{0,4}\+\s*(.+)/.exec(p)))y(),n="+=",i=l[1].trim();else if(i!==void 0&&(l=/^\s+(\S.*)/.exec(p))){const a=l[1];i+=i.length?` ${a.trim()}`:a.trim()}else y(),s=void 0,i=void 0}),y(),c}function $(e,t){if(e.tracks&&!Array.isArray(e.tracks))if(T(e.tracks))e.tracks=[e.tracks];else{const s=[];for(const n of Object.keys(e.tracks)){const i=e.tracks[n];T(i)?s.push(i):s.push({label:n,...i})}e.tracks=s}const r=e.trackMetadata;if(r!=null&&r.sources){if(typeof r.sources=="string"&&(r.sources=[r.sources]),te(r.sources)&&(r.sources=[r.sources]),!Array.isArray(r.sources)){const s=[];for(const n of Object.keys(r.sources)){const i=r.sources[n];"name"in i||(i.name=n),s.push(i)}r.sources=s}r.sources=r.sources.map(s=>{if(typeof s=="string"){const n={url:s},i=/\.(\w+)$/.exec(s);return i&&(n.type=i[1].toLowerCase()),n}return s})}if(e.sourceUrl=e.sourceUrl||t,e.sourceUrl.startsWith("/")&&(e.sourceUrl=new URL(e.sourceUrl,window.location.href).href),e.baseUrl=e.baseUrl||new URL(".",e.sourceUrl).href,e.baseUrl.length&&!e.baseUrl.endsWith("/")&&(e.baseUrl+="/"),e.sourceUrl){const s=[];e.tracks&&s.push(...e.tracks),e.stores&&s.push(...Object.values(e.stores)),e.names&&s.push(e.names),s.forEach(n=>{n.baseUrl||(n.baseUrl=e.baseUrl||"/")}),e.refSeqs&&typeof e.refSeqs=="string"&&(e.refSeqs=new URL(e.refSeqs,e.sourceUrl).href),e.nameUrl&&(e.nameUrl=new URL(e.nameUrl,e.sourceUrl).href)}return e.stores=e.stores||{},(e.tracks||[]).forEach(s=>{if(s.config){const i=s.config;s.config=void 0,s={...i,...s}}if(s.store)return;let n;s.type==="FeatureTrack"?n="JBrowse/View/Track/HTMLFeatures":s.type==="ImageTrack"?n="JBrowse/View/Track/FixedImage":s.type==="ImageTrack.Wiggle"?n="JBrowse/View/Track/FixedImage/Wiggle":s.type==="SequenceTrack"?n="JBrowse/View/Track/Sequence":n=G("JBrowse/View/Track",s.type),s.type=n,R(e,s),s.histograms&&(s.histograms.baseUrl||(s.histograms.baseUrl=s.baseUrl),R(e,s.histograms))}),e}function G(e,t){return t?(t.includes("/")||(t=`${e}/${t}`),t=t.replace(/^\//,""),t):""}function ue(e,t){var r,s;return e?!((r=e.type)===null||r===void 0)&&r.includes("/FixedImage")?`JBrowse/Store/TiledImage/Fixed${e.backendVersion===0?"_v0":""}`:/\.jsonz?$/i.test(t)?`JBrowse/Store/SeqFeature/NCList${e.backendVersion===0?"_v0":""}`:/\.bam$/i.test(t)?"JBrowse/Store/SeqFeature/BAM":/\.cram$/i.test(t)?"JBrowse/Store/SeqFeature/CRAM":/\.gff3?$/i.test(t)?"JBrowse/Store/SeqFeature/GFF3":/\.bed$/i.test(t)?"JBrowse/Store/SeqFeature/BED":/\.vcf.b?gz$/i.test(t)?"JBrowse/Store/SeqFeature/VCFTabix":/\.gff3?.b?gz$/i.test(t)?"JBrowse/Store/SeqFeature/GFF3Tabix":/\.bed.b?gz$/i.test(t)?"JBrowse/Store/SeqFeature/BEDTabix":/\.(bw|bigwig)$/i.test(t)?"JBrowse/Store/SeqFeature/BigWig":/\.(bb|bigbed)$/i.test(t)?"JBrowse/Store/SeqFeature/BigBed":/\.(fa|fasta)$/i.test(t)?"JBrowse/Store/SeqFeature/IndexedFasta":/\.(fa|fasta)\.b?gz$/i.test(t)?"JBrowse/Store/SeqFeature/BgzipIndexedFasta":/\.2bit$/i.test(t)?"JBrowse/Store/SeqFeature/TwoBit":!((s=e.type)===null||s===void 0)&&s.endsWith("/Sequence")?"JBrowse/Store/Sequence/StaticChunked":"":""}function R(e,t){var r;const{urlTemplate:s=""}=t,n=t.storeClass?G("JBrowse/Store",t.storeClass):ue(t,s);if(!n){console.warn(`Unable to determine an appropriate data store to use with track '${t.label}', please explicitly specify a storeClass in the configuration.`);return}const i={...t,type:n};i.name=(n==="JBrowse/Store/Sequence/StaticChunked"||n==="JBrowse/Store/Sequence/IndexedFasta"||n==="JBrowse/Store/SeqFeature/IndexedFasta"||n==="JBrowse/Store/SeqFeature/BgzipIndexedFasta"||n==="JBrowse/Store/SeqFeature/TwoBit"||n==="JBrowse/Store/Sequence/TwoBit"||t.useAsRefSeqStore)&&!(!((r=e.stores)===null||r===void 0)&&r.refseqs)?"refseqs":`store${H.objectHash(i)}`,e.stores||(e.stores={}),e.stores[i.name]=i,t.store=i.name}function U(e){return e.uri!==void 0}function q(e){return e.localPath!==void 0}async function Se(e={uri:"",locationType:"UriLocation"},t={include:["{dataRoot}/trackList.json","{dataRoot}/tracks.conf"]},r={uri:"",locationType:"UriLocation"}){const s="uri"in e?"uri":"localPath",n=JSON.parse(JSON.stringify(e));let i="";if(U(e)&&(i=e.uri),q(e)&&(i=e.localPath),i.endsWith("/")&&(n[s]=i.slice(0,-1)),U(r)&&r.uri||q(r)&&r.localPath){const u="uri"in r?"uri":"localPath";let y="";U(r)&&(y=r.uri),q(r)&&(y=r.localPath),y.endsWith("/")&&(y=y.slice(0,-1));let d={};for(const h of["jbrowse.conf","jbrowse_conf.json"]){let p=null;try{p=await K({[u]:`${y}/${h}`})}catch{console.error(`tried to access ${y}/${h}, but failed`)}d=v(d,p)||{}}return n[s]&&(d.dataRoot=n[s]),z(d)}const c=$(t,window.location.href);return n[s]&&(c.dataRoot=n[s]),z(c)}async function z(e,t=ye){const r=k(structuredClone(t),e);let s=await le(r);return s=v(s,e)||s,J(s,s),he(s),s}async function K(e){const t=await N.openLocation(e).readFile("utf8");return U(e)?P(t,e.uri):q(e)?P(t,e.localPath):P(t)}function P(e,t=""){return e.trim().startsWith("{")?ie(e,t):ne(e,t)}function v(e,t){if(t===null)return null;e===null&&(e={});for(const r of Object.keys(t))if(r==="tracks"&&r in e){const s=e[r]||[],n=t[r]||[];if(Array.isArray(s)&&Array.isArray(n))e[r]=fe(s,n);else throw new Error(`Track config has not been properly regularized: ${s} ${n}`)}else!de(r)&&r in e&&typeof t[r]=="object"&&typeof e[r]=="object"?e[r]=k(e[r],t[r]):r==="dataRoot"?(e[r]===void 0||e[r]==="data"&&t[r]!==void 0)&&(e[r]=t[r]):(e[r]===void 0||t[r]!==void 0)&&(e[r]=t[r]);return e}function fe(e,t){if(!t.length)return e;const r={};return e.forEach((s,n)=>{s.index=n,r[s.label]=s}),t.forEach(s=>{const n=r[s.label];n?v(n,s):e.push(s)}),e}async function le(e){e=structuredClone(e);async function t(r,s){const n=r.sourceUrl||r.baseUrl;if(!n)throw new Error(`Could not determine source URL: ${JSON.stringify(r)}`);const i=v(structuredClone(s),r);if(!i)throw new Error("Problem merging configs");const c=J(ce(r.include||[]),i);r.include=void 0;const u=c.map(async d=>{d.cacheBuster=e.cacheBuster;const h=await K({uri:new URL(d.url,n).href,locationType:"UriLocation"});return t(h,i)});return(await Promise.all(u)).forEach(d=>{r=v(r,d)||r}),r}return t(e,{})}function ce(e){return e?(Array.isArray(e)||(e=[e]),e.map(t=>(typeof t=="string"&&(t={url:t}),"format"in t||(t.format=t.url.endsWith(".conf")?"conf":"JB_json"),t.format==="JB_json"&&!("version"in t)&&(t.version=1),t))):[]}function J(e,t){if(!e)return e;if(Array.isArray(e))for(let r=0;r<e.length;r+=1)e[r]=J(e[r],t);else if(typeof e=="object"){const r=e;for(const s of Object.keys(r))r[s]=J(r[s],t)}else if(typeof e=="string")return se(e,t);return e}function de(e){return e==="datasets"}const ye={tracks:[],containerID:"GenomeBrowser",dataRoot:"data",show_tracklist:!0,show_nav:!0,show_menu:!0,show_overview:!0,show_fullviewlink:!0,update_browser_title:!0,updateBrowserURL:!0,refSeqs:"{dataRoot}/seq/refSeqs.json",include:["jbrowse.conf","jbrowse_conf.json"],nameUrl:"{dataRoot}/names/root.json",datasets:{_DEFAULT_EXAMPLES:!0,volvox:{url:"?data=sample_data/json/volvox",name:"Volvox Example"},modencode:{url:"?data=sample_data/json/modencode",name:"MODEncode Example"},yeast:{url:"?data=sample_data/json/yeast",name:"Yeast Example"}},highlightSearchedRegions:!1,highResolutionMode:"auto"};function he(e){if(e.tracks||(e.tracks=[]),!e.baseUrl)throw new Error("Must provide a `baseUrl` in configuration")}export{z as createFinalConfig,K as fetchConfigFile,Se as fetchJb1,P as parseJb1};
