import{adoptBuffer as t}from"./adopt-buffer.mjs";import{isBOM as s}from"./char-code-definitions.mjs";function e(e){const o=e.source,i=o.length,n=o.length>0?s(o.charCodeAt(0)):0,c=t(e.lines,i),r=t(e.columns,i);let l=e.startLine,u=e.startColumn;for(let t=n;t<i;t++){const s=o.charCodeAt(t);c[t]=l,r[t]=u++,10!==s&&13!==s&&12!==s||(13===s&&t+1<i&&10===o.charCodeAt(t+1)&&(t++,c[t]=l,r[t]=u),l++,u=1)}c[i]=l,r[i]=u,e.lines=c,e.columns=r,e.computed=!0}class o{constructor(t,s,e,o){this.setSource(t,s,e,o),this.lines=null,this.columns=null}setSource(t="",s=0,e=1,o=1){this.source=t,this.startOffset=s,this.startLine=e,this.startColumn=o,this.computed=!1}getLocation(t,s){return this.computed||e(this),{source:s,offset:this.startOffset+t,line:this.lines[t],column:this.columns[t]}}getLocationRange(t,s,o){return this.computed||e(this),{source:o,start:{offset:this.startOffset+t,line:this.lines[t],column:this.columns[t]},end:{offset:this.startOffset+s,line:this.lines[s],column:this.columns[s]}}}}export{o as OffsetToLocation};