@telepath-computer/television 0.1.7 → 0.1.9

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,396 +0,0 @@
1
- var Pr=Object.defineProperty;var hs=r=>{throw TypeError(r)};var Ir=(r,s,t)=>s in r?Pr(r,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[s]=t;var l=(r,s,t)=>Ir(r,typeof s!="symbol"?s+"":s,t),de=(r,s,t)=>s.has(r)||hs("Cannot "+t);var h=(r,s,t)=>(de(r,s,"read from private field"),t?t.call(r):s.get(r)),y=(r,s,t)=>s.has(r)?hs("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(r):s.set(r,t),M=(r,s,t,e)=>(de(r,s,"write to private field"),e?e.call(r,t):s.set(r,t),t),f=(r,s,t)=>(de(r,s,"access private method"),t);(function(){const s=document.createElement("link").relList;if(s&&s.supports&&s.supports("modulepreload"))return;for(const i of document.querySelectorAll('link[rel="modulepreload"]'))e(i);new MutationObserver(i=>{for(const n of i)if(n.type==="childList")for(const o of n.addedNodes)o.tagName==="LINK"&&o.rel==="modulepreload"&&e(o)}).observe(document,{childList:!0,subtree:!0});function t(i){const n={};return i.integrity&&(n.integrity=i.integrity),i.referrerPolicy&&(n.referrerPolicy=i.referrerPolicy),i.crossOrigin==="use-credentials"?n.credentials="include":i.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function e(i){if(i.ep)return;i.ep=!0;const n=t(i);fetch(i.href,n)}})();const ds=new WeakMap;function xr(r){return(typeof r=="object"||typeof r=="function")&&r!==null&&"then"in r&&typeof r.then=="function"}function nt(r){return typeof r=="string"?r:typeof r=="symbol"?r.description??r.toString():r.name||"(anonymous class)"}function us(){return new Error("register(Key, factory) requires a factory function. Wrap existing instances as () => instance.")}function Tr(){return new Error("register(Key, factory) does not accept async factories. Await setup before registering.")}class Rr{constructor(){l(this,"entries",new Map);l(this,"constructionStack",[])}register(s,t){if(t===void 0){if(typeof s!="function")throw us();this.validateClassRegistration(s),this.storeFactory(s,()=>this.instantiateClass(s));return}if(typeof t!="function")throw us();if(t.constructor.name==="AsyncFunction")throw Tr();this.storeFactory(s,t)}has(s){var t;return((t=this.entries.get(s))==null?void 0:t.factory)!==void 0}resolve(s){return this.resolveAny(s)}storeFactory(s,t){const e=this.getOrCreateEntry(s);e.factory=t,e.instance=void 0,e.error=void 0}validateClassRegistration(s){const t=ds.get(s);if(t){if(s.length!==t.length)throw new Error(`${nt(s)} cannot be registered with register(Class). @injectable(...) declared ${t.length} dependencies but constructor arity is ${s.length}. Use register(Key, () => value) instead.`);return}if(s.length!==0)throw new Error(`${nt(s)} cannot be registered with register(Class). Undecorated classes must have zero required constructor parameters. Use register(Key, () => value) instead.`)}instantiateClass(s){const t=ds.get(s);if(!t)return new s;const e=t.map(i=>this.resolveAny(i));return new s(...e)}resolveAny(s){return this.getOrCreateEntry(s).proxy}getOrCreateEntry(s){let t=this.entries.get(s);return t||(t={key:s},t.proxy=this.createProxy(t),this.entries.set(s,t),t)}createProxy(s){return new Proxy({},{get:(t,e)=>{if(e==="then")return;const i=this.getInstance(s),n=Reflect.get(i,e,i);return typeof n=="function"?n.bind(i):n},set:(t,e,i)=>{const n=this.getInstance(s);return Reflect.set(n,e,i,n)},has:(t,e)=>{const i=this.getInstance(s);return e in i}})}getInstance(s){if(s.instance)return s.instance;if(s.error)throw s.error;if(!s.factory)throw new Error(`${nt(s.key)} was resolved but never registered`);const t=this.constructionStack.indexOf(s.key);if(t!==-1){const e=[...this.constructionStack.slice(t),s.key].map(i=>nt(i)).join(" -> ");throw new Error(`Circular dependency detected: ${e}`)}this.constructionStack.push(s.key);try{const e=s.factory();if(xr(e))throw new Error(`Factory for ${nt(s.key)} returned a Promise. Await setup before registering.`);if(typeof e!="object"||e===null)throw new Error(`Factory for ${nt(s.key)} returned a non-object value. Wrap primitives in an object.`);return s.instance=e,e}catch(e){throw s.error=e,e}finally{this.constructionStack.pop()}}}const L=new Rr;function Or(r){return{all:r=r||new Map,on:function(s,t){var e=r.get(s);e?e.push(t):r.set(s,[t])},off:function(s,t){var e=r.get(s);e&&(t?e.splice(e.indexOf(t)>>>0,1):r.set(s,[]))},emit:function(s,t){var e=r.get(s);e&&e.slice().map(function(i){i(t)}),(e=r.get("*"))&&e.slice().map(function(i){i(s,t)})}}}let Ke=class{constructor(){l(this,"emitter",Or());l(this,"off",this.emitter.off)}on(s,t){return this.emitter.on(s,t),{dispose:()=>this.emitter.off(s,t)}}once(s,t){const e=(...i)=>{t(...i),this.emitter.off(s,e)};return this.emitter.on(s,e),{dispose:()=>this.emitter.off(s,e)}}emit(s,...[t]){this.emitter.emit(s,t)}};const Hs="0123456789ABCDEFGHJKMNPQRSTVWXYZ",Zt=32,Nr=16,Fs=10,ps=0xffffffffffff;var Z;(function(r){r.Base32IncorrectEncoding="B32_ENC_INVALID",r.DecodeTimeInvalidCharacter="DEC_TIME_CHAR",r.DecodeTimeValueMalformed="DEC_TIME_MALFORMED",r.EncodeTimeNegative="ENC_TIME_NEG",r.EncodeTimeSizeExceeded="ENC_TIME_SIZE_EXCEED",r.EncodeTimeValueMalformed="ENC_TIME_MALFORMED",r.PRNGDetectFailure="PRNG_DETECT",r.ULIDInvalid="ULID_INVALID",r.Unexpected="UNEXPECTED",r.UUIDInvalid="UUID_INVALID"})(Z||(Z={}));class ft extends Error{constructor(s,t){super(`${t} (${s})`),this.name="ULIDError",this.code=s}}function Ur(r){const s=Math.floor(r()*Zt)%Zt;return Hs.charAt(s)}function Hr(r){const s=Fr(),t=s&&(s.crypto||s.msCrypto)||null;if(typeof(t==null?void 0:t.getRandomValues)=="function")return()=>{const e=new Uint8Array(1);return t.getRandomValues(e),e[0]/256};if(typeof(t==null?void 0:t.randomBytes)=="function")return()=>t.randomBytes(1).readUInt8()/256;throw new ft(Z.PRNGDetectFailure,"Failed to find a reliable PRNG")}function Fr(){return Br()?self:typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:null}function zr(r,s){let t="";for(;r>0;r--)t=Ur(s)+t;return t}function Gr(r,s=Fs){if(isNaN(r))throw new ft(Z.EncodeTimeValueMalformed,`Time must be a number: ${r}`);if(r>ps)throw new ft(Z.EncodeTimeSizeExceeded,`Cannot encode a time larger than ${ps}: ${r}`);if(r<0)throw new ft(Z.EncodeTimeNegative,`Time must be positive: ${r}`);if(Number.isInteger(r)===!1)throw new ft(Z.EncodeTimeValueMalformed,`Time must be an integer: ${r}`);let t,e="";for(let i=s;i>0;i--)t=r%Zt,e=Hs.charAt(t)+e,r=(r-t)/Zt;return e}function Br(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function ye(r,s){const t=Hr(),e=Date.now();return Gr(e,Fs)+zr(Nr,t)}const zs="markdown";function Vr(r){const s=r.type??zs;return{id:r.id??ye(),type:s,title:r.title,content:r.content}}const x=2,B=6,Xr=1,Kr=2,qr=3,Yr=4,jr=[Xr,x],Zr=[Kr,qr,Yr,B];function kt(r){const s=Math.round(r);return jr.includes(s)?s:x}function be(r){const s=Math.round(r);return Zr.includes(s)?s:B}function Se(r){return{type:"artifact",artifactID:r,cols:x,rows:B}}function ue(r){return r.layout.map(s=>s.artifactID)}const Ft=[{cols:2,rows:6},{cols:2,rows:4},{cols:2,rows:3},{cols:2,rows:2},{cols:1,rows:2}],pe="create-artifact",fe="remove-artifact",zt="update-layout";class Qr extends Ke{constructor(t){var i;super();l(this,"artifacts",new Map);l(this,"activeWorkspaceID",null);l(this,"scrollPosition",0);l(this,"activeWorkspaceData",null);l(this,"clientStore");l(this,"serverManager");l(this,"pendingMutations",new Map);l(this,"pendingWorkspaceCreates",new Map);l(this,"pendingWorkspaceDeletes",new Map);this.clientStore=t.clientStore,this.serverManager=t.serverManager;const e=this.clientStore.get();this.activeWorkspaceID=(e==null?void 0:e.lastWorkspaceID)??null,this.activeWorkspaceID&&(this.scrollPosition=((i=e==null?void 0:e.workspaces[this.activeWorkspaceID])==null?void 0:i.scrollPosition)??0)}get workspaces(){return[...this.getServers().values()].flatMap(t=>[...t.workspaces.values()])}get activeWorkspace(){return this.activeWorkspaceData}get activeWorkspaceServerURL(){var t;return this.activeWorkspaceID?((t=this.findWorkspace(this.activeWorkspaceID))==null?void 0:t.serverURL)??null:null}get activeArtifacts(){return(this.activeWorkspaceData?ue(this.activeWorkspaceData):[]).map(t=>this.artifacts.get(t)).filter(t=>t!==void 0)}getArtifactURL(t){const e=this.activeWorkspaceServerURL;if(!e)return null;const i=this.getServers().get(e);return i!=null&&i.getArtifactURL?i.getArtifactURL(t):null}setActiveWorkspace(t){this.selectWorkspace(t)}setScrollPosition(t){const e=Math.max(0,t);this.scrollPosition!==e&&(this.scrollPosition=e,this.persistWorkspaceViewState(),this.emit("change"))}createArtifact(t){var a;const e=this.activeWorkspaceData;if(!e)return;const i=this.snapshotState(),n=Vr({id:ye(),type:zs,title:t.title,content:t.content});e.layout.some(d=>d.artifactID===n.id)||e.layout.push(Se(n.id)),this.artifacts.set(n.id,n),this.scrollPosition=Math.max(e.layout.length-1,0),this.persistWorkspaceViewState(),this.emit("change");const o=((a=this.findWorkspace(e.id))==null?void 0:a.server)??null,c=this.getMutationKey(pe,n.id);this.pendingMutations.set(c,i),this.sendServerMessage(o,{type:"create-artifact",id:n.id,title:t.title,content:t.content,workspaceID:e.id})||(this.pendingMutations.delete(c),this.restoreState(i),this.emit("change"))}removeArtifact(t){var c;const e=this.activeWorkspaceData;if(!e||!this.artifacts.has(t))return;const i=this.snapshotState();this.removeArtifactLocally(t),this.emit("change");const n=((c=this.findWorkspace(e.id))==null?void 0:c.server)??null,o=this.getMutationKey(fe,t);this.pendingMutations.set(o,i),this.sendServerMessage(n,{type:"remove-artifact",artifactID:t,workspaceID:e.id})||(this.pendingMutations.delete(o),this.restoreState(i),this.emit("change"))}reorderLayout(t){const e=this.activeWorkspaceData;if(!e)return;const i=ue(e);if(t.length!==i.length||t.every((c,a)=>c===i[a]))return;const n=new Map(e.layout.map(c=>[c.artifactID,structuredClone(c)]));if(new Set(t).size!==t.length)return;const o=t.map(c=>n.get(c)).filter(c=>c!==void 0);o.length===t.length&&this.updateLayout(o)}cycleArtifactLayout(t){const e=this.activeWorkspaceData;if(!e)return;const i=e.layout.findIndex(o=>o.artifactID===t);if(i===-1)return;const n=e.layout.map((o,c)=>c===i?{...o,...Jr(o.cols,o.rows)}:structuredClone(o));this.updateLayout(n)}handleServerEvent(t,e){var i;switch(e.type){case"workspace-list":this.syncActiveWorkspaceState(t,!0);break;case"workspace-updated":this.syncActiveWorkspaceState(t,!1),Array.isArray(e.fields.layout)&&this.pendingMutations.delete(this.getMutationKey(zt,e.workspaceID));break;case"workspace-removed":{this.syncActiveWorkspaceState(t,!1);const n=this.pendingWorkspaceDeletes.get(e.workspaceID);n&&(this.pendingWorkspaceDeletes.delete(e.workspaceID),n.resolve());break}case"workspace-created":if(this.pendingWorkspaceCreates.has(e.workspace.id)){const n=this.pendingWorkspaceCreates.get(e.workspace.id);this.pendingWorkspaceCreates.delete(e.workspace.id),this.selectWorkspace(e.workspace.id),n==null||n.resolve();return}this.syncActiveWorkspaceState(t,!1);break;case"workspace":this.applyWorkspaceSnapshot(e.workspace,e.artifacts);break;case"artifact-created":this.pendingMutations.delete(this.getMutationKey(pe,e.artifact.id)),this.applyArtifactCreated(e);break;case"artifact-updated":this.applyArtifactUpdated(e);break;case"artifact-removed":if(this.pendingMutations.delete(this.getMutationKey(fe,e.artifactID)),((i=this.activeWorkspaceData)==null?void 0:i.id)!==e.workspaceID)return;this.removeArtifactLocally(e.artifactID)&&this.emit("change");break;case"error":this.handleServerError(e);break}}createWorkspace(t,e){const i=this.getServers().get(t)??null,n=ye(),o=fs();return this.pendingWorkspaceCreates.set(n,o),this.sendServerMessage(i,{type:"create-workspace",id:n,name:e})||(this.pendingWorkspaceCreates.delete(n),o.reject(new Error(`Server unavailable: ${t}`))),o.promise}deleteWorkspace(){var o;const t=this.activeWorkspaceData;if(!t)return Promise.reject(new Error("No active workspace"));const e=this.pendingWorkspaceDeletes.get(t.id);if(e)return e.promise;const i=((o=this.findWorkspace(t.id))==null?void 0:o.server)??null,n=fs();return this.pendingWorkspaceDeletes.set(t.id,n),this.sendServerMessage(i,{type:"delete-workspace",workspaceID:t.id})||(this.pendingWorkspaceDeletes.delete(t.id),n.reject(new Error(`Server unavailable: ${t.id}`))),n.promise}renameWorkspace(t){var n;const e=this.activeWorkspaceData;if(!e)return;const i=((n=this.findWorkspace(e.id))==null?void 0:n.server)??null;e.name=t,this.emit("change"),this.sendServerMessage(i,{type:"update-workspace",workspaceID:e.id,fields:{name:t}})}updateLayout(t){var c;const e=this.activeWorkspaceData;if(!e)return;const i=this.snapshotState();e.layout=t,this.emit("change");const n=((c=this.findWorkspace(e.id))==null?void 0:c.server)??null,o=this.getMutationKey(zt,e.id);this.pendingMutations.set(o,i),this.sendServerMessage(n,{type:"update-workspace",workspaceID:e.id,fields:{layout:t.map(a=>structuredClone(a))}})||(this.pendingMutations.delete(o),this.restoreState(i),this.emit("change"))}syncActiveWorkspaceState(t,e){const i=this.activeWorkspaceID?this.findWorkspace(this.activeWorkspaceID):null;if(!i){const n=this.pickNextWorkspace();if(!n){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.emit("change");return}this.selectWorkspace(n.workspace.id);return}this.applyServerWorkspaceState(i.workspace),e&&i.serverURL===t&&this.requestWorkspace(i.serverURL,i.workspace.id)}hasPendingLayoutMutation(t){return this.pendingMutations.has(this.getMutationKey(zt,t))}selectWorkspace(t){const e=this.findWorkspace(t);e&&(this.activeWorkspaceID=t,this.activeWorkspaceData=structuredClone(e.workspace),this.artifacts.clear(),this.restoreWorkspaceViewState(),this.persistActiveWorkspace(),this.requestWorkspace(e.serverURL,t),this.emit("change"))}requestWorkspace(t,e){const i=this.getServers().get(t);this.sendServerMessage(i??null,{type:"get-workspace",workspaceID:e})}applyWorkspaceSnapshot(t,e){if(t.id===this.activeWorkspaceID){this.applyServerWorkspaceState(t),this.artifacts.clear();for(const i of e)this.artifacts.set(i.id,structuredClone(i));this.restoreWorkspaceViewState(),this.emit("change")}}applyServerWorkspaceState(t){if(!this.activeWorkspaceData||this.activeWorkspaceData.id!==t.id){this.activeWorkspaceData=structuredClone(t);return}this.activeWorkspaceData.name=t.name,this.hasPendingLayoutMutation(t.id)||(this.activeWorkspaceData.layout=t.layout.map(e=>structuredClone(e)))}applyArtifactCreated(t){var e;((e=this.activeWorkspaceData)==null?void 0:e.id)===t.workspaceID&&(this.activeWorkspaceData.layout.some(i=>i.artifactID===t.artifact.id)||this.activeWorkspaceData.layout.push(Se(t.artifact.id)),this.artifacts.set(t.artifact.id,t.artifact),this.emit("change"))}applyArtifactUpdated(t){const e=this.artifacts.get(t.artifactID);e&&(Object.assign(e,t.fields),this.emit("change"))}removeArtifactLocally(t){if(!this.activeWorkspaceData)return!1;const e=this.artifacts.delete(t),i=this.activeWorkspaceData.layout.length;return this.activeWorkspaceData.layout=this.activeWorkspaceData.layout.filter(n=>n.artifactID!==t),!(!e&&i===this.activeWorkspaceData.layout.length)}snapshotState(){return{activeWorkspaceData:this.activeWorkspaceData?structuredClone(this.activeWorkspaceData):null,scrollPosition:this.scrollPosition,artifacts:new Map([...this.artifacts.entries()].map(([t,e])=>[t,structuredClone(e)]))}}restoreState(t){this.activeWorkspaceData=t.activeWorkspaceData?structuredClone(t.activeWorkspaceData):null,this.scrollPosition=t.scrollPosition,this.artifacts.clear();for(const[e,i]of t.artifacts.entries())this.artifacts.set(e,structuredClone(i));this.persistWorkspaceViewState()}handleServerError(t){const e=t.request;if(e){if(e.type==="create-artifact"){const i=this.getMutationKey(pe,e.id),n=this.pendingMutations.get(i);if(!n)return;this.pendingMutations.delete(i),this.restoreState(n),this.emit("change");return}if(e.type==="create-workspace"){const i=this.pendingWorkspaceCreates.get(e.id);if(!i)return;this.pendingWorkspaceCreates.delete(e.id),i.reject(new Error(t.message));return}if(e.type==="delete-workspace"){const i=this.pendingWorkspaceDeletes.get(e.workspaceID);if(!i)return;this.pendingWorkspaceDeletes.delete(e.workspaceID),i.reject(new Error(t.message));return}if(e.type==="update-workspace"&&Array.isArray(e.fields.layout)){const i=this.getMutationKey(zt,e.workspaceID),n=this.pendingMutations.get(i);if(!n)return;this.pendingMutations.delete(i),this.restoreState(n),this.emit("change");return}if(e.type==="remove-artifact"){const i=this.getMutationKey(fe,e.artifactID),n=this.pendingMutations.get(i);if(!n)return;this.pendingMutations.delete(i),this.restoreState(n),this.emit("change")}}}restoreWorkspaceViewState(){var i,n;if(!this.activeWorkspaceID){this.scrollPosition=0;return}const t=((n=(i=this.clientStore.get())==null?void 0:i.workspaces[this.activeWorkspaceID])==null?void 0:n.scrollPosition)??0,e=this.activeWorkspaceData?ue(this.activeWorkspaceData):[];this.scrollPosition=Math.max(0,Math.min(t,Math.max(e.length-1,0))),this.persistWorkspaceViewState()}persistActiveWorkspace(){this.clientStore.update(t=>{t.lastWorkspaceID=this.activeWorkspaceID})}persistWorkspaceViewState(){this.activeWorkspaceID&&this.clientStore.update(t=>{var e,i;(e=t.workspaces)[i=this.activeWorkspaceID]??(e[i]={scrollPosition:0}),t.workspaces[this.activeWorkspaceID].scrollPosition=this.scrollPosition})}findWorkspace(t){for(const[e,i]of this.getServers()){const n=i.workspaces.get(t);if(n)return{serverURL:e,server:i,workspace:n}}return null}pickNextWorkspace(){var e;const t=(e=this.clientStore.get())==null?void 0:e.lastWorkspaceID;if(t){const i=this.findWorkspace(t);if(i)return i}for(const[i,n]of this.getServers()){const o=n.workspaces.values().next().value;if(o)return{serverURL:i,server:n,workspace:o}}return null}sendServerMessage(t,e){return t?t.send(e):!1}getServers(){return this.serverManager.servers}getMutationKey(t,e){return`${t}:${e}`}}function Jr(r,s){const t=Ft.findIndex(i=>i.cols===r&&i.rows===s),e=t===-1?0:(t+1)%Ft.length;return{cols:Ft[e].cols,rows:Ft[e].rows}}function fs(){let r,s;return{promise:new Promise((e,i)=>{r=e,s=i}),resolve:r,reject:s}}var Gs=Symbol.for("immer-nothing"),gs=Symbol.for("immer-draftable"),P=Symbol.for("immer-state");function O(r,...s){throw new Error(`[Immer] minified error nr: ${r}. Full error at: https://bit.ly/3cXEKWf`)}var yt=Object.getPrototypeOf;function ct(r){return!!r&&!!r[P]}function tt(r){var s;return r?Bs(r)||Array.isArray(r)||!!r[gs]||!!((s=r.constructor)!=null&&s[gs])||Ot(r)||oe(r):!1}var ti=Object.prototype.constructor.toString(),ms=new WeakMap;function Bs(r){if(!r||typeof r!="object")return!1;const s=Object.getPrototypeOf(r);if(s===null||s===Object.prototype)return!0;const t=Object.hasOwnProperty.call(s,"constructor")&&s.constructor;if(t===Object)return!0;if(typeof t!="function")return!1;let e=ms.get(t);return e===void 0&&(e=Function.toString.call(t),ms.set(t,e)),e===ti}function Qt(r,s,t=!0){ne(r)===0?(t?Reflect.ownKeys(r):Object.keys(r)).forEach(i=>{s(i,r[i],r)}):r.forEach((e,i)=>s(i,e,r))}function ne(r){const s=r[P];return s?s.type_:Array.isArray(r)?1:Ot(r)?2:oe(r)?3:0}function _e(r,s){return ne(r)===2?r.has(s):Object.prototype.hasOwnProperty.call(r,s)}function Vs(r,s,t){const e=ne(r);e===2?r.set(s,t):e===3?r.add(t):r[s]=t}function ei(r,s){return r===s?r!==0||1/r===1/s:r!==r&&s!==s}function Ot(r){return r instanceof Map}function oe(r){return r instanceof Set}function K(r){return r.copy_||r.base_}function Ae(r,s){if(Ot(r))return new Map(r);if(oe(r))return new Set(r);if(Array.isArray(r))return Array.prototype.slice.call(r);const t=Bs(r);if(s===!0||s==="class_only"&&!t){const e=Object.getOwnPropertyDescriptors(r);delete e[P];let i=Reflect.ownKeys(e);for(let n=0;n<i.length;n++){const o=i[n],c=e[o];c.writable===!1&&(c.writable=!0,c.configurable=!0),(c.get||c.set)&&(e[o]={configurable:!0,writable:!0,enumerable:c.enumerable,value:r[o]})}return Object.create(yt(r),e)}else{const e=yt(r);if(e!==null&&t)return{...r};const i=Object.create(e);return Object.assign(i,r)}}function qe(r,s=!1){return ae(r)||ct(r)||!tt(r)||(ne(r)>1&&Object.defineProperties(r,{set:Gt,add:Gt,clear:Gt,delete:Gt}),Object.freeze(r),s&&Object.values(r).forEach(t=>qe(t,!0))),r}function si(){O(2)}var Gt={value:si};function ae(r){return r===null||typeof r!="object"?!0:Object.isFrozen(r)}var ri={};function et(r){const s=ri[r];return s||O(0,r),s}var bt;function Xs(){return bt}function ii(r,s){return{drafts_:[],parent_:r,immer_:s,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function vs(r,s){s&&(et("Patches"),r.patches_=[],r.inversePatches_=[],r.patchListener_=s)}function Ee(r){De(r),r.drafts_.forEach(ni),r.drafts_=null}function De(r){r===bt&&(bt=r.parent_)}function ws(r){return bt=ii(bt,r)}function ni(r){const s=r[P];s.type_===0||s.type_===1?s.revoke_():s.revoked_=!0}function ks(r,s){s.unfinalizedDrafts_=s.drafts_.length;const t=s.drafts_[0];return r!==void 0&&r!==t?(t[P].modified_&&(Ee(s),O(4)),tt(r)&&(r=Jt(s,r),s.parent_||te(s,r)),s.patches_&&et("Patches").generateReplacementPatches_(t[P].base_,r,s.patches_,s.inversePatches_)):r=Jt(s,t,[]),Ee(s),s.patches_&&s.patchListener_(s.patches_,s.inversePatches_),r!==Gs?r:void 0}function Jt(r,s,t){if(ae(s))return s;const e=r.immer_.shouldUseStrictIteration(),i=s[P];if(!i)return Qt(s,(n,o)=>ys(r,i,s,n,o,t),e),s;if(i.scope_!==r)return s;if(!i.modified_)return te(r,i.base_,!0),i.base_;if(!i.finalized_){i.finalized_=!0,i.scope_.unfinalizedDrafts_--;const n=i.copy_;let o=n,c=!1;i.type_===3&&(o=new Set(n),n.clear(),c=!0),Qt(o,(a,d)=>ys(r,i,n,a,d,t,c),e),te(r,n,!1),t&&r.patches_&&et("Patches").generatePatches_(i,t,r.patches_,r.inversePatches_)}return i.copy_}function ys(r,s,t,e,i,n,o){if(i==null||typeof i!="object"&&!o)return;const c=ae(i);if(!(c&&!o)){if(ct(i)){const a=n&&s&&s.type_!==3&&!_e(s.assigned_,e)?n.concat(e):void 0,d=Jt(r,i,a);if(Vs(t,e,d),ct(d))r.canAutoFreeze_=!1;else return}else o&&t.add(i);if(tt(i)&&!c){if(!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1||s&&s.base_&&s.base_[e]===i&&c)return;Jt(r,i),(!s||!s.scope_.parent_)&&typeof e!="symbol"&&(Ot(t)?t.has(e):Object.prototype.propertyIsEnumerable.call(t,e))&&te(r,i)}}}function te(r,s,t=!1){!r.parent_&&r.immer_.autoFreeze_&&r.canAutoFreeze_&&qe(s,t)}function oi(r,s){const t=Array.isArray(r),e={type_:t?1:0,scope_:s?s.scope_:Xs(),modified_:!1,finalized_:!1,assigned_:{},parent_:s,base_:r,draft_:null,copy_:null,revoke_:null,isManual_:!1};let i=e,n=Ye;t&&(i=[e],n=St);const{revoke:o,proxy:c}=Proxy.revocable(i,n);return e.draft_=c,e.revoke_=o,c}var Ye={get(r,s){if(s===P)return r;const t=K(r);if(!_e(t,s))return ai(r,t,s);const e=t[s];return r.finalized_||!tt(e)?e:e===ge(r.base_,s)?(me(r),r.copy_[s]=$e(e,r)):e},has(r,s){return s in K(r)},ownKeys(r){return Reflect.ownKeys(K(r))},set(r,s,t){const e=Ks(K(r),s);if(e!=null&&e.set)return e.set.call(r.draft_,t),!0;if(!r.modified_){const i=ge(K(r),s),n=i==null?void 0:i[P];if(n&&n.base_===t)return r.copy_[s]=t,r.assigned_[s]=!1,!0;if(ei(t,i)&&(t!==void 0||_e(r.base_,s)))return!0;me(r),Ce(r)}return r.copy_[s]===t&&(t!==void 0||s in r.copy_)||Number.isNaN(t)&&Number.isNaN(r.copy_[s])||(r.copy_[s]=t,r.assigned_[s]=!0),!0},deleteProperty(r,s){return ge(r.base_,s)!==void 0||s in r.base_?(r.assigned_[s]=!1,me(r),Ce(r)):delete r.assigned_[s],r.copy_&&delete r.copy_[s],!0},getOwnPropertyDescriptor(r,s){const t=K(r),e=Reflect.getOwnPropertyDescriptor(t,s);return e&&{writable:!0,configurable:r.type_!==1||s!=="length",enumerable:e.enumerable,value:t[s]}},defineProperty(){O(11)},getPrototypeOf(r){return yt(r.base_)},setPrototypeOf(){O(12)}},St={};Qt(Ye,(r,s)=>{St[r]=function(){return arguments[0]=arguments[0][0],s.apply(this,arguments)}});St.deleteProperty=function(r,s){return St.set.call(this,r,s,void 0)};St.set=function(r,s,t){return Ye.set.call(this,r[0],s,t,r[0])};function ge(r,s){const t=r[P];return(t?K(t):r)[s]}function ai(r,s,t){var i;const e=Ks(s,t);return e?"value"in e?e.value:(i=e.get)==null?void 0:i.call(r.draft_):void 0}function Ks(r,s){if(!(s in r))return;let t=yt(r);for(;t;){const e=Object.getOwnPropertyDescriptor(t,s);if(e)return e;t=yt(t)}}function Ce(r){r.modified_||(r.modified_=!0,r.parent_&&Ce(r.parent_))}function me(r){r.copy_||(r.copy_=Ae(r.base_,r.scope_.immer_.useStrictShallowCopy_))}var ci=class{constructor(r){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(s,t,e)=>{if(typeof s=="function"&&typeof t!="function"){const n=t;t=s;const o=this;return function(a=n,...d){return o.produce(a,u=>t.call(this,u,...d))}}typeof t!="function"&&O(6),e!==void 0&&typeof e!="function"&&O(7);let i;if(tt(s)){const n=ws(this),o=$e(s,void 0);let c=!0;try{i=t(o),c=!1}finally{c?Ee(n):De(n)}return vs(n,e),ks(i,n)}else if(!s||typeof s!="object"){if(i=t(s),i===void 0&&(i=s),i===Gs&&(i=void 0),this.autoFreeze_&&qe(i,!0),e){const n=[],o=[];et("Patches").generateReplacementPatches_(s,i,n,o),e(n,o)}return i}else O(1,s)},this.produceWithPatches=(s,t)=>{if(typeof s=="function")return(o,...c)=>this.produceWithPatches(o,a=>s(a,...c));let e,i;return[this.produce(s,t,(o,c)=>{e=o,i=c}),e,i]},typeof(r==null?void 0:r.autoFreeze)=="boolean"&&this.setAutoFreeze(r.autoFreeze),typeof(r==null?void 0:r.useStrictShallowCopy)=="boolean"&&this.setUseStrictShallowCopy(r.useStrictShallowCopy),typeof(r==null?void 0:r.useStrictIteration)=="boolean"&&this.setUseStrictIteration(r.useStrictIteration)}createDraft(r){tt(r)||O(8),ct(r)&&(r=li(r));const s=ws(this),t=$e(r,void 0);return t[P].isManual_=!0,De(s),t}finishDraft(r,s){const t=r&&r[P];(!t||!t.isManual_)&&O(9);const{scope_:e}=t;return vs(e,s),ks(void 0,e)}setAutoFreeze(r){this.autoFreeze_=r}setUseStrictShallowCopy(r){this.useStrictShallowCopy_=r}setUseStrictIteration(r){this.useStrictIteration_=r}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(r,s){let t;for(t=s.length-1;t>=0;t--){const i=s[t];if(i.path.length===0&&i.op==="replace"){r=i.value;break}}t>-1&&(s=s.slice(t+1));const e=et("Patches").applyPatches_;return ct(r)?e(r,s):this.produce(r,i=>e(i,s))}};function $e(r,s){const t=Ot(r)?et("MapSet").proxyMap_(r,s):oe(r)?et("MapSet").proxySet_(r,s):oi(r,s);return(s?s.scope_:Xs()).drafts_.push(t),t}function li(r){return ct(r)||O(10,r),qs(r)}function qs(r){if(!tt(r)||ae(r))return r;const s=r[P];let t,e=!0;if(s){if(!s.modified_)return s.base_;s.finalized_=!0,t=Ae(r,s.scope_.immer_.useStrictShallowCopy_),e=s.scope_.immer_.shouldUseStrictIteration()}else t=Ae(r,!0);return Qt(t,(i,n)=>{Vs(t,i,qs(n))},e),s&&(s.finalized_=!1),t}var hi=new ci,di=hi.produce,ui=Object.defineProperty,pi=(r,s,t)=>s in r?ui(r,s,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[s]=t,Bt=(r,s,t)=>pi(r,typeof s!="symbol"?s+"":s,t);function fi(r){return{all:r=r||new Map,on:function(s,t){var e=r.get(s);e?e.push(t):r.set(s,[t])},off:function(s,t){var e=r.get(s);e&&(t?e.splice(e.indexOf(t)>>>0,1):r.set(s,[]))},emit:function(s,t){var e=r.get(s);e&&e.slice().map(function(i){i(t)}),(e=r.get("*"))&&e.slice().map(function(i){i(s,t)})}}}var gi=class{constructor(){Bt(this,"emitter",fi()),Bt(this,"on",(r,s)=>(this.emitter.on(r,s),{dispose:()=>this.emitter.off(r,s)})),Bt(this,"once",(r,s)=>{const t=e=>{s(e),this.emitter.off(r,t)};return this.emitter.on(r,t),{dispose:()=>this.emitter.off(r,t)}}),Bt(this,"off",this.emitter.off)}emit(r,...[s]){this.emitter.emit(r,s)}},mi="store-",vi=class extends gi{emitChange(r){this.emit("change",{state:r})}},wi=class{constructor(r,s,t){this.emitter=new vi,this.id=r,this.initValue=s,this.key=`${mi}${r}`,this.storage=(t==null?void 0:t.storage)==="session"?sessionStorage:localStorage,this.get()===void 0&&this.storage.setItem(this.key,JSON.stringify(s))}get(){const r=this.storage.getItem(this.key);return r===null?void 0:JSON.parse(r)}update(r){const s=this.get()??{},t=di(s,r);this.storage.setItem(this.key,JSON.stringify(t)),this.emitter.emitChange(t)}reset(){this.storage.setItem(this.key,JSON.stringify(this.initValue)),this.emitter.emitChange(this.initValue)}on(r,s){return this.emitter.on(r,({state:t})=>s(t))}subscribe(r){const s=this.on("change",r),t=this.get();return t!==void 0&&r(t),s}};const ki="Local";function F(r){return new URL(r).origin}function yi(r){return{servers:[{url:F(r),name:ki}],lastWorkspaceID:null,workspaces:{}}}function bi(r,s){return new wi(r,yi(s))}const Si=4401;class We extends Error{constructor(s="Authentication required"){super(s),this.name="AuthError"}}class Me extends Ke{constructor(t){super();l(this,"url");l(this,"name");l(this,"token");l(this,"status","disconnected");l(this,"workspaces",new Map);l(this,"createSocket");l(this,"socket",null);l(this,"connectAttempt",0);this.url=F(t.url),this.name=t.name,this.token=t.token??null,this.createSocket=t.createSocket??(e=>new WebSocket(e))}async connect(){var i;this.connectAttempt+=1;const t=this.connectAttempt;(i=this.socket)==null||i.close(),this.status="connecting",this.emit("status-changed");const e=this.createSocket(_i(this.url,this.token));return this.socket=e,await new Promise((n,o)=>{let c=!1;const a=()=>{c||this.connectAttempt!==t||(c=!0,this.status="connected",this.emit("status-changed"),n())},d=u=>{c||this.connectAttempt!==t||(c=!0,this.status="disconnected",this.emit("status-changed"),o(u))};e.addEventListener("message",u=>{const p=Ei(u);this.applyServerMessage(p),this.emit("message",p),c||a()}),e.addEventListener("close",u=>{if(this.connectAttempt===t){if(this.socket=null,Ai(u)===Si){d(new We);return}if(!c){d(new Error("Connection closed before initialization"));return}this.status="disconnected",this.emit("status-changed")}}),e.addEventListener("error",()=>{d(new Error("WebSocket connection failed"))})})}disconnect(){var t;this.connectAttempt+=1,(t=this.socket)==null||t.close(),this.socket=null,this.status="disconnected",this.emit("status-changed")}send(t){return!this.socket||this.socket.readyState!==1?!1:(this.socket.send(JSON.stringify(t)),!0)}getArtifactURL(t){const e=new URL(this.url);return e.pathname=`/artifact/${t}`,e.search="",this.token&&e.searchParams.set("token",this.token),e.hash="",e.toString()}applyServerMessage(t){switch(t.type){case"workspace-list":this.workspaces=new Map(t.workspaces.map(e=>[e.id,structuredClone(e)]));break;case"workspace-created":this.workspaces.set(t.workspace.id,structuredClone(t.workspace));break;case"workspace-updated":{const e=this.workspaces.get(t.workspaceID);e&&(typeof t.fields.name=="string"&&(e.name=t.fields.name),Array.isArray(t.fields.layout)&&(e.layout=t.fields.layout));break}case"workspace-removed":this.workspaces.delete(t.workspaceID);break;case"artifact-created":{const e=this.workspaces.get(t.workspaceID);e&&!e.layout.some(i=>i.artifactID===t.artifact.id)&&e.layout.push(Se(t.artifact.id));break}case"artifact-removed":{const e=this.workspaces.get(t.workspaceID);e&&(e.layout=e.layout.filter(i=>i.artifactID!==t.artifactID));break}}}}function _i(r,s){const t=new URL(r);return t.protocol=t.protocol==="https:"?"wss:":"ws:",t.pathname="/ws",t.search="",s&&t.searchParams.set("token",s),t.hash="",t.toString()}function Ai(r){return typeof r=="object"&&r!==null&&"code"in r&&typeof r.code=="number"?r.code:null}function Ei(r){const s=typeof r=="string"?r:typeof r=="object"&&r!==null&&"data"in r&&typeof r.data=="string"?r.data:"";return JSON.parse(s)}class Di extends Ke{constructor(t){super();l(this,"servers",new Map);l(this,"localServerURL");l(this,"activeServer",null);l(this,"clientStore");l(this,"createSocket");l(this,"disposables",new Map);this.clientStore=t.clientStore,this.localServerURL=t.localServerURL?F(t.localServerURL):null,this.createSocket=t.createSocket??(e=>new WebSocket(e))}add(t){const e=F(t.url);this.servers.get(e)&&this.remove(e),this.servers.set(e,t);const n=t.on("status-changed",()=>this.emit("servers-changed")),o=t.on("message",c=>{this.emit("server-event",{serverURL:e,event:c})});this.disposables.set(e,{statusSubscription:n,messageSubscription:o}),this.emit("servers-changed")}remove(t){const e=F(t);if(this.localServerURL&&e===this.localServerURL)return;const i=this.servers.get(e);if(!i)return;const n=this.disposables.get(e);n==null||n.statusSubscription.dispose(),n==null||n.messageSubscription.dispose(),this.disposables.delete(e),i.disconnect(),this.servers.delete(e),this.activeServer===i&&(this.activeServer=null),this.clientStore.update(o=>{o.servers=o.servers.filter(c=>c.url!==e)}),this.emit("servers-changed")}setActive(t){this.activeServer=t,this.emit("servers-changed")}connectConfiguredServers(t){var n;const e=((n=this.clientStore.get())==null?void 0:n.servers)??[];for(const o of e){const c=new Me({url:o.url,name:o.name,createSocket:this.createSocket});this.add(c),c.connect().catch(()=>{})}const i=t?this.servers.get(F(t))??null:null;this.setActive(i??this.servers.values().next().value??null)}addServer(t,e){const i=F(t);this.remove(i),this.clientStore.update(o=>{o.servers=o.servers.filter(c=>F(c.url)!==i),o.servers.push({url:i,name:e})});const n=new Me({url:i,name:e,createSocket:this.createSocket});this.add(n),this.setActive(n),n.connect().catch(()=>{})}removeServer(t){this.remove(t)}}const Ci="serverURL",$i="token",Wi="mode",Mi="electron";function Ys(r=window.location.search,s=window.location.origin){const e=new URLSearchParams(r).get(Ci);return e?new URL(e).origin:new URL(s).origin}function Li(r=window.location.search){return new URLSearchParams(r).get($i)}function js(r=window.location.search){return new URLSearchParams(r).get(Wi)===Mi}class dt{constructor(){this.disposables=[]}add(s){return this.disposables.push(s),s}dispose(){for(const s of this.disposables)s.dispose();this.disposables=[]}}/**
2
- * @license
3
- * Copyright 2017 Google LLC
4
- * SPDX-License-Identifier: BSD-3-Clause
5
- */const wt=globalThis,bs=r=>r,ee=wt.trustedTypes,Ss=ee?ee.createPolicy("lit-html",{createHTML:r=>r}):void 0,Zs="$lit$",z=`lit$${Math.random().toFixed(9).slice(2)}$`,Qs="?"+z,Pi=`<${Qs}>`,st=document,_t=()=>st.createComment(""),At=r=>r===null||typeof r!="object"&&typeof r!="function",je=Array.isArray,Ii=r=>je(r)||typeof(r==null?void 0:r[Symbol.iterator])=="function",ve=`[
6
- \f\r]`,pt=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,_s=/-->/g,As=/>/g,X=RegExp(`>|${ve}(?:([^\\s"'>=/]+)(${ve}*=${ve}*(?:[^
7
- \f\r"'\`<>=]|("|')|))|$)`,"g"),Es=/'/g,Ds=/"/g,Js=/^(?:script|style|textarea|title)$/i,xi=r=>(s,...t)=>({_$litType$:r,strings:s,values:t}),m=xi(1),lt=Symbol.for("lit-noChange"),_=Symbol.for("lit-nothing"),Cs=new WeakMap,Q=st.createTreeWalker(st,129);function tr(r,s){if(!je(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return Ss!==void 0?Ss.createHTML(s):s}const Ti=(r,s)=>{const t=r.length-1,e=[];let i,n=s===2?"<svg>":s===3?"<math>":"",o=pt;for(let c=0;c<t;c++){const a=r[c];let d,u,p=-1,k=0;for(;k<a.length&&(o.lastIndex=k,u=o.exec(a),u!==null);)k=o.lastIndex,o===pt?u[1]==="!--"?o=_s:u[1]!==void 0?o=As:u[2]!==void 0?(Js.test(u[2])&&(i=RegExp("</"+u[2],"g")),o=X):u[3]!==void 0&&(o=X):o===X?u[0]===">"?(o=i??pt,p=-1):u[1]===void 0?p=-2:(p=o.lastIndex-u[2].length,d=u[1],o=u[3]===void 0?X:u[3]==='"'?Ds:Es):o===Ds||o===Es?o=X:o===_s||o===As?o=pt:(o=X,i=void 0);const v=o===X&&r[c+1].startsWith("/>")?" ":"";n+=o===pt?a+Pi:p>=0?(e.push(d),a.slice(0,p)+Zs+a.slice(p)+z+v):a+z+(p===-2?c:v)}return[tr(r,n+(r[t]||"<?>")+(s===2?"</svg>":s===3?"</math>":"")),e]};class Et{constructor({strings:s,_$litType$:t},e){let i;this.parts=[];let n=0,o=0;const c=s.length-1,a=this.parts,[d,u]=Ti(s,t);if(this.el=Et.createElement(d,e),Q.currentNode=this.el.content,t===2||t===3){const p=this.el.content.firstChild;p.replaceWith(...p.childNodes)}for(;(i=Q.nextNode())!==null&&a.length<c;){if(i.nodeType===1){if(i.hasAttributes())for(const p of i.getAttributeNames())if(p.endsWith(Zs)){const k=u[o++],v=i.getAttribute(p).split(z),S=/([.?@])?(.*)/.exec(k);a.push({type:1,index:n,name:S[2],strings:v,ctor:S[1]==="."?Oi:S[1]==="?"?Ni:S[1]==="@"?Ui:ce}),i.removeAttribute(p)}else p.startsWith(z)&&(a.push({type:6,index:n}),i.removeAttribute(p));if(Js.test(i.tagName)){const p=i.textContent.split(z),k=p.length-1;if(k>0){i.textContent=ee?ee.emptyScript:"";for(let v=0;v<k;v++)i.append(p[v],_t()),Q.nextNode(),a.push({type:2,index:++n});i.append(p[k],_t())}}}else if(i.nodeType===8)if(i.data===Qs)a.push({type:2,index:n});else{let p=-1;for(;(p=i.data.indexOf(z,p+1))!==-1;)a.push({type:7,index:n}),p+=z.length-1}n++}}static createElement(s,t){const e=st.createElement("template");return e.innerHTML=s,e}}function ht(r,s,t=r,e){var o,c;if(s===lt)return s;let i=e!==void 0?(o=t._$Co)==null?void 0:o[e]:t._$Cl;const n=At(s)?void 0:s._$litDirective$;return(i==null?void 0:i.constructor)!==n&&((c=i==null?void 0:i._$AO)==null||c.call(i,!1),n===void 0?i=void 0:(i=new n(r),i._$AT(r,t,e)),e!==void 0?(t._$Co??(t._$Co=[]))[e]=i:t._$Cl=i),i!==void 0&&(s=ht(r,i._$AS(r,s.values),i,e)),s}class Ri{constructor(s,t){this._$AV=[],this._$AN=void 0,this._$AD=s,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(s){const{el:{content:t},parts:e}=this._$AD,i=((s==null?void 0:s.creationScope)??st).importNode(t,!0);Q.currentNode=i;let n=Q.nextNode(),o=0,c=0,a=e[0];for(;a!==void 0;){if(o===a.index){let d;a.type===2?d=new Nt(n,n.nextSibling,this,s):a.type===1?d=new a.ctor(n,a.name,a.strings,this,s):a.type===6&&(d=new Hi(n,this,s)),this._$AV.push(d),a=e[++c]}o!==(a==null?void 0:a.index)&&(n=Q.nextNode(),o++)}return Q.currentNode=st,i}p(s){let t=0;for(const e of this._$AV)e!==void 0&&(e.strings!==void 0?(e._$AI(s,e,t),t+=e.strings.length-2):e._$AI(s[t])),t++}}class Nt{get _$AU(){var s;return((s=this._$AM)==null?void 0:s._$AU)??this._$Cv}constructor(s,t,e,i){this.type=2,this._$AH=_,this._$AN=void 0,this._$AA=s,this._$AB=t,this._$AM=e,this.options=i,this._$Cv=(i==null?void 0:i.isConnected)??!0}get parentNode(){let s=this._$AA.parentNode;const t=this._$AM;return t!==void 0&&(s==null?void 0:s.nodeType)===11&&(s=t.parentNode),s}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(s,t=this){s=ht(this,s,t),At(s)?s===_||s==null||s===""?(this._$AH!==_&&this._$AR(),this._$AH=_):s!==this._$AH&&s!==lt&&this._(s):s._$litType$!==void 0?this.$(s):s.nodeType!==void 0?this.T(s):Ii(s)?this.k(s):this._(s)}O(s){return this._$AA.parentNode.insertBefore(s,this._$AB)}T(s){this._$AH!==s&&(this._$AR(),this._$AH=this.O(s))}_(s){this._$AH!==_&&At(this._$AH)?this._$AA.nextSibling.data=s:this.T(st.createTextNode(s)),this._$AH=s}$(s){var n;const{values:t,_$litType$:e}=s,i=typeof e=="number"?this._$AC(s):(e.el===void 0&&(e.el=Et.createElement(tr(e.h,e.h[0]),this.options)),e);if(((n=this._$AH)==null?void 0:n._$AD)===i)this._$AH.p(t);else{const o=new Ri(i,this),c=o.u(this.options);o.p(t),this.T(c),this._$AH=o}}_$AC(s){let t=Cs.get(s.strings);return t===void 0&&Cs.set(s.strings,t=new Et(s)),t}k(s){je(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let e,i=0;for(const n of s)i===t.length?t.push(e=new Nt(this.O(_t()),this.O(_t()),this,this.options)):e=t[i],e._$AI(n),i++;i<t.length&&(this._$AR(e&&e._$AB.nextSibling,i),t.length=i)}_$AR(s=this._$AA.nextSibling,t){var e;for((e=this._$AP)==null?void 0:e.call(this,!1,!0,t);s!==this._$AB;){const i=bs(s).nextSibling;bs(s).remove(),s=i}}setConnected(s){var t;this._$AM===void 0&&(this._$Cv=s,(t=this._$AP)==null||t.call(this,s))}}class ce{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(s,t,e,i,n){this.type=1,this._$AH=_,this._$AN=void 0,this.element=s,this.name=t,this._$AM=i,this.options=n,e.length>2||e[0]!==""||e[1]!==""?(this._$AH=Array(e.length-1).fill(new String),this.strings=e):this._$AH=_}_$AI(s,t=this,e,i){const n=this.strings;let o=!1;if(n===void 0)s=ht(this,s,t,0),o=!At(s)||s!==this._$AH&&s!==lt,o&&(this._$AH=s);else{const c=s;let a,d;for(s=n[0],a=0;a<n.length-1;a++)d=ht(this,c[e+a],t,a),d===lt&&(d=this._$AH[a]),o||(o=!At(d)||d!==this._$AH[a]),d===_?s=_:s!==_&&(s+=(d??"")+n[a+1]),this._$AH[a]=d}o&&!i&&this.j(s)}j(s){s===_?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,s??"")}}class Oi extends ce{constructor(){super(...arguments),this.type=3}j(s){this.element[this.name]=s===_?void 0:s}}class Ni extends ce{constructor(){super(...arguments),this.type=4}j(s){this.element.toggleAttribute(this.name,!!s&&s!==_)}}class Ui extends ce{constructor(s,t,e,i,n){super(s,t,e,i,n),this.type=5}_$AI(s,t=this){if((s=ht(this,s,t,0)??_)===lt)return;const e=this._$AH,i=s===_&&e!==_||s.capture!==e.capture||s.once!==e.once||s.passive!==e.passive,n=s!==_&&(e===_||i);i&&this.element.removeEventListener(this.name,this,e),n&&this.element.addEventListener(this.name,this,s),this._$AH=s}handleEvent(s){var t;typeof this._$AH=="function"?this._$AH.call(((t=this.options)==null?void 0:t.host)??this.element,s):this._$AH.handleEvent(s)}}class Hi{constructor(s,t,e){this.element=s,this.type=6,this._$AN=void 0,this._$AM=t,this.options=e}get _$AU(){return this._$AM._$AU}_$AI(s){ht(this,s)}}const we=wt.litHtmlPolyfillSupport;we==null||we(Et,Nt),(wt.litHtmlVersions??(wt.litHtmlVersions=[])).push("3.3.2");const E=(r,s,t)=>{const e=s;let i=e._$litPart$;return i===void 0&&(e._$litPart$=i=new Nt(s.insertBefore(_t(),null),null,void 0,{})),i._$AI(r),i};/**
8
- * @license
9
- * Copyright 2017 Google LLC
10
- * SPDX-License-Identifier: BSD-3-Clause
11
- */const Fi={CHILD:2},zi=r=>(...s)=>({_$litDirective$:r,values:s});class Gi{constructor(s){}get _$AU(){return this._$AM._$AU}_$AT(s,t,e){this._$Ct=s,this._$AM=t,this._$Ci=e}_$AS(s,t){return this.update(s,t)}update(s,t){return this.render(...t)}}/**
12
- * @license
13
- * Copyright 2017 Google LLC
14
- * SPDX-License-Identifier: BSD-3-Clause
15
- */class Le extends Gi{constructor(s){if(super(s),this.it=_,s.type!==Fi.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(s){if(s===_||s==null)return this._t=void 0,this.it=s;if(s===lt)return s;if(typeof s!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(s===this.it)return this._t;this.it=s;const t=[s];return t.raw=t,this._t={_$litType$:this.constructor.resultType,strings:t,values:[]}}}Le.directiveName="unsafeHTML",Le.resultType=1;/**
16
- * @license
17
- * Copyright 2017 Google LLC
18
- * SPDX-License-Identifier: BSD-3-Clause
19
- */class Pe extends Le{}Pe.directiveName="unsafeSVG",Pe.resultType=2;const Bi=zi(Pe),Vi={size:16,color:"currentColor",weight:"regular"};function Xi(r){return typeof r=="string"?{regular:r}:r}function Ze(r,s="0 0 256 256"){const t=Xi(r);return e=>{const{size:i,color:n,weight:o}={...Vi,...e},c=t[o]??t.regular;return m`<svg
20
- xmlns="http://www.w3.org/2000/svg"
21
- data-ui-icon=""
22
- width="${i}"
23
- height="${i}"
24
- viewBox="${s}"
25
- fill="${n}"
26
- >${Bi(c)}</svg>`}}const Ki=new Map,ke=new Set;var ot,Xt;const ss=class ss extends HTMLElement{constructor(){super(...arguments);y(this,ot)}connectedCallback(){f(this,ot,Xt).call(this)}disconnectedCallback(){ke.delete(this)}attributeChangedCallback(){f(this,ot,Xt).call(this)}refresh(){f(this,ot,Xt).call(this)}get name(){return this.getAttribute("name")}get size(){const t=this.getAttribute("size");if(t===null)return;const e=Number(t);return Number.isFinite(e)?e:void 0}get weight(){const t=this.getAttribute("weight");return t==="bold"||t==="regular"?t:void 0}};ot=new WeakSet,Xt=function(){const t=this.name?Ki.get(this.name):null;if(!t){this.name&&ke.add(this),E(null,this);return}ke.delete(this),E(t({size:this.size,weight:this.weight}),this)},ss.observedAttributes=["name","size","weight"];let Ie=ss;customElements.get("icon-element")||customElements.define("icon-element",Ie);const er=Ze('<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"/>'),xe=Ze('<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"/>'),qi=Ze('<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 sr extends Event{constructor(s){super("dropdown-item-select",{bubbles:!0,composed:!0}),this.value=s}}class rr extends Event{constructor(s){super("select",{bubbles:!0,composed:!0}),this.value=s}}var I,R,G,at,w,Dt,g,ir,gt,nr,or,Re,Oe,Kt,q,J,Ct,$t,Wt,re,ar,cr,Ne,mt,Ue,H;const rs=class rs extends HTMLElement{constructor(){super();y(this,g);y(this,I,!1);y(this,R,null);y(this,G,null);y(this,at);y(this,w,null);y(this,Dt,new MutationObserver(t=>f(this,g,ar).call(this,t)));y(this,J,()=>{f(this,g,Kt).call(this,!h(this,I))});y(this,Ct,t=>{t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),h(this,J).call(this))});y(this,$t,t=>{h(this,I)&&(t.composedPath().includes(this)||f(this,g,Kt).call(this,!1))});y(this,Wt,t=>{t instanceof sr&&(t.stopPropagation(),M(this,I,!1),f(this,g,gt).call(this,t.value),f(this,g,H).call(this),this.dispatchEvent(new rr(t.value)))});y(this,re,()=>{f(this,g,Ne).call(this)});M(this,at,this.attachShadow({mode:"open"}))}connectedCallback(){this.addEventListener("dropdown-item-select",h(this,Wt)),document.addEventListener("click",h(this,$t),!0),f(this,g,ir).call(this),h(this,Dt).observe(this,{childList:!0,subtree:!0,characterData:!0,attributes:!0,attributeFilter:["selected","value","slot"]}),f(this,g,H).call(this)}disconnectedCallback(){this.removeEventListener("dropdown-item-select",h(this,Wt)),document.removeEventListener("click",h(this,$t),!0),h(this,Dt).disconnect(),f(this,g,Ue).call(this)}attributeChangedCallback(){f(this,g,H).call(this)}get title(){return this.getAttribute("title")??""}get value(){return h(this,R)}set value(t){t===null?(f(this,g,q).call(this,null,null),f(this,g,nr).call(this)):f(this,g,gt).call(this,t),f(this,g,H).call(this)}close(){f(this,g,Kt).call(this,!1)}};I=new WeakMap,R=new WeakMap,G=new WeakMap,at=new WeakMap,w=new WeakMap,Dt=new WeakMap,g=new WeakSet,ir=function(){var e;const t=this.querySelector("dropdown-item[selected]");t&&f(this,g,q).call(this,t.value,((e=t.textContent)==null?void 0:e.trim())??null)},gt=function(t){var e;for(const i of h(this,g,Re))i.value===t?(f(this,g,q).call(this,t,((e=i.textContent)==null?void 0:e.trim())??null),i.hasAttribute("selected")||i.setAttribute("selected","")):i.hasAttribute("selected")&&i.removeAttribute("selected")},nr=function(){const t=this.querySelectorAll("dropdown-item[selected]");for(const e of t)e.removeAttribute("selected")},or=function(t){for(const e of h(this,g,Re))if(e.value===t)return e;return null},Re=function(){return this.querySelectorAll("dropdown-item")},Oe=function(){return h(this,G)??this.title},Kt=function(t){h(this,I)!==t&&(M(this,I,t),f(this,g,H).call(this))},q=function(t,e){M(this,R,t),M(this,G,e)},J=new WeakMap,Ct=new WeakMap,$t=new WeakMap,Wt=new WeakMap,re=new WeakMap,ar=function(t){t.every(i=>i.target instanceof Element?i.target.closest('[slot="trigger"]')!==null:!1)||f(this,g,cr).call(this)},cr=function(){var e,i;const t=this.querySelector("dropdown-item[selected]");if(t){const n=t.value,o=((e=t.textContent)==null?void 0:e.trim())??null,c=h(this,R)!==n||h(this,G)!==o;f(this,g,q).call(this,n,o),f(this,g,gt).call(this,n),c?f(this,g,H).call(this):f(this,g,mt).call(this);return}if(h(this,R)!==null){const n=f(this,g,or).call(this,h(this,R));if(n){const o=((i=n.textContent)==null?void 0:i.trim())??null,c=h(this,G)!==o;f(this,g,q).call(this,h(this,R),o),f(this,g,gt).call(this,h(this,R)),c?f(this,g,H).call(this):f(this,g,mt).call(this);return}}if(h(this,R)!==null||h(this,G)!==null){f(this,g,q).call(this,null,null),f(this,g,H).call(this);return}f(this,g,mt).call(this)},Ne=function(){const t=h(this,at).querySelector('slot[name="trigger"]'),e=t instanceof HTMLSlotElement?t.assignedElements({flatten:!0})[0]??null:null;h(this,w)!==e&&(f(this,g,Ue).call(this),M(this,w,e),h(this,w)&&(h(this,w).addEventListener("click",h(this,J)),h(this,w)instanceof HTMLButtonElement?h(this,w).hasAttribute("type")||(h(this,w).type="button"):(h(this,w).hasAttribute("role")||h(this,w).setAttribute("role","button"),h(this,w).hasAttribute("tabindex")||(h(this,w).tabIndex=0),h(this,w).addEventListener("keydown",h(this,Ct))))),f(this,g,mt).call(this)},mt=function(){h(this,w)&&(h(this,w).setAttribute("data-dropdown-trigger",""),h(this,w).setAttribute("aria-haspopup","listbox"),h(this,w).setAttribute("aria-expanded",h(this,I)?"true":"false"),E(m`
27
- <span class="trigger-label" data-dropdown-trigger-label>${h(this,g,Oe)}</span>
28
- <span class="trigger-icon" data-dropdown-trigger-icon aria-hidden="true">
29
- ${xe({size:14})}
30
- </span>
31
- `,h(this,w)))},Ue=function(){h(this,w)&&(h(this,w).removeEventListener("click",h(this,J)),h(this,w).removeEventListener("keydown",h(this,Ct)),h(this,w).removeAttribute("data-dropdown-trigger"),h(this,w).removeAttribute("aria-haspopup"),h(this,w).removeAttribute("aria-expanded"),M(this,w,null))},H=function(){this.toggleAttribute("open",h(this,I)),E(m`
32
- <slot name="trigger" @slotchange=${h(this,re)}>
33
- <button
34
- class="fallback-trigger"
35
- part="trigger"
36
- type="button"
37
- aria-haspopup="listbox"
38
- aria-expanded=${h(this,I)?"true":"false"}
39
- @click=${h(this,J)}
40
- >
41
- <span class="trigger-label" part="trigger-label">${h(this,g,Oe)}</span>
42
- <span class="trigger-icon" part="trigger-icon" aria-hidden="true">
43
- ${xe({size:14})}
44
- </span>
45
- </button>
46
- </slot>
47
- ${h(this,I)?m`
48
- <div class="panel" part="panel" role="listbox">
49
- <slot></slot>
50
- </div>
51
- `:null}
52
- `,h(this,at)),queueMicrotask(()=>f(this,g,Ne).call(this))},rs.observedAttributes=["title"];let Te=rs;class Yi extends HTMLElement{}class ji extends HTMLElement{}class Zi extends HTMLElement{}var rt,Fe,lr,Mt,Lt;const is=class is extends HTMLElement{constructor(){super(...arguments);y(this,rt);y(this,Mt,()=>{this.action||f(this,rt,lr).call(this)});y(this,Lt,t=>{t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),this.click())})}connectedCallback(){this.hasAttribute("role")||this.setAttribute("role","option"),this.hasAttribute("tabindex")||(this.tabIndex=0),this.addEventListener("click",h(this,Mt)),this.addEventListener("keydown",h(this,Lt)),f(this,rt,Fe).call(this)}disconnectedCallback(){this.removeEventListener("click",h(this,Mt)),this.removeEventListener("keydown",h(this,Lt))}attributeChangedCallback(){f(this,rt,Fe).call(this)}get value(){return this.getAttribute("value")??""}get selected(){return this.hasAttribute("selected")}get action(){return this.hasAttribute("action")}};rt=new WeakSet,Fe=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")},lr=function(){this.dispatchEvent(new sr(this.value))},Mt=new WeakMap,Lt=new WeakMap,is.observedAttributes=["action","selected","value"];let He=is;customElements.get("dropdown-menu")||customElements.define("dropdown-menu",Te);customElements.get("dropdown-group")||customElements.define("dropdown-group",Yi);customElements.get("dropdown-label")||customElements.define("dropdown-label",ji);customElements.get("dropdown-divider")||customElements.define("dropdown-divider",Zi);customElements.get("dropdown-item")||customElements.define("dropdown-item",He);class Qi extends Event{constructor(){super("close",{bubbles:!0,composed:!0})}}var Pt,V,Ge,ie,It,Be;const ns=class ns extends HTMLElement{constructor(){super();y(this,V);y(this,Pt);y(this,ie,t=>{t.target===t.currentTarget&&f(this,V,Ge).call(this)});y(this,It,t=>{this.open&&t.key==="Escape"&&f(this,V,Ge).call(this)});M(this,Pt,this.attachShadow({mode:"open"}))}connectedCallback(){document.addEventListener("keydown",h(this,It)),f(this,V,Be).call(this)}disconnectedCallback(){document.removeEventListener("keydown",h(this,It))}attributeChangedCallback(){f(this,V,Be).call(this)}get open(){return this.hasAttribute("open")}};Pt=new WeakMap,V=new WeakSet,Ge=function(){this.dispatchEvent(new Qi)},ie=new WeakMap,It=new WeakMap,Be=function(){E(m`
53
- ${this.open?m`
54
- <div class="backdrop" part="backdrop" @click=${h(this,ie)}>
55
- <slot></slot>
56
- </div>
57
- `:null}
58
- `,h(this,Pt))},ns.observedAttributes=["open"];let ze=ns;customElements.get("modal-overlay")||customElements.define("modal-overlay",ze);class hr extends Event{constructor(){super("close",{bubbles:!0,composed:!0})}}class Ji extends HTMLElement{}var xt,$,Tt,b,qt,Yt,dr,ur,vt,pr,Rt,Xe;const os=class os extends HTMLElement{constructor(){super();y(this,b);y(this,xt);y(this,$,[]);y(this,Tt,new MutationObserver(()=>f(this,b,pr).call(this)));y(this,Rt,t=>{const e=t.target;if(!(e instanceof Element))return;const i=e.closest("[data-navigate]");if(i){this.navigate(i.dataset.navigate??"");return}e.closest("[data-back]")&&this.back()});M(this,xt,this.attachShadow({mode:"open"}))}connectedCallback(){this.addEventListener("click",h(this,Rt)),h(this,Tt).observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["id","title"]}),f(this,b,vt).call(this)}disconnectedCallback(){this.removeEventListener("click",h(this,Rt)),h(this,Tt).disconnect(),M(this,$,[])}attributeChangedCallback(){f(this,b,Xe).call(this)}get closable(){return this.hasAttribute("closable")}navigate(t){var n;const e=((n=h(this,b,qt))==null?void 0:n.id)??null;t===e||!f(this,b,Yt).call(this,t)||(h(this,$).push(t),f(this,b,vt).call(this))}back(){h(this,$).length<=1||(h(this,$).pop(),f(this,b,vt).call(this))}};xt=new WeakMap,$=new WeakMap,Tt=new WeakMap,b=new WeakSet,qt=function(){const t=h(this,$)[h(this,$).length-1]??null;return t?f(this,b,Yt).call(this,t):null},Yt=function(t){const e=this.querySelectorAll("panel-page");for(const i of e)if(i.id===t)return i;return null},dr=function(){if(M(this,$,h(this,$).filter(e=>f(this,b,Yt).call(this,e)!==null)),h(this,$).length>0)return;const t=this.querySelector("panel-page");t!=null&&t.id&&M(this,$,[t.id])},ur=function(){f(this,b,dr).call(this);const t=h(this,b,qt),e=this.querySelectorAll("panel-page");for(const i of e)i.hidden=i!==t},vt=function(){f(this,b,ur).call(this),f(this,b,Xe).call(this)},pr=function(){f(this,b,vt).call(this)},Rt=new WeakMap,Xe=function(){const t=h(this,b,qt);E(m`
59
- <section class="panel" part="panel">
60
- <header class="title-bar" part="header">
61
- <div class="title-group" part="title-group">
62
- ${h(this,$).length>1?m`
63
- <button
64
- type="button"
65
- class="title-button"
66
- part="button back-button"
67
- aria-label="Back"
68
- @click=${()=>this.back()}
69
- >
70
- <span class="back-icon" part="icon back-icon">
71
- ${xe({size:14})}
72
- </span>
73
- </button>
74
- `:null}
75
- <h2 class="title" part="title">${(t==null?void 0:t.getAttribute("title"))??""}</h2>
76
- </div>
77
- ${this.closable?m`
78
- <button
79
- type="button"
80
- class="title-button"
81
- part="button close-button"
82
- aria-label="Close"
83
- @click=${()=>this.dispatchEvent(new hr)}
84
- >
85
- <span class="close-icon" part="icon close-icon">${er({size:14})}</span>
86
- </button>
87
- `:null}
88
- </header>
89
- <slot></slot>
90
- </section>
91
- `,h(this,xt))},os.observedAttributes=["closable"];let Ve=os;customElements.get("panel-view")||customElements.define("panel-view",Ve);customElements.get("panel-page")||customElements.define("panel-page",Ji);class fr extends Event{constructor(t){super("close-artifact",{bubbles:!0,composed:!0});l(this,"id");this.id=t}}class tn extends HTMLElement{constructor(){super(...arguments);l(this,"_artifact",null);l(this,"_artifactURL",null)}set artifact(t){this._artifact=t,this.render()}get artifact(){return this._artifact}set artifactURL(t){this._artifactURL=t,this.render()}get artifactURL(){return this._artifactURL}handleClose(){this._artifact&&this.dispatchEvent(new fr(this._artifact.id))}template(){const t=this._artifact;return m`
92
- <header class="artifact-title-bar" drag-handle>
93
- <span class="artifact-title">${t.title}</span>
94
- <button
95
- class="artifact-close-btn"
96
- @click=${()=>this.handleClose()}
97
- aria-label="Close"
98
- >${er({size:14})}</button>
99
- </header>
100
- <div class="artifact-content">
101
- ${this.renderContent()}
102
- </div>
103
- `}renderContent(){return m`<iframe
104
- class="artifact-html-frame"
105
- title=${this._artifact.title}
106
- src=${this._artifactURL??"about:blank"}
107
- sandbox="allow-scripts"
108
- style="width: 100%; height: 100%; border: none;"
109
- ></iframe>`}render(){this._artifact&&(this.setAttribute("type",this._artifact.type),E(this.template(),this))}}customElements.define("artifact-view",tn);const $s=1/3;function en(r,s,t,e,i){if(t.length===0)return{index:0};for(let n=0;n<t.length;n+=1){const o=t[n],c=o.right-o.left,a=n<i?o.right-c*$s:o.left+c*$s;if(r<a)return{index:n}}return{index:t.length}}const se=6,gr=2,Ws=gr,sn=gr,rn=se;function nn(r,s,t){var e;if(t.cols>s||t.rows>se)return null;for(let i=0;i<=se-t.rows;i+=1)for(let n=0;n<=s-t.cols;n+=1){let o=!0;for(let c=i;c<i+t.rows&&o;c+=1)for(let a=n;a<n+t.cols;a+=1)if((e=r[c])!=null&&e[a]){o=!1;break}if(o)return{x:n,y:i}}return null}function on(r,s){for(let t=s.y;t<s.y+s.rows;t+=1)for(let e=s.x;e<s.x+s.cols;e+=1)r[t][e]=!0}function Vt(r,s){const t=Array.from({length:se},()=>Array.from({length:s},()=>!1)),e=[];for(const i of r){const n=nn(t,s,i);if(!n)return null;const o={cardIndex:i.cardIndex,x:n.x,y:n.y,cols:i.cols,rows:i.rows};on(t,o),e.push(o)}return e}function le(r){const s=r.map((a,d)=>({cardIndex:d,cols:kt(a.cols),rows:be(a.rows)})),t=[];let e=null;for(const a of s){if(!e){const C=a.cols,N=Vt([a],C);if(!N)continue;e={width:C,cardIndexes:[a.cardIndex],localPlacements:N};continue}const u=[...e.cardIndexes.map(C=>s[C]),a];let p=Vt(u,e.width),k=e.width;if(!p&&e.width<Ws&&a.cols>e.width&&(k=Ws,p=Vt(u,k)),p){e={width:k,cardIndexes:u.map(C=>C.cardIndex),localPlacements:p};continue}t.push(e);const v=a.cols,S=Vt([a],v);S&&(e={width:v,cardIndexes:[a.cardIndex],localPlacements:S})}e&&t.push(e);const i=Array.from({length:r.length},(a,d)=>{var u,p;return{cardIndex:d,bandIndex:0,x:0,y:0,cols:kt(((u=r[d])==null?void 0:u.cols)??sn),rows:be(((p=r[d])==null?void 0:p.rows)??rn)}}),n=Array.from({length:r.length},()=>0),o=[];let c=0;for(let a=0;a<t.length;a+=1){const d=t[a];o.push({index:a,startCol:c,width:d.width,cardIndexes:[...d.cardIndexes]});for(const u of d.localPlacements){const p=c+u.x;i[u.cardIndex]={cardIndex:u.cardIndex,bandIndex:a,x:p,y:u.y,cols:u.cols,rows:u.rows},n[u.cardIndex]=p}c+=d.width}return{placements:i,bands:o,totalColumns:c,cardStartColumns:n}}const Ms=120,an=80,Ls=.5;class cn{constructor(){l(this,"awaitingFreshWheelGesture",!1);l(this,"lastWheelEventAt",Number.NEGATIVE_INFINITY);l(this,"lastWheelDeltaX",0);l(this,"activeGestureType","none");l(this,"lastWheelGestureAt",Number.NEGATIVE_INFINITY)}markKeyboardNavigation(s){this.awaitingFreshWheelGesture=!0,this.lastWheelEventAt=s,this.activeGestureType="none"}reset(){this.awaitingFreshWheelGesture=!1,this.lastWheelEventAt=Number.NEGATIVE_INFINITY,this.lastWheelDeltaX=0,this.activeGestureType="none",this.lastWheelGestureAt=Number.NEGATIVE_INFINITY}decide(s){const{now:t,shiftKey:e,deltaX:i,deltaY:n,overArtifactContent:o,artifactCanScrollUp:c,artifactCanScrollDown:a}=s;t-this.lastWheelGestureAt>=Ms&&(this.activeGestureType="none");const u=e&&n!==0,p=u?n:i,k=n>0?a:n<0?c:!1;if(this.activeGestureType==="vertical-artifact"&&o&&k)return this.lastWheelGestureAt=t,{type:"scroll-native"};if(this.activeGestureType==="horizontal-filmstrip"&&Math.abs(p)>=Ls)return this.lastWheelGestureAt=t,this.lastWheelEventAt=t,this.lastWheelDeltaX=p,{type:"scroll-horizontal",horizontalDelta:p};if(Math.abs(p)<Ls)return o&&k&&(this.activeGestureType="vertical-artifact"),this.lastWheelGestureAt=t,{type:"scroll-native"};if(!u&&o&&k&&Math.abs(n)>=Math.abs(p))return this.activeGestureType="vertical-artifact",this.lastWheelGestureAt=t,{type:"scroll-native"};const v=t-this.lastWheelEventAt,S=Math.sign(this.lastWheelDeltaX),C=Math.sign(p),N=S!==0&&C!==0&&S!==C,it=S!==0&&Math.abs(p)>=Math.abs(this.lastWheelDeltaX)+an;return this.lastWheelEventAt=t,this.lastWheelDeltaX=p,this.lastWheelGestureAt=t,this.awaitingFreshWheelGesture&&v<Ms&&!N&&!it?{type:"ignore"}:(this.awaitingFreshWheelGesture=!1,this.activeGestureType="horizontal-filmstrip",{type:"scroll-horizontal",horizontalDelta:p})}}const Y=600,j=800,U=16,ln=800,Ps=.85,hn=.8,dn=200,un=500,pn=5,Is=50,fn=2,gn=60,A=1e-4,mn=1e3;function jt(r,s,t,e){const i=kt(r),n=be(s),o=t<ln,c=o?t*Ps:Y,a=o?e*Ps:j,d=e*hn,u=Math.min(a,d);return{cols:i,rows:n,width:c*(i/x),height:u*(n/B)}}function he(r,s){return jt(1,B,r,s).width}function xs(r,s){const t=he(r,s);return Math.max(1,Math.floor((r+U)/(t+U)))}function Ts(r,s){return r.length===0||!r.every(e=>kt(e.cols)===x)||s<x?s:Math.max(x,Math.floor(s/x)*x)}function vn(r){return le(r).totalColumns}function wn(r,s){return Math.max(0,vn(r)-s)}function Ut(r){const s=le(r);return[...new Set([0,...s.cardStartColumns,s.totalColumns])].sort((e,i)=>e-i)}function Rs(r,s){return s.some(t=>Math.abs(t-r)<A)}function Os(r,s){const t=Ut(r);for(const e of t)if(e>s+A)return e;return t[t.length-1]??0}function kn(r,s){const t=Ut(r);let e=t[0]??0;for(const i of t){if(i<=s+A){e=i;continue}break}return e}function yn(r,s){const t=Ut(r);let e=t[0]??0;for(const i of t){if(i<s-A){e=i;continue}break}return e}function Ns(r,s,t,e,i="start"){const n=r.totalColumns;if(n<=0)return 0;const o=he(t,e),c=u=>u<=0?0:u*o+Math.max(0,u-1)*U,a=Math.min(Math.max(0,s),n);let d=0;for(let u=0;u<r.bands.length;u+=1){const p=r.bands[u],k=p.startCol,v=p.startCol+p.width;if(a<v-A){const S=Math.max(0,a-k);return d+c(S)}if(Math.abs(a-v)<=A){const S=d+c(p.width);return u===r.bands.length-1?S:i==="start"?S+U:S}d+=c(p.width),u<r.bands.length-1&&(d+=U)}return a<=A?0:Math.abs(a-n)<=A?r.bands[r.bands.length-1]?d:0:d}function bn(r,s,t,e,i,n=!0){const o=le(r),c=o.totalColumns,a=Math.max(0,c-i),d=Math.min(Math.max(0,s),a),u=he(t,e),p=new Map;let k=0;for(let D=0;D<o.bands.length;D+=1){const T=o.bands[D];p.set(T.index,k),k+=T.width*u+Math.max(0,T.width-1)*U,D<o.bands.length-1&&(k+=U)}const v=D=>{const T=D,ut=Math.min(D+i,c),Ht=o.bands.map(W=>{const $r=W.startCol,Wr=W.startCol+W.width,ls=p.get(W.index)??0,Mr=W.width*u+Math.max(0,W.width-1)*U,Lr=ls+Mr;return{start:$r,end:Wr,left:ls,right:Lr}}).filter(W=>W.start>=T-A&&W.end<=ut+A),cs=Ht.length>0?Math.min(...Ht.map(W=>W.left)):Ns(o,T,t,e,"start"),Dr=Ht.length>0?Math.max(...Ht.map(W=>W.right)):Ns(o,ut,t,e,"end"),Cr=Math.max(0,Dr-cs);return(t-Cr)/fn-cs},C=[...new Set([0,a,...Ut(r).filter(D=>D>=0&&D<=a)])].sort((D,T)=>D-T);let N=C[0]??0,it=C[C.length-1]??a;for(let D=0;D<C.length-1;D+=1){const T=C[D],ut=C[D+1];if(d>=T-A&&d<=ut+A){N=T,it=ut;break}}if(Math.abs(it-N)<A||!n)return v(d);const as=v(N),Ar=v(it),Er=(d-N)/(it-N);return as+(Ar-as)*Er}class Sn extends Event{constructor(t){super("scroll",{bubbles:!0,composed:!0});l(this,"scrollPosition");this.scrollPosition=t}}class _n extends Event{constructor(t){super("card-order-changed",{bubbles:!0,composed:!0});l(this,"ids");this.ids=t}}class mr extends Event{constructor(t){super("card-layout-resize-requested",{bubbles:!0,composed:!0});l(this,"id");this.id=t}}const Us="[drag-handle]";class An extends HTMLElement{constructor(){super(...arguments);l(this,"_cards",[]);l(this,"_dragHandleSelector",Us);l(this,"_scrollPosition",0);l(this,"_trackEl",null);l(this,"resizeObserver",null);l(this,"renderPending",!1);l(this,"animateNextRender",!0);l(this,"wheelGesture",new cn);l(this,"dragStatus","idle");l(this,"dragPointerID",null);l(this,"dragCardID",null);l(this,"dragCardIndex",-1);l(this,"dragStartX",0);l(this,"dragStartY",0);l(this,"dragPointerX",0);l(this,"dragPointerY",0);l(this,"dragOffsetX",0);l(this,"dragOffsetY",0);l(this,"dragPlaceholderIndex",0);l(this,"dragHoldTimer",null);l(this,"capturedDragTarget",null);l(this,"autoScrollFrame",null);l(this,"autoScrollDirection",0);l(this,"autoScrollLastFrameAt",null);l(this,"handlePointerMove",t=>{if(t.pointerId===this.dragPointerID){if(this.dragPointerX=t.clientX,this.dragPointerY=t.clientY,this.dragStatus==="pending"){this.getDragDistance()>pn&&this.startDragging();return}this.dragStatus==="dragging"&&(t.preventDefault(),this.updateDropTargetFromDOM(),this.updateAutoScrollDirection(),this.scheduleRender())}});l(this,"handlePointerUp",t=>{if(t.pointerId===this.dragPointerID){if(this.dragStatus==="dragging"){t.preventDefault(),this.finishDragging();return}this.dragStatus==="pending"&&this.dragCardID!==null&&this.emitCardLayoutResizeRequested(this.dragCardID),this.resetDragState()}});l(this,"handlePointerCancel",t=>{t.pointerId===this.dragPointerID&&this.cancelDragging()});l(this,"stepAutoScroll",t=>{if(this.dragStatus!=="dragging"||this.autoScrollDirection===0){this.stopAutoScroll();return}const e=this.autoScrollLastFrameAt??t,i=t-e;this.autoScrollLastFrameAt=t;const n=gn*i*this.autoScrollDirection/mn/this.getColumnStep(),o=this.clampScrollPosition(this._scrollPosition+n);Math.abs(o-this._scrollPosition)>=A&&(this._scrollPosition=o,this.emitScrollPositionChanged(this._scrollPosition),this.animateNextRender=!1,this.scheduleRender(),queueMicrotask(()=>this.updateDropTargetFromDOM())),this.autoScrollFrame=requestAnimationFrame(this.stepAutoScroll)});l(this,"handleKeyDown",t=>{if(t.key==="Escape"&&this.dragStatus!=="idle"){t.preventDefault(),this.cancelDragging();return}(t.key==="ArrowRight"||t.key==="ArrowLeft")&&this.wheelGesture.markKeyboardNavigation(Date.now()),t.key==="ArrowRight"?(t.preventDefault(),this.shiftWindow(1)):t.key==="ArrowLeft"&&(t.preventDefault(),this.shiftWindow(-1))});l(this,"handleWindowKeyDown",t=>{document.activeElement!==this&&(t.defaultPrevented||t.key!=="ArrowLeft"&&t.key!=="ArrowRight"&&t.key!=="Escape"||t.target instanceof HTMLInputElement||t.target instanceof HTMLTextAreaElement||t.target instanceof HTMLElement&&t.target.isContentEditable||this.matches(":hover")&&(this.focus({preventScroll:!0}),this.handleKeyDown(t)))});l(this,"handleWheel",t=>{document.activeElement!==this&&this.focus({preventScroll:!0});const e=t.target instanceof Element?t.target:null,i=e==null?void 0:e.closest(".artifact-content"),n=i?i.scrollTop+i.clientHeight<i.scrollHeight-A:!1,o=i?i.scrollTop>A:!1,c=this.wheelGesture.decide({now:Date.now(),shiftKey:t.shiftKey,deltaX:t.deltaX,deltaY:t.deltaY,overArtifactContent:i!==null,artifactCanScrollUp:o,artifactCanScrollDown:n});c.type==="scroll-native"||c.type==="ignore"||(t.preventDefault(),this._scrollPosition=this.clampScrollPosition(this._scrollPosition+c.horizontalDelta/this.getColumnStep()),this.emitScrollPositionChanged(this._scrollPosition),this.animateNextRender=!1,this.scheduleRender())})}set cards(t){this._cards=t.filter(e=>e.type==="content"),this._scrollPosition=this.clampScrollPosition(this._scrollPosition),this.scheduleRender()}get cards(){return this._cards}set dragHandleSelector(t){this._dragHandleSelector=t.trim()||Us,this.scheduleRender()}get dragHandleSelector(){return this._dragHandleSelector}set scrollPosition(t){const e=this.clampScrollPosition(t);Math.abs(e-this._scrollPosition)<A||(this._scrollPosition=e,this.animateNextRender=!1,this.scheduleRender())}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("pointermove",this.handlePointerMove),this.addEventListener("pointerup",this.handlePointerUp),this.addEventListener("pointercancel",this.handlePointerCancel),window.addEventListener("keydown",this.handleWindowKeyDown),typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>this.renderView()),this.resizeObserver.observe(this)),this.renderView()}disconnectedCallback(){var t;this.removeEventListener("keydown",this.handleKeyDown),this.removeEventListener("wheel",this.handleWheel),this.removeEventListener("pointermove",this.handlePointerMove),this.removeEventListener("pointerup",this.handlePointerUp),this.removeEventListener("pointercancel",this.handlePointerCancel),window.removeEventListener("keydown",this.handleWindowKeyDown),(t=this.resizeObserver)==null||t.disconnect(),this.resizeObserver=null,this._trackEl=null,this.wheelGesture.reset(),this.clearDragHoldTimer(),this.stopAutoScroll()}scheduleRender(){this.renderPending||(this.renderPending=!0,queueMicrotask(()=>{this.renderPending=!1,this.renderView()}))}contentCards(){return this._cards.filter(t=>t.type==="content")}getColumnStep(){const t=this.clientWidth>0?this.clientWidth:Y,e=this.clientHeight>0?this.clientHeight:j;return he(t,e)+U}clampScrollPosition(t){const e=this.clientWidth>0?this.clientWidth:Y,i=this.clientHeight>0?this.clientHeight:j,n=Ts(this.contentCards(),xs(e,i)),o=wn(this.contentCards(),n);return Math.min(o,Math.max(0,t))}emitScrollPositionChanged(t){this.dispatchEvent(new Sn(t))}emitCardOrderChanged(t){this.dispatchEvent(new _n(t))}emitCardLayoutResizeRequested(t){this.dispatchEvent(new mr(t))}shiftWindow(t){const e=this.contentCards();if(e.length===0)return;const i=Ut(e);let n=this._scrollPosition;t===1?(Rs(n,i)||(n=Os(e,n)),n=Os(e,n+A)):Rs(n,i)?n=yn(e,n):n=kn(e,n),n=this.clampScrollPosition(n),!(Math.abs(n-this._scrollPosition)<A)&&(this._scrollPosition=n,this.emitScrollPositionChanged(this._scrollPosition),this.animateNextRender=!0,this.scheduleRender())}getRestoreScrollPositionForCard(t){const e=this.contentCards();if(e.length===0||t<0)return this._scrollPosition;let i=0;for(let n=0;n<t&&n<e.length;n+=1)i+=kt(e[n].cols);return this.clampScrollPosition(i)}pointerTargetMatchesDragHandle(t){if(!(t instanceof Element))return!1;const e=t.getRootNode();if(!(e instanceof ShadowRoot)&&!(e instanceof Document))return!1;try{return t.closest(this._dragHandleSelector)!==null}catch{return!1}}handleCardPointerDown(t,e){if(t.pointerType==="touch")return;const i=t.target;if(!(i instanceof Element)||i.closest(".artifact-close-btn")||!this.pointerTargetMatchesDragHandle(i))return;const n=t.currentTarget;if(!(n instanceof HTMLElement))return;const o=this.contentCards().findIndex(a=>a.id===e);if(o===-1)return;const c=n.getBoundingClientRect();this.clearDragHoldTimer(),this.stopAutoScroll(),this.dragStatus="pending",this.dragPointerID=t.pointerId,this.dragCardID=e,this.dragCardIndex=o,this.dragStartX=t.clientX,this.dragStartY=t.clientY,this.dragPointerX=t.clientX,this.dragPointerY=t.clientY,this.dragOffsetX=t.clientX-c.left,this.dragOffsetY=t.clientY-c.top,this.dragPlaceholderIndex=o,this.capturedDragTarget=n,n.setPointerCapture(t.pointerId),this.dragHoldTimer=setTimeout(()=>{this.startDragging()},un)}getDragDistance(){return Math.hypot(this.dragPointerX-this.dragStartX,this.dragPointerY-this.dragStartY)}startDragging(){this.dragStatus!=="pending"||this.dragCardID===null||(this.clearDragHoldTimer(),this.dragStatus="dragging",this.updateAutoScrollDirection(),this.scheduleRender())}finishDragging(){if(this.dragStatus!=="dragging"||this.dragCardID===null){this.resetDragState();return}const t=this.contentCards(),e=[...t],[i]=e.splice(this.dragCardIndex,1);i&&e.splice(this.dragPlaceholderIndex,0,i);const n=e.map(c=>c.id),o=n.some((c,a)=>{var d;return c!==((d=t[a])==null?void 0:d.id)});this.resetDragState(),o&&this.emitCardOrderChanged(n),this.scheduleRender()}cancelDragging(){this.resetDragState(),this.scheduleRender()}resetDragState(){this.clearDragHoldTimer(),this.stopAutoScroll(),this.capturedDragTarget&&this.dragPointerID!==null&&this.capturedDragTarget.hasPointerCapture(this.dragPointerID)&&this.capturedDragTarget.releasePointerCapture(this.dragPointerID),this.dragStatus="idle",this.dragPointerID=null,this.dragCardID=null,this.dragCardIndex=-1,this.dragPlaceholderIndex=0,this.capturedDragTarget=null}clearDragHoldTimer(){this.dragHoldTimer!==null&&(clearTimeout(this.dragHoldTimer),this.dragHoldTimer=null)}updateDropTargetFromDOM(){if(this.dragStatus!=="dragging"||this.dragCardID===null)return;const t=this.contentCards().find(n=>n.id===this.dragCardID);t&&jt(t.cols,t.rows,this.clientWidth||Y,this.clientHeight||j);const e=[...this.querySelectorAll(".track .card-slot[data-layout-card-id]")].filter(n=>n instanceof HTMLElement&&n.getAttribute("data-layout-card-id")!==this.dragCardID).map(n=>{const o=n.getBoundingClientRect();return{left:o.left,right:o.right,top:o.top,bottom:o.bottom}}),{index:i}=en(this.dragPointerX,this.dragPointerY,e,{},this.dragPlaceholderIndex);i!==this.dragPlaceholderIndex&&(this.dragPlaceholderIndex=i,this.scheduleRender())}updateAutoScrollDirection(){if(this.dragStatus!=="dragging"){this.stopAutoScroll();return}let t=0;if(this.dragPointerX<=Is?t=-1:window.innerWidth-this.dragPointerX<=Is&&(t=1),t===0){this.stopAutoScroll();return}this.autoScrollFrame!==null&&this.autoScrollDirection===t||(this.stopAutoScroll(),this.autoScrollDirection=t,this.autoScrollLastFrameAt=null,this.autoScrollFrame=requestAnimationFrame(this.stepAutoScroll))}stopAutoScroll(){this.autoScrollFrame!==null&&(cancelAnimationFrame(this.autoScrollFrame),this.autoScrollFrame=null),this.autoScrollDirection=0,this.autoScrollLastFrameAt=null}getRenderableCards(){const t=this.contentCards();if(this.dragStatus!=="dragging"||this.dragCardID===null)return t.map(a=>({type:"content",card:a}));const e=t.find(a=>a.id===this.dragCardID),i=(e==null?void 0:e.cols)??x,n=(e==null?void 0:e.rows)??B,c=t.filter(a=>a.id!==this.dragCardID).map(a=>({type:"content",card:a}));return c.splice(this.dragPlaceholderIndex,0,{type:"placeholder",cols:i,rows:n}),c}getDraggedCard(){return this.dragCardID===null?null:this.contentCards().find(t=>t.id===this.dragCardID)??null}getBaseLayoutDimensions(){const t=this.clientWidth>0?this.clientWidth:Y,e=this.clientHeight>0?this.clientHeight:j,i=jt(x,B,t,e);return{cardWidth:i.width,cardHeight:i.height,colWidth:i.width/x,rowHeight:i.height/B}}calculateTranslateX(){const t=this.contentCards(),e=this.clientWidth>0?this.clientWidth:Y,i=this.clientHeight>0?this.clientHeight:j,n=Ts(t,xs(e,i));return bn(t,this._scrollPosition,e,i,n,this.dragStatus==="idle")}template(){const t=this.clientWidth>0?this.clientWidth:Y,e=this.clientHeight>0?this.clientHeight:j,i=this.getRenderableCards(),n=this.getDraggedCard(),o=le(i.map(a=>a.type==="content"?{cols:a.card.cols,rows:a.card.rows}:{cols:a.cols,rows:a.rows})),c=new Map;for(let a=0;a<i.length;a+=1){const d=i[a],u=o.placements[a];if(!u)continue;const p=c.get(u.bandIndex)??[];p.push({item:d,placement:u}),c.set(u.bandIndex,p)}return m`
110
- <div class="track">
111
- ${o.bands.map(a=>{const d=c.get(a.index)??[];return m`
112
- <div class="band" layout-band=${String(a.index)} layout-band-cols=${String(a.width)}>
113
- ${d.map(({item:u,placement:p})=>{const k=`grid-column: ${p.x-a.startCol+1} / span ${p.cols}; grid-row: ${p.y+1} / span ${p.rows};`;if(u.type==="placeholder")return m`
114
- <div
115
- class="card-slot placeholder"
116
- layout-cols=${String(u.cols)}
117
- layout-rows=${String(u.rows)}
118
- layout-band=${String(p.bandIndex)}
119
- style=${k}
120
- ></div>
121
- `;const{card:v}=u;return m`
122
- <div
123
- class="card-slot"
124
- data-layout-card-id=${v.id}
125
- layout-cols=${String(v.cols)}
126
- layout-rows=${String(v.rows)}
127
- layout-band=${String(p.bandIndex)}
128
- style=${k}
129
- @pointerdown=${S=>this.handleCardPointerDown(S,v.id)}
130
- >
131
- ${v.render()}
132
- </div>
133
- `})}
134
- </div>
135
- `})}
136
- </div>
137
- ${this.dragStatus==="dragging"&&n?(()=>{const a=jt(n.cols,n.rows,t,e);return m`
138
- <div
139
- class="card-slot dragging"
140
- data-layout-card-id=${n.id}
141
- layout-cols=${String(a.cols)}
142
- layout-rows=${String(a.rows)}
143
- style="
144
- width: ${a.width}px;
145
- height: ${a.height}px;
146
- left: ${this.dragPointerX-this.dragOffsetX}px;
147
- top: ${this.dragPointerY-this.dragOffsetY}px;
148
- "
149
- >
150
- ${n.render()}
151
- </div>
152
- `})():null}
153
- `}updateTrackPosition(t){if(!this._trackEl)return;this._trackEl.style.transition=t?`transform ${dn}ms ease`:"none";const e=this.calculateTranslateX();this._trackEl.style.transform=`translateX(${e}px)`}renderView(){const t=this.animateNextRender;this.animateNextRender=!0,this._scrollPosition=this.clampScrollPosition(this._scrollPosition);const e=this.getBaseLayoutDimensions();this.style.setProperty("--layout-col-width",`${e.colWidth}px`),this.style.setProperty("--layout-row-height",`${e.rowHeight}px`),this.style.setProperty("--layout-gap",`${U}px`),E(this.template(),this),this._trackEl||(this._trackEl=this.querySelector(".track")),this.updateTrackPosition(t)}}customElements.define("layout-stream",An);class En extends HTMLElement{constructor(){super(...arguments);l(this,"workspaceService",L.resolve("WorkspaceService"));l(this,"subscriptions",new dt);l(this,"handleCloseArtifact",t=>{t instanceof fr&&this.workspaceService.removeArtifact(t.id)});l(this,"handleResizeArtifactLayout",t=>{t instanceof mr&&this.workspaceService.cycleArtifactLayout(t.id)});l(this,"handleScrollPositionChanged",t=>{const e=t;typeof e.scrollPosition=="number"&&Number.isFinite(e.scrollPosition)&&this.workspaceService.setScrollPosition(e.scrollPosition)});l(this,"handleCardOrderChanged",t=>{const e=t;Array.isArray(e.ids)&&e.ids.length>0&&this.workspaceService.reorderLayout(e.ids)})}connectedCallback(){this.render(),this.subscriptions.add(this.workspaceService.on("change",()=>this.render()))}disconnectedCallback(){this.subscriptions.dispose()}buildLayoutCards(){const t=this.workspaceService.activeWorkspace;if(!t)return[];const e=new Map(this.workspaceService.activeArtifacts.map(i=>[i.id,i]));return t.layout.map(i=>{const n=e.get(i.artifactID);return n?{id:i.artifactID,cols:i.cols,rows:i.rows,type:"content",render:()=>m`<artifact-view
154
- .artifact=${n}
155
- .artifactURL=${this.workspaceService.getArtifactURL(i.artifactID)}
156
- ></artifact-view>`}:null}).filter(i=>i!==null)}render(){const t=this.buildLayoutCards();if(t.length===0){E(m`<p data-testid="empty-workspace">No artifacts yet.</p>`,this);return}E(m`
157
- <layout-stream
158
- .cards=${t}
159
- .scrollPosition=${this.workspaceService.scrollPosition}
160
- @scroll=${this.handleScrollPositionChanged}
161
- @card-order-changed=${this.handleCardOrderChanged}
162
- @close-artifact=${this.handleCloseArtifact}
163
- @card-layout-resize-requested=${this.handleResizeArtifactLayout}
164
- ></layout-stream>
165
- `,this)}}customElements.define("workspace-view",En);class Dn extends Event{constructor(){super("edit-workspace",{bubbles:!0,composed:!0})}}class vr extends Event{constructor(t){super("create-workspace",{bubbles:!0,composed:!0});l(this,"serverURL");this.serverURL=t}}class Cn extends Event{constructor(){super("delete-workspace",{bubbles:!0,composed:!0})}}class $n extends HTMLElement{constructor(){super(...arguments);l(this,"workspaceService",L.resolve("WorkspaceService"));l(this,"serverManager",L.has("ServerManager")?L.resolve("ServerManager"):null);l(this,"subscriptions",new dt)}connectedCallback(){this.render(),this.subscriptions.add(this.workspaceService.on("change",()=>this.render())),this.serverManager&&this.subscriptions.add(this.serverManager.on("servers-changed",()=>this.render()))}disconnectedCallback(){this.subscriptions.dispose()}handleSelect(t){t instanceof rr&&this.workspaceService.setActiveWorkspace(t.value)}closeDropdown(){var t;(t=this.querySelector("dropdown-menu"))==null||t.close()}handleEditWorkspace(){this.workspaceService.activeWorkspace&&(this.closeDropdown(),this.dispatchEvent(new Dn))}handleCreateWorkspace(t){this.closeDropdown(),this.dispatchEvent(new vr(t))}handleDeleteWorkspace(){this.workspaceService.activeWorkspace&&(this.closeDropdown(),this.dispatchEvent(new Cn))}render(){var c;const t=((c=this.workspaceService.activeWorkspace)==null?void 0:c.name)??"No workspaces",e=this.serverManager?[...this.serverManager.servers.values()]:[],i=this.serverManager?e.map(a=>({...a,sortedWorkspaces:[...a.workspaces.values()].sort((d,u)=>d.name.localeCompare(u.name,void 0,{sensitivity:"base"}))})):[],n=this.serverManager?[]:[...this.workspaceService.workspaces??[]].sort((a,d)=>a.name.localeCompare(d.name,void 0,{sensitivity:"base"})),o=this.workspaceService.activeWorkspaceServerURL;E(m`
166
- <dropdown-menu
167
- title=${t}
168
- @select=${a=>this.handleSelect(a)}
169
- >
170
- <button
171
- slot="trigger"
172
- trigger
173
- type="button"
174
- aria-label="Choose workspace"
175
- ></button>
176
- ${this.serverManager?i.map(a=>m`
177
- <dropdown-group>
178
- <dropdown-label>${a.name}</dropdown-label>
179
- ${a.sortedWorkspaces.map(d=>this.renderWorkspaceItem(d))}
180
- <dropdown-item action @click=${()=>this.handleCreateWorkspace(a.url)}>
181
- + New workspace
182
- </dropdown-item>
183
- </dropdown-group>
184
- `):m`
185
- <dropdown-group>
186
- ${n.map(a=>this.renderWorkspaceItem(a))}
187
- ${o?m`
188
- <dropdown-item action @click=${()=>this.handleCreateWorkspace(o)}>
189
- + New workspace
190
- </dropdown-item>
191
- `:null}
192
- </dropdown-group>
193
- `}
194
- ${this.workspaceService.activeWorkspace?m`
195
- <dropdown-divider></dropdown-divider>
196
- <dropdown-group>
197
- <dropdown-item action @click=${()=>this.handleEditWorkspace()}>
198
- Edit workspace...
199
- </dropdown-item>
200
- <dropdown-item action danger @click=${()=>this.handleDeleteWorkspace()}>
201
- Delete workspace...
202
- </dropdown-item>
203
- </dropdown-group>
204
- `:null}
205
- </dropdown-menu>
206
- `,this)}renderWorkspaceItem(t){var i;const e=t.id===this.workspaceService.activeWorkspaceID?((i=this.workspaceService.activeWorkspace)==null?void 0:i.name)??t.name:t.name;return m`
207
- <dropdown-item
208
- value=${t.id}
209
- ?selected=${t.id===this.workspaceService.activeWorkspaceID}
210
- >
211
- ${e}
212
- </dropdown-item>
213
- `}}customElements.define("workspace-picker",$n);class wr extends HTMLElement{constructor(){super(...arguments);l(this,"workspaceService",L.resolve("WorkspaceService"));l(this,"subscriptions",new dt);l(this,"_mode","edit");l(this,"_targetServerURL");l(this,"createPending",!1)}get open(){return this.hasAttribute("open")}set mode(t){this._mode=t,this.render()}get mode(){return this._mode}set targetServerURL(t){this._targetServerURL=t,this.render()}get targetServerURL(){return this._targetServerURL}attributeChangedCallback(t){t==="open"&&(this.open||(this.createPending=!1),this.render())}connectedCallback(){this.render(),this.subscriptions.add(this.workspaceService.on("change",()=>this.render()))}disconnectedCallback(){this.subscriptions.dispose()}emitClose(){this.dispatchEvent(new Event("close",{bubbles:!0}))}async handleSubmit(t){t.preventDefault();const e=t.currentTarget,i=new FormData(e),n=String(i.get("name")??"").trim();if(n){if(this._mode==="edit"){this.workspaceService.renameWorkspace(n),this.emitClose();return}if(this._targetServerURL){this.createPending=!0,this.render();try{await this.workspaceService.createWorkspace(this._targetServerURL,n),this.emitClose()}catch{this.createPending=!1,this.render()}}}}render(){var n;const t=this._mode==="edit"?"Edit workspace":"New workspace",e=this._mode==="edit"?"Save":this.createPending?"Creating...":"Create",i=this._mode==="edit"?((n=this.workspaceService.activeWorkspace)==null?void 0:n.name)??"":"";E(m`
214
- <modal-overlay ?open=${this.open}>
215
- <section class="workspace-modal">
216
- <form class="workspace-form" @submit=${o=>void this.handleSubmit(o)}>
217
- <h2 class="workspace-modal-title">${t}</h2>
218
- <label class="settings-field">
219
- <span>Name</span>
220
- <input type="text" name="name" .value=${i} required />
221
- </label>
222
- <div class="workspace-form-actions">
223
- <button type="submit" class="settings-submit-button" ?disabled=${this.createPending}>
224
- ${e}
225
- </button>
226
- <button type="button" class="settings-cancel-button" @click=${()=>this.emitClose()}>
227
- Cancel
228
- </button>
229
- </div>
230
- </form>
231
- </section>
232
- </modal-overlay>
233
- `,this)}}l(wr,"observedAttributes",["open"]);customElements.define("workspace-form-modal",wr);class kr extends HTMLElement{constructor(){super(...arguments);l(this,"workspaceService",L.resolve("WorkspaceService"));l(this,"serverManager",L.has("ServerManager")?L.resolve("ServerManager"):null);l(this,"subscriptions",new dt);l(this,"deletePending",!1);l(this,"deleteError",null)}get open(){return this.hasAttribute("open")}attributeChangedCallback(t,e,i){t==="open"&&(i!==null&&e===null&&(this.deletePending=!1,this.deleteError=null),this.render())}connectedCallback(){this.render(),this.subscriptions.add(this.workspaceService.on("change",()=>this.render())),this.serverManager&&this.subscriptions.add(this.serverManager.on("servers-changed",()=>this.render()))}disconnectedCallback(){this.subscriptions.dispose()}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(t){this.deletePending=!1,this.deleteError=t instanceof Error?t.message:String(t),this.render()}}render(){var e;const t=this.workspaceService.activeWorkspaceServerURL!==null&&this.serverManager!==null&&this.workspaceService.activeWorkspaceServerURL!==this.serverManager.localServerURL;E(m`
234
- <modal-overlay ?open=${this.open}>
235
- <section class="workspace-modal workspace-delete-modal">
236
- <div class="workspace-form">
237
- <h2 class="workspace-modal-title">Delete workspace</h2>
238
- <p class="workspace-delete-copy">
239
- Delete <strong>${((e=this.workspaceService.activeWorkspace)==null?void 0:e.name)??""}</strong>?
240
- </p>
241
- ${t?m`<p class="workspace-delete-warning">This will delete it for everyone.</p>`:null}
242
- ${this.deleteError?m`<p class="workspace-delete-error">${this.deleteError}</p>`:null}
243
- <div class="workspace-form-actions">
244
- <button
245
- type="button"
246
- class="settings-server-remove-button"
247
- ?disabled=${this.deletePending}
248
- @click=${()=>void this.handleDeleteWorkspace()}
249
- >
250
- ${this.deletePending?"Deleting...":"Delete"}
251
- </button>
252
- <button
253
- type="button"
254
- class="settings-cancel-button"
255
- ?disabled=${this.deletePending}
256
- @click=${()=>this.emitClose()}
257
- >
258
- Cancel
259
- </button>
260
- </div>
261
- </div>
262
- </section>
263
- </modal-overlay>
264
- `,this)}}l(kr,"observedAttributes",["open"]);customElements.define("workspace-delete-modal",kr);class yr extends HTMLElement{constructor(){super(...arguments);l(this,"serverManager",L.has("ServerManager")?L.resolve("ServerManager"):null);l(this,"subscriptions",new dt);l(this,"addServerFormOpen",!1)}get open(){return this.hasAttribute("open")}attributeChangedCallback(t){t==="open"&&(this.open||(this.addServerFormOpen=!1),this.render())}connectedCallback(){this.render(),this.serverManager&&this.subscriptions.add(this.serverManager.on("servers-changed",()=>this.render()))}disconnectedCallback(){this.subscriptions.dispose()}emitClose(){this.dispatchEvent(new Event("close",{bubbles:!0}))}openAddServerForm(){this.addServerFormOpen=!0,this.render()}closeAddServerForm(){this.addServerFormOpen&&(this.addServerFormOpen=!1,this.render())}handleAddServer(t){if(!this.serverManager)return;t.preventDefault();const e=t.currentTarget,i=new FormData(e),n=String(i.get("name")??"").trim(),o=String(i.get("url")??"").trim();!n||!o||(this.serverManager.addServer(o,n),this.addServerFormOpen=!1,e.reset(),this.render())}render(){const t=this.serverManager?[...this.serverManager.servers.values()]:[],e=this.serverManager!==null;E(m`
265
- <modal-overlay ?open=${this.open}>
266
- <section class="settings-panel">
267
- <panel-view closable @close=${i=>i instanceof hr&&this.emitClose()}>
268
- <panel-page id="main" title="Settings">
269
- <div class="settings-section">
270
- ${e?m`
271
- <h3 class="settings-section-title">Servers</h3>
272
- <div class="settings-server-list">
273
- ${t.map(i=>{var n;return m`
274
- <div class="settings-card settings-server">
275
- <div class="settings-server-details">
276
- <div class="settings-server-name">${i.name}</div>
277
- <div class="settings-server-url">${i.url}</div>
278
- </div>
279
- ${i.url!==((n=this.serverManager)==null?void 0:n.localServerURL)?m`
280
- <button
281
- type="button"
282
- class="settings-server-remove-button"
283
- aria-label=${`Remove ${i.name}`}
284
- @click=${()=>{var o;return(o=this.serverManager)==null?void 0:o.removeServer(i.url)}}
285
- >
286
- Remove
287
- </button>
288
- `:null}
289
- </div>
290
- `})}
291
- </div>
292
- ${this.addServerFormOpen?m`
293
- <form class="settings-card settings-add-server-form" @submit=${i=>this.handleAddServer(i)}>
294
- <label class="settings-field">
295
- <span>Name</span>
296
- <input type="text" name="name" required />
297
- </label>
298
- <label class="settings-field">
299
- <span>URL</span>
300
- <input type="url" name="url" required />
301
- </label>
302
- <div class="settings-form-actions">
303
- <button type="submit" class="settings-submit-button">Connect</button>
304
- <button
305
- type="button"
306
- class="settings-cancel-button"
307
- data-action="cancel-connect-form"
308
- @click=${()=>this.closeAddServerForm()}
309
- >
310
- Cancel
311
- </button>
312
- </div>
313
- </form>
314
- `:m`
315
- <button
316
- type="button"
317
- class="settings-submit-button settings-connect-button"
318
- data-action="show-connect-form"
319
- @click=${()=>this.openAddServerForm()}
320
- >
321
- + Connect to server
322
- </button>
323
- `}
324
- `:m`<p class="settings-copy">No additional settings yet.</p>`}
325
- </div>
326
- </panel-page>
327
- </panel-view>
328
- </section>
329
- </modal-overlay>
330
- `,this)}}l(yr,"observedAttributes",["open"]);customElements.define("settings-modal",yr);class br extends Event{constructor(t){super("auth-submit",{bubbles:!0,composed:!0});l(this,"token");this.token=t}}class Wn extends HTMLElement{constructor(){super(...arguments);l(this,"_invalid",!1);l(this,"_tokenValue","")}set invalid(t){this._invalid=t,this.render()}get invalid(){return this._invalid}set tokenValue(t){this._tokenValue=t,this.render()}get tokenValue(){return this._tokenValue}connectedCallback(){this.render()}handleInput(t){const e=t.currentTarget;this._tokenValue=e.value}handleSubmit(t){t.preventDefault();const e=this._tokenValue.trim();e&&this.dispatchEvent(new br(e))}render(){E(m`
331
- <modal-overlay open>
332
- <section class="auth-modal">
333
- <form class="auth-form" @submit=${t=>this.handleSubmit(t)}>
334
- <h2 class="auth-modal-title">Enter access token</h2>
335
- <p class="auth-modal-copy">This Television server requires a token.</p>
336
- <label class="settings-field">
337
- <span>Token</span>
338
- <input
339
- class=${this.invalid?"auth-token-input-invalid":""}
340
- type="password"
341
- name="token"
342
- .value=${this.tokenValue}
343
- @input=${t=>this.handleInput(t)}
344
- required
345
- />
346
- </label>
347
- <button type="submit" class="settings-submit-button">Connect</button>
348
- </form>
349
- </section>
350
- </modal-overlay>
351
- `,this)}}customElements.get("auth-modal")||customElements.define("auth-modal",Wn);class Mn extends HTMLElement{constructor(){super(...arguments);l(this,"runtimeServerURL",Ys());l(this,"electronMode",js());l(this,"serverManager",L.resolve("ServerManager"));l(this,"subscriptions",new dt);l(this,"modals",{workspaceForm:{open:!1,mode:"edit"},deleteWorkspace:{open:!1},settings:{open:!1}});l(this,"connectError",null)}connectedCallback(){this.subscriptions.add(this.serverManager.on("servers-changed",()=>this.render())),this.addEventListener("auth-submit",t=>{var i;const e=t instanceof br?t.token:t instanceof CustomEvent&&typeof((i=t.detail)==null?void 0:i.token)=="string"?t.detail.token:null;e&&this.handleAuthSubmit(e)}),this.initializeConnection(),this.render()}disconnectedCallback(){this.subscriptions.dispose()}async initializeConnection(){if(this.electronMode){this.serverManager.connectConfiguredServers(this.runtimeServerURL);return}if(this.serverManager.activeServer)return;const t=new Me({url:this.runtimeServerURL,name:"Server",token:Li()});this.serverManager.add(t),this.serverManager.setActive(t);try{await t.connect(),this.connectError=null}catch(e){this.connectError=e instanceof Error&&!(e instanceof We)?e.message:null}this.render()}async handleAuthSubmit(t){const e=this.serverManager.activeServer;if(e){this.connectError=null,e.token=t,this.updateTokenQueryParam(t);try{await e.connect()}catch(i){i instanceof We||(this.connectError=i instanceof Error?i.message:String(i))}this.render()}}updateTokenQueryParam(t){const e=new URL(window.location.href);e.searchParams.set("token",t),window.history.replaceState({},"",`${e.pathname}${e.search}${e.hash}`)}render(){const t=this.serverManager.activeServer,e=(t==null?void 0:t.status)??null;if(e==="connecting"){E(m`
352
- <main class="auth-gate"><p>Connecting...</p></main>
353
- `,this);return}if(e==="disconnected"){const n=t;if(!n)return;E(m`
354
- <main class="auth-gate">
355
- <auth-modal
356
- .invalid=${!!n.token}
357
- .tokenValue=${n.token??""}
358
- ></auth-modal>
359
- </main>
360
- `,this);return}const i=m`
361
- <header>
362
- <nav>
363
- <workspace-picker
364
- @edit-workspace=${()=>{this.modals.workspaceForm={open:!0,mode:"edit"},this.render()}}
365
- @create-workspace=${n=>{n instanceof vr&&(this.modals.workspaceForm={open:!0,mode:"create",targetServerURL:n.serverURL},this.render())}}
366
- @delete-workspace=${()=>{this.modals.deleteWorkspace={open:!0},this.render()}}
367
- ></workspace-picker>
368
- </nav>
369
- <button
370
- type="button"
371
- variant="toolbar"
372
- size="sm"
373
- aria-label="Settings"
374
- @click=${()=>{this.modals.settings={open:!this.modals.settings.open},this.render()}}
375
- >
376
- ${qi({size:16,weight:"bold"})}
377
- </button>
378
- </header>
379
- <main>
380
- ${this.connectError?m`<p data-testid="auth-error">${this.connectError}</p>`:m`<workspace-view></workspace-view>`}
381
- </main>
382
- <workspace-form-modal
383
- ?open=${this.modals.workspaceForm.open}
384
- .mode=${this.modals.workspaceForm.mode}
385
- .targetServerURL=${this.modals.workspaceForm.targetServerURL}
386
- @close=${()=>{this.modals.workspaceForm={open:!1,mode:"edit"},this.render()}}
387
- ></workspace-form-modal>
388
- <workspace-delete-modal
389
- ?open=${this.modals.deleteWorkspace.open}
390
- @close=${()=>{this.modals.deleteWorkspace={open:!1},this.render()}}
391
- ></workspace-delete-modal>
392
- <settings-modal
393
- ?open=${this.modals.settings.open}
394
- @close=${()=>{this.modals.settings={open:!1},this.render()}}
395
- ></settings-modal>
396
- `;E(i,this)}}customElements.get("television-app")||customElements.define("television-app",Mn);const Qe=js(),Je=Ys(),Sr=bi(Qe?"television-electron":"television-browser",Je),ts=new Di({clientStore:Sr,localServerURL:Je}),_r=new Qr({clientStore:Sr,serverManager:ts});L.register("ServerManager",()=>ts);L.register("WorkspaceService",()=>_r);ts.on("server-event",({serverURL:r,event:s})=>{_r.handleServerEvent(r,s)});const es=document.createElement("television-app");es.runtimeServerURL=Je;es.electronMode=Qe;Qe&&document.body.classList.add("electron");document.body.appendChild(es);