1const Ju=function(){const e=typeof document<"u"&&document.createElement("link").relList;return e&&e.supports&&e.supports("modulepreload")?"modulepreload":"preload"}(),Zu=function(n){return"/"+n},Zo={},vi=function(e,t,i){let s=Promise.resolve();if(t&&t.length>0){let o=function(h){return Promise.all(h.map(c=>Promise.resolve(c).then(u=>({status:"fulfilled",value:u}),u=>({status:"rejected",reason:u}))))};document.getElementsByTagName("link");const l=document.querySelector("meta[property=csp-nonce]"),a=l?.nonce||l?.getAttribute("nonce");s=o(t.map(h=>{if(h=Zu(h),h in Zo)return;Zo[h]=!0;const c=h.endsWith(".css"),u=c?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${h}"]${u}`))return;const f=document.createElement("link");if(f.rel=c?"stylesheet":Ju,c||(f.as="script"),f.crossOrigin="",f.href=h,a&&f.setAttribute("nonce",a),document.head.appendChild(f),c)return new Promise((d,p)=>{f.addEventListener("load",d),f.addEventListener("error",()=>p(new Error(`Unable to preload CSS for ${h}`)))})}))}function r(o){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=o,window.dispatchEvent(l),!l.defaultPrevented)throw o}return s.then(o=>{for(const l of o||[])l.status==="rejected"&&r(l.reason);return e().catch(r)})};function si(n){return n==="TINYINT"||n==="SMALLINT"||n==="INTEGER"||n==="BIGINT"||n==="HUGEINT"||n==="UTINYINT"||n==="USMALLINT"||n==="UINTEGER"||n==="UBIGINT"||n==="UHUGEINT"}function ef(n){return n==="FLOAT"||n==="DOUBLE"||n==="DECIMAL"}function ht(n){return si(n)||ef(n)}function He(n){return n==="DATE"}function Qt(n){return n==="TIME"||n==="TIME_TZ"}function dt(n){return n==="TIMESTAMP"||n==="TIMESTAMP_TZ"||n==="TIMESTAMP_NS"||n==="TIMESTAMP_MS"||n==="TIMESTAMP_S"}function Li(n){return He(n)||Qt(n)||dt(n)}function xn(n){return n==="BOOLEAN"}function Ii(n){return n==="VARCHAR"||n==="UUID"||n==="ENUM"}function Vs(n){return n==="LIST"||n==="STRUCT"||n==="MAP"||n==="UNION"||n==="JSON"}function el(n){switch(n){case"STRUCT":return"struct";case"LIST":return"list";case"MAP":return"map";case"JSON":return"json";case"UNION":return"union";default:return null}}function tl(n){if(!n)return"UNKNOWN";let e=n.trim().toUpperCase();if(e.startsWith("STRUCT"))return"STRUCT";if(e.startsWith("LIST")||/\[\d*\]/.test(e))return"LIST";if(e.startsWith("MAP"))return"MAP";if(e.startsWith("UNION"))return"UNION";if(e.startsWith("ENUM"))return"ENUM";if(e==="TIMESTAMP WITH TIME ZONE"||e==="TIMESTAMPTZ")return"TIMESTAMP_TZ";if(e==="TIMESTAMP WITHOUT TIME ZONE")return"TIMESTAMP";if(e==="TIMESTAMP_NS")return"TIMESTAMP_NS";if(e==="TIMESTAMP_MS")return"TIMESTAMP_MS";if(e==="TIMESTAMP_S"||e==="TIMESTAMP(0)")return"TIMESTAMP_S";if(e==="TIME WITH TIME ZONE"||e==="TIMETZ")return"TIME_TZ";const t=e.indexOf("(");switch(t>=0&&(e=e.slice(0,t)),e=e.trim(),e){case"BOOL":case"LOGICAL":return"BOOLEAN";case"INT1":return"TINYINT";case"INT2":case"SHORT":return"SMALLINT";case"INT":case"INT4":case"INT32":return"INTEGER";case"INT8":case"LONG":case"INT64":return"BIGINT";case"INT128":return"HUGEINT";case"REAL":case"FLOAT4":case"FLOAT32":return"FLOAT";case"FLOAT8":case"FLOAT64":case"DOUBLE PRECISION":return"DOUBLE";case"NUMERIC":case"DEC":return"DECIMAL";case"TEXT":case"STRING":case"CHAR":case"BPCHAR":return"VARCHAR";case"BYTEA":case"BINARY":case"VARBINARY":return"BLOB";case"BITSTRING":return"BIT"}const s={BOOLEAN:"BOOLEAN",TINYINT:"TINYINT",SMALLINT:"SMALLINT",INTEGER:"INTEGER",BIGINT:"BIGINT",HUGEINT:"HUGEINT",UTINYINT:"UTINYINT",USMALLINT:"USMALLINT",UINTEGER:"UINTEGER",UBIGINT:"UBIGINT",UHUGEINT:"UHUGEINT",FLOAT:"FLOAT",DOUBLE:"DOUBLE",DECIMAL:"DECIMAL",DATE:"DATE",TIME:"TIME",TIMESTAMP:"TIMESTAMP",INTERVAL:"INTERVAL",VARCHAR:"VARCHAR",BLOB:"BLOB",BIT:"BIT",UUID:"UUID",JSON:"JSON",ENUM:"ENUM",LIST:"LIST",STRUCT:"STRUCT",MAP:"MAP",UNION:"UNION"}[e];return s||"UNKNOWN"}const tf=Number.MAX_SAFE_INTEGER,sf=Number.MAX_SAFE_INTEGER,nf=400,rf=600,of=24,lf=100,af=1e3,hf=100,cf=8,uf=60,mr="geometricPrecision",gr="0px",yr=!1,br="high",ff=1,df="Consolas, 'Courier New', monospace",pf=14,mf=14,gf=12,Za="NULL",eh="TRUE",th="FALSE",yf="left",bf="yyyy-MM-dd",wf="yyyy-MM-dd HH:mm:ss",Cf={minimumFractionDigits:2,maximumFractionDigits:2},xf=new Intl.Locale("en-UK"),Sf=200,vf=.8,ih=200,sh=50,nh=1e3,kf=1e3*60*5;let te=null,Ni=null,il=!1;function Tf(){if(il||typeof document>"u")return;il=!0;const n=()=>{te=null,Ni=null};new MutationObserver(n).observe(document.body,{attributes:!0,attributeFilter:["class"]}),window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",n)}function wr(){return Tf(),te!==null?te:document.body.classList.contains("theme-light")?(te="light",te):document.body.classList.contains("theme-classic-light")?(te="classic-light",te):document.body.classList.contains("theme-github-light")?(te="github-light",te):document.body.classList.contains("theme-classic-dark")?(te="classic-dark",te):document.body.classList.contains("theme-github-dark")?(te="github-dark",te):document.body.classList.contains("theme-dark")||window.matchMedia&&window.matchMedia("(prefers-color-scheme: dark)").matches?(te="dark",te):(te="light",te)}
1function $s(n){if(Ni!==null)return Ni;const e=wr();let t;return e==="dark"?t={headerBackgroundColor:"#171511",headerTextColor:"#ece7da",cellBackgroundColor:"#171511",cellTextColor:"#ece7da",stripeBackgroundColor:"#1c1913",borderColor:"#35322a",selectionColor:"rgba(255, 217, 57, 0.22)",selectionBorderColor:"#ffd939",hoverColor:"rgba(255, 217, 57, 0.10)",hoverBorderColor:"rgba(255, 217, 57, 0.45)",scrollbarColor:"#29251c",scrollbarThumbColor:"#4d483c",scrollbarHoverColor:"#a49e8e",booleanStyle:{backgroundColor:"#171511",textColor:"#8fb8c4"},numericStyle:{backgroundColor:"#171511",textColor:"#ece7da"},stringStyle:{backgroundColor:"#171511",textColor:"#ece7da"},dateStyle:{backgroundColor:"#171511",textColor:"#d9bd66"},datetimeStyle:{backgroundColor:"#171511",textColor:"#cf9a62"},nullStyle:{backgroundColor:"#171511",textColor:"#a49e8e"},headerTopRuleColor:"#ece7da",headerBottomRuleColor:"#ece7da",frameBottomRuleColor:"#ece7da",verticalGridColor:"transparent"}:e==="github-dark"?t={headerBackgroundColor:"#181818",headerTextColor:"#e1e4e8",cellBackgroun
1dColor:"#1f1f1f",cellTextColor:"#e1e4e8",stripeBackgroundColor:"#262626",borderColor:"#3a3a3a",selectionColor:"rgba(121, 184, 255, 0.20)",selectionBorderColor:"#79b8ff",hoverColor:"rgba(121, 184, 255, 0.10)",hoverBorderColor:"rgba(121, 184, 255, 0.5)",scrollbarColor:"#181818",scrollbarThumbColor:"#3a3a3a",scrollbarHoverColor:"#4d4d4d",booleanStyle:{backgroundColor:"#1f1f1f",textColor:"#79b8ff"},numericStyle:{backgroundColor:"#1f1f1f",textColor:"#85e89d"},stringStyle:{backgroundColor:"#1f1f1f",textColor:"#e1e4e8"},dateStyle:{backgroundColor:"#1f1f1f",textColor:"#ffea7f"},datetimeStyle:{backgroundColor:"#1f1f1f",textColor:"#ffab70"},nullStyle:{backgroundColor:"#1f1f1f",textColor:"#6a737d"}}:e==="classic-dark"?t={headerBackgroundColor:"#1f2335",headerTextColor:"#c0caf5",cellBackgroundColor:"#1a1b26",cellTextColor:"#c0caf5",stripeBackgroundColor:"#1d1f2c",borderColor:"#292e42",selectionColor:"rgba(122, 162, 247, 0.22)",selectionBorderColor:"#7aa2f7",hoverColor:"rgba(122, 162, 247, 0.10)",hoverBorderColor:"rgba(122, 162, 247, 0.5)",scrollbarColor:"#16161e",scrollbarThumbColor:"#3b4261",scrollbarHoverColor:"#565f89",booleanStyle:{backgroundColor:"#1a1b26",textColor:"#7aa2f7"},numericStyle:{backgroundColor:"#1a1b26",textColor:"#9ece6a"},stringStyle:{backgroundColor:"#1a1b26",textColor:"#c0caf5"},dateStyle:{backgroundColor:"#1a1b26",textColor:"#e0af68"},datetimeStyle:{backgroundColor:"#1a1b26",textColor:"#ff9e64"},nullStyle:{backgroundColor:"#1a1b26",textColor:"#565f89"}}:e==="classic-light"?t={headerBackgroundColor:"#d6d8e0",headerTextColor:"#3760bf",cellBackgroun
1dColor:"#e1e2e7",cellTextColor:"#3760bf",stripeBackgroundColor:"#dadce4",borderColor:"#b4b5b9",selectionColor:"rgba(46, 125, 233, 0.18)",selectionBorderColor:"#2e7de9",hoverColor:"rgba(46, 125, 233, 0.10)",hoverBorderColor:"rgba(46, 125, 233, 0.45)",scrollbarColor:"#d6d8e0",scrollbarThumbColor:"#a8aecb",scrollbarHoverColor:"#848cb5",booleanStyle:{backgroundColor:"#e1e2e7",textColor:"#2e7de9"},numericStyle:{backgroundColor:"#e1e2e7",textColor:"#587539"},stringStyle:{backgroundColor:"#e1e2e7",textColor:"#3760bf"},dateStyle:{backgroundColor:"#e1e2e7",textColor:"#8c6c3e"},datetimeStyle:{backgroundColor:"#e1e2e7",textColor:"#b15c00"},nullStyle:{backgroundColor:"#e1e2e7",textColor:"#848cb5"}}:e==="github-light"?t={headerBackgroundColor:"#e8e8e4",headerTextColor:"#3760bf",cellBackgroundColor:"#f5f5f3",cellTextColor:"#3760bf",stripeBackgroundColor:"#efefec",borderColor:"#d6d6cf",selectionColor:"rgba(46, 125, 233, 0.18)",selectionBorderColor:"#2e7de9",hoverColor:"rgba(46, 125, 233, 0.10)",hoverBorderColor:"rgba(46, 125, 233, 0.45)",scrollbarColor:"#e8e8e4",scrollbarThumbColor:"#cfcfc7",scrollbarHoverColor:"#aaaaa0",booleanStyle:{backgroundColor:"#f5f5f3",textColor:"#2e7de9"},numericStyle:{backgroundColor:"#f5f5f3",textColor:"#587539"},stringStyle:{backgroundColor:"#f5f5f3",textColor:"#3760bf"},dateStyle:{backgroundColor:"#f5f5f3",textColor:"#8c6c3e"},datetimeStyle:{backgroundColor:"#f5f5f3",textColor:"#b15c00"},nullStyle:{backgroundColor:"#f5f5f3",textColor:"#848cb5"}}:t={headerBackgroundColor:"#f7f5ef",headerTextColor:"#1a1917",cellBackgroun
1dColor:"#f7f5ef",cellTextColor:"#1a1917",stripeBackgroundColor:"#f2efe6",borderColor:"#d9d5c9",selectionColor:"rgba(255, 217, 57, 0.4)",selectionBorderColor:"#1a1917",hoverColor:"rgba(255, 217, 57, 0.18)",hoverBorderColor:"rgba(26, 25, 23, 0.35)",scrollbarColor:"#efece1",scrollbarThumbColor:"#b8b3a3",scrollbarHoverColor:"#5f5c54",booleanStyle:{backgroundColor:"#f7f5ef",textColor:"#275e6e"},numericStyle:{backgroundColor:"#f7f5ef",textColor:"#1a1917"},stringStyle:{backgroundColor:"#f7f5ef",textColor:"#1a1917"},dateStyle:{backgroundColor:"#f7f5ef",textColor:"#8a6d1f"},datetimeStyle:{backgroundColor:"#f7f5ef",textColor:"#a05c2c"},nullStyle:{backgroundColor:"#f7f5ef",textColor:"#5f5c54"},headerTopRuleColor:"#1a1917",headerBottomRuleColor:"#1a1917",frameBottomRuleColor:"#1a1917",verticalGridColor:"transparent"},Ni=t,t}function Af(n){let e=wr();const t=()=>{te=null,Ni=null;const r=wr();r!==e&&(e=r,n(r))},i=new MutationObserver(t);i.observe(document.body,{attributes:!0,attributeFilter:["class"]});const s=window.matchMedia("(prefers-color-scheme: dark)");return s.addEventListener("change",t),()=>{i.disconnect(),s.removeEventListener("change",t)}}function Bn(n,e){if(n)try{return JSON.parse(n)}catch{if(He(e)||dt(e)){const s={"yyyy-MM-dd":{year:"numeric",month:"2-digit",day:"2-digit"},"dd/MM/yyyy":{day:"2-digit",month:"2-digit",year:"numeric"},"MM/dd/yyyy":{month:"2-digit",day:"2-digit",year:"numeric"},"yyyy/MM/dd":{year:"numeric",month:"2-digit",day:"2-digit"},"dd-MM-yyyy":{day:"2-digit",month:"2-digit",year:"numeric"},"MM-dd-yyyy":{month:"2-digit",day:"2-digit",year:"numeric"},yyyyMMdd:{year:"numeric",month:"2-digit",day:"2-digit"},ddMMyyyy:{day:"2-digit",month:"2-digit",year:"numeric"},MMddyyyy:{month:"2-digit",day:"2-digit",year:"numeric"},"yyyy-MM-dd HH:mm:ss":{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"},"dd/MM/yyyy HH:mm:ss":{day:"2-digit",month:"2-digit",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"}}[n];if(s)return s;if(n.includes("yyyy")||n.includes("MM")||n.includes("dd"))return{year:n.includes("yyyy")?"numeric":void 0,month:n.includes("MM")?"2-digit":void 0,day:n.includes("dd")?"2-digit":void 0,hour:n.includes("HH")?"2-digit":void 0,minute:n.includes("mm")?"2-digit":void 0,second:n.includes("ss")?"2-digit":void 0}}return}}function go(n,e){if(n.format){const t=Bn(n.format.toString(),n.dataType);if(t)return t}if(ht(n.dataType))return e.numberFormat;if(He(n.dataType))return Bn(e.dateFormat?.toString(),n.dataType);if(dt(n.dataType))return Bn(e.datetimeFormat?.toString(),n.dataType)}function _n(n,e){if(n.cachedFormatter)return n.cachedFormatter;const t=n.guessedFormat||go(n,e);if(!t)return null;const i=e.datetimeLocale;return ht(n.dataType)?(n.cachedFormatter=new Intl.NumberFormat(i,t),n.cachedFormatter):He(n.dataType)||dt(n.dataType)?(n.cachedFormatter=new Intl.DateTimeFormat(i,t),n.cachedFormatter):null}function sl(n,e){const t=(i,s=2)=>String(i).padStart(s,"0");return e.replace(/yyyy|MM|dd|HH|mm|ss/g,i=>{switch(i){case"yyyy":return String(n.getFullYear());case"MM":return t(n.getMonth()+1);case"dd":return t(n.getDate());case"HH":return t(n.getHours());case"mm":return t(n.getMinutes());case"ss":return t(n.getSeconds());default:return i}})}function nl(n,e,t){if(typeof n.format=="string"){const s=n.format.trim();if(s.length>0&&s[0]!=="{"&&s[0]!=="[")return s}const i=t==="date"?e.dateFormat:e.datetimeFormat;return typeof i=="string"?i:null}function Mf(n){const e=Math.floor(n/1e6),t=Math.floor(e/3600),i=Math.floor(e%3600/60),s=e%60,r=o=>o.toString().padStart(2,"0");return`${r(t)}:${r(i)}:${r(s)}`}function rh(n){if(n==null)return"";if(n instanceof Uint8Array){const t=n.subarray(0,32),i=Array.from(t,r=>r.toString(16).padStart(2,"0")).join(""),s=n.length>32?`... (${n.length}B)`:` (${n.length}B)`;return`0x${i}${s}`}return String(n)}const oh=3;let hs=null;function Ef(n){const e=n.numberFormat;if(typeof e!="object"||e===null)return null;if(hs&&hs.opts===e)return hs.fmt;try{const t=new Intl.NumberFormat(void 0,e);return hs={opts:e,fmt:t},t}catch{return null}}function cs(n,e,t){return Vs(e.dataType)?Of(n):ah(n,e,t).formatted}function Of(n){if(n==null)return"";try{return JSON.stringify(n,(e,t)=>typeof t=="bigint"?t.toString():t instanceof Date?isNaN(t.getTime())?null:t.toISOString():t instanceof Uint8Array?Array.from(t):t)}catch{return String(n)}}function Df(n,e){if(n==null)return"";try{return yo(n,e,!1)}catch{try{return JSON.stringify(n,(t,i)=>typeof i=="bigint"?i.toString():i)}catch{return String(n)}}}function yo(n,e,t){return n==null?"null":Array.isArray(n)?t?"[â¦]":Rf(n,e):typeof n=="object"?n instanceof Date?isNaN(n.getTime())?"null":n.toISOString().slice(0,19).replace("T"," "):n instanceof Uint8Array?rh(n):t?"{â¦}":Lf(n,e):If(n,e)}function Rf(n,e){if(n.length===0)return"[]";const t=n.slice(0,oh).map(r=>yo(r,e,!0)),i=n.length-t.length,s=t.join(", ");return i>0?`[ ${s}, ⦠${i} more ]`:`[ ${s} ]`}function Lf(n,e){const t=Object.entries(n);if(t.length===0)return"{}";const i=t.slice(0,oh).map(([o,l])=>`${o}: ${yo(l,e,!0)}`),s=t.length-i.length,r=i.join(", ");return s>0?`{ ${r}, ⦠${s} more }`:`{ ${r} }`}function If(n,e){if(typeof n=="bigint")return n.toString();if(typeof n=="number"){if(!isFinite(n))return String(n);const t=Ef(e);return t?t.format(n):String(n)}return typeof n=="string"?JSON.stringify(n):typeof n=="boolean"?n?"true":"false":String(n)}const Cr=(n,e,t)=>{const i=t.naText||Za;if(n==null)return{raw:null,formatted:i};const s=n;typeof n=="bigint"&&(n=Number(n));const r=e.dataType;if(ht(r)&&(n=Number(n)),(He(r)||dt(r))&&(n=n instanceof Date?n:new Date(n)),(ht(r)||Li(r))&&typeof n=="number"&&isNaN(n))return{raw:null,formatted:i};if((He(r)||dt(r))&&n instanceof Date&&isNaN(n.getTime()))return{raw:null,formatted:i};if(xn(r))return{raw:n,formatted:n?t.trueText||eh:t.falseText||th};if(ht(r)){const o=_n(e,t);return o?{raw:n,formatted:o.format(n)}
1:{raw:n,formatted:n.toLocaleString()}}if(He(r)){const o=nl(e,t,"date");if(o)return{raw:n,formatted:sl(n,o)};const l=_n(e,t);return l?{raw:n,formatted:l.format(n)}:{raw:n,formatted:n.toLocaleDateString()}}if(Qt(r))return{raw:n,formatted:Mf(n)};if(dt(r)){const o=nl(e,t,"datetime");if(o)return{raw:n,formatted:sl(n,o)};const l=_n(e,t);return l?{raw:n,formatted:l.format(n)}:{raw:n,formatted:n.toLocaleString()}}return r==="INTERVAL"?{raw:n,formatted:String(n)}:Ii(r)?{raw:n,formatted:String(n)}:r==="BLOB"||r==="BIT"?{raw:s,formatted:rh(s)}:Vs(r)?{raw:s,formatted:Df(s,t)}:{raw:n,formatted:String(n)}};function lh(){return{raw:null,formatted:"",textAlign:"left",textColor:"",backgroundColor:""}}function xr(n,e,t,i){const s=e.dataType,r=$s();if(n==null){i.raw=null,i.formatted=Cr(n,e,t).formatted,i.textAlign="left",i.textColor=r.nullStyle.textColor,i.backgroundColor=r.nullStyle.backgroundColor;return}const{raw:o,formatted:l}=Cr(n,e,t);if(i.raw=o,i.formatted=l,xn(s)){i.textAlign="center",i.textColor=r.booleanStyle.textColor,i.backgroundColor=r.booleanStyle.backgroundColor;return}if(ht(s)){i.textAlign="right",i.textColor=r.numericStyle.textColor,i.backgroundColor=r.numericStyle.backgroundColor;return}if(He(s)||Qt(s)){i.textAlign="left",i.textColor=r.dateStyle.textColor,i.backgroundColor=r.dateStyle.backgroundColor;return}if(dt(s)){i.textAlign="left",i.textColor=r.datetimeStyle.textColor,i.backgroundColor=r.datetimeStyle.backgroundColor;return}i.textAlign="left",i.textColor=r.stringStyle.textColor,i.backgroundColor=r.stringStyle.backgroundColor}function ah(n,e,t){const i=lh();return xr(n,e,t,i),{raw:i.raw,formatted:i.formatted,style:{textAlign:i.textAlign,textColor:i.textColor,backgroundColor:i.backgroundColor}}}function Me(n){return String(n).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}class ni{container;spreadsheetVisualizer=null;currentColumn=null;filterManager=null;datasetName="";onFilterChangeCallback;onShowStatsCallback;valueSearchQuery="";valueSearchUseRegex=!1;valueSearchResults=null;valueSearchSeq=0;valueSearchDebounceTimer=null;excludedValues=new Set;static VALUE_SEARCH_LIMIT=500;constructor(e,t){this.container=document.createElement("div"),this.spreadsheetVisualizer=t,this.container.id="column-stats-container",e.appendChild(this.container)}async setSpreadsheetVisualizer(e){this.spreadsheetVisualizer=e,this.spreadsheetVisualizer.getSelectedColumns().length>0?await this.showStats(this.spreadsheetVisualizer.getSelectedColumns()[0]):this.hide()}async showStats(e){if(this.currentColumn?.name!==e.name&&(this.valueSearchQuery="",this.valueSearchUseRegex=!1,this.valueSearchResults=null,this.valueSearchSeq++,this.valueSearchDebounceTimer!==null&&(window.clearTimeout(this.valueSearchDebounceTimer),this.valueSearchDebounceTimer=null),this.excludedValues=new Set,this.filterManager)){const r=this.filterManager.getFilters(this.datasetName).find(o=>o.columnName===e.name);r?.filterType==="exclude"&&r.values&&(this.excludedValues=new Set(r.values))}this.currentColumn=e,this.container.style.display="block",this.container.classList.add("visible"),this.onShowStatsCallback?.();const t=this.spreadsheetVisualizer.getDataProvider(),[i,s]=await Promise.all([t.getColumnStatsFiltered(e),t.getColumnStats(e)]);this.currentColumn===e&&this.render(i??s,s??i)}setOnShowStatsCallback(e){this.onShowStatsCallback=e}hide(){this.container.style.display="none",this.container.classList.remove("visible"),this.currentColumn=null}getContainer(){return this.container}setFilterManager(e,t){this.filterManager=e,this.datasetName=t}setDatasetName(e){this.datasetName=e}setOnFilterChangeCallback(e){this.onFilterChangeCallback=e}displayValue(e){if(!this.currentColumn)return String(e);if(e==null)return"NULL";try{const t=this.spreadsheetVisualizer?.getOptions?.()??{},i=this.currentColumn;return Cr(e,i,t).formatted}catch{return String(e)}}render(e,t){if(!this.currentColumn||!e||!t)return;const i=this.filterManager?.isColumnSorted(this.datasetName,this.currentColumn.name)??null;this.container.innerHTML=` 2 <div class="column-stats"> 3 <div class="column-stats__header"> 4 <div class="column-stats__header-left"> 5 <h3>${Me(this.currentColumn.name)}</h3> 6 ${this.currentColumn.label?`<div class="column-stats__label">${Me(this.currentColumn.label)}</div>`:""} 7 <div class="column-stats__type">${Me(this.currentColumn.rawType||this.currentColumn.dataType)}</div> 8 </div> 9 <div class="column-stats__sort-stack"> 10 <button class="column-stats__sort-btn${i==="asc"?" column-stats__sort-btn--active":""}" data-sort="asc" title="Sort Ascending">▲</button> 11 <button class="column-stats__sort-btn${i==="desc"?" column-stats__sort-btn--active":""}" data-sort="desc" title="Sort Descending">▼</button> 12 ${i?'<button class="column-stats__sort-btn column-stats__sort-btn--clear" data-sort="clear" title="Clear Sort">✕</button>':""} 13 </div> 14 </div> 15 <div class="column-stats__container"> 16 ${this.renderStats(e)} 17 </div> 18 ${this.renderFilterControls(t)} 19 ${this.renderVisualization(e)} 20 </div> 21 `,this.attachEventListeners(t)}renderFilterControls(e){if(!this.filterManager||!this.currentColumn)return"";const t=this.currentColumn.dataType,i=this.filterManager.isColumnFiltered(this.datasetName,this.currentColumn.name),s=this.filterManager.getFilters(this.datasetName).find(r=>r.columnName===this.currentColumn.name);return ht(t)&&e.numericStats?this.renderNumericRangeFilter(e,i,s):Li(t)&&e.temporalStats?this.renderTemporalRangeFilter(t,i,s):xn(t)&&e.isCategorical?this.renderBooleanFilter(e,i,s):Ii(t)&&e.isCategorical&&e.valueCounts.size>0?this.renderCategoricalFilter(e,i,s):""}renderCategoricalFilter(e,t,i){const s=this.valueSearchUseRegex,r=this.valueSearchQuery,o=Array.from(e.valueCounts.entries()).map(([l,a])=>({value:l,count:a}));return` 22 <div class="column-stats__filter"> 23 <div class="column-stats__filter-header">
24 <span class="column-stats__filter-title">Filter Values</span> 25 ${t?'<button class="column-stats__filter-clear" data-action="clear-filter">Clear</button>':""} 26 </div> 27 <div class="column-stats__filter-search"> 28 <input 29 type="search" 30 class="column-stats__filter-search-input" 31 placeholder="${s?"Regexâ¦":"Search valuesâ¦"}" 32 value="${Je(r)}" 33 data-action="value-search" 34 /> 35 <button 36 class="column-stats__filter-regex-toggle${s?" column-stats__filter-regex-toggle--active":""}" 37 data-action="toggle-regex" 38 title="${s?"Regex match (case-insensitive)":"Substring match (case-insensitive)"}. Click to switch." 39 >.*</button> 40 </div> 41 <div class="column-stats__filter-list"> 42 ${this.buildCategoricalListItems(o)} 43 </div> 44 <div class="column-stats__filter-search-summary"></div> 45 <button class="column-stats__filter-apply" data-action="apply-filter">Apply Filter</button> 46 </div> 47 `}buildCategoricalListItems(e){return e.length===0?'<div class="column-stats__filter-empty">No matching values.</div>':e.map(({value:t,count:i})=>{const s=!this.excludedValues.has(t),r=t.length>24?t.substring(0,24)+"â¦":t;return` 48 <label class="column-stats__filter-item" data-value="${Je(t)}" title="${Je(t)}"> 49 <input type="checkbox" value="${Je(t)}" ${s?"checked":""} /> 50 <span>${Me(r)}</span> 51 <span class="column-stats__filter-count">(${i.toLocaleString()})</span> 52 </label> 53 `}).join("")}renderBooleanFilter(e,t,i){const s=new Set(i?.values||[]),r=Array.from(e.valueCounts.entries());return` 54 <div class="column-stats__filter"> 55 <div class="column-stats__filter-header"> 56 <span class="column-stats__filter-title">Filter Values</span> 57 ${t?'<button class="column-stats__filter-clear" data-action="clear-filter">Clear</button>':""} 58 </div> 59 <div class="column-stats__filter-list"> 60 ${r.map(([o,l])=>{const a=s.size===0||s.has(o);return` 61 <label class="column-stats__filter-item"> 62 <input type="checkbox" value="${Je(o)}" ${a?"checked":""} /> 63 <span>${Me(o)} <span class="column-stats__filter-count">(${l.toLocaleString()})</span></span> 64 </label> 65 `}).join("")} 66 </div>
67 <button class="column-stats__filter-apply" data-action="apply-filter">Apply Filter</button> 68 </div> 69 `}renderNumericRangeFilter(e,t,i){const s=e.numericStats;return` 70 <div class="column-stats__filter"> 71 <div class="column-stats__filter-header"> 72 <span class="column-stats__filter-title">Filter Range</span> 73 ${t?'<button class="column-stats__filter-clear" data-action="clear-filter">Clear</button>':""} 74 </div> 75 <div class="column-stats__filter-range"> 76 <label> 77 <span>Min</span> 78 <input type="number" class="column-stats__filter-input" data-range="min" 79 placeholder="${rl(s.min)}" 80 value="${i?.min??""}" /> 81 </label> 82 <label> 83 <span>Max</span> 84 <input type="number" class="column-stats__filter-input" data-range="max" 85 placeholder="${rl(s.max)}" 86 value="${i?.max??""}" /> 87 </label> 88 </div> 89 <button class="column-stats__filter-appl
89y" data-action="apply-range-filter">Apply Filter</button> 90 </div> 91 `}renderTemporalRangeFilter(e,t,i){let s;He(e)?s="date":Qt(e)?s="time":s="datetime-local";const r=i?.minStr??"",o=i?.maxStr??"";return` 92 <div class="column-stats__filter"> 93 <div class="column-stats__filter-header"> 94 <span class="column-stats__filter-title">Filter Range</span> 95 ${t?'<button class="column-stats__filter-clear" data-action="clear-filter">Clear</button>':""} 96 </div> 97 <div class="column-stats__filter-range column-stats__filter-range--stacked"> 98 <label> 99 <span>From</span> 100 <input type="${s}" class="column-stats__filter-input" data-range="min" value="${Je(r)}" /> 101 </label> 102 <label> 103 <span>To</span> 104 <input type="${s}" class="column-stats__filter-input" data-range="max" value="${Je(o)}" /> 105 </label> 106 </div> 107 <button class="column-stats__filter-apply" data-action="apply-temporal-filter">Apply Filter</button> 108 </div> 109 `}attachEventListeners(e){const t=this.currentColumn?.dataType;if(this.container.querySelector(".column-stats__header h3")?.addEventListener("click",i=>{const s=i.currentTarget,r=(s.textContent??"").trim();this.copyToClipboard(r,s)}),this.container.querySelectorAll(".histogram__chart .histogram__label").forEach(i=>{const s=i.getAttribute("title")??i.textContent??"";i.title=`${s} 110Click to copy`,i.addEventListener("click",()=>this.copyToClipboard(s.trim(),i))}),this.container.querySelectorAll(".column-stats__sort-btn").forEach(i=>{i.addEventListener("click",()=>{const s=i.dataset.sort;!this.filterManager||!this.currentColumn||(s==="clear"?this.filterManager.removeSort(this.datasetName,this.currentColumn.name):(s==="asc"||s==="desc")&&this.filterManager.setSort(this.datasetName,{columnName:this.currentColumn.name,direction:s}))})}),this.container.querySelector("[data-action='clear-filter']")?.addEventListener("click",()=>{!this.filterManager||!this.currentColumn||this.filterManager.removeFilter(this.datasetName,this.currentColumn.name)}),this.container.querySelector("[data-action='apply-filter']")?.addEventListener("click",()=>{if(!this.filterManager||!this.currentColumn)return;if(t&&Ii(t)){if(this.valueSearchQuery!==""){const a=(this.valueSearchResults!==null?this.valueSearchResults.map(h=>h.value):Array.from(e.valueCounts.keys())).filter(h=>!this.excludedValues.has(h));if(a.length===0)this.filterManager.removeFilter(this.datasetName,this.currentColumn.name);else{const h={columnName:this.currentColumn.name,dataType:t,filterType:"include",values:a};this.filterManager.setFilter(this.datasetName,h)}return}if(this.excludedValues.size===0)this.filterManager.removeFilter(this.datasetName,this.currentColumn.name);else{const l={columnName:this.currentColumn.name,dataType:t,filterType:"exclude",values:[...this.excludedValues]};this.filterManager.setFilter(this.datasetName,l)}return}const i=this.container.querySelectorAll(".column-stats__filter-item input[type='checkbox']"),s=[];let r=!0;if(i.forEach(o=>{o.checked?s.push(o.value):r=!1}),r||s.length===0)this.filterManager.removeFilter(this.datasetName,this.currentColumn.name);else{const o={columnName:this.currentColumn.name,dataType:t,filterType:"include",values:s};this.filterManager.setFilter(this.datasetName,o)}}),this.container.querySelector("[data-action='apply-range-filter']")?.addEventListener("click",()=>{if(!this.filterManager||!this.currentColumn)return;const i=this.container.querySelector("[data-range='min']"),s=this.container.querySelector("[data-range='max']"),r=i?.value?parseFloat(i.value):void 0,o=s?.value?parseFloat(s.value):void 0;if(r===void 0&&o===void 0)this.filterManager.removeFilter(this.datasetName,this.currentColumn.name);else{const l={columnName:this.currentColumn.name,dataType:t,filterType:"range",min:r,max:o};this.filterManager.setFilter(this.datasetName,l)}}),this.container.querySelector("[data-action='apply-temporal-filter']")?.addEventListener("click",()=>{if(!this.filterManager||!this.currentColumn)return;const i=this.container.querySelector("[data-range='min']"),s=this.container.querySelector("[data-range='max']"),r=i?.value||void 0,o=s?.value||void 0;if(!r&&!o)this.filterManager.removeFilter(this.datasetName,this.currentColumn.name);else{const l={columnName:this.currentColumn.name,dataType:t,filterType:"range",minStr:r,maxStr:o};this.filterManager.setFilter(this.datasetName,l)}}),t&&Ii(t)){const i=this.container.querySelector("[data-action='value-search']"),s=this.container.querySelector("[data-action='toggle-regex']");i&&i.addEventListener("input",()=>{this.valueSearchQuery=i.value,this.scheduleValueSearch(e)}),s&&s.addEventListener("click",()=>{this.valueSearchUseRegex=!this.valueSearchUseRegex,s.classList.toggle("column-stats__filter-regex-toggle--active",this.valueSearchUseRegex),s.title=this.valueSearchUseRegex?"Regex match (case-insensitive). Click to switch.":"Substring match (case-insensitive). Click to switch.",i&&(i.placeholder=this.valueSearchUseRegex?"Regexâ¦":"Search valuesâ¦"),this.scheduleValueSearch(e)}),this.container.querySelector(".column-stats__filter")?.addEventListener("change",o=>{const l=o.target;if(!l.matches(".column-stats__filter-item input[type='checkbox']"))return;const a=l.value;l.checked?this.excludedValues.delete(a):this.excludedValues.add(a)}),this.valueSearchQuery&&this.scheduleValueSearch(e,!0)}}scheduleValueSearch(e,t=!1){this.valueSearchDebounceTimer!==null&&(window.clearTimeout(this.valueSearchDebounceTimer),this.valueSearchDebounceTimer=null);const i=this.valueSearchQuery;if(!i){this.valueSearchSeq++,this.valueSearchResults=null,this.repaintCategoricalList(e);return}const s=async()=>{const r=++this.valueSearchSeq,o=this.spreadsheetVisualizer?.getDataProvider(),l=this.currentColumn;if(!o||!l)return;let a=this.valueSearchUseRegex?"regex":"substring";if(a==="regex")try{new RegExp(i,"i")}catch{a="substring"}try{const h=await o.searchColumnValues(l,{query:i,mode:a,limit:ni.VALUE_SEARCH_LIMIT});if(r!==this.valueSearchSeq)return;this.valueSearchResults=h}catch(h){if(r!==this.valueSearchSeq)return;console.error("searchColumnValues failed:",h),this.valueSearchResults=[]}this.repaintCategoricalList(e)};t?s():this.valueSearchDebounceTimer=window.setTimeout(s,180)}repaintCategoricalList(e){const t=this.container.querySelector(".column-stats__filter-list");if(!t)return;let i;this.valueSearchResults!==null?i=this.valueSearchResults:i=Array.from(e.valueCounts.entries()).map(([r,o])=>({value:r,count:o})),t.innerHTML=this.buildCategoricalListItems(i);const s=this.container.querySelector(".column-stats__filter-search-summary");if(s)if(this.valueSearchResults!==null){const r=i.length,o=r>=ni.VALUE_SEARCH_LIMIT;s.textContent=o?`${r} matches (capped at ${ni.VALUE_SEARCH_LIMIT}; narrow the query for more)`:`${r} match${r===1?"":"es"}`}else s.textContent=""}
110formatNum(e){return e==null||!isFinite(e)||isNaN(e)?"NULL":e.toLocaleString(void 0,{minimumFractionDigits:2,maximumFractionDigits:2})}renderStats(e){if(!e)return"";const t=this.currentColumn?.dataType,i=[["Total Count",e.totalCount.toLocaleString()],["Null Count",e.nullCount.toLocaleString()],["Distinct",e.distinctCount.toLocaleString()]];if(t&&ht(t)&&e.numericStats){const s=e.numericStats;i.push(["Min",this.formatNum(s.min)],["Mean",this.formatNum(s.mean)],["Median",this.formatNum(s.median)],["Std",this.formatNum(s.stdDev)],["Max",this.formatNum(s.max)])}else if(t&&Li(t)&&e.temporalStats){const s=us(e.temporalStats.min,t),r=us(e.temporalStats.max,t);i.push(["Min",this.displayValue(s)],["Max",this.displayValue(r)])}return` 111 <table class="column-stats__table"> 112 <tbody> 113 ${i.map(([s,r])=>` 114 <tr> 115 <td class="column-stats__table-label">${Me(s)}</td> 116 <td class="column-stats__table-value">${Me(r)}</td> 117 </tr> 118 `).join("")} 119 </tbody> 120 </table> 121 `}renderVisualization(e){const t=this.currentColumn?.dataType;if(t&&ht(t))return this.renderNumericalHistogram(e);if(t&&Li(t))return this.renderTemporalHistogram(e);if(!e.valueCounts||e.valueCounts.size===0)return"";const i=Math.max(...Array.from(e.valueCounts.values())),s=e.valueCounts.size,r=Math.max(0,e.distinctCount-s);return` 122 <div class="histogram__container"> 123 <div class="histogram__title">Top ${s} Most Frequent</div> 124 <div class="histogram__chart"> 125 ${Array.from(e.valueCounts.entries()).map(([o,l])=>{const a=e.valueCountsRaw?.get(o),h=a!==void 0?this.displayValue(a):o,c=h.length>24?h.substring(0,24)+"â¦":h,u=(l/e.totalCount*100).toFixed(1),f=l/i*100;return` 126 <div class="histogram__row"> 127 <div class="histogram__label" title="${Je(h)}">${Me(c)}</div> 128 <div class="histogram__bar-track"> 129 <div class="histogram__bar-fill" style="width: ${f}%"></div> 130 </div> 131 <div class="histogram__count">${l.toLocaleString()} <span class="histogram__pct">${u}%</span></div> 132 </div> 133 `}).join("")} 134 </div> 135 ${r>0?`<div class="histogram__footer">${r.toLocaleString()} more distinct values</div>`:""} 136 </div> 137 `}renderNumericalHistogram(e){if(!e.valueCounts||e.valueCounts.size===0)return"";const t=Array.from(e.valueCounts.entries()),i=Math.max(...t.map(([,o])=>
137o)),s=e.numericStats?this.formatNum(e.numericStats.min):"",r=e.numericStats?this.formatNum(e.numericStats.max):"";return` 138 <div class="histogram__container"> 139 <div class="histogram__title">Distribution</div> 140 <div class="histogram__chart histogram__chart--numerical"> 141 ${t.map(([o,l])=>{const a=i>0?l/i*100:0;return` 142 <div class="histogram__numerical-bar" title="${Je(o+` 143`+l.toLocaleString())}"> 144 <div class="histogram__numerical-bar-fill" style="height: ${a}%"></div> 145 </div> 146 `}).join("")} 147 </div> 148 <div class="histogram__axis"> 149 <span>${Me(s)}</span> 150 <span>${Me(r)}</span> 151 </div> 152 </div> 153 `}renderTemporalHistogram(e){if(!e.valueCounts||e.valueCounts.size===0)return"";const t=Array.from(e.valueCounts.entries()),i=Math.max(...t.map(([,l])=>l)),s=this.currentColumn?.dataType,r=s&&e.temporalStats?this.displayValue(us(e.temporalStats.min,s)):"",o=s&&e.temporalStats?this.displayValue(us(e.temporalStats.max,s)):"";return` 154 <div class="histogram__container"> 155 <div class="histogram__title">Distribution</div> 156 <div class="histogram__chart histogram__chart--numerical"> 157 ${t.map(([l,a])=>{const h=i>0?a/i*100:0;return` 158 <div class="histogram__numerical-bar" title="${Je(l+` 159`+a.toLocaleString())}"> 160 <div class="histogram__numerical-bar-fill" style="height: ${h}%"></div> 161 </div> 162 `}).join("")} 163 </div> 164 <div class="histogram__axis"> 165 <span>${Me(r)}</span> 166 <span>${Me(o)}</span> 167 </div> 168 </div> 169 `}copyToClipboard(e,t){if(!e)return;const i=navigator.clipboard?.writeText?.(e);i?i.then(()=>this.flashCopied(t)).catch(s=>{console.warn("ColumnStatsVisualizer: clipboard write failed",s)}):console.warn("ColumnStatsVisualizer: clipboard API unavailable")}flashCopied(e){e.classList.add("column-stats__copied"),window.setTimeout(()=>e.classList.remove("column-stats__copied"),700)}}function Je(n){return Me(n).replace(/"/g,""")}function rl(n){return isFinite(n)?Number(n.toFixed(4)).toString():""}function us(n,e){return isFinite(n)?He(e)?new Date(n*86400*1e3):Qt(e)?n:dt(e)?new Date(n/1e3):n:null}function Pt(n,e,t){return n<e?e:n>t?t:n}function Nf(){if(typeof window>"u")return 1;const n=window.devicePixelRatio;return Number.isFinite(n)&&n>0?n:1}const Pn="â¦",ol=4096;let yt=new Map,Sr="";function ll(n,e){const t=`${n}|${e}`;t!==Sr&&(Sr=t,yt.clear())}function al(n,e,t){if(t<=0||e.length===0)return"";const i=`${Sr}|${t}|${e}`,s=yt.get(i);if(s!==void 0)return yt.delete(i),yt.set(i,s),s;let r;if(n.measureText(e).width<=t)r=e;else{const o=n.measureText(Pn).width;if(o>t)r="";else{const l=t-o;let a=0,h=e.length;for(;a<h;){const c=a+h+1>>1;n.measureText(e.slice(0,c)).width<=l?a=c:h=c-1}r=a===0?Pn:e.slice(0,a)+Pn}}if(yt.size>=ol){const o=ol>>2,l=yt.keys();for(let a=0;a<o;a++){const h=l.next().value;if(h===void 0)break;yt.delete(h)}}return yt.set(i,r),r}class hh{entries=[];inFlight=new Map;datasetTotalRows=0;initialCacheSize;cacheChunkSize;maxCacheSize;dataProvider;listeners=[];accessTick=0;constructor(e,t){this.dataProvider=e,this.initialCacheSize=t.initialCacheSize??ih,this.cacheChunkSize=t.cacheChunkSize??sh,this.maxCacheSize=t.maxCacheSize??nh,this.maxCacheSize=Math.max(this.maxCacheSize,this.initialCacheSize+this.cacheChunkSize)}async initialize(e){if(this.datasetTotalRows=e,e===0)return;const t=Math.min(this.initialCacheSize,this.datasetTotalRows);await this.loadChunk(0,t)}getDataSync(e,t){const i={rows:[],hasMissing:!1};if(e>=this.datasetTotalRows||t<=e)return i;t=Math.min(t,this.datasetTotalRows);const s=++this.accessTick,r=t-e;i.rows=new Array(r);for(let o=0;o<r;o++)i.rows[o]=null;for(const o of this.entries){const l=o.range;if(l.end<=e)continue;if(l.start>=t)break;const a=Math.max(l.start,e),h=Math.min(l.end,t);for(let c=a;c<h;c++)i.rows[c-e]=o.rows[c-l.start];o.lastAccessed=s}for(let o=0;o<r;o++)if(i.rows[o]===null){i.hasMissing=!0;break}return i}async getData(e,t){return e>=this.datasetTotalRows||t<=e?[]:(t=Math.min(t,this.datasetTotalRows),await this.loadChunk(e,t),this.getDataSync(e,t).rows.filter(s=>s!==null))}async getValue(e,t){return(await this.getData(e,e+1))[0]?.[t]}requestRange(e,t){if(e>=this.datasetTotalRows||t<=e)return;t=Math.min(t,this.datasetTotalRows);const i=this.getMissingRanges(e,t);for(const s of i){const r=`${s.start}-${s.end}`;if(this.inFlight.has(r))continue;const o=this.dataProvider.fetchData(s.start,s.end).then(l=>{this.insertEntry({range:s,rows:l,lastAccessed:++this.accessTick}),this.evictIfOverCap(),this.inFlight.delete(r);for(const a of this.listeners)a(s)}).catch(l=>{this.inFlight.delete(r),console.error(`Cache fetch failed for rows ${s.start}-${s.end}:`,l)});this.inFlight.set(r,o)}}onLoaded(e){return this.listeners.push(e),()=>{const t=this.listeners.indexOf(e);t>=0&&this.listeners.splice(t,1)}}async loadChunk(e,t){const i=this.getMissingRanges(e,t);i.length!==0&&await Promise.all(i.map(s=>{const r=`${s.start}-${s.end}`,o=this.inFlight.get(r);if(o)return o;const l=this.dataProvider.fetchData(s.start,s.end).then(a=>{this.insertEntry({range:s,rows:a,lastAccessed:++this.accessTick}),this.evictIfOverCap(),this.inFlight.delete(r);for(const h of this.listeners)h(s)}).catch(a=>{throw this.inFlight.delete(r),a});return this.inFlight.set(r,l),l}))}evictIfOverCap(){let e=this.getCachedRows();if(e<=this.maxCacheSize)return;const t=this.entries.slice().sort((i,s)=>i.lastAccessed-s.lastAccessed);for(const i of t){if(e<=this.maxCacheSize)break;const s=this.entries.indexOf(i);s>=0&&this.entries.splice(s,1),e-=i.range.end-i.range.start}}getCacheStats(){return{cacheSize:this.entries.length,ranges:this.entries.map(e=>e.range),totalRows:this.datasetTotalRows,initialCacheSize:this.initialCacheSize,cacheChunkSize:this.cacheChunkSize,maxCacheSize:this.maxCacheSize,cachedRows:this.getCachedRows(),isLoading:this.inFlight.size>0}}clear(){this.entries=[],this.inFlight.clear(),this.listeners=[]}getCachedRows(){let e=0;for(const t of this.entries)e+=t.range.end-t.range.start;return e}getMissingRanges(e,t){const i=this.cacheChunkSize;if(t-e<i&&(t=Math.min(this.datasetTotalRows,e+i)),this.entries.length===0)return[{start:e,end:t}];const s=[];for(const o of this.entries){const l=o.range;if(e<l.start){if(t<=l.start)return t=Math.min(l.start,e+i),s.push({start:e,end:t}),s;if(s.push({start:e,end:l.start}),t<=l.end)return s;e=l.end}else if(e<l.end){if(t<=l.end)return s;e=l.end,t=Math.min(this.datasetTotalRows,Math.max(t,l.end+i))}}const r=this.entries[this.entries.length-1].range;return e>=r.end&&e<this.datasetTotalRows&&s.push({start:e,end:Math.min(this.datasetTotalRows,Math.max(t,e+i))}),s}insertEntry(e){let t=0;for(;t<this.entries.length&&this.entries[t].range.start<e.range.start;)t++;this.entries.splice(t,0,e)}}class Bf{container;host;handles=[];dragging=null;moveListener=null;upListener=null;constructor(e,t){this.host=t,this.container=document.createElement("div"),this.container.className="spreadsheet-resize-handles",this.container.style.cssText="position:absolute;top:0;left:0;width:0;height:0;pointer-events:none;",e.appendChild(this.container)}relayout(){const e=this.host.getColWidths(),t=this.host.getColOffsets(),i=this.host.getScrollX(),s=this.host.getHeaderHeight(),r=this.host.getViewportHe
169ight(),o=this.host.getRowHeaderWidth();this.ensurePoolSize(e.length);const l=Math.max(0,r-s);for(let a=0;a<e.length;a++){const h=this.handles[a],c=t[a]+e[a],u=c-i-2,f=c-i>=o;h.style.display=f?"block":"none",h.style.left=`${u}px`,h.style.top=`${s}px`,h.style.height=`${l}px`}}destroy(){this.endDrag();for(const e of this.handles)e.remove();this.handles.length=0,this.container.remove()}ensurePoolSize(e){for(;this.handles.length<e;){const t=this.makeHandle(this.handles.length);this.handles.push(t),this.container.appendChild(t)}for(;this.handles.length>e;)this.handles.pop().remove()}makeHandle(e){const t=document.createElement("div");return t.className="spreadsheet-resize-handle",t.style.cssText="position:absolute;width:4px;cursor:col-resize;pointer-events:auto;",t.dataset.col=String(e),t.addEventListener("pointerdown",i=>this.startDrag(i,e)),t}startDrag(e,t){e.preventDefault(),e.stopPropagation();const i=this.host.getColWidths();t<0||t>=i.length||(this.dragging={col:t,startClientX:e.clientX,startWidth:i[t]},this.handles[t].classList.add("is-dragging"),this.moveListener=s=>this.onMove(s),this.upListener=s=>this.onUp(s),document.addEventListener("pointermove",this.moveListener),document.addEventListener("pointerup",this.upListener),document.body.style.cursor="col-resize",document.body.style.userSelect="none")}onMove(e){if(!this.dragging)return;const t=e.clientX-this.dragging.startClientX,i=this.host.getMinCellWidth(),s=Math.max(i,this.dragging.startWidth+t);this.host.applyColumnResize(this.dragging.col,s),this.relayout()}onUp(e){this.endDrag()}endDrag(){if(this.moveListener&&(document.removeEventListener("pointermove",this.moveListener),this.moveListener=null),this.upListener&&(document.removeEventListener("pointerup",this.upListener),this.upListener=null),this.dragging){const e=this.handles[this.dragging.col];e&&e.classList.remove("is-dragging")}this.dragging=null,document.body.style.cursor="",document.body.style.userSelect=""}}var K=(n=>(n[n.None=0]="None",n[n.CellHover=1]="CellHover",n[n.RowHover=2]="RowHover",n[n.ColHover=3]="ColHover",n[n.Selection=4]="Selection",n[n.Cells=5]="Cells",n))(K||{}),Yt=(n=>(n[n.Idle=0]="Idle",n[n.Dragging=1]="Dragging",n[n.Hovering=2]="Hovering",n[n.HoveringVerticalScrollbar=3]="HoveringVerticalScrollbar",n[n.HoveringHorizontalScrollbar=4]="HoveringHorizontalScrollbar",n[n.DraggingVerticalScrollbar=5]="DraggingVerticalScrollbar",n[n.DraggingHorizontalScrollbar=6]="DraggingHorizontalScrollbar",n))(Yt||{});class _f{container;scrollContainer;scrollSpacer;canvasGroup;canvas;selectionCanvas;hoverCanvas;ctx;selectionCtx;hoverCtx;dataProvider;metadata=null;columns;totalRows;totalCols;options;scrollX=0;scrollY=0;cache;colWidths=[];colOffsets=[];totalWidth=0;totalHeight=0;totalScrollY=0;totalScrollX=0;viewportWidth=0;viewportHeight=0;lastObservedClientWidth=0;lastObservedClientHeight=0;dpr=1;filterManager=null;datasetName="";themeCleanup=null;cellScratch=lh();resizeHandles;constructor(e,t,i={}){this.container=e,this.scrollContainer=document.createElement("div"),this.scrollContainer.style.cssText="overflow:auto;position:relative;width:100%;height:100%;outline:none;",this.scrollContainer.tabIndex=0,this.scrollSpacer=document.createElement("div"),this.scrollSpacer.style.cssText="position:relative;",this.canvasGroup=document.createElement("div"),this.canvasGroup.style.cssText="position:sticky;top:0;left:0;width:0;height:0;",this.canvas=document.createElement("canvas"),this.ctx=this.canvas.getContext("2d"),this.selectionCanvas=document.createElement("canvas"),this.selectionCanvas.style.cssText="position:absolute;top:0;left:0;pointer-events:none;",this.selectionCtx=this.selectionCanvas.getContext("2d",{alpha:!0}),this.hoverCanvas=document.createElement("canvas"),this.hoverCanvas.style.cssText="position:absolute;top:0;left:0;pointer-events:none;",this.hoverCtx=this.hoverCanvas.getContext("2d",{alpha:!0}),this.canvasGroup.appendChild(this.canvas),this.canvasGroup.appendChild(this.selectionCanvas),this.canvasGroup.appendChild(this.hoverCanvas),this.scrollSpacer.appendChild(this.canvasGroup),this.scrollContainer.appendChild(this.scrollSpacer),this.container.appendChild(this.scrollContainer),this.resizeHandles=new Bf(this.canvasGroup,{getColWidths:()=>this.colWidths,getColOffsets:()=>this.colOffsets,getHeaderHeight:()=>
169this.options.cellHeight,getViewportHeight:()=>this.viewportHeight,getScrollX:()=>this.scrollX,getMinCellWidth:()=>this.options.minCellWidth,getRowHeaderWidth:()=>this.options.rowHeaderWidth,applyColumnResize:(r,o)=>this.applyColumnResize(r,o)}),this.scrollContainer.addEventListener("scroll",()=>{this.scrollX=this.scrollContainer.scrollLeft,this.scrollY=this.scrollContainer.scrollTop,this.preloadDataForScroll(this.scrollY),this.updateToDraw(5),this.scheduleDraw(),this.resizeHandles.relayout()}),this.scrollContainer.addEventListener("keydown",r=>{["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Home","End","PageUp","PageDown"].includes(r.key)&&r.preventDefault()}),this.dataProvider=t,this.columns=[],this.totalRows=0,this.totalCols=0;const s=$s();this.options={maxHeight:i.maxHeight??tf,maxWidth:i.maxWidth??sf,minHeight:i.minHeight??nf,minWidth:i.minWidth??rf,height:i.height??this.container.clientHeight,width:i.width??this.container.clientWidth,cellHeight:i.cellHeight??of,minCellWidth:i.minCellWidth??lf,maxCellWidth:i.maxCellWidth??af,maxStringLength:i.maxStringLength??hf,cellPadding:i.cellPadding??cf,rowHeaderWidth:i.rowHeaderWidth??uf,textRendering:i.textRendering??mr,letterSpacing:i.letterSpacing??gr,imageSmoothingEnabled:i.imageSmoothingEnabled??yr,imageSmoothingQuality:i.imageSmoothingQuality??br,borderWidth:i.borderWidth??ff,fontFamily:i.fontFamily??df,fontSize:i.fontSize??pf,headerFontSize:i.headerFontSize??mf,headerBackgroundColor:i.headerBackgroundColor??s.headerBackgroundColor,headerTextColor:i.headerTextColor??s.headerTextColor,cellBackgroun
169dColor:i.cellBackgroundColor??s.cellBackgroundColor,cellTextColor:i.cellTextColor??s.cellTextColor,stripeBackgroundColor:i.stripeBackgroundColor??s.stripeBackgroundColor,borderColor:i.borderColor??s.borderColor,selectionColor:i.selectionColor??s.selectionColor,selectionBorderColor:i.selectionBorderColor??s.selectionBorderColor,hoverColor:i.hoverColor??s.hoverColor,hoverBorderColor:i.hoverBorderColor??s.hoverBorderColor,scrollbarWidth:i.scrollbarWidth??gf,scrollbarColor:i.scrollbarColor??s.scrollbarColor,scrollbarThumbColor:i.scrollbarThumbColor??s.scrollbarThumbColor,scrollbarHoverColor:i.scrollbarHoverColor??s.scrollbarHoverColor,dateFormat:i.dateFormat??bf,datetimeFormat:i.datetimeFormat??wf,datetimeLocale:i.datetimeLocale??xf,numberFormat:i.numberFormat??Cf,naText:i.naText??Za,trueText:i.trueText??eh,falseText:i.falseText??th,textAlign:i.textAlign??yf,maxFormatGuessLength:i.maxFormatGuessLength??Sf,percentFormatGuessFit:i.percentFormatGuessFit??vf,initialCacheSize:i.initialCacheSize??ih,cacheChunkSize:i.cacheChunkSize??sh,maxCacheSize:i.maxCacheSize??nh,cacheTimeToLive:i.cacheTimeToLive??kf},this.cache=new hh(this.dataProvider,this.options),this.options.height=Pt(this.options.height,this.options.minHeight,this.options.maxHeight),this.options.width=Pt(this.options.width,this.options.minWidth,this.options.maxWidth),this.installContainerObservers(),this.attachCacheListener()}cacheLoadedUnsubscribe=null;attachCacheListener(){this.cacheLoadedUnsubscribe?.(),this.cacheLoadedUnsubscribe=this.cache.onLoaded(()=>{this.updateToDraw(5),this.scheduleDraw()})}resizeObserver=null;dprMediaQuery=null;dprChangeHandler=null;installContainerObservers(){typeof window>"u"||(typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>{(this.scrollContainer.clientWidth!==this.lastObservedClientWidth||this.scrollContainer.clientHeight!==this.lastObservedClientHeight)&&this.requestRelayout()}),this.resizeObserver.observe(this.container),this.resizeObserver.observe(this.scrollContainer)),this.armDprListener())}armDprListener(){this.disarmDprListener();const e=this.dpr||1;try{this.dprMediaQuery=window.matchMedia(`(resolution: ${e}dppx)`),this.dprChangeHandler=()=>{this.armDprListener(),this.requestRelayout()},this.dprMediaQuery.addEventListener("change",this.dprChangeHandler)}catch{this.dprMediaQuery=null,this.dprChangeHandler=null}}disarmDprListener(){this.dprMediaQuery&&this.dprChangeHandler&&this.dprMediaQuery.removeEventListener("change",this.dprChangeHandler),this.dprMediaQuery=null,this.dprChangeHandler=null}requestRelayout(){const e=this.handleResize;e&&e.call(this).catch(t=>console.error("handleResize failed:",t))}pendingDraw=null;scheduleDraw(){this.pendingDraw===null&&(this.pendingDraw=requestAnimationFrame(()=>{this.pendingDraw=null,this.draw().catch(e=>console.error("draw failed:",e))}))}cancelScheduledDraw(){this.pendingDraw!==null&&(cancelAnimationFrame(this.pendingDraw),this.pendingDraw=null)}destroyBase(){this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),this.disarmDprListener(),this.cancelScheduledDraw(),this.cacheLoadedUnsubscribe?.(),this.cacheLoadedUnsubscribe=null}updateToDraw(e){}async draw(){}scrollTo(e,t){this.scrollContainer.scrollLeft=Math.max(0,Math.min(e,this.totalScrollX)),this.scrollContainer.scrollTop=Math.max(0,Math.min(t,this.totalScrollY))}scrollCellIntoView(e,t){const i=e*this.options.cellHeight,s=t<this.colOffsets.length?this.colOffsets[t]:0,r=t<this.colWidths.length?this.colWidths[t]:0,o=this.options.cellHeight,l=this.options.cellHeight;let a=this.scrollY,h=this.scrollX;i<this.scrollY+l?a=i-l:i+o>this.scrollY+this.viewportHeight&&(a=i+o-this.viewportHeight);const c=this.options.rowHeaderWidth;s<this.scrollX+c?h=s-c:s+r>this.scrollX+this.viewportWidth&&(h=s+r-this.viewportWidth),(h!==this.scrollX||a!==this.scrollY)&&this.scrollTo(h,a)}getContainer(){return this.container}getOptions(){return this.options}getDataProvider(){return this.dataProvider}setFilterManager(e,t){this.filterManager=e,this.datasetName=t}async refreshFormat(e){e.dateFormat!==void 0&&(this.options.dateFormat=e.dateFormat),e.datetimeFormat!==void 0&&(this.options.datetimeFormat=e.datetimeFormat),e.datetimeLocale!==void 0&&(this.options.datetimeLocale=e.datetimeLocale),e.numberFormat!==void 0&&(this.options.numberFormat=e.numberFormat),e.minCellWidth!==void 0&&(this.options.minCellWidth=e.minCellWidth),e.maxStringLength!==void 0&&(this.options.maxStringLength=e.maxStringLength);for(const t of this.columns)t.cachedFormatter=null,t.guessedFormat=go(t,this.options);await this.calculateColumnWidths(),this.updateToDraw(5),await this.draw()}guessColumnWidths(e,t,i){const s=this.options.maxStringLength,r=[this.ctx.measureText(t.name).width+this.options.cellPadding*2],o=this.cellScratch;for(const c of e){xr(c[i],this.columns[i],this.options,o),this.ctx.textAlign=o.textAlign;const u=o.formatted,f=s>0&&u.length>s?u.slice(0,s):u,d=this.ctx.measureText(f).width+this.options.cellPadding*2;r.push(d)}const l=r.sort((c,u)=>c-u),a=Math.floor(l.length*this.options.percentFormatGuessFit),h=l[a];return Pt(h,this.options.minCellWidth,this.options.maxCellWidth)}yieldToBrowser(){return new Promise(e=>{setTimeout(e,0)})}async calculateColumnWidths(){this.ctx.font=`${this.options.fontSize}px ${this.options.fontFamily}`,this.ctx.textAlign="left",this.ctx.textRendering=this.options.textRendering??mr,this.ctx.letterSpacing=this.options.letterSpacing??gr,this.ctx.imageSmoothingEnabled=this.options.imageSmoothingEnabled??yr,this.ctx.imageSmoothingQuality=this.options.imageSmoothingQuality??br;const e=Math.min(this.options.maxFormatGuessLength,this.totalRows),t=await this.cache.getData(0,e);this.colWidths.length!==this.columns.length&&(this.colWidths=this.columns.map(o=>o.widthPx||this.options.minCellWidth));const i=16,s=this.columns.length,r=this.filterManager!==null&&this.filterManager.getSorts(this.datasetName).length>1;for(let o=0;o<s;o+=i){const l=Math.min(o+i,s);for(let a=o;a<l;a++){const h=this.columns[a];h.widthPx=this.guessColumnWidths(t,h,a);let c=16;this.filterManager&&(this.filterManager.isColumnSorted(this.datasetName,h.name)&&r&&(c+=12),this.filterManager.isColumnFiltered(this.datasetName,h.name)&&(c+=10)),h.widthPx=Math.min(h.widthPx+c,this.options.maxCellWidth),this.colWidths[a]=h.widthPx}this.recomputeLayoutFromWidths(),l<s&&(this.updateToDraw(5),this.scheduleDraw(),await this.yieldToBrowser())}}recomputeLayoutFromWidths(){this.colOffsets=[this.options.rowHeaderWidth];for(let e=1;e<this.columns.length;e++)this.colOffsets.push(this.colOffsets[e-1]+this.colWidths[e-1]);this.totalWidth=(this.colOffsets[this.colOffsets.length-1]||0)+(this.colWidths[this.colWidths.length-1]||0),this.totalScrollX=Math.max(0,this.totalWidth-this.viewportWidth),this.scrollSpacer.style.width=`${Math.max(this.totalWidth,this.viewportWidth)}px`,this.resizeHandles?.relayout()}applyColumnResize(e,t){if(e<0||e>=this.colWidths.length)return;const i=Math.max(this.options.minCellWidth,t);this.colWidths[e]!==i&&(this.colWidths[e]=i,this.recomputeLayoutFromWidths(),this.updateToDraw(5),this.scheduleDraw())}calculateRowHeight(){this.totalHeight=(this.totalRows+1)*this.options.cellHeight,this.totalScrollY=Math.max(0,this.totalHeight-this.viewportHe
169ight);const e=Math.max(0,this.lastObservedClientHeight-this.viewportHeight);this.scrollSpacer.style.height=`${Math.max(this.totalHeight+e,this.viewportHeight)}px`}async preloadDataForScroll(e){const t=Math.floor(e/this.options.cellHeight),i=Math.min(t+Math.ceil(this.viewportHeight/this.options.cellHeight),this.totalRows),s=this.options.cacheChunkSize,r=Math.max(0,t-s),o=Math.min(this.totalRows,i+s);this.cache.loadChunk(r,o).catch(console.error)}isMouseOverColumnHeader(e,t){return e>=this.options.rowHeaderWidth&&t<this.options.cellHeight}isMouseOverRowIndex(e,t){return e<=this.options.rowHeaderWidth}getFirstVisibleColumnIndex(){if(this.colOffsets.length===0)return 0;let e=0,t=this.colOffsets.length-1;for(;e<t;){const i=e+t+1>>1;this.colOffsets[i]<=this.scrollX?e=i:t=i-1}return e}getLastVisibleColumnIndex(){if(this.colOffsets.length===0)return 0;const e=this.scrollX+this.viewportWidth;let t=0,i=this.colOffsets.length-1;for(;t<i;){const s=t+i>>1;this.colOffsets[s]+this.colWidths[s]<=e?t=s+1:i=s}return t}getCellAtPosition(e,t){const i=e+this.scrollX,s=t+this.scrollY;if(i<this.options.rowHeaderWidth){const a=Math.floor(s/this.options.cellHeight);return a>=0&&a<this.totalRows?{row:a,col:-1}:null}let r=this.options.rowHeaderWidth,o=0;for(;o<this.colWidths.length&&!(i<r+this.colWidths[o]);o++)r+=this.colWidths[o];const l=Math.floor(s/this.options.cellHeight);return l>=0&&l<=this.totalRows&&o<this.totalCols?{row:l,col:o}:null}drawCells(e,t){const i=this.cache.getDataSync(e,t);i.hasMissing&&this.cache.requestRange(e,t);const s=this.ctx,r=this.options,o=this.viewportWidth,l=this.viewportHeight,a=r.cellHeight,h=r.rowHeaderWidth,c=r.cellPadding,u=this.getFirstVisibleColumnIndex(),f=Math.min(this.getLastVisibleColumnIndex(),this.columns.length-1);
169s.clearRect(0,0,o,l),s.fillStyle=r.cellBackgroundColor,s.fillRect(h,a,o-h,l-a),s.fillStyle=r.headerBackgroundColor,s.fillRect(0,0,o,a),s.fillRect(0,0,h,l);const d=r.stripeBackgroundColor;if(d&&d!==r.cellBackgroundColor){s.fillStyle=d;let D=a;for(let O=e;O<t;O++)(O&1)===1&&s.fillRect(h,D,o-h,a),D+=a}const p=`${r.fontSize}px ${r.fontFamily}`;s.font=p,s.letterSpacing=r.letterSpacing,ll(p,r.letterSpacing),s.textBaseline="middle";const m=this.cellScratch,g=r.maxStringLength;let y=a;for(let D=0;D<i.rows.length;D++){const O=i.rows[D];if(O===null){s.fillStyle=r.headerBackgroundColor,s.fillRect(h,y,o-h,a),s.fillStyle=r.cellBackgroundColor,s.fillRect(h+c,y+a*.38,Math.min(80,o-h-c*2),a*.24),y+=a;continue}let B=this.colOffsets[u]-this.scrollX;for(let _=u;_<=f;_++){const V=this.colWidths[_],ve=this.columns[_];xr(O[_],ve,r,m),m.backgroundColor&&m.backgroundColor!==r.cellBackgroundColor&&(s.fillStyle=m.backgroundColor,s.fillRect(B,y,V,a));const ke=m.textAlign;s.textAlign=ke,s.fillStyle=m.textColor||r.cellTextColor;let Ve=B+c;ke==="center"?Ve=B+V/2:ke==="right"&&(Ve=B+V-c);const Ie=y+a/2,$e=m.formatted,ge=g>0&&$e.length>g?$e.slice(0,g)+"â¦":$e,le=V-c*2,J=al(s,ge,le);J.length>0&&s.fillText(J,Math.round(Ve),Math.round(Ie)),B+=V}y+=a}const b=`${r.headerFontSize}px ${r.fontFamily}`;s.font=b,ll(b,r.letterSpacing),s.textBaseline="middle",s.textAlign="left";const C=a/2;let k=this.colOffsets[u]-this.scrollX;for(let D=u;D<=f;D++){const O=this.columns[D],B=this.colWidths[D];let _=null,V=null,ve=!1,ke=!1;this.filterManager&&(_=this.filterManager.isColumnSorted(this.datasetName,O.name),V=this.filterManager.getSortPosition(this.datasetName,O.name),ve=this.filterManager.getSorts(this.datasetName).length>1,ke=this.filterManager.isColumnFiltered(this.datasetName,O.name));const Ve=O.hasNulls===!0,Ie=_!==null&&ve&&V!==null;let $e=16;Ie&&($e+=12),ke&&($e+=10),Ve&&($e+=10);const ge=Math.max(0,B-c*2-$e),le=al(s,O.name,ge);ge>0&&le.length>0&&(s.fillStyle=r.headerTextColor,s.fillText(le,Math.round(k+c),Math.round(C)));let J=k+B-c;const Q=5;s.fillStyle=r.headerTextColor;const ue=J-Q;_?(s.beginPath(),_==="asc"?(s.moveTo(ue-Q,C+Q/2),s.lineTo(ue,C-Q/2),s.lineTo(ue+Q,C+Q/2)):(s.moveTo(ue-Q,C-Q/2),s.lineTo(ue,C+Q/2),s.lineTo(ue+Q,C-Q/2)),s.closePath(),s.fill()):(s.save(),s.globalAlpha=.28,s.beginPath(),s.moveTo(ue-Q,C+Q/2),s.lineTo(ue,C-Q/2),s.lineTo(ue+Q,C+Q/2),s.closePath(),s.fill(),s.restore()),J-=16,Ie&&(s.save(),s.font=`9px ${r.fontFamily}`,s.fillStyle=r.headerTextColor,s.globalAlpha=.7,s.textAlign="right",s.fillText(String(V),Math.round(J),Math.round(C)),s.restore(),J-=12),ke&&(s.fillStyle=r.selectionBorderColor,s.beginPath(),s.arc(J-4,C,3,0,2*Math.PI),s.fill(),J-=10),Ve&&(s.fillStyle=r.headerTextColor,s.textAlign="right",s.globalAlpha=.55,s.fillText("·",Math.round(J),Math.round(C)),s.globalAlpha=1,s.textAlign="left"),k+=B}s.fillStyle=r.headerBackgroundColor,s.fillRect(0,0,h,l),s.fillStyle=r.headerTextColor,s.textAlign="right";const x=h-c;let T=a;for(let D=e;D<t;D++)s.fillText((D+1).toString(),Math.round(x),Math.round(T+a/2)),T+=a;const v=$s();s.strokeStyle=r.borderColor,s.lineWidth=1,s.beginPath(),v.headerBottomRuleColor||(s.moveTo(0,a+.5),s.lineTo(o,a+.5));let I=a*2;for(let D=e;D<t;D++)s.moveTo(0,I+.5),s.lineTo(o,I+.5),I+=a;const z=I-a;s.stroke();const q=v.verticalGridColor==="transparent"?null:v.verticalGridColor??r.borderColor;if(q!==null){s.strokeStyle=q,s.lineWidth=1,s.beginPath(),s.moveTo(h+.5,0),s.lineTo(h+.5,l);let D=this.colOffsets[u]-this.scrollX;for(let O=u;O<=f;O++)D+=this.colWidths[O],D>h&&(s.moveTo(D+.5,0),s.lineTo(D+.5,l));s.stroke()}v.headerTopRuleColor&&(s.strokeStyle=v.headerTopRuleColor,s.lineWidth=2,s.beginPath(),s.moveTo(0,1),s.lineTo(o,1),s.stroke()),v.headerBottomRuleColor&&(s.strokeStyle=v.headerBottomRuleColor,s.lineWidth=1,s.beginPath(),s.moveTo(0,a+.5),s.lineTo(o,a+.5),s.stroke()),v.frameBottomRuleColor&&t>e&&t>=this.totalRows&&(s.strokeStyle=v.frameBottomRuleColor,s.lineWidth=2,s.beginPath(),s.moveTo(0,z-1),s.lineTo(o,z-1),s.stroke())}}class Pf extends _f{hoveredCell=null;selectedCells=null;mouseState=Yt.Idle;toDraw=K.Cells;dragStartX=0;dragStartY=0;lastScrollX=0;lastScrollY=0;selectedRows=[];selectedCols=[];
169lastRowAnchor=null;lastColAnchor=null;statsVisualizer;onSelectionChange=[];constructor(e,t,i={},s){super(e,t,i),this.statsVisualizer=s}async updateLayout(){const e=this.scrollContainer.clientWidth,t=this.scrollContainer.clientHeight;this.lastObservedClientWidth=e,this.lastObservedClientHeight=t;let i=Math.floor(Pt(e,this.options.minWidth,this.options.maxWidth)),s=Math.floor(Pt(t,this.options.minHeight,this.options.maxHeight));const r=this.options.cellHeight;if(s>r){const c=Math.round((s-r)/r);s=r+c*r}i<=0&&this.options.width!==void 0&&(i=Math.floor(Pt(this.options.width,this.options.minWidth,this.options.maxWidth))),s<=0&&this.options.height!==void 0&&(s=Math.floor(Pt(this.options.height,this.options.minHeight,this.options.maxHeight))),i<=0&&(i=this.options.minWidth),s<=0&&(s=this.options.minHeight);const o=Nf();this.dpr=o,this.viewportWidth=i,this.viewportHeight=s;const l=Math.round(i*o),a=Math.round(s*o),h=[[this.canvas,this.ctx],[this.selectionCanvas,this.selectionCtx],[this.hoverCanvas,this.hoverCtx]];for(const[c,u]of h)c.width=l,c.height=a,c.style.width=`${i}px`,c.style.height=`${s}px`,u.setTransform(o,0,0,o,0,0);this.canvasGroup.style.width=`${i}px`,this.canvasGroup.style.height=`${s}px`,this.calculateColumnWidths(),this.calculateRowHeight(),this.updateToDraw(K.Cells),await this.draw()}
169async getSelectedFormattedValues(){const e=await this.getSelection();return e?{headers:e.columns.map(t=>t.name),indices:e.rows,data:e.formatted}:{headers:[],indices:[],data:[]}}updateToDraw(e){this.toDraw=Math.max(this.toDraw,e)}async draw(){const e=this.viewportHeight,t=Math.floor(this.scrollY/this.options.cellHeight),i=Math.min(t+Math.ceil(e/this.options.cellHeight),this.totalRows);this.ctx.textRendering=this.options.textRendering??mr,this.ctx.letterSpacing=this.options.letterSpacing??gr,this.ctx.imageSmoothingEnabled=this.options.imageSmoothingEnabled??yr,this.ctx.imageSmoothingQuality=this.options.imageSmoothingQuality??br,this.toDraw===K.ColHover?this.drawColHover():this.toDraw===K.RowHover?this.drawRowHover(t):(this.toDraw>=K.Cells&&(this.drawCells(t,i),this.lastCellHoverRect=null),this.toDraw>=K.Selection&&this.drawSelection(t),this.toDraw>=K.CellHover&&this.drawCellHover(t)),this.toDraw=K.None}async selectColumn(e,t={shift:!1,ctrl:!1}){if(t.shift&&this.lastColAnchor!==null){const i=Math.min(this.lastColAnchor,e),s=Math.max(this.lastColAnchor,e),r=[];for(let o=i;o<=s;o++)r.push(o);this.selectedCols=r,this.selectedRows=[],this.selectedCells=null}else t.ctrl?(this.selectedCols.includes(e)?this.selectedCols=this.selectedCols.filter(i=>i!==e):(this.selectedCols=[...this.selectedCols,e],this.selectedRows=[],this.selectedCells=null),this.lastColAnchor=e):(this.selectedCols=[e],this.selectedRows=[],this.selectedCells=null,this.lastColAnchor=e);this.statsVisualizer&&(this.selectedCols.length>0?await this.statsVisualizer.showStats(this.columns[this.selectedCols[0]]):this.statsVisualizer.hide()),this.updateToDraw(K.Selection),this.notifySelectionChange()}async selectRow(e,t){if(t.shift&&this.lastRowAnchor!==null){const i=Math.min(this.lastRowAnchor,e),s=Math.max(this.lastRowAnchor,e),r=[];for(let o=i;o<=s;o++)r.push(o);this.selectedRows=r,this.selectedCols=[],this.selectedCells=null}else t.ctrl?(this.selectedRows.includes(e)?this.selectedRows=this.selectedRows.filter(i=>i!==e):(this.selectedRows=[...this.selectedRows,e],this.selectedCols=[],this.selectedCells=null),this.lastRowAnchor=e):(this.selectedRows=[e],this.selectedCols=[],this.selectedCells=null,this.lastRowAnchor=e);this.updateToDraw(K.Selection),this.notifySelectionChange()}lastCellHoverRect=null;withCellAreaClip(e,t){const i=this.options.rowHeaderWidth;e.save(),e.beginPath(),e.rect(i,0,this.viewportWidth-i,this.viewportHeight),e.clip(),t(),e.restore()}strokeRectEdges(e,t,i,s,r,o=!1,l=!1){if(!o&&!l){e.strokeRect(t,i,s,r);return}e.beginPath(),o&&l?(e.moveTo(t,i),e.lineTo(t+s,i),e.lineTo(t+s,i+r)):o?(e.moveTo(t,i),e.lineTo(t+s,i),e.lineTo(t+s,i+r),e.lineTo(t,i+r)):(e.moveTo(t,i+r),e.lineTo(t,i),e.lineTo(t+s,i),e.lineTo(t+s,i+r)),e.stroke()}fillBoundaryLeftEdge(e,t,i,s){const r=e.fillStyle;e.fillStyle=e.strokeStyle,e.fillRect(t,i+1,2,s-2),e.fillStyle=r}drawCellHover(e){const t=this.lastCellHoverRect;if(t?this.hoverCtx.clearRect(t.x-3,t.y-3,t.w+6,t.h+6):this.hoverCtx.clearRect(0,0,this.viewportWidth,this.viewportHeight),this.lastCellHoverRect=null,!this.hoveredCell)return;const{row:i,col:s}=this.hoveredCell,r=(i-e)*this.options.cellHeight,o=this.options.cellHeight,l=this.options.rowHeaderWidth;let a=this.colOffsets[s]-this.scrollX,h=this.colWidths[s];if(a<l&&(a=l,h=this.colOffsets[s+1]-this.scrollX-l),h<=0)return;const c=a===l;this.withCellAreaClip(this.hoverCtx,()=>{this.hoverCtx.fillStyle=this.options.hoverColor,this.hoverCtx.strokeStyle=this.options.hoverBorderColor||this.options.borderColor,this.hoverCtx.fillRect(a,r,h,o),this.hoverCtx.lineWidth=2,this.strokeRectEdges(this.hoverCtx,a,r,h,o,c),this.hoverCtx.lineWidth=1,this.strokeRectEdges(this.hoverCtx,a+1,r+1,h-2,o-2,c),c&&this.fillBoundaryLeftEdge(this.hoverCtx,a,r,o)}),this.lastCellHoverRect={x:a,y:r,w:h,h:o}}drawColHover(){if(this.hoverCtx.clearRect(0,0,this.viewportWidth,this.viewportHeight),this.lastCellHoverRect=null,!this.hoveredCell)return;const{col:e}=this.hoveredCell,t=this.options.rowHeaderWidth,i=Math.min(this.totalHeight,this.hoverCanvas.height);let s=this.colOffsets[e]-this.scrollX,r=this.colWidths[e];
169s<t&&(s=t,r=this.colOffsets[e+1]-this.scrollX-t),!(r<=0)&&this.withCellAreaClip(this.hoverCtx,()=>{this.hoverCtx.fillStyle=this.options.hoverColor,this.hoverCtx.fillRect(s,0,r,i)})}drawRowHover(e){if(this.hoverCtx.clearRect(0,0,this.viewportWidth,this.viewportHeight),this.lastCellHoverRect=null,!this.hoveredCell)return;const{row:t}=this.hoveredCell;if(t<1)return;const i=this.options.cellHeight,s=this.options.cellHeight,r=Math.min(this.totalWidth,this.viewportWidth),o=(t-e)*i;if(o+i<=s||o>=this.viewportHeight)return;const l=Math.max(o,s),a=o+i-l;a<=0||(this.hoverCtx.fillStyle=this.options.hoverColor,this.hoverCtx.fillRect(0,l,r,a))}drawSelection(e){this.selectionCtx.clearRect(0,0,this.viewportWidth,this.viewportHeight),this.drawRowSelection(e),this.withCellAreaClip(this.selectionCtx,()=>{this.drawCellSelection(e),this.drawColSelection()})}drawRowSelection(e){if(this.selectedRows.length===0)return;this.selectionCtx.fillStyle=this.options.selectionColor;const t=this.options.cellHeight,i=this.options.cellHeight,s=Math.min(this.totalWidth,this.viewportWidth);this.selectedRows.forEach(r=>{const o=(r-e)*t;if(o+t<=i||o>=this.viewportHeight)return;const l=Math.max(o,i),a=o+t-l;a<=0||this.selectionCtx.fillRect(0,l,s,a)})}drawCellSelection(e){if(this.selectedCells){const{startRow:t,endRow:i,startCol:s,endCol:r}=this.selectedCells;this.selectionCtx.fillStyle=this.options.selectionColor;const o=Math.min(t,i),l=Math.max(t,i),a=Math.min(s,r),h=Math.max(s,r),c=this.options.cellHeight;let u={x:0,y:0,width:0,height:0};for(let f=o;f<=l;f++)for(let d=a;d<=h;d++){const p=(f-e)*this.options.cellHeight;let m=this.colOffsets[d]-this.scrollX,g=this.colWidths[d];m<this.options.rowHeaderWidth&&(m=this.options.rowHeaderWidth,g=this.colOffsets[d+1]-this.scrollX-this.options.rowHeaderWidth),m+g>0&&m<this.viewportWidth&&p+c>0&&p<this.viewportHeight&&(this.selectionCtx.fillRect(m,p,g,c),f===o&&d===a&&(u={x:m,y:p,width:0,height:0}),f===l&&d===h&&(u.width=m+g-u.x,u.height=p+c-u.y))}if(u.width>0&&u.height>0){this.selectionCtx.strokeStyle=this.options.selectionBorderColor||this.options.borderColor;const f=u,d=f.x===this.options.rowHeaderWidth;this.selectionCtx.lineWidth=2,this.strokeRectEdges(this.selectionCtx,f.x,f.y,f.width,f.height,d),this.selectionCtx.lineWidth=1,this.strokeRectEdges(this.selectionCtx,f.x+1,f.y+1,f.width-2,f.height-2,d),d&&this.fillBoundaryLeftEdge(this.selectionCtx,f.x,f.y,f.height);const p=8,m=u.x+u.width-p/8,g=u.y+u.height-p/8;this.selectionCtx.fillStyle=this.options.selectionBorderColor||this.options.borderColor,this.selectionCtx.beginPath(),this.selectionCtx.arc(m,g,p/2,0,2*Math.PI),this.selectionCtx.fill(),this.selectionCtx.strokeStyle="#ffffff",this.selectionCtx.lineWidth=1,this.selectionCtx.stroke()}}}drawColSelection(){if(this.selectedCols.length===0)return;this.selectionCtx.fillStyle=this.options.selectionColor;const e=this.options.rowHeaderWidth,t=Math.min(this.totalHeight,this.selectionCanvas.height);this.selectedCols.forEach(i=>{if(this.colOffsets[i+1]-this.scrollX<e)return;let s=this.colOffsets[i]-this.scrollX,r=this.colWidths[i];s<e&&(s=e,r=this.colOffsets[i+1]-this.scrollX-e),!(r<=0)&&this.selectionCtx.fillRect(s,0,r,t)})}async exportFullDataset(){if(this.totalRows===0||this.columns.length===0)return null;try{const e=await this.cache.getData(0,this.totalRows),t=e.map(s=>s.map((r,o)=>{const l=this.columns[o];return l?cs(r,l,this.options):""}));return{rows:Array.from({length:e.length},(s,r)=>r+1),columns:this.columns,values:e,formatted:t}}catch(e){return console.error("Failed to fetch full dataset for export:",e),null}}async getSelection(){if(this.selectedCols.length>0)try{const e=[...this.selectedCols].sort((l,a)=>l-a),t=await this.cache.getData(0,this.totalRows),i=t.map(l=>e.map(a=>l[a])),s=i.map(l=>l.map((a,h)=>{const c=this.columns[e[h]];return c?cs(a,c,this.options):""})),r=e.map(l=>this.columns[l]);return{rows:Array.from({length:t.length},(l,a)=>a+1),columns:r,values:i,formatted:s}}catch(e){return console.error("Failed to fetch column data for selection:",e),null}if(this.selectedRows.length>0)try{const e=[...this.selectedRows].sort((a,h)=>a-h),t=[];let i=e[0],s=e[0];for(let a=1;a<e.length;a++)e[a]===s+1||(t.push({start:i,end:s}),i=e[a]),s=e[a];t.push({start:i,end:s});const r=[],o=[];for(const a of t){const h=await this.cache.getData(a.start-1,a.end);for(let c=0;c<h.length;c++)r.push(h[c]),o.push(a.start+c)}const l=r.map(a=>a.map((h,c)=>{const u=this.columns[c];return u?cs(h,u,this.options):""}));return{rows:o,columns:this.columns,values:r,formatted:l}}catch(e){return console.error("Failed to fetch row data for selection:",e),null}if(this.selectedCells)try{const e=this.getFirstVisibleColumnIndex(),t=this.getLastVisibleColumnIndex(),i=(await this.cache.getData(this.selectedCells.startRow-1,this.selectedCells.endRow)).map(l=>l.slice(this.selectedCells?.startCol??e,(this.selectedCells?.endCol??t)+1)),s=i.map(l=>l.map((a,h)=>{const c=this.columns[h+this.selectedCells.startCol];return c?cs(a,c,this.options):""}
169)),r=Array.from({length:this.selectedCells.endRow-this.selectedCells.startRow+1},(l,a)=>this.selectedCells.startRow+a),o=this.columns.filter((l,a)=>this.selectedCells.startCol<=a&&a<=this.selectedCells.endCol);return{rows:r,columns:o,values:i,formatted:s}}catch(e){return console.error("Failed to fetch cell data for selection:",e),null}else return null}async notifySelectionChange(){const e=await this.buildSelectionSummary();this.onSelectionChange.forEach(t=>t(e))}async buildSelectionSummary(){if(this.selectedCols.length>0){const e=[...this.selectedCols].sort((t,i)=>t-i);return{rows:[],columns:e.map(t=>this.columns[t]).filter(Boolean),values:[],formatted:[]}}if(this.selectedRows.length>0){const e=[...this.selectedRows].sort((s,r)=>s-r);let t=[],i=[];try{const s=await this.cache.getData(e[0]-1,e[0]);if(s.length>0&&this.columns.length>0){const r=s[0][0];t=[[r]],i=[[ah(r,this.columns[0],this.options).formatted]]}}catch{}return{rows:e,columns:this.columns,values:t,formatted:i}}if(this.selectedCells)return await this.getSelection()??void 0}getHoveredCell(){return this.hoveredCell}getSelectedCells(){return this.selectedCells}getMouseState(){return this.mouseState}getSelectedRows(){return this.selectedRows}getSelectedCols(){return this.selectedCols}setHoveredCell(e){this.hoveredCell=e}setSelectedCells(e){this.selectedCells=e}setMouseState(e){this.mouseState=e}setSelectedRows(e){this.selectedRows=e}setSelectedCols(e){this.selectedCols=e}addOnSelectionChangeSubscription(e){this.onSelectionChange.push(e)}removeOnSelectionChangeSubscription(e){this.onSelectionChange=this.onSelectionChange.filter(t=>t!==e)}onCellInspectRequested=[];addOnCellInspectRequestedSubscription(e){this.onCellInspectRequested.push(e)}removeOnCellInspectRequestedSubscription(e){this.onCellInspectRequested=this.onCellInspectRequested.filter(t=>t!==e)}notifyCellInspectRequested(e){this.onCellInspectRequested.forEach(t=>t(e))}onHideColumnRequested=[];addOnHideColumnRequestedSubscription(e){this.onHideColumnRequested.push(e)}removeOnHideColumnRequestedSubscription(e){this.onHideColumnRequested=this.onHideColumnRequested.filter(t=>t!==e)}notifyHideColumnRequested(e){this.onHideColumnRequested.forEach(t=>t(e))}onReorderColumnRequested=[];addOnReorderColumnRequestedSubscription(e){this.onReorderColumnRequested.push(e)}removeOnReorderColumnRequestedSubscription(e){this.onReorderColumnRequested=this.onReorderColumnRequested.filter(t=>t!==e)}notifyReorderColumnRequested(e){this.onReorderColumnRequested.forEach(t=>t(e))}getSelectedColumns(){return this.selectedCols.map(e=>this.columns[e]).filter(e=>e!==void 0)}}class Ff{getItem(e){return localStorage.getItem(e)}setItem(e,t){localStorage.setItem(e,t)}removeItem(e){localStorage.removeItem(e)}keys(){const e=[];for(let t=0;t<localStorage.length;t++){const i=localStorage.key(t);i!==null&&e.push(i)}return e}}const Ne={queries:"bedevere_queries",settings:"bedevere_settings",aliases:"bedevere_aliases",keymap:"bedevere_keymap",environments:"bedevere_environments"},hl="bedevere_db",Hf=2,Ze="table_snapshots",et="folder_handles",cl=5;class Wf{backend=new Ff;setBackend(e){this.backend=e}saveQueryBookmark(e,t){const i=this.loadQueryBookmarks(),s=i.findIndex(o=>o.name===e),r={name:e,sql:t,createdAt:Date.now()};s>=0?i[s]=r:i.push(r),this.backend.setItem(Ne.queries,JSON.stringify(i))}loadQueryBookmarks(){const e=this.backend.getItem(Ne.queries);if(!e)return[];try{return JSON.parse(e)}catch{return[]}}deleteQueryBookmark(e){const t=this.loadQueryBookmarks().filter(i=>i.name!==e);this.backend.setItem(Ne.queries,JSON.stringify(t))}saveAppSettings(e){this.backend.setItem(Ne.settings,JSON.stringify(e))}loadAppSettings(){const e=this.backend.getItem(Ne.settings);if(!e)return{};try{return JSON.parse(e)}catch{return{}}}saveEditorAutoSaveDraft(e){const t=this.loadAppSettings();t.editorAutoSaveDraft=e,this.saveAppSettings(t)}loadEditorAutoSaveDraft(){return this.loadAppSettings().editorAutoSaveDraft??""}loadAliases(){const e=this.backend.getItem(Ne.aliases);if(!e)return{};try{return JSON.parse(e)}catch{return{}}}saveAliases(e){this.backend.setItem(Ne.aliases,JSON.stringify(e))}loadKeymapOverrides(){const e=this.backend.getItem(Ne.keymap);if(!e)return{};try{return JSON.parse(e)}catch{return{}}}saveKeymapOverrides(e){Object.keys(e).length===0?this.backend.removeItem(Ne.keymap):this.backend.setItem(Ne.keymap,JSON.stringify(e))}loadEnvironmentsFile(){const e=this.backend.getItem(Ne.environments);if(!e)return null;try{return JSON.parse(e)}catch{return null}}
169saveEnvironmentsFile(e){this.backend.setItem(Ne.environments,JSON.stringify(e))}async openDB(){return new Promise((e,t)=>{const i=indexedDB.open(hl,Hf);i.onupgradeneeded=()=>{const s=i.result;s.objectStoreNames.contains(Ze)||s.createObjectStore(Ze),s.objectStoreNames.contains(et)||s.createObjectStore(et)},i.onsuccess=()=>e(i.result),i.onerror=()=>t(i.error)})}async saveTableSnapshot(e,t){const i=await this.openDB();return new Promise((s,r)=>{const o=i.transaction(Ze,"readwrite");o.objectStore(Ze).put(t,e),o.oncomplete=()=>s(),o.onerror=()=>r(o.error)})}async loadTableSnapshot(e){const t=await this.openDB();return new Promise((i,s)=>{const o=t.transaction(Ze,"readonly").objectStore(Ze).get(e);o.onsuccess=()=>i(o.result??null),o.onerror=()=>s(o.error)})}async deleteTableSnapshot(e){const t=await this.openDB();return new Promise((i,s)=>{const r=t.transaction(Ze,"readwrite");r.objectStore(Ze).delete(e),r.oncomplete=()=>i(),r.onerror=()=>s(r.error)})}async listTableSnapshots(){const e=await this.openDB();return new Promise((t,i)=>{const r=e.transaction(Ze,"readonly").objectStore(Ze).getAllKeys();r.onsuccess=()=>t(r.result),r.onerror=()=>i(r.error)})}async pushRecentFolder(e){try{const t=this.loadAppSettings(),i=t.recentFolders??[],r=i.find(f=>f.name===e.name)?.id??`folder-${Date.now()}-${Math.random().toString(36).slice(2,8)}`,o=await this.openDB();await new Promise((f,d)=>{const p=o.transaction(et,"readwrite");p.objectStore(et).put(e,r),p.oncomplete=()=>f(),p.onerror=()=>d(p.error)});const l=i.filter(f=>f.id!==r),a={id:r,name:e.name,lastUsed:Date.now()},h=[a,...l].slice(0,cl),u=[a,...l].slice(cl).map(f=>f.id);return t.recentFolders=h,this.saveAppSettings(t),u.length>0&&await new Promise(f=>{const d=o.transaction(et,"readwrite");for(const p of u)d.objectStore(et).delete(p);d.oncomplete=()=>f(),d.onerror=()=>f()}),a}catch(t){return console.warn("pushRecentFolder: persistence failed; recents list will not include this folder",t),null}}async loadRecentFolderHandle(e){try{const t=await this.openDB();return await new Promise((i,s)=>{const o=t.transaction(et,"readonly").objectStore(et).get(e);o.onsuccess=()=>i(o.result??null),o.onerror=()=>s(o.error)})}catch(t){return console.warn("loadRecentFolderHandle: read failed",t),null}}async removeRecentFolder(e){const t=this.loadAppSettings();t.recentFolders=(t.recentFolders??[]).filter(i=>i.id!==e),this.saveAppSettings(t);try{const i=await this.openDB();await new Promise(s=>{const r=i.transaction(et,"readwrite");r.objectStore(et).delete(e),r.oncomplete=()=>s(),r.onerror=()=>s()})}catch{}}getRecentFolders(){return this.loadAppSettings().recentFolders??[]}async clearAll(){try{const e=this.backend.keys().filter(t=>t.startsWith("bedevere_"));for(const t of e)this.backend.removeItem(t)}catch(e){console.error("clearAll: failed to clear KV backend",e)}await new Promise(e=>{try{const t=indexedDB.deleteDatabase(hl);t.onsuccess=()=>e(),t.onerror=()=>{console.error("clearAll: failed to delete IndexedDB",t.error),e()},t.onblocked=()=>{console.warn("clearAll: IndexedDB delete blocked (open connection elsewhere)"),e()}}catch(t){console.error("clearAll: threw while deleting IndexedDB",t),e()}})}}const Bs=new Wf;function Tb(n){const e=[];return n.ctrl&&e.push("Ctrl"),n.shift&&e.push("Shift"),n.alt&&e.push("Alt"),e.push(n.key.length===1?n.key.toUpperCase():n.key),e.join("+")}function zf(n,e){const t=n.ctrlKey||n.metaKey;return(e.ctrl??!1)!==t||(e.shift??!1)!==n.shiftKey||(e.alt??!1)!==n.altKey?!1:e.key.length===1?n.key.toLowerCase()===e.key.toLowerCase():n.key===e.key}const fs=[{action:"app.togglePanel",description:"Toggle control panel",scope:"global",binding:{key:"b",ctrl:!0}},{action:"app.toggleSqlEditor",description:"Toggle SQL editor",scope:"global",binding:{key:"e",ctrl:!0}},{action:"app.toggleFullscreen",description:"Toggle fullscreen",scope:"global",binding:{key:"F11"}},{action:"help.toggle",description:"Toggle help panel",scope:"global",binding:{key:"/",ctrl:!0}},{action:"shell.focus",description:"Focus the shell",scope:"global",binding:{key:"`",ctrl:!0}},{action:"tabs.next",description:"Switch to next tab",scope:"global",binding:{key:"ArrowRight",ctrl:!0,alt:!0}},{action:"tabs.prev",description:"Switch to previous tab",scope:"global",binding:{key:"ArrowLeft",ctrl:!0,alt:!0}},{action:"spreadsheet.moveUp",description:"Move selection up",scope:"spreadsheet",binding:{key:"ArrowUp"}}
169,{action:"spreadsheet.moveDown",description:"Move selection down",scope:"spreadsheet",binding:{key:"ArrowDown"}},{action:"spreadsheet.moveLeft",description:"Move selection left",scope:"spreadsheet",binding:{key:"ArrowLeft"}},{action:"spreadsheet.moveRight",description:"Move selection right",scope:"spreadsheet",binding:{key:"ArrowRight"}},{action:"spreadsheet.extendUp",description:"Extend selection up",scope:"spreadsheet",binding:{key:"ArrowUp",ctrl:!0}},{action:"spreadsheet.extendDown",description:"Extend selection down",scope:"spreadsheet",binding:{key:"ArrowDown",ctrl:!0}},{action:"spreadsheet.extendLeft",description:"Extend selection left",scope:"spreadsheet",binding:{key:"ArrowLeft",ctrl:!0}},{action:"spreadsheet.extendRight",description:"Extend selection right",scope:"spreadsheet",binding:{key:"ArrowRight",ctrl:!0}},{action:"spreadsheet.scrollUp",description:"Scroll viewport up",scope:"spreadsheet",binding:{key:"ArrowUp",shift:!0}},{action:"spreadsheet.scrollDown",description:"Scroll viewport down",scope:"spreadsheet",binding:{key:"ArrowDown",shift:!0}},{action:"spreadsheet.scrollLeft",description:"Scroll viewport left",scope:"spreadsheet",binding:{key:"ArrowLeft",shift:!0}},{action:"spreadsheet.scrollRight",description:"Scroll viewport right",scope:"spreadsheet",binding:{key:"ArrowRight",shift:!0}},{action:"spreadsheet.enter",description:"Start cell selection",scope:"spreadsheet",binding:{key:"Enter"}},{action:"spreadsheet.copy",description:"Copy selection to clipboard",scope:"spreadsheet",binding:{key:"c",ctrl:!0}},{action:"spreadsheet.cancelSelection",description:"Cancel selection",scope:"spreadsheet",binding:{key:"Escape"}},{action:"sqlEditor.execute",description:"Execute query",scope:"sqlEditor",binding:{key:"Enter",ctrl:!0}},{action:"sqlEditor.collapse",description:"Collapse editor",scope:"sqlEditor",binding:{key:"Escape"}},{action:"sqlEditor.saveQuery",description:"Save query asâ¦",scope:"sqlEditor",binding:{key:"s",ctrl:!0}}];class Vf{entries=null;ensureLoaded(){return this.entries===null&&(this.entries=this.loadKeymap()),this.entries}getEntries(e){const t=this.ensureLoaded();return e?t.filter(i=>i.scope===e):[...t]}getBinding(e){return this.ensureLoaded().find(t=>t.action===e)?.binding??null}matchEvent(e,t){for(const i of this.ensureLoaded())if(i.scope===t&&zf(e,i.binding))return i.action;return null}setBinding(e,t){const i=this.ensureLoaded().find(s=>s.action===e);i&&(i.binding=t,this.saveKeymap())}resetToDefaults(){this.entries=fs.map(e=>({...e,binding:{...e.binding}})),Bs.saveKeymapOverrides({})}getDefaultBinding(e){return fs.find(t=>t.action===e)?.binding??null}loadKeymap(){const e=fs.map(i=>({...i,binding:{...i.binding}})),t=Bs.loadKeymapOverrides();for(const i of e)t[i.action]&&(i.binding=t[i.action]);return e}saveKeymap(){const e={};for(const t of this.ensureLoaded()){const i=fs.find(s=>s.action===t.action);i&&JSON.stringify(i.binding)!==JSON.stringify(t.binding)&&(e[t.action]=t.binding)}Bs.saveKeymapOverrides(e)}}const $f=new Vf;class Ue{static active=null;element;onDocumentMouseDown;onKeyDown;onWindowResize;static show(e){Ue.active?.dismiss();const t=new Ue(e);return Ue.active=t,t}static dismissActive(){Ue.active?.dismiss()}constructor(e){this.element=document.createElement("div"),this.element.className="context-menu",this.element.setAttribute("role","menu"),this.element.addEventListener("mousedown",i=>i.stopPropagation()),this.element.addEventListener("contextmenu",i=>i.preventDefault());const t=Uf(e.items);for(const i of t){if(i.separator){const o=document.createElement("div");o.className="context-menu__separator",this.element.appendChild(o);continue}const s=document.createElement("button");s.type="button",s.className="context-menu__item",s.setAttribute("role","menuitem"),i.disabled&&(s.classList.add("context-menu__item--disabled"),s.disabled=!0);const r=document.createElement("span");if(r.className="context-menu__label",r.textContent=i.label??"",s.appendChild(r),i.shortcut){const o=document.createElement("span");o.className="context-menu__shortcut",o.textContent=i.shortcut,s.appendChild(o)}s.addEventListener("click",async()=>
169{if(i.disabled||!i.action){this.dismiss();return}this.dismiss();try{await i.action()}catch(o){console.error("ContextMenu action threw:",o)}}),this.element.appendChild(s)}document.body.appendChild(this.element),this.positionAt(e.x,e.y),this.onDocumentMouseDown=i=>{this.element.contains(i.target)||this.dismiss()},this.onKeyDown=i=>{i.key==="Escape"&&(i.stopPropagation(),this.dismiss())},this.onWindowResize=()=>this.dismiss(),setTimeout(()=>{document.addEventListener("mousedown",this.onDocumentMouseDown,!0),document.addEventListener("keydown",this.onKeyDown,!0),window.addEventListener("resize",this.onWindowResize)},0)}positionAt(e,t){const s=window.innerWidth,r=window.innerHeight,o=this.element.offsetWidth,l=this.element.offsetHeight;let a=e,h=t;a+o+4>s&&(a=Math.max(4,e-o)),h+l+4>r&&(h=Math.max(4,t-l)),this.element.style.left=`${a}px`,this.element.style.top=`${h}px`}dismiss(){document.removeEventListener("mousedown",this.onDocumentMouseDown,!0),document.removeEventListener("keydown",this.onKeyDown,!0),window.removeEventListener("resize",this.onWindowResize),this.element.remove(),Ue.active===this&&(Ue.active=null)}}function Uf(n){const e=[];for(const t of n)if(t.separator){if(e.length===0||e[e.length-1].separator)continue;e.push(t)}else e.push(t);for(;e.length>0&&e[e.length-1].separator;)e.pop();return e}class Us extends Pf{_isFocused=!1;componentId;canReceiveFocus=!0;focusableElement;static HEADER_DRAG_THRESHOLD_PX=4;headerDragCandidate=null;headerDragActive=!1;headerDragGhostEl=null;headerDropIndicatorEl=null;headerDropTarget=null;constructor(e,t,i={},s,r){super(e,t,i,s),this.componentId=r??"spreadsheet-visualizer",this.focusableElement=this.getContainer()}focus(){this._isFocused=!0,this.focusableElement.focus()}blur(){this._isFocused=!1,this.focusableElement.blur()}isFocused(){return this._isFocused}async handleMouseDown(e){if(!this._isFocused||!this.container.contains(e.target))return!1;const t=this.canvas.getBoundingClientRect(),i=e.clientX-t.left,s=e.clientY-t.top;if(i<0||s<0||i>this.viewportWidth||s>this.viewportHeight)return!1;if(this.isMouseOverColumnHeader(i,s)){const r=this.getCellAtPosition(i,s);if(!r)return!1;const{col:o}=r;if(this.filterManager&&o>=0&&o<this.columns.length){const l=this.colOffsets[o]+this.colWidths[o]-this.scrollX;if(i>=l-22)return this.filterManager.cycleSort(this.datasetName,this.columns[o].name,e.shiftKey),!0}if(o>=0&&o<this.columns.length)return this.headerDragCandidate={col:o,columnName:this.columns[o].name,startClientX:e.clientX,startClientY:e.clientY,modifiers:{shift:e.shiftKey,ctrl:e.ctrlKey||e.metaKey}},this.headerDragActive=!1,this.installHeaderDragListeners(),!0}else if(i<=this.options.rowHeaderWidth&&s>=this.options.cellHeight){const r=this.getCellAtPosition(i,s);if(r&&r.row>=1&&r.row<=this.totalRows)return await this.selectRow(r.row,{shift:e.shiftKey,ctrl:e.ctrlKey||e.metaKey}),await this.draw(),!0}else{if(e.button===2)return!1;const r=this.getCellAtPosition(i,s);r&&(this.selectedCols.length>0&&(this.selectedCols=[],this.selectedRows=[],this.selectedCells=null,this.statsVisualizer?.hide()),this.mouseState=Yt.Dragging,this.selectedCols=[],this.selectedRows=[],this.selectedCells={startRow:r.row,endRow:r.row,startCol:r.col,endCol:r.col},this.updateToDraw(K.Selection),this.notifySelectionChange())}return await this.draw(),!0}async handleMouseMove(e){if(!this._isFocused||this.headerDragCandidate||!this.container.contains(e.target))return!1;const t=this.canvas.getBoundingClientRect(),i=e.clientX-t.left,s=e.clientY-t.top;let r=null;switch(this.mouseState){case Yt.Dragging:r=this.getCellAtPosition(i,s),r&&this.selectedCells&&(r.row!==this.selectedCells.endRow||r.col!==this.selectedCells.endCol)&&(this.selectedCells.endRow=r.row,this.selectedCells.endCol=r.col,this.updateToDraw(K.Selection),this.notifySelectionChange());break;default:r=this.getCellAtPosition(i,s),(r?.row!==this.hoveredCell?.row||r?.col!==this.hoveredCell?.col)&&(this.hoveredCell=r,this.isMouseOverColumnHeader(i,s)?this.updateToDraw(K.ColHover):this.isMouseOverRowIndex(i,s)?this.updateToDraw(K.RowHover):this.updateToDraw(K.CellHover));break}return await this.draw(),!0}async handleMouseUp(e){return this._isFocused?(this.mouseState=Yt.Idle,!0):!1}async handleMouseLeave(e){return this._isFocused?(this.hoveredCell=null,this.mouseState=Yt.Idle,this.updateToDraw(K.CellHover),this.draw(),!0):!1}async handleDoubleClick(e){if(!this._isFocused)return!1;const t=this.canvas.getBoundingClientRect(),i=e.clientX-t.left,s=e.clientY-t.top;if(i<0||s<0||i>this.viewportWidth||s>
169this.viewportHeight)return!1;const r=this.getCellAtPosition(i,s);if(!r||r.col<0||r.row<1)return!1;const o=this.columns[r.col];if(!o||!Vs(o.dataType))return!1;const l=el(o.dataType);if(!l)return!1;const a=await this.cache.getValue(r.row-1,r.col);return this.notifyCellInspectRequested({columnName:o.name,kind:l,value:a}),!0}async handleContextMenu(e){if(!this._isFocused)return!1;const t=this.canvas.getBoundingClientRect(),i=e.clientX-t.left,s=e.clientY-t.top;if(i<0||s<0||i>this.viewportWidth||s>this.viewportHeight)return!1;e.preventDefault();const r=this.getCellAtPosition(i,s);if(!r)return Ue.dismissActive(),!0;const o=this.isMouseOverColumnHeader(i,s),l=i<=this.options.rowHeaderWidth&&s>=this.options.cellHeight&&r.row>=1;let a;if(o&&r.col>=0)a=this.buildHeaderContextMenu(r.col);else if(l)this.isRowInCurrentSelection(r.row)||(await this.selectRow(r.row,{shift:!1,ctrl:!1}),await this.draw()),a=this.buildRowContextMenu();else if(r.row>=1&&r.col>=0)this.isCellInCurrentSelection(r.row,r.col)||(this.selectedCols=[],this.selectedRows=[],this.selectedCells={startRow:r.row,endRow:r.row,startCol:r.col,endCol:r.col},this.updateToDraw(K.Selection),this.notifySelectionChange(),await this.draw()),a=await this.buildCellContextMenu(r.row,r.col);else return Ue.dismissActive(),!0;return a.length===0?(Ue.dismissActive(),!0):(Ue.show({x:e.clientX,y:e.clientY,items:a}),!0)}isCellInCurrentSelection(e,t){if(this.selectedCells){const{startRow:i,endRow:s,startCol:r,endCol:o}=this.selectedCells,l=e>=Math.min(i,s)&&e<=Math.max(i,s),a=t>=Math.min(r,o)&&t<=Math.max(r,o);if(l&&a)return!0}return!!(this.selectedCols.includes(t)||this.selectedRows.includes(e))}isRowInCurrentSelection(e){if(this.selectedRows.includes(e))return!0;if(this.selectedCells){const{startRow:t,endRow:i}=this.selectedCells;if(e>=Math.min(t,i)&&e<=Math.max(t,i))return!0}return!1}buildHeaderContextMenu(e){const t=this.columns[e];if(!t)return[];const i=this.filterManager?.isColumnSorted(this.datasetName,t.name)??null;return[{label:"Sort ascending",disabled:i==="asc",action:()=>{this.filterManager?.setSort(this.datasetName,{columnName:t.name,direction:"asc"})}},{label:"Sort descending",disabled:i==="desc",action:()=>{this.filterManager?.setSort(this.datasetName,{columnName:t.name,direction:"desc"})}},{label:"Clear sort",disabled:i===null,action:()=>{this.filterManager?.removeSort(this.datasetName,t.name)}},{separator:!0},{label:"Hide column",action:()=>{this.notifyHideColumnRequested({datasetName:this.datasetName,columnName:t.name})}}]}async buildCellContextMenu(e,t){const i=this.columns[t];if(!i)return[];const s=[{label:"Copy",shortcut:"Ctrl+C",action:async()=>{await this.dispatchKeymapAction("spreadsheet.copy")}}];Vs(i.dataType)&&s.push({label:"Inspect",action:async()=>{const o=this.selectedCells;if(!o)return;const l=el(i.dataType);if(!l)return;const a=await this.cache.getValue(o.startRow-1,o.startCol);this.notifyCellInspectRequested({columnName:i.name,kind:l,value:a})}});const r=this.filterManager?.isColumnSorted(this.datasetName,i.name)??null;return s.push({separator:!0},{label:"Sort by this column â",disabled:r==="asc",action:()=>{this.filterManager?.setSort(this.datasetName,{columnName:i.name,direction:"asc"})}},{label:"Sort by this column â",disabled:r==="desc",action:()=>{this.filterManager?.setSort(this.datasetName,{columnName:i.name,direction:"desc"})}},{separator:!0},{label:"Hide column",action:()=>{this.notifyHideColumnRequested({datasetName:this.datasetName,columnName:i.name})}}),s}buildRowContextMenu(){return[{label:"Copy row",shortcut:"Ctrl+C",action:async()=>{await this.dispatchKeymapAction("spreadsheet.copy")}}]}async handleWheel(e){if(!this._isFocused||!this.container.contains(e.target)||!e.ctrlKey)return!1;e.preventDefault();const t=e.deltaY>0?.9:1.1;return this.options.fontSize=Math.max(14,Math.min(24,this.options.fontSize*t)),this.options.cellHeight=Math.max(14,Math.min(24,this.options.cellHeight*t)),this.options.headerFontSize=Math.max(14,Math.min(24,this.options.headerFontSize*t)),this.options.cellPadding=Math.max(1,Math.min(10,this.options.cellPadding*t)),await this.updateLayout(),this.updateToDraw(K.Cells),await this.draw(),!0}async handleKeyDown(e){if(!this._isFocused)return!1;const t=document.activeElement;if(t&&(t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.isContentEditable))return!1;const i=$f.matchEvent(e,"spreadsheet");if(!i)return!1;if(i==="spreadsheet.copy"){const s=window.getSelection();if((s?s.toString():"").length>0){const o=s?.anchorNode,l=o&&o.nodeType===Node.ELEMENT_NODE?o:o?.parentElement??null;if(l&&!this.container.contains(l))return!1}}return e.preventDefault(),this.dispatchKeymapAction(i)}async dispatchKeymapAction(e){const t=this.options.cellHeight*3;switch(e){case"spreadsheet.scrollUp":this.scrollTo(this.scrollX,this.scrollY-t);break;case"spreadsheet.scrollDown":this.scrollTo(this.scrollX,this.scrollY+t);break;case"spreadsheet.scrollLeft":this.scrollTo(this.scrollX-t,this.scrollY);break;case"spreadsheet.scrollRight":this.scrollTo(this.scrollX+t,this.scrollY);break;case"spreadsheet.extendUp":this.selectedCells&&(this.selectedCells.endRow=Math.max(1,this.selectedCells.endRow-1),this.scrollCellIntoView(this.selectedCells.endRow,this.selectedCells.endCol));break;case"spreadsheet.extendDown":this.selectedCells&&(this.selectedCells.endRow=Math.min(this.totalRows,this.selectedCells.endRow+1),this.scrollCellIntoView(this.selectedCells.endRow,this.selectedCells.endCol));break;case"spreadsheet.extendLeft":this.selectedCells&&(this.selectedCells.endCol=Math.max(0,this.selectedCells.endCol-1),this.scrollCellIntoView(this.selectedCells.endRow,this.selectedCells.endCol));break;case"spreadsheet.extendRight":this.selectedCells&&(this.selectedCells.endCol=Math.min(this.totalCols-1,this.selectedCells.endCol+1),this.scrollCellIntoView(this.selectedCells.endRow,this.selectedCells.endCol));break;case"spreadsheet.moveUp":if(this.selectedCells){const i=Math.max(1,this.selectedCells.startRow-1);this.selectedCells={startRow:i,endRow:i,startCol:this.selectedCells.startCol,endCol:this.selectedCells.startCol},this.scrollCellIntoView(i,this.selectedCells.startCol)}break;case"spreadsheet.moveDown":if(this.selectedCols.length>0){const i=this.selectedCols[0];this.selectedCols=[],this.selectedRows=[],this.selectedCells={startRow:1,endRow:1,startCol:i,endCol:i},this.statsVisualizer?.hide()}else if(this.selectedCells){const i=Math.min(this.totalRows,this.selectedCells.startRow+1);this.selectedCells={startRow:i,endRow:i,startCol:this.selectedCells.startCol,endCol:this.selectedCells.startCol},this.scrollCellIntoView(i,this.selectedCells.startCol)}break;case"spreadsheet.moveLeft":if(this.selectedCols.length>0){const i=Math.max(0,this.selectedCols[0]-1);this.selectedCols=[i],this.selectedCells=null,await this.statsVisualizer?.showStats(this.columns[i]),this.scrollTo(this.colOffsets[i]-this.viewportWidth/2,this.scrollY)}else if(this.selectedCells){const i=Math.max(0,this.selectedCells.startCol-1);this.selectedCells={startRow:this.selectedCells.startRow,endRow:this.selectedCells.startRow,startCol:i,endCol:i},this.scrollCellIntoView(this.selectedCells.startRow,i)}break;case"spreadsheet.moveRight":if(this.selectedCols.length>0){const i=Math.min(this.totalCols-1,this.selectedCols[0]+1);this.selectedCols=[i],this.selectedCells=null,await this.statsVisualizer?.showStats(this.columns[i]),this.scrollTo(this.colOffsets[i]-this.viewportWidth/2,this.scrollY)}else if(this.selectedCells){const i=Math.min(this.totalCols-1,this.selectedCells.startCol+1);this.selectedCells={startRow:this.selectedCells.startRow,endRow:this.selectedCells.startRow,startCol:i,endCol:i},this.scrollCellIntoView(this.selectedCells.startRow,i)}break;case"spreadsheet.enter":!this.selectedCells&&this.selectedCols.length===0&&this.selectedRows.length===0&&(this.selectedCells={startRow:1,endRow:1,startCol:0,endCol:0});break;
169case"spreadsheet.copy":{const i=await this.getSelectedFormattedValues();if(i.data.length>0){const s=Bs.loadAppSettings(),r=s.copyDelimiter==="comma"?",":" ",o=s.copyIncludeHeader??!0,l=i.data.map(a=>a.join(r));o&&l.unshift(i.headers.join(r)),navigator.clipboard.writeText(l.join(` 170`)).catch(console.error)}break}case"spreadsheet.cancelSelection":this.selectedCells=null;break;default:return!1}return this.updateToDraw(K.Selection),this.notifySelectionChange(),await this.draw(),!0}async handleResize(){return await this.updateLayout(),this.updateToDraw(K.Cells),await this.draw(),!0}async resize(){await this.handleResize()}installHeaderDragListeners(){document.addEventListener("mousemove",this.headerDragMouseMove,!0),document.addEventListener("mouseup",this.headerDragMouseUp,!0)}uninstallHeaderDragListeners(){document.removeEventListener("mousemove",this.headerDragMouseMove,!0),document.removeEventListener("mouseup",this.headerDragMouseUp,!0)}headerDragMouseMove=e=>{if(this.headerDragCandidate){if(!this.headerDragActive){const t=Math.abs(e.clientX-this.headerDragCandidate.startClientX),i=Math.abs(e.clientY-this.headerDragCandidate.startClientY);if(t<Us.HEADER_DRAG_THRESHOLD_PX&&i<Us.HEADER_DRAG_THRESHOLD_PX)return;this.headerDragActive=!0,this.createHeaderDragGhost(this.headerDragCandidate.columnName)}this.updateHeaderDragGhost(e.clientX,e.clientY),this.updateHeaderDropIndicator(e.clientX)}};headerDragMouseUp=async e=>{this.uninstallHeaderDragListeners();const t=this.headerDragCandidate;if(this.headerDragCandidate=null,!!t){if(this.headerDragActive){const i=this.headerDropTarget;this.headerDragActive=!1,this.headerDropTarget=null,this.removeHeaderDragGhost(),this.removeHeaderDropIndicator(),i&&i.columnName!==t.columnName&&this.notifyReorderColumnRequested({datasetName:this.datasetName,sourceColumnName:t.columnName,targetColumnName:i.columnName,position:i.position});return}await this.selectColumn(t.col,t.modifiers),await this.draw()}};createHeaderDragGhost(e){const t=document.createElement("div");t.className="spreadsheet__column-drag-ghost",t.textContent=e,document.body.appendChild(t),this.headerDragGhostEl=t;const i=document.createElement("div");i.className="spreadsheet__column-drop-indicator",document.body.appendChild(i),this.headerDropIndicatorEl=i}updateHeaderDragGhost(e,t){this.headerDragGhostEl&&(this.headerDragGhostEl.style.left=`${e+12}px`,this.headerDragGhostEl.style.top=`${t+6}px`)}updateHeaderDropIndicator(e){if(!this.headerDropIndicatorEl)return;const t=this.canvas.getBoundingClientRect(),i=e-t.left;if(i<this.options.rowHeaderWidth||i>this.viewportWidth){this.headerDropTarget=null,this.headerDropIndicatorEl.style.display="none";return}for(let s=0;s<this.columns.length;s++){const r=this.colOffsets[s]-this.scrollX,o=r+this.colWidths[s];if(i>=r&&i<o){const l=r+this.colWidths[s]/2,a=i<l?"before":"after",h=a==="before"?r:o;this.headerDropTarget={columnName:this.columns[s].name,position:a},this.headerDropIndicatorEl.style.display="block",this.headerDropIndicatorEl.style.left=`${t.left+h-1}px`,this.headerDropIndicatorEl.style.top=`${t.top}px`,this.headerDropIndicatorEl.style.height=`${t.height}px`;return}}this.headerDropTarget=null,this.headerDropIndicatorEl.style.display="none"}removeHeaderDragGhost(){this.headerDragGhostEl&&(this.headerDragGhostEl.remove(),this.headerDragGhostEl=null)}removeHeaderDropIndicator(){this.headerDropIndicatorEl&&(this.headerDropIndicatorEl.remove(),this.headerDropIndicatorEl=null)}}class qf{name;key;extra;default;label;dataType;rawType;length;format;hasNulls;widthPx=0;guessedFormat=void 0;cachedFormatter=null;constructor(e,t){this.name=e.name,this.key=e.key,this.extra=e.extra,this.default=e.default,this.dataType=e.dataType,this.rawType=e.rawType,this.label=e.label,this.length=e.length,this.format=e.format,this.hasNulls=e.hasNulls,this.widthPx=0,this.guessedFormat=go(this,t)}}class Ab extends Us{constructor(e,t,i={},s,r){super(e,t,i,s,r??"spreadsheet-visualizer"),this.statsVisualizer=s??new ni(this.container,this),this.statsVisualizer.setSpreadsheetVisualizer(this).catch(console.error),this.themeCleanup=Af(()=>{this.updateThemeColors(),this.updateToDraw(K.Cells),this.calculateColumnWidths().then(()=>this.draw()).catch(console.error)})}async initialize(){this.metadata=await this.dataProvider.getMetadata(),this.metadata&&(this.columns=this.metadata.columns.map(e=>new qf(e,this.options)),this.totalRows=this.metadata.totalRows,this.totalCols=this.metadata.totalColumns,await this.cache.initialize(this.totalRows),await this.updateLayout())}async reinitialize(e){this.dataProvider=e,this.cache.clear(),this.cache=new hh(this.dataProvider,this.options),this.attachCacheListener(),this.hoveredCell=null,await this.initialize(),this.scrollX=Math.min(this.scrollContainer.scrollLeft,this.totalScrollX),this.scrollY=Math.min(this.scrollContainer.scrollTop,this.totalScrollY),this.scrollContainer.scrollLeft=this.scrollX,this.scrollContainer.scrollTop=this.scrollY}
170show(){this.container.style.display="block"}hide(){this.container.style.display="none",this.statsVisualizer?.hide()}destroy(){this.themeCleanup&&(this.themeCleanup(),this.themeCleanup=null),this.destroyBase(),this.statsVisualizer?.hide(),this.cache.clear()}updateThemeColors(){const e=$s();this.options.headerBackgroundColor=e.headerBackgroundColor,this.options.headerTextColor=e.headerTextColor,this.options.cellBackgroundColor=e.cellBackgroundColor,this.options.cellTextColor=e.cellTextColor,this.options.stripeBackgroundColor=e.stripeBackgroundColor,this.options.borderColor=e.borderColor,this.options.selectionColor=e.selectionColor,this.options.selectionBorderColor=e.selectionBorderColor,this.options.hoverColor=e.hoverColor,this.options.hoverBorderColor=e.hoverBorderColor,this.options.scrollbarColor=e.scrollbarColor,this.options.scrollbarThumbColor=e.scrollbarThumbColor,this.options.scrollbarHoverColor=e.scrollbarHoverColor}}class Mb extends ni{componentId;canReceiveFocus=!0;focusableElement;constructor(e,t){super(e,t),this.focusableElement=this.getContainer(),this.componentId="column-stats-visualizer"}focus(){this.focusableElement.focus()}blur(){this.focusableElement.blur()}isFocused(){return this.focusableElement.contains(document.activeElement)}}let vr=[],ch=[];(()=>{let n="lc,34,7n,7,7b,19,,,,2,,2,,,20,b,1c,l,g,,2t,7,2,6,2,2,,4,z,,u,r,2j,b,1m,9,9,,o,4,,9,,3,,5,17,3,3b,f,,w,1j,,,,4,8,4,,3,7,a,2,t,,1m,,,,2,4,8,,9,,a,2,q,,2,2,1l,,4,2,4,2,2,3,3,,u,2,3,,b,2,1l,,4,5,,2,4,,k,2,m,6,,,1m,,,2,,4,8,,7,3,a,2,u,,1n,,,,c,,9,,14,,3,,1l,3,5,3,,4,7,2,b,2,t,,1m,,2,,2,,3,,5,2,7,2,b,2,s,2,1l,2,,,2,4,8,,9,,a,2,t,,20,,4,,2,3,,,8,,29,,2,7,c,8,2q,,2,9,b,6,22,2,r,,,,,,1j,e,,5,,2,5,b,,10,9,,2u,4,,6,,2,2,2,p,2,4,3,g,4,d,,2,2,6,,f,,jj,3,qa,3,t,3,t,2,u,2,1s,2,,7,8,,2,b,9,,19,3,3b,2,y,,3a,3,4,2,9,,6,3,63,2,2,,1m,,,7,,,,,2,8,6,a,2,,1c,h,1r,4,1c,7,,,5,,14,9,c,2,w,4,2,2,,3,1k,,,2,3,,,3,1m,8,2,2,48,3,,d,,7,4,,6,,3,2,5i,1m,,5,ek,,5f,x,2da,3,3x,,2o,w,fe,6,2x,2,n9w,4,,a,w,2,28,2,7k,,3,,4,,p,2,5,,47,2,q,i,d,,12,8,p,b,1a,3,1c,,2,4,2,2,13,,1v,6,2,2,2,2,c,,8,,1b,,1f,,,3,2,2,5,2,,,16,2,8,,6m,,2,,4,,fn4,,kh,g,g,g,a6,2,gt,,6a,,45,5,1ae,3,,2,5,4,14,3,4,,4l,2,fx,4,ar,2,49,b,4w,,1i,f,1k,3,1d,4,2,2,1x,3,10,5,,8,1q,,c,2,1g,9,a,4,2,,2n,3,2,,,2,6,,4g,,3,8,l,2,1l,2,,,,,m,,e,7,3,5,5f,8,2,3,,,n,,29,,2,6,,,2,,,2,,2,6j,,2,4,6,2,,2,r,2,2d,8,2,,,2,2y,,,,2,6,,,2t,3,2,4,,5,77,9,,2,6t,,a,2,,,4,,40,4,2,2,4,,w,a,14,6,2,4,8,,9,6,2,3,1a,d,,2,ba,7,,6,,,2a,m,2,7,,2,,2,3e,6,3,,,2,,7,,,20,2,3,,,,9n,2,f0b,5,1n,7,t4,,1r,4,29,,f5k,2,43q,,,3,4,5,8,8,2,7,u,4,44,3,1iz,1j,4,1e,8,,e,,m,5,,f,11s,7,,h,2,7,,2,,5,79,7,c5,4,15s,7,31,7,240,5,gx7k,2o,3k,6o".split(",").map(e=>e?parseInt(e,36):1);for(let e=0,t=0;e<n.length;e++)(e%2?ch:vr).push(t=t+n[e])})();function Qf(n){if(n<768)return!1;for(let e=0,t=vr.length;;){let i=e+t>>1;if(n<vr[i])t=i;else if(n>=ch[i])e=i+1;else return!0;if(e==t)return!1}}function ul(n){return n>=127462&&n<=127487}const fl=8205;function jf(n,e,t=!0,i=!0){return(t?uh:Gf)(n,e,i)}function uh(n,e,t){if(e==n.length)return e;e&&fh(n.charCodeAt(e))&&dh(n.charCodeAt(e-1))&&e--;let i=Fn(n,e);for(e+=dl(i);e<n.length;){let s=Fn(n,e);if(i==fl||s==fl||t&&Qf(s))e+=dl(s),i=s;else if(ul(s)){let r=0,o=e-2;for(;o>=0&&ul(Fn(n,o));)r++,o-=2;if(r%2==0)break;e+=2}else break}return e}function Gf(n,e,t){for(;e>0;){let i=uh(n,e-2,t);if(i<e)return i;e--}return 0}function Fn(n,e){let t=n.charCodeAt(e);if(!dh(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return fh(i)?(t-55296<<10)+(i-56320)+65536:t}function fh(n){return n>=56320&&n<57344}function dh(n){return n>=55296&&n<56320}function dl(n){return n<65536?1:2}class F{lineAt(e){if(e<0||e>this.length)throw new RangeError(`Invalid position ${e} in document of length ${this.length}`);return this.lineInner(e,!1,1,0)}line(e){if(e<1||e>this.lines)throw new RangeError(`Invalid line number ${e} in ${this.lines}-line document`);return this.lineInner(e,!0,1,0)}replace(e,t,i){[e,t]=fi(this,e,t);let s=[];return this.decompose(0,e,s,2),i.length&&i.decompose(0,i.length,s,3),this.decompose(t,this.length,s,1),rt.from(s,this.length-(t-e)+i.length)}append(e){return this.replace(this.length,this.length,e)}slice(e,t=this.length){[e,t]=fi(this,e,t);let i=[];return this.decompose(e,t,i,0),rt.from(i,t-e)}eq(e){if(e==this)return!0;
vendor: 42,166 bytes, lines 170-174
170if(e.length!=this.length||e.lines!=this.lines)return!1;let t=this.scanIdentical(e,1),i=this.length-this.scanIdentical(e,-1),s=new Bi(this),r=new Bi(e);for(let o=t,l=t;;){if(s.next(o),r.next(o),o=0,s.lineBreak!=r.lineBreak||s.done!=r.done||s.value!=r.value)return!1;if(l+=s.value.length,s.done||l>=i)return!0}}iter(e=1){return new Bi(this,e)}iterRange(e,t=this.length){return new ph(this,e,t)}iterLines(e,t){let i;if(e==null)i=this.iter();else{t==null&&(t=this.lines+1);let s=this.line(e).from;i=this.iterRange(s,Math.max(s,t==this.lines+1?this.length:t<=1?0:this.line(t-1).to))}return new mh(i)}toString(){return this.sliceString(0)}toJSON(){let e=[];return this.flatten(e),e}constructor(){}static of(e){if(e.length==0)throw new RangeError("A document must have at least one line");return e.length==1&&!e[0]?F.empty:e.length<=32?new Z(e):rt.from(Z.split(e,[]))}}class Z extends F{constructor(e,t=Kf(e)){super(),this.text=e,this.length=t}get lines(){return this.text.length}get children(){return null}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.text[r],l=s+o.length;if((t?i:l)>=e)return new Xf(s,l,i,o);s=l+1,i++}}decompose(e,t,i,s){let r=e<=0&&t>=this.length?this:new Z(pl(this.text,e,t),Math.min(t,this.length)-Math.max(0,e));if(s&1){let o=i.pop(),l=_s(r.text,o.text.slice(),0,r.length);if(l.length<=32)i.push(new Z(l,o.length+r.length));else{let a=l.length>>1;i.push(new Z(l.slice(0,a)),new Z(l.slice(a)))}}else i.push(r)}replace(e,t,i){if(!(i instanceof Z))return super.replace(e,t,i);[e,t]=fi(this,e,t);let s=_s(this.text,_s(i.text,pl(this.text,0,e)),t),r=this.length+i.length-(t-e);return s.length<=32?new Z(s,r):rt.from(Z.split(s,[]),r)}sliceString(e,t=this.length,i=` 171`){[e,t]=fi(this,e,t);let s="";for(let r=0,o=0;r<=t&&o<this.text.length;o++){let l=this.text[o],a=r+l.length;r>e&&o&&(s+=i),e<a&&t>r&&(s+=l.slice(Math.max(0,e-r),t-r)),r=a+1}return s}flatten(e){for(let t of this.text)e.push(t)}scanIdentical(){return 0}static split(e,t){let i=[],s=-1;for(let r of e)i.push(r),s+=r.length+1,i.length==32&&(t.push(new Z(i,s)),i=[],s=-1);return s>-1&&t.push(new Z(i,s)),t}}class rt extends F{constructor(e,t){super(),this.children=e,this.length=t,this.lines=0;for(let i of e)this.lines+=i.lines}lineInner(e,t,i,s){for(let r=0;;r++){let o=this.children[r],l=s+o.length,a=i+o.lines-1;if((t?a:l)>=e)return o.lineInner(e,t,i,s);s=l+1,i=a+1}}decompose(e,t,i,s){for(let r=0,o=0;o<=t&&r<this.children.length;r++){let l=this.children[r],a=o+l.length;if(e<=a&&t>=o){let h=s&((o<=e?1:0)|(a>=t?2:0));o>=e&&a<=t&&!h?i.push(l):l.decompose(e-o,t-o,i,h)}o=a+1}}replace(e,t,i){if([e,t]=fi(this,e,t),i.lines<this.lines)for(let s=0,r=0;s<this.children.length;s++){let o=this.children[s],l=r+o.length;if(e>=r&&t<=l){let a=o.replace(e-r,t-r,i),h=this.lines-o.lines+a.lines;if(a.lines<h>>4&&a.lines>h>>6){let c=this.children.slice();return c[s]=a,new rt(c,this.length-(t-e)+i.length)}return super.replace(r,l,a)}r=l+1}return super.replace(e,t,i)}sliceString(e,t=this.length,i=` 172`){[e,t]=fi(this,e,t);let s="";for(let r=0,o=0;r<this.children.length&&o<=t;r++){let l=this.children[r],a=o+l.length;o>e&&r&&(s+=i),e<a&&t>o&&(s+=l.sliceString(e-o,t-o,i)),o=a+1}return s}flatten(e){for(let t of this.children)t.flatten(e)}scanIdentical(e,t){if(!(e instanceof rt))return 0;let i=0,[s,r,o,l]=t>0?[0,0,this.children.length,e.children.length]:[this.children.length-1,e.children.length-1,-1,-1];for(;;s+=t,r+=t){if(s==o||r==l)return i;let a=this.children[s],h=e.children[r];if(a!=h)return i+a.scanIdentical(h,t);i+=a.length+1}}static from(e,t=e.reduce((i,s)=>i+s.length+1,-1)){let i=0;for(let d of e)i+=d.lines;if(i<32){let d=[];for(let p of e)p.flatten(d);return new Z(d,t)}let s=Math.max(32,i>>5),r=s<<1,o=s>>1,l=[],a=0,h=-1,c=[];function u(d){let p;if(d.lines>r&&d instanceof rt)for(let m of d.children)u(m);else d.lines>o&&(a>o||!a)?(f(),l.push(d)):d instanceof Z&&a&&(p=c[c.length-1])instanceof Z&&d.lines+p.lines<=32?(a+=d.lines,h+=d.length+1,c[c.length-1]=new Z(p.text.concat(d.text),p.length+1+d.length)):(a+d.lines>s&&f(),a+=d.lines,h+=d.length+1,c.push(d))}function f(){a!=0&&(l.push(c.length==1?c[0]:rt.from(c,h)),h=-1,a=c.length=0)}for(let d of e)u(d);return f(),l.length==1?l[0]:new rt(l,t)}}F.empty=new Z([""],0);function Kf(n){let e=-1;for(let t of n)e+=t.length+1;return e}function _s(n,e,t=0,i=1e9){for(let s=0,r=0,o=!0;r<n.length&&s<=i;r++){let l=n[r],a=s+l.length;a>=t&&(a>i&&(l=l.slice(0,i-s)),s<t&&(l=l.slice(t-s)),o?(e[e.length-1]+=l,o=!1):e.push(l)),s=a+1}return e}function pl(n,e,t){return _s(n,[""],e,t)}class Bi{constructor(e,t=1){this.dir=t,this.done=!1,this.lineBreak=!1,this.value="",this.nodes=[e],this.offsets=[t>0?1:(e instanceof Z?e.text.length:e.children.length)<<1]}nextInner(e,t){for(this.done=this.lineBreak=!1;;){let i=this.nodes.length-1,s=this.nodes[i],r=this.offsets[i],o=r>>1,l=s instanceof Z?s.text.length:s.children.length;if(o==(t>0?l:0)){if(i==0)return this.done=!0,this.value="",this;t>0&&this.offsets[i-1]++,this.nodes.pop(),this.offsets.pop()}else if((r&1)==(t>0?0:1)){if(this.offsets[i]+=t,e==0)return this.lineBreak=!0,this.value=` 173`,this;e--}else if(s instanceof Z){let a=s.text[o+(t<0?-1:0)];if(this.offsets[i]+=t,a.length>Math.max(0,e))return this.value=e==0?a:t>0?a.slice(e):a.slice(0,a.length-e),this;e-=a.length}else{let a=s.children[o+(t<0?-1:0)];e>a.length?(e-=a.length,this.offsets[i]+=t):(t<0&&this.offsets[i]--,this.nodes.push(a),this.offsets.push(t>0?1:(a instanceof Z?a.text.length:a.children.length)<<1))}}}next(e=0){return e<0&&(this.nextInner(-e,-this.dir),e=this.value.length),this.nextInner(e,this.dir)}}class ph{constructor(e,t,i){this.value="",this.done=!1,this.cursor=new Bi(e,t>i?-1:1),this.pos=t>i?e.length:0,this.from=Math.min(t,i),this.to=Math.max(t,i)}nextInner(e,t){if(t<0?this.pos<=this.from:this.pos>=this.to)return this.value="",this.done=!0,this;e+=Math.max(0,t<0?this.pos-this.to:this.from-this.pos);let i=t<0?this.pos-this.from:this.to-this.pos;e>i&&(e=i),i-=e;let{value:s}=this.cursor.next(e);return this.pos+=(s.length+e)*t,this.value=s.length<=i?s:t<0?s.slice(s.length-i):s.slice(0,i),this.done=!this.value,this}next(e=0){return e<0?e=Math.max(e,this.from-this.pos):e>0&&(e=Math.min(e,this.to-this.pos)),this.nextInner(e,this.cursor.dir)}get lineBreak(){return this.cursor.lineBreak&&this.value!=""}}class mh{constructor(e){this.inner=e,this.afterBreak=!0,this.value="",this.done=!1}next(e=0){let{done:t,lineBreak:i,value:s}=this.inner.next(e);return t&&this.afterBreak?(this.value="",this.afterBreak=!1):t?(this.done=!0,this.value=""):i?this.afterBreak?this.value="":(this.afterBreak=!0,this.next()):(this.value=s,this.afterBreak=!1),this}get lineBreak(){return!1}}typeof Symbol<"u"&&(F.prototype[Symbol.iterator]=function(){return this.iter()},Bi.prototype[Symbol.iterator]=ph.prototype[Symbol.iterator]=mh.prototype[Symbol.iterator]=function(){return this});class Xf{constructor(e,t,i,s){this.from=e,this.to=t,this.number=i,this.text=s}get length(){return this.to-this.from}}function fi(n,e,t){return e=Math.max(0,Math.min(n.length,e)),[e,Math.max(e,Math.min(n.length,t))]}function oe(n,e,t=!0,i=!0){return jf(n,e,t,i)}function Yf(n){return n>=56320&&n<57344}function Jf(n){return n>=55296&&n<56320}function bt(n,e){let t=n.charCodeAt(e);if(!Jf(t)||e+1==n.length)return t;let i=n.charCodeAt(e+1);return Yf(i)?(t-55296<<10)+(i-56320)+65536:t}function gh(n){return n<=65535?String.fromCharCode(n):(n-=65536,String.fromCharCode((n>>10)+55296,(n&1023)+56320))}function Bt(n){return n<65536?1:2}const kr=/\r\n?|\n/;var Oe=function(n){return n[n.Simple=0]="Simple",n[n.TrackDel=1]="TrackDel",n[n.TrackBefore=2]="TrackBefore",n[n.TrackAfter=3]="TrackAfter",n}(Oe||(Oe={}));class ct{constructor(e){this.sections=e}get length(){let e=0;for(let t=0;t<this.sections.length;t+=2)e+=this.sections[t];return e}get newLength(){let e=0;for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t+1];e+=i<0?this.sections[t]:i}return e}get empty(){return this.sections.length==0||this.sections.length==2&&this.sections[1]<0}iterGaps(e){for(let t=0,i=0,s=0;t<this.sections.length;){let r=this.sections[t++],o=this.sections[t++];o<0?(e(i,s,r),s+=r):s+=o,i+=r}}iterChangedRanges(e,t=!1){Tr(this,e,t)}get invertedDesc(){let e=[];for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];s<0?e.push(i,s):e.push(s,i)}return new ct(e)}composeDesc(e){return this.empty?e:e.empty?this:yh(this,e)}mapDesc(e,t=!1){return e.empty?this:Ar(this,e,t)}mapPos(e,t=-1,i=Oe.Simple){let s=0,r=0;for(let o=0;o<this.sections.length;){let l=this.sections[o++],a=this.sections[o++],h=s+l;if(a<0){if(h>e)return r+(e-s);r+=l}else{if(i!=Oe.Simple&&h>=e&&(i==Oe.TrackDel&&s<e&&h>e||i==Oe.TrackBefore&&s<e||i==Oe.TrackAfter&&h>e))return null;if(h>e||h==e&&t<0&&!l)return e==s||t<0?r:r+a;r+=a}s=h}if(e>s)throw new RangeError(`Position ${e} is out of range for changeset of length ${s}`);return r}touchesRange(e,t=e){for(let i=0,s=0;i<this.sections.length&&s<=t;){let r=this.sections[i++],o=this.sections[i++],l=s+r;if(o>=0&&s<=t&&l>=e)return s<e&&l>t?"cover":!0;s=l}return!1}toString(){let e="";for(let t=0;t<this.sections.length;){let i=this.sections[t++],s=this.sections[t++];e+=(e?" ":"")+i+(s>=0?":"+s:"")}return e}toJSON(){return this.sections}static fromJSON(e){if(!Array.isArray(e)||e.length%2||e.some(t=>typeof t!="number"))throw new RangeError("Invalid JSON representation of ChangeDesc");return new ct(e)}static create(e){return new ct(e)}}class ie extends ct{constructor(e,t){super(e),this.inserted=t}apply(e){if(this.length!=e.length)throw new RangeError("Applying change set to a document with the wrong length");return Tr(this,(t,i,s,r,o)=>e=e.replace(s,s+(i-t),o),!1),e}mapDesc(e,t=!1){return Ar(this,e,t,!0)}invert(e){let t=this.sections.slice(),i=[];for(let s=0,r=0;s<t.length;s+=2){let o=t[s],l=t[s+1];if(l>=0){t[s]=l,t[s+1]=o;let a=s>>1;for(;i.length<a;)i.push(F.empty);i.push(o?e.slice(r,r+o):F.empty)}r+=o}return new ie(t,i)}compose(e){return this.empty?e:e.empty?this:yh(this,e,!0)}map(e,t=!1){return e.empty?this:Ar(this,e,t,!0)}iterChanges(e,t=!1){Tr(this,e,t)}get desc(){return ct.create(this.sections)}filter(e){let t=[],i=[],s=[],r=new $i(this);e:for(let o=0,l=0;;){let a=o==e.length?1e9:e[o++];for(;l<a||l==a&&r.len==0;){if(r.done)break e;let c=Math.min(r.len,a-l);fe(s,c,-1);let u=r.ins==-1?-1:r.off==0?r.ins:0;fe(t,c,u),u>0&&St(i,t,r.text),r.forward(c),l+=c}let h=e[o++];for(;l<h;){if(r.done)break e;let c=Math.min(r.len,h-l);fe(t,c,-1),fe(s,c,r.ins==-1?-1:r.off==0?r.ins:0),r.forward(c),l+=c}}return{changes:new ie(t,i),filtered:ct.create(s)}}toJSON(){let e=[];for(let t=0;t<this.sections.length;t+=2){let i=this.sections[t],s=this.sections[t+1];s<0?e.push(i):s==0?e.push([i]):e.push([i].concat(this.inserted[t>>1].toJSON()))}return e}static of(e,t,i){let s=[],r=[],o=0,l=null;function a(c=!1){if(!c&&!s.length)return;o<t&&fe(s,t-o,-1);let u=new ie(s,r);l=l?l.compose(u.map(l)):u,s=[],r=[],o=0}function h(c){if(Array.isArray(c))for(let u of c)h(u);else if(c instanceof ie){if(c.length!=t)throw new RangeError(`Mismatched change set length (got ${c.length}, expected ${t})`);a(),l=l?l.compose(c.map(l)):c}else{let{from:u,to:f=u,insert:d}=c;if(u>f||u<0||f>t)throw new RangeError(`Invalid change range ${u} to ${f} (in doc of length ${t})`);let p=d?typeof d=="string"?F.of(d.split(i||kr)):d:F.empty,m=p.length;if(u==f&&m==0)return;u<o&&a(),u>o&&fe(s,u-o,-1),fe(s,f-u,m),St(r,s,p),o=f}}return h(e),a(!l),l}static empty(e){return new ie(e?[e,-1]:[],[])}static fromJSON(e){if(!Array.isArray(e))throw new RangeError("Invalid JSON representation of ChangeSet");let t=[],i=[];for(let s=0;s<e.length;s++){let r=e[s];if(typeof r=="number")t.push(r,-1);else{if(!Array.isArray(r)||typeof r[0]!="number"||r.some((o,l)=>l&&typeof o!="string"))throw new RangeError("Invalid JSON representation of ChangeSet");if(r.length==1)t.push(r[0],0);else{for(;i.length<s;)i.push(F.empty);i[s]=F.of(r.slice(1)),t.push(r[0],i[s].length)}}}return new ie(t,i)}static createSet(e,t){return new ie(e,t)}}function fe(n,e,t,i=!1){if(e==0&&t<=0)return;let s=n.length-2;s>=0&&t<=0&&t==n[s+1]?n[s]+=e:s>=0&&e==0&&n[s]==0?n[s+1]+=t:i?(n[s]+=e,n[s+1]+=t):n.push(e,t)}function St(n,e,t){if(t.length==0)return;let i=e.length-2>>1;if(i<n.length)n[n.length-1]=n[n.length-1].append(t);else{for(;n.length<i;)n.push(F.empty);n.push(t)}}function Tr(n,e,t){let i=n.inserted;for(let s=0,r=0,o=0;o<n.sections.length;){let l=n.sections[o++],a=n.sections[o++];if(a<0)s+=l,r+=l;else{let h=s,c=r,u=F.empty;for(;h+=l,c+=a,a&&i&&(u=u.append(i[o-2>>1])),!(t||o==n.sections.length||n.sections[o+1]<0);)l=n.sections[o++],a=n.sections[o++];e(s,h,r,c,u),s=h,r=c}}}function Ar(n,e,t,i=!1){let s=[],r=i?[]:null,o=new $i(n),l=new $i(e);for(let a=-1;;){if(o.done&&l.len||l.done&&o.len)throw new Error("Mismatched change set lengths");if(o.ins==-1&&l.ins==-1){let h=Math.min(o.len,l.len);fe(s,h,-1),o.forward(h),l.forward(h)}else if(l.ins>=0&&(o.ins<0||a==o.i||o.off==0&&(l.len<o.len||l.len==o.len&&!t))){let h=l.len;for(fe(s,l.ins,-1);h;){let c=Math.min(o.len,h);o.ins>=0&&a<o.i&&o.len<=c&&(fe(s,0,o.ins),r&&St(r,s,o.text),a=o.i),o.forward(c),h-=c}l.next()}else if(o.ins>=0){let h=0,c=o.len;for(;c;)if(l.ins==-1){let u=Math.min(c,l.len);h+=u,c-=u,l.forward(u)}else if(l.ins==0&&l.len<c)c-=l.len,l.next();else break;fe(s,h,a<o.i?o.ins:0),r&&a<o.i&&St(r,s,o.text),a=o.i,o.forward(o.len-c)}else{if(o.done&&l.done)return r?ie.createSet(s,r):ct.create(s);throw new Error("Mismatched change set lengths")}}}function yh(n,e,t=!1){let i=[],s=t?[]:null,r=new $i(n),o=new $i(e);for(let l=!1;;){if(r.done&&o.done)return s?ie.createSet(i,s):ct.create(i);if(r.ins==0)fe(i,r.len,0,l),r.next();else if(o.len==0&&!o.done)fe(i,0,o.ins,l),s&&St(s,i,o.text),o.next();else{if(r.done||o.done)throw new Error("Mismatched change set lengths");{let a=Math.min(r.len2,o.len),h=i.length;if(r.ins==-1){let c=o.ins==-1?-1:o.off?0:o.ins;fe(i,a,c,l),s&&c&&St(s,i,o.text)}else o.ins==-1?(fe(i,r.off?0:r.len,a,l),s&&St(s,i,r.textBit(a))):(fe(i,r.off?0:r.len,o.off?0:o.ins,l),s&&!o.off&&St(s,i,o.text));l=(r.ins>a||o.ins>=0&&o.len>a)&&(l||i.length>h),r.forward2(a),o.forward(a)}}}}class $i{constructor(e){this.set=e,this.i=0,this.next()}next(){let{sections:e}=this.set;this.i<e.length?(this.len=e[this.i++],this.ins=e[this.i++]):(this.len=0,this.ins=-2),this.off=0}get done(){return this.ins==-2}get len2(){return this.ins<0?this.len:this.ins}get text(){let{inserted:e}=this.set,t=this.i-2>>1;return t>=e.length?F.empty:e[t]}textBit(e){let{inserted:t}=this.set,i=this.i-2>>1;return i>=t.length&&!e?F.empty:t[i].slice(this.off,e==null?void 0:this.off+e)}forward(e){e==this.len?this.next():(this.len-=e,this.off+=e)}forward2(e){this.ins==-1?this.forward(e):e==this.ins?this.next():(this.ins-=e,this.off+=e)}}class Ft{constructor(e,t,i){this.from=e,this.to=t,this.flags=i}get anchor(){return this.flags&32?this.to:this.from}get head(){return this.flags&32?this.from:this.to}get empty(){return this.from==this.to}get assoc(){return this.flags&8?-1:this.flags&16?1:0}get bidiLevel(){let e=this.flags&7;return e==7?null:e}get goalColumn(){let e=this.flags>>6;return e==16777215?void 0:e}map(e,t=-1){let i,s;return this.empty?i=s=e.mapPos(this.from,t):(i=e.mapPos(this.from,1),s=e.mapPos(this.to,-1)),i==this.from&&s==this.to?this:new Ft(i,s,this.flags)}extend(e,t=e,i=0){if(e<=this.anchor&&t>=this.anchor)return w.range(e,t,void 0,void 0,i);let s=Math.abs(e-this.anchor)>Math.abs(t-this.anchor)?e:t;return w.range(this.anchor,s,void 0,void 0,i)}eq(e,t=!1){return this.anchor==e.anchor&&this.head==e.head&&this.goalColumn==e.goalColumn&&(!t||!this.empty||this.assoc==e.assoc)}toJSON(){return{anchor:this.anchor,head:this.head}}static fromJSON(e){if(!e||typeof e.anchor!="number"||typeof e.head!="number")throw new RangeError("Invalid JSON representation for SelectionRange");return w.range(e.anchor,e.head)}static create(e,t,i){return new Ft(e,t,i)}}class w{constructor(e,t){this.ranges=e,this.mainIndex=t}map(e,t=-1){return e.empty?this:w.create(this.ranges.map(i=>i.map(e,t)),this.mainIndex)}eq(e,t=!1){if(this.ranges.length!=e.ranges.length||this.mainIndex!=e.mainIndex)return!1;for(let i=0;i<this.ranges.length;i++)if(!this.ranges[i].eq(e.ranges[i],t))return!1;return!0}get main(){return this.ranges[this.mainIndex]}asSingle(){return this.ranges.length==1?this:new w([this.main],0)}addRange(e,t=!0){return w.create([e].concat(this.ranges),t?0:this.mainIndex+1)}replaceRange(e,t=this.mainIndex){let i=this.ranges.slice();return i[t]=e,w.create(i,this.mainIndex)}toJSON(){return{ranges:this.ranges.map(e=>e.toJSON()),main:this.mainIndex}}static fromJSON(e){if(!e||!Array.isArray(e.ranges)||typeof e.main!="number"||e.main>=e.ranges.length)throw new RangeError("Invalid JSON representation for EditorSelection");return new w(e.ranges.map(t=>Ft.fromJSON(t)),e.main)}static single(e,t=e){return new w([w.range(e,t)],0)}static create(e,t=0){if(e.length==0)throw new RangeError("A selection needs at least one range");for(let i=0,s=0;s<e.length;s++){let r=e[s];if(r.empty?r.from<=i:r.from<i)return w.normalized(e.slice(),t);i=r.to}return new w(e,t)}static cursor(e,t=0,i,s){return Ft.create(e,e,(t==0?0:t<0?8:16)|(i==null?7:Math.min(6,i))|(s??16777215)<<6)}static range(e,t,i,s,r){let o=(i??16777215)<<6|(s==null?7:Math.min(6,s));return!r&&e!=t&&(r=t<e?1:-1),t<e?Ft.create(t,e,48|o):Ft.create(e,t,(r?r<0?8:16:0)|o)}static normalized(e,t=0){let i=e[t];e.sort((s,r)=>s.from-r.from),t=e.indexOf(i);for(let s=1;s<e.length;s++){let r=e[s],o=e[s-1];if(r.empty?r.from<=o.to:r.from<o.to){let l=o.from,a=Math.max(r.to,o.to);s<=t&&t--,e.splice(--s,2,r.anchor>r.head?w.range(a,l):w.range(l,a))}}return new w(e,t)}}function bh(n,e){for(let t of n.ranges)if(t.to>e)throw new RangeError("Selection points outside of document")}let bo=0;class E{constructor(e,t,i,s,r){this.combine=e,this.compareInput=t,this.compare=i,this.isStatic=s,this.id=bo++,this.default=e([]),this.extensions=typeof r=="function"?r(this):r}get reader(){return this}static define(e={}){return new E(e.combine||(t=>t),e.compareInput||((t,i)=>t===i),e.compare||(e.combine?(t,i)=>t===i:wo),!!e.static,e.enables)}of(e){return new Ps([],this,0,e)}compute(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ps(e,this,1,t)}computeN(e,t){if(this.isStatic)throw new Error("Can't compute a static facet");return new Ps(e,this,2,t)}from(e,t){return t||(t=i=>i),this.compute([e],i=>t(i.field(e)))}}function wo(n,e){return n==e||n.length==e.length&&n.every((t,i)=>t===e[i])}class Ps{constructor(e,t,i,s){this.dependencies=e,this.facet=t,this.type=i,this.value=s,this.id=bo++}dynamicSlot(e){var t;let i=this.value,s=this.facet.compareInput,r=this.id,o=e[r]>>1,l=this.type==2,a=!1,h=!1,c=[];for(let u of this.dependencies)u=="doc"?a=!0:u=="selection"?h=!0:(((t=e[u.id])!==null&&t!==void 0?t:1)&1)==0&&c.push(e[u.id]);return{create(u){return u.values[o]=i(u),1},update(u,f){if(a&&f.docChanged||h&&(f.docChanged||f.selection)||Mr(u,c)){let d=i(u);if(l?!ml(d,u.values[o],s):!s(d,u.values[o]))return u.values[o]=d,1}return 0},reconfigure:(u,f)=>{let d,p=f.config.address[r];if(p!=null){let m=Qs(f,p);if(this.dependencies.every(g=>g instanceof E?f.facet(g)===u.facet(g):g instanceof Ke?f.field(g,!1)==u.field(g,!1):!0)||(l?ml(d=i(u),m,s):s(d=i(u),m)))return u.values[o]=m,0}else d=i(u);return u.values[o]=d,1}}}}function ml(n,e,t){if(n.length!=e.length)return!1;for(let i=0;i<n.length;i++)if(!t(n[i],e[i]))return!1;return!0}function Mr(n,e){let t=!1;for(let i of e)_i(n,i)&1&&(t=!0);return t}function Zf(n,e,t){let i=t.map(a=>n[a.id]),s=t.map(a=>a.type),r=i.filter(a=>!(a&1)),o=n[e.id]>>1;function l(a){let h=[];for(let c=0;c<i.length;c++){let u=Qs(a,i[c]);if(s[c]==2)for(let f of u)h.push(f);else h.push(u)}return e.combine(h)}return{create(a){for(let h of i)_i(a,h);return a.values[o]=l(a),1},update(a,h){if(!Mr(a,r))return 0;let c=l(a);return e.compare(c,a.values[o])?0:(a.values[o]=c,1)},reconfigure(a,h){let c=Mr(a,i),u=h.config.facets[e.id],f=h.facet(e);if(u&&!c&&wo(t,u))return a.values[o]=f,0;let d=l(a);return e.compare(d,f)?(a.values[o]=f,0):(a.values[o]=d,1)}}}const ds=E.define({static:!0});class Ke{constructor(e,t,i,s,r){this.id=e,this.createF=t,this.updateF=i,this.compareF=s,this.spec=r,this.provides=void 0}static define(e){let t=new Ke(bo++,e.create,e.update,e.compare||((i,s)=>i===s),e);return e.provide&&(t.provides=e.provide(t)),t}create(e){let t=e.facet(ds).find(i=>i.field==this);return(t?.create||this.createF)(e)}slot(e){let t=e[this.id]>>1;return{create:i=>(i.values[t]=this.create(i),1),update:(i,s)=>{let r=i.values[t],o=this.updateF(r,s);return this.compareF(r,o)?0:(i.values[t]=o,1)},reconfigure:(i,s)=>{let r=i.facet(ds),o=s.facet(ds),l;return(l=r.find(a=>a.field==this))&&l!=o.find(a=>a.field==this)?(i.values[t]=l.create(i),1):s.config.address[this.id]!=null?(i.values[t]=s.field(this),0):(i.values[t]=this.create(i),1)}}}init(e){return[this,ds.of({field:this,create:e})]}get extension(){return this}}const _t={lowest:4,low:3,default:2,high:1,highest:0};function ki(n){return e=>new wh(e,n)}const Ci={highest:ki(_t.highest),high:ki(_t.high),default:ki(_t.default),low:ki(_t.low),lowest:ki(_t.lowest)};class wh{constructor(e,t){this.inner=e,this.prec=t}}class Sn{of(e){return new Er(this,e)}reconfigure(e){return Sn.reconfigure.of({compartment:this,extension:e})}get(e){return e.config.compartments.get(this)}}class Er{constructor(e,t){this.compartment=e,this.inner=t}}class qs{constructor(e,t,i,s,r,o){for(this.base=e,this.compartments=t,this.dynamicSlots=i,this.address=s,this.staticValues=r,this.facets=o,this.statusTemplate=[];this.statusTemplate.length<i.length;)this.statusTemplate.push(0)}staticFacet(e){let t=this.address[e.id];return t==null?e.default:this.staticValues[t>>1]}static resolve(e,t,i){let s=[],r=Object.create(null),o=new Map;for(let f of ed(e,t,o))f instanceof Ke?s.push(f):(r[f.facet.id]||(r[f.facet.id]=[])).push(f);let l=Object.create(null),a=[],h=[];for(let f of s)l[f.id]=h.length<<1,h.push(d=>f.slot(d));let c=i?.config.facets;for(let f in r){let d=r[f],p=d[0].facet,m=c&&c[f]||[];if(d.every(g=>g.type==0))if(l[p.id]=a.length<<1|1,wo(m,d))a.push(i.facet(p));else{let g=p.combine(d.map(y=>y.value));a.push(i&&p.compare(g,i.facet(p))?i.facet(p):g)}else{for(let g of d)g.type==0?(l[g.id]=a.length<<1|1,a.push(g.value)):(l[g.id]=h.length<<1,h.push(y=>g.dynamicSlot(y)));l[p.id]=h.length<<1,h.push(g=>Zf(g,p,d))}}let u=h.map(f=>f(l));return new qs(e,o,u,l,a,r)}}function ed(n,e,t){let i=[[],[],[],[],[]],s=new Map;function r(o,l){let a=s.get(o);if(a!=null){if(a<=l)return;let h=i[a].indexOf(o);h>-1&&i[a].splice(h,1),o instanceof Er&&t.delete(o.compartment)}if(s.set(o,l),Array.isArray(o))for(let h of o)r(h,l);else if(o instanceof Er){if(t.has(o.compartment))throw new RangeError("Duplicate use of compartment in extensions");let h=e.get(o.compartment)||o.inner;t.set(o.compartment,h),r(h,l)}else if(o instanceof wh)r(o.inner,o.prec);else if(o instanceof Ke)i[l].push(o),o.provides&&r(o.provides,l);else if(o instanceof Ps)i[l].push(o),o.facet.extensions&&r(o.facet.extensions,_t.default);else{let h=o.extension;if(!h)throw new Error(`Unrecognized extension value in extension set (${o}). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.`);r(h,l)}}return r(n,_t.default),i.reduce((o,l)=>o.concat(l))}function _i(n,e){if(e&1)return 2;let t=e>>1,i=n.status[t];if(i==4)throw new Error("Cyclic dependency between fields and/or facets");if(i&2)return i;n.status[t]=4;let s=n.computeSlot(n,n.config.dynamicSlots[t]);return n.status[t]=2|s}function Qs(n,e){return e&1?n.config.staticValues[e>>1]:n.values[e>>1]}const Ch=E.define(),Or=E.define({combine:n=>n.some(e=>e),static:!0}),xh=E.define({combine:n=>n.length?n[0]:void 0,static:!0}),Sh=E.define(),vh=E.define(),kh=E.define(),Th=E.define({combine:n=>n.length?n[0]:!1});class gt{constructor(e,t){this.type=e,this.value=t}static define(){return new td}}class td{of(e){return new gt(this,e)}}class id{constructor(e){this.map=e}of(e){return new H(this,e)}}class H{constructor(e,t){this.type=e,this.value=t}map(e){let t=this.type.map(this.value,e);return t===void 0?void 0:t==this.value?this:new H(this.type,t)}is(e){return this.type==e}static define(e={}){return new id(e.map||(t=>t))}static mapEffects(e,t){if(!e.length)return e;let i=[];for(let s of e){let r=s.map(t);r&&i.push(r)}return i}}H.reconfigure=H.define();H.appendConfig=H.define();class se{constructor(e,t,i,s,r,o){this.startState=e,this.changes=t,this.selection=i,this.effects=s,this.annotations=r,this.scrollIntoView=o,this._doc=null,this._state=null,i&&bh(i,t.newLength),r.some(l=>l.type==se.time)||(this.annotations=r.concat(se.time.of(Date.now())))}static create(e,t,i,s,r,o){return new se(e,t,i,s,r,o)}get newDoc(){return this._doc||(this._doc=this.changes.apply(this.startState.doc))}get newSelection(){return this.selection||this.startState.selection.map(this.changes)}get state(){return this._state||this.startState.applyTransaction(this),this._state}annotation(e){for(let t of this.annotations)if(t.type==e)return t.value}get docChanged(){return!this.changes.empty}get reconfigured(){return this.startState.config!=this.state.config}isUserEvent(e){let t=this.annotation(se.userEvent);return!!(t&&(t==e||t.length>e.length&&t.slice(0,e.length)==e&&t[e.length]=="."))}}se.time=gt.define();se.userEvent=gt.define();se.addToHistory=gt.define();se.remote=gt.define();function sd(n,e){let t=[];for(let i=0,s=0;;){let r,o;if(i<n.length&&(s==e.length||e[s]>=n[i]))r=n[i++],o=n[i++];else if(s<e.length)r=e[s++],o=e[s++];else return t;!t.length||t[t.length-1]<r?t.push(r,o):t[t.length-1]<o&&(t[t.length-1]=o)}}function Ah(n,e,t){var i;let s,r,o;return t?(s=e.changes,r=ie.empty(e.changes.length),o=n.changes.compose(e.changes)):(s=e.changes.map(n.changes),r=n.changes.mapDesc(e.changes,!0),o=n.changes.compose(s)),{changes:o,selection:e.selection?e.selection.map(r):(i=n.selection)===null||i===void 0?void 0:i.map(s),effects:H.mapEffects(n.effects,s).concat(H.mapEffects(e.effects,r)),annotations:n.annotations.length?n.annotations.concat(e.annotations):e.annotations,scrollIntoView:n.scrollIntoView||e.scrollIntoView}}function Dr(n,e,t){let i=e.selection,s=ri(e.annotations);return e.userEvent&&(s=s.concat(se.userEvent.of(e.userEvent))),{changes:e.changes instanceof ie?e.changes:ie.of(e.changes||[],t,n.facet(xh)),selection:i&&(i instanceof w?i:w.single(i.anchor,i.head)),effects:ri(e.effects),annotations:s,scrollIntoView:!!e.scrollIntoView}}function Mh(n,e,t){let i=Dr(n,e.length?e[0]:{},n.doc.length);e.length&&e[0].filter===!1&&(t=!1);for(let r=1;r<e.length;r++){e[r].filter===!1&&(t=!1);let o=!!e[r].sequential;i=Ah(i,Dr(n,e[r],o?i.changes.newLength:n.doc.length),o)}let s=se.create(n,i.changes,i.selection,i.effects,i.annotations,i.scrollIntoView);return rd(t?nd(s):s)}function nd(n){let e=n.startState,t=!0;for(let s of e.facet(Sh)){let r=s(n);if(r===!1){t=!1;break}Array.isArray(r)&&(t=t===!0?r:sd(t,r))}if(t!==!0){let s,r;if(t===!1)r=n.changes.invertedDesc,s=ie.empty(e.doc.length);else{let o=n.changes.filter(t);s=o.changes,r=o.filtered.mapDesc(o.changes).invertedDesc}n=se.create(e,s,n.selection&&n.selection.map(r),H.mapEffects(n.effects,r),n.annotations,n.scrollIntoView)}let i=e.facet(vh);for(let s=i.length-1;s>=0;s--){let r=i[s](n);r instanceof se?n=r:Array.isArray(r)&&r.length==1&&r[0]instanceof se?n=r[0]:n=Mh(e,ri(r),!1)}return n}function rd(n){let e=n.startState,t=e.facet(kh),i=n;for(let s=t.length-1;s>=0;s--){let r=t[s](n);r&&Object.keys(r).length&&(i=Ah(i,Dr(e,r,n.changes.newLength),!0))}return i==n?n:se.create(e,n.changes,n.selection,i.effects,i.annotations,i.scrollIntoView)}const od=[];function ri(n){return n==null?od:Array.isArray(n)?n:[n]}var ce=function(n){return n[n.Word=0]="Word",n[n.Space=1]="Space",n[n.Other=2]="Other",n}(ce||(ce={}));const ld=/[\u00df\u0587\u0590-\u05f4\u0600-\u06ff\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;let Rr;try{Rr=new RegExp("[\\p{Alphabetic}\\p{Number}_]","u")}catch{}function ad(n){if(Rr)return Rr.test(n);for(let e=0;e<n.length;e++){let t=n[e];if(/\w/.test(t)||t>"Â"&&(t.toUpperCase()!=t.toLowerCase()||ld.test(t)))return!0}return!1}function hd(n){return e=>{if(!/\S/.test(e))return ce.Space;if(ad(e))return ce.Word;for(let t=0;t<n.length;t++)if(e.indexOf(n[t])>-1)return ce.Word;return ce.Other}}class W{constructor(e,t,i,s,r,o){this.config=e,this.doc=t,this.selection=i,this.values=s,this.status=e.statusTemplate.slice(),this.computeSlot=r,o&&(o._state=this);for(let l=0;l<this.config.dynamicSlots.length;l++)_i(this,l<<1);this.computeSlot=null}field(e,t=!0){let i=this.config.address[e.id];if(i==null){if(t)throw new RangeError("Field is not present in this state");return}return _i(this,i),Qs(this,i)}update(...e){return Mh(this,e,!0)}applyTransaction(e){let t=this.config,{base:i,compartments:s}=t;for(let l of e.effects)l.is(Sn.reconfigure)?(t&&(s=new Map,t.compartments.forEach((a,h)=>s.set(h,a)),t=null),s.set(l.value.compartment,l.value.extension)):l.is(H.reconfigure)?(t=null,i=l.value):l.is(H.appendConfig)&&(t=null,i=ri(i).concat(l.value));let r;t?r=e.startState.values.slice():(t=qs.resolve(i,s,this),r=new W(t,this.doc,this.selection,t.dynamicSlots.map(()=>null),(a,h)=>h.reconfigure(a,this),null).values);let o=e.startState.facet(Or)?e.newSelection:e.newSelection.asSingle();new W(t,e.newDoc,o,r,(l,a)=>a.update(l,e),e)}replaceSelection(e){return typeof e=="string"&&(e=this.toText(e)),this.changeByRange(t=>({changes:{from:t.from,to:t.to,insert:e},range:w.cursor(t.from+e.length)}))}changeByRange(e){let t=this.selection,i=e(t.ranges[0]),s=this.changes(i.changes),r=[i.range],o=ri(i.effects);for(let l=1;l<t.ranges.length;l++){let a=e(t.ranges[l]),h=this.changes(a.changes),c=h.map(s);for(let f=0;f<l;f++)r[f]=r[f].map(c);let u=s.mapDesc(h,!0);r.push(a.range.map(u)),s=s.compose(c),o=H.mapEffects(o,c).concat(H.mapEffects(ri(a.effects),u))}return{changes:s,selection:w.create(r,t.mainIndex),effects:o}}changes(e=[]){return e instanceof ie?e:ie.of(e,this.doc.length,this.facet(W.lineSeparator))}toText(e){return F.of(e.split(this.facet(W.lineSeparator)||kr))}sliceDoc(e=0,t=this.doc.length){return this.doc.sliceString(e,t,this.lineBreak)}facet(e){let t=this.config.address[e.id];return t==null?e.default:(_i(this,t),Qs(this,t))}toJSON(e){let t={doc:this.sliceDoc(),selection:this.selection.toJSON()};if(e)for(let i in e){let s=e[i];s instanceof Ke&&this.config.address[s.id]!=null&&(t[i]=s.spec.toJSON(this.field(e[i]),this))}return t}static fromJSON(e,t={},i){if(!e||typeof e.doc!="string")throw new RangeError("Invalid JSON representation for EditorState");let s=[];if(i){for(let r in i)if(Object.prototype.hasOwnProperty.call(e,r)){let o=i[r],l=e[r];s.push(o.init(a=>o.spec.fromJSON(l,a)))}}return W.create({doc:e.doc,selection:w.fromJSON(e.selection),extensions:t.extensions?s.concat([t.extensions]):s})}static create(e={}){let t=qs.resolve(e.extensions||[],new Map),i=e.doc instanceof F?e.doc:F.of((e.doc||"").split(t.staticFacet(W.lineSeparator)||kr)),s=e.selection?e.selection instanceof w?e.selection:w.single(e.selection.anchor,e.selection.head):w.single(0);return bh(s,i.length),t.staticFacet(Or)||(s=s.asSingle()),new W(t,i,s,t.dynamicSlots.map(()=>null),(r,o)=>o.create(r),null)}get tabSize(){return this.facet(W.tabSize)}get lineBreak(){return this.facet(W.lineSeparator)||` 174`}get readOnly(){return this.facet(Th)}phrase(e,...t){for(let i of this.facet(W.phrases))if(Object.prototype.hasOwnProperty.call(i,e)){e=i[e];break}return t.length&&(e=e.replace(/\$(\$|\d*)/g,(i,s)=>{if(s=="$")return"$";let r=+(s||1);return!r||r>t.length?i:t[r-1]})),e}languageDataAt(e,t,i=-1){let s=[];for(let r of this.facet(Ch))for(let o of r(this,t,i))Object.prototype.hasOwnProperty.call(o,e)&&s.push(o[e]);return s}charCategorizer(e){let t=this.languageDataAt("wordChars",e);return hd(t.length?t[0]:"")}wordAt(e){let{text:t,from:i,length:s}=this.doc.lineAt(e),r=this.charCategorizer(e),o=e-i,l=e-i;for(;o>0;){let a=oe(t,o,!1);if(r(t.slice(a,o))!=ce.Word)break;o=a}for(;l<s;){let a=oe(t,l);if(r(t.slice(l,a))!=ce.Word)break;l=a}return o==l?null:w.range(o+i,l+i)}}W.allowMultipleSelections=Or;W.tabSize=E.define({combine:n=>n.length?n[0]:4});W.lineSeparator=xh;W.readOnly=Th;W.phrases=E.define({compare(n,e){let t=Object.keys(n),i=Object.keys(e);return t.length==i.length&&t.every(s=>n[s]==e[s])}});W.languageData=Ch;W.changeFilter=Sh;W.transactionFilter=vh;W.transactionExtender=kh;Sn.reconfigure=H.define();function vn(n,e,t={}){let i={};for(let s of n)for(let r of Object.keys(s)){let o=s[r],l=i[r];if(l===void 0)i[r]=o;else if(!(l===o||o===void 0))if(Object.hasOwnProperty.call(t,r))i[r]=t[r](l,o);else throw new Error("Config merge conflict for field "+r)}for(let s in e)i[s]===void 0&&(i[s]=e[s]);return i}class Tt{eq(e){return this==e}range(e,t=e){return Lr.create(e,t,this)}}Tt.prototype.startSide=Tt.prototype.endSide=0;Tt.prototype.point=!1;Tt.prototype.mapMode=Oe.TrackDel;function Co(n,e){return n==e||n.constructor==e.constructor&&n.eq(e)}let Lr=class Eh{constructor(e,t,i){this.from=e,this.to=t,this.value=i}static create(e,t,i){return new Eh(e,t,i)}};function Ir(n,e){return n.from-e.from||n.value.startSide-e.value.startSide}class xo{constructor(e,t,i,s){this.from=e,this.to=t,this.value=i,this.maxPoint=s}get length(){return this.to[this.to.length-1]}findIndex(e,t,i,s=0){let r=i?this.to:this.from;for(let o=s,l=r.length;;){if(o==l)return o;let a=o+l>>1,h=r[a]-e||(i?this.value[a].endSide:this.value[a].startSide)-t;if(a==o)return h>=0?o:l;h>=0?l=a:o=a+1}}between(e,t,i,s){for(let r=this.findIndex(t,-1e9,!0),o=this.findIndex(i,1e9,!1,r);r<o;r++)if(s(this.from[r]+e,this.to[r]+e,this.value[r])===!1)return!1}map(e,t){let i=[],s=[],r=[],o=-1,l=-1;for(let a=0;a<this.value.length;a++){let h=this.value[a],c=this.from[a]+e,u=this.to[a]+e,f,d;if(c==u){let p=t.mapPos(c,h.startSide,h.mapMode);if(p==null||(f=d=p,h.startSide!=h.endSide&&(d=t.mapPos(c,h.endSide),d<f)))continue}else if(f=t.mapPos(c,h.startSide),d=t.mapPos(u,h.endSide),f>d||f==d&&h.startSide>0&&h.endSide<=0)continue;(d-f||h.endSide-h.startSide)<0||(o<0&&(o=f),h.point&&(l=Math.max(l,d-f)),i.push(h),s.push(f-o),r.push(d-o))}return{mapped:i.length?new xo(s,r,i,l):null,pos:o}}}class P{constructor(e,t,i,s){this.chunkPos=e,this.chunk=t,this.nextLayer=i,this.maxPoint=s}static create(e,t,i,s){return new P(e,t,i,s)}get length(){let e=this.chunk.length-1;return e<0?0:Math.max(this.chunkEnd(e),this.nextLayer.length)}get size(){if(this.isEmpty)return 0;let e=this.nextLayer.size;for(let t of this.chunk)e+=t.value.length;return e}chunkEnd(e){return this.chunkPos[e]+this.chunk[e].length}update(e){let{add:t=[],sort:i=!1,filterFrom:s=0,filterTo:r=this.length}=e,o=e.filter;if(t.length==0&&!o)return this;if(i&&(t=t.slice().sort(Ir)),this.isEmpty)return t.length?P.of(t):this;let l=new Oh(this,null,-1).goto(0),a=0,h=[],c=new di;for(;l.value||a<t.length;)if(a<t.length&&(l.from-t[a].from||l.startSide-t[a].value.startSide)>=0){let u=t[a++];c.addInner(u.from,u.to,u.value)||h.push(u)}else l.rangeIndex==1&&l.chunkIndex<this.chunk.length&&(a==t.length||this.chunkEnd(l.chunkIndex)<t[a].from)&&(!o||s>this.chunkEnd(l.chunkIndex)||r<this.chunkPos[l.chunkIndex])&&c.addChunk(this.chunkPos[l.chunkIndex],this.chunk[l.chunkIndex])?l.nextChunk():((!o||s>l.to||r<l.from||o(l.from,l.to,l.value))&&(c.addInner(l.from,l.to,l.value)||h.push(Lr.create(l.from,l.to,l.value))),l.next());return c.finishInner(this.nextLayer.isEmpty&&!h.length?P.empty:this.nextLayer.update({add:h,filter:o,filterFrom:s,filterTo:r}))}map(e){if(e.empty||this.isEmpty)return this;let t=[],i=[],s=-1;for(let o=0;o<this.chunk.length;o++){let l=this.chunkPos[o],a=this.chunk[o],h=e.touchesRange(l,l+a.length);if(h===!1)s=Math.max(s,a.maxPoint),t.push(a),i.push(e.mapPos(l));else if(h===!0){let{mapped:c,pos:u}=a.map(l,e);c&&(s=Math.max(s,c.maxPoint),t.push(c),i.push(u))}}let r=this.nextLayer.map(e);return t.length==0?r:new P(i,t,r||P.empty,s)}between(e,t,i){if(!this.isEmpty){for(let s=0;s<this.chunk.length;s++){let r=this.chunkPos[s],o=this.chunk[s];if(t>=r&&e<=r+o.length&&o.between(r,e-r,t-r,i)===!1)return}this.nextLayer.between(e,t,i)}}iter(e=0){return Ui.from([this]).goto(e)}get isEmpty(){return this.nextLayer==this}static iter(e,t=0){return Ui.from(e).goto(t)}static compare(e,t,i,s,r=-1){let o=e.filter(u=>u.maxPoint>0||!u.isEmpty&&u.maxPoint>=r),l=t.filter(u=>u.maxPoint>0||!u.isEmpty&&u.maxPoint>=r),a=gl(o,l,i),h=new Ti(o,a,r),c=new Ti(l,a,r);i.iterGaps((u,f,d)=>yl(h,u,c,f,d,s)),i.empty&&i.length==0&&yl(h,0,c,0,0,s)}static eq(e,t,i=0,s){s==null&&(s=999999999);let r=e.filter(c=>!c.isEmpty&&t.indexOf(c)<0),o=t.filter(c=>!c.isEmpty&&e.indexOf(c)<0);if(r.length!=o.length)return!1;if(!r.length)return!0;let l=gl(r,o),a=new Ti(r,l,0).goto(i),h=new Ti(o,l,0).goto(i);for(;;){if(a.to!=h.to||!Nr(a.active,h.active)||a.point&&(!h.point||!Co(a.point,h.point)))return!1;if(a.to>s)return!0;a.next(),h.next()}}static spans(e,t,i,s,r=-1){let o=new Ti(e,null,r).goto(t),l=t,a=o.openStart;for(;;){let h=Math.min(o.to,i);if(o.point){let c=o.activeForPoint(o.to),u=o.pointFrom<t?c.length+1:o.point.startSide<0?c.length:Math.min(c.length,a);s.point(l,h,o.point,c,u,o.pointRank),a=Math.min(o.openEnd(h),c.length)}else h>l&&(s.span(l,h,o.active,a),a=o.openEnd(h));if(o.to>i)return a+(o.point&&o.to>i?1:0);l=o.to,o.next()}}static of(e,t=!1){let i=new di;for(let s of e instanceof Lr?[e]:t?cd(e):e)i.add(s.from,s.to,s.value);return i.finish()}static join(e){if(!e.length)return P.empty;let t=e[e.length-1];for(let i=e.length-2;i>=0;i--)for(let s=e[i];s!=P.empty;s=s.nextLayer)t=new P(s.chunkPos,s.chunk,t,Math.max(s.maxPoint,t.maxPoint));return t}}P.empty=new P([],[],null,-1);function cd(n){if(n.length>1)for(let e=n[0],t=1;t<n.length;t++){let i=n[t];if(Ir(e,i)>0)return n.slice().sort(Ir);e=i}return n}P.empty.nextLayer=P.empty;class di{finishChunk(e){this.chunks.push(new xo(this.from,this.to,this.value,this.maxPoint)),this.chunkPos.push(this.chunkStart),this.chunkStart=-1,this.setMaxPoint=Math.max(this.setMaxPoint,this.maxPoint),this.maxPoint=-1,e&&(this.from=[],this.to=[],this.value=[])}constructor(){this.chunks=[],this.chunkPos=[],this.chunkStart=-1,this.last=null,this.lastFrom=-1e9,this.lastTo=-1e9,this.from=[],this.to=[],this.value=[],this.maxPoint=-1,this.setMaxPoint=-1,this.nextLayer=null}add(e,t,i){this.addInner(e,t,i)||(this.nextLayer||(this.nextLayer=new di)).add(e,t,i)}addInner(e,t,i){let s=e-this.lastTo||i.startSide-this.last.endSide;if(s<=0&&(e-this.lastFrom||i.startSide-this.last.startSide)<0)throw new Error("Ranges must be added sorted by `from` position and `startSide`");return s<0?!1:(this.from.length==250&&this.finishChunk(!0),this.chunkStart<0&&(this.chunkStart=e),this.from.push(e-this.chunkStart),this.to.push(t-this.chunkStart),this.last=i,this.lastFrom=e,this.lastTo=t,this.value.push(i),i.point&&(this.maxPoint=Math.max(this.maxPoint,t-e)),!0)}addChunk(e,t){if((e-this.lastTo||t.value[0].startSide-this.last.endSide)<0)return!1;this.from.length&&this.finishChunk(!0),this.setMaxPoint=Math.max(this.setMaxPoint,t.maxPoint),this.chunks.push(t),this.chunkPos.push(e);let i=t.value.length-1;return this.last=t.value[i],this.lastFrom=t.from[i]+e,this.lastTo=t.to[i]+e,!0}finish(){return this.finishInner(P.empty)}finishInner(e){if(this.from.length&&this.finishChunk(!1),this.chunks.length==0)return e;let t=P.create(this.chunkPos,this.chunks,this.nextLayer?this.nextLayer.finishInner(e):e,this.setMaxPoint);return this.from=null,t}}function gl(n,e,t){let i=new Map;for(let r of n)for(let o=0;o<r.chunk.length;o++)r.chunk[o].maxPoint<=0&&i.set(r.chunk[o],r.chunkPos[o]);let s=new Set;for(let r of e)for(let o=0;o<r.chunk.length;o++){let l=i.get(r.chunk[o]);l!=null&&(t?t.mapPos(l):l)==r.chunkPos[o]&&!t?.touchesRange(l,l+r.chunk[o].length)&&s.add(r.chunk[o])}return s}class Oh{constructor(e,t,i,s=0){this.layer=e,this.skip=t,this.minPoint=i,this.rank=s}get startSide(){return this.value?this.value.startSide:0}get endSide(){return this.value?this.value.endSide:0}goto(e,t=-1e9){return this.chunkIndex=this.rangeIndex=0,this.gotoInner(e,t,!1),this}gotoInner(e,t,i){for(;this.chunkIndex<this.layer.chunk.length;){let s=this.layer.chunk[this.chunkIndex];if(!(this.skip&&this.skip.has(s)||this.layer.chunkEnd(this.chunkIndex)<e||s.maxPoint<this.minPoint))break;this.chunkIndex++,i=!1}if(this.chunkIndex<this.layer.chunk.length){let s=this.layer.chunk[this.chunkIndex].findIndex(e-this.layer.chunkPos[this.chunkIndex],t,!0);(!i||this.rangeIndex<s)&&this.setRangeIndex(s)}this.next()}forward(e,t){(this.to-e||this.endSide-t)<0&&this.gotoInner(e,t,!0)}next(){for(;;)if(this.chunkIndex==this.layer.chunk.length){this.from=this.to=1e9,this.value=null;break}else{let e=this.layer.chunkPos[this.chunkIndex],t=this.layer.chunk[this.chunkIndex],i=e+t.from[this.rangeIndex];if(this.from=i,this.to=e+t.to[this.rangeIndex],this.value=t.value[this.rangeIndex],this.setRangeIndex(this.rangeIndex+1),this.minPoint<0||this.value.point&&this.to-this.from>=this.minPoint)break}}setRangeIndex(e){if(e==this.layer.chunk[this.chunkIndex].value.length){if(this.chunkIndex++,this.skip)for(;this.chunkIndex<this.layer.chunk.length&&this.skip.has(this.layer.chunk[this.chunkIndex]);)this.chunkIndex++;this.rangeIndex=0}else this.rangeIndex=e}nextChunk(){this.chunkIndex++,this.rangeIndex=0,this.next()}compare(e){return this.from-e.from||this.startSide-e.startSide||this.rank-e.rank||this.to-e.to||this.endSide-e.endSide}}class Ui{constructor(e){this.heap=e}static from(e,t=null,i=-1){let s=[];for(let r=0;r<e.length;r++)for(let o=e[r];!o.isEmpty;o=o.nextLayer)o.maxPoint>=i&&s.push(new Oh(o,t,i,r));return s.length==1?s[0]:new Ui(s)}get startSide(){return this.value?this.value.startSide:0}goto(e,t=-1e9){for(let i of this.heap)i.goto(e,t);for(let i=this.heap.length>>1;i>=0;i--)Hn(this.heap,i);return this.next(),this}forward(e,t){for(let i of this.heap)i.forward(e,t);for(let i=this.heap.length>>1;i>=0;i--)Hn(this.heap,i);(this.to-e||this.value.endSide-t)<0&&this.next()}next(){if(this.heap.length==0)this.from=this.to=1e9,this.value=null,this.rank=-1;else{let e=this.heap[0];this.from=e.from,this.to=e.to,this.value=e.value,this.rank=e.rank,e.value&&e.next(),Hn(this.heap,0)}}}function Hn(n,e){for(let t=n[e];;){let i=(e<<1)+1;if(i>=n.length)break;let s=n[i];
vendor: 4,577 bytes, lines 174-175
174if(i+1<n.length&&s.compare(n[i+1])>=0&&(s=n[i+1],i++),t.compare(s)<0)break;n[i]=t,n[e]=s,e=i}}class Ti{constructor(e,t,i){this.minPoint=i,this.active=[],this.activeTo=[],this.activeRank=[],this.minActive=-1,this.point=null,this.pointFrom=0,this.pointRank=0,this.to=-1e9,this.endSide=0,this.openStart=-1,this.cursor=Ui.from(e,t,i)}goto(e,t=-1e9){return this.cursor.goto(e,t),this.active.length=this.activeTo.length=this.activeRank.length=0,this.minActive=-1,this.to=e,this.endSide=t,this.openStart=-1,this.next(),this}forward(e,t){for(;this.minActive>-1&&(this.activeTo[this.minActive]-e||this.active[this.minActive].endSide-t)<0;)this.removeActive(this.minActive);this.cursor.forward(e,t)}removeActive(e){ps(this.active,e),ps(this.activeTo,e),ps(this.activeRank,e),this.minActive=bl(this.active,this.activeTo)}addActive(e){let t=0,{value:i,to:s,rank:r}=this.cursor;for(;t<this.activeRank.length&&(r-this.activeRank[t]||s-this.activeTo[t])>0;)t++;ms(this.active,t,i),ms(this.activeTo,t,s),ms(this.activeRank,t,r),e&&ms(e,t,this.cursor.from),this.minActive=bl(this.active,this.activeTo)}next(){let e=this.to,t=this.point;this.point=null;let i=this.openStart<0?[]:null;for(;;){let s=this.minActive;if(s>-1&&(this.activeTo[s]-this.cursor.from||this.active[s].endSide-this.cursor.startSide)<0){if(this.activeTo[s]>e){this.to=this.activeTo[s],this.endSide=this.active[s].endSide;break}this.removeActive(s),i&&ps(i,s)}else if(this.cursor.value)if(this.cursor.from>e){this.to=this.cursor.from,this.endSide=this.cursor.startSide;break}else{let r=this.cursor.value;if(!r.point)this.addActive(i),this.cursor.next();else if(t&&this.cursor.to==this.to&&this.cursor.from<this.cursor.to)this.cursor.next();else{this.point=r,this.pointFrom=this.cursor.from,this.pointRank=this.cursor.rank,this.to=this.cursor.to,this.endSide=r.endSide,this.cursor.next(),this.forward(this.to,this.endSide);break}}else{this.to=this.endSide=1e9;break}}if(i){this.openStart=0;for(let s=i.length-1;s>=0&&i[s]<e;s--)this.openStart++}}activeForPoint(e){if(!this.active.length)return this.active;let t=[];for(let i=this.active.length-1;i>=0&&!(this.activeRank[i]<this.pointRank);i--)(this.activeTo[i]>e||this.activeTo[i]==e&&this.active[i].endSide>=this.point.endSide)&&t.push(this.active[i]);return t.reverse()}openEnd(e){let t=0;for(let i=this.activeTo.length-1;i>=0&&this.activeTo[i]>e;i--)t++;return t}}function yl(n,e,t,i,s,r){n.goto(e),t.goto(i);let o=i+s,l=i,a=i-e,h=!!r.boundChange;for(let c=!1;;){let u=n.to+a-t.to,f=u||n.endSide-t.endSide,d=f<0?n.to+a:t.to,p=Math.min(d,o);if(n.point||t.point?(n.point&&t.point&&Co(n.point,t.point)&&Nr(n.activeForPoint(n.to),t.activeForPoint(t.to))||r.comparePoint(l,p,n.point,t.point),c=!1):(c&&r.boundChange(l),p>l&&!Nr(n.active,t.active)&&r.compareRange(l,p,n.active,t.active),h&&p<o&&(u||n.openEnd(d)!=t.openEnd(d))&&(c=!0)),d>o)break;l=d,f<=0&&n.next(),f>=0&&t.next()}}function Nr(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(n[t]!=e[t]&&!Co(n[t],e[t]))return!1;return!0}function ps(n,e){for(let t=e,i=n.length-1;t<i;t++)n[t]=n[t+1];n.pop()}function ms(n,e,t){for(let i=n.length-1;i>=e;i--)n[i+1]=n[i];n[e]=t}function bl(n,e){let t=-1,i=1e9;for(let s=0;s<e.length;s++)(e[s]-i||n[s].endSide-n[t].endSide)<0&&(t=s,i=e[s]);return t}function kn(n,e,t=n.length){let i=0;for(let s=0;s<t&&s<n.length;)n.charCodeAt(s)==9?(i+=e-i%e,s++):(i++,s=oe(n,s));return i}function ud(n,e,t,i){for(let s=0,r=0;;){if(r>=e)return s;if(s==n.length)break;r+=n.charCodeAt(s)==9?t-r%t:1,s=oe(n,s)}return n.length}const Br="ͼ",wl=typeof Symbol>"u"?"__"+Br:Symbol.for(Br),_r=typeof Symbol>"u"?"__styleSet"+Math.floor(Math.random()*1e8):Symbol("styleSet"),Cl=typeof globalThis<"u"?globalThis:typeof window<"u"?window:{};class At{constructor(e,t){this.rules=[];let{finish:i}=t||{};function s(o){return/^@/.test(o)?[o]:o.split(/,\s*/)}function r(o,l,a,h){let c=[],u=/^@(\w+)\b/.exec(o[0]),f=u&&u[1]=="keyframes";if(u&&l==null)return a.push(o[0]+";");for(let d in l){let p=l[d];if(/&/.test(d))r(d.split(/,\s*/).map(m=>o.map(g=>m.replace(/&/,g))).reduce((m,g)=>m.concat(g)),p,a);else if(p&&typeof p=="object"){if(!u)throw new RangeError("The value of a property ("+d+") should be a primitive value.");r(s(d),p,c,f)}else p!=null&&c.push(d.replace(/_.*/,"").replace(/[A-Z]/g,m=>"-"+m.toLowerCase())+": "+p+";")}(c.length||f)&&a.push((i&&!u&&!h?o.map(i):o).join(", ")+" {"+c.join(" ")+"}")}for(let o in e)r(s(o),e[o],this.rules)}getRules(){return this.rules.join(` 175`)}static newName(){let e=Cl[wl]||1;return Cl[wl]=e+1,Br+e.toString(36)}static mount(e,t,i){let s=e[_r],r=i&&i.nonce;
175s?r&&s.setNonce(r):s=new fd(e,r),s.mount(Array.isArray(t)?t:[t],e)}}let xl=new Map;class fd{constructor(e,t){let i=e.ownerDocument||e,s=i.defaultView;if(!e.head&&e.adoptedStyleSheets&&s.CSSStyleSheet){let r=xl.get(i);if(r)return e[_r]=r;this.sheet=new s.CSSStyleSheet,xl.set(i,this)}else this.styleTag=i.createElement("style"),t&&this.styleTag.setAttribute("nonce",t);this.modules=[],e[_r]=this}mount(e,t){let i=this.sheet,s=0,r=0;for(let o=0;o<e.length;o++){let l=e[o],a=this.modules.indexOf(l);if(a<r&&a>-1&&(this.modules.splice(a,1),r--,a=-1),a==-1){if(this.modules.splice(r++,0,l),i)for(let h=0;h<l.rules.length;h++)i.insertRule(l.rules[h],s++)}else{for(;r<a;)s+=this.modules[r++].rules.length;s+=l.rules.length,r++}}if(i)t.adoptedStyleSheets.indexOf(this.sheet)<0&&(t.adoptedStyleSheets=[this.sheet,...t.adoptedStyleSheets]);else{let o="";for(let a=0;a<this.modules.length;a++)o+=this.modules[a].getRules()+` 176`;this.styleTag.textContent=o;let l=t.head||t;this.styleTag.parentNode!=l&&l.insertBefore(this.styleTag,l.firstChild)}}setNonce(e){this.styleTag&&this.styleTag.getAttribute("nonce")!=e&&this.styleTag.setAttribute("nonce",e)}}var Mt={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},qi={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},dd=typeof navigator<"u"&&/Mac/.test(navigator.platform),pd=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(var he=0;he<10;he++)Mt[48+he]=Mt[96+he]=String(he);for(var he=1;he<=24;he++)Mt[he+111]="F"+he;for(var he=65;he<=90;he++)Mt[he]=String.fromCharCode(he+32),qi[he]=String.fromCharCode(he);for(var Wn in Mt)qi.hasOwnProperty(Wn)||(qi[Wn]=Mt[Wn]);function md(n){var e=dd&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||pd&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?qi:Mt)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}function ne(){var n=arguments[0];typeof n=="string"&&(n=document.createElement(n));var e=1,t=arguments[1];if(t&&typeof t=="object"&&t.nodeType==null&&!Array.isArray(t)){for(var i in t)if(Object.prototype.hasOwnProperty.call(t,i)){var s=t[i];typeof s=="string"?n.setAttribute(i,s):s!=null&&(n[i]=s)}e++}for(;e<arguments.length;e++)Dh(n,arguments[e]);return n}function Dh(n,e){if(typeof e=="string")n.appendChild(document.createTextNode(e));else if(e!=null)if(e.nodeType!=null)n.appendChild(e);else if(Array.isArray(e))for(var t=0;t<e.length;t++)Dh(n,e[t]);else throw new RangeError("Unsupported child node: "+e)}let pe=typeof navigator<"u"?navigator:{userAgent:"",vendor:"",platform:""},Pr=typeof document<"u"?document:{documentElement:{style:{}}};const Fr=/Edge\/(\d+)/.exec(pe.userAgent),Rh=/MSIE \d/.test(pe.userAgent),Hr=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(pe.userAgent),Tn=!!(Rh||Hr||Fr),Sl=!Tn&&/gecko\/(\d+)/i.test(pe.userAgent),zn=!Tn&&/Chrome\/(\d+)/.exec(pe.userAgent),gd="webkitFontSmoothing"in Pr.documentElement.style,Wr=!Tn&&/Apple Computer/.test(pe.vendor),vl=Wr&&(/Mobile\/\w+/.test(pe.userAgent)||pe.maxTouchPoints>2);var A={mac:vl||/Mac/.test(pe.platform),windows:/Win/.test(pe.platform),linux:/Linux|X11/.test(pe.platform),ie:Tn,ie_version:Rh?Pr.documentMode||6:Hr?+Hr[1]:Fr?+Fr[1]:0,gecko:Sl,gecko_version:Sl?+(/Firefox\/(\d+)/.exec(pe.userAgent)||[0,0])[1]:0,chrome:!!zn,chrome_version:zn?+zn[1]:0,ios:vl,android:/Android\b/.test(pe.userAgent),webkit_version:gd?+(/\bAppleWebKit\/(\d+)/.exec(pe.userAgent)||[0,0])[1]:0,safari:Wr,safari_version:Wr?+(/\bVersion\/(\d+(\.\d+)?)/.exec(pe.userAgent)||[0,0])[1]:0,tabSize:Pr.documentElement.style.tabSize!=null?"tab-size":"-moz-tab-size"};function So(n,e){for(let t in n)t=="class"&&e.class?e.class+=" "+n.class:t=="style"&&e.style?e.style+=";"+n.style:e[t]=n[t];return e}const js=Object.create(null);function vo(n,e,t){if(n==e)return!0;n||(n=js),e||(e=js);let i=Object.keys(n),s=Object.keys(e);if(i.length-0!=s.length-0)return!1;for(let r of i)if(r!=t&&(s.indexOf(r)==-1||n[r]!==e[r]))return!1;return!0}function yd(n,e){for(let t=n.attributes.length-1;t>=0;t--){let i=n.attributes[t].name;e[i]==null&&n.removeAttribute(i)}for(let t in e){let i=e[t];t=="style"?n.style.cssText=i:n.getAttribute(t)!=i&&n.setAttribute(t,i)}}function kl(n,e,t){let i=!1;if(e)for(let s in e)t&&s in t||(i=!0,s=="style"?n.style.cssText="":n.removeAttribute(s));if(t)for(let s in t)e&&e[s]==t[s]||(i=!0,s=="style"?n.style.cssText=t[s]:n.setAttribute(s,t[s]));return i}function bd(n){let e=Object.create(null);for(let t=0;t<n.attributes.length;t++){let i=n.attributes[t];e[i.name]=i.value}return e}class is{eq(e){return!1}updateDOM(e,t,i){return!1}compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}get estimatedHeight(){return-1}get lineBreaks(){return 0}ignoreEvent(e){return!0}coordsAt(e,t,i){return null}get isHidden(){return!1}get editable(){return!1}destroy(e){}}var Ce=function(n){return n[n.Text=0]="Text",n[n.WidgetBefore=1]="WidgetBefore",n[n.WidgetAfter=2]="WidgetAfter",n[n.WidgetRange=3]="WidgetRange",n}(Ce||(Ce={}));
vendor: 12,613 bytes, line 176
176class j extends Tt{constructor(e,t,i,s){super(),this.startSide=e,this.endSide=t,this.widget=i,this.spec=s}get heightRelevant(){return!1}static mark(e){return new ss(e)}static widget(e){let t=Math.max(-1e4,Math.min(1e4,e.side||0)),i=!!e.block;return t+=i&&!e.inlineOrder?t>0?3e8:-4e8:t>0?1e8:-1e8,new Vt(e,t,t,i,e.widget||null,!1)}static replace(e){let t=!!e.block,i,s;if(e.isBlockGap)i=-5e8,s=4e8;else{let{start:r,end:o}=Lh(e,t);i=(r?t?-3e8:-1:5e8)-1,s=(o?t?2e8:1:-6e8)+1}return new Vt(e,i,s,t,e.widget||null,!0)}static line(e){return new ns(e)}static set(e,t=!1){return P.of(e,t)}hasHeight(){return this.widget?this.widget.estimatedHeight>-1:!1}}j.none=P.empty;class ss extends j{constructor(e){let{start:t,end:i}=Lh(e);super(t?-1:5e8,i?1:-6e8,null,e),this.tagName=e.tagName||"span",this.attrs=e.class&&e.attributes?So(e.attributes,{class:e.class}):e.class?{class:e.class}:e.attributes||js}eq(e){return this==e||e instanceof ss&&this.tagName==e.tagName&&vo(this.attrs,e.attrs)}range(e,t=e){if(e>=t)throw new RangeError("Mark decorations may not be empty");return super.range(e,t)}}ss.prototype.point=!1;class ns extends j{constructor(e){super(-2e8,-2e8,null,e)}eq(e){return e instanceof ns&&this.spec.class==e.spec.class&&vo(this.spec.attributes,e.spec.attributes)}range(e,t=e){if(t!=e)throw new RangeError("Line decoration ranges must be zero-length");return super.range(e,t)}}ns.prototype.mapMode=Oe.TrackBefore;ns.prototype.point=!0;class Vt extends j{constructor(e,t,i,s,r,o){super(t,i,r,e),this.block=s,this.isReplace=o,this.mapMode=s?t<=0?Oe.TrackBefore:Oe.TrackAfter:Oe.TrackDel}get type(){return this.startSide!=this.endSide?Ce.WidgetRange:this.startSide<=0?Ce.WidgetBefore:Ce.WidgetAfter}get heightRelevant(){return this.block||!!this.widget&&(this.widget.estimatedHeight>=5||this.widget.lineBreaks>0)}eq(e){return e instanceof Vt&&wd(this.widget,e.widget)&&this.block==e.block&&this.startSide==e.startSide&&this.endSide==e.endSide}range(e,t=e){if(this.isReplace&&(e>t||e==t&&this.startSide>0&&this.endSide<=0))throw new RangeError("Invalid range for replacement decoration");if(!this.isReplace&&t!=e)throw new RangeError("Widget decorations can only have zero-length ranges");return super.range(e,t)}}Vt.prototype.point=!0;function Lh(n,e=!1){let{inclusiveStart:t,inclusiveEnd:i}=n;return t==null&&(t=n.inclusive),i==null&&(i=n.inclusive),{start:t??e,end:i??e}}function wd(n,e){return n==e||!!(n&&e&&n.compare(e))}function oi(n,e,t,i=0){let s=t.length-1;s>=0&&t[s]+i>=n?t[s]=Math.max(t[s],e):t.push(n,e)}class Qi extends Tt{constructor(e,t){super(),this.tagName=e,this.attributes=t}eq(e){return e==this||e instanceof Qi&&this.tagName==e.tagName&&vo(this.attributes,e.attributes)}static create(e){return new Qi(e.tagName,e.attributes||js)}static set(e,t=!1){return P.of(e,t)}}Qi.prototype.startSide=Qi.prototype.endSide=-1;function ji(n){let e;return n.nodeType==11?e=n.getSelection?n:n.ownerDocument:e=n,e.getSelection()}function zr(n,e){return e?n==e||n.contains(e.nodeType!=1?e.parentNode:e):!1}function Pi(n,e){if(!e.anchorNode)return!1;try{return zr(n,e.anchorNode)}catch{return!1}}function Fi(n){return n.nodeType==3?Ki(n,0,n.nodeValue.length).getClientRects():n.nodeType==1?n.getClientRects():[]}function Hi(n,e,t,i){return t?Tl(n,e,t,i,-1)||Tl(n,e,t,i,1):!1}function Et(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e}function Gs(n){return n.nodeType==1&&/^(DIV|P|LI|UL|OL|BLOCKQUOTE|DD|DT|H\d|SECTION|PRE)$/.test(n.nodeName)}function Tl(n,e,t,i,s){for(;;){if(n==t&&e==i)return!0;if(e==(s<0?0:mt(n))){if(n.nodeName=="DIV")return!1;let r=n.parentNode;if(!r||r.nodeType!=1)return!1;e=Et(n)+(s<0?0:1),n=r}else if(n.nodeType==1){if(n=n.childNodes[e+(s<0?-1:0)],n.nodeType==1&&n.contentEditable=="false")return!1;e=s<0?mt(n):0}else return!1}}function mt(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Gi(n,e){let t=e?n.left:n.right;return{left:t,right:t,top:n.top,bottom:n.bottom}}function Cd(n){let e=n.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.innerWidth,top:0,bottom:n.innerHeight}}function Ih(n,e){let t=e.width/n.offsetWidth,i=e.height/n.offsetHeight;return(t>.995&&t<1.005||!isFinite(t)||Math.abs(e.width-n.offsetWidth)<1)&&(t=1),(i>.995&&i<1.005||!isFinite(i)||Math.abs(e.height-n.offsetHeight)<1)&&(i=1),{scaleX:t,scaleY:i}}function xd(n,e,t,i,s,r,o,l){let a=n.ownerDocument,h=a.defaultView||window;for(let c=n,u=!1;c&&!u;)if(c.nodeType==1){let f,d=c==a.body,p=1,m=1;if(d)f=Cd(h);else{if(/^(fixed|sticky)$/.test(getComputedStyle(c).position)&&(u=!0),c.scrollHeight<=c.clientHeight&&c.scrollWidth<=c.clientWidth){c=c.assignedSlot||c.parentNode;continue}let b=c.getBoundingClientRect();({scaleX:p,scaleY:m}=Ih(c,b)),f={left:b.left,right:b.left+c.clientWidth*p,top:b.top,bottom:b.top+c.clientHeight*m}}let g=0,y=0;if(s=="nearest")e.top<f.top+o?(y=e.top-(f.top+o),t>0&&e.bottom>f.bottom+y&&(y=e.bottom-f.bottom+o)):e.bottom>f.bottom-o&&(y=e.bottom-f.bottom+o,t<0&&e.top-y<f.top&&(y=e.top-(f.top+o)));else{let b=e.bottom-e.top,C=f.bottom-f.top;y=(s=="center"&&b<=C?e.top+b/2-C/2:s=="start"||s=="center"&&t<0?e.top-o:e.bottom-C+o)-f.top}if(i=="nearest"?e.left<f.left+r?(g=e.left-(f.left+r),t>0&&e.right>f.right+g&&(g=e.right-f.right+r)):e.right>f.right-r&&(g=e.right-f.right+r,t<0&&e.left<f.left+g&&(g=e.left-(f.left+r))):g=(i=="center"?e.left+(e.right-e.left)/2-(f.right-f.left)/2:i=="start"==l?e.left-r:e.right-(f.right-f.left)+r)-f.left,g||y)if(d)h.scrollBy(g,y);else{let b=0,C=0;if(y){let k=c.scrollTop;c.scrollTop+=y/m,C=(c.scrollTop-k)*m}if(g){let k=c.scrollLeft;c.scrollLeft+=g/p,b=(c.scrollLeft-k)*p}e={left:e.left-b,top:e.top-C,right:e.right-b,bottom:e.bottom-C},b&&Math.abs(b-g)<1&&(i="nearest"),C&&Math.abs(C-y)<1&&(s="nearest")}if(d)break;(e.top<f.top||e.bottom>f.bottom||e.left<f.left||e.right>f.right)&&(e={left:Math.max(e.left,f.left),right:Math.min(e.right,f.right),top:Math.max(e.top,f.top),bottom:Math.min(e.bottom,f.bottom)}),c=c.assignedSlot||c.parentNode}else if(c.nodeType==11)c=c.host;else break}function Nh(n,e=!0){let t=n.ownerDocument,i=null,s=null;for(let r=n.parentNode;r&&!(r==t.body||(!e||i)&&s);)if(r.nodeType==1)!s&&r.scrollHeight>r.clientHeight&&(s=r),e&&!i&&r.scrollWidth>r.clientWidth&&(i=r),r=r.assignedSlot||r.parentNode;else if(r.nodeType==11)r=r.host;else break;return{x:i,y:s}}class Sd{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}eq(e){return this.anchorNode==e.anchorNode&&this.anchorOffset==e.anchorOffset&&this.focusNode==e.focusNode&&this.focusOffset==e.focusOffset}setRange(e){let{anchorNode:t,focusNode:i}=e;this.set(t,Math.min(e.anchorOffset,t?mt(t):0),i,Math.min(e.focusOffset,i?mt(i):0))}set(e,t,i,s){this.anchorNode=e,this.anchorOffset=t,this.focusNode=i,this.focusOffset=s}}let It=null;A.safari&&A.safari_version>=26&&(It=!1);function Bh(n){if(n.setActive)return n.setActive();if(It)return n.focus(It);let e=[];for(let t=n;t&&(e.push(t,t.scrollTop,t.scrollLeft),t!=t.ownerDocument);t=t.parentNode);if(n.focus(It==null?{get preventScroll(){return It={preventScroll:!0},!0}}:void 0),!It){It=!1;for(let t=0;t<e.length;){let i=e[t++],s=e[t++],r=e[t++];i.scrollTop!=s&&(i.scrollTop=s),i.scrollLeft!=r&&(i.scrollLeft=r)}}}let Al;function Ki(n,e,t=e){let i=Al||(Al=document.createRange());return i.setEnd(n,t),i.setStart(n,e),i}function li(n,e,t,i){let s={key:e,code:e,keyCode:t,which:t,cancelable:!0};i&&({altKey:s.altKey,ctrlKey:s.ctrlKey,shiftKey:s.shiftKey,metaKey:s.metaKey}=i);let r=new KeyboardEvent("keydown",s);r.synthetic=!0,n.dispatchEvent(r);let o=new KeyboardEvent("keyup",s);return o.synthetic=!0,n.dispatchEvent(o),r.defaultPrevented||o.defaultPrevented}function vd(n){for(;n;){if(n&&(n.nodeType==9||n.nodeType==11&&n.host))return n;n=n.assignedSlot||n.parentNode}return null}function kd(n,e){let t=e.focusNode,i=e.focusOffset;if(!t||e.anchorNode!=t||e.anchorOffset!=i)return!1;for(i=Math.min(i,mt(t));;)if(i){if(t.nodeType!=1)return!1;let s=t.childNodes[i-1];s.contentEditable=="false"?i--:(t=s,i=mt(t))}else{if(t==n)return!0;i=Et(t),t=t.parentNode}}function _h(n){return n instanceof Window?n.pageYOffset>Math.max(0,n.document.documentElement.scrollHeight-n.innerHeight-4):n.scrollTop>Math.max(1,n.scrollHeight-n.clientHeight-4)}function Ph(n,e){for(let t=n,i=e;;){if(t.nodeType==3&&i>0)return{node:t,offset:i};if(t.nodeType==1&&i>0){if(t.contentEditable=="false")return null;t=t.childNodes[i-1],i=mt(t)}else if(t.parentNode&&!Gs(t))i=Et(t),t=t.parentNode;else return null}}function Fh(n,e){for(let t=n,i=e;;){if(t.nodeType==3&&i<t.nodeValue.length)return{node:t,offset:i};if(t.nodeType==1&&i<t.childNodes.length){if(t.contentEditable=="false")return null;t=t.childNodes[i],i=0}else if(t.parentNode&&!Gs(t))i=Et(t)+1,t=t.parentNode;else return null}}class Qe{constructor(e,t,i=!0){this.node=e,this.offset=t,this.precise=i}static before(e,t){return new Qe(e.parentNode,Et(e),t)}static after(e,t){return new Qe(e.parentNode,Et(e)+1,t)}}var G=function(n){return n[n.LTR=0]="LTR",n[n.RTL=1]="RTL",n}(G||(G={}));const $t=G.LTR,ko=G.RTL;function Hh(n){let e=[];for(let t=0;t<n.length;t++)e.push(1<<+n[t]);return e}const Td=Hh("88888888888888888888888888888888888666888888787833333333337888888000000000000000000000000008888880000000000000000000000000088888888888888888888888888888888888887866668888088888663380888308888800000000000000000000000800000000000000000000000000000008"),Ad=Hh("4444448826627288999999999992222222222222222222222222222222222222222222222229999999999999999999994444444444644222822222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222999999949999999229989999223333333333"),Vr=Object.create(null),tt=[];for(let n of["()","[]","{}"]){let e=n.charCodeAt(0),t=n.charCodeAt(1);Vr[e]=t,Vr[t]=-e}function Wh(n){return n<=247?Td[n]:1424<=n&&n<=1524?2:1536<=n&&n<=1785?Ad[n-1536]:1774<=n&&n<=2220?4:8192<=n&&n<=8204?256:64336<=n&&n<=65023?4:1}const Md=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac\ufb50-\ufdff]/;class lt{get dir(){return this.level%2?ko:$t}constructor(e,t,i){this.from=e,this.to=t,this.level=i}side(e,t){return this.dir==t==e?this.to:this.from}forward(e,t){return e==(this.dir==t)}static find(e,t,i,s){let r=-1;for(let o=0;o<e.length;o++){let l=e[o];if(l.from<=t&&l.to>=t){if(l.level==i)return o;(r<0||(s!=0?s<0?l.from<t:l.to>t:e[r].level>l.level))&&(r=o)}}if(r<0)throw new RangeError("Index out of range");return r}}function zh(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++){let i=n[t],s=e[t];if(i.from!=s.from||i.to!=s.to||i.direction!=s.direction||!zh(i.inner,s.inner))return!1}return!0}const $=[];function Ed(n,e,t,i,s){for(let r=0;r<=i.length;r++){let o=r?i[r-1].to:e,l=r<i.length?i[r].from:t,a=r?256:s;for(let h=o,c=a,u=a;h<l;h++){let f=Wh(n.charCodeAt(h));f==512?f=c:f==8&&u==4&&(f=16),$[h]=f==4?2:f,f&7&&(u=f),c=f}for(let h=o,c=a,u=a;h<l;h++){let f=$[h];if(f==128)h<l-1&&c==$[h+1]&&c&24?f=$[h]=c:$[h]=256;else if(f==64){let d=h+1;for(;d<l&&$[d]==64;)d++;let p=h&&c==8||d<t&&$[d]==8?u==1?1:8:256;for(let m=h;m<d;m++)$[m]=p;h=d-1}else f==8&&u==1&&($[h]=1);c=f,f&7&&(u=f)}}}function Od(n,e,t,i,s){let r=s==1?2:1;for(let o=0,l=0,a=0;o<=i.length;o++){let h=o?i[o-1].to:e,c=o<i.length?i[o].from:t;for(let u=h,f,d,p;u<c;u++)if(d=Vr[f=n.charCodeAt(u)])if(d<0){for(let m=l-3;m>=0;m-=3)if(tt[m+1]==-d){let g=tt[m+2],y=g&2?s:g&4?g&1?r:s:0;y&&($[u]=$[tt[m]]=y),l=m;break}}else{if(tt.length==189)break;tt[l++]=u,tt[l++]=f,tt[l++]=a}else if((p=$[u])==2||p==1){let m=p==s;a=m?0:1;for(let g=l-3;g>=0;g-=3){let y=tt[g+2];if(y&2)break;if(m)tt[g+2]|=2;else{if(y&4)break;tt[g+2]|=4}}}}}function Dd(n,e,t,i){for(let s=0,r=i;s<=t.length;s++){let o=s?t[s-1].to:n,l=s<t.length?t[s].from:e;for(let a=o;a<l;){let h=$[a];if(h==256){let c=a+1;for(;;)if(c==l){if(s==t.length)break;c=t[s++].to,l=s<t.length?t[s].from:e}else if($[c]==256)c++;else break;let u=r==1,f=(c<e?$[c]:i)==1,d=u==f?u?1:2:i;for(let p=c,m=s,g=m?t[m-1].to:n;p>a;)p==g&&(p=t[--m].from,g=m?t[m-1].to:n),$[--p]=d;a=c}else r=h,a++}}}function $r(n,e,t,i,s,r,o){let l=i%2?2:1;if(i%2==s%2)for(let a=e,h=0;a<t;){let c=!0,u=!1;if(h==r.length||a<r[h].from){let m=$[a];m!=l&&(c=!1,u=m==16)}let f=!c&&l==1?[]:null,d=c?i:i+1,p=a;e:for(;;)if(h<r.length&&p==r[h].from){if(u)break e;let m=r[h];if(!c)for(let g=m.to,y=h+1;;){if(g==t)break e;if(y<r.length&&r[y].from==g)g=r[y++].to;else{if($[g]==l)break e;break}}if(h++,f)f.push(m);else{m.from>a&&o.push(new lt(a,m.from,d));let g=m.direction==$t!=!(d%2);Ur(n,g?i+1:i,s,m.inner,m.from,m.to,o),a=m.to}p=m.to}else{if(p==t||(c?$[p]!=l:$[p]==l))break;p++}f?$r(n,a,p,i+1,s,f,o):a<p&&o.push(new lt(a,p,d)),a=p}else for(let a=t,h=r.length;a>e;){let c=!0,u=!1;
176if(!h||a>r[h-1].to){let m=$[a-1];m!=l&&(c=!1,u=m==16)}let f=!c&&l==1?[]:null,d=c?i:i+1,p=a;e:for(;;)if(h&&p==r[h-1].to){if(u)break e;let m=r[--h];if(!c)for(let g=m.from,y=h;;){if(g==e)break e;if(y&&r[y-1].to==g)g=r[--y].from;else{if($[g-1]==l)break e;break}}if(f)f.push(m);else{m.to<a&&o.push(new lt(m.to,a,d));let g=m.direction==$t!=!(d%2);Ur(n,g?i+1:i,s,m.inner,m.from,m.to,o),a=m.from}p=m.from}else{if(p==e||(c?$[p-1]!=l:$[p-1]==l))break;p--}f?$r(n,p,a,i+1,s,f,o):p<a&&o.push(new lt(p,a,d)),a=p}}function Ur(n,e,t,i,s,r,o){let l=e%2?2:1;Ed(n,s,r,i,l),Od(n,s,r,i,l),Dd(s,r,i,l),$r(n,s,r,e,t,i,o)}function Rd(n,e,t){if(!n)return[new lt(0,0,e==ko?1:0)];if(e==$t&&!t.length&&!Md.test(n))return Vh(n.length);if(t.length)for(;n.length>$.length;)$[$.length]=256;let i=[],s=e==$t?0:1;return Ur(n,s,s,t,0,n.length,i),i}function Vh(n){return[new lt(0,n,0)]}let $h="";function Ld(n,e,t,i,s){var r;let o=i.head-n.from,l=lt.find(e,o,(r=i.bidiLevel)!==null&&r!==void 0?r:-1,i.assoc),a=e[l],h=a.side(s,t);if(o==h){let f=l+=s?1:-1;if(f<0||f>=e.length)return null;a=e[l=f],o=a.side(!s,t),h=a.side(s,t)}let c=oe(n.text,o,a.forward(s,t));(c<a.from||c>a.to)&&(c=h),$h=n.text.slice(Math.min(o,c),Math.max(o,c));let u=l==(s?e.length-1:0)?null:e[l+(s?1:-1)];return u&&c==h&&u.level+(s?0:1)<a.level?w.cursor(u.side(!s,t)+n.from,u.forward(s,t)?1:-1,u.level):w.cursor(c+n.from,a.forward(s,t)?-1:1,a.level)}function Id(n,e,t){for(let i=e;i<t;i++){let s=Wh(n.charCodeAt(i));if(s==1)return $t;if(s==2||s==4)return ko}return $t}const Uh=E.define(),qh=E.define(),Qh=E.define(),jh=E.define(),qr=E.define(),Gh=E.define(),Kh=E.define(),To=E.define(),Ao=E.define(),Xh=E.define({combine:n=>n.some(e=>e)}),Nd=E.define({combine:n=>n.some(e=>e)}),Yh=E.define();class ai{constructor(e,t,i,s,r,o=!1){this.range=e,this.y=t,this.x=i,this.yMargin=s,this.xMargin=r,this.isSnapshot=o}map(e){return e.empty?this:new ai(this.range.map(e),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}clip(e){return this.range.to<=e.doc.length?this:new ai(w.cursor(e.doc.length),this.y,this.x,this.yMargin,this.xMargin,this.isSnapshot)}}const gs=H.define({map:(n,e)=>n.map(e)}),Jh=H.define();function De(n,e,t){let i=n.facet(jh);i.length?i[0](e):window.onerror&&window.onerror(String(e),t,void 0,void 0,e)||(t?console.error(t+":",e):console.error(e))}const ft=E.define({combine:n=>n.length?n[0]:!0});let Bd=0;const Jt=E.define({combine(n){return n.filter((e,t)=>{for(let i=0;i<t;i++)if(n[i].plugin==e.plugin)return!1;return!0})}});class Re{constructor(e,t,i,s,r){this.id=e,this.create=t,this.domEventHandlers=i,this.domEventObservers=s,this.baseExtensions=r(this),this.extension=this.baseExtensions.concat(Jt.of({plugin:this,arg:void 0}))}of(e){return this.baseExtensions.concat(Jt.of({plugin:this,arg:e}))}static define(e,t){const{eventHandlers:i,eventObservers:s,provide:r,decorations:o}=t||{};return new Re(Bd++,e,i,s,l=>{let a=[];return o&&a.push(An.of(h=>{let c=h.plugin(l);return c?o(c):j.none})),r&&a.push(r(l)),a})}static fromClass(e,t){return Re.define((i,s)=>new e(i,s),t)}}class Vn{constructor(e){this.spec=e,this.mustUpdate=null,this.value=null}get plugin(){return this.spec&&this.spec.plugin}update(e){if(this.value){if(this.mustUpdate){let t=this.mustUpdate;if(this.mustUpdate=null,this.value.update)try{this.value.update(t)}catch(i){if(De(t.state,i,"CodeMirror plugin crashed"),this.value.destroy)try{this.value.destroy()}catch{}this.deactivate()}}}else if(this.spec)try{this.value=this.spec.plugin.create(e,this.spec.arg)}catch(t){De(e.state,t,"CodeMirror plugin crashed"),this.deactivate()}return this}destroy(e){var t;if(!((t=this.value)===null||t===void 0)&&t.destroy)try{this.value.destroy()}catch(i){De(e.state,i,"CodeMirror plugin crashed")}}deactivate(){this.spec=this.value=null}}const Zh=E.define(),Mo=E.define(),An=E.define(),ec=E.define(),Eo=E.define(),rs=E.define(),tc=E.define();function Ml(n,e){let t=n.state.facet(tc);if(!t.length)return t;let i=t.map(r=>r instanceof Function?r(n):r),s=[];return P.spans(i,e.from,e.to,{point(){},span(r,o,l,a){let h=r-e.from,c=o-e.from,u=s;for(let f=l.length-1;f>=0;f--,a--){let d=l[f].spec.bidiIsolate,p;if(d==null&&(d=Id(e.text,h,c)),a>0&&u.length&&(p=u[u.length-1]).to==h&&p.direction==d)p.to=c,u=p.inner;else{let m={from:h,to:c,direction:d,inner:[]};u.push(m),u=m.inner}}}}),s}const ic=E.define();function Oo(n){let e=0,t=0,i=0,s=0;
vendor: 5,533 bytes, line 176
176for(let r of n.state.facet(ic)){let o=r(n);o&&(o.left!=null&&(e=Math.max(e,o.left)),o.right!=null&&(t=Math.max(t,o.right)),o.top!=null&&(i=Math.max(i,o.top)),o.bottom!=null&&(s=Math.max(s,o.bottom)))}return{left:e,right:t,top:i,bottom:s}}const Di=E.define();class _e{constructor(e,t,i,s){this.fromA=e,this.toA=t,this.fromB=i,this.toB=s}join(e){return new _e(Math.min(this.fromA,e.fromA),Math.max(this.toA,e.toA),Math.min(this.fromB,e.fromB),Math.max(this.toB,e.toB))}addToSet(e){let t=e.length,i=this;for(;t>0;t--){let s=e[t-1];if(!(s.fromA>i.toA)){if(s.toA<i.fromA)break;i=i.join(s),e.splice(t-1,1)}}return e.splice(t,0,i),e}static extendWithRanges(e,t){if(t.length==0)return e;let i=[];for(let s=0,r=0,o=0;;){let l=s<e.length?e[s].fromB:1e9,a=r<t.length?t[r]:1e9,h=Math.min(l,a);if(h==1e9)break;let c=h+o,u=h,f=c;for(;;)if(r<t.length&&t[r]<=u){let d=t[r+1];r+=2,u=Math.max(u,d);for(let p=s;p<e.length&&e[p].fromB<=u;p++)o=e[p].toA-e[p].toB;f=Math.max(f,d+o)}else if(s<e.length&&e[s].fromB<=u){let d=e[s++];u=Math.max(u,d.toB),f=Math.max(f,d.toA),o=d.toA-d.toB}else break;i.push(new _e(c,f,h,u))}return i}}class Ks{constructor(e,t,i){this.view=e,this.state=t,this.transactions=i,this.flags=0,this.startState=e.state,this.changes=ie.empty(this.startState.doc.length);for(let r of i)this.changes=this.changes.compose(r.changes);let s=[];this.changes.iterChangedRanges((r,o,l,a)=>s.push(new _e(r,o,l,a))),this.changedRanges=s}static create(e,t,i){return new Ks(e,t,i)}get viewportChanged(){return(this.flags&4)>0}get viewportMoved(){return(this.flags&8)>0}get heightChanged(){return(this.flags&2)>0}get geometryChanged(){return this.docChanged||(this.flags&18)>0}get focusChanged(){return(this.flags&1)>0}get docChanged(){return!this.changes.empty}get selectionSet(){return this.transactions.some(e=>e.selection)}get empty(){return this.flags==0&&this.transactions.length==0}}const _d=[];class Y{constructor(e,t,i=0){this.dom=e,this.length=t,this.flags=i,this.parent=null,e.cmTile=this}get breakAfter(){return this.flags&1}get children(){return _d}isWidget(){return!1}get isHidden(){return!1}isComposite(){return!1}isLine(){return!1}isText(){return!1}isBlock(){return!1}get domAttrs(){return null}sync(e){if(this.flags|=2,this.flags&4){this.flags&=-5;let t=this.domAttrs;t&&yd(this.dom,t)}}toString(){return this.constructor.name+(this.children.length?`(${this.children})`:"")+(this.breakAfter?"#":"")}destroy(){this.parent=null}setDOM(e){this.dom=e,e.cmTile=this}get posAtStart(){return this.parent?this.parent.posBefore(this):0}get posAtEnd(){return this.posAtStart+this.length}posBefore(e,t=this.posAtStart){let i=t;for(let s of this.children){if(s==e)return i;i+=s.length+s.breakAfter}throw new RangeError("Invalid child in posBefore")}posAfter(e){return this.posBefore(e)+e.length}covers(e){return!0}coordsIn(e,t){return null}domPosFor(e,t){let i=Et(this.dom),s=this.length?e>0:t>0;return new Qe(this.parent.dom,i+(s?1:0),e==0||e==this.length)}markDirty(e){this.flags&=-3,e&&(this.flags|=4),this.parent&&this.parent.flags&2&&this.parent.markDirty(!1)}get overrideDOMText(){return null}get root(){for(let e=this;e;e=e.parent)if(e instanceof En)return e;return null}static get(e){return e.cmTile}}class Mn extends Y{constructor(e){super(e,0),this._children=[]}isComposite(){return!0}get children(){return this._children}get lastChild(){return this.children.length?this.children[this.children.length-1]:null}append(e){this.children.push(e),e.parent=this}sync(e){if(this.flags&2)return;super.sync(e);let t=this.dom,i=null,s,r=e?.node==t?e:null,o=0;for(let l of this.children){if(l.sync(e),o+=l.length+l.breakAfter,s=i?i.nextSibling:t.firstChild,r&&s!=l.dom&&(r.written=!0),l.dom.parentNode==t)for(;s&&s!=l.dom;)s=El(s);else t.insertBefore(l.dom,s);i=l.dom}for(s=i?i.nextSibling:t.firstChild,r&&s&&(r.written=!0);s;)s=El(s);this.length=o}}function El(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class En extends Mn{constructor(e,t){super(t),this.view=e}owns(e){for(;e;e=e.parent)if(e==this)return!0;return!1}isBlock(){return!0}nearest(e){for(;;){if(!e)return null;let t=Y.get(e);if(t&&this.owns(t))return t;e=e.parentNode}}blockTiles(e){for(let t=[],i=this,s=0,r=0;;)if(s==i.children.length){if(!t.length)return;i=i.parent,i.breakAfter&&r++,s=t.pop()}else{let o=i.children[s++];if(o instanceof pt)t.push(s),i=o,s=0;else{let l=r+o.length,a=e(o,r);if(a!==void 0)return a;r=l+o.breakAfter}}}resolveBlock(e,t){let i,s=-1,r,o=-1;if(this.blockTiles((l,a)=>{let h=a+l.length;if(e>=a&&e<=h){if(l.isWidget()&&t>=-1&&t<=1){if(l.flags&32)return!0;l.flags&16&&(i=void 0)}(a<e||e==h&&(t<-1?l.length:l.covers(1)))&&(!i||!l.isWidget()&&i.isWidget())&&(i=l,s=e-a),(h>e||e==a&&(t>1?l.length:l.covers(-1)))&&(!r||!l.isWidget()&&r.isWidget())&&(r=l,o=e-a)}}),!i&&!r)throw new Error("No tile at position "+e);return i&&t<0||!r?{tile:i,offset:s}:{tile:r,offset:o}}}class pt extends Mn{constructor(e,t){super(e),this.wrapper=t}isBlock(){return!0}covers(e){return this.children.length?e<0?this.children[0].covers(-1):this.lastChild.covers(1):!1}get domAttrs(){return this.wrapper.attributes}static of(e,t){let i=new pt(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class pi extends Mn{constructor(e,t){super(e),this.attrs=t}isLine(){return!0}static start(e,t,i){let s=new pi(t||document.createElement("div"),e);return(!t||!i)&&(s.flags|=4),s}get domAttrs(){return this.attrs}resolveInline(e,t,i){let s=null,r=-1,o=null,l=-1;function a(c,u){for(let f=0,d=0;f<c.children.length&&d<=u;f++){let p=c.children[f],m=d+p.length;m>
176=u&&(p.isComposite()?a(p,u-d):(!o||o.isHidden&&(t>0||i&&Fd(o,p)))&&(m>u||p.flags&32)?(o=p,l=u-d):(d<u||p.flags&16&&!p.isHidden)&&(s=p,r=u-d)),d=m}}a(this,e);let h=(t<0?s:o)||s||o;return h?{tile:h,offset:h==s?r:l}:null}coordsIn(e,t){let i=this.resolveInline(e,t,!0);return i?i.tile.coordsIn(Math.max(0,i.offset),t):Pd(this)}domIn(e,t){let i=this.resolveInline(e,t);if(i){let{tile:s,offset:r}=i;if(this.dom.contains(s.dom))return s.isText()?new Qe(s.dom,Math.min(s.dom.nodeValue.length,r)):s.domPosFor(r,s.flags&16?1:s.flags&32?-1:t);let o=i.tile.parent,l=!1;for(let a of o.children){if(l)return new Qe(a.dom,0);a==i.tile&&(l=!0)}}return new Qe(this.dom,0)}}function Pd(n){let e=n.dom.lastChild;if(!e)return n.dom.getBoundingClientRect();let t=Fi(e);return t[t.length-1]||null}function Fd(n,e){let t=n.coordsIn(0,1),i=e.coordsIn(0,1);return t&&i&&i.top<t.bottom}class be extends Mn{constructor(e,t){super(e),this.mark=t}get domAttrs(){return this.mark.attrs}static of(e,t){let i=new be(t||document.createElement(e.tagName),e);return t||(i.flags|=4),i}}class Ht extends Y{constructor(e,t){super(e,t.length),this.text=t}sync(e){this.flags&2||(super.sync(e),this.dom.nodeValue!=this.text&&(e&&e.node==this.dom&&(e.written=!0),this.dom.nodeValue=this.text))}isText(){return!0}toString(){return JSON.stringify(this.text)}coordsIn(e,t){let i=this.dom.nodeValue.length;e>i&&(e=i);let s=e,r=e,o=0;e==0&&t<0||e==i&&t>=0?A.chrome||A.gecko||(e?(s--,o=1):r<i&&(r++,o=-1)):t<0?s--:r<i&&r++;let l=Ki(this.dom,s,r).getClientRects();if(!l.length)return null;let a=l[(o?o<0:t>=0)?0:l.length-1];return A.safari&&!o&&a.width==0&&(a=Array.prototype.find.call(l,h=>h.width)||a),o?Gi(a,o<0):a||null}static of(e,t){let i=new Ht(t||document.createTextNode(e),e);return t||(i.flags|=2),i}}class Ut extends Y{constructor(e,t,i,s){super(e,t,s),this.widget=i}isWidget(){return!0}get isHidden(){return this.widget.isHidden}covers(e){return this.flags&48?!1:(this.flags&(e<0?64:128))>0}coordsIn(e,t){return this.coordsInWidget(e,t,!1)}coordsInWidget(e,t,i){let s=this.widget.coordsAt(this.dom,e,t);if(s)return s;if(i)return Gi(this.dom.getBoundingClientRect(),this.length?e==0:t<=0);{let r=this.dom.getClientRects(),o=null;if(!r.length)return null;let l=this.flags&16?!0:this.flags&32?!1:e>0;for(let a=l?r.length-1:0;o=r[a],!(e>0?a==0:a==r.length-1||o.top<o.bottom);a+=l?-1:1);return Gi(o,!l)}}get overrideDOMText(){if(!this.length)return F.empty;let{root:e}=this;if(!e)return F.empty;let t=this.posAtStart;return e.view.state.doc.slice(t,t+this.length)}destroy(){super.destroy(),this.widget.destroy(this.dom)}static of(e,t,i,s,r){return r||(r=e.toDOM(t),e.editable||(r.contentEditable="false")),new Ut(r,i,e,s)}}class Xs extends Y{constructor(e){let t=document.createElement("img");t.className="cm-widgetBuffer",t.setAttribute("aria-hidden","true"),super(t,0,e)}get isHidden(){return!0}get overrideDOMText(){return F.empty}coordsIn(e){return this.dom.getBoundingClientRect()}}class Hd{constructor(e){this.index=0,this.beforeBreak=!1,this.parents=[],this.tile=e}advance(e,t,i){let{tile:s,index:r,beforeBreak:o,parents:l}=this;for(;e||t>0;)if(s.isComposite())if(o){if(!e)break;i&&i.break(),e--,o=!1}else if(r==s.children.length){if(!e&&!l.length)break;i&&i.leave(s),o=!!s.breakAfter,{tile:s,index:r}=l.pop(),r++}else{let a=s.children[r],h=a.breakAfter;(t>0?a.length<=e:a.length<e)&&(!i||i.skip(a,0,a.length)!==!1||!a.isComposite)?(o=!!h,r++,e-=a.length):(l.push({tile:s,index:r}),s=a,r=0,i&&a.isComposite()&&i.enter(a))}else if(r==s.length)o=!!s.breakAfter,{tile:s,index:r}=l.pop(),r++;else if(e){let a=Math.min(e,s.length-r);i&&i.skip(s,r,r+a),e-=a,r+=a}else break;return this.tile=s,this.index=r,this.beforeBreak=o,this}get root(){return this.parents.length?this.parents[0].tile:this.tile}}class Wd{constructor(e,t,i,s){this.from=e,this.to=t,this.wrapper=i,this.rank=s}}class zd{constructor(e,t,i){this.cache=e,this.root=t,this.blockWrappers=i,this.curLine=null,this.lastBlock=null,this.afterWidget=null,this.pos=0,this.wrappers=[],this.wrapperPos=0}addText(e,t,i,s){var r;this.flushBuffer();let o=this.ensureMarks(t,i),l=o.lastChild;if(l&&l.isText()&&!(l.flags&8)&&l.length+e.length<512){this.cache.reused.set(l,2);let a=o.children[o.children.length-1]=new Ht(l.dom,l.text+e);a.parent=o}else o.append(s||Ht.of(e,(r=this.cache.find(Ht))===null||r===void 0?void 0:r.dom));this.pos+=e.length,this.afterWidget=null}addComposition(e,t){let i=this.curLine;i.dom!=t.line.dom&&(i.setDOM(this.cache.reused.has(t.line)?$n(t.line.dom):t.line.dom),this.cache.reused.set(t.line,2));let s=i;for(let l=t.marks.length-1;l>=0;l--){let a=t.marks[l],h=s.lastChild;if(h instanceof be&&h.mark.eq(a.mark))h.dom!=a.dom&&h.setDOM($n(a.dom)),s=h;else{if(this.cache.reused.get(a)){let u=Y.get(a.dom);u&&u.setDOM($n(a.dom))}let c=be.of(a.mark,a.dom);s.append(c),s=c}
176this.cache.reused.set(a,2)}let r=Y.get(e.text);r&&this.cache.reused.set(r,2);let o=new Ht(e.text,e.text.nodeValue);o.flags|=8,s.append(o)}addInlineWidget(e,t,i){let s=this.afterWidget&&e.flags&48&&(this.afterWidget.flags&48)==(e.flags&48);s||this.flushBuffer();let r=this.ensureMarks(t,i);!s&&!(e.flags&16)&&r.append(this.getBuffer(1)),r.append(e),this.pos+=e.length,this.afterWidget=e}addMark(e,t,i){this.flushBuffer(),this.ensureMarks(t,i).append(e),this.pos+=e.length,this.afterWidget=null}addBlockWidget(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}continueWidget(e){let t=this.afterWidget||this.lastBlock;t.length+=e,this.pos+=e}addLineStart(e,t){var i;e||(e=sc);let s=pi.start(e,t||((i=this.cache.find(pi))===null||i===void 0?void 0:i.dom),!!t);this.getBlockPos().append(this.lastBlock=this.curLine=s)}addLine(e){this.getBlockPos().append(e),this.pos+=e.length,this.lastBlock=e,this.endLine()}addBreak(){this.lastBlock.flags|=1,this.endLine(),this.pos++}addLineStartIfNotCovered(e){this.blockPosCovered()||this.addLineStart(e)}ensureLine(e){this.curLine||this.addLineStart(e)}ensureMarks(e,t){var i;let s=this.curLine;for(let r=e.length-1;r>=0;r--){let o=e[r],l;if(t>0&&(l=s.lastChild)&&l instanceof be&&l.mark.eq(o))s=l,t--;else{let a=be.of(o,(i=this.cache.find(be,h=>h.mark.eq(o)))===null||i===void 0?void 0:i.dom);s.append(a),s=a,t=0}}return s}endLine(){if(this.curLine){this.flushBuffer();let e=this.curLine.lastChild;(!e||!Ol(this.curLine,!1)||e.dom.nodeName!="BR"&&e.isWidget()&&!(A.ios&&Ol(this.curLine,!0))
vendor: 5,566 bytes, line 176
176)&&this.curLine.append(this.cache.findWidget(Un,0,32)||new Ut(Un.toDOM(),0,Un,32)),this.curLine=this.afterWidget=null}}updateBlockWrappers(){this.wrapperPos>this.pos+1e4&&(this.blockWrappers.goto(this.pos),this.wrappers.length=0);for(let e=this.wrappers.length-1;e>=0;e--)this.wrappers[e].to<this.pos&&this.wrappers.splice(e,1);for(let e=this.blockWrappers;e.value&&e.from<=this.pos;e.next())if(e.to>=this.pos){let t=new Wd(e.from,e.to,e.value,e.rank),i=this.wrappers.length;for(;i>0&&(this.wrappers[i-1].rank-t.rank||this.wrappers[i-1].to-t.to)<0;)i--;this.wrappers.splice(i,0,t)}this.wrapperPos=this.pos}getBlockPos(){var e;this.updateBlockWrappers();let t=this.root;for(let i of this.wrappers){let s=t.lastChild;if(i.from<this.pos&&s instanceof pt&&s.wrapper.eq(i.wrapper))t=s;else{let r=pt.of(i.wrapper,(e=this.cache.find(pt,o=>o.wrapper.eq(i.wrapper)))===null||e===void 0?void 0:e.dom);t.append(r),t=r}}return t}blockPosCovered(){let e=this.lastBlock;return e!=null&&!e.breakAfter&&(!e.isWidget()||(e.flags&160)>0)}getBuffer(e){let t=2|(e<0?16:32),i=this.cache.find(Xs,void 0,1);return i&&(i.flags=t),i||new Xs(t)}flushBuffer(){this.afterWidget&&!(this.afterWidget.flags&32)&&(this.afterWidget.parent.append(this.getBuffer(-1)),this.afterWidget=null)}}class Vd{constructor(e){this.skipCount=0,this.text="",this.textOff=0,this.cursor=e.iter()}skip(e){this.textOff+e<=this.text.length?this.textOff+=e:(this.skipCount+=e-(this.text.length-this.textOff),this.text="",this.textOff=0)}next(e){if(this.textOff==this.text.length){let{value:s,lineBreak:r,done:o}=this.cursor.next(this.skipCount);if(this.skipCount=0,o)throw new Error("Ran out of text content when drawing inline views");this.text=s;let l=this.textOff=Math.min(e,s.length);return r?null:s.slice(0,l)}let t=Math.min(this.text.length,this.textOff+e),i=this.text.slice(this.textOff,t);return this.textOff=t,i}}const Ys=[Ut,pi,Ht,be,Xs,pt,En];for(let n=0;n<Ys.length;n++)Ys[n].bucket=n;class $d{constructor(e){this.view=e,this.buckets=Ys.map(()=>[]),this.index=Ys.map(()=>0),this.reused=new Map}add(e){let t=e.constructor.bucket,i=this.buckets[t];i.length<6?i.push(e):i[this.index[t]=(this.index[t]+1)%6]=e}find(e,t,i=2){let s=e.bucket,r=this.buckets[s],o=this.index[s];for(let l=r.length-1;l>=0;l--){let a=(l+o)%r.length,h=r[a];if((!t||t(h))&&!this.reused.has(h))return r.splice(a,1),a<o&&this.index[s]--,this.reused.set(h,i),h}return null}findWidget(e,t,i){let s=this.buckets[0];if(s.length)for(let r=0,o=0;;r++){if(r==s.length){if(o)return null;o=1,r=0}let l=s[r];if(!this.reused.has(l)&&(o==0?l.widget.compare(e):l.widget.constructor==e.constructor&&e.updateDOM(l.dom,this.view,l.widget)))return s.splice(r,1),r<this.index[0]&&this.index[0]--,l.widget==e&&l.length==t&&(l.flags&497)==i?(this.reused.set(l,1),l):(this.reused.set(l,2),new Ut(l.dom,t,e,l.flags&-498|i))}}reuse(e){return this.reused.set(e,1),e}maybeReuse(e,t=2){if(!this.reused.has(e))return this.reused.set(e,t),e.dom}clear(){for(let e=0;e<this.buckets.length;e++)this.buckets[e].length=this.index[e]=0}}class Ud{constructor(e,t,i,s,r){this.view=e,this.decorations=s,this.disallowBlockEffectsFor=r,this.openWidget=!1,this.openMarks=0,this.cache=new $d(e),this.text=new Vd(e.state.doc),this.builder=new zd(this.cache,new En(e,e.contentDOM),P.iter(i)),this.cache.reused.set(t,2),this.old=new Hd(t),this.reuseWalker={skip:(o,l,a)=>{if(this.cache.add(o),o.isComposite())return!1},enter:o=>this.cache.add(o),leave:()=>{},break:()=>{}}}run(e,t){let i=t&&this.getCompositionContext(t.text);for(let s=0,r=0,o=0;;){let l=o<e.length?e[o++]:null,a=l?l.fromA:this.old.root.length;if(a>s){let h=a-s;this.preserve(h,!o,!l),s=a,r+=h}if(!l)break;t&&l.fromA<=t.range.fromA&&l.toA>=t.range.toA?(this.forward(l.fromA,t.range.fromA,t.range.fromA<t.range.toA?1:-1),this.emit(r,t.range.fromB),this.cache.clear(),this.builder.addComposition(t,i),this.text.skip(t.range.toB-t.range.fromB),this.forward(t.range.fromA,l.toA),this.emit(t.range.toB,l.toB)):(this.forward(l.fromA,l.toA),this.emit(r,l.toB)),r=l.toB,s=l.toA}return this.builder.curLine&&this.builder.endLine(),this.builder.root}preserve(e,t,i){let s=jd(this.old),r=this.openMarks;this.old.advance(e,i?1:-1,{skip:(o,l,a)=>{if(o.isWidget())if(this.openWidget)this.builder.continueWidget(a-l);else{let h=a>0||l<o.length?Ut.of(o.widget,this.view,a-l,o.flags&496,this.cache.maybeReuse(o)):this.cache.reuse(o);h.flags&256?(h.flags&=-2,this.builder.addBlockWidget(h)):(this.builder.ensureLine(null),this.builder.addInlineWidget(h,s,r),r=s.length)}else if(o.isText())this.builder.ensureLine(null),!l&&a==o.length&&!this.cache.reused.has(o)?this.builder.addText(o.text,s,r,this.cache.reuse(o)):(this.cache.add(o),this.builder.addText(o.text.slice(l,a),s,r)),r=s.length;else if(o.isLine())o.flags&=-2,this.cache.reused.set(o,1),this.builder.addLine(o);else if(o instanceof Xs)this.cache.add(o);else if(o instanceof be)this.builder.ensureLine(null),this.builder.addMark(o,s,r),this.cache.reused.set(o,1),r=s.length;else return!1;this.openWidget=!1},enter:o=>{o.isLine()?this.builder.addLineStart(o.attrs,this.cache.maybeReuse(o)):(this.cache.add(o),o instanceof be&&s.unshift(o.mark)),this.openWidget=!1},leave:o=>{o.isLine()?s.length&&(s.length=r=0):o instanceof be&&(s.shift(),r=Math.min(r,s.length))},break:()=>{this.builder.addBreak(),this.openWidget=!1}}),this.text.skip(e)}emit(e,t){let i=null,s=this.builder,r=0,o=P.spans(this.decorations,e,t,{point:(l,a,h,c,u,f)=>{if(h instanceof Vt){if(this.disallowBlockEffectsFor[f]){if(h.block)throw new RangeError("Block decorations may not be specified via plugins");
176if(a>this.view.state.doc.lineAt(l).to)throw new RangeError("Decorations that replace line breaks may not be specified via plugins")}if(r=c.length,u>c.length)s.continueWidget(a-l);else{let d=h.widget||(h.block?mi.block:mi.inline),p=qd(h),m=this.cache.findWidget(d,a-l,p)||Ut.of(d,this.view,a-l,p);h.block?(h.startSide>0&&s.addLineStartIfNotCovered(i),s.addBlockWidget(m)):(s.ensureLine(i),s.addInlineWidget(m,c,u))}i=null}else i=Qd(i,h);a>l&&this.text.skip(a-l)},span:(l,a,h,c)=>{for(let u=l;u<a;){let f=this.text.next(Math.min(512,a-u));f==null?(s.addLineStartIfNotCovered(i),s.addBreak(),u++):(s.ensureLine(i),s.addText(f,h,u==l?c:h.length),u+=f.length),i=null}}});s.addLineStartIfNotCovered(i),this.openWidget=o>r,this.openMarks=o}forward(e,t,i=1){t-e<=10?this.old.advance(t-e,i,this.reuseWalker):(this.old.advance(5,-1,this.reuseWalker),this.old.advance(t-e-10,-1),this.old.advance(5,i,this.reuseWalker))}getCompositionContext(e){let t=[],i=null;for(let s=e.parentNode;;s=s.parentNode){let r=Y.get(s);if(s==this.view.contentDOM)break;r instanceof be?t.push(r):r?.isLine()?i=r:r instanceof pt||(s.nodeName=="DIV"&&!i&&s!=this.view.contentDOM?i=new pi(s,sc):i||t.push(be.of(new ss({tagName:s.nodeName.toLowerCase(),attributes:bd(s)}),s)))}return{line:i,marks:t}}}function Ol(n,e){let t=i=>{for(let s of i.children)if((e?s.isText():s.length)||t(s))return!0;return!1};return t(n)}function qd(n){let e=n.isReplace?(n.startSide<0?64:0)|(n.endSide>0?128:0):n.startSide>0?32:16;return n.block&&(e|=256),e}const sc={class:"cm-line"};function Qd(n,e){let t=e.spec.attributes,i=e.spec.class;return!t&&!i||(n||(n={class:"cm-line"}),t&&So(t,n),i&&(n.class+=" "+i)),n}function jd(n){let e=[];for(let t=n.parents.length;t>1;t--){let i=t==n.parents.length?n.tile:n.parents[t].tile;i instanceof be&&e.push(i.mark)}return e}function $n(n){let e=Y.get(n);return e&&e.setDOM(n.cloneNode()),n}class mi extends is{constructor(e){super(),this.tag=e}eq(e){return e.tag==this.tag}toDOM(){return document.createElement(this.tag)}updateDOM(e){return e.nodeName.toLowerCase()==this.tag}get isHidden(){return!0}}mi.inline=new mi("span");mi.block=new mi("div");const Un=new class extends is{toDOM(){return document.createElement("br")}get isHidden(){return!0}get editable(){return!0}};class Dl{constructor(e){this.view=e,this.decorations=[],this.blockWrappers=[],this.dynamicDecorationMap=[!1],this.domChanged=null,this.hasComposition=null,this.editContextFormatting=j.none,this.lastCompositionAfterCursor=!1,this.minWidth=0,this.minWidthFrom=0,this.minWidthTo=0,this.impreciseAnchor=null,this.impreciseHead=null,this.forceSelection=!1,this.lastUpdate=Date.now(),this.updateDeco(),this.tile=new En(e,e.contentDOM),this.updateInner([new _e(0,0,0,e.state.doc.length)],null)}update(e){var t;let i=e.changedRanges;this.minWidth>0&&i.length&&(i.every(({fromA:c,toA:u})=>u<this.minWidthFrom||c>this.minWidthTo)?(this.minWidthFrom=e.changes.mapPos(this.minWidthFrom,1),this.minWidthTo=e.changes.mapPos(this.minWidthTo,1)):this.minWidth=this.minWidthFrom=this.minWidthTo=0),this.updateEditContextFormatting(e);let s=-1;this.view.inputState.composing>=0&&!this.view.observer.editContext&&(!((t=this.domChanged)===null||t===void 0)&&t.newSel?s=this.domChanged.newSel.head:!ip(e.changes,this.hasComposition)&&!e.selectionSet&&(s=e.state.selection.main.head));let r=s>-1?Kd(this.view,e.changes,s):null;if(this.domChanged=null,this.hasComposition){let{from:c,to:u}=this.hasComposition;i=new _e(c,u,e.changes.mapPos(c,-1),e.changes.mapPos(u,1)).addToSet(i.slice())}this.hasComposition=r?{from:r.range.fromB,to:r.range.toB}:null,(A.ie||A.chrome)&&!r&&e&&e.state.doc.lines!=e.startState.doc.lines&&(this.forceSelection=!0);let o=this.decorations,l=this.blockWrappers;this.updateDeco();let a=Jd(o,this.decorations,e.changes);a.length&&(i=_e.extendWithRanges(i,a));let h=ep(l,this.blockWrappers,e.changes);return h.length&&(i=_e.extendWithRanges(i,h)),r&&!i.some(c=>c.fromA<=r.range.fromA&&c.toA>=r.range.toA)&&(i=r.range.addToSet(i.slice())),this.tile.flags&2&&i.length==0?!1:(this.updateInner(i,r),e.transactions.length&&(this.lastUpdate=Date.now()),!0)}updateInner(e,t){this.view.viewState.mustMeasureContent=!0;let{observer:i}=this.view;i.ignore(()=>
vendor: 7,321 bytes, line 176
176{if(t||e.length){let o=this.tile,l=new Ud(this.view,o,this.blockWrappers,this.decorations,this.dynamicDecorationMap);t&&Y.get(t.text)&&l.cache.reused.set(Y.get(t.text),2),this.tile=l.run(e,t),Qr(o,l.cache.reused)}this.tile.dom.style.height=this.view.viewState.contentHeight/this.view.scaleY+"px",this.tile.dom.style.flexBasis=this.minWidth?this.minWidth+"px":"";let r=A.chrome||A.ios?{node:i.selectionRange.focusNode,written:!1}:void 0;this.tile.sync(r),r&&(r.written||i.selectionRange.focusNode!=r.node||!this.tile.dom.contains(r.node))&&(this.forceSelection=!0),this.tile.dom.style.height=""});let s=[];if(this.view.viewport.from||this.view.viewport.to<this.view.state.doc.length)for(let r of this.tile.children)r.isWidget()&&r.widget instanceof qn&&s.push(r.dom);i.updateGaps(s)}updateEditContextFormatting(e){this.editContextFormatting=this.editContextFormatting.map(e.changes);for(let t of e.transactions)for(let i of t.effects)i.is(Jh)&&(this.editContextFormatting=i.value)}updateSelection(e=!1,t=!1){(e||!this.view.observer.selectionRange.focusNode)&&this.view.observer.readSelectionRange();let{dom:i}=this.tile,s=this.view.root.activeElement,r=s==i,o=!r&&!(this.view.state.facet(ft)||i.tabIndex>-1)&&Pi(i,this.view.observer.selectionRange)&&!(s&&i.contains(s));if(!(r||t||o))return;let l=this.forceSelection;this.forceSelection=!1;let a=this.view.state.selection.main,h,c;if(a.empty?c=h=this.inlineDOMNearPos(a.anchor,a.assoc||1):(c=this.inlineDOMNearPos(a.head,a.head==a.from?1:-1),h=this.inlineDOMNearPos(a.anchor,a.anchor==a.from?1:-1)),A.gecko&&a.empty&&!this.hasComposition&&Gd(h)){let f=document.createTextNode("");this.view.observer.ignore(()=>h.node.insertBefore(f,h.node.childNodes[h.offset]||null)),h=c=new Qe(f,0),l=!0}let u=this.view.observer.selectionRange;(l||!u.focusNode||(!Hi(h.node,h.offset,u.anchorNode,u.anchorOffset)||!Hi(c.node,c.offset,u.focusNode,u.focusOffset))&&!this.suppressWidgetCursorChange(u,a))&&(this.view.observer.ignore(()=>{A.android&&A.chrome&&i.contains(u.focusNode)&&tp(u.focusNode,i)&&(i.blur(),i.focus({preventScroll:!0}));let f=ji(this.view.root);if(f)if(a.empty){if(A.gecko){let d=Xd(h.node,h.offset);if(d&&d!=3){let p=(d==1?Ph:Fh)(h.node,h.offset);p&&(h=new Qe(p.node,p.offset))}}f.collapse(h.node,h.offset),a.bidiLevel!=null&&f.caretBidiLevel!==void 0&&(f.caretBidiLevel=a.bidiLevel)}else if(f.extend){f.collapse(h.node,h.offset);try{f.extend(c.node,c.offset)}catch{}}else{let d=document.createRange();a.anchor>a.head&&([h,c]=[c,h]),d.setEnd(c.node,c.offset),d.setStart(h.node,h.offset),f.removeAllRanges(),f.addRange(d)}o&&this.view.root.activeElement==i&&(i.blur(),s&&s.focus())}),this.view.observer.setSelectionRange(h,c)),this.impreciseAnchor=h.precise?null:new Qe(u.anchorNode,u.anchorOffset),this.impreciseHead=c.precise?null:new Qe(u.focusNode,u.focusOffset)}suppressWidgetCursorChange(e,t){return this.hasComposition&&t.empty&&Hi(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)&&this.posFromDOM(e.focusNode,e.focusOffset)==t.head}enforceCursorAssoc(){if(this.hasComposition)return;let{view:e}=this,t=e.state.selection.main,i=ji(e.root),{anchorNode:s,anchorOffset:r}=e.observer.selectionRange;if(!i||!t.empty||!t.assoc||!i.modify)return;let o=this.lineAt(t.head,t.assoc);if(!o)return;let l=o.posAtStart;if(t.head==l||t.head==l+o.length)return;let a=this.coordsAt(t.head,-1),h=this.coordsAt(t.head,1);if(!a||!h||a.bottom>h.top)return;let c=this.domAtPos(t.head+t.assoc,t.assoc);i.collapse(c.node,c.offset),i.modify("move",t.assoc<0?"forward":"backward","lineboundary"),e.observer.readSelectionRange();let u=e.observer.selectionRange;e.docView.posFromDOM(u.anchorNode,u.anchorOffset)!=t.from&&i.collapse(s,r)}posFromDOM(e,t){let i=this.tile.nearest(e);if(!i)return this.tile.dom.compareDocumentPosition(e)&2?0:this.view.state.doc.length;let s=i.posAtStart;if(i.isComposite()){let r;if(e==i.dom)r=i.dom.childNodes[t];else{let o=mt(e)==0?0:t==0?-1:1;for(;;){let l=e.parentNode;if(l==i.dom)break;o==0&&l.firstChild!=l.lastChild&&(e==l.firstChild?o=-1:o=1),e=l}o<0?r=e:r=e.nextSibling}if(r==i.dom.firstChild)return s;for(;r&&!Y.get(r);)r=r.nextSibling;if(!r)return s+i.length;for(let o=0,l=s;;o++){let a=i.children[o];if(a.dom==r)return l;l+=a.length+a.breakAfter}}else return i.isText()?e==i.dom?s+t:s+(t?i.length:0):s}domAtPos(e,t){let{tile:i,offset:s}=this.tile.resolveBlock(e,t);return i.isWidget()?i.domPosFor(e,t):i.domIn(s,t)}inlineDOMNearPos(e,t){let i,s=-1,r=!1,o,l=-1,a=!1;return this.tile.blockTiles((h,c)=>{if(h.isWidget()){if(h.flags&32&&c>=e)return!0;h.flags&16&&(r=!0)}else{let u=c+h.length;if(c<=e&&(i=h,s=e-c,r=u<e),u>=e&&!o&&(o=h,l=e-c,a=c>e),c>e&&o)return!0}}),!i&&!o?this.domAtPos(e,t):(r&&o?i=null:a&&i&&(o=null),i&&t<0||!o?i.domIn(s,t):o.domIn(l,t))}coordsAt(e,t){let{tile:i,offset:s}=this.tile.resolveBlock(e,t);return i.isWidget()?i.widget instanceof qn?null:i.coordsInWidget(s,t,!0):i.coordsIn(s,t)}lineAt(e,t){let{tile:i}=this.tile.resolveBlock(e,t);return i.isLine()?i:null}coordsForChar(e){let{tile:t,offset:i}=this.tile.resolveBlock(e,1);if(!t.isLine())return null;function s(r,o){if(r.isComposite())for(let l of r.children){if(l.length>=o){let a=s(l,o);if(a)return a}if(o-=l.length,o<0)break}else if(r.isText()&&o<r.length){let l=oe(r.text,o);if(l==o)return null;let a=Ki(r.dom,o,l).getClientRects();for(let h=0;h<a.length;h++){let c=a[h];if(h==a.length-1||c.top<c.bottom&&c.left<c.right)return c}}return null}return s(t,i)}measureVisibleLineHeights(e){let t=[],{from:i,to:s}=e,r=this.view.contentDOM.clientWidth,o=r>Math.max(this.view.scrollDOM.clientWidth,this.minWidth)+1,l=-1,a=this.view.textDirection==G.LTR,h=0,c=(u,f,d)=>{for(let p=0;p<u.children.length&&!(f>s);p++){let m=u.children[p],g=f+m.length,y=m.dom.getBoundingClientRect(),{height:b}=y;if(d&&!p&&(h+=y.top-d.top),m instanceof pt)g>i&&c(m,f,y);else if(f>=i&&(h>0&&t.push(-h),t.push(b+h),h=0,o)){let C=m.dom.lastChild,k=C?Fi(C):[];if(k.length){let x=k[k.length-1],T=a?x.right-y.left:y.right-x.left;T>l&&(l=T,this.minWidth=r,this.minWidthFrom=f,this.minWidthTo=g)}}d&&p==u.children.length-1&&(h+=d.bottom-y.bottom),f=g+m.breakAfter}};return c(this.tile,0,null),t}textDirectionAt(e){let{tile:t}=this.tile.resolveBlock(e,1);return getComputedStyle(t.dom).direction=="rtl"?G.RTL:G.LTR}measureTextSize(){let e=this.tile.blockTiles(o=>{if(o.isLine()&&o.children.length&&o.length<=20){let l=0,a;for(let h of o.children){if(!h.isText()||/[^ -~]/.test(h.text))return;let c=Fi(h.dom);if(c.length!=1)return;l+=c[0].width,a=c[0].height}if(l)return{lineHeight:o.dom.getBoundingClientRect().height,charWidth:l/o.length,textHeight:a}}});if(e)return e;let t=document.createElement("div"),i,s,r;return t.className="cm-line",t.style.width="99999px",t.style.position="absolute",t.textContent="abc def ghi jkl mno pqr stu",this.view.observer.ignore(()=>{this.tile.dom.appendChild(t);let o=Fi(t.firstChild)[0];i=t.getBoundingClientRect().height,s=o&&o.width?o.width/27:7,r=o&&o.height?o.height:i,t.remove()}),{lineHeight:i,charWidth:s,textHeight:r}}computeBlockGapDeco(){let e=[],t=this.view.viewState;for(let i=0,s=0;;s++){let r=s==t.viewports.length?null:t.viewports[s],o=r?r.from-1:this.view.state.doc.length;if(o>i){let l=(t.lineBlockAt(o).bottom-t.lineBlockAt(i).top)/this.view.scaleY;e.push(j.replace({widget:new qn(l),block:!0,inclusive:!0,isBlockGap:!0}).range(i,o))}if(!r)break;
176i=r.to+1}return j.set(e)}updateDeco(){let e=1,t=this.view.state.facet(An).map(r=>(this.dynamicDecorationMap[e++]=typeof r=="function")?r(this.view):r),i=!1,s=this.view.state.facet(Eo).map((r,o)=>{let l=typeof r=="function";return l&&(i=!0),l?r(this.view):r});for(s.length&&(this.dynamicDecorationMap[e++]=i,t.push(P.join(s))),this.decorations=[this.editContextFormatting,...t,this.computeBlockGapDeco(),this.view.viewState.lineGapDeco];e<this.decorations.length;)this.dynamicDecorationMap[e++]=!1;this.blockWrappers=this.view.state.facet(ec).map(r=>typeof r=="function"?r(this.view):r)}scrollIntoView(e){var t;if(e.isSnapshot){let c=this.view.viewState.lineBlockAt(e.range.head);this.view.scrollDOM.scrollTop=c.top-e.yMargin,this.view.scrollDOM.scrollLeft=e.xMargin;return}for(let c of this.view.state.facet(Yh))try{if(c(this.view,e.range,e))return!0}catch(u){De(this.view.state,u,"scroll handler")}let{range:i}=e,s=this.coordsAt(i.head,(t=i.assoc)!==null&&t!==void 0?t:i.empty?0:i.head>i.anchor?-1:1),r;if(!s)return;!i.empty&&(r=this.coordsAt(i.anchor,i.anchor>i.head?-1:1))&&(s={left:Math.min(s.left,r.left),top:Math.min(s.top,r.top),right:Math.max(s.right,r.right),bottom:Math.max(s.bottom,r.bottom)});let o=Oo(this.view),l={left:s.left-o.left,top:s.top-o.top,right:s.right+o.right,bottom:s.bottom+o.bottom},{offsetWidth:a,offsetHeight:h}=this.view.scrollDOM;if(xd(this.view.scrollDOM,l,i.head<i.anchor?-1:1,e.x,e.y,Math.max(Math.min(e.xMargin,a),-a),Math.max(Math.min(e.yMargin,h),-h),this.view.textDirection==G.LTR),window.visualViewport&&window.innerHeight-window.visualViewport.height>1&&(s.top>window.pageYOffset+window.visualViewport.offsetTop+window.visualViewport.height||s.bottom<window.pageYOffset+window.visualViewport.offsetTop)){let c=this.view.docView.lineAt(i.head,1);c&&c.dom.scrollIntoView({block:"nearest"})}}lineHasWidget(e){let t=i=>i.isWidget()||i.children.some(t);return t(this.tile.resolveBlock(e,1).tile)}destroy(){Qr(this.tile)}}function Qr(n,e){let t=e?.get(n);if(t!=1){t==null&&n.destroy();for(let i of n.children)Qr(i,e)}}function Gd(n){return n.node.nodeType==1&&n.node.firstChild&&(n.offset==0||n.node.childNodes[n.offset-1].contentEditable=="false")&&(n.offset==n.node.childNodes.length||n.node.childNodes[n.offset].contentEditable=="false")}function nc(n,e){let t=n.observer.selectionRange;if(!t.focusNode)return null;let i=Ph(t.focusNode,t.focusOffset),s=Fh(t.focusNode,t.focusOffset),r=i||s;if(s&&i&&s.node!=i.node){let l=Y.get(s.node);if(!l||l.isText()&&l.text!=s.node.nodeValue)r=s;else if(n.docView.lastCompositionAfterCursor){let a=Y.get(i.node);!a||a.isText()&&a.text!=i.node.nodeValue||(r=s)}}if(n.docView.lastCompositionAfterCursor=r!=i,!r)return null;let o=e-r.offset;return{from:o,to:o+r.node.nodeValue.length,node:r.node}}function Kd(n,e,t){let i=nc(n,t);if(!i)return null;let{node:s,from:r,to:o}=i,l=s.nodeValue;if(/[\n\r]/.test(l)||n.state.doc.sliceString(i.from,i.to)!=l)return null;let a=e.invertedDesc;return{range:new _e(a.mapPos(r),a.mapPos(o),r,o),text:s}}function Xd(n,e){return n.nodeType!=1?0:(e&&n.childNodes[e-1].contentEditable=="false"?1:0)|(e<n.childNodes.length&&n.childNodes[e].contentEditable=="false"?2:0)}let Yd=class{constructor(){this.changes=[]}compareRange(e,t){oi(e,t,this.changes)}comparePoint(e,t){oi(e,t,this.changes)}boundChange(e){oi(e,e,this.changes)}};function Jd(n,e,t){let i=new Yd;return P.compare(n,e,t,i),i.changes}class Zd{constructor(){this.changes=[]}compareRange(e,t){oi(e,t,this.changes)}comparePoint(){}boundChange(e){oi(e,e,this.changes)}}function ep(n,e,t){let i=new Zd;return P.compare(n,e,t,i),i.changes}function tp(n,e){for(let t=n;t&&t!=e;t=t.assignedSlot||t.parentNode)if(t.nodeType==1&&t.contentEditable=="false")return!0;return!1}function ip(n,e){let t=!1;return e&&n.iterChangedRanges((i,s)=>{i<e.to&&s>e.from&&(t=!0)}),t}class qn extends is{constructor(e){super(),this.height=e}toDOM(){let e=document.createElement("div");return e.className="cm-gap",this.updateDOM(e),e}eq(e){return e.height==this.height}updateDOM(e){return e.style.height=this.height+"px",!0}get editable(){return!0}get estimatedHeight(){return this.height}ignoreEvent(){return!1}}function sp(n,e,t=1){let i=n.charCategorizer(e),s=n.doc.lineAt(e),r=e-s.from;if(s.length==0)return w.cursor(e);r==0?t=1:r==s.length&&(t=-1);let o=r,l=r;t<0?o=oe(s.text,r,!1):l=oe(s.text,r);let a=i(s.text.slice(o,l));for(;o>0;
vendor: 14,591 bytes, lines 176-178
176){let h=oe(s.text,o,!1);if(i(s.text.slice(h,o))!=a)break;o=h}for(;l<s.length;){let h=oe(s.text,l);if(i(s.text.slice(l,h))!=a)break;l=h}return w.range(o+s.from,l+s.from)}function np(n,e,t,i,s){let r=Math.round((i-e.left)*n.defaultCharacterWidth);if(n.lineWrapping&&t.height>n.defaultLineHeight*1.5){let l=n.viewState.heightOracle.textHeight,a=Math.floor((s-t.top-(n.defaultLineHeight-l)*.5)/l);r+=a*n.viewState.heightOracle.lineLength}let o=n.state.sliceDoc(t.from,t.to);return t.from+ud(o,r,n.state.tabSize)}function rp(n,e,t){let i=n.lineBlockAt(e);if(Array.isArray(i.type)){let s;for(let r of i.type){if(r.from>e)break;if(!(r.to<e)){if(r.from<e&&r.to>e)return r;(!s||r.type==Ce.Text&&(s.type!=r.type||(t<0?r.from<e:r.to>e)))&&(s=r)}}return s||i}return i}function op(n,e,t,i){let s=rp(n,e.head,e.assoc||-1),r=!i||s.type!=Ce.Text||!(n.lineWrapping||s.widgetLineBreaks)?null:n.coordsAtPos(e.assoc<0&&e.head>s.from?e.head-1:e.head);if(r){let o=n.dom.getBoundingClientRect(),l=n.textDirectionAt(s.from),a=n.posAtCoords({x:t==(l==G.LTR)?o.right-1:o.left+1,y:(r.top+r.bottom)/2});if(a!=null)return w.cursor(a,t?-1:1)}return w.cursor(t?s.to:s.from,t?-1:1)}function Rl(n,e,t,i){let s=n.state.doc.lineAt(e.head),r=n.bidiSpans(s),o=n.textDirectionAt(s.from);for(let l=e,a=null;;){let h=Ld(s,r,o,l,t),c=$h;if(!h){if(s.number==(t?n.state.doc.lines:1))return l;c=` 177`,s=n.state.doc.line(s.number+(t?1:-1)),r=n.bidiSpans(s),h=n.visualLineSide(s,!t)}if(a){if(!a(c))return l}else{if(!i)return h;a=i(c)}l=h}}function lp(n,e,t){let i=n.state.charCategorizer(e),s=i(t);return r=>{let o=i(r);return s==ce.Space&&(s=o),s==o}}function ap(n,e,t,i){let s=e.head,r=t?1:-1;if(s==(t?n.state.doc.length:0))return w.cursor(s,e.assoc);let o=e.goalColumn,l,a=n.contentDOM.getBoundingClientRect(),h=n.coordsAtPos(s,e.assoc||((e.empty?t:e.head==e.from)?1:-1)),c=n.documentTop;if(h)o==null&&(o=h.left-a.left),l=r<0?h.top:h.bottom;else{let p=n.viewState.lineBlockAt(s);o==null&&(o=Math.min(a.right-a.left,n.defaultCharacterWidth*(s-p.from))),l=(r<0?p.top:p.bottom)+c}let u=a.left+o,f=n.viewState.heightOracle.textHeight>>1,d=i??f;for(let p=0;;p+=f){let m=l+(d+p)*r,g=jr(n,{x:u,y:m},!1,r);if(t?m>a.bottom:m<a.top)return w.cursor(g.pos,g.assoc);let y=n.coordsAtPos(g.pos,g.assoc),b=y?(y.top+y.bottom)/2:0;if(!y||(t?b>l:b<l))return w.cursor(g.pos,g.assoc,void 0,o)}}function Wi(n,e,t){for(;;){let i=0;for(let s of n)s.between(e-1,e+1,(r,o,l)=>{if(e>r&&e<o){let a=i||t||(e-r<o-e?-1:1);e=a<0?r:o,i=a}});if(!i)return e}}function rc(n,e){let t=null;for(let i=0;i<e.ranges.length;i++){let s=e.ranges[i],r=null;if(s.empty){let o=Wi(n,s.from,0);o!=s.from&&(r=w.cursor(o,-1))}else{let o=Wi(n,s.from,-1),l=Wi(n,s.to,1);(o!=s.from||l!=s.to)&&(r=w.range(s.from==s.anchor?o:l,s.from==s.head?o:l))}r&&(t||(t=e.ranges.slice()),t[i]=r)}return t?w.create(t,e.mainIndex):e}function Qn(n,e,t){let i=Wi(n.state.facet(rs).map(s=>s(n)),t.from,e.head>t.from?-1:1);return i==t.from?t:w.cursor(i,i<t.from?1:-1)}class ot{constructor(e,t){this.pos=e,this.assoc=t}}function jr(n,e,t,i){let s=n.contentDOM.getBoundingClientRect(),r=s.top+n.viewState.paddingTop,{x:o,y:l}=e,a=l-r,h;for(;;){if(a<0)return new ot(0,1);if(a>n.viewState.docHeight)return new ot(n.state.doc.length,-1);if(h=n.elementAtHeight(a),i==null)break;if(h.type==Ce.Text){if(i<0?h.to<n.viewport.from:h.from>n.viewport.to)break;let f=n.docView.coordsAt(i<0?h.from:h.to,i>0?-1:1);if(f&&(i<0?f.top<=a+r:f.bottom>=a+r))break}let u=n.viewState.heightOracle.textHeight/2;a=i>0?h.bottom+u:h.top-u}if(n.viewport.from>=h.to||n.viewport.to<=h.from){if(t)return null;if(h.type==Ce.Text){let u=np(n,s,h,o,l);return new ot(u,u==h.from?1:-1)}}if(h.type!=Ce.Text)return a<(h.top+h.bottom)/2?new ot(h.from,1):new ot(h.to,-1);let c=n.docView.lineAt(h.from,2);return(!c||c.length!=h.length)&&(c=n.docView.lineAt(h.from,-2)),new hp(n,o,l,n.textDirectionAt(h.from)).scanTile(c,h.from)}class hp{constructor(e,t,i,s){this.view=e,this.x=t,this.y=i,this.baseDir=s,this.line=null,this.spans=null}bidiSpansAt(e){return(!this.line||this.line.from>e||this.line.to<e)&&(this.line=this.view.state.doc.lineAt(e),this.spans=this.view.bidiSpans(this.line)),this}baseDirAt(e,t){let{line:i,spans:s}=this.bidiSpansAt(e);return s[lt.find(s,e-i.from,-1,t)].level==this.baseDir}dirAt(e,t){let{line:i,spans:s}=this.bidiSpansAt(e);return s[lt.find(s,e-i.from,-1,t)].dir}bidiIn(e,t){let{spans:i,line:s}=this.bidiSpansAt(e);return i.length>1||i.length&&(i[0].level!=this.baseDir||i[0].to+s.from<t)}scan(e,t){let i=0,s=e.length-1,r=new Set,o=this.bidiIn(e[0],e[s]),l,a,h=-1,c=1e9,u;e:for(;i<s;){let d=s-i,p=i+s>>1;t:if(r.has(p)){let g=i+Math.floor(Math.random()*d);for(let y=0;y<d;y++){if(!r.has(g)){p=g;break t}g++,g==s&&(g=i)}break e}r.add(p);let m=t(p);if(m)for(let g=0;g<m.length;g++){let y=m[g],b=0;if(!(y.width==0&&m.length>1)){if(y.bottom<this.y)(!l||l.bottom<y.bottom)&&(l=y),b=1;else if(y.top>this.y)(!a||a.top>y.top)&&(a=y),b=-1;else{let C=y.left>this.x?this.x-y.left:y.right<this.x?this.x-y.right:0,k=Math.abs(C);k<c&&(h=p,c=k,u=y),C&&(b=C<0==(this.baseDir==G.LTR)?-1:1)}b==-1&&(!o||this.baseDirAt(e[p],1))?s=p:b==1&&(!o||this.baseDirAt(e[p+1],-1))&&(i=p+1)}}}if(!u){let d=l&&(!a||this.y-l.bottom<a.top-this.y)?l:a;return this.y=(d.top+d.bottom)/2,this.scan(e,t)}if(c){if(l&&l.bottom>u.top)return this.y=l.bottom-1,this.scan(e,t);if(a&&a.top<u.bottom)return this.y=a.top+1,this.scan(e,t)}let f=(o?this.dirAt(e[h],1):this.baseDir)==G.LTR;return{i:h,after:this.x>(u.left+u.right)/2==f}}scanText(e,t){let i=[];for(let r=0;r<e.length;r=oe(e.text,r))i.push(t+r);i.push(t+e.length);let s=this.scan(i,r=>{let o=i[r]-t,l=i[r+1]-t;return Ki(e.dom,o,l).getClientRects()});return s.after?new ot(i[s.i+1],-1):new ot(i[s.i],1)}scanTile(e,t){if(!e.length)return new ot(t,1);if(e.children.length==1){let l=e.children[0];if(l.isText())return this.scanText(l,t);if(l.isComposite())return this.scanTile(l,t)}let i=[t];for(let l=0,a=t;l<e.children.length;l++)i.push(a+=e.children[l].length);let s=this.scan(i,l=>{let a=e.children[l];return a.flags&48?null:(a.dom.nodeType==1?a.dom:Ki(a.dom,0,a.length)).getClientRects()}),r=e.children[s.i],o=i[s.i];return r.isText()?this.scanText(r,o):r.isComposite()?this.scanTile(r,o):s.after?new ot(i[s.i+1],-1):new ot(o,1)}}const Gt="ï¿¿";class cp{constructor(e,t){this.points=e,this.view=t,this.text="",this.lineSeparator=t.state.facet(W.lineSeparator)}append(e){this.text+=e}lineBreak(){this.text+=Gt}readRange(e,t){if(!e)return this;let i=e.parentNode;for(let s=e;;){this.findPointBefore(i,s);let r=this.text.length;this.readNode(s);let o=Y.get(s),l=s.nextSibling;if(l==t){o?.breakAfter&&!l&&i!=this.view.contentDOM&&this.lineBreak();break}let a=Y.get(l);(o&&a?o.breakAfter:(o?o.breakAfter:Gs(s))||Gs(l)&&(s.nodeName!="BR"||o?.isWidget())&&this.text.length>r)&&!fp(l,t)&&this.lineBreak(),s=l}return this.findPointBefore(i,t),this}readTextNode(e){let t=e.nodeValue;for(let i of this.points)i.node==e&&(i.pos=this.text.length+Math.min(i.offset,t.length));for(let i=0,s=this.lineSeparator?null:/\r\n?|\n/g;;){let r=-1,o=1,l;if(this.lineSeparator?(r=t.indexOf(this.lineSeparator,i),o=this.lineSeparator.length):(l=s.exec(t))&&(r=l.index,o=l[0].length),this.append(t.slice(i,r<0?t.length:r)),r<0)break;if(this.lineBreak(),o>1)for(let a of this.points)a.node==e&&a.pos>this.text.length&&(a.pos-=o-1);i=r+o}}readNode(e){let t=Y.get(e),i=t&&t.overrideDOMText;if(i!=null){this.findPointInside(e,i.length);for(let s=i.iter();!s.next().done;)s.lineBreak?this.lineBreak():this.append(s.value)}else e.nodeType==3?this.readTextNode(e):e.nodeName=="BR"?e.nextSibling&&this.lineBreak():e.nodeType==1&&this.readRange(e.firstChild,null)}findPointBefore(e,t){for(let i of this.points)i.node==e&&e.childNodes[i.offset]==t&&(i.pos=this.text.length)}findPointInside(e,t){for(let i of this.points)(e.nodeType==3?i.node==e:e.contains(i.node))&&(i.pos=this.text.length+(up(e,i.node,i.offset)?t:0))}}function up(n,e,t){for(;;){if(!e||t<mt(e))return!1;if(e==n)return!0;t=Et(e)+1,e=e.parentNode}}function fp(n,e){let t;for(;!(n==e||!n);n=n.nextSibling){let i=Y.get(n);if(!i?.isWidget())return!1;i&&(t||(t=[])).push(i)}if(t)for(let i of t){let s=i.overrideDOMText;if(s?.length)return!1}return!0}class Ll{constructor(e,t){this.node=e,this.offset=t,this.pos=-1}}class dp{constructor(e,t,i,s){this.typeOver=s,this.bounds=null,this.text="",this.domChanged=t>-1;let{impreciseHead:r,impreciseAnchor:o}=e.docView,l=e.state.selection;if(e.state.readOnly&&t>-1)this.newSel=null;else if(t>-1&&(this.bounds=oc(e.docView.tile,t,i,0))){let a=r||o?[]:mp(e),h=new cp(a,e);h.readRange(this.bounds.startDOM,this.bounds.endDOM),this.text=h.text,this.newSel=gp(a,this.bounds.from)}else{let a=e.observer.selectionRange,h=r&&r.node==a.focusNode&&r.offset==a.focusOffset||!zr(e.contentDOM,a.focusNode)?l.main.head:e.docView.posFromDOM(a.focusNode,a.focusOffset),c=o&&o.node==a.anchorNode&&o.offset==a.anchorOffset||!zr(e.contentDOM,a.anchorNode)?l.main.anchor:e.docView.posFromDOM(a.anchorNode,a.anchorOffset),u=e.viewport;if((A.ios||A.chrome)&&l.main.empty&&h!=c&&(u.from>0||u.to<e.state.doc.length)){let f=Math.min(h,c),d=Math.max(h,c),p=u.from-f,m=u.to-d;(p==0||p==1||f==0)&&(m==0||m==-1||d==e.state.doc.length)&&(h=0,c=e.state.doc.length)}if(e.inputState.composing>-1&&l.ranges.length>1)this.newSel=l.replaceRange(w.range(c,h));else if(e.lineWrapping&&c==h&&!(l.main.empty&&l.main.head==h)&&e.inputState.lastTouchTime>Date.now()-100){let f=e.coordsAtPos(h,-1),d=0;f&&(d=e.inputState.lastTouchY<=f.bottom?-1:1),this.newSel=w.create([w.cursor(h,d)])}else this.newSel=w.single(c,h)}}}function oc(n,e,t,i){if(n.isComposite()){let s=-1,r=-1,o=-1,l=-1;for(let a=0,h=i,c=i;a<n.children.length;a++){let u=n.children[a],f=h+u.length;if(h<e&&f>t)return oc(u,e,t,h);if(f>=e&&s==-1&&(s=a,r=h),h>t&&u.dom.parentNode==n.dom){o=a,l=c;break}c=f,h=f+u.breakAfter}return{from:r,to:l<0?i+n.length:l,startDOM:(s?n.children[s-1].dom.nextSibling:null)||n.dom.firstChild,endDOM:o<n.children.length&&o>=0?n.children[o].dom:null}}else return n.isText()?{from:i,to:i+n.length,startDOM:n.dom,endDOM:n.dom.nextSibling}:null}function lc(n,e){let t,{newSel:i}=e,{state:s}=n,r=s.selection.main,o=n.inputState.lastKeyTime>Date.now()-100?n.inputState.lastKeyCode:-1;if(e.bounds){let{from:l,to:a}=e.bounds,h=r.from,c=null;(o===8||A.android&&e.text.length<a-l)&&(h=r.to,c="end");let u=s.doc.sliceString(l,a,Gt),f,d;!r.empty&&r.from>=l&&r.to<=a&&(e.typeOver||u!=e.text)&&u.slice(0,r.from-l)==e.text.slice(0,r.from-l)&&u.slice(r.to-l)==e.text.slice(f=e.text.length-(u.length-(r.to-l)))?t={from:r.from,to:r.to,insert:F.of(e.text.slice(r.from-l,f).split(Gt))}:(d=ac(u,e.text,h-l,c))&&(A.chrome&&o==13&&d.toB==d.from+2&&e.text.slice(d.from,d.toB)==Gt+Gt&&d.toB--,t={from:l+d.from,to:l+d.toA,insert:F.of(e.text.slice(d.from,d.toB).split(Gt))})}else i&&(!n.hasFocus&&s.facet(ft)||Js(i,r))&&(i=null);if(!t&&!i)return!1;if((A.mac||A.android)&&t&&t.from==t.to&&t.from==r.head-1&&/^\. ?$/.test(t.insert.toString())&&n.contentDOM.getAttribute("autocorrect")=="off"?(i&&t.insert.length==2&&(i=w.single(i.main.anchor-1,i.main.head-1)),t={from:t.from,to:t.to,insert:F.of([t.insert.toString().replace("."," ")])}):s.doc.lineAt(r.from).to<r.to&&n.docView.lineHasWidget(r.to)&&n.inputState.insertingTextAt>Date.now()-50?t={from:r.from,to:r.to,insert:s.toText(n.inputState.insertingText)}:A.chrome&&t&&t.from==t.to&&t.from==r.head&&t.insert.toString()==` 178 `&&n.lineWrapping&&(i&&(i=w.single(i.main.anchor-1,i.main.head-1)),t={from:r.from,to:r.to,insert:F.of([" "])}),t)return Do(n,t,i,o);if(i&&!Js(i,r)){let l=!1,a="select";return n.inputState.lastSelectionTime>Date.now()-50&&(n.inputState.lastSelectionOrigin=="select"&&(l=!0),a=n.inputState.lastSelectionOrigin,a=="select.pointer"&&(i=rc(s.facet(rs).map(h=>h(n)),i))),n.dispatch({selection:i,scrollIntoView:l,userEvent:a}),!0}else return!1}function Do(n,e,t,i=-1){if(A.ios&&n.inputState.flushIOSKey(e))return!0;let s=n.state.selection.main;if(A.android&&(e.to==s.to&&(e.from==s.from||e.from==s.from-1&&n.state.sliceDoc(e.from,s.from)==" ")&&e.insert.length==1&&e.insert.lines==2&&li(n.contentDOM,"Enter",13)||(e.from==s.from-1&&e.to==s.to&&e.insert.length==0||i==8&&e.insert.length<e.to-e.from&&e.to>s.head)&&li(n.contentDOM,"Backspace",8)||e.from==s.from&&e.to==s.to+1&&e.insert.length==0&&li(n.contentDOM,"Delete",46)))return!0;let r=e.insert.toString();n.inputState.composing>=0&&n.inputState.composing++;let o,l=()=>o||(o=pp(n,e,t));return n.state.facet(Gh).some(a=>a(n,e.from,e.to,r,l))||n.dispatch(l()),!0}function pp(n,e,t){let i,s=n.state,r=s.selection.main,o=-1;if(e.from==e.to&&e.from<r.from||e.from>r.to){let a=e.from<r.from?-1:1,h=a<0?r.from:r.to,c=Wi(s.facet(rs).map(u=>u(n)),h,a);e.from==c&&(o=c)}if(o>-1)i={changes:e,selection:w.cursor(e.from+e.insert.length,-1)};else if(e.from>=r.from&&e.to<=r.to&&e.to-e.from>=(r.to-r.from)/3&&(!t||t.main.empty&&t.main.from==e.from+e.insert.length)&&n.inputState.composing<0){let a=r.from<e.from?s.sliceDoc(r.from,e.from):"",h=r.to>e.to?s.sliceDoc(e.to,r.to):"";i=s.replaceSelection(n.state.toText(a+e.insert.sliceString(0,void 0,n.state.lineBreak)+h))}else{let a=s.changes(e),h=t&&t.main.to<=a.newLength?t.main:void 0;if(s.selection.ranges.length>1&&(n.inputState.composing>=0||n.inputState.compositionPendingChange)&&e.to<=r.to+10&&e.to>=r.to-10){let c=n.state.sliceDoc(e.from,e.to),u,f=t&&nc(n,t.main.head);if(f){let p=e.insert.length-(e.to-e.from);u={from:f.from,to:f.to-p}}else u=n.state.doc.lineAt(r.head);let d=r.to-e.to;i=s.changeByRange(p=>{if(p.from==r.from&&p.to==r.to)return{changes:a,range:h||p.map(a)};let m=p.to-d,g=m-c.length;if(n.state.sliceDoc(g,m)!=c||m>=u.from&&g<=u.to)return{range:p};let y=s.changes({from:g,to:m,insert:e.insert}),b=p.to-r.to;return{changes:y,range:h?w.range(Math.max(0,h.anchor+b),Math.max(0,h.head+b)):p.map(y)}})}else i={changes:a,selection:h&&s.selection.replaceRange(h)}}let l="input.type";return(n.composing||n.inputState.compositionPendingChange&&n.inputState.compositionEndedAt>Date.now()-50)&&(n.inputState.compositionPendingChange=!1,l+=".compose",n.inputState.compositionFirstChange&&(l+=".start",n.inputState.compositionFirstChange=!1)),s.update(i,{userEvent:l,scrollIntoView:!0})}function ac(n,e,t,i){let s=Math.min(n.length,e.length),r=0;for(;r<s&&n.charCodeAt(r)==e.charCodeAt(r);)r++;if(r==s&&n.length==e.length)return null;let o=n.length,l=e.length;for(;o>0&&l>0&&n.charCodeAt(o-1)==e.charCodeAt(l-1);)o--,l--;if(i=="end"){let a=Math.max(0,r-Math.min(o,l));t-=o+a-r}if(o<r&&n.length<e.length){let a=t<=r&&t>=o?r-t:0;r-=a,l=r+(l-o),o=r}else if(l<r){let a=t<=r&&t>=l?r-t:0;r-=a,o=r+(o-l),l=r}return{from:r,toA:o,toB:l}}function mp(n){let e=[];
vendor: 15,448 bytes, line 178
178if(n.root.activeElement!=n.contentDOM)return e;let{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}=n.observer.selectionRange;return t&&(e.push(new Ll(t,i)),(s!=t||r!=i)&&e.push(new Ll(s,r))),e}function gp(n,e){if(n.length==0)return null;let t=n[0].pos,i=n.length==2?n[1].pos:t;return t>-1&&i>-1?w.single(t+e,i+e):null}function Js(n,e){return e.head==n.main.head&&e.anchor==n.main.anchor}class yp{setSelectionOrigin(e){this.lastSelectionOrigin=e,this.lastSelectionTime=Date.now()}constructor(e){this.view=e,this.lastKeyCode=0,this.lastKeyTime=0,this.lastTouchTime=0,this.lastTouchX=0,this.lastTouchY=0,this.lastFocusTime=0,this.lastScrollTop=0,this.lastScrollLeft=0,this.lastWheelEvent=0,this.pendingIOSKey=void 0,this.tabFocusMode=-1,this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastContextMenu=0,this.scrollHandlers=[],this.handlers=Object.create(null),this.composing=-1,this.compositionFirstChange=null,this.compositionEndedAt=0,this.compositionPendingKey=!1,this.compositionPendingChange=!1,this.insertingText="",this.insertingTextAt=0,this.mouseSelection=null,this.draggedContent=null,this.handleEvent=this.handleEvent.bind(this),this.notifiedFocused=e.hasFocus,A.safari&&e.contentDOM.addEventListener("input",()=>null),A.gecko&&Lp(e.contentDOM.ownerDocument)}handleEvent(e){!Tp(this.view,e)||this.ignoreDuringComposition(e)||e.type=="keydown"&&this.keydown(e)||(this.view.updateState!=0?Promise.resolve().then(()=>this.runHandlers(e.type,e)):this.runHandlers(e.type,e))}runHandlers(e,t){let i=this.handlers[e];if(i){for(let s of i.observers)s(this.view,t);for(let s of i.handlers){if(t.defaultPrevented)break;if(s(this.view,t)){t.preventDefault();break}}}}ensureHandlers(e){let t=bp(e),i=this.handlers,s=this.view.contentDOM;for(let r in t)if(r!="scroll"){let o=!t[r].handlers.length,l=i[r];l&&o!=!l.handlers.length&&(s.removeEventListener(r,this.handleEvent),l=null),l||s.addEventListener(r,this.handleEvent,{passive:o})}for(let r in i)r!="scroll"&&!t[r]&&s.removeEventListener(r,this.handleEvent);this.handlers=t}keydown(e){if(this.lastKeyCode=e.keyCode,this.lastKeyTime=Date.now(),e.keyCode==9&&this.tabFocusMode>-1&&(!this.tabFocusMode||Date.now()<=this.tabFocusMode))return!0;if(this.tabFocusMode>0&&e.keyCode!=27&&cc.indexOf(e.keyCode)<0&&(this.tabFocusMode=-1),A.android&&A.chrome&&!e.synthetic&&(e.keyCode==13||e.keyCode==8))return this.view.observer.delayAndroidKey(e.key,e.keyCode),!0;let t;return A.ios&&!e.synthetic&&!e.altKey&&!e.metaKey&&!e.shiftKey&&((t=hc.find(i=>i.keyCode==e.keyCode))&&!e.ctrlKey||wp.indexOf(e.key)>-1&&e.ctrlKey)?(this.pendingIOSKey=t||e,setTimeout(()=>this.flushIOSKey(),250),!0):(e.keyCode!=229&&this.view.observer.forceFlush(),!1)}flushIOSKey(e){let t=this.pendingIOSKey;return!t||t.key=="Enter"&&e&&e.from<e.to&&/^\S+$/.test(e.insert.toString())?!1:(this.pendingIOSKey=void 0,li(this.view.contentDOM,t.key,t.keyCode,t instanceof KeyboardEvent?t:void 0))}ignoreDuringComposition(e){return!/^key/.test(e.type)||e.synthetic?!1:this.composing>0?!0:A.safari&&!A.ios&&this.compositionPendingKey&&Date.now()-this.compositionEndedAt<100?(this.compositionPendingKey=!1,!0):!1}startMouseSelection(e){this.mouseSelection&&this.mouseSelection.destroy(),this.mouseSelection=e}update(e){this.view.observer.update(e),this.mouseSelection&&this.mouseSelection.update(e),this.draggedContent&&e.docChanged&&(this.draggedContent=this.draggedContent.map(e.changes)),e.transactions.length&&(this.lastKeyCode=this.lastSelectionTime=0)}destroy(){this.mouseSelection&&this.mouseSelection.destroy()}}function Il(n,e){return(t,i)=>{try{return e.call(n,i,t)}catch(s){De(t.state,s)}}}function bp(n){let e=Object.create(null);function t(i){return e[i]||(e[i]={observers:[],handlers:[]})}for(let i of n){let s=i.spec,r=s&&s.plugin.domEventHandlers,o=s&&s.plugin.domEventObservers;if(r)for(let l in r){let a=r[l];a&&t(l).handlers.push(Il(i.value,a))}if(o)for(let l in o){let a=o[l];a&&t(l).observers.push(Il(i.value,a))}}for(let i in Ge)t(i).handlers.push(Ge[i]);for(let i in xe)t(i).observers.push(xe[i]);return e}const hc=[{key:"Backspace",keyCode:8,inputType:"deleteContentBackward"},{key:"Enter",keyCode:13,inputType:"insertParagraph"},{key:"Enter",keyCode:13,inputType:"insertLineBreak"},{key:"Delete",keyCode:46,inputType:"deleteContentForward"}],wp="dthko",cc=[16,17,18,20,91,92,224,225],ys=6;function bs(n){return Math.max(0,n)*.7+8}function Cp(n,e){return Math.max(Math.abs(n.clientX-e.clientX),Math.abs(n.clientY-e.clientY))}class xp{constructor(e,t,i,s){this.view=e,this.startEvent=t,this.style=i,this.mustSelect=s,this.scrollSpeed={x:0,y:0},this.scrolling=-1,this.lastEvent=t,this.scrollParents=Nh(e.contentDOM),this.atoms=e.state.facet(rs).map(o=>o(e));let r=e.contentDOM.ownerDocument;r.addEventListener("mousemove",this.move=this.move.bind(this)),r.addEventListener("mouseup",this.up=this.up.bind(this)),this.extend=t.shiftKey,this.multiple=e.state.facet(W.allowMultipleSelections)&&Sp(e,t),this.dragging=kp(e,t)&&dc(t)==1?null:!1}start(e){this.dragging===!1&&this.select(e)}move(e){if(e.buttons==0)return this.destroy();if(this.dragging||this.dragging==null&&Cp(this.startEvent,e)<10)return;this.select(this.lastEvent=e);let t=0,i=0,s=0,r=0,o=this.view.win.innerWidth,l=this.view.win.innerHeight;this.scrollParents.x&&({left:s,right:o}=this.scrollParents.x.getBoundingClientRect()),this.scrollParents.y&&({top:r,bottom:l}=this.scrollParents.y.getBoundingClientRect());let a=Oo(this.view);e.clientX-a.left<=s+ys?t=-bs(s-e.clientX):e.clientX+a.right>=o-ys&&(t=bs(e.clientX-o)),e.clientY-a.top<=r+ys?i=-bs(r-e.clientY):e.clientY+a.bottom>=l-ys&&(i=bs(e.clientY-l)),this.setScrollSpeed(t,i)}up(e){this.dragging==null&&this.select(this.lastEvent),this.dragging||e.preventDefault(),this.destroy()}destroy(){this.setScrollSpeed(0,0);let e=this.view.contentDOM.ownerDocument;e.removeEventListener("mousemove",this.move),e.removeEventListener("mouseup",this.up),this.view.inputState.mouseSelection=this.view.inputState.draggedContent=null}setScrollSpeed(e,t){this.scrollSpeed={x:e,y:t},e||t?this.scrolling<0&&(this.scrolling=setInterval(()=>this.scroll(),50)):this.scrolling>-1&&(clearInterval(this.scrolling),this.scrolling=-1)}scroll(){let{x:e,y:t}=this.scrollSpeed;e&&this.scrollParents.x&&(this.scrollParents.x.scrollLeft+=e,e=0),t&&this.scrollParents.y&&(this.scrollParents.y.scrollTop+=t,t=0),(e||t)&&this.view.win.scrollBy(e,t),this.dragging===!1&&this.select(this.lastEvent)}select(e){let{view:t}=this,i=rc(this.atoms,this.style.get(e,this.extend,this.multiple));(this.mustSelect||!i.eq(t.state.selection,this.dragging===!1))&&this.view.dispatch({selection:i,userEvent:"select.pointer"}),this.mustSelect=!1}update(e){e.transactions.some(t=>t.isUserEvent("input.type"))?this.destroy():this.style.update(e)&&setTimeout(()=>this.select(this.lastEvent),20)}}function Sp(n,e){let t=n.state.facet(Uh);return t.length?t[0](e):A.mac?e.metaKey:e.ctrlKey}function vp(n,e){let t=n.state.facet(qh);return t.length?t[0](e):A.mac?!e.altKey:!e.ctrlKey}function kp(n,e){let{main:t}=n.state.selection;if(t.empty)return!1;let i=ji(n.root);if(!i||i.rangeCount==0)return!0;let s=i.getRangeAt(0).getClientRects();for(let r=0;r<s.length;r++){let o=s[r];if(o.left<=e.clientX&&o.right>=e.clientX&&o.top<=e.clientY&&o.bottom>=e.clientY)return!0}return!1}function Tp(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target,i;t!=n.contentDOM;t=t.parentNode)if(!t||t.nodeType==11||(i=Y.get(t))&&i.isWidget()&&!i.isHidden&&i.widget.ignoreEvent(e))return!1;return!0}const Ge=Object.create(null),xe=Object.create(null),uc=A.ie&&A.ie_version<15||A.ios&&A.webkit_version<604;function Ap(n){let e=n.dom.parentNode;if(!e)return;let t=e.appendChild(document.createElement("textarea"));t.style.cssText="position: fixed; left: -10000px; top: 10px",t.focus(),setTimeout(()=>{n.focus(),t.remove(),fc(n,t.value)},50)}function On(n,e,t){for(let i of n.facet(e))t=i(t,n);return t}function fc(n,e){e=On(n.state,To,e);let{state:t}=n,i,s=1,r=t.toText(e),o=r.lines==t.selection.ranges.length;if(Gr!=null&&t.selection.ranges.every(a=>a.empty)&&Gr==r.toString()){let a=-1;i=t.changeByRange(h=>{let c=t.doc.lineAt(h.from);if(c.from==a)return{range:h};a=c.from;let u=t.toText((o?r.line(s++).text:e)+t.lineBreak);return{changes:{from:c.from,insert:u},range:w.cursor(h.from+u.length)}})}else o?i=t.changeByRange(a=>{let h=r.line(s++);return{changes:{from:a.from,to:a.to,insert:h.text},range:w.cursor(a.from+h.length)}}):i=t.replaceSelection(r);n.dispatch(i,{userEvent:"input.paste",scrollIntoView:!0})}xe.scroll=n=>{n.inputState.lastScrollTop=n.scrollDOM.scrollTop,n.inputState.lastScrollLeft=n.scrollDOM.scrollLeft};xe.wheel=xe.mousewheel=n=>{n.inputState.lastWheelEvent=Date.now()};Ge.keydown=(n,e)=>(n.inputState.setSelectionOrigin("select"),e.keyCode==27&&n.inputState.tabFocusMode!=0&&(n.inputState.tabFocusMode=Date.now()+2e3),!1);xe.touchstart=(n,e)=>{let t=n.inputState,i=e.targetTouches[0];t.lastTouchTime=Date.now(),i&&(t.lastTouchX=i.clientX,t.lastTouchY=i.clientY),t.setSelectionOrigin("select.pointer")};xe.touchmove=n=>{n.inputState.setSelectionOrigin("select.pointer")};Ge.mousedown=(n,e)=>{if(n.observer.flush(),n.inputState.lastTouchTime>Date.now()-2e3)return!1;let t=null;for(let i of n.state.facet(Qh))if(t=i(n,e),t)break;if(!t&&e.button==0&&(t=Ep(n,e)),t){let i=!n.hasFocus;n.inputState.startMouseSelection(new xp(n,e,t,i)),i&&n.observer.ignore(()=>{Bh(n.contentDOM);let r=n.root.activeElement;r&&!r.contains(n.contentDOM)&&r.blur()});let s=n.inputState.mouseSelection;if(s)return s.start(e),s.dragging===!1}else n.inputState.setSelectionOrigin("select.pointer");return!1};function Nl(n,e,t,i){if(i==1)return w.cursor(e,t);if(i==2)return sp(n.state,e,t);{let s=n.docView.lineAt(e,t),r=n.state.doc.lineAt(s?s.posAtEnd:e),o=s?s.posAtStart:r.from,l=s?s.posAtEnd:r.to;return l<n.state.doc.length&&l==r.to&&l++,w.range(o,l)}}const Mp=A.ie&&A.ie_version<=11;let Bl=null,_l=0,Pl=0;function dc(n){if(!Mp)return n.detail;let e=Bl,t=Pl;return Bl=n,Pl=Date.now(),_l=!e||t>Date.now()-400&&Math.abs(e.clientX-n.clientX)<2&&Math.abs(e.clientY-n.clientY)<2?(_l+1)%3:1}function Ep(n,e){let t=n.posAndSideAtCoords({x:e.clientX,y:e.clientY},!1),i=dc(e),s=n.state.selection;return{update(r){r.docChanged&&(t.pos=r.changes.mapPos(t.pos),s=s.map(r.changes))},get(r,o,l){let a=n.posAndSideAtCoords({x:r.clientX,y:r.clientY},!1),h,c=Nl(n,a.pos,a.assoc,i);if(t.pos!=a.pos&&!o){let u=Nl(n,t.pos,t.assoc,i),f=Math.min(u.from,c.from),d=Math.max(u.to,c.to);c=f<c.from?w.range(f,d,c.assoc):w.range(d,f,c.assoc)}return o?s.replaceRange(s.main.extend(c.from,c.to,c.assoc)):l&&i==1&&s.ranges.length>1&&(h=Op(s,a.pos))?h:l?s.addRange(c):w.create([c])}}}function Op(n,e){for(let t=0;t<n.ranges.length;t++){let{from:i,to:s}=n.ranges[t];if(i<=e&&s>=e)return w.create(n.ranges.slice(0,t).concat(n.ranges.slice(t+1)),n.mainIndex==t?0:n.mainIndex-(n.mainIndex>t?1:0))}return null}Ge.dragstart=(n,e)=>{let{selection:{main:t}}=n.state;if(e.target.draggable){let s=n.docView.tile.nearest(e.target);if(s&&s.isWidget()){let r=s.posAtStart,o=r+s.length;(r>=t.to||o<=t.from)&&(t=w.range(r,o))}}let{inputState:i}=n;return i.mouseSelection&&(i.mouseSelection.dragging=!0),i.draggedContent=t,e.dataTransfer&&(e.dataTransfer.setData("Text",On(n.state,Ao,n.state.sliceDoc(t.from,t.to))),e.dataTransfer.effectAllowed="copyMove"),!1};Ge.dragend=n=>(n.inputState.draggedContent=null,!1);function Fl(n,e,t,i){if(t=On(n.state,To,t),!t)return;let s=n.posAtCoords({x:e.clientX,y:e.clientY},!1),{draggedContent:r}=n.inputState,o=i&&r&&vp(n,e)?{from:r.from,to:r.to}:null,l={from:s,insert:t},a=n.state.changes(o?[o,l]:l);n.focus(),n.dispatch({changes:a,selection:{anchor:a.mapPos(s,-1),head:a.mapPos(s,1)},userEvent:o?"move.drop":"input.drop"}),n.inputState.draggedContent=null}Ge.drop=(n,e)=>{if(!e.dataTransfer)return!1;if(n.state.readOnly)return!0;let t=e.dataTransfer.files;if(t&&t.length){let i=Array(t.length),s=0,r=()=>{++s==t.length&&Fl(n,e,i.filter(o=>o!=null).join(n.state.lineBreak),!1)};for(let o=0;o<t.length;o++){let l=new FileReader;l.onerror=r,l.onload=()=>{/[\x00-\x08\x0e-\x1f]{2}/.test(l.result)||(i[o]=l.result),r()},l.readAsText(t[o])}return!0}else{let i=e.dataTransfer.getData("Text");if(i)return Fl(n,e,i,!0),!0}return!1};Ge.paste=(n,e)=>{if(n.state.readOnly)return!0;n.observer.flush();let t=uc?null:e.clipboardData;return t?(fc(n,t.getData("text/plain")||t.getData("text/uri-list")),!0):(Ap(n),!1)};function Dp(n,e){let t=n.dom.parentNode;if(!t)return;let i=t.appendChild(document.createElement("textarea"));i.style.cssText="position: fixed; left: -10000px; top: 10px",i.value=e,i.focus(),i.selectionEnd=e.length,i.selectionStart=0,setTimeout(()=>{i.remove(),n.focus()},50)}function Rp(n){let e=[],t=[],i=!1;for(let s of n.selection.ranges)s.empty||(e.push(n.sliceDoc(s.from,s.to)),t.push(s));if(!e.length){let s=-1;for(let{from:r}of n.selection.ranges){let o=n.doc.lineAt(r);o.number>s&&(e.push(o.text),t.push({from:o.from,to:Math.min(n.doc.length,o.to+1)})),s=o.number}i=!0}return{text:On(n,Ao,e.join(n.lineBreak)),ranges:t,linewise:i}}let Gr=null;Ge.copy=Ge.cut=(n,e)=>{if(!Pi(n.contentDOM,n.observer.selectionRange))return!1;let{text:t,ranges:i,linewise:s}=Rp(n.state);if(!t&&!s)return!1;Gr=s?t:null,e.type=="cut"&&!n.state.readOnly&&n.dispatch({changes:i,scrollIntoView:!0,userEvent:"delete.cut"});let r=uc?null:e.clipboardData;return r?(r.clearData(),r.setData("text/plain",t),!0):(Dp(n,t),!1)};const pc=gt.define();function mc(n,e){let t=[];for(let i of n.facet(Kh)){let s=i(n,e);s&&t.push(s)}return t.length?n.update({effects:t,annotations:pc.of(!0)}):null}function gc(n){setTimeout(()=>{let e=n.hasFocus;if(e!=n.inputState.notifiedFocused){let t=mc(n.state,e);t?n.dispatch(t):n.update([])}},10)}xe.focus=n=>{n.inputState.lastFocusTime=Date.now(),!n.scrollDOM.scrollTop&&(n.inputState.lastScrollTop||n.inputState.lastScrollLeft)&&(n.scrollDOM.scrollTop=n.inputState.lastScrollTop,n.scrollDOM.scrollLeft=n.inputState.lastScrollLeft),gc(n)};xe.blur=n=>{n.observer.clearSelectionRange(),gc(n)};xe.compositionstart=xe.compositionupdate=n=>{n.observer.editContext||(n.inputState.compositionFirstChange==null&&(n.inputState.compositionFirstChange=!0),n.inputState.composing<0&&(n.inputState.composing=0))};xe.compositionend=n=>{n.observer.editContext||(n.inputState.composing=-1,n.inputState.compositionEndedAt=Date.now(),n.inputState.compositionPendingKey=!0,n.inputState.compositionPendingChange=n.observer.pendingRecords().length>0,n.inputState.compositionFirstChange=null,A.chrome&&A.android?n.observer.flushSoon():n.inputState.compositionPendingChange?Promise.resolve().then(()=>n.observer.flush()):setTimeout(()=>{n.inputState.composing<0&&n.docView.hasComposition&&n.update([])},50))};xe.contextmenu=n=>{n.inputState.lastContextMenu=Date.now()};Ge.beforeinput=(n,e)=>{var t,i;if((e.inputType=="insertText"||e.inputType=="insertCompositionText")&&(n.inputState.insertingText=e.data,n.inputState.insertingTextAt=Date.now()),e.inputType=="insertReplacementText"&&n.observer.editContext){let r=(t=e.dataTransfer)===null||t===void 0?void 0:t.getData("text/plain"),o=e.getTargetRanges();if(r&&o.length){let l=o[0],a=n.posAtDOM(l.startContainer,l.startOffset),h=n.posAtDOM(l.endContainer,l.endOffset);return Do(n,{from:a,to:h,insert:n.state.toText(r)},null),!0}}let s;if(A.chrome&&A.android&&(s=hc.find(r=>r.inputType==e.inputType))&&(n.observer.delayAndroidKey(s.key,s.keyCode),s.key=="Backspace"||s.key=="Delete")){let r=((i=window.visualVie
vendor: 6,690 bytes, line 178
178wport)===null||i===void 0?void 0:i.height)||0;setTimeout(()=>{var o;(((o=window.visualViewport)===null||o===void 0?void 0:o.height)||0)>r+10&&n.hasFocus&&(n.contentDOM.blur(),n.focus())},100)}return A.ios&&e.inputType=="deleteContentForward"&&n.observer.flushSoon(),A.safari&&e.inputType=="insertText"&&n.inputState.composing>=0&&setTimeout(()=>xe.compositionend(n,e),20),!1};const Hl=new Set;function Lp(n){Hl.has(n)||(Hl.add(n),n.addEventListener("copy",()=>{}),n.addEventListener("cut",()=>{}))}const Wl=["pre-wrap","normal","pre-line","break-spaces"];let gi=!1;function zl(){gi=!1}class Ip{constructor(e){this.lineWrapping=e,this.doc=F.empty,this.heightSamples={},this.lineHeight=14,this.charWidth=7,this.textHeight=14,this.lineLength=30}heightForGap(e,t){let i=this.doc.lineAt(t).number-this.doc.lineAt(e).number+1;return this.lineWrapping&&(i+=Math.max(0,Math.ceil((t-e-i*this.lineLength*.5)/this.lineLength))),this.lineHeight*i}heightForLine(e){return this.lineWrapping?(1+Math.max(0,Math.ceil((e-this.lineLength)/Math.max(1,this.lineLength-5))))*this.lineHeight:this.lineHeight}setDoc(e){return this.doc=e,this}mustRefreshForWrapping(e){return Wl.indexOf(e)>-1!=this.lineWrapping}mustRefreshForHeights(e){let t=!1;for(let i=0;i<e.length;i++){let s=e[i];s<0?i++:this.heightSamples[Math.floor(s*10)]||(t=!0,this.heightSamples[Math.floor(s*10)]=!0)}return t}refresh(e,t,i,s,r,o){let l=Wl.indexOf(e)>-1,a=Math.abs(t-this.lineHeight)>.3||this.lineWrapping!=l||Math.abs(i-this.charWidth)>.1;if(this.lineWrapping=l,this.lineHeight=t,this.charWidth=i,this.textHeight=s,this.lineLength=r,a){this.heightSamples={};for(let h=0;h<o.length;h++){let c=o[h];c<0?h++:this.heightSamples[Math.floor(c*10)]=!0}}return a}}class Np{constructor(e,t){this.from=e,this.heights=t,this.index=0}get more(){return this.index<this.heights.length}}class qe{constructor(e,t,i,s,r){this.from=e,this.length=t,this.top=i,this.height=s,this._content=r}get type(){return typeof this._content=="number"?Ce.Text:Array.isArray(this._content)?this._content:this._content.type}get to(){return this.from+this.length}get bottom(){return this.top+this.height}get widget(){return this._content instanceof Vt?this._content.widget:null}get widgetLineBreaks(){return typeof this._content=="number"?this._content:0}join(e){let t=(Array.isArray(this._content)?this._content:[this]).concat(Array.isArray(e._content)?e._content:[e]);return new qe(this.from,this.length+e.length,this.top,this.height+e.height,t)}}var U=function(n){return n[n.ByPos=0]="ByPos",n[n.ByHeight=1]="ByHeight",n[n.ByPosNoHeight=2]="ByPosNoHeight",n}(U||(U={}));const Fs=.001;class me{constructor(e,t,i=2){this.length=e,this.height=t,this.flags=i}get outdated(){return(this.flags&2)>0}set outdated(e){this.flags=(e?2:0)|this.flags&-3}setHeight(e){this.height!=e&&(Math.abs(this.height-e)>Fs&&(gi=!0),this.height=e)}replace(e,t,i){return me.of(i)}decomposeLeft(e,t){t.push(this)}decomposeRight(e,t){t.push(this)}applyChanges(e,t,i,s){let r=this,o=i.doc;for(let l=s.length-1;l>=0;l--){let{fromA:a,toA:h,fromB:c,toB:u}=s[l],f=r.lineAt(a,U.ByPosNoHeight,i.setDoc(t),0,0),d=f.to>=h?f:r.lineAt(h,U.ByPosNoHeight,i,0,0);for(u+=d.to-h,h=d.to;l>0&&f.from<=s[l-1].toA;)a=s[l-1].fromA,c=s[l-1].fromB,l--,a<f.from&&(f=r.lineAt(a,U.ByPosNoHeight,i,0,0));c+=f.from-a,a=f.from;let p=Ro.build(i.setDoc(o),e,c,u);r=Zs(r,r.replace(a,h,p))}return r.updateHeight(i,0)}static empty(){return new Ee(0,0,0)}static of(e){if(e.length==1)return e[0];let t=0,i=e.length,s=0,r=0;for(;;)if(t==i)if(s>r*2){let l=e[t-1];l.break?e.splice(--t,1,l.left,null,l.right):e.splice(--t,1,l.left,l.right),i+=1+l.break,s-=l.size}else if(r>s*2){let l=e[i];l.break?e.splice(i,1,l.left,null,l.right):e.splice(i,1,l.left,l.right),i+=2+l.break,r-=l.size}else break;else if(s<r){let l=e[t++];l&&(s+=l.size)}else{let l=e[--i];l&&(r+=l.size)}let o=0;return e[t-1]==null?(o=1,t--):e[t]==null&&(o=1,i++),new _p(me.of(e.slice(0,t)),o,me.of(e.slice(i)))}}function Zs(n,e){return n==e?n:(n.constructor!=e.constructor&&(gi=!0),e)}me.prototype.size=1;const Bp=j.replace({});class yc extends me{constructor(e,t,i){super(e,t),this.deco=i,this.spaceAbove=0}mainBlock(e,t){return new qe(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.deco||0)}blockAt(e,t,i,s){return this.spaceAbove&&e<i+this.spaceAbove?new qe(s,0,i,this.spaceAbove,Bp):this.mainBlock(i,s)}lineAt(e,t,i,s,r){let o=this.mainBlock(s,r);return this.spaceAbove?this.blockAt(0,i,s,r).join(o):o}forEachLine(e,t,i,s,r,o){e<=r+this.length&&t>=r&&o(this.lineAt(0,U.ByPos,i,s,r))}setMeasuredHeight(e){let t=e.heights[e.index++];t<0?(this.spaceAbove=-t,t=e.heights[e.index++]):this.spaceAbove=0,this.setHeight(t)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more&&this.setMeasuredHeight(s),this.outdated=!1,this}toString(){return`block(${this.length})`}}class Ee extends yc{constructor(e,t,i){super(e,t,null),this.collapsed=0,this.widgetHeight=0,this.breaks=0,this.spaceAbove=i}mainBlock(e,t){return new qe(t,this.length,e+this.spaceAbove,this.height-this.spaceAbove,this.breaks)}replace(e,t,i){let s=i[0];return i.length==1&&(s instanceof Ee||s instanceof ae&&s.flags&4)&&Math.abs(this.length-s.length)<10?(s instanceof ae?s=new Ee(s.length,this.height,this.spaceAbove):s.height=this.height,this.outdated||(s.outdated=!1),s):me.of(i)}updateHeight(e,t=0,i=!1,s){return s&&s.from<=t&&s.more?this.setMeasuredHeight(s):(i||this.outdated)&&(this.spaceAbove=0,this.setHeight(Math.max(this.widgetHeight,e.heightForLine(this.length-this.collapsed))+this.breaks*e.lineHeight)),this.outdated=!1,this}toString(){return`line(${this.length}${this.collapsed?-this.collapsed:""}${this.widgetHeight?":"+this.widgetHeight:""})`}}class ae extends me{constructor(e){super(e,0)}heightMetrics(e,t){let i=e.doc.lineAt(t).number,s=e.doc.lineAt(t+this.length).number,r=s-i+1,o,l=0;if(e.lineWrapping){let a=Math.min(this.height,e.lineHeight*r);o=a/r,this.length>r+1&&(l=(this.height-a)/(this.length-r-1))}else o=this.height/r;return{firstLine:i,lastLine:s,perLine:o,perChar:l}}blockAt(e,t,i,s){let{firstLine:r,lastLine:o,perLine:l,perChar:a}=this.heightMetrics(t,s);if(t.lineWrapping){let h=s+(e<t.lineHeight?0:Math.round(Math.max(0,Math.min(1,(e-i)/this.height))*this.length)),c=t.doc.lineAt(h),u=l+c.length*a,f=Math.max(i,e-u/2);return new qe(c.from,c.length,f,u,0)}else{let h=Math.max(0,Math.min(o-r,Math.floor((e-i)/l))),{from:c,length:u}=t.doc.line(r+h);return new qe(c,u,i+l*h,l,0)}}lineAt(e,t,i,s,r){if(t==U.ByHeight)return this.blockAt(e,i,s,r);if(t==U.ByPosNoHeight){let{from:d,to:p}=i.doc.lineAt(e);return new qe(d,p-d,0,0,0)}let{firstLine:o,perLine:l,perChar:a}=this.heightMetrics(i,r),h=i.doc.lineAt(e),c=l+h.length*a,u=h.number-o,f=s+l*u+a*(h.from-r-u);
vendor: 7,369 bytes, line 178
178return new qe(h.from,h.length,Math.max(s,Math.min(f,s+this.height-c)),c,0)}forEachLine(e,t,i,s,r,o){e=Math.max(e,r),t=Math.min(t,r+this.length);let{firstLine:l,perLine:a,perChar:h}=this.heightMetrics(i,r);for(let c=e,u=s;c<=t;){let f=i.doc.lineAt(c);if(c==e){let p=f.number-l;u+=a*p+h*(e-r-p)}let d=a+h*f.length;o(new qe(f.from,f.length,u,d,0)),u+=d,c=f.to+1}}replace(e,t,i){let s=this.length-t;if(s>0){let r=i[i.length-1];r instanceof ae?i[i.length-1]=new ae(r.length+s):i.push(null,new ae(s-1))}if(e>0){let r=i[0];r instanceof ae?i[0]=new ae(e+r.length):i.unshift(new ae(e-1),null)}return me.of(i)}decomposeLeft(e,t){t.push(new ae(e-1),null)}decomposeRight(e,t){t.push(null,new ae(this.length-e-1))}updateHeight(e,t=0,i=!1,s){let r=t+this.length;if(s&&s.from<=t+this.length&&s.more){let o=[],l=Math.max(t,s.from),a=-1;for(s.from>t&&o.push(new ae(s.from-t-1).updateHeight(e,t));l<=r&&s.more;){let c=e.doc.lineAt(l).length;o.length&&o.push(null);let u=s.heights[s.index++],f=0;u<0&&(f=-u,u=s.heights[s.index++]),a==-1?a=u:Math.abs(u-a)>=Fs&&(a=-2);let d=new Ee(c,u,f);d.outdated=!1,o.push(d),l+=c+1}l<=r&&o.push(null,new ae(r-l).updateHeight(e,l));let h=me.of(o);return(a<0||Math.abs(h.height-this.height)>=Fs||Math.abs(a-this.heightMetrics(e,t).perLine)>=Fs)&&(gi=!0),Zs(this,h)}else(i||this.outdated)&&(this.setHeight(e.heightForGap(t,t+this.length)),this.outdated=!1);return this}toString(){return`gap(${this.length})`}}class _p extends me{constructor(e,t,i){super(e.length+t+i.length,e.height+i.height,t|(e.outdated||i.outdated?2:0)),this.left=e,this.right=i,this.size=e.size+i.size}get break(){return this.flags&1}blockAt(e,t,i,s){let r=i+this.left.height;return e<r?this.left.blockAt(e,t,i,s):this.right.blockAt(e,t,r,s+this.left.length+this.break)}lineAt(e,t,i,s,r){let o=s+this.left.height,l=r+this.left.length+this.break,a=t==U.ByHeight?e<o:e<l,h=a?this.left.lineAt(e,t,i,s,r):this.right.lineAt(e,t,i,o,l);if(this.break||(a?h.to<l:h.from>l))return h;let c=t==U.ByPosNoHeight?U.ByPosNoHeight:U.ByPos;return a?h.join(this.right.lineAt(l,c,i,o,l)):this.left.lineAt(l,c,i,s,r).join(h)}forEachLine(e,t,i,s,r,o){let l=s+this.left.height,a=r+this.left.length+this.break;if(this.break)e<a&&this.left.forEachLine(e,t,i,s,r,o),t>=a&&this.right.forEachLine(e,t,i,l,a,o);else{let h=this.lineAt(a,U.ByPos,i,s,r);e<h.from&&this.left.forEachLine(e,h.from-1,i,s,r,o),h.to>=e&&h.from<=t&&o(h),t>h.to&&this.right.forEachLine(h.to+1,t,i,l,a,o)}}replace(e,t,i){let s=this.left.length+this.break;if(t<s)return this.balanced(this.left.replace(e,t,i),this.right);if(e>this.left.length)return this.balanced(this.left,this.right.replace(e-s,t-s,i));let r=[];e>0&&this.decomposeLeft(e,r);let o=r.length;for(let l of i)r.push(l);if(e>0&&Vl(r,o-1),t<this.length){let l=r.length;this.decomposeRight(t,r),Vl(r,l)}return me.of(r)}decomposeLeft(e,t){let i=this.left.length;if(e<=i)return this.left.decomposeLeft(e,t);t.push(this.left),this.break&&(i++,e>=i&&t.push(null)),e>i&&this.right.decomposeLeft(e-i,t)}decomposeRight(e,t){let i=this.left.length,s=i+this.break;if(e>=s)return this.right.decomposeRight(e-s,t);e<i&&this.left.decomposeRight(e,t),this.break&&e<s&&t.push(null),t.push(this.right)}balanced(e,t){return e.size>2*t.size||t.size>2*e.size?me.of(this.break?[e,null,t]:[e,t]):(this.left=Zs(this.left,e),this.right=Zs(this.right,t),this.setHeight(e.height+t.height),this.outdated=e.outdated||t.outdated,this.size=e.size+t.size,this.length=e.length+this.break+t.length,this)}updateHeight(e,t=0,i=!1,s){let{left:r,right:o}=this,l=t+r.length+this.break,a=null;return s&&s.from<=t+r.length&&s.more?a=r=r.updateHeight(e,t,i,s):r.updateHeight(e,t,i),s&&s.from<=l+o.length&&s.more?a=o=o.updateHeight(e,l,i,s):o.updateHeight(e,l,i),a?this.balanced(r,o):(this.height=this.left.height+this.right.height,this.outdated=!1,this)}toString(){return this.left+(this.break?" ":"-")+this.right}}function Vl(n,e){let t,i;n[e]==null&&(t=n[e-1])instanceof ae&&(i=n[e+1])instanceof ae&&n.splice(e-1,3,new ae(t.length+1+i.length))}const Pp=5;class Ro{constructor(e,t){this.pos=e,this.oracle=t,this.nodes=[],this.lineStart=-1,this.lineEnd=-1,this.covering=null,this.writtenTo=e}get isCovered(){return this.covering&&this.nodes[this.nodes.length-1]==this.covering}span(e,t){if(this.lineStart>-1){let i=Math.min(t,this.lineEnd),s=this.nodes[this.nodes.length-1];s instanceof Ee?s.length+=i-this.pos:(i>this.pos||!this.isCovered)&&this.nodes.push(new Ee(i-this.pos,-1,0)),this.writtenTo=i,t>i&&(this.nodes.push(null),this.writtenTo++,this.lineStart=-1)}this.pos=t}point(e,t,i){if(e<t||i.heightRelevant){let s=i.widget?i.widget.estimatedHeight:0,r=i.widget?i.widget.lineBreaks:0;s<0&&(s=this.oracle.lineHeight);let o=t-e;i.block?this.addBlock(new yc(o,s,i)):(o||r||s>=Pp)&&this.addLineDeco(s,r,o)}else t>e&&this.span(e,t);this.lineEnd>-1&&this.lineEnd<this.pos&&(this.lineEnd=this.oracle.doc.lineAt(this.pos).to)}enterLine(){if(this.lineStart>-1)return;let{from:e,to:t}=this.oracle.doc.lineAt(this.pos);this.lineStart=e,this.lineEnd=t,this.writtenTo<e&&((this.writtenTo<e-1||this.nodes[this.nodes.length-1]==null)&&this.nodes.push(this.blankContent(this.writtenTo,e-1)),this.nodes.push(null)),this.pos>e&&this.nodes.push(new Ee(this.pos-e,-1,0)),this.writtenTo=this.pos}blankContent(e,t){let i=new ae(t-e);return this.oracle.doc.lineAt(e).to==t&&(i.flags|=4),i}ensureLine(){this.enterLine();let e=this.nodes.length?this.nodes[this.nodes.length-1]:null;if(e instanceof Ee)return e;let t=new Ee(0,-1,0);return this.nodes.push(t),t}addBlock(e){this.enterLine();let t=e.deco;t&&t.startSide>0&&!this.isCovered&&this.ensureLine(),this.nodes.push(e),this.writtenTo=this.pos=this.pos+e.length,t&&t.endSide>0&&(this.covering=e)}addLineDeco(e,t,i){let s=this.ensureLine();s.length+=i,s.collapsed+=i,s.widgetHeight=Math.max(s.widgetHeight,e),s.breaks+=t,this.writtenTo=this.pos=this.pos+i}finish(e){let t=this.nodes.length==0?null:this.nodes[this.nodes.length-1];this.lineStart>-1&&!(t instanceof Ee)&&!this.isCovered?this.nodes.push(new Ee(0,-1,0)):(this.writtenTo<this.pos||t==null)&&this.nodes.push(this.blankContent(this.writtenTo,this.pos));let i=e;for(let s of this.nodes)s instanceof Ee&&s.updateHeight(this.oracle,i),i+=s?s.length:1;return this.nodes}static build(e,t,i,s){let r=new Ro(i,e);return P.spans(t,i,s,r,0),r.finish(i)}}function Fp(n,e,t){let i=new Hp;return P.compare(n,e,t,i,0),i.changes}class Hp{constructor(){this.changes=[]}compareRange(){}comparePoint(e,t,i,s){(e<t||i&&i.heightRelevant||s&&s.heightRelevant)&&oi(e,t,this.changes,5)}}function Wp(n,e){let t=n.getBoundingClientRect(),i=n.ownerDocument,s=i.defaultView||window,r=Math.max(0,t.left),o=Math.min(s.innerWidth,t.right),l=Math.max(0,t.top),a=Math.min(s.innerHeight,t.bottom);for(let h=n.parentNode;h&&h!=i.body;)if(h.nodeType==1){let c=h,u=window.getComputedStyle(c);if((c.scrollHeight>c.clientHeight||c.scrollWidth>c.clientWidth)&&u.overflow!="visible"){let f=c.getBoundingClientRect();r=Math.max(r,f.left),o=Math.min(o,f.right),l=Math.max(l,f.top),a=Math.min(h==n.parentNode?s.innerHeight:a,f.bottom)}h=u.position=="absolute"||u.position=="fixed"?c.offsetParent:c.parentNode}else if(h.nodeType==11)h=h.host;else break;return{left:r-t.left,right:Math.max(r,o)-t.left,top:l-(t.top+e),bottom:Math.max(l,a)-(t.top+e)}}function zp(n){let e=n.getBoundingClientRect(),t=n.ownerDocument.defaultView||window;return e.left<t.innerWidth&&e.right>
vendor: 4,455 bytes, line 178
1780&&e.top<t.innerHeight&&e.bottom>0}function Vp(n,e){let t=n.getBoundingClientRect();return{left:0,right:t.right-t.left,top:e,bottom:t.bottom-(t.top+e)}}class jn{constructor(e,t,i,s){this.from=e,this.to=t,this.size=i,this.displaySize=s}static same(e,t){if(e.length!=t.length)return!1;for(let i=0;i<e.length;i++){let s=e[i],r=t[i];if(s.from!=r.from||s.to!=r.to||s.size!=r.size)return!1}return!0}draw(e,t){return j.replace({widget:new $p(this.displaySize*(t?e.scaleY:e.scaleX),t)}).range(this.from,this.to)}}class $p extends is{constructor(e,t){super(),this.size=e,this.vertical=t}eq(e){return e.size==this.size&&e.vertical==this.vertical}toDOM(){let e=document.createElement("div");return this.vertical?e.style.height=this.size+"px":(e.style.width=this.size+"px",e.style.height="2px",e.style.display="inline-block"),e}get estimatedHeight(){return this.vertical?this.size:-1}}class $l{constructor(e,t){this.view=e,this.state=t,this.pixelViewport={left:0,right:window.innerWidth,top:0,bottom:0},this.inView=!0,this.paddingTop=0,this.paddingBottom=0,this.contentDOMWidth=0,this.contentDOMHeight=0,this.editorHeight=0,this.editorWidth=0,this.scaleX=1,this.scaleY=1,this.scrollOffset=0,this.scrolledToBottom=!1,this.scrollAnchorPos=0,this.scrollAnchorHeight=-1,this.scaler=Ul,this.scrollTarget=null,this.printing=!1,this.mustMeasureContent=!0,this.defaultTextDirection=G.LTR,this.visibleRanges=[],this.mustEnforceCursorAssoc=!1;let i=t.facet(Mo).some(s=>typeof s!="function"&&s.class=="cm-lineWrapping");this.heightOracle=new Ip(i),this.stateDeco=ql(t),this.heightMap=me.empty().applyChanges(this.stateDeco,F.empty,this.heightOracle.setDoc(t.doc),[new _e(0,0,0,t.doc.length)]);for(let s=0;s<2&&(this.viewport=this.getViewport(0,null),!!this.updateForViewport());s++);this.updateViewportLines(),this.lineGaps=this.ensureLineGaps([]),this.lineGapDeco=j.set(this.lineGaps.map(s=>s.draw(this,!1))),this.scrollParent=e.scrollDOM,this.computeVisibleRanges()}updateForViewport(){let e=[this.viewport],{main:t}=this.state.selection;for(let i=0;i<=1;i++){let s=i?t.head:t.anchor;if(!e.some(({from:r,to:o})=>s>=r&&s<=o)){let{from:r,to:o}=this.lineBlockAt(s);e.push(new ws(r,o))}}return this.viewports=e.sort((i,s)=>i.from-s.from),this.updateScaler()}updateScaler(){let e=this.scaler;return this.scaler=this.heightMap.height<=7e6?Ul:new Lo(this.heightOracle,this.heightMap,this.viewports),e.eq(this.scaler)?0:2}updateViewportLines(){this.viewportLines=[],this.heightMap.forEachLine(this.viewport.from,this.viewport.to,this.heightOracle.setDoc(this.state.doc),0,0,e=>{this.viewportLines.push(Ri(e,this.scaler))})}update(e,t=null){this.state=e.state;let i=this.stateDeco;this.stateDeco=ql(this.state);let s=e.changedRanges,r=_e.extendWithRanges(s,Fp(i,this.stateDeco,e?e.changes:ie.empty(this.state.doc.length))),o=this.heightMap.height,l=this.scrolledToBottom?null:this.scrollAnchorAt(this.scrollOffset);zl(),this.heightMap=this.heightMap.applyChanges(this.stateDeco,e.startState.doc,this.heightOracle.setDoc(this.state.doc),r),(this.heightMap.height!=o||gi)&&(e.flags|=2),l?(this.scrollAnchorPos=e.changes.mapPos(l.from,-1),this.scrollAnchorHeight=l.top):(this.scrollAnchorPos=-1,this.scrollAnchorHeight=o);let a=r.length?this.mapViewport(this.viewport,e.changes):this.viewport;(t&&(t.range.head<a.from||t.range.head>a.to)||!this.viewportIsAppropriate(a))&&(a=this.getViewport(0,t));let h=a.from!=this.viewport.from||a.to!=this.viewport.to;this.viewport=a,e.flags|=this.updateForViewport(),(h||!e.changes.empty||e.flags&2)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(this.mapLineGaps(this.lineGaps,e.changes))),e.flags|=this.computeVisibleRanges(e.changes),t&&(this.scrollTarget=t),!this.mustEnforceCursorAssoc&&(e.selectionSet||e.focusChanged)&&e.view.lineWrapping&&e.state.selection.main.empty&&e.state.selection.main.assoc&&!e.state.facet(Nd)&&(this.mustEnforceCursorAssoc=!0)}measure(){let{view:e}=this,t=e.contentDOM,i=window.getComputedStyle(t),s=this.heightOracle,r=i.whiteSpace;this.defaultTextDirection=i.direction=="rtl"?G.RTL:G.LTR;let o=this.heightOracle.mustRefreshForWrapping(r)||this.mustMeasureContent==="refresh",l=t.getBoundingClientRect(),a=o||this.mustMeasureContent||this.contentDOMHeight!=l.height;this.contentDOMHeight=l.height,this.mustMeasureContent=!1;let h=0,c=0;if(l.width&&l.height){let{scaleX:x,scaleY:T}=Ih(t,l);(x>.005&&Math.abs(this.scaleX-x)>.005||T>
vendor: 5,156 bytes, line 178
178.005&&Math.abs(this.scaleY-T)>.005)&&(this.scaleX=x,this.scaleY=T,h|=16,o=a=!0)}let u=(parseInt(i.paddingTop)||0)*this.scaleY,f=(parseInt(i.paddingBottom)||0)*this.scaleY;(this.paddingTop!=u||this.paddingBottom!=f)&&(this.paddingTop=u,this.paddingBottom=f,h|=18),this.editorWidth!=e.scrollDOM.clientWidth&&(s.lineWrapping&&(a=!0),this.editorWidth=e.scrollDOM.clientWidth,h|=16);let d=Nh(this.view.contentDOM,!1).y;d!=this.scrollParent&&(this.scrollParent=d,this.scrollAnchorHeight=-1,this.scrollOffset=0);let p=this.getScrollOffset();this.scrollOffset!=p&&(this.scrollAnchorHeight=-1,this.scrollOffset=p),this.scrolledToBottom=_h(this.scrollParent||e.win);let m=(this.printing?Vp:Wp)(t,this.paddingTop),g=m.top-this.pixelViewport.top,y=m.bottom-this.pixelViewport.bottom;this.pixelViewport=m;let b=this.pixelViewport.bottom>this.pixelViewport.top&&this.pixelViewport.right>this.pixelViewport.left;if(b!=this.inView&&(this.inView=b,b&&(a=!0)),!this.inView&&!this.scrollTarget&&!zp(e.dom))return 0;let C=l.width;if((this.contentDOMWidth!=C||this.editorHeight!=e.scrollDOM.clientHeight)&&(this.contentDOMWidth=l.width,this.editorHeight=e.scrollDOM.clientHeight,h|=16),a){let x=e.docView.measureVisibleLineHeights(this.viewport);if(s.mustRefreshForHeights(x)&&(o=!0),o||s.lineWrapping&&Math.abs(C-this.contentDOMWidth)>s.charWidth){let{lineHeight:T,charWidth:v,textHeight:I}=e.docView.measureTextSize();o=T>0&&s.refresh(r,T,v,I,Math.max(5,C/v),x),o&&(e.docView.minWidth=0,h|=16)}g>0&&y>0?c=Math.max(g,y):g<0&&y<0&&(c=Math.min(g,y)),zl();for(let T of this.viewports){let v=T.from==this.viewport.from?x:e.docView.measureVisibleLineHeights(T);this.heightMap=(o?me.empty().applyChanges(this.stateDeco,F.empty,this.heightOracle,[new _e(0,0,0,e.state.doc.length)]):this.heightMap).updateHeight(s,0,o,new Np(T.from,v))}gi&&(h|=2)}let k=!this.viewportIsAppropriate(this.viewport,c)||this.scrollTarget&&(this.scrollTarget.range.head<this.viewport.from||this.scrollTarget.range.head>this.viewport.to);return k&&(h&2&&(h|=this.updateScaler()),this.viewport=this.getViewport(c,this.scrollTarget),h|=this.updateForViewport()),(h&2||k)&&this.updateViewportLines(),(this.lineGaps.length||this.viewport.to-this.viewport.from>4e3)&&this.updateLineGaps(this.ensureLineGaps(o?[]:this.lineGaps,e)),h|=this.computeVisibleRanges(),this.mustEnforceCursorAssoc&&(this.mustEnforceCursorAssoc=!1,e.docView.enforceCursorAssoc()),h}get visibleTop(){return this.scaler.fromDOM(this.pixelViewport.top)}get visibleBottom(){return this.scaler.fromDOM(this.pixelViewport.bottom)}getViewport(e,t){let i=.5-Math.max(-.5,Math.min(.5,e/1e3/2)),s=this.heightMap,r=this.heightOracle,{visibleTop:o,visibleBottom:l}=this,a=new ws(s.lineAt(o-i*1e3,U.ByHeight,r,0,0).from,s.lineAt(l+(1-i)*1e3,U.ByHeight,r,0,0).to);if(t){let{head:h}=t.range;if(h<a.from||h>a.to){let c=Math.min(this.editorHeight,this.pixelViewport.bottom-this.pixelViewport.top),u=s.lineAt(h,U.ByPos,r,0,0),f;t.y=="center"?f=(u.top+u.bottom)/2-c/2:t.y=="start"||t.y=="nearest"&&h<a.from?f=u.top:f=u.bottom-c,a=new ws(s.lineAt(f-1e3/2,U.ByHeight,r,0,0).from,s.lineAt(f+c+1e3/2,U.ByHeight,r,0,0).to)}}return a}mapViewport(e,t){let i=t.mapPos(e.from,-1),s=t.mapPos(e.to,1);return new ws(this.heightMap.lineAt(i,U.ByPos,this.heightOracle,0,0).from,this.heightMap.lineAt(s,U.ByPos,this.heightOracle,0,0).to)}viewportIsAppropriate({from:e,to:t},i=0){if(!this.inView)return!0;let{top:s}=this.heightMap.lineAt(e,U.ByPos,this.heightOracle,0,0),{bottom:r}=this.heightMap.lineAt(t,U.ByPos,this.heightOracle,0,0),{visibleTop:o,visibleBottom:l}=this;return(e==0||s<=o-Math.max(10,Math.min(-i,250)))&&(t==this.state.doc.length||r>=l+Math.max(10,Math.min(i,250)))&&s>o-2*1e3&&r<l+2*1e3}mapLineGaps(e,t){if(!e.length||t.empty)return e;let i=[];for(let s of e)t.touchesRange(s.from,s.to)||i.push(new jn(t.mapPos(s.from),t.mapPos(s.to),s.size,s.displaySize));return i}ensureLineGaps(e,t){let i=this.heightOracle.lineWrapping,s=i?1e4:2e3,r=s>>1,o=s<<1;if(this.defaultTextDirection!=G.LTR&&!i)return[];let l=[],a=(c,u,f,d)=>{if(u-c<r)return;let p=this.state.selection.main,m=[p.from];p.empty||m.push(p.to);for(let y of m)if(y>c&&y<u){a(c,y-10,f,d),a(y+10,u,f,d);return}let g=qp(e,y=>y.from>=f.from&&y.to<=f.to&&Math.abs(y.from-c)<r&&Math.abs(y.to-u)<r&&!m.some(b=>y.from<b&&y.to>b));if(!g){if(u<f.to&&t&&i&&t.visibleRanges.some(C=>C.from<=u&&C.to>=u)){let C=t.moveToLineBoundary(w.cursor(u),!1,!0).head;C>c&&(u=C)}let y=this.gapSize(f,c,u,d),b=i||y<2e6?y:2e6;g=new jn(c,u,y,b)}l.push(g)},h=c=>{if(c.length<o||c.type!=Ce.Text)return;let u=Up(c.from,c.to,this.stateDeco);if(u.total<o)return;let f=this.scrollTarget?this.scrollTarget.range.head:null,d,p;if(i){let m=s/this.heightOracle.lineLength*this.heightOracle.lineHeight,g,y;if(f!=null){let b=xs(u,f),C=((this.visibleBottom-this.visibleTop)/2+m)/c.height;g=b-C,y=b+C}else g=(this.visibleTop-c.top-m)/c.height,y=(this.visibleBottom-c.top+m)/c.height;d=Cs(u,g),p=Cs(u,y)}else{let m=u.total*this.heightOracle.charWidth,g=s*this.heightOracle.charWidth,y=0;if(m>2e6)for(let T of e)T.from>=c.from&&T.from<c.to&&T.size!=T.displaySize&&T.from*this.heightOracle.charWidth+y<this.pixelViewport.left&&(y=T.size-T.dis
vendor: 4,172 bytes, line 178
178playSize);let b=this.pixelViewport.left+y,C=this.pixelViewport.right+y,k,x;if(f!=null){let T=xs(u,f),v=((C-b)/2+g)/m;k=T-v,x=T+v}else k=(b-g)/m,x=(C+g)/m;d=Cs(u,k),p=Cs(u,x)}d>c.from&&a(c.from,d,c,u),p<c.to&&a(p,c.to,c,u)};for(let c of this.viewportLines)Array.isArray(c.type)?c.type.forEach(h):h(c);return l}gapSize(e,t,i,s){let r=xs(s,i)-xs(s,t);return this.heightOracle.lineWrapping?e.height*r:s.total*this.heightOracle.charWidth*r}updateLineGaps(e){jn.same(e,this.lineGaps)||(this.lineGaps=e,this.lineGapDeco=j.set(e.map(t=>t.draw(this,this.heightOracle.lineWrapping))))}computeVisibleRanges(e){let t=this.stateDeco;this.lineGaps.length&&(t=t.concat(this.lineGapDeco));let i=[];P.spans(t,this.viewport.from,this.viewport.to,{span(r,o){i.push({from:r,to:o})},point(){}},20);let s=0;if(i.length!=this.visibleRanges.length)s=12;else for(let r=0;r<i.length&&!(s&8);r++){let o=this.visibleRanges[r],l=i[r];(o.from!=l.from||o.to!=l.to)&&(s|=4,e&&e.mapPos(o.from,-1)==l.from&&e.mapPos(o.to,1)==l.to||(s|=8))}return this.visibleRanges=i,s}lineBlockAt(e){return e>=this.viewport.from&&e<=this.viewport.to&&this.viewportLines.find(t=>t.from<=e&&t.to>=e)||Ri(this.heightMap.lineAt(e,U.ByPos,this.heightOracle,0,0),this.scaler)}lineBlockAtHeight(e){return e>=this.viewportLines[0].top&&e<=this.viewportLines[this.viewportLines.length-1].bottom&&this.viewportLines.find(t=>t.top<=e&&t.bottom>=e)||Ri(this.heightMap.lineAt(this.scaler.fromDOM(e),U.ByHeight,this.heightOracle,0,0),this.scaler)}getScrollOffset(){return(this.scrollParent==this.view.scrollDOM?this.scrollParent.scrollTop:(this.scrollParent?this.scrollParent.getBoundingClientRect().top:0)-this.view.contentDOM.getBoundingClientRect().top)*this.scaleY}scrollAnchorAt(e){let t=this.lineBlockAtHeight(e+8);return t.from>=this.viewport.from||this.viewportLines[0].top-e>200?t:this.viewportLines[0]}elementAtHeight(e){return Ri(this.heightMap.blockAt(this.scaler.fromDOM(e),this.heightOracle,0,0),this.scaler)}get docHeight(){return this.scaler.toDOM(this.heightMap.height)}get contentHeight(){return this.docHeight+this.paddingTop+this.paddingBottom}}class ws{constructor(e,t){this.from=e,this.to=t}}function Up(n,e,t){let i=[],s=n,r=0;return P.spans(t,n,e,{span(){},point(o,l){o>s&&(i.push({from:s,to:o}),r+=o-s),s=l}},20),s<e&&(i.push({from:s,to:e}),r+=e-s),{total:r,ranges:i}}function Cs({total:n,ranges:e},t){if(t<=0)return e[0].from;if(t>=1)return e[e.length-1].to;let i=Math.floor(n*t);for(let s=0;;s++){let{from:r,to:o}=e[s],l=o-r;if(i<=l)return r+i;i-=l}}function xs(n,e){let t=0;for(let{from:i,to:s}of n.ranges){if(e<=s){t+=e-i;break}t+=s-i}return t/n.total}function qp(n,e){for(let t of n)if(e(t))return t}const Ul={toDOM(n){return n},fromDOM(n){return n},scale:1,eq(n){return n==this}};function ql(n){let e=n.facet(An).filter(i=>typeof i!="function"),t=n.facet(Eo).filter(i=>typeof i!="function");return t.length&&e.push(P.join(t)),e}class Lo{constructor(e,t,i){let s=0,r=0,o=0;this.viewports=i.map(({from:l,to:a})=>{let h=t.lineAt(l,U.ByPos,e,0,0).top,c=t.lineAt(a,U.ByPos,e,0,0).bottom;return s+=c-h,{from:l,to:a,top:h,bottom:c,domTop:0,domBottom:0}}),this.scale=(7e6-s)/(t.height-s);for(let l of this.viewports)l.domTop=o+(l.top-r)*this.scale,o=l.domBottom=l.domTop+(l.bottom-l.top),r=l.bottom}toDOM(e){for(let t=0,i=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.top)return s+(e-i)*this.scale;if(e<=r.bottom)return r.domTop+(e-r.top);i=r.bottom,s=r.domBottom}}fromDOM(e){for(let t=0,i=0,s=0;;t++){let r=t<this.viewports.length?this.viewports[t]:null;if(!r||e<r.domTop)return i+(e-s)/this.scale;if(e<=r.domBottom)return r.top+(e-r.domTop);i=r.bottom,s=r.domBottom}}eq(e){return e instanceof Lo?this.scale==e.scale&&this.viewports.length==e.viewports.length&&this.viewports.every((t,i)=>t.from==e.viewports[i].from&&t.to==e.viewports[i].to):!1}}function Ri(n,e){if(e.scale==1)return n;let t=e.toDOM(n.top),i=e.toDOM(n.bottom);return new qe(n.from,n.length,t,i-t,Array.isArray(n._content)?n._content.map(s=>Ri(s,e)):n._content)}const Ss=E.define({combine:n=>n.join(" ")}),Kr=E.define({combine:n=>n.indexOf(!0)>-1}),Xr=At.newName(),bc=At.newName(),wc=At.newName(),Cc={"&light":"."+b
vendor: 12,124 bytes, line 178
178c,"&dark":"."+wc};function Yr(n,e,t){return new At(e,{finish(i){return/&/.test(i)?i.replace(/&\w*/,s=>{if(s=="&")return n;if(!t||!t[s])throw new RangeError(`Unsupported selector: ${s}`);return t[s]}):n+" "+i}})}const Qp=Yr("."+Xr,{"&":{position:"relative !important",boxSizing:"border-box","&.cm-focused":{outline:"1px dotted #212121"},display:"flex !important",flexDirection:"column"},".cm-scroller":{display:"flex !important",alignItems:"flex-start !important",fontFamily:"monospace",lineHeight:1.4,height:"100%",overflowX:"auto",position:"relative",zIndex:0,overflowAnchor:"none"},".cm-content":{margin:0,flexGrow:2,flexShrink:0,display:"block",whiteSpace:"pre",wordWrap:"normal",boxSizing:"border-box",minHeight:"100%",padding:"4px 0",outline:"none","&[contenteditable=true]":{WebkitUserModify:"read-write-plaintext-only"}},".cm-lineWrapping":{whiteSpace_fallback:"pre-wrap",whiteSpace:"break-spaces",wordBreak:"break-word",overflowWrap:"anywhere",flexShrink:1},"&light .cm-content":{caretColor:"black"},"&dark .cm-content":{caretColor:"white"},".cm-line":{display:"block",padding:"0 2px 0 6px"},".cm-layer":{position:"absolute",left:0,top:0,contain:"size style","& > *":{position:"absolute"}},"&light .cm-selectionBackground":{background:"#d9d9d9"},"&dark .cm-selectionBackground":{background:"#222"},"&light.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#d7d4f0"},"&dark.cm-focused > .cm-scroller > .cm-selectionLayer .cm-selectionBackground":{background:"#233"},".cm-cursorLayer":{pointerEvents:"none"},"&.cm-focused > .cm-scroller > .cm-cursorLayer":{animation:"steps(1) cm-blink 1.2s infinite"},"@keyframes cm-blink":{"0%":{},"50%":{opacity:0},"100%":{}},"@keyframes cm-blink2":{"0%":{},"50%":{opacity:0},"100%":{}},".cm-cursor, .cm-dropCursor":{borderLeft:"1.2px solid black",marginLeft:"-0.6px",pointerEvents:"none"},".cm-cursor":{display:"none"},"&dark .cm-cursor":{borderLeftColor:"#ddd"},".cm-selectionHandle":{backgroundColor:"currentColor",width:"1.5px"},".cm-selectionHandle-start::before, .cm-selectionHandle-end::before":{content:'""',backgroundColor:"inherit",borderRadius:"50%",width:"8px",height:"8px",position:"absolute",left:"-3.25px"},".cm-selectionHandle-start::before":{top:"-8px"},".cm-selectionHandle-end::before":{bottom:"-8px"},".cm-dropCursor":{position:"absolute"},"&.cm-focused > .cm-scroller > .cm-cursorLayer .cm-cursor":{display:"block"},".cm-iso":{unicodeBidi:"isolate"},".cm-announced":{position:"fixed",top:"-10000px"},"@media print":{".cm-announced":{display:"none"}},"&light .cm-activeLine":{backgroundColor:"#cceeff44"},"&dark .cm-activeLine":{backgroundColor:"#99eeff33"},"&light .cm-specialChar":{color:"red"},"&dark .cm-specialChar":{color:"#f78"},".cm-gutters":{flexShrink:0,display:"flex",height:"100%",boxSizing:"border-box",zIndex:200},".cm-gutters-before":{insetInlineStart:0},".cm-gutters-after":{insetInlineEnd:0},"&light .cm-gutters":{backgroundColor:"#f5f5f5",color:"#6c6c6c",border:"0px solid #ddd","&.cm-gutters-before":{borderRightWidth:"1px"},"&.cm-gutters-after":{borderLeftWidth:"1px"}},"&dark .cm-gutters":{backgroundColor:"#333338",color:"#ccc"},".cm-gutter":{display:"flex !important",flexDirection:"column",flexShrink:0,boxSizing:"border-box",minHeight:"100%",overflow:"hidden"},".cm-gutterElement":{boxSizing:"border-box"},".cm-lineNumbers .cm-gutterElement":{padding:"0 3px 0 5px",minWidth:"20px",textAlign:"right",whiteSpace:"nowrap"},"&light .cm-activeLineGutter":{backgroundColor:"#e2f2ff"},"&dark .cm-activeLineGutter":{backgroundColor:"#222227"},".cm-panels":{boxSizing:"border-box",position:"sticky",left:0,right:0,zIndex:300},"&light .cm-panels":{backgroundColor:"#f5f5f5",color:"black"},"&light .cm-panels-top":{borderBottom:"1px solid #ddd"},"&light .cm-panels-bottom":{borderTop:"1px solid #ddd"},"&dark .cm-panels":{backgroundColor:"#333338",color:"white"},".cm-dialog":{padding:"2px 19px 4px 6px",position:"relative","& label":{fontSize:"80%"}},".cm-dialog-close":{position:"absolute",top:"3px",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",fontSize:"14px",padding:"0"},".cm-tab":{display:"inline-block",overflow:"hidden",verticalAlign:"bottom"},".cm-widgetBuffer":{verticalAlign:"text-top",height:"1em",width:0,display:"inline"},".cm-placeholder":{color:"#888",display:"inline-block",verticalAlign:"top",userSelect:"none"},".cm-highlightSpace":{backgroundImage:"radial-gradient(circle at 50% 55%, #aaa 20%, transparent 5%)",backgroundPosition:"center"},".cm-highlightTab":{backgroundImage:`url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="200" height="20"><path stroke="%23888" stroke-width="1" fill="none" d="M1 10H196L190 5M190 15L196 10M197 4L197 16"/></svg>')`,backgroundSize:"auto 100%",backgroundPosition:"right 90%",backgroundRepeat:"no-repeat"},".cm-trailingSpace":{backgroundColor:"#ff332255"},".cm-button":{verticalAlign:"middle",color:"inherit",fontSize:"70%",padding:".2em 1em",borderRadius:"1px"},"&light .cm-button":{backgroundImage:"linear-gradient(#eff1f5, #d9d9df)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#b4b4b4, #d0d3d6)"}},"&dark .cm-button":{backgroundImage:"linear-gradient(#393939, #111)",border:"1px solid #888","&:active":{backgroundImage:"linear-gradient(#111, #333)"}},".cm-textfield":{verticalAlign:"middle",color:"inherit",fontSize:"70%",border:"1px solid silver",padding:".2em .5em"},"&light .cm-textfield":{backgroundColor:"white"},"&dark .cm-textfield":{border:"1px solid #555",backgroundColor:"inherit"}},Cc),jp={childList:!0,characterData:!0,subtree:!0,attributes:!0,characterDataOldValue:!0},Gn=A.ie&&A.ie_version<=11;class Gp{constructor(e){this.view=e,this.active=!1,this.editContext=null,this.selectionRange=new Sd,this.selectionChanged=!1,this.delayedFlush=-1,this.resizeTimeout=-1,this.queue=[],this.delayedAndroidKey=null,this.flushingAndroidKey=-1,this.lastChange=0,this.scrollTargets=[],this.intersection=null,this.resizeScroll=null,this.intersecting=!1,this.gapIntersection=null,this.gaps=[],this.printQuery=null,this.parentCheck=-1,this.dom=e.contentDOM,this.observer=new MutationObserver(t=>{for(let i of t)this.queue.push(i);(A.ie&&A.ie_version<=11||A.ios&&e.composing)&&t.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),window.EditContext&&A.android&&e.constructor.EDIT_CONTEXT!==!1&&!(A.chrome&&A.chrome_version<126)&&(this.editContext=new Xp(e),e.state.facet(ft)&&(e.contentDOM.editContext=this.editContext.editContext)),Gn&&(this.onCharData=t=>{this.queue.push({target:t.target,type:"characterData",oldValue:t.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this),this.onResize=this.onResize.bind(this),this.onPrint=this.onPrint.bind(this),this.onScroll=this.onScroll.bind(this),window.matchMedia&&(this.printQuery=window.matchMedia("print")),typeof ResizeObserver=="function"&&(this.resizeScroll=new ResizeObserver(()=>{var t;((t=this.view.docView)===null||t===void 0?void 0:t.lastUpdate)<Date.now()-75&&this.onResize()}),this.resizeScroll.observe(e.scrollDOM)),this.addWindowListeners(this.win=e.win),this.start(),typeof IntersectionObserver=="function"&&(this.intersection=new IntersectionObserver(t=>{this.parentCheck<0&&(this.parentCheck=setTimeout(this.listenForScroll.bind(this),1e3)),t.length>0&&t[t.length-1].intersectionRatio>0!=this.intersecting&&(this.intersecting=!this.intersecting,this.intersecting!=this.view.inView&&this.onScrollChanged(document.createEvent("Event")))},{threshold:[0,.001]}),this.intersection.observe(this.dom),this.gapIntersection=new IntersectionObserver(t=>{t.length>0&&t[t.length-1].intersectionRatio>0&&this.onScrollChanged(document.createEvent("Event"))},{})),this.listenForScroll(),this.readSelectionRange()}onScrollChanged(e){this.view.inputState.runHandlers("scroll",e),this.intersecting&&this.view.measure()}onScroll(e){this.intersecting&&this.flush(!1),this.editContext&&this.view.requestMeasure(this.editContext.measureReq),this.onScrollChanged(e)}onResize(){this.resizeTimeout<0&&(this.resizeTimeout=setTimeout(()=>{this.resizeTimeout=-1,this.view.requestMeasure()},50))}onPrint(e){(e.type=="change"||!e.type)&&!e.matches||(this.view.viewState.printing=!0,this.view.measure(),setTimeout(()=>{this.view.viewState.printing=!1,this.view.requestMeasure()},500))}updateGaps(e){if(this.gapIntersection&&(e.length!=this.gaps.length||this.gaps.some((t,i)=>t!=e[i]))){this.gapIntersection.disconnect();for(let t of e)this.gapIntersection.observe(t);this.gaps=e}}onSelectionChange(e){let t=this.selectionChanged;if(!this.readSelectionRange()||this.delayedAndroidKey)return;let{view:i}=this,s=this.selectionRange;if(i.state.facet(ft)?i.root.activeElement!=this.dom:!Pi(this.dom,s))return;let r=s.anchorNode&&i.docView.tile.nearest(s.anchorNode);if(r&&r.isWidget()&&r.widget.ignoreEvent(e)){t||(this.selectionChanged=!1);return}(A.ie&&A.ie_version<=11||A.android&&A.chrome)&&!i.state.selection.main.empty&&s.focusNode&&Hi(s.focusNode,s.focusOffset,s.anchorNode,s.anchorOffset)?this.flushSoon():this.flush(!1)}readSelectionRange(){let{view:e}=this,t=ji(e.root);if(!t)return!1;let i=A.safari&&e.root.nodeType==11&&e.root.activeElement==this.dom&&Kp(this.view,t)||t;if(!i||this.selectionRange.eq(i))return!1;let s=Pi(this.dom,i);return s&&!this.selectionChanged&&e.inputState.lastFocusTime>Date.now()-200&&e.inputState.lastTouchTime<Date.now()-300&&kd(this.dom,i)?(this.view.inputState.lastFocusTime=0,e.docView.updateSelection(),!1):(this.selectionRange.setRange(i),s&&(this.selectionChanged=!0),!0)}setSelectionRange(e,t){this.selectionRange.set(e.node,e.offset,t.node,t.offset),this.selectionChanged=!1}clearSelectionRange(){this.selectionRange.set(null,0,null,0)}listenForScroll(){this.parentCheck=-1;let e=0,t=null;for(let i=this.dom;i;)if(i.nodeType==1)!t&&e<this.scrollTargets.length&&this.scrollTargets[e]==i?e++:t||(t=this.scrollTargets.slice(0,e)),t&&t.push(i),i=i.assignedSlot||i.parentNode;else if(i.nodeType==11)i=i.host;else break;if(e<this.scrollTargets.length&&!t&&(t=this.scrollTargets.slice(0,e)),t){for(let i of this.scrollTargets)i.removeEventListener("scroll",this.onScroll);for(let i of this.scrollTargets=t)i.addEventListener("scroll",this.onScroll)}}ignore(e){if(!this.active)return e();try{return this.stop(),e()}finally{this.start(),this.clear()}}start(){this.active||(this.observer.observe(this.dom,jp),Gn&&this.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.active=!0)}stop(){this.active&&(this.active=!1,this.observer.disconnect(),Gn&&this.dom.removeEventListener("DOMCharacterDataModified",this.onCharData))}clear(){this.processRecords(),this.queue.length=0,this.selectionChanged=!1}delayAndroidKey(e,t){var i;if(!this.delayedAndroidKey){let s=()=>{let r=this.delayedAndroidKey;r&&(this.clearDelayedAndroidKey(),this.view.inputState.lastKeyCode=r.keyCode,this.view.inputState.lastKeyTime=Date.now(),!this.flush()&&r.force&&li(this.dom,r.key,r.keyCode))};this.flushingAndroidKey=this.view.win.requestAnimationFrame(s)}(!this.delayedAndroidKey||e=="Enter")&&(this.delayedAndroidKey={key:e,keyCode:t,force:this.lastChange<Date.now()-50||!!(!((i=this.delayedAndroidKey)===null||i===void 0)&&i.force)})}clearDelayedAndroidKey(){this.win.cancelAnimationFrame(this.flushingAndroidKey),this.delayedAndroidKey=null,this.flushingAndroidKey=-1}flushSoon(){this.delayedFlush<0&&(this.delayedFlush=this.view.win.requestAnimationFrame(()=>{this.delayedFlush=-1,this.flush()}))}forceFlush(){this.delayedFlush>=0&&(this.view.win.cancelAnimationFrame(this.delayedFlush),this.delayedFlush=-1),this.flush()}pendingRecords(){for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}processRecords(){let e=this.pendingRecords();e.length&&(this.queue=[]);let t=-1,i=-1,s=!1;for(let r of e){let o=this.readMutation(r);o&&(o.typeOver&&(s=!0),t==-1?{from:t,to:i}=o:(t=Math.min(o.from,t),i=Math.max(o.to,i)))}return{from:t,to:i,typeOver:s}}readChange(){let{from:e,to:t,typeOver:i}=this.processRecords(),s=this.selectionChanged&&Pi(this.dom,this.selectionRange);
vendor: 5,149 bytes, lines 178-179
178if(e<0&&!s)return null;e>-1&&(this.lastChange=Date.now()),this.view.inputState.lastFocusTime=0,this.selectionChanged=!1;let r=new dp(this.view,e,t,i);return this.view.docView.domChanged={newSel:r.newSel?r.newSel.main:null},r}flush(e=!0){if(this.delayedFlush>=0||this.delayedAndroidKey)return!1;e&&this.readSelectionRange();let t=this.readChange();if(!t)return this.view.requestMeasure(),!1;let i=this.view.state,s=lc(this.view,t);return this.view.state==i&&(t.domChanged||t.newSel&&!Js(this.view.state.selection,t.newSel.main))&&this.view.update([]),s}readMutation(e){let t=this.view.docView.tile.nearest(e.target);if(!t||t.isWidget())return null;if(t.markDirty(e.type=="attributes"),e.type=="childList"){let i=Ql(t,e.previousSibling||e.target.previousSibling,-1),s=Ql(t,e.nextSibling||e.target.nextSibling,1);return{from:i?t.posAfter(i):t.posAtStart,to:s?t.posBefore(s):t.posAtEnd,typeOver:!1}}else return e.type=="characterData"?{from:t.posAtStart,to:t.posAtEnd,typeOver:e.target.nodeValue==e.oldValue}:null}setWindow(e){e!=this.win&&(this.removeWindowListeners(this.win),this.win=e,this.addWindowListeners(this.win))}addWindowListeners(e){e.addEventListener("resize",this.onResize),this.printQuery?this.printQuery.addEventListener?this.printQuery.addEventListener("change",this.onPrint):this.printQuery.addListener(this.onPrint):e.addEventListener("beforeprint",this.onPrint),e.addEventListener("scroll",this.onScroll),e.document.addEventListener("selectionchange",this.onSelectionChange)}removeWindowListeners(e){e.removeEventListener("scroll",this.onScroll),e.removeEventListener("resize",this.onResize),this.printQuery?this.printQuery.removeEventListener?this.printQuery.removeEventListener("change",this.onPrint):this.printQuery.removeListener(this.onPrint):e.removeEventListener("beforeprint",this.onPrint),e.document.removeEventListener("selectionchange",this.onSelectionChange)}update(e){this.editContext&&(this.editContext.update(e),e.startState.facet(ft)!=e.state.facet(ft)&&(e.view.contentDOM.editContext=e.state.facet(ft)?this.editContext.editContext:null))}destroy(){var e,t,i;this.stop(),(e=this.intersection)===null||e===void 0||e.disconnect(),(t=this.gapIntersection)===null||t===void 0||t.disconnect(),(i=this.resizeScroll)===null||i===void 0||i.disconnect();for(let s of this.scrollTargets)s.removeEventListener("scroll",this.onScroll);this.removeWindowListeners(this.win),clearTimeout(this.parentCheck),clearTimeout(this.resizeTimeout),this.win.cancelAnimationFrame(this.delayedFlush),this.win.cancelAnimationFrame(this.flushingAndroidKey),this.editContext&&(this.view.contentDOM.editContext=null,this.editContext.destroy())}}function Ql(n,e,t){for(;e;){let i=Y.get(e);if(i&&i.parent==n)return i;let s=e.parentNode;e=s!=n.dom?s:t>0?e.nextSibling:e.previousSibling}return null}function jl(n,e){let t=e.startContainer,i=e.startOffset,s=e.endContainer,r=e.endOffset,o=n.docView.domAtPos(n.state.selection.main.anchor,1);return Hi(o.node,o.offset,s,r)&&([t,i,s,r]=[s,r,t,i]),{anchorNode:t,anchorOffset:i,focusNode:s,focusOffset:r}}function Kp(n,e){if(e.getComposedRanges){let s=e.getComposedRanges(n.root)[0];if(s)return jl(n,s)}let t=null;function i(s){s.preventDefault(),s.stopImmediatePropagation(),t=s.getTargetRanges()[0]}return n.contentDOM.addEventListener("beforeinput",i,!0),n.dom.ownerDocument.execCommand("indent"),n.contentDOM.removeEventListener("beforeinput",i,!0),t?jl(n,t):null}class Xp{constructor(e){this.from=0,this.to=0,this.pendingContextChange=null,this.handlers=Object.create(null),this.composing=null,this.resetRange(e.state);let t=this.editContext=new window.EditContext({text:e.state.doc.sliceString(this.from,this.to),selectionStart:this.toContextPos(Math.max(this.from,Math.min(this.to,e.state.selection.main.anchor))),selectionEnd:this.toContextPos(e.state.selection.main.head)});this.handlers.textupdate=i=>{let s=e.state.selection.main,{anchor:r,head:o}=s,l=this.toEditorPos(i.updateRangeStart),a=this.toEditorPos(i.updateRangeEnd);e.inputState.composing>=0&&!this.composing&&(this.composing={contextBase:i.updateRangeStart,editorBase:l,drifted:!1});let h=a-l>i.text.length;l==this.from&&r<this.from?l=r:a==this.to&&r>this.to&&(a=r);let c=ac(e.state.sliceDoc(l,a),i.text,(h?s.from:s.to)-l,h?"end":null);if(!c){let f=w.single(this.toEditorPos(i.selectionStart),this.toEditorPos(i.selectionEnd));Js(f,s)||e.dispatch({selection:f,userEvent:"select"});return}let u={from:c.from+l,to:c.toA+l,insert:F.of(i.text.slice(c.from,c.toB).split(` 179`))};if((A.mac||A.android)&&u.from==o-1&&/^\. ?$/.test(i.text)&&e.contentDOM.getAttribute("autocorrect")=="off"&&(u={from:l,to:a,insert:F.of([i.text.replace("."," ")])}),this.pendingContextChange=u,!e.state.readOnly){let f=this.to-this.from+(u.to-u.from+u.insert.length);Do(e,u,w.single(this.toEditorPos(i.selectionStart,f),this.toEditorPos(i.selectionEnd,f)))}this.pendingContextChange&&(this.revertPending(e.state),this.setSelection(e.state)),u.from<u.to&&!u.insert.length&&e.inputState.composing>=0&&!/[\\p{Alphabetic}\\p{Number}_]/.test(t.text.slice(Math.max(0,i.updateRangeStart-1),Math.min(t.text.length,i.updateRangeStart+1)))&&this.handlers.compositionend(i)}
vendor: 4,483 bytes, line 179
179,this.handlers.characterboundsupdate=i=>{let s=[],r=null;for(let o=this.toEditorPos(i.rangeStart),l=this.toEditorPos(i.rangeEnd);o<l;o++){let a=e.coordsForChar(o);r=a&&new DOMRect(a.left,a.top,a.right-a.left,a.bottom-a.top)||r||new DOMRect,s.push(r)}t.updateCharacterBounds(i.rangeStart,s)},this.handlers.textformatupdate=i=>{let s=[];for(let r of i.getTextFormats()){let o=r.underlineStyle,l=r.underlineThickness;if(!/none/i.test(o)&&!/none/i.test(l)){let a=this.toEditorPos(r.rangeStart),h=this.toEditorPos(r.rangeEnd);if(a<h){let c=`text-decoration: underline ${/^[a-z]/.test(o)?o+" ":o=="Dashed"?"dashed ":o=="Squiggle"?"wavy ":""}${/thin/i.test(l)?1:2}px`;s.push(j.mark({attributes:{style:c}}).range(a,h))}}}e.dispatch({effects:Jh.of(j.set(s))})},this.handlers.compositionstart=()=>{e.inputState.composing<0&&(e.inputState.composing=0,e.inputState.compositionFirstChange=!0)},this.handlers.compositionend=()=>{if(e.inputState.composing=-1,e.inputState.compositionFirstChange=null,this.composing){let{drifted:i}=this.composing;this.composing=null,i&&this.reset(e.state)}};for(let i in this.handlers)t.addEventListener(i,this.handlers[i]);this.measureReq={read:i=>{this.editContext.updateControlBounds(i.contentDOM.getBoundingClientRect());let s=ji(i.root);s&&s.rangeCount&&this.editContext.updateSelectionBounds(s.getRangeAt(0).getBoundingClientRect())}}}applyEdits(e){let t=0,i=!1,s=this.pendingContextChange;return e.changes.iterChanges((r,o,l,a,h)=>{if(i)return;let c=h.length-(o-r);if(s&&o>=s.to)if(s.from==r&&s.to==o&&s.insert.eq(h)){s=this.pendingContextChange=null,t+=c,this.to+=c;return}else s=null,this.revertPending(e.state);if(r+=t,o+=t,o<=this.from)this.from+=c,this.to+=c;else if(r<this.to){if(r<this.from||o>this.to||this.to-this.from+h.length>3e4){i=!0;return}this.editContext.updateText(this.toContextPos(r),this.toContextPos(o),h.toString()),this.to+=c}t+=c}),s&&!i&&this.revertPending(e.state),!i}update(e){let t=this.pendingContextChange,i=e.startState.selection.main;this.composing&&(this.composing.drifted||!e.changes.touchesRange(i.from,i.to)&&e.transactions.some(s=>!s.isUserEvent("input.type")&&s.changes.touchesRange(this.from,this.to)))?(this.composing.drifted=!0,this.composing.editorBase=e.changes.mapPos(this.composing.editorBase)):!this.applyEdits(e)||!this.rangeIsValid(e.state)?(this.pendingContextChange=null,this.reset(e.state)):(e.docChanged||e.selectionSet||t)&&this.setSelection(e.state),(e.geometryChanged||e.docChanged||e.selectionSet)&&e.view.requestMeasure(this.measureReq)}resetRange(e){let{head:t}=e.selection.main;this.from=Math.max(0,t-1e4),this.to=Math.min(e.doc.length,t+1e4)}reset(e){this.resetRange(e),this.editContext.updateText(0,this.editContext.text.length,e.doc.sliceString(this.from,this.to)),this.setSelection(e)}revertPending(e){let t=this.pendingContextChange;this.pendingContextChange=null,this.editContext.updateText(this.toContextPos(t.from),this.toContextPos(t.from+t.insert.length),e.doc.sliceString(t.from,t.to))}setSelection(e){let{main:t}=e.selection,i=this.toContextPos(Math.max(this.from,Math.min(this.to,t.anchor))),s=this.toContextPos(t.head);(this.editContext.selectionStart!=i||this.editContext.selectionEnd!=s)&&this.editContext.updateSelection(i,s)}rangeIsValid(e){let{head:t}=e.selection.main;return!(this.from>0&&t-this.from<500||this.to<e.doc.length&&this.to-t<500||this.to-this.from>1e4*3)}toEditorPos(e,t=this.to-this.from){e=Math.min(e,t);let i=this.composing;return i&&i.drifted?i.editorBase+(e-i.contextBase):e+this.from}toContextPos(e){let t=this.composing;return t&&t.drifted?t.contextBase+(e-t.editorBase):e-this.from}destroy(){for(let e in this.handlers)this.editContext.removeEventListener(e,this.handlers[e])}}class R{get state(){return this.viewState.state}get viewport(){return this.viewState.viewport}get visibleRanges(){return this.viewState.visibleRanges}get inView(){return this.viewState.inView}get composing(){return!!this.inputState&&this.inputState.composing>0}get compositionStarted(){return!!this.inputState&&this.inputState.composing>=0}get root(){return this._root}get win(){return this.dom.ownerDocument.defaultView||window}constructor(e={}){var t;this.plugins=[],this.pluginMap=new Map,this.editorAttrs={},this.contentAttrs={},this.bidiCache=[],this.destroyed=!1,this.updateState=2,this.measureScheduled=-1,this.measureRequests=[],this.contentDOM=document.createElement("div"),this.scrollDOM=document.createElement("div"),this.scrollDOM.tabIndex=-1,this.scrollDOM.className="
179cm-scroller",this.scrollDOM.appendChild(this.contentDOM),this.announceDOM=document.createElement("div"),this.announceDOM.className="cm-announced",this.announceDOM.setAttribute("aria-live","polite"),this.dom=document.createElement("div"),this.dom.appendChild(this.announceDOM),this.dom.appendChild(this.scrollDOM),e.parent&&e.parent.appendChild(this.dom);let{dispatch:i}=e;this.dispatchTransactions=e.dispatchTransactions||i&&(s=>s.forEach(r=>i(r,this)))||(s=>this.update(s)),this.dispatch=this.dispatch.bind(this),this._root=e.root||vd(e.parent)||document,this.viewState=new $l(this,e.state||W.create(e)),e.scrollTo&&e.scrollTo.is(gs)&&(this.viewState.scrollTarget=e.scrollTo.value.clip(this.viewState.state)),this.plugins=this.state.facet(Jt).map(s=>new Vn(s));for(let s of this.plugins)s.update(this);this.observer=new Gp(this),this.inputState=new yp(this),this.inputState.ensureHandlers(this.plugins),this.docView=new Dl(this),this.mountStyles(),this.updateAttrs(),this.updateState=0,this.requestMeasure(),!((t=document.fonts)===null||t===void 0)&&t.ready&&document.fonts.ready.then(()=>{this.viewState.mustMeasureContent="refresh",this.requestMeasure()})}dispatch(...e){let t=e.length==1&&e[0]instanceof se?e:e.length==1&&Array.isArray(e[0])?e[0]:[this.state.update(...e)];this.dispatchTransactions(t,this)}update(e){if(this.updateState!=0)throw new Error("Calls to EditorView.update are not allowed while an update is in progress");let t=!1,i=!1,s,r=this.state;for(let f of e){if(f.startState!=r)throw new RangeError("Trying to update state with a transaction that doesn't start from the previous state.");
vendor: 27,471 bytes, line 179
179r=f.state}if(this.destroyed){this.viewState.state=r;return}let o=this.hasFocus,l=0,a=null;e.some(f=>f.annotation(pc))?(this.inputState.notifiedFocused=o,l=1):o!=this.inputState.notifiedFocused&&(this.inputState.notifiedFocused=o,a=mc(r,o),a||(l=1));let h=this.observer.delayedAndroidKey,c=null;if(h?(this.observer.clearDelayedAndroidKey(),c=this.observer.readChange(),(c&&!this.state.doc.eq(r.doc)||!this.state.selection.eq(r.selection))&&(c=null)):this.observer.clear(),r.facet(W.phrases)!=this.state.facet(W.phrases))return this.setState(r);s=Ks.create(this,r,e),s.flags|=l;let u=this.viewState.scrollTarget;try{this.updateState=2;for(let f of e){if(u&&(u=u.map(f.changes)),f.scrollIntoView){let{main:d}=f.state.selection,{x:p,y:m}=this.state.facet(R.cursorScrollMargin);u=new ai(d.empty?d:w.cursor(d.head,d.head>d.anchor?-1:1),"nearest","nearest",m,p)}for(let d of f.effects)d.is(gs)&&(u=d.value.clip(this.state))}this.viewState.update(s,u),this.bidiCache=en.update(this.bidiCache,s.changes),s.empty||(this.updatePlugins(s),this.inputState.update(s)),t=this.docView.update(s),this.state.facet(Di)!=this.styleModules&&this.mountStyles(),i=this.updateAttrs(),this.showAnnouncements(e),this.docView.updateSelection(t,e.some(f=>f.isUserEvent("select.pointer")))}finally{this.updateState=0}if(s.startState.facet(Ss)!=s.state.facet(Ss)&&(this.viewState.mustMeasureContent=!0),(t||i||u||this.viewState.mustEnforceCursorAssoc||this.viewState.mustMeasureContent)&&this.requestMeasure(),t&&this.docViewUpdate(),!s.empty)for(let f of this.state.facet(qr))try{f(s)}catch(d){De(this.state,d,"update listener")}(a||c)&&Promise.resolve().then(()=>{a&&this.state==a.startState&&this.dispatch(a),c&&!lc(this,c)&&h.force&&li(this.contentDOM,h.key,h.keyCode)})}setState(e){if(this.updateState!=0)throw new Error("Calls to EditorView.setState are not allowed while an update is in progress");if(this.destroyed){this.viewState.state=e;return}this.updateState=2;let t=this.hasFocus;try{for(let i of this.plugins)i.destroy(this);this.viewState=new $l(this,e),this.plugins=e.facet(Jt).map(i=>new Vn(i)),this.pluginMap.clear();for(let i of this.plugins)i.update(this);this.docView.destroy(),this.docView=new Dl(this),this.inputState.ensureHandlers(this.plugins),this.mountStyles(),this.updateAttrs(),this.bidiCache=[]}finally{this.updateState=0}t&&this.focus(),this.requestMeasure()}updatePlugins(e){let t=e.startState.facet(Jt),i=e.state.facet(Jt);if(t!=i){let s=[];for(let r of i){let o=t.indexOf(r);if(o<0)s.push(new Vn(r));else{let l=this.plugins[o];l.mustUpdate=e,s.push(l)}}for(let r of this.plugins)r.mustUpdate!=e&&r.destroy(this);this.plugins=s,this.pluginMap.clear()}else for(let s of this.plugins)s.mustUpdate=e;for(let s=0;s<this.plugins.length;s++)this.plugins[s].update(this);t!=i&&this.inputState.ensureHandlers(this.plugins)}docViewUpdate(){for(let e of this.plugins){let t=e.value;if(t&&t.docViewUpdate)try{t.docViewUpdate(this)}catch(i){De(this.state,i,"doc view update listener")}}}measure(e=!0){if(this.destroyed)return;if(this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.observer.delayedAndroidKey){this.measureScheduled=-1,this.requestMeasure();return}this.measureScheduled=0,e&&this.observer.forceFlush();let t=null,i=this.viewState.scrollParent,s=this.viewState.getScrollOffset(),{scrollAnchorPos:r,scrollAnchorHeight:o}=this.viewState;Math.abs(s-this.viewState.scrollOffset)>1&&(o=-1),this.viewState.scrollAnchorHeight=-1;try{for(let l=0;;l++){if(o<0)if(_h(i||this.win))r=-1,o=this.viewState.heightMap.height;else{let d=this.viewState.scrollAnchorAt(s);r=d.from,o=d.top}this.updateState=1;let a=this.viewState.measure();if(!a&&!this.measureRequests.length&&this.viewState.scrollTarget==null)break;if(l>5){console.warn(this.measureRequests.length?"Measure loop restarted more than 5 times":"Viewport failed to stabilize");break}let h=[];a&4||([this.measureRequests,h]=[h,this.measureRequests]);let c=h.map(d=>{try{return d.read(this)}catch(p){return De(this.state,p),Gl}}),u=Ks.create(this,this.state,[]),f=!1;u.flags|=a,t?t.flags|=a:t=u,this.updateState=2,u.empty||(this.updatePlugins(u),this.inputState.update(u),this.updateAttrs(),f=this.docView.update(u),f&&this.docViewUpdate());for(let d=0;d<h.length;d++)if(c[d]!=Gl)try{let p=h[d];p.write&&p.write(c[d],this)}catch(p){De(this.state,p)}if(f&&this.docView.updateSelection(!0),!u.viewportChanged&&this.measureRequests.length==0){if(this.viewState.editorHeight)if(this.viewState.scrollTarget){this.docView.scrollIntoView(this.viewState.scrollTarget),this.viewState.scrollTarget=null,o=-1;continue}else{let p=((r<0?this.viewState.heightMap.height:this.viewState.lineBlockAt(r).top)-o)/this.scaleY;if((p>1||p<-1)&&(i==this.scrollDOM||this.hasFocus||Math.max(this.inputState.lastWheelEvent,this.inputState.lastTouchTime)>Date.now()-100)){s=s+p,i?i.scrollTop+=p:this.win.scrollBy(0,p),o=-1;continue}}break}}}finally{this.updateState=0,this.measureScheduled=-1}if(t&&!t.empty)for(let l of this.state.facet(qr))l(t)}get themeClasses(){return Xr+" "+(this.state.facet(Kr)?wc:bc)+" "+this.state.facet(Ss)}updateAttrs(){let e=Kl(this,Zh,{class:"cm-editor"+(this.hasFocus?" cm-focused ":" ")+this.themeClasses}),t={spellcheck:"false",autocorrect:"off",autocapitalize:"off",writingsuggestions:"false",translate:"no",contenteditable:this.state.facet(ft)?"true":"false",class:"cm-content",style:`${A.tabSize}: ${this.state.tabSize}`,role:"textbox","aria-multiline":"true"};this.state.readOnly&&(t["aria-readonly"]="true"),Kl(this,Mo,t);let i=this.observer.ignore(()=>{let s=kl(this.contentDOM,this.contentAttrs,t),r=kl(this.dom,this.editorAttrs,e);return s||r});return this.editorAttrs=e,this.contentAttrs=t,i}showAnnouncements(e){let t=!0;for(let i of e)for(let s of i.effects)if(s.is(R.announce)){t&&(this.announceDOM.textContent=""),t=!1;let r=this.announceDOM.appendChild(document.createElement("div"));r.textContent=s.value}}mountStyles(){this.styleModules=this.state.facet(Di);let e=this.state.facet(R.cspNonce);At.mount(this.root,this.styleModules.concat(Qp).reverse(),e?{nonce:e}:void 0)}readMeasured(){if(this.updateState==2)throw new Error("Reading the editor layout isn't allowed during an update");this.updateState==0&&this.measureScheduled>-1&&this.measure(!1)}requestMeasure(e){if(this.measureScheduled<0&&(this.measureScheduled=this.win.requestAnimationFrame(()=>this.measure())),e){if(this.measureRequests.indexOf(e)>-1)return;if(e.key!=null){for(let t=0;t<this.measureRequests.length;t++)if(this.measureRequests[t].key===e.key){this.measureRequests[t]=e;return}}this.measureRequests.push(e)}}plugin(e){let t=this.pluginMap.get(e);return(t===void 0||t&&t.plugin!=e)&&this.pluginMap.set(e,t=this.plugins.find(i=>i.plugin==e)||null),t&&t.update(this).value}get documentTop(){return this.contentDOM.getBoundingClientRect().top+this.viewState.paddingTop}get documentPadding(){return{top:this.viewState.paddingTop,bottom:this.viewState.paddingBottom}}get scaleX(){return this.viewState.scaleX}get scaleY(){return this.viewState.scaleY}elementAtHeight(e){return this.readMeasured(),this.viewState.elementAtHeight(e)}lineBlockAtHeight(e){return this.readMeasured(),this.viewState.lineBlockAtHeight(e)}get viewportLineBlocks(){return this.viewState.viewportLines}lineBlockAt(e){return this.viewState.lineBlockAt(e)}get contentHeight(){return this.viewState.contentHeight}moveByChar(e,t,i){return Qn(this,e,Rl(this,e,t,i))}moveByGroup(e,t){return Qn(this,e,Rl(this,e,t,i=>lp(this,e.head,i)))}visualLineSide(e,t){let i=this.bidiSpans(e),s=this.textDirectionAt(e.from),r=i[t?i.length-1:0];return w.cursor(r.side(t,s)+e.from,r.forward(!t,s)?1:-1)}moveToLineBoundary(e,t,i=!0){return op(this,e,t,i)}moveVertically(e,t,i){return Qn(this,e,ap(this,e,t,i))}domAtPos(e,t=1){return this.docView.domAtPos(e,t)}posAtDOM(e,t=0){return this.docView.posFromDOM(e,t)}posAtCoords(e,t=!0){this.readMeasured();let i=jr(this,e,t);return i&&i.pos}posAndSideAtCoords(e,t=!0){return this.readMeasured(),jr(this,e,t)}coordsAtPos(e,t=1){this.readMeasured();let i=this.docView.coordsAt(e,t);if(!i||i.left==i.right)return i;let s=this.state.doc.lineAt(e),r=this.bidiSpans(s),o=r[lt.find(r,e-s.from,-1,t)];return Gi(i,o.dir==G.LTR==t>0)}coordsForChar(e){return this.readMeasured(),this.docView.coordsForChar(e)}get defaultCharacterWidth(){return this.viewState.heightOracle.charWidth}get defaultLineHeight(){return this.viewState.heightOracle.lineHeight}get textDirection(){return this.viewState.defaultTextDirection}textDirectionAt(e){return!this.state.facet(Xh)||e<this.viewport.from||e>this.viewport.to?this.textDirection:(this.readMeasured(),this.docView.textDirectionAt(e))}get lineWrapping(){return this.viewState.heightOracle.lineWrapping}bidiSpans(e){if(e.length>Yp)return Vh(e.length);let t=this.textDirectionAt(e.from),i;for(let r of this.bidiCache)if(r.from==e.from&&r.dir==t&&(r.fresh||zh(r.isolates,i=Ml(this,e))))return r.order;i||(i=Ml(this,e));let s=Rd(e.text,t,i);return this.bidiCache.push(new en(e.from,e.to,t,i,!0,s)),s}get hasFocus(){var e;return(this.dom.ownerDocument.hasFocus()||A.safari&&((e=this.inputState)===null||e===void 0?void 0:e.lastContextMenu)>Date.now()-3e4)&&this.root.activeElement==this.contentDOM}focus(){this.observer.ignore(()=>{Bh(this.contentDOM),this.docView.updateSelection()})}setRoot(e){this._root!=e&&(this._root=e,this.observer.setWindow((e.nodeType==9?e:e.ownerDocument).defaultView||window),this.mountStyles())}destroy(){this.root.activeElement==this.contentDOM&&this.contentDOM.blur();for(let e of this.plugins)e.destroy(this);this.plugins=[],this.inputState.destroy(),this.docView.destroy(),this.dom.remove(),this.observer.destroy(),this.measureScheduled>-1&&this.win.cancelAnimationFrame(this.measureScheduled),this.destroyed=!0}static scrollIntoView(e,t={}){var i,s,r,o;return gs.of(new ai(typeof e=="number"?w.cursor(e):e,(i=t.y)!==null&&i!==void 0?i:"nearest",(s=t.x)!==null&&s!==void 0?s:"nearest",(r=t.yMargin)!==null&&r!==void 0?r:5,(o=t.xMargin)!==null&&o!==void 0?o:5))}scrollSnapshot(){let{scrollTop:e,scrollLeft:t}=this.scrollDOM,i=this.viewState.scrollAnchorAt(e);return gs.of(new ai(w.cursor(i.from),"start","start",i.top-e,t,!0))}setTabFocusMode(e){e==null?this.inputState.tabFocusMode=this.inputState.tabFocusMode<0?0:-1:typeof e=="boolean"?this.inputState.tabFocusMode=e?0:-1:this.inputState.tabFocusMode!=0&&(this.inputState.tabFocusMode=Date.now()+e)}static domEventHandlers(e){return Re.define(()=>({}),{eventHandlers:e})}static domEventObservers(e){return Re.define(()=>({}),{eventObservers:e})}static theme(e,t){let i=At.newName(),s=[Ss.of(i),Di.of(Yr(`.${i}`,e))];return t&&t.dark&&s.push(Kr.of(!0)),s}static baseTheme(e){return Ci.lowest(Di.of(Yr("."+Xr,e,Cc)))}static findFromDOM(e){var t;let i=e.querySelector(".cm-content"),s=i&&Y.get(i)||Y.get(e);return((t=s?.root)===null||t===void 0?void 0:t.view)||null}}R.styleModule=Di;R.inputHandler=Gh;R.clipboardInputFilter=To;R.clipboardOutputFilter=Ao;R.scrollHandler=Yh;R.focusChangeEffect=Kh;R.perLineTextDirection=Xh;R.exceptionSink=jh;R.updateListener=qr;R.editable=ft;R.mouseSelectionStyle=Qh;R.dragMovesSelection=qh;R.clickAddsSelectionRange=Uh;R.decorations=An;R.blockWrappers=ec;R.outerDecorations=Eo;R.atomicRanges=rs;R.bidiIsolatedRanges=tc;R.cursorScrollMargin=E.define({combine:n=>{let e=5,t=5;for(let i of n)typeof i=="number"?e=t=i:{x:e,y:t}=i;return{x:e,y:t}}});R.scrollMargins=ic;R.darkTheme=Kr;R.cspNonce=E.define({combine:n=>n.length?n[0]:""});R.contentAttributes=Mo;R.editorAttributes=Zh;R.lineWrapping=R.contentAttributes.of({class:"cm-lineWrapping"});R.announce=H.define();const Yp=4096,Gl={};class en{constructor(e,t,i,s,r,o){this.from=e,this.to=t,this.dir=i,this.isolates=s,this.fresh=r,this.order=o}static update(e,t){if(t.empty&&!e.some(r=>r.fresh))return e;let i=[],s=e.length?e[e.length-1].dir:G.LTR;for(let r=Math.max(0,e.length-10);r<e.length;r++){let o=e[r];o.dir==s&&!t.touchesRange(o.from,o.to)&&i.push(new en(t.mapPos(o.from,1),t.mapPos(o.to,-1),o.dir,o.isolates,!1,o.order))}return i}}function Kl(n,e,t){for(let i=n.state.facet(e),s=i.length-1;s>=0;s--){let r=i[s],o=typeof r=="function"?r(n):r;o&&So(o,t)}return t}const Jp=A.mac?"mac":A.windows?"win":A.linux?"linux":"key";function Zp(n,e){const t=n.split(/-(?!$)/);let i=t[t.length-1];i=="Space"&&(i=" ");let s,r,o,l;for(let a=0;a<t.length-1;++a){const h=t[a];if(/^(cmd|meta|m)$/i.test(h))l=!0;else if(/^a(lt)?$/i.test(h))s=!0;else if(/^(c|ctrl|control)$/i.test(h))r=!0;else if(/^s(hift)?$/i.test(h))o=!0;else if(/^mod$/i.test(h))e=="mac"?l=!0:r=!0;else throw new Error("Unrecognized modifier name: "+h)}return s&&(i="Alt-"+i),r&&(i="Ctrl-"+i),l&&(i="Meta-"+i),o&&(i="Shift-"+i),i}function vs(n,e,t){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t!==!1&&e.shiftKey&&(n="Shift-"+n),n}const em=Ci.default(R.domEventHandlers({keydown(n,e){return vc(Sc(e.state),n,e,"editor")}})),xc=E.define({enables:em}),Xl=new WeakMap;function Sc(n){let e=n.facet(xc),t=Xl.get(e);return t||Xl.set(e,t=sm(e.reduce((i,s)=>i.concat(s),[]))),t}function tm(n,e,t){return vc(Sc(n.state),e,n,t)}let xt=null;const im=4e3;function sm(n,e=Jp){let t=Object.create(null),i=Object.create(null),s=(o,l)=>{let a=i[o];if(a==null)i[o]=l;else if(a!=l)throw new Error("Key binding "+o+" is used both as a regular binding and as a multi-stroke prefix")},r=(o,l,a,h,c)=>{var u,f;let d=t[o]||(t[o]=Object.create(null)),p=l.split(/ (?!$)/).map(y=>Zp(y,e));for(let y=1;y<p.length;y++){let b=p.slice(0,y).join(" ");s(b,!0),d[b]||(d[b]={preventDefault:!0,stopPropagation:!1,run:[C=>{let k=xt={view:C,prefix:b,scope:o};return setTimeout(()=>{xt==k&&(xt=null)},im),!0}]})}let m=p.join(" ");s(m,!1);let g=d[m]||(d[m]={preventDefault:!1,stopPropagation:!1,run:((f=(u=d._any)===null||u===void 0?void 0:u.run)===null||f===void 0?void 0:f.slice())||[]});a&&g.run.push(a),h&&(g.preventDefault=!0),c&&(g.stopPropagation=!0)};for(let o of n){let l=o.scope?o.scope.split(" "):["editor"];if(o.any)for(let h of l){let c=t[h]||(t[h]=Object.create(null));c._any||(c._any={preventDefault:!1,stopPropagation:!1,run:[]});let{any:u}=o;for(let f in c)c[f].run.push(d=>u(d,Jr))}let a=o[e]||o.key;if(a)for(let h of l)r(h,a,o.run,o.preventDefault,o.stopPropagation),o.shift&&r(h,"Shift-"+a,o.shift,o.preventDefault,o.stopPropagation)}return t}let Jr=null;function vc(n,e,t,i){Jr=e;let s=md(e),r=bt(s,0),o=Bt(r)==s.length&&s!=" ",l="",a=!1,h=!1,c=!1;xt&&xt.view==t&&xt.scope==i&&(l=xt.prefix+" ",cc.indexOf(e.keyCode)<0&&(h=!0,xt=null));let u=new Set,f=g=>{if(g){for(let y of g.run)if(!u.has(y)&&(u.add(y),y(t)))return g.stopPropagation&&(c=!0),!0;g.preventDefault&&(g.stopPropagation&&(c=!0),h=!0)}return!1},d=n[i],p,m;return d&&(f(d[l+vs(s,e,!o)])?a=!0:o&&(e.altKey||e.metaKey||e.ctrlKey)&&!(A.windows&&e.ctrlKey&&e.altKey)&&!(A.mac&&e.altKey&&!(e.ctrlKey||e.metaKey))&&(p=Mt[e.keyCode])&&p!=s?(f(d[l+vs(p,e,!0)])||e.shiftKey&&(m=qi[e.keyCode])!=s&&m!=p&&f(d[l+vs(m,e,!1)]))&&(a=!0):o&&e.shiftKey&&f(d[l+vs(s,e,!0)])&&(a=!0),!a&&f(d._any)&&(a=!0)),h&&(a=!0),a&&c&&e.stopPropagation(),Jr=null,a}class nm extends is{constructor(e){super(),this.content=e}toDOM(e){let t=document.createElement("span");return t.className="cm-placeholder",t.style.pointerEvents="none",t.appendChild(typeof this.content=="string"?document.createTextNode(this.content):typeof this.content=="function"?this.content(e):this.content.cloneNode(!0)),t.setAttribute("aria-hidden","true"),t}coordsAt(e){let t=e.firstChild?Fi(e.firstChild):[];if(!t.length)return null;let i=window.getComputedStyle(e.parentNode),s=Gi(t[0],i.direction!="rtl"),r=parseInt(i.lineHeight);return s.bottom-s.top>r*1.5?{left:s.left,right:s.right,top:s.top,bottom:s.top+r}:s}ignoreEvent(){return!1}}function Ob(n){return[Re.fromClass(class{constructor(t){this.view=t,this.placeholder=j.set([j.widget({widget:new nm(n),side:1}).range(0)])}get decorations(){return this.view.state.doc.length?j.none:this.placeholder}},{decorations:t=>t.decorations}),R.contentAttributes.of({"aria-placeholder":n})]}const ks="-10000px";class rm{constructor(e,t,i,s){this.facet=t,this.createTooltipView=i,this.removeTooltipView=s,this.input=e.state.facet(t),this.tooltips=this.input.filter(o=>o);let r=null;this.tooltipViews=this.tooltips.map(o=>r=i(o,r))}update(e,t){var i;let s=e.state.facet(this.facet),r=s.filter(a=>a);if(s===this.input){for(let a of this.tooltipViews)a.update&&a.update(e);return!1}let o=[],l=t?[]:null;for(let a=0;a<r.length;a++){let h=r[a],c=-1;if(h){for(let u=0;u<this.tooltips.length;u++){let f=this.tooltips[u];f&&f.create==h.create&&(c=u)}if(c<0)o[a]=this.createTooltipView(h,a?o[a-1]:null),l&&(l[a]=!!h.above);else{let u=o[a]=this.tooltipViews[c];l&&(l[a]=t[c]),u.update&&u.update(e)}}}for(let a of this.tooltipViews)o.indexOf(a)<0&&(this.removeTooltipView(a),(i=a.destroy)===null||i===void 0||i.call(a));return t&&(l.forEach((a,h)=>t[h]=a),t.length=l.length),this.input=s,this.tooltips=r,this.tooltipViews=o,!0}}function om(n){let e=n.dom.ownerDocument.documentElement;return{top:0,left:0,bottom:e.clientHeight,right:e.clientWidth}}const Kn=E.define({combine:n=>{var e,t,i;return{position:A.ios?"absolute":((e=n.find(s=>s.position))===null||e===void 0?void 0:e.position)||"fixed",parent:((t=n.find(s=>s.parent))===null||t===void 0?void 0:t.parent)||null,tooltipSpace:((i=n.find(s=>s.tooltipSpace))===null||i===void 0?void 0:i.tooltipSpace)||om}}}),Yl=new WeakMap,kc=Re.fromClass(class{constructor(n){this.view=n,this.above=[],this.inView=!0,this.madeAbsolute=!1,this.lastTransaction=0,this.measureTimeout=-1;let e=n.state.facet(Kn);this.position=e.position,this.parent=e.parent,this.classes=n.themeClasses,this.createContainer(),this.measureReq={read:this.readMeasure.bind(this),write:this.writeMeasure.bind(this),key:this},this.resizeObserver=typeof ResizeObserver=="function"?new ResizeObserver(()=>this.measureSoon()):null,this.manager=new rm(n,Tc,(t,i)=>this.createTooltip(t,i),t=>{this.resizeObserver&&this.resizeObserver.unobserve(t.dom),t.dom.remove()}),this.above=this.manager.tooltips.map(t=>!!t.above),this.intersectionObserver=typeof IntersectionObserver=="function"?new IntersectionObserver(t=>{Date.now()>this.lastTransaction-50&&t.length>0&&t[t.length-1].intersectionRatio<1&&this.measureSoon()},{threshold:[1]}):null,this.observeIntersection(),n.win.addEventListener("resize",this.measureSoon=this.measureSoon.bind(this)),this.maybeMeasure()}createContainer(){this.parent?(this.container=document.createElement("div"),this.container.style.position="relative",this.container.className=this.view.themeClasses,this.parent.appendChild(this.container)):this.container=this.view.dom}observeIntersection(){if(this.intersectionObserver){this.intersectionObserver.disconnect();for(let n of this.manager.tooltipViews)this.intersectionObserver.observe(n.dom)}}measureSoon(){this.measureTimeout<0&&(this.measureTimeout=setTimeout(()=>{this.measureTimeout=-1,this.maybeMeasure()},50))}update(n){n.transactions.length&&(this.lastTransaction=Date.now());let e=this.manager.update(n,this.above);e&&this.observeIntersection();let t=e||n.geometryChanged,i=n.state.facet(Kn);if(i.position!=this.position&&!this.madeAbsolute){this.position=i.position;for(let s of this.manager.tooltipViews)s.dom.style.position=this.position;t=!0}if(i.parent!=this.parent){this.parent&&this.container.remove(),this.parent=i.parent,this.createContainer();for(let s of this.manager.tooltipViews)this.container.appendChild(s.dom);t=!0}else this.parent&&this.view.themeClasses!=this.classes&&(this.classes=this.container.className=this.view.themeClasses);t&&this.maybeMeasure()}createTooltip(n,e){let t=n.create(this.view),i=e?e.dom:null;if(t.dom.classList.add("cm-tooltip"),n.arrow&&!t.dom.querySelector(".cm-tooltip > .cm-tooltip-arrow")){let s=document.createElement("div");s.className="cm-tooltip-arrow",t.dom.appendChild(s)}return t.dom.style.position=this.position,t.dom.style.top=ks,t.dom.style.left="0px",this.container.insertBefore(t.dom,i),t.mount&&t.mount(this.view),this.resizeObserver&&this.resizeObserver.observe(t.dom),t}destroy(){var n,e,t;this.view.win.removeEventListener("resize",this.measureSoon);for(let i of this.manager.tooltipViews)i.dom.remove(),(n=i.destroy)===null||n===void 0||n.call(i);this.parent&&this.container.remove(),(e=this.resizeObserver)===null||e===void 0||e.disconnect(),(t=this.intersectionObserver)===null||t===void 0||t.disconnect(),clearTimeout(this.measureTimeout)}readMeasure(){let n=1,e=1,t=!1;if(this.position=="fixed"&&this.manager.tooltipViews.length){let{dom:r}=this.manager.tooltipViews[0];if(A.safari){let o=r.getBoundingClientRect();t=Math.abs(o.top+1e4)>1||Math.abs(o.left)>1}else t=!!r.offsetParent&&r.offsetParent!=this.container.ownerDocument.body}if(t||this.position=="absolute")if(this.parent){let r=this.parent.getBoundingClientRect();r.width&&r.height&&(n=r.width/this.parent.offsetWidth,e=r.height/this.parent.offsetHeight)}else({scaleX:n,scaleY:e}=this.view.viewState);let i=this.view.scrollDOM.getBoundingClientRect(),s=Oo(this.view);return{visible:{left:i.left+s.left,top:i.top+s.top,right:i.right-s.right,bottom:i.bottom-s.bottom},parent:this.parent?this.container.getBoundingClientRect():this.view.dom.getBoundingClientRect(),pos:this.manager.tooltips.map((r,o)=>{let l=this.manager.tooltipViews[o];return l.getCoords?l.getCoords(r.pos):this.view.coordsAtPos(r.pos)}),size:this.manager.tooltipViews.map(({dom:r})=>r.getBoundingClientRect()),space:this.view.state.facet(Kn).tooltipSpace(this.view),scaleX:n,scaleY:e,makeAbsolute:t}}writeMeasure(n){var e;if(n.makeAbsolute){this.madeAbsolute=!0,this.position="absolute";for(let l of this.manager.tooltipViews)l.dom.style.position="absolute"}let{visible:t,space:i,scaleX:s,scaleY:r}=n,o=[];for(let l=0;l<this.manager.tooltips.length;l++){let a=this.manager.tooltips[l],h=this.manager.tooltipViews[l],{dom:c}=h,u=n.pos[l],f=n.size[l];if(!u||a.clip!==!1&&(u.bottom<=Math.max(t.top,i.top)||u.top>=Math.min(t.bottom,i.bottom)||u.right<Math.max(t.left,i.left)-.1||u.left>Math.min(t.right,i.right)+.1)){c.style.top=ks;continue}let d=a.arrow?h.dom.querySelector(".cm-tooltip-arrow"):null,p=d?7:0,m=f.right-f.left,g=(e=Yl.get(h))!==null&&e!==void 0?e:f.bottom-f.top,y=h.offset||am,b=this.view.textDirection==G.LTR,C=f.width>i.right-i.left?b?i.left:i.right-f.width:b?Math.max(i.left,Math.min(u.left-(d?14:0)+y.x,i.right-m)):Math.min(Math.max(i.left,u.left-m+(d?14:0)-y.x),i.right-m),k=this.above[l];!a.strictSide&&(k?u.top-g-p-y.y<i.top:u.bottom+g+p+y.y>i.bottom)&&k==i.bottom-u.bottom>u.top-i.top&&(k=this.above[l]=!k);let x=(k?u.top-i.top:i.bottom-u.bottom)-p;if(x<g&&h.resize!==!1){if(x<this.view.defaultLineHeight){c.style.top=ks;continue}Yl.set(h,g),c.style.height=(g=x)/r+"px"}else c.style.height&&(c.style.height="");let T=k?u.top-g-p-y.y:u.bottom+p+y.y,v=C+m;if(h.overlap!==!0)for(let I of o)I.left<v&&I.right>C&&I.top<T+g&&I.bottom>T&&(T=k?I.top-g-2-p:I.bottom+p+2);if(this.position=="absolute"?(c.style.top=(T-n.parent.top)/r+"px",Jl(c,(C-n.parent.left)/s)):(c.style.top=T/r+"px",Jl(c,C/s)),d){let I=u.left+(b?y.x:-y.x)-(C+14-7);d.style.left=I/s+"px"}h.overlap!==!0&&o.push({left:C,top:T,right:v,bottom:T+g}),c.classList.toggle("cm-tooltip-above",k),c.classList.toggle("cm-tooltip-below",!k),h.positioned&&h.positioned(n.space)}}maybeMeasure(){if(this.manager.tooltips.length&&(this.view.inView&&this.view.requestMeasure(this.measureReq),this.inView!=this.view.inView&&(this.inView=this.view.inView,!this.inView)))for(let n of this.manager.tooltipViews)n.dom.style.top=ks}},{eventObservers:{scroll(){this.maybeMeasure()}}});function Jl(n,e){let t=parseInt(n.style.left,10);(isNaN(t)||Math.abs(e-t)>1)&&(n.style.left=e+"px")}const lm=R.baseTheme({".cm-tooltip":{zIndex:500,boxSizing:"border-box"},"&light .cm-tooltip":{border:"1px solid #bbb",backgroundColor:"#f5f5f5"},"&light .cm-tooltip-section:not(:first-child)":{borderTop:"1px solid #bbb"},"&dark .cm-tooltip":{backgroundColor:"#333338",color:"white"},".cm-tooltip-arrow":{height:"7px",width:`${7*2}px`,position:"absolute",zIndex:-1,overflow:"hidden","&:before, &:after":{content:"''",position:"absolute",width:0,height:0,borderLeft:"7px solid transparent",borderRight:"7px solid transparent"},".cm-tooltip-above &":{bottom:"-7px","&:before":{borderTop:"7px solid #bbb"},"&:after":{borderTop:"7px solid #f5f5f5",bottom:"1px"}},".cm-tooltip-below &":{top:"-7px","&:before":{borderBottom:"7px solid #bbb"},"&:after":{borderBottom:"7px solid #f5f5f5",top:"1px"}}},"&dark .cm-tooltip .cm-tooltip-arrow":{"&:before":{borderTopColor:"#333338",borderBottomColor:"#333338"},"&:after":{borderTopColor:"transparent",borderBottomColor:"transparent"}}}),am={x:0,y:0},Tc=E.define({enables:[kc,lm]});function Ac(n,e){let t=n.plugin(kc);if(!t)return null;let i=t.manager.tooltips.indexOf(e);return i<0?null:t.manager.tooltipViews[i]}const Zl=E.define({combine(n){let e,t;for(let i of n)e=e||i.topContainer,t=t||i.bottomContainer;return{topContainer:e,bottomContainer:t}}});function Mc(n,e){let t=n.plugin(Ec),i=t?t.specs.indexOf(e):-1;return i>-1?t.panels[i]:null}const Ec=Re.fromClass(class{constructor(n){this.input=n.state.facet(tn),this.specs=this.input.filter(t=>t),this.panels=this.specs.map(t=>t(n));let e=n.state.facet(Zl);this.top=new Ts(n,!0,e.topContainer),this.bottom=new Ts(n,!1,e.bottomContainer),this.top.sync(this.panels.filter(t=>t.top)),this.bottom.sync(this.panels.filter(t=>!t.top));for(let t of this.panels)t.dom.classList.add("cm-panel"),t.mount&&t.mount()}update(n){let e=n.state.facet(Zl);this.top.container!=e.topContainer&&(this.top.sync([]),this.top=new Ts(n.view,!0,e.topContainer)),this.bottom.container!=e.bottomContainer&&(this.bottom.sync([]),this.bottom=new Ts(n.view,!1,e.bottomContainer)),this.top.syncClasses(),this.bottom.syncClasses();let t=n.state.facet(tn);if(t!=this.input){let i=t.filter(a=>a),s=[],r=[],o=[],l=[];for(let a of i){let h=this.specs.indexOf(a),c;h<0?(c=a(n.view),l.push(c)):(c=this.panels[h],c.update&&c.update(n)),s.push(c),(c.top?r:o).push(c)}this.specs=i,this.panels=s,this.top.sync(r),this.bottom.sync(o);for(let a of l)a.dom.classList.add("cm-panel"),a.mount&&a.mount()}else for(let i of this.panels)i.update&&i.update(n)}destroy(){this.top.sync([]),this.bottom.sync([])}},{provide:n=>R.scrollMargins.of(e=>{let t=e.plugin(n);return t&&{top:t.top.scrollMargin(),bottom:t.bottom.scrollMargin()}})});class Ts{constructor(e,t,i){this.view=e,this.top=t,this.container=i,this.dom=void 0,this.classes="",this.panels=[],this.syncClasses()}sync(e){for(let t of this.panels)t.destroy&&e.indexOf(t)<0&&t.destroy();this.panels=e,this.syncDOM()}syncDOM(){if(this.panels.length==0){this.dom&&(this.dom.remove(),this.dom=void 0);return}if(!this.dom){this.dom=document.createElement("div"),this.dom.className=this.top?"cm-panels cm-panels-top":"cm-panels cm-panels-bottom",this.dom.style[this.top?"top":"bottom"]="0";let t=this.container||this.view.dom;t.insertBefore(this.dom,this.top?t.firstChild:null)}let e=this.dom.firstChild;for(let t of this.panels)if(t.dom.parentNode==this.dom){for(;e!=t.dom;)e=ea(e);e=e.nextSibling}else this.dom.insertBefore(t.dom,e);for(;e;)e=ea(e)}scrollMargin(){return!this.dom||this.container?0:Math.max(0,this.top?this.dom.getBoundingClientRect().bottom-Math.max(0,this.view.scrollDOM.getBoundingClientRect().top):Math.min(innerHeight,this.view.scrollDOM.getBoundingClientRect().bottom)-this.dom.getBoundingClientRect().top)}syncClasses(){if(!(!this.container||this.classes==this.view.themeClasses)){for(let e of this.classes.split(" "))e&&this.container.classList.remove(e);
vendor: 5,364 bytes, line 179
179for(let e of(this.classes=this.view.themeClasses).split(" "))e&&this.container.classList.add(e)}}}function ea(n){let e=n.nextSibling;return n.remove(),e}const tn=E.define({enables:Ec});function hm(n,e){let t,i=new Promise(o=>t=o),s=o=>cm(o,e,t);n.state.field(Xn,!1)?n.dispatch({effects:Oc.of(s)}):n.dispatch({effects:H.appendConfig.of(Xn.init(()=>[s]))});let r=Dc.of(s);return{close:r,result:i.then(o=>((n.win.queueMicrotask||(a=>n.win.setTimeout(a,10)))(()=>{n.state.field(Xn).indexOf(s)>-1&&n.dispatch({effects:r})}),o))}}const Xn=Ke.define({create(){return[]},update(n,e){for(let t of e.effects)t.is(Oc)?n=[t.value].concat(n):t.is(Dc)&&(n=n.filter(i=>i!=t.value));return n},provide:n=>tn.computeN([n],e=>e.field(n))}),Oc=H.define(),Dc=H.define();function cm(n,e,t){let i=e.content?e.content(n,()=>o(null)):null;if(!i){if(i=ne("form"),e.input){let l=ne("input",e.input);/^(text|password|number|email|tel|url)$/.test(l.type)&&l.classList.add("cm-textfield"),l.name||(l.name="input"),i.appendChild(ne("label",(e.label||"")+": ",l))}else i.appendChild(document.createTextNode(e.label||""));i.appendChild(document.createTextNode(" ")),i.appendChild(ne("button",{class:"cm-button",type:"submit"},e.submitLabel||"OK"))}let s=i.nodeName=="FORM"?[i]:i.querySelectorAll("form");for(let l=0;l<s.length;l++){let a=s[l];a.addEventListener("keydown",h=>{h.keyCode==27?(h.preventDefault(),o(null)):h.keyCode==13&&(h.preventDefault(),o(a))}),a.addEventListener("submit",h=>{h.preventDefault(),o(a)})}let r=ne("div",i,ne("button",{onclick:()=>o(null),"aria-label":n.state.phrase("close"),class:"cm-dialog-close",type:"button"},["Ã"]));e.class&&(r.className=e.class),r.classList.add("cm-dialog");function o(l){r.contains(r.ownerDocument.activeElement)&&n.focus(),t(l)}return{dom:r,top:e.top,mount:()=>{if(e.focus){let l;typeof e.focus=="string"?l=i.querySelector(e.focus):l=i.querySelector("input")||i.querySelector("button"),l&&"select"in l?l.select():l&&"focus"in l&&l.focus()}}}}class qt extends Tt{compare(e){return this==e||this.constructor==e.constructor&&this.eq(e)}eq(e){return!1}destroy(e){}}qt.prototype.elementClass="";qt.prototype.toDOM=void 0;qt.prototype.mapMode=Oe.TrackBefore;qt.prototype.startSide=qt.prototype.endSide=-1;qt.prototype.point=!0;const Yn=E.define(),um=E.define(),Hs=E.define(),ta=E.define({combine:n=>n.some(e=>e)});function fm(n){return[dm]}const dm=Re.fromClass(class{constructor(n){this.view=n,this.domAfter=null,this.prevViewport=n.viewport,this.dom=document.createElement("div"),this.dom.className="cm-gutters cm-gutters-before",this.dom.setAttribute("aria-hidden","true"),this.dom.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.gutters=n.state.facet(Hs).map(e=>new sa(n,e)),this.fixed=!n.state.facet(ta);for(let e of this.gutters)e.config.side=="after"?this.getDOMAfter().appendChild(e.dom):this.dom.appendChild(e.dom);this.fixed&&(this.dom.style.position="sticky"),this.syncGutters(!1),n.scrollDOM.insertBefore(this.dom,n.contentDOM)}getDOMAfter(){return this.domAfter||(this.domAfter=document.createElement("div"),this.domAfter.className="cm-gutters cm-gutters-after",this.domAfter.setAttribute("aria-hidden","true"),this.domAfter.style.minHeight=this.view.contentHeight/this.view.scaleY+"px",this.domAfter.style.position=this.fixed?"sticky":"",this.view.scrollDOM.appendChild(this.domAfter)),this.domAfter}update(n){if(this.updateGutters(n)){let e=this.prevViewport,t=n.view.viewport,i=Math.min(e.to,t.to)-Math.max(e.from,t.from);this.syncGutters(i<(t.to-t.from)*.8)}if(n.geometryChanged){let e=this.view.contentHeight/this.view.scaleY+"px";this.dom.style.minHeight=e,this.domAfter&&(this.domAfter.style.minHeight=e)}this.view.state.facet(ta)!=!this.fixed&&(this.fixed=!this.fixed,this.dom.style.position=this.fixed?"sticky":"",this.domAfter&&(this.domAfter.style.position=this.fixed?"sticky":"")),this.prevViewport=n.view.viewport}syncGutters(n){let e=this.dom.nextSibling;n&&(this.dom.remove(),this.domAfter&&this.domAfter.remove());let t=P.iter(this.view.state.facet(Yn),this.view.viewport.from),i=[],s=this.gutters.map(r=>new pm(r,this.view.viewport,-this.view.documentPadding.top));for(let r of this.view.viewportLineBlocks)if(i.length&&(i=[]),Array.isArray(r.type)){let o=!0;for(let l of r.type)if(l.type==Ce.Text&&o){Zr(t,i,l.from);for(let a of s)a.line(this.view,l,i);o=!1}else if(l.widget)for(let a of s)a.widget(this.view,l)}else if(r.type==Ce.Text){Zr(t,i,r.from);for(let o of s)o.line(this.view,r,i)}else if(r.widget)for(let o of s)o.widget(this.view,r);for(let r of s)r.finish();n&&(this.view.scrollDOM.insertBefore(this.dom,e),this.domAfter&&this.view.scrollDOM.appendChild(this.domAfter))}updateGutters(n){let e=n.startState.facet(Hs),t=n.state.facet(Hs),i=n.docChanged||n.heightChanged||n.viewportChanged||!P.eq(n.startState.facet(Yn),n.state.facet(Yn),n.view.viewport.from,n.view.viewport.to);if(e==t)for(let s of this.gutters)s.update(n)&&(i=!0);else{i=!0;let s=[];for(let r of t){let o=e.indexOf(r);o<0?s.push(new sa(this.view,r)):(this.gutters[o].update(n),s.push(this.gutters[o]))}for(let r of this.gutters)r.dom.remove(),s.indexOf(r)<0&&r.destroy();for(let r of s)r.config.side=="after"?this.getDOMAfter().appendChild(r.dom):this.dom.appendChild(r.dom);this.gutters=s}return i}destroy(){for(let n of this.gutters)n.destroy();this.dom.remove(),this.domAfter&&this.domAfter.remove()}},{provide:n=>
vendor: 10,550 bytes, line 179
179R.scrollMargins.of(e=>{let t=e.plugin(n);if(!t||t.gutters.length==0||!t.fixed)return null;let i=t.dom.offsetWidth*e.scaleX,s=t.domAfter?t.domAfter.offsetWidth*e.scaleX:0;return e.textDirection==G.LTR?{left:i,right:s}:{right:i,left:s}})});function ia(n){return Array.isArray(n)?n:[n]}function Zr(n,e,t){for(;n.value&&n.from<=t;)n.from==t&&e.push(n.value),n.next()}class pm{constructor(e,t,i){this.gutter=e,this.height=i,this.i=0,this.cursor=P.iter(e.markers,t.from)}addElement(e,t,i){let{gutter:s}=this,r=(t.top-this.height)/e.scaleY,o=t.height/e.scaleY;if(this.i==s.elements.length){let l=new Rc(e,o,r,i);s.elements.push(l),s.dom.appendChild(l.dom)}else s.elements[this.i].update(e,o,r,i);this.height=t.bottom,this.i++}line(e,t,i){let s=[];Zr(this.cursor,s,t.from),i.length&&(s=s.concat(i));let r=this.gutter.config.lineMarker(e,t,s);r&&s.unshift(r);let o=this.gutter;s.length==0&&!o.config.renderEmptyElements||this.addElement(e,t,s)}widget(e,t){let i=this.gutter.config.widgetMarker(e,t.widget,t),s=i?[i]:null;for(let r of e.state.facet(um)){let o=r(e,t.widget,t);o&&(s||(s=[])).push(o)}s&&this.addElement(e,t,s)}finish(){let e=this.gutter;for(;e.elements.length>this.i;){let t=e.elements.pop();e.dom.removeChild(t.dom),t.destroy()}}}class sa{constructor(e,t){this.view=e,this.config=t,this.elements=[],this.spacer=null,this.dom=document.createElement("div"),this.dom.className="cm-gutter"+(this.config.class?" "+this.config.class:"");for(let i in t.domEventHandlers)this.dom.addEventListener(i,s=>{let r=s.target,o;if(r!=this.dom&&this.dom.contains(r)){for(;r.parentNode!=this.dom;)r=r.parentNode;let a=r.getBoundingClientRect();o=(a.top+a.bottom)/2}else o=s.clientY;let l=e.lineBlockAtHeight(o-e.documentTop);t.domEventHandlers[i](e,l,s)&&s.preventDefault()});this.markers=ia(t.markers(e)),t.initialSpacer&&(this.spacer=new Rc(e,0,0,[t.initialSpacer(e)]),this.dom.appendChild(this.spacer.dom),this.spacer.dom.style.cssText+="visibility: hidden; pointer-events: none")}update(e){let t=this.markers;if(this.markers=ia(this.config.markers(e.view)),this.spacer&&this.config.updateSpacer){let s=this.config.updateSpacer(this.spacer.markers[0],e);s!=this.spacer.markers[0]&&this.spacer.update(e.view,0,0,[s])}let i=e.view.viewport;return!P.eq(this.markers,t,i.from,i.to)||(this.config.lineMarkerChange?this.config.lineMarkerChange(e):!1)}destroy(){for(let e of this.elements)e.destroy()}}class Rc{constructor(e,t,i,s){this.height=-1,this.above=0,this.markers=[],this.dom=document.createElement("div"),this.dom.className="cm-gutterElement",this.update(e,t,i,s)}update(e,t,i,s){this.height!=t&&(this.height=t,this.dom.style.height=t+"px"),this.above!=i&&(this.dom.style.marginTop=(this.above=i)?i+"px":""),mm(this.markers,s)||this.setMarkers(e,s)}setMarkers(e,t){let i="cm-gutterElement",s=this.dom.firstChild;for(let r=0,o=0;;){let l=o,a=r<t.length?t[r++]:null,h=!1;if(a){let c=a.elementClass;c&&(i+=" "+c);for(let u=o;u<this.markers.length;u++)if(this.markers[u].compare(a)){l=u,h=!0;break}}else l=this.markers.length;for(;o<l;){let c=this.markers[o++];if(c.toDOM){c.destroy(s);let u=s.nextSibling;s.remove(),s=u}}if(!a)break;a.toDOM&&(h?s=s.nextSibling:this.dom.insertBefore(a.toDOM(e),s)),h&&o++}this.dom.className=i,this.markers=t}destroy(){this.setMarkers(null,[])}}function mm(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].compare(e[t]))return!1;return!0}const gm=E.define(),ym=E.define(),Zt=E.define({combine(n){return vn(n,{formatNumber:String,domEventHandlers:{}},{domEventHandlers(e,t){let i=Object.assign({},e);for(let s in t){let r=i[s],o=t[s];i[s]=r?(l,a,h)=>r(l,a,h)||o(l,a,h):o}return i}})}});class Jn extends qt{constructor(e){super(),this.number=e}eq(e){return this.number==e.number}toDOM(){return document.createTextNode(this.number)}}function Zn(n,e){return n.state.facet(Zt).formatNumber(e,n.state)}const bm=Hs.compute([Zt],n=>({class:"cm-lineNumbers",renderEmptyElements:!1,markers(e){return e.state.facet(gm)},lineMarker(e,t,i){return i.some(s=>s.toDOM)?null:new Jn(Zn(e,e.state.doc.lineAt(t.from).number))},widgetMarker:(e,t,i)=>{for(let s of e.state.facet(ym)){let r=s(e,t,i);if(r)return r}return null},lineMarkerChange:e=>e.startState.facet(Zt)!=e.state.facet(Zt),initialSpacer(e){return new Jn(Zn(e,na(e.state.doc.lines)))},updateSpacer(e,t){let i=Zn(t.view,na(t.view.state.doc.lines));return i==e.number?e:new Jn(i)},domEventHandlers:n.facet(Zt).domEventHandlers,side:"before"}));function Db(n={}){return[Zt.of(n),fm(),bm]}function na(n){let e=9;for(;e<n;)e=e*10+9;return e}const Lc=1024;let wm=0;class er{constructor(e,t){this.from=e,this.to=t}}class N{constructor(e={}){this.id=wm++,this.perNode=!!e.perNode,this.deserialize=e.deserialize||(()=>{throw new Error("This node type doesn't define a deserialize function")}),this.combine=e.combine||null}add(e){if(this.perNode)throw new RangeError("Can't add per-node props to node types");return typeof e!="function"&&(e=Se.match(e)),t=>{let i=e(t);return i===void 0?null:[this,i]}}}N.closedBy=new N({deserialize:n=>n.split(" ")});N.openedBy=new N({deserialize:n=>n.split(" ")});N.group=new N({deserialize:n=>n.split(" ")});N.isolate=new N({deserialize:n=>{if(n&&n!="rtl"&&n!="ltr"&&n!="auto")throw new RangeError("Invalid value for isolate: "+n);return n||"auto"}});N.contextHash=new N({perNode:!0});N.lookAhead=new N({perNode:!0});N.mounted=new N({perNode:!0});class zi{constructor(e,t,i,s=!1){this.tree=e,this.overlay=t,this.parser=i,this.bracketed=s}static get(e){return e&&e.props&&e.props[N.mounted.id]}}const Cm=Object.create(null);class Se{constructor(e,t,i,s=0){this.name=e,this.props=t,this.id=i,this.flags=s}static define(e){let t=e.props&&e.props.length?Object.create(null):Cm,i=(e.top?1:0)|(e.skipped?2:0)|(e.error?4:0)|(e.name==null?8:0),s=new Se(e.name||"",t,e.id,i);if(e.props){for(let r of e.props)if(Array.isArray(r)||(r=r(s)),r){if(r[0].perNode)throw new RangeError("Can't store a per-node prop on a node type");t[r[0].id]=r[1]}}return s}prop(e){return this.props[e.id]}get isTop(){return(this.flags&1)>0}get isSkipped(){return(this.flags&2)>0}get isError(){return(this.flags&4)>0}get isAnonymous(){return(this.flags&8)>0}is(e){if(typeof e=="string"){if(this.name==e)return!0;let t=this.prop(N.group);return t?t.indexOf(e)>-1:!1}return this.id==e}static match(e){let t=Object.create(null);for(let i in e)for(let s of i.split(" "))t[s]=e[i];return i=>{for(let s=i.prop(N.group),r=-1;r<(s?s.length:0);r++){let o=t[r<0?i.name:s[r]];if(o)return o}}}}Se.none=new Se("",Object.create(null),0,8);class Io{constructor(e){this.types=e;for(let t=0;t<e.length;t++)if(e[t].id!=t)throw new RangeError("Node type ids should correspond to array positions when creating a node set")}extend(...e){let t=[];for(let i of this.types){let s=null;for(let r of e){let o=r(i);if(o){s||(s=Object.assign({},i.props));let l=o[1],a=o[0];a.combine&&a.id in s&&(l=a.combine(s[a.id],l)),s[a.id]=l}}t.push(s?new Se(i.name,s,i.id,i.flags):i)}return new Io(t)}}const As=new WeakMap,ra=new WeakMap;var X;(function(n){n[n.ExcludeBuffers=1]="ExcludeBuffers",n[n.IncludeAnonymous=2]="IncludeAnonymous",n[n.IgnoreMounts=4]="IgnoreMounts",n[n.IgnoreOverlays=8]="IgnoreOverlays",n[n.EnterBracketed=16]="EnterBracketed"})(X||(X={}));class ee{constructor(e,t,i,s,r){if(this.type=e,this.children=t,this.positions=i,this.length=s,this.props=null,r&&r.length){this.props=Object.create(null);for(let[o,l]of r)this.props[typeof o=="number"?o:o.id]=l}}toString(){let e=zi.get(this);if(e&&!e.overlay)return e.tree.toString();let t="";for(let i of this.children){let s=i.toString();s&&(t&&(t+=","),t+=s)}return this.type.name?(/\W/.test(this.type.name)&&!this.type.isError?JSON.stringify(this.type.name):this.type.name)+(t.length?"("+t+")":""):t}cursor(e=0){return new to(this.topNode,e)}cursorAt(e,t=0,i=0){let s=As.get(this)||this.topNode,r=new to(s);return r.moveTo(e,t),As.set(this,r._tree),r}get topNode(){return new We(this,0,0,null)}resolve(e,t=0){let i=Xi(As.get(this)||this.topNode,e,t,!1);return As.set(this,i),i}resolveInner(e,t=0){let i=Xi(ra.get(this)||this.topNode,e,t,!0);return ra.set(this,i),i}resolveStack(e,t=0){return vm(this,e,t)}iterate(e){let{enter:t,leave:i,from:s=0,to:r=this.length}=e,o=e.mode||0,l=(o&X.IncludeAnonymous)>0;for(let a=this.cursor(o|X.IncludeAnonymous);;){let h=!1;if(a.from<=r&&a.to>=s&&(!l&&a.type.isAnonymous||t(a)!==!1)){if(a.firstChild())continue;h=!0}for(;h&&i&&(l||!a.type.isAnonymous)&&i(a),!a.nextSibling();){if(!a.parent())return;h=!0}}}prop(e){return e.perNode?this.props?this.props[e.id]:void 0:this.type.prop(e)}get propValues(){let e=[];if(this.props)for(let t in this.props)e.push([+t,this.props[t]]);return e}balance(e={}){return this.children.length<=8?this:_o(Se.none,this.children,this.positions,0,this.children.length,0,this.length,(t,i,s)=>new ee(this.type,t,i,s,this.propValues),e.makeTree||((t,i,s)=>new ee(Se.none,t,i,s)))}static build(e){return km(e)}}ee.empty=new ee(Se.none,[],[],0);class No{constructor(e,t){this.buffer=e,this.index=t}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}get pos(){return this.index}next(){this.index-=4}fork(){return new No(this.buffer,this.index)}}class Ot{constructor(e,t,i){this.buffer=e,this.length=t,this.set=i}get type(){return Se.none}toString(){let e=[];for(let t=0;t<this.buffer.length;)e.push(this.childString(t)),t=this.buffer[t+3];return e.join(",")}childString(e){let t=this.buffer[e],i=this.buffer[e+3],s=this.set.types[t],r=s.name;if(/\W/.test(r)&&!s.isError&&(r=JSON.stringify(r)),e+=4,i==e)return r;let o=[];for(;e<i;)o.push(this.childString(e)),e=this.buffer[e+3];return r+"("+o.join(",")+")"}findChild(e,t,i,s,r){let{buffer:o}=this,l=-1;for(let a=e;a!=t&&!(Ic(r,s,o[a+1],o[a+2])&&(l=a,i>0));a=o[a+3]);return l}slice(e,t,i){let s=this.buffer,r=new Uint16Array(t-e),o=0;for(let l=e,a=0;l<t;){r[a++]=s[l++],r[a++]=s[l++]-i;let h=r[a++]=s[l++]-i;r[a++]=s[l++]-e,o=Math.max(o,h)}return new Ot(r,o,this.set)}}function Ic(n,e,t,i){switch(n){case-2:return t<e;case-1:return i>=e&&t<e;case 0:return t<e&&i>e;case 1:return t<=e&&i>e;case 2:return i>e;case 4:return!0}}function Xi(n,e,t,i){for(var s;n.from==n.to||(t<1?n.from>=e:n.from>e)||(t>-1?n.to<=e:n.to<e);){let o=!i&&n instanceof We&&n.index<0?null:n.parent;if(!o)return n;n=o}let r=i?0:X.IgnoreOverlays;if(i)for(let o=n,l=o.parent;l;o=l,l=o.parent)o instanceof We&&o.index<0&&((s=l.enter(e,t,r))===null||s===void 0?void 0:s.from)!=o.from&&(n=l);for(;;){let o=n.enter(e,t,r);if(!o)return n;n=o}}
vendor: 4,131 bytes, line 179
179class Nc{cursor(e=0){return new to(this,e)}getChild(e,t=null,i=null){let s=oa(this,e,t,i);return s.length?s[0]:null}getChildren(e,t=null,i=null){return oa(this,e,t,i)}resolve(e,t=0){return Xi(this,e,t,!1)}resolveInner(e,t=0){return Xi(this,e,t,!0)}matchContext(e){return eo(this.parent,e)}enterUnfinishedNodesBefore(e){let t=this.childBefore(e),i=this;for(;t;){let s=t.lastChild;if(!s||s.to!=t.to)break;s.type.isError&&s.from==s.to?(i=t,t=s.prevSibling):t=s}return i}get node(){return this}get next(){return this.parent}}class We extends Nc{constructor(e,t,i,s){super(),this._tree=e,this.from=t,this.index=i,this._parent=s}get type(){return this._tree.type}get name(){return this._tree.type.name}get to(){return this.from+this._tree.length}nextChild(e,t,i,s,r=0){for(let o=this;;){for(let{children:l,positions:a}=o._tree,h=t>0?l.length:-1;e!=h;e+=t){let c=l[e],u=a[e]+o.from,f;if(!(!(r&X.EnterBracketed&&c instanceof ee&&(f=zi.get(c))&&!f.overlay&&f.bracketed&&i>=u&&i<=u+c.length)&&!Ic(s,i,u,u+c.length))){if(c instanceof Ot){if(r&X.ExcludeBuffers)continue;let d=c.findChild(0,c.buffer.length,t,i-u,s);if(d>-1)return new vt(new xm(o,c,e,u),null,d)}else if(r&X.IncludeAnonymous||!c.type.isAnonymous||Bo(c)){let d;if(!(r&X.IgnoreMounts)&&(d=zi.get(c))&&!d.overlay)return new We(d.tree,u,e,o);let p=new We(c,u,e,o);return r&X.IncludeAnonymous||!p.type.isAnonymous?p:p.nextChild(t<0?c.children.length-1:0,t,i,s,r)}}}if(r&X.IncludeAnonymous||!o.type.isAnonymous||(o.index>=0?e=o.index+t:e=t<0?-1:o._parent._tree.children.length,o=o._parent,!o))return null}}get firstChild(){return this.nextChild(0,1,0,4)}get lastChild(){return this.nextChild(this._tree.children.length-1,-1,0,4)}childAfter(e){return this.nextChild(0,1,e,2)}childBefore(e){return this.nextChild(this._tree.children.length-1,-1,e,-2)}prop(e){return this._tree.prop(e)}enter(e,t,i=0){let s;if(!(i&X.IgnoreOverlays)&&(s=zi.get(this._tree))&&s.overlay){let r=e-this.from,o=i&X.EnterBracketed&&s.bracketed;for(let{from:l,to:a}of s.overlay)if((t>0||o?l<=r:l<r)&&(t<0||o?a>=r:a>r))return new We(s.tree,s.overlay[0].from+this.from,-1,this)}return this.nextChild(0,1,e,t,i)}nextSignificantParent(){let e=this;for(;e.type.isAnonymous&&e._parent;)e=e._parent;return e}get parent(){return this._parent?this._parent.nextSignificantParent():null}get nextSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index+1,1,0,4):null}get prevSibling(){return this._parent&&this.index>=0?this._parent.nextChild(this.index-1,-1,0,4):null}get tree(){return this._tree}toTree(){return this._tree}toString(){return this._tree.toString()}}function oa(n,e,t,i){let s=n.cursor(),r=[];if(!s.firstChild())return r;if(t!=null){for(let o=!1;!o;)if(o=s.type.is(t),!s.nextSibling())return r}for(;;){if(i!=null&&s.type.is(i))return r;if(s.type.is(e)&&r.push(s.node),!s.nextSibling())return i==null?r:[]}}function eo(n,e,t=e.length-1){for(let i=n;t>=0;i=i.parent){if(!i)return!1;if(!i.type.isAnonymous){if(e[t]&&e[t]!=i.name)return!1;t--}}return!0}class xm{constructor(e,t,i,s){this.parent=e,this.buffer=t,this.index=i,this.start=s}}class vt extends Nc{get name(){return this.type.name}get from(){return this.context.start+this.context.buffer.buffer[this.index+1]}get to(){return this.context.start+this.context.buffer.buffer[this.index+2]}constructor(e,t,i){super(),this.context=e,this._parent=t,this.index=i,this.type=e.buffer.set.types[e.buffer.buffer[i]]}child(e,t,i){let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.context.start,i);return r<0?null:new vt(this.context,this,r)}get firstChild(){return this.child(1,0,4)}get lastChild(){return this.child(-1,0,4)}childAfter(e){return this.child(1,e,2)}childBefore(e){return this.child(-1,e,-2)}prop(e){return this.type.prop(e)}enter(e,t,i=0){if(i&X.ExcludeBuffers)return null;let{buffer:s}=this.context,r=s.findChild(this.index+4,s.buffer[this.index+3],t>0?1:-1,e-this.context.start,t);return r<0?null:new vt(this.context,this,r)}get parent(){return this._parent||this.context.parent.nextSignificantParent()}externalSibling(e){return this._parent?null:this.context.parent.nextChild(this.context.
vendor: 1,648 bytes, line 179
179index+e,e,0,4)}get nextSibling(){let{buffer:e}=this.context,t=e.buffer[this.index+3];return t<(this._parent?e.buffer[this._parent.index+3]:e.buffer.length)?new vt(this.context,this._parent,t):this.externalSibling(1)}get prevSibling(){let{buffer:e}=this.context,t=this._parent?this._parent.index+4:0;return this.index==t?this.externalSibling(-1):new vt(this.context,this._parent,e.findChild(t,this.index,-1,0,4))}get tree(){return null}toTree(){let e=[],t=[],{buffer:i}=this.context,s=this.index+4,r=i.buffer[this.index+3];if(r>s){let o=i.buffer[this.index+1];e.push(i.slice(s,r,o)),t.push(0)}return new ee(this.type,e,t,this.to-this.from)}toString(){return this.context.buffer.childString(this.index)}}function Bc(n){if(!n.length)return null;let e=0,t=n[0];for(let r=1;r<n.length;r++){let o=n[r];(o.from>t.from||o.to<t.to)&&(t=o,e=r)}let i=t instanceof We&&t.index<0?null:t.parent,s=n.slice();return i?s[e]=i:s.splice(e,1),new Sm(s,t)}class Sm{constructor(e,t){this.heads=e,this.node=t}get next(){return Bc(this.heads)}}function vm(n,e,t){let i=n.resolveInner(e,t),s=null;for(let r=i instanceof We?i:i.context.parent;r;r=r.parent)if(r.index<0){let o=r.parent;(s||(s=[i])).push(o.resolve(e,t)),r=o}else{let o=zi.get(r.tree);if(o&&o.overlay&&o.overlay[0].from<=e&&o.overlay[o.overlay.length-1].to>=e){let l=new We(o.tree,o.overlay[0].from+r.from,-1,r);(s||(s=[i])).push(Xi(l,e,t,!1))}}return s?Bc(s):i}class to{get name(){return this.type.name}constructor(e,t=0){if(this.buffer=null,this.stack=[],this.index=0,this.bufferNode=null,this.mode=t&~X.EnterBracketed,e instanceof We)this.yieldNode(e);else{this._tree=e.context.parent,this.buffer=e.context;
vendor: 14,507 bytes, line 179
179for(let i=e._parent;i;i=i._parent)this.stack.unshift(i.index);this.bufferNode=e,this.yieldBuf(e.index)}}yieldNode(e){return e?(this._tree=e,this.type=e.type,this.from=e.from,this.to=e.to,!0):!1}yieldBuf(e,t){this.index=e;let{start:i,buffer:s}=this.buffer;return this.type=t||s.set.types[s.buffer[e]],this.from=i+s.buffer[e+1],this.to=i+s.buffer[e+2],!0}yield(e){return e?e instanceof We?(this.buffer=null,this.yieldNode(e)):(this.buffer=e.context,this.yieldBuf(e.index,e.type)):!1}toString(){return this.buffer?this.buffer.buffer.childString(this.index):this._tree.toString()}enterChild(e,t,i){if(!this.buffer)return this.yield(this._tree.nextChild(e<0?this._tree._tree.children.length-1:0,e,t,i,this.mode));let{buffer:s}=this.buffer,r=s.findChild(this.index+4,s.buffer[this.index+3],e,t-this.buffer.start,i);return r<0?!1:(this.stack.push(this.index),this.yieldBuf(r))}firstChild(){return this.enterChild(1,0,4)}lastChild(){return this.enterChild(-1,0,4)}childAfter(e){return this.enterChild(1,e,2)}childBefore(e){return this.enterChild(-1,e,-2)}enter(e,t,i=this.mode){return this.buffer?i&X.ExcludeBuffers?!1:this.enterChild(1,e,t):this.yield(this._tree.enter(e,t,i))}parent(){if(!this.buffer)return this.yieldNode(this.mode&X.IncludeAnonymous?this._tree._parent:this._tree.parent);if(this.stack.length)return this.yieldBuf(this.stack.pop());let e=this.mode&X.IncludeAnonymous?this.buffer.parent:this.buffer.parent.nextSignificantParent();return this.buffer=null,this.yieldNode(e)}sibling(e){if(!this.buffer)return this._tree._parent?this.yield(this._tree.index<0?null:this._tree._parent.nextChild(this._tree.index+e,e,0,4,this.mode)):!1;let{buffer:t}=this.buffer,i=this.stack.length-1;if(e<0){let s=i<0?0:this.stack[i]+4;if(this.index!=s)return this.yieldBuf(t.findChild(s,this.index,-1,0,4))}else{let s=t.buffer[this.index+3];if(s<(i<0?t.buffer.length:t.buffer[this.stack[i]+3]))return this.yieldBuf(s)}return i<0?this.yield(this.buffer.parent.nextChild(this.buffer.index+e,e,0,4,this.mode)):!1}nextSibling(){return this.sibling(1)}prevSibling(){return this.sibling(-1)}atLastNode(e){let t,i,{buffer:s}=this;if(s){if(e>0){if(this.index<s.buffer.buffer.length)return!1}else for(let r=0;r<this.index;r++)if(s.buffer.buffer[r+3]<this.index)return!1;({index:t,parent:i}=s)}else({index:t,_parent:i}=this._tree);for(;i;{index:t,_parent:i}=i)if(t>-1)for(let r=t+e,o=e<0?-1:i._tree.children.length;r!=o;r+=e){let l=i._tree.children[r];if(this.mode&X.IncludeAnonymous||l instanceof Ot||!l.type.isAnonymous||Bo(l))return!1}return!0}move(e,t){if(t&&this.enterChild(e,0,4))return!0;for(;;){if(this.sibling(e))return!0;if(this.atLastNode(e)||!this.parent())return!1}}next(e=!0){return this.move(1,e)}prev(e=!0){return this.move(-1,e)}moveTo(e,t=0){for(;(this.from==this.to||(t<1?this.from>=e:this.from>e)||(t>-1?this.to<=e:this.to<e))&&this.parent(););for(;this.enterChild(1,e,t););return this}get node(){if(!this.buffer)return this._tree;let e=this.bufferNode,t=null,i=0;if(e&&e.context==this.buffer)e:for(let s=this.index,r=this.stack.length;r>=0;){for(let o=e;o;o=o._parent)if(o.index==s){if(s==this.index)return o;t=o,i=r+1;break e}s=this.stack[--r]}for(let s=i;s<this.stack.length;s++)t=new vt(this.buffer,t,this.stack[s]);return this.bufferNode=new vt(this.buffer,t,this.index)}get tree(){return this.buffer?null:this._tree._tree}iterate(e,t){for(let i=0;;){let s=!1;if(this.type.isAnonymous||e(this)!==!1){if(this.firstChild()){i++;continue}this.type.isAnonymous||(s=!0)}for(;;){if(s&&t&&t(this),s=this.type.isAnonymous,!i)return;if(this.nextSibling())break;this.parent(),i--,s=!0}}}matchContext(e){if(!this.buffer)return eo(this.node.parent,e);let{buffer:t}=this.buffer,{types:i}=t.set;for(let s=e.length-1,r=this.stack.length-1;s>=0;r--){if(r<0)return eo(this._tree,e,s);let o=i[t.buffer[this.stack[r]]];if(!o.isAnonymous){if(e[s]&&e[s]!=o.name)return!1;s--}}return!0}}function Bo(n){return n.children.some(e=>e instanceof Ot||!e.type.isAnonymous||Bo(e))}function km(n){var e;let{buffer:t,nodeSet:i,maxBufferLength:s=Lc,reused:r=[],minRepeatType:o=i.types.length}=n,l=Array.isArray(t)?new No(t,t.length):t,a=i.types,h=0,c=0;function u(x,T,v,I,z,q){let{id:D,start:O,end:B,size:_}=l,V=c,ve=h;if(_<0)if(l.next(),_==-1){let ge=r[D];v.push(ge),I.push(O-x);return}else if(_==-3){h=D;return}else if(_==-4){c=D;return}else throw new RangeError(`Unrecognized record size: ${_}`);let ke=a[D],Ve,Ie,$e=O-x;if(B-O<=s&&(Ie=g(l.pos-T,z))){let ge=new Uint16Array(Ie.size-Ie.skip),le=l.pos-Ie.size,J=ge.length;for(;l.pos>le;)J=y(Ie.start,ge,J);Ve=new Ot(ge,B-Ie.start,i),$e=Ie.start-x}else{let ge=l.pos-_;l.next();let le=[],J=[],Q=D>=o?D:-1,ue=0,as=B;for(;l.pos>ge;)Q>=0&&l.id==Q&&l.size>=0?(l.end<=as-s&&(p(le,J,O,ue,l.end,as,Q,V,ve),ue=le.length,as=l.end),l.next()):q>2500?f(O,ge,le,J):u(O,ge,le,J,Q,q+1);if(Q>=0&&ue>0&&ue<le.length&&p(le,J,O,ue,O,as,Q,V,ve),le.reverse(),J.reverse(),Q>-1&&ue>0){let Jo=d(ke,ve);Ve=_o(ke,le,J,0,le.length,0,B-O,Jo,Jo)}else Ve=m(ke,le,J,B-O,V-B,ve)}v.push(Ve),I.push($e)}function f(x,T,v,I){let z=[],q=0,D=-1;for(;l.pos>T;){let{id:O,start:B,end:_,size:V}=l;if(V>4)l.next();else{if(D>-1&&B<D)break;D<0&&(D=_-s),z.push(O,B,_),q++,l.next()}}if(q){let O=new Uint16Array(q*4),B=z[z.length-2];for(let _=z.length-3,V=0;_>=0;_-=3)O[V++]=z[_],O[V++]=z[_+1]-B,O[V++]=z[_+2]-B,O[V++]=V;v.push(new Ot(O,z[2]-B,i)),I.push(B-x)}}function d(x,T){return(v,I,z)=>{let q=0,D=v.length-1,O,B;if(D>=0&&(O=v[D])instanceof ee){if(!D&&O.type==x&&O.length==z)return O;(B=O.prop(N.lookAhead))&&(q=I[D]+O.length+B)}return m(x,v,I,z,q,T)}}function p(x,T,v,I,z,q,D,O,B){let _=[],V=[];for(;x.length>I;)_.push(x.pop()),V.push(T.pop()+v-z);x.push(m(i.types[D],_,V,q-z,O-q,B)),T.push(z-v)}function m(x,T,v,I,z,q,D){if(q){let O=[N.contextHash,q];D=D?[O].concat(D):[O]}if(z>25){let O=[N.lookAhead,z];D=D?[O].concat(D):[O]}return new ee(x,T,v,I,D)}function g(x,T){let v=l.fork(),I=0,z=0,q=0,D=v.end-s,O={size:0,start:0,skip:0};e:for(let B=v.pos-x;v.pos>B;){let _=v.size;if(v.id==T&&_>=0){O.size=I,O.start=z,O.skip=q,q+=4,I+=4,v.next();continue}let V=v.pos-_;if(_<0||V<B||v.start<D)break;let ve=v.id>=o?4:0,ke=v.start;for(v.next();v.pos>V;){if(v.size<0)if(v.size==-3||v.size==-4)ve+=4;else break e;else v.id>=o&&(ve+=4);v.next()}z=ke,I+=_,q+=ve}return(T<0||I==x)&&(O.size=I,O.start=z,O.skip=q),O.size>4?O:void 0}function y(x,T,v){let{id:I,start:z,end:q,size:D}=l;if(l.next(),D>=0&&I<o){let O=v;if(D>4){let B=l.pos-(D-4);for(;l.pos>B;)v=y(x,T,v)}T[--v]=O,T[--v]=q-x,T[--v]=z-x,T[--v]=I}else D==-3?h=I:D==-4&&(c=I);return v}let b=[],C=[];for(;l.pos>0;)u(n.start||0,n.bufferStart||0,b,C,-1,0);let k=(e=n.length)!==null&&e!==void 0?e:b.length?C[0]+b[0].length:0;return new ee(a[n.topID],b.reverse(),C.reverse(),k)}const la=new WeakMap;function Ws(n,e){if(!n.isAnonymous||e instanceof Ot||e.type!=n)return 1;let t=la.get(e);if(t==null){t=1;for(let i of e.children){if(i.type!=n||!(i instanceof ee)){t=1;break}t+=Ws(n,i)}la.set(e,t)}return t}function _o(n,e,t,i,s,r,o,l,a){let h=0;for(let p=i;p<s;p++)h+=Ws(n,e[p]);let c=Math.ceil(h*1.5/8),u=[],f=[];function d(p,m,g,y,b){for(let C=g;C<y;){let k=C,x=m[C],T=Ws(n,p[C]);for(C++;C<y;C++){let v=Ws(n,p[C]);if(T+v>=c)break;T+=v}if(C==k+1){if(T>c){let v=p[k];d(v.children,v.positions,0,v.children.length,m[k]+b);continue}u.push(p[k])}else{let v=m[C-1]+p[C-1].length-x;u.push(_o(n,p,m,k,C,x,v,null,a))}f.push(x+b-r)}}return d(e,t,i,s,0),(l||a)(u,f,o)}class Wt{constructor(e,t,i,s,r=!1,o=!1){this.from=e,this.to=t,this.tree=i,this.offset=s,this.open=(r?1:0)|(o?2:0)}get openStart(){return(this.open&1)>0}get openEnd(){return(this.open&2)>0}static addTree(e,t=[],i=!1){let s=[new Wt(0,e.length,e,0,!1,i)];for(let r of t)r.to>e.length&&s.push(r);return s}static applyChanges(e,t,i=128){if(!t.length)return e;let s=[],r=1,o=e.length?e[0]:null;for(let l=0,a=0,h=0;;l++){let c=l<t.length?t[l]:null,u=c?c.fromA:1e9;if(u-a>=i)for(;o&&o.from<u;){let f=o;if(a>=f.from||u<=f.to||h){let d=Math.max(f.from,a)-h,p=Math.min(f.to,u)-h;f=d>=p?null:new Wt(d,p,f.tree,f.offset+h,l>0,!!c)}if(f&&s.push(f),o.to>u)break;o=r<e.length?e[r++]:null}if(!c)break;a=c.toA,h=c.toA-c.toB}return s}}let _c=class{startParse(e,t,i){return typeof e=="string"&&(e=new Tm(e)),i=i?i.length?i.map(s=>new er(s.from,s.to)):[new er(0,0)]:[new er(0,e.length)],this.createParse(e,t||[],i)}parse(e,t,i){let s=this.startParse(e,t,i);for(;;){let r=s.advance();if(r)return r}}};class Tm{constructor(e){this.string=e}get length(){return this.string.length}chunk(e){return this.string.slice(e)}get lineChunks(){return!1}read(e,t){return this.string.slice(e,t)}}new N({perNode:!0});let Am=0;class Be{constructor(e,t,i,s){this.name=e,this.set=t,this.base=i,this.modified=s,this.id=Am++}toString(){let{name:e}=this;for(let t of this.modified)t.name&&(e=`${t.name}(${e})`);return e}static define(e,t){let i=typeof e=="string"?e:"?";if(e instanceof Be&&(t=e),t?.base)throw new Error("Can not derive from a modified tag");let s=new Be(i,[],null,[]);if(s.set.push(s),t)for(let r of t.set)s.set.push(r);return s}static defineModifier(e){let t=new sn(e);return i=>i.modified.indexOf(t)>-1?i:sn.get(i.base||i,i.modified.concat(t).sort((s,r)=>s.id-r.id))}}let Mm=0;class sn{constructor(e){this.name=e,this.instances=[],this.id=Mm++}static get(e,t){if(!t.length)return e;let i=t[0].instances.find(l=>l.base==e&&Em(t,l.modified));if(i)return i;let s=[],r=new Be(e.name,s,e,t);for(let l of t)l.instances.push(r);let o=Om(t);for(let l of e.set)if(!l.modified.length)for(let a of o)s.push(sn.get(l,a));return r}}function Em(n,e){return n.length==e.length&&n.every((t,i)=>t==e[i])}function Om(n){let e=[[]];for(let t=0;t<n.length;t++)for(let i=0,s=e.length;i<s;i++)e.push(e[i].concat(n[t]));return e.sort((t,i)=>i.length-t.length)}function Pc(n){let e=Object.create(null);for(let t in n){let i=n[t];Array.isArray(i)||(i=[i]);for(let s of t.split(" "))if(s){let r=[],o=2,l=s;for(let u=0;;){if(l=="..."&&u>0&&u+3==s.length){o=1;break}let f=/^"(?:[^"\\]|\\.)*?"|[^\/!]+/.exec(l);if(!f)throw new RangeError("Invalid path: "+s);if(r.push(f[0]=="*"?"":f[0][0]=='"'?JSON.parse(f[0]):f[0]),u+=f[0].length,u==s.length)break;let d=s[u++];if(u==s.length&&d=="!"){o=0;break}if(d!="/")throw new RangeError("Invalid path: "+s);l=s.slice(u)}let a=r.length-1,h=r[a];if(!h)throw new RangeError("Invalid path: "+s);let c=new Yi(i,o,a>0?r.slice(0,a):null);e[h]=c.sort(e[h])}}return Fc.add(e)}const Fc=new N({combine(n,e){let t,i,s;for(;n||e;){if(!n||e&&n.depth>=e.depth?(s=e,e=e.next):(s=n,n=n.next),t&&t.mode==s.mode&&!s.context&&!t.context)continue;let r=new Yi(s.tags,s.mode,s.context);t?t.next=r:i=r,t=r}return i}});class Yi{constructor(e,t,i,s){this.tags=e,this.mode=t,this.context=i,this.next=s}get opaque(){return this.mode==0}get inherit(){return this.mode==1}sort(e){return!e||e.depth<this.depth?(this.next=e,this):(e.next=this.sort(e.next),e)}get depth(){return this.context?this.context.length:0}}Yi.empty=new Yi([],2,null);function Hc(n,e){let t=Object.create(null);for(let r of n)if(!Array.isArray(r.tag))t[r.tag.id]=r.class;else for(let o of r.tag)t[o.id]=r.class;let{scope:i,all:s=null}=e||{};return{style:r=>{let o=s;for(let l of r)for(let a of l.set){let h=t[a.id];if(h){o=o?o+" "+h:h;break}}return o},scope:i}}function Dm(n,e){let t=null;for(let i of n){let s=i.style(e);s&&(t=t?t+" "+s:s)}return t}function Rm(n,e,t,i=0,s=n.length){let r=new Lm(i,Array.isArray(e)?e:[e],t);r.highlightRange(n.cursor(),i,s,"",r.highlighters),r.flush(s)}class Lm{constructor(e,t,i){this.at=e,this.highlighters=t,this.span=i,this.class=""}startSpan(e,t){t!=this.class&&(this.flush(e),e>this.at&&(this.at=e),this.class=t)}flush(e){e>this.at&&this.class&&this.span(this.at,e,this.class)}highlightRange(e,t,i,s,r){let{type:o,from:l,to:a}=e;if(l>=i||a<=t)return;o.isTop&&(r=this.highlighters.filter(d=>!d.scope||d.scope(o)));let h=s,c=Im(e)||Yi.empty,u=Dm(r,c.tags);if(u&&(h&&(h+=" "),h+=u,c.mode==1&&(s+=(s?" ":"")+u)),this.startSpan(Math.max(t,l),h),c.opaque)return;let f=e.tree&&e.tree.prop(N.mounted);if(f&&f.overlay){let d=e.node.enter(f.overlay[0].from+l,1),p=this.highlighters.filter(g=>!g.scope||g.scope(f.tree.type)),m=e.firstChild();for(let g=0,y=l;;g++){let b=g<f.overlay.length?f.overlay[g]:null,C=b?b.from+l:a,k=Math.max(t,y),x=Math.min(i,C);if(k<x&&m)for(;e.from<x&&(this.highlightRange(e,k,x,s,r),this.startSpan(Math.min(x,e.to),h),!(e.to>=C||!e.nextSibling())););if(!b||C>i)break;y=b.to+l,y>t&&(this.highlightRange(d.cursor(),Math.max(t,b.from+l),Math.min(i,y),"",p),this.startSpan(Math.min(i,y),h))}m&&e.parent()}else if(e.firstChild()){f&&(s="");do if(!(e.to<=t)){if(e.from>=i)break;this.highlightRange(e,t,i,s,r),this.startSpan(Math.min(i,e.to),h)}while(e.nextSibling());e.parent()}}}function Im(n){let e=n.type.prop(Fc);for(;e&&e.context&&!n.matchContext(e.context);)e=e.next;return e||null}const S=Be.define,Ms=S(),wt=S(),aa=S(wt),ha=S(wt),Ct=S(),Es=S(Ct),tr=S(Ct),nt=S(),Rt=S(nt),it=S(),st=S(),io=S(),Ai=S(io),Os=S(),M={comment:Ms,lineComment:S(Ms),blockComment:S(Ms),docComment:S(Ms),name:wt,variableName:S(wt),typeName:aa,tagName:S(aa),propertyName:ha,attributeName:S(ha),className:S(wt),labelName:S(wt),namespace:S(wt),macroName:S(wt),literal:Ct,string:Es,docString:S(Es),character:S(Es),attributeValue:S(Es),number:tr,integer:S(tr),float:S(tr),bool:S(Ct),regexp:S(Ct),escape:S(Ct),color:S(Ct),url:S(Ct),keyword:it,self:S(it),null:S(it),atom:S(it),unit:S(it),modifier:S(it),operatorKeyword:S(it),controlKeyword:S(it),definitionKeyword:S(it),moduleKeyword:S(it),operator:st,derefOperator:S(st),arithmeticOperator:S(st),logicOperator:S(st),bitwiseOperator:S(st),compareOperator:S(st),updateOperator:S(st),definitionOperator:S(st),typeOperator:S(st),controlOperator:S(st),punctuation:io,separator:S(io),bracket:Ai,angleBracket:S(Ai),squareBracket:S(Ai),paren:S(Ai),brace:S(Ai),content:nt,heading:Rt,heading1:S(Rt),heading2:S(Rt),heading3:S(Rt),heading4:S(Rt),heading5:S(Rt),heading6:S(Rt),contentSeparator:S(nt),list:S(nt),quote:S(nt),emphasis:S(nt),strong:S(nt),link:S(nt),monospace:S(nt),strikethrough:S(nt),inserted:S(),deleted:S(),changed:S(),invalid:S(),meta:Os,documentMeta:S(Os),annotation:S(Os),processingInstruction:S(Os),definition:Be.defineModifier("definition"),constant:Be.defineModifier("constant"),function:Be.defineModifier("function"),standard:Be.defineModifier("standard"),local:Be.defineModifier("local"),special:Be.defineModifier("special")};for(let n in M){let e=M[n];e instanceof Be&&(e.name=n)}Hc([{tag:M.link,class:"tok-link"},{tag:M.heading,class:"tok-heading"},{tag:M.emphasis,class:"tok-emphasis"},{tag:M.strong,class:"tok-strong"}
179,{tag:M.keyword,class:"tok-keyword"},{tag:M.atom,class:"tok-atom"},{tag:M.bool,class:"tok-bool"},{tag:M.url,class:"tok-url"},{tag:M.labelName,class:"tok-labelName"},{tag:M.inserted,class:"tok-inserted"},{tag:M.deleted,class:"tok-deleted"},{tag:M.literal,class:"tok-literal"},{tag:M.string,class:"tok-string"},{tag:M.number,class:"tok-number"},{tag:[M.regexp,M.escape,M.special(M.string)],class:"tok-string2"},{tag:M.variableName,class:"tok-variableName"},{tag:M.local(M.variableName),class:"tok-variableName tok-local"},{tag:M.definition(M.variableName),class:"tok-variableName tok-definition"},{tag:M.special(M.variableName),class:"tok-variableName2"},{tag:M.definition(M.propertyName),class:"tok-propertyName tok-definition"},{tag:M.typeName,class:"tok-typeName"},{tag:M.namespace,class:"tok-namespace"},{tag:M.className,class:"tok-className"},{tag:M.macroName,class:"tok-macroName"},{tag:M.propertyName,class:"tok-propertyName"},{tag:M.operator,class:"tok-operator"},{tag:M.comment,class:"tok-comment"},{tag:M.meta,class:"tok-meta"},{tag:M.invalid,class:"tok-invalid"},{tag:M.punctuation,class:"tok-punctuation"}]);var ir;const ei=new N;function Nm(n){return E.define({combine:n?e=>e.concat(n):void 0})}const Bm=new N;
vendor: 16,429 bytes, line 179
179class je{constructor(e,t,i=[],s=""){this.data=e,this.name=s,W.prototype.hasOwnProperty("tree")||Object.defineProperty(W.prototype,"tree",{get(){return Le(this)}}),this.parser=t,this.extension=[bi.of(this),W.languageData.of((r,o,l)=>{let a=ca(r,o,l),h=a.type.prop(ei);if(!h)return[];let c=r.facet(h),u=a.type.prop(Bm);if(u){let f=a.resolve(o-a.from,l);for(let d of u)if(d.test(f,r)){let p=r.facet(d.facet);return d.type=="replace"?p:p.concat(c)}}return c})].concat(i)}isActiveAt(e,t,i=-1){return ca(e,t,i).type.prop(ei)==this.data}findRegions(e){let t=e.facet(bi);if(t?.data==this.data)return[{from:0,to:e.doc.length}];if(!t||!t.allowsNesting)return[];let i=[],s=(r,o)=>{if(r.prop(ei)==this.data){i.push({from:o,to:o+r.length});return}let l=r.prop(N.mounted);if(l){if(l.tree.prop(ei)==this.data){if(l.overlay)for(let a of l.overlay)i.push({from:a.from+o,to:a.to+o});else i.push({from:o,to:o+r.length});return}else if(l.overlay){let a=i.length;if(s(l.tree,l.overlay[0].from+o),i.length>a)return}}for(let a=0;a<r.children.length;a++){let h=r.children[a];h instanceof ee&&s(h,r.positions[a]+o)}};return s(Le(e),0),i}get allowsNesting(){return!0}}je.setState=H.define();function ca(n,e,t){let i=n.facet(bi),s=Le(n).topNode;if(!i||i.allowsNesting)for(let r=s;r;r=r.enter(e,t,X.ExcludeBuffers|X.EnterBracketed))r.type.isTop&&(s=r);return s}class nn extends je{constructor(e,t,i){super(e,t,[],i),this.parser=t}static define(e){let t=Nm(e.languageData);return new nn(t,e.parser.configure({props:[ei.add(i=>i.isTop?t:void 0)]}),e.name)}configure(e,t){return new nn(this.data,this.parser.configure(e),t||this.name)}get allowsNesting(){return this.parser.hasWrappers()}}function Le(n){let e=n.field(je.state,!1);return e?e.tree:ee.empty}class _m{constructor(e){this.doc=e,this.cursorPos=0,this.string="",this.cursor=e.iter()}get length(){return this.doc.length}syncTo(e){return this.string=this.cursor.next(e-this.cursorPos).value,this.cursorPos=e+this.string.length,this.cursorPos-this.string.length}chunk(e){return this.syncTo(e),this.string}get lineChunks(){return!0}read(e,t){let i=this.cursorPos-this.string.length;return e<i||t>=this.cursorPos?this.doc.sliceString(e,t):this.string.slice(e-i,t-i)}}let Mi=null;class rn{constructor(e,t,i=[],s,r,o,l,a){this.parser=e,this.state=t,this.fragments=i,this.tree=s,this.treeLen=r,this.viewport=o,this.skipped=l,this.scheduleOn=a,this.parse=null,this.tempSkipped=[]}static create(e,t,i){return new rn(e,t,[],ee.empty,0,i,[],null)}startParse(){return this.parser.startParse(new _m(this.state.doc),this.fragments)}work(e,t){return t!=null&&t>=this.state.doc.length&&(t=void 0),this.tree!=ee.empty&&this.isDone(t??this.state.doc.length)?(this.takeTree(),!0):this.withContext(()=>{var i;if(typeof e=="number"){let s=Date.now()+e;e=()=>Date.now()>s}for(this.parse||(this.parse=this.startParse()),t!=null&&(this.parse.stoppedAt==null||this.parse.stoppedAt>t)&&t<this.state.doc.length&&this.parse.stopAt(t);;){let s=this.parse.advance();if(s)if(this.fragments=this.withoutTempSkipped(Wt.addTree(s,this.fragments,this.parse.stoppedAt!=null)),this.treeLen=(i=this.parse.stoppedAt)!==null&&i!==void 0?i:this.state.doc.length,this.tree=s,this.parse=null,this.treeLen<(t??this.state.doc.length))this.parse=this.startParse();else return!0;if(e())return!1}})}takeTree(){let e,t;this.parse&&(e=this.parse.parsedPos)>=this.treeLen&&((this.parse.stoppedAt==null||this.parse.stoppedAt>e)&&this.parse.stopAt(e),this.withContext(()=>{for(;!(t=this.parse.advance()););}),this.treeLen=e,this.tree=t,this.fragments=this.withoutTempSkipped(Wt.addTree(this.tree,this.fragments,!0)),this.parse=null)}withContext(e){let t=Mi;Mi=this;try{return e()}finally{Mi=t}}withoutTempSkipped(e){for(let t;t=this.tempSkipped.pop();)e=ua(e,t.from,t.to);return e}changes(e,t){let{fragments:i,tree:s,treeLen:r,viewport:o,skipped:l}=this;if(this.takeTree(),!e.empty){let a=[];if(e.iterChangedRanges((h,c,u,f)=>a.push({fromA:h,toA:c,fromB:u,toB:f})),i=Wt.applyChanges(i,a),s=ee.empty,r=0,o={from:e.mapPos(o.from,-1),to:e.mapPos(o.to,1)},this.skipped.length){l=[];for(let h of this.skipped){let c=e.mapPos(h.from,1),u=e.mapPos(h.to,-1);c<u&&l.push({from:c,to:u})}}}return new rn(this.parser,t,i,s,r,o,l,this.scheduleOn)}updateViewport(e){if(this.viewport.from==e.from&&this.viewport.to==e.to)return!1;this.viewport=e;let t=this.skipped.length;for(let i=0;i<this.skipped.length;i++){let{from:s,to:r}=this.skipped[i];s<e.to&&r>e.from&&(this.fragments=ua(this.fragments,s,r),this.skipped.splice(i--,1))}return this.skipped.length>=t?!1:(this.reset(),!0)}reset(){this.parse&&(this.takeTree(),this.parse=null)}skipUntilInView(e,t){this.skipped.push({from:e,to:t})}static getSkippingParser(e){return new class extends _c{createParse(t,i,s){let r=s[0].from,o=s[s.length-1].to;return{parsedPos:r,advance(){let a=Mi;if(a){for(let h of s)a.tempSkipped.push(h);e&&(a.scheduleOn=a.scheduleOn?Promise.all([a.scheduleOn,e]):e)}return this.parsedPos=o,new ee(Se.none,[],[],o-r)},stoppedAt:null,stopAt(){}}}}}isDone(e){e=Math.min(e,this.state.doc.length);let t=this.fragments;return this.treeLen>=e&&t.length&&t[0].from==0&&t[0].to>=e}static get(){return Mi}}function ua(n,e,t){return Wt.applyChanges(n,[{fromA:e,toA:t,fromB:e,toB:t}])}class yi{constructor(e){this.context=e,this.tree=e.tree}apply(e){if(!e.docChanged&&this.tree==this.context.tree)return this;let t=this.context.changes(e.changes,e.state),i=this.context.treeLen==e.startState.doc.length?void 0:Math.max(e.changes.mapPos(this.context.treeLen),t.viewport.to);return t.work(20,i)||t.takeTree(),new yi(t)}static init(e){let t=Math.min(3e3,e.doc.length),i=rn.create(e.facet(bi).parser,e,{from:0,to:t});return i.work(20,t)||i.takeTree(),new yi(i)}}je.state=Ke.define({create:yi.init,update(n,e){for(let t of e.effects)if(t.is(je.setState))return t.value;return e.startState.facet(bi)!=e.state.facet(bi)?yi.init(e.state):n.apply(e)}});let Wc=n=>{let e=setTimeout(()=>n(),500);return()=>clearTimeout(e)};typeof requestIdleCallback<"u"&&(Wc=n=>{let e=-1,t=setTimeout(()=>{e=requestIdleCallback(n,{timeout:400})},100);return()=>e<0?clearTimeout(t):cancelIdleCallback(e)});const sr=typeof navigator<"u"&&(!((ir=navigator.scheduling)===null||ir===void 0)&&ir.isInputPending)?()=>navigator.scheduling.isInputPending():null,Pm=Re.fromClass(class{constructor(e){this.view=e,this.working=null,this.workScheduled=0,this.chunkEnd=-1,this.chunkBudget=-1,this.work=this.work.bind(this),this.scheduleWork()}update(e){let t=this.view.state.field(je.state).context;(t.updateViewport(e.view.viewport)||this.view.viewport.to>t.treeLen)&&this.scheduleWork(),(e.docChanged||e.selectionSet)&&(this.view.hasFocus&&(this.chunkBudget+=50),this.scheduleWork()),this.checkAsyncSchedule(t)}scheduleWork(){if(this.working)return;let{state:e}=this.view,t=e.field(je.state);(t.tree!=t.context.tree||!t.context.isDone(e.doc.length))&&(this.working=Wc(this.work))}work(e){this.working=null;let t=Date.now();if(this.chunkEnd<t&&(this.chunkEnd<0||this.view.hasFocus)&&(this.chunkEnd=t+3e4,this.chunkBudget=3e3),this.chunkBudget<=0)return;let{state:i,viewport:{to:s}}=this.view,r=i.field(je.state);if(r.tree==r.context.tree&&r.context.isDone(s+1e5))return;let o=Date.now()+Math.min(this.chunkBudget,100,e&&!sr?Math.max(25,e.timeRemaining()-5):1e9),l=r.context.treeLen<s&&i.doc.length>s+1e3,a=r.context.work(()=>sr&&sr()||Date.now()>o,s+(l?0:1e5));this.chunkBudget-=Date.now()-t,(a||this.chunkBudget<=0)&&(r.context.takeTree(),this.view.dispatch({effects:je.setState.of(new yi(r.context))})),this.chunkBudget>0&&!(a&&!l)&&this.scheduleWork(),this.checkAsyncSchedule(r.context)}checkAsyncSchedule(e){e.scheduleOn&&(this.workScheduled++,e.scheduleOn.then(()=>this.scheduleWork()).catch(t=>De(this.view.state,t)).then(()=>this.workScheduled--),e.scheduleOn=null)}destroy(){this.working&&this.working()}isWorking(){return!!(this.working||this.workScheduled>0)}},{eventHandlers:{focus(){this.scheduleWork()}}}),bi=E.define({combine(n){return n.length?n[0]:null},enables:n=>[je.state,Pm,R.contentAttributes.compute([n],e=>{let t=e.facet(n);return t&&t.name?{"data-language":t.name}:{}})]});class Fm{constructor(e,t=[]){this.language=e,this.support=t,this.extension=[e,t]}}const Hm=E.define(),Po=E.define({combine:n=>{if(!n.length)return" ";let e=n[0];if(!e||/\S/.test(e)||Array.from(e).some(t=>t!=e[0]))throw new Error("Invalid indent unit: "+JSON.stringify(n[0]));return e}});function on(n){let e=n.facet(Po);return e.charCodeAt(0)==9?n.tabSize*e.length:e.length}function ln(n,e){let t="",i=n.tabSize,s=n.facet(Po)[0];if(s==" "){for(;e>=i;)t+=" ",e-=i;s=" "}for(let r=0;r<e;r++)t+=s;return t}function zc(n,e){n instanceof W&&(n=new Dn(n));for(let i of n.state.facet(Hm)){let s=i(n,e);if(s!==void 0)return s}let t=Le(n.state);return t.length>=e?Wm(n,t,e):null}class Dn{constructor(e,t={}){this.state=e,this.options=t,this.unit=on(e)}lineAt(e,t=1){let i=this.state.doc.lineAt(e),{simulateBreak:s,simulateDoubleBreak:r}=this.options;return s!=null&&s>=i.from&&s<=i.to?r&&s==e?{text:"",from:e}:(t<0?s<e:s<=e)?{text:i.text.slice(s-i.from),from:s}:{text:i.text.slice(0,s-i.from),from:i.from}:i}textAfterPos(e,t=1){if(this.options.simulateDoubleBreak&&e==this.options.simulateBreak)return"";let{text:i,from:s}=this.lineAt(e,t);return i.slice(e-s,Math.min(i.length,e+100-s))}column(e,t=1){let{text:i,from:s}=this.lineAt(e,t),r=this.countColumn(i,e-s),o=this.options.overrideIndentation?this.options.overrideIndentation(s):-1;return o>-1&&(r+=o-this.countColumn(i,i.search(/\S|$/))),r}countColumn(e,t=e.length){return kn(e,this.state.tabSize,t)}lineIndent(e,t=1){let{text:i,from:s}=this.lineAt(e,t),r=this.options.overrideIndentation;if(r){let o=r(s);if(o>-1)return o}return this.countColumn(i,i.search(/\S|$/))}get simulatedBreak(){return this.options.simulateBreak||null}}const Vc=new N;function Wm(n,e,t){let i=e.resolveStack(t),s=e.resolveInner(t,-1).resolve(t,0).enterUnfinishedNodesBefore(t);if(s!=i.node){let r=[];for(let o=s;o&&!(o.from<i.node.from||o.to>i.node.to||o.from==i.node.from&&o.type==i.node.type);o=o.parent)r.push(o);for(let o=r.length-1;o>=0;o--)i={node:r[o],next:i}}return $c(i,n,t)}function $c(n,e,t){for(let i=n;i;i=i.next){let s=Vm(i.node);if(s)return s(Fo.create(e,t,i))}return 0}function zm(n){return n.pos==n.options.simulateBreak&&n.options.simulateDoubleBreak}function Vm(n){let e=n.type.prop(Vc);if(e)return e;let t=n.firstChild,i;if(t&&(i=t.type.prop(N.closedBy))){let s=n.lastChild,r=s&&i.indexOf(s.name)>-1;return o=>Qm(o,!0,1,void 0,r&&!zm(o)?s.from:void 0)}return n.parent==null?$m:null}function $m(){return 0}class Fo extends Dn{constructor(e,t,i){super(e.state,e.options),this.base=e,this.pos=t,this.context=i}get node(){return this.context.node}static create(e,t,i){return new Fo(e,t,i)}get textAfter(){return this.textAfterPos(this.pos)}get baseIndent(){return this.baseIndentFor(this.node)}baseIndentFor(e){let t=this.state.doc.lineAt(e.from);for(;;){let i=e.resolve(t.from);for(;i.parent&&i.parent.from==i.from;)i=i.parent;if(Um(i,e))break;t=this.state.doc.lineAt(i.from)}return this.lineIndent(t.from)}continue(){return $c(this.context.next,this.base,this.pos)}}function Um(n,e){for(let t=e;t;t=t.parent)if(n==t)return!0;return!1}function qm(n){let e=n.node,t=e.childAfter(e.from),i=e.lastChild;if(!t)return null;let s=n.options.simulateBreak,r=n.state.doc.lineAt(t.from),o=s==null||s<=r.from?r.to:Math.min(r.to,s);for(let l=t.to;;){let a=e.childAfter(l);if(!a||a==i)return null;if(!a.type.isSkipped){if(a.from>=o)return null;let h=/^ */.exec(r.text.slice(t.to-r.from))[0].length;return{from:t.from,to:t.to+h}}l=a.to}}function Qm(n,e,t,i,s){let r=n.textAfter,o=r.match(/^\s*/)[0].length,l=i&&r.slice(o,o+i.length)==i||s==n.pos+o,a=qm(n);return a?l?n.column(a.from):n.column(a.to):n.baseIndent+(l?0:n.unit*t)}function jm({except:n,units:e=1}={}){return t=>{let i=n&&n.test(t.textAfter);return t.baseIndent+(i?0:e*t.unit)}}const Gm=new N;class Ho{constructor(e,t){this.specs=e;let i;function s(l){let a=At.newName();return(i||(i=Object.create(null)))["."+a]=l,a}const r=typeof t.all=="string"?t.all:t.all?s(t.all):void 0,o=t.scope;this.scope=o instanceof je?l=>l.prop(ei)==o.data:o?l=>l==o:void 0,this.style=Hc(e.map(l=>({tag:l.tag,class:l.class||s(Object.assign({},l,{tag:null}))})),{all:r}).style,this.module=i?new At(i):null,this.themeType=t.themeType}static define(e,t){return new Ho(e,t||{})}}const so=E.define(),Km=E.define({combine(n){return n.length?[n[0]]:null}});function nr(n){let e=n.facet(so);return e.length?e:n.facet(Km)}function Ib(n,e){let t=[Ym],i;return n instanceof Ho&&(n.module&&t.push(R.styleModule.of(n.module)),i=n.themeType),i?t.push(so.computeN([R.darkTheme],s=>s.facet(R.darkTheme)==(i=="dark")?[n]:[])):t.push(so.of(n)),t}class Xm{constructor(e){this.markCache=Object.create(null),this.tree=Le(e.state),this.decorations=this.buildDeco(e,nr(e.state)),this.decoratedTo=e.viewport.to}update(e){let t=Le(e.state),i=nr(e.state),s=i!=nr(e.startState),{viewport:r}=e.view,o=e.changes.mapPos(this.decoratedTo,1);t.length<r.to&&!s&&t.type==this.tree.type&&o>=r.to?(this.decorations=this.decorations.map(e.changes),this.decoratedTo=o):(t!=this.tree||e.viewportChanged||s)&&(this.tree=t,this.decorations=this.buildDeco(e.view,i),this.decoratedTo=r.to)}buildDeco(e,t){if(!t||!this.tree.length)return j.none;let i=new di;for(let{from:s,to:r}of e.visibleRanges)Rm(this.tree,t,(o,l,a)=>{i.add(o,l,this.markCache[a]||(this.markCache[a]=j.mark({class:a})))},s,r);return i.finish()}}const Ym=Ci.high(Re.fromClass(Xm,{decorations:n=>n.decorations})),Jm=1e4,Zm="()[]{}",eg=new N;function no(n,e,t){let i=n.prop(e<0?N.openedBy:N.closedBy);if(i)return i;if(n.name.length==1){let s=t.indexOf(n.name);if(s>-1&&s%2==(e<0?1:0))return[t[s+e]]}return null}function ro(n){let e=n.type.prop(eg);return e?e(n.node):n}function ti(n,e,t,i={}){let s=i.maxScanDistance||Jm,r=i.brackets||Zm,o=Le(n),l=o.resolveInner(e,t);for(let a=l;a;a=a.parent){let h=no(a.type,t,r);if(h&&a.from<a.to){let c=ro(a);if(c&&(t>0?e>=c.from&&e<c.to:e>c.from&&e<=c.to))return tg(n,e,t,a,c,h,r)}}return ig(n,e,t,o,l.type,s,r)}function tg(n,e,t,i,s,r,o){let l=i.parent,a={from:s.from,to:s.to},h=0,c=l?.cursor();if(c&&(t<0?c.childBefore(i.from):c.childAfter(i.to)))do if(t<0?c.to<=i.from:c.from>=i.to){if(h==0&&r.indexOf(c.type.name)>-1&&c.from<c.to){let u=ro(c);return{start:a,end:u?{from:u.from,to:u.to}:void 0,matched:!0}}else if(no(c.type,t,o))h++;else if(no(c.type,-t,o)){if(h==0){let u=ro(c);return{start:a,end:u&&u.from<u.to?{from:u.from,to:u.to}:void 0,matched:!1}}h--}}while(t<0?c.prevSibling():c.nextSibling());return{start:a,matched:!1}}function ig(n,e,t,i,s,r,o){if(t<0?!e:e==n.doc.length)return null;let l=t<0?n.sliceDoc(e-1,e):n.sliceDoc(e,e+1),a=o.indexOf(l);if(a<0||a%2==0!=t>0)return null;let h={from:t<0?e-1:e,to:t>0?e+1:e},c=n.doc.iterRange(e,t>0?n.doc.length:0),u=0;for(let f=0;!c.next().done&&f<=r;){let d=c.value;t<0&&(f+=d.length);let p=e+f*t;for(let m=t>0?0:d.length-1,g=t>0?d.length:-1;m!=g;m+=t){let y=o.indexOf(d[m]);if(!(y<0||i.resolveInner(p+m,1).type!=s))if(y%2==0==t>0)u++;else{if(u==1)return{start:h,end:{from:p+m,to:p+m+1},matched:y>>1==a>>1};u--}}t>0&&(f+=d.length)}return c.done?{start:h,matched:!1}:null}const sg=Object.create(null),fa=[Se.none],da=[],pa=Object.create(null),ng=Object.create(null);for(let[n,e]of[["variable","variableName"],["variable-2","variableName.special"],["string-2","string.special"],["def","variableName.definition"],["tag","tagName"],["attribute","attributeName"],["type","typeName"],["builtin","variableName.standard"],["qualifier","modifier"],["error","invalid"],["header","heading"],["property","propertyName"]])ng[n]=rg(sg,e);function rr(n,e){da.indexOf(n)>-1||(da.push(n),console.warn(e))}function rg(n,e){let t=[];for(let l of e.split(" ")){let a=[];for(let h of l.split(".")){let c=n[h]||M[h];c?typeof c=="function"?a.length?a=a.map(c):rr(h,`Modifier ${h} used at start of tag`):a.length?rr(h,`Tag ${h} used as modifier`):a=Array.isArray(c)?c:[c]:rr(h,`Unknown highlighting tag ${h}`)}for(let h of a)t.push(h)}if(!t.length)return 0;let i=e.replace(/ /g,"_"),s=i+" "+t.map(l=>l.id),r=pa[s];if(r)return r.id;let o=pa[s]=Se.define({id:fa.length,name:i,props:[Pc({[i]:t})]});return fa.push(o),o.id}G.RTL,G.LTR;var ma={};class an{constructor(e,t,i,s,r,o,l,a,h,c=0,u){this.p=e,this.stack=t,this.state=i,this.reducePos=s,this.pos=r,this.score=o,this.buffer=l,this.bufferBase=a,this.curContext=h,this.lookAhead=c,this.parent=u}toString(){return`[${this.stack.filter((e,t)=>
179t%3==0).concat(this.state)}]@${this.pos}${this.score?"!"+this.score:""}`}static start(e,t,i=0){let s=e.parser.context;return new an(e,[],t,i,i,0,[],0,s?new ga(s,s.start):null,0,null)}get context(){return this.curContext?this.curContext.context:null}pushState(e,t){this.stack.push(this.state,t,this.bufferBase+this.buffer.length),this.state=e}reduce(e){var t;let i=e>>19,s=e&65535,{parser:r}=this.p,o=this.reducePos<this.pos-25&&this.setLookAhead(this.pos),l=r.dynamicPrecedence(s);if(l&&(this.score+=l),i==0){this.pushState(r.getGoto(this.state,s,!0),this.reducePos),s<r.minRepeatTerm&&this.storeNode(s,this.reducePos,this.reducePos,o?8:4,!0),this.reduceContext(s,this.reducePos);return}let a=this.stack.length-(i-1)*3-(e&262144?6:0),h=a?this.stack[a-2]:this.p.ranges[0].from,c=this.reducePos-h;c>=2e3&&!(!((t=this.p.parser.nodeSet.types[s])===null||t===void 0)&&t.isAnonymous)&&(h==this.p.lastBigReductionStart?(this.p.bigReductionCount++,this.p.lastBigReductionSize=c):this.p.lastBigReductionSize<c&&(this.p.bigReductionCount=1,this.p.lastBigReductionStart=h,this.p.lastBigReductionSize=c));let u=a?this.stack[a-1]:0,f=this.bufferBase+this.buffer.length-u;if(s<r.minRepeatTerm||e&131072){let d=r.stateFlag(this.state,1)?this.pos:this.reducePos;this.storeNode(s,h,d,f+4,!0)}if(e&262144)this.state=this.stack[a];else{let d=this.stack[a-3];this.state=r.getGoto(d,s,!0)}for(;this.stack.length>a;)this.stack.pop();this.reduceContext(s,h)}storeNode(e,t,i,s=4,r=!1){if(e==0&&(!this.stack.length||this.stack[this.stack.length-1]<this.buffer.length+this.bufferBase)){let o=this,l=this.buffer.length;if(l==0&&o.parent&&(l=o.bufferBase-o.parent.bufferBase,o=o.parent),l>0&&o.buffer[l-4]==0&&o.buffer[l-1]>-1){if(t==i)return;if(o.buffer[l-2]>=t){o.buffer[l-2]=i;return}}}if(!r||this.pos==i)this.buffer.push(e,t,i,s);else{let o=this.buffer.length;if(o>0&&(this.buffer[o-4]!=0||this.buffer[o-1]<0)){let l=!1;for(let a=o;a>0&&this.buffer[a-2]>i;a-=4)if(this.buffer[a-1]>=0){l=!0;break}if(l)for(;o>0&&this.buffer[o-2]>i;)this.buffer[o]=this.buffer[o-4],this.buffer[o+1]=this.buffer[o-3],this.buffer[o+2]=this.buffer[o-2],this.buffer[o+3]=this.buffer[o-1],o-=4,s>4&&(s-=4)}this.buffer[o]=e,this.buffer[o+1]=t,this.buffer[o+2]=i,this.buffer[o+3]=s}}shift(e,t,i,s){if(e&131072)this.pushState(e&65535,this.pos);else if((e&262144)==0){let r=e,{parser:o}=this.p;this.pos=s;let l=o.stateFlag(r,1);!l&&(s>i||t<=o.maxNode)&&(this.reducePos=s),this.pushState(r,l?i:Math.min(i,this.reducePos)),this.shiftContext(t,i),t<=o.maxNode&&this.buffer.push(t,i,s,4)}else this.pos=s,this.shiftContext(t,i),t<=this.p.parser.maxNode&&this.buffer.push(t,i,s,4)}apply(e,t,i,s){e&65536?this.reduce(e):this.shift(e,t,i,s)}useNode(e,t){let i=this.p.reused.length-1;(i<0||this.p.reused[i]!=e)&&(this.p.reused.push(e),i++);let s=this.pos;this.reducePos=this.pos=s+e.length,this.pushState(t,s),this.buffer.push(i,s,this.reducePos,-1),this.curContext&&this.updateContext(this.curContext.tracker.reuse(this.curContext.context,e,this,this.p.stream.reset(this.pos-e.length)))}split(){let e=this,t=e.buffer.length;for(;t>0&&e.buffer[t-2]>e.reducePos;)t-=4;let i=e.buffer.slice(t),s=e.bufferBase+t;for(;e&&s==e.bufferBase;)e=e.parent;return new an(this.p,this.stack.slice(),this.state,this.reducePos,this.pos,this.score,i,s,this.curContext,this.lookAhead,e)}recoverByDelete(e,t){let i=e<=this.p.parser.maxNode;i&&this.storeNode(e,this.pos,t,4),this.storeNode(0,this.pos,t,i?8:4),this.pos=this.reducePos=t,this.score-=190}canShift(e){for(let t=new og(this);;){let i=this.p.parser.stateSlot(t.state,4)||this.p.parser.hasAction(t.state,e);if(i==0)return!1;if((i&65536)==0)return!0;t.reduce(i)}}recoverByInsert(e){if(this.stack.length>=300)return[];let t=this.p.parser.nextStates(this.state);if(t.length>8||this.stack.length>=120){let s=[];for(let r=0,o;r<t.length;r+=2)(o=t[r+1])!=this.state&&this.p.parser.hasAction(o,e)&&s.push(t[r],o);if(this.stack.length<120)for(let r=0;s.length<8&&r<t.length;r+=2){let o=t[r+1];s.some((l,a)=>a&1&&l==o)||s.push(t[r],o)}t=s}let i=[];for(let s=0;s<t.length&&i.length<4;s+=2){let r=t[s+1];if(r==this.state)continue;let o=this.split();o.pushState(r,this.pos),o.storeNode(0,o.pos,o.pos,4,!0),o.shiftContext(t[s],this.pos),o.reducePos=this.pos,o.score-=200,i.push(o)}return i}forceReduce(){let{parser:e}=this.p,t=e.stateSlot(this.state,5);if((t&65536)==0)return!1;if(!e.validAction(this.state,t)){let i=t>>19,s=t&65535,r=this.stack.length-i*3;if(r<0||e.getGoto(this.stack[r],s,!1)<0){let o=this.findForcedReduction();if(o==null)return!1;t=o}this.storeNode(0,this.pos,this.pos,4,!0),this.score-=100}return this.reducePos=this.pos,this.reduce(t),!0}findForcedReduction(){let{parser:e}=this.p,t=[],i=(s,r)=>{if(!t.includes(s))return t.push(s),e.allActions(s,o=>{if(!(o&393216))if(o&65536){let l=(o>>19)-r;if(l>1){let a=o&65535,h=this.stack.length-l*3;if(h>=0&&e.getGoto(this.stack[h],a,!1)>=0)return l<<19|65536|a}}else{let l=i(o,r+1);if(l!=null)return l}})};return i(this.state,0)}forceAll(){for(;!this.p.parser.stateFlag(this.state,2);)if(!this.forceReduce()){this.storeNode(0,this.pos,this.pos,4,!0);break}return this}get deadEnd(){if(this.stack.length!=3)return!1;let{parser:e}=this.p;return e.data[e.stateSlot(this.state,1)]==65535&&!e.stateSlot(this.state,4)}restart(){this.storeNode(0,this.pos,this.pos,4,!0),this.state=this.stack[0],this.stack.length=0}sameState(e){if(this.state!=e.state||this.stack.length!=e.stack.length)return!1;for(let t=0;t<this.stack.length;t+=3)if(this.stack[t]!=e.stack[t])return!1;return!0}get parser(){return this.p.parser}dialectEnabled(e){return this.p.parser.dialect.flags[e]}shiftContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.shift(this.curContext.context,e,this,this.p.stream.reset(t)))}reduceContext(e,t){this.curContext&&this.updateContext(this.curContext.tracker.reduce(this.curContext.context,e,this,this.p.stream.reset(t)))}emitContext(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-3)&&this.buffer.push(this.curContext.hash,this.pos,this.pos,-3)}emitLookAhead(){let e=this.buffer.length-1;(e<0||this.buffer[e]!=-4)&&this.buffer.push(this.lookAhead,this.pos,this.pos,-4)}updateContext(e){if(e!=this.curContext.context){let t=new ga(this.curContext.tracker,e);t.hash!=this.curContext.hash&&this.emitContext(),this.curContext=t}}setLookAhead(e){return e<=this.lookAhead?!1:(this.emitLookAhead(),this.lookAhead=e,!0)}close(){this.curContext&&this.curContext.tracker.strict&&this.emitContext(),this.lookAhead>0&&this.emitLookAhead()}}class ga{constructor(e,t){this.tracker=e,this.context=t,this.hash=e.strict?e.hash(t):0}}class og{constructor(e){this.start=e,this.state=e.state,this.stack=e.stack,this.base=this.stack.length}reduce(e){let t=e&65535,i=e>>19;i==0?(this.stack==this.start.stack&&(this.stack=this.stack.slice()),this.stack.push(this.state,0,0
vendor: 16,083 bytes, line 179
179),this.base+=3):this.base-=(i-1)*3;let s=this.start.p.parser.getGoto(this.stack[this.base-3],t,!0);this.state=s}}class hn{constructor(e,t,i){this.stack=e,this.pos=t,this.index=i,this.buffer=e.buffer,this.index==0&&this.maybeNext()}static create(e,t=e.bufferBase+e.buffer.length){return new hn(e,t,t-e.bufferBase)}maybeNext(){let e=this.stack.parent;e!=null&&(this.index=this.stack.bufferBase-e.bufferBase,this.stack=e,this.buffer=e.buffer)}get id(){return this.buffer[this.index-4]}get start(){return this.buffer[this.index-3]}get end(){return this.buffer[this.index-2]}get size(){return this.buffer[this.index-1]}next(){this.index-=4,this.pos-=4,this.index==0&&this.maybeNext()}fork(){return new hn(this.stack,this.pos,this.index)}}function Ds(n,e=Uint16Array){if(typeof n!="string")return n;let t=null;for(let i=0,s=0;i<n.length;){let r=0;for(;;){let o=n.charCodeAt(i++),l=!1;if(o==126){r=65535;break}o>=92&&o--,o>=34&&o--;let a=o-32;if(a>=46&&(a-=46,l=!0),r+=a,l)break;r*=46}t?t[s++]=r:t=new e(r)}return t}class zs{constructor(){this.start=-1,this.value=-1,this.end=-1,this.extended=-1,this.lookAhead=0,this.mask=0,this.context=0}}const ya=new zs;class lg{constructor(e,t){this.input=e,this.ranges=t,this.chunk="",this.chunkOff=0,this.chunk2="",this.chunk2Pos=0,this.next=-1,this.token=ya,this.rangeIndex=0,this.pos=this.chunkPos=t[0].from,this.range=t[0],this.end=t[t.length-1].to,this.readNext()}resolveOffset(e,t){let i=this.range,s=this.rangeIndex,r=this.pos+e;for(;r<i.from;){if(!s)return null;let o=this.ranges[--s];r-=i.from-o.to,i=o}for(;t<0?r>i.to:r>=i.to;){if(s==this.ranges.length-1)return null;let o=this.ranges[++s];r+=o.from-i.to,i=o}return r}clipPos(e){if(e>=this.range.from&&e<this.range.to)return e;for(let t of this.ranges)if(t.to>e)return Math.max(e,t.from);return this.end}peek(e){let t=this.chunkOff+e,i,s;if(t>=0&&t<this.chunk.length)i=this.pos+e,s=this.chunk.charCodeAt(t);else{let r=this.resolveOffset(e,1);if(r==null)return-1;if(i=r,i>=this.chunk2Pos&&i<this.chunk2Pos+this.chunk2.length)s=this.chunk2.charCodeAt(i-this.chunk2Pos);else{let o=this.rangeIndex,l=this.range;for(;l.to<=i;)l=this.ranges[++o];this.chunk2=this.input.chunk(this.chunk2Pos=i),i+this.chunk2.length>l.to&&(this.chunk2=this.chunk2.slice(0,l.to-i)),s=this.chunk2.charCodeAt(0)}}return i>=this.token.lookAhead&&(this.token.lookAhead=i+1),s}acceptToken(e,t=0){let i=t?this.resolveOffset(t,-1):this.pos;if(i==null||i<this.token.start)throw new RangeError("Token end out of bounds");this.token.value=e,this.token.end=i}acceptTokenTo(e,t){this.token.value=e,this.token.end=t}getChunk(){if(this.pos>=this.chunk2Pos&&this.pos<this.chunk2Pos+this.chunk2.length){let{chunk:e,chunkPos:t}=this;this.chunk=this.chunk2,this.chunkPos=this.chunk2Pos,this.chunk2=e,this.chunk2Pos=t,this.chunkOff=this.pos-this.chunkPos}else{this.chunk2=this.chunk,this.chunk2Pos=this.chunkPos;let e=this.input.chunk(this.pos),t=this.pos+e.length;this.chunk=t>this.range.to?e.slice(0,this.range.to-this.pos):e,this.chunkPos=this.pos,this.chunkOff=0}}readNext(){return this.chunkOff>=this.chunk.length&&(this.getChunk(),this.chunkOff==this.chunk.length)?this.next=-1:this.next=this.chunk.charCodeAt(this.chunkOff)}advance(e=1){for(this.chunkOff+=e;this.pos+e>=this.range.to;){if(this.rangeIndex==this.ranges.length-1)return this.setDone();e-=this.range.to-this.pos,this.range=this.ranges[++this.rangeIndex],this.pos=this.range.from}return this.pos+=e,this.pos>=this.token.lookAhead&&(this.token.lookAhead=this.pos+1),this.readNext()}setDone(){return this.pos=this.chunkPos=this.end,this.range=this.ranges[this.rangeIndex=this.ranges.length-1],this.chunk="",this.next=-1}reset(e,t){if(t?(this.token=t,t.start=e,t.lookAhead=e+1,t.value=t.extended=-1):this.token=ya,this.pos!=e){if(this.pos=e,e==this.end)return this.setDone(),this;for(;e<this.range.from;)this.range=this.ranges[--this.rangeIndex];for(;e>=this.range.to;)this.range=this.ranges[++this.rangeIndex];e>=this.chunkPos&&e<this.chunkPos+this.chunk.length?this.chunkOff=e-this.chunkPos:(this.chunk="",this.chunkOff=0),this.readNext()}return this}read(e,t){if(e>=this.chunkPos&&t<=this.chunkPos+this.chunk.length)return this.chunk.slice(e-this.chunkPos,t-this.chunkPos);if(e>=this.chunk2Pos&&t<=this.chunk2Pos+this.chunk2.length)return this.chunk2.slice(e-this.chunk2Pos,t-this.chunk2Pos);if(e>=this.range.from&&t<=this.range.to)return this.input.read(e,t);let i="";for(let s of this.ranges){if(s.from>=t)break;s.to>e&&(i+=this.input.read(Math.max(s.from,e),Math.min(s.to,t)))}return i}}class hi{constructor(e,t){this.data=e,this.id=t}token(e,t){let{parser:i}=t.p;hg(this.data,e,t,this.id,i.data,i.tokenPrecTable)}}hi.prototype.contextual=hi.prototype.fallback=hi.prototype.extend=!1;hi.prototype.fallback=hi.prototype.extend=!1;class ag{constructor(e,t={}){this.token=e,this.contextual=!!t.contextual,this.fallback=!!t.fallback,this.extend=!!t.extend}}function hg(n,e,t,i,s,r){let o=0,l=1<<i,{dialect:a}=t.p.parser;e:for(;(l&n[o])!=0;){let h=n[o+1];for(let d=o+3;d<h;d+=2)if((n[d+1]&l)>0){let p=n[d];if(a.allows(p)&&(e.token.value==-1||e.token.value==p||cg(p,e.token.value,s,r))){e.acceptToken(p);break}}let c=e.next,u=0,f=n[o+2];if(e.next<0&&f>u&&n[h+f*3-3]==65535){o=n[h+f*3-1];continue e}for(;u<f;){let d=u+f>>1,p=h+d+(d<<1),m=n[p],g=n[p+1]||65536;if(c<m)f=d;else if(c>=g)u=d+1;else{o=n[p+2],e.advance();continue e}}break}}function ba(n,e,t){for(let i=e,s;(s=n[i])!=65535;i++)if(s==t)return i-e;return-1}function cg(n,e,t,i){let s=ba(t,i,e);return s<0||ba(t,i,n)<s}const Te=typeof process<"u"&&ma&&/\bparse\b/.test(ma.LOG);let or=null;function wa(n,e,t){let i=n.cursor(X.IncludeAnonymous);for(i.moveTo(e);;)if(!(t<0?i.childBefore(e):i.childAfter(e)))for(;;){if((t<0?i.to<e:i.from>e)&&!i.type.isError)return t<0?Math.max(0,Math.min(i.to-1,e-25)):Math.min(n.length,Math.max(i.from+1,e+25));if(t<0?i.prevSibling():i.nextSibling())break;if(!i.parent())return t<0?0:n.length}}class ug{constructor(e,t){this.fragments=e,this.nodeSet=t,this.i=0,this.fragment=null,this.safeFrom=-1,this.safeTo=-1,this.trees=[],this.start=[],this.index=[],this.nextFragment()}nextFragment(){let e=this.fragment=this.i==this.fragments.length?null:this.fragments[this.i++];if(e){for(this.safeFrom=e.openStart?wa(e.tree,e.from+e.offset,1)-e.offset:e.from,this.safeTo=e.openEnd?wa(e.tree,e.to+e.offset,-1)-e.offset:e.to;this.trees.length;)this.trees.pop(),this.start.pop(),this.index.pop();this.trees.push(e.tree),this.start.push(-e.offset),this.index.push(0),this.nextStart=this.safeFrom}else this.nextStart=1e9}nodeAt(e){if(e<this.nextStart)return null;for(;this.fragment&&this.safeTo<=e;)this.nextFragment();if(!this.fragment)return null;for(;;){let t=this.trees.length-1;if(t<0)return this.nextFragment(),null;let i=this.trees[t],s=this.index[t];if(s==i.children.length){this.trees.pop(),this.start.pop(),this.index.pop();continue}let r=i.children[s],o=this.start[t]+i.positions[s];if(o>e)return this.nextStart=o,null;if(r instanceof ee){if(o==e){if(o<this.safeFrom)return null;let l=o+r.length;if(l<=this.safeTo){let a=r.prop(N.lookAhead);if(!a||l+a<this.fragment.to)return r}}this.index[t]++,o+r.length>=Math.max(this.safeFrom,e)&&(this.trees.push(r),this.start.push(o),this.index.push(0))}else this.index[t]++,this.nextStart=o+r.length}}}class fg{constructor(e,t){this.stream=t,this.tokens=[],this.mainToken=null,this.actions=[],this.tokens=e.tokenizers.map(i=>new zs)}getActions(e){let t=0,i=null,{parser:s}=e.p,{tokenizers:r}=s,o=s.stateSlot(e.state,3),l=e.curContext?e.curContext.hash:0,a=0;for(let h=0;h<r.length;h++){if((1<<h&o)==0)continue;let c=r[h],u=this.tokens[h];if(!(i&&!c.fallback)&&((c.contextual||u.start!=e.pos||u.mask!=o||u.context!=l)&&(this.updateCachedToken(u,c,e),u.mask=o,u.context=l),u.lookAhead>u.end+25&&(a=Math.max(u.lookAhead,a)),u.value!=0)){let f=t;if(u.extended>-1&&(t=this.addActions(e,u.extended,u.end,t)),t=this.addActions(e,u.value,u.end,t),!c.extend&&(i=u,t>f))break}}for(;this.actions.length>t;)this.actions.pop();return a&&e.setLookAhead(a),!i&&e.pos==this.stream.end&&(i=new zs,i.value=e.p.parser.eofTerm,i.start=i.end=e.pos,t=this.addActions(e,i.value,i.end,t)),this.mainToken=i,this.actions}getMainToken(e){if(this.mainToken)return this.mainToken;let t=new zs,{pos:i,p:s}=e;return t.start=i,t.end=Math.min(i+1,s.stream.end),t.value=i==s.stream.end?s.parser.eofTerm:0,t}updateCachedToken(e,t,i){let s=this.stream.clipPos(i.pos);if(t.token(this.stream.reset(s,e),i),e.value>-1){let{parser:r}=i.p;for(let o=0;o<r.specialized.length;o++)if(r.specialized[o]==e.value){let l=r.specializers[o](this.stream.read(e.start,e.end),i);if(l>=0&&i.p.parser.dialect.allows(l>>1)){(l&1)==0?e.value=l>>1:e.extended=l>>1;break}}}else e.value=0,e.end=this.stream.clipPos(s+1)}putAction(e,t,i,s){for(let r=0;r<s;r+=3)if(this.actions[r]==e)return s;return this.actions[s++]=e,this.actions[s++]=t,this.actions[s++]=i,s}addActions(e,t,i,s){let{state:r}=e,{parser:o}=e.p,{data:l}=o;for(let a=0;a<2;a++)for(let h=o.stateSlot(r,a?2:1);;h+=3){if(l[h]==65535)if(l[h+1]==1)h=ut(l,h+2);else{s==0&&l[h+1]==2&&(s=this.putAction(ut(l,h+2),t,i,s));break}l[h]==t&&(s=this.putAction(ut(l,h+1),t,i,s))}return s}}class dg{constructor(e,t,i,s){this.parser=e,this.input=t,this.ranges=s,this.recovering=0,this.nextStackID=9812,this.minStackPos=0,this.reused=[],this.stoppedAt=null,this.lastBigReductionStart=-1,this.lastBigReductionSize=0,this.bigReductionCount=0,this.stream=new lg(t,s),this.tokens=new fg(e,this.stream),this.topTerm=e.top[1];let{from:r}=s[0];this.stacks=[an.start(this,e.top[0],r)],this.fragments=i.length&&this.stream.end-r>e.bufferLength*4?new ug(i,e.nodeSet):null}get parsedPos(){return this.minStackPos}advance(){let e=this.stacks,t=this.minStackPos,i=this.stacks=[],s,r;if(this.bigReductionCount>300&&e.length==1){let[o]=e;for(;o.forceReduce()&&o.stack.length&&o.stack[o.stack.length-2]>=this.lastBigReductionStart;);this.bigReductionCount=this.lastBigReductionSize=0}for(let o=0;o<e.length;o++){let l=e[o];for(;;){if(this.tokens.mainToken=null,l.pos>t)i.push(l);else{if(this.advanceStack(l,i,e))continue;{s||(s=[],r=[]),s.push(l);let a=this.tokens.getMainToken(l);r.push(a.value,a.end)}}break}}if(!i.length){let o=s&&mg(s);if(o)return Te&&console.log("Finish with "+this.stackID(o)),this.stackToTree(o);if(this.parser.strict)throw Te&&s&&console.log("Stuck with token "+(this.tokens.mainToken?this.parser.getName(this.tokens.mainToken.value):"none")),new SyntaxError("No parse at "+t);this.recovering||(this.recovering=5)}if(this.recovering&&s){let o=this.stoppedAt!=null&&s[0].pos>this.stoppedAt?s[0]:this.runRecovery(s,r,i);if(o)return Te&&console.log("Force-finish "+this.stackID(o)),this.stackToTree(o.forceAll())}if(this.recovering){let o=this.recovering==1?1:this.recovering*3;if(i.length>o)for(i.sort((l,a)=>a.score-l.score);i.length>o;)i.pop();i.some(l=>l.reducePos>t)&&this.recovering--}else if(i.length>1){e:for(let o=0;o<i.length-1;o++){let l=i[o];for(let a=o+1;a<i.length;a++){let h=i[a];if(l.sameState(h)||l.buffer.length>500&&h.buffer.length>500)if((l.score-h.score||l.buffer.length-h.buffer.length)>0)i.splice(a--,1);else{i.splice(o--,1);continue e}}}i.length>12&&(i.sort((o,l)=>l.score-o.score),i.splice(12,i.length-12))}this.minStackPos=i[0].pos;for(let o=1;o<i.length;o++)i[o].pos<this.minStackPos&&(this.minStackPos=i[o].pos);return null}stopAt(e){if(this.stoppedAt!=null&&this.stoppedAt<e)throw new RangeError("Can't move stoppedAt forward");this.stoppedAt=e}advanceStack(e,t,i){let s=e.pos,{parser:r}=this,o=Te?this.stackID(e)+" -> ":"";if(this.stoppedAt!=null&&s>this.stoppedAt)return e.forceReduce()?e:null;if(this.fragments){let h=e.curContext&&e.curContext.tracker.strict,c=h?e.curContext.hash:0;for(let u=this.fragments.nodeAt(s);u;){let f=this.parser.nodeSet.types[u.type.id]==u.type?r.getGoto(e.state,u.type.id):-1;if(f>-1&&u.length&&(!h||(u.prop(N.contextHash)||0)==c))return e.useNode(u,f),Te&&console.log(o+this.stackID(e)+` (via reuse of ${r.getName(u.type.id)})`),!0;if(!(u instanceof ee)||u.children.length==0||u.positions[0]>0)break;let d=u.children[0];if(d instanceof ee&&u.positions[0]==0)u=d;else break}}let l=r.stateSlot(e.state,4);if(l>0)return e.reduce(l),Te&&console.log(o+this.stackID(e)+` (via always-reduce ${r.getName(l&65535)})`),!0;if(e.stack.length>=8400)for(;e.stack.length>6e3&&e.forceReduce(););let a=this.tokens.getActions(e);for(let h=0;h<a.length;){let c=a[h++],u=a[h++],f=a[h++],d=h==a.length||!i,p=d?e:e.split(),m=this.tokens.mainToken;if(p.apply(c,u,m?m.start:p.pos,f),Te&&console.log(o+this.stackID(p)+` (via ${(c&65536)==0?"shift":`reduce of ${r.getName(c&65535)}`} for ${r.getName(u)} @ ${s}${p==e?"":", split"})`),d)return!0;p.pos>s?t.push(p):i.push(p)}return!1}advanceFully(e,t){let i=e.pos;for(;;){if(!this.advanceStack(e,null,null))return!1;if(e.pos>i)return Ca(e,t),!0}}runRecovery(e,t,i){let s=null,r=!1;for(let o=0;o<e.length;o++){let l=e[o],a=t[o<<1],h=t[(o<<1)+1],c=Te?this.stackID(l)+" -> ":"";if(l.deadEnd&&(r||(r=!0,l.restart(),Te&&console.log(c+this.stackID(l)+" (restarted)"),this.advanceFully(l,i))))continue;let u=l.split(),f=c;for(let d=0;d<10&&u.forceReduce()&&(Te&&console.log(f+this.stackID(u)+" (via force-reduce)"),!this.advanceFully(u,i));d++)Te&&(f=this.stackID(u)+" -> ");for(let d of l.recoverByInsert(a))Te&&console.log(c+this.stackID(d)+" (via recover-insert)"),this.advanceFully(d,i);this.stream.end>l.pos?(h==l.pos&&(h++,a=0),l.recoverByDelete(a,h),Te&&console.log(c+this.stackID(l)+` (via recover-delete ${this.parser.getName(a)})`),Ca(l,i)):(!s||s.score<u.score)&&(s=u)}return s}stackToTree(e){return e.close(),ee.build({buffer:hn.create(e),nodeSet:this.parser.nodeSet,topID:this.topTerm,maxBufferLength:this.parser.bufferLength,reused:this.reused,start:this.ranges[0].from,length:e.pos-this.ranges[0].from,minRepeatType:this.parser.minRepeatTerm})}stackID(e){let t=(or||(or=new WeakMap)).get(e);return t||or.set(e,t=String.fromCodePoint(this.nextStackID++)),t+e}}function Ca(n,e){for(let t=0;t<e.length;t++){let i=e[t];if(i.pos==n.pos&&i.sameState(n)){e[t].score<n.score&&(e[t]=n);return}}e.push(n)}class pg{constructor(e,t,i){this.source=e,this.flags=t,this.disabled=i}allows(e){return!this.disabled||this.disabled[e]==0}}class cn extends _c{constructor(e){if(super(),this.wrappers=[],e.version!=14)throw new RangeError(`Parser version (${e.version}) doesn't match runtime version (14)`);let t=e.nodeNames.split(" ");this.minRepeatTerm=t.length;for(let l=0;l<e.repeatNodeCount;l++)t.push("");let i=Object.keys(e.topRules).map(l=>e.topRules[l][1]),s=[];for(let l=0;l<t.length;l++)s.push([]);function r(l,a,h){s[l].push([a,a.deserialize(String(h))])}if(e.nodeProps)for(let l of e.nodeProps){let a=l[0];typeof a=="string"&&(a=N[a]);for(let h=1;h<l.length;){let c=l[h++];if(c>=0)r(c,a,l[h++]);else{let u=l[h+-c];for(let f=-c;f>0;f--)r(l[h++],a,u);h++}}}this.nodeSet=new Io(t.map((l,a)=>Se.define({name:a>=this.minRepeatTerm?void 0:l,id:a,props:s[a],top:i.indexOf(a)>-1,error:a==0,skipped:e.skippedNodes&&e.skippedNodes.indexOf(a)>-1}))),e.propSources&&(this.nodeSet=this.nodeSet.extend(...e.propSources)),this.strict=!1,this.bufferLength=Lc;let o=Ds(e.tokenData);this.context=e.context,this.specializerSpecs=e.specialized||[],this.specialized=new Uint16Array(this.specializerSpecs.length);for(let l=0;l<this.specializerSpecs.length;l++)this.specialized[l]=this.specializerSpecs[l].term;this.specializers=this.specializerSpecs.map(xa),this.states=Ds(e.states,Uint32Array),this.data=Ds(e.stateData),this.goto=Ds(e.goto),this.maxTerm=e.maxTerm,this.tokenizers=e.tokenizers.map(l=>typeof l=="number"?new hi(o,l):l),this.topRules=e.topRules,this.dialects=e.dialects||{},this.dynamicPrecedences=e.dynamicPrecedences||null,this.tokenPrecTable=e.tokenPrec,this.termNames=e.termNames||null,this.maxNode=this.nodeSet.types.length-1,this.dialect=this.parseDialect(),this.top=this.topRules[Object.keys(this.topRules)[0]]}createParse(e,t,i){let s=new dg(this,e,t,i);for(let r of this.wrappers)s=r(s,e,t,i);return s}getGoto(e,t,i=!1){let s=this.goto;if(t>=s[0])return-1;for(let r=s[t+1];;){let o=s[r++],l=o&1,a=s[r++];if(l&&i)return a;for(let h=r+(o>>1);r<h;r++)if(s[r]==e)return a;
179if(l)return-1}}hasAction(e,t){let i=this.data;for(let s=0;s<2;s++)for(let r=this.stateSlot(e,s?2:1),o;;r+=3){if((o=i[r])==65535)if(i[r+1]==1)o=i[r=ut(i,r+2)];else{if(i[r+1]==2)return ut(i,r+2);break}if(o==t||o==0)return ut(i,r+1)}return 0}stateSlot(e,t){return this.states[e*6+t]}stateFlag(e,t){return(this.stateSlot(e,0)&t)>0}validAction(e,t){return!!this.allActions(e,i=>i==t?!0:null)}allActions(e,t){let i=this.stateSlot(e,4),s=i?t(i):void 0;for(let r=this.stateSlot(e,1);s==null;r+=3){if(this.data[r]==65535)if(this.data[r+1]==1)r=ut(this.data,r+2);else break;s=t(ut(this.data,r+1))}return s}nextStates(e){let t=[];for(let i=this.stateSlot(e,1);;i+=3){if(this.data[i]==65535)if(this.data[i+1]==1)i=ut(this.data,i+2);else break;if((this.data[i+2]&1)==0){let s=this.data[i+1];t.some((r,o)=>o&1&&r==s)||t.push(this.data[i],s)}}return t}configure(e){let t=Object.assign(Object.create(cn.prototype),this);if(e.props&&(t.nodeSet=this.nodeSet.extend(...e.props)),e.top){let i=this.topRules[e.top];if(!i)throw new RangeError(`Invalid top rule name ${e.top}`);t.top=i}return e.tokenizers&&(t.tokenizers=this.tokenizers.map(i=>{let s=e.tokenizers.find(r=>r.from==i);return s?s.to:i})),e.specializers&&(t.specializers=this.specializers.slice(),t.specializerSpecs=this.specializerSpecs.map((i,s)=>{let r=e.specializers.find(l=>l.from==i.external);if(!r)return i;let o=Object.assign(Object.assign({},i),{external:r.to});return t.specializers[s]=xa(o),o})),e.contextTracker&&(t.context=e.contextTracker),e.dialect&&(t.dialect=this.parseDialect(e.dialect)),e.strict!=null&&(t.strict=e.strict),e.wrap&&(t.wrappers=t.wrappers.concat(e.wrap)),e.bufferLength!=null&&(t.bufferLength=e.bufferLength),t}hasWrappers(){return this.wrappers.length>0}getName(e){return this.termNames?this.termNames[e]:String(e<=this.maxNode&&this.nodeSet.types[e].name||e)}get eofTerm(){return this.maxNode+1}get topNode(){return this.nodeSet.types[this.top[1]]}dynamicPrecedence(e){let t=this.dynamicPrecedences;return t==null?0:t[e]||0}parseDialect(e){let t=Object.keys(this.dialects),i=t.map(()=>!1);if(e)for(let r of e.split(" ")){let o=t.indexOf(r);o>=0&&(i[o]=!0)}let s=null;for(let r=0;r<t.length;r++)if(!i[r])for(let o=this.dialects[t[r]],l;(l=this.data[o++])!=65535;)(s||(s=new Uint8Array(this.maxTerm+1)))[l]=1;return new pg(e,i,s)}static deserialize(e){return new cn(e)}}function ut(n,e){return n[e]|n[e+1]<<16}function mg(n){let e=null;for(let t of n){let i=t.p.stoppedAt;(t.pos==t.p.stream.end||i!=null&&t.pos>i)&&t.p.parser.stateFlag(t.state,2)&&(!e||e.score<t.score)&&(e=t)}return e}function xa(n){if(n.external){let e=n.extend?1:0;return(t,i)=>n.external(t,i)<<1|e}return n.get}class Uc{constructor(e,t,i,s){this.state=e,this.pos=t,this.explicit=i,this.view=s,this.abortListeners=[],this.abortOnDocChange=!1}tokenBefore(e){let t=Le(this.state).resolveInner(this.pos,-1);for(;t&&e.indexOf(t.name)<0;)t=t.parent;return t?{from:t.from,to:this.pos,text:this.state.sliceDoc(t.from,this.pos),type:t.type}:null}matchBefore(e){let t=this.state.doc.lineAt(this.pos),i=Math.max(t.from,this.pos-250),s=t.text.slice(i-t.from,this.pos-t.from),r=s.search(Qc(e,!1));return r<0?null:{from:i+r,to:this.pos,text:s.slice(r)}}get aborted(){return this.abortListeners==null}addEventListener(e,t,i){e=="abort"&&this.abortListeners&&(this.abortListeners.push(t),i&&i.onDocChange&&(this.abortOnDocChange=!0))}}function Sa(n){let e=Object.keys(n).join(""),t=/\w/.test(e);return t&&(e=e.replace(/\w/g,"")),`[${t?"\\w":""}${e.replace(/[^\w\s]/g,"\\$&")}]`}function gg(n){let e=Object.create(null),t=Object.create(null);for(let{label:s}of n){e[s[0]]=!0;for(let r=1;r<s.length;r++)t[s[r]]=!0}let i=Sa(e)+Sa(t)+"*$";return[new RegExp("^"+i),new RegExp(i)]}function qc(n){let e=n.map(s=>typeof s=="string"?{label:s}:s),[t,i]=e.every(s=>/^\w+$/.test(s.label))?[/\w*$/,/\w+$/]:gg(e);return s=>{let r=s.matchBefore(i);return r||s.explicit?{from:r?r.from:s.pos,options:e,validFor:t}:null}}function yg(n,e){return t=>{for(let i=Le(t.state).resolveInner(t.pos,-1);i;i=i.parent){if(n.indexOf(i.name)>-1)return null;if(i.type.isTop)break}return e(t)}}class va{constructor(e,t,i,s){this.completion=e,this.source=t,this.match=i,this.score=s}}function zt(n){return n.selection.main.from}function Qc(n,e){var t;let{source:i}=n,s=e&&i[0]!="^",r=i[i.length-1]!="$";return!s&&!r?n:new RegExp(`${s?"^":""}(?:${i})${r?"$":""}`,(t=n.flags)!==null&&t!==void 0?t:n.ignoreCase?"i":"")}const jc=gt.define();function bg(n,e,t,i){let{main:s}=n.selection,r=t-s.from,o=i-s.from;return{...n.changeByRange(l=>{if(l!=s&&t!=i&&n.sliceDoc(l.from+r,l.from+o)!=n.sliceDoc(t,i))return{range:l};let a=n.toText(e);return{changes:{from:l.from+r,to:i==s.from?l.to:l.from+o,insert:a},range:w.cursor(l.from+r+a.length)}}),scrollIntoView:!0,userEvent:"input.complete"}}const ka=new WeakMap;function wg(n){if(!Array.isArray(n))return n;let e=ka.get(n);return e||ka.set(n,e=qc(n)),e}const un=H.define(),Ji=H.define();class Cg{constructor(e){this.pattern=e,this.chars=[],this.folded=[],this.any=[],this.precise=[],this.byWord=[],this.score=0,this.matched=[];for(let t=0;t<e.length;){let i=bt(e,t),s=Bt(i);this.chars.push(i);let r=e.slice(t,t+s),o=r.toUpperCase();this.folded.push(bt(o==r?r.toLowerCase():o,0)),t+=s}
vendor: 4,853 bytes, line 179
179this.astral=e.length!=this.chars.length}ret(e,t){return this.score=e,this.matched=t,this}match(e){if(this.pattern.length==0)return this.ret(-100,[]);if(e.length<this.pattern.length)return null;let{chars:t,folded:i,any:s,precise:r,byWord:o}=this;if(t.length==1){let b=bt(e,0),C=Bt(b),k=C==e.length?0:-100;if(b!=t[0])if(b==i[0])k+=-200;else return null;return this.ret(k,[0,C])}let l=e.indexOf(this.pattern);if(l==0)return this.ret(e.length==this.pattern.length?0:-100,[0,this.pattern.length]);let a=t.length,h=0;if(l<0){for(let b=0,C=Math.min(e.length,200);b<C&&h<a;){let k=bt(e,b);(k==t[h]||k==i[h])&&(s[h++]=b),b+=Bt(k)}if(h<a)return null}let c=0,u=0,f=!1,d=0,p=-1,m=-1,g=/[a-z]/.test(e),y=!0;for(let b=0,C=Math.min(e.length,200),k=0;b<C&&u<a;){let x=bt(e,b);l<0&&(c<a&&x==t[c]&&(r[c++]=b),d<a&&(x==t[d]||x==i[d]?(d==0&&(p=b),m=b+1,d++):d=0));let T,v=x<255?x>=48&&x<=57||x>=97&&x<=122?2:x>=65&&x<=90?1:0:(T=gh(x))!=T.toLowerCase()?1:T!=T.toUpperCase()?2:0;(!b||v==1&&g||k==0&&v!=0)&&(t[u]==x||i[u]==x&&(f=!0)?o[u++]=b:o.length&&(y=!1)),k=v,b+=Bt(x)}return u==a&&o[0]==0&&y?this.result(-100+(f?-200:0),o,e):d==a&&p==0?this.ret(-200-e.length+(m==e.length?0:-100),[0,m]):l>-1?this.ret(-700-e.length,[l,l+this.pattern.length]):d==a?this.ret(-900-e.length,[p,m]):u==a?this.result(-100+(f?-200:0)+-700+(y?0:-1100),o,e):t.length==2?null:this.result((s[0]?-700:0)+-200+-1100,s,e)}result(e,t,i){let s=[],r=0;for(let o of t){let l=o+(this.astral?Bt(bt(i,o)):1);r&&s[r-1]==o?s[r-1]=l:(s[r++]=o,s[r++]=l)}return this.ret(e-i.length,s)}}class xg{constructor(e){this.pattern=e,this.matched=[],this.score=0,this.folded=e.toLowerCase()}match(e){if(e.length<this.pattern.length)return null;let t=e.slice(0,this.pattern.length),i=t==this.pattern?0:t.toLowerCase()==this.folded?-200:null;return i==null?null:(this.matched=[0,t.length],this.score=i+(e.length==this.pattern.length?0:-100),this)}}const re=E.define({combine(n){return vn(n,{activateOnTyping:!0,activateOnCompletion:()=>!1,activateOnTypingDelay:100,selectOnOpen:!0,override:null,closeOnBlur:!0,maxRenderedOptions:100,defaultKeymap:!0,tooltipClass:()=>"",optionClass:()=>"",aboveCursor:!1,icons:!0,addToOptions:[],positionInfo:Sg,filterStrict:!1,compareCompletions:(e,t)=>(e.sortText||e.label).localeCompare(t.sortText||t.label),interactionDelay:75,updateSyncTime:100},{defaultKeymap:(e,t)=>e&&t,closeOnBlur:(e,t)=>e&&t,icons:(e,t)=>e&&t,tooltipClass:(e,t)=>i=>Ta(e(i),t(i)),optionClass:(e,t)=>i=>Ta(e(i),t(i)),addToOptions:(e,t)=>e.concat(t),filterStrict:(e,t)=>e||t})}});function Ta(n,e){return n?e?n+" "+e:n:e}function Sg(n,e,t,i,s,r){let o=n.textDirection==G.RTL,l=o,a=!1,h="top",c,u,f=e.left-s.left,d=s.right-e.right,p=i.right-i.left,m=i.bottom-i.top;if(l&&f<Math.min(p,d)?l=!1:!l&&d<Math.min(p,f)&&(l=!0),p<=(l?f:d))c=Math.max(s.top,Math.min(t.top,s.bottom-m))-e.top,u=Math.min(400,l?f:d);else{a=!0,u=Math.min(400,(o?e.right:s.right-e.left)-30);let b=s.bottom-e.bottom;b>=m||b>e.top?c=t.bottom-e.top:(h="bottom",c=e.bottom-t.top)}let g=(e.bottom-e.top)/r.offsetHeight,y=(e.right-e.left)/r.offsetWidth;return{style:`${h}: ${c/g}px; max-width: ${u/y}px`,class:"cm-completionInfo-"+(a?o?"left-narrow":"right-narrow":l?"left":"right")}}const Wo=H.define();function vg(n){let e=n.addToOptions.slice();return n.icons&&e.push({render(t){let i=document.createElement("div");return i.classList.add("cm-completionIcon"),t.type&&i.classList.add(...t.type.split(/\s+/g).map(s=>"cm-completionIcon-"+s)),i.setAttribute("aria-hidden","true"),i},position:20}),e.push({render(t,i,s,r){let o=document.createElement("span");o.className="cm-completionLabel";let l=t.displayLabel||t.label,a=0;for(let h=0;h<r.length;){let c=r[h++],u=r[h++];c>a&&o.appendChild(document.createTextNode(l.slice(a,c)));let f=o.appendChild(document.createElement("span"));f.appendChild(document.createTextNode(l.slice(c,u))),f.className="cm-completionMatchedText",a=u}return a<l.length&&o.appendChild(document.createTextNode(l.slice(a))),o},position:50},{render(t){if(!t.detail)return null;let i=document.createElement("span");return i.className="cm-completionDetail",i.textContent=t.detail,i},position:80}),e.sort((t,i)=>t.position-i.position).map(t=>t.render)}function lr(n,e,t){if(n<=t)return{from:0,to:n};if(e<0&&(e=0),e<=n>>1){let s=Math.floor(e/t);return{from:s*t,to:(s+1)*t}}let i=Math.floor((n-e)/t);return{from:n-(i+1)*t,to:n-i*t}}class kg{constructor(e,t,i){this.view=e,this.stateField=t,this.applyCompletion=i,this.info=null,this.infoDestroy=null,this.placeInfoReq={read:()=>this.measureInfo(),write:a=>this.placeInfo(a),key:this},this.space=null,this.currentClass="";let s=e.state.field(t),{options:r,selected:o}=s.open,l=e.state.facet(re);this.optionContent=vg(l),this.optionClass=l.optionClass,this.tooltipClass=l.tooltipClass,this.range=lr(r.length,o,l.maxRenderedOptions),this.dom=document.createElement("div"),this.dom.className="
179cm-tooltip-autocomplete",this.updateTooltipClass(e.state),this.dom.addEventListener("mousedown",a=>{let{options:h}=e.state.field(t).open;for(let c=a.target,u;c&&c!=this.dom;c=c.parentNode)if(c.nodeName=="LI"&&(u=/-(\d+)$/.exec(c.id))&&+u[1]<h.length){this.applyCompletion(e,h[+u[1]]),a.preventDefault();return}if(a.target==this.list){let c=this.list.classList.contains("cm-completionListIncompleteTop")&&a.clientY<this.list.firstChild.getBoundingClientRect().top?this.range.from-1:this.list.classList.contains("cm-completionListIncompleteBottom")&&a.clientY>this.list.lastChild.getBoundingClientRect().bottom?this.range.to:null;c!=null&&(e.dispatch({effects:Wo.of(c)}),a.preventDefault())}}),this.dom.addEventListener("focusout",a=>{let h=e.state.field(this.stateField,!1);h&&h.tooltip&&e.state.facet(re).closeOnBlur&&a.relatedTarget!=e.contentDOM&&e.dispatch({effects:Ji.of(null)})}),this.showOptions(r,s.id)}mount(){this.updateSel()}showOptions(e,t){this.list&&this.list.remove(),this.list=this.dom.appendChild(this.createListBox(e,t,this.range)),this.list.addEventListener("scroll",()=>{this.info&&this.view.requestMeasure(this.placeInfoReq)})}update(e){var t;let i=e.state.field(this.stateField),s=e.startState.field(this.stateField);if(this.updateTooltipClass(e.state),i!=s){let{options:r,selected:o,disabled:l}=i.open;(!s.open||s.open.options!=r)&&(this.range=lr(r.length,o,e.state.facet(re).maxRenderedOptions),this.showOptions(r,i.id)),this.updateSel(),l!=((t=s.open)===null||t===void 0?void 0:t.disabled)&&this.dom.classList.toggle("cm-tooltip-autocomplete-disabled",!!l)}}updateTooltipClass(e){let t=this.tooltipClass(e);if(t!=this.currentClass){for(let i of this.currentClass.split(" "))i&&this.dom.classList.remove(i);for(let i of t.split(" "))i&&this.dom.classList.add(i);this.currentClass=t}}positioned(e){this.space=e,this.info&&this.view.requestMeasure(this.placeInfoReq)}updateSel(){let e=this.view.state.field(this.stateField),t=e.open;(t.selected>-1&&t.selected<this.range.from||t.selected>=this.range.to)&&(this.range=lr(t.options.length,t.selected,this.view.state.facet(re).maxRenderedOptions),this.showOptions(t.options,e.id));let i=this.updateSelectedOption(t.selected);if(i){this.destroyInfo();
vendor: 4,152 bytes, line 179
179let{completion:s}=t.options[t.selected],{info:r}=s;if(!r)return;let o=typeof r=="string"?document.createTextNode(r):r(s);if(!o)return;"then"in o?o.then(l=>{l&&this.view.state.field(this.stateField,!1)==e&&this.addInfoPane(l,s)}).catch(l=>De(this.view.state,l,"completion info")):(this.addInfoPane(o,s),i.setAttribute("aria-describedby",this.info.id))}}addInfoPane(e,t){this.destroyInfo();let i=this.info=document.createElement("div");if(i.className="cm-tooltip cm-completionInfo",i.id="cm-completionInfo-"+Math.floor(Math.random()*65535).toString(16),e.nodeType!=null)i.appendChild(e),this.infoDestroy=null;else{let{dom:s,destroy:r}=e;i.appendChild(s),this.infoDestroy=r||null}this.dom.appendChild(i),this.view.requestMeasure(this.placeInfoReq)}updateSelectedOption(e){let t=null;for(let i=this.list.firstChild,s=this.range.from;i;i=i.nextSibling,s++)i.nodeName!="LI"||!i.id?s--:s==e?i.hasAttribute("aria-selected")||(i.setAttribute("aria-selected","true"),t=i):i.hasAttribute("aria-selected")&&(i.removeAttribute("aria-selected"),i.removeAttribute("aria-describedby"));return t&&Ag(this.list,t),t}measureInfo(){let e=this.dom.querySelector("[aria-selected]");if(!e||!this.info)return null;let t=this.dom.getBoundingClientRect(),i=this.info.getBoundingClientRect(),s=e.getBoundingClientRect(),r=this.space;if(!r){let o=this.dom.ownerDocument.documentElement;r={left:0,top:0,right:o.clientWidth,bottom:o.clientHeight}}return s.top>Math.min(r.bottom,t.bottom)-10||s.bottom<Math.max(r.top,t.top)+10?null:this.view.state.facet(re).positionInfo(this.view,t,s,i,r,this.dom)}placeInfo(e){this.info&&(e?(e.style&&(this.info.style.cssText=e.style),this.info.className="cm-tooltip cm-completionInfo "+(e.class||"")):this.info.style.cssText="top: -1e6px")}createListBox(e,t,i){const s=document.createElement("ul");s.id=t,s.setAttribute("role","listbox"),s.setAttribute("aria-expanded","true"),s.setAttribute("aria-label",this.view.state.phrase("Completions")),s.addEventListener("mousedown",o=>{o.target==s&&o.preventDefault()});let r=null;for(let o=i.from;o<i.to;o++){let{completion:l,match:a}=e[o],{section:h}=l;if(h){let f=typeof h=="string"?h:h.name;if(f!=r&&(o>i.from||i.from==0))if(r=f,typeof h!="string"&&h.header)s.appendChild(h.header(h));else{let d=s.appendChild(document.createElement("completion-section"));d.textContent=f}}const c=s.appendChild(document.createElement("li"));c.id=t+"-"+o,c.setAttribute("role","option");let u=this.optionClass(l);u&&(c.className=u);for(let f of this.optionContent){let d=f(l,this.view.state,this.view,a);d&&c.appendChild(d)}}return i.from&&s.classList.add("cm-completionListIncompleteTop"),i.to<e.length&&s.classList.add("cm-completionListIncompleteBottom"),s}destroyInfo(){this.info&&(this.infoDestroy&&this.infoDestroy(),this.info.remove(),this.info=null)}destroy(){this.destroyInfo()}}function Tg(n,e){return t=>new kg(t,n,e)}function Ag(n,e){let t=n.getBoundingClientRect(),i=e.getBoundingClientRect(),s=t.height/n.offsetHeight;i.top<t.top?n.scrollTop-=(t.top-i.top)/s:i.bottom>t.bottom&&(n.scrollTop+=(i.bottom-t.bottom)/s)}function Aa(n){return(n.boost||0)*100+(n.apply?10:0)+(n.info?5:0)+(n.type?1:0)}function Mg(n,e){let t=[],i=null,s=null,r=c=>{t.push(c);let{section:u}=c.completion;if(u){i||(i=[]);let f=typeof u=="string"?u:u.name;i.some(d=>d.name==f)||i.push(typeof u=="string"?{name:f}:u)}},o=e.facet(re);for(let c of n)if(c.hasResult()){let u=c.result.getMatch;if(c.result.filter===!1)for(let f of c.result.options)r(new va(f,c.source,u?u(f):[],1e9-t.length));else{let f=e.sliceDoc(c.from,c.to),d,p=o.filterStrict?new xg(f):new Cg(f);for(let m of c.result.options)if(d=p.match(m.label)){let g=m.displayLabel?u?u(m,d.matched):[]:d.matched,y=d.score+(m.boost||0);if(r(new va(m,c.source,g,y)),typeof m.section=="object"&&m.section.rank==="dynamic"){let{name:b}=m.section;s||(s=Object.create(null)),s[b]=Math.max(y,s[b]||-1e9)}}}}if(i){let c=Object.create(null),u=0,f=(d,p)=>(d.rank==="dynamic"&&p.rank==="dynamic"?s[p.name]-s[d.name]:0)||(typeof d.rank=="number"?d.rank:1e9)-(typeof p.rank=="number"?p.rank:1e9)||(d.name<p.name?-1:1);for(let d of i.sort(f))u-=1e5,c[d.name]=u;for(let d of t){let{section:p}
vendor: 9,752 bytes, line 179
179=d.completion;p&&(d.score+=c[typeof p=="string"?p:p.name])}}let l=[],a=null,h=o.compareCompletions;for(let c of t.sort((u,f)=>f.score-u.score||h(u.completion,f.completion))){let u=c.completion;!a||a.label!=u.label||a.detail!=u.detail||a.type!=null&&u.type!=null&&a.type!=u.type||a.apply!=u.apply||a.boost!=u.boost?l.push(c):Aa(c.completion)>Aa(a)&&(l[l.length-1]=c),a=c.completion}return l}class ii{constructor(e,t,i,s,r,o){this.options=e,this.attrs=t,this.tooltip=i,this.timestamp=s,this.selected=r,this.disabled=o}setSelected(e,t){return e==this.selected||e>=this.options.length?this:new ii(this.options,Ma(t,e),this.tooltip,this.timestamp,e,this.disabled)}static build(e,t,i,s,r,o){if(s&&!o&&e.some(h=>h.isPending))return s.setDisabled();let l=Mg(e,t);if(!l.length)return s&&e.some(h=>h.isPending)?s.setDisabled():null;let a=t.facet(re).selectOnOpen?0:-1;if(s&&s.selected!=a&&s.selected!=-1){let h=s.options[s.selected].completion;for(let c=0;c<l.length;c++)if(l[c].completion==h){a=c;break}}return new ii(l,Ma(i,a),{pos:e.reduce((h,c)=>c.hasResult()?Math.min(h,c.from):h,1e8),create:Ig,above:r.aboveCursor},s?s.timestamp:Date.now(),a,!1)}map(e){return new ii(this.options,this.attrs,{...this.tooltip,pos:e.mapPos(this.tooltip.pos)},this.timestamp,this.selected,this.disabled)}setDisabled(){return new ii(this.options,this.attrs,this.tooltip,this.timestamp,this.selected,!0)}}class fn{constructor(e,t,i){this.active=e,this.id=t,this.open=i}static start(){return new fn(Rg,"cm-ac-"+Math.floor(Math.random()*2e6).toString(36),null)}update(e){let{state:t}=e,i=t.facet(re),r=(i.override||t.languageDataAt("autocomplete",zt(t)).map(wg)).map(a=>(this.active.find(c=>c.source==a)||new Pe(a,this.active.some(c=>c.state!=0)?1:0)).update(e,i));r.length==this.active.length&&r.every((a,h)=>a==this.active[h])&&(r=this.active);let o=this.open,l=e.effects.some(a=>a.is(zo));o&&e.docChanged&&(o=o.map(e.changes)),e.selection||r.some(a=>a.hasResult()&&e.changes.touchesRange(a.from,a.to))||!Eg(r,this.active)||l?o=ii.build(r,t,this.id,o,i,l):o&&o.disabled&&!r.some(a=>a.isPending)&&(o=null),!o&&r.every(a=>!a.isPending)&&r.some(a=>a.hasResult())&&(r=r.map(a=>a.hasResult()?new Pe(a.source,0):a));for(let a of e.effects)a.is(Wo)&&(o=o&&o.setSelected(a.value,this.id));return r==this.active&&o==this.open?this:new fn(r,this.id,o)}get tooltip(){return this.open?this.open.tooltip:null}get attrs(){return this.open?this.open.attrs:this.active.length?Og:Dg}}function Eg(n,e){if(n==e)return!0;for(let t=0,i=0;;){for(;t<n.length&&!n[t].hasResult();)t++;for(;i<e.length&&!e[i].hasResult();)i++;let s=t==n.length,r=i==e.length;if(s||r)return s==r;if(n[t++].result!=e[i++].result)return!1}}const Og={"aria-autocomplete":"list"},Dg={};function Ma(n,e){let t={"aria-autocomplete":"list","aria-haspopup":"listbox","aria-controls":n};return e>-1&&(t["aria-activedescendant"]=n+"-"+e),t}const Rg=[];function Gc(n,e){if(n.isUserEvent("input.complete")){let i=n.annotation(jc);if(i&&e.activateOnCompletion(i))return 12}let t=n.isUserEvent("input.type");return t&&e.activateOnTyping?5:t?1:n.isUserEvent("delete.backward")?2:n.selection?8:n.docChanged?16:0}class Pe{constructor(e,t,i=!1){this.source=e,this.state=t,this.explicit=i}hasResult(){return!1}get isPending(){return this.state==1}update(e,t){let i=Gc(e,t),s=this;(i&8||i&16&&this.touches(e))&&(s=new Pe(s.source,0)),i&4&&s.state==0&&(s=new Pe(this.source,1)),s=s.updateFor(e,i);for(let r of e.effects)if(r.is(un))s=new Pe(s.source,1,r.value);else if(r.is(Ji))s=new Pe(s.source,0);else if(r.is(zo))for(let o of r.value)o.source==s.source&&(s=o);return s}updateFor(e,t){return this.map(e.changes)}map(e){return this}touches(e){return e.changes.touchesRange(zt(e.state))}}class ci extends Pe{constructor(e,t,i,s,r,o){super(e,3,t),this.limit=i,this.result=s,this.from=r,this.to=o}hasResult(){return!0}updateFor(e,t){var i;if(!(t&3))return this.map(e.changes);let s=this.result;s.map&&!e.changes.empty&&(s=s.map(s,e.changes));let r=e.changes.mapPos(this.from),o=e.changes.mapPos(this.to,1),l=zt(e.state);if(l>o||!s||t&2&&(zt(e.startState)==this.from||l<this.limit))return new Pe(this.source,t&4?1:0);let a=e.changes.mapPos(this.limit);return Lg(s.validFor,e.state,r,o)?new ci(this.source,this.explicit,a,s,r,o):s.update&&(s=s.update(s,r,o,new Uc(e.state,l,!1)))?new ci(this.source,this.explicit,a,s,s.from,(i=s.to)!==null&&i!==void 0?i:zt(e.state)):new Pe(this.source,1,this.explicit)}map(e){return e.empty?this:(this.result.map?this.result.map(this.result,e):this.result)?new ci(this.source,this.explicit,e.mapPos(this.limit),this.result,e.mapPos(this.from),e.mapPos(this.to,1)):new Pe(this.source,0)}touches(e){return e.changes.touchesRange(this.from,this.to)}}function Lg(n,e,t,i){if(!n)return!1;let s=e.sliceDoc(t,i);return typeof n=="function"?n(s,t,i,e):Qc(n,!0).test(s)}const zo=H.define({map(n,e){return n.map(t=>t.map(e))}}),ye=Ke.define({create(){return fn.start()},update(n,e){return n.update(e)},provide:n=>[Tc.from(n,e=>e.tooltip),R.contentAttributes.from(n,e=>e.attrs)]});function Vo(n,e){const t=e.completion.apply||e.completion.label;let i=n.state.field(ye).active.find(s=>s.source==e.source);return i instanceof ci?(typeof t=="string"?n.dispatch({...bg(n.state,t,i.from,i.to),annotations:jc.of(e.completion)}):t(n,e.completion,i.from,i.to),!0):!1}const Ig=Tg(ye,Vo);function Rs(n,e="option"){return t=>{let i=t.state.field(ye,!1);if(!i||!i.open||i.open.disabled||Date.now()-i.open.timestamp<t.state.facet(re).interactionDelay)return!1;let s=1,r;e=="page"&&(r=Ac(t,i.open.tooltip))&&(s=Math.max(2,Math.floor(r.dom.offsetHeight/r.dom.querySelector("li").offsetHeight)-1));let{length:o}=i.open.options,l=i.open.selected>-1?i.open.selected+s*(n?1:-1):n?0:o-1;return l<0?l=e=="page"?0:o-1:l>=o&&(l=e=="page"?o-1:0),t.dispatch({effects:Wo.of(l)}),!0}}const Ng=n=>{let e=n.state.field(ye,!1);return n.state.readOnly||!e||!e.open||e.open.selected<0||e.open.disabled||Date.now()-e.open.timestamp<n.state.facet(re).interactionDelay?!1:Vo(n,e.open.options[e.open.selected])},ar=n=>n.state.field(ye,!1)?(n.dispatch({effects:un.of(!0)}),!0):!1,Bg=n=>{let e=n.state.field(ye,!1);return!e||!e.active.some(t=>t.state!=0)?!1:(n.dispatch({effects:Ji.of(null)}),!0)};class _g{constructor(e,t){this.active=e,this.context=t,this.time=Date.now(),this.updates=[],this.done=void 0}}const Pg=50,Fg=1e3,Hg=Re.fromClass(class{constructor(n){this.view=n,this.debounceUpdate=-1,this.running=[],this.debounceAccept=-1,this.pendingStart=!1,this.composing=0;for(let e of n.state.field(ye).active)e.isPending&&this.startQuery(e)}update(n){let e=n.state.field(ye),t=n.state.facet(re);if(!n.selectionSet&&!n.docChanged&&n.startState.field(ye)==e)return;let i=n.transactions.some(r=>{let o=Gc(r,t);return o&8||(r.selection||r.docChanged)&&!(o&3)});for(let r=0;r<this.running.length;r++){let o=this.running[r];if(i||o.context.abortOnDocChange&&n.docChanged||o.updates.length+n.transactions.length>Pg&&Date.now()-o.time>Fg){for(let l of o.context.abortListeners)try{l()}catch(a){De(this.view.state,a)}o.context.abortListeners=null,this.running.splice(r--,1)}else o.updates.push(...n.transactions)}this.debounceUpdate>-1&&clearTimeout(this.debounceUpdate),n.transactions.some(r=>r.effects.some(o=>o.is(un)))&&(this.pendingStart=!0);let s=this.pendingStart?50:t.activateOnTypingDelay;if(this.debounceUpdate=e.active.some(r=>r.isPending&&!this.running.some(o=>o.active.source==r.source))?setTimeout(()=>this.startUpdate(),s):-1,this.composing!=0)for(let r of n.transactions)r.isUserEvent("input.type")?this.composing=2:this.composing==2&&r.selection&&(this.composing=3)}startUpdate(){this.debounceUpdate=-1,this.pendingStart=!1;let{state:n}=this.view,e=n.field(ye);for(let t of e.active)t.isPending&&!this.running.some(i=>i.active.source==t.source)&&this.startQuery(t);this.running.length&&e.open&&e.open.disabled&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(re).updateSyncTime))}startQuery(n){let{state:e}=this.view,t=zt(e),i=new Uc(e,t,n.explicit,this.view),s=new _g(n,i);this.running.push(s),Promise.resolve(n.source(i)).then(r=>{s.context.aborted||(s.done=r||null,this.scheduleAccept())},r=>{this.view.dispatch({effects:Ji.of(null)}),De(this.view.state,r)})}scheduleAccept(){this.running.every(n=>n.done!==void 0)?this.accept():this.debounceAccept<0&&(this.debounceAccept=setTimeout(()=>this.accept(),this.view.state.facet(re).updateSyncTime))}accept(){var n;this.debounceAccept>-1&&clearTimeout(this.debounceAccept),this.debounceAccept=-1;let e=[],t=this.view.state.facet(re),i=this.view.state.field(ye);for(let s=0;s<this.running.length;s++){let r=this.running[s];if(r.done===void 0)continue;if(this.running.splice(s--,1),r.done){let l=zt(r.updates.length?r.updates[0].startState:this.view.state),a=Math.min(l,r.done.from+(r.active.explicit?0:1)),h=new ci(r.active.source,r.active.explicit,a,r.done,r.done.from,(n=r.done.to)!==null&&n!==void 0?n:l);for(let c of r.updates)h=h.update(c,t);if(h.hasResult()){e.push(h);continue}}let o=i.active.find(l=>l.source==r.active.source);if(o&&o.isPending)if(r.done==null){let l=new Pe(r.active.source,0);for(let a of r.updates)l=l.update(a,t);l.isPending||e.push(l)}else this.startQuery(o)}(e.length||i.open&&i.open.disabled)&&this.view.dispatch({effects:zo.of(e)})}},{eventHandlers:{blur(n){let e=this.view.state.field(ye,!1);if(e&&e.tooltip&&this.view.state.facet(re).closeOnBlur){let t=e.open&&Ac(this.view,e.open.tooltip);(!t||!t.dom.contains(n.relatedTarget))&&setTimeout(()=>this.view.dispatch({effects:Ji.of(null)}),10)}},compositionstart(){this.composing=1},compositionend(){this.composing==3&&setTimeout(()=>this.view.dispatch({effects:un.of(!1)}),20),this.composing=0}}}),Wg=typeof navigator=="object"&&/Win/.test(navigator.platform),zg=Ci.highest(R.domEventHandlers({ke
179ydown(n,e){let t=e.state.field(ye,!1);if(!t||!t.open||t.open.disabled||t.open.selected<0||n.key.length>1||n.ctrlKey&&!(Wg&&n.altKey)||n.metaKey)return!1;let i=t.open.options[t.open.selected],s=t.active.find(o=>o.source==i.source),r=i.completion.commitCharacters||s.result.commitCharacters;return r&&r.indexOf(n.key)>-1&&Vo(e,i),!1}})),Vg=R.baseTheme({".cm-tooltip.cm-tooltip-autocomplete":{"& > ul":{fontFamily:"monospace",whiteSpace:"nowrap",overflow:"hidden auto",maxWidth_fallback:"700px",maxWidth:"min(700px, 95vw)",minWidth:"250px",maxHeight:"10em",height:"100%",listStyle:"none",margin:0,padding:0,"& > li, & > completion-section":{padding:"1px 3px",lineHeight:1.2},"& > li":{overflowX:"hidden",textOverflow:"ellipsis",cursor:"pointer"},"& > completion-section":{display:"list-item",borderBottom:"1px solid silver",paddingLeft:"0.5em",opacity:.7}}},"&light .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#17c",color:"white"},"&light .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#777"},"&dark .cm-tooltip-autocomplete ul li[aria-selected]":{background:"#347",color:"white"},"&dark .cm-tooltip-autocomplete-disabled ul li[aria-selected]":{background:"#444"},".cm-completionListIncompleteTop:before, .cm-completionListIncompleteBottom:after":{content:'"···"',opacity:.5,display:"block",textAlign:"center"},".cm-tooltip.cm-completionInfo":{position:"absolute",padding:"3px 9px",width:"max-content",maxWidth:"400px",boxSizing:"border-box",whiteSpace:"pre-line"},".cm-completionInfo.cm-completionInfo-left":{right:"100%"},".cm-completionInfo.cm-completionInfo-right":{left:"100%"},".cm-completionInfo.cm-completionInfo-left-narrow":{right:"30px"},".cm-completionInfo.cm-completionInfo-right-narrow":{left:"30px"},"&light .cm-snippetField":{backgroundColor:"#00000022"},"&dark .cm-snippetField":{backgroundColor:"#ffffff22"},".cm-snippetFieldPosition":{verticalAlign:"text-top",width:0,height:"1.15em",display:"inline-block",margin:"0 -0.7px -.7em",borderLeft:"1.4px dotted #888"},".cm-completionMatchedText":{textDecoration:"underline"},".cm-completionDetail":{marginLeft:"0.5em",fontStyle:"italic"},".cm-completionIcon":{fontSize:"90%",width:".8em",display:"inline-block",textAlign:"center",paddingRight:".6em",opacity:"0.6",boxSizing:"content-box"},".cm-completionIcon-function, .cm-completionIcon-method":{"&:after":{content:"'Æ'"}},".cm-completionIcon-class":{"&:after":{content:"'â'"}},".cm-completionIcon-interface":{"&:after":{content:"'â'"}},".cm-completionIcon-variable":{"&:after":{content:"'ð¥'"}},".cm-completionIcon-constant":{"&:after":{content:"'ð¶'"}},".cm-completionIcon-type":{"&:after":{content:"'ð¡'"}},".cm-completionIcon-enum":{"&:after":{content:"'âª'"}},".cm-completionIcon-property":{"&:after":{content:"'â¡'"}},".cm-completionIcon-keyword":{"&:after":{content:"'ðï¸'"}},".cm-completionIcon-namespace":{"&:after":{content:"'â¢'"}},".cm-completionIcon-text":{"&:after":{content:"'abc'",fontSize:"50%",verticalAlign:"middle"}}}),Kc=new class extends Tt{};Kc.startSide=1;Kc.endSide=-1;function Nb(n={}){return[zg,ye,re.of(n),Hg,Ug,Vg]}const $g=[{key:"Ctrl-Space",run:ar},{mac:"Alt-`",run:ar},{mac:"Alt-i",run:ar},{key:"Escape",run:Bg},{key:"ArrowDown",run:Rs(!0)},{key:"ArrowUp",run:Rs(!1)},{key:"PageDown",run:Rs(!0,"page")},{key:"PageUp",run:Rs(!1,"page")},{key:"Enter",run:Ng}],Ug=Ci.highest(xc.computeN([re],n=>n.facet(re).defaultKeymap?[$g]:[])),qg=36,Ea=1,Qg=2,jt=3,hr=4,jg=5,Gg=6,Kg=7,Xg=8,Yg=9,Jg=10,Zg=11,e0=12,t0=13,i0=14,s0=15,n0=16,r0=17,Oa=18,o0=19,Xc=20,Yc=21,Da=22,l0=23,a0=24;function oo(n){return n>=65&&n<=90||n>=97&&n<=122||n>=48&&n<=57}function h0(n){return n>=48&&n<=57||n>=97&&n<=102||n>=65&&n<=70}function Nt(n,e,t){for(let i=!1;;){if(n.next<0)return;if(n.next==e&&!i){n.advance();return}i=t&&!i&&n.next==92,n.advance()}}function c0(n,e){e:for(;;){if(n.next<0)return;if(n.next==36){n.advance();for(let t=0;t<e.length;t++){if(n.next!=e.charCodeAt(t))continue e;n.advance()}if(n.next==36){n.advance();return}}else n.advance()}}function u0(n,e){let t="[{<(".indexOf(String.fromCharCode(e)),i=t<0?e:"]}>)".charCodeAt(t);for(;;){if(n.next<0)return;if(n.next==i&&n.peek(1)==39){n.advance(2);return}n.advance()}}function lo(n,e){for(;!(n.next!=95&&!oo(n.next));)e!=null&&(e+=String.fromCharCode(n.next)),n.advance();return e}function f0(n){if(n.next==39||n.next==34||n.next==96){let e=n.next;n.advance(),Nt(n,e,!1)}else lo(n)}function Ra(n,e){for(;n.next==48||n.next==49;)n.advance();e&&n.next==e&&n.advance()}function La(n,e){for(;;){if(n.next==46){if(e)break;e=!0}else if(n.next<48||n.next>57)break;n.advance()}if(n.next==69||n.next==101)for(n.advance(),(n.next==43||n.next==45)&&n.advance();n.next>=48&&n.next<=57;)n.advance()}function Ia(n){for(;!(n.next<0||n.next==10);)n.advance()}function Lt(n,e){for(let t=0;t<e.length;t++)if(e.charCodeAt(t)==n)return!0;return!1}const cr=` \r 180`;
vendor: 5,516 bytes, line 180
180function Jc(n,e,t){let i=Object.create(null);i.true=i.false=jg,i.null=i.unknown=Gg;for(let s of n.split(" "))s&&(i[s]=Xc);for(let s of e.split(" "))s&&(i[s]=Yc);for(let s of(t||"").split(" "))s&&(i[s]=a0);return i}const Zc="array binary bit boolean char character clob date decimal double float int integer interval large national nchar nclob numeric object precision real smallint time timestamp varchar varying ",eu="absolute action add after all allocate alter and any are as asc assertion at authorization before begin between both breadth by call cascade cascaded case cast catalog check close collate collation column commit condition connect connection constraint constraints constructor continue corresponding count create cross cube current current_date current_default_transform_group current_transform_group_for_type current_path current_role current_time current_timestamp current_user cursor cycle data day deallocate declare default deferrable deferred delete depth deref desc describe descriptor deterministic diagnostics disconnect distinct do domain drop dynamic each else elseif end end-exec equals escape except exception exec execute exists exit external fetch first for foreign found from free full function general get global go goto grant group grouping handle having hold hour identity if immediate in indicator initially inner inout input insert intersect into is isolation join key language last lateral leading leave left level like limit local localtime localtimestamp locator loop map match method minute modifies module month names natural nesting new next no none not of old on only open option or order ordinality out outer output overlaps pad parameter partial path prepare preserve primary prior privileges procedure public read reads recursive redo ref references referencing relative release repeat resignal restrict result return returns revoke right role rollback rollup routine row rows savepoint schema scroll search second section select session session_user set sets signal similar size some space specific specifictype sql sqlexception sqlstate sqlwarning start state static system_user table temporary then timezone_hour timezone_minute to trailing transaction translation treat trigger under undo union unique unnest until update usage user using value values view when whenever where while with without work write year zone ",ao={backslashEscapes:!1,hashComments:!1,spaceAfterDashes:!1,slashComments:!1,doubleQuotedStrings:!1,doubleDollarQuotedStrings:!1,unquotedBitLiterals:!1,treatBitsAsBytes:!1,charSetCasts:!1,plsqlQuotingMechanism:!1,operatorChars:"*+-%<>!=&|~^/",specialVar:"?",identifierQuotes:'"',caseInsensitiveIdentifiers:!1,words:Jc(eu,Zc)};function d0(n,e,t,i){let s={};for(let r in ao)s[r]=(n.hasOwnProperty(r)?n:ao)[r];return e&&(s.words=Jc(e,t||"",i)),s}function tu(n){return new ag(e=>{var t;let{next:i}=e;if(e.advance(),Lt(i,cr)){for(;Lt(e.next,cr);)e.advance();e.acceptToken(qg)}else if(i==36&&n.doubleDollarQuotedStrings){let s=lo(e,"");e.next==36&&(e.advance(),c0(e,s),e.acceptToken(jt))}else if(i==39||i==34&&n.doubleQuotedStrings)Nt(e,i,n.backslashEscapes),e.acceptToken(jt);else if(i==35&&n.hashComments||i==47&&e.next==47&&n.slashComments)Ia(e),e.acceptToken(Ea);else if(i==45&&e.next==45&&(!n.spaceAfterDashes||e.peek(1)==32))Ia(e),e.acceptToken(Ea);else if(i==47&&e.next==42){e.advance();for(let s=1;;){let r=e.next;if(e.next<0)break;if(e.advance(),r==42&&e.next==47){if(s--,e.advance(),!s)break}else r==47&&e.next==42&&(s++,e.advance())}e.acceptToken(Qg)}else if((i==101||i==69)&&e.next==39)e.advance(),Nt(e,39,!0),e.acceptToken(jt);else if((i==110||i==78)&&e.next==39&&n.charSetCasts)e.advance(),Nt(e,39,n.backslashEscapes),e.acceptToken(jt);else if(i==95&&n.charSetCasts)for(let s=0;;s++){if(e.next==39&&s>1){e.advance(),Nt(e,39,n.backslashEscapes),e.acceptToken(jt);break}if(!oo(e.next))break;e.advance()}else if(n.plsqlQuotingMechanism&&(i==113||i==81)&&e.next==39&&e.peek(1)>0&&!Lt(e.peek(1),cr)){let s=e.peek(1);e.advance(2),u0(e,s),e.acceptToken(jt)}else if(Lt(i,n.identifierQuotes)){const s=i==91?93:i;Nt(e,s,!1),e.acceptToken(o0)}else if(i==40)e.acceptToken(Kg);else if(i==41)e.acceptToken(Xg);else if(i==123)e.acceptToken(Yg);else if(i==125)e.acceptToken(Jg);else if(i==91)e.acceptToken(Zg);else if(i==93)e.acceptToken(e0);else if(i==59)e.acceptToken(t0);else if(n.unquotedBitLiterals&&i==48&&e.next==98)e.advance(),Ra(e),e.acceptToken(Da);else if((i==98||i==66)&&(e.next==39||e.next==34)){const s=e.next;e.advance(),n.treatBitsAsBytes?(Nt(e,s,n.backslashEscapes),e.acceptToken(l0)):(Ra(e,s),e.acceptToken(Da))}else if(i==48&&(e.next==120||e.next==88)||(i==120||i==88)&&e.next==39){let s=e.next==39;for(e.advance();h0(e.next);)e.advance();s&&e.next==39&&e.advance(),e.acceptToken(hr)}else if(i==46&&e.next>=48&&e.next<=57)La(e,!0),e.acceptToken(hr);else if(i==46)e.acceptToken(i0);else if(i>=48&&i<=57)La(e,!1),e.acceptToken(hr);else if(Lt(i,n.operatorChars)){for(;Lt(e.next,n.operatorChars);)e.advance();e.acceptToken(s0)}else if(Lt(i,n.specialVar))e.next==i&&e.advance(),f0(e),e.acceptToken(r0);else if(i==58||i==44)e.acceptToken(n0);else if(oo(i)){let s=lo(e,String.fromCharCode(i));e.acceptToken(e.next==46||e.peek(-s.length-1)==46?Oa:(t=n.words[s.toLowerCase()])!==null&&t!==void 0?t:Oa)}})}const iu=tu(ao),p0=cn.deserialize({version:14,states:"%vQ]QQOOO#wQRO'#DSO$OQQO'#CwO%eQQO'#CxO%lQQO'#CyO%sQQO'#CzOOQQ'#DS'#DSOOQQ'#C}'#C}O'UQRO'#C{OOQQ'#Cv'#CvOOQQ'#C|'#C|Q]QQOOQOQQOOO'`QQO'#DOO(xQRO,59cO)PQQO,59cO)UQQO'#DSOOQQ,59d,59dO)c
180QQO,59dOOQQ,59e,59eO)jQQO,59eOOQQ,59f,59fO)qQQO,59fOOQQ-E6{-E6{OOQQ,59b,59bOOQQ-E6z-E6zOOQQ,59j,59jOOQQ-E6|-E6|O+VQRO1G.}O+^QQO,59cOOQQ1G/O1G/OOOQQ1G/P1G/POOQQ1G/Q1G/QP+kQQO'#C}O+rQQO1G.}O)PQQO,59cO,PQQO'#Cw",stateData:",[~OtOSPOSQOS~ORUOSUOTUOUUOVROXSOZTO]XO^QO_UO`UOaPObPOcPOdUOeUOfUOgUOhUO~O^]ORvXSvXTvXUvXVvXXvXZvX]vX_vX`vXavXbvXcvXdvXevXfvXgvXhvX~OsvX~P!jOa_Ob_Oc_O~ORUOSUOTUOUUOVROXSOZTO^tO_UO`UOa`Ob`Oc`OdUOeUOfUOgUOhUO~OWaO~P$ZOYcO~P$ZO[eO~P$ZORUOSUOTUOUUOVROXSOZTO^QO_UO`UOaPObPOcPOdUOeUOfUOgUOhUO~O]hOsoX~P%zOajObjOcjO~O^]ORkaSkaTkaUkaVkaXkaZka]ka_ka`kaakabkackadkaekafkagkahka~Oska~P'kO^]O~OWvXYvX[vX~P!jOWnO~P$ZOYoO~P$ZO[pO~P$ZO^]ORkiSkiTkiUkiVkiXkiZki]ki_ki`kiakibkickidkiekifkigkihki~Oski~P)xOWkaYka[ka~P'kO]hO~P$ZOWkiYki[ki~P)xOasObsOcsO~O",goto:"#hwPPPPPPPPPPPPPPPPPPPPPPPPPPx||||!Y!^!d!xPPP#[TYOZeUORSTWZbdfqT[OZQZORiZSWOZQbRQdSQfTZgWbdfqQ^PWk^lmrQl_Qm`RrseVORSTWZbdfq",nodeNames:"â LineComment BlockComment String Number Bool Null ( ) { } [ ] ; . Operator Punctuation SpecialVar Identifier QuotedIdentifier Keyword Type Bits Bytes Builtin Script Statement CompositeIdentifier Parens Braces Brackets Statement",maxTerm:38,nodeProps:[["isolate",-4,1,2,3,19,""]],skippedNodes:[0,1,2],repeatNodeCount:3,tokenData:"RORO",tokenizers:[0,iu],topRules:{Script:[0,25]},tokenPrec:0});
180function ho(n){let e=n.cursor().moveTo(n.from,-1);for(;/Comment/.test(e.name);)e.moveTo(e.from,-1);return e.node}function Zi(n,e){let t=n.sliceString(e.from,e.to),i=/^([`'"\[])(.*)([`'"\]])$/.exec(t);return i?i[2]:t}function dn(n){return n&&(n.name=="Identifier"||n.name=="QuotedIdentifier")}function m0(n,e){if(e.name=="CompositeIdentifier"){let t=[];for(let i=e.firstChild;i;i=i.nextSibling)dn(i)&&t.push(Zi(n,i));return t}return[Zi(n,e)]}function Na(n,e){for(let t=[];;){if(!e||e.name!=".")return t;let i=ho(e);if(!dn(i))return t;t.unshift(Zi(n,i)),e=ho(i)}}function g0(n,e){let t=Le(n).resolveInner(e,-1),i=b0(n.doc,t);return t.name=="Identifier"||t.name=="QuotedIdentifier"||t.name=="Keyword"?{from:t.from,quoted:t.name=="QuotedIdentifier"?n.doc.sliceString(t.from,t.from+1):null,parents:Na(n.doc,ho(t)),aliases:i}:t.name=="."?{from:e,quoted:null,parents:Na(n.doc,t),aliases:i}:{from:e,quoted:null,parents:[],empty:!0,aliases:i}}const y0=new Set("where group having order union intersect except all distinct limit offset fetch for".split(" "));function b0(n,e){let t;for(let s=e;!t;s=s.parent){if(!s)return null;s.name=="Statement"&&(t=s)}let i=null;for(let s=t.firstChild,r=!1,o=null;s;s=s.nextSibling){let l=s.name=="Keyword"?n.sliceString(s.from,s.to).toLowerCase():null,a=null;if(!r)r=l=="from";else if(l=="as"&&o&&dn(s.nextSibling))a=Zi(n,s.nextSibling);else{if(l&&y0.has(l))break;o&&dn(s)&&(a=Zi(n,s))}a&&(i||(i=Object.create(null)),i[a]=m0(n,o)),o=/Identifier$/.test(s.name)?s:null}return i}function w0(n,e,t){return t.map(i=>({...i,label:i.label[0]==n?i.label:n+i.label+e,apply:void 0}))}const C0=/^\w*$/,x0=/^[`'"\[]?\w*[`'"\]]?$/;function Ba(n){return n.self&&typeof n.self.label=="string"}class $o{constructor(e,t){this.idQuote=e,this.idCaseInsensitive=t,this.list=[],this.children=void 0}child(e){let t=this.children||(this.children=Object.create(null)),i=t[e];return i||(e&&!this.list.some(s=>s.label==e)&&this.list.push(_a(e,"type",this.idQuote,this.idCaseInsensitive)),t[e]=new $o(this.idQuote,this.idCaseInsensitive))}maybeChild(e){return this.children?this.children[e]:null}addCompletion(e){let t=this.list.findIndex(i=>i.label==e.label);t>-1?this.list[t]=e:this.list.push(e)}addCompletions(e){for(let t of e)this.addCompletion(typeof t=="string"?_a(t,"property",this.idQuote,this.idCaseInsensitive):t)}addNamespace(e){Array.isArray(e)?this.addCompletions(e):Ba(e)?this.addNamespace(e.children):this.addNamespaceObject(e)}addNamespaceObject(e){for(let t of Object.keys(e)){let i=e[t],s=null,r=t.replace(/\\?\./g,l=>l=="."?"\0":l).split("\0"),o=this;Ba(i)&&(s=i.self,i=i.children);for(let l=0;l<r.length;l++)s&&l==r.length-1&&o.addCompletion(s),o=o.child(r[l].replace(/\\\./g,"."));o.addNamespace(i)}}}function _a(n,e,t,i){return new RegExp("^[a-z_][a-z_\\d]*$",i?"i":"").test(n)?{label:n,type:e}:{label:n,type:e,apply:t+n+su(t)}}function su(n){return n==="["?"]":n}function S0(n,e,t,i,s,r){var o;let l=((o=r?.spec.identifierQuotes)===null||o===void 0?void 0:o[0])||'"',a=new $o(l,!!r?.spec.caseInsensitiveIdentifiers),h=s?a.child(s):null;return a.addNamespace(n),e&&(h||a).addCompletions(e),t&&a.addCompletions(t),h&&a.addCompletions(h.list),i&&a.addCompletions((h||a).child(i).list),c=>{let{parents:u,from:f,quoted:d,empty:p,aliases:m}=g0(c.state,c.pos);if(p&&!c.explicit)return null;m&&u.length==1&&(u=m[u[0]]||u);let g=a;for(let b of u){for(;!g.children||!g.children[b];)if(g==a&&h)g=h;else if(g==h&&i)g=g.child(i);else return null;let C=g.maybeChild(b);if(!C)return null;g=C}let y=g.list;if(g==a&&m&&(y=y.concat(Object.keys(m).map(b=>({label:b,type:"constant"})))),d){let b=d[0],C=su(b),k=c.state.sliceDoc(c.pos,c.pos+1)==C;return{from:f,to:k?c.pos+1:void 0,options:w0(b,C,y),validFor:x0}}else return{from:f,options:y,validFor:C0}}}function v0(n){return n==Yc?"type":n==Xc?"keyword":"variable"}function k0(n,e,t){let i=Object.keys(n).map(s=>t(e?s.toUpperCase():s,v0(n[s])));return yg(["QuotedIdentifier","String","LineComment","BlockComment","."],qc(i))}let T0=p0.configure({props:[Vc.add({Statement:jm()}),Gm.add({Statement(n,e){return{from:Math.min(n.from+100,e.doc.lineAt(n.from).to),to:n.to}},BlockComment(n){return{from:n.from+2,to:n.to-2}}}),Pc({Keyword:M.keyword,Type:M.typeName,Builtin:M.standard(M.name),Bits:M.number,Bytes:M.string,Bool:M.bool,Null:M.null,Number:M.number,String:M.str
vendor: 5,968 bytes, line 180
180ing,Identifier:M.name,QuotedIdentifier:M.special(M.string),SpecialVar:M.special(M.name),LineComment:M.lineComment,BlockComment:M.blockComment,Operator:M.operator,"Semi Punctuation":M.punctuation,"( )":M.paren,"{ }":M.brace,"[ ]":M.squareBracket})]});class wi{constructor(e,t,i){this.dialect=e,this.language=t,this.spec=i}get extension(){return this.language.extension}configureLanguage(e,t){return new wi(this.dialect,this.language.configure(e,t),this.spec)}static define(e){let t=d0(e,e.keywords,e.types,e.builtin),i=nn.define({name:"sql",parser:T0.configure({tokenizers:[{from:iu,to:tu(t)}]}),languageData:{commentTokens:{line:"--",block:{open:"/*",close:"*/"}},closeBrackets:{brackets:["(","[","{","'",'"',"`"]}}});return new wi(t,i,e)}}function A0(n,e){return{label:n,type:e,boost:-1}}function M0(n,e=!1,t){return k0(n.dialect.words,e,t||A0)}function E0(n){return n.schema?S0(n.schema,n.tables,n.schemas,n.defaultTable,n.defaultSchema,n.dialect||Uo):()=>null}function O0(n){return n.schema?(n.dialect||Uo).language.data.of({autocomplete:E0(n)}):[]}function Bb(n={}){let e=n.dialect||Uo;return new Fm(e.language,[O0(n),e.language.data.of({autocomplete:M0(e,n.upperCaseKeywords,n.keywordCompletion)})])}const Uo=wi.define({}),ur=wi.define({charSetCasts:!0,doubleDollarQuotedStrings:!0,operatorChars:"+-*/<>=~!@#%^&|`?",specialVar:"",keywords:eu+"abort abs absent access according ada admin aggregate alias also always analyse analyze array_agg array_max_cardinality asensitive assert assignment asymmetric atomic attach attribute attributes avg backward base64 begin_frame begin_partition bernoulli bit_length blocked bom cache called cardinality catalog_name ceil ceiling chain char_length character_length character_set_catalog character_set_name character_set_schema characteristics characters checkpoint class class_origin cluster coalesce cobol collation_catalog collation_name collation_schema collect column_name columns command_function command_function_code comment comments committed concurrently condition_number configuration conflict connection_name constant constraint_catalog constraint_name constraint_schema contains content control conversion convert copy corr cost covar_pop covar_samp csv cume_dist current_catalog current_row current_schema cursor_name database datalink datatype datetime_interval_code datetime_interval_precision db debug defaults defined definer degree delimiter delimiters dense_rank depends derived detach detail dictionary disable discard dispatch dlnewcopy dlpreviouscopy dlurlcomplete dlurlcompleteonly dlurlcompletewrite dlurlpath dlurlpathonly dlurlpathwrite dlurlscheme dlurlserver dlvalue document dump dynamic_function dynamic_function_code element elsif empty enable encoding encrypted end_frame end_partition endexec enforced enum errcode error event every exclude excluding exclusive exp explain expression extension extract family file filter final first_value flag floor following force foreach fortran forward frame_row freeze fs functions fusion generated granted greatest groups handler header hex hierarchy hint id ignore ilike immediately immutable implementation implicit import include including increment indent index indexes info inherit inherits inline insensitive instance instantiable instead integrity intersection invoker isnull key_member key_type label lag last_value lead leakproof least length library like_regex link listen ln load location lock locked log logged lower mapping matched materialized max max_cardinality maxvalue member merge message message_length message_octet_length message_text min minvalue mod mode more move multiset mumps name namespace nfc nfd nfkc nfkd nil normalize normalized nothing notice notify notnull nowait nth_value ntile nullable nullif nulls number occurrences_regex octet_length octets off offset oids operator options ordering others over overlay overriding owned owner parallel parameter_mode parameter_name parameter_ordinal_position parameter_specific_catalog parameter_specific_name parameter_specific_schema parser partition pascal passing passthrough password percent percent_rank percentile_cont percentile_disc perform period permission pg_context pg_datatype_name pg_exception_context pg_exception_detail pg_exception_hint placing plans pli policy portion position position_regex power precedes preceding prepared print_strict_params procedural procedures program publication query quote raise range rank reassign recheck recovery refresh regr_avgx regr_avgy regr_count regr_intercept regr_r2 regr_slope regr_sxx regr_sxy regr_syy reindex rename repeatable replace replica requiring reset respect restart restore result_oid returned_cardinality returned_length returned_octet_length returned_sqlstate returning reverse routine_catalog routine_name routine_schema routines row_count row_number rowtype rule scale schema_name schemas scope scope_catalog scope_name scope_schema security selective self sensitive sequence sequences serializable server server_name setof share show simple skip slice snapshot source specific_name sqlcode sqlerror sqrt stable stacked standalone statement statistics stddev_pop stddev_samp stdin stdout storage strict strip structure style subclass_origin submultiset subscription substring substring_regex succeeds sum symmetric sysid system system_time table_name tables tablesample tablespace temp template ties token top_level_count transaction_active transactions_committed transactions_rolled_back transform transforms translate translate_regex trigger_catalog trigger_name trigger_schema trim trim_array truncate trusted type types uescape unbounded uncommitted unencrypted unlink unlisten unlogged unnamed untyped upper uri use_column use_variable user_defined_type_catalog user_defined_type_code user_defined_type_name user_defined_type_schema vacuum valid validate validator value_of var_pop var_samp varbinary variable_conflict variadic verbose version versioning views volatile warning whitespace width_bu
180cket window within wrapper xmlagg xmlattributes xmlbinary xmlcast xmlcomment xmlconcat xmldeclaration xmldocument xmlelement xmlexists xmlforest xmliterate xmlnamespaces xmlparse xmlpi xmlquery xmlroot xmlschema xmlserialize xmltable xmltext xmlvalidate yes",types:Zc+"bigint int8 bigserial serial8 varbit bool box bytea cidr circle precision float8 inet int4 json jsonb line lseg macaddr macaddr8 money numeric pg_lsn point polygon float4 int2 smallserial serial2 serial serial4 text timetz timestamptz tsquery tsvector txid_snapshot uuid xml"}),D0=n=>{let{state:e}=n,t=e.doc.lineAt(e.selection.main.from),i=Qo(n.state,t.from);return i.line?R0(n):i.block?I0(n):!1};function qo(n,e){return({state:t,dispatch:i})=>{if(t.readOnly)return!1;let s=n(e,t);return s?(i(t.update(s)),!0):!1}}const R0=qo(_0,0),L0=qo(nu,0),I0=qo((n,e)=>nu(n,e,B0(e)),0);function Qo(n,e){let t=n.languageDataAt("commentTokens",e,1);return t.length?t[0]:{}}const Ei=50;function N0(n,{open:e,close:t},i,s){let r=n.sliceDoc(i-Ei,i),o=n.sliceDoc(s,s+Ei),l=/\s*$/.exec(r)[0].length,a=/^\s*/.exec(o)[0].length,h=r.length-l;if(r.slice(h-e.length,h)==e&&o.slice(a,a+t.length)==t)return{open:{pos:i-l,margin:l&&1},close:{pos:s+a,margin:a&&1}};let c,u;s-i<=2*Ei?c=u=n.sliceDoc(i,s):(c=n.sliceDoc(i,i+Ei),u=n.sliceDoc(s-Ei,s));let f=/^\s*/.exec(c)[0].length,d=/\s*$/.exec(u)[0].length,p=u.length-d-t.length;return c.slice(f,f+e.length)==e&&u.slice(p,p+t.length)==t?{open:{pos:i+f+e.length,margin:/\s/.test(c.charAt(f+e.length))?1:0},close:{pos:s-d-t.length,margin:/\s/.test(u.charAt(p-1))?1:0}}:null}function B0(n){let e=[];for(let t of n.selection.ranges){let i=n.doc.lineAt(t.from),s=t.to<=i.to?i:n.doc.lineAt(t.to);s.from>i.from&&s.from==t.to&&(s=t.to==i.to+1?i:n.doc.lineAt(t.to-1));let r=e.length-1;r>=0&&e[r].to>i.from?e[r].to=s.to:e.push({from:i.from+/^\s*/.exec(i.text)[0].length,to:s.to})}return e}function nu(n,e,t=e.selection.ranges){let i=t.map(r=>Qo(e,r.from).block);if(!i.every(r=>r))return null;let s=t.map((r,o)=>N0(e,i[o],r.from,r.to));if(n!=2&&!s.every(r=>r))return{changes:e.changes(t.map((r,o)=>s[o]?[]:[{from:r.from,insert:i[o].open+" "},{from:r.to,insert:" "+i[o].close}]))};if(n!=1&&s.some(r=>r)){let r=[];for(let o=0,l;o<s.length;o++)if(l=s[o]){let a=i[o],{open:h,close:c}=l;r.push({from:h.pos-a.open.length,to:h.pos+h.margin},{from:c.pos-c.margin,to:c.pos+a.close.length})}return{changes:r}}return null}function _0(n,e,t=e.selection.ranges){let i=[],s=-1;e:for(let{from:r,to:o}of t){let l=i.length,a=1e9,h;for(let c=r;c<=o;){let u=e.doc.lineAt(c);if(h==null&&(h=Qo(e,u.from).line,!h))continue e;if(u.from>s&&(r==o||o>u.from)){s=u.from;let f=/^\s*/.exec(u.text)[0].length,d=f==u.length,p=u.text.slice(f,f+h.length)==h?f:-1;f<u.text.length&&f<a&&(a=f),i.push({line:u,comment:p,token:h,indent:f,empty:d,single:!1})}c=u.to+1}if(a<1e9)for(let c=l;c<i.length;c++)i[c].indent<i[c].line.text.length&&(i[c].indent=a);i.length==l+1&&(i[l].single=!0)}if(n!=2&&i.some(r=>r.comment<0&&(!r.empty||r.single))){let r=[];for(let{line:l,token:a,indent:h,empty:c,single:u}of i)(u||!c)&&r.push({from:l.from+h,insert:a+" "});let o=e.changes(r);return{changes:o,selection:e.selection.map(o,1)}}else if(n!=1&&i.some(r=>r.comment>=0)){let r=[];for(let{line:o,comment:l,token:a}of i)if(l>=0){let h=o.from+l,c=h+a.length;o.text[c-o.from]==" "&&c++,r.push({from:h,to:c})}return{changes:r}}return null}const co=gt.define(),P0=gt.define(),F0=E.define(),ru=E.define({combine(n){return vn(n,{minDepth:100,newGroupDelay:500,joinToEvent:(e,t)=>t},{minDepth:Math.max,newGroupDelay:Math.min,joinToEvent:(e,t)=>(i,s)=>e(i,s)||t(i,s)})}}),ou=Ke.define({create(){return at.empty},update(n,e){let t=e.state.facet(ru),i=e.annotation(co);if(i){let a=we.fromTransaction(e,i.selection),h=i.side,c=h==0?n.undone:n.done;return a?c=pn(c,c.length,t.minDepth,a):c=hu(c,e.startState.selection),new at(h==0?i.rest:c,h==0?c:i.rest)}let s=e.annotation(P0);if((s=="full"||s=="before")&&(n=n.isolate()),e.annotation(se.addToHistory)===!1)return e.changes.empty?n:n.addMapping(e.changes.desc);let r=we.fromTransaction(e),o=e.annotation(se.time),l=e.annotation(se.userEvent);return r?n=n.addChanges(r,o,l,t,e):e.selection&&(n=n.addSelection(e.startState.selection,o,l,t.newGroupDelay)),(s=="full"||s=="after")&&(n=n.isolate()),n},toJSON(n){return{done:n.done.map(e=>e.toJSON()),undone:n.undone.map(e=>e.toJSON())}}
vendor: 15,948 bytes, line 180
180,fromJSON(n){return new at(n.done.map(we.fromJSON),n.undone.map(we.fromJSON))}});function _b(n={}){return[ou,ru.of(n),R.domEventHandlers({beforeinput(e,t){let i=e.inputType=="historyUndo"?lu:e.inputType=="historyRedo"?uo:null;return i?(e.preventDefault(),i(t)):!1}})]}function Rn(n,e){return function({state:t,dispatch:i}){if(!e&&t.readOnly)return!1;let s=t.field(ou,!1);if(!s)return!1;let r=s.pop(n,t,e);return r?(i(r),!0):!1}}const lu=Rn(0,!1),uo=Rn(1,!1),H0=Rn(0,!0),W0=Rn(1,!0);class we{constructor(e,t,i,s,r){this.changes=e,this.effects=t,this.mapped=i,this.startSelection=s,this.selectionsAfter=r}setSelAfter(e){return new we(this.changes,this.effects,this.mapped,this.startSelection,e)}toJSON(){var e,t,i;return{changes:(e=this.changes)===null||e===void 0?void 0:e.toJSON(),mapped:(t=this.mapped)===null||t===void 0?void 0:t.toJSON(),startSelection:(i=this.startSelection)===null||i===void 0?void 0:i.toJSON(),selectionsAfter:this.selectionsAfter.map(s=>s.toJSON())}}static fromJSON(e){return new we(e.changes&&ie.fromJSON(e.changes),[],e.mapped&&ct.fromJSON(e.mapped),e.startSelection&&w.fromJSON(e.startSelection),e.selectionsAfter.map(w.fromJSON))}static fromTransaction(e,t){let i=Fe;for(let s of e.startState.facet(F0)){let r=s(e);r.length&&(i=i.concat(r))}return!i.length&&e.changes.empty?null:new we(e.changes.invert(e.startState.doc),i,void 0,t||e.startState.selection,Fe)}static selection(e){return new we(void 0,Fe,void 0,void 0,e)}}function pn(n,e,t,i){let s=e+1>t+20?e-t-1:0,r=n.slice(s,e);return r.push(i),r}function z0(n,e){let t=[],i=!1;return n.iterChangedRanges((s,r)=>t.push(s,r)),e.iterChangedRanges((s,r,o,l)=>{for(let a=0;a<t.length;){let h=t[a++],c=t[a++];l>=h&&o<=c&&(i=!0)}}),i}function V0(n,e){return n.ranges.length==e.ranges.length&&n.ranges.filter((t,i)=>t.empty!=e.ranges[i].empty).length===0}function au(n,e){return n.length?e.length?n.concat(e):n:e}const Fe=[],$0=200;function hu(n,e){if(n.length){let t=n[n.length-1],i=t.selectionsAfter.slice(Math.max(0,t.selectionsAfter.length-$0));return i.length&&i[i.length-1].eq(e)?n:(i.push(e),pn(n,n.length-1,1e9,t.setSelAfter(i)))}else return[we.selection([e])]}function U0(n){let e=n[n.length-1],t=n.slice();return t[n.length-1]=e.setSelAfter(e.selectionsAfter.slice(0,e.selectionsAfter.length-1)),t}function fr(n,e){if(!n.length)return n;let t=n.length,i=Fe;for(;t;){let s=q0(n[t-1],e,i);if(s.changes&&!s.changes.empty||s.effects.length){let r=n.slice(0,t);return r[t-1]=s,r}else e=s.mapped,t--,i=s.selectionsAfter}return i.length?[we.selection(i)]:Fe}function q0(n,e,t){let i=au(n.selectionsAfter.length?n.selectionsAfter.map(l=>l.map(e)):Fe,t);if(!n.changes)return we.selection(i);let s=n.changes.map(e),r=e.mapDesc(n.changes,!0),o=n.mapped?n.mapped.composeDesc(r):r;return new we(s,H.mapEffects(n.effects,e),o,n.startSelection.map(r),i)}const Q0=/^(input\.type|delete)($|\.)/;class at{constructor(e,t,i=0,s=void 0){this.done=e,this.undone=t,this.prevTime=i,this.prevUserEvent=s}isolate(){return this.prevTime?new at(this.done,this.undone):this}addChanges(e,t,i,s,r){let o=this.done,l=o[o.length-1];return l&&l.changes&&!l.changes.empty&&e.changes&&(!i||Q0.test(i))&&(!l.selectionsAfter.length&&t-this.prevTime<s.newGroupDelay&&s.joinToEvent(r,z0(l.changes,e.changes))||i=="input.type.compose")?o=pn(o,o.length-1,s.minDepth,new we(e.changes.compose(l.changes),au(H.mapEffects(e.effects,l.changes),l.effects),l.mapped,l.startSelection,Fe)):o=pn(o,o.length,s.minDepth,e),new at(o,Fe,t,i)}addSelection(e,t,i,s){let r=this.done.length?this.done[this.done.length-1].selectionsAfter:Fe;return r.length>0&&t-this.prevTime<s&&i==this.prevUserEvent&&i&&/^select($|\.)/.test(i)&&V0(r[r.length-1],e)?this:new at(hu(this.done,e),this.undone,t,i)}addMapping(e){return new at(fr(this.done,e),fr(this.undone,e),this.prevTime,this.prevUserEvent)}pop(e,t,i){let s=e==0?this.done:this.undone;if(s.length==0)return null;let r=s[s.length-1],o=r.selectionsAfter[0]||(r.startSelection?r.startSelection.map(r.changes.invertedDesc,1):t.selection);if(i&&r.selectionsAfter.length)return t.update({selection:r.selectionsAfter[r.selectionsAfter.length-1],annotations:co.of({side:e,rest:U0(s),selection:o}),userEvent:e==0?"select.undo":"select.redo",scrollIntoView:!0});if(r.changes){let l=s.length==1?Fe:s.slice(0,s.length-1);return r.mapped&&(l=fr(l,r.mapped)),t.update({changes:r.changes,selection:r.startSelection,effects:r.effects,annotations:co.of({side:e,rest:l,selection:o}),filter:!1,userEvent:e==0?"undo":"redo",scrollIntoView:!0})}else return null}}at.empty=new at(Fe,Fe);const Pb=[{key:"Mod-z",run:lu,preventDefault:!0},{key:"Mod-y",mac:"Mod-Shift-z",run:uo,preventDefault:!0},{linux:"Ctrl-Shift-z",run:uo,preventDefault:!0},{key:"Mod-u",run:H0,preventDefault:!0},{key:"Alt-u",mac:"Mod-Shift-u",run:W0,preventDefault:!0}];function xi(n,e){return w.create(n.ranges.map(e),n.mainIndex)}function Xe(n,e){return n.update({selection:e,scrollIntoView:!0,userEvent:"select"})}function Ye({state:n,dispatch:e},t){let i=xi(n.selection,t);return i.eq(n.selection,!0)?!1:(e(Xe(n,i)),!0)}function Ln(n,e){return w.cursor(e?n.to:n.from)}function cu(n,e){return Ye(n,t=>t.empty?n.moveByChar(t,e):Ln(t,e))}function de(n){return n.textDirectionAt(n.state.selection.main.head)==G.LTR}const uu=n=>cu(n,!de(n)),fu=n=>cu(n,de(n));function du(n,e){return Ye(n,t=>t.empty?n.moveByGroup(t,e):Ln(t,e))}const j0=n=>du(n,!de(n)),G0=n=>du(n,de(n));function K0(n,e,t){if(e.type.prop(t))return!0;let i=e.to-e.from;return i&&(i>2||/[^\s,.;:]/.test(n.sliceDoc(e.from,e.to)))||e.firstChild}function In(n,e,t){let i=Le(n).resolveInner(e.head),s=t?N.closedBy:N.openedBy;for(let a=e.head;;){let h=t?i.childAfter(a):i.childBefore(a);if(!h)break;K0(n,h,s)?i=h:a=t?h.to:h.from}let r=i.type.prop(s),o,l;return r&&(o=t?ti(n,i.from,1):ti(n,i.to,-1))&&o.matched?l=t?o.end.to:o.end.from:l=t?i.to:i.from,w.cursor(l,t?-1:1)}const X0=n=>Ye(n,e=>In(n.state,e,!de(n))),Y0=n=>Ye(n,e=>In(n.state,e,de(n)));function pu(n,e){return Ye(n,t=>{if(!t.empty)return Ln(t,e);let i=n.moveVertically(t,e);return i.head!=t.head?i:n.moveToLineBoundary(t,e)})}const mu=n=>pu(n,!1),gu=n=>pu(n,!0);function yu(n){let e=n.scrollDOM.clientHeight<n.scrollDOM.scrollHeight-2,t=0,i=0,s;if(e){for(let r of n.state.facet(R.scrollMargins)){let o=r(n);o?.top&&(t=Math.max(o?.top,t)),o?.bottom&&(i=Math.max(o?.bottom,i))}s=n.scrollDOM.clientHeight-t-i}else s=(n.dom.ownerDocument.defaultView||window).innerHeight;return{marginTop:t,marginBottom:i,selfScroll:e,height:Math.max(n.defaultLineHeight,s-5)}}function bu(n,e){let t=yu(n),{state:i}=n,s=xi(i.selection,o=>o.empty?n.moveVertically(o,e,t.height):Ln(o,e));if(s.eq(i.selection))return!1;let r;if(t.selfScroll){let o=n.coordsAtPos(i.selection.main.head),l=n.scrollDOM.getBoundingClientRect(),a=l.top+t.marginTop,h=l.bottom-t.marginBottom;o&&o.top>a&&o.bottom<h&&(r=R.scrollIntoView(s.main.head,{y:"start",yMargin:o.top-a}))}return n.dispatch(Xe(i,s),{effects:r}),!0}const Pa=n=>bu(n,!1),fo=n=>bu(n,!0);function Dt(n,e,t){let i=n.lineBlockAt(e.head),s=n.moveToLineBoundary(e,t);if(s.head==e.head&&s.head!=(t?i.to:i.from)&&(s=n.moveToLineBoundary(e,t,!1)),!t&&s.head==i.from&&i.length){let r=/^\s*/.exec(n.state.sliceDoc(i.from,Math.min(i.from+100,i.to)))[0].length;r&&e.head!=i.from+r&&(s=w.cursor(i.from+r))}return s}const J0=n=>Ye(n,e=>Dt(n,e,!0)),Z0=n=>Ye(n,e=>Dt(n,e,!1)),ey=n=>Ye(n,e=>Dt(n,e,!de(n))),ty=n=>Ye(n,e=>Dt(n,e,de(n))),iy=n=>Ye(n,e=>w.cursor(n.lineBlockAt(e.head).from,1)),sy=n=>Ye(n,e=>w.cursor(n.lineBlockAt(e.head).to,-1));function ny(n,e,t){let i=!1,s=xi(n.selection,r=>{let o=ti(n,r.head,-1)||ti(n,r.head,1)||r.head>0&&ti(n,r.head-1,1)||r.head<n.doc.length&&ti(n,r.head+1,-1);if(!o||!o.end)return r;i=!0;let l=o.start.from==r.head?o.end.to:o.end.from;return w.cursor(l)});return i?(e(Xe(n,s)),!0):!1}const ry=({state:n,dispatch:e})=>ny(n,e);function ze(n,e){let t=xi(n.state.selection,i=>{let s=e(i);return w.range(i.anchor,s.head,s.goalColumn,s.bidiLevel||void 0,s.assoc)});return t.eq(n.state.selection)?!1:(n.dispatch(Xe(n.state,t)),!0)}function wu(n,e){return ze(n,t=>n.moveByChar(t,e))}const Cu=n=>wu(n,!de(n)),xu=n=>wu(n,de(n));function Su(n,e){return ze(n,t=>n.moveByGroup(t,e))}const oy=n=>Su(n,!de(n)),ly=n=>Su(n,de(n)),ay=n=>ze(n,e=>In(n.state,e,!de(n))),hy=n=>ze(n,e=>In(n.state,e,de(n)));function vu(n,e){return ze(n,t=>n.moveVertically(t,e))}const ku=n=>vu(n,!1),Tu=n=>vu(n,!0);function Au(n,e){return ze(n,t=>n.moveVertically(t,e,yu(n).height))}const Fa=n=>Au(n,!1),Ha=n=>Au(n,!0),cy=n=>ze(n,e=>Dt(n,e,!0)),uy=n=>ze(n,e=>Dt(n,e,!1)),fy=n=>ze(n,e=>Dt(n,e,!de(n))),dy=n=>ze(n,e=>Dt(n,e,de(n))),py=n=>ze(n,e=>w.cursor(n.lineBlockAt(e.head).from)),my=n=>ze(n,e=>w.cursor(n.lineBlockAt(e.head).to)),Wa=({state:n,dispatch:e})=>(e(Xe(n,{anchor:0})),!0),za=({state:n,dispatch:e})=>(e(Xe(n,{anchor:n.doc.length})),!0),Va=({state:n,dispatch:e})=>(e(Xe(n,{anchor:n.selection.main.anchor,head:0})),!0),$a=({state:n,dispatch:e})=>(e(Xe(n,{anchor:n.selection.main.anchor,head:n.doc.length})),!0),gy=({state:n,dispatch:e})=>(e(n.update({selection:{anchor:0,head:n.doc.length},userEvent:"select"})),!0),yy=({state:n,dispatch:e})=>{let t=Nn(n).map(({from:i,to:s})=>w.range(i,Math.min(s+1,n.doc.length)));return e(n.update({selection:w.create(t),userEvent:"select"})),!0},by=({state:n,dispatch:e})=>{let t=xi(n.selection,i=>{let s=Le(n),r=s.resolveStack(i.from,1);if(i.empty){let o=s.resolveStack(i.from,-1);o.node.from>=r.node.from&&o.node.to<=r.node.to&&(r=o)}for(let o=r;o;o=o.next){let{node:l}=o;if((l.from<i.from&&l.to>=i.to||l.to>i.to&&l.from<=i.from)&&o.next)return w.range(l.to,l.from)}return i});return t.eq(n.selection)?!1:(e(Xe(n,t)),!0)};function Mu(n,e){let{state:t}=n,i=t.selection,s=t.selection.ranges.slice();for(let r of t.selection.ranges){let o=t.doc.lineAt(r.head);if(e?o.to<n.state.doc.length:o.from>0)for(let l=r;;){let a=n.moveVertically(l,e);if(a.head<o.from||a.head>o.to){s.some(h=>h.head==a.head)||s.push(a);break}else{if(a.head==l.head)break;l=a}}}return s.length==i.ranges.length?!1:(n.dispatch(Xe(t,w.create(s,s.length-1))),!0)}const wy=n=>Mu(n,!1),Cy=n=>Mu(n,!0),xy=({state:n,dispatch:e})=>{let t=n.selection,i=null;return t.ranges.length>1?i=w.create([t.main]):t.main.empty||(i=w.create([w.cursor(t.main.head)])),i?(e(Xe(n,i)),!0):!1};function os(n,e){if(n.state.readOnly)return!1;let t="delete.selection",{state:i}=n,s=i.changeByRange(r=>{let{from:o,to:l}=r;if(o==l){let a=e(r);a<o?(t="delete.backward",a=Ls(n,a,!1)):a>o&&(t="delete.forward",a=Ls(n,a,!0)),o=Math.min(o,a),l=Math.max(l,a)}else o=Ls(n,o,!1),l=Ls(n,l,!0);return o==l?{range:r}:{changes:{from:o,to:l},range:w.cursor(o,o<r.head?-1:1)}});return s.changes.empty?!1:(n.dispatch(i.update(s,{scrollIntoView:!0,userEvent:t,effects:t=="delete.selection"?R.announce.of(i.phrase("Selection deleted")):void 0})),!0)}function Ls(n,e,t){if(n instanceof R)for(let i of n.state.facet(R.atomicRanges).map(s=>s(n)))i.between(e,e,(s,r)=>{s<e&&r>e&&(e=t?r:s)});return e}const Eu=(n,e,t)=>os(n,i=>{let s=i.from,{state:r}=n,o=r.doc.lineAt(s),l,a;if(t&&!e&&s>o.from&&s<o.from+200&&!/[^ \t]/.test(l=o.text.slice(0,s-o.from))){if(l[l.length-1]==" ")return s-1;let h=kn(l,r.tabSize),c=h%on(r)||on(r);for(let u=0;u<c&&l[l.length-1-u]==" ";u++)s--;a=s}else a=oe(o.text,s-o.from,e,e)+o.from,a==s&&o.number!=(e?r.doc.lines:1)?a+=e?1:-1:!e&&/[\ufe00-\ufe0f]/.test(o.text.slice(a-o.from,s-o.from))&&(a=oe(o.text,a-o.from,!1,!1)+o.from);return a}),po=n=>Eu(n,!1,!0),Ou=n=>Eu(n,!0,!1),Du=(n,e)=>os(n,t=>{let i=t.head,{state:s}=n,r=s.doc.lineAt(i),o=s.charCategorizer(i);for(let l=null;;){if(i==(e?r.to:r.from)){i==t.head&&r.number!=(e?s.doc.lines:1)&&(i+=e?1:-1);break}let a=oe(r.text,i-r.from,e)+r.from,h=r.text.slice(Math.min(i,a)-r.from,Math.max(i,a)-r.from),c=o(h);if(l!=null&&c!=l)break;(h!=" "||i!=t.head)&&(l=c),i=a}return i}),Ru=n=>Du(n,!1),Sy=n=>Du(n,!0),vy=n=>os(n,e=>{let t=n.lineBlockAt(e.head).to;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)}),ky=n=>os(n,e=>{let t=n.moveToLineBoundary(e,!1).head;return e.head>t?t:Math.max(0,e.head-1)}),Ty=n=>os(n,e=>{let t=n.moveToLineBoundary(e,!0).head;return e.head<t?t:Math.min(n.state.doc.length,e.head+1)}),Ay=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>({changes:{from:i.from,to:i.to,insert:F.of(["",""])},range:w.cursor(i.from)}));return e(n.update(t,{scrollIntoView:!0,userEvent:"input"})),!0},My=({state:n,dispatch:e})=>{if(n.readOnly)return!1;let t=n.changeByRange(i=>{if(!i.empty||i.from==0||i.from==n.doc.length)return{range:i};let s=i.from,r=n.doc.lineAt(s),o=s==r.from?s-1:oe(r.text,s-r.from,!1)+r.from,l=s==r.to?s+1:oe(r.text,s-r.from,!0)+r.from;return{changes:{from:o,to:l,insert:n.doc.slice(s,l).append(n.doc.slice(o,s))},range:w.cursor(l)}});return t.changes.empty?!1:(e(n.update(t,{scrollIntoView:!0,userEvent:"move.character"})),!0)};function Nn(n){let e=[],t=-1;for(let i of n.selection.ranges){let s=n.doc.lineAt(i.from),r=n.doc.lineAt(i.to);if(!i.empty&&i.to==r.from&&(r=n.doc.lineAt(i.to-1)),t>=s.number){let o=e[e.length-1];o.to=r.to,o.ranges.push(i)}else e.push({from:s.from,to:r.to,ranges:[i]});t=r.number+1}return e}function Lu(n,e,t){if(n.readOnly)return!1;let i=[],s=[];for(let r of Nn(n)){if(t?r.to==n.doc.length:r.from==0)continue;let o=n.doc.lineAt(t?r.to+1:r.from-1),l=o.length+1;if(t){i.push({from:r.to,to:o.to},{from:r.from,insert:o.text+n.lineBreak});for(let a of r.ranges)s.push(w.range(Math.min(n.doc.length,a.anchor+l),Math.min(n.doc.length,a.head+l)))}else{i.push({from:o.from,to:r.from},{from:r.to,insert:n.lineBreak+o.text});for(let a of r.ranges)s.push(w.range(a.anchor-l,a.head-l))}}return i.length?(e(n.update({changes:i,scrollIntoView:!0,selection:w.create(s,n.selection.mainIndex),userEvent:"move.line"})),!0):!1}const Ey=({state:n,dispatch:e})=>Lu(n,e,!1),Oy=({state:n,dispatch:e})=>Lu(n,e,!0);function Iu(n,e,t){if(n.readOnly)return!1;let i=[];for(let r of Nn(n))t?i.push({from:r.from,insert:n.doc.slice(r.from,r.to)+n.lineBreak}):i.push({from:r.to,insert:n.lineBreak+n.doc.slice(r.from,r.to)});let s=n.changes(i);return e(n.update({changes:s,selection:n.selection.map(s,t?1:-1),scrollIntoView:!0,userEvent:"input.copyline"})),!0}const Dy=({state:n,dispatch:e})=>Iu(n,e,!1),Ry=({state:n,dispatch:e})=>Iu(n,e,!0),Ly=n=>{if(n.state.readOnly)return!1;let{state:e}=n,t=e.changes(Nn(e).map(({from:s,to:r})=>(s>0?s--:r<e.doc.length&&r++,{from:s,to:r}))),i=xi(e.selection,s=>{let r;if(n.lineWrapping){let o=n.lineBlockAt(s.head),l=n.coordsAtPos(s.head,s.assoc||1);l&&(r=o.bottom+n.documentTop-l.bottom+n.defaultLineHeight/2)}return n.moveVertically(s,!0,r)}).map(t);return n.dispatch({changes:t,selection:i,scrollIntoView:!0,userEvent:"delete.line"}),!0};function Iy(n,e){if(/\(\)|\[\]|\{\}/.test(n.sliceDoc(e-1,e+1)))return{from:e,to:e};let t=Le(n).resolveInner(e),i=t.childBefore(e),s=t.childAfter(e),r;return i&&s&&i.to<=e&&s.from>=e&&(r=i.type.prop(N.closedBy))&&r.indexOf(s.name)>-1&&n.doc.lineAt(i.to).from==n.doc.lineAt(s.from).from&&!/\S/.test(n.sliceDoc(i.to,s.from))?{from:i.to,to:s.from}:null}const Ua=Nu(!1),Ny=Nu(!0);function Nu(n){return({state:e,dispatch:t})=>{if(e.readOnly)return!1;let i=e.changeByRange(s=>{let{from:r,to:o}=s,l=e.doc.lineAt(r),a=!n&&r==o&&Iy(e,r);n&&(r=o=(o<=l.to?l:e.doc.lineAt(o)).to);let h=new Dn(e,{simulateBreak:r,simulateDoubleBreak:!!a}),c=zc(h,r);for(c==null&&(c=kn(/^\s*/.exec(e.doc.lineAt(r).text)[0],e.tabSize));o<l.to&&/\s/.test(l.text[o-l.from]);)o++;a?{from:r,to:o}=a:r>l.from&&r<l.from+100&&!/\S/.test(l.text.slice(0,r))&&(r=l.from);let u=["",ln(e,c)];return a&&u.push(ln(e,h.lineIndent(l.from,-1))),{changes:{from:r,to:o,insert:F.of(u)},range:w.cursor(r+1+u[1].length)}});return t(e.update(i,{scrollIntoView:!0,userEvent:"input"})),!0}}function jo(n,e){let t=-1;return n.changeByRange(i=>{let s=[];for(let o=i.from;o<=i.to;){let l=n.doc.lineAt(o);l.number>t&&(i.empty||i.to>l.from)&&(e(l,s,i),t=l.number),o=l.to+1}let r=n.changes(s);return{changes:s,range:w.range(r.mapPos(i.anchor,1),r.mapPos(i.head,1))}})}const By=({state:n,dispatch:e})=>
vendor: 20,542 bytes, lines 180-181
180{if(n.readOnly)return!1;let t=Object.create(null),i=new Dn(n,{overrideIndentation:r=>{let o=t[r];return o??-1}}),s=jo(n,(r,o,l)=>{let a=zc(i,r.from);if(a==null)return;/\S/.test(r.text)||(a=0);let h=/^\s*/.exec(r.text)[0],c=ln(n,a);(h!=c||l.from<r.from+h.length)&&(t[r.from]=a,o.push({from:r.from,to:r.from+h.length,insert:c}))});return s.changes.empty||e(n.update(s,{userEvent:"indent"})),!0},_y=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(jo(n,(t,i)=>{i.push({from:t.from,insert:n.facet(Po)})}),{userEvent:"input.indent"})),!0),Py=({state:n,dispatch:e})=>n.readOnly?!1:(e(n.update(jo(n,(t,i)=>{let s=/^\s*/.exec(t.text)[0];if(!s)return;let r=kn(s,n.tabSize),o=0,l=ln(n,Math.max(0,r-on(n)));for(;o<s.length&&o<l.length&&s.charCodeAt(o)==l.charCodeAt(o);)o++;i.push({from:t.from+o,to:t.from+s.length,insert:l.slice(o)})}),{userEvent:"delete.dedent"})),!0),Fy=n=>(n.setTabFocusMode(),!0),Hy=[{key:"Ctrl-b",run:uu,shift:Cu,preventDefault:!0},{key:"Ctrl-f",run:fu,shift:xu},{key:"Ctrl-p",run:mu,shift:ku},{key:"Ctrl-n",run:gu,shift:Tu},{key:"Ctrl-a",run:iy,shift:py},{key:"Ctrl-e",run:sy,shift:my},{key:"Ctrl-d",run:Ou},{key:"Ctrl-h",run:po},{key:"Ctrl-k",run:vy},{key:"Ctrl-Alt-h",run:Ru},{key:"Ctrl-o",run:Ay},{key:"Ctrl-t",run:My},{key:"Ctrl-v",run:fo}],Wy=[{key:"ArrowLeft",run:uu,shift:Cu,preventDefault:!0},{key:"Mod-ArrowLeft",mac:"Alt-ArrowLeft",run:j0,shift:oy,preventDefault:!0},{mac:"Cmd-ArrowLeft",run:ey,shift:fy,preventDefault:!0},{key:"ArrowRight",run:fu,shift:xu,preventDefault:!0},{key:"Mod-ArrowRight",mac:"Alt-ArrowRight",run:G0,shift:ly,preventDefault:!0},{mac:"Cmd-ArrowRight",run:ty,shift:dy,preventDefault:!0},{key:"ArrowUp",run:mu,shift:ku,preventDefault:!0},{mac:"Cmd-ArrowUp",run:Wa,shift:Va},{mac:"Ctrl-ArrowUp",run:Pa,shift:Fa},{key:"ArrowDown",run:gu,shift:Tu,preventDefault:!0},{mac:"Cmd-ArrowDown",run:za,shift:$a},{mac:"Ctrl-ArrowDown",run:fo,shift:Ha},{key:"PageUp",run:Pa,shift:Fa},{key:"PageDown",run:fo,shift:Ha},{key:"Home",run:Z0,shift:uy,preventDefault:!0},{key:"Mod-Home",run:Wa,shift:Va},{key:"End",run:J0,shift:cy,preventDefault:!0},{key:"Mod-End",run:za,shift:$a},{key:"Enter",run:Ua,shift:Ua},{key:"Mod-a",run:gy},{key:"Backspace",run:po,shift:po,preventDefault:!0},{key:"Delete",run:Ou,preventDefault:!0},{key:"Mod-Backspace",mac:"Alt-Backspace",run:Ru,preventDefault:!0},{key:"Mod-Delete",mac:"Alt-Delete",run:Sy,preventDefault:!0},{mac:"Mod-Backspace",run:ky,preventDefault:!0},{mac:"Mod-Delete",run:Ty,preventDefault:!0}].concat(Hy.map(n=>({mac:n.key,run:n.run,shift:n.shift}))),Fb=[{key:"Alt-ArrowLeft",mac:"Ctrl-ArrowLeft",run:X0,shift:ay},{key:"Alt-ArrowRight",mac:"Ctrl-ArrowRight",run:Y0,shift:hy},{key:"Alt-ArrowUp",run:Ey},{key:"Shift-Alt-ArrowUp",run:Dy},{key:"Alt-ArrowDown",run:Oy},{key:"Shift-Alt-ArrowDown",run:Ry},{key:"Mod-Alt-ArrowUp",run:wy},{key:"Mod-Alt-ArrowDown",run:Cy},{key:"Escape",run:xy},{key:"Mod-Enter",run:Ny},{key:"Alt-l",mac:"Ctrl-l",run:yy},{key:"Mod-i",run:by,preventDefault:!0},{key:"Mod-[",run:Py},{key:"Mod-]",run:_y},{key:"Mod-Alt-\\",run:By},{key:"Shift-Mod-k",run:Ly},{key:"Shift-Mod-\\",run:ry},{key:"Mod-/",run:D0},{key:"Alt-A",run:L0},{key:"Ctrl-m",mac:"Shift-Alt-m",run:Fy}].concat(Wy),qa=typeof String.prototype.normalize=="function"?n=>n.normalize("NFKD"):n=>n;class es{constructor(e,t,i=0,s=e.length,r,o){this.test=o,this.value={from:0,to:0,precise:!1},this.done=!1,this.matches=[],this.buffer="",this.bufferPos=0,this.iter=e.iterRange(i,s),this.bufferStart=i,this.normalize=r?l=>r(qa(l)):qa,this.query=this.normalize(t)}peek(){if(this.bufferPos==this.buffer.length){if(this.bufferStart+=this.buffer.length,this.iter.next(),this.iter.done)return-1;this.bufferPos=0,this.buffer=this.iter.value}return bt(this.buffer,this.bufferPos)}next(){for(;this.matches.length;)this.matches.pop();return this.nextOverlapping()}nextOverlapping(){for(;;){let e=this.peek();if(e<0)return this.done=!0,this;let t=gh(e),i=this.bufferStart+this.bufferPos;this.bufferPos+=Bt(e);let s=this.normalize(t);if(s.length)for(let r=0,o=i,l=!0;;r++){let a=s.charCodeAt(r),h=this.match(a,o,l,this.bufferPos+this.bufferStart,r==s.length-1);if(h)return this.value=h,this;if(r==s.length-1)break;l&&r<t.length&&t.charCodeAt(r)==a?o++:l=!1}}}match(e,t,i,s,r){let o=null;for(let l=0;l<this.matches.length;){let a=this.matches[l],h=!1;this.query.charCodeAt(a.index)==e&&(a.index==this.query.length-1?o={from:a.from,to:s,precise:r&&a.precise}:(a.index++,h=!0)),h?l++:this.matches.splice(l,1)}return this.query.charCodeAt(0)==e&&(this.query.length==1?o={from:t,to:s,precise:i&&r}:this.matches.push({from:t,index:1,precise:i})),o&&this.test&&!this.test(o.from,o.to,this.buffer,this.bufferStart)&&(o=null),o}}typeof Symbol<"u"&&(es.prototype[Symbol.iterator]=function(){return this});const Bu={from:-1,to:-1,match:/.*/.exec(""),precise:!0},Go="gm"+(/x/.unicode==null?"":"u");class _u{constructor(e,t,i,s=0,r=e.length){if(this.text=e,this.to=r,this.curLine="",this.done=!1,this.value=Bu,/\\[sWDnr]|\n|\r|\[\^/.test(t))return new Pu(e,t,i,s,r);this.re=new RegExp(t,Go+(i?.ignoreCase?"i":"")),this.test=i?.test,this.iter=e.iter();let o=e.lineAt(s);this.curLineStart=o.from,this.matchPos=mn(e,s),this.getLine(this.curLineStart)}getLine(e){this.iter.next(e),this.iter.lineBreak?this.curLine="":(this.curLine=this.iter.value,this.curLineStart+this.curLine.length>this.to&&(this.curLine=this.curLine.slice(0,this.to-this.curLineStart)),this.iter.next())}nextLine(){this.curLineStart=this.curLineStart+this.curLine.length+1,this.curLineStart>this.to?this.curLine="":this.getLine(0)}next(){for(let e=this.matchPos-this.curLineStart;;){this.re.lastIndex=e;let t=this.matchPos<=this.to&&this.re.exec(this.curLine);if(t){let i=this.curLineStart+t.index,s=i+t[0].length;if(this.matchPos=mn(this.text,s+(i==s?1:0)),i==this.curLineStart+this.curLine.length&&this.nextLine(),(i<s||i>this.value.to)&&(!this.test||this.test(i,s,t)))return this.value={from:i,to:s,precise:!0,match:t},this;e=this.matchPos-this.curLineStart}else if(this.curLineStart+this.curLine.length<this.to)this.nextLine(),e=0;else return this.done=!0,this}}}const dr=new WeakMap;class ui{constructor(e,t){this.from=e,this.text=t}get to(){return this.from+this.text.length}static get(e,t,i){let s=dr.get(e);if(!s||s.from>=i||s.to<=t){let l=new ui(t,e.sliceString(t,i));return dr.set(e,l),l}if(s.from==t&&s.to==i)return s;let{text:r,from:o}=s;return o>t&&(r=e.sliceString(t,o)+r,o=t),s.to<i&&(r+=e.sliceString(s.to,i)),dr.set(e,new ui(o,r)),new ui(t,r.slice(t-o,i-o))}}class Pu{constructor(e,t,i,s,r){this.text=e,this.to=r,this.done=!1,this.value=Bu,this.matchPos=mn(e,s),this.re=new RegExp(t,Go+(i?.ignoreCase?"i":"")),this.test=i?.test,this.flat=ui.get(e,s,this.chunkEnd(s+5e3))}chunkEnd(e){return e>=this.to?this.to:this.text.lineAt(e).to}next(){for(;;){let e=this.re.lastIndex=this.matchPos-this.flat.from,t=this.re.exec(this.flat.text);if(t&&!t[0]&&t.index==e&&(this.re.lastIndex=e+1,t=this.re.exec(this.flat.text)),t){let i=this.flat.from+t.index,s=i+t[0].length;if((this.flat.to>=this.to||t.index+t[0].length<=this.flat.text.length-10)&&(!this.test||this.test(i,s,t)))return this.value={from:i,to:s,precise:!0,match:t},this.matchPos=mn(this.text,s+(i==s?1:0)),this}if(this.flat.to==this.to)return this.done=!0,this;this.flat=ui.get(this.text,this.flat.from,this.chunkEnd(this.flat.from+this.flat.text.length*2))}}}typeof Symbol<"u"&&(_u.prototype[Symbol.iterator]=Pu.prototype[Symbol.iterator]=function(){return this});function zy(n){try{return new RegExp(n,Go),!0}catch{return!1}}function mn(n,e){if(e>=n.length)return e;let t=n.lineAt(e),i;for(;e<t.to&&(i=t.text.charCodeAt(e-t.from))>=56320&&i<57344;)e++;return e}const Vy=n=>{let{state:e}=n,t=String(e.doc.lineAt(n.state.selection.main.head).number),{close:i,result:s}=hm(n,{label:e.phrase("Go to line"),input:{type:"text",name:"line",value:t},focus:!0,submitLabel:e.phrase("go")});return s.then(r=>{let o=r&&/^([+-])?(\d+)?(:\d+)?(%)?$/.exec(r.elements.line.value);if(!o){n.dispatch({effects:i});return}let l=e.doc.lineAt(e.selection.main.head),[,a,h,c,u]=o,f=c?+c.slice(1):0,d=h?+h:l.number;if(h&&u){let g=d/100;a&&(g=g*(a=="-"?-1:1)+l.number/e.doc.lines),d=Math.round(e.doc.lines*g)}else h&&a&&(d=d*(a=="-"?-1:1)+l.number);let p=e.doc.line(Math.max(1,Math.min(e.doc.lines,d))),m=w.cursor(p.from+Math.max(0,Math.min(f,p.length)));n.dispatch({effects:[i,R.scrollIntoView(m.from,{y:"center"})],selection:m})}),!0},$y=({state:n,dispatch:e})=>{let{selection:t}=n,i=w.create(t.ranges.map(s=>n.wordAt(s.head)||w.cursor(s.head)),t.mainIndex);return i.eq(t)?!1:(e(n.update({selection:i})),!0)};function Uy(n,e){let{main:t,ranges:i}=n.selection,s=n.wordAt(t.head),r=s&&s.from==t.from&&s.to==t.to;for(let o=!1,l=new es(n.doc,e,i[i.length-1].to);;)if(l.next(),l.done){if(o)return null;l=new es(n.doc,e,0,Math.max(0,i[i.length-1].from-1)),o=!0}else{if(o&&i.some(a=>a.from==l.value.from))continue;if(r){let a=n.wordAt(l.value.from);if(!a||a.from!=l.value.from||a.to!=l.value.to)continue}return l.value}}const qy=({state:n,dispatch:e})=>{let{ranges:t}=n.selection;if(t.some(r=>r.from===r.to))return $y({state:n,dispatch:e});let i=n.sliceDoc(t[0].from,t[0].to);if(n.selection.ranges.some(r=>n.sliceDoc(r.from,r.to)!=i))return!1;let s=Uy(n,i);return s?(e(n.update({selection:n.selection.addRange(w.range(s.from,s.to),!1),effects:R.scrollIntoView(s.to)})),!0):!1},Si=E.define({combine(n){return vn(n,{top:!1,caseSensitive:!1,literal:!1,regexp:!1,wholeWord:!1,createPanel:e=>new nb(e),scrollToMatch:e=>R.scrollIntoView(e)})}});class Fu{constructor(e){this.search=e.search,this.caseSensitive=!!e.caseSensitive,this.literal=!!e.literal,this.regexp=!!e.regexp,this.replace=e.replace||"",this.valid=!!this.search&&(!this.regexp||zy(this.search)),this.unquoted=this.unquote(this.search),this.wholeWord=!!e.wholeWord,this.test=e.test}unquote(e){return this.literal?e:e.replace(/\\([nrt\\])/g,(t,i)=>i=="n"?` 181`:i=="r"?"\r":i=="t"?" ":"\\")}eq(e){return this.search==e.search&&this.replace==e.replace&&this.caseSensitive==e.caseSensitive&&this.regexp==e.regexp&&this.wholeWord==e.wholeWord&&this.test==e.test}create(){return this.regexp?new Yy(this):new Gy(this)}getCursor(e,t=0,i){let s=e.doc?e:W.create({doc:e});return i==null&&(i=s.doc.length),this.regexp?Xt(this,s,t,i):Kt(this,s,t,i)}}class Hu{constructor(e){this.spec=e}}function Qy(n,e,t){return(i,s,r,o)=>{if(t&&!t(i,s,r,o))return!1;let l=i>=o&&s<=o+r.length?r.slice(i-o,s-o):e.doc.sliceString(i,s);return n(l,e,i,s)}}function Kt(n,e,t,i){let s;return n.wholeWord&&(s=jy(e.doc,e.charCategorizer(e.selection.main.head))),n.test&&(s=Qy(n.test,e,s)),new es(e.doc,n.unquoted,t,i,n.caseSensitive?void 0:r=>r.toLowerCase(),s)}function jy(n,e){return(t,i,s,r)=>((r>t||r+s.length<i)&&(r=Math.max(0,t-2),s=n.sliceString(r,Math.min(n.length,i+2))),(e(gn(s,t-r))!=ce.Word||e(yn(s,t-r))!=ce.Word)&&(e(yn(s,i-r))!=ce.Word||e(gn(s,i-r))!=ce.Word))}class Gy extends Hu{constructor(e){super(e)}nextMatch(e,t,i){let s=Kt(this.spec,e,i,e.doc.length).nextOverlapping();if(s.done){let r=Math.min(e.doc.length,t+this.spec.unquoted.length);s=Kt(this.spec,e,0,r).nextOverlapping()}return s.done||s.value.from==t&&s.value.to==i?null:s.value}prevMatchInRange(e,t,i){for(let s=i;;){let r=Math.max(t,s-1e4-this.spec.unquoted.length),o=Kt(this.spec,e,r,s),l=null;for(;!o.nextOverlapping().done;)l=o.value;if(l)return l;if(r==t)return null;s-=1e4}}prevMatch(e,t,i){let s=this.prevMatchInRange(e,0,t);return s||(s=this.prevMatchInRange(e,Math.max(0,i-this.spec.unquoted.length),e.doc.length)),s&&(s.from!=t||s.to!=i)?s:null}getReplacement(e){return this.spec.unquote(this.spec.replace)}matchAll(e,t){let i=Kt(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=t)return null;s.push(i.value)}return s}highlight(e,t,i,s){let r=Kt(this.spec,e,Math.max(0,t-this.spec.unquoted.length),Math.min(i+this.spec.unquoted.length,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}function Ky(n,e,t){return(i,s,r)=>(!t||t(i,s,r))&&n(r[0],e,i,s)}function Xt(n,e,t,i){let s;return n.wholeWord&&(s=Xy(e.charCategorizer(e.selection.main.head))),n.test&&(s=Ky(n.test,e,s)),new _u(e.doc,n.search,{ignoreCase:!n.caseSensitive,test:s},t,i)}function gn(n,e){return n.slice(oe(n,e,!1),e)}function yn(n,e){return n.slice(e,oe(n,e))}function Xy(n){return(e,t,i)=>!i[0].length||(n(gn(i.input,i.index))!=ce.Word||n(yn(i.input,i.index))!=ce.Word)&&(n(yn(i.input,i.index+i[0].length))!=ce.Word||n(gn(i.input,i.index+i[0].length))!=ce.Word)}class Yy extends Hu{nextMatch(e,t,i){let s=Xt(this.spec,e,i,e.doc.length).next();return s.done&&(s=Xt(this.spec,e,0,t).next()),s.done?null:s.value}prevMatchInRange(e,t,i){for(let s=1;;s++){let r=Math.max(t,i-s*1e4),o=Xt(this.spec,e,r,i),l=null;for(;!o.next().done;)l=o.value;if(l&&(r==t||l.from>r+10))return l;if(r==t)return null}}prevMatch(e,t,i){return this.prevMatchInRange(e,0,t)||this.prevMatchInRange(e,i,e.doc.length)}getReplacement(e){return this.spec.unquote(this.spec.replace).replace(/\$([$&]|\d+)/g,(t,i)=>{if(i=="&")return e.match[0];if(i=="$")return"$";for(let s=i.length;s>0;s--){let r=+i.slice(0,s);if(r>0&&r<e.match.length)return e.match[r]+i.slice(s)}return t})}matchAll(e,t){let i=Xt(this.spec,e,0,e.doc.length),s=[];for(;!i.next().done;){if(s.length>=t)return null;s.push(i.value)}return s}highlight(e,t,i,s){let r=Xt(this.spec,e,Math.max(0,t-250),Math.min(i+250,e.doc.length));for(;!r.next().done;)s(r.value.from,r.value.to)}}const ts=H.define(),Ko=H.define(),kt=Ke.define({create(n){return new pr(mo(n).create(),null)},update(n,e){for(let t of e.effects)t.is(ts)?n=new pr(t.value.create(),n.panel):t.is(Ko)&&(n=new pr(n.query,t.value?Xo:null));return n},provide:n=>tn.from(n,e=>e.panel)});class pr{constructor(e,t){this.query=e,this.panel=t}}const Jy=j.mark({class:"cm-searchMatch"}),Zy=j.mark({class:"cm-searchMatch cm-searchMatch-selected"}),eb=Re.fromClass(class{constructor(n){this.view=n,this.decorations=this.highlight(n.state.field(kt))}update(n){let e=n.state.field(kt);(e!=n.startState.field(kt)||n.docChanged||n.selectionSet||n.viewportChanged)&&(this.decorations=this.highlight(e))}highlight({query:n,panel:e}){if(!e||!n.spec.valid)return j.none;let{view:t}=this,i=new di;for(let s=0,r=t.visibleRanges,o=r.length;s<o;s++){let{from:l,to:a}=r[s];for(;s<o-1&&a>r[s+1].from-2*250;)a=r[++s].to;n.highlight(t.state,l,a,(h,c)=>{let u=t.state.selection.ranges.some(f=>f.from==h&&f.to==c);i.add(h,c,u?Zy:Jy)})}return i.finish()}},{decorations:n=>n.decorations});function ls(n){return e=>{let t=e.state.field(kt,!1);return t&&t.query.spec.valid?n(e,t):Vu(e)}}const bn=ls((n,{query:e})=>{let{to:t}=n.state.selection.main,i=e.nextMatch(n.state,t,t);if(!i)return!1;let s=w.single(i.from,i.to),r=n.state.facet(Si);return n.dispatch({selection:s,effects:[Yo(n,i),r.scrollToMatch(s.main,n)],userEvent:"select.search"}),zu(n),!0}),wn=ls((n,{query:e})=>{let{state:t}=n,{from:i}=t.selection.main,s=e.prevMatch(t,i,i);if(!s)return!1;let r=w.single(s.from,s.to),o=n.state.facet(Si);return n.dispatch({selection:r,effects:[Yo(n,s),o.scrollToMatch(r.main,n)],userEvent:"select.search"}),zu(n),!0}),tb=ls((n,{query:e})=>{let t=e.matchAll(n.state,1e3);return!t||!t.length?!1:(n.dispatch({selection:w.create(t.map(i=>w.range(i.from,i.to))),userEvent:"select.search.matches"}),!0)}),ib=({state:n,dispatch:e})=>{let t=n.selection;if(t.ranges.length>1||t.main.empty)return!1;let{from:i,to:s}=t.main,r=[],o=0;for(let l=new es(n.doc,n.sliceDoc(i,s));!l.next().done;){if(r.length>1e3)return!1;l.value.from==i&&(o=r.length),r.push(w.range(l.value.from,l.value.to))}return e(n.update({selection:w.create(r,o),userEvent:"select.search.matches"})),!0},Qa=ls((n,{query:e})=>{let{state:t}=n,{from:i,to:s}=t.selection.main;if(t.readOnly)return!1;let r=e.nextMatch(t,i,i);if(!r)return!1;let o=r,l=[],a,h,c=[];o.precise?o.from==i&&o.to==s&&(h=t.toText(e.getReplacement(o)),l.push({from:o.from,to:o.to,insert:h}),c.push(R.announce.of(t.phrase("replaced match on line $",t.doc.lineAt(i).number)+"."))):o=e.nextMatch(t,o.from,o.to);let u=n.state.changes(l);return o&&(a=w.single(o.from,o.to).map(u),c.push(Yo(n,o)),c.push(t.facet(Si).scrollToMatch(a.main,n))),n.dispatch({changes:u,selection:a,effects:c,userEvent:"input.replace"}),!0}),sb=ls((n,{query:e})=>{if(n.state.readOnly)return!1;let t=[];for(let s of e.matchAll(n.state,1e9)){let{from:r,to:o,precise:l}=s;l&&t.push({from:r,to:o,insert:e.getReplacement(s)})}if(!t.length)return!1;let i=n.state.phrase("replaced $ matches",t.length)+".";return n.dispatch({changes:t,effects:R.announce.of(i),userEvent:"input.replace.all"}),!0});function Xo(n){return n.state.facet(Si).createPanel(n)}function mo(n,e){var t,i,s,r,o;let l=n.selection.main,a=l.empty||l.to>l.from+100?"":n.sliceDoc(l.from,l.to);if(e&&!a)return e;let h=n.facet(Si);return new Fu({search:((t=e?.literal)!==null&&t!==void 0?t:h.literal)?a:a.replace(/\n/g,"\\n"),caseSensitive:(i=e?.caseSensitive)!==null&&i!==void 0?i:h.caseSensitive,literal:(s=e?.literal)!==null&&s!==void 0?s:h.literal,regexp:(r=e?.regexp)!==null&&r!==void 0?r:h.regexp,wholeWord:(o=e?.wholeWord)!==null&&o!==void 0?o:h.wholeWord})}function Wu(n){let e=Mc(n,Xo);return e&&e.dom.querySelector("[main-field]")}function zu(n){let e=Wu(n);e&&e==n.root.activeElement&&e.select()}const Vu=n=>{let e=n.state.field(kt,!1);if(e&&e.panel){let t=Wu(n);if(t&&t!=n.root.activeElement){let i=mo(n.state,e.query.spec);i.valid&&n.dispatch({effects:ts.of(i)}),t.focus(),t.select()}}else n.dispatch({effects:[Ko.of(!0),e?ts.of(mo(n.state,e.query.spec)):H.appendConfig.of(ob)]});return!0},$u=n=>{let e=n.state.field(kt,!1);if(!e||!e.panel)return!1;let t=Mc(n,Xo);return t&&t.dom.contains(n.root.activeElement)&&n.focus(),n.dispatch({effects:Ko.of(!1)}),!0},Hb=[{key:"Mod-f",run:Vu,scope:"editor search-panel"},{key:"F3",run:bn,shift:wn,scope:"editor search-panel",preventDefault:!0},{key:"Mod-g",run:bn,shift:wn,scope:"editor search-panel",preventDefault:!0},{key:"Escape",run:$u,scope:"editor search-panel"},{key:"Mod-Shift-l",run:ib},{key:"Mod-Alt-g",run:Vy},{key:"Mod-d",run:qy,preventDefault:!0}];class nb{constructor(e){this.view=e;let t=this.query=e.state.field(kt).query.spec;this.commit=this.commit.bind(this),this.searchField=ne("input",{value:t.search,placeholder:Ae(e,"Find"),"aria-label":Ae(e,"Find"),class:"cm-textfield",name:"search",form:"","main-field":"true",onchange:this.commit,onkeyup:this.commit}),this.replaceField=ne("input",{value:t.replace,placeholder:Ae(e,"Replace"),"aria-label":Ae(e,"Replace"),class:"cm-textfield",name:"replace",form:"",onchange:this.commit,onkeyup:this.commit}),this.caseField=ne("input",{type:"checkbox",name:"case",form:"",checked:t.caseSensitive,onchange:this.commit}),this.reField=ne("input",{type:"checkbox",name:"re",form:"",checked:t.regexp,onchange:this.commit}),this.wordField=ne("input",{type:"checkbox",name:"word",form:"",checked:t.wholeWord,onchange:this.commit});function i(s,r,o){return ne("button",{class:"cm-button",name:s,onclick:r,type:"button"},o)}this.dom=ne("div",{onkeydown:s=>this.keydown(s),class:"cm-search"},[this.searchField,i("next",()=>bn(e),[Ae(e,"next")]),i("prev",()=>wn(e),[Ae(e,"previous")]),i("select",()=>tb(e),[Ae(e,"all")]),ne("label",null,[this.caseField,Ae(e,"match case")]),ne("label",null,[this.reField,Ae(e,"regexp")]),ne("label",null,[this.wordField,Ae(e,"by word")]),...e.state.readOnly?[]:[ne("br"),this.replaceField,i("replace",()=>Qa(e),[Ae(e,"replace")]),i("replaceAll",()=>sb(e),[Ae(e,"replace all")])],ne("button",{name:"close",onclick:()=>$u(e),"aria-label":Ae(e,"close"),type:"button"},["Ã"])])}commit(){let e=new Fu({search:this.searchField.value,caseSensitive:this.caseField.checked,regexp:this.reField.checked,wholeWord:this.wordField.checked,replace:this.replaceField.value});e.eq(this.query)||(this.query=e,this.view.dispatch({effects:ts.of(e)}))}keydown(e){tm(this.view,e,"search-panel")?e.preventDefault():e.keyCode==13&&e.target==this.searchField?(e.preventDefault(),(e.shiftKey?wn:bn)(this.view)):e.keyCode==13&&e.target==this.replaceField&&(e.preventDefault(),Qa(this.view))}update(e){for(let t of e.transactions)for(let i of t.effects)i.is(ts)&&!i.value.eq(this.query)&&this.setQuery(i.value)}setQuery(e){this.query=e,this.searchField.value=e.search,this.replaceField.value=e.replace,this.caseField.checked=e.caseSensitive,this.reField.checked=e.regexp,this.wordField.checked=e.wholeWord}mount(){this.searchField.select()}get pos(){return 80}get top(){return this.view.state.facet(Si).top}}function Ae(n,e){return n.state.phrase(e)}const Is=30,Ns=/[\s\.,:;?!]/;function Yo(n,{from:e,to:t}){let i=n.state.doc.lineAt(e),s=n.state.doc.lineAt(t).to,r=Math.max(i.from,e-
181Is),o=Math.min(s,t+Is),l=n.state.sliceDoc(r,o);if(r!=i.from){for(let a=0;a<Is;a++)if(!Ns.test(l[a+1])&&Ns.test(l[a])){l=l.slice(a);break}}if(o!=s){for(let a=l.length-1;a>l.length-Is;a--)if(!Ns.test(l[a-1])&&Ns.test(l[a])){l=l.slice(0,a);break}}return R.announce.of(`${n.state.phrase("current match")}. ${l} ${n.state.phrase("on line")} ${i.number}.`)}const rb=R.baseTheme({".cm-panel.cm-search":{padding:"2px 6px 4px",position:"relative","& [name=close]":{position:"absolute",top:"0",right:"4px",backgroundColor:"inherit",border:"none",font:"inherit",padding:0,margin:0},"& input, & button, & label":{margin:".2em .6em .2em 0"},"& input[type=checkbox]":{marginRight:".2em"},"& label":{fontSize:"80%",whiteSpace:"pre"}},"&light .cm-searchMatch":{backgroundColor:"#ffff0054"},"&dark .cm-searchMatch":{backgroundColor:"#00ffff8a"},"&light .cm-searchMatch-selected":{backgroundColor:"#ff6a0054"},"&dark .cm-searchMatch-selected":{backgroundColor:"#ff00ff8a"}}),ob=[kt,Ci.low(eb),rb],Wb=[".no-output"];function zb(n){const e=[];let t=[],i=0;for(;i<n.length;){for(;i<n.length&&/\s/.test(n[i]);)i++;if(i>=n.length)break;if(n[i]==="-"&&n[i+1]==="-"){for(;i<n.length&&n[i]!==` 182`;)i++;continue}if(n[i]==="/"&&n[i+1]==="*"){i=Cn(n,i);continue}if(n[i]==="."){const o=i;for(;i<n.length&&n[i]!==` 183`;)i++;t.push(n.slice(o,i).trim());continue}const s=i;for(;i<n.length;){const o=n[i];if(o==="-"&&n[i+1]==="-"){for(;i<n.length&&n[i]!==` 184`;)i++;continue}if(o==="/"&&n[i+1]==="*"){i=Cn(n,i);continue}if(o==="'"||o==='"'){i=Uu(n,i,o);continue}if(o==="$"){const l=qu(n,i);if(l!==null){i=l;continue}}if(o===";")break;i++}const r=n.slice(s,i).trim();r.length>0&&(e.push({sql:r,directives:t}),t=[]),n[i]===";"&&i++}return e}function Cn(n,e){let t=e+2;for(;t<n.length&&!(n[t]==="*"&&n[t+1]==="/");)t++;return t<n.length?t+2:t}function Uu(n,e,t){let i=e+1;for(;i<n.length;){const s=n[i];if(s==="\\"&&i+1<n.length){i+=2;continue}if(s===t){if(n[i+1]===t){i+=2;continue}return i+1}i++}return i}function qu(n,e){let t=e+1;for(;t<n.length&&/[A-Za-z0-9_]/.test(n[t]);)t++;if(t>=n.length||n[t]!=="$")return null;const i=n.slice(e,t+1),s=n.indexOf(i,t+1);return s===-1?n.length:s+i.length}function Vb(n){const e=ab(n);return e==="VISUALIZE"||e==="WITH"&&lb(n)?"visualize":e==="SELECT"||e==="WITH"?"query":"side-effect"}function lb(n){let e=0,t=0;for(;e<n.length;){const i=n[e];if(i==="-"&&n[e+1]==="-"){for(;e<n.length&&n[e]!==` 185`;)e++;continue}if(i==="/"&&n[e+1]==="*"){e=Cn(n,e);continue}if(i==="'"||i==='"'){e=Uu(n,e,i);continue}if(i==="$"){const s=qu(n,e);if(s!==null){e=s;continue}}if(i==="("){t++,e++;continue}if(i===")"){t>0&&t--,e++;continue}if(t===0&&(i==="v"||i==="V")){const s=e>0?n[e-1]:" ";if(!/[A-Za-z0-9_]/.test(s)){const r=n.slice(e,e+9),o=n[e+9];if(/^visualize$/i.test(r)&&(o===void 0||!/[A-Za-z0-9_]/.test(o)))return!0}}e++}return!1}function ab(n){return Qu(n).match(/^[A-Za-z]+/)?.[0]?.toUpperCase()??""}function $b(n){const e=Qu(n),t=/^CREATE\s+(?:OR\s+REPLACE\s+)?(?:TEMP(?:ORARY)?\s+)?(?:TABLE|VIEW)\s+(?:IF\s+NOT\s+EXISTS\s+)?("(?:[^"]|"")+"|[A-Za-z_]\w*)(?![\w.])/i.exec(e);if(!t)return null;let i=t[1];return i.startsWith('"')&&i.endsWith('"')&&(i=i.slice(1,-1).replace(/""/g,'"')),i}function Qu(n){let e=0;for(;e<n.length;){for(;e<n.length&&/\s/.test(n[e]);)e++;if(n[e]==="-"&&n[e+1]==="-"){for(;e<n.length&&n[e]!==` 186`;)e++;continue}if(n[e]==="/"&&n[e+1]==="*"){e=Cn(n,e);continue}break}return n.slice(e)}const hb=["summary_stats","ttest_2samp","mann_whitney_u"],cb=["visualize","draw"],Ub=wi.define({...ur.spec,keywords:`${ur.spec.keywords??""} ${cb.join(" ")}`,builtin:`${ur.spec.builtin??""} ${hb.join(" ")}`});function L(n){return`"${n.replace(/"/g,'""')}"`}function Oi(n){return`'${n.replace(/'/g,"''")}'`}function Vi(n,e){if(n==null||typeof n!="object"||n instanceof Date||n instanceof Uint8Array)return n;if(e?.kind==="decimal"){const a=ub(n);if(a!==null){const h=e.scale;return typeof h=="number"&&h>0?fb(a,Math.pow(10,h)):a}}if(ju(n))return Ku(Gu(n));if(typeof n.length=="number"&&typeof n.toArray=="function"&&typeof n[Symbol.iterator]=="function"){const a=e?.kind==="list"?e.element:void 0,h=[];for(const c of n)h.push(Vi(c,a));return h}if(Array.isArray(n)){const a=e?.kind==="list"?e.element:void 0;return n.map(h=>Vi(h,a))}const s=e?.kind==="struct"?e.fields:[],r={};for(const a of s)r[a.name]=a.type;const o={},l=Object.keys(n);for(let a=0;a<l.length;a++){const h=l[a],c=r[h]??s[a]?.type;o[h]=Vi(n[h],c)}return o}function ja(n,e){return n.map(t=>t.toArray().map((i,s)=>Vi(i,e[s])))}function ub(n){if(ju(n))return Ku(Gu(n));if(typeof n=="object"&&typeof n.toJSON=="function")try{const e=n.toJSON();if(typeof e=="number"||typeof e=="bigint")return e;if(typeof e=="string"&&e.length>0){if(/^-?\d+$/.test(e))try{const i=BigInt(e);return i>=BigInt(Number.MIN_SAFE_INTEGER)&&i<=BigInt(Number.MAX_SAFE_INTEGER)?Number(i):i}catch{}const t=Number(e);if(Number.isFinite(t))return t}}catch{}return null}function ju(n){if(n==null||typeof n!="object"||n instanceof Date||n instanceof Uint8Array||n instanceof DataView)return!1;const e=n.length;if(e!==2&&e!==4)return!1;for(let t=0;t<e;t++)if(typeof n[t]!="number")return!1;return!0}function Gu(n){const e=n.length,t=[];for(let i=0;i<e;i++)t.push(n[i]|0);return t}function Ku(n){if(n.length===0)return 0;if(n.length===1)return n[0];const t=n[n.length-1]<0;let i=0n;for(let s=n.length-1;s>=0;s--)i=i<<32n|BigInt(n[s]>>>0);return t&&(i-=1n<<BigInt(n.length*32)),i>=BigInt(Number.MIN_SAFE_INTEGER)&&i<=BigInt(Number.MAX_SAFE_INTEGER)?Number(i):i}function fb(n,e){if(typeof n=="bigint")return Number(n)/e;if(typeof n=="number")return n/e;if(typeof n=="string"){const t=Number(n);if(!Number.isNaN(t))return t/e}return n}function db(n){if(!(!n||typeof n!="object")){if(typeof n.scale=="number")return n.scale;if(typeof n.toString=="function"){const e=String(n),t=/Decimal\d*\s*[<(]\s*\d+\s*,\s*(\d+)/i.exec(e);if(t)return Number(t[1])}}}function pb(n){const e={};for(const t of n??[]){const i=String(t?.name??"");if(!i)continue;const s=db(t?.type);typeof s=="number"&&s>0&&(e[i]=s)}return e}function mb(n){if(n)try{return new gb(n).parseType()}catch{return}}class gb{s;i=0;constructor(e){this.s=e}parseType(){this.skipWs();const e=this.i,i=this.readIdent().toUpperCase();let s;if(i==="STRUCT"&&this.peekNonWs()==="("){this.expect("(");const r=[];for(this.skipWs();this.peek()!==")";){const o=this.readIdent(),l=this.parseType();if(r.push({name:o,type:l}),this.skipWs(),this.peek()===","){this.i++,this.skipWs();continue}break}this.expect(")"),s={kind:"struct",fields:r}}else if(i==="LIST"&&this.peekNonWs()==="("){this.expect("(");const r=this.parseType();this.skipWs(),this.expect(")"),s={kind:"list",element:r}}else if(i==="MAP"&&this.peekNonWs()==="("){this.expect("(");const r=this.parseType();this.skipWs(),this.expect(",");const o=this.parseType();this.skipWs(),this.expect(")"),s={kind:"map",key:r,value:o}}else if(i==="DECIMAL"||i==="NUMERIC"||i==="DEC"){let r,o;if(this.peekNonWs()==="("){this.expect("("),this.skipWs();const l=this.readIdent();if(l.length>0&&(r=Number(l)),this.skipWs(),this.peek()===","){this.i++,this.skipWs();const a=this.readIdent();a.length>0&&(o=Number(a)),this.skipWs()}this.expect(")")}s={kind:"decimal",precision:r,scale:o}}else{if(this.peekNonWs()==="("){this.expect("(");let r=1;for(;this.i<this.s.length&&r>0;){const o=this.s[this.i++];o==="("?r++:o===")"&&r--}}s={kind:"scalar",name:this.s.slice(e,this.i).trim()}}for(this.skipWs();this.peek()==="[";){for(this.i++;this.i<this.s.length&&/\d/.test(this.s[this.i]);)this.i++;this.skipWs(),this.expect("]"),s={kind:"list",element:s},this.skipWs()}return s}peek(){return this.s[this.i]??""}peekNonWs(){let e=this.i;for(;e<this.s.length&&/\s/.test(this.s[e]);)e++;return this.s[e]??""}skipWs(){for(;this.i<this.s.length&&/\s/.test(this.s[this.i]);)this.i++}expect(e){if(this.skipWs(),this.s[this.i]!==e)throw new Error(`expected '${e}' at ${this.i}`);this.i++}readIdent(){this.skipWs();const e=this.i;for(;this.i<this.s.length&&/[A-Za-z0-9_]/.test(this.s[this.i]);)this.i++;return this.s.slice(e,this.i)}}let Xu;function qb(n){Xu=n}function yb(){return Xu}function bb(n,e){if(!("facet"in n||"repeat"in n||"concat"in n||"hconcat"in n||"vconcat"in n)||n.data)return;const s=(n.spec??n).layer;if(!Array.isArray(s)||s.length===0)return;const r=s.map(o=>o.data?.name).find(o=>
186typeof o=="string"&&o in e);if(r){n.data={name:r};for(const o of s)o.data&&delete o.data}}const Ga="https://vega.github.io/schema/vega-lite/v6.json";function wb(n){const e=n.$schema;typeof e=="string"&&e.includes("/vega-lite/")&&e!==Ga&&(n.$schema=Ga)}function Cb(n){for(const e of Object.values(n))for(const t of e){if(!t||typeof t!="object")continue;const i=t;for(const s of Object.keys(i))typeof i[s]=="bigint"&&(i[s]=Number(i[s]))}}function xb(n){const e=[],t=i=>{if(!i||typeof i!="object")return;const s=i;if(s.encoding&&typeof s.encoding=="object"&&e.push(s.encoding),Array.isArray(s.layer))for(const r of s.layer)t(r);s.spec&&t(s.spec)};return t(n),e}function Sb(n,e){for(const t of Object.values(n))for(const i of t){if(!i||typeof i!="object")continue;const s=i[e];if(s!=null)return s}}function vb(n,e){for(const t of xb(n))for(const i of Object.values(t)){if(!i||typeof i!="object")continue;const s=i;if(s.type!=="quantitative"||typeof s.field!="string")continue;const r=Sb(e,s.field);(typeof r=="string"||typeof r=="boolean")&&(s.type="nominal")}}function Ka(n,e){bb(n,e),Cb(e),vb(n,e),wb(n)}async function Qb(n,e){if(e.visualize){const a=await e.visualize(n),h=a.spec,c=a.datasets;return Ka(h,c),{spec:h,datasets:c}}let t;try{t=await e.executeQuery(n)}catch(a){const h=a instanceof Error?a.message:String(a);if(/syntax error/i.test(h)&&/VISUALIZE/i.test(h)){const c=yb()??"no startup details captured (check browser console)";throw new Error(`VISUALIZE rejected by DuckDB â the stats_duck (ggsql) parser extension didn't load: ${c}`)}throw a}if(!t||t.length===0)throw new Error("VISUALIZE returned no rows â stats_duck parser may not be loaded");const i=t[0];
186if(typeof i.spec!="string")throw new Error("VISUALIZE result is missing the 'spec' column");const s=JSON.parse(i.spec),r=i.layer_sqls,o=[];if(r instanceof Map)for(const[a,h]of r)o.push([String(a),String(h)]);else if(r&&typeof r=="object")for(const[a,h]of Object.entries(r))o.push([a,String(h)]);else throw new Error("VISUALIZE result is missing the 'layer_sqls' map");const l={};for(const[a,h]of o){const{rows:c,decimalScales:u}=await e.executeQueryWithSchema(h);l[a]=c.map(f=>{const d=f&&typeof f.toJSON=="function"?f.toJSON():{...f};for(const[p,m]of Object.entries(u))d[p]=Vi(d[p],{kind:"decimal",scale:m});return d})}return Ka(s,l),{spec:s,datasets:l}}const Yu={parquet:{format:"parquet",ext:"parquet",duckFormat:"parquet",mime:"application/vnd.apache.parquet",label:"Parquet",requiresStatsDuck:!1},json:{format:"json",ext:"json",duckFormat:"json",mime:"application/json",label:"JSON",requiresStatsDuck:!1},xpt:{format:"xpt",ext:"xpt",duckFormat:"xpt",mime:"application/x-sas-xport",label:"SAS Transport (.xpt)",requiresStatsDuck:!0},sav:{format:"sav",ext:"sav",duckFormat:"sav",mime:"application/x-spss-sav",label:"SPSS (.sav)",requiresStatsDuck:!0},por:{format:"por",ext:"por",duckFormat:"por",mime:"application/x-spss-por",label:"SPSS Portable (.por)",requiresStatsDuck:!0},sas7bdat:{format:"sas7bdat",ext:"sas7bdat",duckFormat:"sas7bdat",mime:"application/x-sas-data",label:"SAS7BDAT (.sas7bdat â not real-SAS readable)",requiresStatsDuck:!0}},jb=["parquet","json","xpt","sav","por","sas7bdat"];function Gb(n){return Object.prototype.hasOwnProperty.call(Yu,n)}class Kb{loaded=new Set;backend;customRepository;constructor(e,t){this.backend=e,this.customRepository=t}async tryLoad(e,t,i){try{this.customRepository&&!t&&await this.backend.executeQuery(`SET custom_extension_repository = '${this.customRepository}'`);const s=t?`INSTALL ${e} FROM '${t}'`:`INSTALL ${e}`;if(await this.backend.executeQuery(s),await this.backend.executeQuery(`LOAD ${e}`),this.loaded.add(e),i)for(const r of i)try{await this.backend.executeQuery(r)}catch(o){const l=o instanceof Error?o.message:String(o);if(l.includes("signature mismatch")||l.includes("memory access out of bounds")||l.includes("RuntimeError")||l.includes("unreachable"))return console.warn(`DuckDB extension "${e}" loaded but functions crash in WASM â disabling`),this.loaded.delete(e),!1}return!0}catch{return!1}}isLoaded(e){return this.loaded.has(e)}getLoadedExtensions(){return Array.from(this.loaded)}}function Xb(){const n="/extensions/stats-duck";return n.startsWith("/")?`${window.location.origin}${n}`:n}class Xa{constructor(e,t,i){this.duckDBService=e,this.name=t,this.fileName=i}name="";fileName="";description="";label="";parsedColumnTypes=null;async ensureColumnTypes(){if(this.parsedColumnTypes)return this.parsedColumnTypes;const e=await this.duckDBService.getTableInfo(this.name);return this.parsedColumnTypes=e.map(t=>mb(t.column_type)),this.parsedColumnTypes}setName(e){this.duckDBService.executeQuery(`ALTER TABLE ${L(this.name)} RENAME TO ${L(e)}`).then(()=>{this.name=e})}setDescription(e){this.description=e}setLabel(e){this.label=e}getSourceTable(){return this.name}async getMetadata(){const e=(await this.duckDBService.executeQuery(`SELECT COUNT(*) FROM ${L(this.name)}`))[0].toArray()[0],t=await this.duckDBService.getTableInfo(this.name);return{name:this.name,fileName:this.fileName,description:this.description,label:this.label,totalRows:Number(e),totalColumns:t.length,columns:t.map(i=>({name:i.column_name,key:i.key,extra:i.extra,default:i.default,dataType:tl(i.column_type),rawType:i.column_type,hasNulls:i.nulls==="YES"}))}}async fetchData(e,t){const i=`SELECT * FROM ${L(this.name)} LIMIT ${t-e} OFFSET ${e}`,[s,r]=await Promise.all([this.duckDBService.executeQuery(i),this.ensureColumnTypes()]);return ja(s,r)}async fetchDataColumnRange(e,t,i,s){const a=`SELECT ${(await this.duckDBService.getTableInfo(this.name)).map(f=>f.column_name).slice(i,s).map(L).join(", ")} FROM ${L(this.name)} LIMIT ${t-e} OFFSET ${e}`,[h,c]=await Promise.all([this.duckDBService.executeQuery(a),this.ensureColumnTypes()]),u=c.slice(i,s);return ja(h,u)}async getColumnStatsFiltered(e){return this.getColumnStats(e)}async getColumnStats(e,t=10){const i=typeof e=="string"?e:e.name;let s=typeof e=="string"?void 0:e.dataType;if(!s){const r=await this.duckDBService.getColumnInfo(this.name,i);s=tl(r?.data_type)}try{return ht(s)?await this.getNumericStats(i,s):Li(s)?await this.getTemporalStats(i,s):xn(s)?await this.getBooleanStats(i):Ii(s)?await this.getCategorical
186Stats(i,t):await this.getBasicStats(i)}catch(r){return console.error(`Error getting column stats for ${i}:`,r),null}}async getBasicStats(e){const t=` 187 SELECT COUNT(*) as total_count, 188 COUNT(CASE WHEN ${L(e)} IS NULL THEN 1 END) as null_count, 189 COUNT(DISTINCT ${L(e)}) as distinct_count 190 FROM ${L(this.name)} 191 `,i=(await this.duckDBService.executeQuery(t))[0];return{totalCount:Number(i.total_count),nullCount:Number(i.null_count),distinctCount:Number(i.distinct_count),valueCounts:new Map,isCategorical:!1,numericStats:null}}async getCategoricalStats(e,t){const i=` 192 SELECT COUNT(*) as total_count, 193 COUNT(CASE WHEN ${L(e)} IS NULL THEN 1 END) as null_count, 194 COUNT(DISTINCT ${L(e)}) as distinct_count 195 FROM ${L(this.name)} 196 `,s=(await this.duckDBService.executeQuery(i))[0],r=` 197 SELECT ${L(e)} as val, COUNT(*) as cnt 198 FROM ${L(this.name)} 199 WHERE ${L(e)} IS NOT NULL 200 GROUP BY ${L(e)} 201 ORDER BY cnt DESC 202 LIMIT ${t} 203 `,o=await this.duckDBService.executeQuery(r),l=new Map,a=new Map;for(const h of o){const c=String(h.val);l.set(c,Number(h.cnt)),a.set(c,h.val)}return{totalCount:Number(s.total_count),nullCount:Number(s.null_count),distinctCount:Number(s.distinct_count),valueCounts:l,valueCountsRaw:a,isCategorical:!0,numericStats:null}}async searchColumnValues(e,t){const i=typeof e=="string"?e:e.name,s=L(i),r=`CAST(${s} AS VARCHAR)`;let o;if(t.mode==="regex"){const h=t.query.replace(/'/g,"''");o=`regexp_full_match(${r}, '${h}', 'i')`}else{const h=t.query.replace(/\\/g,"\\\\").replace(/'/g,"''").replace(/[%_]/g,"\\$&");o=`${r} ILIKE '%${h}%' ESCAPE '\\'`}const l=` 204 SELECT ${s} as val, COUNT(*) as cnt 205 FROM ${L(this.name)} 206 WHERE ${s} IS NOT NULL AND ${o} 207 GROUP BY ${s} 208 ORDER BY cnt DESC 209 LIMIT ${t.limit} 210 `;return(await this.duckDBService.executeQuery(l)).map(h=>({value:String(h.val),count:Number(h.cnt)}))}async getBooleanStats(e){const t=` 211 SELECT COUNT(*) as total_count, 212 COUNT(CASE WHEN ${L(e)} IS NULL THEN 1 END) as null_count, 213 COUNT(CASE WHEN ${L(e)} = TRUE THEN 1 END) as true_count, 214 COUNT(CASE WHEN ${L(e)} = FALSE THEN 1 END) as false_count 215 FROM ${L(this.name)} 216 `,i=(await this.duckDBService.executeQuery(t))[0],s=Number(i.true_count),r=Number(i.false_count),o=new Map,l=new Map;return s>0&&(o.set("TRUE",s),l.set("TRUE",!0)),r>0&&(o.set("FALSE",r),l.set("FALSE",!1)),{totalCount:Number(i.total_count),nullCount:Number(i.null_count),distinctCount:(s>0?1:0)+(r>0?1:0),valueCounts:o,valueCountsRaw:l,isCategorical:!0,numericStats:null}}async getNumericStats(e,t){const i=` 217 SELECT COUNT(*) as total_count, 218 COUNT(CASE WHEN ${L(e)} IS NULL THEN 1 END) as null_count, 219 COUNT(DISTINCT ${L(e)}) as distinct_count, 220 CAST(MIN(${L(e)}) AS DOUBLE) as min_val, 221 CAST(MAX(${L(e)}) AS DOUBLE) as max_val, 222 CAST(AVG(${L(e)}) AS DOUBLE) as mean_val, 223 CAST(MEDIAN(${L(e)}) AS DOUBLE) as median_val, 224 CAST(STDDEV(${L(e)}) AS DOUBLE) as stddev_val 225 FROM ${L(this.name)} 226 `,s=(await this.duckDBService.executeQuery(i))[0],r=Number(s.total_count),o=Number(s.null_count),l=Number(s.distinct_count);if(r===o||s.min_val==null||s.max_val==null)return{totalCount:r,nullCount:o,distinctCount:l,isCategorical:!1,valueCounts:new Map,histogramEdges:[],numericStats:null};const a=Number(s.min_val),h=Number(s.max_val),c=r-o,u=kb(t,l,a,h,c),f=new Map,d=[],p=si(t)?Math.floor(h-a)+1:1/0,m=si(t)&&l>0&&l<=20&&p<=50;if(a===h||c===0){if(c>0){const g=Ya(a,h,t);f.set(g,c),d.push(a,h)}}else if(m){const g=` 227 SELECT ${L(e)} as val, COUNT(*) as cnt 228 FROM ${L(this.name)} 229 WHERE ${L(e)} IS NOT NULL 230 GROUP BY ${L(e)} 231 ORDER BY val 232 `,y=await this.duckDBService.executeQuery(g);for(const b of y){const C=Number(b.val);f.set(String(C),Number(b.cnt)),d.push(C)}}else{let g=(h-a)/u;si(t)&&(g=Math.max(1,Math.ceil(g)));const y=` 233 SELECT CAST(FLOOR((CAST(${L(e)} AS DOUBLE) - ${a}) / ${g}) AS INTEGER) AS bin, COUNT(*) AS cnt 234 FROM ${L(this.name)} 235 WHERE ${L(e)} IS NOT NULL 236 GROUP BY bin 237 ORDER BY bin 238 `,b=await this.duckDBService.executeQuery(y),C=[];for(let k=0;k<u;
238k++){const x=a+k*g,T=k===u-1?h:a+(k+1)*g;d.push(x);const v=Ya(x,T,t);C.push(v),f.set(v,0)}d.push(h);for(const k of b){let x=Number(k.bin);x<0&&(x=0),x>=u&&(x=u-1),f.set(C[x],(f.get(C[x])||0)+Number(k.cnt))}}return{totalCount:r,nullCount:o,distinctCount:l,isCategorical:!1,valueCounts:f,histogramEdges:d,numericStats:{min:a,max:h,mean:s.mean_val==null?NaN:Number(s.mean_val),median:s.median_val==null?NaN:Number(s.median_val),stdDev:s.stddev_val==null?NaN:Number(s.stddev_val)}}}async getTemporalStats(e,t){let i;He(t)?i=`CAST(date_diff('day', DATE '1970-01-01', ${L(e)}) AS BIGINT)`:Qt(t)?i=`CAST(EXTRACT(epoch_us FROM ${L(e)}) AS BIGINT)`:i=`CAST(EXTRACT(epoch_us FROM ${L(e)}) AS BIGINT)`;const s=` 239 SELECT COUNT(*) as total_count, 240 COUNT(CASE WHEN ${L(e)} IS NULL THEN 1 END) as null_count, 241 COUNT(DISTINCT ${L(e)}) as distinct_count, 242 CAST(MIN(${i}) AS DOUBLE) as min_val, 243 CAST(MAX(${i}) AS DOUBLE) as max_val 244 FROM ${L(this.name)} 245 `;let r;try{r=(await this.duckDBService.executeQuery(s))[0]}catch{return await this.getCategoricalStats(e,10)}const o=Number(r.total_count),l=Number(r.null_count),a=Number(r.distinct_count),h=o-l;if(h===0||r.min_val==null||r.max_val==null)return{totalCount:o,nullCount:l,distinctCount:a,isCategorical:!1,valueCounts:new Map,valueCountsRaw:new Map,histogramEdges:[],numericStats:null,temporalStats:null};const c=Number(r.min_val),u=Number(r.max_val),f=new Map,d=new Map,p=[];if(!isFinite(c)||!isFinite(u))return{totalCount:o,nullCount:l,distinctCount:a,isCategorical:!1,valueCounts:f,valueCountsRaw:d,histogramEdges:p,numericStats:null,temporalStats:null};if(c===u){const m=Ja(c,t);f.set(m,h),d.set(m,c),p.push(c,u)}else{const m=Math.min(20,Math.max(5,Math.ceil(Math.log2(h)+1))),g=(u-c)/m,y=` 246 SELECT CAST(FLOOR((CAST(${i} AS DOUBLE) - ${c}) / ${g}) AS INTEGER) as bin, COUNT(*) as cnt 247 FROM ${L(this.name)} 248 WHERE ${L(e)} IS NOT NULL 249 GROUP BY bin 250 ORDER BY bin 251 `,b=await this.duckDBService.executeQuery(y),C=[];for(let k=0;k<m;k++){const x=c+k*g;p.push(x);const T=Ja(x,t);C.push(T),f.set(T,0),d.set(T,x)}p.push(u);for(const k of b){let x=Number(k.bin);x<0&&(x=0),x>=m&&(x=m-1),f.set(C[x],(f.get(C[x])||0)+Number(k.cnt))}}return{totalCount:o,nullCount:l,distinctCount:a,isCategorical:!1,valueCounts:f,valueCountsRaw:d,histogramEdges:p,numericStats:null,temporalStats:{min:c,max:u}}}}function kb(n,e,t,i,s){if(s<=1)return 1;if(si(n)){const l=Math.max(1,Math.floor(i-t)+1),a=Math.ceil(Math.log2(s)+1);return Math.max(5,Math.min(30,Math.min(l,a*2)))}const r=Math.ceil(Math.log2(s)+1);let o=Math.max(10,Math.min(30,r*2));return e>0&&e<o&&(o=e),o}function Ya(n,e,t){if(si(t)){const s=Math.round(n),r=Math.round(e);return s===r?String(s):`${s}â${r}`}const i=s=>{if(!isFinite(s))return String(s);const r=Math.abs(s);return r!==0&&(r<.01||r>=1e6)?s.toExponential(2):Number(s.toFixed(2)).toString()};return`${i(n)}â${i(e)}`}function Ja(n,e){if(!isFinite(n))return"";if(He(e)){const i=new Date(n*86400*1e3);return isNaN(i.getTime())?"":i.toISOString().slice(0,10)}if(Qt(e)){const i=Math.floor(n/1e6),s=Math.floor(i/3600),r=Math.floor(i%3600/60),o=i%60,l=a=>a.toString().padStart(2,"0");return`${l(s)}:${l(r)}:${l(o)}`}const t=new Date(n/1e3);return isNaN(t.getTime())?"":t.toISOString().replace("T"," ").slice(0,19)}class Yb{id="duckdb-wasm";displayName="DuckDB (browser, WebAssembly)";capabilities={arrow:!0,visualize:!1,registerFileText:!0,registerFileBuffer:!0,wipeUserState:!0,dropByName:!0,sas:!0,spss:!0,stata:!0};db=null;worker=null;isInitialized=!1;wasm=null;async initialize(){if(!this.isInitialized)try{const e=await vi(()=>import("./duckdb-browser-B6xT6Smf.js"),[]);this.wasm=e;const[t,i,s,r]=await Promise.all([vi(()=>import("./duckdb-browser-mvp.worker-ZlAJ-lVK.js"),[]),vi(()=>import("./duckdb-browser-eh.worker-Bef-XVGK.js"),[]),vi(()=>import("./duckdb-browser-coi.worker-B43pXDi-.js"),[]),vi(()=>import("./duckdb-browser-coi.pthread.worker-BbplXQ69.js"),[])]),o=e.getJsDelivrBundles();o.mvp.mainWorker=t.default,o.eh&&(o.eh.mainWorker=i.default),o.coi&&(o.coi.mainWorker=s.default,o.coi.pthreadWorker=r.default);const l=await e.selectBundle(o);this.worker=new Worker(l.mainWorker);const a=new e.VoidLogger;this.db=new e.AsyncDuckDB(a,this.worker),await this.db.instantiate(l.mainModule,l.pthreadWorker),await this.db.open({allowUnsignedExtensions:!0}),this.isInitialized=!0}catch(e){throw console.error("Failed to initialize DuckDB:",e),e}}async getConnection(){if(!this.db||!this.isInitialized)throw new Error("DuckDB not initialized. Call initialize() first.");return await this.db.connect()}async executeQuery(e){const t=await this.getConnection();try{return(await t.query(e)).toArray()}finally{await t.close()}}async executeQueryWithSchema(e){const t=await this.getConnection();
251try{const i=await t.query(e),s=pb(i?.schema?.fields);return{rows:i.toArray(),decimalScales:s}}finally{await t.close()}}async listTables(){return(await this.executeQuery("SHOW TABLES")).map(e=>e.name)}async getTableInfo(e){return await this.executeQuery(`DESCRIBE ${L(e)}`)}async getColumnInfo(e,t){return(await this.executeQuery(`DESCRIBE ${L(e)}`)).find(s=>s.column_name===t)}async listFunctions(){return(await this.executeQuery("SELECT DISTINCT function_name, function_type FROM duckdb_functions()")).map(t=>{const i=t.function_name,s=t.function_type;return typeof i!="string"||typeof s!="string"?null:{name:i,type:s}}).filter(t=>t!==null)}getDataProvider(e,t){return new Xa(this,e,t??"")}async executeQueryAsDataProvider(e,t){const i=t||`query_result_${Date.now()}`,s=e.replace(/;\s*$/,""),r=await this.getConnection();try{await r.query(`CREATE OR REPLACE TABLE ${L(i)} AS (${s})`)}finally{await r.close()}return new Xa(this,i,"")}async registerFileText(e,t){if(!this.db)throw new Error("DuckDB not initialized");await this.db.registerFileText(e,t)}async registerFileBuffer(e,t){if(!this.db)throw new Error("DuckDB not initialized");await this.db.registerFileBuffer(e,t)}async registerFileURL(e,t,i){if(!this.db||!this.wasm)throw new Error("DuckDB not initialized");await this.db.registerFileURL(e,t,this.wasm.DuckDBDataProtocol.HTTP,!1)}async exportTable(e){if(!this.db)throw new Error("DuckDB not initialized");const t=Yu[e.format],i=`__bedevere_export_${Date.now().toString(36)}.${t.ext}`,s=await this.getConnection();try{await s.query(`COPY ${L(e.table)} TO ${Oi(i)} (FORMAT ${t.duckFormat})`)}finally{await s.close()}const r=await this.db.copyFileToBuffer(i);try{await this.db.dropFile(i)}catch{}const o=e.filenameHint&&e.filenameHint.length>0?e.filenameHint:e.table;return{kind:"bytes",data:r,filename:`${o}.${t.ext}`,mime:t.mime}}isReady(){return this.isInitialized}async cleanup(){this.worker&&(this.worker.terminate(),this.worker=null),this.db=null,this.isInitialized=!1}async wipeUserState(){const e={tables:0,views:0,macros:0,types:0,sequences:0};if(!this.isInitialized)return e;const t=await this.getConnection();try{try{const i=(await t.query("SELECT table_name AS name FROM information_schema.tables WHERE table_schema = 'main' AND table_type = 'VIEW'")).toArray();for(const s of i)try{await t.query(`DROP VIEW IF EXISTS ${L(String(s.name))} CASCADE`),e.views+=1}catch(r){console.warn(`wipeUserState: failed to drop view ${s.name}:`,r)}}catch(i){console.warn("wipeUserState: failed to enumerate views:",i)}try{const i=(await t.query("SELECT table_name AS name FROM information_schema.tables WHERE table_schema = 'main' AND table_type = 'BASE TABLE'")).toArray();for(const s of i)try{await t.query(`DROP TABLE IF EXISTS ${L(String(s.name))} CASCADE`),e.tables+=1}catch(r){console.warn(`wipeUserState: failed to drop table ${s.name}:`,r)}}catch(i){console.warn("wipeUserState: failed to enumerate tables:",i)}try{const i=(await t.query("SELECT DISTINCT function_name AS name FROM duckdb_functions() WHERE schema_name = 'main' AND function_type IN ('macro', 'table_macro') AND internal = false")).toArray();for(const s of i)try{await t.query(`DROP MACRO IF EXISTS ${L(String(s.name))}`),e.macros+=1}catch(r){console.warn(`wipeUserState: failed to drop macro ${s.name}:`,r)}}catch(i){console.warn("wipeUserState: failed to enumerate macros:",i)}try{const i=(await t.query("SELECT type_name AS name FROM duckdb_types() WHERE schema_name = 'main' AND internal = false")).toArray();for(const s of i)try{await t.query(`DROP TYPE IF EXISTS ${L(String(s.name))}`),e.types+=1}catch(r){console.warn(`wipeUserState: failed to drop type ${s.name}:`,r)}}catch(i){console.warn("wipeUserState: failed to enumerate types:",i)}try{const i=(await t.query("SELECT sequence_name AS name FROM duckdb_sequences() WHERE schema_name = 'main'")).toArray();for(const s of i)try{await t.query(`DROP SEQUENCE IF EXISTS ${L(String(s.name))}`),e.sequences+=1}catch(r){console.warn(`wipeUserState: failed to drop sequence ${s.name}:`,r)}}catch(i){console.warn("wipeUserState: failed to enumerate sequences:",i)}}finally{await t.close()}return e}async dropByName(e){if(!this.isInitialized)return null;const t=L(e),i=await this.getConnection();try{const s=(await i.query(`SELECT table_type FROM information_schema.tables WHERE table_schema = 'main' AND table_name = ${Oi(e)}`)).toArray();if(s.length>0){const o=String(s[0].table_type).toUpperCase()==="VIEW";return await i.query(`${o?"DROP VIEW":"DROP TABLE"} IF EXISTS ${t} CASCADE`),o?"view":"table"}if((await i.query(`SELECT 1 AS x FROM duckdb_functions() WHERE schema_name = 'main' AND function_type IN ('macro', 'table_macro') AND internal = false AN
251D function_name = ${Oi(e)} LIMIT 1`)).toArray().length>0)return await i.query(`DROP MACRO IF EXISTS ${t}`),"macro";try{if((await i.query(`SELECT 1 AS x FROM duckdb_types() WHERE schema_name = 'main' AND internal = false AND type_name = ${Oi(e)} LIMIT 1`)).toArray().length>0)return await i.query(`DROP TYPE IF EXISTS ${t}`),"type"}catch{}try{if((await i.query(`SELECT 1 AS x FROM duckdb_sequences() WHERE schema_name = 'main' AND internal = false AND sequence_name = ${Oi(e)} LIMIT 1`)).toArray().length>0)return await i.query(`DROP SEQUENCE IF EXISTS ${t}`),"sequence"}catch{}return null}finally{await i.close()}}}export{wf as $,mb as A,Ub as B,tl as C,ja as D,R as E,Mb as F,Ab as G,Ho as H,zb as I,Vb as J,Wb as K,$b as L,Qb as M,Me as N,el as O,Ci as P,Vs as Q,Tb as R,hb as S,zf as T,Oi as U,Kb as V,Xb as W,hf as X,lf as Y,Cf as Z,vi as _,Db as a,bf as a0,Gb as a1,jb as a2,Yu as a3,qb as a4,Yb as a5,Xa as a6,wr as a7,Ib as b,Nb as c,xc as d,Ob as e,Fb as f,Pb as g,_b as h,Po as i,Hb as j,$f as k,Af as l,Py as m,_y as n,W as o,Bs as p,L as q,Li as r,Bb as s,M as t,He as u,Qt as v,dt as w,xn as x,ht as y,Ii as z};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.