{"repo_name": "glass", "file_name": "/glass/src/ui/listen/ListenView.js", "inference_info": {"prefix_code": "import { html, css, LitElement } from '../assets/lit-core-2.7.4.min.js';\nimport './stt/SttView.js';\nimport './summary/SummaryView.js';\n\nexport class ListenView extends LitElement {\n static styles = css`\n :host {\n display: block;\n width: 400px;\n transform: translate3d(0, 0, 0);\n backface-visibility: hidden;\n transition: transform 0.2s cubic-bezier(0.23, 1, 0.32, 1), opacity 0.2s ease-out;\n will-change: transform, opacity;\n }\n\n :host(.hiding) {\n animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.6, 1) forwards;\n }\n\n :host(.showing) {\n animation: slideDown 0.35s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;\n }\n\n :host(.hidden) {\n opacity: 0;\n transform: translateY(-150%) scale(0.85);\n pointer-events: none;\n }\n\n\n * {\n font-family: 'Helvetica Neue', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;\n cursor: default;\n user-select: none;\n }\n\n/* Allow text selection in insights responses */\n.insights-container, .insights-container *, .markdown-content {\n user-select: text !important;\n cursor: text !important;\n}\n\n/* highlight.js 스타일 추가 */\n.insights-container pre {\n background: rgba(0, 0, 0, 0.4) !important;\n border-radius: 8px !important;\n padding: 12px !important;\n margin: 8px 0 !important;\n overflow-x: auto !important;\n border: 1px solid rgba(255, 255, 255, 0.1) !important;\n white-space: pre !important;\n word-wrap: normal !important;\n word-break: normal !important;\n}\n\n.insights-container code {\n font-family: 'Monaco', 'Menlo', 'Consolas', monospace !important;\n font-size: 11px !important;\n background: transparent !important;\n white-space: pre !important;\n word-wrap: normal !important;\n word-break: normal !important;\n}\n\n.insights-container pre code {\n white-space: pre !important;\n word-wrap: normal !important;\n word-break: normal !important;\n display: block !important;\n}\n\n.insights-container p code {\n background: rgba(255, 255, 255, 0.1) !important;\n padding: 2px 4px !important;\n border-radius: 3px !important;\n color: #ffd700 !important;\n}\n\n.hljs-keyword {\n color: #ff79c6 !important;\n}\n\n.hljs-string {\n color: #f1fa8c !important;\n}\n\n.hljs-comment {\n color: #6272a4 !important;\n}\n\n.hljs-number {\n color: #bd93f9 !important;\n}\n\n.hljs-function {\n color: #50fa7b !important;\n}\n\n.hljs-title {\n color: #50fa7b !important;\n}\n\n.hljs-variable {\n color: #8be9fd !important;\n}\n\n.hljs-built_in {\n color: #ffb86c !important;\n}\n\n.hljs-attr {\n color: #50fa7b !important;\n}\n\n.hljs-tag {\n color: #ff79c6 !important;\n}\n .assistant-container {\n display: flex;\n flex-direction: column;\n color: #ffffff;\n box-sizing: border-box;\n position: relative;\n background: rgba(0, 0, 0, 0.6);\n overflow: hidden;\n border-radius: 12px;\n width: 100%;\n height: 100%;\n }\n\n .assistant-container::after {\n content: '';\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n border-radius: 12px;\n padding: 1px;\n background: linear-gradient(169deg, rgba(255, 255, 255, 0.17) 0%, rgba(255, 255, 255, 0.08) 50%, rgba(255, 255, 255, 0.17) 100%);\n -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);\n -webkit-mask-composite: destination-out;\n mask-composite: exclude;\n pointer-events: none;\n }\n\n .assistant-container::before {\n content: '';\n position: absolute;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n width: 100%;\n height: 100%;\n background: rgba(0, 0, 0, 0.15);\n box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);\n border-radius: 12px;\n z-index: -1;\n }\n\n .top-bar {\n display: flex;\n justify-content: space-between;\n align-items: center;\n padding: 6px 16px;\n min-height: 32px;\n position: relative;\n z-index: 1;\n width: 100%;\n box-sizing: border-box;\n flex-shrink: 0;\n border-bottom: 1px solid rgba(255, 255, 255, 0.1);\n }\n\n .bar-left-text {\n color: white;\n font-size: 13px;\n font-family: 'Helvetica Neue', sans-serif;\n font-weight: 500;\n position: relative;\n overflow: hidden;\n white-space: nowrap;\n flex: 1;\n min-width: 0;\n max-width: 200px;\n }\n\n .bar-left-text-content {\n display: inline-block;\n transition: transform 0.3s ease;\n }\n\n .bar-left-text-content.slide-in {\n animation: slideIn 0.3s ease forwards;\n }\n\n .bar-controls {\n display: flex;\n gap: 4px;\n align-items: center;\n flex-shrink: 0;\n width: 120px;\n justify-content: flex-end;\n box-sizing: border-box;\n padding: 4px;\n }\n\n .toggle-button {\n display: flex;\n align-items: center;\n gap: 5px;\n background: transparent;\n color: rgba(255, 255, 255, 0.9);\n border: none;\n outline: none;\n box-shadow: none;\n padding: 4px 8px;\n border-radius: 5px;\n font-size: 11px;\n font-weight: 500;\n cursor: pointer;\n height: 24px;\n white-space: nowrap;\n transition: background-color 0.15s ease;\n justify-content: center;\n }\n\n .toggle-button:hover {\n background: rgba(255, 255, 255, 0.1);\n }\n\n .toggle-button svg {\n flex-shrink: 0;\n width: 12px;\n height: 12px;\n }\n\n .copy-button {\n background: transparent;\n color: rgba(255, 255, 255, 0.9);\n border: none;\n outline: none;\n box-shadow: none;\n padding: 4px;\n border-radius: 3px;\n cursor: pointer;\n display: flex;\n align-items: center;\n justify-content: center;\n min-width: 24px;\n height: 24px;\n flex-shrink: 0;\n transition: background-color 0.15s ease;\n position: relative;\n overflow: hidden;\n }\n\n .copy-button:hover {\n background: rgba(255, 255, 255, 0.15);\n }\n\n .copy-button svg {\n position: absolute;\n top: 50%;\n left: 50%;\n transform: translate(-50%, -50%);\n transition: opacity 0.2s ease-in-out, transform 0.2s ease-in-out;\n }\n\n .copy-button .check-icon {\n opacity: 0;\n transform: translate(-50%, -50%) scale(0.5);\n }\n\n .copy-button.copied .copy-icon {\n opacity: 0;\n transform: translate(-50%, -50%) scale(0.5);\n }\n\n .copy-button.copied .check-icon {\n opacity: 1;\n transform: translate(-50%, -50%) scale(1);\n }\n\n .timer {\n font-family: 'Monaco', 'Menlo', monospace;\n font-size: 10px;\n color: rgba(255, 255, 255, 0.7);\n }\n \n /* ────────────────[ GLASS BYPASS ]─────────────── */\n :host-context(body.has-glass) .assistant-container,\n :host-context(body.has-glass) .top-bar,\n :host-context(body.has-glass) .toggle-button,\n :host-context(body.has-glass) .copy-button,\n :host-context(body.has-glass) .transcription-container,\n :host-context(body.has-glass) .insights-container,\n :host-context(body.has-glass) .stt-message,\n :host-context(body.has-glass) .outline-item,\n :host-context(body.has-glass) .request-item,\n :host-context(body.has-glass) .markdown-content,\n :host-context(body.has-glass) .insights-container pre,\n :host-context(body.has-glass) .insights-container p code,\n :host-context(body.has-glass) .insights-container pre code {\n background: transparent !important;\n border: none !important;\n outline: none !important;\n box-shadow: none !important;\n filter: none !important;\n backdrop-filter: none !important;\n }\n\n :host-context(body.has-glass) .assistant-container::before,\n :host-context(body.has-glass) .assistant-container::after {\n display: none !important;\n }\n\n :host-context(body.has-glass) .toggle-button:hover,\n :host-context(body.has-glass) .copy-button:hover,\n :host-context(body.has-glass) .outline-item:hover,\n :host-context(body.has-glass) .request-item.clickable:hover,\n :host-context(body.has-glass) .markdown-content:hover {\n background: transparent !important;\n transform: none !important;\n }\n\n :host-context(body.has-glass) .transcription-container::-webkit-scrollbar-track,\n :host-context(body.has-glass) .transcription-container::-webkit-scrollbar-thumb,\n :host-context(body.has-glass) .insights-container::-webkit-scrollbar-track,\n :host-context(body.has-glass) .insights-container::-webkit-scrollbar-thumb {\n background: transparent !important;\n }\n :host-context(body.has-glass) * {\n animation: none !important;\n transition: none !important;\n transform: none !important;\n filter: none !important;\n backdrop-filter: none !important;\n box-shadow: none !important;\n }\n\n :host-context(body.has-glass) .assistant-container,\n :host-context(body.has-glass) .stt-message,\n :host-context(body.has-glass) .toggle-button,\n :host-context(body.has-glass) .copy-button {\n border-radius: 0 !important;\n }\n\n :host-context(body.has-glass) ::-webkit-scrollbar,\n :host-context(body.has-glass) ::-webkit-scrollbar-track,\n :host-context(body.has-glass) ::-webkit-scrollbar-thumb {\n background: transparent !important;\n width: 0 !important; /* 스크롤바 자체 숨기기 */\n }\n :host-context(body.has-glass) .assistant-container,\n :host-context(body.has-glass) .top-bar,\n :host-context(body.has-glass) .toggle-button,\n :host-context(body.has-glass) .copy-button,\n :host-context(body.has-glass) .transcription-container,\n :host-context(body.has-glass) .insights-container,\n :host-context(body.has-glass) .stt-message,\n :host-context(body.has-glass) .outline-item,\n :host-context(body.has-glass) .request-item,\n :host-context(body.has-glass) .markdown-content,\n :host-context(body.has-glass) .insights-container pre,\n :host-context(body.has-glass) .insights-container p code,\n :host-context(body.has-glass) .insights-container pre code {\n background: transparent !important;\n border: none !important;\n outline: none !important;\n box-shadow: none !important;\n filter: none !important;\n backdrop-filter: none !important;\n }\n\n :host-context(body.has-glass) .assistant-container::before,\n :host-context(body.has-glass) .assistant-container::after {\n display: none !important;\n }\n\n :host-context(body.has-glass) .toggle-button:hover,\n :host-context(body.has-glass) .copy-button:hover,\n :host-context(body.has-glass) .outline-item:hover,\n :host-context(body.has-glass) .request-item.clickable:hover,\n :host-context(body.has-glass) .markdown-content:hover {\n background: transparent !important;\n transform: none !important;\n }\n\n :host-context(body.has-glass) .transcription-container::-webkit-scrollbar-track,\n :host-context(body.has-glass) .transcription-container::-webkit-scrollbar-thumb,\n :host-context(body.has-glass) .insights-container::-webkit-scrollbar-track,\n :host-context(body.has-glass) .insights-container::-webkit-scrollbar-thumb {\n background: transparent !important;\n }\n :host-context(body.has-glass) * {\n animation: none !important;\n transition: none !important;\n transform: none !important;\n filter: none !important;\n backdrop-filter: none !important;\n box-shadow: none !important;\n }\n\n :host-context(body.has-glass) .assistant-container,\n :host-context(body.has-glass) .stt-message,\n :host-context(body.has-glass) .toggle-button,\n :host-context(body.has-glass) .copy-button {\n border-radius: 0 !important;\n }\n\n :host-context(body.has-glass) ::-webkit-scrollbar,\n :host-context(body.has-glass) ::-webkit-scrollbar-track,\n :host-context(body.has-glass) ::-webkit-scrollbar-thumb {\n background: transparent !important;\n width: 0 !important;\n }\n `;\n\n static properties = {\n viewMode: { type: String },\n isHovering: { type: Boolean },\n isAnimating: { type: Boolean },\n copyState: { type: String },\n elapsedTime: { type: String },\n captureStartTime: { type: Number },\n isSessionActive: { type: Boolean },\n hasCompletedRecording: { type: Boolean },\n };\n\n constructor() {\n super();\n this.isSessionActive = false;\n this.hasCompletedRecording = false;\n this.viewMode = 'insights';\n this.isHovering = false;\n this.isAnimating = false;\n this.elapsedTime = '00:00';\n this.captureStartTime = null;\n this.timerInterval = null;\n this.adjustHeightThrottle = null;\n this.isThrottled = false;\n this.copyState = 'idle';\n this.copyTimeout = null;\n\n this.adjustWindowHeight = this.adjustWindowHeight.bind(this);\n }\n\n connectedCallback() {\n super.connectedCallback();\n // Only start timer if session is active\n if (this.isSessionActive) {\n this.startTimer();\n }\n if (window.api) {\n window.api.listenView.onSessionStateChanged(", "suffix_code": ");\n }\n }\n\n disconnectedCallback() {\n super.disconnectedCallback();\n this.stopTimer();\n\n if (this.adjustHeightThrottle) {\n clearTimeout(this.adjustHeightThrottle);\n this.adjustHeightThrottle = null;\n }\n if (this.copyTimeout) {\n clearTimeout(this.copyTimeout);\n }\n }\n\n startTimer() {\n this.captureStartTime = Date.now();\n this.timerInterval = setInterval(() => {\n const elapsed = Math.floor((Date.now() - this.captureStartTime) / 1000);\n const minutes = Math.floor(elapsed / 60)\n .toString()\n .padStart(2, '0');\n const seconds = (elapsed % 60).toString().padStart(2, '0');\n this.elapsedTime = `${minutes}:${seconds}`;\n this.requestUpdate();\n }, 1000);\n }\n\n stopTimer() {\n if (this.timerInterval) {\n clearInterval(this.timerInterval);\n this.timerInterval = null;\n }\n }\n\n adjustWindowHeight() {\n if (!window.api) return;\n\n this.updateComplete\n .then(() => {\n const topBar = this.shadowRoot.querySelector('.top-bar');\n const activeContent = this.viewMode === 'transcript'\n ? this.shadowRoot.querySelector('stt-view')\n : this.shadowRoot.querySelector('summary-view');\n\n if (!topBar || !activeContent) return;\n\n const topBarHeight = topBar.offsetHeight;\n\n const contentHeight = activeContent.scrollHeight;\n\n const idealHeight = topBarHeight + contentHeight;\n\n const targetHeight = Math.min(700, idealHeight);\n\n console.log(\n `[Height Adjusted] Mode: ${this.viewMode}, TopBar: ${topBarHeight}px, Content: ${contentHeight}px, Ideal: ${idealHeight}px, Target: ${targetHeight}px`\n );\n\n window.api.listenView.adjustWindowHeight('listen', targetHeight);\n })\n .catch(error => {\n console.error('Error in adjustWindowHeight:', error);\n });\n }\n\n toggleViewMode() {\n this.viewMode = this.viewMode === 'insights' ? 'transcript' : 'insights';\n this.requestUpdate();\n }\n\n handleCopyHover(isHovering) {\n this.isHovering = isHovering;\n if (isHovering) {\n this.isAnimating = true;\n } else {\n this.isAnimating = false;\n }\n this.requestUpdate();\n }\n\n async handleCopy() {\n if (this.copyState === 'copied') return;\n\n let textToCopy = '';\n\n if (this.viewMode === 'transcript') {\n const sttView = this.shadowRoot.querySelector('stt-view');\n textToCopy = sttView ? sttView.getTranscriptText() : '';\n } else {\n const summaryView = this.shadowRoot.querySelector('summary-view');\n textToCopy = summaryView ? summaryView.getSummaryText() : '';\n }\n\n try {\n await navigator.clipboard.writeText(textToCopy);\n console.log('Content copied to clipboard');\n\n this.copyState = 'copied';\n this.requestUpdate();\n\n if (this.copyTimeout) {\n clearTimeout(this.copyTimeout);\n }\n\n this.copyTimeout = setTimeout(() => {\n this.copyState = 'idle';\n this.requestUpdate();\n }, 1500);\n } catch (err) {\n console.error('Failed to copy:', err);\n }\n }\n\n adjustWindowHeightThrottled() {\n if (this.isThrottled) {\n return;\n }\n\n this.adjustWindowHeight();\n\n this.isThrottled = true;\n\n this.adjustHeightThrottle = setTimeout(() => {\n this.isThrottled = false;\n }, 16);\n }\n\n updated(changedProperties) {\n super.updated(changedProperties);\n\n if (changedProperties.has('viewMode')) {\n this.adjustWindowHeight();\n }\n }\n\n handleSttMessagesUpdated(event) {\n // Handle messages update from SttView if needed\n this.adjustWindowHeightThrottled();\n }\n\n firstUpdated() {\n super.firstUpdated();\n setTimeout(() => this.adjustWindowHeight(), 200);\n }\n\n render() {\n const displayText = this.isHovering\n ? this.viewMode === 'transcript'\n ? 'Copy Transcript'\n : 'Copy Glass Analysis'\n : this.viewMode === 'insights'\n ? `Live insights`\n : `Glass is Listening ${this.elapsedTime}`;\n\n return html`\n
')\n .replace(/\\n/g, '
')\n .replace(/\\*\\*(.*?)\\*\\*/g, '$1')\n .replace(/\\*(.*?)\\*/g, '$1')\n .replace(/`([^`]+)`/g, '$1');\n\n responseContainer.innerHTML = `
${basicHtml}
`;\n }\n }\n\n\n requestWindowResize(targetHeight) {\n if (window.api) {\n window.api.askView.adjustWindowHeight(targetHeight);\n }\n }\n\n animateHeaderText(text) {\n this.headerAnimating = true;\n this.requestUpdate();\n\n setTimeout(() => {\n this.headerText = text;\n this.headerAnimating = false;\n this.requestUpdate();\n }, 150);\n }\n\n startHeaderAnimation() {\n this.animateHeaderText('analyzing screen...');\n\n if (this.headerAnimationTimeout) {\n clearTimeout(this.headerAnimationTimeout);\n }\n\n this.headerAnimationTimeout = setTimeout(() => {\n this.animateHeaderText('thinking...');\n }, 1500);\n }\n\n renderMarkdown(content) {\n if (!content) return '';\n\n if (this.isLibrariesLoaded && this.marked) {\n return this.parseMarkdown(content);\n }\n\n return content\n .replace(/\\*\\*(.*?)\\*\\*/g, '$1')\n .replace(/\\*(.*?)\\*/g, '$1')\n .replace(/`(.*?)`/g, '$1');\n }\n\n fixIncompleteMarkdown(text) {\n if (!text) return text;\n\n // 불완전한 볼드체 처리\n const boldCount = (text.match(/\\*\\*/g) || []).length;\n if (boldCount % 2 === 1) {\n text += '**';\n }\n\n // 불완전한 이탤릭체 처리\n const italicCount = (text.match(/(? closeBrackets) {\n text += ']';\n }\n\n const openParens = (text.match(/\\]\\(/g) || []).length;\n const closeParens = (text.match(/\\)\\s*$/g) || []).length;\n if (openParens > closeParens && text.endsWith('(')) {\n text += ')';\n }\n\n return text;\n }\n\n\n async handleCopy() {\n if (this.copyState === 'copied') return;\n\n let responseToCopy = this.currentResponse;\n\n if (this.isDOMPurifyLoaded && this.DOMPurify) {\n const testHtml = this.renderMarkdown(responseToCopy);\n const sanitized = this.DOMPurify.sanitize(testHtml);\n\n if (this.DOMPurify.removed && this.DOMPurify.removed.length > 0) {\n console.warn('Unsafe content detected, copy blocked');\n return;\n }\n }\n\n const textToCopy = `Question: ${this.currentQuestion}\\n\\nAnswer: ${responseToCopy}`;\n\n try {\n await navigator.clipboard.writeText(textToCopy);\n console.log('Content copied to clipboard');\n\n this.copyState = 'copied';\n this.requestUpdate();\n\n if (this.copyTimeout) {\n clearTimeout(this.copyTimeout);\n }\n\n this.copyTimeout = setTimeout(() => {\n this.copyState = 'idle';\n this.requestUpdate();\n }, 1500);\n } catch (err) {\n console.error('Failed to copy:', err);\n }\n }\n\n async handleLineCopy(lineIndex) {\n const originalLines = this.currentResponse.split('\\n');\n const lineToCopy = originalLines[lineIndex];\n\n if (!lineToCopy) return;\n\n try {\n await navigator.clipboard.writeText(lineToCopy);\n console.log('Line copied to clipboard');\n\n // '복사됨' 상태로 UI 즉시 업데이트\n this.lineCopyState = { ...this.lineCopyState, [lineIndex]: true };\n this.requestUpdate(); // LitElement에 UI 업데이트 요청\n\n // 기존 타임아웃이 있다면 초기화\n if (this.lineCopyTimeouts && this.lineCopyTimeouts[lineIndex]) {\n clearTimeout(this.lineCopyTimeouts[lineIndex]);\n }\n\n // ✨ 수정된 타임아웃: 1.5초 후 '복사됨' 상태 해제\n this.lineCopyTimeouts[lineIndex] = setTimeout(() => {\n const updatedState = { ...this.lineCopyState };\n delete updatedState[lineIndex];\n this.lineCopyState = updatedState;\n this.requestUpdate(); // UI 업데이트 요청\n }, 1500);\n } catch (err) {\n console.error('Failed to copy line:', err);\n }\n }\n\n async handleSendText(e, overridingText = '') {\n const textInput = this.shadowRoot?.getElementById('textInput');\n const text = (overridingText || textInput?.value || '').trim();\n // if (!text) return;\n\n textInput.value = '';\n\n if (window.api) {\n window.api.askView.sendMessage(text).catch(error => {\n console.error('Error sending text:', error);\n });\n }\n }\n\n handleTextKeydown(e) {\n // Fix for IME composition issue: Ignore Enter key presses while composing.\n if (e.isComposing) {\n return;\n }\n\n const isPlainEnter = e.key === 'Enter' && !e.shiftKey && !e.metaKey && !e.ctrlKey;\n const isModifierEnter = e.key === 'Enter' && (e.metaKey || e.ctrlKey);\n\n if (isPlainEnter || isModifierEnter) {\n e.preventDefault();\n this.handleSendText();\n }\n }\n\n updated(changedProperties) {\n super.updated(changedProperties);\n \n // ✨ isLoading 또는 currentResponse가 변경될 때마다 뷰를 다시 그립니다.\n if (changedProperties.has('isLoading') || changedProperties.has('currentResponse')) {\n this.renderContent();\n }\n \n if (changedProperties.has('showTextInput') || changedProperties.has('isLoading') || changedProperties.has('currentResponse')) {\n this.adjustWindowHeightThrottled();\n }\n \n if (changedProperties.has('showTextInput') && this.showTextInput) {\n this.focusTextInput();\n }\n }\n\n firstUpdated() {\n setTimeout(() => this.adjustWindowHeight(), 200);\n }\n\n\n getTruncatedQuestion(question, maxLength = 30) {\n if (!question) return '';\n if (question.length <= maxLength) return question;\n return question.substring(0, maxLength) + '...';\n }\n\n\n\n render() {\n const hasResponse = this.isLoading || this.currentResponse || this.isStreaming;\n const headerText = this.isLoading ? 'Thinking...' : 'AI Response';\n\n return html`\n