/* esm.sh - @codemirror/lint@6.9.7 */
import{Decoration as T,showPanel as le,EditorView as A,ViewPlugin as re,gutter as ae,showTooltip as ce,hoverTooltip as fe,getPanel as de,activateHover as q,logException as ue,WidgetType as me,GutterMarker as he}from"../../view@^6.42.0?target=es2022";import{StateEffect as R,StateField as G,Facet as Z,combineConfig as U,RangeSet as z,RangeSetBuilder as ge}from"../../state@^6.0.0?target=es2022";import x from"../../../crelt@^1.0.5?target=es2022";var M=class{constructor(e,n,i){this.from=e,this.to=n,this.diagnostic=i}},C=class t{constructor(e,n,i){this.diagnostics=e,this.panel=n,this.selected=i}static init(e,n,i){let o=i.facet(v).markerFilter;o&&(e=o(e,i));let s=e.slice().sort((h,b)=>h.from-b.from||h.to-b.to),r=new ge,l=[],c=0,a=i.doc.iter(),f=0,u=i.doc.length;for(let h=0;;){let b=h==s.length?null:s[h];if(!b&&!l.length)break;let w,g;if(l.length)w=c,g=l.reduce((d,k)=>Math.min(d,k.to),b&&b.from>w?b.from:1e8);else{if(w=b.from,w>u)break;g=b.to,l.push(b),h++}for(;h<s.length;){let d=s[h];if(d.from==w&&(d.to>d.from||d.to==w))l.push(d),h++,g=Math.min(d.to,g);else{g=Math.min(d.from,g);break}}g=Math.min(g,u);let P=!1;if(l.some(d=>d.from==w&&(d.to==g||g==u))&&(P=w==g,!P&&g-w<10)){let d=w-(f+a.value.length);d>0&&(a.next(d),f=w);for(let k=w;;){if(k>=g){P=!0;break}if(!a.lineBreak&&f+a.value.length>k)break;k=f+a.value.length,f+=a.value.length,a.next()}}let _=ne(l);if(P)r.add(w,w,T.widget({widget:new O(_),diagnostics:l.slice()}));else{let d=l.reduce((k,j)=>j.markClass?k+" "+j.markClass:k,"");r.add(w,g,T.mark({class:"cm-lintRange cm-lintRange-"+_+d,diagnostics:l.slice(),inclusiveEnd:l.some(k=>k.to>g)}))}if(c=g,c==u)break;for(let d=0;d<l.length;d++)l[d].to<=c&&l.splice(d--,1)}let m=r.finish();return new t(m,n,y(m))}};function y(t,e=null,n=0){let i=null;return t.between(n,1e9,(o,s,{spec:r})=>{if(!(e&&r.diagnostics.indexOf(e)<0))if(!i)i=new M(o,s,e||r.diagnostics[0]);else{if(r.diagnostics.indexOf(i.diagnostic)<0)return!1;i=new M(i.from,s,i.diagnostic)}}),i}function X(t,e){let n=e.pos,i=e.end||n,o=t.state.facet(v).hideOn(t,n,i);if(o!=null)return o;let s=t.startState.doc.lineAt(e.pos);return!!(t.effects.some(r=>r.is(E))||t.changes.touchesRange(s.from,Math.max(s.to,i)))}function W(t,e){return t.field(p,!1)?e:e.concat(R.appendConfig.of(se))}function pe(t,e){return{effects:W(t,[E.of(e)])}}var E=R.define(),$=R.define(),J=R.define(),p=G.define({create(){return new C(T.none,null,null)},update(t,e){if(e.docChanged&&t.diagnostics.size){let n=t.diagnostics.map(e.changes),i=null,o=t.panel;if(t.selected){let s=e.changes.mapPos(t.selected.from,1);i=y(n,t.selected.diagnostic,s)||y(n,null,s)}!n.size&&o&&e.state.facet(v).autoPanel&&(o=null),t=new C(n,o,i)}for(let n of e.effects)if(n.is(E)){let i=e.state.facet(v).autoPanel?n.value.length?S.open:null:t.panel;t=C.init(n.value,i,e.state)}else n.is($)?t=new C(t.diagnostics,n.value?S.open:null,t.selected):n.is(J)&&(t=new C(t.diagnostics,t.panel,n.value));return t},provide:t=>[le.from(t,e=>e.panel),A.decorations.from(t,e=>e.diagnostics)]});function Ie(t){let e=t.field(p,!1);return e?e.diagnostics.size:0}var we=T.mark({class:"cm-lintRange cm-lintRange-active"});function be(t,e,n){let{diagnostics:i}=t.state.field(p),o,s=-1,r=-1;i.between(e-(n<0?1:0),e+(n>0?1:0),(c,a,{spec:f})=>{if(e>=c&&e<=a&&(c==a||(e>c||n>0)&&(e<a||n<0)))return o=f.diagnostics,s=c,r=a,!1});let l=t.state.facet(v).tooltipFilter;return o&&l&&(o=l(o,t.state)),o?{pos:s,end:r,above:!0,create(){return{dom:Q(t,o)}}}:null}function Q(t,e){return x("ul",{class:"cm-tooltip-lint"},e.map(n=>ie(t,n,!1)))}var ke=t=>{let e=t.state.field(p,!1);(!e||!e.panel)&&t.dispatch({effects:W(t.state,[$.of(!0)])});let n=de(t,S.open);return n&&n.dom.querySelector(".cm-panel-lint ul").focus(),!0},N=t=>{let e=t.state.field(p,!1);return!e||!e.panel?!1:(t.dispatch({effects:$.of(!1)}),!0)},xe=t=>{let e=t.state.field(p,!1);if(!e)return!1;let n=t.state.selection.main,i=y(e.diagnostics,null,n.to+1);return!i&&(i=y(e.diagnostics,null,0),!i||i.from==n.from&&i.to==n.to)?!1:(t.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0}),q(t,i.from,1,{tooltip:V,until:o=>o.docChanged||o.newSelection.main.head<i.from||o.newSelection.main.head>i.to}),!0)},Ae=t=>{var e;let{state:n}=t,i=n.field(p,!1);if(!i)return!1;let o=n.selection.main,s,r,l,c;if(i.diagnostics.between(0,n.doc.length,(u,m)=>{m<o.to&&(s==null||s<u)&&(s=u,r=m),(l==null||u>l)&&(l=u,c=m)}),l==null||s==null&&l==o.from)return!1;let a=s??l,f=(e=r??c)!==null&&e!==void 0?e:a;return t.dispatch({selection:{anchor:a,head:f},scrollIntoView:!0}),q(t,a,1,{tooltip:V,until:u=>u.docChanged||u.newSelection.main.head<a||u.newSelection.main.head>f}),!0},Ee=[{key:"Mod-Shift-m",run:ke,preventDefault:!0},{key:"F8",run:xe}],ee=re.fromClass(class{constructor(t){this.view=t,this.timeout=-1,this.set=!0;let{delay:e}=t.state.facet(v);this.lintTime=Date.now()+e,this.run=this.run.bind(this),this.timeout=setTimeout(this.run,e)}run(){clearTimeout(this.timeout);let t=Date.now();if(t<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-t);else{this.set=!1;let{state:e}=this.view,{sources:n}=e.facet(v);n.length&&ve(n.map(i=>Promise.resolve(i(this.view))),i=>{this.view.state.doc==e.doc&&this.view.dispatch(pe(this.view.state,i.reduce((o,s)=>o.concat(s))))},i=>{ue(this.view.state,i)})}}update(t){let e=t.state.facet(v);(t.docChanged||e!=t.startState.facet(v)||e.needsRefresh&&e.needsRefresh(t))&&(this.lintTime=Date.now()+e.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,e.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});function ve(t,e,n){let i=[],o=-1;for(let s of t)s.then(r=>{i.push(r),clearTimeout(o),i.length==t.length?e(i):o=setTimeout(()=>e(i),200)},n)}var v=Z.define({combine(t){return{sources:t.map(e=>e.source).filter(e=>e!=null),...U(t.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:Y,tooltipFilter:Y,needsRefresh:(e,n)=>e?n?i=>e(i)||n(i):e:n,hideOn:(e,n)=>e?n?(i,o,s)=>e(i,o,s)||n(i,o,s):e:n,autoPanel:(e,n)=>e||n})}}});function Y(t,e){return t?e?(n,i)=>e(t(n,i),i):t:e}function Be(t,e={}){return[v.of({source:t,config:e}),ee,se]}function Oe(t){let e=t.plugin(ee);e&&e.force()}function te(t){let e=[];if(t)e:for(let{name:n}of t){for(let i=0;i<n.length;i++){let o=n[i];if(/[a-zA-Z]/.test(o)&&!e.some(s=>s.toLowerCase()==o.toLowerCase())){e.push(o);continue e}}e.push("")}return e}function ie(t,e,n){var i;let o=n?te(e.actions):[];return x("li",{class:"cm-diagnostic cm-diagnostic-"+e.severity},x("span",{class:"cm-diagnosticText"},e.renderMessage?e.renderMessage(t):e.message),(i=e.actions)===null||i===void 0?void 0:i.map((s,r)=>{let l=!1,c=h=>{if(h.preventDefault(),l)return;l=!0;let b=y(t.state.field(p).diagnostics,e);b&&s.apply(t,b.from,b.to)},{name:a}=s,f=o[r]?a.indexOf(o[r]):-1,u=f<0?a:[a.slice(0,f),x("u",a.slice(f,f+1)),a.slice(f+1)],m=s.markClass?" "+s.markClass:"";return x("button",{type:"button",class:"cm-diagnosticAction"+m,onclick:c,onmousedown:c,"aria-label":` Action: ${a}${f<0?"":` (access key "${o[r]})"`}.`},u)}),e.source&&x("div",{class:"cm-diagnosticSource"},e.source))}var O=class extends me{constructor(e){super(),this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return x("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}},D=class{constructor(e,n){this.diagnostic=n,this.id="item_"+Math.floor(Math.random()*4294967295).toString(16),this.dom=ie(e,n,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}},S=class t{constructor(e){this.view=e,this.items=[];let n=o=>{if(!(o.ctrlKey||o.altKey||o.metaKey)){if(o.keyCode==27)N(this.view),this.view.focus();else if(o.keyCode==38||o.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(o.keyCode==40||o.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(o.keyCode==36)this.moveSelection(0);else if(o.keyCode==35)this.moveSelection(this.items.length-1);else if(o.keyCode==13)this.view.focus();else if(o.keyCode>=65&&o.keyCode<=90&&this.selectedIndex>=0){let{diagnostic:s}=this.items[this.selectedIndex],r=te(s.actions);for(let l=0;l<r.length;l++)if(r[l].toUpperCase().charCodeAt(0)==o.keyCode){let c=y(this.view.state.field(p).diagnostics,s);c&&s.actions[l].apply(e,c.from,c.to)}}else return;o.preventDefault()}},i=o=>{for(let s=0;s<this.items.length;s++)this.items[s].dom.contains(o.target)&&this.moveSelection(s)};this.list=x("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:n,onclick:i}),this.dom=x("div",{class:"cm-panel-lint"},this.list,x("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>N(this.view)},"\xD7")),this.update()}get selectedIndex(){let e=this.view.state.field(p).selected;if(!e)return-1;for(let n=0;n<this.items.length;n++)if(this.items[n].diagnostic==e.diagnostic)return n;return-1}update(){let{diagnostics:e,selected:n}=this.view.state.field(p),i=0,o=!1,s=null,r=new Set;for(e.between(0,this.view.state.doc.length,(l,c,{spec:a})=>{for(let f of a.diagnostics){if(r.has(f))continue;r.add(f);let u=-1,m;for(let h=i;h<this.items.length;h++)if(this.items[h].diagnostic==f){u=h;break}u<0?(m=new D(this.view,f),this.items.splice(i,0,m),o=!0):(m=this.items[u],u>i&&(this.items.splice(i,u-i),o=!0)),n&&m.diagnostic==n.diagnostic?m.dom.hasAttribute("aria-selected")||(m.dom.setAttribute("aria-selected","true"),s=m):m.dom.hasAttribute("aria-selected")&&m.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0);)o=!0,this.items.pop();this.items.length==0&&(this.items.push(new D(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")})),o=!0),s?(this.list.setAttribute("aria-activedescendant",s.id),this.view.requestMeasure({key:this,read:()=>({sel:s.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:l,panel:c})=>{let a=c.height/this.list.offsetHeight;l.top<c.top?this.list.scrollTop-=(c.top-l.top)/a:l.bottom>c.bottom&&(this.list.scrollTop+=(l.bottom-c.bottom)/a)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),o&&this.sync()}sync(){let e=this.list.firstChild;function n(){let i=e;e=i.nextSibling,i.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){for(;e!=i.dom;)n();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)n()}moveSelection(e){if(this.selectedIndex<0)return;let n=this.view.state.field(p),i=y(n.diagnostics,this.items[e].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:!0,effects:J.of(i)})}static open(e){return new t(e)}};function L(t,e='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${e}>${encodeURIComponent(t)}</svg>')`}function F(t){return L(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${t}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}var ye=A.baseTheme({".cm-diagnostic":{padding:"3px 6px 3px 8px",marginLeft:"-1px",display:"block",whiteSpace:"pre-wrap"},".cm-diagnostic-error":{borderLeft:"5px solid #d11"},".cm-diagnostic-warning":{borderLeft:"5px solid orange"},".cm-diagnostic-info":{borderLeft:"5px solid #999"},".cm-diagnostic-hint":{borderLeft:"5px solid #66d"},".cm-diagnosticAction":{font:"inherit",border:"none",padding:"2px 4px",backgroundColor:"#444",color:"white",borderRadius:"3px",marginLeft:"8px",cursor:"pointer"},".cm-diagnosticSource":{fontSize:"70%",opacity:.7},".cm-lintRange":{backgroundPosition:"left bottom",backgroundRepeat:"repeat-x",paddingBottom:"0.7px"},".cm-lintRange-error":{backgroundImage:F("#f11")},".cm-lintRange-warning":{backgroundImage:F("orange")},".cm-lintRange-info":{backgroundImage:F("#999")},".cm-lintRange-hint":{backgroundImage:F("#66d")},".cm-lintRange-active":{backgroundColor:"#ffdd9980"},".cm-tooltip-lint":{padding:0,margin:0},".cm-lintPoint":{position:"relative","&:after":{content:'""',position:"absolute",bottom:0,left:"-2px",borderLeft:"3px solid transparent",borderRight:"3px solid transparent",borderBottom:"4px solid #d11"}},".cm-lintPoint-warning":{"&:after":{borderBottomColor:"orange"}},".cm-lintPoint-info":{"&:after":{borderBottomColor:"#999"}},".cm-lintPoint-hint":{"&:after":{borderBottomColor:"#66d"}},".cm-panel.cm-panel-lint":{position:"relative","& ul":{maxHeight:"100px",overflowY:"auto","& [aria-selected]":{backgroundColor:"#ddd","& u":{textDecoration:"underline"}},"&:focus [aria-selected]":{background_fallback:"#bdf",backgroundColor:"Highlight",color_fallback:"white",color:"HighlightText"},"& u":{textDecoration:"none"},padding:0,margin:0},"& [name=close]":{position:"absolute",top:"0",right:"2px",background:"inherit",border:"none",font:"inherit",padding:0,margin:0}},"&dark .cm-lintRange-active":{backgroundColor:"#86714a80"},"&dark .cm-panel.cm-panel-lint ul":{"& [aria-selected]":{backgroundColor:"#2e343e"}}});function Ce(t){return t=="error"?4:t=="warning"?3:t=="info"?2:1}function ne(t){let e="hint",n=1;for(let i of t){let o=Ce(i.severity);o>n&&(n=o,e=i.severity)}return e}var I=class extends he{constructor(e){super(),this.diagnostics=e,this.severity=ne(e)}toDOM(e){let n=document.createElement("div");n.className="cm-lint-marker cm-lint-marker-"+this.severity;let i=this.diagnostics,o=e.state.facet(B).tooltipFilter;return o&&(i=o(i,e.state)),i.length&&(n.onmouseover=()=>Se(e,n,i)),n}};function Te(t,e){let n=i=>{let o=e.getBoundingClientRect();if(!(i.clientX>o.left-10&&i.clientX<o.right+10&&i.clientY>o.top-10&&i.clientY<o.bottom+10)){for(let s=i.target;s;s=s.parentNode)if(s.nodeType==1&&s.classList.contains("cm-tooltip-lint"))return;window.removeEventListener("mousemove",n),t.state.field(oe)&&t.dispatch({effects:K.of(null)})}};window.addEventListener("mousemove",n)}function Se(t,e,n){function i(){let r=t.elementAtHeight(e.getBoundingClientRect().top+5-t.documentTop);t.coordsAtPos(r.from)&&t.dispatch({effects:K.of({pos:r.from,above:!1,clip:!1,create(){return{dom:Q(t,n),getCoords:()=>e.getBoundingClientRect()}}})}),e.onmouseout=e.onmousemove=null,Te(t,e)}let{hoverTime:o}=t.state.facet(B),s=setTimeout(i,o);e.onmouseout=()=>{clearTimeout(s),e.onmouseout=e.onmousemove=null},e.onmousemove=()=>{clearTimeout(s),s=setTimeout(i,o)}}function Re(t,e){let n=Object.create(null);for(let o of e){let s=t.lineAt(o.from);(n[s.from]||(n[s.from]=[])).push(o)}let i=[];for(let o in n)i.push(new I(n[o]).range(+o));return z.of(i,!0)}var Pe=ae({class:"cm-gutter-lint",markers:t=>t.state.field(H),widgetMarker:(t,e,n)=>{let i=[];return t.state.field(H).between(n.from,n.to,(o,s,r)=>{o>n.from&&o<n.to&&i.push(...r.diagnostics)}),i.length?new I(i):null}}),H=G.define({create(){return z.empty},update(t,e){t=t.map(e.changes);let n=e.state.facet(B).markerFilter;for(let i of e.effects)if(i.is(E)){let o=i.value;n&&(o=n(o||[],e.state)),t=Re(e.state.doc,o.slice(0))}return t}}),K=R.define(),oe=G.define({create(){return null},update(t,e){return t&&e.docChanged&&(t=X(e,t)?null:{...t,pos:e.changes.mapPos(t.pos)}),e.effects.reduce((n,i)=>i.is(K)?i.value:n,t)},provide:t=>ce.from(t)}),Fe=A.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:L('<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>')},".cm-lint-marker-warning":{content:L('<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>')},".cm-lint-marker-error":{content:L('<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>')}}),V=fe(be,{hideOn:X}),se=[p,A.decorations.compute([p],t=>{let{selected:e,panel:n}=t.field(p);return!e||!n||e.from==e.to?T.none:T.set([we.range(e.from,e.to)])}),V,ye],B=Z.define({combine(t){return U(t,{hoverTime:300,markerFilter:null,tooltipFilter:null})}});function He(t={}){return[B.of(t),H,Pe,Fe,oe]}function Ge(t,e){let n=t.field(p,!1);if(n&&n.diagnostics.size){let i=[],o=[],s=-1;for(let r=z.iter([n.diagnostics]);;r.next()){for(let l=0;l<i.length;l++)(!r.value||r.value.spec.diagnostics.indexOf(i[l])<0)&&(e(i[l],o[l],s),i.splice(l,1),o.splice(l--,1));if(!r.value)break;for(let l of r.value.spec.diagnostics)i.indexOf(l)<0&&(i.push(l),o.push(r.from));s=r.to}}}export{N as closeLintPanel,Ie as diagnosticCount,Ge as forEachDiagnostic,Oe as forceLinting,He as lintGutter,Ee as lintKeymap,Be as linter,xe as nextDiagnostic,ke as openLintPanel,Ae as previousDiagnostic,pe as setDiagnostics,E as setDiagnosticsEffect};
//# sourceMappingURL=lint.mjs.map