import{__exports as e}from"../../../_virtual/source-map-generator3.mjs";import{__require as n}from"./base64-vlq.mjs";import{__require as o}from"./util.mjs";import{__require as r}from"./array-set.mjs";import{__require as t}from"./mapping-list.mjs";var i;function s(){if(i)return e;i=1;var s=n(),l=o(),u=r().ArraySet,a=t().MappingList;function c(e){e||(e={}),this._file=l.getArg(e,"file",null),this._sourceRoot=l.getArg(e,"sourceRoot",null),this._skipValidation=l.getArg(e,"skipValidation",!1),this._sources=new u,this._names=new u,this._mappings=new a,this._sourcesContents=null}return c.prototype._version=3,c.fromSourceMap=function(e){var n=e.sourceRoot,o=new c({file:e.file,sourceRoot:n});return e.eachMapping(function(e){var r={generated:{line:e.generatedLine,column:e.generatedColumn}};null!=e.source&&(r.source=e.source,null!=n&&(r.source=l.relative(n,r.source)),r.original={line:e.originalLine,column:e.originalColumn},null!=e.name&&(r.name=e.name)),o.addMapping(r)}),e.sources.forEach(function(r){var t=r;null!==n&&(t=l.relative(n,r)),o._sources.has(t)||o._sources.add(t);var i=e.sourceContentFor(r);null!=i&&o.setSourceContent(r,i)}),o},c.prototype.addMapping=function(e){var n=l.getArg(e,"generated"),o=l.getArg(e,"original",null),r=l.getArg(e,"source",null),t=l.getArg(e,"name",null);this._skipValidation||this._validateMapping(n,o,r,t),null!=r&&(r=String(r),this._sources.has(r)||this._sources.add(r)),null!=t&&(t=String(t),this._names.has(t)||this._names.add(t)),this._mappings.add({generatedLine:n.line,generatedColumn:n.column,originalLine:null!=o&&o.line,originalColumn:null!=o&&o.column,source:r,name:t})},c.prototype.setSourceContent=function(e,n){var o=e;null!=this._sourceRoot&&(o=l.relative(this._sourceRoot,o)),null!=n?(this._sourcesContents||(this._sourcesContents=Object.create(null)),this._sourcesContents[l.toSetString(o)]=n):this._sourcesContents&&(delete this._sourcesContents[l.toSetString(o)],0===Object.keys(this._sourcesContents).length&&(this._sourcesContents=null))},c.prototype.applySourceMap=function(e,n,o){var r=n;if(null==n){if(null==e.file)throw new Error('SourceMapGenerator.prototype.applySourceMap requires either an explicit source file, or the source map\'s "file" property. Both were omitted.');r=e.file}var t=this._sourceRoot;null!=t&&(r=l.relative(t,r));var i=new u,s=new u;this._mappings.unsortedForEach(function(n){if(n.source===r&&null!=n.originalLine){var u=e.originalPositionFor({line:n.originalLine,column:n.originalColumn});null!=u.source&&(n.source=u.source,null!=o&&(n.source=l.join(o,n.source)),null!=t&&(n.source=l.relative(t,n.source)),n.originalLine=u.line,n.originalColumn=u.column,null!=u.name&&(n.name=u.name))}var a=n.source;null==a||i.has(a)||i.add(a);var c=n.name;null==c||s.has(c)||s.add(c)},this),this._sources=i,this._names=s,e.sources.forEach(function(n){var r=e.sourceContentFor(n);null!=r&&(null!=o&&(n=l.join(o,n)),null!=t&&(n=l.relative(t,n)),this.setSourceContent(n,r))},this)},c.prototype._validateMapping=function(e,n,o,r){if(n&&"number"!=typeof n.line&&"number"!=typeof n.column)throw new Error("original.line and original.column are not numbers -- you probably meant to omit the original mapping entirely and only map the generated position. If so, pass null for the original mapping instead of an object with empty or null values.");if((!(e&&"line"in e&&"column"in e&&e.line>0&&e.column>=0)||n||o||r)&&!(e&&"line"in e&&"column"in e&&n&&"line"in n&&"column"in n&&e.line>0&&e.column>=0&&n.line>0&&n.column>=0&&o))throw new Error("Invalid mapping: "+JSON.stringify({generated:e,source:o,original:n,name:r}))},c.prototype._serializeMappings=function(){for(var e,n,o,r,t=0,i=1,u=0,a=0,c=0,p=0,m="",g=this._mappings.toArray(),h=0,_=g.length;h<_;h++){if(e="",(n=g[h]).generatedLine!==i)for(t=0;n.generatedLine!==i;)e+=";",i++;else if(h>0){if(!l.compareByGeneratedPositionsInflated(n,g[h-1]))continue;e+=","}e+=s.encode(n.generatedColumn-t),t=n.generatedColumn,null!=n.source&&(r=this._sources.indexOf(n.source),e+=s.encode(r-p),p=r,e+=s.encode(n.originalLine-1-a),a=n.originalLine-1,e+=s.encode(n.originalColumn-u),u=n.originalColumn,null!=n.name&&(o=this._names.indexOf(n.name),e+=s.encode(o-c),c=o)),m+=e}return m},c.prototype._generateSourcesContent=function(e,n){return e.map(function(e){if(!this._sourcesContents)return null;null!=n&&(e=l.relative(n,e));var o=l.toSetString(e);return Object.prototype.hasOwnProperty.call(this._sourcesContents,o)?this._sourcesContents[o]:null},this)},c.prototype.toJSON=function(){var e={version:this._version,sources:this._sources.toArray(),names:this._names.toArray(),mappings:this._serializeMappings()};return null!=this._file&&(e.file=this._file),null!=this._sourceRoot&&(e.sourceRoot=this._sourceRoot),this._sourcesContents&&(e.sourcesContent=this._generateSourcesContent(e.sources,e.sourceRoot)),e},c.prototype.toString=function(){return JSON.stringify(this.toJSON())},e.SourceMapGenerator=c,e}export{s as __require};