|
| 1 | +<script lang="ts"> |
| 2 | + import { imageStore } from '../stores/imageStore'; |
| 3 | +
|
| 4 | + $: hasImage = !!$imageStore.currentImageUrl; |
| 5 | + $: isLoading = $imageStore.isLoading; |
| 6 | +</script> |
| 7 | + |
| 8 | +<figure |
| 9 | + id="hero-stage" |
| 10 | + class="image-stage" |
| 11 | + data-state={hasImage ? 'loaded' : 'empty'} |
| 12 | + class:loading={isLoading} |
| 13 | + aria-hidden={!hasImage} |
| 14 | +> |
| 15 | + {#if $imageStore.currentImageUrl} |
| 16 | + <img |
| 17 | + id="hero-image" |
| 18 | + src={$imageStore.currentImageUrl} |
| 19 | + alt="AI generated visualization" |
| 20 | + loading="lazy" |
| 21 | + decoding="async" |
| 22 | + crossorigin="anonymous" |
| 23 | + /> |
| 24 | + {/if} |
| 25 | + |
| 26 | + {#if isLoading} |
| 27 | + <div class="loading-indicator"> |
| 28 | + <div class="spinner"></div> |
| 29 | + <p>Generating image...</p> |
| 30 | + </div> |
| 31 | + {/if} |
| 32 | + |
| 33 | + {#if $imageStore.error} |
| 34 | + <div class="error-message"> |
| 35 | + {$imageStore.error} |
| 36 | + </div> |
| 37 | + {/if} |
| 38 | +</figure> |
| 39 | + |
| 40 | +<style> |
| 41 | + .image-stage { |
| 42 | + position: relative; |
| 43 | + width: 100%; |
| 44 | + max-width: 800px; |
| 45 | + aspect-ratio: 1; |
| 46 | + margin: 0 auto; |
| 47 | + background: rgba(0, 0, 0, 0.2); |
| 48 | + border-radius: 12px; |
| 49 | + overflow: hidden; |
| 50 | + transition: opacity 0.3s ease; |
| 51 | + } |
| 52 | +
|
| 53 | + .image-stage[data-state="empty"] { |
| 54 | + opacity: 0.5; |
| 55 | + } |
| 56 | +
|
| 57 | + .image-stage[data-state="loaded"] { |
| 58 | + opacity: 1; |
| 59 | + } |
| 60 | +
|
| 61 | + img { |
| 62 | + width: 100%; |
| 63 | + height: 100%; |
| 64 | + object-fit: contain; |
| 65 | + transition: opacity 0.5s ease; |
| 66 | + } |
| 67 | +
|
| 68 | + .loading-indicator { |
| 69 | + position: absolute; |
| 70 | + inset: 0; |
| 71 | + display: flex; |
| 72 | + flex-direction: column; |
| 73 | + align-items: center; |
| 74 | + justify-content: center; |
| 75 | + background: rgba(0, 0, 0, 0.7); |
| 76 | + color: white; |
| 77 | + } |
| 78 | +
|
| 79 | + .spinner { |
| 80 | + width: 48px; |
| 81 | + height: 48px; |
| 82 | + border: 4px solid rgba(255, 255, 255, 0.1); |
| 83 | + border-top-color: rgba(0, 255, 255, 1); |
| 84 | + border-radius: 50%; |
| 85 | + animation: spin 1s linear infinite; |
| 86 | + } |
| 87 | +
|
| 88 | + @keyframes spin { |
| 89 | + to { |
| 90 | + transform: rotate(360deg); |
| 91 | + } |
| 92 | + } |
| 93 | +
|
| 94 | + .error-message { |
| 95 | + position: absolute; |
| 96 | + bottom: 20px; |
| 97 | + left: 50%; |
| 98 | + transform: translateX(-50%); |
| 99 | + background: rgba(255, 0, 0, 0.9); |
| 100 | + color: white; |
| 101 | + padding: 12px 24px; |
| 102 | + border-radius: 8px; |
| 103 | + } |
| 104 | +</style> |
0 commit comments