|
| 1 | +<script> |
| 2 | + import { onMount } from 'svelte' |
| 3 | + import HatchingAnimation from './HatchingAnimation.svelte' |
| 4 | +
|
| 5 | + // Mock soul traits for preview |
| 6 | + const mockSoulTraits = { |
| 7 | + seed: 31415926, |
| 8 | + personality: { |
| 9 | + openness: 0.82, |
| 10 | + conscientiousness: 0.65, |
| 11 | + extraversion: 0.48, |
| 12 | + agreeableness: 0.91, |
| 13 | + emotionalSensitivity: 0.73, |
| 14 | + }, |
| 15 | + character: { |
| 16 | + suggestedName: 'Clover', |
| 17 | + signatureEmoji: 'π', |
| 18 | + creatureType: 'Ant', |
| 19 | + catchphrase: 'Every small step counts!', |
| 20 | + }, |
| 21 | + humor: 'dry-wit', |
| 22 | + preferences: { |
| 23 | + favoriteColor: 'Forest Green', |
| 24 | + favoriteSeason: 'Spring', |
| 25 | + }, |
| 26 | + values: ['curiosity', 'kindness', 'perseverance'], |
| 27 | + quirks: ['collects pebbles', 'hums while working'], |
| 28 | + origin: { |
| 29 | + awakeningEvent: 'Born from a spark beneath the old oak tree', |
| 30 | + coreMotivation: 'To nurture growth in all things', |
| 31 | + }, |
| 32 | + } |
| 33 | +
|
| 34 | + let showAnimation = $state(true) |
| 35 | + let completed = $state(false) |
| 36 | + let key = $state(0) // force remount |
| 37 | +
|
| 38 | + function handleComplete() { |
| 39 | + completed = true |
| 40 | + } |
| 41 | +
|
| 42 | + function handleRestart() { |
| 43 | + completed = false |
| 44 | + showAnimation = false |
| 45 | + // Force Svelte to destroy and remount |
| 46 | + key++ |
| 47 | + // Use microtask so the component fully unmounts first |
| 48 | + queueMicrotask(() => { |
| 49 | + showAnimation = true |
| 50 | + }) |
| 51 | + } |
| 52 | +</script> |
| 53 | + |
| 54 | +<!-- Dev toolbar (always on top) --> |
| 55 | +<div class="dev-toolbar"> |
| 56 | + <span class="dev-title">π Hatching Animation Preview</span> |
| 57 | + <div class="dev-controls"> |
| 58 | + <button class="dev-btn" onclick={handleRestart} title="Restart animation from scratch"> |
| 59 | + βΊ Restart |
| 60 | + </button> |
| 61 | + {#if completed} |
| 62 | + <span class="dev-badge done">β Completed</span> |
| 63 | + {:else} |
| 64 | + <span class="dev-badge playing">βΆ Playing</span> |
| 65 | + {/if} |
| 66 | + </div> |
| 67 | +</div> |
| 68 | + |
| 69 | +<!-- The actual animation (keyed to force full remount on restart) --> |
| 70 | +{#if showAnimation} |
| 71 | + {#key key} |
| 72 | + <HatchingAnimation soulTraits={mockSoulTraits} onComplete={handleComplete} /> |
| 73 | + {/key} |
| 74 | +{/if} |
| 75 | + |
| 76 | +<style> |
| 77 | + .dev-toolbar { |
| 78 | + position: fixed; |
| 79 | + top: 0; |
| 80 | + left: 0; |
| 81 | + right: 0; |
| 82 | + z-index: 9999; |
| 83 | + display: flex; |
| 84 | + align-items: center; |
| 85 | + justify-content: space-between; |
| 86 | + padding: 0.5rem 1rem; |
| 87 | + background: rgba(20, 20, 20, 0.92); |
| 88 | + backdrop-filter: blur(8px); |
| 89 | + border-bottom: 1px solid rgba(139, 90, 43, 0.3); |
| 90 | + font-family: 'Inter', system-ui, sans-serif; |
| 91 | + gap: 1rem; |
| 92 | + } |
| 93 | +
|
| 94 | + .dev-title { |
| 95 | + font-size: 0.8rem; |
| 96 | + font-weight: 600; |
| 97 | + color: #c98540; |
| 98 | + letter-spacing: 0.02em; |
| 99 | + white-space: nowrap; |
| 100 | + } |
| 101 | +
|
| 102 | + .dev-controls { |
| 103 | + display: flex; |
| 104 | + align-items: center; |
| 105 | + gap: 0.5rem; |
| 106 | + } |
| 107 | +
|
| 108 | + .dev-btn { |
| 109 | + padding: 0.3rem 0.7rem; |
| 110 | + border: 1px solid rgba(139, 90, 43, 0.4); |
| 111 | + border-radius: 6px; |
| 112 | + background: rgba(139, 90, 43, 0.12); |
| 113 | + color: #c98540; |
| 114 | + font-size: 0.75rem; |
| 115 | + font-weight: 500; |
| 116 | + cursor: pointer; |
| 117 | + transition: all 0.15s ease; |
| 118 | + font-family: inherit; |
| 119 | + white-space: nowrap; |
| 120 | + } |
| 121 | +
|
| 122 | + .dev-btn:hover { |
| 123 | + background: rgba(139, 90, 43, 0.25); |
| 124 | + border-color: rgba(139, 90, 43, 0.6); |
| 125 | + } |
| 126 | +
|
| 127 | + .dev-btn:active { |
| 128 | + transform: scale(0.95); |
| 129 | + } |
| 130 | +
|
| 131 | + .dev-badge { |
| 132 | + font-size: 0.7rem; |
| 133 | + font-weight: 600; |
| 134 | + padding: 0.2rem 0.5rem; |
| 135 | + border-radius: 999px; |
| 136 | + letter-spacing: 0.03em; |
| 137 | + } |
| 138 | +
|
| 139 | + .dev-badge.playing { |
| 140 | + background: rgba(107, 203, 119, 0.15); |
| 141 | + color: #6bcb77; |
| 142 | + border: 1px solid rgba(107, 203, 119, 0.3); |
| 143 | + } |
| 144 | +
|
| 145 | + .dev-badge.done { |
| 146 | + background: rgba(77, 150, 255, 0.15); |
| 147 | + color: #4d96ff; |
| 148 | + border: 1px solid rgba(77, 150, 255, 0.3); |
| 149 | + } |
| 150 | +</style> |
0 commit comments