import{__require as e}from"../../nanoid/non-secure/index.mjs";import i from"../../../_virtual/_node_path.mjs";import{__require as t}from"../../source-map-js/source-map.mjs";import o from"../../../_virtual/_node_url.mjs";import{__require as s}from"./css-syntax-error.mjs";import{__require as n}from"./previous-map.mjs";import{__require as r}from"./terminal-highlight.mjs";var l,m;function u(){if(m)return l;m=1;let{nanoid:u}=e(),{isAbsolute:f,resolve:c}=i,{SourceMapConsumer:h,SourceMapGenerator:a}=t(),{fileURLToPath:p,pathToFileURL:d}=o,g=s(),_=n(),C=r(),S=Symbol("lineToIndexCache"),v=Boolean(h&&a),L=Boolean(c&&f);function w(e){if(e[S])return e[S];let i=e.css.split("\n"),t=new Array(i.length),o=0;for(let e=0,s=i.length;e<s;e++)t[e]=o,o+=i[e].length+1;return e[S]=t,t}class b{get from(){return this.file||this.id}constructor(e,i={}){if(null==e||"object"==typeof e&&!e.toString)throw new Error(`PostCSS received ${e} instead of CSS string`);if(this.css=e.toString(),"\ufeff"===this.css[0]||""===this.css[0]?(this.hasBOM=!0,this.css=this.css.slice(1)):this.hasBOM=!1,this.document=this.css,i.document&&(this.document=i.document.toString()),i.from&&(!L||/^\w+:\/\//.test(i.from)||f(i.from)?this.file=i.from:this.file=c(i.from)),L&&v){let e=new _(this.css,i);if(e.text){this.map=e;let i=e.consumer().file;!this.file&&i&&(this.file=this.mapResolve(i))}}this.file||(this.id="<input css "+u(6)+">"),this.map&&(this.map.file=this.from)}error(e,i,t,o={}){let s,n,r,l,m;if(i&&"object"==typeof i){let e=i,o=t;if("number"==typeof e.offset){l=e.offset;let o=this.fromOffset(l);i=o.line,t=o.col}else i=e.line,t=e.column,l=this.fromLineAndColumn(i,t);if("number"==typeof o.offset){r=o.offset;let e=this.fromOffset(r);n=e.line,s=e.col}else n=o.line,s=o.column,r=this.fromLineAndColumn(o.line,o.column)}else if(t)l=this.fromLineAndColumn(i,t);else{l=i;let e=this.fromOffset(l);i=e.line,t=e.col}let u=this.origin(i,t,n,s);return m=u?new g(e,void 0===u.endLine?u.line:{column:u.column,line:u.line},void 0===u.endLine?u.column:{column:u.endColumn,line:u.endLine},u.source,u.file,o.plugin):new g(e,void 0===n?i:{column:t,line:i},void 0===n?t:{column:s,line:n},this.css,this.file,o.plugin),m.input={column:t,endColumn:s,endLine:n,endOffset:r,line:i,offset:l,source:this.css},this.file&&(d&&(m.input.url=d(this.file).toString()),m.input.file=this.file),m}fromLineAndColumn(e,i){return w(this)[e-1]+i-1}fromOffset(e){let i=w(this),t=0;if(e>=i[i.length-1])t=i.length-1;else{let o,s=i.length-2;for(;t<s;)if(o=t+(s-t>>1),e<i[o])s=o-1;else{if(!(e>=i[o+1])){t=o;break}t=o+1}}return{col:e-i[t]+1,line:t+1}}mapResolve(e){return/^\w+:\/\//.test(e)?e:c(this.map.consumer().sourceRoot||this.map.root||".",e)}origin(e,i,t,o){if(!this.map)return!1;let s,n,r=this.map.consumer(),l=r.originalPositionFor({column:i,line:e});if(!l.source)return!1;"number"==typeof t&&(s=r.originalPositionFor({column:o,line:t})),n=f(l.source)?d(l.source):new URL(l.source,this.map.consumer().sourceRoot||d(this.map.mapFile));let m={column:l.column,endColumn:s&&s.column,endLine:s&&s.line,line:l.line,url:n.toString()};if("file:"===n.protocol){if(!p)throw new Error("file: protocol is not available in this PostCSS build");m.file=p(n)}let u=r.sourceContentFor(l.source);return u&&(m.source=u),m}toJSON(){let e={};for(let i of["hasBOM","css","file","id"])null!=this[i]&&(e[i]=this[i]);return this.map&&(e.map={...this.map},e.map.consumerCache&&(e.map.consumerCache=void 0)),e}}return l=b,b.default=b,C&&C.registerInput&&C.registerInput(b),l}export{u as __require};