InfoPanel builds the payload, applies the Inspector's edit guards and refreshes the viewer on a 250 ms tick while connected, also when the glass is off. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1549 lines
54 KiB
HTML
1549 lines
54 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>🔍 MagnifyGlass Viewer</title>
|
|
<style>
|
|
:root {
|
|
--bg-primary: #0f0f14;
|
|
--bg-secondary: #16161d;
|
|
--bg-tertiary: #1e1e28;
|
|
--bg-elevated: #252532;
|
|
--border-subtle: rgba(255, 255, 255, 0.06);
|
|
--border-default: rgba(255, 255, 255, 0.1);
|
|
--border-accent: rgba(99, 102, 241, 0.4);
|
|
--text-primary: #f0f0f5;
|
|
--text-secondary: #9ca3af;
|
|
--text-tertiary: #6b7280;
|
|
--accent-blue: #6366f1;
|
|
--accent-cyan: #22d3ee;
|
|
--accent-green: #22c55e;
|
|
--accent-amber: #f59e0b;
|
|
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
|
|
--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
|
|
--shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
|
|
--radius-sm: 6px;
|
|
--radius-md: 10px;
|
|
--radius-lg: 14px;
|
|
--radius-lg: 14px;
|
|
}
|
|
|
|
/* Light Theme Overrides */
|
|
[data-theme="light"] {
|
|
--bg-primary: #f9f9fb;
|
|
--bg-secondary: #ffffff;
|
|
--bg-tertiary: #f3f4f6;
|
|
--bg-elevated: #e5e7eb;
|
|
--border-subtle: rgba(0, 0, 0, 0.05);
|
|
--border-default: rgba(0, 0, 0, 0.1);
|
|
--border-accent: rgba(99, 102, 241, 0.3);
|
|
--text-primary: #111827;
|
|
--text-secondary: #4b5563;
|
|
--text-tertiary: #9ca3af;
|
|
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
|
|
--shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
|
|
--shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.12);
|
|
}
|
|
|
|
* {
|
|
margin: 0;
|
|
padding: 0;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
body {
|
|
min-height: 100vh;
|
|
background: var(--bg-primary);
|
|
font-family: 'Inter', system-ui, -apple-system, sans-serif;
|
|
color: var(--text-primary);
|
|
overflow: hidden;
|
|
}
|
|
|
|
/* Header */
|
|
.header {
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
right: 0;
|
|
height: 48px;
|
|
background: var(--bg-secondary);
|
|
border-bottom: 1px solid var(--border-default);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: space-between;
|
|
padding: 0 20px;
|
|
z-index: 100;
|
|
}
|
|
|
|
.header-left {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
}
|
|
|
|
.logo {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
}
|
|
|
|
.logo-icon {
|
|
width: 28px;
|
|
height: 28px;
|
|
background: var(--bg-tertiary);
|
|
border: 1px solid var(--border-default);
|
|
border-radius: var(--radius-sm);
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
.logo-icon svg {
|
|
width: 16px;
|
|
height: 16px;
|
|
stroke: var(--accent-blue);
|
|
fill: none;
|
|
}
|
|
|
|
.logo-text {
|
|
font-weight: 600;
|
|
font-size: 15px;
|
|
letter-spacing: -0.3px;
|
|
}
|
|
|
|
.logo-text span {
|
|
color: var(--text-secondary);
|
|
font-weight: 400;
|
|
}
|
|
|
|
.header-right {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 16px;
|
|
}
|
|
|
|
.status-indicator {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
padding: 6px 12px;
|
|
background: var(--bg-tertiary);
|
|
border-radius: 20px;
|
|
border: 1px solid var(--border-subtle);
|
|
}
|
|
|
|
.status-dot {
|
|
width: 8px;
|
|
height: 8px;
|
|
border-radius: 50%;
|
|
background: var(--text-tertiary);
|
|
transition: all 0.3s ease;
|
|
}
|
|
|
|
.status-dot.connected {
|
|
background: var(--accent-green);
|
|
box-shadow: 0 0 8px var(--accent-green);
|
|
}
|
|
|
|
.status-dot.connecting {
|
|
background: var(--accent-amber);
|
|
animation: pulse 1.5s infinite;
|
|
}
|
|
|
|
.status-label {
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
color: var(--text-secondary);
|
|
}
|
|
|
|
@keyframes pulse {
|
|
|
|
0%,
|
|
100% {
|
|
opacity: 1;
|
|
}
|
|
|
|
50% {
|
|
opacity: 0.4;
|
|
}
|
|
}
|
|
|
|
/* Main Layout */
|
|
.main-container {
|
|
display: flex;
|
|
height: 100vh;
|
|
padding-top: 48px;
|
|
}
|
|
|
|
/* Canvas Section */
|
|
.canvas-section {
|
|
flex: 1;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 24px;
|
|
background: var(--bg-primary);
|
|
position: relative;
|
|
}
|
|
|
|
.canvas-wrapper {
|
|
position: relative;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
#viewer-canvas {
|
|
max-width: calc(100vw - 380px - 80px);
|
|
max-height: calc(100vh - 48px - 48px);
|
|
border-radius: var(--radius-lg);
|
|
box-shadow: var(--shadow-lg), 0 0 0 1px var(--border-accent);
|
|
background: var(--bg-secondary);
|
|
transition: box-shadow 0.3s ease;
|
|
}
|
|
|
|
#viewer-canvas.active {
|
|
box-shadow: var(--shadow-lg), 0 0 0 2px var(--accent-blue), 0 0 40px rgba(99, 102, 241, 0.15);
|
|
}
|
|
|
|
/* The last frame, while no new ones come */
|
|
#viewer-canvas.dimmed {
|
|
opacity: 0.4;
|
|
}
|
|
|
|
/* Resize handle */
|
|
.resize-handle {
|
|
position: absolute;
|
|
bottom: -4px;
|
|
right: -4px;
|
|
width: 20px;
|
|
height: 20px;
|
|
cursor: nwse-resize;
|
|
z-index: 10;
|
|
}
|
|
|
|
.resize-handle::before {
|
|
content: '';
|
|
position: absolute;
|
|
bottom: 6px;
|
|
right: 6px;
|
|
width: 8px;
|
|
height: 8px;
|
|
border-right: 2px solid var(--accent-blue);
|
|
border-bottom: 2px solid var(--accent-blue);
|
|
opacity: 0.6;
|
|
}
|
|
|
|
.resize-handle:hover::before {
|
|
opacity: 1;
|
|
}
|
|
|
|
.canvas-placeholder {
|
|
position: absolute;
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
gap: 16px;
|
|
color: var(--text-tertiary);
|
|
}
|
|
|
|
.canvas-placeholder.hidden {
|
|
display: none;
|
|
}
|
|
|
|
.placeholder-icon {
|
|
width: 64px;
|
|
height: 64px;
|
|
stroke: var(--text-tertiary);
|
|
opacity: 0.5;
|
|
}
|
|
|
|
.placeholder-text {
|
|
font-size: 14px;
|
|
text-align: center;
|
|
max-width: 200px;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
/* Inspector Sidebar */
|
|
.inspector-sidebar {
|
|
width: 340px;
|
|
background: var(--bg-secondary);
|
|
border-left: 1px solid var(--border-default);
|
|
display: flex;
|
|
flex-direction: column;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.sidebar-header {
|
|
padding: 16px 20px;
|
|
border-bottom: 1px solid var(--border-subtle);
|
|
background: var(--bg-tertiary);
|
|
}
|
|
|
|
.sidebar-title {
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
text-transform: uppercase;
|
|
letter-spacing: 0.5px;
|
|
color: var(--text-secondary);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.sidebar-title svg {
|
|
width: 14px;
|
|
height: 14px;
|
|
stroke: var(--accent-cyan);
|
|
}
|
|
|
|
.sidebar-content {
|
|
flex: 1;
|
|
overflow-y: auto;
|
|
padding: 12px;
|
|
}
|
|
|
|
.sidebar-content::-webkit-scrollbar {
|
|
width: 6px;
|
|
}
|
|
|
|
.sidebar-content::-webkit-scrollbar-track {
|
|
background: transparent;
|
|
}
|
|
|
|
.sidebar-content::-webkit-scrollbar-thumb {
|
|
background: var(--border-default);
|
|
border-radius: 3px;
|
|
}
|
|
|
|
/* Info Sections */
|
|
.info-section {
|
|
background: var(--bg-tertiary);
|
|
border: 1px solid var(--border-subtle);
|
|
border-radius: var(--radius-md);
|
|
margin-bottom: 12px;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.section-header {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 10px;
|
|
padding: 12px 14px;
|
|
background: var(--bg-elevated);
|
|
cursor: pointer;
|
|
transition: background 0.2s ease;
|
|
position: relative;
|
|
/* For chevron positioning if needed */
|
|
}
|
|
|
|
/* Chevron Icon */
|
|
.section-header::after {
|
|
content: '';
|
|
width: 16px;
|
|
height: 16px;
|
|
margin-left: auto;
|
|
/* Push to right */
|
|
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
|
|
background-repeat: no-repeat;
|
|
background-position: center;
|
|
transition: transform 0.2s ease;
|
|
opacity: 0.7;
|
|
}
|
|
|
|
/* Collapsed State */
|
|
.info-section.collapsed .section-header::after {
|
|
transform: rotate(-90deg);
|
|
}
|
|
|
|
.info-section.collapsed .section-body {
|
|
display: none;
|
|
}
|
|
|
|
.section-header:hover {
|
|
background: rgba(255, 255, 255, 0.05);
|
|
}
|
|
|
|
.section-header:hover::after {
|
|
opacity: 1;
|
|
stroke: var(--text-primary);
|
|
}
|
|
|
|
.section-header:hover {
|
|
background: rgba(255, 255, 255, 0.05);
|
|
}
|
|
|
|
.section-icon {
|
|
width: 18px;
|
|
height: 18px;
|
|
stroke: var(--accent-blue);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.section-title {
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
flex: 1;
|
|
}
|
|
|
|
.section-badge {
|
|
font-size: 11px;
|
|
font-weight: 500;
|
|
padding: 3px 8px;
|
|
background: rgba(99, 102, 241, 0.15);
|
|
color: var(--accent-blue);
|
|
border-radius: 4px;
|
|
max-width: 120px;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.section-body {
|
|
padding: 12px 14px;
|
|
border-top: 1px solid var(--border-subtle);
|
|
}
|
|
|
|
.info-row {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: flex-start;
|
|
padding: 8px 0;
|
|
gap: 12px;
|
|
}
|
|
|
|
.info-row:not(:last-child) {
|
|
border-bottom: 1px solid var(--border-subtle);
|
|
}
|
|
|
|
.info-label {
|
|
font-size: 12px;
|
|
font-weight: 500;
|
|
color: var(--text-secondary);
|
|
flex-shrink: 0;
|
|
}
|
|
|
|
.info-value {
|
|
font-family: 'JetBrains Mono', monospace;
|
|
font-size: 12px;
|
|
color: var(--accent-cyan);
|
|
background: rgba(34, 211, 238, 0.08);
|
|
padding: 4px 8px;
|
|
border-radius: 4px;
|
|
text-align: right;
|
|
word-break: break-word;
|
|
max-width: 180px;
|
|
}
|
|
|
|
/* Empty State */
|
|
.empty-state {
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 40px 20px;
|
|
text-align: center;
|
|
color: var(--text-tertiary);
|
|
}
|
|
|
|
.empty-state svg {
|
|
width: 32px;
|
|
height: 32px;
|
|
stroke: var(--text-tertiary);
|
|
opacity: 0.5;
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
.empty-state-text {
|
|
font-size: 13px;
|
|
line-height: 1.5;
|
|
}
|
|
|
|
/* Footer Stats */
|
|
.sidebar-footer {
|
|
padding: 12px 16px;
|
|
border-top: 1px solid var(--border-default);
|
|
background: var(--bg-tertiary);
|
|
display: flex;
|
|
justify-content: space-between;
|
|
font-size: 11px;
|
|
color: var(--text-tertiary);
|
|
}
|
|
|
|
.stat-item {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
}
|
|
|
|
.stat-value {
|
|
color: var(--text-secondary);
|
|
font-family: 'JetBrains Mono', monospace;
|
|
}
|
|
|
|
.icon-button {
|
|
background: transparent;
|
|
border: 1px solid var(--border-subtle);
|
|
color: var(--text-secondary);
|
|
padding: 4px;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
transition: all 0.2s;
|
|
margin-right: 12px;
|
|
width: 28px;
|
|
height: 28px;
|
|
}
|
|
|
|
.icon-button:hover {
|
|
background: var(--bg-elevated);
|
|
color: var(--text-primary);
|
|
border-color: var(--border-default);
|
|
}
|
|
|
|
.icon-button svg {
|
|
width: 16px;
|
|
height: 16px;
|
|
}
|
|
|
|
/* Fullscreen Mode */
|
|
:root:fullscreen .header,
|
|
:root:fullscreen .inspector-sidebar {
|
|
display: none !important;
|
|
}
|
|
|
|
:root:fullscreen .main-container {
|
|
padding-top: 0;
|
|
height: 100vh;
|
|
}
|
|
|
|
:root:fullscreen .canvas-section {
|
|
padding: 0;
|
|
width: 100vw;
|
|
height: 100vh;
|
|
background: #000;
|
|
}
|
|
|
|
/* Wrapper always fills available space to allow centering */
|
|
.canvas-wrapper {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
/* Inner wrapper to anchor resize handle tightly to canvas */
|
|
.canvas-inner {
|
|
position: relative;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
}
|
|
|
|
/* Force inner to fill in fit mode OR fullscreen */
|
|
:root:fullscreen .canvas-inner,
|
|
.canvas-wrapper.fit-active .canvas-inner {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
/* Fit Mode */
|
|
#viewer-canvas.fit-mode {
|
|
width: 100% !important;
|
|
height: 100% !important;
|
|
max-width: 100% !important;
|
|
max-height: 100% !important;
|
|
border-radius: 0;
|
|
object-fit: cover;
|
|
box-shadow: none;
|
|
}
|
|
|
|
/* Remove padding when fitting */
|
|
.canvas-section.fit-mode-section {
|
|
padding: 0;
|
|
}
|
|
|
|
/* Hide resize handle in fit mode OR fullscreen */
|
|
:root:fullscreen .resize-handle,
|
|
.canvas-wrapper.fit-active .resize-handle {
|
|
display: none;
|
|
}
|
|
|
|
:root:fullscreen #viewer-canvas {
|
|
width: 100% !important;
|
|
height: 100% !important;
|
|
max-width: none !important;
|
|
max-height: none !important;
|
|
border-radius: 0 !important;
|
|
box-shadow: none !important;
|
|
object-fit: cover;
|
|
}
|
|
|
|
/* Clickable row styles */
|
|
.info-row.clickable-row {
|
|
cursor: pointer;
|
|
transition: background 0.2s ease;
|
|
}
|
|
|
|
.info-row.clickable-row:hover {
|
|
background: var(--bg-elevated);
|
|
}
|
|
|
|
.dropdown-indicator {
|
|
margin-left: 4px;
|
|
opacity: 0.6;
|
|
font-size: 10px;
|
|
}
|
|
|
|
/* Node selector dropdown */
|
|
.node-selector-dropdown {
|
|
position: absolute;
|
|
z-index: 100000;
|
|
max-height: 300px;
|
|
overflow-y: auto;
|
|
background: var(--bg-elevated);
|
|
border: 1px solid var(--border-default);
|
|
border-radius: var(--radius-md);
|
|
box-shadow: var(--shadow-lg);
|
|
min-width: 200px;
|
|
max-width: 300px;
|
|
}
|
|
|
|
.node-selector-dropdown .dropdown-item {
|
|
padding: 8px 12px;
|
|
cursor: pointer;
|
|
border-bottom: 1px solid var(--border-subtle);
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
font-size: 13px;
|
|
}
|
|
|
|
.node-selector-dropdown .dropdown-item:hover {
|
|
background: var(--bg-tertiary);
|
|
}
|
|
|
|
.node-selector-dropdown .dropdown-item:last-child {
|
|
border-bottom: none;
|
|
}
|
|
|
|
.node-selector-dropdown .node-order {
|
|
color: var(--accent-cyan);
|
|
font-weight: 600;
|
|
min-width: 24px;
|
|
}
|
|
|
|
.node-selector-dropdown .node-title {
|
|
flex: 1;
|
|
overflow: hidden;
|
|
text-overflow: ellipsis;
|
|
white-space: nowrap;
|
|
}
|
|
|
|
.node-selector-dropdown .node-type {
|
|
color: var(--text-tertiary);
|
|
font-size: 11px;
|
|
}
|
|
|
|
/* Widget Editor Styles for Pop-out */
|
|
.widget-value-editable {
|
|
cursor: pointer;
|
|
border: 1px solid transparent;
|
|
transition: border-color 0.15s ease;
|
|
}
|
|
|
|
.widget-value-editable:hover {
|
|
border-color: var(--accent-blue);
|
|
}
|
|
|
|
.widget-list {
|
|
margin-top: 12px;
|
|
}
|
|
|
|
.widget-card {
|
|
padding: 10px 12px;
|
|
margin-bottom: 6px;
|
|
border-radius: 6px;
|
|
background: var(--bg-secondary);
|
|
border: 1px solid var(--border-subtle);
|
|
}
|
|
|
|
.widget-card:hover {
|
|
background: var(--bg-tertiary);
|
|
border-color: var(--border-default);
|
|
}
|
|
|
|
.widget-head {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
align-items: center;
|
|
gap: 6px;
|
|
margin-bottom: 6px;
|
|
}
|
|
|
|
.widget-name {
|
|
font-size: 12px;
|
|
font-weight: 600;
|
|
color: var(--text-primary);
|
|
}
|
|
|
|
.widget-type {
|
|
font-size: 11px;
|
|
color: var(--text-secondary);
|
|
}
|
|
|
|
.widget-value {
|
|
font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
|
|
font-size: 12px;
|
|
line-height: 1.4;
|
|
color: var(--accent-blue);
|
|
background: var(--bg-tertiary);
|
|
padding: 8px 10px;
|
|
border-radius: 4px;
|
|
word-break: break-word;
|
|
white-space: pre-wrap;
|
|
}
|
|
|
|
.value-empty {
|
|
color: var(--text-secondary);
|
|
font-style: italic;
|
|
}
|
|
|
|
.widget-button {
|
|
width: 100%;
|
|
padding: 8px 16px;
|
|
font: inherit;
|
|
font-size: 13px;
|
|
font-weight: 600;
|
|
color: var(--bg-primary);
|
|
background: var(--accent-blue);
|
|
border: none;
|
|
border-radius: 6px;
|
|
cursor: pointer;
|
|
}
|
|
|
|
.widget-slider {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 8px;
|
|
}
|
|
|
|
.widget-editor-slider {
|
|
flex: 1;
|
|
accent-color: var(--accent-blue);
|
|
}
|
|
|
|
.widget-slider-value {
|
|
min-width: 50px;
|
|
text-align: right;
|
|
font-family: monospace;
|
|
color: var(--accent-blue);
|
|
}
|
|
|
|
.widget-image {
|
|
background: var(--bg-tertiary);
|
|
border-radius: 4px;
|
|
padding: 8px;
|
|
text-align: center;
|
|
overflow: hidden;
|
|
}
|
|
|
|
.widget-image img {
|
|
max-width: 100%;
|
|
}
|
|
|
|
.widget-editor-inline {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 4px;
|
|
}
|
|
|
|
.widget-editor-input {
|
|
font-family: 'JetBrains Mono', monospace;
|
|
font-size: 12px;
|
|
background: var(--bg-primary);
|
|
border: 1px solid var(--accent-blue);
|
|
border-radius: 4px;
|
|
color: var(--text-primary);
|
|
padding: 4px 8px;
|
|
width: 100%;
|
|
outline: none;
|
|
}
|
|
|
|
textarea.widget-editor-input {
|
|
resize: vertical;
|
|
line-height: 1.4;
|
|
}
|
|
|
|
.widget-editor-input:focus {
|
|
box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.25);
|
|
}
|
|
|
|
.widget-editor-select {
|
|
font-family: 'JetBrains Mono', monospace;
|
|
font-size: 12px;
|
|
background: var(--bg-primary);
|
|
border: 1px solid var(--accent-blue);
|
|
border-radius: 4px;
|
|
color: var(--text-primary);
|
|
padding: 4px 8px;
|
|
width: 100%;
|
|
cursor: pointer;
|
|
}
|
|
</style>
|
|
</head>
|
|
|
|
<body>
|
|
<header class="header">
|
|
<div class="header-left">
|
|
<div class="logo">
|
|
<div class="logo-icon">
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" stroke-width="2" stroke-linecap="round"
|
|
stroke-linejoin="round">
|
|
<circle cx="11" cy="11" r="8" />
|
|
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
</svg>
|
|
</div>
|
|
<span class="logo-text">MagnifyGlass <span>Viewer</span></span>
|
|
</div>
|
|
</div>
|
|
<div class="header-right">
|
|
<button id="fit-btn" class="icon-button" title="Fit to Container">
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
|
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7" />
|
|
</svg>
|
|
</button>
|
|
<button id="fullscreen-btn" class="icon-button" title="Toggle Fullscreen">
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor"
|
|
stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path
|
|
d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3" />
|
|
</svg>
|
|
</button>
|
|
<div class="status-indicator">
|
|
<span class="status-dot connecting"></span>
|
|
<span class="status-label">Connecting...</span>
|
|
</div>
|
|
</div>
|
|
</header>
|
|
|
|
<main class="main-container">
|
|
<section class="canvas-section">
|
|
<div class="canvas-wrapper">
|
|
<div class="canvas-inner">
|
|
<canvas id="viewer-canvas" width="300" height="300"></canvas>
|
|
<div class="resize-handle" id="resize-handle" title="Drag to resize"></div>
|
|
</div>
|
|
<div class="canvas-placeholder">
|
|
<svg class="placeholder-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none"
|
|
stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round">
|
|
<circle cx="11" cy="11" r="8" />
|
|
<line x1="21" y1="21" x2="16.65" y2="16.65" />
|
|
</svg>
|
|
<p class="placeholder-text">Waiting for connection from ComfyUI...</p>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
|
|
<aside class="inspector-sidebar">
|
|
<div class="sidebar-header">
|
|
<div class="sidebar-title">
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-width="2"
|
|
stroke-linecap="round" stroke-linejoin="round">
|
|
<circle cx="12" cy="12" r="10" />
|
|
<line x1="12" y1="16" x2="12" y2="12" />
|
|
<line x1="12" y1="8" x2="12.01" y2="8" />
|
|
</svg>
|
|
Inspector
|
|
</div>
|
|
</div>
|
|
<div class="sidebar-content" id="sidebar-content">
|
|
<div class="empty-state" id="empty-state">
|
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-width="1.5"
|
|
stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z" />
|
|
<circle cx="12" cy="10" r="3" />
|
|
</svg>
|
|
<p class="empty-state-text">Move your cursor over nodes in ComfyUI to see details here</p>
|
|
</div>
|
|
</div>
|
|
<!-- Stats footer removed per user request -->
|
|
</aside>
|
|
</main>
|
|
|
|
|
|
|
|
<script>
|
|
const CHANNEL_NAME = 'comfyui-magnifyglass-popout';
|
|
// Each ComfyUI tab has its own channel, named by the session in this page's URL
|
|
const session = new URLSearchParams(location.search).get('session');
|
|
|
|
// DOM Elements
|
|
const canvas = document.getElementById('viewer-canvas');
|
|
const ctx = canvas.getContext('2d');
|
|
const statusDot = document.querySelector('.status-dot');
|
|
const statusLabel = document.querySelector('.status-label');
|
|
const placeholder = document.querySelector('.canvas-placeholder');
|
|
const sidebarContent = document.getElementById('sidebar-content');
|
|
const emptyState = document.getElementById('empty-state');
|
|
|
|
// State: 'connecting', 'connected', 'inactive' (no ping for a while) or 'closed' (ComfyUI closed or reloaded, or closed this viewer)
|
|
let connection = 'connecting';
|
|
let lastPingTime = 0;
|
|
let config = { glass: 'on', inspector: true };
|
|
const frameImage = new Image();
|
|
|
|
const channel = new BroadcastChannel(`${CHANNEL_NAME}:${session}`);
|
|
|
|
// Fullscreen Logic
|
|
const fullscreenBtn = document.getElementById('fullscreen-btn');
|
|
const enterFullscreenIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/></svg>';
|
|
const exitFullscreenIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 3v3a2 2 0 0 1-2 2H3m18 0h-3a2 2 0 0 1-2-2V3m0 18v-3a2 2 0 0 1 2-2h3M3 16h3a2 2 0 0 1 2 2v3"/></svg>';
|
|
|
|
fullscreenBtn.addEventListener('click', () => {
|
|
if (!document.fullscreenElement) {
|
|
document.documentElement.requestFullscreen().catch(err => {
|
|
console.error(`Error attempting to enable fullscreen: ${err.message}`);
|
|
});
|
|
} else {
|
|
if (document.exitFullscreen) {
|
|
document.exitFullscreen();
|
|
}
|
|
}
|
|
});
|
|
|
|
document.addEventListener('fullscreenchange', () => {
|
|
if (document.fullscreenElement) {
|
|
fullscreenBtn.innerHTML = exitFullscreenIcon;
|
|
fullscreenBtn.title = "Exit Fullscreen";
|
|
} else {
|
|
fullscreenBtn.innerHTML = enterFullscreenIcon;
|
|
fullscreenBtn.title = "Enter Fullscreen";
|
|
}
|
|
});
|
|
|
|
channel.onmessage = (event) => {
|
|
const message = event.data;
|
|
|
|
switch (message.type) {
|
|
case 'frame':
|
|
handleFrame(message.data);
|
|
break;
|
|
case 'config':
|
|
handleConfig(message.data);
|
|
break;
|
|
case 'info':
|
|
handleInfo(message.data);
|
|
break;
|
|
case 'ping':
|
|
lastPingTime = Date.now();
|
|
channel.postMessage({ type: 'pong' });
|
|
setConnection('connected');
|
|
break;
|
|
case 'close':
|
|
setConnection('closed');
|
|
break;
|
|
case 'nodes-list':
|
|
handleNodesList(message.data);
|
|
break;
|
|
case 'options':
|
|
handleOptions(message.data);
|
|
break;
|
|
}
|
|
};
|
|
|
|
function handleFrame(dataUrl) {
|
|
if (!dataUrl) return;
|
|
|
|
frameImage.onload = () => {
|
|
if (canvas.width !== frameImage.width || canvas.height !== frameImage.height) {
|
|
canvas.width = frameImage.width;
|
|
canvas.height = frameImage.height;
|
|
// Resolution display removed
|
|
}
|
|
|
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
|
ctx.drawImage(frameImage, 0, 0);
|
|
canvas.classList.add('active');
|
|
};
|
|
|
|
frameImage.src = dataUrl;
|
|
placeholder.classList.add('hidden');
|
|
}
|
|
|
|
function handleConfig(data) {
|
|
document.documentElement.setAttribute('data-theme', data.theme);
|
|
const inspectorChanged = data.inspector !== config.inspector;
|
|
config = data;
|
|
renderStatus();
|
|
if (inspectorChanged) handleInfo(currentInfo);
|
|
}
|
|
|
|
// The latest info, the info the sidebar was last rendered from, and the combo editor waiting for its options
|
|
let currentInfo = null;
|
|
let renderedInfo = null;
|
|
let pendingOptions = null;
|
|
|
|
function handleInfo(info) {
|
|
currentInfo = info;
|
|
// Re-rendering would drop an open editor; closing it renders the latest info
|
|
if (sidebarContent.querySelector('.widget-editor-inline')) return;
|
|
if (!info || !info.node || !config.inspector) {
|
|
showEmptyState();
|
|
return;
|
|
}
|
|
|
|
hideEmptyState();
|
|
renderInfo(info);
|
|
}
|
|
|
|
function sendWidgetEdit(row, value) {
|
|
channel.postMessage({ type: 'widget-edit', data: { nodeId: renderedInfo.node.id, widgetName: row.widgetName, value } });
|
|
}
|
|
|
|
// Rows carry their index into renderedInfo.rows; names never go into inline handlers
|
|
function rowFor(element) {
|
|
const index = element.dataset.widget;
|
|
return renderedInfo && index !== undefined ? renderedInfo.rows[Number(index)] : null;
|
|
}
|
|
|
|
sidebarContent.addEventListener('click', (e) => {
|
|
const action = e.target.closest('[data-action]');
|
|
if (action) {
|
|
if (action.dataset.action === 'toggle-section') toggleSection(action);
|
|
else if (action.dataset.action === 'node-dropdown') requestNodeDropdown(action.dataset.sort, action);
|
|
else if (action.dataset.action === 'focus-node' && renderedInfo) {
|
|
channel.postMessage({ type: 'panel-action', data: { name: 'focus-node', nodeId: renderedInfo.node.id } });
|
|
}
|
|
return;
|
|
}
|
|
const element = e.target.closest('[data-widget]');
|
|
const row = element && rowFor(element);
|
|
if (!row) return;
|
|
if (element.dataset.kind === 'action') {
|
|
channel.postMessage({ type: 'button-click', data: { nodeId: renderedInfo.node.id, widgetName: row.widgetName } });
|
|
} else if (element.dataset.kind === 'value') {
|
|
editWidgetValue(element, row);
|
|
}
|
|
});
|
|
|
|
sidebarContent.addEventListener('input', (e) => {
|
|
const slider = e.target.closest('.widget-editor-slider');
|
|
if (slider) slider.nextElementSibling.textContent = slider.value;
|
|
});
|
|
|
|
sidebarContent.addEventListener('change', (e) => {
|
|
const slider = e.target.closest('.widget-editor-slider');
|
|
const row = slider && rowFor(slider);
|
|
if (row) sendWidgetEdit(row, parseFloat(slider.value));
|
|
});
|
|
|
|
function handleOptions(data) {
|
|
const pending = pendingOptions;
|
|
if (!pending || pending.nodeId !== data.nodeId || pending.widgetName !== data.widgetName) return;
|
|
pendingOptions = null;
|
|
pending.fill(data.options);
|
|
}
|
|
|
|
/**
|
|
* Start editing a widget value inline. Enter or blur commits, Escape cancels;
|
|
* a textarea commits on Ctrl/Cmd+Enter so its newlines survive.
|
|
*/
|
|
function editWidgetValue(element, row) {
|
|
if (element.querySelector('.widget-editor-inline')) return;
|
|
|
|
const type = row.widgetType;
|
|
const constraints = row.constraints;
|
|
|
|
if (type === 'boolean') {
|
|
const newValue = !row.rawValue;
|
|
sendWidgetEdit(row, newValue);
|
|
element.textContent = String(newValue);
|
|
return;
|
|
}
|
|
|
|
let editor;
|
|
let readValue;
|
|
if (type === 'combo') {
|
|
editor = document.createElement('select');
|
|
editor.className = 'widget-editor-select';
|
|
// A hidden placeholder, so picking the current value again still fires change
|
|
const addOption = (label) => {
|
|
const option = document.createElement('option');
|
|
option.textContent = String(label);
|
|
editor.appendChild(option);
|
|
};
|
|
addOption('Loading…');
|
|
editor.options[0].disabled = true;
|
|
let options = [];
|
|
// The option itself, so numeric combo values stay numbers
|
|
readValue = () => editor.selectedIndex > 0 ? options[editor.selectedIndex - 1] : undefined;
|
|
// ComfyUI sends the list only for an open editor, as it can be long
|
|
pendingOptions = {
|
|
nodeId: renderedInfo.node.id,
|
|
widgetName: row.widgetName,
|
|
editor,
|
|
fill(list) {
|
|
if (!list.length) return finish(false);
|
|
options = list;
|
|
editor.options[0].textContent = 'Select...';
|
|
editor.options[0].hidden = true;
|
|
list.forEach(addOption);
|
|
editor.selectedIndex = 0;
|
|
}
|
|
};
|
|
channel.postMessage({ type: 'request-options', data: { nodeId: pendingOptions.nodeId, widgetName: row.widgetName } });
|
|
} else if (type === 'INT' || type === 'FLOAT') {
|
|
editor = document.createElement('input');
|
|
editor.type = 'number';
|
|
editor.className = 'widget-editor-input';
|
|
if (constraints.min !== undefined) editor.min = String(constraints.min);
|
|
if (constraints.max !== undefined) editor.max = String(constraints.max);
|
|
editor.step = String(constraints.step ?? (type === 'INT' ? 1 : 'any'));
|
|
editor.value = String(row.rawValue);
|
|
readValue = () => editor.value === '' || isNaN(parseFloat(editor.value)) ? undefined : parseFloat(editor.value);
|
|
} else {
|
|
const text = String(row.rawValue ?? '');
|
|
const multiline = type === 'multiline' || text.includes('\n');
|
|
editor = document.createElement(multiline ? 'textarea' : 'input');
|
|
editor.className = 'widget-editor-input';
|
|
if (multiline) {
|
|
editor.rows = Math.min(Math.max(text.split('\n').length, 3), 12);
|
|
} else {
|
|
editor.type = 'text';
|
|
}
|
|
editor.value = text;
|
|
readValue = () => editor.value;
|
|
}
|
|
|
|
let done = false;
|
|
function finish(commit) {
|
|
if (done) return;
|
|
done = true;
|
|
if (pendingOptions?.editor === editor) pendingOptions = null;
|
|
const value = readValue();
|
|
element.innerHTML = '';
|
|
if (commit && value !== undefined) {
|
|
// Shown until ComfyUI sends the value it kept
|
|
sendWidgetEdit(row, value);
|
|
element.textContent = String(value);
|
|
} else {
|
|
handleInfo(currentInfo);
|
|
}
|
|
}
|
|
|
|
if (editor.tagName === 'SELECT') {
|
|
editor.addEventListener('change', () => finish(true));
|
|
// Clicking away without a pick cancels
|
|
editor.addEventListener('blur', () => finish(editor.selectedIndex > 0));
|
|
} else {
|
|
editor.addEventListener('blur', () => finish(true));
|
|
}
|
|
editor.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Escape') {
|
|
finish(false);
|
|
} else if (e.key === 'Enter' && (editor.tagName !== 'TEXTAREA' || e.ctrlKey || e.metaKey)) {
|
|
e.preventDefault();
|
|
finish(true);
|
|
}
|
|
});
|
|
|
|
const wrapper = document.createElement('div');
|
|
wrapper.className = 'widget-editor-inline';
|
|
wrapper.appendChild(editor);
|
|
element.innerHTML = '';
|
|
element.appendChild(wrapper);
|
|
editor.focus();
|
|
if (editor.select) editor.select();
|
|
}
|
|
|
|
function renderInfo(info) {
|
|
renderedInfo = info;
|
|
const node = info.node;
|
|
const isCollapsed = window.collapsedSections?.has('node');
|
|
|
|
sidebarContent.innerHTML = `
|
|
<div class="info-section ${isCollapsed ? 'collapsed' : ''}" data-section-id="node">
|
|
<div class="section-header" data-action="toggle-section">
|
|
<svg class="section-icon" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
<path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/>
|
|
</svg>
|
|
<span class="section-title">Node</span>
|
|
<span class="section-badge">${escapeHtml(node.type)}</span>
|
|
</div>
|
|
<div class="section-body">
|
|
<div class="info-row clickable-row" data-action="node-dropdown" data-sort="title">
|
|
<span class="info-label">Title</span>
|
|
<span class="info-value clickable-value">${escapeHtml(node.title)} (#${escapeHtml(node.id)})<span class="dropdown-indicator">▼</span></span>
|
|
</div>
|
|
${node.execOrder !== undefined ? `
|
|
<div class="info-row clickable-row" data-action="node-dropdown" data-sort="execOrder">
|
|
<span class="info-label">Exec Order</span>
|
|
<span class="info-value">${escapeHtml(node.execOrder)}<span class="dropdown-indicator">▼</span></span>
|
|
</div>` : ''}
|
|
<div class="info-row clickable-row" data-action="focus-node">
|
|
<span class="info-label">Location</span>
|
|
<span class="info-value">Focus Node</span>
|
|
</div>
|
|
<div class="info-row">
|
|
<span class="info-label">Mode</span>
|
|
<span class="info-value">${escapeHtml(node.mode)}</span>
|
|
</div>
|
|
${renderRows(info)}
|
|
</div>
|
|
</div>
|
|
`;
|
|
for (const holder of sidebarContent.querySelectorAll('.widget-image')) {
|
|
const img = document.createElement('img');
|
|
img.src = holder.dataset.src;
|
|
holder.appendChild(img);
|
|
}
|
|
}
|
|
|
|
// Initialize collapsed state tracking
|
|
window.collapsedSections = new Set();
|
|
|
|
function toggleSection(header) {
|
|
const section = header.parentElement;
|
|
const sectionId = section.dataset.sectionId;
|
|
section.classList.toggle('collapsed');
|
|
|
|
if (section.classList.contains('collapsed')) {
|
|
window.collapsedSections.add(sectionId);
|
|
} else {
|
|
window.collapsedSections.delete(sectionId);
|
|
}
|
|
}
|
|
|
|
// The widget rows as ComfyUI's Inspector computed them; it also decides which can be edited
|
|
function renderRows(info) {
|
|
if (!info.rows.length) return '';
|
|
|
|
return `<div class="widget-list">${info.rows.map((row, index) => {
|
|
const label = escapeHtml(row.label);
|
|
// Values without a primitive raw value, like objects, have no editor that keeps them intact
|
|
const editable = row.isEditable && info.nav.canEdit && row.rawValue !== undefined;
|
|
// Plot nodes send an <img> with a data URI; only the URI itself is used
|
|
const imageSrc = row.value.match(IMAGE_DATA_URI)?.[0];
|
|
let body;
|
|
if (row.isActionable) {
|
|
body = `<button class="widget-button" data-widget="${index}" data-kind="action">${label}</button>`;
|
|
} else if (imageSrc) {
|
|
body = `<div class="widget-image" data-src="${imageSrc}"></div>`;
|
|
} else if (editable && row.widgetType === 'slider') {
|
|
const { min = 0, max = 100, step = 0.01 } = row.constraints;
|
|
body = `
|
|
<div class="widget-slider">
|
|
<input type="range" class="widget-editor-slider" min="${escapeHtml(min)}" max="${escapeHtml(max)}" step="${escapeHtml(step)}" value="${escapeHtml(row.rawValue)}" data-widget="${index}">
|
|
<span class="widget-slider-value">${escapeHtml(row.value)}</span>
|
|
</div>`;
|
|
} else {
|
|
const shown = row.value === '' ? '<span class="value-empty">empty</span>' : escapeHtml(row.value);
|
|
const attrs = editable ? ` data-widget="${index}" data-kind="value" title="Click to edit"`
|
|
: row.isEditable && !info.nav.canEdit ? ' title="Lock the node in ComfyUI to edit"' : '';
|
|
body = `<div class="widget-value${editable ? ' widget-value-editable' : ''}"${attrs}>${shown}</div>`;
|
|
}
|
|
return `
|
|
<div class="widget-card">
|
|
<div class="widget-head">
|
|
<span class="widget-name">${label}</span>
|
|
${row.widgetType ? `<span class="widget-type">${escapeHtml(row.widgetType)}</span>` : ''}
|
|
${row.isLinked ? '<span class="widget-type" title="Set by a link">linked</span>' : ''}
|
|
</div>
|
|
${body}
|
|
</div>`;
|
|
}).join('')}</div>`;
|
|
}
|
|
|
|
const HTML_ESCAPES = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' };
|
|
const IMAGE_DATA_URI = /data:image\/(?:png|jpeg|webp|gif);base64,[A-Za-z0-9+\/=]+/;
|
|
|
|
function escapeHtml(text) {
|
|
return String(text ?? '').replace(/[&<>"']/g, c => HTML_ESCAPES[c]);
|
|
}
|
|
|
|
function showEmptyState() {
|
|
const empty = emptyState.cloneNode(true);
|
|
if (!config.inspector) empty.querySelector('.empty-state-text').textContent = 'The Inspector is off in ComfyUI';
|
|
sidebarContent.innerHTML = '';
|
|
sidebarContent.appendChild(empty);
|
|
}
|
|
|
|
function hideEmptyState() {
|
|
const existing = sidebarContent.querySelector('.empty-state');
|
|
if (existing) existing.remove();
|
|
}
|
|
|
|
// Node selection dropdown functionality
|
|
let currentDropdownAnchorRect = null;
|
|
|
|
function requestNodeDropdown(type, anchorElement) {
|
|
// Store anchor position immediately (before potential re-render)
|
|
if (anchorElement) {
|
|
currentDropdownAnchorRect = anchorElement.getBoundingClientRect();
|
|
}
|
|
|
|
if (channel) {
|
|
channel.postMessage({ type: 'request-nodes', data: type });
|
|
}
|
|
}
|
|
|
|
function handleNodesList(data) {
|
|
if (!data || !data.nodes || !currentDropdownAnchorRect) return;
|
|
showDropdown(data.nodes, data.sortBy);
|
|
}
|
|
|
|
function showDropdown(nodes, sortBy) {
|
|
// Save anchorRect before hideDropdown clears it
|
|
const savedAnchorRect = currentDropdownAnchorRect;
|
|
hideDropdown();
|
|
|
|
if (nodes.length === 0) return;
|
|
if (!savedAnchorRect) return;
|
|
|
|
const dropdown = document.createElement('div');
|
|
dropdown.className = 'node-selector-dropdown';
|
|
dropdown.id = 'node-dropdown';
|
|
|
|
nodes.forEach(node => {
|
|
const item = document.createElement('div');
|
|
item.className = 'dropdown-item';
|
|
|
|
if (sortBy === 'execOrder' && node.order !== undefined) {
|
|
item.innerHTML = `
|
|
<span class="node-order">#${escapeHtml(node.order)}</span>
|
|
<span class="node-title">${escapeHtml(node.title)} (#${escapeHtml(node.id)})</span>
|
|
<span class="node-type">${escapeHtml(node.type)}</span>
|
|
`;
|
|
} else if (sortBy === 'id') {
|
|
item.innerHTML = `
|
|
<span class="node-order">#${escapeHtml(node.id)}</span>
|
|
<span class="node-title">${escapeHtml(node.title)}</span>
|
|
<span class="node-type">${escapeHtml(node.type)}</span>
|
|
`;
|
|
} else {
|
|
item.innerHTML = `
|
|
<span class="node-title">${escapeHtml(node.title)} (#${escapeHtml(node.id)})</span>
|
|
<span class="node-type">${escapeHtml(node.type)}</span>
|
|
`;
|
|
}
|
|
|
|
item.addEventListener('click', (e) => {
|
|
e.stopPropagation();
|
|
selectNode(node.id);
|
|
hideDropdown();
|
|
});
|
|
|
|
dropdown.appendChild(item);
|
|
});
|
|
|
|
// Position dropdown
|
|
document.body.appendChild(dropdown);
|
|
const anchorRect = savedAnchorRect;
|
|
dropdown.style.top = `${anchorRect.bottom + 4}px`;
|
|
dropdown.style.left = `${anchorRect.left}px`;
|
|
|
|
// Adjust if off-screen
|
|
const dropdownRect = dropdown.getBoundingClientRect();
|
|
if (dropdownRect.right > window.innerWidth - 10) {
|
|
dropdown.style.left = `${window.innerWidth - dropdownRect.width - 10}px`;
|
|
}
|
|
if (dropdownRect.bottom > window.innerHeight - 10) {
|
|
dropdown.style.top = `${anchorRect.top - dropdownRect.height - 4}px`;
|
|
}
|
|
|
|
// Close on click outside
|
|
setTimeout(() => {
|
|
document.addEventListener('click', closeDropdownOnClickOutside);
|
|
}, 10);
|
|
}
|
|
|
|
function closeDropdownOnClickOutside(e) {
|
|
const dropdown = document.getElementById('node-dropdown');
|
|
if (dropdown && !dropdown.contains(e.target)) {
|
|
hideDropdown();
|
|
}
|
|
}
|
|
|
|
function hideDropdown() {
|
|
const dropdown = document.getElementById('node-dropdown');
|
|
if (dropdown) {
|
|
dropdown.remove();
|
|
}
|
|
document.removeEventListener('click', closeDropdownOnClickOutside);
|
|
currentDropdownAnchorRect = null;
|
|
}
|
|
|
|
function selectNode(nodeId) {
|
|
// Send node selection to main window
|
|
if (channel) {
|
|
channel.postMessage({ type: 'node-select', data: nodeId });
|
|
}
|
|
}
|
|
|
|
const STATUS_LABELS = { connecting: 'Connecting...', inactive: 'ComfyUI tab inactive', closed: 'Disconnected from ComfyUI' };
|
|
const GLASS_LABELS = { on: 'Connected', hidden: 'Glass hidden', off: 'Glass off' };
|
|
|
|
function setConnection(state) {
|
|
if (state === connection) return;
|
|
connection = state;
|
|
renderStatus();
|
|
// The ComfyUI tab skips frames while this page is hidden
|
|
if (state === 'connected') channel.postMessage({ type: 'visibility', data: document.hidden });
|
|
}
|
|
|
|
// Status never touches the sidebar, so an open editor and the last info stay
|
|
function renderStatus() {
|
|
const live = connection === 'connected';
|
|
statusDot.classList.toggle('connected', live && config.glass !== 'off');
|
|
statusDot.classList.toggle('connecting', connection === 'connecting' || connection === 'inactive');
|
|
statusLabel.textContent = live ? GLASS_LABELS[config.glass] : STATUS_LABELS[connection];
|
|
canvas.classList.toggle('dimmed', !live || config.glass === 'off');
|
|
}
|
|
|
|
document.addEventListener('visibilitychange', () => {
|
|
if (connection === 'connected') channel.postMessage({ type: 'visibility', data: document.hidden });
|
|
});
|
|
|
|
// ComfyUI pings only while it counts this page as connected; until then announce once a second
|
|
setInterval(() => {
|
|
if (connection === 'connected' && Date.now() - lastPingTime > 3000) setConnection('inactive');
|
|
if (connection !== 'connected') channel.postMessage({ type: 'pong' });
|
|
}, 1000);
|
|
channel.postMessage({ type: 'pong' });
|
|
|
|
window.addEventListener('beforeunload', () => {
|
|
channel.postMessage({ type: 'close' });
|
|
channel.close();
|
|
});
|
|
|
|
// Escape closes the node list; an editor handles its own
|
|
document.addEventListener('keydown', (e) => {
|
|
if (e.key === 'Escape') hideDropdown();
|
|
});
|
|
|
|
// Fit Mode Logic
|
|
const fitBtn = document.getElementById('fit-btn');
|
|
const canvasWrapper = document.querySelector('.canvas-wrapper');
|
|
let isFitMode = false;
|
|
|
|
// Icons
|
|
const fitIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7"/></svg>';
|
|
const originalSizeIcon = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="4" y="4" width="16" height="16" rx="2" /><path d="M15 3h6v6M9 21H3v-6"/></svg>'; // Approx icon for "Manual/Original"
|
|
|
|
// Load saved fit mode
|
|
const savedFitMode = localStorage.getItem('magnifyglass-viewer-fitmode');
|
|
if (savedFitMode === 'true') {
|
|
toggleFitMode(true);
|
|
}
|
|
|
|
fitBtn.addEventListener('click', () => {
|
|
toggleFitMode(!isFitMode);
|
|
});
|
|
|
|
function toggleFitMode(active) {
|
|
isFitMode = active;
|
|
localStorage.setItem('magnifyglass-viewer-fitmode', isFitMode);
|
|
|
|
const canvasSection = canvasWrapper.closest('.canvas-section');
|
|
|
|
if (isFitMode) {
|
|
canvas.classList.add('fit-mode');
|
|
canvasWrapper.classList.add('fit-active');
|
|
if (canvasSection) canvasSection.classList.add('fit-mode-section');
|
|
|
|
fitBtn.title = "Restore Manual Size";
|
|
fitBtn.classList.add('active'); // Optional styling
|
|
// We don't change icon, or maybe we do?
|
|
// Let's keep the "arrows out" to mean "currently fit"?
|
|
// Or "arrows out" means "Click to Fit"?
|
|
// Let's toggle icon for clarity.
|
|
// Actually, let's just highlight the button/change title.
|
|
fitBtn.style.color = 'var(--text-primary)';
|
|
fitBtn.style.background = 'var(--bg-elevated)';
|
|
} else {
|
|
canvas.classList.remove('fit-mode');
|
|
canvasWrapper.classList.remove('fit-active');
|
|
if (canvasSection) canvasSection.classList.remove('fit-mode-section');
|
|
|
|
fitBtn.title = "Fit to Container";
|
|
fitBtn.style.color = '';
|
|
fitBtn.style.background = '';
|
|
}
|
|
}
|
|
|
|
// Resize functionality
|
|
const resizeHandle = document.getElementById('resize-handle');
|
|
// canvasWrapper already selected above
|
|
let isResizing = false;
|
|
let startX, startY, startWidth, startHeight;
|
|
|
|
// Load saved size
|
|
const savedSize = localStorage.getItem('magnifyglass-viewer-size');
|
|
if (savedSize) {
|
|
try {
|
|
const { width, height } = JSON.parse(savedSize);
|
|
canvas.style.width = `${width}px`;
|
|
canvas.style.height = `${height}px`;
|
|
} catch (e) { }
|
|
}
|
|
|
|
resizeHandle.addEventListener('mousedown', (e) => {
|
|
isResizing = true;
|
|
startX = e.clientX;
|
|
startY = e.clientY;
|
|
startWidth = canvas.offsetWidth;
|
|
startHeight = canvas.offsetHeight;
|
|
document.body.style.cursor = 'nwse-resize';
|
|
e.preventDefault();
|
|
});
|
|
|
|
document.addEventListener('mousemove', (e) => {
|
|
if (!isResizing) return;
|
|
|
|
const deltaX = e.clientX - startX;
|
|
const deltaY = e.clientY - startY;
|
|
|
|
// Keep aspect ratio by using the larger delta
|
|
const delta = Math.max(deltaX, deltaY);
|
|
const aspectRatio = startWidth / startHeight;
|
|
|
|
let newWidth = Math.max(200, startWidth + delta);
|
|
let newHeight = newWidth / aspectRatio;
|
|
|
|
// Constrain to viewport
|
|
const maxW = window.innerWidth - 400;
|
|
const maxH = window.innerHeight - 100;
|
|
if (newWidth > maxW) {
|
|
newWidth = maxW;
|
|
newHeight = newWidth / aspectRatio;
|
|
}
|
|
if (newHeight > maxH) {
|
|
newHeight = maxH;
|
|
newWidth = newHeight * aspectRatio;
|
|
}
|
|
|
|
canvas.style.width = `${newWidth}px`;
|
|
canvas.style.height = `${newHeight}px`;
|
|
});
|
|
|
|
document.addEventListener('mouseup', () => {
|
|
if (isResizing) {
|
|
isResizing = false;
|
|
document.body.style.cursor = '';
|
|
// Save size
|
|
localStorage.setItem('magnifyglass-viewer-size', JSON.stringify({
|
|
width: canvas.offsetWidth,
|
|
height: canvas.offsetHeight
|
|
}));
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
|
|
</html> |