import t from"../../../_virtual/_node_fs.mjs";import r from"../../../_virtual/_node_path.mjs";import{__require as e}from"../../source-map-js/source-map.mjs";var n,i;function o(){if(i)return n;i=1;let{existsSync:o,readFileSync:a}=t,{dirname:s,join:u}=r,{SourceMapConsumer:p,SourceMapGenerator:h}=e();class c{constructor(t,r){if(!1===r.map)return;this.loadAnnotation(t),this.inline=this.startWith(this.annotation,"data:");let e=r.map?r.map.prev:void 0,n=this.loadMap(r.from,e);!this.mapFile&&r.from&&(this.mapFile=r.from),this.mapFile&&(this.root=s(this.mapFile)),n&&(this.text=n)}consumer(){return this.consumerCache||(this.consumerCache=new p(this.text)),this.consumerCache}decodeInline(t){let r=t.match(/^data:application\/json;charset=utf-?8,/)||t.match(/^data:application\/json,/);if(r)return decodeURIComponent(t.substr(r[0].length));let e=t.match(/^data:application\/json;charset=utf-?8;base64,/)||t.match(/^data:application\/json;base64,/);if(e)return n=t.substr(e[0].length),Buffer?Buffer.from(n,"base64").toString():window.atob(n);var n;let i=t.match(/data:application\/json;([^,]+),/)[1];throw new Error("Unsupported source map encoding "+i)}getAnnotationURL(t){return t.replace(/^\/\*\s*# sourceMappingURL=/,"").trim()}isMap(t){return"object"==typeof t&&("string"==typeof t.mappings||"string"==typeof t._mappings||Array.isArray(t.sections))}loadAnnotation(t){let r=t.match(/\/\*\s*# sourceMappingURL=/g);if(!r)return;let e=t.lastIndexOf(r.pop()),n=t.indexOf("*/",e);e>-1&&n>-1&&(this.annotation=this.getAnnotationURL(t.substring(e,n)))}loadFile(t){if(this.root=s(t),o(t))return this.mapFile=t,a(t,"utf-8").toString().trim()}loadMap(t,r){if(!1===r)return!1;if(r){if("string"==typeof r)return r;if("function"!=typeof r){if(r instanceof p)return h.fromSourceMap(r).toString();if(r instanceof h)return r.toString();if(this.isMap(r))return JSON.stringify(r);throw new Error("Unsupported previous source map format: "+r.toString())}{let e=r(t);if(e){let t=this.loadFile(e);if(!t)throw new Error("Unable to load previous source map: "+e.toString());return t}}}else{if(this.inline)return this.decodeInline(this.annotation);if(this.annotation){let r=this.annotation;return t&&(r=u(s(t),r)),this.loadFile(r)}}}startWith(t,r){return!!t&&t.substr(0,r.length)===r}withContent(){return!!(this.consumer().sourcesContent&&this.consumer().sourcesContent.length>0)}}return n=c,c.default=c,n}export{o as __require};