|
8 | 8 | import { Audio } from "@gradio/audio/shared";
|
9 | 9 | import { Image } from "@gradio/image/shared";
|
10 | 10 | import { Video } from "@gradio/video/shared";
|
| 11 | + import { Clear } from "@gradio/icons"; |
11 | 12 | import type { SelectData, LikeData } from "@gradio/utils";
|
12 | 13 | import { MarkdownCode as Markdown } from "@gradio/markdown";
|
13 | 14 | import { type FileData } from "@gradio/client";
|
|
95 | 96 | div.scrollTo(0, div.scrollHeight);
|
96 | 97 | }
|
97 | 98 | };
|
| 99 | +
|
| 100 | + let image_preview_source: string; |
| 101 | + let image_preview_source_alt: string; |
| 102 | + let is_image_preview_open = false; |
| 103 | + let image_preview_close_button: HTMLButtonElement; |
| 104 | +
|
98 | 105 | afterUpdate(() => {
|
99 | 106 | if (autoscroll) {
|
100 | 107 | scroll();
|
|
104 | 111 | });
|
105 | 112 | });
|
106 | 113 | }
|
| 114 | + div.querySelectorAll("img").forEach((n) => { |
| 115 | + n.addEventListener("click", (e) => { |
| 116 | + const target = e.target as HTMLImageElement; |
| 117 | + if (target) { |
| 118 | + image_preview_source = target.src; |
| 119 | + image_preview_source_alt = target.alt; |
| 120 | + is_image_preview_open = true; |
| 121 | + } |
| 122 | + }); |
| 123 | + }); |
107 | 124 | });
|
108 | 125 |
|
109 | 126 | $: {
|
|
163 | 180 | {#each value as message_pair, i}
|
164 | 181 | {#each message_pair as message, j}
|
165 | 182 | {#if message !== null}
|
| 183 | + {#if is_image_preview_open} |
| 184 | + <div class="image-preview"> |
| 185 | + <img |
| 186 | + src={image_preview_source} |
| 187 | + alt={image_preview_source_alt} |
| 188 | + /> |
| 189 | + <button |
| 190 | + bind:this={image_preview_close_button} |
| 191 | + class="image-preview-close-button" |
| 192 | + on:click={() => { |
| 193 | + is_image_preview_open = false; |
| 194 | + }}><Clear /></button |
| 195 | + > |
| 196 | + </div> |
| 197 | + {/if} |
166 | 198 | <div class="message-row {layout} {j == 0 ? 'user-row' : 'bot-row'}">
|
167 | 199 | {#if avatar_images[j] !== null}
|
168 | 200 | <div class="avatar-container">
|
|
554 | 586 | height: 100%;
|
555 | 587 | color: var(--body-text-color);
|
556 | 588 | }
|
| 589 | +
|
| 590 | + /* Image preview */ |
| 591 | + .message :global(.preview) { |
| 592 | + object-fit: contain; |
| 593 | + width: 95%; |
| 594 | + max-height: 93%; |
| 595 | + } |
| 596 | + .image-preview { |
| 597 | + position: absolute; |
| 598 | + z-index: 999; |
| 599 | + left: 0; |
| 600 | + top: 0; |
| 601 | + width: 100%; |
| 602 | + height: 100%; |
| 603 | + overflow: auto; |
| 604 | + background-color: rgba(0, 0, 0, 0.9); |
| 605 | + } |
| 606 | + .image-preview :global(img) { |
| 607 | + width: 100%; |
| 608 | + height: 100%; |
| 609 | + object-fit: contain; |
| 610 | + } |
| 611 | + .image-preview :global(svg) { |
| 612 | + stroke: white; |
| 613 | + } |
| 614 | + .image-preview-close-button { |
| 615 | + position: absolute; |
| 616 | + top: 10px; |
| 617 | + right: 10px; |
| 618 | + background: none; |
| 619 | + border: none; |
| 620 | + font-size: 1.5em; |
| 621 | + cursor: pointer; |
| 622 | + height: 30px; |
| 623 | + width: 30px; |
| 624 | + padding: 3px; |
| 625 | + background: var(--bg-color); |
| 626 | + box-shadow: var(--shadow-drop); |
| 627 | + border: 1px solid var(--button-secondary-border-color); |
| 628 | + border-radius: var(--radius-lg); |
| 629 | + } |
557 | 630 | </style>
|
0 commit comments