@telepath-computer/television 1.4.27 → 1.4.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.cjs
CHANGED
|
@@ -54221,7 +54221,7 @@ function disabledTelemetryRuntime() {
|
|
|
54221
54221
|
|
|
54222
54222
|
// ../server/src/updates/version.ts
|
|
54223
54223
|
function readVersionStamp() {
|
|
54224
|
-
if ("1.4.
|
|
54224
|
+
if ("1.4.28".length > 0) return "1.4.28";
|
|
54225
54225
|
return void 0;
|
|
54226
54226
|
}
|
|
54227
54227
|
function resolveUpdateReleaseVersion(env = process.env, stamp = readVersionStamp()) {
|
|
@@ -56635,8 +56635,8 @@ var Server = class {
|
|
|
56635
56635
|
};
|
|
56636
56636
|
};
|
|
56637
56637
|
function readServerPackageVersion() {
|
|
56638
|
-
if ("1.4.
|
|
56639
|
-
return telemetryVersion("1.4.
|
|
56638
|
+
if ("1.4.28".length > 0) {
|
|
56639
|
+
return telemetryVersion("1.4.28");
|
|
56640
56640
|
}
|
|
56641
56641
|
const packageJsonPath = import_node_path16.default.resolve(import_node_path16.default.dirname((0, import_node_url.fileURLToPath)(import_meta.url)), "..", "package.json");
|
|
56642
56642
|
if (!(0, import_node_fs12.existsSync)(packageJsonPath)) return telemetryVersion("0.0.0");
|
|
@@ -59176,8 +59176,8 @@ function resolveVercelSkillsInstallerBin() {
|
|
|
59176
59176
|
return localRequire.resolve("skills/bin/cli.mjs");
|
|
59177
59177
|
}
|
|
59178
59178
|
function readCLIVersion() {
|
|
59179
|
-
if ("1.4.
|
|
59180
|
-
return "1.4.
|
|
59179
|
+
if ("1.4.28".length > 0) {
|
|
59180
|
+
return "1.4.28";
|
|
59181
59181
|
}
|
|
59182
59182
|
const devPackageJsonPath = import_node_path23.default.join(getDevPackageDir(), "package.json");
|
|
59183
59183
|
if (!(0, import_node_fs19.existsSync)(devPackageJsonPath)) {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
</span>`)}function xZ({textContent:i,classes:t}){return L(t)?`<span class="${t.join(" ")}">${ig(i)}</span>`:ig(i)}const yZ=[{type:"table",location:"bottom-right"},{type:"table",location:"right"},{type:"table",location:"bottom"}];function kZ({row:i,col:t},e){const n=[{type:"header",location:"col",index:t},{type:"border",location:"top",index:i}],r=[{type:"border",location:"col",index:t+1},{type:"border",location:"row",index:i+1}],s=[{type:"header",location:"row",index:i},{type:"border",location:"left",index:i}];return[...e.top?n:[],...r,...e.left?s:[]]}function QZ({location:i,type:t},e){return t==="header"?{location:i,type:t,index:e[i]}:i==="top"?{location:i,type:t,index:e.row}:i==="left"?{location:i,type:t,index:e.col}:{location:i,type:t,index:e[i]+1}}function kf(i,t){return(i==null?void 0:i.type)!==(t==null?void 0:t.type)||(i==null?void 0:i.location)!==(t==null?void 0:t.location)?!1:(i==null?void 0:i.type)==="table"||(t==null?void 0:t.type)==="table"?!0:(i==null?void 0:i.index)===(t==null?void 0:t.index)}class vc{constructor(t,e){C(this,"state");C(this,"extraTags");this.state=t,this.extraTags=e}style(t){return lQ(this.state,L(this.extraTags)?[...t,...this.extraTags]:t)}static of(t,e){return new vc(t,e)}}function sv(i){return rh(i).type==="None"}function ov(i){return!sv(i)}function rg(i){return ov(i)?rh(i).getRangeAt(0).startOffset:void 0}function $Z(i){return ov(i)?rh(i).getRangeAt(0).startContainer:void 0}function CZ(i){rh(i).empty()}function rh(i){return i.getSelection()}var Os,ps,ms,gs,bs,ws,Ss,vs,xs,ys,ks,Qs,$s,Cs,Ps,Ts,As,Rs,Zs,Xs,Es,Ls,Ms,zs,_s,Is,js,Ds,Ys,Ws,Vs;const sO=class sO{constructor({table:t,selection:e,scrollElement:n,rootEditor:r,menuRootElement:s,extensions:o,markdownConfig:l,globalKeyBindings:a,selectionType:c,lineWrapping:h,onUndo:u,onRedo:f,onNavigate:d,onDelete:O}){A(this,Os);A(this,ps);A(this,ms);A(this,gs);A(this,bs);A(this,ws);A(this,Ss);A(this,vs);A(this,xs);A(this,ys);A(this,ks);A(this,Qs);A(this,$s);A(this,Cs);A(this,Ps);A(this,Ts);A(this,As);A(this,Rs);A(this,Zs);A(this,Xs);A(this,Es);A(this,Ls);A(this,Ms);A(this,zs);A(this,_s);A(this,Is);A(this,js);A(this,Ds);A(this,Ys);A(this,Ws);A(this,Vs);R(this,Os,H(t)),R(this,ps,H(e)),R(this,ms,ct(!1));const p=this.selection.isCell()?this.selection.cell:void 0;R(this,gs,ct(p)),R(this,bs,ct(p)),R(this,ws,ct(L(p)?rt.ofCell(p):void 0)),R(this,Ss,H(r)),R(this,vs,H(o)),R(this,xs,H(l)),R(this,ys,H(a)),R(this,ks,H(c)),R(this,Qs,H(h)),R(this,$s,ct(void 0)),R(this,Cs,ct(void 0)),R(this,Ps,H(n)),R(this,Ts,H(s)),R(this,As,H(()=>vc.of(this.rootEditor.state,[v.heading]))),R(this,Rs,H(()=>vc.of(this.rootEditor.state))),R(this,Zs,H(u)),R(this,Xs,H(f)),R(this,Es,H(d)),R(this,Ls,H(O)),R(this,Ms,ct(!1)),R(this,zs,ct(void 0)),R(this,_s,ct(void 0)),R(this,Is,ct(void 0)),R(this,js,ct(void 0)),R(this,Ds,ct(void 0)),R(this,Ys,ct(void 0)),R(this,Ws,H(()=>V(this.move)&&V(this.resize)&&V(this.menu)&&V(this.outline))),R(this,Vs,ct(!1));const m=H(()=>{var g;if(Uc(this.window)){if(L(this.menu))return"default";if(L(this.activeHandle)){const{type:b,location:S}=this.activeHandle.handle;if(b==="table"){if(S==="right")return"col-resize";if(S==="bottom-right")return"nwse-resize";if(S==="bottom")return"row-resize"}else{if(b==="border")return S==="top"?"row-resize":S==="left"?"col-resize":`${S}-resize`;if(b==="header")return this.pointerDown?"grabbing":this.activeHandle.state==="hover"?"pointer":void 0}}else{if(((g=this.outline)==null?void 0:g.outlined)??!1)return"cell";if(L(this.hoveredCell))return"text"}}});Dd([()=>this.selectionValue],()=>{if(this.selectionChanged){this.selectionChanged=!1;return}this.selection.isCell()?(this.activeCell=this.selection.cell,this.anchorCell=this.selection.cell,this.outlinedSection=rt.ofCell(this.selection.cell)):this.selection.isHidden()?(this.focusTable(),this.activeCell=void 0,this.anchorCell=void 0,this.outlinedSection=void 0):(this.activeTable=!1,this.activeCell=void 0,this.anchorCell=void 0,this.outlinedSection=void 0)}),Kc(()=>{this.document.body.style.cursor=$(m)??""})}get table(){return $(w(this,Os))}set table(t){q(w(this,Os),t)}get _selection(){return $(w(this,ps))}set _selection(t){q(w(this,ps),t)}get selectionChanged(){return $(w(this,ms))}set selectionChanged(t){q(w(this,ms),t,!0)}get activeCell(){return $(w(this,gs))}set activeCell(t){q(w(this,gs),t)}get anchorCell(){return $(w(this,bs))}set anchorCell(t){q(w(this,bs),t)}get outlinedSection(){return $(w(this,ws))}set outlinedSection(t){q(w(this,ws),t)}get rootEditor(){return $(w(this,Ss))}set rootEditor(t){q(w(this,Ss),t)}get extensions(){return $(w(this,vs))}set extensions(t){q(w(this,vs),t)}get markdownConfig(){return $(w(this,xs))}set markdownConfig(t){q(w(this,xs),t)}get globalKeyBindings(){return $(w(this,ys))}set globalKeyBindings(t){q(w(this,ys),t)}get selectionType(){return $(w(this,ks))}set selectionType(t){q(w(this,ks),t)}get lineWrapping(){return $(w(this,Qs))}set lineWrapping(t){q(w(this,Qs),t)}get wrapperElement(){return $(w(this,$s))}set wrapperElement(t){q(w(this,$s),t)}get tableElement(){return $(w(this,Cs))}set tableElement(t){q(w(this,Cs),t)}get scrollElement(){return $(w(this,Ps))}set scrollElement(t){q(w(this,Ps),t)}get menuRootElement(){return $(w(this,Ts))}set menuRootElement(t){q(w(this,Ts),t)}get headerCellHighlighter(){return $(w(this,As))}set headerCellHighlighter(t){q(w(this,As),t)}get dataCellHighlighter(){return $(w(this,Rs))}set dataCellHighlighter(t){q(w(this,Rs),t)}get onUndo(){return $(w(this,Zs))}set onUndo(t){q(w(this,Zs),t)}get onRedo(){return $(w(this,Xs))}set onRedo(t){q(w(this,Xs),t)}get onNavigate(){return $(w(this,Es))}set onNavigate(t){q(w(this,Es),t)}get onDelete(){return $(w(this,Ls))}set onDelete(t){q(w(this,Ls),t)}get activeTable(){return $(w(this,Ms))}set activeTable(t){q(w(this,Ms),t)}get hoveredCell(){return $(w(this,zs))}set hoveredCell(t){q(w(this,zs),t)}get activeHandle(){return $(w(this,_s))}set activeHandle(t){q(w(this,_s),t)}get menu(){return $(w(this,Is))}set menu(t){q(w(this,Is),t)}get move(){return $(w(this,js))}set move(t){q(w(this,js),t)}get outline(){return $(w(this,Ds))}set outline(t){q(w(this,Ds),t)}get resize(){return $(w(this,Ys))}set resize(t){q(w(this,Ys),t)}get interactive(){return $(w(this,Ws))}set interactive(t){q(w(this,Ws),t)}get pointerDown(){return $(w(this,Vs))}set pointerDown(t){q(w(this,Vs),t)}static of(t){return new sO(t)}focusTable(){this.activeTable=!0,this.tableElement.focus({preventScroll:!0}),this.selectionValue="hidden",CZ(this.document)}scrollToCell(t){requestAnimationFrame(()=>{var e;(e=Sc(this.tableElement,t))==null||e.scrollIntoView({inline:"nearest",block:"nearest"})})}scrollToFirstCell(t,e){requestAnimationFrame(()=>{var n;(n=Sc(this.tableElement,{...this.table.firstCellLocation,[t]:e}))==null||n.scrollIntoView({inline:"nearest",block:"nearest"})})}get document(){return this.rootEditor.dom.ownerDocument}get window(){return this.document.defaultView??window}get rootScrollElement(){return this.rootEditor.scrollDOM}get scrollOffsetX(){return this.rootScrollElement.scrollLeft+this.scrollElement.scrollLeft}get scrollOffsetY(){return this.rootScrollElement.scrollTop+this.scrollElement.scrollTop}deleteTable(){this.onDelete()}navigate(t){this.onNavigate(t)}undo(){this.onUndo()}redo(){this.onRedo()}get selection(){return this._selection}get selectionValue(){return this._selection.value}set selectionValue(t){ih(this._selection.value,t)||(this._selection.value=t,this.selectionChanged=!0)}highlighter({row:t}){return t===this.table.firstRowIndex?this.headerCellHighlighter:this.dataCellHighlighter}cellHandleState(t,e){var n,r,s,o,l;return e.type==="border"||((n=this.activeHandle)==null?void 0:n.state)=="active"?kf((r=this.activeHandle)==null?void 0:r.handle,e)?(s=this.activeHandle)==null?void 0:s.state:void 0:kf((o=this.activeHandle)==null?void 0:o.handle,e)||t[e.location]===((l=this.activeCell)==null?void 0:l[e.location])?"hover":void 0}};Os=new WeakMap,ps=new WeakMap,ms=new WeakMap,gs=new WeakMap,bs=new WeakMap,ws=new WeakMap,Ss=new WeakMap,vs=new WeakMap,xs=new WeakMap,ys=new WeakMap,ks=new WeakMap,Qs=new WeakMap,$s=new WeakMap,Cs=new WeakMap,Ps=new WeakMap,Ts=new WeakMap,As=new WeakMap,Rs=new WeakMap,Zs=new WeakMap,Xs=new WeakMap,Es=new WeakMap,Ls=new WeakMap,Ms=new WeakMap,zs=new WeakMap,_s=new WeakMap,Is=new WeakMap,js=new WeakMap,Ds=new WeakMap,Ys=new WeakMap,Ws=new WeakMap,Vs=new WeakMap;let Qf=sO;function lv({tableState:i,event:t}){if(V(i.outlinedSection))return;t==null||t.preventDefault();const e=Um(i.outlinedSection.rowRange,i.table.rowRange),n=Um(i.outlinedSection.colRange,i.table.colRange),r=n&&!e&&Qn(i.outlinedSection.rowRange).every(l=>i.table.hasEmptyRowAt(l)),s=e&&!n&&Qn(i.outlinedSection.colRange).every(l=>i.table.hasEmptyColAt(l)),o=e&&n&&Qn(i.outlinedSection.colRange).every(l=>i.table.hasEmptyColAt(l));if(r){i.table.removeRowsAt({row:i.outlinedSection.startRow,count:i.outlinedSection.rowCount});const l=i.table.hasRowAt(i.outlinedSection.startRow)?i.outlinedSection.startRow:i.table.lastRowIndex,a={row:l,col:i.table.lastColIndex};i.outlinedSection=rt.of({row:{start:l,endExclusive:l+1},col:i.table.colRange}),i.activeCell=a,i.anchorCell=a}else if(s){i.table.removeColsAt({col:i.outlinedSection.startCol,count:i.outlinedSection.colCount});const l=i.table.hasColAt(i.outlinedSection.startCol)?i.outlinedSection.startCol:i.table.lastColIndex,a={row:i.table.lastRowIndex,col:l};i.outlinedSection=rt.of({row:i.table.rowRange,col:{start:l,endExclusive:l+1}}),i.activeCell=a,i.anchorCell=a}else o?i.deleteTable():i.table.clearSection(i.outlinedSection)}function av(i){hv(i,"copy")}function cv(i){hv(i,"cut")}function Yd({event:i,tableState:t}){if(V(t.outlinedSection))return;const e=i.clipboardData.getData("text/plain"),n=wl.maybeOf(B.of(e.split(/\r\n|\n|\r/)));L(n)?(i.preventDefault(),i.stopPropagation(),sg(n,t)):t.selection.isCell()||(i.preventDefault(),i.stopPropagation(),sg(PZ(e),t))}function sg(i,t){const{startRow:e,startCol:n,rowCount:r,colCount:s}=t.outlinedSection,o=Am(r/i.rowCount),l=Am(s/i.colCount);i.tile({rowRepeat:ce(o-1,{min:0}),colRepeat:ce(l-1,{min:0})}),t.table.merge(i,{row:e,col:n}),t.outlinedSection=rt.of({row:{start:e,endExclusive:e+i.rowCount},col:{start:n,endExclusive:n+i.colCount}}),V(t.anchorCell)&&(t.anchorCell=t.activeCell);const a=t.anchorCell.row<=t.activeCell.row,c=t.anchorCell.col<=t.activeCell.col;t.anchorCell=t.outlinedSection.cornerCellAt(`${a?"top":"bottom"}-${c?"left":"right"}`),t.activeCell=t.outlinedSection.cornerCellAt(`${a?"bottom":"top"}-${c?"right":"left"}`),t.focusTable()}function PZ(i){const{text:t}=I1([[le(i)]],["none"]);return wl.of(t)}function hv({event:i,tableState:t},e){var r;if(V(t.outlinedSection)||t.selection.isCell())return;i.preventDefault(),i.stopPropagation();const n=t.table.sliceSectionAt(t.outlinedSection);(r=i.clipboardData)==null||r.setData("text/plain",n.text.toString()),e==="cut"&&lv({tableState:t})}function TZ(i){i.pointerDown=!0}function AZ(i){i.pointerDown=!1}function RZ(i){i.pointerDown=!1}function ZZ(i,t){t.selection.isCell()||av({tableState:t,event:i})}function XZ(i,t){t.selection.isCell()||cv({tableState:t,event:i})}function EZ(i,t){t.selection.isCell()||Yd({tableState:t,event:i})}const Wd="CellView";function uv(i){return BS(i,{component:Wd})}function LZ(i){return VS(i,{component:Wd})}const kn="\0";function fv(i,t,{trim:e}){const n=iv(i),{from:r,to:s}=ev(i),o=t.toString(),l=B.of(`${o.slice(0,r)}${kn}${o.slice(r,s)}${kn}${o.slice(s)}`.split(`
|
|
63
63
|
`)),a=kd(l,{trim:e}).toString(),c=a.indexOf(kn),h=a.lastIndexOf(kn)-1;return n?{anchor:c,head:h}:{head:c,anchor:h}}function og(i,t){const e=iv(i),{from:n,to:r}=ev(i),s=t.toString(),o=B.of(`${s.slice(0,n)}${kn}${s.slice(n,r)}${kn}${s.slice(r)}`.split(`
|
|
64
64
|
`)),l=pc(o).toString(),a=l.indexOf(kn),c=l.lastIndexOf(kn)-1;return e?{anchor:a,head:c}:{head:a,anchor:c}}function MZ(i){if(V(i.tableElement)||sv(i.document))return;const t=$Z(i.document);if(V(t)||!YS(i.tableElement,t))return;const e=Wl(t);if(V(e))return;const n=nh(e);i.selection.isCell()&&Pr(i.selection.cell,n)||(i.activeTable=!1,i.selectionValue={cell:n,section:zZ(i.document,t)},i.activeCell=n,i.anchorCell=n,i.outlinedSection=rt.ofCell(n))}function zZ(i,t){const e=uv(t),n=j5({ancestor:e,descendent:t,getText:l=>_5(l)?`
|
|
65
|
-
`:l.textContent??""})??"",r=(t.textContent??"").slice(0,rg(i)),s=le(`${n}${r}`),o=n.length+rg(i);return fv({anchor:o,head:o},s,{trim:!1})}function _Z(i,t){var e=zd(),n=Xt(e);$r(n,()=>t.children),I(i,e)}function IZ(i,t){Dn(t,!0),th(()=>{const e=zS(_Z,{target:t.to,context:VR(),props:{children:t.children}});return()=>{_S(e)}}),Yn()}YR();var jZ=ot('<div class="tbl-blocking-overlay" aria-hidden="true"></div>');function DZ(i){var t=jZ();I(i,t)}function xc(i,t){const e=t.devicePixelRatio;return MA(i*e)/e}function YZ({x:i,y:t},e){return{x:xc(i,e),y:xc(t,e)}}var WZ=ot('<th class="tbl-cell tbl-header-cell"><!></th>'),VZ=ot('<td class="tbl-cell tbl-data-cell"><!></td>');function BZ(i,t){Dn(t,!0);const e=H(()=>ng(L(t.movement)?t.movement.border:{top:t.position.top,right:!0,bottom:!0,left:t.position.left})),n=H(()=>ng(t.outline)),r=H(()=>{var u;if(V((u=t.movement)==null?void 0:u.translate))return;const{x:c,y:h}=t.movement.state==="moving"?YZ(t.movement.translate,t.win):t.movement.translate;return`translate3d(${c}px, ${h}px, 0px)`});var s=zd(),o=Xt(s);{var l=c=>{var h=WZ();let u;var f=Ue(h);$r(f,()=>t.children),se(d=>{var O;$t(h,"align",t.alignment==="none"?void 0:t.alignment),$t(h,"data-component",Sl),$t(h,"data-row",t.location.row),$t(h,"data-col",t.location.col),$t(h,"data-border",$(e)),$t(h,"data-outline",$(n)),$t(h,"data-selected",d),$t(h,"data-state",(O=t.movement)==null?void 0:O.state),u=gc(h,"",u,{transform:$(r)})},[()=>gr(t.selected)]),I(c,h)},a=c=>{var h=VZ();let u;var f=Ue(h);$r(f,()=>t.children),se(d=>{var O;$t(h,"align",t.alignment==="none"?void 0:t.alignment),$t(h,"data-component",Sl),$t(h,"data-row",t.location.row),$t(h,"data-col",t.location.col),$t(h,"data-border",$(e)),$t(h,"data-outline",$(n)),$t(h,"data-selected",d),$t(h,"data-state",(O=t.movement)==null?void 0:O.state),u=gc(h,"",u,{transform:$(r)})},[()=>gr(t.selected)]),I(c,h)};Ft(o,c=>{t.position.top?c(l):c(a,!1)})}I(i,s),Yn()}function dv(i){var t;return L((t=bl(i.dom).activeElement)==null?void 0:t.closest(".cm-panels"))}function lg(i){return i.trim().split(/\s+/)}function qZ({doc:i,selection:t,parent:e,extensions:n,markdownConfig:r,selectionType:s,lineWrapping:o,globalKeyBindings:l,rootEditor:a,highlighter:c,onChange:h,eventHandlers:u}){return new z({doc:i,selection:t,parent:e,extensions:[n,hn.lowest([z.editorAttributes.of(f=>{const d=new Set(lg(a.themeClasses)),O=new Set(lg(f.themeClasses));return{class:[...d.difference(O)].join(" ")}}),Mn.of([...l.map(f=>({...f,run:L(f.run)?()=>f.run(a):void 0,shift:L(f.shift)?()=>f.shift(a):void 0}))]),s==="codemirror"?wk():[],b0(c),Ml({extensions:[E1,r.extensions??[]],addKeymap:!1,completeHTMLTags:r.completeHTMLTags,pasteURLAsLink:r.pasteURLAsLink,htmlTagLanguage:r.htmlTagLanguage}),z.domEventObservers(u),o==="wrap"?z.lineWrapping:[]])],dispatchTransactions:(f,d)=>{d.update(f),f.forEach(h)}})}var NZ=ot('<div class="tbl-cell-editor"></div>');function GZ(i,t){Dn(t,!0);let e=bf(t,"text",15),n=bf(t,"selection",15),r,s,o=!1,l=!1;function a(h){const{docChanged:u,newDoc:f,selection:d}=h;if(o)return;const O=L(d);if(u||O){if(u){const p=kd(f,{trim:!0});p.eq(e())||(e(p),l=!0)}if(O){const{head:p,anchor:m}=d.main,g=fv({head:p,anchor:m},f,{trim:!0});tv(g,n())||(n(g),l=!0)}}}Dd([()=>e(),()=>n()],()=>{if(l){l=!1;return}o=!0,s.dispatch({changes:s.state.changes({from:0,to:s.state.doc.length,insert:pc(e())}),selection:og(n(),e())}),o=!1},{lazy:!0}),th(()=>(s=qZ({doc:pc(e()),selection:og(n(),e()),parent:r,selectionType:t.selectionType,lineWrapping:t.lineWrapping,extensions:t.extensions,markdownConfig:t.markdownConfig,globalKeyBindings:t.globalKeyBindings,rootEditor:t.rootEditor,highlighter:t.highlighter,onChange:a,eventHandlers:{beforeinput:t.onbeforeinput,dragstart:t.ondragstart,keydown:(h,{state:u})=>t.onkeydown(h,u),paste:t.onpaste}}),dv(s)||s.focus(),()=>s.destroy()));var c=NZ();bc(c,h=>r=h,()=>r),I(i,c),Yn()}class sh{constructor({event:t,tableState:e,position:n}){C(this,"event");C(this,"tableState");C(this,"position");this.event=t,this.tableState=e,this.position=n}static navigate(t){new sh(t)[`navigate${t.key}`]()}navigateTab(){this.moveRight({createRow:!1,position:"end"})}navigateShiftTab(){this.moveLeft({createRow:!1,position:"end"})}navigateEnter(){this.moveDown({createRow:!1,position:"end"})}navigateArrowLeft(){this.position.left&&this.moveLeft({createRow:!1,position:"end"})}navigateArrowUp(){this.position.top&&this.moveUp({createRow:!1,position:"end"})}navigateArrowRight(){this.position.right&&this.moveRight({createRow:!1,position:"start"})}navigateArrowDown(){this.position.bottom&&this.moveDown({createRow:!1,position:"end"})}navigateShiftArrowLeft(){if(!(!this.position.left||V(this.tableState.outlinedSection)||V(this.tableState.activeCell))){if(this.event.preventDefault(),this.tableState.focusTable(),V(this.tableState.anchorCell)&&(this.tableState.anchorCell=this.tableState.activeCell),this.tableState.outlinedSection.endCol===this.tableState.anchorCell.col){if(this.tableState.outlinedSection.startCol===this.tableState.table.firstColIndex)return;this.tableState.outlinedSection=this.tableState.outlinedSection.expandLeft()}else this.tableState.outlinedSection=this.tableState.outlinedSection.contractLeft();this.tableState.activeCell=JS(this.tableState.activeCell)}}navigateShiftArrowUp(){if(!(!this.position.top||V(this.tableState.outlinedSection)||V(this.tableState.activeCell))){if(this.event.preventDefault(),this.tableState.focusTable(),V(this.tableState.anchorCell)&&(this.tableState.anchorCell=this.tableState.activeCell),this.tableState.outlinedSection.endRow===this.tableState.anchorCell.row){if(this.tableState.outlinedSection.startRow===this.tableState.table.firstRowIndex)return;this.tableState.outlinedSection=this.tableState.outlinedSection.expandUp()}else this.tableState.outlinedSection=this.tableState.outlinedSection.contractUp();this.tableState.activeCell=HS(this.tableState.activeCell)}}navigateShiftArrowRight(){if(!(!this.position.right||V(this.tableState.outlinedSection)||V(this.tableState.activeCell))){if(this.event.preventDefault(),this.tableState.focusTable(),V(this.tableState.anchorCell)&&(this.tableState.anchorCell=this.tableState.activeCell),this.tableState.outlinedSection.startCol===this.tableState.anchorCell.col){if(this.tableState.outlinedSection.endCol===this.tableState.table.lastColIndex)return;this.tableState.outlinedSection=this.tableState.outlinedSection.expandRight()}else this.tableState.outlinedSection=this.tableState.outlinedSection.contractRight();this.tableState.activeCell=FS(this.tableState.activeCell)}}navigateShiftArrowDown(){if(!(!this.position.bottom||V(this.tableState.outlinedSection)||V(this.tableState.activeCell))){if(this.event.preventDefault(),this.tableState.focusTable(),V(this.tableState.anchorCell)&&(this.tableState.anchorCell=this.tableState.activeCell),this.tableState.outlinedSection.startRow===this.tableState.anchorCell.row){if(this.tableState.outlinedSection.endRow===this.tableState.table.lastRowIndex)return;this.tableState.outlinedSection=this.tableState.outlinedSection.expandDown()}else this.tableState.outlinedSection=this.tableState.outlinedSection.contractDown();this.tableState.activeCell=KS(this.tableState.activeCell)}}moveLeft({createRow:t,position:e}){if(!V(this.tableState.activeCell)){if(this.event.preventDefault(),Pr(this.tableState.activeCell,this.tableState.table.firstCellLocation)){if(!t){this.tableState.navigate("before");return}this.tableState.table.prependEmptyRows(1),this.tableState.activeCell={row:this.tableState.activeCell.row+1,col:this.tableState.activeCell.col}}this.moveTo(this.tableState.activeCell.col===this.tableState.table.firstColIndex?{row:this.tableState.activeCell.row-1,col:this.tableState.table.lastColIndex}:{row:this.tableState.activeCell.row,col:this.tableState.activeCell.col-1},e)}}moveUp({createRow:t,position:e}){if(!V(this.tableState.activeCell)){if(this.event.preventDefault(),this.tableState.activeCell.row===this.tableState.table.firstRowIndex){if(!t){this.tableState.navigate("before");return}this.tableState.table.prependEmptyRows(1),this.tableState.activeCell={row:this.tableState.activeCell.row+1,col:this.tableState.activeCell.col}}this.moveTo({row:this.tableState.activeCell.row-1,col:this.tableState.activeCell.col},e)}}moveRight({createRow:t,position:e}){if(!V(this.tableState.activeCell)){if(this.event.preventDefault(),Pr(this.tableState.activeCell,this.tableState.table.lastCellLocation)){if(!t){this.tableState.navigate("after");return}this.tableState.table.appendEmptyRows(1)}this.moveTo(this.tableState.activeCell.col===this.tableState.table.lastColIndex?{row:this.tableState.activeCell.row+1,col:this.tableState.table.firstColIndex}:{row:this.tableState.activeCell.row,col:this.tableState.activeCell.col+1},e)}}moveDown({createRow:t,position:e}){if(!V(this.tableState.activeCell)){if(this.event.preventDefault(),this.tableState.activeCell.row===this.tableState.table.lastRowIndex){if(!t){this.tableState.navigate("after");return}this.tableState.table.appendEmptyRows(1)}this.moveTo({row:this.tableState.activeCell.row+1,col:this.tableState.activeCell.col},e)}}moveTo(t,e){if(this.tableState.activeCell=t,this.tableState.anchorCell=t,this.tableState.outlinedSection=rt.ofCell(t),this.tableState.selection.isCell()){const n=e==="start"?0:this.tableState.table.cellAt(t).length;this.tableState.selectionValue={cell:t,section:{anchor:n,head:n}}}}}const bt={alt:"Alt",arrowDown:"ArrowDown",arrowLeft:"ArrowLeft",arrowRight:"ArrowRight",arrowUp:"ArrowUp",backspace:"Backspace",c:"c",delete:"Delete",enter:"Enter",escape:"Escape",shift:"Shift",tab:"Tab",v:"v",x:"x"},UZ=[bt.arrowDown,bt.arrowLeft,bt.arrowRight,bt.arrowUp,bt.enter,bt.tab,`${bt.shift}${bt.arrowDown}`,`${bt.shift}${bt.arrowLeft}`,`${bt.shift}${bt.arrowRight}`,`${bt.shift}${bt.arrowUp}`,`${bt.shift}${bt.tab}`],ag=new Set(UZ);function Ov({key:i,shiftKey:t,altKey:e,metaKey:n,ctrlKey:r}){if(!(e||n||r))return t?ag.has(`${bt.shift}${i}`)?`${bt.shift}${i}`:void 0:ag.has(i)?i:void 0}function HZ(i,t){i.inputType==="historyUndo"?(t.undo(),i.preventDefault()):i.inputType==="historyRedo"&&(t.redo(),i.preventDefault())}function FZ(i){i.preventDefault()}function KZ(i,t,e){const n=Ov(i);if(V(n))return;const r=t.selection.main.head,s=t.doc.lineAt(r).number,o=0,l=t.doc.length,a=1,c=t.doc.lines,h={top:s===a,right:r===l,bottom:s===c,left:r===o};sh.navigate({tableState:e,key:n,event:i,position:h})}function JZ(i,t){Yd({tableState:t,event:i})}var tX=ot('<div class="tbl-cell-view" contenteditable="" tabindex="-1"><!></div>');function eX(i,t){Dn(t,!0);var e=tX(),n=Ue(e);$r(n,()=>t.children),se(r=>{$t(e,"data-component",Wd),$t(e,"data-hidden",r)},[()=>gr(t.hidden)]),I(i,e),Yn()}const pv="Handle";function Vd(i){if(!qS(i,{component:pv}))return;const{type:t,location:e}=_d(i).dataset;if(t==="table")return{type:t,location:e};{const n=nh(Wl(i));return QZ({location:e,type:t},n)}}var iX=ri('<svg class="tbl-handle-grip" width="15" height="3" fill="currentColor" viewBox="0 0 15 3" xmlns="http://www.w3.org/2000/svg"><circle cx="1.5" cy="1.5" r="1.5"></circle><circle cx="7.5" cy="1.5" r="1.5"></circle><circle cx="13.5" cy="1.5" r="1.5"></circle></svg>'),nX=ri('<svg class="tbl-handle-grip" width="3" height="15" fill="currentColor" viewBox="0 0 3 15" xmlns="http://www.w3.org/2000/svg"><circle cy="1.5" cx="1.5" r="1.5"></circle><circle cy="7.5" cx="1.5" r="1.5"></circle><circle cy="13.5" cx="1.5" r="1.5"></circle></svg>'),rX=ot('<div class="tbl-handle" role="button" aria-hidden="true"><!></div>');function cg(i,t){Dn(t,!0);let e=bf(t,"toggle",3,!1);const n={table:{right:"vertical",bottom:"horizontal"},header:{row:"vertical",col:"horizontal"}},r=H(()=>{var c;return(c=n[t.of.type])==null?void 0:c[t.of.location]});var s=rX();gc(s,"",{},{opacity:"var(--tbl-handle-opacity, 0)"});var o=Ue(s);{var l=c=>{var h=iX();I(c,h)},a=c=>{var h=nX();I(c,h)};Ft(o,c=>{$(r)==="horizontal"?c(l):$(r)==="vertical"&&c(a,1)})}se((c,h,u)=>{$t(s,"data-component",pv),$t(s,"data-type",t.of.type),$t(s,"data-location",t.of.location),$t(s,"data-active",c),$t(s,"data-hover",h),$t(s,"data-toggle",u)},[()=>gr(t.state==="active"),()=>gr(t.state==="hover"),()=>gr(e())]),I(i,s),Yn()}var sX=ot('<div class="tbl-menu"><!></div>');function oX(i,t){Dn(t,!0);let e,n=ct(void 0);th(()=>{t.translate(e).then(l=>q(n,l,!0))});var r=sX();let s;var o=Ue(r);$r(o,()=>t.children),bc(r,l=>e=l,()=>e),se(l=>s=gc(r,"",s,l),[()=>({visibility:L($(n))?void 0:"hidden",transform:L($(n))?`translate3d(${$(n).x}px, ${$(n).y}px, 0px)`:void 0})]),I(i,r),Yn()}var lX=ot('<div class="tbl-menu-item" role="menuitem" tabindex="-1"><!></div>');function Ae(i,t){var e=lX(),n=Ue(e);$r(n,()=>t.children),Mo("click",e,function(...r){var s;(s=t.onclick)==null||s.apply(this,r)}),I(i,e)}MS(["click"]);function Re(i,t){switch(i.action){case"add":return t.menu.clickAdd(i.direction);case"align":return t.menu.clickAlign(i.alignment);case"clear":return t.menu.clickClear();case"duplicate":return t.menu.clickDuplicate();case"move":return t.menu.clickMove(i.direction);case"remove":return t.menu.clickRemove();case"sort":return t.menu.clickSort(i.direction)}}var aX=ri('<path d="M294.6 454.6L214.6 534.6C202.1 547.1 181.8 547.1 169.3 534.6L89.3 454.6C76.8 442.1 76.8 421.8 89.3 409.3C101.8 396.8 122.1 396.8 134.6 409.3L160 434.7L160 128C160 110.3 174.3 96 192 96C209.7 96 224 110.3 224 128L224 434.7L249.4 409.3C261.9 396.8 282.2 396.8 294.7 409.3C307.2 421.8 307.2 442.1 294.7 454.6zM476.6 113.7C527.3 215 553.9 268.4 556.6 273.7C564.5 289.5 558.1 308.7 542.3 316.6C526.5 324.5 507.3 318.1 499.4 302.3L492.2 288L403.8 288L396.6 302.3C388.7 318.1 369.5 324.5 353.7 316.6C337.9 308.7 331.5 289.5 339.4 273.7C342.1 268.4 368.7 215 419.4 113.7C424.8 102.9 435.9 96 448 96C460.1 96 471.2 102.8 476.6 113.7zM448 199.6L427.8 240L468.2 240L448 199.6zM352 384C352 366.3 366.3 352 384 352L512 352C524.9 352 536.6 359.8 541.6 371.8C546.6 383.8 543.8 397.5 534.7 406.7L461.3 480L512 480C529.7 480 544 494.3 544 512C544 529.7 529.7 544 512 544L384 544C371.1 544 359.4 536.2 354.4 524.2C349.4 512.2 352.2 498.5 361.3 489.3L434.7 415.9L384 415.9C366.3 415.9 352 401.6 352 383.9z"></path>'),cX=ri('<path d="M294.6 454.6L214.6 534.6C202.1 547.1 181.8 547.1 169.3 534.6L89.3 454.6C76.8 442.1 76.8 421.8 89.3 409.3C101.8 396.8 122.1 396.8 134.6 409.3L160 434.7L160 128C160 110.3 174.3 96 192 96C209.7 96 224 110.3 224 128L224 434.7L249.4 409.3C261.9 396.8 282.2 396.8 294.7 409.3C307.2 421.8 307.2 442.1 294.7 454.6zM352 128C352 110.3 366.3 96 384 96L512 96C524.9 96 536.6 103.8 541.6 115.8C546.6 127.8 543.8 141.5 534.7 150.7L461.3 224L512 224C529.7 224 544 238.3 544 256C544 273.7 529.7 288 512 288L384 288C371.1 288 359.4 280.2 354.4 268.2C349.4 256.2 352.2 242.5 361.3 233.3L434.8 160L384 160C366.3 160 352 145.7 352 128zM476.6 337.7L556.6 497.7C564.5 513.5 558.1 532.7 542.3 540.6C526.5 548.5 507.3 542.1 499.4 526.3L492.2 512L403.8 512L396.6 526.3C388.7 542.1 369.5 548.5 353.7 540.6C337.9 532.7 331.5 513.5 339.4 497.7L419.4 337.7C424.8 326.9 435.9 320 448 320C460.1 320 471.2 326.8 476.6 337.7zM448 423.6L427.8 464L468.2 464L448 423.6z"></path>'),hX=ri('<path d="M384 128C384 145.7 369.7 160 352 160L128 160C110.3 160 96 145.7 96 128C96 110.3 110.3 96 128 96L352 96C369.7 96 384 110.3 384 128zM384 384C384 401.7 369.7 416 352 416L128 416C110.3 416 96 401.7 96 384C96 366.3 110.3 352 128 352L352 352C369.7 352 384 366.3 384 384zM96 256C96 238.3 110.3 224 128 224L512 224C529.7 224 544 238.3 544 256C544 273.7 529.7 288 512 288L128 288C110.3 288 96 273.7 96 256zM544 512C544 529.7 529.7 544 512 544L128 544C110.3 544 96 529.7 96 512C96 494.3 110.3 480 128 480L512 480C529.7 480 544 494.3 544 512z"></path>'),uX=ri('<path d="M448 128C448 110.3 433.7 96 416 96L224 96C206.3 96 192 110.3 192 128C192 145.7 206.3 160 224 160L416 160C433.7 160 448 145.7 448 128zM544 256C544 238.3 529.7 224 512 224L128 224C110.3 224 96 238.3 96 256C96 273.7 110.3 288 128 288L512 288C529.7 288 544 273.7 544 256zM96 512C96 529.7 110.3 544 128 544L512 544C529.7 544 544 529.7 544 512C544 494.3 529.7 480 512 480L128 480C110.3 480 96 494.3 96 512zM448 384C448 366.3 433.7 352 416 352L224 352C206.3 352 192 366.3 192 384C192 401.7 206.3 416 224 416L416 416C433.7 416 448 401.7 448 384z"></path>'),fX=ri('<path d="M544 128C544 145.7 529.7 160 512 160L288 160C270.3 160 256 145.7 256 128C256 110.3 270.3 96 288 96L512 96C529.7 96 544 110.3 544 128zM544 384C544 401.7 529.7 416 512 416L288 416C270.3 416 256 401.7 256 384C256 366.3 270.3 352 288 352L512 352C529.7 352 544 366.3 544 384zM96 256C96 238.3 110.3 224 128 224L512 224C529.7 224 544 238.3 544 256C544 273.7 529.7 288 512 288L128 288C110.3 288 96 273.7 96 256zM544 512C544 529.7 529.7 544 512 544L128 544C110.3 544 96 529.7 96 512C96 494.3 110.3 480 128 480L512 480C529.7 480 544 494.3 544 512z"></path>'),dX=ri('<path d="M342.6 81.4C330.1 68.9 309.8 68.9 297.3 81.4L137.3 241.4C124.8 253.9 124.8 274.2 137.3 286.7C149.8 299.2 170.1 299.2 182.6 286.7L288 181.3L288 552C288 569.7 302.3 584 320 584C337.7 584 352 569.7 352 552L352 181.3L457.4 286.7C469.9 299.2 490.2 299.2 502.7 286.7C515.2 274.2 515.2 253.9 502.7 241.4L342.7 81.4z"></path>'),OX=ri('<path d="M566.6 342.6C579.1 330.1 579.1 309.8 566.6 297.3L406.6 137.3C394.1 124.8 373.8 124.8 361.3 137.3C348.8 149.8 348.8 170.1 361.3 182.6L466.7 288L96 288C78.3 288 64 302.3 64 320C64 337.7 78.3 352 96 352L466.7 352L361.3 457.4C348.8 469.9 348.8 490.2 361.3 502.7C373.8 515.2 394.1 515.2 406.6 502.7L566.6 342.7z"></path>'),pX=ri('<path d="M297.4 566.6C309.9 579.1 330.2 579.1 342.7 566.6L502.7 406.6C515.2 394.1 515.2 373.8 502.7 361.3C490.2 348.8 469.9 348.8 457.4 361.3L352 466.7L352 96C352 78.3 337.7 64 320 64C302.3 64 288 78.3 288 96L288 466.7L182.6 361.3C170.1 348.8 149.8 348.8 137.3 361.3C124.8 373.8 124.8 394.1 137.3 406.6L297.3 566.6z"></path>'),mX=ri('<path d="M73.4 297.4C60.9 309.9 60.9 330.2 73.4 342.7L233.4 502.7C245.9 515.2 266.2 515.2 278.7 502.7C291.2 490.2 291.2 469.9 278.7 457.4L173.3 352L544 352C561.7 352 576 337.7 576 320C576 302.3 561.7 288 544 288L173.3 288L278.7 182.6C291.2 170.1 291.2 149.8 278.7 137.3C266.2 124.8 245.9 124.8 233.4 137.3L73.4 297.3z"></path>'),gX=ri('<path d="M262.2 48C248.9 48 236.9 56.3 232.2 68.8L216 112L120 112C106.7 112 96 122.7 96 136C96 149.3 106.7 160 120 160L520 160C533.3 160 544 149.3 544 136C544 122.7 533.3 112 520 112L424 112L407.8 68.8C403.1 56.3 391.2 48 377.8 48L262.2 48zM128 208L128 512C128 547.3 156.7 576 192 576L448 576C483.3 576 512 547.3 512 512L512 208L464 208L464 512C464 520.8 456.8 528 448 528L192 528C183.2 528 176 520.8 176 512L176 208L128 208zM288 280C288 266.7 277.3 256 264 256C250.7 256 240 266.7 240 280L240 456C240 469.3 250.7 480 264 480C277.3 480 288 469.3 288 456L288 280zM400 280C400 266.7 389.3 256 376 256C362.7 256 352 266.7 352 280L352 456C352 469.3 362.7 480 376 480C389.3 480 400 469.3 400 456L400 280z"></path>'),bX=ot('<div class="tbl-menu-item-icon"><svg xmlns="http://www.w3.org/2000/svg" height="14" width="14" viewBox="0 0 640 640" fill="currentColor"><!></svg></div>');function Ze(i,t){var e=bX(),n=Ue(e),r=Ue(n);{var s=b=>{var S=aX();I(b,S)},o=b=>{var S=cX();I(b,S)},l=b=>{},a=b=>{var S=hX();I(b,S)},c=b=>{var S=uX();I(b,S)},h=b=>{var S=fX();I(b,S)},u=b=>{var S=dX();I(b,S)},f=b=>{var S=OX();I(b,S)},d=b=>{var S=pX();I(b,S)},O=b=>{var S=mX();I(b,S)},p=b=>{},m=b=>{},g=b=>{var S=gX();I(b,S)};Ft(r,b=>{t.name==="sort-ascending"?b(s):t.name==="sort-descending"?b(o,1):t.name==="align-none"?b(l,2):t.name==="align-left"?b(a,3):t.name==="align-center"?b(c,4):t.name==="align-right"?b(h,5):t.name==="move-up"?b(u,6):t.name==="move-right"?b(f,7):t.name==="move-down"?b(d,8):t.name==="move-left"?b(O,9):t.name==="duplicate"?b(p,10):t.name==="clear"?b(m,11):t.name==="remove"&&b(g,12)})}I(i,e)}var wX=ot('<div class="tbl-menu-item-text"><!></div>');function Xe(i,t){var e=wX(),n=Ue(e);$r(n,()=>t.children),I(i,e)}var SX=ot('<div class="tbl-menu-separator"></div>');function ga(i){var t=SX();I(i,t)}var vX=ot('<div class="tbl-select-all-overlay" aria-hidden="true"></div>');function xX(i){var t=vX();I(i,t)}const yX=new Set([bt.c,bt.v,bt.x]);function kX(i,t){return yX.has(i.key)&&i[lR(t)]}const QX=[bt.backspace,bt.delete],$X=new Set(QX);function CX({key:i}){return $X.has(i)?i:void 0}function PX(i){return/^F\d+$/.test(i)}const TX=new Set([bt.alt,bt.escape,bt.enter,bt.shift]);function AX({metaKey:i,ctrlKey:t,key:e}){return!t&&!i&&!TX.has(e)&&!PX(e)}function RX(i,t){t.selection.isCell()||av({tableState:t,event:i})}function ZX(i,t){t.selection.isCell()||cv({tableState:t,event:i})}function XX(i,t){t.selection.isCell()||Yd({tableState:t,event:i})}function EX(i,t){if(L(i.target)&&L(uv(i.target))){i.preventDefault();return}if(!t.interactive||t.selection.isCell())return;const e=Ov(i);if(L(e)){sh.navigate({tableState:t,key:e,event:i,position:{left:!0,top:!0,right:!0,bottom:!0}});return}const n=CX(i);if(L(n)){lv({tableState:t,event:i});return}if(t.activeTable&&L(t.activeCell)&&AX(i)){t.activeTable=!1,t.anchorCell=t.activeCell;const r=t.table.cellAt(t.activeCell).length;t.selectionValue={cell:t.activeCell,section:{head:r,anchor:r}},t.outlinedSection=rt.ofCell(t.activeCell);return}kX(i,t.window)||dk(t.rootEditor,i,"editor")&&i.preventDefault()}function Bd(i){return i.buttons===1}function mv(i,t){return t.setPointerCapture(i.pointerId),()=>t.releasePointerCapture(i.pointerId)}class oh{constructor({offset:t,maxScroll:e,boundaryElement:n,scrollElement:r}){C(this,"offset");C(this,"maxScroll");C(this,"boundaryElement");C(this,"scrollElement");C(this,"scroll");C(this,"handle");C(this,"xAmount");C(this,"yAmount");const s=this.scrollInternal.bind(this);this.scroll=()=>{this.handle=requestAnimationFrame(s)},this.xAmount=0,this.yAmount=0,this.offset=t??0,this.maxScroll=e,this.boundaryElement=n,this.scrollElement=r}updatePosition(t,e){const n=this.boundaryElement.x.getBoundingClientRect();t<n.left+this.offset?this.xAmount=-ce(this.offset+(n.left-t),{max:this.maxScroll}):t>n.right-this.offset?this.xAmount=ce(this.offset-(n.right-t),{max:this.maxScroll}):this.xAmount=0;const r=this.boundaryElement.y.getBoundingClientRect();e<r.top+this.offset?this.yAmount=-ce(this.offset+(r.top-e),{max:this.maxScroll}):e>r.bottom-this.offset?this.yAmount=ce(this.offset-(r.bottom-e),{max:this.maxScroll}):this.yAmount=0,V(this.handle)&&(this.xAmount!==0||this.yAmount!==0)&&this.scroll()}destroy(){L(this.handle)&&cancelAnimationFrame(this.handle)}scrollInternal(){if(this.xAmount===0&&this.yAmount===0){this.scroll();return}this.scrollElement.x.scrollBy({left:this.xAmount}),this.scrollElement.y.scrollBy({top:this.yAmount}),this.scroll()}static of(t){return new oh(t)}}class yc{constructor({start:t,size:e}){C(this,"start");C(this,"size");this.start=t,this.size=e}get mid(){return this.start+this.size/2}get end(){return this.start+this.size}static of(t){return new yc(t)}}var kc;(i=>{function t(e,n){return qd.of(e,n)}i.of=t})(kc||(kc={}));class qd{constructor(t,e){C(this,"rows");C(this,"cols");C(this,"firstRowIndex",0);C(this,"firstColIndex",0);const n=[...t.querySelectorAll("tr:first-child > th")],r=[...t.querySelectorAll("tr > th:first-child,tr > td:first-child")];this.rows=r.map((s,o)=>{const{top:l,height:a}=hg(s,e),c=0;return yc.of({start:l+c,size:a-c})}),this.cols=n.map((s,o)=>{const{left:l,width:a}=hg(s,e),c=o===0?1:0;return yc.of({start:l+c,size:a-c})})}rowsOrCols(t){return t==="row"?this.rows:this.cols}rowAt(t){return this.rows[t]}colAt(t){return this.cols[t]}rowOrColAt(t,e){return t==="row"?this.rowAt(e):this.colAt(e)}get firstRow(){return this.rows[this.firstRowIndex]}get firstCol(){return this.cols[this.firstColIndex]}firstRowOrCol(t){return t==="row"?this.firstRow:this.firstCol}get lastRow(){return this.rows[this.lastRowIndex]}get lastCol(){return this.cols[this.lastColIndex]}lastRowOrCol(t){return t==="row"?this.lastRow:this.lastCol}firstRowOrColIndex(t){return 0}get lastRowIndex(){return this.rowCount-1}get lastColIndex(){return this.colCount-1}lastRowOrColIndex(t){return t==="row"?this.lastRowIndex:this.lastColIndex}get rowCount(){return this.rows.length}get colCount(){return this.cols.length}get minRowSize(){return Oc(...this.rows.map(t=>t.size))}get minColSize(){return Oc(...this.cols.map(t=>t.size))}moveRowOrColAt(t,{fromIndex:e,toIndex:n}){if(e===n)return;const r=this.rowsOrCols(t),s=r[e];if(e<n){for(const o of Qn({start:e,endExclusive:n}))r[o]=r[o+1],r[o].start-=s.size;s.start=r[n].start+r[n].size}else{for(const o of Qn({start:e,endExclusive:n}))r[o]=r[o-1],r[o].start+=s.size;s.start=r[n].start-s.size}r[n]=s}lastCellBeforePosition(t){const e=this.rows.map(r=>r.start).findLastIndex(r=>r<t.y),n=this.cols.map(r=>r.start).findLastIndex(r=>r<t.x);return{row:e===-1?0:e,col:n===-1?0:n}}static of(t,e){return new qd(t,e)}}function hg(i,t){const{top:e,left:n,width:r,height:s}=i.getBoundingClientRect();return{top:e+t.y,left:n+t.x,width:r,height:s}}class vl{constructor({tableState:t,cellLocation:e}){C(this,"tableState");C(this,"tableMeasurement");C(this,"autoScroller");C(this,"shouldAutoScroll");C(this,"removeEventListeners");C(this,"currentCell");this.tableState=t,this.currentCell=e,this.autoScroller=oh.of({offset:10,maxScroll:32,boundaryElement:{x:t.scrollElement,y:t.rootScrollElement},scrollElement:{x:t.scrollElement,y:t.rootScrollElement}}),this.shouldAutoScroll=V5({delayMillis:500}),this.tableMeasurement=kc.of(t.tableElement,{x:t.scrollOffsetX,y:t.scrollOffsetY})}start(){this.tableState.activeCell=this.currentCell,this.tableState.anchorCell=this.currentCell,this.tableState.outlinedSection=rt.ofCell(this.currentCell),this.tableState.outline={outlined:!1},this.removeEventListeners=Cr(Et(this.tableState.window,"pointermove",t=>this.drag(t)),Et(this.tableState.window,"pointerup",()=>this.end()),Et(this.tableState.window,"pointerleave",()=>this.end()))}resizeAndContinue(t){t.preventDefault(),V(this.tableState.anchorCell)&&(this.tableState.anchorCell=this.currentCell),this.expandOrContract(this.currentCell),this.tableState.outline={outlined:!0},this.removeEventListeners=Cr(Et(this.tableState.window,"pointermove",e=>this.drag(e)),Et(this.tableState.window,"pointerup",()=>this.end()),Et(this.tableState.window,"pointerleave",()=>this.end()))}drag(t){if(!Bd(t)){this.end();return}t.preventDefault(),this.shouldAutoScroll()&&this.autoScroller.updatePosition(t.clientX,t.clientY);const e=this.tableMeasurement.lastCellBeforePosition({x:t.clientX+this.tableState.scrollOffsetX,y:t.clientY+this.tableState.scrollOffsetY});Pr(e,this.currentCell)||(this.currentCell=e,this.tableState.outline={outlined:!0},this.expandOrContract(e))}end(){var t;(t=this.removeEventListeners)==null||t.call(this),this.autoScroller.destroy(),this.tableState.outline=void 0}expandOrContract(t){this.tableState.focusTable();const[e,n]=t.row<=this.tableState.anchorCell.row?[t.row,this.tableState.anchorCell.row]:[this.tableState.anchorCell.row,t.row],[r,s]=t.col<=this.tableState.anchorCell.col?[t.col,this.tableState.anchorCell.col]:[this.tableState.anchorCell.col,t.col];this.tableState.outlinedSection=rt.of({row:{start:e,endExclusive:n+1},col:{start:r,endExclusive:s+1}}),this.tableState.activeCell=t}static startOutline(t){new vl(t).start()}static resizeAndContinueOutline(t){new vl(t).resizeAndContinue(t.event)}}function LX(i,t){Uc(t.window)&&(t.hoveredCell=i)}function MX(i){Uc(i.window)&&(i.hoveredCell=void 0)}function zX(i,t,e){if(!(!e.interactive||!Bd(i)))if(i.shiftKey){if(e.selection.isCell()&&Pr(t,e.selection.cell))return;vl.resizeAndContinueOutline({event:i,tableState:e,cellLocation:t})}else vl.startOutline({event:i,tableState:e,cellLocation:t})}const _X=new Intl.Collator(navigator.language,{numeric:!0,sensitivity:"base"});function ug(i,t){return _X.compare(i,t)}function IX({metaKey:i,shiftKey:t,altKey:e,ctrlKey:n,key:r}){return r===bt.escape&&!t&&!e&&!i&&!n}class Nd{constructor({tableState:t,handle:e,point:n}){C(this,"tableState");C(this,"handle");C(this,"point");C(this,"removeEventListeners");this.tableState=t,this.handle=e,this.point=n}get rowOrCol(){return this.handle.location}get index(){return this.handle.index}open(){const t=this.tableState.document.body;this.removeEventListeners=Cr(Et(t,"pointerdown",o=>{o.preventDefault(),(V(o.target)||!YS(this.tableState.menuRootElement,o.target))&&this.close()}),Et(t,"wheel",o=>o.preventDefault(),{passive:!1}),Et(t,"keydown",o=>{o.preventDefault(),IX(o)&&this.close()})),this.tableState.focusTable(),this.tableState.activeHandle={state:"active",handle:this.handle},this.tableState.outlinedSection=rt.of(this.rowOrCol==="row"?{row:{start:this.index,endExclusive:this.index+1},col:this.tableState.table.colRange}:{row:this.tableState.table.rowRange,col:{start:this.index,endExclusive:this.index+1}});const e=this.rowOrCol==="row"?{row:this.index,col:this.tableState.table.lastColIndex}:{row:this.tableState.table.lastRowIndex,col:this.index};this.tableState.activeCell=e,this.tableState.anchorCell=e;const n=this.index!==this.tableState.table.firstRowOrColIndex(this.rowOrCol),r=this.index!==this.tableState.table.lastRowOrColIndex(this.rowOrCol);let s=!1;n?s=r?!0:"backward":r&&(s="forward"),this.tableState.menu={type:this.rowOrCol,capabilities:{addable:!0,alignable:this.rowOrCol==="col",clearable:!0,duplicatable:!0,moveable:s,removable:!this.tableState.table.hasSingleRowOrCol(this.rowOrCol),sortable:this.rowOrCol==="col"},clickAdd:o=>this.clickAdd(o),clickAlign:o=>this.clickAlign(o),clickClear:()=>this.clickClear(),clickDuplicate:()=>this.clickDuplicate(),clickMove:o=>this.clickMove(o),clickRemove:()=>this.clickRemove(),clickSort:o=>this.clickSort(o),computeTranslation:o=>this.computeTranslation(o)}}close(){var t;(t=this.removeEventListeners)==null||t.call(this),this.tableState.menu=void 0,this.tableState.activeHandle=void 0}async computeTranslation(t){const e=await JT({getBoundingClientRect:()=>({x:this.point.x,y:this.point.y,top:this.point.y,right:this.point.x,bottom:this.point.y,left:this.point.x,width:0,height:0})},t,{middleware:[FT({allowedPlacements:this.rowOrCol==="row"?["right-start","right-end"]:["right-start","right"]}),KT({crossAxis:!0})]}),n=wo(t);return{x:xc(e.x,n),y:xc(e.y,n)}}clickAdd(t){var e;if(this.tableState.table.addEmptyRowsOrColsAt(this.rowOrCol,{index:t==="before"?this.index:this.index+1,count:1}),t==="after"){this.tableState.outlinedSection=(e=this.tableState.outlinedSection)==null?void 0:e.shift(this.rowOrCol,"forward");const n=Fh(this.rowOrCol,this.tableState.activeCell,"forward");this.tableState.activeCell=n,this.tableState.anchorCell=n}this.close()}clickAlign(t){this.tableState.table.setAlignmentAt(this.index,t),this.close()}clickClear(){this.tableState.table.clearRowOrCol(this.rowOrCol,this.index),this.close()}clickDuplicate(){this.tableState.table.duplicateRowOrColAt(this.rowOrCol,this.index),this.close()}clickMove(t){var n;this.tableState.table.moveRowOrColAt(this.rowOrCol,{fromIndex:this.index,toIndex:t==="backward"?this.index-1:this.index+1}),this.tableState.outlinedSection=(n=this.tableState.outlinedSection)==null?void 0:n.shift(this.rowOrCol,t);const e=Fh(this.rowOrCol,this.tableState.activeCell,t);this.tableState.activeCell=e,this.tableState.anchorCell=e,this.close()}clickRemove(){var t;if(this.tableState.table.removeRowsOrColsAt(this.rowOrCol,{index:this.index,count:1}),!this.tableState.table.hasRowOrColAt(this.rowOrCol,this.index)){this.tableState.outlinedSection=(t=this.tableState.outlinedSection)==null?void 0:t.shift(this.rowOrCol,"backward");const e=Fh(this.rowOrCol,this.tableState.activeCell,"backward");this.tableState.activeCell=e,this.tableState.anchorCell=e}this.close()}clickSort(t){this.tableState.table.sortByColAt(this.index,t==="ascending"?(e,n)=>ug(e.toString(),n.toString()):(e,n)=>ug(n.toString(),e.toString())),this.close()}static showMenu(t){new Nd(t).open()}}class Gd{constructor({rowOrCol:t,index:e,position:n,subject:r,tableElement:s,scrollOffsetX:o,scrollOffsetY:l}){C(this,"coordinate");C(this,"initialIndex");C(this,"size");C(this,"initialPosition");C(this,"minBound");C(this,"maxBound");C(this,"scrollOffsetX");C(this,"scrollOffsetY");C(this,"subject");C(this,"rowOrCol");C(this,"tableMeasurement");C(this,"currentIndex");C(this,"currentPosition");C(this,"dragged");this.scrollOffsetX=o,this.scrollOffsetY=l;const a=kc.of(s,{x:this.scrollOffsetX(),y:this.scrollOffsetY()});this.rowOrCol=t,this.coordinate=t==="row"?"y":"x",this.initialIndex=e,this.initialPosition=n[this.coordinate],this.minBound=a.firstRowOrCol(this.rowOrCol).start-a.rowOrColAt(this.rowOrCol,e).start,this.maxBound=a.lastRowOrCol(this.rowOrCol).end-a.rowOrColAt(this.rowOrCol,e).end,this.size=a.rowOrColAt(this.rowOrCol,e).size,this.subject=r,this.dragged=!1,this.tableMeasurement=a,this.currentIndex=e,this.currentPosition=n[this.coordinate]}start(){return{cellMovement:t=>this.cellMovement(t)}}drag(t){this.currentPosition=t[this.coordinate];const{currentIndex:e,move:n}=this.calculateDrag();return this.currentIndex=e,this.initialIndex!==this.currentIndex&&(this.dragged=!0),L(n)&&this.tableMeasurement.moveRowOrColAt(this.rowOrCol,n),{cellMovement:r=>this.cellMovement(r)}}end(){return this.initialIndex===this.currentIndex?{moved:!1,dragged:this.dragged}:{moved:!0,toIndex:this.currentIndex}}cellMovement(t){return{border:this.cellBorder(t),state:this.cellState(t),translate:this.cellTranslate(t)}}cellBorder(t){const e=this.isRowOrColExposed(t[this.rowOrCol]),n=this.subject.containsCell(t);return this.rowOrCol==="row"?{top:e,right:!0,bottom:!n||t.row===this.tableMeasurement.lastRowIndex,left:this.tableMeasurement.firstColIndex===t.col}:{top:this.tableMeasurement.firstRowIndex===t.row,right:!n||t.col===this.tableMeasurement.lastColIndex,bottom:!0,left:e}}cellState(t){return this.subject.containsCell(t)?"moving":"shiftable"}cellTranslate(t){const e=this.rowOrColTranslate(t[this.rowOrCol]);return this.rowOrCol==="row"?{x:0,y:e}:{x:e,y:0}}isRowOrColExposed(t){const e=this.reorderIndex(t),n=e===this.tableMeasurement.firstRowOrColIndex(this.rowOrCol),r=e===this.currentIndex+1;return n||r}get rowOrColShift(){if(this.currentIndex!==this.initialIndex)return this.currentIndex<this.initialIndex?{direction:"forwards",range:{start:this.currentIndex,endExclusive:this.initialIndex},indexDiff:1,positionDiff:this.size-1}:{direction:"backwards",range:{start:this.initialIndex+1,endExclusive:this.currentIndex+1},indexDiff:-1,positionDiff:1-this.size}}rowOrColTranslate(t){if(t===this.initialIndex)return ce(this.currentPosition-this.initialPosition,{min:this.minBound,max:this.maxBound});const e=this.rowOrColShift;return V(e)?0:yn(t,e.range)?e.positionDiff:0}reorderIndex(t){const e=this.rowOrColShift;return V(e)?t:t===this.initialIndex?this.currentIndex:yn(t,e.range)?t+e.indexDiff:t}calculateDrag(){const t=this.tableMeasurement.rowsOrCols(this.rowOrCol),e={name:"current",index:this.currentIndex,mid:t[this.currentIndex].mid},n=this.currentIndex!==this.tableMeasurement.firstRowOrColIndex(this.rowOrCol)?{name:"left",index:this.currentIndex-1,mid:t[this.currentIndex-1].start+t[this.currentIndex].size/2}:void 0,r=this.currentIndex!==this.tableMeasurement.lastRowOrColIndex(this.rowOrCol)?{name:"right",index:this.currentIndex+1,mid:t[this.currentIndex].start+t[this.currentIndex+1].size+t[this.currentIndex].size/2}:void 0,s=RA(ZA([e,n,r]),(o,l)=>nf(this.currentPosition-o.mid)-nf(this.currentPosition-l.mid));return s.name==="current"?{currentIndex:this.currentIndex,move:void 0}:{currentIndex:s.index,move:{fromIndex:this.currentIndex,toIndex:s.index}}}static of(t){return new Gd(t)}}class Ud{constructor({event:t,tableState:e,rowOrCol:n,index:r,onClick:s}){C(this,"tableState");C(this,"rowOrCol");C(this,"index");C(this,"onClick");C(this,"moveTracker");C(this,"subject");C(this,"autoScroller");C(this,"removeEventListeners");this.tableState=e,this.rowOrCol=n,this.index=r,this.subject=rt.of(n==="row"?{row:{start:r,endExclusive:r+1},col:this.tableState.table.colRange}:{row:this.tableState.table.rowRange,col:{start:r,endExclusive:r+1}}),this.onClick=s,this.autoScroller=oh.of({offset:16,maxScroll:32,boundaryElement:{x:e.scrollElement,y:e.rootScrollElement},scrollElement:{x:e.scrollElement,y:e.rootScrollElement}}),this.moveTracker=Gd.of({subject:this.subject,rowOrCol:n,index:r,position:{x:t.clientX+e.scrollOffsetX,y:t.clientY+e.scrollOffsetY},tableElement:e.tableElement,scrollOffsetX:()=>this.tableState.scrollOffsetX,scrollOffsetY:()=>this.tableState.scrollOffsetY})}start(t){t.preventDefault();const e=this.moveTracker.start();this.tableState.outlinedSection=this.subject,this.tableState.move=e,this.tableState.activeHandle={state:"active",handle:{type:"header",index:this.index,location:this.rowOrCol}};const n=this.rowOrCol==="row"?{row:this.index,col:this.tableState.table.lastColIndex}:{row:this.tableState.table.lastRowIndex,col:this.index};this.tableState.activeCell=n,this.tableState.anchorCell=n,this.tableState.focusTable();const r=_d(t.target);this.removeEventListeners=Cr(mv(t,r),Et(r,"pointermove",s=>this.drag(s)),Et(r,"pointerup",()=>this.end()))}drag(t){t.preventDefault(),this.autoScroller.updatePosition(t.clientX,t.clientY),this.tableState.move=this.moveTracker.drag({x:t.clientX+this.tableState.scrollOffsetX,y:t.clientY+this.tableState.scrollOffsetY})}end(){var e;(e=this.removeEventListeners)==null||e.call(this),this.autoScroller.destroy();const t=this.moveTracker.end();if(t.moved){this.tableState.table.moveRowOrColAt(this.rowOrCol,{fromIndex:this.index,toIndex:t.toIndex}),this.tableState.outlinedSection=rt.of(this.rowOrCol==="row"?{row:{start:t.toIndex,endExclusive:t.toIndex+1},col:this.tableState.table.colRange}:{row:this.tableState.table.rowRange,col:{start:t.toIndex,endExclusive:t.toIndex+1}});const n=this.rowOrCol==="row"?{row:t.toIndex,col:this.tableState.table.lastColIndex}:{row:this.tableState.table.lastRowIndex,col:t.toIndex};this.tableState.activeCell=n,this.tableState.anchorCell=n}this.tableState.move=void 0,this.tableState.activeHandle=void 0,!t.moved&&!t.dragged&&this.onClick()}static startMove(t){new Ud(t).start(t.event)}}function jX(i){return i==="row"?"y":"x"}class Hd{constructor({tableState:t,handle:e,position:n,cellSizePixels:r,dragThresholdPixels:s}){C(this,"tableState");C(this,"type");C(this,"initialHandle");C(this,"initialRowOrColCount");C(this,"initialPosition");C(this,"initialOutlinedSection");C(this,"initialActiveCell");C(this,"initialAnchorCell");C(this,"cellSizePixels");C(this,"dragThresholdPixels");C(this,"dragged");this.tableState=t,this.type=this.handleToType(e),this.initialHandle=e,this.initialPosition=n,this.initialRowOrColCount={row:t.table.rowCount,col:t.table.colCount},this.initialActiveCell=t.activeCell,this.initialAnchorCell=t.anchorCell,this.initialOutlinedSection=t.outlinedSection,this.cellSizePixels=r,this.dragThresholdPixels=s,this.dragged=!1}start(){return{activeHandle:{state:"active",handle:this.initialHandle}}}drag(t){return this.dragged=!0,this.calculateDrag(t)}end(){return this.dragged?{activeHandle:void 0}:this.calculateClick()}calculateClick(){if(this.type!=="table")return this.calculateClickRowOrCol(this.type);if(this.initialHandle.location==="right")return this.calculateClickRowOrCol("col");if(this.initialHandle.location==="bottom")return this.calculateClickRowOrCol("row");const t=this.calculateClickRowOrCol("row"),e=this.calculateClickRowOrCol("col");return{operation:{row:t.operation.row,col:e.operation.col},activeHandle:t.activeHandle,activeCell:L(t.activeCell)&&L(e.activeCell)?{row:t.activeCell.row,col:e.activeCell.col}:void 0,anchorCell:L(t.anchorCell)&&L(e.anchorCell)?{row:t.anchorCell.row,col:e.anchorCell.col}:void 0,outlinedSection:L(t.outlinedSection)&&L(e.outlinedSection)?rt.of({row:t.outlinedSection.row,col:e.outlinedSection.col}):void 0}}calculateClickRowOrCol(t){const e=this.type==="table"?this.tableState.table.lastRowOrColIndex(t)+1:this.initialHandle.index;return{operation:{[t]:{action:"add",index:e,count:1}},activeHandle:this.type==="table"?void 0:{state:"hover",handle:{type:"border",location:this.handleLocationAt(e),index:e}},...this.calculateCellMovement(t,1)}}calculateDrag(t){if(this.type!=="table")return this.calculateDragRowOrCol(this.type,t);if(this.initialHandle.location==="right")return this.calculateDragRowOrCol("col",t);if(this.initialHandle.location==="bottom")return this.calculateDragRowOrCol("row",t);const e=this.calculateDragRowOrCol("row",t),n=this.calculateDragRowOrCol("col",t);if(V(e)&&V(n))return;const r=e??this.calculateCellMovement("row",this.rowOrColDiff("row")),s=n??this.calculateCellMovement("col",this.rowOrColDiff("col"));return{operation:{row:e==null?void 0:e.operation.row,col:n==null?void 0:n.operation.col},activeHandle:(e==null?void 0:e.activeHandle)??(n==null?void 0:n.activeHandle),activeCell:L(r.activeCell)&&L(s.activeCell)?{row:r.activeCell.row,col:s.activeCell.col}:void 0,anchorCell:L(r.anchorCell)&&L(s.anchorCell)?{row:r.anchorCell.row,col:s.anchorCell.col}:void 0,outlinedSection:L(r.outlinedSection)&&L(s.outlinedSection)?rt.of({row:r.outlinedSection.row,col:s.outlinedSection.col}):void 0}}calculateDragRowOrCol(t,e){const n=jX(t),r=e.position[n]-this.initialPosition[n],s=zA(r/this.cellSizePixels[t]),o=r%this.cellSizePixels[t]>=this.dragThresholdPixels[t]?1:0,l=this.tableState.table.rowOrColCount(t)-this.initialRowOrColCount[t],a=s+o-l,c=this.type==="table"?this.tableState.table.lastRowOrColIndex(t)+1:this.initialHandle.index+l;if(a!==0)return a>0?this.calculateDragRowOrColMore({rowOrCol:t,start:c,length:a}):this.calculateDragRowOrColLess({rowOrCol:t,start:c,length:Oc(-a,c,this.tableState.table.lastRowOrColIndex(t))})}calculateDragRowOrColLess({rowOrCol:t,start:e,length:n}){let r=0;for(const o of Qn({start:e-1,endExclusive:e-n-1})){if(!this.tableState.table.hasEmptyRowOrColAt(t,o))break;r++}if(r===0)return;const s=e-(r-1)-1;return{operation:{[t]:{action:"remove",index:e-r,count:r}},activeHandle:this.type==="table"?{state:"active",handle:this.initialHandle}:{state:"active",handle:{type:"border",location:this.handleLocationAt(s),index:s}},...this.calculateCellMovement(t,this.rowOrColDiff(t)-r)}}calculateDragRowOrColMore({rowOrCol:t,start:e,length:n}){return{operation:{[t]:{action:"add",index:e,count:n}},activeHandle:{state:"active",handle:this.type==="table"?this.initialHandle:{type:"border",location:this.handleLocationAt(e+n),index:e+n}},...this.calculateCellMovement(t,this.rowOrColDiff(t)+n)}}calculateCellMovement(t,e){var r,s;const n=this.type==="table"?this.initialRowOrColCount[t]:this.initialHandle.index;if(e>=0)return{outlinedSection:(r=this.initialOutlinedSection)==null?void 0:r.addForwardsByRowOrCol(t,{start:n,count:e}),activeCell:L(this.initialActiveCell)?tg(t,this.initialActiveCell,{start:n,count:e}):void 0,anchorCell:L(this.initialAnchorCell)?tg(t,this.initialAnchorCell,{start:n,count:e}):void 0};{const o=-e,l=(s=this.initialOutlinedSection)==null?void 0:s.subtractBackwardsByRowOrCol(t,{start:n,count:o,min:this.tableState.table.firstRowOrColIndex(t)}),a=L(l)?{min:l.startRowOrCol(t),max:l.endRowOrCol(t)}:void 0,c=L(this.initialActiveCell)?eg(t,this.initialActiveCell,{start:n,count:o,boundary:a}):void 0,h=L(this.initialAnchorCell)?eg(t,this.initialAnchorCell,{start:n,count:o,boundary:a}):void 0;return{outlinedSection:l,activeCell:c,anchorCell:h}}}rowOrColDiff(t){return this.tableState.table.rowOrColCount(t)-this.initialRowOrColCount[t]}handleLocationAt(t){if(this.type!=="table")return this.type==="row"&&t===this.tableState.table.firstRowIndex?"top":this.type==="col"&&t===this.tableState.table.firstColIndex?"left":this.type}handleToType(t){return t.type==="table"?"table":t.location==="top"?"row":t.location==="left"?"col":t.location}static of(t){return new Hd(t)}}function DX(i){const t=Sc(i.tableElement,i.table.firstCellLocation),e=LZ(t),{minWidth:n}=getComputedStyle(t),{lineHeight:r,paddingTop:s,paddingBottom:o}=getComputedStyle(e),l=parseFloat(n)+1,a=parseFloat(r)+parseFloat(s)+parseFloat(o)+1;return{width:l,height:a}}class Fd{constructor({event:t,tableState:e,handle:n}){C(this,"tableState");C(this,"resizeTracker");C(this,"removeEventListeners");this.tableState=e;const{width:r,height:s}=DX(e);this.resizeTracker=Hd.of({tableState:this.tableState,handle:n,position:{x:t.clientX,y:t.clientY},cellSizePixels:{row:s,col:r},dragThresholdPixels:{row:s/2,col:r/2}})}start(t){t.preventDefault();const e=this.resizeTracker.start();this.tableState.resize={},this.tableState.activeHandle=e.activeHandle,this.tableState.focusTable(),this.removeEventListeners=Cr(mv(t,this.tableState.tableElement),Et(this.tableState.tableElement,"pointermove",n=>this.drag(n)),Et(this.tableState.tableElement,"pointerup",()=>this.end()))}drag(t){t.preventDefault();const e=this.resizeTracker.drag({position:{x:t.clientX,y:t.clientY}});L(e)&&(this.resizeTable(e.operation),this.tableState.activeHandle=e.activeHandle,this.tableState.activeCell=e.activeCell,this.tableState.anchorCell=e.anchorCell,this.tableState.outlinedSection=e.outlinedSection)}end(){var e;(e=this.removeEventListeners)==null||e.call(this);const t=this.resizeTracker.end();"operation"in t&&(this.resizeTable(t.operation),this.tableState.activeCell=t.activeCell,this.tableState.anchorCell=t.anchorCell,this.tableState.outlinedSection=t.outlinedSection),this.tableState.activeHandle=t.activeHandle,this.tableState.resize=void 0}resizeTable({row:t,col:e}){if(L(t)){const{action:n,index:r,count:s}=t;n==="add"?this.tableState.table.addEmptyRowsAt({row:r,count:s}):this.tableState.table.removeRowsAt({row:r,count:s})}if(L(e)){const{action:n,index:r,count:s}=e;n==="add"?this.tableState.table.addEmptyColsAt({col:r,count:s}):this.tableState.table.removeColsAt({col:r,count:s})}}static startResize(t){new Fd(t).start(t.event)}}function YX(i,t){t.interactive&&(t.activeHandle={state:"hover",handle:i})}function WX(i){i.interactive&&(i.activeHandle=void 0)}function VX(i,t,e){if(e.interactive){if(!Bd(i)){i.preventDefault();return}t.type==="table"||t.type==="border"?Fd.startResize({event:i,handle:t,tableState:e}):t.type==="header"&&Ud.startMove({event:i,rowOrCol:t.location,index:t.index,tableState:e,onClick:()=>Nd.showMenu({handle:t,point:{x:i.clientX,y:i.clientY},tableState:e})})}}function BX(i,t){const e=i.target;if(V(e))return;const n=Vd(e);if(L(n)){YX(n,t);return}const r=Wl(e);if(L(r)){LX(nh(r),t);return}}function qX(i,t){const e=i.target;if(V(e))return;const n=Vd(e);if(L(n)){WX(t);return}const r=Wl(e);if(L(r)){MX(t);return}}function NX(i,t){const e=i.target;if(V(e))return;const n=Vd(e);if(L(n)){VX(i,n,t);return}const r=Wl(e);if(L(r)){zX(i,nh(r),t);return}i.preventDefault()}function GX(i){i.preventDefault()}var UX=ot("<!> <!> <!>",1),HX=ot('<tr class="tbl-table-row"></tr>'),FX=ot('<tbody class="tbl-table-body"></tbody>'),KX=ot("<!> <!>",1),JX=ot("<!> <!>",1),tE=ot("<!> <!> <!>",1),eE=ot("<!> <!>",1),iE=ot("<!> <!>",1),nE=ot("<!> <!>",1),rE=ot("<!> <!>",1),sE=ot("<!> <!> <!> <!> <!>",1),oE=ot("<!> <!>",1),lE=ot("<!> <!>",1),aE=ot("<!> <!> <!>",1),cE=ot("<!> <!>",1),hE=ot("<!> <!>",1),uE=ot("<!> <!> <!>",1),fE=ot("<!> <!>",1),dE=ot("<!> <!>",1),OE=ot("<!> <!>",1),pE=ot("<!> <!> <!> <!> <!> <!> <!>",1),mE=ot('<div class="tbl-table-wrapper"><table class="tbl-table" role="grid" tabindex="-1"><thead class="tbl-table-head"><!></thead><!></table> <!> <!> <!> <!></div>');function gE(i,t){Dn(t,!0);const e=Qf.of({table:()=>t.table,selection:()=>t.selection,scrollElement:()=>t.scrollElement,rootEditor:()=>t.rootEditor,menuRootElement:()=>t.menuRootElement,extensions:()=>t.extensions,markdownConfig:()=>t.markdownConfig,globalKeyBindings:()=>t.globalKeyBindings,selectionType:()=>t.selectionType,lineWrapping:()=>t.lineWrapping,onUndo:()=>t.onUndo,onRedo:()=>t.onRedo,onNavigate:()=>t.onNavigate,onDelete:()=>t.onDelete});th(()=>Cr(Et(e.document,"selectionchange",()=>MZ(e)),Et(e.document.body,"pointerdown",()=>TZ(e),{capture:!0,passive:!0}),Et(e.document.body,"pointerup",()=>AZ(e),{capture:!0,passive:!0}),Et(e.document.body,"pointerleave",()=>RZ(e),{capture:!0,passive:!0}),Et(e.document.body,"copy",x=>ZZ(x,e)),Et(e.document.body,"cut",x=>XZ(x,e)),Et(e.document.body,"paste",x=>EZ(x,e))));var n=mE(),r=Ue(n);{const x=(y,k=N1)=>{var Q=HX();Oa(Q,20,()=>e.table.colIndices,E=>E,(E,W)=>{const X=H(()=>({row:k(),col:W})),D=H(()=>({top:k()===e.table.firstRowIndex,left:W===e.table.firstColIndex})),_=H(()=>e.selection.isCell()&&Pr($(X),e.selection.cell));{let F=H(()=>{var U;return((U=e.outlinedSection)==null?void 0:U.containsOnEdge($(X)))??{top:!1,right:!1,bottom:!1,left:!1}}),G=H(()=>{var U;return(U=e.move)==null?void 0:U.cellMovement($(X))});BZ(E,{get location(){return $(X)},get alignment(){return e.table.alignments[W]},get selected(){return $(_)},get position(){return $(D)},get outline(){return $(F)},get movement(){return $(G)},get win(){return e.window},children:(U,Zt)=>{var zt=UX(),Bt=Xt(zt);Oa(Bt,16,()=>kZ($(X),$(D)),yt=>yt,(yt,Nt)=>{{let re=H(()=>e.cellHandleState($(X),Nt)),be=H(()=>L(e.resize));cg(yt,{get of(){return Nt},get state(){return $(re)},get toggle(){return $(be)}})}});var lt=et(Bt,2);eX(lt,{get hidden(){return $(_)},children:(yt,Nt)=>{var re=zd(),be=Xt(re);R5(be,()=>SZ(e.table.cellAt($(X)),e.highlighter($(X)))),I(yt,re)},$$slots:{default:!0}});var Dt=et(lt,2);{var $e=yt=>{var Nt=()=>e.table.cellAt($(X)),re=pt=>e.table.setCellAt($(X),pt),be=()=>e.selection.cellSection,tt=pt=>{e.selectionValue={cell:$(X),section:pt}};{let pt=H(()=>e.highlighter($(X)));GZ(yt,{get text(){return Nt()},set text(mt){re(mt)},get selection(){return be()},set selection(mt){tt(mt)},get selectionType(){return e.selectionType},get lineWrapping(){return e.lineWrapping},get extensions(){return e.extensions},get markdownConfig(){return e.markdownConfig},get rootEditor(){return e.rootEditor},get globalKeyBindings(){return e.globalKeyBindings},get highlighter(){return $(pt)},onbeforeinput:mt=>HZ(mt,e),ondragstart:mt=>FZ(mt),onkeydown:(mt,At)=>KZ(mt,At,e),onpaste:mt=>JZ(mt,e)})}};Ft(Dt,yt=>{$(_)&&yt($e)})}I(U,zt)},$$slots:{default:!0}})}}),I(y,Q)};var s=Ue(r),o=Ue(s);x(o,()=>e.table.headerRowIndex);var l=et(s);{var a=y=>{var k=FX();Oa(k,20,()=>e.table.dataRowIndices,Q=>Q,(Q,E)=>{x(Q,()=>E)}),I(y,k)},c=H(()=>e.table.hasDataRows());Ft(l,y=>{$(c)&&y(a)})}bc(r,y=>e.tableElement=y,()=>e==null?void 0:e.tableElement)}var h=et(r,2);{var u=x=>{const y=H(()=>e.menu.type==="row"?"row":"column");IZ(x,{get to(){return e.menuRootElement},children:(k,Q)=>{oX(k,{translate:E=>e.menu.computeTranslation(E),children:(E,W)=>{const X=H(()=>{const{addable:tt,alignable:pt,clearable:mt,duplicatable:At,moveable:Yt,removable:Wt,sortable:fe}=e.menu.capabilities;return{addable:tt,alignable:pt,clearable:mt,duplicatable:At,moveable:Yt,removable:Wt,sortable:fe}});var D=pE(),_=Xt(D);{var F=tt=>{var pt=tE(),mt=Xt(pt);Ae(mt,{onclick:()=>Re({action:"sort",direction:"ascending"},e),children:(Wt,fe)=>{var ut=KX(),gt=Xt(ut);Ze(gt,{name:"sort-ascending"});var _t=et(gt,2);Xe(_t,{children:(kt,Ut)=>{var Rt=Te();se(()=>Bi(Rt,`Sort by ${$(y)??""} (A-Z)`)),I(kt,Rt)}}),I(Wt,ut)}});var At=et(mt,2);Ae(At,{onclick:()=>Re({action:"sort",direction:"descending"},e),children:(Wt,fe)=>{var ut=JX(),gt=Xt(ut);Ze(gt,{name:"sort-descending"});var _t=et(gt,2);Xe(_t,{children:(kt,Ut)=>{var Rt=Te();se(()=>Bi(Rt,`Sort by ${$(y)??""} (Z-A)`)),I(kt,Rt)}}),I(Wt,ut)}});var Yt=et(At,2);ga(Yt),I(tt,pt)};Ft(_,tt=>{$(X).sortable&&tt(F)})}var G=et(_,2);{var U=tt=>{var pt=sE(),mt=Xt(pt);Ae(mt,{onclick:()=>Re({action:"align",alignment:"none"},e),children:(ut,gt)=>{var _t=eE(),kt=Xt(_t);Ze(kt,{name:"align-none"});var Ut=et(kt,2);Xe(Ut,{children:(Rt,si)=>{var Wi=Te("Align none");I(Rt,Wi)}}),I(ut,_t)}});var At=et(mt,2);Ae(At,{onclick:()=>Re({action:"align",alignment:"left"},e),children:(ut,gt)=>{var _t=iE(),kt=Xt(_t);Ze(kt,{name:"align-left"});var Ut=et(kt,2);Xe(Ut,{children:(Rt,si)=>{var Wi=Te("Align left");I(Rt,Wi)}}),I(ut,_t)}});var Yt=et(At,2);Ae(Yt,{onclick:()=>Re({action:"align",alignment:"center"},e),children:(ut,gt)=>{var _t=nE(),kt=Xt(_t);Ze(kt,{name:"align-center"});var Ut=et(kt,2);Xe(Ut,{children:(Rt,si)=>{var Wi=Te("Align center");I(Rt,Wi)}}),I(ut,_t)}});var Wt=et(Yt,2);Ae(Wt,{onclick:()=>Re({action:"align",alignment:"right"},e),children:(ut,gt)=>{var _t=rE(),kt=Xt(_t);Ze(kt,{name:"align-right"});var Ut=et(kt,2);Xe(Ut,{children:(Rt,si)=>{var Wi=Te("Align right");I(Rt,Wi)}}),I(ut,_t)}});var fe=et(Wt,2);ga(fe),I(tt,pt)};Ft(G,tt=>{$(X).alignable&&tt(U)})}var Zt=et(G,2);{var zt=tt=>{var pt=aE(),mt=Xt(pt);Ae(mt,{onclick:()=>Re({action:"add",direction:"before"},e),children:(Wt,fe)=>{var ut=oE(),gt=Xt(ut);Ze(gt,{name:"add-before"});var _t=et(gt,2);Xe(_t,{children:(kt,Ut)=>{var Rt=Te();se(()=>Bi(Rt,`Add ${$(y)??""} ${$(y)==="row"?"above":"before"}`)),I(kt,Rt)}}),I(Wt,ut)}});var At=et(mt,2);Ae(At,{onclick:()=>Re({action:"add",direction:"after"},e),children:(Wt,fe)=>{var ut=lE(),gt=Xt(ut);Ze(gt,{name:"add-after"});var _t=et(gt,2);Xe(_t,{children:(kt,Ut)=>{var Rt=Te();se(()=>Bi(Rt,`Add ${$(y)??""} ${$(y)==="row"?"below":"after"}`)),I(kt,Rt)}}),I(Wt,ut)}});var Yt=et(At,2);ga(Yt),I(tt,pt)};Ft(Zt,tt=>{$(X).addable&&tt(zt)})}var Bt=et(Zt,2);{var lt=tt=>{var pt=uE(),mt=Xt(pt);{var At=ut=>{Ae(ut,{onclick:()=>Re({action:"move",direction:"backward"},e),children:(gt,_t)=>{var kt=cE(),Ut=Xt(kt);{let si=H(()=>`move-${$(y)==="row"?"up":"left"}`);Ze(Ut,{get name(){return $(si)}})}var Rt=et(Ut,2);Xe(Rt,{children:(si,Wi)=>{var So=Te();se(()=>Bi(So,`Move ${$(y)??""} ${$(y)==="row"?"up":"left"}`)),I(si,So)}}),I(gt,kt)}})};Ft(mt,ut=>{($(X).moveable==="backward"||$(X).moveable===!0)&&ut(At)})}var Yt=et(mt,2);{var Wt=ut=>{Ae(ut,{onclick:()=>Re({action:"move",direction:"forward"},e),children:(gt,_t)=>{var kt=hE(),Ut=Xt(kt);{let si=H(()=>`move-${$(y)==="row"?"down":"right"}`);Ze(Ut,{get name(){return $(si)}})}var Rt=et(Ut,2);Xe(Rt,{children:(si,Wi)=>{var So=Te();se(()=>Bi(So,`Move ${$(y)??""} ${$(y)==="row"?"down":"right"}`)),I(si,So)}}),I(gt,kt)}})};Ft(Yt,ut=>{($(X).moveable==="forward"||$(X).moveable===!0)&&ut(Wt)})}var fe=et(Yt,2);ga(fe),I(tt,pt)};Ft(Bt,tt=>{$(X).moveable!==!1&&tt(lt)})}var Dt=et(Bt,2);{var $e=tt=>{Ae(tt,{onclick:()=>Re({action:"duplicate"},e),children:(pt,mt)=>{var At=fE(),Yt=Xt(At);Ze(Yt,{name:"duplicate"});var Wt=et(Yt,2);Xe(Wt,{children:(fe,ut)=>{var gt=Te();se(()=>Bi(gt,`Duplicate ${$(y)??""}`)),I(fe,gt)}}),I(pt,At)}})};Ft(Dt,tt=>{$(X).duplicatable&&tt($e)})}var yt=et(Dt,2);{var Nt=tt=>{Ae(tt,{onclick:()=>Re({action:"clear"},e),children:(pt,mt)=>{var At=dE(),Yt=Xt(At);Ze(Yt,{name:"clear"});var Wt=et(Yt,2);Xe(Wt,{children:(fe,ut)=>{var gt=Te();se(()=>Bi(gt,`Clear ${$(y)??""}`)),I(fe,gt)}}),I(pt,At)}})};Ft(yt,tt=>{$(X).clearable&&tt(Nt)})}var re=et(yt,2);{var be=tt=>{Ae(tt,{onclick:()=>Re({action:"remove"},e),children:(pt,mt)=>{var At=OE(),Yt=Xt(At);Ze(Yt,{name:"remove"});var Wt=et(Yt,2);Xe(Wt,{children:(fe,ut)=>{var gt=Te();se(()=>Bi(gt,`Delete ${$(y)??""}`)),I(fe,gt)}}),I(pt,At)}})};Ft(re,tt=>{$(X).removable&&tt(be)})}I(E,D)},$$slots:{default:!0}})},$$slots:{default:!0}})},f=H(()=>L(e.menu));Ft(h,x=>{$(f)&&x(u)})}var d=et(h,2);Oa(d,16,()=>yZ,x=>x,(x,y)=>{{let k=H(()=>{var Q;return kf((Q=e.activeHandle)==null?void 0:Q.handle,y)?e.activeHandle.state:void 0});cg(x,{get of(){return y},get state(){return $(k)}})}});var O=et(d,2);{var p=x=>{DZ(x)},m=H(()=>!e.interactive&&V(e.outline));Ft(O,x=>{$(m)&&x(p)})}var g=et(O,2);{var b=x=>{xX(x)},S=H(()=>e.selection.isAll());Ft(g,x=>{$(S)&&x(b)})}bc(n,x=>e.wrapperElement=x,()=>e==null?void 0:e.wrapperElement),se(x=>$t(n,"data-select-all",x),[()=>gr(e.selection.isAll())]),Mo("mouseover",n,x=>BX(x,e)),Mo("mouseout",n,x=>qX(x,e)),Mo("pointerdown",n,x=>NX(x,e)),fa("dragover",n,x=>GX(x)),Mo("keydown",r,x=>EX(x,e)),fa("copy",r,x=>RX(x,e)),fa("cut",r,x=>ZX(x,e)),fa("paste",r,x=>XX(x,e)),I(i,n),Yn()}MS(["mouseover","mouseout","pointerdown","keydown"]);class Kd extends Ln{constructor(e,n){super();C(this,"tableDescription");C(this,"widgetElement");C(this,"height");C(this,"destroyWidgetElement");this.tableDescription=e;const r=$E(n);if(L(r)){const{widgetElement:s,destroyWidgetElement:o}=this.create(r);this.widgetElement=s,this.destroyWidgetElement=o,this.height=D5(r,s)}else this.widgetElement=void 0,this.destroyWidgetElement=void 0,this.height=Nm}get estimatedHeight(){return this.height}coordsAt(e,n,r){const s=this.tableDescription.source.closestCell(n),o=Sc(e,s);if(V(o))return null;const l=o.getBoundingClientRect();return{top:l.top,right:l.right,bottom:l.bottom,left:l.left}}toDOM(e){if(L(this.widgetElement))return this.widgetElement;const{widgetElement:n,destroyWidgetElement:r}=this.create(e);return this.widgetElement=n,this.destroyWidgetElement=r,e.requestMeasure({read:()=>{this.height=n.getBoundingClientRect().height}}),n}destroy(e){var n;(n=this.destroyWidgetElement)==null||n.call(this),this.destroyWidgetElement=void 0,this.widgetElement=void 0,this.height=Nm}create(e){const n=bl(e.dom).createElement("div");n.className="tbl-table-widget",n.tabIndex=-1,n.addEventListener("pointerdown",O=>{(O==null?void 0:O.target)===n&&O.preventDefault()});const r=this.tableDescription,s=p5(()=>{Kc(()=>{const O=!r.table.text.eq(r.editorTableText),p=!ih(r.selection.value,r.editorSelectionValue);if(!O&&!p)return;const m=O?r.source.applyContent(r.table.text,r.editorTableText):void 0,g=O?new ro(m,r.table.colCount):r.source;let b;if(r.selection.isCell()){const{from:x}=g.cellSpan(r.selection.cell);b={anchor:r.from+x+r.selection.cellSection.anchor,head:r.from+x+r.selection.cellSection.head}}else r.selection.isAll()?b={anchor:r.from,head:r.to}:r.selection.isHidden()&&(b={anchor:r.from+1,head:r.from+1});const S=O?{from:r.from,to:r.to,insert:m}:void 0;r.markSynchronized(),e.dispatch({annotations:Gr("table.edit"),changes:S,selection:b})})}),{extensions:o,markdownConfig:l,globalKeyBindings:a,selectionType:c,lineWrapping:h}=wv(e.state),u=zS(gE,{target:n,props:{table:r.table,selection:r.selection,scrollElement:n,rootEditor:e,extensions:o,markdownConfig:l,globalKeyBindings:a,selectionType:c,lineWrapping:h,menuRootElement:Ck(e,nv).dom,onUndo:()=>id(e),onRedo:()=>Ka(e),onNavigate:O=>{e.dispatch({annotations:Gr("table.navigate"),selection:{anchor:O==="before"?Math.max(0,r.from-1):Math.min(e.state.doc.length,r.to+1)}}),e.focus()},onDelete:()=>{e.dispatch({annotations:Gr("table.delete"),changes:{from:r.from,to:r.to},selection:e.state.selection}),e.focus()}}}),f=()=>{_S(u)},d=Y5(n,({height:O})=>{this.height=O});return{widgetElement:n,destroyWidgetElement:Cr(s,f,d)}}static of(e,n){return new Kd(e,n)}}function bE(i,t){return{widget:Kd.of(i,t),block:!0,inclusive:!0}}function wE(i,t){return K.replace(bE(i,t))}function SE(i,t){const e=new qs;for(const n of i)e.add(n.from,n.to,wE(n,t));return e.finish()}function vE(i){return gv(i)}function xE(i,t){return gv(i,t)}function gv(i,t=[]){const e=[];return kA(St(i),n=>{L1(n)&&e.push({from:i.doc.lineAt(n.from).from,to:i.doc.lineAt(n.to).to})}),{spans:e,formatting:[],complete:Gk(i)}}const yE={create(i){return ba(i)},update(i,t){if(eZ(t))return ba(t.state);if(!t.docChanged&&V(t.selection)&&i.complete)return i;const{tables:e,formatting:n,decorations:r}=i;if(!t.docChanged&&i.complete)return{tables:fg(e,t),formatting:n,decorations:r.map(t.changes),complete:!0};if(tZ(t)||kE(t,e))return ba(t.state);const s=fg(e,t).map(c=>c.span),{complete:o,spans:l,formatting:a}=xE(t.state,s);return mn(s,l,aR)?{complete:o,tables:e,formatting:a,decorations:r.map(t.changes)}:ba(t.state)},provide(i){return z.decorations.from(i,t=>t.decorations)}},bv=mi.define(yE);function ba(i){const{spans:t,formatting:e,complete:n}=vE(i),{doc:r,selection:s}=i,o=t.map(l=>xf.of({span:l,doc:r,selection:s}));return{complete:n,tables:o,formatting:e,decorations:SE(o,i)}}function kE(i,t){return!GS(i)&&t.some(e=>i.changes.touchesRange(e.from,e.to)!==!1)}function fg(i,t){return PA(i,e=>e.applyTransaction(t))}const QE={create(){return{view:void 0}},update(i){return i}},Jd=mi.define(QE);function wv(i){return i.facet(rf)}function uo(i){return i.field(bv)}function $E(i){return i.field(Jd).view}function CE(i){const{handlePosition:t,selectionType:e,lineWrapping:n}=wv(i);return{...Uc(window)?{"data-tbl-hoverable":""}:{},"data-tbl-theme-mode":i.facet(z.darkTheme)?"dark":"light","data-tbl-handle-position":t,"data-tbl-selection-type":e,"data-tbl-line-wrapping":n}}const PE=["undo","redo","select.undo","select.redo"];function TE(i){return PE.some(t=>i.isUserEvent(t))}function AE(i){return Sv(i,"select.search")}function RE(i){return Sv(i,"select")}function ZE(i){return i.isUserEvent("delete.forward")}function XE(i){return i.isUserEvent("delete.backward")}function Sv(i,t){return i.annotation(Lt.userEvent)===t}const EE=({state:i,view:t,transactions:e})=>{t.hasFocus||uo(i).tables.some(n=>n.containsSelection())||e.some(n=>TE(n)||AE(n)&&!dv(t))&&t.focus()},vv=Pt.define(),LE=new Map(NS.map(i=>[i,vv.of(i)]));function xv(i){return LE.get(i)}const ME=(i,t)=>!t||!uo(i).tables.some(e=>e.containsSelection())?null:xv("table.focus"),zE=i=>{const{selection:t,startState:e,docChanged:n}=i;if(V(t)||n||!RE(i)||!hc(t)||!hc(e.selection))return i;const r=e.selection.main,s=t.main;for(const o of uo(e).tables){const l=o.from===s.head,a=o.to===s.head,c=o.from===r.head+1&&o.to===s.head-1,h=o.from===s.head+1&&o.to===r.head-1;let u;if(l?u=o.source.cellSpan(o.table.firstCellLocation).from:c?u=o.source.cellSpan(o.table.firstCellLocation).to:(a||h)&&(u=o.source.cellSpan(o.table.lastCellLocation).to),L(u))return[i,{annotation:Gr("table.navigate"),selection:oA({pos:o.from+u})}]}return i},_E=i=>{const{selection:t,startState:e}=i;if(V(t)||!hc(t))return i;const n=e.selection.main;if(ZE(i)){for(const r of uo(e).tables)if(n.head===r.from-1){const s=r.source.cellSpan(r.table.firstCellLocation).from;return[{selection:{anchor:r.from+s,head:r.from+s}}]}return i}else if(XE(i)){for(const r of uo(e).tables)if(n.head===r.to+1){const s=r.source.cellSpan(r.table.lastCellLocation).to;return[{selection:{anchor:r.from+s,head:r.from+s}}]}return i}else return i};function IE(i,{anchor:t,head:e,goalColumn:n,bidiLevel:r}={}){return P.range(t??i.anchor,e??i.head,n??i.goalColumn,r??i.bidiLevel??void 0)}const jE=i=>{const{selection:t,startState:e,docChanged:n}=i;if(V(t)||n||hc(t))return i;const r=t.ranges.map(s=>{if(s.empty)return s;const o=uo(e).tables,l=dg(s.anchor,o,e.doc.length),a=dg(s.head,o,e.doc.length);return L(l)||L(a)?IE(s,{anchor:l,head:a}):s});return mn(t.ranges,r,(s,o)=>s===o)?i:[i,{annotations:Gr("table.select"),selection:P.create(r,t.mainIndex)}]};function dg(i,t,e){for(const n of t){const r=n.from,s=n.to,o=n.from+1,l=n.to-1;if(i===r||i===o)return Math.max(0,r-1);if(i===s||i===l)return Math.min(e,s+1)}}const DE={"& .cm-tooltip.cm-tooltip-autocomplete:has(.cm-completionIcon-table)":{border:"1px solid var(--tbl-theme-menu-border-color)","box-shadow":"2px 2px 0 0 rgb(0 0 0 / 10%)","font-family":"var(--tbl-style-menu-font-family)","font-size":"var(--tbl-style-menu-font-size)"},"& .cm-tooltip.cm-tooltip-autocomplete > ul:has(.cm-completionIcon-table)":{"min-width":"auto",display:"flex","flex-direction":"column","justify-content":"center",padding:"0.25em 0","line-height":1,"font-family":"var(--tbl-style-menu-font-family)","font-size":"var(--tbl-style-menu-font-size)",background:"var(--tbl-theme-menu-background)"},"& .cm-tooltip.cm-tooltip-autocomplete ul li[aria-selected]:has(.cm-completionIcon-table)":{color:"var(--tbl-theme-menu-hover-text-color)","&::before":{background:"var(--tbl-theme-menu-hover-background)"}},"& .cm-tooltip.cm-tooltip-autocomplete ul li:not([aria-selected]):has(.cm-completionIcon-table)":{color:"var(--tbl-theme-menu-text-color)"},"& .cm-tooltip.cm-tooltip-autocomplete ul li:not([aria-selected]):has(.cm-completionIcon-table), & .cm-tooltip.cm-tooltip-autocomplete ul li[aria-selected]:has(.cm-completionIcon-table)":{position:"relative",padding:"0.5em 0.75em",background:"var(--tbl-theme-menu-background)",display:"flex",gap:"0.75em","align-items":"center","font-family":"var(--tbl-style-menu-font-family)","font-size":"var(--tbl-style-menu-font-size)","line-height":1,"&::before":{position:"absolute",height:"100%",width:"calc(100% - 0.5em)",left:"0.25em",top:0,content:'""',"pointer-events":"none"}},"& .cm-completionIcon.cm-completionIcon-table":{opacity:1,"mask-image":`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='14' width='12.25' viewBox='0 0 448 512'%3E%3C!--!Font Awesome Free v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2026 Fonticons, Inc.--%3E%3Cpath d='M384 96l-128 0 0 128 128 0 0-128zm64 128l0 192c0 35.3-28.7 64-64 64L64 480c-35.3 0-64-28.7-64-64L0 96C0 60.7 28.7 32 64 32l320 0c35.3 0 64 28.7 64 64l0 128zM64 288l0 128 128 0 0-128-128 0zm128-64l0-128-128 0 0 128 128 0zm64 64l0 128 128 0 0-128-128 0z'/%3E%3C/svg%3E")`,"mask-position":"center","mask-repeat":"no-repeat",padding:0,background:"currentColor",position:"relative",width:"1em",height:"1em","font-family":"var(--tbl-style-menu-font-family)","font-size":"var(--tbl-style-menu-font-size)","line-height":1},"& :has(.cm-completionIcon.cm-completionIcon-table) .cm-completionLabel":{position:"relative"}},YE={'&[data-tbl-handle-position="inside"] .tbl-table-widget':{"padding-left":"6px","margin-left":0},".tbl-table-widget":{contain:"paint","padding-top":"16px","padding-right":"16px","padding-bottom":"16px","padding-left":"16px","margin-left":"-10px","overflow-x":"auto","overflow-y":"hidden","&, &::before, &::after, & *, & *::before, & *::after":{"box-sizing":"border-box"}},"&.cm-editor .cm-content div.tbl-table-widget::selection, & .cm-content div.tbl-table-widget ::selection, & .cm-content div.tbl-table-widget:focus::selection, & .cm-content div.tbl-table-widget :focus::selection":{"background-color":"transparent !important","caret-color":"transparent !important"}},WE={".cm-tooltip.tbl-menu-tooltip":{border:"none","user-select":"none","&, &::before, &::after, & *, & *::before, & *::after":{"box-sizing":"border-box"}}},VE={".tbl-blocking-overlay":{position:"absolute",top:0,left:0,"z-index":900,"background-color":"transparent",width:"100%",height:"100%"}},BE={"& .cm-content div.tbl-table-widget .tbl-cell-editor ::selection, & .cm-content div.tbl-table-widget .tbl-cell-editor :focus::selection":{"background-color":"Highlight !important","caret-color":"initial !important"},"&[data-tbl-selection-type='codemirror'] .tbl-cell-editor .cm-editor .cm-content":{"caret-color":"transparent !important"},"&[data-tbl-selection-type='codemirror'] .tbl-cell-editor .cm-editor .cm-content ::selection, &[data-tbl-selection-type='codemirror'] .tbl-cell-editor .cm-editor .cm-content :focus::selection":{"background-color":"transparent !important","caret-color":"transparent !important"},"&[data-tbl-line-wrapping='wrap'] .tbl-cell-editor .cm-editor .cm-content":{"word-break":"normal","overflow-wrap":"break-word"},".tbl-cell-editor":{height:"100%"},".tbl-cell-editor .cm-editor":{margin:0,padding:0,outline:"none",height:"100%",background:"unset",color:"var(--tbl-theme-text-color)"},".tbl-cell-editor .cm-editor .cm-scroller":{margin:0,padding:0,overflow:"hidden","line-height":1.5,"font-family":"var(--tbl-style-font-family)","font-size":"var(--tbl-style-font-size)",color:"var(--tbl-theme-text-color)"},".tbl-cell-editor .cm-editor .cm-content":{margin:0,padding:"7px 9px","line-height":1.5,"font-family":"var(--tbl-style-font-family)","font-size":"var(--tbl-style-font-size)",color:"var(--tbl-theme-text-color)"},".tbl-cell-editor .cm-editor .cm-line":{margin:0,padding:"0 1px","line-height":1.5,"touch-action":"none","font-family":"var(--tbl-style-font-family)","font-size":"var(--tbl-style-font-size)",color:"var(--tbl-theme-text-color)"}},qE={".tbl-cell":{"box-sizing":"content-box",position:"relative","vertical-align":"top","background-color":"var(--tbl-row-background)",padding:0,"font-family":"var(--tbl-style-font-family)","font-size":"var(--tbl-style-font-size)","min-width":"calc(4ch + 20px)",height:"inherit","user-select":"none",border:"none","scroll-margin-right":"1px","scroll-margin-left":"1px","&:first-child":{"scroll-margin-left":"16px"},"&:last-child":{"scroll-margin-right":"16px"},'&[align="left"]':{"text-align":"left"},'&[align="center"]':{"text-align":"center"},'&[align="right"]':{"text-align":"right"},'&[data-border~="top"]':{"border-top":"1px solid var(--tbl-theme-border-color)"},'&[data-border~="right"]':{"border-right":"1px solid var(--tbl-theme-border-color)"},'&[data-border~="bottom"]':{"border-bottom":"1px solid var(--tbl-theme-border-color)"},'&[data-border~="left"]':{"border-left":"1px solid var(--tbl-theme-border-color)"},'&[data-state="moving"]':{"z-index":200,"background-color":"color-mix(in srgb, var(--tbl-row-background), transparent 15%)"},'&[data-state="shiftable"]':{transform:"translate3d(0, 0, 0)",transition:"transform 150ms ease"},"&[data-outline]":{"&::after":{display:"block",position:"absolute",top:"-1px",left:"-1px",border:"none",width:"calc(100% + 2px)",height:"calc(100% + 2px)","pointer-events":"none",content:'""'},'&[data-outline~="top"]::after':{"border-top":"2px solid var(--tbl-theme-outline-color)"},'&[data-outline~="right"]::after':{"border-right":"2px solid var(--tbl-theme-outline-color)"},'&[data-outline~="bottom"]::after':{"border-bottom":"2px solid var(--tbl-theme-outline-color)"},'&[data-outline~="left"]::after':{"border-left":"2px solid var(--tbl-theme-outline-color)"}}},".tbl-header-cell:not([align])":{"text-align":"var(--tbl-style-default-header-alignment)"}},NE={'&[data-tbl-line-wrapping="wrap"] .tbl-cell-view':{"word-break":"normal","overflow-wrap":"break-word"},'&[data-tbl-line-wrapping="nowrap"] .tbl-cell-view':{"white-space":"pre"},".tbl-cell-view":{margin:0,outline:"none",padding:"7px 10px",height:"100%","line-height":1.5,"white-space-collapse":"break-spaces","font-family":"var(--tbl-style-font-family)","font-size":"var(--tbl-style-font-size)",color:"var(--tbl-theme-text-color)","&[data-hidden]":{display:"none"}},".tbl-cell-view [data-br]":{"white-space":"pre"}},GE={".tbl-handle":{display:"flex",position:"absolute","justify-content":"center","align-items":"center","z-index":200,transition:"opacity 150ms ease 50ms","touch-action":"none"},".tbl-handle[data-hover], .tbl-handle[data-active]":{"--tbl-handle-opacity":1},'&:not([data-tbl-hoverable]) .tbl-handle[data-type="border"], &:not([data-tbl-hoverable]) .tbl-handle[data-type="table"]':{display:"none"},'.tbl-handle[data-type="border"]':{"background-color":"var(--tbl-theme-border-hover-color)"},'.tbl-handle[data-type="border"][data-active]':{"background-color":"var(--tbl-theme-border-active-color)"},'.tbl-handle[data-type="border"][data-toggle]':{transition:"none"},'.tbl-handle[data-type="border"][data-location="top"]':{top:"-1px",left:"-1px",width:"calc(100% + 2px)",height:"2px"},'.tbl-handle[data-type="border"][data-location="left"]':{top:"-1px",left:"-1px",width:"2px",height:"calc(100% + 2px)"},'.tbl-handle[data-type="border"][data-location="col"]':{top:"-1px",right:"-2px",width:"3px",height:"calc(100% + 2px)"},'.tbl-handle[data-type="border"][data-location="row"]':{bottom:"-2px",left:"-1px",width:"calc(100% + 2px)",height:"3px"},'.tbl-handle[data-type="table"]':{"box-sizing":"content-box",color:"var(--tbl-theme-border-hover-color)","background-color":"color-mix(in srgb, var(--tbl-theme-border-color), var(--tbl-theme-header-row-background) 80%)"},'.tbl-handle[data-type="table"][data-location="right"]':{top:0,left:"100%",width:"15px",height:"calc(100% - 2px)",border:"1px solid var(--tbl-theme-border-color)","border-left":"none","&::before":{position:"absolute",top:"-1px",left:"-2px",width:"2px",height:"calc(100% + 2px)",content:'""'},"&::after":{position:"absolute","z-index":366,top:"-1px",left:0,content:'""',width:"calc(100% + 1px)",height:"calc(100% + 2px)","background-color":"var(--tbl-overlay)"}},'.tbl-handle[data-type="table"][data-location="bottom-right"]':{left:"calc(100% - 1px)",top:"calc(100% - 1px)","z-index":250,width:"15px",height:"15px",border:"1px solid var(--tbl-theme-border-color)","border-top-style":"dashed","border-left-style":"dashed","&::after":{position:"absolute","z-index":366,top:"-1px",left:"-1px",content:'""',width:"calc(100% + 2px)",height:"calc(100% + 2px)","background-color":"var(--tbl-overlay)"}},'.tbl-handle[data-type="table"][data-location="bottom"]':{top:"100%",left:"0",width:"calc(100% - 2px)",height:"15px",border:"1px solid var(--tbl-theme-border-color)","border-top":"none","&::before":{position:"absolute",top:"-2px",left:"-1px",width:"calc(100% + 2px)",height:"2px",content:'""'},"&::after":{position:"absolute","z-index":366,top:0,left:"-1px",content:'""',width:"calc(100% + 2px)",height:"calc(100% + 1px)","background-color":"var(--tbl-overlay)"}},'.tbl-handle[data-type="table"][data-location="bottom-right"][data-hover] ~ .tbl-handle[data-type="table"][data-location="right"], .tbl-handle[data-type="table"][data-location="bottom-right"][data-active] ~ .tbl-handle[data-type="table"][data-location="right"], .tbl-handle[data-type="table"][data-location="bottom-right"][data-hover] ~ .tbl-handle[data-type="table"][data-location="bottom"], .tbl-handle[data-type="table"][data-location="bottom-right"][data-active] ~ .tbl-handle[data-type="table"][data-location="bottom"]':{"--tbl-handle-opacity":1},'.tbl-handle[data-type="table"][data-location="bottom-right"][data-hover] ~ .tbl-handle[data-type="table"][data-location="right"], .tbl-handle[data-type="table"][data-location="bottom-right"][data-active] ~ .tbl-handle[data-type="table"][data-location="right"]':{"border-bottom":"none"},'.tbl-handle[data-type="table"][data-location="bottom-right"][data-hover] ~ .tbl-handle[data-type="table"][data-location="bottom"], .tbl-handle[data-type="table"][data-location="bottom-right"][data-active] ~ .tbl-handle[data-type="table"][data-location="bottom"]':{"border-right":"none"},'.tbl-handle[data-type="table"][data-active], .tbl-handle[data-type="table"][data-location="bottom-right"][data-active] ~ .tbl-handle[data-type="table"][data-location="right"], .tbl-handle[data-type="table"][data-location="bottom-right"][data-active] ~ .tbl-handle[data-type="table"][data-location="bottom"]':{"background-color":"color-mix(in srgb, var(--tbl-theme-border-color), var(--tbl-theme-header-row-background) 80%)",color:"var(--tbl-theme-border-active-color)"},'&[data-tbl-handle-position="outside"] .tbl-handle[data-type="header"]':{"box-sizing":"content-box",transition:"none","z-index":300,color:"var(--tbl-theme-border-hover-color)",border:"1px solid transparent","&:hover":{"border-color":"var(--tbl-theme-border-color)","background-color":"color-mix(in srgb, var(--tbl-theme-border-color), var(--tbl-theme-header-row-background) 80%)"},"&[data-active]":{"background-color":"var(--tbl-theme-outline-color)","border-color":"var(--tbl-theme-outline-color)",color:"#ffffff"}},'&[data-tbl-handle-position="outside"] .tbl-handle[data-type="header"][data-location="row"]':{top:"-1px",left:"-17px",width:"15px",height:"100%","border-right":"none"},'&[data-tbl-handle-position="outside"] .tbl-handle[data-type="header"][data-location="col"]':{top:"-17px",left:"-1px",width:"100%",height:"15px","border-bottom":"none","&:hover::after":{position:"absolute","z-index":366,top:"-1px",left:"-1px",content:'""',width:"calc(100% + 2px)",height:"calc(100% + 1px)","background-color":"var(--tbl-overlay)"}},'&[data-tbl-handle-position="inside"] .tbl-handle[data-type="header"]':{transition:"none","z-index":300,color:"var(--tbl-theme-border-hover-color)","&:hover":{color:"var(--tbl-theme-border-active-color)"},"&[data-active]":{color:"var(--tbl-theme-outline-color)"}},'&[data-tbl-handle-position="inside"] .tbl-handle[data-type="header"][data-location="row"]':{top:"calc(50% - 13px)",left:"-1px",width:"3px",height:"26px","border-top":"4px solid var(--tbl-row-background)","border-bottom":"4px solid var(--tbl-row-background)","background-color":"var(--tbl-row-background)","&:hover::after, &[data-active]::after":{position:"absolute",top:"-6px",left:0,"box-sizing":"content-box","border-top":"2px solid transparent","border-bottom":"2px solid transparent",width:"calc(100% + 6px)",height:"calc(100% + 8px)",content:'""'}},'&[data-tbl-handle-position="inside"] .tbl-handle[data-type="header"][data-location="col"]':{top:"-1px",left:"calc(50% - 11.5px)",width:"23px",height:"3px","border-right":"4px solid var(--tbl-row-background)","border-left":"4px solid var(--tbl-row-background)","background-color":"var(--tbl-row-background)","&:hover::after, &[data-active]::after":{position:"absolute",top:0,left:"-6px","box-sizing":"content-box","border-right":"2px solid transparent","border-left":"2px solid transparent",width:"calc(100% + 8px)",height:"calc(100% + 6px)",content:'""'}},".tbl-handle-grip":{"pointer-events":"none","z-index":333}},UE={".tbl-menu-item-icon":{"z-index":200,width:"1em",height:"1em","pointer-events":"none","font-size":"var(--tbl-style-menu-font-size)"}},HE={".tbl-menu-item-text":{"z-index":200,"pointer-events":"none","user-select":"none","font-size":"var(--tbl-style-menu-font-size)"}},FE={".tbl-menu-item":{display:"flex",position:"relative","align-items":"center",gap:"0.75em",padding:"0.5em 0.75em",color:"var(--tbl-theme-menu-text-color)","user-select":"none","line-height":1,"font-size":"var(--tbl-style-menu-font-size)","&:active":{cursor:"pointer",color:"var(--tbl-theme-menu-hover-text-color)","&::after":{"background-color":"var(--tbl-theme-menu-hover-background)"}},"&::after":{position:"absolute",left:"0.25em",width:"calc(100% - 0.5em)",height:"100%",content:'""'}},"&[data-tbl-hoverable] .tbl-menu-item:hover":{cursor:"pointer",color:"var(--tbl-theme-menu-hover-text-color)","&::after":{"background-color":"var(--tbl-theme-menu-hover-background)"}}},KE={".tbl-menu-separator":{margin:"0.25em 0.5em","background-color":"var(--tbl-theme-menu-border-color)",height:"1px","font-size":"var(--tbl-style-menu-font-size)"}},JE={".tbl-menu":{position:"absolute",top:0,left:0,"z-index":900,"box-shadow":"2px 2px 0 0 rgb(0 0 0 / 10%)",border:"1px solid var(--tbl-theme-menu-border-color)","background-color":"var(--tbl-theme-menu-background)",padding:"0.25em 0",width:"max-content","font-family":"var(--tbl-style-menu-font-family)","font-size":"var(--tbl-style-menu-font-size)"}},tL={".tbl-select-all-overlay":{position:"absolute",top:0,left:0,"z-index":900,"background-color":"var(--tbl-overlay)",width:"100%",height:"100%","pointer-events":"none"}},eL={"& .tbl-table-wrapper[data-select-all]":{"--tbl-select-all-overlay":"var(--tbl-theme-select-all-blur-overlay)"},"&.cm-focused .tbl-table-wrapper[data-select-all]":{"--tbl-select-all-overlay":"var(--tbl-theme-select-all-focus-overlay)"},".tbl-table-wrapper":{"--tbl-overlay":"var(--tbl-select-all-overlay, transparent)",position:"relative",width:"fit-content","white-space-collapse":"collapse","touch-action":"none"},".tbl-table":{"border-collapse":"separate","border-spacing":0,overflow:"visible","touch-action":"none","&:focus-visible":{outline:"none"}},".tbl-table-head, .tbl-table-body":{height:"100%"},".tbl-table-row":{height:0},"@supports (-moz-appearance: none) /* TableTheme */":{".tbl-table-row":{height:"fit-content"}},".tbl-table-head .tbl-table-row":{"--tbl-row-background":"var(--tbl-theme-header-row-background)"},".tbl-table-body .tbl-table-row:nth-child(2n + 1)":{"--tbl-row-background":"var(--tbl-theme-even-row-background)"},".tbl-table-body .tbl-table-row:nth-child(2n)":{"--tbl-row-background":"var(--tbl-theme-odd-row-background)"}},iL={...DE,...WE,...YE,...eL,...VE,...qE,...BE,...NE,...GE,...JE,...FE,...UE,...HE,...KE,...tL},nL=i=>{var e;const t=(e=i.effects.find(n=>n.is(vv)))==null?void 0:e.value;return L(t)?{annotations:Gr(t)}:null},rL=i=>{const t=i.annotation(jd);return L(t)?[xv(H5(t))]:[]};class tO{static of(t){return t.state.field(Jd).view=t,new tO}constructor(){}}function sL(i){return[rf.of(i),bv,Jd,Fe.define(t=>tO.of(t)),z.editorAttributes.compute([rf,z.darkTheme],CE),z.baseTheme(iL),z.theme("light"in i.theme?{':where(:root:has(&[data-tbl-theme-mode="light"]))':i.theme.light.props,':where(:root:has(&[data-tbl-theme-mode="dark"]))':i.theme.dark.props}:{":where(:root:has(&))":i.theme.props}),z.theme({":where(:root:has(&))":i.style.props}),v0.of(rL),n0.of(nv),J.transactionExtender.of(nL),J.transactionFilter.of(_E),J.transactionFilter.of(zE),J.transactionFilter.of(jE),z.updateListener.of(EE),z.clipboardInputFilter.of(sR),z.focusChangeEffect.of(ME)]}function oL(i){return sL(Z1(i))}const lL=new Set(["about:","blob:","chrome-extension:","chrome:","data:","devtools:","file:","filesystem:","javascript:","view-source:"]);function yv(i,t){try{const e=new URL(t),n=new URL(i,e);return n.protocol==="http:"||n.protocol==="https:"?{kind:"web",url:n.href}:lL.has(n.protocol)?{kind:"browser-local",url:n.href}:{kind:"application",url:n.href}}catch{return{kind:"invalid"}}}const kv="cm-md-mark",Qv="cm-md-inline-code",$f="cm-md-list-item",Cf="cm-md-list-bullet",$v="cm-md-blockquote-line",Cv="cm-md-fenced-line",Pv="cm-md-hr",Tv="cm-md-task-checkbox",Av="cm-md-heading-1",Rv="cm-md-heading-2",eO="cm-md-link",Zv="cm-md-tag",Xv="cm-md-list-indent-source",Og="1.2em",aL="0.62em",Ro=K.replace({}),qn=K.mark({class:kv}),cL=K.mark({class:Xv}),hL=K.mark({class:Qv}),uL=K.line({class:Cf}),fL=K.line({class:$v}),dL=K.line({class:Cv}),OL=K.line({class:Av}),pL=K.line({class:Rv}),mL=K.mark({class:Zv});class gL extends Ln{toDOM(){const t=document.createElement("hr");return t.className=Pv,t}eq(t){return!0}ignoreEvent(){return!0}}const bL=K.replace({widget:new gL});class wL extends Ln{constructor(e,n,r){super();C(this,"checked");C(this,"from");C(this,"to");this.checked=e,this.from=n,this.to=r}eq(e){return e.checked===this.checked&&e.from===this.from&&e.to===this.to}toDOM(e){const n=document.createElement("input");return n.type="checkbox",n.checked=this.checked,n.className=Tv,n.tabIndex=-1,n.addEventListener("mousedown",r=>{r.preventDefault()}),n.addEventListener("change",()=>{const r=this.checked?"[ ]":"[x]";e.dispatch({changes:{from:this.from,to:this.to,insert:r}})}),n}ignoreEvent(e){return e.type!=="click"&&e.type!=="change"&&e.type!=="mousedown"}}const SL=new Set(["EmphasisMark","LinkMark","URL"]),vL=new Set(["HeaderMark","QuoteMark"]),pg=/(^|\s)(#[\p{L}\p{N}_/-]+)/gu,xL=/[/.,;:!?]+$/u,yL=new RegExp("\\p{L}","u"),kL=new Set(["InlineCode","FencedCode","URL","Link"]);function QL(i,t,e,n,r,s){return vL.has(i)?{kind:"block",contextFrom:r,contextTo:s}:i==="CodeMark"?t==="InlineCode"&&e!==null&&n!==null?{kind:"inline",contextFrom:e,contextTo:n}:null:SL.has(i)?e===null||n===null?null:{kind:"inline",contextFrom:e,contextTo:n}:null}function gn(i,t,e,n){return i<=n&&t>=e}function $L(i,t,e,n){const r=i.doc.lineAt(n);return gn(t,e,r.from,r.to)}function CL(i,t,e,n){return t.kind==="inline"?!gn(e,n,t.contextFrom,t.contextTo):!$L(i,e,n,t.contextFrom)}function PL(i){let t=i.firstChild;for(;t;){if(t.name==="TaskMarker")return!0;if(t.name==="Task"){let e=t.firstChild;for(;e;){if(e.name==="TaskMarker")return!0;e=e.nextSibling}}t=t.nextSibling}return!1}function TL(i){let t=i.parent;for(;t;){if(t.name==="ListItem")return t;t=t.parent}return null}function Hn(i,t){let e=i.firstChild;for(;e;){if(e.name===t)return e;e=e.nextSibling}return null}function mg(i,t){const e=[];let n=t.firstChild;for(;n;)n.name==="CodeMark"&&e.push(n),n=n.nextSibling;if(e.length>=2)return{from:t.from,to:e[e.length-1].to,closed:!0};const r=i.doc.lineAt(t.from);return{from:r.from,to:r.to,closed:!1}}function Ev(i,t){let e=t.to;for(;e<i.doc.length&&i.doc.sliceString(e,e+1)===" ";)e+=1;return{from:t.from,to:e}}function Kh(i,t){return{from:i.doc.lineAt(t.from).from,to:Ev(i,t).to}}function Jh(i,t){return Ev(i,t)}function gg(i,t,e){const n=Hn(t,"ListMark"),r=n?i.doc.lineAt(n.from).from:e.from;let s=e.to;for(;s<i.doc.length&&i.doc.sliceString(s,s+1)===" ";)s+=1;return{from:r,to:s}}function tu(i,t,e){const n=i.doc.lineAt(t.from);n.from<t.from&&e.push(cL.range(n.from,t.from))}function AL(i,t,e){let n=0;for(let r=t;r<e;r+=1)n+=i.doc.sliceString(r,r+1)===" "?2:1;return n}function RL(i){return K.line({class:$f,attributes:{style:`--cm-md-list-indent: ${i.prefixRevealed?0:i.indentColumns};`}})}function bg(i,t,e,n,r){let s=t;for(;s<=e;){const o=i.doc.lineAt(s);if(r.push(n.range(o.from)),o.to>=e)break;s=o.to+1}}function ZL(i,t,e,n){const r=Hn(t,"ListMark"),s=i.doc.lineAt(r?r.from:t.from).from,o=r?AL(i,s,r.from):0;let l=t.from;for(;l<=t.to;){const a=i.doc.lineAt(l),c=a.from===s,h=/^\s/.test(a.text);if(c||h){const u=e.get(a.from),f={indentColumns:o,prefixRevealed:c&&n};u===void 0||o>u.indentColumns?e.set(a.from,f):o===u.indentColumns&&f.prefixRevealed&&e.set(a.from,{...u,prefixRevealed:!0})}if(a.to>=t.to)break;l=a.to+1}}function XL(i,t){let e=i.resolveInner(t,1);for(;e;){if(kL.has(e.name)||e.name.startsWith("Table"))return!0;e=e.parent}return!1}function EL(i,t){const e=/^( {0,3})(#{1,6})(?:\s|$)/.exec(i);if(!e)return!1;const n=e[1]??"",r=e[2]??"",s=n.length,o=s+r.length;return t>=s&&t<o}function LL(i,t,e){for(let n=1;n<=i.doc.lines;n+=1){const r=i.doc.line(n);pg.lastIndex=0;let s;for(;(s=pg.exec(r.text))!==null;){const o=s[1]??"",a=(s[2]??"").replace(xL,"");if(a.length<=1||!yL.test(a))continue;const c=r.from+s.index+o.length,h=c+a.length;EL(r.text,c-r.from)||XL(t,c)||e.push(mL.range(c,h))}}}function wg(i,t,e,n){const r=[],s=new Map,o=new Set,l=i.selection.main,a=n?Math.min(l.from,l.to):-1,c=n?Math.max(l.from,l.to):-1;e.iterate({from:0,to:i.doc.length,enter:h=>{var p,m;if(h.name==="Table"||h.name.startsWith("Table"))return!1;const u=h.node.parent,f=(u==null?void 0:u.name)??null;let d=h.to;(h.name==="HeaderMark"||h.name==="QuoteMark")&&i.doc.sliceString(d,d+1)===" "&&(d+=1);const O=QL(h.name,f,(u==null?void 0:u.from)??null,(u==null?void 0:u.to)??null,h.from,d);if(O){const g=CL(i,O,a,c)?Ro:qn;r.push(g.range(h.from,d))}if(h.name==="ListMark"){const g=h.node.parent;if(g&&g.name==="ListItem"){const b=PL(g),S=((p=g.parent)==null?void 0:p.name)==="OrderedList";if(!b&&!S){const x=Kh(i,h.node),y=Jh(i,h.node);gn(a,c,x.from,x.to)?(tu(i,h.node,r),r.push(qn.range(y.from,y.to))):r.push(Ro.range(x.from,x.to))}else if(S){const x=i.doc.lineAt(h.node.from),y=Kh(i,h.node);x.from<h.node.from&&(gn(a,c,y.from,y.to)?tu(i,h.node,r):r.push(Ro.range(x.from,h.node.from))),r.push(qn.range(h.node.from,h.node.to))}}}if(h.name==="InlineCode"){const g=h.node.firstChild,b=h.node.lastChild;g&&b&&g!==b&&g.name==="CodeMark"&&b.name==="CodeMark"&&g.to<b.from&&r.push(hL.range(g.to,b.from))}if(h.name==="ListItem"){const g=Hn(h.node,"ListMark"),b=Hn(h.node,"Task"),S=Hn(h.node,"TaskMarker")??(b?Hn(b,"TaskMarker"):null),x=S!==null,y=((m=h.node.parent)==null?void 0:m.name)==="OrderedList";let k=!1;if(g){const Q=S?gg(i,h.node,S):Kh(i,g);k=gn(a,c,Q.from,Q.to)}if(ZL(i,h.node,s,k),!x&&!y&&g&&!k){const Q=i.doc.lineAt(h.from);o.add(Q.from)}}else if(h.name==="Blockquote")bg(i,h.from,h.to,fL,r);else if(h.name==="ATXHeading1"){const g=i.doc.lineAt(h.from);r.push(OL.range(g.from))}else if(h.name==="ATXHeading2"){const g=i.doc.lineAt(h.from);r.push(pL.range(g.from))}else if(h.name==="FencedCode"){const g=mg(i,h.node);bg(i,g.from,g.to,dL,r)}if(h.name==="Link"){let g=null,b=null,S=null,x=h.node.firstChild;for(;x;)x.name==="LinkMark"?g===null?g=x:b=x:x.name==="URL"&&(S=x),x=x.nextSibling;if(g&&b&&S&&g.to<b.from){const y=i.doc.sliceString(S.from,S.to),k=K.mark({class:eO,tagName:"a",attributes:{"data-href":y}});r.push(k.range(g.to,b.from))}}if(h.name==="CodeMark"&&f==="FencedCode"){const g=h.node.parent;if(g){const b=mg(i,g);if(b.closed){const S=gn(a,c,b.from,b.to)?qn:Ro;r.push(S.range(h.from,h.to))}else r.push(qn.range(h.from,h.to))}}if(h.name==="HorizontalRule"){const g=i.doc.lineAt(h.from);g.to>g.from&&!gn(a,c,g.from,g.to)&&r.push(bL.range(g.from,g.to))}if(h.name==="TaskMarker"){const g=TL(h.node),b=g?Hn(g,"ListMark"):null,S=g?gg(i,g,h.node):{from:h.from,to:h.to};if(gn(a,c,S.from,S.to)){if(b){const y=Jh(i,b);tu(i,b,r),r.push(qn.range(y.from,y.to))}r.push(qn.range(h.from,h.to))}else{if(b){const E=Jh(i,b),W=i.doc.lineAt(b.from).from;r.push(Ro.range(W,E.to))}const y=i.doc.sliceString(h.from,h.to),k=y==="[x]"||y==="[X]",Q=K.replace({widget:new wL(k,h.from,h.to)});r.push(Q.range(h.from,h.to))}}}});for(const[h,u]of s)r.push(RL(u).range(h));for(const h of o)r.push(uL.range(h));return LL(i,e,r),K.set(r,!0)}const ML=Fe.fromClass(class{constructor(i){C(this,"decorations");this.decorations=wg(i.state,i.visibleRanges,St(i.state),i.hasFocus)}update(i){(i.docChanged||i.selectionSet||i.viewportChanged||i.focusChanged||St(i.state)!==St(i.startState))&&(this.decorations=wg(i.state,i.view.visibleRanges,St(i.state),i.view.hasFocus))}},{decorations:i=>i.decorations}),zL=z.theme({"&":{fontFamily:"var(--font-sans)",fontSize:"calc(var(--text-base) + 0.5px)",lineHeight:"1.5"},".cm-scroller":{fontFamily:"inherit",fontSize:"inherit",lineHeight:"inherit"},".cm-content":{fontFamily:"inherit",fontSize:"inherit",lineHeight:"inherit",padding:"1.5rem 1rem"},[`.${Xv}`]:{fontFamily:"var(--font-mono)"},[`.${kv}`]:{fontFamily:"var(--font-mono)",fontSize:"0.9em"},[`.${Av}`]:{fontSize:"1.3em"},[`.${Rv}`]:{fontSize:"1.1em"},[`.${Qv}`]:{fontFamily:"var(--font-mono)",fontSize:"0.92em",padding:"1px 4px",borderRadius:"3px"},[`.${Zv}`]:{borderRadius:"var(--radius-pill)",padding:"0 0.35em",fontWeight:"600",boxDecorationBreak:"clone",WebkitBoxDecorationBreak:"clone"},[`.${$f}`]:{paddingLeft:`calc(0.5rem + var(--cm-md-list-indent, 0) * ${aL})`},[`.${$f}.${Cf}`]:{borderLeft:`${Og} solid transparent`},[`.${Cf}::before`]:{content:"'•'",marginLeft:`calc(-1 * ${Og})`,fontFamily:"var(--font-mono)",fontSize:"0.9em",paddingRight:"0.5rem"},[`.${$v}`]:{borderLeft:"3px solid transparent",paddingLeft:"1rem",marginLeft:"0.25rem"},[`.${Cv}`]:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:"0.92em",paddingLeft:"0.75em"},[`.${Pv}`]:{display:"inline-block",verticalAlign:"middle",border:"none",borderTop:"1px solid transparent",margin:0,width:"100%"},[`.${Tv}`]:{margin:"0 0.4em 0 0",cursor:"default",verticalAlign:"middle"},[`a.${eO}`]:{textDecoration:"underline",textUnderlineOffset:"0.15em",cursor:"pointer"}}),_L=4;function Lv(i){return i instanceof Element?i.closest(`a.${eO}`):null}function IL(i){const t=i.getAttribute("data-href");if(t===null)return null;try{return new URL(t,window.document.baseURI).href}catch{return null}}function Mv(){return window.__televisionContentBridge}function jL(i){const t={type:"navigation-request",url:i},e=Mv();if(e){e.postToHost(t);return}window.parent.postMessage(t,"*")}function DL(i){const t=Mv();if(t!=null&&t.openApplicationLink){t.openApplicationLink(i);return}window.location.href=i}function YL(i,t){return Math.hypot(t.clientX-i.x,t.clientY-i.y)>_L}let zr=null;function Sg(i){const t=Lv(i.target);if(!t||i.altKey)return zr=null,!1;const e=zr;if(zr=null,!e||e.anchor!==t)return!1;if(i.preventDefault(),YL(e,i))return!0;const n=yv(e.url,window.document.baseURI);return n.kind==="application"?DL(n.url):n.kind==="web"&&e.openExternally?window.open(n.url,"_blank","noopener,noreferrer"):n.kind==="web"&&jL(n.url),!0}const Ea={mousedown(i){const t=Lv(i.target);if(zr=null,!t||i.button!==0&&i.button!==1||i.altKey)return!1;const e=IL(t);return e===null||i.button===1&&yv(e,window.document.baseURI).kind!=="application"?!1:(zr={anchor:t,url:e,openExternally:i.metaKey||i.ctrlKey,x:i.clientX,y:i.clientY},i.preventDefault(),!0)},click(i){return i.button!==0?!1:Sg(i)},auxclick(i){return i.button!==1?!1:Sg(i)}},WL=z.domEventHandlers(Ea),Pf=/^(\d+)([.)])(\s|$)/;function VL(i,t){const e=[];let n=[],r=0;const s=a=>{o&&t.some(c=>c.from<=a&&c.to>=r)&&e.push(...n),n=[]};let o=!1,l=1;for(let a=1;a<=i.doc.lines;a+=1){const c=i.doc.line(a),h=Pf.exec(c.text);h?(o||(o=!0,l=1,r=c.from),parseInt(h[1],10)!==l&&n.push({from:c.from,to:c.from+h[1].length,insert:String(l)}),l+=1):c.text===""&&(s(c.from-1),o=!1)}return s(i.doc.length),e}const vg=ei.define(),BL=J.transactionFilter.of(i=>{if(!i.docChanged||i.annotation(vg)||!i.isUserEvent("input")&&!i.isUserEvent("delete"))return i;const t=[];i.changes.iterChangedRanges((n,r,s,o)=>{const l=i.state.doc.lineAt(s),a=Pf.test(i.startState.doc.lineAt(n).text)&&!Pf.test(l.text);t.push({from:l.from,to:a&&l.number<i.state.doc.lines?i.state.doc.line(l.number+1).to:i.state.doc.lineAt(Math.max(s,o-1)).to})});const e=VL(i.state,t);return e.length===0?i:[i,{changes:Vt.of(e,i.state.doc.length),annotations:vg.of(!0),sequential:!0}]}),qL=/^(\s*)([-*]|\d+[.)])(\s\[[ xX]\])?\s$/,NL=i=>{const{state:t}=i,e=t.selection.main;if(e.from!==e.to)return!1;const n=t.doc.lineAt(e.from),r=n.text.slice(0,e.from-n.from);return qL.test(r)?(i.dispatch({changes:{from:e.from-1,to:e.from,insert:""},selection:{anchor:e.from-1},userEvent:"delete.backward",scrollIntoView:!0}),!0):!1},GL=hn.highest(Mn.of([{key:"Backspace",run:NL}])),UL=[ML,zL,BL,GL,WL];function HL(i){const t=i.textContent??"",e=[];fl.parser.parse(t).iterate({enter(n){if(n.name!=="Link")return;const r=n.node,s=r.getChild("LinkMark"),o=r.getChildren("LinkMark")[1],l=r.getChild("URL");!s||!o||!l||s.to>=o.from||e.push({from:n.from,to:n.to,labelFrom:s.to,labelTo:o.from,href:t.slice(l.from,l.to)})}});for(const n of e.reverse()){const r=(h,u)=>{var m;const f=i.ownerDocument.createRange(),d=i.ownerDocument.createTreeWalker(i,NodeFilter.SHOW_TEXT);let O=0,p=!1;for(let g=d.nextNode();g;g=d.nextNode()){const b=O+(((m=g.textContent)==null?void 0:m.length)??0);if(!p&&h<=b&&(f.setStart(g,h-O),p=!0),u<=b){f.setEnd(g,u-O);break}O=b}return f},s=i.ownerDocument.createElement("a");s.className="cm-md-link",s.dataset.href=n.href,s.append(r(n.labelFrom,n.labelTo).cloneContents());const o=i.ownerDocument.createElement("span");o.className="cm-md-table-link";const l=i.ownerDocument.createElement("span");l.hidden=!0,l.textContent=t.slice(n.from,n.labelFrom);const a=i.ownerDocument.createElement("span");a.hidden=!0,a.textContent=t.slice(n.labelTo,n.to),o.append(l,s,a);const c=r(n.from,n.to);c.deleteContents(),c.insertNode(o)}}const FL=Fe.fromClass(class{constructor(i){C(this,"observer");C(this,"rendered",new WeakMap);C(this,"view");C(this,"pointerdown",i=>{this.isTableLink(i)&&!i.altKey&&(i.button===0||i.button===1)&&i.stopPropagation()});C(this,"mousedown",i=>{this.isTableLink(i)&&(Ea.mousedown(i)||i.button===1&&!i.altKey)&&(i.preventDefault(),i.stopPropagation())});C(this,"click",i=>{this.isTableLink(i)&&Ea.click(i)&&i.stopPropagation()});C(this,"auxclick",i=>{this.isTableLink(i)&&Ea.auxclick(i)&&i.stopPropagation()});this.view=i,this.observer=new MutationObserver(()=>this.render()),this.observer.observe(i.dom,{childList:!0,characterData:!0,attributes:!0,attributeFilter:["data-hidden"],subtree:!0}),i.dom.addEventListener("pointerdown",this.pointerdown,!0),i.dom.addEventListener("mousedown",this.mousedown,!0),i.dom.addEventListener("click",this.click,!0),i.dom.addEventListener("auxclick",this.auxclick,!0),this.render()}render(){for(const i of this.view.dom.querySelectorAll(".tbl-cell-view:not(.cm-md-table-cell-view)")){const t=i.innerHTML;let e=this.rendered.get(i);if(!e||e.source!==t){const n=(e==null?void 0:e.display)??i.cloneNode(!1);if(n.classList.add("cm-md-table-cell-view"),n.style.display="",n.replaceChildren(...Array.from(i.childNodes,r=>r.cloneNode(!0))),HL(n),!n.querySelector("a.cm-md-link")){e==null||e.display.remove(),this.rendered.delete(i),i.style.display="";continue}i.style.display="none",e||i.after(n),e={display:n,source:t},this.rendered.set(i,e)}e.display.getAttribute("data-hidden")!==i.getAttribute("data-hidden")&&(i.hasAttribute("data-hidden")?e.display.setAttribute("data-hidden",i.getAttribute("data-hidden")??""):e.display.removeAttribute("data-hidden"))}}isTableLink(i){return i.target instanceof Element&&!!i.target.closest(".tbl-cell-view a.cm-md-link")}destroy(){this.observer.disconnect();for(const i of this.view.dom.querySelectorAll(".tbl-cell-view:not(.cm-md-table-cell-view)")){const t=this.rendered.get(i);t&&(t.display.remove(),i.style.display="")}this.view.dom.removeEventListener("pointerdown",this.pointerdown,!0),this.view.dom.removeEventListener("mousedown",this.mousedown,!0),this.view.dom.removeEventListener("click",this.click,!0),this.view.dom.removeEventListener("auxclick",this.auxclick,!0)}}),KL=500,xg=ei.define(),JL=Lc.define([{tag:v.heading,fontWeight:"600"},{tag:v.strong,fontWeight:"600"},{tag:v.emphasis,fontStyle:"italic"},{tag:v.strikethrough,textDecoration:"line-through"}]);function yg(i){const t=i.length;return({state:e,dispatch:n})=>{const r=e.changeByRange(s=>{if(s.empty)return{changes:{from:s.from,insert:i+i},range:P.cursor(s.from+t)};const o=e.sliceDoc(s.from,s.to);if(o.length>=t*2&&o.startsWith(i)&&o.endsWith(i))return{changes:[{from:s.from,to:s.from+t},{from:s.to-t,to:s.to}],range:P.range(s.from,s.to-t*2)};const l=s.from>=t&&e.sliceDoc(s.from-t,s.from)===i,a=s.to+t<=e.doc.length&&e.sliceDoc(s.to,s.to+t)===i;return l&&a?{changes:[{from:s.from-t,to:s.from},{from:s.to,to:s.to+t}],range:P.range(s.from-t,s.to-t)}:{changes:[{from:s.from,insert:i},{from:s.to,insert:i}],range:P.range(s.from+t,s.to+t)}});return n(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}const tM=hn.highest(Mn.of([{key:"Mod-b",run:yg("**")},{key:"Mod-i",run:yg("*")},{key:"Enter",run:d1({nonTightLists:!1})}])),eM=cc.default.with({"--tbl-style-font-family":"var(--font-sans)","--tbl-style-font-size":"inherit","--tbl-style-menu-font-family":"var(--font-sans)","--tbl-style-menu-font-size":"var(--text-sm, 0.875rem)","--tbl-style-default-header-alignment":"left"}),iM=oL({theme:pl.light,style:eM,selectionType:"native",handlePosition:"outside",lineWrapping:"wrap",extensions:[Mn.of(tw)],globalKeyBindings:[...$0]}),zv=[QQ(),Oo.of(" "),tM,Mn.of([...tw,...$0,$$]),Ml({extensions:[kw,Dc,{remove:["SetextHeading"]}]}),b0(JL),z.lineWrapping,UL,iM,FL];function nM(i){const{parent:t,ctx:e}=i,n=i.debounceMs??KL;let r=null,s=null,o=null;const l=f=>{h.state.doc.toString()!==f&&h.dispatch({changes:{from:0,to:h.state.doc.length,insert:f},annotations:[xg.of(!0),Lt.addToHistory.of(!1)]})},a=async()=>{o=null;const f=h.state.doc.toString();r=f;try{await e.updateContent(f),s=f}catch{const d=s??"";l(d),r=d}},c=z.updateListener.of(f=>{!f.docChanged||f.transactions.some(O=>O.annotation(xg))||(o!==null&&clearTimeout(o),o=setTimeout(()=>{a()},n))}),h=new z({parent:t,state:J.create({doc:"",extensions:[zv,c]})}),u=f=>{const d=f.content;r!==null&&d===r||(l(d),s=d)};return e.addEventListener("content-updated",u),{view:h,dispose(){o!==null&&(clearTimeout(o),o=null),e.removeEventListener("content-updated",u),h.destroy()}}}const rM=`# Heading 1
|
|
65
|
+
`:l.textContent??""})??"",r=(t.textContent??"").slice(0,rg(i)),s=le(`${n}${r}`),o=n.length+rg(i);return fv({anchor:o,head:o},s,{trim:!1})}function _Z(i,t){var e=zd(),n=Xt(e);$r(n,()=>t.children),I(i,e)}function IZ(i,t){Dn(t,!0),th(()=>{const e=zS(_Z,{target:t.to,context:VR(),props:{children:t.children}});return()=>{_S(e)}}),Yn()}YR();var jZ=ot('<div class="tbl-blocking-overlay" aria-hidden="true"></div>');function DZ(i){var t=jZ();I(i,t)}function xc(i,t){const e=t.devicePixelRatio;return MA(i*e)/e}function YZ({x:i,y:t},e){return{x:xc(i,e),y:xc(t,e)}}var WZ=ot('<th class="tbl-cell tbl-header-cell"><!></th>'),VZ=ot('<td class="tbl-cell tbl-data-cell"><!></td>');function BZ(i,t){Dn(t,!0);const e=H(()=>ng(L(t.movement)?t.movement.border:{top:t.position.top,right:!0,bottom:!0,left:t.position.left})),n=H(()=>ng(t.outline)),r=H(()=>{var u;if(V((u=t.movement)==null?void 0:u.translate))return;const{x:c,y:h}=t.movement.state==="moving"?YZ(t.movement.translate,t.win):t.movement.translate;return`translate3d(${c}px, ${h}px, 0px)`});var s=zd(),o=Xt(s);{var l=c=>{var h=WZ();let u;var f=Ue(h);$r(f,()=>t.children),se(d=>{var O;$t(h,"align",t.alignment==="none"?void 0:t.alignment),$t(h,"data-component",Sl),$t(h,"data-row",t.location.row),$t(h,"data-col",t.location.col),$t(h,"data-border",$(e)),$t(h,"data-outline",$(n)),$t(h,"data-selected",d),$t(h,"data-state",(O=t.movement)==null?void 0:O.state),u=gc(h,"",u,{transform:$(r)})},[()=>gr(t.selected)]),I(c,h)},a=c=>{var h=VZ();let u;var f=Ue(h);$r(f,()=>t.children),se(d=>{var O;$t(h,"align",t.alignment==="none"?void 0:t.alignment),$t(h,"data-component",Sl),$t(h,"data-row",t.location.row),$t(h,"data-col",t.location.col),$t(h,"data-border",$(e)),$t(h,"data-outline",$(n)),$t(h,"data-selected",d),$t(h,"data-state",(O=t.movement)==null?void 0:O.state),u=gc(h,"",u,{transform:$(r)})},[()=>gr(t.selected)]),I(c,h)};Ft(o,c=>{t.position.top?c(l):c(a,!1)})}I(i,s),Yn()}function dv(i){var t;return L((t=bl(i.dom).activeElement)==null?void 0:t.closest(".cm-panels"))}function lg(i){return i.trim().split(/\s+/)}function qZ({doc:i,selection:t,parent:e,extensions:n,markdownConfig:r,selectionType:s,lineWrapping:o,globalKeyBindings:l,rootEditor:a,highlighter:c,onChange:h,eventHandlers:u}){return new z({doc:i,selection:t,parent:e,extensions:[n,hn.lowest([z.editorAttributes.of(f=>{const d=new Set(lg(a.themeClasses)),O=new Set(lg(f.themeClasses));return{class:[...d.difference(O)].join(" ")}}),Mn.of([...l.map(f=>({...f,run:L(f.run)?()=>f.run(a):void 0,shift:L(f.shift)?()=>f.shift(a):void 0}))]),s==="codemirror"?wk():[],b0(c),Ml({extensions:[E1,r.extensions??[]],addKeymap:!1,completeHTMLTags:r.completeHTMLTags,pasteURLAsLink:r.pasteURLAsLink,htmlTagLanguage:r.htmlTagLanguage}),z.domEventObservers(u),o==="wrap"?z.lineWrapping:[]])],dispatchTransactions:(f,d)=>{d.update(f),f.forEach(h)}})}var NZ=ot('<div class="tbl-cell-editor"></div>');function GZ(i,t){Dn(t,!0);let e=bf(t,"text",15),n=bf(t,"selection",15),r,s,o=!1,l=!1;function a(h){const{docChanged:u,newDoc:f,selection:d}=h;if(o)return;const O=L(d);if(u||O){if(u){const p=kd(f,{trim:!0});p.eq(e())||(e(p),l=!0)}if(O){const{head:p,anchor:m}=d.main,g=fv({head:p,anchor:m},f,{trim:!0});tv(g,n())||(n(g),l=!0)}}}Dd([()=>e(),()=>n()],()=>{if(l){l=!1;return}o=!0,s.dispatch({changes:s.state.changes({from:0,to:s.state.doc.length,insert:pc(e())}),selection:og(n(),e())}),o=!1},{lazy:!0}),th(()=>(s=qZ({doc:pc(e()),selection:og(n(),e()),parent:r,selectionType:t.selectionType,lineWrapping:t.lineWrapping,extensions:t.extensions,markdownConfig:t.markdownConfig,globalKeyBindings:t.globalKeyBindings,rootEditor:t.rootEditor,highlighter:t.highlighter,onChange:a,eventHandlers:{beforeinput:t.onbeforeinput,dragstart:t.ondragstart,keydown:(h,{state:u})=>t.onkeydown(h,u),paste:t.onpaste}}),dv(s)||s.focus(),()=>s.destroy()));var c=NZ();bc(c,h=>r=h,()=>r),I(i,c),Yn()}class sh{constructor({event:t,tableState:e,position:n}){C(this,"event");C(this,"tableState");C(this,"position");this.event=t,this.tableState=e,this.position=n}static navigate(t){new sh(t)[`navigate${t.key}`]()}navigateTab(){this.moveRight({createRow:!1,position:"end"})}navigateShiftTab(){this.moveLeft({createRow:!1,position:"end"})}navigateEnter(){this.moveDown({createRow:!1,position:"end"})}navigateArrowLeft(){this.position.left&&this.moveLeft({createRow:!1,position:"end"})}navigateArrowUp(){this.position.top&&this.moveUp({createRow:!1,position:"end"})}navigateArrowRight(){this.position.right&&this.moveRight({createRow:!1,position:"start"})}navigateArrowDown(){this.position.bottom&&this.moveDown({createRow:!1,position:"end"})}navigateShiftArrowLeft(){if(!(!this.position.left||V(this.tableState.outlinedSection)||V(this.tableState.activeCell))){if(this.event.preventDefault(),this.tableState.focusTable(),V(this.tableState.anchorCell)&&(this.tableState.anchorCell=this.tableState.activeCell),this.tableState.outlinedSection.endCol===this.tableState.anchorCell.col){if(this.tableState.outlinedSection.startCol===this.tableState.table.firstColIndex)return;this.tableState.outlinedSection=this.tableState.outlinedSection.expandLeft()}else this.tableState.outlinedSection=this.tableState.outlinedSection.contractLeft();this.tableState.activeCell=JS(this.tableState.activeCell)}}navigateShiftArrowUp(){if(!(!this.position.top||V(this.tableState.outlinedSection)||V(this.tableState.activeCell))){if(this.event.preventDefault(),this.tableState.focusTable(),V(this.tableState.anchorCell)&&(this.tableState.anchorCell=this.tableState.activeCell),this.tableState.outlinedSection.endRow===this.tableState.anchorCell.row){if(this.tableState.outlinedSection.startRow===this.tableState.table.firstRowIndex)return;this.tableState.outlinedSection=this.tableState.outlinedSection.expandUp()}else this.tableState.outlinedSection=this.tableState.outlinedSection.contractUp();this.tableState.activeCell=HS(this.tableState.activeCell)}}navigateShiftArrowRight(){if(!(!this.position.right||V(this.tableState.outlinedSection)||V(this.tableState.activeCell))){if(this.event.preventDefault(),this.tableState.focusTable(),V(this.tableState.anchorCell)&&(this.tableState.anchorCell=this.tableState.activeCell),this.tableState.outlinedSection.startCol===this.tableState.anchorCell.col){if(this.tableState.outlinedSection.endCol===this.tableState.table.lastColIndex)return;this.tableState.outlinedSection=this.tableState.outlinedSection.expandRight()}else this.tableState.outlinedSection=this.tableState.outlinedSection.contractRight();this.tableState.activeCell=FS(this.tableState.activeCell)}}navigateShiftArrowDown(){if(!(!this.position.bottom||V(this.tableState.outlinedSection)||V(this.tableState.activeCell))){if(this.event.preventDefault(),this.tableState.focusTable(),V(this.tableState.anchorCell)&&(this.tableState.anchorCell=this.tableState.activeCell),this.tableState.outlinedSection.startRow===this.tableState.anchorCell.row){if(this.tableState.outlinedSection.endRow===this.tableState.table.lastRowIndex)return;this.tableState.outlinedSection=this.tableState.outlinedSection.expandDown()}else this.tableState.outlinedSection=this.tableState.outlinedSection.contractDown();this.tableState.activeCell=KS(this.tableState.activeCell)}}moveLeft({createRow:t,position:e}){if(!V(this.tableState.activeCell)){if(this.event.preventDefault(),Pr(this.tableState.activeCell,this.tableState.table.firstCellLocation)){if(!t){this.tableState.navigate("before");return}this.tableState.table.prependEmptyRows(1),this.tableState.activeCell={row:this.tableState.activeCell.row+1,col:this.tableState.activeCell.col}}this.moveTo(this.tableState.activeCell.col===this.tableState.table.firstColIndex?{row:this.tableState.activeCell.row-1,col:this.tableState.table.lastColIndex}:{row:this.tableState.activeCell.row,col:this.tableState.activeCell.col-1},e)}}moveUp({createRow:t,position:e}){if(!V(this.tableState.activeCell)){if(this.event.preventDefault(),this.tableState.activeCell.row===this.tableState.table.firstRowIndex){if(!t){this.tableState.navigate("before");return}this.tableState.table.prependEmptyRows(1),this.tableState.activeCell={row:this.tableState.activeCell.row+1,col:this.tableState.activeCell.col}}this.moveTo({row:this.tableState.activeCell.row-1,col:this.tableState.activeCell.col},e)}}moveRight({createRow:t,position:e}){if(!V(this.tableState.activeCell)){if(this.event.preventDefault(),Pr(this.tableState.activeCell,this.tableState.table.lastCellLocation)){if(!t){this.tableState.navigate("after");return}this.tableState.table.appendEmptyRows(1)}this.moveTo(this.tableState.activeCell.col===this.tableState.table.lastColIndex?{row:this.tableState.activeCell.row+1,col:this.tableState.table.firstColIndex}:{row:this.tableState.activeCell.row,col:this.tableState.activeCell.col+1},e)}}moveDown({createRow:t,position:e}){if(!V(this.tableState.activeCell)){if(this.event.preventDefault(),this.tableState.activeCell.row===this.tableState.table.lastRowIndex){if(!t){this.tableState.navigate("after");return}this.tableState.table.appendEmptyRows(1)}this.moveTo({row:this.tableState.activeCell.row+1,col:this.tableState.activeCell.col},e)}}moveTo(t,e){if(this.tableState.activeCell=t,this.tableState.anchorCell=t,this.tableState.outlinedSection=rt.ofCell(t),this.tableState.selection.isCell()){const n=e==="start"?0:this.tableState.table.cellAt(t).length;this.tableState.selectionValue={cell:t,section:{anchor:n,head:n}}}}}const bt={alt:"Alt",arrowDown:"ArrowDown",arrowLeft:"ArrowLeft",arrowRight:"ArrowRight",arrowUp:"ArrowUp",backspace:"Backspace",c:"c",delete:"Delete",enter:"Enter",escape:"Escape",shift:"Shift",tab:"Tab",v:"v",x:"x"},UZ=[bt.arrowDown,bt.arrowLeft,bt.arrowRight,bt.arrowUp,bt.enter,bt.tab,`${bt.shift}${bt.arrowDown}`,`${bt.shift}${bt.arrowLeft}`,`${bt.shift}${bt.arrowRight}`,`${bt.shift}${bt.arrowUp}`,`${bt.shift}${bt.tab}`],ag=new Set(UZ);function Ov({key:i,shiftKey:t,altKey:e,metaKey:n,ctrlKey:r}){if(!(e||n||r))return t?ag.has(`${bt.shift}${i}`)?`${bt.shift}${i}`:void 0:ag.has(i)?i:void 0}function HZ(i,t){i.inputType==="historyUndo"?(t.undo(),i.preventDefault()):i.inputType==="historyRedo"&&(t.redo(),i.preventDefault())}function FZ(i){i.preventDefault()}function KZ(i,t,e){const n=Ov(i);if(V(n))return;const r=t.selection.main.head,s=t.doc.lineAt(r).number,o=0,l=t.doc.length,a=1,c=t.doc.lines,h={top:s===a,right:r===l,bottom:s===c,left:r===o};sh.navigate({tableState:e,key:n,event:i,position:h})}function JZ(i,t){Yd({tableState:t,event:i})}var tX=ot('<div class="tbl-cell-view" contenteditable="" tabindex="-1"><!></div>');function eX(i,t){Dn(t,!0);var e=tX(),n=Ue(e);$r(n,()=>t.children),se(r=>{$t(e,"data-component",Wd),$t(e,"data-hidden",r)},[()=>gr(t.hidden)]),I(i,e),Yn()}const pv="Handle";function Vd(i){if(!qS(i,{component:pv}))return;const{type:t,location:e}=_d(i).dataset;if(t==="table")return{type:t,location:e};{const n=nh(Wl(i));return QZ({location:e,type:t},n)}}var iX=ri('<svg class="tbl-handle-grip" width="15" height="3" fill="currentColor" viewBox="0 0 15 3" xmlns="http://www.w3.org/2000/svg"><circle cx="1.5" cy="1.5" r="1.5"></circle><circle cx="7.5" cy="1.5" r="1.5"></circle><circle cx="13.5" cy="1.5" r="1.5"></circle></svg>'),nX=ri('<svg class="tbl-handle-grip" width="3" height="15" fill="currentColor" viewBox="0 0 3 15" xmlns="http://www.w3.org/2000/svg"><circle cy="1.5" cx="1.5" r="1.5"></circle><circle cy="7.5" cx="1.5" r="1.5"></circle><circle cy="13.5" cx="1.5" r="1.5"></circle></svg>'),rX=ot('<div class="tbl-handle" role="button" aria-hidden="true"><!></div>');function cg(i,t){Dn(t,!0);let e=bf(t,"toggle",3,!1);const n={table:{right:"vertical",bottom:"horizontal"},header:{row:"vertical",col:"horizontal"}},r=H(()=>{var c;return(c=n[t.of.type])==null?void 0:c[t.of.location]});var s=rX();gc(s,"",{},{opacity:"var(--tbl-handle-opacity, 0)"});var o=Ue(s);{var l=c=>{var h=iX();I(c,h)},a=c=>{var h=nX();I(c,h)};Ft(o,c=>{$(r)==="horizontal"?c(l):$(r)==="vertical"&&c(a,1)})}se((c,h,u)=>{$t(s,"data-component",pv),$t(s,"data-type",t.of.type),$t(s,"data-location",t.of.location),$t(s,"data-active",c),$t(s,"data-hover",h),$t(s,"data-toggle",u)},[()=>gr(t.state==="active"),()=>gr(t.state==="hover"),()=>gr(e())]),I(i,s),Yn()}var sX=ot('<div class="tbl-menu"><!></div>');function oX(i,t){Dn(t,!0);let e,n=ct(void 0);th(()=>{t.translate(e).then(l=>q(n,l,!0))});var r=sX();let s;var o=Ue(r);$r(o,()=>t.children),bc(r,l=>e=l,()=>e),se(l=>s=gc(r,"",s,l),[()=>({visibility:L($(n))?void 0:"hidden",transform:L($(n))?`translate3d(${$(n).x}px, ${$(n).y}px, 0px)`:void 0})]),I(i,r),Yn()}var lX=ot('<div class="tbl-menu-item" role="menuitem" tabindex="-1"><!></div>');function Ae(i,t){var e=lX(),n=Ue(e);$r(n,()=>t.children),Mo("click",e,function(...r){var s;(s=t.onclick)==null||s.apply(this,r)}),I(i,e)}MS(["click"]);function Re(i,t){switch(i.action){case"add":return t.menu.clickAdd(i.direction);case"align":return t.menu.clickAlign(i.alignment);case"clear":return t.menu.clickClear();case"duplicate":return t.menu.clickDuplicate();case"move":return t.menu.clickMove(i.direction);case"remove":return t.menu.clickRemove();case"sort":return t.menu.clickSort(i.direction)}}var aX=ri('<path d="M294.6 454.6L214.6 534.6C202.1 547.1 181.8 547.1 169.3 534.6L89.3 454.6C76.8 442.1 76.8 421.8 89.3 409.3C101.8 396.8 122.1 396.8 134.6 409.3L160 434.7L160 128C160 110.3 174.3 96 192 96C209.7 96 224 110.3 224 128L224 434.7L249.4 409.3C261.9 396.8 282.2 396.8 294.7 409.3C307.2 421.8 307.2 442.1 294.7 454.6zM476.6 113.7C527.3 215 553.9 268.4 556.6 273.7C564.5 289.5 558.1 308.7 542.3 316.6C526.5 324.5 507.3 318.1 499.4 302.3L492.2 288L403.8 288L396.6 302.3C388.7 318.1 369.5 324.5 353.7 316.6C337.9 308.7 331.5 289.5 339.4 273.7C342.1 268.4 368.7 215 419.4 113.7C424.8 102.9 435.9 96 448 96C460.1 96 471.2 102.8 476.6 113.7zM448 199.6L427.8 240L468.2 240L448 199.6zM352 384C352 366.3 366.3 352 384 352L512 352C524.9 352 536.6 359.8 541.6 371.8C546.6 383.8 543.8 397.5 534.7 406.7L461.3 480L512 480C529.7 480 544 494.3 544 512C544 529.7 529.7 544 512 544L384 544C371.1 544 359.4 536.2 354.4 524.2C349.4 512.2 352.2 498.5 361.3 489.3L434.7 415.9L384 415.9C366.3 415.9 352 401.6 352 383.9z"></path>'),cX=ri('<path d="M294.6 454.6L214.6 534.6C202.1 547.1 181.8 547.1 169.3 534.6L89.3 454.6C76.8 442.1 76.8 421.8 89.3 409.3C101.8 396.8 122.1 396.8 134.6 409.3L160 434.7L160 128C160 110.3 174.3 96 192 96C209.7 96 224 110.3 224 128L224 434.7L249.4 409.3C261.9 396.8 282.2 396.8 294.7 409.3C307.2 421.8 307.2 442.1 294.7 454.6zM352 128C352 110.3 366.3 96 384 96L512 96C524.9 96 536.6 103.8 541.6 115.8C546.6 127.8 543.8 141.5 534.7 150.7L461.3 224L512 224C529.7 224 544 238.3 544 256C544 273.7 529.7 288 512 288L384 288C371.1 288 359.4 280.2 354.4 268.2C349.4 256.2 352.2 242.5 361.3 233.3L434.8 160L384 160C366.3 160 352 145.7 352 128zM476.6 337.7L556.6 497.7C564.5 513.5 558.1 532.7 542.3 540.6C526.5 548.5 507.3 542.1 499.4 526.3L492.2 512L403.8 512L396.6 526.3C388.7 542.1 369.5 548.5 353.7 540.6C337.9 532.7 331.5 513.5 339.4 497.7L419.4 337.7C424.8 326.9 435.9 320 448 320C460.1 320 471.2 326.8 476.6 337.7zM448 423.6L427.8 464L468.2 464L448 423.6z"></path>'),hX=ri('<path d="M384 128C384 145.7 369.7 160 352 160L128 160C110.3 160 96 145.7 96 128C96 110.3 110.3 96 128 96L352 96C369.7 96 384 110.3 384 128zM384 384C384 401.7 369.7 416 352 416L128 416C110.3 416 96 401.7 96 384C96 366.3 110.3 352 128 352L352 352C369.7 352 384 366.3 384 384zM96 256C96 238.3 110.3 224 128 224L512 224C529.7 224 544 238.3 544 256C544 273.7 529.7 288 512 288L128 288C110.3 288 96 273.7 96 256zM544 512C544 529.7 529.7 544 512 544L128 544C110.3 544 96 529.7 96 512C96 494.3 110.3 480 128 480L512 480C529.7 480 544 494.3 544 512z"></path>'),uX=ri('<path d="M448 128C448 110.3 433.7 96 416 96L224 96C206.3 96 192 110.3 192 128C192 145.7 206.3 160 224 160L416 160C433.7 160 448 145.7 448 128zM544 256C544 238.3 529.7 224 512 224L128 224C110.3 224 96 238.3 96 256C96 273.7 110.3 288 128 288L512 288C529.7 288 544 273.7 544 256zM96 512C96 529.7 110.3 544 128 544L512 544C529.7 544 544 529.7 544 512C544 494.3 529.7 480 512 480L128 480C110.3 480 96 494.3 96 512zM448 384C448 366.3 433.7 352 416 352L224 352C206.3 352 192 366.3 192 384C192 401.7 206.3 416 224 416L416 416C433.7 416 448 401.7 448 384z"></path>'),fX=ri('<path d="M544 128C544 145.7 529.7 160 512 160L288 160C270.3 160 256 145.7 256 128C256 110.3 270.3 96 288 96L512 96C529.7 96 544 110.3 544 128zM544 384C544 401.7 529.7 416 512 416L288 416C270.3 416 256 401.7 256 384C256 366.3 270.3 352 288 352L512 352C529.7 352 544 366.3 544 384zM96 256C96 238.3 110.3 224 128 224L512 224C529.7 224 544 238.3 544 256C544 273.7 529.7 288 512 288L128 288C110.3 288 96 273.7 96 256zM544 512C544 529.7 529.7 544 512 544L128 544C110.3 544 96 529.7 96 512C96 494.3 110.3 480 128 480L512 480C529.7 480 544 494.3 544 512z"></path>'),dX=ri('<path d="M342.6 81.4C330.1 68.9 309.8 68.9 297.3 81.4L137.3 241.4C124.8 253.9 124.8 274.2 137.3 286.7C149.8 299.2 170.1 299.2 182.6 286.7L288 181.3L288 552C288 569.7 302.3 584 320 584C337.7 584 352 569.7 352 552L352 181.3L457.4 286.7C469.9 299.2 490.2 299.2 502.7 286.7C515.2 274.2 515.2 253.9 502.7 241.4L342.7 81.4z"></path>'),OX=ri('<path d="M566.6 342.6C579.1 330.1 579.1 309.8 566.6 297.3L406.6 137.3C394.1 124.8 373.8 124.8 361.3 137.3C348.8 149.8 348.8 170.1 361.3 182.6L466.7 288L96 288C78.3 288 64 302.3 64 320C64 337.7 78.3 352 96 352L466.7 352L361.3 457.4C348.8 469.9 348.8 490.2 361.3 502.7C373.8 515.2 394.1 515.2 406.6 502.7L566.6 342.7z"></path>'),pX=ri('<path d="M297.4 566.6C309.9 579.1 330.2 579.1 342.7 566.6L502.7 406.6C515.2 394.1 515.2 373.8 502.7 361.3C490.2 348.8 469.9 348.8 457.4 361.3L352 466.7L352 96C352 78.3 337.7 64 320 64C302.3 64 288 78.3 288 96L288 466.7L182.6 361.3C170.1 348.8 149.8 348.8 137.3 361.3C124.8 373.8 124.8 394.1 137.3 406.6L297.3 566.6z"></path>'),mX=ri('<path d="M73.4 297.4C60.9 309.9 60.9 330.2 73.4 342.7L233.4 502.7C245.9 515.2 266.2 515.2 278.7 502.7C291.2 490.2 291.2 469.9 278.7 457.4L173.3 352L544 352C561.7 352 576 337.7 576 320C576 302.3 561.7 288 544 288L173.3 288L278.7 182.6C291.2 170.1 291.2 149.8 278.7 137.3C266.2 124.8 245.9 124.8 233.4 137.3L73.4 297.3z"></path>'),gX=ri('<path d="M262.2 48C248.9 48 236.9 56.3 232.2 68.8L216 112L120 112C106.7 112 96 122.7 96 136C96 149.3 106.7 160 120 160L520 160C533.3 160 544 149.3 544 136C544 122.7 533.3 112 520 112L424 112L407.8 68.8C403.1 56.3 391.2 48 377.8 48L262.2 48zM128 208L128 512C128 547.3 156.7 576 192 576L448 576C483.3 576 512 547.3 512 512L512 208L464 208L464 512C464 520.8 456.8 528 448 528L192 528C183.2 528 176 520.8 176 512L176 208L128 208zM288 280C288 266.7 277.3 256 264 256C250.7 256 240 266.7 240 280L240 456C240 469.3 250.7 480 264 480C277.3 480 288 469.3 288 456L288 280zM400 280C400 266.7 389.3 256 376 256C362.7 256 352 266.7 352 280L352 456C352 469.3 362.7 480 376 480C389.3 480 400 469.3 400 456L400 280z"></path>'),bX=ot('<div class="tbl-menu-item-icon"><svg xmlns="http://www.w3.org/2000/svg" height="14" width="14" viewBox="0 0 640 640" fill="currentColor"><!></svg></div>');function Ze(i,t){var e=bX(),n=Ue(e),r=Ue(n);{var s=b=>{var S=aX();I(b,S)},o=b=>{var S=cX();I(b,S)},l=b=>{},a=b=>{var S=hX();I(b,S)},c=b=>{var S=uX();I(b,S)},h=b=>{var S=fX();I(b,S)},u=b=>{var S=dX();I(b,S)},f=b=>{var S=OX();I(b,S)},d=b=>{var S=pX();I(b,S)},O=b=>{var S=mX();I(b,S)},p=b=>{},m=b=>{},g=b=>{var S=gX();I(b,S)};Ft(r,b=>{t.name==="sort-ascending"?b(s):t.name==="sort-descending"?b(o,1):t.name==="align-none"?b(l,2):t.name==="align-left"?b(a,3):t.name==="align-center"?b(c,4):t.name==="align-right"?b(h,5):t.name==="move-up"?b(u,6):t.name==="move-right"?b(f,7):t.name==="move-down"?b(d,8):t.name==="move-left"?b(O,9):t.name==="duplicate"?b(p,10):t.name==="clear"?b(m,11):t.name==="remove"&&b(g,12)})}I(i,e)}var wX=ot('<div class="tbl-menu-item-text"><!></div>');function Xe(i,t){var e=wX(),n=Ue(e);$r(n,()=>t.children),I(i,e)}var SX=ot('<div class="tbl-menu-separator"></div>');function ga(i){var t=SX();I(i,t)}var vX=ot('<div class="tbl-select-all-overlay" aria-hidden="true"></div>');function xX(i){var t=vX();I(i,t)}const yX=new Set([bt.c,bt.v,bt.x]);function kX(i,t){return yX.has(i.key)&&i[lR(t)]}const QX=[bt.backspace,bt.delete],$X=new Set(QX);function CX({key:i}){return $X.has(i)?i:void 0}function PX(i){return/^F\d+$/.test(i)}const TX=new Set([bt.alt,bt.escape,bt.enter,bt.shift]);function AX({metaKey:i,ctrlKey:t,key:e}){return!t&&!i&&!TX.has(e)&&!PX(e)}function RX(i,t){t.selection.isCell()||av({tableState:t,event:i})}function ZX(i,t){t.selection.isCell()||cv({tableState:t,event:i})}function XX(i,t){t.selection.isCell()||Yd({tableState:t,event:i})}function EX(i,t){if(L(i.target)&&L(uv(i.target))){i.preventDefault();return}if(!t.interactive||t.selection.isCell())return;const e=Ov(i);if(L(e)){sh.navigate({tableState:t,key:e,event:i,position:{left:!0,top:!0,right:!0,bottom:!0}});return}const n=CX(i);if(L(n)){lv({tableState:t,event:i});return}if(t.activeTable&&L(t.activeCell)&&AX(i)){t.activeTable=!1,t.anchorCell=t.activeCell;const r=t.table.cellAt(t.activeCell).length;t.selectionValue={cell:t.activeCell,section:{head:r,anchor:r}},t.outlinedSection=rt.ofCell(t.activeCell);return}kX(i,t.window)||dk(t.rootEditor,i,"editor")&&i.preventDefault()}function Bd(i){return i.buttons===1}function mv(i,t){return t.setPointerCapture(i.pointerId),()=>t.releasePointerCapture(i.pointerId)}class oh{constructor({offset:t,maxScroll:e,boundaryElement:n,scrollElement:r}){C(this,"offset");C(this,"maxScroll");C(this,"boundaryElement");C(this,"scrollElement");C(this,"scroll");C(this,"handle");C(this,"xAmount");C(this,"yAmount");const s=this.scrollInternal.bind(this);this.scroll=()=>{this.handle=requestAnimationFrame(s)},this.xAmount=0,this.yAmount=0,this.offset=t??0,this.maxScroll=e,this.boundaryElement=n,this.scrollElement=r}updatePosition(t,e){const n=this.boundaryElement.x.getBoundingClientRect();t<n.left+this.offset?this.xAmount=-ce(this.offset+(n.left-t),{max:this.maxScroll}):t>n.right-this.offset?this.xAmount=ce(this.offset-(n.right-t),{max:this.maxScroll}):this.xAmount=0;const r=this.boundaryElement.y.getBoundingClientRect();e<r.top+this.offset?this.yAmount=-ce(this.offset+(r.top-e),{max:this.maxScroll}):e>r.bottom-this.offset?this.yAmount=ce(this.offset-(r.bottom-e),{max:this.maxScroll}):this.yAmount=0,V(this.handle)&&(this.xAmount!==0||this.yAmount!==0)&&this.scroll()}destroy(){L(this.handle)&&cancelAnimationFrame(this.handle)}scrollInternal(){if(this.xAmount===0&&this.yAmount===0){this.scroll();return}this.scrollElement.x.scrollBy({left:this.xAmount}),this.scrollElement.y.scrollBy({top:this.yAmount}),this.scroll()}static of(t){return new oh(t)}}class yc{constructor({start:t,size:e}){C(this,"start");C(this,"size");this.start=t,this.size=e}get mid(){return this.start+this.size/2}get end(){return this.start+this.size}static of(t){return new yc(t)}}var kc;(i=>{function t(e,n){return qd.of(e,n)}i.of=t})(kc||(kc={}));class qd{constructor(t,e){C(this,"rows");C(this,"cols");C(this,"firstRowIndex",0);C(this,"firstColIndex",0);const n=[...t.querySelectorAll("tr:first-child > th")],r=[...t.querySelectorAll("tr > th:first-child,tr > td:first-child")];this.rows=r.map((s,o)=>{const{top:l,height:a}=hg(s,e),c=0;return yc.of({start:l+c,size:a-c})}),this.cols=n.map((s,o)=>{const{left:l,width:a}=hg(s,e),c=o===0?1:0;return yc.of({start:l+c,size:a-c})})}rowsOrCols(t){return t==="row"?this.rows:this.cols}rowAt(t){return this.rows[t]}colAt(t){return this.cols[t]}rowOrColAt(t,e){return t==="row"?this.rowAt(e):this.colAt(e)}get firstRow(){return this.rows[this.firstRowIndex]}get firstCol(){return this.cols[this.firstColIndex]}firstRowOrCol(t){return t==="row"?this.firstRow:this.firstCol}get lastRow(){return this.rows[this.lastRowIndex]}get lastCol(){return this.cols[this.lastColIndex]}lastRowOrCol(t){return t==="row"?this.lastRow:this.lastCol}firstRowOrColIndex(t){return 0}get lastRowIndex(){return this.rowCount-1}get lastColIndex(){return this.colCount-1}lastRowOrColIndex(t){return t==="row"?this.lastRowIndex:this.lastColIndex}get rowCount(){return this.rows.length}get colCount(){return this.cols.length}get minRowSize(){return Oc(...this.rows.map(t=>t.size))}get minColSize(){return Oc(...this.cols.map(t=>t.size))}moveRowOrColAt(t,{fromIndex:e,toIndex:n}){if(e===n)return;const r=this.rowsOrCols(t),s=r[e];if(e<n){for(const o of Qn({start:e,endExclusive:n}))r[o]=r[o+1],r[o].start-=s.size;s.start=r[n].start+r[n].size}else{for(const o of Qn({start:e,endExclusive:n}))r[o]=r[o-1],r[o].start+=s.size;s.start=r[n].start-s.size}r[n]=s}lastCellBeforePosition(t){const e=this.rows.map(r=>r.start).findLastIndex(r=>r<t.y),n=this.cols.map(r=>r.start).findLastIndex(r=>r<t.x);return{row:e===-1?0:e,col:n===-1?0:n}}static of(t,e){return new qd(t,e)}}function hg(i,t){const{top:e,left:n,width:r,height:s}=i.getBoundingClientRect();return{top:e+t.y,left:n+t.x,width:r,height:s}}class vl{constructor({tableState:t,cellLocation:e}){C(this,"tableState");C(this,"tableMeasurement");C(this,"autoScroller");C(this,"shouldAutoScroll");C(this,"removeEventListeners");C(this,"currentCell");this.tableState=t,this.currentCell=e,this.autoScroller=oh.of({offset:10,maxScroll:32,boundaryElement:{x:t.scrollElement,y:t.rootScrollElement},scrollElement:{x:t.scrollElement,y:t.rootScrollElement}}),this.shouldAutoScroll=V5({delayMillis:500}),this.tableMeasurement=kc.of(t.tableElement,{x:t.scrollOffsetX,y:t.scrollOffsetY})}start(){this.tableState.activeCell=this.currentCell,this.tableState.anchorCell=this.currentCell,this.tableState.outlinedSection=rt.ofCell(this.currentCell),this.tableState.outline={outlined:!1},this.removeEventListeners=Cr(Et(this.tableState.window,"pointermove",t=>this.drag(t)),Et(this.tableState.window,"pointerup",()=>this.end()),Et(this.tableState.window,"pointerleave",()=>this.end()))}resizeAndContinue(t){t.preventDefault(),V(this.tableState.anchorCell)&&(this.tableState.anchorCell=this.currentCell),this.expandOrContract(this.currentCell),this.tableState.outline={outlined:!0},this.removeEventListeners=Cr(Et(this.tableState.window,"pointermove",e=>this.drag(e)),Et(this.tableState.window,"pointerup",()=>this.end()),Et(this.tableState.window,"pointerleave",()=>this.end()))}drag(t){if(!Bd(t)){this.end();return}t.preventDefault(),this.shouldAutoScroll()&&this.autoScroller.updatePosition(t.clientX,t.clientY);const e=this.tableMeasurement.lastCellBeforePosition({x:t.clientX+this.tableState.scrollOffsetX,y:t.clientY+this.tableState.scrollOffsetY});Pr(e,this.currentCell)||(this.currentCell=e,this.tableState.outline={outlined:!0},this.expandOrContract(e))}end(){var t;(t=this.removeEventListeners)==null||t.call(this),this.autoScroller.destroy(),this.tableState.outline=void 0}expandOrContract(t){this.tableState.focusTable();const[e,n]=t.row<=this.tableState.anchorCell.row?[t.row,this.tableState.anchorCell.row]:[this.tableState.anchorCell.row,t.row],[r,s]=t.col<=this.tableState.anchorCell.col?[t.col,this.tableState.anchorCell.col]:[this.tableState.anchorCell.col,t.col];this.tableState.outlinedSection=rt.of({row:{start:e,endExclusive:n+1},col:{start:r,endExclusive:s+1}}),this.tableState.activeCell=t}static startOutline(t){new vl(t).start()}static resizeAndContinueOutline(t){new vl(t).resizeAndContinue(t.event)}}function LX(i,t){Uc(t.window)&&(t.hoveredCell=i)}function MX(i){Uc(i.window)&&(i.hoveredCell=void 0)}function zX(i,t,e){if(!(!e.interactive||!Bd(i)))if(i.shiftKey){if(e.selection.isCell()&&Pr(t,e.selection.cell))return;vl.resizeAndContinueOutline({event:i,tableState:e,cellLocation:t})}else vl.startOutline({event:i,tableState:e,cellLocation:t})}const _X=new Intl.Collator(navigator.language,{numeric:!0,sensitivity:"base"});function ug(i,t){return _X.compare(i,t)}function IX({metaKey:i,shiftKey:t,altKey:e,ctrlKey:n,key:r}){return r===bt.escape&&!t&&!e&&!i&&!n}class Nd{constructor({tableState:t,handle:e,point:n}){C(this,"tableState");C(this,"handle");C(this,"point");C(this,"removeEventListeners");this.tableState=t,this.handle=e,this.point=n}get rowOrCol(){return this.handle.location}get index(){return this.handle.index}open(){const t=this.tableState.document.body;this.removeEventListeners=Cr(Et(t,"pointerdown",o=>{o.preventDefault(),(V(o.target)||!YS(this.tableState.menuRootElement,o.target))&&this.close()}),Et(t,"wheel",o=>o.preventDefault(),{passive:!1}),Et(t,"keydown",o=>{o.preventDefault(),IX(o)&&this.close()})),this.tableState.focusTable(),this.tableState.activeHandle={state:"active",handle:this.handle},this.tableState.outlinedSection=rt.of(this.rowOrCol==="row"?{row:{start:this.index,endExclusive:this.index+1},col:this.tableState.table.colRange}:{row:this.tableState.table.rowRange,col:{start:this.index,endExclusive:this.index+1}});const e=this.rowOrCol==="row"?{row:this.index,col:this.tableState.table.lastColIndex}:{row:this.tableState.table.lastRowIndex,col:this.index};this.tableState.activeCell=e,this.tableState.anchorCell=e;const n=this.index!==this.tableState.table.firstRowOrColIndex(this.rowOrCol),r=this.index!==this.tableState.table.lastRowOrColIndex(this.rowOrCol);let s=!1;n?s=r?!0:"backward":r&&(s="forward"),this.tableState.menu={type:this.rowOrCol,capabilities:{addable:!0,alignable:this.rowOrCol==="col",clearable:!0,duplicatable:!0,moveable:s,removable:!this.tableState.table.hasSingleRowOrCol(this.rowOrCol),sortable:this.rowOrCol==="col"},clickAdd:o=>this.clickAdd(o),clickAlign:o=>this.clickAlign(o),clickClear:()=>this.clickClear(),clickDuplicate:()=>this.clickDuplicate(),clickMove:o=>this.clickMove(o),clickRemove:()=>this.clickRemove(),clickSort:o=>this.clickSort(o),computeTranslation:o=>this.computeTranslation(o)}}close(){var t;(t=this.removeEventListeners)==null||t.call(this),this.tableState.menu=void 0,this.tableState.activeHandle=void 0}async computeTranslation(t){const e=await JT({getBoundingClientRect:()=>({x:this.point.x,y:this.point.y,top:this.point.y,right:this.point.x,bottom:this.point.y,left:this.point.x,width:0,height:0})},t,{middleware:[FT({allowedPlacements:this.rowOrCol==="row"?["right-start","right-end"]:["right-start","right"]}),KT({crossAxis:!0})]}),n=wo(t);return{x:xc(e.x,n),y:xc(e.y,n)}}clickAdd(t){var e;if(this.tableState.table.addEmptyRowsOrColsAt(this.rowOrCol,{index:t==="before"?this.index:this.index+1,count:1}),t==="after"){this.tableState.outlinedSection=(e=this.tableState.outlinedSection)==null?void 0:e.shift(this.rowOrCol,"forward");const n=Fh(this.rowOrCol,this.tableState.activeCell,"forward");this.tableState.activeCell=n,this.tableState.anchorCell=n}this.close()}clickAlign(t){this.tableState.table.setAlignmentAt(this.index,t),this.close()}clickClear(){this.tableState.table.clearRowOrCol(this.rowOrCol,this.index),this.close()}clickDuplicate(){this.tableState.table.duplicateRowOrColAt(this.rowOrCol,this.index),this.close()}clickMove(t){var n;this.tableState.table.moveRowOrColAt(this.rowOrCol,{fromIndex:this.index,toIndex:t==="backward"?this.index-1:this.index+1}),this.tableState.outlinedSection=(n=this.tableState.outlinedSection)==null?void 0:n.shift(this.rowOrCol,t);const e=Fh(this.rowOrCol,this.tableState.activeCell,t);this.tableState.activeCell=e,this.tableState.anchorCell=e,this.close()}clickRemove(){var t;if(this.tableState.table.removeRowsOrColsAt(this.rowOrCol,{index:this.index,count:1}),!this.tableState.table.hasRowOrColAt(this.rowOrCol,this.index)){this.tableState.outlinedSection=(t=this.tableState.outlinedSection)==null?void 0:t.shift(this.rowOrCol,"backward");const e=Fh(this.rowOrCol,this.tableState.activeCell,"backward");this.tableState.activeCell=e,this.tableState.anchorCell=e}this.close()}clickSort(t){this.tableState.table.sortByColAt(this.index,t==="ascending"?(e,n)=>ug(e.toString(),n.toString()):(e,n)=>ug(n.toString(),e.toString())),this.close()}static showMenu(t){new Nd(t).open()}}class Gd{constructor({rowOrCol:t,index:e,position:n,subject:r,tableElement:s,scrollOffsetX:o,scrollOffsetY:l}){C(this,"coordinate");C(this,"initialIndex");C(this,"size");C(this,"initialPosition");C(this,"minBound");C(this,"maxBound");C(this,"scrollOffsetX");C(this,"scrollOffsetY");C(this,"subject");C(this,"rowOrCol");C(this,"tableMeasurement");C(this,"currentIndex");C(this,"currentPosition");C(this,"dragged");this.scrollOffsetX=o,this.scrollOffsetY=l;const a=kc.of(s,{x:this.scrollOffsetX(),y:this.scrollOffsetY()});this.rowOrCol=t,this.coordinate=t==="row"?"y":"x",this.initialIndex=e,this.initialPosition=n[this.coordinate],this.minBound=a.firstRowOrCol(this.rowOrCol).start-a.rowOrColAt(this.rowOrCol,e).start,this.maxBound=a.lastRowOrCol(this.rowOrCol).end-a.rowOrColAt(this.rowOrCol,e).end,this.size=a.rowOrColAt(this.rowOrCol,e).size,this.subject=r,this.dragged=!1,this.tableMeasurement=a,this.currentIndex=e,this.currentPosition=n[this.coordinate]}start(){return{cellMovement:t=>this.cellMovement(t)}}drag(t){this.currentPosition=t[this.coordinate];const{currentIndex:e,move:n}=this.calculateDrag();return this.currentIndex=e,this.initialIndex!==this.currentIndex&&(this.dragged=!0),L(n)&&this.tableMeasurement.moveRowOrColAt(this.rowOrCol,n),{cellMovement:r=>this.cellMovement(r)}}end(){return this.initialIndex===this.currentIndex?{moved:!1,dragged:this.dragged}:{moved:!0,toIndex:this.currentIndex}}cellMovement(t){return{border:this.cellBorder(t),state:this.cellState(t),translate:this.cellTranslate(t)}}cellBorder(t){const e=this.isRowOrColExposed(t[this.rowOrCol]),n=this.subject.containsCell(t);return this.rowOrCol==="row"?{top:e,right:!0,bottom:!n||t.row===this.tableMeasurement.lastRowIndex,left:this.tableMeasurement.firstColIndex===t.col}:{top:this.tableMeasurement.firstRowIndex===t.row,right:!n||t.col===this.tableMeasurement.lastColIndex,bottom:!0,left:e}}cellState(t){return this.subject.containsCell(t)?"moving":"shiftable"}cellTranslate(t){const e=this.rowOrColTranslate(t[this.rowOrCol]);return this.rowOrCol==="row"?{x:0,y:e}:{x:e,y:0}}isRowOrColExposed(t){const e=this.reorderIndex(t),n=e===this.tableMeasurement.firstRowOrColIndex(this.rowOrCol),r=e===this.currentIndex+1;return n||r}get rowOrColShift(){if(this.currentIndex!==this.initialIndex)return this.currentIndex<this.initialIndex?{direction:"forwards",range:{start:this.currentIndex,endExclusive:this.initialIndex},indexDiff:1,positionDiff:this.size-1}:{direction:"backwards",range:{start:this.initialIndex+1,endExclusive:this.currentIndex+1},indexDiff:-1,positionDiff:1-this.size}}rowOrColTranslate(t){if(t===this.initialIndex)return ce(this.currentPosition-this.initialPosition,{min:this.minBound,max:this.maxBound});const e=this.rowOrColShift;return V(e)?0:yn(t,e.range)?e.positionDiff:0}reorderIndex(t){const e=this.rowOrColShift;return V(e)?t:t===this.initialIndex?this.currentIndex:yn(t,e.range)?t+e.indexDiff:t}calculateDrag(){const t=this.tableMeasurement.rowsOrCols(this.rowOrCol),e={name:"current",index:this.currentIndex,mid:t[this.currentIndex].mid},n=this.currentIndex!==this.tableMeasurement.firstRowOrColIndex(this.rowOrCol)?{name:"left",index:this.currentIndex-1,mid:t[this.currentIndex-1].start+t[this.currentIndex].size/2}:void 0,r=this.currentIndex!==this.tableMeasurement.lastRowOrColIndex(this.rowOrCol)?{name:"right",index:this.currentIndex+1,mid:t[this.currentIndex].start+t[this.currentIndex+1].size+t[this.currentIndex].size/2}:void 0,s=RA(ZA([e,n,r]),(o,l)=>nf(this.currentPosition-o.mid)-nf(this.currentPosition-l.mid));return s.name==="current"?{currentIndex:this.currentIndex,move:void 0}:{currentIndex:s.index,move:{fromIndex:this.currentIndex,toIndex:s.index}}}static of(t){return new Gd(t)}}class Ud{constructor({event:t,tableState:e,rowOrCol:n,index:r,onClick:s}){C(this,"tableState");C(this,"rowOrCol");C(this,"index");C(this,"onClick");C(this,"moveTracker");C(this,"subject");C(this,"autoScroller");C(this,"removeEventListeners");this.tableState=e,this.rowOrCol=n,this.index=r,this.subject=rt.of(n==="row"?{row:{start:r,endExclusive:r+1},col:this.tableState.table.colRange}:{row:this.tableState.table.rowRange,col:{start:r,endExclusive:r+1}}),this.onClick=s,this.autoScroller=oh.of({offset:16,maxScroll:32,boundaryElement:{x:e.scrollElement,y:e.rootScrollElement},scrollElement:{x:e.scrollElement,y:e.rootScrollElement}}),this.moveTracker=Gd.of({subject:this.subject,rowOrCol:n,index:r,position:{x:t.clientX+e.scrollOffsetX,y:t.clientY+e.scrollOffsetY},tableElement:e.tableElement,scrollOffsetX:()=>this.tableState.scrollOffsetX,scrollOffsetY:()=>this.tableState.scrollOffsetY})}start(t){t.preventDefault();const e=this.moveTracker.start();this.tableState.outlinedSection=this.subject,this.tableState.move=e,this.tableState.activeHandle={state:"active",handle:{type:"header",index:this.index,location:this.rowOrCol}};const n=this.rowOrCol==="row"?{row:this.index,col:this.tableState.table.lastColIndex}:{row:this.tableState.table.lastRowIndex,col:this.index};this.tableState.activeCell=n,this.tableState.anchorCell=n,this.tableState.focusTable();const r=_d(t.target);this.removeEventListeners=Cr(mv(t,r),Et(r,"pointermove",s=>this.drag(s)),Et(r,"pointerup",()=>this.end()))}drag(t){t.preventDefault(),this.autoScroller.updatePosition(t.clientX,t.clientY),this.tableState.move=this.moveTracker.drag({x:t.clientX+this.tableState.scrollOffsetX,y:t.clientY+this.tableState.scrollOffsetY})}end(){var e;(e=this.removeEventListeners)==null||e.call(this),this.autoScroller.destroy();const t=this.moveTracker.end();if(t.moved){this.tableState.table.moveRowOrColAt(this.rowOrCol,{fromIndex:this.index,toIndex:t.toIndex}),this.tableState.outlinedSection=rt.of(this.rowOrCol==="row"?{row:{start:t.toIndex,endExclusive:t.toIndex+1},col:this.tableState.table.colRange}:{row:this.tableState.table.rowRange,col:{start:t.toIndex,endExclusive:t.toIndex+1}});const n=this.rowOrCol==="row"?{row:t.toIndex,col:this.tableState.table.lastColIndex}:{row:this.tableState.table.lastRowIndex,col:t.toIndex};this.tableState.activeCell=n,this.tableState.anchorCell=n}this.tableState.move=void 0,this.tableState.activeHandle=void 0,!t.moved&&!t.dragged&&this.onClick()}static startMove(t){new Ud(t).start(t.event)}}function jX(i){return i==="row"?"y":"x"}class Hd{constructor({tableState:t,handle:e,position:n,cellSizePixels:r,dragThresholdPixels:s}){C(this,"tableState");C(this,"type");C(this,"initialHandle");C(this,"initialRowOrColCount");C(this,"initialPosition");C(this,"initialOutlinedSection");C(this,"initialActiveCell");C(this,"initialAnchorCell");C(this,"cellSizePixels");C(this,"dragThresholdPixels");C(this,"dragged");this.tableState=t,this.type=this.handleToType(e),this.initialHandle=e,this.initialPosition=n,this.initialRowOrColCount={row:t.table.rowCount,col:t.table.colCount},this.initialActiveCell=t.activeCell,this.initialAnchorCell=t.anchorCell,this.initialOutlinedSection=t.outlinedSection,this.cellSizePixels=r,this.dragThresholdPixels=s,this.dragged=!1}start(){return{activeHandle:{state:"active",handle:this.initialHandle}}}drag(t){return this.dragged=!0,this.calculateDrag(t)}end(){return this.dragged?{activeHandle:void 0}:this.calculateClick()}calculateClick(){if(this.type!=="table")return this.calculateClickRowOrCol(this.type);if(this.initialHandle.location==="right")return this.calculateClickRowOrCol("col");if(this.initialHandle.location==="bottom")return this.calculateClickRowOrCol("row");const t=this.calculateClickRowOrCol("row"),e=this.calculateClickRowOrCol("col");return{operation:{row:t.operation.row,col:e.operation.col},activeHandle:t.activeHandle,activeCell:L(t.activeCell)&&L(e.activeCell)?{row:t.activeCell.row,col:e.activeCell.col}:void 0,anchorCell:L(t.anchorCell)&&L(e.anchorCell)?{row:t.anchorCell.row,col:e.anchorCell.col}:void 0,outlinedSection:L(t.outlinedSection)&&L(e.outlinedSection)?rt.of({row:t.outlinedSection.row,col:e.outlinedSection.col}):void 0}}calculateClickRowOrCol(t){const e=this.type==="table"?this.tableState.table.lastRowOrColIndex(t)+1:this.initialHandle.index;return{operation:{[t]:{action:"add",index:e,count:1}},activeHandle:this.type==="table"?void 0:{state:"hover",handle:{type:"border",location:this.handleLocationAt(e),index:e}},...this.calculateCellMovement(t,1)}}calculateDrag(t){if(this.type!=="table")return this.calculateDragRowOrCol(this.type,t);if(this.initialHandle.location==="right")return this.calculateDragRowOrCol("col",t);if(this.initialHandle.location==="bottom")return this.calculateDragRowOrCol("row",t);const e=this.calculateDragRowOrCol("row",t),n=this.calculateDragRowOrCol("col",t);if(V(e)&&V(n))return;const r=e??this.calculateCellMovement("row",this.rowOrColDiff("row")),s=n??this.calculateCellMovement("col",this.rowOrColDiff("col"));return{operation:{row:e==null?void 0:e.operation.row,col:n==null?void 0:n.operation.col},activeHandle:(e==null?void 0:e.activeHandle)??(n==null?void 0:n.activeHandle),activeCell:L(r.activeCell)&&L(s.activeCell)?{row:r.activeCell.row,col:s.activeCell.col}:void 0,anchorCell:L(r.anchorCell)&&L(s.anchorCell)?{row:r.anchorCell.row,col:s.anchorCell.col}:void 0,outlinedSection:L(r.outlinedSection)&&L(s.outlinedSection)?rt.of({row:r.outlinedSection.row,col:s.outlinedSection.col}):void 0}}calculateDragRowOrCol(t,e){const n=jX(t),r=e.position[n]-this.initialPosition[n],s=zA(r/this.cellSizePixels[t]),o=r%this.cellSizePixels[t]>=this.dragThresholdPixels[t]?1:0,l=this.tableState.table.rowOrColCount(t)-this.initialRowOrColCount[t],a=s+o-l,c=this.type==="table"?this.tableState.table.lastRowOrColIndex(t)+1:this.initialHandle.index+l;if(a!==0)return a>0?this.calculateDragRowOrColMore({rowOrCol:t,start:c,length:a}):this.calculateDragRowOrColLess({rowOrCol:t,start:c,length:Oc(-a,c,this.tableState.table.lastRowOrColIndex(t))})}calculateDragRowOrColLess({rowOrCol:t,start:e,length:n}){let r=0;for(const o of Qn({start:e-1,endExclusive:e-n-1})){if(!this.tableState.table.hasEmptyRowOrColAt(t,o))break;r++}if(r===0)return;const s=e-(r-1)-1;return{operation:{[t]:{action:"remove",index:e-r,count:r}},activeHandle:this.type==="table"?{state:"active",handle:this.initialHandle}:{state:"active",handle:{type:"border",location:this.handleLocationAt(s),index:s}},...this.calculateCellMovement(t,this.rowOrColDiff(t)-r)}}calculateDragRowOrColMore({rowOrCol:t,start:e,length:n}){return{operation:{[t]:{action:"add",index:e,count:n}},activeHandle:{state:"active",handle:this.type==="table"?this.initialHandle:{type:"border",location:this.handleLocationAt(e+n),index:e+n}},...this.calculateCellMovement(t,this.rowOrColDiff(t)+n)}}calculateCellMovement(t,e){var r,s;const n=this.type==="table"?this.initialRowOrColCount[t]:this.initialHandle.index;if(e>=0)return{outlinedSection:(r=this.initialOutlinedSection)==null?void 0:r.addForwardsByRowOrCol(t,{start:n,count:e}),activeCell:L(this.initialActiveCell)?tg(t,this.initialActiveCell,{start:n,count:e}):void 0,anchorCell:L(this.initialAnchorCell)?tg(t,this.initialAnchorCell,{start:n,count:e}):void 0};{const o=-e,l=(s=this.initialOutlinedSection)==null?void 0:s.subtractBackwardsByRowOrCol(t,{start:n,count:o,min:this.tableState.table.firstRowOrColIndex(t)}),a=L(l)?{min:l.startRowOrCol(t),max:l.endRowOrCol(t)}:void 0,c=L(this.initialActiveCell)?eg(t,this.initialActiveCell,{start:n,count:o,boundary:a}):void 0,h=L(this.initialAnchorCell)?eg(t,this.initialAnchorCell,{start:n,count:o,boundary:a}):void 0;return{outlinedSection:l,activeCell:c,anchorCell:h}}}rowOrColDiff(t){return this.tableState.table.rowOrColCount(t)-this.initialRowOrColCount[t]}handleLocationAt(t){if(this.type!=="table")return this.type==="row"&&t===this.tableState.table.firstRowIndex?"top":this.type==="col"&&t===this.tableState.table.firstColIndex?"left":this.type}handleToType(t){return t.type==="table"?"table":t.location==="top"?"row":t.location==="left"?"col":t.location}static of(t){return new Hd(t)}}function DX(i){const t=Sc(i.tableElement,i.table.firstCellLocation),e=LZ(t),{minWidth:n}=getComputedStyle(t),{lineHeight:r,paddingTop:s,paddingBottom:o}=getComputedStyle(e),l=parseFloat(n)+1,a=parseFloat(r)+parseFloat(s)+parseFloat(o)+1;return{width:l,height:a}}class Fd{constructor({event:t,tableState:e,handle:n}){C(this,"tableState");C(this,"resizeTracker");C(this,"removeEventListeners");this.tableState=e;const{width:r,height:s}=DX(e);this.resizeTracker=Hd.of({tableState:this.tableState,handle:n,position:{x:t.clientX,y:t.clientY},cellSizePixels:{row:s,col:r},dragThresholdPixels:{row:s/2,col:r/2}})}start(t){t.preventDefault();const e=this.resizeTracker.start();this.tableState.resize={},this.tableState.activeHandle=e.activeHandle,this.tableState.focusTable(),this.removeEventListeners=Cr(mv(t,this.tableState.tableElement),Et(this.tableState.tableElement,"pointermove",n=>this.drag(n)),Et(this.tableState.tableElement,"pointerup",()=>this.end()))}drag(t){t.preventDefault();const e=this.resizeTracker.drag({position:{x:t.clientX,y:t.clientY}});L(e)&&(this.resizeTable(e.operation),this.tableState.activeHandle=e.activeHandle,this.tableState.activeCell=e.activeCell,this.tableState.anchorCell=e.anchorCell,this.tableState.outlinedSection=e.outlinedSection)}end(){var e;(e=this.removeEventListeners)==null||e.call(this);const t=this.resizeTracker.end();"operation"in t&&(this.resizeTable(t.operation),this.tableState.activeCell=t.activeCell,this.tableState.anchorCell=t.anchorCell,this.tableState.outlinedSection=t.outlinedSection),this.tableState.activeHandle=t.activeHandle,this.tableState.resize=void 0}resizeTable({row:t,col:e}){if(L(t)){const{action:n,index:r,count:s}=t;n==="add"?this.tableState.table.addEmptyRowsAt({row:r,count:s}):this.tableState.table.removeRowsAt({row:r,count:s})}if(L(e)){const{action:n,index:r,count:s}=e;n==="add"?this.tableState.table.addEmptyColsAt({col:r,count:s}):this.tableState.table.removeColsAt({col:r,count:s})}}static startResize(t){new Fd(t).start(t.event)}}function YX(i,t){t.interactive&&(t.activeHandle={state:"hover",handle:i})}function WX(i){i.interactive&&(i.activeHandle=void 0)}function VX(i,t,e){if(e.interactive){if(!Bd(i)){i.preventDefault();return}t.type==="table"||t.type==="border"?Fd.startResize({event:i,handle:t,tableState:e}):t.type==="header"&&Ud.startMove({event:i,rowOrCol:t.location,index:t.index,tableState:e,onClick:()=>Nd.showMenu({handle:t,point:{x:i.clientX,y:i.clientY},tableState:e})})}}function BX(i,t){const e=i.target;if(V(e))return;const n=Vd(e);if(L(n)){YX(n,t);return}const r=Wl(e);if(L(r)){LX(nh(r),t);return}}function qX(i,t){const e=i.target;if(V(e))return;const n=Vd(e);if(L(n)){WX(t);return}const r=Wl(e);if(L(r)){MX(t);return}}function NX(i,t){const e=i.target;if(V(e))return;const n=Vd(e);if(L(n)){VX(i,n,t);return}const r=Wl(e);if(L(r)){zX(i,nh(r),t);return}i.preventDefault()}function GX(i){i.preventDefault()}var UX=ot("<!> <!> <!>",1),HX=ot('<tr class="tbl-table-row"></tr>'),FX=ot('<tbody class="tbl-table-body"></tbody>'),KX=ot("<!> <!>",1),JX=ot("<!> <!>",1),tE=ot("<!> <!> <!>",1),eE=ot("<!> <!>",1),iE=ot("<!> <!>",1),nE=ot("<!> <!>",1),rE=ot("<!> <!>",1),sE=ot("<!> <!> <!> <!> <!>",1),oE=ot("<!> <!>",1),lE=ot("<!> <!>",1),aE=ot("<!> <!> <!>",1),cE=ot("<!> <!>",1),hE=ot("<!> <!>",1),uE=ot("<!> <!> <!>",1),fE=ot("<!> <!>",1),dE=ot("<!> <!>",1),OE=ot("<!> <!>",1),pE=ot("<!> <!> <!> <!> <!> <!> <!>",1),mE=ot('<div class="tbl-table-wrapper"><table class="tbl-table" role="grid" tabindex="-1"><thead class="tbl-table-head"><!></thead><!></table> <!> <!> <!> <!></div>');function gE(i,t){Dn(t,!0);const e=Qf.of({table:()=>t.table,selection:()=>t.selection,scrollElement:()=>t.scrollElement,rootEditor:()=>t.rootEditor,menuRootElement:()=>t.menuRootElement,extensions:()=>t.extensions,markdownConfig:()=>t.markdownConfig,globalKeyBindings:()=>t.globalKeyBindings,selectionType:()=>t.selectionType,lineWrapping:()=>t.lineWrapping,onUndo:()=>t.onUndo,onRedo:()=>t.onRedo,onNavigate:()=>t.onNavigate,onDelete:()=>t.onDelete});th(()=>Cr(Et(e.document,"selectionchange",()=>MZ(e)),Et(e.document.body,"pointerdown",()=>TZ(e),{capture:!0,passive:!0}),Et(e.document.body,"pointerup",()=>AZ(e),{capture:!0,passive:!0}),Et(e.document.body,"pointerleave",()=>RZ(e),{capture:!0,passive:!0}),Et(e.document.body,"copy",x=>ZZ(x,e)),Et(e.document.body,"cut",x=>XZ(x,e)),Et(e.document.body,"paste",x=>EZ(x,e))));var n=mE(),r=Ue(n);{const x=(y,k=N1)=>{var Q=HX();Oa(Q,20,()=>e.table.colIndices,E=>E,(E,W)=>{const X=H(()=>({row:k(),col:W})),D=H(()=>({top:k()===e.table.firstRowIndex,left:W===e.table.firstColIndex})),_=H(()=>e.selection.isCell()&&Pr($(X),e.selection.cell));{let F=H(()=>{var U;return((U=e.outlinedSection)==null?void 0:U.containsOnEdge($(X)))??{top:!1,right:!1,bottom:!1,left:!1}}),G=H(()=>{var U;return(U=e.move)==null?void 0:U.cellMovement($(X))});BZ(E,{get location(){return $(X)},get alignment(){return e.table.alignments[W]},get selected(){return $(_)},get position(){return $(D)},get outline(){return $(F)},get movement(){return $(G)},get win(){return e.window},children:(U,Zt)=>{var zt=UX(),Bt=Xt(zt);Oa(Bt,16,()=>kZ($(X),$(D)),yt=>yt,(yt,Nt)=>{{let re=H(()=>e.cellHandleState($(X),Nt)),be=H(()=>L(e.resize));cg(yt,{get of(){return Nt},get state(){return $(re)},get toggle(){return $(be)}})}});var lt=et(Bt,2);eX(lt,{get hidden(){return $(_)},children:(yt,Nt)=>{var re=zd(),be=Xt(re);R5(be,()=>SZ(e.table.cellAt($(X)),e.highlighter($(X)))),I(yt,re)},$$slots:{default:!0}});var Dt=et(lt,2);{var $e=yt=>{var Nt=()=>e.table.cellAt($(X)),re=pt=>e.table.setCellAt($(X),pt),be=()=>e.selection.cellSection,tt=pt=>{e.selectionValue={cell:$(X),section:pt}};{let pt=H(()=>e.highlighter($(X)));GZ(yt,{get text(){return Nt()},set text(mt){re(mt)},get selection(){return be()},set selection(mt){tt(mt)},get selectionType(){return e.selectionType},get lineWrapping(){return e.lineWrapping},get extensions(){return e.extensions},get markdownConfig(){return e.markdownConfig},get rootEditor(){return e.rootEditor},get globalKeyBindings(){return e.globalKeyBindings},get highlighter(){return $(pt)},onbeforeinput:mt=>HZ(mt,e),ondragstart:mt=>FZ(mt),onkeydown:(mt,At)=>KZ(mt,At,e),onpaste:mt=>JZ(mt,e)})}};Ft(Dt,yt=>{$(_)&&yt($e)})}I(U,zt)},$$slots:{default:!0}})}}),I(y,Q)};var s=Ue(r),o=Ue(s);x(o,()=>e.table.headerRowIndex);var l=et(s);{var a=y=>{var k=FX();Oa(k,20,()=>e.table.dataRowIndices,Q=>Q,(Q,E)=>{x(Q,()=>E)}),I(y,k)},c=H(()=>e.table.hasDataRows());Ft(l,y=>{$(c)&&y(a)})}bc(r,y=>e.tableElement=y,()=>e==null?void 0:e.tableElement)}var h=et(r,2);{var u=x=>{const y=H(()=>e.menu.type==="row"?"row":"column");IZ(x,{get to(){return e.menuRootElement},children:(k,Q)=>{oX(k,{translate:E=>e.menu.computeTranslation(E),children:(E,W)=>{const X=H(()=>{const{addable:tt,alignable:pt,clearable:mt,duplicatable:At,moveable:Yt,removable:Wt,sortable:fe}=e.menu.capabilities;return{addable:tt,alignable:pt,clearable:mt,duplicatable:At,moveable:Yt,removable:Wt,sortable:fe}});var D=pE(),_=Xt(D);{var F=tt=>{var pt=tE(),mt=Xt(pt);Ae(mt,{onclick:()=>Re({action:"sort",direction:"ascending"},e),children:(Wt,fe)=>{var ut=KX(),gt=Xt(ut);Ze(gt,{name:"sort-ascending"});var _t=et(gt,2);Xe(_t,{children:(kt,Ut)=>{var Rt=Te();se(()=>Bi(Rt,`Sort by ${$(y)??""} (A-Z)`)),I(kt,Rt)}}),I(Wt,ut)}});var At=et(mt,2);Ae(At,{onclick:()=>Re({action:"sort",direction:"descending"},e),children:(Wt,fe)=>{var ut=JX(),gt=Xt(ut);Ze(gt,{name:"sort-descending"});var _t=et(gt,2);Xe(_t,{children:(kt,Ut)=>{var Rt=Te();se(()=>Bi(Rt,`Sort by ${$(y)??""} (Z-A)`)),I(kt,Rt)}}),I(Wt,ut)}});var Yt=et(At,2);ga(Yt),I(tt,pt)};Ft(_,tt=>{$(X).sortable&&tt(F)})}var G=et(_,2);{var U=tt=>{var pt=sE(),mt=Xt(pt);Ae(mt,{onclick:()=>Re({action:"align",alignment:"none"},e),children:(ut,gt)=>{var _t=eE(),kt=Xt(_t);Ze(kt,{name:"align-none"});var Ut=et(kt,2);Xe(Ut,{children:(Rt,si)=>{var Wi=Te("Align none");I(Rt,Wi)}}),I(ut,_t)}});var At=et(mt,2);Ae(At,{onclick:()=>Re({action:"align",alignment:"left"},e),children:(ut,gt)=>{var _t=iE(),kt=Xt(_t);Ze(kt,{name:"align-left"});var Ut=et(kt,2);Xe(Ut,{children:(Rt,si)=>{var Wi=Te("Align left");I(Rt,Wi)}}),I(ut,_t)}});var Yt=et(At,2);Ae(Yt,{onclick:()=>Re({action:"align",alignment:"center"},e),children:(ut,gt)=>{var _t=nE(),kt=Xt(_t);Ze(kt,{name:"align-center"});var Ut=et(kt,2);Xe(Ut,{children:(Rt,si)=>{var Wi=Te("Align center");I(Rt,Wi)}}),I(ut,_t)}});var Wt=et(Yt,2);Ae(Wt,{onclick:()=>Re({action:"align",alignment:"right"},e),children:(ut,gt)=>{var _t=rE(),kt=Xt(_t);Ze(kt,{name:"align-right"});var Ut=et(kt,2);Xe(Ut,{children:(Rt,si)=>{var Wi=Te("Align right");I(Rt,Wi)}}),I(ut,_t)}});var fe=et(Wt,2);ga(fe),I(tt,pt)};Ft(G,tt=>{$(X).alignable&&tt(U)})}var Zt=et(G,2);{var zt=tt=>{var pt=aE(),mt=Xt(pt);Ae(mt,{onclick:()=>Re({action:"add",direction:"before"},e),children:(Wt,fe)=>{var ut=oE(),gt=Xt(ut);Ze(gt,{name:"add-before"});var _t=et(gt,2);Xe(_t,{children:(kt,Ut)=>{var Rt=Te();se(()=>Bi(Rt,`Add ${$(y)??""} ${$(y)==="row"?"above":"before"}`)),I(kt,Rt)}}),I(Wt,ut)}});var At=et(mt,2);Ae(At,{onclick:()=>Re({action:"add",direction:"after"},e),children:(Wt,fe)=>{var ut=lE(),gt=Xt(ut);Ze(gt,{name:"add-after"});var _t=et(gt,2);Xe(_t,{children:(kt,Ut)=>{var Rt=Te();se(()=>Bi(Rt,`Add ${$(y)??""} ${$(y)==="row"?"below":"after"}`)),I(kt,Rt)}}),I(Wt,ut)}});var Yt=et(At,2);ga(Yt),I(tt,pt)};Ft(Zt,tt=>{$(X).addable&&tt(zt)})}var Bt=et(Zt,2);{var lt=tt=>{var pt=uE(),mt=Xt(pt);{var At=ut=>{Ae(ut,{onclick:()=>Re({action:"move",direction:"backward"},e),children:(gt,_t)=>{var kt=cE(),Ut=Xt(kt);{let si=H(()=>`move-${$(y)==="row"?"up":"left"}`);Ze(Ut,{get name(){return $(si)}})}var Rt=et(Ut,2);Xe(Rt,{children:(si,Wi)=>{var So=Te();se(()=>Bi(So,`Move ${$(y)??""} ${$(y)==="row"?"up":"left"}`)),I(si,So)}}),I(gt,kt)}})};Ft(mt,ut=>{($(X).moveable==="backward"||$(X).moveable===!0)&&ut(At)})}var Yt=et(mt,2);{var Wt=ut=>{Ae(ut,{onclick:()=>Re({action:"move",direction:"forward"},e),children:(gt,_t)=>{var kt=hE(),Ut=Xt(kt);{let si=H(()=>`move-${$(y)==="row"?"down":"right"}`);Ze(Ut,{get name(){return $(si)}})}var Rt=et(Ut,2);Xe(Rt,{children:(si,Wi)=>{var So=Te();se(()=>Bi(So,`Move ${$(y)??""} ${$(y)==="row"?"down":"right"}`)),I(si,So)}}),I(gt,kt)}})};Ft(Yt,ut=>{($(X).moveable==="forward"||$(X).moveable===!0)&&ut(Wt)})}var fe=et(Yt,2);ga(fe),I(tt,pt)};Ft(Bt,tt=>{$(X).moveable!==!1&&tt(lt)})}var Dt=et(Bt,2);{var $e=tt=>{Ae(tt,{onclick:()=>Re({action:"duplicate"},e),children:(pt,mt)=>{var At=fE(),Yt=Xt(At);Ze(Yt,{name:"duplicate"});var Wt=et(Yt,2);Xe(Wt,{children:(fe,ut)=>{var gt=Te();se(()=>Bi(gt,`Duplicate ${$(y)??""}`)),I(fe,gt)}}),I(pt,At)}})};Ft(Dt,tt=>{$(X).duplicatable&&tt($e)})}var yt=et(Dt,2);{var Nt=tt=>{Ae(tt,{onclick:()=>Re({action:"clear"},e),children:(pt,mt)=>{var At=dE(),Yt=Xt(At);Ze(Yt,{name:"clear"});var Wt=et(Yt,2);Xe(Wt,{children:(fe,ut)=>{var gt=Te();se(()=>Bi(gt,`Clear ${$(y)??""}`)),I(fe,gt)}}),I(pt,At)}})};Ft(yt,tt=>{$(X).clearable&&tt(Nt)})}var re=et(yt,2);{var be=tt=>{Ae(tt,{onclick:()=>Re({action:"remove"},e),children:(pt,mt)=>{var At=OE(),Yt=Xt(At);Ze(Yt,{name:"remove"});var Wt=et(Yt,2);Xe(Wt,{children:(fe,ut)=>{var gt=Te();se(()=>Bi(gt,`Delete ${$(y)??""}`)),I(fe,gt)}}),I(pt,At)}})};Ft(re,tt=>{$(X).removable&&tt(be)})}I(E,D)},$$slots:{default:!0}})},$$slots:{default:!0}})},f=H(()=>L(e.menu));Ft(h,x=>{$(f)&&x(u)})}var d=et(h,2);Oa(d,16,()=>yZ,x=>x,(x,y)=>{{let k=H(()=>{var Q;return kf((Q=e.activeHandle)==null?void 0:Q.handle,y)?e.activeHandle.state:void 0});cg(x,{get of(){return y},get state(){return $(k)}})}});var O=et(d,2);{var p=x=>{DZ(x)},m=H(()=>!e.interactive&&V(e.outline));Ft(O,x=>{$(m)&&x(p)})}var g=et(O,2);{var b=x=>{xX(x)},S=H(()=>e.selection.isAll());Ft(g,x=>{$(S)&&x(b)})}bc(n,x=>e.wrapperElement=x,()=>e==null?void 0:e.wrapperElement),se(x=>$t(n,"data-select-all",x),[()=>gr(e.selection.isAll())]),Mo("mouseover",n,x=>BX(x,e)),Mo("mouseout",n,x=>qX(x,e)),Mo("pointerdown",n,x=>NX(x,e)),fa("dragover",n,x=>GX(x)),Mo("keydown",r,x=>EX(x,e)),fa("copy",r,x=>RX(x,e)),fa("cut",r,x=>ZX(x,e)),fa("paste",r,x=>XX(x,e)),I(i,n),Yn()}MS(["mouseover","mouseout","pointerdown","keydown"]);class Kd extends Ln{constructor(e,n){super();C(this,"tableDescription");C(this,"widgetElement");C(this,"height");C(this,"destroyWidgetElement");this.tableDescription=e;const r=$E(n);if(L(r)){const{widgetElement:s,destroyWidgetElement:o}=this.create(r);this.widgetElement=s,this.destroyWidgetElement=o,this.height=D5(r,s)}else this.widgetElement=void 0,this.destroyWidgetElement=void 0,this.height=Nm}get estimatedHeight(){return this.height}coordsAt(e,n,r){const s=this.tableDescription.source.closestCell(n),o=Sc(e,s);if(V(o))return null;const l=o.getBoundingClientRect();return{top:l.top,right:l.right,bottom:l.bottom,left:l.left}}toDOM(e){if(L(this.widgetElement))return this.widgetElement;const{widgetElement:n,destroyWidgetElement:r}=this.create(e);return this.widgetElement=n,this.destroyWidgetElement=r,e.requestMeasure({read:()=>{this.height=n.getBoundingClientRect().height}}),n}destroy(e){var n;(n=this.destroyWidgetElement)==null||n.call(this),this.destroyWidgetElement=void 0,this.widgetElement=void 0,this.height=Nm}create(e){const n=bl(e.dom).createElement("div");n.className="tbl-table-widget",n.tabIndex=-1,n.addEventListener("pointerdown",O=>{(O==null?void 0:O.target)===n&&O.preventDefault()});const r=this.tableDescription,s=p5(()=>{Kc(()=>{const O=!r.table.text.eq(r.editorTableText),p=!ih(r.selection.value,r.editorSelectionValue);if(!O&&!p)return;const m=O?r.source.applyContent(r.table.text,r.editorTableText):void 0,g=O?new ro(m,r.table.colCount):r.source;let b;if(r.selection.isCell()){const{from:x}=g.cellSpan(r.selection.cell);b={anchor:r.from+x+r.selection.cellSection.anchor,head:r.from+x+r.selection.cellSection.head}}else r.selection.isAll()?b={anchor:r.from,head:r.to}:r.selection.isHidden()&&(b={anchor:r.from+1,head:r.from+1});const S=O?{from:r.from,to:r.to,insert:m}:void 0;r.markSynchronized(),e.dispatch({annotations:Gr("table.edit"),changes:S,selection:b})})}),{extensions:o,markdownConfig:l,globalKeyBindings:a,selectionType:c,lineWrapping:h}=wv(e.state),u=zS(gE,{target:n,props:{table:r.table,selection:r.selection,scrollElement:n,rootEditor:e,extensions:o,markdownConfig:l,globalKeyBindings:a,selectionType:c,lineWrapping:h,menuRootElement:Ck(e,nv).dom,onUndo:()=>id(e),onRedo:()=>Ka(e),onNavigate:O=>{const p=O==="before"?r.from-1:r.to+1;p<0||p>e.state.doc.length||(e.dispatch({annotations:Gr("table.navigate"),selection:{anchor:p}}),e.focus())},onDelete:()=>{e.dispatch({annotations:Gr("table.delete"),changes:{from:r.from,to:r.to},selection:e.state.selection}),e.focus()}}}),f=()=>{_S(u)},d=Y5(n,({height:O})=>{this.height=O});return{widgetElement:n,destroyWidgetElement:Cr(s,f,d)}}static of(e,n){return new Kd(e,n)}}function bE(i,t){return{widget:Kd.of(i,t),block:!0,inclusive:!0}}function wE(i,t){return K.replace(bE(i,t))}function SE(i,t){const e=new qs;for(const n of i)e.add(n.from,n.to,wE(n,t));return e.finish()}function vE(i){return gv(i)}function xE(i,t){return gv(i,t)}function gv(i,t=[]){const e=[];return kA(St(i),n=>{L1(n)&&e.push({from:i.doc.lineAt(n.from).from,to:i.doc.lineAt(n.to).to})}),{spans:e,formatting:[],complete:Gk(i)}}const yE={create(i){return ba(i)},update(i,t){if(eZ(t))return ba(t.state);if(!t.docChanged&&V(t.selection)&&i.complete)return i;const{tables:e,formatting:n,decorations:r}=i;if(!t.docChanged&&i.complete)return{tables:fg(e,t),formatting:n,decorations:r.map(t.changes),complete:!0};if(tZ(t)||kE(t,e))return ba(t.state);const s=fg(e,t).map(c=>c.span),{complete:o,spans:l,formatting:a}=xE(t.state,s);return mn(s,l,aR)?{complete:o,tables:e,formatting:a,decorations:r.map(t.changes)}:ba(t.state)},provide(i){return z.decorations.from(i,t=>t.decorations)}},bv=mi.define(yE);function ba(i){const{spans:t,formatting:e,complete:n}=vE(i),{doc:r,selection:s}=i,o=t.map(l=>xf.of({span:l,doc:r,selection:s}));return{complete:n,tables:o,formatting:e,decorations:SE(o,i)}}function kE(i,t){return!GS(i)&&t.some(e=>i.changes.touchesRange(e.from,e.to)!==!1)}function fg(i,t){return PA(i,e=>e.applyTransaction(t))}const QE={create(){return{view:void 0}},update(i){return i}},Jd=mi.define(QE);function wv(i){return i.facet(rf)}function uo(i){return i.field(bv)}function $E(i){return i.field(Jd).view}function CE(i){const{handlePosition:t,selectionType:e,lineWrapping:n}=wv(i);return{...Uc(window)?{"data-tbl-hoverable":""}:{},"data-tbl-theme-mode":i.facet(z.darkTheme)?"dark":"light","data-tbl-handle-position":t,"data-tbl-selection-type":e,"data-tbl-line-wrapping":n}}const PE=["undo","redo","select.undo","select.redo"];function TE(i){return PE.some(t=>i.isUserEvent(t))}function AE(i){return Sv(i,"select.search")}function RE(i){return Sv(i,"select")}function ZE(i){return i.isUserEvent("delete.forward")}function XE(i){return i.isUserEvent("delete.backward")}function Sv(i,t){return i.annotation(Lt.userEvent)===t}const EE=({state:i,view:t,transactions:e})=>{t.hasFocus||uo(i).tables.some(n=>n.containsSelection())||e.some(n=>TE(n)||AE(n)&&!dv(t))&&t.focus()},vv=Pt.define(),LE=new Map(NS.map(i=>[i,vv.of(i)]));function xv(i){return LE.get(i)}const ME=(i,t)=>!t||!uo(i).tables.some(e=>e.containsSelection())?null:xv("table.focus"),zE=i=>{const{selection:t,startState:e,docChanged:n}=i;if(V(t)||n||!RE(i)||!hc(t)||!hc(e.selection))return i;const r=e.selection.main,s=t.main;for(const o of uo(e).tables){const l=o.from===s.head,a=o.to===s.head,c=o.from===r.head+1&&o.to===s.head-1,h=o.from===s.head+1&&o.to===r.head-1;let u;if(l?u=o.source.cellSpan(o.table.firstCellLocation).from:c?u=o.source.cellSpan(o.table.firstCellLocation).to:(a||h)&&(u=o.source.cellSpan(o.table.lastCellLocation).to),L(u))return[i,{annotation:Gr("table.navigate"),selection:oA({pos:o.from+u})}]}return i},_E=i=>{const{selection:t,startState:e}=i;if(V(t)||!hc(t))return i;const n=e.selection.main;if(ZE(i)){for(const r of uo(e).tables)if(n.head===r.from-1){const s=r.source.cellSpan(r.table.firstCellLocation).from;return[{selection:{anchor:r.from+s,head:r.from+s}}]}return i}else if(XE(i)){for(const r of uo(e).tables)if(n.head===r.to+1){const s=r.source.cellSpan(r.table.lastCellLocation).to;return[{selection:{anchor:r.from+s,head:r.from+s}}]}return i}else return i};function IE(i,{anchor:t,head:e,goalColumn:n,bidiLevel:r}={}){return P.range(t??i.anchor,e??i.head,n??i.goalColumn,r??i.bidiLevel??void 0)}const jE=i=>{const{selection:t,startState:e,docChanged:n}=i;if(V(t)||n||hc(t))return i;const r=t.ranges.map(s=>{if(s.empty)return s;const o=uo(e).tables,l=dg(s.anchor,o,e.doc.length),a=dg(s.head,o,e.doc.length);return L(l)||L(a)?IE(s,{anchor:l,head:a}):s});return mn(t.ranges,r,(s,o)=>s===o)?i:[i,{annotations:Gr("table.select"),selection:P.create(r,t.mainIndex)}]};function dg(i,t,e){for(const n of t){const r=n.from,s=n.to,o=n.from+1,l=n.to-1;if(i===r||i===o)return Math.max(0,r-1);if(i===s||i===l)return Math.min(e,s+1)}}const DE={"& .cm-tooltip.cm-tooltip-autocomplete:has(.cm-completionIcon-table)":{border:"1px solid var(--tbl-theme-menu-border-color)","box-shadow":"2px 2px 0 0 rgb(0 0 0 / 10%)","font-family":"var(--tbl-style-menu-font-family)","font-size":"var(--tbl-style-menu-font-size)"},"& .cm-tooltip.cm-tooltip-autocomplete > ul:has(.cm-completionIcon-table)":{"min-width":"auto",display:"flex","flex-direction":"column","justify-content":"center",padding:"0.25em 0","line-height":1,"font-family":"var(--tbl-style-menu-font-family)","font-size":"var(--tbl-style-menu-font-size)",background:"var(--tbl-theme-menu-background)"},"& .cm-tooltip.cm-tooltip-autocomplete ul li[aria-selected]:has(.cm-completionIcon-table)":{color:"var(--tbl-theme-menu-hover-text-color)","&::before":{background:"var(--tbl-theme-menu-hover-background)"}},"& .cm-tooltip.cm-tooltip-autocomplete ul li:not([aria-selected]):has(.cm-completionIcon-table)":{color:"var(--tbl-theme-menu-text-color)"},"& .cm-tooltip.cm-tooltip-autocomplete ul li:not([aria-selected]):has(.cm-completionIcon-table), & .cm-tooltip.cm-tooltip-autocomplete ul li[aria-selected]:has(.cm-completionIcon-table)":{position:"relative",padding:"0.5em 0.75em",background:"var(--tbl-theme-menu-background)",display:"flex",gap:"0.75em","align-items":"center","font-family":"var(--tbl-style-menu-font-family)","font-size":"var(--tbl-style-menu-font-size)","line-height":1,"&::before":{position:"absolute",height:"100%",width:"calc(100% - 0.5em)",left:"0.25em",top:0,content:'""',"pointer-events":"none"}},"& .cm-completionIcon.cm-completionIcon-table":{opacity:1,"mask-image":`url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' height='14' width='12.25' viewBox='0 0 448 512'%3E%3C!--!Font Awesome Free v7.1.0 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2026 Fonticons, Inc.--%3E%3Cpath d='M384 96l-128 0 0 128 128 0 0-128zm64 128l0 192c0 35.3-28.7 64-64 64L64 480c-35.3 0-64-28.7-64-64L0 96C0 60.7 28.7 32 64 32l320 0c35.3 0 64 28.7 64 64l0 128zM64 288l0 128 128 0 0-128-128 0zm128-64l0-128-128 0 0 128 128 0zm64 64l0 128 128 0 0-128-128 0z'/%3E%3C/svg%3E")`,"mask-position":"center","mask-repeat":"no-repeat",padding:0,background:"currentColor",position:"relative",width:"1em",height:"1em","font-family":"var(--tbl-style-menu-font-family)","font-size":"var(--tbl-style-menu-font-size)","line-height":1},"& :has(.cm-completionIcon.cm-completionIcon-table) .cm-completionLabel":{position:"relative"}},YE={'&[data-tbl-handle-position="inside"] .tbl-table-widget':{"padding-left":"6px","margin-left":0},".tbl-table-widget":{contain:"paint","padding-top":"16px","padding-right":"16px","padding-bottom":"16px","padding-left":"16px","margin-left":"-10px","overflow-x":"auto","overflow-y":"hidden","&, &::before, &::after, & *, & *::before, & *::after":{"box-sizing":"border-box"}},"&.cm-editor .cm-content div.tbl-table-widget::selection, & .cm-content div.tbl-table-widget ::selection, & .cm-content div.tbl-table-widget:focus::selection, & .cm-content div.tbl-table-widget :focus::selection":{"background-color":"transparent !important","caret-color":"transparent !important"}},WE={".cm-tooltip.tbl-menu-tooltip":{border:"none","user-select":"none","&, &::before, &::after, & *, & *::before, & *::after":{"box-sizing":"border-box"}}},VE={".tbl-blocking-overlay":{position:"absolute",top:0,left:0,"z-index":900,"background-color":"transparent",width:"100%",height:"100%"}},BE={"& .cm-content div.tbl-table-widget .tbl-cell-editor ::selection, & .cm-content div.tbl-table-widget .tbl-cell-editor :focus::selection":{"background-color":"Highlight !important","caret-color":"initial !important"},"&[data-tbl-selection-type='codemirror'] .tbl-cell-editor .cm-editor .cm-content":{"caret-color":"transparent !important"},"&[data-tbl-selection-type='codemirror'] .tbl-cell-editor .cm-editor .cm-content ::selection, &[data-tbl-selection-type='codemirror'] .tbl-cell-editor .cm-editor .cm-content :focus::selection":{"background-color":"transparent !important","caret-color":"transparent !important"},"&[data-tbl-line-wrapping='wrap'] .tbl-cell-editor .cm-editor .cm-content":{"word-break":"normal","overflow-wrap":"break-word"},".tbl-cell-editor":{height:"100%"},".tbl-cell-editor .cm-editor":{margin:0,padding:0,outline:"none",height:"100%",background:"unset",color:"var(--tbl-theme-text-color)"},".tbl-cell-editor .cm-editor .cm-scroller":{margin:0,padding:0,overflow:"hidden","line-height":1.5,"font-family":"var(--tbl-style-font-family)","font-size":"var(--tbl-style-font-size)",color:"var(--tbl-theme-text-color)"},".tbl-cell-editor .cm-editor .cm-content":{margin:0,padding:"7px 9px","line-height":1.5,"font-family":"var(--tbl-style-font-family)","font-size":"var(--tbl-style-font-size)",color:"var(--tbl-theme-text-color)"},".tbl-cell-editor .cm-editor .cm-line":{margin:0,padding:"0 1px","line-height":1.5,"touch-action":"none","font-family":"var(--tbl-style-font-family)","font-size":"var(--tbl-style-font-size)",color:"var(--tbl-theme-text-color)"}},qE={".tbl-cell":{"box-sizing":"content-box",position:"relative","vertical-align":"top","background-color":"var(--tbl-row-background)",padding:0,"font-family":"var(--tbl-style-font-family)","font-size":"var(--tbl-style-font-size)","min-width":"calc(4ch + 20px)",height:"inherit","user-select":"none",border:"none","scroll-margin-right":"1px","scroll-margin-left":"1px","&:first-child":{"scroll-margin-left":"16px"},"&:last-child":{"scroll-margin-right":"16px"},'&[align="left"]':{"text-align":"left"},'&[align="center"]':{"text-align":"center"},'&[align="right"]':{"text-align":"right"},'&[data-border~="top"]':{"border-top":"1px solid var(--tbl-theme-border-color)"},'&[data-border~="right"]':{"border-right":"1px solid var(--tbl-theme-border-color)"},'&[data-border~="bottom"]':{"border-bottom":"1px solid var(--tbl-theme-border-color)"},'&[data-border~="left"]':{"border-left":"1px solid var(--tbl-theme-border-color)"},'&[data-state="moving"]':{"z-index":200,"background-color":"color-mix(in srgb, var(--tbl-row-background), transparent 15%)"},'&[data-state="shiftable"]':{transform:"translate3d(0, 0, 0)",transition:"transform 150ms ease"},"&[data-outline]":{"&::after":{display:"block",position:"absolute",top:"-1px",left:"-1px",border:"none",width:"calc(100% + 2px)",height:"calc(100% + 2px)","pointer-events":"none",content:'""'},'&[data-outline~="top"]::after':{"border-top":"2px solid var(--tbl-theme-outline-color)"},'&[data-outline~="right"]::after':{"border-right":"2px solid var(--tbl-theme-outline-color)"},'&[data-outline~="bottom"]::after':{"border-bottom":"2px solid var(--tbl-theme-outline-color)"},'&[data-outline~="left"]::after':{"border-left":"2px solid var(--tbl-theme-outline-color)"}}},".tbl-header-cell:not([align])":{"text-align":"var(--tbl-style-default-header-alignment)"}},NE={'&[data-tbl-line-wrapping="wrap"] .tbl-cell-view':{"word-break":"normal","overflow-wrap":"break-word"},'&[data-tbl-line-wrapping="nowrap"] .tbl-cell-view':{"white-space":"pre"},".tbl-cell-view":{margin:0,outline:"none",padding:"7px 10px",height:"100%","line-height":1.5,"white-space-collapse":"break-spaces","font-family":"var(--tbl-style-font-family)","font-size":"var(--tbl-style-font-size)",color:"var(--tbl-theme-text-color)","&[data-hidden]":{display:"none"}},".tbl-cell-view [data-br]":{"white-space":"pre"}},GE={".tbl-handle":{display:"flex",position:"absolute","justify-content":"center","align-items":"center","z-index":200,transition:"opacity 150ms ease 50ms","touch-action":"none"},".tbl-handle[data-hover], .tbl-handle[data-active]":{"--tbl-handle-opacity":1},'&:not([data-tbl-hoverable]) .tbl-handle[data-type="border"], &:not([data-tbl-hoverable]) .tbl-handle[data-type="table"]':{display:"none"},'.tbl-handle[data-type="border"]':{"background-color":"var(--tbl-theme-border-hover-color)"},'.tbl-handle[data-type="border"][data-active]':{"background-color":"var(--tbl-theme-border-active-color)"},'.tbl-handle[data-type="border"][data-toggle]':{transition:"none"},'.tbl-handle[data-type="border"][data-location="top"]':{top:"-1px",left:"-1px",width:"calc(100% + 2px)",height:"2px"},'.tbl-handle[data-type="border"][data-location="left"]':{top:"-1px",left:"-1px",width:"2px",height:"calc(100% + 2px)"},'.tbl-handle[data-type="border"][data-location="col"]':{top:"-1px",right:"-2px",width:"3px",height:"calc(100% + 2px)"},'.tbl-handle[data-type="border"][data-location="row"]':{bottom:"-2px",left:"-1px",width:"calc(100% + 2px)",height:"3px"},'.tbl-handle[data-type="table"]':{"box-sizing":"content-box",color:"var(--tbl-theme-border-hover-color)","background-color":"color-mix(in srgb, var(--tbl-theme-border-color), var(--tbl-theme-header-row-background) 80%)"},'.tbl-handle[data-type="table"][data-location="right"]':{top:0,left:"100%",width:"15px",height:"calc(100% - 2px)",border:"1px solid var(--tbl-theme-border-color)","border-left":"none","&::before":{position:"absolute",top:"-1px",left:"-2px",width:"2px",height:"calc(100% + 2px)",content:'""'},"&::after":{position:"absolute","z-index":366,top:"-1px",left:0,content:'""',width:"calc(100% + 1px)",height:"calc(100% + 2px)","background-color":"var(--tbl-overlay)"}},'.tbl-handle[data-type="table"][data-location="bottom-right"]':{left:"calc(100% - 1px)",top:"calc(100% - 1px)","z-index":250,width:"15px",height:"15px",border:"1px solid var(--tbl-theme-border-color)","border-top-style":"dashed","border-left-style":"dashed","&::after":{position:"absolute","z-index":366,top:"-1px",left:"-1px",content:'""',width:"calc(100% + 2px)",height:"calc(100% + 2px)","background-color":"var(--tbl-overlay)"}},'.tbl-handle[data-type="table"][data-location="bottom"]':{top:"100%",left:"0",width:"calc(100% - 2px)",height:"15px",border:"1px solid var(--tbl-theme-border-color)","border-top":"none","&::before":{position:"absolute",top:"-2px",left:"-1px",width:"calc(100% + 2px)",height:"2px",content:'""'},"&::after":{position:"absolute","z-index":366,top:0,left:"-1px",content:'""',width:"calc(100% + 2px)",height:"calc(100% + 1px)","background-color":"var(--tbl-overlay)"}},'.tbl-handle[data-type="table"][data-location="bottom-right"][data-hover] ~ .tbl-handle[data-type="table"][data-location="right"], .tbl-handle[data-type="table"][data-location="bottom-right"][data-active] ~ .tbl-handle[data-type="table"][data-location="right"], .tbl-handle[data-type="table"][data-location="bottom-right"][data-hover] ~ .tbl-handle[data-type="table"][data-location="bottom"], .tbl-handle[data-type="table"][data-location="bottom-right"][data-active] ~ .tbl-handle[data-type="table"][data-location="bottom"]':{"--tbl-handle-opacity":1},'.tbl-handle[data-type="table"][data-location="bottom-right"][data-hover] ~ .tbl-handle[data-type="table"][data-location="right"], .tbl-handle[data-type="table"][data-location="bottom-right"][data-active] ~ .tbl-handle[data-type="table"][data-location="right"]':{"border-bottom":"none"},'.tbl-handle[data-type="table"][data-location="bottom-right"][data-hover] ~ .tbl-handle[data-type="table"][data-location="bottom"], .tbl-handle[data-type="table"][data-location="bottom-right"][data-active] ~ .tbl-handle[data-type="table"][data-location="bottom"]':{"border-right":"none"},'.tbl-handle[data-type="table"][data-active], .tbl-handle[data-type="table"][data-location="bottom-right"][data-active] ~ .tbl-handle[data-type="table"][data-location="right"], .tbl-handle[data-type="table"][data-location="bottom-right"][data-active] ~ .tbl-handle[data-type="table"][data-location="bottom"]':{"background-color":"color-mix(in srgb, var(--tbl-theme-border-color), var(--tbl-theme-header-row-background) 80%)",color:"var(--tbl-theme-border-active-color)"},'&[data-tbl-handle-position="outside"] .tbl-handle[data-type="header"]':{"box-sizing":"content-box",transition:"none","z-index":300,color:"var(--tbl-theme-border-hover-color)",border:"1px solid transparent","&:hover":{"border-color":"var(--tbl-theme-border-color)","background-color":"color-mix(in srgb, var(--tbl-theme-border-color), var(--tbl-theme-header-row-background) 80%)"},"&[data-active]":{"background-color":"var(--tbl-theme-outline-color)","border-color":"var(--tbl-theme-outline-color)",color:"#ffffff"}},'&[data-tbl-handle-position="outside"] .tbl-handle[data-type="header"][data-location="row"]':{top:"-1px",left:"-17px",width:"15px",height:"100%","border-right":"none"},'&[data-tbl-handle-position="outside"] .tbl-handle[data-type="header"][data-location="col"]':{top:"-17px",left:"-1px",width:"100%",height:"15px","border-bottom":"none","&:hover::after":{position:"absolute","z-index":366,top:"-1px",left:"-1px",content:'""',width:"calc(100% + 2px)",height:"calc(100% + 1px)","background-color":"var(--tbl-overlay)"}},'&[data-tbl-handle-position="inside"] .tbl-handle[data-type="header"]':{transition:"none","z-index":300,color:"var(--tbl-theme-border-hover-color)","&:hover":{color:"var(--tbl-theme-border-active-color)"},"&[data-active]":{color:"var(--tbl-theme-outline-color)"}},'&[data-tbl-handle-position="inside"] .tbl-handle[data-type="header"][data-location="row"]':{top:"calc(50% - 13px)",left:"-1px",width:"3px",height:"26px","border-top":"4px solid var(--tbl-row-background)","border-bottom":"4px solid var(--tbl-row-background)","background-color":"var(--tbl-row-background)","&:hover::after, &[data-active]::after":{position:"absolute",top:"-6px",left:0,"box-sizing":"content-box","border-top":"2px solid transparent","border-bottom":"2px solid transparent",width:"calc(100% + 6px)",height:"calc(100% + 8px)",content:'""'}},'&[data-tbl-handle-position="inside"] .tbl-handle[data-type="header"][data-location="col"]':{top:"-1px",left:"calc(50% - 11.5px)",width:"23px",height:"3px","border-right":"4px solid var(--tbl-row-background)","border-left":"4px solid var(--tbl-row-background)","background-color":"var(--tbl-row-background)","&:hover::after, &[data-active]::after":{position:"absolute",top:0,left:"-6px","box-sizing":"content-box","border-right":"2px solid transparent","border-left":"2px solid transparent",width:"calc(100% + 8px)",height:"calc(100% + 6px)",content:'""'}},".tbl-handle-grip":{"pointer-events":"none","z-index":333}},UE={".tbl-menu-item-icon":{"z-index":200,width:"1em",height:"1em","pointer-events":"none","font-size":"var(--tbl-style-menu-font-size)"}},HE={".tbl-menu-item-text":{"z-index":200,"pointer-events":"none","user-select":"none","font-size":"var(--tbl-style-menu-font-size)"}},FE={".tbl-menu-item":{display:"flex",position:"relative","align-items":"center",gap:"0.75em",padding:"0.5em 0.75em",color:"var(--tbl-theme-menu-text-color)","user-select":"none","line-height":1,"font-size":"var(--tbl-style-menu-font-size)","&:active":{cursor:"pointer",color:"var(--tbl-theme-menu-hover-text-color)","&::after":{"background-color":"var(--tbl-theme-menu-hover-background)"}},"&::after":{position:"absolute",left:"0.25em",width:"calc(100% - 0.5em)",height:"100%",content:'""'}},"&[data-tbl-hoverable] .tbl-menu-item:hover":{cursor:"pointer",color:"var(--tbl-theme-menu-hover-text-color)","&::after":{"background-color":"var(--tbl-theme-menu-hover-background)"}}},KE={".tbl-menu-separator":{margin:"0.25em 0.5em","background-color":"var(--tbl-theme-menu-border-color)",height:"1px","font-size":"var(--tbl-style-menu-font-size)"}},JE={".tbl-menu":{position:"absolute",top:0,left:0,"z-index":900,"box-shadow":"2px 2px 0 0 rgb(0 0 0 / 10%)",border:"1px solid var(--tbl-theme-menu-border-color)","background-color":"var(--tbl-theme-menu-background)",padding:"0.25em 0",width:"max-content","font-family":"var(--tbl-style-menu-font-family)","font-size":"var(--tbl-style-menu-font-size)"}},tL={".tbl-select-all-overlay":{position:"absolute",top:0,left:0,"z-index":900,"background-color":"var(--tbl-overlay)",width:"100%",height:"100%","pointer-events":"none"}},eL={"& .tbl-table-wrapper[data-select-all]":{"--tbl-select-all-overlay":"var(--tbl-theme-select-all-blur-overlay)"},"&.cm-focused .tbl-table-wrapper[data-select-all]":{"--tbl-select-all-overlay":"var(--tbl-theme-select-all-focus-overlay)"},".tbl-table-wrapper":{"--tbl-overlay":"var(--tbl-select-all-overlay, transparent)",position:"relative",width:"fit-content","white-space-collapse":"collapse","touch-action":"none"},".tbl-table":{"border-collapse":"separate","border-spacing":0,overflow:"visible","touch-action":"none","&:focus-visible":{outline:"none"}},".tbl-table-head, .tbl-table-body":{height:"100%"},".tbl-table-row":{height:0},"@supports (-moz-appearance: none) /* TableTheme */":{".tbl-table-row":{height:"fit-content"}},".tbl-table-head .tbl-table-row":{"--tbl-row-background":"var(--tbl-theme-header-row-background)"},".tbl-table-body .tbl-table-row:nth-child(2n + 1)":{"--tbl-row-background":"var(--tbl-theme-even-row-background)"},".tbl-table-body .tbl-table-row:nth-child(2n)":{"--tbl-row-background":"var(--tbl-theme-odd-row-background)"}},iL={...DE,...WE,...YE,...eL,...VE,...qE,...BE,...NE,...GE,...JE,...FE,...UE,...HE,...KE,...tL},nL=i=>{var e;const t=(e=i.effects.find(n=>n.is(vv)))==null?void 0:e.value;return L(t)?{annotations:Gr(t)}:null},rL=i=>{const t=i.annotation(jd);return L(t)?[xv(H5(t))]:[]};class tO{static of(t){return t.state.field(Jd).view=t,new tO}constructor(){}}function sL(i){return[rf.of(i),bv,Jd,Fe.define(t=>tO.of(t)),z.editorAttributes.compute([rf,z.darkTheme],CE),z.baseTheme(iL),z.theme("light"in i.theme?{':where(:root:has(&[data-tbl-theme-mode="light"]))':i.theme.light.props,':where(:root:has(&[data-tbl-theme-mode="dark"]))':i.theme.dark.props}:{":where(:root:has(&))":i.theme.props}),z.theme({":where(:root:has(&))":i.style.props}),v0.of(rL),n0.of(nv),J.transactionExtender.of(nL),J.transactionFilter.of(_E),J.transactionFilter.of(zE),J.transactionFilter.of(jE),z.updateListener.of(EE),z.clipboardInputFilter.of(sR),z.focusChangeEffect.of(ME)]}function oL(i){return sL(Z1(i))}const lL=new Set(["about:","blob:","chrome-extension:","chrome:","data:","devtools:","file:","filesystem:","javascript:","view-source:"]);function yv(i,t){try{const e=new URL(t),n=new URL(i,e);return n.protocol==="http:"||n.protocol==="https:"?{kind:"web",url:n.href}:lL.has(n.protocol)?{kind:"browser-local",url:n.href}:{kind:"application",url:n.href}}catch{return{kind:"invalid"}}}const kv="cm-md-mark",Qv="cm-md-inline-code",$f="cm-md-list-item",Cf="cm-md-list-bullet",$v="cm-md-blockquote-line",Cv="cm-md-fenced-line",Pv="cm-md-hr",Tv="cm-md-task-checkbox",Av="cm-md-heading-1",Rv="cm-md-heading-2",eO="cm-md-link",Zv="cm-md-tag",Xv="cm-md-list-indent-source",Og="1.2em",aL="0.62em",Ro=K.replace({}),qn=K.mark({class:kv}),cL=K.mark({class:Xv}),hL=K.mark({class:Qv}),uL=K.line({class:Cf}),fL=K.line({class:$v}),dL=K.line({class:Cv}),OL=K.line({class:Av}),pL=K.line({class:Rv}),mL=K.mark({class:Zv});class gL extends Ln{toDOM(){const t=document.createElement("hr");return t.className=Pv,t}eq(t){return!0}ignoreEvent(){return!0}}const bL=K.replace({widget:new gL});class wL extends Ln{constructor(e,n,r){super();C(this,"checked");C(this,"from");C(this,"to");this.checked=e,this.from=n,this.to=r}eq(e){return e.checked===this.checked&&e.from===this.from&&e.to===this.to}toDOM(e){const n=document.createElement("input");return n.type="checkbox",n.checked=this.checked,n.className=Tv,n.tabIndex=-1,n.addEventListener("mousedown",r=>{r.preventDefault()}),n.addEventListener("change",()=>{const r=this.checked?"[ ]":"[x]";e.dispatch({changes:{from:this.from,to:this.to,insert:r}})}),n}ignoreEvent(e){return e.type!=="click"&&e.type!=="change"&&e.type!=="mousedown"}}const SL=new Set(["EmphasisMark","LinkMark","URL"]),vL=new Set(["HeaderMark","QuoteMark"]),pg=/(^|\s)(#[\p{L}\p{N}_/-]+)/gu,xL=/[/.,;:!?]+$/u,yL=new RegExp("\\p{L}","u"),kL=new Set(["InlineCode","FencedCode","URL","Link"]);function QL(i,t,e,n,r,s){return vL.has(i)?{kind:"block",contextFrom:r,contextTo:s}:i==="CodeMark"?t==="InlineCode"&&e!==null&&n!==null?{kind:"inline",contextFrom:e,contextTo:n}:null:SL.has(i)?e===null||n===null?null:{kind:"inline",contextFrom:e,contextTo:n}:null}function gn(i,t,e,n){return i<=n&&t>=e}function $L(i,t,e,n){const r=i.doc.lineAt(n);return gn(t,e,r.from,r.to)}function CL(i,t,e,n){return t.kind==="inline"?!gn(e,n,t.contextFrom,t.contextTo):!$L(i,e,n,t.contextFrom)}function PL(i){let t=i.firstChild;for(;t;){if(t.name==="TaskMarker")return!0;if(t.name==="Task"){let e=t.firstChild;for(;e;){if(e.name==="TaskMarker")return!0;e=e.nextSibling}}t=t.nextSibling}return!1}function TL(i){let t=i.parent;for(;t;){if(t.name==="ListItem")return t;t=t.parent}return null}function Hn(i,t){let e=i.firstChild;for(;e;){if(e.name===t)return e;e=e.nextSibling}return null}function mg(i,t){const e=[];let n=t.firstChild;for(;n;)n.name==="CodeMark"&&e.push(n),n=n.nextSibling;if(e.length>=2)return{from:t.from,to:e[e.length-1].to,closed:!0};const r=i.doc.lineAt(t.from);return{from:r.from,to:r.to,closed:!1}}function Ev(i,t){let e=t.to;for(;e<i.doc.length&&i.doc.sliceString(e,e+1)===" ";)e+=1;return{from:t.from,to:e}}function Kh(i,t){return{from:i.doc.lineAt(t.from).from,to:Ev(i,t).to}}function Jh(i,t){return Ev(i,t)}function gg(i,t,e){const n=Hn(t,"ListMark"),r=n?i.doc.lineAt(n.from).from:e.from;let s=e.to;for(;s<i.doc.length&&i.doc.sliceString(s,s+1)===" ";)s+=1;return{from:r,to:s}}function tu(i,t,e){const n=i.doc.lineAt(t.from);n.from<t.from&&e.push(cL.range(n.from,t.from))}function AL(i,t,e){let n=0;for(let r=t;r<e;r+=1)n+=i.doc.sliceString(r,r+1)===" "?2:1;return n}function RL(i){return K.line({class:$f,attributes:{style:`--cm-md-list-indent: ${i.prefixRevealed?0:i.indentColumns};`}})}function bg(i,t,e,n,r){let s=t;for(;s<=e;){const o=i.doc.lineAt(s);if(r.push(n.range(o.from)),o.to>=e)break;s=o.to+1}}function ZL(i,t,e,n){const r=Hn(t,"ListMark"),s=i.doc.lineAt(r?r.from:t.from).from,o=r?AL(i,s,r.from):0;let l=t.from;for(;l<=t.to;){const a=i.doc.lineAt(l),c=a.from===s,h=/^\s/.test(a.text);if(c||h){const u=e.get(a.from),f={indentColumns:o,prefixRevealed:c&&n};u===void 0||o>u.indentColumns?e.set(a.from,f):o===u.indentColumns&&f.prefixRevealed&&e.set(a.from,{...u,prefixRevealed:!0})}if(a.to>=t.to)break;l=a.to+1}}function XL(i,t){let e=i.resolveInner(t,1);for(;e;){if(kL.has(e.name)||e.name.startsWith("Table"))return!0;e=e.parent}return!1}function EL(i,t){const e=/^( {0,3})(#{1,6})(?:\s|$)/.exec(i);if(!e)return!1;const n=e[1]??"",r=e[2]??"",s=n.length,o=s+r.length;return t>=s&&t<o}function LL(i,t,e){for(let n=1;n<=i.doc.lines;n+=1){const r=i.doc.line(n);pg.lastIndex=0;let s;for(;(s=pg.exec(r.text))!==null;){const o=s[1]??"",a=(s[2]??"").replace(xL,"");if(a.length<=1||!yL.test(a))continue;const c=r.from+s.index+o.length,h=c+a.length;EL(r.text,c-r.from)||XL(t,c)||e.push(mL.range(c,h))}}}function wg(i,t,e,n){const r=[],s=new Map,o=new Set,l=i.selection.main,a=n?Math.min(l.from,l.to):-1,c=n?Math.max(l.from,l.to):-1;e.iterate({from:0,to:i.doc.length,enter:h=>{var p,m;if(h.name==="Table"||h.name.startsWith("Table"))return!1;const u=h.node.parent,f=(u==null?void 0:u.name)??null;let d=h.to;(h.name==="HeaderMark"||h.name==="QuoteMark")&&i.doc.sliceString(d,d+1)===" "&&(d+=1);const O=QL(h.name,f,(u==null?void 0:u.from)??null,(u==null?void 0:u.to)??null,h.from,d);if(O){const g=CL(i,O,a,c)?Ro:qn;r.push(g.range(h.from,d))}if(h.name==="ListMark"){const g=h.node.parent;if(g&&g.name==="ListItem"){const b=PL(g),S=((p=g.parent)==null?void 0:p.name)==="OrderedList";if(!b&&!S){const x=Kh(i,h.node),y=Jh(i,h.node);gn(a,c,x.from,x.to)?(tu(i,h.node,r),r.push(qn.range(y.from,y.to))):r.push(Ro.range(x.from,x.to))}else if(S){const x=i.doc.lineAt(h.node.from),y=Kh(i,h.node);x.from<h.node.from&&(gn(a,c,y.from,y.to)?tu(i,h.node,r):r.push(Ro.range(x.from,h.node.from))),r.push(qn.range(h.node.from,h.node.to))}}}if(h.name==="InlineCode"){const g=h.node.firstChild,b=h.node.lastChild;g&&b&&g!==b&&g.name==="CodeMark"&&b.name==="CodeMark"&&g.to<b.from&&r.push(hL.range(g.to,b.from))}if(h.name==="ListItem"){const g=Hn(h.node,"ListMark"),b=Hn(h.node,"Task"),S=Hn(h.node,"TaskMarker")??(b?Hn(b,"TaskMarker"):null),x=S!==null,y=((m=h.node.parent)==null?void 0:m.name)==="OrderedList";let k=!1;if(g){const Q=S?gg(i,h.node,S):Kh(i,g);k=gn(a,c,Q.from,Q.to)}if(ZL(i,h.node,s,k),!x&&!y&&g&&!k){const Q=i.doc.lineAt(h.from);o.add(Q.from)}}else if(h.name==="Blockquote")bg(i,h.from,h.to,fL,r);else if(h.name==="ATXHeading1"){const g=i.doc.lineAt(h.from);r.push(OL.range(g.from))}else if(h.name==="ATXHeading2"){const g=i.doc.lineAt(h.from);r.push(pL.range(g.from))}else if(h.name==="FencedCode"){const g=mg(i,h.node);bg(i,g.from,g.to,dL,r)}if(h.name==="Link"){let g=null,b=null,S=null,x=h.node.firstChild;for(;x;)x.name==="LinkMark"?g===null?g=x:b=x:x.name==="URL"&&(S=x),x=x.nextSibling;if(g&&b&&S&&g.to<b.from){const y=i.doc.sliceString(S.from,S.to),k=K.mark({class:eO,tagName:"a",attributes:{"data-href":y}});r.push(k.range(g.to,b.from))}}if(h.name==="CodeMark"&&f==="FencedCode"){const g=h.node.parent;if(g){const b=mg(i,g);if(b.closed){const S=gn(a,c,b.from,b.to)?qn:Ro;r.push(S.range(h.from,h.to))}else r.push(qn.range(h.from,h.to))}}if(h.name==="HorizontalRule"){const g=i.doc.lineAt(h.from);g.to>g.from&&!gn(a,c,g.from,g.to)&&r.push(bL.range(g.from,g.to))}if(h.name==="TaskMarker"){const g=TL(h.node),b=g?Hn(g,"ListMark"):null,S=g?gg(i,g,h.node):{from:h.from,to:h.to};if(gn(a,c,S.from,S.to)){if(b){const y=Jh(i,b);tu(i,b,r),r.push(qn.range(y.from,y.to))}r.push(qn.range(h.from,h.to))}else{if(b){const E=Jh(i,b),W=i.doc.lineAt(b.from).from;r.push(Ro.range(W,E.to))}const y=i.doc.sliceString(h.from,h.to),k=y==="[x]"||y==="[X]",Q=K.replace({widget:new wL(k,h.from,h.to)});r.push(Q.range(h.from,h.to))}}}});for(const[h,u]of s)r.push(RL(u).range(h));for(const h of o)r.push(uL.range(h));return LL(i,e,r),K.set(r,!0)}const ML=Fe.fromClass(class{constructor(i){C(this,"decorations");this.decorations=wg(i.state,i.visibleRanges,St(i.state),i.hasFocus)}update(i){(i.docChanged||i.selectionSet||i.viewportChanged||i.focusChanged||St(i.state)!==St(i.startState))&&(this.decorations=wg(i.state,i.view.visibleRanges,St(i.state),i.view.hasFocus))}},{decorations:i=>i.decorations}),zL=z.theme({"&":{fontFamily:"var(--font-sans)",fontSize:"calc(var(--text-base) + 0.5px)",lineHeight:"1.5"},".cm-scroller":{fontFamily:"inherit",fontSize:"inherit",lineHeight:"inherit"},".cm-content":{fontFamily:"inherit",fontSize:"inherit",lineHeight:"inherit",padding:"1.5rem 1rem"},[`.${Xv}`]:{fontFamily:"var(--font-mono)"},[`.${kv}`]:{fontFamily:"var(--font-mono)",fontSize:"0.9em"},[`.${Av}`]:{fontSize:"1.3em"},[`.${Rv}`]:{fontSize:"1.1em"},[`.${Qv}`]:{fontFamily:"var(--font-mono)",fontSize:"0.92em",padding:"1px 4px",borderRadius:"3px"},[`.${Zv}`]:{borderRadius:"var(--radius-pill)",padding:"0 0.35em",fontWeight:"600",boxDecorationBreak:"clone",WebkitBoxDecorationBreak:"clone"},[`.${$f}`]:{paddingLeft:`calc(0.5rem + var(--cm-md-list-indent, 0) * ${aL})`},[`.${$f}.${Cf}`]:{borderLeft:`${Og} solid transparent`},[`.${Cf}::before`]:{content:"'•'",marginLeft:`calc(-1 * ${Og})`,fontFamily:"var(--font-mono)",fontSize:"0.9em",paddingRight:"0.5rem"},[`.${$v}`]:{borderLeft:"3px solid transparent",paddingLeft:"1rem",marginLeft:"0.25rem"},[`.${Cv}`]:{fontFamily:"ui-monospace, SFMono-Regular, Menlo, Consolas, monospace",fontSize:"0.92em",paddingLeft:"0.75em"},[`.${Pv}`]:{display:"inline-block",verticalAlign:"middle",border:"none",borderTop:"1px solid transparent",margin:0,width:"100%"},[`.${Tv}`]:{margin:"0 0.4em 0 0",cursor:"default",verticalAlign:"middle"},[`a.${eO}`]:{textDecoration:"underline",textUnderlineOffset:"0.15em",cursor:"pointer"}}),_L=4;function Lv(i){return i instanceof Element?i.closest(`a.${eO}`):null}function IL(i){const t=i.getAttribute("data-href");if(t===null)return null;try{return new URL(t,window.document.baseURI).href}catch{return null}}function Mv(){return window.__televisionContentBridge}function jL(i){const t={type:"navigation-request",url:i},e=Mv();if(e){e.postToHost(t);return}window.parent.postMessage(t,"*")}function DL(i){const t=Mv();if(t!=null&&t.openApplicationLink){t.openApplicationLink(i);return}window.location.href=i}function YL(i,t){return Math.hypot(t.clientX-i.x,t.clientY-i.y)>_L}let zr=null;function Sg(i){const t=Lv(i.target);if(!t||i.altKey)return zr=null,!1;const e=zr;if(zr=null,!e||e.anchor!==t)return!1;if(i.preventDefault(),YL(e,i))return!0;const n=yv(e.url,window.document.baseURI);return n.kind==="application"?DL(n.url):n.kind==="web"&&e.openExternally?window.open(n.url,"_blank","noopener,noreferrer"):n.kind==="web"&&jL(n.url),!0}const Ea={mousedown(i){const t=Lv(i.target);if(zr=null,!t||i.button!==0&&i.button!==1||i.altKey)return!1;const e=IL(t);return e===null||i.button===1&&yv(e,window.document.baseURI).kind!=="application"?!1:(zr={anchor:t,url:e,openExternally:i.metaKey||i.ctrlKey,x:i.clientX,y:i.clientY},i.preventDefault(),!0)},click(i){return i.button!==0?!1:Sg(i)},auxclick(i){return i.button!==1?!1:Sg(i)}},WL=z.domEventHandlers(Ea),Pf=/^(\d+)([.)])(\s|$)/;function VL(i,t){const e=[];let n=[],r=0;const s=a=>{o&&t.some(c=>c.from<=a&&c.to>=r)&&e.push(...n),n=[]};let o=!1,l=1;for(let a=1;a<=i.doc.lines;a+=1){const c=i.doc.line(a),h=Pf.exec(c.text);h?(o||(o=!0,l=1,r=c.from),parseInt(h[1],10)!==l&&n.push({from:c.from,to:c.from+h[1].length,insert:String(l)}),l+=1):c.text===""&&(s(c.from-1),o=!1)}return s(i.doc.length),e}const vg=ei.define(),BL=J.transactionFilter.of(i=>{if(!i.docChanged||i.annotation(vg)||!i.isUserEvent("input")&&!i.isUserEvent("delete"))return i;const t=[];i.changes.iterChangedRanges((n,r,s,o)=>{const l=i.state.doc.lineAt(s),a=Pf.test(i.startState.doc.lineAt(n).text)&&!Pf.test(l.text);t.push({from:l.from,to:a&&l.number<i.state.doc.lines?i.state.doc.line(l.number+1).to:i.state.doc.lineAt(Math.max(s,o-1)).to})});const e=VL(i.state,t);return e.length===0?i:[i,{changes:Vt.of(e,i.state.doc.length),annotations:vg.of(!0),sequential:!0}]}),qL=/^(\s*)([-*]|\d+[.)])(\s\[[ xX]\])?\s$/,NL=i=>{const{state:t}=i,e=t.selection.main;if(e.from!==e.to)return!1;const n=t.doc.lineAt(e.from),r=n.text.slice(0,e.from-n.from);return qL.test(r)?(i.dispatch({changes:{from:e.from-1,to:e.from,insert:""},selection:{anchor:e.from-1},userEvent:"delete.backward",scrollIntoView:!0}),!0):!1},GL=hn.highest(Mn.of([{key:"Backspace",run:NL}])),UL=[ML,zL,BL,GL,WL];function HL(i){const t=i.textContent??"",e=[];fl.parser.parse(t).iterate({enter(n){if(n.name!=="Link")return;const r=n.node,s=r.getChild("LinkMark"),o=r.getChildren("LinkMark")[1],l=r.getChild("URL");!s||!o||!l||s.to>=o.from||e.push({from:n.from,to:n.to,labelFrom:s.to,labelTo:o.from,href:t.slice(l.from,l.to)})}});for(const n of e.reverse()){const r=(h,u)=>{var m;const f=i.ownerDocument.createRange(),d=i.ownerDocument.createTreeWalker(i,NodeFilter.SHOW_TEXT);let O=0,p=!1;for(let g=d.nextNode();g;g=d.nextNode()){const b=O+(((m=g.textContent)==null?void 0:m.length)??0);if(!p&&h<=b&&(f.setStart(g,h-O),p=!0),u<=b){f.setEnd(g,u-O);break}O=b}return f},s=i.ownerDocument.createElement("a");s.className="cm-md-link",s.dataset.href=n.href,s.append(r(n.labelFrom,n.labelTo).cloneContents());const o=i.ownerDocument.createElement("span");o.className="cm-md-table-link";const l=i.ownerDocument.createElement("span");l.hidden=!0,l.textContent=t.slice(n.from,n.labelFrom);const a=i.ownerDocument.createElement("span");a.hidden=!0,a.textContent=t.slice(n.labelTo,n.to),o.append(l,s,a);const c=r(n.from,n.to);c.deleteContents(),c.insertNode(o)}}const FL=Fe.fromClass(class{constructor(i){C(this,"observer");C(this,"rendered",new WeakMap);C(this,"view");C(this,"pointerdown",i=>{this.isTableLink(i)&&!i.altKey&&(i.button===0||i.button===1)&&i.stopPropagation()});C(this,"mousedown",i=>{this.isTableLink(i)&&(Ea.mousedown(i)||i.button===1&&!i.altKey)&&(i.preventDefault(),i.stopPropagation())});C(this,"click",i=>{this.isTableLink(i)&&Ea.click(i)&&i.stopPropagation()});C(this,"auxclick",i=>{this.isTableLink(i)&&Ea.auxclick(i)&&i.stopPropagation()});this.view=i,this.observer=new MutationObserver(()=>this.render()),this.observer.observe(i.dom,{childList:!0,characterData:!0,attributes:!0,attributeFilter:["data-hidden"],subtree:!0}),i.dom.addEventListener("pointerdown",this.pointerdown,!0),i.dom.addEventListener("mousedown",this.mousedown,!0),i.dom.addEventListener("click",this.click,!0),i.dom.addEventListener("auxclick",this.auxclick,!0),this.render()}render(){for(const i of this.view.dom.querySelectorAll(".tbl-cell-view:not(.cm-md-table-cell-view)")){const t=i.innerHTML;let e=this.rendered.get(i);if(!e||e.source!==t){const n=(e==null?void 0:e.display)??i.cloneNode(!1);if(n.classList.add("cm-md-table-cell-view"),n.style.display="",n.replaceChildren(...Array.from(i.childNodes,r=>r.cloneNode(!0))),HL(n),!n.querySelector("a.cm-md-link")){e==null||e.display.remove(),this.rendered.delete(i),i.style.display="";continue}i.style.display="none",e||i.after(n),e={display:n,source:t},this.rendered.set(i,e)}e.display.getAttribute("data-hidden")!==i.getAttribute("data-hidden")&&(i.hasAttribute("data-hidden")?e.display.setAttribute("data-hidden",i.getAttribute("data-hidden")??""):e.display.removeAttribute("data-hidden"))}}isTableLink(i){return i.target instanceof Element&&!!i.target.closest(".tbl-cell-view a.cm-md-link")}destroy(){this.observer.disconnect();for(const i of this.view.dom.querySelectorAll(".tbl-cell-view:not(.cm-md-table-cell-view)")){const t=this.rendered.get(i);t&&(t.display.remove(),i.style.display="")}this.view.dom.removeEventListener("pointerdown",this.pointerdown,!0),this.view.dom.removeEventListener("mousedown",this.mousedown,!0),this.view.dom.removeEventListener("click",this.click,!0),this.view.dom.removeEventListener("auxclick",this.auxclick,!0)}}),KL=500,xg=ei.define(),JL=Lc.define([{tag:v.heading,fontWeight:"600"},{tag:v.strong,fontWeight:"600"},{tag:v.emphasis,fontStyle:"italic"},{tag:v.strikethrough,textDecoration:"line-through"}]);function yg(i){const t=i.length;return({state:e,dispatch:n})=>{const r=e.changeByRange(s=>{if(s.empty)return{changes:{from:s.from,insert:i+i},range:P.cursor(s.from+t)};const o=e.sliceDoc(s.from,s.to);if(o.length>=t*2&&o.startsWith(i)&&o.endsWith(i))return{changes:[{from:s.from,to:s.from+t},{from:s.to-t,to:s.to}],range:P.range(s.from,s.to-t*2)};const l=s.from>=t&&e.sliceDoc(s.from-t,s.from)===i,a=s.to+t<=e.doc.length&&e.sliceDoc(s.to,s.to+t)===i;return l&&a?{changes:[{from:s.from-t,to:s.from},{from:s.to,to:s.to+t}],range:P.range(s.from-t,s.to-t)}:{changes:[{from:s.from,insert:i},{from:s.to,insert:i}],range:P.range(s.from+t,s.to+t)}});return n(e.update(r,{scrollIntoView:!0,userEvent:"input"})),!0}}const tM=hn.highest(Mn.of([{key:"Mod-b",run:yg("**")},{key:"Mod-i",run:yg("*")},{key:"Enter",run:d1({nonTightLists:!1})}])),eM=cc.default.with({"--tbl-style-font-family":"var(--font-sans)","--tbl-style-font-size":"inherit","--tbl-style-menu-font-family":"var(--font-sans)","--tbl-style-menu-font-size":"var(--text-sm, 0.875rem)","--tbl-style-default-header-alignment":"left"}),iM=oL({theme:pl.light,style:eM,selectionType:"native",handlePosition:"outside",lineWrapping:"wrap",extensions:[Mn.of(tw)],globalKeyBindings:[...$0]}),zv=[QQ(),Oo.of(" "),tM,Mn.of([...tw,...$0,$$]),Ml({extensions:[kw,Dc,{remove:["SetextHeading"]}]}),b0(JL),z.lineWrapping,UL,iM,FL];function nM(i){const{parent:t,ctx:e}=i,n=i.debounceMs??KL;let r=null,s=null,o=null;const l=f=>{h.state.doc.toString()!==f&&h.dispatch({changes:{from:0,to:h.state.doc.length,insert:f},annotations:[xg.of(!0),Lt.addToHistory.of(!1)]})},a=async()=>{o=null;const f=h.state.doc.toString();r=f;try{await e.updateContent(f),s=f}catch{const d=s??"";l(d),r=d}},c=z.updateListener.of(f=>{!f.docChanged||f.transactions.some(O=>O.annotation(xg))||(o!==null&&clearTimeout(o),o=setTimeout(()=>{a()},n))}),h=new z({parent:t,state:J.create({doc:"",extensions:[zv,c]})}),u=f=>{const d=f.content;r!==null&&d===r||(l(d),s=d)};return e.addEventListener("content-updated",u),{view:h,dispose(){o!==null&&(clearTimeout(o),o=null),e.removeEventListener("content-updated",u),h.destroy()}}}const rM=`# Heading 1
|
|
66
66
|
|
|
67
67
|
Some paragraph text with **bold**, *italic*, \`inline code\`, and an [inline link](https://example.com).
|
|
68
68
|
|
|
@@ -62,7 +62,7 @@ var bA=Object.defineProperty;var Zv=n=>{throw TypeError(n)};var SA=(n,t,e)=>t in
|
|
|
62
62
|
`)}v.write("payload.value = newResult;"),v.write("return payload;");const L=v.compile();return(P,B)=>L(y,P,B)};let s;const a=eu,l=!X8.jitless,u=l&&RT.value,f=t.catchall;let p;n._zod.parse=(y,v)=>{p??(p=r.value);const S=y.value;return a(S)?l&&u&&(v==null?void 0:v.async)===!1&&v.jitless!==!0?(s||(s=i(t.shape)),y=s(y,v),f?m6([],S,y,v,p,n):y):e(y,v):(y.issues.push({expected:"object",code:"invalid_type",input:S,inst:n}),y)}});function k2(n,t,e,r){for(const s of n)if(s.issues.length===0)return t.value=s.value,t;const i=n.filter(s=>!Ma(s));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:e,errors:n.map(s=>s.issues.map(a=>$s(a,r,Is())))}),t)}const g6=I("$ZodUnion",(n,t)=>{Ze.init(n,t),Ae(n._zod,"optin",()=>t.options.some(i=>i._zod.optin==="optional")?"optional":void 0),Ae(n._zod,"optout",()=>t.options.some(i=>i._zod.optout==="optional")?"optional":void 0),Ae(n._zod,"values",()=>{if(t.options.every(i=>i._zod.values))return new Set(t.options.flatMap(i=>Array.from(i._zod.values)))}),Ae(n._zod,"pattern",()=>{if(t.options.every(i=>i._zod.pattern)){const i=t.options.map(s=>s._zod.pattern);return new RegExp(`^(${i.map(s=>ev(s.source)).join("|")})$`)}});const e=t.options.length===1,r=t.options[0]._zod.run;n._zod.parse=(i,s)=>{if(e)return r(i,s);let a=!1;const l=[];for(const c of t.options){const u=c._zod.run({value:i.value,issues:[]},s);if(u instanceof Promise)l.push(u),a=!0;else{if(u.issues.length===0)return u;l.push(u)}}return a?Promise.all(l).then(c=>k2(c,i,n,s)):k2(l,i,n,s)}}),fC=I("$ZodDiscriminatedUnion",(n,t)=>{t.inclusive=!1,g6.init(n,t);const e=n._zod.parse;Ae(n._zod,"propValues",()=>{const i={};for(const s of t.options){const a=s._zod.propValues;if(!a||Object.keys(a).length===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(s)}"`);for(const[l,c]of Object.entries(a)){i[l]||(i[l]=new Set);for(const u of c)i[l].add(u)}}return i});const r=Vf(()=>{var a;const i=t.options,s=new Map;for(const l of i){const c=(a=l._zod.propValues)==null?void 0:a[t.discriminator];if(!c||c.size===0)throw new Error(`Invalid discriminated union option at index "${t.options.indexOf(l)}"`);for(const u of c){if(s.has(u))throw new Error(`Duplicate discriminator value "${String(u)}"`);s.set(u,l)}}return s});n._zod.parse=(i,s)=>{const a=i.value;if(!eu(a))return i.issues.push({code:"invalid_type",expected:"object",input:a,inst:n}),i;const l=r.value.get(a==null?void 0:a[t.discriminator]);return l?l._zod.run(i,s):t.unionFallback?e(i,s):(i.issues.push({code:"invalid_union",errors:[],note:"No matching discriminator",discriminator:t.discriminator,input:a,path:[t.discriminator],inst:n}),i)}}),pC=I("$ZodIntersection",(n,t)=>{Ze.init(n,t),n._zod.parse=(e,r)=>{const i=e.value,s=t.left._zod.run({value:i,issues:[]},r),a=t.right._zod.run({value:i,issues:[]},r);return s instanceof Promise||a instanceof Promise?Promise.all([s,a]).then(([c,u])=>T2(e,c,u)):T2(e,s,a)}});function tg(n,t){if(n===t)return{valid:!0,data:n};if(n instanceof Date&&t instanceof Date&&+n==+t)return{valid:!0,data:n};if(ql(n)&&ql(t)){const e=Object.keys(t),r=Object.keys(n).filter(s=>e.indexOf(s)!==-1),i={...n,...t};for(const s of r){const a=tg(n[s],t[s]);if(!a.valid)return{valid:!1,mergeErrorPath:[s,...a.mergeErrorPath]};i[s]=a.data}return{valid:!0,data:i}}if(Array.isArray(n)&&Array.isArray(t)){if(n.length!==t.length)return{valid:!1,mergeErrorPath:[]};const e=[];for(let r=0;r<n.length;r++){const i=n[r],s=t[r],a=tg(i,s);if(!a.valid)return{valid:!1,mergeErrorPath:[r,...a.mergeErrorPath]};e.push(a.data)}return{valid:!0,data:e}}return{valid:!1,mergeErrorPath:[]}}function T2(n,t,e){const r=new Map;let i;for(const l of t.issues)if(l.code==="unrecognized_keys"){i??(i=l);for(const c of l.keys)r.has(c)||r.set(c,{}),r.get(c).l=!0}else n.issues.push(l);for(const l of e.issues)if(l.code==="unrecognized_keys")for(const c of l.keys)r.has(c)||r.set(c,{}),r.get(c).r=!0;else n.issues.push(l);const s=[...r].filter(([,l])=>l.l&&l.r).map(([l])=>l);if(s.length&&i&&n.issues.push({...i,keys:s}),Ma(n))return n;const a=tg(t.value,e.value);if(!a.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(a.mergeErrorPath)}`);return n.value=a.data,n}const mC=I("$ZodRecord",(n,t)=>{Ze.init(n,t),n._zod.parse=(e,r)=>{const i=e.value;if(!ql(i))return e.issues.push({expected:"record",code:"invalid_type",input:i,inst:n}),e;const s=[],a=t.keyType._zod.values;if(a){e.value={};const l=new Set;for(const u of a)if(typeof u=="string"||typeof u=="number"||typeof u=="symbol"){l.add(typeof u=="number"?u.toString():u);const f=t.valueType._zod.run({value:i[u],issues:[]},r);f instanceof Promise?s.push(f.then(p=>{p.issues.length&&e.issues.push(...Na(u,p.issues)),e.value[u]=p.value})):(f.issues.length&&e.issues.push(...Na(u,f.issues)),e.value[u]=f.value)}let c;for(const u in i)l.has(u)||(c=c??[],c.push(u));c&&c.length>0&&e.issues.push({code:"unrecognized_keys",input:i,inst:n,keys:c})}else{e.value={};for(const l of Reflect.ownKeys(i)){if(l==="__proto__")continue;let c=t.keyType._zod.run({value:l,issues:[]},r);if(c instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof l=="string"&&l6.test(l)&&c.issues.length){const p=t.keyType._zod.run({value:Number(l),issues:[]},r);if(p instanceof Promise)throw new Error("Async schemas not supported in object keys currently");p.issues.length===0&&(c=p)}if(c.issues.length){t.mode==="loose"?e.value[l]=i[l]:e.issues.push({code:"invalid_key",origin:"record",issues:c.issues.map(p=>$s(p,r,Is())),input:l,path:[l],inst:n});continue}const f=t.valueType._zod.run({value:i[l],issues:[]},r);f instanceof Promise?s.push(f.then(p=>{p.issues.length&&e.issues.push(...Na(l,p.issues)),e.value[c.value]=p.value})):(f.issues.length&&e.issues.push(...Na(l,f.issues)),e.value[c.value]=f.value)}}return s.length?Promise.all(s).then(()=>e):e}}),gC=I("$ZodEnum",(n,t)=>{Ze.init(n,t);const e=Q8(t.entries),r=new Set(e);n._zod.values=r,n._zod.pattern=new RegExp(`^(${e.filter(i=>CT.has(typeof i)).map(i=>typeof i=="string"?Vl(i):i.toString()).join("|")})$`),n._zod.parse=(i,s)=>{const a=i.value;return r.has(a)||i.issues.push({code:"invalid_value",values:e,input:a,inst:n}),i}}),vC=I("$ZodLiteral",(n,t)=>{if(Ze.init(n,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const e=new Set(t.values);n._zod.values=e,n._zod.pattern=new RegExp(`^(${t.values.map(r=>typeof r=="string"?Vl(r):r?Vl(r.toString()):String(r)).join("|")})$`),n._zod.parse=(r,i)=>{const s=r.value;return e.has(s)||r.issues.push({code:"invalid_value",values:t.values,input:s,inst:n}),r}}),yC=I("$ZodTransform",(n,t)=>{Ze.init(n,t),n._zod.parse=(e,r)=>{if(r.direction==="backward")throw new K8(n.constructor.name);const i=t.transform(e.value,e);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(a=>(e.value=a,e));if(i instanceof Promise)throw new Ha;return e.value=i,e}});function R2(n,t){return n.issues.length&&t===void 0?{issues:[],value:void 0}:n}const v6=I("$ZodOptional",(n,t)=>{Ze.init(n,t),n._zod.optin="optional",n._zod.optout="optional",Ae(n._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Ae(n._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${ev(e.source)})?$`):void 0}),n._zod.parse=(e,r)=>{if(t.innerType._zod.optin==="optional"){const i=t.innerType._zod.run(e,r);return i instanceof Promise?i.then(s=>R2(s,e.value)):R2(i,e.value)}return e.value===void 0?e:t.innerType._zod.run(e,r)}}),wC=I("$ZodExactOptional",(n,t)=>{v6.init(n,t),Ae(n._zod,"values",()=>t.innerType._zod.values),Ae(n._zod,"pattern",()=>t.innerType._zod.pattern),n._zod.parse=(e,r)=>t.innerType._zod.run(e,r)}),bC=I("$ZodNullable",(n,t)=>{Ze.init(n,t),Ae(n._zod,"optin",()=>t.innerType._zod.optin),Ae(n._zod,"optout",()=>t.innerType._zod.optout),Ae(n._zod,"pattern",()=>{const e=t.innerType._zod.pattern;return e?new RegExp(`^(${ev(e.source)}|null)$`):void 0}),Ae(n._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),n._zod.parse=(e,r)=>e.value===null?e:t.innerType._zod.run(e,r)}),SC=I("$ZodDefault",(n,t)=>{Ze.init(n,t),n._zod.optin="optional",Ae(n._zod,"values",()=>t.innerType._zod.values),n._zod.parse=(e,r)=>{if(r.direction==="backward")return t.innerType._zod.run(e,r);if(e.value===void 0)return e.value=t.defaultValue,e;const i=t.innerType._zod.run(e,r);return i instanceof Promise?i.then(s=>C2(s,t)):C2(i,t)}});function C2(n,t){return n.value===void 0&&(n.value=t.defaultValue),n}const _C=I("$ZodPrefault",(n,t)=>{Ze.init(n,t),n._zod.optin="optional",Ae(n._zod,"values",()=>t.innerType._zod.values),n._zod.parse=(e,r)=>(r.direction==="backward"||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,r))}),AC=I("$ZodNonOptional",(n,t)=>{Ze.init(n,t),Ae(n._zod,"values",()=>{const e=t.innerType._zod.values;return e?new Set([...e].filter(r=>r!==void 0)):void 0}),n._zod.parse=(e,r)=>{const i=t.innerType._zod.run(e,r);return i instanceof Promise?i.then(s=>I2(s,n)):I2(i,n)}});function I2(n,t){return!n.issues.length&&n.value===void 0&&n.issues.push({code:"invalid_type",expected:"nonoptional",input:n.value,inst:t}),n}const EC=I("$ZodCatch",(n,t)=>{Ze.init(n,t),Ae(n._zod,"optin",()=>t.innerType._zod.optin),Ae(n._zod,"optout",()=>t.innerType._zod.optout),Ae(n._zod,"values",()=>t.innerType._zod.values),n._zod.parse=(e,r)=>{if(r.direction==="backward")return t.innerType._zod.run(e,r);const i=t.innerType._zod.run(e,r);return i instanceof Promise?i.then(s=>(e.value=s.value,s.issues.length&&(e.value=t.catchValue({...e,error:{issues:s.issues.map(a=>$s(a,r,Is()))},input:e.value}),e.issues=[]),e)):(e.value=i.value,i.issues.length&&(e.value=t.catchValue({...e,error:{issues:i.issues.map(s=>$s(s,r,Is()))},input:e.value}),e.issues=[]),e)}}),kC=I("$ZodPipe",(n,t)=>{Ze.init(n,t),Ae(n._zod,"values",()=>t.in._zod.values),Ae(n._zod,"optin",()=>t.in._zod.optin),Ae(n._zod,"optout",()=>t.out._zod.optout),Ae(n._zod,"propValues",()=>t.in._zod.propValues),n._zod.parse=(e,r)=>{if(r.direction==="backward"){const s=t.out._zod.run(e,r);return s instanceof Promise?s.then(a=>Uh(a,t.in,r)):Uh(s,t.in,r)}const i=t.in._zod.run(e,r);return i instanceof Promise?i.then(s=>Uh(s,t.out,r)):Uh(i,t.out,r)}});function Uh(n,t,e){return n.issues.length?(n.aborted=!0,n):t._zod.run({value:n.value,issues:n.issues},e)}const TC=I("$ZodReadonly",(n,t)=>{Ze.init(n,t),Ae(n._zod,"propValues",()=>t.innerType._zod.propValues),Ae(n._zod,"values",()=>t.innerType._zod.values),Ae(n._zod,"optin",()=>{var e,r;return(r=(e=t.innerType)==null?void 0:e._zod)==null?void 0:r.optin}),Ae(n._zod,"optout",()=>{var e,r;return(r=(e=t.innerType)==null?void 0:e._zod)==null?void 0:r.optout}),n._zod.parse=(e,r)=>{if(r.direction==="backward")return t.innerType._zod.run(e,r);const i=t.innerType._zod.run(e,r);return i instanceof Promise?i.then($2):$2(i)}});function $2(n){return n.value=Object.freeze(n.value),n}const RC=I("$ZodCustom",(n,t)=>{Gt.init(n,t),Ze.init(n,t),n._zod.parse=(e,r)=>e,n._zod.check=e=>{const r=e.value,i=t.fn(r);if(i instanceof Promise)return i.then(s=>x2(s,e,r,n));x2(i,e,r,n)}});function x2(n,t,e,r){if(!n){const i={code:"custom",input:e,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(i.params=r._zod.def.params),t.issues.push(tu(i))}}var P2;class CC{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...e){const r=e[0];return this._map.set(t,r),r&&typeof r=="object"&&"id"in r&&this._idmap.set(r.id,t),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const e=this._map.get(t);return e&&typeof e=="object"&&"id"in e&&this._idmap.delete(e.id),this._map.delete(t),this}get(t){const e=t._zod.parent;if(e){const r={...this.get(e)??{}};delete r.id;const i={...r,...this._map.get(t)};return Object.keys(i).length?i:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function IC(){return new CC}(P2=globalThis).__zod_globalRegistry??(P2.__zod_globalRegistry=IC());const $c=globalThis.__zod_globalRegistry;function $C(n,t){return new n({type:"string",...Y(t)})}function xC(n,t){return new n({type:"string",format:"email",check:"string_format",abort:!1,...Y(t)})}function D2(n,t){return new n({type:"string",format:"guid",check:"string_format",abort:!1,...Y(t)})}function PC(n,t){return new n({type:"string",format:"uuid",check:"string_format",abort:!1,...Y(t)})}function DC(n,t){return new n({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...Y(t)})}function LC(n,t){return new n({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...Y(t)})}function OC(n,t){return new n({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...Y(t)})}function MC(n,t){return new n({type:"string",format:"url",check:"string_format",abort:!1,...Y(t)})}function NC(n,t){return new n({type:"string",format:"emoji",check:"string_format",abort:!1,...Y(t)})}function zC(n,t){return new n({type:"string",format:"nanoid",check:"string_format",abort:!1,...Y(t)})}function UC(n,t){return new n({type:"string",format:"cuid",check:"string_format",abort:!1,...Y(t)})}function HC(n,t){return new n({type:"string",format:"cuid2",check:"string_format",abort:!1,...Y(t)})}function ZC(n,t){return new n({type:"string",format:"ulid",check:"string_format",abort:!1,...Y(t)})}function qC(n,t){return new n({type:"string",format:"xid",check:"string_format",abort:!1,...Y(t)})}function VC(n,t){return new n({type:"string",format:"ksuid",check:"string_format",abort:!1,...Y(t)})}function FC(n,t){return new n({type:"string",format:"ipv4",check:"string_format",abort:!1,...Y(t)})}function BC(n,t){return new n({type:"string",format:"ipv6",check:"string_format",abort:!1,...Y(t)})}function jC(n,t){return new n({type:"string",format:"cidrv4",check:"string_format",abort:!1,...Y(t)})}function WC(n,t){return new n({type:"string",format:"cidrv6",check:"string_format",abort:!1,...Y(t)})}function GC(n,t){return new n({type:"string",format:"base64",check:"string_format",abort:!1,...Y(t)})}function JC(n,t){return new n({type:"string",format:"base64url",check:"string_format",abort:!1,...Y(t)})}function YC(n,t){return new n({type:"string",format:"e164",check:"string_format",abort:!1,...Y(t)})}function KC(n,t){return new n({type:"string",format:"jwt",check:"string_format",abort:!1,...Y(t)})}function XC(n,t){return new n({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...Y(t)})}function QC(n,t){return new n({type:"string",format:"date",check:"string_format",...Y(t)})}function e3(n,t){return new n({type:"string",format:"time",check:"string_format",precision:null,...Y(t)})}function t3(n,t){return new n({type:"string",format:"duration",check:"string_format",...Y(t)})}function n3(n,t){return new n({type:"number",checks:[],...Y(t)})}function r3(n,t){return new n({type:"number",check:"number_format",abort:!1,format:"safeint",...Y(t)})}function i3(n,t){return new n({type:"boolean",...Y(t)})}function s3(n){return new n({type:"unknown"})}function o3(n,t){return new n({type:"never",...Y(t)})}function L2(n,t){return new u6({check:"less_than",...Y(t),value:n,inclusive:!1})}function Rm(n,t){return new u6({check:"less_than",...Y(t),value:n,inclusive:!0})}function O2(n,t){return new h6({check:"greater_than",...Y(t),value:n,inclusive:!1})}function Cm(n,t){return new h6({check:"greater_than",...Y(t),value:n,inclusive:!0})}function M2(n,t){return new SR({check:"multiple_of",...Y(t),value:n})}function y6(n,t){return new AR({check:"max_length",...Y(t),maximum:n})}function Pd(n,t){return new ER({check:"min_length",...Y(t),minimum:n})}function w6(n,t){return new kR({check:"length_equals",...Y(t),length:n})}function a3(n,t){return new TR({check:"string_format",format:"regex",...Y(t),pattern:n})}function l3(n){return new RR({check:"string_format",format:"lowercase",...Y(n)})}function c3(n){return new CR({check:"string_format",format:"uppercase",...Y(n)})}function u3(n,t){return new IR({check:"string_format",format:"includes",...Y(t),includes:n})}function h3(n,t){return new $R({check:"string_format",format:"starts_with",...Y(t),prefix:n})}function d3(n,t){return new xR({check:"string_format",format:"ends_with",...Y(t),suffix:n})}function ec(n){return new PR({check:"overwrite",tx:n})}function f3(n){return ec(t=>t.normalize(n))}function p3(){return ec(n=>n.trim())}function m3(){return ec(n=>n.toLowerCase())}function g3(){return ec(n=>n.toUpperCase())}function v3(){return ec(n=>TT(n))}function y3(n,t,e){return new n({type:"array",element:t,...Y(e)})}function w3(n,t,e){return new n({type:"custom",check:"custom",fn:t,...Y(e)})}function b3(n){const t=S3(e=>(e.addIssue=r=>{if(typeof r=="string")e.issues.push(tu(r,e.value,t._zod.def));else{const i=r;i.fatal&&(i.continue=!1),i.code??(i.code="custom"),i.input??(i.input=e.value),i.inst??(i.inst=t),i.continue??(i.continue=!t._zod.def.abort),e.issues.push(tu(i))}},n(e.value,e)));return t}function S3(n,t){const e=new Gt({check:"custom",...Y(t)});return e._zod.check=n,e}function b6(n){let t=(n==null?void 0:n.target)??"draft-2020-12";return t==="draft-4"&&(t="draft-04"),t==="draft-7"&&(t="draft-07"),{processors:n.processors??{},metadataRegistry:(n==null?void 0:n.metadata)??$c,target:t,unrepresentable:(n==null?void 0:n.unrepresentable)??"throw",override:(n==null?void 0:n.override)??(()=>{}),io:(n==null?void 0:n.io)??"output",counter:0,seen:new Map,cycles:(n==null?void 0:n.cycles)??"ref",reused:(n==null?void 0:n.reused)??"inline",external:(n==null?void 0:n.external)??void 0}}function Xe(n,t,e={path:[],schemaPath:[]}){var f,p;var r;const i=n._zod.def,s=t.seen.get(n);if(s)return s.count++,e.schemaPath.includes(n)&&(s.cycle=e.path),s.schema;const a={schema:{},count:1,cycle:void 0,path:e.path};t.seen.set(n,a);const l=(p=(f=n._zod).toJSONSchema)==null?void 0:p.call(f);if(l)a.schema=l;else{const y={...e,schemaPath:[...e.schemaPath,n],path:e.path};if(n._zod.processJSONSchema)n._zod.processJSONSchema(t,a.schema,y);else{const S=a.schema,_=t.processors[i.type];if(!_)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);_(n,t,S,y)}const v=n._zod.parent;v&&(a.ref||(a.ref=v),Xe(v,t,y),t.seen.get(v).isParent=!0)}const c=t.metadataRegistry.get(n);return c&&Object.assign(a.schema,c),t.io==="input"&&At(n)&&(delete a.schema.examples,delete a.schema.default),t.io==="input"&&a.schema._prefault&&((r=a.schema).default??(r.default=a.schema._prefault)),delete a.schema._prefault,t.seen.get(n).schema}function S6(n,t){var a,l,c,u;const e=n.seen.get(t);if(!e)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=new Map;for(const f of n.seen.entries()){const p=(a=n.metadataRegistry.get(f[0]))==null?void 0:a.id;if(p){const y=r.get(p);if(y&&y!==f[0])throw new Error(`Duplicate schema id "${p}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(p,f[0])}}const i=f=>{var _;const p=n.target==="draft-2020-12"?"$defs":"definitions";if(n.external){const $=(_=n.external.registry.get(f[0]))==null?void 0:_.id,H=n.external.uri??(z=>z);if($)return{ref:H($)};const L=f[1].defId??f[1].schema.id??`schema${n.counter++}`;return f[1].defId=L,{defId:L,ref:`${H("__shared")}#/${p}/${L}`}}if(f[1]===e)return{ref:"#"};const v=`#/${p}/`,S=f[1].schema.id??`__schema${n.counter++}`;return{defId:S,ref:v+S}},s=f=>{if(f[1].schema.$ref)return;const p=f[1],{ref:y,defId:v}=i(f);p.def={...p.schema},v&&(p.defId=v);const S=p.schema;for(const _ in S)delete S[_];S.$ref=y};if(n.cycles==="throw")for(const f of n.seen.entries()){const p=f[1];if(p.cycle)throw new Error(`Cycle detected: #/${(l=p.cycle)==null?void 0:l.join("/")}/<root>
|
|
63
63
|
|
|
64
64
|
Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const f of n.seen.entries()){const p=f[1];if(t===f[0]){s(f);continue}if(n.external){const v=(c=n.external.registry.get(f[0]))==null?void 0:c.id;if(t!==f[0]&&v){s(f);continue}}if((u=n.metadataRegistry.get(f[0]))==null?void 0:u.id){s(f);continue}if(p.cycle){s(f);continue}if(p.count>1&&n.reused==="ref"){s(f);continue}}}function _6(n,t){var a,l,c;const e=n.seen.get(t);if(!e)throw new Error("Unprocessed schema. This is a bug in Zod.");const r=u=>{const f=n.seen.get(u);if(f.ref===null)return;const p=f.def??f.schema,y={...p},v=f.ref;if(f.ref=null,v){r(v);const _=n.seen.get(v),$=_.schema;if($.$ref&&(n.target==="draft-07"||n.target==="draft-04"||n.target==="openapi-3.0")?(p.allOf=p.allOf??[],p.allOf.push($)):Object.assign(p,$),Object.assign(p,y),u._zod.parent===v)for(const L in p)L==="$ref"||L==="allOf"||L in y||delete p[L];if($.$ref&&_.def)for(const L in p)L==="$ref"||L==="allOf"||L in _.def&&JSON.stringify(p[L])===JSON.stringify(_.def[L])&&delete p[L]}const S=u._zod.parent;if(S&&S!==v){r(S);const _=n.seen.get(S);if(_!=null&&_.schema.$ref&&(p.$ref=_.schema.$ref,_.def))for(const $ in p)$==="$ref"||$==="allOf"||$ in _.def&&JSON.stringify(p[$])===JSON.stringify(_.def[$])&&delete p[$]}n.override({zodSchema:u,jsonSchema:p,path:f.path??[]})};for(const u of[...n.seen.entries()].reverse())r(u[0]);const i={};if(n.target==="draft-2020-12"?i.$schema="https://json-schema.org/draft/2020-12/schema":n.target==="draft-07"?i.$schema="http://json-schema.org/draft-07/schema#":n.target==="draft-04"?i.$schema="http://json-schema.org/draft-04/schema#":n.target,(a=n.external)!=null&&a.uri){const u=(l=n.external.registry.get(t))==null?void 0:l.id;if(!u)throw new Error("Schema is missing an `id` property");i.$id=n.external.uri(u)}Object.assign(i,e.def??e.schema);const s=((c=n.external)==null?void 0:c.defs)??{};for(const u of n.seen.entries()){const f=u[1];f.def&&f.defId&&(s[f.defId]=f.def)}n.external||Object.keys(s).length>0&&(n.target==="draft-2020-12"?i.$defs=s:i.definitions=s);try{const u=JSON.parse(JSON.stringify(i));return Object.defineProperty(u,"~standard",{value:{...t["~standard"],jsonSchema:{input:Dd(t,"input",n.processors),output:Dd(t,"output",n.processors)}},enumerable:!1,writable:!1}),u}catch{throw new Error("Error converting schema to JSON.")}}function At(n,t){const e=t??{seen:new Set};if(e.seen.has(n))return!1;e.seen.add(n);const r=n._zod.def;if(r.type==="transform")return!0;if(r.type==="array")return At(r.element,e);if(r.type==="set")return At(r.valueType,e);if(r.type==="lazy")return At(r.getter(),e);if(r.type==="promise"||r.type==="optional"||r.type==="nonoptional"||r.type==="nullable"||r.type==="readonly"||r.type==="default"||r.type==="prefault")return At(r.innerType,e);if(r.type==="intersection")return At(r.left,e)||At(r.right,e);if(r.type==="record"||r.type==="map")return At(r.keyType,e)||At(r.valueType,e);if(r.type==="pipe")return At(r.in,e)||At(r.out,e);if(r.type==="object"){for(const i in r.shape)if(At(r.shape[i],e))return!0;return!1}if(r.type==="union"){for(const i of r.options)if(At(i,e))return!0;return!1}if(r.type==="tuple"){for(const i of r.items)if(At(i,e))return!0;return!!(r.rest&&At(r.rest,e))}return!1}const _3=(n,t={})=>e=>{const r=b6({...e,processors:t});return Xe(n,r),S6(r,n),_6(r,n)},Dd=(n,t,e={})=>r=>{const{libraryOptions:i,target:s}=r??{},a=b6({...i??{},target:s,io:t,processors:e});return Xe(n,a),S6(a,n),_6(a,n)},A3={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},E3=(n,t,e,r)=>{const i=e;i.type="string";const{minimum:s,maximum:a,format:l,patterns:c,contentEncoding:u}=n._zod.bag;if(typeof s=="number"&&(i.minLength=s),typeof a=="number"&&(i.maxLength=a),l&&(i.format=A3[l]??l,i.format===""&&delete i.format,l==="time"&&delete i.format),u&&(i.contentEncoding=u),c&&c.size>0){const f=[...c];f.length===1?i.pattern=f[0].source:f.length>1&&(i.allOf=[...f.map(p=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:p.source}))])}},k3=(n,t,e,r)=>{const i=e,{minimum:s,maximum:a,format:l,multipleOf:c,exclusiveMaximum:u,exclusiveMinimum:f}=n._zod.bag;typeof l=="string"&&l.includes("int")?i.type="integer":i.type="number",typeof f=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(i.minimum=f,i.exclusiveMinimum=!0):i.exclusiveMinimum=f),typeof s=="number"&&(i.minimum=s,typeof f=="number"&&t.target!=="draft-04"&&(f>=s?delete i.minimum:delete i.exclusiveMinimum)),typeof u=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(i.maximum=u,i.exclusiveMaximum=!0):i.exclusiveMaximum=u),typeof a=="number"&&(i.maximum=a,typeof u=="number"&&t.target!=="draft-04"&&(u<=a?delete i.maximum:delete i.exclusiveMaximum)),typeof c=="number"&&(i.multipleOf=c)},T3=(n,t,e,r)=>{e.type="boolean"},R3=(n,t,e,r)=>{e.not={}},C3=(n,t,e,r)=>{},I3=(n,t,e,r)=>{const i=n._zod.def,s=Q8(i.entries);s.every(a=>typeof a=="number")&&(e.type="number"),s.every(a=>typeof a=="string")&&(e.type="string"),e.enum=s},$3=(n,t,e,r)=>{const i=n._zod.def,s=[];for(const a of i.values)if(a===void 0){if(t.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof a=="bigint"){if(t.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");s.push(Number(a))}else s.push(a);if(s.length!==0)if(s.length===1){const a=s[0];e.type=a===null?"null":typeof a,t.target==="draft-04"||t.target==="openapi-3.0"?e.enum=[a]:e.const=a}else s.every(a=>typeof a=="number")&&(e.type="number"),s.every(a=>typeof a=="string")&&(e.type="string"),s.every(a=>typeof a=="boolean")&&(e.type="boolean"),s.every(a=>a===null)&&(e.type="null"),e.enum=s},x3=(n,t,e,r)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},P3=(n,t,e,r)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},D3=(n,t,e,r)=>{const i=e,s=n._zod.def,{minimum:a,maximum:l}=n._zod.bag;typeof a=="number"&&(i.minItems=a),typeof l=="number"&&(i.maxItems=l),i.type="array",i.items=Xe(s.element,t,{...r,path:[...r.path,"items"]})},L3=(n,t,e,r)=>{var u;const i=e,s=n._zod.def;i.type="object",i.properties={};const a=s.shape;for(const f in a)i.properties[f]=Xe(a[f],t,{...r,path:[...r.path,"properties",f]});const l=new Set(Object.keys(a)),c=new Set([...l].filter(f=>{const p=s.shape[f]._zod;return t.io==="input"?p.optin===void 0:p.optout===void 0}));c.size>0&&(i.required=Array.from(c)),((u=s.catchall)==null?void 0:u._zod.def.type)==="never"?i.additionalProperties=!1:s.catchall?s.catchall&&(i.additionalProperties=Xe(s.catchall,t,{...r,path:[...r.path,"additionalProperties"]})):t.io==="output"&&(i.additionalProperties=!1)},O3=(n,t,e,r)=>{const i=n._zod.def,s=i.inclusive===!1,a=i.options.map((l,c)=>Xe(l,t,{...r,path:[...r.path,s?"oneOf":"anyOf",c]}));s?e.oneOf=a:e.anyOf=a},M3=(n,t,e,r)=>{const i=n._zod.def,s=Xe(i.left,t,{...r,path:[...r.path,"allOf",0]}),a=Xe(i.right,t,{...r,path:[...r.path,"allOf",1]}),l=u=>"allOf"in u&&Object.keys(u).length===1,c=[...l(s)?s.allOf:[s],...l(a)?a.allOf:[a]];e.allOf=c},N3=(n,t,e,r)=>{const i=e,s=n._zod.def;i.type="object";const a=s.keyType,l=a._zod.bag,c=l==null?void 0:l.patterns;if(s.mode==="loose"&&c&&c.size>0){const f=Xe(s.valueType,t,{...r,path:[...r.path,"patternProperties","*"]});i.patternProperties={};for(const p of c)i.patternProperties[p.source]=f}else(t.target==="draft-07"||t.target==="draft-2020-12")&&(i.propertyNames=Xe(s.keyType,t,{...r,path:[...r.path,"propertyNames"]})),i.additionalProperties=Xe(s.valueType,t,{...r,path:[...r.path,"additionalProperties"]});const u=a._zod.values;if(u){const f=[...u].filter(p=>typeof p=="string"||typeof p=="number");f.length>0&&(i.required=f)}},z3=(n,t,e,r)=>{const i=n._zod.def,s=Xe(i.innerType,t,r),a=t.seen.get(n);t.target==="openapi-3.0"?(a.ref=i.innerType,e.nullable=!0):e.anyOf=[s,{type:"null"}]},U3=(n,t,e,r)=>{const i=n._zod.def;Xe(i.innerType,t,r);const s=t.seen.get(n);s.ref=i.innerType},H3=(n,t,e,r)=>{const i=n._zod.def;Xe(i.innerType,t,r);const s=t.seen.get(n);s.ref=i.innerType,e.default=JSON.parse(JSON.stringify(i.defaultValue))},Z3=(n,t,e,r)=>{const i=n._zod.def;Xe(i.innerType,t,r);const s=t.seen.get(n);s.ref=i.innerType,t.io==="input"&&(e._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},q3=(n,t,e,r)=>{const i=n._zod.def;Xe(i.innerType,t,r);const s=t.seen.get(n);s.ref=i.innerType;let a;try{a=i.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}e.default=a},V3=(n,t,e,r)=>{const i=n._zod.def,s=t.io==="input"?i.in._zod.def.type==="transform"?i.out:i.in:i.out;Xe(s,t,r);const a=t.seen.get(n);a.ref=s},F3=(n,t,e,r)=>{const i=n._zod.def;Xe(i.innerType,t,r);const s=t.seen.get(n);s.ref=i.innerType,e.readOnly=!0},A6=(n,t,e,r)=>{const i=n._zod.def;Xe(i.innerType,t,r);const s=t.seen.get(n);s.ref=i.innerType},B3=I("ZodISODateTime",(n,t)=>{jR.init(n,t),Ve.init(n,t)});function j3(n){return XC(B3,n)}const W3=I("ZodISODate",(n,t)=>{WR.init(n,t),Ve.init(n,t)});function G3(n){return QC(W3,n)}const J3=I("ZodISOTime",(n,t)=>{GR.init(n,t),Ve.init(n,t)});function Y3(n){return e3(J3,n)}const K3=I("ZodISODuration",(n,t)=>{JR.init(n,t),Ve.init(n,t)});function X3(n){return t3(K3,n)}const E6=(n,t)=>{r6.init(n,t),n.name="ZodError",Object.defineProperties(n,{format:{value:e=>UT(n,e)},flatten:{value:e=>zT(n,e)},addIssue:{value:e=>{n.issues.push(e),n.message=JSON.stringify(n.issues,eg,2)}},addIssues:{value:e=>{n.issues.push(...e),n.message=JSON.stringify(n.issues,eg,2)}},isEmpty:{get(){return n.issues.length===0}}})},N2=I("ZodError",E6),xn=I("ZodError",E6,{Parent:Error}),Q3=nv(xn),eI=rv(xn),tI=Ff(xn),nI=Bf(xn),rI=qT(xn),iI=VT(xn),sI=FT(xn),oI=BT(xn),aI=jT(xn),lI=WT(xn),cI=GT(xn),uI=JT(xn),qe=I("ZodType",(n,t)=>(Ze.init(n,t),Object.assign(n["~standard"],{jsonSchema:{input:Dd(n,"input"),output:Dd(n,"output")}}),n.toJSONSchema=_3(n,{}),n.def=t,n.type=t.type,Object.defineProperty(n,"_def",{value:t}),n.check=(...e)=>n.clone(Ls(t,{checks:[...t.checks??[],...e.map(r=>typeof r=="function"?{_zod:{check:r,def:{check:"custom"},onattach:[]}}:r)]}),{parent:!0}),n.with=n.check,n.clone=(e,r)=>Os(n,e,r),n.brand=()=>n,n.register=((e,r)=>(e.add(n,r),n)),n.parse=(e,r)=>Q3(n,e,r,{callee:n.parse}),n.safeParse=(e,r)=>tI(n,e,r),n.parseAsync=async(e,r)=>eI(n,e,r,{callee:n.parseAsync}),n.safeParseAsync=async(e,r)=>nI(n,e,r),n.spa=n.safeParseAsync,n.encode=(e,r)=>rI(n,e,r),n.decode=(e,r)=>iI(n,e,r),n.encodeAsync=async(e,r)=>sI(n,e,r),n.decodeAsync=async(e,r)=>oI(n,e,r),n.safeEncode=(e,r)=>aI(n,e,r),n.safeDecode=(e,r)=>lI(n,e,r),n.safeEncodeAsync=async(e,r)=>cI(n,e,r),n.safeDecodeAsync=async(e,r)=>uI(n,e,r),n.refine=(e,r)=>n.check(n$(e,r)),n.superRefine=e=>n.check(r$(e)),n.overwrite=e=>n.check(ec(e)),n.optional=()=>H2(n),n.exactOptional=()=>VI(n),n.nullable=()=>Z2(n),n.nullish=()=>H2(Z2(n)),n.nonoptional=e=>JI(n,e),n.array=()=>G(n),n.or=e=>ae([n,e]),n.and=e=>Wf(n,e),n.transform=e=>q2(n,ZI(e)),n.default=e=>jI(n,e),n.prefault=e=>GI(n,e),n.catch=e=>KI(n,e),n.pipe=e=>q2(n,e),n.readonly=()=>e$(n),n.describe=e=>{const r=n.clone();return $c.add(r,{description:e}),r},Object.defineProperty(n,"description",{get(){var e;return(e=$c.get(n))==null?void 0:e.description},configurable:!0}),n.meta=(...e)=>{if(e.length===0)return $c.get(n);const r=n.clone();return $c.add(r,e[0]),r},n.isOptional=()=>n.safeParse(void 0).success,n.isNullable=()=>n.safeParse(null).success,n.apply=e=>e(n),n)),k6=I("_ZodString",(n,t)=>{iv.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(r,i,s)=>E3(n,r,i);const e=n._zod.bag;n.format=e.format??null,n.minLength=e.minimum??null,n.maxLength=e.maximum??null,n.regex=(...r)=>n.check(a3(...r)),n.includes=(...r)=>n.check(u3(...r)),n.startsWith=(...r)=>n.check(h3(...r)),n.endsWith=(...r)=>n.check(d3(...r)),n.min=(...r)=>n.check(Pd(...r)),n.max=(...r)=>n.check(y6(...r)),n.length=(...r)=>n.check(w6(...r)),n.nonempty=(...r)=>n.check(Pd(1,...r)),n.lowercase=r=>n.check(l3(r)),n.uppercase=r=>n.check(c3(r)),n.trim=()=>n.check(p3()),n.normalize=(...r)=>n.check(f3(...r)),n.toLowerCase=()=>n.check(m3()),n.toUpperCase=()=>n.check(g3()),n.slugify=()=>n.check(v3())}),hI=I("ZodString",(n,t)=>{iv.init(n,t),k6.init(n,t),n.email=e=>n.check(xC(dI,e)),n.url=e=>n.check(MC(fI,e)),n.jwt=e=>n.check(KC(CI,e)),n.emoji=e=>n.check(NC(pI,e)),n.guid=e=>n.check(D2(z2,e)),n.uuid=e=>n.check(PC(Hh,e)),n.uuidv4=e=>n.check(DC(Hh,e)),n.uuidv6=e=>n.check(LC(Hh,e)),n.uuidv7=e=>n.check(OC(Hh,e)),n.nanoid=e=>n.check(zC(mI,e)),n.guid=e=>n.check(D2(z2,e)),n.cuid=e=>n.check(UC(gI,e)),n.cuid2=e=>n.check(HC(vI,e)),n.ulid=e=>n.check(ZC(yI,e)),n.base64=e=>n.check(GC(kI,e)),n.base64url=e=>n.check(JC(TI,e)),n.xid=e=>n.check(qC(wI,e)),n.ksuid=e=>n.check(VC(bI,e)),n.ipv4=e=>n.check(FC(SI,e)),n.ipv6=e=>n.check(BC(_I,e)),n.cidrv4=e=>n.check(jC(AI,e)),n.cidrv6=e=>n.check(WC(EI,e)),n.e164=e=>n.check(YC(RI,e)),n.datetime=e=>n.check(j3(e)),n.date=e=>n.check(G3(e)),n.time=e=>n.check(Y3(e)),n.duration=e=>n.check(X3(e))});function g(n){return $C(hI,n)}const Ve=I("ZodStringFormat",(n,t)=>{Me.init(n,t),k6.init(n,t)}),dI=I("ZodEmail",(n,t)=>{NR.init(n,t),Ve.init(n,t)}),z2=I("ZodGUID",(n,t)=>{OR.init(n,t),Ve.init(n,t)}),Hh=I("ZodUUID",(n,t)=>{MR.init(n,t),Ve.init(n,t)}),fI=I("ZodURL",(n,t)=>{zR.init(n,t),Ve.init(n,t)}),pI=I("ZodEmoji",(n,t)=>{UR.init(n,t),Ve.init(n,t)}),mI=I("ZodNanoID",(n,t)=>{HR.init(n,t),Ve.init(n,t)}),gI=I("ZodCUID",(n,t)=>{ZR.init(n,t),Ve.init(n,t)}),vI=I("ZodCUID2",(n,t)=>{qR.init(n,t),Ve.init(n,t)}),yI=I("ZodULID",(n,t)=>{VR.init(n,t),Ve.init(n,t)}),wI=I("ZodXID",(n,t)=>{FR.init(n,t),Ve.init(n,t)}),bI=I("ZodKSUID",(n,t)=>{BR.init(n,t),Ve.init(n,t)}),SI=I("ZodIPv4",(n,t)=>{YR.init(n,t),Ve.init(n,t)}),_I=I("ZodIPv6",(n,t)=>{KR.init(n,t),Ve.init(n,t)}),AI=I("ZodCIDRv4",(n,t)=>{XR.init(n,t),Ve.init(n,t)}),EI=I("ZodCIDRv6",(n,t)=>{QR.init(n,t),Ve.init(n,t)}),kI=I("ZodBase64",(n,t)=>{eC.init(n,t),Ve.init(n,t)}),TI=I("ZodBase64URL",(n,t)=>{nC.init(n,t),Ve.init(n,t)}),RI=I("ZodE164",(n,t)=>{rC.init(n,t),Ve.init(n,t)}),CI=I("ZodJWT",(n,t)=>{sC.init(n,t),Ve.init(n,t)}),T6=I("ZodNumber",(n,t)=>{f6.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(r,i,s)=>k3(n,r,i),n.gt=(r,i)=>n.check(O2(r,i)),n.gte=(r,i)=>n.check(Cm(r,i)),n.min=(r,i)=>n.check(Cm(r,i)),n.lt=(r,i)=>n.check(L2(r,i)),n.lte=(r,i)=>n.check(Rm(r,i)),n.max=(r,i)=>n.check(Rm(r,i)),n.int=r=>n.check(U2(r)),n.safe=r=>n.check(U2(r)),n.positive=r=>n.check(O2(0,r)),n.nonnegative=r=>n.check(Cm(0,r)),n.negative=r=>n.check(L2(0,r)),n.nonpositive=r=>n.check(Rm(0,r)),n.multipleOf=(r,i)=>n.check(M2(r,i)),n.step=(r,i)=>n.check(M2(r,i)),n.finite=()=>n;const e=n._zod.bag;n.minValue=Math.max(e.minimum??Number.NEGATIVE_INFINITY,e.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,n.maxValue=Math.min(e.maximum??Number.POSITIVE_INFINITY,e.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,n.isInt=(e.format??"").includes("int")||Number.isSafeInteger(e.multipleOf??.5),n.isFinite=!0,n.format=e.format??null});function ie(n){return n3(T6,n)}const II=I("ZodNumberFormat",(n,t)=>{oC.init(n,t),T6.init(n,t)});function U2(n){return r3(II,n)}const $I=I("ZodBoolean",(n,t)=>{aC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>T3(n,e,r)});function lt(n){return i3($I,n)}const xI=I("ZodUnknown",(n,t)=>{lC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>C3()});function E(){return s3(xI)}const PI=I("ZodNever",(n,t)=>{cC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>R3(n,e,r)});function DI(n){return o3(PI,n)}const LI=I("ZodArray",(n,t)=>{uC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>D3(n,e,r,i),n.element=t.element,n.min=(e,r)=>n.check(Pd(e,r)),n.nonempty=e=>n.check(Pd(1,e)),n.max=(e,r)=>n.check(y6(e,r)),n.length=(e,r)=>n.check(w6(e,r)),n.unwrap=()=>n.element});function G(n,t){return y3(LI,n,t)}const R6=I("ZodObject",(n,t)=>{dC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>L3(n,e,r,i),Ae(n,"shape",()=>t.shape),n.keyof=()=>sv(Object.keys(n._zod.def.shape)),n.catchall=e=>n.clone({...n._zod.def,catchall:e}),n.passthrough=()=>n.clone({...n._zod.def,catchall:E()}),n.loose=()=>n.clone({...n._zod.def,catchall:E()}),n.strict=()=>n.clone({...n._zod.def,catchall:DI()}),n.strip=()=>n.clone({...n._zod.def,catchall:void 0}),n.extend=e=>DT(n,e),n.safeExtend=e=>LT(n,e),n.merge=e=>OT(n,e),n.pick=e=>xT(n,e),n.omit=e=>PT(n,e),n.partial=(...e)=>MT(I6,n,e[0]),n.required=(...e)=>NT($6,n,e[0])});function ng(n,t){const e={type:"object",shape:n??{},...Y(t)};return new R6(e)}function b(n,t){return new R6({type:"object",shape:n,catchall:E(),...Y(t)})}const C6=I("ZodUnion",(n,t)=>{g6.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>O3(n,e,r,i),n.options=t.options});function ae(n,t){return new C6({type:"union",options:n,...Y(t)})}const OI=I("ZodDiscriminatedUnion",(n,t)=>{C6.init(n,t),fC.init(n,t)});function MI(n,t,e){return new OI({type:"union",options:t,discriminator:n,...Y(e)})}const NI=I("ZodIntersection",(n,t)=>{pC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>M3(n,e,r,i)});function Wf(n,t){return new NI({type:"intersection",left:n,right:t})}const zI=I("ZodRecord",(n,t)=>{mC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>N3(n,e,r,i),n.keyType=t.keyType,n.valueType=t.valueType});function T(n,t,e){return new zI({type:"record",keyType:n,valueType:t,...Y(e)})}const rg=I("ZodEnum",(n,t)=>{gC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(r,i,s)=>I3(n,r,i),n.enum=t.entries,n.options=Object.values(t.entries);const e=new Set(Object.keys(t.entries));n.extract=(r,i)=>{const s={};for(const a of r)if(e.has(a))s[a]=t.entries[a];else throw new Error(`Key ${a} not found in enum`);return new rg({...t,checks:[],...Y(i),entries:s})},n.exclude=(r,i)=>{const s={...t.entries};for(const a of r)if(e.has(a))delete s[a];else throw new Error(`Key ${a} not found in enum`);return new rg({...t,checks:[],...Y(i),entries:s})}});function sv(n,t){const e=Array.isArray(n)?Object.fromEntries(n.map(r=>[r,r])):n;return new rg({type:"enum",entries:e,...Y(t)})}const UI=I("ZodLiteral",(n,t)=>{vC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>$3(n,e,r),n.values=new Set(t.values),Object.defineProperty(n,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function D(n,t){return new UI({type:"literal",values:Array.isArray(n)?n:[n],...Y(t)})}const HI=I("ZodTransform",(n,t)=>{yC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>P3(n,e),n._zod.parse=(e,r)=>{if(r.direction==="backward")throw new K8(n.constructor.name);e.addIssue=s=>{if(typeof s=="string")e.issues.push(tu(s,e.value,t));else{const a=s;a.fatal&&(a.continue=!1),a.code??(a.code="custom"),a.input??(a.input=e.value),a.inst??(a.inst=n),e.issues.push(tu(a))}};const i=t.transform(e.value,e);return i instanceof Promise?i.then(s=>(e.value=s,e)):(e.value=i,e)}});function ZI(n){return new HI({type:"transform",transform:n})}const I6=I("ZodOptional",(n,t)=>{v6.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>A6(n,e,r,i),n.unwrap=()=>n._zod.def.innerType});function H2(n){return new I6({type:"optional",innerType:n})}const qI=I("ZodExactOptional",(n,t)=>{wC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>A6(n,e,r,i),n.unwrap=()=>n._zod.def.innerType});function VI(n){return new qI({type:"optional",innerType:n})}const FI=I("ZodNullable",(n,t)=>{bC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>z3(n,e,r,i),n.unwrap=()=>n._zod.def.innerType});function Z2(n){return new FI({type:"nullable",innerType:n})}const BI=I("ZodDefault",(n,t)=>{SC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>H3(n,e,r,i),n.unwrap=()=>n._zod.def.innerType,n.removeDefault=n.unwrap});function jI(n,t){return new BI({type:"default",innerType:n,get defaultValue(){return typeof t=="function"?t():t6(t)}})}const WI=I("ZodPrefault",(n,t)=>{_C.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>Z3(n,e,r,i),n.unwrap=()=>n._zod.def.innerType});function GI(n,t){return new WI({type:"prefault",innerType:n,get defaultValue(){return typeof t=="function"?t():t6(t)}})}const $6=I("ZodNonOptional",(n,t)=>{AC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>U3(n,e,r,i),n.unwrap=()=>n._zod.def.innerType});function JI(n,t){return new $6({type:"nonoptional",innerType:n,...Y(t)})}const YI=I("ZodCatch",(n,t)=>{EC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>q3(n,e,r,i),n.unwrap=()=>n._zod.def.innerType,n.removeCatch=n.unwrap});function KI(n,t){return new YI({type:"catch",innerType:n,catchValue:typeof t=="function"?t:()=>t})}const XI=I("ZodPipe",(n,t)=>{kC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>V3(n,e,r,i),n.in=t.in,n.out=t.out});function q2(n,t){return new XI({type:"pipe",in:n,out:t})}const QI=I("ZodReadonly",(n,t)=>{TC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>F3(n,e,r,i),n.unwrap=()=>n._zod.def.innerType});function e$(n){return new QI({type:"readonly",innerType:n})}const t$=I("ZodCustom",(n,t)=>{RC.init(n,t),qe.init(n,t),n._zod.processJSONSchema=(e,r,i)=>x3(n,e)});function n$(n,t={}){return w3(t$,n,t)}function r$(n){return b3(n)}const i$=[".md",".markdown"];function x6(n){if(n.length===0)return!1;const t=n.at(-1);return t==="/"||t==="\\"}function P6(n){const t=n.lastIndexOf("/"),e=n.lastIndexOf("\\");return n.slice(Math.max(t,e)+1)}function s$(n){return P6(n).toLowerCase()}function o$(n,t){const e=s$(n);return t.some(r=>e.endsWith(r))}function ig(n){return!x6(n)&&o$(n,i$)}function a$(n){let t;try{t=new URL(n)}catch{return!1}return t.protocol==="http:"||t.protocol==="https:"}function Vr(n){try{const{pathname:t}=new URL(n);return/^\/artifact\/[0-9A-Za-z]{26}(\/|$)/.test(t)}catch{return!1}}const l$=ng({id:g().min(1),kind:D("path"),title:g(),path:g(),store:g().optional(),share:ng({id:g().min(1),access:sv(["read","read-write"])}).strict().optional()}).strict(),c$=ng({id:g().min(1),kind:D("url"),title:g(),url:g().refine(a$,{message:"url must be an http(s) URL"})}).strict();MI("kind",[l$,c$]);const u$=new Set(["about:","blob:","chrome-extension:","chrome:","data:","devtools:","file:","filesystem:","javascript:","view-source:"]);function h$(n,t){try{const e=new URL(t),r=new URL(n,e);return r.protocol==="http:"||r.protocol==="https:"?{kind:"web",url:r.href}:u$.has(r.protocol)?{kind:"browser-local",url:r.href}:{kind:"application",url:r.href}}catch{return{kind:"invalid"}}}function V2(n,t){return h$(n,t).kind==="web"}const d$="/views/markdown/",f$="/views/url-unsupported/";function p$(n){try{const{protocol:t}=new URL(n);return t==="http:"||t==="https:"}catch{return!1}}function D6(n){return`/artifact/${encodeURIComponent(n)}`}function m$(n,t){return`${D6(n)}/${encodeURIComponent(t)}`}function g$(n){return`/markdown/${encodeURIComponent(n)}`}function Ld(n,t={electron:!1}){if(n.kind==="url")return t.electron?{renderer:"url-webview",viewURL:n.url,contentURL:null}:Vr(n.url)?{renderer:"proxy-iframe",viewURL:n.url,contentURL:null}:t.browserDemo&&p$(n.url)?{renderer:"url-direct",viewURL:n.url,contentURL:null}:{renderer:"url-unsupported",viewURL:f$,contentURL:null};if(ig(n.path)){const r={viewURL:d$,contentURL:g$(n.id)};return t.electron?{renderer:"url-webview",...r}:{renderer:"markdown",...r}}const e=x6(n.path)?`${D6(n.id)}/`:m$(n.id,P6(n.path));return t.electron?{renderer:"url-webview",viewURL:e,contentURL:null}:{renderer:"proxy-iframe",viewURL:e,contentURL:null}}const v$="serverURL",y$="token",w$="mode",b$="desktopAppVersion",S$="electron";function _$(n=window.location.search,t=window.location.origin){const r=new URLSearchParams(n).get(v$);return r?new URL(r).origin:new URL(t).origin}function A$(n=window.location.search){return new URLSearchParams(n).get(y$)}function wi(n=typeof window>"u"?"":window.location.search){return new URLSearchParams(n).get(w$)===S$}function L6(n=typeof window>"u"?"":window.location.search){return new URLSearchParams(n).get(b$)}const F2="tv.telemetry.clientId",E$=5,k$=60,T$=1e3,R$=E$*k$*T$,B2=["pointerdown","scroll","keydown"],j2=["focus"],W2=["visibilitychange"],C$="hidden";function I$(n,t=L$){const e=n.getItem(F2);if(e)return e;const r=t();return n.setItem(F2,r),r}function $$(n){return{clientId:I$(n.storage,n.idFactory),userAgent:n.userAgent??(typeof navigator>"u"?"":navigator.userAgent),clientApp:n.clientApp,...n.desktopAppVersion?{desktopAppVersion:n.desktopAppVersion}:{}}}function x$(n){const t=new URLSearchParams;return t.set("clientId",n.clientId),t.set("userAgent",n.userAgent),t.set("clientApp",n.clientApp),n.desktopAppVersion&&t.set("desktopAppVersion",n.desktopAppVersion),t}function P$(n){return new D$(n)}var cu,Gr,ji,uu,hu,vn,mo,du,Wd,O6;class D${constructor(t){m(this,Wd);m(this,cu);m(this,Gr);m(this,ji);m(this,uu);m(this,hu);m(this,vn);m(this,mo,!1);m(this,du,Number.NEGATIVE_INFINITY);d(this,cu,t.meta),d(this,Gr,t.documentTarget),d(this,ji,t.windowTarget),d(this,uu,t.send),d(this,hu,t.nowMs??Date.now),d(this,vn,()=>h(this,Wd,O6).call(this))}start(){if(!o(this,mo)){d(this,mo,!0);for(const t of B2)o(this,ji).addEventListener(t,o(this,vn)),o(this,Gr).addEventListener(t,o(this,vn));for(const t of j2)o(this,ji).addEventListener(t,o(this,vn));for(const t of W2)o(this,Gr).addEventListener(t,o(this,vn))}}stop(){if(o(this,mo)){d(this,mo,!1);for(const t of B2)o(this,ji).removeEventListener(t,o(this,vn)),o(this,Gr).removeEventListener(t,o(this,vn));for(const t of j2)o(this,ji).removeEventListener(t,o(this,vn));for(const t of W2)o(this,Gr).removeEventListener(t,o(this,vn))}}}cu=new WeakMap,Gr=new WeakMap,ji=new WeakMap,uu=new WeakMap,hu=new WeakMap,vn=new WeakMap,mo=new WeakMap,du=new WeakMap,Wd=new WeakSet,O6=function(){if(o(this,Gr).visibilityState===C$)return;const t=o(this,hu).call(this);t-o(this,du)<R$||(d(this,du,t),o(this,uu).call(this,{type:ak,clientId:o(this,cu).clientId}))};function L$(){return typeof crypto<"u"&&typeof crypto.randomUUID=="function"?crypto.randomUUID():X1().toLowerCase()}const De={authenticate:"authenticate",document_did_change:"document/didChange",document_did_close:"document/didClose",document_did_focus:"document/didFocus",document_did_open:"document/didOpen",document_did_save:"document/didSave",initialize:"initialize",logout:"logout",nes_accept:"nes/accept",nes_close:"nes/close",nes_reject:"nes/reject",nes_start:"nes/start",nes_suggest:"nes/suggest",session_cancel:"session/cancel",session_close:"session/close",session_fork:"session/fork",session_list:"session/list",session_load:"session/load",session_new:"session/new",session_prompt:"session/prompt",session_resume:"session/resume",session_set_config_option:"session/set_config_option",session_set_mode:"session/set_mode",session_set_model:"session/set_model"},Ur={fs_read_text_file:"fs/read_text_file",fs_write_text_file:"fs/write_text_file",session_request_permission:"session/request_permission",session_update:"session/update",terminal_create:"terminal/create",terminal_kill:"terminal/kill",terminal_output:"terminal/output",terminal_release:"terminal/release",terminal_wait_for_exit:"terminal/wait_for_exit"},O$=1,M$=b({_meta:T(g(),E()).nullish(),terminal:lt().optional().default(!1)}),N$=b({_meta:T(g(),E()).nullish(),label:g().nullish(),name:g(),optional:lt().optional().default(!1),secret:lt().optional().default(!0)}),z$=b({_meta:T(g(),E()).nullish(),description:g().nullish(),id:g(),name:g()}),U$=b({_meta:T(g(),E()).nullish(),description:g().nullish(),id:g(),link:g().nullish(),name:g(),vars:G(N$)}),H$=b({_meta:T(g(),E()).nullish(),args:G(g()).optional(),description:g().nullish(),env:T(g(),g()).optional(),id:g(),name:g()}),Z$=ae([U$.and(b({type:D("env_var")})),H$.and(b({type:D("terminal")})),z$]),q$=b({_meta:T(g(),E()).nullish(),methodId:g()}),V$=b({_meta:T(g(),E()).nullish()}),F$=b({_meta:T(g(),E()).nullish(),blob:g(),mimeType:g().nullish(),uri:g()}),B$=b({default:lt().nullish(),description:g().nullish(),title:g().nullish()}),j$=b({_meta:T(g(),E()).nullish()}),W$=b({_meta:T(g(),E()).nullish()}),G$=b({amount:ie(),currency:g()}),J$=b({_meta:T(g(),E()).nullish(),terminalId:g()}),Y$=b({_meta:T(g(),E()).nullish(),newText:g(),oldText:g().nullish(),path:g()}),K$=ae([g(),ie(),ie(),lt(),G(g())]),X$=b({content:T(g(),K$).nullish()}),Q$=ae([X$.and(b({action:D("accept")})),b({action:D("decline")}),b({action:D("cancel")})]),ex=b({_meta:T(g(),E()).nullish()}),M6=g(),tx=b({_meta:T(g(),E()).nullish(),elicitationId:M6}),nx=b({_meta:T(g(),E()).nullish(),action:Q$}),rx=D("object"),ix=D("string"),sx=b({_meta:T(g(),E()).nullish()}),ox=b({_meta:T(g(),E()).nullish(),form:ex.nullish(),url:sx.nullish()}),ax=b({elicitationId:M6,url:g().url()}),N6=b({const:g(),title:g()}),z6=b({_meta:T(g(),E()).nullish(),name:g(),value:g()}),lx=ae([D(-32700),D(-32600),D(-32601),D(-32602),D(-32603),D(-32800),D(-32e3),D(-32002),D(-32042),ie().int().min(-2147483648,{message:"Invalid value: Expected int32 to be >= -2147483648"}).max(2147483647,{message:"Invalid value: Expected int32 to be <= 2147483647"})]),U6=b({code:lx,data:E().optional(),message:g()}),H6=E(),Z6=E(),q6=E(),cx=b({_meta:T(g(),E()).nullish(),readTextFile:lt().optional().default(!1),writeTextFile:lt().optional().default(!1)}),V6=b({_meta:T(g(),E()).nullish(),name:g(),value:g()}),F6=b({_meta:T(g(),E()).nullish(),name:g(),title:g().nullish(),version:g()}),ux=b({default:ie().nullish(),description:g().nullish(),maximum:ie().nullish(),minimum:ie().nullish(),title:g().nullish()}),hx=b({_meta:T(g(),E()).nullish()}),dx=b({_meta:T(g(),E()).nullish(),additionalDirectories:G(g()).optional(),cursor:g().nullish(),cwd:g().nullish()}),fx=b({_meta:T(g(),E()).nullish()}),px=b({_meta:T(g(),E()).nullish(),logout:fx.nullish()}),mx=b({_meta:T(g(),E()).nullish()}),gx=b({_meta:T(g(),E()).nullish()}),vx=b({_meta:T(g(),E()).nullish(),http:lt().optional().default(!1),sse:lt().optional().default(!1)}),yx=b({_meta:T(g(),E()).nullish(),headers:G(V6),name:g(),url:g()}),wx=b({_meta:T(g(),E()).nullish(),headers:G(V6),name:g(),url:g()}),bx=b({_meta:T(g(),E()).nullish(),args:G(g()),command:g(),env:G(z6),name:g()}),Gf=ae([yx.and(b({type:D("http")})),wx.and(b({type:D("sse")})),bx]),ov=g(),Sx=b({_meta:T(g(),E()).nullish(),description:g().nullish(),modelId:ov,name:g()}),_x=ae([D("error"),D("warning"),D("information"),D("hint")]),Ax=b({_meta:T(g(),E()).nullish()}),Ex=b({_meta:T(g(),E()).nullish()}),kx=b({_meta:T(g(),E()).nullish()}),Tx=b({_meta:T(g(),E()).nullish()}),Rx=b({_meta:T(g(),E()).nullish()}),Cx=b({_meta:T(g(),E()).nullish(),maxCount:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish()}),Ix=b({diff:g(),uri:g()}),$x=b({endLine:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}),startLine:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}),text:g()}),xx=b({_meta:T(g(),E()).nullish()}),Px=b({_meta:T(g(),E()).nullish()}),Dx=b({languageId:g(),text:g(),uri:g()}),Lx=b({_meta:T(g(),E()).nullish(),maxCount:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish()}),Ox=ae([D("rejected"),D("ignored"),D("replaced"),D("cancelled")]),Mx=b({excerpts:G($x),uri:g()}),Nx=b({_meta:T(g(),E()).nullish()}),zx=b({_meta:T(g(),E()).nullish()}),Ux=b({name:g(),owner:g(),remoteUrl:g()}),Hx=b({_meta:T(g(),E()).nullish()}),Zx=b({_meta:T(g(),E()).nullish(),jump:xx.nullish(),rename:zx.nullish(),searchAndReplace:Hx.nullish()}),qx=b({id:g(),isRegex:lt().nullish(),replace:g(),search:g(),uri:g()}),Vx=ae([D("automatic"),D("diagnostic"),D("manual")]),Fx=b({_meta:T(g(),E()).nullish(),maxCount:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish()}),Bx=b({_meta:T(g(),E()).nullish(),diagnostics:Ax.nullish(),editHistory:Cx.nullish(),openFiles:Px.nullish(),recentFiles:Lx.nullish(),relatedSnippets:Nx.nullish(),userActions:Fx.nullish()}),jx=b({_meta:T(g(),E()).nullish(),additionalDirectories:G(g()).optional(),cwd:g(),mcpServers:G(Gf)}),Wx=b({default:ie().nullish(),description:g().nullish(),maximum:ie().nullish(),minimum:ie().nullish(),title:g().nullish()}),B6=g(),Gx=ae([D("allow_once"),D("allow_always"),D("reject_once"),D("reject_always")]),Jx=b({_meta:T(g(),E()).nullish(),kind:Gx,name:g(),optionId:B6}),Yx=ae([D("high"),D("medium"),D("low")]),Kx=ae([D("pending"),D("in_progress"),D("completed")]),Xx=b({_meta:T(g(),E()).nullish(),content:g(),priority:Yx,status:Kx}),Qx=b({_meta:T(g(),E()).nullish(),entries:G(Xx)}),xs=b({character:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}),line:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"})}),eP=b({id:g(),position:xs,uri:g()}),tP=b({id:g(),newName:g(),position:xs,uri:g()}),nP=b({action:g(),position:xs,timestampMs:ie(),uri:g()}),j6=ae([D("utf-16"),D("utf-32"),D("utf-8")]),rP=b({_meta:T(g(),E()).nullish(),auth:M$.optional().default({terminal:!1}),elicitation:ox.nullish(),fs:cx.optional().default({readTextFile:!1,writeTextFile:!1}),nes:Zx.nullish(),positionEncodings:G(j6).optional(),terminal:lt().optional().default(!1)}),iP=b({_meta:T(g(),E()).nullish(),audio:lt().optional().default(!1),embeddedContext:lt().optional().default(!1),image:lt().optional().default(!1)}),W6=ie().int().gte(0).lte(65535),sP=b({_meta:T(g(),E()).nullish(),clientCapabilities:rP.optional().default({auth:{terminal:!1},fs:{readTextFile:!1,writeTextFile:!1},terminal:!1}),clientInfo:F6.nullish(),protocolVersion:W6}),tc=b({end:xs,start:xs}),oP=b({message:g(),range:tc,severity:_x,uri:g()}),aP=b({languageId:g(),lastFocusedMs:ie().nullish(),uri:g(),visibleRange:tc.nullish()}),lP=b({_meta:T(g(),E()).nullish(),diagnostics:G(oP).nullish(),editHistory:G(Ix).nullish(),openFiles:G(aP).nullish(),recentFiles:G(Dx).nullish(),relatedSnippets:G(Mx).nullish(),userActions:G(nP).nullish()}),cP=b({newText:g(),range:tc}),uP=b({cursorPosition:xs.nullish(),edits:G(cP),id:g(),uri:g()}),hP=ae([uP.and(b({kind:D("edit")})),eP.and(b({kind:D("jump")})),tP.and(b({kind:D("rename")})),qx.and(b({kind:D("searchAndReplace")}))]),dP=b({_meta:T(g(),E()).nullish(),content:g()}),fP=b({_meta:T(g(),E()).nullish()}),ra=ae([ie(),g()]).nullable();b({_meta:T(g(),E()).nullish(),requestId:ra});const pP=sv(["assistant","user"]),_h=b({_meta:T(g(),E()).nullish(),audience:G(pP).nullish(),lastModified:g().nullish(),priority:ie().nullish()}),mP=b({_meta:T(g(),E()).nullish(),annotations:_h.nullish(),data:g(),mimeType:g()}),gP=b({_meta:T(g(),E()).nullish(),annotations:_h.nullish(),data:g(),mimeType:g(),uri:g().nullish()}),vP=b({_meta:T(g(),E()).nullish(),annotations:_h.nullish(),description:g().nullish(),mimeType:g().nullish(),name:g(),size:ie().nullish(),title:g().nullish(),uri:g()}),yP=b({_meta:T(g(),E()).nullish(),optionId:B6}),wP=ae([b({outcome:D("cancelled")}),yP.and(b({outcome:D("selected")}))]),bP=b({_meta:T(g(),E()).nullish(),outcome:wP}),SP=b({_meta:T(g(),E()).nullish()}),_P=b({_meta:T(g(),E()).nullish()}),AP=b({currentValue:lt()}),EP=g(),G6=g(),kP=ae([D("mode"),D("model"),D("thought_level"),g()]),av=g(),J6=b({_meta:T(g(),E()).nullish(),description:g().nullish(),name:g(),value:av}),TP=b({_meta:T(g(),E()).nullish(),group:EP,name:g(),options:G(J6)}),RP=ae([G(J6),G(TP)]),CP=b({currentValue:av,options:RP}),nc=Wf(ae([CP.and(b({type:D("select")})),AP.and(b({type:D("boolean")}))]),b({_meta:T(g(),E()).nullish(),category:kP.nullish(),description:g().nullish(),id:G6,name:g()})),IP=b({_meta:T(g(),E()).nullish(),configOptions:G(nc)}),$P=b({_meta:T(g(),E()).nullish()}),be=g(),xP=b({_meta:T(g(),E()).nullish(),id:g(),sessionId:be}),PP=b({_meta:T(g(),E()).nullish(),sessionId:be}),DP=b({_meta:T(g(),E()).nullish(),sessionId:be}),LP=b({_meta:T(g(),E()).nullish(),sessionId:be}),Y6=b({_meta:T(g(),E()).nullish(),args:G(g()).optional(),command:g(),cwd:g().nullish(),env:G(z6).optional(),outputByteLimit:ie().nullish(),sessionId:be}),OP=b({_meta:T(g(),E()).nullish(),sessionId:be,uri:g()}),MP=b({_meta:T(g(),E()).nullish(),position:xs,sessionId:be,uri:g(),version:ie(),visibleRange:tc}),NP=b({_meta:T(g(),E()).nullish(),languageId:g(),sessionId:be,text:g(),uri:g(),version:ie()}),zP=b({_meta:T(g(),E()).nullish(),sessionId:be,uri:g()}),UP=b({_meta:T(g(),E()).nullish(),additionalDirectories:G(g()).optional(),cwd:g(),mcpServers:G(Gf).optional(),sessionId:be}),K6=b({_meta:T(g(),E()).nullish(),sessionId:be,terminalId:g()}),HP=b({_meta:T(g(),E()).nullish(),additionalDirectories:G(g()).optional(),cwd:g(),mcpServers:G(Gf),sessionId:be}),X6=b({_meta:T(g(),E()).nullish(),limit:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),line:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),path:g(),sessionId:be}),ZP=b({_meta:T(g(),E()).nullish(),id:g(),reason:Ox.nullish(),sessionId:be}),Q6=b({_meta:T(g(),E()).nullish(),sessionId:be,terminalId:g()}),qP=b({_meta:T(g(),E()).nullish(),additionalDirectories:G(g()).optional(),cwd:g(),mcpServers:G(Gf).optional(),sessionId:be}),VP=b({_meta:T(g(),E()).nullish(),additionalDirectories:G(g()).optional(),cwd:g(),sessionId:be,title:g().nullish(),updatedAt:g().nullish()}),FP=b({_meta:T(g(),E()).nullish(),nextCursor:g().nullish(),sessions:G(VP)}),BP=b({_meta:T(g(),E()).nullish(),title:g().nullish(),updatedAt:g().nullish()}),jP=b({_meta:T(g(),E()).nullish()}),Jf=g(),WP=b({_meta:T(g(),E()).nullish(),currentModeId:Jf}),GP=b({_meta:T(g(),E()).nullish(),description:g().nullish(),id:Jf,name:g()}),Yf=b({_meta:T(g(),E()).nullish(),availableModes:G(GP),currentModeId:Jf}),Kf=b({_meta:T(g(),E()).nullish(),availableModels:G(Sx),currentModelId:ov}),JP=b({_meta:T(g(),E()).nullish(),configOptions:G(nc).nullish(),models:Kf.nullish(),modes:Yf.nullish(),sessionId:be}),YP=b({_meta:T(g(),E()).nullish(),configOptions:G(nc).nullish(),models:Kf.nullish(),modes:Yf.nullish()}),KP=b({_meta:T(g(),E()).nullish(),configOptions:G(nc).nullish(),models:Kf.nullish(),modes:Yf.nullish(),sessionId:be}),XP=b({_meta:T(g(),E()).nullish(),configOptions:G(nc).nullish(),models:Kf.nullish(),modes:Yf.nullish()}),QP=b({_meta:T(g(),E()).nullish()}),e5=b({_meta:T(g(),E()).nullish(),additionalDirectories:SP.nullish(),close:_P.nullish(),fork:$P.nullish(),list:jP.nullish(),resume:QP.nullish()}),t5=Wf(ae([b({type:D("boolean"),value:lt()}),b({value:av})]),b({_meta:T(g(),E()).nullish(),configId:G6,sessionId:be})),n5=b({_meta:T(g(),E()).nullish(),configOptions:G(nc)}),r5=b({_meta:T(g(),E()).nullish(),modeId:Jf,sessionId:be}),i5=b({_meta:T(g(),E()).nullish()}),s5=b({_meta:T(g(),E()).nullish(),modelId:ov,sessionId:be}),o5=b({_meta:T(g(),E()).nullish()}),a5=b({_meta:T(g(),E()).nullish(),sessionId:be}),l5=ae([D("end_turn"),D("max_tokens"),D("max_turn_requests"),D("refusal"),D("cancelled")]),c5=ae([D("email"),D("uri"),D("date"),D("date-time")]),u5=b({default:g().nullish(),description:g().nullish(),enum:G(g()).nullish(),format:c5.nullish(),maxLength:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),minLength:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),oneOf:G(N6).nullish(),pattern:g().nullish(),title:g().nullish()}),h5=b({_meta:T(g(),E()).nullish(),context:lP.nullish(),position:xs,selection:tc.nullish(),sessionId:be,triggerKind:Vx,uri:g(),version:ie()}),d5=b({_meta:T(g(),E()).nullish(),suggestions:G(hP)}),f5=b({_meta:T(g(),E()).nullish(),terminalId:g()}),p5=b({_meta:T(g(),E()).nullish(),exitCode:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),signal:g().nullish()}),eS=b({_meta:T(g(),E()).nullish(),sessionId:be,terminalId:g()}),m5=b({_meta:T(g(),E()).nullish(),exitStatus:p5.nullish(),output:g(),truncated:lt()}),g5=b({_meta:T(g(),E()).nullish(),annotations:_h.nullish(),text:g()}),v5=b({range:tc.nullish(),text:g()}),y5=b({_meta:T(g(),E()).nullish(),contentChanges:G(v5),sessionId:be,uri:g(),version:ie()});b({method:g(),params:ae([PP,NP,y5,OP,zP,MP,xP,ZP,H6]).nullish()});const w5=ae([D("full"),D("incremental")]),b5=b({_meta:T(g(),E()).nullish(),syncKind:w5}),S5=b({_meta:T(g(),E()).nullish(),didChange:b5.nullish(),didClose:Ex.nullish(),didFocus:kx.nullish(),didOpen:Tx.nullish(),didSave:Rx.nullish()}),_5=b({_meta:T(g(),E()).nullish(),document:S5.nullish()}),A5=b({_meta:T(g(),E()).nullish(),context:Bx.nullish(),events:_5.nullish()}),E5=b({_meta:T(g(),E()).nullish(),auth:px.optional().default({}),loadSession:lt().optional().default(!1),mcpCapabilities:vx.optional().default({http:!1,sse:!1}),nes:A5.nullish(),positionEncoding:j6.nullish(),promptCapabilities:iP.optional().default({audio:!1,embeddedContext:!1,image:!1}),sessionCapabilities:e5.optional().default({})}),k5=b({_meta:T(g(),E()).nullish(),agentCapabilities:E5.optional().default({auth:{},loadSession:!1,mcpCapabilities:{http:!1,sse:!1},promptCapabilities:{audio:!1,embeddedContext:!1,image:!1},sessionCapabilities:{}}),agentInfo:F6.nullish(),authMethods:G(Z$).optional().default([]),protocolVersion:W6}),T5=b({_meta:T(g(),E()).nullish(),mimeType:g().nullish(),text:g(),uri:g()}),R5=ae([T5,F$]),C5=b({_meta:T(g(),E()).nullish(),annotations:_h.nullish(),resource:R5}),lv=ae([g5.and(b({type:D("text")})),gP.and(b({type:D("image")})),mP.and(b({type:D("audio")})),vP.and(b({type:D("resource_link")})),C5.and(b({type:D("resource")}))]),I5=b({_meta:T(g(),E()).nullish(),content:lv}),Im=b({_meta:T(g(),E()).nullish(),content:lv,messageId:g().nullish()}),$5=b({_meta:T(g(),E()).nullish(),messageId:g().nullish(),prompt:G(lv),sessionId:be}),x5=b({anyOf:G(N6)}),tS=ae([I5.and(b({type:D("content")})),Y$.and(b({type:D("diff")})),f5.and(b({type:D("terminal")}))]),nS=g(),rS=b({_meta:T(g(),E()).nullish(),line:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),path:g()}),iS=ae([D("pending"),D("in_progress"),D("completed"),D("failed")]),sS=ae([D("read"),D("edit"),D("delete"),D("move"),D("search"),D("execute"),D("think"),D("fetch"),D("switch_mode"),D("other")]),P5=b({_meta:T(g(),E()).nullish(),content:G(tS).optional(),kind:sS.optional(),locations:G(rS).optional(),rawInput:E().optional(),rawOutput:E().optional(),status:iS.optional(),title:g(),toolCallId:nS}),oS=b({_meta:T(g(),E()).nullish(),content:G(tS).nullish(),kind:sS.nullish(),locations:G(rS).nullish(),rawInput:E().optional(),rawOutput:E().optional(),status:iS.nullish(),title:g().nullish(),toolCallId:nS}),aS=b({_meta:T(g(),E()).nullish(),options:G(Jx),sessionId:be,toolCall:oS}),D5=b({_meta:T(g(),E()).nullish(),hint:g()}),L5=D5,O5=b({_meta:T(g(),E()).nullish(),description:g(),input:L5.nullish(),name:g()}),M5=b({_meta:T(g(),E()).nullish(),availableCommands:G(O5)}),N5=b({enum:G(g()),type:ix}),z5=ae([N5,x5]),U5=b({default:G(g()).nullish(),description:g().nullish(),items:z5,maxItems:ie().nullish(),minItems:ie().nullish(),title:g().nullish()}),H5=ae([u5.and(b({type:D("string")})),Wx.and(b({type:D("number")})),ux.and(b({type:D("integer")})),B$.and(b({type:D("boolean")})),U5.and(b({type:D("array")}))]),Z5=b({description:g().nullish(),properties:T(g(),H5).optional().default({}),required:G(g()).nullish(),title:g().nullish(),type:rx.optional().default("object")}),q5=b({requestedSchema:Z5}),V5=Wf(ae([q5.and(b({mode:D("form")})),ax.and(b({mode:D("url")}))]),b({_meta:T(g(),E()).nullish(),message:g(),sessionId:be})),F5=b({cachedReadTokens:ie().nullish(),cachedWriteTokens:ie().nullish(),inputTokens:ie(),outputTokens:ie(),thoughtTokens:ie().nullish(),totalTokens:ie()}),B5=b({_meta:T(g(),E()).nullish(),stopReason:l5,usage:F5.nullish(),userMessageId:g().nullish()});ae([b({id:ra,result:ae([k5,V$,gx,KP,YP,FP,JP,XP,W$,i5,n5,B5,o5,a5,d5,j$,q6])}),b({error:U6,id:ra})]);const j5=b({_meta:T(g(),E()).nullish(),cost:G$.nullish(),size:ie(),used:ie()}),W5=ae([Im.and(b({sessionUpdate:D("user_message_chunk")})),Im.and(b({sessionUpdate:D("agent_message_chunk")})),Im.and(b({sessionUpdate:D("agent_thought_chunk")})),P5.and(b({sessionUpdate:D("tool_call")})),oS.and(b({sessionUpdate:D("tool_call_update")})),Qx.and(b({sessionUpdate:D("plan")})),M5.and(b({sessionUpdate:D("available_commands_update")})),WP.and(b({sessionUpdate:D("current_mode_update")})),IP.and(b({sessionUpdate:D("config_option_update")})),BP.and(b({sessionUpdate:D("session_info_update")})),j5.and(b({sessionUpdate:D("usage_update")}))]),lS=b({_meta:T(g(),E()).nullish(),sessionId:be,update:W5});b({method:g(),params:ae([lS,tx,H6]).nullish()});const cS=b({_meta:T(g(),E()).nullish(),sessionId:be,terminalId:g()}),G5=b({_meta:T(g(),E()).nullish(),exitCode:ie().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),signal:g().nullish()}),J5=b({name:g(),uri:g()}),Y5=b({_meta:T(g(),E()).nullish(),repository:Ux.nullish(),workspaceFolders:G(J5).nullish(),workspaceUri:g().nullish()});b({id:ra,method:g(),params:ae([sP,q$,mx,jx,HP,dx,UP,qP,LP,r5,t5,$5,s5,Y5,h5,DP,Z6]).nullish()});const uS=b({_meta:T(g(),E()).nullish(),content:g(),path:g(),sessionId:be});b({id:ra,method:g(),params:ae([uS,X6,aS,Y6,eS,Q6,cS,K6,V5,Z6]).nullish()});const K5=b({_meta:T(g(),E()).nullish()});ae([b({id:ra,result:ae([K5,dP,bP,J$,m5,fP,G5,hx,nx,q6])}),b({error:U6,id:ra})]);var we;class X5{constructor(t,e){m(this,we);const r=t(this),i=async(a,l)=>{var c,u,f,p,y,v,S;switch(a){case Ur.fs_write_text_file:{const _=uS.parse(l);return(c=r.writeTextFile)==null?void 0:c.call(r,_)}case Ur.fs_read_text_file:{const _=X6.parse(l);return(u=r.readTextFile)==null?void 0:u.call(r,_)}case Ur.session_request_permission:{const _=aS.parse(l);return r.requestPermission(_)}case Ur.terminal_create:{const _=Y6.parse(l);return(f=r.createTerminal)==null?void 0:f.call(r,_)}case Ur.terminal_output:{const _=eS.parse(l);return(p=r.terminalOutput)==null?void 0:p.call(r,_)}case Ur.terminal_release:{const _=Q6.parse(l);return await((y=r.releaseTerminal)==null?void 0:y.call(r,_))??{}}case Ur.terminal_wait_for_exit:{const _=cS.parse(l);return(v=r.waitForTerminalExit)==null?void 0:v.call(r,_)}case Ur.terminal_kill:{const _=K6.parse(l);return await((S=r.killTerminal)==null?void 0:S.call(r,_))??{}}default:if(r.extMethod)return r.extMethod(a,l);throw rt.methodNotFound(a)}},s=async(a,l)=>{switch(a){case Ur.session_update:{const c=lS.parse(l);return r.sessionUpdate(c)}default:if(r.extNotification)return r.extNotification(a,l);throw rt.methodNotFound(a)}};d(this,we,new Q5(i,s,e))}async initialize(t){return await o(this,we).sendRequest(De.initialize,t)}async newSession(t){return await o(this,we).sendRequest(De.session_new,t)}async loadSession(t){return await o(this,we).sendRequest(De.session_load,t)??{}}async unstable_forkSession(t){return await o(this,we).sendRequest(De.session_fork,t)}async listSessions(t){return await o(this,we).sendRequest(De.session_list,t)}async unstable_resumeSession(t){return await o(this,we).sendRequest(De.session_resume,t)}async unstable_closeSession(t){return await o(this,we).sendRequest(De.session_close,t)}async setSessionMode(t){return await o(this,we).sendRequest(De.session_set_mode,t)??{}}async unstable_setSessionModel(t){return await o(this,we).sendRequest(De.session_set_model,t)??{}}async setSessionConfigOption(t){return await o(this,we).sendRequest(De.session_set_config_option,t)}async authenticate(t){return await o(this,we).sendRequest(De.authenticate,t)??{}}async unstable_logout(t){return await o(this,we).sendRequest(De.logout,t)??{}}async prompt(t){return await o(this,we).sendRequest(De.session_prompt,t)}async cancel(t){return await o(this,we).sendNotification(De.session_cancel,t)}async unstable_startNes(t){return await o(this,we).sendRequest(De.nes_start,t)}async unstable_suggestNes(t){return await o(this,we).sendRequest(De.nes_suggest,t)}async unstable_closeNes(t){return await o(this,we).sendRequest(De.nes_close,t)??{}}async unstable_didOpenDocument(t){return await o(this,we).sendNotification(De.document_did_open,t)}async unstable_didChangeDocument(t){return await o(this,we).sendNotification(De.document_did_change,t)}async unstable_didCloseDocument(t){return await o(this,we).sendNotification(De.document_did_close,t)}async unstable_didSaveDocument(t){return await o(this,we).sendNotification(De.document_did_save,t)}async unstable_didFocusDocument(t){return await o(this,we).sendNotification(De.document_did_focus,t)}async unstable_acceptNes(t){return await o(this,we).sendNotification(De.nes_accept,t)}async unstable_rejectNes(t){return await o(this,we).sendNotification(De.nes_reject,t)}async extMethod(t,e){return await o(this,we).sendRequest(t,e)}async extNotification(t,e){return await o(this,we).sendNotification(t,e)}get signal(){return o(this,we).signal}get closed(){return o(this,we).closed}}we=new WeakMap;var Wi,Gd,fu,pu,Ba,ja,ar,mu,He,hS,sg,dS,fS,pS,mS,og,xc;class Q5{constructor(t,e,r){m(this,He);m(this,Wi,new Map);m(this,Gd,0);m(this,fu);m(this,pu);m(this,Ba);m(this,ja,Promise.resolve());m(this,ar,new AbortController);m(this,mu);d(this,fu,t),d(this,pu,e),d(this,Ba,r),d(this,mu,new Promise(i=>{o(this,ar).signal.addEventListener("abort",()=>i())})),h(this,He,hS).call(this)}get signal(){return o(this,ar).signal}get closed(){return o(this,mu)}async sendRequest(t,e){h(this,He,og).call(this);const r=Lh(this,Gd)._++,i=new Promise((s,a)=>{o(this,Wi).set(r,{resolve:s,reject:a})});return await h(this,He,xc).call(this,{jsonrpc:"2.0",id:r,method:t,params:e}),i}async sendNotification(t,e){h(this,He,og).call(this),await h(this,He,xc).call(this,{jsonrpc:"2.0",method:t,params:e})}}Wi=new WeakMap,Gd=new WeakMap,fu=new WeakMap,pu=new WeakMap,Ba=new WeakMap,ja=new WeakMap,ar=new WeakMap,mu=new WeakMap,He=new WeakSet,hS=async function(){let t;try{const e=o(this,Ba).readable.getReader();try{for(;!o(this,ar).signal.aborted;){const{value:r,done:i}=await e.read();if(i)break;if(r)try{h(this,He,dS).call(this,r)}catch(s){console.error("Unexpected error during message processing:",r,s),"id"in r&&r.id!==void 0&&h(this,He,xc).call(this,{jsonrpc:"2.0",id:r.id,error:{code:-32700,message:"Parse error"}})}}}finally{e.releaseLock()}}catch(e){t=e}finally{h(this,He,sg).call(this,t)}},sg=function(t){if(o(this,ar).signal.aborted)return;const e=t??new Error("ACP connection closed");for(const r of o(this,Wi).values())r.reject(e);o(this,Wi).clear(),o(this,ar).abort(e)},dS=async function(t){if("method"in t&&"id"in t){const e=await h(this,He,fS).call(this,t.method,t.params);"error"in e&&console.error("Error handling request",t,e.error),await h(this,He,xc).call(this,{jsonrpc:"2.0",id:t.id,...e})}else if("method"in t){const e=await h(this,He,pS).call(this,t.method,t.params);"error"in e&&console.error("Error handling notification",t,e.error)}else"id"in t?h(this,He,mS).call(this,t):console.error("Invalid message",{message:t})},fS=async function(t,e){try{return{result:await o(this,fu).call(this,t,e)??null}}catch(r){if(r instanceof rt)return r.toResult();if(r instanceof N2)return rt.invalidParams(r.format()).toResult();let i;(r instanceof Error||typeof r=="object"&&r!=null&&"message"in r&&typeof r.message=="string")&&(i=r.message);try{return rt.internalError(i?JSON.parse(i):{}).toResult()}catch{return rt.internalError({details:i}).toResult()}}},pS=async function(t,e){try{return await o(this,pu).call(this,t,e),{result:null}}catch(r){if(r instanceof rt)return r.toResult();if(r instanceof N2)return rt.invalidParams(r.format()).toResult();let i;(r instanceof Error||typeof r=="object"&&r!=null&&"message"in r&&typeof r.message=="string")&&(i=r.message);try{return rt.internalError(i?JSON.parse(i):{}).toResult()}catch{return rt.internalError({details:i}).toResult()}}},mS=function(t){const e=o(this,Wi).get(t.id);if(e){if("result"in t)e.resolve(t.result);else if("error"in t){const{code:r,message:i,data:s}=t.error;e.reject(new rt(r,i,s))}o(this,Wi).delete(t.id)}else console.error("Got response to unknown request",t.id)},og=function(){if(o(this,ar).signal.aborted)throw o(this,ar).signal.reason??new Error("ACP connection closed")},xc=async function(t){return d(this,ja,o(this,ja).then(async()=>{const e=o(this,Ba).writable.getWriter();try{await e.write(t)}finally{e.releaseLock()}}).catch(e=>{h(this,He,sg).call(this,e)})),o(this,ja)};class rt extends Error{constructor(e,r,i){super(r);C(this,"code");C(this,"data");this.code=e,this.name="RequestError",this.data=i}static parseError(e,r){return new rt(-32700,`Parse error${r?`: ${r}`:""}`,e)}static invalidRequest(e,r){return new rt(-32600,`Invalid request${r?`: ${r}`:""}`,e)}static methodNotFound(e){return new rt(-32601,`"Method not found": ${e}`,{method:e})}static invalidParams(e,r){return new rt(-32602,`Invalid params${r?`: ${r}`:""}`,e)}static internalError(e,r){return new rt(-32603,`Internal error${r?`: ${r}`:""}`,e)}static authRequired(e,r){return new rt(-32e3,`Authentication required${r?`: ${r}`:""}`,e)}static resourceNotFound(e){return new rt(-32002,`Resource not found${e?`: ${e}`:""}`,e&&{uri:e})}toResult(){return{error:{code:this.code,message:this.message,data:this.data}}}toErrorResponse(){return{code:this.code,message:this.message,data:this.data}}}function eD(n,t,e){const r=n.dispose.bind(n);n.dispose=(()=>{if(!t())return e(),r()})}function gS(n){var e;class t extends n{constructor(...s){super(...s);m(this,e,!1);eD(this,()=>o(this,e),()=>{d(this,e,!0)})}[Symbol.dispose](){this.dispose()}get disposed(){return o(this,e)}}return e=new WeakMap,t}const tD=/^Sender \(untrusted metadata\):\n```json\n[\s\S]*?\n```\n\n?/,nD=/^\[[^\n]*Working directory:[^\n]*\]\n\n?/,rD=/\[Television channel context\][\s\S]*?\[\/Television channel context\]\n*/,iD=/\b(tv|television|channel|artifact|artifacts|viewer|filmstrip|layout|focus)\b/i,sD=/^[A-Za-z0-9_@%+=:,./-]+$/,oD=/\[\[\s*(?:reply_to_current|reply_to\s*:\s*[^\]\n]+|audio_as_voice)\s*\]\]\s*/gi,aD="single_session",lD={name:"television-acp-client",version:"0.0.0"},vS="agent:main:television",cD=gS(Ri);var Wa,lr,nn,cr,Gi,Nn,Jr,ur,zn,Ji,Un,Ga,Ja,hr,Et,Yr,Ya,go,Kr,Yi,gu,Hn,dr,Jd,fr,O,ag,yS,wS,bS,Qh,SS,_S,AS,ES,kS,TS,RS,Gs,Aa,Ea,Zr,CS,ka,lg,cg,ed,IS,td,ug,hg,vu,yu,nd,Ta,dg,$S;class uD extends cD{constructor(e){super();m(this,O);m(this,Wa,"disconnected");m(this,lr,null);m(this,nn,new Map);m(this,cr,null);m(this,Gi,null);m(this,Nn,null);m(this,Jr,null);m(this,ur,null);m(this,zn,null);m(this,Ji);m(this,Un,null);m(this,Ga,0);m(this,Ja,1);m(this,hr,null);m(this,Et,null);m(this,Yr,!1);m(this,Ya,!1);m(this,go,!1);m(this,Kr,null);m(this,Yi,new Set);m(this,gu);m(this,Hn);m(this,dr);m(this,Jd,e=>{h(this,O,wS).call(this,e)});m(this,fr,null);m(this,vu,()=>{h(this,O,Ta).call(this,"ACP bridge websocket closed")});m(this,yu,()=>{h(this,O,Ta).call(this,"ACP bridge websocket error")});d(this,Hn,e),d(this,dr,e.sessionMode??aD),d(this,Ji,e.mappedSessionStore??hD()),d(this,gu,e.createSocket??(r=>new WebSocket(r)))}get status(){return o(this,Wa)}get messages(){return[...o(this,nn).values()]}get enabled(){return o(this,Hn).enabled??!1}setToken(e){o(this,Hn).token=e??""}setEnabled(e){o(this,Hn).enabled=e,e||(h(this,O,nd).call(this),d(this,lr,null),h(this,O,Zr).call(this,"disconnected"))}async connect(){if(this.disposed)throw new Error("ACPClient has been disposed");if(this.enabled&&this.status==="disconnected"){o(this,Gi)===null&&(d(this,lr,null),d(this,Gi,h(this,O,yS).call(this)));try{await o(this,Gi),await h(this,O,Qh).call(this)}catch(e){throw h(this,O,Ta).call(this,$m(e)),e}}}dispose(){h(this,O,nd).call(this),d(this,lr,null),h(this,O,Zr).call(this,"disposed")}async sendMessage(e){if(await this.connect(),(this.status==="running"||this.status==="cancelling")&&(await this.cancel(),await h(this,O,ag).call(this,"ready")),(o(this,ur)===null||o(this,Un)!==h(this,O,td).call(this))&&await h(this,O,Qh).call(this),this.status!=="ready")throw new Error("ACPClient is not ready to send a new message");const r=e.text.trim();if(!r)throw new Error("Cannot send an empty message");h(this,O,Aa).call(this,{id:h(this,O,ka).call(this,"user"),kind:"user",text:r,status:"final"}),h(this,O,Zr).call(this,"running");try{const i=await h(this,O,ed).call(this).prompt({sessionId:h(this,O,cg).call(this),prompt:[{type:"text",text:h(this,O,CS).call(this,r)}]});h(this,O,Gs).call(this,i.stopReason==="cancelled"?"cancelled":"final"),h(this,O,Zr).call(this,"ready")}catch(i){throw h(this,O,$S).call(this)||(h(this,O,Gs).call(this,"error"),h(this,O,Zr).call(this,"ready")),i}}async startNewSession(){var r;await this.connect(),(this.status==="running"||this.status==="cancelling")&&(await this.cancel(),await h(this,O,ag).call(this,"ready"));const e=h(this,O,td).call(this);((r=o(this,zn))==null?void 0:r.sessionIdStrategy)==="mapped"?o(this,Ji).clearActualSessionId(e):d(this,Ga,o(this,Ga)+1),d(this,Nn,null),d(this,Jr,null),d(this,ur,null),d(this,Un,null),h(this,O,dg).call(this)}async cancel(){this.status==="running"&&(h(this,O,Zr).call(this,"cancelling"),await h(this,O,ed).call(this).cancel({sessionId:h(this,O,cg).call(this)}))}setChannelContext(e){var s,a,l;if(e===null){if(o(this,Et)===null)return;d(this,Et,null),d(this,Yr,!1);return}const r={channelID:e.channelID,channelName:e.channelName};if(((s=o(this,Et))==null?void 0:s.channelID)===r.channelID&&((a=o(this,Et))==null?void 0:a.channelName)===r.channelName)return;const i=((l=o(this,Et))==null?void 0:l.channelID)??null;if(d(this,Et,r),o(this,dr)==="single_session"){(!o(this,Un)||i!==r.channelID)&&d(this,Yr,!0);return}o(this,Un)!==h(this,O,ug).call(this,r.channelID)&&(d(this,Nn,null),d(this,Jr,null),o(this,cr)&&this.status==="ready"&&h(this,O,Qh).call(this).catch(c=>{h(this,O,Ta).call(this,$m(c))}))}}Wa=new WeakMap,lr=new WeakMap,nn=new WeakMap,cr=new WeakMap,Gi=new WeakMap,Nn=new WeakMap,Jr=new WeakMap,ur=new WeakMap,zn=new WeakMap,Ji=new WeakMap,Un=new WeakMap,Ga=new WeakMap,Ja=new WeakMap,hr=new WeakMap,Et=new WeakMap,Yr=new WeakMap,Ya=new WeakMap,go=new WeakMap,Kr=new WeakMap,Yi=new WeakMap,gu=new WeakMap,Hn=new WeakMap,dr=new WeakMap,Jd=new WeakMap,fr=new WeakMap,O=new WeakSet,ag=async function(e){if(this.status!==e){if(this.status==="disposed")throw new Error("ACPClient has been disposed");if(this.status==="disconnected")throw new Error(o(this,lr)??"ACPClient is disconnected");await new Promise((r,i)=>{const s=()=>{this.removeEventListener("status-changed",a)},a=()=>{if(this.status===e){s(),r();return}if(this.status==="disposed"){s(),i(new Error("ACPClient has been disposed"));return}this.status==="disconnected"&&(s(),i(new Error(o(this,lr)??"ACPClient is disconnected")))};this.addEventListener("status-changed",a)})}},yS=async function(){try{const{stream:e,socket:r,metadata:i}=await mD({serverURL:o(this,Hn).serverURL,token:o(this,Hn).token,createSocket:o(this,gu),onDisconnect:o(this,Jd)});d(this,zn,i),d(this,fr,r),r.addEventListener("close",o(this,vu)),r.addEventListener("error",o(this,yu)),d(this,cr,new X5(s=>({connection:s,sessionUpdate:async a=>{await h(this,O,_S).call(this,a)},requestPermission:async a=>h(this,O,AS).call(this,a)}),e)),await o(this,cr).initialize({protocolVersion:O$,clientCapabilities:{},clientInfo:lD})}catch(e){throw e}},wS=function(e){h(this,O,Ta).call(this,$m(e))},bS=function(e){const r=e==null?void 0:e.models;if(!(r!=null&&r.currentModelId))return;const i=r.availableModels.find(s=>s.modelId===r.currentModelId);console.info("[ACPClient] Current model:",(i==null?void 0:i.name)??r.currentModelId,`(${r.currentModelId})`)},Qh=async function(){const e=h(this,O,td).call(this);if(o(this,Nn)&&o(this,Jr)===e){await o(this,Nn);return}d(this,Jr,e),d(this,Nn,h(this,O,SS).call(this,e)),await o(this,Nn)},SS=async function(e){var c;const r=h(this,O,ed).call(this);h(this,O,dg).call(this);let i,s=!1,a=null;const l={cwd:h(this,O,IS).call(this),mcpServers:[],_meta:{sessionKey:e}};try{if(d(this,go,!0),d(this,Kr,null),((c=o(this,zn))==null?void 0:c.sessionIdStrategy)==="mapped"){const u=o(this,Ji).getActualSessionId(e);if(u)try{const f=await r.loadSession({...l,sessionId:u});if(dD(f))throw new Error("Mapped ACP session was not found");a=f,i=u,s=!0}catch{const f=await r.newSession(l);a=f,i=f.sessionId,o(this,Ji).setActualSessionId(e,i),s=!1}else{const f=await r.newSession(l);a=f,i=f.sessionId,o(this,Ji).setActualSessionId(e,i),s=!1}}else try{a=await r.loadSession({...l,sessionId:e}),i=e,s=o(this,nn).size>0}catch{const u=await r.newSession(l);a=u,i=u.sessionId,s=!1}}finally{d(this,go,!1),d(this,Kr,null),h(this,O,Gs).call(this,"final")}h(this,O,bS).call(this,a),await r.setSessionConfigOption({sessionId:i,configId:"verbose_level",value:"full"}),d(this,ur,i),d(this,Un,e),d(this,Ya,!0),s?(o(this,Yi).add(e),o(this,dr)==="single_session"&&d(this,Yr,!1)):(o(this,Yi).delete(e),d(this,Yr,o(this,dr)==="single_session")),d(this,lr,null),h(this,O,Zr).call(this,"ready")},_S=async function(e){const r=e.update;switch(r.sessionUpdate){case"user_message_chunk":r.content.type==="text"&&h(this,O,RS).call(this,r.content.text);return;case"agent_message_chunk":r.content.type==="text"&&h(this,O,ES).call(this,r.content.text);return;case"tool_call":h(this,O,kS).call(this,r);return;case"tool_call_update":h(this,O,TS).call(this,r);return;case"agent_thought_chunk":return;default:return}},AS=async function(e){return{outcome:{outcome:"cancelled"}}},ES=function(e){d(this,Kr,null);const r=pD(e);if(!r)return;if(!o(this,hr)){const s={id:h(this,O,ka).call(this,"assistant"),kind:"assistant",text:r,status:"streaming"};d(this,hr,s.id),h(this,O,Aa).call(this,s);return}const i=o(this,nn).get(o(this,hr));if(!i||i.kind!=="assistant")throw new Error("Open assistant message invariant violated");h(this,O,Ea).call(this,{...i,text:`${i.text}${r}`,status:"streaming"})},kS=function(e){h(this,O,Gs).call(this,"final");const r=h(this,O,lg).call(this,e.toolCallId),i=J2("content"in e?e.content:void 0),s={id:(r==null?void 0:r.id)??h(this,O,ka).call(this,"tool"),kind:"tool_call",toolCallId:e.toolCallId,title:e.title,toolKind:e.kind??"other",status:e.status==="failed"?"failed":e.status==="completed"?"completed":"in_progress",text:(r==null?void 0:r.text)??i,locations:e.locations??(r==null?void 0:r.locations)};if(r){h(this,O,Ea).call(this,s);return}h(this,O,Aa).call(this,s)},TS=function(e){const r=h(this,O,lg).call(this,e.toolCallId),i=(r==null?void 0:r.text)??"",s=J2(e.content),a=s?`${i}${s}`:i,l={id:(r==null?void 0:r.id)??h(this,O,ka).call(this,"tool"),kind:"tool_call",toolCallId:e.toolCallId,title:(r==null?void 0:r.title)??e.toolCallId,toolKind:(r==null?void 0:r.toolKind)??"other",status:e.status==="failed"?"failed":e.status==="completed"?"completed":"in_progress",text:a,locations:e.locations??(r==null?void 0:r.locations)};if(r){h(this,O,Ea).call(this,l);return}h(this,O,Aa).call(this,l)},RS=function(e){if(h(this,O,Gs).call(this,"final"),!e)return;const r=o(this,go)?o(this,Kr):null;if(!r){const s=G2(e);if(!s)return;const a={id:h(this,O,ka).call(this,"user"),kind:"user",text:s,status:"final"};h(this,O,Aa).call(this,a),o(this,go)&&d(this,Kr,a.id);return}const i=o(this,nn).get(r);if(!i||i.kind!=="user")throw new Error("Replay user message invariant violated");h(this,O,Ea).call(this,{...i,text:G2(`${i.text}${e}`)})},Gs=function(e){if(!o(this,hr))return;const r=o(this,nn).get(o(this,hr));(r==null?void 0:r.kind)==="assistant"&&h(this,O,Ea).call(this,{...r,status:e}),d(this,hr,null)},Aa=function(e){o(this,nn).set(e.id,e),this.dispatchEvent(new Tm("messages-changed"))},Ea=function(e){o(this,nn).set(e.id,e),this.dispatchEvent(new Tm("messages-changed"))},Zr=function(e){o(this,Wa)!==e&&(d(this,Wa,e),this.dispatchEvent(new vT("status-changed")))},CS=function(e){var u;const r=o(this,Un);if(!r)return e;const i=o(this,Et)?o(this,dr)==="single_session"?o(this,Yr)||!o(this,Yi).has(r):!o(this,Yi).has(r):!1,s=o(this,Ya)&&(o(this,Et)!==null||iD.test(e));if(!(s||i))return e;s&&d(this,Ya,!1),i&&(d(this,Yr,!1),o(this,Yi).add(r));const l=["[Television channel context]","This chat session is coming from a Television client.","Using Television requires the knowledge in the `television` skill. Re-read it only if it is not already in context or you know it changed.","If the skill is not installed, it can be installed via `tv skills install <your agent skills path>`."],c=((u=o(this,zn))==null?void 0:u.tvArgs)??[];return c.length>0&&l.push(`To reach this Television server, add these arguments to each tv command that contacts it: ${c.map(yD).join(" ")}`),o(this,Et)?(l.push("This conversation is currently attached to the channel below."),l.push(`channel_id: ${o(this,Et).channelID}`),l.push(`channel_name: ${o(this,Et).channelName??""}`),l.push("When the user asks to inspect or change Television state with the tv CLI, use this channel ID with the --channel argument.")):l.push("There is currently no active Television channel."),l.push("[/Television channel context]","",e),l.join(`
|
|
65
|
-
`)},ka=function(e){const r=`${e}-${o(this,Ja)}`;return d(this,Ja,o(this,Ja)+1),r},lg=function(e){for(const r of o(this,nn).values())if((r==null?void 0:r.kind)==="tool_call"&&r.toolCallId===e)return r;return null},cg=function(){if(!o(this,ur))throw new Error("ACP session is not ready");return o(this,ur)},ed=function(){if(!o(this,cr))throw new Error("ACP connection is not ready");return o(this,cr)},IS=function(){var r;const e=(r=o(this,zn))==null?void 0:r.sessionCwd;if(!e)throw new Error("ACP bridge session cwd is not ready");return e},td=function(){var r;if(o(this,dr)==="single_session")return h(this,O,hg).call(this,`${vS}-${(o(this,Hn).clientGUID??"default-client").toLowerCase()}`);const e=(r=o(this,Et))==null?void 0:r.channelID;if(!e)throw new Error("Channel context is required for per-channel session mode");return h(this,O,ug).call(this,e)},ug=function(e){return h(this,O,hg).call(this,fD(o(this,dr),e,o(this,Hn).clientGUID??"default-client"))},hg=function(e){var r;return((r=o(this,zn))==null?void 0:r.sessionIdStrategy)==="deterministic"&&o(this,Ga)>0?`${e}:epoch-${o(this,Ga)}`:e},vu=new WeakMap,yu=new WeakMap,nd=function(){d(this,cr,null),d(this,Gi,null),d(this,Nn,null),d(this,Jr,null),d(this,ur,null),d(this,Un,null),d(this,zn,null),o(this,fr)&&(o(this,fr).removeEventListener("close",o(this,vu)),o(this,fr).removeEventListener("error",o(this,yu)),o(this,fr).close(),d(this,fr,null))},Ta=function(e){const r=o(this,cr)!==null||o(this,Gi)!==null||o(this,Nn)!==null||o(this,Jr)!==null||o(this,ur)!==null||o(this,Un)!==null||o(this,zn)!==null||o(this,fr)!==null;this.disposed||this.status==="disconnected"&&!r||(h(this,O,Gs).call(this,"error"),h(this,O,nd).call(this),d(this,lr,e??null),h(this,O,Zr).call(this,"disconnected"))},dg=function(){const e=o(this,nn).size>0;d(this,hr,null),d(this,Kr,null),d(this,Ja,1),o(this,nn).clear(),e&&this.dispatchEvent(new Tm("messages-changed"))},$S=function(){return this.status==="disconnected"};function hD(){const n=new Map;return{getActualSessionId(t){return n.get(t)??null},setActualSessionId(t,e){n.set(t,e)},clearActualSessionId(t){n.delete(t)}}}function dD(n){return n==null?!0:typeof n=="object"&&Object.keys(n).length===0}function fD(n,t,e){return n==="single_session"?`${vS}-${e.toLowerCase()}`:`agent:main:television-${e.toLowerCase()}-${t.toLowerCase()}`}function xS(n){return n.replace(/^(?:\s*\n)+/,"")}function G2(n){let t=n;return t=t.replace(tD,""),t=t.replace(nD,""),t=t.replace(rD,""),t=xS(t),t}function pD(n){let t=n;return t=t.replace(oD,""),t=xS(t),t}function J2(n){return!n||n.length===0?"":n.flatMap(t=>t.type==="content"&&t.content.type==="text"?[t.content.text]:[]).join("")}async function mD(n){const t=n.createSocket(bD(n.serverURL,n.token));let e=!1,r,i;const s=new Promise((u,f)=>{r=u,i=f}),a=new ReadableStream({start(u){let f=!1;const p=()=>{t.send(JSON.stringify({type:"acp-bridge-connect"}))},y=_=>{const $=wD(_);if(!$)return;let H;try{H=JSON.parse($)}catch(L){const z=L instanceof Error?L:new Error(String(L));i(z),u.error(z);return}switch(H.type){case"acp-bridge-status":if(H.status==="ready"){let L;try{L=gD(H)}catch(z){const P=z instanceof Error?z:new Error(String(z));e||i(P),u.error(P);return}e||(e=!0,r(L));return}if(H.status==="error"||H.status==="exited"){const L=new Error(H.error??`ACP bridge ${H.status}`);e||i(L),u.error(L)}return;case"acp-bridge-message":u.enqueue(H.message);return}},v=()=>{var $;if(f)return;f=!0;const _=new Error("ACP bridge websocket closed");e||i(_),($=n.onDisconnect)==null||$.call(n,_),u.close()},S=()=>{var $;if(f)return;f=!0;const _=new Error("ACP bridge websocket error");e||i(_),($=n.onDisconnect)==null||$.call(n,_),u.error(_)};t.addEventListener("open",p),t.addEventListener("message",y),t.addEventListener("close",v),t.addEventListener("error",S)}}),l=new WritableStream({async write(u){await s,t.send(JSON.stringify({type:"acp-bridge-message",message:u}))},close(){t.close()},abort(){t.close()}}),c=await s;return{stream:{readable:a,writable:l},socket:t,metadata:c}}function gD(n){const{agent:t,sessionIdStrategy:e,sessionCwd:r,tvArgs:i}=n;if((t==="openclaw"||t==="hermes")&&(e==="deterministic"||e==="mapped")&&typeof r=="string"&&r.length>0&&vD(i))return{agent:t,sessionIdStrategy:e,sessionCwd:r,tvArgs:i};throw new Error("ACP bridge ready status missing bootstrap metadata")}function vD(n){return Array.isArray(n)&&n.every(t=>typeof t=="string")}function yD(n){return sD.test(n)?n:`'${n.replace(/'/g,"'\\''")}'`}function wD(n){if(typeof n=="string")return n;if(n instanceof Uint8Array)return new TextDecoder().decode(n);if(typeof Buffer<"u"&&n instanceof Buffer)return n.toString("utf8");if(typeof n=="object"&&n!==null&&"data"in n){const t=n.data;if(typeof t=="string")return t;if(t instanceof Uint8Array)return new TextDecoder().decode(t);if(Array.isArray(t))return Buffer.concat(t).toString("utf8")}return null}function bD(n,t){const e=new URL(n);return e.protocol=e.protocol==="https:"?"wss:":"ws:",e.pathname="/acp",e.search="",e.searchParams.set("token",t),e.hash="",e.toString()}function $m(n){return n instanceof Error?n.message:String(n)}const Y2="television.acpClientGUID",K2="television.acpMappedSessions",X2=1;var Ka;class SD{constructor(){m(this,Ka,new Map)}getActualSessionId(t){return o(this,Ka).get(t)??null}setActualSessionId(t,e){o(this,Ka).set(t,e)}clearActualSessionId(t){o(this,Ka).delete(t)}}Ka=new WeakMap;var Xa,wu,cn,rd,id,fg;class _D{constructor(t,e){m(this,cn);m(this,Xa);m(this,wu);d(this,Xa,t),d(this,wu,e)}getActualSessionId(t){const e=h(this,cn,id).call(this)[h(this,cn,rd).call(this,t)];return typeof e=="string"&&e.length>0?e:null}setActualSessionId(t,e){const r=h(this,cn,id).call(this);r[h(this,cn,rd).call(this,t)]=e,h(this,cn,fg).call(this,r)}clearActualSessionId(t){const e=h(this,cn,id).call(this);delete e[h(this,cn,rd).call(this,t)],h(this,cn,fg).call(this,e)}}Xa=new WeakMap,wu=new WeakMap,cn=new WeakSet,rd=function(t){return JSON.stringify([o(this,wu),t])},id=function(){const t=o(this,Xa).getItem(K2);if(!t)return{};let e;try{e=JSON.parse(t)}catch{return{}}if(typeof e!="object"||e===null||Array.isArray(e))return{};const r=e;return r.version!==X2?{}:typeof r.entries!="object"||r.entries===null||Array.isArray(r.entries)?{}:Object.fromEntries(Object.entries(r.entries).filter(i=>typeof i[1]=="string"))},fg=function(t){const e={version:X2,entries:t};o(this,Xa).setItem(K2,JSON.stringify(e))};function PS(){return typeof window>"u"?null:window.localStorage}function AD(n){const t=n.getItem(Y2);if(t)return t;const e=X1().toLowerCase();return n.setItem(Y2,e),e}const Q2=4401,ED=401,Zh=1e3,kD=3e4;class sd extends Error{constructor(t="Authentication required"){super(t),this.name="AuthError"}}class TD extends Ri{constructor(e){var a,l;super();C(this,"url");C(this,"name");C(this,"telemetryMeta");C(this,"status","unauthorized");C(this,"channels",new Map);C(this,"client");C(this,"acpClient");C(this,"_token");C(this,"attempting",!1);C(this,"nextRetryAt",null);C(this,"hasEverConnected",!1);C(this,"failedReconnectAttempts",0);C(this,"browserDemoMode",!1);C(this,"hasAuthRejected",!1);C(this,"bootState","pending");C(this,"serverVersion",null);C(this,"updateState",null);C(this,"decideBoot");C(this,"navigationPending");C(this,"createSocket");C(this,"createClient");C(this,"socket",null);C(this,"connectAttempt",0);C(this,"autoReconnect",!1);C(this,"retryTimer",null);C(this,"retryDelay",Zh);C(this,"visibilityEventTarget");C(this,"networkEventTarget");C(this,"onVisibilityChange");C(this,"onNetworkOnline");C(this,"telemetryActivityAgent");this.url=Cs(e.url),this.name=e.name,this.decideBoot=e.decideBoot??null,this.navigationPending=e.navigationPending??(()=>!1),this._token=e.token??null,this.telemetryMeta=e.telemetryMeta??null,this.createSocket=e.createSocket??(c=>new WebSocket(c)),this.createClient=e.createClient??((c,u,f)=>new Fk(c,{token:u??void 0,onUnauthorized:()=>this.handleAuthRejected(),...f?{telemetryMeta:f}:{}})),this.client=this.createClient(this.url,this._token,this.telemetryMeta);const r=e.mappedSessionStore??(e.acpStorage?new _D(e.acpStorage,this.url):new SD);this.acpClient=new uD({serverURL:this.url,token:this._token??"",...e.createACPSocket?{createSocket:e.createACPSocket}:e.createSocket?{createSocket:e.createSocket}:{},...e.clientGUID?{clientGUID:e.clientGUID}:{},mappedSessionStore:r}),this.visibilityEventTarget=e.visibilityEventTarget!==void 0?e.visibilityEventTarget:typeof document<"u"?document:null,this.networkEventTarget=e.networkEventTarget!==void 0?e.networkEventTarget:typeof window<"u"?window:null,this.onVisibilityChange=()=>{this.isPageVisible()&&this.kickReconnect()},this.onNetworkOnline=()=>{this.kickReconnect()},(a=this.visibilityEventTarget)==null||a.addEventListener("visibilitychange",this.onVisibilityChange),(l=this.networkEventTarget)==null||l.addEventListener("online",this.onNetworkOnline);const i=e.telemetryDocumentTarget!==void 0?e.telemetryDocumentTarget:typeof document<"u"?document:null,s=e.telemetryWindowTarget!==void 0?e.telemetryWindowTarget:typeof window<"u"?window:null;this.telemetryActivityAgent=this.telemetryMeta&&i&&s?P$({meta:this.telemetryMeta,documentTarget:i,windowTarget:s,send:c=>this.sendTelemetryActivity(c)}):null}get token(){return this._token}clearToken(){this._token=null,this.acpClient.setToken(null),this.client=this.createClient(this.url,null,this.telemetryMeta)}async connect(e){this._token=e,this.hasAuthRejected=!1,this.acpClient.setToken(e),this.cancelRetryTimer(),this.retryDelay=Zh,this.autoReconnect=!0,await this.attempt()}dispose(){var e,r,i,s;this.autoReconnect=!1,this.connectAttempt+=1,this.cancelRetryTimer(),(e=this.socket)==null||e.close(),this.socket=null,this.setStatus("unauthorized"),(r=this.visibilityEventTarget)==null||r.removeEventListener("visibilitychange",this.onVisibilityChange),(i=this.networkEventTarget)==null||i.removeEventListener("online",this.onNetworkOnline),(s=this.telemetryActivityAgent)==null||s.stop(),this.acpClient.dispose()}getViewURL(e){const r=Ld(e,this.renderOptions());return wi()?new URL(r.viewURL,this.url).toString():r.renderer==="proxy-iframe"?new URL(r.viewURL,this.url).toString():r.viewURL}async readDemoMode(){try{return await this.client.demoMode()}catch{return null}}renderOptions(){return{electron:wi(),browserDemo:this.browserDemoMode}}getContentURL(e){const r=Ld(e,this.renderOptions()).contentURL;return r===null?null:new URL(r,this.url).toString()}async createChannel(e){const{channel:r}=await this.client.channels.create({name:e});return this.channels.set(r.id,structuredClone(r)),r}applyServerEvent(e){switch(e.type){case"channel-created":this.channels.set(e.channel.id,structuredClone(e.channel)),this.dispatchEvent(new Ic("channels-changed"));break;case"channel-updated":this.channels.set(e.channel.id,structuredClone(e.channel)),this.dispatchEvent(new Ic("channels-changed"));break;case"channel-removed":this.channels.delete(e.channelID),this.dispatchEvent(new Ic("channels-changed"));break;case"artifact-created":{const r=this.channels.get(e.channelID);r&&!ck(r).includes(e.artifact.id)&&(r.layout=[...r.layout,{artifactIds:[e.artifact.id],geometry:{...P8},size:{...D8}}]);break}case"artifact-removed":{const r=this.channels.get(e.channelID);r&&(r.layout=Fm(r.layout,e.artifactID));break}case"artifact-updated":case"artifact-content-changed":case"channel-changed":case"pinned-channels-changed":case"theme-changed":case"appearance-changed":case"artifact-focus":break;default:return RD(e,"server event")}}async attempt(){var i;this.attempting=!0,this.nextRetryAt=null,this.connectAttempt+=1,this.bootState="pending";const e=this.connectAttempt;(i=this.socket)==null||i.close(),this.client=this.createClient(this.url,this._token,this.telemetryMeta),this.setStatus("disconnected"),this.dispatchEvent(new jt("change"));const r=this.createSocket(CD(this.url,this._token,this.telemetryMeta));return this.socket=r,await new Promise((s,a)=>{let l=!1,c=!1;const u=()=>{var y;l||this.connectAttempt!==e||(l=!0,c=!0,this.retryDelay=Zh,this.hasEverConnected=!0,this.failedReconnectAttempts=0,this.setStatus("connected"),(y=this.telemetryActivityAgent)==null||y.start(),s())},f=y=>{l||this.connectAttempt!==e||(l=!0,a(y))},p=async()=>{const y=this.hasEverConnected;try{const[{channels:v},S,_]=await Promise.all([this.client.channels.list(),this.client.display.get(),y?null:this.readDemoMode()]);y||(this.browserDemoMode=(_==null?void 0:_.browserExternalPages)===!0),this.channels=new Map(v.map($=>[$.id,structuredClone($)])),this.acpClient.setEnabled(S.acpEnabled),this.dispatchEvent(new jt("change")),y&&this.dispatchEvent(new Ic("channels-changed")),this.dispatchEvent(new Kh("server-event",{serverURL:this.url,event:{type:"channel-changed",channelID:S.focusedChannelId}})),this.dispatchEvent(new Kh("server-event",{serverURL:this.url,event:{type:"pinned-channels-changed",pinnedChannelIds:[...S.pinnedChannelIds]}})),u(),y&&this.connectAttempt===e&&this.dispatchEvent(new J8("server-reconnected",{serverURL:this.url}))}catch(v){if(LD(v)){f(new sd);return}f(v instanceof Error?v:new Error(String(v)))}};r.addEventListener("open",()=>{this.decideBoot===null&&(this.bootState="booted",this.navigationPending()||p())}),r.addEventListener("message",y=>{const v=DD(y);if(!v)return;if(v.type==="server-status"){const _=v;this.serverVersion=_.version,this.updateState=_.update??null;let $=!1;this.decideBoot!==null&&this.bootState==="pending"&&this.connectAttempt===e&&(this.decideBoot(_)==="boot"?(this.bootState="booted",$=!0):(this.bootState="halted",this.attempting=!1)),this.dispatchEvent(new Y8("server-status",{serverURL:this.url,message:_})),$?this.navigationPending()||p():this.bootState==="halted"&&!this.navigationPending()&&this.dispatchEvent(new jt("change"));return}if(!PD(v.type))return;const S=v;this.applyServerEvent(S),this.dispatchEvent(new Kh("server-event",{serverURL:this.url,event:S}))}),r.addEventListener("close",y=>{if(this.connectAttempt!==e)return;this.socket=null;const v=ID(y);if(!l){f(v===Q2?new sd:new Error("Connection closed before initialization"));return}if(c){if(v===Q2){this.handleAuthRejected();return}this.handleTransportFailure(new Error("Connection closed"))}}),r.addEventListener("error",()=>{if(this.connectAttempt===e){if(l){if(!c)return;this.handleTransportFailure(new Error("WebSocket error"));return}f(new Error("WebSocket connection failed"))}})}).then(()=>{this.attempting=!1},s=>{throw this.attempting=!1,this.handleAttemptFailure(s),s})}handleAuthRejected(){this.hasAuthRejected=!0,this.autoReconnect=!1,this.cancelRetryTimer(),this.setStatus("unauthorized")}handleAttemptFailure(e){if(e instanceof sd){this.handleAuthRejected();return}this.autoReconnect&&(this.hasEverConnected&&(this.failedReconnectAttempts+=1),this.scheduleRetry())}handleTransportFailure(e){this.autoReconnect&&(this.setStatus("disconnected"),this.scheduleRetry())}scheduleRetry(){this.cancelRetryTimer(),this.connectAttempt+=1;const e=this.retryDelay;this.retryDelay=Math.min(this.retryDelay*2,kD),this.nextRetryAt=Date.now()+e,this.retryTimer=setTimeout(()=>{this.retryTimer=null,this.attempt().catch(()=>{})},e),this.dispatchEvent(new jt("change"))}cancelRetryTimer(){this.retryTimer!==null&&(clearTimeout(this.retryTimer),this.retryTimer=null),this.nextRetryAt!==null&&(this.nextRetryAt=null,this.dispatchEvent(new jt("change")))}kickReconnect(){this.autoReconnect&&this.status!=="connected"&&(this.attempting||(this.cancelRetryTimer(),this.retryDelay=Zh,this.attempt().catch(()=>{})))}sendTelemetryActivity(e){var r;this.status==="connected"&&((r=this.socket)==null||r.send(JSON.stringify(e)))}sendTelemetrySignal(e,r){var s;if(!this.telemetryMeta||this.status!=="connected"&&this.bootState!=="halted")return;const i={type:lk,clientId:this.telemetryMeta.clientId,event:e,properties:r};(s=this.socket)==null||s.send(JSON.stringify(i))}setStatus(e){this.status!==e&&(this.status=e,this.dispatchEvent(new jt("change")))}isPageVisible(){return this.visibilityEventTarget===null?!0:this.visibilityEventTarget.visibilityState==="visible"}}function RD(n,t){throw new Error(`Unexpected ${t}: ${JSON.stringify(n)}`)}function CD(n,t,e=null){const r=new URL(n);if(r.protocol=r.protocol==="https:"?"wss:":"ws:",r.pathname="/events",r.search="",t&&r.searchParams.set("token",t),e)for(const[i,s]of x$(e))r.searchParams.set(i,s);return r.hash="",r.toString()}function ID(n){return typeof n=="object"&&n!==null&&"code"in n&&typeof n.code=="number"?n.code:null}const $D={"artifact-created":!0,"artifact-updated":!0,"artifact-content-changed":!0,"artifact-removed":!0,"channel-created":!0,"channel-updated":!0,"channel-removed":!0,"channel-changed":!0,"pinned-channels-changed":!0,"theme-changed":!0,"appearance-changed":!0,"artifact-focus":!0},xD=new Set(Object.keys($D));function PD(n){return xD.has(n)}function DD(n){const t=typeof n=="string"?n:typeof n=="object"&&n!==null&&"data"in n&&typeof n.data=="string"?n.data:"";if(!t)return null;let e;try{e=JSON.parse(t)}catch{return null}return typeof e!="object"||e===null||!("type"in e)||typeof e.type!="string"?null:e}function LD(n){return n instanceof Ql&&n.status===ED}const OD="Local";var pr,Zn,Ai,DS,pg,LS,bu,Su,_u,Au,Eu;class MD extends Ri{constructor(e){super();m(this,Ai);C(this,"connection");C(this,"clientGUID");C(this,"acpStorage");C(this,"connectError",null);m(this,pr);m(this,Zn,!1);m(this,bu,()=>{o(this,Zn)||(h(this,Ai,LS).call(this),this.dispatchEvent(new jt("change")))});m(this,Su,e=>{o(this,Zn)||this.dispatchEvent(new Kh("server-event",{serverURL:e.serverURL,event:e.event}))});m(this,_u,()=>{o(this,Zn)||this.dispatchEvent(new Ic("channels-changed"))});m(this,Au,e=>{o(this,Zn)||this.dispatchEvent(new J8("server-reconnected",{serverURL:e.serverURL}))});m(this,Eu,e=>{o(this,Zn)||this.dispatchEvent(new Y8("server-status",{serverURL:e.serverURL,message:e.message}))});d(this,pr,e.localStore),this.acpStorage=e.acpStorage===void 0?PS():e.acpStorage,this.clientGUID=e.clientGUID??(this.acpStorage?AD(this.acpStorage):X1().toLowerCase());const r=Cs(e.serverURL);e.launchToken!==void 0&&e.launchToken!==null&&o(this,pr).set(ST(o(this,pr).get(),r,e.launchToken));const i=e.launchToken??b2(o(this,pr).get(),r),s=e.createSocket??(l=>new WebSocket(l)),a=e.createConnection??(l=>new TD(l));this.connection=a({url:r,name:e.connectionName??OD,token:i,createSocket:s,clientGUID:this.clientGUID,acpStorage:this.acpStorage,telemetryMeta:e.telemetryMeta??null,decideBoot:e.decideBoot,navigationPending:e.navigationPending}),this.connection.addEventListener("change",o(this,bu)),this.connection.addEventListener("server-event",o(this,Su)),this.connection.addEventListener("channels-changed",o(this,_u)),this.connection.addEventListener("server-reconnected",o(this,Au)),this.connection.addEventListener("server-status",o(this,Eu))}get storedAuthToken(){return b2(o(this,pr).get(),this.connection.url)}async connect(){await h(this,Ai,DS).call(this,this.connection.token)}dispose(){o(this,Zn)||(d(this,Zn,!0),this.connection.removeEventListener("change",o(this,bu)),this.connection.removeEventListener("server-event",o(this,Su)),this.connection.removeEventListener("channels-changed",o(this,_u)),this.connection.removeEventListener("server-reconnected",o(this,Au)),this.connection.removeEventListener("server-status",o(this,Eu)),this.connection.dispose())}}pr=new WeakMap,Zn=new WeakMap,Ai=new WeakSet,DS=async function(e){if(!o(this,Zn)){h(this,Ai,pg).call(this,null);try{await this.connection.connect(e)}catch(r){h(this,Ai,pg).call(this,r instanceof sd?null:r instanceof Error?r.message:String(r))}}},pg=function(e){this.connectError!==e&&(this.connectError=e,this.dispatchEvent(new jt("change")))},LS=function(){if(this.connection.status!=="unauthorized"||!this.connection.hasAuthRejected)return;const e=o(this,pr).get(),r=_T(e,this.connection.url);r!==e&&o(this,pr).set(r),this.connection.token!==null&&this.connection.clearToken()},bu=new WeakMap,Su=new WeakMap,_u=new WeakMap,Au=new WeakMap,Eu=new WeakMap;const mg="tv-nav:",Fl="tv-reload",eb=100,ND=1e3,zD=60,UD=60,HD=24,ZD=30,qD=ZD*HD*UD*zD*ND;function bi(n){try{const t=new URL(n,window.location.href),e=t.searchParams.has(Fl);return t.searchParams.delete(Fl),t.origin===window.location.origin?`${t.pathname}${t.search}${t.hash}`:e?t.toString():n}catch{return n}}var ku,Qa,$e,Re,vo,Ke,OS,Ni,MS,gg,vg;class VD extends Ri{constructor(e,r){super();m(this,Ke);m(this,ku);m(this,Qa);m(this,$e,[]);m(this,Re,-1);m(this,vo,0);d(this,ku,e),d(this,Qa,bi(r)),h(this,Ke,OS).call(this)}get currentURL(){var e;return o(this,Re)===-1?null:((e=o(this,$e)[o(this,Re)])==null?void 0:e.url)??null}get canGoBack(){return o(this,Re)>-1}get canGoForward(){return o(this,Re)<o(this,$e).length-1}get entries(){return o(this,$e).map(e=>({...e}))}get cursor(){return o(this,Re)}navigate(e){const r=bi(e);if(r===o(this,Qa)){if(o(this,Re)===-1)return;d(this,Re,-1),h(this,Ke,Ni).call(this);return}o(this,Re)<o(this,$e).length-1&&d(this,$e,o(this,$e).slice(0,o(this,Re)+1)),o(this,$e).push({url:r}),d(this,Re,o(this,$e).length-1),h(this,Ke,gg).call(this),h(this,Ke,Ni).call(this)}replace(e){var i;if(o(this,Re)===-1){this.navigate(e);return}const r=bi(e);if(r===o(this,Qa)){d(this,$e,o(this,$e).filter((s,a)=>a!==o(this,Re))),d(this,Re,-1),h(this,Ke,Ni).call(this);return}((i=o(this,$e)[o(this,Re)])==null?void 0:i.url)!==r&&(d(this,$e,o(this,$e).map((s,a)=>a===o(this,Re)?{url:r}:s)),h(this,Ke,Ni).call(this))}back(){o(this,Re)!==-1&&(d(this,Re,o(this,Re)-1),h(this,Ke,Ni).call(this))}forward(){this.canGoForward&&(d(this,Re,o(this,Re)+1),h(this,Ke,Ni).call(this))}reset(){o(this,Re)===-1&&o(this,$e).length===0||(d(this,$e,[]),d(this,Re,-1),h(this,Ke,Ni).call(this))}}ku=new WeakMap,Qa=new WeakMap,$e=new WeakMap,Re=new WeakMap,vo=new WeakMap,Ke=new WeakSet,OS=function(){const e=localStorage.getItem(o(this,Ke,vg));if(e!==null)try{const r=JSON.parse(e);if(!NS(r))return;d(this,$e,r.entries.map(i=>({url:i.url}))),d(this,Re,r.cursor),d(this,vo,r.lastWritten),h(this,Ke,gg).call(this)}catch{d(this,$e,[]),d(this,Re,-1),d(this,vo,0)}},Ni=function(){d(this,vo,Date.now());try{localStorage.setItem(o(this,Ke,vg),JSON.stringify(h(this,Ke,MS).call(this)))}catch(e){if(!jD(e))throw e}this.dispatchEvent(new jt("change"))},MS=function(){return{v:1,entries:o(this,$e).map(e=>({...e})),cursor:o(this,Re),lastWritten:o(this,vo)}},gg=function(){if(o(this,$e).length<=eb)return;const e=o(this,$e).length-eb;d(this,$e,o(this,$e).slice(e)),d(this,Re,Math.max(-1,o(this,Re)-e))},vg=function(){return FD(o(this,ku))};function FD(n){return`${mg}${n}`}function BD(n){const t=Date.now()-qD,e=[];for(let r=0;r<localStorage.length;r+=1){const i=localStorage.key(r);if(!(i!=null&&i.startsWith(mg)))continue;const s=i.slice(mg.length),a=localStorage.getItem(i);if(a===null)continue;let l;try{l=JSON.parse(a)}catch{e.push(i);continue}if(!NS(l)){e.push(i);continue}!n.has(s)&&l.lastWritten<t&&e.push(i)}for(const r of e)localStorage.removeItem(r)}function jD(n){return n instanceof DOMException&&n.name==="QuotaExceededError"}function NS(n){if(typeof n!="object"||n===null)return!1;const t=n;if(t.v!==1||!Array.isArray(t.entries))return!1;const e=t.cursor;return typeof e!="number"||!Number.isInteger(e)||typeof t.lastWritten!="number"||!Number.isFinite(t.lastWritten)||e<-1||e>=t.entries.length?!1:t.entries.every(r=>typeof r=="object"&&r!==null&&typeof r.url=="string")}const xm="tv-channel-sidebar-collapsed";var yo;class WD{constructor(t){m(this,yo);d(this,yo,t)}read(){return o(this,yo).getItem(xm)==="true"}setCollapsed(t){try{t?o(this,yo).setItem(xm,"true"):o(this,yo).removeItem(xm)}catch{}}}yo=new WeakMap;const Pm="tv-channel-sidebar-width",yg=160,wg=350,qh=260,GD=/^-?\d+$/;var wo;class JD{constructor(t){m(this,wo);d(this,wo,t)}read(){const t=o(this,wo).getItem(Pm);if(t===null||!GD.test(t))return null;const e=BigInt(t);return e<BigInt(yg)?yg:e>BigInt(wg)?wg:Number(e)}commit(t){const e=zS(Math.round(t));try{o(this,wo).setItem(Pm,String(e))}catch{}return e}clear(){try{o(this,wo).removeItem(Pm)}catch{}}}wo=new WeakMap;function zS(n){return Math.min(Math.max(n,yg),wg)}const YD="1.4.27";function cv(n=YD){return n!==void 0&&n.length>0?n:"0.0.0"}function uv(){let n=!1;return{get pending(){return n},begin(t){n||(n=!0,t())}}}const bg="tv-reload-attempted";function KD(n){return n.originMatch?n.marker!==null&&n.bundleVersion===n.serverVersion?{action:"signal-autoreloaded",fromVersion:n.marker.fromVersion,toVersion:n.bundleVersion}:Wk(n.bundleVersion,n.serverVersion)?n.marker!==null&&n.marker.serverVersion===n.serverVersion?{action:"none"}:{action:"reload",marker:{serverVersion:n.serverVersion,fromVersion:n.bundleVersion}}:{action:"none"}:{action:"none"}}function XD(n){const t=n.getItem(bg);if(t===null)return null;let e;try{e=JSON.parse(t)}catch{return null}if(!e||typeof e!="object")return null;const r=e;return typeof r.serverVersion!="string"||typeof r.fromVersion!="string"?null:{serverVersion:r.serverVersion,fromVersion:r.fromVersion}}function QD(n){const t=n.storage!==void 0?n.storage:typeof sessionStorage<"u"?sessionStorage:null,e=n.reload??(()=>location.reload()),r=n.navigationLatch??uv(),i=n.bundleVersion??cv();if(t===null)return{dispose(){}};let s=null;const a=()=>{if(s===null)return;const u=n.owner.connection;if(u.url!==n.primaryServerURL||u.status!=="connected")return;const f=s;s=null,u.sendTelemetrySignal("client_autoreloaded",{from_version:f.fromVersion,to_version:f.toVersion})},l=u=>{if(r.pending)return;const f=KD({bundleVersion:i,serverVersion:u.message.version,originMatch:u.serverURL===n.primaryServerURL,marker:XD(t)});switch(f.action){case"reload":t.setItem(bg,JSON.stringify(f.marker)),r.begin(e);return;case"signal-autoreloaded":t.removeItem(bg),s={fromVersion:f.fromVersion,toVersion:f.toVersion},a();return;case"none":return}},c=()=>{a()};return n.owner.addEventListener("server-status",l),n.owner.addEventListener("change",c),{dispose(){n.owner.removeEventListener("server-status",l),n.owner.removeEventListener("change",c)}}}function eL(n){const t=wi(n.search),e=L6(n.search),r=e!==null&&qf(e)?e:null;return{electron:t,shellVersion:r}}function tL(n){return!n.electron||n.requiredDesktopVersion===null||!qf(n.requiredDesktopVersion)?!1:n.shellVersion===null?!0:n.shellVersion===Cd?!1:K1(n.requiredDesktopVersion,n.shellVersion)}const nL=`# Desktop app update required
|
|
65
|
+
`)},ka=function(e){const r=`${e}-${o(this,Ja)}`;return d(this,Ja,o(this,Ja)+1),r},lg=function(e){for(const r of o(this,nn).values())if((r==null?void 0:r.kind)==="tool_call"&&r.toolCallId===e)return r;return null},cg=function(){if(!o(this,ur))throw new Error("ACP session is not ready");return o(this,ur)},ed=function(){if(!o(this,cr))throw new Error("ACP connection is not ready");return o(this,cr)},IS=function(){var r;const e=(r=o(this,zn))==null?void 0:r.sessionCwd;if(!e)throw new Error("ACP bridge session cwd is not ready");return e},td=function(){var r;if(o(this,dr)==="single_session")return h(this,O,hg).call(this,`${vS}-${(o(this,Hn).clientGUID??"default-client").toLowerCase()}`);const e=(r=o(this,Et))==null?void 0:r.channelID;if(!e)throw new Error("Channel context is required for per-channel session mode");return h(this,O,ug).call(this,e)},ug=function(e){return h(this,O,hg).call(this,fD(o(this,dr),e,o(this,Hn).clientGUID??"default-client"))},hg=function(e){var r;return((r=o(this,zn))==null?void 0:r.sessionIdStrategy)==="deterministic"&&o(this,Ga)>0?`${e}:epoch-${o(this,Ga)}`:e},vu=new WeakMap,yu=new WeakMap,nd=function(){d(this,cr,null),d(this,Gi,null),d(this,Nn,null),d(this,Jr,null),d(this,ur,null),d(this,Un,null),d(this,zn,null),o(this,fr)&&(o(this,fr).removeEventListener("close",o(this,vu)),o(this,fr).removeEventListener("error",o(this,yu)),o(this,fr).close(),d(this,fr,null))},Ta=function(e){const r=o(this,cr)!==null||o(this,Gi)!==null||o(this,Nn)!==null||o(this,Jr)!==null||o(this,ur)!==null||o(this,Un)!==null||o(this,zn)!==null||o(this,fr)!==null;this.disposed||this.status==="disconnected"&&!r||(h(this,O,Gs).call(this,"error"),h(this,O,nd).call(this),d(this,lr,e??null),h(this,O,Zr).call(this,"disconnected"))},dg=function(){const e=o(this,nn).size>0;d(this,hr,null),d(this,Kr,null),d(this,Ja,1),o(this,nn).clear(),e&&this.dispatchEvent(new Tm("messages-changed"))},$S=function(){return this.status==="disconnected"};function hD(){const n=new Map;return{getActualSessionId(t){return n.get(t)??null},setActualSessionId(t,e){n.set(t,e)},clearActualSessionId(t){n.delete(t)}}}function dD(n){return n==null?!0:typeof n=="object"&&Object.keys(n).length===0}function fD(n,t,e){return n==="single_session"?`${vS}-${e.toLowerCase()}`:`agent:main:television-${e.toLowerCase()}-${t.toLowerCase()}`}function xS(n){return n.replace(/^(?:\s*\n)+/,"")}function G2(n){let t=n;return t=t.replace(tD,""),t=t.replace(nD,""),t=t.replace(rD,""),t=xS(t),t}function pD(n){let t=n;return t=t.replace(oD,""),t=xS(t),t}function J2(n){return!n||n.length===0?"":n.flatMap(t=>t.type==="content"&&t.content.type==="text"?[t.content.text]:[]).join("")}async function mD(n){const t=n.createSocket(bD(n.serverURL,n.token));let e=!1,r,i;const s=new Promise((u,f)=>{r=u,i=f}),a=new ReadableStream({start(u){let f=!1;const p=()=>{t.send(JSON.stringify({type:"acp-bridge-connect"}))},y=_=>{const $=wD(_);if(!$)return;let H;try{H=JSON.parse($)}catch(L){const z=L instanceof Error?L:new Error(String(L));i(z),u.error(z);return}switch(H.type){case"acp-bridge-status":if(H.status==="ready"){let L;try{L=gD(H)}catch(z){const P=z instanceof Error?z:new Error(String(z));e||i(P),u.error(P);return}e||(e=!0,r(L));return}if(H.status==="error"||H.status==="exited"){const L=new Error(H.error??`ACP bridge ${H.status}`);e||i(L),u.error(L)}return;case"acp-bridge-message":u.enqueue(H.message);return}},v=()=>{var $;if(f)return;f=!0;const _=new Error("ACP bridge websocket closed");e||i(_),($=n.onDisconnect)==null||$.call(n,_),u.close()},S=()=>{var $;if(f)return;f=!0;const _=new Error("ACP bridge websocket error");e||i(_),($=n.onDisconnect)==null||$.call(n,_),u.error(_)};t.addEventListener("open",p),t.addEventListener("message",y),t.addEventListener("close",v),t.addEventListener("error",S)}}),l=new WritableStream({async write(u){await s,t.send(JSON.stringify({type:"acp-bridge-message",message:u}))},close(){t.close()},abort(){t.close()}}),c=await s;return{stream:{readable:a,writable:l},socket:t,metadata:c}}function gD(n){const{agent:t,sessionIdStrategy:e,sessionCwd:r,tvArgs:i}=n;if((t==="openclaw"||t==="hermes")&&(e==="deterministic"||e==="mapped")&&typeof r=="string"&&r.length>0&&vD(i))return{agent:t,sessionIdStrategy:e,sessionCwd:r,tvArgs:i};throw new Error("ACP bridge ready status missing bootstrap metadata")}function vD(n){return Array.isArray(n)&&n.every(t=>typeof t=="string")}function yD(n){return sD.test(n)?n:`'${n.replace(/'/g,"'\\''")}'`}function wD(n){if(typeof n=="string")return n;if(n instanceof Uint8Array)return new TextDecoder().decode(n);if(typeof Buffer<"u"&&n instanceof Buffer)return n.toString("utf8");if(typeof n=="object"&&n!==null&&"data"in n){const t=n.data;if(typeof t=="string")return t;if(t instanceof Uint8Array)return new TextDecoder().decode(t);if(Array.isArray(t))return Buffer.concat(t).toString("utf8")}return null}function bD(n,t){const e=new URL(n);return e.protocol=e.protocol==="https:"?"wss:":"ws:",e.pathname="/acp",e.search="",e.searchParams.set("token",t),e.hash="",e.toString()}function $m(n){return n instanceof Error?n.message:String(n)}const Y2="television.acpClientGUID",K2="television.acpMappedSessions",X2=1;var Ka;class SD{constructor(){m(this,Ka,new Map)}getActualSessionId(t){return o(this,Ka).get(t)??null}setActualSessionId(t,e){o(this,Ka).set(t,e)}clearActualSessionId(t){o(this,Ka).delete(t)}}Ka=new WeakMap;var Xa,wu,cn,rd,id,fg;class _D{constructor(t,e){m(this,cn);m(this,Xa);m(this,wu);d(this,Xa,t),d(this,wu,e)}getActualSessionId(t){const e=h(this,cn,id).call(this)[h(this,cn,rd).call(this,t)];return typeof e=="string"&&e.length>0?e:null}setActualSessionId(t,e){const r=h(this,cn,id).call(this);r[h(this,cn,rd).call(this,t)]=e,h(this,cn,fg).call(this,r)}clearActualSessionId(t){const e=h(this,cn,id).call(this);delete e[h(this,cn,rd).call(this,t)],h(this,cn,fg).call(this,e)}}Xa=new WeakMap,wu=new WeakMap,cn=new WeakSet,rd=function(t){return JSON.stringify([o(this,wu),t])},id=function(){const t=o(this,Xa).getItem(K2);if(!t)return{};let e;try{e=JSON.parse(t)}catch{return{}}if(typeof e!="object"||e===null||Array.isArray(e))return{};const r=e;return r.version!==X2?{}:typeof r.entries!="object"||r.entries===null||Array.isArray(r.entries)?{}:Object.fromEntries(Object.entries(r.entries).filter(i=>typeof i[1]=="string"))},fg=function(t){const e={version:X2,entries:t};o(this,Xa).setItem(K2,JSON.stringify(e))};function PS(){return typeof window>"u"?null:window.localStorage}function AD(n){const t=n.getItem(Y2);if(t)return t;const e=X1().toLowerCase();return n.setItem(Y2,e),e}const Q2=4401,ED=401,Zh=1e3,kD=3e4;class sd extends Error{constructor(t="Authentication required"){super(t),this.name="AuthError"}}class TD extends Ri{constructor(e){var a,l;super();C(this,"url");C(this,"name");C(this,"telemetryMeta");C(this,"status","unauthorized");C(this,"channels",new Map);C(this,"client");C(this,"acpClient");C(this,"_token");C(this,"attempting",!1);C(this,"nextRetryAt",null);C(this,"hasEverConnected",!1);C(this,"failedReconnectAttempts",0);C(this,"browserDemoMode",!1);C(this,"hasAuthRejected",!1);C(this,"bootState","pending");C(this,"serverVersion",null);C(this,"updateState",null);C(this,"decideBoot");C(this,"navigationPending");C(this,"createSocket");C(this,"createClient");C(this,"socket",null);C(this,"connectAttempt",0);C(this,"autoReconnect",!1);C(this,"retryTimer",null);C(this,"retryDelay",Zh);C(this,"visibilityEventTarget");C(this,"networkEventTarget");C(this,"onVisibilityChange");C(this,"onNetworkOnline");C(this,"telemetryActivityAgent");this.url=Cs(e.url),this.name=e.name,this.decideBoot=e.decideBoot??null,this.navigationPending=e.navigationPending??(()=>!1),this._token=e.token??null,this.telemetryMeta=e.telemetryMeta??null,this.createSocket=e.createSocket??(c=>new WebSocket(c)),this.createClient=e.createClient??((c,u,f)=>new Fk(c,{token:u??void 0,onUnauthorized:()=>this.handleAuthRejected(),...f?{telemetryMeta:f}:{}})),this.client=this.createClient(this.url,this._token,this.telemetryMeta);const r=e.mappedSessionStore??(e.acpStorage?new _D(e.acpStorage,this.url):new SD);this.acpClient=new uD({serverURL:this.url,token:this._token??"",...e.createACPSocket?{createSocket:e.createACPSocket}:e.createSocket?{createSocket:e.createSocket}:{},...e.clientGUID?{clientGUID:e.clientGUID}:{},mappedSessionStore:r}),this.visibilityEventTarget=e.visibilityEventTarget!==void 0?e.visibilityEventTarget:typeof document<"u"?document:null,this.networkEventTarget=e.networkEventTarget!==void 0?e.networkEventTarget:typeof window<"u"?window:null,this.onVisibilityChange=()=>{this.isPageVisible()&&this.kickReconnect()},this.onNetworkOnline=()=>{this.kickReconnect()},(a=this.visibilityEventTarget)==null||a.addEventListener("visibilitychange",this.onVisibilityChange),(l=this.networkEventTarget)==null||l.addEventListener("online",this.onNetworkOnline);const i=e.telemetryDocumentTarget!==void 0?e.telemetryDocumentTarget:typeof document<"u"?document:null,s=e.telemetryWindowTarget!==void 0?e.telemetryWindowTarget:typeof window<"u"?window:null;this.telemetryActivityAgent=this.telemetryMeta&&i&&s?P$({meta:this.telemetryMeta,documentTarget:i,windowTarget:s,send:c=>this.sendTelemetryActivity(c)}):null}get token(){return this._token}clearToken(){this._token=null,this.acpClient.setToken(null),this.client=this.createClient(this.url,null,this.telemetryMeta)}async connect(e){this._token=e,this.hasAuthRejected=!1,this.acpClient.setToken(e),this.cancelRetryTimer(),this.retryDelay=Zh,this.autoReconnect=!0,await this.attempt()}dispose(){var e,r,i,s;this.autoReconnect=!1,this.connectAttempt+=1,this.cancelRetryTimer(),(e=this.socket)==null||e.close(),this.socket=null,this.setStatus("unauthorized"),(r=this.visibilityEventTarget)==null||r.removeEventListener("visibilitychange",this.onVisibilityChange),(i=this.networkEventTarget)==null||i.removeEventListener("online",this.onNetworkOnline),(s=this.telemetryActivityAgent)==null||s.stop(),this.acpClient.dispose()}getViewURL(e){const r=Ld(e,this.renderOptions());return wi()?new URL(r.viewURL,this.url).toString():r.renderer==="proxy-iframe"?new URL(r.viewURL,this.url).toString():r.viewURL}async readDemoMode(){try{return await this.client.demoMode()}catch{return null}}renderOptions(){return{electron:wi(),browserDemo:this.browserDemoMode}}getContentURL(e){const r=Ld(e,this.renderOptions()).contentURL;return r===null?null:new URL(r,this.url).toString()}async createChannel(e){const{channel:r}=await this.client.channels.create({name:e});return this.channels.set(r.id,structuredClone(r)),r}applyServerEvent(e){switch(e.type){case"channel-created":this.channels.set(e.channel.id,structuredClone(e.channel)),this.dispatchEvent(new Ic("channels-changed"));break;case"channel-updated":this.channels.set(e.channel.id,structuredClone(e.channel)),this.dispatchEvent(new Ic("channels-changed"));break;case"channel-removed":this.channels.delete(e.channelID),this.dispatchEvent(new Ic("channels-changed"));break;case"artifact-created":{const r=this.channels.get(e.channelID);r&&!ck(r).includes(e.artifact.id)&&(r.layout=[...r.layout,{artifactIds:[e.artifact.id],geometry:{...P8},size:{...D8}}]);break}case"artifact-removed":{const r=this.channels.get(e.channelID);r&&(r.layout=Fm(r.layout,e.artifactID));break}case"artifact-updated":case"artifact-content-changed":case"channel-changed":case"pinned-channels-changed":case"theme-changed":case"appearance-changed":case"artifact-focus":break;default:return RD(e,"server event")}}async attempt(){var i;this.attempting=!0,this.nextRetryAt=null,this.connectAttempt+=1,this.bootState="pending";const e=this.connectAttempt;(i=this.socket)==null||i.close(),this.client=this.createClient(this.url,this._token,this.telemetryMeta),this.setStatus("disconnected"),this.dispatchEvent(new jt("change"));const r=this.createSocket(CD(this.url,this._token,this.telemetryMeta));return this.socket=r,await new Promise((s,a)=>{let l=!1,c=!1;const u=()=>{var y;l||this.connectAttempt!==e||(l=!0,c=!0,this.retryDelay=Zh,this.hasEverConnected=!0,this.failedReconnectAttempts=0,this.setStatus("connected"),(y=this.telemetryActivityAgent)==null||y.start(),s())},f=y=>{l||this.connectAttempt!==e||(l=!0,a(y))},p=async()=>{const y=this.hasEverConnected;try{const[{channels:v},S,_]=await Promise.all([this.client.channels.list(),this.client.display.get(),y?null:this.readDemoMode()]);y||(this.browserDemoMode=(_==null?void 0:_.browserExternalPages)===!0),this.channels=new Map(v.map($=>[$.id,structuredClone($)])),this.acpClient.setEnabled(S.acpEnabled),this.dispatchEvent(new jt("change")),y&&this.dispatchEvent(new Ic("channels-changed")),this.dispatchEvent(new Kh("server-event",{serverURL:this.url,event:{type:"channel-changed",channelID:S.focusedChannelId}})),this.dispatchEvent(new Kh("server-event",{serverURL:this.url,event:{type:"pinned-channels-changed",pinnedChannelIds:[...S.pinnedChannelIds]}})),u(),y&&this.connectAttempt===e&&this.dispatchEvent(new J8("server-reconnected",{serverURL:this.url}))}catch(v){if(LD(v)){f(new sd);return}f(v instanceof Error?v:new Error(String(v)))}};r.addEventListener("open",()=>{this.decideBoot===null&&(this.bootState="booted",this.navigationPending()||p())}),r.addEventListener("message",y=>{const v=DD(y);if(!v)return;if(v.type==="server-status"){const _=v;this.serverVersion=_.version,this.updateState=_.update??null;let $=!1;this.decideBoot!==null&&this.bootState==="pending"&&this.connectAttempt===e&&(this.decideBoot(_)==="boot"?(this.bootState="booted",$=!0):(this.bootState="halted",this.attempting=!1)),this.dispatchEvent(new Y8("server-status",{serverURL:this.url,message:_})),$?this.navigationPending()||p():this.bootState==="halted"&&!this.navigationPending()&&this.dispatchEvent(new jt("change"));return}if(!PD(v.type))return;const S=v;this.applyServerEvent(S),this.dispatchEvent(new Kh("server-event",{serverURL:this.url,event:S}))}),r.addEventListener("close",y=>{if(this.connectAttempt!==e)return;this.socket=null;const v=ID(y);if(!l){f(v===Q2?new sd:new Error("Connection closed before initialization"));return}if(c){if(v===Q2){this.handleAuthRejected();return}this.handleTransportFailure(new Error("Connection closed"))}}),r.addEventListener("error",()=>{if(this.connectAttempt===e){if(l){if(!c)return;this.handleTransportFailure(new Error("WebSocket error"));return}f(new Error("WebSocket connection failed"))}})}).then(()=>{this.attempting=!1},s=>{throw this.attempting=!1,this.handleAttemptFailure(s),s})}handleAuthRejected(){this.hasAuthRejected=!0,this.autoReconnect=!1,this.cancelRetryTimer(),this.setStatus("unauthorized")}handleAttemptFailure(e){if(e instanceof sd){this.handleAuthRejected();return}this.autoReconnect&&(this.hasEverConnected&&(this.failedReconnectAttempts+=1),this.scheduleRetry())}handleTransportFailure(e){this.autoReconnect&&(this.setStatus("disconnected"),this.scheduleRetry())}scheduleRetry(){this.cancelRetryTimer(),this.connectAttempt+=1;const e=this.retryDelay;this.retryDelay=Math.min(this.retryDelay*2,kD),this.nextRetryAt=Date.now()+e,this.retryTimer=setTimeout(()=>{this.retryTimer=null,this.attempt().catch(()=>{})},e),this.dispatchEvent(new jt("change"))}cancelRetryTimer(){this.retryTimer!==null&&(clearTimeout(this.retryTimer),this.retryTimer=null),this.nextRetryAt!==null&&(this.nextRetryAt=null,this.dispatchEvent(new jt("change")))}kickReconnect(){this.autoReconnect&&this.status!=="connected"&&(this.attempting||(this.cancelRetryTimer(),this.retryDelay=Zh,this.attempt().catch(()=>{})))}sendTelemetryActivity(e){var r;this.status==="connected"&&((r=this.socket)==null||r.send(JSON.stringify(e)))}sendTelemetrySignal(e,r){var s;if(!this.telemetryMeta||this.status!=="connected"&&this.bootState!=="halted")return;const i={type:lk,clientId:this.telemetryMeta.clientId,event:e,properties:r};(s=this.socket)==null||s.send(JSON.stringify(i))}setStatus(e){this.status!==e&&(this.status=e,this.dispatchEvent(new jt("change")))}isPageVisible(){return this.visibilityEventTarget===null?!0:this.visibilityEventTarget.visibilityState==="visible"}}function RD(n,t){throw new Error(`Unexpected ${t}: ${JSON.stringify(n)}`)}function CD(n,t,e=null){const r=new URL(n);if(r.protocol=r.protocol==="https:"?"wss:":"ws:",r.pathname="/events",r.search="",t&&r.searchParams.set("token",t),e)for(const[i,s]of x$(e))r.searchParams.set(i,s);return r.hash="",r.toString()}function ID(n){return typeof n=="object"&&n!==null&&"code"in n&&typeof n.code=="number"?n.code:null}const $D={"artifact-created":!0,"artifact-updated":!0,"artifact-content-changed":!0,"artifact-removed":!0,"channel-created":!0,"channel-updated":!0,"channel-removed":!0,"channel-changed":!0,"pinned-channels-changed":!0,"theme-changed":!0,"appearance-changed":!0,"artifact-focus":!0},xD=new Set(Object.keys($D));function PD(n){return xD.has(n)}function DD(n){const t=typeof n=="string"?n:typeof n=="object"&&n!==null&&"data"in n&&typeof n.data=="string"?n.data:"";if(!t)return null;let e;try{e=JSON.parse(t)}catch{return null}return typeof e!="object"||e===null||!("type"in e)||typeof e.type!="string"?null:e}function LD(n){return n instanceof Ql&&n.status===ED}const OD="Local";var pr,Zn,Ai,DS,pg,LS,bu,Su,_u,Au,Eu;class MD extends Ri{constructor(e){super();m(this,Ai);C(this,"connection");C(this,"clientGUID");C(this,"acpStorage");C(this,"connectError",null);m(this,pr);m(this,Zn,!1);m(this,bu,()=>{o(this,Zn)||(h(this,Ai,LS).call(this),this.dispatchEvent(new jt("change")))});m(this,Su,e=>{o(this,Zn)||this.dispatchEvent(new Kh("server-event",{serverURL:e.serverURL,event:e.event}))});m(this,_u,()=>{o(this,Zn)||this.dispatchEvent(new Ic("channels-changed"))});m(this,Au,e=>{o(this,Zn)||this.dispatchEvent(new J8("server-reconnected",{serverURL:e.serverURL}))});m(this,Eu,e=>{o(this,Zn)||this.dispatchEvent(new Y8("server-status",{serverURL:e.serverURL,message:e.message}))});d(this,pr,e.localStore),this.acpStorage=e.acpStorage===void 0?PS():e.acpStorage,this.clientGUID=e.clientGUID??(this.acpStorage?AD(this.acpStorage):X1().toLowerCase());const r=Cs(e.serverURL);e.launchToken!==void 0&&e.launchToken!==null&&o(this,pr).set(ST(o(this,pr).get(),r,e.launchToken));const i=e.launchToken??b2(o(this,pr).get(),r),s=e.createSocket??(l=>new WebSocket(l)),a=e.createConnection??(l=>new TD(l));this.connection=a({url:r,name:e.connectionName??OD,token:i,createSocket:s,clientGUID:this.clientGUID,acpStorage:this.acpStorage,telemetryMeta:e.telemetryMeta??null,decideBoot:e.decideBoot,navigationPending:e.navigationPending}),this.connection.addEventListener("change",o(this,bu)),this.connection.addEventListener("server-event",o(this,Su)),this.connection.addEventListener("channels-changed",o(this,_u)),this.connection.addEventListener("server-reconnected",o(this,Au)),this.connection.addEventListener("server-status",o(this,Eu))}get storedAuthToken(){return b2(o(this,pr).get(),this.connection.url)}async connect(){await h(this,Ai,DS).call(this,this.connection.token)}dispose(){o(this,Zn)||(d(this,Zn,!0),this.connection.removeEventListener("change",o(this,bu)),this.connection.removeEventListener("server-event",o(this,Su)),this.connection.removeEventListener("channels-changed",o(this,_u)),this.connection.removeEventListener("server-reconnected",o(this,Au)),this.connection.removeEventListener("server-status",o(this,Eu)),this.connection.dispose())}}pr=new WeakMap,Zn=new WeakMap,Ai=new WeakSet,DS=async function(e){if(!o(this,Zn)){h(this,Ai,pg).call(this,null);try{await this.connection.connect(e)}catch(r){h(this,Ai,pg).call(this,r instanceof sd?null:r instanceof Error?r.message:String(r))}}},pg=function(e){this.connectError!==e&&(this.connectError=e,this.dispatchEvent(new jt("change")))},LS=function(){if(this.connection.status!=="unauthorized"||!this.connection.hasAuthRejected)return;const e=o(this,pr).get(),r=_T(e,this.connection.url);r!==e&&o(this,pr).set(r),this.connection.token!==null&&this.connection.clearToken()},bu=new WeakMap,Su=new WeakMap,_u=new WeakMap,Au=new WeakMap,Eu=new WeakMap;const mg="tv-nav:",Fl="tv-reload",eb=100,ND=1e3,zD=60,UD=60,HD=24,ZD=30,qD=ZD*HD*UD*zD*ND;function bi(n){try{const t=new URL(n,window.location.href),e=t.searchParams.has(Fl);return t.searchParams.delete(Fl),t.origin===window.location.origin?`${t.pathname}${t.search}${t.hash}`:e?t.toString():n}catch{return n}}var ku,Qa,$e,Re,vo,Ke,OS,Ni,MS,gg,vg;class VD extends Ri{constructor(e,r){super();m(this,Ke);m(this,ku);m(this,Qa);m(this,$e,[]);m(this,Re,-1);m(this,vo,0);d(this,ku,e),d(this,Qa,bi(r)),h(this,Ke,OS).call(this)}get currentURL(){var e;return o(this,Re)===-1?null:((e=o(this,$e)[o(this,Re)])==null?void 0:e.url)??null}get canGoBack(){return o(this,Re)>-1}get canGoForward(){return o(this,Re)<o(this,$e).length-1}get entries(){return o(this,$e).map(e=>({...e}))}get cursor(){return o(this,Re)}navigate(e){const r=bi(e);if(r===o(this,Qa)){if(o(this,Re)===-1)return;d(this,Re,-1),h(this,Ke,Ni).call(this);return}o(this,Re)<o(this,$e).length-1&&d(this,$e,o(this,$e).slice(0,o(this,Re)+1)),o(this,$e).push({url:r}),d(this,Re,o(this,$e).length-1),h(this,Ke,gg).call(this),h(this,Ke,Ni).call(this)}replace(e){var i;if(o(this,Re)===-1){this.navigate(e);return}const r=bi(e);if(r===o(this,Qa)){d(this,$e,o(this,$e).filter((s,a)=>a!==o(this,Re))),d(this,Re,-1),h(this,Ke,Ni).call(this);return}((i=o(this,$e)[o(this,Re)])==null?void 0:i.url)!==r&&(d(this,$e,o(this,$e).map((s,a)=>a===o(this,Re)?{url:r}:s)),h(this,Ke,Ni).call(this))}back(){o(this,Re)!==-1&&(d(this,Re,o(this,Re)-1),h(this,Ke,Ni).call(this))}forward(){this.canGoForward&&(d(this,Re,o(this,Re)+1),h(this,Ke,Ni).call(this))}reset(){o(this,Re)===-1&&o(this,$e).length===0||(d(this,$e,[]),d(this,Re,-1),h(this,Ke,Ni).call(this))}}ku=new WeakMap,Qa=new WeakMap,$e=new WeakMap,Re=new WeakMap,vo=new WeakMap,Ke=new WeakSet,OS=function(){const e=localStorage.getItem(o(this,Ke,vg));if(e!==null)try{const r=JSON.parse(e);if(!NS(r))return;d(this,$e,r.entries.map(i=>({url:i.url}))),d(this,Re,r.cursor),d(this,vo,r.lastWritten),h(this,Ke,gg).call(this)}catch{d(this,$e,[]),d(this,Re,-1),d(this,vo,0)}},Ni=function(){d(this,vo,Date.now());try{localStorage.setItem(o(this,Ke,vg),JSON.stringify(h(this,Ke,MS).call(this)))}catch(e){if(!jD(e))throw e}this.dispatchEvent(new jt("change"))},MS=function(){return{v:1,entries:o(this,$e).map(e=>({...e})),cursor:o(this,Re),lastWritten:o(this,vo)}},gg=function(){if(o(this,$e).length<=eb)return;const e=o(this,$e).length-eb;d(this,$e,o(this,$e).slice(e)),d(this,Re,Math.max(-1,o(this,Re)-e))},vg=function(){return FD(o(this,ku))};function FD(n){return`${mg}${n}`}function BD(n){const t=Date.now()-qD,e=[];for(let r=0;r<localStorage.length;r+=1){const i=localStorage.key(r);if(!(i!=null&&i.startsWith(mg)))continue;const s=i.slice(mg.length),a=localStorage.getItem(i);if(a===null)continue;let l;try{l=JSON.parse(a)}catch{e.push(i);continue}if(!NS(l)){e.push(i);continue}!n.has(s)&&l.lastWritten<t&&e.push(i)}for(const r of e)localStorage.removeItem(r)}function jD(n){return n instanceof DOMException&&n.name==="QuotaExceededError"}function NS(n){if(typeof n!="object"||n===null)return!1;const t=n;if(t.v!==1||!Array.isArray(t.entries))return!1;const e=t.cursor;return typeof e!="number"||!Number.isInteger(e)||typeof t.lastWritten!="number"||!Number.isFinite(t.lastWritten)||e<-1||e>=t.entries.length?!1:t.entries.every(r=>typeof r=="object"&&r!==null&&typeof r.url=="string")}const xm="tv-channel-sidebar-collapsed";var yo;class WD{constructor(t){m(this,yo);d(this,yo,t)}read(){return o(this,yo).getItem(xm)==="true"}setCollapsed(t){try{t?o(this,yo).setItem(xm,"true"):o(this,yo).removeItem(xm)}catch{}}}yo=new WeakMap;const Pm="tv-channel-sidebar-width",yg=160,wg=350,qh=260,GD=/^-?\d+$/;var wo;class JD{constructor(t){m(this,wo);d(this,wo,t)}read(){const t=o(this,wo).getItem(Pm);if(t===null||!GD.test(t))return null;const e=BigInt(t);return e<BigInt(yg)?yg:e>BigInt(wg)?wg:Number(e)}commit(t){const e=zS(Math.round(t));try{o(this,wo).setItem(Pm,String(e))}catch{}return e}clear(){try{o(this,wo).removeItem(Pm)}catch{}}}wo=new WeakMap;function zS(n){return Math.min(Math.max(n,yg),wg)}const YD="1.4.28";function cv(n=YD){return n!==void 0&&n.length>0?n:"0.0.0"}function uv(){let n=!1;return{get pending(){return n},begin(t){n||(n=!0,t())}}}const bg="tv-reload-attempted";function KD(n){return n.originMatch?n.marker!==null&&n.bundleVersion===n.serverVersion?{action:"signal-autoreloaded",fromVersion:n.marker.fromVersion,toVersion:n.bundleVersion}:Wk(n.bundleVersion,n.serverVersion)?n.marker!==null&&n.marker.serverVersion===n.serverVersion?{action:"none"}:{action:"reload",marker:{serverVersion:n.serverVersion,fromVersion:n.bundleVersion}}:{action:"none"}:{action:"none"}}function XD(n){const t=n.getItem(bg);if(t===null)return null;let e;try{e=JSON.parse(t)}catch{return null}if(!e||typeof e!="object")return null;const r=e;return typeof r.serverVersion!="string"||typeof r.fromVersion!="string"?null:{serverVersion:r.serverVersion,fromVersion:r.fromVersion}}function QD(n){const t=n.storage!==void 0?n.storage:typeof sessionStorage<"u"?sessionStorage:null,e=n.reload??(()=>location.reload()),r=n.navigationLatch??uv(),i=n.bundleVersion??cv();if(t===null)return{dispose(){}};let s=null;const a=()=>{if(s===null)return;const u=n.owner.connection;if(u.url!==n.primaryServerURL||u.status!=="connected")return;const f=s;s=null,u.sendTelemetrySignal("client_autoreloaded",{from_version:f.fromVersion,to_version:f.toVersion})},l=u=>{if(r.pending)return;const f=KD({bundleVersion:i,serverVersion:u.message.version,originMatch:u.serverURL===n.primaryServerURL,marker:XD(t)});switch(f.action){case"reload":t.setItem(bg,JSON.stringify(f.marker)),r.begin(e);return;case"signal-autoreloaded":t.removeItem(bg),s={fromVersion:f.fromVersion,toVersion:f.toVersion},a();return;case"none":return}},c=()=>{a()};return n.owner.addEventListener("server-status",l),n.owner.addEventListener("change",c),{dispose(){n.owner.removeEventListener("server-status",l),n.owner.removeEventListener("change",c)}}}function eL(n){const t=wi(n.search),e=L6(n.search),r=e!==null&&qf(e)?e:null;return{electron:t,shellVersion:r}}function tL(n){return!n.electron||n.requiredDesktopVersion===null||!qf(n.requiredDesktopVersion)?!1:n.shellVersion===null?!0:n.shellVersion===Cd?!1:K1(n.requiredDesktopVersion,n.shellVersion)}const nL=`# Desktop app update required
|
|
66
66
|
|
|
67
67
|
This version of the Television desktop app does not work with this server and needs to be updated. The new version has already downloaded and installs when you restart the app.`,rL=`# Desktop app update required
|
|
68
68
|
|
package/dist/web/index.html
CHANGED
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
|
41
41
|
<link rel="icon" type="image/svg+xml" href="./assets/favicon-DaYMFRha.svg" />
|
|
42
42
|
<title>Television</title>
|
|
43
|
-
<script type="module" crossorigin src="./assets/main-
|
|
43
|
+
<script type="module" crossorigin src="./assets/main-B1UYVUiH.js"></script>
|
|
44
44
|
<link rel="modulepreload" crossorigin href="./assets/artifact-bridge-BEUWXKq7.js">
|
|
45
45
|
<link rel="modulepreload" crossorigin href="./assets/missing-artifact-page-DVzJ41AE.js">
|
|
46
46
|
<link rel="stylesheet" crossorigin href="./assets/main-CunC2_Nx.css">
|