@telepath-computer/television 0.1.8 → 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.
- package/dist/browser/assets/index-BEMTFjJ-.js +394 -0
- package/dist/browser/assets/index-CmOTsDN-.css +1 -0
- package/dist/browser/index.html +2 -2
- package/dist/cli.cjs +376 -59
- package/dist/electron.cjs +376 -59
- package/package.json +5 -3
- package/dist/browser/assets/index-C3ygXWMh.js +0 -396
- package/dist/browser/assets/index-nGpvLl78.css +0 -1
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
var es=Object.defineProperty;var _r=r=>{throw TypeError(r)};var rs=(r,i,t)=>i in r?es(r,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[i]=t;var h=(r,i,t)=>rs(r,typeof i!="symbol"?i+"":i,t),ke=(r,i,t)=>i.has(r)||_r("Cannot "+t);var p=(r,i,t)=>(ke(r,i,"read from private field"),t?t.call(r):i.get(r)),b=(r,i,t)=>i.has(r)?_r("Cannot add the same private member more than once"):i instanceof WeakSet?i.add(r):i.set(r,t),$=(r,i,t,e)=>(ke(r,i,"write to private field"),e?e.call(r,t):i.set(r,t),t),f=(r,i,t)=>(ke(r,i,"access private method"),t);(function(){const i=document.createElement("link").relList;if(i&&i.supports&&i.supports("modulepreload"))return;for(const s of document.querySelectorAll('link[rel="modulepreload"]'))e(s);new MutationObserver(s=>{for(const n of s)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(s){const n={};return s.integrity&&(n.integrity=s.integrity),s.referrerPolicy&&(n.referrerPolicy=s.referrerPolicy),s.crossOrigin==="use-credentials"?n.credentials="include":s.crossOrigin==="anonymous"?n.credentials="omit":n.credentials="same-origin",n}function e(s){if(s.ep)return;s.ep=!0;const n=t(s);fetch(s.href,n)}})();const xr=new WeakMap;function is(r){return(typeof r=="object"||typeof r=="function")&&r!==null&&"then"in r&&typeof r.then=="function"}function dt(r){return typeof r=="string"?r:typeof r=="symbol"?r.description??r.toString():r.name||"(anonymous class)"}function Ar(){return new Error("register(Key, factory) requires a factory function. Wrap existing instances as () => instance.")}function ss(){return new Error("register(Key, factory) does not accept async factories. Await setup before registering.")}class ns{constructor(){h(this,"entries",new Map);h(this,"constructionStack",[])}register(i,t){if(t===void 0){if(typeof i!="function")throw Ar();this.validateClassRegistration(i),this.storeFactory(i,()=>this.instantiateClass(i));return}if(typeof t!="function")throw Ar();if(t.constructor.name==="AsyncFunction")throw ss();this.storeFactory(i,t)}has(i){var t;return((t=this.entries.get(i))==null?void 0:t.factory)!==void 0}resolve(i){return this.resolveAny(i)}storeFactory(i,t){const e=this.getOrCreateEntry(i);e.factory=t,e.instance=void 0,e.error=void 0}validateClassRegistration(i){const t=xr.get(i);if(t){if(i.length!==t.length)throw new Error(`${dt(i)} cannot be registered with register(Class). @injectable(...) declared ${t.length} dependencies but constructor arity is ${i.length}. Use register(Key, () => value) instead.`);return}if(i.length!==0)throw new Error(`${dt(i)} cannot be registered with register(Class). Undecorated classes must have zero required constructor parameters. Use register(Key, () => value) instead.`)}instantiateClass(i){const t=xr.get(i);if(!t)return new i;const e=t.map(s=>this.resolveAny(s));return new i(...e)}resolveAny(i){return this.getOrCreateEntry(i).proxy}getOrCreateEntry(i){let t=this.entries.get(i);return t||(t={key:i},t.proxy=this.createProxy(t),this.entries.set(i,t),t)}createProxy(i){return new Proxy({},{get:(t,e)=>{if(e==="then")return;const s=this.getInstance(i),n=Reflect.get(s,e,s);return typeof n=="function"?n.bind(s):n},set:(t,e,s)=>{const n=this.getInstance(i);return Reflect.set(n,e,s,n)},has:(t,e)=>{const s=this.getInstance(i);return e in s}})}getInstance(i){if(i.instance)return i.instance;if(i.error)throw i.error;if(!i.factory)throw new Error(`${dt(i.key)} was resolved but never registered`);const t=this.constructionStack.indexOf(i.key);if(t!==-1){const e=[...this.constructionStack.slice(t),i.key].map(s=>dt(s)).join(" -> ");throw new Error(`Circular dependency detected: ${e}`)}this.constructionStack.push(i.key);try{const e=i.factory();if(is(e))throw new Error(`Factory for ${dt(i.key)} returned a Promise. Await setup before registering.`);if(typeof e!="object"||e===null)throw new Error(`Factory for ${dt(i.key)} returned a non-object value. Wrap primitives in an object.`);return i.instance=e,e}catch(e){throw i.error=e,e}finally{this.constructionStack.pop()}}}const M=new ns;function os(r){return{all:r=r||new Map,on:function(i,t){var e=r.get(i);e?e.push(t):r.set(i,[t])},off:function(i,t){var e=r.get(i);e&&(t?e.splice(e.indexOf(t)>>>0,1):r.set(i,[]))},emit:function(i,t){var e=r.get(i);e&&e.slice().map(function(s){s(t)}),(e=r.get("*"))&&e.slice().map(function(s){s(i,t)})}}}let Kt=class{constructor(){h(this,"emitter",os());h(this,"off",this.emitter.off)}on(i,t){return this.emitter.on(i,t),{dispose:()=>this.emitter.off(i,t)}}once(i,t){const e=(...s)=>{t(...s),this.emitter.off(i,e)};return this.emitter.on(i,e),{dispose:()=>this.emitter.off(i,e)}}emit(i,...[t]){this.emitter.emit(i,t)}};const Qr="0123456789ABCDEFGHJKMNPQRSTVWXYZ",ae=32,as=16,ti=10,Pr=0xffffffffffff;var et;(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"})(et||(et={}));class _t extends Error{constructor(i,t){super(`${t} (${i})`),this.name="ULIDError",this.code=i}}function cs(r){const i=Math.floor(r()*ae)%ae;return Qr.charAt(i)}function ls(r){const i=hs(),t=i&&(i.crypto||i.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 _t(et.PRNGDetectFailure,"Failed to find a reliable PRNG")}function hs(){return ps()?self:typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:null}function ds(r,i){let t="";for(;r>0;r--)t=cs(i)+t;return t}function us(r,i=ti){if(isNaN(r))throw new _t(et.EncodeTimeValueMalformed,`Time must be a number: ${r}`);if(r>Pr)throw new _t(et.EncodeTimeSizeExceeded,`Cannot encode a time larger than ${Pr}: ${r}`);if(r<0)throw new _t(et.EncodeTimeNegative,`Time must be positive: ${r}`);if(Number.isInteger(r)===!1)throw new _t(et.EncodeTimeValueMalformed,`Time must be an integer: ${r}`);let t,e="";for(let s=i;s>0;s--)t=r%ae,e=Qr.charAt(t)+e,r=(r-t)/ae;return e}function ps(){return typeof WorkerGlobalScope<"u"&&self instanceof WorkerGlobalScope}function Dt(r,i){const t=ls(),e=Date.now();return us(e,ti)+ds(as,t)}const ei="markdown";function fs(r){const i=r.type??ei;return{id:r.id??Dt(),type:i,title:r.title,content:r.content}}const G=4,T=6,ri=2,$e=2,gs=G,ms=T,or="auto",q="auto",Q=120,Ir=75,x=16,st=Q*G+x*(G-1),pt=Q*T+x*(T-1),vs=200,ys=4,Jt=150,ws=10,Er=2;function Le(r,i={}){return{id:i.id??Dt(),type:"card",artifactID:r,width:i.width??or,height:i.height??q}}function Me(r,i){return r.some(t=>ii(t,i))}function ii(r,i){switch(r.type){case"card":return r.artifactID===i;case"row":return r.children.some(t=>t.artifactID===i);case"stack":return r.children.some(t=>ii(t,i))}}function be(r){return r.layout.flatMap(si)}function si(r){switch(r.type){case"card":return[r.artifactID];case"row":return r.children.map(i=>i.artifactID);case"stack":return r.children.flatMap(si)}}const ks=4,bs=/^[0-9A-HJKMNP-TV-Z]{26}$/;function ni(r){return ci(r)}function oi(r,i){return ci(r.flatMap(t=>hi(t,i)))}function ai(r){const i=[],t=new Set;for(const e of r){if(e.type==="row"){i.push(`Top-level rows are invalid: ${e.id}`);continue}di(e,"strip",i,t)}return{valid:i.length===0,errors:i}}function It(r){const i=ni(r),t=ai(i);if(!t.valid)throw new Error(`Invalid layout: ${t.errors.join("; ")}`);return{totalNodes:i.length,nodes:i.filter(e=>e.type!=="row").map(As)}}function ci(r){const i=[];for(const t of r){const e=li(t);for(const s of e){if(s.type==="row"){i.push(...s.children.map(z));continue}i.push(s)}}return i}function li(r){switch(r.type){case"card":return[z(r)];case"row":{const i=r.children.map(z);return i.length===0?[]:i.length===1?[i[0]]:[{...r,children:i}]}case"stack":{const i=[];for(const t of r.children){const e=li(t);for(const s of e){if(s.type==="stack"){i.push(...s.children.map(Te));continue}if(s.type==="row"){i.push({...s,children:s.children.map(z)});continue}i.push(z(s))}}return i.length===0?[]:i.length===1?[Te(i[0])]:[{...r,children:i}]}}}function hi(r,i){switch(r.type){case"card":return r.artifactID===i?[]:[z(r)];case"row":{const t=r.children.filter(e=>e.artifactID!==i).map(z);return t.length===0?[]:t.length===1?[t[0]]:[{...r,children:t}]}case"stack":{const t=r.children.flatMap(e=>hi(e,i).filter(n=>n.type!=="stack"));return t.length===0?[]:t.length===1?[Te(t[0])]:[{...r,children:t}]}}}function di(r,i,t,e){switch(r.type){case"card":ui(r,i,t,e);return;case"row":Ss(r,i,t,e);return;case"stack":_s(r,i,t,e);return}}function ui(r,i,t,e){ar(r.id,t),typeof r.artifactID!="string"||r.artifactID.length===0?t.push(`Card ${r.id} is missing artifactID`):e.has(r.artifactID)?t.push(`Duplicate artifactID in layout: ${r.artifactID}`):e.add(r.artifactID),xs(r.width)||t.push(`Card ${r.id} width must be an integer in the range 2-4`),pi(r.height)||t.push(`Card ${r.id} height must be an integer in the range 2-6 or "auto"`);const s=tt(r.width);i==="row"&&s<ri&&t.push(`Row child ${r.id} must be at least 2 columns wide`)}function Ss(r,i,t,e){if(ar(r.id,t),i!=="stack"&&t.push(`Row ${r.id} may only appear inside a stack`),pi(r.height,ks)||t.push(`Row ${r.id} height must be an integer in the range 2-4 or "auto"`),!Array.isArray(r.children)||r.children.length===0){t.push(`Row ${r.id} must contain card nodes`);return}let s=0;for(const n of r.children){if(n.type!=="card"){t.push(`Row ${r.id} must contain only card nodes`);continue}ui(n,"row",t,e),s+=tt(n.width)}s!==G&&t.push(`Row ${r.id} children must sum to 4 columns`)}function _s(r,i,t,e){if(ar(r.id,t),i!=="strip"&&t.push(`Invalid nested stack at ${r.id}; stack children cannot contain another nested stack`),!Array.isArray(r.children)||r.children.length===0){t.push(`Stack ${r.id} must contain at least one child`);return}let s=0,n=0;for(const a of r.children){if(a.type==="stack"){t.push(`Stack ${r.id} cannot contain another nested stack`);continue}if(di(a,"stack",t,e),a.height===q){n+=1;continue}s+=a.height}if(s>T&&t.push(`Stack ${r.id} exceeds the 6-row budget`),n===0)return;const o=T-s;if(o<n*$e||o%n!==0){t.push(`Stack ${r.id} has auto-height children that cannot resolve to whole height >= 2`);return}o/n<$e&&t.push(`Stack ${r.id} has auto-height children below the minimum row size`)}function ar(r,i){(typeof r!="string"||!bs.test(r))&&i.push(`Node id must be a ULID: ${String(r)}`)}function xs(r){return r===or||Number.isInteger(r)&&r>=ri&&r<=gs}function pi(r,i=ms){return r===q||Number.isInteger(r)&&r>=$e&&r<=i}function tt(r){return r===or?G:r}function As(r){if(r.type==="card")return{id:r.id,type:"card",width:tt(r.width),cards:[{id:r.id,artifactID:r.artifactID,col:1,row:1,width:tt(r.width),height:fi(r.height,T)}]};const i=Ps(r.children),t=[];let e=1;for(let s=0;s<r.children.length;s+=1){const n=r.children[s],o=i[s];if(n.type==="card")t.push({id:n.id,artifactID:n.artifactID,col:1,row:e,width:tt(n.width),height:o});else{let a=1;for(const c of n.children)t.push({id:c.id,artifactID:c.artifactID,col:a,row:e,width:tt(c.width),height:o}),a+=tt(c.width)}e+=o}return{id:r.id,type:"stack",width:t.reduce((s,n)=>Math.max(s,n.col+n.width-1),1),cards:t}}function Ps(r){let i=0,t=0;for(const s of r)s.height===q?t+=1:i+=s.height;const e=t>0?(T-i)/t:0;return r.map(s=>fi(s.height,e))}function fi(r,i){return r===q?i:r}function z(r){return{...r}}function Te(r){return r.type==="card"?z(r):{...r,children:r.children.map(z)}}const Se="create-artifact",_e="remove-artifact",Qt="update-layout";class Is extends Kt{constructor(t){var s;super();h(this,"artifacts",new Map);h(this,"activeWorkspaceID",null);h(this,"scrollPosition",0);h(this,"activeWorkspaceData",null);h(this,"clientStore");h(this,"serverManager");h(this,"pendingMutations",new Map);h(this,"pendingWorkspaceCreates",new Map);h(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=((s=e==null?void 0:e.workspaces[this.activeWorkspaceID])==null?void 0:s.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?be(this.activeWorkspaceData):[]).map(t=>this.artifacts.get(t)).filter(t=>t!==void 0)}getArtifactURL(t){const e=this.activeWorkspaceServerURL;if(!e)return null;const s=this.getServers().get(e);return s!=null&&s.getArtifactURL?s.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 c;const e=this.activeWorkspaceData;if(!e)return;const s=this.snapshotState(),n=fs({id:Dt(),type:ei,title:t.title,content:t.content});Me(e.layout,n.id)||(e.layout=[...e.layout,Le(n.id)]),this.artifacts.set(n.id,n),this.scrollPosition=Es(e.layout),this.persistWorkspaceViewState(),this.emit("change");const o=((c=this.findWorkspace(e.id))==null?void 0:c.server)??null,a=this.getMutationKey(Se,n.id);this.pendingMutations.set(a,s),this.sendServerMessage(o,{type:"create-artifact",id:n.id,title:t.title,content:t.content,workspaceID:e.id})||(this.pendingMutations.delete(a),this.restoreState(s),this.emit("change"))}removeArtifact(t){var a;const e=this.activeWorkspaceData;if(!e||!this.artifacts.has(t))return;const s=this.snapshotState();this.removeArtifactLocally(t),this.emit("change");const n=((a=this.findWorkspace(e.id))==null?void 0:a.server)??null,o=this.getMutationKey(_e,t);this.pendingMutations.set(o,s),this.sendServerMessage(n,{type:"remove-artifact",artifactID:t,workspaceID:e.id})||(this.pendingMutations.delete(o),this.restoreState(s),this.emit("change"))}handleServerEvent(t,e){var s;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(Qt,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(Se,e.artifact.id)),this.applyArtifactCreated(e);break;case"artifact-updated":this.applyArtifactUpdated(e);break;case"artifact-removed":if(this.pendingMutations.delete(this.getMutationKey(_e,e.artifactID)),((s=this.activeWorkspaceData)==null?void 0:s.id)!==e.workspaceID)return;this.removeArtifactLocally(e.artifactID)&&this.emit("change");break;case"error":this.handleServerError(e);break}}createWorkspace(t,e){const s=this.getServers().get(t)??null,n=Dt(),o=Dr();return this.pendingWorkspaceCreates.set(n,o),this.sendServerMessage(s,{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 s=((o=this.findWorkspace(t.id))==null?void 0:o.server)??null,n=Dr();return this.pendingWorkspaceDeletes.set(t.id,n),this.sendServerMessage(s,{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 s=((n=this.findWorkspace(e.id))==null?void 0:n.server)??null;e.name=t,this.emit("change"),this.sendServerMessage(s,{type:"update-workspace",workspaceID:e.id,fields:{name:t}})}updateLayout(t){var l;const e=this.activeWorkspaceData;if(!e)return;const s=ni(t);if(!ai(s).valid)return;const o=this.snapshotState();e.layout=s,this.emit("change");const a=((l=this.findWorkspace(e.id))==null?void 0:l.server)??null,c=this.getMutationKey(Qt,e.id);this.pendingMutations.set(c,o),this.sendServerMessage(a,{type:"update-workspace",workspaceID:e.id,fields:{layout:s.map(d=>structuredClone(d))}})||(this.pendingMutations.delete(c),this.restoreState(o),this.emit("change"))}syncActiveWorkspaceState(t,e){const s=this.activeWorkspaceID?this.findWorkspace(this.activeWorkspaceID):null;if(!s){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(s.workspace),e&&s.serverURL===t&&this.requestWorkspace(s.serverURL,s.workspace.id)}hasPendingLayoutMutation(t){return this.pendingMutations.has(this.getMutationKey(Qt,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 s=this.getServers().get(t);this.sendServerMessage(s??null,{type:"get-workspace",workspaceID:e})}applyWorkspaceSnapshot(t,e){if(t.id===this.activeWorkspaceID){this.applyServerWorkspaceState(t),this.artifacts.clear();for(const s of e)this.artifacts.set(s.id,structuredClone(s));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&&(Me(this.activeWorkspaceData.layout,t.artifact.id)||(this.activeWorkspaceData.layout=[...this.activeWorkspaceData.layout,Le(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),s=be(this.activeWorkspaceData).length;return this.activeWorkspaceData.layout=oi(this.activeWorkspaceData.layout,t),!(!e&&s===be(this.activeWorkspaceData).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,s]of t.artifacts.entries())this.artifacts.set(e,structuredClone(s));this.persistWorkspaceViewState()}handleServerError(t){const e=t.request;if(e){if(e.type==="create-artifact"){const s=this.getMutationKey(Se,e.id),n=this.pendingMutations.get(s);if(!n)return;this.pendingMutations.delete(s),this.restoreState(n),this.emit("change");return}if(e.type==="create-workspace"){const s=this.pendingWorkspaceCreates.get(e.id);if(!s)return;this.pendingWorkspaceCreates.delete(e.id),s.reject(new Error(t.message));return}if(e.type==="delete-workspace"){const s=this.pendingWorkspaceDeletes.get(e.workspaceID);if(!s)return;this.pendingWorkspaceDeletes.delete(e.workspaceID),s.reject(new Error(t.message));return}if(e.type==="update-workspace"&&Array.isArray(e.fields.layout)){const s=this.getMutationKey(Qt,e.workspaceID),n=this.pendingMutations.get(s);if(!n)return;this.pendingMutations.delete(s),this.restoreState(n),this.emit("change");return}if(e.type==="remove-artifact"){const s=this.getMutationKey(_e,e.artifactID),n=this.pendingMutations.get(s);if(!n)return;this.pendingMutations.delete(s),this.restoreState(n),this.emit("change")}}}restoreWorkspaceViewState(){var e,s;if(!this.activeWorkspaceID){this.scrollPosition=0;return}const t=((s=(e=this.clientStore.get())==null?void 0:e.workspaces[this.activeWorkspaceID])==null?void 0:s.scrollPosition)??0;this.scrollPosition=Math.max(0,t),this.persistWorkspaceViewState()}persistActiveWorkspace(){this.clientStore.update(t=>{t.lastWorkspaceID=this.activeWorkspaceID})}persistWorkspaceViewState(){this.activeWorkspaceID&&this.clientStore.update(t=>{var e,s;(e=t.workspaces)[s=this.activeWorkspaceID]??(e[s]={scrollPosition:0}),t.workspaces[this.activeWorkspaceID].scrollPosition=this.scrollPosition})}findWorkspace(t){for(const[e,s]of this.getServers()){const n=s.workspaces.get(t);if(n)return{serverURL:e,server:s,workspace:n}}return null}pickNextWorkspace(){var e;const t=(e=this.clientStore.get())==null?void 0:e.lastWorkspaceID;if(t){const s=this.findWorkspace(t);if(s)return s}for(const[s,n]of this.getServers()){const o=n.workspaces.values().next().value;if(o)return{serverURL:s,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 Es(r){var e;const i=It(r);if(i.nodes.length<=1)return 0;let t=0;for(let s=0;s<i.nodes.length-1;s+=1)t+=((e=i.nodes[s])==null?void 0:e.width)??0;return t}function Dr(){let r,i;return{promise:new Promise((e,s)=>{r=e,i=s}),resolve:r,reject:i}}var gi=Symbol.for("immer-nothing"),Cr=Symbol.for("immer-draftable"),W=Symbol.for("immer-state");function U(r,...i){throw new Error(`[Immer] minified error nr: ${r}. Full error at: https://bit.ly/3cXEKWf`)}var Ct=Object.getPrototypeOf;function mt(r){return!!r&&!!r[W]}function nt(r){var i;return r?mi(r)||Array.isArray(r)||!!r[Cr]||!!((i=r.constructor)!=null&&i[Cr])||qt(r)||me(r):!1}var Ds=Object.prototype.constructor.toString(),$r=new WeakMap;function mi(r){if(!r||typeof r!="object")return!1;const i=Object.getPrototypeOf(r);if(i===null||i===Object.prototype)return!0;const t=Object.hasOwnProperty.call(i,"constructor")&&i.constructor;if(t===Object)return!0;if(typeof t!="function")return!1;let e=$r.get(t);return e===void 0&&(e=Function.toString.call(t),$r.set(t,e)),e===Ds}function ce(r,i,t=!0){ge(r)===0?(t?Reflect.ownKeys(r):Object.keys(r)).forEach(s=>{i(s,r[s],r)}):r.forEach((e,s)=>i(s,e,r))}function ge(r){const i=r[W];return i?i.type_:Array.isArray(r)?1:qt(r)?2:me(r)?3:0}function We(r,i){return ge(r)===2?r.has(i):Object.prototype.hasOwnProperty.call(r,i)}function vi(r,i,t){const e=ge(r);e===2?r.set(i,t):e===3?r.add(t):r[i]=t}function Cs(r,i){return r===i?r!==0||1/r===1/i:r!==r&&i!==i}function qt(r){return r instanceof Map}function me(r){return r instanceof Set}function Z(r){return r.copy_||r.base_}function Re(r,i){if(qt(r))return new Map(r);if(me(r))return new Set(r);if(Array.isArray(r))return Array.prototype.slice.call(r);const t=mi(r);if(i===!0||i==="class_only"&&!t){const e=Object.getOwnPropertyDescriptors(r);delete e[W];let s=Reflect.ownKeys(e);for(let n=0;n<s.length;n++){const o=s[n],a=e[o];a.writable===!1&&(a.writable=!0,a.configurable=!0),(a.get||a.set)&&(e[o]={configurable:!0,writable:!0,enumerable:a.enumerable,value:r[o]})}return Object.create(Ct(r),e)}else{const e=Ct(r);if(e!==null&&t)return{...r};const s=Object.create(e);return Object.assign(s,r)}}function cr(r,i=!1){return ve(r)||mt(r)||!nt(r)||(ge(r)>1&&Object.defineProperties(r,{set:te,add:te,clear:te,delete:te}),Object.freeze(r),i&&Object.values(r).forEach(t=>cr(t,!0))),r}function $s(){U(2)}var te={value:$s};function ve(r){return r===null||typeof r!="object"?!0:Object.isFrozen(r)}var Ls={};function ot(r){const i=Ls[r];return i||U(0,r),i}var $t;function yi(){return $t}function Ms(r,i){return{drafts_:[],parent_:r,immer_:i,canAutoFreeze_:!0,unfinalizedDrafts_:0}}function Lr(r,i){i&&(ot("Patches"),r.patches_=[],r.inversePatches_=[],r.patchListener_=i)}function Ne(r){Fe(r),r.drafts_.forEach(Ts),r.drafts_=null}function Fe(r){r===$t&&($t=r.parent_)}function Mr(r){return $t=Ms($t,r)}function Ts(r){const i=r[W];i.type_===0||i.type_===1?i.revoke_():i.revoked_=!0}function Tr(r,i){i.unfinalizedDrafts_=i.drafts_.length;const t=i.drafts_[0];return r!==void 0&&r!==t?(t[W].modified_&&(Ne(i),U(4)),nt(r)&&(r=le(i,r),i.parent_||he(i,r)),i.patches_&&ot("Patches").generateReplacementPatches_(t[W].base_,r,i.patches_,i.inversePatches_)):r=le(i,t,[]),Ne(i),i.patches_&&i.patchListener_(i.patches_,i.inversePatches_),r!==gi?r:void 0}function le(r,i,t){if(ve(i))return i;const e=r.immer_.shouldUseStrictIteration(),s=i[W];if(!s)return ce(i,(n,o)=>Wr(r,s,i,n,o,t),e),i;if(s.scope_!==r)return i;if(!s.modified_)return he(r,s.base_,!0),s.base_;if(!s.finalized_){s.finalized_=!0,s.scope_.unfinalizedDrafts_--;const n=s.copy_;let o=n,a=!1;s.type_===3&&(o=new Set(n),n.clear(),a=!0),ce(o,(c,l)=>Wr(r,s,n,c,l,t,a),e),he(r,n,!1),t&&r.patches_&&ot("Patches").generatePatches_(s,t,r.patches_,r.inversePatches_)}return s.copy_}function Wr(r,i,t,e,s,n,o){if(s==null||typeof s!="object"&&!o)return;const a=ve(s);if(!(a&&!o)){if(mt(s)){const c=n&&i&&i.type_!==3&&!We(i.assigned_,e)?n.concat(e):void 0,l=le(r,s,c);if(vi(t,e,l),mt(l))r.canAutoFreeze_=!1;else return}else o&&t.add(s);if(nt(s)&&!a){if(!r.immer_.autoFreeze_&&r.unfinalizedDrafts_<1||i&&i.base_&&i.base_[e]===s&&a)return;le(r,s),(!i||!i.scope_.parent_)&&typeof e!="symbol"&&(qt(t)?t.has(e):Object.prototype.propertyIsEnumerable.call(t,e))&&he(r,s)}}}function he(r,i,t=!1){!r.parent_&&r.immer_.autoFreeze_&&r.canAutoFreeze_&&cr(i,t)}function Ws(r,i){const t=Array.isArray(r),e={type_:t?1:0,scope_:i?i.scope_:yi(),modified_:!1,finalized_:!1,assigned_:{},parent_:i,base_:r,draft_:null,copy_:null,revoke_:null,isManual_:!1};let s=e,n=lr;t&&(s=[e],n=Lt);const{revoke:o,proxy:a}=Proxy.revocable(s,n);return e.draft_=a,e.revoke_=o,a}var lr={get(r,i){if(i===W)return r;const t=Z(r);if(!We(t,i))return Rs(r,t,i);const e=t[i];return r.finalized_||!nt(e)?e:e===xe(r.base_,i)?(Ae(r),r.copy_[i]=Ue(e,r)):e},has(r,i){return i in Z(r)},ownKeys(r){return Reflect.ownKeys(Z(r))},set(r,i,t){const e=wi(Z(r),i);if(e!=null&&e.set)return e.set.call(r.draft_,t),!0;if(!r.modified_){const s=xe(Z(r),i),n=s==null?void 0:s[W];if(n&&n.base_===t)return r.copy_[i]=t,r.assigned_[i]=!1,!0;if(Cs(t,s)&&(t!==void 0||We(r.base_,i)))return!0;Ae(r),Oe(r)}return r.copy_[i]===t&&(t!==void 0||i in r.copy_)||Number.isNaN(t)&&Number.isNaN(r.copy_[i])||(r.copy_[i]=t,r.assigned_[i]=!0),!0},deleteProperty(r,i){return xe(r.base_,i)!==void 0||i in r.base_?(r.assigned_[i]=!1,Ae(r),Oe(r)):delete r.assigned_[i],r.copy_&&delete r.copy_[i],!0},getOwnPropertyDescriptor(r,i){const t=Z(r),e=Reflect.getOwnPropertyDescriptor(t,i);return e&&{writable:!0,configurable:r.type_!==1||i!=="length",enumerable:e.enumerable,value:t[i]}},defineProperty(){U(11)},getPrototypeOf(r){return Ct(r.base_)},setPrototypeOf(){U(12)}},Lt={};ce(lr,(r,i)=>{Lt[r]=function(){return arguments[0]=arguments[0][0],i.apply(this,arguments)}});Lt.deleteProperty=function(r,i){return Lt.set.call(this,r,i,void 0)};Lt.set=function(r,i,t){return lr.set.call(this,r[0],i,t,r[0])};function xe(r,i){const t=r[W];return(t?Z(t):r)[i]}function Rs(r,i,t){var s;const e=wi(i,t);return e?"value"in e?e.value:(s=e.get)==null?void 0:s.call(r.draft_):void 0}function wi(r,i){if(!(i in r))return;let t=Ct(r);for(;t;){const e=Object.getOwnPropertyDescriptor(t,i);if(e)return e;t=Ct(t)}}function Oe(r){r.modified_||(r.modified_=!0,r.parent_&&Oe(r.parent_))}function Ae(r){r.copy_||(r.copy_=Re(r.base_,r.scope_.immer_.useStrictShallowCopy_))}var Ns=class{constructor(r){this.autoFreeze_=!0,this.useStrictShallowCopy_=!1,this.useStrictIteration_=!0,this.produce=(i,t,e)=>{if(typeof i=="function"&&typeof t!="function"){const n=t;t=i;const o=this;return function(c=n,...l){return o.produce(c,d=>t.call(this,d,...l))}}typeof t!="function"&&U(6),e!==void 0&&typeof e!="function"&&U(7);let s;if(nt(i)){const n=Mr(this),o=Ue(i,void 0);let a=!0;try{s=t(o),a=!1}finally{a?Ne(n):Fe(n)}return Lr(n,e),Tr(s,n)}else if(!i||typeof i!="object"){if(s=t(i),s===void 0&&(s=i),s===gi&&(s=void 0),this.autoFreeze_&&cr(s,!0),e){const n=[],o=[];ot("Patches").generateReplacementPatches_(i,s,n,o),e(n,o)}return s}else U(1,i)},this.produceWithPatches=(i,t)=>{if(typeof i=="function")return(o,...a)=>this.produceWithPatches(o,c=>i(c,...a));let e,s;return[this.produce(i,t,(o,a)=>{e=o,s=a}),e,s]},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){nt(r)||U(8),mt(r)&&(r=Fs(r));const i=Mr(this),t=Ue(r,void 0);return t[W].isManual_=!0,Fe(i),t}finishDraft(r,i){const t=r&&r[W];(!t||!t.isManual_)&&U(9);const{scope_:e}=t;return Lr(e,i),Tr(void 0,e)}setAutoFreeze(r){this.autoFreeze_=r}setUseStrictShallowCopy(r){this.useStrictShallowCopy_=r}setUseStrictIteration(r){this.useStrictIteration_=r}shouldUseStrictIteration(){return this.useStrictIteration_}applyPatches(r,i){let t;for(t=i.length-1;t>=0;t--){const s=i[t];if(s.path.length===0&&s.op==="replace"){r=s.value;break}}t>-1&&(i=i.slice(t+1));const e=ot("Patches").applyPatches_;return mt(r)?e(r,i):this.produce(r,s=>e(s,i))}};function Ue(r,i){const t=qt(r)?ot("MapSet").proxyMap_(r,i):me(r)?ot("MapSet").proxySet_(r,i):Ws(r,i);return(i?i.scope_:yi()).drafts_.push(t),t}function Fs(r){return mt(r)||U(10,r),ki(r)}function ki(r){if(!nt(r)||ve(r))return r;const i=r[W];let t,e=!0;if(i){if(!i.modified_)return i.base_;i.finalized_=!0,t=Re(r,i.scope_.immer_.useStrictShallowCopy_),e=i.scope_.immer_.shouldUseStrictIteration()}else t=Re(r,!0);return ce(t,(s,n)=>{vi(t,s,ki(n))},e),i&&(i.finalized_=!1),t}var Os=new Ns,Us=Os.produce,Hs=Object.defineProperty,Vs=(r,i,t)=>i in r?Hs(r,i,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[i]=t,ee=(r,i,t)=>Vs(r,typeof i!="symbol"?i+"":i,t);function zs(r){return{all:r=r||new Map,on:function(i,t){var e=r.get(i);e?e.push(t):r.set(i,[t])},off:function(i,t){var e=r.get(i);e&&(t?e.splice(e.indexOf(t)>>>0,1):r.set(i,[]))},emit:function(i,t){var e=r.get(i);e&&e.slice().map(function(s){s(t)}),(e=r.get("*"))&&e.slice().map(function(s){s(i,t)})}}}var Gs=class{constructor(){ee(this,"emitter",zs()),ee(this,"on",(r,i)=>(this.emitter.on(r,i),{dispose:()=>this.emitter.off(r,i)})),ee(this,"once",(r,i)=>{const t=e=>{i(e),this.emitter.off(r,t)};return this.emitter.on(r,t),{dispose:()=>this.emitter.off(r,t)}}),ee(this,"off",this.emitter.off)}emit(r,...[i]){this.emitter.emit(r,i)}},Ys="store-",Xs=class extends Gs{emitChange(r){this.emit("change",{state:r})}},Ks=class{constructor(r,i,t){this.emitter=new Xs,this.id=r,this.initValue=i,this.key=`${Ys}${r}`,this.storage=(t==null?void 0:t.storage)==="session"?sessionStorage:localStorage,this.get()===void 0&&this.storage.setItem(this.key,JSON.stringify(i))}get(){const r=this.storage.getItem(this.key);return r===null?void 0:JSON.parse(r)}update(r){const i=this.get()??{},t=Us(i,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,i){return this.emitter.on(r,({state:t})=>i(t))}subscribe(r){const i=this.on("change",r),t=this.get();return t!==void 0&&r(t),i}};const qs="Local";function Y(r){return new URL(r).origin}function Bs(r){return{servers:[{url:Y(r),name:qs}],lastWorkspaceID:null,workspaces:{}}}function js(r,i){return new Ks(r,Bs(i))}const Zs=4401;class He extends Error{constructor(i="Authentication required"){super(i),this.name="AuthError"}}class Ve extends Kt{constructor(t){super();h(this,"url");h(this,"name");h(this,"token");h(this,"status","disconnected");h(this,"workspaces",new Map);h(this,"createSocket");h(this,"socket",null);h(this,"connectAttempt",0);this.url=Y(t.url),this.name=t.name,this.token=t.token??null,this.createSocket=t.createSocket??(e=>new WebSocket(e))}async connect(){var s;this.connectAttempt+=1;const t=this.connectAttempt;(s=this.socket)==null||s.close(),this.status="connecting",this.emit("status-changed");const e=this.createSocket(Js(this.url,this.token));return this.socket=e,await new Promise((n,o)=>{let a=!1;const c=()=>{a||this.connectAttempt!==t||(a=!0,this.status="connected",this.emit("status-changed"),n())},l=d=>{a||this.connectAttempt!==t||(a=!0,this.status="disconnected",this.emit("status-changed"),o(d))};e.addEventListener("message",d=>{const u=tn(d);this.applyServerMessage(u),this.emit("message",u),a||c()}),e.addEventListener("close",d=>{if(this.connectAttempt===t){if(this.socket=null,Qs(d)===Zs){l(new He);return}if(!a){l(new Error("Connection closed before initialization"));return}this.status="disconnected",this.emit("status-changed")}}),e.addEventListener("error",()=>{l(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&&!Me(e.layout,t.artifact.id)&&(e.layout=[...e.layout,Le(t.artifact.id)]);break}case"artifact-removed":{const e=this.workspaces.get(t.workspaceID);e&&(e.layout=oi(e.layout,t.artifactID));break}}}}function Js(r,i){const t=new URL(r);return t.protocol=t.protocol==="https:"?"wss:":"ws:",t.pathname="/ws",t.search="",i&&t.searchParams.set("token",i),t.hash="",t.toString()}function Qs(r){return typeof r=="object"&&r!==null&&"code"in r&&typeof r.code=="number"?r.code:null}function tn(r){const i=typeof r=="string"?r:typeof r=="object"&&r!==null&&"data"in r&&typeof r.data=="string"?r.data:"";return JSON.parse(i)}class en extends Kt{constructor(t){super();h(this,"servers",new Map);h(this,"localServerURL");h(this,"activeServer",null);h(this,"clientStore");h(this,"createSocket");h(this,"disposables",new Map);this.clientStore=t.clientStore,this.localServerURL=t.localServerURL?Y(t.localServerURL):null,this.createSocket=t.createSocket??(e=>new WebSocket(e))}add(t){const e=Y(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",a=>{this.emit("server-event",{serverURL:e,event:a})});this.disposables.set(e,{statusSubscription:n,messageSubscription:o}),this.emit("servers-changed")}remove(t){const e=Y(t);if(this.localServerURL&&e===this.localServerURL)return;const s=this.servers.get(e);if(!s)return;const n=this.disposables.get(e);n==null||n.statusSubscription.dispose(),n==null||n.messageSubscription.dispose(),this.disposables.delete(e),s.disconnect(),this.servers.delete(e),this.activeServer===s&&(this.activeServer=null),this.clientStore.update(o=>{o.servers=o.servers.filter(a=>a.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 a=new Ve({url:o.url,name:o.name,createSocket:this.createSocket});this.add(a),a.connect().catch(()=>{})}const s=t?this.servers.get(Y(t))??null:null;this.setActive(s??this.servers.values().next().value??null)}addServer(t,e){const s=Y(t);this.remove(s),this.clientStore.update(o=>{o.servers=o.servers.filter(a=>Y(a.url)!==s),o.servers.push({url:s,name:e})});const n=new Ve({url:s,name:e,createSocket:this.createSocket});this.add(n),this.setActive(n),n.connect().catch(()=>{})}removeServer(t){this.remove(t)}}const rn="serverURL",sn="token",nn="mode",on="electron";function bi(r=window.location.search,i=window.location.origin){const e=new URLSearchParams(r).get(rn);return e?new URL(e).origin:new URL(i).origin}function an(r=window.location.search){return new URLSearchParams(r).get(sn)}function Si(r=window.location.search){return new URLSearchParams(r).get(nn)===on}class wt{constructor(){h(this,"disposables",[])}add(i){return this.disposables.push(i),i}dispose(){for(const i of this.disposables)i.dispose();this.disposables=[]}}/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2017 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/const Et=globalThis,Rr=r=>r,de=Et.trustedTypes,Nr=de?de.createPolicy("lit-html",{createHTML:r=>r}):void 0,_i="$lit$",X=`lit$${Math.random().toFixed(9).slice(2)}$`,xi="?"+X,cn=`<${xi}>`,at=document,Mt=()=>at.createComment(""),Tt=r=>r===null||typeof r!="object"&&typeof r!="function",hr=Array.isArray,ln=r=>hr(r)||typeof(r==null?void 0:r[Symbol.iterator])=="function",Pe=`[
|
|
6
|
+
\f\r]`,kt=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,Fr=/-->/g,Or=/>/g,j=RegExp(`>|${Pe}(?:([^\\s"'>=/]+)(${Pe}*=${Pe}*(?:[^
|
|
7
|
+
\f\r"'\`<>=]|("|')|))|$)`,"g"),Ur=/'/g,Hr=/"/g,Ai=/^(?:script|style|textarea|title)$/i,hn=r=>(i,...t)=>({_$litType$:r,strings:i,values:t}),v=hn(1),vt=Symbol.for("lit-noChange"),A=Symbol.for("lit-nothing"),Vr=new WeakMap,rt=at.createTreeWalker(at,129);function Pi(r,i){if(!hr(r)||!r.hasOwnProperty("raw"))throw Error("invalid template strings array");return Nr!==void 0?Nr.createHTML(i):i}const dn=(r,i)=>{const t=r.length-1,e=[];let s,n=i===2?"<svg>":i===3?"<math>":"",o=kt;for(let a=0;a<t;a++){const c=r[a];let l,d,u=-1,y=0;for(;y<c.length&&(o.lastIndex=y,d=o.exec(c),d!==null);)y=o.lastIndex,o===kt?d[1]==="!--"?o=Fr:d[1]!==void 0?o=Or:d[2]!==void 0?(Ai.test(d[2])&&(s=RegExp("</"+d[2],"g")),o=j):d[3]!==void 0&&(o=j):o===j?d[0]===">"?(o=s??kt,u=-1):d[1]===void 0?u=-2:(u=o.lastIndex-d[2].length,l=d[1],o=d[3]===void 0?j:d[3]==='"'?Hr:Ur):o===Hr||o===Ur?o=j:o===Fr||o===Or?o=kt:(o=j,s=void 0);const w=o===j&&r[a+1].startsWith("/>")?" ":"";n+=o===kt?c+cn:u>=0?(e.push(l),c.slice(0,u)+_i+c.slice(u)+X+w):c+X+(u===-2?a:w)}return[Pi(r,n+(r[t]||"<?>")+(i===2?"</svg>":i===3?"</math>":"")),e]};class Wt{constructor({strings:i,_$litType$:t},e){let s;this.parts=[];let n=0,o=0;const a=i.length-1,c=this.parts,[l,d]=dn(i,t);if(this.el=Wt.createElement(l,e),rt.currentNode=this.el.content,t===2||t===3){const u=this.el.content.firstChild;u.replaceWith(...u.childNodes)}for(;(s=rt.nextNode())!==null&&c.length<a;){if(s.nodeType===1){if(s.hasAttributes())for(const u of s.getAttributeNames())if(u.endsWith(_i)){const y=d[o++],w=s.getAttribute(u).split(X),m=/([.?@])?(.*)/.exec(y);c.push({type:1,index:n,name:m[2],strings:w,ctor:m[1]==="."?pn:m[1]==="?"?fn:m[1]==="@"?gn:ye}),s.removeAttribute(u)}else u.startsWith(X)&&(c.push({type:6,index:n}),s.removeAttribute(u));if(Ai.test(s.tagName)){const u=s.textContent.split(X),y=u.length-1;if(y>0){s.textContent=de?de.emptyScript:"";for(let w=0;w<y;w++)s.append(u[w],Mt()),rt.nextNode(),c.push({type:2,index:++n});s.append(u[y],Mt())}}}else if(s.nodeType===8)if(s.data===xi)c.push({type:2,index:n});else{let u=-1;for(;(u=s.data.indexOf(X,u+1))!==-1;)c.push({type:7,index:n}),u+=X.length-1}n++}}static createElement(i,t){const e=at.createElement("template");return e.innerHTML=i,e}}function yt(r,i,t=r,e){var o,a;if(i===vt)return i;let s=e!==void 0?(o=t._$Co)==null?void 0:o[e]:t._$Cl;const n=Tt(i)?void 0:i._$litDirective$;return(s==null?void 0:s.constructor)!==n&&((a=s==null?void 0:s._$AO)==null||a.call(s,!1),n===void 0?s=void 0:(s=new n(r),s._$AT(r,t,e)),e!==void 0?(t._$Co??(t._$Co=[]))[e]=s:t._$Cl=s),s!==void 0&&(i=yt(r,s._$AS(r,i.values),s,e)),i}class un{constructor(i,t){this._$AV=[],this._$AN=void 0,this._$AD=i,this._$AM=t}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(i){const{el:{content:t},parts:e}=this._$AD,s=((i==null?void 0:i.creationScope)??at).importNode(t,!0);rt.currentNode=s;let n=rt.nextNode(),o=0,a=0,c=e[0];for(;c!==void 0;){if(o===c.index){let l;c.type===2?l=new Bt(n,n.nextSibling,this,i):c.type===1?l=new c.ctor(n,c.name,c.strings,this,i):c.type===6&&(l=new mn(n,this,i)),this._$AV.push(l),c=e[++a]}o!==(c==null?void 0:c.index)&&(n=rt.nextNode(),o++)}return rt.currentNode=at,s}p(i){let t=0;for(const e of this._$AV)e!==void 0&&(e.strings!==void 0?(e._$AI(i,e,t),t+=e.strings.length-2):e._$AI(i[t])),t++}}class Bt{get _$AU(){var i;return((i=this._$AM)==null?void 0:i._$AU)??this._$Cv}constructor(i,t,e,s){this.type=2,this._$AH=A,this._$AN=void 0,this._$AA=i,this._$AB=t,this._$AM=e,this.options=s,this._$Cv=(s==null?void 0:s.isConnected)??!0}get parentNode(){let i=this._$AA.parentNode;const t=this._$AM;return t!==void 0&&(i==null?void 0:i.nodeType)===11&&(i=t.parentNode),i}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(i,t=this){i=yt(this,i,t),Tt(i)?i===A||i==null||i===""?(this._$AH!==A&&this._$AR(),this._$AH=A):i!==this._$AH&&i!==vt&&this._(i):i._$litType$!==void 0?this.$(i):i.nodeType!==void 0?this.T(i):ln(i)?this.k(i):this._(i)}O(i){return this._$AA.parentNode.insertBefore(i,this._$AB)}T(i){this._$AH!==i&&(this._$AR(),this._$AH=this.O(i))}_(i){this._$AH!==A&&Tt(this._$AH)?this._$AA.nextSibling.data=i:this.T(at.createTextNode(i)),this._$AH=i}$(i){var n;const{values:t,_$litType$:e}=i,s=typeof e=="number"?this._$AC(i):(e.el===void 0&&(e.el=Wt.createElement(Pi(e.h,e.h[0]),this.options)),e);if(((n=this._$AH)==null?void 0:n._$AD)===s)this._$AH.p(t);else{const o=new un(s,this),a=o.u(this.options);o.p(t),this.T(a),this._$AH=o}}_$AC(i){let t=Vr.get(i.strings);return t===void 0&&Vr.set(i.strings,t=new Wt(i)),t}k(i){hr(this._$AH)||(this._$AH=[],this._$AR());const t=this._$AH;let e,s=0;for(const n of i)s===t.length?t.push(e=new Bt(this.O(Mt()),this.O(Mt()),this,this.options)):e=t[s],e._$AI(n),s++;s<t.length&&(this._$AR(e&&e._$AB.nextSibling,s),t.length=s)}_$AR(i=this._$AA.nextSibling,t){var e;for((e=this._$AP)==null?void 0:e.call(this,!1,!0,t);i!==this._$AB;){const s=Rr(i).nextSibling;Rr(i).remove(),i=s}}setConnected(i){var t;this._$AM===void 0&&(this._$Cv=i,(t=this._$AP)==null||t.call(this,i))}}class ye{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(i,t,e,s,n){this.type=1,this._$AH=A,this._$AN=void 0,this.element=i,this.name=t,this._$AM=s,this.options=n,e.length>2||e[0]!==""||e[1]!==""?(this._$AH=Array(e.length-1).fill(new String),this.strings=e):this._$AH=A}_$AI(i,t=this,e,s){const n=this.strings;let o=!1;if(n===void 0)i=yt(this,i,t,0),o=!Tt(i)||i!==this._$AH&&i!==vt,o&&(this._$AH=i);else{const a=i;let c,l;for(i=n[0],c=0;c<n.length-1;c++)l=yt(this,a[e+c],t,c),l===vt&&(l=this._$AH[c]),o||(o=!Tt(l)||l!==this._$AH[c]),l===A?i=A:i!==A&&(i+=(l??"")+n[c+1]),this._$AH[c]=l}o&&!s&&this.j(i)}j(i){i===A?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,i??"")}}class pn extends ye{constructor(){super(...arguments),this.type=3}j(i){this.element[this.name]=i===A?void 0:i}}class fn extends ye{constructor(){super(...arguments),this.type=4}j(i){this.element.toggleAttribute(this.name,!!i&&i!==A)}}class gn extends ye{constructor(i,t,e,s,n){super(i,t,e,s,n),this.type=5}_$AI(i,t=this){if((i=yt(this,i,t,0)??A)===vt)return;const e=this._$AH,s=i===A&&e!==A||i.capture!==e.capture||i.once!==e.once||i.passive!==e.passive,n=i!==A&&(e===A||s);s&&this.element.removeEventListener(this.name,this,e),n&&this.element.addEventListener(this.name,this,i),this._$AH=i}handleEvent(i){var t;typeof this._$AH=="function"?this._$AH.call(((t=this.options)==null?void 0:t.host)??this.element,i):this._$AH.handleEvent(i)}}class mn{constructor(i,t,e){this.element=i,this.type=6,this._$AN=void 0,this._$AM=t,this.options=e}get _$AU(){return this._$AM._$AU}_$AI(i){yt(this,i)}}const Ie=Et.litHtmlPolyfillSupport;Ie==null||Ie(Wt,Bt),(Et.litHtmlVersions??(Et.litHtmlVersions=[])).push("3.3.2");const I=(r,i,t)=>{const e=i;let s=e._$litPart$;return s===void 0&&(e._$litPart$=s=new Bt(i.insertBefore(Mt(),null),null,void 0,{})),s._$AI(r),s};/**
|
|
8
|
+
* @license
|
|
9
|
+
* Copyright 2017 Google LLC
|
|
10
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
11
|
+
*/const vn={CHILD:2},yn=r=>(...i)=>({_$litDirective$:r,values:i});class wn{constructor(i){}get _$AU(){return this._$AM._$AU}_$AT(i,t,e){this._$Ct=i,this._$AM=t,this._$Ci=e}_$AS(i,t){return this.update(i,t)}update(i,t){return this.render(...t)}}/**
|
|
12
|
+
* @license
|
|
13
|
+
* Copyright 2017 Google LLC
|
|
14
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
15
|
+
*/class ze extends wn{constructor(i){if(super(i),this.it=A,i.type!==vn.CHILD)throw Error(this.constructor.directiveName+"() can only be used in child bindings")}render(i){if(i===A||i==null)return this._t=void 0,this.it=i;if(i===vt)return i;if(typeof i!="string")throw Error(this.constructor.directiveName+"() called with a non-string value");if(i===this.it)return this._t;this.it=i;const t=[i];return t.raw=t,this._t={_$litType$:this.constructor.resultType,strings:t,values:[]}}}ze.directiveName="unsafeHTML",ze.resultType=1;/**
|
|
16
|
+
* @license
|
|
17
|
+
* Copyright 2017 Google LLC
|
|
18
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
19
|
+
*/class Ge extends ze{}Ge.directiveName="unsafeSVG",Ge.resultType=2;const kn=yn(Ge),bn={size:16,color:"currentColor",weight:"regular"};function Sn(r){return typeof r=="string"?{regular:r}:r}function dr(r,i="0 0 256 256"){const t=Sn(r);return e=>{const{size:s,color:n,weight:o}={...bn,...e},a=t[o]??t.regular;return v`<svg
|
|
20
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
21
|
+
data-ui-icon=""
|
|
22
|
+
width="${s}"
|
|
23
|
+
height="${s}"
|
|
24
|
+
viewBox="${i}"
|
|
25
|
+
fill="${n}"
|
|
26
|
+
>${kn(a)}</svg>`}}const _n=new Map,Ee=new Set;var ft,ie;const vr=class vr extends HTMLElement{constructor(){super(...arguments);b(this,ft)}connectedCallback(){f(this,ft,ie).call(this)}disconnectedCallback(){Ee.delete(this)}attributeChangedCallback(){f(this,ft,ie).call(this)}refresh(){f(this,ft,ie).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}};ft=new WeakSet,ie=function(){const t=this.name?_n.get(this.name):null;if(!t){this.name&&Ee.add(this),I(null,this);return}Ee.delete(this),I(t({size:this.size,weight:this.weight}),this)},vr.observedAttributes=["name","size","weight"];let Ye=vr;customElements.get("icon-element")||customElements.define("icon-element",Ye);const Ii=dr('<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=dr('<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"/>'),xn=dr('<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 Ei extends Event{constructor(i){super("dropdown-item-select",{bubbles:!0,composed:!0}),this.value=i}}class Di extends Event{constructor(i){super("select",{bubbles:!0,composed:!0}),this.value=i}}var N,O,K,gt,k,Rt,g,Ci,xt,$i,Li,qe,Be,se,J,it,Nt,Ft,Ot,pe,Mi,Ti,je,At,Ze,H;const yr=class yr extends HTMLElement{constructor(){super();b(this,g);b(this,N,!1);b(this,O,null);b(this,K,null);b(this,gt);b(this,k,null);b(this,Rt,new MutationObserver(t=>f(this,g,Mi).call(this,t)));b(this,it,()=>{f(this,g,se).call(this,!p(this,N))});b(this,Nt,t=>{t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),p(this,it).call(this))});b(this,Ft,t=>{p(this,N)&&(t.composedPath().includes(this)||f(this,g,se).call(this,!1))});b(this,Ot,t=>{t instanceof Ei&&(t.stopPropagation(),$(this,N,!1),f(this,g,xt).call(this,t.value),f(this,g,H).call(this),this.dispatchEvent(new Di(t.value)))});b(this,pe,()=>{f(this,g,je).call(this)});$(this,gt,this.attachShadow({mode:"open"}))}connectedCallback(){this.addEventListener("dropdown-item-select",p(this,Ot)),document.addEventListener("click",p(this,Ft),!0),f(this,g,Ci).call(this),p(this,Rt).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",p(this,Ot)),document.removeEventListener("click",p(this,Ft),!0),p(this,Rt).disconnect(),f(this,g,Ze).call(this)}attributeChangedCallback(){f(this,g,H).call(this)}get title(){return this.getAttribute("title")??""}get value(){return p(this,O)}set value(t){t===null?(f(this,g,J).call(this,null,null),f(this,g,$i).call(this)):f(this,g,xt).call(this,t),f(this,g,H).call(this)}close(){f(this,g,se).call(this,!1)}};N=new WeakMap,O=new WeakMap,K=new WeakMap,gt=new WeakMap,k=new WeakMap,Rt=new WeakMap,g=new WeakSet,Ci=function(){var e;const t=this.querySelector("dropdown-item[selected]");t&&f(this,g,J).call(this,t.value,((e=t.textContent)==null?void 0:e.trim())??null)},xt=function(t){var e;for(const s of p(this,g,qe))s.value===t?(f(this,g,J).call(this,t,((e=s.textContent)==null?void 0:e.trim())??null),s.hasAttribute("selected")||s.setAttribute("selected","")):s.hasAttribute("selected")&&s.removeAttribute("selected")},$i=function(){const t=this.querySelectorAll("dropdown-item[selected]");for(const e of t)e.removeAttribute("selected")},Li=function(t){for(const e of p(this,g,qe))if(e.value===t)return e;return null},qe=function(){return this.querySelectorAll("dropdown-item")},Be=function(){return p(this,K)??this.title},se=function(t){p(this,N)!==t&&($(this,N,t),f(this,g,H).call(this))},J=function(t,e){$(this,O,t),$(this,K,e)},it=new WeakMap,Nt=new WeakMap,Ft=new WeakMap,Ot=new WeakMap,pe=new WeakMap,Mi=function(t){t.every(s=>s.target instanceof Element?s.target.closest('[slot="trigger"]')!==null:!1)||f(this,g,Ti).call(this)},Ti=function(){var e,s;const t=this.querySelector("dropdown-item[selected]");if(t){const n=t.value,o=((e=t.textContent)==null?void 0:e.trim())??null,a=p(this,O)!==n||p(this,K)!==o;f(this,g,J).call(this,n,o),f(this,g,xt).call(this,n),a?f(this,g,H).call(this):f(this,g,At).call(this);return}if(p(this,O)!==null){const n=f(this,g,Li).call(this,p(this,O));if(n){const o=((s=n.textContent)==null?void 0:s.trim())??null,a=p(this,K)!==o;f(this,g,J).call(this,p(this,O),o),f(this,g,xt).call(this,p(this,O)),a?f(this,g,H).call(this):f(this,g,At).call(this);return}}if(p(this,O)!==null||p(this,K)!==null){f(this,g,J).call(this,null,null),f(this,g,H).call(this);return}f(this,g,At).call(this)},je=function(){const t=p(this,gt).querySelector('slot[name="trigger"]'),e=t instanceof HTMLSlotElement?t.assignedElements({flatten:!0})[0]??null:null;p(this,k)!==e&&(f(this,g,Ze).call(this),$(this,k,e),p(this,k)&&(p(this,k).addEventListener("click",p(this,it)),p(this,k)instanceof HTMLButtonElement?p(this,k).hasAttribute("type")||(p(this,k).type="button"):(p(this,k).hasAttribute("role")||p(this,k).setAttribute("role","button"),p(this,k).hasAttribute("tabindex")||(p(this,k).tabIndex=0),p(this,k).addEventListener("keydown",p(this,Nt))))),f(this,g,At).call(this)},At=function(){p(this,k)&&(p(this,k).setAttribute("data-dropdown-trigger",""),p(this,k).setAttribute("aria-haspopup","listbox"),p(this,k).setAttribute("aria-expanded",p(this,N)?"true":"false"),I(v`
|
|
27
|
+
<span class="trigger-label" data-dropdown-trigger-label>${p(this,g,Be)}</span>
|
|
28
|
+
<span class="trigger-icon" data-dropdown-trigger-icon aria-hidden="true">
|
|
29
|
+
${Xe({size:14})}
|
|
30
|
+
</span>
|
|
31
|
+
`,p(this,k)))},Ze=function(){p(this,k)&&(p(this,k).removeEventListener("click",p(this,it)),p(this,k).removeEventListener("keydown",p(this,Nt)),p(this,k).removeAttribute("data-dropdown-trigger"),p(this,k).removeAttribute("aria-haspopup"),p(this,k).removeAttribute("aria-expanded"),$(this,k,null))},H=function(){this.toggleAttribute("open",p(this,N)),I(v`
|
|
32
|
+
<slot name="trigger" @slotchange=${p(this,pe)}>
|
|
33
|
+
<button
|
|
34
|
+
class="fallback-trigger"
|
|
35
|
+
part="trigger"
|
|
36
|
+
type="button"
|
|
37
|
+
aria-haspopup="listbox"
|
|
38
|
+
aria-expanded=${p(this,N)?"true":"false"}
|
|
39
|
+
@click=${p(this,it)}
|
|
40
|
+
>
|
|
41
|
+
<span class="trigger-label" part="trigger-label">${p(this,g,Be)}</span>
|
|
42
|
+
<span class="trigger-icon" part="trigger-icon" aria-hidden="true">
|
|
43
|
+
${Xe({size:14})}
|
|
44
|
+
</span>
|
|
45
|
+
</button>
|
|
46
|
+
</slot>
|
|
47
|
+
${p(this,N)?v`
|
|
48
|
+
<div class="panel" part="panel" role="listbox">
|
|
49
|
+
<slot></slot>
|
|
50
|
+
</div>
|
|
51
|
+
`:null}
|
|
52
|
+
`,p(this,gt)),queueMicrotask(()=>f(this,g,je).call(this))},yr.observedAttributes=["title"];let Ke=yr;class An extends HTMLElement{}class Pn extends HTMLElement{}class In extends HTMLElement{}var lt,Qe,Wi,Ut,Ht;const wr=class wr extends HTMLElement{constructor(){super(...arguments);b(this,lt);b(this,Ut,()=>{this.action||f(this,lt,Wi).call(this)});b(this,Ht,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",p(this,Ut)),this.addEventListener("keydown",p(this,Ht)),f(this,lt,Qe).call(this)}disconnectedCallback(){this.removeEventListener("click",p(this,Ut)),this.removeEventListener("keydown",p(this,Ht))}attributeChangedCallback(){f(this,lt,Qe).call(this)}get value(){return this.getAttribute("value")??""}get selected(){return this.hasAttribute("selected")}get action(){return this.hasAttribute("action")}};lt=new WeakSet,Qe=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")},Wi=function(){this.dispatchEvent(new Ei(this.value))},Ut=new WeakMap,Ht=new WeakMap,wr.observedAttributes=["action","selected","value"];let Je=wr;customElements.get("dropdown-menu")||customElements.define("dropdown-menu",Ke);customElements.get("dropdown-group")||customElements.define("dropdown-group",An);customElements.get("dropdown-label")||customElements.define("dropdown-label",Pn);customElements.get("dropdown-divider")||customElements.define("dropdown-divider",In);customElements.get("dropdown-item")||customElements.define("dropdown-item",Je);class En extends Event{constructor(){super("close",{bubbles:!0,composed:!0})}}var Vt,B,er,fe,zt,rr;const kr=class kr extends HTMLElement{constructor(){super();b(this,B);b(this,Vt);b(this,fe,t=>{t.target===t.currentTarget&&f(this,B,er).call(this)});b(this,zt,t=>{this.open&&t.key==="Escape"&&f(this,B,er).call(this)});$(this,Vt,this.attachShadow({mode:"open"}))}connectedCallback(){document.addEventListener("keydown",p(this,zt)),f(this,B,rr).call(this)}disconnectedCallback(){document.removeEventListener("keydown",p(this,zt))}attributeChangedCallback(){f(this,B,rr).call(this)}get open(){return this.hasAttribute("open")}};Vt=new WeakMap,B=new WeakSet,er=function(){this.dispatchEvent(new En)},fe=new WeakMap,zt=new WeakMap,rr=function(){I(v`
|
|
53
|
+
${this.open?v`
|
|
54
|
+
<div class="backdrop" part="backdrop" @click=${p(this,fe)}>
|
|
55
|
+
<slot></slot>
|
|
56
|
+
</div>
|
|
57
|
+
`:null}
|
|
58
|
+
`,p(this,Vt))},kr.observedAttributes=["open"];let tr=kr;customElements.get("modal-overlay")||customElements.define("modal-overlay",tr);class Ri extends Event{constructor(){super("close",{bubbles:!0,composed:!0})}}class Dn extends HTMLElement{}var Gt,C,Yt,S,ne,oe,Ni,Fi,Pt,Oi,Xt,sr;const br=class br extends HTMLElement{constructor(){super();b(this,S);b(this,Gt);b(this,C,[]);b(this,Yt,new MutationObserver(()=>f(this,S,Oi).call(this)));b(this,Xt,t=>{const e=t.target;if(!(e instanceof Element))return;const s=e.closest("[data-navigate]");if(s){this.navigate(s.dataset.navigate??"");return}e.closest("[data-back]")&&this.back()});$(this,Gt,this.attachShadow({mode:"open"}))}connectedCallback(){this.addEventListener("click",p(this,Xt)),p(this,Yt).observe(this,{childList:!0,subtree:!0,attributes:!0,attributeFilter:["id","title"]}),f(this,S,Pt).call(this)}disconnectedCallback(){this.removeEventListener("click",p(this,Xt)),p(this,Yt).disconnect(),$(this,C,[])}attributeChangedCallback(){f(this,S,sr).call(this)}get closable(){return this.hasAttribute("closable")}navigate(t){var n;const e=((n=p(this,S,ne))==null?void 0:n.id)??null;t===e||!f(this,S,oe).call(this,t)||(p(this,C).push(t),f(this,S,Pt).call(this))}back(){p(this,C).length<=1||(p(this,C).pop(),f(this,S,Pt).call(this))}};Gt=new WeakMap,C=new WeakMap,Yt=new WeakMap,S=new WeakSet,ne=function(){const t=p(this,C)[p(this,C).length-1]??null;return t?f(this,S,oe).call(this,t):null},oe=function(t){const e=this.querySelectorAll("panel-page");for(const s of e)if(s.id===t)return s;return null},Ni=function(){if($(this,C,p(this,C).filter(e=>f(this,S,oe).call(this,e)!==null)),p(this,C).length>0)return;const t=this.querySelector("panel-page");t!=null&&t.id&&$(this,C,[t.id])},Fi=function(){f(this,S,Ni).call(this);const t=p(this,S,ne),e=this.querySelectorAll("panel-page");for(const s of e)s.hidden=s!==t},Pt=function(){f(this,S,Fi).call(this),f(this,S,sr).call(this)},Oi=function(){f(this,S,Pt).call(this)},Xt=new WeakMap,sr=function(){const t=p(this,S,ne);I(v`
|
|
59
|
+
<section class="panel" part="panel">
|
|
60
|
+
<header class="title-bar" part="header">
|
|
61
|
+
<div class="title-group" part="title-group">
|
|
62
|
+
${p(this,C).length>1?v`
|
|
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?v`
|
|
78
|
+
<button
|
|
79
|
+
type="button"
|
|
80
|
+
class="title-button"
|
|
81
|
+
part="button close-button"
|
|
82
|
+
aria-label="Close"
|
|
83
|
+
@click=${()=>this.dispatchEvent(new Ri)}
|
|
84
|
+
>
|
|
85
|
+
<span class="close-icon" part="icon close-icon">${Ii({size:14})}</span>
|
|
86
|
+
</button>
|
|
87
|
+
`:null}
|
|
88
|
+
</header>
|
|
89
|
+
<slot></slot>
|
|
90
|
+
</section>
|
|
91
|
+
`,p(this,Gt))},br.observedAttributes=["closable"];let ir=br;customElements.get("panel-view")||customElements.define("panel-view",ir);customElements.get("panel-page")||customElements.define("panel-page",Dn);class Ui extends Event{constructor(t){super("close-artifact",{bubbles:!0,composed:!0});h(this,"id");this.id=t}}class Cn extends HTMLElement{constructor(){super(...arguments);h(this,"_artifact",null);h(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 Ui(this._artifact.id))}template(){const t=this._artifact;return v`
|
|
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
|
+
>${Ii({size:14})}</button>
|
|
99
|
+
</header>
|
|
100
|
+
<div class="artifact-content">
|
|
101
|
+
${this.renderContent()}
|
|
102
|
+
</div>
|
|
103
|
+
`}renderContent(){return v`<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),I(this.template(),this))}}customElements.define("artifact-view",Cn);const L=r=>({type:"px",...r}),D=r=>({type:"unit",...r}),re=2,$n=2;class Ln{constructor(i){h(this,"basis");h(this,"min");h(this,"_gap");h(this,"_viewport");h(this,"_unit");this.basis=i.basis,this.min=i.min,this._viewport=i.viewport,this._gap=i.gap??L({x,y:x});const t=this._viewport.x??st,e=this._viewport.y??pt,s=this._gap.x??x,n=this._gap.y??x,o=st+s*$n,a=t<=o,c=a?t-s*re:Math.min(st,t-s*re),l=a?e-n*re:Math.min(pt,e-n*re),d=(c-s*(G-1))/G,u=(l-n*(T-1))/T,y=this.basis.x??0,w=this.basis.y??0,m=this.min.x??0,E=this.min.y??0;this._unit=L(a?{x:Math.max(m,d),y:Math.max(E,u)}:{x:Math.max(m,Math.min(y,d)),y:Math.max(E,Math.min(w,u))})}get unit(){return this._unit}get viewport(){return this._viewport}get gap(){return this._gap}toUnits(i){return D({x:i.x==null?void 0:i.x/(this._unit.x??1),y:i.y==null?void 0:i.y/(this._unit.y??1)})}toPixels(i){const t=this._unit.x??0,e=this._unit.y??0,s=this._gap.x??x,n=this._gap.y??x,o=i.x==null?void 0:i.x*t+Math.max(0,i.x-1)*s,a=i.y==null?void 0:i.y*e+Math.max(0,i.y-1)*n;return L({x:o,y:a})}}const ct=1e-4,V=1e-6,Mn=40,Tn=24;function Hi(r,i){return Math.max(0,r-i*2)}function Vi(r){const i=[0];for(const t of r)i.push((i[i.length-1]??0)+t);return i}function zi(r){const i=[0];for(let t=0;t<r.length;t+=1){const e=i[t]??0;i.push(e+r[t]+x)}return i}function Gi(r,i,t){if(i<0||i>=r.length)return 0;let e=0,s=0;for(let n=i;n<r.length;n+=1){const o=r[n],a=s===0?o:e+x+o;if(a>t+ct)break;e=a,s+=1}return Math.max(1,s)}function Wn(r,i,t){if(i<0||i>=r.length)return 0;let e=0,s=0;for(let n=i;n>=0;n-=1){const o=r[n],a=s===0?o:e+x+o;if(a>t+ct)break;e=a,s+=1}return Math.max(1,s)}function Rn(r,i){if(r.length===0)return 0;let t=0,e=0;for(let s=r.length-1;s>=0;s-=1){const n=r[s],o=e===0?n:t+x+n;if(o>i+ct)break;t=o,e+=1}return Math.max(1,e)}function ur(r,i){if(r.length===0)return 0;const t=Rn(r,i);return Math.max(0,r.length-t)}function zr(r,i,t){if(r.length===0)return 0;const e=Gi(r,i,t),s=Math.min(r.length,i+e);if(s<=i)return 0;const n=r.slice(i,s);return n.reduce((o,a)=>o+a,0)+Math.max(0,n.length-1)*x}function nr(r,i,t){const e=r[i]??0;return t-e}function ut(r,i,t,e,s){if(r.length===0)return 0;const n=ur(r,s),o=i[n]??0,a=Math.max(0,Math.min(o,t));let c=0;for(let _=0;_<n;_+=1){const Zt=i[_]??0,P=i[_+1]??Zt;if(a>=Zt&&a<=P+ct){c=_;break}c=_+1}const l=Math.min(c+1,n),d=i[c]??0,u=i[l]??d,y=Math.max(u-d,ct),w=l===c?0:(a-d)/y,m=zi(r),E=zr(r,c,s),R=zr(r,l,s),F=(e-E)/2,ht=(e-R)/2,jt=nr(m,c,F),we=nr(m,l,ht);return jt+(we-jt)*w}function Gr(r,i,t,e,s){const n=ur(r,e),o=i[n]??0;let a=0,c=o;for(let l=0;l<Mn;l+=1){const d=(a+c)/2;ut(r,i,d,t,e)>s?a=d:c=d}return(a+c)/2}function Yr(r,i,t){const e=zi(r),[s,n]=i,o=r.slice(s,n+1),a=o.reduce((l,d)=>l+d,0)+Math.max(0,o.length-1)*x,c=(t-a)/2;return nr(e,s,c)}function Nn(r,i,t){const e=Gi(r,i,t);return[i,Math.min(r.length-1,i+e-1)]}function Fn(r,i,t){const e=Wn(r,i,t);return[Math.max(0,i-e+1),i]}function On(r){const i=new Set,t=[];for(const e of r){const s=`${e.nodeRange[0]}:${e.nodeRange[1]}`;if(i.has(s))continue;const n=t[t.length-1];n&&Math.abs(n.anchor-e.anchor)<=V||(i.add(s),t.push(e))}return t}function Un(r){const{nodeCols:i,nodeWidthsPx:t,viewportWidthPx:e}=r;if(i.length===0||t.length===0)return{viewspans:[],minScroll:0,maxScroll:0};const s=r.gapPx??x,n=Hi(e,s),o=Vi(i),a=ur(t,n),c=o[a]??0,l=[];for(let d=0;d<=a;d+=1){const u=Nn(t,d,n),y=Yr(t,u,e),w=Gr(t,o,e,n,y);l.push({nodeRange:u,anchor:Math.max(0,Math.min(c,w))})}for(let d=t.length-1;d>=0;d-=1){const u=Fn(t,d,n),y=`${u[0]}:${u[1]}`;if(l.some(E=>`${E.nodeRange[0]}:${E.nodeRange[1]}`===y))continue;const w=Yr(t,u,e),m=Gr(t,o,e,n,w);l.push({nodeRange:u,anchor:Math.max(0,Math.min(c,m))})}return l.sort((d,u)=>Math.abs(d.anchor-u.anchor)>V?d.anchor-u.anchor:d.nodeRange[0]!==u.nodeRange[0]?d.nodeRange[0]-u.nodeRange[0]:d.nodeRange[1]-u.nodeRange[1]),{viewspans:On(l),minScroll:0,maxScroll:c}}function Hn(r,i){var s;let t=0,e=Number.POSITIVE_INFINITY;for(let n=0;n<r.length;n+=1){const o=Math.abs((((s=r[n])==null?void 0:s.anchor)??0)-i);if(o+V<e){e=o,t=n;continue}Math.abs(o-e)<=V&&n<t&&(t=n)}return t}function Vn(r,i,t){return t<=0?0:Math.max(0,Math.min(t-1,r+i))}function bt(r,i,t){return Math.max(i,Math.min(t,r))}class zn extends Kt{constructor(t){super();h(this,"_scroll",0);h(this,"minScroll",0);h(this,"maxScroll",0);h(this,"viewspans",[]);h(this,"activeViewspanIndex",null);h(this,"nodeWidthsPx",[]);h(this,"boundaryCols",[0]);h(this,"viewportWidthPx",0);h(this,"framedViewportWidthPx",0);this._scroll=(t==null?void 0:t.x)??0}get scroll(){return D({x:this._scroll})}get translate(){return L({x:ut(this.nodeWidthsPx,this.boundaryCols,this._scroll,this.viewportWidthPx,this.framedViewportWidthPx)})}set scroll(t){const e=bt(t.x??this._scroll,this.minScroll,this.maxScroll);Math.abs(e-this._scroll)<=V||(this._scroll=e,this.activeViewspanIndex=null,this.emit("scroll",this.scroll))}rebuild(t){const e=t.nodeWidths.map(l=>Math.max(0,l.x??0)),s=e.map(l=>t.grid.toPixels(D({x:l})).x??0),n=t.grid.viewport.x??0,o=t.grid.gap.x??x,a=Un({nodeCols:e,nodeWidthsPx:s,viewportWidthPx:n,gapPx:o});this.nodeWidthsPx=s,this.boundaryCols=Vi(e),this.viewportWidthPx=n,this.framedViewportWidthPx=Hi(n,o),this.viewspans=a.viewspans,this.minScroll=a.minScroll,this.maxScroll=a.maxScroll,this.activeViewspanIndex=null;const c=bt(this._scroll,this.minScroll,this.maxScroll);Math.abs(c-this._scroll)>V&&(this._scroll=c,this.emit("scroll",this.scroll))}step(t){var a;if(this.viewspans.length===0)return;const e=this.activeViewspanIndex??Hn(this.viewspans,this._scroll),s=Vn(e,t,this.viewspans.length),n=((a=this.viewspans[s])==null?void 0:a.anchor)??this._scroll,o=bt(n,this.minScroll,this.maxScroll);this.activeViewspanIndex=s,!(Math.abs(o-this._scroll)<=V)&&(this._scroll=o,this.emit("scroll",this.scroll))}wheel(t){const e=bt(this._scroll+(t.x??0),this.minScroll,this.maxScroll);this.activeViewspanIndex=null,!(Math.abs(e-this._scroll)<=V)&&(this._scroll=e,this.emit("scroll",this.scroll))}wheelPixels(t){const e=t.x??0;if(Math.abs(e)<=ct)return;this.activeViewspanIndex=null;const s=ut(this.nodeWidthsPx,this.boundaryCols,this._scroll,this.viewportWidthPx,this.framedViewportWidthPx),n=s-e,o=ut(this.nodeWidthsPx,this.boundaryCols,this.maxScroll,this.viewportWidthPx,this.framedViewportWidthPx),a=ut(this.nodeWidthsPx,this.boundaryCols,this.minScroll,this.viewportWidthPx,this.framedViewportWidthPx),c=Math.max(o,Math.min(a,n));if(Math.abs(c-s)<=ct)return;let l=this.minScroll,d=this.maxScroll;for(let y=0;y<Tn;y+=1){const w=(l+d)/2;ut(this.nodeWidthsPx,this.boundaryCols,w,this.viewportWidthPx,this.framedViewportWidthPx)>c?l=w:d=w}const u=bt((l+d)/2,this.minScroll,this.maxScroll);Math.abs(u-this._scroll)<=V||(this._scroll=u,this.emit("scroll",this.scroll))}}const Gn={"stack-above":{left:.25,top:0,width:.5,height:.5},"stack-below":{left:.25,top:.5,width:.5,height:.5},"reorder-before":{left:0,top:0,width:.25,height:1},"reorder-after":{left:.75,top:0,width:.25,height:1}},Yn=["stack-above","stack-below","reorder-before","reorder-after"];function Xn(r,i){return{left:r.left+r.width*i.left,top:r.top+r.height*i.top,width:r.width*i.width,height:r.height*i.height}}function De(r,i,t){return r>=t.left&&r<t.left+t.width&&i>=t.top&&i<t.top+t.height}function ue(r){return r.height===T||r.height===q?{...r,height:q}:r}function Xr(r){return r.height===q?{...r,height:T}:r}function Kn(r,i,t){if(i===t)return r;const e=[...r],[s]=e.splice(i,1);return s?(e.splice(t,0,s),e):r}function qn(r,i,t,e){const s=r[i];if(!s||s.type!=="card")return r;const n=r.findIndex(m=>m.type==="card"&&m.id===t);if(n===-1||n===i)return r;const o=r[n];if(o.type!=="card")return r;const a=Math.max(i,n),c=Math.min(i,n),l=[...r];l.splice(a,1),l.splice(c,1);const d=ue(s),u=ue(o),y=e==="above"?[d,u]:[u,d],w={id:Dt(),type:"stack",children:y};return l.splice(c,0,w),l}function Yi(r,i,t,e){const s=r.findIndex(d=>d.type==="stack"&&d.id===i);if(s===-1)return r;const n=r[s];if(!n||n.type!=="stack")return r;const o=n.children.find(d=>d.type==="card"&&d.id===t);if(!o||o.type!=="card")return r;const a=n.children.filter(d=>d.id!==t);if(a.length===n.children.length||a.length<1)return r;const c=[...r];if(a.length===1){const[d]=a;c[s]=d.type==="card"?Xr(d):d}else c[s]={...n,children:a};const l=Math.max(0,Math.min(e,c.length));return c.splice(l,0,Xr(o)),c}function Bn(r,i,t,e){const s=r.findIndex(u=>u.type==="stack"&&u.id===i);if(s===-1)return r;const n=r[s];if(!n||n.type!=="stack"||!n.children.every(u=>u.type==="card"))return r;const o=n.children,a=o.find(u=>u.id===t);if(!a)return r;const c=o.filter(u=>u.id!==t);if(c.length===0)return r;const l=e==="above"?[a,...c]:[...c,a];if(l.every((u,y)=>{var w;return u.id===((w=o[y])==null?void 0:w.id)}))return r;const d=[...r];return d[s]={...n,children:l},d}const jn=50;function Zn(r,i){if(r.type!==i.type)return!1;switch(r.type){case"reorder":return i.index===r.index;case"stack":return i.targetCardId===r.targetCardId&&i.position===r.position;case"stack-child-noop":return!0;case"stack-child-extract":return i.toIndex===r.toIndex;case"stack-child-reorder":return i.position===r.position;default:return!1}}class Jn extends Kt{constructor(t){super();h(this,"pendingDrag",null);h(this,"activeDrag",null);h(this,"init");this.init=t}startPotentialDrag(t){if(this.pendingDrag||this.activeDrag)return;const e=t.pointerCoord.x??0,s=t.pointerCoord.y??0;this.pendingDrag={pointerId:t.pointerId,cardId:t.cardId,cardIndex:t.cardIndex,startX:e,startY:s,grabOffsetX:e-t.cardRect.left,grabOffsetY:s-t.cardRect.top,pointerX:e,pointerY:s,width:t.cardRect.width,height:t.cardRect.height,sourceStackId:t.sourceStackId}}update(t){const e=t.pointer.x??0,s=t.pointer.y??0,n=this.pendingDrag;if(n){const a=e-n.startX,c=s-n.startY;Math.hypot(a,c)>=ys&&(this.pendingDrag=null,this.activeDrag={...n,pointerX:e,pointerY:s,dropTarget:{type:"reorder",index:n.cardIndex},placeholderId:n.cardId,lastReorderIndex:n.cardIndex},this.emit("render-requested"));return}if(!this.activeDrag)return;const o=this.getDropTargetForPointer(e,s,t);this.activeDrag.pointerX===e&&this.activeDrag.pointerY===s&&Zn(this.activeDrag.dropTarget,o)||(this.activeDrag={...this.activeDrag,pointerX:e,pointerY:s,dropTarget:o,lastReorderIndex:o.type==="reorder"?o.index:this.activeDrag.lastReorderIndex},this.emit("render-requested"))}endDrag(t){if(this.pendingDrag&&t===this.pendingDrag.pointerId){this.cancel();return}if(!this.activeDrag)return;const e=this.activeDrag,s=this.init.getLayout(),n=e.dropTarget;switch(n.type){case"stack-child-noop":break;case"stack-child-reorder":{if(!e.sourceStackId)break;const o=Bn(s,e.sourceStackId,e.cardId,n.position);o!==s&&this.emit("layout-proposed",o);break}case"stack-child-extract":{if(!e.sourceStackId)break;const o=Yi(s,e.sourceStackId,e.cardId,n.toIndex);o!==s&&this.emit("layout-proposed",o);break}case"stack":{const o=qn(s,e.cardIndex,n.targetCardId,n.position);o!==s&&this.emit("layout-proposed",o);break}case"reorder":{if(n.index!==e.cardIndex){const o=Kn(s,e.cardIndex,n.index);this.emit("layout-proposed",o)}break}}this.resetDragState(),this.emit("render-requested")}cancel(){!this.pendingDrag&&!this.activeDrag||(this.resetDragState(),this.emit("render-requested"))}get status(){return this.activeDrag?"active":this.pendingDrag?"pending":"idle"}getSnapshot(){return!this.pendingDrag&&!this.activeDrag?null:{pending:this.pendingDrag,active:this.activeDrag}}dispose(){this.resetDragState()}resetDragState(){this.pendingDrag=null,this.activeDrag=null}getDropTargetForPointer(t,e,s){return this.activeDrag?this.isPointerInsideDragBounds(t,e,s.viewport)?this.activeDrag.sourceStackId?this.getStackChildDropTarget(t,e,s):this.getTopLevelCardDropTarget(t,e,s):{type:"reorder",index:this.activeDrag.cardIndex}:{type:"reorder",index:0}}getStackChildDropTarget(t,e,s){var c;if(!((c=this.activeDrag)!=null&&c.sourceStackId))return{type:"stack-child-noop"};const n=s.nodes.find(l=>{var d;return l.id===((d=this.activeDrag)==null?void 0:d.sourceStackId)});n&&(this.activeDrag.sourceStackRect=n.rect);const o=(n==null?void 0:n.rect)??this.activeDrag.sourceStackRect;if(o&&t<=o.left)return{type:"stack-child-extract",toIndex:0};if(o&&De(t,e,o)){const l=o.top+o.height/2;return{type:"stack-child-reorder",position:e<l?"above":"below"}}const a=this.getDropIndexForPointerLegacy(t,e,s);return a===this.activeDrag.cardIndex||a<0?{type:"stack-child-noop"}:{type:"stack-child-extract",toIndex:a}}getTopLevelCardDropTarget(t,e,s){var w,m,E;const n=s.nodes,o=this.getTopLevelZoneNodes(n);if(o.length===0)return{type:"reorder",index:((w=this.activeDrag)==null?void 0:w.cardIndex)??0};const c=(s.effectiveVelocity??0)<=jn;for(const R of o){const F=R.rect;if(!De(t,e,F))continue;const ht=this.resolveTopLevelTargetForCard(t,e,R,R.logicalIndex,c);if(ht)return ht;if(!c&&((m=this.activeDrag)!=null&&m.dropTarget))return this.activeDrag.dropTarget}const l=this.getNearestTargetableZone(t,o);if(!l)return{type:"reorder",index:((E=this.activeDrag)==null?void 0:E.cardIndex)??0};const d=Math.max(l.rect.left,Math.min(l.rect.left+l.rect.width,t)),u=this.resolveTopLevelTargetForCard(d,e,l,l.logicalIndex,c);if(u)return u;const y=l.rect.left+l.rect.width/2;return{type:"reorder",index:t<y?l.logicalIndex:l.logicalIndex+1}}getDropIndexForPointerLegacy(t,e,s){var o;if(!this.activeDrag)return 0;const n=this.getTopLevelZoneNodes(s.nodes);for(let a=0;a<n.length;a+=1){const c=(o=n[a])==null?void 0:o.rect;if(!c)continue;const l=c.left+c.width/2;if(t<l)return a}return n.length}getTopLevelZoneNodes(t){const e=[];let s=0;for(const n of t)n.targetable&&(n.type==="card"||n.type==="stack")&&(e.push({id:n.id,rect:n.rect,logicalIndex:s}),s+=1);return e}resolveTopLevelTargetForCard(t,e,s,n,o){const a=s.rect;for(const c of Yn){if(!o&&(c==="stack-above"||c==="stack-below"))continue;const l=Gn[c],d=Xn(a,l);if(De(t,e,d))return c==="stack-above"?{type:"stack",targetCardId:s.id,position:"above"}:c==="stack-below"?{type:"stack",targetCardId:s.id,position:"below"}:c==="reorder-before"?{type:"reorder",index:n}:{type:"reorder",index:n+1}}return null}getNearestTargetableZone(t,e){let s=null,n=Number.POSITIVE_INFINITY;for(const o of e){const a=o.rect.left,c=o.rect.left+o.rect.width,l=t<a?a-t:t>c?t-c:0;l<n&&(n=l,s=o)}return s}isPointerInsideDragBounds(t,e,s){return t>=s.left&&t<=s.left+s.width&&e>=s.top&&e<=s.top+s.height}}const Kr=120,Qn=80,qr=.5;class to{constructor(){h(this,"awaitingFreshWheelGesture",!1);h(this,"lastWheelEventAt",Number.NEGATIVE_INFINITY);h(this,"lastWheelDeltaX",0);h(this,"activeGestureType","none");h(this,"lastWheelGestureAt",Number.NEGATIVE_INFINITY)}markKeyboardNavigation(i){this.awaitingFreshWheelGesture=!0,this.lastWheelEventAt=i,this.activeGestureType="none"}reset(){this.awaitingFreshWheelGesture=!1,this.lastWheelEventAt=Number.NEGATIVE_INFINITY,this.lastWheelDeltaX=0,this.activeGestureType="none",this.lastWheelGestureAt=Number.NEGATIVE_INFINITY}decide(i){const{now:t,shiftKey:e,deltaX:s,deltaY:n,overArtifactContent:o,artifactCanScrollUp:a,artifactCanScrollDown:c}=i;t-this.lastWheelGestureAt>=Kr&&(this.activeGestureType="none");const d=e&&n!==0,u=d?n:s,y=n>0?c:n<0?a:!1;if(this.activeGestureType==="vertical-artifact"&&o&&y)return this.lastWheelGestureAt=t,{type:"scroll-native"};if(this.activeGestureType==="horizontal-filmstrip"&&Math.abs(u)>=qr)return this.lastWheelGestureAt=t,this.lastWheelEventAt=t,this.lastWheelDeltaX=u,{type:"scroll-horizontal",horizontalDelta:u};if(Math.abs(u)<qr)return o&&y&&(this.activeGestureType="vertical-artifact"),this.lastWheelGestureAt=t,{type:"scroll-native"};if(!d&&o&&y&&Math.abs(n)>=Math.abs(u))return this.activeGestureType="vertical-artifact",this.lastWheelGestureAt=t,{type:"scroll-native"};const w=t-this.lastWheelEventAt,m=Math.sign(this.lastWheelDeltaX),E=Math.sign(u),R=m!==0&&E!==0&&m!==E,F=m!==0&&Math.abs(u)>=Math.abs(this.lastWheelDeltaX)+Qn;return this.lastWheelEventAt=t,this.lastWheelDeltaX=u,this.lastWheelGestureAt=t,this.awaitingFreshWheelGesture&&w<Kr&&!R&&!F?{type:"ignore"}:(this.awaitingFreshWheelGesture=!1,this.activeGestureType="horizontal-filmstrip",{type:"scroll-horizontal",horizontalDelta:u})}}const eo=2,Br=1e3,Ce=1e-4;function jr(r,i,t){if(r===0)return 0;const e=i.toPixels(D({y:T})).y??0;return(t-e)/eo}class ro extends Event{constructor(t){super("scroll",{bubbles:!0,composed:!0});h(this,"scrollPosition");this.scrollPosition=t}}class io extends Event{constructor(t){super("layout-change",{bubbles:!0,composed:!0});h(this,"layout");this.layout=t}}class so extends HTMLElement{constructor(){super();h(this,"_layout",[]);h(this,"_scrollPosition",0);h(this,"layoutGrid",null);h(this,"layoutScroll",new zn(D({x:0})));h(this,"scrollModelKey","");h(this,"resizeObserver",null);h(this,"renderPending",!1);h(this,"animateNextRender",!0);h(this,"wheelGesture",new to);h(this,"dragController",new Jn({getLayout:()=>this._layout}));h(this,"dragListenersAttached",!1);h(this,"dragFrame",0);h(this,"lastDragFrameTime",0);h(this,"lastPointerX",0);h(this,"lastPointerY",0);h(this,"pointerVelocityPxPerSec",0);h(this,"scrollVelocityPxPerSec",0);h(this,"motionSampleTime",0);h(this,"motionSampleX",0);h(this,"motionSampleY",0);h(this,"renderContent",()=>v``);h(this,"handleKeyDown",t=>{var e,s;if(t.key==="Escape"&&this.dragController.getSnapshot()){t.preventDefault(),this.stopDragFrameLoop();const n=this.dragController.getSnapshot(),o=((e=n==null?void 0:n.active)==null?void 0:e.pointerId)??((s=n==null?void 0:n.pending)==null?void 0:s.pointerId);o!==void 0&&this.releasePointerCaptureForEvent(o),this.dragController.cancel(),this.detachDragListeners();return}this.dragController.getSnapshot()||(t.key==="ArrowRight"?(t.preventDefault(),this.wheelGesture.markKeyboardNavigation(Date.now()),this.shiftWindow(1)):t.key==="ArrowLeft"&&(t.preventDefault(),this.wheelGesture.markKeyboardNavigation(Date.now()),this.shiftWindow(-1)))});h(this,"handleWheel",t=>{if(this._layout.length===0)return;const e=this.wheelGesture.decide({now:Date.now(),shiftKey:t.shiftKey,deltaX:t.deltaX,deltaY:t.deltaY,overArtifactContent:!1,artifactCanScrollDown:!1,artifactCanScrollUp:!1});if(e.type!=="scroll-horizontal")return;t.preventDefault(),this.syncScrollModel();const s=this.layoutGrid;if(!s)return;this.animateNextRender=!1;const n=s.toUnits(L({x:e.horizontalDelta}));this.layoutScroll.wheel(D({x:n.x??0}))});h(this,"handlePointerDown",t=>{if(t.button!==0||this.dragController.getSnapshot())return;const e=t.target;if(!(e instanceof Element))return;const s=e.closest(".card-slot[data-layout-draggable='true']");if(!s)return;const n=s.getAttribute("data-layout-node-id");if(!n)return;const o=oo(this._layout,n);if(!o)return;const a=s.getBoundingClientRect();this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.resetMotionTracking(t.clientX,t.clientY),this.focus(),this.dragController.startPotentialDrag({pointerId:t.pointerId,pointerCoord:L({x:t.clientX,y:t.clientY}),cardId:n,cardIndex:o.topLevelIndex,cardRect:{left:a.left,top:a.top,width:a.width,height:a.height},sourceStackId:o.sourceStackId}),this.attachDragListeners();try{this.setPointerCapture(t.pointerId)}catch{}t.preventDefault()});h(this,"handleWindowPointerMove",t=>{this.lastPointerX=t.clientX,this.lastPointerY=t.clientY,this.updatePointerVelocity(t.clientX,t.clientY),this.syncDragTargetForLatestPointer(),this.ensureDragFrameLoop()});h(this,"handleWindowPointerUp",t=>{this.stopDragFrameLoop(),this.releasePointerCaptureForEvent(t.pointerId),this.dragController.endDrag(t.pointerId),this.clearMotionTracking(),this.detachDragListeners()});h(this,"handleWindowPointerCancel",t=>{this.stopDragFrameLoop(),this.releasePointerCaptureForEvent(t.pointerId),this.dragController.cancel(),this.clearMotionTracking(),this.detachDragListeners()});h(this,"handleWindowBlur",()=>{var s,n;const t=this.dragController.getSnapshot(),e=((s=t==null?void 0:t.active)==null?void 0:s.pointerId)??((n=t==null?void 0:t.pending)==null?void 0:n.pointerId);e!==void 0&&this.releasePointerCaptureForEvent(e),this.stopDragFrameLoop(),this.dragController.cancel(),this.clearMotionTracking(),this.detachDragListeners()});h(this,"runDragFrame",t=>{if(this.dragController.status==="idle"){this.dragFrame=0;return}const e=Math.max(0,t-this.lastDragFrameTime)/Br;this.lastDragFrameTime=t,this.samplePointerVelocityAt(t,this.lastPointerX,this.lastPointerY);const s=this.getBoundingClientRect(),n=this.clampPointerToViewport(this.lastPointerX,this.lastPointerY,s),o=this.getDragEdgeScrollDeltaPixels(n.x,s,e);this.scrollVelocityPxPerSec=e>Ce?Math.abs(o)/e:0,Math.abs(o)>Ce&&(this.animateNextRender=!1,this.layoutScroll.wheelPixels(L({x:o}))),this.dragController.status==="active"&&this.syncDragTarget(n.x,n.y,s),this.dragFrame=requestAnimationFrame(this.runDragFrame)});this.dragController.on("render-requested",()=>this.scheduleRender()),this.dragController.on("layout-proposed",t=>this.commitLayout(t)),this.layoutScroll.on("scroll",t=>{const e=t.x??0;Math.abs(e-this._scrollPosition)<Ce||(this._scrollPosition=e,this.emitScrollPositionChanged(e),this.scheduleRender())})}set layout(t){this._layout=[...t],this.stopDragFrameLoop(),this.dragController.cancel(),this.scrollModelKey="",this.syncScrollModel(),this.layoutScroll.scroll=D({x:this._scrollPosition}),this.scheduleRender()}get layout(){return this._layout}commitLayout(t){this.layout=t,this.emitLayoutChanged()}set scrollPosition(t){this.animateNextRender=!1,this.syncScrollModel(),this.layoutScroll.scroll=D({x:t})}get scrollPosition(){return this._scrollPosition}connectedCallback(){this.hasAttribute("tabindex")||(this.tabIndex=0),this.focus(),this.addEventListener("keydown",this.handleKeyDown),this.addEventListener("wheel",this.handleWheel,{passive:!1}),this.addEventListener("pointerdown",this.handlePointerDown),typeof ResizeObserver<"u"&&(this.resizeObserver=new ResizeObserver(()=>this.render()),this.resizeObserver.observe(this)),this.render()}disconnectedCallback(){var t;this.removeEventListener("keydown",this.handleKeyDown),this.removeEventListener("wheel",this.handleWheel),this.removeEventListener("pointerdown",this.handlePointerDown),(t=this.resizeObserver)==null||t.disconnect(),this.resizeObserver=null,this.wheelGesture.reset(),this.detachDragListeners(),this.dragController.dispose(),this.stopDragFrameLoop()}scheduleRender(){this.renderPending||(this.renderPending=!0,queueMicrotask(()=>{this.renderPending=!1,this.render()}))}createGrid(t,e){return new Ln({basis:L({x:Q,y:Q}),min:L({x:Ir,y:Ir}),viewport:L({x:t,y:e}),gap:L({x,y:x})})}syncScrollModel(){const t=this.clientWidth>0?this.clientWidth:st,e=this.clientHeight>0?this.clientHeight:pt,n=It(this._layout).nodes.map(a=>a.width),o=`${t}x${e}:${n.join(",")}`;o===this.scrollModelKey&&this.layoutGrid||(this.scrollModelKey=o,this.layoutGrid=this.createGrid(t,e),this.layoutScroll.rebuild({grid:this.layoutGrid,nodeWidths:n.map(a=>D({x:a}))}))}emitScrollPositionChanged(t){this.dispatchEvent(new ro(t))}emitLayoutChanged(){this.dispatchEvent(new io([...this._layout]))}shiftWindow(t){this.syncScrollModel(),this.animateNextRender=!0,this.layoutScroll.step(t)}releasePointerCaptureForEvent(t){try{this.hasPointerCapture(t)&&this.releasePointerCapture(t)}catch{}}attachDragListeners(){this.dragListenersAttached||(window.addEventListener("pointermove",this.handleWindowPointerMove),window.addEventListener("pointerup",this.handleWindowPointerUp),window.addEventListener("pointercancel",this.handleWindowPointerCancel),this.addEventListener("pointermove",this.handleWindowPointerMove),this.addEventListener("pointerup",this.handleWindowPointerUp),this.addEventListener("pointercancel",this.handleWindowPointerCancel),window.addEventListener("blur",this.handleWindowBlur),this.dragListenersAttached=!0)}detachDragListeners(){this.dragListenersAttached&&(window.removeEventListener("pointermove",this.handleWindowPointerMove),window.removeEventListener("pointerup",this.handleWindowPointerUp),window.removeEventListener("pointercancel",this.handleWindowPointerCancel),this.removeEventListener("pointermove",this.handleWindowPointerMove),this.removeEventListener("pointerup",this.handleWindowPointerUp),this.removeEventListener("pointercancel",this.handleWindowPointerCancel),window.removeEventListener("blur",this.handleWindowBlur),this.dragListenersAttached=!1)}getDisplayPreview(t){const e=t==null?void 0:t.active;if(!e)return{layout:this._layout,activePlaceholderId:null,placeholdersById:new Map};const s=new Map;return s.set(e.placeholderId,{id:e.placeholderId,sourceCardId:e.cardId}),e.sourceStackId?this.getStackChildDragPreview(e,s):this.getTopLevelDragPreview(e,s)}getStackChildDragPreview(t,e){const s=t.dropTarget;switch(s.type){case"stack-child-reorder":return this.buildStackChildReorderPreview(t,e,s.position);case"stack-child-extract":return this.buildStackChildExtractPreview(t,e,s.toIndex);case"stack-child-noop":return this.buildStackChildNoopPreview(t,e);default:return{layout:this._layout,activePlaceholderId:null,placeholdersById:e}}}buildStackChildReorderPreview(t,e,s){const n=this._layout.findIndex(m=>m.type==="stack"&&m.id===t.sourceStackId);if(n===-1)return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};const o=this._layout[n];if(!o||o.type!=="stack")return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};if(!o.children.every(m=>m.type==="card"))return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};const a=o.children,c=a.findIndex(m=>m.id===t.cardId);if(c===-1)return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};const l=a[c],d=a.filter(m=>m.id!==t.cardId),u=St(l,t.placeholderId),y=s==="above"?[u,...d]:[...d,u],w=[...this._layout];return w[n]={...o,children:y},{layout:w,activePlaceholderId:t.placeholderId,placeholdersById:e}}buildStackChildExtractPreview(t,e,s){if(!t.sourceStackId)return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};const n=Yi(this._layout,t.sourceStackId,t.cardId,s);if(n===this._layout)return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};const o=n.findIndex(l=>l.type==="card"&&l.id===t.cardId);if(o===-1)return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};const a=n[o];if(!a||a.type!=="card")return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};const c=[...n];return c[o]=St(a,t.placeholderId),{layout:c,activePlaceholderId:t.placeholderId,placeholdersById:e}}buildStackChildNoopPreview(t,e){const s=this._layout.findIndex(d=>d.type==="stack"&&d.id===t.sourceStackId);if(s===-1)return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};const n=this._layout[s];if(!n||n.type!=="stack")return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};const o=n.children.findIndex(d=>d.type==="card"&&d.id===t.cardId);if(o===-1)return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};const a=n.children[o];if(!a||a.type!=="card")return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};const c=[...this._layout],l=[...n.children];return l[o]=St(a,t.placeholderId),c[s]={...n,children:l},{layout:c,activePlaceholderId:t.placeholderId,placeholdersById:e}}getTopLevelDragPreview(t,e){const s=t.dropTarget;if(s.type==="reorder"){const n=this._layout[t.cardIndex];return!n||n.type!=="card"?{layout:this._layout,activePlaceholderId:null,placeholdersById:e}:this.buildTopLevelReorderPreview(t,e,n,s.index)}return s.type==="stack"?this.buildTopLevelStackPreview(t,e,s):{layout:this._layout,activePlaceholderId:null,placeholdersById:e}}buildTopLevelReorderPreview(t,e,s,n){const o=[...this._layout];return o.splice(t.cardIndex,1),o.splice(n,0,St(s,t.placeholderId)),{layout:o,activePlaceholderId:t.placeholderId,placeholdersById:e}}buildTopLevelStackPreview(t,e,s){const n=this.buildTopLevelVisualBaseLayout(t);if(!n)return{layout:this._layout,activePlaceholderId:null,placeholdersById:e};const o=this.buildTopLevelStackPreviewLayout(n,t,s);return o?{layout:o,activePlaceholderId:t.placeholderId,placeholdersById:e}:{layout:this._layout,activePlaceholderId:null,placeholdersById:e}}render(){const t=this.clientWidth>0?this.clientWidth:st,e=this.clientHeight>0?this.clientHeight:pt,s=this.createGrid(t,e);this.layoutGrid=s;const n=this.dragController.getSnapshot(),o=this.getDisplayPreview(n),a=o.layout,c=(n==null?void 0:n.active)!==void 0,l=It(a),d=l.nodes.map(_=>_.width),u=ao(a),y=`${t}x${e}:${d.join(",")}`;!c&&y!==this.scrollModelKey&&(this.scrollModelKey=y,this.layoutScroll.rebuild({grid:s,nodeWidths:d.map(_=>D({x:_}))}),this._scrollPosition=this.layoutScroll.scroll.x??this._scrollPosition);const w=no(a),m=s.unit.x??Q,E=s.unit.y??Q,R=this.getPreviewTranslateOffsetX((n==null?void 0:n.active)??null),F=(this.layoutScroll.translate.x??0)+R,ht=jr(l.nodes.length,s,e),jt=this.animateNextRender&&!c,we=[`transform: translate(${F}px, ${ht}px);`,`transition-duration: ${jt?vs:0}ms;`,`pointer-events: ${c?"none":"auto"};`].join(" ");this.animateNextRender=!0,this.style.setProperty("--layout-unit-x",`${m}px`),this.style.setProperty("--layout-unit-y",`${E}px`),this.style.setProperty("--layout-gap",`${x}px`),I(v`
|
|
110
|
+
<div class="track" style=${we}>
|
|
111
|
+
${l.nodes.map((_,Zt)=>v`
|
|
112
|
+
<div
|
|
113
|
+
class="node"
|
|
114
|
+
layout-node=${String(Zt)}
|
|
115
|
+
data-layout-node-id=${_.id}
|
|
116
|
+
data-layout-placeholder=${String(o.activePlaceholderId===_.id)}
|
|
117
|
+
layout-node-cols=${String(_.width)}
|
|
118
|
+
style=${`grid-template-columns: repeat(${_.width}, var(--layout-unit-x)); width: ${s.toPixels(D({x:_.width})).x}px;`}
|
|
119
|
+
>
|
|
120
|
+
${_.cards.map(P=>{const Qi=o.placeholdersById.get(P.id);if(n!=null&&n.active&&Qi)return v`
|
|
121
|
+
<div
|
|
122
|
+
class="card-slot card-placeholder"
|
|
123
|
+
data-layout-placeholder-for=${n.active.cardId}
|
|
124
|
+
data-layout-placeholder-ghost="false"
|
|
125
|
+
style=${`grid-column: ${P.col} / span ${P.width}; grid-row: ${P.row} / span ${P.height};`}
|
|
126
|
+
></div>
|
|
127
|
+
`;const Sr=w.get(P.id);if(!Sr)return null;const ts=(_.type==="card"&&P.id===_.id||u.has(P.id))&&(!(n!=null&&n.active)||_.id!==o.activePlaceholderId);return v`
|
|
128
|
+
<div
|
|
129
|
+
class="card-slot"
|
|
130
|
+
data-layout-card-id=${P.artifactID}
|
|
131
|
+
data-layout-draggable=${String(ts)}
|
|
132
|
+
data-layout-node-id=${P.id}
|
|
133
|
+
layout-cols=${String(P.width)}
|
|
134
|
+
layout-rows=${String(P.height)}
|
|
135
|
+
style=${`grid-column: ${P.col} / span ${P.width}; grid-row: ${P.row} / span ${P.height};`}
|
|
136
|
+
>
|
|
137
|
+
${this.renderContent(Sr)}
|
|
138
|
+
</div>
|
|
139
|
+
`})}
|
|
140
|
+
</div>
|
|
141
|
+
`)}
|
|
142
|
+
</div>
|
|
143
|
+
${n!=null&&n.active?(()=>{const _=this.getPlaceholderPixelSize(l,o.activePlaceholderId,s,n.active);return v`
|
|
144
|
+
<div
|
|
145
|
+
class="drag-preview"
|
|
146
|
+
data-layout-preview-card-id=${n.active.cardId}
|
|
147
|
+
style=${[`width: ${_.width}px;`,`height: ${_.height}px;`,`left: ${n.active.pointerX-n.active.grabOffsetX}px;`,`top: ${n.active.pointerY-n.active.grabOffsetY}px;`].join(" ")}
|
|
148
|
+
>
|
|
149
|
+
${this.renderDraggedPreview(n.active.cardId)}
|
|
150
|
+
</div>
|
|
151
|
+
`})():null}
|
|
152
|
+
`,this)}ensureDragFrameLoop(){this.dragFrame!==0||this.dragController.status==="idle"||(this.lastDragFrameTime=performance.now(),this.dragFrame=requestAnimationFrame(this.runDragFrame))}stopDragFrameLoop(){this.dragFrame!==0&&(cancelAnimationFrame(this.dragFrame),this.dragFrame=0,this.scrollVelocityPxPerSec=0)}syncDragTargetForLatestPointer(){const t=this.dragController.getSnapshot();if(!t)return;const e=this.getBoundingClientRect();if(t.active){const n=this.clampPointerToViewport(this.lastPointerX,this.lastPointerY,e);this.syncDragTarget(n.x,n.y,e);return}if(this.syncDragTarget(this.lastPointerX,this.lastPointerY,e),this.dragController.status!=="active")return;const s=this.clampPointerToViewport(this.lastPointerX,this.lastPointerY,e);(s.x!==this.lastPointerX||s.y!==this.lastPointerY)&&this.syncDragTarget(s.x,s.y,e)}syncDragTarget(t,e,s=this.getBoundingClientRect()){const n=this.dragController.getSnapshot();if(!n)return;const o=this.getDisplayPreview(n),a=new Set(o.placeholdersById.keys()),c=this.getPreviewTranslateOffsetX(n.active??null),l=this.measureLayoutGeometry(o.layout,a,c);this.dragController.update({pointer:L({x:t,y:e}),viewport:{left:s.left,top:s.top,width:s.width,height:s.height},nodes:l,effectiveVelocity:Math.max(this.pointerVelocityPxPerSec,this.scrollVelocityPxPerSec)})}resetMotionTracking(t,e){this.pointerVelocityPxPerSec=0,this.scrollVelocityPxPerSec=0,this.motionSampleTime=performance.now(),this.motionSampleX=t,this.motionSampleY=e}clearMotionTracking(){this.pointerVelocityPxPerSec=0,this.scrollVelocityPxPerSec=0,this.motionSampleTime=0}updatePointerVelocity(t,e){this.samplePointerVelocityAt(performance.now(),t,e)}samplePointerVelocityAt(t,e,s){if(this.motionSampleTime===0){this.motionSampleTime=t,this.motionSampleX=e,this.motionSampleY=s,this.pointerVelocityPxPerSec=0;return}const n=t-this.motionSampleTime;if(n<100)return;const o=e-this.motionSampleX;this.pointerVelocityPxPerSec=Math.abs(o)/n*Br,this.motionSampleTime=t,this.motionSampleX=e,this.motionSampleY=s}clampPointerToViewport(t,e,s){return{x:Math.max(s.left,Math.min(s.left+s.width,t)),y:Math.max(s.top,Math.min(s.top+s.height,e))}}isPointerOutsideViewport(t,e,s){return t<s.left||t>s.left+s.width||e<s.top||e>s.top+s.height}getDragEdgeScrollDeltaPixels(t,e,s){var l;const n=e.left+Jt,o=e.left+e.width-Jt,a=((l=this.layoutGrid)==null?void 0:l.unit.x)??Q,c=ws*a;if(t<n){const d=Math.max(0,Math.min(1,(n-t)/Jt));return-(c*d**Er)*s}if(t>o){const d=Math.max(0,Math.min(1,(t-o)/Jt));return c*d**Er*s}return 0}measureLayoutGeometry(t,e,s=0){const n=this.layoutGrid;if(!n)return[];const o=It(t),a=new Map(o.nodes.map(m=>[m.id,m.width])),c=n.toPixels(D({y:T})).y??pt,l=this.clientHeight>0?this.clientHeight:pt,d=(this.layoutScroll.translate.x??0)+s,u=jr(o.nodes.length,n,l),y=[];let w=d;for(const m of t){const E=a.get(m.id)??G,R=n.toPixels(D({x:E})).x??st,F={left:w,top:u,width:R,height:c};m.type==="card"?y.push({...m,rect:F,targetable:!e.has(m.id)}):m.type==="row"?y.push({...m,rect:F,children:[],targetable:!0}):y.push({...m,rect:F,children:[],targetable:!0}),w+=R+x}return y}getPreviewTranslateOffsetX(t){if(!t)return 0;const e=t.dropTarget;if(!t.sourceStackId&&e.type==="stack"){const s=this.layoutGrid;if(!s)return 0;const n=this.buildTopLevelVisualBaseLayout(t);if(!n)return 0;const o=this.buildTopLevelStackPreviewLayout(n,t,e);if(!o)return 0;const a=Zr(n.base,e.targetCardId,s),c=Zr(o,e.targetCardId,s);return a===null||c===null?0:a-c}return t.sourceStackId&&e.type==="stack-child-extract"&&(e.toIndex<t.cardIndex||e.toIndex===0)?-(t.width+x):0}buildTopLevelVisualBaseLayout(t){const e=[...this._layout],s=e.findIndex(c=>c.type==="card"&&c.id===t.cardId);if(s===-1)return null;const n=e[s];if(!n||n.type!=="card")return null;e.splice(s,1);const o=Math.max(0,Math.min(t.lastReorderIndex,e.length));e.splice(o,0,n);const a=e.findIndex(c=>c.type==="card"&&c.id===t.cardId);return a===-1?null:{base:e,visualDraggedIndex:a}}buildTopLevelStackPreviewLayout(t,e,s){const n=[...t.base];n.splice(t.visualDraggedIndex,1);const o=n.findIndex(w=>w.type==="card"&&w.id===s.targetCardId),a=o===-1?null:n[o];if(!a||a.type!=="card")return null;const c=Jr(this._layout,e.cardId);if(!c)return null;const l=ue(c),d=ue(a),u=St(l,e.placeholderId),y=s.position==="above"?[u,d]:[d,u];return n[o]={id:a.id,type:"stack",children:y},n}getPlaceholderPixelSize(t,e,s,n){if(!e)return n;for(const o of t.nodes)for(const a of o.cards)if(a.id===e)return{width:s.toPixels(D({x:a.width})).x??n.width,height:s.toPixels(D({y:a.height})).y??n.height};return n}renderDraggedPreview(t){const e=Jr(this._layout,t);return e?this.renderContent(e):v``}}function no(r){const i=new Map;for(const t of r){if(t.type==="card"){i.set(t.id,t);continue}for(const e of t.children)if(e.type==="card")i.set(e.id,e);else for(const s of e.children)i.set(s.id,s)}return i}function St(r,i){return{...r,id:i,artifactID:i}}function Zr(r,i,t){const e=It(r),s=new Map(e.nodes.map(o=>[o.id,o.width]));let n=0;for(const o of r){if(o.id===i)return n;const a=s.get(o.id)??G,c=t.toPixels(D({x:a})).x??st;n+=c+x}return null}function oo(r,i){const t=r.findIndex(e=>e.type==="card"&&e.id===i);if(t!==-1)return{topLevelIndex:t};for(let e=0;e<r.length;e+=1){const s=r[e];if(!(!s||s.type!=="stack")&&s.children.some(n=>n.type==="card"&&n.id===i))return{topLevelIndex:e,sourceStackId:s.id}}return null}function ao(r){const i=new Set;for(const t of r)if(t.type==="stack")for(const e of t.children)e.type==="card"&&i.add(e.id);return i}function Jr(r,i){return r.find(e=>e.type==="card"&&e.id===i)??null}customElements.get("layout-view")||customElements.define("layout-view",so);class co extends HTMLElement{constructor(){super(...arguments);h(this,"workspaceService",M.resolve("WorkspaceService"));h(this,"subscriptions",new wt);h(this,"handleCloseArtifact",t=>{t instanceof Ui&&this.workspaceService.removeArtifact(t.id)});h(this,"handleScrollPositionChanged",t=>{const e=t;typeof e.scrollPosition=="number"&&Number.isFinite(e.scrollPosition)&&this.workspaceService.setScrollPosition(e.scrollPosition)})}connectedCallback(){this.render(),this.subscriptions.add(this.workspaceService.on("change",()=>this.render()))}disconnectedCallback(){this.subscriptions.dispose()}buildArtifactMap(){return new Map(this.workspaceService.activeArtifacts.map(t=>[t.id,t]))}render(){const t=this.workspaceService.activeWorkspace,e=(t==null?void 0:t.layout)??[],s=this.buildArtifactMap();if(e.length===0){I(v`<p data-testid="empty-workspace">No artifacts yet.</p>`,this);return}I(v`
|
|
153
|
+
<layout-view
|
|
154
|
+
.layout=${e}
|
|
155
|
+
.renderContent=${n=>{const o=s.get(n.artifactID);return o?v`<artifact-view
|
|
156
|
+
.artifact=${o}
|
|
157
|
+
.artifactURL=${this.workspaceService.getArtifactURL(n.artifactID)}
|
|
158
|
+
></artifact-view>`:v``}}
|
|
159
|
+
.scrollPosition=${this.workspaceService.scrollPosition}
|
|
160
|
+
@scroll=${this.handleScrollPositionChanged}
|
|
161
|
+
@close-artifact=${this.handleCloseArtifact}
|
|
162
|
+
></layout-view>
|
|
163
|
+
`,this)}}customElements.define("workspace-view",co);class lo extends Event{constructor(){super("edit-workspace",{bubbles:!0,composed:!0})}}class Xi extends Event{constructor(t){super("create-workspace",{bubbles:!0,composed:!0});h(this,"serverURL");this.serverURL=t}}class ho extends Event{constructor(){super("delete-workspace",{bubbles:!0,composed:!0})}}class uo extends HTMLElement{constructor(){super(...arguments);h(this,"workspaceService",M.resolve("WorkspaceService"));h(this,"serverManager",M.has("ServerManager")?M.resolve("ServerManager"):null);h(this,"subscriptions",new wt)}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 Di&&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 lo))}handleCreateWorkspace(t){this.closeDropdown(),this.dispatchEvent(new Xi(t))}handleDeleteWorkspace(){this.workspaceService.activeWorkspace&&(this.closeDropdown(),this.dispatchEvent(new ho))}render(){var a;const t=((a=this.workspaceService.activeWorkspace)==null?void 0:a.name)??"No workspaces",e=this.serverManager?[...this.serverManager.servers.values()]:[],s=this.serverManager?e.map(c=>({...c,sortedWorkspaces:[...c.workspaces.values()].sort((l,d)=>l.name.localeCompare(d.name,void 0,{sensitivity:"base"}))})):[],n=this.serverManager?[]:[...this.workspaceService.workspaces??[]].sort((c,l)=>c.name.localeCompare(l.name,void 0,{sensitivity:"base"})),o=this.workspaceService.activeWorkspaceServerURL;I(v`
|
|
164
|
+
<dropdown-menu
|
|
165
|
+
title=${t}
|
|
166
|
+
@select=${c=>this.handleSelect(c)}
|
|
167
|
+
>
|
|
168
|
+
<button
|
|
169
|
+
slot="trigger"
|
|
170
|
+
trigger
|
|
171
|
+
type="button"
|
|
172
|
+
aria-label="Choose workspace"
|
|
173
|
+
></button>
|
|
174
|
+
${this.serverManager?s.map(c=>v`
|
|
175
|
+
<dropdown-group>
|
|
176
|
+
<dropdown-label>${c.name}</dropdown-label>
|
|
177
|
+
${c.sortedWorkspaces.map(l=>this.renderWorkspaceItem(l))}
|
|
178
|
+
<dropdown-item action @click=${()=>this.handleCreateWorkspace(c.url)}>
|
|
179
|
+
+ New workspace
|
|
180
|
+
</dropdown-item>
|
|
181
|
+
</dropdown-group>
|
|
182
|
+
`):v`
|
|
183
|
+
<dropdown-group>
|
|
184
|
+
${n.map(c=>this.renderWorkspaceItem(c))}
|
|
185
|
+
${o?v`
|
|
186
|
+
<dropdown-item action @click=${()=>this.handleCreateWorkspace(o)}>
|
|
187
|
+
+ New workspace
|
|
188
|
+
</dropdown-item>
|
|
189
|
+
`:null}
|
|
190
|
+
</dropdown-group>
|
|
191
|
+
`}
|
|
192
|
+
${this.workspaceService.activeWorkspace?v`
|
|
193
|
+
<dropdown-divider></dropdown-divider>
|
|
194
|
+
<dropdown-group>
|
|
195
|
+
<dropdown-item action @click=${()=>this.handleEditWorkspace()}>
|
|
196
|
+
Edit workspace...
|
|
197
|
+
</dropdown-item>
|
|
198
|
+
<dropdown-item action danger @click=${()=>this.handleDeleteWorkspace()}>
|
|
199
|
+
Delete workspace...
|
|
200
|
+
</dropdown-item>
|
|
201
|
+
</dropdown-group>
|
|
202
|
+
`:null}
|
|
203
|
+
</dropdown-menu>
|
|
204
|
+
`,this)}renderWorkspaceItem(t){var s;const e=t.id===this.workspaceService.activeWorkspaceID?((s=this.workspaceService.activeWorkspace)==null?void 0:s.name)??t.name:t.name;return v`
|
|
205
|
+
<dropdown-item
|
|
206
|
+
value=${t.id}
|
|
207
|
+
?selected=${t.id===this.workspaceService.activeWorkspaceID}
|
|
208
|
+
>
|
|
209
|
+
${e}
|
|
210
|
+
</dropdown-item>
|
|
211
|
+
`}}customElements.define("workspace-picker",uo);class Ki extends HTMLElement{constructor(){super(...arguments);h(this,"workspaceService",M.resolve("WorkspaceService"));h(this,"subscriptions",new wt);h(this,"_mode","edit");h(this,"_targetServerURL");h(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,s=new FormData(e),n=String(s.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",s=this._mode==="edit"?((n=this.workspaceService.activeWorkspace)==null?void 0:n.name)??"":"";I(v`
|
|
212
|
+
<modal-overlay ?open=${this.open}>
|
|
213
|
+
<section class="workspace-modal">
|
|
214
|
+
<form class="workspace-form" @submit=${o=>void this.handleSubmit(o)}>
|
|
215
|
+
<h2 class="workspace-modal-title">${t}</h2>
|
|
216
|
+
<label class="settings-field">
|
|
217
|
+
<span>Name</span>
|
|
218
|
+
<input type="text" name="name" .value=${s} required />
|
|
219
|
+
</label>
|
|
220
|
+
<div class="workspace-form-actions">
|
|
221
|
+
<button type="submit" class="settings-submit-button" ?disabled=${this.createPending}>
|
|
222
|
+
${e}
|
|
223
|
+
</button>
|
|
224
|
+
<button type="button" class="settings-cancel-button" @click=${()=>this.emitClose()}>
|
|
225
|
+
Cancel
|
|
226
|
+
</button>
|
|
227
|
+
</div>
|
|
228
|
+
</form>
|
|
229
|
+
</section>
|
|
230
|
+
</modal-overlay>
|
|
231
|
+
`,this)}}h(Ki,"observedAttributes",["open"]);customElements.define("workspace-form-modal",Ki);class qi extends HTMLElement{constructor(){super(...arguments);h(this,"workspaceService",M.resolve("WorkspaceService"));h(this,"serverManager",M.has("ServerManager")?M.resolve("ServerManager"):null);h(this,"subscriptions",new wt);h(this,"deletePending",!1);h(this,"deleteError",null)}get open(){return this.hasAttribute("open")}attributeChangedCallback(t,e,s){t==="open"&&(s!==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;I(v`
|
|
232
|
+
<modal-overlay ?open=${this.open}>
|
|
233
|
+
<section class="workspace-modal workspace-delete-modal">
|
|
234
|
+
<div class="workspace-form">
|
|
235
|
+
<h2 class="workspace-modal-title">Delete workspace</h2>
|
|
236
|
+
<p class="workspace-delete-copy">
|
|
237
|
+
Delete <strong>${((e=this.workspaceService.activeWorkspace)==null?void 0:e.name)??""}</strong>?
|
|
238
|
+
</p>
|
|
239
|
+
${t?v`<p class="workspace-delete-warning">This will delete it for everyone.</p>`:null}
|
|
240
|
+
${this.deleteError?v`<p class="workspace-delete-error">${this.deleteError}</p>`:null}
|
|
241
|
+
<div class="workspace-form-actions">
|
|
242
|
+
<button
|
|
243
|
+
type="button"
|
|
244
|
+
class="settings-server-remove-button"
|
|
245
|
+
?disabled=${this.deletePending}
|
|
246
|
+
@click=${()=>void this.handleDeleteWorkspace()}
|
|
247
|
+
>
|
|
248
|
+
${this.deletePending?"Deleting...":"Delete"}
|
|
249
|
+
</button>
|
|
250
|
+
<button
|
|
251
|
+
type="button"
|
|
252
|
+
class="settings-cancel-button"
|
|
253
|
+
?disabled=${this.deletePending}
|
|
254
|
+
@click=${()=>this.emitClose()}
|
|
255
|
+
>
|
|
256
|
+
Cancel
|
|
257
|
+
</button>
|
|
258
|
+
</div>
|
|
259
|
+
</div>
|
|
260
|
+
</section>
|
|
261
|
+
</modal-overlay>
|
|
262
|
+
`,this)}}h(qi,"observedAttributes",["open"]);customElements.define("workspace-delete-modal",qi);class Bi extends HTMLElement{constructor(){super(...arguments);h(this,"serverManager",M.has("ServerManager")?M.resolve("ServerManager"):null);h(this,"subscriptions",new wt);h(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,s=new FormData(e),n=String(s.get("name")??"").trim(),o=String(s.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;I(v`
|
|
263
|
+
<modal-overlay ?open=${this.open}>
|
|
264
|
+
<section class="settings-panel">
|
|
265
|
+
<panel-view closable @close=${s=>s instanceof Ri&&this.emitClose()}>
|
|
266
|
+
<panel-page id="main" title="Settings">
|
|
267
|
+
<div class="settings-section">
|
|
268
|
+
${e?v`
|
|
269
|
+
<h3 class="settings-section-title">Servers</h3>
|
|
270
|
+
<div class="settings-server-list">
|
|
271
|
+
${t.map(s=>{var n;return v`
|
|
272
|
+
<div class="settings-card settings-server">
|
|
273
|
+
<div class="settings-server-details">
|
|
274
|
+
<div class="settings-server-name">${s.name}</div>
|
|
275
|
+
<div class="settings-server-url">${s.url}</div>
|
|
276
|
+
</div>
|
|
277
|
+
${s.url!==((n=this.serverManager)==null?void 0:n.localServerURL)?v`
|
|
278
|
+
<button
|
|
279
|
+
type="button"
|
|
280
|
+
class="settings-server-remove-button"
|
|
281
|
+
aria-label=${`Remove ${s.name}`}
|
|
282
|
+
@click=${()=>{var o;return(o=this.serverManager)==null?void 0:o.removeServer(s.url)}}
|
|
283
|
+
>
|
|
284
|
+
Remove
|
|
285
|
+
</button>
|
|
286
|
+
`:null}
|
|
287
|
+
</div>
|
|
288
|
+
`})}
|
|
289
|
+
</div>
|
|
290
|
+
${this.addServerFormOpen?v`
|
|
291
|
+
<form class="settings-card settings-add-server-form" @submit=${s=>this.handleAddServer(s)}>
|
|
292
|
+
<label class="settings-field">
|
|
293
|
+
<span>Name</span>
|
|
294
|
+
<input type="text" name="name" required />
|
|
295
|
+
</label>
|
|
296
|
+
<label class="settings-field">
|
|
297
|
+
<span>URL</span>
|
|
298
|
+
<input type="url" name="url" required />
|
|
299
|
+
</label>
|
|
300
|
+
<div class="settings-form-actions">
|
|
301
|
+
<button type="submit" class="settings-submit-button">Connect</button>
|
|
302
|
+
<button
|
|
303
|
+
type="button"
|
|
304
|
+
class="settings-cancel-button"
|
|
305
|
+
data-action="cancel-connect-form"
|
|
306
|
+
@click=${()=>this.closeAddServerForm()}
|
|
307
|
+
>
|
|
308
|
+
Cancel
|
|
309
|
+
</button>
|
|
310
|
+
</div>
|
|
311
|
+
</form>
|
|
312
|
+
`:v`
|
|
313
|
+
<button
|
|
314
|
+
type="button"
|
|
315
|
+
class="settings-submit-button settings-connect-button"
|
|
316
|
+
data-action="show-connect-form"
|
|
317
|
+
@click=${()=>this.openAddServerForm()}
|
|
318
|
+
>
|
|
319
|
+
+ Connect to server
|
|
320
|
+
</button>
|
|
321
|
+
`}
|
|
322
|
+
`:v`<p class="settings-copy">No additional settings yet.</p>`}
|
|
323
|
+
</div>
|
|
324
|
+
</panel-page>
|
|
325
|
+
</panel-view>
|
|
326
|
+
</section>
|
|
327
|
+
</modal-overlay>
|
|
328
|
+
`,this)}}h(Bi,"observedAttributes",["open"]);customElements.define("settings-modal",Bi);class ji extends Event{constructor(t){super("auth-submit",{bubbles:!0,composed:!0});h(this,"token");this.token=t}}class po extends HTMLElement{constructor(){super(...arguments);h(this,"_invalid",!1);h(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 ji(e))}render(){I(v`
|
|
329
|
+
<modal-overlay open>
|
|
330
|
+
<section class="auth-modal">
|
|
331
|
+
<form class="auth-form" @submit=${t=>this.handleSubmit(t)}>
|
|
332
|
+
<h2 class="auth-modal-title">Enter access token</h2>
|
|
333
|
+
<p class="auth-modal-copy">This Television server requires a token.</p>
|
|
334
|
+
<label class="settings-field">
|
|
335
|
+
<span>Token</span>
|
|
336
|
+
<input
|
|
337
|
+
class=${this.invalid?"auth-token-input-invalid":""}
|
|
338
|
+
type="password"
|
|
339
|
+
name="token"
|
|
340
|
+
.value=${this.tokenValue}
|
|
341
|
+
@input=${t=>this.handleInput(t)}
|
|
342
|
+
required
|
|
343
|
+
/>
|
|
344
|
+
</label>
|
|
345
|
+
<button type="submit" class="settings-submit-button">Connect</button>
|
|
346
|
+
</form>
|
|
347
|
+
</section>
|
|
348
|
+
</modal-overlay>
|
|
349
|
+
`,this)}}customElements.get("auth-modal")||customElements.define("auth-modal",po);class fo extends HTMLElement{constructor(){super(...arguments);h(this,"runtimeServerURL",bi());h(this,"electronMode",Si());h(this,"serverManager",M.resolve("ServerManager"));h(this,"subscriptions",new wt);h(this,"modals",{workspaceForm:{open:!1,mode:"edit"},deleteWorkspace:{open:!1},settings:{open:!1}});h(this,"connectError",null)}connectedCallback(){this.subscriptions.add(this.serverManager.on("servers-changed",()=>this.render())),this.addEventListener("auth-submit",t=>{var s;const e=t instanceof ji?t.token:t instanceof CustomEvent&&typeof((s=t.detail)==null?void 0:s.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 Ve({url:this.runtimeServerURL,name:"Server",token:an()});this.serverManager.add(t),this.serverManager.setActive(t);try{await t.connect(),this.connectError=null}catch(e){this.connectError=e instanceof Error&&!(e instanceof He)?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(s){s instanceof He||(this.connectError=s instanceof Error?s.message:String(s))}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"){I(v`
|
|
350
|
+
<main class="auth-gate"><p>Connecting...</p></main>
|
|
351
|
+
`,this);return}if(e==="disconnected"){const n=t;if(!n)return;I(v`
|
|
352
|
+
<main class="auth-gate">
|
|
353
|
+
<auth-modal
|
|
354
|
+
.invalid=${!!n.token}
|
|
355
|
+
.tokenValue=${n.token??""}
|
|
356
|
+
></auth-modal>
|
|
357
|
+
</main>
|
|
358
|
+
`,this);return}const s=v`
|
|
359
|
+
<header>
|
|
360
|
+
<nav>
|
|
361
|
+
<workspace-picker
|
|
362
|
+
@edit-workspace=${()=>{this.modals.workspaceForm={open:!0,mode:"edit"},this.render()}}
|
|
363
|
+
@create-workspace=${n=>{n instanceof Xi&&(this.modals.workspaceForm={open:!0,mode:"create",targetServerURL:n.serverURL},this.render())}}
|
|
364
|
+
@delete-workspace=${()=>{this.modals.deleteWorkspace={open:!0},this.render()}}
|
|
365
|
+
></workspace-picker>
|
|
366
|
+
</nav>
|
|
367
|
+
<button
|
|
368
|
+
type="button"
|
|
369
|
+
variant="toolbar"
|
|
370
|
+
size="sm"
|
|
371
|
+
aria-label="Settings"
|
|
372
|
+
@click=${()=>{this.modals.settings={open:!this.modals.settings.open},this.render()}}
|
|
373
|
+
>
|
|
374
|
+
${xn({size:16,weight:"bold"})}
|
|
375
|
+
</button>
|
|
376
|
+
</header>
|
|
377
|
+
<main>
|
|
378
|
+
${this.connectError?v`<p data-testid="auth-error">${this.connectError}</p>`:v`<workspace-view></workspace-view>`}
|
|
379
|
+
</main>
|
|
380
|
+
<workspace-form-modal
|
|
381
|
+
?open=${this.modals.workspaceForm.open}
|
|
382
|
+
.mode=${this.modals.workspaceForm.mode}
|
|
383
|
+
.targetServerURL=${this.modals.workspaceForm.targetServerURL}
|
|
384
|
+
@close=${()=>{this.modals.workspaceForm={open:!1,mode:"edit"},this.render()}}
|
|
385
|
+
></workspace-form-modal>
|
|
386
|
+
<workspace-delete-modal
|
|
387
|
+
?open=${this.modals.deleteWorkspace.open}
|
|
388
|
+
@close=${()=>{this.modals.deleteWorkspace={open:!1},this.render()}}
|
|
389
|
+
></workspace-delete-modal>
|
|
390
|
+
<settings-modal
|
|
391
|
+
?open=${this.modals.settings.open}
|
|
392
|
+
@close=${()=>{this.modals.settings={open:!1},this.render()}}
|
|
393
|
+
></settings-modal>
|
|
394
|
+
`;I(s,this)}}customElements.get("television-app")||customElements.define("television-app",fo);const pr=Si(),fr=bi(),Zi=js(pr?"television-electron":"television-browser",fr),gr=new en({clientStore:Zi,localServerURL:fr}),Ji=new Is({clientStore:Zi,serverManager:gr});M.register("ServerManager",()=>gr);M.register("WorkspaceService",()=>Ji);gr.on("server-event",({serverURL:r,event:i})=>{Ji.handleServerEvent(r,i)});const mr=document.createElement("television-app");mr.runtimeServerURL=fr;mr.electronMode=pr;pr&&document.body.classList.add("electron");document.body.appendChild(mr);
|