import{d as e,s as t,y as n}from"./dist.BKE5SKAa.js";import{a as r,r as i,t as a}from"./dist.DN9QYtNP.js";import{getIndentUnit as o}from"./dist.C3J8NGfd.js";function s(e,t=e.state){let n=new Set;for(let{from:r,to:i}of e.visibleRanges){let e=r;for(;e<=i;){let r=t.doc.lineAt(e);n.has(r)||n.add(r),e=r.to+1}}return n}function c(e){let t=e.selection.main.head;return e.doc.lineAt(t)}function l(e,t){let n=0;loop:for(let r=0;r<e.length;r++)switch(e[r]){case` `:case`\xA0`:n+=1;continue loop;case`	`:n+=t-n%t;continue loop;case`\r`:continue loop;default:break loop}return n}var u=t.define({combine(e){return n(e,{highlightActiveBlock:!0,hideFirstIndent:!1,markerType:`fullScope`,thickness:1})}}),d=class{constructor(e,t,n,r){this.lines=e,this.state=t,this.map=new Map,this.unitWidth=n,this.markerType=r;for(let e of this.lines)this.add(e);this.state.facet(u).highlightActiveBlock&&this.findAndSetActiveLines()}has(e){return this.map.has(typeof e==`number`?e:e.number)}get(e){let t=this.map.get(typeof e==`number`?e:e.number);if(!t)throw Error(`Line not found in indentation map`);return t}set(e,t,n){let r={line:e,col:t,level:n,empty:!e.text.trim().length};return this.map.set(r.line.number,r),r}add(e){if(this.has(e))return this.get(e);if(!e.length||!e.text.trim().length){if(e.number===1)return this.set(e,0,0);if(e.number===this.state.doc.lines){let t=this.closestNonEmpty(e,-1);return this.set(e,0,t.level)}let t=this.closestNonEmpty(e,-1),n=this.closestNonEmpty(e,1);return t.level>=n.level&&this.markerType!==`codeOnly`?this.set(e,0,t.level):t.empty&&t.level===0&&n.level!==0?this.set(e,0,0):n.level>t.level?this.set(e,0,t.level+1):this.set(e,0,n.level)}let t=l(e.text,this.state.tabSize),n=Math.floor(t/this.unitWidth);return this.set(e,t,n)}closestNonEmpty(e,t){let n=e.number+t;for(;t===-1?n>=1:n<=this.state.doc.lines;){if(this.has(n)){let e=this.get(n);if(!e.empty)return e}let e=this.state.doc.line(n);if(e.text.trim().length){let t=l(e.text,this.state.tabSize),n=Math.floor(t/this.unitWidth);return this.set(e,t,n)}n+=t}let r=this.state.doc.line(t===-1?1:this.state.doc.lines);return this.set(r,0,0)}findAndSetActiveLines(){let e=c(this.state);if(!this.has(e))return;let t=this.get(e);if(this.has(t.line.number+1)){let e=this.get(t.line.number+1);e.level>t.level&&(t=e)}if(this.has(t.line.number-1)){let e=this.get(t.line.number-1);e.level>t.level&&(t=e)}if(t.level===0)return;t.active=t.level;let n,r;for(n=t.line.number;n>1;n--){if(!this.has(n-1))continue;let e=this.get(n-1);if(e.level<t.level)break;e.active=t.level}for(r=t.line.number;r<this.state.doc.lines;r++){if(!this.has(r+1))continue;let e=this.get(r+1);if(e.level<t.level)break;e.active=t.level}}};function f(e){let t={light:`#F0F1F2`,dark:`#2B3245`,activeLight:`#E4E5E6`,activeDark:`#3C445C`},n=t;return e&&(n=Object.assign(Object.assign({},t),e)),i.baseTheme({"&light":{"--indent-marker-bg-color":n.light,"--indent-marker-active-bg-color":n.activeLight},"&dark":{"--indent-marker-bg-color":n.dark,"--indent-marker-active-bg-color":n.activeDark},".cm-line":{position:`relative`},".cm-indent-markers::before":{content:`""`,position:`absolute`,top:0,left:`2px`,right:0,bottom:0,background:`var(--indent-markers)`,pointerEvents:`none`,zIndex:`-1`}})}function p(e,t,n,r,i){return`${`repeating-linear-gradient(to right, var(${e}) 0 ${t}px, transparent ${t}px ${n}ch)`} ${r*n}.5ch/calc(${n*i}ch - 1px) no-repeat`}function m(e,t,n,r,i){let{level:a,active:o}=e;if(i=i??r,n&&a===0)return[];let s=n?1:0,c=[];if(o!==void 0){let e=o-s-1;e>0&&c.push(p(`--indent-marker-bg-color`,r,t,s,e)),c.push(p(`--indent-marker-active-bg-color`,i,t,o-1,1)),o!==a&&c.push(p(`--indent-marker-bg-color`,r,t,o,a-o))}else c.push(p(`--indent-marker-bg-color`,r,t,s,a-s));return c.join(`,`)}var h=class{constructor(e){this.view=e,this.unitWidth=o(e.state),this.currentLineNumber=c(e.state).number,this.generate(e.state)}update(e){let t=o(e.state),n=t!==this.unitWidth;n&&(this.unitWidth=t);let r=c(e.state).number,i=r!==this.currentLineNumber;this.currentLineNumber=r;let a=e.state.facet(u).highlightActiveBlock&&i;(e.docChanged||e.viewportChanged||n||a)&&this.generate(e.state)}generate(t){let n=new e,r=s(this.view,t),{hideFirstIndent:i,markerType:o,thickness:c,activeThickness:l}=t.facet(u),f=new d(r,t,this.unitWidth,o);for(let e of r){let t=f.get(e.number);if(!t?.level)continue;let r=m(t,this.unitWidth,i,c,l);n.add(e.from,e.from,a.line({class:`cm-indent-markers`,attributes:{style:`--indent-markers: ${r}`}}))}this.decorations=n.finish()}};function g(e={}){return[u.of(e),f(e.colors),r.fromClass(h,{decorations:e=>e.decorations})]}export{g as indentationMarkers};
//# sourceMappingURL=dist.tLoiYG1O.js.map