@synclineapi/editor 4.0.2 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +217 -4
- package/dist/syncline-editor.es.js +5364 -0
- package/dist/syncline-editor.es.js.map +1 -0
- package/dist/syncline-editor.umd.js +520 -0
- package/dist/syncline-editor.umd.js.map +1 -0
- package/dist/types/index.d.ts +1474 -0
- package/package.json +1 -1
|
@@ -0,0 +1,520 @@
|
|
|
1
|
+
(function(D,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(D=typeof globalThis<"u"?globalThis:D||self,$(D.SynclineEditor={}))})(this,function(D){"use strict";var li=Object.defineProperty;var ci=(D,$,K)=>$ in D?li(D,$,{enumerable:!0,configurable:!0,writable:!0,value:K}):D[$]=K;var v=(D,$,K)=>ci(D,typeof $!="symbol"?$+"":$,K);const Zt={typescript:"//",javascript:"//",css:"//",json:"",markdown:"",text:""},ot=new Set(["function","const","let","var","return","if","else","for","while","class","import","export","default","async","await","new","this","typeof","instanceof","try","catch","finally","throw","extends","interface","type","readonly","private","public","protected","static","override","implements","enum","namespace","declare","abstract","as","from","of","in","void","switch","case","break","continue","do","delete","yield","super","null","true","false","undefined","require","constructor"]),Qt=new Set(["function","const","let","var","return","if","else","for","while","class","import","export","default","async","await","new","this","typeof","instanceof","try","catch","finally","throw","extends","as","from","of","in","void","switch","case","break","continue","do","delete","yield","super","null","true","false","undefined","require","constructor","static"]),te=new Set(["media","keyframes","import","charset","supports","layer","container","namespace","page","static","relative","absolute","fixed","sticky","block","inline","flex","grid","none","contents","table","hidden","visible","scroll","clip","auto","bold","normal","italic","underline","uppercase","lowercase","capitalize","left","right","center","justify","inherit","initial","unset","revert","pointer","default","transparent","solid","dashed","dotted","double","cover","contain","no-repeat","repeat","var","calc","min","max","clamp"]),ee=new Set(["null","true","false"]),yt=new Set,at=new Set(["number","string","boolean","any","never","unknown","object","Promise","Array","Map","Set","Record","Partial","Required","Readonly","HTMLElement","KeyboardEvent","Float64Array","EventListener","Document","Window","Node","Element","Event","MouseEvent","CustomEvent"]),ie=new Set(["number","string","boolean","object","Promise","Array","Map","Set","HTMLElement","KeyboardEvent","Float64Array","EventListener","Document","Window","Node","Element","Event","MouseEvent","CustomEvent"]),se=new Set,ne=new Set,wt=new Set,vt={typescript:ot,javascript:Qt,css:te,json:ee,markdown:yt,text:yt},kt={typescript:at,javascript:ie,css:se,json:ne,markdown:wt,text:wt};function xt(r,t){return{fileId:r,doc:[...t],cur:{row:0,col:0},sel:null,dirty:!1,undoStack:[],redoStack:[],scrollTop:0}}function re(r,t){switch(r.kind){case"insert":t.splice(r.row,0,...r.lines);break;case"delete":t.splice(r.row,r.count);break;case"replace":t.splice(r.row,r.oldLines.length,...r.newLines);break}}function oe(r,t){switch(r.kind){case"insert":t.splice(r.row,r.lines.length);break;case"delete":t.splice(r.row,0,...r.removed);break;case"replace":t.splice(r.row,r.newLines.length,...r.oldLines);break}}function M(r,t=100,s,i,e,n=[],o=[]){const l={op:s,beforeCur:{...i},beforeSel:e?{...e}:null,afterCur:{...r.cur},afterSel:r.sel?{...r.sel}:null,beforeExtra:n.map(a=>({...a,sel:a.sel?{...a.sel}:null})),afterExtra:o.map(a=>({...a,sel:a.sel?{...a.sel}:null}))};r.undoStack.push(l),r.undoStack.length>t&&r.undoStack.shift(),r.redoStack=[],r.dirty=!0}function ae(r){if(!r.undoStack.length)return null;const t=r.undoStack.pop();return r.redoStack.push(t),oe(t.op,r.doc),r.cur={...t.beforeCur},r.sel=t.beforeSel?{...t.beforeSel}:null,t.beforeExtra.map(s=>({...s,sel:s.sel?{...s.sel}:null}))}function le(r){if(!r.redoStack.length)return null;const t=r.redoStack.pop();return r.undoStack.push(t),re(t.op,r.doc),r.cur={...t.afterCur},r.sel=t.afterSel?{...t.afterSel}:null,t.afterExtra.map(s=>({...s,sel:s.sel?{...s.sel}:null}))}function L(r){const{doc:t,cur:s}=r;s.row=Math.max(0,Math.min(t.length-1,s.row)),s.col=Math.max(0,Math.min((t[s.row]??"").length,s.col))}function A(r){const{ar:t,ac:s,fr:i,fc:e}=r;return t<i||t===i&&s<=e?r:{ar:i,ac:e,fr:t,fc:s}}function Ct(r,t,s){if(!r)return null;const i=A(r);return t<i.ar||t>i.fr?null:{start:t===i.ar?i.ac:0,end:t===i.fr?i.fc:s}}function ce(r){if(!r.sel)return 0;const t=A(r.sel);let s=0;for(let i=t.ar;i<=t.fr;i++){const e=r.doc[i]??"",n=i===t.ar?t.ac:0,o=i===t.fr?t.fc:e.length;s+=o-n}return s}function St(r){if(!r.sel)return"";const t=A(r.sel),s=[];for(let i=t.ar;i<=t.fr;i++){const e=r.doc[i]??"";s.push(e.slice(i===t.ar?t.ac:0,i===t.fr?t.fc:e.length))}return s.join(`
|
|
2
|
+
`)}function lt(r,t){const s=Math.min(r.length,t.length);let i=0;for(;i<s&&r[i]===t[i];)i++;if(i===r.length&&i===t.length)return{row:i,oldLines:[],newLines:[]};let e=r.length-1,n=t.length-1;for(;e>i&&n>i&&r[e]===t[n];)e--,n--;return{row:i,oldLines:r.slice(i,e+1),newLines:t.slice(i,n+1)}}function O(r){const t=r.sel;if(!t)return r.cur;const s=A(t),i=(r.doc[s.ar]??"").slice(0,s.ac),e=(r.doc[s.fr]??"").slice(s.fc);return r.doc.splice(s.ar,s.fr-s.ar+1,i+e),r.sel=null,{row:s.ar,col:s.ac}}function de(r,t,s){if(!s||r.length<=t)return[r];const i=[];let e=0;for(;e<r.length;){if(r.length-e<=t){i.push(r.slice(e));break}const n=e+t;let o=-1;for(let l=n;l>e;l--)if(r[l-1]===" "){o=l;break}o===-1?(i.push(r.slice(e,n)),e=n):(i.push(r.slice(e,o)),e=o)}return i}function he(r,t,s){return!s||r.length<=t?1:Math.max(1,Math.ceil(r.length/t))}function Tt(r,t,s,i,e,n){const o=e!==void 0&&n!==void 0,l=e??0,a=n??r.length-1;if(o&&!s&&i.size===0){const g=[],k=[];for(let f=l;f<=a&&f<r.length;f++){const C=r[f]??"";g[f]=[C],k.push({docLine:f,segIdx:0,text:C})}return{segments:g,visualRows:k,docToVisArr:null,totalVisualRows:r.length,windowVisStart:l}}const d=new Array(r.length),c=new Array(r.length),p=[];let h=0,b=-1,m=0;for(let g=0;g<r.length;g++){if(c[g]=h,g>0&&g<=b){d[g]=[r[g]??""];continue}if(o&&g===l&&(m=h),!o||g>=l&&g<=a){const k=de(r[g]??"",t,s);d[g]=k,k.forEach((f,C)=>p.push({docLine:g,segIdx:C,text:f})),h+=k.length}else d[g]=[],h+=he(r[g]??"",t,s);i.has(g)&&(b=i.get(g))}return{segments:d,visualRows:p,docToVisArr:c,totalVisualRows:h,windowVisStart:m}}function z(r,t,s){const i=r.segments[t];if(!i||i.length===0)return{visRow:r.docToVisArr!==null?r.docToVisArr[t]??t:t,colInSeg:0};const e=r.docToVisArr!==null?r.docToVisArr[t]??t:t;let n=s;for(let o=0;o<i.length;o++){if(n<=i[o].length||o===i.length-1)return{visRow:e+o,colInSeg:Math.min(n,i[o].length)};n-=i[o].length}return{visRow:e,colInSeg:0}}function et(r,t,s){var l,a;const i=t-r.windowVisStart,e=r.visualRows[i];if(!e)return r.docToVisArr===null?{row:Math.max(0,Math.min(r.totalVisualRows-1,t)),col:s}:{row:0,col:0};const n=r.segments[e.docLine]??[""];let o=Math.min(s,((l=n[e.segIdx])==null?void 0:l.length)??0);for(let d=0;d<e.segIdx;d++)o+=((a=n[d])==null?void 0:a.length)??0;return{row:e.docLine,col:o}}function Mt(r){return r.split(`
|
|
3
|
+
`)}function I(r){return r.join(`
|
|
4
|
+
`)}function it(r){return(r.match(/^(\s*)/)??["",""])[1]}function st(r){return" ".repeat(Math.max(0,r))}function Et(r){return/[\w$]/.test(r)}function Lt(r,t,s=Et){let i=t;for(;i>0&&s(r[i-1]);)i--;return i}function Rt(r,t,s=Et){let i=t;for(;i<r.length&&s(r[i]);)i++;return i}function ct(r,t){let s=0,i=null;return(...e)=>{const n=Date.now(),o=t-(n-s);o<=0?(i!==null&&(clearTimeout(i),i=null),s=n,r(...e)):i===null&&(i=setTimeout(()=>{s=Date.now(),i=null,r(...e)},o))}}function pe(){return{cursors:[],searchWord:"",lastMatchRow:-1,lastMatchCol:-1}}function It(r,t,s,i){r.cursors.some(n=>n.row===t&&n.col===s)||r.cursors.push({row:t,col:s,sel:i})}function At(r){r.cursors=[],r.searchWord="",r.lastMatchRow=-1,r.lastMatchCol=-1}function ue(r,t,s,i,e){const n=[{row:t,col:s,isPrimary:!0,idx:0},...i.map((c,p)=>({row:c.row,col:c.col,isPrimary:!1,idx:p+1}))];n.sort((c,p)=>p.row!==c.row?p.row-c.row:p.col-c.col);const o=r.map(c=>c);let l=t,a=s;const d=i.map(c=>({...c}));for(const c of n){const p=o[c.row]??"";o[c.row]=p.slice(0,c.col)+e+p.slice(c.col);for(const h of n)h!==c&&h.row===c.row&&h.col>=c.col&&(h.col+=e.length);c.col+=e.length}for(const c of n)c.isPrimary?(l=c.row,a=c.col):(d[c.idx-1].row=c.row,d[c.idx-1].col=c.col);return{doc:o,primaryRow:l,primaryCol:a,extraCursors:d}}function dt(r,t,s,i,e,n){const o=[{row:t,col:s,sel:i,isPrimary:!0,idx:0},...e.map((p,h)=>({row:p.row,col:p.col,sel:p.sel,isPrimary:!1,idx:h+1}))];o.sort((p,h)=>h.row!==p.row?h.row-p.row:h.col-p.col);const l=r.slice();let a=t,d=s;const c=e.map(p=>({...p}));for(const p of o){const h=n(l,p.row,p.col,p.sel);if(!h)continue;const{fromRow:b,fromCol:m,toRow:g,toCol:k}=h;if(b===g){const f=l[b]??"";l[b]=f.slice(0,m)+f.slice(k)}else{const f=l[b]??"",C=l[g]??"";l[b]=f.slice(0,m)+C.slice(k),l.splice(b+1,g-b)}p.isPrimary?(a=b,d=m):(c[p.idx-1].row=b,c[p.idx-1].col=m,c[p.idx-1].sel=null)}return{doc:l,primaryRow:a,primaryCol:d,extraCursors:c}}function fe(r,t,s,i,e){let n=r.searchWord;if(!n){if(e&&e.ar===e.fr&&(n=(t[e.ar]??"").slice(e.ac,e.fc),n))return r.searchWord=n,r.lastMatchRow=e.fr,r.lastMatchCol=e.fc,{word:n,sel:{ar:e.ar,ac:e.ac,fr:e.fr,fc:e.fc},row:e.fr,col:e.fc};const a=t[s]??"",d=Lt(a,i),c=Rt(a,i);return n=a.slice(d,c),n?(r.searchWord=n,r.lastMatchRow=s,r.lastMatchCol=c,{word:n,sel:{ar:s,ac:d,fr:s,fc:c},row:s,col:c}):null}const o=r.lastMatchRow,l=r.lastMatchCol;for(let a=o;a<t.length;a++){const d=t[a]??"";let p=a===o?l:0;for(;p<=d.length-n.length;){const h=d.indexOf(n,p);if(h<0)break;const b=h===0||!/\w/.test(d[h-1]),m=h+n.length>=d.length||!/\w/.test(d[h+n.length]);if(b&&m)return r.lastMatchRow=a,r.lastMatchCol=h+n.length,{word:n,sel:{ar:a,ac:h,fr:a,fc:h+n.length},row:a,col:h+n.length};p=h+1}}for(let a=0;a<=o;a++){const d=t[a]??"",c=a===o?l:d.length;let p=0;for(;p<c;){const h=d.indexOf(n,p);if(h<0||h>=c)break;const b=h===0||!/\w/.test(d[h-1]),m=h+n.length>=d.length||!/\w/.test(d[h+n.length]);if(b&&m)return r.lastMatchRow=a,r.lastMatchCol=h+n.length,{word:n,sel:{ar:a,ac:h,fr:a,fc:h+n.length},row:a,col:h+n.length};p=h+1}}return null}function ht(r,t={}){var c,p;if(t.provideTokens)return t.provideTokens(r,t.language??"typescript");const s=[],i=r.length;let e=0;const n=(h,b,m)=>{m>b&&s.push({cls:h,start:b,end:m})},o=vt[t.language??"typescript"]??ot,l=kt[t.language??"typescript"]??at,a=(c=t.extraKeywords)!=null&&c.size?new Set([...o,...t.extraKeywords]):o,d=(p=t.extraTypes)!=null&&p.size?new Set([...l,...t.extraTypes]):l;for(;e<i;){if(r[e]==="/"&&r[e+1]==="/"){n("cmt",e,i);break}if(r[e]==="*"||r[e]==="/"&&r[e+1]==="*"){n("cmt",e,i);break}if(r[e]==="@"){let h=e+1;for(;h<i&&/\w/.test(r[h]);)h++;n("dec",e,h),e=h;continue}if(r[e]==='"'||r[e]==="'"||r[e]==="`"){const h=r[e];let b=e+1;for(;b<i;){if(r[b]==="\\"){b+=2;continue}if(r[b]===h){b++;break}b++}n("str",e,b),e=b;continue}if(/\d/.test(r[e])&&(e===0||!/\w/.test(r[e-1]))){let h=e;for(;h<i&&/[\d._xXa-fA-F]/.test(r[h]);)h++;n("num",e,h),e=h;continue}if(/[a-zA-Z_$]/.test(r[e])){let h=e;for(;h<i&&/[\w$]/.test(r[h]);)h++;const b=r.slice(e,h);a.has(b)?n("kw",e,h):d.has(b)?n("typ",e,h):h<i&&r[h]==="("?n("fn",e,h):/^[A-Z]/.test(b)&&n("cls",e,h),e=h;continue}if(/[=<>!&|+\-*/%^~?:,;.[\]{}()]/.test(r[e])){n("op",e,e+1),e++;continue}e++}return s}function Ht(r,t){const s=new Array(r.length).fill("");for(const i of t)for(let e=i.start;e<i.end;e++)s[e]=i.cls;return s}class be{constructor(t=5e3){v(this,"_cache",new Map);v(this,"_maxSize");v(this,"_hits",0);v(this,"_misses",0);v(this,"_evictions",0);this._maxSize=t}get metrics(){return{hits:this._hits,misses:this._misses,evictions:this._evictions,size:this._cache.size}}get(t,s){const i=this._cache.get(t);return i&&i.src===s?(this._hits++,i.segs):(this._misses++,null)}set(t,s,i){this._cache.size>=this._maxSize&&(this._cache.delete(this._cache.keys().next().value),this._evictions++),this._cache.set(t,{src:s,segs:i})}invalidateLine(t,s){for(let i=0;i<s;i++)this._cache.delete(`${t}:${i}`)}clear(){this._cache.clear(),this._hits=0,this._misses=0,this._evictions=0}resetMetrics(){this._hits=0,this._misses=0,this._evictions=0}}function B(r,t,s){const i=document.createElement(r);return t&&(i.className=t),i}function q(r){return r.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function nt(r,t=document.documentElement){return getComputedStyle(t).getPropertyValue(r).trim()}function Dt(r,t){const s=r.replace("#",""),i=parseInt(s.slice(0,2),16),e=parseInt(s.slice(2,4),16),n=parseInt(s.slice(4,6),16);return`rgba(${i},${e},${n},${t})`}function pt(r,t,s,i,e){const n=Math.max(0,r*e-s),o=Math.max(0,r*2-i),a=(n>0?t/n:0)*o,d=Math.max(20,s/e*2),c=t/e*2-a;return{mmScroll:a,sliderTop:c,sliderHeight:d}}function ge(r,t,s,i,e){const n=Math.max(0,t*e-s),o=Math.max(0,t*2-i);if(n<=0)return 0;const l=2/e-o/n;if(Math.abs(l)<1e-9){const a=Math.max(20,s/e*2);return Math.max(0,Math.min(n,r/Math.max(1,i-a)*n))}return Math.max(0,Math.min(n,r/l))}function _e(r,t,s,i,e,n){const o=Math.max(0,t*n-i),l=Math.max(0,t*2-e);if(o<=0)return 0;const a=s/o*l,d=(r+a)/2;return Math.max(0,Math.min(o,d*n-i/2))}function ut(r){const t=s=>{const i=r(s);return i.startsWith("#")&&i.length===7?Dt(i,.85):i};return{kw:t("--tok-kw"),fn:t("--tok-fn"),cls:t("--tok-cls"),typ:t("--tok-typ"),str:t("--tok-str"),num:t("--tok-num"),cmt:t("--tok-cmt"),dec:t("--tok-dec"),op:t("--tok-op"),txt:(()=>{const s=r("--text2");return s.startsWith("#")&&s.length===7?Dt(s,.28):"rgba(150,148,140,0.28)"})()}}function me(r){var J,Z,Q,tt;const{canvas:t,doc:s,firstLine:i,lastLine:e,subPx:n,wrapperWidth:o,canvasHeight:l,cursorRow:a,sel:d,findMatches:c,findIdx:p,sliderTop:h,sliderHeight:b,colors:m,getCssVar:g,dpr:k}=r,f=t.getContext("2d");if(!f)return;f.setTransform(k,0,0,k,0,0);const C=g("--mm-bg")||"#0d0d0f",_=g("--mm-dim")||"rgba(0,0,0,.30)",w=g("--mm-edge")||"rgba(255,255,255,.18)",u=g("--mm-slider")||"rgba(255,255,255,.07)",y=g("--sel-bg")||"rgba(110,159,255,.22)",S=g("--cur-line-bg")||"rgba(255,255,255,.05)",x=g("--find-border")||"rgba(234,180,86,.50)",R=g("--find-cur-bg")||"rgba(234,180,86,.80)",P=T=>(T-i)*2;if(f.fillStyle=C,f.fillRect(0,0,o,l),a>=i&&a<e&&(f.fillStyle=S,f.fillRect(0,P(a),o,2)),d){const T=Math.max(i,d.ar),E=Math.min(e-1,d.fr);E>=T&&(f.fillStyle=y,f.fillRect(0,P(T),o,(E-T+1)*2))}for(const T of c){if(T.row<i||T.row>=e)continue;const E=p>=0&&((J=c[p])==null?void 0:J.row)===T.row&&((Z=c[p])==null?void 0:Z.col)===T.col;f.fillStyle=E?R:x,f.fillRect(3+T.col*1.1,P(T.row),Math.max(3,T.len*1.1),2)}const j=Math.floor((o-3)/1.1);for(let T=i;T<e;T++){const E=s[T]??"";if(!E.trim())continue;const H=P(T),W=1.5,U=`${T}:0:none`;let V=((Q=r.tokenCache)==null?void 0:Q.get(U,E))??null;V||(V=ht(E,{language:r.language,provideTokens:r.provideTokens}),(tt=r.tokenCache)==null||tt.set(U,E,V));let F=0;for(const G of V){if(G.start>=j)break;G.start>F&&(f.fillStyle=m.txt,f.fillRect(3+F*1.1,H,(Math.min(G.start,j)-F)*1.1,W));const ai=m[G.cls]??m.txt,Jt=Math.min(G.end,j)-G.start;Jt>0&&(f.fillStyle=ai,f.fillRect(3+G.start*1.1,H,Jt*1.1,W)),F=Math.max(F,Math.min(G.end,j))}const Xt=Math.min(E.length,j);F<Xt&&(f.fillStyle=m.txt,f.fillRect(3+F*1.1,H,(Xt-F)*1.1,W))}const N=h+n,X=N+b;f.fillStyle=_,N>0&&f.fillRect(0,0,o,N),X<l&&f.fillRect(0,X,o,l-X),f.fillStyle=u,f.fillRect(0,N,o,b),f.fillStyle=w,f.fillRect(0,Math.max(0,N),o,1),f.fillRect(0,Math.max(0,X-1),o,1)}function ye(r,t){const s=n=>/[\w$]/.test(n);let i=t;for(;i<r.length&&s(r[i]);)i++;let e=t;for(;e>0&&s(r[e-1]);)e--;if(e===i)return"";if(e>0&&r[e-1]==="."){let n=e-1,o=n;for(;o>0&&s(r[o-1]);)o--;if(o<n)return r.slice(o,i)}return r.slice(e,i)}const we={console:{title:"console",type:"Console",body:"Provides access to the browser's debugging console. Useful for logging, timing, profiling, and inspecting values during development.",language:["typescript","javascript"]},"console.log":{title:"console.log()",type:"(...data: any[]) => void",body:"Outputs a message to the web console. Accepts any number of arguments — objects are logged as expandable trees, primitives as their string form.",language:["typescript","javascript"]},"console.error":{title:"console.error()",type:"(...data: any[]) => void",body:"Logs an error message to the console, typically rendered in red with a stack trace. Use for unrecoverable failures.",language:["typescript","javascript"]},"console.warn":{title:"console.warn()",type:"(...data: any[]) => void",body:"Logs a warning message to the console, typically rendered in yellow. Use for non-fatal issues or deprecation notices.",language:["typescript","javascript"]},"console.info":{title:"console.info()",type:"(...data: any[]) => void",body:"Logs an informational message. Behaves identically to console.log in most environments.",language:["typescript","javascript"]},"console.table":{title:"console.table()",type:"(data: any, columns?: string[]) => void",body:"Displays an array or object as a formatted table in the console. Optionally restrict displayed columns.",language:["typescript","javascript"]},"console.time":{title:"console.time()",type:"(label?: string) => void",body:"Starts a timer with the given label. Call console.timeEnd() with the same label to log the elapsed time.",language:["typescript","javascript"]},"console.timeEnd":{title:"console.timeEnd()",type:"(label?: string) => void",body:"Stops the timer started by console.time() and logs the elapsed duration in milliseconds.",language:["typescript","javascript"]},"console.group":{title:"console.group()",type:"(...label: any[]) => void",body:"Creates a new inline group in the console output, indenting subsequent messages until console.groupEnd() is called.",language:["typescript","javascript"]},"console.groupEnd":{title:"console.groupEnd()",type:"() => void",body:"Closes the current inline group in the console, exiting the indented group created by console.group().",language:["typescript","javascript"]},Math:{title:"Math",type:"namespace Math",body:"A built-in object with properties and methods for mathematical constants and functions. Not a constructor — all properties and methods are static.",language:["typescript","javascript"]},"Math.max":{title:"Math.max()",type:"(...values: number[]) => number",body:"Returns the largest of the given numbers. Returns -Infinity if no arguments, or NaN if any argument is not a number.",language:["typescript","javascript"]},"Math.min":{title:"Math.min()",type:"(...values: number[]) => number",body:"Returns the smallest of the given numbers. Returns Infinity if no arguments, or NaN if any argument is not a number.",language:["typescript","javascript"]},"Math.floor":{title:"Math.floor()",type:"(x: number) => number",body:"Returns the largest integer less than or equal to x. Rounds toward negative infinity.",language:["typescript","javascript"]},"Math.ceil":{title:"Math.ceil()",type:"(x: number) => number",body:"Returns the smallest integer greater than or equal to x. Rounds toward positive infinity.",language:["typescript","javascript"]},"Math.round":{title:"Math.round()",type:"(x: number) => number",body:"Returns the value of x rounded to the nearest integer. Values with a fractional part of exactly 0.5 round up.",language:["typescript","javascript"]},"Math.abs":{title:"Math.abs()",type:"(x: number) => number",body:"Returns the absolute (non-negative) value of x.",language:["typescript","javascript"]},"Math.sqrt":{title:"Math.sqrt()",type:"(x: number) => number",body:"Returns the square root of x. Returns NaN if x is negative.",language:["typescript","javascript"]},"Math.pow":{title:"Math.pow()",type:"(base: number, exponent: number) => number",body:"Returns base raised to the power of exponent. Equivalent to the ** operator.",language:["typescript","javascript"]},"Math.random":{title:"Math.random()",type:"() => number",body:"Returns a pseudo-random floating-point number in the range [0, 1). Not cryptographically secure — use crypto.getRandomValues() for security-sensitive code.",language:["typescript","javascript"]},"Math.PI":{title:"Math.PI",type:"number",body:"The ratio of a circle's circumference to its diameter: approximately 3.14159265358979.",language:["typescript","javascript"]},"Math.trunc":{title:"Math.trunc()",type:"(x: number) => number",body:"Returns the integer part of x by removing any fractional digits. Does not round — simply truncates toward zero.",language:["typescript","javascript"]},"Math.sign":{title:"Math.sign()",type:"(x: number) => number",body:"Returns 1 if x is positive, -1 if x is negative, 0 if x is zero, or NaN if x is not a number.",language:["typescript","javascript"]},"Math.clamp":{title:"Math.clamp()",type:"(value: number, min: number, max: number) => number",body:"Clamps value between min and max. Note: not yet standard — use Math.min(Math.max(value, min), max) for compatibility.",language:["typescript","javascript"]},JSON:{title:"JSON",type:"namespace JSON",body:"Provides methods for parsing and serializing JSON (JavaScript Object Notation). All methods are static.",language:["typescript","javascript"]},"JSON.stringify":{title:"JSON.stringify()",type:"(value: any, replacer?: any, space?: string | number) => string",body:"Converts a JavaScript value to a JSON string. Pass a number or string as the third argument to pretty-print with indentation. Throws on circular references.",language:["typescript","javascript"]},"JSON.parse":{title:"JSON.parse()",type:"(text: string, reviver?: (key: string, value: any) => any) => any",body:"Parses a JSON string and returns the corresponding JavaScript value. Throws SyntaxError if the string is not valid JSON.",language:["typescript","javascript"]},Array:{title:"Array",type:"interface Array<T>",body:"Represents an ordered list of values. Provides methods for traversal, mutation, searching, and transformation.",language:["typescript","javascript"]},"Array.from":{title:"Array.from()",type:"<T>(arrayLike: Iterable<T> | ArrayLike<T>, mapFn?: (v: T, i: number) => T) => T[]",body:"Creates a new Array from an array-like or iterable object (e.g. NodeList, Set, Map, string). Optionally applies a mapping function.",language:["typescript","javascript"]},"Array.isArray":{title:"Array.isArray()",type:"(value: unknown) => value is any[]",body:"Returns true if the given value is an Array. More reliable than instanceof Array across iframe boundaries.",language:["typescript","javascript"]},Object:{title:"Object",type:"interface Object",body:"The base class of all JavaScript objects. Provides static methods for working with object properties, prototypes, and descriptors.",language:["typescript","javascript"]},"Object.keys":{title:"Object.keys()",type:"(obj: object) => string[]",body:"Returns an array of an object's own enumerable string-keyed property names, in insertion order.",language:["typescript","javascript"]},"Object.values":{title:"Object.values()",type:"(obj: object) => any[]",body:"Returns an array of an object's own enumerable string-keyed property values, in insertion order.",language:["typescript","javascript"]},"Object.entries":{title:"Object.entries()",type:"(obj: object) => [string, any][]",body:"Returns an array of [key, value] pairs for all own enumerable string-keyed properties of an object.",language:["typescript","javascript"]},"Object.assign":{title:"Object.assign()",type:"<T, U>(target: T, source: U) => T & U",body:"Copies own enumerable properties from one or more source objects into a target object. Returns the modified target. Does a shallow copy.",language:["typescript","javascript"]},"Object.freeze":{title:"Object.freeze()",type:"<T>(obj: T) => Readonly<T>",body:"Freezes an object — prevents adding, removing, or changing its properties. Returns the same object. Shallow — nested objects are not frozen.",language:["typescript","javascript"]},"Object.create":{title:"Object.create()",type:"(proto: object | null, propertiesObject?: PropertyDescriptorMap) => any",body:"Creates a new object with the specified prototype object and optional property descriptors.",language:["typescript","javascript"]},"Object.fromEntries":{title:"Object.fromEntries()",type:"<T>(entries: Iterable<[string, T]>) => Record<string, T>",body:"Creates an object from an array of [key, value] pairs or any iterable of key-value entries. The inverse of Object.entries().",language:["typescript","javascript"]},Promise:{title:"Promise",type:"interface Promise<T>",body:"Represents an asynchronous operation that will eventually complete (or fail) and produce a value. Use .then(), .catch(), and .finally() to handle outcomes.",language:["typescript","javascript"]},"Promise.all":{title:"Promise.all()",type:"<T>(promises: Iterable<Promise<T>>) => Promise<T[]>",body:"Waits for all promises to resolve and returns an array of results. If any promise rejects, the entire result rejects immediately (fail-fast).",language:["typescript","javascript"]},"Promise.allSettled":{title:"Promise.allSettled()",type:"<T>(promises: Iterable<Promise<T>>) => Promise<PromiseSettledResult<T>[]>",body:'Waits for all promises to settle (resolve or reject) and returns an array of result objects, each with a status of "fulfilled" or "rejected". Never rejects.',language:["typescript","javascript"]},"Promise.race":{title:"Promise.race()",type:"<T>(promises: Iterable<Promise<T>>) => Promise<T>",body:"Returns a promise that resolves or rejects as soon as one of the given promises resolves or rejects, with that value or reason.",language:["typescript","javascript"]},"Promise.resolve":{title:"Promise.resolve()",type:"<T>(value: T | PromiseLike<T>) => Promise<T>",body:"Returns a Promise object that is resolved with the given value. If the value is a thenable, the returned promise follows it.",language:["typescript","javascript"]},"Promise.reject":{title:"Promise.reject()",type:"(reason?: any) => Promise<never>",body:"Returns a Promise that is rejected with the given reason. Useful for creating pre-rejected promises in control flow.",language:["typescript","javascript"]},setTimeout:{title:"setTimeout()",type:"(callback: () => void, delay?: number, ...args: any[]) => number",body:"Executes a function after a specified delay in milliseconds. Returns a timer ID that can be passed to clearTimeout() to cancel.",language:["typescript","javascript"]},clearTimeout:{title:"clearTimeout()",type:"(id: number) => void",body:"Cancels a timeout previously established by setTimeout(), preventing its callback from running.",language:["typescript","javascript"]},setInterval:{title:"setInterval()",type:"(callback: () => void, delay?: number, ...args: any[]) => number",body:"Repeatedly executes a function with a fixed time delay between each call. Returns a timer ID for cancellation via clearInterval().",language:["typescript","javascript"]},clearInterval:{title:"clearInterval()",type:"(id: number) => void",body:"Cancels a repeating timer established by setInterval().",language:["typescript","javascript"]},requestAnimationFrame:{title:"requestAnimationFrame()",type:"(callback: (timestamp: DOMHighResTimeStamp) => void) => number",body:"Schedules a callback to run before the next browser repaint. Ideal for animations — the browser can batch and throttle calls to 60fps or the display refresh rate.",language:["typescript","javascript"]},cancelAnimationFrame:{title:"cancelAnimationFrame()",type:"(id: number) => void",body:"Cancels an animation frame request previously scheduled with requestAnimationFrame().",language:["typescript","javascript"]},queueMicrotask:{title:"queueMicrotask()",type:"(callback: () => void) => void",body:"Queues a microtask to be executed before the next task in the event loop. Runs after the current JavaScript execution but before any setTimeout callbacks.",language:["typescript","javascript"]},fetch:{title:"fetch()",type:"(input: RequestInfo | URL, init?: RequestInit) => Promise<Response>",body:"Fetches a resource from the network. Returns a Promise that resolves to a Response. Use .json(), .text(), or .blob() on the response to read the body.",language:["typescript","javascript"]},parseInt:{title:"parseInt()",type:"(string: string, radix?: number) => number",body:"Parses a string and returns an integer in the specified radix (base). Always provide the radix (typically 10) to avoid unexpected behavior with leading zeros.",language:["typescript","javascript"]},parseFloat:{title:"parseFloat()",type:"(string: string) => number",body:"Parses a string and returns a floating-point number. Returns NaN if the string cannot be converted.",language:["typescript","javascript"]},isNaN:{title:"isNaN()",type:"(value: number) => boolean",body:"Returns true if the value is NaN (Not a Number). Note: coerces the argument to number first — use Number.isNaN() for strict checking without coercion.",language:["typescript","javascript"]},isFinite:{title:"isFinite()",type:"(value: number) => boolean",body:"Returns true if the value is a finite number. Returns false for ±Infinity and NaN. Coerces the argument to number first.",language:["typescript","javascript"]},encodeURIComponent:{title:"encodeURIComponent()",type:"(uriComponent: string | number | boolean) => string",body:"Encodes a URI component by replacing special characters with their UTF-8 escape sequences. Use for encoding query string values before appending to a URL.",language:["typescript","javascript"]},decodeURIComponent:{title:"decodeURIComponent()",type:"(encodedURIComponent: string) => string",body:"Decodes a URI component that was previously encoded with encodeURIComponent(). Throws URIError on malformed sequences.",language:["typescript","javascript"]},structuredClone:{title:"structuredClone()",type:"<T>(value: T, options?: StructuredSerializeOptions) => T",body:"Creates a deep clone of the given value using the structured clone algorithm. Handles cycles, Maps, Sets, Dates, and typed arrays. Does not clone functions or class instances.",language:["typescript","javascript"]},"document.getElementById":{title:"document.getElementById()",type:"(elementId: string) => HTMLElement | null",body:"Returns the first element in the document with the specified ID, or null if not found. IDs must be unique per document.",language:["typescript","javascript"]},"document.querySelector":{title:"document.querySelector()",type:"(selectors: string) => Element | null",body:"Returns the first Element matching the given CSS selector string, or null if no match. Use querySelectorAll() for all matches.",language:["typescript","javascript"]},"document.querySelectorAll":{title:"document.querySelectorAll()",type:"(selectors: string) => NodeListOf<Element>",body:"Returns a static NodeList of all Elements matching the given CSS selector string. Does not update as the document changes.",language:["typescript","javascript"]},"document.createElement":{title:"document.createElement()",type:"<K extends keyof HTMLElementTagNameMap>(tagName: K) => HTMLElementTagNameMap[K]",body:"Creates a new HTML element with the specified tag name. The element is not attached to the DOM until you call appendChild() or similar.",language:["typescript","javascript"]},addEventListener:{title:"addEventListener()",type:"(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions) => void",body:"Registers an event listener on the target element. The listener is called whenever the specified event fires. Remember to call removeEventListener() to clean up.",language:["typescript","javascript"]},removeEventListener:{title:"removeEventListener()",type:"(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions) => void",body:"Removes an event listener previously added with addEventListener(). The listener reference must be the same function object.",language:["typescript","javascript"]},const:{title:"const",type:"keyword",body:"Declares a block-scoped variable that cannot be reassigned. The binding is immutable — but for objects and arrays, their contents can still be mutated.",language:["typescript","javascript"]},let:{title:"let",type:"keyword",body:"Declares a block-scoped variable that can be reassigned. Prefer const for bindings that never change.",language:["typescript","javascript"]},var:{title:"var",type:"keyword",body:"Declares a function-scoped (or globally-scoped) variable. Hoisted to the top of its scope. Prefer const or let in modern code.",language:["typescript","javascript"]},function:{title:"function",type:"keyword",body:"Defines a named function declaration, or introduces a function expression. Function declarations are hoisted; expressions are not.",language:["typescript","javascript"]},class:{title:"class",type:"keyword",body:"Declares a class — a blueprint for creating objects with shared methods and properties. Classes support extends, implements, constructors, getters, setters, and static members.",language:["typescript","javascript"]},async:{title:"async",type:"keyword",body:"Marks a function as asynchronous, making it return a Promise implicitly. Enables the use of the await keyword inside the function body.",language:["typescript","javascript"]},await:{title:"await",type:"keyword",body:"Pauses execution of an async function until the Promise settles, then returns the resolved value. Must be used inside an async function.",language:["typescript","javascript"]},return:{title:"return",type:"keyword",body:"Exits the current function and optionally returns a value to the caller. In an async function, the value is wrapped in a resolved Promise.",language:["typescript","javascript"]},interface:{title:"interface",type:"keyword",body:"Defines a TypeScript interface — a named contract describing the shape of an object. Interfaces can be extended, merged (declaration merging), and implemented by classes.",language:["typescript"]},type:{title:"type",type:"keyword",body:"Declares a TypeScript type alias — a name for any type expression including unions, intersections, tuples, mapped types, and conditional types.",language:["typescript"]},extends:{title:"extends",type:"keyword",body:"Establishes inheritance (class extends Base) or constrains a generic type parameter (T extends object). Also used in conditional types (T extends U ? X : Y).",language:["typescript","javascript"]},implements:{title:"implements",type:"keyword",body:"Declares that a class satisfies the shape of one or more interfaces. TypeScript verifies at compile time that all required members are present.",language:["typescript"]},export:{title:"export",type:"keyword",body:"Makes a declaration (variable, function, class, type, interface) available for import in other modules. Use export default for a single primary export.",language:["typescript","javascript"]},import:{title:"import",type:"keyword",body:"Imports bindings from another module. Supports named imports ({ foo, bar }), default imports (Foo), namespace imports (* as Foo), and side-effect imports.",language:["typescript","javascript"]},typeof:{title:"typeof",type:"keyword",body:'Returns a string describing the type of its operand at runtime ("string", "number", "boolean", "object", "function", "undefined", "symbol", "bigint"). In TypeScript, also used as a type operator to capture the type of a value.',language:["typescript","javascript"]},instanceof:{title:"instanceof",type:"keyword",body:"Tests whether an object has a given constructor in its prototype chain. Returns true if the object is an instance of the constructor.",language:["typescript","javascript"]},new:{title:"new",type:"keyword",body:"Creates a new instance of a class or constructor function. Allocates memory, sets the prototype, calls the constructor with `this` bound to the new object, and returns it.",language:["typescript","javascript"]},throw:{title:"throw",type:"keyword",body:"Throws a user-defined exception, stopping execution of the current function and propagating up the call stack until caught by a try...catch block.",language:["typescript","javascript"]},try:{title:"try...catch...finally",type:"keyword",body:"Wraps code that might throw an exception. The catch block handles errors; the finally block always runs whether or not an error occurred.",language:["typescript","javascript"]},string:{title:"string",type:"primitive type",body:'Represents a sequence of UTF-16 code units. In TypeScript, the string type accepts any text value. Literal types like "hello" narrow to specific string values.',language:["typescript"]},number:{title:"number",type:"primitive type",body:"Represents a double-precision 64-bit IEEE 754 floating-point value. Includes integers, decimals, NaN, and Infinity. TypeScript does not have a separate int type.",language:["typescript"]},boolean:{title:"boolean",type:"primitive type",body:"Represents a logical true or false value. Literal types true and false narrow to specific boolean values.",language:["typescript"]},any:{title:"any",type:"TypeScript type",body:"Disables type checking for a value — allows any operation without compile errors. Avoid using any; prefer unknown when the type is genuinely uncertain.",language:["typescript"]},unknown:{title:"unknown",type:"TypeScript type",body:"The type-safe alternative to any. You cannot perform operations on an unknown value without first narrowing its type with typeof, instanceof, or a type guard.",language:["typescript"]},void:{title:"void",type:"TypeScript type",body:"Represents the absence of a value, typically used as the return type of functions that do not return anything meaningful.",language:["typescript"]},never:{title:"never",type:"TypeScript type",body:"A type with no values — used for functions that never return (throw or infinite loop) and for exhaustive checks in union type switches.",language:["typescript"]},Record:{title:"Record<K, V>",type:"type Record<K extends keyof any, T> = { [P in K]: T }",body:"A utility type that constructs an object type whose keys are of type K and values are of type V. Useful for dictionaries and lookup tables.",language:["typescript"]},Partial:{title:"Partial<T>",type:"type Partial<T> = { [P in keyof T]?: T[P] }",body:"A utility type that makes all properties of T optional. Useful for update payloads, patches, and configuration objects with defaults.",language:["typescript"]},Required:{title:"Required<T>",type:"type Required<T> = { [P in keyof T]-?: T[P] }",body:"A utility type that makes all properties of T required (removes optionality). The inverse of Partial<T>.",language:["typescript"]},Readonly:{title:"Readonly<T>",type:"type Readonly<T> = { readonly [P in keyof T]: T[P] }",body:"A utility type that makes all properties of T readonly. Prevents property reassignment at the type level.",language:["typescript"]},ReturnType:{title:"ReturnType<T>",type:"type ReturnType<T extends (...args: any) => any> = T extends (...args: any) => infer R ? R : any",body:"A utility type that extracts the return type of a function type T.",language:["typescript"]},Omit:{title:"Omit<T, K>",type:"type Omit<T, K extends keyof any> = Pick<T, Exclude<keyof T, K>>",body:"A utility type that constructs a type by picking all properties from T then removing those in K.",language:["typescript"]},Pick:{title:"Pick<T, K>",type:"type Pick<T, K extends keyof T> = { [P in K]: T[P] }",body:"A utility type that constructs a type by picking the set of properties K from T.",language:["typescript"]},NonNullable:{title:"NonNullable<T>",type:"type NonNullable<T> = T extends null | undefined ? never : T",body:"A utility type that removes null and undefined from the type T.",language:["typescript"]},keyof:{title:"keyof",type:"TypeScript type operator",body:'Produces a union type of all property keys of an object type. keyof { a: string; b: number } is "a" | "b".',language:["typescript"]}};function ve(r,t){const s=we[r];return!s||s.language&&!(Array.isArray(s.language)?s.language:[s.language]).includes(t)?null:s}const ke=new Set(["img","input","br","hr","meta","link","area","base","col","embed","param","source","track","wbr"]);function Bt(r){const t=r.trim();if(!t)return null;try{const s=ft(t);return s===t?null:s}catch{return null}}function ft(r){if(r.includes(">")){const s=r.indexOf(">");return bt(r.slice(0,s),ft(r.slice(s+1)))}if(r.includes("+"))return r.split("+").map(s=>ft(s.trim())).join(`
|
|
5
|
+
`);const t=r.match(/^(.+)\*(\d+)$/);if(t){const s=parseInt(t[2],10);return Array.from({length:s},(i,e)=>bt(t[1],`$${e+1}`)).join(`
|
|
6
|
+
`)}return bt(r,"$1")}function bt(r,t){const s=r.match(/#([\w-]+)/),i=r.match(/\.([\w.-]+)/g),e=r.match(/\[([^\]]+)\]/);let n=r.replace(/#[\w-]+/g,"").replace(/\.[\w.-]+/g,"").replace(/\[[^\]]+\]/g,"").trim()||"div",o="";return s&&(o+=` id="${s[1]}"`),i&&(o+=` class="${i.map(l=>l.slice(1)).join(" ")}"`),e&&(o+=` ${e[1]}`),ke.has(n)?`<${n}${o}>`:`<${n}${o}>${t}</${n}>`}function jt(r,t){let s=t;for(;s>0&&/[\w#.[\]*>+{}()$@:-]/.test(r[s-1]);)s--;const i=r.slice(s,t);return i.length<2?null:{abbr:i,start:s}}const xe=[{label:"fn",kind:"snip",detail:"function declaration",description:`Declares a named function.
|
|
7
|
+
|
|
8
|
+
function name(params) {
|
|
9
|
+
// body
|
|
10
|
+
}`,body:`function $1($2) {
|
|
11
|
+
$3
|
|
12
|
+
}`},{label:"afn",kind:"snip",detail:"arrow function",description:`Declares a const arrow function.
|
|
13
|
+
|
|
14
|
+
const name = (params) => {
|
|
15
|
+
// body
|
|
16
|
+
};`,body:`const $1 = ($2) => {
|
|
17
|
+
$3
|
|
18
|
+
};`},{label:"asyncfn",kind:"snip",detail:"async function",description:`Declares an async function returning a Promise.
|
|
19
|
+
|
|
20
|
+
async function name(params): Promise<T> {
|
|
21
|
+
// body
|
|
22
|
+
}`,body:`async function $1($2): Promise<$3> {
|
|
23
|
+
$4
|
|
24
|
+
}`},{label:"cl",kind:"snip",detail:"class declaration",description:`Declares a class with a constructor.
|
|
25
|
+
|
|
26
|
+
class Name {
|
|
27
|
+
constructor(params) { ... }
|
|
28
|
+
}`,body:`class $1 {
|
|
29
|
+
constructor($2) {
|
|
30
|
+
$3
|
|
31
|
+
}
|
|
32
|
+
}`},{label:"forof",kind:"snip",detail:"for…of loop",description:`Iterates over the values of an iterable (array, string, Map, etc.).
|
|
33
|
+
|
|
34
|
+
for (const item of iterable) { ... }`,body:`for (const $1 of $2) {
|
|
35
|
+
$3
|
|
36
|
+
}`},{label:"forin",kind:"snip",detail:"for…in loop",description:`Iterates over the enumerable property keys of an object.
|
|
37
|
+
|
|
38
|
+
for (const key in object) { ... }`,body:`for (const $1 in $2) {
|
|
39
|
+
$3
|
|
40
|
+
}`},{label:"trycatch",kind:"snip",detail:"try / catch block",description:`Wraps code in a try/catch to handle runtime errors.
|
|
41
|
+
|
|
42
|
+
try {
|
|
43
|
+
...
|
|
44
|
+
} catch (error) {
|
|
45
|
+
...
|
|
46
|
+
}`,body:`try {
|
|
47
|
+
$1
|
|
48
|
+
} catch ($2error) {
|
|
49
|
+
$3
|
|
50
|
+
}`},{label:"promise",kind:"snip",detail:"new Promise",description:`Creates a new Promise with resolve and reject handlers.
|
|
51
|
+
|
|
52
|
+
new Promise<T>((resolve, reject) => { ... })`,body:`new Promise<$1>((resolve, reject) => {
|
|
53
|
+
$2
|
|
54
|
+
})`},{label:"imp",kind:"snip",detail:"import statement",description:`Adds a named import from a module.
|
|
55
|
+
|
|
56
|
+
import { name } from 'module';`,body:"import { $1 } from '$2';"},{label:"iface",kind:"snip",detail:"interface (TypeScript)",description:`Declares a TypeScript interface.
|
|
57
|
+
|
|
58
|
+
interface Name {
|
|
59
|
+
field: Type;
|
|
60
|
+
}`,body:`interface $1 {
|
|
61
|
+
$2: $3;
|
|
62
|
+
}`,language:["typescript"]},{label:"ife",kind:"snip",detail:"immediately-invoked function expression",description:`An IIFE — defines and immediately calls a function.
|
|
63
|
+
|
|
64
|
+
((params) => {
|
|
65
|
+
...
|
|
66
|
+
})(args);`,body:`(($1) => {
|
|
67
|
+
$2
|
|
68
|
+
})($3);`},{label:"sw",kind:"snip",detail:"switch statement",description:`A switch/case statement with a default branch.
|
|
69
|
+
|
|
70
|
+
switch (expr) {
|
|
71
|
+
case value:
|
|
72
|
+
...
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
...
|
|
76
|
+
}`,body:`switch ($1) {
|
|
77
|
+
case $2:
|
|
78
|
+
$3
|
|
79
|
+
break;
|
|
80
|
+
default:
|
|
81
|
+
$4
|
|
82
|
+
}`}],Ce=[{label:"flex",kind:"snip",detail:"flexbox container",description:`Sets up a flex container with centered alignment.
|
|
83
|
+
|
|
84
|
+
display: flex;
|
|
85
|
+
align-items: center;
|
|
86
|
+
justify-content: center;`,body:`display: flex;
|
|
87
|
+
align-items: $1center;
|
|
88
|
+
justify-content: $2center;`,language:["css"]},{label:"grid",kind:"snip",detail:"CSS grid",description:`Sets up a CSS grid with equal columns and gap.
|
|
89
|
+
|
|
90
|
+
display: grid;
|
|
91
|
+
grid-template-columns: repeat(3, 1fr);
|
|
92
|
+
gap: 16px;`,body:`display: grid;
|
|
93
|
+
grid-template-columns: $1repeat(3, 1fr);
|
|
94
|
+
gap: $2;`,language:["css"]},{label:"media",kind:"snip",detail:"@media query",description:`A responsive media query breakpoint.
|
|
95
|
+
|
|
96
|
+
@media (max-width: 768px) {
|
|
97
|
+
...
|
|
98
|
+
}`,body:`@media ($1max-width: 768px) {
|
|
99
|
+
$2
|
|
100
|
+
}`,language:["css"]},{label:"anim",kind:"snip",detail:"@keyframes animation",description:`A CSS keyframes animation block.
|
|
101
|
+
|
|
102
|
+
@keyframes name {
|
|
103
|
+
from { ... }
|
|
104
|
+
to { ... }
|
|
105
|
+
}`,body:`@keyframes $1 {
|
|
106
|
+
from { $2 }
|
|
107
|
+
to { $3 }
|
|
108
|
+
}`,language:["css"]},{label:"var",kind:"snip",detail:"CSS custom property",description:`Declares a CSS custom property (variable).
|
|
109
|
+
|
|
110
|
+
--name: value;`,body:"--$1: $2;",language:["css"]}],Se=[{label:"accordion",kind:"snip",detail:"HTML details/summary",description:`An accessible accordion using the native <details> and <summary> elements.
|
|
111
|
+
|
|
112
|
+
<details>
|
|
113
|
+
<summary>Title</summary>
|
|
114
|
+
<div>content</div>
|
|
115
|
+
</details>`,body:`<details>
|
|
116
|
+
<summary>$1Title</summary>
|
|
117
|
+
<div>
|
|
118
|
+
$2
|
|
119
|
+
</div>
|
|
120
|
+
</details>`},{label:"card",kind:"snip",detail:"card component",description:"A generic card component with header, body, and footer sections.",body:`<div class="card">
|
|
121
|
+
<div class="card-header">$1</div>
|
|
122
|
+
<div class="card-body">$2</div>
|
|
123
|
+
<div class="card-footer">$3</div>
|
|
124
|
+
</div>`},{label:"navbar",kind:"snip",detail:"navigation bar",description:`A simple navigation bar with anchor links.
|
|
125
|
+
|
|
126
|
+
<nav class="navbar">
|
|
127
|
+
<a href="#">Home</a> ...
|
|
128
|
+
</nav>`,body:`<nav class="navbar">
|
|
129
|
+
<a href="$1#">Home</a>
|
|
130
|
+
<a href="$2#">About</a>
|
|
131
|
+
<a href="$3#">Contact</a>
|
|
132
|
+
</nav>`},{label:"modal",kind:"snip",detail:"modal dialog",description:`A modal dialog layout with header, body, and footer.
|
|
133
|
+
|
|
134
|
+
<div class="modal">
|
|
135
|
+
<div class="modal-dialog"> ... </div>
|
|
136
|
+
</div>`,body:`<div class="modal">
|
|
137
|
+
<div class="modal-dialog">
|
|
138
|
+
<div class="modal-header">$1</div>
|
|
139
|
+
<div class="modal-body">$2</div>
|
|
140
|
+
<div class="modal-footer">$3</div>
|
|
141
|
+
</div>
|
|
142
|
+
</div>`},{label:"table",kind:"snip",detail:"HTML table",description:`A semantic HTML table with thead and tbody.
|
|
143
|
+
|
|
144
|
+
<table>
|
|
145
|
+
<thead><tr><th>...</th></tr></thead>
|
|
146
|
+
<tbody><tr><td>...</td></tr></tbody>
|
|
147
|
+
</table>`,body:`<table>
|
|
148
|
+
<thead>
|
|
149
|
+
<tr>
|
|
150
|
+
<th>$1</th>
|
|
151
|
+
</tr>
|
|
152
|
+
</thead>
|
|
153
|
+
<tbody>
|
|
154
|
+
<tr>
|
|
155
|
+
<td>$2</td>
|
|
156
|
+
</tr>
|
|
157
|
+
</tbody>
|
|
158
|
+
</table>`}];function Te(r){const t=[...Se];return(r==="typescript"||r==="javascript")&&t.push(...xe.filter(s=>!s.language||(Array.isArray(s.language)?s.language.includes(r):s.language===r))),r==="css"&&t.push(...Ce),t}function Me(r,t,s){let i=t;for(;i>0&&/\w/.test(r[i-1]);)i--;const e=r.slice(i,t);if(!e)return null;const n=s.find(o=>o.kind==="snip"&&o.label===e);return n?{snippet:n,start:i}:null}const gt=[{label:"console.log",kind:"fn",detail:"void"},{label:"console.error",kind:"fn",detail:"void"},{label:"console.warn",kind:"fn",detail:"void"},{label:"console.info",kind:"fn",detail:"void"},{label:"console.table",kind:"fn",detail:"void"},{label:"document.getElementById",kind:"fn",detail:"HTMLElement | null"},{label:"document.querySelector",kind:"fn",detail:"Element | null"},{label:"document.querySelectorAll",kind:"fn",detail:"NodeList"},{label:"document.createElement",kind:"fn",detail:"HTMLElement"},{label:"document.createTextNode",kind:"fn",detail:"Text"},{label:"addEventListener",kind:"fn",detail:"(ev, cb) => void"},{label:"removeEventListener",kind:"fn",detail:"(ev, cb) => void"},{label:"requestAnimationFrame",kind:"fn",detail:"(cb) => number"},{label:"cancelAnimationFrame",kind:"fn",detail:"(id) => void"},{label:"setTimeout",kind:"fn",detail:"(cb, ms) => id"},{label:"clearTimeout",kind:"fn",detail:"(id) => void"},{label:"setInterval",kind:"fn",detail:"(cb, ms) => id"},{label:"clearInterval",kind:"fn",detail:"(id) => void"},{label:"JSON.stringify",kind:"fn",detail:"string"},{label:"JSON.parse",kind:"fn",detail:"any"},{label:"Math.max",kind:"fn",detail:"number"},{label:"Math.min",kind:"fn",detail:"number"},{label:"Math.floor",kind:"fn",detail:"number"},{label:"Math.ceil",kind:"fn",detail:"number"},{label:"Math.round",kind:"fn",detail:"number"},{label:"Math.abs",kind:"fn",detail:"number"},{label:"Math.pow",kind:"fn",detail:"number"},{label:"Math.sqrt",kind:"fn",detail:"number"},{label:"Math.random",kind:"fn",detail:"number"},{label:"Object.keys",kind:"fn",detail:"string[]"},{label:"Object.values",kind:"fn",detail:"any[]"},{label:"Object.entries",kind:"fn",detail:"[string, any][]"},{label:"Object.assign",kind:"fn",detail:"T & U"},{label:"Object.freeze",kind:"fn",detail:"Readonly<T>"},{label:"Object.create",kind:"fn",detail:"object"},{label:"Array.from",kind:"fn",detail:"T[]"},{label:"Array.isArray",kind:"fn",detail:"boolean"},{label:"Promise.all",kind:"fn",detail:"Promise<T[]>"},{label:"Promise.resolve",kind:"fn",detail:"Promise<T>"},{label:"Promise.reject",kind:"fn",detail:"Promise<never>"},{label:"Promise.allSettled",kind:"fn",detail:"Promise<...>"},{label:"parseInt",kind:"fn",detail:"number"},{label:"parseFloat",kind:"fn",detail:"number"},{label:"isNaN",kind:"fn",detail:"boolean"},{label:"isFinite",kind:"fn",detail:"boolean"},{label:"encodeURIComponent",kind:"fn",detail:"string"},{label:"decodeURIComponent",kind:"fn",detail:"string"},{label:"structuredClone",kind:"fn",detail:"T"},{label:"queueMicrotask",kind:"fn",detail:"void"},{label:"fetch",kind:"fn",detail:"Promise<Response>"}],Ee={typescript:gt,javascript:gt,css:[{label:"display",kind:"var",detail:"property"},{label:"position",kind:"var",detail:"property"},{label:"top",kind:"var",detail:"property"},{label:"right",kind:"var",detail:"property"},{label:"bottom",kind:"var",detail:"property"},{label:"left",kind:"var",detail:"property"},{label:"width",kind:"var",detail:"property"},{label:"height",kind:"var",detail:"property"},{label:"min-width",kind:"var",detail:"property"},{label:"max-width",kind:"var",detail:"property"},{label:"min-height",kind:"var",detail:"property"},{label:"max-height",kind:"var",detail:"property"},{label:"z-index",kind:"var",detail:"property"},{label:"overflow",kind:"var",detail:"property"},{label:"overflow-x",kind:"var",detail:"property"},{label:"overflow-y",kind:"var",detail:"property"},{label:"box-sizing",kind:"var",detail:"property"},{label:"flex",kind:"var",detail:"property"},{label:"flex-direction",kind:"var",detail:"property"},{label:"flex-wrap",kind:"var",detail:"property"},{label:"flex-grow",kind:"var",detail:"property"},{label:"flex-shrink",kind:"var",detail:"property"},{label:"flex-basis",kind:"var",detail:"property"},{label:"flex-flow",kind:"var",detail:"property"},{label:"align-items",kind:"var",detail:"property"},{label:"align-content",kind:"var",detail:"property"},{label:"align-self",kind:"var",detail:"property"},{label:"justify-content",kind:"var",detail:"property"},{label:"justify-items",kind:"var",detail:"property"},{label:"justify-self",kind:"var",detail:"property"},{label:"gap",kind:"var",detail:"property"},{label:"row-gap",kind:"var",detail:"property"},{label:"column-gap",kind:"var",detail:"property"},{label:"grid",kind:"var",detail:"property"},{label:"grid-template",kind:"var",detail:"property"},{label:"grid-template-columns",kind:"var",detail:"property"},{label:"grid-template-rows",kind:"var",detail:"property"},{label:"grid-template-areas",kind:"var",detail:"property"},{label:"grid-column",kind:"var",detail:"property"},{label:"grid-row",kind:"var",detail:"property"},{label:"grid-area",kind:"var",detail:"property"},{label:"grid-auto-flow",kind:"var",detail:"property"},{label:"margin",kind:"var",detail:"property"},{label:"margin-top",kind:"var",detail:"property"},{label:"margin-right",kind:"var",detail:"property"},{label:"margin-bottom",kind:"var",detail:"property"},{label:"margin-left",kind:"var",detail:"property"},{label:"padding",kind:"var",detail:"property"},{label:"padding-top",kind:"var",detail:"property"},{label:"padding-right",kind:"var",detail:"property"},{label:"padding-bottom",kind:"var",detail:"property"},{label:"padding-left",kind:"var",detail:"property"},{label:"color",kind:"var",detail:"property"},{label:"font",kind:"var",detail:"property"},{label:"font-family",kind:"var",detail:"property"},{label:"font-size",kind:"var",detail:"property"},{label:"font-weight",kind:"var",detail:"property"},{label:"font-style",kind:"var",detail:"property"},{label:"line-height",kind:"var",detail:"property"},{label:"text-align",kind:"var",detail:"property"},{label:"text-decoration",kind:"var",detail:"property"},{label:"text-transform",kind:"var",detail:"property"},{label:"letter-spacing",kind:"var",detail:"property"},{label:"word-spacing",kind:"var",detail:"property"},{label:"white-space",kind:"var",detail:"property"},{label:"word-break",kind:"var",detail:"property"},{label:"word-wrap",kind:"var",detail:"property"},{label:"text-overflow",kind:"var",detail:"property"},{label:"background",kind:"var",detail:"property"},{label:"background-color",kind:"var",detail:"property"},{label:"background-image",kind:"var",detail:"property"},{label:"background-size",kind:"var",detail:"property"},{label:"background-position",kind:"var",detail:"property"},{label:"background-repeat",kind:"var",detail:"property"},{label:"background-clip",kind:"var",detail:"property"},{label:"background-attachment",kind:"var",detail:"property"},{label:"border",kind:"var",detail:"property"},{label:"border-width",kind:"var",detail:"property"},{label:"border-style",kind:"var",detail:"property"},{label:"border-color",kind:"var",detail:"property"},{label:"border-radius",kind:"var",detail:"property"},{label:"border-top",kind:"var",detail:"property"},{label:"border-right",kind:"var",detail:"property"},{label:"border-bottom",kind:"var",detail:"property"},{label:"border-left",kind:"var",detail:"property"},{label:"outline",kind:"var",detail:"property"},{label:"outline-width",kind:"var",detail:"property"},{label:"outline-style",kind:"var",detail:"property"},{label:"outline-color",kind:"var",detail:"property"},{label:"outline-offset",kind:"var",detail:"property"},{label:"opacity",kind:"var",detail:"property"},{label:"box-shadow",kind:"var",detail:"property"},{label:"text-shadow",kind:"var",detail:"property"},{label:"filter",kind:"var",detail:"property"},{label:"backdrop-filter",kind:"var",detail:"property"},{label:"transform",kind:"var",detail:"property"},{label:"transform-origin",kind:"var",detail:"property"},{label:"transition",kind:"var",detail:"property"},{label:"animation",kind:"var",detail:"property"},{label:"animation-name",kind:"var",detail:"property"},{label:"animation-duration",kind:"var",detail:"property"},{label:"animation-timing-function",kind:"var",detail:"property"},{label:"animation-delay",kind:"var",detail:"property"},{label:"animation-iteration-count",kind:"var",detail:"property"},{label:"animation-fill-mode",kind:"var",detail:"property"},{label:"cursor",kind:"var",detail:"property"},{label:"pointer-events",kind:"var",detail:"property"},{label:"user-select",kind:"var",detail:"property"},{label:"resize",kind:"var",detail:"property"},{label:"visibility",kind:"var",detail:"property"},{label:"content",kind:"var",detail:"property"},{label:"list-style",kind:"var",detail:"property"},{label:"will-change",kind:"var",detail:"property"},{label:"appearance",kind:"var",detail:"property"},{label:"clip-path",kind:"var",detail:"property"},{label:"object-fit",kind:"var",detail:"property"},{label:"object-position",kind:"var",detail:"property"},{label:"scroll-behavior",kind:"var",detail:"property"},{label:"aspect-ratio",kind:"var",detail:"property"},{label:"var",kind:"fn",detail:"css fn"},{label:"calc",kind:"fn",detail:"css fn"},{label:"min",kind:"fn",detail:"css fn"},{label:"max",kind:"fn",detail:"css fn"},{label:"clamp",kind:"fn",detail:"css fn"},{label:"rgb",kind:"fn",detail:"css fn"},{label:"rgba",kind:"fn",detail:"css fn"},{label:"hsl",kind:"fn",detail:"css fn"},{label:"hsla",kind:"fn",detail:"css fn"},{label:"oklch",kind:"fn",detail:"css fn"},{label:"linear-gradient",kind:"fn",detail:"css fn"},{label:"radial-gradient",kind:"fn",detail:"css fn"},{label:"conic-gradient",kind:"fn",detail:"css fn"},{label:"translate",kind:"fn",detail:"css fn"},{label:"scale",kind:"fn",detail:"css fn"},{label:"rotate",kind:"fn",detail:"css fn"},{label:"skew",kind:"fn",detail:"css fn"},{label:"matrix",kind:"fn",detail:"css fn"},{label:"perspective",kind:"fn",detail:"css fn"},{label:"url",kind:"fn",detail:"css fn"},{label:"attr",kind:"fn",detail:"css fn"},{label:"env",kind:"fn",detail:"css fn"},{label:"repeat",kind:"fn",detail:"css fn"},{label:"minmax",kind:"fn",detail:"css fn"},{label:"fit-content",kind:"fn",detail:"css fn"}],json:[],markdown:[],text:[]};function Pt(r,t,s){const i=vt[r]??ot,e=kt[r]??at,n=Ee[r]??gt;return[...[...i,...t].map(o=>({label:o,kind:"kw",detail:"keyword"})),...[...e,...s].map(o=>({label:o,kind:"typ",detail:"type"})),...n]}function Le(r,t){const s=new Set;for(const i of r){const e=i.match(/[a-zA-Z_$][\w$]*/g)??[];for(const n of e)n!==t&&n.length>2&&s.add(n)}return s}function Wt(r,t){return r.language?Array.isArray(r.language)?r.language.includes(t):r.language===t:!0}function Re(r,t,s={},i=0,e=0){if(t.length<2)return[];const n=t.toLowerCase(),{language:o="typescript",extraKeywords:l=[],extraTypes:a=[],completions:d=[],replaceBuiltins:c=!1,maxResults:p=14}=s,h=d.filter(u=>u.kind==="snip"&&!!u.body&&Wt(u,o)),b=d.filter(u=>!(u.kind==="snip"&&u.body)&&Wt(u,o)),m=h.filter(u=>u.label.toLowerCase().startsWith(n));let g;if(s.provideCompletions){const u={line:r[i]??"",col:e,prefix:t,language:o,doc:r};let y;try{y=s.provideCompletions(u)}catch(S){console.error("[syncline-editor] provideCompletions threw an error:",S),y=null}g=y!=null?[...y,...b]:[...c?[]:Pt(o,l,a),...b]}else g=c?b:[...Pt(o,l,a),...b];const k=new Set(g.map(u=>u.label)),f=g.filter(u=>u.label.toLowerCase().startsWith(n)&&u.label!==t),C=new Set(m.map(u=>u.label)),w=[...Le(r,t)].filter(u=>u.toLowerCase().startsWith(n)&&!k.has(u)&&!C.has(u)).slice(0,8).map(u=>({label:u,kind:"var",detail:"in file"}));return[...m,...f.filter(u=>!C.has(u.label)),...w].slice(0,p)}function Ie(r,t,s=!1){let i=t;for(;i>0&&(s?/[\w$.\-]/:/[\w$.]/).test(r[i-1]);)i--;return{prefix:r.slice(i,t),start:i}}function Ae(r,t,s){if(!t)return[];const i=[];for(let e=0;e<r.length;e++){const n=r[e]??"";if(s.useRegex)try{const o=new RegExp(t,s.caseSensitive?"g":"gi");let l;for(;(l=o.exec(n))!==null&&(i.push({row:e,col:l.index,len:l[0].length}),!!l[0].length););}catch{}else{const o=s.caseSensitive?n:n.toLowerCase(),l=s.caseSensitive?t:t.toLowerCase();let a=0;for(;;){const d=o.indexOf(l,a);if(d===-1)break;i.push({row:e,col:d,len:t.length}),a=d+1}}}return i}function He(r,t,s,i){const e=t[s];if(!e)return r;const n=[...r],o=n[e.row]??"";return n[e.row]=o.slice(0,e.col)+i+o.slice(e.col+e.len),n}function De(r,t,s){const i=[...r];for(let e=t.length-1;e>=0;e--){const n=t[e],o=i[n.row]??"";i[n.row]=o.slice(0,n.col)+s+o.slice(n.col+n.len)}return i}function Be(r,t,s){return r.length?(t+s+r.length)%r.length:-1}function je(r,t){const s=r[t]??"";let i=0;for(const e of s)e==="{"?i++:e==="}"&&i--;return i>0}function Pe(r,t){let s=0;for(let i=t;i<r.length;i++)for(const e of r[i]??"")if(e==="{")s++;else if(e==="}"&&(s--,s===0))return i;return null}function We(r,t,s){const i=new Map(r);if(i.has(s))i.delete(s);else{const e=Pe(t,s);e!==null&&e>s&&i.set(s,e)}return i}function $e(r){var J,Z,Q,tt;const{vr:t,visIdx:s,curVisRow:i,wm:e,foldedLines:n,isFoldable:o,opts:l}=r,{docLine:a,segIdx:d,text:c}=t,p=s===i,h=a===((J=e.visualRows[i-e.windowVisStart])==null?void 0:J.docLine),b=d>0,m=((Z=e.segments[a])==null?void 0:Z.slice(0,d).reduce((T,E)=>T+E.length,0))??0,g=r.docSel?Ct(r.docSel,a,((Q=(e.segments[a]??[""])[d])==null?void 0:Q.length)??0):null;let k=null;if(g){const T=((tt=(e.segments[a]??[""])[d])==null?void 0:tt.length)??0,E=Ct(r.docSel,a,T+m);if(E){const H=E.start-m,W=E.end-m;W>0&&H<c.length&&(k={start:Math.max(0,H),end:Math.min(c.length,W)})}}const f=r.findMatches.filter(T=>T.row===a).map(T=>{var U,V;const E=T.col-m,H=T.col+T.len-m;if(H<=0||E>=c.length)return null;const W=r.findIdx>=0&&((U=r.findMatches[r.findIdx])==null?void 0:U.row)===T.row&&((V=r.findMatches[r.findIdx])==null?void 0:V.col)===T.col;return{start:Math.max(0,E),end:Math.min(c.length,H),isCur:W}}).filter(Boolean),C=r.wordHighlights.filter(T=>T.row===a).map(T=>{const E=T.col-m,H=T.col+T.len-m;return H<=0||E>=c.length?null:{start:Math.max(0,E),end:Math.min(c.length,H)}}).filter(Boolean),_=[];if(r.bracketMatch){for(const T of[r.bracketMatch.open,r.bracketMatch.close])if(T.row===a){const E=T.col-m;E>=0&&E<c.length&&_.push({start:E,end:E+1})}}const w=[],u=[];for(const T of r.extraCursors){const E=z(e,T.row,T.col);if(E.visRow===s&&w.push(E.colInSeg),T.sel){const H=Oe(T.sel);if(a>=H.ar&&a<=H.fr){const W=a===H.ar?H.ac-m:-m,U=a===H.fr?H.fc-m:c.length+999;U>0&&W<c.length&&u.push({start:Math.max(0,W),end:Math.min(c.length,U)})}}}const y=Ne(c,l.renderWhitespace),S=p||k||f.length||w.length||C.length||_.length||u.length||r.snippetStopCols.length>0;let x;if(S)x=Fe(y,p?r.curColInSeg:-1,k,f,w,r.snippetStopCols,C,_,u,l.tokeniserOpts);else{const T=`${a}:${d}:${l.renderWhitespace}`;let E=r.tokenCache.get(T,y);E||(E=ht(y,l.tokeniserOpts),r.tokenCache.set(T,y,E)),x=Ue(y,E)||"​"}let R="";if(d===0&&l.showIndentGuides){const T=(c.match(/^(\s*)/)??["",""])[1].length,E=Math.floor(T/l.tabSize);for(let H=1;H<E;H++){const W=l.codePaddingLeft+H*l.tabSize*l.charWidth;R+=`<span class="sl-ig" style="left:${W}px"></span>`}}let P="";if(d===0&&o){const T=n.has(a);P=`<span class="sl-fold-btn" data-row="${a}">${T?"▸":"▾"}</span>`}const j=n.has(a)&&d===0,N=d===0?String(a+1):"";return`<div class="${["sl-er",l.highlightActiveLine&&h?"sl-cur-row":"",b?"sl-wrap-cont":"",j?"sl-folded":""].filter(Boolean).join(" ")}" style="height:${l.lineHeight}px" data-v="${s}" data-doc="${a}"><div class="sl-eg" style="position:relative">${P}<span class="sl-egn">${N}</span></div><div class="sl-el"><span class="sl-cl">${R}${x}</span></div></div>`}function Ne(r,t){if(t==="none")return r;if(t==="all")return r.replace(/ /g,"·").replace(/\t/g,"→");const s=(r.match(/^ +/)??[""])[0].length,i=(r.match(/ +$/)??[""])[0].length;let e=r;return s&&(e="·".repeat(s)+e.slice(s)),i&&(e=e.slice(0,e.length-i)+"·".repeat(i)),e.replace(/\t/g,"→")}function Oe(r){return r.ar<r.fr||r.ar===r.fr&&r.ac<=r.fc?r:{ar:r.fr,ac:r.fc,fr:r.ar,fc:r.ac}}function Ue(r,t){if(!r)return"";const s=Ht(r,t);let i="",e=0,n=s[0];const o=l=>{if(l<=e)return;const a=q(r.slice(e,l));i+=n?`<span class="${n}">${a}</span>`:a};for(let l=1;l<=r.length;l++){const a=l<r.length?s[l]:null;a!==n&&(o(l),e=l,n=a??"")}return i}function Fe(r,t,s,i,e,n,o,l,a,d){if(r.length===0){let f=t>=0?'<span class="sl-cur"></span>':"";for(const C of e)f+='<span class="sl-cur-extra"></span>';for(const C of n)f+='<span class="sl-snip-stop"></span>';return f||"​"}const c=ht(r,d),p=Ht(r,c);let h="",b=0,m="",g="";const k=f=>{if(f<=b)return;const C=q(r.slice(b,f)),_=[m,g].filter(Boolean).join(" ");h+=_?`<span class="${_}">${C}</span>`:C};for(let f=0;f<=r.length;f++){t===f&&(k(f),b=f,h+='<span class="sl-cur"></span>');for(const x of e)x===f&&(k(f),b=f,h+='<span class="sl-cur-extra"></span>');for(const x of n)x===f&&(k(f),b=f,h+='<span class="sl-snip-stop"></span>');if(f===r.length){k(f);break}const C=p[f],_=i.find(x=>f>=x.start&&f<x.end),w=s&&f>=s.start&&f<s.end||a.some(x=>f>=x.start&&f<x.end),u=!w&&!_&&o.some(x=>f>=x.start&&f<x.end),y=!w&&!_&&l.some(x=>f>=x.start&&f<x.end);let S="";w?S="sl-sh":_?S="sl-fh"+(_.isCur?" sl-fh-cur":""):y?S="sl-bm":u&&(S="sl-wh"),(S!==m||C!==g)&&(k(f),b=f,m=S,g=C)}return h||"​"}const _t={"(":")","{":"}","[":"]"},mt={")":"(","}":"{","]":"["};function Ge(r,t){const{row:s,col:i}=t,e=r[s]??"";let n=e[i],o=i;if(!_t[n]&&!mt[n]&&(n=e[i-1],o=i-1),!n)return null;if(_t[n]){const l=_t[n];let a=0;for(let d=s;d<Math.min(r.length,s+500);d++){const c=r[d]??"",p=d===s?o:0;for(let h=p;h<c.length;h++)if(c[h]===n)a++;else if(c[h]===l&&(a--,a===0))return{open:{row:s,col:o},close:{row:d,col:h}}}}else if(mt[n]){const l=mt[n];let a=0;for(let d=s;d>=Math.max(0,s-500);d--){const c=r[d]??"",p=d===s?o:c.length-1;for(let h=p;h>=0;h--)if(c[h]===n)a++;else if(c[h]===l&&(a--,a===0))return{open:{row:d,col:h},close:{row:s,col:o}}}}return null}function ze(r,t,s,i,e=0,n=r.length-1){if(i)return[];const o=r[t]??"",l=Lt(o,s),a=Rt(o,s),d=o.slice(l,a);if(!d||d.length<2)return[];const c=[],p=Math.min(n,r.length-1);for(let h=Math.max(0,e);h<=p;h++){const b=r[h]??"";let m=0;for(;m<=b.length-d.length;){const g=b.indexOf(d,m);if(g<0)break;const k=g===0||!/\w/.test(b[g-1]),f=g+d.length>=b.length||!/\w/.test(b[g+d.length]);k&&f&&!(h===t&&g===l)&&c.push({row:h,col:g,len:d.length}),m=g+1}}return c}const $t={id:"",name:"VR Dark",description:"Default deep dark theme",light:!1,tokens:{bg0:"#0d0d0f",bg1:"#111115",bg2:"#16161b",bg3:"#1d1d24",bg4:"#24242d",border:"rgba(255,255,255,.07)",border2:"rgba(255,255,255,.12)",border3:"rgba(255,255,255,.19)",text:"#c9c7c0",text2:"#8b8994",text3:"#4e4c58",accent:"#6e9fff",accent2:"#2f5db0",green:"#4ec9a0",orange:"#d4976e",purple:"#b48eff",red:"#f28b82",yellow:"#e8c97a",cur:"#6e9fff",curGlow:"rgba(110,159,255,.65)",curLineBg:"rgba(255,255,255,.032)",curLineGutter:"#181820",gutterBg:"#0f0f12",gutterHover:"#181820",gutterBorder:"rgba(255,255,255,.06)",gutterNum:"#4e4c58",gutterNumAct:"#9997a2",selBg:"rgba(110,159,255,.22)",wordHlBg:"rgba(200,198,210,.09)",wordHlBorder:"rgba(200,198,210,.28)",bmBorder:"rgba(110,159,255,.65)",foldBg:"rgba(110,159,255,.07)",foldBorder:"rgba(110,159,255,.30)",findBg:"rgba(234,180,86,.18)",findBorder:"rgba(234,180,86,.50)",findCurBg:"rgba(234,180,86,.80)",findCurBorder:"rgba(234,180,86,.95)",findCurText:"#1a1000",fileActiveBg:"rgba(110,159,255,.11)",fileActiveText:"#6e9fff",mmBg:"#0d0d0f",mmSlider:"rgba(255,255,255,.07)",mmDim:"rgba(0,0,0,.30)",mmEdge:"rgba(255,255,255,.18)",indentGuide:"rgba(255,255,255,.06)",tokKw:"#6e9fff",tokStr:"#4ec9a0",tokCmt:"#4e4c58",tokFn:"#d4976e",tokNum:"#b48eff",tokCls:"#e8c97a",tokOp:"#55536a",tokTyp:"#6ec9d4",tokDec:"#f28b82"}},Nt={id:"vscode-dark",name:"VSCode Dark+",description:"Visual Studio Code dark",light:!1,tokens:{bg0:"#1e1e1e",bg1:"#252526",bg2:"#1e1e1e",bg3:"#2d2d30",bg4:"#3a3a3d",border:"rgba(255,255,255,.09)",border2:"rgba(255,255,255,.15)",border3:"rgba(255,255,255,.24)",text:"#d4d4d4",text2:"#9a9a9a",text3:"#505050",accent:"#569cd6",accent2:"#0e639c",green:"#4ec9b0",orange:"#ce9178",purple:"#c586c0",red:"#f44747",yellow:"#dcdcaa",cur:"#aeafad",curGlow:"rgba(174,175,173,.40)",curLineBg:"rgba(255,255,255,.038)",curLineGutter:"#282828",gutterBg:"#1e1e1e",gutterHover:"#282828",gutterBorder:"rgba(255,255,255,.07)",gutterNum:"#838383",gutterNumAct:"#c8c8c8",selBg:"rgba(38,79,120,.65)",wordHlBg:"rgba(173,214,255,.06)",wordHlBorder:"rgba(173,214,255,.28)",bmBorder:"rgba(86,156,214,.70)",foldBg:"rgba(86,156,214,.07)",foldBorder:"rgba(86,156,214,.35)",findBg:"rgba(255,215,0,.13)",findBorder:"rgba(255,215,0,.52)",findCurBg:"#f6f6a0",findCurBorder:"#d4d400",findCurText:"#000",fileActiveBg:"rgba(255,255,255,.07)",fileActiveText:"#d4d4d4",mmBg:"#1e1e1e",mmSlider:"rgba(255,255,255,.07)",mmDim:"rgba(0,0,0,.32)",mmEdge:"rgba(255,255,255,.20)",indentGuide:"rgba(255,255,255,.07)",tokKw:"#569cd6",tokStr:"#ce9178",tokCmt:"#6a9955",tokFn:"#dcdcaa",tokNum:"#b5cea8",tokCls:"#4ec9b0",tokOp:"#d4d4d4",tokTyp:"#4ec9b0",tokDec:"#9cdcfe"}},Ot={id:"monokai",name:"Monokai",description:"Classic Sublime Text theme",light:!1,tokens:{bg0:"#272822",bg1:"#1e1f1c",bg2:"#272822",bg3:"#3a3930",bg4:"#48473d",border:"rgba(255,255,255,.08)",border2:"rgba(255,255,255,.13)",border3:"rgba(255,255,255,.20)",text:"#f8f8f2",text2:"#a8a7a0",text3:"#58574e",accent:"#a6e22e",accent2:"#3d5a10",green:"#a6e22e",orange:"#fd971f",purple:"#ae81ff",red:"#f92672",yellow:"#e6db74",cur:"#f8f8f2",curGlow:"rgba(248,248,242,.25)",curLineBg:"rgba(255,255,255,.042)",curLineGutter:"#2c2d27",gutterBg:"#1e1f1c",gutterHover:"#2c2d27",gutterBorder:"rgba(255,255,255,.06)",gutterNum:"#6e6d64",gutterNumAct:"#cccac0",selBg:"rgba(73,72,62,.80)",wordHlBg:"rgba(248,248,242,.06)",wordHlBorder:"rgba(248,248,242,.22)",bmBorder:"rgba(166,226,46,.65)",foldBg:"rgba(166,226,46,.07)",foldBorder:"rgba(166,226,46,.30)",findBg:"rgba(230,219,116,.16)",findBorder:"rgba(230,219,116,.52)",findCurBg:"#e6db74",findCurBorder:"#c9be50",findCurText:"#272822",fileActiveBg:"rgba(166,226,46,.10)",fileActiveText:"#a6e22e",mmBg:"#1e1f1c",mmSlider:"rgba(255,255,255,.06)",mmDim:"rgba(0,0,0,.32)",mmEdge:"rgba(255,255,255,.18)",indentGuide:"rgba(255,255,255,.06)",tokKw:"#f92672",tokStr:"#e6db74",tokCmt:"#75715e",tokFn:"#a6e22e",tokNum:"#ae81ff",tokCls:"#66d9e8",tokOp:"#f8f8f2",tokTyp:"#66d9e8",tokDec:"#fd971f"}},Ut={id:"dracula",name:"Dracula",description:"Purple-tinted dark theme",light:!1,tokens:{bg0:"#282a36",bg1:"#21222c",bg2:"#282a36",bg3:"#333545",bg4:"#44475a",border:"rgba(255,255,255,.08)",border2:"rgba(255,255,255,.14)",border3:"rgba(255,255,255,.22)",text:"#f8f8f2",text2:"#b2b5c8",text3:"#5a5e78",accent:"#bd93f9",accent2:"#5b3fa8",green:"#50fa7b",orange:"#ffb86c",purple:"#bd93f9",red:"#ff5555",yellow:"#f1fa8c",cur:"#f8f8f2",curGlow:"rgba(189,147,249,.55)",curLineBg:"rgba(255,255,255,.045)",curLineGutter:"#2f3144",gutterBg:"#21222c",gutterHover:"#2f3144",gutterBorder:"rgba(255,255,255,.07)",gutterNum:"#5e638a",gutterNumAct:"#f8f8f2",selBg:"rgba(68,71,90,.85)",wordHlBg:"rgba(248,248,242,.05)",wordHlBorder:"rgba(248,248,242,.20)",bmBorder:"rgba(189,147,249,.70)",foldBg:"rgba(189,147,249,.08)",foldBorder:"rgba(189,147,249,.35)",findBg:"rgba(241,250,140,.14)",findBorder:"rgba(241,250,140,.52)",findCurBg:"#f1fa8c",findCurBorder:"#d4dc50",findCurText:"#282a36",fileActiveBg:"rgba(189,147,249,.12)",fileActiveText:"#bd93f9",mmBg:"#21222c",mmSlider:"rgba(255,255,255,.07)",mmDim:"rgba(0,0,0,.32)",mmEdge:"rgba(255,255,255,.20)",indentGuide:"rgba(255,255,255,.07)",tokKw:"#ff79c6",tokStr:"#f1fa8c",tokCmt:"#6272a4",tokFn:"#50fa7b",tokNum:"#bd93f9",tokCls:"#8be9fd",tokOp:"#f8f8f2",tokTyp:"#8be9fd",tokDec:"#ffb86c"}},Ft={id:"github-light",name:"GitHub Light",description:"GitHub's clean light theme",light:!0,tokens:{bg0:"#ffffff",bg1:"#f6f8fa",bg2:"#ffffff",bg3:"#f0f3f6",bg4:"#e7eaee",border:"#d0d7de",border2:"#bdc4cc",border3:"#aab1ba",text:"#1f2328",text2:"#57606a",text3:"#8c959f",accent:"#0969da",accent2:"#0550ae",green:"#1a7f37",orange:"#bc4c00",purple:"#8250df",red:"#cf222e",yellow:"#7d4e00",cur:"#0969da",curGlow:"rgba(9,105,218,.30)",curLineBg:"rgba(9,105,218,.055)",curLineGutter:"#ebf0f8",gutterBg:"#f6f8fa",gutterHover:"#eaedf1",gutterBorder:"#d0d7de",gutterNum:"#9da5b0",gutterNumAct:"#1f2328",selBg:"rgba(9,105,218,.15)",wordHlBg:"rgba(9,105,218,.07)",wordHlBorder:"rgba(9,105,218,.28)",bmBorder:"rgba(9,105,218,.60)",foldBg:"rgba(9,105,218,.06)",foldBorder:"rgba(9,105,218,.28)",findBg:"rgba(180,100,0,.09)",findBorder:"rgba(180,100,0,.42)",findCurBg:"rgba(180,100,0,.75)",findCurBorder:"rgba(180,100,0,.95)",findCurText:"#fff",fileActiveBg:"rgba(9,105,218,.09)",fileActiveText:"#0969da",mmBg:"#f6f8fa",mmSlider:"rgba(0,0,0,.06)",mmDim:"rgba(0,0,0,.055)",mmEdge:"rgba(0,0,0,.18)",indentGuide:"rgba(0,0,0,.09)",tokKw:"#cf222e",tokStr:"#0a3069",tokCmt:"#6e7781",tokFn:"#8250df",tokNum:"#0550ae",tokCls:"#953800",tokOp:"#1f2328",tokTyp:"#0550ae",tokDec:"#0969da"}},Gt={id:"solarized-light",name:"Solarized Light",description:"Warm precision light theme",light:!0,tokens:{bg0:"#fdf6e3",bg1:"#eee8d5",bg2:"#fdf6e3",bg3:"#e5dfcc",bg4:"#dad4c1",border:"#cdc7b4",border2:"#bab4a2",border3:"#a9a390",text:"#002b36",text2:"#586e75",text3:"#93a1a1",accent:"#268bd2",accent2:"#1a6fa8",green:"#859900",orange:"#cb4b16",purple:"#6c71c4",red:"#dc322f",yellow:"#b58900",cur:"#268bd2",curGlow:"rgba(38,139,210,.32)",curLineBg:"rgba(38,139,210,.07)",curLineGutter:"#e2dcc8",gutterBg:"#eee8d5",gutterHover:"#e2dcc8",gutterBorder:"#cdc7b4",gutterNum:"#93a1a1",gutterNumAct:"#002b36",selBg:"rgba(38,139,210,.18)",wordHlBg:"rgba(38,139,210,.08)",wordHlBorder:"rgba(38,139,210,.28)",bmBorder:"rgba(38,139,210,.58)",foldBg:"rgba(38,139,210,.07)",foldBorder:"rgba(38,139,210,.28)",findBg:"rgba(181,137,0,.11)",findBorder:"rgba(181,137,0,.42)",findCurBg:"rgba(181,137,0,.75)",findCurBorder:"rgba(181,137,0,.95)",findCurText:"#fff",fileActiveBg:"rgba(38,139,210,.10)",fileActiveText:"#268bd2",mmBg:"#eee8d5",mmSlider:"rgba(0,0,0,.06)",mmDim:"rgba(0,0,0,.055)",mmEdge:"rgba(0,0,0,.16)",indentGuide:"rgba(0,0,0,.08)",tokKw:"#859900",tokStr:"#2aa198",tokCmt:"#93a1a1",tokFn:"#268bd2",tokNum:"#d33682",tokCls:"#b58900",tokOp:"#657b83",tokTyp:"#268bd2",tokDec:"#cb4b16"}},zt={id:"mdx-dark",name:"MDX Dark",description:"Catppuccin Mocha — matches .smdx-dark MDX editor chrome, single-colour tokens",light:!1,tokens:{bg0:"#181825",bg1:"#1e1e2e",bg2:"#1e1e2e",bg3:"#2a2a3c",bg4:"#313147",border:"#374151",border2:"rgba(129,140,248,.22)",border3:"rgba(129,140,248,.40)",text:"#e2e8f0",text2:"#94a3b8",text3:"#475569",accent:"#818cf8",accent2:"#6366f1",green:"#c3e88d",orange:"#f78c6c",purple:"#c792ea",red:"#f07178",yellow:"#ffcb6b",cur:"#818cf8",curGlow:"rgba(129,140,248,.55)",curLineBg:"rgba(129,140,248,.055)",curLineGutter:"#252540",gutterBg:"#181825",gutterHover:"#252540",gutterBorder:"#374151",gutterNum:"#475569",gutterNumAct:"#94a3b8",selBg:"rgba(129,140,248,.24)",wordHlBg:"rgba(226,232,240,.07)",wordHlBorder:"rgba(226,232,240,.25)",bmBorder:"rgba(137,221,255,.70)",foldBg:"rgba(129,140,248,.07)",foldBorder:"rgba(129,140,248,.30)",findBg:"rgba(251,191,36,.16)",findBorder:"rgba(251,191,36,.50)",findCurBg:"rgba(251,191,36,.85)",findCurBorder:"rgba(251,191,36,.95)",findCurText:"#1a1000",fileActiveBg:"rgba(129,140,248,.12)",fileActiveText:"#818cf8",mmBg:"#181825",mmSlider:"rgba(255,255,255,.07)",mmDim:"rgba(0,0,0,.30)",mmEdge:"rgba(255,255,255,.18)",indentGuide:"rgba(255,255,255,.06)",tokKw:"#e2e8f0",tokStr:"#e2e8f0",tokCmt:"#e2e8f0",tokFn:"#e2e8f0",tokNum:"#e2e8f0",tokCls:"#e2e8f0",tokOp:"#e2e8f0",tokTyp:"#e2e8f0",tokDec:"#e2e8f0"}},Vt={id:"mdx-light",name:"MDX Light",description:"Clean light — matches default .smdx-editor MDX chrome, single-colour tokens",light:!0,tokens:{bg0:"#f1f5f9",bg1:"#ffffff",bg2:"#ffffff",bg3:"#f8fafc",bg4:"#f1f5f9",border:"#e2e8f0",border2:"rgba(99,102,241,.20)",border3:"rgba(99,102,241,.40)",text:"#1e293b",text2:"#64748b",text3:"#94a3b8",accent:"#6366f1",accent2:"#4f46e5",green:"#15803d",orange:"#c2410c",purple:"#7c3aed",red:"#dc2626",yellow:"#b45309",cur:"#6366f1",curGlow:"rgba(99,102,241,.35)",curLineBg:"rgba(99,102,241,.05)",curLineGutter:"#eef2ff",gutterBg:"#f8fafc",gutterHover:"#eef2ff",gutterBorder:"#e2e8f0",gutterNum:"#94a3b8",gutterNumAct:"#475569",selBg:"rgba(99,102,241,.18)",wordHlBg:"rgba(99,102,241,.07)",wordHlBorder:"rgba(99,102,241,.30)",bmBorder:"rgba(14,116,144,.60)",foldBg:"rgba(99,102,241,.06)",foldBorder:"rgba(99,102,241,.28)",findBg:"rgba(180,83,9,.09)",findBorder:"rgba(180,83,9,.40)",findCurBg:"rgba(180,83,9,.75)",findCurBorder:"rgba(180,83,9,.95)",findCurText:"#ffffff",fileActiveBg:"rgba(99,102,241,.10)",fileActiveText:"#6366f1",mmBg:"#f8fafc",mmSlider:"rgba(0,0,0,.06)",mmDim:"rgba(0,0,0,.05)",mmEdge:"rgba(0,0,0,.18)",indentGuide:"rgba(0,0,0,.08)",tokKw:"#1e293b",tokStr:"#1e293b",tokCmt:"#1e293b",tokFn:"#1e293b",tokNum:"#1e293b",tokCls:"#1e293b",tokOp:"#1e293b",tokTyp:"#1e293b",tokDec:"#1e293b"}},Kt=[$t,Nt,Ot,Ut,Ft,Gt,zt,Vt],Ve={bg0:"--bg0",bg1:"--bg1",bg2:"--bg2",bg3:"--bg3",bg4:"--bg4",border:"--border",border2:"--border2",border3:"--border3",text:"--text",text2:"--text2",text3:"--text3",accent:"--accent",accent2:"--accent2",green:"--green",orange:"--orange",purple:"--purple",red:"--red",yellow:"--yellow",cur:"--cur",curGlow:"--cur-glow",curLineBg:"--cur-line-bg",curLineGutter:"--cur-line-gutter",gutterBg:"--gutter-bg",gutterHover:"--gutter-hover",gutterBorder:"--gutter-border",gutterNum:"--gutter-num",gutterNumAct:"--gutter-num-act",selBg:"--sel-bg",wordHlBg:"--word-hl-bg",wordHlBorder:"--word-hl-border",bmBorder:"--bm-border",foldBg:"--fold-bg",foldBorder:"--fold-border",findBg:"--find-bg",findBorder:"--find-border",findCurBg:"--find-cur-bg",findCurBorder:"--find-cur-border",findCurText:"--find-cur-text",fileActiveBg:"--file-active-bg",fileActiveText:"--file-active-text",mmBg:"--mm-bg",mmSlider:"--mm-slider",mmDim:"--mm-dim",mmEdge:"--mm-edge",indentGuide:"--indent-guide",tokKw:"--tok-kw",tokStr:"--tok-str",tokCmt:"--tok-cmt",tokFn:"--tok-fn",tokNum:"--tok-num",tokCls:"--tok-cls",tokOp:"--tok-op",tokTyp:"--tok-typ",tokDec:"--tok-dec"};class Ke{constructor(t){v(this,"_registry",new Map);v(this,"_activeId","");v(this,"_root");this._root=t;for(const s of Kt)this._registry.set(s.id,s)}register(t){this._registry.set(t.id,t)}apply(t){let s;typeof t=="string"?(s=this._registry.get(t),s||(console.warn(`[syncline-editor] Unknown theme: "${t}". Falling back to VR Dark.`),s=this._registry.get(""))):(s=t,this._registry.set(s.id,s)),this._activeId=s.id,this._applyTokens(s.tokens)}get activeId(){return this._activeId}get activeTheme(){return this._registry.get(this._activeId)}get allIds(){return[...this._registry.keys()]}get all(){return[...this._registry.values()]}_applyTokens(t){const s=this._root.style;for(const[i,e]of Object.entries(Ve))s.setProperty(e,t[i])}}const qe=`
|
|
159
|
+
/* ── Reset ── */
|
|
160
|
+
*,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
|
|
161
|
+
|
|
162
|
+
/* ── Host element ── */
|
|
163
|
+
:host,.sl-host{
|
|
164
|
+
display:flex;flex-direction:column;
|
|
165
|
+
height:100%;overflow:hidden;
|
|
166
|
+
font-family:var(--sans,'Geist',system-ui,sans-serif);
|
|
167
|
+
color:var(--text,#c9c7c0);
|
|
168
|
+
background:var(--bg0,#0d0d0f);
|
|
169
|
+
|
|
170
|
+
/* Default token vars (can be overridden by theme) */
|
|
171
|
+
--sans:'Geist',system-ui,sans-serif;
|
|
172
|
+
--mono:'JetBrains Mono',monospace;
|
|
173
|
+
|
|
174
|
+
/* ── VR Dark defaults ── */
|
|
175
|
+
--bg0:#0d0d0f; --bg1:#111115; --bg2:#16161b; --bg3:#1d1d24; --bg4:#24242d;
|
|
176
|
+
--border:rgba(255,255,255,.07);
|
|
177
|
+
--border2:rgba(255,255,255,.12);
|
|
178
|
+
--border3:rgba(255,255,255,.19);
|
|
179
|
+
--text:#c9c7c0; --text2:#8b8994; --text3:#4e4c58;
|
|
180
|
+
--accent:#6e9fff; --accent2:#2f5db0;
|
|
181
|
+
--green:#4ec9a0; --orange:#d4976e; --purple:#b48eff;
|
|
182
|
+
--red:#f28b82; --yellow:#e8c97a;
|
|
183
|
+
--cur:#6e9fff; --cur-glow:rgba(110,159,255,.65);
|
|
184
|
+
--cur-line-bg:rgba(255,255,255,.032);
|
|
185
|
+
--cur-line-gutter:#181820;
|
|
186
|
+
--gutter-bg:#0f0f12; --gutter-hover:#181820;
|
|
187
|
+
--gutter-border:rgba(255,255,255,.06);
|
|
188
|
+
--gutter-num:#4e4c58; --gutter-num-act:#9997a2;
|
|
189
|
+
--sel-bg:rgba(110,159,255,.22);
|
|
190
|
+
--word-hl-bg:rgba(200,198,210,.09);
|
|
191
|
+
--word-hl-border:rgba(200,198,210,.28);
|
|
192
|
+
--bm-border:rgba(110,159,255,.65);
|
|
193
|
+
--fold-bg:rgba(110,159,255,.07);
|
|
194
|
+
--fold-border:rgba(110,159,255,.30);
|
|
195
|
+
--find-bg:rgba(234,180,86,.18);
|
|
196
|
+
--find-border:rgba(234,180,86,.50);
|
|
197
|
+
--find-cur-bg:rgba(234,180,86,.80);
|
|
198
|
+
--find-cur-border:rgba(234,180,86,.95);
|
|
199
|
+
--find-cur-text:#1a1000;
|
|
200
|
+
--file-active-bg:rgba(110,159,255,.11);
|
|
201
|
+
--file-active-text:#6e9fff;
|
|
202
|
+
--mm-bg:#0d0d0f; --mm-slider:rgba(255,255,255,.07);
|
|
203
|
+
--mm-dim:rgba(0,0,0,.30); --mm-edge:rgba(255,255,255,.18);
|
|
204
|
+
--indent-guide:rgba(255,255,255,.06);
|
|
205
|
+
--tok-kw:#6e9fff; --tok-str:#4ec9a0; --tok-cmt:#4e4c58;
|
|
206
|
+
--tok-fn:#d4976e; --tok-num:#b48eff; --tok-cls:#e8c97a;
|
|
207
|
+
--tok-op:#55536a; --tok-typ:#6ec9d4; --tok-dec:#f28b82;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/* ── Layout ── */
|
|
211
|
+
.sl-layout{display:flex;flex:1;overflow:hidden}
|
|
212
|
+
.sl-ed-pane{flex:1;display:flex;flex-direction:column;overflow:hidden;position:relative;background:var(--bg2)}
|
|
213
|
+
|
|
214
|
+
/* ── Hidden textarea (input capture) ── */
|
|
215
|
+
.sl-input{position:fixed;left:-9999px;top:0;width:200px;height:40px;
|
|
216
|
+
opacity:0;resize:none;border:none;outline:none;padding:0;margin:0;
|
|
217
|
+
font-size:16px;background:transparent;color:transparent;
|
|
218
|
+
caret-color:transparent;pointer-events:none}
|
|
219
|
+
|
|
220
|
+
/* ── Editor scroll container ── */
|
|
221
|
+
.sl-editor{flex:1;overflow-y:scroll;overflow-x:auto;position:relative;
|
|
222
|
+
cursor:text;scrollbar-width:thin;scrollbar-color:var(--border3) transparent}
|
|
223
|
+
.sl-editor::-webkit-scrollbar{width:10px;height:8px}
|
|
224
|
+
.sl-editor::-webkit-scrollbar-track{background:transparent}
|
|
225
|
+
.sl-editor::-webkit-scrollbar-thumb{background:var(--border3);border-radius:5px;border:2px solid var(--bg2)}
|
|
226
|
+
.sl-spacer{position:absolute;left:0;top:0;width:1px;pointer-events:none}
|
|
227
|
+
.sl-vp{position:absolute;left:0;right:0;overflow-x:hidden;will-change:transform}
|
|
228
|
+
|
|
229
|
+
/* ── Editor row ── */
|
|
230
|
+
.sl-er{display:flex;align-items:stretch;position:relative}
|
|
231
|
+
.sl-er:hover .sl-eg{background:var(--gutter-hover)}
|
|
232
|
+
.sl-er.sl-cur-row{background:var(--cur-line-bg)}
|
|
233
|
+
.sl-er.sl-cur-row .sl-eg{background:var(--cur-line-gutter)!important}
|
|
234
|
+
.sl-eg{min-width:60px;font-family:var(--mono);font-size:11px;color:var(--gutter-num);
|
|
235
|
+
user-select:none;border-right:1px solid var(--gutter-border);
|
|
236
|
+
background:var(--gutter-bg);flex-shrink:0;position:sticky;left:0;z-index:2;
|
|
237
|
+
display:flex;flex-direction:column;justify-content:flex-start;
|
|
238
|
+
transition:background .12s,color .12s}
|
|
239
|
+
.sl-er.sl-cur-row .sl-eg{color:var(--gutter-num-act)}
|
|
240
|
+
.sl-egn{height:22px;line-height:22px;padding-right:10px;text-align:right;display:block}
|
|
241
|
+
.sl-er.sl-wrap-cont .sl-egn{visibility:hidden}
|
|
242
|
+
.sl-el{flex:1;font-family:var(--mono);font-size:13px;line-height:22px;
|
|
243
|
+
color:var(--text);position:relative;min-width:0}
|
|
244
|
+
.sl-cl{display:block;height:22px;line-height:22px;
|
|
245
|
+
padding:0 20px 0 14px;white-space:pre;position:relative}
|
|
246
|
+
.sl-wrap-mode .sl-cl{white-space:pre-wrap;word-break:break-all;height:auto;overflow-wrap:anywhere}
|
|
247
|
+
|
|
248
|
+
/* ── Cursor ── */
|
|
249
|
+
.sl-cur{display:inline;width:0;height:0;position:relative}
|
|
250
|
+
.sl-cur::after{content:'';position:absolute;left:0;top:2px;width:2px;height:18px;
|
|
251
|
+
background:var(--cur);border-radius:1px;
|
|
252
|
+
box-shadow:0 0 8px var(--cur-glow);
|
|
253
|
+
animation:sl-blink 1.05s step-end infinite;pointer-events:none}
|
|
254
|
+
@keyframes sl-blink{0%,100%{opacity:1}45%,55%{opacity:0}}
|
|
255
|
+
|
|
256
|
+
/* ── Multi-cursor extra beams ── */
|
|
257
|
+
.sl-cur-extra{display:inline;width:0;height:0;position:relative}
|
|
258
|
+
.sl-cur-extra::after{content:'';position:absolute;left:0;top:2px;width:2px;height:18px;
|
|
259
|
+
background:var(--cur);border-radius:1px;
|
|
260
|
+
box-shadow:0 0 8px var(--cur-glow);
|
|
261
|
+
animation:sl-blink 1.05s step-end infinite;pointer-events:none}
|
|
262
|
+
|
|
263
|
+
/* ── Snippet tab-stop ghost markers ── */
|
|
264
|
+
.sl-snip-stop{display:inline;width:0;height:0;position:relative}
|
|
265
|
+
.sl-snip-stop::after{content:'';position:absolute;left:0;top:2px;width:2px;height:18px;
|
|
266
|
+
background:var(--cur);border-radius:1px;opacity:0.28;pointer-events:none}
|
|
267
|
+
|
|
268
|
+
/* ── Overlays ── */
|
|
269
|
+
.sl-sh{background:var(--sel-bg);border-radius:2px}
|
|
270
|
+
.sl-fh{background:var(--find-bg);box-shadow:0 0 0 1px var(--find-border);border-radius:2px}
|
|
271
|
+
.sl-fh.sl-fh-cur{background:var(--find-cur-bg);box-shadow:0 0 0 1px var(--find-cur-border);color:var(--find-cur-text)}
|
|
272
|
+
.sl-wh{background:var(--word-hl-bg);box-shadow:0 0 0 1px var(--word-hl-border);border-radius:2px}
|
|
273
|
+
.sl-bm{box-shadow:0 0 0 1px var(--bm-border);border-radius:2px}
|
|
274
|
+
.sl-ig{position:absolute;top:0;bottom:0;width:1px;background:var(--indent-guide);pointer-events:none}
|
|
275
|
+
|
|
276
|
+
/* ── Code folding ── */
|
|
277
|
+
.sl-fold-btn{position:absolute;left:3px;top:4px;width:13px;height:13px;border-radius:3px;
|
|
278
|
+
display:flex;align-items:center;justify-content:center;font-size:9px;
|
|
279
|
+
color:var(--gutter-num);cursor:pointer;opacity:0;
|
|
280
|
+
transition:opacity .15s,background .1s;user-select:none;line-height:1}
|
|
281
|
+
.sl-er:hover .sl-fold-btn{opacity:1}
|
|
282
|
+
.sl-fold-btn:hover{background:var(--border3);color:var(--gutter-num-act)}
|
|
283
|
+
.sl-folded{background:var(--fold-bg);border-bottom:1px dashed var(--fold-border)}
|
|
284
|
+
|
|
285
|
+
/* ── Syntax tokens ── */
|
|
286
|
+
.kw{color:var(--tok-kw)}.str{color:var(--tok-str)}.cmt{color:var(--tok-cmt);font-style:italic}
|
|
287
|
+
.fn{color:var(--tok-fn)}.num{color:var(--tok-num)}.cls{color:var(--tok-cls)}
|
|
288
|
+
.op{color:var(--tok-op)}.typ{color:var(--tok-typ)}.dec{color:var(--tok-dec)}
|
|
289
|
+
|
|
290
|
+
/* ── Minimap ── */
|
|
291
|
+
.sl-minimap{background:var(--mm-bg);border-left:1px solid var(--border);
|
|
292
|
+
overflow:hidden;position:relative;flex-shrink:0;cursor:pointer;user-select:none}
|
|
293
|
+
.sl-minimap canvas{display:block;position:absolute;top:0;left:0}
|
|
294
|
+
.sl-mm-slider{position:absolute;left:0;right:0;pointer-events:none}
|
|
295
|
+
|
|
296
|
+
/* ── Status bar ── */
|
|
297
|
+
.sl-statusbar{height:26px;background:var(--accent2);display:flex;align-items:center;
|
|
298
|
+
padding:0 6px;font-size:11px;color:rgba(255,255,255,.85);flex-shrink:0;gap:0}
|
|
299
|
+
.sl-sb-item{display:flex;align-items:center;gap:4px;padding:0 8px;height:100%;
|
|
300
|
+
cursor:pointer;transition:background .1s;white-space:nowrap;border-radius:3px}
|
|
301
|
+
.sl-sb-item:hover{background:rgba(255,255,255,.15)}
|
|
302
|
+
.sl-sb-item.sl-no-click{cursor:default}
|
|
303
|
+
.sl-sb-item.sl-no-click:hover{background:transparent}
|
|
304
|
+
.sl-sb-sep{width:1px;height:14px;background:rgba(255,255,255,.22);margin:0 1px;flex-shrink:0}
|
|
305
|
+
.sl-sb-right{margin-left:auto;display:flex;align-items:center}
|
|
306
|
+
.sl-sb-wrap.sl-on{font-weight:700}
|
|
307
|
+
|
|
308
|
+
/* ── Placeholder ── */
|
|
309
|
+
.sl-placeholder{position:absolute;top:0;right:0;pointer-events:none;user-select:none;
|
|
310
|
+
color:var(--text3);white-space:pre;overflow:hidden;z-index:1}
|
|
311
|
+
|
|
312
|
+
/* ── Go to Line bar ── */
|
|
313
|
+
.sl-gtl-bar{position:absolute;top:0;left:50%;z-index:50;background:var(--bg3);
|
|
314
|
+
border:1px solid var(--border3);border-top:none;border-radius:0 0 10px 10px;
|
|
315
|
+
display:flex;align-items:center;gap:8px;padding:8px 12px;
|
|
316
|
+
transform:translateX(-50%) translateY(-100%);transition:transform .18s,box-shadow .18s;pointer-events:none}
|
|
317
|
+
.sl-gtl-bar.sl-open{transform:translateX(-50%) translateY(0);pointer-events:all;box-shadow:0 8px 28px rgba(0,0,0,.4)}
|
|
318
|
+
.sl-gtl-label{font-size:12px;color:var(--text2);white-space:nowrap}
|
|
319
|
+
.sl-gtl-input{width:72px;background:var(--bg4);border:1px solid var(--border3);
|
|
320
|
+
border-radius:5px;padding:4px 8px;font-size:12px;font-family:var(--mono);
|
|
321
|
+
color:var(--text);outline:none;transition:border-color .15s;text-align:center}
|
|
322
|
+
.sl-gtl-input:focus{border-color:var(--accent)}
|
|
323
|
+
.sl-gtl-input.sl-gtl-err{border-color:#e05252}
|
|
324
|
+
.sl-gtl-hint{font-size:11px;color:var(--text3);font-family:var(--mono);min-width:40px}
|
|
325
|
+
|
|
326
|
+
/* ── Find + Replace bar ── */
|
|
327
|
+
.sl-find-bar{position:absolute;top:0;right:125px;z-index:50;background:var(--bg3);
|
|
328
|
+
border:1px solid var(--border3);border-top:none;border-radius:0 0 10px 10px;
|
|
329
|
+
display:flex;flex-direction:column;overflow:hidden;
|
|
330
|
+
transform:translateY(-100%);transition:transform .18s,box-shadow .18s;pointer-events:none}
|
|
331
|
+
.sl-find-bar.sl-open{transform:translateY(0);pointer-events:all;box-shadow:0 8px 28px rgba(0,0,0,.4)}
|
|
332
|
+
.sl-find-row{display:flex;align-items:center;gap:6px;padding:7px 10px}
|
|
333
|
+
.sl-find-row+.sl-find-row{border-top:1px solid var(--border)}
|
|
334
|
+
.sl-find-bar input{width:180px;background:var(--bg4);border:1px solid var(--border3);
|
|
335
|
+
border-radius:5px;padding:4px 8px;font-size:12px;font-family:var(--mono);
|
|
336
|
+
color:var(--text);outline:none;transition:border-color .15s}
|
|
337
|
+
.sl-find-bar input:focus{border-color:var(--accent)}
|
|
338
|
+
.sl-find-btn{padding:3px 8px;font-size:11px;border:1px solid var(--border3);
|
|
339
|
+
border-radius:4px;background:transparent;color:var(--text2);cursor:pointer;
|
|
340
|
+
transition:background .1s;white-space:nowrap}
|
|
341
|
+
.sl-find-btn:hover{background:var(--border3);color:var(--text)}
|
|
342
|
+
.sl-find-btn.sl-active{background:var(--accent);border-color:var(--accent);color:#fff}
|
|
343
|
+
.sl-find-count{font-size:11px;color:var(--text3);font-family:var(--mono);min-width:52px}
|
|
344
|
+
.sl-find-x{font-size:14px;color:var(--text3);cursor:pointer;padding:2px 5px;
|
|
345
|
+
border-radius:3px;margin-left:2px}
|
|
346
|
+
.sl-find-x:hover{color:var(--text);background:var(--border3)}
|
|
347
|
+
|
|
348
|
+
/* ── Autocomplete popup (VS Code-style with optional description panel) ── */
|
|
349
|
+
.sl-ac-popup{position:fixed;z-index:400;background:var(--bg3);
|
|
350
|
+
border:1px solid var(--border3);border-radius:8px;overflow:hidden;
|
|
351
|
+
box-shadow:0 12px 40px rgba(0,0,0,.55);
|
|
352
|
+
display:flex;flex-direction:row;
|
|
353
|
+
animation:sl-acIn .1s ease;pointer-events:all}
|
|
354
|
+
@keyframes sl-acIn{from{opacity:0;transform:translateY(-4px)}to{opacity:1;transform:none}}
|
|
355
|
+
/* Left: item list */
|
|
356
|
+
.sl-ac-list{min-width:240px;max-width:300px;max-height:320px;overflow-y:auto;flex-shrink:0}
|
|
357
|
+
.sl-ac-list::-webkit-scrollbar{width:4px}
|
|
358
|
+
.sl-ac-list::-webkit-scrollbar-thumb{background:var(--border3);border-radius:2px}
|
|
359
|
+
.sl-ac-item{display:flex;align-items:center;gap:8px;padding:4px 10px;font-size:12px;
|
|
360
|
+
font-family:var(--mono);cursor:pointer;color:var(--text2);transition:background .07s;
|
|
361
|
+
white-space:nowrap}
|
|
362
|
+
.sl-ac-item:hover,.sl-ac-item.sl-sel{background:var(--bg4);color:var(--text)}
|
|
363
|
+
.sl-ac-badge{width:18px;height:18px;border-radius:4px;display:flex;align-items:center;
|
|
364
|
+
justify-content:center;font-size:9px;font-weight:700;flex-shrink:0;font-family:var(--sans)}
|
|
365
|
+
.sl-ac-badge.kw{background:rgba(110,159,255,.18);color:var(--tok-kw)}
|
|
366
|
+
.sl-ac-badge.fn{background:rgba(212,151,110,.18);color:var(--tok-fn)}
|
|
367
|
+
.sl-ac-badge.typ{background:rgba(110,201,212,.18);color:var(--tok-typ)}
|
|
368
|
+
.sl-ac-badge.cls{background:rgba(232,201,122,.18);color:var(--tok-cls)}
|
|
369
|
+
.sl-ac-badge.var{background:rgba(78,201,160,.18);color:var(--tok-str)}
|
|
370
|
+
.sl-ac-badge.snip{background:rgba(155,100,255,.18);color:#a78bfa}
|
|
371
|
+
.sl-ac-badge.emmet{background:rgba(255,140,0,.18);color:#fb923c}
|
|
372
|
+
.sl-ac-label{flex:1;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
373
|
+
.sl-ac-detail{font-size:10px;color:var(--text3);flex-shrink:0;max-width:120px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;margin-left:4px}
|
|
374
|
+
/* Right: description / docs panel */
|
|
375
|
+
.sl-ac-desc{width:260px;max-height:320px;overflow-y:auto;
|
|
376
|
+
border-left:1px solid var(--border3);padding:10px 12px;flex-shrink:0}
|
|
377
|
+
.sl-ac-desc::-webkit-scrollbar{width:4px}
|
|
378
|
+
.sl-ac-desc::-webkit-scrollbar-thumb{background:var(--border3);border-radius:2px}
|
|
379
|
+
.sl-ac-desc-body{margin:0;font-size:11.5px;font-family:var(--mono);
|
|
380
|
+
color:var(--text2);line-height:1.6;white-space:pre-wrap;word-break:break-word}
|
|
381
|
+
|
|
382
|
+
/* ── Hover documentation tooltip ── */
|
|
383
|
+
.sl-hover-tip{position:fixed;z-index:500;background:var(--bg3);
|
|
384
|
+
border:1px solid var(--border3);border-radius:8px;
|
|
385
|
+
box-shadow:0 8px 32px rgba(0,0,0,.55);
|
|
386
|
+
max-width:380px;min-width:180px;padding:10px 14px;
|
|
387
|
+
pointer-events:all;cursor:default;
|
|
388
|
+
animation:sl-hoverIn .12s ease}
|
|
389
|
+
@keyframes sl-hoverIn{from{opacity:0;transform:translateY(3px)}to{opacity:1;transform:none}}
|
|
390
|
+
.sl-ht-sig{display:flex;align-items:baseline;flex-wrap:wrap;gap:8px;margin-bottom:5px}
|
|
391
|
+
.sl-ht-title{font-size:12.5px;font-family:var(--mono);font-weight:600;color:var(--tok-fn)}
|
|
392
|
+
.sl-ht-type{font-size:11px;font-family:var(--mono);color:var(--tok-typ);opacity:.9;word-break:break-all}
|
|
393
|
+
.sl-ht-body{font-size:12px;font-family:var(--sans);color:var(--text2);line-height:1.55;
|
|
394
|
+
max-height:120px;overflow-y:auto}
|
|
395
|
+
.sl-ht-body::-webkit-scrollbar{width:3px}
|
|
396
|
+
.sl-ht-body::-webkit-scrollbar-thumb{background:var(--border3);border-radius:2px}
|
|
397
|
+
.sl-hover-tip .sl-ht-divider{height:1px;background:var(--border);margin:6px 0}
|
|
398
|
+
|
|
399
|
+
/* ── Emmet tooltip ── */
|
|
400
|
+
.sl-emmet-tip{position:fixed;z-index:600;background:var(--bg3);
|
|
401
|
+
border:1px solid var(--border3);border-radius:6px;padding:4px 10px;
|
|
402
|
+
font-size:11px;font-family:var(--mono);color:var(--accent);
|
|
403
|
+
pointer-events:none;box-shadow:0 4px 16px rgba(0,0,0,.45);
|
|
404
|
+
white-space:nowrap;max-width:400px;overflow:hidden;text-overflow:ellipsis}
|
|
405
|
+
|
|
406
|
+
/* ── Theme picker ── */
|
|
407
|
+
.sl-theme-overlay{position:fixed;inset:0;z-index:700;
|
|
408
|
+
background:rgba(0,0,0,.50);backdrop-filter:blur(2px)}
|
|
409
|
+
.sl-theme-panel{position:fixed;top:50%;left:50%;transform:translate(-50%,-50%);
|
|
410
|
+
z-index:701;background:var(--bg2);border:1px solid var(--border3);
|
|
411
|
+
border-radius:14px;overflow:hidden;width:420px;
|
|
412
|
+
box-shadow:0 32px 80px rgba(0,0,0,.65),0 0 0 1px var(--border2)}
|
|
413
|
+
.sl-theme-header{padding:16px 20px 12px;display:flex;align-items:center;
|
|
414
|
+
justify-content:space-between;border-bottom:1px solid var(--border)}
|
|
415
|
+
.sl-theme-title{font-size:13px;font-weight:600;color:var(--text);letter-spacing:.01em}
|
|
416
|
+
.sl-theme-close{width:24px;height:24px;border-radius:6px;display:flex;align-items:center;
|
|
417
|
+
justify-content:center;font-size:14px;color:var(--text3);cursor:pointer;
|
|
418
|
+
transition:background .1s,color .1s}
|
|
419
|
+
.sl-theme-close:hover{background:var(--border3);color:var(--text)}
|
|
420
|
+
.sl-theme-list{padding:8px 8px 10px}
|
|
421
|
+
.sl-theme-item{display:flex;align-items:center;gap:14px;padding:10px 12px;
|
|
422
|
+
border-radius:9px;cursor:pointer;transition:background .1s;
|
|
423
|
+
border:1px solid transparent;margin-bottom:2px}
|
|
424
|
+
.sl-theme-item:hover{background:var(--bg4)}
|
|
425
|
+
.sl-theme-item.sl-active{background:var(--bg4);border-color:var(--border3)}
|
|
426
|
+
.sl-theme-check{width:18px;height:18px;margin-left:auto;color:var(--accent);
|
|
427
|
+
font-size:13px;font-weight:700;flex-shrink:0;opacity:0}
|
|
428
|
+
.sl-theme-item.sl-active .sl-theme-check{opacity:1}
|
|
429
|
+
.sl-theme-swatch{width:46px;height:30px;border-radius:7px;flex-shrink:0;
|
|
430
|
+
overflow:hidden;border:1px solid rgba(0,0,0,.15);
|
|
431
|
+
display:grid;grid-template-columns:1fr 1fr;grid-template-rows:1fr 1fr}
|
|
432
|
+
.sl-theme-swatch span{display:block}
|
|
433
|
+
.sl-theme-name{font-size:13px;color:var(--text);font-weight:500;line-height:1.3}
|
|
434
|
+
.sl-theme-desc{font-size:11px;color:var(--text3);margin-top:2px}
|
|
435
|
+
.sl-theme-tag{display:inline-block;font-size:9px;font-weight:600;letter-spacing:.08em;
|
|
436
|
+
text-transform:uppercase;padding:1px 5px;border-radius:3px;margin-left:6px;
|
|
437
|
+
background:var(--border3);color:var(--text3);vertical-align:middle}
|
|
438
|
+
.sl-theme-tag.sl-light{background:rgba(255,200,50,.15);color:#b58900}
|
|
439
|
+
|
|
440
|
+
/* ── Empty state ── */
|
|
441
|
+
.sl-empty{flex:1;display:flex;flex-direction:column;align-items:center;
|
|
442
|
+
justify-content:center;gap:10px;color:var(--text3);font-size:13px}
|
|
443
|
+
`,Ye={fontSize:[8,72,13],lineHeight:[14,64,22],tabSize:[1,16,2],wrapColumn:[20,500,80],maxCompletions:[1,50,14],autocompletePrefixLength:[1,10,2],gutterWidth:[30,200,60],minimapWidth:[60,300,120],cursorBlinkRate:[200,5e3,1050],maxUndoHistory:[10,5e3,300],undoBatchMs:[0,5e3,700]};function Xe(r,t,s,i){const e=Number(r);return Number.isFinite(e)?Math.max(t,Math.min(s,Math.round(e))):i}function qt(r){const t={...r};for(const[s,i]of Object.entries(Ye))if(s in r&&r[s]!==void 0){const[e,n,o]=i;t[s]=Xe(r[s],e,n,o)}return t}const Je={value:"",language:"typescript",theme:"",showGutter:!0,showMinimap:!0,showStatusBar:!0,wordWrap:!1,wrapColumn:80,fontFamily:"'JetBrains Mono', monospace",fontSize:13,lineHeight:22,tabSize:2,insertSpaces:!0,maxUndoHistory:100,showIndentGuides:!0,bracketMatching:!0,codeFolding:!0,emmet:!0,snippetExpansion:!0,autocomplete:!0,multiCursor:!0,find:!0,findReplace:!0,wordSelection:!0,wordHighlight:!0,highlightActiveLine:!0,autocompletePrefixLength:2,readOnly:!1,extraKeywords:[],extraTypes:[],completions:[],replaceBuiltins:!1,maxCompletions:14,autoClosePairs:{"(":")","[":"]","{":"}",'"':'"',"'":"'","`":"`"},lineCommentToken:"",wordSeparators:"",undoBatchMs:700,gutterWidth:60,minimapWidth:120,cursorBlinkRate:1050,cursorStyle:"line",renderWhitespace:"none",tokenColors:{},hover:!0,placeholder:"",goToLine:!1};class Ze{constructor(t,s={}){v(this,"_host");v(this,"_shadow");v(this,"_editorEl");v(this,"_spacerEl");v(this,"_vpEl");v(this,"_inputEl");v(this,"_minimapWrap");v(this,"_mmCanvas");v(this,"_mmSlider");v(this,"_statusBar");v(this,"_findBar");v(this,"_findInput");v(this,"_replaceInput");v(this,"_findCount");v(this,"_replaceRow");v(this,"_acPopup");v(this,"_emmetTip");v(this,"_snippetTip");v(this,"_hoverTip");v(this,"_themeOverlay");v(this,"_themePanel");v(this,"_placeholderEl");v(this,"_goToLineBar");v(this,"_goToLineInput");v(this,"_goToLineHint");v(this,"_config");v(this,"_tab",xt(1,[""]));v(this,"_wm",{segments:[[""]],visualRows:[{docLine:0,segIdx:0,text:""}],docToVisArr:[0],totalVisualRows:1,windowVisStart:0});v(this,"_foldedLines",new Map);v(this,"_tokenCache",new be);v(this,"_themeManager");v(this,"_findMatches",[]);v(this,"_findIdx",-1);v(this,"_findCaseSensitive",!1);v(this,"_findRegex",!1);v(this,"_wordHighlights",[]);v(this,"_bracketMatch",null);v(this,"_acItems",[]);v(this,"_acSel",0);v(this,"_acPrefix","");v(this,"_acStartCol",0);v(this,"_emmetAcStartCol",0);v(this,"_mc",pe());v(this,"_extraCursors",[]);v(this,"_isDragging",!1);v(this,"_dragAnchor",null);v(this,"_hoverTimer",null);v(this,"_hoverPinned",!1);v(this,"_mmDragMode","none");v(this,"_mmDragStartY",0);v(this,"_mmDragStartScroll",0);v(this,"_mmSliderOffset",0);v(this,"_mmColors");v(this,"_lastInputTime",0);v(this,"_linewiseCopy",!1);v(this,"_dynamicStyleEl");v(this,"_emmetExpanded",null);v(this,"_snippetExpanded",null);v(this,"_snippetSession",null);v(this,"_acDebounceTimer",null);v(this,"_rafId",null);v(this,"_renderedRowCount",0);v(this,"_lastRenderScroll",-1);v(this,"_onWinMouseUp");v(this,"_onWinResize");v(this,"_onEditorScroll");v(this,"_onWinMmMouseMove");v(this,"_onWinMmMouseUp");v(this,"_ro",null);this._config={...Je,...qt(s)},this._onWinMouseUp=()=>{this._isDragging=!1,this._dragAnchor=null},this._onEditorScroll=ct(()=>{this._hideHover(),this._scheduleRender(),this._updateMinimap()},16),this._onWinResize=ct(()=>{this._config.wordWrap&&this._rebuildWrapMap(),this._scheduleRender()},100),this._onWinMmMouseMove=l=>{if(this._mmDragMode==="none")return;const a=this._minimapWrap.clientHeight,d=this._tab.doc.length,c=this._config.lineHeight;if(this._mmDragMode==="slider"){const p=l.clientY-this._minimapWrap.getBoundingClientRect().top,h=ge(p-this._mmSliderOffset,d,this._editorEl.clientHeight,a,c);this._editorEl.scrollTop=this._domScroll(h)}else{const p=l.clientY-this._mmDragStartY,h=this._logicalScroll(this._mmDragStartScroll),b=Math.max(0,d*c-this._editorEl.clientHeight),m=Math.max(0,Math.min(b,h+p/2*c));this._editorEl.scrollTop=this._domScroll(m)}this._render()},this._onWinMmMouseUp=()=>{this._mmDragMode!=="none"&&(this._mmDragMode="none",this._minimapWrap.style.cursor="pointer")},this._host=t,this._host.classList.add("sl-host"),this._shadow=this._host.attachShadow({mode:"open"});const i=B("style");i.textContent=qe,this._shadow.appendChild(i),this._dynamicStyleEl=B("style"),this._shadow.appendChild(this._dynamicStyleEl),this._themeManager=new Ke(this._host),this._themeManager.apply(this._config.theme);const e=B("div","sl-layout"),n=B("div","sl-ed-pane");this._inputEl=B("textarea","sl-input"),this._inputEl.setAttribute("autocomplete","off"),this._inputEl.setAttribute("autocorrect","off"),this._inputEl.setAttribute("autocapitalize","off"),this._inputEl.setAttribute("spellcheck","false"),this._inputEl.setAttribute("role","textbox"),this._inputEl.setAttribute("aria-multiline","true"),this._inputEl.setAttribute("aria-label","Code editor"),this._inputEl.setAttribute("aria-readonly",String(!!this._config.readOnly)),this._inputEl.setAttribute("aria-haspopup","listbox"),this._editorEl=B("div","sl-editor"),this._spacerEl=B("div","sl-spacer"),this._vpEl=B("div","sl-vp"),this._editorEl.appendChild(this._spacerEl),this._editorEl.appendChild(this._vpEl),this._findBar=this._buildFindBar(),this._findInput=this._findBar.querySelector(".sl-find-input"),this._replaceInput=this._findBar.querySelector(".sl-find-replace-input"),this._findCount=this._findBar.querySelector(".sl-find-count"),this._replaceRow=this._findBar.querySelector(".sl-replace-row"),this._goToLineBar=this._buildGoToLineBar(),this._goToLineInput=this._goToLineBar.querySelector(".sl-gtl-input"),this._goToLineHint=this._goToLineBar.querySelector(".sl-gtl-hint"),this._placeholderEl=B("div","sl-placeholder"),this._placeholderEl.textContent=this._config.placeholder,this._placeholderEl.style.display="none",n.appendChild(this._inputEl),n.appendChild(this._findBar),n.appendChild(this._goToLineBar),n.appendChild(this._placeholderEl),n.appendChild(this._editorEl),this._minimapWrap=B("div","sl-minimap"),this._minimapWrap.style.width=`${this._config.minimapWidth}px`,this._mmCanvas=B("canvas",""),this._mmSlider=B("div","sl-mm-slider"),this._minimapWrap.appendChild(this._mmCanvas),this._minimapWrap.appendChild(this._mmSlider),e.appendChild(n),this._config.showMinimap&&e.appendChild(this._minimapWrap),this._statusBar=this._buildStatusBar(),this._acPopup=B("div","sl-ac-popup"),this._acPopup.setAttribute("role","listbox"),this._acPopup.setAttribute("aria-label","Code suggestions"),this._acPopup.style.display="none",this._emmetTip=B("div","sl-emmet-tip"),this._emmetTip.style.display="none",this._snippetTip=B("div","sl-emmet-tip"),this._snippetTip.style.display="none",this._hoverTip=B("div","sl-hover-tip"),this._hoverTip.style.display="none",this._hoverTip.addEventListener("mouseenter",()=>{this._hoverPinned=!0}),this._hoverTip.addEventListener("mouseleave",()=>{this._hoverPinned=!1,this._hideHover()}),this._themeOverlay=B("div","sl-theme-overlay"),this._themeOverlay.style.display="none",this._themePanel=B("div","sl-theme-panel"),this._themeOverlay.appendChild(this._themePanel),this._shadow.appendChild(e),this._config.showStatusBar&&this._shadow.appendChild(this._statusBar),this._shadow.appendChild(this._acPopup),this._shadow.appendChild(this._emmetTip),this._shadow.appendChild(this._snippetTip),this._shadow.appendChild(this._hoverTip),this._shadow.appendChild(this._themeOverlay);const o=typeof this._config.value=="string"?Mt(this._config.value):this._config.value;this._tab=xt(1,o.length?o:[""]),this._mmColors=ut(l=>nt(l,this._host)),this._bindEditorEvents(),this._bindMinimapEvents(),this._bindFindEvents(),this._applyDynamicStyles(),typeof ResizeObserver<"u"&&(this._ro=new ResizeObserver(ct(()=>{this._config.wordWrap&&(this._rebuildWrapMap(),this._scheduleRender())},60)),this._ro.observe(this._host)),this._rebuildWrapMap(),this._render()}_logicalScroll(t){const s=this._tab.doc.length*this._config.lineHeight;if(s<=15e6)return t;const i=this._editorEl.clientHeight,e=15e6-i,n=s-i;return e<=0?0:t/e*n}_domScroll(t){const s=this._tab.doc.length*this._config.lineHeight;if(s<=15e6)return t;const i=this._editorEl.clientHeight,e=15e6-i,n=s-i;return n<=0?0:t/n*e}_buildFindBar(){const t=B("div","sl-find-bar");return t.innerHTML=`
|
|
444
|
+
<div class="sl-find-row">
|
|
445
|
+
<input class="sl-find-input" placeholder="Find…" autocomplete="off" spellcheck="false">
|
|
446
|
+
<span class="sl-find-count">–</span>
|
|
447
|
+
<button class="sl-find-btn sl-find-prev" title="Previous">↑</button>
|
|
448
|
+
<button class="sl-find-btn sl-find-next" title="Next">↓</button>
|
|
449
|
+
<button class="sl-find-btn sl-find-case" title="Match case">Aa</button>
|
|
450
|
+
<button class="sl-find-btn sl-find-regex" title="Regex">.*</button>
|
|
451
|
+
<span class="sl-find-x sl-find-close">✕</span>
|
|
452
|
+
</div>
|
|
453
|
+
<div class="sl-find-row sl-replace-row" style="display:none">
|
|
454
|
+
<input class="sl-find-replace-input" placeholder="Replace…" autocomplete="off" spellcheck="false">
|
|
455
|
+
<button class="sl-find-btn sl-replace-one">Replace</button>
|
|
456
|
+
<button class="sl-find-btn sl-replace-all">All</button>
|
|
457
|
+
</div>
|
|
458
|
+
`,t}_buildGoToLineBar(){const t=B("div","sl-gtl-bar");t.innerHTML=`
|
|
459
|
+
<span class="sl-gtl-label">Go to line</span>
|
|
460
|
+
<input class="sl-gtl-input" type="text" inputmode="numeric" autocomplete="off" spellcheck="false" placeholder="…">
|
|
461
|
+
<span class="sl-gtl-hint"></span>
|
|
462
|
+
<span class="sl-find-x sl-gtl-close" title="Close">✕</span>
|
|
463
|
+
`;const s=t.querySelector(".sl-gtl-input"),i=t.querySelector(".sl-gtl-hint");return s.addEventListener("input",()=>{const e=parseInt(s.value,10),n=!isNaN(e)&&e>=1&&e<=this._tab.doc.length;s.classList.toggle("sl-gtl-err",s.value!==""&&!n),i.textContent=`(1–${this._tab.doc.length})`}),s.addEventListener("keydown",e=>{var n,o;if(e.key==="Enter"){e.preventDefault();const l=parseInt(s.value,10);!isNaN(l)&&l>=1&&l<=this._tab.doc.length&&(this._tab.cur.row=l-1,this._tab.cur.col=Math.min(this._tab.cur.col,(this._tab.doc[l-1]??"").length),L(this._tab),this._tab.sel=null,this._closeGoToLine(),this._scrollIntoView(),this._render(),(o=(n=this._config).onCursorChange)==null||o.call(n,{...this._tab.cur}))}else e.key==="Escape"&&(e.preventDefault(),this._closeGoToLine());e.stopPropagation()}),t.querySelector(".sl-gtl-close").addEventListener("click",()=>this._closeGoToLine()),t}_openGoToLine(){if(this._goToLineBar.classList.contains("sl-open")){this._closeGoToLine();return}this._goToLineHint.textContent=`(1–${this._tab.doc.length})`,this._goToLineInput.value=String(this._tab.cur.row+1),this._goToLineInput.classList.remove("sl-gtl-err"),this._goToLineBar.classList.add("sl-open"),this._goToLineInput.focus(),this._goToLineInput.select()}_closeGoToLine(){this._goToLineBar.classList.remove("sl-open"),this._focusInput()}_focusInput(){this._inputEl.style.pointerEvents="auto",this._inputEl.focus(),this._inputEl.style.pointerEvents="none"}_buildStatusBar(){const t=B("div","sl-statusbar");return t.innerHTML=`
|
|
464
|
+
<div class="sl-sb-item sl-no-click sl-sb-lang">⬡ TypeScript</div>
|
|
465
|
+
<div class="sl-sb-sep"></div>
|
|
466
|
+
<div class="sl-sb-item sl-no-click sl-sb-pos">Ln 1, Col 1</div>
|
|
467
|
+
<div class="sl-sb-sep"></div>
|
|
468
|
+
<div class="sl-sb-item sl-no-click sl-sb-sel"></div>
|
|
469
|
+
<div class="sl-sb-sep sl-sb-sel-sep" style="display:none"></div>
|
|
470
|
+
<div class="sl-sb-item sl-no-click sl-sb-lines">1 line</div>
|
|
471
|
+
<div class="sl-sb-sep"></div>
|
|
472
|
+
<div class="sl-sb-item sl-no-click">UTF-8 LF</div>
|
|
473
|
+
<div class="sl-sb-right">
|
|
474
|
+
<div class="sl-sb-item sl-no-click sl-sb-mc" style="display:none">⊕ <span class="sl-sb-mc-count">1</span> cursors</div>
|
|
475
|
+
<div class="sl-sb-item sl-no-click sl-sb-dom">0 DOM rows</div>
|
|
476
|
+
<div class="sl-sb-sep"></div>
|
|
477
|
+
<div class="sl-sb-item sl-sb-wrap sl-sb-wrap-btn">⇥ Wrap: OFF</div>
|
|
478
|
+
<div class="sl-sb-sep"></div>
|
|
479
|
+
<div class="sl-sb-item sl-sb-theme-btn">🎨 Theme</div>
|
|
480
|
+
<div class="sl-sb-sep"></div>
|
|
481
|
+
<div class="sl-sb-item sl-no-click sl-sb-undo">↩0 ↪0</div>
|
|
482
|
+
</div>
|
|
483
|
+
`,t.querySelector(".sl-sb-wrap-btn").addEventListener("click",()=>this._toggleWrap()),t.querySelector(".sl-sb-theme-btn").addEventListener("click",()=>this._openThemePicker()),t}_destroyBase(){var s;this._acDebounceTimer!==null&&(clearTimeout(this._acDebounceTimer),this._acDebounceTimer=null),this._hoverTimer!==null&&(clearTimeout(this._hoverTimer),this._hoverTimer=null),this._rafId!==null&&(cancelAnimationFrame(this._rafId),this._rafId=null),window.removeEventListener("mouseup",this._onWinMouseUp),window.removeEventListener("resize",this._onWinResize),window.removeEventListener("mousemove",this._onWinMmMouseMove),window.removeEventListener("mouseup",this._onWinMmMouseUp),(s=this._ro)==null||s.disconnect();const t=this._mmCanvas.getContext("2d");t&&t.clearRect(0,0,this._mmCanvas.width,this._mmCanvas.height),this._shadow.innerHTML="",this._host.classList.remove("sl-host")}}class Qe extends Ze{_applyDynamicStyles(){const{fontFamily:t,fontSize:s,lineHeight:i,cursorBlinkRate:e,cursorStyle:n,gutterWidth:o,minimapWidth:l,showGutter:a}=this._config,d=Math.max(2,i-4),c=Math.floor((i-d)/2);let p="";n==="block"?p=`width:${7.82}px;opacity:.5;border-radius:1px;`:n==="underline"&&(p=`width:${7.82}px;height:2px;top:${i-2}px;border-radius:0;`);const h=a?o:0;this._dynamicStyleEl.textContent=`
|
|
484
|
+
.sl-el{font-family:${t};font-size:${s}px;line-height:${i}px}
|
|
485
|
+
.sl-cl{height:${i}px;line-height:${i}px}
|
|
486
|
+
.sl-egn{height:${i}px;line-height:${i}px}
|
|
487
|
+
.sl-eg{min-width:${h}px;width:${h}px;${a?"":"display:none"}}
|
|
488
|
+
.sl-cur::after{height:${d}px;top:${c}px;animation-duration:${e}ms;${p}}
|
|
489
|
+
.sl-cur-extra::after{height:${d}px;top:${c}px;animation-duration:${e}ms;${p}}
|
|
490
|
+
`,this._applyTokenOverrides(),this._minimapWrap.style.width=`${l}px`,this._placeholderEl.style.left=`${h+14}px`,this._placeholderEl.style.fontFamily=t,this._placeholderEl.style.fontSize=`${s}px`,this._placeholderEl.style.lineHeight=`${i}px`}_applyTokenOverrides(){const t=this._config.tokenColors??{},s=this._themeManager.activeTheme,i=this._host.style,e=(o,l,a)=>{i.setProperty(o,l||a)},n=s==null?void 0:s.tokens;e("--tok-kw",t.keyword,(n==null?void 0:n.tokKw)??""),e("--tok-str",t.string,(n==null?void 0:n.tokStr)??""),e("--tok-cmt",t.comment,(n==null?void 0:n.tokCmt)??""),e("--tok-fn",t.function,(n==null?void 0:n.tokFn)??""),e("--tok-num",t.number,(n==null?void 0:n.tokNum)??""),e("--tok-cls",t.class,(n==null?void 0:n.tokCls)??""),e("--tok-op",t.operator,(n==null?void 0:n.tokOp)??""),e("--tok-typ",t.type,(n==null?void 0:n.tokTyp)??""),e("--tok-dec",t.decorator,(n==null?void 0:n.tokDec)??"")}_refreshMinimapColors(){this._mmColors=ut(t=>nt(t,this._host))}}const Y=1e4,rt=6*4;class ti extends Qe{constructor(){super(...arguments);v(this,"_onFoldBtnClick",s=>{const i=s.target.closest(".sl-fold-btn");if(!i)return;s.preventDefault(),s.stopPropagation();const e=parseInt(i.dataset.row??"0",10);if(this._foldedLines=We(this._foldedLines,this._tab.doc,e),this._foldedLines.has(e)){const n=this._foldedLines.get(e),o=this._tab.cur;o.row>e&&o.row<=n&&(this._tab.cur={row:e,col:(this._tab.doc[e]??"").length},this._tab.sel=null)}this._rebuildWrapMap(),this._render()})}_scheduleRender(){this._rafId===null&&(this._rafId=requestAnimationFrame(()=>{this._rafId=null,this._render()}))}_render(){const{doc:s,cur:i,sel:e}=this._tab,{lineHeight:n}=this._config,o=s.length,l=o*n,a=Math.min(l,15e6);this._spacerEl.style.height=`${a}px`;const d=this._editorEl.scrollTop,c=this._logicalScroll(d);o>Y&&d!==this._lastRenderScroll&&(this._lastRenderScroll=d,this._rebuildWrapMap());const p=this._wm.totalVisualRows,h=this._editorEl.clientHeight,b=Math.max(0,Math.floor(c/n)-6),m=Math.min(p-1,Math.ceil((c+h)/n)+6),g=o>Y?b:0,k=o>Y?m:o-1;if(this._wordHighlights=this._config.wordHighlight?ze(s,i.row,i.col,e,g,k):[],this._bracketMatch=this._config.bracketMatching?Ge(s,i):null,this._config.wordWrap)this._spacerEl.style.width="",this._vpEl.style.width="";else{const u=o>Y?this._wm.visualRows.reduce((x,R)=>Math.max(x,(s[R.docLine]??"").length),0):s.reduce((x,R)=>Math.max(x,R.length),0),y=this._config.showGutter?this._config.gutterWidth:0,S=Math.max(this._editorEl.clientWidth,y+14+Math.ceil(u*7.82)+20+64);this._spacerEl.style.width=`${S}px`,this._vpEl.style.width=`${S}px`}this._vpEl.style.transform=`translateY(${d+(b*n-c)}px)`;const f=z(this._wm,i.row,i.col),C=new Map;if(this._snippetSession)for(let u=this._snippetSession.idx+1;u<this._snippetSession.stops.length;u++){const y=this._snippetSession.stops[u],S=z(this._wm,y.row,y.col),x=C.get(S.visRow)??[];x.push(S.colInSeg),C.set(S.visRow,x)}const _=this._wm.windowVisStart;let w="";for(let u=b;u<=m;u++){const y=this._wm.visualRows[u-_];y&&(w+=$e({vr:y,visIdx:u,curVisRow:f.visRow,curColInSeg:f.colInSeg,docSel:e,findMatches:this._findMatches,findIdx:this._findIdx,wordHighlights:this._wordHighlights,bracketMatch:this._bracketMatch,extraCursors:this._extraCursors,snippetStopCols:C.get(u)??[],foldedLines:this._foldedLines,isFoldable:this._config.codeFolding&&je(s,y.docLine),wm:this._wm,tokenCache:this._tokenCache,opts:{tokeniserOpts:{language:this._config.language,extraKeywords:new Set(this._config.extraKeywords),extraTypes:new Set(this._config.extraTypes),provideTokens:this._config.provideTokens},showIndentGuides:this._config.showIndentGuides,highlightActiveLine:this._config.highlightActiveLine,charWidth:7.82,codePaddingLeft:14,tabSize:this._config.tabSize,lineHeight:n,renderWhitespace:this._config.renderWhitespace}}))}if(this._renderedRowCount=Math.max(0,m-b+1),this._vpEl.innerHTML=w,this._updateStatusBar(),this._updateMinimap(),this._config.placeholder){const u=this._tab.doc.length===1&&this._tab.doc[0]==="";this._placeholderEl.style.display=u?"":"none"}else this._placeholderEl.style.display="none"}_updateStatusBar(){if(!this._config.showStatusBar)return;const{cur:s,doc:i,undoStack:e,redoStack:n}=this._tab,o=this._config.language,l={typescript:"TypeScript",javascript:"JavaScript",css:"CSS",json:"JSON",markdown:"Markdown",text:"Text"},a=b=>this._statusBar.querySelector(b);a(".sl-sb-lang").textContent=`⬡ ${l[o]??o}`,a(".sl-sb-pos").textContent=`Ln ${s.row+1}, Col ${s.col+1}`,a(".sl-sb-lines").textContent=`${i.length.toLocaleString()} lines`;const d=ce(this._tab),c=a(".sl-sb-sel"),p=a(".sl-sb-sel-sep");c.textContent=d?`${d.toLocaleString()} selected`:"",p.style.display=d?"":"none",a(".sl-sb-undo").textContent=`↩${e.length} ↪${n.length}`;const h=a(".sl-sb-mc");this._extraCursors.length?(h.style.display="",a(".sl-sb-mc-count").textContent=String(this._extraCursors.length+1)):h.style.display="none",a(".sl-sb-dom").textContent=`${this._renderedRowCount} DOM rows`}_updateMinimap(){if(!this._config.showMinimap)return;const s=this._minimapWrap.clientWidth,i=this._minimapWrap.clientHeight;if(!s||!i)return;const e=this._tab.doc,n=e.length,o=Math.min(window.devicePixelRatio||1,2),l=this._config.lineHeight,{mmScroll:a,sliderTop:d,sliderHeight:c}=pt(n,this._logicalScroll(this._editorEl.scrollTop),this._editorEl.clientHeight,i,l),p=a/2,h=Math.floor(p),b=Math.ceil(i/2)+2,m=Math.min(n,h+b),g=(m-h)*2,k=(p-h)*2,f=Math.round(s*o),C=Math.round(g*o);(this._mmCanvas.width!==f||this._mmCanvas.height!==C)&&(this._mmCanvas.width=f,this._mmCanvas.height=C,this._mmCanvas.style.width=`${s}px`,this._mmCanvas.style.height=`${g}px`),this._mmCanvas.style.transform=`translateY(${-k}px)`,me({canvas:this._mmCanvas,doc:e,firstLine:h,lastLine:m,subPx:k,wrapperWidth:s,canvasHeight:g,cursorRow:this._tab.cur.row,sel:this._tab.sel,findMatches:this._findMatches,findIdx:this._findIdx,sliderTop:d,sliderHeight:c,colors:this._mmColors,getCssVar:_=>nt(_,this._host),dpr:o,tokenCache:this._tokenCache,language:this._config.language,provideTokens:this._config.provideTokens}),this._mmSlider.style.top=`${Math.max(0,Math.min(i-c,d))}px`,this._mmSlider.style.height=`${c}px`}_rebuildWrapMap(){let s;if(this._config.wordWrap){const e=this._config.showGutter?this._config.gutterWidth:0,n=this._editorEl.clientWidth;if(n>0){const o=n-e-14-20;s=Math.max(20,Math.floor(o/7.82))}else s=this._config.wrapColumn}else s=9999;const i=this._tab.doc.length;if(i>Y){const e=this._config.lineHeight,n=this._editorEl.scrollTop,o=this._logicalScroll(n),l=this._editorEl.clientHeight,a=this._tab.cur.row,d=Math.max(0,Math.floor(o/e)-rt),c=Math.min(i-1,Math.ceil((o+l)/e)+rt),p=this._config.wordWrap||this._foldedLines.size>0,h=p?Math.max(0,Math.min(d,a-rt)):d,b=p?Math.min(i-1,Math.max(c,a+rt)):c;this._wm=Tt(this._tab.doc,s,this._config.wordWrap,this._foldedLines,h,b)}else this._wm=Tt(this._tab.doc,s,this._config.wordWrap,this._foldedLines)}_scrollIntoView(){const s=this._tab.cur,i=this._config.lineHeight,n=this._tab.doc.length*i,o=Math.min(n,15e6);this._spacerEl.style.height=`${o}px`;const a=z(this._wm,s.row,s.col).visRow*i,d=a+i,c=this._domScroll(a),p=this._domScroll(d),h=this._editorEl.scrollTop,b=this._editorEl.clientHeight,m=i*3;c<h+m?this._editorEl.scrollTop=Math.max(0,c-m):p>h+b-m&&(this._editorEl.scrollTop=p-b+m)}}class ei extends ti{_insertStr(t,s){var g,k;const i=Date.now(),e=!s||i-this._lastInputTime>this._config.undoBatchMs;this._lastInputTime=i;const n={...this._tab.cur},o=this._tab.sel?{...this._tab.sel}:null;let l,a;if(this._tab.sel){const f=A(this._tab.sel);l=f.ar,a=this._tab.doc.slice(f.ar,f.fr+1),this._tab.cur=O(this._tab)}else l=this._tab.cur.row,a=[this._tab.doc[l]??""];const{doc:d,cur:c}=this._tab,p=t.split(`
|
|
491
|
+
`),h=d[c.row]??"",b=h.slice(0,c.col),m=h.slice(c.col);if(p.length===1)d[c.row]=b+t+m,c.col+=t.length;else{const f=[b+p[0]];for(let C=1;C<p.length-1;C++)f.push(p[C]);f.push(p[p.length-1]+m),d.splice(c.row,1,...f),c.row+=p.length-1,c.col=p[p.length-1].length}if(e){const f=d.slice(l,c.row+1);M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:l,oldLines:a,newLines:f},n,o)}this._tokenCache.invalidateLine(c.row,(this._wm.segments[c.row]??[""]).length),this._tab.dirty=!0,(k=(g=this._config).onChange)==null||k.call(g,I(d))}_doBackspace(){var n;const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null;if(this._tab.sel){const o=A(this._tab.sel),l=this._tab.doc.slice(o.ar,o.fr+1);this._tab.cur=O(this._tab),this._tokenCache.clear(),this._tab.dirty=!0;const a=[this._tab.doc[o.ar]??""];M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:o.ar,oldLines:l,newLines:a},t,s);return}const{doc:i,cur:e}=this._tab;if(e.col>0){const o=i[e.row]??"",l=o.slice(0,e.col),a=l.length>=2&&l.endsWith(" ")&&!l.trim()?2:1;i[e.row]=o.slice(0,e.col-a)+o.slice(e.col),e.col-=a,this._tokenCache.invalidateLine(e.row,((n=this._wm.segments[e.row])==null?void 0:n.length)??1),M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:e.row,oldLines:[o],newLines:[i[e.row]]},t,s)}else if(e.row>0){const o=i[e.row-1]??"",l=i[e.row]??"",a=o.length;i[e.row-1]=o+l,i.splice(e.row,1),e.row--,e.col=a,this._tokenCache.clear(),M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:e.row,oldLines:[o,l],newLines:[i[e.row]]},t,s)}else return;this._tab.dirty=!0}_doEnter(){const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null;let i,e;if(this._tab.sel){const b=A(this._tab.sel);i=b.ar,e=this._tab.doc.slice(b.ar,b.fr+1),this._tab.cur=O(this._tab)}else i=this._tab.cur.row,e=[this._tab.doc[i]??""];const{doc:n,cur:o}=this._tab,l=n[o.row]??"",a=l.slice(0,o.col),d=l.slice(o.col),c=it(l),p=a.trimEnd().endsWith("{")?st(this._config.tabSize):"";n[o.row]=a,a.trimEnd().endsWith("{")&&d.trimStart()==="}"?n.splice(o.row+1,0,c+p,c+d):n.splice(o.row+1,0,c+p+d),o.row++,o.col=c.length+p.length,this._tokenCache.clear();const h=n.slice(i,o.row+1);M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:i,oldLines:e,newLines:h},t,s),this._tab.dirty=!0}_doDelete(){var o;const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null;if(this._tab.sel){const l=A(this._tab.sel),a=this._tab.doc.slice(l.ar,l.fr+1);this._tab.cur=O(this._tab),this._tokenCache.clear(),this._tab.dirty=!0;const d=[this._tab.doc[l.ar]??""];M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:l.ar,oldLines:a,newLines:d},t,s);return}const{doc:i,cur:e}=this._tab,n=i[e.row]??"";if(e.col<n.length){const l=n;i[e.row]=n.slice(0,e.col)+n.slice(e.col+1),this._tokenCache.invalidateLine(e.row,((o=this._wm.segments[e.row])==null?void 0:o.length)??1),M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:e.row,oldLines:[l],newLines:[i[e.row]]},t,s)}else if(e.row<i.length-1){const l=n,a=i[e.row+1]??"";i[e.row]=l+a,i.splice(e.row+1,1),this._tokenCache.clear(),M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:e.row,oldLines:[l,a],newLines:[i[e.row]]},t,s)}else return;this._tab.dirty=!0}_selectAll(){const t=this._tab.doc,s=t.length-1;this._tab.sel={ar:0,ac:0,fr:s,fc:(t[s]??"").length},this._tab.cur={row:s,col:(t[s]??"").length},this._render()}_doCopy(){var s,i;const t=St(this._tab);if(t)this._linewiseCopy=!1,(s=navigator.clipboard)==null||s.writeText(t).catch(()=>{});else{this._linewiseCopy=!0;const e=(this._tab.doc[this._tab.cur.row]??"")+`
|
|
492
|
+
`;(i=navigator.clipboard)==null||i.writeText(e).catch(()=>{})}}_doCut(){var s,i,e,n,o,l;const t=St(this._tab);if(t){this._linewiseCopy=!1,(s=navigator.clipboard)==null||s.writeText(t).catch(()=>{});const a={...this._tab.cur},d=this._tab.sel?{...this._tab.sel}:null,c=A(this._tab.sel),p=this._tab.doc.slice(c.ar,c.fr+1);this._tab.cur=O(this._tab),this._tokenCache.clear(),this._tab.dirty=!0;const h=[this._tab.doc[c.ar]??""];M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:c.ar,oldLines:p,newLines:h},a,d),this._rebuildWrapMap(),this._render(),(e=(i=this._config).onChange)==null||e.call(i,I(this._tab.doc))}else{this._linewiseCopy=!0;const{doc:a,cur:d}=this._tab,c={...d},p=a[d.row]??"";(n=navigator.clipboard)==null||n.writeText(p+`
|
|
493
|
+
`).catch(()=>{}),a.length>1?(a.splice(d.row,1),L(this._tab),this._tokenCache.clear(),this._tab.dirty=!0,M(this._tab,this._config.maxUndoHistory,{kind:"delete",row:c.row,count:1,removed:[p]},c,null)):(a[0]="",d.col=0,this._tokenCache.clear(),this._tab.dirty=!0,M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:0,oldLines:[p],newLines:[""]},c,null)),this._rebuildWrapMap(),L(this._tab),this._render(),(l=(o=this._config).onChange)==null||l.call(o,I(this._tab.doc))}}_doInsertLineBelow(){var n,o,l,a;const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null,i=this._tab.cur.row,e=it(this._tab.doc[i]??"");this._tab.doc.splice(i+1,0,e),this._tab.cur.row=i+1,this._tab.cur.col=e.length,this._tab.sel=null,this._tokenCache.clear(),this._tab.dirty=!0,M(this._tab,this._config.maxUndoHistory,{kind:"insert",row:i+1,lines:[e]},t,s),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),(o=(n=this._config).onChange)==null||o.call(n,I(this._tab.doc)),(a=(l=this._config).onCursorChange)==null||a.call(l,{...this._tab.cur})}_doInsertLineAbove(){var n,o,l,a;const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null,i=this._tab.cur.row,e=it(this._tab.doc[i]??"");this._tab.doc.splice(i,0,e),this._tab.cur.row=i,this._tab.cur.col=e.length,this._tab.sel=null,this._tokenCache.clear(),this._tab.dirty=!0,M(this._tab,this._config.maxUndoHistory,{kind:"insert",row:i,lines:[e]},t,s),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),(o=(n=this._config).onChange)==null||o.call(n,I(this._tab.doc)),(a=(l=this._config).onCursorChange)==null||a.call(l,{...this._tab.cur})}_toggleComment(){var p,h;const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null,i=this._getSelRows(),e=i[0],n=i[i.length-1],o=this._tab.doc.slice(e,n+1),l=this._config.lineCommentToken||Zt[this._config.language]||"";if(!l)return;const a=l.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),d=i.every(b=>(this._tab.doc[b]??"").trimStart().startsWith(l));i.forEach(b=>{var g;const m=this._tab.doc[b]??"";this._tab.doc[b]=d?m.replace(new RegExp(`^(\\s*)${a}\\s?`),"$1"):m.replace(/^(\s*)/,`$1${l} `),this._tokenCache.invalidateLine(b,((g=this._wm.segments[b])==null?void 0:g.length)??1)}),this._tab.dirty=!0;const c=this._tab.doc.slice(e,n+1);M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:e,oldLines:o,newLines:c},t,s),this._rebuildWrapMap(),this._render(),(h=(p=this._config).onChange)==null||h.call(p,I(this._tab.doc))}_duplicateLine(){var n,o;const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null,i=this._tab.cur.row,e=this._tab.doc[i]??"";this._tab.doc.splice(i+1,0,e),this._tab.cur.row++,this._tokenCache.clear(),this._tab.dirty=!0,M(this._tab,this._config.maxUndoHistory,{kind:"insert",row:i+1,lines:[e]},t,s),this._rebuildWrapMap(),this._render(),(o=(n=this._config).onChange)==null||o.call(n,I(this._tab.doc))}_deleteLine(){var n,o;const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null,{doc:i,cur:e}=this._tab;if(i.length>1){const l=e.row,a=[i[l]??""];i.splice(l,1),L(this._tab),this._tokenCache.clear(),this._tab.dirty=!0,M(this._tab,this._config.maxUndoHistory,{kind:"delete",row:l,count:1,removed:a},t,s)}else{const l=i[0]??"";i[0]="",e.col=0,M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:0,oldLines:[l],newLines:[""]},t,s)}this._tokenCache.clear(),this._tab.dirty=!0,L(this._tab),this._rebuildWrapMap(),this._render(),(o=(n=this._config).onChange)==null||o.call(n,I(this._tab.doc))}_indentSel(){var d,c;if(!this._tab.sel){this._insertStr(st(this._config.tabSize),!1);return}const t={...this._tab.cur},s={...this._tab.sel},i=st(this._config.tabSize),e=this._getSelRows(),n=e[0],o=e[e.length-1],l=this._tab.doc.slice(n,o+1);e.forEach(p=>{var h;this._tab.doc[p]=i+(this._tab.doc[p]??""),this._tokenCache.invalidateLine(p,((h=this._wm.segments[p])==null?void 0:h.length)??1)}),this._tab.dirty=!0;const a=this._tab.doc.slice(n,o+1);M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:n,oldLines:l,newLines:a},t,s),this._rebuildWrapMap(),this._render(),(c=(d=this._config).onChange)==null||c.call(d,I(this._tab.doc))}_unindentSel(){var d,c;const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null,i=this._config.tabSize,e=this._getSelRows(),n=e[0],o=e[e.length-1],l=this._tab.doc.slice(n,o+1);e.forEach(p=>{var b;const h=this._tab.doc[p]??"";h.startsWith(st(i))?this._tab.doc[p]=h.slice(i):h.startsWith(" ")&&(this._tab.doc[p]=h.slice(1)),this._tokenCache.invalidateLine(p,((b=this._wm.segments[p])==null?void 0:b.length)??1)}),this._tab.dirty=!0;const a=this._tab.doc.slice(n,o+1);M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:n,oldLines:l,newLines:a},t,s),this._rebuildWrapMap(),this._render(),(c=(d=this._config).onChange)==null||c.call(d,I(this._tab.doc))}_toggleWrap(){this._config.wordWrap=!this._config.wordWrap,this._vpEl.classList.toggle("sl-wrap-mode",this._config.wordWrap);const t=this._statusBar.querySelector(".sl-sb-wrap-btn");t&&(t.textContent=`⇥ Wrap: ${this._config.wordWrap?"ON":"OFF"}`,t.classList.toggle("sl-on",this._config.wordWrap)),this._tokenCache.clear(),this._rebuildWrapMap(),this._render()}_getSelRows(){if(!this._tab.sel)return[this._tab.cur.row];const t=A(this._tab.sel),s=[];for(let i=t.ar;i<=t.fr;i++)s.push(i);return s}_duplicateLines(t){var c,p,h,b;const{doc:s,cur:i}=this._tab,e=this._tab.sel;let n=i.row,o=i.row;if(e){const m=A(e);n=m.ar,o=m.fr,m.fc===0&&m.fr>m.ar&&o--}const l={...this._tab.cur},a=e?{...e}:null,d=s.slice(n,o+1);t?(s.splice(o+1,0,...d),i.row+=d.length,e&&(e.ar+=d.length,e.fr+=d.length),M(this._tab,this._config.maxUndoHistory,{kind:"insert",row:o+1,lines:[...d]},l,a)):(s.splice(n,0,...d),M(this._tab,this._config.maxUndoHistory,{kind:"insert",row:n,lines:[...d]},l,a)),this._tab.dirty=!0,this._tokenCache.clear(),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),(p=(c=this._config).onChange)==null||p.call(c,I(this._tab.doc)),(b=(h=this._config).onCursorChange)==null||b.call(h,{...this._tab.cur})}_moveLines(t){var l,a,d,c;const{doc:s,cur:i}=this._tab,e=this._tab.sel;let n=i.row,o=i.row;if(e){const p=A(e);n=p.ar,o=p.fr,p.fc===0&&p.fr>p.ar&&o--}if(t){if(n===0)return;const p={...this._tab.cur},h=e?{...e}:null,b=n-1,m=s.slice(b,o+1),g=s.splice(n,o-n+1);s.splice(n-1,0,...g),i.row--,e&&(e.ar--,e.fr--);const k=s.slice(b,o+1);M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:b,oldLines:m,newLines:k},p,h)}else{if(o>=s.length-1)return;const p={...this._tab.cur},h=e?{...e}:null,b=o+1,m=s.slice(n,b+1),g=s.splice(n,o-n+1);s.splice(n+1,0,...g),i.row++,e&&(e.ar++,e.fr++);const k=s.slice(n,b+1);M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:n,oldLines:m,newLines:k},p,h)}this._tab.dirty=!0,this._tokenCache.clear(),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),(a=(l=this._config).onChange)==null||a.call(l,I(this._tab.doc)),(c=(d=this._config).onCursorChange)==null||c.call(d,{...this._tab.cur})}_wordSkipRight(t,s){let i=s;const e=t.length;for(;i<e&&/\s/.test(t[i]);)i++;if(i>=e)return i;if(/\w/.test(t[i]))for(;i<e&&/\w/.test(t[i]);)i++;else for(;i<e&&/[^\w\s]/.test(t[i]);)i++;return i}_wordSkipLeft(t,s){let i=s;for(;i>0&&/\s/.test(t[i-1]);)i--;if(i<=0)return i;if(/\w/.test(t[i-1]))for(;i>0&&/\w/.test(t[i-1]);)i--;else for(;i>0&&/[^\w\s]/.test(t[i-1]);)i--;return i}_deleteToLineStart(){var o;const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null;if(this._tab.sel){const l=A(this._tab.sel),a=this._tab.doc.slice(l.ar,l.fr+1);this._tab.cur=O(this._tab),this._tokenCache.clear(),this._tab.dirty=!0;const d=[this._tab.doc[l.ar]??""];M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:l.ar,oldLines:a,newLines:d},t,s);return}const{doc:i,cur:e}=this._tab;if(e.col===0)return;const n=i[e.row]??"";i[e.row]=n.slice(e.col),e.col=0,this._tokenCache.invalidateLine(e.row,((o=this._wm.segments[e.row])==null?void 0:o.length)??1),M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:e.row,oldLines:[n],newLines:[i[e.row]]},t,s),this._tab.dirty=!0}_deleteWordLeft(){var a;const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null;if(this._tab.sel){const d=A(this._tab.sel),c=this._tab.doc.slice(d.ar,d.fr+1);this._tab.cur=O(this._tab),this._tokenCache.clear(),this._tab.dirty=!0;const p=[this._tab.doc[d.ar]??""];M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:d.ar,oldLines:c,newLines:p},t,s);return}const{doc:i,cur:e}=this._tab;if(e.col===0){if(e.row>0){const d=i[e.row-1]??"",c=i[e.row]??"",p=d.length;i[e.row-1]=d+c,i.splice(e.row,1),e.row--,e.col=p,this._tokenCache.clear(),M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:e.row,oldLines:[d,c],newLines:[i[e.row]]},t,s),this._tab.dirty=!0}return}const n=i[e.row]??"",o=this._wordSkipLeft(n,e.col),l=n;i[e.row]=n.slice(0,o)+n.slice(e.col),e.col=o,this._tokenCache.invalidateLine(e.row,((a=this._wm.segments[e.row])==null?void 0:a.length)??1),M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:e.row,oldLines:[l],newLines:[i[e.row]]},t,s),this._tab.dirty=!0}_deleteToLineEnd(){var l;const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null;if(this._tab.sel){const a=A(this._tab.sel),d=this._tab.doc.slice(a.ar,a.fr+1);this._tab.cur=O(this._tab),this._tokenCache.clear(),this._tab.dirty=!0;const c=[this._tab.doc[a.ar]??""];M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:a.ar,oldLines:d,newLines:c},t,s);return}const{doc:i,cur:e}=this._tab,n=i[e.row]??"";if(e.col>=n.length)return;const o=n;i[e.row]=n.slice(0,e.col),this._tokenCache.invalidateLine(e.row,((l=this._wm.segments[e.row])==null?void 0:l.length)??1),M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:e.row,oldLines:[o],newLines:[i[e.row]]},t,s),this._tab.dirty=!0}_deleteWordRight(){var a;const t={...this._tab.cur},s=this._tab.sel?{...this._tab.sel}:null;if(this._tab.sel){const d=A(this._tab.sel),c=this._tab.doc.slice(d.ar,d.fr+1);this._tab.cur=O(this._tab),this._tokenCache.clear(),this._tab.dirty=!0;const p=[this._tab.doc[d.ar]??""];M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:d.ar,oldLines:c,newLines:p},t,s);return}const{doc:i,cur:e}=this._tab,n=i[e.row]??"";if(e.col>=n.length){if(e.row<i.length-1){const d=i[e.row+1]??"",c=n;i[e.row]=n+d,i.splice(e.row+1,1),this._tokenCache.clear(),M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:e.row,oldLines:[c,d],newLines:[i[e.row]]},t,s),this._tab.dirty=!0}return}const o=this._wordSkipRight(n,e.col),l=n;i[e.row]=n.slice(0,e.col)+n.slice(o),this._tokenCache.invalidateLine(e.row,((a=this._wm.segments[e.row])==null?void 0:a.length)??1),M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:e.row,oldLines:[l],newLines:[i[e.row]]},t,s),this._tab.dirty=!0}_doUndo(){var s,i;const t=ae(this._tab);t!==null&&(this._extraCursors=t,this._mc.cursors=t,this._mc.searchWord="",this._mc.lastMatchRow=-1,this._mc.lastMatchCol=-1,this._tokenCache.clear(),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),(i=(s=this._config).onChange)==null||i.call(s,I(this._tab.doc)))}_doRedo(){var s,i;const t=le(this._tab);t!==null&&(this._extraCursors=t,this._mc.cursors=t,this._mc.searchWord="",this._mc.lastMatchRow=-1,this._mc.lastMatchCol=-1,this._tokenCache.clear(),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),(i=(s=this._config).onChange)==null||i.call(s,I(this._tab.doc)))}}class ii extends ei{_openFind(t){this._findBar.classList.add("sl-open"),this._replaceRow.style.display=t&&this._config.findReplace?"":"none",this._findInput.focus(),this._findInput.select(),this._runFind(this._findInput.value),this._findMatches.length?(this._findIdx=-1,this._navFind(1)):this._render()}_closeFind(){this._findBar.classList.remove("sl-open"),this._findMatches=[],this._findIdx=-1,this._findCount.textContent="–",this._focusInput(),this._render()}_runFind(t){this._findMatches=Ae(this._tab.doc,t,{caseSensitive:this._findCaseSensitive,useRegex:this._findRegex})}_navFind(t){if(!this._findMatches.length){this._findCount.textContent="0/0";return}this._findIdx=Be(this._findMatches,this._findIdx,t);const s=this._findMatches[this._findIdx];this._tab.cur={row:s.row,col:s.col},this._tab.sel={ar:s.row,ac:s.col,fr:s.row,fc:s.col+s.len},this._scrollIntoView(),this._render(),this._findCount.textContent=`${this._findIdx+1}/${this._findMatches.length}`}_doReplaceOne(){var o,l;if(this._findIdx<0||!this._findMatches.length)return;const t=this._findMatches[this._findIdx],s={...this._tab.cur},i=this._tab.sel?{...this._tab.sel}:null,e=this._tab.doc[t.row]??"";this._tab.doc=He(this._tab.doc,this._findMatches,this._findIdx,this._replaceInput.value),this._tokenCache.clear(),this._tab.dirty=!0;const n=this._tab.doc[t.row]??"";M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:t.row,oldLines:[e],newLines:[n]},s,i),this._runFind(this._findInput.value),this._findMatches.length?(this._findIdx>=this._findMatches.length&&(this._findIdx=0),this._navFind(0)):(this._findCount.textContent="0/0",this._rebuildWrapMap(),this._render()),(l=(o=this._config).onChange)==null||l.call(o,I(this._tab.doc))}_doReplaceAll(){var a,d;if(!this._findMatches.length)return;const t=this._findMatches.length,s={...this._tab.cur},i=this._tab.sel?{...this._tab.sel}:null,e=this._findMatches[0].row,n=this._findMatches[this._findMatches.length-1].row,o=this._tab.doc.slice(e,n+1);this._tab.doc=De(this._tab.doc,this._findMatches,this._replaceInput.value),this._tokenCache.clear(),this._tab.dirty=!0;const l=this._tab.doc.slice(e,n+1);M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:e,oldLines:o,newLines:l},s,i),this._findMatches=[],this._findIdx=-1,this._findCount.textContent=`0/0 (${t} replaced)`,this._rebuildWrapMap(),this._render(),(d=(a=this._config).onChange)==null||d.call(a,I(this._tab.doc))}_bindFindEvents(){var t,s,i,e,n,o,l;this._findInput.addEventListener("input",()=>{this._runFind(this._findInput.value),this._findIdx=-1,this._findMatches.length?this._navFind(1):(this._findCount.textContent="0/0",this._render())}),this._findInput.addEventListener("keydown",a=>{a.key==="Enter"?a.shiftKey?this._navFind(-1):this._navFind(1):a.key==="Escape"&&this._closeFind(),a.stopPropagation()}),this._replaceInput.addEventListener("keydown",a=>{a.key==="Enter"?this._doReplaceOne():a.key==="Escape"&&this._closeFind(),a.stopPropagation()}),(t=this._findBar.querySelector(".sl-find-prev"))==null||t.addEventListener("click",()=>this._navFind(-1)),(s=this._findBar.querySelector(".sl-find-next"))==null||s.addEventListener("click",()=>this._navFind(1)),(i=this._findBar.querySelector(".sl-find-close"))==null||i.addEventListener("click",()=>this._closeFind()),(e=this._findBar.querySelector(".sl-find-case"))==null||e.addEventListener("click",a=>{this._findCaseSensitive=!this._findCaseSensitive,a.target.classList.toggle("sl-active",this._findCaseSensitive),this._runFind(this._findInput.value),this._findIdx=-1,this._findMatches.length?this._navFind(1):(this._findCount.textContent="0/0",this._render())}),(n=this._findBar.querySelector(".sl-find-regex"))==null||n.addEventListener("click",a=>{this._findRegex=!this._findRegex,a.target.classList.toggle("sl-active",this._findRegex),this._runFind(this._findInput.value),this._findIdx=-1,this._findMatches.length?this._navFind(1):(this._findCount.textContent="0/0",this._render())}),(o=this._findBar.querySelector(".sl-replace-one"))==null||o.addEventListener("click",()=>this._doReplaceOne()),(l=this._findBar.querySelector(".sl-replace-all"))==null||l.addEventListener("click",()=>this._doReplaceAll())}}class si extends ii{_acVisible(){return this._acPopup.style.display!=="none"}_acHide(){this._acPopup.style.display="none",this._acItems=[]}_acTrigger(){if(!this._config.autocomplete){this._acHide();return}this._acDebounceTimer!==null&&clearTimeout(this._acDebounceTimer),this._acDebounceTimer=setTimeout(()=>{this._acDebounceTimer=null,this._acTriggerNow()},120)}_acTriggerNow(){if(!this._config.autocomplete){this._acHide();return}const{cur:t,doc:s}=this._tab,i=s[t.row]??"",e=this._config.language==="css",{prefix:n,start:o}=Ie(i,t.col,e);this._acPrefix=n,this._acStartCol=o;const l=[];if(this._config.emmet){const d=jt(i,t.col);if(d){const c=Bt(d.abbr);if(c){this._emmetAcStartCol=d.start;const p=c.replace(/\n/g,"↵ ").slice(0,60);l.push({label:d.abbr,kind:"emmet",detail:p,body:c})}}}const a=n.length>=this._config.autocompletePrefixLength?Re(s,n,{language:this._config.language,extraKeywords:this._config.extraKeywords,extraTypes:this._config.extraTypes,completions:this._allCompletions(),replaceBuiltins:this._config.replaceBuiltins,maxResults:this._config.maxCompletions,provideCompletions:this._config.provideCompletions},t.row,t.col):[];if(this._acItems=[...l,...a],!this._acItems.length){this._acHide();return}this._acSel=0,this._renderAcPopup()}_renderAcPopup(){const t=a=>{switch(a){case"kw":return"K";case"fn":return"f";case"typ":return"T";case"cls":return"C";case"snip":return"S";case"emmet":return"E";default:return"·"}},s=this._acItems[this._acSel];let i="";s!=null&&s.description?i=s.description:(s==null?void 0:s.kind)==="snip"&&s.body?i=s.body.replace(/\$\d/g,"▌"):(s==null?void 0:s.kind)==="emmet"&&s.body&&(i=s.body);const e=this._acItems.map((a,d)=>{const c=d===this._acSel;return`<div class="sl-ac-item${c?" sl-sel":""}" data-i="${d}" role="option" aria-selected="${c}"><span class="sl-ac-badge ${a.kind}">${t(a.kind)}</span><span class="sl-ac-label">${a.label}</span><span class="sl-ac-detail">${a.detail??""}</span></div>`}).join(""),n=i?`<div class="sl-ac-desc"><pre class="sl-ac-desc-body">${i.replace(/</g,"<")}</pre></div>`:"";this._acPopup.innerHTML=`<div class="sl-ac-list">${e}</div>`+n,this._acPopup.style.display="flex",this._posAcPopup();const o=this._acPopup.querySelector(".sl-ac-list"),l=this._acPopup.querySelector(".sl-ac-item.sl-sel");if(o&&l){const a=l.offsetTop,d=a+l.offsetHeight;d>o.scrollTop+o.clientHeight?o.scrollTop=d-o.clientHeight:a<o.scrollTop&&(o.scrollTop=a)}this._acPopup.querySelectorAll(".sl-ac-item").forEach(a=>{a.addEventListener("mousedown",d=>{d.preventDefault(),this._acSel=parseInt(a.dataset.i??"0",10),this._acAccept()})})}_posAcPopup(){const t=this._editorEl.getBoundingClientRect(),s=z(this._wm,this._tab.cur.row,this._tab.cur.col),i=this._config.showGutter?this._config.gutterWidth:0,e=t.left+i+14+this._acStartCol*7.82,n=t.top+(s.visRow*this._config.lineHeight-this._editorEl.scrollTop)+this._config.lineHeight+2,l=!!this._acPopup.querySelector(".sl-ac-desc")?620:300,a=Math.min(this._acItems.length*28+8,320),d=n+a>window.innerHeight-16;this._acPopup.style.left=`${Math.min(e,window.innerWidth-l-16)}px`,this._acPopup.style.top=`${d?n-this._config.lineHeight-2-a:n}px`}_acAccept(){const t=this._acItems[this._acSel];if(!t)return;if(this._acHide(),t.kind==="emmet"&&t.body){const i={...this._tab.cur},e=this._tab.sel?{...this._tab.sel}:null,n=this._tab.cur.row,o=this._tab.doc[n]??"";this._expandBodyAt(t.body,this._emmetAcStartCol);const l=this._tab.doc.slice(n,this._tab.cur.row+1);M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:n,oldLines:[o],newLines:l},i,e);return}if(t.body){const i={...this._tab.cur},e=this._tab.sel?{...this._tab.sel}:null,n=this._tab.cur.row,o=this._tab.doc[n]??"";this._expandBodyAt(t.body,this._acStartCol);const l=this._tab.doc.slice(n,this._tab.cur.row+1);M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:n,oldLines:[o],newLines:l},i,e);return}const s=t.label.slice(this._acPrefix.length);this._insertStr(s,!1),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render()}_allCompletions(){return[...this._config.replaceBuiltins?[]:Te(this._config.language),...this._config.completions]}_emmetCheck(){if(this._emmetTip.style.display="none",!this._config.emmet){this._emmetExpanded=null;return}const{cur:t,doc:s}=this._tab,i=s[t.row]??"",e=jt(i,t.col);if(!e){this._emmetExpanded=null;return}const n=Bt(e.abbr);if(!n){this._emmetExpanded=null;return}this._emmetExpanded={abbr:e.abbr,result:n,start:e.start}}_emmetAccept(){if(!this._emmetExpanded||this._emmetTip.style.display==="none")return!1;const{result:t,start:s}=this._emmetExpanded,i={...this._tab.cur},e=this._tab.sel?{...this._tab.sel}:null,n=this._tab.cur.row,o=this._tab.doc[n]??"";this._emmetExpanded=null,this._emmetTip.style.display="none",this._expandBodyAt(t,s);const l=this._tab.doc.slice(n,this._tab.cur.row+1);return M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:n,oldLines:[o],newLines:l},i,e),!0}_snippetCheck(){if(this._snippetTip.style.display="none",!this._config.snippetExpansion){this._snippetExpanded=null;return}const{cur:t,doc:s}=this._tab,i=s[t.row]??"",e=Me(i,t.col,this._allCompletions());if(!e){this._snippetExpanded=null;return}this._snippetExpanded={snippet:e.snippet,start:e.start}}_snippetAccept(){if(!this._snippetExpanded||this._snippetTip.style.display==="none")return!1;const{snippet:t,start:s}=this._snippetExpanded;if(!t.body)return!1;const i={...this._tab.cur},e=this._tab.sel?{...this._tab.sel}:null,n=this._tab.cur.row,o=this._tab.doc[n]??"";this._snippetExpanded=null,this._snippetTip.style.display="none",this._expandBodyAt(t.body,s);const l=this._tab.doc.slice(n,this._tab.cur.row+1);return M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:n,oldLines:[o],newLines:l},i,e),!0}_expandBodyAt(t,s){var f,C;const{doc:i,cur:e}=this._tab,n=e.row,o=i[e.row]??"",l=o.slice(0,s),a=o.slice(e.col),d=it(o),c=t.split(`
|
|
494
|
+
`).map((_,w)=>w===0?_:d+_),p=c.join(`
|
|
495
|
+
`),h=[],b=/\$(\d+)/g;let m;for(;(m=b.exec(p))!==null;){const _=parseInt(m[1],10),u=p.slice(0,m.index).split(`
|
|
496
|
+
`),y=u.length-1,S=u[y].length,x=(u[y].match(/\$\d+/g)??[]).join("").length,R=n+y,P=(y===0?s:d.length)+(S-x);h.push({n:_,row:R,col:P})}h.sort((_,w)=>_.n===0?1:w.n===0?-1:_.n-w.n);const g=c.map(_=>_.replace(/\$\d+/g,"")),k=g.length===1?[l+g[0]+a]:[l+g[0],...g.slice(1,-1),g[g.length-1]+a];i.splice(e.row,1,...k),h.length>0?(this._snippetSession={stops:h.map(_=>({row:_.row,col:_.col})),idx:0},e.row=h[0].row,e.col=h[0].col):(this._snippetSession=null,e.row+=k.length-1,e.col=(k[k.length-1]??"").length-a.length),this._tokenCache.clear(),this._tab.dirty=!0,this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),(C=(f=this._config).onChange)==null||C.call(f,I(this._tab.doc))}_ctrlD(){if(!this._config.multiCursor)return;const t=!this._mc.searchWord,s=!!this._tab.sel;if(t&&s){const e=this._tab.sel,n=Math.min(e.ac,e.fc),o=Math.max(e.ac,e.fc);if(e.ar===e.fr){const l=(this._tab.doc[e.ar]??"").slice(n,o);l&&(this._mc.searchWord=l,this._mc.lastMatchRow=e.fr,this._mc.lastMatchCol=o)}}const i=fe(this._mc,this._tab.doc,this._tab.cur.row,this._tab.cur.col,this._tab.sel);i&&(t&&!s?(this._tab.sel=i.sel,this._tab.cur.row=i.row,this._tab.cur.col=i.col):(i.row!==this._tab.cur.row||i.col!==this._tab.cur.col)&&(It(this._mc,i.row,i.col,i.sel),this._extraCursors=[...this._mc.cursors]),this._mc.searchWord=i.word,this._mc.lastMatchRow=i.row,this._mc.lastMatchCol=i.col,this._scrollIntoView(),this._render())}}class ni extends si{_scheduleHover(t){this._hoverTip.style.display!=="none"&&(this._hoverTip.style.display="none"),this._hoverTimer!==null&&(clearTimeout(this._hoverTimer),this._hoverTimer=null);const{clientX:s,clientY:i}=t;this._hoverTimer=setTimeout(()=>{this._hoverTimer=null,this._doHover(s,i)},500)}_doHover(t,s){var f,C,_;if(!this._config.hover)return;const i=this._editorEl.getBoundingClientRect(),e=this._logicalScroll(this._editorEl.scrollTop),n=s-i.top+e,o=this._config.showGutter?this._config.gutterWidth:0,l=t-i.left-o-14,a=this._config.lineHeight,d=this._wm.windowVisStart,c=d+this._wm.visualRows.length-1,p=Math.max(d,Math.min(c,Math.floor(n/a))),h=Math.max(0,Math.min((((f=this._wm.visualRows[p-d])==null?void 0:f.text)??"").length,Math.round(l/7.82))),b=et(this._wm,p,h),m=this._tab.doc[b.row]??"",g=ye(m,b.col);if(!g)return;let k=ve(g,this._config.language);if(!k){const w=this._config.completions.find(u=>u.label===g);w&&(w.description||w.detail)&&(k={title:w.label,type:w.detail,body:w.description??""})}if(!k){const w=(_=(C=this._config).provideHover)==null?void 0:_.call(C,{word:g,row:b.row,col:b.col,line:m,language:this._config.language,doc:this._tab.doc});w&&(k=w)}k&&this._showHoverTip(k,t,s)}_showHoverTip(t,s,i){const e=this._hoverTip;let n='<div class="sl-ht-sig">';n+=`<span class="sl-ht-title">${q(t.title)}</span>`,t.type&&(n+=`<code class="sl-ht-type">${q(t.type)}</code>`),n+="</div>",t.title&&t.body&&(n+='<div class="sl-ht-divider"></div>'),t.body&&(n+=`<div class="sl-ht-body">${q(t.body)}</div>`),e.innerHTML=n,e.style.display="block";const o=12,l=18,a=e.offsetWidth||300,d=e.offsetHeight||80;let c=s,p=i+l;p+d>window.innerHeight-o&&(p=i-d-8),c+a>window.innerWidth-o&&(c=window.innerWidth-a-o),c<o&&(c=o),e.style.left=`${c}px`,e.style.top=`${Math.max(o,p)}px`}_hideHover(){this._hoverTimer!==null&&(clearTimeout(this._hoverTimer),this._hoverTimer=null),this._hoverPinned=!1,this._hoverTip.style.display="none"}_openThemePicker(){var s;const t=this._themeManager.all;this._themePanel.innerHTML=`
|
|
497
|
+
<div class="sl-theme-header">
|
|
498
|
+
<div class="sl-theme-title">Color Theme</div>
|
|
499
|
+
<div class="sl-theme-close">✕</div>
|
|
500
|
+
</div>
|
|
501
|
+
<div class="sl-theme-list">
|
|
502
|
+
${t.map(i=>`
|
|
503
|
+
<div class="sl-theme-item${i.id===this._themeManager.activeId?" sl-active":""}" data-id="${i.id}">
|
|
504
|
+
<div class="sl-theme-swatch">
|
|
505
|
+
${i.tokens.bg0?`<span style="background:${i.tokens.bg0}"></span>`:""}
|
|
506
|
+
<span style="background:${i.tokens.accent}"></span>
|
|
507
|
+
<span style="background:${i.tokens.tokStr}"></span>
|
|
508
|
+
<span style="background:${i.tokens.tokFn}"></span>
|
|
509
|
+
</div>
|
|
510
|
+
<div>
|
|
511
|
+
<div class="sl-theme-name">${i.name}<span class="sl-theme-tag${i.light?" sl-light":""}">${i.light?"Light":"Dark"}</span></div>
|
|
512
|
+
<div class="sl-theme-desc">${i.description}</div>
|
|
513
|
+
</div>
|
|
514
|
+
<div class="sl-theme-check">✓</div>
|
|
515
|
+
</div>
|
|
516
|
+
`).join("")}
|
|
517
|
+
</div>
|
|
518
|
+
`,this._themeOverlay.style.display="block",(s=this._themePanel.querySelector(".sl-theme-close"))==null||s.addEventListener("click",()=>{this._themeOverlay.style.display="none"}),this._themeOverlay.addEventListener("click",i=>{i.target===this._themeOverlay&&(this._themeOverlay.style.display="none")},{once:!0}),this._themePanel.querySelectorAll(".sl-theme-item").forEach(i=>{i.addEventListener("click",()=>{const e=i.dataset.id??"";this._applyTheme(e),this._themePanel.querySelectorAll(".sl-theme-item").forEach(n=>n.classList.remove("sl-active")),i.classList.add("sl-active")})})}_applyTheme(t){this._themeManager.apply(t),this._applyTokenOverrides(),this._mmColors=ut(s=>nt(s,this._host)),this._tokenCache.clear(),this._render()}}class ri extends ni{_posFromMouse(t){var h;const s=this._editorEl.getBoundingClientRect(),i=this._logicalScroll(this._editorEl.scrollTop),e=t.clientY-s.top+i,n=this._config.showGutter?this._config.gutterWidth:0,o=t.clientX-s.left-n-14,l=this._config.lineHeight,a=this._wm.windowVisStart,d=a+this._wm.visualRows.length-1,c=Math.max(a,Math.min(d,Math.floor(e/l))),p=Math.max(0,Math.min((((h=this._wm.visualRows[c-a])==null?void 0:h.text)??"").length,Math.round(o/7.82)));return et(this._wm,c,p)}_bindEditorEvents(){this._vpEl.addEventListener("mousedown",t=>this._onFoldBtnClick(t)),this._editorEl.addEventListener("mousedown",t=>{var i,e;if(t.button!==0)return;t.preventDefault(),this._focusInput(),this._acHide(),this._snippetSession=null,this._emmetTip.style.display="none",t.altKey||(At(this._mc),this._extraCursors=[]);const s=this._posFromMouse(t);if(t.altKey&&t.detail===1&&!t.shiftKey&&this._config.multiCursor){It(this._mc,s.row,s.col,null),this._extraCursors=[...this._mc.cursors],this._render();return}if(t.shiftKey&&t.detail===1){const n=this._tab.sel?{row:this._tab.sel.ar,col:this._tab.sel.ac}:{row:this._tab.cur.row,col:this._tab.cur.col};this._tab.cur={...s},this._tab.sel={ar:n.row,ac:n.col,fr:s.row,fc:s.col},n.row===s.row&&n.col===s.col&&(this._tab.sel=null),this._isDragging=!1,L(this._tab),this._render(),(e=(i=this._config).onSelectionChange)==null||e.call(i,this._tab.sel?{...this._tab.sel}:null);return}if(this._tab.cur={...s},t.detail===3)this._tab.sel={ar:s.row,ac:0,fr:s.row,fc:(this._tab.doc[s.row]??"").length},this._tab.cur.col=this._tab.sel.fc;else if(t.detail===2&&this._config.wordSelection){const n=this._tab.doc[s.row]??"",o=this._wordStart(n,s.col),l=this._wordEnd(n,s.col);o!==l?(this._tab.sel={ar:s.row,ac:o,fr:s.row,fc:l},this._tab.cur.col=l):this._tab.sel=null}else this._tab.sel=null,this._isDragging=!0,this._dragAnchor={...s};L(this._tab),this._render()}),this._editorEl.addEventListener("mousemove",t=>{if(this._config.hover&&!this._hoverPinned&&!this._isDragging&&this._scheduleHover(t),!this._isDragging||!this._dragAnchor)return;const s=this._posFromMouse(t);this._tab.cur={...s},s.row!==this._dragAnchor.row||s.col!==this._dragAnchor.col?this._tab.sel={ar:this._dragAnchor.row,ac:this._dragAnchor.col,fr:s.row,fc:s.col}:this._tab.sel=null,L(this._tab),this._render()}),this._editorEl.addEventListener("mouseleave",()=>{this._hoverPinned||this._hideHover()}),window.addEventListener("mouseup",this._onWinMouseUp),this._editorEl.addEventListener("scroll",this._onEditorScroll,{passive:!0}),window.addEventListener("resize",this._onWinResize),this._inputEl.addEventListener("keydown",t=>this._onKeyDown(t)),this._inputEl.addEventListener("input",t=>this._onInput(t)),this._inputEl.addEventListener("paste",t=>{var i,e,n,o,l;if(t.preventDefault(),this._config.readOnly)return;const s=(i=t.clipboardData??window.clipboardData)==null?void 0:i.getData("text/plain");if(s){if(this._linewiseCopy&&!this._tab.sel){const a={...this._tab.cur},d=this._tab.cur.row,c=s.endsWith(`
|
|
519
|
+
`)?s.slice(0,-1):s;this._tab.doc.splice(d,0,c),this._tab.cur.row=d+1,M(this._tab,this._config.maxUndoHistory,{kind:"insert",row:d,lines:[c]},a,null),this._tab.dirty=!0,this._tokenCache.clear(),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),(n=(e=this._config).onChange)==null||n.call(e,I(this._tab.doc)),(l=(o=this._config).onCursorChange)==null||l.call(o,{...this._tab.cur});return}this._insertStr(s,!1),this._tokenCache.clear(),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render()}}),this._editorEl.addEventListener("mousedown",()=>setTimeout(()=>this._focusInput(),0)),this._inputEl.addEventListener("focus",()=>{var t,s;return(s=(t=this._config).onFocus)==null?void 0:s.call(t)}),this._inputEl.addEventListener("blur",()=>{var t,s;return(s=(t=this._config).onBlur)==null?void 0:s.call(t)})}_onKeyDown(t){var o,l,a,d,c,p,h,b,m;const s=t.ctrlKey||t.metaKey,i=t.shiftKey,e=t.altKey,n=this._config.readOnly;if(this._hideHover(),this._acVisible()){if(t.key==="ArrowDown"){t.preventDefault(),this._acSel=Math.min(this._acItems.length-1,this._acSel+1),this._renderAcPopup();return}if(t.key==="ArrowUp"){t.preventDefault(),this._acSel=Math.max(0,this._acSel-1),this._renderAcPopup();return}if(t.key==="Tab"||t.key==="Enter"){t.preventDefault(),this._acAccept();return}if(t.key==="Escape"){this._acHide();return}}if(e&&(t.key==="z"||t.key==="Z"||t.key==="Ω")){t.preventDefault(),this._toggleWrap();return}if(s&&t.key==="z"&&!i){t.preventDefault(),n||this._doUndo();return}if(s&&(t.key==="y"||i&&t.key==="z")){t.preventDefault(),n||this._doRedo();return}if(s&&t.key==="a"){t.preventDefault(),this._selectAll();return}if(s&&t.key==="c"){t.preventDefault(),this._doCopy();return}if(s&&t.key==="x"){t.preventDefault(),n||this._doCut();return}if(s&&t.key==="f"){t.preventDefault(),this._config.find&&this._openFind(!1);return}if(s&&t.key==="h"){t.preventDefault(),this._config.find&&this._config.findReplace&&this._openFind(!0);return}if(s&&t.key==="g"){t.preventDefault(),this._config.goToLine&&this._openGoToLine();return}if(s&&t.key==="d"){t.preventDefault(),!n&&this._config.multiCursor&&this._ctrlD();return}if(s&&i&&t.key==="d"){t.preventDefault(),n||this._duplicateLine();return}if(s&&t.key==="/"){t.preventDefault(),n||this._toggleComment();return}if(s&&t.key==="k"){t.preventDefault(),n||this._deleteLine();return}if(s&&t.key==="Enter"){t.preventDefault(),n||(i?this._doInsertLineAbove():this._doInsertLineBelow());return}if(t.key==="Escape"){this._tab.sel=null,this._acHide(),this._closeFind(),this._closeGoToLine(),this._emmetTip.style.display="none",this._snippetTip.style.display="none",this._snippetExpanded=null,this._snippetSession=null,At(this._mc),this._extraCursors=[],this._mc.searchWord="",this._render();return}if(n){this._handleArrowKeys(t,s,i);return}if(t.key==="Tab"){if(t.preventDefault(),this._snippetSession){if(i){if(this._snippetSession.idx>0){this._snippetSession.idx--;const g=this._snippetSession.stops[this._snippetSession.idx];this._tab.cur.row=g.row,this._tab.cur.col=g.col,this._tab.sel=null,L(this._tab),this._scrollIntoView(),this._render()}}else if(this._snippetSession.idx++,this._snippetSession.idx>=this._snippetSession.stops.length)this._snippetSession=null;else{const g=this._snippetSession.stops[this._snippetSession.idx];this._tab.cur.row=g.row,this._tab.cur.col=g.col,this._tab.sel=null,L(this._tab),this._scrollIntoView(),this._render()}return}if(!i&&this._emmetAccept()||!i&&this._snippetAccept())return;i?this._unindentSel():this._indentSel(),L(this._tab),this._scrollIntoView(),this._rebuildWrapMap(),this._render();return}if(t.key==="Backspace"){if(t.preventDefault(),this._extraCursors.length){this._snippetSession=null;const g=t.metaKey,k=t.altKey||t.ctrlKey,f=this._tab.doc.slice(),C={...this._tab.cur},_=this._tab.sel?{...this._tab.sel}:null,w=this._extraCursors.map(S=>({...S,sel:S.sel?{...S.sel}:null})),u=dt(this._tab.doc,this._tab.cur.row,this._tab.cur.col,this._tab.sel,this._extraCursors,(S,x,R,P)=>{if(P){const j=A(P);return{fromRow:j.ar,fromCol:j.ac,toRow:j.fr,toCol:j.fc}}return g?R===0?null:{fromRow:x,fromCol:0,toRow:x,toCol:R}:k?R===0?x===0?null:{fromRow:x-1,fromCol:(S[x-1]??"").length,toRow:x,toCol:0}:{fromRow:x,fromCol:this._wordSkipLeft(S[x]??"",R),toRow:x,toCol:R}:R===0?x===0?null:{fromRow:x-1,fromCol:(S[x-1]??"").length,toRow:x,toCol:0}:{fromRow:x,fromCol:R-1,toRow:x,toCol:R}});this._tab.doc=u.doc,this._tab.cur.row=u.primaryRow,this._tab.cur.col=u.primaryCol,this._tab.sel=null,this._extraCursors=u.extraCursors,this._mc.cursors=u.extraCursors,this._mc.searchWord="",this._mc.lastMatchRow=-1,this._mc.lastMatchCol=-1;const y=lt(f,this._tab.doc);(y.oldLines.length||y.newLines.length)&&M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:y.row,oldLines:y.oldLines,newLines:y.newLines},C,_,w,u.extraCursors)}else if(t.metaKey)this._snippetSession=null,this._deleteToLineStart();else if(t.altKey||t.ctrlKey)this._snippetSession=null,this._deleteWordLeft();else{if(this._snippetSession){const g=this._snippetSession.stops[this._snippetSession.idx];if(this._tab.cur.row===g.row&&this._tab.cur.col>g.col){for(let k=this._snippetSession.idx+1;k<this._snippetSession.stops.length;k++){const f=this._snippetSession.stops[k];f.row===g.row&&f.col>=this._tab.cur.col&&f.col--}g.col--}else this._snippetSession=null}this._doBackspace()}this._tokenCache.clear(),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),this._acTrigger(),this._emmetCheck(),this._snippetCheck(),(l=(o=this._config).onChange)==null||l.call(o,I(this._tab.doc));return}if(t.key==="Delete"){if(t.preventDefault(),this._snippetSession=null,this._extraCursors.length){const g=t.metaKey,k=t.altKey||t.ctrlKey,f=this._tab.doc.slice(),C={...this._tab.cur},_=this._tab.sel?{...this._tab.sel}:null,w=this._extraCursors.map(S=>({...S,sel:S.sel?{...S.sel}:null})),u=dt(this._tab.doc,this._tab.cur.row,this._tab.cur.col,this._tab.sel,this._extraCursors,(S,x,R,P)=>{if(P){const N=A(P);return{fromRow:N.ar,fromCol:N.ac,toRow:N.fr,toCol:N.fc}}const j=S[x]??"";return g?R>=j.length?null:{fromRow:x,fromCol:R,toRow:x,toCol:j.length}:k?R>=j.length?x>=S.length-1?null:{fromRow:x,fromCol:R,toRow:x+1,toCol:0}:{fromRow:x,fromCol:R,toRow:x,toCol:this._wordSkipRight(j,R)}:R<j.length?{fromRow:x,fromCol:R,toRow:x,toCol:R+1}:x<S.length-1?{fromRow:x,fromCol:R,toRow:x+1,toCol:0}:null});this._tab.doc=u.doc,this._tab.cur.row=u.primaryRow,this._tab.cur.col=u.primaryCol,this._tab.sel=null,this._extraCursors=u.extraCursors,this._mc.cursors=u.extraCursors,this._mc.searchWord="",this._mc.lastMatchRow=-1,this._mc.lastMatchCol=-1;const y=lt(f,this._tab.doc);(y.oldLines.length||y.newLines.length)&&M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:y.row,oldLines:y.oldLines,newLines:y.newLines},C,_,w,u.extraCursors)}else t.metaKey?this._deleteToLineEnd():t.altKey||t.ctrlKey?this._deleteWordRight():this._doDelete();this._tokenCache.clear(),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),(d=(a=this._config).onChange)==null||d.call(a,I(this._tab.doc));return}if(t.key==="Enter"){t.preventDefault(),this._snippetSession=null,this._doEnter(),this._tokenCache.clear(),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),(p=(c=this._config).onChange)==null||p.call(c,I(this._tab.doc));return}if(!s&&!e&&this._config.autoClosePairs[t.key]){t.preventDefault();const g={...this._tab.cur},k=this._tab.sel?{...this._tab.sel}:null;let f,C;if(this._tab.sel){const y=A(this._tab.sel);f=y.ar,C=this._tab.doc.slice(y.ar,y.fr+1),this._tab.cur=O(this._tab)}else f=this._tab.cur.row,C=[this._tab.doc[f]??""];const{doc:_,cur:w}=this._tab,u=_[w.row]??"";_[w.row]=u.slice(0,w.col)+t.key+this._config.autoClosePairs[t.key]+u.slice(w.col),w.col++,this._tokenCache.invalidateLine(w.row,((h=this._wm.segments[w.row])==null?void 0:h.length)??1),this._tab.dirty=!0,M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:f,oldLines:C,newLines:[_[w.row]]},g,k),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),(m=(b=this._config).onChange)==null||m.call(b,I(this._tab.doc));return}if(!s&&!e&&Object.values(this._config.autoClosePairs).includes(t.key)){const{doc:g,cur:k}=this._tab;if((g[k.row]??"")[k.col]===t.key){t.preventDefault(),k.col++,L(this._tab),this._scrollIntoView(),this._render();return}}if(i&&e&&!s&&(t.key==="ArrowUp"||t.key==="ArrowDown")){t.preventDefault(),this._duplicateLines(t.key==="ArrowDown");return}if(e&&!s&&(t.key==="ArrowUp"||t.key==="ArrowDown")){t.preventDefault(),this._moveLines(t.key==="ArrowUp");return}this._handleArrowKeys(t,s,i)}_handleArrowKeys(t,s,i){var b,m,g,k,f,C;const{doc:e,cur:n}=this._tab,o=this._config.lineHeight,l=t.metaKey,a=t.ctrlKey,d=t.altKey,c=(_,w)=>{if(i){this._tab.sel||(this._tab.sel={ar:n.row,ac:n.col,fr:n.row,fc:n.col}),n.row=_,n.col=w;const u=this._tab.sel;u.fr=_,u.fc=w,u.ar===u.fr&&u.ac===u.fc&&(this._tab.sel=null)}else this._tab.sel=null,n.row=_,n.col=w},p=_=>{const u=(e[_]??"").search(/\S/);return u===-1||n.col===u?0:u},h=()=>({row:e.length-1,col:(e[e.length-1]??"").length});switch(t.key){case"ArrowRight":if(t.preventDefault(),this._tab.sel&&!i){const _=A(this._tab.sel);n.row=_.fr,n.col=_.fc,this._tab.sel=null;break}if(l)c(n.row,(e[n.row]??"").length);else if(a||d){const _=e[n.row]??"";if(n.col>=_.length)n.row<e.length-1&&c(n.row+1,0);else{const w=this._wordSkipRight(_,n.col);c(n.row,w)}}else n.col<(e[n.row]??"").length?c(n.row,n.col+1):n.row<e.length-1&&c(n.row+1,0);break;case"ArrowLeft":if(t.preventDefault(),this._tab.sel&&!i){const _=A(this._tab.sel);n.row=_.ar,n.col=_.ac,this._tab.sel=null;break}if(l)c(n.row,p(n.row));else if(a||d)if(n.col===0)n.row>0&&c(n.row-1,(e[n.row-1]??"").length);else{const _=this._wordSkipLeft(e[n.row]??"",n.col);c(n.row,_)}else n.col>0?c(n.row,n.col-1):n.row>0&&c(n.row-1,(e[n.row-1]??"").length);break;case"ArrowDown":if(t.preventDefault(),l){const _=h();c(_.row,_.col)}else if(this._config.wordWrap){const _=z(this._wm,n.row,n.col),w=this._wm.windowVisStart,u=Math.min(this._wm.totalVisualRows-1,_.visRow+1),y=et(this._wm,u,Math.min(_.colInSeg,(((b=this._wm.visualRows[u-w])==null?void 0:b.text)??"").length));c(y.row,y.col)}else{let _=Math.min(e.length-1,n.row+1);for(const[w,u]of this._foldedLines)if(_>w&&_<=u){_=Math.min(e.length-1,u+1);break}c(_,Math.min(n.col,(e[_]??"").length))}break;case"ArrowUp":if(t.preventDefault(),l)c(0,0);else if(this._config.wordWrap){const _=z(this._wm,n.row,n.col),w=this._wm.windowVisStart,u=Math.max(0,_.visRow-1),y=et(this._wm,u,Math.min(_.colInSeg,(((m=this._wm.visualRows[u-w])==null?void 0:m.text)??"").length));c(y.row,y.col)}else{let _=Math.max(0,n.row-1);for(const[w,u]of this._foldedLines)if(_>w&&_<=u){_=w;break}c(_,Math.min(n.col,(e[_]??"").length))}break;case"Home":t.preventDefault(),a?c(0,0):c(n.row,p(n.row));break;case"End":if(t.preventDefault(),a){const _=h();c(_.row,_.col)}else c(n.row,(e[n.row]??"").length);break;case"PageDown":t.preventDefault();{const _=Math.max(1,Math.floor(this._editorEl.clientHeight/o)-1),w=Math.min(e.length-1,n.row+_);c(w,Math.min(n.col,(e[w]??"").length)),this._editorEl.scrollTop+=this._editorEl.clientHeight-o;break}case"PageUp":t.preventDefault();{const _=Math.max(1,Math.floor(this._editorEl.clientHeight/o)-1),w=Math.max(0,n.row-_);c(w,Math.min(n.col,(e[w]??"").length)),this._editorEl.scrollTop-=this._editorEl.clientHeight-o;break}default:return}if(this._extraCursors.length){const _=(w,u)=>{const S=(e[w]??"").search(/\S/);return S===-1||u===S?0:S};this._extraCursors=this._extraCursors.map(w=>{let u=w.row,y=w.col;if(!i&&w.sel){const S=A(w.sel);if(t.key==="ArrowLeft")return{row:S.ar,col:S.ac,sel:null};if(t.key==="ArrowRight")return{row:S.fr,col:S.fc,sel:null};y=w.col}switch(t.key){case"ArrowRight":if(l)y=(e[u]??"").length;else if(a||d){const S=e[u]??"";y>=S.length?u<e.length-1&&(u++,y=0):y=this._wordSkipRight(S,y)}else y<(e[u]??"").length?y++:u<e.length-1&&(u++,y=0);break;case"ArrowLeft":l?y=_(u,y):a||d?y===0?u>0&&(u--,y=(e[u]??"").length):y=this._wordSkipLeft(e[u]??"",y):y>0?y--:u>0&&(u--,y=(e[u]??"").length);break;case"ArrowDown":l?(u=e.length-1,y=(e[u]??"").length):(u=Math.min(e.length-1,u+1),y=Math.min(w.col,(e[u]??"").length));break;case"ArrowUp":l?(u=0,y=0):(u=Math.max(0,u-1),y=Math.min(w.col,(e[u]??"").length));break;case"Home":a?(u=0,y=0):y=_(u,y);break;case"End":a&&(u=e.length-1),y=(e[u]??"").length;break}return y=Math.max(0,Math.min(y,(e[u]??"").length)),{row:u,col:y,sel:i?w.sel:null}}),this._extraCursors=this._extraCursors.filter(w=>!(w.row===this._tab.cur.row&&w.col===this._tab.cur.col)),this._mc.cursors=this._extraCursors}L(this._tab),this._scrollIntoView(),this._acHide(),(k=(g=this._config).onCursorChange)==null||k.call(g,{...this._tab.cur}),(C=(f=this._config).onSelectionChange)==null||C.call(f,this._tab.sel?{...this._tab.sel}:null),this._render()}_isWordChar(t){const s=this._config.wordSeparators;return s?t.trim()!==""&&!s.includes(t):/[\w$]/.test(t)}_wordStart(t,s){let i=s;for(;i>0&&this._isWordChar(t[i-1]);)i--;return i}_wordEnd(t,s){let i=s;for(;i<t.length&&this._isWordChar(t[i]);)i++;return i}_onInput(t){var n,o,l,a;if(this._config.readOnly){t.target.value="";return}const s=t.target,i=s.value;if(s.value="",!i||i==="Ω")return;const e=i.replace(/[\x00-\x08\x0a-\x1f\x7f]/g,"");if(e){if(this._extraCursors.length){this._snippetSession=null;const d=this._tab.doc.slice(),c={...this._tab.cur},p=this._tab.sel?{...this._tab.sel}:null,h=this._extraCursors.map(_=>({..._,sel:_.sel?{..._.sel}:null}));let b=this._tab.doc,m=this._tab.cur.row,g=this._tab.cur.col,k=this._extraCursors;if(this._tab.sel||this._extraCursors.some(_=>_.sel)){const _=dt(b,m,g,this._tab.sel,k,(w,u,y,S)=>{if(!S)return null;const x=A(S);return{fromRow:x.ar,fromCol:x.ac,toRow:x.fr,toCol:x.fc}});b=_.doc,m=_.primaryRow,g=_.primaryCol,k=_.extraCursors,this._tab.sel=null,this._mc.searchWord="",this._mc.lastMatchRow=-1,this._mc.lastMatchCol=-1}const f=ue(b,m,g,k,e);this._tab.doc=f.doc,this._tab.cur.row=f.primaryRow,this._tab.cur.col=f.primaryCol,this._extraCursors=f.extraCursors,this._mc.cursors=f.extraCursors,this._tab.dirty=!0;const C=lt(d,this._tab.doc);(C.oldLines.length||C.newLines.length)&&M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:C.row,oldLines:C.oldLines,newLines:C.newLines},c,p,h,this._extraCursors),(o=(n=this._config).onChange)==null||o.call(n,I(this._tab.doc))}else{const d=this._tab.cur.row,c=this._tab.cur.col;if(this._insertStr(e,!0),this._snippetSession){const p=this._snippetSession,h=p.stops[p.idx];if(this._tab.cur.row===h.row){const b=this._tab.cur.col-c;for(let m=p.idx+1;m<p.stops.length;m++){const g=p.stops[m];g.row===d&&g.col>=c&&(g.col+=b)}h.col=this._tab.cur.col}else this._snippetSession=null}}this._tokenCache.clear(),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render(),this._acTrigger(),this._emmetCheck(),this._snippetCheck(),(a=(l=this._config).onCursorChange)==null||a.call(l,{...this._tab.cur})}}_bindMinimapEvents(){const t=this._minimapWrap;t.addEventListener("mousemove",s=>{if(this._mmDragMode!=="none")return;const i=s.clientY-t.getBoundingClientRect().top,{sliderTop:e,sliderHeight:n}=pt(this._tab.doc.length,this._logicalScroll(this._editorEl.scrollTop),this._editorEl.clientHeight,t.clientHeight,this._config.lineHeight);t.style.cursor=i>=e&&i<=e+n?"grab":"pointer"}),t.addEventListener("mousedown",s=>{s.preventDefault();const i=t.clientHeight,e=s.clientY-t.getBoundingClientRect().top,{sliderTop:n,sliderHeight:o}=pt(this._tab.doc.length,this._logicalScroll(this._editorEl.scrollTop),this._editorEl.clientHeight,i,this._config.lineHeight);if(e>=n&&e<=n+o)this._mmDragMode="slider",this._mmSliderOffset=e-n,this._mmDragStartY=s.clientY,this._mmDragStartScroll=this._editorEl.scrollTop,t.style.cursor="grabbing";else{this._mmDragMode="jump";const l=_e(e,this._tab.doc.length,this._logicalScroll(this._editorEl.scrollTop),this._editorEl.clientHeight,i,this._config.lineHeight);this._editorEl.scrollTop=this._domScroll(l),this._mmDragStartY=s.clientY,this._mmDragStartScroll=this._editorEl.scrollTop,this._render()}}),window.addEventListener("mousemove",this._onWinMmMouseMove),window.addEventListener("mouseup",this._onWinMmMouseUp)}}class Yt extends ri{getValue(){return I(this._tab.doc)}setValue(t){var o,l;const s={...this._tab.cur},i=this._tab.sel?{...this._tab.sel}:null,e=[...this._tab.doc];this._tab.doc=Mt(t),this._tab.cur={row:0,col:0},this._tab.sel=null;const n=[...this._tab.doc];M(this._tab,this._config.maxUndoHistory,{kind:"replace",row:0,oldLines:e,newLines:n},s,i),this._tokenCache.clear(),this._foldedLines.clear(),this._rebuildWrapMap(),this._render(),(l=(o=this._config).onChange)==null||l.call(o,t)}getCursor(){return{...this._tab.cur}}setCursor(t){this._tab.cur={...t},L(this._tab),this._scrollIntoView(),this._render()}getSelection(){return this._tab.sel?{...this._tab.sel}:null}setSelection(t){this._tab.sel=t,this._render()}insertText(t){this._config.readOnly||(this._insertStr(t,!1),this._rebuildWrapMap(),L(this._tab),this._scrollIntoView(),this._render())}setTheme(t){this._applyTheme(t)}updateConfig(t){const s=qt(t);if(s.autoClosePairs!==void 0){const i=s.autoClosePairs;this._config.autoClosePairs=Object.keys(i).length===0?{}:{...this._config.autoClosePairs,...i};const{autoClosePairs:e,...n}=s;Object.assign(this._config,n)}else Object.assign(this._config,s);if(s.readOnly!==void 0&&this._inputEl.setAttribute("aria-readonly",String(!!s.readOnly)),t.theme!==void 0&&this.setTheme(t.theme),(t.wordWrap!==void 0||t.wrapColumn!==void 0)&&this._rebuildWrapMap(),t.showMinimap!==void 0){const i=this._shadow.querySelector(".sl-layout");t.showMinimap?i.contains(this._minimapWrap)||i.appendChild(this._minimapWrap):this._minimapWrap.remove()}t.showStatusBar!==void 0&&(t.showStatusBar?this._shadow.contains(this._statusBar)||this._shadow.appendChild(this._statusBar):this._statusBar.remove()),(t.fontFamily!==void 0||t.fontSize!==void 0||t.lineHeight!==void 0||t.cursorBlinkRate!==void 0||t.cursorStyle!==void 0||t.gutterWidth!==void 0||t.minimapWidth!==void 0||t.showGutter!==void 0||t.tokenColors!==void 0)&&this._applyDynamicStyles(),(t.language!==void 0||t.extraKeywords!==void 0||t.extraTypes!==void 0||t.renderWhitespace!==void 0||t.completions!==void 0||t.provideTokens!==void 0)&&this._tokenCache.clear(),t.find===!1?this._closeFind():t.findReplace===!1&&(this._replaceRow.style.display="none"),t.goToLine===!1&&this._closeGoToLine(),t.placeholder!==void 0&&(this._placeholderEl.textContent=t.placeholder),this._render()}focus(){this._focusInput()}getThemes(){return this._themeManager.allIds}registerTheme(t){this._themeManager.register(t)}undo(){this._doUndo()}redo(){this._doRedo()}executeCommand(t){const s=this._config.readOnly;switch(t){case"undo":s||this.undo();break;case"redo":s||this.redo();break;case"selectAll":this._selectAll();break;case"copy":this._doCopy();break;case"cut":s||this._doCut();break;case"toggleComment":s||this._toggleComment();break;case"duplicateLine":s||this._duplicateLine();break;case"deleteLine":s||this._deleteLine();break;case"toggleWordWrap":this._toggleWrap();break;case"find":this._config.find&&this._openFind(!1);break;case"findReplace":this._config.find&&this._config.findReplace&&this._openFind(!0);break;case"indentLine":s||this._indentSel();break;case"outdentLine":s||this._unindentSel();break;default:console.warn(`[syncline-editor] executeCommand: unknown command "${t}"`);break}}destroy(){this._destroyBase()}}function oi(r,t){return new Yt(r,t)}D.BUILT_IN_THEMES=Kt,D.SynclineEditor=Yt,D.THEME_DRACULA=Ut,D.THEME_GITHUB_LIGHT=Ft,D.THEME_MDX_DARK=zt,D.THEME_MDX_LIGHT=Vt,D.THEME_MONOKAI=Ot,D.THEME_SOLARIZED_LIGHT=Gt,D.THEME_VR_DARK=$t,D.THEME_VSCODE_DARK=Nt,D.createEditor=oi,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
|
|
520
|
+
//# sourceMappingURL=syncline-editor.umd.js.map
|