@telepath-computer/television 0.1.21 → 0.1.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,555 +0,0 @@
1
- var Id=Object.defineProperty;var Ka=e=>{throw TypeError(e)};var Cd=(e,t,n)=>t in e?Id(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n;var m=(e,t,n)=>Cd(e,typeof t!="symbol"?t+"":t,n),Ii=(e,t,n)=>t.has(e)||Ka("Cannot "+n);var d=(e,t,n)=>(Ii(e,t,"read from private field"),n?n.call(e):t.get(e)),I=(e,t,n)=>t.has(e)?Ka("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,n),C=(e,t,n,s)=>(Ii(e,t,"write to private field"),s?s.call(e,n):t.set(e,n),n),y=(e,t,n)=>(Ii(e,t,"access private method"),n);var Ya=(e,t,n,s)=>({set _(r){C(e,t,r,n)},get _(){return d(e,t,s)}});(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))s(r);new MutationObserver(r=>{for(const i of r)if(i.type==="childList")for(const o of i.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&s(o)}).observe(document,{childList:!0,subtree:!0});function n(r){const i={};return r.integrity&&(i.integrity=r.integrity),r.referrerPolicy&&(i.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?i.credentials="include":r.crossOrigin==="anonymous"?i.credentials="omit":i.credentials="same-origin",i}function s(r){if(r.ep)return;r.ep=!0;const i=n(r);fetch(r.href,i)}})();const Xa=new WeakMap;function zd(e){return(typeof e=="object"||typeof e=="function")&&e!==null&&"then"in e&&typeof e.then=="function"}function _n(e){return typeof e=="string"?e:typeof e=="symbol"?e.description??e.toString():e.name||"(anonymous class)"}function Ja(){return new Error("register(Key, factory) requires a factory function. Wrap existing instances as () => instance.")}function $d(){return new Error("register(Key, factory) does not accept async factories. Await setup before registering.")}class Rd{constructor(){m(this,"entries",new Map);m(this,"constructionStack",[])}register(t,n){if(n===void 0){if(typeof t!="function")throw Ja();this.validateClassRegistration(t),this.storeFactory(t,()=>this.instantiateClass(t));return}if(typeof n!="function")throw Ja();if(n.constructor.name==="AsyncFunction")throw $d();this.storeFactory(t,n)}has(t){var n;return((n=this.entries.get(t))==null?void 0:n.factory)!==void 0}resolve(t){return this.resolveAny(t)}storeFactory(t,n){const s=this.getOrCreateEntry(t);s.factory=n,s.instance=void 0,s.error=void 0}validateClassRegistration(t){const n=Xa.get(t);if(n){if(t.length!==n.length)throw new Error(`${_n(t)} cannot be registered with register(Class). @injectable(...) declared ${n.length} dependencies but constructor arity is ${t.length}. Use register(Key, () => value) instead.`);return}if(t.length!==0)throw new Error(`${_n(t)} cannot be registered with register(Class). Undecorated classes must have zero required constructor parameters. Use register(Key, () => value) instead.`)}instantiateClass(t){const n=Xa.get(t);if(!n)return new t;const s=n.map(r=>this.resolveAny(r));return new t(...s)}resolveAny(t){return this.getOrCreateEntry(t).proxy}getOrCreateEntry(t){let n=this.entries.get(t);return n||(n={key:t},n.proxy=this.createProxy(n),this.entries.set(t,n),n)}createProxy(t){return new Proxy({},{get:(n,s)=>{if(s==="then")return;const r=this.getInstance(t),i=Reflect.get(r,s,r);return typeof i=="function"?i.bind(r):i},set:(n,s,r)=>{const i=this.getInstance(t);return Reflect.set(i,s,r,i)},has:(n,s)=>{const r=this.getInstance(t);return s in r}})}getInstance(t){if(t.instance)return t.instance;if(t.error)throw t.error;if(!t.factory)throw new Error(`${_n(t.key)} was resolved but never registered`);const n=this.constructionStack.indexOf(t.key);if(n!==-1){const s=[...this.constructionStack.slice(n),t.key].map(r=>_n(r)).join(" -> ");throw new Error(`Circular dependency detected: ${s}`)}this.constructionStack.push(t.key);try{const s=t.factory();if(zd(s))throw new Error(`Factory for ${_n(t.key)} returned a Promise. Await setup before registering.`);if(typeof s!="object"||s===null)throw new Error(`Factory for ${_n(t.key)} returned a non-object value. Wrap primitives in an object.`);return t.instance=s,s}catch(s){throw t.error=s,s}finally{this.constructionStack.pop()}}}const Ze=new Rd,Pd=new Set(["target","currentTarget","eventPhase","defaultPrevented","isTrusted","timeStamp","srcElement","returnValue","cancelBubble","NONE","CAPTURING_PHASE","AT_TARGET","BUBBLING_PHASE","composedPath","stopPropagation","stopImmediatePropagation","preventDefault","initEvent"]);function Dd(e){for(const t of Object.keys(e))if(Pd.has(t))throw new Error(`Event payload key "${t}" is reserved; choose a different property name`)}function Ld(e,t){Dd(t);for(const n of Object.keys(t))Object.defineProperty(e,n,{value:t[n],writable:!0,enumerable:!0,configurable:!0})}function rt(){class e extends Event{constructor(n,s){const{type:r,bubbles:i,cancelable:o,composed:a,...c}=s??{};if(r!==void 0)throw new Error('Do not pass "type" in init; use the constructor argument instead');super(n,{bubbles:i,cancelable:o,composed:a}),Ld(this,c)}}return e}class cn extends globalThis.EventTarget{}const B=rt(),vl=rt(),es=rt(),_l="0123456789ABCDEFGHJKMNPQRSTVWXYZ",Rr=32,Md=16,yl=10,Qa=0xffffffffffff;var Bt;(function(e){e.Base32IncorrectEncoding="B32_ENC_INVALID",e.DecodeTimeInvalidCharacter="DEC_TIME_CHAR",e.DecodeTimeValueMalformed="DEC_TIME_MALFORMED",e.EncodeTimeNegative="ENC_TIME_NEG",e.EncodeTimeSizeExceeded="ENC_TIME_SIZE_EXCEED",e.EncodeTimeValueMalformed="ENC_TIME_MALFORMED",e.PRNGDetectFailure="PRNG_DETECT",e.ULIDInvalid="ULID_INVALID",e.Unexpected="UNEXPECTED",e.UUIDInvalid="UUID_INVALID"})(Bt||(Bt={}));class us extends Error{constructor(t,n){super(`${n} (${t})`),this.name="ULIDError",this.code=t}}function Od(e){const t=Math.floor(e()*Rr)%Rr;return _l.charAt(t)}function Nd(e){const t=Wd(),n=t&&(t.crypto||t.msCrypto)||null;if(typeof(n==null?void 0:n.getRandomValues)=="function")return()=>{const s=new Uint8Array(1);return n.getRandomValues(s),s[0]/256};if(typeof(n==null?void 0:n.randomBytes)=="function")return()=>n.randomBytes(1).readUInt8()/256;throw new us(Bt.PRNGDetectFailure,"Failed to find a reliable PRNG")}function Wd(){return Zd()?self:typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:null}function Fd(e,t){let n="";for(;e>0;e--)n=Od(t)+n;return n}function Ud(e,t=yl){if(isNaN(e))throw new us(Bt.EncodeTimeValueMalformed,`Time must be a number: ${e}`);if(e>Qa)throw new us(Bt.EncodeTimeSizeExceeded,`Cannot encode a time larger than ${Qa}: ${e}`);if(e<0)throw new us(Bt.EncodeTimeNegative,`Time must be positive: ${e}`);if(Number.isInteger(e)===!1)throw new us(Bt.EncodeTimeValueMalformed,`Time must be an integer: ${e}`);let n,s="";for(let r=t;r>0;r--)n=e%Rr,s=_l.charAt(n)+s,e=(e-n)/Rr;return s}function Zd(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function Wn(e,t){const n=Nd(),s=Date.now();return Ud(s,yl)+Fd(Md,n)}const kl="markdown";function jd(e){const t=e.type??kl;return{id:e.id??Wn(),type:t,title:e.title,content:e.content}}const st=4,We=6,wl=2,Yi=2,Hd=st,Bd=We,Zo="auto",It="auto",Zt=120,ec=75,ce=16,Tt=Zt*st+ce*(st-1),En=Zt*We+ce*(We-1),Gd=200,Vd=4,cr=150,qd=10,tc=2;function Xi(e,t={}){return{id:t.id??Wn(),type:"card",artifactID:e,width:t.width??Zo,height:t.height??It}}function Ji(e,t){return e.some(n=>bl(n,t))}function bl(e,t){switch(e.type){case"card":return e.artifactID===t;case"row":return e.children.some(n=>n.artifactID===t);case"stack":return e.children.some(n=>bl(n,t))}}function Ci(e){return e.layout.flatMap(Sl)}function Sl(e){switch(e.type){case"card":return[e.artifactID];case"row":return e.children.map(t=>t.artifactID);case"stack":return e.children.flatMap(Sl)}}const Kd=4,Yd=/^[0-9A-HJKMNP-TV-Z]{26}$/;function xl(e){return Tl(e)}function El(e,t){return Tl(e.flatMap(n=>Cl(n,t)))}function Al(e){const t=[],n=new Set;for(const s of e){if(s.type==="row"){t.push(`Top-level rows are invalid: ${s.id}`);continue}zl(s,"strip",t,n)}return{valid:t.length===0,errors:t}}function In(e){const t=xl(e),n=Al(t);if(!n.valid)throw new Error(`Invalid layout: ${n.errors.join("; ")}`);return{totalNodes:t.length,nodes:t.filter(s=>s.type!=="row").map(ep)}}function Tl(e){const t=[];for(const n of e){const s=Il(n);for(const r of s){if(r.type==="row"){t.push(...r.children.map(_t));continue}t.push(r)}}return t}function Il(e){switch(e.type){case"card":return[_t(e)];case"row":{const t=e.children.map(_t);return t.length===0?[]:t.length===1?[t[0]]:[{...e,children:t}]}case"stack":{const t=[];for(const n of e.children){const s=Il(n);for(const r of s){if(r.type==="stack"){t.push(...r.children.map(Qi));continue}if(r.type==="row"){t.push({...r,children:r.children.map(_t)});continue}t.push(_t(r))}}return t.length===0?[]:t.length===1?[Qi(t[0])]:[{...e,children:t}]}}}function Cl(e,t){switch(e.type){case"card":return e.artifactID===t?[]:[_t(e)];case"row":{const n=e.children.filter(s=>s.artifactID!==t).map(_t);return n.length===0?[]:n.length===1?[n[0]]:[{...e,children:n}]}case"stack":{const n=e.children.flatMap(s=>Cl(s,t).filter(i=>i.type!=="stack"));return n.length===0?[]:n.length===1?[Qi(n[0])]:[{...e,children:n}]}}}function zl(e,t,n,s){switch(e.type){case"card":$l(e,t,n,s);return;case"row":Xd(e,t,n,s);return;case"stack":Jd(e,t,n,s);return}}function $l(e,t,n,s){jo(e.id,n),typeof e.artifactID!="string"||e.artifactID.length===0?n.push(`Card ${e.id} is missing artifactID`):s.has(e.artifactID)?n.push(`Duplicate artifactID in layout: ${e.artifactID}`):s.add(e.artifactID),Qd(e.width)||n.push(`Card ${e.id} width must be an integer in the range 2-4`),Rl(e.height)||n.push(`Card ${e.id} height must be an integer in the range 2-6 or "auto"`);const r=jt(e.width);t==="row"&&r<wl&&n.push(`Row child ${e.id} must be at least 2 columns wide`)}function Xd(e,t,n,s){if(jo(e.id,n),t!=="stack"&&n.push(`Row ${e.id} may only appear inside a stack`),Rl(e.height,Kd)||n.push(`Row ${e.id} height must be an integer in the range 2-4 or "auto"`),!Array.isArray(e.children)||e.children.length===0){n.push(`Row ${e.id} must contain card nodes`);return}let r=0;for(const i of e.children){if(i.type!=="card"){n.push(`Row ${e.id} must contain only card nodes`);continue}$l(i,"row",n,s),r+=jt(i.width)}r!==st&&n.push(`Row ${e.id} children must sum to 4 columns`)}function Jd(e,t,n,s){if(jo(e.id,n),t!=="strip"&&n.push(`Invalid nested stack at ${e.id}; stack children cannot contain another nested stack`),!Array.isArray(e.children)||e.children.length===0){n.push(`Stack ${e.id} must contain at least one child`);return}let r=0,i=0;for(const a of e.children){if(a.type==="stack"){n.push(`Stack ${e.id} cannot contain another nested stack`);continue}if(zl(a,"stack",n,s),a.height===It){i+=1;continue}r+=a.height}if(r>We&&n.push(`Stack ${e.id} exceeds the 6-row budget`),i===0)return;const o=We-r;if(o<i*Yi||o%i!==0){n.push(`Stack ${e.id} has auto-height children that cannot resolve to whole height >= 2`);return}o/i<Yi&&n.push(`Stack ${e.id} has auto-height children below the minimum row size`)}function jo(e,t){(typeof e!="string"||!Yd.test(e))&&t.push(`Node id must be a ULID: ${String(e)}`)}function Qd(e){return e===Zo||Number.isInteger(e)&&e>=wl&&e<=Hd}function Rl(e,t=Bd){return e===It||Number.isInteger(e)&&e>=Yi&&e<=t}function jt(e){return e===Zo?st:e}function ep(e){if(e.type==="card")return{id:e.id,type:"card",width:jt(e.width),cards:[{id:e.id,artifactID:e.artifactID,col:1,row:1,width:jt(e.width),height:Pl(e.height,We)}]};const t=tp(e.children),n=[];let s=1;for(let r=0;r<e.children.length;r+=1){const i=e.children[r],o=t[r];if(i.type==="card")n.push({id:i.id,artifactID:i.artifactID,col:1,row:s,width:jt(i.width),height:o});else{let a=1;for(const c of i.children)n.push({id:c.id,artifactID:c.artifactID,col:a,row:s,width:jt(c.width),height:o}),a+=jt(c.width)}s+=o}return{id:e.id,type:"stack",width:n.reduce((r,i)=>Math.max(r,i.col+i.width-1),1),cards:n}}function tp(e){let t=0,n=0;for(const r of e)r.height===It?n+=1:t+=r.height;const s=n>0?(We-t)/n:0;return e.map(r=>Pl(r.height,s))}function Pl(e,t){return e===It?t:e}function _t(e){return{...e}}function Qi(e){return e.type==="card"?_t(e):{...e,children:e.children.map(_t)}}const zi="create-artifact",$i="remove-artifact",lr="update-layout";class np extends cn{constructor(n){var r;super();m(this,"artifacts",new Map);m(this,"activeWorkspaceID",null);m(this,"scrollPosition",0);m(this,"activeWorkspaceData",null);m(this,"clientStore");m(this,"serverManager");m(this,"pendingMutations",new Map);m(this,"pendingWorkspaceCreates",new Map);m(this,"pendingWorkspaceDeletes",new Map);this.clientStore=n.clientStore,this.serverManager=n.serverManager;const s=this.clientStore.get();this.activeWorkspaceID=(s==null?void 0:s.lastWorkspaceID)??null,this.activeWorkspaceID&&(this.scrollPosition=((r=s==null?void 0:s.workspaces[this.activeWorkspaceID])==null?void 0:r.scrollPosition)??0)}get workspaces(){return[...this.serverManager.servers.values()].flatMap(n=>[...n.workspaces.values()])}get activeWorkspace(){return this.activeWorkspaceData}get activeWorkspaceServerURL(){var n;return this.activeWorkspaceID?((n=this.findWorkspace(this.activeWorkspaceID))==null?void 0:n.serverURL)??null:null}get activeArtifacts(){return(this.activeWorkspaceData?Ci(this.activeWorkspaceData):[]).map(n=>this.artifacts.get(n)).filter(n=>n!==void 0)}getArtifactURL(n){const s=this.activeWorkspaceServerURL;if(!s)return null;const r=this.serverManager.servers.get(s);return r!=null&&r.getArtifactURL?r.getArtifactURL(n):null}setActiveWorkspace(n){this.selectWorkspace(n)}setScrollPosition(n){const s=Math.max(0,n);this.scrollPosition!==s&&(this.scrollPosition=s,this.persistWorkspaceViewState(),this.dispatchEvent(new B("change")))}createArtifact(n){var c;const s=this.activeWorkspaceData;if(!s)return;const r=this.snapshotState(),i=jd({id:Wn(),type:kl,title:n.title,content:n.content});Ji(s.layout,i.id)||(s.layout=[...s.layout,Xi(i.id)]),this.artifacts.set(i.id,i),this.scrollPosition=sp(s.layout),this.persistWorkspaceViewState(),this.dispatchEvent(new B("change"));const o=((c=this.findWorkspace(s.id))==null?void 0:c.server)??null,a=this.getMutationKey(zi,i.id);this.pendingMutations.set(a,r),this.sendServerMessage(o,{type:"create-artifact",id:i.id,title:n.title,content:n.content,workspaceID:s.id})||(this.pendingMutations.delete(a),this.restoreState(r),this.dispatchEvent(new B("change")))}removeArtifact(n){var a;const s=this.activeWorkspaceData;if(!s||!this.artifacts.has(n))return;const r=this.snapshotState();this.removeArtifactLocally(n),this.dispatchEvent(new B("change"));const i=((a=this.findWorkspace(s.id))==null?void 0:a.server)??null,o=this.getMutationKey($i,n);this.pendingMutations.set(o,r),this.sendServerMessage(i,{type:"remove-artifact",artifactID:n,workspaceID:s.id})||(this.pendingMutations.delete(o),this.restoreState(r),this.dispatchEvent(new B("change")))}handleServerEvent(n,s){var r;switch(s.type){case"workspace-list":this.syncActiveWorkspaceState(n,!0);break;case"workspace-updated":this.syncActiveWorkspaceState(n,!1),Array.isArray(s.fields.layout)&&this.pendingMutations.delete(this.getMutationKey(lr,s.workspaceID));break;case"workspace-removed":{this.syncActiveWorkspaceState(n,!1);const i=this.pendingWorkspaceDeletes.get(s.workspaceID);i&&(this.pendingWorkspaceDeletes.delete(s.workspaceID),i.resolve());break}case"workspace-created":if(this.pendingWorkspaceCreates.has(s.workspace.id)){const i=this.pendingWorkspaceCreates.get(s.workspace.id);this.pendingWorkspaceCreates.delete(s.workspace.id),this.selectWorkspace(s.workspace.id),i==null||i.resolve();return}this.syncActiveWorkspaceState(n,!1);break;case"workspace":this.applyWorkspaceSnapshot(s.workspace,s.artifacts);break;case"artifact-created":this.pendingMutations.delete(this.getMutationKey(zi,s.artifact.id)),this.applyArtifactCreated(s);break;case"artifact-updated":this.applyArtifactUpdated(s);break;case"artifact-removed":if(this.pendingMutations.delete(this.getMutationKey($i,s.artifactID)),((r=this.activeWorkspaceData)==null?void 0:r.id)!==s.workspaceID)return;this.removeArtifactLocally(s.artifactID)&&this.dispatchEvent(new B("change"));break;case"error":this.handleServerError(s);break}}createWorkspace(n,s){const r=this.serverManager.servers.get(n)??null,i=Wn(),o=nc();return this.pendingWorkspaceCreates.set(i,o),this.sendServerMessage(r,{type:"create-workspace",id:i,name:s})||(this.pendingWorkspaceCreates.delete(i),o.reject(new Error(`Server unavailable: ${n}`))),o.promise}deleteWorkspace(){var o;const n=this.activeWorkspaceData;if(!n)return Promise.reject(new Error("No active workspace"));const s=this.pendingWorkspaceDeletes.get(n.id);if(s)return s.promise;const r=((o=this.findWorkspace(n.id))==null?void 0:o.server)??null,i=nc();return this.pendingWorkspaceDeletes.set(n.id,i),this.sendServerMessage(r,{type:"delete-workspace",workspaceID:n.id})||(this.pendingWorkspaceDeletes.delete(n.id),i.reject(new Error(`Server unavailable: ${n.id}`))),i.promise}renameWorkspace(n){var i;const s=this.activeWorkspaceData;if(!s)return;const r=((i=this.findWorkspace(s.id))==null?void 0:i.server)??null;s.name=n,this.dispatchEvent(new B("change")),this.sendServerMessage(r,{type:"update-workspace",workspaceID:s.id,fields:{name:n}})}setLayout(n){var l;const s=this.activeWorkspaceData;if(!s)return;const r=xl(n);if(!Al(r).valid)return;const o=this.snapshotState();s.layout=r,this.dispatchEvent(new B("change"));const a=((l=this.findWorkspace(s.id))==null?void 0:l.server)??null,c=this.getMutationKey(lr,s.id);this.pendingMutations.set(c,o),this.sendServerMessage(a,{type:"update-workspace",workspaceID:s.id,fields:{layout:r.map(h=>structuredClone(h))}})||(this.pendingMutations.delete(c),this.restoreState(o),this.dispatchEvent(new B("change")))}syncActiveWorkspaceState(n,s){const r=this.activeWorkspaceID?this.findWorkspace(this.activeWorkspaceID):null;if(!r){const i=this.pickNextWorkspace();if(!i){const o=this.activeWorkspaceID!==null||this.activeWorkspaceData!==null||this.artifacts.size>0;this.activeWorkspaceID=null,this.activeWorkspaceData=null,this.artifacts.clear(),this.scrollPosition=0,o&&this.dispatchEvent(new B("change"));return}this.selectWorkspace(i.workspace.id);return}this.applyServerWorkspaceState(r.workspace),s&&r.serverURL===n&&this.requestWorkspace(r.serverURL,r.workspace.id)}hasPendingLayoutMutation(n){return this.pendingMutations.has(this.getMutationKey(lr,n))}selectWorkspace(n){const s=this.findWorkspace(n);s&&(this.activeWorkspaceID=n,this.activeWorkspaceData=structuredClone(s.workspace),this.artifacts.clear(),this.restoreWorkspaceViewState(),this.persistActiveWorkspace(),this.requestWorkspace(s.serverURL,n),this.dispatchEvent(new B("change")))}requestWorkspace(n,s){const r=this.serverManager.servers.get(n);this.sendServerMessage(r??null,{type:"get-workspace",workspaceID:s})}applyWorkspaceSnapshot(n,s){if(n.id===this.activeWorkspaceID){this.applyServerWorkspaceState(n),this.artifacts.clear();for(const r of s)this.artifacts.set(r.id,structuredClone(r));this.restoreWorkspaceViewState(),this.dispatchEvent(new B("change"))}}applyServerWorkspaceState(n){if(!this.activeWorkspaceData||this.activeWorkspaceData.id!==n.id){this.activeWorkspaceData=structuredClone(n);return}this.activeWorkspaceData.name=n.name,this.hasPendingLayoutMutation(n.id)||(this.activeWorkspaceData.layout=n.layout.map(s=>structuredClone(s)))}applyArtifactCreated(n){var s;((s=this.activeWorkspaceData)==null?void 0:s.id)===n.workspaceID&&(Ji(this.activeWorkspaceData.layout,n.artifact.id)||(this.activeWorkspaceData.layout=[...this.activeWorkspaceData.layout,Xi(n.artifact.id)]),this.artifacts.set(n.artifact.id,n.artifact),this.dispatchEvent(new B("change")))}applyArtifactUpdated(n){const s=this.artifacts.get(n.artifactID);s&&(Object.assign(s,n.fields),this.dispatchEvent(new B("change")))}removeArtifactLocally(n){if(!this.activeWorkspaceData)return!1;const s=this.artifacts.delete(n),r=Ci(this.activeWorkspaceData).length;return this.activeWorkspaceData.layout=El(this.activeWorkspaceData.layout,n),!(!s&&r===Ci(this.activeWorkspaceData).length)}snapshotState(){return{activeWorkspaceData:this.activeWorkspaceData?structuredClone(this.activeWorkspaceData):null,scrollPosition:this.scrollPosition,artifacts:new Map([...this.artifacts.entries()].map(([n,s])=>[n,structuredClone(s)]))}}restoreState(n){this.activeWorkspaceData=n.activeWorkspaceData?structuredClone(n.activeWorkspaceData):null,this.scrollPosition=n.scrollPosition,this.artifacts.clear();for(const[s,r]of n.artifacts.entries())this.artifacts.set(s,structuredClone(r));this.persistWorkspaceViewState()}handleServerError(n){const s=n.request;if(s){if(s.type==="create-artifact"){const r=this.getMutationKey(zi,s.id),i=this.pendingMutations.get(r);if(!i)return;this.pendingMutations.delete(r),this.restoreState(i),this.dispatchEvent(new B("change"));return}if(s.type==="create-workspace"){const r=this.pendingWorkspaceCreates.get(s.id);if(!r)return;this.pendingWorkspaceCreates.delete(s.id),r.reject(new Error(n.message));return}if(s.type==="delete-workspace"){const r=this.pendingWorkspaceDeletes.get(s.workspaceID);if(!r)return;this.pendingWorkspaceDeletes.delete(s.workspaceID),r.reject(new Error(n.message));return}if(s.type==="update-workspace"&&Array.isArray(s.fields.layout)){const r=this.getMutationKey(lr,s.workspaceID),i=this.pendingMutations.get(r);if(!i)return;this.pendingMutations.delete(r),this.restoreState(i),this.dispatchEvent(new B("change"));return}if(s.type==="remove-artifact"){const r=this.getMutationKey($i,s.artifactID),i=this.pendingMutations.get(r);if(!i)return;this.pendingMutations.delete(r),this.restoreState(i),this.dispatchEvent(new B("change"))}}}restoreWorkspaceViewState(){var s,r;if(!this.activeWorkspaceID){this.scrollPosition=0;return}const n=((r=(s=this.clientStore.get())==null?void 0:s.workspaces[this.activeWorkspaceID])==null?void 0:r.scrollPosition)??0;this.scrollPosition=Math.max(0,n),this.persistWorkspaceViewState()}persistActiveWorkspace(){this.clientStore.update(n=>{n.lastWorkspaceID=this.activeWorkspaceID})}persistWorkspaceViewState(){this.activeWorkspaceID&&this.clientStore.update(n=>{var s,r;(s=n.workspaces)[r=this.activeWorkspaceID]??(s[r]={scrollPosition:0}),n.workspaces[this.activeWorkspaceID].scrollPosition=this.scrollPosition})}findWorkspace(n){for(const[s,r]of this.serverManager.servers){const i=r.workspaces.get(n);if(i)return{serverURL:s,server:r,workspace:i}}return null}pickNextWorkspace(){var s;const n=(s=this.clientStore.get())==null?void 0:s.lastWorkspaceID;if(n){const r=this.findWorkspace(n);if(r)return r}for(const[r,i]of this.serverManager.servers){const o=i.workspaces.values().next().value;if(o)return{serverURL:r,server:i,workspace:o}}return null}sendServerMessage(n,s){return n?n.send(s):!1}getServers(){return this.serverManager.servers}getMutationKey(n,s){return`${n}:${s}`}}function sp(e){var s;const t=In(e);if(t.nodes.length<=1)return 0;let n=0;for(let r=0;r<t.nodes.length-1;r+=1)n+=((s=t.nodes[r])==null?void 0:s.width)??0;return n}function nc(){let e,t;return{promise:new Promise((s,r)=>{e=s,t=r}),resolve:e,reject:t}}var Dl=Symbol.for("immer-nothing"),sc=Symbol.for("immer-draftable"),Fe=Symbol.for("immer-state");function Ye(e,...t){throw new Error(`[Immer] minified error nr: ${e}. Full error at: https://bit.ly/3cXEKWf`)}var ys=Object.getPrototypeOf;function Fn(e){return!!e&&!!e[Fe]}function en(e){var t;return e?Ll(e)||Array.isArray(e)||!!e[sc]||!!((t=e.constructor)!=null&&t[sc])||Ks(e)||ti(e):!1}var rp=Object.prototype.constructor.toString(),rc=new WeakMap;function Ll(e){if(!e||typeof e!="object")return!1;const t=Object.getPrototypeOf(e);if(t===null||t===Object.prototype)return!0;const n=Object.hasOwnProperty.call(t,"constructor")&&t.constructor;if(n===Object)return!0;if(typeof n!="function")return!1;let s=rc.get(n);return s===void 0&&(s=Function.toString.call(n),rc.set(n,s)),s===rp}function Pr(e,t,n=!0){ei(e)===0?(n?Reflect.ownKeys(e):Object.keys(e)).forEach(r=>{t(r,e[r],e)}):e.forEach((s,r)=>t(r,s,e))}function ei(e){const t=e[Fe];return t?t.type_:Array.isArray(e)?1:Ks(e)?2:ti(e)?3:0}function eo(e,t){return ei(e)===2?e.has(t):Object.prototype.hasOwnProperty.call(e,t)}function Ml(e,t,n){const s=ei(e);s===2?e.set(t,n):s===3?e.add(n):e[t]=n}function ip(e,t){return e===t?e!==0||1/e===1/t:e!==e&&t!==t}function Ks(e){return e instanceof Map}function ti(e){return e instanceof Set}function Wt(e){return e.copy_||e.base_}function to(e,t){if(Ks(e))return new Map(e);if(ti(e))return new Set(e);if(Array.isArray(e))return Array.prototype.slice.call(e);const n=Ll(e);if(t===!0||t==="class_only"&&!n){const s=Object.getOwnPropertyDescriptors(e);delete s[Fe];let r=Reflect.ownKeys(s);for(let i=0;i<r.length;i++){const o=r[i],a=s[o];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(s[o]={configurable:!0,writable:!0,enumerable:a.enumerable,value:e[o]})}return Object.create(ys(e),s)}else{const s=ys(e);if(s!==null&&n)return{...e};const r=Object.create(s);return Object.assign(r,e)}}function Ho(e,t=!1){return ni(e)||Fn(e)||!en(e)||(ei(e)>1&&Object.defineProperties(e,{set:ur,add:ur,clear:ur,delete:ur}),Object.freeze(e),t&&Object.values(e).forEach(n=>Ho(n,!0))),e}function op(){Ye(2)}var ur={value:op};function ni(e){return e===null||typeof e!="object"?!0:Object.isFrozen(e)}var ap={};function tn(e){const t=ap[e];return t||Ye(0,e),t}var ks;function Ol(){return ks}function cp(e,t){return{drafts_:[],parent_:e,immer_:t,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function ic(e,t){t&&(tn("Patches"),e.patches_=[],e.inversePatches_=[],e.patchListener_=t)}function no(e){so(e),e.drafts_.forEach(lp),e.drafts_=null}function so(e){e===ks&&(ks=e.parent_)}function oc(e){return ks=cp(ks,e)}function lp(e){const t=e[Fe];t.type_===0||t.type_===1?t.revoke_():t.revoked_=!0}function ac(e,t){t.unfinalizedDrafts_=t.drafts_.length;const n=t.drafts_[0];return e!==void 0&&e!==n?(n[Fe].modified_&&(no(t),Ye(4)),en(e)&&(e=Dr(t,e),t.parent_||Lr(t,e)),t.patches_&&tn("Patches").generateReplacementPatches_(n[Fe].base_,e,t.patches_,t.inversePatches_)):e=Dr(t,n,[]),no(t),t.patches_&&t.patchListener_(t.patches_,t.inversePatches_),e!==Dl?e:void 0}function Dr(e,t,n){if(ni(t))return t;const s=e.immer_.shouldUseStrictIteration(),r=t[Fe];if(!r)return Pr(t,(i,o)=>cc(e,r,t,i,o,n),s),t;if(r.scope_!==e)return t;if(!r.modified_)return Lr(e,r.base_,!0),r.base_;if(!r.finalized_){r.finalized_=!0,r.scope_.unfinalizedDrafts_--;const i=r.copy_;let o=i,a=!1;r.type_===3&&(o=new Set(i),i.clear(),a=!0),Pr(o,(c,l)=>cc(e,r,i,c,l,n,a),s),Lr(e,i,!1),n&&e.patches_&&tn("Patches").generatePatches_(r,n,e.patches_,e.inversePatches_)}return r.copy_}function cc(e,t,n,s,r,i,o){if(r==null||typeof r!="object"&&!o)return;const a=ni(r);if(!(a&&!o)){if(Fn(r)){const c=i&&t&&t.type_!==3&&!eo(t.assigned_,s)?i.concat(s):void 0,l=Dr(e,r,c);if(Ml(n,s,l),Fn(l))e.canAutoFreeze_=!1;else return}else o&&n.add(r);if(en(r)&&!a){if(!e.immer_.autoFreeze_&&e.unfinalizedDrafts_<1||t&&t.base_&&t.base_[s]===r&&a)return;Dr(e,r),(!t||!t.scope_.parent_)&&typeof s!="symbol"&&(Ks(n)?n.has(s):Object.prototype.propertyIsEnumerable.call(n,s))&&Lr(e,r)}}}function Lr(e,t,n=!1){!e.parent_&&e.immer_.autoFreeze_&&e.canAutoFreeze_&&Ho(t,n)}function up(e,t){const n=Array.isArray(e),s={type_:n?1:0,scope_:t?t.scope_:Ol(),modified_:!1,finalized_:!1,assigned_:{},parent_:t,base_:e,draft_:null,copy_:null,revoke_:null,isManual_:!1};let r=s,i=Bo;n&&(r=[s],i=ws);const{revoke:o,proxy:a}=Proxy.revocable(r,i);return s.draft_=a,s.revoke_=o,a}var Bo={get(e,t){if(t===Fe)return e;const n=Wt(e);if(!eo(n,t))return hp(e,n,t);const s=n[t];return e.finalized_||!en(s)?s:s===Ri(e.base_,t)?(Pi(e),e.copy_[t]=io(s,e)):s},has(e,t){return t in Wt(e)},ownKeys(e){return Reflect.ownKeys(Wt(e))},set(e,t,n){const s=Nl(Wt(e),t);if(s!=null&&s.set)return s.set.call(e.draft_,n),!0;if(!e.modified_){const r=Ri(Wt(e),t),i=r==null?void 0:r[Fe];if(i&&i.base_===n)return e.copy_[t]=n,e.assigned_[t]=!1,!0;if(ip(n,r)&&(n!==void 0||eo(e.base_,t)))return!0;Pi(e),ro(e)}return e.copy_[t]===n&&(n!==void 0||t in e.copy_)||Number.isNaN(n)&&Number.isNaN(e.copy_[t])||(e.copy_[t]=n,e.assigned_[t]=!0),!0},deleteProperty(e,t){return Ri(e.base_,t)!==void 0||t in e.base_?(e.assigned_[t]=!1,Pi(e),ro(e)):delete e.assigned_[t],e.copy_&&delete e.copy_[t],!0},getOwnPropertyDescriptor(e,t){const n=Wt(e),s=Reflect.getOwnPropertyDescriptor(n,t);return s&&{writable:!0,configurable:e.type_!==1||t!=="length",enumerable:s.enumerable,value:n[t]}},defineProperty(){Ye(11)},getPrototypeOf(e){return ys(e.base_)},setPrototypeOf(){Ye(12)}},ws={};Pr(Bo,(e,t)=>{ws[e]=function(){return arguments[0]=arguments[0][0],t.apply(this,arguments)}});ws.deleteProperty=function(e,t){return ws.set.call(this,e,t,void 0)};ws.set=function(e,t,n){return Bo.set.call(this,e[0],t,n,e[0])};function Ri(e,t){const n=e[Fe];return(n?Wt(n):e)[t]}function hp(e,t,n){var r;const s=Nl(t,n);return s?"value"in s?s.value:(r=s.get)==null?void 0:r.call(e.draft_):void 0}function Nl(e,t){if(!(t in e))return;let n=ys(e);for(;n;){const s=Object.getOwnPropertyDescriptor(n,t);if(s)return s;n=ys(n)}}function ro(e){e.modified_||(e.modified_=!0,e.parent_&&ro(e.parent_))}function Pi(e){e.copy_||(e.copy_=to(e.base_,e.scope_.immer_.useStrictShallowCopy_))}var dp=class{constructor(e){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(t,n,s)=>{if(typeof t=="function"&&typeof n!="function"){const i=n;n=t;const o=this;return function(c=i,...l){return o.produce(c,h=>n.call(this,h,...l))}}typeof n!="function"&&Ye(6),s!==void 0&&typeof s!="function"&&Ye(7);let r;if(en(t)){const i=oc(this),o=io(t,void 0);let a=!0;try{r=n(o),a=!1}finally{a?no(i):so(i)}return ic(i,s),ac(r,i)}else if(!t||typeof t!="object"){if(r=n(t),r===void 0&&(r=t),r===Dl&&(r=void 0),this.autoFreeze_&&Ho(r,!0),s){const i=[],o=[];tn("Patches").generateReplacementPatches_(t,r,i,o),s(i,o)}return r}else Ye(1,t)},this.produceWithPatches=(t,n)=>{if(typeof t=="function")return(o,...a)=>this.produceWithPatches(o,c=>t(c,...a));let s,r;return[this.produce(t,n,(o,a)=>{s=o,r=a}),s,r]},typeof(e==null?void 0:e.autoFreeze)=="boolean"&&this.setAutoFreeze(e.autoFreeze),typeof(e==null?void 0:e.useStrictShallowCopy)=="boolean"&&this.setUseStrictShallowCopy(e.useStrictShallowCopy),typeof(e==null?void 0:e.useStrictIteration)=="boolean"&&this.setUseStrictIteration(e.useStrictIteration)}createDraft(e){en(e)||Ye(8),Fn(e)&&(e=pp(e));const t=oc(this),n=io(e,void 0);return n[Fe].isManual_=!0,so(t),n}finishDraft(e,t){const n=e&&e[Fe];(!n||!n.isManual_)&&Ye(9);const{scope_:s}=n;return ic(s,t),ac(void 0,s)}setAutoFreeze(e){this.autoFreeze_=e}setUseStrictShallowCopy(e){this.useStrictShallowCopy_=e}setUseStrictIteration(e){this.useStrictIteration_=e}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(e,t){let n;for(n=t.length-1;n>=0;n--){const r=t[n];if(r.path.length===0&&r.op==="replace"){e=r.value;break}}n>-1&&(t=t.slice(n+1));const s=tn("Patches").applyPatches_;return Fn(e)?s(e,t):this.produce(e,r=>s(r,t))}};function io(e,t){const n=Ks(e)?tn("MapSet").proxyMap_(e,t):ti(e)?tn("MapSet").proxySet_(e,t):up(e,t);return(t?t.scope_:Ol()).drafts_.push(n),n}function pp(e){return Fn(e)||Ye(10,e),Wl(e)}function Wl(e){if(!en(e)||ni(e))return e;const t=e[Fe];let n,s=!0;if(t){if(!t.modified_)return t.base_;t.finalized_=!0,n=to(e,t.scope_.immer_.useStrictShallowCopy_),s=t.scope_.immer_.shouldUseStrictIteration()}else n=to(e,!0);return Pr(n,(r,i)=>{Ml(n,r,Wl(i))},s),t&&(t.finalized_=!1),n}var fp=new dp,gp=fp.produce,mp=Object.defineProperty,vp=(e,t,n)=>t in e?mp(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,hr=(e,t,n)=>vp(e,typeof t!="symbol"?t+"":t,n);function _p(e){return{all:e=e||new Map,on:function(t,n){var s=e.get(t);s?s.push(n):e.set(t,[n])},off:function(t,n){var s=e.get(t);s&&(n?s.splice(s.indexOf(n)>>>0,1):e.set(t,[]))},emit:function(t,n){var s=e.get(t);s&&s.slice().map(function(r){r(n)}),(s=e.get("*"))&&s.slice().map(function(r){r(t,n)})}}}var yp=class{constructor(){hr(this,"emitter",_p()),hr(this,"on",(e,t)=>(this.emitter.on(e,t),{dispose:()=>this.emitter.off(e,t)})),hr(this,"once",(e,t)=>{const n=s=>{t(s),this.emitter.off(e,n)};return this.emitter.on(e,n),{dispose:()=>this.emitter.off(e,n)}}),hr(this,"off",this.emitter.off)}emit(e,...[t]){this.emitter.emit(e,t)}},kp="store-",wp=class extends yp{emitChange(e){this.emit("change",{state:e})}},bp=class{constructor(e,t,n){this.emitter=new wp,this.id=e,this.initValue=t,this.key=`${kp}${e}`,this.storage=(n==null?void 0:n.storage)==="session"?sessionStorage:localStorage,this.get()===void 0&&this.storage.setItem(this.key,JSON.stringify(t))}get(){const e=this.storage.getItem(this.key);return e===null?void 0:JSON.parse(e)}update(e){const t=this.get()??{},n=gp(t,e);this.storage.setItem(this.key,JSON.stringify(n)),this.emitter.emitChange(n)}reset(){this.storage.setItem(this.key,JSON.stringify(this.initValue)),this.emitter.emitChange(this.initValue)}on(e,t){return this.emitter.on(e,({state:n})=>t(n))}subscribe(e){const t=this.on("change",e),n=this.get();return n!==void 0&&e(n),t}};const Sp="Local";function kt(e){return new URL(e).origin}function xp(e){return{servers:[{url:kt(e),name:Sp}],lastWorkspaceID:null,workspaces:{}}}function Ep(e,t){return new bp(e,xp(t))}const Ap=4401;class oo extends Error{constructor(t="Authentication required"){super(t),this.name="AuthError"}}class ao extends cn{constructor(n){super();m(this,"url");m(this,"name");m(this,"token");m(this,"status","disconnected");m(this,"workspaces",new Map);m(this,"createSocket");m(this,"socket",null);m(this,"connectAttempt",0);this.url=kt(n.url),this.name=n.name,this.token=n.token??null,this.createSocket=n.createSocket??(s=>new WebSocket(s))}async connect(){var r;this.connectAttempt+=1;const n=this.connectAttempt;(r=this.socket)==null||r.close(),this.status="connecting",this.dispatchEvent(new B("change"));const s=this.createSocket(Tp(this.url,this.token));return this.socket=s,await new Promise((i,o)=>{let a=!1;const c=()=>{a||this.connectAttempt!==n||(a=!0,this.status="connected",this.dispatchEvent(new B("change")),i())},l=h=>{a||this.connectAttempt!==n||(a=!0,this.status="disconnected",this.dispatchEvent(new B("change")),o(h))};s.addEventListener("message",h=>{const f=Cp(h);this.applyServerMessage(f),this.dispatchEvent(new vl("server-message",{serverURL:this.url,message:f})),a||c()}),s.addEventListener("close",h=>{if(this.connectAttempt===n){if(this.socket=null,Ip(h)===Ap){l(new oo);return}if(!a){l(new Error("Connection closed before initialization"));return}this.status="disconnected",this.dispatchEvent(new B("change"))}}),s.addEventListener("error",()=>{l(new Error("WebSocket connection failed"))})})}disconnect(){var n;this.connectAttempt+=1,(n=this.socket)==null||n.close(),this.socket=null,this.status="disconnected",this.dispatchEvent(new B("change"))}send(n){return!this.socket||this.socket.readyState!==1?!1:(this.socket.send(JSON.stringify(n)),!0)}getArtifactURL(n){const s=new URL(this.url);return s.pathname=`/artifact/${n}`,s.search="",this.token&&s.searchParams.set("token",this.token),s.hash="",s.toString()}applyServerMessage(n){switch(n.type){case"workspace-list":this.workspaces=new Map(n.workspaces.map(s=>[s.id,structuredClone(s)]));break;case"workspace-created":this.workspaces.set(n.workspace.id,structuredClone(n.workspace));break;case"workspace-updated":{const s=this.workspaces.get(n.workspaceID);s&&(typeof n.fields.name=="string"&&(s.name=n.fields.name),Array.isArray(n.fields.layout)&&(s.layout=n.fields.layout));break}case"workspace-removed":this.workspaces.delete(n.workspaceID);break;case"artifact-created":{const s=this.workspaces.get(n.workspaceID);s&&!Ji(s.layout,n.artifact.id)&&(s.layout=[...s.layout,Xi(n.artifact.id)]);break}case"artifact-removed":{const s=this.workspaces.get(n.workspaceID);s&&(s.layout=El(s.layout,n.artifactID));break}}}}function Tp(e,t){const n=new URL(e);return n.protocol=n.protocol==="https:"?"wss:":"ws:",n.pathname="/ws",n.search="",t&&n.searchParams.set("token",t),n.hash="",n.toString()}function Ip(e){return typeof e=="object"&&e!==null&&"code"in e&&typeof e.code=="number"?e.code:null}function Cp(e){const t=typeof e=="string"?e:typeof e=="object"&&e!==null&&"data"in e&&typeof e.data=="string"?e.data:"";return JSON.parse(t)}class zp extends cn{constructor(n){super();m(this,"servers",new Map);m(this,"localServerURL");m(this,"activeServer",null);m(this,"clientStore");m(this,"createSocket");m(this,"serverListeners",new Map);this.clientStore=n.clientStore,this.localServerURL=n.localServerURL?kt(n.localServerURL):null,this.createSocket=n.createSocket??(s=>new WebSocket(s))}add(n){const s=kt(n.url);this.servers.get(s)&&this.remove(s),this.servers.set(s,n);const i=()=>{this.dispatchEvent(new B("change"))},o=a=>{this.dispatchEvent(new vl("server-message",{serverURL:a.serverURL,message:a.message}))};n.addEventListener("change",i),n.addEventListener("server-message",o),this.serverListeners.set(s,{onServerChange:i,onServerMessage:o}),this.dispatchEvent(new B("change"))}remove(n){const s=kt(n);if(this.localServerURL&&s===this.localServerURL)return;const r=this.servers.get(s);if(!r)return;const i=this.serverListeners.get(s);i&&(r.removeEventListener("change",i.onServerChange),r.removeEventListener("server-message",i.onServerMessage),this.serverListeners.delete(s)),r.disconnect(),this.servers.delete(s),this.activeServer===r&&(this.activeServer=null),this.clientStore.update(o=>{o.servers=o.servers.filter(a=>a.url!==s)}),this.dispatchEvent(new B("change"))}setActive(n){this.activeServer=n,this.dispatchEvent(new B("change"))}connectConfiguredServers(n){var i;const s=((i=this.clientStore.get())==null?void 0:i.servers)??[];for(const o of s){const a=new ao({url:o.url,name:o.name,createSocket:this.createSocket});this.add(a),a.connect().catch(()=>{})}const r=n?this.servers.get(kt(n))??null:null;this.setActive(r??this.servers.values().next().value??null)}addServer(n,s){const r=kt(n);this.remove(r),this.clientStore.update(o=>{o.servers=o.servers.filter(a=>kt(a.url)!==r),o.servers.push({url:r,name:s})});const i=new ao({url:r,name:s,createSocket:this.createSocket});this.add(i),this.setActive(i),i.connect().catch(()=>{})}removeServer(n){this.remove(n)}}function b(e,t,n){function s(a,c){if(a._zod||Object.defineProperty(a,"_zod",{value:{def:c,constr:o,traits:new Set},enumerable:!1}),a._zod.traits.has(e))return;a._zod.traits.add(e),t(a,c);const l=o.prototype,h=Object.keys(l);for(let f=0;f<h.length;f++){const w=h[f];w in a||(a[w]=l[w].bind(a))}}const r=(n==null?void 0:n.Parent)??Object;class i extends r{}Object.defineProperty(i,"name",{value:e});function o(a){var c;const l=n!=null&&n.Parent?new i:this;s(l,a),(c=l._zod).deferred??(c.deferred=[]);for(const h of l._zod.deferred)h();return l}return Object.defineProperty(o,"init",{value:s}),Object.defineProperty(o,Symbol.hasInstance,{value:a=>{var c,l;return n!=null&&n.Parent&&a instanceof n.Parent?!0:(l=(c=a==null?void 0:a._zod)==null?void 0:c.traits)==null?void 0:l.has(e)}}),Object.defineProperty(o,"name",{value:e}),o}class Cn extends Error{constructor(){super("Encountered Promise during synchronous parse. Use .parseAsync() instead.")}}class Fl extends Error{constructor(t){super(`Encountered unidirectional transform during encode: ${t}`),this.name="ZodEncodeError"}}const Ul={};function Ct(e){return Ul}function Zl(e){const t=Object.values(e).filter(s=>typeof s=="number");return Object.entries(e).filter(([s,r])=>t.indexOf(+s)===-1).map(([s,r])=>r)}function co(e,t){return typeof t=="bigint"?t.toString():t}function Go(e){return{get value(){{const t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function Vo(e){return e==null}function qo(e){const t=e.startsWith("^")?1:0,n=e.endsWith("$")?e.length-1:e.length;return e.slice(t,n)}function $p(e,t){const n=(e.toString().split(".")[1]||"").length,s=t.toString();let r=(s.split(".")[1]||"").length;if(r===0&&/\d?e-\d?/.test(s)){const c=s.match(/\d?e-(\d?)/);c!=null&&c[1]&&(r=Number.parseInt(c[1]))}const i=n>r?n:r,o=Number.parseInt(e.toFixed(i).replace(".","")),a=Number.parseInt(t.toFixed(i).replace(".",""));return o%a/10**i}const lc=Symbol("evaluating");function Y(e,t,n){let s;Object.defineProperty(e,t,{get(){if(s!==lc)return s===void 0&&(s=lc,s=n()),s},set(r){Object.defineProperty(e,t,{value:r})},configurable:!0})}function ln(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function Pt(...e){const t={};for(const n of e){const s=Object.getOwnPropertyDescriptors(n);Object.assign(t,s)}return Object.defineProperties({},t)}function uc(e){return JSON.stringify(e)}function Rp(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,"").replace(/[\s_-]+/g,"-").replace(/^-+|-+$/g,"")}const jl="captureStackTrace"in Error?Error.captureStackTrace:(...e)=>{};function Mr(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const Pp=Go(()=>{var e;if(typeof navigator<"u"&&((e=navigator==null?void 0:navigator.userAgent)!=null&&e.includes("Cloudflare")))return!1;try{const t=Function;return new t(""),!0}catch{return!1}});function Un(e){if(Mr(e)===!1)return!1;const t=e.constructor;if(t===void 0||typeof t!="function")return!0;const n=t.prototype;return!(Mr(n)===!1||Object.prototype.hasOwnProperty.call(n,"isPrototypeOf")===!1)}function Hl(e){return Un(e)?{...e}:Array.isArray(e)?[...e]:e}const Dp=new Set(["string","number","symbol"]);function Zn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Dt(e,t,n){const s=new e._zod.constr(t??e._zod.def);return(!t||n!=null&&n.parent)&&(s._zod.parent=e),s}function P(e){const t=e;if(!t)return{};if(typeof t=="string")return{error:()=>t};if((t==null?void 0:t.message)!==void 0){if((t==null?void 0:t.error)!==void 0)throw new Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error=="string"?{...t,error:()=>t.error}:t}function Lp(e){return Object.keys(e).filter(t=>e[t]._zod.optin==="optional"&&e[t]._zod.optout==="optional")}const Mp={safeint:[Number.MIN_SAFE_INTEGER,Number.MAX_SAFE_INTEGER],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]};function Op(e,t){const n=e._zod.def,s=n.checks;if(s&&s.length>0)throw new Error(".pick() cannot be used on object schemas containing refinements");const i=Pt(e._zod.def,{get shape(){const o={};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&(o[a]=n.shape[a])}return ln(this,"shape",o),o},checks:[]});return Dt(e,i)}function Np(e,t){const n=e._zod.def,s=n.checks;if(s&&s.length>0)throw new Error(".omit() cannot be used on object schemas containing refinements");const i=Pt(e._zod.def,{get shape(){const o={...e._zod.def.shape};for(const a in t){if(!(a in n.shape))throw new Error(`Unrecognized key: "${a}"`);t[a]&&delete o[a]}return ln(this,"shape",o),o},checks:[]});return Dt(e,i)}function Wp(e,t){if(!Un(t))throw new Error("Invalid input to extend: expected a plain object");const n=e._zod.def.checks;if(n&&n.length>0){const i=e._zod.def.shape;for(const o in t)if(Object.getOwnPropertyDescriptor(i,o)!==void 0)throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}const r=Pt(e._zod.def,{get shape(){const i={...e._zod.def.shape,...t};return ln(this,"shape",i),i}});return Dt(e,r)}function Fp(e,t){if(!Un(t))throw new Error("Invalid input to safeExtend: expected a plain object");const n=Pt(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t};return ln(this,"shape",s),s}});return Dt(e,n)}function Up(e,t){const n=Pt(e._zod.def,{get shape(){const s={...e._zod.def.shape,...t._zod.def.shape};return ln(this,"shape",s),s},get catchall(){return t._zod.def.catchall},checks:[]});return Dt(e,n)}function Zp(e,t,n){const r=t._zod.def.checks;if(r&&r.length>0)throw new Error(".partial() cannot be used on object schemas containing refinements");const o=Pt(t._zod.def,{get shape(){const a=t._zod.def.shape,c={...a};if(n)for(const l in n){if(!(l in a))throw new Error(`Unrecognized key: "${l}"`);n[l]&&(c[l]=e?new e({type:"optional",innerType:a[l]}):a[l])}else for(const l in a)c[l]=e?new e({type:"optional",innerType:a[l]}):a[l];return ln(this,"shape",c),c},checks:[]});return Dt(t,o)}function jp(e,t,n){const s=Pt(t._zod.def,{get shape(){const r=t._zod.def.shape,i={...r};if(n)for(const o in n){if(!(o in i))throw new Error(`Unrecognized key: "${o}"`);n[o]&&(i[o]=new e({type:"nonoptional",innerType:r[o]}))}else for(const o in r)i[o]=new e({type:"nonoptional",innerType:r[o]});return ln(this,"shape",i),i}});return Dt(t,s)}function An(e,t=0){var n;if(e.aborted===!0)return!0;for(let s=t;s<e.issues.length;s++)if(((n=e.issues[s])==null?void 0:n.continue)!==!0)return!0;return!1}function Tn(e,t){return t.map(n=>{var s;return(s=n).path??(s.path=[]),n.path.unshift(e),n})}function dr(e){return typeof e=="string"?e:e==null?void 0:e.message}function zt(e,t,n){var r,i,o,a,c,l;const s={...e,path:e.path??[]};if(!e.message){const h=dr((o=(i=(r=e.inst)==null?void 0:r._zod.def)==null?void 0:i.error)==null?void 0:o.call(i,e))??dr((a=t==null?void 0:t.error)==null?void 0:a.call(t,e))??dr((c=n.customError)==null?void 0:c.call(n,e))??dr((l=n.localeError)==null?void 0:l.call(n,e))??"Invalid input";s.message=h}return delete s.inst,delete s.continue,t!=null&&t.reportInput||delete s.input,s}function Ko(e){return Array.isArray(e)?"array":typeof e=="string"?"string":"unknown"}function bs(...e){const[t,n,s]=e;return typeof t=="string"?{message:t,code:"custom",input:n,inst:s}:{...t}}const Bl=(e,t)=>{e.name="$ZodError",Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,co,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Gl=b("$ZodError",Bl),Vl=b("$ZodError",Bl,{Parent:Error});function Hp(e,t=n=>n.message){const n={},s=[];for(const r of e.issues)r.path.length>0?(n[r.path[0]]=n[r.path[0]]||[],n[r.path[0]].push(t(r))):s.push(t(r));return{formErrors:s,fieldErrors:n}}function Bp(e,t=n=>n.message){const n={_errors:[]},s=r=>{for(const i of r.issues)if(i.code==="invalid_union"&&i.errors.length)i.errors.map(o=>s({issues:o}));else if(i.code==="invalid_key")s({issues:i.issues});else if(i.code==="invalid_element")s({issues:i.issues});else if(i.path.length===0)n._errors.push(t(i));else{let o=n,a=0;for(;a<i.path.length;){const c=i.path[a];a===i.path.length-1?(o[c]=o[c]||{_errors:[]},o[c]._errors.push(t(i))):o[c]=o[c]||{_errors:[]},o=o[c],a++}}};return s(e),n}const Yo=e=>(t,n,s,r)=>{const i=s?Object.assign(s,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise)throw new Cn;if(o.issues.length){const a=new((r==null?void 0:r.Err)??e)(o.issues.map(c=>zt(c,i,Ct())));throw jl(a,r==null?void 0:r.callee),a}return o.value},Xo=e=>async(t,n,s,r)=>{const i=s?Object.assign(s,{async:!0}):{async:!0};let o=t._zod.run({value:n,issues:[]},i);if(o instanceof Promise&&(o=await o),o.issues.length){const a=new((r==null?void 0:r.Err)??e)(o.issues.map(c=>zt(c,i,Ct())));throw jl(a,r==null?void 0:r.callee),a}return o.value},si=e=>(t,n,s)=>{const r=s?{...s,async:!1}:{async:!1},i=t._zod.run({value:n,issues:[]},r);if(i instanceof Promise)throw new Cn;return i.issues.length?{success:!1,error:new(e??Gl)(i.issues.map(o=>zt(o,r,Ct())))}:{success:!0,data:i.value}},Gp=si(Vl),ri=e=>async(t,n,s)=>{const r=s?Object.assign(s,{async:!0}):{async:!0};let i=t._zod.run({value:n,issues:[]},r);return i instanceof Promise&&(i=await i),i.issues.length?{success:!1,error:new e(i.issues.map(o=>zt(o,r,Ct())))}:{success:!0,data:i.value}},Vp=ri(Vl),qp=e=>(t,n,s)=>{const r=s?Object.assign(s,{direction:"backward"}):{direction:"backward"};return Yo(e)(t,n,r)},Kp=e=>(t,n,s)=>Yo(e)(t,n,s),Yp=e=>async(t,n,s)=>{const r=s?Object.assign(s,{direction:"backward"}):{direction:"backward"};return Xo(e)(t,n,r)},Xp=e=>async(t,n,s)=>Xo(e)(t,n,s),Jp=e=>(t,n,s)=>{const r=s?Object.assign(s,{direction:"backward"}):{direction:"backward"};return si(e)(t,n,r)},Qp=e=>(t,n,s)=>si(e)(t,n,s),ef=e=>async(t,n,s)=>{const r=s?Object.assign(s,{direction:"backward"}):{direction:"backward"};return ri(e)(t,n,r)},tf=e=>async(t,n,s)=>ri(e)(t,n,s),nf=/^[cC][^\s-]{8,}$/,sf=/^[0-9a-z]+$/,rf=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,of=/^[0-9a-vA-V]{20}$/,af=/^[A-Za-z0-9]{27}$/,cf=/^[a-zA-Z0-9_-]{21}$/,lf=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,uf=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,hc=e=>e?new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,hf=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,df="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";function pf(){return new RegExp(df,"u")}const ff=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,gf=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,mf=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,vf=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,_f=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,ql=/^[A-Za-z0-9_-]*$/,yf=/^\+[1-9]\d{6,14}$/,Kl="(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))",kf=new RegExp(`^${Kl}$`);function Yl(e){const t="(?:[01]\\d|2[0-3]):[0-5]\\d";return typeof e.precision=="number"?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function wf(e){return new RegExp(`^${Yl(e)}$`)}function bf(e){const t=Yl({precision:e.precision}),n=["Z"];e.local&&n.push(""),e.offset&&n.push("([+-](?:[01]\\d|2[0-3]):[0-5]\\d)");const s=`${t}(?:${n.join("|")})`;return new RegExp(`^${Kl}T(?:${s})$`)}const Sf=e=>{const t=e?`[\\s\\S]{${(e==null?void 0:e.minimum)??0},${(e==null?void 0:e.maximum)??""}}`:"[\\s\\S]*";return new RegExp(`^${t}$`)},xf=/^-?\d+$/,Xl=/^-?\d+(?:\.\d+)?$/,Ef=/^(?:true|false)$/i,Af=/^[^A-Z]*$/,Tf=/^[^a-z]*$/,Le=b("$ZodCheck",(e,t)=>{var n;e._zod??(e._zod={}),e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Jl={number:"number",bigint:"bigint",object:"date"},Ql=b("$ZodCheckLessThan",(e,t)=>{Le.init(e,t);const n=Jl[typeof t.value];e._zod.onattach.push(s=>{const r=s._zod.bag,i=(t.inclusive?r.maximum:r.exclusiveMaximum)??Number.POSITIVE_INFINITY;t.value<i&&(t.inclusive?r.maximum=t.value:r.exclusiveMaximum=t.value)}),e._zod.check=s=>{(t.inclusive?s.value<=t.value:s.value<t.value)||s.issues.push({origin:n,code:"too_big",maximum:typeof t.value=="object"?t.value.getTime():t.value,input:s.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),eu=b("$ZodCheckGreaterThan",(e,t)=>{Le.init(e,t);const n=Jl[typeof t.value];e._zod.onattach.push(s=>{const r=s._zod.bag,i=(t.inclusive?r.minimum:r.exclusiveMinimum)??Number.NEGATIVE_INFINITY;t.value>i&&(t.inclusive?r.minimum=t.value:r.exclusiveMinimum=t.value)}),e._zod.check=s=>{(t.inclusive?s.value>=t.value:s.value>t.value)||s.issues.push({origin:n,code:"too_small",minimum:typeof t.value=="object"?t.value.getTime():t.value,input:s.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),If=b("$ZodCheckMultipleOf",(e,t)=>{Le.init(e,t),e._zod.onattach.push(n=>{var s;(s=n._zod.bag).multipleOf??(s.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw new Error("Cannot mix number and bigint in multiple_of check.");(typeof n.value=="bigint"?n.value%t.value===BigInt(0):$p(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:"not_multiple_of",divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Cf=b("$ZodCheckNumberFormat",(e,t)=>{var o;Le.init(e,t),t.format=t.format||"float64";const n=(o=t.format)==null?void 0:o.includes("int"),s=n?"int":"number",[r,i]=Mp[t.format];e._zod.onattach.push(a=>{const c=a._zod.bag;c.format=t.format,c.minimum=r,c.maximum=i,n&&(c.pattern=xf)}),e._zod.check=a=>{const c=a.value;if(n){if(!Number.isInteger(c)){a.issues.push({expected:s,format:t.format,code:"invalid_type",continue:!1,input:c,inst:e});return}if(!Number.isSafeInteger(c)){c>0?a.issues.push({input:c,code:"too_big",maximum:Number.MAX_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:s,inclusive:!0,continue:!t.abort}):a.issues.push({input:c,code:"too_small",minimum:Number.MIN_SAFE_INTEGER,note:"Integers must be within the safe integer range.",inst:e,origin:s,inclusive:!0,continue:!t.abort});return}}c<r&&a.issues.push({origin:"number",input:c,code:"too_small",minimum:r,inclusive:!0,inst:e,continue:!t.abort}),c>i&&a.issues.push({origin:"number",input:c,code:"too_big",maximum:i,inclusive:!0,inst:e,continue:!t.abort})}}),zf=b("$ZodCheckMaxLength",(e,t)=>{var n;Le.init(e,t),(n=e._zod.def).when??(n.when=s=>{const r=s.value;return!Vo(r)&&r.length!==void 0}),e._zod.onattach.push(s=>{const r=s._zod.bag.maximum??Number.POSITIVE_INFINITY;t.maximum<r&&(s._zod.bag.maximum=t.maximum)}),e._zod.check=s=>{const r=s.value;if(r.length<=t.maximum)return;const o=Ko(r);s.issues.push({origin:o,code:"too_big",maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),$f=b("$ZodCheckMinLength",(e,t)=>{var n;Le.init(e,t),(n=e._zod.def).when??(n.when=s=>{const r=s.value;return!Vo(r)&&r.length!==void 0}),e._zod.onattach.push(s=>{const r=s._zod.bag.minimum??Number.NEGATIVE_INFINITY;t.minimum>r&&(s._zod.bag.minimum=t.minimum)}),e._zod.check=s=>{const r=s.value;if(r.length>=t.minimum)return;const o=Ko(r);s.issues.push({origin:o,code:"too_small",minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Rf=b("$ZodCheckLengthEquals",(e,t)=>{var n;Le.init(e,t),(n=e._zod.def).when??(n.when=s=>{const r=s.value;return!Vo(r)&&r.length!==void 0}),e._zod.onattach.push(s=>{const r=s._zod.bag;r.minimum=t.length,r.maximum=t.length,r.length=t.length}),e._zod.check=s=>{const r=s.value,i=r.length;if(i===t.length)return;const o=Ko(r),a=i>t.length;s.issues.push({origin:o,...a?{code:"too_big",maximum:t.length}:{code:"too_small",minimum:t.length},inclusive:!0,exact:!0,input:s.value,inst:e,continue:!t.abort})}}),ii=b("$ZodCheckStringFormat",(e,t)=>{var n,s;Le.init(e,t),e._zod.onattach.push(r=>{const i=r._zod.bag;i.format=t.format,t.pattern&&(i.patterns??(i.patterns=new Set),i.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=r=>{t.pattern.lastIndex=0,!t.pattern.test(r.value)&&r.issues.push({origin:"string",code:"invalid_format",format:t.format,input:r.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(s=e._zod).check??(s.check=()=>{})}),Pf=b("$ZodCheckRegex",(e,t)=>{ii.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:"string",code:"invalid_format",format:"regex",input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Df=b("$ZodCheckLowerCase",(e,t)=>{t.pattern??(t.pattern=Af),ii.init(e,t)}),Lf=b("$ZodCheckUpperCase",(e,t)=>{t.pattern??(t.pattern=Tf),ii.init(e,t)}),Mf=b("$ZodCheckIncludes",(e,t)=>{Le.init(e,t);const n=Zn(t.includes),s=new RegExp(typeof t.position=="number"?`^.{${t.position}}${n}`:n);t.pattern=s,e._zod.onattach.push(r=>{const i=r._zod.bag;i.patterns??(i.patterns=new Set),i.patterns.add(s)}),e._zod.check=r=>{r.value.includes(t.includes,t.position)||r.issues.push({origin:"string",code:"invalid_format",format:"includes",includes:t.includes,input:r.value,inst:e,continue:!t.abort})}}),Of=b("$ZodCheckStartsWith",(e,t)=>{Le.init(e,t);const n=new RegExp(`^${Zn(t.prefix)}.*`);t.pattern??(t.pattern=n),e._zod.onattach.push(s=>{const r=s._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=s=>{s.value.startsWith(t.prefix)||s.issues.push({origin:"string",code:"invalid_format",format:"starts_with",prefix:t.prefix,input:s.value,inst:e,continue:!t.abort})}}),Nf=b("$ZodCheckEndsWith",(e,t)=>{Le.init(e,t);const n=new RegExp(`.*${Zn(t.suffix)}$`);t.pattern??(t.pattern=n),e._zod.onattach.push(s=>{const r=s._zod.bag;r.patterns??(r.patterns=new Set),r.patterns.add(n)}),e._zod.check=s=>{s.value.endsWith(t.suffix)||s.issues.push({origin:"string",code:"invalid_format",format:"ends_with",suffix:t.suffix,input:s.value,inst:e,continue:!t.abort})}}),Wf=b("$ZodCheckOverwrite",(e,t)=>{Le.init(e,t),e._zod.check=n=>{n.value=t.tx(n.value)}});class Ff{constructor(t=[]){this.content=[],this.indent=0,this&&(this.args=t)}indented(t){this.indent+=1,t(this),this.indent-=1}write(t){if(typeof t=="function"){t(this,{execution:"sync"}),t(this,{execution:"async"});return}const s=t.split(`
2
- `).filter(o=>o),r=Math.min(...s.map(o=>o.length-o.trimStart().length)),i=s.map(o=>o.slice(r)).map(o=>" ".repeat(this.indent*2)+o);for(const o of i)this.content.push(o)}compile(){const t=Function,n=this==null?void 0:this.args,r=[...((this==null?void 0:this.content)??[""]).map(i=>` ${i}`)];return new t(...n,r.join(`
3
- `))}}const Uf={major:4,minor:3,patch:6},ie=b("$ZodType",(e,t)=>{var r;var n;e??(e={}),e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Uf;const s=[...e._zod.def.checks??[]];e._zod.traits.has("$ZodCheck")&&s.unshift(e);for(const i of s)for(const o of i._zod.onattach)o(e);if(s.length===0)(n=e._zod).deferred??(n.deferred=[]),(r=e._zod.deferred)==null||r.push(()=>{e._zod.run=e._zod.parse});else{const i=(a,c,l)=>{let h=An(a),f;for(const w of c){if(w._zod.def.when){if(!w._zod.def.when(a))continue}else if(h)continue;const v=a.issues.length,E=w._zod.check(a);if(E instanceof Promise&&(l==null?void 0:l.async)===!1)throw new Cn;if(f||E instanceof Promise)f=(f??Promise.resolve()).then(async()=>{await E,a.issues.length!==v&&(h||(h=An(a,v)))});else{if(a.issues.length===v)continue;h||(h=An(a,v))}}return f?f.then(()=>a):a},o=(a,c,l)=>{if(An(a))return a.aborted=!0,a;const h=i(c,s,l);if(h instanceof Promise){if(l.async===!1)throw new Cn;return h.then(f=>e._zod.parse(f,l))}return e._zod.parse(h,l)};e._zod.run=(a,c)=>{if(c.skipChecks)return e._zod.parse(a,c);if(c.direction==="backward"){const h=e._zod.parse({value:a.value,issues:[]},{...c,skipChecks:!0});return h instanceof Promise?h.then(f=>o(f,a,c)):o(h,a,c)}const l=e._zod.parse(a,c);if(l instanceof Promise){if(c.async===!1)throw new Cn;return l.then(h=>i(h,s,c))}return i(l,s,c)}}Y(e,"~standard",()=>({validate:i=>{var o;try{const a=Gp(e,i);return a.success?{value:a.data}:{issues:(o=a.error)==null?void 0:o.issues}}catch{return Vp(e,i).then(c=>{var l;return c.success?{value:c.data}:{issues:(l=c.error)==null?void 0:l.issues}})}},vendor:"zod",version:1}))}),Jo=b("$ZodString",(e,t)=>{var n;ie.init(e,t),e._zod.pattern=[...((n=e==null?void 0:e._zod.bag)==null?void 0:n.patterns)??[]].pop()??Sf(e._zod.bag),e._zod.parse=(s,r)=>{if(t.coerce)try{s.value=String(s.value)}catch{}return typeof s.value=="string"||s.issues.push({expected:"string",code:"invalid_type",input:s.value,inst:e}),s}}),se=b("$ZodStringFormat",(e,t)=>{ii.init(e,t),Jo.init(e,t)}),Zf=b("$ZodGUID",(e,t)=>{t.pattern??(t.pattern=uf),se.init(e,t)}),jf=b("$ZodUUID",(e,t)=>{if(t.version){const s={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(s===void 0)throw new Error(`Invalid UUID version: "${t.version}"`);t.pattern??(t.pattern=hc(s))}else t.pattern??(t.pattern=hc());se.init(e,t)}),Hf=b("$ZodEmail",(e,t)=>{t.pattern??(t.pattern=hf),se.init(e,t)}),Bf=b("$ZodURL",(e,t)=>{se.init(e,t),e._zod.check=n=>{try{const s=n.value.trim(),r=new URL(s);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(r.hostname)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid hostname",pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(r.protocol.endsWith(":")?r.protocol.slice(0,-1):r.protocol)||n.issues.push({code:"invalid_format",format:"url",note:"Invalid protocol",pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),t.normalize?n.value=r.href:n.value=s;return}catch{n.issues.push({code:"invalid_format",format:"url",input:n.value,inst:e,continue:!t.abort})}}}),Gf=b("$ZodEmoji",(e,t)=>{t.pattern??(t.pattern=pf()),se.init(e,t)}),Vf=b("$ZodNanoID",(e,t)=>{t.pattern??(t.pattern=cf),se.init(e,t)}),qf=b("$ZodCUID",(e,t)=>{t.pattern??(t.pattern=nf),se.init(e,t)}),Kf=b("$ZodCUID2",(e,t)=>{t.pattern??(t.pattern=sf),se.init(e,t)}),Yf=b("$ZodULID",(e,t)=>{t.pattern??(t.pattern=rf),se.init(e,t)}),Xf=b("$ZodXID",(e,t)=>{t.pattern??(t.pattern=of),se.init(e,t)}),Jf=b("$ZodKSUID",(e,t)=>{t.pattern??(t.pattern=af),se.init(e,t)}),Qf=b("$ZodISODateTime",(e,t)=>{t.pattern??(t.pattern=bf(t)),se.init(e,t)}),eg=b("$ZodISODate",(e,t)=>{t.pattern??(t.pattern=kf),se.init(e,t)}),tg=b("$ZodISOTime",(e,t)=>{t.pattern??(t.pattern=wf(t)),se.init(e,t)}),ng=b("$ZodISODuration",(e,t)=>{t.pattern??(t.pattern=lf),se.init(e,t)}),sg=b("$ZodIPv4",(e,t)=>{t.pattern??(t.pattern=ff),se.init(e,t),e._zod.bag.format="ipv4"}),rg=b("$ZodIPv6",(e,t)=>{t.pattern??(t.pattern=gf),se.init(e,t),e._zod.bag.format="ipv6",e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:"invalid_format",format:"ipv6",input:n.value,inst:e,continue:!t.abort})}}}),ig=b("$ZodCIDRv4",(e,t)=>{t.pattern??(t.pattern=mf),se.init(e,t)}),og=b("$ZodCIDRv6",(e,t)=>{t.pattern??(t.pattern=vf),se.init(e,t),e._zod.check=n=>{const s=n.value.split("/");try{if(s.length!==2)throw new Error;const[r,i]=s;if(!i)throw new Error;const o=Number(i);if(`${o}`!==i)throw new Error;if(o<0||o>128)throw new Error;new URL(`http://[${r}]`)}catch{n.issues.push({code:"invalid_format",format:"cidrv6",input:n.value,inst:e,continue:!t.abort})}}});function tu(e){if(e==="")return!0;if(e.length%4!==0)return!1;try{return atob(e),!0}catch{return!1}}const ag=b("$ZodBase64",(e,t)=>{t.pattern??(t.pattern=_f),se.init(e,t),e._zod.bag.contentEncoding="base64",e._zod.check=n=>{tu(n.value)||n.issues.push({code:"invalid_format",format:"base64",input:n.value,inst:e,continue:!t.abort})}});function cg(e){if(!ql.test(e))return!1;const t=e.replace(/[-_]/g,s=>s==="-"?"+":"/"),n=t.padEnd(Math.ceil(t.length/4)*4,"=");return tu(n)}const lg=b("$ZodBase64URL",(e,t)=>{t.pattern??(t.pattern=ql),se.init(e,t),e._zod.bag.contentEncoding="base64url",e._zod.check=n=>{cg(n.value)||n.issues.push({code:"invalid_format",format:"base64url",input:n.value,inst:e,continue:!t.abort})}}),ug=b("$ZodE164",(e,t)=>{t.pattern??(t.pattern=yf),se.init(e,t)});function hg(e,t=null){try{const n=e.split(".");if(n.length!==3)return!1;const[s]=n;if(!s)return!1;const r=JSON.parse(atob(s));return!("typ"in r&&(r==null?void 0:r.typ)!=="JWT"||!r.alg||t&&(!("alg"in r)||r.alg!==t))}catch{return!1}}const dg=b("$ZodJWT",(e,t)=>{se.init(e,t),e._zod.check=n=>{hg(n.value,t.alg)||n.issues.push({code:"invalid_format",format:"jwt",input:n.value,inst:e,continue:!t.abort})}}),nu=b("$ZodNumber",(e,t)=>{ie.init(e,t),e._zod.pattern=e._zod.bag.pattern??Xl,e._zod.parse=(n,s)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}const r=n.value;if(typeof r=="number"&&!Number.isNaN(r)&&Number.isFinite(r))return n;const i=typeof r=="number"?Number.isNaN(r)?"NaN":Number.isFinite(r)?void 0:"Infinity":void 0;return n.issues.push({expected:"number",code:"invalid_type",input:r,inst:e,...i?{received:i}:{}}),n}}),pg=b("$ZodNumberFormat",(e,t)=>{Cf.init(e,t),nu.init(e,t)}),fg=b("$ZodBoolean",(e,t)=>{ie.init(e,t),e._zod.pattern=Ef,e._zod.parse=(n,s)=>{if(t.coerce)try{n.value=!!n.value}catch{}const r=n.value;return typeof r=="boolean"||n.issues.push({expected:"boolean",code:"invalid_type",input:r,inst:e}),n}}),gg=b("$ZodUnknown",(e,t)=>{ie.init(e,t),e._zod.parse=n=>n}),mg=b("$ZodNever",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>(n.issues.push({expected:"never",code:"invalid_type",input:n.value,inst:e}),n)});function dc(e,t,n){e.issues.length&&t.issues.push(...Tn(n,e.issues)),t.value[n]=e.value}const vg=b("$ZodArray",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>{const r=n.value;if(!Array.isArray(r))return n.issues.push({expected:"array",code:"invalid_type",input:r,inst:e}),n;n.value=Array(r.length);const i=[];for(let o=0;o<r.length;o++){const a=r[o],c=t.element._zod.run({value:a,issues:[]},s);c instanceof Promise?i.push(c.then(l=>dc(l,n,o))):dc(c,n,o)}return i.length?Promise.all(i).then(()=>n):n}});function Or(e,t,n,s,r){if(e.issues.length){if(r&&!(n in s))return;t.issues.push(...Tn(n,e.issues))}e.value===void 0?n in s&&(t.value[n]=void 0):t.value[n]=e.value}function su(e){var s,r,i,o;const t=Object.keys(e.shape);for(const a of t)if(!((o=(i=(r=(s=e.shape)==null?void 0:s[a])==null?void 0:r._zod)==null?void 0:i.traits)!=null&&o.has("$ZodType")))throw new Error(`Invalid element at key "${a}": expected a Zod schema`);const n=Lp(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function ru(e,t,n,s,r,i){const o=[],a=r.keySet,c=r.catchall._zod,l=c.def.type,h=c.optout==="optional";for(const f in t){if(a.has(f))continue;if(l==="never"){o.push(f);continue}const w=c.run({value:t[f],issues:[]},s);w instanceof Promise?e.push(w.then(v=>Or(v,n,f,t,h))):Or(w,n,f,t,h)}return o.length&&n.issues.push({code:"unrecognized_keys",keys:o,input:t,inst:i}),e.length?Promise.all(e).then(()=>n):n}const _g=b("$ZodObject",(e,t)=>{ie.init(e,t);const n=Object.getOwnPropertyDescriptor(t,"shape");if(!(n!=null&&n.get)){const a=t.shape;Object.defineProperty(t,"shape",{get:()=>{const c={...a};return Object.defineProperty(t,"shape",{value:c}),c}})}const s=Go(()=>su(t));Y(e._zod,"propValues",()=>{const a=t.shape,c={};for(const l in a){const h=a[l]._zod;if(h.values){c[l]??(c[l]=new Set);for(const f of h.values)c[l].add(f)}}return c});const r=Mr,i=t.catchall;let o;e._zod.parse=(a,c)=>{o??(o=s.value);const l=a.value;if(!r(l))return a.issues.push({expected:"object",code:"invalid_type",input:l,inst:e}),a;a.value={};const h=[],f=o.shape;for(const w of o.keys){const v=f[w],E=v._zod.optout==="optional",S=v._zod.run({value:l[w],issues:[]},c);S instanceof Promise?h.push(S.then(z=>Or(z,a,w,l,E))):Or(S,a,w,l,E)}return i?ru(h,l,a,c,s.value,e):h.length?Promise.all(h).then(()=>a):a}}),yg=b("$ZodObjectJIT",(e,t)=>{_g.init(e,t);const n=e._zod.parse,s=Go(()=>su(t)),r=w=>{var ye;const v=new Ff(["shape","payload","ctx"]),E=s.value,S=M=>{const V=uc(M);return`shape[${V}]._zod.run({ value: input[${V}], issues: [] }, ctx)`};v.write("const input = payload.value;");const z=Object.create(null);let q=0;for(const M of E.keys)z[M]=`key_${q++}`;v.write("const newResult = {};");for(const M of E.keys){const V=z[M],U=uc(M),Te=w[M],X=((ye=Te==null?void 0:Te._zod)==null?void 0:ye.optout)==="optional";v.write(`const ${V} = ${S(M)};`),X?v.write(`
4
- if (${V}.issues.length) {
5
- if (${U} in input) {
6
- payload.issues = payload.issues.concat(${V}.issues.map(iss => ({
7
- ...iss,
8
- path: iss.path ? [${U}, ...iss.path] : [${U}]
9
- })));
10
- }
11
- }
12
-
13
- if (${V}.value === undefined) {
14
- if (${U} in input) {
15
- newResult[${U}] = undefined;
16
- }
17
- } else {
18
- newResult[${U}] = ${V}.value;
19
- }
20
-
21
- `):v.write(`
22
- if (${V}.issues.length) {
23
- payload.issues = payload.issues.concat(${V}.issues.map(iss => ({
24
- ...iss,
25
- path: iss.path ? [${U}, ...iss.path] : [${U}]
26
- })));
27
- }
28
-
29
- if (${V}.value === undefined) {
30
- if (${U} in input) {
31
- newResult[${U}] = undefined;
32
- }
33
- } else {
34
- newResult[${U}] = ${V}.value;
35
- }
36
-
37
- `)}v.write("payload.value = newResult;"),v.write("return payload;");const Z=v.compile();return(M,V)=>Z(w,M,V)};let i;const o=Mr,a=!Ul.jitless,l=a&&Pp.value,h=t.catchall;let f;e._zod.parse=(w,v)=>{f??(f=s.value);const E=w.value;return o(E)?a&&l&&(v==null?void 0:v.async)===!1&&v.jitless!==!0?(i||(i=r(t.shape)),w=i(w,v),h?ru([],E,w,v,f,e):w):n(w,v):(w.issues.push({expected:"object",code:"invalid_type",input:E,inst:e}),w)}});function pc(e,t,n,s){for(const i of e)if(i.issues.length===0)return t.value=i.value,t;const r=e.filter(i=>!An(i));return r.length===1?(t.value=r[0].value,r[0]):(t.issues.push({code:"invalid_union",input:t.value,inst:n,errors:e.map(i=>i.issues.map(o=>zt(o,s,Ct())))}),t)}const kg=b("$ZodUnion",(e,t)=>{ie.init(e,t),Y(e._zod,"optin",()=>t.options.some(r=>r._zod.optin==="optional")?"optional":void 0),Y(e._zod,"optout",()=>t.options.some(r=>r._zod.optout==="optional")?"optional":void 0),Y(e._zod,"values",()=>{if(t.options.every(r=>r._zod.values))return new Set(t.options.flatMap(r=>Array.from(r._zod.values)))}),Y(e._zod,"pattern",()=>{if(t.options.every(r=>r._zod.pattern)){const r=t.options.map(i=>i._zod.pattern);return new RegExp(`^(${r.map(i=>qo(i.source)).join("|")})$`)}});const n=t.options.length===1,s=t.options[0]._zod.run;e._zod.parse=(r,i)=>{if(n)return s(r,i);let o=!1;const a=[];for(const c of t.options){const l=c._zod.run({value:r.value,issues:[]},i);if(l instanceof Promise)a.push(l),o=!0;else{if(l.issues.length===0)return l;a.push(l)}}return o?Promise.all(a).then(c=>pc(c,r,e,i)):pc(a,r,e,i)}}),wg=b("$ZodIntersection",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>{const r=n.value,i=t.left._zod.run({value:r,issues:[]},s),o=t.right._zod.run({value:r,issues:[]},s);return i instanceof Promise||o instanceof Promise?Promise.all([i,o]).then(([c,l])=>fc(n,c,l)):fc(n,i,o)}});function lo(e,t){if(e===t)return{valid:!0,data:e};if(e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(Un(e)&&Un(t)){const n=Object.keys(t),s=Object.keys(e).filter(i=>n.indexOf(i)!==-1),r={...e,...t};for(const i of s){const o=lo(e[i],t[i]);if(!o.valid)return{valid:!1,mergeErrorPath:[i,...o.mergeErrorPath]};r[i]=o.data}return{valid:!0,data:r}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};const n=[];for(let s=0;s<e.length;s++){const r=e[s],i=t[s],o=lo(r,i);if(!o.valid)return{valid:!1,mergeErrorPath:[s,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function fc(e,t,n){const s=new Map;let r;for(const a of t.issues)if(a.code==="unrecognized_keys"){r??(r=a);for(const c of a.keys)s.has(c)||s.set(c,{}),s.get(c).l=!0}else e.issues.push(a);for(const a of n.issues)if(a.code==="unrecognized_keys")for(const c of a.keys)s.has(c)||s.set(c,{}),s.get(c).r=!0;else e.issues.push(a);const i=[...s].filter(([,a])=>a.l&&a.r).map(([a])=>a);if(i.length&&r&&e.issues.push({...r,keys:i}),An(e))return e;const o=lo(t.value,n.value);if(!o.valid)throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}const bg=b("$ZodRecord",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>{const r=n.value;if(!Un(r))return n.issues.push({expected:"record",code:"invalid_type",input:r,inst:e}),n;const i=[],o=t.keyType._zod.values;if(o){n.value={};const a=new Set;for(const l of o)if(typeof l=="string"||typeof l=="number"||typeof l=="symbol"){a.add(typeof l=="number"?l.toString():l);const h=t.valueType._zod.run({value:r[l],issues:[]},s);h instanceof Promise?i.push(h.then(f=>{f.issues.length&&n.issues.push(...Tn(l,f.issues)),n.value[l]=f.value})):(h.issues.length&&n.issues.push(...Tn(l,h.issues)),n.value[l]=h.value)}let c;for(const l in r)a.has(l)||(c=c??[],c.push(l));c&&c.length>0&&n.issues.push({code:"unrecognized_keys",input:r,inst:e,keys:c})}else{n.value={};for(const a of Reflect.ownKeys(r)){if(a==="__proto__")continue;let c=t.keyType._zod.run({value:a,issues:[]},s);if(c instanceof Promise)throw new Error("Async schemas not supported in object keys currently");if(typeof a=="string"&&Xl.test(a)&&c.issues.length){const f=t.keyType._zod.run({value:Number(a),issues:[]},s);if(f instanceof Promise)throw new Error("Async schemas not supported in object keys currently");f.issues.length===0&&(c=f)}if(c.issues.length){t.mode==="loose"?n.value[a]=r[a]:n.issues.push({code:"invalid_key",origin:"record",issues:c.issues.map(f=>zt(f,s,Ct())),input:a,path:[a],inst:e});continue}const h=t.valueType._zod.run({value:r[a],issues:[]},s);h instanceof Promise?i.push(h.then(f=>{f.issues.length&&n.issues.push(...Tn(a,f.issues)),n.value[c.value]=f.value})):(h.issues.length&&n.issues.push(...Tn(a,h.issues)),n.value[c.value]=h.value)}}return i.length?Promise.all(i).then(()=>n):n}}),Sg=b("$ZodEnum",(e,t)=>{ie.init(e,t);const n=Zl(t.entries),s=new Set(n);e._zod.values=s,e._zod.pattern=new RegExp(`^(${n.filter(r=>Dp.has(typeof r)).map(r=>typeof r=="string"?Zn(r):r.toString()).join("|")})$`),e._zod.parse=(r,i)=>{const o=r.value;return s.has(o)||r.issues.push({code:"invalid_value",values:n,input:o,inst:e}),r}}),xg=b("$ZodLiteral",(e,t)=>{if(ie.init(e,t),t.values.length===0)throw new Error("Cannot create literal schema with no valid values");const n=new Set(t.values);e._zod.values=n,e._zod.pattern=new RegExp(`^(${t.values.map(s=>typeof s=="string"?Zn(s):s?Zn(s.toString()):String(s)).join("|")})$`),e._zod.parse=(s,r)=>{const i=s.value;return n.has(i)||s.issues.push({code:"invalid_value",values:t.values,input:i,inst:e}),s}}),Eg=b("$ZodTransform",(e,t)=>{ie.init(e,t),e._zod.parse=(n,s)=>{if(s.direction==="backward")throw new Fl(e.constructor.name);const r=t.transform(n.value,n);if(s.async)return(r instanceof Promise?r:Promise.resolve(r)).then(o=>(n.value=o,n));if(r instanceof Promise)throw new Cn;return n.value=r,n}});function gc(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}const iu=b("$ZodOptional",(e,t)=>{ie.init(e,t),e._zod.optin="optional",e._zod.optout="optional",Y(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),Y(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${qo(n.source)})?$`):void 0}),e._zod.parse=(n,s)=>{if(t.innerType._zod.optin==="optional"){const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(i=>gc(i,n.value)):gc(r,n.value)}return n.value===void 0?n:t.innerType._zod.run(n,s)}}),Ag=b("$ZodExactOptional",(e,t)=>{iu.init(e,t),Y(e._zod,"values",()=>t.innerType._zod.values),Y(e._zod,"pattern",()=>t.innerType._zod.pattern),e._zod.parse=(n,s)=>t.innerType._zod.run(n,s)}),Tg=b("$ZodNullable",(e,t)=>{ie.init(e,t),Y(e._zod,"optin",()=>t.innerType._zod.optin),Y(e._zod,"optout",()=>t.innerType._zod.optout),Y(e._zod,"pattern",()=>{const n=t.innerType._zod.pattern;return n?new RegExp(`^(${qo(n.source)}|null)$`):void 0}),Y(e._zod,"values",()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(n,s)=>n.value===null?n:t.innerType._zod.run(n,s)}),Ig=b("$ZodDefault",(e,t)=>{ie.init(e,t),e._zod.optin="optional",Y(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,s)=>{if(s.direction==="backward")return t.innerType._zod.run(n,s);if(n.value===void 0)return n.value=t.defaultValue,n;const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(i=>mc(i,t)):mc(r,t)}});function mc(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}const Cg=b("$ZodPrefault",(e,t)=>{ie.init(e,t),e._zod.optin="optional",Y(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,s)=>(s.direction==="backward"||n.value===void 0&&(n.value=t.defaultValue),t.innerType._zod.run(n,s))}),zg=b("$ZodNonOptional",(e,t)=>{ie.init(e,t),Y(e._zod,"values",()=>{const n=t.innerType._zod.values;return n?new Set([...n].filter(s=>s!==void 0)):void 0}),e._zod.parse=(n,s)=>{const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(i=>vc(i,e)):vc(r,e)}});function vc(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:"invalid_type",expected:"nonoptional",input:e.value,inst:t}),e}const $g=b("$ZodCatch",(e,t)=>{ie.init(e,t),Y(e._zod,"optin",()=>t.innerType._zod.optin),Y(e._zod,"optout",()=>t.innerType._zod.optout),Y(e._zod,"values",()=>t.innerType._zod.values),e._zod.parse=(n,s)=>{if(s.direction==="backward")return t.innerType._zod.run(n,s);const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(i=>(n.value=i.value,i.issues.length&&(n.value=t.catchValue({...n,error:{issues:i.issues.map(o=>zt(o,s,Ct()))},input:n.value}),n.issues=[]),n)):(n.value=r.value,r.issues.length&&(n.value=t.catchValue({...n,error:{issues:r.issues.map(i=>zt(i,s,Ct()))},input:n.value}),n.issues=[]),n)}}),Rg=b("$ZodPipe",(e,t)=>{ie.init(e,t),Y(e._zod,"values",()=>t.in._zod.values),Y(e._zod,"optin",()=>t.in._zod.optin),Y(e._zod,"optout",()=>t.out._zod.optout),Y(e._zod,"propValues",()=>t.in._zod.propValues),e._zod.parse=(n,s)=>{if(s.direction==="backward"){const i=t.out._zod.run(n,s);return i instanceof Promise?i.then(o=>pr(o,t.in,s)):pr(i,t.in,s)}const r=t.in._zod.run(n,s);return r instanceof Promise?r.then(i=>pr(i,t.out,s)):pr(r,t.out,s)}});function pr(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}const Pg=b("$ZodReadonly",(e,t)=>{ie.init(e,t),Y(e._zod,"propValues",()=>t.innerType._zod.propValues),Y(e._zod,"values",()=>t.innerType._zod.values),Y(e._zod,"optin",()=>{var n,s;return(s=(n=t.innerType)==null?void 0:n._zod)==null?void 0:s.optin}),Y(e._zod,"optout",()=>{var n,s;return(s=(n=t.innerType)==null?void 0:n._zod)==null?void 0:s.optout}),e._zod.parse=(n,s)=>{if(s.direction==="backward")return t.innerType._zod.run(n,s);const r=t.innerType._zod.run(n,s);return r instanceof Promise?r.then(_c):_c(r)}});function _c(e){return e.value=Object.freeze(e.value),e}const Dg=b("$ZodCustom",(e,t)=>{Le.init(e,t),ie.init(e,t),e._zod.parse=(n,s)=>n,e._zod.check=n=>{const s=n.value,r=t.fn(s);if(r instanceof Promise)return r.then(i=>yc(i,n,s,e));yc(r,n,s,e)}});function yc(e,t,n,s){if(!e){const r={code:"custom",input:n,inst:s,path:[...s._zod.def.path??[]],continue:!s._zod.def.abort};s._zod.def.params&&(r.params=s._zod.def.params),t.issues.push(bs(r))}}var kc;class Lg{constructor(){this._map=new WeakMap,this._idmap=new Map}add(t,...n){const s=n[0];return this._map.set(t,s),s&&typeof s=="object"&&"id"in s&&this._idmap.set(s.id,t),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(t){const n=this._map.get(t);return n&&typeof n=="object"&&"id"in n&&this._idmap.delete(n.id),this._map.delete(t),this}get(t){const n=t._zod.parent;if(n){const s={...this.get(n)??{}};delete s.id;const r={...s,...this._map.get(t)};return Object.keys(r).length?r:void 0}return this._map.get(t)}has(t){return this._map.has(t)}}function Mg(){return new Lg}(kc=globalThis).__zod_globalRegistry??(kc.__zod_globalRegistry=Mg());const hs=globalThis.__zod_globalRegistry;function Og(e,t){return new e({type:"string",...P(t)})}function Ng(e,t){return new e({type:"string",format:"email",check:"string_format",abort:!1,...P(t)})}function wc(e,t){return new e({type:"string",format:"guid",check:"string_format",abort:!1,...P(t)})}function Wg(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,...P(t)})}function Fg(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v4",...P(t)})}function Ug(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v6",...P(t)})}function Zg(e,t){return new e({type:"string",format:"uuid",check:"string_format",abort:!1,version:"v7",...P(t)})}function jg(e,t){return new e({type:"string",format:"url",check:"string_format",abort:!1,...P(t)})}function Hg(e,t){return new e({type:"string",format:"emoji",check:"string_format",abort:!1,...P(t)})}function Bg(e,t){return new e({type:"string",format:"nanoid",check:"string_format",abort:!1,...P(t)})}function Gg(e,t){return new e({type:"string",format:"cuid",check:"string_format",abort:!1,...P(t)})}function Vg(e,t){return new e({type:"string",format:"cuid2",check:"string_format",abort:!1,...P(t)})}function qg(e,t){return new e({type:"string",format:"ulid",check:"string_format",abort:!1,...P(t)})}function Kg(e,t){return new e({type:"string",format:"xid",check:"string_format",abort:!1,...P(t)})}function Yg(e,t){return new e({type:"string",format:"ksuid",check:"string_format",abort:!1,...P(t)})}function Xg(e,t){return new e({type:"string",format:"ipv4",check:"string_format",abort:!1,...P(t)})}function Jg(e,t){return new e({type:"string",format:"ipv6",check:"string_format",abort:!1,...P(t)})}function Qg(e,t){return new e({type:"string",format:"cidrv4",check:"string_format",abort:!1,...P(t)})}function em(e,t){return new e({type:"string",format:"cidrv6",check:"string_format",abort:!1,...P(t)})}function tm(e,t){return new e({type:"string",format:"base64",check:"string_format",abort:!1,...P(t)})}function nm(e,t){return new e({type:"string",format:"base64url",check:"string_format",abort:!1,...P(t)})}function sm(e,t){return new e({type:"string",format:"e164",check:"string_format",abort:!1,...P(t)})}function rm(e,t){return new e({type:"string",format:"jwt",check:"string_format",abort:!1,...P(t)})}function im(e,t){return new e({type:"string",format:"datetime",check:"string_format",offset:!1,local:!1,precision:null,...P(t)})}function om(e,t){return new e({type:"string",format:"date",check:"string_format",...P(t)})}function am(e,t){return new e({type:"string",format:"time",check:"string_format",precision:null,...P(t)})}function cm(e,t){return new e({type:"string",format:"duration",check:"string_format",...P(t)})}function lm(e,t){return new e({type:"number",checks:[],...P(t)})}function um(e,t){return new e({type:"number",check:"number_format",abort:!1,format:"safeint",...P(t)})}function hm(e,t){return new e({type:"boolean",...P(t)})}function dm(e){return new e({type:"unknown"})}function pm(e,t){return new e({type:"never",...P(t)})}function bc(e,t){return new Ql({check:"less_than",...P(t),value:e,inclusive:!1})}function Di(e,t){return new Ql({check:"less_than",...P(t),value:e,inclusive:!0})}function Sc(e,t){return new eu({check:"greater_than",...P(t),value:e,inclusive:!1})}function Li(e,t){return new eu({check:"greater_than",...P(t),value:e,inclusive:!0})}function xc(e,t){return new If({check:"multiple_of",...P(t),value:e})}function ou(e,t){return new zf({check:"max_length",...P(t),maximum:e})}function Nr(e,t){return new $f({check:"min_length",...P(t),minimum:e})}function au(e,t){return new Rf({check:"length_equals",...P(t),length:e})}function fm(e,t){return new Pf({check:"string_format",format:"regex",...P(t),pattern:e})}function gm(e){return new Df({check:"string_format",format:"lowercase",...P(e)})}function mm(e){return new Lf({check:"string_format",format:"uppercase",...P(e)})}function vm(e,t){return new Mf({check:"string_format",format:"includes",...P(t),includes:e})}function _m(e,t){return new Of({check:"string_format",format:"starts_with",...P(t),prefix:e})}function ym(e,t){return new Nf({check:"string_format",format:"ends_with",...P(t),suffix:e})}function Bn(e){return new Wf({check:"overwrite",tx:e})}function km(e){return Bn(t=>t.normalize(e))}function wm(){return Bn(e=>e.trim())}function bm(){return Bn(e=>e.toLowerCase())}function Sm(){return Bn(e=>e.toUpperCase())}function xm(){return Bn(e=>Rp(e))}function Em(e,t,n){return new e({type:"array",element:t,...P(n)})}function Am(e,t,n){return new e({type:"custom",check:"custom",fn:t,...P(n)})}function Tm(e){const t=Im(n=>(n.addIssue=s=>{if(typeof s=="string")n.issues.push(bs(s,n.value,t._zod.def));else{const r=s;r.fatal&&(r.continue=!1),r.code??(r.code="custom"),r.input??(r.input=n.value),r.inst??(r.inst=t),r.continue??(r.continue=!t._zod.def.abort),n.issues.push(bs(r))}},e(n.value,n)));return t}function Im(e,t){const n=new Le({check:"custom",...P(t)});return n._zod.check=e,n}function cu(e){let t=(e==null?void 0:e.target)??"draft-2020-12";return t==="draft-4"&&(t="draft-04"),t==="draft-7"&&(t="draft-07"),{processors:e.processors??{},metadataRegistry:(e==null?void 0:e.metadata)??hs,target:t,unrepresentable:(e==null?void 0:e.unrepresentable)??"throw",override:(e==null?void 0:e.override)??(()=>{}),io:(e==null?void 0:e.io)??"output",counter:0,seen:new Map,cycles:(e==null?void 0:e.cycles)??"ref",reused:(e==null?void 0:e.reused)??"inline",external:(e==null?void 0:e.external)??void 0}}function pe(e,t,n={path:[],schemaPath:[]}){var h,f;var s;const r=e._zod.def,i=t.seen.get(e);if(i)return i.count++,n.schemaPath.includes(e)&&(i.cycle=n.path),i.schema;const o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);const a=(f=(h=e._zod).toJSONSchema)==null?void 0:f.call(h);if(a)o.schema=a;else{const w={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,w);else{const E=o.schema,S=t.processors[r.type];if(!S)throw new Error(`[toJSONSchema]: Non-representable type encountered: ${r.type}`);S(e,t,E,w)}const v=e._zod.parent;v&&(o.ref||(o.ref=v),pe(v,t,w),t.seen.get(v).isParent=!0)}const c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io==="input"&&Ce(e)&&(delete o.schema.examples,delete o.schema.default),t.io==="input"&&o.schema._prefault&&((s=o.schema).default??(s.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function lu(e,t){var o,a,c,l;const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const s=new Map;for(const h of e.seen.entries()){const f=(o=e.metadataRegistry.get(h[0]))==null?void 0:o.id;if(f){const w=s.get(f);if(w&&w!==h[0])throw new Error(`Duplicate schema id "${f}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);s.set(f,h[0])}}const r=h=>{var S;const f=e.target==="draft-2020-12"?"$defs":"definitions";if(e.external){const z=(S=e.external.registry.get(h[0]))==null?void 0:S.id,q=e.external.uri??(ye=>ye);if(z)return{ref:q(z)};const Z=h[1].defId??h[1].schema.id??`schema${e.counter++}`;return h[1].defId=Z,{defId:Z,ref:`${q("__shared")}#/${f}/${Z}`}}if(h[1]===n)return{ref:"#"};const v=`#/${f}/`,E=h[1].schema.id??`__schema${e.counter++}`;return{defId:E,ref:v+E}},i=h=>{if(h[1].schema.$ref)return;const f=h[1],{ref:w,defId:v}=r(h);f.def={...f.schema},v&&(f.defId=v);const E=f.schema;for(const S in E)delete E[S];E.$ref=w};if(e.cycles==="throw")for(const h of e.seen.entries()){const f=h[1];if(f.cycle)throw new Error(`Cycle detected: #/${(a=f.cycle)==null?void 0:a.join("/")}/<root>
38
-
39
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(const h of e.seen.entries()){const f=h[1];if(t===h[0]){i(h);continue}if(e.external){const v=(c=e.external.registry.get(h[0]))==null?void 0:c.id;if(t!==h[0]&&v){i(h);continue}}if((l=e.metadataRegistry.get(h[0]))==null?void 0:l.id){i(h);continue}if(f.cycle){i(h);continue}if(f.count>1&&e.reused==="ref"){i(h);continue}}}function uu(e,t){var o,a,c;const n=e.seen.get(t);if(!n)throw new Error("Unprocessed schema. This is a bug in Zod.");const s=l=>{const h=e.seen.get(l);if(h.ref===null)return;const f=h.def??h.schema,w={...f},v=h.ref;if(h.ref=null,v){s(v);const S=e.seen.get(v),z=S.schema;if(z.$ref&&(e.target==="draft-07"||e.target==="draft-04"||e.target==="openapi-3.0")?(f.allOf=f.allOf??[],f.allOf.push(z)):Object.assign(f,z),Object.assign(f,w),l._zod.parent===v)for(const Z in f)Z==="$ref"||Z==="allOf"||Z in w||delete f[Z];if(z.$ref&&S.def)for(const Z in f)Z==="$ref"||Z==="allOf"||Z in S.def&&JSON.stringify(f[Z])===JSON.stringify(S.def[Z])&&delete f[Z]}const E=l._zod.parent;if(E&&E!==v){s(E);const S=e.seen.get(E);if(S!=null&&S.schema.$ref&&(f.$ref=S.schema.$ref,S.def))for(const z in f)z==="$ref"||z==="allOf"||z in S.def&&JSON.stringify(f[z])===JSON.stringify(S.def[z])&&delete f[z]}e.override({zodSchema:l,jsonSchema:f,path:h.path??[]})};for(const l of[...e.seen.entries()].reverse())s(l[0]);const r={};if(e.target==="draft-2020-12"?r.$schema="https://json-schema.org/draft/2020-12/schema":e.target==="draft-07"?r.$schema="http://json-schema.org/draft-07/schema#":e.target==="draft-04"?r.$schema="http://json-schema.org/draft-04/schema#":e.target,(o=e.external)!=null&&o.uri){const l=(a=e.external.registry.get(t))==null?void 0:a.id;if(!l)throw new Error("Schema is missing an `id` property");r.$id=e.external.uri(l)}Object.assign(r,n.def??n.schema);const i=((c=e.external)==null?void 0:c.defs)??{};for(const l of e.seen.entries()){const h=l[1];h.def&&h.defId&&(i[h.defId]=h.def)}e.external||Object.keys(i).length>0&&(e.target==="draft-2020-12"?r.$defs=i:r.definitions=i);try{const l=JSON.parse(JSON.stringify(r));return Object.defineProperty(l,"~standard",{value:{...t["~standard"],jsonSchema:{input:Wr(t,"input",e.processors),output:Wr(t,"output",e.processors)}},enumerable:!1,writable:!1}),l}catch{throw new Error("Error converting schema to JSON.")}}function Ce(e,t){const n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);const s=e._zod.def;if(s.type==="transform")return!0;if(s.type==="array")return Ce(s.element,n);if(s.type==="set")return Ce(s.valueType,n);if(s.type==="lazy")return Ce(s.getter(),n);if(s.type==="promise"||s.type==="optional"||s.type==="nonoptional"||s.type==="nullable"||s.type==="readonly"||s.type==="default"||s.type==="prefault")return Ce(s.innerType,n);if(s.type==="intersection")return Ce(s.left,n)||Ce(s.right,n);if(s.type==="record"||s.type==="map")return Ce(s.keyType,n)||Ce(s.valueType,n);if(s.type==="pipe")return Ce(s.in,n)||Ce(s.out,n);if(s.type==="object"){for(const r in s.shape)if(Ce(s.shape[r],n))return!0;return!1}if(s.type==="union"){for(const r of s.options)if(Ce(r,n))return!0;return!1}if(s.type==="tuple"){for(const r of s.items)if(Ce(r,n))return!0;return!!(s.rest&&Ce(s.rest,n))}return!1}const Cm=(e,t={})=>n=>{const s=cu({...n,processors:t});return pe(e,s),lu(s,e),uu(s,e)},Wr=(e,t,n={})=>s=>{const{libraryOptions:r,target:i}=s??{},o=cu({...r??{},target:i,io:t,processors:n});return pe(e,o),lu(o,e),uu(o,e)},zm={guid:"uuid",url:"uri",datetime:"date-time",json_string:"json-string",regex:""},$m=(e,t,n,s)=>{const r=n;r.type="string";const{minimum:i,maximum:o,format:a,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof i=="number"&&(r.minLength=i),typeof o=="number"&&(r.maxLength=o),a&&(r.format=zm[a]??a,r.format===""&&delete r.format,a==="time"&&delete r.format),l&&(r.contentEncoding=l),c&&c.size>0){const h=[...c];h.length===1?r.pattern=h[0].source:h.length>1&&(r.allOf=[...h.map(f=>({...t.target==="draft-07"||t.target==="draft-04"||t.target==="openapi-3.0"?{type:"string"}:{},pattern:f.source}))])}},Rm=(e,t,n,s)=>{const r=n,{minimum:i,maximum:o,format:a,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:h}=e._zod.bag;typeof a=="string"&&a.includes("int")?r.type="integer":r.type="number",typeof h=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(r.minimum=h,r.exclusiveMinimum=!0):r.exclusiveMinimum=h),typeof i=="number"&&(r.minimum=i,typeof h=="number"&&t.target!=="draft-04"&&(h>=i?delete r.minimum:delete r.exclusiveMinimum)),typeof l=="number"&&(t.target==="draft-04"||t.target==="openapi-3.0"?(r.maximum=l,r.exclusiveMaximum=!0):r.exclusiveMaximum=l),typeof o=="number"&&(r.maximum=o,typeof l=="number"&&t.target!=="draft-04"&&(l<=o?delete r.maximum:delete r.exclusiveMaximum)),typeof c=="number"&&(r.multipleOf=c)},Pm=(e,t,n,s)=>{n.type="boolean"},Dm=(e,t,n,s)=>{n.not={}},Lm=(e,t,n,s)=>{},Mm=(e,t,n,s)=>{const r=e._zod.def,i=Zl(r.entries);i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),n.enum=i},Om=(e,t,n,s)=>{const r=e._zod.def,i=[];for(const o of r.values)if(o===void 0){if(t.unrepresentable==="throw")throw new Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof o=="bigint"){if(t.unrepresentable==="throw")throw new Error("BigInt literals cannot be represented in JSON Schema");i.push(Number(o))}else i.push(o);if(i.length!==0)if(i.length===1){const o=i[0];n.type=o===null?"null":typeof o,t.target==="draft-04"||t.target==="openapi-3.0"?n.enum=[o]:n.const=o}else i.every(o=>typeof o=="number")&&(n.type="number"),i.every(o=>typeof o=="string")&&(n.type="string"),i.every(o=>typeof o=="boolean")&&(n.type="boolean"),i.every(o=>o===null)&&(n.type="null"),n.enum=i},Nm=(e,t,n,s)=>{if(t.unrepresentable==="throw")throw new Error("Custom types cannot be represented in JSON Schema")},Wm=(e,t,n,s)=>{if(t.unrepresentable==="throw")throw new Error("Transforms cannot be represented in JSON Schema")},Fm=(e,t,n,s)=>{const r=n,i=e._zod.def,{minimum:o,maximum:a}=e._zod.bag;typeof o=="number"&&(r.minItems=o),typeof a=="number"&&(r.maxItems=a),r.type="array",r.items=pe(i.element,t,{...s,path:[...s.path,"items"]})},Um=(e,t,n,s)=>{var l;const r=n,i=e._zod.def;r.type="object",r.properties={};const o=i.shape;for(const h in o)r.properties[h]=pe(o[h],t,{...s,path:[...s.path,"properties",h]});const a=new Set(Object.keys(o)),c=new Set([...a].filter(h=>{const f=i.shape[h]._zod;return t.io==="input"?f.optin===void 0:f.optout===void 0}));c.size>0&&(r.required=Array.from(c)),((l=i.catchall)==null?void 0:l._zod.def.type)==="never"?r.additionalProperties=!1:i.catchall?i.catchall&&(r.additionalProperties=pe(i.catchall,t,{...s,path:[...s.path,"additionalProperties"]})):t.io==="output"&&(r.additionalProperties=!1)},Zm=(e,t,n,s)=>{const r=e._zod.def,i=r.inclusive===!1,o=r.options.map((a,c)=>pe(a,t,{...s,path:[...s.path,i?"oneOf":"anyOf",c]}));i?n.oneOf=o:n.anyOf=o},jm=(e,t,n,s)=>{const r=e._zod.def,i=pe(r.left,t,{...s,path:[...s.path,"allOf",0]}),o=pe(r.right,t,{...s,path:[...s.path,"allOf",1]}),a=l=>"allOf"in l&&Object.keys(l).length===1,c=[...a(i)?i.allOf:[i],...a(o)?o.allOf:[o]];n.allOf=c},Hm=(e,t,n,s)=>{const r=n,i=e._zod.def;r.type="object";const o=i.keyType,a=o._zod.bag,c=a==null?void 0:a.patterns;if(i.mode==="loose"&&c&&c.size>0){const h=pe(i.valueType,t,{...s,path:[...s.path,"patternProperties","*"]});r.patternProperties={};for(const f of c)r.patternProperties[f.source]=h}else(t.target==="draft-07"||t.target==="draft-2020-12")&&(r.propertyNames=pe(i.keyType,t,{...s,path:[...s.path,"propertyNames"]})),r.additionalProperties=pe(i.valueType,t,{...s,path:[...s.path,"additionalProperties"]});const l=o._zod.values;if(l){const h=[...l].filter(f=>typeof f=="string"||typeof f=="number");h.length>0&&(r.required=h)}},Bm=(e,t,n,s)=>{const r=e._zod.def,i=pe(r.innerType,t,s),o=t.seen.get(e);t.target==="openapi-3.0"?(o.ref=r.innerType,n.nullable=!0):n.anyOf=[i,{type:"null"}]},Gm=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType},Vm=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType,n.default=JSON.parse(JSON.stringify(r.defaultValue))},qm=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType,t.io==="input"&&(n._prefault=JSON.parse(JSON.stringify(r.defaultValue)))},Km=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType;let o;try{o=r.catchValue(void 0)}catch{throw new Error("Dynamic catch values are not supported in JSON Schema")}n.default=o},Ym=(e,t,n,s)=>{const r=e._zod.def,i=t.io==="input"?r.in._zod.def.type==="transform"?r.out:r.in:r.out;pe(i,t,s);const o=t.seen.get(e);o.ref=i},Xm=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType,n.readOnly=!0},hu=(e,t,n,s)=>{const r=e._zod.def;pe(r.innerType,t,s);const i=t.seen.get(e);i.ref=r.innerType},Jm=b("ZodISODateTime",(e,t)=>{Qf.init(e,t),ae.init(e,t)});function Qm(e){return im(Jm,e)}const ev=b("ZodISODate",(e,t)=>{eg.init(e,t),ae.init(e,t)});function tv(e){return om(ev,e)}const nv=b("ZodISOTime",(e,t)=>{tg.init(e,t),ae.init(e,t)});function sv(e){return am(nv,e)}const rv=b("ZodISODuration",(e,t)=>{ng.init(e,t),ae.init(e,t)});function iv(e){return cm(rv,e)}const du=(e,t)=>{Gl.init(e,t),e.name="ZodError",Object.defineProperties(e,{format:{value:n=>Bp(e,n)},flatten:{value:n=>Hp(e,n)},addIssue:{value:n=>{e.issues.push(n),e.message=JSON.stringify(e.issues,co,2)}},addIssues:{value:n=>{e.issues.push(...n),e.message=JSON.stringify(e.issues,co,2)}},isEmpty:{get(){return e.issues.length===0}}})},Ec=b("ZodError",du),He=b("ZodError",du,{Parent:Error}),ov=Yo(He),av=Xo(He),cv=si(He),lv=ri(He),uv=qp(He),hv=Kp(He),dv=Yp(He),pv=Xp(He),fv=Jp(He),gv=Qp(He),mv=ef(He),vv=tf(He),oe=b("ZodType",(e,t)=>(ie.init(e,t),Object.assign(e["~standard"],{jsonSchema:{input:Wr(e,"input"),output:Wr(e,"output")}}),e.toJSONSchema=Cm(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(Pt(t,{checks:[...t.checks??[],...n.map(s=>typeof s=="function"?{_zod:{check:s,def:{check:"custom"},onattach:[]}}:s)]}),{parent:!0}),e.with=e.check,e.clone=(n,s)=>Dt(e,n,s),e.brand=()=>e,e.register=(n,s)=>(n.add(e,s),e),e.parse=(n,s)=>ov(e,n,s,{callee:e.parse}),e.safeParse=(n,s)=>cv(e,n,s),e.parseAsync=async(n,s)=>av(e,n,s,{callee:e.parseAsync}),e.safeParseAsync=async(n,s)=>lv(e,n,s),e.spa=e.safeParseAsync,e.encode=(n,s)=>uv(e,n,s),e.decode=(n,s)=>hv(e,n,s),e.encodeAsync=async(n,s)=>dv(e,n,s),e.decodeAsync=async(n,s)=>pv(e,n,s),e.safeEncode=(n,s)=>fv(e,n,s),e.safeDecode=(n,s)=>gv(e,n,s),e.safeEncodeAsync=async(n,s)=>mv(e,n,s),e.safeDecodeAsync=async(n,s)=>vv(e,n,s),e.refine=(n,s)=>e.check(l_(n,s)),e.superRefine=n=>e.check(u_(n)),e.overwrite=n=>e.check(Bn(n)),e.optional=()=>Ic(e),e.exactOptional=()=>Yv(e),e.nullable=()=>Cc(e),e.nullish=()=>Ic(Cc(e)),e.nonoptional=n=>n_(e,n),e.array=()=>R(e),e.or=n=>W([e,n]),e.and=n=>oi(e,n),e.transform=n=>zc(e,qv(n)),e.default=n=>Qv(e,n),e.prefault=n=>t_(e,n),e.catch=n=>r_(e,n),e.pipe=n=>zc(e,n),e.readonly=()=>a_(e),e.describe=n=>{const s=e.clone();return hs.add(s,{description:n}),s},Object.defineProperty(e,"description",{get(){var n;return(n=hs.get(e))==null?void 0:n.description},configurable:!0}),e.meta=(...n)=>{if(n.length===0)return hs.get(e);const s=e.clone();return hs.add(s,n[0]),s},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=n=>n(e),e)),pu=b("_ZodString",(e,t)=>{Jo.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(s,r,i)=>$m(e,s,r);const n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...s)=>e.check(fm(...s)),e.includes=(...s)=>e.check(vm(...s)),e.startsWith=(...s)=>e.check(_m(...s)),e.endsWith=(...s)=>e.check(ym(...s)),e.min=(...s)=>e.check(Nr(...s)),e.max=(...s)=>e.check(ou(...s)),e.length=(...s)=>e.check(au(...s)),e.nonempty=(...s)=>e.check(Nr(1,...s)),e.lowercase=s=>e.check(gm(s)),e.uppercase=s=>e.check(mm(s)),e.trim=()=>e.check(wm()),e.normalize=(...s)=>e.check(km(...s)),e.toLowerCase=()=>e.check(bm()),e.toUpperCase=()=>e.check(Sm()),e.slugify=()=>e.check(xm())}),_v=b("ZodString",(e,t)=>{Jo.init(e,t),pu.init(e,t),e.email=n=>e.check(Ng(yv,n)),e.url=n=>e.check(jg(kv,n)),e.jwt=n=>e.check(rm(Lv,n)),e.emoji=n=>e.check(Hg(wv,n)),e.guid=n=>e.check(wc(Ac,n)),e.uuid=n=>e.check(Wg(fr,n)),e.uuidv4=n=>e.check(Fg(fr,n)),e.uuidv6=n=>e.check(Ug(fr,n)),e.uuidv7=n=>e.check(Zg(fr,n)),e.nanoid=n=>e.check(Bg(bv,n)),e.guid=n=>e.check(wc(Ac,n)),e.cuid=n=>e.check(Gg(Sv,n)),e.cuid2=n=>e.check(Vg(xv,n)),e.ulid=n=>e.check(qg(Ev,n)),e.base64=n=>e.check(tm(Rv,n)),e.base64url=n=>e.check(nm(Pv,n)),e.xid=n=>e.check(Kg(Av,n)),e.ksuid=n=>e.check(Yg(Tv,n)),e.ipv4=n=>e.check(Xg(Iv,n)),e.ipv6=n=>e.check(Jg(Cv,n)),e.cidrv4=n=>e.check(Qg(zv,n)),e.cidrv6=n=>e.check(em($v,n)),e.e164=n=>e.check(sm(Dv,n)),e.datetime=n=>e.check(Qm(n)),e.date=n=>e.check(tv(n)),e.time=n=>e.check(sv(n)),e.duration=n=>e.check(iv(n))});function u(e){return Og(_v,e)}const ae=b("ZodStringFormat",(e,t)=>{se.init(e,t),pu.init(e,t)}),yv=b("ZodEmail",(e,t)=>{Hf.init(e,t),ae.init(e,t)}),Ac=b("ZodGUID",(e,t)=>{Zf.init(e,t),ae.init(e,t)}),fr=b("ZodUUID",(e,t)=>{jf.init(e,t),ae.init(e,t)}),kv=b("ZodURL",(e,t)=>{Bf.init(e,t),ae.init(e,t)}),wv=b("ZodEmoji",(e,t)=>{Gf.init(e,t),ae.init(e,t)}),bv=b("ZodNanoID",(e,t)=>{Vf.init(e,t),ae.init(e,t)}),Sv=b("ZodCUID",(e,t)=>{qf.init(e,t),ae.init(e,t)}),xv=b("ZodCUID2",(e,t)=>{Kf.init(e,t),ae.init(e,t)}),Ev=b("ZodULID",(e,t)=>{Yf.init(e,t),ae.init(e,t)}),Av=b("ZodXID",(e,t)=>{Xf.init(e,t),ae.init(e,t)}),Tv=b("ZodKSUID",(e,t)=>{Jf.init(e,t),ae.init(e,t)}),Iv=b("ZodIPv4",(e,t)=>{sg.init(e,t),ae.init(e,t)}),Cv=b("ZodIPv6",(e,t)=>{rg.init(e,t),ae.init(e,t)}),zv=b("ZodCIDRv4",(e,t)=>{ig.init(e,t),ae.init(e,t)}),$v=b("ZodCIDRv6",(e,t)=>{og.init(e,t),ae.init(e,t)}),Rv=b("ZodBase64",(e,t)=>{ag.init(e,t),ae.init(e,t)}),Pv=b("ZodBase64URL",(e,t)=>{lg.init(e,t),ae.init(e,t)}),Dv=b("ZodE164",(e,t)=>{ug.init(e,t),ae.init(e,t)}),Lv=b("ZodJWT",(e,t)=>{dg.init(e,t),ae.init(e,t)}),fu=b("ZodNumber",(e,t)=>{nu.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(s,r,i)=>Rm(e,s,r),e.gt=(s,r)=>e.check(Sc(s,r)),e.gte=(s,r)=>e.check(Li(s,r)),e.min=(s,r)=>e.check(Li(s,r)),e.lt=(s,r)=>e.check(bc(s,r)),e.lte=(s,r)=>e.check(Di(s,r)),e.max=(s,r)=>e.check(Di(s,r)),e.int=s=>e.check(Tc(s)),e.safe=s=>e.check(Tc(s)),e.positive=s=>e.check(Sc(0,s)),e.nonnegative=s=>e.check(Li(0,s)),e.negative=s=>e.check(bc(0,s)),e.nonpositive=s=>e.check(Di(0,s)),e.multipleOf=(s,r)=>e.check(xc(s,r)),e.step=(s,r)=>e.check(xc(s,r)),e.finite=()=>e;const n=e._zod.bag;e.minValue=Math.max(n.minimum??Number.NEGATIVE_INFINITY,n.exclusiveMinimum??Number.NEGATIVE_INFINITY)??null,e.maxValue=Math.min(n.maximum??Number.POSITIVE_INFINITY,n.exclusiveMaximum??Number.POSITIVE_INFINITY)??null,e.isInt=(n.format??"").includes("int")||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null});function N(e){return lm(fu,e)}const Mv=b("ZodNumberFormat",(e,t)=>{pg.init(e,t),fu.init(e,t)});function Tc(e){return um(Mv,e)}const Ov=b("ZodBoolean",(e,t)=>{fg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Pm(e,n,s)});function _e(e){return hm(Ov,e)}const Nv=b("ZodUnknown",(e,t)=>{gg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Lm()});function _(){return dm(Nv)}const Wv=b("ZodNever",(e,t)=>{mg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Dm(e,n,s)});function Fv(e){return pm(Wv,e)}const Uv=b("ZodArray",(e,t)=>{vg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Fm(e,n,s,r),e.element=t.element,e.min=(n,s)=>e.check(Nr(n,s)),e.nonempty=n=>e.check(Nr(1,n)),e.max=(n,s)=>e.check(ou(n,s)),e.length=(n,s)=>e.check(au(n,s)),e.unwrap=()=>e.element});function R(e,t){return Em(Uv,e,t)}const Zv=b("ZodObject",(e,t)=>{yg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Um(e,n,s,r),Y(e,"shape",()=>t.shape),e.keyof=()=>gu(Object.keys(e._zod.def.shape)),e.catchall=n=>e.clone({...e._zod.def,catchall:n}),e.passthrough=()=>e.clone({...e._zod.def,catchall:_()}),e.loose=()=>e.clone({...e._zod.def,catchall:_()}),e.strict=()=>e.clone({...e._zod.def,catchall:Fv()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=n=>Wp(e,n),e.safeExtend=n=>Fp(e,n),e.merge=n=>Up(e,n),e.pick=n=>Op(e,n),e.omit=n=>Np(e,n),e.partial=(...n)=>Zp(mu,e,n[0]),e.required=(...n)=>jp(vu,e,n[0])});function p(e,t){return new Zv({type:"object",shape:e,catchall:_(),...P(t)})}const jv=b("ZodUnion",(e,t)=>{kg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Zm(e,n,s,r),e.options=t.options});function W(e,t){return new jv({type:"union",options:e,...P(t)})}const Hv=b("ZodIntersection",(e,t)=>{wg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>jm(e,n,s,r)});function oi(e,t){return new Hv({type:"intersection",left:e,right:t})}const Bv=b("ZodRecord",(e,t)=>{bg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Hm(e,n,s,r),e.keyType=t.keyType,e.valueType=t.valueType});function k(e,t,n){return new Bv({type:"record",keyType:e,valueType:t,...P(n)})}const uo=b("ZodEnum",(e,t)=>{Sg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(s,r,i)=>Mm(e,s,r),e.enum=t.entries,e.options=Object.values(t.entries);const n=new Set(Object.keys(t.entries));e.extract=(s,r)=>{const i={};for(const o of s)if(n.has(o))i[o]=t.entries[o];else throw new Error(`Key ${o} not found in enum`);return new uo({...t,checks:[],...P(r),entries:i})},e.exclude=(s,r)=>{const i={...t.entries};for(const o of s)if(n.has(o))delete i[o];else throw new Error(`Key ${o} not found in enum`);return new uo({...t,checks:[],...P(r),entries:i})}});function gu(e,t){const n=Array.isArray(e)?Object.fromEntries(e.map(s=>[s,s])):e;return new uo({type:"enum",entries:n,...P(t)})}const Gv=b("ZodLiteral",(e,t)=>{xg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Om(e,n,s),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw new Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})});function x(e,t){return new Gv({type:"literal",values:Array.isArray(e)?e:[e],...P(t)})}const Vv=b("ZodTransform",(e,t)=>{Eg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Wm(e,n),e._zod.parse=(n,s)=>{if(s.direction==="backward")throw new Fl(e.constructor.name);n.addIssue=i=>{if(typeof i=="string")n.issues.push(bs(i,n.value,t));else{const o=i;o.fatal&&(o.continue=!1),o.code??(o.code="custom"),o.input??(o.input=n.value),o.inst??(o.inst=e),n.issues.push(bs(o))}};const r=t.transform(n.value,n);return r instanceof Promise?r.then(i=>(n.value=i,n)):(n.value=r,n)}});function qv(e){return new Vv({type:"transform",transform:e})}const mu=b("ZodOptional",(e,t)=>{iu.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>hu(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function Ic(e){return new mu({type:"optional",innerType:e})}const Kv=b("ZodExactOptional",(e,t)=>{Ag.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>hu(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function Yv(e){return new Kv({type:"optional",innerType:e})}const Xv=b("ZodNullable",(e,t)=>{Tg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Bm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function Cc(e){return new Xv({type:"nullable",innerType:e})}const Jv=b("ZodDefault",(e,t)=>{Ig.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Vm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap});function Qv(e,t){return new Jv({type:"default",innerType:e,get defaultValue(){return typeof t=="function"?t():Hl(t)}})}const e_=b("ZodPrefault",(e,t)=>{Cg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>qm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function t_(e,t){return new e_({type:"prefault",innerType:e,get defaultValue(){return typeof t=="function"?t():Hl(t)}})}const vu=b("ZodNonOptional",(e,t)=>{zg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Gm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function n_(e,t){return new vu({type:"nonoptional",innerType:e,...P(t)})}const s_=b("ZodCatch",(e,t)=>{$g.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Km(e,n,s,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap});function r_(e,t){return new s_({type:"catch",innerType:e,catchValue:typeof t=="function"?t:()=>t})}const i_=b("ZodPipe",(e,t)=>{Rg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Ym(e,n,s,r),e.in=t.in,e.out=t.out});function zc(e,t){return new i_({type:"pipe",in:e,out:t})}const o_=b("ZodReadonly",(e,t)=>{Pg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Xm(e,n,s,r),e.unwrap=()=>e._zod.def.innerType});function a_(e){return new o_({type:"readonly",innerType:e})}const c_=b("ZodCustom",(e,t)=>{Dg.init(e,t),oe.init(e,t),e._zod.processJSONSchema=(n,s,r)=>Nm(e,n)});function l_(e,t={}){return Am(c_,e,t)}function u_(e){return Tm(e)}const te={authenticate:"authenticate",document_did_change:"document/didChange",document_did_close:"document/didClose",document_did_focus:"document/didFocus",document_did_open:"document/didOpen",document_did_save:"document/didSave",initialize:"initialize",logout:"logout",nes_accept:"nes/accept",nes_close:"nes/close",nes_reject:"nes/reject",nes_start:"nes/start",nes_suggest:"nes/suggest",session_cancel:"session/cancel",session_close:"session/close",session_fork:"session/fork",session_list:"session/list",session_load:"session/load",session_new:"session/new",session_prompt:"session/prompt",session_resume:"session/resume",session_set_config_option:"session/set_config_option",session_set_mode:"session/set_mode",session_set_model:"session/set_model"},ct={fs_read_text_file:"fs/read_text_file",fs_write_text_file:"fs/write_text_file",session_request_permission:"session/request_permission",session_update:"session/update",terminal_create:"terminal/create",terminal_kill:"terminal/kill",terminal_output:"terminal/output",terminal_release:"terminal/release",terminal_wait_for_exit:"terminal/wait_for_exit"},h_=1,d_=p({_meta:k(u(),_()).nullish(),terminal:_e().optional().default(!1)}),p_=p({_meta:k(u(),_()).nullish(),label:u().nullish(),name:u(),optional:_e().optional().default(!1),secret:_e().optional().default(!0)}),f_=p({_meta:k(u(),_()).nullish(),description:u().nullish(),id:u(),name:u()}),g_=p({_meta:k(u(),_()).nullish(),description:u().nullish(),id:u(),link:u().nullish(),name:u(),vars:R(p_)}),m_=p({_meta:k(u(),_()).nullish(),args:R(u()).optional(),description:u().nullish(),env:k(u(),u()).optional(),id:u(),name:u()}),v_=W([g_.and(p({type:x("env_var")})),m_.and(p({type:x("terminal")})),f_]),__=p({_meta:k(u(),_()).nullish(),methodId:u()}),y_=p({_meta:k(u(),_()).nullish()}),k_=p({_meta:k(u(),_()).nullish(),blob:u(),mimeType:u().nullish(),uri:u()}),w_=p({default:_e().nullish(),description:u().nullish(),title:u().nullish()}),b_=p({_meta:k(u(),_()).nullish()}),S_=p({_meta:k(u(),_()).nullish()}),x_=p({amount:N(),currency:u()}),E_=p({_meta:k(u(),_()).nullish(),terminalId:u()}),A_=p({_meta:k(u(),_()).nullish(),newText:u(),oldText:u().nullish(),path:u()}),T_=W([u(),N(),N(),_e(),R(u())]),I_=p({content:k(u(),T_).nullish()}),C_=W([I_.and(p({action:x("accept")})),p({action:x("decline")}),p({action:x("cancel")})]),z_=p({_meta:k(u(),_()).nullish()}),_u=u(),$_=p({_meta:k(u(),_()).nullish(),elicitationId:_u}),R_=p({_meta:k(u(),_()).nullish(),action:C_}),P_=x("object"),D_=x("string"),L_=p({_meta:k(u(),_()).nullish()}),M_=p({_meta:k(u(),_()).nullish(),form:z_.nullish(),url:L_.nullish()}),O_=p({elicitationId:_u,url:u().url()}),yu=p({const:u(),title:u()}),ku=p({_meta:k(u(),_()).nullish(),name:u(),value:u()}),N_=W([x(-32700),x(-32600),x(-32601),x(-32602),x(-32603),x(-32800),x(-32e3),x(-32002),x(-32042),N().int().min(-2147483648,{message:"Invalid value: Expected int32 to be >= -2147483648"}).max(2147483647,{message:"Invalid value: Expected int32 to be <= 2147483647"})]),wu=p({code:N_,data:_().optional(),message:u()}),bu=_(),Su=_(),xu=_(),W_=p({_meta:k(u(),_()).nullish(),readTextFile:_e().optional().default(!1),writeTextFile:_e().optional().default(!1)}),Eu=p({_meta:k(u(),_()).nullish(),name:u(),value:u()}),Au=p({_meta:k(u(),_()).nullish(),name:u(),title:u().nullish(),version:u()}),F_=p({default:N().nullish(),description:u().nullish(),maximum:N().nullish(),minimum:N().nullish(),title:u().nullish()}),U_=p({_meta:k(u(),_()).nullish()}),Z_=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cursor:u().nullish(),cwd:u().nullish()}),j_=p({_meta:k(u(),_()).nullish()}),H_=p({_meta:k(u(),_()).nullish(),logout:j_.nullish()}),B_=p({_meta:k(u(),_()).nullish()}),G_=p({_meta:k(u(),_()).nullish()}),V_=p({_meta:k(u(),_()).nullish(),http:_e().optional().default(!1),sse:_e().optional().default(!1)}),q_=p({_meta:k(u(),_()).nullish(),headers:R(Eu),name:u(),url:u()}),K_=p({_meta:k(u(),_()).nullish(),headers:R(Eu),name:u(),url:u()}),Y_=p({_meta:k(u(),_()).nullish(),args:R(u()),command:u(),env:R(ku),name:u()}),ai=W([q_.and(p({type:x("http")})),K_.and(p({type:x("sse")})),Y_]),Qo=u(),X_=p({_meta:k(u(),_()).nullish(),description:u().nullish(),modelId:Qo,name:u()}),J_=W([x("error"),x("warning"),x("information"),x("hint")]),Q_=p({_meta:k(u(),_()).nullish()}),ey=p({_meta:k(u(),_()).nullish()}),ty=p({_meta:k(u(),_()).nullish()}),ny=p({_meta:k(u(),_()).nullish()}),sy=p({_meta:k(u(),_()).nullish()}),ry=p({_meta:k(u(),_()).nullish(),maxCount:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish()}),iy=p({diff:u(),uri:u()}),oy=p({endLine:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}),startLine:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}),text:u()}),ay=p({_meta:k(u(),_()).nullish()}),cy=p({_meta:k(u(),_()).nullish()}),ly=p({languageId:u(),text:u(),uri:u()}),uy=p({_meta:k(u(),_()).nullish(),maxCount:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish()}),hy=W([x("rejected"),x("ignored"),x("replaced"),x("cancelled")]),dy=p({excerpts:R(oy),uri:u()}),py=p({_meta:k(u(),_()).nullish()}),fy=p({_meta:k(u(),_()).nullish()}),gy=p({name:u(),owner:u(),remoteUrl:u()}),my=p({_meta:k(u(),_()).nullish()}),vy=p({_meta:k(u(),_()).nullish(),jump:ay.nullish(),rename:fy.nullish(),searchAndReplace:my.nullish()}),_y=p({id:u(),isRegex:_e().nullish(),replace:u(),search:u(),uri:u()}),yy=W([x("automatic"),x("diagnostic"),x("manual")]),ky=p({_meta:k(u(),_()).nullish(),maxCount:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish()}),wy=p({_meta:k(u(),_()).nullish(),diagnostics:Q_.nullish(),editHistory:ry.nullish(),openFiles:cy.nullish(),recentFiles:uy.nullish(),relatedSnippets:py.nullish(),userActions:ky.nullish()}),by=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),mcpServers:R(ai)}),Sy=p({default:N().nullish(),description:u().nullish(),maximum:N().nullish(),minimum:N().nullish(),title:u().nullish()}),Tu=u(),xy=W([x("allow_once"),x("allow_always"),x("reject_once"),x("reject_always")]),Ey=p({_meta:k(u(),_()).nullish(),kind:xy,name:u(),optionId:Tu}),Ay=W([x("high"),x("medium"),x("low")]),Ty=W([x("pending"),x("in_progress"),x("completed")]),Iy=p({_meta:k(u(),_()).nullish(),content:u(),priority:Ay,status:Ty}),Cy=p({_meta:k(u(),_()).nullish(),entries:R(Iy)}),$t=p({character:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}),line:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"})}),zy=p({id:u(),position:$t,uri:u()}),$y=p({id:u(),newName:u(),position:$t,uri:u()}),Ry=p({action:u(),position:$t,timestampMs:N(),uri:u()}),Iu=W([x("utf-16"),x("utf-32"),x("utf-8")]),Py=p({_meta:k(u(),_()).nullish(),auth:d_.optional().default({terminal:!1}),elicitation:M_.nullish(),fs:W_.optional().default({readTextFile:!1,writeTextFile:!1}),nes:vy.nullish(),positionEncodings:R(Iu).optional(),terminal:_e().optional().default(!1)}),Dy=p({_meta:k(u(),_()).nullish(),audio:_e().optional().default(!1),embeddedContext:_e().optional().default(!1),image:_e().optional().default(!1)}),Cu=N().int().gte(0).lte(65535),Ly=p({_meta:k(u(),_()).nullish(),clientCapabilities:Py.optional().default({auth:{terminal:!1},fs:{readTextFile:!1,writeTextFile:!1},terminal:!1}),clientInfo:Au.nullish(),protocolVersion:Cu}),Gn=p({end:$t,start:$t}),My=p({message:u(),range:Gn,severity:J_,uri:u()}),Oy=p({languageId:u(),lastFocusedMs:N().nullish(),uri:u(),visibleRange:Gn.nullish()}),Ny=p({_meta:k(u(),_()).nullish(),diagnostics:R(My).nullish(),editHistory:R(iy).nullish(),openFiles:R(Oy).nullish(),recentFiles:R(ly).nullish(),relatedSnippets:R(dy).nullish(),userActions:R(Ry).nullish()}),Wy=p({newText:u(),range:Gn}),Fy=p({cursorPosition:$t.nullish(),edits:R(Wy),id:u(),uri:u()}),Uy=W([Fy.and(p({kind:x("edit")})),zy.and(p({kind:x("jump")})),$y.and(p({kind:x("rename")})),_y.and(p({kind:x("searchAndReplace")}))]),Zy=p({_meta:k(u(),_()).nullish(),content:u()}),jy=p({_meta:k(u(),_()).nullish()}),nn=W([N(),u()]).nullable();p({_meta:k(u(),_()).nullish(),requestId:nn});const Hy=gu(["assistant","user"]),Ys=p({_meta:k(u(),_()).nullish(),audience:R(Hy).nullish(),lastModified:u().nullish(),priority:N().nullish()}),By=p({_meta:k(u(),_()).nullish(),annotations:Ys.nullish(),data:u(),mimeType:u()}),Gy=p({_meta:k(u(),_()).nullish(),annotations:Ys.nullish(),data:u(),mimeType:u(),uri:u().nullish()}),Vy=p({_meta:k(u(),_()).nullish(),annotations:Ys.nullish(),description:u().nullish(),mimeType:u().nullish(),name:u(),size:N().nullish(),title:u().nullish(),uri:u()}),qy=p({_meta:k(u(),_()).nullish(),optionId:Tu}),Ky=W([p({outcome:x("cancelled")}),qy.and(p({outcome:x("selected")}))]),Yy=p({_meta:k(u(),_()).nullish(),outcome:Ky}),Xy=p({_meta:k(u(),_()).nullish()}),Jy=p({_meta:k(u(),_()).nullish()}),Qy=p({currentValue:_e()}),ek=u(),zu=u(),tk=W([x("mode"),x("model"),x("thought_level"),u()]),ea=u(),$u=p({_meta:k(u(),_()).nullish(),description:u().nullish(),name:u(),value:ea}),nk=p({_meta:k(u(),_()).nullish(),group:ek,name:u(),options:R($u)}),sk=W([R($u),R(nk)]),rk=p({currentValue:ea,options:sk}),Vn=oi(W([rk.and(p({type:x("select")})),Qy.and(p({type:x("boolean")}))]),p({_meta:k(u(),_()).nullish(),category:tk.nullish(),description:u().nullish(),id:zu,name:u()})),ik=p({_meta:k(u(),_()).nullish(),configOptions:R(Vn)}),ok=p({_meta:k(u(),_()).nullish()}),G=u(),ak=p({_meta:k(u(),_()).nullish(),id:u(),sessionId:G}),ck=p({_meta:k(u(),_()).nullish(),sessionId:G}),lk=p({_meta:k(u(),_()).nullish(),sessionId:G}),uk=p({_meta:k(u(),_()).nullish(),sessionId:G}),Ru=p({_meta:k(u(),_()).nullish(),args:R(u()).optional(),command:u(),cwd:u().nullish(),env:R(ku).optional(),outputByteLimit:N().nullish(),sessionId:G}),hk=p({_meta:k(u(),_()).nullish(),sessionId:G,uri:u()}),dk=p({_meta:k(u(),_()).nullish(),position:$t,sessionId:G,uri:u(),version:N(),visibleRange:Gn}),pk=p({_meta:k(u(),_()).nullish(),languageId:u(),sessionId:G,text:u(),uri:u(),version:N()}),fk=p({_meta:k(u(),_()).nullish(),sessionId:G,uri:u()}),gk=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),mcpServers:R(ai).optional(),sessionId:G}),Pu=p({_meta:k(u(),_()).nullish(),sessionId:G,terminalId:u()}),mk=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),mcpServers:R(ai),sessionId:G}),Du=p({_meta:k(u(),_()).nullish(),limit:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),line:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),path:u(),sessionId:G}),vk=p({_meta:k(u(),_()).nullish(),id:u(),reason:hy.nullish(),sessionId:G}),Lu=p({_meta:k(u(),_()).nullish(),sessionId:G,terminalId:u()}),_k=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),mcpServers:R(ai).optional(),sessionId:G}),yk=p({_meta:k(u(),_()).nullish(),additionalDirectories:R(u()).optional(),cwd:u(),sessionId:G,title:u().nullish(),updatedAt:u().nullish()}),kk=p({_meta:k(u(),_()).nullish(),nextCursor:u().nullish(),sessions:R(yk)}),wk=p({_meta:k(u(),_()).nullish(),title:u().nullish(),updatedAt:u().nullish()}),bk=p({_meta:k(u(),_()).nullish()}),ci=u(),Sk=p({_meta:k(u(),_()).nullish(),currentModeId:ci}),xk=p({_meta:k(u(),_()).nullish(),description:u().nullish(),id:ci,name:u()}),li=p({_meta:k(u(),_()).nullish(),availableModes:R(xk),currentModeId:ci}),ui=p({_meta:k(u(),_()).nullish(),availableModels:R(X_),currentModelId:Qo}),Ek=p({_meta:k(u(),_()).nullish(),configOptions:R(Vn).nullish(),models:ui.nullish(),modes:li.nullish(),sessionId:G}),Ak=p({_meta:k(u(),_()).nullish(),configOptions:R(Vn).nullish(),models:ui.nullish(),modes:li.nullish()}),Tk=p({_meta:k(u(),_()).nullish(),configOptions:R(Vn).nullish(),models:ui.nullish(),modes:li.nullish(),sessionId:G}),Ik=p({_meta:k(u(),_()).nullish(),configOptions:R(Vn).nullish(),models:ui.nullish(),modes:li.nullish()}),Ck=p({_meta:k(u(),_()).nullish()}),zk=p({_meta:k(u(),_()).nullish(),additionalDirectories:Xy.nullish(),close:Jy.nullish(),fork:ok.nullish(),list:bk.nullish(),resume:Ck.nullish()}),$k=oi(W([p({type:x("boolean"),value:_e()}),p({value:ea})]),p({_meta:k(u(),_()).nullish(),configId:zu,sessionId:G})),Rk=p({_meta:k(u(),_()).nullish(),configOptions:R(Vn)}),Pk=p({_meta:k(u(),_()).nullish(),modeId:ci,sessionId:G}),Dk=p({_meta:k(u(),_()).nullish()}),Lk=p({_meta:k(u(),_()).nullish(),modelId:Qo,sessionId:G}),Mk=p({_meta:k(u(),_()).nullish()}),Ok=p({_meta:k(u(),_()).nullish(),sessionId:G}),Nk=W([x("end_turn"),x("max_tokens"),x("max_turn_requests"),x("refusal"),x("cancelled")]),Wk=W([x("email"),x("uri"),x("date"),x("date-time")]),Fk=p({default:u().nullish(),description:u().nullish(),enum:R(u()).nullish(),format:Wk.nullish(),maxLength:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),minLength:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),oneOf:R(yu).nullish(),pattern:u().nullish(),title:u().nullish()}),Uk=p({_meta:k(u(),_()).nullish(),context:Ny.nullish(),position:$t,selection:Gn.nullish(),sessionId:G,triggerKind:yy,uri:u(),version:N()}),Zk=p({_meta:k(u(),_()).nullish(),suggestions:R(Uy)}),jk=p({_meta:k(u(),_()).nullish(),terminalId:u()}),Hk=p({_meta:k(u(),_()).nullish(),exitCode:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),signal:u().nullish()}),Mu=p({_meta:k(u(),_()).nullish(),sessionId:G,terminalId:u()}),Bk=p({_meta:k(u(),_()).nullish(),exitStatus:Hk.nullish(),output:u(),truncated:_e()}),Gk=p({_meta:k(u(),_()).nullish(),annotations:Ys.nullish(),text:u()}),Vk=p({range:Gn.nullish(),text:u()}),qk=p({_meta:k(u(),_()).nullish(),contentChanges:R(Vk),sessionId:G,uri:u(),version:N()});p({method:u(),params:W([ck,pk,qk,hk,fk,dk,ak,vk,bu]).nullish()});const Kk=W([x("full"),x("incremental")]),Yk=p({_meta:k(u(),_()).nullish(),syncKind:Kk}),Xk=p({_meta:k(u(),_()).nullish(),didChange:Yk.nullish(),didClose:ey.nullish(),didFocus:ty.nullish(),didOpen:ny.nullish(),didSave:sy.nullish()}),Jk=p({_meta:k(u(),_()).nullish(),document:Xk.nullish()}),Qk=p({_meta:k(u(),_()).nullish(),context:wy.nullish(),events:Jk.nullish()}),ew=p({_meta:k(u(),_()).nullish(),auth:H_.optional().default({}),loadSession:_e().optional().default(!1),mcpCapabilities:V_.optional().default({http:!1,sse:!1}),nes:Qk.nullish(),positionEncoding:Iu.nullish(),promptCapabilities:Dy.optional().default({audio:!1,embeddedContext:!1,image:!1}),sessionCapabilities:zk.optional().default({})}),tw=p({_meta:k(u(),_()).nullish(),agentCapabilities:ew.optional().default({auth:{},loadSession:!1,mcpCapabilities:{http:!1,sse:!1},promptCapabilities:{audio:!1,embeddedContext:!1,image:!1},sessionCapabilities:{}}),agentInfo:Au.nullish(),authMethods:R(v_).optional().default([]),protocolVersion:Cu}),nw=p({_meta:k(u(),_()).nullish(),mimeType:u().nullish(),text:u(),uri:u()}),sw=W([nw,k_]),rw=p({_meta:k(u(),_()).nullish(),annotations:Ys.nullish(),resource:sw}),ta=W([Gk.and(p({type:x("text")})),Gy.and(p({type:x("image")})),By.and(p({type:x("audio")})),Vy.and(p({type:x("resource_link")})),rw.and(p({type:x("resource")}))]),iw=p({_meta:k(u(),_()).nullish(),content:ta}),Mi=p({_meta:k(u(),_()).nullish(),content:ta,messageId:u().nullish()}),ow=p({_meta:k(u(),_()).nullish(),messageId:u().nullish(),prompt:R(ta),sessionId:G}),aw=p({anyOf:R(yu)}),Ou=W([iw.and(p({type:x("content")})),A_.and(p({type:x("diff")})),jk.and(p({type:x("terminal")}))]),Nu=u(),Wu=p({_meta:k(u(),_()).nullish(),line:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),path:u()}),Fu=W([x("pending"),x("in_progress"),x("completed"),x("failed")]),Uu=W([x("read"),x("edit"),x("delete"),x("move"),x("search"),x("execute"),x("think"),x("fetch"),x("switch_mode"),x("other")]),cw=p({_meta:k(u(),_()).nullish(),content:R(Ou).optional(),kind:Uu.optional(),locations:R(Wu).optional(),rawInput:_().optional(),rawOutput:_().optional(),status:Fu.optional(),title:u(),toolCallId:Nu}),Zu=p({_meta:k(u(),_()).nullish(),content:R(Ou).nullish(),kind:Uu.nullish(),locations:R(Wu).nullish(),rawInput:_().optional(),rawOutput:_().optional(),status:Fu.nullish(),title:u().nullish(),toolCallId:Nu}),ju=p({_meta:k(u(),_()).nullish(),options:R(Ey),sessionId:G,toolCall:Zu}),lw=p({_meta:k(u(),_()).nullish(),hint:u()}),uw=lw,hw=p({_meta:k(u(),_()).nullish(),description:u(),input:uw.nullish(),name:u()}),dw=p({_meta:k(u(),_()).nullish(),availableCommands:R(hw)}),pw=p({enum:R(u()),type:D_}),fw=W([pw,aw]),gw=p({default:R(u()).nullish(),description:u().nullish(),items:fw,maxItems:N().nullish(),minItems:N().nullish(),title:u().nullish()}),mw=W([Fk.and(p({type:x("string")})),Sy.and(p({type:x("number")})),F_.and(p({type:x("integer")})),w_.and(p({type:x("boolean")})),gw.and(p({type:x("array")}))]),vw=p({description:u().nullish(),properties:k(u(),mw).optional().default({}),required:R(u()).nullish(),title:u().nullish(),type:P_.optional().default("object")}),_w=p({requestedSchema:vw}),yw=oi(W([_w.and(p({mode:x("form")})),O_.and(p({mode:x("url")}))]),p({_meta:k(u(),_()).nullish(),message:u(),sessionId:G})),kw=p({cachedReadTokens:N().nullish(),cachedWriteTokens:N().nullish(),inputTokens:N(),outputTokens:N(),thoughtTokens:N().nullish(),totalTokens:N()}),ww=p({_meta:k(u(),_()).nullish(),stopReason:Nk,usage:kw.nullish(),userMessageId:u().nullish()});W([p({id:nn,result:W([tw,y_,G_,Tk,Ak,kk,Ek,Ik,S_,Dk,Rk,ww,Mk,Ok,Zk,b_,xu])}),p({error:wu,id:nn})]);const bw=p({_meta:k(u(),_()).nullish(),cost:x_.nullish(),size:N(),used:N()}),Sw=W([Mi.and(p({sessionUpdate:x("user_message_chunk")})),Mi.and(p({sessionUpdate:x("agent_message_chunk")})),Mi.and(p({sessionUpdate:x("agent_thought_chunk")})),cw.and(p({sessionUpdate:x("tool_call")})),Zu.and(p({sessionUpdate:x("tool_call_update")})),Cy.and(p({sessionUpdate:x("plan")})),dw.and(p({sessionUpdate:x("available_commands_update")})),Sk.and(p({sessionUpdate:x("current_mode_update")})),ik.and(p({sessionUpdate:x("config_option_update")})),wk.and(p({sessionUpdate:x("session_info_update")})),bw.and(p({sessionUpdate:x("usage_update")}))]),Hu=p({_meta:k(u(),_()).nullish(),sessionId:G,update:Sw});p({method:u(),params:W([Hu,$_,bu]).nullish()});const Bu=p({_meta:k(u(),_()).nullish(),sessionId:G,terminalId:u()}),xw=p({_meta:k(u(),_()).nullish(),exitCode:N().int().gte(0).max(4294967295,{message:"Invalid value: Expected uint32 to be <= 4294967295"}).nullish(),signal:u().nullish()}),Ew=p({name:u(),uri:u()}),Aw=p({_meta:k(u(),_()).nullish(),repository:gy.nullish(),workspaceFolders:R(Ew).nullish(),workspaceUri:u().nullish()});p({id:nn,method:u(),params:W([Ly,__,B_,by,mk,Z_,gk,_k,uk,Pk,$k,ow,Lk,Aw,Uk,lk,Su]).nullish()});const Gu=p({_meta:k(u(),_()).nullish(),content:u(),path:u(),sessionId:G});p({id:nn,method:u(),params:W([Gu,Du,ju,Ru,Mu,Lu,Bu,Pu,yw,Su]).nullish()});const Tw=p({_meta:k(u(),_()).nullish()});W([p({id:nn,result:W([Tw,Zy,Yy,E_,Bk,jy,xw,U_,R_,xu])}),p({error:wu,id:nn})]);var H;class Iw{constructor(t,n){I(this,H);const s=t(this),r=async(o,a)=>{var c,l,h,f,w,v,E;switch(o){case ct.fs_write_text_file:{const S=Gu.parse(a);return(c=s.writeTextFile)==null?void 0:c.call(s,S)}case ct.fs_read_text_file:{const S=Du.parse(a);return(l=s.readTextFile)==null?void 0:l.call(s,S)}case ct.session_request_permission:{const S=ju.parse(a);return s.requestPermission(S)}case ct.terminal_create:{const S=Ru.parse(a);return(h=s.createTerminal)==null?void 0:h.call(s,S)}case ct.terminal_output:{const S=Mu.parse(a);return(f=s.terminalOutput)==null?void 0:f.call(s,S)}case ct.terminal_release:{const S=Lu.parse(a);return await((w=s.releaseTerminal)==null?void 0:w.call(s,S))??{}}case ct.terminal_wait_for_exit:{const S=Bu.parse(a);return(v=s.waitForTerminalExit)==null?void 0:v.call(s,S)}case ct.terminal_kill:{const S=Pu.parse(a);return await((E=s.killTerminal)==null?void 0:E.call(s,S))??{}}default:if(s.extMethod)return s.extMethod(o,a);throw ge.methodNotFound(o)}},i=async(o,a)=>{switch(o){case ct.session_update:{const c=Hu.parse(a);return s.sessionUpdate(c)}default:if(s.extNotification)return s.extNotification(o,a);throw ge.methodNotFound(o)}};C(this,H,new Cw(r,i,n))}async initialize(t){return await d(this,H).sendRequest(te.initialize,t)}async newSession(t){return await d(this,H).sendRequest(te.session_new,t)}async loadSession(t){return await d(this,H).sendRequest(te.session_load,t)??{}}async unstable_forkSession(t){return await d(this,H).sendRequest(te.session_fork,t)}async listSessions(t){return await d(this,H).sendRequest(te.session_list,t)}async unstable_resumeSession(t){return await d(this,H).sendRequest(te.session_resume,t)}async unstable_closeSession(t){return await d(this,H).sendRequest(te.session_close,t)}async setSessionMode(t){return await d(this,H).sendRequest(te.session_set_mode,t)??{}}async unstable_setSessionModel(t){return await d(this,H).sendRequest(te.session_set_model,t)??{}}async setSessionConfigOption(t){return await d(this,H).sendRequest(te.session_set_config_option,t)}async authenticate(t){return await d(this,H).sendRequest(te.authenticate,t)??{}}async unstable_logout(t){return await d(this,H).sendRequest(te.logout,t)??{}}async prompt(t){return await d(this,H).sendRequest(te.session_prompt,t)}async cancel(t){return await d(this,H).sendNotification(te.session_cancel,t)}async unstable_startNes(t){return await d(this,H).sendRequest(te.nes_start,t)}async unstable_suggestNes(t){return await d(this,H).sendRequest(te.nes_suggest,t)}async unstable_closeNes(t){return await d(this,H).sendRequest(te.nes_close,t)??{}}async unstable_didOpenDocument(t){return await d(this,H).sendNotification(te.document_did_open,t)}async unstable_didChangeDocument(t){return await d(this,H).sendNotification(te.document_did_change,t)}async unstable_didCloseDocument(t){return await d(this,H).sendNotification(te.document_did_close,t)}async unstable_didSaveDocument(t){return await d(this,H).sendNotification(te.document_did_save,t)}async unstable_didFocusDocument(t){return await d(this,H).sendNotification(te.document_did_focus,t)}async unstable_acceptNes(t){return await d(this,H).sendNotification(te.nes_accept,t)}async unstable_rejectNes(t){return await d(this,H).sendNotification(te.nes_reject,t)}async extMethod(t,n){return await d(this,H).sendRequest(t,n)}async extNotification(t,n){return await d(this,H).sendNotification(t,n)}get signal(){return d(this,H).signal}get closed(){return d(this,H).closed}}H=new WeakMap;var bt,Gr,Cs,zs,zn,$n,tt,$s,re,Vu,ho,qu,Ku,Yu,Xu,po,ds;class Cw{constructor(t,n,s){I(this,re);I(this,bt,new Map);I(this,Gr,0);I(this,Cs);I(this,zs);I(this,zn);I(this,$n,Promise.resolve());I(this,tt,new AbortController);I(this,$s);C(this,Cs,t),C(this,zs,n),C(this,zn,s),C(this,$s,new Promise(r=>{d(this,tt).signal.addEventListener("abort",()=>r())})),y(this,re,Vu).call(this)}get signal(){return d(this,tt).signal}get closed(){return d(this,$s)}async sendRequest(t,n){y(this,re,po).call(this);const s=Ya(this,Gr)._++,r=new Promise((i,o)=>{d(this,bt).set(s,{resolve:i,reject:o})});return await y(this,re,ds).call(this,{jsonrpc:"2.0",id:s,method:t,params:n}),r}async sendNotification(t,n){y(this,re,po).call(this),await y(this,re,ds).call(this,{jsonrpc:"2.0",method:t,params:n})}}bt=new WeakMap,Gr=new WeakMap,Cs=new WeakMap,zs=new WeakMap,zn=new WeakMap,$n=new WeakMap,tt=new WeakMap,$s=new WeakMap,re=new WeakSet,Vu=async function(){let t;try{const n=d(this,zn).readable.getReader();try{for(;!d(this,tt).signal.aborted;){const{value:s,done:r}=await n.read();if(r)break;if(s)try{y(this,re,qu).call(this,s)}catch(i){console.error("Unexpected error during message processing:",s,i),"id"in s&&s.id!==void 0&&y(this,re,ds).call(this,{jsonrpc:"2.0",id:s.id,error:{code:-32700,message:"Parse error"}})}}}finally{n.releaseLock()}}catch(n){t=n}finally{y(this,re,ho).call(this,t)}},ho=function(t){if(d(this,tt).signal.aborted)return;const n=t??new Error("ACP connection closed");for(const s of d(this,bt).values())s.reject(n);d(this,bt).clear(),d(this,tt).abort(n)},qu=async function(t){if("method"in t&&"id"in t){const n=await y(this,re,Ku).call(this,t.method,t.params);"error"in n&&console.error("Error handling request",t,n.error),await y(this,re,ds).call(this,{jsonrpc:"2.0",id:t.id,...n})}else if("method"in t){const n=await y(this,re,Yu).call(this,t.method,t.params);"error"in n&&console.error("Error handling notification",t,n.error)}else"id"in t?y(this,re,Xu).call(this,t):console.error("Invalid message",{message:t})},Ku=async function(t,n){try{return{result:await d(this,Cs).call(this,t,n)??null}}catch(s){if(s instanceof ge)return s.toResult();if(s instanceof Ec)return ge.invalidParams(s.format()).toResult();let r;(s instanceof Error||typeof s=="object"&&s!=null&&"message"in s&&typeof s.message=="string")&&(r=s.message);try{return ge.internalError(r?JSON.parse(r):{}).toResult()}catch{return ge.internalError({details:r}).toResult()}}},Yu=async function(t,n){try{return await d(this,zs).call(this,t,n),{result:null}}catch(s){if(s instanceof ge)return s.toResult();if(s instanceof Ec)return ge.invalidParams(s.format()).toResult();let r;(s instanceof Error||typeof s=="object"&&s!=null&&"message"in s&&typeof s.message=="string")&&(r=s.message);try{return ge.internalError(r?JSON.parse(r):{}).toResult()}catch{return ge.internalError({details:r}).toResult()}}},Xu=function(t){const n=d(this,bt).get(t.id);if(n){if("result"in t)n.resolve(t.result);else if("error"in t){const{code:s,message:r,data:i}=t.error;n.reject(new ge(s,r,i))}d(this,bt).delete(t.id)}else console.error("Got response to unknown request",t.id)},po=function(){if(d(this,tt).signal.aborted)throw d(this,tt).signal.reason??new Error("ACP connection closed")},ds=async function(t){return C(this,$n,d(this,$n).then(async()=>{const n=d(this,zn).writable.getWriter();try{await n.write(t)}finally{n.releaseLock()}}).catch(n=>{y(this,re,ho).call(this,n)})),d(this,$n)};class ge extends Error{constructor(n,s,r){super(s);m(this,"code");m(this,"data");this.code=n,this.name="RequestError",this.data=r}static parseError(n,s){return new ge(-32700,`Parse error${s?`: ${s}`:""}`,n)}static invalidRequest(n,s){return new ge(-32600,`Invalid request${s?`: ${s}`:""}`,n)}static methodNotFound(n){return new ge(-32601,`"Method not found": ${n}`,{method:n})}static invalidParams(n,s){return new ge(-32602,`Invalid params${s?`: ${s}`:""}`,n)}static internalError(n,s){return new ge(-32603,`Internal error${s?`: ${s}`:""}`,n)}static authRequired(n,s){return new ge(-32e3,`Authentication required${s?`: ${s}`:""}`,n)}static resourceNotFound(n){return new ge(-32002,`Resource not found${n?`: ${n}`:""}`,n&&{uri:n})}toResult(){return{error:{code:this.code,message:this.message,data:this.data}}}toErrorResponse(){return{code:this.code,message:this.message,data:this.data}}}const zw=/^Sender \(untrusted metadata\):\n```json\n[\s\S]*?\n```\n\n?/,$w=/^\[[^\n]*Working directory:[^\n]*\]\n\n?/,Rw=/\[\[\s*(?:reply_to_current|reply_to\s*:\s*[^\]\n]+|audio_as_voice)\s*\]\]\s*/gi,Pw="single_session",Dw={name:"television-acp-client",version:"0.0.0"},Ju="agent:main:television";var Q,ut,Rn,ht,Vt,qt,St,Pn,nt,Be,xt,Kt,dt,Et,Rs,pt,Ge,Vr,ft,Yt,T,Qu,eh,fo,th,nh,sh,rh,ih,oh,ah,Ft,yn,kn,Me,ch,wn,go,mo,Sr,lh,Ps,Ds,vo,bn,uh,hh;class Lw extends cn{constructor(n){super();I(this,T);I(this,Q,Mw());I(this,ut,null);I(this,Rn,null);I(this,ht,null);I(this,Vt,null);I(this,qt,null);I(this,St,null);I(this,Pn,1);I(this,nt,null);I(this,Be,null);I(this,xt,!1);I(this,Kt,!1);I(this,dt,null);I(this,Et,new Set);I(this,Rs);I(this,pt);I(this,Ge);I(this,Vr,n=>{y(this,T,eh).call(this,n)});I(this,ft,null);I(this,Yt,!1);I(this,Ps,()=>{y(this,T,bn).call(this,"ACP bridge websocket closed")});I(this,Ds,()=>{y(this,T,bn).call(this,"ACP bridge websocket error")});C(this,pt,n),C(this,Ge,n.sessionMode??Pw),C(this,Rs,n.createSocket??(s=>new WebSocket(s)))}getState(){return d(this,Q)}async connect(){if(d(this,Yt))throw new Error("ACPClientService has been disposed");if(d(this,Q).lifecycle.status!=="ready"){y(this,T,Me).call(this,{lifecycle:{status:"connecting"}}),d(this,Rn)??C(this,Rn,y(this,T,Qu).call(this));try{await d(this,Rn),await y(this,T,fo).call(this)}catch(n){throw y(this,T,bn).call(this,gr(n)),n}}}async dispose(){d(this,Yt)||(C(this,Yt,!0),y(this,T,vo).call(this),y(this,T,Me).call(this,{lifecycle:{status:"disposed"},run:{status:"idle",stopReason:null,canCancel:!1,error:null}}))}async sendMessage(n){if(await this.connect(),d(this,Q).lifecycle.status!=="ready"||d(this,Q).run.status==="running"||d(this,Q).run.status==="cancelling")throw new Error("ACPClientService is not ready to send a new message");const s=n.text.trim();if(!s)throw new Error("Cannot send an empty message");y(this,T,yn).call(this,{id:y(this,T,wn).call(this,"user"),kind:"user",text:s,status:"final"}),y(this,T,Me).call(this,{run:{status:"running",stopReason:null,canCancel:!0,error:null}});try{const r=await y(this,T,Sr).call(this).prompt({sessionId:y(this,T,mo).call(this),prompt:[{type:"text",text:y(this,T,ch).call(this,s)}]});y(this,T,Ft).call(this,r.stopReason==="cancelled"?"cancelled":"final"),y(this,T,Me).call(this,{run:{status:r.stopReason==="cancelled"?"cancelled":"completed",stopReason:r.stopReason,canCancel:!1,error:null}})}catch(r){throw y(this,T,hh).call(this)||(y(this,T,Ft).call(this,"error"),y(this,T,Me).call(this,{run:{status:"error",stopReason:null,canCancel:!1,error:gr(r)}})),r}}async cancel(){if(await this.connect(),!d(this,Q).run.canCancel||d(this,Q).run.status!=="running")throw new Error("No active cancellable run");y(this,T,Me).call(this,{run:{...d(this,Q).run,status:"cancelling"}}),await y(this,T,Sr).call(this).cancel({sessionId:y(this,T,mo).call(this)})}setWorkspaceContext(n){var i,o,a;const s={workspaceID:n.workspaceID,workspaceName:n.workspaceName};if(((i=d(this,Be))==null?void 0:i.workspaceID)===s.workspaceID&&((o=d(this,Be))==null?void 0:o.workspaceName)===s.workspaceName)return;const r=((a=d(this,Be))==null?void 0:a.workspaceID)??null;if(C(this,Be,s),d(this,Ge)==="single_session"){(!d(this,St)||r!==s.workspaceID)&&C(this,xt,!0);return}d(this,St)!==$c(d(this,Ge),s.workspaceID,d(this,pt).clientGUID??"default-client")&&(C(this,ht,null),C(this,Vt,null),d(this,ut)&&d(this,Q).run.status==="idle"&&y(this,T,fo).call(this).catch(c=>{y(this,T,bn).call(this,gr(c))}))}}Q=new WeakMap,ut=new WeakMap,Rn=new WeakMap,ht=new WeakMap,Vt=new WeakMap,qt=new WeakMap,St=new WeakMap,Pn=new WeakMap,nt=new WeakMap,Be=new WeakMap,xt=new WeakMap,Kt=new WeakMap,dt=new WeakMap,Et=new WeakMap,Rs=new WeakMap,pt=new WeakMap,Ge=new WeakMap,Vr=new WeakMap,ft=new WeakMap,Yt=new WeakMap,T=new WeakSet,Qu=async function(){try{y(this,T,Me).call(this,{lifecycle:{status:"connecting"}});const{stream:n,socket:s}=await Fw({serverURL:d(this,pt).serverURL,token:d(this,pt).token,createSocket:d(this,Rs),onDisconnect:d(this,Vr)});C(this,ft,s),s.addEventListener("close",d(this,Ps)),s.addEventListener("error",d(this,Ds)),C(this,ut,new Iw(r=>({connection:r,sessionUpdate:async i=>{await y(this,T,nh).call(this,i)},requestPermission:async i=>y(this,T,sh).call(this,i)}),n)),await d(this,ut).initialize({protocolVersion:h_,clientCapabilities:{},clientInfo:Dw})}catch(n){throw n}},eh=function(n){y(this,T,bn).call(this,gr(n))},fo=async function(){const n=y(this,T,lh).call(this);if(d(this,ht)&&d(this,Vt)===n){await d(this,ht);return}C(this,Vt,n),C(this,ht,y(this,T,th).call(this,n)),await d(this,ht)},th=async function(n){const s=y(this,T,Sr).call(this);y(this,T,uh).call(this);let r,i=!1;try{C(this,Kt,!0),C(this,dt,null),await s.loadSession({sessionId:n,cwd:"/",mcpServers:[],_meta:{sessionKey:n}}),r=n,i=d(this,Q).messageOrder.length>0}catch{r=(await s.newSession({cwd:"/",mcpServers:[],_meta:{sessionKey:n}})).sessionId,i=!1}finally{C(this,Kt,!1),C(this,dt,null),y(this,T,Ft).call(this,"final")}await s.setSessionConfigOption({sessionId:r,configId:"verbose_level",value:"full"}),C(this,qt,r),C(this,St,n),i?(d(this,Et).add(n),d(this,Ge)==="single_session"&&C(this,xt,!1)):(d(this,Et).delete(n),C(this,xt,d(this,Ge)==="single_session")),y(this,T,Me).call(this,{lifecycle:{status:"ready"}})},nh=async function(n){const s=n.update;switch(s.sessionUpdate){case"user_message_chunk":s.content.type==="text"&&y(this,T,ah).call(this,s.content.text);return;case"agent_message_chunk":s.content.type==="text"&&y(this,T,rh).call(this,s.content.text);return;case"tool_call":y(this,T,ih).call(this,s);return;case"tool_call_update":y(this,T,oh).call(this,s);return;case"agent_thought_chunk":return;default:return}},sh=async function(n){return{outcome:{outcome:"cancelled"}}},rh=function(n){C(this,dt,null);const s=Nw(n);if(!s)return;if(!d(this,nt)){const i={id:y(this,T,wn).call(this,"assistant"),kind:"assistant",text:s,status:"streaming"};C(this,nt,i.id),y(this,T,yn).call(this,i);return}const r=d(this,Q).messagesById[d(this,nt)];if(!r||r.kind!=="assistant")throw new Error("Open assistant message invariant violated");y(this,T,kn).call(this,{...r,text:`${r.text}${s}`,status:"streaming"})},ih=function(n){y(this,T,Ft).call(this,"final");const s=y(this,T,go).call(this,n.toolCallId),r={id:(s==null?void 0:s.id)??y(this,T,wn).call(this,"tool"),kind:"tool_call",toolCallId:n.toolCallId,title:n.title,toolKind:n.kind??"other",status:n.status==="failed"?"failed":n.status==="completed"?"completed":"in_progress",text:(s==null?void 0:s.text)??"",locations:n.locations??(s==null?void 0:s.locations)};if(s){y(this,T,kn).call(this,r);return}y(this,T,yn).call(this,r)},oh=function(n){const s=y(this,T,go).call(this,n.toolCallId),r=(s==null?void 0:s.text)??"",i=Ww(n.content),o=i?`${r}${i}`:r,a={id:(s==null?void 0:s.id)??y(this,T,wn).call(this,"tool"),kind:"tool_call",toolCallId:n.toolCallId,title:(s==null?void 0:s.title)??n.toolCallId,toolKind:(s==null?void 0:s.toolKind)??"other",status:n.status==="failed"?"failed":n.status==="completed"?"completed":"in_progress",text:o,locations:n.locations??(s==null?void 0:s.locations)};if(s){y(this,T,kn).call(this,a);return}y(this,T,yn).call(this,a)},ah=function(n){y(this,T,Ft).call(this,"final");const s=Ow(n);if(!s)return;const r=d(this,Kt)?d(this,dt):null;if(!r){const o={id:y(this,T,wn).call(this,"user"),kind:"user",text:s,status:"final"};y(this,T,yn).call(this,o),d(this,Kt)&&C(this,dt,o.id);return}const i=d(this,Q).messagesById[r];if(!i||i.kind!=="user")throw new Error("Replay user message invariant violated");y(this,T,kn).call(this,{...i,text:`${i.text}${s}`})},Ft=function(n){if(!d(this,nt))return;const s=d(this,Q).messagesById[d(this,nt)];(s==null?void 0:s.kind)==="assistant"&&y(this,T,kn).call(this,{...s,status:n}),C(this,nt,null)},yn=function(n){y(this,T,Me).call(this,{messagesById:{...d(this,Q).messagesById,[n.id]:n},messageOrder:[...d(this,Q).messageOrder,n.id]})},kn=function(n){y(this,T,Me).call(this,{messagesById:{...d(this,Q).messagesById,[n.id]:n}})},Me=function(n){const s={...d(this,Q),...n};C(this,Q,{...s,sendDisabled:s.lifecycle.status!=="ready"||s.run.status==="running"||s.run.status==="cancelling",cancelDisabled:!(s.run.status==="running"||s.run.status==="cancelling")||!s.run.canCancel}),this.dispatchEvent(new B("change"))},ch=function(n){const s=d(this,St);return!d(this,Be)||!s||!(d(this,Ge)==="single_session"?d(this,xt)||!d(this,Et).has(s):!d(this,Et).has(s))?n:(C(this,xt,!1),d(this,Et).add(s),["[Television workspace context]","This chat session is coming from a Television client in the workspace below.",`workspace_id: ${d(this,Be).workspaceID}`,`workspace_name: ${d(this,Be).workspaceName??""}`,"When the user asks to inspect or change Television state with the tv CLI, use this workspace ID with the --workspace argument.","[/Television workspace context]","",n].join(`
40
- `))},wn=function(n){const s=`${n}-${d(this,Pn)}`;return C(this,Pn,d(this,Pn)+1),s},go=function(n){for(const s of d(this,Q).messageOrder){const r=d(this,Q).messagesById[s];if((r==null?void 0:r.kind)==="tool_call"&&r.toolCallId===n)return r}return null},mo=function(){if(!d(this,qt))throw new Error("ACP session is not ready");return d(this,qt)},Sr=function(){if(!d(this,ut))throw new Error("ACP connection is not ready");return d(this,ut)},lh=function(){var s;if(d(this,Ge)==="single_session")return`${Ju}-${(d(this,pt).clientGUID??"default-client").toLowerCase()}`;const n=(s=d(this,Be))==null?void 0:s.workspaceID;if(!n)throw new Error("Workspace context is required for per-workspace session mode");return $c(d(this,Ge),n,d(this,pt).clientGUID??"default-client")},Ps=new WeakMap,Ds=new WeakMap,vo=function(){C(this,ut,null),C(this,Rn,null),C(this,ht,null),C(this,Vt,null),C(this,qt,null),C(this,St,null),d(this,ft)&&(d(this,ft).removeEventListener("close",d(this,Ps)),d(this,ft).removeEventListener("error",d(this,Ds)),d(this,ft).close(),C(this,ft,null))},bn=function(n){d(this,Yt)||d(this,Q).lifecycle.status==="disconnected"||(y(this,T,Ft).call(this,"error"),y(this,T,vo).call(this),y(this,T,Me).call(this,{lifecycle:{status:"disconnected",...n?{error:n}:{}},run:{status:"idle",stopReason:null,canCancel:!1,error:null}}))},uh=function(){C(this,nt,null),C(this,dt,null),C(this,Pn,1),y(this,T,Me).call(this,{run:{status:"idle",stopReason:null,canCancel:!1,error:null},messagesById:{},messageOrder:[]})},hh=function(){return d(this,Q).lifecycle.status==="disconnected"};function Mw(){return{lifecycle:{status:"connecting"},run:{status:"idle",stopReason:null,canCancel:!1,error:null},messagesById:{},messageOrder:[],sendDisabled:!0,cancelDisabled:!0}}function $c(e,t,n){return e==="single_session"?`${Ju}-${n.toLowerCase()}`:`agent:main:television-${n.toLowerCase()}-${t.toLowerCase()}`}function dh(e){return e.replace(/^(?:\s*\n)+/,"")}function Ow(e){let t=e;return t=t.replace(zw,""),t=t.replace($w,""),t=dh(t),t}function Nw(e){let t=e;return t=t.replace(Rw,""),t=dh(t),t}function Ww(e){return!e||e.length===0?"":e.flatMap(t=>t.type==="content"&&t.content.type==="text"?[t.content.text]:[]).join("")}async function Fw(e){const t=e.createSocket(Zw(e.serverURL,e.token));let n=!1,s,r;const i=new Promise((c,l)=>{s=c,r=l}),o=new ReadableStream({start(c){let l=!1;const h=()=>{t.send(JSON.stringify({type:"acp-bridge-connect"}))},f=E=>{const S=Uw(E);if(!S)return;let z;try{z=JSON.parse(S)}catch(q){const Z=q instanceof Error?q:new Error(String(q));r(Z),c.error(Z);return}switch(z.type){case"acp-bridge-status":if(z.status==="ready"){n||(n=!0,s());return}if(z.status==="error"||z.status==="exited"){const q=new Error(z.error??`ACP bridge ${z.status}`);n||r(q),c.error(q)}return;case"acp-bridge-message":c.enqueue(z.message);return}},w=()=>{var S;if(l)return;l=!0;const E=new Error("ACP bridge websocket closed");n||r(E),(S=e.onDisconnect)==null||S.call(e,E),c.close()},v=()=>{var S;if(l)return;l=!0;const E=new Error("ACP bridge websocket error");n||r(E),(S=e.onDisconnect)==null||S.call(e,E),c.error(E)};t.addEventListener("open",h),t.addEventListener("message",f),t.addEventListener("close",w),t.addEventListener("error",v)}}),a=new WritableStream({async write(c){await i,t.send(JSON.stringify({type:"acp-bridge-message",message:c}))},close(){t.close()},abort(){t.close()}});return await i,{stream:{readable:o,writable:a},socket:t}}function Uw(e){if(typeof e=="string")return e;if(e instanceof Uint8Array)return new TextDecoder().decode(e);if(typeof Buffer<"u"&&e instanceof Buffer)return e.toString("utf8");if(typeof e=="object"&&e!==null&&"data"in e){const t=e.data;if(typeof t=="string")return t;if(t instanceof Uint8Array)return new TextDecoder().decode(t);if(Array.isArray(t))return Buffer.concat(t).toString("utf8")}return null}function Zw(e,t){const n=new URL(e);return n.protocol=n.protocol==="https:"?"wss:":"ws:",n.pathname="/ws",n.search="",n.searchParams.set("token",t),n.hash="",n.toString()}function gr(e){return e instanceof Error?e.message:String(e)}const Rc="television.acpClientGUID";class jw extends cn{constructor(n){super();m(this,"workspaceService");m(this,"services",new Map);m(this,"options");m(this,"sessionMode");m(this,"clientGUID");m(this,"activeService",null);m(this,"handleWorkspaceChange",()=>{this.syncActiveService()});this.workspaceService=n.workspaceService,this.sessionMode=n.sessionMode??"single_session",this.options={serverURL:n.serverURL,token:n.token,...n.createSocket?{createSocket:n.createSocket}:{},...n.sessionMode?{sessionMode:n.sessionMode}:{}},this.clientGUID=n.clientGUID??Hw(n.storage??window.localStorage),this.workspaceService.addEventListener("change",this.handleWorkspaceChange),this.syncActiveService()}getActiveService(){return this.activeService}dispose(){this.workspaceService.removeEventListener("change",this.handleWorkspaceChange);for(const n of this.services.values())n.dispose();this.services.clear(),this.activeService=null}syncActiveService(){const n=this.workspaceService.activeWorkspace,s=n?this.getServiceForWorkspace(n):null;this.activeService!==s&&(this.activeService=s,this.dispatchEvent(new B("change")))}getServiceForWorkspace(n){const s=this.sessionMode==="single_session"?"single_session":n.id;let r=this.services.get(s);return r||(r=new Lw({...this.options,sessionMode:this.sessionMode,clientGUID:this.clientGUID}),this.services.set(s,r)),r.setWorkspaceContext({workspaceID:n.id,workspaceName:n.name}),r}}function Hw(e){const t=e.getItem(Rc);if(t)return t;const n=Wn().toLowerCase();return e.setItem(Rc,n),n}const Bw="serverURL",Gw="token",Vw="mode",qw="electron";function ph(e=window.location.search,t=window.location.origin){const s=new URLSearchParams(e).get(Bw);return s?new URL(s).origin:new URL(t).origin}function fh(e=window.location.search){return new URLSearchParams(e).get(Gw)}function gh(e=window.location.search){return new URLSearchParams(e).get(Vw)===qw}/**
41
- * @license
42
- * Copyright 2017 Google LLC
43
- * SPDX-License-Identifier: BSD-3-Clause
44
- */const _s=globalThis,Pc=e=>e,Fr=_s.trustedTypes,Dc=Fr?Fr.createPolicy("lit-html",{createHTML:e=>e}):void 0,mh="$lit$",wt=`lit$${Math.random().toFixed(9).slice(2)}$`,vh="?"+wt,Kw=`<${vh}>`,sn=document,Ss=()=>sn.createComment(""),xs=e=>e===null||typeof e!="object"&&typeof e!="function",na=Array.isArray,Yw=e=>na(e)||typeof(e==null?void 0:e[Symbol.iterator])=="function",Oi=`[
45
- \f\r]`,ts=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Lc=/-->/g,Mc=/>/g,Ot=RegExp(`>|${Oi}(?:([^\\s"'>=/]+)(${Oi}*=${Oi}*(?:[^
46
- \f\r"'\`<>=]|("|')|))|$)`,"g"),Oc=/'/g,Nc=/"/g,_h=/^(?:script|style|textarea|title)$/i,Xw=e=>(t,...n)=>({_$litType$:e,strings:t,values:n}),O=Xw(1),jn=Symbol.for("lit-noChange"),de=Symbol.for("lit-nothing"),Wc=new WeakMap,Gt=sn.createTreeWalker(sn,129);function yh(e,t){if(!na(e)||!e.hasOwnProperty("raw"))throw Error("invalid template strings array");return Dc!==void 0?Dc.createHTML(t):t}const Jw=(e,t)=>{const n=e.length-1,s=[];let r,i=t===2?"<svg>":t===3?"<math>":"",o=ts;for(let a=0;a<n;a++){const c=e[a];let l,h,f=-1,w=0;for(;w<c.length&&(o.lastIndex=w,h=o.exec(c),h!==null);)w=o.lastIndex,o===ts?h[1]==="!--"?o=Lc:h[1]!==void 0?o=Mc:h[2]!==void 0?(_h.test(h[2])&&(r=RegExp("</"+h[2],"g")),o=Ot):h[3]!==void 0&&(o=Ot):o===Ot?h[0]===">"?(o=r??ts,f=-1):h[1]===void 0?f=-2:(f=o.lastIndex-h[2].length,l=h[1],o=h[3]===void 0?Ot:h[3]==='"'?Nc:Oc):o===Nc||o===Oc?o=Ot:o===Lc||o===Mc?o=ts:(o=Ot,r=void 0);const v=o===Ot&&e[a+1].startsWith("/>")?" ":"";i+=o===ts?c+Kw:f>=0?(s.push(l),c.slice(0,f)+mh+c.slice(f)+wt+v):c+wt+(f===-2?a:v)}return[yh(e,i+(e[n]||"<?>")+(t===2?"</svg>":t===3?"</math>":"")),s]};class Es{constructor({strings:t,_$litType$:n},s){let r;this.parts=[];let i=0,o=0;const a=t.length-1,c=this.parts,[l,h]=Jw(t,n);if(this.el=Es.createElement(l,s),Gt.currentNode=this.el.content,n===2||n===3){const f=this.el.content.firstChild;f.replaceWith(...f.childNodes)}for(;(r=Gt.nextNode())!==null&&c.length<a;){if(r.nodeType===1){if(r.hasAttributes())for(const f of r.getAttributeNames())if(f.endsWith(mh)){const w=h[o++],v=r.getAttribute(f).split(wt),E=/([.?@])?(.*)/.exec(w);c.push({type:1,index:i,name:E[2],strings:v,ctor:E[1]==="."?eb:E[1]==="?"?tb:E[1]==="@"?nb:hi}),r.removeAttribute(f)}else f.startsWith(wt)&&(c.push({type:6,index:i}),r.removeAttribute(f));if(_h.test(r.tagName)){const f=r.textContent.split(wt),w=f.length-1;if(w>0){r.textContent=Fr?Fr.emptyScript:"";for(let v=0;v<w;v++)r.append(f[v],Ss()),Gt.nextNode(),c.push({type:2,index:++i});r.append(f[w],Ss())}}}else if(r.nodeType===8)if(r.data===vh)c.push({type:2,index:i});else{let f=-1;for(;(f=r.data.indexOf(wt,f+1))!==-1;)c.push({type:7,index:i}),f+=wt.length-1}i++}}static createElement(t,n){const s=sn.createElement("template");return s.innerHTML=t,s}}function Hn(e,t,n=e,s){var o,a;if(t===jn)return t;let r=s!==void 0?(o=n._$Co)==null?void 0:o[s]:n._$Cl;const i=xs(t)?void 0:t._$litDirective$;return(r==null?void 0:r.constructor)!==i&&((a=r==null?void 0:r._$AO)==null||a.call(r,!1),i===void 0?r=void 0:(r=new i(e),r._$AT(e,n,s)),s!==void 0?(n._$Co??(n._$Co=[]))[s]=r:n._$Cl=r),r!==void 0&&(t=Hn(e,r._$AS(e,t.values),r,s)),t}class Qw{constructor(t,n){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=n}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:n},parts:s}=this._$AD,r=((t==null?void 0:t.creationScope)??sn).importNode(n,!0);Gt.currentNode=r;let i=Gt.nextNode(),o=0,a=0,c=s[0];for(;c!==void 0;){if(o===c.index){let l;c.type===2?l=new sa(i,i.nextSibling,this,t):c.type===1?l=new c.ctor(i,c.name,c.strings,this,t):c.type===6&&(l=new sb(i,this,t)),this._$AV.push(l),c=s[++a]}o!==(c==null?void 0:c.index)&&(i=Gt.nextNode(),o++)}return Gt.currentNode=sn,r}p(t){let n=0;for(const s of this._$AV)s!==void 0&&(s.strings!==void 0?(s._$AI(t,s,n),n+=s.strings.length-2):s._$AI(t[n])),n++}}let sa=class kh{get _$AU(){var t;return((t=this._$AM)==null?void 0:t._$AU)??this._$Cv}constructor(t,n,s,r){this.type=2,this._$AH=de,this._$AN=void 0,this._$AA=t,this._$AB=n,this._$AM=s,this.options=r,this._$Cv=(r==null?void 0:r.isConnected)??!0}get parentNode(){let t=this._$AA.parentNode;const n=this._$AM;return n!==void 0&&(t==null?void 0:t.nodeType)===11&&(t=n.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,n=this){t=Hn(this,t,n),xs(t)?t===de||t==null||t===""?(this._$AH!==de&&this._$AR(),this._$AH=de):t!==this._$AH&&t!==jn&&this._(t):t._$litType$!==void 0?this.$(t):t.nodeType!==void 0?this.T(t):Yw(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==de&&xs(this._$AH)?this._$AA.nextSibling.data=t:this.T(sn.createTextNode(t)),this._$AH=t}$(t){var i;const{values:n,_$litType$:s}=t,r=typeof s=="number"?this._$AC(t):(s.el===void 0&&(s.el=Es.createElement(yh(s.h,s.h[0]),this.options)),s);if(((i=this._$AH)==null?void 0:i._$AD)===r)this._$AH.p(n);else{const o=new Qw(r,this),a=o.u(this.options);o.p(n),this.T(a),this._$AH=o}}_$AC(t){let n=Wc.get(t.strings);return n===void 0&&Wc.set(t.strings,n=new Es(t)),n}k(t){na(this._$AH)||(this._$AH=[],this._$AR());const n=this._$AH;let s,r=0;for(const i of t)r===n.length?n.push(s=new kh(this.O(Ss()),this.O(Ss()),this,this.options)):s=n[r],s._$AI(i),r++;r<n.length&&(this._$AR(s&&s._$AB.nextSibling,r),n.length=r)}_$AR(t=this._$AA.nextSibling,n){var s;for((s=this._$AP)==null?void 0:s.call(this,!1,!0,n);t!==this._$AB;){const r=Pc(t).nextSibling;Pc(t).remove(),t=r}}setConnected(t){var n;this._$AM===void 0&&(this._$Cv=t,(n=this._$AP)==null||n.call(this,t))}},hi=class{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,n,s,r,i){this.type=1,this._$AH=de,this._$AN=void 0,this.element=t,this.name=n,this._$AM=r,this.options=i,s.length>2||s[0]!==""||s[1]!==""?(this._$AH=Array(s.length-1).fill(new String),this.strings=s):this._$AH=de}_$AI(t,n=this,s,r){const i=this.strings;let o=!1;if(i===void 0)t=Hn(this,t,n,0),o=!xs(t)||t!==this._$AH&&t!==jn,o&&(this._$AH=t);else{const a=t;let c,l;for(t=i[0],c=0;c<i.length-1;c++)l=Hn(this,a[s+c],n,c),l===jn&&(l=this._$AH[c]),o||(o=!xs(l)||l!==this._$AH[c]),l===de?t=de:t!==de&&(t+=(l??"")+i[c+1]),this._$AH[c]=l}o&&!r&&this.j(t)}j(t){t===de?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}},eb=class extends hi{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===de?void 0:t}},tb=class extends hi{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==de)}},nb=class extends hi{constructor(t,n,s,r,i){super(t,n,s,r,i),this.type=5}_$AI(t,n=this){if((t=Hn(this,t,n,0)??de)===jn)return;const s=this._$AH,r=t===de&&s!==de||t.capture!==s.capture||t.once!==s.once||t.passive!==s.passive,i=t!==de&&(s===de||r);r&&this.element.removeEventListener(this.name,this,s),i&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){var n;typeof this._$AH=="function"?this._$AH.call(((n=this.options)==null?void 0:n.host)??this.element,t):this._$AH.handleEvent(t)}};class sb{constructor(t,n,s){this.element=t,this.type=6,this._$AN=void 0,this._$AM=n,this.options=s}get _$AU(){return this._$AM._$AU}_$AI(t){Hn(this,t)}}const Ni=_s.litHtmlPolyfillSupport;Ni==null||Ni(Es,sa),(_s.litHtmlVersions??(_s.litHtmlVersions=[])).push("3.3.2");const ue=(e,t,n)=>{const s=t;let r=s._$litPart$;return r===void 0&&(s._$litPart$=r=new sa(t.insertBefore(Ss(),null),null,void 0,{})),r._$AI(e),r};/**
47
- * @license
48
- * Copyright 2017 Google LLC
49
- * SPDX-License-Identifier: BSD-3-Clause
50
- */const rb={CHILD:2},wh=e=>(...t)=>({_$litDirective$:e,values:t});class ib{constructor(t){}get _$AU(){return this._$AM._$AU}_$AT(t,n,s){this._$Ct=t,this._$AM=n,this._$Ci=s}_$AS(t,n){return this.update(t,n)}update(t,n){return this.render(...n)}}/**
51
- * @license
52
- * Copyright 2017 Google LLC
53
- * SPDX-License-Identifier: BSD-3-Clause
54
- */class Ur extends ib{constructor(t){if(super(t),this.it=de,t.type!==rb.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(t){if(t===de||t==null)return this._t=void 0,this.it=t;if(t===jn)return t;if(typeof t!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(t===this.it)return this._t;this.it=t;const n=[t];return n.raw=n,this._t={_$litType$:this.constructor.resultType,strings:n,values:[]}}}Ur.directiveName="unsafeHTML",Ur.resultType=1;const ob=wh(Ur);/**
55
- * @license
56
- * Copyright 2017 Google LLC
57
- * SPDX-License-Identifier: BSD-3-Clause
58
- */class _o extends Ur{}_o.directiveName="unsafeSVG",_o.resultType=2;const ab=wh(_o),cb={size:16,color:"currentColor",weight:"regular"};function lb(e){return typeof e=="string"?{regular:e}:e}function Xs(e,t="0 0 256 256"){const n=lb(e);return s=>{const{size:r,color:i,weight:o}={...cb,...s},a=n[o]??n.regular;return O`<svg
59
- xmlns="http://www.w3.org/2000/svg"
60
- data-ui-icon=""
61
- width="${r}"
62
- height="${r}"
63
- viewBox="${t}"
64
- fill="${i}"
65
- >${ab(a)}</svg>`}}const ub=new Map,Wi=new Set;var Dn,xr;const ka=class ka extends HTMLElement{constructor(){super(...arguments);I(this,Dn)}connectedCallback(){y(this,Dn,xr).call(this)}disconnectedCallback(){Wi.delete(this)}attributeChangedCallback(){y(this,Dn,xr).call(this)}refresh(){y(this,Dn,xr).call(this)}get name(){return this.getAttribute("name")}get size(){const n=this.getAttribute("size");if(n===null)return;const s=Number(n);return Number.isFinite(s)?s:void 0}get weight(){const n=this.getAttribute("weight");return n==="bold"||n==="regular"?n:void 0}};Dn=new WeakSet,xr=function(){const n=this.name?ub.get(this.name):null;if(!n){this.name&&Wi.add(this),ue(null,this);return}Wi.delete(this),ue(n({size:this.size,weight:this.weight}),this)},ka.observedAttributes=["name","size","weight"];let yo=ka;customElements.get("icon-element")||customElements.define("icon-element",yo);const bh=Xs('<path d="M205.66,194.34a8,8,0,0,1-11.32,11.32L128,139.31,61.66,205.66a8,8,0,0,1-11.32-11.32L116.69,128,50.34,61.66A8,8,0,0,1,61.66,50.34L128,116.69l66.34-66.35a8,8,0,0,1,11.32,11.32L139.31,128Z"/>'),hb=Xs('<path d="M216,56V200a16,16,0,0,1-16,16H56a16,16,0,0,1-16-16V56A16,16,0,0,1,56,40H200A16,16,0,0,1,216,56Z"/>'),db=Xs({regular:'<path d="M231.87,114l-168-95.89A16,16,0,0,0,40.92,37.34L71.55,128,40.92,218.67A16,16,0,0,0,56,240a16.15,16.15,0,0,0,7.93-2.1l167.92-96.05a16,16,0,0,0,.05-27.89ZM56,224a.56.56,0,0,0,0-.12L85.74,136H144a8,8,0,0,0,0-16H85.74L56.06,32.16A.46.46,0,0,0,56,32l168,95.83Z"/>',bold:'<path d="M233.86,110.48,65.8,14.58A20,20,0,0,0,37.15,38.64L67.33,128,37.15,217.36A20,20,0,0,0,56,244a20.1,20.1,0,0,0,9.81-2.58l.09-.06,168-96.07a20,20,0,0,0,0-34.81ZM63.19,215.26,88.61,140H144a12,12,0,0,0,0-24H88.61L63.18,40.72l152.76,87.17Z"/>'}),Zr=Xs('<path d="M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z"/>'),pb=Xs('<path d="M128,80a48,48,0,1,0,48,48A48.05,48.05,0,0,0,128,80Zm0,80a32,32,0,1,1,32-32A32,32,0,0,1,128,160Zm88-29.84q.06-2.16,0-4.32l14.92-18.64a8,8,0,0,0,1.48-7.06,107.21,107.21,0,0,0-10.88-26.25,8,8,0,0,0-6-3.93l-23.72-2.64q-1.48-1.56-3-3L186,40.54a8,8,0,0,0-3.94-6,107.71,107.71,0,0,0-26.25-10.87,8,8,0,0,0-7.06,1.49L130.16,40Q128,40,125.84,40L107.2,25.11a8,8,0,0,0-7.06-1.48A107.6,107.6,0,0,0,73.89,34.51a8,8,0,0,0-3.93,6L67.32,64.27q-1.56,1.49-3,3L40.54,70a8,8,0,0,0-6,3.94,107.71,107.71,0,0,0-10.87,26.25,8,8,0,0,0,1.49,7.06L40,125.84Q40,128,40,130.16L25.11,148.8a8,8,0,0,0-1.48,7.06,107.21,107.21,0,0,0,10.88,26.25,8,8,0,0,0,6,3.93l23.72,2.64q1.49,1.56,3,3L70,215.46a8,8,0,0,0,3.94,6,107.71,107.71,0,0,0,26.25,10.87,8,8,0,0,0,7.06-1.49L125.84,216q2.16.06,4.32,0l18.64,14.92a8,8,0,0,0,7.06,1.48,107.21,107.21,0,0,0,26.25-10.88,8,8,0,0,0,3.93-6l2.64-23.72q1.56-1.48,3-3L215.46,186a8,8,0,0,0,6-3.94,107.71,107.71,0,0,0,10.87-26.25,8,8,0,0,0-1.49-7.06Zm-16.1-6.5a73.93,73.93,0,0,1,0,8.68,8,8,0,0,0,1.74,5.48l14.19,17.73a91.57,91.57,0,0,1-6.23,15L187,173.11a8,8,0,0,0-5.1,2.64,74.11,74.11,0,0,1-6.14,6.14,8,8,0,0,0-2.64,5.1l-2.51,22.58a91.32,91.32,0,0,1-15,6.23l-17.74-14.19a8,8,0,0,0-5-1.75h-.48a73.93,73.93,0,0,1-8.68,0,8,8,0,0,0-5.48,1.74L100.45,215.8a91.57,91.57,0,0,1-15-6.23L82.89,187a8,8,0,0,0-2.64-5.1,74.11,74.11,0,0,1-6.14-6.14,8,8,0,0,0-5.1-2.64L46.43,170.6a91.32,91.32,0,0,1-6.23-15l14.19-17.74a8,8,0,0,0,1.74-5.48,73.93,73.93,0,0,1,0-8.68,8,8,0,0,0-1.74-5.48L40.2,100.45a91.57,91.57,0,0,1,6.23-15L69,82.89a8,8,0,0,0,5.1-2.64,74.11,74.11,0,0,1,6.14-6.14A8,8,0,0,0,82.89,69L85.4,46.43a91.32,91.32,0,0,1,15-6.23l17.74,14.19a8,8,0,0,0,5.48,1.74,73.93,73.93,0,0,1,8.68,0,8,8,0,0,0,5.48-1.74L155.55,40.2a91.57,91.57,0,0,1,15,6.23L173.11,69a8,8,0,0,0,2.64,5.1,74.11,74.11,0,0,1,6.14,6.14,8,8,0,0,0,5.1,2.64l22.58,2.51a91.32,91.32,0,0,1,6.23,15l-14.19,17.74A8,8,0,0,0,199.87,123.66Z"/>');class Sh extends Event{constructor(t){super("dropdown-item-select",{bubbles:!0,composed:!0}),this.value=t}}class fb extends Event{constructor(t){super("select",{bubbles:!0,composed:!0}),this.value=t}}var Ue,Ve,At,Ln,J,Ls,L,xh,ps,Eh,Ah,wo,bo,Er,Ut,Xt,Ms,Os,Ns,qr,Th,Ih,So,fs,xo,lt;const wa=class wa extends HTMLElement{constructor(){super();I(this,L);I(this,Ue,!1);I(this,Ve,null);I(this,At,null);I(this,Ln);I(this,J,null);I(this,Ls,new MutationObserver(n=>y(this,L,Th).call(this,n)));I(this,Xt,()=>{y(this,L,Er).call(this,!d(this,Ue))});I(this,Ms,n=>{n.key!=="Enter"&&n.key!==" "||(n.preventDefault(),d(this,Xt).call(this))});I(this,Os,n=>{d(this,Ue)&&(n.composedPath().includes(this)||y(this,L,Er).call(this,!1))});I(this,Ns,n=>{n instanceof Sh&&(n.stopPropagation(),C(this,Ue,!1),y(this,L,ps).call(this,n.value),y(this,L,lt).call(this),this.dispatchEvent(new fb(n.value)))});I(this,qr,()=>{y(this,L,So).call(this)});C(this,Ln,this.attachShadow({mode:"open"}))}connectedCallback(){this.addEventListener("dropdown-item-select",d(this,Ns)),document.addEventListener("click",d(this,Os),!0),y(this,L,xh).call(this),d(this,Ls).observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["selected","value","slot"]}),y(this,L,lt).call(this)}disconnectedCallback(){this.removeEventListener("dropdown-item-select",d(this,Ns)),document.removeEventListener("click",d(this,Os),!0),d(this,Ls).disconnect(),y(this,L,xo).call(this)}attributeChangedCallback(){y(this,L,lt).call(this)}get title(){return this.getAttribute("title")??""}get value(){return d(this,Ve)}set value(n){n===null?(y(this,L,Ut).call(this,null,null),y(this,L,Eh).call(this)):y(this,L,ps).call(this,n),y(this,L,lt).call(this)}close(){y(this,L,Er).call(this,!1)}};Ue=new WeakMap,Ve=new WeakMap,At=new WeakMap,Ln=new WeakMap,J=new WeakMap,Ls=new WeakMap,L=new WeakSet,xh=function(){var s;const n=this.querySelector("dropdown-item[selected]");n&&y(this,L,Ut).call(this,n.value,((s=n.textContent)==null?void 0:s.trim())??null)},ps=function(n){var s;for(const r of d(this,L,wo))r.value===n?(y(this,L,Ut).call(this,n,((s=r.textContent)==null?void 0:s.trim())??null),r.hasAttribute("selected")||r.setAttribute("selected","")):r.hasAttribute("selected")&&r.removeAttribute("selected")},Eh=function(){const n=this.querySelectorAll("dropdown-item[selected]");for(const s of n)s.removeAttribute("selected")},Ah=function(n){for(const s of d(this,L,wo))if(s.value===n)return s;return null},wo=function(){return this.querySelectorAll("dropdown-item")},bo=function(){return d(this,At)??this.title},Er=function(n){d(this,Ue)!==n&&(C(this,Ue,n),y(this,L,lt).call(this))},Ut=function(n,s){C(this,Ve,n),C(this,At,s)},Xt=new WeakMap,Ms=new WeakMap,Os=new WeakMap,Ns=new WeakMap,qr=new WeakMap,Th=function(n){n.every(r=>r.target instanceof Element?r.target.closest('[slot="trigger"]')!==null:!1)||y(this,L,Ih).call(this)},Ih=function(){var s,r;const n=this.querySelector("dropdown-item[selected]");if(n){const i=n.value,o=((s=n.textContent)==null?void 0:s.trim())??null,a=d(this,Ve)!==i||d(this,At)!==o;y(this,L,Ut).call(this,i,o),y(this,L,ps).call(this,i),a?y(this,L,lt).call(this):y(this,L,fs).call(this);return}if(d(this,Ve)!==null){const i=y(this,L,Ah).call(this,d(this,Ve));if(i){const o=((r=i.textContent)==null?void 0:r.trim())??null,a=d(this,At)!==o;y(this,L,Ut).call(this,d(this,Ve),o),y(this,L,ps).call(this,d(this,Ve)),a?y(this,L,lt).call(this):y(this,L,fs).call(this);return}}if(d(this,Ve)!==null||d(this,At)!==null){y(this,L,Ut).call(this,null,null),y(this,L,lt).call(this);return}y(this,L,fs).call(this)},So=function(){const n=d(this,Ln).querySelector('slot[name="trigger"]'),s=n instanceof HTMLSlotElement?n.assignedElements({flatten:!0})[0]??null:null;d(this,J)!==s&&(y(this,L,xo).call(this),C(this,J,s),d(this,J)&&(d(this,J).addEventListener("click",d(this,Xt)),d(this,J)instanceof HTMLButtonElement?d(this,J).hasAttribute("type")||(d(this,J).type="button"):(d(this,J).hasAttribute("role")||d(this,J).setAttribute("role","button"),d(this,J).hasAttribute("tabindex")||(d(this,J).tabIndex=0),d(this,J).addEventListener("keydown",d(this,Ms))))),y(this,L,fs).call(this)},fs=function(){d(this,J)&&(d(this,J).setAttribute("data-dropdown-trigger",""),d(this,J).setAttribute("aria-haspopup","listbox"),d(this,J).setAttribute("aria-expanded",d(this,Ue)?"true":"false"),ue(O`
66
- <span class="trigger-label" data-dropdown-trigger-label>${d(this,L,bo)}</span>
67
- <span class="trigger-icon" data-dropdown-trigger-icon aria-hidden="true">
68
- ${Zr({size:14})}
69
- </span>
70
- `,d(this,J)))},xo=function(){d(this,J)&&(d(this,J).removeEventListener("click",d(this,Xt)),d(this,J).removeEventListener("keydown",d(this,Ms)),d(this,J).removeAttribute("data-dropdown-trigger"),d(this,J).removeAttribute("aria-haspopup"),d(this,J).removeAttribute("aria-expanded"),C(this,J,null))},lt=function(){this.toggleAttribute("open",d(this,Ue)),ue(O`
71
- <slot name="trigger" @slotchange=${d(this,qr)}>
72
- <button
73
- class="fallback-trigger"
74
- part="trigger"
75
- type="button"
76
- aria-haspopup="listbox"
77
- aria-expanded=${d(this,Ue)?"true":"false"}
78
- @click=${d(this,Xt)}
79
- >
80
- <span class="trigger-label" part="trigger-label">${d(this,L,bo)}</span>
81
- <span class="trigger-icon" part="trigger-icon" aria-hidden="true">
82
- ${Zr({size:14})}
83
- </span>
84
- </button>
85
- </slot>
86
- ${d(this,Ue)?O`
87
- <div class="panel" part="panel" role="listbox">
88
- <slot></slot>
89
- </div>
90
- `:null}
91
- `,d(this,Ln)),queueMicrotask(()=>y(this,L,So).call(this))},wa.observedAttributes=["title"];let ko=wa;class gb extends HTMLElement{}class mb extends HTMLElement{}class vb extends HTMLElement{}var an,Ao,Ch,Ws,Fs;const ba=class ba extends HTMLElement{constructor(){super(...arguments);I(this,an);I(this,Ws,()=>{this.action||y(this,an,Ch).call(this)});I(this,Fs,n=>{n.key!=="Enter"&&n.key!==" "||(n.preventDefault(),this.click())})}connectedCallback(){this.hasAttribute("role")||this.setAttribute("role","option"),this.hasAttribute("tabindex")||(this.tabIndex=0),this.addEventListener("click",d(this,Ws)),this.addEventListener("keydown",d(this,Fs)),y(this,an,Ao).call(this)}disconnectedCallback(){this.removeEventListener("click",d(this,Ws)),this.removeEventListener("keydown",d(this,Fs))}attributeChangedCallback(){y(this,an,Ao).call(this)}get value(){return this.getAttribute("value")??""}get selected(){return this.hasAttribute("selected")}get action(){return this.hasAttribute("action")}};an=new WeakSet,Ao=function(){if(this.action){this.setAttribute("role","button"),this.removeAttribute("aria-selected");return}this.setAttribute("role","option"),this.setAttribute("aria-selected",this.selected?"true":"false")},Ch=function(){this.dispatchEvent(new Sh(this.value))},Ws=new WeakMap,Fs=new WeakMap,ba.observedAttributes=["action","selected","value"];let Eo=ba;customElements.get("dropdown-menu")||customElements.define("dropdown-menu",ko);customElements.get("dropdown-group")||customElements.define("dropdown-group",gb);customElements.get("dropdown-label")||customElements.define("dropdown-label",mb);customElements.get("dropdown-divider")||customElements.define("dropdown-divider",vb);customElements.get("dropdown-item")||customElements.define("dropdown-item",Eo);class _b extends Event{constructor(){super("close",{bubbles:!0,composed:!0})}}var Us,Rt,Io,Kr,Zs,Co;const Sa=class Sa extends HTMLElement{constructor(){super();I(this,Rt);I(this,Us);I(this,Kr,n=>{n.target===n.currentTarget&&y(this,Rt,Io).call(this)});I(this,Zs,n=>{this.open&&n.key==="Escape"&&y(this,Rt,Io).call(this)});C(this,Us,this.attachShadow({mode:"open"}))}connectedCallback(){document.addEventListener("keydown",d(this,Zs)),y(this,Rt,Co).call(this)}disconnectedCallback(){document.removeEventListener("keydown",d(this,Zs))}attributeChangedCallback(){y(this,Rt,Co).call(this)}get open(){return this.hasAttribute("open")}};Us=new WeakMap,Rt=new WeakSet,Io=function(){this.dispatchEvent(new _b)},Kr=new WeakMap,Zs=new WeakMap,Co=function(){ue(O`
92
- ${this.open?O`
93
- <div class="backdrop" part="backdrop" @click=${d(this,Kr)}>
94
- <slot></slot>
95
- </div>
96
- `:null}
97
- `,d(this,Us))},Sa.observedAttributes=["open"];let To=Sa;customElements.get("modal-overlay")||customElements.define("modal-overlay",To);class zh extends Event{constructor(){super("close",{bubbles:!0,composed:!0})}}class yb extends HTMLElement{}var js,De,Hs,ne,Ar,Tr,$h,Rh,gs,Ph,Bs,$o;const xa=class xa extends HTMLElement{constructor(){super();I(this,ne);I(this,js);I(this,De,[]);I(this,Hs,new MutationObserver(()=>y(this,ne,Ph).call(this)));I(this,Bs,n=>{const s=n.target;if(!(s instanceof Element))return;const r=s.closest("[data-navigate]");if(r){this.navigate(r.dataset.navigate??"");return}s.closest("[data-back]")&&this.back()});C(this,js,this.attachShadow({mode:"open"}))}connectedCallback(){this.addEventListener("click",d(this,Bs)),d(this,Hs).observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["id","title"]}),y(this,ne,gs).call(this)}disconnectedCallback(){this.removeEventListener("click",d(this,Bs)),d(this,Hs).disconnect(),C(this,De,[])}attributeChangedCallback(){y(this,ne,$o).call(this)}get closable(){return this.hasAttribute("closable")}navigate(n){var i;const s=((i=d(this,ne,Ar))==null?void 0:i.id)??null;n===s||!y(this,ne,Tr).call(this,n)||(d(this,De).push(n),y(this,ne,gs).call(this))}back(){d(this,De).length<=1||(d(this,De).pop(),y(this,ne,gs).call(this))}};js=new WeakMap,De=new WeakMap,Hs=new WeakMap,ne=new WeakSet,Ar=function(){const n=d(this,De)[d(this,De).length-1]??null;return n?y(this,ne,Tr).call(this,n):null},Tr=function(n){const s=this.querySelectorAll("panel-page");for(const r of s)if(r.id===n)return r;return null},$h=function(){if(C(this,De,d(this,De).filter(s=>y(this,ne,Tr).call(this,s)!==null)),d(this,De).length>0)return;const n=this.querySelector("panel-page");n!=null&&n.id&&C(this,De,[n.id])},Rh=function(){y(this,ne,$h).call(this);const n=d(this,ne,Ar),s=this.querySelectorAll("panel-page");for(const r of s)r.hidden=r!==n},gs=function(){y(this,ne,Rh).call(this),y(this,ne,$o).call(this)},Ph=function(){y(this,ne,gs).call(this)},Bs=new WeakMap,$o=function(){const n=d(this,ne,Ar);ue(O`
98
- <section class="panel" part="panel">
99
- <header class="title-bar" part="header">
100
- <div class="title-group" part="title-group">
101
- ${d(this,De).length>1?O`
102
- <button
103
- type="button"
104
- class="title-button"
105
- part="button back-button"
106
- aria-label="Back"
107
- @click=${()=>this.back()}
108
- >
109
- <span class="back-icon" part="icon back-icon">
110
- ${Zr({size:14})}
111
- </span>
112
- </button>
113
- `:null}
114
- <h2 class="title" part="title">${(n==null?void 0:n.getAttribute("title"))??""}</h2>
115
- </div>
116
- ${this.closable?O`
117
- <button
118
- type="button"
119
- class="title-button"
120
- part="button close-button"
121
- aria-label="Close"
122
- @click=${()=>this.dispatchEvent(new zh)}
123
- >
124
- <span class="close-icon" part="icon close-icon">${bh({size:14})}</span>
125
- </button>
126
- `:null}
127
- </header>
128
- <slot></slot>
129
- </section>
130
- `,d(this,js))},xa.observedAttributes=["closable"];let zo=xa;customElements.get("panel-view")||customElements.define("panel-view",zo);customElements.get("panel-page")||customElements.define("panel-page",yb);const Dh=rt();class kb extends HTMLElement{constructor(){super(...arguments);m(this,"_artifact",null);m(this,"_artifactURL",null)}set artifact(n){this._artifact=n,this.render()}get artifact(){return this._artifact}set artifactURL(n){this._artifactURL=n,this.render()}get artifactURL(){return this._artifactURL}handleClose(){this._artifact&&this.dispatchEvent(new Dh("close-artifact",{artifactID:this._artifact.id,bubbles:!0,composed:!0}))}template(){const n=this._artifact;return O`
131
- <header class="artifact-title-bar" drag-handle>
132
- <span class="artifact-title">${n.title}</span>
133
- <button
134
- class="artifact-close-btn"
135
- @click=${()=>this.handleClose()}
136
- aria-label="Close"
137
- >
138
- ${bh({size:14})}
139
- </button>
140
- </header>
141
- <div class="artifact-content">
142
- <iframe
143
- class="artifact-html-frame"
144
- title=${this._artifact.title}
145
- src=${this._artifactURL??"about:blank"}
146
- sandbox="allow-scripts"
147
- style="width: 100%; height: 100%; border: none;"
148
- ></iframe>
149
- </div>
150
- `}render(){this._artifact&&(this.setAttribute("type",this._artifact.type),ue(this.template(),this))}}customElements.define("artifact-view",kb);const ve=e=>({type:"px",...e}),Se=e=>({type:"unit",...e}),mr=2,wb=2;class bb{constructor(t){m(this,"basis");m(this,"min");m(this,"_gap");m(this,"_viewport");m(this,"_unit");this.basis=t.basis,this.min=t.min,this._viewport=t.viewport,this._gap=t.gap??ve({x:ce,y:ce});const n=this._viewport.x??Tt,s=this._viewport.y??En,r=this._gap.x??ce,i=this._gap.y??ce,o=Tt+r*wb,a=n<=o,c=a?n-r*mr:Math.min(Tt,n-r*mr),l=a?s-i*mr:Math.min(En,s-i*mr),h=(c-r*(st-1))/st,f=(l-i*(We-1))/We,w=this.basis.x??0,v=this.basis.y??0,E=this.min.x??0,S=this.min.y??0;this._unit=ve(a?{x:Math.max(E,h),y:Math.max(S,f)}:{x:Math.max(E,Math.min(w,h)),y:Math.max(S,Math.min(v,f))})}get unit(){return this._unit}get viewport(){return this._viewport}get gap(){return this._gap}toUnits(t){return Se({x:t.x==null?void 0:t.x/(this._unit.x??1),y:t.y==null?void 0:t.y/(this._unit.y??1)})}toPixels(t){const n=this._unit.x??0,s=this._unit.y??0,r=this._gap.x??ce,i=this._gap.y??ce,o=t.x==null?void 0:t.x*n+Math.max(0,t.x-1)*r,a=t.y==null?void 0:t.y*s+Math.max(0,t.y-1)*i;return ve({x:o,y:a})}}const rn=1e-4,vt=1e-6,Sb=40,xb=24;function Lh(e,t){return Math.max(0,e-t*2)}function Mh(e){const t=[0];for(const n of e)t.push((t[t.length-1]??0)+n);return t}function Oh(e){const t=[0];for(let n=0;n<e.length;n+=1){const s=t[n]??0;t.push(s+e[n]+ce)}return t}function Nh(e,t,n){if(t<0||t>=e.length)return 0;let s=0,r=0;for(let i=t;i<e.length;i+=1){const o=e[i],a=r===0?o:s+ce+o;if(a>n+rn)break;s=a,r+=1}return Math.max(1,r)}function Eb(e,t,n){if(t<0||t>=e.length)return 0;let s=0,r=0;for(let i=t;i>=0;i-=1){const o=e[i],a=r===0?o:s+ce+o;if(a>n+rn)break;s=a,r+=1}return Math.max(1,r)}function Ab(e,t){if(e.length===0)return 0;let n=0,s=0;for(let r=e.length-1;r>=0;r-=1){const i=e[r],o=s===0?i:n+ce+i;if(o>t+rn)break;n=o,s+=1}return Math.max(1,s)}function ra(e,t){if(e.length===0)return 0;const n=Ab(e,t);return Math.max(0,e.length-n)}function Fc(e,t,n){if(e.length===0)return 0;const s=Nh(e,t,n),r=Math.min(e.length,t+s);if(r<=t)return 0;const i=e.slice(t,r);return i.reduce((o,a)=>o+a,0)+Math.max(0,i.length-1)*ce}function Ro(e,t,n){const s=e[t]??0;return n-s}function Sn(e,t,n,s,r){if(e.length===0)return 0;const i=ra(e,r),o=t[i]??0,a=Math.max(0,Math.min(o,n));let c=0;for(let V=0;V<i;V+=1){const U=t[V]??0,Te=t[V+1]??U;if(a>=U&&a<=Te+rn){c=V;break}c=V+1}const l=Math.min(c+1,i),h=t[c]??0,f=t[l]??h,w=Math.max(f-h,rn),v=l===c?0:(a-h)/w,E=Oh(e),S=Fc(e,c,r),z=Fc(e,l,r),q=(s-S)/2,Z=(s-z)/2,ye=Ro(E,c,q),M=Ro(E,l,Z);return ye+(M-ye)*v}function Uc(e,t,n,s,r){const i=ra(e,s),o=t[i]??0;let a=0,c=o;for(let l=0;l<Sb;l+=1){const h=(a+c)/2;Sn(e,t,h,n,s)>r?a=h:c=h}return(a+c)/2}function Zc(e,t,n){const s=Oh(e),[r,i]=t,o=e.slice(r,i+1),a=o.reduce((l,h)=>l+h,0)+Math.max(0,o.length-1)*ce,c=(n-a)/2;return Ro(s,r,c)}function Tb(e,t,n){const s=Nh(e,t,n);return[t,Math.min(e.length-1,t+s-1)]}function Ib(e,t,n){const s=Eb(e,t,n);return[Math.max(0,t-s+1),t]}function Cb(e){const t=new Set,n=[];for(const s of e){const r=`${s.nodeRange[0]}:${s.nodeRange[1]}`;if(t.has(r))continue;const i=n[n.length-1];i&&Math.abs(i.anchor-s.anchor)<=vt||(t.add(r),n.push(s))}return n}function zb(e){const{nodeCols:t,nodeWidthsPx:n,viewportWidthPx:s}=e;if(t.length===0||n.length===0)return{viewspans:[],minScroll:0,maxScroll:0};const r=e.gapPx??ce,i=Lh(s,r),o=Mh(t),a=ra(n,i),c=o[a]??0,l=[];for(let h=0;h<=a;h+=1){const f=Tb(n,h,i),w=Zc(n,f,s),v=Uc(n,o,s,i,w);l.push({nodeRange:f,anchor:Math.max(0,Math.min(c,v))})}for(let h=n.length-1;h>=0;h-=1){const f=Ib(n,h,i),w=`${f[0]}:${f[1]}`;if(l.some(S=>`${S.nodeRange[0]}:${S.nodeRange[1]}`===w))continue;const v=Zc(n,f,s),E=Uc(n,o,s,i,v);l.push({nodeRange:f,anchor:Math.max(0,Math.min(c,E))})}return l.sort((h,f)=>Math.abs(h.anchor-f.anchor)>vt?h.anchor-f.anchor:h.nodeRange[0]!==f.nodeRange[0]?h.nodeRange[0]-f.nodeRange[0]:h.nodeRange[1]-f.nodeRange[1]),{viewspans:Cb(l),minScroll:0,maxScroll:c}}function $b(e,t){var r;let n=0,s=Number.POSITIVE_INFINITY;for(let i=0;i<e.length;i+=1){const o=Math.abs((((r=e[i])==null?void 0:r.anchor)??0)-t);if(o+vt<s){s=o,n=i;continue}Math.abs(o-s)<=vt&&i<n&&(n=i)}return n}function Rb(e,t,n){return n<=0?0:Math.max(0,Math.min(n-1,e+t))}function ns(e,t,n){return Math.max(t,Math.min(n,e))}class Pb extends cn{constructor(n){super();m(this,"_scroll",0);m(this,"minScroll",0);m(this,"maxScroll",0);m(this,"viewspans",[]);m(this,"activeViewspanIndex",null);m(this,"nodeWidthsPx",[]);m(this,"boundaryCols",[0]);m(this,"viewportWidthPx",0);m(this,"framedViewportWidthPx",0);this._scroll=(n==null?void 0:n.x)??0}get scroll(){return Se({x:this._scroll})}get translate(){return ve({x:Sn(this.nodeWidthsPx,this.boundaryCols,this._scroll,this.viewportWidthPx,this.framedViewportWidthPx)})}set scroll(n){const s=ns(n.x??this._scroll,this.minScroll,this.maxScroll);Math.abs(s-this._scroll)<=vt||(this._scroll=s,this.activeViewspanIndex=null,this.dispatchEvent(new es("layout-scroll",{scroll:this.scroll})))}rebuild(n){const s=n.nodeWidths.map(l=>Math.max(0,l.x??0)),r=s.map(l=>n.grid.toPixels(Se({x:l})).x??0),i=n.grid.viewport.x??0,o=n.grid.gap.x??ce,a=zb({nodeCols:s,nodeWidthsPx:r,viewportWidthPx:i,gapPx:o});this.nodeWidthsPx=r,this.boundaryCols=Mh(s),this.viewportWidthPx=i,this.framedViewportWidthPx=Lh(i,o),this.viewspans=a.viewspans,this.minScroll=a.minScroll,this.maxScroll=a.maxScroll,this.activeViewspanIndex=null;const c=ns(this._scroll,this.minScroll,this.maxScroll);Math.abs(c-this._scroll)>vt&&(this._scroll=c,this.dispatchEvent(new es("layout-scroll",{scroll:this.scroll})))}step(n){var a;if(this.viewspans.length===0)return;const s=this.activeViewspanIndex??$b(this.viewspans,this._scroll),r=Rb(s,n,this.viewspans.length),i=((a=this.viewspans[r])==null?void 0:a.anchor)??this._scroll,o=ns(i,this.minScroll,this.maxScroll);this.activeViewspanIndex=r,!(Math.abs(o-this._scroll)<=vt)&&(this._scroll=o,this.dispatchEvent(new es("layout-scroll",{scroll:this.scroll})))}wheel(n){const s=ns(this._scroll+(n.x??0),this.minScroll,this.maxScroll);this.activeViewspanIndex=null,!(Math.abs(s-this._scroll)<=vt)&&(this._scroll=s,this.dispatchEvent(new es("layout-scroll",{scroll:this.scroll})))}wheelPixels(n){const s=n.x??0;if(Math.abs(s)<=rn)return;this.activeViewspanIndex=null;const r=Sn(this.nodeWidthsPx,this.boundaryCols,this._scroll,this.viewportWidthPx,this.framedViewportWidthPx),i=r-s,o=Sn(this.nodeWidthsPx,this.boundaryCols,this.maxScroll,this.viewportWidthPx,this.framedViewportWidthPx),a=Sn(this.nodeWidthsPx,this.boundaryCols,this.minScroll,this.viewportWidthPx,this.framedViewportWidthPx),c=Math.max(o,Math.min(a,i));if(Math.abs(c-r)<=rn)return;let l=this.minScroll,h=this.maxScroll;for(let w=0;w<xb;w+=1){const v=(l+h)/2;Sn(this.nodeWidthsPx,this.boundaryCols,v,this.viewportWidthPx,this.framedViewportWidthPx)>c?l=v:h=v}const f=ns((l+h)/2,this.minScroll,this.maxScroll);Math.abs(f-this._scroll)<=vt||(this._scroll=f,this.dispatchEvent(new es("layout-scroll",{scroll:this.scroll})))}}const Fi={"stack-above":{left:.25,top:0,width:.5,height:.5},"stack-below":{left:.25,top:.5,width:.5,height:.5},"reorder-before":{left:0,top:0,width:.25,height:1},"reorder-after":{left:.75,top:0,width:.25,height:1}},Db=["stack-above","stack-below","reorder-before","reorder-after"];function Ui(e,t){return{left:e.left+e.width*t.left,top:e.top+e.height*t.top,width:e.width*t.width,height:e.height*t.height}}function Nt(e,t,n){return e>=n.left&&e<n.left+n.width&&t>=n.top&&t<n.top+n.height}function ia(e,t){for(const n of e){if(n.type==="card"&&n.id===t)return n;if(n.type==="stack")for(const s of n.children){if(s.type==="card"&&s.id===t)return s;if(s.type==="row"){for(const r of s.children)if(r.id===t)return r}}}return null}function Po(e){return e.height===We||e.height===It?{...e,height:It}:e}function Do(e){return e.height===It?{...e,height:We}:e}function Lb(e,t,n,s){const r=e.findIndex(h=>h.type==="stack"&&h.id===t);if(r===-1)return e;const i=e[r];if(!i||i.type!=="stack")return e;const o=i.children.find(h=>h.type==="card"&&h.id===n);if(!o||o.type!=="card")return e;const a=i.children.filter(h=>h.id!==n);if(a.length===i.children.length||a.length<1)return e;const c=[...e];if(a.length===1){const[h]=a;c[r]=h.type==="card"?Do(h):h}else c[r]={...i,children:a};const l=Math.max(0,Math.min(s,c.length));return c.splice(l,0,Do(o)),c}const Mb=rt(),Ob=rt(),Nb=50;function Wb(e,t){if(e.type!==t.type)return!1;switch(e.type){case"reorder":return t.index===e.index;case"stack":return t.targetCardId===e.targetCardId&&t.position===e.position;case"stack-child-noop":return!0;case"stack-child-extract":return t.toIndex===e.toIndex;case"stack-child-reorder":return t.position===e.position;default:return!1}}function Js(e){return{id:e.id,type:"drop-target",width:e.width,height:e.height}}function jc(e){return e.map(Ub)}function Fb(e){return e.type==="drop-target"?{id:e.id,type:"card",artifactID:e.id,width:e.width,height:e.height}:e}function Ub(e){return e.type==="drop-target"?{id:e.id,type:"card",artifactID:e.id,width:e.width,height:e.height}:e.type==="stack"?{...e,children:e.children.map(Fb)}:e}function Wh(e,t){return e.find(s=>s.type==="card"&&s.id===t)??null}function Hc(e,t){return e.find(s=>s.type==="stack"&&s.id===t)??null}function Zb(e,t){const n=[...t],s=n.findIndex(a=>a.type==="card"&&a.id===e.nodeId);if(s===-1)return null;const r=n[s];if(!r||r.type!=="card")return null;n.splice(s,1);const i=Math.max(0,Math.min(e.lastReorderIndex,n.length));n.splice(i,0,r);const o=n.findIndex(a=>a.type==="card"&&a.id===e.nodeId);return o===-1?null:{base:n,visualDraggedIndex:o}}function jb(e,t,n,s){const r=[...e.base];r.splice(e.visualDraggedIndex,1);const i=r.findIndex(w=>w.type==="card"&&w.id===n.targetCardId),o=i===-1?null:r[i];if(!o||o.type!=="card")return null;const a=Wh(s,t.nodeId);if(!a)return null;const c=Po(a),l=Po(o),h=Js(c),f=n.position==="above"?[h,l]:[l,h];return r[i]={id:o.id,type:"stack",children:f},r}function Zi(e,t){return e.parentStackId?Bb(e,t):Hb(e,t)}function Hb(e,t){const n=e.hitTarget;if(n.type==="reorder"){const s=t[e.sourceIndex];if(!s||s.type!=="card")return[...t];const r=[...t];return r.splice(e.sourceIndex,1),r.splice(n.index,0,Js(s)),r}if(n.type==="stack"){const s=Zb(e,t);return s?jb(s,e,n,t)??[...t]:[...t]}return[...t]}function Bb(e,t){const n=e.hitTarget;switch(n.type){case"stack-child-reorder":return Gb(e,t,n.position);case"stack-child-extract":return Vb(e,t,n.toIndex);case"stack-child-noop":return qb(e,t);default:return[...t]}}function Gb(e,t,n){const s=t.findIndex(w=>w.type==="stack"&&w.id===e.parentStackId);if(s===-1)return[...t];const r=t[s];if(!r||r.type!=="stack")return[...t];if(!r.children.every(w=>w.type==="card"))return[...t];const i=r.children,o=i.findIndex(w=>w.id===e.nodeId);if(o===-1)return[...t];const a=i[o],c=i.filter(w=>w.id!==e.nodeId),l=Js(a),h=n==="above"?[l,...c]:[...c,l],f=[...t];return f[s]={...r,children:h},f}function Vb(e,t,n){if(!e.parentStackId)return[...t];const s=Lb(t,e.parentStackId,e.nodeId,n);if(s===t)return[...t];const r=s.findIndex(a=>a.type==="card"&&a.id===e.nodeId);if(r===-1)return[...t];const i=s[r];if(!i||i.type!=="card")return[...t];const o=[...s];return o[r]=Js(i),o}function qb(e,t){const n=t.findIndex(c=>c.type==="stack"&&c.id===e.parentStackId);if(n===-1)return[...t];const s=t[n];if(!s||s.type!=="stack")return[...t];const r=s.children.findIndex(c=>c.type==="card"&&c.id===e.nodeId);if(r===-1)return[...t];const i=s.children[r];if(!i||i.type!=="card")return[...t];const o=[...t],a=[...s.children];return a[r]=Js(i),o[n]={...s,children:a},o}function Kb(e,t){return t.find(s=>s.type==="stack"&&s.id===e.id)?e.id:Wn()}function Yb(e,t,n){if(e.type==="drop-target"){const s=ia(t,n);if(!s)throw new Error(`finalize: missing dragged card ${n}`);return Po(s)}return e}function Xb(e,t,n){const s=e.children.map(i=>Yb(i,t,n));return{id:Kb(e,t),type:"stack",children:s}}function Jb(e,t,n){if(e.type==="drop-target"){const s=ia(t,n);if(!s)throw new Error(`finalize: missing dragged card ${n}`);return Wh(t,n)!==null?s:Do(s)}return e.type==="card"||e.type==="row"?e:Xb(e,t,n)}function Qb(e,t,n){return e.map(s=>Jb(s,t,n))}function eS(e,t){return JSON.stringify(e)===JSON.stringify(t)}class tS extends cn{constructor(n={}){super();m(this,"pending",null);m(this,"active",null)}start(n){if(this.pending||this.active)return;const s=n.pointer.x??0,r=n.pointer.y??0;this.pending={startX:s,startY:r,grabOffsetX:n.grabOffset.x??0,grabOffsetY:n.grabOffset.y??0,nodeId:n.nodeId,sourceIndex:n.source.index,parentStackId:n.source.parentId,width:n.size.x??0,height:n.size.y??0,baseLayout:n.layout}}update(n){const s=n.pointer.x??0,r=n.pointer.y??0,i=this.pending;if(i){const l=s-i.startX,h=r-i.startY;Math.hypot(l,h)>=Vd&&(this.pending=null,this.active={...i,pointerX:s,pointerY:r,hitTarget:{type:"reorder",index:i.sourceIndex},lastReorderIndex:i.sourceIndex},this.emitDrag(),this.dispatchEvent(new B("change")));return}if(!this.active)return;const o=Zi(this.active,this.active.baseLayout),a=this.getHitTargetForPointer(s,r,n,o),c=a.type==="reorder"?a.index:this.active.lastReorderIndex;this.active.pointerX===s&&this.active.pointerY===r&&Wb(this.active.hitTarget,a)&&this.active.lastReorderIndex===c||(this.active={...this.active,pointerX:s,pointerY:r,hitTarget:a,lastReorderIndex:c},this.emitDrag(),this.dispatchEvent(new B("change")))}drop(){if(this.pending){this.cancel();return}if(!this.active)return;const n=this.active.baseLayout;let s=null;try{const r=Zi(this.active,n),i=Qb(r,n,this.active.nodeId);eS(i,n)||(s=i)}catch{s=null}this.reset(),s&&this.dispatchEvent(new Ob("drop",{layout:s})),this.dispatchEvent(new B("change"))}cancel(){!this.pending&&!this.active||(this.reset(),this.dispatchEvent(new B("change")))}dispose(){this.reset()}get status(){return this.active?"active":this.pending?"pending":"idle"}reset(){this.pending=null,this.active=null}emitDrag(){if(!this.active)return;const n=Zi(this.active,this.active.baseLayout);this.dispatchEvent(new Mb("drag",{nodeId:this.active.nodeId,source:{index:this.active.sourceIndex,parentId:this.active.parentStackId},grabOffset:ve({x:this.active.grabOffsetX,y:this.active.grabOffsetY}),pointer:ve({x:this.active.pointerX,y:this.active.pointerY}),size:ve({x:this.active.width,y:this.active.height}),projectedLayout:n}))}getHitTargetForPointer(n,s,r,i){return this.active?this.isPointerInsideDragBounds(n,s,r.viewport)?this.active.parentStackId?this.getStackChildHitTarget(n,s,r,i):this.getTopLevelCardHitTarget(n,s,r,i):{type:"reorder",index:this.active.sourceIndex}:{type:"reorder",index:0}}getStackChildHitTarget(n,s,r,i){var l;if(!((l=this.active)!=null&&l.parentStackId))return{type:"stack-child-noop"};const o=this.getSourceStackInteractionRect(r.geometry);if(o&&Nt(n,s,o)){const h=o.top+o.height/2;return{type:"stack-child-reorder",position:s<h?"above":"below"}}const a=this.getSourceRemainingSiblingRect(r.geometry);if(a&&Nt(n,s,a)){const h=a.top+a.height/2;return{type:"stack-child-reorder",position:s<h?"above":"below"}}return{type:"stack-child-extract",toIndex:this.getTopLevelReorderIndexForPointer(n,s,r,i)}}getSourceRemainingSiblingRect(n){var i,o;if(!((i=this.active)!=null&&i.parentStackId))return;const s=Hc(this.active.baseLayout,this.active.parentStackId);if(!s)return;const r=s.children.find(a=>{var c;return a.type==="card"&&a.id!==((c=this.active)==null?void 0:c.nodeId)});if(r)return(o=n.find(a=>a.id===r.id))==null?void 0:o.rect}getSourceStackInteractionRect(n){var o;if(!((o=this.active)!=null&&o.parentStackId))return;const s=n.find(a=>{var c;return a.id===((c=this.active)==null?void 0:c.parentStackId)});if(s)return this.active.sourceStackRect=s.rect,s.rect;const r=Hc(this.active.baseLayout,this.active.parentStackId);if(!r)return this.active.sourceStackRect;const i=r.children.find(a=>{var c;return a.type==="card"&&a.id!==((c=this.active)==null?void 0:c.nodeId)});if(i){const a=n.find(c=>c.id===i.id);if(a)return a.rect}return this.active.sourceStackRect}getTopLevelCardHitTarget(n,s,r,i){var v,E,S;const o=this.getTopLevelZoneNodes(r.geometry,i);if(o.length===0)return{type:"reorder",index:((v=this.active)==null?void 0:v.sourceIndex)??0};const c=(r.effectiveVelocity??0)<=Nb;for(const z of o){const q=z.rect;if(!Nt(n,s,q))continue;const Z=this.resolveTopLevelTargetForCard(n,s,z,z.logicalIndex,c);if(Z)return Z;if(!c&&((E=this.active)!=null&&E.hitTarget))return this.active.hitTarget}const l=this.getNearestTargetableZone(n,o);if(!l)return{type:"reorder",index:((S=this.active)==null?void 0:S.sourceIndex)??0};const h=Math.max(l.rect.left,Math.min(l.rect.left+l.rect.width,n)),f=this.resolveTopLevelTargetForCard(h,s,l,l.logicalIndex,c);if(f)return f;const w=l.rect.left+l.rect.width/2;return{type:"reorder",index:n<w?l.logicalIndex:l.logicalIndex+1}}getTopLevelReorderIndexForPointer(n,s,r,i){var l,h;const o=this.getTopLevelZoneNodes(r.geometry,i);if(o.length===0)return((l=this.active)==null?void 0:l.sourceIndex)??0;for(const f of o){if(!Nt(n,s,f.rect))continue;const w=Ui(f.rect,Fi["reorder-before"]);if(Nt(n,s,w))return f.logicalIndex;const v=Ui(f.rect,Fi["reorder-after"]);if(Nt(n,s,v))return f.logicalIndex+1}const a=this.getNearestTargetableZone(n,o);if(!a)return((h=this.active)==null?void 0:h.sourceIndex)??0;const c=a.rect.left+a.rect.width/2;return n<c?a.logicalIndex:a.logicalIndex+1}getTopLevelZoneNodes(n,s){const r=new Map(s.map(a=>[a.id,a])),i=[];let o=0;for(const a of n){const c=r.get(a.id);c&&c.type!=="drop-target"&&(c.type==="card"||c.type==="stack")&&(i.push({id:c.id,rect:a.rect,logicalIndex:o}),o+=1)}return i}resolveTopLevelTargetForCard(n,s,r,i,o){const a=r.rect;for(const c of Db){if(!o&&(c==="stack-above"||c==="stack-below"))continue;const l=Fi[c],h=Ui(a,l);if(Nt(n,s,h))return c==="stack-above"?{type:"stack",targetCardId:r.id,position:"above"}:c==="stack-below"?{type:"stack",targetCardId:r.id,position:"below"}:c==="reorder-before"?{type:"reorder",index:i}:{type:"reorder",index:i+1}}return null}getNearestTargetableZone(n,s){let r=null,i=Number.POSITIVE_INFINITY;for(const o of s){const a=o.rect.left,c=o.rect.left+o.rect.width,l=n<a?a-n:n>c?n-c:0;l<i&&(i=l,r=o)}return r}isPointerInsideDragBounds(n,s,r){return n>=r.left&&n<=r.left+r.width&&s>=r.top&&s<=r.top+r.height}}const Bc=60,nS=80,Gc=.5,Vc=10;class sS{constructor(){m(this,"awaitingFreshWheelGesture",!1);m(this,"lastWheelEventAt",Number.NEGATIVE_INFINITY);m(this,"lastWheelDeltaX",0);m(this,"activeGestureType","none");m(this,"lastWheelGestureAt",Number.NEGATIVE_INFINITY)}markKeyboardNavigation(t){this.awaitingFreshWheelGesture=!0,this.lastWheelEventAt=t,this.activeGestureType="none"}reset(){this.awaitingFreshWheelGesture=!1,this.lastWheelEventAt=Number.NEGATIVE_INFINITY,this.lastWheelDeltaX=0,this.activeGestureType="none",this.lastWheelGestureAt=Number.NEGATIVE_INFINITY}decide(t){const{now:n,shiftKey:s,deltaX:r,deltaY:i,overArtifactContent:o}=t;n-this.lastWheelGestureAt>=Bc&&(this.activeGestureType="none");const c=s&&i!==0,l=c?i:r,h=Math.abs(l),f=Math.abs(i);return this.activeGestureType==="vertical-artifact"&&o?h>=Gc&&h>=f*Vc?this.classifyHorizontal(n,l):(this.lastWheelGestureAt=n,{type:"scroll-native"}):this.activeGestureType==="horizontal-filmstrip"?!c&&o&&f>0&&f>=h*Vc?(this.activeGestureType="vertical-artifact",this.lastWheelGestureAt=n,{type:"scroll-native"}):this.classifyHorizontal(n,l):h<Gc?(o&&(this.activeGestureType="vertical-artifact"),this.lastWheelGestureAt=n,{type:"scroll-native"}):c||h>f?this.classifyHorizontal(n,l):f>h?(o&&(this.activeGestureType="vertical-artifact"),this.lastWheelGestureAt=n,{type:"scroll-native"}):o?(this.activeGestureType="vertical-artifact",this.lastWheelGestureAt=n,{type:"scroll-native"}):this.classifyHorizontal(n,l)}classifyHorizontal(t,n){const s=t-this.lastWheelEventAt,r=Math.sign(this.lastWheelDeltaX),i=Math.sign(n),o=r!==0&&i!==0&&r!==i,a=r!==0&&Math.abs(n)>=Math.abs(this.lastWheelDeltaX)+nS;return this.awaitingFreshWheelGesture&&s<Bc&&!o&&!a?{type:"ignore"}:(this.lastWheelEventAt=t,this.lastWheelDeltaX=n,this.lastWheelGestureAt=t,this.awaitingFreshWheelGesture=!1,this.activeGestureType="horizontal-filmstrip",{type:"scroll-horizontal",horizontalDelta:n})}}const rS=2,qc=1e3,vr=1e-4;function iS(e){if(!e||typeof e!="object")return!1;const t=e;return t.type==="wheel"&&typeof t.deltaX=="number"&&typeof t.deltaY=="number"&&typeof t.shiftKey=="boolean"}function Kc(e,t,n){if(e===0)return 0;const s=t.toPixels(Se({y:We})).y??0;return(n-s)/rS}class oS extends Event{constructor(n){super("scroll",{bubbles:!0,composed:!0});m(this,"scrollPosition");this.scrollPosition=n}}class Fh extends Event{constructor(n){super("layout-change",{bubbles:!0,composed:!0});m(this,"layout");this.layout=n}}class aS extends HTMLElement{constructor(){super();m(this,"_layout",[]);m(this,"_scrollPosition",0);m(this,"layoutGrid",null);m(this,"layoutScroll",new Pb(Se({x:0})));m(this,"scrollModelKey","");m(this,"resizeObserver",null);m(this,"renderPending",!1);m(this,"animateNextRender",!0);m(this,"wheelGesture",new sS);m(this,"dragController",new tS);m(this,"dragState",null);m(this,"activeDragPointerId",null);m(this,"dragListenersAttached",!1);m(this,"dragFrame",0);m(this,"lastDragFrameTime",0);m(this,"lastPointerX",0);m(this,"lastPointerY",0);m(this,"pointerVelocityPxPerSec",0);m(this,"scrollVelocityPxPerSec",0);m(this,"motionSampleTime",0);m(this,"motionSampleX",0);m(this,"motionSampleY",0);m(this,"dragTrackOffsetXPx",0);m(this,"previousProjectedLayoutForOffset",null);m(this,"renderContent",()=>O``);m(this,"onDragControllerChange",()=>{this.dragController.status==="idle"&&(this.dragState=null,this.dragTrackOffsetXPx=0,this.previousProjectedLayoutForOffset=null),this.scheduleRender()});m(this,"onDragControllerDrag",n=>{const s=jc(n.projectedLayout),r=this.shouldApplyTrackOffset(n.projectedLayout,n.source.parentId),i=n.source.parentId?this.getStackChildAnchorCardId(n.source.parentId,n.nodeId):null;this.dragTrackOffsetXPx=r?this.computeDragTrackOffset(this.previousProjectedLayoutForOffset,s,n.nodeId,n.source.parentId,i,this.dragTrackOffsetXPx):0,this.previousProjectedLayoutForOffset=s,this.dragState={nodeId:n.nodeId,source:n.source,grabOffset:n.grabOffset,pointer:n.pointer,size:n.size,projectedLayout:n.projectedLayout},this.scheduleRender()});m(this,"onDragControllerDrop",n=>{this.dragState=null,this.dragTrackOffsetXPx=0,this.previousProjectedLayoutForOffset=null,this.commitLayout(n.layout)});m(this,"onLayoutScrollInternal",n=>{const r=n.scroll.x??0;Math.abs(r-this._scrollPosition)<vr||(this._scrollPosition=r,this.emitScrollPositionChanged(r),this.scheduleRender())});m(this,"handleKeyDown",n=>{if(n.key==="Escape"&&this.dragController.status!=="idle"){n.preventDefault(),this.stopDragFrameLoop(),this.releaseActiveDragPointerCapture(),this.dragController.cancel(),this.detachDragListeners();return}this.dragController.status==="idle"&&(n.key==="ArrowRight"?(n.preventDefault(),this.wheelGesture.markKeyboardNavigation(Date.now()),this.shiftWindow(1)):n.key==="ArrowLeft"&&(n.preventDefault(),this.wheelGesture.markKeyboardNavigation(Date.now()),this.shiftWindow(-1)))});m(this,"handleWheel",n=>{if(this._layout.length===0)return;const s=this.wheelGesture.decide({now:Date.now(),shiftKey:n.shiftKey,deltaX:n.deltaX,deltaY:n.deltaY,overArtifactContent:!1});s.type==="scroll-horizontal"&&(n.preventDefault(),this.applyHorizontalWheel(s.horizontalDelta))});m(this,"handleWindowMessage",n=>{var o;if(this._layout.length===0)return;const s=this.findManagedArtifactFrame(n.source);if(!s||!this.isTrustedArtifactFrameMessage(n,s)||!iS(n.data))return;const r=this.wheelGesture.decide({now:Date.now(),shiftKey:n.data.shiftKey,deltaX:n.data.deltaX,deltaY:n.data.deltaY,overArtifactContent:!0});if(r.type==="scroll-horizontal"){this.applyHorizontalWheel(r.horizontalDelta);return}if(r.type!=="scroll-native")return;const i={type:"scroll",deltaX:0,deltaY:n.data.deltaY};(o=s.contentWindow)==null||o.postMessage(i,this.getArtifactFrameTargetOrigin(s))});m(this,"handlePointerDown",n=>{if(n.button!==0||this.dragController.status!=="idle")return;const s=n.target;if(!(s instanceof Element))return;const r=s.closest(".card-slot[data-layout-draggable='true']");if(!r)return;const i=r.getAttribute("data-layout-node-id");if(!i)return;const o=lS(this._layout,i);if(!o)return;const a=r.getBoundingClientRect();this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.resetMotionTracking(n.clientX,n.clientY),this.focus(),this.dragController.start({nodeId:i,source:{index:o.topLevelIndex,parentId:o.sourceStackId},pointer:ve({x:n.clientX,y:n.clientY}),grabOffset:ve({x:n.clientX-a.left,y:n.clientY-a.top}),size:ve({x:a.width,y:a.height}),layout:this._layout}),this.attachDragListeners(),this.activeDragPointerId=n.pointerId;try{this.setPointerCapture(n.pointerId)}catch{}n.preventDefault()});m(this,"handleWindowPointerMove",n=>{this.lastPointerX=n.clientX,this.lastPointerY=n.clientY,this.updatePointerVelocity(n.clientX,n.clientY),this.syncDragTargetForLatestPointer(),this.ensureDragFrameLoop()});m(this,"handleWindowPointerUp",n=>{this.stopDragFrameLoop(),this.releasePointerCaptureForEvent(n.pointerId),this.dragController.drop(),this.clearMotionTracking(),this.detachDragListeners()});m(this,"handleWindowPointerCancel",n=>{this.stopDragFrameLoop(),this.releasePointerCaptureForEvent(n.pointerId),this.dragController.cancel(),this.clearMotionTracking(),this.detachDragListeners()});m(this,"handleWindowBlur",()=>{this.releaseActiveDragPointerCapture(),this.stopDragFrameLoop(),this.dragController.cancel(),this.clearMotionTracking(),this.detachDragListeners()});m(this,"runDragFrame",n=>{if(this.dragController.status==="idle"){this.dragFrame=0;return}const s=Math.max(0,n-this.lastDragFrameTime)/qc;this.lastDragFrameTime=n,this.samplePointerVelocityAt(n,this.lastPointerX,this.lastPointerY);const r=this.getBoundingClientRect(),i=this.clampPointerToViewport(this.lastPointerX,this.lastPointerY,r),o=this.getDragEdgeScrollDeltaPixels(i.x,r,s);this.scrollVelocityPxPerSec=s>vr?Math.abs(o)/s:0,Math.abs(o)>vr&&(this.animateNextRender=!1,this.layoutScroll.wheelPixels(ve({x:o}))),this.dragController.status==="active"&&this.syncDragTarget(i.x,i.y,r),this.dragFrame=requestAnimationFrame(this.runDragFrame)});this.dragController.addEventListener("change",this.onDragControllerChange),this.dragController.addEventListener("drag",this.onDragControllerDrag),this.dragController.addEventListener("drop",this.onDragControllerDrop),this.layoutScroll.addEventListener("layout-scroll",this.onLayoutScrollInternal)}set layout(n){this._layout=[...n],this.stopDragFrameLoop(),this.dragController.cancel(),this.scrollModelKey="",this.syncScrollModel(),this.layoutScroll.scroll=Se({x:this._scrollPosition}),this.scheduleRender()}get layout(){return this._layout}commitLayout(n){this.layout=n,this.emitLayoutChanged()}set scrollPosition(n){Math.abs(n-this._scrollPosition)<vr||(this.animateNextRender=!1,this.syncScrollModel(),this.layoutScroll.scroll=Se({x:n}))}get scrollPosition(){return this._scrollPosition}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.focus(),this.addEventListener("keydown",this.handleKeyDown),this.addEventListener("wheel",this.handleWheel,{passive:!1}),this.addEventListener("pointerdown",this.handlePointerDown),window.addEventListener("message",this.handleWindowMessage),typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>this.render()),this.resizeObserver.observe(this)),this.render()}disconnectedCallback(){var n;this.removeEventListener("keydown",this.handleKeyDown),this.removeEventListener("wheel",this.handleWheel),this.removeEventListener("pointerdown",this.handlePointerDown),window.removeEventListener("message",this.handleWindowMessage),(n=this.resizeObserver)==null||n.disconnect(),this.resizeObserver=null,this.wheelGesture.reset(),this.detachDragListeners(),this.dragController.removeEventListener("change",this.onDragControllerChange),this.dragController.removeEventListener("drag",this.onDragControllerDrag),this.dragController.removeEventListener("drop",this.onDragControllerDrop),this.layoutScroll.removeEventListener("layout-scroll",this.onLayoutScrollInternal),this.dragController.dispose(),this.stopDragFrameLoop()}scheduleRender(){this.renderPending||(this.renderPending=!0,queueMicrotask(()=>{this.renderPending=!1,this.render()}))}createGrid(n,s){return new bb({basis:ve({x:Zt,y:Zt}),min:ve({x:ec,y:ec}),viewport:ve({x:n,y:s}),gap:ve({x:ce,y:ce})})}syncScrollModel(){const n=this.clientWidth>0?this.clientWidth:Tt,s=this.clientHeight>0?this.clientHeight:En,i=In(this._layout).nodes.map(a=>a.width),o=`${n}x${s}:${i.join(",")}`;o===this.scrollModelKey&&this.layoutGrid||(this.scrollModelKey=o,this.layoutGrid=this.createGrid(n,s),this.layoutScroll.rebuild({grid:this.layoutGrid,nodeWidths:i.map(a=>Se({x:a}))}))}emitScrollPositionChanged(n){this.dispatchEvent(new oS(n))}emitLayoutChanged(){this.dispatchEvent(new Fh([...this._layout]))}shiftWindow(n){this.syncScrollModel(),this.animateNextRender=!0,this.layoutScroll.step(n)}applyHorizontalWheel(n){this.syncScrollModel();const s=this.layoutGrid;if(!s)return;this.animateNextRender=!1;const r=s.toUnits(ve({x:n}));this.layoutScroll.wheel(Se({x:r.x??0}))}findManagedArtifactFrame(n){if(!n)return null;const s=this.querySelectorAll("iframe.artifact-html-frame");for(const r of s)if(r.contentWindow===n)return r;return null}isTrustedArtifactFrameMessage(n,s){if(n.origin==="null")return!0;const r=this.getArtifactFrameOrigin(s);return r===null||n.origin===r}getArtifactFrameTargetOrigin(n){const s=n.getAttribute("sandbox")??"";return new Set(s.split(/\s+/).filter(Boolean)).has("allow-same-origin")?this.getArtifactFrameOrigin(n)??"*":"*"}getArtifactFrameOrigin(n){const s=n.getAttribute("src")??n.src;if(!s)return null;try{return new URL(s,window.location.href).origin}catch{return null}}releaseActiveDragPointerCapture(){this.activeDragPointerId!==null&&this.releasePointerCaptureForEvent(this.activeDragPointerId)}releasePointerCaptureForEvent(n){try{this.hasPointerCapture(n)&&this.releasePointerCapture(n)}catch{}}attachDragListeners(){this.dragListenersAttached||(window.addEventListener("pointermove",this.handleWindowPointerMove),window.addEventListener("pointerup",this.handleWindowPointerUp),window.addEventListener("pointercancel",this.handleWindowPointerCancel),this.addEventListener("pointermove",this.handleWindowPointerMove),this.addEventListener("pointerup",this.handleWindowPointerUp),this.addEventListener("pointercancel",this.handleWindowPointerCancel),window.addEventListener("blur",this.handleWindowBlur),this.dragListenersAttached=!0)}detachDragListeners(){this.dragListenersAttached&&(window.removeEventListener("pointermove",this.handleWindowPointerMove),window.removeEventListener("pointerup",this.handleWindowPointerUp),window.removeEventListener("pointercancel",this.handleWindowPointerCancel),this.removeEventListener("pointermove",this.handleWindowPointerMove),this.removeEventListener("pointerup",this.handleWindowPointerUp),this.removeEventListener("pointercancel",this.handleWindowPointerCancel),window.removeEventListener("blur",this.handleWindowBlur),this.dragListenersAttached=!1,this.activeDragPointerId=null)}getDisplayModel(){if(this.dragController.status!=="active"||!this.dragState)return{layout:this._layout,activePlaceholderId:null,placeholdersById:new Map};const n=new Map;return n.set(this.dragState.nodeId,{id:this.dragState.nodeId,sourceCardId:this.dragState.nodeId}),{layout:jc(this.dragState.projectedLayout),activePlaceholderId:this.dragState.nodeId,placeholdersById:n}}render(){const n=this.clientWidth>0?this.clientWidth:Tt,s=this.clientHeight>0?this.clientHeight:En,r=this.createGrid(n,s);this.layoutGrid=r;const i=this.getDisplayModel(),o=i.layout,a=this.dragController.status==="active",c=In(o),l=c.nodes.map(U=>U.width),h=uS(o),f=`${n}x${s}:${l.join(",")}`;!a&&f!==this.scrollModelKey&&(this.scrollModelKey=f,this.layoutScroll.rebuild({grid:r,nodeWidths:l.map(U=>Se({x:U}))}),this._scrollPosition=this.layoutScroll.scroll.x??this._scrollPosition);const w=cS(o),v=r.unit.x??Zt,E=r.unit.y??Zt,S=a?this.dragTrackOffsetXPx:0,z=(this.layoutScroll.translate.x??0)+S,q=Kc(c.nodes.length,r,s),Z=this.animateNextRender&&!a,ye=[`transform: translate(${z}px, ${q}px);`,`transition-duration: ${Z?Gd:0}ms;`,`pointer-events: ${a?"none":"auto"};`].join(" ");this.animateNextRender=!0,this.style.setProperty("--layout-unit-x",`${v}px`),this.style.setProperty("--layout-unit-y",`${E}px`),this.style.setProperty("--layout-gap",`${ce}px`);const M=this.dragState,V={width:(M==null?void 0:M.size.x)??0,height:(M==null?void 0:M.size.y)??0};ue(O`
151
- <div class="track" style=${ye}>
152
- ${c.nodes.map((U,Te)=>O`
153
- <div
154
- class="node"
155
- layout-node=${String(Te)}
156
- data-layout-node-id=${U.id}
157
- data-layout-placeholder=${String(i.activePlaceholderId===U.id)}
158
- layout-node-cols=${String(U.width)}
159
- style=${`grid-template-columns: repeat(${U.width}, var(--layout-unit-x)); width: ${r.toPixels(Se({x:U.width})).x}px;`}
160
- >
161
- ${U.cards.map(X=>{const Kn=i.placeholdersById.get(X.id);if(M&&Kn)return O`
162
- <div
163
- class="card-slot card-placeholder"
164
- data-layout-placeholder-for=${M.nodeId}
165
- data-layout-placeholder-ghost="false"
166
- data-layout-source-stack=${M.source.parentId??""}
167
- style=${`grid-column: ${X.col} / span ${X.width}; grid-row: ${X.row} / span ${X.height};`}
168
- ></div>
169
- `;const hn=w.get(X.id);if(!hn)return null;const Yn=(U.type==="card"&&X.id===U.id||h.has(X.id))&&(!M||U.id!==i.activePlaceholderId);return O`
170
- <div
171
- class="card-slot"
172
- data-layout-card-id=${X.artifactID}
173
- data-layout-draggable=${String(Yn)}
174
- data-layout-node-id=${X.id}
175
- layout-cols=${String(X.width)}
176
- layout-rows=${String(X.height)}
177
- style=${`grid-column: ${X.col} / span ${X.width}; grid-row: ${X.row} / span ${X.height};`}
178
- >
179
- ${this.renderContent(hn)}
180
- </div>
181
- `})}
182
- </div>
183
- `)}
184
- </div>
185
- ${M?(()=>{const U=this.getPlaceholderPixelSize(c,i.activePlaceholderId,r,V),Te=M.pointer.x??0,X=M.pointer.y??0,Kn=M.grabOffset.x??0,hn=M.grabOffset.y??0;return O`
186
- <div
187
- class="drag-preview"
188
- data-layout-preview-card-id=${M.nodeId}
189
- style=${[`width: ${U.width}px;`,`height: ${U.height}px;`,`left: ${Te-Kn}px;`,`top: ${X-hn}px;`].join(" ")}
190
- >
191
- ${this.renderDraggedPreview(M.nodeId)}
192
- </div>
193
- `})():null}
194
- `,this)}ensureDragFrameLoop(){this.dragFrame!==0||this.dragController.status==="idle"||(this.lastDragFrameTime=performance.now(),this.dragFrame=requestAnimationFrame(this.runDragFrame))}stopDragFrameLoop(){this.dragFrame!==0&&(cancelAnimationFrame(this.dragFrame),this.dragFrame=0,this.scrollVelocityPxPerSec=0)}syncDragTargetForLatestPointer(){if(this.dragController.status==="idle")return;const n=this.getBoundingClientRect();if(this.dragController.status==="active"){const r=this.clampPointerToViewport(this.lastPointerX,this.lastPointerY,n);this.syncDragTarget(r.x,r.y,n);return}if(this.syncDragTarget(this.lastPointerX,this.lastPointerY,n),this.dragController.status==="pending")return;const s=this.clampPointerToViewport(this.lastPointerX,this.lastPointerY,n);(s.x!==this.lastPointerX||s.y!==this.lastPointerY)&&this.syncDragTarget(s.x,s.y,n)}syncDragTarget(n,s,r=this.getBoundingClientRect()){if(this.dragController.status==="idle")return;const i=this.getDisplayModel(),o=new Set(i.placeholdersById.keys()),a=this.dragController.status==="active"?this.dragTrackOffsetXPx:0,c=this.measureLayoutGeometry(i.layout,o,a);this.dragController.update({pointer:ve({x:n,y:s}),viewport:{left:r.left,top:r.top,width:r.width,height:r.height},geometry:c,effectiveVelocity:Math.max(this.pointerVelocityPxPerSec,this.scrollVelocityPxPerSec)})}resetMotionTracking(n,s){this.pointerVelocityPxPerSec=0,this.scrollVelocityPxPerSec=0,this.motionSampleTime=performance.now(),this.motionSampleX=n,this.motionSampleY=s}clearMotionTracking(){this.pointerVelocityPxPerSec=0,this.scrollVelocityPxPerSec=0,this.motionSampleTime=0}updatePointerVelocity(n,s){this.samplePointerVelocityAt(performance.now(),n,s)}samplePointerVelocityAt(n,s,r){if(this.motionSampleTime===0){this.motionSampleTime=n,this.motionSampleX=s,this.motionSampleY=r,this.pointerVelocityPxPerSec=0;return}const i=n-this.motionSampleTime;if(i<100)return;const o=s-this.motionSampleX;this.pointerVelocityPxPerSec=Math.abs(o)/i*qc,this.motionSampleTime=n,this.motionSampleX=s,this.motionSampleY=r}clampPointerToViewport(n,s,r){return{x:Math.max(r.left,Math.min(r.left+r.width,n)),y:Math.max(r.top,Math.min(r.top+r.height,s))}}isPointerOutsideViewport(n,s,r){return n<r.left||n>r.left+r.width||s<r.top||s>r.top+r.height}getDragEdgeScrollDeltaPixels(n,s,r){var l;const i=s.left+cr,o=s.left+s.width-cr,a=((l=this.layoutGrid)==null?void 0:l.unit.x)??Zt,c=qd*a;if(n<i){const h=Math.max(0,Math.min(1,(i-n)/cr));return-(c*h**tc)*r}if(n>o){const h=Math.max(0,Math.min(1,(n-o)/cr));return c*h**tc*r}return 0}measureLayoutGeometry(n,s,r=0){const i=this.layoutGrid;if(!i)return[];const o=In(n),a=new Map(o.nodes.map(E=>[E.id,E.width])),c=i.toPixels(Se({y:We})).y??En,l=this.clientHeight>0?this.clientHeight:En,h=(this.layoutScroll.translate.x??0)+r,f=Kc(o.nodes.length,i,l),w=[];let v=h;for(const E of n){const S=a.get(E.id)??st,z=i.toPixels(Se({x:S})).x??Tt,q={left:v,top:f,width:z,height:c};w.push({id:E.id,rect:q}),v+=z+ce}return w}getPlaceholderPixelSize(n,s,r,i){if(!s)return i;for(const o of n.nodes)for(const a of o.cards)if(a.id===s)return{width:r.toPixels(Se({x:a.width})).x??i.width,height:r.toPixels(Se({y:a.height})).y??i.height};return i}renderDraggedPreview(n){const s=ia(this._layout,n);return s?this.renderContent(s):O``}shouldApplyTrackOffset(n,s){if(s)return!0;for(const r of n){if(r.type!=="stack")continue;if(r.children.some(o=>o.type==="drop-target")&&s!==r.id)return!0}return!1}computeDragTrackOffset(n,s,r,i,o,a){if(!n)return a;const c=i?o??this.getStableAnchorCardId(n,s,r):this.getStableAnchorNodeId(n,s,r);if(!c)return a;const l=i?Xc(n,c,this.layoutGrid):Jc(n,c,this.layoutGrid),h=i?Xc(s,c,this.layoutGrid):Jc(s,c,this.layoutGrid);return l===null||h===null?a:a+(l-h)}getStableAnchorCardId(n,s,r){const i=Yc(n),o=new Set(Yc(s));for(const a of i)if(a!==r&&o.has(a))return a;return null}getStableAnchorNodeId(n,s,r){const i=new Set(s.map(o=>o.id));for(const o of n)if(o.id!==r&&i.has(o.id))return o.id;return null}getStackChildAnchorCardId(n,s){const r=this._layout.find(o=>o.type==="stack"&&o.id===n);if(!r||r.type!=="stack")return null;const i=r.children.find(o=>o.type==="card"&&o.id!==s);return(i==null?void 0:i.id)??null}}function cS(e){const t=new Map;for(const n of e){if(n.type==="card"){t.set(n.id,n);continue}for(const s of n.children)if(s.type==="card")t.set(s.id,s);else for(const r of s.children)t.set(r.id,r)}return t}function lS(e,t){const n=e.findIndex(s=>s.type==="card"&&s.id===t);if(n!==-1)return{topLevelIndex:n};for(let s=0;s<e.length;s+=1){const r=e[s];if(!(!r||r.type!=="stack")&&r.children.some(i=>i.type==="card"&&i.id===t))return{topLevelIndex:s,sourceStackId:r.id}}return null}function uS(e){const t=new Set;for(const n of e)if(n.type==="stack")for(const s of n.children)s.type==="card"&&t.add(s.id);return t}function Yc(e){const t=[];for(const n of e){if(n.type==="card"){t.push(n.id);continue}if(n.type==="stack"){const s=n.children.find(r=>r.type==="card");s&&t.push(s.id)}}return t}function Xc(e,t,n){if(!n)return null;const s=In(e),r=new Map(s.nodes.map(o=>[o.id,o.width]));let i=0;for(const o of e){if(o.type==="card"&&o.id===t||o.type==="stack"&&o.children.some(l=>l.type==="card"&&l.id===t))return i;const a=r.get(o.id)??st,c=n.toPixels(Se({x:a})).x??Tt;i+=c+ce}return null}function Jc(e,t,n){if(!n)return null;const s=In(e),r=new Map(s.nodes.map(o=>[o.id,o.width]));let i=0;for(const o of e){if(o.id===t)return i;const a=r.get(o.id)??st,c=n.toPixels(Se({x:a})).x??Tt;i+=c+ce}return null}customElements.get("layout-view")||customElements.define("layout-view",aS);class hS extends HTMLElement{constructor(){super(...arguments);m(this,"workspaceService",Ze.resolve("WorkspaceService"));m(this,"handleWorkspaceChange",()=>{this.render()});m(this,"handleCloseArtifact",n=>{n instanceof Dh&&this.workspaceService.removeArtifact(n.artifactID)});m(this,"handleScrollPositionChanged",n=>{const s=n;typeof s.scrollPosition=="number"&&Number.isFinite(s.scrollPosition)&&this.workspaceService.setScrollPosition(s.scrollPosition)});m(this,"handleLayoutChanged",n=>{n instanceof Fh&&this.workspaceService.setLayout(n.layout)})}connectedCallback(){this.render(),this.workspaceService.addEventListener("change",this.handleWorkspaceChange)}disconnectedCallback(){this.workspaceService.removeEventListener("change",this.handleWorkspaceChange)}buildArtifactMap(){return new Map(this.workspaceService.activeArtifacts.map(n=>[n.id,n]))}render(){const n=this.workspaceService.activeWorkspace,s=(n==null?void 0:n.layout)??[],r=this.buildArtifactMap();if(s.length===0){ue(O`<p data-testid="empty-workspace">No artifacts yet.</p>`,this);return}ue(O`
195
- <layout-view
196
- .layout=${s}
197
- .renderContent=${o=>{const a=r.get(o.artifactID);return a?O`<artifact-view
198
- .artifact=${a}
199
- .artifactURL=${this.workspaceService.getArtifactURL(o.artifactID)}
200
- ></artifact-view>`:O``}}
201
- .scrollPosition=${this.workspaceService.scrollPosition}
202
- @scroll=${this.handleScrollPositionChanged}
203
- @layout-change=${this.handleLayoutChanged}
204
- @close-artifact=${this.handleCloseArtifact}
205
- ></layout-view>
206
- `,this)}}customElements.define("workspace-view",hS);const ji=rt();class dS extends HTMLElement{constructor(){super(...arguments);m(this,"workspaceService",Ze.resolve("WorkspaceService"));m(this,"serverManager",Ze.resolve("ServerManager"));m(this,"handleChange",()=>{this.render()})}connectedCallback(){this.render(),this.workspaceService.addEventListener("change",this.handleChange),this.serverManager.addEventListener("change",this.handleChange)}disconnectedCallback(){this.workspaceService.removeEventListener("change",this.handleChange),this.serverManager.removeEventListener("change",this.handleChange)}handleSelect(n){this.workspaceService.setActiveWorkspace(n.value)}closeDropdown(){var n;(n=this.querySelector("dropdown-menu"))==null||n.close()}handleEditWorkspace(){this.workspaceService.activeWorkspace&&(this.closeDropdown(),this.dispatchEvent(new ji("edit-workspace",{bubbles:!0,composed:!0})))}handleCreateWorkspace(n){this.closeDropdown(),this.dispatchEvent(new ji("create-workspace",{serverURL:n,bubbles:!0,composed:!0}))}handleDeleteWorkspace(){this.workspaceService.activeWorkspace&&(this.closeDropdown(),this.dispatchEvent(new ji("delete-workspace",{bubbles:!0,composed:!0})))}render(){var r;const n=((r=this.workspaceService.activeWorkspace)==null?void 0:r.name)??"No workspaces",s=[...this.serverManager.servers.values()].map(i=>({...i,sortedWorkspaces:[...i.workspaces.values()].sort((o,a)=>o.name.localeCompare(a.name,void 0,{sensitivity:"base"}))}));ue(O`
207
- <dropdown-menu
208
- title=${n}
209
- @select=${i=>this.handleSelect(i)}
210
- >
211
- <button
212
- slot="trigger"
213
- trigger
214
- type="button"
215
- aria-label="Choose workspace"
216
- ></button>
217
- ${s.map(i=>O`
218
- <dropdown-group>
219
- <dropdown-label>${i.name}</dropdown-label>
220
- ${i.sortedWorkspaces.map(o=>this.renderWorkspaceItem(o))}
221
- <dropdown-item
222
- action
223
- @click=${()=>this.handleCreateWorkspace(i.url)}
224
- >
225
- + New workspace
226
- </dropdown-item>
227
- </dropdown-group>
228
- `)}
229
- ${this.workspaceService.activeWorkspace?O`
230
- <dropdown-divider></dropdown-divider>
231
- <dropdown-group>
232
- <dropdown-item
233
- action
234
- @click=${()=>this.handleEditWorkspace()}
235
- >
236
- Edit workspace...
237
- </dropdown-item>
238
- <dropdown-item
239
- action
240
- danger
241
- @click=${()=>this.handleDeleteWorkspace()}
242
- >
243
- Delete workspace...
244
- </dropdown-item>
245
- </dropdown-group>
246
- `:null}
247
- </dropdown-menu>
248
- `,this)}renderWorkspaceItem(n){var r;const s=n.id===this.workspaceService.activeWorkspaceID?((r=this.workspaceService.activeWorkspace)==null?void 0:r.name)??n.name:n.name;return O`
249
- <dropdown-item
250
- value=${n.id}
251
- ?selected=${n.id===this.workspaceService.activeWorkspaceID}
252
- >
253
- ${s}
254
- </dropdown-item>
255
- `}}customElements.define("workspace-picker",dS);const Qc=new WeakMap,el=new WeakSet,Uh=new WeakMap,Zh=new WeakMap,_r=new WeakSet,jh=e=>e;function Hh(e,t){return e===Boolean?t===null?!1:t!=="false":t===null?null:e===Number?Number(t):e===Object?JSON.parse(t):t}function pS(e,t){return t==null?null:e===Boolean?t?"":"false":e===Object?JSON.stringify(t):String(t)}function fS(e){const t=new Map;if(!e)return t;if(Array.isArray(e)){for(const n of e)t.set(n,{attribute:!1});return t}for(const[n,s]of Object.entries(e))t.set(n,{type:s.type,attribute:s.attribute??!1});return t}function As(e){let t=Qc.get(e);return t||(t={constructing:!0,syncingFromAttribute:null,syncingToAttribute:null,values:new Map},Qc.set(e,t)),t}function oa(e){return Zh.get(e)??new Map}function Bh(e,t){var n;return((n=Uh.get(e))==null?void 0:n.has(t))??!1}function Ts(e){return typeof e.attribute=="string"?e.attribute:null}function gS(e,t){for(const[n,s]of oa(e))if(Ts(s)===t)return{prop:n,config:s};return null}function Ir(e){if(el.has(e))return;const t=fS(e.observedProperties);Zh.set(e,t);const n=new Set;Uh.set(e,n);for(const[s,r]of t){if(Ts(r)&&!r.type)throw new Error(`Observed property "${s}" requires a "type" when "attribute" is set.`);const o=Object.getOwnPropertyDescriptor(e.prototype,s);if(o!=null&&o.get||o!=null&&o.set)throw new Error(`Observed property "${s}" cannot define a custom getter/setter. Use propertyChangedCallback for side effects instead.`);o||(n.add(s),Object.defineProperty(e.prototype,s,{enumerable:!0,configurable:!0,get(){return As(this).values.get(s)},set(a){const c=As(this),l=c.values.get(s);if(Object.is(l,a))return;c.values.set(s,a);const h=Ts(r);if(h&&c.syncingFromAttribute!==h&&c.syncingToAttribute!==h){const f=pS(r.type,a);c.syncingToAttribute=h;try{const w=this;f===null?w.removeAttribute(h):w.setAttribute(h,f)}finally{c.syncingToAttribute=null}}(!c.constructing||c.syncingFromAttribute!==null||l!==void 0)&&this.propertyChangedCallback(s,l,a)}}))}el.add(e)}function mS(e,t){Ir(t);const n=As(e),s=jh(e),r=oa(t);for(const[i,o]of r){if(!Bh(t,i))continue;const a=Object.prototype.hasOwnProperty.call(e,i),c=a?s[i]:void 0;a&&delete s[i];const l=Ts(o);if(l&&e.hasAttribute(l)){const h=Hh(o.type,e.getAttribute(l));n.syncingFromAttribute=l;try{s[i]=h}finally{n.syncingFromAttribute=null}continue}a&&(s[i]=c)}n.constructing=!1}class Is extends globalThis.HTMLElement{static get observedAttributes(){const t=this;return Ir(t),vS(t),[...oa(t).values()].map(n=>Ts(n)).filter(n=>!!n)}constructor(){super();const t=this.constructor;Ir(t),As(this),queueMicrotask(()=>mS(this,t))}attributeChangedCallback(t,n,s){const r=this.constructor;Ir(r);const i=gS(r,t);if(!i||!Bh(r,i.prop))return;const o=As(this);if(o.syncingToAttribute===t)return;const a=jh(this);Object.prototype.hasOwnProperty.call(this,i.prop)&&delete a[i.prop],o.syncingFromAttribute=t;try{a[i.prop]=Hh(i.config.type,s)}finally{o.syncingFromAttribute=null}}propertyChangedCallback(t,n,s){}}m(Is,"observedProperties");function vS(e){if(_r.has(e))return;const t=Object.getOwnPropertyDescriptor(e.prototype,"attributeChangedCallback");if(!t||typeof t.value!="function"){_r.add(e);return}const n=t.value;if(n===Is.prototype.attributeChangedCallback){_r.add(e);return}Object.defineProperty(e.prototype,"attributeChangedCallback",{configurable:!0,writable:!0,value(s,r,i){Is.prototype.attributeChangedCallback.call(this,s,r,i),n.call(this,s,r,i)}}),_r.add(e)}/*! @license DOMPurify 3.3.3 | (c) Cure53 and other contributors | Released under the Apache license 2.0 and Mozilla Public License 2.0 | github.com/cure53/DOMPurify/blob/3.3.3/LICENSE */const{entries:Gh,setPrototypeOf:tl,isFrozen:_S,getPrototypeOf:yS,getOwnPropertyDescriptor:kS}=Object;let{freeze:$e,seal:je,create:Cr}=Object,{apply:Lo,construct:Mo}=typeof Reflect<"u"&&Reflect;$e||($e=function(t){return t});je||(je=function(t){return t});Lo||(Lo=function(t,n){for(var s=arguments.length,r=new Array(s>2?s-2:0),i=2;i<s;i++)r[i-2]=arguments[i];return t.apply(n,r)});Mo||(Mo=function(t){for(var n=arguments.length,s=new Array(n>1?n-1:0),r=1;r<n;r++)s[r-1]=arguments[r];return new t(...s)});const yr=Re(Array.prototype.forEach),wS=Re(Array.prototype.lastIndexOf),nl=Re(Array.prototype.pop),ss=Re(Array.prototype.push),bS=Re(Array.prototype.splice),zr=Re(String.prototype.toLowerCase),Hi=Re(String.prototype.toString),Bi=Re(String.prototype.match),rs=Re(String.prototype.replace),SS=Re(String.prototype.indexOf),xS=Re(String.prototype.trim),Oe=Re(Object.prototype.hasOwnProperty),Ie=Re(RegExp.prototype.test),is=ES(TypeError);function Re(e){return function(t){t instanceof RegExp&&(t.lastIndex=0);for(var n=arguments.length,s=new Array(n>1?n-1:0),r=1;r<n;r++)s[r-1]=arguments[r];return Lo(e,t,s)}}function ES(e){return function(){for(var t=arguments.length,n=new Array(t),s=0;s<t;s++)n[s]=arguments[s];return Mo(e,n)}}function F(e,t){let n=arguments.length>2&&arguments[2]!==void 0?arguments[2]:zr;tl&&tl(e,null);let s=t.length;for(;s--;){let r=t[s];if(typeof r=="string"){const i=n(r);i!==r&&(_S(t)||(t[s]=i),r=i)}e[r]=!0}return e}function AS(e){for(let t=0;t<e.length;t++)Oe(e,t)||(e[t]=null);return e}function Qe(e){const t=Cr(null);for(const[n,s]of Gh(e))Oe(e,n)&&(Array.isArray(s)?t[n]=AS(s):s&&typeof s=="object"&&s.constructor===Object?t[n]=Qe(s):t[n]=s);return t}function os(e,t){for(;e!==null;){const s=kS(e,t);if(s){if(s.get)return Re(s.get);if(typeof s.value=="function")return Re(s.value)}e=yS(e)}function n(){return null}return n}const sl=$e(["a","abbr","acronym","address","area","article","aside","audio","b","bdi","bdo","big","blink","blockquote","body","br","button","canvas","caption","center","cite","code","col","colgroup","content","data","datalist","dd","decorator","del","details","dfn","dialog","dir","div","dl","dt","element","em","fieldset","figcaption","figure","font","footer","form","h1","h2","h3","h4","h5","h6","head","header","hgroup","hr","html","i","img","input","ins","kbd","label","legend","li","main","map","mark","marquee","menu","menuitem","meter","nav","nobr","ol","optgroup","option","output","p","picture","pre","progress","q","rp","rt","ruby","s","samp","search","section","select","shadow","slot","small","source","spacer","span","strike","strong","style","sub","summary","sup","table","tbody","td","template","textarea","tfoot","th","thead","time","tr","track","tt","u","ul","var","video","wbr"]),Gi=$e(["svg","a","altglyph","altglyphdef","altglyphitem","animatecolor","animatemotion","animatetransform","circle","clippath","defs","desc","ellipse","enterkeyhint","exportparts","filter","font","g","glyph","glyphref","hkern","image","inputmode","line","lineargradient","marker","mask","metadata","mpath","part","path","pattern","polygon","polyline","radialgradient","rect","stop","style","switch","symbol","text","textpath","title","tref","tspan","view","vkern"]),Vi=$e(["feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence"]),TS=$e(["animate","color-profile","cursor","discard","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignobject","hatch","hatchpath","mesh","meshgradient","meshpatch","meshrow","missing-glyph","script","set","solidcolor","unknown","use"]),qi=$e(["math","menclose","merror","mfenced","mfrac","mglyph","mi","mlabeledtr","mmultiscripts","mn","mo","mover","mpadded","mphantom","mroot","mrow","ms","mspace","msqrt","mstyle","msub","msup","msubsup","mtable","mtd","mtext","mtr","munder","munderover","mprescripts"]),IS=$e(["maction","maligngroup","malignmark","mlongdiv","mscarries","mscarry","msgroup","mstack","msline","msrow","semantics","annotation","annotation-xml","mprescripts","none"]),rl=$e(["#text"]),il=$e(["accept","action","align","alt","autocapitalize","autocomplete","autopictureinpicture","autoplay","background","bgcolor","border","capture","cellpadding","cellspacing","checked","cite","class","clear","color","cols","colspan","controls","controlslist","coords","crossorigin","datetime","decoding","default","dir","disabled","disablepictureinpicture","disableremoteplayback","download","draggable","enctype","enterkeyhint","exportparts","face","for","headers","height","hidden","high","href","hreflang","id","inert","inputmode","integrity","ismap","kind","label","lang","list","loading","loop","low","max","maxlength","media","method","min","minlength","multiple","muted","name","nonce","noshade","novalidate","nowrap","open","optimum","part","pattern","placeholder","playsinline","popover","popovertarget","popovertargetaction","poster","preload","pubdate","radiogroup","readonly","rel","required","rev","reversed","role","rows","rowspan","spellcheck","scope","selected","shape","size","sizes","slot","span","srclang","start","src","srcset","step","style","summary","tabindex","title","translate","type","usemap","valign","value","width","wrap","xmlns","slot"]),Ki=$e(["accent-height","accumulate","additive","alignment-baseline","amplitude","ascent","attributename","attributetype","azimuth","basefrequency","baseline-shift","begin","bias","by","class","clip","clippathunits","clip-path","clip-rule","color","color-interpolation","color-interpolation-filters","color-profile","color-rendering","cx","cy","d","dx","dy","diffuseconstant","direction","display","divisor","dur","edgemode","elevation","end","exponent","fill","fill-opacity","fill-rule","filter","filterunits","flood-color","flood-opacity","font-family","font-size","font-size-adjust","font-stretch","font-style","font-variant","font-weight","fx","fy","g1","g2","glyph-name","glyphref","gradientunits","gradienttransform","height","href","id","image-rendering","in","in2","intercept","k","k1","k2","k3","k4","kerning","keypoints","keysplines","keytimes","lang","lengthadjust","letter-spacing","kernelmatrix","kernelunitlength","lighting-color","local","marker-end","marker-mid","marker-start","markerheight","markerunits","markerwidth","maskcontentunits","maskunits","max","mask","mask-type","media","method","mode","min","name","numoctaves","offset","operator","opacity","order","orient","orientation","origin","overflow","paint-order","path","pathlength","patterncontentunits","patterntransform","patternunits","points","preservealpha","preserveaspectratio","primitiveunits","r","rx","ry","radius","refx","refy","repeatcount","repeatdur","restart","result","rotate","scale","seed","shape-rendering","slope","specularconstant","specularexponent","spreadmethod","startoffset","stddeviation","stitchtiles","stop-color","stop-opacity","stroke-dasharray","stroke-dashoffset","stroke-linecap","stroke-linejoin","stroke-miterlimit","stroke-opacity","stroke","stroke-width","style","surfacescale","systemlanguage","tabindex","tablevalues","targetx","targety","transform","transform-origin","text-anchor","text-decoration","text-rendering","textlength","type","u1","u2","unicode","values","viewbox","visibility","version","vert-adv-y","vert-origin-x","vert-origin-y","width","word-spacing","wrap","writing-mode","xchannelselector","ychannelselector","x","x1","x2","xmlns","y","y1","y2","z","zoomandpan"]),ol=$e(["accent","accentunder","align","bevelled","close","columnsalign","columnlines","columnspan","denomalign","depth","dir","display","displaystyle","encoding","fence","frame","height","href","id","largeop","length","linethickness","lspace","lquote","mathbackground","mathcolor","mathsize","mathvariant","maxsize","minsize","movablelimits","notation","numalign","open","rowalign","rowlines","rowspacing","rowspan","rspace","rquote","scriptlevel","scriptminsize","scriptsizemultiplier","selection","separator","separators","stretchy","subscriptshift","supscriptshift","symmetric","voffset","width","xmlns"]),kr=$e(["xlink:href","xml:id","xlink:title","xml:space","xmlns:xlink"]),CS=je(/\{\{[\w\W]*|[\w\W]*\}\}/gm),zS=je(/<%[\w\W]*|[\w\W]*%>/gm),$S=je(/\$\{[\w\W]*/gm),RS=je(/^data-[\-\w.\u00B7-\uFFFF]+$/),PS=je(/^aria-[\-\w]+$/),Vh=je(/^(?:(?:(?:f|ht)tps?|mailto|tel|callto|sms|cid|xmpp|matrix):|[^a-z]|[a-z+.\-]+(?:[^a-z+.\-:]|$))/i),DS=je(/^(?:\w+script|data):/i),LS=je(/[\u0000-\u0020\u00A0\u1680\u180E\u2000-\u2029\u205F\u3000]/g),qh=je(/^html$/i),MS=je(/^[a-z][.\w]*(-[.\w]+)+$/i);var al=Object.freeze({__proto__:null,ARIA_ATTR:PS,ATTR_WHITESPACE:LS,CUSTOM_ELEMENT:MS,DATA_ATTR:RS,DOCTYPE_NAME:qh,ERB_EXPR:zS,IS_ALLOWED_URI:Vh,IS_SCRIPT_OR_DATA:DS,MUSTACHE_EXPR:CS,TMPLIT_EXPR:$S});const as={element:1,text:3,progressingInstruction:7,comment:8,document:9},OS=function(){return typeof window>"u"?null:window},NS=function(t,n){if(typeof t!="object"||typeof t.createPolicy!="function")return null;let s=null;const r="data-tt-policy-suffix";n&&n.hasAttribute(r)&&(s=n.getAttribute(r));const i="dompurify"+(s?"#"+s:"");try{return t.createPolicy(i,{createHTML(o){return o},createScriptURL(o){return o}})}catch{return console.warn("TrustedTypes policy "+i+" could not be created."),null}},cl=function(){return{afterSanitizeAttributes:[],afterSanitizeElements:[],afterSanitizeShadowDOM:[],beforeSanitizeAttributes:[],beforeSanitizeElements:[],beforeSanitizeShadowDOM:[],uponSanitizeAttribute:[],uponSanitizeElement:[],uponSanitizeShadowNode:[]}};function Kh(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:OS();const t=D=>Kh(D);if(t.version="3.3.3",t.removed=[],!e||!e.document||e.document.nodeType!==as.document||!e.Element)return t.isSupported=!1,t;let{document:n}=e;const s=n,r=s.currentScript,{DocumentFragment:i,HTMLTemplateElement:o,Node:a,Element:c,NodeFilter:l,NamedNodeMap:h=e.NamedNodeMap||e.MozNamedAttrMap,HTMLFormElement:f,DOMParser:w,trustedTypes:v}=e,E=c.prototype,S=os(E,"cloneNode"),z=os(E,"remove"),q=os(E,"nextSibling"),Z=os(E,"childNodes"),ye=os(E,"parentNode");if(typeof o=="function"){const D=n.createElement("template");D.content&&D.content.ownerDocument&&(n=D.content.ownerDocument)}let M,V="";const{implementation:U,createNodeIterator:Te,createDocumentFragment:X,getElementsByTagName:Kn}=n,{importNode:hn}=s;let xe=cl();t.isSupported=typeof Gh=="function"&&typeof ye=="function"&&U&&U.createHTMLDocument!==void 0;const{MUSTACHE_EXPR:Yn,ERB_EXPR:gi,TMPLIT_EXPR:mi,DATA_ATTR:md,ARIA_ATTR:vd,IS_SCRIPT_OR_DATA:_d,ATTR_WHITESPACE:Ea,CUSTOM_ELEMENT:yd}=al;let{IS_ALLOWED_URI:Aa}=al,me=null;const Ta=F({},[...sl,...Gi,...Vi,...qi,...rl]);let ke=null;const Ia=F({},[...il,...Ki,...ol,...kr]);let le=Object.seal(Cr(null,{tagNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeNameCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},allowCustomizedBuiltInElements:{writable:!0,configurable:!1,enumerable:!0,value:!1}})),Xn=null,er=null;const yt=Object.seal(Cr(null,{tagCheck:{writable:!0,configurable:!1,enumerable:!0,value:null},attributeCheck:{writable:!0,configurable:!1,enumerable:!0,value:null}}));let Ca=!0,vi=!0,za=!1,$a=!0,dn=!1,tr=!0,Lt=!1,_i=!1,yi=!1,pn=!1,nr=!1,sr=!1,Ra=!0,Pa=!1;const kd="user-content-";let ki=!0,Jn=!1,fn={},Xe=null;const wi=F({},["annotation-xml","audio","colgroup","desc","foreignobject","head","iframe","math","mi","mn","mo","ms","mtext","noembed","noframes","noscript","plaintext","script","style","svg","template","thead","title","video","xmp"]);let Da=null;const La=F({},["audio","video","img","source","image","track"]);let bi=null;const Ma=F({},["alt","class","for","id","label","name","pattern","placeholder","role","summary","title","value","style","xmlns"]),rr="http://www.w3.org/1998/Math/MathML",ir="http://www.w3.org/2000/svg",it="http://www.w3.org/1999/xhtml";let gn=it,Si=!1,xi=null;const wd=F({},[rr,ir,it],Hi);let or=F({},["mi","mo","mn","ms","mtext"]),ar=F({},["annotation-xml"]);const bd=F({},["title","style","font","a","script"]);let Qn=null;const Sd=["application/xhtml+xml","text/html"],xd="text/html";let fe=null,mn=null;const Ed=n.createElement("form"),Oa=function(g){return g instanceof RegExp||g instanceof Function},Ei=function(){let g=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};if(!(mn&&mn===g)){if((!g||typeof g!="object")&&(g={}),g=Qe(g),Qn=Sd.indexOf(g.PARSER_MEDIA_TYPE)===-1?xd:g.PARSER_MEDIA_TYPE,fe=Qn==="application/xhtml+xml"?Hi:zr,me=Oe(g,"ALLOWED_TAGS")?F({},g.ALLOWED_TAGS,fe):Ta,ke=Oe(g,"ALLOWED_ATTR")?F({},g.ALLOWED_ATTR,fe):Ia,xi=Oe(g,"ALLOWED_NAMESPACES")?F({},g.ALLOWED_NAMESPACES,Hi):wd,bi=Oe(g,"ADD_URI_SAFE_ATTR")?F(Qe(Ma),g.ADD_URI_SAFE_ATTR,fe):Ma,Da=Oe(g,"ADD_DATA_URI_TAGS")?F(Qe(La),g.ADD_DATA_URI_TAGS,fe):La,Xe=Oe(g,"FORBID_CONTENTS")?F({},g.FORBID_CONTENTS,fe):wi,Xn=Oe(g,"FORBID_TAGS")?F({},g.FORBID_TAGS,fe):Qe({}),er=Oe(g,"FORBID_ATTR")?F({},g.FORBID_ATTR,fe):Qe({}),fn=Oe(g,"USE_PROFILES")?g.USE_PROFILES:!1,Ca=g.ALLOW_ARIA_ATTR!==!1,vi=g.ALLOW_DATA_ATTR!==!1,za=g.ALLOW_UNKNOWN_PROTOCOLS||!1,$a=g.ALLOW_SELF_CLOSE_IN_ATTR!==!1,dn=g.SAFE_FOR_TEMPLATES||!1,tr=g.SAFE_FOR_XML!==!1,Lt=g.WHOLE_DOCUMENT||!1,pn=g.RETURN_DOM||!1,nr=g.RETURN_DOM_FRAGMENT||!1,sr=g.RETURN_TRUSTED_TYPE||!1,yi=g.FORCE_BODY||!1,Ra=g.SANITIZE_DOM!==!1,Pa=g.SANITIZE_NAMED_PROPS||!1,ki=g.KEEP_CONTENT!==!1,Jn=g.IN_PLACE||!1,Aa=g.ALLOWED_URI_REGEXP||Vh,gn=g.NAMESPACE||it,or=g.MATHML_TEXT_INTEGRATION_POINTS||or,ar=g.HTML_INTEGRATION_POINTS||ar,le=g.CUSTOM_ELEMENT_HANDLING||{},g.CUSTOM_ELEMENT_HANDLING&&Oa(g.CUSTOM_ELEMENT_HANDLING.tagNameCheck)&&(le.tagNameCheck=g.CUSTOM_ELEMENT_HANDLING.tagNameCheck),g.CUSTOM_ELEMENT_HANDLING&&Oa(g.CUSTOM_ELEMENT_HANDLING.attributeNameCheck)&&(le.attributeNameCheck=g.CUSTOM_ELEMENT_HANDLING.attributeNameCheck),g.CUSTOM_ELEMENT_HANDLING&&typeof g.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements=="boolean"&&(le.allowCustomizedBuiltInElements=g.CUSTOM_ELEMENT_HANDLING.allowCustomizedBuiltInElements),dn&&(vi=!1),nr&&(pn=!0),fn&&(me=F({},rl),ke=Cr(null),fn.html===!0&&(F(me,sl),F(ke,il)),fn.svg===!0&&(F(me,Gi),F(ke,Ki),F(ke,kr)),fn.svgFilters===!0&&(F(me,Vi),F(ke,Ki),F(ke,kr)),fn.mathMl===!0&&(F(me,qi),F(ke,ol),F(ke,kr))),Oe(g,"ADD_TAGS")||(yt.tagCheck=null),Oe(g,"ADD_ATTR")||(yt.attributeCheck=null),g.ADD_TAGS&&(typeof g.ADD_TAGS=="function"?yt.tagCheck=g.ADD_TAGS:(me===Ta&&(me=Qe(me)),F(me,g.ADD_TAGS,fe))),g.ADD_ATTR&&(typeof g.ADD_ATTR=="function"?yt.attributeCheck=g.ADD_ATTR:(ke===Ia&&(ke=Qe(ke)),F(ke,g.ADD_ATTR,fe))),g.ADD_URI_SAFE_ATTR&&F(bi,g.ADD_URI_SAFE_ATTR,fe),g.FORBID_CONTENTS&&(Xe===wi&&(Xe=Qe(Xe)),F(Xe,g.FORBID_CONTENTS,fe)),g.ADD_FORBID_CONTENTS&&(Xe===wi&&(Xe=Qe(Xe)),F(Xe,g.ADD_FORBID_CONTENTS,fe)),ki&&(me["#text"]=!0),Lt&&F(me,["html","head","body"]),me.table&&(F(me,["tbody"]),delete Xn.tbody),g.TRUSTED_TYPES_POLICY){if(typeof g.TRUSTED_TYPES_POLICY.createHTML!="function")throw is('TRUSTED_TYPES_POLICY configuration option must provide a "createHTML" hook.');if(typeof g.TRUSTED_TYPES_POLICY.createScriptURL!="function")throw is('TRUSTED_TYPES_POLICY configuration option must provide a "createScriptURL" hook.');M=g.TRUSTED_TYPES_POLICY,V=M.createHTML("")}else M===void 0&&(M=NS(v,r)),M!==null&&typeof V=="string"&&(V=M.createHTML(""));$e&&$e(g),mn=g}},Na=F({},[...Gi,...Vi,...TS]),Wa=F({},[...qi,...IS]),Ad=function(g){let A=ye(g);(!A||!A.tagName)&&(A={namespaceURI:gn,tagName:"template"});const $=zr(g.tagName),ee=zr(A.tagName);return xi[g.namespaceURI]?g.namespaceURI===ir?A.namespaceURI===it?$==="svg":A.namespaceURI===rr?$==="svg"&&(ee==="annotation-xml"||or[ee]):!!Na[$]:g.namespaceURI===rr?A.namespaceURI===it?$==="math":A.namespaceURI===ir?$==="math"&&ar[ee]:!!Wa[$]:g.namespaceURI===it?A.namespaceURI===ir&&!ar[ee]||A.namespaceURI===rr&&!or[ee]?!1:!Wa[$]&&(bd[$]||!Na[$]):!!(Qn==="application/xhtml+xml"&&xi[g.namespaceURI]):!1},Je=function(g){ss(t.removed,{element:g});try{ye(g).removeChild(g)}catch{z(g)}},Mt=function(g,A){try{ss(t.removed,{attribute:A.getAttributeNode(g),from:A})}catch{ss(t.removed,{attribute:null,from:A})}if(A.removeAttribute(g),g==="is")if(pn||nr)try{Je(A)}catch{}else try{A.setAttribute(g,"")}catch{}},Fa=function(g){let A=null,$=null;if(yi)g="<remove></remove>"+g;else{const he=Bi(g,/^[\r\n\t ]+/);$=he&&he[0]}Qn==="application/xhtml+xml"&&gn===it&&(g='<html xmlns="http://www.w3.org/1999/xhtml"><head></head><body>'+g+"</body></html>");const ee=M?M.createHTML(g):g;if(gn===it)try{A=new w().parseFromString(ee,Qn)}catch{}if(!A||!A.documentElement){A=U.createDocument(gn,"template",null);try{A.documentElement.innerHTML=Si?V:ee}catch{}}const Ee=A.body||A.documentElement;return g&&$&&Ee.insertBefore(n.createTextNode($),Ee.childNodes[0]||null),gn===it?Kn.call(A,Lt?"html":"body")[0]:Lt?A.documentElement:Ee},Ua=function(g){return Te.call(g.ownerDocument||g,g,l.SHOW_ELEMENT|l.SHOW_COMMENT|l.SHOW_TEXT|l.SHOW_PROCESSING_INSTRUCTION|l.SHOW_CDATA_SECTION,null)},Ai=function(g){return g instanceof f&&(typeof g.nodeName!="string"||typeof g.textContent!="string"||typeof g.removeChild!="function"||!(g.attributes instanceof h)||typeof g.removeAttribute!="function"||typeof g.setAttribute!="function"||typeof g.namespaceURI!="string"||typeof g.insertBefore!="function"||typeof g.hasChildNodes!="function")},Za=function(g){return typeof a=="function"&&g instanceof a};function ot(D,g,A){yr(D,$=>{$.call(t,g,A,mn)})}const ja=function(g){let A=null;if(ot(xe.beforeSanitizeElements,g,null),Ai(g))return Je(g),!0;const $=fe(g.nodeName);if(ot(xe.uponSanitizeElement,g,{tagName:$,allowedTags:me}),tr&&g.hasChildNodes()&&!Za(g.firstElementChild)&&Ie(/<[/\w!]/g,g.innerHTML)&&Ie(/<[/\w!]/g,g.textContent)||g.nodeType===as.progressingInstruction||tr&&g.nodeType===as.comment&&Ie(/<[/\w]/g,g.data))return Je(g),!0;if(!(yt.tagCheck instanceof Function&&yt.tagCheck($))&&(!me[$]||Xn[$])){if(!Xn[$]&&Ba($)&&(le.tagNameCheck instanceof RegExp&&Ie(le.tagNameCheck,$)||le.tagNameCheck instanceof Function&&le.tagNameCheck($)))return!1;if(ki&&!Xe[$]){const ee=ye(g)||g.parentNode,Ee=Z(g)||g.childNodes;if(Ee&&ee){const he=Ee.length;for(let Pe=he-1;Pe>=0;--Pe){const at=S(Ee[Pe],!0);at.__removalCount=(g.__removalCount||0)+1,ee.insertBefore(at,q(g))}}}return Je(g),!0}return g instanceof c&&!Ad(g)||($==="noscript"||$==="noembed"||$==="noframes")&&Ie(/<\/no(script|embed|frames)/i,g.innerHTML)?(Je(g),!0):(dn&&g.nodeType===as.text&&(A=g.textContent,yr([Yn,gi,mi],ee=>{A=rs(A,ee," ")}),g.textContent!==A&&(ss(t.removed,{element:g.cloneNode()}),g.textContent=A)),ot(xe.afterSanitizeElements,g,null),!1)},Ha=function(g,A,$){if(er[A]||Ra&&(A==="id"||A==="name")&&($ in n||$ in Ed))return!1;if(!(vi&&!er[A]&&Ie(md,A))){if(!(Ca&&Ie(vd,A))){if(!(yt.attributeCheck instanceof Function&&yt.attributeCheck(A,g))){if(!ke[A]||er[A]){if(!(Ba(g)&&(le.tagNameCheck instanceof RegExp&&Ie(le.tagNameCheck,g)||le.tagNameCheck instanceof Function&&le.tagNameCheck(g))&&(le.attributeNameCheck instanceof RegExp&&Ie(le.attributeNameCheck,A)||le.attributeNameCheck instanceof Function&&le.attributeNameCheck(A,g))||A==="is"&&le.allowCustomizedBuiltInElements&&(le.tagNameCheck instanceof RegExp&&Ie(le.tagNameCheck,$)||le.tagNameCheck instanceof Function&&le.tagNameCheck($))))return!1}else if(!bi[A]){if(!Ie(Aa,rs($,Ea,""))){if(!((A==="src"||A==="xlink:href"||A==="href")&&g!=="script"&&SS($,"data:")===0&&Da[g])){if(!(za&&!Ie(_d,rs($,Ea,"")))){if($)return!1}}}}}}}return!0},Ba=function(g){return g!=="annotation-xml"&&Bi(g,yd)},Ga=function(g){ot(xe.beforeSanitizeAttributes,g,null);const{attributes:A}=g;if(!A||Ai(g))return;const $={attrName:"",attrValue:"",keepAttr:!0,allowedAttributes:ke,forceKeepAttr:void 0};let ee=A.length;for(;ee--;){const Ee=A[ee],{name:he,namespaceURI:Pe,value:at}=Ee,vn=fe(he),Ti=at;let we=he==="value"?Ti:xS(Ti);if($.attrName=vn,$.attrValue=we,$.keepAttr=!0,$.forceKeepAttr=void 0,ot(xe.uponSanitizeAttribute,g,$),we=$.attrValue,Pa&&(vn==="id"||vn==="name")&&(Mt(he,g),we=kd+we),tr&&Ie(/((--!?|])>)|<\/(style|script|title|xmp|textarea|noscript|iframe|noembed|noframes)/i,we)){Mt(he,g);continue}if(vn==="attributename"&&Bi(we,"href")){Mt(he,g);continue}if($.forceKeepAttr)continue;if(!$.keepAttr){Mt(he,g);continue}if(!$a&&Ie(/\/>/i,we)){Mt(he,g);continue}dn&&yr([Yn,gi,mi],qa=>{we=rs(we,qa," ")});const Va=fe(g.nodeName);if(!Ha(Va,vn,we)){Mt(he,g);continue}if(M&&typeof v=="object"&&typeof v.getAttributeType=="function"&&!Pe)switch(v.getAttributeType(Va,vn)){case"TrustedHTML":{we=M.createHTML(we);break}case"TrustedScriptURL":{we=M.createScriptURL(we);break}}if(we!==Ti)try{Pe?g.setAttributeNS(Pe,he,we):g.setAttribute(he,we),Ai(g)?Je(g):nl(t.removed)}catch{Mt(he,g)}}ot(xe.afterSanitizeAttributes,g,null)},Td=function D(g){let A=null;const $=Ua(g);for(ot(xe.beforeSanitizeShadowDOM,g,null);A=$.nextNode();)ot(xe.uponSanitizeShadowNode,A,null),ja(A),Ga(A),A.content instanceof i&&D(A.content);ot(xe.afterSanitizeShadowDOM,g,null)};return t.sanitize=function(D){let g=arguments.length>1&&arguments[1]!==void 0?arguments[1]:{},A=null,$=null,ee=null,Ee=null;if(Si=!D,Si&&(D="<!-->"),typeof D!="string"&&!Za(D))if(typeof D.toString=="function"){if(D=D.toString(),typeof D!="string")throw is("dirty is not a string, aborting")}else throw is("toString is not a function");if(!t.isSupported)return D;if(_i||Ei(g),t.removed=[],typeof D=="string"&&(Jn=!1),Jn){if(D.nodeName){const at=fe(D.nodeName);if(!me[at]||Xn[at])throw is("root node is forbidden and cannot be sanitized in-place")}}else if(D instanceof a)A=Fa("<!---->"),$=A.ownerDocument.importNode(D,!0),$.nodeType===as.element&&$.nodeName==="BODY"||$.nodeName==="HTML"?A=$:A.appendChild($);else{if(!pn&&!dn&&!Lt&&D.indexOf("<")===-1)return M&&sr?M.createHTML(D):D;if(A=Fa(D),!A)return pn?null:sr?V:""}A&&yi&&Je(A.firstChild);const he=Ua(Jn?D:A);for(;ee=he.nextNode();)ja(ee),Ga(ee),ee.content instanceof i&&Td(ee.content);if(Jn)return D;if(pn){if(nr)for(Ee=X.call(A.ownerDocument);A.firstChild;)Ee.appendChild(A.firstChild);else Ee=A;return(ke.shadowroot||ke.shadowrootmode)&&(Ee=hn.call(s,Ee,!0)),Ee}let Pe=Lt?A.outerHTML:A.innerHTML;return Lt&&me["!doctype"]&&A.ownerDocument&&A.ownerDocument.doctype&&A.ownerDocument.doctype.name&&Ie(qh,A.ownerDocument.doctype.name)&&(Pe="<!DOCTYPE "+A.ownerDocument.doctype.name+`>
256
- `+Pe),dn&&yr([Yn,gi,mi],at=>{Pe=rs(Pe,at," ")}),M&&sr?M.createHTML(Pe):Pe},t.setConfig=function(){let D=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{};Ei(D),_i=!0},t.clearConfig=function(){mn=null,_i=!1},t.isValidAttribute=function(D,g,A){mn||Ei({});const $=fe(D),ee=fe(g);return Ha($,ee,A)},t.addHook=function(D,g){typeof g=="function"&&ss(xe[D],g)},t.removeHook=function(D,g){if(g!==void 0){const A=wS(xe[D],g);return A===-1?void 0:bS(xe[D],A,1)[0]}return nl(xe[D])},t.removeHooks=function(D){xe[D]=[]},t.removeAllHooks=function(){xe=cl()},t}var Yh=Kh();function aa(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var un=aa();function Xh(e){un=e}var Ht={exec:()=>null};function j(e,t=""){let n=typeof e=="string"?e:e.source,s={replace:(r,i)=>{let o=typeof i=="string"?i:i.source;return o=o.replace(ze.caret,"$1"),n=n.replace(r,o),s},getRegex:()=>new RegExp(n,t)};return s}var WS=(()=>{try{return!!new RegExp("(?<=1)(?<!1)")}catch{return!1}})(),ze={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,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,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"),blockquoteBeginRegex:e=>new RegExp(`^ {0,${Math.min(3,e-1)}}>`)},FS=/^(?:[ \t]*(?:\n|$))+/,US=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,ZS=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,Qs=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,jS=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,ca=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,Jh=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,Qh=j(Jh).replace(/bull/g,ca).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(),HS=j(Jh).replace(/bull/g,ca).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(),la=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,BS=/^[^\n]+/,ua=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,GS=j(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",ua).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),VS=j(/^(bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,ca).getRegex(),di="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",ha=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,qS=j("^ {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",ha).replace("tag",di).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),ed=j(la).replace("hr",Qs).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[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",di).getRegex(),KS=j(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",ed).getRegex(),da={blockquote:KS,code:US,def:GS,fences:ZS,heading:jS,hr:Qs,html:qS,lheading:Qh,list:VS,newline:FS,paragraph:ed,table:Ht,text:BS},ll=j("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",Qs).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[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",di).getRegex(),YS={...da,lheading:HS,table:ll,paragraph:j(la).replace("hr",Qs).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",ll).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)])[ \\t]").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",di).getRegex()},XS={...da,html:j(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",ha).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:Ht,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:j(la).replace("hr",Qs).replace("heading",` *#{1,6} *[^
257
- ]`).replace("lheading",Qh).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},JS=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,QS=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,td=/^( {2,}|\\)\n(?!\s*$)/,e0=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,qn=/[\p{P}\p{S}]/u,pi=/[\s\p{P}\p{S}]/u,pa=/[^\s\p{P}\p{S}]/u,t0=j(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,pi).getRegex(),nd=/(?!~)[\p{P}\p{S}]/u,n0=/(?!~)[\s\p{P}\p{S}]/u,s0=/(?:[^\s\p{P}\p{S}]|~)/u,r0=j(/link|precode-code|html/,"g").replace("link",/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace("precode-",WS?"(?<!`)()":"(^^|[^`])").replace("code",/(?<b>`+)[^`]+\k<b>(?!`)/).replace("html",/<(?! )[^<>]*?>/).getRegex(),sd=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,i0=j(sd,"u").replace(/punct/g,qn).getRegex(),o0=j(sd,"u").replace(/punct/g,nd).getRegex(),rd="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",a0=j(rd,"gu").replace(/notPunctSpace/g,pa).replace(/punctSpace/g,pi).replace(/punct/g,qn).getRegex(),c0=j(rd,"gu").replace(/notPunctSpace/g,s0).replace(/punctSpace/g,n0).replace(/punct/g,nd).getRegex(),l0=j("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,pa).replace(/punctSpace/g,pi).replace(/punct/g,qn).getRegex(),u0=j(/^~~?(?:((?!~)punct)|[^\s~])/,"u").replace(/punct/g,qn).getRegex(),h0="^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)",d0=j(h0,"gu").replace(/notPunctSpace/g,pa).replace(/punctSpace/g,pi).replace(/punct/g,qn).getRegex(),p0=j(/\\(punct)/,"gu").replace(/punct/g,qn).getRegex(),f0=j(/^<(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(),g0=j(ha).replace("(?:-->|$)","-->").getRegex(),m0=j("^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",g0).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),jr=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,v0=j(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace("label",jr).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),id=j(/^!?\[(label)\]\[(ref)\]/).replace("label",jr).replace("ref",ua).getRegex(),od=j(/^!?\[(ref)\](?:\[\])?/).replace("ref",ua).getRegex(),_0=j("reflink|nolink(?!\\()","g").replace("reflink",id).replace("nolink",od).getRegex(),ul=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,fa={_backpedal:Ht,anyPunctuation:p0,autolink:f0,blockSkip:r0,br:td,code:QS,del:Ht,delLDelim:Ht,delRDelim:Ht,emStrongLDelim:i0,emStrongRDelimAst:a0,emStrongRDelimUnd:l0,escape:JS,link:v0,nolink:od,punctuation:t0,reflink:id,reflinkSearch:_0,tag:m0,text:e0,url:Ht},y0={...fa,link:j(/^!?\[(label)\]\((.*?)\)/).replace("label",jr).getRegex(),reflink:j(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",jr).getRegex()},Oo={...fa,emStrongRDelimAst:c0,emStrongLDelim:o0,delLDelim:u0,delRDelim:d0,url:j(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace("protocol",ul).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:j(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace("protocol",ul).getRegex()},k0={...Oo,br:j(td).replace("{2,}","*").getRegex(),text:j(Oo.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},wr={normal:da,gfm:YS,pedantic:XS},cs={normal:fa,gfm:Oo,breaks:k0,pedantic:y0},w0={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"},hl=e=>w0[e];function et(e,t){if(t){if(ze.escapeTest.test(e))return e.replace(ze.escapeReplace,hl)}else if(ze.escapeTestNoEncode.test(e))return e.replace(ze.escapeReplaceNoEncode,hl);return e}function dl(e){try{e=encodeURI(e).replace(ze.percentDecode,"%")}catch{return null}return e}function pl(e,t){var i;let n=e.replace(ze.findPipe,(o,a,c)=>{let l=!1,h=a;for(;--h>=0&&c[h]==="\\";)l=!l;return l?"|":" |"}),s=n.split(ze.splitPipe),r=0;if(s[0].trim()||s.shift(),s.length>0&&!((i=s.at(-1))!=null&&i.trim())&&s.pop(),t)if(s.length>t)s.splice(t);else for(;s.length<t;)s.push("");for(;r<s.length;r++)s[r]=s[r].trim().replace(ze.slashPipe,"|");return s}function ls(e,t,n){let s=e.length;if(s===0)return"";let r=0;for(;r<s&&e.charAt(s-r-1)===t;)r++;return e.slice(0,s-r)}function b0(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let s=0;s<e.length;s++)if(e[s]==="\\")s++;else if(e[s]===t[0])n++;else if(e[s]===t[1]&&(n--,n<0))return s;return n>0?-2:-1}function S0(e,t=0){let n=t,s="";for(let r of e)if(r===" "){let i=4-n%4;s+=" ".repeat(i),n+=i}else s+=r,n++;return s}function fl(e,t,n,s,r){let i=t.href,o=t.title||null,a=e[1].replace(r.other.outputLinkReplace,"$1");s.state.inLink=!0;let c={type:e[0].charAt(0)==="!"?"image":"link",raw:n,href:i,title:o,text:a,tokens:s.inlineTokens(a)};return s.state.inLink=!1,c}function x0(e,t,n){let s=e.match(n.other.indentCodeCompensation);if(s===null)return t;let r=s[1];return t.split(`
258
- `).map(i=>{let o=i.match(n.other.beginningSpace);if(o===null)return i;let[a]=o;return a.length>=r.length?i.slice(r.length):i}).join(`
259
- `)}var Hr=class{constructor(e){m(this,"options");m(this,"rules");m(this,"lexer");this.options=e||un}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:ls(n,`
260
- `)}}}fences(e){let t=this.rules.block.fences.exec(e);if(t){let n=t[0],s=x0(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:s}}}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 s=ls(n,"#");(this.options.pedantic||!s||this.rules.other.endingSpaceChar.test(s))&&(n=s.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:ls(t[0],`
261
- `)}}blockquote(e){let t=this.rules.block.blockquote.exec(e);if(t){let n=ls(t[0],`
262
- `).split(`
263
- `),s="",r="",i=[];for(;n.length>0;){let o=!1,a=[],c;for(c=0;c<n.length;c++)if(this.rules.other.blockquoteStart.test(n[c]))a.push(n[c]),o=!0;else if(!o)a.push(n[c]);else break;n=n.slice(c);let l=a.join(`
264
- `),h=l.replace(this.rules.other.blockquoteSetextReplace,`
265
- $1`).replace(this.rules.other.blockquoteSetextReplace2,"");s=s?`${s}
266
- ${l}`:l,r=r?`${r}
267
- ${h}`:h;let f=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(h,i,!0),this.lexer.state.top=f,n.length===0)break;let w=i.at(-1);if((w==null?void 0:w.type)==="code")break;if((w==null?void 0:w.type)==="blockquote"){let v=w,E=v.raw+`
268
- `+n.join(`
269
- `),S=this.blockquote(E);i[i.length-1]=S,s=s.substring(0,s.length-v.raw.length)+S.raw,r=r.substring(0,r.length-v.text.length)+S.text;break}else if((w==null?void 0:w.type)==="list"){let v=w,E=v.raw+`
270
- `+n.join(`
271
- `),S=this.list(E);i[i.length-1]=S,s=s.substring(0,s.length-w.raw.length)+S.raw,r=r.substring(0,r.length-v.raw.length)+S.raw,n=E.substring(i.at(-1).raw.length).split(`
272
- `);continue}}return{type:"blockquote",raw:s,tokens:i,text:r}}}list(e){var n,s;let t=this.rules.block.list.exec(e);if(t){let r=t[1].trim(),i=r.length>1,o={type:"list",raw:"",ordered:i,start:i?+r.slice(0,-1):"",loose:!1,items:[]};r=i?`\\d{1,9}\\${r.slice(-1)}`:`\\${r}`,this.options.pedantic&&(r=i?r:"[*+-]");let a=this.rules.other.listItemRegex(r),c=!1;for(;e;){let h=!1,f="",w="";if(!(t=a.exec(e))||this.rules.block.hr.test(e))break;f=t[0],e=e.substring(f.length);let v=S0(t[2].split(`
273
- `,1)[0],t[1].length),E=e.split(`
274
- `,1)[0],S=!v.trim(),z=0;if(this.options.pedantic?(z=2,w=v.trimStart()):S?z=t[1].length+1:(z=v.search(this.rules.other.nonSpaceChar),z=z>4?1:z,w=v.slice(z),z+=t[1].length),S&&this.rules.other.blankLine.test(E)&&(f+=E+`
275
- `,e=e.substring(E.length+1),h=!0),!h){let q=this.rules.other.nextBulletRegex(z),Z=this.rules.other.hrRegex(z),ye=this.rules.other.fencesBeginRegex(z),M=this.rules.other.headingBeginRegex(z),V=this.rules.other.htmlBeginRegex(z),U=this.rules.other.blockquoteBeginRegex(z);for(;e;){let Te=e.split(`
276
- `,1)[0],X;if(E=Te,this.options.pedantic?(E=E.replace(this.rules.other.listReplaceNesting," "),X=E):X=E.replace(this.rules.other.tabCharGlobal," "),ye.test(E)||M.test(E)||V.test(E)||U.test(E)||q.test(E)||Z.test(E))break;if(X.search(this.rules.other.nonSpaceChar)>=z||!E.trim())w+=`
277
- `+X.slice(z);else{if(S||v.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||ye.test(v)||M.test(v)||Z.test(v))break;w+=`
278
- `+E}S=!E.trim(),f+=Te+`
279
- `,e=e.substring(Te.length+1),v=X.slice(z)}}o.loose||(c?o.loose=!0:this.rules.other.doubleBlankLine.test(f)&&(c=!0)),o.items.push({type:"list_item",raw:f,task:!!this.options.gfm&&this.rules.other.listIsTask.test(w),loose:!1,text:w,tokens:[]}),o.raw+=f}let l=o.items.at(-1);if(l)l.raw=l.raw.trimEnd(),l.text=l.text.trimEnd();else return;o.raw=o.raw.trimEnd();for(let h of o.items){if(this.lexer.state.top=!1,h.tokens=this.lexer.blockTokens(h.text,[]),h.task){if(h.text=h.text.replace(this.rules.other.listReplaceTask,""),((n=h.tokens[0])==null?void 0:n.type)==="text"||((s=h.tokens[0])==null?void 0:s.type)==="paragraph"){h.tokens[0].raw=h.tokens[0].raw.replace(this.rules.other.listReplaceTask,""),h.tokens[0].text=h.tokens[0].text.replace(this.rules.other.listReplaceTask,"");for(let w=this.lexer.inlineQueue.length-1;w>=0;w--)if(this.rules.other.listIsTask.test(this.lexer.inlineQueue[w].src)){this.lexer.inlineQueue[w].src=this.lexer.inlineQueue[w].src.replace(this.rules.other.listReplaceTask,"");break}}let f=this.rules.other.listTaskCheckbox.exec(h.raw);if(f){let w={type:"checkbox",raw:f[0]+" ",checked:f[0]!=="[ ]"};h.checked=w.checked,o.loose?h.tokens[0]&&["paragraph","text"].includes(h.tokens[0].type)&&"tokens"in h.tokens[0]&&h.tokens[0].tokens?(h.tokens[0].raw=w.raw+h.tokens[0].raw,h.tokens[0].text=w.raw+h.tokens[0].text,h.tokens[0].tokens.unshift(w)):h.tokens.unshift({type:"paragraph",raw:w.raw,text:w.raw,tokens:[w]}):h.tokens.unshift(w)}}if(!o.loose){let f=h.tokens.filter(v=>v.type==="space"),w=f.length>0&&f.some(v=>this.rules.other.anyLine.test(v.raw));o.loose=w}}if(o.loose)for(let h of o.items){h.loose=!0;for(let f of h.tokens)f.type==="text"&&(f.type="paragraph")}return o}}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," "),s=t[2]?t[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",r=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:s,title:r}}}table(e){var o;let t=this.rules.block.table.exec(e);if(!t||!this.rules.other.tableDelimiter.test(t[2]))return;let n=pl(t[1]),s=t[2].replace(this.rules.other.tableAlignChars,"").split("|"),r=(o=t[3])!=null&&o.trim()?t[3].replace(this.rules.other.tableRowBlankLine,"").split(`
280
- `):[],i={type:"table",raw:t[0],header:[],align:[],rows:[]};if(n.length===s.length){for(let a of s)this.rules.other.tableAlignRight.test(a)?i.align.push("right"):this.rules.other.tableAlignCenter.test(a)?i.align.push("center"):this.rules.other.tableAlignLeft.test(a)?i.align.push("left"):i.align.push(null);for(let a=0;a<n.length;a++)i.header.push({text:n[a],tokens:this.lexer.inline(n[a]),header:!0,align:i.align[a]});for(let a of r)i.rows.push(pl(a,i.header.length).map((c,l)=>({text:c,tokens:this.lexer.inline(c),header:!1,align:i.align[l]})));return i}}lheading(e){let t=this.rules.block.lheading.exec(e);if(t){let n=t[1].trim();return{type:"heading",raw:t[0],depth:t[2].charAt(0)==="="?1:2,text:n,tokens:this.lexer.inline(n)}}}paragraph(e){let t=this.rules.block.paragraph.exec(e);if(t){let n=t[1].charAt(t[1].length-1)===`
281
- `?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 i=ls(n.slice(0,-1),"\\");if((n.length-i.length)%2===0)return}else{let i=b0(t[2],"()");if(i===-2)return;if(i>-1){let o=(t[0].indexOf("!")===0?5:4)+t[1].length+i;t[2]=t[2].substring(0,i),t[0]=t[0].substring(0,o).trim(),t[3]=""}}let s=t[2],r="";if(this.options.pedantic){let i=this.rules.other.pedanticHrefTitle.exec(s);i&&(s=i[1],r=i[3])}else r=t[3]?t[3].slice(1,-1):"";return s=s.trim(),this.rules.other.startAngleBracket.test(s)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(n)?s=s.slice(1):s=s.slice(1,-1)),fl(t,{href:s&&s.replace(this.rules.inline.anyPunctuation,"$1"),title:r&&r.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 s=(n[2]||n[1]).replace(this.rules.other.multipleSpaceGlobal," "),r=t[s.toLowerCase()];if(!r){let i=n[0].charAt(0);return{type:"text",raw:i,text:i}}return fl(n,r,n[0],this.lexer,this.rules)}}emStrong(e,t,n=""){let s=this.rules.inline.emStrongLDelim.exec(e);if(!(!s||!s[1]&&!s[2]&&!s[3]&&!s[4]||s[4]&&n.match(this.rules.other.unicodeAlphaNumeric))&&(!(s[1]||s[3])||!n||this.rules.inline.punctuation.exec(n))){let r=[...s[0]].length-1,i,o,a=r,c=0,l=s[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(l.lastIndex=0,t=t.slice(-1*e.length+r);(s=l.exec(t))!=null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i)continue;if(o=[...i].length,s[3]||s[4]){a+=o;continue}else if((s[5]||s[6])&&r%3&&!((r+o)%3)){c+=o;continue}if(a-=o,a>0)continue;o=Math.min(o,o+a+c);let h=[...s[0]][0].length,f=e.slice(0,r+s.index+h+o);if(Math.min(r,o)%2){let v=f.slice(1,-1);return{type:"em",raw:f,text:v,tokens:this.lexer.inlineTokens(v)}}let w=f.slice(2,-2);return{type:"strong",raw:f,text:w,tokens:this.lexer.inlineTokens(w)}}}}codespan(e){let t=this.rules.inline.code.exec(e);if(t){let n=t[2].replace(this.rules.other.newLineCharGlobal," "),s=this.rules.other.nonSpaceChar.test(n),r=this.rules.other.startingSpaceChar.test(n)&&this.rules.other.endingSpaceChar.test(n);return s&&r&&(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,t,n=""){let s=this.rules.inline.delLDelim.exec(e);if(s&&(!s[1]||!n||this.rules.inline.punctuation.exec(n))){let r=[...s[0]].length-1,i,o,a=r,c=this.rules.inline.delRDelim;for(c.lastIndex=0,t=t.slice(-1*e.length+r);(s=c.exec(t))!=null;){if(i=s[1]||s[2]||s[3]||s[4]||s[5]||s[6],!i||(o=[...i].length,o!==r))continue;if(s[3]||s[4]){a+=o;continue}if(a-=o,a>0)continue;o=Math.min(o,o+a);let l=[...s[0]][0].length,h=e.slice(0,r+s.index+l+o),f=h.slice(r,-r);return{type:"del",raw:h,text:f,tokens:this.lexer.inlineTokens(f)}}}}autolink(e){let t=this.rules.inline.autolink.exec(e);if(t){let n,s;return t[2]==="@"?(n=t[1],s="mailto:"+n):(n=t[1],s=n),{type:"link",raw:t[0],text:n,href:s,tokens:[{type:"text",raw:n,text:n}]}}}url(e){var n;let t;if(t=this.rules.inline.url.exec(e)){let s,r;if(t[2]==="@")s=t[0],r="mailto:"+s;else{let i;do i=t[0],t[0]=((n=this.rules.inline._backpedal.exec(t[0]))==null?void 0:n[0])??"";while(i!==t[0]);s=t[0],t[1]==="www."?r="http://"+t[0]:r=t[0]}return{type:"link",raw:t[0],text:s,href:r,tokens:[{type:"text",raw:s,text:s}]}}}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 No{constructor(t){m(this,"tokens");m(this,"options");m(this,"state");m(this,"inlineQueue");m(this,"tokenizer");this.tokens=[],this.tokens.links=Object.create(null),this.options=t||un,this.options.tokenizer=this.options.tokenizer||new Hr,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:ze,block:wr.normal,inline:cs.normal};this.options.pedantic?(n.block=wr.pedantic,n.inline=cs.pedantic):this.options.gfm&&(n.block=wr.gfm,this.options.breaks?n.inline=cs.breaks:n.inline=cs.gfm),this.tokenizer.rules=n}static get rules(){return{block:wr,inline:cs}}static lex(t,n){return new No(n).lex(t)}static lexInline(t,n){return new No(n).inlineTokens(t)}lex(t){t=t.replace(ze.carriageReturn,`
282
- `),this.blockTokens(t,this.tokens);for(let n=0;n<this.inlineQueue.length;n++){let s=this.inlineQueue[n];this.inlineTokens(s.src,s.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(t,n=[],s=!1){var r,i,o;for(this.tokenizer.lexer=this,this.options.pedantic&&(t=t.replace(ze.tabCharGlobal," ").replace(ze.spaceLine,""));t;){let a;if((i=(r=this.options.extensions)==null?void 0:r.block)!=null&&i.some(l=>(a=l.call({lexer:this},t,n))?(t=t.substring(a.raw.length),n.push(a),!0):!1))continue;if(a=this.tokenizer.space(t)){t=t.substring(a.raw.length);let l=n.at(-1);a.raw.length===1&&l!==void 0?l.raw+=`
283
- `:n.push(a);continue}if(a=this.tokenizer.code(t)){t=t.substring(a.raw.length);let l=n.at(-1);(l==null?void 0:l.type)==="paragraph"||(l==null?void 0:l.type)==="text"?(l.raw+=(l.raw.endsWith(`
284
- `)?"":`
285
- `)+a.raw,l.text+=`
286
- `+a.text,this.inlineQueue.at(-1).src=l.text):n.push(a);continue}if(a=this.tokenizer.fences(t)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.heading(t)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.hr(t)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.blockquote(t)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.list(t)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.html(t)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.def(t)){t=t.substring(a.raw.length);let l=n.at(-1);(l==null?void 0:l.type)==="paragraph"||(l==null?void 0:l.type)==="text"?(l.raw+=(l.raw.endsWith(`
287
- `)?"":`
288
- `)+a.raw,l.text+=`
289
- `+a.raw,this.inlineQueue.at(-1).src=l.text):this.tokens.links[a.tag]||(this.tokens.links[a.tag]={href:a.href,title:a.title},n.push(a));continue}if(a=this.tokenizer.table(t)){t=t.substring(a.raw.length),n.push(a);continue}if(a=this.tokenizer.lheading(t)){t=t.substring(a.raw.length),n.push(a);continue}let c=t;if((o=this.options.extensions)!=null&&o.startBlock){let l=1/0,h=t.slice(1),f;this.options.extensions.startBlock.forEach(w=>{f=w.call({lexer:this},h),typeof f=="number"&&f>=0&&(l=Math.min(l,f))}),l<1/0&&l>=0&&(c=t.substring(0,l+1))}if(this.state.top&&(a=this.tokenizer.paragraph(c))){let l=n.at(-1);s&&(l==null?void 0:l.type)==="paragraph"?(l.raw+=(l.raw.endsWith(`
290
- `)?"":`
291
- `)+a.raw,l.text+=`
292
- `+a.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=l.text):n.push(a),s=c.length!==t.length,t=t.substring(a.raw.length);continue}if(a=this.tokenizer.text(t)){t=t.substring(a.raw.length);let l=n.at(-1);(l==null?void 0:l.type)==="text"?(l.raw+=(l.raw.endsWith(`
293
- `)?"":`
294
- `)+a.raw,l.text+=`
295
- `+a.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=l.text):n.push(a);continue}if(t){let l="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(l);break}else throw new Error(l)}}return this.state.top=!0,n}inline(t,n=[]){return this.inlineQueue.push({src:t,tokens:n}),n}inlineTokens(t,n=[]){var c,l,h,f,w;this.tokenizer.lexer=this;let s=t,r=null;if(this.tokens.links){let v=Object.keys(this.tokens.links);if(v.length>0)for(;(r=this.tokenizer.rules.inline.reflinkSearch.exec(s))!=null;)v.includes(r[0].slice(r[0].lastIndexOf("[")+1,-1))&&(s=s.slice(0,r.index)+"["+"a".repeat(r[0].length-2)+"]"+s.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(r=this.tokenizer.rules.inline.anyPunctuation.exec(s))!=null;)s=s.slice(0,r.index)+"++"+s.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);let i;for(;(r=this.tokenizer.rules.inline.blockSkip.exec(s))!=null;)i=r[2]?r[2].length:0,s=s.slice(0,r.index+i)+"["+"a".repeat(r[0].length-i-2)+"]"+s.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);s=((l=(c=this.options.hooks)==null?void 0:c.emStrongMask)==null?void 0:l.call({lexer:this},s))??s;let o=!1,a="";for(;t;){o||(a=""),o=!1;let v;if((f=(h=this.options.extensions)==null?void 0:h.inline)!=null&&f.some(S=>(v=S.call({lexer:this},t,n))?(t=t.substring(v.raw.length),n.push(v),!0):!1))continue;if(v=this.tokenizer.escape(t)){t=t.substring(v.raw.length),n.push(v);continue}if(v=this.tokenizer.tag(t)){t=t.substring(v.raw.length),n.push(v);continue}if(v=this.tokenizer.link(t)){t=t.substring(v.raw.length),n.push(v);continue}if(v=this.tokenizer.reflink(t,this.tokens.links)){t=t.substring(v.raw.length);let S=n.at(-1);v.type==="text"&&(S==null?void 0:S.type)==="text"?(S.raw+=v.raw,S.text+=v.text):n.push(v);continue}if(v=this.tokenizer.emStrong(t,s,a)){t=t.substring(v.raw.length),n.push(v);continue}if(v=this.tokenizer.codespan(t)){t=t.substring(v.raw.length),n.push(v);continue}if(v=this.tokenizer.br(t)){t=t.substring(v.raw.length),n.push(v);continue}if(v=this.tokenizer.del(t,s,a)){t=t.substring(v.raw.length),n.push(v);continue}if(v=this.tokenizer.autolink(t)){t=t.substring(v.raw.length),n.push(v);continue}if(!this.state.inLink&&(v=this.tokenizer.url(t))){t=t.substring(v.raw.length),n.push(v);continue}let E=t;if((w=this.options.extensions)!=null&&w.startInline){let S=1/0,z=t.slice(1),q;this.options.extensions.startInline.forEach(Z=>{q=Z.call({lexer:this},z),typeof q=="number"&&q>=0&&(S=Math.min(S,q))}),S<1/0&&S>=0&&(E=t.substring(0,S+1))}if(v=this.tokenizer.inlineText(E)){t=t.substring(v.raw.length),v.raw.slice(-1)!=="_"&&(a=v.raw.slice(-1)),o=!0;let S=n.at(-1);(S==null?void 0:S.type)==="text"?(S.raw+=v.raw,S.text+=v.text):n.push(v);continue}if(t){let S="Infinite loop on byte: "+t.charCodeAt(0);if(this.options.silent){console.error(S);break}else throw new Error(S)}}return n}},Br=class{constructor(e){m(this,"options");m(this,"parser");this.options=e||un}space(e){return""}code({text:e,lang:t,escaped:n}){var i;let s=(i=(t||"").match(ze.notSpaceStart))==null?void 0:i[0],r=e.replace(ze.endingNewline,"")+`
296
- `;return s?'<pre><code class="language-'+et(s)+'">'+(n?r:et(r,!0))+`</code></pre>
297
- `:"<pre><code>"+(n?r:et(r,!0))+`</code></pre>
298
- `}blockquote({tokens:e}){return`<blockquote>
299
- ${this.parser.parse(e)}</blockquote>
300
- `}html({text:e}){return e}def(e){return""}heading({tokens:e,depth:t}){return`<h${t}>${this.parser.parseInline(e)}</h${t}>
301
- `}hr(e){return`<hr>
302
- `}list(e){let t=e.ordered,n=e.start,s="";for(let o=0;o<e.items.length;o++){let a=e.items[o];s+=this.listitem(a)}let r=t?"ol":"ul",i=t&&n!==1?' start="'+n+'"':"";return"<"+r+i+`>
303
- `+s+"</"+r+`>
304
- `}listitem(e){return`<li>${this.parser.parse(e.tokens)}</li>
305
- `}checkbox({checked:e}){return"<input "+(e?'checked="" ':"")+'disabled="" type="checkbox"> '}paragraph({tokens:e}){return`<p>${this.parser.parseInline(e)}</p>
306
- `}table(e){let t="",n="";for(let r=0;r<e.header.length;r++)n+=this.tablecell(e.header[r]);t+=this.tablerow({text:n});let s="";for(let r=0;r<e.rows.length;r++){let i=e.rows[r];n="";for(let o=0;o<i.length;o++)n+=this.tablecell(i[o]);s+=this.tablerow({text:n})}return s&&(s=`<tbody>${s}</tbody>`),`<table>
307
- <thead>
308
- `+t+`</thead>
309
- `+s+`</table>
310
- `}tablerow({text:e}){return`<tr>
311
- ${e}</tr>
312
- `}tablecell(e){let t=this.parser.parseInline(e.tokens),n=e.header?"th":"td";return(e.align?`<${n} align="${e.align}">`:`<${n}>`)+t+`</${n}>
313
- `}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>${et(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 s=this.parser.parseInline(n),r=dl(e);if(r===null)return s;e=r;let i='<a href="'+e+'"';return t&&(i+=' title="'+et(t)+'"'),i+=">"+s+"</a>",i}image({href:e,title:t,text:n,tokens:s}){s&&(n=this.parser.parseInline(s,this.parser.textRenderer));let r=dl(e);if(r===null)return et(n);e=r;let i=`<img src="${e}" alt="${et(n)}"`;return t&&(i+=` title="${et(t)}"`),i+=">",i}text(e){return"tokens"in e&&e.tokens?this.parser.parseInline(e.tokens):"escaped"in e&&e.escaped?e.text:et(e.text)}},ga=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}},Ke=class Wo{constructor(t){m(this,"options");m(this,"renderer");m(this,"textRenderer");this.options=t||un,this.options.renderer=this.options.renderer||new Br,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new ga}static parse(t,n){return new Wo(n).parse(t)}static parseInline(t,n){return new Wo(n).parseInline(t)}parse(t){var s,r;this.renderer.parser=this;let n="";for(let i=0;i<t.length;i++){let o=t[i];if((r=(s=this.options.extensions)==null?void 0:s.renderers)!=null&&r[o.type]){let c=o,l=this.options.extensions.renderers[c.type].call({parser:this},c);if(l!==!1||!["space","hr","heading","code","table","blockquote","list","html","def","paragraph","text"].includes(c.type)){n+=l||"";continue}}let a=o;switch(a.type){case"space":{n+=this.renderer.space(a);break}case"hr":{n+=this.renderer.hr(a);break}case"heading":{n+=this.renderer.heading(a);break}case"code":{n+=this.renderer.code(a);break}case"table":{n+=this.renderer.table(a);break}case"blockquote":{n+=this.renderer.blockquote(a);break}case"list":{n+=this.renderer.list(a);break}case"checkbox":{n+=this.renderer.checkbox(a);break}case"html":{n+=this.renderer.html(a);break}case"def":{n+=this.renderer.def(a);break}case"paragraph":{n+=this.renderer.paragraph(a);break}case"text":{n+=this.renderer.text(a);break}default:{let c='Token with "'+a.type+'" type was not found.';if(this.options.silent)return console.error(c),"";throw new Error(c)}}}return n}parseInline(t,n=this.renderer){var r,i;this.renderer.parser=this;let s="";for(let o=0;o<t.length;o++){let a=t[o];if((i=(r=this.options.extensions)==null?void 0:r.renderers)!=null&&i[a.type]){let l=this.options.extensions.renderers[a.type].call({parser:this},a);if(l!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(a.type)){s+=l||"";continue}}let c=a;switch(c.type){case"escape":{s+=n.text(c);break}case"html":{s+=n.html(c);break}case"link":{s+=n.link(c);break}case"image":{s+=n.image(c);break}case"checkbox":{s+=n.checkbox(c);break}case"strong":{s+=n.strong(c);break}case"em":{s+=n.em(c);break}case"codespan":{s+=n.codespan(c);break}case"br":{s+=n.br(c);break}case"del":{s+=n.del(c);break}case"text":{s+=n.text(c);break}default:{let l='Token with "'+c.type+'" type was not found.';if(this.options.silent)return console.error(l),"";throw new Error(l)}}}return s}},br,ms=(br=class{constructor(e){m(this,"options");m(this,"block");this.options=e||un}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?Ke.parse:Ke.parseInline}},m(br,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens","emStrongMask"])),m(br,"passThroughHooksRespectAsync",new Set(["preprocess","postprocess","processAllTokens"])),br),E0=class{constructor(...e){m(this,"defaults",aa());m(this,"options",this.setOptions);m(this,"parse",this.parseMarkdown(!0));m(this,"parseInline",this.parseMarkdown(!1));m(this,"Parser",Ke);m(this,"Renderer",Br);m(this,"TextRenderer",ga);m(this,"Lexer",qe);m(this,"Tokenizer",Hr);m(this,"Hooks",ms);this.use(...e)}walkTokens(e,t){var s,r;let n=[];for(let i of e)switch(n=n.concat(t.call(this,i)),i.type){case"table":{let o=i;for(let a of o.header)n=n.concat(this.walkTokens(a.tokens,t));for(let a of o.rows)for(let c of a)n=n.concat(this.walkTokens(c.tokens,t));break}case"list":{let o=i;n=n.concat(this.walkTokens(o.items,t));break}default:{let o=i;(r=(s=this.defaults.extensions)==null?void 0:s.childTokens)!=null&&r[o.type]?this.defaults.extensions.childTokens[o.type].forEach(a=>{let c=o[a].flat(1/0);n=n.concat(this.walkTokens(c,t))}):o.tokens&&(n=n.concat(this.walkTokens(o.tokens,t)))}}return n}use(...e){let t=this.defaults.extensions||{renderers:{},childTokens:{}};return e.forEach(n=>{let s={...n};if(s.async=this.defaults.async||s.async||!1,n.extensions&&(n.extensions.forEach(r=>{if(!r.name)throw new Error("extension name required");if("renderer"in r){let i=t.renderers[r.name];i?t.renderers[r.name]=function(...o){let a=r.renderer.apply(this,o);return a===!1&&(a=i.apply(this,o)),a}:t.renderers[r.name]=r.renderer}if("tokenizer"in r){if(!r.level||r.level!=="block"&&r.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");let i=t[r.level];i?i.unshift(r.tokenizer):t[r.level]=[r.tokenizer],r.start&&(r.level==="block"?t.startBlock?t.startBlock.push(r.start):t.startBlock=[r.start]:r.level==="inline"&&(t.startInline?t.startInline.push(r.start):t.startInline=[r.start]))}"childTokens"in r&&r.childTokens&&(t.childTokens[r.name]=r.childTokens)}),s.extensions=t),n.renderer){let r=this.defaults.renderer||new Br(this.defaults);for(let i in n.renderer){if(!(i in r))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;let o=i,a=n.renderer[o],c=r[o];r[o]=(...l)=>{let h=a.apply(r,l);return h===!1&&(h=c.apply(r,l)),h||""}}s.renderer=r}if(n.tokenizer){let r=this.defaults.tokenizer||new Hr(this.defaults);for(let i in n.tokenizer){if(!(i in r))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;let o=i,a=n.tokenizer[o],c=r[o];r[o]=(...l)=>{let h=a.apply(r,l);return h===!1&&(h=c.apply(r,l)),h}}s.tokenizer=r}if(n.hooks){let r=this.defaults.hooks||new ms;for(let i in n.hooks){if(!(i in r))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;let o=i,a=n.hooks[o],c=r[o];ms.passThroughHooks.has(i)?r[o]=l=>{if(this.defaults.async&&ms.passThroughHooksRespectAsync.has(i))return(async()=>{let f=await a.call(r,l);return c.call(r,f)})();let h=a.call(r,l);return c.call(r,h)}:r[o]=(...l)=>{if(this.defaults.async)return(async()=>{let f=await a.apply(r,l);return f===!1&&(f=await c.apply(r,l)),f})();let h=a.apply(r,l);return h===!1&&(h=c.apply(r,l)),h}}s.hooks=r}if(n.walkTokens){let r=this.defaults.walkTokens,i=n.walkTokens;s.walkTokens=function(o){let a=[];return a.push(i.call(this,o)),r&&(a=a.concat(r.call(this,o))),a}}this.defaults={...this.defaults,...s}}),this}setOptions(e){return this.defaults={...this.defaults,...e},this}lexer(e,t){return qe.lex(e,t??this.defaults)}parser(e,t){return Ke.parse(e,t??this.defaults)}parseMarkdown(e){return(t,n)=>{let s={...n},r={...this.defaults,...s},i=this.onError(!!r.silent,!!r.async);if(this.defaults.async===!0&&s.async===!1)return i(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 i(new Error("marked(): input parameter is undefined or null"));if(typeof t!="string")return i(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(t)+", string expected"));if(r.hooks&&(r.hooks.options=r,r.hooks.block=e),r.async)return(async()=>{let o=r.hooks?await r.hooks.preprocess(t):t,a=await(r.hooks?await r.hooks.provideLexer():e?qe.lex:qe.lexInline)(o,r),c=r.hooks?await r.hooks.processAllTokens(a):a;r.walkTokens&&await Promise.all(this.walkTokens(c,r.walkTokens));let l=await(r.hooks?await r.hooks.provideParser():e?Ke.parse:Ke.parseInline)(c,r);return r.hooks?await r.hooks.postprocess(l):l})().catch(i);try{r.hooks&&(t=r.hooks.preprocess(t));let o=(r.hooks?r.hooks.provideLexer():e?qe.lex:qe.lexInline)(t,r);r.hooks&&(o=r.hooks.processAllTokens(o)),r.walkTokens&&this.walkTokens(o,r.walkTokens);let a=(r.hooks?r.hooks.provideParser():e?Ke.parse:Ke.parseInline)(o,r);return r.hooks&&(a=r.hooks.postprocess(a)),a}catch(o){return i(o)}}}onError(e,t){return n=>{if(n.message+=`
314
- Please report this to https://github.com/markedjs/marked.`,e){let s="<p>An error occurred:</p><pre>"+et(n.message+"",!0)+"</pre>";return t?Promise.resolve(s):s}if(t)return Promise.reject(n);throw n}}},on=new E0;function K(e,t){return on.parse(e,t)}K.options=K.setOptions=function(e){return on.setOptions(e),K.defaults=on.defaults,Xh(K.defaults),K};K.getDefaults=aa;K.defaults=un;K.use=function(...e){return on.use(...e),K.defaults=on.defaults,Xh(K.defaults),K};K.walkTokens=function(e,t){return on.walkTokens(e,t)};K.parseInline=on.parseInline;K.Parser=Ke;K.parser=Ke.parse;K.Renderer=Br;K.TextRenderer=ga;K.Lexer=qe;K.lexer=qe.lex;K.Tokenizer=Hr;K.Hooks=ms;K.parse=K;K.options;K.setOptions;K.use;K.walkTokens;K.parseInline;Ke.parse;qe.lex;const A0=8;let gl=!1;function T0(){gl||(gl=!0,Yh.addHook("afterSanitizeAttributes",e=>{e.tagName==="A"&&(e.setAttribute("target","_blank"),e.setAttribute("rel","noopener noreferrer"))}))}function I0(e){T0();const t=K.parse(e,{async:!1});return Yh.sanitize(t,{USE_PROFILES:{html:!0}})}function C0(e){return e.kind==="user"||e.kind==="assistant"}function ml(e,t){for(let n=e.length-1;n>=0;n-=1){const s=e[n];if(s&&s.kind===t)return s.id}return null}var gt,Mn,mt,On,Ne,vs,cd,Gs,Yr,$r;class ad extends Is{constructor(){super(...arguments);I(this,Ne);m(this,"messages",[]);I(this,gt,!0);I(this,Mn,null);I(this,mt,null);I(this,On,!1);I(this,Gs,()=>{const n=d(this,mt);if(!n)return;const r=n.scrollHeight-n.clientHeight-n.scrollTop<=A0;r!==d(this,gt)&&(C(this,gt,r),y(this,Ne,vs).call(this))});I(this,Yr,()=>{C(this,gt,!0),y(this,Ne,vs).call(this),y(this,Ne,$r).call(this,{force:!0})})}connectedCallback(){C(this,On,!0),C(this,Mn,ml(this.messages??[],"user")),y(this,Ne,vs).call(this),y(this,Ne,$r).call(this,{force:!0})}disconnectedCallback(){C(this,On,!1),C(this,mt,null)}propertyChangedCallback(n,s,r){if(n!=="messages"||!d(this,On))return;const i=this.messages??[],o=ml(i,"user"),a=o!==null&&o!==d(this,Mn);C(this,Mn,o),a&&C(this,gt,!0),y(this,Ne,vs).call(this),y(this,Ne,$r).call(this,{force:a})}}gt=new WeakMap,Mn=new WeakMap,mt=new WeakMap,On=new WeakMap,Ne=new WeakSet,vs=function(){var i;const n=(this.messages??[]).filter(C0),s=d(this,gt);ue(O`
315
- <div
316
- class="chat-history-scroll"
317
- role="log"
318
- aria-live="polite"
319
- @scroll=${d(this,Gs)}
320
- >
321
- ${n.map(o=>y(this,Ne,cd).call(this,o))}
322
- </div>
323
- <button
324
- type="button"
325
- class="chat-history-jump"
326
- aria-label="Jump to latest message"
327
- ?hidden=${s}
328
- @click=${d(this,Yr)}
329
- >
330
- ${Zr({size:14})}
331
- <span>Jump to latest</span>
332
- </button>
333
- `,this);const r=this.querySelector(".chat-history-scroll");r&&r!==d(this,mt)&&((i=d(this,mt))==null||i.removeEventListener("scroll",d(this,Gs)),C(this,mt,r))},cd=function(n){const s=ob(I0(n.text));if(n.kind==="user")return O`
334
- <div class="chat-message chat-message-user">
335
- <div class="chat-message-body">${s}</div>
336
- </div>
337
- `;const r=n.status==="cancelled"?O`<span class="chat-message-badge">[cancelled]</span>`:n.status==="error"?O`<span class="chat-message-badge">[error]</span>`:null;return O`
338
- <div class="chat-message chat-message-assistant">
339
- <div class="chat-message-body">${s}${r}</div>
340
- </div>
341
- `},Gs=new WeakMap,Yr=new WeakMap,$r=function(n){requestAnimationFrame(()=>{const s=d(this,mt);s&&(!d(this,gt)&&!n.force||(s.scrollTop=s.scrollHeight-s.clientHeight))})},m(ad,"observedProperties",{messages:{type:Object}});customElements.define("chat-history",ad);const z0=rt(),$0=rt(),R0=rt(),P0=3;class ld extends Is{constructor(){super(...arguments);m(this,"value","");m(this,"disabled",!1);m(this,"disabledPlaceholder","");m(this,"action","send");m(this,"handleInput",n=>{const r=n.currentTarget.value??"";this.value=r,this.dispatchEvent(new z0("change",{value:r,bubbles:!0,composed:!0}))});m(this,"handleKeyDown",n=>{n.key==="Enter"&&(n.shiftKey||n.isComposing||(n.preventDefault(),!this.disabled&&this.action==="send"&&this.submitMessage()))});m(this,"handleButtonClick",()=>{this.disabled||(this.action==="send"?this.submitMessage():this.dispatchEvent(new R0("cancel",{bubbles:!0,composed:!0})))})}connectedCallback(){this.render()}propertyChangedCallback(){this.render()}get textareaEl(){return this.querySelector("textarea")}submitMessage(){var s;const n=(this.value??"").trim();n.length!==0&&(this.dispatchEvent(new $0("submit",{text:n,bubbles:!0,composed:!0})),(s=this.textareaEl)==null||s.focus())}computeRows(){const n=(this.value??"").split(/\r?\n/).length;return Math.min(P0,Math.max(1,n))}render(){const n=this.action==="send",s=n?"Send message":"Cancel",r=n?db({size:16}):hb({size:16}),i=this.computeRows(),o=this.value??"",a=this.disabled?"":o,c=this.disabled?this.disabledPlaceholder:"";ue(O`
342
- <textarea
343
- .value=${a}
344
- placeholder=${c}
345
- rows=${i}
346
- ?disabled=${this.disabled}
347
- @input=${this.handleInput}
348
- @keydown=${this.handleKeyDown}
349
- ></textarea>
350
- <button
351
- type="button"
352
- aria-label=${s}
353
- ?disabled=${this.disabled}
354
- @click=${this.handleButtonClick}
355
- >
356
- ${r}
357
- </button>
358
- `,this)}}m(ld,"observedProperties",{value:{type:String},disabled:{type:Boolean},disabledPlaceholder:{type:String},action:{type:String}});customElements.define("chat-input",ld);var Jt,be,Nn,Qt,Vs,Ae,Fo,Uo,qs,Xr,Jr,Qr,ud,xn;class D0 extends HTMLElement{constructor(){super(...arguments);I(this,Ae);I(this,Jt,Ze.resolve("ACPClientManager"));I(this,be,null);I(this,Nn,"");I(this,Qt,!1);I(this,Vs,()=>{if(!d(this,Qt))return;const n=d(this,Jt).getActiveService();n!==d(this,be)&&(y(this,Ae,Uo).call(this),y(this,Ae,Fo).call(this,n)),y(this,Ae,xn).call(this)});I(this,qs,()=>{d(this,Qt)&&y(this,Ae,xn).call(this)});I(this,Xr,n=>{const s=n.value;C(this,Nn,s),y(this,Ae,xn).call(this)});I(this,Jr,n=>{if(!d(this,be))return;const s=n.text;C(this,Nn,""),y(this,Ae,xn).call(this),d(this,be).sendMessage({text:s}).catch(r=>{console.error("ACPClientService.sendMessage() failed",r)})});I(this,Qr,n=>{d(this,be)&&d(this,be).cancel().catch(s=>{console.error("ACPClientService.cancel() failed",s)})})}connectedCallback(){C(this,Qt,!0),d(this,Jt).addEventListener("change",d(this,Vs)),y(this,Ae,Fo).call(this,d(this,Jt).getActiveService()),y(this,Ae,xn).call(this)}disconnectedCallback(){C(this,Qt,!1),d(this,Jt).removeEventListener("change",d(this,Vs)),y(this,Ae,Uo).call(this)}}Jt=new WeakMap,be=new WeakMap,Nn=new WeakMap,Qt=new WeakMap,Vs=new WeakMap,Ae=new WeakSet,Fo=function(n){C(this,be,n),d(this,be)&&(d(this,be).addEventListener("change",d(this,qs)),d(this,be).connect().catch(s=>{console.error("ACPClientService.connect() failed",s)}))},Uo=function(){d(this,be)&&(d(this,be).removeEventListener("change",d(this,qs)),C(this,be,null))},qs=new WeakMap,Xr=new WeakMap,Jr=new WeakMap,Qr=new WeakMap,ud=function(n){return n.lifecycle.status==="connecting"?"Connecting to agent…":n.lifecycle.status==="disconnected"?n.lifecycle.error?"Agent unavailable":"Agent disconnected":n.lifecycle.status==="disposed"?"Agent unavailable":n.run.status==="cancelling"?"Cancelling…":""},xn=function(){if(!d(this,be)){this.hidden=!0;return}const n=d(this,be).getState();this.hidden=n.lifecycle.status!=="ready";const s=n.messageOrder.map(a=>n.messagesById[a]).filter(a=>a!==void 0),r=n.run.canCancel&&n.run.status==="running"?"cancel":"send",i=n.lifecycle.status!=="ready"||n.run.status==="cancelling",o=y(this,Ae,ud).call(this,n);ue(O`
359
- <chat-history .messages=${s}></chat-history>
360
- <div class="chat-panel-input">
361
- <chat-input
362
- .value=${d(this,Nn)}
363
- .action=${r}
364
- .disabled=${i}
365
- .disabledPlaceholder=${o}
366
- @change=${d(this,Xr)}
367
- @submit=${d(this,Jr)}
368
- @cancel=${d(this,Qr)}
369
- ></chat-input>
370
- </div>
371
- `,this)};customElements.get("chat-panel")||customElements.define("chat-panel",D0);class hd extends HTMLElement{constructor(){super(...arguments);m(this,"workspaceService",Ze.resolve("WorkspaceService"));m(this,"handleWorkspaceChange",()=>{this.render()});m(this,"_mode","edit");m(this,"_targetServerURL");m(this,"createPending",!1)}get open(){return this.hasAttribute("open")}set mode(n){this._mode=n,this.render()}get mode(){return this._mode}set targetServerURL(n){this._targetServerURL=n,this.render()}get targetServerURL(){return this._targetServerURL}attributeChangedCallback(n){n==="open"&&(this.open||(this.createPending=!1),this.render())}connectedCallback(){this.render(),this.workspaceService.addEventListener("change",this.handleWorkspaceChange)}disconnectedCallback(){this.workspaceService.removeEventListener("change",this.handleWorkspaceChange)}emitClose(){this.dispatchEvent(new Event("close",{bubbles:!0}))}async handleSubmit(n){n.preventDefault();const s=n.currentTarget,r=new FormData(s),i=String(r.get("name")??"").trim();if(i){if(this._mode==="edit"){this.workspaceService.renameWorkspace(i),this.emitClose();return}if(this._targetServerURL){this.createPending=!0,this.render();try{await this.workspaceService.createWorkspace(this._targetServerURL,i),this.emitClose()}catch{this.createPending=!1,this.render()}}}}render(){var i;const n=this._mode==="edit"?"Edit workspace":"New workspace",s=this._mode==="edit"?"Save":this.createPending?"Creating...":"Create",r=this._mode==="edit"?((i=this.workspaceService.activeWorkspace)==null?void 0:i.name)??"":"";ue(O`
372
- <modal-overlay ?open=${this.open}>
373
- <section class="workspace-modal">
374
- <form class="workspace-form" @submit=${o=>void this.handleSubmit(o)}>
375
- <h2 class="workspace-modal-title">${n}</h2>
376
- <label class="settings-field">
377
- <span>Name</span>
378
- <input type="text" name="name" .value=${r} required />
379
- </label>
380
- <div class="workspace-form-actions">
381
- <button type="submit" class="settings-submit-button" ?disabled=${this.createPending}>
382
- ${s}
383
- </button>
384
- <button type="button" class="settings-cancel-button" @click=${()=>this.emitClose()}>
385
- Cancel
386
- </button>
387
- </div>
388
- </form>
389
- </section>
390
- </modal-overlay>
391
- `,this)}}m(hd,"observedAttributes",["open"]);customElements.define("workspace-form-modal",hd);class dd extends HTMLElement{constructor(){super(...arguments);m(this,"workspaceService",Ze.resolve("WorkspaceService"));m(this,"serverManager",Ze.resolve("ServerManager"));m(this,"handleChange",()=>{this.render()});m(this,"deletePending",!1);m(this,"deleteError",null)}get open(){return this.hasAttribute("open")}attributeChangedCallback(n,s,r){n==="open"&&(r!==null&&s===null&&(this.deletePending=!1,this.deleteError=null),this.render())}connectedCallback(){this.render(),this.workspaceService.addEventListener("change",this.handleChange),this.serverManager.addEventListener("change",this.handleChange)}disconnectedCallback(){this.workspaceService.removeEventListener("change",this.handleChange),this.serverManager.removeEventListener("change",this.handleChange)}emitClose(){this.dispatchEvent(new Event("close",{bubbles:!0}))}async handleDeleteWorkspace(){this.deletePending=!0,this.deleteError=null,this.render();try{await this.workspaceService.deleteWorkspace(),this.emitClose()}catch(n){this.deletePending=!1,this.deleteError=n instanceof Error?n.message:String(n),this.render()}}render(){var s;const n=this.workspaceService.activeWorkspaceServerURL!==null&&this.workspaceService.activeWorkspaceServerURL!==this.serverManager.localServerURL;ue(O`
392
- <modal-overlay ?open=${this.open}>
393
- <section class="workspace-modal workspace-delete-modal">
394
- <div class="workspace-form">
395
- <h2 class="workspace-modal-title">Delete workspace</h2>
396
- <p class="workspace-delete-copy">
397
- Delete <strong>${((s=this.workspaceService.activeWorkspace)==null?void 0:s.name)??""}</strong>?
398
- </p>
399
- ${n?O`<p class="workspace-delete-warning">This will delete it for everyone.</p>`:null}
400
- ${this.deleteError?O`<p class="workspace-delete-error">${this.deleteError}</p>`:null}
401
- <div class="workspace-form-actions">
402
- <button
403
- type="button"
404
- class="settings-server-remove-button"
405
- ?disabled=${this.deletePending}
406
- @click=${()=>void this.handleDeleteWorkspace()}
407
- >
408
- ${this.deletePending?"Deleting...":"Delete"}
409
- </button>
410
- <button
411
- type="button"
412
- class="settings-cancel-button"
413
- ?disabled=${this.deletePending}
414
- @click=${()=>this.emitClose()}
415
- >
416
- Cancel
417
- </button>
418
- </div>
419
- </div>
420
- </section>
421
- </modal-overlay>
422
- `,this)}}m(dd,"observedAttributes",["open"]);customElements.define("workspace-delete-modal",dd);class pd extends HTMLElement{constructor(){super(...arguments);m(this,"serverManager",Ze.resolve("ServerManager"));m(this,"handleChange",()=>{this.render()});m(this,"addServerFormOpen",!1)}get open(){return this.hasAttribute("open")}attributeChangedCallback(n){n==="open"&&(this.open||(this.addServerFormOpen=!1),this.render())}connectedCallback(){this.render(),this.serverManager.addEventListener("change",this.handleChange)}disconnectedCallback(){this.serverManager.removeEventListener("change",this.handleChange)}emitClose(){this.dispatchEvent(new Event("close",{bubbles:!0}))}openAddServerForm(){this.addServerFormOpen=!0,this.render()}closeAddServerForm(){this.addServerFormOpen&&(this.addServerFormOpen=!1,this.render())}handleAddServer(n){n.preventDefault();const s=n.currentTarget,r=new FormData(s),i=String(r.get("name")??"").trim(),o=String(r.get("url")??"").trim();!i||!o||(this.serverManager.addServer(o,i),this.addServerFormOpen=!1,s.reset(),this.render())}render(){const n=[...this.serverManager.servers.values()];ue(O`
423
- <modal-overlay ?open=${this.open}>
424
- <section class="settings-panel">
425
- <panel-view closable @close=${s=>s instanceof zh&&this.emitClose()}>
426
- <panel-page id="main" title="Settings">
427
- <div class="settings-section">
428
- <h3 class="settings-section-title">Servers</h3>
429
- <div class="settings-server-list">
430
- ${n.map(s=>O`
431
- <div class="settings-card settings-server">
432
- <div class="settings-server-details">
433
- <div class="settings-server-name">${s.name}</div>
434
- <div class="settings-server-url">${s.url}</div>
435
- </div>
436
- ${s.url!==this.serverManager.localServerURL?O`
437
- <button
438
- type="button"
439
- class="settings-server-remove-button"
440
- aria-label=${`Remove ${s.name}`}
441
- @click=${()=>this.serverManager.removeServer(s.url)}
442
- >
443
- Remove
444
- </button>
445
- `:null}
446
- </div>
447
- `)}
448
- </div>
449
- ${this.addServerFormOpen?O`
450
- <form class="settings-card settings-add-server-form" @submit=${s=>this.handleAddServer(s)}>
451
- <label class="settings-field">
452
- <span>Name</span>
453
- <input type="text" name="name" required />
454
- </label>
455
- <label class="settings-field">
456
- <span>URL</span>
457
- <input type="url" name="url" required />
458
- </label>
459
- <div class="settings-form-actions">
460
- <button type="submit" class="settings-submit-button">Connect</button>
461
- <button
462
- type="button"
463
- class="settings-cancel-button"
464
- data-action="cancel-connect-form"
465
- @click=${()=>this.closeAddServerForm()}
466
- >
467
- Cancel
468
- </button>
469
- </div>
470
- </form>
471
- `:O`
472
- <button
473
- type="button"
474
- class="settings-submit-button settings-connect-button"
475
- data-action="show-connect-form"
476
- @click=${()=>this.openAddServerForm()}
477
- >
478
- + Connect to server
479
- </button>
480
- `}
481
- </div>
482
- </panel-page>
483
- </panel-view>
484
- </section>
485
- </modal-overlay>
486
- `,this)}}m(pd,"observedAttributes",["open"]);customElements.define("settings-modal",pd);class fd extends Event{constructor(n){super("auth-submit",{bubbles:!0,composed:!0});m(this,"token");this.token=n}}class L0 extends HTMLElement{constructor(){super(...arguments);m(this,"_invalid",!1);m(this,"_tokenValue","")}set invalid(n){this._invalid=n,this.render()}get invalid(){return this._invalid}set tokenValue(n){this._tokenValue=n,this.render()}get tokenValue(){return this._tokenValue}connectedCallback(){this.render()}handleInput(n){const s=n.currentTarget;this._tokenValue=s.value}handleSubmit(n){n.preventDefault();const s=this._tokenValue.trim();s&&this.dispatchEvent(new fd(s))}render(){ue(O`
487
- <modal-overlay open>
488
- <section class="auth-modal">
489
- <form class="auth-form" @submit=${n=>this.handleSubmit(n)}>
490
- <h2 class="auth-modal-title">Enter access token</h2>
491
- <p class="auth-modal-copy">This Television server requires a token.</p>
492
- <label class="settings-field">
493
- <span>Token</span>
494
- <input
495
- class=${this.invalid?"auth-token-input-invalid":""}
496
- type="password"
497
- name="token"
498
- .value=${this.tokenValue}
499
- @input=${n=>this.handleInput(n)}
500
- required
501
- />
502
- </label>
503
- <button type="submit" class="settings-submit-button">Connect</button>
504
- </form>
505
- </section>
506
- </modal-overlay>
507
- `,this)}}customElements.get("auth-modal")||customElements.define("auth-modal",L0);class M0 extends HTMLElement{constructor(){super(...arguments);m(this,"runtimeServerURL",ph());m(this,"electronMode",gh());m(this,"serverManager",Ze.resolve("ServerManager"));m(this,"modals",{workspaceForm:{open:!1,mode:"edit"},deleteWorkspace:{open:!1},settings:{open:!1}});m(this,"connectError",null);m(this,"handleServerManagerChange",()=>{this.render()})}connectedCallback(){this.serverManager.addEventListener("change",this.handleServerManagerChange),this.addEventListener("auth-submit",n=>{var r;const s=n instanceof fd?n.token:n instanceof CustomEvent&&typeof((r=n.detail)==null?void 0:r.token)=="string"?n.detail.token:null;s&&this.handleAuthSubmit(s)}),this.initializeConnection(),this.render()}disconnectedCallback(){this.serverManager.removeEventListener("change",this.handleServerManagerChange)}async initializeConnection(){if(this.electronMode){this.serverManager.connectConfiguredServers(this.runtimeServerURL);return}if(this.serverManager.activeServer)return;const n=new ao({url:this.runtimeServerURL,name:"Server",token:fh()});this.serverManager.add(n),this.serverManager.setActive(n);try{await n.connect(),this.connectError=null}catch(s){this.connectError=s instanceof Error&&!(s instanceof oo)?s.message:null}this.render()}async handleAuthSubmit(n){const s=this.serverManager.activeServer;if(s){this.connectError=null,s.token=n,this.updateTokenQueryParam(n);try{await s.connect()}catch(r){r instanceof oo||(this.connectError=r instanceof Error?r.message:String(r))}this.render()}}updateTokenQueryParam(n){const s=new URL(window.location.href);s.searchParams.set("token",n),window.history.replaceState({},"",`${s.pathname}${s.search}${s.hash}`)}render(){const n=this.serverManager.activeServer,s=(n==null?void 0:n.status)??null;if(s==="connecting"){ue(O`
508
- <main class="auth-gate"><p>Connecting...</p></main>
509
- `,this);return}if(s==="disconnected"){const i=n;if(!i)return;ue(O`
510
- <main class="auth-gate">
511
- <auth-modal
512
- .invalid=${!!i.token}
513
- .tokenValue=${i.token??""}
514
- ></auth-modal>
515
- </main>
516
- `,this);return}const r=O`
517
- <header>
518
- <nav>
519
- <workspace-picker
520
- @edit-workspace=${()=>{this.modals.workspaceForm={open:!0,mode:"edit"},this.render()}}
521
- @create-workspace=${i=>{this.modals.workspaceForm={open:!0,mode:"create",targetServerURL:i.serverURL},this.render()}}
522
- @delete-workspace=${()=>{this.modals.deleteWorkspace={open:!0},this.render()}}
523
- ></workspace-picker>
524
- </nav>
525
- <button
526
- type="button"
527
- variant="toolbar"
528
- size="sm"
529
- aria-label="Settings"
530
- @click=${()=>{this.modals.settings={open:!this.modals.settings.open},this.render()}}
531
- >
532
- ${pb({size:16,weight:"bold"})}
533
- </button>
534
- </header>
535
- <main>
536
- ${this.connectError?O`<p data-testid="auth-error">${this.connectError}</p>`:O`
537
- <workspace-view></workspace-view>
538
- ${s==="connected"?O`<chat-panel></chat-panel>`:null}
539
- `}
540
- </main>
541
- <workspace-form-modal
542
- ?open=${this.modals.workspaceForm.open}
543
- .mode=${this.modals.workspaceForm.mode}
544
- .targetServerURL=${this.modals.workspaceForm.targetServerURL}
545
- @close=${()=>{this.modals.workspaceForm={open:!1,mode:"edit"},this.render()}}
546
- ></workspace-form-modal>
547
- <workspace-delete-modal
548
- ?open=${this.modals.deleteWorkspace.open}
549
- @close=${()=>{this.modals.deleteWorkspace={open:!1},this.render()}}
550
- ></workspace-delete-modal>
551
- <settings-modal
552
- ?open=${this.modals.settings.open}
553
- @close=${()=>{this.modals.settings={open:!1},this.render()}}
554
- ></settings-modal>
555
- `;ue(r,this)}}customElements.get("television-app")||customElements.define("television-app",M0);const ma=gh(),fi=ph(),gd=Ep(ma?"television-electron":"television-browser",fi),va=new zp({clientStore:gd,localServerURL:fi}),_a=new np({clientStore:gd,serverManager:va}),O0=new jw({serverURL:fi,token:fh()??"",workspaceService:_a});Ze.register("ServerManager",()=>va);Ze.register("WorkspaceService",()=>_a);Ze.register("ACPClientManager",()=>O0);va.addEventListener("server-message",e=>{_a.handleServerEvent(e.serverURL,e.message)});const ya=document.createElement("television-app");ya.runtimeServerURL=fi;ya.electronMode=ma;ma&&document.body.classList.add("electron");document.body.appendChild(ya);