opencami 1.3.2 → 1.4.0
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/client/assets/_sessionKey-DB95zj1L.js +97 -0
- package/dist/client/assets/agents-LFrWe-HX.js +2 -0
- package/dist/client/assets/agents-screen-CEBBk1yO.js +1 -0
- package/dist/client/assets/bots-CxDwf_WK.js +2 -0
- package/dist/client/assets/bots-screen-D6qma1wK.js +1 -0
- package/dist/client/assets/button-Il3CHIzX.js +1 -0
- package/dist/client/assets/{connect-CtDn993i.js → connect-D3baVDFL.js} +1 -1
- package/dist/client/assets/file-explorer-screen-rtV6n-5_.js +1 -0
- package/dist/client/assets/files-DMemuq9D.js +2 -0
- package/dist/client/assets/{index-N9-2R5hZ.js → index-ByIsZcHh.js} +1 -1
- package/dist/client/assets/index-CVV4XiZo.js +153 -0
- package/dist/client/assets/keyboard-shortcuts-dialog-DXC0YHoy.js +1 -0
- package/dist/client/assets/{main-DrVY5UJU.js → main-CkIF0soY.js} +9 -9
- package/dist/client/assets/opencami-logo-CIxSO1oo.js +1 -0
- package/dist/client/assets/{react-CzqI3gbN.js → react-BhVdgA5r.js} +1 -1
- package/dist/client/assets/search-dialog-I1jJplIh.js +1 -0
- package/dist/client/assets/session-export-dialog-CH5unryw.js +1 -0
- package/dist/client/assets/settings-dialog-B8v-GVJ8.js +1 -0
- package/dist/client/assets/styles-BaTVzdPa.css +1 -0
- package/dist/client/assets/switch-sQnv1YsK.js +1 -0
- package/dist/client/assets/tooltip-j_viC_EE.js +1 -0
- package/dist/client/assets/use-file-explorer-state-BUH-u7Jv.js +12 -0
- package/dist/client/assets/useButton-9VAzplAB.js +9 -0
- package/dist/client/assets/useControlled-Y306krcC.js +1 -0
- package/dist/client/assets/useMutation-0WgW4xQJ.js +1 -0
- package/dist/server/assets/{_sessionKey-DVNrEYFh.js → _sessionKey-BhFH4uWY.js} +325 -56
- package/dist/server/assets/_tanstack-start-manifest_v-BaIrL1VQ.js +4 -0
- package/dist/server/assets/bots-6ryCIgKh.js +11 -0
- package/dist/server/assets/bots-screen-DS_ZF9Ec.js +417 -0
- package/dist/server/assets/{connect-CIDOw12K.js → connect-B8jpGQGK.js} +1 -1
- package/dist/server/assets/{file-explorer-screen-Cx0jiLRU.js → file-explorer-screen-DCfS_Ajx.js} +4 -5
- package/dist/server/assets/{files-Trs1M5ba.js → files-D2GIrPF4.js} +1 -1
- package/dist/server/assets/{index-Dv2RXDa2.js → index-B2JHn34C.js} +1 -1
- package/dist/server/assets/{index-CmbNTqa2.js → index-BNSsDaLb.js} +71 -35
- package/dist/server/assets/{keyboard-shortcuts-dialog-7OEtXUlW.js → keyboard-shortcuts-dialog-CqIm8aYF.js} +1 -1
- package/dist/server/assets/{router-OoQe2c20.js → router-Dme7USeO.js} +219 -74
- package/dist/server/assets/{search-dialog-Bq0Pnxdb.js → search-dialog-DG0D9KRN.js} +4 -4
- package/dist/server/assets/{session-export-dialog-DRVbC8Q-.js → session-export-dialog-DLPZVlQV.js} +1 -1
- package/dist/server/assets/{settings-dialog-BsJsnMiu.js → settings-dialog-BaGT4e5l.js} +27 -4
- package/dist/server/assets/{use-file-explorer-state-DMHdtb7D.js → use-file-explorer-state-DfAKF2gZ.js} +12 -0
- package/dist/server/server.js +2 -2
- package/package.json +1 -1
- package/dist/client/assets/_sessionKey-Z6Wcnj0N.js +0 -97
- package/dist/client/assets/agents-D8ZHVQ1Z.js +0 -2
- package/dist/client/assets/agents-screen-BVK0QTRH.js +0 -1
- package/dist/client/assets/button-CuH8u1uR.js +0 -1
- package/dist/client/assets/file-explorer-screen-DMUuR1uG.js +0 -1
- package/dist/client/assets/files-CDMLoJ0u.js +0 -2
- package/dist/client/assets/index-IGP-Igwt.js +0 -153
- package/dist/client/assets/keyboard-shortcuts-dialog-DW--4YLF.js +0 -1
- package/dist/client/assets/opencami-logo-ChD2XR2j.js +0 -1
- package/dist/client/assets/search-dialog-DYyFYJmw.js +0 -1
- package/dist/client/assets/session-export-dialog-BFizBmGb.js +0 -1
- package/dist/client/assets/settings-dialog-UvgVi2It.js +0 -1
- package/dist/client/assets/styles-BGTCU8mq.css +0 -1
- package/dist/client/assets/switch-DxW2OWPG.js +0 -1
- package/dist/client/assets/use-file-explorer-state-Cii59H70.js +0 -12
- package/dist/client/assets/useButton-hZdvKtl_.js +0 -9
- package/dist/server/assets/_tanstack-start-manifest_v-PwRq_yJS.js +0 -4
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/settings-dialog-B8v-GVJ8.js","assets/main-CkIF0soY.js","assets/button-Il3CHIzX.js","assets/use-file-explorer-state-BUH-u7Jv.js","assets/useButton-9VAzplAB.js","assets/tooltip-j_viC_EE.js","assets/react-BhVdgA5r.js","assets/switch-sQnv1YsK.js","assets/useControlled-Y306krcC.js","assets/index-CVV4XiZo.js","assets/useMutation-0WgW4xQJ.js","assets/opencami-logo-CIxSO1oo.js","assets/session-export-dialog-CH5unryw.js","assets/keyboard-shortcuts-dialog-DXC0YHoy.js","assets/search-dialog-I1jJplIh.js"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{j as h,r as m,L as Rt,u as Wt,_ as Bn,g as Gs,a as Vr,b as dl,c as ml,d as gl}from"./main-CkIF0soY.js";import{u as Qs,a as mt,c as Js,t as xl,b as Ze,d as yl,n as bl,m as He,A as ft,e as En}from"./useButton-9VAzplAB.js";import{u as kl,a as wl,T as Pi,t as Zs,b as Sl,A as Xe,c as Cl,d as vl,e as Tn,f as El,g as eo,i as Tl,h as gt,j as xt,k as yt,l as bt,s as dt,m as jl,n as zi}from"./tooltip-j_viC_EE.js";import{B as Ce,u as Al,c as q,f as Yr,a as St,b as Il,H as ee,J as to,V as Hn,d as Rl,e as Nl,g as Ll,h as no,q as Ml,i as Dl,M as Pl,l as Gr,j as pn,I as zl,k as _l,P as Ol,s as ro,m as Fl,A as io,n as $l,o as Bl,X as Qr,x as Hl,p as Ul,D as so,T as ql,r as Jr,t as oo,Q as tr,W as _i,v as Wl,S as Kl,w as Xl,y as Vl}from"./button-Il3CHIzX.js";import{D as ao,a as lo,b as uo,c as Yl,d as co,u as Gl,e as Ql,f as Jl,g as Zl,h as eu,i as tu,j as nu,k as ru,l as iu,m as fo,M as Un,n as qn,o as Wn,p as kt,q as nr}from"./use-file-explorer-state-BUH-u7Jv.js";import{u as su}from"./useControlled-Y306krcC.js";import{u as ho}from"./useMutation-0WgW4xQJ.js";import{O as ou,a as au}from"./opencami-logo-CIxSO1oo.js";import{s as Zr,h as lu,w as uu,f as cu,a as fu,b as hu,c as Oi,r as pu,C as ei,u as du,p as po}from"./index-CVV4XiZo.js";import{c as mo}from"./react-BhVdgA5r.js";const mu={classId:"classID",dataType:"datatype",itemId:"itemID",strokeDashArray:"strokeDasharray",strokeDashOffset:"strokeDashoffset",strokeLineCap:"strokeLinecap",strokeLineJoin:"strokeLinejoin",strokeMiterLimit:"strokeMiterlimit",typeOf:"typeof",xLinkActuate:"xlinkActuate",xLinkArcRole:"xlinkArcrole",xLinkHref:"xlinkHref",xLinkRole:"xlinkRole",xLinkShow:"xlinkShow",xLinkTitle:"xlinkTitle",xLinkType:"xlinkType",xmlnsXLink:"xmlnsXlink"};function Rr(e){if(!e)return"main";const t=e.trim();if(t.length===0)return"main";const n=t.split(":"),i=(n[n.length-1]??"").trim();return i.length>0?i:t}function et(e){return(Array.isArray(e.content)?e.content:[]).map(n=>n.type==="text"?String(n.text??""):"").join("").trim()}function Nt(e){return(Array.isArray(e.content)?e.content:[]).filter(n=>n.type==="toolCall")}function gu(e){if(typeof e=="number"&&Number.isFinite(e))return e<1e12?e*1e3:e;if(typeof e=="string"){const t=Date.parse(e);if(!Number.isNaN(t))return t}return null}function Nr(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const n of t){const r=gu(n);if(r)return r}return Date.now()}const xu=["agent:main:main","main"];function Lr(e){return xu.includes(e)}const yu=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function bu(e){if(e.includes(":subagent:")||e.startsWith("agent:codex:")||e.includes(":openai:"))return"subagent";if(e.startsWith("isolated:")||e.includes(":cron:"))return"cron";if(e.startsWith("agent:")&&!e.startsWith("agent:main:"))return"other";if(e.startsWith("agent:main:")){const t=e.slice(11);return yu.test(t)?"webchat":"chat"}return"other"}function ku(e){return Array.isArray(e)?e.map(t=>{const n=typeof t.key=="string"&&t.key.trim().length>0?t.key.trim():Rr(t.friendlyId??t.key),r=typeof t.friendlyId=="string"&&t.friendlyId.trim().length>0?t.friendlyId.trim():Rr(n),i=bu(n),s=t,o=typeof s.totalTokens=="number"?s.totalTokens:void 0,a=typeof s.contextTokens=="number"?s.contextTokens:void 0,l=typeof s.status=="string"?s.status:void 0;return{key:n,friendlyId:r,title:typeof t.title=="string"?t.title:void 0,derivedTitle:typeof t.derivedTitle=="string"?t.derivedTitle:void 0,label:typeof t.label=="string"?t.label:void 0,updatedAt:typeof t.updatedAt=="number"?t.updatedAt:void 0,lastMessage:t.lastMessage??null,kind:i,status:l,totalTokens:o,contextTokens:a}}):[]}async function it(e){try{const t=await e.json();return t?.error?String(t.error):t?.message?String(t.message):JSON.stringify(t)}catch{try{return await e.text()}catch{return e.statusText||"Request failed"}}}const wu="Missing gateway auth. Set CLAWDBOT_GATEWAY_TOKEN (recommended) or CLAWDBOT_GATEWAY_PASSWORD in the server environment.";function Fi(e){return e.includes(wu)}function $i(e,t){const n=crypto.randomUUID(),r=`opt-${n}`,i=Date.now(),s=[];if(t&&t.length>0)for(const a of t)a.type==="image"&&a.base64&&s.push({type:"image",source:{type:"base64",media_type:a.file.type,data:a.base64}});return e.trim()?s.push({type:"text",text:e}):t&&t.length>0&&s.push({type:"text",text:""}),{clientId:n,optimisticId:r,optimisticMessage:{role:"user",content:s,__optimisticId:r,clientId:n,status:"sending",timestamp:i}}}const be={sessions:["chat","sessions"],history:function(t,n){return["chat","history",t,n]}};async function Su(){const e=await fetch("/api/sessions");if(!e.ok)throw new Error(await it(e));const t=await e.json();return ku(t.sessions)}async function Cu(e){const t=new URLSearchParams({limit:"200"});e.sessionKey&&t.set("sessionKey",e.sessionKey),e.friendlyId&&t.set("friendlyId",e.friendlyId);const n=await fetch(`/api/history?${t.toString()}`);if(!n.ok)throw new Error(await it(n));return await n.json()}async function vu(){const e=new AbortController,t=window.setTimeout(()=>e.abort(),2500);try{const n=await fetch("/api/ping",{signal:e.signal});if(!n.ok)throw new Error(await it(n));return await n.json()}catch(n){throw n instanceof DOMException&&n.name==="AbortError"?new Error("Gateway check timed out"):n}finally{window.clearTimeout(t)}}function ti(e,t,n,r){const i=be.history(t,n);e.setQueryData(i,function(o){const a=o,l=Array.isArray(a?.messages)?a.messages:[],u=r(l);return{sessionKey:a?.sessionKey??n,sessionId:a?.sessionId,messages:u}})}function rr(e,t,n,r){ti(e,t,n,function(s){return[...s,r]})}function Eu(e,t,n,r,i){const s=`opt-${r}`;ti(e,t,n,function(a){return a.map(l=>l.clientId===r||l.__optimisticId===r||l.__optimisticId===s?i(l):l)})}function Tu(e,t,n,r,i){ti(e,t,n,function(o){return o.filter(a=>!(a.clientId===r||a.__optimisticId===r||i&&a.__optimisticId===i))})}function Mr(e,t,n){const r=be.history(t,n);e.setQueryData(r,{sessionKey:n,messages:[]})}function ju(e,t,n,r,i){const s=be.history(t,n),o=be.history(r,i),a=e.getQueryData(s);if(!a)return;const l=Array.isArray(a.messages)?a.messages:[];e.setQueryData(o,{sessionKey:i,sessionId:a.sessionId,messages:l}),e.removeQueries({queryKey:s,exact:!0})}function Au(e,t,n,r){e.setQueryData(be.sessions,function(s){return Array.isArray(s)?s.map(o=>o.key!==t&&o.friendlyId!==n?o:{...o,lastMessage:r}):s})}function Iu(e,t,n){e.setQueryData(be.sessions,function(i){return Array.isArray(i)?i.filter(s=>s.key!==t&&s.friendlyId!==n):i}),e.removeQueries({queryKey:["chat","history",n],exact:!1}),t&&t!==n&&e.removeQueries({queryKey:["chat","history",t],exact:!1})}async function Ru(e,t,n,r){e.setQueryData(be.sessions,function(s){return Array.isArray(s)?s.map(o=>o.key===t||o.friendlyId===n?{...o,label:r}:o):s});try{const i=await fetch("/api/sessions",{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionKey:t,friendlyId:n,label:r})});if(!i.ok){const s=await it(i);console.error("[updateSessionLabel] Failed to persist:",s)}}catch(i){console.error("[updateSessionLabel] Network error:",i)}}function go(e){return!e.content||!Array.isArray(e.content)?"":e.content.filter(t=>t.type==="text").map(t=>t.text||"").join(`
|
|
3
|
+
`)}function Nu(e,t,n){const r=[];r.push(`# Conversation: ${e}`),r.push(`Date: ${n.toLocaleString()}`),r.push("");for(const i of t){const s=i.role||"unknown",o=go(i);if(o){const a=s==="user"?"User":"Assistant";r.push(`## ${a}`),r.push(""),r.push(o),r.push("")}}return r.join(`
|
|
4
|
+
`)}function Lu(e,t,n){const r={title:e,exportDate:n.toISOString(),messages:t.map(i=>({role:i.role,content:i.content,timestamp:i.timestamp}))};return JSON.stringify(r,null,2)}function Mu(e,t,n){const r=[];r.push(`Conversation: ${e}`),r.push(`Date: ${n.toLocaleString()}`),r.push("─".repeat(60)),r.push("");for(const i of t){const s=i.role||"unknown",o=go(i);if(o){const a=s==="user"?"User":"Assistant";r.push(`${a}:`),r.push(o),r.push("")}}return r.join(`
|
|
5
|
+
`)}function Du(e,t,n){const r=new Date;let i,s,o;switch(n){case"markdown":i=Nu(e,t,r),s=`${ir(e)}.md`,o="text/markdown";break;case"json":i=Lu(e,t,r),s=`${ir(e)}.json`,o="application/json";break;case"txt":i=Mu(e,t,r),s=`${ir(e)}.txt`,o="text/plain";break;default:throw new Error(`Unsupported format: ${n}`)}Pu(i,s,o)}function ir(e){return e.replace(/[^a-z0-9-_\s]/gi,"").replace(/\s+/g,"-").toLowerCase().slice(0,50)||"conversation"}function Pu(e,t,n){const r=new Blob([e],{type:n}),i=URL.createObjectURL(r),s=document.createElement("a");s.href=i,s.download=t,document.body.appendChild(s),s.click(),document.body.removeChild(s),URL.revokeObjectURL(i)}function zu({open:e,onOpenChange:t,sessionTitle:n,onSave:r,onCancel:i}){return h.jsx(ao,{open:e,onOpenChange:t,children:h.jsx(lo,{children:h.jsxs("div",{className:"p-4",children:[h.jsx(uo,{className:"mb-1",children:"Rename"}),h.jsx(Yl,{className:"mb-4",children:"Enter a new name for this session."}),h.jsx("input",{type:"text",defaultValue:n,onKeyDown:s=>{s.key==="Enter"&&(s.preventDefault(),r(s.currentTarget.value))},className:"w-full rounded-lg border border-primary-200 bg-primary-50 px-3 py-2 text-sm text-primary-900 outline-none focus:border-primary-400",placeholder:"Session name",autoFocus:!0}),h.jsxs("div",{className:"mt-4 flex justify-end gap-2",children:[h.jsx(co,{onClick:i,children:"Cancel"}),h.jsx(Ce,{onClick:s=>{const o=s.currentTarget.parentElement?.previousElementSibling;r(o.value)},children:"Save"})]})]})})})}function _u(e){const{children:t,open:n,defaultOpen:r=!1,onOpenChange:i,onOpenChangeComplete:s,actionsRef:o,handle:a,triggerId:l,defaultTriggerId:u=null}=e,c=Gl(),f=!!c,p=Al(()=>a?.store??new Ql({open:n??r,activeTriggerId:l!==void 0?l:u,modal:!0,disablePointerDismissal:!0,nested:f,role:"alertdialog"})).current;p.useControlledProp("open",n,r),p.useControlledProp("activeTriggerId",l,u),p.useSyncedValue("nested",f),p.useContextCallback("onOpenChange",i),p.useContextCallback("onOpenChangeComplete",s);const d=p.useState("payload");Jl({store:p,actionsRef:o,parentContext:c?.store.context});const g=m.useMemo(()=>({store:p}),[p]);return h.jsx(Zl.Provider,{value:g,children:typeof t=="function"?t({payload:d}):t})}function Ou({children:e,...t}){return h.jsx(_u,{...t,children:e})}function Fu({className:e,children:t}){return h.jsxs(eu,{children:[h.jsx(tu,{className:"fixed inset-0 bg-primary-950/20 transition-all duration-150 data-[state=open]:opacity-100 data-[state=closed]:opacity-0"}),h.jsx(nu,{className:q("fixed left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2","w-[min(400px,92vw)] rounded-xl border border-primary-200 bg-primary-50 p-0 shadow-xl","transition-all duration-150","data-[state=open]:opacity-100 data-[state=closed]:opacity-0","data-[state=open]:scale-100 data-[state=closed]:scale-95",e),children:t})]})}function $u({className:e,...t}){return h.jsx(ru,{className:q("text-lg font-medium text-primary-900",e),...t})}function Bu({className:e,...t}){return h.jsx(iu,{className:q("text-sm text-primary-600",e),...t})}function Hu({className:e,...t}){return h.jsx(fo,{render:h.jsx(Ce,{variant:"outline",className:q(e)}),...t})}function Uu({className:e,...t}){return h.jsx(fo,{render:h.jsx(Ce,{variant:"destructive",className:q(e)}),...t})}function qu({open:e,onOpenChange:t,sessionTitle:n,onConfirm:r,onCancel:i}){return h.jsx(Ou,{open:e,onOpenChange:t,children:h.jsx(Fu,{children:h.jsxs("div",{className:"p-4",children:[h.jsx($u,{className:"mb-1",children:"Delete Session"}),h.jsxs(Bu,{className:"mb-4",children:['Are you sure you want to delete "',n,'"? This action cannot be undone.']}),h.jsxs("div",{className:"flex justify-end gap-2",children:[h.jsx(Hu,{onClick:i,children:"Cancel"}),h.jsx(Uu,{onClick:r,children:"Delete"})]})]})})})}function Wu(e){const{open:t,defaultOpen:n,onOpenChange:r,disabled:i}=e,s=t!==void 0,[o,a]=su({controlled:t,default:n,name:"Collapsible",state:"open"}),{mounted:l,setMounted:u,transitionStatus:c}=kl(o,!0,!0),[f,p]=m.useState(o),[{height:d,width:g},x]=m.useState({height:void 0,width:void 0}),w=Qs(),[b,S]=m.useState(),v=b??w,[R,M]=m.useState(!1),[C,P]=m.useState(!1),U=m.useRef(null),F=m.useRef(null),E=m.useRef(null),N=m.useRef(null),A=wl(N,!1),z=mt(j=>{const T=!o,D=Js(xl,j.nativeEvent);if(r(T,D),D.isCanceled)return;const L=N.current;F.current==="css-animation"&&L!=null&&L.style.removeProperty("animation-name"),!R&&!C&&(F.current!=null&&F.current!=="css-animation"&&!l&&T&&u(!0),F.current==="css-animation"&&(!f&&T&&p(!0),!l&&T&&u(!0))),a(T),F.current==="none"&&l&&!T&&u(!1)});return Ze(()=>{s&&F.current==="none"&&!C&&!o&&u(!1)},[s,C,o,t,u]),m.useMemo(()=>({abortControllerRef:U,animationTypeRef:F,disabled:i,handleTrigger:z,height:d,mounted:l,open:o,panelId:v,panelRef:N,runOnceAnimationsFinish:A,setDimensions:x,setHiddenUntilFound:M,setKeepMounted:P,setMounted:u,setOpen:a,setPanelIdState:S,setVisible:p,transitionDimensionRef:E,transitionStatus:c,visible:f,width:g}),[U,F,i,z,d,l,o,v,N,A,x,M,P,u,a,p,E,c,f,g])}const xo=m.createContext(void 0);function yo(){const e=m.useContext(xo);if(e===void 0)throw new Error(Yr(15));return e}let nn=(function(e){return e.open="data-open",e.closed="data-closed",e[e.startingStyle=Pi.startingStyle]="startingStyle",e[e.endingStyle=Pi.endingStyle]="endingStyle",e})({}),Ku=(function(e){return e.panelOpen="data-panel-open",e})({});const Xu={[nn.open]:""},Vu={[nn.closed]:""},Yu={open(e){return e?{[Ku.panelOpen]:""}:null}},Gu={open(e){return e?Xu:Vu}},bo={...Gu,...Zs},Qu=m.forwardRef(function(t,n){const{render:r,className:i,defaultOpen:s=!1,disabled:o=!1,onOpenChange:a,open:l,...u}=t,c=mt(a),f=Wu({open:l,defaultOpen:s,onOpenChange:c,disabled:o}),p=m.useMemo(()=>({open:f.open,disabled:f.disabled,transitionStatus:f.transitionStatus}),[f.open,f.disabled,f.transitionStatus]),d=m.useMemo(()=>({...f,onOpenChange:c,state:p}),[f,c,p]),g=St("div",t,{state:p,ref:n,props:u,stateAttributesMapping:bo});return h.jsx(xo.Provider,{value:d,children:g})}),Ju={...Yu,...Zs},Zu=m.forwardRef(function(t,n){const{panelId:r,open:i,handleTrigger:s,state:o,disabled:a}=yo(),{className:l,disabled:u=a,id:c,render:f,nativeButton:p=!0,...d}=t,{getButtonProps:g,buttonRef:x}=yl({disabled:u,focusableWhenDisabled:!0,native:p}),w=m.useMemo(()=>({"aria-controls":i?r:void 0,"aria-expanded":i,onClick:s}),[r,i,s]);return St("button",t,{state:o,ref:[n,x],props:[w,d,g],stateAttributesMapping:Ju})});let ec=(function(e){return e.disabled="data-disabled",e.orientation="data-orientation",e})({});function tc(e){const{abortControllerRef:t,animationTypeRef:n,externalRef:r,height:i,hiddenUntilFound:s,keepMounted:o,id:a,mounted:l,onOpenChange:u,open:c,panelRef:f,runOnceAnimationsFinish:p,setDimensions:d,setMounted:g,setOpen:x,setVisible:w,transitionDimensionRef:b,visible:S,width:v}=e,R=m.useRef(!1),M=m.useRef(null),C=m.useRef(c),P=m.useRef(c),U=Sl(),F=m.useMemo(()=>n.current==="css-animation"?!S:!c&&!l,[c,l,S,n]),E=mt(A=>{if(!A)return;if(n.current==null||b.current==null){const T=getComputedStyle(A),D=T.animationName!=="none"&&T.animationName!=="",L=T.transitionDuration!=="0s"&&T.transitionDuration!=="";D&&L||(T.animationName==="none"&&T.transitionDuration!=="0s"?n.current="css-transition":T.animationName!=="none"&&T.transitionDuration==="0s"?n.current="css-animation":n.current="none"),A.getAttribute(ec.orientation)==="horizontal"||T.transitionProperty.indexOf("width")>-1?b.current="width":b.current="height"}if(n.current!=="css-transition")return;(i===void 0||v===void 0)&&(d({height:A.scrollHeight,width:A.scrollWidth}),P.current&&A.style.setProperty("transition-duration","0s"));let z=-1,j=-1;return z=Xe.request(()=>{P.current=!1,j=Xe.request(()=>{setTimeout(()=>{A.style.removeProperty("transition-duration")})})}),()=>{Xe.cancel(z),Xe.cancel(j)}}),N=Il(r,f,E);return Ze(()=>{if(n.current!=="css-transition")return;const A=f.current;if(!A)return;let z=-1;if(t.current!=null&&(t.current.abort(),t.current=null),c){const j={"justify-content":A.style.justifyContent,"align-items":A.style.alignItems,"align-content":A.style.alignContent,"justify-items":A.style.justifyItems};Object.keys(j).forEach(T=>{A.style.setProperty(T,"initial","important")}),!P.current&&!o&&A.setAttribute(nn.startingStyle,""),d({height:A.scrollHeight,width:A.scrollWidth}),z=Xe.request(()=>{Object.entries(j).forEach(([T,D])=>{D===""?A.style.removeProperty(T):A.style.setProperty(T,D)})})}else{if(A.scrollHeight===0&&A.scrollWidth===0)return;d({height:A.scrollHeight,width:A.scrollWidth});const j=new AbortController;t.current=j;const T=j.signal;let D=null;const L=nn.endingStyle;return D=new MutationObserver(H=>{H.some(y=>y.type==="attributes"&&y.attributeName===L)&&(D?.disconnect(),D=null,p(()=>{d({height:0,width:0}),A.style.removeProperty("content-visibility"),g(!1),t.current===j&&(t.current=null)},T))}),D.observe(A,{attributes:!0,attributeFilter:[L]}),()=>{D?.disconnect(),U.cancel(),t.current===j&&(j.abort(),t.current=null)}}return()=>{Xe.cancel(z)}},[t,n,U,s,o,l,c,f,p,d,g]),Ze(()=>{if(n.current!=="css-animation")return;const A=f.current;A&&(M.current=A.style.animationName||M.current,A.style.setProperty("animation-name","none"),d({height:A.scrollHeight,width:A.scrollWidth}),!C.current&&!R.current&&A.style.removeProperty("animation-name"),c?(t.current!=null&&(t.current.abort(),t.current=null),g(!0),w(!0)):(t.current=new AbortController,p(()=>{g(!1),w(!1),t.current=null},t.current.signal)))},[t,n,c,f,p,d,g,w,S]),Cl(()=>{const A=Xe.request(()=>{C.current=!1});return()=>Xe.cancel(A)}),Ze(()=>{if(!s)return;const A=f.current;if(!A)return;let z=-1,j=-1;return c&&R.current&&(A.style.transitionDuration="0s",d({height:A.scrollHeight,width:A.scrollWidth}),z=Xe.request(()=>{R.current=!1,j=Xe.request(()=>{setTimeout(()=>{A.style.removeProperty("transition-duration")})})})),()=>{Xe.cancel(z),Xe.cancel(j)}},[s,c,f,d]),Ze(()=>{const A=f.current;A&&s&&F&&(A.setAttribute("hidden","until-found"),n.current==="css-transition"&&A.setAttribute(nn.startingStyle,""))},[s,F,n,f]),m.useEffect(function(){const z=f.current;if(!z)return;function j(T){R.current=!0,x(!0),u(!0,Js(bl,T))}return z.addEventListener("beforematch",j),()=>{z.removeEventListener("beforematch",j)}},[u,f,x]),m.useMemo(()=>({props:{hidden:F,id:a,ref:N}}),[F,a,N])}let Bi=(function(e){return e.collapsiblePanelHeight="--collapsible-panel-height",e.collapsiblePanelWidth="--collapsible-panel-width",e})({});const nc=m.forwardRef(function(t,n){const{className:r,hiddenUntilFound:i,keepMounted:s,render:o,id:a,...l}=t,{abortControllerRef:u,animationTypeRef:c,height:f,mounted:p,onOpenChange:d,open:g,panelId:x,panelRef:w,runOnceAnimationsFinish:b,setDimensions:S,setHiddenUntilFound:v,setKeepMounted:R,setMounted:M,setPanelIdState:C,setOpen:P,setVisible:U,state:F,transitionDimensionRef:E,visible:N,width:A,transitionStatus:z}=yo(),j=i??!1,T=s??!1;Ze(()=>{if(a)return C(a),()=>{C(void 0)}},[a,C]),Ze(()=>{v(j)},[v,j]),Ze(()=>{R(T)},[R,T]);const{props:D}=tc({abortControllerRef:u,animationTypeRef:c,externalRef:n,height:f,hiddenUntilFound:j,id:x,keepMounted:T,mounted:p,onOpenChange:d,open:g,panelRef:w,runOnceAnimationsFinish:b,setDimensions:S,setMounted:M,setOpen:P,setVisible:U,transitionDimensionRef:E,visible:N,width:A});vl({open:g&&z==="idle",ref:w,onComplete(){g&&S({height:void 0,width:void 0})}});const L=m.useMemo(()=>({...F,transitionStatus:z}),[F,z]),H=St("div",t,{state:L,ref:[n,w],props:[D,{style:{[Bi.collapsiblePanelHeight]:f===void 0?"auto":`${f}px`,[Bi.collapsiblePanelWidth]:A===void 0?"auto":`${A}px`}},l],stateAttributesMapping:bo});return T||j||!T&&p?H:null});function jn(e){return h.jsx(Qu,{...e})}function An({className:e,...t}){return h.jsx(Zu,{className:q("group inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-left text-xs font-medium text-primary-500 transition-colors hover:bg-primary-100 hover:text-primary-700 data-panel-open:text-primary-700",e),...t})}function In({className:e,contentClassName:t,children:n,...r}){return h.jsx(nc,{className:q('flex h-(--collapsible-panel-height) flex-col overflow-hidden text-sm transition-all duration-150 ease-out data-ending-style:h-0 data-starting-style:h-0 [&[hidden]:not([hidden="until-found"])]:hidden',e),...r,children:h.jsx("div",{className:q("pt-1",t),children:n})})}const ko=m.createContext(void 0);function Kn(){const e=m.useContext(ko);if(e===void 0)throw new Error(Yr(53));return e}let Rn=(function(e){return e.scrollAreaCornerHeight="--scroll-area-corner-height",e.scrollAreaCornerWidth="--scroll-area-corner-width",e})({});const dn=500,Hi=16;function Ye(e,t,n){if(!e)return 0;const r=getComputedStyle(e),i=n==="x"?"Inline":"Block";return n==="x"&&t==="margin"?parseFloat(r[`${t}InlineStart`])*2:parseFloat(r[`${t}${i}Start`])+parseFloat(r[`${t}${i}End`])}let rc=(function(e){return e.orientation="data-orientation",e.hovering="data-hovering",e.scrolling="data-scrolling",e.hasOverflowX="data-has-overflow-x",e.hasOverflowY="data-has-overflow-y",e.overflowXStart="data-overflow-x-start",e.overflowXEnd="data-overflow-x-end",e.overflowYStart="data-overflow-y-start",e.overflowYEnd="data-overflow-y-end",e})({});const mn="base-ui-disable-scrollbar",wo={className:mn,getElement(e){return h.jsx("style",{nonce:e,href:mn,precedence:"base-ui:low",children:`.${mn}{scrollbar-width:none}.${mn}::-webkit-scrollbar{display:none}`})}};let Ot=(function(e){return e.hasOverflowX="data-has-overflow-x",e.hasOverflowY="data-has-overflow-y",e.overflowXStart="data-overflow-x-start",e.overflowXEnd="data-overflow-x-end",e.overflowYStart="data-overflow-y-start",e.overflowYEnd="data-overflow-y-end",e})({});const ni={hasOverflowX:e=>e?{[Ot.hasOverflowX]:""}:null,hasOverflowY:e=>e?{[Ot.hasOverflowY]:""}:null,overflowXStart:e=>e?{[Ot.overflowXStart]:""}:null,overflowXEnd:e=>e?{[Ot.overflowXEnd]:""}:null,overflowYStart:e=>e?{[Ot.overflowYStart]:""}:null,overflowYEnd:e=>e?{[Ot.overflowYEnd]:""}:null,cornerHidden:()=>null},ic=m.createContext(void 0),sc={disableStyleElements:!1};function oc(){return m.useContext(ic)??sc}const ac={x:0,y:0},Ui={width:0,height:0},lc={xStart:!1,xEnd:!1,yStart:!1,yEnd:!1},uc={x:!1,y:!1,corner:!1},cc=m.forwardRef(function(t,n){const{render:r,className:i,overflowEdgeThreshold:s,...o}=t,a=fc(s),l=Qs(),u=Tn(),c=Tn(),{nonce:f,disableStyleElements:p}=oc(),[d,g]=m.useState(!1),[x,w]=m.useState(!1),[b,S]=m.useState(!1),[v,R]=m.useState(!1),[M,C]=m.useState(Ui),[P,U]=m.useState(Ui),[F,E]=m.useState(lc),[N,A]=m.useState(uc),z=m.useRef(null),j=m.useRef(null),T=m.useRef(null),D=m.useRef(null),L=m.useRef(null),H=m.useRef(null),_=m.useRef(null),y=m.useRef(!1),X=m.useRef(0),V=m.useRef(0),k=m.useRef(0),Q=m.useRef(0),re=m.useRef("vertical"),W=m.useRef(ac),he=mt($=>{const J=$.x-W.current.x,xe=$.y-W.current.y;W.current=$,xe!==0&&(S(!0),u.start(dn,()=>{S(!1)})),J!==0&&(w(!0),c.start(dn,()=>{w(!1)}))}),me=mt($=>{$.button===0&&(y.current=!0,X.current=$.clientY,V.current=$.clientX,re.current=$.currentTarget.getAttribute(rc.orientation),j.current&&(k.current=j.current.scrollTop,Q.current=j.current.scrollLeft),L.current&&re.current==="vertical"&&L.current.setPointerCapture($.pointerId),H.current&&re.current==="horizontal"&&H.current.setPointerCapture($.pointerId))}),ue=mt($=>{if(!y.current)return;const J=$.clientY-X.current,xe=$.clientX-V.current;if(j.current){const ne=j.current.scrollHeight,pe=j.current.clientHeight,Oe=j.current.scrollWidth,Fe=j.current.clientWidth;if(L.current&&T.current&&re.current==="vertical"){const Ae=Ye(T.current,"padding","y"),$e=Ye(L.current,"margin","y"),I=L.current.offsetHeight,O=T.current.offsetHeight-I-Ae-$e,Y=J/O;j.current.scrollTop=k.current+Y*(ne-pe),$.preventDefault(),S(!0),u.start(dn,()=>{S(!1)})}if(H.current&&D.current&&re.current==="horizontal"){const Ae=Ye(D.current,"padding","x"),$e=Ye(H.current,"margin","x"),I=H.current.offsetWidth,O=D.current.offsetWidth-I-Ae-$e,Y=xe/O;j.current.scrollLeft=Q.current+Y*(Oe-Fe),$.preventDefault(),w(!0),c.start(dn,()=>{w(!1)})}}}),se=mt($=>{y.current=!1,L.current&&re.current==="vertical"&&L.current.releasePointerCapture($.pointerId),H.current&&re.current==="horizontal"&&H.current.releasePointerCapture($.pointerId)});function ge($){R($.pointerType==="touch")}function ke($){if(ge($),$.pointerType!=="touch"){const J=El(z.current,$.target);g(J)}}const we=m.useMemo(()=>({hasOverflowX:!N.x,hasOverflowY:!N.y,overflowXStart:F.xStart,overflowXEnd:F.xEnd,overflowYStart:F.yStart,overflowYEnd:F.yEnd,cornerHidden:N.corner}),[N.x,N.y,N.corner,F]),Se={role:"presentation",onPointerEnter:ke,onPointerMove:ke,onPointerDown:ge,onPointerLeave(){g(!1)},style:{position:"relative",[Rn.scrollAreaCornerHeight]:`${M.height}px`,[Rn.scrollAreaCornerWidth]:`${M.width}px`}},Le=St("div",t,{state:we,ref:[n,z],props:[Se,o],stateAttributesMapping:ni}),K=m.useMemo(()=>({handlePointerDown:me,handlePointerMove:ue,handlePointerUp:se,handleScroll:he,cornerSize:M,setCornerSize:C,thumbSize:P,setThumbSize:U,touchModality:v,cornerRef:_,scrollingX:x,setScrollingX:w,scrollingY:b,setScrollingY:S,hovering:d,setHovering:g,viewportRef:j,rootRef:z,scrollbarYRef:T,scrollbarXRef:D,thumbYRef:L,thumbXRef:H,rootId:l,hiddenState:N,setHiddenState:A,overflowEdges:F,setOverflowEdges:E,viewportState:we,overflowEdgeThreshold:a}),[me,ue,se,he,M,P,v,x,w,b,S,d,g,l,N,F,we,a]);return h.jsxs(ko.Provider,{value:K,children:[!p&&wo.getElement(f),Le]})});function fc(e){if(typeof e=="number"){const t=Math.max(0,e);return{xStart:t,xEnd:t,yStart:t,yEnd:t}}return{xStart:Math.max(0,e?.xStart||0),xEnd:Math.max(0,e?.xEnd||0),yStart:Math.max(0,e?.yStart||0),yEnd:Math.max(0,e?.yEnd||0)}}const hc=m.createContext(void 0);function ot(e,t=Number.MIN_SAFE_INTEGER,n=Number.MAX_SAFE_INTEGER){return Math.max(t,Math.min(e,n))}function pc(e,t){if(typeof IntersectionObserver>"u")return()=>{};const n=new IntersectionObserver(r=>{r.forEach(i=>{i.intersectionRatio>0&&(t(),n.disconnect())})});return n.observe(e),()=>{n.disconnect()}}let wt=(function(e){return e.scrollAreaOverflowXStart="--scroll-area-overflow-x-start",e.scrollAreaOverflowXEnd="--scroll-area-overflow-x-end",e.scrollAreaOverflowYStart="--scroll-area-overflow-y-start",e.scrollAreaOverflowYEnd="--scroll-area-overflow-y-end",e})({}),qi=!1;function dc(){qi||Tl||(typeof CSS<"u"&&"registerProperty"in CSS&&[wt.scrollAreaOverflowXStart,wt.scrollAreaOverflowXEnd,wt.scrollAreaOverflowYStart,wt.scrollAreaOverflowYEnd].forEach(e=>{try{CSS.registerProperty({name:e,syntax:"<length>",inherits:!1,initialValue:"0px"})}catch{}}),qi=!0)}const mc=m.forwardRef(function(t,n){const{render:r,className:i,...s}=t,{viewportRef:o,scrollbarYRef:a,scrollbarXRef:l,thumbYRef:u,thumbXRef:c,cornerRef:f,cornerSize:p,setCornerSize:d,setThumbSize:g,rootId:x,setHiddenState:w,hiddenState:b,handleScroll:S,setHovering:v,setOverflowEdges:R,overflowEdges:M,overflowEdgeThreshold:C}=Kn(),P=eo(),U=m.useRef(!0),F=Tn(),E=Tn(),N=mt(()=>{const L=o.current,H=a.current,_=l.current,y=u.current,X=c.current,V=f.current;if(!L)return;const k=L.scrollHeight,Q=L.scrollWidth,re=L.clientHeight,W=L.clientWidth,he=L.scrollTop,me=L.scrollLeft;if(k===0||Q===0)return;const ue=re>=k,se=W>=Q,ge=W/Q,ke=re/k,we=Math.max(0,Q-W),Se=Math.max(0,k-re);let Le=0,K=0;se||(P==="rtl"?Le=ot(-me,0,we):Le=ot(me,0,we),K=we-Le);const $=ue?0:ot(he,0,Se),J=ue?0:Se-$,xe=se?0:W,ne=ue?0:re;let pe=0,Oe=0;!se&&!ue&&(pe=H?.offsetWidth||0,Oe=_?.offsetHeight||0);const Fe=p.width===0&&p.height===0,Ae=Fe?pe:0,$e=Fe?Oe:0,I=Ye(_,"padding","x"),O=Ye(H,"padding","y"),Y=Ye(X,"margin","x"),te=Ye(y,"margin","y"),ae=xe-I-Y,Ee=ne-O-te,We=_?Math.min(_.offsetWidth-Ae,ae):ae,Be=H?Math.min(H.offsetHeight-$e,Ee):Ee,Ge=Math.max(Hi,We*ge),Ke=Math.max(Hi,Be*ke);if(g(de=>de.height===Ke&&de.width===Ge?de:{width:Ge,height:Ke}),H&&y){const de=H.offsetHeight-Ke-O-te,je=k-re,Tt=je===0?0:he/je,ut=Math.min(de,Math.max(0,Tt*de));y.style.transform=`translate3d(0,${ut}px,0)`}if(_&&X){const de=_.offsetWidth-Ge-I-Y,je=Q-W,Tt=je===0?0:me/je,ut=P==="rtl"?ot(Tt*de,-de,0):ot(Tt*de,0,de);X.style.transform=`translate3d(${ut}px,0,0)`}const ve=ot(Le,0,we),Te=ot(K,0,we),Pe=ot($,0,Se),vt=ot(J,0,Se),zt=[[wt.scrollAreaOverflowXStart,ve],[wt.scrollAreaOverflowXEnd,Te],[wt.scrollAreaOverflowYStart,Pe],[wt.scrollAreaOverflowYEnd,vt]];for(const[de,je]of zt)L.style.setProperty(de,`${je}px`);V&&(se||ue?d({width:0,height:0}):!se&&!ue&&d({width:pe,height:Oe})),w(de=>{const je=ue||se;return de.y===ue&&de.x===se&&de.corner===je?de:{y:ue,x:se,corner:je}});const Et={xStart:!se&&ve>C.xStart,xEnd:!se&&Te>C.xEnd,yStart:!ue&&Pe>C.yStart,yEnd:!ue&&vt>C.yEnd};R(de=>de.xStart===Et.xStart&&de.xEnd===Et.xEnd&&de.yStart===Et.yStart&&de.yEnd===Et.yEnd?de:Et)});Ze(()=>{if(!o.current)return;dc();let L=!1;return pc(o.current,()=>{if(!L){L=!0;return}N()})},[N,o]),Ze(()=>{queueMicrotask(N)},[N,b,P]),Ze(()=>{o.current?.matches(":hover")&&v(!0)},[o,v]),m.useEffect(()=>{const L=o.current;if(typeof ResizeObserver>"u"||!L)return;let H=!1;const _=new ResizeObserver(()=>{if(!H){H=!0;return}N()});return _.observe(L),E.start(0,()=>{const y=L.getAnimations({subtree:!0});y.length!==0&&Promise.all(y.map(X=>X.finished)).then(N).catch(()=>{})}),()=>{_.disconnect(),E.clear()}},[N,o,E]);function A(){U.current=!1}const z={role:"presentation",...x&&{"data-id":`${x}-viewport`},...(!b.x||!b.y)&&{tabIndex:0},className:wo.className,style:{overflow:"scroll"},onScroll(){o.current&&(N(),U.current||S({x:o.current.scrollLeft,y:o.current.scrollTop}),F.start(100,()=>{U.current=!0}))},onWheel:A,onTouchMove:A,onPointerMove:A,onPointerEnter:A,onKeyDown:A},j=m.useMemo(()=>({hasOverflowX:!b.x,hasOverflowY:!b.y,overflowXStart:M.xStart,overflowXEnd:M.xEnd,overflowYStart:M.yStart,overflowYEnd:M.yEnd,cornerHidden:b.corner}),[b.x,b.y,b.corner,M]),T=St("div",t,{ref:[n,o],state:j,props:[z,s],stateAttributesMapping:ni}),D=m.useMemo(()=>({computeThumbPosition:N}),[N]);return h.jsx(hc.Provider,{value:D,children:T})}),So=m.createContext(void 0);function gc(){const e=m.useContext(So);if(e===void 0)throw new Error(Yr(54));return e}let Nn=(function(e){return e.scrollAreaThumbHeight="--scroll-area-thumb-height",e.scrollAreaThumbWidth="--scroll-area-thumb-width",e})({});const xc=m.forwardRef(function(t,n){const{render:r,className:i,orientation:s="vertical",keepMounted:o=!1,...a}=t,{hovering:l,scrollingX:u,scrollingY:c,hiddenState:f,overflowEdges:p,scrollbarYRef:d,scrollbarXRef:g,viewportRef:x,thumbYRef:w,thumbXRef:b,handlePointerDown:S,handlePointerUp:v,rootId:R,thumbSize:M}=Kn(),C=m.useMemo(()=>({hovering:l,scrolling:{horizontal:u,vertical:c}[s],orientation:s,hasOverflowX:!f.x,hasOverflowY:!f.y,overflowXStart:p.xStart,overflowXEnd:p.xEnd,overflowYStart:p.yStart,overflowYEnd:p.yEnd,cornerHidden:f.corner}),[l,u,c,s,f,p]),P=eo();m.useEffect(()=>{const z=x.current,j=s==="vertical"?d.current:g.current;if(!j)return;function T(D){if(!(!z||!j||D.ctrlKey)){if(D.preventDefault(),s==="vertical"){if(z.scrollTop===0&&D.deltaY<0)return}else if(z.scrollLeft===0&&D.deltaX<0)return;if(s==="vertical"){if(z.scrollTop===z.scrollHeight-z.clientHeight&&D.deltaY>0)return}else if(z.scrollLeft===z.scrollWidth-z.clientWidth&&D.deltaX>0)return;s==="vertical"?z.scrollTop+=D.deltaY:z.scrollLeft+=D.deltaX}}return j.addEventListener("wheel",T,{passive:!1}),()=>{j.removeEventListener("wheel",T)}},[s,g,d,x]);const U={...R&&{"data-id":`${R}-scrollbar`},onPointerDown(z){if(z.button===0&&z.currentTarget===z.target&&x.current){if(w.current&&d.current&&s==="vertical"){const j=Ye(w.current,"margin","y"),T=Ye(d.current,"padding","y"),D=w.current.offsetHeight,L=d.current.getBoundingClientRect(),H=z.clientY-L.top-D/2-T+j/2,_=x.current.scrollHeight,y=x.current.clientHeight,X=d.current.offsetHeight-D-T-j,k=H/X*(_-y);x.current.scrollTop=k}if(b.current&&g.current&&s==="horizontal"){const j=Ye(b.current,"margin","x"),T=Ye(g.current,"padding","x"),D=b.current.offsetWidth,L=g.current.getBoundingClientRect(),H=z.clientX-L.left-D/2-T+j/2,_=x.current.scrollWidth,y=x.current.clientWidth,X=g.current.offsetWidth-D-T-j,V=H/X;let k;P==="rtl"?(k=(1-V)*(_-y),x.current.scrollLeft<=0&&(k=-k)):k=V*(_-y),x.current.scrollLeft=k}S(z)}},onPointerUp:v,style:{position:"absolute",touchAction:"none",WebkitUserSelect:"none",userSelect:"none",...s==="vertical"&&{top:0,bottom:`var(${Rn.scrollAreaCornerHeight})`,insetInlineEnd:0,[Nn.scrollAreaThumbHeight]:`${M.height}px`},...s==="horizontal"&&{insetInlineStart:0,insetInlineEnd:`var(${Rn.scrollAreaCornerWidth})`,bottom:0,[Nn.scrollAreaThumbWidth]:`${M.width}px`}}},F=St("div",t,{ref:[n,s==="vertical"?d:g],state:C,props:[U,a],stateAttributesMapping:ni}),E=m.useMemo(()=>({orientation:s}),[s]),N=s==="vertical"?f.y:f.x;return o||!N?h.jsx(So.Provider,{value:E,children:F}):null}),yc=m.forwardRef(function(t,n){const{render:r,className:i,...s}=t,{thumbYRef:o,thumbXRef:a,handlePointerDown:l,handlePointerMove:u,handlePointerUp:c,setScrollingX:f,setScrollingY:p}=Kn(),{orientation:d}=gc(),g=m.useMemo(()=>({orientation:d}),[d]);return St("div",t,{ref:[n,d==="vertical"?o:a],state:g,props:[{onPointerDown:l,onPointerMove:u,onPointerUp(w){d==="vertical"&&p(!1),d==="horizontal"&&f(!1),c(w)},style:{...d==="vertical"&&{height:`var(${Nn.scrollAreaThumbHeight})`},...d==="horizontal"&&{width:`var(${Nn.scrollAreaThumbWidth})`}}},s]})}),bc=m.forwardRef(function(t,n){const{render:r,className:i,...s}=t,{cornerRef:o,cornerSize:a,hiddenState:l}=Kn(),u=St("div",t,{ref:[n,o],props:[{style:{position:"absolute",bottom:0,insetInlineEnd:0,width:a.width,height:a.height}},s]});return l.corner?null:u});function Co({className:e,...t}){return h.jsx(cc,{className:q("group/scroll-area relative outline-none focus-visible:outline-none",e),...t})}function vo({className:e,...t}){return h.jsx(mc,{className:q("h-full w-full outline-none focus-visible:outline-none",e),...t})}function Eo({className:e,...t}){return h.jsx(xc,{className:q("flex w-2 touch-none select-none p-0.5 outline-none focus-visible:outline-none","opacity-0 transition-opacity duration-150","data-hovering:opacity-100 data-scrolling:opacity-100 group-hover/scroll-area:opacity-100",e),...t})}function To({className:e,...t}){return h.jsx(yc,{className:q("flex-1 rounded-full bg-primary-500 outline-none focus-visible:outline-none",e),...t})}function kc({className:e,...t}){return h.jsx(bc,{className:q("bg-primary-100 outline-none focus-visible:outline-none",e),...t})}function wc(e){return e==="subagent"?Ml:e==="cron"?Dl:Pl}function Sc(e){return!e||!Array.isArray(e.content)?"":e.content.map(n=>n.type==="text"?String(n.text??""):"").join(" ").replace(/\s+/g," ").trim()}function Cc(e){if(typeof e=="number"&&Number.isFinite(e))return e<1e12?e*1e3:e;if(typeof e=="string"){const t=Date.parse(e);if(!Number.isNaN(t))return t}return null}function vc(e){if(!e)return null;const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const n of t){const r=Cc(n);if(r)return r}return null}function Ec(e){const t=e-Date.now(),n=Math.abs(t),r=[["minute",6e4],["hour",36e5],["day",864e5]];let i="minute",s=6e4;n>=r[2][1]?[i,s]=r[2]:n>=r[1][1]&&([i,s]=r[1]);const o=Math.round(t/s);return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(o,i)}function Tc(e){const t=String(e??"").toLowerCase().trim();return t?t==="error"||t==="failed"?"error":t==="completed"||t==="ended"||t==="done"?"success":null:null}function jc({session:e,active:t,isGenerating:n=!1,isPinned:r,selectionMode:i=!1,selected:s=!1,onToggleSelect:o,onSelect:a,onTogglePin:l,onRename:u,onDelete:c,onExport:f}){const p=e.label||e.title||e.derivedTitle||e.friendlyId,d=wc(e.kind),g=e.kind==="subagent"&&(e.lastMessage?.role==="assistant"||e.lastMessage?.role==="toolResult")?Sc(e.lastMessage):"",x=g.length>50?`${g.slice(0,50).trimEnd()}…`:g,w=e.kind==="subagent"?Tc(e.status):null,b=e.kind==="cron"?vc(e.lastMessage):null;return h.jsxs(Rt,{to:"/chat/$sessionKey",params:{sessionKey:e.friendlyId},onClick:S=>{if(i){S.preventDefault(),S.stopPropagation(),o?.(e);return}a?.()},className:q("group inline-flex items-center justify-between","w-full text-left pl-1.5 pr-0.5 min-h-8 py-1 rounded-lg transition-colors duration-0","select-none",t?"bg-primary-200 text-primary-950":"bg-transparent text-primary-950 [&:hover:not(:has(button:hover))]:bg-primary-200"),children:[h.jsxs("div",{className:"flex items-center gap-2 flex-1 min-w-0",children:[i?h.jsx("span",{"aria-hidden":"true",className:q("inline-flex items-center justify-center size-4 shrink-0 rounded border transition-colors",s?"bg-primary-700 border-primary-700 text-white":"border-primary-300 bg-surface"),children:s?h.jsx("svg",{viewBox:"0 0 12 12",className:"size-3",fill:"none",stroke:"currentColor",strokeWidth:2,children:h.jsx("path",{d:"M2.5 6l2.5 2.5 4.5-5"})}):null}):null,h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsxs("div",{className:"flex items-center gap-1.5 min-w-0",children:[h.jsx(ee,{icon:d,size:12,strokeWidth:1.75,className:"text-primary-500/70 shrink-0"}),h.jsxs("div",{className:"min-w-0 truncate text-sm font-[450]",title:p,children:[r?h.jsx("span",{className:"mr-1 text-xs text-primary-700","aria-hidden":"true",children:"📌"}):null,p]}),e.kind==="subagent"?n?h.jsx("span",{"aria-label":"Session active",className:"size-1.5 rounded-full bg-green-500 shrink-0"}):w==="success"?h.jsx(ee,{icon:to,size:12,strokeWidth:1.8,className:"text-green-600/80 shrink-0"}):w==="error"?h.jsx(ee,{icon:Hn,size:12,strokeWidth:1.8,className:"text-red-600/80 shrink-0"}):null:null]}),x?h.jsx("div",{className:"text-[11px] text-primary-600/80 line-clamp-1 mt-0.5 pl-[18px]",children:x}):null,e.kind==="cron"&&b?h.jsx("div",{className:"text-[10px] text-primary-500/75 line-clamp-1 mt-0.5 pl-[18px] font-mono",children:Ec(b)}):null]})]}),i?null:h.jsxs(Un,{children:[h.jsx(qn,{type:"button",onClick:S=>{S.preventDefault(),S.stopPropagation()},className:q("ml-2 inline-flex size-7 items-center justify-center rounded-md text-primary-700","opacity-0 transition-opacity group-hover:opacity-100 hover:bg-primary-200","aria-expanded:opacity-100 aria-expanded:bg-primary-200"),children:h.jsx(ee,{icon:Rl,size:20,strokeWidth:1.5})}),h.jsxs(Wn,{side:"bottom",align:"end",children:[h.jsxs(kt,{onClick:S=>{S.preventDefault(),S.stopPropagation(),l(e)},className:"gap-2",children:[h.jsx("span",{className:"text-xs","aria-hidden":"true",children:"📌"})," ",r?"Unpin Session":"Pin Session"]}),h.jsxs(kt,{onClick:S=>{S.preventDefault(),S.stopPropagation(),u(e)},className:"gap-2",children:[h.jsx(ee,{icon:Nl,size:20,strokeWidth:1.5})," ","Rename"]}),h.jsxs(kt,{onClick:S=>{S.preventDefault(),S.stopPropagation(),f(e)},className:"gap-2",children:[h.jsx(ee,{icon:Ll,size:20,strokeWidth:1.5})," ","Export"]}),Lr(e.key)?null:h.jsxs(kt,{onClick:S=>{S.preventDefault(),S.stopPropagation(),c(e)},className:"text-red-700 gap-2 hover:bg-red-50/80 data-highlighted:bg-red-50/80",children:[h.jsx(ee,{icon:no,size:20,strokeWidth:1.5})," ","Delete"]})]})]})]})}function Ac(e,t){return e.active!==t.active||e.isGenerating!==t.isGenerating||e.isPinned!==t.isPinned||e.selectionMode!==t.selectionMode||e.selected!==t.selected||e.onToggleSelect!==t.onToggleSelect||e.onSelect!==t.onSelect||e.onTogglePin!==t.onTogglePin||e.onRename!==t.onRename||e.onDelete!==t.onDelete||e.onExport!==t.onExport?!1:e.session===t.session?!0:e.session.key===t.session.key&&e.session.friendlyId===t.session.friendlyId&&e.session.label===t.session.label&&e.session.title===t.session.title&&e.session.derivedTitle===t.session.derivedTitle&&e.session.updatedAt===t.session.updatedAt&&e.session.kind===t.session.kind&&e.session.status===t.session.status&&e.session.lastMessage===t.session.lastMessage}const sr=m.memo(jc,Ac),jo="opencami-pinned-sessions",Ao="opencami-sidebar-folders",ht={webchat:!1,subagent:!1,cron:!1,other:!1};async function Ic(e){const t=new URLSearchParams;e&&t.set("sessionKey",e);const n=await fetch(`/api/sessions?${t.toString()}`,{method:"DELETE"});if(!n.ok)throw new Error(await it(n))}async function Rc(e,t,n){const r=[];let i=0;const s=Array.from({length:Math.min(t,e.length)},async function(){for(;i<e.length;){const a=i;i+=1;try{await n(e[a])}catch(l){r.push(l)}}});return await Promise.all(s),r}function Nc(){if(typeof window>"u")return[];try{const e=localStorage.getItem(jo);if(!e)return[];const t=JSON.parse(e);return Array.isArray(t)?t.filter(n=>typeof n=="string"):[]}catch{return[]}}function Lc(e){if(!(typeof window>"u"))try{const t=Array.from(new Set(e));localStorage.setItem(jo,JSON.stringify(t))}catch{}}function Mc(){if(typeof window>"u")return{...ht};try{const e=localStorage.getItem(Ao);if(!e)return{...ht};const t=JSON.parse(e);return!t||typeof t!="object"?{...ht}:{webchat:typeof t.webchat=="boolean"?t.webchat:ht.webchat,subagent:typeof t.subagent=="boolean"?t.subagent:ht.subagent,cron:typeof t.cron=="boolean"?t.cron:ht.cron,other:typeof t.other=="boolean"?t.other:ht.other}}catch{return{...ht}}}function Dc(e){if(!(typeof window>"u"))try{localStorage.setItem(Ao,JSON.stringify(e))}catch{}}function wn(e,t,n){return n&&e.key?e.key===n:e.friendlyId===t}function Pc(e){if(!e)return!1;const t=e.toLowerCase();return t.includes("running")||t.includes("active")||t.includes("stream")||t.includes("generat")}function or(e,t,n,r){return wn(e,t,n)&&r?!0:Pc(e.status)}const zc=m.memo(function({sessions:t,activeFriendlyId:n,activeSessionKey:r,isStreaming:i=!1,defaultOpen:s=!0,onSelect:o,onRename:a,onDelete:l,onExport:u}){const c=m.useDeferredValue(t),f=Wt(),[p,d]=m.useState(()=>Nc()),[g,x]=m.useState(()=>Mc()),[w,b]=m.useState(!1),[S,v]=m.useState(()=>new Set),R=m.useMemo(()=>new Set(p),[p]),M=c.filter(_=>R.has(_.key)),C=c.filter(_=>!R.has(_.key)),P=M.length>0&&C.length>0,U=m.useMemo(()=>{const _={chat:[],webchat:[],subagent:[],cron:[],other:[]};for(const y of C){const X=y.kind??"other";_[X].push(y)}return _},[C]),F=m.useMemo(()=>c.filter(_=>S.has(_.key)),[S,c]),E=F.length,N=m.useCallback(()=>{b(_=>(_&&v(new Set),!_))},[]),A=m.useCallback(_=>{Lr(_.key)||v(y=>{const X=new Set(y);return X.has(_.key)?X.delete(_.key):X.add(_.key),X})},[]),z=m.useCallback(()=>{v(new Set(c.filter(_=>!Lr(_.key)).map(_=>_.key)))},[c]),j=m.useCallback(()=>{b(!1),v(new Set)},[]),T=m.useCallback(async()=>{if(F.length===0||!window.confirm(`Delete ${F.length} sessions? This will archive them.`))return;const y=await Rc(F.map(X=>X.key),10,Ic);y.length>0&&console.error("[sidebar] Bulk delete failed for some sessions",y),b(!1),v(new Set),f.invalidateQueries({queryKey:be.sessions})},[f,F]),D=m.useCallback(_=>{d(y=>{const V=y.includes(_.key)?y.filter(k=>k!==_.key):[...y,_.key];return Lc(V),V})},[]),L=m.useCallback((_,y)=>{x(X=>{const V={...X,[_]:y};return Dc(V),V})},[]);function H(_,y,X){return X.length===0?null:h.jsxs(jn,{className:"flex flex-col",open:g[_],onOpenChange:V=>L(_,V),children:[h.jsxs(An,{className:q("w-full justify-between border-l-2 border-primary-200/70 px-2 py-1 text-[11px] font-medium text-primary-500/80 text-balance"),children:[h.jsx("span",{className:"truncate",children:y}),h.jsx("span",{className:q("rounded-full bg-primary-100 px-1.5 py-0.5 text-[10px] font-medium text-primary-700 tabular-nums"),children:X.length})]}),h.jsx(In,{contentClassName:"flex flex-col gap-px",children:X.map(V=>h.jsx(sr,{session:V,active:wn(V,n,r),isGenerating:or(V,n,r,i),isPinned:!1,selectionMode:w,selected:S.has(V.key),onToggleSelect:A,onSelect:o,onTogglePin:D,onRename:a,onDelete:l,onExport:u},V.key))})]})}return h.jsxs(jn,{className:"flex h-full flex-col flex-1 min-h-0 w-full",defaultOpen:s,children:[h.jsxs("div",{className:"flex items-center justify-between pr-2 shrink-0",children:[h.jsxs(An,{className:"w-fit pl-1.5 text-balance",children:["Sessions",h.jsx("span",{className:"opacity-0 transition-opacity duration-150 group-hover:opacity-100",children:h.jsx(ee,{icon:Gr,className:"size-3 transition-transform duration-150 group-data-panel-open:rotate-90"})})]}),h.jsx("button",{type:"button",onClick:N,className:q("text-[11px] font-medium px-1.5 py-0.5 rounded-md transition-colors",w?"text-primary-900 bg-primary-200":"text-primary-500 hover:text-primary-700 hover:bg-primary-100"),children:w?"Done":"Select"})]}),h.jsx(In,{className:"w-full flex-1 min-h-0 h-auto data-starting-style:h-0 data-ending-style:h-0",contentClassName:"flex flex-1 min-h-0 flex-col overflow-y-auto",children:h.jsxs(Co,{className:"flex-1 min-h-0",children:[h.jsx(vo,{className:"min-h-0",children:h.jsxs("div",{className:"flex flex-col gap-2 pl-2 pr-2",children:[M.length>0?h.jsx("div",{className:"flex flex-col gap-px",children:M.map(_=>h.jsx(sr,{session:_,active:wn(_,n,r),isGenerating:or(_,n,r,i),isPinned:!0,selectionMode:w,selected:S.has(_.key),onToggleSelect:A,onSelect:o,onTogglePin:D,onRename:a,onDelete:l,onExport:u},_.key))}):null,P?h.jsx("div",{className:"my-1 border-t border-primary-200/80"}):null,U.chat.length>0?h.jsxs("div",{className:"flex flex-col gap-px",children:[h.jsx("div",{className:q("border-l-2 border-primary-200/70 px-2 py-1 text-[11px] font-medium text-primary-500/80 text-balance"),children:"💬 Chats"}),h.jsx("div",{className:"flex flex-col gap-px",children:U.chat.map(_=>h.jsx(sr,{session:_,active:wn(_,n,r),isGenerating:or(_,n,r,i),isPinned:!1,selectionMode:w,selected:S.has(_.key),onToggleSelect:A,onSelect:o,onTogglePin:D,onRename:a,onDelete:l,onExport:u},_.key))})]}):null,H("webchat","🦎 OpenCami",U.webchat),H("subagent","🤖 Sub-agents",U.subagent),H("cron","⏰ Cron / Isolated",U.cron),H("other","📁 Other",U.other)]})}),h.jsx(Eo,{orientation:"vertical",children:h.jsx(To,{})})]})}),w?h.jsxs("div",{className:"shrink-0 border-t border-primary-200 bg-surface px-2 py-2 flex flex-col gap-1.5",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("span",{className:"text-xs text-primary-600 font-medium",children:[E," selected"]}),h.jsx("button",{type:"button",onClick:z,className:"text-[11px] font-medium text-primary-600 hover:text-primary-800",children:"Select all"})]}),h.jsxs("div",{className:"flex gap-1.5",children:[h.jsxs("button",{type:"button",onClick:T,disabled:E===0,className:q("flex-1 inline-flex items-center justify-center gap-1.5 rounded-md px-2 py-1.5 text-xs font-medium transition-colors",E>0?"bg-red-100 text-red-700 hover:bg-red-200":"bg-primary-100 text-primary-400 cursor-not-allowed"),children:[h.jsx(ee,{icon:no,size:14,strokeWidth:1.5}),"Delete"]}),h.jsx("button",{type:"button",onClick:j,className:"flex-1 inline-flex items-center justify-center rounded-md px-2 py-1.5 text-xs font-medium bg-primary-100 text-primary-700 hover:bg-primary-200 transition-colors",children:"Cancel"})]})]}):null]})},_c);function _c(e,t){if(e.activeFriendlyId!==t.activeFriendlyId||e.activeSessionKey!==t.activeSessionKey||e.isStreaming!==t.isStreaming||e.defaultOpen!==t.defaultOpen||e.onSelect!==t.onSelect||e.onRename!==t.onRename||e.onDelete!==t.onDelete||e.onExport!==t.onExport)return!1;if(e.sessions===t.sessions)return!0;if(e.sessions.length!==t.sessions.length)return!1;for(let n=0;n<e.sessions.length;n+=1){const r=e.sessions[n],i=t.sessions[n];if(r.key!==i.key||r.friendlyId!==i.friendlyId||r.label!==i.label||r.title!==i.title||r.derivedTitle!==i.derivedTitle||r.updatedAt!==i.updatedAt||r.kind!==i.kind||r.status!==i.status||r.lastMessage!==i.lastMessage)return!1}return!0}function Oc(){const[e,t]=m.useState(!1),[n,r]=m.useState(!1),[i,s]=m.useState(null),[o,a]=m.useState(null),l=m.useCallback(async()=>{if(t(!0),s(null),!(n||o)){r(!0);try{const d=await fetch("/api/paths");if(!d.ok)throw new Error(await it(d));const g=await d.json();a({agentId:String(g.agentId??"main"),stateDir:String(g.stateDir??""),sessionsDir:String(g.sessionsDir??""),storePath:String(g.storePath??"")})}catch(d){s(d instanceof Error?d.message:String(d))}finally{r(!1)}}},[o,n]),u=m.useCallback(()=>{l()},[l]),c=m.useCallback(()=>{t(!1)},[]),f=m.useCallback(()=>{if(o?.sessionsDir)try{navigator.clipboard.writeText(o.sessionsDir)}catch{}},[o]),p=m.useCallback(()=>{if(o?.storePath)try{navigator.clipboard.writeText(o.storePath)}catch{}},[o]);return{settingsOpen:e,setSettingsOpen:t,pathsLoading:n,pathsError:i,paths:o,handleOpenSettings:u,closeSettings:c,copySessionsDir:f,copyStorePath:p}}let Ue=null,ri=!1,Sn=null;function Fc(e){Ue=e}function ar(){return Ue!==null}function Vt(e){ri=e}function lr(){return ri}function Ln(){Ue=null,ri=!1}function $c(e,t){if(Ue){if(e&&Ue.sessionKey===e){Ln();return}t&&Ue.friendlyId===t&&Ln()}}function Bc(e){Sn={friendlyId:e,at:Date.now()}}function Io(e,t=15e3){return!(!Sn||Sn.friendlyId!==e||Date.now()-Sn.at>t)}function Hc(e,t){if(!Ue)return null;if(e&&Ue.sessionKey===e){const n=Ue;return Ue=null,n}if(t&&Ue.friendlyId===t){const n=Ue;return Ue=null,n}return null}const Uc=8e3,It=new Map;function qc(e){e&&It.set(e,{id:e,expiresAt:Date.now()+Uc})}function Wc(e){e&&It.delete(e)}function Kc(e){if(It.size===0)return e;const t=Date.now();let n=!1;const r=e.filter(i=>{const s=It.get(i.key),o=It.get(i.friendlyId);return s&&s.expiresAt<=t||o&&o.expiresAt<=t?(s&&s.expiresAt<=t&&It.delete(i.key),o&&o.expiresAt<=t&&It.delete(i.friendlyId),!0):s||o?(n=!0,!1):!0});return n?r:e}function Xc(){const e=Wt(),[t,n]=m.useState(!1),[r,i]=m.useState(null),s=ho({mutationFn:async function(l){const u=new URLSearchParams;l.sessionKey&&u.set("sessionKey",l.sessionKey),l.friendlyId&&u.set("friendlyId",l.friendlyId);const c=await fetch(`/api/sessions?${u.toString()}`,{method:"DELETE"});if(!c.ok)throw new Error(await it(c));return l},onMutate:async function(l){i(null),qc(l.sessionKey||l.friendlyId),$c(l.sessionKey,l.friendlyId),await e.cancelQueries({queryKey:be.sessions});const u=e.getQueryData(be.sessions);return Iu(e,l.sessionKey,l.friendlyId),l.isActive&&(l.sessionKey||l.friendlyId)&&Mr(e,l.friendlyId||l.sessionKey,l.sessionKey||l.friendlyId),{previousSessions:u,isActive:l.isActive}},onError:function(l,u,c){c?.previousSessions&&e.setQueryData(be.sessions,c.previousSessions),Wc(u.sessionKey||u.friendlyId),i(l instanceof Error?l.message:String(l))},onSuccess:function(l){l.isActive&&Ln(),e.invalidateQueries({queryKey:be.sessions})},onSettled:function(){n(!1)}});return{deleteSession:m.useCallback(async(a,l,u)=>{!a&&!l||(n(!0),await s.mutateAsync({sessionKey:a,friendlyId:l,isActive:u}))},[s]),deleting:t,error:r}}function Vc(){const e=Wt(),[t,n]=m.useState(!1),[r,i]=m.useState(null),s=ho({mutationFn:async function(l){const u=await fetch("/api/sessions",{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({sessionKey:l.sessionKey,label:l.newTitle})});if(!u.ok)throw new Error(await it(u));return l},onMutate:async function(l){i(null),await e.cancelQueries({queryKey:be.sessions});const u=e.getQueryData(be.sessions);return e.setQueryData(be.sessions,function(f){return Array.isArray(f)?f.map(p=>p.key!==l.sessionKey?p:{...p,label:l.newTitle,title:l.newTitle}):f}),{previousSessions:u}},onError:function(l,u,c){c?.previousSessions&&e.setQueryData(be.sessions,c.previousSessions),i(l instanceof Error?l.message:String(l))},onSuccess:function(){e.invalidateQueries({queryKey:be.sessions})},onSettled:function(){n(!1)}});return{renameSession:m.useCallback(async(a,l)=>{!a||!l.trim()||(n(!0),await s.mutateAsync({sessionKey:a,newTitle:l.trim()}))},[s]),renaming:t,error:r}}const Yc=m.lazy(()=>Bn(()=>import("./settings-dialog-B8v-GVJ8.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11])).then(e=>({default:e.SettingsDialog}))),Gc=m.lazy(()=>Bn(()=>import("./session-export-dialog-CH5unryw.js"),__vite__mapDeps([12,1,3,2,4,5,6])).then(e=>({default:e.SessionExportDialog})));function Qc({sessions:e,activeFriendlyId:t,activeSessionKey:n,isStreaming:r=!1,creatingSession:i,onCreateSession:s,isCollapsed:o,onToggleCollapse:a,onSelectSession:l,onActiveSessionDelete:u,onOpenSearch:c}){const{settingsOpen:f,setSettingsOpen:p,pathsLoading:d,pathsError:g,paths:x,handleOpenSettings:w,closeSettings:b,copySessionsDir:S,copyStorePath:v}=Oc(),{deleteSession:R}=Xc(),{renameSession:M}=Vc(),C={duration:.15,ease:o?"easeIn":"easeOut"},[P,U]=m.useState(!1),[F,E]=m.useState(null),[N,A]=m.useState(""),[z,j]=m.useState(!1),[T,D]=m.useState(null),[L,H]=m.useState(null),[_,y]=m.useState(""),[X,V]=m.useState(!1),[k,Q]=m.useState(null),[re,W]=m.useState(null),[he,me]=m.useState(""),ue=Wt();function se($){E($.key),A($.label||$.title||$.derivedTitle||""),U(!0)}function ge($){F&&M(F,$),U(!1),E(null)}function ke($){D($.key),H($.friendlyId),y($.label||$.title||$.derivedTitle||$.friendlyId),j(!0)}function we(){if(T&&L){const $=L===t;$&&u&&u(),R(T,L,$)}j(!1),D(null),H(null)}function Se($){Q($.key),W($.friendlyId),me($.label||$.title||$.derivedTitle||$.friendlyId),V(!0)}function Le($){if(k&&re){const J=be.history(re,k),xe=ue.getQueryData(J);xe?.messages&&Du(he,xe.messages,$)}V(!1),Q(null),W(null)}const K={className:"border-r border-primary-200 h-full overflow-hidden bg-primary-100 flex flex-col"};return h.jsxs(He.aside,{initial:!1,animate:{width:o?48:300},transition:C,className:K.className,children:[h.jsxs(He.div,{layout:!0,transition:{layout:C},className:q("flex items-center h-12 px-2 justify-between"),children:[h.jsx(ft,{initial:!1,children:o?null:h.jsx(He.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,children:h.jsxs(Rt,{to:"/new",className:q(pn({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),children:[h.jsx(ou,{className:"size-5"}),h.jsx(au,{})]})})}),h.jsx(gt,{children:h.jsxs(xt,{children:[h.jsx(yt,{onClick:a,render:h.jsx(Ce,{size:"icon-sm",variant:"ghost",children:h.jsx(ee,{icon:zl,size:20,strokeWidth:1.5})})}),h.jsx(bt,{side:"right",children:o?"Open Sidebar":"Close Sidebar"})]})})]}),h.jsxs("div",{className:"px-2 mb-4 flex flex-col gap-1",children:[h.jsxs(He.div,{layout:!0,transition:{layout:C},className:"w-full space-y-2",children:[h.jsxs(Ce,{disabled:i,variant:"ghost",size:"sm",onClick:s,onMouseUp:l,className:"w-full pl-1.5 justify-start",children:[h.jsx(ee,{icon:_l,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(ft,{initial:!1,mode:"wait",children:!o&&h.jsx(He.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"overflow-hidden whitespace-nowrap",children:"New Session"})})]}),h.jsx(gt,{children:h.jsxs(xt,{children:[h.jsx(yt,{asChild:!0,children:h.jsxs(Rt,{to:"/files",className:q(pn({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:l,children:[h.jsx(ee,{icon:Ol,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(ft,{initial:!1,mode:"wait",children:!o&&h.jsx(He.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"overflow-hidden whitespace-nowrap",children:"Files"})})]})}),o&&h.jsx(bt,{side:"right",children:"Files"})]})}),(()=>{try{return localStorage.getItem("opencami-agent-manager")==="true"}catch{return!1}})()&&h.jsx(gt,{children:h.jsxs(xt,{children:[h.jsx(yt,{asChild:!0,children:h.jsxs(Rt,{to:"/agents",className:q(pn({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:l,children:[h.jsx(ee,{icon:ro,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(ft,{initial:!1,mode:"wait",children:!o&&h.jsx(He.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"overflow-hidden whitespace-nowrap",children:"Agents"})})]})}),o&&h.jsx(bt,{side:"right",children:"Agents"})]})}),(()=>{try{return localStorage.getItem("opencami-cron-manager")==="true"}catch{return!1}})()&&h.jsx(gt,{children:h.jsxs(xt,{children:[h.jsx(yt,{asChild:!0,children:h.jsxs(Rt,{to:"/bots",className:q(pn({variant:"ghost",size:"sm"}),"w-full pl-1.5 justify-start"),onClick:l,children:[h.jsx(ee,{icon:Fl,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(ft,{initial:!1,mode:"wait",children:!o&&h.jsx(He.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"overflow-hidden whitespace-nowrap",children:"Cron Jobs"})})]})}),o&&h.jsx(bt,{side:"right",children:"Cron Jobs"})]})})]}),h.jsx(He.div,{layout:!0,transition:{layout:C},className:"w-full",children:h.jsxs(Ce,{variant:"ghost",size:"sm",onClick:c,className:"w-full pl-1.5 justify-start",children:[h.jsx(ee,{icon:io,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(ft,{initial:!1,mode:"wait",children:!o&&h.jsx(He.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"overflow-hidden whitespace-nowrap",children:"Search"})})]})})]}),h.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:h.jsx(ft,{initial:!1,children:!o&&h.jsx(He.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"pt-0 flex flex-col w-full min-h-0 h-full",children:h.jsx("div",{className:"flex-1 min-h-0",children:h.jsx(zc,{sessions:e,activeFriendlyId:t,activeSessionKey:n,isStreaming:r,onSelect:l,onRename:se,onDelete:ke,onExport:Se})})},"content")})}),h.jsx("div",{className:"px-2 py-3 border-t border-primary-200 bg-primary-100",children:h.jsx(He.div,{layout:!0,transition:{layout:C},className:"w-full",children:h.jsxs(Ce,{variant:"ghost",size:"sm",onClick:w,title:o?"Settings":void 0,className:"w-full justify-start pl-1.5",children:[h.jsx(ee,{icon:$l,size:20,strokeWidth:1.5,className:"min-w-5"}),h.jsx(ft,{initial:!1,mode:"wait",children:!o&&h.jsx(He.span,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:C,className:"overflow-hidden whitespace-nowrap",children:"Settings"})})]})})}),f&&h.jsx(m.Suspense,{fallback:null,children:h.jsx(Yc,{open:f,onOpenChange:p,pathsLoading:d,pathsError:g,paths:x,onClose:b,onCopySessionsDir:S,onCopyStorePath:v})}),h.jsx(zu,{open:P,onOpenChange:U,sessionTitle:N,onSave:ge,onCancel:()=>U(!1)}),h.jsx(qu,{open:z,onOpenChange:j,sessionTitle:_,onConfirm:we,onCancel:()=>j(!1)}),X&&h.jsx(m.Suspense,{fallback:null,children:h.jsx(Gc,{open:X,onOpenChange:V,sessionTitle:he,onExport:Le,onCancel:()=>V(!1)})})]})}function Jc(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let n=0;n<e.length;n+=1){const r=e[n],i=t[n];if(r.key!==i.key||r.friendlyId!==i.friendlyId||r.label!==i.label||r.title!==i.title||r.derivedTitle!==i.derivedTitle||r.updatedAt!==i.updatedAt||r.kind!==i.kind||r.status!==i.status||r.lastMessage!==i.lastMessage)return!1}return!0}function Zc(e,t){return!(e.activeFriendlyId!==t.activeFriendlyId||e.activeSessionKey!==t.activeSessionKey||e.isStreaming!==t.isStreaming||e.creatingSession!==t.creatingSession||e.isCollapsed!==t.isCollapsed||!Jc(e.sessions,t.sessions))}const ef=m.memo(Qc,Zc);function Wi(e){if(e<=0)return"0";if(e>=1e6){const t=e/1e6,n=t.toFixed(1);return n.endsWith(".0")?`${Math.round(t)}M`:`${n}M`}if(e>=1e5)return`${Math.round(e/1e3)}K`;if(e>=1e4)return`${Math.round(e/1e3)}K`;if(e>=1e3){const t=e/1e3,n=t.toFixed(1);return n.endsWith(".0")?`${Math.round(t)}K`:`${n}K`}return String(Math.round(e))}function Ki(e){return e>=90?{bar:"bg-red-500",text:"text-red-600 dark:text-red-400"}:e>=70?{bar:"bg-yellow-500",text:"text-yellow-600 dark:text-yellow-400"}:{bar:"bg-emerald-500",text:"text-emerald-600 dark:text-emerald-400"}}function tf({totalTokens:e,contextTokens:t,className:n}){const{percentage:r,usedStr:i,maxStr:s,colors:o,hasData:a,isNearlyFull:l}=m.useMemo(()=>{if(typeof t!="number"||t<=0)return{percentage:0,usedStr:"",maxStr:"",colors:Ki(0),hasData:!1,isNearlyFull:!1};const f=typeof e=="number"&&e>0?e:0,p=Math.min(100,Math.round(f/t*100));return{percentage:p,usedStr:Wi(f),maxStr:Wi(t),colors:Ki(p),hasData:!0,isNearlyFull:p>=95}},[e,t]);if(!a)return null;const u=typeof e=="number"&&e>0?e.toLocaleString():"0",c=typeof t=="number"?t.toLocaleString():"0";return h.jsxs("div",{className:q("group relative flex items-center gap-1.5",n),title:`Context: ${u} / ${c} tokens (${r}%)`,children:[h.jsxs("div",{className:"flex items-center gap-1.5",children:[h.jsx("div",{className:"w-12 h-1.5 rounded-full bg-primary-200 dark:bg-primary-700 overflow-hidden shrink-0 group-hover:h-2 transition-all",children:h.jsx("div",{className:q("h-full rounded-full transition-all duration-500 ease-out",o.bar,l&&"animate-pulse"),style:{width:`${r}%`}})}),h.jsx("span",{className:q("text-[10px] leading-none font-medium tabular-nums whitespace-nowrap",l?o.text:"text-primary-500 dark:text-primary-400"),children:i})]}),h.jsx("div",{className:q("absolute right-0 top-full mt-1 z-50","pointer-events-none opacity-0 scale-95","group-hover:pointer-events-auto group-hover:opacity-100 group-hover:scale-100","transition-all duration-150 origin-top-right"),children:h.jsxs("div",{className:q("rounded-md border border-primary-200 dark:border-primary-700","bg-surface shadow-lg px-3 py-2","text-xs whitespace-nowrap"),children:[h.jsxs("div",{className:"flex items-center gap-2 mb-1.5",children:[h.jsx("span",{className:"text-primary-500 dark:text-primary-400",children:"Context window"}),h.jsxs("span",{className:q("font-semibold",o.text),children:[r,"%"]})]}),h.jsxs("div",{className:"flex items-center gap-1.5 text-primary-700 dark:text-primary-300",children:[h.jsx("span",{className:"font-medium",children:i}),h.jsx("span",{className:"text-primary-400",children:"/"}),h.jsx("span",{children:s}),h.jsx("span",{className:"text-primary-400",children:"tokens"})]}),h.jsx("div",{className:"w-full h-1.5 rounded-full bg-primary-200 dark:bg-primary-700 overflow-hidden mt-1.5",children:h.jsx("div",{className:q("h-full rounded-full transition-all duration-500 ease-out",o.bar),style:{width:`${r}%`}})}),l&&h.jsx("div",{className:"mt-1.5 text-[10px] text-red-500 dark:text-red-400 font-medium",children:"⚠ Context nearly full — consider /compact"})]})})]})}const nf=m.memo(tf);function rf({activeTitle:e,wrapperRef:t,showSidebarButton:n=!1,onOpenSidebar:r,totalTokens:i,contextTokens:s}){return h.jsxs("div",{ref:t,className:"border-b border-primary-200 px-4 h-12 flex min-w-0 items-center overflow-x-hidden bg-surface",children:[n?h.jsx(Ce,{size:"icon-sm",variant:"ghost",onClick:r,className:"mr-2 text-primary-800 hover:bg-primary-100","aria-label":"Open sidebar",children:h.jsx(ee,{icon:Bl,size:18,strokeWidth:1.6})}):null,h.jsx("div",{className:"flex-1 min-w-0 overflow-hidden",children:h.jsx("div",{className:"truncate text-sm font-medium",children:e})}),h.jsx(nf,{totalTokens:i,contextTokens:s,className:"ml-3 hidden sm:flex"})]})}const sf=m.memo(rf);function of(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function af(e){const t=new Date(e);return of(t,new Date)?new Intl.DateTimeFormat("en-GB",{hour:"2-digit",minute:"2-digit"}).format(t):new Intl.DateTimeFormat("en-GB",{day:"2-digit",month:"short"}).format(t)}function lf(e){return new Intl.DateTimeFormat("en-GB",{day:"2-digit",month:"short",year:"numeric",hour:"2-digit",minute:"2-digit",second:"2-digit"}).format(new Date(e))}function uf({timestamp:e}){const t=af(e),n=lf(e);return h.jsx(gt,{children:h.jsxs(xt,{children:[h.jsx(yt,{className:"inline-flex items-center text-xs text-primary-600",children:t}),h.jsx(bt,{side:"top",children:n})]})})}function cf({text:e,align:t,timestamp:n,forceVisible:r=!1}){const[i,s]=m.useState(!1),[o,a]=m.useState("idle"),l=m.useRef(null),u=m.useRef(null),c=m.useRef(null),[f,p]=m.useState(()=>{if(typeof window>"u")return!0;try{const b=localStorage.getItem("opencami-tts-enabled");return b===null?!0:b==="true"}catch{return!0}});m.useEffect(()=>{function b(S){S.key==="opencami-tts-enabled"&&p(S.newValue===null?!0:S.newValue==="true")}return window.addEventListener("storage",b),()=>window.removeEventListener("storage",b)},[]),m.useEffect(()=>()=>{c.current?.abort(),l.current&&(l.current.pause(),l.current=null),u.current&&(URL.revokeObjectURL(u.current),u.current=null)},[]);const d=async()=>{try{await navigator.clipboard.writeText(e),s(!0),window.setTimeout(()=>s(!1),1400)}catch{s(!1)}},g=async()=>{if(o==="playing"){c.current?.abort(),l.current&&(l.current.pause(),l.current=null),u.current&&(URL.revokeObjectURL(u.current),u.current=null),a("idle");return}c.current?.abort();const b=new AbortController;c.current=b,a("loading");try{const S=await fetch("/api/tts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({text:e}),signal:b.signal});if(!S.ok)throw new Error("TTS failed");const v=await S.blob(),R=URL.createObjectURL(v);u.current=R;const M=new Audio(R);l.current=M,M.onended=()=>{a("idle"),u.current&&(URL.revokeObjectURL(u.current),u.current=null),l.current=null},M.onerror=()=>{a("idle"),u.current&&(URL.revokeObjectURL(u.current),u.current=null),l.current=null},await M.play(),a("playing")}catch(S){if(S instanceof Error&&S.name==="AbortError"){a("idle");return}a("idle"),u.current&&(URL.revokeObjectURL(u.current),u.current=null),l.current=null}},x=t==="end"?"justify-end":"justify-start",w=t==="start"&&f&&e.trim().length>0;return h.jsxs("div",{className:q("flex items-center gap-2 text-xs text-primary-600 transition-opacity group-hover:opacity-100 group-focus-within:opacity-100 duration-100 ease-out",r?"opacity-100":"opacity-0",x),children:[h.jsx(gt,{children:h.jsxs(xt,{children:[h.jsx(yt,{type:"button",onClick:()=>{d().catch(()=>{})},className:"inline-flex items-center justify-center rounded border border-transparent bg-transparent p-1 text-primary-700 hover:text-primary-900 hover:bg-primary-100",children:h.jsx(ee,{icon:i?Qr:Hl,size:16,strokeWidth:1.6})}),h.jsx(bt,{side:"top",children:"Copy"})]})}),w&&h.jsx(gt,{children:h.jsxs(xt,{children:[h.jsx(yt,{type:"button",onClick:()=>{g().catch(()=>{})},disabled:o==="loading",className:q("inline-flex items-center justify-center rounded border border-transparent bg-transparent p-1 text-primary-700 hover:text-primary-900 hover:bg-primary-100",o==="loading"&&"opacity-60 cursor-wait"),children:h.jsx(ee,{icon:o==="loading"?Ul:o==="playing"?so:ql,size:16,strokeWidth:1.6,className:q(o==="loading"&&"animate-spin")})}),h.jsx(bt,{side:"top",children:o==="loading"?"Generating speech…":o==="playing"?"Stop":"Listen"})]})}),h.jsx(uf,{timestamp:n})]})}function ii(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Pt=ii();function Ro(e){Pt=e}var rn={exec:()=>null};function le(e,t=""){let n=typeof e=="string"?e:e.source,r={replace:(i,s)=>{let o=typeof s=="string"?s:s.source;return o=o.replace(De.caret,"$1"),n=n.replace(i,o),r},getRegex:()=>new RegExp(n,t)};return r}var ff=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),De={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>new RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}#`),htmlBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}<(?:[a-z].*>|!--)`,"i")},hf=/^(?:[ \t]*(?:\n|$))+/,pf=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,df=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,cn=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,mf=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,si=/(?:[*+-]|\d{1,9}[.)])/,No=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Lo=le(No).replace(/bull/g,si).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),gf=le(No).replace(/bull/g,si).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),oi=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,xf=/^[^\n]+/,ai=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,yf=le(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ai).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),bf=le(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,si).getRegex(),Xn="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",li=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,kf=le("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",li).replace("tag",Xn).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),Mo=le(oi).replace("hr",cn).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Xn).getRegex(),wf=le(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",Mo).getRegex(),ui={blockquote:wf,code:pf,def:yf,fences:df,heading:mf,hr:cn,html:kf,lheading:Lo,list:bf,newline:hf,paragraph:Mo,table:rn,text:xf},Xi=le("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",cn).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Xn).getRegex(),Sf={...ui,lheading:gf,table:Xi,paragraph:le(oi).replace("hr",cn).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Xi).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",Xn).getRegex()},Cf={...ui,html:le(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",li).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:rn,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:le(oi).replace("hr",cn).replace("heading",` *#{1,6} *[^
|
|
6
|
+
]`).replace("lheading",Lo).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},vf=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Ef=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,Do=/^( {2,}|\\)\n(?!\s*$)/,Tf=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,Vn=/[\p{P}\p{S}]/u,ci=/[\s\p{P}\p{S}]/u,Po=/[^\s\p{P}\p{S}]/u,jf=le(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,ci).getRegex(),zo=/(?!~)[\p{P}\p{S}]/u,Af=/(?!~)[\s\p{P}\p{S}]/u,If=/(?:[^\s\p{P}\p{S}]|~)/u,Rf=le(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",ff?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),_o=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,Nf=le(_o,"u").replace(/punct/g,Vn).getRegex(),Lf=le(_o,"u").replace(/punct/g,zo).getRegex(),Oo="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",Mf=le(Oo,"gu").replace(/notPunctSpace/g,Po).replace(/punctSpace/g,ci).replace(/punct/g,Vn).getRegex(),Df=le(Oo,"gu").replace(/notPunctSpace/g,If).replace(/punctSpace/g,Af).replace(/punct/g,zo).getRegex(),Pf=le("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,Po).replace(/punctSpace/g,ci).replace(/punct/g,Vn).getRegex(),zf=le(/\\(punct)/,"gu").replace(/punct/g,Vn).getRegex(),_f=le(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),Of=le(li).replace("(?:-->|$)","-->").getRegex(),Ff=le("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",Of).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),Mn=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+[^`]*?`+(?!`)|[^\[\]\\`])*?/,$f=le(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",Mn).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),Fo=le(/^!?\[(label)\]\[(ref)\]/).replace("label",Mn).replace("ref",ai).getRegex(),$o=le(/^!?\[(ref)\](?:\[\])?/).replace("ref",ai).getRegex(),Bf=le("reflink|nolink(?!\\()","g").replace("reflink",Fo).replace("nolink",$o).getRegex(),Vi=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,fi={_backpedal:rn,anyPunctuation:zf,autolink:_f,blockSkip:Rf,br:Do,code:Ef,del:rn,emStrongLDelim:Nf,emStrongRDelimAst:Mf,emStrongRDelimUnd:Pf,escape:vf,link:$f,nolink:$o,punctuation:jf,reflink:Fo,reflinkSearch:Bf,tag:Ff,text:Tf,url:rn},Hf={...fi,link:le(/^!?\[(label)\]\((.*?)\)/).replace("label",Mn).getRegex(),reflink:le(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",Mn).getRegex()},Dr={...fi,emStrongRDelimAst:Df,emStrongLDelim:Lf,url:le(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",Vi).replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:le(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",Vi).getRegex()},Uf={...Dr,br:le(Do).replace("{2,}","*").getRegex(),text:le(Dr.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},gn={normal:ui,gfm:Sf,pedantic:Cf},Yt={normal:fi,gfm:Dr,breaks:Uf,pedantic:Hf},qf={"&":"&","<":"<",">":">",'"':""","'":"'"},Yi=e=>qf[e];function at(e,t){if(t){if(De.escapeTest.test(e))return e.replace(De.escapeReplace,Yi)}else if(De.escapeTestNoEncode.test(e))return e.replace(De.escapeReplaceNoEncode,Yi);return e}function Gi(e){try{e=encodeURI(e).replace(De.percentDecode,"%")}catch{return null}return e}function Qi(e,t){let n=e.replace(De.findPipe,(s,o,a)=>{let l=!1,u=o;for(;--u>=0&&a[u]==="\\";)l=!l;return l?"|":" |"}),r=n.split(De.splitPipe),i=0;if(r[0].trim()||r.shift(),r.length>0&&!r.at(-1)?.trim()&&r.pop(),t)if(r.length>t)r.splice(t);else for(;r.length<t;)r.push("");for(;i<r.length;i++)r[i]=r[i].trim().replace(De.slashPipe,"|");return r}function Gt(e,t,n){let r=e.length;if(r===0)return"";let i=0;for(;i<r&&e.charAt(r-i-1)===t;)i++;return e.slice(0,r-i)}function Wf(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]==="\\")r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function Ji(e,t,n,r,i){let s=t.href,o=t.title||null,a=e[1].replace(i.other.outputLinkReplace,"$1");r.state.inLink=!0;let l={type:e[0].charAt(0)==="!"?"image":"link",raw:n,href:s,title:o,text:a,tokens:r.inlineTokens(a)};return r.state.inLink=!1,l}function Kf(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
|
|
7
|
+
`).map(s=>{let o=s.match(n.other.beginningSpace);if(o===null)return s;let[a]=o;return a.length>=i.length?s.slice(i.length):s}).join(`
|
|
8
|
+
`)}var Dn=class{options;rules;lexer;constructor(e){this.options=e||Pt}space(e){let t=this.rules.block.newline.exec(e);if(t&&t[0].length>0)return{type:"space",raw:t[0]}}code(e){let t=this.rules.block.code.exec(e);if(t){let n=t[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:t[0],codeBlockStyle:"indented",text:this.options.pedantic?n:Gt(n,`
|
|
9
|
+
`)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let n=t[0],r=Kf(n,t[3]||"",this.rules);return{type:"code",raw:n,lang:t[2]?t[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):t[2],text:r}}}heading(e){let t=this.rules.block.heading.exec(e);if(t){let n=t[2].trim();if(this.rules.other.endingHash.test(n)){let r=Gt(n,"#");(this.options.pedantic||!r||this.rules.other.endingSpaceChar.test(r))&&(n=r.trim())}return{type:"heading",raw:t[0],depth:t[1].length,text:n,tokens:this.lexer.inline(n)}}}hr(e){let t=this.rules.block.hr.exec(e);if(t)return{type:"hr",raw:Gt(t[0],`
|
|
10
|
+
`)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=Gt(t[0],`
|
|
11
|
+
`).split(`
|
|
12
|
+
`),r="",i="",s=[];for(;n.length>0;){let o=!1,a=[],l;for(l=0;l<n.length;l++)if(this.rules.other.blockquoteStart.test(n[l]))a.push(n[l]),o=!0;else if(!o)a.push(n[l]);else break;n=n.slice(l);let u=a.join(`
|
|
13
|
+
`),c=u.replace(this.rules.other.blockquoteSetextReplace,`
|
|
14
|
+
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");r=r?`${r}
|
|
15
|
+
${u}`:u,i=i?`${i}
|
|
16
|
+
${c}`:c;let f=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(c,s,!0),this.lexer.state.top=f,n.length===0)break;let p=s.at(-1);if(p?.type==="code")break;if(p?.type==="blockquote"){let d=p,g=d.raw+`
|
|
17
|
+
`+n.join(`
|
|
18
|
+
`),x=this.blockquote(g);s[s.length-1]=x,r=r.substring(0,r.length-d.raw.length)+x.raw,i=i.substring(0,i.length-d.text.length)+x.text;break}else if(p?.type==="list"){let d=p,g=d.raw+`
|
|
19
|
+
`+n.join(`
|
|
20
|
+
`),x=this.list(g);s[s.length-1]=x,r=r.substring(0,r.length-p.raw.length)+x.raw,i=i.substring(0,i.length-d.raw.length)+x.raw,n=g.substring(s.at(-1).raw.length).split(`
|
|
21
|
+
`);continue}}return{type:"blockquote",raw:r,tokens:s,text:i}}}list(e){let t=this.rules.block.list.exec(e);if(t){let n=t[1].trim(),r=n.length>1,i={type:"list",raw:"",ordered:r,start:r?+n.slice(0,-1):"",loose:!1,items:[]};n=r?`\\d{1,9}\\${n.slice(-1)}`:`\\${n}`,this.options.pedantic&&(n=r?n:"[*+-]");let s=this.rules.other.listItemRegex(n),o=!1;for(;e;){let l=!1,u="",c="";if(!(t=s.exec(e))||this.rules.block.hr.test(e))break;u=t[0],e=e.substring(u.length);let f=t[2].split(`
|
|
22
|
+
`,1)[0].replace(this.rules.other.listReplaceTabs,x=>" ".repeat(3*x.length)),p=e.split(`
|
|
23
|
+
`,1)[0],d=!f.trim(),g=0;if(this.options.pedantic?(g=2,c=f.trimStart()):d?g=t[1].length+1:(g=t[2].search(this.rules.other.nonSpaceChar),g=g>4?1:g,c=f.slice(g),g+=t[1].length),d&&this.rules.other.blankLine.test(p)&&(u+=p+`
|
|
24
|
+
`,e=e.substring(p.length+1),l=!0),!l){let x=this.rules.other.nextBulletRegex(g),w=this.rules.other.hrRegex(g),b=this.rules.other.fencesBeginRegex(g),S=this.rules.other.headingBeginRegex(g),v=this.rules.other.htmlBeginRegex(g);for(;e;){let R=e.split(`
|
|
25
|
+
`,1)[0],M;if(p=R,this.options.pedantic?(p=p.replace(this.rules.other.listReplaceNesting," "),M=p):M=p.replace(this.rules.other.tabCharGlobal," "),b.test(p)||S.test(p)||v.test(p)||x.test(p)||w.test(p))break;if(M.search(this.rules.other.nonSpaceChar)>=g||!p.trim())c+=`
|
|
26
|
+
`+M.slice(g);else{if(d||f.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||b.test(f)||S.test(f)||w.test(f))break;c+=`
|
|
27
|
+
`+p}!d&&!p.trim()&&(d=!0),u+=R+`
|
|
28
|
+
`,e=e.substring(R.length+1),f=M.slice(g)}}i.loose||(o?i.loose=!0:this.rules.other.doubleBlankLine.test(u)&&(o=!0)),i.items.push({type:"list_item",raw:u,task:!!this.options.gfm&&this.rules.other.listIsTask.test(c),loose:!1,text:c,tokens:[]}),i.raw+=u}let a=i.items.at(-1);if(a)a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd();else return;i.raw=i.raw.trimEnd();for(let l of i.items){if(this.lexer.state.top=!1,l.tokens=this.lexer.blockTokens(l.text,[]),l.task){if(l.text=l.text.replace(this.rules.other.listReplaceTask,""),l.tokens[0]?.type==="text"||l.tokens[0]?.type==="paragraph"){l.tokens[0].raw=l.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),l.tokens[0].text=l.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let c=this.lexer.inlineQueue.length-1;c>=0;c--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[c].src)){this.lexer.inlineQueue[c].src=this.lexer.inlineQueue[c].src.replace(this.rules.other.listReplaceTask,"");break}}let u=this.rules.other.listTaskCheckbox.exec(l.raw);if(u){let c={type:"checkbox",raw:u[0]+" ",checked:u[0]!=="[ ]"};l.checked=c.checked,i.loose?l.tokens[0]&&["paragraph","text"].includes(l.tokens[0].type)&&"tokens"in l.tokens[0]&&l.tokens[0].tokens?(l.tokens[0].raw=c.raw+l.tokens[0].raw,l.tokens[0].text=c.raw+l.tokens[0].text,l.tokens[0].tokens.unshift(c)):l.tokens.unshift({type:"paragraph",raw:c.raw,text:c.raw,tokens:[c]}):l.tokens.unshift(c)}}if(!i.loose){let u=l.tokens.filter(f=>f.type==="space"),c=u.length>0&&u.some(f=>this.rules.other.anyLine.test(f.raw));i.loose=c}}if(i.loose)for(let l of i.items){l.loose=!0;for(let u of l.tokens)u.type==="text"&&(u.type="paragraph")}return i}}html(e){let t=this.rules.block.html.exec(e);if(t)return{type:"html",block:!0,raw:t[0],pre:t[1]==="pre"||t[1]==="script"||t[1]==="style",text:t[0]}}def(e){let t=this.rules.block.def.exec(e);if(t){let n=t[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),r=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",i=t[3]?t[3].substring(1,t[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):t[3];return{type:"def",tag:n,raw:t[0],href:r,title:i}}}table(e){let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=Qi(t[1]),r=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),i=t[3]?.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
|
29
|
+
`):[],s={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===r.length){for(let o of r)this.rules.other.tableAlignRight.test(o)?s.align.push("right"):this.rules.other.tableAlignCenter.test(o)?s.align.push("center"):this.rules.other.tableAlignLeft.test(o)?s.align.push("left"):s.align.push(null);for(let o=0;o<n.length;o++)s.header.push({text:n[o],tokens:this.lexer.inline(n[o]),header:!0,align:s.align[o]});for(let o of i)s.rows.push(Qi(o,s.header.length).map((a,l)=>({text:a,tokens:this.lexer.inline(a),header:!1,align:s.align[l]})));return s}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t)return{type:"heading",raw:t[0],depth:t[2].charAt(0)==="="?1:2,text:t[1],tokens:this.lexer.inline(t[1])}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let n=t[1].charAt(t[1].length-1)===`
|
|
30
|
+
`?t[1].slice(0,-1):t[1];return{type:"paragraph",raw:t[0],text:n,tokens:this.lexer.inline(n)}}}text(e){let t=this.rules.block.text.exec(e);if(t)return{type:"text",raw:t[0],text:t[0],tokens:this.lexer.inline(t[0])}}escape(e){let t=this.rules.inline.escape.exec(e);if(t)return{type:"escape",raw:t[0],text:t[1]}}tag(e){let t=this.rules.inline.tag.exec(e);if(t)return!this.lexer.state.inLink&&this.rules.other.startATag.test(t[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(t[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(t[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(t[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:t[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:t[0]}}link(e){let t=this.rules.inline.link.exec(e);if(t){let n=t[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(n)){if(!this.rules.other.endAngleBracket.test(n))return;let s=Gt(n.slice(0,-1),"\\");if((n.length-s.length)%2===0)return}else{let s=Wf(t[2],"()");if(s===-2)return;if(s>-1){let o=(t[0].indexOf("!")===0?5:4)+t[1].length+s;t[2]=t[2].substring(0,s),t[0]=t[0].substring(0,o).trim(),t[3]=""}}let r=t[2],i="";if(this.options.pedantic){let s=this.rules.other.pedanticHrefTitle.exec(r);s&&(r=s[1],i=s[3])}else i=t[3]?t[3].slice(1,-1):"";return r=r.trim(),this.rules.other.startAngleBracket.test(r)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?r=r.slice(1):r=r.slice(1,-1)),Ji(t,{href:r&&r.replace(this.rules.inline.anyPunctuation,"$1"),title:i&&i.replace(this.rules.inline.anyPunctuation,"$1")},t[0],this.lexer,this.rules)}}reflink(e,t){let n;if((n=this.rules.inline.reflink.exec(e))||(n=this.rules.inline.nolink.exec(e))){let r=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),i=t[r.toLowerCase()];if(!i){let s=n[0].charAt(0);return{type:"text",raw:s,text:s}}return Ji(n,i,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let r=this.rules.inline.emStrongLDelim.exec(e);if(!(!r||r[3]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(r[1]||r[2])||!n||this.rules.inline.punctuation.exec(n))){let i=[...r[0]].length-1,s,o,a=i,l=0,u=r[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(u.lastIndex=0,t=t.slice(-1*e.length+i);(r=u.exec(t))!=null;){if(s=r[1]||r[2]||r[3]||r[4]||r[5]||r[6],!s)continue;if(o=[...s].length,r[3]||r[4]){a+=o;continue}else if((r[5]||r[6])&&i%3&&!((i+o)%3)){l+=o;continue}if(a-=o,a>0)continue;o=Math.min(o,o+a+l);let c=[...r[0]][0].length,f=e.slice(0,i+r.index+c+o);if(Math.min(i,o)%2){let d=f.slice(1,-1);return{type:"em",raw:f,text:d,tokens:this.lexer.inlineTokens(d)}}let p=f.slice(2,-2);return{type:"strong",raw:f,text:p,tokens:this.lexer.inlineTokens(p)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let n=t[2].replace(this.rules.other.newLineCharGlobal," "),r=this.rules.other.nonSpaceChar.test(n),i=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return r&&i&&(n=n.substring(1,n.length-1)),{type:"codespan",raw:t[0],text:n}}}br(e){let t=this.rules.inline.br.exec(e);if(t)return{type:"br",raw:t[0]}}del(e){let t=this.rules.inline.del.exec(e);if(t)return{type:"del",raw:t[0],text:t[2],tokens:this.lexer.inlineTokens(t[2])}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let n,r;return t[2]==="@"?(n=t[1],r="mailto:"+n):(n=t[1],r=n),{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}url(e){let t;if(t=this.rules.inline.url.exec(e)){let n,r;if(t[2]==="@")n=t[0],r="mailto:"+n;else{let i;do i=t[0],t[0]=this.rules.inline._backpedal.exec(t[0])?.[0]??"";while(i!==t[0]);n=t[0],t[1]==="www."?r="http://"+t[0]:r=t[0]}return{type:"link",raw:t[0],text:n,href:r,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(e){let t=this.rules.inline.text.exec(e);if(t){let n=this.lexer.state.inRawBlock;return{type:"text",raw:t[0],text:t[0],escaped:n}}}},Qe=class Pr{tokens;options;state;inlineQueue;tokenizer;constructor(t){this.tokens=[],this.tokens.links=Object.create(null),this.options=t||Pt,this.options.tokenizer=this.options.tokenizer||new Dn,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};let n={other:De,block:gn.normal,inline:Yt.normal};this.options.pedantic?(n.block=gn.pedantic,n.inline=Yt.pedantic):this.options.gfm&&(n.block=gn.gfm,this.options.breaks?n.inline=Yt.breaks:n.inline=Yt.gfm),this.tokenizer.rules=n}static get rules(){return{block:gn,inline:Yt}}static lex(t,n){return new Pr(n).lex(t)}static lexInline(t,n){return new Pr(n).inlineTokens(t)}lex(t){t=t.replace(De.carriageReturn,`
|
|
31
|
+
`),this.blockTokens(t,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let r=this.inlineQueue[n];this.inlineTokens(r.src,r.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(t,n=[],r=!1){for(this.options.pedantic&&(t=t.replace(De.tabCharGlobal," ").replace(De.spaceLine,""));t;){let i;if(this.options.extensions?.block?.some(o=>(i=o.call({lexer:this},t,n))?(t=t.substring(i.raw.length),n.push(i),!0):!1))continue;if(i=this.tokenizer.space(t)){t=t.substring(i.raw.length);let o=n.at(-1);i.raw.length===1&&o!==void 0?o.raw+=`
|
|
32
|
+
`:n.push(i);continue}if(i=this.tokenizer.code(t)){t=t.substring(i.raw.length);let o=n.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=(o.raw.endsWith(`
|
|
33
|
+
`)?"":`
|
|
34
|
+
`)+i.raw,o.text+=`
|
|
35
|
+
`+i.text,this.inlineQueue.at(-1).src=o.text):n.push(i);continue}if(i=this.tokenizer.fences(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.heading(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.hr(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.blockquote(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.list(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.html(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.def(t)){t=t.substring(i.raw.length);let o=n.at(-1);o?.type==="paragraph"||o?.type==="text"?(o.raw+=(o.raw.endsWith(`
|
|
36
|
+
`)?"":`
|
|
37
|
+
`)+i.raw,o.text+=`
|
|
38
|
+
`+i.raw,this.inlineQueue.at(-1).src=o.text):this.tokens.links[i.tag]||(this.tokens.links[i.tag]={href:i.href,title:i.title},n.push(i));continue}if(i=this.tokenizer.table(t)){t=t.substring(i.raw.length),n.push(i);continue}if(i=this.tokenizer.lheading(t)){t=t.substring(i.raw.length),n.push(i);continue}let s=t;if(this.options.extensions?.startBlock){let o=1/0,a=t.slice(1),l;this.options.extensions.startBlock.forEach(u=>{l=u.call({lexer:this},a),typeof l=="number"&&l>=0&&(o=Math.min(o,l))}),o<1/0&&o>=0&&(s=t.substring(0,o+1))}if(this.state.top&&(i=this.tokenizer.paragraph(s))){let o=n.at(-1);r&&o?.type==="paragraph"?(o.raw+=(o.raw.endsWith(`
|
|
39
|
+
`)?"":`
|
|
40
|
+
`)+i.raw,o.text+=`
|
|
41
|
+
`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):n.push(i),r=s.length!==t.length,t=t.substring(i.raw.length);continue}if(i=this.tokenizer.text(t)){t=t.substring(i.raw.length);let o=n.at(-1);o?.type==="text"?(o.raw+=(o.raw.endsWith(`
|
|
42
|
+
`)?"":`
|
|
43
|
+
`)+i.raw,o.text+=`
|
|
44
|
+
`+i.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):n.push(i);continue}if(t){let o="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(o);break}else throw new Error(o)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){let r=t,i=null;if(this.tokens.links){let l=Object.keys(this.tokens.links);if(l.length>0)for(;(i=this.tokenizer.rules.inline.reflinkSearch.exec(r))!=null;)l.includes(i[0].slice(i[0].lastIndexOf("[")+1,-1))&&(r=r.slice(0,i.index)+"["+"a".repeat(i[0].length-2)+"]"+r.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(i=this.tokenizer.rules.inline.anyPunctuation.exec(r))!=null;)r=r.slice(0,i.index)+"++"+r.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let s;for(;(i=this.tokenizer.rules.inline.blockSkip.exec(r))!=null;)s=i[2]?i[2].length:0,r=r.slice(0,i.index+s)+"["+"a".repeat(i[0].length-s-2)+"]"+r.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);r=this.options.hooks?.emStrongMask?.call({lexer:this},r)??r;let o=!1,a="";for(;t;){o||(a=""),o=!1;let l;if(this.options.extensions?.inline?.some(c=>(l=c.call({lexer:this},t,n))?(t=t.substring(l.raw.length),n.push(l),!0):!1))continue;if(l=this.tokenizer.escape(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.tag(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.link(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(l.raw.length);let c=n.at(-1);l.type==="text"&&c?.type==="text"?(c.raw+=l.raw,c.text+=l.text):n.push(l);continue}if(l=this.tokenizer.emStrong(t,r,a)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.codespan(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.br(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.del(t)){t=t.substring(l.raw.length),n.push(l);continue}if(l=this.tokenizer.autolink(t)){t=t.substring(l.raw.length),n.push(l);continue}if(!this.state.inLink&&(l=this.tokenizer.url(t))){t=t.substring(l.raw.length),n.push(l);continue}let u=t;if(this.options.extensions?.startInline){let c=1/0,f=t.slice(1),p;this.options.extensions.startInline.forEach(d=>{p=d.call({lexer:this},f),typeof p=="number"&&p>=0&&(c=Math.min(c,p))}),c<1/0&&c>=0&&(u=t.substring(0,c+1))}if(l=this.tokenizer.inlineText(u)){t=t.substring(l.raw.length),l.raw.slice(-1)!=="_"&&(a=l.raw.slice(-1)),o=!0;let c=n.at(-1);c?.type==="text"?(c.raw+=l.raw,c.text+=l.text):n.push(l);continue}if(t){let c="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(c);break}else throw new Error(c)}}return n}},Pn=class{options;parser;constructor(e){this.options=e||Pt}space(e){return""}code({text:e,lang:t,escaped:n}){let r=(t||"").match(De.notSpaceStart)?.[0],i=e.replace(De.endingNewline,"")+`
|
|
45
|
+
`;return r?'<pre><code class="language-'+at(r)+'">'+(n?i:at(i,!0))+`</code></pre>
|
|
46
|
+
`:"<pre><code>"+(n?i:at(i,!0))+`</code></pre>
|
|
47
|
+
`}blockquote({tokens:e}){return`<blockquote>
|
|
48
|
+
${this.parser.parse(e)}</blockquote>
|
|
49
|
+
`}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
|
|
50
|
+
`}hr(e){return`<hr>
|
|
51
|
+
`}list(e){let t=e.ordered,n=e.start,r="";for(let o=0;o<e.items.length;o++){let a=e.items[o];r+=this.listitem(a)}let i=t?"ol":"ul",s=t&&n!==1?' start="'+n+'"':"";return"<"+i+s+`>
|
|
52
|
+
`+r+"</"+i+`>
|
|
53
|
+
`}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>
|
|
54
|
+
`}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
|
|
55
|
+
`}table(e){let t="",n="";for(let i=0;i<e.header.length;i++)n+=this.tablecell(e.header[i]);t+=this.tablerow({text:n});let r="";for(let i=0;i<e.rows.length;i++){let s=e.rows[i];n="";for(let o=0;o<s.length;o++)n+=this.tablecell(s[o]);r+=this.tablerow({text:n})}return r&&(r=`<tbody>${r}</tbody>`),`<table>
|
|
56
|
+
<thead>
|
|
57
|
+
`+t+`</thead>
|
|
58
|
+
`+r+`</table>
|
|
59
|
+
`}tablerow({text:e}){return`<tr>
|
|
60
|
+
${e}</tr>
|
|
61
|
+
`}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
|
|
62
|
+
`}strong({tokens:e}){return`<strong>${this.parser.parseInline(e)}</strong>`}em({tokens:e}){return`<em>${this.parser.parseInline(e)}</em>`}codespan({text:e}){return`<code>${at(e,!0)}</code>`}br(e){return"<br>"}del({tokens:e}){return`<del>${this.parser.parseInline(e)}</del>`}link({href:e,title:t,tokens:n}){let r=this.parser.parseInline(n),i=Gi(e);if(i===null)return r;e=i;let s='<a href="'+e+'"';return t&&(s+=' title="'+at(t)+'"'),s+=">"+r+"</a>",s}image({href:e,title:t,text:n,tokens:r}){r&&(n=this.parser.parseInline(r,this.parser.textRenderer));let i=Gi(e);if(i===null)return at(n);e=i;let s=`<img src="${e}" alt="${n}"`;return t&&(s+=` title="${at(t)}"`),s+=">",s}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:at(e.text)}},hi=class{strong({text:e}){return e}em({text:e}){return e}codespan({text:e}){return e}del({text:e}){return e}html({text:e}){return e}text({text:e}){return e}link({text:e}){return""+e}image({text:e}){return""+e}br(){return""}checkbox({raw:e}){return e}},Je=class zr{options;renderer;textRenderer;constructor(t){this.options=t||Pt,this.options.renderer=this.options.renderer||new Pn,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new hi}static parse(t,n){return new zr(n).parse(t)}static parseInline(t,n){return new zr(n).parseInline(t)}parse(t){let n="";for(let r=0;r<t.length;r++){let i=t[r];if(this.options.extensions?.renderers?.[i.type]){let o=i,a=this.options.extensions.renderers[o.type].call({parser:this},o);if(a!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(o.type)){n+=a||"";continue}}let s=i;switch(s.type){case"space":{n+=this.renderer.space(s);break}case"hr":{n+=this.renderer.hr(s);break}case"heading":{n+=this.renderer.heading(s);break}case"code":{n+=this.renderer.code(s);break}case"table":{n+=this.renderer.table(s);break}case"blockquote":{n+=this.renderer.blockquote(s);break}case"list":{n+=this.renderer.list(s);break}case"checkbox":{n+=this.renderer.checkbox(s);break}case"html":{n+=this.renderer.html(s);break}case"def":{n+=this.renderer.def(s);break}case"paragraph":{n+=this.renderer.paragraph(s);break}case"text":{n+=this.renderer.text(s);break}default:{let o='Token with "'+s.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}parseInline(t,n=this.renderer){let r="";for(let i=0;i<t.length;i++){let s=t[i];if(this.options.extensions?.renderers?.[s.type]){let a=this.options.extensions.renderers[s.type].call({parser:this},s);if(a!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(s.type)){r+=a||"";continue}}let o=s;switch(o.type){case"escape":{r+=n.text(o);break}case"html":{r+=n.html(o);break}case"link":{r+=n.link(o);break}case"image":{r+=n.image(o);break}case"checkbox":{r+=n.checkbox(o);break}case"strong":{r+=n.strong(o);break}case"em":{r+=n.em(o);break}case"codespan":{r+=n.codespan(o);break}case"br":{r+=n.br(o);break}case"del":{r+=n.del(o);break}case"text":{r+=n.text(o);break}default:{let a='Token with "'+o.type+'" type was not found.';if(this.options.silent)return console.error(a),"";throw new Error(a)}}}return r}},tn=class{options;block;constructor(e){this.options=e||Pt}static passThroughHooks=new Set(["preprocess","postprocess","processAllTokens","emStrongMask"]);static passThroughHooksRespectAsync=new Set(["preprocess","postprocess","processAllTokens"]);preprocess(e){return e}postprocess(e){return e}processAllTokens(e){return e}emStrongMask(e){return e}provideLexer(){return this.block?Qe.lex:Qe.lexInline}provideParser(){return this.block?Je.parse:Je.parseInline}},Xf=class{defaults=ii();options=this.setOptions;parse=this.parseMarkdown(!0);parseInline=this.parseMarkdown(!1);Parser=Je;Renderer=Pn;TextRenderer=hi;Lexer=Qe;Tokenizer=Dn;Hooks=tn;constructor(...e){this.use(...e)}walkTokens(e,t){let n=[];for(let r of e)switch(n=n.concat(t.call(this,r)),r.type){case"table":{let i=r;for(let s of i.header)n=n.concat(this.walkTokens(s.tokens,t));for(let s of i.rows)for(let o of s)n=n.concat(this.walkTokens(o.tokens,t));break}case"list":{let i=r;n=n.concat(this.walkTokens(i.items,t));break}default:{let i=r;this.defaults.extensions?.childTokens?.[i.type]?this.defaults.extensions.childTokens[i.type].forEach(s=>{let o=i[s].flat(1/0);n=n.concat(this.walkTokens(o,t))}):i.tokens&&(n=n.concat(this.walkTokens(i.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(n=>{let r={...n};if(r.async=this.defaults.async||r.async||!1,n.extensions&&(n.extensions.forEach(i=>{if(!i.name)throw new Error("extension name required");if("renderer"in i){let s=t.renderers[i.name];s?t.renderers[i.name]=function(...o){let a=i.renderer.apply(this,o);return a===!1&&(a=s.apply(this,o)),a}:t.renderers[i.name]=i.renderer}if("tokenizer"in i){if(!i.level||i.level!=="block"&&i.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let s=t[i.level];s?s.unshift(i.tokenizer):t[i.level]=[i.tokenizer],i.start&&(i.level==="block"?t.startBlock?t.startBlock.push(i.start):t.startBlock=[i.start]:i.level==="inline"&&(t.startInline?t.startInline.push(i.start):t.startInline=[i.start]))}"childTokens"in i&&i.childTokens&&(t.childTokens[i.name]=i.childTokens)}),r.extensions=t),n.renderer){let i=this.defaults.renderer||new Pn(this.defaults);for(let s in n.renderer){if(!(s in i))throw new Error(`renderer '${s}' does not exist`);if(["options","parser"].includes(s))continue;let o=s,a=n.renderer[o],l=i[o];i[o]=(...u)=>{let c=a.apply(i,u);return c===!1&&(c=l.apply(i,u)),c||""}}r.renderer=i}if(n.tokenizer){let i=this.defaults.tokenizer||new Dn(this.defaults);for(let s in n.tokenizer){if(!(s in i))throw new Error(`tokenizer '${s}' does not exist`);if(["options","rules","lexer"].includes(s))continue;let o=s,a=n.tokenizer[o],l=i[o];i[o]=(...u)=>{let c=a.apply(i,u);return c===!1&&(c=l.apply(i,u)),c}}r.tokenizer=i}if(n.hooks){let i=this.defaults.hooks||new tn;for(let s in n.hooks){if(!(s in i))throw new Error(`hook '${s}' does not exist`);if(["options","block"].includes(s))continue;let o=s,a=n.hooks[o],l=i[o];tn.passThroughHooks.has(s)?i[o]=u=>{if(this.defaults.async&&tn.passThroughHooksRespectAsync.has(s))return(async()=>{let f=await a.call(i,u);return l.call(i,f)})();let c=a.call(i,u);return l.call(i,c)}:i[o]=(...u)=>{if(this.defaults.async)return(async()=>{let f=await a.apply(i,u);return f===!1&&(f=await l.apply(i,u)),f})();let c=a.apply(i,u);return c===!1&&(c=l.apply(i,u)),c}}r.hooks=i}if(n.walkTokens){let i=this.defaults.walkTokens,s=n.walkTokens;r.walkTokens=function(o){let a=[];return a.push(s.call(this,o)),i&&(a=a.concat(i.call(this,o))),a}}this.defaults={...this.defaults,...r}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return Qe.lex(e,t??this.defaults)}parser(e,t){return Je.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let r={...n},i={...this.defaults,...r},s=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&r.async===!1)return s(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof t>"u"||t===null)return s(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return s(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(i.hooks&&(i.hooks.options=i,i.hooks.block=e),i.async)return(async()=>{let o=i.hooks?await i.hooks.preprocess(t):t,a=await(i.hooks?await i.hooks.provideLexer():e?Qe.lex:Qe.lexInline)(o,i),l=i.hooks?await i.hooks.processAllTokens(a):a;i.walkTokens&&await Promise.all(this.walkTokens(l,i.walkTokens));let u=await(i.hooks?await i.hooks.provideParser():e?Je.parse:Je.parseInline)(l,i);return i.hooks?await i.hooks.postprocess(u):u})().catch(s);try{i.hooks&&(t=i.hooks.preprocess(t));let o=(i.hooks?i.hooks.provideLexer():e?Qe.lex:Qe.lexInline)(t,i);i.hooks&&(o=i.hooks.processAllTokens(o)),i.walkTokens&&this.walkTokens(o,i.walkTokens);let a=(i.hooks?i.hooks.provideParser():e?Je.parse:Je.parseInline)(o,i);return i.hooks&&(a=i.hooks.postprocess(a)),a}catch(o){return s(o)}}}onError(e,t){return n=>{if(n.message+=`
|
|
63
|
+
Please report this to https://github.com/markedjs/marked.`,e){let r="<p>An error occurred:</p><pre>"+at(n.message+"",!0)+"</pre>";return t?Promise.resolve(r):r}if(t)return Promise.reject(n);throw n}}},Mt=new Xf;function ce(e,t){return Mt.parse(e,t)}ce.options=ce.setOptions=function(e){return Mt.setOptions(e),ce.defaults=Mt.defaults,Ro(ce.defaults),ce};ce.getDefaults=ii;ce.defaults=Pt;ce.use=function(...e){return Mt.use(...e),ce.defaults=Mt.defaults,Ro(ce.defaults),ce};ce.walkTokens=function(e,t){return Mt.walkTokens(e,t)};ce.parseInline=Mt.parseInline;ce.Parser=Je;ce.parser=Je.parse;ce.Renderer=Pn;ce.TextRenderer=hi;ce.Lexer=Qe;ce.lexer=Qe.lex;ce.Tokenizer=Dn;ce.Hooks=tn;ce.parse=ce;ce.options;ce.setOptions;ce.use;ce.walkTokens;ce.parseInline;Je.parse;Qe.lex;const Vf=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Yf=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,Gf={};function Zi(e,t){return(Gf.jsx?Yf:Vf).test(e)}var Ft={},ur,es;function Qf(){if(es)return ur;es=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,i=/^:\s*/,s=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,o=/^[;\s]*/,a=/^\s+|\s+$/g,l=`
|
|
64
|
+
`,u="/",c="*",f="",p="comment",d="declaration";function g(w,b){if(typeof w!="string")throw new TypeError("First argument must be a string");if(!w)return[];b=b||{};var S=1,v=1;function R(j){var T=j.match(t);T&&(S+=T.length);var D=j.lastIndexOf(l);v=~D?j.length-D:v+j.length}function M(){var j={line:S,column:v};return function(T){return T.position=new C(j),F(),T}}function C(j){this.start=j,this.end={line:S,column:v},this.source=b.source}C.prototype.content=w;function P(j){var T=new Error(b.source+":"+S+":"+v+": "+j);if(T.reason=j,T.filename=b.source,T.line=S,T.column=v,T.source=w,!b.silent)throw T}function U(j){var T=j.exec(w);if(T){var D=T[0];return R(D),w=w.slice(D.length),T}}function F(){U(n)}function E(j){var T;for(j=j||[];T=N();)T!==!1&&j.push(T);return j}function N(){var j=M();if(!(u!=w.charAt(0)||c!=w.charAt(1))){for(var T=2;f!=w.charAt(T)&&(c!=w.charAt(T)||u!=w.charAt(T+1));)++T;if(T+=2,f===w.charAt(T-1))return P("End of comment missing");var D=w.slice(2,T-2);return v+=2,R(D),w=w.slice(T),v+=2,j({type:p,comment:D})}}function A(){var j=M(),T=U(r);if(T){if(N(),!U(i))return P("property missing ':'");var D=U(s),L=j({type:d,property:x(T[0].replace(e,f)),value:D?x(D[0].replace(e,f)):f});return U(o),L}}function z(){var j=[];E(j);for(var T;T=A();)T!==!1&&(j.push(T),E(j));return j}return F(),z()}function x(w){return w?w.replace(a,f):f}return ur=g,ur}var ts;function Jf(){if(ts)return Ft;ts=1;var e=Ft&&Ft.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Ft,"__esModule",{value:!0}),Ft.default=n;const t=e(Qf());function n(r,i){let s=null;if(!r||typeof r!="string")return s;const o=(0,t.default)(r),a=typeof i=="function";return o.forEach(l=>{if(l.type!=="declaration")return;const{property:u,value:c}=l;a?i(u,c,l):c&&(s=s||{},s[u]=c)}),s}return Ft}var Qt={},ns;function Zf(){if(ns)return Qt;ns=1,Object.defineProperty(Qt,"__esModule",{value:!0}),Qt.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,i=/^-(ms)-/,s=function(u){return!u||n.test(u)||e.test(u)},o=function(u,c){return c.toUpperCase()},a=function(u,c){return"".concat(c,"-")},l=function(u,c){return c===void 0&&(c={}),s(u)?u:(u=u.toLowerCase(),c.reactCompat?u=u.replace(i,a):u=u.replace(r,a),u.replace(t,o))};return Qt.camelCase=l,Qt}var Jt,rs;function eh(){if(rs)return Jt;rs=1;var e=Jt&&Jt.__importDefault||function(i){return i&&i.__esModule?i:{default:i}},t=e(Jf()),n=Zf();function r(i,s){var o={};return!i||typeof i!="string"||(0,t.default)(i,function(a,l){a&&l&&(o[(0,n.camelCase)(a,s)]=l)}),o}return r.default=r,Jt=r,Jt}var th=eh();const nh=Gs(th),Bo=Ho("end"),pi=Ho("start");function Ho(e){return t;function t(n){const r=n&&n.position&&n.position[e]||{};if(typeof r.line=="number"&&r.line>0&&typeof r.column=="number"&&r.column>0)return{line:r.line,column:r.column,offset:typeof r.offset=="number"&&r.offset>-1?r.offset:void 0}}}function rh(e){const t=pi(e),n=Bo(e);if(t&&n)return{start:t,end:n}}function sn(e){return!e||typeof e!="object"?"":"position"in e||"type"in e?is(e.position):"start"in e||"end"in e?is(e):"line"in e||"column"in e?_r(e):""}function _r(e){return ss(e&&e.line)+":"+ss(e&&e.column)}function is(e){return _r(e&&e.start)+"-"+_r(e&&e.end)}function ss(e){return e&&typeof e=="number"?e:1}class Ne extends Error{constructor(t,n,r){super(),typeof n=="string"&&(r=n,n=void 0);let i="",s={},o=!1;if(n&&("line"in n&&"column"in n?s={place:n}:"start"in n&&"end"in n?s={place:n}:"type"in n?s={ancestors:[n],place:n.position}:s={...n}),typeof t=="string"?i=t:!s.cause&&t&&(o=!0,i=t.message,s.cause=t),!s.ruleId&&!s.source&&typeof r=="string"){const l=r.indexOf(":");l===-1?s.ruleId=r:(s.source=r.slice(0,l),s.ruleId=r.slice(l+1))}if(!s.place&&s.ancestors&&s.ancestors){const l=s.ancestors[s.ancestors.length-1];l&&(s.place=l.position)}const a=s.place&&"start"in s.place?s.place.start:s.place;this.ancestors=s.ancestors||void 0,this.cause=s.cause||void 0,this.column=a?a.column:void 0,this.fatal=void 0,this.file="",this.message=i,this.line=a?a.line:void 0,this.name=sn(s.place)||"1:1",this.place=s.place||void 0,this.reason=this.message,this.ruleId=s.ruleId||void 0,this.source=s.source||void 0,this.stack=o&&s.cause&&typeof s.cause.stack=="string"?s.cause.stack:"",this.actual=void 0,this.expected=void 0,this.note=void 0,this.url=void 0}}Ne.prototype.file="";Ne.prototype.name="";Ne.prototype.reason="";Ne.prototype.message="";Ne.prototype.stack="";Ne.prototype.column=void 0;Ne.prototype.line=void 0;Ne.prototype.ancestors=void 0;Ne.prototype.cause=void 0;Ne.prototype.fatal=void 0;Ne.prototype.place=void 0;Ne.prototype.ruleId=void 0;Ne.prototype.source=void 0;const di={}.hasOwnProperty,ih=new Map,sh=/[A-Z]/g,oh=new Set(["table","tbody","thead","tfoot","tr"]),ah=new Set(["td","th"]),Uo="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function lh(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=gh(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=mh(n,t.jsx,t.jsxs)}const i={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?Zr:lu,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},s=qo(i,e,void 0);return s&&typeof s!="string"?s:i.create(e,i.Fragment,{children:s||void 0},void 0)}function qo(e,t,n){if(t.type==="element")return uh(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return ch(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return hh(e,t,n);if(t.type==="mdxjsEsm")return fh(e,t);if(t.type==="root")return ph(e,t,n);if(t.type==="text")return dh(e,t)}function uh(e,t,n){const r=e.schema;let i=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(i=Zr,e.schema=i),e.ancestors.push(t);const s=Ko(e,t.tagName,!1),o=xh(e,t);let a=gi(e,t);return oh.has(t.tagName)&&(a=a.filter(function(l){return typeof l=="string"?!uu(l):!0})),Wo(e,o,s,t),mi(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function ch(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}ln(e,t.position)}function fh(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);ln(e,t.position)}function hh(e,t,n){const r=e.schema;let i=r;t.name==="svg"&&r.space==="html"&&(i=Zr,e.schema=i),e.ancestors.push(t);const s=t.name===null?e.Fragment:Ko(e,t.name,!0),o=yh(e,t),a=gi(e,t);return Wo(e,o,s,t),mi(o,a),e.ancestors.pop(),e.schema=r,e.create(t,s,o,n)}function ph(e,t,n){const r={};return mi(r,gi(e,t)),e.create(t,e.Fragment,r,n)}function dh(e,t){return t.value}function Wo(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function mi(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function mh(e,t,n){return r;function r(i,s,o,a){const u=Array.isArray(o.children)?n:t;return a?u(s,o,a):u(s,o)}}function gh(e,t){return n;function n(r,i,s,o){const a=Array.isArray(s.children),l=pi(r);return t(i,s,o,a,{columnNumber:l?l.column-1:void 0,fileName:e,lineNumber:l?l.line:void 0},void 0)}}function xh(e,t){const n={};let r,i;for(i in t.properties)if(i!=="children"&&di.call(t.properties,i)){const s=bh(e,i,t.properties[i]);if(s){const[o,a]=s;e.tableCellAlignToStyle&&o==="align"&&typeof a=="string"&&ah.has(t.tagName)?r=a:n[o]=a}}if(r){const s=n.style||(n.style={});s[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function yh(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const s=r.data.estree.body[0];s.type;const o=s.expression;o.type;const a=o.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else ln(e,t.position);else{const i=r.name;let s;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const a=r.value.data.estree.body[0];a.type,s=e.evaluater.evaluateExpression(a.expression)}else ln(e,t.position);else s=r.value===null?!0:r.value;n[i]=s}return n}function gi(e,t){const n=[];let r=-1;const i=e.passKeys?new Map:ih;for(;++r<t.children.length;){const s=t.children[r];let o;if(e.passKeys){const l=s.type==="element"?s.tagName:s.type==="mdxJsxFlowElement"||s.type==="mdxJsxTextElement"?s.name:void 0;if(l){const u=i.get(l)||0;o=l+"-"+u,i.set(l,u+1)}}const a=qo(e,s,o);a!==void 0&&n.push(a)}return n}function bh(e,t,n){const r=cu(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?fu(n):hu(n)),r.property==="style"){let i=typeof n=="object"?n:kh(e,String(n));return e.stylePropertyNameCase==="css"&&(i=wh(i)),["style",i]}return[e.elementAttributeNameCase==="react"&&r.space?mu[r.property]||r.property:r.attribute,n]}}function kh(e,t){try{return nh(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,i=new Ne("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw i.file=e.filePath||void 0,i.url=Uo+"#cannot-parse-style-attribute",i}}function Ko(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const i=t.split(".");let s=-1,o;for(;++s<i.length;){const a=Zi(i[s])?{type:"Identifier",name:i[s]}:{type:"Literal",value:i[s]};o=o?{type:"MemberExpression",object:o,property:a,computed:!!(s&&a.type==="Literal"),optional:!1}:a}r=o}else r=Zi(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const i=r.value;return di.call(e.components,i)?e.components[i]:i}if(e.evaluater)return e.evaluater.evaluateExpression(r);ln(e)}function ln(e,t){const n=new Ne("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=Uo+"#cannot-handle-mdx-estrees-without-createevaluater",n}function wh(e){const t={};let n;for(n in e)di.call(e,n)&&(t[Sh(n)]=e[n]);return t}function Sh(e){let t=e.replace(sh,Ch);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function Ch(e){return"-"+e.toLowerCase()}const cr={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},vh={};function xi(e,t){const n=vh,r=typeof n.includeImageAlt=="boolean"?n.includeImageAlt:!0,i=typeof n.includeHtml=="boolean"?n.includeHtml:!0;return Xo(e,r,i)}function Xo(e,t,n){if(Eh(e)){if("value"in e)return e.type==="html"&&!n?"":e.value;if(t&&"alt"in e&&e.alt)return e.alt;if("children"in e)return os(e.children,t,n)}return Array.isArray(e)?os(e,t,n):""}function os(e,t,n){const r=[];let i=-1;for(;++i<e.length;)r[i]=Xo(e[i],t,n);return r.join("")}function Eh(e){return!!(e&&typeof e=="object")}const as=document.createElement("i");function yi(e){const t="&"+e+";";as.innerHTML=t;const n=as.textContent;return n.charCodeAt(n.length-1)===59&&e!=="semi"||n===t?!1:n}function qe(e,t,n,r){const i=e.length;let s=0,o;if(t<0?t=-t>i?0:i+t:t=t>i?i:t,n=n>0?n:0,r.length<1e4)o=Array.from(r),o.unshift(t,n),e.splice(...o);else for(n&&e.splice(t,n);s<r.length;)o=r.slice(s,s+1e4),o.unshift(t,0),e.splice(...o),s+=1e4,t+=1e4}function Ve(e,t){return e.length>0?(qe(e,e.length,0,t),e):t}const ls={}.hasOwnProperty;function Vo(e){const t={};let n=-1;for(;++n<e.length;)Th(t,e[n]);return t}function Th(e,t){let n;for(n in t){const i=(ls.call(e,n)?e[n]:void 0)||(e[n]={}),s=t[n];let o;if(s)for(o in s){ls.call(i,o)||(i[o]=[]);const a=s[o];jh(i[o],Array.isArray(a)?a:a?[a]:[])}}}function jh(e,t){let n=-1;const r=[];for(;++n<t.length;)(t[n].add==="after"?e:r).push(t[n]);qe(e,0,0,r)}function Yo(e,t){const n=Number.parseInt(e,t);return n<9||n===11||n>13&&n<32||n>126&&n<160||n>55295&&n<57344||n>64975&&n<65008||(n&65535)===65535||(n&65535)===65534||n>1114111?"�":String.fromCodePoint(n)}function tt(e){return e.replace(/[\t\n\r ]+/g," ").replace(/^ | $/g,"").toLowerCase().toUpperCase()}const Me=Ct(/[A-Za-z]/),Re=Ct(/[\dA-Za-z]/),Ah=Ct(/[#-'*+\--9=?A-Z^-~]/);function zn(e){return e!==null&&(e<32||e===127)}const Or=Ct(/\d/),Ih=Ct(/[\dA-Fa-f]/),Rh=Ct(/[!-/:-@[-`{-~]/);function G(e){return e!==null&&e<-2}function fe(e){return e!==null&&(e<0||e===32)}function ie(e){return e===-2||e===-1||e===32}const Yn=Ct(new RegExp("\\p{P}|\\p{S}","u")),Dt=Ct(/\s/);function Ct(e){return t;function t(n){return n!==null&&n>-1&&e.test(String.fromCharCode(n))}}function Kt(e){const t=[];let n=-1,r=0,i=0;for(;++n<e.length;){const s=e.charCodeAt(n);let o="";if(s===37&&Re(e.charCodeAt(n+1))&&Re(e.charCodeAt(n+2)))i=2;else if(s<128)/[!#$&-;=?-Z_a-z~]/.test(String.fromCharCode(s))||(o=String.fromCharCode(s));else if(s>55295&&s<57344){const a=e.charCodeAt(n+1);s<56320&&a>56319&&a<57344?(o=String.fromCharCode(s,a),i=1):o="�"}else o=String.fromCharCode(s);o&&(t.push(e.slice(r,n),encodeURIComponent(o)),r=n+i+1,o=""),i&&(n+=i,i=0)}return t.join("")+e.slice(r)}function oe(e,t,n,r){const i=r?r-1:Number.POSITIVE_INFINITY;let s=0;return o;function o(l){return ie(l)?(e.enter(n),a(l)):t(l)}function a(l){return ie(l)&&s++<i?(e.consume(l),a):(e.exit(n),t(l))}}const Nh={tokenize:Lh};function Lh(e){const t=e.attempt(this.parser.constructs.contentInitial,r,i);let n;return t;function r(a){if(a===null){e.consume(a);return}return e.enter("lineEnding"),e.consume(a),e.exit("lineEnding"),oe(e,t,"linePrefix")}function i(a){return e.enter("paragraph"),s(a)}function s(a){const l=e.enter("chunkText",{contentType:"text",previous:n});return n&&(n.next=l),n=l,o(a)}function o(a){if(a===null){e.exit("chunkText"),e.exit("paragraph"),e.consume(a);return}return G(a)?(e.consume(a),e.exit("chunkText"),s):(e.consume(a),o)}}const Mh={tokenize:Dh},us={tokenize:Ph};function Dh(e){const t=this,n=[];let r=0,i,s,o;return a;function a(v){if(r<n.length){const R=n[r];return t.containerState=R[1],e.attempt(R[0].continuation,l,u)(v)}return u(v)}function l(v){if(r++,t.containerState._closeFlow){t.containerState._closeFlow=void 0,i&&S();const R=t.events.length;let M=R,C;for(;M--;)if(t.events[M][0]==="exit"&&t.events[M][1].type==="chunkFlow"){C=t.events[M][1].end;break}b(r);let P=R;for(;P<t.events.length;)t.events[P][1].end={...C},P++;return qe(t.events,M+1,0,t.events.slice(R)),t.events.length=P,u(v)}return a(v)}function u(v){if(r===n.length){if(!i)return p(v);if(i.currentConstruct&&i.currentConstruct.concrete)return g(v);t.interrupt=!!(i.currentConstruct&&!i._gfmTableDynamicInterruptHack)}return t.containerState={},e.check(us,c,f)(v)}function c(v){return i&&S(),b(r),p(v)}function f(v){return t.parser.lazy[t.now().line]=r!==n.length,o=t.now().offset,g(v)}function p(v){return t.containerState={},e.attempt(us,d,g)(v)}function d(v){return r++,n.push([t.currentConstruct,t.containerState]),p(v)}function g(v){if(v===null){i&&S(),b(0),e.consume(v);return}return i=i||t.parser.flow(t.now()),e.enter("chunkFlow",{_tokenizer:i,contentType:"flow",previous:s}),x(v)}function x(v){if(v===null){w(e.exit("chunkFlow"),!0),b(0),e.consume(v);return}return G(v)?(e.consume(v),w(e.exit("chunkFlow")),r=0,t.interrupt=void 0,a):(e.consume(v),x)}function w(v,R){const M=t.sliceStream(v);if(R&&M.push(null),v.previous=s,s&&(s.next=v),s=v,i.defineSkip(v.start),i.write(M),t.parser.lazy[v.start.line]){let C=i.events.length;for(;C--;)if(i.events[C][1].start.offset<o&&(!i.events[C][1].end||i.events[C][1].end.offset>o))return;const P=t.events.length;let U=P,F,E;for(;U--;)if(t.events[U][0]==="exit"&&t.events[U][1].type==="chunkFlow"){if(F){E=t.events[U][1].end;break}F=!0}for(b(r),C=P;C<t.events.length;)t.events[C][1].end={...E},C++;qe(t.events,U+1,0,t.events.slice(P)),t.events.length=C}}function b(v){let R=n.length;for(;R-- >v;){const M=n[R];t.containerState=M[1],M[0].exit.call(t,e)}n.length=v}function S(){i.write([null]),s=void 0,i=void 0,t.containerState._closeFlow=void 0}}function Ph(e,t,n){return oe(e,e.attempt(this.parser.constructs.document,t,n),"linePrefix",this.parser.constructs.disable.null.includes("codeIndented")?void 0:4)}function qt(e){if(e===null||fe(e)||Dt(e))return 1;if(Yn(e))return 2}function Gn(e,t,n){const r=[];let i=-1;for(;++i<e.length;){const s=e[i].resolveAll;s&&!r.includes(s)&&(t=s(t,n),r.push(s))}return t}const Fr={name:"attention",resolveAll:zh,tokenize:_h};function zh(e,t){let n=-1,r,i,s,o,a,l,u,c;for(;++n<e.length;)if(e[n][0]==="enter"&&e[n][1].type==="attentionSequence"&&e[n][1]._close){for(r=n;r--;)if(e[r][0]==="exit"&&e[r][1].type==="attentionSequence"&&e[r][1]._open&&t.sliceSerialize(e[r][1]).charCodeAt(0)===t.sliceSerialize(e[n][1]).charCodeAt(0)){if((e[r][1]._close||e[n][1]._open)&&(e[n][1].end.offset-e[n][1].start.offset)%3&&!((e[r][1].end.offset-e[r][1].start.offset+e[n][1].end.offset-e[n][1].start.offset)%3))continue;l=e[r][1].end.offset-e[r][1].start.offset>1&&e[n][1].end.offset-e[n][1].start.offset>1?2:1;const f={...e[r][1].end},p={...e[n][1].start};cs(f,-l),cs(p,l),o={type:l>1?"strongSequence":"emphasisSequence",start:f,end:{...e[r][1].end}},a={type:l>1?"strongSequence":"emphasisSequence",start:{...e[n][1].start},end:p},s={type:l>1?"strongText":"emphasisText",start:{...e[r][1].end},end:{...e[n][1].start}},i={type:l>1?"strong":"emphasis",start:{...o.start},end:{...a.end}},e[r][1].end={...o.start},e[n][1].start={...a.end},u=[],e[r][1].end.offset-e[r][1].start.offset&&(u=Ve(u,[["enter",e[r][1],t],["exit",e[r][1],t]])),u=Ve(u,[["enter",i,t],["enter",o,t],["exit",o,t],["enter",s,t]]),u=Ve(u,Gn(t.parser.constructs.insideSpan.null,e.slice(r+1,n),t)),u=Ve(u,[["exit",s,t],["enter",a,t],["exit",a,t],["exit",i,t]]),e[n][1].end.offset-e[n][1].start.offset?(c=2,u=Ve(u,[["enter",e[n][1],t],["exit",e[n][1],t]])):c=0,qe(e,r-1,n-r+3,u),n=r+u.length-c-2;break}}for(n=-1;++n<e.length;)e[n][1].type==="attentionSequence"&&(e[n][1].type="data");return e}function _h(e,t){const n=this.parser.constructs.attentionMarkers.null,r=this.previous,i=qt(r);let s;return o;function o(l){return s=l,e.enter("attentionSequence"),a(l)}function a(l){if(l===s)return e.consume(l),a;const u=e.exit("attentionSequence"),c=qt(l),f=!c||c===2&&i||n.includes(l),p=!i||i===2&&c||n.includes(r);return u._open=!!(s===42?f:f&&(i||!p)),u._close=!!(s===42?p:p&&(c||!f)),t(l)}}function cs(e,t){e.column+=t,e.offset+=t,e._bufferIndex+=t}const Oh={name:"autolink",tokenize:Fh};function Fh(e,t,n){let r=0;return i;function i(d){return e.enter("autolink"),e.enter("autolinkMarker"),e.consume(d),e.exit("autolinkMarker"),e.enter("autolinkProtocol"),s}function s(d){return Me(d)?(e.consume(d),o):d===64?n(d):u(d)}function o(d){return d===43||d===45||d===46||Re(d)?(r=1,a(d)):u(d)}function a(d){return d===58?(e.consume(d),r=0,l):(d===43||d===45||d===46||Re(d))&&r++<32?(e.consume(d),a):(r=0,u(d))}function l(d){return d===62?(e.exit("autolinkProtocol"),e.enter("autolinkMarker"),e.consume(d),e.exit("autolinkMarker"),e.exit("autolink"),t):d===null||d===32||d===60||zn(d)?n(d):(e.consume(d),l)}function u(d){return d===64?(e.consume(d),c):Ah(d)?(e.consume(d),u):n(d)}function c(d){return Re(d)?f(d):n(d)}function f(d){return d===46?(e.consume(d),r=0,c):d===62?(e.exit("autolinkProtocol").type="autolinkEmail",e.enter("autolinkMarker"),e.consume(d),e.exit("autolinkMarker"),e.exit("autolink"),t):p(d)}function p(d){if((d===45||Re(d))&&r++<63){const g=d===45?p:f;return e.consume(d),g}return n(d)}}const fn={partial:!0,tokenize:$h};function $h(e,t,n){return r;function r(s){return ie(s)?oe(e,i,"linePrefix")(s):i(s)}function i(s){return s===null||G(s)?t(s):n(s)}}const Go={continuation:{tokenize:Hh},exit:Uh,name:"blockQuote",tokenize:Bh};function Bh(e,t,n){const r=this;return i;function i(o){if(o===62){const a=r.containerState;return a.open||(e.enter("blockQuote",{_container:!0}),a.open=!0),e.enter("blockQuotePrefix"),e.enter("blockQuoteMarker"),e.consume(o),e.exit("blockQuoteMarker"),s}return n(o)}function s(o){return ie(o)?(e.enter("blockQuotePrefixWhitespace"),e.consume(o),e.exit("blockQuotePrefixWhitespace"),e.exit("blockQuotePrefix"),t):(e.exit("blockQuotePrefix"),t(o))}}function Hh(e,t,n){const r=this;return i;function i(o){return ie(o)?oe(e,s,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(o):s(o)}function s(o){return e.attempt(Go,t,n)(o)}}function Uh(e){e.exit("blockQuote")}const Qo={name:"characterEscape",tokenize:qh};function qh(e,t,n){return r;function r(s){return e.enter("characterEscape"),e.enter("escapeMarker"),e.consume(s),e.exit("escapeMarker"),i}function i(s){return Rh(s)?(e.enter("characterEscapeValue"),e.consume(s),e.exit("characterEscapeValue"),e.exit("characterEscape"),t):n(s)}}const Jo={name:"characterReference",tokenize:Wh};function Wh(e,t,n){const r=this;let i=0,s,o;return a;function a(f){return e.enter("characterReference"),e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),l}function l(f){return f===35?(e.enter("characterReferenceMarkerNumeric"),e.consume(f),e.exit("characterReferenceMarkerNumeric"),u):(e.enter("characterReferenceValue"),s=31,o=Re,c(f))}function u(f){return f===88||f===120?(e.enter("characterReferenceMarkerHexadecimal"),e.consume(f),e.exit("characterReferenceMarkerHexadecimal"),e.enter("characterReferenceValue"),s=6,o=Ih,c):(e.enter("characterReferenceValue"),s=7,o=Or,c(f))}function c(f){if(f===59&&i){const p=e.exit("characterReferenceValue");return o===Re&&!yi(r.sliceSerialize(p))?n(f):(e.enter("characterReferenceMarker"),e.consume(f),e.exit("characterReferenceMarker"),e.exit("characterReference"),t)}return o(f)&&i++<s?(e.consume(f),c):n(f)}}const fs={partial:!0,tokenize:Xh},hs={concrete:!0,name:"codeFenced",tokenize:Kh};function Kh(e,t,n){const r=this,i={partial:!0,tokenize:M};let s=0,o=0,a;return l;function l(C){return u(C)}function u(C){const P=r.events[r.events.length-1];return s=P&&P[1].type==="linePrefix"?P[2].sliceSerialize(P[1],!0).length:0,a=C,e.enter("codeFenced"),e.enter("codeFencedFence"),e.enter("codeFencedFenceSequence"),c(C)}function c(C){return C===a?(o++,e.consume(C),c):o<3?n(C):(e.exit("codeFencedFenceSequence"),ie(C)?oe(e,f,"whitespace")(C):f(C))}function f(C){return C===null||G(C)?(e.exit("codeFencedFence"),r.interrupt?t(C):e.check(fs,x,R)(C)):(e.enter("codeFencedFenceInfo"),e.enter("chunkString",{contentType:"string"}),p(C))}function p(C){return C===null||G(C)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),f(C)):ie(C)?(e.exit("chunkString"),e.exit("codeFencedFenceInfo"),oe(e,d,"whitespace")(C)):C===96&&C===a?n(C):(e.consume(C),p)}function d(C){return C===null||G(C)?f(C):(e.enter("codeFencedFenceMeta"),e.enter("chunkString",{contentType:"string"}),g(C))}function g(C){return C===null||G(C)?(e.exit("chunkString"),e.exit("codeFencedFenceMeta"),f(C)):C===96&&C===a?n(C):(e.consume(C),g)}function x(C){return e.attempt(i,R,w)(C)}function w(C){return e.enter("lineEnding"),e.consume(C),e.exit("lineEnding"),b}function b(C){return s>0&&ie(C)?oe(e,S,"linePrefix",s+1)(C):S(C)}function S(C){return C===null||G(C)?e.check(fs,x,R)(C):(e.enter("codeFlowValue"),v(C))}function v(C){return C===null||G(C)?(e.exit("codeFlowValue"),S(C)):(e.consume(C),v)}function R(C){return e.exit("codeFenced"),t(C)}function M(C,P,U){let F=0;return E;function E(T){return C.enter("lineEnding"),C.consume(T),C.exit("lineEnding"),N}function N(T){return C.enter("codeFencedFence"),ie(T)?oe(C,A,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(T):A(T)}function A(T){return T===a?(C.enter("codeFencedFenceSequence"),z(T)):U(T)}function z(T){return T===a?(F++,C.consume(T),z):F>=o?(C.exit("codeFencedFenceSequence"),ie(T)?oe(C,j,"whitespace")(T):j(T)):U(T)}function j(T){return T===null||G(T)?(C.exit("codeFencedFence"),P(T)):U(T)}}}function Xh(e,t,n){const r=this;return i;function i(o){return o===null?n(o):(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s)}function s(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}const fr={name:"codeIndented",tokenize:Yh},Vh={partial:!0,tokenize:Gh};function Yh(e,t,n){const r=this;return i;function i(u){return e.enter("codeIndented"),oe(e,s,"linePrefix",5)(u)}function s(u){const c=r.events[r.events.length-1];return c&&c[1].type==="linePrefix"&&c[2].sliceSerialize(c[1],!0).length>=4?o(u):n(u)}function o(u){return u===null?l(u):G(u)?e.attempt(Vh,o,l)(u):(e.enter("codeFlowValue"),a(u))}function a(u){return u===null||G(u)?(e.exit("codeFlowValue"),o(u)):(e.consume(u),a)}function l(u){return e.exit("codeIndented"),t(u)}}function Gh(e,t,n){const r=this;return i;function i(o){return r.parser.lazy[r.now().line]?n(o):G(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),i):oe(e,s,"linePrefix",5)(o)}function s(o){const a=r.events[r.events.length-1];return a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(o):G(o)?i(o):n(o)}}const Qh={name:"codeText",previous:Zh,resolve:Jh,tokenize:ep};function Jh(e){let t=e.length-4,n=3,r,i;if((e[n][1].type==="lineEnding"||e[n][1].type==="space")&&(e[t][1].type==="lineEnding"||e[t][1].type==="space")){for(r=n;++r<t;)if(e[r][1].type==="codeTextData"){e[n][1].type="codeTextPadding",e[t][1].type="codeTextPadding",n+=2,t-=2;break}}for(r=n-1,t++;++r<=t;)i===void 0?r!==t&&e[r][1].type!=="lineEnding"&&(i=r):(r===t||e[r][1].type==="lineEnding")&&(e[i][1].type="codeTextData",r!==i+2&&(e[i][1].end=e[r-1][1].end,e.splice(i+2,r-i-2),t-=r-i-2,r=i+2),i=void 0);return e}function Zh(e){return e!==96||this.events[this.events.length-1][1].type==="characterEscape"}function ep(e,t,n){let r=0,i,s;return o;function o(f){return e.enter("codeText"),e.enter("codeTextSequence"),a(f)}function a(f){return f===96?(e.consume(f),r++,a):(e.exit("codeTextSequence"),l(f))}function l(f){return f===null?n(f):f===32?(e.enter("space"),e.consume(f),e.exit("space"),l):f===96?(s=e.enter("codeTextSequence"),i=0,c(f)):G(f)?(e.enter("lineEnding"),e.consume(f),e.exit("lineEnding"),l):(e.enter("codeTextData"),u(f))}function u(f){return f===null||f===32||f===96||G(f)?(e.exit("codeTextData"),l(f)):(e.consume(f),u)}function c(f){return f===96?(e.consume(f),i++,c):i===r?(e.exit("codeTextSequence"),e.exit("codeText"),t(f)):(s.type="codeTextData",u(f))}}class tp{constructor(t){this.left=t?[...t]:[],this.right=[]}get(t){if(t<0||t>=this.left.length+this.right.length)throw new RangeError("Cannot access index `"+t+"` in a splice buffer of size `"+(this.left.length+this.right.length)+"`");return t<this.left.length?this.left[t]:this.right[this.right.length-t+this.left.length-1]}get length(){return this.left.length+this.right.length}shift(){return this.setCursor(0),this.right.pop()}slice(t,n){const r=n??Number.POSITIVE_INFINITY;return r<this.left.length?this.left.slice(t,r):t>this.left.length?this.right.slice(this.right.length-r+this.left.length,this.right.length-t+this.left.length).reverse():this.left.slice(t).concat(this.right.slice(this.right.length-r+this.left.length).reverse())}splice(t,n,r){const i=n||0;this.setCursor(Math.trunc(t));const s=this.right.splice(this.right.length-i,Number.POSITIVE_INFINITY);return r&&Zt(this.left,r),s.reverse()}pop(){return this.setCursor(Number.POSITIVE_INFINITY),this.left.pop()}push(t){this.setCursor(Number.POSITIVE_INFINITY),this.left.push(t)}pushMany(t){this.setCursor(Number.POSITIVE_INFINITY),Zt(this.left,t)}unshift(t){this.setCursor(0),this.right.push(t)}unshiftMany(t){this.setCursor(0),Zt(this.right,t.reverse())}setCursor(t){if(!(t===this.left.length||t>this.left.length&&this.right.length===0||t<0&&this.left.length===0))if(t<this.left.length){const n=this.left.splice(t,Number.POSITIVE_INFINITY);Zt(this.right,n.reverse())}else{const n=this.right.splice(this.left.length+this.right.length-t,Number.POSITIVE_INFINITY);Zt(this.left,n.reverse())}}}function Zt(e,t){let n=0;if(t.length<1e4)e.push(...t);else for(;n<t.length;)e.push(...t.slice(n,n+1e4)),n+=1e4}function Zo(e){const t={};let n=-1,r,i,s,o,a,l,u;const c=new tp(e);for(;++n<c.length;){for(;n in t;)n=t[n];if(r=c.get(n),n&&r[1].type==="chunkFlow"&&c.get(n-1)[1].type==="listItemPrefix"&&(l=r[1]._tokenizer.events,s=0,s<l.length&&l[s][1].type==="lineEndingBlank"&&(s+=2),s<l.length&&l[s][1].type==="content"))for(;++s<l.length&&l[s][1].type!=="content";)l[s][1].type==="chunkText"&&(l[s][1]._isInFirstContentOfListItem=!0,s++);if(r[0]==="enter")r[1].contentType&&(Object.assign(t,np(c,n)),n=t[n],u=!0);else if(r[1]._container){for(s=n,i=void 0;s--;)if(o=c.get(s),o[1].type==="lineEnding"||o[1].type==="lineEndingBlank")o[0]==="enter"&&(i&&(c.get(i)[1].type="lineEndingBlank"),o[1].type="lineEnding",i=s);else if(!(o[1].type==="linePrefix"||o[1].type==="listItemIndent"))break;i&&(r[1].end={...c.get(i)[1].start},a=c.slice(i,n),a.unshift(r),c.splice(i,n-i+1,a))}}return qe(e,0,Number.POSITIVE_INFINITY,c.slice(0)),!u}function np(e,t){const n=e.get(t)[1],r=e.get(t)[2];let i=t-1;const s=[];let o=n._tokenizer;o||(o=r.parser[n.contentType](n.start),n._contentTypeTextTrailing&&(o._contentTypeTextTrailing=!0));const a=o.events,l=[],u={};let c,f,p=-1,d=n,g=0,x=0;const w=[x];for(;d;){for(;e.get(++i)[1]!==d;);s.push(i),d._tokenizer||(c=r.sliceStream(d),d.next||c.push(null),f&&o.defineSkip(d.start),d._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=!0),o.write(c),d._isInFirstContentOfListItem&&(o._gfmTasklistFirstContentOfListItem=void 0)),f=d,d=d.next}for(d=n;++p<a.length;)a[p][0]==="exit"&&a[p-1][0]==="enter"&&a[p][1].type===a[p-1][1].type&&a[p][1].start.line!==a[p][1].end.line&&(x=p+1,w.push(x),d._tokenizer=void 0,d.previous=void 0,d=d.next);for(o.events=[],d?(d._tokenizer=void 0,d.previous=void 0):w.pop(),p=w.length;p--;){const b=a.slice(w[p],w[p+1]),S=s.pop();l.push([S,S+b.length-1]),e.splice(S,2,b)}for(l.reverse(),p=-1;++p<l.length;)u[g+l[p][0]]=g+l[p][1],g+=l[p][1]-l[p][0]-1;return u}const rp={resolve:sp,tokenize:op},ip={partial:!0,tokenize:ap};function sp(e){return Zo(e),e}function op(e,t){let n;return r;function r(a){return e.enter("content"),n=e.enter("chunkContent",{contentType:"content"}),i(a)}function i(a){return a===null?s(a):G(a)?e.check(ip,o,s)(a):(e.consume(a),i)}function s(a){return e.exit("chunkContent"),e.exit("content"),t(a)}function o(a){return e.consume(a),e.exit("chunkContent"),n.next=e.enter("chunkContent",{contentType:"content",previous:n}),n=n.next,i}}function ap(e,t,n){const r=this;return i;function i(o){return e.exit("chunkContent"),e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),oe(e,s,"linePrefix")}function s(o){if(o===null||G(o))return n(o);const a=r.events[r.events.length-1];return!r.parser.constructs.disable.null.includes("codeIndented")&&a&&a[1].type==="linePrefix"&&a[2].sliceSerialize(a[1],!0).length>=4?t(o):e.interrupt(r.parser.constructs.flow,n,t)(o)}}function ea(e,t,n,r,i,s,o,a,l){const u=l||Number.POSITIVE_INFINITY;let c=0;return f;function f(b){return b===60?(e.enter(r),e.enter(i),e.enter(s),e.consume(b),e.exit(s),p):b===null||b===32||b===41||zn(b)?n(b):(e.enter(r),e.enter(o),e.enter(a),e.enter("chunkString",{contentType:"string"}),x(b))}function p(b){return b===62?(e.enter(s),e.consume(b),e.exit(s),e.exit(i),e.exit(r),t):(e.enter(a),e.enter("chunkString",{contentType:"string"}),d(b))}function d(b){return b===62?(e.exit("chunkString"),e.exit(a),p(b)):b===null||b===60||G(b)?n(b):(e.consume(b),b===92?g:d)}function g(b){return b===60||b===62||b===92?(e.consume(b),d):d(b)}function x(b){return!c&&(b===null||b===41||fe(b))?(e.exit("chunkString"),e.exit(a),e.exit(o),e.exit(r),t(b)):c<u&&b===40?(e.consume(b),c++,x):b===41?(e.consume(b),c--,x):b===null||b===32||b===40||zn(b)?n(b):(e.consume(b),b===92?w:x)}function w(b){return b===40||b===41||b===92?(e.consume(b),x):x(b)}}function ta(e,t,n,r,i,s){const o=this;let a=0,l;return u;function u(d){return e.enter(r),e.enter(i),e.consume(d),e.exit(i),e.enter(s),c}function c(d){return a>999||d===null||d===91||d===93&&!l||d===94&&!a&&"_hiddenFootnoteSupport"in o.parser.constructs?n(d):d===93?(e.exit(s),e.enter(i),e.consume(d),e.exit(i),e.exit(r),t):G(d)?(e.enter("lineEnding"),e.consume(d),e.exit("lineEnding"),c):(e.enter("chunkString",{contentType:"string"}),f(d))}function f(d){return d===null||d===91||d===93||G(d)||a++>999?(e.exit("chunkString"),c(d)):(e.consume(d),l||(l=!ie(d)),d===92?p:f)}function p(d){return d===91||d===92||d===93?(e.consume(d),a++,f):f(d)}}function na(e,t,n,r,i,s){let o;return a;function a(p){return p===34||p===39||p===40?(e.enter(r),e.enter(i),e.consume(p),e.exit(i),o=p===40?41:p,l):n(p)}function l(p){return p===o?(e.enter(i),e.consume(p),e.exit(i),e.exit(r),t):(e.enter(s),u(p))}function u(p){return p===o?(e.exit(s),l(o)):p===null?n(p):G(p)?(e.enter("lineEnding"),e.consume(p),e.exit("lineEnding"),oe(e,u,"linePrefix")):(e.enter("chunkString",{contentType:"string"}),c(p))}function c(p){return p===o||p===null||G(p)?(e.exit("chunkString"),u(p)):(e.consume(p),p===92?f:c)}function f(p){return p===o||p===92?(e.consume(p),c):c(p)}}function on(e,t){let n;return r;function r(i){return G(i)?(e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),n=!0,r):ie(i)?oe(e,r,n?"linePrefix":"lineSuffix")(i):t(i)}}const lp={name:"definition",tokenize:cp},up={partial:!0,tokenize:fp};function cp(e,t,n){const r=this;let i;return s;function s(d){return e.enter("definition"),o(d)}function o(d){return ta.call(r,e,a,n,"definitionLabel","definitionLabelMarker","definitionLabelString")(d)}function a(d){return i=tt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)),d===58?(e.enter("definitionMarker"),e.consume(d),e.exit("definitionMarker"),l):n(d)}function l(d){return fe(d)?on(e,u)(d):u(d)}function u(d){return ea(e,c,n,"definitionDestination","definitionDestinationLiteral","definitionDestinationLiteralMarker","definitionDestinationRaw","definitionDestinationString")(d)}function c(d){return e.attempt(up,f,f)(d)}function f(d){return ie(d)?oe(e,p,"whitespace")(d):p(d)}function p(d){return d===null||G(d)?(e.exit("definition"),r.parser.defined.push(i),t(d)):n(d)}}function fp(e,t,n){return r;function r(a){return fe(a)?on(e,i)(a):n(a)}function i(a){return na(e,s,n,"definitionTitle","definitionTitleMarker","definitionTitleString")(a)}function s(a){return ie(a)?oe(e,o,"whitespace")(a):o(a)}function o(a){return a===null||G(a)?t(a):n(a)}}const hp={name:"hardBreakEscape",tokenize:pp};function pp(e,t,n){return r;function r(s){return e.enter("hardBreakEscape"),e.consume(s),i}function i(s){return G(s)?(e.exit("hardBreakEscape"),t(s)):n(s)}}const dp={name:"headingAtx",resolve:mp,tokenize:gp};function mp(e,t){let n=e.length-2,r=3,i,s;return e[r][1].type==="whitespace"&&(r+=2),n-2>r&&e[n][1].type==="whitespace"&&(n-=2),e[n][1].type==="atxHeadingSequence"&&(r===n-1||n-4>r&&e[n-2][1].type==="whitespace")&&(n-=r+1===n?2:4),n>r&&(i={type:"atxHeadingText",start:e[r][1].start,end:e[n][1].end},s={type:"chunkText",start:e[r][1].start,end:e[n][1].end,contentType:"text"},qe(e,r,n-r+1,[["enter",i,t],["enter",s,t],["exit",s,t],["exit",i,t]])),e}function gp(e,t,n){let r=0;return i;function i(c){return e.enter("atxHeading"),s(c)}function s(c){return e.enter("atxHeadingSequence"),o(c)}function o(c){return c===35&&r++<6?(e.consume(c),o):c===null||fe(c)?(e.exit("atxHeadingSequence"),a(c)):n(c)}function a(c){return c===35?(e.enter("atxHeadingSequence"),l(c)):c===null||G(c)?(e.exit("atxHeading"),t(c)):ie(c)?oe(e,a,"whitespace")(c):(e.enter("atxHeadingText"),u(c))}function l(c){return c===35?(e.consume(c),l):(e.exit("atxHeadingSequence"),a(c))}function u(c){return c===null||c===35||fe(c)?(e.exit("atxHeadingText"),a(c)):(e.consume(c),u)}}const xp=["address","article","aside","base","basefont","blockquote","body","caption","center","col","colgroup","dd","details","dialog","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frame","frameset","h1","h2","h3","h4","h5","h6","head","header","hr","html","iframe","legend","li","link","main","menu","menuitem","nav","noframes","ol","optgroup","option","p","param","search","section","summary","table","tbody","td","tfoot","th","thead","title","tr","track","ul"],ps=["pre","script","style","textarea"],yp={concrete:!0,name:"htmlFlow",resolveTo:wp,tokenize:Sp},bp={partial:!0,tokenize:vp},kp={partial:!0,tokenize:Cp};function wp(e){let t=e.length;for(;t--&&!(e[t][0]==="enter"&&e[t][1].type==="htmlFlow"););return t>1&&e[t-2][1].type==="linePrefix"&&(e[t][1].start=e[t-2][1].start,e[t+1][1].start=e[t-2][1].start,e.splice(t-2,2)),e}function Sp(e,t,n){const r=this;let i,s,o,a,l;return u;function u(k){return c(k)}function c(k){return e.enter("htmlFlow"),e.enter("htmlFlowData"),e.consume(k),f}function f(k){return k===33?(e.consume(k),p):k===47?(e.consume(k),s=!0,x):k===63?(e.consume(k),i=3,r.interrupt?t:y):Me(k)?(e.consume(k),o=String.fromCharCode(k),w):n(k)}function p(k){return k===45?(e.consume(k),i=2,d):k===91?(e.consume(k),i=5,a=0,g):Me(k)?(e.consume(k),i=4,r.interrupt?t:y):n(k)}function d(k){return k===45?(e.consume(k),r.interrupt?t:y):n(k)}function g(k){const Q="CDATA[";return k===Q.charCodeAt(a++)?(e.consume(k),a===Q.length?r.interrupt?t:A:g):n(k)}function x(k){return Me(k)?(e.consume(k),o=String.fromCharCode(k),w):n(k)}function w(k){if(k===null||k===47||k===62||fe(k)){const Q=k===47,re=o.toLowerCase();return!Q&&!s&&ps.includes(re)?(i=1,r.interrupt?t(k):A(k)):xp.includes(o.toLowerCase())?(i=6,Q?(e.consume(k),b):r.interrupt?t(k):A(k)):(i=7,r.interrupt&&!r.parser.lazy[r.now().line]?n(k):s?S(k):v(k))}return k===45||Re(k)?(e.consume(k),o+=String.fromCharCode(k),w):n(k)}function b(k){return k===62?(e.consume(k),r.interrupt?t:A):n(k)}function S(k){return ie(k)?(e.consume(k),S):E(k)}function v(k){return k===47?(e.consume(k),E):k===58||k===95||Me(k)?(e.consume(k),R):ie(k)?(e.consume(k),v):E(k)}function R(k){return k===45||k===46||k===58||k===95||Re(k)?(e.consume(k),R):M(k)}function M(k){return k===61?(e.consume(k),C):ie(k)?(e.consume(k),M):v(k)}function C(k){return k===null||k===60||k===61||k===62||k===96?n(k):k===34||k===39?(e.consume(k),l=k,P):ie(k)?(e.consume(k),C):U(k)}function P(k){return k===l?(e.consume(k),l=null,F):k===null||G(k)?n(k):(e.consume(k),P)}function U(k){return k===null||k===34||k===39||k===47||k===60||k===61||k===62||k===96||fe(k)?M(k):(e.consume(k),U)}function F(k){return k===47||k===62||ie(k)?v(k):n(k)}function E(k){return k===62?(e.consume(k),N):n(k)}function N(k){return k===null||G(k)?A(k):ie(k)?(e.consume(k),N):n(k)}function A(k){return k===45&&i===2?(e.consume(k),D):k===60&&i===1?(e.consume(k),L):k===62&&i===4?(e.consume(k),X):k===63&&i===3?(e.consume(k),y):k===93&&i===5?(e.consume(k),_):G(k)&&(i===6||i===7)?(e.exit("htmlFlowData"),e.check(bp,V,z)(k)):k===null||G(k)?(e.exit("htmlFlowData"),z(k)):(e.consume(k),A)}function z(k){return e.check(kp,j,V)(k)}function j(k){return e.enter("lineEnding"),e.consume(k),e.exit("lineEnding"),T}function T(k){return k===null||G(k)?z(k):(e.enter("htmlFlowData"),A(k))}function D(k){return k===45?(e.consume(k),y):A(k)}function L(k){return k===47?(e.consume(k),o="",H):A(k)}function H(k){if(k===62){const Q=o.toLowerCase();return ps.includes(Q)?(e.consume(k),X):A(k)}return Me(k)&&o.length<8?(e.consume(k),o+=String.fromCharCode(k),H):A(k)}function _(k){return k===93?(e.consume(k),y):A(k)}function y(k){return k===62?(e.consume(k),X):k===45&&i===2?(e.consume(k),y):A(k)}function X(k){return k===null||G(k)?(e.exit("htmlFlowData"),V(k)):(e.consume(k),X)}function V(k){return e.exit("htmlFlow"),t(k)}}function Cp(e,t,n){const r=this;return i;function i(o){return G(o)?(e.enter("lineEnding"),e.consume(o),e.exit("lineEnding"),s):n(o)}function s(o){return r.parser.lazy[r.now().line]?n(o):t(o)}}function vp(e,t,n){return r;function r(i){return e.enter("lineEnding"),e.consume(i),e.exit("lineEnding"),e.attempt(fn,t,n)}}const Ep={name:"htmlText",tokenize:Tp};function Tp(e,t,n){const r=this;let i,s,o;return a;function a(y){return e.enter("htmlText"),e.enter("htmlTextData"),e.consume(y),l}function l(y){return y===33?(e.consume(y),u):y===47?(e.consume(y),M):y===63?(e.consume(y),v):Me(y)?(e.consume(y),U):n(y)}function u(y){return y===45?(e.consume(y),c):y===91?(e.consume(y),s=0,g):Me(y)?(e.consume(y),S):n(y)}function c(y){return y===45?(e.consume(y),d):n(y)}function f(y){return y===null?n(y):y===45?(e.consume(y),p):G(y)?(o=f,L(y)):(e.consume(y),f)}function p(y){return y===45?(e.consume(y),d):f(y)}function d(y){return y===62?D(y):y===45?p(y):f(y)}function g(y){const X="CDATA[";return y===X.charCodeAt(s++)?(e.consume(y),s===X.length?x:g):n(y)}function x(y){return y===null?n(y):y===93?(e.consume(y),w):G(y)?(o=x,L(y)):(e.consume(y),x)}function w(y){return y===93?(e.consume(y),b):x(y)}function b(y){return y===62?D(y):y===93?(e.consume(y),b):x(y)}function S(y){return y===null||y===62?D(y):G(y)?(o=S,L(y)):(e.consume(y),S)}function v(y){return y===null?n(y):y===63?(e.consume(y),R):G(y)?(o=v,L(y)):(e.consume(y),v)}function R(y){return y===62?D(y):v(y)}function M(y){return Me(y)?(e.consume(y),C):n(y)}function C(y){return y===45||Re(y)?(e.consume(y),C):P(y)}function P(y){return G(y)?(o=P,L(y)):ie(y)?(e.consume(y),P):D(y)}function U(y){return y===45||Re(y)?(e.consume(y),U):y===47||y===62||fe(y)?F(y):n(y)}function F(y){return y===47?(e.consume(y),D):y===58||y===95||Me(y)?(e.consume(y),E):G(y)?(o=F,L(y)):ie(y)?(e.consume(y),F):D(y)}function E(y){return y===45||y===46||y===58||y===95||Re(y)?(e.consume(y),E):N(y)}function N(y){return y===61?(e.consume(y),A):G(y)?(o=N,L(y)):ie(y)?(e.consume(y),N):F(y)}function A(y){return y===null||y===60||y===61||y===62||y===96?n(y):y===34||y===39?(e.consume(y),i=y,z):G(y)?(o=A,L(y)):ie(y)?(e.consume(y),A):(e.consume(y),j)}function z(y){return y===i?(e.consume(y),i=void 0,T):y===null?n(y):G(y)?(o=z,L(y)):(e.consume(y),z)}function j(y){return y===null||y===34||y===39||y===60||y===61||y===96?n(y):y===47||y===62||fe(y)?F(y):(e.consume(y),j)}function T(y){return y===47||y===62||fe(y)?F(y):n(y)}function D(y){return y===62?(e.consume(y),e.exit("htmlTextData"),e.exit("htmlText"),t):n(y)}function L(y){return e.exit("htmlTextData"),e.enter("lineEnding"),e.consume(y),e.exit("lineEnding"),H}function H(y){return ie(y)?oe(e,_,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(y):_(y)}function _(y){return e.enter("htmlTextData"),o(y)}}const bi={name:"labelEnd",resolveAll:Rp,resolveTo:Np,tokenize:Lp},jp={tokenize:Mp},Ap={tokenize:Dp},Ip={tokenize:Pp};function Rp(e){let t=-1;const n=[];for(;++t<e.length;){const r=e[t][1];if(n.push(e[t]),r.type==="labelImage"||r.type==="labelLink"||r.type==="labelEnd"){const i=r.type==="labelImage"?4:2;r.type="data",t+=i}}return e.length!==n.length&&qe(e,0,e.length,n),e}function Np(e,t){let n=e.length,r=0,i,s,o,a;for(;n--;)if(i=e[n][1],s){if(i.type==="link"||i.type==="labelLink"&&i._inactive)break;e[n][0]==="enter"&&i.type==="labelLink"&&(i._inactive=!0)}else if(o){if(e[n][0]==="enter"&&(i.type==="labelImage"||i.type==="labelLink")&&!i._balanced&&(s=n,i.type!=="labelLink")){r=2;break}}else i.type==="labelEnd"&&(o=n);const l={type:e[s][1].type==="labelLink"?"link":"image",start:{...e[s][1].start},end:{...e[e.length-1][1].end}},u={type:"label",start:{...e[s][1].start},end:{...e[o][1].end}},c={type:"labelText",start:{...e[s+r+2][1].end},end:{...e[o-2][1].start}};return a=[["enter",l,t],["enter",u,t]],a=Ve(a,e.slice(s+1,s+r+3)),a=Ve(a,[["enter",c,t]]),a=Ve(a,Gn(t.parser.constructs.insideSpan.null,e.slice(s+r+4,o-3),t)),a=Ve(a,[["exit",c,t],e[o-2],e[o-1],["exit",u,t]]),a=Ve(a,e.slice(o+1)),a=Ve(a,[["exit",l,t]]),qe(e,s,e.length,a),e}function Lp(e,t,n){const r=this;let i=r.events.length,s,o;for(;i--;)if((r.events[i][1].type==="labelImage"||r.events[i][1].type==="labelLink")&&!r.events[i][1]._balanced){s=r.events[i][1];break}return a;function a(p){return s?s._inactive?f(p):(o=r.parser.defined.includes(tt(r.sliceSerialize({start:s.end,end:r.now()}))),e.enter("labelEnd"),e.enter("labelMarker"),e.consume(p),e.exit("labelMarker"),e.exit("labelEnd"),l):n(p)}function l(p){return p===40?e.attempt(jp,c,o?c:f)(p):p===91?e.attempt(Ap,c,o?u:f)(p):o?c(p):f(p)}function u(p){return e.attempt(Ip,c,f)(p)}function c(p){return t(p)}function f(p){return s._balanced=!0,n(p)}}function Mp(e,t,n){return r;function r(f){return e.enter("resource"),e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),i}function i(f){return fe(f)?on(e,s)(f):s(f)}function s(f){return f===41?c(f):ea(e,o,a,"resourceDestination","resourceDestinationLiteral","resourceDestinationLiteralMarker","resourceDestinationRaw","resourceDestinationString",32)(f)}function o(f){return fe(f)?on(e,l)(f):c(f)}function a(f){return n(f)}function l(f){return f===34||f===39||f===40?na(e,u,n,"resourceTitle","resourceTitleMarker","resourceTitleString")(f):c(f)}function u(f){return fe(f)?on(e,c)(f):c(f)}function c(f){return f===41?(e.enter("resourceMarker"),e.consume(f),e.exit("resourceMarker"),e.exit("resource"),t):n(f)}}function Dp(e,t,n){const r=this;return i;function i(a){return ta.call(r,e,s,o,"reference","referenceMarker","referenceString")(a)}function s(a){return r.parser.defined.includes(tt(r.sliceSerialize(r.events[r.events.length-1][1]).slice(1,-1)))?t(a):n(a)}function o(a){return n(a)}}function Pp(e,t,n){return r;function r(s){return e.enter("reference"),e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),i}function i(s){return s===93?(e.enter("referenceMarker"),e.consume(s),e.exit("referenceMarker"),e.exit("reference"),t):n(s)}}const zp={name:"labelStartImage",resolveAll:bi.resolveAll,tokenize:_p};function _p(e,t,n){const r=this;return i;function i(a){return e.enter("labelImage"),e.enter("labelImageMarker"),e.consume(a),e.exit("labelImageMarker"),s}function s(a){return a===91?(e.enter("labelMarker"),e.consume(a),e.exit("labelMarker"),e.exit("labelImage"),o):n(a)}function o(a){return a===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(a):t(a)}}const Op={name:"labelStartLink",resolveAll:bi.resolveAll,tokenize:Fp};function Fp(e,t,n){const r=this;return i;function i(o){return e.enter("labelLink"),e.enter("labelMarker"),e.consume(o),e.exit("labelMarker"),e.exit("labelLink"),s}function s(o){return o===94&&"_hiddenFootnoteSupport"in r.parser.constructs?n(o):t(o)}}const hr={name:"lineEnding",tokenize:$p};function $p(e,t){return n;function n(r){return e.enter("lineEnding"),e.consume(r),e.exit("lineEnding"),oe(e,t,"linePrefix")}}const Cn={name:"thematicBreak",tokenize:Bp};function Bp(e,t,n){let r=0,i;return s;function s(u){return e.enter("thematicBreak"),o(u)}function o(u){return i=u,a(u)}function a(u){return u===i?(e.enter("thematicBreakSequence"),l(u)):r>=3&&(u===null||G(u))?(e.exit("thematicBreak"),t(u)):n(u)}function l(u){return u===i?(e.consume(u),r++,l):(e.exit("thematicBreakSequence"),ie(u)?oe(e,a,"whitespace")(u):a(u))}}const _e={continuation:{tokenize:Wp},exit:Xp,name:"list",tokenize:qp},Hp={partial:!0,tokenize:Vp},Up={partial:!0,tokenize:Kp};function qp(e,t,n){const r=this,i=r.events[r.events.length-1];let s=i&&i[1].type==="linePrefix"?i[2].sliceSerialize(i[1],!0).length:0,o=0;return a;function a(d){const g=r.containerState.type||(d===42||d===43||d===45?"listUnordered":"listOrdered");if(g==="listUnordered"?!r.containerState.marker||d===r.containerState.marker:Or(d)){if(r.containerState.type||(r.containerState.type=g,e.enter(g,{_container:!0})),g==="listUnordered")return e.enter("listItemPrefix"),d===42||d===45?e.check(Cn,n,u)(d):u(d);if(!r.interrupt||d===49)return e.enter("listItemPrefix"),e.enter("listItemValue"),l(d)}return n(d)}function l(d){return Or(d)&&++o<10?(e.consume(d),l):(!r.interrupt||o<2)&&(r.containerState.marker?d===r.containerState.marker:d===41||d===46)?(e.exit("listItemValue"),u(d)):n(d)}function u(d){return e.enter("listItemMarker"),e.consume(d),e.exit("listItemMarker"),r.containerState.marker=r.containerState.marker||d,e.check(fn,r.interrupt?n:c,e.attempt(Hp,p,f))}function c(d){return r.containerState.initialBlankLine=!0,s++,p(d)}function f(d){return ie(d)?(e.enter("listItemPrefixWhitespace"),e.consume(d),e.exit("listItemPrefixWhitespace"),p):n(d)}function p(d){return r.containerState.size=s+r.sliceSerialize(e.exit("listItemPrefix"),!0).length,t(d)}}function Wp(e,t,n){const r=this;return r.containerState._closeFlow=void 0,e.check(fn,i,s);function i(a){return r.containerState.furtherBlankLines=r.containerState.furtherBlankLines||r.containerState.initialBlankLine,oe(e,t,"listItemIndent",r.containerState.size+1)(a)}function s(a){return r.containerState.furtherBlankLines||!ie(a)?(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,o(a)):(r.containerState.furtherBlankLines=void 0,r.containerState.initialBlankLine=void 0,e.attempt(Up,t,o)(a))}function o(a){return r.containerState._closeFlow=!0,r.interrupt=void 0,oe(e,e.attempt(_e,t,n),"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(a)}}function Kp(e,t,n){const r=this;return oe(e,i,"listItemIndent",r.containerState.size+1);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="listItemIndent"&&o[2].sliceSerialize(o[1],!0).length===r.containerState.size?t(s):n(s)}}function Xp(e){e.exit(this.containerState.type)}function Vp(e,t,n){const r=this;return oe(e,i,"listItemPrefixWhitespace",r.parser.constructs.disable.null.includes("codeIndented")?void 0:5);function i(s){const o=r.events[r.events.length-1];return!ie(s)&&o&&o[1].type==="listItemPrefixWhitespace"?t(s):n(s)}}const ds={name:"setextUnderline",resolveTo:Yp,tokenize:Gp};function Yp(e,t){let n=e.length,r,i,s;for(;n--;)if(e[n][0]==="enter"){if(e[n][1].type==="content"){r=n;break}e[n][1].type==="paragraph"&&(i=n)}else e[n][1].type==="content"&&e.splice(n,1),!s&&e[n][1].type==="definition"&&(s=n);const o={type:"setextHeading",start:{...e[r][1].start},end:{...e[e.length-1][1].end}};return e[i][1].type="setextHeadingText",s?(e.splice(i,0,["enter",o,t]),e.splice(s+1,0,["exit",e[r][1],t]),e[r][1].end={...e[s][1].end}):e[r][1]=o,e.push(["exit",o,t]),e}function Gp(e,t,n){const r=this;let i;return s;function s(u){let c=r.events.length,f;for(;c--;)if(r.events[c][1].type!=="lineEnding"&&r.events[c][1].type!=="linePrefix"&&r.events[c][1].type!=="content"){f=r.events[c][1].type==="paragraph";break}return!r.parser.lazy[r.now().line]&&(r.interrupt||f)?(e.enter("setextHeadingLine"),i=u,o(u)):n(u)}function o(u){return e.enter("setextHeadingLineSequence"),a(u)}function a(u){return u===i?(e.consume(u),a):(e.exit("setextHeadingLineSequence"),ie(u)?oe(e,l,"lineSuffix")(u):l(u))}function l(u){return u===null||G(u)?(e.exit("setextHeadingLine"),t(u)):n(u)}}const Qp={tokenize:Jp};function Jp(e){const t=this,n=e.attempt(fn,r,e.attempt(this.parser.constructs.flowInitial,i,oe(e,e.attempt(this.parser.constructs.flow,i,e.attempt(rp,i)),"linePrefix")));return n;function r(s){if(s===null){e.consume(s);return}return e.enter("lineEndingBlank"),e.consume(s),e.exit("lineEndingBlank"),t.currentConstruct=void 0,n}function i(s){if(s===null){e.consume(s);return}return e.enter("lineEnding"),e.consume(s),e.exit("lineEnding"),t.currentConstruct=void 0,n}}const Zp={resolveAll:ia()},ed=ra("string"),td=ra("text");function ra(e){return{resolveAll:ia(e==="text"?nd:void 0),tokenize:t};function t(n){const r=this,i=this.parser.constructs[e],s=n.attempt(i,o,a);return o;function o(c){return u(c)?s(c):a(c)}function a(c){if(c===null){n.consume(c);return}return n.enter("data"),n.consume(c),l}function l(c){return u(c)?(n.exit("data"),s(c)):(n.consume(c),l)}function u(c){if(c===null)return!0;const f=i[c];let p=-1;if(f)for(;++p<f.length;){const d=f[p];if(!d.previous||d.previous.call(r,r.previous))return!0}return!1}}}function ia(e){return t;function t(n,r){let i=-1,s;for(;++i<=n.length;)s===void 0?n[i]&&n[i][1].type==="data"&&(s=i,i++):(!n[i]||n[i][1].type!=="data")&&(i!==s+2&&(n[s][1].end=n[i-1][1].end,n.splice(s+2,i-s-2),i=s+2),s=void 0);return e?e(n,r):n}}function nd(e,t){let n=0;for(;++n<=e.length;)if((n===e.length||e[n][1].type==="lineEnding")&&e[n-1][1].type==="data"){const r=e[n-1][1],i=t.sliceStream(r);let s=i.length,o=-1,a=0,l;for(;s--;){const u=i[s];if(typeof u=="string"){for(o=u.length;u.charCodeAt(o-1)===32;)a++,o--;if(o)break;o=-1}else if(u===-2)l=!0,a++;else if(u!==-1){s++;break}}if(t._contentTypeTextTrailing&&n===e.length&&(a=0),a){const u={type:n===e.length||l||a<2?"lineSuffix":"hardBreakTrailing",start:{_bufferIndex:s?o:r.start._bufferIndex+o,_index:r.start._index+s,line:r.end.line,column:r.end.column-a,offset:r.end.offset-a},end:{...r.end}};r.end={...u.start},r.start.offset===r.end.offset?Object.assign(r,u):(e.splice(n,0,["enter",u,t],["exit",u,t]),n+=2)}n++}return e}const rd={42:_e,43:_e,45:_e,48:_e,49:_e,50:_e,51:_e,52:_e,53:_e,54:_e,55:_e,56:_e,57:_e,62:Go},id={91:lp},sd={[-2]:fr,[-1]:fr,32:fr},od={35:dp,42:Cn,45:[ds,Cn],60:yp,61:ds,95:Cn,96:hs,126:hs},ad={38:Jo,92:Qo},ld={[-5]:hr,[-4]:hr,[-3]:hr,33:zp,38:Jo,42:Fr,60:[Oh,Ep],91:Op,92:[hp,Qo],93:bi,95:Fr,96:Qh},ud={null:[Fr,Zp]},cd={null:[42,95]},fd={null:[]},hd=Object.freeze(Object.defineProperty({__proto__:null,attentionMarkers:cd,contentInitial:id,disable:fd,document:rd,flow:od,flowInitial:sd,insideSpan:ud,string:ad,text:ld},Symbol.toStringTag,{value:"Module"}));function pd(e,t,n){let r={_bufferIndex:-1,_index:0,line:n&&n.line||1,column:n&&n.column||1,offset:n&&n.offset||0};const i={},s=[];let o=[],a=[];const l={attempt:P(M),check:P(C),consume:S,enter:v,exit:R,interrupt:P(C,{interrupt:!0})},u={code:null,containerState:{},defineSkip:x,events:[],now:g,parser:e,previous:null,sliceSerialize:p,sliceStream:d,write:f};let c=t.tokenize.call(u,l);return t.resolveAll&&s.push(t),u;function f(N){return o=Ve(o,N),w(),o[o.length-1]!==null?[]:(U(t,0),u.events=Gn(s,u.events,u),u.events)}function p(N,A){return md(d(N),A)}function d(N){return dd(o,N)}function g(){const{_bufferIndex:N,_index:A,line:z,column:j,offset:T}=r;return{_bufferIndex:N,_index:A,line:z,column:j,offset:T}}function x(N){i[N.line]=N.column,E()}function w(){let N;for(;r._index<o.length;){const A=o[r._index];if(typeof A=="string")for(N=r._index,r._bufferIndex<0&&(r._bufferIndex=0);r._index===N&&r._bufferIndex<A.length;)b(A.charCodeAt(r._bufferIndex));else b(A)}}function b(N){c=c(N)}function S(N){G(N)?(r.line++,r.column=1,r.offset+=N===-3?2:1,E()):N!==-1&&(r.column++,r.offset++),r._bufferIndex<0?r._index++:(r._bufferIndex++,r._bufferIndex===o[r._index].length&&(r._bufferIndex=-1,r._index++)),u.previous=N}function v(N,A){const z=A||{};return z.type=N,z.start=g(),u.events.push(["enter",z,u]),a.push(z),z}function R(N){const A=a.pop();return A.end=g(),u.events.push(["exit",A,u]),A}function M(N,A){U(N,A.from)}function C(N,A){A.restore()}function P(N,A){return z;function z(j,T,D){let L,H,_,y;return Array.isArray(j)?V(j):"tokenize"in j?V([j]):X(j);function X(W){return he;function he(me){const ue=me!==null&&W[me],se=me!==null&&W.null,ge=[...Array.isArray(ue)?ue:ue?[ue]:[],...Array.isArray(se)?se:se?[se]:[]];return V(ge)(me)}}function V(W){return L=W,H=0,W.length===0?D:k(W[H])}function k(W){return he;function he(me){return y=F(),_=W,W.partial||(u.currentConstruct=W),W.name&&u.parser.constructs.disable.null.includes(W.name)?re():W.tokenize.call(A?Object.assign(Object.create(u),A):u,l,Q,re)(me)}}function Q(W){return N(_,y),T}function re(W){return y.restore(),++H<L.length?k(L[H]):D}}}function U(N,A){N.resolveAll&&!s.includes(N)&&s.push(N),N.resolve&&qe(u.events,A,u.events.length-A,N.resolve(u.events.slice(A),u)),N.resolveTo&&(u.events=N.resolveTo(u.events,u))}function F(){const N=g(),A=u.previous,z=u.currentConstruct,j=u.events.length,T=Array.from(a);return{from:j,restore:D};function D(){r=N,u.previous=A,u.currentConstruct=z,u.events.length=j,a=T,E()}}function E(){r.line in i&&r.column<2&&(r.column=i[r.line],r.offset+=i[r.line]-1)}}function dd(e,t){const n=t.start._index,r=t.start._bufferIndex,i=t.end._index,s=t.end._bufferIndex;let o;if(n===i)o=[e[n].slice(r,s)];else{if(o=e.slice(n,i),r>-1){const a=o[0];typeof a=="string"?o[0]=a.slice(r):o.shift()}s>0&&o.push(e[i].slice(0,s))}return o}function md(e,t){let n=-1;const r=[];let i;for(;++n<e.length;){const s=e[n];let o;if(typeof s=="string")o=s;else switch(s){case-5:{o="\r";break}case-4:{o=`
|
|
65
|
+
`;break}case-3:{o=`\r
|
|
66
|
+
`;break}case-2:{o=t?" ":" ";break}case-1:{if(!t&&i)continue;o=" ";break}default:o=String.fromCharCode(s)}i=s===-2,r.push(o)}return r.join("")}function gd(e){const r={constructs:Vo([hd,...(e||{}).extensions||[]]),content:i(Nh),defined:[],document:i(Mh),flow:i(Qp),lazy:{},string:i(ed),text:i(td)};return r;function i(s){return o;function o(a){return pd(r,s,a)}}}function xd(e){for(;!Zo(e););return e}const ms=/[\0\t\n\r]/g;function yd(){let e=1,t="",n=!0,r;return i;function i(s,o,a){const l=[];let u,c,f,p,d;for(s=t+(typeof s=="string"?s.toString():new TextDecoder(o||void 0).decode(s)),f=0,t="",n&&(s.charCodeAt(0)===65279&&f++,n=void 0);f<s.length;){if(ms.lastIndex=f,u=ms.exec(s),p=u&&u.index!==void 0?u.index:s.length,d=s.charCodeAt(p),!u){t=s.slice(f);break}if(d===10&&f===p&&r)l.push(-3),r=void 0;else switch(r&&(l.push(-5),r=void 0),f<p&&(l.push(s.slice(f,p)),e+=p-f),d){case 0:{l.push(65533),e++;break}case 9:{for(c=Math.ceil(e/4)*4,l.push(-2);e++<c;)l.push(-1);break}case 10:{l.push(-4),e=1;break}default:r=!0,e=1}f=p+1}return a&&(r&&l.push(-5),t&&l.push(t),l.push(null)),l}}const bd=/\\([!-/:-@[-`{-~])|&(#(?:\d{1,7}|x[\da-f]{1,6})|[\da-z]{1,31});/gi;function kd(e){return e.replace(bd,wd)}function wd(e,t,n){if(t)return t;if(n.charCodeAt(0)===35){const i=n.charCodeAt(1),s=i===120||i===88;return Yo(n.slice(s?2:1),s?16:10)}return yi(n)||e}const sa={}.hasOwnProperty;function Sd(e,t,n){return typeof t!="string"&&(n=t,t=void 0),Cd(n)(xd(gd(n).document().write(yd()(e,t,!0))))}function Cd(e){const t={transforms:[],canContainEols:["emphasis","fragment","heading","paragraph","strong"],enter:{autolink:s(xe),autolinkProtocol:F,autolinkEmail:F,atxHeading:s(Le),blockQuote:s(se),characterEscape:F,characterReference:F,codeFenced:s(ge),codeFencedFenceInfo:o,codeFencedFenceMeta:o,codeIndented:s(ge,o),codeText:s(ke,o),codeTextData:F,data:F,codeFlowValue:F,definition:s(we),definitionDestinationString:o,definitionLabelString:o,definitionTitleString:o,emphasis:s(Se),hardBreakEscape:s(K),hardBreakTrailing:s(K),htmlFlow:s($,o),htmlFlowData:F,htmlText:s($,o),htmlTextData:F,image:s(J),label:o,link:s(xe),listItem:s(pe),listItemValue:p,listOrdered:s(ne,f),listUnordered:s(ne),paragraph:s(Oe),reference:k,referenceString:o,resourceDestinationString:o,resourceTitleString:o,setextHeading:s(Le),strong:s(Fe),thematicBreak:s($e)},exit:{atxHeading:l(),atxHeadingSequence:M,autolink:l(),autolinkEmail:ue,autolinkProtocol:me,blockQuote:l(),characterEscapeValue:E,characterReferenceMarkerHexadecimal:re,characterReferenceMarkerNumeric:re,characterReferenceValue:W,characterReference:he,codeFenced:l(w),codeFencedFence:x,codeFencedFenceInfo:d,codeFencedFenceMeta:g,codeFlowValue:E,codeIndented:l(b),codeText:l(T),codeTextData:E,data:E,definition:l(),definitionDestinationString:R,definitionLabelString:S,definitionTitleString:v,emphasis:l(),hardBreakEscape:l(A),hardBreakTrailing:l(A),htmlFlow:l(z),htmlFlowData:E,htmlText:l(j),htmlTextData:E,image:l(L),label:_,labelText:H,lineEnding:N,link:l(D),listItem:l(),listOrdered:l(),listUnordered:l(),paragraph:l(),referenceString:Q,resourceDestinationString:y,resourceTitleString:X,resource:V,setextHeading:l(U),setextHeadingLineSequence:P,setextHeadingText:C,strong:l(),thematicBreak:l()}};oa(t,(e||{}).mdastExtensions||[]);const n={};return r;function r(I){let O={type:"root",children:[]};const Y={stack:[O],tokenStack:[],config:t,enter:a,exit:u,buffer:o,resume:c,data:n},te=[];let ae=-1;for(;++ae<I.length;)if(I[ae][1].type==="listOrdered"||I[ae][1].type==="listUnordered")if(I[ae][0]==="enter")te.push(ae);else{const Ee=te.pop();ae=i(I,Ee,ae)}for(ae=-1;++ae<I.length;){const Ee=t[I[ae][0]];sa.call(Ee,I[ae][1].type)&&Ee[I[ae][1].type].call(Object.assign({sliceSerialize:I[ae][2].sliceSerialize},Y),I[ae][1])}if(Y.tokenStack.length>0){const Ee=Y.tokenStack[Y.tokenStack.length-1];(Ee[1]||gs).call(Y,void 0,Ee[0])}for(O.position={start:pt(I.length>0?I[0][1].start:{line:1,column:1,offset:0}),end:pt(I.length>0?I[I.length-2][1].end:{line:1,column:1,offset:0})},ae=-1;++ae<t.transforms.length;)O=t.transforms[ae](O)||O;return O}function i(I,O,Y){let te=O-1,ae=-1,Ee=!1,We,Be,Ge,Ke;for(;++te<=Y;){const ve=I[te];switch(ve[1].type){case"listUnordered":case"listOrdered":case"blockQuote":{ve[0]==="enter"?ae++:ae--,Ke=void 0;break}case"lineEndingBlank":{ve[0]==="enter"&&(We&&!Ke&&!ae&&!Ge&&(Ge=te),Ke=void 0);break}case"linePrefix":case"listItemValue":case"listItemMarker":case"listItemPrefix":case"listItemPrefixWhitespace":break;default:Ke=void 0}if(!ae&&ve[0]==="enter"&&ve[1].type==="listItemPrefix"||ae===-1&&ve[0]==="exit"&&(ve[1].type==="listUnordered"||ve[1].type==="listOrdered")){if(We){let Te=te;for(Be=void 0;Te--;){const Pe=I[Te];if(Pe[1].type==="lineEnding"||Pe[1].type==="lineEndingBlank"){if(Pe[0]==="exit")continue;Be&&(I[Be][1].type="lineEndingBlank",Ee=!0),Pe[1].type="lineEnding",Be=Te}else if(!(Pe[1].type==="linePrefix"||Pe[1].type==="blockQuotePrefix"||Pe[1].type==="blockQuotePrefixWhitespace"||Pe[1].type==="blockQuoteMarker"||Pe[1].type==="listItemIndent"))break}Ge&&(!Be||Ge<Be)&&(We._spread=!0),We.end=Object.assign({},Be?I[Be][1].start:ve[1].end),I.splice(Be||te,0,["exit",We,ve[2]]),te++,Y++}if(ve[1].type==="listItemPrefix"){const Te={type:"listItem",_spread:!1,start:Object.assign({},ve[1].start),end:void 0};We=Te,I.splice(te,0,["enter",Te,ve[2]]),te++,Y++,Ge=void 0,Ke=!0}}}return I[O][1]._spread=Ee,Y}function s(I,O){return Y;function Y(te){a.call(this,I(te),te),O&&O.call(this,te)}}function o(){this.stack.push({type:"fragment",children:[]})}function a(I,O,Y){this.stack[this.stack.length-1].children.push(I),this.stack.push(I),this.tokenStack.push([O,Y||void 0]),I.position={start:pt(O.start),end:void 0}}function l(I){return O;function O(Y){I&&I.call(this,Y),u.call(this,Y)}}function u(I,O){const Y=this.stack.pop(),te=this.tokenStack.pop();if(te)te[0].type!==I.type&&(O?O.call(this,I,te[0]):(te[1]||gs).call(this,I,te[0]));else throw new Error("Cannot close `"+I.type+"` ("+sn({start:I.start,end:I.end})+"): it’s not open");Y.position.end=pt(I.end)}function c(){return xi(this.stack.pop())}function f(){this.data.expectingFirstListItemValue=!0}function p(I){if(this.data.expectingFirstListItemValue){const O=this.stack[this.stack.length-2];O.start=Number.parseInt(this.sliceSerialize(I),10),this.data.expectingFirstListItemValue=void 0}}function d(){const I=this.resume(),O=this.stack[this.stack.length-1];O.lang=I}function g(){const I=this.resume(),O=this.stack[this.stack.length-1];O.meta=I}function x(){this.data.flowCodeInside||(this.buffer(),this.data.flowCodeInside=!0)}function w(){const I=this.resume(),O=this.stack[this.stack.length-1];O.value=I.replace(/^(\r?\n|\r)|(\r?\n|\r)$/g,""),this.data.flowCodeInside=void 0}function b(){const I=this.resume(),O=this.stack[this.stack.length-1];O.value=I.replace(/(\r?\n|\r)$/g,"")}function S(I){const O=this.resume(),Y=this.stack[this.stack.length-1];Y.label=O,Y.identifier=tt(this.sliceSerialize(I)).toLowerCase()}function v(){const I=this.resume(),O=this.stack[this.stack.length-1];O.title=I}function R(){const I=this.resume(),O=this.stack[this.stack.length-1];O.url=I}function M(I){const O=this.stack[this.stack.length-1];if(!O.depth){const Y=this.sliceSerialize(I).length;O.depth=Y}}function C(){this.data.setextHeadingSlurpLineEnding=!0}function P(I){const O=this.stack[this.stack.length-1];O.depth=this.sliceSerialize(I).codePointAt(0)===61?1:2}function U(){this.data.setextHeadingSlurpLineEnding=void 0}function F(I){const Y=this.stack[this.stack.length-1].children;let te=Y[Y.length-1];(!te||te.type!=="text")&&(te=Ae(),te.position={start:pt(I.start),end:void 0},Y.push(te)),this.stack.push(te)}function E(I){const O=this.stack.pop();O.value+=this.sliceSerialize(I),O.position.end=pt(I.end)}function N(I){const O=this.stack[this.stack.length-1];if(this.data.atHardBreak){const Y=O.children[O.children.length-1];Y.position.end=pt(I.end),this.data.atHardBreak=void 0;return}!this.data.setextHeadingSlurpLineEnding&&t.canContainEols.includes(O.type)&&(F.call(this,I),E.call(this,I))}function A(){this.data.atHardBreak=!0}function z(){const I=this.resume(),O=this.stack[this.stack.length-1];O.value=I}function j(){const I=this.resume(),O=this.stack[this.stack.length-1];O.value=I}function T(){const I=this.resume(),O=this.stack[this.stack.length-1];O.value=I}function D(){const I=this.stack[this.stack.length-1];if(this.data.inReference){const O=this.data.referenceType||"shortcut";I.type+="Reference",I.referenceType=O,delete I.url,delete I.title}else delete I.identifier,delete I.label;this.data.referenceType=void 0}function L(){const I=this.stack[this.stack.length-1];if(this.data.inReference){const O=this.data.referenceType||"shortcut";I.type+="Reference",I.referenceType=O,delete I.url,delete I.title}else delete I.identifier,delete I.label;this.data.referenceType=void 0}function H(I){const O=this.sliceSerialize(I),Y=this.stack[this.stack.length-2];Y.label=kd(O),Y.identifier=tt(O).toLowerCase()}function _(){const I=this.stack[this.stack.length-1],O=this.resume(),Y=this.stack[this.stack.length-1];if(this.data.inReference=!0,Y.type==="link"){const te=I.children;Y.children=te}else Y.alt=O}function y(){const I=this.resume(),O=this.stack[this.stack.length-1];O.url=I}function X(){const I=this.resume(),O=this.stack[this.stack.length-1];O.title=I}function V(){this.data.inReference=void 0}function k(){this.data.referenceType="collapsed"}function Q(I){const O=this.resume(),Y=this.stack[this.stack.length-1];Y.label=O,Y.identifier=tt(this.sliceSerialize(I)).toLowerCase(),this.data.referenceType="full"}function re(I){this.data.characterReferenceType=I.type}function W(I){const O=this.sliceSerialize(I),Y=this.data.characterReferenceType;let te;Y?(te=Yo(O,Y==="characterReferenceMarkerNumeric"?10:16),this.data.characterReferenceType=void 0):te=yi(O);const ae=this.stack[this.stack.length-1];ae.value+=te}function he(I){const O=this.stack.pop();O.position.end=pt(I.end)}function me(I){E.call(this,I);const O=this.stack[this.stack.length-1];O.url=this.sliceSerialize(I)}function ue(I){E.call(this,I);const O=this.stack[this.stack.length-1];O.url="mailto:"+this.sliceSerialize(I)}function se(){return{type:"blockquote",children:[]}}function ge(){return{type:"code",lang:null,meta:null,value:""}}function ke(){return{type:"inlineCode",value:""}}function we(){return{type:"definition",identifier:"",label:null,title:null,url:""}}function Se(){return{type:"emphasis",children:[]}}function Le(){return{type:"heading",depth:0,children:[]}}function K(){return{type:"break"}}function $(){return{type:"html",value:""}}function J(){return{type:"image",title:null,url:"",alt:null}}function xe(){return{type:"link",title:null,url:"",children:[]}}function ne(I){return{type:"list",ordered:I.type==="listOrdered",start:null,spread:I._spread,children:[]}}function pe(I){return{type:"listItem",spread:I._spread,checked:null,children:[]}}function Oe(){return{type:"paragraph",children:[]}}function Fe(){return{type:"strong",children:[]}}function Ae(){return{type:"text",value:""}}function $e(){return{type:"thematicBreak"}}}function pt(e){return{line:e.line,column:e.column,offset:e.offset}}function oa(e,t){let n=-1;for(;++n<t.length;){const r=t[n];Array.isArray(r)?oa(e,r):vd(e,r)}}function vd(e,t){let n;for(n in t)if(sa.call(t,n))switch(n){case"canContainEols":{const r=t[n];r&&e[n].push(...r);break}case"transforms":{const r=t[n];r&&e[n].push(...r);break}case"enter":case"exit":{const r=t[n];r&&Object.assign(e[n],r);break}}}function gs(e,t){throw e?new Error("Cannot close `"+e.type+"` ("+sn({start:e.start,end:e.end})+"): a different token (`"+t.type+"`, "+sn({start:t.start,end:t.end})+") is open"):new Error("Cannot close document, a token (`"+t.type+"`, "+sn({start:t.start,end:t.end})+") is still open")}function Ed(e){const t=this;t.parser=n;function n(r){return Sd(r,{...t.data("settings"),...e,extensions:t.data("micromarkExtensions")||[],mdastExtensions:t.data("fromMarkdownExtensions")||[]})}}function Td(e,t){const n={type:"element",tagName:"blockquote",properties:{},children:e.wrap(e.all(t),!0)};return e.patch(t,n),e.applyData(t,n)}function jd(e,t){const n={type:"element",tagName:"br",properties:{},children:[]};return e.patch(t,n),[e.applyData(t,n),{type:"text",value:`
|
|
67
|
+
`}]}function Ad(e,t){const n=t.value?t.value+`
|
|
68
|
+
`:"",r={},i=t.lang?t.lang.split(/\s+/):[];i.length>0&&(r.className=["language-"+i[0]]);let s={type:"element",tagName:"code",properties:r,children:[{type:"text",value:n}]};return t.meta&&(s.data={meta:t.meta}),e.patch(t,s),s=e.applyData(t,s),s={type:"element",tagName:"pre",properties:{},children:[s]},e.patch(t,s),s}function Id(e,t){const n={type:"element",tagName:"del",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Rd(e,t){const n={type:"element",tagName:"em",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Nd(e,t){const n=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",r=String(t.identifier).toUpperCase(),i=Kt(r.toLowerCase()),s=e.footnoteOrder.indexOf(r);let o,a=e.footnoteCounts.get(r);a===void 0?(a=0,e.footnoteOrder.push(r),o=e.footnoteOrder.length):o=s+1,a+=1,e.footnoteCounts.set(r,a);const l={type:"element",tagName:"a",properties:{href:"#"+n+"fn-"+i,id:n+"fnref-"+i+(a>1?"-"+a:""),dataFootnoteRef:!0,ariaDescribedBy:["footnote-label"]},children:[{type:"text",value:String(o)}]};e.patch(t,l);const u={type:"element",tagName:"sup",properties:{},children:[l]};return e.patch(t,u),e.applyData(t,u)}function Ld(e,t){const n={type:"element",tagName:"h"+t.depth,properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Md(e,t){if(e.options.allowDangerousHtml){const n={type:"raw",value:t.value};return e.patch(t,n),e.applyData(t,n)}}function aa(e,t){const n=t.referenceType;let r="]";if(n==="collapsed"?r+="[]":n==="full"&&(r+="["+(t.label||t.identifier)+"]"),t.type==="imageReference")return[{type:"text",value:"!["+t.alt+r}];const i=e.all(t),s=i[0];s&&s.type==="text"?s.value="["+s.value:i.unshift({type:"text",value:"["});const o=i[i.length-1];return o&&o.type==="text"?o.value+=r:i.push({type:"text",value:r}),i}function Dd(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return aa(e,t);const i={src:Kt(r.url||""),alt:t.alt};r.title!==null&&r.title!==void 0&&(i.title=r.title);const s={type:"element",tagName:"img",properties:i,children:[]};return e.patch(t,s),e.applyData(t,s)}function Pd(e,t){const n={src:Kt(t.url)};t.alt!==null&&t.alt!==void 0&&(n.alt=t.alt),t.title!==null&&t.title!==void 0&&(n.title=t.title);const r={type:"element",tagName:"img",properties:n,children:[]};return e.patch(t,r),e.applyData(t,r)}function zd(e,t){const n={type:"text",value:t.value.replace(/\r?\n|\r/g," ")};e.patch(t,n);const r={type:"element",tagName:"code",properties:{},children:[n]};return e.patch(t,r),e.applyData(t,r)}function _d(e,t){const n=String(t.identifier).toUpperCase(),r=e.definitionById.get(n);if(!r)return aa(e,t);const i={href:Kt(r.url||"")};r.title!==null&&r.title!==void 0&&(i.title=r.title);const s={type:"element",tagName:"a",properties:i,children:e.all(t)};return e.patch(t,s),e.applyData(t,s)}function Od(e,t){const n={href:Kt(t.url)};t.title!==null&&t.title!==void 0&&(n.title=t.title);const r={type:"element",tagName:"a",properties:n,children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function Fd(e,t,n){const r=e.all(t),i=n?$d(n):la(t),s={},o=[];if(typeof t.checked=="boolean"){const c=r[0];let f;c&&c.type==="element"&&c.tagName==="p"?f=c:(f={type:"element",tagName:"p",properties:{},children:[]},r.unshift(f)),f.children.length>0&&f.children.unshift({type:"text",value:" "}),f.children.unshift({type:"element",tagName:"input",properties:{type:"checkbox",checked:t.checked,disabled:!0},children:[]}),s.className=["task-list-item"]}let a=-1;for(;++a<r.length;){const c=r[a];(i||a!==0||c.type!=="element"||c.tagName!=="p")&&o.push({type:"text",value:`
|
|
69
|
+
`}),c.type==="element"&&c.tagName==="p"&&!i?o.push(...c.children):o.push(c)}const l=r[r.length-1];l&&(i||l.type!=="element"||l.tagName!=="p")&&o.push({type:"text",value:`
|
|
70
|
+
`});const u={type:"element",tagName:"li",properties:s,children:o};return e.patch(t,u),e.applyData(t,u)}function $d(e){let t=!1;if(e.type==="list"){t=e.spread||!1;const n=e.children;let r=-1;for(;!t&&++r<n.length;)t=la(n[r])}return t}function la(e){const t=e.spread;return t??e.children.length>1}function Bd(e,t){const n={},r=e.all(t);let i=-1;for(typeof t.start=="number"&&t.start!==1&&(n.start=t.start);++i<r.length;){const o=r[i];if(o.type==="element"&&o.tagName==="li"&&o.properties&&Array.isArray(o.properties.className)&&o.properties.className.includes("task-list-item")){n.className=["contains-task-list"];break}}const s={type:"element",tagName:t.ordered?"ol":"ul",properties:n,children:e.wrap(r,!0)};return e.patch(t,s),e.applyData(t,s)}function Hd(e,t){const n={type:"element",tagName:"p",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Ud(e,t){const n={type:"root",children:e.wrap(e.all(t))};return e.patch(t,n),e.applyData(t,n)}function qd(e,t){const n={type:"element",tagName:"strong",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}function Wd(e,t){const n=e.all(t),r=n.shift(),i=[];if(r){const o={type:"element",tagName:"thead",properties:{},children:e.wrap([r],!0)};e.patch(t.children[0],o),i.push(o)}if(n.length>0){const o={type:"element",tagName:"tbody",properties:{},children:e.wrap(n,!0)},a=pi(t.children[1]),l=Bo(t.children[t.children.length-1]);a&&l&&(o.position={start:a,end:l}),i.push(o)}const s={type:"element",tagName:"table",properties:{},children:e.wrap(i,!0)};return e.patch(t,s),e.applyData(t,s)}function Kd(e,t,n){const r=n?n.children:void 0,s=(r?r.indexOf(t):1)===0?"th":"td",o=n&&n.type==="table"?n.align:void 0,a=o?o.length:t.children.length;let l=-1;const u=[];for(;++l<a;){const f=t.children[l],p={},d=o?o[l]:void 0;d&&(p.align=d);let g={type:"element",tagName:s,properties:p,children:[]};f&&(g.children=e.all(f),e.patch(f,g),g=e.applyData(f,g)),u.push(g)}const c={type:"element",tagName:"tr",properties:{},children:e.wrap(u,!0)};return e.patch(t,c),e.applyData(t,c)}function Xd(e,t){const n={type:"element",tagName:"td",properties:{},children:e.all(t)};return e.patch(t,n),e.applyData(t,n)}const xs=9,ys=32;function Vd(e){const t=String(e),n=/\r?\n|\r/g;let r=n.exec(t),i=0;const s=[];for(;r;)s.push(bs(t.slice(i,r.index),i>0,!0),r[0]),i=r.index+r[0].length,r=n.exec(t);return s.push(bs(t.slice(i),i>0,!1)),s.join("")}function bs(e,t,n){let r=0,i=e.length;if(t){let s=e.codePointAt(r);for(;s===xs||s===ys;)r++,s=e.codePointAt(r)}if(n){let s=e.codePointAt(i-1);for(;s===xs||s===ys;)i--,s=e.codePointAt(i-1)}return i>r?e.slice(r,i):""}function Yd(e,t){const n={type:"text",value:Vd(String(t.value))};return e.patch(t,n),e.applyData(t,n)}function Gd(e,t){const n={type:"element",tagName:"hr",properties:{},children:[]};return e.patch(t,n),e.applyData(t,n)}const Qd={blockquote:Td,break:jd,code:Ad,delete:Id,emphasis:Rd,footnoteReference:Nd,heading:Ld,html:Md,imageReference:Dd,image:Pd,inlineCode:zd,linkReference:_d,link:Od,listItem:Fd,list:Bd,paragraph:Hd,root:Ud,strong:qd,table:Wd,tableCell:Xd,tableRow:Kd,text:Yd,thematicBreak:Gd,toml:xn,yaml:xn,definition:xn,footnoteDefinition:xn};function xn(){}const ua=-1,Qn=0,an=1,_n=2,ki=3,wi=4,Si=5,Ci=6,ca=7,fa=8,ks=typeof self=="object"?self:globalThis,Jd=(e,t)=>{const n=(i,s)=>(e.set(s,i),i),r=i=>{if(e.has(i))return e.get(i);const[s,o]=t[i];switch(s){case Qn:case ua:return n(o,i);case an:{const a=n([],i);for(const l of o)a.push(r(l));return a}case _n:{const a=n({},i);for(const[l,u]of o)a[r(l)]=r(u);return a}case ki:return n(new Date(o),i);case wi:{const{source:a,flags:l}=o;return n(new RegExp(a,l),i)}case Si:{const a=n(new Map,i);for(const[l,u]of o)a.set(r(l),r(u));return a}case Ci:{const a=n(new Set,i);for(const l of o)a.add(r(l));return a}case ca:{const{name:a,message:l}=o;return n(new ks[a](l),i)}case fa:return n(BigInt(o),i);case"BigInt":return n(Object(BigInt(o)),i);case"ArrayBuffer":return n(new Uint8Array(o).buffer,o);case"DataView":{const{buffer:a}=new Uint8Array(o);return n(new DataView(a),o)}}return n(new ks[s](o),i)};return r},ws=e=>Jd(new Map,e)(0),$t="",{toString:Zd}={},{keys:em}=Object,en=e=>{const t=typeof e;if(t!=="object"||!e)return[Qn,t];const n=Zd.call(e).slice(8,-1);switch(n){case"Array":return[an,$t];case"Object":return[_n,$t];case"Date":return[ki,$t];case"RegExp":return[wi,$t];case"Map":return[Si,$t];case"Set":return[Ci,$t];case"DataView":return[an,n]}return n.includes("Array")?[an,n]:n.includes("Error")?[ca,n]:[_n,n]},yn=([e,t])=>e===Qn&&(t==="function"||t==="symbol"),tm=(e,t,n,r)=>{const i=(o,a)=>{const l=r.push(o)-1;return n.set(a,l),l},s=o=>{if(n.has(o))return n.get(o);let[a,l]=en(o);switch(a){case Qn:{let c=o;switch(l){case"bigint":a=fa,c=o.toString();break;case"function":case"symbol":if(e)throw new TypeError("unable to serialize "+l);c=null;break;case"undefined":return i([ua],o)}return i([a,c],o)}case an:{if(l){let p=o;return l==="DataView"?p=new Uint8Array(o.buffer):l==="ArrayBuffer"&&(p=new Uint8Array(o)),i([l,[...p]],o)}const c=[],f=i([a,c],o);for(const p of o)c.push(s(p));return f}case _n:{if(l)switch(l){case"BigInt":return i([l,o.toString()],o);case"Boolean":case"Number":case"String":return i([l,o.valueOf()],o)}if(t&&"toJSON"in o)return s(o.toJSON());const c=[],f=i([a,c],o);for(const p of em(o))(e||!yn(en(o[p])))&&c.push([s(p),s(o[p])]);return f}case ki:return i([a,o.toISOString()],o);case wi:{const{source:c,flags:f}=o;return i([a,{source:c,flags:f}],o)}case Si:{const c=[],f=i([a,c],o);for(const[p,d]of o)(e||!(yn(en(p))||yn(en(d))))&&c.push([s(p),s(d)]);return f}case Ci:{const c=[],f=i([a,c],o);for(const p of o)(e||!yn(en(p)))&&c.push(s(p));return f}}const{message:u}=o;return i([a,{name:l,message:u}],o)};return s},Ss=(e,{json:t,lossy:n}={})=>{const r=[];return tm(!(t||n),!!t,new Map,r)(e),r},On=typeof structuredClone=="function"?(e,t)=>t&&("json"in t||"lossy"in t)?ws(Ss(e,t)):structuredClone(e):(e,t)=>ws(Ss(e,t));function nm(e,t){const n=[{type:"text",value:"↩"}];return t>1&&n.push({type:"element",tagName:"sup",properties:{},children:[{type:"text",value:String(t)}]}),n}function rm(e,t){return"Back to reference "+(e+1)+(t>1?"-"+t:"")}function im(e){const t=typeof e.options.clobberPrefix=="string"?e.options.clobberPrefix:"user-content-",n=e.options.footnoteBackContent||nm,r=e.options.footnoteBackLabel||rm,i=e.options.footnoteLabel||"Footnotes",s=e.options.footnoteLabelTagName||"h2",o=e.options.footnoteLabelProperties||{className:["sr-only"]},a=[];let l=-1;for(;++l<e.footnoteOrder.length;){const u=e.footnoteById.get(e.footnoteOrder[l]);if(!u)continue;const c=e.all(u),f=String(u.identifier).toUpperCase(),p=Kt(f.toLowerCase());let d=0;const g=[],x=e.footnoteCounts.get(f);for(;x!==void 0&&++d<=x;){g.length>0&&g.push({type:"text",value:" "});let S=typeof n=="string"?n:n(l,d);typeof S=="string"&&(S={type:"text",value:S}),g.push({type:"element",tagName:"a",properties:{href:"#"+t+"fnref-"+p+(d>1?"-"+d:""),dataFootnoteBackref:"",ariaLabel:typeof r=="string"?r:r(l,d),className:["data-footnote-backref"]},children:Array.isArray(S)?S:[S]})}const w=c[c.length-1];if(w&&w.type==="element"&&w.tagName==="p"){const S=w.children[w.children.length-1];S&&S.type==="text"?S.value+=" ":w.children.push({type:"text",value:" "}),w.children.push(...g)}else c.push(...g);const b={type:"element",tagName:"li",properties:{id:t+"fn-"+p},children:e.wrap(c,!0)};e.patch(u,b),a.push(b)}if(a.length!==0)return{type:"element",tagName:"section",properties:{dataFootnotes:!0,className:["footnotes"]},children:[{type:"element",tagName:s,properties:{...On(o),id:"footnote-label"},children:[{type:"text",value:i}]},{type:"text",value:`
|
|
71
|
+
`},{type:"element",tagName:"ol",properties:{},children:e.wrap(a,!0)},{type:"text",value:`
|
|
72
|
+
`}]}}const Jn=(function(e){if(e==null)return lm;if(typeof e=="function")return Zn(e);if(typeof e=="object")return Array.isArray(e)?sm(e):om(e);if(typeof e=="string")return am(e);throw new Error("Expected function, string, or object as test")});function sm(e){const t=[];let n=-1;for(;++n<e.length;)t[n]=Jn(e[n]);return Zn(r);function r(...i){let s=-1;for(;++s<t.length;)if(t[s].apply(this,i))return!0;return!1}}function om(e){const t=e;return Zn(n);function n(r){const i=r;let s;for(s in e)if(i[s]!==t[s])return!1;return!0}}function am(e){return Zn(t);function t(n){return n&&n.type===e}}function Zn(e){return t;function t(n,r,i){return!!(um(n)&&e.call(this,n,typeof r=="number"?r:void 0,i||void 0))}}function lm(){return!0}function um(e){return e!==null&&typeof e=="object"&&"type"in e}const ha=[],cm=!0,$r=!1,fm="skip";function pa(e,t,n,r){let i;typeof t=="function"&&typeof n!="function"?(r=n,n=t):i=t;const s=Jn(i),o=r?-1:1;a(e,void 0,[])();function a(l,u,c){const f=l&&typeof l=="object"?l:{};if(typeof f.type=="string"){const d=typeof f.tagName=="string"?f.tagName:typeof f.name=="string"?f.name:void 0;Object.defineProperty(p,"name",{value:"node ("+(l.type+(d?"<"+d+">":""))+")"})}return p;function p(){let d=ha,g,x,w;if((!t||s(l,u,c[c.length-1]||void 0))&&(d=hm(n(l,c)),d[0]===$r))return d;if("children"in l&&l.children){const b=l;if(b.children&&d[0]!==fm)for(x=(r?b.children.length:-1)+o,w=c.concat(b);x>-1&&x<b.children.length;){const S=b.children[x];if(g=a(S,x,w)(),g[0]===$r)return g;x=typeof g[1]=="number"?g[1]:x+o}}return d}}}function hm(e){return Array.isArray(e)?e:typeof e=="number"?[cm,e]:e==null?ha:[e]}function vi(e,t,n,r){let i,s,o;typeof t=="function"&&typeof n!="function"?(s=void 0,o=t,i=n):(s=t,o=n,i=r),pa(e,s,a,i);function a(l,u){const c=u[u.length-1],f=c?c.children.indexOf(l):void 0;return o(l,f,c)}}const Br={}.hasOwnProperty,pm={};function dm(e,t){const n=t||pm,r=new Map,i=new Map,s=new Map,o={...Qd,...n.handlers},a={all:u,applyData:gm,definitionById:r,footnoteById:i,footnoteCounts:s,footnoteOrder:[],handlers:o,one:l,options:n,patch:mm,wrap:ym};return vi(e,function(c){if(c.type==="definition"||c.type==="footnoteDefinition"){const f=c.type==="definition"?r:i,p=String(c.identifier).toUpperCase();f.has(p)||f.set(p,c)}}),a;function l(c,f){const p=c.type,d=a.handlers[p];if(Br.call(a.handlers,p)&&d)return d(a,c,f);if(a.options.passThrough&&a.options.passThrough.includes(p)){if("children"in c){const{children:x,...w}=c,b=On(w);return b.children=a.all(c),b}return On(c)}return(a.options.unknownHandler||xm)(a,c,f)}function u(c){const f=[];if("children"in c){const p=c.children;let d=-1;for(;++d<p.length;){const g=a.one(p[d],c);if(g){if(d&&p[d-1].type==="break"&&(!Array.isArray(g)&&g.type==="text"&&(g.value=Cs(g.value)),!Array.isArray(g)&&g.type==="element")){const x=g.children[0];x&&x.type==="text"&&(x.value=Cs(x.value))}Array.isArray(g)?f.push(...g):f.push(g)}}}return f}}function mm(e,t){e.position&&(t.position=rh(e))}function gm(e,t){let n=t;if(e&&e.data){const r=e.data.hName,i=e.data.hChildren,s=e.data.hProperties;if(typeof r=="string")if(n.type==="element")n.tagName=r;else{const o="children"in n?n.children:[n];n={type:"element",tagName:r,properties:{},children:o}}n.type==="element"&&s&&Object.assign(n.properties,On(s)),"children"in n&&n.children&&i!==null&&i!==void 0&&(n.children=i)}return n}function xm(e,t){const n=t.data||{},r="value"in t&&!(Br.call(n,"hProperties")||Br.call(n,"hChildren"))?{type:"text",value:t.value}:{type:"element",tagName:"div",properties:{},children:e.all(t)};return e.patch(t,r),e.applyData(t,r)}function ym(e,t){const n=[];let r=-1;for(t&&n.push({type:"text",value:`
|
|
73
|
+
`});++r<e.length;)r&&n.push({type:"text",value:`
|
|
74
|
+
`}),n.push(e[r]);return t&&e.length>0&&n.push({type:"text",value:`
|
|
75
|
+
`}),n}function Cs(e){let t=0,n=e.charCodeAt(t);for(;n===9||n===32;)t++,n=e.charCodeAt(t);return e.slice(t)}function vs(e,t){const n=dm(e,t),r=n.one(e,void 0),i=im(n),s=Array.isArray(r)?{type:"root",children:r}:r||{type:"root",children:[]};return i&&s.children.push({type:"text",value:`
|
|
76
|
+
`},i),s}function bm(e,t){return e&&"run"in e?async function(n,r){const i=vs(n,{file:r,...t});await e.run(i,r)}:function(n,r){return vs(n,{file:r,...e||t})}}function Es(e){if(e)throw e}var pr,Ts;function km(){if(Ts)return pr;Ts=1;var e=Object.prototype.hasOwnProperty,t=Object.prototype.toString,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=function(u){return typeof Array.isArray=="function"?Array.isArray(u):t.call(u)==="[object Array]"},s=function(u){if(!u||t.call(u)!=="[object Object]")return!1;var c=e.call(u,"constructor"),f=u.constructor&&u.constructor.prototype&&e.call(u.constructor.prototype,"isPrototypeOf");if(u.constructor&&!c&&!f)return!1;var p;for(p in u);return typeof p>"u"||e.call(u,p)},o=function(u,c){n&&c.name==="__proto__"?n(u,c.name,{enumerable:!0,configurable:!0,value:c.newValue,writable:!0}):u[c.name]=c.newValue},a=function(u,c){if(c==="__proto__")if(e.call(u,c)){if(r)return r(u,c).value}else return;return u[c]};return pr=function l(){var u,c,f,p,d,g,x=arguments[0],w=1,b=arguments.length,S=!1;for(typeof x=="boolean"&&(S=x,x=arguments[1]||{},w=2),(x==null||typeof x!="object"&&typeof x!="function")&&(x={});w<b;++w)if(u=arguments[w],u!=null)for(c in u)f=a(x,c),p=a(u,c),x!==p&&(S&&p&&(s(p)||(d=i(p)))?(d?(d=!1,g=f&&i(f)?f:[]):g=f&&s(f)?f:{},o(x,{name:c,newValue:l(S,g,p)})):typeof p<"u"&&o(x,{name:c,newValue:p}));return x},pr}var wm=km();const dr=Gs(wm);function Hr(e){if(typeof e!="object"||e===null)return!1;const t=Object.getPrototypeOf(e);return(t===null||t===Object.prototype||Object.getPrototypeOf(t)===null)&&!(Symbol.toStringTag in e)&&!(Symbol.iterator in e)}function Sm(){const e=[],t={run:n,use:r};return t;function n(...i){let s=-1;const o=i.pop();if(typeof o!="function")throw new TypeError("Expected function as last argument, not "+o);a(null,...i);function a(l,...u){const c=e[++s];let f=-1;if(l){o(l);return}for(;++f<i.length;)(u[f]===null||u[f]===void 0)&&(u[f]=i[f]);i=u,c?Cm(c,a)(...u):o(null,...u)}}function r(i){if(typeof i!="function")throw new TypeError("Expected `middelware` to be a function, not "+i);return e.push(i),t}}function Cm(e,t){let n;return r;function r(...o){const a=e.length>o.length;let l;a&&o.push(i);try{l=e.apply(this,o)}catch(u){const c=u;if(a&&n)throw c;return i(c)}a||(l&&l.then&&typeof l.then=="function"?l.then(s,i):l instanceof Error?i(l):s(l))}function i(o,...a){n||(n=!0,t(o,...a))}function s(o){i(null,o)}}const rt={basename:vm,dirname:Em,extname:Tm,join:jm,sep:"/"};function vm(e,t){if(t!==void 0&&typeof t!="string")throw new TypeError('"ext" argument must be a string');hn(e);let n=0,r=-1,i=e.length,s;if(t===void 0||t.length===0||t.length>e.length){for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else r<0&&(s=!0,r=i+1);return r<0?"":e.slice(n,r)}if(t===e)return"";let o=-1,a=t.length-1;for(;i--;)if(e.codePointAt(i)===47){if(s){n=i+1;break}}else o<0&&(s=!0,o=i+1),a>-1&&(e.codePointAt(i)===t.codePointAt(a--)?a<0&&(r=i):(a=-1,r=o));return n===r?r=o:r<0&&(r=e.length),e.slice(n,r)}function Em(e){if(hn(e),e.length===0)return".";let t=-1,n=e.length,r;for(;--n;)if(e.codePointAt(n)===47){if(r){t=n;break}}else r||(r=!0);return t<0?e.codePointAt(0)===47?"/":".":t===1&&e.codePointAt(0)===47?"//":e.slice(0,t)}function Tm(e){hn(e);let t=e.length,n=-1,r=0,i=-1,s=0,o;for(;t--;){const a=e.codePointAt(t);if(a===47){if(o){r=t+1;break}continue}n<0&&(o=!0,n=t+1),a===46?i<0?i=t:s!==1&&(s=1):i>-1&&(s=-1)}return i<0||n<0||s===0||s===1&&i===n-1&&i===r+1?"":e.slice(i,n)}function jm(...e){let t=-1,n;for(;++t<e.length;)hn(e[t]),e[t]&&(n=n===void 0?e[t]:n+"/"+e[t]);return n===void 0?".":Am(n)}function Am(e){hn(e);const t=e.codePointAt(0)===47;let n=Im(e,!t);return n.length===0&&!t&&(n="."),n.length>0&&e.codePointAt(e.length-1)===47&&(n+="/"),t?"/"+n:n}function Im(e,t){let n="",r=0,i=-1,s=0,o=-1,a,l;for(;++o<=e.length;){if(o<e.length)a=e.codePointAt(o);else{if(a===47)break;a=47}if(a===47){if(!(i===o-1||s===1))if(i!==o-1&&s===2){if(n.length<2||r!==2||n.codePointAt(n.length-1)!==46||n.codePointAt(n.length-2)!==46){if(n.length>2){if(l=n.lastIndexOf("/"),l!==n.length-1){l<0?(n="",r=0):(n=n.slice(0,l),r=n.length-1-n.lastIndexOf("/")),i=o,s=0;continue}}else if(n.length>0){n="",r=0,i=o,s=0;continue}}t&&(n=n.length>0?n+"/..":"..",r=2)}else n.length>0?n+="/"+e.slice(i+1,o):n=e.slice(i+1,o),r=o-i-1;i=o,s=0}else a===46&&s>-1?s++:s=-1}return n}function hn(e){if(typeof e!="string")throw new TypeError("Path must be a string. Received "+JSON.stringify(e))}const Rm={cwd:Nm};function Nm(){return"/"}function Ur(e){return!!(e!==null&&typeof e=="object"&&"href"in e&&e.href&&"protocol"in e&&e.protocol&&e.auth===void 0)}function Lm(e){if(typeof e=="string")e=new URL(e);else if(!Ur(e)){const t=new TypeError('The "path" argument must be of type string or an instance of URL. Received `'+e+"`");throw t.code="ERR_INVALID_ARG_TYPE",t}if(e.protocol!=="file:"){const t=new TypeError("The URL must be of scheme file");throw t.code="ERR_INVALID_URL_SCHEME",t}return Mm(e)}function Mm(e){if(e.hostname!==""){const r=new TypeError('File URL host must be "localhost" or empty on darwin');throw r.code="ERR_INVALID_FILE_URL_HOST",r}const t=e.pathname;let n=-1;for(;++n<t.length;)if(t.codePointAt(n)===37&&t.codePointAt(n+1)===50){const r=t.codePointAt(n+2);if(r===70||r===102){const i=new TypeError("File URL path must not include encoded / characters");throw i.code="ERR_INVALID_FILE_URL_PATH",i}}return decodeURIComponent(t)}const mr=["history","path","basename","stem","extname","dirname"];class da{constructor(t){let n;t?Ur(t)?n={path:t}:typeof t=="string"||Dm(t)?n={value:t}:n=t:n={},this.cwd="cwd"in n?"":Rm.cwd(),this.data={},this.history=[],this.messages=[],this.value,this.map,this.result,this.stored;let r=-1;for(;++r<mr.length;){const s=mr[r];s in n&&n[s]!==void 0&&n[s]!==null&&(this[s]=s==="history"?[...n[s]]:n[s])}let i;for(i in n)mr.includes(i)||(this[i]=n[i])}get basename(){return typeof this.path=="string"?rt.basename(this.path):void 0}set basename(t){xr(t,"basename"),gr(t,"basename"),this.path=rt.join(this.dirname||"",t)}get dirname(){return typeof this.path=="string"?rt.dirname(this.path):void 0}set dirname(t){js(this.basename,"dirname"),this.path=rt.join(t||"",this.basename)}get extname(){return typeof this.path=="string"?rt.extname(this.path):void 0}set extname(t){if(gr(t,"extname"),js(this.dirname,"extname"),t){if(t.codePointAt(0)!==46)throw new Error("`extname` must start with `.`");if(t.includes(".",1))throw new Error("`extname` cannot contain multiple dots")}this.path=rt.join(this.dirname,this.stem+(t||""))}get path(){return this.history[this.history.length-1]}set path(t){Ur(t)&&(t=Lm(t)),xr(t,"path"),this.path!==t&&this.history.push(t)}get stem(){return typeof this.path=="string"?rt.basename(this.path,this.extname):void 0}set stem(t){xr(t,"stem"),gr(t,"stem"),this.path=rt.join(this.dirname||"",t+(this.extname||""))}fail(t,n,r){const i=this.message(t,n,r);throw i.fatal=!0,i}info(t,n,r){const i=this.message(t,n,r);return i.fatal=void 0,i}message(t,n,r){const i=new Ne(t,n,r);return this.path&&(i.name=this.path+":"+i.name,i.file=this.path),i.fatal=!1,this.messages.push(i),i}toString(t){return this.value===void 0?"":typeof this.value=="string"?this.value:new TextDecoder(t||void 0).decode(this.value)}}function gr(e,t){if(e&&e.includes(rt.sep))throw new Error("`"+t+"` cannot be a path: did not expect `"+rt.sep+"`")}function xr(e,t){if(!e)throw new Error("`"+t+"` cannot be empty")}function js(e,t){if(!e)throw new Error("Setting `"+t+"` requires `path` to be set too")}function Dm(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Pm=(function(e){const r=this.constructor.prototype,i=r[e],s=function(){return i.apply(s,arguments)};return Object.setPrototypeOf(s,r),s}),zm={}.hasOwnProperty;class Ei extends Pm{constructor(){super("copy"),this.Compiler=void 0,this.Parser=void 0,this.attachers=[],this.compiler=void 0,this.freezeIndex=-1,this.frozen=void 0,this.namespace={},this.parser=void 0,this.transformers=Sm()}copy(){const t=new Ei;let n=-1;for(;++n<this.attachers.length;){const r=this.attachers[n];t.use(...r)}return t.data(dr(!0,{},this.namespace)),t}data(t,n){return typeof t=="string"?arguments.length===2?(kr("data",this.frozen),this.namespace[t]=n,this):zm.call(this.namespace,t)&&this.namespace[t]||void 0:t?(kr("data",this.frozen),this.namespace=t,this):this.namespace}freeze(){if(this.frozen)return this;const t=this;for(;++this.freezeIndex<this.attachers.length;){const[n,...r]=this.attachers[this.freezeIndex];if(r[0]===!1)continue;r[0]===!0&&(r[0]=void 0);const i=n.call(t,...r);typeof i=="function"&&this.transformers.use(i)}return this.frozen=!0,this.freezeIndex=Number.POSITIVE_INFINITY,this}parse(t){this.freeze();const n=bn(t),r=this.parser||this.Parser;return yr("parse",r),r(String(n),n)}process(t,n){const r=this;return this.freeze(),yr("process",this.parser||this.Parser),br("process",this.compiler||this.Compiler),n?i(void 0,n):new Promise(i);function i(s,o){const a=bn(t),l=r.parse(a);r.run(l,a,function(c,f,p){if(c||!f||!p)return u(c);const d=f,g=r.stringify(d,p);Fm(g)?p.value=g:p.result=g,u(c,p)});function u(c,f){c||!f?o(c):s?s(f):n(void 0,f)}}}processSync(t){let n=!1,r;return this.freeze(),yr("processSync",this.parser||this.Parser),br("processSync",this.compiler||this.Compiler),this.process(t,i),Is("processSync","process",n),r;function i(s,o){n=!0,Es(s),r=o}}run(t,n,r){As(t),this.freeze();const i=this.transformers;return!r&&typeof n=="function"&&(r=n,n=void 0),r?s(void 0,r):new Promise(s);function s(o,a){const l=bn(n);i.run(t,l,u);function u(c,f,p){const d=f||t;c?a(c):o?o(d):r(void 0,d,p)}}}runSync(t,n){let r=!1,i;return this.run(t,n,s),Is("runSync","run",r),i;function s(o,a){Es(o),i=a,r=!0}}stringify(t,n){this.freeze();const r=bn(n),i=this.compiler||this.Compiler;return br("stringify",i),As(t),i(t,r)}use(t,...n){const r=this.attachers,i=this.namespace;if(kr("use",this.frozen),t!=null)if(typeof t=="function")l(t,n);else if(typeof t=="object")Array.isArray(t)?a(t):o(t);else throw new TypeError("Expected usable value, not `"+t+"`");return this;function s(u){if(typeof u=="function")l(u,[]);else if(typeof u=="object")if(Array.isArray(u)){const[c,...f]=u;l(c,f)}else o(u);else throw new TypeError("Expected usable value, not `"+u+"`")}function o(u){if(!("plugins"in u)&&!("settings"in u))throw new Error("Expected usable value but received an empty preset, which is probably a mistake: presets typically come with `plugins` and sometimes with `settings`, but this has neither");a(u.plugins),u.settings&&(i.settings=dr(!0,i.settings,u.settings))}function a(u){let c=-1;if(u!=null)if(Array.isArray(u))for(;++c<u.length;){const f=u[c];s(f)}else throw new TypeError("Expected a list of plugins, not `"+u+"`")}function l(u,c){let f=-1,p=-1;for(;++f<r.length;)if(r[f][0]===u){p=f;break}if(p===-1)r.push([u,...c]);else if(c.length>0){let[d,...g]=c;const x=r[p][1];Hr(x)&&Hr(d)&&(d=dr(!0,x,d)),r[p]=[u,d,...g]}}}}const _m=new Ei().freeze();function yr(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `parser`")}function br(e,t){if(typeof t!="function")throw new TypeError("Cannot `"+e+"` without `compiler`")}function kr(e,t){if(t)throw new Error("Cannot call `"+e+"` on a frozen processor.\nCreate a new processor first, by calling it: use `processor()` instead of `processor`.")}function As(e){if(!Hr(e)||typeof e.type!="string")throw new TypeError("Expected node, got `"+e+"`")}function Is(e,t,n){if(!n)throw new Error("`"+e+"` finished async. Use `"+t+"` instead")}function bn(e){return Om(e)?e:new da(e)}function Om(e){return!!(e&&typeof e=="object"&&"message"in e&&"messages"in e)}function Fm(e){return typeof e=="string"||$m(e)}function $m(e){return!!(e&&typeof e=="object"&&"byteLength"in e&&"byteOffset"in e)}const Bm="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",Rs=[],Ns={allowDangerousHtml:!0},Hm=/^(https?|ircs?|mailto|xmpp)$/i,Um=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"className",id:"remove-classname"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function qm(e){const t=Wm(e),n=Km(e);return Xm(t.runSync(t.parse(n),n),e)}function Wm(e){const t=e.rehypePlugins||Rs,n=e.remarkPlugins||Rs,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...Ns}:Ns;return _m().use(Ed).use(n).use(bm,r).use(t)}function Km(e){const t=e.children||"",n=new da;return typeof t=="string"&&(n.value=t),n}function Xm(e,t){const n=t.allowedElements,r=t.allowElement,i=t.components,s=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,l=t.urlTransform||Vm;for(const c of Um)Object.hasOwn(t,c.from)&&(""+c.from+(c.to?"use `"+c.to+"` instead":"remove it")+Bm+c.id,void 0);return vi(e,u),lh(e,{Fragment:h.Fragment,components:i,ignoreInvalidStyle:!0,jsx:h.jsx,jsxs:h.jsxs,passKeys:!0,passNode:!0});function u(c,f,p){if(c.type==="raw"&&p&&typeof f=="number")return o?p.children.splice(f,1):p.children[f]={type:"text",value:c.value},f;if(c.type==="element"){let d;for(d in cr)if(Object.hasOwn(cr,d)&&Object.hasOwn(c.properties,d)){const g=c.properties[d],x=cr[d];(x===null||x.includes(c.tagName))&&(c.properties[d]=l(String(g||""),d,c))}}if(c.type==="element"){let d=n?!n.includes(c.tagName):s?s.includes(c.tagName):!1;if(!d&&r&&typeof f=="number"&&(d=!r(c,f,p)),d&&p&&typeof f=="number")return a&&c.children?p.children.splice(f,1,...c.children):p.children.splice(f,1),f}}}function Vm(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),i=e.indexOf("/");return t===-1||i!==-1&&t>i||n!==-1&&t>n||r!==-1&&t>r||Hm.test(e.slice(0,t))?e:""}function Ym(e){if(typeof e!="string")throw new TypeError("Expected a string");return e.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&").replace(/-/g,"\\x2d")}function ma(e,t,n){const i=Jn((n||{}).ignore||[]),s=Gm(t);let o=-1;for(;++o<s.length;)pa(e,"text",a);function a(u,c){let f=-1,p;for(;++f<c.length;){const d=c[f],g=p?p.children:void 0;if(i(d,g?g.indexOf(d):void 0,p))return;p=d}if(p)return l(u,c)}function l(u,c){const f=c[c.length-1],p=s[o][0],d=s[o][1];let g=0;const w=f.children.indexOf(u);let b=!1,S=[];p.lastIndex=0;let v=p.exec(u.value);for(;v;){const R=v.index,M={index:v.index,input:v.input,stack:[...c,u]};let C=d(...v,M);if(typeof C=="string"&&(C=C.length>0?{type:"text",value:C}:void 0),C===!1?p.lastIndex=R+1:(g!==R&&S.push({type:"text",value:u.value.slice(g,R)}),Array.isArray(C)?S.push(...C):C&&S.push(C),g=R+v[0].length,b=!0),!p.global)break;v=p.exec(u.value)}return b?(g<u.value.length&&S.push({type:"text",value:u.value.slice(g)}),f.children.splice(w,1,...S)):S=[u],w+S.length}}function Gm(e){const t=[];if(!Array.isArray(e))throw new TypeError("Expected find and replace tuple or list of tuples");const n=!e[0]||Array.isArray(e[0])?e:[e];let r=-1;for(;++r<n.length;){const i=n[r];t.push([Qm(i[0]),Jm(i[1])])}return t}function Qm(e){return typeof e=="string"?new RegExp(Ym(e),"g"):e}function Jm(e){return typeof e=="function"?e:function(){return e}}function Zm(e){ma(e,[/\r?\n|\r/g,eg])}function eg(){return{type:"break"}}function tg(){return function(e){Zm(e)}}const wr="phrasing",Sr=["autolink","link","image","label"];function ng(){return{transforms:[ug],enter:{literalAutolink:ig,literalAutolinkEmail:Cr,literalAutolinkHttp:Cr,literalAutolinkWww:Cr},exit:{literalAutolink:lg,literalAutolinkEmail:ag,literalAutolinkHttp:sg,literalAutolinkWww:og}}}function rg(){return{unsafe:[{character:"@",before:"[+\\-.\\w]",after:"[\\-.\\w]",inConstruct:wr,notInConstruct:Sr},{character:".",before:"[Ww]",after:"[\\-.\\w]",inConstruct:wr,notInConstruct:Sr},{character:":",before:"[ps]",after:"\\/",inConstruct:wr,notInConstruct:Sr}]}}function ig(e){this.enter({type:"link",title:null,url:"",children:[]},e)}function Cr(e){this.config.enter.autolinkProtocol.call(this,e)}function sg(e){this.config.exit.autolinkProtocol.call(this,e)}function og(e){this.config.exit.data.call(this,e);const t=this.stack[this.stack.length-1];t.type,t.url="http://"+this.sliceSerialize(e)}function ag(e){this.config.exit.autolinkEmail.call(this,e)}function lg(e){this.exit(e)}function ug(e){ma(e,[[/(https?:\/\/|www(?=\.))([-.\w]+)([^ \t\r\n]*)/gi,cg],[new RegExp("(?<=^|\\s|\\p{P}|\\p{S})([-.\\w+]+)@([-\\w]+(?:\\.[-\\w]+)+)","gu"),fg]],{ignore:["link","linkReference"]})}function cg(e,t,n,r,i){let s="";if(!ga(i)||(/^w/i.test(t)&&(n=t+n,t="",s="http://"),!hg(n)))return!1;const o=pg(n+r);if(!o[0])return!1;const a={type:"link",title:null,url:s+t+o[0],children:[{type:"text",value:t+o[0]}]};return o[1]?[a,{type:"text",value:o[1]}]:a}function fg(e,t,n,r){return!ga(r,!0)||/[-\d_]$/.test(n)?!1:{type:"link",title:null,url:"mailto:"+t+"@"+n,children:[{type:"text",value:t+"@"+n}]}}function hg(e){const t=e.split(".");return!(t.length<2||t[t.length-1]&&(/_/.test(t[t.length-1])||!/[a-zA-Z\d]/.test(t[t.length-1]))||t[t.length-2]&&(/_/.test(t[t.length-2])||!/[a-zA-Z\d]/.test(t[t.length-2])))}function pg(e){const t=/[!"&'),.:;<>?\]}]+$/.exec(e);if(!t)return[e,void 0];e=e.slice(0,t.index);let n=t[0],r=n.indexOf(")");const i=Oi(e,"(");let s=Oi(e,")");for(;r!==-1&&i>s;)e+=n.slice(0,r+1),n=n.slice(r+1),r=n.indexOf(")"),s++;return[e,n]}function ga(e,t){const n=e.input.charCodeAt(e.index-1);return(e.index===0||Dt(n)||Yn(n))&&(!t||n!==47)}xa.peek=Sg;function dg(){this.buffer()}function mg(e){this.enter({type:"footnoteReference",identifier:"",label:""},e)}function gg(){this.buffer()}function xg(e){this.enter({type:"footnoteDefinition",identifier:"",label:"",children:[]},e)}function yg(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=tt(this.sliceSerialize(e)).toLowerCase(),n.label=t}function bg(e){this.exit(e)}function kg(e){const t=this.resume(),n=this.stack[this.stack.length-1];n.type,n.identifier=tt(this.sliceSerialize(e)).toLowerCase(),n.label=t}function wg(e){this.exit(e)}function Sg(){return"["}function xa(e,t,n,r){const i=n.createTracker(r);let s=i.move("[^");const o=n.enter("footnoteReference"),a=n.enter("reference");return s+=i.move(n.safe(n.associationId(e),{after:"]",before:s})),a(),o(),s+=i.move("]"),s}function Cg(){return{enter:{gfmFootnoteCallString:dg,gfmFootnoteCall:mg,gfmFootnoteDefinitionLabelString:gg,gfmFootnoteDefinition:xg},exit:{gfmFootnoteCallString:yg,gfmFootnoteCall:bg,gfmFootnoteDefinitionLabelString:kg,gfmFootnoteDefinition:wg}}}function vg(e){let t=!1;return e&&e.firstLineBlank&&(t=!0),{handlers:{footnoteDefinition:n,footnoteReference:xa},unsafe:[{character:"[",inConstruct:["label","phrasing","reference"]}]};function n(r,i,s,o){const a=s.createTracker(o);let l=a.move("[^");const u=s.enter("footnoteDefinition"),c=s.enter("label");return l+=a.move(s.safe(s.associationId(r),{before:l,after:"]"})),c(),l+=a.move("]:"),r.children&&r.children.length>0&&(a.shift(4),l+=a.move((t?`
|
|
77
|
+
`:" ")+s.indentLines(s.containerFlow(r,a.current()),t?ya:Eg))),u(),l}}function Eg(e,t,n){return t===0?e:ya(e,t,n)}function ya(e,t,n){return(n?"":" ")+e}const Tg=["autolink","destinationLiteral","destinationRaw","reference","titleQuote","titleApostrophe"];ba.peek=Ng;function jg(){return{canContainEols:["delete"],enter:{strikethrough:Ig},exit:{strikethrough:Rg}}}function Ag(){return{unsafe:[{character:"~",inConstruct:"phrasing",notInConstruct:Tg}],handlers:{delete:ba}}}function Ig(e){this.enter({type:"delete",children:[]},e)}function Rg(e){this.exit(e)}function ba(e,t,n,r){const i=n.createTracker(r),s=n.enter("strikethrough");let o=i.move("~~");return o+=n.containerPhrasing(e,{...i.current(),before:o,after:"~"}),o+=i.move("~~"),s(),o}function Ng(){return"~"}function Lg(e){return e.length}function Mg(e,t){const n=t||{},r=(n.align||[]).concat(),i=n.stringLength||Lg,s=[],o=[],a=[],l=[];let u=0,c=-1;for(;++c<e.length;){const x=[],w=[];let b=-1;for(e[c].length>u&&(u=e[c].length);++b<e[c].length;){const S=Dg(e[c][b]);if(n.alignDelimiters!==!1){const v=i(S);w[b]=v,(l[b]===void 0||v>l[b])&&(l[b]=v)}x.push(S)}o[c]=x,a[c]=w}let f=-1;if(typeof r=="object"&&"length"in r)for(;++f<u;)s[f]=Ls(r[f]);else{const x=Ls(r);for(;++f<u;)s[f]=x}f=-1;const p=[],d=[];for(;++f<u;){const x=s[f];let w="",b="";x===99?(w=":",b=":"):x===108?w=":":x===114&&(b=":");let S=n.alignDelimiters===!1?1:Math.max(1,l[f]-w.length-b.length);const v=w+"-".repeat(S)+b;n.alignDelimiters!==!1&&(S=w.length+S+b.length,S>l[f]&&(l[f]=S),d[f]=S),p[f]=v}o.splice(1,0,p),a.splice(1,0,d),c=-1;const g=[];for(;++c<o.length;){const x=o[c],w=a[c];f=-1;const b=[];for(;++f<u;){const S=x[f]||"";let v="",R="";if(n.alignDelimiters!==!1){const M=l[f]-(w[f]||0),C=s[f];C===114?v=" ".repeat(M):C===99?M%2?(v=" ".repeat(M/2+.5),R=" ".repeat(M/2-.5)):(v=" ".repeat(M/2),R=v):R=" ".repeat(M)}n.delimiterStart!==!1&&!f&&b.push("|"),n.padding!==!1&&!(n.alignDelimiters===!1&&S==="")&&(n.delimiterStart!==!1||f)&&b.push(" "),n.alignDelimiters!==!1&&b.push(v),b.push(S),n.alignDelimiters!==!1&&b.push(R),n.padding!==!1&&b.push(" "),(n.delimiterEnd!==!1||f!==u-1)&&b.push("|")}g.push(n.delimiterEnd===!1?b.join("").replace(/ +$/,""):b.join(""))}return g.join(`
|
|
78
|
+
`)}function Dg(e){return e==null?"":String(e)}function Ls(e){const t=typeof e=="string"?e.codePointAt(0):0;return t===67||t===99?99:t===76||t===108?108:t===82||t===114?114:0}function Pg(e,t,n,r){const i=n.enter("blockquote"),s=n.createTracker(r);s.move("> "),s.shift(2);const o=n.indentLines(n.containerFlow(e,s.current()),zg);return i(),o}function zg(e,t,n){return">"+(n?"":" ")+e}function _g(e,t){return Ms(e,t.inConstruct,!0)&&!Ms(e,t.notInConstruct,!1)}function Ms(e,t,n){if(typeof t=="string"&&(t=[t]),!t||t.length===0)return n;let r=-1;for(;++r<t.length;)if(e.includes(t[r]))return!0;return!1}function Ds(e,t,n,r){let i=-1;for(;++i<n.unsafe.length;)if(n.unsafe[i].character===`
|
|
79
|
+
`&&_g(n.stack,n.unsafe[i]))return/[ \t]/.test(r.before)?"":" ";return`\\
|
|
80
|
+
`}function Og(e,t){const n=String(e);let r=n.indexOf(t),i=r,s=0,o=0;if(typeof t!="string")throw new TypeError("Expected substring");for(;r!==-1;)r===i?++s>o&&(o=s):s=1,i=r+t.length,r=n.indexOf(t,i);return o}function Fg(e,t){return!!(t.options.fences===!1&&e.value&&!e.lang&&/[^ \r\n]/.test(e.value)&&!/^[\t ]*(?:[\r\n]|$)|(?:^|[\r\n])[\t ]*$/.test(e.value))}function $g(e){const t=e.options.fence||"`";if(t!=="`"&&t!=="~")throw new Error("Cannot serialize code with `"+t+"` for `options.fence`, expected `` ` `` or `~`");return t}function Bg(e,t,n,r){const i=$g(n),s=e.value||"",o=i==="`"?"GraveAccent":"Tilde";if(Fg(e,n)){const f=n.enter("codeIndented"),p=n.indentLines(s,Hg);return f(),p}const a=n.createTracker(r),l=i.repeat(Math.max(Og(s,i)+1,3)),u=n.enter("codeFenced");let c=a.move(l);if(e.lang){const f=n.enter(`codeFencedLang${o}`);c+=a.move(n.safe(e.lang,{before:c,after:" ",encode:["`"],...a.current()})),f()}if(e.lang&&e.meta){const f=n.enter(`codeFencedMeta${o}`);c+=a.move(" "),c+=a.move(n.safe(e.meta,{before:c,after:`
|
|
81
|
+
`,encode:["`"],...a.current()})),f()}return c+=a.move(`
|
|
82
|
+
`),s&&(c+=a.move(s+`
|
|
83
|
+
`)),c+=a.move(l),u(),c}function Hg(e,t,n){return(n?"":" ")+e}function Ti(e){const t=e.options.quote||'"';if(t!=='"'&&t!=="'")throw new Error("Cannot serialize title with `"+t+"` for `options.quote`, expected `\"`, or `'`");return t}function Ug(e,t,n,r){const i=Ti(n),s=i==='"'?"Quote":"Apostrophe",o=n.enter("definition");let a=n.enter("label");const l=n.createTracker(r);let u=l.move("[");return u+=l.move(n.safe(n.associationId(e),{before:u,after:"]",...l.current()})),u+=l.move("]: "),a(),!e.url||/[\0- \u007F]/.test(e.url)?(a=n.enter("destinationLiteral"),u+=l.move("<"),u+=l.move(n.safe(e.url,{before:u,after:">",...l.current()})),u+=l.move(">")):(a=n.enter("destinationRaw"),u+=l.move(n.safe(e.url,{before:u,after:e.title?" ":`
|
|
84
|
+
`,...l.current()}))),a(),e.title&&(a=n.enter(`title${s}`),u+=l.move(" "+i),u+=l.move(n.safe(e.title,{before:u,after:i,...l.current()})),u+=l.move(i),a()),o(),u}function qg(e){const t=e.options.emphasis||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize emphasis with `"+t+"` for `options.emphasis`, expected `*`, or `_`");return t}function un(e){return"&#x"+e.toString(16).toUpperCase()+";"}function Fn(e,t,n){const r=qt(e),i=qt(t);return r===void 0?i===void 0?n==="_"?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!0}:r===1?i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!0}:{inside:!1,outside:!1}:i===void 0?{inside:!1,outside:!1}:i===1?{inside:!0,outside:!1}:{inside:!1,outside:!1}}ka.peek=Wg;function ka(e,t,n,r){const i=qg(n),s=n.enter("emphasis"),o=n.createTracker(r),a=o.move(i);let l=o.move(n.containerPhrasing(e,{after:i,before:a,...o.current()}));const u=l.charCodeAt(0),c=Fn(r.before.charCodeAt(r.before.length-1),u,i);c.inside&&(l=un(u)+l.slice(1));const f=l.charCodeAt(l.length-1),p=Fn(r.after.charCodeAt(0),f,i);p.inside&&(l=l.slice(0,-1)+un(f));const d=o.move(i);return s(),n.attentionEncodeSurroundingInfo={after:p.outside,before:c.outside},a+l+d}function Wg(e,t,n){return n.options.emphasis||"*"}function Kg(e,t){let n=!1;return vi(e,function(r){if("value"in r&&/\r?\n|\r/.test(r.value)||r.type==="break")return n=!0,$r}),!!((!e.depth||e.depth<3)&&xi(e)&&(t.options.setext||n))}function Xg(e,t,n,r){const i=Math.max(Math.min(6,e.depth||1),1),s=n.createTracker(r);if(Kg(e,n)){const c=n.enter("headingSetext"),f=n.enter("phrasing"),p=n.containerPhrasing(e,{...s.current(),before:`
|
|
85
|
+
`,after:`
|
|
86
|
+
`});return f(),c(),p+`
|
|
87
|
+
`+(i===1?"=":"-").repeat(p.length-(Math.max(p.lastIndexOf("\r"),p.lastIndexOf(`
|
|
88
|
+
`))+1))}const o="#".repeat(i),a=n.enter("headingAtx"),l=n.enter("phrasing");s.move(o+" ");let u=n.containerPhrasing(e,{before:"# ",after:`
|
|
89
|
+
`,...s.current()});return/^[\t ]/.test(u)&&(u=un(u.charCodeAt(0))+u.slice(1)),u=u?o+" "+u:o,n.options.closeAtx&&(u+=" "+o),l(),a(),u}wa.peek=Vg;function wa(e){return e.value||""}function Vg(){return"<"}Sa.peek=Yg;function Sa(e,t,n,r){const i=Ti(n),s=i==='"'?"Quote":"Apostrophe",o=n.enter("image");let a=n.enter("label");const l=n.createTracker(r);let u=l.move("![");return u+=l.move(n.safe(e.alt,{before:u,after:"]",...l.current()})),u+=l.move("]("),a(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(a=n.enter("destinationLiteral"),u+=l.move("<"),u+=l.move(n.safe(e.url,{before:u,after:">",...l.current()})),u+=l.move(">")):(a=n.enter("destinationRaw"),u+=l.move(n.safe(e.url,{before:u,after:e.title?" ":")",...l.current()}))),a(),e.title&&(a=n.enter(`title${s}`),u+=l.move(" "+i),u+=l.move(n.safe(e.title,{before:u,after:i,...l.current()})),u+=l.move(i),a()),u+=l.move(")"),o(),u}function Yg(){return"!"}Ca.peek=Gg;function Ca(e,t,n,r){const i=e.referenceType,s=n.enter("imageReference");let o=n.enter("label");const a=n.createTracker(r);let l=a.move("![");const u=n.safe(e.alt,{before:l,after:"]",...a.current()});l+=a.move(u+"]["),o();const c=n.stack;n.stack=[],o=n.enter("reference");const f=n.safe(n.associationId(e),{before:l,after:"]",...a.current()});return o(),n.stack=c,s(),i==="full"||!u||u!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function Gg(){return"!"}va.peek=Qg;function va(e,t,n){let r=e.value||"",i="`",s=-1;for(;new RegExp("(^|[^`])"+i+"([^`]|$)").test(r);)i+="`";for(/[^ \r\n]/.test(r)&&(/^[ \r\n]/.test(r)&&/[ \r\n]$/.test(r)||/^`|`$/.test(r))&&(r=" "+r+" ");++s<n.unsafe.length;){const o=n.unsafe[s],a=n.compilePattern(o);let l;if(o.atBreak)for(;l=a.exec(r);){let u=l.index;r.charCodeAt(u)===10&&r.charCodeAt(u-1)===13&&u--,r=r.slice(0,u)+" "+r.slice(l.index+1)}}return i+r+i}function Qg(){return"`"}function Ea(e,t){const n=xi(e);return!!(!t.options.resourceLink&&e.url&&!e.title&&e.children&&e.children.length===1&&e.children[0].type==="text"&&(n===e.url||"mailto:"+n===e.url)&&/^[a-z][a-z+.-]+:/i.test(e.url)&&!/[\0- <>\u007F]/.test(e.url))}Ta.peek=Jg;function Ta(e,t,n,r){const i=Ti(n),s=i==='"'?"Quote":"Apostrophe",o=n.createTracker(r);let a,l;if(Ea(e,n)){const c=n.stack;n.stack=[],a=n.enter("autolink");let f=o.move("<");return f+=o.move(n.containerPhrasing(e,{before:f,after:">",...o.current()})),f+=o.move(">"),a(),n.stack=c,f}a=n.enter("link"),l=n.enter("label");let u=o.move("[");return u+=o.move(n.containerPhrasing(e,{before:u,after:"](",...o.current()})),u+=o.move("]("),l(),!e.url&&e.title||/[\0- \u007F]/.test(e.url)?(l=n.enter("destinationLiteral"),u+=o.move("<"),u+=o.move(n.safe(e.url,{before:u,after:">",...o.current()})),u+=o.move(">")):(l=n.enter("destinationRaw"),u+=o.move(n.safe(e.url,{before:u,after:e.title?" ":")",...o.current()}))),l(),e.title&&(l=n.enter(`title${s}`),u+=o.move(" "+i),u+=o.move(n.safe(e.title,{before:u,after:i,...o.current()})),u+=o.move(i),l()),u+=o.move(")"),a(),u}function Jg(e,t,n){return Ea(e,n)?"<":"["}ja.peek=Zg;function ja(e,t,n,r){const i=e.referenceType,s=n.enter("linkReference");let o=n.enter("label");const a=n.createTracker(r);let l=a.move("[");const u=n.containerPhrasing(e,{before:l,after:"]",...a.current()});l+=a.move(u+"]["),o();const c=n.stack;n.stack=[],o=n.enter("reference");const f=n.safe(n.associationId(e),{before:l,after:"]",...a.current()});return o(),n.stack=c,s(),i==="full"||!u||u!==f?l+=a.move(f+"]"):i==="shortcut"?l=l.slice(0,-1):l+=a.move("]"),l}function Zg(){return"["}function ji(e){const t=e.options.bullet||"*";if(t!=="*"&&t!=="+"&&t!=="-")throw new Error("Cannot serialize items with `"+t+"` for `options.bullet`, expected `*`, `+`, or `-`");return t}function ex(e){const t=ji(e),n=e.options.bulletOther;if(!n)return t==="*"?"-":"*";if(n!=="*"&&n!=="+"&&n!=="-")throw new Error("Cannot serialize items with `"+n+"` for `options.bulletOther`, expected `*`, `+`, or `-`");if(n===t)throw new Error("Expected `bullet` (`"+t+"`) and `bulletOther` (`"+n+"`) to be different");return n}function tx(e){const t=e.options.bulletOrdered||".";if(t!=="."&&t!==")")throw new Error("Cannot serialize items with `"+t+"` for `options.bulletOrdered`, expected `.` or `)`");return t}function Aa(e){const t=e.options.rule||"*";if(t!=="*"&&t!=="-"&&t!=="_")throw new Error("Cannot serialize rules with `"+t+"` for `options.rule`, expected `*`, `-`, or `_`");return t}function nx(e,t,n,r){const i=n.enter("list"),s=n.bulletCurrent;let o=e.ordered?tx(n):ji(n);const a=e.ordered?o==="."?")":".":ex(n);let l=t&&n.bulletLastUsed?o===n.bulletLastUsed:!1;if(!e.ordered){const c=e.children?e.children[0]:void 0;if((o==="*"||o==="-")&&c&&(!c.children||!c.children[0])&&n.stack[n.stack.length-1]==="list"&&n.stack[n.stack.length-2]==="listItem"&&n.stack[n.stack.length-3]==="list"&&n.stack[n.stack.length-4]==="listItem"&&n.indexStack[n.indexStack.length-1]===0&&n.indexStack[n.indexStack.length-2]===0&&n.indexStack[n.indexStack.length-3]===0&&(l=!0),Aa(n)===o&&c){let f=-1;for(;++f<e.children.length;){const p=e.children[f];if(p&&p.type==="listItem"&&p.children&&p.children[0]&&p.children[0].type==="thematicBreak"){l=!0;break}}}}l&&(o=a),n.bulletCurrent=o;const u=n.containerFlow(e,r);return n.bulletLastUsed=o,n.bulletCurrent=s,i(),u}function rx(e){const t=e.options.listItemIndent||"one";if(t!=="tab"&&t!=="one"&&t!=="mixed")throw new Error("Cannot serialize items with `"+t+"` for `options.listItemIndent`, expected `tab`, `one`, or `mixed`");return t}function ix(e,t,n,r){const i=rx(n);let s=n.bulletCurrent||ji(n);t&&t.type==="list"&&t.ordered&&(s=(typeof t.start=="number"&&t.start>-1?t.start:1)+(n.options.incrementListMarker===!1?0:t.children.indexOf(e))+s);let o=s.length+1;(i==="tab"||i==="mixed"&&(t&&t.type==="list"&&t.spread||e.spread))&&(o=Math.ceil(o/4)*4);const a=n.createTracker(r);a.move(s+" ".repeat(o-s.length)),a.shift(o);const l=n.enter("listItem"),u=n.indentLines(n.containerFlow(e,a.current()),c);return l(),u;function c(f,p,d){return p?(d?"":" ".repeat(o))+f:(d?s:s+" ".repeat(o-s.length))+f}}function sx(e,t,n,r){const i=n.enter("paragraph"),s=n.enter("phrasing"),o=n.containerPhrasing(e,r);return s(),i(),o}const ox=Jn(["break","delete","emphasis","footnote","footnoteReference","image","imageReference","inlineCode","inlineMath","link","linkReference","mdxJsxTextElement","mdxTextExpression","strong","text","textDirective"]);function ax(e,t,n,r){return(e.children.some(function(o){return ox(o)})?n.containerPhrasing:n.containerFlow).call(n,e,r)}function lx(e){const t=e.options.strong||"*";if(t!=="*"&&t!=="_")throw new Error("Cannot serialize strong with `"+t+"` for `options.strong`, expected `*`, or `_`");return t}Ia.peek=ux;function Ia(e,t,n,r){const i=lx(n),s=n.enter("strong"),o=n.createTracker(r),a=o.move(i+i);let l=o.move(n.containerPhrasing(e,{after:i,before:a,...o.current()}));const u=l.charCodeAt(0),c=Fn(r.before.charCodeAt(r.before.length-1),u,i);c.inside&&(l=un(u)+l.slice(1));const f=l.charCodeAt(l.length-1),p=Fn(r.after.charCodeAt(0),f,i);p.inside&&(l=l.slice(0,-1)+un(f));const d=o.move(i+i);return s(),n.attentionEncodeSurroundingInfo={after:p.outside,before:c.outside},a+l+d}function ux(e,t,n){return n.options.strong||"*"}function cx(e,t,n,r){return n.safe(e.value,r)}function fx(e){const t=e.options.ruleRepetition||3;if(t<3)throw new Error("Cannot serialize rules with repetition `"+t+"` for `options.ruleRepetition`, expected `3` or more");return t}function hx(e,t,n){const r=(Aa(n)+(n.options.ruleSpaces?" ":"")).repeat(fx(n));return n.options.ruleSpaces?r.slice(0,-1):r}const Ra={blockquote:Pg,break:Ds,code:Bg,definition:Ug,emphasis:ka,hardBreak:Ds,heading:Xg,html:wa,image:Sa,imageReference:Ca,inlineCode:va,link:Ta,linkReference:ja,list:nx,listItem:ix,paragraph:sx,root:ax,strong:Ia,text:cx,thematicBreak:hx};function px(){return{enter:{table:dx,tableData:Ps,tableHeader:Ps,tableRow:gx},exit:{codeText:xx,table:mx,tableData:vr,tableHeader:vr,tableRow:vr}}}function dx(e){const t=e._align;this.enter({type:"table",align:t.map(function(n){return n==="none"?null:n}),children:[]},e),this.data.inTable=!0}function mx(e){this.exit(e),this.data.inTable=void 0}function gx(e){this.enter({type:"tableRow",children:[]},e)}function vr(e){this.exit(e)}function Ps(e){this.enter({type:"tableCell",children:[]},e)}function xx(e){let t=this.resume();this.data.inTable&&(t=t.replace(/\\([\\|])/g,yx));const n=this.stack[this.stack.length-1];n.type,n.value=t,this.exit(e)}function yx(e,t){return t==="|"?t:e}function bx(e){const t=e||{},n=t.tableCellPadding,r=t.tablePipeAlign,i=t.stringLength,s=n?" ":"|";return{unsafe:[{character:"\r",inConstruct:"tableCell"},{character:`
|
|
90
|
+
`,inConstruct:"tableCell"},{atBreak:!0,character:"|",after:"[ :-]"},{character:"|",inConstruct:"tableCell"},{atBreak:!0,character:":",after:"-"},{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{inlineCode:p,table:o,tableCell:l,tableRow:a}};function o(d,g,x,w){return u(c(d,x,w),d.align)}function a(d,g,x,w){const b=f(d,x,w),S=u([b]);return S.slice(0,S.indexOf(`
|
|
91
|
+
`))}function l(d,g,x,w){const b=x.enter("tableCell"),S=x.enter("phrasing"),v=x.containerPhrasing(d,{...w,before:s,after:s});return S(),b(),v}function u(d,g){return Mg(d,{align:g,alignDelimiters:r,padding:n,stringLength:i})}function c(d,g,x){const w=d.children;let b=-1;const S=[],v=g.enter("table");for(;++b<w.length;)S[b]=f(w[b],g,x);return v(),S}function f(d,g,x){const w=d.children;let b=-1;const S=[],v=g.enter("tableRow");for(;++b<w.length;)S[b]=l(w[b],d,g,x);return v(),S}function p(d,g,x){let w=Ra.inlineCode(d,g,x);return x.stack.includes("tableCell")&&(w=w.replace(/\|/g,"\\$&")),w}}function kx(){return{exit:{taskListCheckValueChecked:zs,taskListCheckValueUnchecked:zs,paragraph:Sx}}}function wx(){return{unsafe:[{atBreak:!0,character:"-",after:"[:|-]"}],handlers:{listItem:Cx}}}function zs(e){const t=this.stack[this.stack.length-2];t.type,t.checked=e.type==="taskListCheckValueChecked"}function Sx(e){const t=this.stack[this.stack.length-2];if(t&&t.type==="listItem"&&typeof t.checked=="boolean"){const n=this.stack[this.stack.length-1];n.type;const r=n.children[0];if(r&&r.type==="text"){const i=t.children;let s=-1,o;for(;++s<i.length;){const a=i[s];if(a.type==="paragraph"){o=a;break}}o===n&&(r.value=r.value.slice(1),r.value.length===0?n.children.shift():n.position&&r.position&&typeof r.position.start.offset=="number"&&(r.position.start.column++,r.position.start.offset++,n.position.start=Object.assign({},r.position.start)))}}this.exit(e)}function Cx(e,t,n,r){const i=e.children[0],s=typeof e.checked=="boolean"&&i&&i.type==="paragraph",o="["+(e.checked?"x":" ")+"] ",a=n.createTracker(r);s&&a.move(o);let l=Ra.listItem(e,t,n,{...r,...a.current()});return s&&(l=l.replace(/^(?:[*+-]|\d+\.)([\r\n]| {1,3})/,u)),l;function u(c){return c+o}}function vx(){return[ng(),Cg(),jg(),px(),kx()]}function Ex(e){return{extensions:[rg(),vg(e),Ag(),bx(e),wx()]}}const Tx={tokenize:Lx,partial:!0},Na={tokenize:Mx,partial:!0},La={tokenize:Dx,partial:!0},Ma={tokenize:Px,partial:!0},jx={tokenize:zx,partial:!0},Da={name:"wwwAutolink",tokenize:Rx,previous:za},Pa={name:"protocolAutolink",tokenize:Nx,previous:_a},lt={name:"emailAutolink",tokenize:Ix,previous:Oa},st={};function Ax(){return{text:st}}let At=48;for(;At<123;)st[At]=lt,At++,At===58?At=65:At===91&&(At=97);st[43]=lt;st[45]=lt;st[46]=lt;st[95]=lt;st[72]=[lt,Pa];st[104]=[lt,Pa];st[87]=[lt,Da];st[119]=[lt,Da];function Ix(e,t,n){const r=this;let i,s;return o;function o(f){return!qr(f)||!Oa.call(r,r.previous)||Ai(r.events)?n(f):(e.enter("literalAutolink"),e.enter("literalAutolinkEmail"),a(f))}function a(f){return qr(f)?(e.consume(f),a):f===64?(e.consume(f),l):n(f)}function l(f){return f===46?e.check(jx,c,u)(f):f===45||f===95||Re(f)?(s=!0,e.consume(f),l):c(f)}function u(f){return e.consume(f),i=!0,l}function c(f){return s&&i&&Me(r.previous)?(e.exit("literalAutolinkEmail"),e.exit("literalAutolink"),t(f)):n(f)}}function Rx(e,t,n){const r=this;return i;function i(o){return o!==87&&o!==119||!za.call(r,r.previous)||Ai(r.events)?n(o):(e.enter("literalAutolink"),e.enter("literalAutolinkWww"),e.check(Tx,e.attempt(Na,e.attempt(La,s),n),n)(o))}function s(o){return e.exit("literalAutolinkWww"),e.exit("literalAutolink"),t(o)}}function Nx(e,t,n){const r=this;let i="",s=!1;return o;function o(f){return(f===72||f===104)&&_a.call(r,r.previous)&&!Ai(r.events)?(e.enter("literalAutolink"),e.enter("literalAutolinkHttp"),i+=String.fromCodePoint(f),e.consume(f),a):n(f)}function a(f){if(Me(f)&&i.length<5)return i+=String.fromCodePoint(f),e.consume(f),a;if(f===58){const p=i.toLowerCase();if(p==="http"||p==="https")return e.consume(f),l}return n(f)}function l(f){return f===47?(e.consume(f),s?u:(s=!0,l)):n(f)}function u(f){return f===null||zn(f)||fe(f)||Dt(f)||Yn(f)?n(f):e.attempt(Na,e.attempt(La,c),n)(f)}function c(f){return e.exit("literalAutolinkHttp"),e.exit("literalAutolink"),t(f)}}function Lx(e,t,n){let r=0;return i;function i(o){return(o===87||o===119)&&r<3?(r++,e.consume(o),i):o===46&&r===3?(e.consume(o),s):n(o)}function s(o){return o===null?n(o):t(o)}}function Mx(e,t,n){let r,i,s;return o;function o(u){return u===46||u===95?e.check(Ma,l,a)(u):u===null||fe(u)||Dt(u)||u!==45&&Yn(u)?l(u):(s=!0,e.consume(u),o)}function a(u){return u===95?r=!0:(i=r,r=void 0),e.consume(u),o}function l(u){return i||r||!s?n(u):t(u)}}function Dx(e,t){let n=0,r=0;return i;function i(o){return o===40?(n++,e.consume(o),i):o===41&&r<n?s(o):o===33||o===34||o===38||o===39||o===41||o===42||o===44||o===46||o===58||o===59||o===60||o===63||o===93||o===95||o===126?e.check(Ma,t,s)(o):o===null||fe(o)||Dt(o)?t(o):(e.consume(o),i)}function s(o){return o===41&&r++,e.consume(o),i}}function Px(e,t,n){return r;function r(a){return a===33||a===34||a===39||a===41||a===42||a===44||a===46||a===58||a===59||a===63||a===95||a===126?(e.consume(a),r):a===38?(e.consume(a),s):a===93?(e.consume(a),i):a===60||a===null||fe(a)||Dt(a)?t(a):n(a)}function i(a){return a===null||a===40||a===91||fe(a)||Dt(a)?t(a):r(a)}function s(a){return Me(a)?o(a):n(a)}function o(a){return a===59?(e.consume(a),r):Me(a)?(e.consume(a),o):n(a)}}function zx(e,t,n){return r;function r(s){return e.consume(s),i}function i(s){return Re(s)?n(s):t(s)}}function za(e){return e===null||e===40||e===42||e===95||e===91||e===93||e===126||fe(e)}function _a(e){return!Me(e)}function Oa(e){return!(e===47||qr(e))}function qr(e){return e===43||e===45||e===46||e===95||Re(e)}function Ai(e){let t=e.length,n=!1;for(;t--;){const r=e[t][1];if((r.type==="labelLink"||r.type==="labelImage")&&!r._balanced){n=!0;break}if(r._gfmAutolinkLiteralWalkedInto){n=!1;break}}return e.length>0&&!n&&(e[e.length-1][1]._gfmAutolinkLiteralWalkedInto=!0),n}const _x={tokenize:Wx,partial:!0};function Ox(){return{document:{91:{name:"gfmFootnoteDefinition",tokenize:Hx,continuation:{tokenize:Ux},exit:qx}},text:{91:{name:"gfmFootnoteCall",tokenize:Bx},93:{name:"gfmPotentialFootnoteCall",add:"after",tokenize:Fx,resolveTo:$x}}}}function Fx(e,t,n){const r=this;let i=r.events.length;const s=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let o;for(;i--;){const l=r.events[i][1];if(l.type==="labelImage"){o=l;break}if(l.type==="gfmFootnoteCall"||l.type==="labelLink"||l.type==="label"||l.type==="image"||l.type==="link")break}return a;function a(l){if(!o||!o._balanced)return n(l);const u=tt(r.sliceSerialize({start:o.end,end:r.now()}));return u.codePointAt(0)!==94||!s.includes(u.slice(1))?n(l):(e.enter("gfmFootnoteCallLabelMarker"),e.consume(l),e.exit("gfmFootnoteCallLabelMarker"),t(l))}}function $x(e,t){let n=e.length;for(;n--;)if(e[n][1].type==="labelImage"&&e[n][0]==="enter"){e[n][1];break}e[n+1][1].type="data",e[n+3][1].type="gfmFootnoteCallLabelMarker";const r={type:"gfmFootnoteCall",start:Object.assign({},e[n+3][1].start),end:Object.assign({},e[e.length-1][1].end)},i={type:"gfmFootnoteCallMarker",start:Object.assign({},e[n+3][1].end),end:Object.assign({},e[n+3][1].end)};i.end.column++,i.end.offset++,i.end._bufferIndex++;const s={type:"gfmFootnoteCallString",start:Object.assign({},i.end),end:Object.assign({},e[e.length-1][1].start)},o={type:"chunkString",contentType:"string",start:Object.assign({},s.start),end:Object.assign({},s.end)},a=[e[n+1],e[n+2],["enter",r,t],e[n+3],e[n+4],["enter",i,t],["exit",i,t],["enter",s,t],["enter",o,t],["exit",o,t],["exit",s,t],e[e.length-2],e[e.length-1],["exit",r,t]];return e.splice(n,e.length-n+1,...a),e}function Bx(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s=0,o;return a;function a(f){return e.enter("gfmFootnoteCall"),e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),l}function l(f){return f!==94?n(f):(e.enter("gfmFootnoteCallMarker"),e.consume(f),e.exit("gfmFootnoteCallMarker"),e.enter("gfmFootnoteCallString"),e.enter("chunkString").contentType="string",u)}function u(f){if(s>999||f===93&&!o||f===null||f===91||fe(f))return n(f);if(f===93){e.exit("chunkString");const p=e.exit("gfmFootnoteCallString");return i.includes(tt(r.sliceSerialize(p)))?(e.enter("gfmFootnoteCallLabelMarker"),e.consume(f),e.exit("gfmFootnoteCallLabelMarker"),e.exit("gfmFootnoteCall"),t):n(f)}return fe(f)||(o=!0),s++,e.consume(f),f===92?c:u}function c(f){return f===91||f===92||f===93?(e.consume(f),s++,u):u(f)}}function Hx(e,t,n){const r=this,i=r.parser.gfmFootnotes||(r.parser.gfmFootnotes=[]);let s,o=0,a;return l;function l(g){return e.enter("gfmFootnoteDefinition")._container=!0,e.enter("gfmFootnoteDefinitionLabel"),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionLabelMarker"),u}function u(g){return g===94?(e.enter("gfmFootnoteDefinitionMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionMarker"),e.enter("gfmFootnoteDefinitionLabelString"),e.enter("chunkString").contentType="string",c):n(g)}function c(g){if(o>999||g===93&&!a||g===null||g===91||fe(g))return n(g);if(g===93){e.exit("chunkString");const x=e.exit("gfmFootnoteDefinitionLabelString");return s=tt(r.sliceSerialize(x)),e.enter("gfmFootnoteDefinitionLabelMarker"),e.consume(g),e.exit("gfmFootnoteDefinitionLabelMarker"),e.exit("gfmFootnoteDefinitionLabel"),p}return fe(g)||(a=!0),o++,e.consume(g),g===92?f:c}function f(g){return g===91||g===92||g===93?(e.consume(g),o++,c):c(g)}function p(g){return g===58?(e.enter("definitionMarker"),e.consume(g),e.exit("definitionMarker"),i.includes(s)||i.push(s),oe(e,d,"gfmFootnoteDefinitionWhitespace")):n(g)}function d(g){return t(g)}}function Ux(e,t,n){return e.check(fn,t,e.attempt(_x,t,n))}function qx(e){e.exit("gfmFootnoteDefinition")}function Wx(e,t,n){const r=this;return oe(e,i,"gfmFootnoteDefinitionIndent",5);function i(s){const o=r.events[r.events.length-1];return o&&o[1].type==="gfmFootnoteDefinitionIndent"&&o[2].sliceSerialize(o[1],!0).length===4?t(s):n(s)}}function Kx(e){let n=(e||{}).singleTilde;const r={name:"strikethrough",tokenize:s,resolveAll:i};return n==null&&(n=!0),{text:{126:r},insideSpan:{null:[r]},attentionMarkers:{null:[126]}};function i(o,a){let l=-1;for(;++l<o.length;)if(o[l][0]==="enter"&&o[l][1].type==="strikethroughSequenceTemporary"&&o[l][1]._close){let u=l;for(;u--;)if(o[u][0]==="exit"&&o[u][1].type==="strikethroughSequenceTemporary"&&o[u][1]._open&&o[l][1].end.offset-o[l][1].start.offset===o[u][1].end.offset-o[u][1].start.offset){o[l][1].type="strikethroughSequence",o[u][1].type="strikethroughSequence";const c={type:"strikethrough",start:Object.assign({},o[u][1].start),end:Object.assign({},o[l][1].end)},f={type:"strikethroughText",start:Object.assign({},o[u][1].end),end:Object.assign({},o[l][1].start)},p=[["enter",c,a],["enter",o[u][1],a],["exit",o[u][1],a],["enter",f,a]],d=a.parser.constructs.insideSpan.null;d&&qe(p,p.length,0,Gn(d,o.slice(u+1,l),a)),qe(p,p.length,0,[["exit",f,a],["enter",o[l][1],a],["exit",o[l][1],a],["exit",c,a]]),qe(o,u-1,l-u+3,p),l=u+p.length-2;break}}for(l=-1;++l<o.length;)o[l][1].type==="strikethroughSequenceTemporary"&&(o[l][1].type="data");return o}function s(o,a,l){const u=this.previous,c=this.events;let f=0;return p;function p(g){return u===126&&c[c.length-1][1].type!=="characterEscape"?l(g):(o.enter("strikethroughSequenceTemporary"),d(g))}function d(g){const x=qt(u);if(g===126)return f>1?l(g):(o.consume(g),f++,d);if(f<2&&!n)return l(g);const w=o.exit("strikethroughSequenceTemporary"),b=qt(g);return w._open=!b||b===2&&!!x,w._close=!x||x===2&&!!b,a(g)}}}class Xx{constructor(){this.map=[]}add(t,n,r){Vx(this,t,n,r)}consume(t){if(this.map.sort(function(s,o){return s[0]-o[0]}),this.map.length===0)return;let n=this.map.length;const r=[];for(;n>0;)n-=1,r.push(t.slice(this.map[n][0]+this.map[n][1]),this.map[n][2]),t.length=this.map[n][0];r.push(t.slice()),t.length=0;let i=r.pop();for(;i;){for(const s of i)t.push(s);i=r.pop()}this.map.length=0}}function Vx(e,t,n,r){let i=0;if(!(n===0&&r.length===0)){for(;i<e.map.length;){if(e.map[i][0]===t){e.map[i][1]+=n,e.map[i][2].push(...r);return}i+=1}e.map.push([t,n,r])}}function Yx(e,t){let n=!1;const r=[];for(;t<e.length;){const i=e[t];if(n){if(i[0]==="enter")i[1].type==="tableContent"&&r.push(e[t+1][1].type==="tableDelimiterMarker"?"left":"none");else if(i[1].type==="tableContent"){if(e[t-1][1].type==="tableDelimiterMarker"){const s=r.length-1;r[s]=r[s]==="left"?"center":"right"}}else if(i[1].type==="tableDelimiterRow")break}else i[0]==="enter"&&i[1].type==="tableDelimiterRow"&&(n=!0);t+=1}return r}function Gx(){return{flow:{null:{name:"table",tokenize:Qx,resolveAll:Jx}}}}function Qx(e,t,n){const r=this;let i=0,s=0,o;return a;function a(E){let N=r.events.length-1;for(;N>-1;){const j=r.events[N][1].type;if(j==="lineEnding"||j==="linePrefix")N--;else break}const A=N>-1?r.events[N][1].type:null,z=A==="tableHead"||A==="tableRow"?C:l;return z===C&&r.parser.lazy[r.now().line]?n(E):z(E)}function l(E){return e.enter("tableHead"),e.enter("tableRow"),u(E)}function u(E){return E===124||(o=!0,s+=1),c(E)}function c(E){return E===null?n(E):G(E)?s>1?(s=0,r.interrupt=!0,e.exit("tableRow"),e.enter("lineEnding"),e.consume(E),e.exit("lineEnding"),d):n(E):ie(E)?oe(e,c,"whitespace")(E):(s+=1,o&&(o=!1,i+=1),E===124?(e.enter("tableCellDivider"),e.consume(E),e.exit("tableCellDivider"),o=!0,c):(e.enter("data"),f(E)))}function f(E){return E===null||E===124||fe(E)?(e.exit("data"),c(E)):(e.consume(E),E===92?p:f)}function p(E){return E===92||E===124?(e.consume(E),f):f(E)}function d(E){return r.interrupt=!1,r.parser.lazy[r.now().line]?n(E):(e.enter("tableDelimiterRow"),o=!1,ie(E)?oe(e,g,"linePrefix",r.parser.constructs.disable.null.includes("codeIndented")?void 0:4)(E):g(E))}function g(E){return E===45||E===58?w(E):E===124?(o=!0,e.enter("tableCellDivider"),e.consume(E),e.exit("tableCellDivider"),x):M(E)}function x(E){return ie(E)?oe(e,w,"whitespace")(E):w(E)}function w(E){return E===58?(s+=1,o=!0,e.enter("tableDelimiterMarker"),e.consume(E),e.exit("tableDelimiterMarker"),b):E===45?(s+=1,b(E)):E===null||G(E)?R(E):M(E)}function b(E){return E===45?(e.enter("tableDelimiterFiller"),S(E)):M(E)}function S(E){return E===45?(e.consume(E),S):E===58?(o=!0,e.exit("tableDelimiterFiller"),e.enter("tableDelimiterMarker"),e.consume(E),e.exit("tableDelimiterMarker"),v):(e.exit("tableDelimiterFiller"),v(E))}function v(E){return ie(E)?oe(e,R,"whitespace")(E):R(E)}function R(E){return E===124?g(E):E===null||G(E)?!o||i!==s?M(E):(e.exit("tableDelimiterRow"),e.exit("tableHead"),t(E)):M(E)}function M(E){return n(E)}function C(E){return e.enter("tableRow"),P(E)}function P(E){return E===124?(e.enter("tableCellDivider"),e.consume(E),e.exit("tableCellDivider"),P):E===null||G(E)?(e.exit("tableRow"),t(E)):ie(E)?oe(e,P,"whitespace")(E):(e.enter("data"),U(E))}function U(E){return E===null||E===124||fe(E)?(e.exit("data"),P(E)):(e.consume(E),E===92?F:U)}function F(E){return E===92||E===124?(e.consume(E),U):U(E)}}function Jx(e,t){let n=-1,r=!0,i=0,s=[0,0,0,0],o=[0,0,0,0],a=!1,l=0,u,c,f;const p=new Xx;for(;++n<e.length;){const d=e[n],g=d[1];d[0]==="enter"?g.type==="tableHead"?(a=!1,l!==0&&(_s(p,t,l,u,c),c=void 0,l=0),u={type:"table",start:Object.assign({},g.start),end:Object.assign({},g.end)},p.add(n,0,[["enter",u,t]])):g.type==="tableRow"||g.type==="tableDelimiterRow"?(r=!0,f=void 0,s=[0,0,0,0],o=[0,n+1,0,0],a&&(a=!1,c={type:"tableBody",start:Object.assign({},g.start),end:Object.assign({},g.end)},p.add(n,0,[["enter",c,t]])),i=g.type==="tableDelimiterRow"?2:c?3:1):i&&(g.type==="data"||g.type==="tableDelimiterMarker"||g.type==="tableDelimiterFiller")?(r=!1,o[2]===0&&(s[1]!==0&&(o[0]=o[1],f=kn(p,t,s,i,void 0,f),s=[0,0,0,0]),o[2]=n)):g.type==="tableCellDivider"&&(r?r=!1:(s[1]!==0&&(o[0]=o[1],f=kn(p,t,s,i,void 0,f)),s=o,o=[s[1],n,0,0])):g.type==="tableHead"?(a=!0,l=n):g.type==="tableRow"||g.type==="tableDelimiterRow"?(l=n,s[1]!==0?(o[0]=o[1],f=kn(p,t,s,i,n,f)):o[1]!==0&&(f=kn(p,t,o,i,n,f)),i=0):i&&(g.type==="data"||g.type==="tableDelimiterMarker"||g.type==="tableDelimiterFiller")&&(o[3]=n)}for(l!==0&&_s(p,t,l,u,c),p.consume(t.events),n=-1;++n<t.events.length;){const d=t.events[n];d[0]==="enter"&&d[1].type==="table"&&(d[1]._align=Yx(t.events,n))}return e}function kn(e,t,n,r,i,s){const o=r===1?"tableHeader":r===2?"tableDelimiter":"tableData",a="tableContent";n[0]!==0&&(s.end=Object.assign({},Ht(t.events,n[0])),e.add(n[0],0,[["exit",s,t]]));const l=Ht(t.events,n[1]);if(s={type:o,start:Object.assign({},l),end:Object.assign({},l)},e.add(n[1],0,[["enter",s,t]]),n[2]!==0){const u=Ht(t.events,n[2]),c=Ht(t.events,n[3]),f={type:a,start:Object.assign({},u),end:Object.assign({},c)};if(e.add(n[2],0,[["enter",f,t]]),r!==2){const p=t.events[n[2]],d=t.events[n[3]];if(p[1].end=Object.assign({},d[1].end),p[1].type="chunkText",p[1].contentType="text",n[3]>n[2]+1){const g=n[2]+1,x=n[3]-n[2]-1;e.add(g,x,[])}}e.add(n[3]+1,0,[["exit",f,t]])}return i!==void 0&&(s.end=Object.assign({},Ht(t.events,i)),e.add(i,0,[["exit",s,t]]),s=void 0),s}function _s(e,t,n,r,i){const s=[],o=Ht(t.events,n);i&&(i.end=Object.assign({},o),s.push(["exit",i,t])),r.end=Object.assign({},o),s.push(["exit",r,t]),e.add(n+1,0,s)}function Ht(e,t){const n=e[t],r=n[0]==="enter"?"start":"end";return n[1][r]}const Zx={name:"tasklistCheck",tokenize:ty};function ey(){return{text:{91:Zx}}}function ty(e,t,n){const r=this;return i;function i(l){return r.previous!==null||!r._gfmTasklistFirstContentOfListItem?n(l):(e.enter("taskListCheck"),e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),s)}function s(l){return fe(l)?(e.enter("taskListCheckValueUnchecked"),e.consume(l),e.exit("taskListCheckValueUnchecked"),o):l===88||l===120?(e.enter("taskListCheckValueChecked"),e.consume(l),e.exit("taskListCheckValueChecked"),o):n(l)}function o(l){return l===93?(e.enter("taskListCheckMarker"),e.consume(l),e.exit("taskListCheckMarker"),e.exit("taskListCheck"),a):n(l)}function a(l){return G(l)?t(l):ie(l)?e.check({tokenize:ny},t,n)(l):n(l)}}function ny(e,t,n){return oe(e,r,"whitespace");function r(i){return i===null?n(i):t(i)}}function ry(e){return Vo([Ax(),Ox(),Kx(e),Gx(),ey()])}const iy={};function sy(e){const t=this,n=e||iy,r=t.data(),i=r.micromarkExtensions||(r.micromarkExtensions=[]),s=r.fromMarkdownExtensions||(r.fromMarkdownExtensions=[]),o=r.toMarkdownExtensions||(r.toMarkdownExtensions=[]);i.push(ry(n)),s.push(vx()),o.push(Ex(n))}const oy=["md","txt","json","yaml","yml","toml","py","js","ts","tsx","jsx","css","scss","html","xml","sh","bash","go","rs","rb","php","java","kt","swift","c","cpp","h","hpp","sql","graphql","dockerfile","env","conf","cfg","ini","log","csv"],ay=oy.join("|"),ly="(?:~\\/[A-Za-z0-9._\\-\\/]*[A-Za-z0-9._\\-\\/]|\\/(?:[\\w.\\-]+\\/)*[\\w.\\-]+\\/?)",uy="(?:[A-Za-z0-9._\\-]+(?:\\/[A-Za-z0-9._\\-]+)+\\/?)",cy=`(?:[A-Za-z0-9_-][A-Za-z0-9._-]*[A-Za-z0-9_-]\\.(?:${ay})|dockerfile)`,$n=new RegExp(`(^|[\\s"'(,;:])(${ly}|${uy}|${cy})(?=$|[\\s"'),;:!?])`,"gi");function fy(e){if(!e)return{path:e??"",trailing:""};const t=e.match(/^(.*?)([),.;:!?]+)?$/);return t?{path:t[1]||e,trailing:t[2]||""}:{path:e,trailing:""}}function hy(e){if(!e)return!1;$n.lastIndex=0;const t=$n.exec(e);if(!t)return!1;const n=t[1]||"",r=t[2]||"",i=t.index+n.length,s=i+r.length;return i===0&&s===e.length}function py(e){if(!e)return[{type:"text",value:e}];const t=[];let n=0;$n.lastIndex=0;let r;for(;(r=$n.exec(e))!==null;){const i=r[1]||"",s=r[2]||"",o=r[0],a=r.index,l=a,u=a+i.length;l>n&&t.push({type:"text",value:e.slice(n,l)}),i&&t.push({type:"text",value:i});const{path:c,trailing:f}=fy(s);c.length>1?(t.push({type:"path",value:c}),f&&t.push({type:"text",value:f})):t.push({type:"text",value:o}),n=u+s.length}return n<e.length&&t.push({type:"text",value:e.slice(n)}),t.length>0?t:[{type:"text",value:e}]}function dy(e){return`openclaw-file://${encodeURIComponent(e)}`}function Fa(e){if(!e?.startsWith("openclaw-file://"))return null;try{return decodeURIComponent(e.slice(16))}catch{return null}}function my(){return e=>{function t(n,r){if(n){if(n.type==="text"&&r&&r.type!=="link"&&r.type!=="inlineCode"&&r.type!=="code"){const i=py(String(n.value||""));if(!i.some(l=>l.type==="path"))return;const o=i.map(l=>l.type==="text"?{type:"text",value:l.value}:{type:"link",url:dy(l.value),children:[{type:"text",value:l.value}]}),a=r.children.indexOf(n);a>=0&&r.children.splice(a,1,...o);return}if(Array.isArray(n.children))for(const i of[...n.children])t(i,n)}}t(e,null)}}const gy={py:"python",ts:"typescript",js:"javascript",jsx:"jsx",tsx:"tsx",json:"json",md:"markdown",yml:"yaml",yaml:"yaml",sh:"bash",bash:"bash",zsh:"bash",html:"html",css:"css",sql:"sql",xml:"xml",toml:"toml",rs:"rust",go:"go",java:"java",c:"c",cpp:"cpp",cs:"csharp",php:"php",rb:"ruby",graphql:"graphql",diff:"diff",patch:"diff",env:"text"};function xy(e){if(!e)return"text";const n=(e.split("/").pop()||"").toLowerCase();if(n==="dockerfile")return"dockerfile";if(n==="makefile")return"text";const r=n.split("."),i=r.length>1&&r.pop()||"",s=gy[i]||i||"text";return pu(s)}const yy=100*1024;function $a(e){return e?e.includes("/")?e:`/${e}`:"/"}function Er(e){let t=$a(e);const n=["/root/clawd/","/root/"];for(const r of n)if(t.startsWith(r)){t="/"+t.slice(r.length);break}return t.startsWith("/")?t:`/${t}`}function by(e){const n=e.replace(/\/+$/,"").split("/").pop()||"";return!n||n.startsWith(".")?!1:n.includes(".")}function ky(e){return e?e.endsWith("/")||!by(e):!1}function wy(e,t){const n=String(e||"").toUpperCase(),r=String(t||"").toLowerCase();return n.includes("DIRECTORY")||r.includes("is a directory")||r.includes("directory")}function Sy(e){return ce.lexer(e).map(n=>n.raw)}function Ba(e){if(!e)return"text";const t=e.match(/language-([\w-]+)/);return t?t[1]:"text"}function Ha(e){const t=e?.trim();return t&&t.split(/\s+/)[0]||void 0}const Cy={code:function({className:t,children:n,node:r}){if(!t?.includes("language-"))return h.jsx("code",{className:"rounded bg-primary-100 px-1.5 py-1 text-sm font-mono text-primary-900 border border-primary-200",children:n});const s=Ba(t),o=Ha(r?.data?.meta);return h.jsx(ei,{content:String(n??""),language:s,filename:o,className:"w-full"})},pre:function({children:t}){return h.jsx(h.Fragment,{children:t})},h1:function({children:t}){return h.jsx("h1",{className:"text-xl font-medium text-primary-950",children:t})},h2:function({children:t}){return h.jsx("h2",{className:"text-lg font-medium text-primary-900",children:t})},h3:function({children:t}){return h.jsx("h3",{className:"font-medium text-primary-900",children:t})},p:function({children:t}){return h.jsx("p",{className:"text-primary-950 text-pretty leading-relaxed",children:t})},ul:function({children:t}){return h.jsx("ul",{className:"ml-4 list-disc text-primary-950 marker:text-primary-400",children:t})},ol:function({children:t}){return h.jsx("ol",{className:"ml-4 list-decimal text-primary-950 marker:text-primary-500",children:t})},li:function({children:t}){return h.jsx("li",{className:"leading-relaxed",children:t})},blockquote:function({children:t}){return h.jsx("blockquote",{className:"border-l-2 border-primary-300 pl-4 text-primary-900 italic",children:t})},strong:function({children:t}){return h.jsx("strong",{className:"font-medium text-primary-950",children:t})},em:function({children:t}){return h.jsx("em",{className:"italic text-primary-950",children:t})},hr:function(){return h.jsx("hr",{className:"my-3 border-primary-200"})},table:function({children:t}){return h.jsx("div",{className:"overflow-x-auto",children:h.jsx("table",{className:"w-full border-collapse text-sm",children:t})})},thead:function({children:t}){return h.jsx("thead",{className:"border-b border-primary-200 bg-primary-50",children:t})},tbody:function({children:t}){return h.jsx("tbody",{className:"divide-y divide-primary-100",children:t})},tr:function({children:t}){return h.jsx("tr",{className:"transition-colors hover:bg-primary-50/50",children:t})},th:function({children:t}){return h.jsx("th",{className:"px-3 py-2 text-left font-medium text-primary-950",children:t})},td:function({children:t}){return h.jsx("td",{className:"px-3 py-2 text-primary-950",children:t})}};function vy(e){return{...Cy,a:function({children:n,href:r}){const i=Fa(r);return i?h.jsx("button",{type:"button",onClick:()=>e(i),className:"font-mono text-primary-900 underline decoration-primary-300 underline-offset-4 hover:decoration-primary-600 cursor-pointer",children:n}):h.jsx("a",{href:r,onClick:s=>{r?.startsWith("openclaw-file://")&&s.preventDefault()},className:"text-primary-950 underline decoration-primary-300 underline-offset-4 transition-colors hover:text-primary-950 hover:decoration-primary-500",target:"_blank",rel:"noopener noreferrer",children:n})},code:function({children:n,className:r,node:i}){if(r?.includes("language-")){const o=Ba(r),a=Ha(i?.data?.meta);return h.jsx(ei,{content:String(n??""),language:o,filename:a,className:"w-full"})}const s=typeof n=="string"?n:Array.isArray(n)?n.filter(o=>typeof o=="string").join(""):String(n??"");return s&&hy(s)?h.jsx("button",{type:"button",onClick:()=>e(s),className:"font-mono text-sm bg-primary-100 rounded px-1.5 py-0.5 text-primary-900 underline decoration-primary-300 underline-offset-4 hover:decoration-primary-600 cursor-pointer",children:n}):h.jsx("code",{className:"font-mono text-sm bg-primary-100 rounded px-1.5 py-0.5 text-primary-900",children:n})}}}const Ua=m.memo(function({content:t,components:n}){return h.jsx(qm,{remarkPlugins:[sy,tg,my],components:n,children:t})},function(t,n){return t.content===n.content});Ua.displayName="MemoizedMarkdownBlock";function Ey(e,t){return t==="NOT_FOUND"||e===404?"File not found":t==="UNSUPPORTED_TYPE"?"Binary file":t==="FILE_TOO_LARGE"||e===413?"File too large":"Failed to load file preview"}function Ty({children:e,id:t,className:n,components:r}){const i=m.useId(),s=t??i,o=m.useMemo(()=>Sy(e),[e]),[a,l]=m.useState({status:"idle"}),u=Vr(),c=m.useCallback(x=>{const w=Er(x);nr.getState().navigateTo(w),l({status:"idle"}),u({to:"/files"})},[u]),f=m.useCallback(x=>{const w=$a(x);if(ky(w)){c(w);return}l({status:"loading",path:w})},[c]),p=m.useMemo(()=>vy(f),[f]),d=m.useMemo(()=>({...p,...r||{}}),[p,r]);m.useEffect(()=>{if(a.status!=="loading")return;const x=a.path,w=new AbortController;return fetch(`/api/files/read?path=${encodeURIComponent(x)}`,{signal:w.signal}).then(async b=>{const S=await b.json().catch(()=>({}));if(!b.ok){if(wy(S.code,S.message)){c(x);return}const M=Ey(b.status,S.code);l({status:"error",path:x,message:M});return}if(Number(S.size??0)>yy){l({status:"error",path:x,message:"File too large"});return}const R=String(S.content??"");l({status:"success",path:x,content:R,language:xy(x)})}).catch(()=>{w.signal.aborted||l({status:"error",path:x,message:"Failed to load file preview"})}),()=>w.abort()},[a,c]);const g=a.status!=="idle";return h.jsxs(h.Fragment,{children:[h.jsx("div",{className:q("flex min-w-0 max-w-full flex-col gap-2 overflow-x-hidden",n),onClickCapture:x=>{const b=x.target?.closest?.('a[href^="openclaw-file://"]');if(!b)return;const S=Fa(b.getAttribute("href")??void 0);S&&(x.preventDefault(),x.stopPropagation(),f(S))},children:o.map((x,w)=>h.jsx(Ua,{content:x,components:d},`${s}-block-${w}`))}),h.jsx(ao,{open:g,onOpenChange:x=>{x||l({status:"idle"})},children:h.jsxs(lo,{className:"w-[min(1000px,95vw)] max-h-[88vh] overflow-hidden p-0",children:[h.jsxs("div",{className:"border-b border-primary-200 px-4 py-3 flex items-start justify-between gap-3",children:[h.jsxs("div",{className:"min-w-0",children:[h.jsx(uo,{className:"text-base",children:"File Preview"}),a.status!=="idle"&&h.jsx("p",{className:"text-xs text-primary-600 font-mono truncate",children:a.path})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[a.status!=="idle"&&h.jsx(Ce,{variant:"ghost",size:"sm",asChild:!0,children:h.jsx(Rt,{to:"/files",onClick:()=>{const x=a.status!=="idle"?Er(a.path):"";if(x){const w=x.includes("/")&&x.slice(0,x.lastIndexOf("/"))||"/";nr.getState().navigateTo(w)}l({status:"idle"})},children:"Open in Explorer"})}),a.status!=="idle"&&h.jsx(Ce,{variant:"ghost",size:"sm",asChild:!0,children:h.jsx(Rt,{to:"/files",onClick:()=>{const x=a.status!=="idle"?Er(a.path):"";x&&nr.getState().openInEditor(x),l({status:"idle"})},children:"Open in Editor"})}),h.jsx(co,{children:"Close"})]})]}),h.jsxs("div",{className:"p-4 overflow-auto max-h-[calc(88vh-72px)]",children:[a.status==="loading"&&h.jsx("p",{className:"text-sm text-primary-600",children:"Loading preview…"}),a.status==="error"&&h.jsx("p",{className:"text-sm text-red-600",children:a.message}),a.status==="success"&&h.jsx(ei,{content:a.content,language:a.language,className:"w-full"})]})]})})]})}const qa=m.memo(Ty);qa.displayName="Markdown";function Wa({children:e,className:t,...n}){return h.jsx("div",{className:q("flex gap-3 w-full",t),...n,children:e})}function jy({children:e,markdown:t=!1,className:n,...r}){const i=q("rounded-[12px] break-words whitespace-normal min-w-0 max-w-full overflow-x-hidden",n);return t?h.jsx(qa,{className:i,...r,children:e}):h.jsx("div",{className:i,...r,children:e})}function Ay(){const[e,t]=m.useState(()=>typeof window<"u"?window.innerWidth<768:!1);return m.useEffect(()=>{if(typeof window>"u")return;const n=window.matchMedia("(max-width: 767px)"),r=i=>t(i.matches);return n.addEventListener("change",r),t(n.matches),()=>n.removeEventListener("change",r)},[]),e}function Iy({content:e}){const t=Ay();return h.jsx("div",{className:"inline-flex flex-col",children:h.jsxs(jn,{defaultOpen:!t,children:[h.jsxs(An,{render:h.jsx(Ce,{variant:"ghost",className:"h-auto gap-1.5 px-1.5 py-0.5 -mx-2"}),children:[h.jsx("span",{className:"text-sm font-medium text-primary-900",children:"Thinking"}),h.jsx(ee,{icon:Jr,size:14,strokeWidth:1.5,className:"text-primary-900 transition-transform duration-150 group-data-panel-open:rotate-180"})]}),h.jsx(In,{children:h.jsx("div",{className:"pt-1 mb-3",children:h.jsx("p",{className:"text-sm text-primary-700 whitespace-pre-wrap",children:e})})})]})})}function Ry({toolPart:e,defaultOpen:t=!1}){const{state:n,input:r,output:i,toolCallId:s}=e,o=(u,c=3200)=>{const f=u===void 0?"undefined":u;let p;if(typeof f=="string")try{p=JSON.stringify(JSON.parse(f),null,2)}catch{p=f}else p=JSON.stringify(f,null,2);return p.length<=c?p:`${p.slice(0,c).trimEnd()}
|
|
92
|
+
…[truncated]`},a=n==="output-error"?Hn:n==="output-available"?to:oo,l=n==="output-error"?"text-red-600/80":n==="output-available"?"text-green-600/80":"text-primary-500/80";return h.jsx("div",{className:"inline-flex flex-col w-full",children:h.jsxs(jn,{defaultOpen:t,children:[h.jsxs(An,{render:h.jsx(Ce,{variant:"ghost",className:"h-auto w-full justify-start gap-1.5 rounded-md px-1.5 py-1"}),children:[h.jsx(ee,{icon:a,size:12,strokeWidth:1.7,className:l}),h.jsx("span",{className:"text-sm font-medium text-primary-900",children:e.type}),h.jsx(ee,{icon:Jr,size:14,strokeWidth:1.5,className:"ml-auto text-primary-700/80 transition-transform duration-150 group-data-panel-open:rotate-180"})]}),h.jsx(In,{className:"mt-1",children:h.jsxs("div",{className:"space-y-2 rounded-md border border-primary-200 bg-primary-100/70 p-2",children:[h.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[h.jsx("div",{className:"text-[11px] font-medium text-primary-600",children:"Tool"}),h.jsx("div",{className:"font-mono text-xs text-primary-800 break-all",children:e.type})]}),r&&Object.keys(r).length>0&&h.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[h.jsx("h4",{className:"mb-1 text-[11px] font-medium text-primary-600",children:"Input"}),h.jsx("pre",{className:"max-h-44 overflow-auto whitespace-pre-wrap break-all font-mono text-xs leading-relaxed text-primary-800",children:o(r)})]}),i!=null&&h.jsxs("div",{className:"rounded border border-primary-200 bg-primary-50 px-2 py-1.5",children:[h.jsx("h4",{className:"mb-1 text-[11px] font-medium text-primary-600",children:"Output"}),h.jsx("pre",{className:"max-h-44 overflow-auto whitespace-pre-wrap break-all font-mono text-xs leading-relaxed text-primary-800",children:o(i)})]}),n==="output-error"&&e.errorText&&h.jsxs("div",{className:"rounded border border-red-200 bg-red-50 px-2 py-1.5",children:[h.jsx("h4",{className:"mb-1 text-[11px] font-medium text-red-600",children:"Error"}),h.jsx("div",{className:"text-xs text-red-700",children:e.errorText})]}),s&&h.jsxs("div",{className:"text-[11px] text-primary-500/80 font-mono tabular-nums",children:["ID: ",s.slice(0,16),"..."]})]})})]})})}function Os(e){try{return new URL(e).hostname.replace("www.","")}catch{return e}}function Fs({domain:e}){return h.jsx("div",{className:"flex items-center justify-center w-5 h-5 rounded-full bg-white dark:bg-zinc-800 border border-cyan-500/20 overflow-hidden",title:e,children:h.jsx("img",{src:`https://www.google.com/s2/favicons?domain=${e}&sz=32`,alt:"",className:"w-4 h-4 object-contain",loading:"lazy",onError:t=>{const n=t.target;n.style.display="none";const r=n.parentElement;r&&(r.textContent=e.charAt(0).toUpperCase(),r.classList.add("text-[10px]","font-medium","text-cyan-400"))}})})}function Ny({sources:e}){const[t,n]=m.useState(!1);if(!e.length)return null;const r=[...new Set(e.map(i=>Os(i.url)))];return h.jsxs("div",{className:"mt-2 w-full",children:[h.jsxs("button",{onClick:()=>n(!t),className:q("inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-xs","bg-cyan-500/10 hover:bg-cyan-500/20 border border-cyan-500/30","text-cyan-300 transition-colors"),children:[h.jsx(ee,{icon:io,size:14}),h.jsx("span",{className:"font-medium",children:"Sources"}),h.jsx("span",{className:"px-1.5 py-0.5 rounded-full bg-cyan-500/20 text-cyan-400 font-semibold",children:e.length}),h.jsxs("div",{className:"flex items-center gap-0.5 ml-1",children:[r.slice(0,3).map(i=>h.jsx(Fs,{domain:i},i)),r.length>3&&h.jsxs("span",{className:"text-cyan-500/70 text-[10px] ml-0.5",children:["+",r.length-3]})]}),h.jsx(ee,{icon:Gr,size:12,className:q("transition-transform",t&&"rotate-90")})]}),t&&h.jsx("div",{className:"mt-2 rounded-lg border border-cyan-500/20 bg-cyan-500/5 max-h-80 overflow-y-auto",children:e.map((i,s)=>{const o=Os(i.url);return h.jsxs("a",{href:i.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-start gap-2 p-2.5 border-b border-cyan-500/10 last:border-b-0 hover:bg-cyan-500/5 transition-colors",children:[h.jsx(Fs,{domain:o}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"text-sm font-medium text-primary-900 hover:underline line-clamp-1",children:i.title||o}),h.jsx("div",{className:"text-xs text-muted-foreground",children:o}),i.snippet&&h.jsx("p",{className:"text-xs text-muted-foreground/80 line-clamp-2 mt-0.5",children:i.snippet})]})]},`${i.url}-${s}`)})})]})}function Ly(e,t){const n=t!==void 0,r=t?.isError??!1;let i;n?r?i="output-error":i="output-available":i="input-available";let s;r&&t?.content?.[0]?.type==="text"&&(s=t.content[0].text||"Unknown error");const o=t?.content?.map(l=>l.type==="text"?String(l.text??""):"").join("").trim(),a=t?.details??(o&&o.length>0?o:void 0);return{type:e.name||"unknown",state:i,input:e.arguments,output:a,toolCallId:e.id,errorText:s}}function $s(e){return Nt(e).map(n=>{const r=n.id??"",i=n.name??"",s=n.partialJson??"",o=n.arguments?JSON.stringify(n.arguments):"";return`${r}|${i}|${s}|${o}`}).join("||")}function My(e){if(!e)return"missing";const n=(Array.isArray(e.content)?e.content:[]).map(i=>i.type==="text"?String(i.text??""):"").join("").trim(),r=e.details?JSON.stringify(e.details):"";return`${e.toolCallId??""}|${e.toolName??""}|${e.isError?"1":"0"}|${n}|${r}`}function Bs(e,t){if(!t)return"";const n=Nt(e);return n.length===0?"":n.map(r=>r.id?My(t.get(r.id)):"missing").join("||")}function Dy(e){if(typeof e=="number"&&Number.isFinite(e))return e<1e12?e*1e3:e;if(typeof e=="string"){const t=Date.parse(e);if(!Number.isNaN(t))return t}return null}function Hs(e){const t=[e.createdAt,e.created_at,e.timestamp,e.time,e.ts];for(const n of t){const r=Dy(n);if(r)return r}return null}function Wr(e){const n=(Array.isArray(e.content)?e.content:[]).find(r=>r.type==="thinking");return n&&"thinking"in n?String(n.thinking??""):null}function Py(e){const t=Array.isArray(e.content)?e.content:[],n=[];for(const r of t)r.type==="image"&&"source"in r&&typeof r.source?.data=="string"&&n.push(r);return n}function zy({message:e,toolResultsByCallId:t,forceActionsVisible:n=!1,isStreaming:r=!1,isLastAssistant:i=!1,aggregatedSearchSources:s,wrapperRef:o,wrapperClassName:a,wrapperScrollMarginTop:l}){const{settings:u}=du(),c=e.role||"assistant",f=et(e),p=Wr(e),d=Py(e),g=c==="user",x=Nr(e),w=c==="assistant"?Nt(e):[],b=w.length>0,S=i&&!r&&u.showSearchSources&&s?s:[];return h.jsxs("div",{ref:o,style:{contentVisibility:"auto",containIntrinsicSize:"auto 120px",...typeof l=="number"?{scrollMarginTop:`${l}px`}:void 0},className:q("group flex flex-col gap-1",a,g?"items-end":"items-start"),children:[p&&u.showReasoningBlocks&&h.jsx("div",{className:"w-full max-w-[900px]",children:h.jsx(Iy,{content:p})}),d.length>0&&h.jsx("div",{className:q("flex flex-wrap gap-2 mb-2",g?"justify-end":"justify-start"),children:d.map((v,R)=>h.jsx("img",{src:`data:${v.source.media_type};base64,${v.source.data}`,alt:`Attachment ${R+1}`,loading:"lazy",decoding:"async",className:"max-w-[300px] max-h-[300px] rounded-lg object-cover"},R))}),h.jsx(Wa,{className:q("min-w-0 max-w-full",g?"flex-row-reverse":""),children:h.jsx(jy,{markdown:!g,className:q("text-primary-900 opencami-text-size min-w-0 max-w-full",g?"bg-primary-100 px-4 py-2.5 max-w-[85%]":"bg-transparent w-full",!g&&r&&"stream-fade-in"),children:f})}),b&&u.showToolMessages&&h.jsx("div",{className:"mt-2 flex w-full min-w-0 max-w-[900px] flex-col gap-3 overflow-x-hidden",children:w.map(v=>{const R=v.id?t?.get(v.id):void 0,M=Ly(v,R);return h.jsx(Ry,{toolPart:M,defaultOpen:!1},v.id||v.name)})}),S.length>0&&h.jsx("div",{className:"w-full max-w-[900px]",children:h.jsx(Ny,{sources:S})}),!b&&h.jsx(cf,{text:f,timestamp:x,align:g?"end":"start",forceVisible:n})]})}function _y(e,t){return!(e.forceActionsVisible!==t.forceActionsVisible||e.isStreaming!==t.isStreaming||e.isLastAssistant!==t.isLastAssistant||e.aggregatedSearchSources!==t.aggregatedSearchSources||e.wrapperClassName!==t.wrapperClassName||e.wrapperRef!==t.wrapperRef||e.wrapperScrollMarginTop!==t.wrapperScrollMarginTop||(e.message.role||"assistant")!==(t.message.role||"assistant")||et(e.message)!==et(t.message)||Wr(e.message)!==Wr(t.message)||$s(e.message)!==$s(t.message)||Bs(e.message,e.toolResultsByCallId)!==Bs(t.message,t.toolResultsByCallId)||Hs(e.message)!==Hs(t.message))}const Tr=m.memo(zy,_y),Oy=[/```[\s\S]*?```/g,/`[^`]+`/g,/\b(function|const|let|var|class|import|export|return|async|await)\b/g];function Fy(e){const t=[],n=e.match(/"([^"]+)"|'([^']+)'/g);n&&t.push(...n.map(s=>s.replace(/['"]/g,"")));const r=e.match(/\b[A-Z][a-z]+(?:\s+[A-Z][a-z]+)*\b/g);r&&t.push(...r.filter(s=>!["I","The","A","An","This"].includes(s)));const i=e.match(/`([^`]+)`/g);return i&&t.push(...i.map(s=>s.replace(/`/g,""))),[...new Set(t)].slice(0,5)}function $y(e){return Oy.some(t=>t.test(e))}function By(e){return/^[\s]*[-*•\d]+[.)\s]/m.test(e)||/\b(first|second|third|1\.|2\.|3\.)/i.test(e)}function Hy(e){return/\b(alternatively|another|other option|could also|you might|consider)\b/i.test(e)}function Uy(e){return/\b(because|since|due to|reason|why|how|what|when|where)\b/i.test(e)}function qy(e){return/\b(however|but|note|warning|caution|careful|important|keep in mind|be aware)\b/i.test(e)}function Wy(e){const t=[],n=Fy(e);if($y(e)&&(t.push({text:"Can you explain this code step by step?",type:"clarify"}),t.push({text:"How would I modify this for my use case?",type:"actionable"})),By(e)&&(t.push({text:"Can you elaborate on the first point?",type:"expand"}),t.push({text:"Which of these is most important to start with?",type:"actionable"})),Hy(e)&&(t.push({text:"What are the pros and cons of each approach?",type:"alternative"}),t.push({text:"Which option would you recommend and why?",type:"clarify"})),Uy(e)&&t.length<3&&t.push({text:"Can you give me a practical example?",type:"example"}),qy(e)&&t.length<3&&t.push({text:"What potential issues should I watch out for?",type:"clarify"}),n.length>0&&t.length<3){const s=n[0];t.push({text:`Tell me more about ${s}`,type:"expand"})}const r=[{text:"Can you give me a concrete example?",type:"example"},{text:"What would be the next steps?",type:"actionable"},{text:"How does this work in practice?",type:"expand"},{text:"Are there any common mistakes to avoid?",type:"clarify"},{text:"Can you simplify this explanation?",type:"clarify"}],i=new Set(t.map(s=>s.type));for(const s of r){if(t.length>=3)break;i.has(s.type)||(t.push(s),i.add(s.type))}for(const s of r){if(t.length>=3)break;t.some(o=>o.text===s.text)||t.push(s)}return t.slice(0,3)}function Us(e){return Wy(e).map(t=>t.text)}const Ky={openai:{baseUrl:"https://api.openai.com/v1",model:"gpt-4.1-nano"},openrouter:{baseUrl:"https://openrouter.ai/api/v1",model:"openai/gpt-oss-120b"},ollama:{baseUrl:"http://localhost:11434/v1",model:"llama3.2"},custom:{baseUrl:"",model:""}},vn={useLlmTitles:!0,useLlmFollowUps:!0,llmProvider:"openai",llmBaseUrl:"",llmModel:"",llmApiKey:""};function Ka(e){return Ky[e]}function Xy(e){return e.llmBaseUrl.trim()?e.llmBaseUrl.trim():Ka(e.llmProvider).baseUrl}function Vy(e){return e.llmModel.trim()?e.llmModel.trim():Ka(e.llmProvider).model}function qs(e,t){return e.llmProvider==="ollama"?!0:e.llmProvider==="custom"?!!e.llmApiKey.trim()||e.llmBaseUrl.trim()&&e.llmModel.trim():t||!!e.llmApiKey.trim()}function Yy(e){if(!e||typeof e!="object")return{settings:vn};const{settings:t}=e;if(!t)return{settings:vn};const{openaiApiKey:n,...r}=t,i=r.llmApiKey??n??"";return{settings:{...vn,...r,llmApiKey:i}}}const Lt=mo()(po(e=>({settings:{...vn},updateSettings:t=>e(n=>({settings:{...n.settings,...t}})),clearApiKey:()=>e(t=>({settings:{...t.settings,llmApiKey:""}}))}),{name:"llm-settings",version:2,migrate:e=>Yy(e)}));function b0(){const e=Lt(o=>o.settings),t=Lt(o=>o.updateSettings),n=Lt(o=>o.clearApiKey),[r,i]=m.useState({hasEnvKey:!1,hasOpenRouterKey:!1,hasUserKey:!!e.llmApiKey,isAvailable:qs(e,!1),isLoading:!0,error:null});m.useEffect(()=>{let o=!1;async function a(){try{const l=await fetch("/api/llm-features");if(!l.ok)throw new Error("Failed to check LLM status");const u=await l.json();if(o)return;const c=!!e.llmApiKey,f=e.llmProvider==="openrouter"?!!u.hasOpenRouterKey:u.hasEnvKey;i({hasEnvKey:u.hasEnvKey,hasOpenRouterKey:!!u.hasOpenRouterKey,hasUserKey:c,isAvailable:qs(e,f),isLoading:!1,error:null})}catch(l){if(o)return;i(u=>({...u,isLoading:!1,error:l instanceof Error?l.message:"Failed to check status"}))}}return a(),()=>{o=!0}},[e.llmApiKey,e.llmProvider,e.llmBaseUrl,e.llmModel]);const s=m.useCallback(async o=>{try{const a=Xa({...e,llmApiKey:o}),u=await(await fetch("/api/llm-features",{method:"POST",headers:{"Content-Type":"application/json",...a},body:JSON.stringify({action:"test"})})).json();return u.ok?{valid:u.valid??!1,error:u.error}:{valid:!1,error:u.error||"Test failed"}}catch(a){return{valid:!1,error:a instanceof Error?a.message:"Network error"}}},[e]);return{settings:e,updateSettings:t,clearApiKey:n,status:r,testApiKey:s}}function Xa(e){const t=e.llmApiKey,n=Xy(e),r=Vy(e);return t?{"X-OpenAI-API-Key":t,...n?{"X-LLM-Base-URL":n}:{},...r?{"X-LLM-Model":r}:{}}:{...n?{"X-LLM-Base-URL":n}:{},...r?{"X-LLM-Model":r}:{}}}function Va(){const e=Lt.getState().settings;return Xa(e)}async function Gy(e,t){const n={"Content-Type":"application/json",...Va()},r=await fetch("/api/llm-features",{method:"POST",headers:n,body:JSON.stringify({action:"followups",conversationContext:e}),signal:t});if(!r.ok)throw new Error(`API error: ${r.status}`);const i=await r.json();return i.ok&&Array.isArray(i.suggestions)&&i.suggestions.length>0?i.suggestions:[]}function Qy(e,t,n){const r=Lt(v=>v.settings),i=r.useLlmFollowUps,{minResponseLength:s=50,timeoutMs:o=8e3,heuristicsOnly:a}=n??{},l=a??!i,[u,c]=m.useState([]),[f,p]=m.useState(!1),[d,g]=m.useState(null),[x,w]=m.useState(null),b=m.useRef(""),S=m.useRef(null);return m.useEffect(()=>{if(!e||e.trim().length<s){c([]),w(null),p(!1),g(null);return}const v=e.slice(0,200)+e.length;if(v===b.current)return;if(b.current=v,S.current&&S.current.abort(),l){const P=Us(e);c(P),w("heuristic"),p(!1),g(null);return}const R=new AbortController;S.current=R,p(!0),g(null);const M=Us(e);c(M),w("heuristic");const C=t?`Context: ${t}
|
|
93
|
+
|
|
94
|
+
Assistant's response:
|
|
95
|
+
${e.slice(0,2e3)}`:`Assistant's response:
|
|
96
|
+
${e.slice(0,2e3)}`;return Gy(C,R.signal).then(P=>{R.signal.aborted||(P.length>0&&(c(P),w("llm")),p(!1))}).catch(P=>{R.signal.aborted||(g(P instanceof Error?P.message:String(P)),p(!1))}),()=>{}},[e,t,s,o,l,r.llmApiKey,r.llmBaseUrl,r.llmModel,r.llmProvider]),{suggestions:u,isLoading:f,error:d,source:x}}function Jy({responseText:e,contextSummary:t,onSuggestionClick:n,disabled:r=!1,className:i}){const{suggestions:s,isLoading:o,source:a}=Qy(e,t,{minResponseLength:50,timeoutMs:8e3});return s.length===0&&!o?null:h.jsxs("div",{className:q("flex flex-col gap-2 mt-3",i),children:[h.jsxs("div",{className:"flex items-center gap-1.5 text-xs text-primary-500",children:[h.jsx("span",{className:"text-primary-400",children:"✨"}),h.jsx("span",{children:o?h.jsxs("span",{className:"flex items-center gap-1",children:["Thinking of follow-ups",h.jsx(ee,{icon:oo,size:12,strokeWidth:2,className:"animate-spin text-primary-400"})]}):a==="llm"?"AI suggestions":"Follow-up suggestions"})]}),h.jsx("div",{className:"flex flex-wrap gap-2",children:s.map((l,u)=>h.jsxs("button",{type:"button",disabled:r,onClick:()=>n(l),className:q("group inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full","text-sm text-primary-700 bg-primary-50 border border-primary-200","hover:bg-primary-100 hover:border-primary-300 hover:text-primary-900","focus:outline-none focus:ring-2 focus:ring-primary-500/20 focus:ring-offset-1","transition-all duration-150 cursor-pointer","disabled:opacity-50 disabled:cursor-not-allowed disabled:hover:bg-primary-50 disabled:hover:border-primary-200",o&&"opacity-75"),children:[h.jsx("span",{children:l}),h.jsx(ee,{icon:Gr,size:14,strokeWidth:2,className:"text-primary-400 group-hover:text-primary-600 group-hover:translate-x-0.5 transition-all duration-150"})]},`${u}-${l.slice(0,20)}`))})]})}const Ws=m.memo(Jy);function Zy({className:e,variant:t="outline",scrollRef:n,...r}){const[i,s]=m.useState(!0),[o,a]=m.useState(!1),l=m.useRef(0),u=m.useCallback(()=>{const c=n.current;if(!c)return;const f=Math.abs(c.scrollHeight-c.scrollTop-c.clientHeight)<100;s(f)},[n]);return m.useLayoutEffect(()=>{const c=n.current;if(!c)return;const f=()=>{l.current=c.scrollTop,u()},p=new MutationObserver(()=>{c&&(c.scrollTop!==l.current&&(l.current=c.scrollTop),u())});return u(),c.addEventListener("scroll",f),p.observe(c,{childList:!0,subtree:!0}),()=>{c.removeEventListener("scroll",f),p.disconnect()}},[u,n]),m.useLayoutEffect(()=>{if(i){a(!1);return}const c=window.setTimeout(()=>{a(!0)},200);return()=>window.clearTimeout(c)},[i]),h.jsx(Ce,{variant:"secondary",size:"icon-sm",className:q("pointer-events-auto rounded-full shadow-md","transition-all duration-100 ease-in-out",!i&&o?"translate-y-0 scale-100 opacity-100":"pointer-events-none translate-y-4 scale-98 opacity-0",e),onClick:()=>{const c=n.current;c&&(c.scrollTop=c.scrollHeight,s(!0))},...r,children:h.jsx(ee,{icon:Jr,size:18,strokeWidth:1.8})})}function eb({className:e,viewportRef:t,scrollRef:n,viewportProps:r}){return h.jsxs(Co,{className:q("relative flex flex-1 min-h-0 flex-col",e),children:[h.jsx(vo,{className:"relative will-change-transform overflow-x-hidden",ref:t,...r}),h.jsx("div",{className:"relative mx-auto w-full min-w-0 max-w-full px-5 sm:max-w-[768px]",children:h.jsx("div",{className:"pointer-events-none absolute bottom-10 right-10 z-50",children:h.jsx(Zy,{scrollRef:n})})}),h.jsx(Eo,{orientation:"vertical",children:h.jsx(To,{})}),h.jsx(kc,{})]})}function tb(e,t){if(e===t)return!0;const n=Object.keys(e),r=Object.keys(t);if(n.length!==r.length)return!1;for(const i of n)if(e[i]!==t[i])return!1;return!0}function nb(e,t){return!(e.className!==t.className||e.viewportRef!==t.viewportRef||e.scrollRef!==t.scrollRef||!tb(e.viewportProps,t.viewportProps))}const rb=m.memo(eb,nb);function ib({viewportNode:e,children:t}){return e?dl.createPortal(h.jsx("div",{className:"relative flex w-full min-w-0 max-w-full flex-col overflow-x-hidden",children:t}),e):null}function sb({children:e,className:t,onUserScroll:n,...r}){const i=m.useRef(null),[s,o]=m.useState(null),a=m.useCallback(function(u){i.current=u,o(u)},[]);return m.useLayoutEffect(()=>{const l=i.current;if(!l)return;const u=()=>{n?.(l.scrollTop)};return l.addEventListener("scroll",u),()=>l.removeEventListener("scroll",u)},[n]),h.jsxs(h.Fragment,{children:[h.jsx(rb,{className:t,viewportRef:a,scrollRef:i,viewportProps:r}),h.jsx(ib,{viewportNode:s,children:e})]})}const ob=m.memo(sb);function ab({children:e,className:t,...n}){return h.jsx("div",{className:q("flex w-full min-w-0 max-w-full flex-col min-h-full overflow-x-hidden",t),...n,children:h.jsx("div",{className:"mx-auto w-full min-w-0 max-w-full px-2 md:px-5 sm:max-w-[768px] flex flex-col flex-1 min-h-full overflow-x-hidden",children:h.jsx("div",{className:"flex min-w-0 max-w-full flex-col space-y-3 md:space-y-6",children:e})})})}function lb({...e}){return h.jsx("div",{className:"h-px w-full shrink-0 scroll-mt-4 pt-6","aria-hidden":"true",...e})}function ub({as:e="span",className:t,duration:n=4,spread:r=20,children:i,...s}){const o=Math.min(Math.max(r,5),45),a=e;return h.jsx(a,{className:q("bg-size-[200%_auto] bg-clip-text font-medium text-transparent","animate-[shimmer_4s_infinite_linear]",t),style:{backgroundImage:`linear-gradient(to right, var(--color-primary-600) ${50-o}%, var(--color-primary-950) 50%, var(--color-primary-600) ${50+o}%)`,animationDuration:`${n}s`},...s,children:i})}function cb({className:e}){return h.jsxs("div",{className:q("flex items-center gap-2",e),children:[h.jsxs("div",{className:"relative flex h-1.5 w-1.5",children:[h.jsx("span",{className:"animate-ping absolute inline-flex h-full w-full rounded-full bg-primary-400 opacity-75"}),h.jsx("span",{className:"relative inline-flex rounded-full h-1.5 w-1.5 bg-size-[200%_auto] animate-[shimmer_2s_infinite_linear]",style:{backgroundImage:"linear-gradient(to right, var(--color-primary-600) 0%, var(--color-primary-950) 50%, var(--color-primary-600) 100%)"}})]}),h.jsx(ub,{className:"text-sm",duration:2,children:"Generating..."})]})}function fb({messages:e,loading:t,empty:n,emptyState:r,notice:i,noticePosition:s="start",waitingForResponse:o,isStreaming:a=!1,sessionKey:l,pinToTop:u,pinGroupMinHeight:c,headerHeight:f,contentStyle:p,onFollowUpClick:d}){const g=m.useRef(null),x=m.useRef(null),w=m.useRef(!1),b=m.useRef(u),S=m.useRef(void 0),v=m.useMemo(()=>e.filter(j=>j.role!=="toolResult"),[e]),R=m.useMemo(()=>{const j=new Map;for(const T of e){if(T.role!=="toolResult")continue;const D=T.toolCallId;typeof D=="string"&&D.trim().length>0&&j.set(D,T)}return j},[e]),M=m.useMemo(()=>{const j=H=>H?H.replace(/SECURITY NOTICE:[\s\S]*?<<<EXTERNAL_UNTRUSTED_CONTENT>>>/g,"").replace(/<<<\/?EXTERNAL_UNTRUSTED_CONTENT>>>/g,"").replace(/<<<\/?END_EXTERNAL_UNTRUSTED_CONTENT>>>/g,"").replace(/Source: Web (?:Search|Fetch)\n---/g,"").replace(/\n{2,}/g,`
|
|
97
|
+
`).trim():"",T=(H,_,y)=>{try{const X=JSON.parse(H),V=Array.isArray(X)?X:X?.results??X?.web?.results??[];if(!Array.isArray(V))return!1;let k=!1;for(const Q of V)Q?.url&&Q?.title&&!y.has(Q.url)&&(y.add(Q.url),_.push({title:j(Q.title),url:Q.url,snippet:j(Q.description||Q.snippet||Q.content||"")}),k=!0);return k}catch{return!1}},D=[],L=new Set;for(const H of v){if(H.role!=="assistant")continue;const _=Nt(H);for(const y of _){if(!y.id)continue;const X=y.name==="web_search",V=y.name==="web_fetch",k=y.name==="exec";if(!X&&!V&&!k)continue;const Q=R.get(y.id);if(!Q)continue;const re=Q.content?.map(W=>W.type==="text"?String(W.text??""):"").join("").trim();if(re){if(X||k){if(k&&(!re.includes('"results"')||!re.includes('"url"')))continue;let W=re;const he=re.indexOf("{");he>0&&(W=re.slice(he));const me=W.lastIndexOf("}");me>0&&(W=W.slice(0,me+1)),T(W,D,L)}else if(V){const W=y.arguments?.url;if(W&&!L.has(W)){L.add(W);let he;try{he=new URL(W).hostname}catch{he=W}D.push({title:he,url:W})}}}}}return D},[v,R]),C=v.map((j,T)=>({message:j,index:T})).filter(({message:j})=>j.role!=="user").map(({index:j})=>j).pop(),P=v.map((j,T)=>({message:j,index:T})).filter(({message:j})=>j.role==="user").map(({index:j})=>j).pop(),U=o&&(typeof P!="number"||typeof C!="number"||C<P),F=typeof P=="number"?P:-1,E=u&&F>=0,N=typeof C=="number"?v[C]:void 0,A=N?et(N):"",z=!o&&!a&&A.length>0&&d!==void 0&&(typeof P!="number"||typeof C!="number"||C>P);return m.useLayoutEffect(()=>{if(!t){if(u){const j=!b.current||S.current!==P;b.current=!0,S.current=P,j&&x.current&&(w.current=!0,x.current.scrollIntoView({behavior:"auto",block:"start"}),window.setTimeout(()=>{w.current=!1},0));return}b.current=!1,S.current=P,g.current&&(w.current=!0,g.current.scrollIntoView({behavior:"auto",block:"end"}),window.setTimeout(()=>{w.current=!1},0))}},[t,v.length,l,u,P]),h.jsx(ob,{className:"flex-1 min-h-0 -mb-4",children:h.jsxs(ab,{className:"pt-6",style:p,children:[i&&s==="start"?i:null,n&&!i?r??h.jsx("div",{"aria-hidden":!0}):E?h.jsxs(h.Fragment,{children:[v.slice(0,F).map((j,T)=>{const D=T,L=typeof C=="number"&&T===C,H=typeof C=="number"&&T===C,_=j.role==="assistant"&&Nt(j).length>0;return h.jsx(Tr,{message:j,toolResultsByCallId:_?R:void 0,forceActionsVisible:L,isStreaming:H&&a,isLastAssistant:H,aggregatedSearchSources:H?M:void 0},D)}),h.jsxs("div",{className:"flex flex-col space-y-3 md:space-y-6",style:{minHeight:`${Math.max(0,c-24)}px`},children:[v.slice(F).map((j,T)=>{const D=F+T,L=D,H=typeof C=="number"&&D===C,_=typeof C=="number"&&D===C,y=D===P?x:void 0,X=D===P?"scroll-mt-0":void 0,V=D===P?f:void 0,k=j.role==="assistant"&&Nt(j).length>0;return h.jsx(Tr,{message:j,toolResultsByCallId:k?R:void 0,forceActionsVisible:H,isStreaming:_&&a,isLastAssistant:_,aggregatedSearchSources:_?M:void 0,wrapperRef:y,wrapperClassName:X,wrapperScrollMarginTop:V},L)}),U?h.jsx("div",{className:"py-2",children:h.jsx(cb,{})}):null,z&&d?h.jsx(Ws,{responseText:A,onSuggestionClick:d,disabled:o}):null]})]}):h.jsxs(h.Fragment,{children:[v.map((j,T)=>{const D=T,L=typeof C=="number"&&T===C,H=typeof C=="number"&&T===C,_=j.role==="assistant"&&Nt(j).length>0;return h.jsx(Tr,{message:j,toolResultsByCallId:_?R:void 0,forceActionsVisible:L,isStreaming:H&&a,isLastAssistant:H,aggregatedSearchSources:H?M:void 0},D)}),z&&d?h.jsx(Ws,{responseText:A,onSuggestionClick:d,disabled:o}):null]}),i&&s==="end"?i:null,h.jsx(lb,{ref:g})]})})}function hb(e,t){return e.messages===t.messages&&e.loading===t.loading&&e.empty===t.empty&&e.emptyState===t.emptyState&&e.notice===t.notice&&e.noticePosition===t.noticePosition&&e.waitingForResponse===t.waitingForResponse&&e.isStreaming===t.isStreaming&&e.sessionKey===t.sessionKey&&e.pinToTop===t.pinToTop&&e.pinGroupMinHeight===t.pinGroupMinHeight&&e.headerHeight===t.headerHeight&&e.contentStyle===t.contentStyle&&e.onFollowUpClick===t.onFollowUpClick}const pb=m.memo(fb,hb),Ya=m.createContext({isLoading:!1,value:"",setValue:()=>{},maxHeight:240,onSubmit:void 0,disabled:!1,textareaRef:ml.createRef()});let Ut=null,Ks=!1;function db(){Ks||typeof window>"u"||(Ks=!0,window.addEventListener("keydown",e=>{if(e.defaultPrevented||e.metaKey||e.ctrlKey||e.altKey)return;const t=e.target;if(!t)return;const n=t.tagName.toLowerCase();if(n==="input"||n==="textarea"||n==="select"||t.isContentEditable)return;const r=e.key.length===1,i=e.key==="Backspace";!r&&!i||!Ut||Ut.disabled||Ut.focus()}))}function Ga(){return m.useContext(Ya)}function mb({className:e,isLoading:t=!1,maxHeight:n=240,value:r,onValueChange:i,onSubmit:s,children:o,disabled:a=!1,onClick:l,...u}){const[c,f]=m.useState(r||""),p=m.useRef(null);db();function d(x){f(x),i?.(x)}function g(x){a||p.current?.focus(),l?.(x)}return h.jsx(gt,{children:h.jsx(Ya.Provider,{value:{isLoading:t,value:r??c,setValue:i??d,maxHeight:n,onSubmit:s,disabled:a,textareaRef:p},children:h.jsx("div",{onClick:g,className:q("bg-surface cursor-text rounded-[22px] outline outline-ink/10 shadow-[0px_12px_32px_0px_rgba(0,0,0,0.05)] py-3 gap-3 flex flex-col",a&&"cursor-not-allowed opacity-60",e),...u,children:o})})})}function gb({className:e,onKeyDown:t,disableAutosize:n=!1,inputRef:r,...i}){const{value:s,setValue:o,maxHeight:a,onSubmit:l,disabled:u,textareaRef:c}=Ga();function f(x){!x||n||(x.style.height="auto",typeof a=="number"?x.style.height=`${Math.min(x.scrollHeight,a)}px`:x.style.height=`min(${x.scrollHeight}px, ${a})`)}function p(x){c.current=x,typeof r=="function"?r(x):r&&"current"in r&&(r.current=x),x?Ut=x:Ut===x&&(Ut=null),f(x)}m.useLayoutEffect(()=>{if(!c.current||n)return;const x=c.current;x.style.height="auto",typeof a=="number"?x.style.height=`${Math.min(x.scrollHeight,a)}px`:x.style.height=`min(${x.scrollHeight}px, ${a})`},[s,a,n]);function d(x){f(x.target),o(x.target.value)}function g(x){x.key==="Enter"&&!x.shiftKey&&(x.preventDefault(),l?.()),t?.(x)}return h.jsx("textarea",{ref:p,value:s,onChange:d,onKeyDown:g,className:q("text-primary-950 opencami-text-size min-h-[28px] w-full resize-none border-none bg-transparent shadow-none outline-none focus-visible:ring-0 pl-4 pr-1 placeholder:text-primary-500",e),rows:1,readOnly:u,"aria-disabled":u,...i})}function xb({children:e,className:t,...n}){return h.jsx("div",{className:q("flex items-center gap-2",t),...n,children:e})}function jr({tooltip:e,children:t,className:n,side:r="top",...i}){const{disabled:s}=Ga();return h.jsxs(xt,{...i,children:[h.jsx(yt,{disabled:s,onClick:o=>o.stopPropagation(),children:t}),h.jsx(bt,{side:r,className:n,children:e})]})}const Qa="opencami-selected-model";function yb(){if(typeof window>"u")return null;try{return localStorage.getItem(Qa)}catch{return null}}function bb(e){if(!(typeof window>"u"))try{localStorage.setItem(Qa,e)}catch{}}function kb({className:e,onModelChange:t}){const[n,r]=m.useState([]),[i,s]=m.useState(""),[o,a]=m.useState(!0),[l,u]=m.useState(null),c=m.useRef(null);m.useEffect(()=>{let x=!0;async function w(){c.current?.abort();const b=new AbortController;c.current=b;try{a(!0),u(null);const S=await fetch("/api/models",{signal:b.signal});if(!S.ok)throw new Error("Failed to fetch models");const v=await S.json();if(!x)return;if(v.ok&&v.models.length>0){r(v.models);const R=yb(),M=R&&v.models.some(C=>C.id===R)?R:v.defaultModel;s(M),t?.(M)}else throw new Error("No models available")}catch(S){if(S instanceof Error&&S.name==="AbortError"||!x)return;console.error("[model-selector] Error fetching models:",S),u(S instanceof Error?S.message:"Failed to load models"),r([{id:"default",name:"Default Model"}]),s("default")}finally{x&&a(!1)}}return w(),()=>{x=!1,c.current?.abort()}},[t]);function f(x){s(x),bb(x),t?.(x)}if(o)return h.jsxs("div",{className:q("flex items-center gap-2 text-xs text-primary-500",e),children:[h.jsx(ee,{icon:tr,size:14}),h.jsx("span",{children:"Loading..."})]});if(l||n.length===0)return null;const p=n.find(x=>x.id===i),d=p?.name||"Select Model",g=(()=>{if(!p?.name)return d;const w=p.name.replace(/\s*\([^)]*\)\s*$/,"").trim(),b=w.split(/\s+/);return b.length>3?b.slice(0,3).join(" "):w})();return n.length===1?h.jsxs("div",{className:q("flex items-center gap-2 text-xs text-primary-500",e),children:[h.jsx(ee,{icon:tr,size:14}),h.jsx("span",{className:"font-[450] md:hidden",children:g}),h.jsx("span",{className:"font-[450] hidden md:inline",children:d})]}):h.jsxs(Un,{children:[h.jsxs(qn,{className:q("inline-flex h-7 items-center gap-2 rounded-md px-2 text-xs font-[450] text-primary-600 hover:text-primary-900 hover:bg-primary-100",e),children:[h.jsx(ee,{icon:tr,size:14}),h.jsx("span",{className:"md:hidden",children:g}),h.jsx("span",{className:"hidden md:inline",children:d})]}),h.jsx(Wn,{side:"top",align:"start",children:n.map(x=>h.jsxs(kt,{onClick:()=>f(x.id),className:"justify-between min-w-[180px]",children:[h.jsx("span",{children:x.name}),i===x.id&&h.jsx(ee,{icon:Qr,size:14,className:"text-primary-600"})]},x.id))})]})}const Ja="opencami-personas-enabled",Kr="opencami-active-persona";function wb(){if(typeof window>"u")return!0;try{const e=localStorage.getItem(Ja);return e===null?!0:e==="true"}catch{return!0}}function Sb(){if(typeof window>"u")return null;try{const e=localStorage.getItem(Kr);return e?JSON.parse(e):null}catch{return null}}function Xs(e){if(!(typeof window>"u"))try{e?localStorage.setItem(Kr,JSON.stringify(e)):localStorage.removeItem(Kr)}catch{}}const Cb={core:"Core",creative:"Creative",curator:"Curator",learning:"Learning",lifestyle:"Lifestyle",professional:"Professional"};function vb({className:e,onSelect:t}){const[n,r]=m.useState({}),[i,s]=m.useState(null),[o,a]=m.useState(!0),[l,u]=m.useState(!1),[c,f]=m.useState(wb),p=m.useRef(null);m.useEffect(()=>{const w=b=>{b.key===Ja&&f(b.newValue===null?!0:b.newValue==="true")};return window.addEventListener("storage",w),()=>window.removeEventListener("storage",w)},[]),m.useEffect(()=>{let w=!0;async function b(){p.current?.abort();const S=new AbortController;p.current=S;try{a(!0);const v=await fetch("/api/personas",{signal:S.signal});if(!v.ok){u(!1);return}const R=await v.json();if(!w)return;R.ok&&R.available?(r(R.personas),u(!0),s(Sb())):u(!1)}catch(v){if(v instanceof Error&&v.name==="AbortError"||!w)return;u(!1)}finally{w&&a(!1)}}return b(),()=>{w=!1,p.current?.abort()}},[]);const d=m.useCallback(w=>{s(w),Xs(w),t(`/persona ${w.id}`)},[t]),g=m.useCallback(()=>{s(null),Xs(null),t("/persona exit")},[t]);if(o||!l||!c)return null;const x=Object.entries(n);return x.length===0?null:h.jsxs(Un,{children:[h.jsxs(qn,{className:q("inline-flex h-7 items-center gap-1.5 rounded-md px-2 text-xs font-[450] text-primary-600 hover:text-primary-900 hover:bg-primary-100",e),children:[h.jsx("span",{className:"text-sm","aria-hidden":"true",children:"🎭"}),i?h.jsxs("span",{className:"flex items-center gap-1",children:[h.jsx("span",{children:i.emoji}),h.jsx("span",{children:i.name})]}):h.jsx("span",{children:"Persona"})]}),h.jsxs(Wn,{side:"top",align:"start",className:"w-[300px] max-h-[360px] overflow-y-auto",children:[i&&h.jsxs(h.Fragment,{children:[h.jsxs(kt,{onClick:g,className:"text-red-600 hover:bg-red-50",children:[h.jsx("span",{className:"text-sm",children:"✕"}),h.jsx("span",{children:"Exit Persona"}),h.jsxs("span",{className:"ml-auto text-[10px] text-primary-400",children:[i.emoji," ",i.name]})]}),h.jsx("div",{className:"my-1 h-px bg-primary-200"})]}),x.map(([w,b])=>h.jsxs("div",{children:[h.jsx("div",{className:"px-2 pb-0.5 pt-2 text-[10px] font-semibold uppercase tracking-wider text-primary-400",children:Cb[w]??w}),b.map(S=>h.jsxs(kt,{onClick:()=>d(S),className:"justify-between",children:[h.jsxs("span",{className:"flex items-center gap-2 min-w-0",children:[h.jsx("span",{className:"text-sm flex-shrink-0",children:S.emoji}),h.jsx("span",{className:"truncate",children:S.name})]}),h.jsx("span",{className:"text-[11px] text-primary-400 truncate ml-2 max-w-[140px]",children:S.description})]},S.id))]},w))]})]})}const Eb=[{command:"/new",description:"Start a new conversation",usage:"/new"},{command:"/reset",description:"Reset conversation context",usage:"/reset"},{command:"/abort",description:"Abort current generation",usage:"/abort"},{command:"/status",description:"Show session status card",usage:"/status"},{command:"/usage",description:"Show token usage",usage:"/usage [off|tokens|full]"},{command:"/models",description:"List available models",usage:"/models"},{command:"/agents",description:"List available agents",usage:"/agents"},{command:"/sessions",description:"List active sessions",usage:"/sessions"},{command:"/model",description:"Switch model for this session",usage:"/model <alias>"},{command:"/reasoning",description:"Toggle reasoning mode",usage:"/reasoning [on|off|stream]"},{command:"/think",description:"Set thinking budget",usage:"/think [off|minimal|low|medium|high]"},{command:"/verbose",description:"Toggle verbose output",usage:"/verbose [on|full|off]"},{command:"/tts",description:"Text-to-speech controls",usage:"/tts [status|off|always]"},{command:"/settings",description:"Show current settings",usage:"/settings"},{command:"/help",description:"Show help",usage:"/help"}];function Tb({className:e,onCommandSelect:t}){const[n,r]=m.useState(!1);function i(s){t?.(s),r(!1)}return h.jsxs(h.Fragment,{children:[h.jsx(Ce,{variant:"ghost",size:"sm",onClick:()=>r(!0),className:q("h-7 w-7 p-0",e),title:"Show commands (Ctrl+/)",children:h.jsx(ee,{icon:_i,size:16,className:"text-primary-500"})}),n&&h.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm",children:h.jsxs("div",{className:"bg-white dark:bg-neutral-900 border border-primary-200 dark:border-neutral-700 rounded-xl shadow-2xl w-full max-w-lg max-h-[80vh] overflow-hidden",children:[h.jsxs("div",{className:"flex items-center justify-between px-4 py-3 border-b border-primary-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(ee,{icon:_i,size:18,className:"text-primary-600 dark:text-primary-400"}),h.jsx("h2",{className:"font-semibold text-primary-900 dark:text-white",children:"Slash Commands"})]}),h.jsx(Ce,{variant:"ghost",size:"sm",onClick:()=>r(!1),className:"h-7 w-7 p-0",children:h.jsx(ee,{icon:Hn,size:16})})]}),h.jsxs("div",{className:"overflow-y-auto max-h-[60vh] p-2 bg-white dark:bg-neutral-900",children:[h.jsx("div",{className:"text-xs text-primary-500 dark:text-neutral-400 px-2 py-1 mb-2",children:"Type these commands in the chat input"}),Eb.map(s=>h.jsxs("button",{onClick:()=>i(s.command),className:"w-full flex items-start gap-3 px-3 py-2 rounded-lg hover:bg-primary-100 dark:hover:bg-neutral-800 transition-colors text-left",children:[h.jsx("code",{className:"text-sm font-mono font-medium text-primary-700 dark:text-primary-300 bg-primary-100 dark:bg-neutral-800 px-1.5 py-0.5 rounded min-w-[80px]",children:s.command}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsx("div",{className:"text-sm text-primary-900 dark:text-neutral-100",children:s.description}),s.usage&&s.usage!==s.command&&h.jsx("div",{className:"text-xs text-primary-500 dark:text-neutral-500 font-mono mt-0.5",children:s.usage})]})]},s.command))]}),h.jsx("div",{className:"px-4 py-2 border-t border-primary-200 dark:border-neutral-700 bg-neutral-50 dark:bg-neutral-800",children:h.jsxs("div",{className:"text-xs text-primary-500 dark:text-neutral-400",children:["Press ",h.jsx("kbd",{className:"px-1 py-0.5 bg-primary-200 dark:bg-neutral-700 rounded text-primary-700 dark:text-neutral-300",children:"Esc"})," to close"]})})]})})]})}const jb=10*1024*1024,Bt=1280,Ab=.75,Ib=300*1024,Rb=["image/png","image/jpeg","image/gif","image/webp"],Nb=".png,.jpg,.jpeg,.gif,.webp";function Lb(){if(typeof document>"u")return!1;try{const e=document.createElement("canvas");return!!(e.getContext&&e.getContext("2d"))}catch{return!1}}async function Mb(e){if(!Lb())throw new Error("Image compression not available in this browser");return new Promise((t,n)=>{const r=new Image,i=URL.createObjectURL(e),s=()=>{URL.revokeObjectURL(i)};r.onload=()=>{try{let o=r.width,a=r.height;(o>Bt||a>Bt)&&(o>a?(a=Math.round(a*Bt/o),o=Bt):(o=Math.round(o*Bt/a),a=Bt));const l=document.createElement("canvas");l.width=o,l.height=a;const u=l.getContext("2d");if(!u){s(),n(new Error("Failed to get canvas context"));return}u.drawImage(r,0,0,o,a);const c=e.type==="image/png"?"image/png":"image/jpeg";let f=Ab,p=l.toDataURL(c,f);if(c==="image/jpeg"){const g=Ib*1.37;for(;p.length>g&&f>.3;)f-=.1,p=l.toDataURL(c,f)}const d=p.split(",")[1];if(!d){s(),n(new Error("Failed to encode image"));return}s(),t(d)}catch(o){s(),n(o instanceof Error?o:new Error("Image compression failed"))}},r.onerror=()=>{s(),n(new Error("Failed to load image"))},r.src=i})}function Za(e){return Rb.includes(e.type)}async function el(e){const t=crypto.randomUUID();if(!Za(e))return{id:t,file:e,preview:null,type:"image",base64:null,error:"Unsupported file type. Please use PNG, JPG, GIF, or WebP images."};if(e.size>jb)return{id:t,file:e,preview:null,type:"image",base64:null,error:"Image is too large. Maximum size is 10MB."};try{const n=await Mb(e),r=URL.createObjectURL(e);return{id:t,file:e,preview:r,type:"image",base64:n}}catch(n){return{id:t,file:e,preview:null,type:"image",base64:null,error:n instanceof Error?n.message:"Failed to process image"}}}function Db({onFileSelect:e,disabled:t=!1,className:n}){const r=m.useRef(null),i=m.useCallback(()=>{r.current?.click()},[]),s=m.useCallback(async o=>{const a=o.target.files?.[0];if(!a)return;o.target.value="";const l=await el(a);e(l)},[e]);return h.jsxs(h.Fragment,{children:[h.jsx("input",{ref:r,type:"file",accept:Nb,onChange:s,className:"hidden","aria-hidden":"true"}),h.jsx(Ce,{variant:"ghost",size:"icon-sm",onClick:i,disabled:t,className:n,"aria-label":"Attach image",type:"button",children:h.jsx(ee,{icon:Wl,size:18,strokeWidth:1.8})})]})}function Pb(e){return e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function zb(e){const t=e.split(".");return t.length>1&&t.pop()?.toUpperCase()||""}function _b({attachment:e,onRemove:t,className:n}){m.useEffect(()=>()=>{e.preview&&URL.revokeObjectURL(e.preview)},[e.preview]);const r=!!e.error;return h.jsxs("div",{className:q("relative flex items-center gap-3 rounded-xl border p-2 pr-3",r?"border-red-300 bg-red-50":"border-primary-200 bg-primary-50",n),children:[h.jsx("div",{className:"relative shrink-0",children:e.type==="image"&&e.preview?h.jsx("img",{src:e.preview,alt:e.file.name,className:"h-12 w-12 rounded-lg object-cover"}):h.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-lg bg-primary-100",children:h.jsx(ee,{icon:Kl,size:24,className:"text-primary-500"})})}),h.jsxs("div",{className:"min-w-0 flex-1",children:[h.jsx("p",{className:"truncate text-sm font-medium text-primary-900",children:e.file.name}),r?h.jsx("p",{className:"text-xs text-red-600",children:e.error}):h.jsxs("p",{className:"text-xs text-primary-500",children:[zb(e.file.name)," •"," ",Pb(e.file.size)]})]}),h.jsx(Ce,{variant:"ghost",size:"icon-sm",onClick:()=>t(e.id),className:"h-6 w-6 shrink-0 rounded-full hover:bg-primary-200","aria-label":"Remove attachment",type:"button",children:h.jsx(ee,{icon:Hn,size:14})})]})}function Ob({attachments:e,onRemove:t,className:n}){return e.length===0?null:h.jsx("div",{className:q("flex flex-col gap-2 px-4",n),children:e.map(r=>h.jsx(_b,{attachment:r,onRemove:t},r.id))})}function Fb({commands:e,selectedIndex:t,onSelect:n,className:r}){return e.length===0?null:h.jsx("div",{className:q("absolute left-2 right-2 md:left-5 md:right-5 bottom-full mb-2 z-20 rounded-xl border border-white/10 bg-neutral-900/95 shadow-2xl backdrop-blur-sm overflow-hidden",r),role:"listbox","aria-label":"Slash commands",children:h.jsx("div",{className:"max-h-56 overflow-y-auto p-1",children:e.map((i,s)=>{const o=s===t;return h.jsx("button",{type:"button",role:"option","aria-selected":o,onMouseDown:a=>{a.preventDefault(),n(i)},className:q("w-full rounded-md px-3 py-2 text-left transition-colors",o?"bg-neutral-800":"hover:bg-neutral-800/80"),children:h.jsxs("div",{className:"flex items-start gap-3",children:[h.jsx("code",{className:"min-w-[90px] font-mono text-xs text-primary-300",children:i.command}),h.jsx("span",{className:"text-xs text-neutral-300",children:i.description})]})},i.command)})})})}const $b=m.memo(Fb),Xr=mo()(po(e=>({level:"low",setLevel:t=>e({level:t})}),{name:"thinking-level"}));function Bb(){const e=Xr(n=>n.level),t=Xr(n=>n.setLevel);return{level:e,setLevel:t}}const Ar=[{value:"off",label:"Off",description:"No reasoning",shortLabel:"Off"},{value:"low",label:"Low",description:"Think",shortLabel:"Low"},{value:"medium",label:"Medium",description:"Think harder",shortLabel:"Medium"},{value:"high",label:"High",description:"Ultrathink",shortLabel:"High"}];function Hb({className:e}){const{level:t,setLevel:n}=Bb(),r=Ar.find(i=>i.value===t)??Ar[1];return h.jsxs(Un,{children:[h.jsxs(qn,{className:q("inline-flex h-7 items-center gap-2 rounded-md px-2 text-xs font-[450] text-primary-600 hover:text-primary-900 hover:bg-primary-100",e),children:[h.jsx(ee,{icon:ro,size:20,strokeWidth:1.5,className:q(t==="off"?"text-primary-400":"text-primary-700")}),h.jsx("span",{className:"text-pretty",children:r.shortLabel})]}),h.jsx(Wn,{side:"top",align:"start",className:"min-w-[190px]",children:Ar.map(i=>h.jsxs(kt,{onClick:()=>n(i.value),className:"justify-between",children:[h.jsxs("span",{className:"flex flex-col text-pretty",children:[h.jsx("span",{className:"text-sm text-primary-900",children:i.label}),h.jsx("span",{className:"text-xs text-primary-500",children:i.description})]}),t===i.value&&h.jsx(ee,{icon:Qr,size:20,strokeWidth:1.5,className:"text-primary-600"})]},i.value))})]})}const Vs=[{command:"/haiku",description:"Switch to Claude Haiku 4.5"},{command:"/sonnet",description:"Switch to Claude Sonnet 4.5"},{command:"/opus",description:"Switch to Claude Opus 4.5"},{command:"/opus46",description:"Switch to Claude Opus 4.6"},{command:"/codex",description:"Switch to GPT 5.3 Codex"},{command:"/glm",description:"Switch to GLM 4.7"},{command:"/kimi",description:"Switch to Kimi K2.5"},{command:"/minimax",description:"Switch to MiniMax M2.1"},{command:"/grok",description:"Switch to Grok 4.1 Fast"},{command:"/model",description:"Show model picker or switch model"},{command:"/new",description:"New chat (optional: /new model)"},{command:"/reset",description:"Reset session"},{command:"/stop",description:"Stop current generation"},{command:"/compact",description:"Compact conversation context"},{command:"/help",description:"Show available commands"},{command:"/commands",description:"List all commands"},{command:"/status",description:"Show session status & usage"},{command:"/whoami",description:"Show your sender ID"},{command:"/context",description:"Show context window details"},{command:"/usage",description:"Toggle usage footer (off/tokens/full/cost)"},{command:"/think",description:"Set thinking level (off/low/medium/high)"},{command:"/reasoning",description:"Toggle reasoning (on/off/stream)"},{command:"/verbose",description:"Toggle verbose mode (on/full/off)"},{command:"/elevated",description:"Toggle elevated permissions (on/off/ask)"},{command:"/exec",description:"Configure exec settings"},{command:"/queue",description:"Show/configure message queue"},{command:"/tts",description:"Text-to-speech (off/always/tagged/status)"},{command:"/subagents",description:"List/stop/log sub-agent runs"},{command:"/followups",description:"Show follow-up suggestions"},{command:"/skill",description:"Run a skill by name"},{command:"/allowlist",description:"List/add/remove allowlist entries"},{command:"/approve",description:"Resolve exec approval (allow/deny)"},{command:"/config",description:"Show/get/set config (owner-only)"},{command:"/debug",description:"Runtime overrides (owner-only)"},{command:"/send",description:"Toggle message sending (on/off)"},{command:"/restart",description:"Restart gateway"},{command:"/activation",description:"Set activation mode (mention/always)"},{command:"/dock-telegram",description:"Switch replies to Telegram"},{command:"/dock-discord",description:"Switch replies to Discord"},{command:"/bash",description:"Run host shell command"}];function Ub({onSubmit:e,isLoading:t,disabled:n,wrapperRef:r,inputRef:i}){const[s,o]=m.useState(""),[a,l]=m.useState(""),[u,c]=m.useState([]),[f,p]=m.useState(0),[d,g]=m.useState(!1),[x,w]=m.useState(!1),[b,S]=m.useState(!1),[v,R]=m.useState(0),[M,C]=m.useState(!1),P=m.useRef(null),U=m.useRef([]),F=m.useRef(null),E=m.useRef(null),N=m.useRef(null),A=m.useRef(null),z=m.useMemo(()=>/^\/\S*$/.test(s)&&!d,[s,d]),j=m.useMemo(()=>z?s.slice(1).toLowerCase():"",[z,s]),T=m.useMemo(()=>z?j?Vs.filter(K=>K.command.slice(1).toLowerCase().startsWith(j)):Vs:[],[z,j]),D=m.useCallback(K=>{A.current=K,i&&(typeof i=="function"?i(K):i.current=K)},[i]),L=m.useCallback(()=>{typeof window>"u"||window.requestAnimationFrame(()=>{A.current?.focus()})},[]),H=m.useCallback(()=>{o(""),c([]),p(0),g(!1),L()},[L]),_=m.useCallback(K=>{c($=>[...$,K])},[]),y=m.useCallback(K=>{c($=>$.filter(J=>J.id!==K))},[]),X=m.useCallback(K=>{Array.from(K.dataTransfer.types).includes("Files")&&(K.preventDefault(),K.dataTransfer.dropEffect="copy",w(!0))},[]),V=m.useCallback(K=>{K.preventDefault();const $=K.relatedTarget;$&&K.currentTarget.contains($)||w(!1)},[]),k=m.useCallback(async K=>{K.preventDefault(),w(!1);const $=Array.from(K.dataTransfer.files??[]);if($.length===0)return;const J=$.filter(ne=>Za(ne));if(J.length===0)return;const xe=await Promise.all(J.map(ne=>el(ne)));c(ne=>[...ne,...xe]),L()},[L]),Q=m.useCallback(K=>{o(K),p(0),g(!1),L()},[L]),re=m.useCallback(K=>{o(K),p(0),g(!1)},[]),W=m.useCallback(K=>{o(`${K.command} `),p(0),g(!1),L()},[L]),he=m.useCallback(()=>{if(n)return;if(z&&T.length>0){const J=Math.min(f,T.length-1);W(T[J]);return}const K=s.trim(),$=u.filter(J=>!J.error&&J.base64);K.length===0&&$.length===0||(e(K,{reset:H,setValue:Q,model:a||void 0,attachments:$}),L())},[n,z,T,f,W,s,u,e,H,Q,a,L]),me=m.useCallback(K=>{e(K,{reset:H,setValue:Q,model:a||void 0,attachments:[]}),L()},[L,e,H,Q,a]),ue=m.useCallback(K=>{if(z){if(K.key==="Escape"){K.preventDefault(),g(!0),p(0);return}if(T.length!==0){if(K.key==="ArrowDown"){K.preventDefault(),p($=>($+1)%T.length);return}if(K.key==="ArrowUp"){K.preventDefault(),p($=>($-1+T.length)%T.length);return}if(K.key==="Tab"){K.preventDefault();const $=Math.min(f,T.length-1);W(T[$])}}}},[z,T,f,W]);m.useEffect(()=>()=>{E.current?.abort(),F.current&&clearInterval(F.current),P.current&&P.current.state!=="inactive"&&P.current.stop(),N.current&&N.current.abort()},[]);const se=m.useCallback(()=>{if(typeof window>"u")return"auto";try{return localStorage.getItem("opencami-stt-provider")||"auto"}catch{return"auto"}},[]),ge=m.useCallback(()=>{P.current&&P.current.state!=="inactive"&&P.current.stop(),N.current&&N.current.stop(),F.current&&(clearInterval(F.current),F.current=null),S(!1),R(0)},[]),ke=m.useCallback(async()=>{const K=se();if(K==="browser"){const $=window.SpeechRecognition||window.webkitSpeechRecognition;if(!$){alert("Web Speech API is not supported in this browser.");return}const J=new $;J.continuous=!0,J.interimResults=!1,J.lang=navigator.language||"en-US",N.current=J,S(!0),R(0),F.current=setInterval(()=>{R(ne=>ne>=119?(ge(),0):ne+1)},1e3);let xe="";J.onresult=ne=>{for(let pe=ne.resultIndex;pe<ne.results.length;pe++)ne.results[pe].isFinal&&(xe+=ne.results[pe][0].transcript)},J.onend=()=>{S(!1),R(0),F.current&&clearInterval(F.current),xe.trim()&&(o(ne=>ne+(ne?" ":"")+xe.trim()),L())},J.onerror=()=>{S(!1),R(0),F.current&&clearInterval(F.current)},J.start();return}try{const $=await navigator.mediaDevices.getUserMedia({audio:!0}),J=MediaRecorder.isTypeSupported("audio/webm")?"audio/webm":"audio/mp4",xe=new MediaRecorder($,{mimeType:J});P.current=xe,U.current=[],xe.ondataavailable=ne=>{ne.data.size>0&&U.current.push(ne.data)},xe.onstop=async()=>{$.getTracks().forEach(pe=>pe.stop());const ne=new Blob(U.current,{type:J});if(ne.size!==0){C(!0);try{const pe=new FormData;pe.append("audio",ne,`recording.${J==="audio/webm"?"webm":"mp4"}`),K!=="auto"&&pe.append("provider",K),E.current?.abort();const Oe=new AbortController;E.current=Oe;const Ae=await(await fetch("/api/stt",{method:"POST",body:pe,signal:Oe.signal})).json();Ae.ok&&Ae.text?(o($e=>$e+($e?" ":"")+Ae.text),L()):Ae.ok||(console.warn("STT failed:",Ae.error),alert(Ae.error||"Speech-to-text failed. Try the Browser provider in Settings."))}catch(pe){if(pe instanceof Error&&pe.name==="AbortError")return;console.warn("STT request failed:",pe),alert("Could not reach speech-to-text service.")}finally{C(!1)}}},S(!0),R(0),F.current=setInterval(()=>{R(ne=>ne>=119?(ge(),0):ne+1)},1e3),xe.start()}catch($){const J=$ instanceof Error?$.message:String($);if(J.includes("NotAllowedError")||J.includes("Permission"))try{(await navigator.permissions.query({name:"microphone"})).state==="denied"?alert("Microphone access is blocked. Please enable it in your browser/app settings."):alert("Microphone permission was not granted. Please try again and allow access when prompted.")}catch{alert("Could not access microphone. Please check your browser settings and allow microphone access for this site.")}else alert("Could not access microphone: "+J)}},[se,ge,L]),we=m.useCallback(()=>{b?ge():ke()},[b,ge,ke]),Se=u.filter(K=>!K.error&&K.base64),Le=n||s.trim().length===0&&Se.length===0;return h.jsxs("div",{className:"mx-auto w-full max-w-full px-2 md:px-5 sm:max-w-[768px] sm:min-w-[400px] relative pb-1 md:pb-3",ref:r,onDragOver:X,onDragLeave:V,onDrop:k,children:[x&&h.jsx("div",{className:"pointer-events-none absolute inset-2 z-20 flex items-center justify-center rounded-2xl border-2 border-dashed border-primary-400 bg-primary-50/90 text-sm font-medium text-primary-700",children:"Drop image here"}),h.jsxs(mb,{value:s,onValueChange:re,onSubmit:he,isLoading:t,disabled:n,children:[h.jsx(Ob,{attachments:u,onRemove:y}),z&&T.length>0&&h.jsx($b,{commands:T,selectedIndex:Math.min(f,T.length-1),onSelect:W}),h.jsx(gb,{placeholder:"Type a message…",inputRef:D,onKeyDown:ue}),h.jsxs(xb,{className:"justify-between px-3",children:[h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx(kb,{onModelChange:l}),h.jsx(Hb,{}),h.jsx(vb,{onSelect:me}),h.jsx(Tb,{onCommandSelect:K=>re(K+" ")})]}),h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx(jr,{tooltip:"Attach file",children:h.jsx(Db,{onFileSelect:_,disabled:n})}),h.jsx(jr,{tooltip:b?"Stop recording":"Voice input",children:h.jsx(Ce,{onClick:we,disabled:n||M,size:"icon-sm",variant:b?"destructive":"ghost",className:`rounded-full ${b?"animate-pulse":""}`,"aria-label":b?"Stop recording":"Voice input",children:M?h.jsx("span",{className:"size-4 animate-spin rounded-full border-2 border-current border-t-transparent"}):b?h.jsxs("span",{className:"flex items-center gap-1",children:[h.jsx("span",{className:"size-2 rounded-full bg-red-500"}),h.jsxs("span",{className:"text-xs tabular-nums",children:[Math.floor(v/60),":",String(v%60).padStart(2,"0")]}),h.jsx(ee,{icon:so,size:14,strokeWidth:2})]}):h.jsx(ee,{icon:Xl,size:18,strokeWidth:2})})}),h.jsx(jr,{tooltip:"Send message",children:h.jsx(Ce,{onClick:he,disabled:Le,size:"icon-sm",className:"rounded-full","aria-label":"Send message",children:h.jsx(ee,{icon:Vl,size:18,strokeWidth:2})})})]})]})]})]})}const qb=m.memo(Ub);function Wb({title:e,description:t,detail:n,actionLabel:r,onAction:i,className:s}){return h.jsx("div",{className:q("w-full max-w-[900px]",s),children:h.jsx(Wa,{children:h.jsxs("div",{className:"w-full rounded-xl border border-primary-200 bg-primary-50 p-4 text-primary-900",children:[h.jsx("div",{className:"text-balance font-medium",children:e}),h.jsx("div",{className:"mt-2 text-pretty text-primary-700",children:t}),n?h.jsx("div",{className:"mt-2 text-xs text-primary-600",children:n}):null,r&&i?h.jsx("div",{className:"mt-3",children:h.jsx(Ce,{size:"sm",variant:"outline",onClick:i,children:r})}):null]})})})}function Kb({state:e,error:t,onRetry:n,className:r}){const i=e==="checking",s=i?"Checking gateway connection...":"OpenClaw gateway is unreachable",o=i?"This dashboard needs access to the OpenClaw gateway configured by your server environment variables.":"";return h.jsx(Wb,{title:s,description:i?o:h.jsxs(h.Fragment,{children:["We could not reach the gateway from the dashboard server. Start the gateway and confirm your server environment has"," ",h.jsx("span",{className:"font-mono",children:"CLAWDBOT_GATEWAY_URL"})," plus"," ",h.jsx("span",{className:"font-mono",children:"CLAWDBOT_GATEWAY_TOKEN"})," (or"," ",h.jsx("span",{className:"font-mono",children:"CLAWDBOT_GATEWAY_PASSWORD"}),")."]}),detail:i?null:t,actionLabel:i?void 0:"Retry",onAction:i?void 0:n,className:r})}function Xb(){const e=m.useRef(null),t=m.useRef(null),n=m.useRef(null),[r,i]=m.useState(0),[s,o]=m.useState(0);return m.useLayoutEffect(()=>{const a=e.current,l=t.current,u=n.current;if(!u)return;const c=()=>{const p=a?.offsetHeight??0,d=l?.offsetHeight??0,g=u.clientHeight;u.style.setProperty("--chat-header-height",`${Math.max(0,p)}px`),u.style.setProperty("--chat-composer-height",`${Math.max(0,d)}px`),o(p),i(Math.max(0,g-p-d))};c();const f=new ResizeObserver(()=>c());return a&&f.observe(a),l&&f.observe(l),()=>f.disconnect()},[]),{headerRef:e,composerRef:t,mainRef:n,pinGroupMinHeight:r,headerHeight:s}}function Vb({activeFriendlyId:e,activeSessionKey:t,forcedSessionKey:n,isNewChat:r,isRedirecting:i,activeExists:s,sessionsReady:o,queryClient:a}){const l=n||t||e,u=be.history(e,l),c=En({queryKey:u,queryFn:async function(){const S=a.getQueryData(u),v=Array.isArray(S?.messages)?S.messages.filter(C=>C.status==="sending"||C.__optimisticId?!0:!!C.clientId):[],R=await Cu({sessionKey:l,friendlyId:e});if(!v.length)return R;const M=Yb(R.messages,v);return{...R,messages:M}},enabled:!r&&!!e&&!i&&(!o||s),placeholderData:function(){return a.getQueryData(u)},gcTime:1e3*60*10}),f=m.useRef(""),p=m.useRef([]),d=m.useMemo(()=>{const b=Array.isArray(c.data?.messages)?c.data.messages:[],S=b[b.length-1],v=S&&typeof S.id=="string"?S.id:"",R=`${b.length}:${S?.role??""}:${v}:${et(S??{content:[]}).slice(-32)}`;return R===f.current?p.current:(f.current=R,p.current=b,b)},[c.data?.messages]),g=c.error instanceof Error?c.error.message:null,x=m.useMemo(()=>{if(n)return n;const b=c.data?.sessionKey;return typeof b=="string"&&b.trim().length>0?b.trim():t},[t,n,c.data?.sessionKey]);return{historyQuery:c,historyMessages:d,displayMessages:d,historyError:g,resolvedSessionKey:x,activeCanonicalKey:r?"new":x||e,sessionKeyForHistory:l}}function Yb(e,t){if(!t.length)return e;const n=[...e];for(const r of t)e.some(s=>{if(r.clientId&&s.clientId&&r.clientId===s.clientId||r.__optimisticId&&s.__optimisticId&&r.__optimisticId===s.__optimisticId)return!0;if(r.role&&s.role&&r.role!==s.role)return!1;const o=et(r);if(!o||o!==et(s))return!1;const a=Nr(r),l=Nr(s);return Math.abs(a-l)<=1e4})||n.push(r);return n}function Gb(e){const[t,n]=m.useState(!1);return m.useLayoutEffect(()=>{const r=window.matchMedia("(max-width: 768px)"),i=()=>n(r.matches);return i(),r.addEventListener("change",i),()=>r.removeEventListener("change",i)},[]),m.useLayoutEffect(()=>{t&&dt(e,function(i){return{...i,isSidebarCollapsed:!0}})},[t,e]),{isMobile:t}}function Qb({activeFriendlyId:e,isNewChat:t,forcedSessionKey:n}){const r=En({queryKey:be.sessions,queryFn:Su,refetchInterval:3e4}),i=m.useMemo(()=>{const f=r.data??[];return Kc(f)},[r.data]),s=m.useMemo(()=>i.find(f=>f.friendlyId===e),[i,e]),o=m.useMemo(()=>t||n||Io(e)?!0:i.some(f=>f.friendlyId===e),[e,n,t,i]),a=s?.key??"",l=m.useMemo(()=>s?s.label||s.title||s.derivedTitle||s.friendlyId:e,[e,s]),u=r.error instanceof Error?r.error.message:null,c=m.useMemo(()=>({totalTokens:s?.totalTokens,contextTokens:s?.contextTokens}),[s?.totalTokens,s?.contextTokens]);return{sessionsQuery:r,sessions:i,activeSession:s,activeExists:o,activeSessionKey:a,activeTitle:l,activeTokens:c,sessionsError:u}}function Jb(){const e=Lt(u=>u.settings),[t,n]=m.useState(!1),[r,i]=m.useState(null),[s,o]=m.useState(null),a=m.useRef(null);return{generateTitle:m.useCallback(async u=>{a.current&&a.current.abort();const c=new AbortController;a.current=c,n(!0);try{const f={"Content-Type":"application/json",...Va()},p=await fetch("/api/llm-features",{method:"POST",headers:f,body:JSON.stringify({action:"title",message:u}),signal:c.signal});if(!p.ok)throw new Error(`API error: ${p.status}`);const d=await p.json();if(c.signal.aborted)throw new Error("Aborted");const g=d.title||u.slice(0,50),x=d.source||"heuristic";return i(g),o(x),{title:g,source:x,error:d.error}}catch(f){if(f instanceof Error&&f.name==="AbortError")throw f;const p=Zb(u);return i(p),o("heuristic"),{title:p,source:"heuristic",error:f instanceof Error?f.message:"Unknown error"}}finally{n(!1),a.current===c&&(a.current=null)}},[e.llmApiKey,e.llmBaseUrl,e.llmModel,e.llmProvider]),isGenerating:t,lastTitle:r,lastSource:s}}function Zb(e){let t=e.replace(/```[\s\S]*?```/g," ");t=t.replace(/`[^`]+`/g," "),t=t.replace(/https?:\/\/[^\s]+/g," "),t=t.replace(/[^\w\s.,!?'-]/g," "),t=t.replace(/\s+/g," ").trim();let i=t.split(/\s+/).filter(s=>{if(s.length<=2){const o=s.toUpperCase();return["AI","ML","UI","UX","API","CSS","JS"].includes(o)}return!0}).slice(0,6).join(" ");return i=i.replace(/[.,!?]+$/,""),i.length>60&&(i=i.slice(0,57)+"..."),i||e.slice(0,50)}function e0(){return Lt(e=>e.settings.useLlmTitles)}const Ir={active:!1,text:"",tools:[],sessionKey:null};function t0(e){const[t,n]=m.useState(Ir),r=m.useRef(null),i=m.useRef(e.onDone),s=m.useRef(e.onError);i.current=e.onDone,s.current=e.onError;const o=m.useCallback(l=>{if(r.current&&(r.current.close(),r.current=null),l?.preserveState){n(u=>({...u,active:!1}));return}n(Ir)},[]),a=m.useCallback(l=>{r.current&&(r.current.close(),r.current=null),n({active:!0,text:"",tools:[],sessionKey:l});const u=new EventSource(`/api/stream?sessionKey=${encodeURIComponent(l)}`);r.current=u,u.addEventListener("delta",c=>{try{const f=JSON.parse(c.data);n(p=>({...p,text:p.text+f.text}))}catch{}}),u.addEventListener("tool",c=>{try{const f=JSON.parse(c.data);n(p=>{const d=p.tools.findIndex(x=>x.id===f.id),g=[...p.tools];return d>=0?g[d]={name:f.name,status:f.status,id:f.id}:g.push({name:f.name,status:f.status,id:f.id}),{...p,tools:g}})}catch{}}),u.addEventListener("done",c=>{try{const f=JSON.parse(c.data);u.close(),r.current=null,n(p=>({...p,active:!1})),i.current(f.sessionKey)}catch{}}),u.onerror=()=>{u.readyState===EventSource.CLOSED&&(u.close(),r.current=null,n(Ir),s.current?.("Stream connection lost"))}},[]);return{streaming:t,startStream:a,stopStream:o}}function n0(e){const t=m.useCallback(n=>{const r=n.target,i=r.tagName==="INPUT"||r.tagName==="TEXTAREA"||r.isContentEditable;if(n.key==="Escape"){e.onEscape?.();return}if(n.key==="?"&&!i&&!n.metaKey&&!n.ctrlKey){n.preventDefault(),e.onShowHelp?.();return}if(i)return;const o=navigator.platform.toUpperCase().indexOf("MAC")>=0?n.metaKey:n.ctrlKey;if(o&&n.key==="k"&&!n.shiftKey){n.preventDefault(),e.onNewChat?.();return}if(o&&n.key==="/"){n.preventDefault(),e.onFocusInput?.();return}if(o&&n.shiftKey&&n.key==="C"){n.preventDefault(),e.onCopyLastResponse?.();return}if(o&&n.key==="f"&&!n.shiftKey){n.preventDefault(),e.onSearch?.();return}if(o&&n.shiftKey&&n.key==="F"){n.preventDefault(),e.onSearchGlobal?.();return}},[e]);m.useEffect(()=>(window.addEventListener("keydown",t),()=>{window.removeEventListener("keydown",t)}),[t])}function Ys(e){const{threshold:t=50,edgeWidth:n,onMove:r,onSwipe:i,onCancel:s,direction:o,enabled:a=!0}=e,l=m.useRef({startX:0,startY:0,tracking:!1,directionLocked:!1}),u=m.useCallback(p=>{if(!a)return;const d=p.touches[0];d&&(n!==void 0&&d.clientX>n||(l.current={startX:d.clientX,startY:d.clientY,tracking:!0,directionLocked:!1}))},[a,n]),c=m.useCallback(p=>{const d=l.current;if(!d.tracking)return;const g=p.touches[0];if(!g)return;const x=g.clientX-d.startX,w=g.clientY-d.startY,b=Math.abs(x),S=Math.abs(w);if(!d.directionLocked){if(b<5&&S<5)return;if(S>b){d.tracking=!1,s?.();return}d.directionLocked=!0}o==="left"&&x>0||o==="right"&&x<0||(p.preventDefault(),r?.(x))},[o,r,s]),f=m.useCallback(p=>{const d=l.current;if(!d.tracking)return;d.tracking=!1;const g=p.changedTouches[0];if(!g){s?.();return}const x=g.clientX-d.startX,w=Math.abs(x);if(!d.directionLocked||w<t){s?.();return}const b=x>0?"right":"left";if(o&&b!==o){s?.();return}i(b)},[o,s,i,t]);return{onTouchStart:u,onTouchMove:c,onTouchEnd:f}}const r0=m.lazy(()=>Bn(()=>import("./keyboard-shortcuts-dialog-DXC0YHoy.js"),__vite__mapDeps([13,1,3,2,4,5,6])).then(e=>({default:e.KeyboardShortcutsDialog}))),i0=m.lazy(()=>Bn(()=>import("./search-dialog-I1jJplIh.js"),__vite__mapDeps([14,1,2,3,4,5,6,8,10,11,9])).then(e=>({default:e.SearchDialog})));function s0({activeFriendlyId:e,isNewChat:t=!1,onSessionResolved:n,forcedSessionKey:r}){const i=Vr(),s=Wt(),[o,a]=m.useState(!1),[l,u]=m.useState(!1),[c,f]=m.useState(null),[p,d]=m.useState(!1),{headerRef:g,composerRef:x,mainRef:w,pinGroupMinHeight:b,headerHeight:S}=Xb(),[v,R]=m.useState(()=>ar()||lr()),[M,C]=m.useState(()=>ar()||lr()),[P,U]=m.useState(!1),[F,E]=m.useState(!1),[N,A]=m.useState("global"),[z,j]=m.useState(!1),T=Xr(B=>B.level),D=m.useRef(null),L=m.useRef(null),H=m.useRef(null),_=m.useRef(""),y=m.useRef(()=>{}),X=m.useRef(!1),{isMobile:V}=Gb(s),{sessionsQuery:k,sessions:Q,activeExists:re,activeSessionKey:W,activeTitle:he,activeTokens:me,sessionsError:ue}=Qb({activeFriendlyId:e,isNewChat:t,forcedSessionKey:r}),{historyQuery:se,historyMessages:ge,displayMessages:ke,historyError:we,resolvedSessionKey:Se,activeCanonicalKey:Le,sessionKeyForHistory:K}=Vb({activeFriendlyId:e,activeSessionKey:W,forcedSessionKey:r,isNewChat:t,isRedirecting:p,activeExists:re,sessionsReady:k.isSuccess,queryClient:s}),$=En({queryKey:jl,queryFn:function(){return zi(s)},initialData:function(){return zi(s)},staleTime:1/0}),J=En({queryKey:["gateway","status"],queryFn:vu,retry:!1,refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:"always"}),xe=m.useRef(Date.now()),ne=J.error instanceof Error?J.error.message:J.data&&!J.data.ok?J.data.error||"Gateway unavailable":null,pe=ne??ue??we,Oe=m.useCallback(()=>{J.refetch()},[J]),Fe=$.data?.isSidebarCollapsed??!1,Ae=Ys({enabled:V&&Fe,edgeWidth:40,threshold:50,direction:"right",onSwipe:()=>{dt(s,B=>({...B,isSidebarCollapsed:!1}))}}),$e=Ys({enabled:V&&!Fe,threshold:50,direction:"left",onSwipe:()=>{dt(s,B=>({...B,isSidebarCollapsed:!0}))}}),I=m.useCallback(()=>{f(null),d(!0),i({to:"/new",replace:!0})},[i]),O=m.useCallback(()=>{L.current&&(window.clearInterval(L.current),L.current=null),H.current&&(window.clearTimeout(H.current),H.current=null)},[]),Y=m.useCallback(()=>{O(),Vt(!1),R(!1),j(!1)},[O]),te=e0(),{generateTitle:ae}=Jb(),Ee=m.useRef(new Set),We=150,Be=600,Ge=m.useCallback(()=>{!e||t||(L.current&&window.clearInterval(L.current),j(!0),L.current=window.setInterval(()=>{y.current()},We))},[e,t]),Ke=m.useRef(()=>{}),ve=m.useRef(()=>{}),{streaming:Te,startStream:Pe,stopStream:vt}=t0({onDone:B=>Ke.current(B),onError:B=>ve.current(B)});Ke.current=m.useCallback(async B=>{await se.refetch(),vt({preserveState:!0}),Y(),s.invalidateQueries({queryKey:be.sessions})},[se,s,vt,Y]),ve.current=m.useCallback(B=>{console.warn("[stream] SSE error, falling back to polling")},[]);const zt=m.useMemo(()=>{if(!Te.text)return null;const B=[];for(const Z of Te.tools)B.push({type:"toolCall",name:Z.name,id:Z.id});return B.push({type:"text",text:Te.text}),{role:"assistant",content:B,id:"__streaming__",__streaming:!0,timestamp:Date.now()}},[Te.text,Te.tools]),Et=m.useMemo(()=>{if(!zt)return ke;const B=ke[ke.length-1];if(B?.role==="assistant"){if(et(B).length>=Te.text.length)return ke;const ye=[...ke];return ye[ye.length-1]=zt,ye}return[...ke,zt]},[ke,zt,Te.text]),de=m.useMemo(()=>({}),[]);y.current=function(){se.refetch()},m.useEffect(()=>{if(p){c&&f(null);return}if(je){c&&f(null);return}if(k.isSuccess&&!re){c&&f(null);return}const B=ue??we??ne;if(!B){c?.startsWith("Failed to load")&&f(null);return}Fi(B)&&i({to:"/connect",replace:!0});const Z=ue?`Failed to load sessions. ${ue}`:we?`Failed to load history. ${we}`:ne?`Gateway unavailable. ${ne}`:null;Z&&f(Z)},[c,ne,we,p,i,ue]);const je=!t&&!r&&!Io(e)&&k.isSuccess&&Q.length>0&&!Q.some(B=>B.friendlyId===e)&&!se.isFetching&&!se.isSuccess;m.useEffect(()=>{if(p){if(t){d(!1);return}!je&&k.isSuccess&&d(!1)}},[t,p,k.isSuccess,je]),m.useEffect(()=>{t||k.isSuccess&&Q.length!==0&&je&&(Ln(),Mr(s,e,K),i({to:"/new",replace:!0}))},[e,se.isFetching,se.isSuccess,t,i,s,K,Q,k.isSuccess,je]);const Tt=je||p,ut=m.useRef("fast");m.useEffect(()=>{const B=ge[ge.length-1];if(!B||B.role!=="assistant")return;const Z=`${ge.length}:${et(B).slice(-64)}`;Z!==_.current&&(_.current=Z,ut.current!=="fast"&&L.current&&(window.clearInterval(L.current),L.current=window.setInterval(()=>{y.current()},We),ut.current="fast"),H.current&&window.clearTimeout(H.current),H.current=window.setTimeout(()=>{L.current&&(window.clearInterval(L.current),L.current=window.setInterval(()=>{y.current()},Be),ut.current="slow"),H.current=window.setTimeout(()=>{Y(),ut.current="fast"},3e3)},1500))},[ge,Y]),m.useEffect(()=>{if(!te||t||p)return;const B=r||Se||W;if(!B||Ee.current.has(B))return;const Z=ge.filter(ze=>ze.role==="user"),ye=ge.filter(ze=>ze.role==="assistant");if(Z.length===0||ye.length===0||Z.length!==1)return;const nt=et(Z[0]);!nt||nt.length<5||(Ee.current.add(B),(async()=>{try{const ze=await ae(nt);ze.title&&await Ru(s,B,e,ze.title)}catch(ze){console.error("[smart-title] Error generating title:",ze)}})())},[te,t,p,r,Se,W,e,ge,ae,s]),m.useEffect(()=>{if(t||e){if(X.current){X.current=!1;return}if(ar()||lr()){R(!0),C(!0);return}O(),vt(),_.current="",R(!1),C(!1),j(!1)}},[e,t,O,vt]),m.useLayoutEffect(()=>{if(t)return;const B=Hc(r||Se||W,e);if(!B)return;X.current=!0;const Z=be.history(B.friendlyId,B.sessionKey),ye=s.getQueryData(Z);(Array.isArray(ye?.messages)?ye.messages:[]).some(jt=>!!(B.optimisticMessage.clientId&&(jt.clientId===B.optimisticMessage.clientId||jt.__optimisticId===B.optimisticMessage.clientId)||B.optimisticMessage.__optimisticId&&jt.__optimisticId===B.optimisticMessage.__optimisticId))||rr(s,B.friendlyId,B.sessionKey,B.optimisticMessage),R(!0),C(!0),er(B.sessionKey,B.friendlyId,B.message,!0,B.attachments)},[e,W,r,t,s,Se]);function er(B,Z,ye,nt=!1,ze,jt){let _t="";if(!nt){const{clientId:Ie,optimisticMessage:Xt}=$i(ye,ze);_t=Ie,rr(s,Z,B,Xt),Au(s,B,Z,Xt)}Vt(!0),a(!0),f(null),R(!0),C(!0);const ct=ze?.map(Ie=>({mimeType:Ie.file.type,content:Ie.base64}));Pe(B),Ge(),fetch("/api/send",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({sessionKey:B,friendlyId:Z,message:ye,thinking:T,idempotencyKey:crypto.randomUUID(),attachments:ct,model:jt||void 0})}).then(async Ie=>{if(!Ie.ok)throw new Error(await it(Ie))}).catch(Ie=>{const Xt=Ie instanceof Error?Ie.message:String(Ie);if(Fi(Xt)){i({to:"/connect",replace:!0});return}_t&&Eu(s,Z,B,_t,function(pl){return{...pl,status:"error"}}),f(`Failed to send message. ${Xt}`),Vt(!1),R(!1),C(!1)}).finally(()=>{a(!1)})}const Ii=m.useCallback(async()=>{u(!0);try{const B=await fetch("/api/sessions",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({})});if(!B.ok)throw new Error(await it(B));const Z=await B.json(),ye=typeof Z.sessionKey=="string"?Z.sessionKey:"",nt=typeof Z.friendlyId=="string"&&Z.friendlyId.trim().length>0?Z.friendlyId.trim():Rr(ye);if(!ye||!nt)throw new Error("Invalid session response");return s.invalidateQueries({queryKey:be.sessions}),{sessionKey:ye,friendlyId:nt}}finally{u(!1)}},[s]),tl=m.useCallback((B,Z)=>{const ye=Z.attachments;if(B.length===0&&(!ye||ye.length===0))return;if(Z.reset(),t){const{clientId:ze,optimisticId:jt,optimisticMessage:_t}=$i(B,ye);rr(s,"new","new",_t),Vt(!0),a(!0),R(!0),C(!0),Ii().then(({sessionKey:ct,friendlyId:Ie})=>{if(Bc(Ie),Fc({sessionKey:ct,friendlyId:Ie,message:B,optimisticMessage:_t,attachments:ye}),n){n({sessionKey:ct,friendlyId:Ie});return}i({to:"/chat/$sessionKey",params:{sessionKey:Ie},replace:!0})}).catch(ct=>{Tu(s,"new","new",ze,jt),Z.setValue(B),f(`Failed to create session. ${ct instanceof Error?ct.message:String(ct)}`),Vt(!1),R(!1),C(!1),a(!1)});return}er(r||Se||W,e,B,!1,ye,Z.model)},[e,W,Ii,r,t,i,n,s,Se]),Ri=m.useCallback(()=>{R(!1),C(!1),Mr(s,"new","new"),i({to:"/new"}),V&&dt(s,function(Z){return{...Z,isSidebarCollapsed:!0}})},[V,i,s]),nl=m.useCallback(()=>{dt(s,function(Z){return{...Z,isSidebarCollapsed:!Z.isSidebarCollapsed}})},[s]),rl=m.useCallback(()=>{V&&dt(s,function(Z){return{...Z,isSidebarCollapsed:!0}})},[V,s]),il=m.useCallback(()=>{dt(s,function(Z){return{...Z,isSidebarCollapsed:!1}})},[s]),sl=m.useCallback(B=>{if(t||!B.trim())return;const Z=r||Se||W;Z&&er(Z,e,B.trim())},[e,W,r,t,Se]),ol=m.useCallback(()=>{D.current?.focus()},[]),al=m.useCallback(()=>{if(P){U(!1);return}document.activeElement instanceof HTMLElement&&document.activeElement.blur()},[P]),ll=m.useCallback(()=>{const B=[...ke].reverse().find(ye=>ye.role==="assistant");if(!B)return;const Z=et(B);Z&&navigator.clipboard.writeText(Z).catch(()=>{})},[ke]),ul=m.useCallback(()=>{U(!0)},[]),cl=m.useCallback(()=>{A(t?"global":"current"),E(!0)},[t]),Ni=m.useCallback(()=>{A("global"),E(!0)},[]);n0({onNewChat:Ri,onFocusInput:ol,onEscape:al,onCopyLastResponse:ll,onShowHelp:ul,onSearch:cl,onSearchGlobal:Ni});const Li=se.isLoading&&!se.data||p,Mi=!!ne&&J.errorUpdatedAt>xe.current,fl=!Li&&ke.length===0,hl=m.useMemo(()=>!Mi||!pe?null:h.jsx(Kb,{state:"error",error:pe,onRetry:Oe}),[pe,Oe,Mi]),Di=h.jsx(ef,{sessions:Q,activeFriendlyId:e,activeSessionKey:K,creatingSession:l,onCreateSession:Ri,isCollapsed:V?!1:Fe,onToggleCollapse:nl,onSelectSession:rl,onActiveSessionDelete:I,onOpenSearch:Ni});return h.jsxs("div",{className:"h-screen bg-surface text-primary-900",children:[h.jsxs("div",{className:q("h-full overflow-hidden",V?"relative":"grid grid-cols-[auto_minmax(0,1fr)]"),children:[Tt?null:V?h.jsxs(h.Fragment,{children:[!Fe&&h.jsx("div",{className:"fixed inset-0 z-40 bg-black/40 transition-opacity duration-200",onClick:()=>dt(s,B=>({...B,isSidebarCollapsed:!0})),...$e}),h.jsx("div",{className:q("fixed inset-y-0 left-0 z-50 w-[300px] transition-transform duration-150 safe-area-top",Fe?"-translate-x-full":"translate-x-0"),...$e,children:Di})]}):Di,h.jsxs("main",{className:"flex flex-col h-full min-h-0 min-w-0 overflow-x-hidden",ref:w,...Ae,children:[h.jsx(sf,{activeTitle:he,wrapperRef:g,showSidebarButton:V,onOpenSidebar:il,totalTokens:me.totalTokens,contextTokens:me.contextTokens}),Tt?null:h.jsxs(h.Fragment,{children:[h.jsx(pb,{messages:Et,loading:Li,empty:fl,notice:hl,noticePosition:"end",waitingForResponse:v,isStreaming:z,sessionKey:Le,pinToTop:M,pinGroupMinHeight:b,headerHeight:S,contentStyle:de,onFollowUpClick:sl}),h.jsx(qb,{onSubmit:tl,isLoading:o,disabled:o,wrapperRef:x,inputRef:D})]})]})]}),P&&h.jsx(m.Suspense,{fallback:null,children:h.jsx(r0,{open:P,onOpenChange:U})}),F&&h.jsx(m.Suspense,{fallback:null,children:h.jsx(i0,{open:F,onOpenChange:E,sessions:Q,currentFriendlyId:e,currentSessionKey:W,mode:N,onJumpToMessage:B=>{E(!1),B.friendlyId&&i({to:"/chat/$sessionKey",params:{sessionKey:B.friendlyId}})}})})]})}function o0(){const e=Wt(),t=Vr(),[n,r]=m.useState(null),i=gl.useParams(),s=typeof i.sessionKey=="string"?i.sessionKey:"main",o=s==="new",a=n?.friendlyId===s?n.sessionKey:void 0,l=m.useCallback(function(c){ju(e,"new","new",c.friendlyId,c.sessionKey),r({friendlyId:c.friendlyId,sessionKey:c.sessionKey}),t({to:"/chat/$sessionKey",params:{sessionKey:c.friendlyId},replace:!0})},[t,e]);return h.jsx(s0,{activeFriendlyId:s,isNewChat:o,forcedSessionKey:a,onSessionResolved:o?l:void 0})}const k0=Object.freeze(Object.defineProperty({__proto__:null,component:o0},Symbol.toStringTag,{value:"Module"}));export{k0 as $,b0 as a,be as c,Ka as g,oc as u};
|