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