/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
import{ViewPlugin as e,EditorView as t,Decoration as i,hoverTooltip as o,showPanel as s,gutter as n,showTooltip as l,getPanel as r,WidgetType as a,GutterMarker as c,logException as d}from"../../view/dist/index.js";import{StateField as m,Facet as f,combineConfig as u,RangeSet as h,RangeSetBuilder as g,StateEffect as p}from"../../state/dist/index.js";import v from"../../../crelt/index.js";class w{constructor(e,t,i){this.from=e,this.to=t,this.diagnostic=i}}class b{constructor(e,t,i){this.diagnostics=e,this.panel=t,this.selected=i}static init(e,t,o){let s=o.facet(j).markerFilter;s&&(e=s(e,o));let n=e.slice().sort((e,t)=>e.from-t.from||e.to-t.to),l=new g,r=[],a=0,c=o.doc.iter(),d=0,m=o.doc.length;for(let u=0;;){let e,t,o=u==n.length?null:n[u];if(!o&&!r.length)break;if(r.length)e=a,t=r.reduce((e,t)=>Math.min(e,t.to),o&&o.from>e?o.from:1e8);else{if(e=o.from,e>m)break;t=o.to,r.push(o),u++}for(;u<n.length;){let i=n[u];if(i.from!=e||!(i.to>i.from||i.to==e)){t=Math.min(i.from,t);break}r.push(i),u++,t=Math.min(i.to,t)}t=Math.min(t,m);let s=!1;if(r.some(i=>i.from==e&&(i.to==t||t==m))&&(s=e==t,!s&&t-e<10)){let i=e-(d+c.value.length);i>0&&(c.next(i),d=e);for(let o=e;;){if(o>=t){s=!0;break}if(!c.lineBreak&&d+c.value.length>o)break;o=d+c.value.length,d+=c.value.length,c.next()}}let f=V(r);if(s)l.add(e,e,i.widget({widget:new N(f),diagnostics:r.slice()}));else{let o=r.reduce((e,t)=>t.markClass?e+" "+t.markClass:e,"");l.add(e,t,i.mark({class:"cm-lintRange cm-lintRange-"+f+o,diagnostics:r.slice(),inclusiveEnd:r.some(e=>e.to>t)}))}if(a=t,a==m)break;for(let i=0;i<r.length;i++)r[i].to<=a&&r.splice(i--,1)}let f=l.finish();return new b(f,t,k(f))}}function k(e,t=null,i=0){let o=null;return e.between(i,1e9,(e,i,{spec:s})=>{if(!(t&&s.diagnostics.indexOf(t)<0))if(o){if(s.diagnostics.indexOf(o.diagnostic)<0)return!1;o=new w(o.from,i,o.diagnostic)}else o=new w(e,i,t||s.diagnostics[0])}),o}function x(e,t){let i=t.pos,o=t.end||i,s=e.state.facet(j).hideOn(e,i,o);if(null!=s)return s;let n=e.startState.doc.lineAt(t.pos);return!(!e.effects.some(e=>e.is(T))&&!e.changes.touchesRange(n.from,Math.max(n.to,o)))}function y(e,t){return e.field(A,!1)?t:t.concat(p.appendConfig.of(ie))}function C(e,t){return{effects:y(e,[T.of(t)])}}const T=/* @__PURE__ */p.define(),R=/* @__PURE__ */p.define(),S=/* @__PURE__ */p.define(),A=/* @__PURE__ */m.define({create:()=>new b(i.none,null,null),update(e,t){if(t.docChanged&&e.diagnostics.size){let i=e.diagnostics.map(t.changes),o=null,s=e.panel;if(e.selected){let s=t.changes.mapPos(e.selected.from,1);o=k(i,e.selected.diagnostic,s)||k(i,null,s)}!i.size&&s&&t.state.facet(j).autoPanel&&(s=null),e=new b(i,s,o)}for(let i of t.effects)if(i.is(T)){let o=t.state.facet(j).autoPanel?i.value.length?K.open:null:e.panel;e=b.init(i.value,o,t.state)}else i.is(R)?e=new b(e.diagnostics,i.value?K.open:null,e.selected):i.is(S)&&(e=new b(e.diagnostics,e.panel,i.value));return e},provide:e=>[s.from(e,e=>e.panel),t.decorations.from(e,e=>e.diagnostics)]}),L=/* @__PURE__ */i.mark({class:"cm-lintRange cm-lintRange-active"});function M(e,t,i){let o,{diagnostics:s}=e.state.field(A),n=-1,l=-1;s.between(t-(i<0?1:0),t+(i>0?1:0),(e,s,{spec:r})=>{if(t>=e&&t<=s&&(e==s||(t>e||i>0)&&(t<s||i<0)))return o=r.diagnostics,n=e,l=s,!1});let r=e.state.facet(j).tooltipFilter;return o&&r&&(o=r(o,e.state)),o?{pos:n,end:l,above:e.state.doc.lineAt(n).to<l,create:()=>({dom:I(e,o)})}:null}function I(e,t){return v("ul",{class:"cm-tooltip-lint"},t.map(t=>z(e,t,!1)))}const P=e=>{let t=e.state.field(A,!1);t&&t.panel||e.dispatch({effects:y(e.state,[R.of(!0)])});let i=r(e,K.open);return i&&i.dom.querySelector(".cm-panel-lint ul").focus(),!0},B=e=>{let t=e.state.field(A,!1);return!(!t||!t.panel)&&(e.dispatch({effects:R.of(!1)}),!0)},D=e=>{let t=e.state.field(A,!1);if(!t)return!1;let i=e.state.selection.main,o=k(t.diagnostics,null,i.to+1);return!(!o&&(o=k(t.diagnostics,null,0),!o||o.from==i.from&&o.to==i.to))&&(e.dispatch({selection:{anchor:o.from,head:o.to},scrollIntoView:!0}),!0)},F=[{key:"Mod-Shift-m",run:P,preventDefault:!0},{key:"F8",run:D}],O=/* @__PURE__ */e.fromClass(class{constructor(e){this.view=e,this.timeout=-1,this.set=!0;let{delay:t}=e.state.facet(j);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=!1;let{state:e}=this.view,{sources:t}=e.facet(j);t.length&&function(e,t,i){let o=[],s=-1;for(let n of e)n.then(i=>{o.push(i),clearTimeout(s),o.length==e.length?t(o):s=setTimeout(()=>t(o),200)},i)}(t.map(e=>Promise.resolve(e(this.view))),t=>{this.view.state.doc==e.doc&&this.view.dispatch(C(this.view.state,t.reduce((e,t)=>e.concat(t))))},e=>{d(this.view.state,e)})}}update(e){let t=e.state.facet(j);(e.docChanged||t!=e.startState.facet(j)||t.needsRefresh&&t.needsRefresh(e))&&(this.lintTime=Date.now()+t.delay,this.set||(this.set=!0,this.timeout=setTimeout(this.run,t.delay)))}force(){this.set&&(this.lintTime=Date.now(),this.run())}destroy(){clearTimeout(this.timeout)}});const j=/* @__PURE__ */f.define({combine:e=>({sources:e.map(e=>e.source).filter(e=>null!=e),...u(e.map(e=>e.config),{delay:750,markerFilter:null,tooltipFilter:null,needsRefresh:null,hideOn:()=>null},{delay:Math.max,markerFilter:$,tooltipFilter:$,needsRefresh:(e,t)=>e?t?i=>e(i)||t(i):e:t,hideOn:(e,t)=>e?t?(i,o,s)=>e(i,o,s)||t(i,o,s):e:t,autoPanel:(e,t)=>e||t})})});function $(e,t){return e?t?(i,o)=>t(e(i,o),o):e:t}function E(e,t={}){return[j.of({source:e,config:t}),O,ie]}function H(e){let t=[];if(e)e:for(let{name:i}of e){for(let e=0;e<i.length;e++){let o=i[e];if(/[a-zA-Z]/.test(o)&&!t.some(e=>e.toLowerCase()==o.toLowerCase())){t.push(o);continue e}}t.push("")}return t}function z(e,t,i){var o;let s=i?H(t.actions):[];return v("li",{class:"cm-diagnostic cm-diagnostic-"+t.severity},v("span",{class:"cm-diagnosticText"},t.renderMessage?t.renderMessage(e):t.message),null===(o=t.actions)||void 0===o?void 0:o.map((i,o)=>{let n=!1,l=o=>{if(o.preventDefault(),n)return;n=!0;let s=k(e.state.field(A).diagnostics,t);s&&i.apply(e,s.from,s.to)},{name:r}=i,a=s[o]?r.indexOf(s[o]):-1,c=a<0?r:[r.slice(0,a),v("u",r.slice(a,a+1)),r.slice(a+1)],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[o]})"`}.`},c)}),t.source&&v("div",{class:"cm-diagnosticSource"},t.source))}class N extends a{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 q{constructor(e,t){this.diagnostic=t,this.id="item_"+Math.floor(4294967295*Math.random()).toString(16),this.dom=z(e,t,!0),this.dom.id=this.id,this.dom.setAttribute("role","option")}}class K{constructor(e){this.view=e,this.items=[];this.list=v("ul",{tabIndex:0,role:"listbox","aria-label":this.view.state.phrase("Diagnostics"),onkeydown:t=>{if(!(t.ctrlKey||t.altKey||t.metaKey)){if(27==t.keyCode)B(this.view),this.view.focus();else if(38==t.keyCode||33==t.keyCode)this.moveSelection((this.selectedIndex-1+this.items.length)%this.items.length);else if(40==t.keyCode||34==t.keyCode)this.moveSelection((this.selectedIndex+1)%this.items.length);else if(36==t.keyCode)this.moveSelection(0);else if(35==t.keyCode)this.moveSelection(this.items.length-1);else if(13==t.keyCode)this.view.focus();else{if(!(t.keyCode>=65&&t.keyCode<=90&&this.selectedIndex>=0))return;{let{diagnostic:i}=this.items[this.selectedIndex],o=H(i.actions);for(let s=0;s<o.length;s++)if(o[s].toUpperCase().charCodeAt(0)==t.keyCode){let t=k(this.view.state.field(A).diagnostics,i);t&&i.actions[s].apply(e,t.from,t.to)}}}t.preventDefault()}},onclick:e=>{for(let t=0;t<this.items.length;t++)this.items[t].dom.contains(e.target)&&this.moveSelection(t)}}),this.dom=v("div",{class:"cm-panel-lint"},this.list,v("button",{type:"button",name:"close","aria-label":this.view.state.phrase("close"),onclick:()=>B(this.view)},"×")),this.update()}get selectedIndex(){let e=this.view.state.field(A).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(A),i=0,o=!1,s=null,n=/* @__PURE__ */new Set;for(e.between(0,this.view.state.doc.length,(e,l,{spec:r})=>{for(let a of r.diagnostics){if(n.has(a))continue;n.add(a);let e,l=-1;for(let t=i;t<this.items.length;t++)if(this.items[t].diagnostic==a){l=t;break}l<0?(e=new q(this.view,a),this.items.splice(i,0,e),o=!0):(e=this.items[l],l>i&&(this.items.splice(i,l-i),o=!0)),t&&e.diagnostic==t.diagnostic?e.dom.hasAttribute("aria-selected")||(e.dom.setAttribute("aria-selected","true"),s=e):e.dom.hasAttribute("aria-selected")&&e.dom.removeAttribute("aria-selected"),i++}});i<this.items.length&&!(1==this.items.length&&this.items[0].diagnostic.from<0);)o=!0,this.items.pop();0==this.items.length&&(this.items.push(new q(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: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)}})):this.selectedIndex<0&&this.list.removeAttribute("aria-activedescendant"),o&&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){for(;e!=i.dom;)t();e=i.dom.nextSibling}else this.list.insertBefore(i.dom,e);for(;e;)t()}moveSelection(e){if(this.selectedIndex<0)return;let t=k(this.view.state.field(A).diagnostics,this.items[e].diagnostic);t&&this.view.dispatch({selection:{anchor:t.from,head:t.to},scrollIntoView:!0,effects:S.of(t)})}static open(e){return new K(e)}}function Y(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 Z(e){return Y(`<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 _=/* @__PURE__ */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:/* @__PURE__ */Z("#d11")},".cm-lintRange-warning":{backgroundImage:/* @__PURE__ */Z("orange")},".cm-lintRange-info":{backgroundImage:/* @__PURE__ */Z("#999")},".cm-lintRange-hint":{backgroundImage:/* @__PURE__ */Z("#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}}});function U(e){return"error"==e?4:"warning"==e?3:"info"==e?2:1}function V(e){let t="hint",i=1;for(let o of e){let e=U(o.severity);e>i&&(i=e,t=o.severity)}return t}class X extends c{constructor(e){super(),this.diagnostics=e,this.severity=V(e)}toDOM(e){let t=document.createElement("div");t.className="cm-lint-marker cm-lint-marker-"+this.severity;let i=this.diagnostics,o=e.state.facet(oe).tooltipFilter;return o&&(i=o(i,e.state)),i.length&&(t.onmouseover=()=>function(e,t,i){function o(){let o=e.elementAtHeight(t.getBoundingClientRect().top+5-e.documentTop);e.coordsAtPos(o.from)&&e.dispatch({effects:W.of({pos:o.from,above:!1,clip:!1,create:()=>({dom:I(e,i),getCoords:()=>t.getBoundingClientRect()})})}),t.onmouseout=t.onmousemove=null,function(e,t){let i=o=>{let s=t.getBoundingClientRect();if(!(o.clientX>s.left-10&&o.clientX<s.right+10&&o.clientY>s.top-10&&o.clientY<s.bottom+10)){for(let e=o.target;e;e=e.parentNode)if(1==e.nodeType&&e.classList.contains("cm-tooltip-lint"))return;window.removeEventListener("mousemove",i),e.state.field(ee)&&e.dispatch({effects:W.of(null)})}};window.addEventListener("mousemove",i)}(e,t)}let{hoverTime:s}=e.state.facet(oe),n=setTimeout(o,s);t.onmouseout=()=>{clearTimeout(n),t.onmouseout=t.onmousemove=null},t.onmousemove=()=>{clearTimeout(n),n=setTimeout(o,s)}}(e,t,i)),t}}function G(e,t){let i=/* @__PURE__ */Object.create(null);for(let s of t){let t=e.lineAt(s.from);(i[t.from]||(i[t.from]=[])).push(s)}let o=[];for(let s in i)o.push(new X(i[s]).range(+s));return h.of(o,!0)}const J=/* @__PURE__ */n({class:"cm-gutter-lint",markers:e=>e.state.field(Q),widgetMarker:(e,t,i)=>{let o=[];return e.state.field(Q).between(i.from,i.to,(e,t,s)=>{e>i.from&&e<i.to&&o.push(...s.diagnostics)}),o.length?new X(o):null}}),Q=/* @__PURE__ */m.define({create:()=>h.empty,update(e,t){e=e.map(t.changes);let i=t.state.facet(oe).markerFilter;for(let o of t.effects)if(o.is(T)){let s=o.value;i&&(s=i(s||[],t.state)),e=G(t.state.doc,s.slice(0))}return e}}),W=/* @__PURE__ */p.define(),ee=/* @__PURE__ */m.define({create:()=>null,update:(e,t)=>(e&&t.docChanged&&(e=x(t,e)?null:{...e,pos:t.changes.mapPos(e.pos)}),t.effects.reduce((e,t)=>t.is(W)?t.value:e,e)),provide:e=>l.from(e)}),te=/* @__PURE__ */t.baseTheme({".cm-gutter-lint":{width:"1.4em","& .cm-gutterElement":{padding:".2em"}},".cm-lint-marker":{width:"1em",height:"1em"},".cm-lint-marker-info":{content:/* @__PURE__ */Y('<path fill="#aaf" stroke="#77e" stroke-width="6" stroke-linejoin="round" d="M5 5L35 5L35 35L5 35Z"/>')},".cm-lint-marker-warning":{content:/* @__PURE__ */Y('<path fill="#fe8" stroke="#fd7" stroke-width="6" stroke-linejoin="round" d="M20 6L37 35L3 35Z"/>')},".cm-lint-marker-error":{content:/* @__PURE__ */Y('<circle cx="20" cy="20" r="15" fill="#f87" stroke="#f43" stroke-width="6"/>')}}),ie=[A,
/* @__PURE__ */t.decorations.compute([A],e=>{let{selected:t,panel:o}=e.field(A);return t&&o&&t.from!=t.to?i.set([L.range(t.from,t.to)]):i.none}),
/* @__PURE__ */o(M,{hideOn:x}),_],oe=/* @__PURE__ */f.define({combine:e=>u(e,{hoverTime:300,markerFilter:null,tooltipFilter:null})});function se(e={}){return[oe.of(e),Q,J,te,ee]}export{B as closeLintPanel,se as lintGutter,F as lintKeymap,E as linter,D as nextDiagnostic,P as openLintPanel,C as setDiagnostics,T as setDiagnosticsEffect};