@synclineapi/editor 2.0.0 → 3.0.1

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.
@@ -1,5 +1,5 @@
1
- (function(E,B){typeof exports=="object"&&typeof module<"u"?B(exports):typeof define=="function"&&define.amd?define(["exports"],B):(E=typeof globalThis<"u"?globalThis:E||self,B(E.SynclineEditor={}))})(this,function(E){"use strict";var Ut=Object.defineProperty;var Gt=(E,B,z)=>B in E?Ut(E,B,{enumerable:!0,configurable:!0,writable:!0,value:z}):E[B]=z;var u=(E,B,z)=>Gt(E,typeof B!="symbol"?B+"":B,z);const Fe={typescript:"//",javascript:"//",css:"//",json:"",markdown:"",text:""},ee=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"]),Ue=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"]),Ge=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"]),ze=new Set(["null","true","false"]),ue=new Set,te=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"]),Ke=new Set(["number","string","boolean","object","Promise","Array","Map","Set","HTMLElement","KeyboardEvent","Float64Array","EventListener","Document","Window","Node","Element","Event","MouseEvent","CustomEvent"]),qe=new Set,Ve=new Set,fe=new Set,ge={typescript:ee,javascript:Ue,css:Ge,json:ze,markdown:ue,text:ue},be={typescript:te,javascript:Ke,css:qe,json:Ve,markdown:fe,text:fe};function me(s,e){return{fileId:s,doc:[...e],cur:{row:0,col:0},sel:null,dirty:!1,undoStack:[],redoStack:[],scrollTop:0}}function S(s,e=300){const t={doc:[...s.doc],cur:{...s.cur},sel:s.sel?{...s.sel}:null};s.undoStack.push(t),s.undoStack.length>e&&s.undoStack.shift(),s.redoStack=[],s.dirty=!0}function Ye(s){if(!s.undoStack.length)return!1;const e={doc:[...s.doc],cur:{...s.cur},sel:s.sel?{...s.sel}:null};s.redoStack.push(e);const t=s.undoStack.pop();return s.doc=t.doc,s.cur=t.cur,s.sel=t.sel,!0}function Je(s){if(!s.redoStack.length)return!1;const e={doc:[...s.doc],cur:{...s.cur},sel:s.sel?{...s.sel}:null};s.undoStack.push(e);const t=s.redoStack.pop();return s.doc=t.doc,s.cur=t.cur,s.sel=t.sel,!0}function I(s){const{doc:e,cur:t}=s;t.row=Math.max(0,Math.min(e.length-1,t.row)),t.col=Math.max(0,Math.min((e[t.row]??"").length,t.col))}function $(s){const{ar:e,ac:t,fr:i,fc:r}=s;return e<i||e===i&&t<=r?s:{ar:i,ac:r,fr:e,fc:t}}function _e(s,e,t){if(!s)return null;const i=$(s);return e<i.ar||e>i.fr?null:{start:e===i.ar?i.ac:0,end:e===i.fr?i.fc:t}}function Xe(s){if(!s.sel)return 0;const e=$(s.sel);let t=0;for(let i=e.ar;i<=e.fr;i++){const r=s.doc[i]??"",n=i===e.ar?e.ac:0,a=i===e.fr?e.fc:r.length;t+=a-n}return t}function ye(s){if(!s.sel)return"";const e=$(s.sel),t=[];for(let i=e.ar;i<=e.fr;i++){const r=s.doc[i]??"";t.push(r.slice(i===e.ar?e.ac:0,i===e.fr?e.fc:r.length))}return t.join(`
2
- `)}function U(s){const e=s.sel;if(!e)return s.cur;const t=$(e),i=(s.doc[t.ar]??"").slice(0,t.ac),r=(s.doc[t.fr]??"").slice(t.fc);return s.doc.splice(t.ar,t.fr-t.ar+1,i+r),s.sel=null,{row:t.ar,col:t.ac}}function Ze(s,e,t){if(!t||s.length<=e)return[s];const i=[];let r=0;for(;r<s.length;){if(s.length-r<=e){i.push(s.slice(r));break}const n=r+e;let a=-1;for(let l=n;l>r;l--)if(s[l-1]===" "){a=l;break}a===-1?(i.push(s.slice(r,n)),r=n):(i.push(s.slice(r,a)),r=a)}return i}function Qe(s,e,t,i){const r=[],n=[],a=[];let l=-1;for(let o=0;o<s.length;o++){if(o>0&&o<=l){a.push(n.length),r.push([s[o]??""]);continue}a.push(n.length);const c=Ze(s[o]??"",e,t);r.push(c),c.forEach((d,p)=>n.push({docLine:o,segIdx:p,text:d})),i.has(o)&&(l=i.get(o))}return{segments:r,visualRows:n,docToVisArr:a}}function G(s,e,t){const i=s.segments[e]??[""];let r=t;for(let n=0;n<i.length;n++){if(r<=i[n].length||n===i.length-1)return{visRow:s.docToVisArr[e]+n,colInSeg:Math.min(r,i[n].length)};r-=i[n].length}return{visRow:s.docToVisArr[e]??0,colInSeg:0}}function X(s,e,t){var a;const i=s.visualRows[e];if(!i)return{row:0,col:0};const r=s.segments[i.docLine]??[""];let n=Math.min(t,((a=r[i.segIdx])==null?void 0:a.length)??0);for(let l=0;l<i.segIdx;l++)n+=r[l].length;return{row:i.docLine,col:n}}function ie(s,e={}){var d,p;const t=[],i=s.length;let r=0;const n=(h,g,y)=>{y>g&&t.push({cls:h,start:g,end:y})},a=ge[e.language??"typescript"]??ee,l=be[e.language??"typescript"]??te,o=(d=e.extraKeywords)!=null&&d.size?new Set([...a,...e.extraKeywords]):a,c=(p=e.extraTypes)!=null&&p.size?new Set([...l,...e.extraTypes]):l;for(;r<i;){if(s[r]==="/"&&s[r+1]==="/"){n("cmt",r,i);break}if(s[r]==="*"||s[r]==="/"&&s[r+1]==="*"){n("cmt",r,i);break}if(s[r]==="@"){let h=r+1;for(;h<i&&/\w/.test(s[h]);)h++;n("dec",r,h),r=h;continue}if(s[r]==='"'||s[r]==="'"||s[r]==="`"){const h=s[r];let g=r+1;for(;g<i;){if(s[g]==="\\"){g+=2;continue}if(s[g]===h){g++;break}g++}n("str",r,g),r=g;continue}if(/\d/.test(s[r])&&(r===0||!/\w/.test(s[r-1]))){let h=r;for(;h<i&&/[\d._xXa-fA-F]/.test(s[h]);)h++;n("num",r,h),r=h;continue}if(/[a-zA-Z_$]/.test(s[r])){let h=r;for(;h<i&&/[\w$]/.test(s[h]);)h++;const g=s.slice(r,h);o.has(g)?n("kw",r,h):c.has(g)?n("typ",r,h):h<i&&s[h]==="("?n("fn",r,h):/^[A-Z]/.test(g)&&n("cls",r,h),r=h;continue}if(/[=<>!&|+\-*/%^~?:,;.[\]{}()]/.test(s[r])){n("op",r,r+1),r++;continue}r++}return t}function ve(s,e){const t=new Array(s.length).fill("");for(const i of e)for(let r=i.start;r<i.end;r++)t[r]=i.cls;return t}class et{constructor(e=5e3){u(this,"_cache",new Map);u(this,"_maxSize");u(this,"_hits",0);u(this,"_misses",0);u(this,"_evictions",0);this._maxSize=e}get metrics(){return{hits:this._hits,misses:this._misses,evictions:this._evictions,size:this._cache.size}}get(e,t){const i=this._cache.get(e);return i&&i.src===t?(this._hits++,i.segs):(this._misses++,null)}set(e,t,i){this._cache.size>=this._maxSize&&(this._cache.delete(this._cache.keys().next().value),this._evictions++),this._cache.set(e,{src:t,segs:i})}invalidateLine(e,t){for(let i=0;i<t;i++)this._cache.delete(`${e}:${i}`)}clear(){this._cache.clear(),this._hits=0,this._misses=0,this._evictions=0}resetMetrics(){this._hits=0,this._misses=0,this._evictions=0}}const we={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"}},ke={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"}},xe={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"}},Te={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"}},Me={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"}},Ce={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"}},Ee=[we,ke,xe,Te,Me,Ce,{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"}},{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"}}],tt={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 it{constructor(e){u(this,"_registry",new Map);u(this,"_activeId","");u(this,"_root");this._root=e;for(const t of Ee)this._registry.set(t.id,t)}register(e){this._registry.set(e.id,e)}apply(e){let t;typeof e=="string"?(t=this._registry.get(e),t||(console.warn(`[syncline-editor] Unknown theme: "${e}". Falling back to VR Dark.`),t=this._registry.get(""))):(t=e,this._registry.set(t.id,t)),this._activeId=t.id,this._applyTokens(t.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(e){const t=this._root.style;for(const[i,r]of Object.entries(tt))t.setProperty(r,e[i])}}const rt=`
1
+ (function(C,D){typeof exports=="object"&&typeof module<"u"?D(exports):typeof define=="function"&&define.amd?define(["exports"],D):(C=typeof globalThis<"u"?globalThis:C||self,D(C.SynclineEditor={}))})(this,function(C){"use strict";var Ri=Object.defineProperty;var Bi=(C,D,O)=>D in C?Ri(C,D,{enumerable:!0,configurable:!0,writable:!0,value:O}):C[D]=O;var p=(C,D,O)=>Bi(C,typeof D!="symbol"?D+"":D,O);const D=Object.freeze({site:"\0root",clock:0});function O(r){return`${r.site}@${r.clock}`}function de(r,e){return r.site===e.site&&r.clock===e.clock}function he(r){return Object.fromEntries(r)}function Ee(r){return new Map(Object.entries(r))}class ae{constructor(e){p(this,"_chars",new Map);p(this,"_seq",[]);p(this,"_idxDirty",!1);p(this,"_idxMap",new Map);p(this,"siteId");p(this,"_clock",0);p(this,"stateVector",new Map);p(this,"_opLog",[]);this.siteId=e;const t={id:D,after:D,char:"",deleted:!0};this._chars.set(O(D),t),this._seq=[D],this._rebuildIdx()}get clock(){return this._clock}getText(){let e="";for(const t of this._seq){const i=this._chars.get(O(t));i.deleted||(e+=i.char)}return e}get length(){let e=0;for(const t of this._seq)this._chars.get(O(t)).deleted||e++;return e}localInsert(e,t){const i=[];let s=this._visibleIdAt(e-1);for(const n of t){const o=this._genId(),a={type:"insert",id:o,after:s,char:n};this._applyInsert(a,!0),this._opLog.push(a),i.push(a),s=o}return i}localDelete(e,t){const i=this._visibleIdsInRange(e,t),s=[];for(const n of i){const o={type:"delete",id:n};this._applyDelete(o,!0),this._opLog.push(o),s.push(o)}return s}apply(e){const t=O(e.id);if(e.type==="insert"){if(this._chars.has(t))return!1;this._applyInsert(e,!1)}else{const i=this._chars.get(t);if(!i||i.deleted)return!1;this._applyDelete(e,!1)}return this._opLog.push(e),this._updateSV(e.id),!0}getOpsSince(e){return this._opLog.filter(t=>(e.get(t.id.site)??0)<t.id.clock)}getStateVector(){return new Map(this.stateVector)}serialize(){return{siteId:this.siteId,clock:this._clock,ops:[...this._opLog]}}static deserialize(e){const t=new ae(e.siteId);t._clock=e.clock;for(const i of e.ops)t.apply(i);return t}_genId(){return{site:this.siteId,clock:++this._clock}}_updateSV(e){const t=this.stateVector.get(e.site)??0;e.clock>t&&this.stateVector.set(e.site,e.clock),e.clock>=this._clock&&(this._clock=e.clock+1)}_applyInsert(e,t){t&&this._updateSV(e.id);const i={id:e.id,after:e.after,char:e.char,deleted:!1};this._chars.set(O(e.id),i);const s=O(e.after);this._idxDirty&&this._rebuildIdx();let n=(this._idxMap.get(s)??0)+1;for(;n<this._seq.length;){const o=this._seq[n],a=this._chars.get(O(o));if(!de(a.after,e.after))break;if(this._cmp(o,e.id)>0){n++;continue}break}this._seq.splice(n,0,e.id),this._idxDirty=!0}_applyDelete(e,t){t&&this._updateSV(e.id);const i=this._chars.get(O(e.id));i&&(i.deleted=!0)}_cmp(e,t){return e.clock!==t.clock?e.clock-t.clock:e.site<t.site?1:e.site>t.site?-1:0}_rebuildIdx(){this._idxMap.clear();for(let e=0;e<this._seq.length;e++)this._idxMap.set(O(this._seq[e]),e);this._idxDirty=!1}_visibleIdAt(e){if(e<0)return D;let t=0;for(const s of this._seq)if(!(this._chars.get(O(s)).deleted||de(s,D))){if(t===e)return s;t++}let i=D;for(const s of this._seq)this._chars.get(O(s)).deleted||(i=s);return i}_visibleIdsInRange(e,t){const i=[];let s=0;for(const n of this._seq){if(i.length>=t)break;this._chars.get(O(n)).deleted||de(n,D)||(s>=e&&i.push(n),s++)}return i}}function Ie(r,e){if(r===e)return[];if(r.length===0)return[{type:"insert",offset:0,chars:e}];if(e.length===0)return[{type:"delete",offset:0,chars:r}];let t=0;const i=Math.min(r.length,e.length);for(;t<i&&r[t]===e[t];)t++;let s=0;for(;s<r.length-t&&s<e.length-t&&r[r.length-1-s]===e[e.length-1-s];)s++;const n=r.slice(t,r.length-s),o=e.slice(t,e.length-s),a=[];return n.length>0&&a.push({type:"delete",offset:t,chars:n}),o.length>0&&a.push({type:"insert",offset:t,chars:o}),a}const Le=1e4,vt=3e3,Re=["#e06c75","#98c379","#e5c07b","#61afef","#c678dd","#56b6c2","#d19a66","#be5046"];function Be(r){let e=0;for(let t=0;t<r.length;t++)e=e*31+r.charCodeAt(t)>>>0;return Re[e%Re.length]}class Ae{constructor(e,t){p(this,"_local");p(this,"_peers",new Map);p(this,"_transport");p(this,"_unsub",null);p(this,"_heartbeat",null);p(this,"_gcTimer",null);p(this,"_onChange",null);this._transport=e,this._local={siteId:e.siteId,name:t,color:Be(e.siteId),cursor:null,selection:null,updatedAt:Date.now()},this._unsub=e.onMessage(i=>{var n;if(i.type!=="awareness")return;const s=i.state;s.siteId!==e.siteId&&(this._peers.set(s.siteId,s),(n=this._onChange)==null||n.call(this,this._peers))}),this._heartbeat=setInterval(()=>this._broadcast(),vt),this._gcTimer=setInterval(()=>{var n;const i=Date.now();let s=!1;for(const[o,a]of this._peers)i-a.updatedAt>Le&&(this._peers.delete(o),s=!0);s&&((n=this._onChange)==null||n.call(this,this._peers))},Le)}updateCursor(e,t){this._local={...this._local,cursor:{row:e,col:t},updatedAt:Date.now()},this._broadcast()}updateSelection(e,t){this._local={...this._local,selection:{from:e,to:t},updatedAt:Date.now()},this._broadcast()}clearSelection(){this._local={...this._local,selection:null,updatedAt:Date.now()},this._broadcast()}get localState(){return this._local}get peers(){return this._peers}onChange(e){this._onChange=e}broadcast(){this._broadcast()}_broadcast(){this._transport.send({type:"awareness",state:{...this._local,updatedAt:Date.now()}})}destroy(){var e;(e=this._unsub)==null||e.call(this),this._heartbeat&&clearInterval(this._heartbeat),this._gcTimer&&clearInterval(this._gcTimer)}}class fe{constructor(e,t,i,s={}){p(this,"doc");p(this,"awareness");p(this,"_editor");p(this,"_transport");p(this,"_unsub");p(this,"_lastText");p(this,"_suppress",!1);if(this._editor=e,this.doc=t,this._transport=i,this._lastText=e.getValue(),this._lastText){const n=t.localInsert(0,this._lastText);i.send({type:"ops",fromSite:i.siteId,ops:n,sv:he(t.stateVector)})}this.awareness=new Ae(i,s.name??"Peer"),this.awareness.onChange(n=>{var o;return(o=s.onPeersChange)==null?void 0:o.call(s,n)}),e.updateConfig({onChange:n=>this._onEditorChange(n)}),this._unsub=i.onMessage(n=>this._onMessage(n)),i.send({type:"sync-request",fromSite:i.siteId,sv:he(t.stateVector)}),this.awareness.broadcast()}_onEditorChange(e){if(this._suppress)return;const t=this._lastText;this._lastText=e;const i=Ie(t,e);if(i.length===0)return;const s=[],n=i.filter(a=>a.type==="delete"),o=i.filter(a=>a.type==="insert");for(const a of[...n].reverse())s.push(...this.doc.localDelete(a.offset,a.chars.length));for(const a of o)s.push(...this.doc.localInsert(a.offset,a.chars));s.length>0&&this._transport.send({type:"ops",fromSite:this._transport.siteId,ops:s,sv:he(this.doc.stateVector)})}_onMessage(e){if(e.type==="ops")this._applyRemoteOps(e.ops);else if(e.type==="sync-request"){const t=Ee(e.sv),i=this.doc.getOpsSince(t);i.length>0&&this._transport.send({type:"sync-reply",fromSite:this._transport.siteId,ops:i})}else e.type==="sync-reply"&&this._applyRemoteOps(e.ops)}_applyRemoteOps(e){let t=!1;for(const s of e)this.doc.apply(s)&&(t=!0);if(!t)return;const i=this.doc.getText();i!==this._lastText&&(this._suppress=!0,this._lastText=i,this._editor.setValue(i),this._suppress=!1)}destroy(){this._unsub(),this.awareness.destroy()}}const wt=22,De=6,je=300,kt=60,ie=14,He=20,Q=7.82,xt=13,Ct=2,Tt=80,V=2,Y=1.1,le=3,St=120,Mt=700,Et=120,It={typescript:"//",javascript:"//",css:"//",json:"",markdown:"",text:""},ge=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"]),Lt=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"]),Rt=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"]),Bt=new Set(["null","true","false"]),Pe=new Set,be=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"]),At=new Set(["number","string","boolean","object","Promise","Array","Map","Set","HTMLElement","KeyboardEvent","Float64Array","EventListener","Document","Window","Node","Element","Event","MouseEvent","CustomEvent"]),Dt=new Set,jt=new Set,$e=new Set,We={typescript:ge,javascript:Lt,css:Rt,json:Bt,markdown:Pe,text:Pe},Oe={typescript:be,javascript:At,css:Dt,json:jt,markdown:$e,text:$e};function Ne(r,e){return{fileId:r,doc:[...e],cur:{row:0,col:0},sel:null,dirty:!1,undoStack:[],redoStack:[],scrollTop:0}}function j(r,e=je){const t={doc:[...r.doc],cur:{...r.cur},sel:r.sel?{...r.sel}:null};r.undoStack.push(t),r.undoStack.length>e&&r.undoStack.shift(),r.redoStack=[],r.dirty=!0}function Ht(r){if(!r.undoStack.length)return!1;const e={doc:[...r.doc],cur:{...r.cur},sel:r.sel?{...r.sel}:null};r.redoStack.push(e);const t=r.undoStack.pop();return r.doc=t.doc,r.cur=t.cur,r.sel=t.sel,!0}function Pt(r){if(!r.redoStack.length)return!1;const e={doc:[...r.doc],cur:{...r.cur},sel:r.sel?{...r.sel}:null};r.undoStack.push(e);const t=r.redoStack.pop();return r.doc=t.doc,r.cur=t.cur,r.sel=t.sel,!0}function A(r){const{doc:e,cur:t}=r;t.row=Math.max(0,Math.min(e.length-1,t.row)),t.col=Math.max(0,Math.min((e[t.row]??"").length,t.col))}function J(r){const{ar:e,ac:t,fr:i,fc:s}=r;return e<i||e===i&&t<=s?r:{ar:i,ac:s,fr:e,fc:t}}function Fe(r,e,t){if(!r)return null;const i=J(r);return e<i.ar||e>i.fr?null:{start:e===i.ar?i.ac:0,end:e===i.fr?i.fc:t}}function $t(r){if(!r.sel)return 0;const e=J(r.sel);let t=0;for(let i=e.ar;i<=e.fr;i++){const s=r.doc[i]??"",n=i===e.ar?e.ac:0,o=i===e.fr?e.fc:s.length;t+=o-n}return t}function Ue(r){if(!r.sel)return"";const e=J(r.sel),t=[];for(let i=e.ar;i<=e.fr;i++){const s=r.doc[i]??"";t.push(s.slice(i===e.ar?e.ac:0,i===e.fr?e.fc:s.length))}return t.join(`
2
+ `)}function oe(r){const e=r.sel;if(!e)return r.cur;const t=J(e),i=(r.doc[t.ar]??"").slice(0,t.ac),s=(r.doc[t.fr]??"").slice(t.fc);return r.doc.splice(t.ar,t.fr-t.ar+1,i+s),r.sel=null,{row:t.ar,col:t.ac}}function Wt(r,e,t){if(!t||r.length<=e)return[r];const i=[];let s=0;for(;s<r.length;){if(r.length-s<=e){i.push(r.slice(s));break}const n=s+e;let o=-1;for(let a=n;a>s;a--)if(r[a-1]===" "){o=a;break}o===-1?(i.push(r.slice(s,n)),s=n):(i.push(r.slice(s,o)),s=o)}return i}function Ot(r,e,t,i){const s=[],n=[],o=[];let a=-1;for(let l=0;l<r.length;l++){if(l>0&&l<=a){o.push(n.length),s.push([r[l]??""]);continue}o.push(n.length);const c=Wt(r[l]??"",e,t);s.push(c),c.forEach((d,u)=>n.push({docLine:l,segIdx:u,text:d})),i.has(l)&&(a=i.get(l))}return{segments:s,visualRows:n,docToVisArr:o}}function ee(r,e,t){const i=r.segments[e]??[""];let s=t;for(let n=0;n<i.length;n++){if(s<=i[n].length||n===i.length-1)return{visRow:r.docToVisArr[e]+n,colInSeg:Math.min(s,i[n].length)};s-=i[n].length}return{visRow:r.docToVisArr[e]??0,colInSeg:0}}function pe(r,e,t){var o;const i=r.visualRows[e];if(!i)return{row:0,col:0};const s=r.segments[i.docLine]??[""];let n=Math.min(t,((o=s[i.segIdx])==null?void 0:o.length)??0);for(let a=0;a<i.segIdx;a++)n+=s[a].length;return{row:i.docLine,col:n}}function _e(r,e={}){var d,u;const t=[],i=r.length;let s=0;const n=(h,_,y)=>{y>_&&t.push({cls:h,start:_,end:y})},o=We[e.language??"typescript"]??ge,a=Oe[e.language??"typescript"]??be,l=(d=e.extraKeywords)!=null&&d.size?new Set([...o,...e.extraKeywords]):o,c=(u=e.extraTypes)!=null&&u.size?new Set([...a,...e.extraTypes]):a;for(;s<i;){if(r[s]==="/"&&r[s+1]==="/"){n("cmt",s,i);break}if(r[s]==="*"||r[s]==="/"&&r[s+1]==="*"){n("cmt",s,i);break}if(r[s]==="@"){let h=s+1;for(;h<i&&/\w/.test(r[h]);)h++;n("dec",s,h),s=h;continue}if(r[s]==='"'||r[s]==="'"||r[s]==="`"){const h=r[s];let _=s+1;for(;_<i;){if(r[_]==="\\"){_+=2;continue}if(r[_]===h){_++;break}_++}n("str",s,_),s=_;continue}if(/\d/.test(r[s])&&(s===0||!/\w/.test(r[s-1]))){let h=s;for(;h<i&&/[\d._xXa-fA-F]/.test(r[h]);)h++;n("num",s,h),s=h;continue}if(/[a-zA-Z_$]/.test(r[s])){let h=s;for(;h<i&&/[\w$]/.test(r[h]);)h++;const _=r.slice(s,h);l.has(_)?n("kw",s,h):c.has(_)?n("typ",s,h):h<i&&r[h]==="("?n("fn",s,h):/^[A-Z]/.test(_)&&n("cls",s,h),s=h;continue}if(/[=<>!&|+\-*/%^~?:,;.[\]{}()]/.test(r[s])){n("op",s,s+1),s++;continue}s++}return t}function ze(r,e){const t=new Array(r.length).fill("");for(const i of e)for(let s=i.start;s<i.end;s++)t[s]=i.cls;return t}class Nt{constructor(e=5e3){p(this,"_cache",new Map);p(this,"_maxSize");p(this,"_hits",0);p(this,"_misses",0);p(this,"_evictions",0);this._maxSize=e}get metrics(){return{hits:this._hits,misses:this._misses,evictions:this._evictions,size:this._cache.size}}get(e,t){const i=this._cache.get(e);return i&&i.src===t?(this._hits++,i.segs):(this._misses++,null)}set(e,t,i){this._cache.size>=this._maxSize&&(this._cache.delete(this._cache.keys().next().value),this._evictions++),this._cache.set(e,{src:t,segs:i})}invalidateLine(e,t){for(let i=0;i<t;i++)this._cache.delete(`${e}:${i}`)}clear(){this._cache.clear(),this._hits=0,this._misses=0,this._evictions=0}resetMetrics(){this._hits=0,this._misses=0,this._evictions=0}}const qe={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"}},Ge={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"}},Ve={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"}},Ke={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"}},Ye={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"}},Je={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"}},Xe=[qe,Ge,Ve,Ke,Ye,Je,{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"}},{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"}}],Ft={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 Ut{constructor(e){p(this,"_registry",new Map);p(this,"_activeId","");p(this,"_root");this._root=e;for(const t of Xe)this._registry.set(t.id,t)}register(e){this._registry.set(e.id,e)}apply(e){let t;typeof e=="string"?(t=this._registry.get(e),t||(console.warn(`[syncline-editor] Unknown theme: "${e}". Falling back to VR Dark.`),t=this._registry.get(""))):(t=e,this._registry.set(t.id,t)),this._activeId=t.id,this._applyTokens(t.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(e){const t=this._root.style;for(const[i,s]of Object.entries(Ft))t.setProperty(s,e[i])}}const zt=`
3
3
  /* ── Reset ── */
4
4
  *,*::before,*::after{box-sizing:border-box;margin:0;padding:0}
5
5
 
@@ -68,7 +68,11 @@
68
68
  .sl-editor::-webkit-scrollbar-track{background:transparent}
69
69
  .sl-editor::-webkit-scrollbar-thumb{background:var(--border3);border-radius:5px;border:2px solid var(--bg2)}
70
70
  .sl-spacer{position:absolute;left:0;top:0;width:1px;pointer-events:none}
71
- .sl-vp{position:absolute;left:0;right:0;will-change:transform}
71
+ /* overflow-x:clip clips horizontal overflow without creating a scroll container.
72
+ * Unlike overflow-x:hidden, it does NOT force overflow-y from visible→auto,
73
+ * so absolutely-positioned children (remote cursor name labels) that extend
74
+ * above their row are never clipped on the Y axis. */
75
+ .sl-vp{position:absolute;left:0;right:0;overflow-x:clip;overflow-y:visible;will-change:transform}
72
76
 
73
77
  /* ── Editor row ── */
74
78
  .sl-er{display:flex;align-items:stretch;position:relative}
@@ -104,11 +108,66 @@
104
108
  box-shadow:0 0 8px var(--cur-glow);
105
109
  animation:sl-blink 1.05s step-end infinite;pointer-events:none}
106
110
 
111
+ /* ── Snippet tab-stop ghost markers ── */
112
+ .sl-snip-stop{display:inline;width:0;height:0;position:relative}
113
+ .sl-snip-stop::after{content:'';position:absolute;left:0;top:2px;width:2px;height:18px;
114
+ background:var(--cur);border-radius:1px;opacity:0.28;pointer-events:none}
115
+
116
+ /* ── Remote peer cursors ── */
117
+ /*
118
+ * Architecture:
119
+ * .sl-rc — zero-size inline anchor; creates relative-positioning context
120
+ * .sl-rc::after — the 2 px tall vertical beam (full line height, like local cursor)
121
+ * .sl-rc-label — name chip anchored at beam-top, translated up by its own height
122
+ * so it always floats ABOVE the current row regardless of font/line-height.
123
+ * .sl-rc-label::after — tiny downward triangle connecting label to beam
124
+ */
125
+ .sl-rc{display:inline;width:0;height:0;position:relative}
126
+ /* Full-height coloured beam */
127
+ .sl-rc::after{
128
+ content:'';position:absolute;left:0;top:1px;
129
+ width:2px;height:20px;
130
+ background:var(--rc-color,#e06c75);border-radius:1px;
131
+ pointer-events:none;z-index:3;
132
+ box-shadow:0 0 6px color-mix(in srgb,var(--rc-color,#e06c75) 55%,transparent)}
133
+ /* Name label — sits at beam-top then transforms up by its own height */
134
+ .sl-rc-label{
135
+ position:absolute;top:1px;left:2px;
136
+ transform:translateY(-100%);
137
+ background:var(--rc-color,#e06c75);color:#fff;
138
+ font-size:10px;padding:1px 6px;
139
+ border-radius:3px 3px 3px 0;white-space:nowrap;
140
+ pointer-events:none;opacity:0.93;
141
+ font-family:var(--mono);line-height:1.5;
142
+ z-index:10;
143
+ box-shadow:0 1px 5px rgba(0,0,0,.35);
144
+ /* Small downward-pointing triangle connecting label to beam */
145
+ }
146
+ .sl-rc-label::after{
147
+ content:'';position:absolute;bottom:-4px;left:0;
148
+ width:0;height:0;
149
+ border-left:4px solid transparent;
150
+ border-right:4px solid transparent;
151
+ border-top:4px solid var(--rc-color,#e06c75);
152
+ }
153
+ /* Flipped variant: label below the cursor beam (used on the first visible row
154
+ so the label is never clipped by the scroll container's overflow). */
155
+ .sl-rc-flip .sl-rc-label{
156
+ top:auto;bottom:1px;
157
+ transform:translateY(100%);
158
+ border-radius:0 3px 3px 3px}
159
+ .sl-rc-flip .sl-rc-label::after{
160
+ bottom:auto;top:-4px;
161
+ border-top:none;
162
+ border-bottom:4px solid var(--rc-color,#e06c75)}
163
+ /* Remote peer selection highlight — semi-transparent coloured fill */
164
+ .sl-rs{border-radius:2px;background:var(--rs-color,rgba(224,108,117,0.28))}
165
+
107
166
  /* ── Overlays ── */
108
167
  .sl-sh{background:var(--sel-bg);border-radius:2px}
109
- .sl-fh{background:var(--find-bg);border:1px solid var(--find-border);border-radius:2px}
110
- .sl-fh.sl-fh-cur{background:var(--find-cur-bg);border:1px solid var(--find-cur-border);color:var(--find-cur-text)}
111
- .sl-wh{background:var(--word-hl-bg);border:1px solid var(--word-hl-border);border-radius:2px}
168
+ .sl-fh{background:var(--find-bg);box-shadow:0 0 0 1px var(--find-border);border-radius:2px}
169
+ .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)}
170
+ .sl-wh{background:var(--word-hl-bg);box-shadow:0 0 0 1px var(--word-hl-border);border-radius:2px}
112
171
  .sl-bm{box-shadow:0 0 0 1px var(--bm-border);border-radius:2px}
113
172
  .sl-ig{position:absolute;top:0;bottom:0;width:1px;background:var(--indent-guide);pointer-events:none}
114
173
 
@@ -144,6 +203,24 @@
144
203
  .sl-sb-right{margin-left:auto;display:flex;align-items:center}
145
204
  .sl-sb-wrap.sl-on{font-weight:700}
146
205
 
206
+ /* ── Placeholder ── */
207
+ .sl-placeholder{position:absolute;top:0;right:0;pointer-events:none;user-select:none;
208
+ color:var(--text3);white-space:pre;overflow:hidden;z-index:1}
209
+
210
+ /* ── Go to Line bar ── */
211
+ .sl-gtl-bar{position:absolute;top:0;left:50%;z-index:50;background:var(--bg3);
212
+ border:1px solid var(--border3);border-top:none;border-radius:0 0 10px 10px;
213
+ display:flex;align-items:center;gap:8px;padding:8px 12px;
214
+ transform:translateX(-50%) translateY(-100%);transition:transform .18s,box-shadow .18s;pointer-events:none}
215
+ .sl-gtl-bar.sl-open{transform:translateX(-50%) translateY(0);pointer-events:all;box-shadow:0 8px 28px rgba(0,0,0,.4)}
216
+ .sl-gtl-label{font-size:12px;color:var(--text2);white-space:nowrap}
217
+ .sl-gtl-input{width:72px;background:var(--bg4);border:1px solid var(--border3);
218
+ border-radius:5px;padding:4px 8px;font-size:12px;font-family:var(--mono);
219
+ color:var(--text);outline:none;transition:border-color .15s;text-align:center}
220
+ .sl-gtl-input:focus{border-color:var(--accent)}
221
+ .sl-gtl-input.sl-gtl-err{border-color:#e05252}
222
+ .sl-gtl-hint{font-size:11px;color:var(--text3);font-family:var(--mono);min-width:40px}
223
+
147
224
  /* ── Find + Replace bar ── */
148
225
  .sl-find-bar{position:absolute;top:0;right:125px;z-index:50;background:var(--bg3);
149
226
  border:1px solid var(--border3);border-top:none;border-radius:0 0 10px 10px;
@@ -261,11 +338,11 @@
261
338
  /* ── Empty state ── */
262
339
  .sl-empty{flex:1;display:flex;flex-direction:column;align-items:center;
263
340
  justify-content:center;gap:10px;color:var(--text3);font-size:13px}
264
- `;function A(s,e,t){const i=document.createElement(s);return e&&(i.className=e),i}function K(s){return s.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function re(s,e=document.documentElement){return getComputedStyle(e).getPropertyValue(s).trim()}function Se(s,e){const t=s.replace("#",""),i=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),n=parseInt(t.slice(4,6),16);return`rgba(${i},${r},${n},${e})`}function Ie(s){return s.split(`
265
- `)}function L(s){return s.join(`
266
- `)}function Ae(s){return(s.match(/^(\s*)/)??["",""])[1]}function Z(s){return" ".repeat(Math.max(0,s))}function Le(s){return/[\w$]/.test(s)}function ne(s,e,t=Le){let i=e;for(;i>0&&t(s[i-1]);)i--;return i}function se(s,e,t=Le){let i=e;for(;i<s.length&&t(s[i]);)i++;return i}function ae(s,e){let t=0,i=null;return(...r)=>{const n=Date.now(),a=e-(n-t);a<=0?(i!==null&&(clearTimeout(i),i=null),t=n,s(...r)):i===null&&(i=setTimeout(()=>{t=Date.now(),i=null,s(...r)},a))}}const nt={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 st(s,e,t,i){const r=Number(s);return Number.isFinite(r)?Math.max(e,Math.min(t,Math.round(r))):i}function He(s){const e={...s};for(const[t,i]of Object.entries(nt))if(t in s&&s[t]!==void 0){const[r,n,a]=i;e[t]=st(s[t],r,n,a)}return e}const oe={"(":")","{":"}","[":"]"},le={")":"(","}":"{","]":"["};function at(s,e){const{row:t,col:i}=e,r=s[t]??"";let n=r[i],a=i;if(!oe[n]&&!le[n]&&(n=r[i-1],a=i-1),!n)return null;if(oe[n]){const l=oe[n];let o=0;for(let c=t;c<Math.min(s.length,t+500);c++){const d=s[c]??"",p=c===t?a:0;for(let h=p;h<d.length;h++)if(d[h]===n)o++;else if(d[h]===l&&(o--,o===0))return{open:{row:t,col:a},close:{row:c,col:h}}}}else if(le[n]){const l=le[n];let o=0;for(let c=t;c>=Math.max(0,t-500);c--){const d=s[c]??"",p=c===t?a:d.length-1;for(let h=p;h>=0;h--)if(d[h]===n)o++;else if(d[h]===l&&(o--,o===0))return{open:{row:c,col:h},close:{row:t,col:a}}}}return null}function ot(s,e){const t=s[e]??"";let i=0;for(const r of t)r==="{"?i++:r==="}"&&i--;return i>0}function lt(s,e){let t=0;for(let i=e;i<s.length;i++)for(const r of s[i]??"")if(r==="{")t++;else if(r==="}"&&(t--,t===0))return i;return null}function ct(s,e,t){const i=new Map(s);if(i.has(t))i.delete(t);else{const r=lt(e,t);r!==null&&r>t&&i.set(t,r)}return i}const dt=new Set(["img","input","br","hr","meta","link","area","base","col","embed","param","source","track","wbr"]);function De(s){const e=s.trim();if(!e)return null;try{const t=ce(e);return t===e?null:t}catch{return null}}function ce(s){if(s.includes(">")){const t=s.indexOf(">");return de(s.slice(0,t),ce(s.slice(t+1)))}if(s.includes("+"))return s.split("+").map(t=>ce(t.trim())).join(`
267
- `);const e=s.match(/^(.+)\*(\d+)$/);if(e){const t=parseInt(e[2],10);return Array.from({length:t},(i,r)=>de(e[1],`$${r+1}`)).join(`
268
- `)}return de(s,"$1")}function de(s,e){const t=s.match(/#([\w-]+)/),i=s.match(/\.([\w.-]+)/g),r=s.match(/\[([^\]]+)\]/);let n=s.replace(/#[\w-]+/g,"").replace(/\.[\w.-]+/g,"").replace(/\[[^\]]+\]/g,"").trim()||"div",a="";return t&&(a+=` id="${t[1]}"`),i&&(a+=` class="${i.map(l=>l.slice(1)).join(" ")}"`),r&&(a+=` ${r[1]}`),dt.has(n)?`<${n}${a}>`:`<${n}${a}>${e}</${n}>`}function Re(s,e){let t=e;for(;t>0&&/[\w#.[\]*>+{}()$@:-]/.test(s[t-1]);)t--;const i=s.slice(t,e);return i.length<2?null:{abbr:i,start:t}}const ht=[{label:"fn",kind:"snip",detail:"function declaration",description:`Declares a named function.
341
+ `;function H(r,e,t){const i=document.createElement(r);return e&&(i.className=e),i}function se(r){return r.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;")}function me(r,e=document.documentElement){return getComputedStyle(e).getPropertyValue(r).trim()}function Ze(r,e){const t=r.replace("#",""),i=parseInt(t.slice(0,2),16),s=parseInt(t.slice(2,4),16),n=parseInt(t.slice(4,6),16);return`rgba(${i},${s},${n},${e})`}function Qe(r){return r.split(`
342
+ `)}function $(r){return r.join(`
343
+ `)}function et(r){return(r.match(/^(\s*)/)??["",""])[1]}function ue(r){return" ".repeat(Math.max(0,r))}function tt(r){return/[\w$]/.test(r)}function ye(r,e,t=tt){let i=e;for(;i>0&&t(r[i-1]);)i--;return i}function ve(r,e,t=tt){let i=e;for(;i<r.length&&t(r[i]);)i++;return i}function we(r,e){let t=0,i=null;return(...s)=>{const n=Date.now(),o=e-(n-t);o<=0?(i!==null&&(clearTimeout(i),i=null),t=n,r(...s)):i===null&&(i=setTimeout(()=>{t=Date.now(),i=null,r(...s)},o))}}const qt={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 Gt(r,e,t,i){const s=Number(r);return Number.isFinite(s)?Math.max(e,Math.min(t,Math.round(s))):i}function it(r){const e={...r};for(const[t,i]of Object.entries(qt))if(t in r&&r[t]!==void 0){const[s,n,o]=i;e[t]=Gt(r[t],s,n,o)}return e}const ke={"(":")","{":"}","[":"]"},xe={")":"(","}":"{","]":"["};function Vt(r,e){const{row:t,col:i}=e,s=r[t]??"";let n=s[i],o=i;if(!ke[n]&&!xe[n]&&(n=s[i-1],o=i-1),!n)return null;if(ke[n]){const a=ke[n];let l=0;for(let c=t;c<Math.min(r.length,t+500);c++){const d=r[c]??"",u=c===t?o:0;for(let h=u;h<d.length;h++)if(d[h]===n)l++;else if(d[h]===a&&(l--,l===0))return{open:{row:t,col:o},close:{row:c,col:h}}}}else if(xe[n]){const a=xe[n];let l=0;for(let c=t;c>=Math.max(0,t-500);c--){const d=r[c]??"",u=c===t?o:d.length-1;for(let h=u;h>=0;h--)if(d[h]===n)l++;else if(d[h]===a&&(l--,l===0))return{open:{row:c,col:h},close:{row:t,col:o}}}}return null}function Kt(r,e){const t=r[e]??"";let i=0;for(const s of t)s==="{"?i++:s==="}"&&i--;return i>0}function Yt(r,e){let t=0;for(let i=e;i<r.length;i++)for(const s of r[i]??"")if(s==="{")t++;else if(s==="}"&&(t--,t===0))return i;return null}function Jt(r,e,t){const i=new Map(r);if(i.has(t))i.delete(t);else{const s=Yt(e,t);s!==null&&s>t&&i.set(t,s)}return i}const Xt=new Set(["img","input","br","hr","meta","link","area","base","col","embed","param","source","track","wbr"]);function st(r){const e=r.trim();if(!e)return null;try{const t=Ce(e);return t===e?null:t}catch{return null}}function Ce(r){if(r.includes(">")){const t=r.indexOf(">");return Te(r.slice(0,t),Ce(r.slice(t+1)))}if(r.includes("+"))return r.split("+").map(t=>Ce(t.trim())).join(`
344
+ `);const e=r.match(/^(.+)\*(\d+)$/);if(e){const t=parseInt(e[2],10);return Array.from({length:t},(i,s)=>Te(e[1],`$${s+1}`)).join(`
345
+ `)}return Te(r,"$1")}function Te(r,e){const t=r.match(/#([\w-]+)/),i=r.match(/\.([\w.-]+)/g),s=r.match(/\[([^\]]+)\]/);let n=r.replace(/#[\w-]+/g,"").replace(/\.[\w.-]+/g,"").replace(/\[[^\]]+\]/g,"").trim()||"div",o="";return t&&(o+=` id="${t[1]}"`),i&&(o+=` class="${i.map(a=>a.slice(1)).join(" ")}"`),s&&(o+=` ${s[1]}`),Xt.has(n)?`<${n}${o}>`:`<${n}${o}>${e}</${n}>`}function nt(r,e){let t=e;for(;t>0&&/[\w#.[\]*>+{}()$@:-]/.test(r[t-1]);)t--;const i=r.slice(t,e);return i.length<2?null:{abbr:i,start:t}}const Zt=[{label:"fn",kind:"snip",detail:"function declaration",description:`Declares a named function.
269
346
 
270
347
  function name(params) {
271
348
  // body
@@ -341,7 +418,7 @@ switch (expr) {
341
418
  break;
342
419
  default:
343
420
  $4
344
- }`}],pt=[{label:"flex",kind:"snip",detail:"flexbox container",description:`Sets up a flex container with centered alignment.
421
+ }`}],Qt=[{label:"flex",kind:"snip",detail:"flexbox container",description:`Sets up a flex container with centered alignment.
345
422
 
346
423
  display: flex;
347
424
  align-items: center;
@@ -369,7 +446,7 @@ gap: $2;`,language:["css"]},{label:"media",kind:"snip",detail:"@media query",des
369
446
  to { $3 }
370
447
  }`,language:["css"]},{label:"var",kind:"snip",detail:"CSS custom property",description:`Declares a CSS custom property (variable).
371
448
 
372
- --name: value;`,body:"--$1: $2;",language:["css"]}],ut=[{label:"accordion",kind:"snip",detail:"HTML details/summary",description:`An accessible accordion using the native <details> and <summary> elements.
449
+ --name: value;`,body:"--$1: $2;",language:["css"]}],ei=[{label:"accordion",kind:"snip",detail:"HTML details/summary",description:`An accessible accordion using the native <details> and <summary> elements.
373
450
 
374
451
  <details>
375
452
  <summary>Title</summary>
@@ -417,7 +494,7 @@ gap: $2;`,language:["css"]},{label:"media",kind:"snip",detail:"@media query",des
417
494
  <td>$2</td>
418
495
  </tr>
419
496
  </tbody>
420
- </table>`}];function ft(s){const e=[...ut];return(s==="typescript"||s==="javascript")&&e.push(...ht.filter(t=>!t.language||(Array.isArray(t.language)?t.language.includes(s):t.language===s))),s==="css"&&e.push(...pt),e}function gt(s,e,t){let i=e;for(;i>0&&/\w/.test(s[i-1]);)i--;const r=s.slice(i,e);if(!r)return null;const n=t.find(a=>a.kind==="snip"&&a.label===r);return n?{snippet:n,start:i}:null}function bt(){return{cursors:[],searchWord:"",lastMatchRow:-1,lastMatchCol:-1}}function Be(s,e,t,i){s.cursors.some(n=>n.row===e&&n.col===t)||s.cursors.push({row:e,col:t,sel:i})}function je(s){s.cursors=[],s.searchWord="",s.lastMatchRow=-1,s.lastMatchCol=-1}function mt(s,e,t,i,r){const n=[{row:e,col:t,isPrimary:!0,idx:0},...i.map((d,p)=>({row:d.row,col:d.col,isPrimary:!1,idx:p+1}))];n.sort((d,p)=>p.row!==d.row?p.row-d.row:p.col-d.col);const a=s.map(d=>d);let l=e,o=t;const c=i.map(d=>({...d}));for(const d of n){const p=a[d.row]??"";a[d.row]=p.slice(0,d.col)+r+p.slice(d.col);for(const h of n)h!==d&&h.row===d.row&&h.col>=d.col&&(h.col+=r.length);d.col+=r.length,d.isPrimary?(l=d.row,o=d.col):(c[d.idx-1].row=d.row,c[d.idx-1].col=d.col)}return{doc:a,primaryRow:l,primaryCol:o,extraCursors:c}}function _t(s,e,t,i){const r=[{row:e,col:t,isPrimary:!0,idx:0},...i.map((c,d)=>({row:c.row,col:c.col,isPrimary:!1,idx:d+1}))];r.sort((c,d)=>d.row!==c.row?d.row-c.row:d.col-c.col);const n=s.map(c=>c);let a=e,l=t;const o=i.map(c=>({...c}));for(const c of r){if(c.col<=0)continue;const d=n[c.row]??"";n[c.row]=d.slice(0,c.col-1)+d.slice(c.col);for(const p of r)p!==c&&p.row===c.row&&p.col>c.col&&p.col--;c.col--,c.isPrimary?(a=c.row,l=c.col):o[c.idx-1].col=c.col}return{doc:n,primaryRow:a,primaryCol:l,extraCursors:o}}function yt(s,e,t,i,r){let n=s.searchWord;if(!n){if(r&&r.ar===r.fr&&(n=(e[r.ar]??"").slice(r.ac,r.fc)),!n){const o=e[t]??"",c=ne(o,i),d=se(o,i);n=o.slice(c,d)}if(!n)return null;s.searchWord=n,s.lastMatchRow=t,s.lastMatchCol=i}const a=s.lastMatchRow,l=s.lastMatchCol;for(let o=a;o<e.length;o++){const c=e[o]??"";let p=o===a?l:0;for(;p<=c.length-n.length;){const h=c.indexOf(n,p);if(h<0)break;const g=h===0||!/\w/.test(c[h-1]),y=h+n.length>=c.length||!/\w/.test(c[h+n.length]);if(g&&y)return s.lastMatchRow=o,s.lastMatchCol=h+n.length,{word:n,sel:{ar:o,ac:h,fr:o,fc:h+n.length},row:o,col:h+n.length};p=h+1}}for(let o=0;o<=a;o++){const c=e[o]??"",d=o===a?l:c.length;let p=0;for(;p<d;){const h=c.indexOf(n,p);if(h<0||h>=d)break;const g=h===0||!/\w/.test(c[h-1]),y=h+n.length>=c.length||!/\w/.test(c[h+n.length]);if(g&&y)return s.lastMatchRow=o,s.lastMatchCol=h+n.length,{word:n,sel:{ar:o,ac:h,fr:o,fc:h+n.length},row:o,col:h+n.length};p=h+1}}return null}function vt(s,e,t){if(!e)return[];const i=[];for(let r=0;r<s.length;r++){const n=s[r]??"";if(t.useRegex)try{const a=new RegExp(e,t.caseSensitive?"g":"gi");let l;for(;(l=a.exec(n))!==null&&(i.push({row:r,col:l.index,len:l[0].length}),!!l[0].length););}catch{}else{const a=t.caseSensitive?n:n.toLowerCase(),l=t.caseSensitive?e:e.toLowerCase();let o=0;for(;;){const c=a.indexOf(l,o);if(c===-1)break;i.push({row:r,col:c,len:e.length}),o=c+1}}}return i}function wt(s,e,t,i){const r=e[t];if(!r)return s;const n=[...s],a=n[r.row]??"";return n[r.row]=a.slice(0,r.col)+i+a.slice(r.col+r.len),n}function kt(s,e,t){const i=[...s];for(let r=e.length-1;r>=0;r--){const n=e[r],a=i[n.row]??"";i[n.row]=a.slice(0,n.col)+t+a.slice(n.col+n.len)}return i}function xt(s,e,t){return s.length?(e+t+s.length)%s.length:-1}function Tt(s,e,t,i){if(i)return[];const r=s[e]??"",n=ne(r,t),a=se(r,t),l=r.slice(n,a);if(!l||l.length<2)return[];const o=[];for(let c=0;c<s.length;c++){const d=s[c]??"";let p=0;for(;p<=d.length-l.length;){const h=d.indexOf(l,p);if(h<0)break;const g=h===0||!/\w/.test(d[h-1]),y=h+l.length>=d.length||!/\w/.test(d[h+l.length]);g&&y&&!(c===e&&h===n)&&o.push({row:c,col:h,len:l.length}),p=h+1}}return o}const he=[{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>"}],Mt={typescript:he,javascript:he,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 Pe(s,e,t){const i=ge[s]??ee,r=be[s]??te,n=Mt[s]??he;return[...[...i,...e].map(a=>({label:a,kind:"kw",detail:"keyword"})),...[...r,...t].map(a=>({label:a,kind:"typ",detail:"type"})),...n]}function Ct(s,e){const t=new Set;for(const i of s){const r=i.match(/[a-zA-Z_$][\w$]*/g)??[];for(const n of r)n!==e&&n.length>2&&t.add(n)}return t}function $e(s,e){return s.language?Array.isArray(s.language)?s.language.includes(e):s.language===e:!0}function Et(s,e,t={},i=0,r=0){if(e.length<2)return[];const n=e.toLowerCase(),{language:a="typescript",extraKeywords:l=[],extraTypes:o=[],completions:c=[],replaceBuiltins:d=!1,maxResults:p=14}=t,h=c.filter(m=>m.kind==="snip"&&!!m.body&&$e(m,a)),g=c.filter(m=>!(m.kind==="snip"&&m.body)&&$e(m,a)),y=h.filter(m=>m.label.toLowerCase().startsWith(n));let v;if(t.provideCompletions){const m={line:s[i]??"",col:r,prefix:e,language:a,doc:s};let H;try{H=t.provideCompletions(m)}catch(D){console.error("[syncline-editor] provideCompletions threw an error:",D),H=null}v=H!=null?[...H,...g]:[...d?[]:Pe(a,l,o),...g]}else v=d?g:[...Pe(a,l,o),...g];const f=new Set(v.map(m=>m.label)),b=v.filter(m=>m.label.toLowerCase().startsWith(n)&&m.label!==e),T=new Set(y.map(m=>m.label)),x=[...Ct(s,e)].filter(m=>m.toLowerCase().startsWith(n)&&!f.has(m)&&!T.has(m)).slice(0,8).map(m=>({label:m,kind:"var",detail:"in file"}));return[...y,...b.filter(m=>!T.has(m.label)),...x].slice(0,p)}function St(s,e,t=!1){let i=e;for(;i>0&&(t?/[\w$.\-]/:/[\w$.]/).test(s[i-1]);)i--;return{prefix:s.slice(i,e),start:i}}function It(s,e){const t=n=>/[\w$]/.test(n);let i=e;for(;i<s.length&&t(s[i]);)i++;let r=e;for(;r>0&&t(s[r-1]);)r--;if(r===i)return"";if(r>0&&s[r-1]==="."){let n=r-1,a=n;for(;a>0&&t(s[a-1]);)a--;if(a<n)return s.slice(a,i)}return s.slice(r,i)}const At={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 Lt(s,e){const t=At[s];return!t||t.language&&!(Array.isArray(t.language)?t.language:[t.language]).includes(e)?null:t}function Ht(s){var Y,J,M,j;const{vr:e,visIdx:t,curVisRow:i,wm:r,foldedLines:n,isFoldable:a,opts:l}=s,{docLine:o,segIdx:c,text:d}=e,p=t===i,h=o===((Y=r.visualRows[i])==null?void 0:Y.docLine),g=c>0,y=((J=r.segments[o])==null?void 0:J.slice(0,c).reduce((w,k)=>w+k.length,0))??0,v=s.docSel?_e(s.docSel,o,((M=(r.segments[o]??[""])[c])==null?void 0:M.length)??0):null;let f=null;if(v){const w=((j=(r.segments[o]??[""])[c])==null?void 0:j.length)??0,k=_e(s.docSel,o,w+y);if(k){const C=k.start-y,R=k.end-y;R>0&&C<d.length&&(f={start:Math.max(0,C),end:Math.min(d.length,R)})}}const b=s.findMatches.filter(w=>w.row===o).map(w=>{var W,P;const k=w.col-y,C=w.col+w.len-y;if(C<=0||k>=d.length)return null;const R=s.findIdx>=0&&((W=s.findMatches[s.findIdx])==null?void 0:W.row)===w.row&&((P=s.findMatches[s.findIdx])==null?void 0:P.col)===w.col;return{start:Math.max(0,k),end:Math.min(d.length,C),isCur:R}}).filter(Boolean),T=s.wordHighlights.filter(w=>w.row===o).map(w=>{const k=w.col-y,C=w.col+w.len-y;return C<=0||k>=d.length?null:{start:Math.max(0,k),end:Math.min(d.length,C)}}).filter(Boolean),_=[];if(s.bracketMatch){for(const w of[s.bracketMatch.open,s.bracketMatch.close])if(w.row===o){const k=w.col-y;k>=0&&k<d.length&&_.push({start:k,end:k+1})}}const x=[],m=[];for(const w of s.extraCursors){const k=G(r,w.row,w.col);if(k.visRow===t&&x.push(k.colInSeg),w.sel){const C=Rt(w.sel);if(o>=C.ar&&o<=C.fr){const R=o===C.ar?C.ac-y:-y,W=o===C.fr?C.fc-y:d.length+999;W>0&&R<d.length&&m.push({start:Math.max(0,R),end:Math.min(d.length,W)})}}}const H=Dt(d,l.renderWhitespace),D=p||f||b.length||x.length||T.length||_.length||m.length;let q;if(D)q=jt(H,p?s.curColInSeg:-1,f,b,x,T,_,m,l.tokeniserOpts);else{const w=`${o}:${c}:${l.renderWhitespace}`;let k=s.tokenCache.get(w,H);k||(k=ie(H,l.tokeniserOpts),s.tokenCache.set(w,H,k)),q=Bt(H,k)||"&#8203;"}let Q="";if(c===0&&l.showIndentGuides){const w=(d.match(/^(\s*)/)??["",""])[1].length,k=Math.floor(w/l.tabSize);for(let C=1;C<k;C++){const R=l.codePaddingLeft+C*l.tabSize*l.charWidth;Q+=`<span class="sl-ig" style="left:${R}px"></span>`}}let N="";if(c===0&&a){const w=n.has(o);N=`<span class="sl-fold-btn" data-row="${o}">${w?"▸":"▾"}</span>`}const O=n.has(o)&&c===0,F=c===0?String(o+1):"";return`<div class="${["sl-er",l.highlightActiveLine&&h?"sl-cur-row":"",g?"sl-wrap-cont":"",O?"sl-folded":""].filter(Boolean).join(" ")}" style="height:${l.lineHeight}px" data-v="${t}" data-doc="${o}"><div class="sl-eg" style="position:relative">${N}<span class="sl-egn">${F}</span></div><div class="sl-el"><span class="sl-cl">${Q}${q}</span></div></div>`}function Dt(s,e){if(e==="none")return s;if(e==="all")return s.replace(/ /g,"·").replace(/\t/g,"→");const t=(s.match(/^ +/)??[""])[0].length,i=(s.match(/ +$/)??[""])[0].length;let r=s;return t&&(r="·".repeat(t)+r.slice(t)),i&&(r=r.slice(0,r.length-i)+"·".repeat(i)),r.replace(/\t/g,"→")}function Rt(s){return s.ar<s.fr||s.ar===s.fr&&s.ac<=s.fc?s:{ar:s.fr,ac:s.fc,fr:s.ar,fc:s.ac}}function Bt(s,e){if(!s)return"";const t=ve(s,e);let i="",r=0,n=t[0];const a=l=>{if(l<=r)return;const o=K(s.slice(r,l));i+=n?`<span class="${n}">${o}</span>`:o};for(let l=1;l<=s.length;l++){const o=l<s.length?t[l]:null;o!==n&&(a(l),r=l,n=o??"")}return i}function jt(s,e,t,i,r,n,a,l,o){if(s.length===0){let f=e>=0?'<span class="sl-cur"></span>':"";for(const b of r)f+='<span class="sl-cur-extra"></span>';return f||"&#8203;"}const c=ie(s,o),d=ve(s,c);let p="",h=0,g="",y="";const v=f=>{if(f<=h)return;const b=K(s.slice(h,f)),T=[g,y].filter(Boolean).join(" ");p+=T?`<span class="${T}">${b}</span>`:b};for(let f=0;f<=s.length;f++){e===f&&(v(f),h=f,p+='<span class="sl-cur"></span>');for(const D of r)D===f&&(v(f),h=f,p+='<span class="sl-cur-extra"></span>');if(f===s.length){v(f);break}const b=d[f],T=i.find(D=>f>=D.start&&f<D.end),_=t&&f>=t.start&&f<t.end||l.some(D=>f>=D.start&&f<D.end),x=!_&&!T&&n.some(D=>f>=D.start&&f<D.end),m=!_&&!T&&a.some(D=>f>=D.start&&f<D.end);let H="";_?H="sl-sh":T?H="sl-fh"+(T.isCur?" sl-fh-cur":""):m?H="sl-bm":x&&(H="sl-wh"),(H!==g||b!==y)&&(v(f),h=f,g=H,y=b)}return p||"&#8203;"}function pe(s,e,t,i,r){const n=Math.max(0,s*r-t),a=Math.max(0,s*2-i),o=(n>0?e/n:0)*a,c=Math.max(20,t/r*2),d=e/r*2-o;return{mmScroll:o,sliderTop:d,sliderHeight:c}}function Pt(s,e,t,i,r){const n=Math.max(0,e*r-t),a=Math.max(0,e*2-i);if(n<=0)return 0;const l=2/r-a/n;if(Math.abs(l)<1e-9){const o=Math.max(20,t/r*2);return Math.max(0,Math.min(n,s/Math.max(1,i-o)*n))}return Math.max(0,Math.min(n,s/l))}function $t(s,e,t,i,r,n){const a=Math.max(0,e*n-i),l=Math.max(0,e*2-r);if(a<=0)return 0;const o=t/a*l,c=(s+o)/2;return Math.max(0,Math.min(a,c*n-i/2))}function We(s){const e=t=>{const i=s(t);return i.startsWith("#")&&i.length===7?Se(i,.85):i};return{kw:e("--tok-kw"),fn:e("--tok-fn"),cls:e("--tok-cls"),typ:e("--tok-typ"),str:e("--tok-str"),num:e("--tok-num"),cmt:e("--tok-cmt"),dec:e("--tok-dec"),op:e("--tok-op"),txt:(()=>{const t=s("--text2");return t.startsWith("#")&&t.length===7?Se(t,.28):"rgba(150,148,140,0.28)"})()}}function Wt(s){var Y,J;const{canvas:e,doc:t,firstLine:i,lastLine:r,subPx:n,wrapperWidth:a,canvasHeight:l,cursorRow:o,sel:c,findMatches:d,findIdx:p,sliderTop:h,sliderHeight:g,colors:y,getCssVar:v,dpr:f}=s,b=e.getContext("2d");if(!b)return;b.setTransform(f,0,0,f,0,0);const T=v("--mm-bg")||"#0d0d0f",_=v("--mm-dim")||"rgba(0,0,0,.30)",x=v("--mm-edge")||"rgba(255,255,255,.18)",m=v("--mm-slider")||"rgba(255,255,255,.07)",H=v("--sel-bg")||"rgba(110,159,255,.22)",D=v("--cur-line-bg")||"rgba(255,255,255,.05)",q=v("--find-border")||"rgba(234,180,86,.50)",Q=v("--find-cur-bg")||"rgba(234,180,86,.80)",N=M=>(M-i)*2;if(b.fillStyle=T,b.fillRect(0,0,a,l),o>=i&&o<r&&(b.fillStyle=D,b.fillRect(0,N(o),a,2)),c){const M=Math.max(i,c.ar),j=Math.min(r-1,c.fr);j>=M&&(b.fillStyle=H,b.fillRect(0,N(M),a,(j-M+1)*2))}for(const M of d){if(M.row<i||M.row>=r)continue;const j=p>=0&&((Y=d[p])==null?void 0:Y.row)===M.row&&((J=d[p])==null?void 0:J.col)===M.col;b.fillStyle=j?Q:q,b.fillRect(3+M.col*1.1,N(M.row),Math.max(3,M.len*1.1),2)}const O=Math.floor((a-3)/1.1);for(let M=i;M<r;M++){const j=t[M]??"";if(!j.trim())continue;const w=N(M),k=1.5,C=ie(j);let R=0;for(const P of C){if(P.start>=O)break;P.start>R&&(b.fillStyle=y.txt,b.fillRect(3+R*1.1,w,(Math.min(P.start,O)-R)*1.1,k));const Ft=y[P.cls]??y.txt,Oe=Math.min(P.end,O)-P.start;Oe>0&&(b.fillStyle=Ft,b.fillRect(3+P.start*1.1,w,Oe*1.1,k)),R=Math.max(R,Math.min(P.end,O))}const W=Math.min(j.length,O);R<W&&(b.fillStyle=y.txt,b.fillRect(3+R*1.1,w,(W-R)*1.1,k))}const F=h+n,V=F+g;b.fillStyle=_,F>0&&b.fillRect(0,0,a,F),V<l&&b.fillRect(0,V,a,l-V),b.fillStyle=m,b.fillRect(0,F,a,g),b.fillStyle=x,b.fillRect(0,Math.max(0,F),a,1),b.fillRect(0,Math.max(0,V-1),a,1)}const Nt={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:300,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};class Ne{constructor(e,t={}){u(this,"_host");u(this,"_shadow");u(this,"_editorEl");u(this,"_spacerEl");u(this,"_vpEl");u(this,"_inputEl");u(this,"_minimapWrap");u(this,"_mmCanvas");u(this,"_mmSlider");u(this,"_statusBar");u(this,"_findBar");u(this,"_findInput");u(this,"_replaceInput");u(this,"_findCount");u(this,"_replaceRow");u(this,"_acPopup");u(this,"_emmetTip");u(this,"_snippetTip");u(this,"_hoverTip");u(this,"_themeOverlay");u(this,"_themePanel");u(this,"_config");u(this,"_tab",me(1,[""]));u(this,"_wm",{segments:[[""]],visualRows:[{docLine:0,segIdx:0,text:""}],docToVisArr:[0]});u(this,"_foldedLines",new Map);u(this,"_tokenCache",new et);u(this,"_themeManager");u(this,"_findMatches",[]);u(this,"_findIdx",-1);u(this,"_findCaseSensitive",!1);u(this,"_findRegex",!1);u(this,"_wordHighlights",[]);u(this,"_bracketMatch",null);u(this,"_acItems",[]);u(this,"_acSel",0);u(this,"_acPrefix","");u(this,"_acStartCol",0);u(this,"_emmetAcStartCol",0);u(this,"_mc",bt());u(this,"_extraCursors",[]);u(this,"_isDragging",!1);u(this,"_dragAnchor",null);u(this,"_hoverTimer",null);u(this,"_hoverPinned",!1);u(this,"_mmDragMode","none");u(this,"_mmDragStartY",0);u(this,"_mmDragStartScroll",0);u(this,"_mmSliderOffset",0);u(this,"_mmColors");u(this,"_lastInputTime",0);u(this,"_dynamicStyleEl");u(this,"_emmetExpanded",null);u(this,"_snippetExpanded",null);u(this,"_acDebounceTimer",null);u(this,"_rafId",null);u(this,"_onWinMouseUp");u(this,"_onWinResize");u(this,"_onEditorScroll");u(this,"_onWinMmMouseMove");u(this,"_onWinMmMouseUp");u(this,"_ro",null);u(this,"_onFoldBtnClick",e=>{const t=e.target.closest(".sl-fold-btn");if(!t)return;e.preventDefault(),e.stopPropagation();const i=parseInt(t.dataset.row??"0",10);this._foldedLines=ct(this._foldedLines,this._tab.doc,i),this._tokenCache.clear(),this._rebuildWrapMap(),this._render()});this._config={...Nt,...He(t)},this._onWinMouseUp=()=>{this._isDragging=!1,this._dragAnchor=null},this._onEditorScroll=ae(()=>{this._hideHover(),this._scheduleRender(),this._updateMinimap()},16),this._onWinResize=ae(()=>{this._config.wordWrap&&this._rebuildWrapMap(),this._scheduleRender()},100),this._onWinMmMouseMove=o=>{if(this._mmDragMode==="none")return;const c=this._minimapWrap.clientHeight;if(this._mmDragMode==="slider"){const d=o.clientY-this._minimapWrap.getBoundingClientRect().top;this._editorEl.scrollTop=Pt(d-this._mmSliderOffset,this._tab.doc.length,this._editorEl.clientHeight,c,this._config.lineHeight)}else{const d=o.clientY-this._mmDragStartY,p=Math.max(0,this._tab.doc.length*this._config.lineHeight-this._editorEl.clientHeight);this._editorEl.scrollTop=Math.max(0,Math.min(p,this._mmDragStartScroll+d/2*this._config.lineHeight))}this._render()},this._onWinMmMouseUp=()=>{this._mmDragMode!=="none"&&(this._mmDragMode="none",this._minimapWrap.style.cursor="pointer")},this._host=e,this._host.classList.add("sl-host"),this._shadow=this._host.attachShadow({mode:"open"});const i=A("style");i.textContent=rt,this._shadow.appendChild(i),this._dynamicStyleEl=A("style"),this._shadow.appendChild(this._dynamicStyleEl),this._themeManager=new it(this._host);const r=typeof this._config.theme=="string"?this._config.theme:this._config.theme;this._themeManager.apply(r);const n=A("div","sl-layout"),a=A("div","sl-ed-pane");this._inputEl=A("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=A("div","sl-editor"),this._spacerEl=A("div","sl-spacer"),this._vpEl=A("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"),a.appendChild(this._inputEl),a.appendChild(this._findBar),a.appendChild(this._editorEl),this._minimapWrap=A("div","sl-minimap"),this._minimapWrap.style.width=`${this._config.minimapWidth}px`,this._mmCanvas=A("canvas",""),this._mmSlider=A("div","sl-mm-slider"),this._minimapWrap.appendChild(this._mmCanvas),this._minimapWrap.appendChild(this._mmSlider),n.appendChild(a),this._config.showMinimap&&n.appendChild(this._minimapWrap),this._statusBar=this._buildStatusBar(),this._acPopup=A("div","sl-ac-popup"),this._acPopup.setAttribute("role","listbox"),this._acPopup.setAttribute("aria-label","Code suggestions"),this._acPopup.style.display="none",this._emmetTip=A("div","sl-emmet-tip"),this._emmetTip.style.display="none",this._snippetTip=A("div","sl-emmet-tip"),this._snippetTip.style.display="none",this._hoverTip=A("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=A("div","sl-theme-overlay"),this._themeOverlay.style.display="none",this._themePanel=A("div","sl-theme-panel"),this._themeOverlay.appendChild(this._themePanel),this._shadow.appendChild(n),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 l=typeof this._config.value=="string"?Ie(this._config.value):this._config.value;this._tab=me(1,l.length?l:[""]),this._mmColors=We(o=>re(o,this._host)),this._bindEditorEvents(),this._bindMinimapEvents(),this._bindFindEvents(),this._applyDynamicStyles(),typeof ResizeObserver<"u"&&(this._ro=new ResizeObserver(ae(()=>{this._config.wordWrap&&(this._rebuildWrapMap(),this._scheduleRender())},60)),this._ro.observe(this._host)),this._rebuildWrapMap(),this._render()}getValue(){return L(this._tab.doc)}setValue(e){var t,i;S(this._tab,this._config.maxUndoHistory),this._tab.doc=Ie(e),this._tab.cur={row:0,col:0},this._tab.sel=null,this._tokenCache.clear(),this._foldedLines.clear(),this._rebuildWrapMap(),this._render(),(i=(t=this._config).onChange)==null||i.call(t,e)}getCursor(){return{...this._tab.cur}}setCursor(e){this._tab.cur={...e},I(this._tab),this._scrollIntoView(),this._render()}getSelection(){return this._tab.sel?{...this._tab.sel}:null}setSelection(e){this._tab.sel=e,this._render()}insertText(e){this._config.readOnly||(this._insertStr(e,!1),this._rebuildWrapMap(),I(this._tab),this._scrollIntoView(),this._render())}setTheme(e){this._themeManager.apply(e),this._applyTokenOverrides(),this._mmColors=We(t=>re(t,this._host)),this._tokenCache.clear(),this._render()}updateConfig(e){const t=He(e);if(t.autoClosePairs!==void 0){const i=t.autoClosePairs;this._config.autoClosePairs=Object.keys(i).length===0?{}:{...this._config.autoClosePairs,...i};const{autoClosePairs:r,...n}=t;Object.assign(this._config,n)}else Object.assign(this._config,t);if(t.readOnly!==void 0&&this._inputEl.setAttribute("aria-readonly",String(!!t.readOnly)),e.theme!==void 0&&this.setTheme(e.theme),(e.wordWrap!==void 0||e.wrapColumn!==void 0)&&this._rebuildWrapMap(),e.showMinimap!==void 0){const i=this._shadow.querySelector(".sl-layout");e.showMinimap?i.contains(this._minimapWrap)||i.appendChild(this._minimapWrap):this._minimapWrap.remove()}e.showStatusBar!==void 0&&(e.showStatusBar?this._shadow.contains(this._statusBar)||this._shadow.appendChild(this._statusBar):this._statusBar.remove()),(e.fontFamily!==void 0||e.fontSize!==void 0||e.lineHeight!==void 0||e.cursorBlinkRate!==void 0||e.cursorStyle!==void 0||e.gutterWidth!==void 0||e.minimapWidth!==void 0||e.showGutter!==void 0||e.tokenColors!==void 0)&&this._applyDynamicStyles(),(e.language!==void 0||e.extraKeywords!==void 0||e.extraTypes!==void 0||e.renderWhitespace!==void 0||e.completions!==void 0)&&this._tokenCache.clear(),e.find===!1?this._closeFind():e.findReplace===!1&&(this._replaceRow.style.display="none"),this._render()}focus(){this._focusInput()}getThemes(){return this._themeManager.allIds}registerTheme(e){this._themeManager.register(e)}undo(){var e,t;Ye(this._tab)&&(this._tokenCache.clear(),this._rebuildWrapMap(),I(this._tab),this._scrollIntoView(),this._render(),(t=(e=this._config).onChange)==null||t.call(e,L(this._tab.doc)))}redo(){var e,t;Je(this._tab)&&(this._tokenCache.clear(),this._rebuildWrapMap(),I(this._tab),this._scrollIntoView(),this._render(),(t=(e=this._config).onChange)==null||t.call(e,L(this._tab.doc)))}executeCommand(e){const t=this._config.readOnly;switch(e){case"undo":t||this.undo();break;case"redo":t||this.redo();break;case"selectAll":this._selectAll();break;case"copy":this._doCopy();break;case"cut":t||this._doCut();break;case"toggleComment":t||this._toggleComment();break;case"duplicateLine":t||this._duplicateLine();break;case"deleteLine":t||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":t||this._indentSel();break;case"outdentLine":t||this._unindentSel();break;default:console.warn(`[syncline-editor] executeCommand: unknown command "${e}"`);break}}destroy(){var t;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),(t=this._ro)==null||t.disconnect();const e=this._mmCanvas.getContext("2d");e&&e.clearRect(0,0,this._mmCanvas.width,this._mmCanvas.height),this._shadow.innerHTML="",this._host.classList.remove("sl-host")}_buildFindBar(){const e=A("div","sl-find-bar");return e.innerHTML=`
497
+ </table>`}];function ti(r){const e=[...ei];return(r==="typescript"||r==="javascript")&&e.push(...Zt.filter(t=>!t.language||(Array.isArray(t.language)?t.language.includes(r):t.language===r))),r==="css"&&e.push(...Qt),e}function ii(r,e,t){let i=e;for(;i>0&&/\w/.test(r[i-1]);)i--;const s=r.slice(i,e);if(!s)return null;const n=t.find(o=>o.kind==="snip"&&o.label===s);return n?{snippet:n,start:i}:null}function si(){return{cursors:[],searchWord:"",lastMatchRow:-1,lastMatchCol:-1}}function rt(r,e,t,i){r.cursors.some(n=>n.row===e&&n.col===t)||r.cursors.push({row:e,col:t,sel:i})}function ot(r){r.cursors=[],r.searchWord="",r.lastMatchRow=-1,r.lastMatchCol=-1}function ni(r,e,t,i,s){const n=[{row:e,col:t,isPrimary:!0,idx:0},...i.map((d,u)=>({row:d.row,col:d.col,isPrimary:!1,idx:u+1}))];n.sort((d,u)=>u.row!==d.row?u.row-d.row:u.col-d.col);const o=r.map(d=>d);let a=e,l=t;const c=i.map(d=>({...d}));for(const d of n){const u=o[d.row]??"";o[d.row]=u.slice(0,d.col)+s+u.slice(d.col);for(const h of n)h!==d&&h.row===d.row&&h.col>=d.col&&(h.col+=s.length);d.col+=s.length,d.isPrimary?(a=d.row,l=d.col):(c[d.idx-1].row=d.row,c[d.idx-1].col=d.col)}return{doc:o,primaryRow:a,primaryCol:l,extraCursors:c}}function ri(r,e,t,i){const s=[{row:e,col:t,isPrimary:!0,idx:0},...i.map((c,d)=>({row:c.row,col:c.col,isPrimary:!1,idx:d+1}))];s.sort((c,d)=>d.row!==c.row?d.row-c.row:d.col-c.col);const n=r.map(c=>c);let o=e,a=t;const l=i.map(c=>({...c}));for(const c of s){if(c.col<=0)continue;const d=n[c.row]??"";n[c.row]=d.slice(0,c.col-1)+d.slice(c.col);for(const u of s)u!==c&&u.row===c.row&&u.col>c.col&&u.col--;c.col--,c.isPrimary?(o=c.row,a=c.col):l[c.idx-1].col=c.col}return{doc:n,primaryRow:o,primaryCol:a,extraCursors:l}}function oi(r,e,t,i,s){let n=r.searchWord;if(!n){if(s&&s.ar===s.fr&&(n=(e[s.ar]??"").slice(s.ac,s.fc)),!n){const l=e[t]??"",c=ye(l,i),d=ve(l,i);n=l.slice(c,d)}if(!n)return null;r.searchWord=n,r.lastMatchRow=t,r.lastMatchCol=i}const o=r.lastMatchRow,a=r.lastMatchCol;for(let l=o;l<e.length;l++){const c=e[l]??"";let u=l===o?a:0;for(;u<=c.length-n.length;){const h=c.indexOf(n,u);if(h<0)break;const _=h===0||!/\w/.test(c[h-1]),y=h+n.length>=c.length||!/\w/.test(c[h+n.length]);if(_&&y)return r.lastMatchRow=l,r.lastMatchCol=h+n.length,{word:n,sel:{ar:l,ac:h,fr:l,fc:h+n.length},row:l,col:h+n.length};u=h+1}}for(let l=0;l<=o;l++){const c=e[l]??"",d=l===o?a:c.length;let u=0;for(;u<d;){const h=c.indexOf(n,u);if(h<0||h>=d)break;const _=h===0||!/\w/.test(c[h-1]),y=h+n.length>=c.length||!/\w/.test(c[h+n.length]);if(_&&y)return r.lastMatchRow=l,r.lastMatchCol=h+n.length,{word:n,sel:{ar:l,ac:h,fr:l,fc:h+n.length},row:l,col:h+n.length};u=h+1}}return null}function ai(r,e,t){if(!e)return[];const i=[];for(let s=0;s<r.length;s++){const n=r[s]??"";if(t.useRegex)try{const o=new RegExp(e,t.caseSensitive?"g":"gi");let a;for(;(a=o.exec(n))!==null&&(i.push({row:s,col:a.index,len:a[0].length}),!!a[0].length););}catch{}else{const o=t.caseSensitive?n:n.toLowerCase(),a=t.caseSensitive?e:e.toLowerCase();let l=0;for(;;){const c=o.indexOf(a,l);if(c===-1)break;i.push({row:s,col:c,len:e.length}),l=c+1}}}return i}function li(r,e,t,i){const s=e[t];if(!s)return r;const n=[...r],o=n[s.row]??"";return n[s.row]=o.slice(0,s.col)+i+o.slice(s.col+s.len),n}function ci(r,e,t){const i=[...r];for(let s=e.length-1;s>=0;s--){const n=e[s],o=i[n.row]??"";i[n.row]=o.slice(0,n.col)+t+o.slice(n.col+n.len)}return i}function di(r,e,t){return r.length?(e+t+r.length)%r.length:-1}function hi(r,e,t,i){if(i)return[];const s=r[e]??"",n=ye(s,t),o=ve(s,t),a=s.slice(n,o);if(!a||a.length<2)return[];const l=[];for(let c=0;c<r.length;c++){const d=r[c]??"";let u=0;for(;u<=d.length-a.length;){const h=d.indexOf(a,u);if(h<0)break;const _=h===0||!/\w/.test(d[h-1]),y=h+a.length>=d.length||!/\w/.test(d[h+a.length]);_&&y&&!(c===e&&h===n)&&l.push({row:c,col:h,len:a.length}),u=h+1}}return l}const Se=[{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>"}],pi={typescript:Se,javascript:Se,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 at(r,e,t){const i=We[r]??ge,s=Oe[r]??be,n=pi[r]??Se;return[...[...i,...e].map(o=>({label:o,kind:"kw",detail:"keyword"})),...[...s,...t].map(o=>({label:o,kind:"typ",detail:"type"})),...n]}function ui(r,e){const t=new Set;for(const i of r){const s=i.match(/[a-zA-Z_$][\w$]*/g)??[];for(const n of s)n!==e&&n.length>2&&t.add(n)}return t}function lt(r,e){return r.language?Array.isArray(r.language)?r.language.includes(e):r.language===e:!0}function fi(r,e,t={},i=0,s=0){if(e.length<2)return[];const n=e.toLowerCase(),{language:o="typescript",extraKeywords:a=[],extraTypes:l=[],completions:c=[],replaceBuiltins:d=!1,maxResults:u=14}=t,h=c.filter(f=>f.kind==="snip"&&!!f.body&&lt(f,o)),_=c.filter(f=>!(f.kind==="snip"&&f.body)&&lt(f,o)),y=h.filter(f=>f.label.toLowerCase().startsWith(n));let g;if(t.provideCompletions){const f={line:r[i]??"",col:s,prefix:e,language:o,doc:r};let I;try{I=t.provideCompletions(f)}catch(T){console.error("[syncline-editor] provideCompletions threw an error:",T),I=null}g=I!=null?[...I,..._]:[...d?[]:at(o,a,l),..._]}else g=d?_:[...at(o,a,l),..._];const k=new Set(g.map(f=>f.label)),b=g.filter(f=>f.label.toLowerCase().startsWith(n)&&f.label!==e),M=new Set(y.map(f=>f.label)),x=[...ui(r,e)].filter(f=>f.toLowerCase().startsWith(n)&&!k.has(f)&&!M.has(f)).slice(0,8).map(f=>({label:f,kind:"var",detail:"in file"}));return[...y,...b.filter(f=>!M.has(f.label)),...x].slice(0,u)}function gi(r,e,t=!1){let i=e;for(;i>0&&(t?/[\w$.\-]/:/[\w$.]/).test(r[i-1]);)i--;return{prefix:r.slice(i,e),start:i}}function bi(r,e){const t=n=>/[\w$]/.test(n);let i=e;for(;i<r.length&&t(r[i]);)i++;let s=e;for(;s>0&&t(r[s-1]);)s--;if(s===i)return"";if(s>0&&r[s-1]==="."){let n=s-1,o=n;for(;o>0&&t(r[o-1]);)o--;if(o<n)return r.slice(o,i)}return r.slice(s,i)}const _i={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 mi(r,e){const t=_i[r];return!t||t.language&&!(Array.isArray(t.language)?t.language:[t.language]).includes(e)?null:t}function yi(r){var R,q,X,Z;const{vr:e,visIdx:t,curVisRow:i,wm:s,foldedLines:n,isFoldable:o,opts:a}=r,{docLine:l,segIdx:c,text:d}=e,u=t===i,h=l===((R=s.visualRows[i])==null?void 0:R.docLine),_=c>0,y=((q=s.segments[l])==null?void 0:q.slice(0,c).reduce((v,w)=>v+w.length,0))??0,g=r.docSel?Fe(r.docSel,l,((X=(s.segments[l]??[""])[c])==null?void 0:X.length)??0):null;let k=null;if(g){const v=((Z=(s.segments[l]??[""])[c])==null?void 0:Z.length)??0,w=Fe(r.docSel,l,v+y);if(w){const E=w.start-y,B=w.end-y;B>0&&E<d.length&&(k={start:Math.max(0,E),end:Math.min(d.length,B)})}}const b=r.findMatches.filter(v=>v.row===l).map(v=>{var G,te;const w=v.col-y,E=v.col+v.len-y;if(E<=0||w>=d.length)return null;const B=r.findIdx>=0&&((G=r.findMatches[r.findIdx])==null?void 0:G.row)===v.row&&((te=r.findMatches[r.findIdx])==null?void 0:te.col)===v.col;return{start:Math.max(0,w),end:Math.min(d.length,E),isCur:B}}).filter(Boolean),M=r.wordHighlights.filter(v=>v.row===l).map(v=>{const w=v.col-y,E=v.col+v.len-y;return E<=0||w>=d.length?null:{start:Math.max(0,w),end:Math.min(d.length,E)}}).filter(Boolean),m=[];if(r.bracketMatch){for(const v of[r.bracketMatch.open,r.bracketMatch.close])if(v.row===l){const w=v.col-y;w>=0&&w<d.length&&m.push({start:w,end:w+1})}}const x=[],f=[];for(const v of r.extraCursors){const w=ee(s,v.row,v.col);if(w.visRow===t&&x.push(w.colInSeg),v.sel){const E=wi(v.sel);if(l>=E.ar&&l<=E.fr){const B=l===E.ar?E.ac-y:-y,G=l===E.fr?E.fc-y:d.length+999;G>0&&B<d.length&&f.push({start:Math.max(0,B),end:Math.min(d.length,G)})}}}const I=[];for(const v of r.remoteCursors){const w=ee(s,v.row,v.col);w.visRow===t&&I.push({col:w.colInSeg,name:v.name,color:v.color})}const T=[];for(const v of r.remoteSels){const w=v.from.row<v.to.row||v.from.row===v.to.row&&v.from.col<=v.to.col?v.from:v.to,E=w===v.from?v.to:v.from;if(l>=w.row&&l<=E.row){const B=l===w.row?w.col-y:-y,G=l===E.row?E.col-y:d.length+999;G>0&&B<d.length&&T.push({start:Math.max(0,B),end:Math.min(d.length,G),color:v.color})}}const L=vi(d,a.renderWhitespace),K=u||k||b.length||x.length||M.length||m.length||f.length||r.snippetStopCols.length>0||I.length>0||T.length>0;let N;if(K)N=xi(L,u?r.curColInSeg:-1,k,b,x,r.snippetStopCols,M,m,f,a.tokeniserOpts,I,T,t===0);else{const v=`${l}:${c}:${a.renderWhitespace}`;let w=r.tokenCache.get(v,L);w||(w=_e(L,a.tokeniserOpts),r.tokenCache.set(v,L,w)),N=ki(L,w)||"&#8203;"}let W="";if(c===0&&a.showIndentGuides){const v=(d.match(/^(\s*)/)??["",""])[1].length,w=Math.floor(v/a.tabSize);for(let E=1;E<w;E++){const B=a.codePaddingLeft+E*a.tabSize*a.charWidth;W+=`<span class="sl-ig" style="left:${B}px"></span>`}}let F="";if(c===0&&o){const v=n.has(l);F=`<span class="sl-fold-btn" data-row="${l}">${v?"▸":"▾"}</span>`}const z=n.has(l)&&c===0,S=c===0?String(l+1):"";return`<div class="${["sl-er",a.highlightActiveLine&&h?"sl-cur-row":"",_?"sl-wrap-cont":"",z?"sl-folded":""].filter(Boolean).join(" ")}" style="height:${a.lineHeight}px" data-v="${t}" data-doc="${l}"><div class="sl-eg" style="position:relative">${F}<span class="sl-egn">${S}</span></div><div class="sl-el"><span class="sl-cl">${W}${N}</span></div></div>`}function vi(r,e){if(e==="none")return r;if(e==="all")return r.replace(/ /g,"·").replace(/\t/g,"→");const t=(r.match(/^ +/)??[""])[0].length,i=(r.match(/ +$/)??[""])[0].length;let s=r;return t&&(s="·".repeat(t)+s.slice(t)),i&&(s=s.slice(0,s.length-i)+"·".repeat(i)),s.replace(/\t/g,"→")}function wi(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 ki(r,e){if(!r)return"";const t=ze(r,e);let i="",s=0,n=t[0];const o=a=>{if(a<=s)return;const l=se(r.slice(s,a));i+=n?`<span class="${n}">${l}</span>`:l};for(let a=1;a<=r.length;a++){const l=a<r.length?t[a]:null;l!==n&&(o(a),s=a,n=l??"")}return i}function xi(r,e,t,i,s,n,o,a,l,c,d=[],u=[],h=!1){if(r.length===0){let f=e>=0?'<span class="sl-cur"></span>':"";for(const I of s)f+='<span class="sl-cur-extra"></span>';for(const I of n)f+='<span class="sl-snip-stop"></span>';for(const I of d)f+=`<span class="${h?"sl-rc sl-rc-flip":"sl-rc"}" style="--rc-color:${I.color}"><span class="sl-rc-label">${se(I.name)}</span></span>`;return f||"&#8203;"}const _=_e(r,c),y=ze(r,_);let g="",k=0,b="",M="",m="";const x=f=>{if(f<=k)return;const I=se(r.slice(k,f)),T=[b,M,m?"sl-rs":""].filter(Boolean).join(" "),L=m?` style="--rs-color:${m}33"`:"";g+=T||L?`<span${L}${T?` class="${T}"`:""}>${I}</span>`:I};for(let f=0;f<=r.length;f++){e===f&&(x(f),k=f,g+='<span class="sl-cur"></span>');for(const S of s)S===f&&(x(f),k=f,g+='<span class="sl-cur-extra"></span>');for(const S of n)S===f&&(x(f),k=f,g+='<span class="sl-snip-stop"></span>');for(const S of d)S.col===f&&(x(f),k=f,g+=`<span class="${h?"sl-rc sl-rc-flip":"sl-rc"}" style="--rc-color:${S.color}"><span class="sl-rc-label">${se(S.name)}</span></span>`);if(f===r.length){x(f);break}const I=y[f]??"",T=i.find(S=>f>=S.start&&f<S.end),L=t&&f>=t.start&&f<t.end||l.some(S=>f>=S.start&&f<S.end),K=!L&&!T&&o.some(S=>f>=S.start&&f<S.end),N=!L&&!T&&a.some(S=>f>=S.start&&f<S.end);let W="";L?W="sl-sh":T?W="sl-fh"+(T.isCur?" sl-fh-cur":""):N?W="sl-bm":K&&(W="sl-wh");const F=L?void 0:u.find(S=>f>=S.start&&f<S.end),z=(F==null?void 0:F.color)??"";(W!==b||I!==M||z!==m)&&(x(f),k=f,b=W,M=I,m=z)}return g||"&#8203;"}function Me(r,e,t,i,s){const n=Math.max(0,r*s-t),o=Math.max(0,r*V-i),l=(n>0?e/n:0)*o,c=Math.max(20,t/s*V),d=e/s*V-l;return{mmScroll:l,sliderTop:d,sliderHeight:c}}function Ci(r,e,t,i,s){const n=Math.max(0,e*s-t),o=Math.max(0,e*V-i);if(n<=0)return 0;const a=V/s-o/n;if(Math.abs(a)<1e-9){const l=Math.max(20,t/s*V);return Math.max(0,Math.min(n,r/Math.max(1,i-l)*n))}return Math.max(0,Math.min(n,r/a))}function Ti(r,e,t,i,s,n){const o=Math.max(0,e*n-i),a=Math.max(0,e*V-s);if(o<=0)return 0;const l=t/o*a,c=(r+l)/V;return Math.max(0,Math.min(o,c*n-i/2))}function ct(r){const e=t=>{const i=r(t);return i.startsWith("#")&&i.length===7?Ze(i,.85):i};return{kw:e("--tok-kw"),fn:e("--tok-fn"),cls:e("--tok-cls"),typ:e("--tok-typ"),str:e("--tok-str"),num:e("--tok-num"),cmt:e("--tok-cmt"),dec:e("--tok-dec"),op:e("--tok-op"),txt:(()=>{const t=r("--text2");return t.startsWith("#")&&t.length===7?Ze(t,.28):"rgba(150,148,140,0.28)"})()}}function Si(r){var S,ne;const{canvas:e,doc:t,firstLine:i,lastLine:s,subPx:n,wrapperWidth:o,canvasHeight:a,cursorRow:l,sel:c,findMatches:d,findIdx:u,sliderTop:h,sliderHeight:_,colors:y,getCssVar:g,dpr:k}=r,b=e.getContext("2d");if(!b)return;b.setTransform(k,0,0,k,0,0);const M=g("--mm-bg")||"#0d0d0f",m=g("--mm-dim")||"rgba(0,0,0,.30)",x=g("--mm-edge")||"rgba(255,255,255,.18)",f=g("--mm-slider")||"rgba(255,255,255,.07)",I=g("--sel-bg")||"rgba(110,159,255,.22)",T=g("--cur-line-bg")||"rgba(255,255,255,.05)",L=g("--find-border")||"rgba(234,180,86,.50)",K=g("--find-cur-bg")||"rgba(234,180,86,.80)",N=R=>(R-i)*V;if(b.fillStyle=M,b.fillRect(0,0,o,a),l>=i&&l<s&&(b.fillStyle=T,b.fillRect(0,N(l),o,V)),c){const R=Math.max(i,c.ar),q=Math.min(s-1,c.fr);q>=R&&(b.fillStyle=I,b.fillRect(0,N(R),o,(q-R+1)*V))}for(const R of d){if(R.row<i||R.row>=s)continue;const q=u>=0&&((S=d[u])==null?void 0:S.row)===R.row&&((ne=d[u])==null?void 0:ne.col)===R.col;b.fillStyle=q?K:L,b.fillRect(le+R.col*Y,N(R.row),Math.max(3,R.len*Y),V)}const W=Math.floor((o-le)/Y);for(let R=i;R<s;R++){const q=t[R]??"";if(!q.trim())continue;const X=N(R),Z=1.5,v=_e(q);let w=0;for(const B of v){if(B.start>=W)break;B.start>w&&(b.fillStyle=y.txt,b.fillRect(le+w*Y,X,(Math.min(B.start,W)-w)*Y,Z));const G=y[B.cls]??y.txt,te=Math.min(B.end,W)-B.start;te>0&&(b.fillStyle=G,b.fillRect(le+B.start*Y,X,te*Y,Z)),w=Math.max(w,Math.min(B.end,W))}const E=Math.min(q.length,W);w<E&&(b.fillStyle=y.txt,b.fillRect(le+w*Y,X,(E-w)*Y,Z))}const F=h+n,z=F+_;b.fillStyle=m,F>0&&b.fillRect(0,0,o,F),z<a&&b.fillRect(0,z,o,a-z),b.fillStyle=f,b.fillRect(0,F,o,_),b.fillStyle=x,b.fillRect(0,Math.max(0,F),o,1),b.fillRect(0,Math.max(0,z-1),o,1)}const Mi={value:"",language:"typescript",theme:"",showGutter:!0,showMinimap:!0,showStatusBar:!0,wordWrap:!1,wrapColumn:Tt,fontFamily:"'JetBrains Mono', monospace",fontSize:xt,lineHeight:wt,tabSize:Ct,insertSpaces:!0,maxUndoHistory:je,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:Mt,gutterWidth:kt,minimapWidth:St,cursorBlinkRate:1050,cursorStyle:"line",renderWhitespace:"none",tokenColors:{},hover:!0,placeholder:"",goToLine:!1};class dt{constructor(e,t={}){p(this,"_host");p(this,"_shadow");p(this,"_editorEl");p(this,"_spacerEl");p(this,"_vpEl");p(this,"_inputEl");p(this,"_minimapWrap");p(this,"_mmCanvas");p(this,"_mmSlider");p(this,"_statusBar");p(this,"_findBar");p(this,"_findInput");p(this,"_replaceInput");p(this,"_findCount");p(this,"_replaceRow");p(this,"_acPopup");p(this,"_emmetTip");p(this,"_snippetTip");p(this,"_hoverTip");p(this,"_themeOverlay");p(this,"_themePanel");p(this,"_placeholderEl");p(this,"_goToLineBar");p(this,"_goToLineInput");p(this,"_goToLineHint");p(this,"_config");p(this,"_tab",Ne(1,[""]));p(this,"_wm",{segments:[[""]],visualRows:[{docLine:0,segIdx:0,text:""}],docToVisArr:[0]});p(this,"_foldedLines",new Map);p(this,"_tokenCache",new Nt);p(this,"_themeManager");p(this,"_findMatches",[]);p(this,"_findIdx",-1);p(this,"_findCaseSensitive",!1);p(this,"_findRegex",!1);p(this,"_wordHighlights",[]);p(this,"_bracketMatch",null);p(this,"_acItems",[]);p(this,"_acSel",0);p(this,"_acPrefix","");p(this,"_acStartCol",0);p(this,"_emmetAcStartCol",0);p(this,"_mc",si());p(this,"_extraCursors",[]);p(this,"_isDragging",!1);p(this,"_dragAnchor",null);p(this,"_hoverTimer",null);p(this,"_hoverPinned",!1);p(this,"_mmDragMode","none");p(this,"_mmDragStartY",0);p(this,"_mmDragStartScroll",0);p(this,"_mmSliderOffset",0);p(this,"_mmColors");p(this,"_lastInputTime",0);p(this,"_dynamicStyleEl");p(this,"_emmetExpanded",null);p(this,"_snippetExpanded",null);p(this,"_snippetSession",null);p(this,"_collabBinding",null);p(this,"_remotePeers",new Map);p(this,"_acDebounceTimer",null);p(this,"_rafId",null);p(this,"_onWinMouseUp");p(this,"_onWinResize");p(this,"_onEditorScroll");p(this,"_onWinMmMouseMove");p(this,"_onWinMmMouseUp");p(this,"_ro",null);p(this,"_onFoldBtnClick",e=>{const t=e.target.closest(".sl-fold-btn");if(!t)return;e.preventDefault(),e.stopPropagation();const i=parseInt(t.dataset.row??"0",10);this._foldedLines=Jt(this._foldedLines,this._tab.doc,i),this._tokenCache.clear(),this._rebuildWrapMap(),this._render()});this._config={...Mi,...it(t)},this._onWinMouseUp=()=>{var l,c,d,u;this._isDragging&&((c=(l=this._config).onCursorChange)==null||c.call(l,{...this._tab.cur}),(u=(d=this._config).onSelectionChange)==null||u.call(d,this._tab.sel?{...this._tab.sel}:null),this._broadcastCursorToCollab()),this._isDragging=!1,this._dragAnchor=null},this._onEditorScroll=we(()=>{this._hideHover(),this._scheduleRender(),this._updateMinimap()},16),this._onWinResize=we(()=>{this._config.wordWrap&&this._rebuildWrapMap(),this._scheduleRender()},100),this._onWinMmMouseMove=l=>{if(this._mmDragMode==="none")return;const c=this._minimapWrap.clientHeight;if(this._mmDragMode==="slider"){const d=l.clientY-this._minimapWrap.getBoundingClientRect().top;this._editorEl.scrollTop=Ci(d-this._mmSliderOffset,this._tab.doc.length,this._editorEl.clientHeight,c,this._config.lineHeight)}else{const d=l.clientY-this._mmDragStartY,u=Math.max(0,this._tab.doc.length*this._config.lineHeight-this._editorEl.clientHeight);this._editorEl.scrollTop=Math.max(0,Math.min(u,this._mmDragStartScroll+d/2*this._config.lineHeight))}this._render()},this._onWinMmMouseUp=()=>{this._mmDragMode!=="none"&&(this._mmDragMode="none",this._minimapWrap.style.cursor="pointer")},this._host=e,this._host.classList.add("sl-host"),this._shadow=this._host.attachShadow({mode:"open"});const i=H("style");i.textContent=zt,this._shadow.appendChild(i),this._dynamicStyleEl=H("style"),this._shadow.appendChild(this._dynamicStyleEl),this._themeManager=new Ut(this._host);const s=typeof this._config.theme=="string"?this._config.theme:this._config.theme;this._themeManager.apply(s);const n=H("div","sl-layout"),o=H("div","sl-ed-pane");this._inputEl=H("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=H("div","sl-editor"),this._spacerEl=H("div","sl-spacer"),this._vpEl=H("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=H("div","sl-placeholder"),this._placeholderEl.textContent=this._config.placeholder,this._placeholderEl.style.display="none",o.appendChild(this._inputEl),o.appendChild(this._findBar),o.appendChild(this._goToLineBar),o.appendChild(this._placeholderEl),o.appendChild(this._editorEl),this._minimapWrap=H("div","sl-minimap"),this._minimapWrap.style.width=`${this._config.minimapWidth}px`,this._mmCanvas=H("canvas",""),this._mmSlider=H("div","sl-mm-slider"),this._minimapWrap.appendChild(this._mmCanvas),this._minimapWrap.appendChild(this._mmSlider),n.appendChild(o),this._config.showMinimap&&n.appendChild(this._minimapWrap),this._statusBar=this._buildStatusBar(),this._acPopup=H("div","sl-ac-popup"),this._acPopup.setAttribute("role","listbox"),this._acPopup.setAttribute("aria-label","Code suggestions"),this._acPopup.style.display="none",this._emmetTip=H("div","sl-emmet-tip"),this._emmetTip.style.display="none",this._snippetTip=H("div","sl-emmet-tip"),this._snippetTip.style.display="none",this._hoverTip=H("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=H("div","sl-theme-overlay"),this._themeOverlay.style.display="none",this._themePanel=H("div","sl-theme-panel"),this._themeOverlay.appendChild(this._themePanel),this._shadow.appendChild(n),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 a=typeof this._config.value=="string"?Qe(this._config.value):this._config.value;this._tab=Ne(1,a.length?a:[""]),this._mmColors=ct(l=>me(l,this._host)),this._bindEditorEvents(),this._bindMinimapEvents(),this._bindFindEvents(),this._applyDynamicStyles(),typeof ResizeObserver<"u"&&(this._ro=new ResizeObserver(we(()=>{this._config.wordWrap&&(this._rebuildWrapMap(),this._scheduleRender())},60)),this._ro.observe(this._host)),this._rebuildWrapMap(),this._render(),this._config.collab&&this._initCollab(this._config.collab)}getValue(){return $(this._tab.doc)}setValue(e){var t,i;j(this._tab,this._config.maxUndoHistory),this._tab.doc=Qe(e),this._tab.cur={row:0,col:0},this._tab.sel=null,this._tokenCache.clear(),this._foldedLines.clear(),this._rebuildWrapMap(),this._render(),(i=(t=this._config).onChange)==null||i.call(t,e)}getCursor(){return{...this._tab.cur}}setCursor(e){this._tab.cur={...e},A(this._tab),this._scrollIntoView(),this._render()}getSelection(){return this._tab.sel?{...this._tab.sel}:null}setSelection(e){this._tab.sel=e,this._render()}insertText(e){this._config.readOnly||(this._insertStr(e,!1),this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render())}setTheme(e){this._themeManager.apply(e),this._applyTokenOverrides(),this._mmColors=ct(t=>me(t,this._host)),this._tokenCache.clear(),this._render()}updateConfig(e){const t=it(e);if(t.autoClosePairs!==void 0){const i=t.autoClosePairs;this._config.autoClosePairs=Object.keys(i).length===0?{}:{...this._config.autoClosePairs,...i};const{autoClosePairs:s,...n}=t;Object.assign(this._config,n)}else Object.assign(this._config,t);if(t.readOnly!==void 0&&this._inputEl.setAttribute("aria-readonly",String(!!t.readOnly)),e.theme!==void 0&&this.setTheme(e.theme),(e.wordWrap!==void 0||e.wrapColumn!==void 0)&&this._rebuildWrapMap(),e.showMinimap!==void 0){const i=this._shadow.querySelector(".sl-layout");e.showMinimap?i.contains(this._minimapWrap)||i.appendChild(this._minimapWrap):this._minimapWrap.remove()}e.showStatusBar!==void 0&&(e.showStatusBar?this._shadow.contains(this._statusBar)||this._shadow.appendChild(this._statusBar):this._statusBar.remove()),(e.fontFamily!==void 0||e.fontSize!==void 0||e.lineHeight!==void 0||e.cursorBlinkRate!==void 0||e.cursorStyle!==void 0||e.gutterWidth!==void 0||e.minimapWidth!==void 0||e.showGutter!==void 0||e.tokenColors!==void 0)&&this._applyDynamicStyles(),(e.language!==void 0||e.extraKeywords!==void 0||e.extraTypes!==void 0||e.renderWhitespace!==void 0||e.completions!==void 0)&&this._tokenCache.clear(),e.find===!1?this._closeFind():e.findReplace===!1&&(this._replaceRow.style.display="none"),e.goToLine===!1&&this._closeGoToLine(),e.placeholder!==void 0&&(this._placeholderEl.textContent=e.placeholder),"collab"in e&&(e.collab?this._initCollab(e.collab):this._destroyCollab()),this._render()}focus(){this._focusInput()}getThemes(){return this._themeManager.allIds}registerTheme(e){this._themeManager.register(e)}undo(){var e,t;Ht(this._tab)&&(this._tokenCache.clear(),this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render(),(t=(e=this._config).onChange)==null||t.call(e,$(this._tab.doc)))}redo(){var e,t;Pt(this._tab)&&(this._tokenCache.clear(),this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render(),(t=(e=this._config).onChange)==null||t.call(e,$(this._tab.doc)))}executeCommand(e){const t=this._config.readOnly;switch(e){case"undo":t||this.undo();break;case"redo":t||this.redo();break;case"selectAll":this._selectAll();break;case"copy":this._doCopy();break;case"cut":t||this._doCut();break;case"toggleComment":t||this._toggleComment();break;case"duplicateLine":t||this._duplicateLine();break;case"deleteLine":t||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":t||this._indentSel();break;case"outdentLine":t||this._unindentSel();break;default:console.warn(`[syncline-editor] executeCommand: unknown command "${e}"`);break}}_initCollab(e){this._destroyCollab();const t=new ae(e.transport.siteId),i=this._config.onChange;this._collabBinding=new fe(this,t,e.transport,{name:e.name,onPeersChange:n=>{var o;this._remotePeers=new Map(n),(o=e.onPeersChange)==null||o.call(e,n),this._scheduleRender()}});const s=this._config.onChange;s!==i&&(this._config.onChange=n=>{s==null||s(n),i==null||i(n)}),this._broadcastCursorToCollab()}_destroyCollab(){this._collabBinding&&(this._collabBinding.destroy(),this._collabBinding=null,this._remotePeers=new Map,this._scheduleRender())}_broadcastCursorToCollab(){if(!this._collabBinding)return;const{row:e,col:t}=this._tab.cur;if(this._collabBinding.awareness.updateCursor(e,t),this._tab.sel){const i=this._tab.sel;this._collabBinding.awareness.updateSelection({row:i.ar,col:i.ac},{row:i.fr,col:i.fc})}else this._collabBinding.awareness.clearSelection()}destroy(){var t;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),(t=this._ro)==null||t.disconnect();const e=this._mmCanvas.getContext("2d");e&&e.clearRect(0,0,this._mmCanvas.width,this._mmCanvas.height),this._shadow.innerHTML="",this._host.classList.remove("sl-host"),this._destroyCollab()}_buildFindBar(){const e=H("div","sl-find-bar");return e.innerHTML=`
421
498
  <div class="sl-find-row">
422
499
  <input class="sl-find-input" placeholder="Find…" autocomplete="off" spellcheck="false">
423
500
  <span class="sl-find-count">–</span>
@@ -432,7 +509,12 @@ gap: $2;`,language:["css"]},{label:"media",kind:"snip",detail:"@media query",des
432
509
  <button class="sl-find-btn sl-replace-one">Replace</button>
433
510
  <button class="sl-find-btn sl-replace-all">All</button>
434
511
  </div>
435
- `,e}_buildStatusBar(){const e=A("div","sl-statusbar");return e.innerHTML=`
512
+ `,e}_buildGoToLineBar(){const e=H("div","sl-gtl-bar");e.innerHTML=`
513
+ <span class="sl-gtl-label">Go to line</span>
514
+ <input class="sl-gtl-input" type="text" inputmode="numeric" autocomplete="off" spellcheck="false" placeholder="…">
515
+ <span class="sl-gtl-hint"></span>
516
+ <span class="sl-find-x sl-gtl-close" title="Close">✕</span>
517
+ `;const t=e.querySelector(".sl-gtl-input"),i=e.querySelector(".sl-gtl-hint");return t.addEventListener("input",()=>{const s=parseInt(t.value,10),n=!isNaN(s)&&s>=1&&s<=this._tab.doc.length;t.classList.toggle("sl-gtl-err",t.value!==""&&!n),i.textContent=`(1–${this._tab.doc.length})`}),t.addEventListener("keydown",s=>{var n,o;if(s.key==="Enter"){s.preventDefault();const a=parseInt(t.value,10);!isNaN(a)&&a>=1&&a<=this._tab.doc.length&&(this._tab.cur.row=a-1,this._tab.cur.col=Math.min(this._tab.cur.col,(this._tab.doc[a-1]??"").length),A(this._tab),this._tab.sel=null,this._closeGoToLine(),this._scrollIntoView(),this._render(),(o=(n=this._config).onCursorChange)==null||o.call(n,{...this._tab.cur}),this._broadcastCursorToCollab())}else s.key==="Escape"&&(s.preventDefault(),this._closeGoToLine());s.stopPropagation()}),e.querySelector(".sl-gtl-close").addEventListener("click",()=>this._closeGoToLine()),e}_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()}_buildStatusBar(){const e=H("div","sl-statusbar");return e.innerHTML=`
436
518
  <div class="sl-sb-item sl-no-click sl-sb-lang">⬡ TypeScript</div>
437
519
  <div class="sl-sb-sep"></div>
438
520
  <div class="sl-sb-item sl-no-click sl-sb-pos">Ln 1, Col 1</div>
@@ -450,18 +532,18 @@ gap: $2;`,language:["css"]},{label:"media",kind:"snip",detail:"@media query",des
450
532
  <div class="sl-sb-sep"></div>
451
533
  <div class="sl-sb-item sl-no-click sl-sb-undo">↩0 ↪0</div>
452
534
  </div>
453
- `,e.querySelector(".sl-sb-wrap-btn").addEventListener("click",()=>this._toggleWrap()),e.querySelector(".sl-sb-theme-btn").addEventListener("click",()=>this._openThemePicker()),e}_applyDynamicStyles(){const{fontFamily:e,fontSize:t,lineHeight:i,cursorBlinkRate:r,cursorStyle:n,gutterWidth:a,minimapWidth:l,showGutter:o}=this._config,c=Math.max(2,i-4),d=Math.floor((i-c)/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=o?a:0;this._dynamicStyleEl.textContent=`
535
+ `,e.querySelector(".sl-sb-wrap-btn").addEventListener("click",()=>this._toggleWrap()),e.querySelector(".sl-sb-theme-btn").addEventListener("click",()=>this._openThemePicker()),e}_applyDynamicStyles(){const{fontFamily:e,fontSize:t,lineHeight:i,cursorBlinkRate:s,cursorStyle:n,gutterWidth:o,minimapWidth:a,showGutter:l}=this._config,c=Math.max(2,i-4),d=Math.floor((i-c)/2);let u="";n==="block"?u=`width:${Q}px;opacity:.5;border-radius:1px;`:n==="underline"&&(u=`width:${Q}px;height:2px;top:${i-2}px;border-radius:0;`);const h=l?o:0;this._dynamicStyleEl.textContent=`
454
536
  .sl-el{font-family:${e};font-size:${t}px;line-height:${i}px}
455
537
  .sl-cl{height:${i}px;line-height:${i}px}
456
538
  .sl-egn{height:${i}px;line-height:${i}px}
457
- .sl-eg{min-width:${h}px;width:${h}px;${o?"":"display:none"}}
458
- .sl-cur::after{height:${c}px;top:${d}px;animation-duration:${r}ms;${p}}
459
- .sl-cur-extra::after{height:${c}px;top:${d}px;animation-duration:${r}ms;${p}}
460
- `,this._applyTokenOverrides(),this._minimapWrap.style.width=`${l}px`}_applyTokenOverrides(){const e=this._config.tokenColors??{},t=this._themeManager.activeTheme,i=this._host.style,r=(a,l,o)=>{i.setProperty(a,l||o)},n=t==null?void 0:t.tokens;r("--tok-kw",e.keyword,(n==null?void 0:n.tokKw)??""),r("--tok-str",e.string,(n==null?void 0:n.tokStr)??""),r("--tok-cmt",e.comment,(n==null?void 0:n.tokCmt)??""),r("--tok-fn",e.function,(n==null?void 0:n.tokFn)??""),r("--tok-num",e.number,(n==null?void 0:n.tokNum)??""),r("--tok-cls",e.class,(n==null?void 0:n.tokCls)??""),r("--tok-op",e.operator,(n==null?void 0:n.tokOp)??""),r("--tok-typ",e.type,(n==null?void 0:n.tokTyp)??""),r("--tok-dec",e.decorator,(n==null?void 0:n.tokDec)??"")}_scheduleRender(){this._rafId===null&&(this._rafId=requestAnimationFrame(()=>{this._rafId=null,this._render()}))}_render(){const{doc:e,cur:t,sel:i}=this._tab,{lineHeight:r}=this._config;this._wordHighlights=this._config.wordHighlight?Tt(e,t.row,t.col,i):[],this._bracketMatch=this._config.bracketMatching?at(e,t):null;const n=this._wm.visualRows.length;this._spacerEl.style.height=`${n*r}px`;const a=this._editorEl.scrollTop,l=this._editorEl.clientHeight,o=Math.max(0,Math.floor(a/r)-6),c=Math.min(n-1,Math.ceil((a+l)/r)+6);this._vpEl.style.transform=`translateY(${o*r}px)`;const d=G(this._wm,t.row,t.col);let p="";for(let h=o;h<=c;h++){const g=this._wm.visualRows[h];g&&(p+=Ht({vr:g,visIdx:h,curVisRow:d.visRow,curColInSeg:d.colInSeg,docSel:i,findMatches:this._findMatches,findIdx:this._findIdx,wordHighlights:this._wordHighlights,bracketMatch:this._bracketMatch,extraCursors:this._extraCursors,foldedLines:this._foldedLines,isFoldable:this._config.codeFolding&&ot(e,g.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)},showIndentGuides:this._config.showIndentGuides,highlightActiveLine:this._config.highlightActiveLine,charWidth:7.82,codePaddingLeft:14,tabSize:this._config.tabSize,lineHeight:r,renderWhitespace:this._config.renderWhitespace}}))}this._vpEl.innerHTML=p,this._updateStatusBar(),this._updateMinimap()}_updateStatusBar(){if(!this._config.showStatusBar)return;const{cur:e,doc:t,undoStack:i,redoStack:r}=this._tab,n=this._config.language,a={typescript:"TypeScript",javascript:"JavaScript",css:"CSS",json:"JSON",markdown:"Markdown",text:"Text"},l=h=>this._statusBar.querySelector(h);l(".sl-sb-lang").textContent=`⬡ ${a[n]??n}`,l(".sl-sb-pos").textContent=`Ln ${e.row+1}, Col ${e.col+1}`,l(".sl-sb-lines").textContent=`${t.length.toLocaleString()} lines`;const o=Xe(this._tab),c=l(".sl-sb-sel"),d=l(".sl-sb-sel-sep");c.textContent=o?`${o.toLocaleString()} selected`:"",d.style.display=o?"":"none",l(".sl-sb-undo").textContent=`↩${i.length} ↪${r.length}`;const p=l(".sl-sb-mc");this._extraCursors.length?(p.style.display="",l(".sl-sb-mc-count").textContent=String(this._extraCursors.length+1)):p.style.display="none"}_updateMinimap(){if(!this._config.showMinimap)return;const e=this._minimapWrap.clientWidth,t=this._minimapWrap.clientHeight;if(!e||!t)return;const i=this._tab.doc,r=i.length,n=Math.min(window.devicePixelRatio||1,2),a=this._config.lineHeight,{mmScroll:l,sliderTop:o,sliderHeight:c}=pe(r,this._editorEl.scrollTop,this._editorEl.clientHeight,t,a),d=l/2,p=Math.floor(d),h=Math.ceil(t/2)+2,g=Math.min(r,p+h),y=(g-p)*2,v=(d-p)*2,f=Math.round(e*n),b=Math.round(y*n);(this._mmCanvas.width!==f||this._mmCanvas.height!==b)&&(this._mmCanvas.width=f,this._mmCanvas.height=b,this._mmCanvas.style.width=`${e}px`,this._mmCanvas.style.height=`${y}px`),this._mmCanvas.style.transform=`translateY(${-v}px)`,Wt({canvas:this._mmCanvas,doc:i,firstLine:p,lastLine:g,subPx:v,wrapperWidth:e,canvasHeight:y,cursorRow:this._tab.cur.row,sel:this._tab.sel,findMatches:this._findMatches,findIdx:this._findIdx,sliderTop:o,sliderHeight:c,colors:this._mmColors,getCssVar:T=>re(T,this._host),dpr:n}),this._mmSlider.style.top=`${Math.max(0,Math.min(t-c,o))}px`,this._mmSlider.style.height=`${c}px`}_rebuildWrapMap(){let e;if(this._config.wordWrap){const t=this._config.showGutter?this._config.gutterWidth:0,i=this._editorEl.clientWidth;if(i>0){const r=i-t-14-20;e=Math.max(20,Math.floor(r/7.82))}else e=this._config.wrapColumn}else e=9999;this._wm=Qe(this._tab.doc,e,this._config.wordWrap,this._foldedLines)}_scrollIntoView(){const e=this._tab.cur,i=G(this._wm,e.row,e.col).visRow*this._config.lineHeight,r=i+this._config.lineHeight,n=this._editorEl.scrollTop,a=this._editorEl.clientHeight,l=this._config.lineHeight*3;i<n+l?this._editorEl.scrollTop=Math.max(0,i-l):r>n+a-l&&(this._editorEl.scrollTop=r-a+l)}_focusInput(){this._inputEl.style.pointerEvents="auto",this._inputEl.focus(),this._inputEl.style.pointerEvents="none"}_insertStr(e,t){var d,p;const i=Date.now();(!t||i-this._lastInputTime>this._config.undoBatchMs)&&S(this._tab,this._config.maxUndoHistory),this._lastInputTime=i,this._tab.sel&&(this._tab.cur=U(this._tab));const{doc:r,cur:n}=this._tab,a=e.split(`
461
- `),l=r[n.row]??"",o=l.slice(0,n.col),c=l.slice(n.col);if(a.length===1)r[n.row]=o+e+c,n.col+=e.length;else{const h=[o+a[0]];for(let g=1;g<a.length-1;g++)h.push(a[g]);h.push(a[a.length-1]+c),r.splice(n.row,1,...h),n.row+=a.length-1,n.col=a[a.length-1].length}this._tokenCache.invalidateLine(n.row,(this._wm.segments[n.row]??[""]).length),this._tab.dirty=!0,(p=(d=this._config).onChange)==null||p.call(d,L(r))}_doBackspace(){var i;if(S(this._tab,this._config.maxUndoHistory),this._tab.sel){this._tab.cur=U(this._tab),this._tokenCache.clear(),this._tab.dirty=!0;return}const{doc:e,cur:t}=this._tab;if(t.col>0){const r=e[t.row]??"",n=r.slice(0,t.col),a=n.length>=2&&n.endsWith(" ")&&!n.trim()?2:1;e[t.row]=r.slice(0,t.col-a)+r.slice(t.col),t.col-=a,this._tokenCache.invalidateLine(t.row,((i=this._wm.segments[t.row])==null?void 0:i.length)??1)}else if(t.row>0){const r=(e[t.row-1]??"").length;e[t.row-1]+=e[t.row]??"",e.splice(t.row,1),t.row--,t.col=r,this._tokenCache.clear()}this._tab.dirty=!0}_doEnter(){S(this._tab,this._config.maxUndoHistory),this._tab.sel&&(this._tab.cur=U(this._tab));const{doc:e,cur:t}=this._tab,i=e[t.row]??"",r=i.slice(0,t.col),n=i.slice(t.col),a=Ae(i),l=r.trimEnd().endsWith("{")?Z(this._config.tabSize):"";e[t.row]=r,r.trimEnd().endsWith("{")&&n.trimStart()==="}"?e.splice(t.row+1,0,a+l,a+n):e.splice(t.row+1,0,a+l+n),t.row++,t.col=a.length+l.length,this._tokenCache.clear(),this._tab.dirty=!0}_doDelete(){var r;if(S(this._tab,this._config.maxUndoHistory),this._tab.sel){this._tab.cur=U(this._tab),this._tokenCache.clear(),this._tab.dirty=!0;return}const{doc:e,cur:t}=this._tab,i=e[t.row]??"";t.col<i.length?(e[t.row]=i.slice(0,t.col)+i.slice(t.col+1),this._tokenCache.invalidateLine(t.row,((r=this._wm.segments[t.row])==null?void 0:r.length)??1)):t.row<e.length-1&&(e[t.row]=i+(e[t.row+1]??""),e.splice(t.row+1,1),this._tokenCache.clear()),this._tab.dirty=!0}_selectAll(){const e=this._tab.doc,t=e.length-1;this._tab.sel={ar:0,ac:0,fr:t,fc:(e[t]??"").length},this._tab.cur={row:t,col:(e[t]??"").length},this._render()}_doCopy(){var t;const e=ye(this._tab);e&&((t=navigator.clipboard)==null||t.writeText(e).catch(()=>{}))}_doCut(){var t,i,r;const e=ye(this._tab);e&&((t=navigator.clipboard)==null||t.writeText(e).catch(()=>{}),S(this._tab,this._config.maxUndoHistory),this._tab.cur=U(this._tab),this._tokenCache.clear(),this._tab.dirty=!0,this._rebuildWrapMap(),this._render(),(r=(i=this._config).onChange)==null||r.call(i,L(this._tab.doc)))}_toggleComment(){var n,a;S(this._tab,this._config.maxUndoHistory);const e=this._getSelRows(),t=this._config.lineCommentToken||Fe[this._config.language]||"";if(!t)return;const i=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),r=e.every(l=>(this._tab.doc[l]??"").trimStart().startsWith(t));e.forEach(l=>{var c;const o=this._tab.doc[l]??"";this._tab.doc[l]=r?o.replace(new RegExp(`^(\\s*)${i}\\s?`),"$1"):o.replace(/^(\s*)/,`$1${t} `),this._tokenCache.invalidateLine(l,((c=this._wm.segments[l])==null?void 0:c.length)??1)}),this._tab.dirty=!0,this._rebuildWrapMap(),this._render(),(a=(n=this._config).onChange)==null||a.call(n,L(this._tab.doc))}_duplicateLine(){var t,i;S(this._tab,this._config.maxUndoHistory);const e=this._tab.cur.row;this._tab.doc.splice(e+1,0,this._tab.doc[e]??""),this._tab.cur.row++,this._tokenCache.clear(),this._tab.dirty=!0,this._rebuildWrapMap(),this._render(),(i=(t=this._config).onChange)==null||i.call(t,L(this._tab.doc))}_deleteLine(){var i,r;S(this._tab,this._config.maxUndoHistory);const{doc:e,cur:t}=this._tab;e.length>1?e.splice(t.row,1):(e[0]="",t.col=0),this._tokenCache.clear(),this._tab.dirty=!0,I(this._tab),this._rebuildWrapMap(),this._render(),(r=(i=this._config).onChange)==null||r.call(i,L(this._tab.doc))}_indentSel(){var t,i;if(!this._tab.sel){this._insertStr(Z(this._config.tabSize),!1);return}S(this._tab,this._config.maxUndoHistory);const e=Z(this._config.tabSize);this._getSelRows().forEach(r=>{var n;this._tab.doc[r]=e+(this._tab.doc[r]??""),this._tokenCache.invalidateLine(r,((n=this._wm.segments[r])==null?void 0:n.length)??1)}),this._tab.dirty=!0,this._rebuildWrapMap(),this._render(),(i=(t=this._config).onChange)==null||i.call(t,L(this._tab.doc))}_unindentSel(){var t,i;S(this._tab,this._config.maxUndoHistory);const e=this._config.tabSize;this._getSelRows().forEach(r=>{var a;const n=this._tab.doc[r]??"";n.startsWith(Z(e))?this._tab.doc[r]=n.slice(e):n.startsWith(" ")&&(this._tab.doc[r]=n.slice(1)),this._tokenCache.invalidateLine(r,((a=this._wm.segments[r])==null?void 0:a.length)??1)}),this._tab.dirty=!0,this._rebuildWrapMap(),this._render(),(i=(t=this._config).onChange)==null||i.call(t,L(this._tab.doc))}_toggleWrap(){this._config.wordWrap=!this._config.wordWrap,this._vpEl.classList.toggle("sl-wrap-mode",this._config.wordWrap);const e=this._statusBar.querySelector(".sl-sb-wrap-btn");e&&(e.textContent=`⇥ Wrap: ${this._config.wordWrap?"ON":"OFF"}`,e.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 e=$(this._tab.sel),t=[];for(let i=e.ar;i<=e.fr;i++)t.push(i);return t}_posFromMouse(e){var c;const t=this._editorEl.getBoundingClientRect(),i=e.clientY-t.top+this._editorEl.scrollTop,r=this._config.showGutter?this._config.gutterWidth:0,n=e.clientX-t.left-r-14,a=this._config.lineHeight,l=Math.max(0,Math.min(this._wm.visualRows.length-1,Math.floor(i/a))),o=Math.max(0,Math.min((((c=this._wm.visualRows[l])==null?void 0:c.text)??"").length,Math.round(n/7.82)));return X(this._wm,l,o)}_openFind(e){this._findBar.classList.add("sl-open"),this._replaceRow.style.display=e&&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(e){this._findMatches=vt(this._tab.doc,e,{caseSensitive:this._findCaseSensitive,useRegex:this._findRegex})}_navFind(e){if(!this._findMatches.length){this._findCount.textContent="0/0";return}this._findIdx=xt(this._findMatches,this._findIdx,e);const t=this._findMatches[this._findIdx];this._tab.cur={row:t.row,col:t.col},this._tab.sel={ar:t.row,ac:t.col,fr:t.row,fc:t.col+t.len},this._scrollIntoView(),this._render(),this._findCount.textContent=`${this._findIdx+1}/${this._findMatches.length}`}_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:e,doc:t}=this._tab,i=t[e.row]??"",r=this._config.language==="css",{prefix:n,start:a}=St(i,e.col,r);this._acPrefix=n,this._acStartCol=a;const l=[];if(this._config.emmet){const c=Re(i,e.col);if(c){const d=De(c.abbr);if(d){this._emmetAcStartCol=c.start;const p=d.replace(/\n/g,"↵ ").slice(0,60);l.push({label:c.abbr,kind:"emmet",detail:p,body:d})}}}const o=n.length>=this._config.autocompletePrefixLength?Et(t,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},e.row,e.col):[];if(this._acItems=[...l,...o],!this._acItems.length){this._acHide();return}this._acSel=0,this._renderAcPopup()}_renderAcPopup(){const e=o=>{switch(o){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"·"}},t=this._acItems[this._acSel];let i="";t!=null&&t.description?i=t.description:(t==null?void 0:t.kind)==="snip"&&t.body?i=t.body.replace(/\$\d/g,"▌"):(t==null?void 0:t.kind)==="emmet"&&t.body&&(i=t.body);const r=this._acItems.map((o,c)=>{const d=c===this._acSel;return`<div class="sl-ac-item${d?" sl-sel":""}" data-i="${c}" role="option" aria-selected="${d}"><span class="sl-ac-badge ${o.kind}">${e(o.kind)}</span><span class="sl-ac-label">${o.label}</span><span class="sl-ac-detail">${o.detail??""}</span></div>`}).join(""),n=i?`<div class="sl-ac-desc"><pre class="sl-ac-desc-body">${i.replace(/</g,"&lt;")}</pre></div>`:"";this._acPopup.innerHTML=`<div class="sl-ac-list">${r}</div>`+n,this._acPopup.style.display="flex",this._posAcPopup();const a=this._acPopup.querySelector(".sl-ac-list"),l=this._acPopup.querySelector(".sl-ac-item.sl-sel");if(a&&l){const o=l.offsetTop,c=o+l.offsetHeight;c>a.scrollTop+a.clientHeight?a.scrollTop=c-a.clientHeight:o<a.scrollTop&&(a.scrollTop=o)}this._acPopup.querySelectorAll(".sl-ac-item").forEach(o=>{o.addEventListener("mousedown",c=>{c.preventDefault(),this._acSel=parseInt(o.dataset.i??"0",10),this._acAccept()})})}_posAcPopup(){const e=this._editorEl.getBoundingClientRect(),t=G(this._wm,this._tab.cur.row,this._tab.cur.col),i=this._config.showGutter?this._config.gutterWidth:0,r=e.left+i+14+this._acStartCol*7.82,n=e.top+(t.visRow*this._config.lineHeight-this._editorEl.scrollTop)+this._config.lineHeight+2,l=!!this._acPopup.querySelector(".sl-ac-desc")?620:300,o=Math.min(this._acItems.length*28+8,320),c=n+o>window.innerHeight-16;this._acPopup.style.left=`${Math.min(r,window.innerWidth-l-16)}px`,this._acPopup.style.top=`${c?n-this._config.lineHeight-2-o:n}px`}_acAccept(){const e=this._acItems[this._acSel];if(!e)return;if(this._acHide(),e.kind==="emmet"&&e.body){S(this._tab,this._config.maxUndoHistory),this._expandBodyAt(e.body,this._emmetAcStartCol);return}if(e.body){S(this._tab,this._config.maxUndoHistory),this._expandBodyAt(e.body,this._acStartCol);return}const t=e.label.slice(this._acPrefix.length);this._insertStr(t,!1),this._rebuildWrapMap(),I(this._tab),this._scrollIntoView(),this._render()}_emmetCheck(){if(this._emmetTip.style.display="none",!this._config.emmet){this._emmetExpanded=null;return}const{cur:e,doc:t}=this._tab,i=t[e.row]??"",r=Re(i,e.col);if(!r){this._emmetExpanded=null;return}const n=De(r.abbr);if(!n){this._emmetExpanded=null;return}this._emmetExpanded={abbr:r.abbr,result:n,start:r.start}}_emmetAccept(){if(!this._emmetExpanded||this._emmetTip.style.display==="none")return!1;const{abbr:e,result:t,start:i}=this._emmetExpanded;return S(this._tab,this._config.maxUndoHistory),this._emmetExpanded=null,this._emmetTip.style.display="none",this._expandBodyAt(t,i),!0}_allCompletions(){return[...this._config.replaceBuiltins?[]:ft(this._config.language),...this._config.completions]}_snippetCheck(){if(this._snippetTip.style.display="none",!this._config.snippetExpansion){this._snippetExpanded=null;return}const{cur:e,doc:t}=this._tab,i=t[e.row]??"",r=gt(i,e.col,this._allCompletions());if(!r){this._snippetExpanded=null;return}this._snippetExpanded={snippet:r.snippet,start:r.start}}_snippetAccept(){if(!this._snippetExpanded||this._snippetTip.style.display==="none")return!1;const{snippet:e,start:t}=this._snippetExpanded;return e.body?(S(this._tab,this._config.maxUndoHistory),this._snippetExpanded=null,this._snippetTip.style.display="none",this._expandBodyAt(e.body,t),!0):!1}_expandBodyAt(e,t){var y,v;const{doc:i,cur:r}=this._tab,n=i[r.row]??"",a=n.slice(0,t),l=n.slice(r.col),o=Ae(n),c=e.split(`
462
- `).map((f,b)=>b===0?f:o+f),d=c.join(`
463
- `),p=d.indexOf("$1"),h=c.map(f=>f.replace(/\$\d+/g,"")),g=h.length===1?[a+h[0]+l]:[a+h[0],...h.slice(1,-1),h[h.length-1]+l];if(i.splice(r.row,1,...g),p>=0){const f=d.slice(0,p).split(`
464
- `),b=f.length-1,T=f[b].length,_=(f[b].match(/\$\d+/g)??[]).join("").length;r.row+=b,r.col=(b===0?t:o.length)+(T-_)}else r.row+=g.length-1,r.col=(g[g.length-1]??"").length-l.length;this._tokenCache.clear(),this._tab.dirty=!0,this._rebuildWrapMap(),I(this._tab),this._scrollIntoView(),this._render(),(v=(y=this._config).onChange)==null||v.call(y,L(this._tab.doc))}_openThemePicker(){var t;const e=this._themeManager.all;this._themePanel.innerHTML=`
539
+ .sl-eg{min-width:${h}px;width:${h}px;${l?"":"display:none"}}
540
+ .sl-cur::after{height:${c}px;top:${d}px;animation-duration:${s}ms;${u}}
541
+ .sl-cur-extra::after{height:${c}px;top:${d}px;animation-duration:${s}ms;${u}}
542
+ `,this._applyTokenOverrides(),this._minimapWrap.style.width=`${a}px`,this._placeholderEl.style.left=`${h+ie}px`,this._placeholderEl.style.fontFamily=e,this._placeholderEl.style.fontSize=`${t}px`,this._placeholderEl.style.lineHeight=`${i}px`}_applyTokenOverrides(){const e=this._config.tokenColors??{},t=this._themeManager.activeTheme,i=this._host.style,s=(o,a,l)=>{i.setProperty(o,a||l)},n=t==null?void 0:t.tokens;s("--tok-kw",e.keyword,(n==null?void 0:n.tokKw)??""),s("--tok-str",e.string,(n==null?void 0:n.tokStr)??""),s("--tok-cmt",e.comment,(n==null?void 0:n.tokCmt)??""),s("--tok-fn",e.function,(n==null?void 0:n.tokFn)??""),s("--tok-num",e.number,(n==null?void 0:n.tokNum)??""),s("--tok-cls",e.class,(n==null?void 0:n.tokCls)??""),s("--tok-op",e.operator,(n==null?void 0:n.tokOp)??""),s("--tok-typ",e.type,(n==null?void 0:n.tokTyp)??""),s("--tok-dec",e.decorator,(n==null?void 0:n.tokDec)??"")}_scheduleRender(){this._rafId===null&&(this._rafId=requestAnimationFrame(()=>{this._rafId=null,this._render()}))}_render(){const{doc:e,cur:t,sel:i}=this._tab,{lineHeight:s}=this._config;this._wordHighlights=this._config.wordHighlight?hi(e,t.row,t.col,i):[],this._bracketMatch=this._config.bracketMatching?Vt(e,t):null;const n=this._wm.visualRows.length;if(this._spacerEl.style.height=`${n*s}px`,this._config.wordWrap)this._spacerEl.style.width="",this._vpEl.style.width="";else{const g=e.reduce((M,m)=>Math.max(M,m.length),0),k=this._config.showGutter?this._config.gutterWidth:0,b=Math.max(this._editorEl.clientWidth,k+ie+Math.ceil(g*Q)+He+64);this._spacerEl.style.width=`${b}px`,this._vpEl.style.width=`${b}px`}const o=this._editorEl.scrollTop,a=this._editorEl.clientHeight,l=Math.max(0,Math.floor(o/s)-De),c=Math.min(n-1,Math.ceil((o+a)/s)+De);this._vpEl.style.transform=`translateY(${l*s}px)`;const d=ee(this._wm,t.row,t.col),u=new Map;if(this._snippetSession)for(let g=this._snippetSession.idx+1;g<this._snippetSession.stops.length;g++){const k=this._snippetSession.stops[g],b=ee(this._wm,k.row,k.col),M=u.get(b.visRow)??[];M.push(b.colInSeg),u.set(b.visRow,M)}const h=[],_=[];for(const g of this._remotePeers.values())g.cursor&&h.push({row:g.cursor.row,col:g.cursor.col,name:g.name,color:g.color}),g.selection&&_.push({from:g.selection.from,to:g.selection.to,color:g.color});let y="";for(let g=l;g<=c;g++){const k=this._wm.visualRows[g];k&&(y+=yi({vr:k,visIdx:g,curVisRow:d.visRow,curColInSeg:d.colInSeg,docSel:i,findMatches:this._findMatches,findIdx:this._findIdx,wordHighlights:this._wordHighlights,bracketMatch:this._bracketMatch,extraCursors:this._extraCursors,snippetStopCols:u.get(g)??[],foldedLines:this._foldedLines,isFoldable:this._config.codeFolding&&Kt(e,k.docLine),wm:this._wm,tokenCache:this._tokenCache,remoteCursors:h,remoteSels:_,opts:{tokeniserOpts:{language:this._config.language,extraKeywords:new Set(this._config.extraKeywords),extraTypes:new Set(this._config.extraTypes)},showIndentGuides:this._config.showIndentGuides,highlightActiveLine:this._config.highlightActiveLine,charWidth:Q,codePaddingLeft:ie,tabSize:this._config.tabSize,lineHeight:s,renderWhitespace:this._config.renderWhitespace}}))}if(this._vpEl.innerHTML=y,this._updateStatusBar(),this._updateMinimap(),this._config.placeholder){const g=this._tab.doc.length===1&&this._tab.doc[0]==="";this._placeholderEl.style.display=g?"":"none"}else this._placeholderEl.style.display="none"}_updateStatusBar(){if(!this._config.showStatusBar)return;const{cur:e,doc:t,undoStack:i,redoStack:s}=this._tab,n=this._config.language,o={typescript:"TypeScript",javascript:"JavaScript",css:"CSS",json:"JSON",markdown:"Markdown",text:"Text"},a=h=>this._statusBar.querySelector(h);a(".sl-sb-lang").textContent=`⬡ ${o[n]??n}`,a(".sl-sb-pos").textContent=`Ln ${e.row+1}, Col ${e.col+1}`,a(".sl-sb-lines").textContent=`${t.length.toLocaleString()} lines`;const l=$t(this._tab),c=a(".sl-sb-sel"),d=a(".sl-sb-sel-sep");c.textContent=l?`${l.toLocaleString()} selected`:"",d.style.display=l?"":"none",a(".sl-sb-undo").textContent=`↩${i.length} ↪${s.length}`;const u=a(".sl-sb-mc");this._extraCursors.length?(u.style.display="",a(".sl-sb-mc-count").textContent=String(this._extraCursors.length+1)):u.style.display="none"}_updateMinimap(){if(!this._config.showMinimap)return;const e=this._minimapWrap.clientWidth,t=this._minimapWrap.clientHeight;if(!e||!t)return;const i=this._tab.doc,s=i.length,n=Math.min(window.devicePixelRatio||1,2),o=this._config.lineHeight,{mmScroll:a,sliderTop:l,sliderHeight:c}=Me(s,this._editorEl.scrollTop,this._editorEl.clientHeight,t,o),d=a/2,u=Math.floor(d),h=Math.ceil(t/2)+2,_=Math.min(s,u+h),y=(_-u)*2,g=(d-u)*2,k=Math.round(e*n),b=Math.round(y*n);(this._mmCanvas.width!==k||this._mmCanvas.height!==b)&&(this._mmCanvas.width=k,this._mmCanvas.height=b,this._mmCanvas.style.width=`${e}px`,this._mmCanvas.style.height=`${y}px`),this._mmCanvas.style.transform=`translateY(${-g}px)`,Si({canvas:this._mmCanvas,doc:i,firstLine:u,lastLine:_,subPx:g,wrapperWidth:e,canvasHeight:y,cursorRow:this._tab.cur.row,sel:this._tab.sel,findMatches:this._findMatches,findIdx:this._findIdx,sliderTop:l,sliderHeight:c,colors:this._mmColors,getCssVar:M=>me(M,this._host),dpr:n}),this._mmSlider.style.top=`${Math.max(0,Math.min(t-c,l))}px`,this._mmSlider.style.height=`${c}px`}_rebuildWrapMap(){let e;if(this._config.wordWrap){const t=this._config.showGutter?this._config.gutterWidth:0,i=this._editorEl.clientWidth;if(i>0){const s=i-t-ie-He;e=Math.max(20,Math.floor(s/Q))}else e=this._config.wrapColumn}else e=9999;this._wm=Ot(this._tab.doc,e,this._config.wordWrap,this._foldedLines)}_scrollIntoView(){const e=this._config.lineHeight;this._spacerEl.style.height=`${this._wm.visualRows.length*e}px`;const t=this._tab.cur,s=ee(this._wm,t.row,t.col).visRow*e,n=s+e,o=this._editorEl.scrollTop,a=this._editorEl.clientHeight,l=e*3;s<o+l?this._editorEl.scrollTop=Math.max(0,s-l):n>o+a-l&&(this._editorEl.scrollTop=n-a+l)}_focusInput(){this._inputEl.style.pointerEvents="auto",this._inputEl.focus(),this._inputEl.style.pointerEvents="none"}_insertStr(e,t){var d,u;const i=Date.now();(!t||i-this._lastInputTime>this._config.undoBatchMs)&&j(this._tab,this._config.maxUndoHistory),this._lastInputTime=i,this._tab.sel&&(this._tab.cur=oe(this._tab));const{doc:s,cur:n}=this._tab,o=e.split(`
543
+ `),a=s[n.row]??"",l=a.slice(0,n.col),c=a.slice(n.col);if(o.length===1)s[n.row]=l+e+c,n.col+=e.length;else{const h=[l+o[0]];for(let _=1;_<o.length-1;_++)h.push(o[_]);h.push(o[o.length-1]+c),s.splice(n.row,1,...h),n.row+=o.length-1,n.col=o[o.length-1].length}this._tokenCache.invalidateLine(n.row,(this._wm.segments[n.row]??[""]).length),this._tab.dirty=!0,(u=(d=this._config).onChange)==null||u.call(d,$(s))}_doBackspace(){var i;if(j(this._tab,this._config.maxUndoHistory),this._tab.sel){this._tab.cur=oe(this._tab),this._tokenCache.clear(),this._tab.dirty=!0;return}const{doc:e,cur:t}=this._tab;if(t.col>0){const s=e[t.row]??"",n=s.slice(0,t.col),o=n.length>=2&&n.endsWith(" ")&&!n.trim()?2:1;e[t.row]=s.slice(0,t.col-o)+s.slice(t.col),t.col-=o,this._tokenCache.invalidateLine(t.row,((i=this._wm.segments[t.row])==null?void 0:i.length)??1)}else if(t.row>0){const s=(e[t.row-1]??"").length;e[t.row-1]+=e[t.row]??"",e.splice(t.row,1),t.row--,t.col=s,this._tokenCache.clear()}this._tab.dirty=!0}_doEnter(){j(this._tab,this._config.maxUndoHistory),this._tab.sel&&(this._tab.cur=oe(this._tab));const{doc:e,cur:t}=this._tab,i=e[t.row]??"",s=i.slice(0,t.col),n=i.slice(t.col),o=et(i),a=s.trimEnd().endsWith("{")?ue(this._config.tabSize):"";e[t.row]=s,s.trimEnd().endsWith("{")&&n.trimStart()==="}"?e.splice(t.row+1,0,o+a,o+n):e.splice(t.row+1,0,o+a+n),t.row++,t.col=o.length+a.length,this._tokenCache.clear(),this._tab.dirty=!0}_doDelete(){var s;if(j(this._tab,this._config.maxUndoHistory),this._tab.sel){this._tab.cur=oe(this._tab),this._tokenCache.clear(),this._tab.dirty=!0;return}const{doc:e,cur:t}=this._tab,i=e[t.row]??"";t.col<i.length?(e[t.row]=i.slice(0,t.col)+i.slice(t.col+1),this._tokenCache.invalidateLine(t.row,((s=this._wm.segments[t.row])==null?void 0:s.length)??1)):t.row<e.length-1&&(e[t.row]=i+(e[t.row+1]??""),e.splice(t.row+1,1),this._tokenCache.clear()),this._tab.dirty=!0}_selectAll(){var i,s,n,o;const e=this._tab.doc,t=e.length-1;this._tab.sel={ar:0,ac:0,fr:t,fc:(e[t]??"").length},this._tab.cur={row:t,col:(e[t]??"").length},this._render(),(s=(i=this._config).onCursorChange)==null||s.call(i,{...this._tab.cur}),(o=(n=this._config).onSelectionChange)==null||o.call(n,this._tab.sel?{...this._tab.sel}:null),this._broadcastCursorToCollab()}_doCopy(){var t;const e=Ue(this._tab);e&&((t=navigator.clipboard)==null||t.writeText(e).catch(()=>{}))}_doCut(){var t,i,s,n,o,a,l;const e=Ue(this._tab);e&&((t=navigator.clipboard)==null||t.writeText(e).catch(()=>{}),j(this._tab,this._config.maxUndoHistory),this._tab.cur=oe(this._tab),this._tokenCache.clear(),this._tab.dirty=!0,this._rebuildWrapMap(),this._render(),(s=(i=this._config).onChange)==null||s.call(i,$(this._tab.doc)),(o=(n=this._config).onCursorChange)==null||o.call(n,{...this._tab.cur}),(l=(a=this._config).onSelectionChange)==null||l.call(a,null),this._broadcastCursorToCollab())}_toggleComment(){var n,o,a,l;j(this._tab,this._config.maxUndoHistory);const e=this._getSelRows(),t=this._config.lineCommentToken||It[this._config.language]||"";if(!t)return;const i=t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),s=e.every(c=>(this._tab.doc[c]??"").trimStart().startsWith(t));e.forEach(c=>{var u;const d=this._tab.doc[c]??"";this._tab.doc[c]=s?d.replace(new RegExp(`^(\\s*)${i}\\s?`),"$1"):d.replace(/^(\s*)/,`$1${t} `),this._tokenCache.invalidateLine(c,((u=this._wm.segments[c])==null?void 0:u.length)??1)}),this._tab.dirty=!0,this._rebuildWrapMap(),this._render(),(o=(n=this._config).onChange)==null||o.call(n,$(this._tab.doc)),(l=(a=this._config).onCursorChange)==null||l.call(a,{...this._tab.cur}),this._broadcastCursorToCollab()}_duplicateLine(){var t,i,s,n;j(this._tab,this._config.maxUndoHistory);const e=this._tab.cur.row;this._tab.doc.splice(e+1,0,this._tab.doc[e]??""),this._tab.cur.row++,this._tokenCache.clear(),this._tab.dirty=!0,this._rebuildWrapMap(),this._render(),(i=(t=this._config).onChange)==null||i.call(t,$(this._tab.doc)),(n=(s=this._config).onCursorChange)==null||n.call(s,{...this._tab.cur}),this._broadcastCursorToCollab()}_deleteLine(){var i,s,n,o;j(this._tab,this._config.maxUndoHistory);const{doc:e,cur:t}=this._tab;e.length>1?e.splice(t.row,1):(e[0]="",t.col=0),this._tokenCache.clear(),this._tab.dirty=!0,A(this._tab),this._rebuildWrapMap(),this._render(),(s=(i=this._config).onChange)==null||s.call(i,$(this._tab.doc)),(o=(n=this._config).onCursorChange)==null||o.call(n,{...this._tab.cur}),this._broadcastCursorToCollab()}_indentSel(){var t,i,s,n;if(!this._tab.sel){this._insertStr(ue(this._config.tabSize),!1);return}j(this._tab,this._config.maxUndoHistory);const e=ue(this._config.tabSize);this._getSelRows().forEach(o=>{var a;this._tab.doc[o]=e+(this._tab.doc[o]??""),this._tokenCache.invalidateLine(o,((a=this._wm.segments[o])==null?void 0:a.length)??1)}),this._tab.dirty=!0,this._rebuildWrapMap(),this._render(),(i=(t=this._config).onChange)==null||i.call(t,$(this._tab.doc)),(n=(s=this._config).onCursorChange)==null||n.call(s,{...this._tab.cur}),this._broadcastCursorToCollab()}_unindentSel(){var t,i,s,n;j(this._tab,this._config.maxUndoHistory);const e=this._config.tabSize;this._getSelRows().forEach(o=>{var l;const a=this._tab.doc[o]??"";a.startsWith(ue(e))?this._tab.doc[o]=a.slice(e):a.startsWith(" ")&&(this._tab.doc[o]=a.slice(1)),this._tokenCache.invalidateLine(o,((l=this._wm.segments[o])==null?void 0:l.length)??1)}),this._tab.dirty=!0,this._rebuildWrapMap(),this._render(),(i=(t=this._config).onChange)==null||i.call(t,$(this._tab.doc)),(n=(s=this._config).onCursorChange)==null||n.call(s,{...this._tab.cur}),this._broadcastCursorToCollab()}_toggleWrap(){this._config.wordWrap=!this._config.wordWrap,this._vpEl.classList.toggle("sl-wrap-mode",this._config.wordWrap);const e=this._statusBar.querySelector(".sl-sb-wrap-btn");e&&(e.textContent=`⇥ Wrap: ${this._config.wordWrap?"ON":"OFF"}`,e.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 e=J(this._tab.sel),t=[];for(let i=e.ar;i<=e.fr;i++)t.push(i);return t}_posFromMouse(e){var c;const t=this._editorEl.getBoundingClientRect(),i=e.clientY-t.top+this._editorEl.scrollTop,s=this._config.showGutter?this._config.gutterWidth:0,n=e.clientX-t.left-s-ie,o=this._config.lineHeight,a=Math.max(0,Math.min(this._wm.visualRows.length-1,Math.floor(i/o))),l=Math.max(0,Math.min((((c=this._wm.visualRows[a])==null?void 0:c.text)??"").length,Math.round(n/Q)));return pe(this._wm,a,l)}_openFind(e){this._findBar.classList.add("sl-open"),this._replaceRow.style.display=e&&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(e){this._findMatches=ai(this._tab.doc,e,{caseSensitive:this._findCaseSensitive,useRegex:this._findRegex})}_navFind(e){if(!this._findMatches.length){this._findCount.textContent="0/0";return}this._findIdx=di(this._findMatches,this._findIdx,e);const t=this._findMatches[this._findIdx];this._tab.cur={row:t.row,col:t.col},this._tab.sel={ar:t.row,ac:t.col,fr:t.row,fc:t.col+t.len},this._scrollIntoView(),this._render(),this._findCount.textContent=`${this._findIdx+1}/${this._findMatches.length}`}_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()},Et)}_acTriggerNow(){if(!this._config.autocomplete){this._acHide();return}const{cur:e,doc:t}=this._tab,i=t[e.row]??"",s=this._config.language==="css",{prefix:n,start:o}=gi(i,e.col,s);this._acPrefix=n,this._acStartCol=o;const a=[];if(this._config.emmet){const c=nt(i,e.col);if(c){const d=st(c.abbr);if(d){this._emmetAcStartCol=c.start;const u=d.replace(/\n/g,"↵ ").slice(0,60);a.push({label:c.abbr,kind:"emmet",detail:u,body:d})}}}const l=n.length>=this._config.autocompletePrefixLength?fi(t,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},e.row,e.col):[];if(this._acItems=[...a,...l],!this._acItems.length){this._acHide();return}this._acSel=0,this._renderAcPopup()}_renderAcPopup(){const e=l=>{switch(l){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"·"}},t=this._acItems[this._acSel];let i="";t!=null&&t.description?i=t.description:(t==null?void 0:t.kind)==="snip"&&t.body?i=t.body.replace(/\$\d/g,"▌"):(t==null?void 0:t.kind)==="emmet"&&t.body&&(i=t.body);const s=this._acItems.map((l,c)=>{const d=c===this._acSel;return`<div class="sl-ac-item${d?" sl-sel":""}" data-i="${c}" role="option" aria-selected="${d}"><span class="sl-ac-badge ${l.kind}">${e(l.kind)}</span><span class="sl-ac-label">${l.label}</span><span class="sl-ac-detail">${l.detail??""}</span></div>`}).join(""),n=i?`<div class="sl-ac-desc"><pre class="sl-ac-desc-body">${i.replace(/</g,"&lt;")}</pre></div>`:"";this._acPopup.innerHTML=`<div class="sl-ac-list">${s}</div>`+n,this._acPopup.style.display="flex",this._posAcPopup();const o=this._acPopup.querySelector(".sl-ac-list"),a=this._acPopup.querySelector(".sl-ac-item.sl-sel");if(o&&a){const l=a.offsetTop,c=l+a.offsetHeight;c>o.scrollTop+o.clientHeight?o.scrollTop=c-o.clientHeight:l<o.scrollTop&&(o.scrollTop=l)}this._acPopup.querySelectorAll(".sl-ac-item").forEach(l=>{l.addEventListener("mousedown",c=>{c.preventDefault(),this._acSel=parseInt(l.dataset.i??"0",10),this._acAccept()})})}_posAcPopup(){const e=this._editorEl.getBoundingClientRect(),t=ee(this._wm,this._tab.cur.row,this._tab.cur.col),i=this._config.showGutter?this._config.gutterWidth:0,s=e.left+i+ie+this._acStartCol*Q,n=e.top+(t.visRow*this._config.lineHeight-this._editorEl.scrollTop)+this._config.lineHeight+2,a=!!this._acPopup.querySelector(".sl-ac-desc")?620:300,l=Math.min(this._acItems.length*28+8,320),c=n+l>window.innerHeight-16;this._acPopup.style.left=`${Math.min(s,window.innerWidth-a-16)}px`,this._acPopup.style.top=`${c?n-this._config.lineHeight-2-l:n}px`}_acAccept(){const e=this._acItems[this._acSel];if(!e)return;if(this._acHide(),e.kind==="emmet"&&e.body){j(this._tab,this._config.maxUndoHistory),this._expandBodyAt(e.body,this._emmetAcStartCol);return}if(e.body){j(this._tab,this._config.maxUndoHistory),this._expandBodyAt(e.body,this._acStartCol);return}const t=e.label.slice(this._acPrefix.length);this._insertStr(t,!1),this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render()}_emmetCheck(){if(this._emmetTip.style.display="none",!this._config.emmet){this._emmetExpanded=null;return}const{cur:e,doc:t}=this._tab,i=t[e.row]??"",s=nt(i,e.col);if(!s){this._emmetExpanded=null;return}const n=st(s.abbr);if(!n){this._emmetExpanded=null;return}this._emmetExpanded={abbr:s.abbr,result:n,start:s.start}}_emmetAccept(){if(!this._emmetExpanded||this._emmetTip.style.display==="none")return!1;const{abbr:e,result:t,start:i}=this._emmetExpanded;return j(this._tab,this._config.maxUndoHistory),this._emmetExpanded=null,this._emmetTip.style.display="none",this._expandBodyAt(t,i),!0}_allCompletions(){return[...this._config.replaceBuiltins?[]:ti(this._config.language),...this._config.completions]}_snippetCheck(){if(this._snippetTip.style.display="none",!this._config.snippetExpansion){this._snippetExpanded=null;return}const{cur:e,doc:t}=this._tab,i=t[e.row]??"",s=ii(i,e.col,this._allCompletions());if(!s){this._snippetExpanded=null;return}this._snippetExpanded={snippet:s.snippet,start:s.start}}_snippetAccept(){if(!this._snippetExpanded||this._snippetTip.style.display==="none")return!1;const{snippet:e,start:t}=this._snippetExpanded;return e.body?(j(this._tab,this._config.maxUndoHistory),this._snippetExpanded=null,this._snippetTip.style.display="none",this._expandBodyAt(e.body,t),!0):!1}_expandBodyAt(e,t){var b,M,m,x,f,I;const{doc:i,cur:s}=this._tab,n=s.row,o=i[s.row]??"",a=o.slice(0,t),l=o.slice(s.col),c=et(o),d=e.split(`
544
+ `).map((T,L)=>L===0?T:c+T),u=d.join(`
545
+ `),h=[],_=/\$(\d+)/g;let y;for(;(y=_.exec(u))!==null;){const T=parseInt(y[1],10),K=u.slice(0,y.index).split(`
546
+ `),N=K.length-1,W=K[N].length,F=(K[N].match(/\$\d+/g)??[]).join("").length,z=n+N,S=(N===0?t:c.length)+(W-F);h.push({n:T,row:z,col:S})}h.sort((T,L)=>T.n===0?1:L.n===0?-1:T.n-L.n);const g=d.map(T=>T.replace(/\$\d+/g,"")),k=g.length===1?[a+g[0]+l]:[a+g[0],...g.slice(1,-1),g[g.length-1]+l];i.splice(s.row,1,...k),h.length>0?(this._snippetSession={stops:h.map(T=>({row:T.row,col:T.col})),idx:0},s.row=h[0].row,s.col=h[0].col):(this._snippetSession=null,s.row+=k.length-1,s.col=(k[k.length-1]??"").length-l.length),this._tokenCache.clear(),this._tab.dirty=!0,this._tab.sel=null,this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render(),(M=(b=this._config).onCursorChange)==null||M.call(b,{...this._tab.cur}),(x=(m=this._config).onSelectionChange)==null||x.call(m,null),this._broadcastCursorToCollab(),(I=(f=this._config).onChange)==null||I.call(f,$(this._tab.doc))}_openThemePicker(){var t;const e=this._themeManager.all;this._themePanel.innerHTML=`
465
547
  <div class="sl-theme-header">
466
548
  <div class="sl-theme-title">Color Theme</div>
467
549
  <div class="sl-theme-close">✕</div>
@@ -483,5 +565,5 @@ gap: $2;`,language:["css"]},{label:"media",kind:"snip",detail:"@media query",des
483
565
  </div>
484
566
  `).join("")}
485
567
  </div>
486
- `,this._themeOverlay.style.display="block",(t=this._themePanel.querySelector(".sl-theme-close"))==null||t.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 r=i.dataset.id??"";this.setTheme(r),this._themePanel.querySelectorAll(".sl-theme-item").forEach(n=>n.classList.remove("sl-active")),i.classList.add("sl-active")})})}_bindEditorEvents(){this._vpEl.addEventListener("mousedown",this._onFoldBtnClick),this._editorEl.addEventListener("mousedown",e=>{if(e.button!==0)return;e.preventDefault(),this._focusInput(),this._acHide(),this._emmetTip.style.display="none",e.altKey||(je(this._mc),this._extraCursors=[]);const t=this._posFromMouse(e);if(this._tab.cur={...t},e.detail===3)this._tab.sel={ar:t.row,ac:0,fr:t.row,fc:(this._tab.doc[t.row]??"").length},this._tab.cur.col=this._tab.sel.fc;else if(e.detail===2&&this._config.wordSelection){const i=this._tab.doc[t.row]??"",r=ne(i,t.col,this._isWordChar.bind(this)),n=se(i,t.col,this._isWordChar.bind(this));r!==n?(this._tab.sel={ar:t.row,ac:r,fr:t.row,fc:n},this._tab.cur.col=n):this._tab.sel=null}else{if(e.altKey&&this._config.multiCursor){Be(this._mc,t.row,t.col,null),this._extraCursors=[...this._mc.cursors],this._render();return}this._tab.sel=null,this._isDragging=!0,this._dragAnchor={...t}}I(this._tab),this._render()}),this._editorEl.addEventListener("mousemove",e=>{if(this._config.hover&&!this._hoverPinned&&!this._isDragging&&this._scheduleHover(e),!this._isDragging||!this._dragAnchor)return;const t=this._posFromMouse(e);this._tab.cur={...t},t.row!==this._dragAnchor.row||t.col!==this._dragAnchor.col?this._tab.sel={ar:this._dragAnchor.row,ac:this._dragAnchor.col,fr:t.row,fc:t.col}:this._tab.sel=null,I(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",e=>this._onKeyDown(e)),this._inputEl.addEventListener("input",e=>this._onInput(e)),this._inputEl.addEventListener("paste",e=>{var i;if(e.preventDefault(),this._config.readOnly)return;const t=(i=e.clipboardData??window.clipboardData)==null?void 0:i.getData("text/plain");t&&(this._insertStr(t,!1),this._tokenCache.clear(),this._rebuildWrapMap(),I(this._tab),this._scrollIntoView(),this._render())}),this._editorEl.addEventListener("mousedown",()=>setTimeout(()=>this._focusInput(),0)),this._inputEl.addEventListener("focus",()=>{var e,t;return(t=(e=this._config).onFocus)==null?void 0:t.call(e)}),this._inputEl.addEventListener("blur",()=>{var e,t;return(t=(e=this._config).onBlur)==null?void 0:t.call(e)})}_onKeyDown(e){var a,l,o,c,d,p,h,g,y;const t=e.ctrlKey||e.metaKey,i=e.shiftKey,r=e.altKey,n=this._config.readOnly;if(this._hideHover(),this._acVisible()){if(e.key==="ArrowDown"){e.preventDefault(),this._acSel=Math.min(this._acItems.length-1,this._acSel+1),this._renderAcPopup();return}if(e.key==="ArrowUp"){e.preventDefault(),this._acSel=Math.max(0,this._acSel-1),this._renderAcPopup();return}if(e.key==="Tab"||e.key==="Enter"){e.preventDefault(),this._acAccept();return}if(e.key==="Escape"){this._acHide();return}}if(r&&(e.key==="z"||e.key==="Z"||e.key==="Ω")){e.preventDefault(),this._toggleWrap();return}if(t&&e.key==="z"&&!i){e.preventDefault(),n||this.undo();return}if(t&&(e.key==="y"||i&&e.key==="z")){e.preventDefault(),n||this.redo();return}if(t&&e.key==="a"){e.preventDefault(),this._selectAll();return}if(t&&e.key==="c"){e.preventDefault(),this._doCopy();return}if(t&&e.key==="x"){e.preventDefault(),n||this._doCut();return}if(t&&e.key==="f"){e.preventDefault(),this._config.find&&this._openFind(!1);return}if(t&&e.key==="h"){e.preventDefault(),this._config.find&&this._config.findReplace&&this._openFind(!0);return}if(t&&e.key==="d"){e.preventDefault(),!n&&this._config.multiCursor&&this._ctrlD();return}if(t&&i&&e.key==="d"){e.preventDefault(),n||this._duplicateLine();return}if(t&&e.key==="/"){e.preventDefault(),n||this._toggleComment();return}if(t&&e.key==="k"){e.preventDefault(),n||this._deleteLine();return}if(e.key==="Escape"){this._tab.sel=null,this._acHide(),this._closeFind(),this._emmetTip.style.display="none",this._snippetTip.style.display="none",this._snippetExpanded=null,je(this._mc),this._extraCursors=[],this._mc.searchWord="",this._render();return}if(n){this._handleArrowKeys(e,t,i);return}if(e.key==="Tab"){if(e.preventDefault(),!i&&this._emmetAccept()||!i&&this._snippetAccept())return;i?this._unindentSel():this._indentSel(),I(this._tab),this._scrollIntoView(),this._rebuildWrapMap(),this._render();return}if(e.key==="Backspace"){if(e.preventDefault(),this._extraCursors.length){const v=_t(this._tab.doc,this._tab.cur.row,this._tab.cur.col,this._extraCursors);this._tab.doc=v.doc,this._tab.cur.row=v.primaryRow,this._tab.cur.col=v.primaryCol,this._extraCursors=v.extraCursors,this._mc.cursors=v.extraCursors}else this._doBackspace();this._tokenCache.clear(),this._rebuildWrapMap(),I(this._tab),this._scrollIntoView(),this._render(),this._acTrigger(),this._emmetCheck(),this._snippetCheck(),(l=(a=this._config).onChange)==null||l.call(a,L(this._tab.doc));return}if(e.key==="Delete"){e.preventDefault(),this._doDelete(),this._tokenCache.clear(),this._rebuildWrapMap(),I(this._tab),this._scrollIntoView(),this._render(),(c=(o=this._config).onChange)==null||c.call(o,L(this._tab.doc));return}if(e.key==="Enter"){e.preventDefault(),this._doEnter(),this._tokenCache.clear(),this._rebuildWrapMap(),I(this._tab),this._scrollIntoView(),this._render(),(p=(d=this._config).onChange)==null||p.call(d,L(this._tab.doc));return}if(!t&&!r&&this._config.autoClosePairs[e.key]){e.preventDefault(),S(this._tab,this._config.maxUndoHistory),this._tab.sel&&(this._tab.cur=U(this._tab));const{doc:v,cur:f}=this._tab,b=v[f.row]??"";v[f.row]=b.slice(0,f.col)+e.key+this._config.autoClosePairs[e.key]+b.slice(f.col),f.col++,this._tokenCache.invalidateLine(f.row,((h=this._wm.segments[f.row])==null?void 0:h.length)??1),this._tab.dirty=!0,this._rebuildWrapMap(),I(this._tab),this._scrollIntoView(),this._render(),(y=(g=this._config).onChange)==null||y.call(g,L(this._tab.doc));return}if(!t&&!r&&Object.values(this._config.autoClosePairs).includes(e.key)){const{doc:v,cur:f}=this._tab;if((v[f.row]??"")[f.col]===e.key){e.preventDefault(),f.col++,I(this._tab),this._scrollIntoView(),this._render();return}}if(r&&!t&&(e.key==="ArrowUp"||e.key==="ArrowDown")){e.preventDefault(),this._moveLines(e.key==="ArrowUp");return}this._handleArrowKeys(e,t,i)}_handleArrowKeys(e,t,i){var g,y,v,f,b,T;const{doc:r,cur:n}=this._tab,a=this._config.lineHeight,l=e.metaKey,o=e.ctrlKey,c=e.altKey,d=(_,x)=>{if(i){this._tab.sel||(this._tab.sel={ar:n.row,ac:n.col,fr:n.row,fc:n.col}),n.row=_,n.col=x;const m=this._tab.sel;m.fr=_,m.fc=x,m.ar===m.fr&&m.ac===m.fc&&(this._tab.sel=null)}else this._tab.sel=null,n.row=_,n.col=x},p=_=>{const m=(r[_]??"").search(/\S/);return m===-1||n.col===m?0:m},h=()=>({row:r.length-1,col:(r[r.length-1]??"").length});switch(e.key){case"ArrowRight":if(e.preventDefault(),this._tab.sel&&!i){const _=$(this._tab.sel);n.row=_.fr,n.col=_.fc,this._tab.sel=null;break}if(l)d(n.row,(r[n.row]??"").length);else if(o||c){const _=this._wordSkipRight(r[n.row]??"",n.col);d(n.row,_)}else n.col<(r[n.row]??"").length?d(n.row,n.col+1):n.row<r.length-1&&d(n.row+1,0);break;case"ArrowLeft":if(e.preventDefault(),this._tab.sel&&!i){const _=$(this._tab.sel);n.row=_.ar,n.col=_.ac,this._tab.sel=null;break}if(l)d(n.row,p(n.row));else if(o||c){const _=this._wordSkipLeft(r[n.row]??"",n.col);d(n.row,_)}else n.col>0?d(n.row,n.col-1):n.row>0&&d(n.row-1,(r[n.row-1]??"").length);break;case"ArrowDown":if(e.preventDefault(),l){const _=h();d(_.row,_.col)}else if(this._config.wordWrap){const _=G(this._wm,n.row,n.col),x=Math.min(this._wm.visualRows.length-1,_.visRow+1),m=X(this._wm,x,Math.min(_.colInSeg,(((g=this._wm.visualRows[x])==null?void 0:g.text)??"").length));d(m.row,m.col)}else{const _=Math.min(r.length-1,n.row+1);d(_,Math.min(n.col,(r[_]??"").length))}break;case"ArrowUp":if(e.preventDefault(),l)d(0,0);else if(this._config.wordWrap){const _=G(this._wm,n.row,n.col),x=Math.max(0,_.visRow-1),m=X(this._wm,x,Math.min(_.colInSeg,(((y=this._wm.visualRows[x])==null?void 0:y.text)??"").length));d(m.row,m.col)}else{const _=Math.max(0,n.row-1);d(_,Math.min(n.col,(r[_]??"").length))}break;case"Home":e.preventDefault(),o?d(0,0):d(n.row,p(n.row));break;case"End":if(e.preventDefault(),o){const _=h();d(_.row,_.col)}else d(n.row,(r[n.row]??"").length);break;case"PageDown":e.preventDefault();{const _=Math.max(1,Math.floor(this._editorEl.clientHeight/a)-1),x=Math.min(r.length-1,n.row+_);d(x,Math.min(n.col,(r[x]??"").length)),this._editorEl.scrollTop+=this._editorEl.clientHeight-a;break}case"PageUp":e.preventDefault();{const _=Math.max(1,Math.floor(this._editorEl.clientHeight/a)-1),x=Math.max(0,n.row-_);d(x,Math.min(n.col,(r[x]??"").length)),this._editorEl.scrollTop-=this._editorEl.clientHeight-a;break}default:return}I(this._tab),this._scrollIntoView(),this._acHide(),(f=(v=this._config).onCursorChange)==null||f.call(v,{...this._tab.cur}),(T=(b=this._config).onSelectionChange)==null||T.call(b,this._tab.sel?{...this._tab.sel}:null),this._render()}_isWordChar(e){const t=this._config.wordSeparators;return t?e.trim()!==""&&!t.includes(e):/[\w$]/.test(e)}_wordSkipRight(e,t){let i=t;for(;i<e.length&&/\s/.test(e[i]);)i++;for(;i<e.length&&/\S/.test(e[i]);)i++;return i}_wordSkipLeft(e,t){let i=t;for(;i>0&&/\s/.test(e[i-1]);)i--;for(;i>0&&/\S/.test(e[i-1]);)i--;return i}_moveLines(e){var l,o,c,d;const{doc:t,cur:i}=this._tab,r=this._tab.sel;let n=i.row,a=i.row;if(r){const p=$(r);n=p.ar,a=p.fr,p.fc===0&&p.fr>p.ar&&a--}if(e){if(n===0)return;S(this._tab,this._config.maxUndoHistory);const p=t.splice(n,a-n+1);t.splice(n-1,0,...p),i.row--,r&&(r.ar--,r.fr--)}else{if(a>=t.length-1)return;S(this._tab,this._config.maxUndoHistory);const p=t.splice(n,a-n+1);t.splice(n+1,0,...p),i.row++,r&&(r.ar++,r.fr++)}this._tab.dirty=!0,this._tokenCache.clear(),this._rebuildWrapMap(),I(this._tab),this._scrollIntoView(),this._render(),(o=(l=this._config).onChange)==null||o.call(l,L(this._tab.doc)),(d=(c=this._config).onCursorChange)==null||d.call(c,{...this._tab.cur})}_scheduleHover(e){this._hoverTip.style.display!=="none"&&(this._hoverTip.style.display="none"),this._hoverTimer!==null&&(clearTimeout(this._hoverTimer),this._hoverTimer=null);const{clientX:t,clientY:i}=e;this._hoverTimer=setTimeout(()=>{this._hoverTimer=null,this._doHover(t,i)},500)}_doHover(e,t){var y,v,f;if(!this._config.hover)return;const i=this._editorEl.getBoundingClientRect(),r=t-i.top+this._editorEl.scrollTop,n=this._config.showGutter?this._config.gutterWidth:0,a=e-i.left-n-14,l=this._config.lineHeight,o=Math.max(0,Math.min(this._wm.visualRows.length-1,Math.floor(r/l))),c=Math.max(0,Math.min((((y=this._wm.visualRows[o])==null?void 0:y.text)??"").length,Math.round(a/7.82))),d=X(this._wm,o,c),p=this._tab.doc[d.row]??"",h=It(p,d.col);if(!h)return;let g=Lt(h,this._config.language);if(!g){const b=this._config.completions.find(T=>T.label===h);b&&(b.description||b.detail)&&(g={title:b.label,type:b.detail,body:b.description??""})}if(!g){const b=(f=(v=this._config).provideHover)==null?void 0:f.call(v,{word:h,row:d.row,col:d.col,line:p,language:this._config.language,doc:this._tab.doc});b&&(g=b)}g&&this._showHoverTip(g,e,t)}_showHoverTip(e,t,i){const r=this._hoverTip;let n='<div class="sl-ht-sig">';n+=`<span class="sl-ht-title">${K(e.title)}</span>`,e.type&&(n+=`<code class="sl-ht-type">${K(e.type)}</code>`),n+="</div>",e.title&&e.body&&(n+='<div class="sl-ht-divider"></div>'),e.body&&(n+=`<div class="sl-ht-body">${K(e.body)}</div>`),r.innerHTML=n,r.style.display="block";const a=12,l=18,o=r.offsetWidth||300,c=r.offsetHeight||80;let d=t,p=i+l;p+c>window.innerHeight-a&&(p=i-c-8),d+o>window.innerWidth-a&&(d=window.innerWidth-o-a),d<a&&(d=a),r.style.left=`${d}px`,r.style.top=`${Math.max(a,p)}px`}_hideHover(){this._hoverTimer!==null&&(clearTimeout(this._hoverTimer),this._hoverTimer=null),this._hoverPinned=!1,this._hoverTip.style.display="none"}_onInput(e){var n,a,l,o;if(this._config.readOnly){e.target.value="";return}const t=e.target,i=t.value;if(t.value="",!i||i==="Ω")return;const r=i.replace(/[\x00-\x08\x0a-\x1f\x7f]/g,"");if(r){if(this._extraCursors.length){const c=mt(this._tab.doc,this._tab.cur.row,this._tab.cur.col,this._extraCursors,r);this._tab.doc=c.doc,this._tab.cur.row=c.primaryRow,this._tab.cur.col=c.primaryCol,this._extraCursors=c.extraCursors,this._mc.cursors=c.extraCursors,this._tab.dirty=!0,(a=(n=this._config).onChange)==null||a.call(n,L(this._tab.doc))}else this._insertStr(r,!0);this._tokenCache.clear(),this._rebuildWrapMap(),I(this._tab),this._scrollIntoView(),this._render(),this._acTrigger(),this._emmetCheck(),this._snippetCheck(),(o=(l=this._config).onCursorChange)==null||o.call(l,{...this._tab.cur})}}_ctrlD(){if(!this._config.multiCursor)return;const e=yt(this._mc,this._tab.doc,this._tab.cur.row,this._tab.cur.col,this._tab.sel);e&&(!this._mc.cursors.length||e.word!==this._mc.searchWord?(this._tab.sel=e.sel,this._tab.cur.col=e.col):(Be(this._mc,e.row,e.col,e.sel),this._extraCursors=[...this._mc.cursors]),this._mc.searchWord=e.word,this._mc.lastMatchRow=e.row,this._mc.lastMatchCol=e.col,this._scrollIntoView(),this._render())}_bindFindEvents(){var e,t,i,r,n,a,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",o=>{o.key==="Enter"?o.shiftKey?this._navFind(-1):this._navFind(1):o.key==="Escape"&&this._closeFind(),o.stopPropagation()}),this._replaceInput.addEventListener("keydown",o=>{o.key==="Enter"?this._doReplaceOne():o.key==="Escape"&&this._closeFind(),o.stopPropagation()}),(e=this._findBar.querySelector(".sl-find-prev"))==null||e.addEventListener("click",()=>this._navFind(-1)),(t=this._findBar.querySelector(".sl-find-next"))==null||t.addEventListener("click",()=>this._navFind(1)),(i=this._findBar.querySelector(".sl-find-close"))==null||i.addEventListener("click",()=>this._closeFind()),(r=this._findBar.querySelector(".sl-find-case"))==null||r.addEventListener("click",o=>{this._findCaseSensitive=!this._findCaseSensitive,o.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",o=>{this._findRegex=!this._findRegex,o.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())}),(a=this._findBar.querySelector(".sl-replace-one"))==null||a.addEventListener("click",()=>this._doReplaceOne()),(l=this._findBar.querySelector(".sl-replace-all"))==null||l.addEventListener("click",()=>this._doReplaceAll())}_doReplaceOne(){var e,t;this._findIdx<0||!this._findMatches.length||(S(this._tab,this._config.maxUndoHistory),this._tab.doc=wt(this._tab.doc,this._findMatches,this._findIdx,this._replaceInput.value),this._tokenCache.clear(),this._tab.dirty=!0,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()),(t=(e=this._config).onChange)==null||t.call(e,L(this._tab.doc)))}_doReplaceAll(){var t,i;if(!this._findMatches.length)return;const e=this._findMatches.length;S(this._tab,this._config.maxUndoHistory),this._tab.doc=kt(this._tab.doc,this._findMatches,this._replaceInput.value),this._tokenCache.clear(),this._tab.dirty=!0,this._findMatches=[],this._findIdx=-1,this._findCount.textContent=`0/0 (${e} replaced)`,this._rebuildWrapMap(),this._render(),(i=(t=this._config).onChange)==null||i.call(t,L(this._tab.doc))}_bindMinimapEvents(){const e=this._minimapWrap;e.addEventListener("mousemove",t=>{if(this._mmDragMode!=="none")return;const i=t.clientY-e.getBoundingClientRect().top,{sliderTop:r,sliderHeight:n}=pe(this._tab.doc.length,this._editorEl.scrollTop,this._editorEl.clientHeight,e.clientHeight,this._config.lineHeight);e.style.cursor=i>=r&&i<=r+n?"grab":"pointer"}),e.addEventListener("mousedown",t=>{t.preventDefault();const i=e.clientHeight,r=t.clientY-e.getBoundingClientRect().top,{sliderTop:n,sliderHeight:a}=pe(this._tab.doc.length,this._editorEl.scrollTop,this._editorEl.clientHeight,i,this._config.lineHeight);if(r>=n&&r<=n+a)this._mmDragMode="slider",this._mmSliderOffset=r-n,this._mmDragStartY=t.clientY,this._mmDragStartScroll=this._editorEl.scrollTop,e.style.cursor="grabbing";else{this._mmDragMode="jump";const l=$t(r,this._tab.doc.length,this._editorEl.scrollTop,this._editorEl.clientHeight,i,this._config.lineHeight);this._editorEl.scrollTop=l,this._mmDragStartY=t.clientY,this._mmDragStartScroll=l,this._render()}}),window.addEventListener("mousemove",this._onWinMmMouseMove),window.addEventListener("mouseup",this._onWinMmMouseUp)}}function Ot(s,e){return new Ne(s,e)}E.BUILT_IN_THEMES=Ee,E.SynclineEditor=Ne,E.THEME_DRACULA=Te,E.THEME_GITHUB_LIGHT=Me,E.THEME_MONOKAI=xe,E.THEME_SOLARIZED_LIGHT=Ce,E.THEME_VR_DARK=we,E.THEME_VSCODE_DARK=ke,E.createEditor=Ot,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
568
+ `,this._themeOverlay.style.display="block",(t=this._themePanel.querySelector(".sl-theme-close"))==null||t.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 s=i.dataset.id??"";this.setTheme(s),this._themePanel.querySelectorAll(".sl-theme-item").forEach(n=>n.classList.remove("sl-active")),i.classList.add("sl-active")})})}_bindEditorEvents(){this._vpEl.addEventListener("mousedown",this._onFoldBtnClick),this._editorEl.addEventListener("mousedown",e=>{var i,s,n,o;if(e.button!==0)return;e.preventDefault(),this._focusInput(),this._acHide(),this._snippetSession=null,this._emmetTip.style.display="none",e.altKey||(ot(this._mc),this._extraCursors=[]);const t=this._posFromMouse(e);if(this._tab.cur={...t},e.detail===3)this._tab.sel={ar:t.row,ac:0,fr:t.row,fc:(this._tab.doc[t.row]??"").length},this._tab.cur.col=this._tab.sel.fc;else if(e.detail===2&&this._config.wordSelection){const a=this._tab.doc[t.row]??"",l=ye(a,t.col,this._isWordChar.bind(this)),c=ve(a,t.col,this._isWordChar.bind(this));l!==c?(this._tab.sel={ar:t.row,ac:l,fr:t.row,fc:c},this._tab.cur.col=c):this._tab.sel=null}else{if(e.altKey&&this._config.multiCursor){rt(this._mc,t.row,t.col,null),this._extraCursors=[...this._mc.cursors],this._render();return}this._tab.sel=null,this._isDragging=!0,this._dragAnchor={...t}}A(this._tab),this._render(),(s=(i=this._config).onCursorChange)==null||s.call(i,{...this._tab.cur}),(o=(n=this._config).onSelectionChange)==null||o.call(n,this._tab.sel?{...this._tab.sel}:null),this._broadcastCursorToCollab()}),this._editorEl.addEventListener("mousemove",e=>{if(this._config.hover&&!this._hoverPinned&&!this._isDragging&&this._scheduleHover(e),!this._isDragging||!this._dragAnchor)return;const t=this._posFromMouse(e);this._tab.cur={...t},t.row!==this._dragAnchor.row||t.col!==this._dragAnchor.col?this._tab.sel={ar:this._dragAnchor.row,ac:this._dragAnchor.col,fr:t.row,fc:t.col}:this._tab.sel=null,A(this._tab),this._render(),this._broadcastCursorToCollab()}),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",e=>this._onKeyDown(e)),this._inputEl.addEventListener("input",e=>this._onInput(e)),this._inputEl.addEventListener("paste",e=>{var i;if(e.preventDefault(),this._config.readOnly)return;const t=(i=e.clipboardData??window.clipboardData)==null?void 0:i.getData("text/plain");t&&(this._insertStr(t,!1),this._tokenCache.clear(),this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render())}),this._editorEl.addEventListener("mousedown",()=>setTimeout(()=>this._focusInput(),0)),this._inputEl.addEventListener("focus",()=>{var e,t;return(t=(e=this._config).onFocus)==null?void 0:t.call(e)}),this._inputEl.addEventListener("blur",()=>{var e,t;return(t=(e=this._config).onBlur)==null?void 0:t.call(e)})}_onKeyDown(e){var o,a,l,c,d,u,h,_,y,g,k,b,M,m,x,f,I,T,L,K,N,W,F,z,S,ne,R,q,X,Z,v,w,E,B,G,te,ut,ft,gt,bt,_t,mt,yt;const t=e.ctrlKey||e.metaKey,i=e.shiftKey,s=e.altKey,n=this._config.readOnly;if(this._hideHover(),this._acVisible()){if(e.key==="ArrowDown"){e.preventDefault(),this._acSel=Math.min(this._acItems.length-1,this._acSel+1),this._renderAcPopup();return}if(e.key==="ArrowUp"){e.preventDefault(),this._acSel=Math.max(0,this._acSel-1),this._renderAcPopup();return}if(e.key==="Tab"||e.key==="Enter"){e.preventDefault(),this._acAccept();return}if(e.key==="Escape"){this._acHide();return}}if(s&&(e.key==="z"||e.key==="Z"||e.key==="Ω")){e.preventDefault(),this._toggleWrap();return}if(t&&e.key==="z"&&!i){e.preventDefault(),n||this.undo();return}if(t&&(e.key==="y"||i&&e.key==="z")){e.preventDefault(),n||this.redo();return}if(t&&e.key==="a"){e.preventDefault(),this._selectAll();return}if(t&&e.key==="c"){e.preventDefault(),this._doCopy();return}if(t&&e.key==="x"){e.preventDefault(),n||this._doCut();return}if(t&&e.key==="f"){e.preventDefault(),this._config.find&&this._openFind(!1);return}if(t&&e.key==="h"){e.preventDefault(),this._config.find&&this._config.findReplace&&this._openFind(!0);return}if(t&&e.key==="g"){e.preventDefault(),this._config.goToLine&&this._openGoToLine();return}if(t&&e.key==="d"){e.preventDefault(),!n&&this._config.multiCursor&&this._ctrlD();return}if(t&&i&&e.key==="d"){e.preventDefault(),n||this._duplicateLine();return}if(t&&e.key==="/"){e.preventDefault(),n||this._toggleComment();return}if(t&&e.key==="k"){e.preventDefault(),n||this._deleteLine();return}if(e.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,ot(this._mc),this._extraCursors=[],this._mc.searchWord="",this._render(),(a=(o=this._config).onCursorChange)==null||a.call(o,{...this._tab.cur}),(c=(l=this._config).onSelectionChange)==null||c.call(l,null),this._broadcastCursorToCollab();return}if(n){this._handleArrowKeys(e,t,i);return}if(e.key==="Tab"){if(e.preventDefault(),this._snippetSession){if(i){if(this._snippetSession.idx>0){this._snippetSession.idx--;const P=this._snippetSession.stops[this._snippetSession.idx];this._tab.cur.row=P.row,this._tab.cur.col=P.col,this._tab.sel=null,A(this._tab),this._scrollIntoView(),this._render(),(u=(d=this._config).onCursorChange)==null||u.call(d,{...this._tab.cur}),(_=(h=this._config).onSelectionChange)==null||_.call(h,null),this._broadcastCursorToCollab()}}else if(this._snippetSession.idx++,this._snippetSession.idx>=this._snippetSession.stops.length)this._snippetSession=null;else{const P=this._snippetSession.stops[this._snippetSession.idx];this._tab.cur.row=P.row,this._tab.cur.col=P.col,this._tab.sel=null,A(this._tab),this._scrollIntoView(),this._render(),(g=(y=this._config).onCursorChange)==null||g.call(y,{...this._tab.cur}),(b=(k=this._config).onSelectionChange)==null||b.call(k,null),this._broadcastCursorToCollab()}return}if(!i&&this._emmetAccept()||!i&&this._snippetAccept())return;i?this._unindentSel():this._indentSel(),A(this._tab),this._scrollIntoView(),this._rebuildWrapMap(),this._render(),(m=(M=this._config).onCursorChange)==null||m.call(M,{...this._tab.cur}),(f=(x=this._config).onSelectionChange)==null||f.call(x,this._tab.sel?{...this._tab.sel}:null),this._broadcastCursorToCollab();return}if(e.key==="Backspace"){if(e.preventDefault(),this._extraCursors.length){this._snippetSession=null;const P=ri(this._tab.doc,this._tab.cur.row,this._tab.cur.col,this._extraCursors);this._tab.doc=P.doc,this._tab.cur.row=P.primaryRow,this._tab.cur.col=P.primaryCol,this._extraCursors=P.extraCursors,this._mc.cursors=P.extraCursors}else{if(this._snippetSession){const P=this._snippetSession.stops[this._snippetSession.idx];if(this._tab.cur.row===P.row&&this._tab.cur.col>P.col){for(let U=this._snippetSession.idx+1;U<this._snippetSession.stops.length;U++){const re=this._snippetSession.stops[U];re.row===P.row&&re.col>=this._tab.cur.col&&re.col--}P.col--}else this._snippetSession=null}this._doBackspace()}this._tokenCache.clear(),this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render(),this._acTrigger(),this._emmetCheck(),this._snippetCheck(),(T=(I=this._config).onChange)==null||T.call(I,$(this._tab.doc)),(K=(L=this._config).onCursorChange)==null||K.call(L,{...this._tab.cur}),(W=(N=this._config).onSelectionChange)==null||W.call(N,this._tab.sel?{...this._tab.sel}:null),this._broadcastCursorToCollab();return}if(e.key==="Delete"){e.preventDefault(),this._snippetSession=null,this._doDelete(),this._tokenCache.clear(),this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render(),(z=(F=this._config).onChange)==null||z.call(F,$(this._tab.doc)),(ne=(S=this._config).onCursorChange)==null||ne.call(S,{...this._tab.cur}),(q=(R=this._config).onSelectionChange)==null||q.call(R,this._tab.sel?{...this._tab.sel}:null),this._broadcastCursorToCollab();return}if(e.key==="Enter"){e.preventDefault(),this._snippetSession=null,this._doEnter(),this._tokenCache.clear(),this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render(),(Z=(X=this._config).onChange)==null||Z.call(X,$(this._tab.doc)),(w=(v=this._config).onCursorChange)==null||w.call(v,{...this._tab.cur}),(B=(E=this._config).onSelectionChange)==null||B.call(E,this._tab.sel?{...this._tab.sel}:null),this._broadcastCursorToCollab();return}if(!t&&!s&&this._config.autoClosePairs[e.key]){e.preventDefault(),j(this._tab,this._config.maxUndoHistory),this._tab.sel&&(this._tab.cur=oe(this._tab));const{doc:P,cur:U}=this._tab,re=P[U.row]??"";P[U.row]=re.slice(0,U.col)+e.key+this._config.autoClosePairs[e.key]+re.slice(U.col),U.col++,this._tokenCache.invalidateLine(U.row,((G=this._wm.segments[U.row])==null?void 0:G.length)??1),this._tab.dirty=!0,this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render(),(ut=(te=this._config).onChange)==null||ut.call(te,$(this._tab.doc)),(gt=(ft=this._config).onCursorChange)==null||gt.call(ft,{...this._tab.cur}),(_t=(bt=this._config).onSelectionChange)==null||_t.call(bt,null),this._broadcastCursorToCollab();return}if(!t&&!s&&Object.values(this._config.autoClosePairs).includes(e.key)){const{doc:P,cur:U}=this._tab;if((P[U.row]??"")[U.col]===e.key){e.preventDefault(),U.col++,A(this._tab),this._scrollIntoView(),this._render(),(yt=(mt=this._config).onCursorChange)==null||yt.call(mt,{...this._tab.cur}),this._broadcastCursorToCollab();return}}if(i&&s&&!t&&(e.key==="ArrowUp"||e.key==="ArrowDown")){e.preventDefault(),this._duplicateLines(e.key==="ArrowDown");return}if(s&&!t&&(e.key==="ArrowUp"||e.key==="ArrowDown")){e.preventDefault(),this._moveLines(e.key==="ArrowUp");return}this._handleArrowKeys(e,t,i)}_handleArrowKeys(e,t,i){var _,y,g,k,b,M;const{doc:s,cur:n}=this._tab,o=this._config.lineHeight,a=e.metaKey,l=e.ctrlKey,c=e.altKey,d=(m,x)=>{if(i){this._tab.sel||(this._tab.sel={ar:n.row,ac:n.col,fr:n.row,fc:n.col}),n.row=m,n.col=x;const f=this._tab.sel;f.fr=m,f.fc=x,f.ar===f.fr&&f.ac===f.fc&&(this._tab.sel=null)}else this._tab.sel=null,n.row=m,n.col=x},u=m=>{const f=(s[m]??"").search(/\S/);return f===-1||n.col===f?0:f},h=()=>({row:s.length-1,col:(s[s.length-1]??"").length});switch(e.key){case"ArrowRight":if(e.preventDefault(),this._tab.sel&&!i){const m=J(this._tab.sel);n.row=m.fr,n.col=m.fc,this._tab.sel=null;break}if(a)d(n.row,(s[n.row]??"").length);else if(l||c){const m=s[n.row]??"";if(n.col>=m.length)n.row<s.length-1&&d(n.row+1,0);else{const x=this._wordSkipRight(m,n.col);d(n.row,x)}}else n.col<(s[n.row]??"").length?d(n.row,n.col+1):n.row<s.length-1&&d(n.row+1,0);break;case"ArrowLeft":if(e.preventDefault(),this._tab.sel&&!i){const m=J(this._tab.sel);n.row=m.ar,n.col=m.ac,this._tab.sel=null;break}if(a)d(n.row,u(n.row));else if(l||c)if(n.col===0)n.row>0&&d(n.row-1,(s[n.row-1]??"").length);else{const m=this._wordSkipLeft(s[n.row]??"",n.col);d(n.row,m)}else n.col>0?d(n.row,n.col-1):n.row>0&&d(n.row-1,(s[n.row-1]??"").length);break;case"ArrowDown":if(e.preventDefault(),a){const m=h();d(m.row,m.col)}else if(this._config.wordWrap){const m=ee(this._wm,n.row,n.col),x=Math.min(this._wm.visualRows.length-1,m.visRow+1),f=pe(this._wm,x,Math.min(m.colInSeg,(((_=this._wm.visualRows[x])==null?void 0:_.text)??"").length));d(f.row,f.col)}else{const m=Math.min(s.length-1,n.row+1);d(m,Math.min(n.col,(s[m]??"").length))}break;case"ArrowUp":if(e.preventDefault(),a)d(0,0);else if(this._config.wordWrap){const m=ee(this._wm,n.row,n.col),x=Math.max(0,m.visRow-1),f=pe(this._wm,x,Math.min(m.colInSeg,(((y=this._wm.visualRows[x])==null?void 0:y.text)??"").length));d(f.row,f.col)}else{const m=Math.max(0,n.row-1);d(m,Math.min(n.col,(s[m]??"").length))}break;case"Home":e.preventDefault(),l?d(0,0):d(n.row,u(n.row));break;case"End":if(e.preventDefault(),l){const m=h();d(m.row,m.col)}else d(n.row,(s[n.row]??"").length);break;case"PageDown":e.preventDefault();{const m=Math.max(1,Math.floor(this._editorEl.clientHeight/o)-1),x=Math.min(s.length-1,n.row+m);d(x,Math.min(n.col,(s[x]??"").length)),this._editorEl.scrollTop+=this._editorEl.clientHeight-o;break}case"PageUp":e.preventDefault();{const m=Math.max(1,Math.floor(this._editorEl.clientHeight/o)-1),x=Math.max(0,n.row-m);d(x,Math.min(n.col,(s[x]??"").length)),this._editorEl.scrollTop-=this._editorEl.clientHeight-o;break}default:return}A(this._tab),this._scrollIntoView(),this._acHide(),(k=(g=this._config).onCursorChange)==null||k.call(g,{...this._tab.cur}),(M=(b=this._config).onSelectionChange)==null||M.call(b,this._tab.sel?{...this._tab.sel}:null),this._broadcastCursorToCollab(),this._render()}_isWordChar(e){const t=this._config.wordSeparators;return t?e.trim()!==""&&!t.includes(e):/[\w$]/.test(e)}_wordSkipRight(e,t){let i=t;const s=e.length;for(;i<s&&/\s/.test(e[i]);)i++;if(i>=s)return i;if(/\w/.test(e[i]))for(;i<s&&/\w/.test(e[i]);)i++;else for(;i<s&&/[^\w\s]/.test(e[i]);)i++;return i}_wordSkipLeft(e,t){let i=t;for(;i>0&&/\s/.test(e[i-1]);)i--;if(i<=0)return i;if(/\w/.test(e[i-1]))for(;i>0&&/\w/.test(e[i-1]);)i--;else for(;i>0&&/[^\w\s]/.test(e[i-1]);)i--;return i}_duplicateLines(e){var l,c,d,u;const{doc:t,cur:i}=this._tab,s=this._tab.sel;let n=i.row,o=i.row;if(s){const h=J(s);n=h.ar,o=h.fr,h.fc===0&&h.fr>h.ar&&o--}j(this._tab,this._config.maxUndoHistory);const a=t.slice(n,o+1);e?(t.splice(o+1,0,...a),i.row+=a.length,s&&(s.ar+=a.length,s.fr+=a.length)):t.splice(n,0,...a),this._tab.dirty=!0,this._tokenCache.clear(),this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render(),(c=(l=this._config).onChange)==null||c.call(l,$(this._tab.doc)),(u=(d=this._config).onCursorChange)==null||u.call(d,{...this._tab.cur}),this._broadcastCursorToCollab()}_moveLines(e){var a,l,c,d;const{doc:t,cur:i}=this._tab,s=this._tab.sel;let n=i.row,o=i.row;if(s){const u=J(s);n=u.ar,o=u.fr,u.fc===0&&u.fr>u.ar&&o--}if(e){if(n===0)return;j(this._tab,this._config.maxUndoHistory);const u=t.splice(n,o-n+1);t.splice(n-1,0,...u),i.row--,s&&(s.ar--,s.fr--)}else{if(o>=t.length-1)return;j(this._tab,this._config.maxUndoHistory);const u=t.splice(n,o-n+1);t.splice(n+1,0,...u),i.row++,s&&(s.ar++,s.fr++)}this._tab.dirty=!0,this._tokenCache.clear(),this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render(),(l=(a=this._config).onChange)==null||l.call(a,$(this._tab.doc)),(d=(c=this._config).onCursorChange)==null||d.call(c,{...this._tab.cur}),this._broadcastCursorToCollab()}_scheduleHover(e){this._hoverTip.style.display!=="none"&&(this._hoverTip.style.display="none"),this._hoverTimer!==null&&(clearTimeout(this._hoverTimer),this._hoverTimer=null);const{clientX:t,clientY:i}=e;this._hoverTimer=setTimeout(()=>{this._hoverTimer=null,this._doHover(t,i)},500)}_doHover(e,t){var y,g,k;if(!this._config.hover)return;const i=this._editorEl.getBoundingClientRect(),s=t-i.top+this._editorEl.scrollTop,n=this._config.showGutter?this._config.gutterWidth:0,o=e-i.left-n-ie,a=this._config.lineHeight,l=Math.max(0,Math.min(this._wm.visualRows.length-1,Math.floor(s/a))),c=Math.max(0,Math.min((((y=this._wm.visualRows[l])==null?void 0:y.text)??"").length,Math.round(o/Q))),d=pe(this._wm,l,c),u=this._tab.doc[d.row]??"",h=bi(u,d.col);if(!h)return;let _=mi(h,this._config.language);if(!_){const b=this._config.completions.find(M=>M.label===h);b&&(b.description||b.detail)&&(_={title:b.label,type:b.detail,body:b.description??""})}if(!_){const b=(k=(g=this._config).provideHover)==null?void 0:k.call(g,{word:h,row:d.row,col:d.col,line:u,language:this._config.language,doc:this._tab.doc});b&&(_=b)}_&&this._showHoverTip(_,e,t)}_showHoverTip(e,t,i){const s=this._hoverTip;let n='<div class="sl-ht-sig">';n+=`<span class="sl-ht-title">${se(e.title)}</span>`,e.type&&(n+=`<code class="sl-ht-type">${se(e.type)}</code>`),n+="</div>",e.title&&e.body&&(n+='<div class="sl-ht-divider"></div>'),e.body&&(n+=`<div class="sl-ht-body">${se(e.body)}</div>`),s.innerHTML=n,s.style.display="block";const o=12,a=18,l=s.offsetWidth||300,c=s.offsetHeight||80;let d=t,u=i+a;u+c>window.innerHeight-o&&(u=i-c-8),d+l>window.innerWidth-o&&(d=window.innerWidth-l-o),d<o&&(d=o),s.style.left=`${d}px`,s.style.top=`${Math.max(o,u)}px`}_hideHover(){this._hoverTimer!==null&&(clearTimeout(this._hoverTimer),this._hoverTimer=null),this._hoverPinned=!1,this._hoverTip.style.display="none"}_onInput(e){var n,o,a,l;if(this._config.readOnly){e.target.value="";return}const t=e.target,i=t.value;if(t.value="",!i||i==="Ω")return;const s=i.replace(/[\x00-\x08\x0a-\x1f\x7f]/g,"");if(s){if(this._extraCursors.length){this._snippetSession=null;const c=ni(this._tab.doc,this._tab.cur.row,this._tab.cur.col,this._extraCursors,s);this._tab.doc=c.doc,this._tab.cur.row=c.primaryRow,this._tab.cur.col=c.primaryCol,this._extraCursors=c.extraCursors,this._mc.cursors=c.extraCursors,this._tab.dirty=!0,(o=(n=this._config).onChange)==null||o.call(n,$(this._tab.doc))}else{const c=this._tab.cur.row,d=this._tab.cur.col;if(this._insertStr(s,!0),this._snippetSession){const u=this._snippetSession,h=u.stops[u.idx];if(this._tab.cur.row===h.row){const _=this._tab.cur.col-d;for(let y=u.idx+1;y<u.stops.length;y++){const g=u.stops[y];g.row===c&&g.col>=d&&(g.col+=_)}h.col=this._tab.cur.col}else this._snippetSession=null}}this._tokenCache.clear(),this._rebuildWrapMap(),A(this._tab),this._scrollIntoView(),this._render(),this._acTrigger(),this._emmetCheck(),this._snippetCheck(),(l=(a=this._config).onCursorChange)==null||l.call(a,{...this._tab.cur}),this._broadcastCursorToCollab()}}_ctrlD(){if(!this._config.multiCursor)return;const e=oi(this._mc,this._tab.doc,this._tab.cur.row,this._tab.cur.col,this._tab.sel);e&&(!this._mc.cursors.length||e.word!==this._mc.searchWord?(this._tab.sel=e.sel,this._tab.cur.col=e.col):(rt(this._mc,e.row,e.col,e.sel),this._extraCursors=[...this._mc.cursors]),this._mc.searchWord=e.word,this._mc.lastMatchRow=e.row,this._mc.lastMatchCol=e.col,this._scrollIntoView(),this._render())}_bindFindEvents(){var e,t,i,s,n,o,a;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",l=>{l.key==="Enter"?l.shiftKey?this._navFind(-1):this._navFind(1):l.key==="Escape"&&this._closeFind(),l.stopPropagation()}),this._replaceInput.addEventListener("keydown",l=>{l.key==="Enter"?this._doReplaceOne():l.key==="Escape"&&this._closeFind(),l.stopPropagation()}),(e=this._findBar.querySelector(".sl-find-prev"))==null||e.addEventListener("click",()=>this._navFind(-1)),(t=this._findBar.querySelector(".sl-find-next"))==null||t.addEventListener("click",()=>this._navFind(1)),(i=this._findBar.querySelector(".sl-find-close"))==null||i.addEventListener("click",()=>this._closeFind()),(s=this._findBar.querySelector(".sl-find-case"))==null||s.addEventListener("click",l=>{this._findCaseSensitive=!this._findCaseSensitive,l.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",l=>{this._findRegex=!this._findRegex,l.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()),(a=this._findBar.querySelector(".sl-replace-all"))==null||a.addEventListener("click",()=>this._doReplaceAll())}_doReplaceOne(){var e,t;this._findIdx<0||!this._findMatches.length||(j(this._tab,this._config.maxUndoHistory),this._tab.doc=li(this._tab.doc,this._findMatches,this._findIdx,this._replaceInput.value),this._tokenCache.clear(),this._tab.dirty=!0,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()),(t=(e=this._config).onChange)==null||t.call(e,$(this._tab.doc)))}_doReplaceAll(){var t,i;if(!this._findMatches.length)return;const e=this._findMatches.length;j(this._tab,this._config.maxUndoHistory),this._tab.doc=ci(this._tab.doc,this._findMatches,this._replaceInput.value),this._tokenCache.clear(),this._tab.dirty=!0,this._findMatches=[],this._findIdx=-1,this._findCount.textContent=`0/0 (${e} replaced)`,this._rebuildWrapMap(),this._render(),(i=(t=this._config).onChange)==null||i.call(t,$(this._tab.doc))}_bindMinimapEvents(){const e=this._minimapWrap;e.addEventListener("mousemove",t=>{if(this._mmDragMode!=="none")return;const i=t.clientY-e.getBoundingClientRect().top,{sliderTop:s,sliderHeight:n}=Me(this._tab.doc.length,this._editorEl.scrollTop,this._editorEl.clientHeight,e.clientHeight,this._config.lineHeight);e.style.cursor=i>=s&&i<=s+n?"grab":"pointer"}),e.addEventListener("mousedown",t=>{t.preventDefault();const i=e.clientHeight,s=t.clientY-e.getBoundingClientRect().top,{sliderTop:n,sliderHeight:o}=Me(this._tab.doc.length,this._editorEl.scrollTop,this._editorEl.clientHeight,i,this._config.lineHeight);if(s>=n&&s<=n+o)this._mmDragMode="slider",this._mmSliderOffset=s-n,this._mmDragStartY=t.clientY,this._mmDragStartScroll=this._editorEl.scrollTop,e.style.cursor="grabbing";else{this._mmDragMode="jump";const a=Ti(s,this._tab.doc.length,this._editorEl.scrollTop,this._editorEl.clientHeight,i,this._config.lineHeight);this._editorEl.scrollTop=a,this._mmDragStartY=t.clientY,this._mmDragStartScroll=a,this._render()}}),window.addEventListener("mousemove",this._onWinMmMouseMove),window.addEventListener("mouseup",this._onWinMmMouseUp)}}const ce=new Map;class ht{constructor(e,t){p(this,"siteId");p(this,"_room");p(this,"_cbs",new Set);p(this,"_receive",e=>{for(const t of this._cbs)t(e)});this._room=e,this.siteId=t,ce.has(e)||ce.set(e,new Set),ce.get(e).add(this._receive)}send(e){const t=ce.get(this._room);t&&queueMicrotask(()=>{for(const i of t)i!==this._receive&&i(e)})}onMessage(e){return this._cbs.add(e),()=>this._cbs.delete(e)}close(){var e;(e=ce.get(this._room))==null||e.delete(this._receive),this._cbs.clear()}}class pt{constructor(e,t){p(this,"siteId");p(this,"_channel");p(this,"_cbs",new Set);this.siteId=t,this._channel=new BroadcastChannel(e),this._channel.onmessage=i=>{for(const s of this._cbs)s(i.data)}}send(e){try{this._channel.postMessage(e)}catch{}}onMessage(e){return this._cbs.add(e),()=>this._cbs.delete(e)}close(){this._channel.close(),this._cbs.clear()}}class Ei{constructor(e,t,i,s={}){p(this,"siteId");p(this,"_ws",null);p(this,"_baseUrl");p(this,"_cbs",new Set);p(this,"_reconnectTimer",null);p(this,"_pingTimer",null);p(this,"_closed",!1);p(this,"_attempt",0);p(this,"_queue",[]);p(this,"_opts");this.siteId=i;const n=e.replace(/\/$/,"");this._baseUrl=`${n}/${encodeURIComponent(t)}?site=${encodeURIComponent(i)}`,this._opts={onConnect:s.onConnect??(()=>{}),onDisconnect:s.onDisconnect??(()=>{}),onError:s.onError??(()=>{}),pingIntervalMs:s.pingIntervalMs??25e3,maxBackoffMs:s.maxBackoffMs??3e4},this._connect()}_connect(){this._closed||(this._ws=new WebSocket(this._baseUrl),this._ws.onopen=()=>{this._attempt=0;for(const e of this._queue)this._rawSend(e);this._queue=[],this._startPing(),this._opts.onConnect()},this._ws.onmessage=e=>{if(e.data!=="__pong__")try{const t=JSON.parse(e.data);for(const i of this._cbs)i(t)}catch{}},this._ws.onclose=()=>{if(this._stopPing(),this._closed){this._opts.onDisconnect(!1);return}this._opts.onDisconnect(!0),this._scheduleReconnect()},this._ws.onerror=e=>{var t;this._opts.onError(e),(t=this._ws)==null||t.close()})}_scheduleReconnect(){const e=Math.min(250*2**this._attempt,this._opts.maxBackoffMs);this._attempt++,this._reconnectTimer=setTimeout(()=>this._connect(),e)}_startPing(){this._opts.pingIntervalMs<=0||(this._pingTimer=setInterval(()=>{var e;((e=this._ws)==null?void 0:e.readyState)===WebSocket.OPEN&&this._ws.send("__ping__")},this._opts.pingIntervalMs))}_stopPing(){this._pingTimer!==null&&(clearInterval(this._pingTimer),this._pingTimer=null)}send(e){var t;((t=this._ws)==null?void 0:t.readyState)===WebSocket.OPEN?this._rawSend(e):this._queue.push(e)}_rawSend(e){try{this._ws.send(JSON.stringify(e))}catch{}}onMessage(e){return this._cbs.add(e),()=>this._cbs.delete(e)}close(){var e;this._closed=!0,this._reconnectTimer!==null&&(clearTimeout(this._reconnectTimer),this._reconnectTimer=null),this._stopPing(),(e=this._ws)==null||e.close(),this._cbs.clear()}get connectionState(){var e;switch((e=this._ws)==null?void 0:e.readyState){case WebSocket.CONNECTING:return"connecting";case WebSocket.OPEN:return"open";case WebSocket.CLOSING:return"closing";default:return"closed"}}get queuedMessageCount(){return this._queue.length}}function Ii(r,e={}){const t=e.siteId??crypto.randomUUID(),i=e.room??"syncline-default",s=new ae(t);let n;const o=e.transport??"local";o==="broadcastchannel"?n=new pt(i,t):typeof o=="function"?n=new o(i,t):n=new ht(i,t);const a=new fe(r,s,n,{name:e.name,onPeersChange:e.onPeersChange});return{binding:a,doc:s,destroy(){a.destroy(),n.close()}}}function Li(r,e){return new dt(r,e)}C.AwarenessManager=Ae,C.BUILT_IN_THEMES=Xe,C.BroadcastChannelTransport=pt,C.CRDTBinding=fe,C.LocalTransport=ht,C.RGADocument=ae,C.ROOT_ID=D,C.SynclineEditor=dt,C.THEME_DRACULA=Ke,C.THEME_GITHUB_LIGHT=Ye,C.THEME_MONOKAI=Ve,C.THEME_SOLARIZED_LIGHT=Je,C.THEME_VR_DARK=qe,C.THEME_VSCODE_DARK=Ge,C.WebSocketTransport=Ei,C.charIdEq=de,C.charIdToStr=O,C.createCollabSession=Ii,C.createEditor=Li,C.diffText=Ie,C.siteColor=Be,C.svFromRecord=Ee,C.svToRecord=he,Object.defineProperty(C,Symbol.toStringTag,{value:"Module"})});
487
569
  //# sourceMappingURL=syncline-editor.umd.js.map