import { FolkShape } from "./folk-shape"; import { css, html } from "./tags"; const styles = css` :host { background: white; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); min-width: 400px; min-height: 500px; } .header { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: linear-gradient(135deg, #f97316, #dc2626); 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; } .mode-tabs { display: flex; border-bottom: 1px solid #e2e8f0; } .mode-tab { flex: 1; padding: 10px; border: none; background: none; cursor: pointer; font-size: 13px; font-weight: 500; color: #64748b; border-bottom: 2px solid transparent; transition: all 0.2s; } .mode-tab:hover { color: #1e293b; } .mode-tab.active { color: #f97316; border-bottom-color: #f97316; } .input-area { padding: 12px; border-bottom: 1px solid #e2e8f0; } .image-upload { border: 2px dashed #e2e8f0; border-radius: 8px; padding: 24px; text-align: center; cursor: pointer; transition: all 0.2s; } .image-upload:hover { border-color: #f97316; background: #fff7ed; } .image-upload.has-image { padding: 8px; } .upload-icon { font-size: 32px; margin-bottom: 8px; } .upload-text { color: #64748b; font-size: 13px; } .uploaded-image { max-width: 100%; max-height: 150px; border-radius: 6px; } .prompt-input { width: 100%; padding: 10px 12px; border: 2px solid #e2e8f0; border-radius: 8px; font-size: 13px; resize: none; outline: none; font-family: inherit; margin-top: 8px; } .prompt-input:focus { border-color: #f97316; } .controls { display: flex; gap: 8px; margin-top: 8px; align-items: center; } .duration-select { padding: 6px 10px; border: 2px solid #e2e8f0; border-radius: 6px; font-size: 12px; background: white; cursor: pointer; } .generate-btn { flex: 1; padding: 8px 16px; background: linear-gradient(135deg, #f97316, #dc2626); color: white; border: none; border-radius: 6px; font-size: 13px; font-weight: 600; cursor: pointer; transition: opacity 0.2s; } .generate-btn:hover { opacity: 0.9; } .generate-btn:disabled { opacity: 0.5; cursor: not-allowed; } .video-area { flex: 1; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; } .placeholder { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; color: #94a3b8; text-align: center; gap: 8px; } .placeholder-icon { font-size: 48px; opacity: 0.5; } .generated-video { width: 100%; border-radius: 8px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1); } .video-item { position: relative; } .video-prompt { font-size: 11px; color: #64748b; margin-top: 4px; padding: 4px 8px; background: #f1f5f9; border-radius: 4px; } .loading { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; gap: 12px; } .spinner { width: 32px; height: 32px; border: 3px solid #e2e8f0; border-top-color: #f97316; border-radius: 50%; animation: spin 1s linear infinite; } @keyframes spin { to { transform: rotate(360deg); } } .progress-bar { width: 200px; height: 4px; background: #e2e8f0; border-radius: 2px; overflow: hidden; } .progress-fill { height: 100%; background: linear-gradient(135deg, #f97316, #dc2626); transition: width 0.3s; } .error { color: #ef4444; padding: 12px; background: #fef2f2; border-radius: 6px; font-size: 13px; } .hidden-input { display: none; } `; export interface GeneratedVideo { id: string; prompt: string; url: string; sourceImage?: string; duration: number; timestamp: Date; } declare global { interface HTMLElementTagNameMap { "folk-video-gen": FolkVideoGen; } } export class FolkVideoGen extends FolkShape { static override tagName = "folk-video-gen"; 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; } #videos: GeneratedVideo[] = []; #mode: "i2v" | "t2v" = "i2v"; #sourceImage: string | null = null; #isLoading = false; #progress = 0; #error: string | null = null; #promptInput: HTMLTextAreaElement | null = null; #durationSelect: HTMLSelectElement | null = null; #videoArea: HTMLElement | null = null; #generateBtn: HTMLButtonElement | null = null; #imageUpload: HTMLElement | null = null; #fileInput: HTMLInputElement | null = null; get videos() { return this.#videos; } override createRenderRoot() { const root = super.createRenderRoot(); const wrapper = document.createElement("div"); wrapper.innerHTML = html`