var Common;!function(t){!function(t){"use strict";class e{constructor(t,i,s,n,o){F12.Tools.Utility.Assert.isTrue(2===t||1===t,"Invalid sourceType");F12.Tools.Utility.Assert.hasValue(n&&n.length,"sourceSpans are required");this.sourceType=t;this.text=i;this._originalText=s;this._sourceSpans=n;this.errorMessage=o||s.errorMessage;this._formattedOffsets=e.calculateLineOffsets(i)}static calculateLineOffsets(t){var e=0,i=[];i[e]=0;if(t)for(var s=0;s<t.length;s++)"\n"===t.charAt(s)&&(i[++e]=s+1);return i}getOffsetMappings(){for(var t=[],e=this._sourceSpans[0].sourcemap.allMappings,i=0;i<e.length;i++){var s=e[i];t.push({originalOffset:this._originalText.positionToOffset({line:s.sourceLine,column:s.sourceColumn,file:0}),mappedOffset:this.positionToOffset({line:s.generatedLine,column:s.generatedColumn,file:0})})}return t}getOriginalPosition(t){var e=this.getOriginalOffset(t);return this._originalText.getOriginalPosition(this._originalText.offsetToPosition(e))}getMappedPosition(e){e=this._originalText.getMappedPosition(e);var i,s,n=this._originalText.positionToOffset(e),o=this._originalText.text.length;if(0===o)return new t.Position(0,0);n<0&&(n=0);n>=o&&(n=o-1);for(s=0;s<this._sourceSpans.length;s++)if(this._sourceSpans[s].start<=n&&this._sourceSpans[s].end>=n){i=this._sourceSpans[s];break}F12.Tools.Utility.Assert.isTrue(s<this._sourceSpans.length,"Could not find source code for offset");var r=i.getPosition(n-i.start);i.sourcemap&&(r=i.sourcemap.getGeneratedPosition(r));r.line+=i.generatedLineOffset;return r}positionToOffset(t){return this._formattedOffsets[t.line]+t.column}offsetToPosition(e){for(var i=0;i<this._formattedOffsets.length&&!(this._formattedOffsets[i]>e);i++);i--;return new t.Position(i,e-this._formattedOffsets[i],0)}getOriginalOffset(e){if(0===this._originalText.text.length)return 0;for(var i=new t.Position(e.line,e.column,e.file),s=0;s<this._sourceSpans.length-1&&!(i.line<this._sourceSpans[s+1].generatedLineOffset);s++);var n=this._sourceSpans[s];i.line-=n.generatedLineOffset;n.sourcemap&&(i=n.sourcemap.getOriginalPosition(i));return n.getOffset(i)}}t.FormattedTextMapping=e;class i{constructor(t,e){this.originalOffset=t;this.mappedOffset=e}}t.OffsetMappingPair=i;class s{constructor(t,e,i){this.text=t;this.mappings=e;this._originalTextMapper=new n(i);this._mappedTextMapper=new n(t)}getOriginalPosition(t){for(var e=this._mappedTextMapper.positionToOffset(t),i=this.mappings.length-1;i>=0;i--)if(e>=this.mappings[i].mappedOffset){var s=e-this.mappings[i].mappedOffset;return this._originalTextMapper.offsetToPosition(this.mappings[i].originalOffset+s)}return this._mappedTextMapper.offsetToPosition(0)}getMappedPosition(t){for(var e=this._originalTextMapper.positionToOffset(t),i=this.mappings.length-1;i>=0;i--)if(e>=this.mappings[i].originalOffset){var s=e-this.mappings[i].originalOffset;return this._mappedTextMapper.offsetToPosition(this.mappings[i].mappedOffset+s)}return this._mappedTextMapper.offsetToPosition(0)}positionToOffset(t){return this._mappedTextMapper.positionToOffset(t)}offsetToPosition(t){return this._mappedTextMapper.offsetToPosition(t)}getOffsetMappings(){return this.mappings}}t.OffsetTextMapping=s;class n{constructor(t){this.text=t||"";this._newlineOffsets=[0];for(var e;(e=t.indexOf("\n",e+1))>-1;)this._newlineOffsets.push(e+1)}positionToOffset(t){if(!t)return 0;var e=t.line;e>=this._newlineOffsets.length&&(e=Math.max(0,this._newlineOffsets.length-1));return this._newlineOffsets[e]+t.column}offsetToPosition(t){t=Math.max(t,0);for(var e=this._newlineOffsets.length-1;e>=0;e--)if(this._newlineOffsets[e]<=t)return{line:e,column:t-this._newlineOffsets[e],file:0};return{line:0,column:t,file:0}}getOriginalPosition(t){return t}getMappedPosition(t){return t}getOffsetMappings(){return[]}}t.PositionOffsetMapper=n}(t.FormatService||(t.FormatService={}))}(Common||(Common={}));
