import { FolkShape } from "./folk-shape"; import { css, html } from "./tags"; const styles = css` :host { background: #0f172a; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3); min-width: 360px; min-height: 400px; } .header { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: linear-gradient(135deg, #7c3aed, #2563eb); color: white; border-radius: 8px 8px 0 0; font-size: 12px; font-weight: 600; cursor: move; } .header-title { display: flex; align-items: center; gap: 6px; } .header-actions { display: flex; gap: 4px; } .header-actions button { background: transparent; border: none; color: white; cursor: pointer; padding: 2px 6px; border-radius: 4px; font-size: 14px; } .header-actions button:hover { background: rgba(255, 255, 255, 0.2); } .content { display: flex; flex-direction: column; height: calc(100% - 36px); overflow: hidden; } .controls { padding: 10px 12px; border-bottom: 1px solid #1e293b; display: flex; gap: 8px; align-items: center; } .splat-url-input { flex: 1; padding: 8px 10px; border: 2px solid #334155; border-radius: 6px; background: #1e293b; color: #e2e8f0; font-size: 12px; outline: none; } .splat-url-input:focus { border-color: #7c3aed; } .load-btn { padding: 8px 14px; background: linear-gradient(135deg, #7c3aed, #2563eb); color: white; border: none; border-radius: 6px; font-size: 12px; font-weight: 600; cursor: pointer; } .load-btn:hover { opacity: 0.9; } .viewer-area { flex: 1; position: relative; background: #0a0a0a; overflow: hidden; } .viewer-area canvas { width: 100%; height: 100%; display: block; } .placeholder { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #64748b; text-align: center; gap: 8px; } .placeholder-icon { font-size: 48px; opacity: 0.5; } .gallery-list { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; padding: 10px; overflow-y: auto; max-height: 200px; } .gallery-item { padding: 8px; background: #1e293b; border-radius: 6px; cursor: pointer; color: #cbd5e1; font-size: 11px; text-align: center; border: 2px solid transparent; transition: border-color 0.2s; } .gallery-item:hover { border-color: #7c3aed; } .gallery-item .title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; } .gallery-item .meta { font-size: 10px; color: #64748b; margin-top: 2px; } .loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; gap: 12px; color: #94a3b8; } .spinner { width: 32px; height: 32px; border: 3px solid #334155; border-top-color: #7c3aed; border-radius: 50%; animation: spin 1s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } } .error { color: #ef4444; padding: 12px; background: #1c1017; border-radius: 6px; font-size: 13px; margin: 10px; } .upload-btn { padding: 8px 14px; background: #334155; color: #e2e8f0; border: none; border-radius: 6px; font-size: 12px; cursor: pointer; } .upload-btn:hover { background: #475569; } `; declare global { interface HTMLElementTagNameMap { "folk-splat": FolkSplat; } } export class FolkSplat extends FolkShape { static override tagName = "folk-splat"; static { const sheet = new CSSStyleSheet(); const parentRules = Array.from(FolkShape.styles.cssRules) .map((r) => r.cssText) .join("\n"); const childRules = Array.from(styles.cssRules) .map((r) => r.cssText) .join("\n"); sheet.replaceSync(`${parentRules}\n${childRules}`); this.styles = sheet; } #splatUrl = ""; #isLoading = false; #error: string | null = null; #viewer: any = null; #viewerCanvas: HTMLCanvasElement | null = null; #gallerySplats: any[] = []; #urlInput: HTMLInputElement | null = null; get splatUrl() { return this.#splatUrl; } set splatUrl(v: string) { this.#splatUrl = v; } override createRenderRoot() { const root = super.createRenderRoot(); const wrapper = document.createElement("div"); wrapper.innerHTML = html`