Agent Zero AI framework
images, image viewer
frdelcc834d3b36b4
diff --git a/webui/components/modals/image-viewer/image-viewer-store.js b/webui/components/modals/image-viewer/image-viewer-store.jsindex 3b6685769..7c3f10b77 100644--- a/webui/components/modals/image-viewer/image-viewer-store.js+++ b/webui/components/modals/image-viewer/image-viewer-store.js@@ -11,6 +11,23 @@ const model = {refreshInterval: 0,activeIntervalId: null,closePromise: null,++ // Image dimensions+ naturalWidth: 0,+ naturalHeight: 0,+ baseScale: 1,++ // Pan state+ panX: 0,+ panY: 0,+ isDragging: false,+ dragStartX: 0,+ dragStartY: 0,+ dragStartPanX: 0,+ dragStartPanY: 0,+ activePointerId: null,+ windowDragMoveHandler: null,+ windowDragUpHandler: null,/*** Open image viewer modal@@ -129,31 +146,163 @@ const model = {this.imageError = false;this.zoomLevel = 1;this.refreshInterval = 0;+ this.naturalWidth = 0;+ this.naturalHeight = 0;+ this.baseScale = 1;+ this.panX = 0;+ this.panY = 0;+ this.isDragging = false;+ this.activePointerId = null;+ this.removeWindowDragListeners();+ },++ onImageLoad(event) {+ const img = event.target;+ this.naturalWidth = img.naturalWidth;+ this.naturalHeight = img.naturalHeight;+ this.imageLoaded = true;+ this.zoomLevel = 1;+ this.panX = 0;+ this.panY = 0;+ // Reset any previous transform+ img.classList.remove('zoomed');+ img.style.width = '';+ img.style.height = '';+ img.style.transform = '';+ },++ // Drag/pan methods+ startDrag(event) {+ // Pointer events: mouse (button 0) or touch/pen (button can be -1/undefined)+ if (typeof event.button === 'number' && event.button !== 0) return;+ event.preventDefault();++ this.isDragging = true;+ this.activePointerId = typeof event.pointerId === 'number' ? event.pointerId : null;+ this.dragStartX = event.clientX;+ this.dragStartY = event.clientY;+ this.dragStartPanX = this.panX;+ this.dragStartPanY = this.panY;++ const canvas = document.querySelector('.image-canvas');+ if (canvas && this.activePointerId !== null && typeof canvas.setPointerCapture === 'function') {+ try {+ canvas.setPointerCapture(this.activePointerId);+ } catch (e) {+ // ignore+ }+ }++ this.addWindowDragListeners();+ },++ onDrag(event) {+ if (!this.isDragging) return;+ if (this.activePointerId !== null && typeof event.pointerId === 'number' && event.pointerId !== this.activePointerId) {+ return;+ }+ event.preventDefault();+ const dx = event.clientX - this.dragStartX;+ const dy = event.clientY - this.dragStartY;+ this.panX = this.dragStartPanX + dx;+ this.panY = this.dragStartPanY + dy;+ this.updateImageTransform();+ },++ endDrag() {+ if (!this.isDragging) return;+ this.isDragging = false;+ this.activePointerId = null;+ this.removeWindowDragListeners();+ },++ addWindowDragListeners() {+ this.removeWindowDragListeners();++ this.windowDragMoveHandler = (e) => this.onDrag(e);+ this.windowDragUpHandler = () => this.endDrag();++ window.addEventListener('pointermove', this.windowDragMoveHandler, { passive: false });+ window.addEventListener('pointerup', this.windowDragUpHandler, { passive: false });+ window.addEventListener('pointercancel', this.windowDragUpHandler, { passive: false });+ },++ removeWindowDragListeners() {+ if (this.windowDragMoveHandler) {+ window.removeEventListener('pointermove', this.windowDragMoveHandler);+ this.windowDragMoveHandler = null;+ }+ if (this.windowDragUpHandler) {+ window.removeEventListener('pointerup', this.windowDragUpHandler);+ window.removeEventListener('pointercancel', this.windowDragUpHandler);+ this.windowDragUpHandler = null;+ }+ },++ clampPan(containerWidth, containerHeight, displayWidth, displayHeight) {+ const margin = 25;++ const limitX = Math.max(0, (containerWidth + displayWidth) / 2 - margin);+ const limitY = Math.max(0, (containerHeight + displayHeight) / 2 - margin);++ this.panX = Math.max(-limitX, Math.min(limitX, this.panX));+ this.panY = Math.max(-limitY, Math.min(limitY, this.panY));+ },++ getDisplaySize(containerWidth, containerHeight) {+ // Fit in both dimensions without upscaling+ const scaleX = containerWidth / this.naturalWidth;+ const scaleY = containerHeight / this.naturalHeight;+ const fitScale = Math.min(scaleX, scaleY, 1);+ const scale = fitScale * this.zoomLevel;++ return {+ width: this.naturalWidth * scale,+ height: this.naturalHeight * scale,+ };},// Zoom controlszoomIn() {- this.zoomLevel = Math.min(this.zoomLevel * 1.2, 5); // Max 5x zoom- this.updateImageZoom();+ this.zoomLevel = Math.min(this.zoomLevel * 1.25, 10);+ this.updateImageTransform();},zoomOut() {- this.zoomLevel = Math.max(this.zoomLevel / 1.2, 0.1); // Min 0.1x zoom- this.updateImageZoom();+ this.zoomLevel = Math.max(this.zoomLevel / 1.25, 0.1);+ this.updateImageTransform();},resetZoom() {this.zoomLevel = 1;- this.updateImageZoom();- },-- updateImageZoom() {- const img = document.querySelector(".modal-image");+ this.panX = 0;+ this.panY = 0;+ const img = document.querySelector('.modal-image');if (img) {- img.style.transform = `scale(${this.zoomLevel})`;+ img.classList.remove('zoomed');+ img.style.width = '';+ img.style.height = '';+ img.style.transform = '';}},+ updateImageTransform() {+ const img = document.querySelector('.modal-image');+ const wrapper = document.querySelector('.image-canvas');+ if (!img || !wrapper || !this.naturalWidth || !this.naturalHeight) return;++ const containerWidth = wrapper.clientWidth;+ const containerHeight = wrapper.clientHeight;++ const displaySize = this.getDisplaySize(containerWidth, containerHeight);+ this.clampPan(containerWidth, containerHeight, displaySize.width, displaySize.height);++ img.classList.add('zoomed');+ img.style.width = `${displaySize.width}px`;+ img.style.height = `${displaySize.height}px`;+ img.style.transform = `translate(${this.panX}px, ${this.panY}px)`;+ },+// Utility methodsaddTimestamp(url) {try {diff --git a/webui/components/modals/image-viewer/image-viewer.html b/webui/components/modals/image-viewer/image-viewer.htmlindex a554a60d8..228e4b6ed 100644--- a/webui/components/modals/image-viewer/image-viewer.html+++ b/webui/components/modals/image-viewer/image-viewer.html@@ -12,15 +12,21 @@<div x-data><template x-if="$store.imageViewer"><div id="image-viewer-wrapper" class="image-modal-container">- <!-- Image display area -->- <div class="image-display-wrapper">+ <!-- Image canvas for panning -->+ <div class="image-canvas"+ @pointerdown="$store.imageViewer.startDrag($event)"+ @pointermove="$store.imageViewer.onDrag($event)"+ @pointerup="$store.imageViewer.endDrag()"+ @pointercancel="$store.imageViewer.endDrag()"><imgx-show="$store.imageViewer.currentImageUrl":src="$store.imageViewer.currentImageUrl":alt="$store.imageViewer.currentImageName || 'Image'"class="modal-image"- @load="$store.imageViewer.imageLoaded = true"+ :class="{ 'dragging': $store.imageViewer.isDragging }"+ @load="$store.imageViewer.onImageLoad($event)"@error="$store.imageViewer.imageError = true"+ draggable="false"/><!-- Loading indicator -->@@ -35,11 +41,17 @@</div></div>- <!-- Simple zoom controls -->+ <!-- Fixed zoom controls - OUTSIDE the canvas --><div class="zoom-controls">- <button @click="$store.imageViewer.zoomOut()" class="zoom-btn" title="Zoom Out">−</button>- <button @click="$store.imageViewer.resetZoom()" class="zoom-btn" title="Reset">⌂</button>- <button @click="$store.imageViewer.zoomIn()" class="zoom-btn" title="Zoom In">+</button>+ <button type="button" @click="$store.imageViewer.zoomOut()" class="button zoom-btn">+ <span class="icon material-symbols-outlined">zoom_out</span>+ </button>+ <button type="button" @click="$store.imageViewer.resetZoom()" class="button zoom-btn">+ <span class="icon material-symbols-outlined">home</span>+ </button>+ <button type="button" @click="$store.imageViewer.zoomIn()" class="button zoom-btn">+ <span class="icon material-symbols-outlined">zoom_in</span>+ </button></div></div></template>@@ -48,61 +60,46 @@<style>.image-modal-container {width: 100%;- height: 100%;+ height: 70vh;+ position: relative;+ background: var(--color-bg-secondary);display: flex;- flex-direction: column;align-items: center;justify-content: center;- position: relative;- background: var(--color-bg-secondary);}- .image-display-wrapper {- flex: 1;+ .image-canvas {+ width: 100%;+ height: 100%;display: flex;align-items: center;justify-content: center;- overflow: auto;- width: 100%;- height: 100%;- position: relative;- }-- /* Unified scrollbar styling for modal content */- .image-display-wrapper::-webkit-scrollbar {- width: 6px;- height: 6px;- }-- .image-display-wrapper::-webkit-scrollbar-track {- background: transparent;- margin: 4px 0;- border-radius: 6px;- }-- .image-display-wrapper::-webkit-scrollbar-thumb {- background-color: rgba(155, 155, 155, 0.5);- border-radius: 6px;- transition: background-color 0.2s ease;+ cursor: grab;+ overflow: hidden;+ touch-action: none;+ background: repeating-linear-gradient(45deg, var(--color-panel) 0 10px, var(--color-chat-background) 10px 20px);}- .image-display-wrapper::-webkit-scrollbar-thumb:hover {- background-color: rgba(155, 155, 155, 0.7);+ .image-canvas:active {+ cursor: grabbing;}.modal-image {max-width: 100%;max-height: 100%;object-fit: contain;- transition: transform 0.2s ease;- cursor: grab;+ user-select: none;+ -webkit-user-drag: none;+ pointer-events: none;}- .modal-image:active {- cursor: grabbing;+ .modal-image.zoomed {+ max-width: none;+ max-height: none;}.loading-indicator, .error-indicator {+ position: absolute;display: flex;flex-direction: column;align-items: center;@@ -136,6 +133,7 @@padding: 6px;border-radius: 12px;backdrop-filter: blur(5px);+ z-index: 100;}.zoom-btn {@@ -158,11 +156,6 @@.zoom-btn:hover {background: rgba(255, 255, 255, 0.15);}-- /* Dark mode adjustments */- .dark-mode .image-modal-container {- background: var(--color-bg-secondary);- }</style></body>diff --git a/webui/css/messages.css b/webui/css/messages.cssindex dfd620dc1..313370584 100644--- a/webui/css/messages.css+++ b/webui/css/messages.css@@ -643,10 +643,18 @@}.message-agent-response .msg-content img {- max-width: 100%;- max-height: 100em;+ margin: var(--spacing-xs);+ max-width: 25em;+ max-height: 25em;+ border-radius: var(--border-radius);+ background: repeating-linear-gradient(45deg, var(--color-panel) 0 10px, var(--color-chat-background) 10px 20px);}+.message-agent-response .msg-content .message-markdown-image-wrap img:hover{+ transform: translateY(-2px);+}++.msg-content h1 {font-size: 1.25em;font-weight: 800;diff --git a/webui/index.css b/webui/index.cssindex 976eefffb..b9a0b445d 100644--- a/webui/index.css+++ b/webui/index.css@@ -700,7 +700,7 @@ h4 {width: 100%;height: 100%;object-fit: cover;- border-radius: 10px;+ border-radius: var(--border-radius);background: repeating-linear-gradient(45deg, var(--color-panel) 0 10px, var(--color-chat-background) 10px 20px);}diff --git a/webui/js/messages.js b/webui/js/messages.jsindex e61c74876..1b1f426cc 100644--- a/webui/js/messages.js+++ b/webui/js/messages.js@@ -1235,6 +1235,20 @@ function adjustMarkdownRender(element) {el.parentNode.insertBefore(wrapper, el);wrapper.appendChild(el);});++ // find all images+ const images = element.querySelectorAll("img");++ // wrap each image in <a>+ images.forEach((img) => {+ if (img.parentNode?.tagName === "A") return;+ const link = document.createElement("a");+ link.className = "message-markdown-image-wrap";+ link.href = img.src;+ img.parentNode.insertBefore(link, img);+ link.appendChild(img);+ link.onclick = (e) => (e.preventDefault(), imageViewerStore.open(img.src, { name: img.alt || "Image" }));+ });}class Scroller {