PageSourceSearch

https://pika.page/assets/@codemirror--lint-84fc926026425151dbfd4db041882b27eb73c6d7c80552ac18f93728a3a44adb.js

js pika.page collected 2026-10-03 21:44:08 UTC 17,093 bytes, 4 lines download raw bytes

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