1// @codemirror/[email protected] downloaded from https://ga.jspm.io/npm:@codemirror/[email protected]/dist/index.js 2 3import{Decoration as e,EditorView as t,hoverTooltip as i,showPanel as n,getPanel as s,ViewPlugin as o,logException as l,WidgetType as r,GutterMarker as a,gutter as c,showTooltip as d}from"@codemirror/view";import{Facet as f,RangeSetBuilder as u,StateEffect as m,StateField as h,combineConfig as g,RangeSet as p}from"@codemirror/state";import v from"crelt";class SelectedDiagnostic{constructor(e,t,i){this.from=e;this.to=t;this.diagnostic=i}}class LintState{constructor(e,t,i){this.diagnostics=e;this.panel=t;this.selected=i}static init(t,i,n){let s=n.facet($).markerFilter;s&&(t=s(t,n));let o=t.slice().sort(((e,t)=>e.from-t.from||e.to-t.to));let l=new u,r=[],a=0;let c=n.doc.iter(),d=0,f=n.doc.length;for(let t=0;;){let i=t==o.length?null:o[t];if(!i&&!r.length)break;let n,s;if(r.length){n=a;s=r.reduce(((e,t)=>Math.min(e,t.to)),i&&i.from>n?i.from:1e8)}else{n=i.from;if(n>f)break;s=i.to;r.push(i);t++}while(t<o.length){let e=o[t];if(e.from!=n||!(e.to>e.from||e.to==n)){s=Math.min(e.from,s);break}r.push(e);t++;s=Math.min(e.to,s)}s=Math.min(s,f);let u=false;if(r.some((e=>e.from==n&&(e.to==s||s==f)))){u=n==s;if(!u&&s-n<10){let e=n-(d+c.value.length);if(e>0){c.next(e);d=n}for(let e=n;;){if(e>=s){u=true;break}if(!c.lineBreak&&d+c.value.length>e)break;e=d+c.value.length;d+=c.value.length;c.next()}}}let m=_(r);if(u)l.add(n,n,e.widget({widget:new DiagnosticWidget(m),diagnostics:r.slice()}));else{let t=r.reduce(((e,t)=>t.markClass?e+" "+t.markClass:e),"");l.add(n,s,e.mark({class:"cm-lintRange cm-lintRange-"+m+t,diagnostics:r.slice(),inclusiveEnd:r.some((e=>e.to>s))}))}a=s;if(a==f)break;for(let e=0;e<r.length;e++)r[e].to<=a&&r.splice(e--,1)}let m=l.finish();return new LintState(m,i,w(m))}}function w(e,t=null,i=0){let n=null;e.between(i,1e9,((e,i,{spec:s})=>{if(!(t&&s.diagnostics.indexOf(t)<0))if(n){if(s.diagnostics.indexOf(n.diagnostic)<0)return false;n=new SelectedDiagnostic(n.from,i,n.diagnostic)}else n=new SelectedDiagnostic(e,i,t||s.diagnostics[0])}));return n}function b(e,t){let i=t.pos,n=t.end||i;let s=e.state.facet($).hideOn(e,i,n);if(s!=null)return s;let o=e.startState.doc.lineAt(t.pos);return!!(e.effects.some((e=>e.is(y)))||e.changes.touchesRange(o.from,Math.max(o.to,n)))}function k(e,t){return e.field(S,false)?t:t.concat(m.appendConfig.of(ie))}function x(e,t){return{effects:k(e,[y.of(t)])}}const y=m.define();const C=m.define();const L=m.define();const S=h.define({create(){return new LintState(e.none,null,null)},update(e,t){if(t.docChanged&&e.diagnostics.size){let i=e.diagnostics.map(t.changes),n=null,s=e.panel;if(e.selected){let s=t.changes.mapPos(e.selected.from,1);n=w(i,e.selected.diagnostic,s)||w(i,null,s)}!i.size&&s&&t.state.facet($).autoPanel&&(s=null);e=new LintState(i,s,n)}for(let i of t.effects)if(i.is(y)){let n=t.state.facet($).autoPanel?i.value.length?LintPanel.open:null:e.panel;e=LintState.init(i.value,n,t.state)}else i.is(C)?e=new LintState(e.diagnostics,i.value?LintPanel.open:null,e.selected):i.is(L)&&(e=new LintState(e.diagnostics,e.panel,i.value));return e},provide:e=>[n.from(e,(e=>e.panel)),t.decorations.from(e,(e=>e.diagnostics))]});function T(e){let t=e.field(S,false);return t?t.diagnostics.size:0}const R=e.mark({class:"cm-lintRange cm-lintRange-active"});function P(e,t,i){let{diagnostics:n}=e.state.field(S);let s,o=-1,l=-1;n.between(t-(i<0?1:0),t+(i>0?1:0),((e,n,{spec:r})=>{if(t>=e&&t<=n&&(e==n||(t>e||i>0)&&(t<n||i<0))){s=r.diagnostics;o=e;l=n;return false}}));let r=e.state.facet($).tooltipFilter;s&&r&&(s=r(s,e.state));return s?{pos:o,end:l,above:e.state.doc.lineAt(o).to<l,create(){return{dom:M(e,s)}}}:null}function M(e,t){return v("ul",{class:"cm-tooltip-lint"},t.map((t=>q(e,t,false))))}const I=e=>{let t=e.state.field(S,false);t&&t.panel||e.dispatch({effects:k(e.state,[C.of(true)])});let i=s(e,LintPanel.open);i&&i.dom.querySelector(".cm-panel-lint ul").focus();return true};const A=e=>{let t=e.state.field(S,false);
3if(!t||!t.panel)return false;e.dispatch({effects:C.of(false)});return true};const D=e=>{let t=e.state.field(S,false);if(!t)return false;let i=e.state.selection.main,n=t.diagnostics.iter(i.to+1);if(!n.value){n=t.diagnostics.iter(0);if(!n.value||n.from==i.from&&n.to==i.to)return false}e.dispatch({selection:{anchor:n.from,head:n.to},scrollIntoView:true});return true};const B=e=>{let{state:t}=e,i=t.field(S,false);if(!i)return false;let n=t.selection.main;let s,o,l,r;i.diagnostics.between(0,t.doc.length,((e,t)=>{if(t<n.to&&(s==null||s<e)){s=e;o=t}if(l==null||e>l){l=e;r=t}}));if(l==null||s==null&&l==n.from)return false;e.dispatch({selection:{anchor:s!==null&&s!==void 0?s:l,head:o!==null&&o!==void 0?o:r},scrollIntoView:true});return true};const O=[{key:"Mod-Shift-m",run:I,preventDefault:true},{key:"F8",run:D}];const F=o.fromClass(class{constructor(e){this.view=e;this.timeout=-1;this.set=true;let{delay:t}=e.state.facet($);this.lintTime=Date.now()+t;this.run=this.run.bind(this);this.timeout=setTimeout(this.run,t)}run(){clearTimeout(this.timeout);let e=Date.now();if(e<this.lintTime-10)this.timeout=setTimeout(this.run,this.lintTime-e);else{this.set=false;let{state:e}=this.view,{sources:t}=e.facet($);t.length&&z(t.map((e=>Promise.resolve(e(this.view)))),(t=>{this.view.state.doc==e.doc&&this.view.dispatch(x(this.view.state,t.reduce(((e,t)=>e.concat(t)))))}),(e=>{l(this.view.state,e)}))}}update(e){let t=e.state.facet($);if(e.docChanged||t!=e.startState.facet($)||t.needsRefresh&&t.needsRefresh(e)){this.lintTime=Date.now()+t.delay;if(!this.set){this.set=true;this.timeout=setTimeout(this.run,t.delay)}}}force(){if(this.set){this.lintTime=Date.now();this.run()}}destroy(){clearTimeout(this.timeout)}});function z(e,t,i){let n=[],s=-1;for(let o of e)o.then((i=>{n.push(i);clearTimeout(s);n.length==e.length?t(n):s=setTimeout((()=>t(n)),200)}),i)}const $=f.define({combine(e){return{sources:e.map((e=>e.source)).filter((e=>e!=null)),...g(e.map((e=>e.config)),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:E,tooltipFilter:E,needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t,hideOn:(e,t)=>e?t?(i,n,s)=>e(i,n,s)||t(i,n,s):e:t,autoPanel:(e,t)=>e||t})}}});function E(e,t){return e?t?(i,n)=>t(e(i,n),n):e:t}function H(e,t={}){return[$.of({source:e,config:t}),F,ie]}function N(e){let t=e.plugin(F);t&&t.force()}function j(e){let t=[];if(e)e:for(let{name:i}of e){for(let e=0;e<i.length;e++){let n=i[e];if(/[a-zA-Z]/.test(n)&&!t.some((e=>e.toLowerCase()==n.toLowerCase()))){t.push(n);continue e}}t.push("")}return t}function q(e,t,i){var n;let s=i?j(t.actions):[];return v("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},v("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(e):t.message),(n=t.actions)===null||n===void 0?void 0:n.map(((i,n)=>{let o=false,l=n=>{n.preventDefault();if(o)return;o=true;let s=w(e.state.field(S).diagnostics,t);s&&i.apply(e,s.from,s.to)};let{name:r}=i,a=s[n]?r.indexOf(s[n]):-1;let c=a<0?r:[r.slice(0,a),v("u",r.slice(a,a+1)),r.slice(a+1)];let d=i.markClass?" "+i.markClass:"";return v("button",{type:"button",class:"cm-diagnosticAction"+d,onclick:l,onmousedown:l,"aria-label":` Action: ${r}${a<0?"":` (access key "${s[n]})"`}.`},c)})),t.source&&v("div",{class:"cm-diagnosticSource"},t.source))}class DiagnosticWidget extends r{constructor(e){super();this.sev=e}eq(e){return e.sev==this.sev}toDOM(){return v("span",{class:"cm-lintPoint cm-lintPoint-"+this.sev})}}class PanelItem{constructor(e,t){this.diagnostic=t;this.id="item_"+Math.floor(Math.random()*4294967295).toString(16);this.dom=q(e,t,true);this.dom.id=this.id;this.dom.setAttribute("role","option")}}class LintPanel{constructor(e){this.view=e;this.items=[];let t=t=>{if(t.keyCode==27){A(this.view);this.view.focus()}else if(t.keyCode==38||t.keyCode==33)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(t.keyCode==40||t.keyCode==34)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(t.keyCode==36)this.moveSelection(0);else if(t.keyCode==35)this.moveSelection(this.items.length-1);else if(t.keyCode==13)this.view.focus();else{if(!(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],n=j(i.actions);for(let s=0;s<n.length;
3s++)if(n[s].toUpperCase().charCodeAt(0)==t.keyCode){let t=w(this.view.state.field(S).diagnostics,i);t&&i.actions[s].apply(e,t.from,t.to)}}}t.preventDefault()};let i=e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)};this.list=v("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t,onclick:i});this.dom=v("div",{class:"cm-panel-lint"},this.list,v("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>A(this.view)},"Ã"));this.update()}get selectedIndex(){let e=this.view.state.field(S).selected;if(!e)return-1;for(let t=0;t<this.items.length;t++)if(this.items[t].diagnostic==e.diagnostic)return t;return-1}update(){let{diagnostics:e,selected:t}=this.view.state.field(S);let i=0,n=false,s=null;let o=new Set;e.between(0,this.view.state.doc.length,((e,l,{spec:r})=>{for(let e of r.diagnostics){if(o.has(e))continue;o.add(e);let l,r=-1;for(let t=i;t<this.items.length;t++)if(this.items[t].diagnostic==e){r=t;break}if(r<0){l=new PanelItem(this.view,e);this.items.splice(i,0,l);n=true}else{l=this.items[r];if(r>i){this.items.splice(i,r-i);n=true}}if(t&&l.diagnostic==t.diagnostic){if(!l.dom.hasAttribute("aria-selected")){l.dom.setAttribute("aria-selected","true");s=l}}else l.dom.hasAttribute("aria-selected")&&l.dom.removeAttribute("aria-selected");i++}}));while(i<this.items.length&&!(this.items.length==1&&this.items[0].diagnostic.from<0)){n=true;this.items.pop()}if(this.items.length==0){this.items.push(new PanelItem(this.view,{from:-1,to:-1,severity:"info",message:this.view.state.phrase("No diagnostics")}));n=true}if(s){this.list.setAttribute("aria-activedescendant",s.id);this.view.requestMeasure({key:this,read:()=>({sel:s.dom.getBoundingClientRect(),panel:this.list.getBoundingClientRect()}),write:({sel:e,panel:t})=>{let i=t.height/this.list.offsetHeight;e.top<t.top?this.list.scrollTop-=(t.top-e.top)/i:e.bottom>t.bottom&&(this.list.scrollTop+=(e.bottom-t.bottom)/i)}})}else this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant");n&&this.sync()}sync(){let e=this.list.firstChild;function t(){let t=e;e=t.nextSibling;t.remove()}for(let i of this.items)if(i.dom.parentNode==this.list){while(e!=i.dom)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);while(e)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=this.view.state.field(S);let i=w(t.diagnostics,this.items[e].diagnostic);i&&this.view.dispatch({selection:{anchor:i.from,head:i.to},scrollIntoView:true,effects:L.of(i)})}static open(e){return new LintPanel(e)}}function G(e,t='viewBox="0 0 40 40"'){return`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" ${t}>${encodeURIComponent(e)}</svg>')`}function V(e){return G(`<path d="m0 2.5 l2 -1.5 l1 0 l2 1.5 l1 0" stroke="${e}" fill="none" stroke-width=".7"/>`,'width="6" height="3"')}const Y=t.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:V("#d11")},".cm-lintRange-warning":{backgroundImage:V("orange")},".cm-lintRange-info":{backgroundImage:V("#999")},".cm-lintRange-hint":{backgroundImage:V("#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}}});
3function Z(e){return e=="error"?4:e=="warning"?3:e=="info"?2:1}function _(e){let t="hint",i=1;for(let n of e){let e=Z(n.severity);if(e>i){i=e;t=n.severity}}return t}class LintGutterMarker extends a{constructor(e){super();this.diagnostics=e;this.severity=_(e)}toDOM(e){let t=document.createElement("div");t.className="cm-lint-marker cm-lint-marker-"+this.severity;let i=this.diagnostics;let n=e.state.facet(ne).tooltipFilter;n&&(i=n(i,e.state));i.length&&(t.onmouseover=()=>W(e,t,i));return t}}function U(e,t){let i=n=>{let s=t.getBoundingClientRect();if(!(n.clientX>s.left-10&&n.clientX<s.right+10&&n.clientY>s.top-10&&n.clientY<s.bottom+10)){for(let e=n.target;e;e=e.parentNode)if(e.nodeType==1&&e.classList.contains("cm-tooltip-lint"))return;window.removeEventListener("mousemove",i);e.state.field(ee)&&e.dispatch({effects:Q.of(null)})}};window.addEventListener("mousemove",i)}function W(e,t,i){function n(){let n=e.elementAtHeight(t.getBoundingClientRect().top+5-e.documentTop);const s=e.coordsAtPos(n.from);s&&e.dispatch({effects:Q.of({pos:n.from,above:false,clip:false,create(){return{dom:M(e,i),getCoords:()=>t.getBoundingClientRect()}}})});t.onmouseout=t.onmousemove=null;U(e,t)}let{hoverTime:s}=e.state.facet(ne);let o=setTimeout(n,s);t.onmouseout=()=>{clearTimeout(o);t.onmouseout=t.onmousemove=null};t.onmousemove=()=>{clearTimeout(o);o=setTimeout(n,s)}}function X(e,t){let i=Object.create(null);for(let n of t){let t=e.lineAt(n.from);(i[t.from]||(i[t.from]=[])).push(n)}let n=[];for(let e in i)n.push(new LintGutterMarker(i[e]).range(+e));return p.of(n,true)}const J=c({class:"cm-gutter-lint",markers:e=>e.state.field(K),widgetMarker:(e,t,i)=>{let n=[];e.state.field(K).between(i.from,i.to,((e,t,s)=>{e>i.from&&e<i.to&&n.push(...s.diagnostics)}));return n.length?new LintGutterMarker(n):null}});const K=h.define({create(){return p.empty},update(e,t){e=e.map(t.changes);let i=t.state.facet(ne).markerFilter;for(let n of t.effects)if(n.is(y)){let s=n.value;i&&(s=i(s||[],t.state));e=X(t.state.doc,s.slice(0))}return e}});const Q=m.define();const ee=h.define({create(){return null},update(e,t){e&&t.docChanged&&(e=b(t,e)?null:{...e,pos:t.changes.mapPos(e.pos)});return t.effects.reduce(((e,t)=>t.is(Q)?t.value:e),e)},provide:e=>d.from(e)});const te=t.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:G('<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>')},".cm-lint-marker-warning":{content:G('<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>')},".cm-lint-marker-error":{content:G('<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>')}});const ie=[S,t.decorations.compute([S],(t=>{let{selected:i,panel:n}=t.field(S);return i&&n&&i.from!=i.to?e.set([R.range(i.from,i.to)]):e.none})),i(P,{hideOn:b}),Y];const ne=f.define({combine(e){return g(e,{hoverTime:300,markerFilter:null,tooltipFilter:null})}});function se(e={}){return[ne.of(e),K,J,te,ee]}function oe(e,t){let i=e.field(S,false);
3if(i&&i.diagnostics.size){let e=[],n=[],s=-1;for(let o=p.iter([i.diagnostics]);;o.next()){for(let i=0;i<e.length;i++)if(!o.value||o.value.spec.diagnostics.indexOf(e[i])<0){t(e[i],n[i],s);e.splice(i,1);n.splice(i--,1)}if(!o.value)break;for(let t of o.value.spec.diagnostics)if(e.indexOf(t)<0){e.push(t);n.push(o.from)}s=o.to}}}export{A as closeLintPanel,T as diagnosticCount,oe as forEachDiagnostic,N as forceLinting,se as lintGutter,O as lintKeymap,H as linter,D as nextDiagnostic,I as openLintPanel,B as previousDiagnostic,x as setDiagnostics,y as setDiagnosticsEffect}; 4
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.