BlackRiver AI commited on
Commit ·
c18a8a5
0
Parent(s):
Launch BlackRiver Gemma 4 multimodal WebGPU Space
Browse files- .gitattributes +7 -0
- README.md +54 -0
- index.html +1758 -0
- landing.js +717 -0
- transformers-gemma4.js +195 -0
.gitattributes
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.gguf filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: BlackRiver Gemma 4 Multimodal
|
| 3 |
+
emoji: 🌊
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: indigo
|
| 6 |
+
sdk: static
|
| 7 |
+
app_file: index.html
|
| 8 |
+
pinned: false
|
| 9 |
+
short_description: Gemma 4 E2B/E4B with vision, audio and text running locally on WebGPU.
|
| 10 |
+
models:
|
| 11 |
+
- onnx-community/gemma-4-E2B-it-ONNX
|
| 12 |
+
- onnx-community/gemma-4-E4B-it-ONNX
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# BlackRiver AI · Gemma 4 Multimodal
|
| 16 |
+
|
| 17 |
+
A standalone BlackRiver AI implementation of Gemma 4 for fully local browser inference with WebGPU.
|
| 18 |
+
|
| 19 |
+
## Capabilities
|
| 20 |
+
|
| 21 |
+
- Gemma 4 E2B and E4B model selection
|
| 22 |
+
- Text conversation
|
| 23 |
+
- Image understanding
|
| 24 |
+
- Audio recording and transcription/instruction input
|
| 25 |
+
- Streaming generation
|
| 26 |
+
- Local browser cache for model weights
|
| 27 |
+
- Rendered WebGPU kernel inspection
|
| 28 |
+
- No inference server: prompts and media stay on the user's device
|
| 29 |
+
|
| 30 |
+
The first model load downloads the selected ONNX weights from Hugging Face. A WebGPU-capable browser and sufficient GPU memory are required. E4B requires more memory than E2B.
|
| 31 |
+
|
| 32 |
+
## BlackRiver AI implementation
|
| 33 |
+
|
| 34 |
+
This Space packages the models into a unified BlackRiver interface and adds the multimodal browser workflow used here, including image attachment, microphone capture, 16 kHz audio preparation, E2B/E4B selection and media-history handling for reliable repeated generations.
|
| 35 |
+
|
| 36 |
+
BlackRiver AI does not claim authorship of the underlying models or the original WebGPU research work.
|
| 37 |
+
|
| 38 |
+
## Credits
|
| 39 |
+
|
| 40 |
+
- **Gemma 4 models:** Google — [Gemma 4 E2B](https://huggingface.co/google/gemma-4-E2B)
|
| 41 |
+
- **ONNX model conversions:** [ONNX Community E2B](https://huggingface.co/onnx-community/gemma-4-E2B-it-ONNX) and [E4B](https://huggingface.co/onnx-community/gemma-4-E4B-it-ONNX)
|
| 42 |
+
- **Browser runtime:** [Transformers.js](https://huggingface.co/docs/transformers.js)
|
| 43 |
+
- **Original WebGPU demo foundation:** [WebML Community](https://huggingface.co/spaces/webml-community/gemma-4-webgpu-kernels)
|
| 44 |
+
- **Original optimized WebGPU kernels:** Fable 5, as credited by the upstream demo
|
| 45 |
+
|
| 46 |
+
Model use remains subject to the licenses and terms published in the respective model repositories.
|
| 47 |
+
|
| 48 |
+
## Files
|
| 49 |
+
|
| 50 |
+
- `index.html` — complete BlackRiver multimodal interface
|
| 51 |
+
- `transformers-gemma4.js` — Gemma 4 E2B/E4B Transformers.js adapter
|
| 52 |
+
- `landing.js` — landing-page WebGL background
|
| 53 |
+
|
| 54 |
+
No build step or server backend is required.
|
index.html
ADDED
|
@@ -0,0 +1,1758 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1, viewport-fit=cover" />
|
| 6 |
+
<meta name="color-scheme" content="dark" />
|
| 7 |
+
<title>BlackRiver AI · Gemma 4 Multimodal</title>
|
| 8 |
+
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Crect x='7' y='7' width='50' height='50' rx='15' fill='none' stroke='%238DB4FF' stroke-width='3'/%3E%3Cpath d='M16 39.5C25 25 35.5 43 47 19.5' stroke='%23F7F9FC' stroke-width='4.6' stroke-linecap='round' fill='none'/%3E%3Cpath d='M16 28.5C25 14 36 32 47 8.5' stroke='%238DB4FF' stroke-width='3.1' stroke-linecap='round' fill='none' opacity='.8'/%3E%3C/svg%3E">
|
| 9 |
+
<meta name="description" content="BlackRiver AI implementation of Gemma 4 E2B and E4B — vision, audio and text running locally with WebGPU." />
|
| 10 |
+
<meta property="og:title" content="BlackRiver AI · Gemma 4 Multimodal" />
|
| 11 |
+
<meta property="og:description" content="Run Gemma 4 E2B or E4B locally with vision, audio and text input through WebGPU." />
|
| 12 |
+
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 13 |
+
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 14 |
+
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&family=Geist+Mono:wght@400;500&display=swap" rel="stylesheet">
|
| 15 |
+
<script type="importmap">
|
| 16 |
+
{
|
| 17 |
+
"imports": {
|
| 18 |
+
"three": "https://cdn.jsdelivr.net/npm/three@0.169.0/build/three.module.js",
|
| 19 |
+
"three/examples/jsm/": "https://cdn.jsdelivr.net/npm/three@0.169.0/examples/jsm/"
|
| 20 |
+
}
|
| 21 |
+
}
|
| 22 |
+
</script>
|
| 23 |
+
<style>
|
| 24 |
+
:root {
|
| 25 |
+
--bg: #020203;
|
| 26 |
+
--t1: rgba(255, 255, 255, 0.92);
|
| 27 |
+
--t2: rgba(255, 255, 255, 0.55);
|
| 28 |
+
--t3: rgba(255, 255, 255, 0.32);
|
| 29 |
+
--t4: rgba(255, 255, 255, 0.20);
|
| 30 |
+
--line: rgba(255, 255, 255, 0.08);
|
| 31 |
+
--line-soft: rgba(255, 255, 255, 0.06);
|
| 32 |
+
--panel: rgba(255, 255, 255, 0.03);
|
| 33 |
+
--panel-hover: rgba(255, 255, 255, 0.06);
|
| 34 |
+
--ok: #64ffa0;
|
| 35 |
+
--warn: #ffcd6b;
|
| 36 |
+
--danger: #ff7a6b;
|
| 37 |
+
--user-bubble: rgba(255, 255, 255, 0.065);
|
| 38 |
+
--display: "Instrument Serif", Georgia, "Times New Roman", serif;
|
| 39 |
+
--body: "Geist", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
| 40 |
+
--mono: "Geist Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
|
| 41 |
+
--maxw: 820px;
|
| 42 |
+
}
|
| 43 |
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
| 44 |
+
html { height: 100%; }
|
| 45 |
+
body {
|
| 46 |
+
background: var(--bg);
|
| 47 |
+
color: var(--t1);
|
| 48 |
+
font-family: var(--body);
|
| 49 |
+
font-size: 16px;
|
| 50 |
+
font-weight: 400;
|
| 51 |
+
line-height: 1.6;
|
| 52 |
+
-webkit-font-smoothing: antialiased;
|
| 53 |
+
height: 100dvh;
|
| 54 |
+
overflow-x: hidden;
|
| 55 |
+
overflow-y: scroll;
|
| 56 |
+
scroll-behavior: smooth;
|
| 57 |
+
}
|
| 58 |
+
button, textarea, input { font: inherit; color: inherit; }
|
| 59 |
+
button { appearance: none; background: none; border: 0; cursor: pointer; }
|
| 60 |
+
a { color: inherit; text-decoration: none; }
|
| 61 |
+
::selection { background: rgba(255, 255, 255, 0.18); }
|
| 62 |
+
body::-webkit-scrollbar { width: 0; }
|
| 63 |
+
.screen { min-height: 100dvh; position: relative; width: 100%; }
|
| 64 |
+
|
| 65 |
+
/* LANDING */
|
| 66 |
+
#landing {
|
| 67 |
+
display: flex;
|
| 68 |
+
flex-direction: column;
|
| 69 |
+
overflow: hidden;
|
| 70 |
+
}
|
| 71 |
+
#crt-frame {
|
| 72 |
+
position: absolute;
|
| 73 |
+
inset: 0;
|
| 74 |
+
z-index: 0;
|
| 75 |
+
overflow: hidden;
|
| 76 |
+
pointer-events: none;
|
| 77 |
+
opacity: 0;
|
| 78 |
+
transition: opacity 2.4s cubic-bezier(0.25, 0.1, 0.25, 1) 0.6s;
|
| 79 |
+
}
|
| 80 |
+
#crt-frame.visible { opacity: 1; }
|
| 81 |
+
#crt-frame canvas { display: block; width: 100% !important; height: 100% !important; pointer-events: none; }
|
| 82 |
+
.hero-fade {
|
| 83 |
+
position: absolute;
|
| 84 |
+
bottom: 0; left: 0;
|
| 85 |
+
width: 100%; height: 68%;
|
| 86 |
+
background: linear-gradient(to top, var(--bg) 0%, var(--bg) 14%, rgba(2, 2, 3, 0.55) 52%, transparent 100%);
|
| 87 |
+
z-index: 1;
|
| 88 |
+
pointer-events: none;
|
| 89 |
+
opacity: 0;
|
| 90 |
+
transition: opacity 2s ease 1s;
|
| 91 |
+
}
|
| 92 |
+
.hero-fade.in { opacity: 1; }
|
| 93 |
+
.hero-overlay {
|
| 94 |
+
position: relative;
|
| 95 |
+
z-index: 2;
|
| 96 |
+
flex: 1;
|
| 97 |
+
display: flex;
|
| 98 |
+
flex-direction: column;
|
| 99 |
+
pointer-events: none;
|
| 100 |
+
min-height: 100dvh;
|
| 101 |
+
}
|
| 102 |
+
.brand-name {
|
| 103 |
+
font-family: var(--mono);
|
| 104 |
+
font-size: 12px;
|
| 105 |
+
font-weight: 500;
|
| 106 |
+
letter-spacing: 0.22em;
|
| 107 |
+
text-transform: uppercase;
|
| 108 |
+
color: var(--t1);
|
| 109 |
+
}
|
| 110 |
+
.hero-content {
|
| 111 |
+
flex: 1;
|
| 112 |
+
display: flex;
|
| 113 |
+
flex-direction: column;
|
| 114 |
+
justify-content: flex-end;
|
| 115 |
+
padding: 0 48px 18px;
|
| 116 |
+
pointer-events: none;
|
| 117 |
+
}
|
| 118 |
+
.eyebrow {
|
| 119 |
+
display: inline-flex;
|
| 120 |
+
align-items: center;
|
| 121 |
+
gap: 10px;
|
| 122 |
+
width: fit-content;
|
| 123 |
+
font-family: var(--mono);
|
| 124 |
+
font-size: 11px;
|
| 125 |
+
letter-spacing: 0.2em;
|
| 126 |
+
text-transform: uppercase;
|
| 127 |
+
color: var(--t3);
|
| 128 |
+
margin-bottom: 22px;
|
| 129 |
+
text-shadow: 0 2px 16px var(--bg);
|
| 130 |
+
}
|
| 131 |
+
.eyebrow::before {
|
| 132 |
+
content: "";
|
| 133 |
+
flex-shrink: 0;
|
| 134 |
+
width: 7px; height: 7px; border-radius: 50%;
|
| 135 |
+
background: var(--ok);
|
| 136 |
+
box-shadow: 0 0 12px rgba(100, 255, 160, 0.5);
|
| 137 |
+
animation: statusPulse 2.4s ease-in-out infinite;
|
| 138 |
+
}
|
| 139 |
+
.hero-h1 {
|
| 140 |
+
font-family: var(--display);
|
| 141 |
+
font-size: clamp(44px, 7.6vw, 100px);
|
| 142 |
+
font-weight: 400;
|
| 143 |
+
line-height: 0.98;
|
| 144 |
+
letter-spacing: -0.015em;
|
| 145 |
+
color: #fff;
|
| 146 |
+
margin-bottom: 30px;
|
| 147 |
+
max-width: 26ch;
|
| 148 |
+
text-shadow: 0 3px 40px var(--bg), 0 1px 14px rgba(2, 2, 3, 0.85);
|
| 149 |
+
}
|
| 150 |
+
.hero-h1 .thin { color: var(--t3); }
|
| 151 |
+
.hero-row {
|
| 152 |
+
display: flex;
|
| 153 |
+
align-items: flex-end;
|
| 154 |
+
justify-content: space-between;
|
| 155 |
+
gap: 56px;
|
| 156 |
+
}
|
| 157 |
+
.hero-main { display: flex; flex-direction: column; min-width: 0; }
|
| 158 |
+
.hero-sub {
|
| 159 |
+
font-size: 15px;
|
| 160 |
+
font-weight: 300;
|
| 161 |
+
line-height: 1.7;
|
| 162 |
+
color: var(--t2);
|
| 163 |
+
max-width: 52ch;
|
| 164 |
+
text-shadow: 0 2px 16px var(--bg), 0 1px 30px var(--bg);
|
| 165 |
+
margin-bottom: 26px;
|
| 166 |
+
}
|
| 167 |
+
.hero-sub b { color: var(--t1); font-weight: 500; }
|
| 168 |
+
.hero-stats { display: flex; flex-wrap: wrap; gap: 36px; }
|
| 169 |
+
.stat { display: flex; flex-direction: column; gap: 5px; }
|
| 170 |
+
.stat-val {
|
| 171 |
+
font-family: var(--display);
|
| 172 |
+
font-size: 30px;
|
| 173 |
+
font-weight: 400;
|
| 174 |
+
letter-spacing: -0.01em;
|
| 175 |
+
color: var(--t1);
|
| 176 |
+
line-height: 1;
|
| 177 |
+
text-shadow: 0 2px 16px var(--bg);
|
| 178 |
+
}
|
| 179 |
+
.stat-label {
|
| 180 |
+
font-family: var(--mono);
|
| 181 |
+
font-size: 10.5px;
|
| 182 |
+
letter-spacing: 0.12em;
|
| 183 |
+
text-transform: uppercase;
|
| 184 |
+
color: var(--t3);
|
| 185 |
+
}
|
| 186 |
+
.hero-side {
|
| 187 |
+
display: flex;
|
| 188 |
+
flex-direction: column;
|
| 189 |
+
align-items: flex-end;
|
| 190 |
+
gap: 18px;
|
| 191 |
+
flex-shrink: 0;
|
| 192 |
+
text-align: right;
|
| 193 |
+
}
|
| 194 |
+
.hero-actions {
|
| 195 |
+
display: flex;
|
| 196 |
+
align-items: center;
|
| 197 |
+
gap: 12px;
|
| 198 |
+
pointer-events: auto;
|
| 199 |
+
}
|
| 200 |
+
.btn-primary {
|
| 201 |
+
position: relative;
|
| 202 |
+
display: inline-flex;
|
| 203 |
+
align-items: center;
|
| 204 |
+
gap: 10px;
|
| 205 |
+
padding: 14px 28px;
|
| 206 |
+
color: #000;
|
| 207 |
+
font-size: 13.5px;
|
| 208 |
+
font-weight: 500;
|
| 209 |
+
letter-spacing: 0.01em;
|
| 210 |
+
border-radius: 100px;
|
| 211 |
+
border: 1px solid #fff;
|
| 212 |
+
white-space: nowrap;
|
| 213 |
+
overflow: hidden;
|
| 214 |
+
isolation: isolate;
|
| 215 |
+
transition: opacity 0.2s ease;
|
| 216 |
+
}
|
| 217 |
+
.btn-primary::before {
|
| 218 |
+
content: "";
|
| 219 |
+
position: absolute;
|
| 220 |
+
inset: 0;
|
| 221 |
+
background: #fff;
|
| 222 |
+
border-radius: inherit;
|
| 223 |
+
transform: scaleX(1);
|
| 224 |
+
transform-origin: left center;
|
| 225 |
+
transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
|
| 226 |
+
z-index: -1;
|
| 227 |
+
}
|
| 228 |
+
.btn-primary:hover:not(:disabled)::before { transform: scaleX(0); transform-origin: right center; }
|
| 229 |
+
.btn-primary:hover:not(:disabled) { color: #fff; }
|
| 230 |
+
.btn-primary svg { width: 14px; height: 14px; }
|
| 231 |
+
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }
|
| 232 |
+
.btn-secondary {
|
| 233 |
+
display: inline-flex;
|
| 234 |
+
align-items: center;
|
| 235 |
+
gap: 9px;
|
| 236 |
+
padding: 14px 26px;
|
| 237 |
+
color: var(--t2);
|
| 238 |
+
font-size: 13.5px;
|
| 239 |
+
font-weight: 400;
|
| 240 |
+
border-radius: 100px;
|
| 241 |
+
border: 1px solid var(--line);
|
| 242 |
+
white-space: nowrap;
|
| 243 |
+
transition: border-color 0.25s ease, color 0.25s ease;
|
| 244 |
+
}
|
| 245 |
+
.btn-secondary:hover { border-color: rgba(255, 255, 255, 0.4); color: var(--t1); }
|
| 246 |
+
.btn-secondary svg { width: 12px; height: 12px; }
|
| 247 |
+
.hero-foot {
|
| 248 |
+
display: flex;
|
| 249 |
+
flex-direction: column;
|
| 250 |
+
align-items: flex-end;
|
| 251 |
+
gap: 8px;
|
| 252 |
+
pointer-events: auto;
|
| 253 |
+
}
|
| 254 |
+
.kernel-note-cta {
|
| 255 |
+
width: fit-content;
|
| 256 |
+
font-size: 13px;
|
| 257 |
+
font-weight: 400;
|
| 258 |
+
color: var(--t2);
|
| 259 |
+
border-bottom: 1px solid var(--line);
|
| 260 |
+
padding-bottom: 2px;
|
| 261 |
+
transition: color 0.2s ease, border-color 0.2s ease;
|
| 262 |
+
}
|
| 263 |
+
.kernel-note-cta b { color: var(--t1); font-weight: 600; }
|
| 264 |
+
.kernel-note-cta:hover { color: var(--t1); border-color: rgba(255, 255, 255, 0.4); }
|
| 265 |
+
.hero-foot-note {
|
| 266 |
+
font-family: var(--mono);
|
| 267 |
+
font-size: 10px;
|
| 268 |
+
letter-spacing: 0.06em;
|
| 269 |
+
color: var(--t4);
|
| 270 |
+
}
|
| 271 |
+
.scroll-cue {
|
| 272 |
+
flex: 0 0 auto;
|
| 273 |
+
align-self: center;
|
| 274 |
+
display: flex;
|
| 275 |
+
flex-direction: column;
|
| 276 |
+
align-items: center;
|
| 277 |
+
gap: 9px;
|
| 278 |
+
padding-bottom: 18px;
|
| 279 |
+
pointer-events: none;
|
| 280 |
+
opacity: 0;
|
| 281 |
+
transition: opacity 0.8s ease 1.8s;
|
| 282 |
+
}
|
| 283 |
+
.scroll-cue.in { opacity: 1; }
|
| 284 |
+
.scroll-cue span {
|
| 285 |
+
font-family: var(--mono);
|
| 286 |
+
font-size: 9.5px;
|
| 287 |
+
letter-spacing: 0.2em;
|
| 288 |
+
text-transform: uppercase;
|
| 289 |
+
color: var(--t4);
|
| 290 |
+
}
|
| 291 |
+
.scroll-cue-line { width: 1px; height: 30px; background: var(--line); position: relative; overflow: hidden; }
|
| 292 |
+
.scroll-cue-line::after {
|
| 293 |
+
content: "";
|
| 294 |
+
position: absolute;
|
| 295 |
+
top: -100%; left: 0;
|
| 296 |
+
width: 100%; height: 100%;
|
| 297 |
+
background: linear-gradient(to bottom, transparent, rgba(255, 255, 255, 0.4), transparent);
|
| 298 |
+
animation: scrollDrop 2s ease-in-out infinite;
|
| 299 |
+
}
|
| 300 |
+
|
| 301 |
+
/* CHAT */
|
| 302 |
+
#chat {
|
| 303 |
+
display: flex;
|
| 304 |
+
flex-direction: column;
|
| 305 |
+
height: 100dvh;
|
| 306 |
+
background: radial-gradient(circle at 50% -20%, rgba(255, 255, 255, 0.035), transparent 55%), var(--bg);
|
| 307 |
+
}
|
| 308 |
+
.chat-head {
|
| 309 |
+
position: relative;
|
| 310 |
+
flex: 0 0 auto;
|
| 311 |
+
border-bottom: 1px solid var(--line-soft);
|
| 312 |
+
background: rgba(2, 2, 3, 0.72);
|
| 313 |
+
backdrop-filter: blur(12px);
|
| 314 |
+
-webkit-backdrop-filter: blur(12px);
|
| 315 |
+
}
|
| 316 |
+
.chat-head-inner {
|
| 317 |
+
margin: 0 auto;
|
| 318 |
+
max-width: var(--maxw);
|
| 319 |
+
padding: 16px 28px;
|
| 320 |
+
display: flex;
|
| 321 |
+
align-items: center;
|
| 322 |
+
gap: 16px;
|
| 323 |
+
}
|
| 324 |
+
.to-top {
|
| 325 |
+
display: inline-flex;
|
| 326 |
+
align-items: center;
|
| 327 |
+
gap: 9px;
|
| 328 |
+
flex-shrink: 0;
|
| 329 |
+
transition: opacity 0.2s ease;
|
| 330 |
+
}
|
| 331 |
+
.to-top:hover { opacity: 0.7; }
|
| 332 |
+
.to-top svg { width: 13px; height: 13px; color: var(--t3); }
|
| 333 |
+
.to-top .brand-name { font-size: 11px; }
|
| 334 |
+
.status {
|
| 335 |
+
flex: 1;
|
| 336 |
+
min-width: 0;
|
| 337 |
+
display: flex;
|
| 338 |
+
align-items: center;
|
| 339 |
+
gap: 9px;
|
| 340 |
+
color: var(--t2);
|
| 341 |
+
font-size: 13px;
|
| 342 |
+
}
|
| 343 |
+
.status-dot {
|
| 344 |
+
width: 7px; height: 7px; border-radius: 50%;
|
| 345 |
+
background: var(--t4);
|
| 346 |
+
flex-shrink: 0;
|
| 347 |
+
transition: background 0.3s ease, box-shadow 0.3s ease;
|
| 348 |
+
}
|
| 349 |
+
.status.loading .status-dot { background: var(--warn); box-shadow: 0 0 10px rgba(255, 205, 107, 0.5); }
|
| 350 |
+
.status.ready .status-dot { background: var(--ok); box-shadow: 0 0 10px rgba(100, 255, 160, 0.5); }
|
| 351 |
+
.status.busy .status-dot { background: var(--ok); box-shadow: 0 0 10px rgba(100, 255, 160, 0.5); animation: statusPulse 1.1s ease-in-out infinite; }
|
| 352 |
+
.status.error .status-dot { background: var(--danger); box-shadow: 0 0 10px rgba(255, 122, 107, 0.5); }
|
| 353 |
+
.status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
|
| 354 |
+
.status-text strong { color: var(--t1); font-weight: 500; }
|
| 355 |
+
.chat-head-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
|
| 356 |
+
.head-btn {
|
| 357 |
+
display: inline-flex;
|
| 358 |
+
align-items: center;
|
| 359 |
+
gap: 7px;
|
| 360 |
+
padding: 8px 15px;
|
| 361 |
+
font-family: var(--mono);
|
| 362 |
+
font-size: 11px;
|
| 363 |
+
letter-spacing: 0.08em;
|
| 364 |
+
text-transform: uppercase;
|
| 365 |
+
color: var(--t2);
|
| 366 |
+
border: 1px solid var(--line);
|
| 367 |
+
border-radius: 100px;
|
| 368 |
+
transition: border-color 0.2s ease, color 0.2s ease, opacity 0.2s ease;
|
| 369 |
+
}
|
| 370 |
+
.head-btn:hover:not(:disabled) { border-color: rgba(255, 255, 255, 0.35); color: var(--t1); }
|
| 371 |
+
.head-btn:disabled { opacity: 0.35; cursor: not-allowed; }
|
| 372 |
+
.head-btn[hidden] { display: none; }
|
| 373 |
+
.head-btn.solid { background: #fff; color: #000; border-color: #fff; }
|
| 374 |
+
.head-btn.solid:hover:not(:disabled) { opacity: 0.85; color: #000; }
|
| 375 |
+
.bar {
|
| 376 |
+
position: absolute;
|
| 377 |
+
left: 0; right: 0; bottom: 0;
|
| 378 |
+
height: 2px;
|
| 379 |
+
overflow: hidden;
|
| 380 |
+
pointer-events: none;
|
| 381 |
+
}
|
| 382 |
+
.bar > div {
|
| 383 |
+
height: 100%;
|
| 384 |
+
width: 0%;
|
| 385 |
+
background: linear-gradient(90deg, var(--t2), #fff);
|
| 386 |
+
transition: opacity 0.4s ease;
|
| 387 |
+
}
|
| 388 |
+
.bar.done > div { opacity: 0; }
|
| 389 |
+
.thread-scroll {
|
| 390 |
+
flex: 1 1 auto;
|
| 391 |
+
min-height: 0;
|
| 392 |
+
overflow-y: auto;
|
| 393 |
+
scroll-behavior: smooth;
|
| 394 |
+
}
|
| 395 |
+
.thread {
|
| 396 |
+
margin: 0 auto;
|
| 397 |
+
max-width: var(--maxw);
|
| 398 |
+
min-height: 100%;
|
| 399 |
+
padding: 40px 28px 24px;
|
| 400 |
+
display: flex;
|
| 401 |
+
flex-direction: column;
|
| 402 |
+
gap: 32px;
|
| 403 |
+
}
|
| 404 |
+
.welcome {
|
| 405 |
+
margin: auto 0;
|
| 406 |
+
text-align: center;
|
| 407 |
+
padding: 4vh 0;
|
| 408 |
+
animation: rise 0.7s cubic-bezier(0.2, 0.7, 0.2, 1) both;
|
| 409 |
+
}
|
| 410 |
+
.welcome h2 {
|
| 411 |
+
font-family: var(--display);
|
| 412 |
+
font-size: clamp(30px, 6vw, 46px);
|
| 413 |
+
font-weight: 400;
|
| 414 |
+
line-height: 1.05;
|
| 415 |
+
color: #fff;
|
| 416 |
+
margin-bottom: 14px;
|
| 417 |
+
}
|
| 418 |
+
.welcome h2 .thin { color: var(--t3); }
|
| 419 |
+
.welcome p { color: var(--t2); max-width: 46ch; margin: 0 auto 28px; font-weight: 300; }
|
| 420 |
+
.seeds { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; }
|
| 421 |
+
.seed {
|
| 422 |
+
padding: 9px 16px;
|
| 423 |
+
font-size: 13.5px;
|
| 424 |
+
color: var(--t2);
|
| 425 |
+
background: var(--panel);
|
| 426 |
+
border: 1px solid var(--line);
|
| 427 |
+
border-radius: 100px;
|
| 428 |
+
transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease, transform 0.15s ease, opacity 0.2s ease;
|
| 429 |
+
}
|
| 430 |
+
.seed:hover:not(:disabled) { border-color: rgba(255, 255, 255, 0.3); color: var(--t1); background: var(--panel-hover); transform: translateY(-1px); }
|
| 431 |
+
.seed:disabled { opacity: 0.4; cursor: not-allowed; }
|
| 432 |
+
.msg { display: flex; flex-direction: column; animation: rise 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) both; }
|
| 433 |
+
.role {
|
| 434 |
+
display: flex;
|
| 435 |
+
align-items: center;
|
| 436 |
+
gap: 8px;
|
| 437 |
+
font-family: var(--mono);
|
| 438 |
+
font-size: 10.5px;
|
| 439 |
+
letter-spacing: 0.16em;
|
| 440 |
+
text-transform: uppercase;
|
| 441 |
+
margin-bottom: 10px;
|
| 442 |
+
}
|
| 443 |
+
.role::before { content: ""; width: 5px; height: 5px; border-radius: 50%; }
|
| 444 |
+
.msg.user { align-items: flex-end; }
|
| 445 |
+
.msg.user .role { color: var(--t3); }
|
| 446 |
+
.msg.user .role::before { background: var(--t3); }
|
| 447 |
+
.msg.assistant .role { color: var(--ok); }
|
| 448 |
+
.msg.assistant .role::before { background: var(--ok); }
|
| 449 |
+
.bubble { overflow-wrap: anywhere; }
|
| 450 |
+
.bubble.user {
|
| 451 |
+
background: var(--user-bubble);
|
| 452 |
+
border: 1px solid var(--line);
|
| 453 |
+
border-radius: 16px 16px 4px 16px;
|
| 454 |
+
padding: 12px 17px;
|
| 455 |
+
line-height: 1.55;
|
| 456 |
+
max-width: min(82%, 600px);
|
| 457 |
+
white-space: pre-wrap;
|
| 458 |
+
color: var(--t1);
|
| 459 |
+
}
|
| 460 |
+
.bubble.assistant { font-size: 16px; line-height: 1.72; color: var(--t1); max-width: 100%; }
|
| 461 |
+
.bubble.assistant > :first-child { margin-top: 0; }
|
| 462 |
+
.bubble.assistant > :last-child { margin-bottom: 0; }
|
| 463 |
+
.bubble.assistant p { margin: 0 0 0.9em; }
|
| 464 |
+
.bubble.assistant strong { color: #fff; font-weight: 600; }
|
| 465 |
+
.bubble.assistant em { font-style: italic; }
|
| 466 |
+
.bubble.assistant a { color: #8ab4ff; text-decoration: underline; text-underline-offset: 2px; }
|
| 467 |
+
.bubble.assistant a:hover { color: #aecbff; }
|
| 468 |
+
.bubble.assistant h1, .bubble.assistant h2, .bubble.assistant h3,
|
| 469 |
+
.bubble.assistant h4, .bubble.assistant h5, .bubble.assistant h6 {
|
| 470 |
+
color: #fff; font-weight: 600; line-height: 1.25; margin: 1.3em 0 0.6em;
|
| 471 |
+
}
|
| 472 |
+
.bubble.assistant h1 { font-size: 1.5em; }
|
| 473 |
+
.bubble.assistant h2 { font-size: 1.3em; }
|
| 474 |
+
.bubble.assistant h3 { font-size: 1.13em; }
|
| 475 |
+
.bubble.assistant h4, .bubble.assistant h5, .bubble.assistant h6 { font-size: 1em; }
|
| 476 |
+
.bubble.assistant ul, .bubble.assistant ol { margin: 0 0 0.9em; padding-left: 1.5em; }
|
| 477 |
+
.bubble.assistant li { margin: 0.25em 0; }
|
| 478 |
+
.bubble.assistant li::marker { color: var(--t3); }
|
| 479 |
+
.bubble.assistant blockquote {
|
| 480 |
+
margin: 0 0 0.9em; padding: 2px 0 2px 16px;
|
| 481 |
+
border-left: 2px solid var(--line); color: var(--t2);
|
| 482 |
+
}
|
| 483 |
+
.bubble.assistant hr { border: 0; border-top: 1px solid var(--line); margin: 1.3em 0; }
|
| 484 |
+
.bubble.assistant code {
|
| 485 |
+
font-family: var(--mono);
|
| 486 |
+
font-size: 0.85em;
|
| 487 |
+
background: var(--panel);
|
| 488 |
+
border: 1px solid var(--line);
|
| 489 |
+
border-radius: 5px;
|
| 490 |
+
padding: 1px 5px;
|
| 491 |
+
}
|
| 492 |
+
.bubble.assistant pre {
|
| 493 |
+
margin: 0 0 0.9em;
|
| 494 |
+
padding: 14px 16px;
|
| 495 |
+
background: #0a0a0c;
|
| 496 |
+
border: 1px solid var(--line);
|
| 497 |
+
border-radius: 12px;
|
| 498 |
+
overflow-x: auto;
|
| 499 |
+
}
|
| 500 |
+
.bubble.assistant pre code { background: none; border: 0; padding: 0; font-size: 0.82em; line-height: 1.6; }
|
| 501 |
+
.bubble.assistant table { border-collapse: collapse; margin: 0 0 0.9em; font-size: 0.92em; display: block; overflow-x: auto; }
|
| 502 |
+
.bubble.assistant th, .bubble.assistant td { border: 1px solid var(--line); padding: 6px 11px; text-align: left; }
|
| 503 |
+
.bubble.assistant th { background: var(--panel); color: var(--t1); font-weight: 600; }
|
| 504 |
+
.bubble.assistant pre::-webkit-scrollbar, .bubble.assistant table::-webkit-scrollbar { height: 8px; }
|
| 505 |
+
.bubble.assistant pre::-webkit-scrollbar-thumb, .bubble.assistant table::-webkit-scrollbar-thumb { background: var(--line); border-radius: 8px; }
|
| 506 |
+
.meta {
|
| 507 |
+
font-family: var(--mono);
|
| 508 |
+
font-size: 10.5px;
|
| 509 |
+
letter-spacing: 0.04em;
|
| 510 |
+
color: var(--t3);
|
| 511 |
+
margin-top: 12px;
|
| 512 |
+
}
|
| 513 |
+
.thinking { display: inline-flex; gap: 5px; padding: 4px 0; }
|
| 514 |
+
.thinking span { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); opacity: 0.5; animation: bob 1.3s ease-in-out infinite; }
|
| 515 |
+
.thinking span:nth-child(2) { animation-delay: 0.18s; }
|
| 516 |
+
.thinking span:nth-child(3) { animation-delay: 0.36s; }
|
| 517 |
+
.caret { display: inline-block; width: 2px; height: 1.05em; margin-left: 2px; vertical-align: -0.16em; background: var(--ok); animation: blink 1s steps(2) infinite; }
|
| 518 |
+
|
| 519 |
+
/* MULTIMODAL ATTACHMENTS */
|
| 520 |
+
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
|
| 521 |
+
.attachment {
|
| 522 |
+
position: relative;
|
| 523 |
+
display: inline-flex;
|
| 524 |
+
align-items: center;
|
| 525 |
+
gap: 8px;
|
| 526 |
+
padding: 6px 10px;
|
| 527 |
+
background: var(--panel);
|
| 528 |
+
border: 1px solid var(--line);
|
| 529 |
+
border-radius: 10px;
|
| 530 |
+
font-size: 12px;
|
| 531 |
+
color: var(--t2);
|
| 532 |
+
}
|
| 533 |
+
.attachment img { width: 32px; height: 32px; border-radius: 6px; object-fit: cover; }
|
| 534 |
+
.attachment .att-name { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
| 535 |
+
.attachment .att-type { font-family: var(--mono); font-size: 9px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--t4); }
|
| 536 |
+
.attachment .att-remove {
|
| 537 |
+
display: grid; place-items: center;
|
| 538 |
+
width: 18px; height: 18px;
|
| 539 |
+
border-radius: 50%;
|
| 540 |
+
background: rgba(255,255,255,0.08);
|
| 541 |
+
color: var(--t3);
|
| 542 |
+
font-size: 12px;
|
| 543 |
+
line-height: 1;
|
| 544 |
+
transition: background 0.15s ease, color 0.15s ease;
|
| 545 |
+
}
|
| 546 |
+
.attachment .att-remove:hover { background: rgba(255,122,107,0.2); color: var(--danger); }
|
| 547 |
+
.attachment.audio .att-icon { font-size: 18px; }
|
| 548 |
+
.attachment.audio canvas { width: 48px; height: 24px; border-radius: 4px; }
|
| 549 |
+
|
| 550 |
+
.composer-wrap {
|
| 551 |
+
flex: 0 0 auto;
|
| 552 |
+
background: linear-gradient(rgba(2, 2, 3, 0), var(--bg) 30%);
|
| 553 |
+
padding-top: 8px;
|
| 554 |
+
}
|
| 555 |
+
.composer { margin: 0 auto; max-width: var(--maxw); padding: 0 28px 22px; }
|
| 556 |
+
.composer-tools {
|
| 557 |
+
display: flex;
|
| 558 |
+
align-items: center;
|
| 559 |
+
gap: 4px;
|
| 560 |
+
margin-bottom: 8px;
|
| 561 |
+
}
|
| 562 |
+
.tool-btn {
|
| 563 |
+
display: grid;
|
| 564 |
+
place-items: center;
|
| 565 |
+
width: 34px;
|
| 566 |
+
height: 34px;
|
| 567 |
+
border-radius: 9px;
|
| 568 |
+
color: var(--t3);
|
| 569 |
+
border: 1px solid transparent;
|
| 570 |
+
transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
|
| 571 |
+
}
|
| 572 |
+
.tool-btn:hover:not(:disabled) { border-color: var(--line); color: var(--t1); background: var(--panel); }
|
| 573 |
+
.tool-btn:disabled { opacity: 0.3; cursor: not-allowed; }
|
| 574 |
+
.tool-btn.recording { color: var(--danger); border-color: rgba(255,122,107,0.3); background: rgba(255,122,107,0.08); animation: statusPulse 1s ease-in-out infinite; }
|
| 575 |
+
.tool-btn svg { width: 17px; height: 17px; }
|
| 576 |
+
.field {
|
| 577 |
+
display: grid;
|
| 578 |
+
grid-template-columns: 1fr 44px;
|
| 579 |
+
align-items: flex-end;
|
| 580 |
+
gap: 8px;
|
| 581 |
+
background: var(--panel);
|
| 582 |
+
border: 1px solid var(--line);
|
| 583 |
+
border-radius: 18px;
|
| 584 |
+
padding: 8px 8px 8px 18px;
|
| 585 |
+
transition: border-color 0.2s ease, background 0.2s ease;
|
| 586 |
+
}
|
| 587 |
+
.field:focus-within { border-color: rgba(255, 255, 255, 0.28); background: rgba(255, 255, 255, 0.05); }
|
| 588 |
+
textarea {
|
| 589 |
+
background: transparent;
|
| 590 |
+
border: 0;
|
| 591 |
+
outline: none;
|
| 592 |
+
resize: none;
|
| 593 |
+
width: 100%;
|
| 594 |
+
min-height: 42px;
|
| 595 |
+
max-height: 180px;
|
| 596 |
+
padding: 8px 0;
|
| 597 |
+
color: var(--t1);
|
| 598 |
+
}
|
| 599 |
+
textarea::placeholder { color: var(--t3); }
|
| 600 |
+
.icon-button {
|
| 601 |
+
display: grid;
|
| 602 |
+
place-items: center;
|
| 603 |
+
width: 42px;
|
| 604 |
+
height: 42px;
|
| 605 |
+
border-radius: 13px;
|
| 606 |
+
transition: background 0.2s ease, opacity 0.2s ease, transform 0.1s ease;
|
| 607 |
+
}
|
| 608 |
+
.icon-button svg { width: 19px; height: 19px; }
|
| 609 |
+
.icon-button:active:not(:disabled) { transform: scale(0.94); }
|
| 610 |
+
.icon-button:disabled { opacity: 0.3; cursor: not-allowed; }
|
| 611 |
+
.send-button { background: #fff; color: #000; }
|
| 612 |
+
.send-button:hover:not(:disabled) { opacity: 0.86; }
|
| 613 |
+
.stop-button { background: rgba(255, 122, 107, 0.14); color: var(--danger); border: 1px solid rgba(255, 122, 107, 0.3); display: none; }
|
| 614 |
+
.stop-button:hover:not(:disabled) { background: rgba(255, 122, 107, 0.22); }
|
| 615 |
+
.composer-meta {
|
| 616 |
+
display: flex;
|
| 617 |
+
align-items: center;
|
| 618 |
+
justify-content: center;
|
| 619 |
+
gap: 12px;
|
| 620 |
+
margin: 10px 4px 0;
|
| 621 |
+
min-height: 22px;
|
| 622 |
+
font-family: var(--mono);
|
| 623 |
+
font-size: 10.5px;
|
| 624 |
+
letter-spacing: 0.04em;
|
| 625 |
+
text-transform: uppercase;
|
| 626 |
+
color: var(--t3);
|
| 627 |
+
}
|
| 628 |
+
.thread-scroll::-webkit-scrollbar { width: 10px; }
|
| 629 |
+
.thread-scroll::-webkit-scrollbar-thumb { background: var(--line); border: 3px solid var(--bg); border-radius: 10px; }
|
| 630 |
+
:focus-visible { outline: 1px solid rgba(255, 255, 255, 0.45); outline-offset: 3px; }
|
| 631 |
+
textarea:focus, textarea:focus-visible { outline: none; }
|
| 632 |
+
|
| 633 |
+
/* kernels overlay */
|
| 634 |
+
.kx {
|
| 635 |
+
position: fixed;
|
| 636 |
+
inset: 0;
|
| 637 |
+
z-index: 50;
|
| 638 |
+
display: flex;
|
| 639 |
+
align-items: center;
|
| 640 |
+
justify-content: center;
|
| 641 |
+
padding: 28px;
|
| 642 |
+
}
|
| 643 |
+
.kx[hidden] { display: none; }
|
| 644 |
+
.kx-backdrop {
|
| 645 |
+
position: absolute;
|
| 646 |
+
inset: 0;
|
| 647 |
+
background: rgba(0, 0, 0, 0.62);
|
| 648 |
+
backdrop-filter: blur(6px);
|
| 649 |
+
-webkit-backdrop-filter: blur(6px);
|
| 650 |
+
animation: kxFade 0.25s ease;
|
| 651 |
+
}
|
| 652 |
+
.kx-panel {
|
| 653 |
+
position: relative;
|
| 654 |
+
display: flex;
|
| 655 |
+
flex-direction: column;
|
| 656 |
+
width: min(1080px, 100%);
|
| 657 |
+
height: min(86vh, 920px);
|
| 658 |
+
background: #0a0a0c;
|
| 659 |
+
border: 1px solid var(--line);
|
| 660 |
+
border-radius: 18px;
|
| 661 |
+
overflow: hidden;
|
| 662 |
+
box-shadow: 0 40px 120px -30px rgba(0, 0, 0, 0.9);
|
| 663 |
+
animation: kxRise 0.3s cubic-bezier(0.2, 0.7, 0.2, 1);
|
| 664 |
+
}
|
| 665 |
+
.kx-head {
|
| 666 |
+
display: flex;
|
| 667 |
+
align-items: flex-start;
|
| 668 |
+
justify-content: space-between;
|
| 669 |
+
gap: 16px;
|
| 670 |
+
padding: 20px 22px;
|
| 671 |
+
border-bottom: 1px solid var(--line-soft);
|
| 672 |
+
}
|
| 673 |
+
.kx-title h3 { font-family: var(--display); font-weight: 400; font-size: 26px; color: #fff; line-height: 1; }
|
| 674 |
+
.kx-sub { display: block; margin-top: 7px; font-size: 12.5px; color: var(--t3); }
|
| 675 |
+
.kx-close {
|
| 676 |
+
display: grid; place-items: center;
|
| 677 |
+
width: 34px; height: 34px;
|
| 678 |
+
flex-shrink: 0; border-radius: 9px;
|
| 679 |
+
color: var(--t2);
|
| 680 |
+
border: 1px solid var(--line);
|
| 681 |
+
transition: color 0.2s ease, border-color 0.2s ease, background 0.2s ease;
|
| 682 |
+
}
|
| 683 |
+
.kx-close:hover { color: var(--t1); border-color: rgba(255, 255, 255, 0.35); background: var(--panel); }
|
| 684 |
+
.kx-close svg { width: 15px; height: 15px; }
|
| 685 |
+
.kx-body { flex: 1; display: grid; grid-template-columns: 236px 1fr; min-height: 0; }
|
| 686 |
+
.kx-side { position: relative; min-width: 0; min-height: 0; border-right: 1px solid var(--line-soft); }
|
| 687 |
+
.kx-list { height: 100%; overflow-y: auto; padding: 10px; display: flex; flex-direction: column; gap: 2px; }
|
| 688 |
+
.kx-item {
|
| 689 |
+
flex-shrink: 0;
|
| 690 |
+
text-align: left;
|
| 691 |
+
padding: 9px 12px;
|
| 692 |
+
border-radius: 8px;
|
| 693 |
+
font-family: var(--mono);
|
| 694 |
+
font-size: 12px;
|
| 695 |
+
line-height: 1.5;
|
| 696 |
+
color: var(--t2);
|
| 697 |
+
white-space: nowrap;
|
| 698 |
+
overflow: hidden;
|
| 699 |
+
text-overflow: ellipsis;
|
| 700 |
+
transition: background 0.15s ease, color 0.15s ease;
|
| 701 |
+
}
|
| 702 |
+
.kx-item:hover { background: var(--panel); color: var(--t1); }
|
| 703 |
+
.kx-item.active { background: var(--panel-hover); color: #fff; }
|
| 704 |
+
.kx-view { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; }
|
| 705 |
+
.kx-view-head {
|
| 706 |
+
display: flex; align-items: center; justify-content: space-between; gap: 12px;
|
| 707 |
+
padding: 12px 18px; border-bottom: 1px solid var(--line-soft);
|
| 708 |
+
}
|
| 709 |
+
.kx-name { font-family: var(--mono); font-size: 13px; color: var(--t1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
| 710 |
+
.kx-view-actions { display: flex; align-items: center; gap: 14px; flex-shrink: 0; }
|
| 711 |
+
.kx-lines { font-family: var(--mono); font-size: 11px; color: var(--t4); }
|
| 712 |
+
.kx-copy {
|
| 713 |
+
font-family: var(--mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
|
| 714 |
+
color: var(--t2); border: 1px solid var(--line); border-radius: 100px; padding: 5px 13px;
|
| 715 |
+
transition: color 0.2s ease, border-color 0.2s ease;
|
| 716 |
+
}
|
| 717 |
+
.kx-copy:hover { color: var(--t1); border-color: rgba(255, 255, 255, 0.35); }
|
| 718 |
+
.kx-code { flex: 1; min-height: 0; min-width: 0; overflow: auto; margin: 0; padding: 18px 20px; font-family: var(--mono); font-size: 12.5px; line-height: 1.65; color: var(--t2); tab-size: 2; }
|
| 719 |
+
.kx-code code { white-space: pre; }
|
| 720 |
+
.k-cm { color: #5d6b6f; font-style: italic; }
|
| 721 |
+
.k-kw { color: #c792ea; }
|
| 722 |
+
.k-ty { color: #6fb3ff; }
|
| 723 |
+
.k-at { color: #ffb074; }
|
| 724 |
+
.k-nu { color: #7ee787; }
|
| 725 |
+
.kx-source { flex: 1; min-height: 0; display: flex; flex-direction: column; }
|
| 726 |
+
.kx-source[hidden] { display: none; }
|
| 727 |
+
.kx-code::-webkit-scrollbar, .kx-list::-webkit-scrollbar { width: 10px; height: 10px; }
|
| 728 |
+
.kx-code::-webkit-scrollbar-thumb, .kx-list::-webkit-scrollbar-thumb { background: var(--line); border: 3px solid #0a0a0c; border-radius: 10px; }
|
| 729 |
+
body.kx-locked { overflow: hidden; }
|
| 730 |
+
|
| 731 |
+
@keyframes kxFade { from { opacity: 0; } to { opacity: 1; } }
|
| 732 |
+
@keyframes kxRise { from { opacity: 0; transform: translateY(12px) scale(0.99); } to { opacity: 1; transform: none; } }
|
| 733 |
+
@keyframes statusPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
|
| 734 |
+
@keyframes scrollDrop { 0% { top: -100%; } 55% { top: 100%; } 100% { top: 100%; } }
|
| 735 |
+
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
|
| 736 |
+
@keyframes blink { 0%, 49% { opacity: 1; } 50%, 100% { opacity: 0; } }
|
| 737 |
+
@keyframes bob { 0%, 60%, 100% { opacity: 0.5; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-5px); } }
|
| 738 |
+
|
| 739 |
+
.anim { opacity: 0; transition: opacity 0.9s cubic-bezier(0.25, 0.1, 0.25, 1); }
|
| 740 |
+
.anim.in { opacity: 1; }
|
| 741 |
+
.eyebrow { transition-delay: 0.35s; }
|
| 742 |
+
.hero-h1 { transition-delay: 0.5s; }
|
| 743 |
+
.hero-row { transition-delay: 0.78s; }
|
| 744 |
+
|
| 745 |
+
@media (prefers-reduced-motion: reduce) {
|
| 746 |
+
*, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
|
| 747 |
+
.anim, #crt-frame, .hero-fade, .scroll-cue { opacity: 1 !important; }
|
| 748 |
+
.caret { opacity: 1; }
|
| 749 |
+
}
|
| 750 |
+
|
| 751 |
+
@media (max-width: 760px) {
|
| 752 |
+
.hero-content { padding: 0 22px 22px; }
|
| 753 |
+
.hero-h1 { font-size: clamp(38px, 12vw, 60px); margin-bottom: 24px; max-width: none; }
|
| 754 |
+
.hero-row { flex-direction: column; align-items: stretch; gap: 28px; }
|
| 755 |
+
.hero-side { align-items: flex-start; text-align: left; }
|
| 756 |
+
.hero-foot { align-items: flex-start; }
|
| 757 |
+
.hero-actions { flex-wrap: wrap; }
|
| 758 |
+
.hero-stats { gap: 22px 30px; }
|
| 759 |
+
.stat-val { font-size: 24px; }
|
| 760 |
+
.scroll-cue { display: none; }
|
| 761 |
+
.chat-head-inner { padding: 13px 18px; gap: 12px; }
|
| 762 |
+
.to-top .brand-name { display: none; }
|
| 763 |
+
.thread { padding: 28px 18px 20px; }
|
| 764 |
+
.composer { padding: 0 18px 18px; }
|
| 765 |
+
.bubble.user { max-width: 88%; }
|
| 766 |
+
.head-btn { padding: 8px 12px; }
|
| 767 |
+
.kx { padding: 0; }
|
| 768 |
+
.kx-panel { width: 100%; height: 100%; border-radius: 0; border: 0; }
|
| 769 |
+
.kx-body { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
|
| 770 |
+
.kx-side { border-right: 0; border-bottom: 1px solid var(--line-soft); }
|
| 771 |
+
.kx-list { flex-direction: row; height: auto; overflow-x: auto; overflow-y: hidden; }
|
| 772 |
+
.kx-item { flex-shrink: 0; }
|
| 773 |
+
}
|
| 774 |
+
</style>
|
| 775 |
+
<style id="blackriver-theme">
|
| 776 |
+
:root {
|
| 777 |
+
--bg: #020306;
|
| 778 |
+
--panel: rgba(141, 180, 255, 0.055);
|
| 779 |
+
--panel2: rgba(255, 255, 255, 0.035);
|
| 780 |
+
--line: rgba(196, 211, 255, 0.20);
|
| 781 |
+
--line-soft: rgba(196, 211, 255, 0.10);
|
| 782 |
+
--t1: #f7f9fc;
|
| 783 |
+
--t2: #98a2b3;
|
| 784 |
+
--t3: #626b7d;
|
| 785 |
+
--accent: #8db4ff;
|
| 786 |
+
--accent2: #8df1ff;
|
| 787 |
+
--green: #58e6b1;
|
| 788 |
+
--sans: "Inter", system-ui, sans-serif;
|
| 789 |
+
--mono: "Geist Mono", "SFMono-Regular", Consolas, monospace;
|
| 790 |
+
}
|
| 791 |
+
|
| 792 |
+
html, body { background: var(--bg); }
|
| 793 |
+
body { font-family: var(--sans); color: var(--t1); }
|
| 794 |
+
::selection { background: rgba(141, 180, 255, 0.28); color: #fff; }
|
| 795 |
+
|
| 796 |
+
body::before {
|
| 797 |
+
content: "";
|
| 798 |
+
position: fixed; inset: 0; pointer-events: none; z-index: 9997;
|
| 799 |
+
background-image:
|
| 800 |
+
linear-gradient(rgba(141,180,255,.025) 1px, transparent 1px),
|
| 801 |
+
linear-gradient(90deg, rgba(141,180,255,.025) 1px, transparent 1px);
|
| 802 |
+
background-size: 52px 52px;
|
| 803 |
+
mask-image: linear-gradient(to bottom, #000, transparent 75%);
|
| 804 |
+
}
|
| 805 |
+
body::after {
|
| 806 |
+
content: "";
|
| 807 |
+
position: fixed; inset: 0; pointer-events: none; z-index: 9998; opacity: .025;
|
| 808 |
+
background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
|
| 809 |
+
}
|
| 810 |
+
|
| 811 |
+
#landing { background: #020306; isolation: isolate; }
|
| 812 |
+
#landing::after {
|
| 813 |
+
content: ""; position: absolute; inset: 0; z-index: 1; pointer-events: none;
|
| 814 |
+
background: radial-gradient(ellipse 60% 72% at 73% 44%, transparent 0%, rgba(2,3,6,.15) 45%, #020306 88%);
|
| 815 |
+
}
|
| 816 |
+
#crt-frame { opacity: .78; filter: saturate(.48) hue-rotate(169deg) contrast(1.12); }
|
| 817 |
+
.hero-fade { background: linear-gradient(90deg, rgba(2,3,6,.98) 0%, rgba(2,3,6,.78) 47%, rgba(2,3,6,.16) 100%); }
|
| 818 |
+
.hero-overlay { z-index: 2; }
|
| 819 |
+
.hero-content { width: min(1380px, calc(100% - 9vw)); padding-top: 5vh; }
|
| 820 |
+
|
| 821 |
+
.eyebrow {
|
| 822 |
+
display: flex; align-items: center; gap: 13px; margin-bottom: clamp(28px, 5vh, 58px);
|
| 823 |
+
color: var(--t2); font-family: var(--mono); font-size: 10px; font-weight: 500;
|
| 824 |
+
letter-spacing: .15em; text-transform: uppercase;
|
| 825 |
+
}
|
| 826 |
+
.eyebrow::before { display: none; }
|
| 827 |
+
.br-mark { width: 31px; height: 31px; flex: none; color: var(--t1); }
|
| 828 |
+
.br-mark.small { width: 22px; height: 22px; }
|
| 829 |
+
.br-lockup { display: grid; gap: 3px; }
|
| 830 |
+
.br-lockup strong { color: var(--t1); font-weight: 600; letter-spacing: .18em; }
|
| 831 |
+
.br-lockup span { color: var(--t3); font-size: 8px; letter-spacing: .17em; }
|
| 832 |
+
|
| 833 |
+
.hero-h1 {
|
| 834 |
+
max-width: 990px; margin-bottom: clamp(36px, 7vh, 78px);
|
| 835 |
+
font-family: var(--sans); font-size: clamp(54px, 7.8vw, 116px); line-height: .88;
|
| 836 |
+
letter-spacing: -.072em; font-weight: 580;
|
| 837 |
+
}
|
| 838 |
+
.hero-h1 .thin {
|
| 839 |
+
color: transparent; font-weight: 250;
|
| 840 |
+
background: linear-gradient(102deg, #f7f9fc 4%, #8db4ff 58%, #8df1ff 100%);
|
| 841 |
+
-webkit-background-clip: text; background-clip: text;
|
| 842 |
+
}
|
| 843 |
+
.hero-row { border-top: 1px solid var(--line); padding-top: 28px; grid-template-columns: minmax(0, 1.25fr) minmax(280px, .75fr); }
|
| 844 |
+
.hero-main { padding-right: clamp(30px, 6vw, 90px); }
|
| 845 |
+
.hero-side { border-left: 1px solid var(--line-soft); padding-left: clamp(24px, 4vw, 58px); }
|
| 846 |
+
.hero-sub { max-width: 710px; color: var(--t2); font-size: 14px; line-height: 1.75; }
|
| 847 |
+
.hero-sub b { color: var(--t1); }
|
| 848 |
+
.hero-stats { border-top-color: var(--line-soft); }
|
| 849 |
+
.stat { border-left: 1px solid var(--line-soft); padding-left: 15px; }
|
| 850 |
+
.stat:first-child { border-left: 0; padding-left: 0; }
|
| 851 |
+
.stat-val { font-family: var(--sans); font-size: 20px; font-weight: 450; letter-spacing: -.03em; }
|
| 852 |
+
.stat-label { font-size: 8px; letter-spacing: .14em; text-transform: uppercase; }
|
| 853 |
+
|
| 854 |
+
.hero-actions { align-items: stretch; }
|
| 855 |
+
.btn-primary {
|
| 856 |
+
min-height: 50px; border: 1px solid rgba(141,180,255,.62); border-radius: 0;
|
| 857 |
+
background: rgba(141,180,255,.12); color: #fff; box-shadow: inset 0 0 24px rgba(141,180,255,.04);
|
| 858 |
+
font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .15em; text-transform: uppercase;
|
| 859 |
+
}
|
| 860 |
+
.btn-primary:hover { background: var(--accent); border-color: var(--accent); color: #020306; transform: none; }
|
| 861 |
+
.btn-primary::before { display: none; }
|
| 862 |
+
#landingModelSelect {
|
| 863 |
+
min-height: 50px !important; border-radius: 0 !important; border-color: var(--line) !important;
|
| 864 |
+
background: rgba(2,3,6,.64) !important; text-transform: uppercase; letter-spacing: .08em;
|
| 865 |
+
}
|
| 866 |
+
.hero-foot { border-top: 1px solid var(--line-soft); padding-top: 18px; }
|
| 867 |
+
.kernel-note-cta { color: var(--t2); font-family: var(--mono); font-size: 9px; letter-spacing: .06em; text-transform: uppercase; }
|
| 868 |
+
.kernel-note-cta b { color: var(--accent2); }
|
| 869 |
+
.hero-foot-note { font-size: 8px; letter-spacing: .12em; text-transform: uppercase; }
|
| 870 |
+
.scroll-cue { left: auto; right: 4.5vw; bottom: 24px; align-items: flex-end; }
|
| 871 |
+
.scroll-cue span { font-size: 8px; letter-spacing: .18em; text-transform: uppercase; }
|
| 872 |
+
.scroll-cue-line { background: linear-gradient(90deg, var(--accent), transparent); width: 82px; height: 1px; }
|
| 873 |
+
|
| 874 |
+
#chat {
|
| 875 |
+
background:
|
| 876 |
+
radial-gradient(circle at 50% 22%, rgba(32,49,82,.24), transparent 34%),
|
| 877 |
+
linear-gradient(180deg, #05070c 0%, #020306 100%);
|
| 878 |
+
}
|
| 879 |
+
.chat-head { background: rgba(2,3,6,.82); border-bottom: 1px solid var(--line); backdrop-filter: blur(24px); }
|
| 880 |
+
.chat-head-inner { max-width: 1280px; height: 64px; }
|
| 881 |
+
.to-top { gap: 11px; opacity: 1; font-family: var(--mono); letter-spacing: .14em; text-transform: uppercase; }
|
| 882 |
+
.to-top svg:not(.br-mark) { display: none; }
|
| 883 |
+
.to-top .brand-name { color: var(--t1); font-size: 9px; font-weight: 600; }
|
| 884 |
+
.status { font-family: var(--mono); font-size: 8px; letter-spacing: .14em; text-transform: uppercase; }
|
| 885 |
+
.status-dot { background: var(--t3); box-shadow: none; }
|
| 886 |
+
.status.ready .status-dot { background: var(--green); box-shadow: 0 0 12px rgba(88,230,177,.5); }
|
| 887 |
+
.head-btn {
|
| 888 |
+
height: 34px; border-radius: 0; border-color: var(--line); background: transparent !important;
|
| 889 |
+
color: var(--t2); font-family: var(--mono); font-size: 8px; font-weight: 500; letter-spacing: .1em; text-transform: uppercase;
|
| 890 |
+
}
|
| 891 |
+
.head-btn:hover { color: var(--t1); border-color: rgba(141,180,255,.55); background: rgba(141,180,255,.07) !important; }
|
| 892 |
+
.head-btn.solid { background: rgba(141,180,255,.12) !important; color: var(--t1); border-color: rgba(141,180,255,.45); }
|
| 893 |
+
.bar { height: 1px; }
|
| 894 |
+
.bar > div { background: linear-gradient(90deg, var(--accent), var(--accent2), var(--green)); }
|
| 895 |
+
|
| 896 |
+
.thread-scroll { scrollbar-color: rgba(141,180,255,.25) transparent; }
|
| 897 |
+
.thread { max-width: 900px; padding: 52px 0 180px; }
|
| 898 |
+
.welcome { min-height: 54vh; display: flex; flex-direction: column; justify-content: center; text-align: left; }
|
| 899 |
+
.welcome-mark { width: 46px; height: 46px; margin-bottom: 30px; color: var(--accent); }
|
| 900 |
+
.welcome h2 { max-width: 670px; font-family: var(--sans); font-size: clamp(44px, 6vw, 78px); line-height: .92; letter-spacing: -.06em; font-weight: 550; }
|
| 901 |
+
.welcome h2 .thin { color: var(--accent); font-weight: 250; }
|
| 902 |
+
.welcome p { margin: 22px 0 0; max-width: none; color: var(--t2); font-family: var(--mono); font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
|
| 903 |
+
.seeds { justify-content: flex-start; margin-top: 34px; }
|
| 904 |
+
.seed { border-radius: 0; border-color: var(--line); background: rgba(255,255,255,.02); font-family: var(--mono); font-size: 9px; letter-spacing: .05em; }
|
| 905 |
+
.seed:not(:disabled):hover { color: var(--accent2); border-color: var(--accent); background: rgba(141,180,255,.06); }
|
| 906 |
+
|
| 907 |
+
.msg { max-width: 100%; }
|
| 908 |
+
.msg .role { color: var(--t3); font-size: 8px; letter-spacing: .16em; text-transform: uppercase; }
|
| 909 |
+
.bubble { border-radius: 0; font-size: 14px; line-height: 1.72; }
|
| 910 |
+
.msg.user .bubble { background: rgba(141,180,255,.08); border: 1px solid rgba(141,180,255,.22); color: var(--t1); }
|
| 911 |
+
.msg.assistant .bubble { background: transparent; border-left: 1px solid var(--accent); padding-left: 20px; }
|
| 912 |
+
.msg-media img { border-radius: 0; border: 1px solid var(--line); }
|
| 913 |
+
|
| 914 |
+
.composer-wrap { background: linear-gradient(0deg, #020306 74%, transparent); border-top: 0; padding-top: 42px; }
|
| 915 |
+
.composer { max-width: 900px; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; }
|
| 916 |
+
.attachments { grid-column: 1 / -1; }
|
| 917 |
+
.composer-tools { grid-column: 1; align-self: stretch; gap: 6px; }
|
| 918 |
+
.field { grid-column: 2; min-height: 56px; border-radius: 0; border-color: rgba(141,180,255,.32); background: rgba(8,11,18,.94); box-shadow: 0 16px 60px rgba(0,0,0,.42); }
|
| 919 |
+
.field:focus-within { border-color: var(--accent); box-shadow: 0 0 0 1px rgba(141,180,255,.14), 0 16px 60px rgba(0,0,0,.42); }
|
| 920 |
+
.field textarea { font-family: var(--sans); font-size: 14px; }
|
| 921 |
+
.field textarea::placeholder { color: #5d6678; }
|
| 922 |
+
.tool-btn { width: 48px; height: 56px; border-radius: 0; border: 1px solid var(--line); background: rgba(8,11,18,.94); color: var(--t2); }
|
| 923 |
+
.tool-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--accent2); background: rgba(141,180,255,.08); }
|
| 924 |
+
.tool-btn.recording { color: #ff938a; border-color: rgba(255,147,138,.5); background: rgba(255,147,138,.08); }
|
| 925 |
+
.icon-button { border-radius: 0; }
|
| 926 |
+
.send-button { color: #020306; background: var(--accent); }
|
| 927 |
+
.composer-meta { grid-column: 1 / -1; color: var(--t3); font-family: var(--mono); font-size: 8px; letter-spacing: .11em; text-transform: uppercase; }
|
| 928 |
+
.attachment { border-radius: 0; border-color: var(--line); background: rgba(8,11,18,.95); }
|
| 929 |
+
|
| 930 |
+
.kx-backdrop { background: rgba(2,3,6,.85); backdrop-filter: blur(15px); }
|
| 931 |
+
.kx-panel { border-radius: 0; border-color: var(--line); background: #060810; }
|
| 932 |
+
.kx-head, .kx-view-head { border-color: var(--line); }
|
| 933 |
+
.kx-title h3 { font-family: var(--mono); letter-spacing: .13em; text-transform: uppercase; }
|
| 934 |
+
.kx-side { border-color: var(--line); }
|
| 935 |
+
.kx-item.active { border-left-color: var(--accent); background: rgba(141,180,255,.08); }
|
| 936 |
+
|
| 937 |
+
@media (max-width: 800px) {
|
| 938 |
+
.hero-content { width: min(100% - 38px, 680px); padding-top: 28px; }
|
| 939 |
+
.eyebrow { margin-bottom: 34px; }
|
| 940 |
+
.hero-h1 { font-size: clamp(46px, 15vw, 72px); margin-bottom: 38px; }
|
| 941 |
+
.hero-row { grid-template-columns: 1fr; }
|
| 942 |
+
.hero-main { padding-right: 0; }
|
| 943 |
+
.hero-side { border-left: 0; border-top: 1px solid var(--line-soft); padding: 25px 0 0; }
|
| 944 |
+
.hero-stats { grid-template-columns: repeat(2, 1fr); row-gap: 20px; }
|
| 945 |
+
.stat:nth-child(3) { border-left: 0; padding-left: 0; }
|
| 946 |
+
.chat-head-inner { padding: 0 16px; }
|
| 947 |
+
#modelSelect { display: none; }
|
| 948 |
+
.thread, .composer { width: calc(100% - 28px); }
|
| 949 |
+
.welcome { min-height: 48vh; }
|
| 950 |
+
.welcome h2 { font-size: clamp(42px, 13vw, 64px); }
|
| 951 |
+
.composer-wrap { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
|
| 952 |
+
}
|
| 953 |
+
.br-lab-dock { position: fixed; right: 16px; top: 50%; transform: translateY(-50%); z-index: 10000; display: flex; flex-direction: column; gap: 7px; padding: 6px; border: 1px solid rgba(196,211,255,.18); background: rgba(2,3,6,.78); backdrop-filter: blur(18px); box-shadow: 0 18px 60px rgba(0,0,0,.35); }
|
| 954 |
+
.br-lab-dock a { position: relative; width: 40px; height: 40px; display: grid; place-items: center; color: #98a2b3; border: 1px solid transparent; transition: .2s ease; }
|
| 955 |
+
.br-lab-dock a:hover { color: #f7f9fc; border-color: rgba(141,180,255,.35); background: rgba(141,180,255,.09); }
|
| 956 |
+
.br-lab-dock svg { width: 17px; height: 17px; }
|
| 957 |
+
.br-lab-dock span { position: absolute; right: 51px; white-space: nowrap; padding: 8px 10px; background: #080b12; border: 1px solid rgba(196,211,255,.18); font-family: var(--mono); font-size: 8px; letter-spacing: .14em; text-transform: uppercase; opacity: 0; pointer-events: none; transform: translateX(5px); transition: .2s ease; }
|
| 958 |
+
.br-lab-dock a:hover span { opacity: 1; transform: none; }
|
| 959 |
+
@media(max-width:650px) { .br-lab-dock { right: 7px; } .br-lab-dock a { width: 34px; height: 34px; } .br-lab-dock span { display: none; } }
|
| 960 |
+
</style>
|
| 961 |
+
</head>
|
| 962 |
+
<body>
|
| 963 |
+
<nav class="br-lab-dock" aria-label="BlackRiver navigation">
|
| 964 |
+
<a href="./" aria-label="Gemma 4 Space home"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8"><path d="M3 11.5 12 4l9 7.5"/><path d="M5.5 10v10h13V10"/></svg><span>Space home</span></a>
|
| 965 |
+
<a href="https://blackriver-ai.vercel.app/labs.html" target="_blank" rel="noopener" aria-label="BlackRiver Labs"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/></svg><span>BlackRiver Labs</span></a>
|
| 966 |
+
</nav>
|
| 967 |
+
|
| 968 |
+
<section id="landing" class="screen">
|
| 969 |
+
<div id="crt-frame"></div>
|
| 970 |
+
<div class="hero-fade"></div>
|
| 971 |
+
<div class="hero-overlay">
|
| 972 |
+
<div class="hero-content">
|
| 973 |
+
<div class="eyebrow anim">
|
| 974 |
+
<svg class="br-mark" viewBox="0 0 32 32" fill="none" aria-hidden="true"><path d="M4 3h10v10H4zM18 3h10v10H18zM4 17h10v12H4z" fill="currentColor"/><path d="M18 17h10v4H18zM18 25h10v4H18z" fill="currentColor" opacity=".62"/></svg>
|
| 975 |
+
<span class="br-lockup"><strong>BlackRiver AI</strong><span>Private multimodal inference / WebGPU</span></span>
|
| 976 |
+
</div>
|
| 977 |
+
<h1 class="hero-h1 anim">Gemma 4.<br><span class="thin">Multimodal intelligence.</span></h1>
|
| 978 |
+
<div class="hero-row anim">
|
| 979 |
+
<div class="hero-main">
|
| 980 |
+
<p class="hero-sub">
|
| 981 |
+
<b>Gemma 4 E2B/E4B</b> with native vision, audio and text intelligence.
|
| 982 |
+
Powered locally through WebGPU: the model is cached on this device and your data stays private.
|
| 983 |
+
</p>
|
| 984 |
+
<div class="hero-stats">
|
| 985 |
+
<div class="stat"><span class="stat-val">2.3B</span><span class="stat-label">Effective params</span></div>
|
| 986 |
+
<div class="stat"><span class="stat-val">128K</span><span class="stat-label">Context window</span></div>
|
| 987 |
+
<div class="stat"><span class="stat-val">~41</span><span class="stat-label">tok/s · M4 Max</span></div>
|
| 988 |
+
<div class="stat"><span class="stat-val">100%</span><span class="stat-label">On-device</span></div>
|
| 989 |
+
</div>
|
| 990 |
+
</div>
|
| 991 |
+
<div class="hero-side">
|
| 992 |
+
<div class="hero-actions">
|
| 993 |
+
<button class="btn-primary" id="loadBtn" type="button">
|
| 994 |
+
<span id="loadBtnLabel">Initialize model</span>
|
| 995 |
+
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M8 2v9M4 7l4 4 4-4"/></svg>
|
| 996 |
+
</button>
|
| 997 |
+
<select id="landingModelSelect" style="appearance:auto;background:transparent;color:var(--t2);font-family:var(--mono);font-size:12px;padding:14px 16px;border:1px solid var(--line);border-radius:100px;cursor:pointer;">
|
| 998 |
+
<option value="onnx-community/gemma-4-E2B-it-ONNX">E2B · 2.3B</option>
|
| 999 |
+
<option value="onnx-community/gemma-4-E4B-it-ONNX">E4B · 4B</option>
|
| 1000 |
+
</select>
|
| 1001 |
+
</div>
|
| 1002 |
+
<div class="hero-foot">
|
| 1003 |
+
<a class="kernel-note-cta" href="https://x.com/xenovacom/status/2065656427117437213" target="_blank" rel="noopener">WebGPU kernels <b>100% written & optimized by Fable 5</b> →</a>
|
| 1004 |
+
<span class="hero-foot-note">Tuned for Apple M4 Max · experimental multimodal</span>
|
| 1005 |
+
</div>
|
| 1006 |
+
</div>
|
| 1007 |
+
</div>
|
| 1008 |
+
</div>
|
| 1009 |
+
<div class="scroll-cue" id="scrollCue">
|
| 1010 |
+
<span>Enter console</span>
|
| 1011 |
+
<div class="scroll-cue-line"></div>
|
| 1012 |
+
</div>
|
| 1013 |
+
</div>
|
| 1014 |
+
</section>
|
| 1015 |
+
|
| 1016 |
+
<section id="chat" class="screen">
|
| 1017 |
+
<header class="chat-head">
|
| 1018 |
+
<div class="chat-head-inner">
|
| 1019 |
+
<a class="to-top" href="#landing" id="toTop" title="Back to top">
|
| 1020 |
+
<svg class="br-mark small" viewBox="0 0 32 32" fill="none" aria-hidden="true"><path d="M4 3h10v10H4zM18 3h10v10H18zM4 17h10v12H4z" fill="currentColor"/><path d="M18 17h10v4H18zM18 25h10v4H18z" fill="currentColor" opacity=".62"/></svg>
|
| 1021 |
+
<span class="brand-name">BlackRiver · Gemma 4</span>
|
| 1022 |
+
</a>
|
| 1023 |
+
<div class="status" id="status">
|
| 1024 |
+
<span class="status-dot"></span>
|
| 1025 |
+
<span class="status-text" id="statusText">Not loaded</span>
|
| 1026 |
+
</div>
|
| 1027 |
+
<div class="chat-head-actions">
|
| 1028 |
+
<select id="modelSelect" class="head-btn" style="appearance:auto;background:var(--panel);cursor:pointer;padding:8px 12px;">
|
| 1029 |
+
<option value="onnx-community/gemma-4-E2B-it-ONNX">Gemma 4 E2B (2.3B)</option>
|
| 1030 |
+
<option value="onnx-community/gemma-4-E4B-it-ONNX">Gemma 4 E4B (4B)</option>
|
| 1031 |
+
</select>
|
| 1032 |
+
<button class="head-btn solid" id="headLoadBtn" type="button">Initialize</button>
|
| 1033 |
+
<button class="head-btn" id="kernelsBtn" type="button" hidden>View Kernels</button>
|
| 1034 |
+
<button class="head-btn" id="clearBtn" type="button" disabled>Clear</button>
|
| 1035 |
+
</div>
|
| 1036 |
+
</div>
|
| 1037 |
+
<div class="bar" id="bar"><div></div></div>
|
| 1038 |
+
</header>
|
| 1039 |
+
|
| 1040 |
+
<div class="thread-scroll" id="threadScroll">
|
| 1041 |
+
<div class="thread" id="thread">
|
| 1042 |
+
<div class="welcome" id="welcome">
|
| 1043 |
+
<svg class="welcome-mark" viewBox="0 0 32 32" fill="none" aria-hidden="true"><path d="M4 3h10v10H4zM18 3h10v10H18zM4 17h10v12H4z" fill="currentColor"/><path d="M18 17h10v4H18zM18 25h10v4H18z" fill="currentColor" opacity=".62"/></svg>
|
| 1044 |
+
<h2>What will you <span class="thin">explore?</span></h2>
|
| 1045 |
+
<p>Private on-device intelligence · Image · Audio · Text</p>
|
| 1046 |
+
<div class="seeds">
|
| 1047 |
+
<button class="seed" type="button" disabled>What does this image show?</button>
|
| 1048 |
+
<button class="seed" type="button" disabled>Transcribe this audio</button>
|
| 1049 |
+
<button class="seed" type="button" disabled>Write a haiku about on-device AI</button>
|
| 1050 |
+
</div>
|
| 1051 |
+
</div>
|
| 1052 |
+
</div>
|
| 1053 |
+
</div>
|
| 1054 |
+
|
| 1055 |
+
<footer class="composer-wrap">
|
| 1056 |
+
<div class="composer">
|
| 1057 |
+
<div id="attachments" class="attachments" style="display:none;"></div>
|
| 1058 |
+
<div class="composer-tools">
|
| 1059 |
+
<button class="tool-btn" id="imageBtn" type="button" disabled title="Attach image" aria-label="Attach image">
|
| 1060 |
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="18" height="18" rx="3"/><circle cx="8.5" cy="8.5" r="1.5"/><path d="M21 15l-5-5L5 21"/></svg>
|
| 1061 |
+
</button>
|
| 1062 |
+
<button class="tool-btn" id="audioBtn" type="button" disabled title="Record audio" aria-label="Record audio">
|
| 1063 |
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z"/><path d="M19 10v2a7 7 0 0 1-14 0v-2"/><line x1="12" y1="19" x2="12" y2="23"/><line x1="8" y1="23" x2="16" y2="23"/></svg>
|
| 1064 |
+
</button>
|
| 1065 |
+
</div>
|
| 1066 |
+
<div class="field">
|
| 1067 |
+
<textarea id="input" rows="1" placeholder="Initialize the model to begin..." disabled></textarea>
|
| 1068 |
+
<button class="icon-button send-button" id="sendBtn" type="button" disabled aria-label="Send message">
|
| 1069 |
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M5 12h14"/><path d="m13 6 6 6-6 6"/></svg>
|
| 1070 |
+
</button>
|
| 1071 |
+
<button class="icon-button stop-button" id="stopBtn" type="button" aria-label="Stop generation">
|
| 1072 |
+
<svg viewBox="0 0 24 24" fill="currentColor"><rect x="7" y="7" width="10" height="10" rx="1.5"/></svg>
|
| 1073 |
+
</button>
|
| 1074 |
+
</div>
|
| 1075 |
+
<div class="composer-meta">
|
| 1076 |
+
<span id="hint">BlackRiver private runtime · nothing leaves this device</span>
|
| 1077 |
+
<span id="liveStat"></span>
|
| 1078 |
+
</div>
|
| 1079 |
+
</div>
|
| 1080 |
+
</footer>
|
| 1081 |
+
</section>
|
| 1082 |
+
|
| 1083 |
+
<div class="kx" id="kernelsOverlay" hidden>
|
| 1084 |
+
<div class="kx-backdrop" data-close></div>
|
| 1085 |
+
<div class="kx-panel" role="dialog" aria-modal="true" aria-label="Rendered kernels">
|
| 1086 |
+
<div class="kx-head">
|
| 1087 |
+
<div class="kx-title">
|
| 1088 |
+
<h3>Compute kernels</h3>
|
| 1089 |
+
<span class="kx-sub" id="kxSub"></span>
|
| 1090 |
+
</div>
|
| 1091 |
+
<button class="kx-close" id="kxClose" type="button" aria-label="Close" data-close>
|
| 1092 |
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round"><path d="M6 6l12 12M18 6 6 18"/></svg>
|
| 1093 |
+
</button>
|
| 1094 |
+
</div>
|
| 1095 |
+
<div class="kx-body">
|
| 1096 |
+
<div class="kx-side"><div class="kx-list" id="kxList"></div></div>
|
| 1097 |
+
<div class="kx-view">
|
| 1098 |
+
<div class="kx-view-head">
|
| 1099 |
+
<span class="kx-name" id="kxName"></span>
|
| 1100 |
+
<div class="kx-view-actions">
|
| 1101 |
+
<span class="kx-lines" id="kxLines"></span>
|
| 1102 |
+
<button class="kx-copy" id="kxCopy" type="button">Copy</button>
|
| 1103 |
+
</div>
|
| 1104 |
+
</div>
|
| 1105 |
+
<pre class="kx-code"><code id="kxCode"></code></pre>
|
| 1106 |
+
</div>
|
| 1107 |
+
</div>
|
| 1108 |
+
</div>
|
| 1109 |
+
</div>
|
| 1110 |
+
|
| 1111 |
+
<input type="file" id="imageInput" accept="image/*" hidden>
|
| 1112 |
+
<script>
|
| 1113 |
+
// ES modules, WebGPU and microphone access are blocked when this HTML file is
|
| 1114 |
+
// opened directly. Keep the controls informative even though module scripts
|
| 1115 |
+
// cannot start under file://.
|
| 1116 |
+
if (location.protocol === "file:") {
|
| 1117 |
+
addEventListener("DOMContentLoaded", () => {
|
| 1118 |
+
const message = "Ouvrez l’application avec start.bat — localhost est requis pour WebGPU et le microphone.";
|
| 1119 |
+
const status = document.getElementById("status");
|
| 1120 |
+
const statusText = document.getElementById("statusText");
|
| 1121 |
+
const loadButtons = [document.getElementById("loadBtn"), document.getElementById("headLoadBtn")];
|
| 1122 |
+
status?.classList.add("error");
|
| 1123 |
+
if (statusText) statusText.textContent = message;
|
| 1124 |
+
for (const button of loadButtons) {
|
| 1125 |
+
if (!button) continue;
|
| 1126 |
+
button.disabled = false;
|
| 1127 |
+
button.title = message;
|
| 1128 |
+
button.addEventListener("click", () => {
|
| 1129 |
+
status?.classList.add("error");
|
| 1130 |
+
if (statusText) statusText.textContent = message;
|
| 1131 |
+
alert(message);
|
| 1132 |
+
});
|
| 1133 |
+
}
|
| 1134 |
+
});
|
| 1135 |
+
}
|
| 1136 |
+
</script>
|
| 1137 |
+
<script type="module" src="./landing.js"></script>
|
| 1138 |
+
<script>
|
| 1139 |
+
(function () {
|
| 1140 |
+
const fire = () => {
|
| 1141 |
+
document.getElementById("crt-frame")?.classList.add("visible");
|
| 1142 |
+
document.querySelector(".hero-fade")?.classList.add("in");
|
| 1143 |
+
document.querySelectorAll(".anim").forEach((el) => el.classList.add("in"));
|
| 1144 |
+
document.getElementById("scrollCue")?.classList.add("in");
|
| 1145 |
+
};
|
| 1146 |
+
requestAnimationFrame(() => requestAnimationFrame(fire));
|
| 1147 |
+
})();
|
| 1148 |
+
</script>
|
| 1149 |
+
|
| 1150 |
+
<script type="module">
|
| 1151 |
+
import { Gemma4Multimodal } from "./transformers-gemma4.js";
|
| 1152 |
+
|
| 1153 |
+
let marked = null;
|
| 1154 |
+
import("https://esm.sh/marked@17")
|
| 1155 |
+
.then((m) => { marked = m.marked; marked.use({ gfm: true, breaks: true }); })
|
| 1156 |
+
.catch(() => { marked = null; });
|
| 1157 |
+
|
| 1158 |
+
const $ = (id) => document.getElementById(id);
|
| 1159 |
+
const landing = $("landing");
|
| 1160 |
+
const chat = $("chat");
|
| 1161 |
+
const threadScroll = $("threadScroll");
|
| 1162 |
+
const thread = $("thread");
|
| 1163 |
+
const loadBtn = $("loadBtn");
|
| 1164 |
+
const loadBtnLabel = $("loadBtnLabel");
|
| 1165 |
+
const headLoadBtn = $("headLoadBtn");
|
| 1166 |
+
const statusEl = $("status");
|
| 1167 |
+
const statusText = $("statusText");
|
| 1168 |
+
const bar = $("bar");
|
| 1169 |
+
const barFill = bar.firstElementChild;
|
| 1170 |
+
const input = $("input");
|
| 1171 |
+
const sendBtn = $("sendBtn");
|
| 1172 |
+
const stopBtn = $("stopBtn");
|
| 1173 |
+
const clearBtn = $("clearBtn");
|
| 1174 |
+
const hint = $("hint");
|
| 1175 |
+
const liveStat = $("liveStat");
|
| 1176 |
+
const kernelsBtn = $("kernelsBtn");
|
| 1177 |
+
const kernelsOverlay = $("kernelsOverlay");
|
| 1178 |
+
const imageBtn = $("imageBtn");
|
| 1179 |
+
const audioBtn = $("audioBtn");
|
| 1180 |
+
const imageInput = $("imageInput");
|
| 1181 |
+
const attachmentsEl = $("attachments");
|
| 1182 |
+
|
| 1183 |
+
let model = null;
|
| 1184 |
+
let kernels = [];
|
| 1185 |
+
let messages = [];
|
| 1186 |
+
let abortController = null;
|
| 1187 |
+
let isGenerating = false;
|
| 1188 |
+
let isLoading = false;
|
| 1189 |
+
let attachments = [];
|
| 1190 |
+
let targetProgress = 0;
|
| 1191 |
+
let shownProgress = 0;
|
| 1192 |
+
let progressRaf = 0;
|
| 1193 |
+
|
| 1194 |
+
// Model ID comes from the dropdown selector
|
| 1195 |
+
|
| 1196 |
+
if (!navigator.gpu) {
|
| 1197 |
+
const msg = "WebGPU isn't available here. Try a recent Chrome, Edge, or Safari Technology Preview.";
|
| 1198 |
+
loadBtn.disabled = true;
|
| 1199 |
+
headLoadBtn.disabled = true;
|
| 1200 |
+
setStatus("error", msg);
|
| 1201 |
+
}
|
| 1202 |
+
|
| 1203 |
+
const modelSelect = $("modelSelect");
|
| 1204 |
+
const landingModelSelect = $("landingModelSelect");
|
| 1205 |
+
|
| 1206 |
+
modelSelect.addEventListener("change", () => {
|
| 1207 |
+
landingModelSelect.value = modelSelect.value;
|
| 1208 |
+
updateModelCard();
|
| 1209 |
+
});
|
| 1210 |
+
landingModelSelect.addEventListener("change", () => {
|
| 1211 |
+
modelSelect.value = landingModelSelect.value;
|
| 1212 |
+
updateModelCard();
|
| 1213 |
+
});
|
| 1214 |
+
|
| 1215 |
+
function getSelectedModelId() {
|
| 1216 |
+
return modelSelect.value || "onnx-community/gemma-4-E2B-it-ONNX";
|
| 1217 |
+
}
|
| 1218 |
+
|
| 1219 |
+
function updateModelCard() {
|
| 1220 |
+
const id = getSelectedModelId();
|
| 1221 |
+
const isE4B = id.includes("E4B");
|
| 1222 |
+
const stats = document.querySelectorAll(".hero-stats .stat-val");
|
| 1223 |
+
if (stats.length >= 4) {
|
| 1224 |
+
stats[0].textContent = isE4B ? "4B" : "2.3B";
|
| 1225 |
+
stats[2].textContent = isE4B ? "~20" : "~41";
|
| 1226 |
+
}
|
| 1227 |
+
}
|
| 1228 |
+
|
| 1229 |
+
loadBtn.addEventListener("click", loadModel);
|
| 1230 |
+
headLoadBtn.addEventListener("click", loadModel);
|
| 1231 |
+
sendBtn.addEventListener("click", send);
|
| 1232 |
+
stopBtn.addEventListener("click", () => abortController?.abort());
|
| 1233 |
+
clearBtn.addEventListener("click", clearChat);
|
| 1234 |
+
kernelsBtn.addEventListener("click", openKernels);
|
| 1235 |
+
kernelsOverlay.addEventListener("click", (e) => { if (e.target.closest("[data-close]")) closeKernels(); });
|
| 1236 |
+
$("kxList").addEventListener("scroll", updateListFade, { passive: true });
|
| 1237 |
+
$("kxCopy").addEventListener("click", copyKernel);
|
| 1238 |
+
document.addEventListener("keydown", (e) => { if (e.key === "Escape" && !kernelsOverlay.hidden) closeKernels(); });
|
| 1239 |
+
$("toTop").addEventListener("click", (e) => { e.preventDefault(); landing.scrollIntoView({ behavior: "smooth" }); });
|
| 1240 |
+
|
| 1241 |
+
input.addEventListener("input", () => { autoGrow(); refreshSend(); });
|
| 1242 |
+
input.addEventListener("keydown", (e) => {
|
| 1243 |
+
if (e.key === "Enter" && !e.shiftKey) { e.preventDefault(); if (!sendBtn.disabled) send(); }
|
| 1244 |
+
});
|
| 1245 |
+
document.addEventListener("click", (e) => {
|
| 1246 |
+
const seed = e.target.closest(".seed");
|
| 1247 |
+
if (!seed || seed.disabled || !model || isGenerating) return;
|
| 1248 |
+
input.value = seed.textContent;
|
| 1249 |
+
send();
|
| 1250 |
+
});
|
| 1251 |
+
|
| 1252 |
+
// ---- Multimodal attachment handling ----
|
| 1253 |
+
imageBtn.addEventListener("click", () => imageInput.click());
|
| 1254 |
+
imageInput.addEventListener("change", (e) => {
|
| 1255 |
+
for (const file of e.target.files) addImageAttachment(file);
|
| 1256 |
+
imageInput.value = "";
|
| 1257 |
+
});
|
| 1258 |
+
|
| 1259 |
+
// Files can also be pasted or dropped into the composer.
|
| 1260 |
+
document.addEventListener("paste", (e) => {
|
| 1261 |
+
if (!model || isGenerating) return;
|
| 1262 |
+
for (const file of [...(e.clipboardData?.files ?? [])]) {
|
| 1263 |
+
if (file.type.startsWith("image/")) addImageAttachment(file);
|
| 1264 |
+
else if (file.type.startsWith("audio/")) addAudioAttachment(file, file.name);
|
| 1265 |
+
}
|
| 1266 |
+
});
|
| 1267 |
+
const composer = document.querySelector(".composer");
|
| 1268 |
+
composer.addEventListener("dragover", (e) => { e.preventDefault(); });
|
| 1269 |
+
composer.addEventListener("drop", (e) => {
|
| 1270 |
+
e.preventDefault();
|
| 1271 |
+
if (!model || isGenerating) return;
|
| 1272 |
+
for (const file of [...(e.dataTransfer?.files ?? [])]) {
|
| 1273 |
+
if (file.type.startsWith("image/")) addImageAttachment(file);
|
| 1274 |
+
else if (file.type.startsWith("audio/")) addAudioAttachment(file, file.name);
|
| 1275 |
+
}
|
| 1276 |
+
});
|
| 1277 |
+
|
| 1278 |
+
let mediaRecorder = null;
|
| 1279 |
+
let audioChunks = [];
|
| 1280 |
+
let recordingStream = null;
|
| 1281 |
+
let recordingTimer = 0;
|
| 1282 |
+
audioBtn.addEventListener("click", async () => {
|
| 1283 |
+
if (mediaRecorder && mediaRecorder.state === "recording") {
|
| 1284 |
+
mediaRecorder.stop();
|
| 1285 |
+
audioBtn.classList.remove("recording");
|
| 1286 |
+
clearTimeout(recordingTimer);
|
| 1287 |
+
return;
|
| 1288 |
+
}
|
| 1289 |
+
try {
|
| 1290 |
+
recordingStream = await navigator.mediaDevices.getUserMedia({ audio: true });
|
| 1291 |
+
audioChunks = [];
|
| 1292 |
+
const mimeType = ["audio/webm;codecs=opus", "audio/webm", "audio/mp4"]
|
| 1293 |
+
.find((type) => MediaRecorder.isTypeSupported?.(type));
|
| 1294 |
+
mediaRecorder = new MediaRecorder(recordingStream, mimeType ? { mimeType } : undefined);
|
| 1295 |
+
mediaRecorder.ondataavailable = (e) => { if (e.data.size > 0) audioChunks.push(e.data); };
|
| 1296 |
+
mediaRecorder.onstop = async () => {
|
| 1297 |
+
clearTimeout(recordingTimer);
|
| 1298 |
+
audioBtn.classList.remove("recording");
|
| 1299 |
+
const blob = new Blob(audioChunks, { type: mediaRecorder.mimeType || "audio/webm" });
|
| 1300 |
+
await addAudioAttachment(blob);
|
| 1301 |
+
recordingStream?.getTracks().forEach(t => t.stop());
|
| 1302 |
+
recordingStream = null;
|
| 1303 |
+
};
|
| 1304 |
+
mediaRecorder.start();
|
| 1305 |
+
audioBtn.classList.add("recording");
|
| 1306 |
+
recordingTimer = setTimeout(() => {
|
| 1307 |
+
if (mediaRecorder?.state === "recording") mediaRecorder.stop();
|
| 1308 |
+
}, 30_000);
|
| 1309 |
+
} catch (err) {
|
| 1310 |
+
console.error("Audio recording failed:", err);
|
| 1311 |
+
recordingStream?.getTracks().forEach(t => t.stop());
|
| 1312 |
+
recordingStream = null;
|
| 1313 |
+
audioBtn.classList.remove("recording");
|
| 1314 |
+
setStatus("error", location.protocol === "file:"
|
| 1315 |
+
? "Microphone requires localhost or HTTPS"
|
| 1316 |
+
: "Microphone access denied or unavailable");
|
| 1317 |
+
}
|
| 1318 |
+
});
|
| 1319 |
+
|
| 1320 |
+
function addImageAttachment(file) {
|
| 1321 |
+
if (!file?.type?.startsWith("image/")) return;
|
| 1322 |
+
const url = URL.createObjectURL(file);
|
| 1323 |
+
const id = crypto.randomUUID();
|
| 1324 |
+
attachments.push({ id, type: "image", url, file, name: file.name });
|
| 1325 |
+
renderAttachments();
|
| 1326 |
+
refreshSend();
|
| 1327 |
+
}
|
| 1328 |
+
|
| 1329 |
+
async function addAudioAttachment(blob, suppliedName = "") {
|
| 1330 |
+
let decoded;
|
| 1331 |
+
try {
|
| 1332 |
+
decoded = await decodeAudioToPcm(blob);
|
| 1333 |
+
} catch (error) {
|
| 1334 |
+
console.error("Audio decoding failed:", error);
|
| 1335 |
+
setStatus("error", "Audio illisible — essayez un enregistrement plus long ou un fichier WAV.");
|
| 1336 |
+
return;
|
| 1337 |
+
}
|
| 1338 |
+
if (decoded.duration < 0.2 || decoded.pcm.length < 3200) {
|
| 1339 |
+
setStatus("error", "Enregistrement trop court — parlez pendant au moins une seconde.");
|
| 1340 |
+
return;
|
| 1341 |
+
}
|
| 1342 |
+
const url = URL.createObjectURL(blob);
|
| 1343 |
+
const id = crypto.randomUUID();
|
| 1344 |
+
const extension = blob.type.includes("mp4") ? "m4a" : blob.type.includes("wav") ? "wav" : "webm";
|
| 1345 |
+
attachments.push({
|
| 1346 |
+
id, type: "audio", url, blob,
|
| 1347 |
+
pcm: decoded.pcm,
|
| 1348 |
+
duration: decoded.duration,
|
| 1349 |
+
name: suppliedName || `recording-${Date.now()}.${extension}`,
|
| 1350 |
+
});
|
| 1351 |
+
renderAttachments();
|
| 1352 |
+
refreshSend();
|
| 1353 |
+
}
|
| 1354 |
+
|
| 1355 |
+
async function decodeAudioToPcm(blob) {
|
| 1356 |
+
const AudioContextClass = window.AudioContext || window.webkitAudioContext;
|
| 1357 |
+
if (!AudioContextClass) throw new Error("Web Audio is unavailable");
|
| 1358 |
+
const context = new AudioContextClass({ sampleRate: 16000 });
|
| 1359 |
+
try {
|
| 1360 |
+
const buffer = await context.decodeAudioData(await blob.arrayBuffer());
|
| 1361 |
+
const length = buffer.length;
|
| 1362 |
+
const mono = new Float32Array(length);
|
| 1363 |
+
for (let channel = 0; channel < buffer.numberOfChannels; channel++) {
|
| 1364 |
+
const data = buffer.getChannelData(channel);
|
| 1365 |
+
for (let i = 0; i < length; i++) mono[i] += data[i] / buffer.numberOfChannels;
|
| 1366 |
+
}
|
| 1367 |
+
const pcm = buffer.sampleRate === 16000 ? mono : resampleLinear(mono, buffer.sampleRate, 16000);
|
| 1368 |
+
return { pcm, duration: buffer.duration };
|
| 1369 |
+
} finally {
|
| 1370 |
+
await context.close();
|
| 1371 |
+
}
|
| 1372 |
+
}
|
| 1373 |
+
|
| 1374 |
+
function resampleLinear(inputSamples, fromRate, toRate) {
|
| 1375 |
+
const output = new Float32Array(Math.max(1, Math.round(inputSamples.length * toRate / fromRate)));
|
| 1376 |
+
const ratio = fromRate / toRate;
|
| 1377 |
+
for (let i = 0; i < output.length; i++) {
|
| 1378 |
+
const position = i * ratio;
|
| 1379 |
+
const left = Math.floor(position);
|
| 1380 |
+
const right = Math.min(left + 1, inputSamples.length - 1);
|
| 1381 |
+
const mix = position - left;
|
| 1382 |
+
output[i] = inputSamples[left] * (1 - mix) + inputSamples[right] * mix;
|
| 1383 |
+
}
|
| 1384 |
+
return output;
|
| 1385 |
+
}
|
| 1386 |
+
|
| 1387 |
+
function renderAttachments() {
|
| 1388 |
+
attachmentsEl.innerHTML = "";
|
| 1389 |
+
if (attachments.length === 0) { attachmentsEl.style.display = "none"; return; }
|
| 1390 |
+
attachmentsEl.style.display = "flex";
|
| 1391 |
+
for (const att of attachments) {
|
| 1392 |
+
const el = document.createElement("div");
|
| 1393 |
+
el.className = `attachment ${att.type}`;
|
| 1394 |
+
if (att.type === "image") {
|
| 1395 |
+
el.innerHTML = `<img src="${att.url}"><span class="att-name">${escapeHtml(att.name)}</span><span class="att-type">IMG</span><button class="att-remove" data-id="${att.id}">×</button>`;
|
| 1396 |
+
} else {
|
| 1397 |
+
const duration = finiteNumber(att.duration) ? ` · ${att.duration.toFixed(1)}s` : "";
|
| 1398 |
+
el.innerHTML = `<span class="att-icon">🎙</span><span class="att-name">${escapeHtml(att.name)}</span><span class="att-type">AUDIO${duration}</span><button class="att-remove" data-id="${att.id}">×</button>`;
|
| 1399 |
+
}
|
| 1400 |
+
el.querySelector(".att-remove").addEventListener("click", () => {
|
| 1401 |
+
attachments = attachments.filter(a => a.id !== att.id);
|
| 1402 |
+
URL.revokeObjectURL(att.url);
|
| 1403 |
+
renderAttachments();
|
| 1404 |
+
refreshSend();
|
| 1405 |
+
});
|
| 1406 |
+
attachmentsEl.appendChild(el);
|
| 1407 |
+
}
|
| 1408 |
+
}
|
| 1409 |
+
|
| 1410 |
+
function setStatus(state, text) {
|
| 1411 |
+
statusEl.className = "status" + (state ? " " + state : "");
|
| 1412 |
+
if (text !== undefined) statusText.innerHTML = text;
|
| 1413 |
+
}
|
| 1414 |
+
|
| 1415 |
+
async function loadModel() {
|
| 1416 |
+
if (model || isLoading) return;
|
| 1417 |
+
isLoading = true;
|
| 1418 |
+
loadBtn.disabled = true;
|
| 1419 |
+
headLoadBtn.disabled = true;
|
| 1420 |
+
modelSelect.disabled = true;
|
| 1421 |
+
landingModelSelect.disabled = true;
|
| 1422 |
+
loadBtnLabel.textContent = "Loading…";
|
| 1423 |
+
bar.classList.remove("done");
|
| 1424 |
+
setProgressImmediate(0.02);
|
| 1425 |
+
setStatus("loading", "Requesting WebGPU device…");
|
| 1426 |
+
chat.scrollIntoView({ behavior: "smooth" });
|
| 1427 |
+
|
| 1428 |
+
const started = performance.now();
|
| 1429 |
+
try {
|
| 1430 |
+
const selectedModelId = getSelectedModelId();
|
| 1431 |
+
model = await Gemma4Multimodal.load(selectedModelId, { onProgress: updateLoadProgress });
|
| 1432 |
+
|
| 1433 |
+
const seconds = ((performance.now() - started) / 1000).toFixed(1);
|
| 1434 |
+
setStatus("ready", `Ready in <strong>${seconds}s</strong> · multimodal · on-device`);
|
| 1435 |
+
setProgressImmediate(1);
|
| 1436 |
+
bar.classList.add("done");
|
| 1437 |
+
loadBtnLabel.textContent = "Model loaded";
|
| 1438 |
+
headLoadBtn.style.display = "none";
|
| 1439 |
+
enableChat();
|
| 1440 |
+
} catch (error) {
|
| 1441 |
+
console.error(error);
|
| 1442 |
+
setStatus("error", `Failed to load: ${escapeHtml(String(error?.message ?? error))}`);
|
| 1443 |
+
bar.classList.add("done");
|
| 1444 |
+
loadBtn.disabled = false;
|
| 1445 |
+
headLoadBtn.disabled = false;
|
| 1446 |
+
modelSelect.disabled = false;
|
| 1447 |
+
landingModelSelect.disabled = false;
|
| 1448 |
+
loadBtnLabel.textContent = "Initialize model";
|
| 1449 |
+
isLoading = false;
|
| 1450 |
+
}
|
| 1451 |
+
}
|
| 1452 |
+
|
| 1453 |
+
function labelFor(status) {
|
| 1454 |
+
return {
|
| 1455 |
+
init: "Requesting WebGPU device…",
|
| 1456 |
+
tokenizer: "Loading tokenizer…",
|
| 1457 |
+
weights: "Downloading weights…",
|
| 1458 |
+
encoder: "Loading vision/audio encoder…",
|
| 1459 |
+
ready: "Ready.",
|
| 1460 |
+
}[status] ?? status;
|
| 1461 |
+
}
|
| 1462 |
+
|
| 1463 |
+
function updateLoadProgress(event) {
|
| 1464 |
+
if (event.status !== "weights") {
|
| 1465 |
+
setStatus("loading", labelFor(event.status));
|
| 1466 |
+
setPhaseProgress(event.status, event.fraction);
|
| 1467 |
+
return;
|
| 1468 |
+
}
|
| 1469 |
+
const kind = event.kind ?? inferProgressKind(event);
|
| 1470 |
+
const fraction = finiteNumber(event.fraction) ? clamp(event.fraction, 0, 1) : null;
|
| 1471 |
+
if (kind !== "tensors") setPhaseProgress("weights", fraction);
|
| 1472 |
+
setStatus("loading", formatWeightProgress(event, fraction));
|
| 1473 |
+
}
|
| 1474 |
+
|
| 1475 |
+
function setPhaseProgress(status, frac) {
|
| 1476 |
+
const [lo, hi] = status === "weights"
|
| 1477 |
+
? [0.04, 1.0]
|
| 1478 |
+
: ({ init: [0, 0.02], tokenizer: [0.02, 0.04], encoder: [0.04, 0.06], ready: [1, 1] }[status] ?? [0, 1]);
|
| 1479 |
+
const f = finiteNumber(frac) ? clamp(frac, 0, 1) : 0;
|
| 1480 |
+
setProgressFraction(lo + (hi - lo) * f);
|
| 1481 |
+
}
|
| 1482 |
+
|
| 1483 |
+
function formatWeightProgress(event, fraction) {
|
| 1484 |
+
const kind = event.kind ?? inferProgressKind(event);
|
| 1485 |
+
const pct = fraction === null ? "" : ` (${Math.round(fraction * 100)}%)`;
|
| 1486 |
+
const loaded = finiteNumber(event.loaded) ? event.loaded : null;
|
| 1487 |
+
const total = finiteNumber(event.total) ? event.total : null;
|
| 1488 |
+
if (kind === "bytes") {
|
| 1489 |
+
const verb = event.fromCache ? "Loading cached weights" : "Downloading weights";
|
| 1490 |
+
if (loaded !== null && total !== null) return `${verb}: ${formatBytes(loaded)} / ${formatBytes(total)}${pct}`;
|
| 1491 |
+
if (total !== null) return `${verb}: ${formatBytes(total)} total`;
|
| 1492 |
+
return `${escapeHtml(event.message || verb)}…`;
|
| 1493 |
+
}
|
| 1494 |
+
if (loaded !== null && total !== null) {
|
| 1495 |
+
const label = event.message ? ` (${escapeHtml(event.message)})` : "";
|
| 1496 |
+
return `Preparing GPU weights: ${formatInteger(loaded)} / ${formatInteger(total)} tensors${pct}${label}`;
|
| 1497 |
+
}
|
| 1498 |
+
return event.message ? `Preparing GPU weights: ${escapeHtml(event.message)}` : "Preparing GPU weights…";
|
| 1499 |
+
}
|
| 1500 |
+
|
| 1501 |
+
function inferProgressKind(event) {
|
| 1502 |
+
if (event.kind === "bytes" || event.kind === "tensors") return event.kind;
|
| 1503 |
+
if (finiteNumber(event.total) && event.total > 1_000_000) return "bytes";
|
| 1504 |
+
return "tensors";
|
| 1505 |
+
}
|
| 1506 |
+
|
| 1507 |
+
function setProgressFraction(value) {
|
| 1508 |
+
if (!finiteNumber(value)) return;
|
| 1509 |
+
targetProgress = Math.max(clamp(value, 0, 1), targetProgress);
|
| 1510 |
+
if (!progressRaf) progressRaf = requestAnimationFrame(stepProgressBar);
|
| 1511 |
+
}
|
| 1512 |
+
|
| 1513 |
+
function stepProgressBar() {
|
| 1514 |
+
const gap = targetProgress - shownProgress;
|
| 1515 |
+
shownProgress += gap < 0.0015 ? gap : gap * 0.3;
|
| 1516 |
+
barFill.style.width = `${(shownProgress * 100).toFixed(2)}%`;
|
| 1517 |
+
progressRaf = shownProgress < targetProgress ? requestAnimationFrame(stepProgressBar) : 0;
|
| 1518 |
+
}
|
| 1519 |
+
|
| 1520 |
+
function setProgressImmediate(value) {
|
| 1521 |
+
if (progressRaf) { cancelAnimationFrame(progressRaf); progressRaf = 0; }
|
| 1522 |
+
targetProgress = shownProgress = clamp(value, 0, 1);
|
| 1523 |
+
barFill.style.width = `${(shownProgress * 100).toFixed(2)}%`;
|
| 1524 |
+
}
|
| 1525 |
+
|
| 1526 |
+
function enableChat() {
|
| 1527 |
+
isLoading = false;
|
| 1528 |
+
input.disabled = false;
|
| 1529 |
+
input.placeholder = "Message Gemma 4 · image, audio or text…";
|
| 1530 |
+
clearBtn.disabled = false;
|
| 1531 |
+
kernelsBtn.hidden = true;
|
| 1532 |
+
imageBtn.disabled = false;
|
| 1533 |
+
audioBtn.disabled = false;
|
| 1534 |
+
setSeedButtonsEnabled(true);
|
| 1535 |
+
refreshSend();
|
| 1536 |
+
input.focus();
|
| 1537 |
+
}
|
| 1538 |
+
|
| 1539 |
+
function setSeedButtonsEnabled(enabled) {
|
| 1540 |
+
document.querySelectorAll(".seed").forEach((s) => { s.disabled = !enabled; });
|
| 1541 |
+
}
|
| 1542 |
+
|
| 1543 |
+
function autoGrow() {
|
| 1544 |
+
input.style.height = "auto";
|
| 1545 |
+
input.style.height = Math.min(input.scrollHeight, 180) + "px";
|
| 1546 |
+
}
|
| 1547 |
+
|
| 1548 |
+
function refreshSend() {
|
| 1549 |
+
sendBtn.disabled = input.value.trim().length === 0 && attachments.length === 0;
|
| 1550 |
+
}
|
| 1551 |
+
|
| 1552 |
+
input.addEventListener("input", refreshSend);
|
| 1553 |
+
attachmentsEl.addEventListener("change", refreshSend);
|
| 1554 |
+
|
| 1555 |
+
async function send() {
|
| 1556 |
+
if (!model || isGenerating || (input.value.trim().length === 0 && attachments.length === 0)) return;
|
| 1557 |
+
const text = input.value.trim();
|
| 1558 |
+
const currentAttachments = [...attachments];
|
| 1559 |
+
attachments = [];
|
| 1560 |
+
renderAttachments();
|
| 1561 |
+
input.value = "";
|
| 1562 |
+
autoGrow();
|
| 1563 |
+
refreshSend();
|
| 1564 |
+
|
| 1565 |
+
const userMsg = { role: "user", content: text, attachments: currentAttachments };
|
| 1566 |
+
messages.push(userMsg);
|
| 1567 |
+
|
| 1568 |
+
const userEl = renderMessage("user", text, currentAttachments);
|
| 1569 |
+
thread.appendChild(userEl);
|
| 1570 |
+
scrollToBottom();
|
| 1571 |
+
|
| 1572 |
+
const assistantEl = renderMessage("assistant", "");
|
| 1573 |
+
const bubble = assistantEl.querySelector(".bubble");
|
| 1574 |
+
const thinking = document.createElement("div");
|
| 1575 |
+
thinking.className = "thinking";
|
| 1576 |
+
thinking.innerHTML = "<span></span><span></span><span></span>";
|
| 1577 |
+
bubble.appendChild(thinking);
|
| 1578 |
+
thread.appendChild(assistantEl);
|
| 1579 |
+
scrollToBottom();
|
| 1580 |
+
|
| 1581 |
+
abortController = new AbortController();
|
| 1582 |
+
isGenerating = true;
|
| 1583 |
+
sendBtn.style.display = "none";
|
| 1584 |
+
stopBtn.style.display = "grid";
|
| 1585 |
+
|
| 1586 |
+
try {
|
| 1587 |
+
let fullText = "";
|
| 1588 |
+
const stream = model.generate(messages, {
|
| 1589 |
+
maxNewTokens: 1024,
|
| 1590 |
+
signal: abortController.signal,
|
| 1591 |
+
});
|
| 1592 |
+
|
| 1593 |
+
thinking.remove();
|
| 1594 |
+
let lastLen = 0;
|
| 1595 |
+
for await (const chunk of stream) {
|
| 1596 |
+
fullText = chunk.text;
|
| 1597 |
+
bubble.innerHTML = renderMarkdown(fullText);
|
| 1598 |
+
if (bubble.innerHTML.length !== lastLen) {
|
| 1599 |
+
scrollToBottom();
|
| 1600 |
+
lastLen = bubble.innerHTML.length;
|
| 1601 |
+
}
|
| 1602 |
+
if (liveStat) liveStat.textContent = `${fullText.length} chars`;
|
| 1603 |
+
}
|
| 1604 |
+
|
| 1605 |
+
messages.push({ role: "assistant", content: fullText });
|
| 1606 |
+
const meta = document.createElement("div");
|
| 1607 |
+
meta.className = "meta";
|
| 1608 |
+
meta.textContent = `${fullText.length} chars`;
|
| 1609 |
+
assistantEl.appendChild(meta);
|
| 1610 |
+
} catch (err) {
|
| 1611 |
+
if (err?.name !== "AbortError") {
|
| 1612 |
+
thinking.remove();
|
| 1613 |
+
bubble.textContent = `Error: ${err?.message ?? err}`;
|
| 1614 |
+
console.error(err);
|
| 1615 |
+
}
|
| 1616 |
+
} finally {
|
| 1617 |
+
isGenerating = false;
|
| 1618 |
+
sendBtn.style.display = "grid";
|
| 1619 |
+
stopBtn.style.display = "none";
|
| 1620 |
+
}
|
| 1621 |
+
}
|
| 1622 |
+
|
| 1623 |
+
function renderMessage(role, text, atts = []) {
|
| 1624 |
+
const el = document.createElement("div");
|
| 1625 |
+
el.className = `msg ${role}`;
|
| 1626 |
+
const roleEl = document.createElement("div");
|
| 1627 |
+
roleEl.className = "role";
|
| 1628 |
+
roleEl.textContent = role;
|
| 1629 |
+
el.appendChild(roleEl);
|
| 1630 |
+
const bubble = document.createElement("div");
|
| 1631 |
+
bubble.className = `bubble ${role}`;
|
| 1632 |
+
if (role === "user" && atts.length > 0) {
|
| 1633 |
+
const attContainer = document.createElement("div");
|
| 1634 |
+
attContainer.style.cssText = "display:flex;flex-wrap:wrap;gap:6px;margin-bottom:8px;";
|
| 1635 |
+
for (const att of atts) {
|
| 1636 |
+
if (att.type === "image") {
|
| 1637 |
+
const img = document.createElement("img");
|
| 1638 |
+
img.src = att.url;
|
| 1639 |
+
img.style.cssText = "max-width:200px;max-height:200px;border-radius:8px;";
|
| 1640 |
+
attContainer.appendChild(img);
|
| 1641 |
+
} else {
|
| 1642 |
+
const badge = document.createElement("span");
|
| 1643 |
+
badge.textContent = "🎙 Audio";
|
| 1644 |
+
badge.style.cssText = "font-family:var(--mono);font-size:11px;padding:4px 8px;background:var(--panel);border:1px solid var(--line);border-radius:6px;";
|
| 1645 |
+
attContainer.appendChild(badge);
|
| 1646 |
+
}
|
| 1647 |
+
}
|
| 1648 |
+
bubble.appendChild(attContainer);
|
| 1649 |
+
}
|
| 1650 |
+
if (text) bubble.appendChild(document.createTextNode(text));
|
| 1651 |
+
el.appendChild(bubble);
|
| 1652 |
+
return el;
|
| 1653 |
+
}
|
| 1654 |
+
|
| 1655 |
+
function clearChat() {
|
| 1656 |
+
for (const message of messages) {
|
| 1657 |
+
for (const att of message.attachments ?? []) URL.revokeObjectURL(att.url);
|
| 1658 |
+
}
|
| 1659 |
+
messages = [];
|
| 1660 |
+
thread.innerHTML = "";
|
| 1661 |
+
const welcome = document.createElement("div");
|
| 1662 |
+
welcome.className = "welcome";
|
| 1663 |
+
welcome.id = "welcome";
|
| 1664 |
+
welcome.innerHTML = `
|
| 1665 |
+
<svg class="welcome-mark" viewBox="0 0 32 32" fill="none" aria-hidden="true"><path d="M4 3h10v10H4zM18 3h10v10H18zM4 17h10v12H4z" fill="currentColor"/><path d="M18 17h10v4H18zM18 25h10v4H18z" fill="currentColor" opacity=".62"/></svg>
|
| 1666 |
+
<h2>What will you <span class="thin">explore?</span></h2>
|
| 1667 |
+
<p>Private on-device intelligence · Image · Audio · Text</p>
|
| 1668 |
+
<div class="seeds">
|
| 1669 |
+
<button class="seed" type="button">What does this image show?</button>
|
| 1670 |
+
<button class="seed" type="button">Transcribe this audio</button>
|
| 1671 |
+
<button class="seed" type="button">Write a haiku about on-device AI</button>
|
| 1672 |
+
</div>
|
| 1673 |
+
`;
|
| 1674 |
+
thread.appendChild(welcome);
|
| 1675 |
+
setSeedButtonsEnabled(!!model);
|
| 1676 |
+
model?.reset?.();
|
| 1677 |
+
}
|
| 1678 |
+
|
| 1679 |
+
function renderMarkdown(text) {
|
| 1680 |
+
if (marked) return marked.parse(text);
|
| 1681 |
+
return escapeHtml(text).replace(/\n/g, "<br>");
|
| 1682 |
+
}
|
| 1683 |
+
|
| 1684 |
+
function scrollToBottom() {
|
| 1685 |
+
threadScroll.scrollTo({ top: threadScroll.scrollHeight, behavior: "smooth" });
|
| 1686 |
+
}
|
| 1687 |
+
|
| 1688 |
+
// ---- Kernels viewer ----
|
| 1689 |
+
function openKernels() {
|
| 1690 |
+
if (!model) return;
|
| 1691 |
+
kernels = model.runtime.getRenderedShaders?.() ?? [];
|
| 1692 |
+
const list = $("kxList");
|
| 1693 |
+
list.replaceChildren();
|
| 1694 |
+
for (let i = 0; i < kernels.length; i++) {
|
| 1695 |
+
const item = document.createElement("button");
|
| 1696 |
+
item.className = "kx-item";
|
| 1697 |
+
item.textContent = kernels[i].name;
|
| 1698 |
+
item.addEventListener("click", () => selectKernel(i));
|
| 1699 |
+
list.appendChild(item);
|
| 1700 |
+
}
|
| 1701 |
+
$("kxSub").textContent = `${kernels.length} rendered WGSL shaders on ${model.deviceInfo?.vendor ?? "unknown"} ${model.deviceInfo?.architecture ?? ""}`.trim();
|
| 1702 |
+
kernelsOverlay.hidden = false;
|
| 1703 |
+
document.body.classList.add("kx-locked");
|
| 1704 |
+
updateListFade();
|
| 1705 |
+
if (kernels.length > 0) selectKernel(0);
|
| 1706 |
+
}
|
| 1707 |
+
|
| 1708 |
+
function selectKernel(index) {
|
| 1709 |
+
const k = kernels[index];
|
| 1710 |
+
if (!k) return;
|
| 1711 |
+
document.querySelectorAll(".kx-item").forEach((el, i) => el.classList.toggle("active", i === index));
|
| 1712 |
+
$("kxName").textContent = k.name;
|
| 1713 |
+
$("kxLines").textContent = `${k.source.split("\n").length} lines`;
|
| 1714 |
+
$("kxCode").innerHTML = highlightWgsl(k.source);
|
| 1715 |
+
kxCopySource = k.source;
|
| 1716 |
+
updateListFade();
|
| 1717 |
+
}
|
| 1718 |
+
|
| 1719 |
+
function updateListFade() {
|
| 1720 |
+
const list = $("kxList");
|
| 1721 |
+
const side = list.parentElement;
|
| 1722 |
+
side.classList.toggle("at-end", list.scrollTop + list.clientHeight >= list.scrollHeight - 2);
|
| 1723 |
+
}
|
| 1724 |
+
|
| 1725 |
+
function closeKernels() {
|
| 1726 |
+
kernelsOverlay.hidden = true;
|
| 1727 |
+
document.body.classList.remove("kx-locked");
|
| 1728 |
+
}
|
| 1729 |
+
|
| 1730 |
+
function copyKernel() {
|
| 1731 |
+
navigator.clipboard.writeText(kxCopySource);
|
| 1732 |
+
const btn = $("kxCopy");
|
| 1733 |
+
const orig = btn.textContent;
|
| 1734 |
+
btn.textContent = "Copied!";
|
| 1735 |
+
setTimeout(() => { btn.textContent = orig; }, 1500);
|
| 1736 |
+
}
|
| 1737 |
+
|
| 1738 |
+
let kxCopySource = "";
|
| 1739 |
+
|
| 1740 |
+
function highlightWgsl(source) {
|
| 1741 |
+
let s = escapeHtml(source);
|
| 1742 |
+
s = s.replace(/\/\/[^\n]*/g, '<span class="k-cm">$&</span>');
|
| 1743 |
+
s = s.replace(/\b(fn|var|let|const|for|if|else|while|loop|break|continue|return|struct|enable|@compute|@workgroup_size|@group|@binding|@builtin|@stage)\b/g, '<span class="k-kw">$&</span>');
|
| 1744 |
+
s = s.replace(/\b(f32|u32|i32|bool|vec2|vec3|vec4|mat4x4|mat3x3|array|ptr|void)\b/g, '<span class="k-ty">$&</span>');
|
| 1745 |
+
s = s.replace(/@[\w]+/g, '<span class="k-at">$&</span>');
|
| 1746 |
+
s = s.replace(/\b\d+\.?\d*[fu]?\b/g, '<span class="k-nu">$&</span>');
|
| 1747 |
+
return `<code>${s}</code>`;
|
| 1748 |
+
}
|
| 1749 |
+
|
| 1750 |
+
// ---- Helpers ----
|
| 1751 |
+
function escapeHtml(s) { return String(s).replace(/[&<>"']/g, c => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c])); }
|
| 1752 |
+
function clamp(v, lo, hi) { return Math.min(Math.max(v, lo), hi); }
|
| 1753 |
+
function finiteNumber(v) { return typeof v === "number" && Number.isFinite(v); }
|
| 1754 |
+
function formatBytes(n) { if (n < 1024) return `${n} B`; if (n < 1048576) return `${(n/1024).toFixed(1)} KB`; if (n < 1073741824) return `${(n/1048576).toFixed(1)} MB`; return `${(n/1073741824).toFixed(2)} GB`; }
|
| 1755 |
+
function formatInteger(n) { return Math.floor(n).toLocaleString(); }
|
| 1756 |
+
</script>
|
| 1757 |
+
</body>
|
| 1758 |
+
</html>
|
landing.js
ADDED
|
@@ -0,0 +1,717 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import * as THREE from 'three';
|
| 2 |
+
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
|
| 3 |
+
import { EffectComposer } from 'three/examples/jsm/postprocessing/EffectComposer.js';
|
| 4 |
+
import { RenderPass } from 'three/examples/jsm/postprocessing/RenderPass.js';
|
| 5 |
+
import { ShaderPass } from 'three/examples/jsm/postprocessing/ShaderPass.js';
|
| 6 |
+
import { OutputPass } from 'three/examples/jsm/postprocessing/OutputPass.js';
|
| 7 |
+
|
| 8 |
+
// ============ DEVICE DETECTION ============
|
| 9 |
+
const isMobile = /Android|iPhone|iPad|iPod|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
|
| 10 |
+
|| (navigator.maxTouchPoints > 1 && window.innerWidth < 1024);
|
| 11 |
+
const gpuTier = (() => {
|
| 12 |
+
const gl = document.createElement('canvas').getContext('webgl');
|
| 13 |
+
if (!gl) return 'low';
|
| 14 |
+
const ext = gl.getExtension('WEBGL_debug_renderer_info');
|
| 15 |
+
const gpu = ext ? gl.getParameter(ext.UNMASKED_RENDERER_WEBGL).toLowerCase() : '';
|
| 16 |
+
// Apple GPU = Apple Silicon (M1/M2/M3/M4) — these are high-tier
|
| 17 |
+
if (/apple gpu|apple m/.test(gpu)) return 'high';
|
| 18 |
+
// Low-tier: old Intel integrated, software renderers, old mobile chips
|
| 19 |
+
if (/swiftshader|llvmpipe|mali-4|adreno 3/.test(gpu)) return 'low';
|
| 20 |
+
if (/intel(?!.*(iris|uhd|arc))/.test(gpu)) return 'low';
|
| 21 |
+
// Mid-tier: mid-range mobile, Intel Iris/UHD, older discrete
|
| 22 |
+
if (/mali-g[567]|adreno [45]|intel (iris|uhd)|geforce (mx|gt)|radeon (rx )?(5[0-4]|vega 8)/.test(gpu)) return 'mid';
|
| 23 |
+
// Everything else (RTX, RX 6000+, Arc, etc.) = high
|
| 24 |
+
return 'high';
|
| 25 |
+
})();
|
| 26 |
+
|
| 27 |
+
const qualityPresets = {
|
| 28 |
+
low: { pixelRatio: 1.0, marchSteps: 48, aoSteps: 2, dotSize: 6.0, dotGap: 3.0, scanlines: 0.55, bloomEnabled: false },
|
| 29 |
+
mid: { pixelRatio: 1.25, marchSteps: 64, aoSteps: 3, dotSize: 5.0, dotGap: 2.5, scanlines: 0.75, bloomEnabled: true },
|
| 30 |
+
high: { pixelRatio: 1.5, marchSteps: 80, aoSteps: 3, dotSize: 5.0, dotGap: 2.5, scanlines: 0.75, bloomEnabled: true },
|
| 31 |
+
};
|
| 32 |
+
let currentTier = isMobile ? 'low' : gpuTier;
|
| 33 |
+
let quality = { ...qualityPresets[currentTier] };
|
| 34 |
+
|
| 35 |
+
// ============ SETTINGS ============
|
| 36 |
+
const settings = {
|
| 37 |
+
dither: { enabled: true, dotSize: quality.dotSize, dotGap: quality.dotGap, brightness: 0.85, contrast: 0.60, threshold: 0.03, dotColor: [1.0, 1.0, 1.0], bgColor: [0.00784, 0.00784, 0.01176] },
|
| 38 |
+
crosshatch: { enabled: false, intensity: 0.95, angle: 0.4363 },
|
| 39 |
+
bloom: { enabled: quality.bloomEnabled, intensity: 0.55, size: 1.50 },
|
| 40 |
+
crt: { enabled: true, curvature: 0.0, scanlines: quality.scanlines, vignette: 2.00, chroma: 0.0 },
|
| 41 |
+
scene: { gooeyness: 1.20, speed: 0.85 }
|
| 42 |
+
};
|
| 43 |
+
|
| 44 |
+
// ============ MOUSE TRACKING ============
|
| 45 |
+
const mouse = new THREE.Vector2(0, 0);
|
| 46 |
+
let mouseInScene = false;
|
| 47 |
+
let mousePressed = false;
|
| 48 |
+
let mouseSphereRadius = 0.0;
|
| 49 |
+
const mouseSphereTargetRadius = 0.55;
|
| 50 |
+
const mouseSphereClickRadius = 0.95;
|
| 51 |
+
const mouseWorld = new THREE.Vector3(0, 0, 0);
|
| 52 |
+
const mouseWorldTarget = new THREE.Vector3(0, 0, 0);
|
| 53 |
+
const mouseDamping = 0.15;
|
| 54 |
+
|
| 55 |
+
// ============ THREE.JS SETUP ============
|
| 56 |
+
const scene = new THREE.Scene();
|
| 57 |
+
scene.background = new THREE.Color(0x020203);
|
| 58 |
+
|
| 59 |
+
const crtFrame = document.getElementById('crt-frame');
|
| 60 |
+
const getSize = () => {
|
| 61 |
+
return { width: window.innerWidth, height: window.innerHeight };
|
| 62 |
+
};
|
| 63 |
+
let size = getSize();
|
| 64 |
+
|
| 65 |
+
const camera = new THREE.PerspectiveCamera(60, size.width / size.height, 0.1, 100);
|
| 66 |
+
camera.position.set(0, 0, 5);
|
| 67 |
+
const renderer = new THREE.WebGLRenderer({ antialias: false, powerPreference: 'high-performance' });
|
| 68 |
+
renderer.setSize(size.width, size.height);
|
| 69 |
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio, quality.pixelRatio));
|
| 70 |
+
crtFrame.appendChild(renderer.domElement);
|
| 71 |
+
|
| 72 |
+
const controls = new OrbitControls(camera, renderer.domElement);
|
| 73 |
+
controls.enableDamping = true;
|
| 74 |
+
controls.dampingFactor = 0.05;
|
| 75 |
+
controls.enableZoom = false;
|
| 76 |
+
controls.enablePan = false;
|
| 77 |
+
controls.enableRotate = false;
|
| 78 |
+
controls.enabled = false; // prevent OrbitControls from capturing scroll/pointer events
|
| 79 |
+
|
| 80 |
+
// ============ INPUT EVENTS ============
|
| 81 |
+
let pageVisible = true;
|
| 82 |
+
// Render only while the hero canvas is actually on screen. When the chat view scrolls into
|
| 83 |
+
// place the background pauses itself (below), freeing the GPU for the WebGPU model so decode
|
| 84 |
+
// throughput isn't dragged down by the WebGL background.
|
| 85 |
+
let heroOnScreen = true;
|
| 86 |
+
const onPointerMove = (e) => {
|
| 87 |
+
mouseInScene = true;
|
| 88 |
+
const x = e.clientX ?? (e.touches && e.touches[0] ? e.touches[0].clientX : 0);
|
| 89 |
+
const y = e.clientY ?? (e.touches && e.touches[0] ? e.touches[0].clientY : 0);
|
| 90 |
+
mouse.x = (x / window.innerWidth) * 2 - 1;
|
| 91 |
+
mouse.y = -(y / window.innerHeight) * 2 + 1;
|
| 92 |
+
};
|
| 93 |
+
document.addEventListener('mousemove', onPointerMove, { passive: true });
|
| 94 |
+
document.addEventListener('touchmove', onPointerMove, { passive: true });
|
| 95 |
+
document.addEventListener('mouseenter', () => { mouseInScene = true; }, { passive: true });
|
| 96 |
+
document.addEventListener('mouseleave', () => { mouseInScene = false; }, { passive: true });
|
| 97 |
+
document.addEventListener('touchstart', (e) => { mouseInScene = true; mousePressed = true; onPointerMove(e); }, { passive: true });
|
| 98 |
+
document.addEventListener('touchend', () => { mousePressed = false; mouseInScene = false; }, { passive: true });
|
| 99 |
+
document.addEventListener('visibilitychange', () => {
|
| 100 |
+
pageVisible = !document.hidden;
|
| 101 |
+
if (document.hidden) mouseInScene = false;
|
| 102 |
+
});
|
| 103 |
+
// Pause the WebGL background as soon as the chat view dominates the screen, so it never competes
|
| 104 |
+
// with the WebGPU model for the GPU. Resume when scrolling back to the landing. Falls back to the
|
| 105 |
+
// hero canvas's own visibility if there is no #chat section on the page.
|
| 106 |
+
const chatSection = document.getElementById('chat');
|
| 107 |
+
if (chatSection) {
|
| 108 |
+
new IntersectionObserver(([entry]) => { heroOnScreen = entry.intersectionRatio < 0.4; }, { threshold: [0, 0.4, 1] }).observe(chatSection);
|
| 109 |
+
} else {
|
| 110 |
+
new IntersectionObserver(([entry]) => { heroOnScreen = entry.isIntersecting; }, { threshold: 0 }).observe(crtFrame);
|
| 111 |
+
}
|
| 112 |
+
document.addEventListener('mousedown', () => { mousePressed = true; }, { passive: true });
|
| 113 |
+
document.addEventListener('mouseup', () => { mousePressed = false; }, { passive: true });
|
| 114 |
+
|
| 115 |
+
// ============ RAYMARCHING QUAD ============
|
| 116 |
+
const quadGeometry = new THREE.PlaneGeometry(2, 2);
|
| 117 |
+
const quadMaterial = new THREE.ShaderMaterial({
|
| 118 |
+
uniforms: {
|
| 119 |
+
uTime: { value: 0 },
|
| 120 |
+
uResolution: { value: new THREE.Vector2(size.width, size.height) },
|
| 121 |
+
uCameraPos: { value: camera.position.clone() },
|
| 122 |
+
uCameraTarget: { value: new THREE.Vector3(0, 0, 0) },
|
| 123 |
+
uPixelRatio: { value: Math.min(window.devicePixelRatio, 1.5) },
|
| 124 |
+
uGooeyness: { value: settings.scene.gooeyness },
|
| 125 |
+
uSpeed: { value: settings.scene.speed },
|
| 126 |
+
uMouseSpherePos: { value: new THREE.Vector3(0, 0, 0) },
|
| 127 |
+
uMouseSphereRadius: { value: 0.0 },
|
| 128 |
+
},
|
| 129 |
+
vertexShader: `
|
| 130 |
+
varying vec2 vUv;
|
| 131 |
+
void main() {
|
| 132 |
+
vUv = uv;
|
| 133 |
+
gl_Position = vec4(position, 1.0);
|
| 134 |
+
}
|
| 135 |
+
`,
|
| 136 |
+
fragmentShader: `
|
| 137 |
+
precision highp float;
|
| 138 |
+
#define MARCH_STEPS ${quality.marchSteps}
|
| 139 |
+
#define AO_STEPS ${quality.aoSteps}
|
| 140 |
+
uniform float uTime;
|
| 141 |
+
uniform vec2 uResolution;
|
| 142 |
+
uniform vec3 uCameraPos;
|
| 143 |
+
uniform vec3 uCameraTarget;
|
| 144 |
+
uniform float uPixelRatio;
|
| 145 |
+
uniform float uGooeyness;
|
| 146 |
+
uniform float uSpeed;
|
| 147 |
+
uniform vec3 uMouseSpherePos;
|
| 148 |
+
uniform float uMouseSphereRadius;
|
| 149 |
+
|
| 150 |
+
varying vec2 vUv;
|
| 151 |
+
|
| 152 |
+
float smin(float a, float b, float k) {
|
| 153 |
+
float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);
|
| 154 |
+
return mix(b, a, h) - k * h * (1.0 - h);
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
float sdSphere(vec3 p, vec3 center, float radius) {
|
| 158 |
+
return length(p - center) - radius;
|
| 159 |
+
}
|
| 160 |
+
|
| 161 |
+
float sceneCompound(vec3 p, float t, float k) {
|
| 162 |
+
// Two large primary blobs
|
| 163 |
+
float angle1 = t * 0.5;
|
| 164 |
+
float angle2 = t * 0.5 + 3.14159;
|
| 165 |
+
vec3 c1 = vec3(
|
| 166 |
+
cos(angle1) * 2.4 + sin(t * 0.25) * 0.3,
|
| 167 |
+
sin(angle1 * 0.6) * 0.8 + cos(t * 0.4) * 0.2,
|
| 168 |
+
sin(angle1 * 0.35) * 0.6
|
| 169 |
+
);
|
| 170 |
+
vec3 c2 = vec3(
|
| 171 |
+
cos(angle2) * 2.4 + sin(t * 0.3) * 0.3,
|
| 172 |
+
sin(angle2 * 0.6) * 0.8 - cos(t * 0.35) * 0.2,
|
| 173 |
+
sin(angle2 * 0.35) * 0.6
|
| 174 |
+
);
|
| 175 |
+
float s1 = sdSphere(p, c1, 1.2 + 0.07 * sin(t * 2.5));
|
| 176 |
+
float s2 = sdSphere(p, c2, 1.05 + 0.07 * cos(t * 2.0));
|
| 177 |
+
|
| 178 |
+
// Medium satellites
|
| 179 |
+
vec3 c3 = c1 + vec3(sin(t * 1.8) * 0.9, cos(t * 2.2) * 0.9, sin(t * 1.5) * 0.6);
|
| 180 |
+
vec3 c4 = c2 + vec3(-cos(t * 1.5) * 0.8, sin(t * 1.9) * 0.8, -cos(t * 1.7) * 0.5);
|
| 181 |
+
float s3 = sdSphere(p, c3, 0.55);
|
| 182 |
+
float s4 = sdSphere(p, c4, 0.5);
|
| 183 |
+
|
| 184 |
+
// Free-floating blobs
|
| 185 |
+
vec3 c5 = vec3(sin(t * 0.7) * 3.0, cos(t * 0.55) * 1.2, cos(t * 0.45) * 0.7);
|
| 186 |
+
vec3 c6 = vec3(-cos(t * 0.65) * 2.8, sin(t * 0.75) * 1.0, sin(t * 0.5) * 0.8);
|
| 187 |
+
float s5 = sdSphere(p, c5, 0.6);
|
| 188 |
+
float s6 = sdSphere(p, c6, 0.55);
|
| 189 |
+
|
| 190 |
+
float d = smin(s1, s2, k);
|
| 191 |
+
d = smin(d, s3, k * 0.7);
|
| 192 |
+
d = smin(d, s4, k * 0.7);
|
| 193 |
+
d = smin(d, s5, k * 0.8);
|
| 194 |
+
d = smin(d, s6, k * 0.8);
|
| 195 |
+
return d;
|
| 196 |
+
}
|
| 197 |
+
|
| 198 |
+
float sceneSDF(vec3 p) {
|
| 199 |
+
float t = uTime * uSpeed;
|
| 200 |
+
float k = uGooeyness;
|
| 201 |
+
float d = sceneCompound(p, t, k);
|
| 202 |
+
if (uMouseSphereRadius > 0.001) {
|
| 203 |
+
float ms = sdSphere(p, uMouseSpherePos, uMouseSphereRadius);
|
| 204 |
+
d = smin(d, ms, k * 0.8);
|
| 205 |
+
}
|
| 206 |
+
return d;
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
vec3 calcNormal(vec3 p) {
|
| 210 |
+
const float eps = 0.001;
|
| 211 |
+
vec2 h = vec2(eps, 0.0);
|
| 212 |
+
return normalize(vec3(
|
| 213 |
+
sceneSDF(p + h.xyy) - sceneSDF(p - h.xyy),
|
| 214 |
+
sceneSDF(p + h.yxy) - sceneSDF(p - h.yxy),
|
| 215 |
+
sceneSDF(p + h.yyx) - sceneSDF(p - h.yyx)
|
| 216 |
+
));
|
| 217 |
+
}
|
| 218 |
+
|
| 219 |
+
float calcAO(vec3 pos, vec3 nor) {
|
| 220 |
+
float occ = 0.0;
|
| 221 |
+
float sca = 1.0;
|
| 222 |
+
for (int i = 0; i < AO_STEPS; i++) {
|
| 223 |
+
float h = 0.02 + 0.15 * float(i);
|
| 224 |
+
float d = sceneSDF(pos + h * nor);
|
| 225 |
+
occ += (h - d) * sca;
|
| 226 |
+
sca *= 0.9;
|
| 227 |
+
}
|
| 228 |
+
return clamp(1.0 - 3.0 * occ, 0.0, 1.0);
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
float fresnel(vec3 viewDir, vec3 normal, float power) {
|
| 232 |
+
return pow(1.0 - max(dot(viewDir, normal), 0.0), power);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
// Fake directional shadow via downward AO probe
|
| 236 |
+
float cheapShadow(vec3 pos, vec3 lightDir) {
|
| 237 |
+
float d1 = sceneSDF(pos + lightDir * 0.15);
|
| 238 |
+
float d2 = sceneSDF(pos + lightDir * 0.4);
|
| 239 |
+
float d3 = sceneSDF(pos + lightDir * 0.8);
|
| 240 |
+
return clamp(0.3 + 0.7 * smoothstep(0.0, 0.3, min(min(d1, d2), d3)), 0.0, 1.0);
|
| 241 |
+
}
|
| 242 |
+
|
| 243 |
+
mat3 setCamera(vec3 ro, vec3 ta, float cr) {
|
| 244 |
+
vec3 cw = normalize(ta - ro);
|
| 245 |
+
vec3 cp = vec3(sin(cr), cos(cr), 0.0);
|
| 246 |
+
vec3 cu = normalize(cross(cw, cp));
|
| 247 |
+
vec3 cv = normalize(cross(cu, cw));
|
| 248 |
+
return mat3(cu, cv, cw);
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
void main() {
|
| 252 |
+
vec2 fragCoord = vUv * uResolution;
|
| 253 |
+
vec2 uv = (2.0 * fragCoord - uResolution) / uResolution.y;
|
| 254 |
+
vec3 ro = uCameraPos;
|
| 255 |
+
vec3 ta = uCameraTarget;
|
| 256 |
+
mat3 ca = setCamera(ro, ta, 0.0);
|
| 257 |
+
vec3 rd = ca * normalize(vec3(uv, 1.8));
|
| 258 |
+
float t = 0.0;
|
| 259 |
+
float d;
|
| 260 |
+
vec3 p;
|
| 261 |
+
bool hit = false;
|
| 262 |
+
for (int i = 0; i < MARCH_STEPS; i++) {
|
| 263 |
+
p = ro + rd * t;
|
| 264 |
+
d = sceneSDF(p);
|
| 265 |
+
if (d < 0.002) { hit = true; break; }
|
| 266 |
+
t += d * 0.9;
|
| 267 |
+
if (t > 15.0) break;
|
| 268 |
+
}
|
| 269 |
+
vec3 col = vec3(0.02, 0.02, 0.04);
|
| 270 |
+
col += vec3(0.03, 0.01, 0.06) * (1.0 - uv.y * 0.5);
|
| 271 |
+
if (hit) {
|
| 272 |
+
vec3 nor = calcNormal(p);
|
| 273 |
+
vec3 viewDir = normalize(ro - p);
|
| 274 |
+
vec3 lightPos1 = vec3(3.0, 4.0, 5.0);
|
| 275 |
+
vec3 lightPos2 = vec3(-4.0, 2.0, -3.0);
|
| 276 |
+
vec3 lightDir1 = normalize(lightPos1 - p);
|
| 277 |
+
vec3 lightDir2 = normalize(lightPos2 - p);
|
| 278 |
+
float diff1 = max(dot(nor, lightDir1), 0.0);
|
| 279 |
+
float diff2 = max(dot(nor, lightDir2), 0.0);
|
| 280 |
+
vec3 halfDir1 = normalize(lightDir1 + viewDir);
|
| 281 |
+
vec3 halfDir2 = normalize(lightDir2 + viewDir);
|
| 282 |
+
float spec1 = pow(max(dot(nor, halfDir1), 0.0), 64.0);
|
| 283 |
+
float spec2 = pow(max(dot(nor, halfDir2), 0.0), 32.0);
|
| 284 |
+
float sha1 = cheapShadow(p + nor * 0.01, lightDir1);
|
| 285 |
+
float sha2 = cheapShadow(p + nor * 0.01, lightDir2);
|
| 286 |
+
float ao = calcAO(p, nor);
|
| 287 |
+
float fres = fresnel(viewDir, nor, 3.0);
|
| 288 |
+
float sss = max(0.0, dot(viewDir, -lightDir1)) * 0.3;
|
| 289 |
+
vec3 baseColor1 = vec3(0.8, 0.15, 0.3);
|
| 290 |
+
vec3 baseColor2 = vec3(0.15, 0.4, 0.9);
|
| 291 |
+
vec3 baseColor3 = vec3(0.95, 0.5, 0.1);
|
| 292 |
+
float colorMix = sin(p.x * 1.5 + uTime * 0.5) * 0.5 + 0.5;
|
| 293 |
+
float colorMix2 = cos(p.y * 2.0 - uTime * 0.3) * 0.5 + 0.5;
|
| 294 |
+
vec3 baseColor = mix(baseColor1, baseColor2, colorMix);
|
| 295 |
+
baseColor = mix(baseColor, baseColor3, colorMix2 * 0.3);
|
| 296 |
+
vec3 diffuse = baseColor * (diff1 * sha1 * vec3(1.0, 0.95, 0.9) * 0.8 + diff2 * sha2 * vec3(0.4, 0.5, 0.9) * 0.4);
|
| 297 |
+
vec3 specular = vec3(1.0, 0.95, 0.9) * spec1 * sha1 * 0.7 + vec3(0.5, 0.6, 1.0) * spec2 * sha2 * 0.3;
|
| 298 |
+
vec3 ambient = baseColor * vec3(0.08, 0.06, 0.12) * ao;
|
| 299 |
+
vec3 rim = mix(vec3(0.4, 0.6, 1.0), vec3(1.0, 0.4, 0.6), colorMix) * fres * 0.6;
|
| 300 |
+
vec3 subsurface = baseColor * sss * vec3(1.0, 0.3, 0.2);
|
| 301 |
+
col = ambient + diffuse + specular + rim + subsurface;
|
| 302 |
+
float iridescence = fres * 0.4;
|
| 303 |
+
vec3 iriColor = vec3(
|
| 304 |
+
sin(dot(nor, vec3(1.0, 0.0, 0.0)) * 6.0 + uTime) * 0.5 + 0.5,
|
| 305 |
+
sin(dot(nor, vec3(0.0, 1.0, 0.0)) * 6.0 + uTime * 1.3) * 0.5 + 0.5,
|
| 306 |
+
sin(dot(nor, vec3(0.0, 0.0, 1.0)) * 6.0 + uTime * 0.7) * 0.5 + 0.5
|
| 307 |
+
);
|
| 308 |
+
col += iriColor * iridescence;
|
| 309 |
+
vec3 ref = reflect(-viewDir, nor);
|
| 310 |
+
float envRefl = smoothstep(-0.2, 1.0, ref.y) * 0.15;
|
| 311 |
+
col += vec3(0.3, 0.4, 0.8) * envRefl * fres;
|
| 312 |
+
}
|
| 313 |
+
col = col / (col + vec3(1.0));
|
| 314 |
+
col = pow(col, vec3(1.0 / 2.2));
|
| 315 |
+
float vig = 1.0 - 0.3 * dot(uv * 0.5, uv * 0.5);
|
| 316 |
+
col *= vig;
|
| 317 |
+
gl_FragColor = vec4(col, 1.0);
|
| 318 |
+
}
|
| 319 |
+
`,
|
| 320 |
+
depthWrite: false,
|
| 321 |
+
depthTest: false
|
| 322 |
+
});
|
| 323 |
+
|
| 324 |
+
const quad = new THREE.Mesh(quadGeometry, quadMaterial);
|
| 325 |
+
quad.name = 'raymarchQuad';
|
| 326 |
+
quad.frustumCulled = false;
|
| 327 |
+
|
| 328 |
+
const quadScene = new THREE.Scene();
|
| 329 |
+
const quadCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
| 330 |
+
quadScene.add(quad);
|
| 331 |
+
|
| 332 |
+
// ============ DOT MATRIX SHADER ============
|
| 333 |
+
const DotMatrixShader = {
|
| 334 |
+
uniforms: {
|
| 335 |
+
tDiffuse: { value: null },
|
| 336 |
+
uResolution: { value: new THREE.Vector2(size.width, size.height) },
|
| 337 |
+
uDotSize: { value: 5.0 },
|
| 338 |
+
uDotGap: { value: 2.5 },
|
| 339 |
+
uBrightness: { value: 0.85 },
|
| 340 |
+
uContrast: { value: 0.60 },
|
| 341 |
+
uThreshold: { value: 0.03 },
|
| 342 |
+
uDotColor: { value: new THREE.Vector3(1.0, 1.0, 1.0) },
|
| 343 |
+
uBgColor: { value: new THREE.Vector3(0.00784, 0.00784, 0.01176) },
|
| 344 |
+
uCrossEnabled: { value: 0.0 },
|
| 345 |
+
uCrossIntensity: { value: 0.95 },
|
| 346 |
+
uCrossAngle: { value: 0.4363 },
|
| 347 |
+
uBloomEnabled: { value: 1.0 },
|
| 348 |
+
uBloomIntensity: { value: 0.55 },
|
| 349 |
+
uBloomSize: { value: 1.50 },
|
| 350 |
+
uCrtEnabled: { value: 1.0 },
|
| 351 |
+
uCrtCurvature: { value: 0.0 },
|
| 352 |
+
uCrtScanlines: { value: 0.75 },
|
| 353 |
+
uCrtVignette: { value: 2.00 },
|
| 354 |
+
uCrtChroma: { value: 0.0 },
|
| 355 |
+
uDitherEnabled: { value: 1.0 },
|
| 356 |
+
uTime: { value: 0 }
|
| 357 |
+
},
|
| 358 |
+
vertexShader: `
|
| 359 |
+
varying vec2 vUv;
|
| 360 |
+
void main() {
|
| 361 |
+
vUv = uv;
|
| 362 |
+
gl_Position = vec4(position, 1.0);
|
| 363 |
+
}
|
| 364 |
+
`,
|
| 365 |
+
fragmentShader: `
|
| 366 |
+
precision highp float;
|
| 367 |
+
uniform sampler2D tDiffuse;
|
| 368 |
+
uniform vec2 uResolution;
|
| 369 |
+
uniform float uDotSize;
|
| 370 |
+
uniform float uDotGap;
|
| 371 |
+
uniform float uBrightness;
|
| 372 |
+
uniform float uContrast;
|
| 373 |
+
uniform float uThreshold;
|
| 374 |
+
uniform vec3 uDotColor;
|
| 375 |
+
uniform vec3 uBgColor;
|
| 376 |
+
uniform float uCrossEnabled;
|
| 377 |
+
uniform float uCrossIntensity;
|
| 378 |
+
uniform float uCrossAngle;
|
| 379 |
+
uniform float uBloomEnabled;
|
| 380 |
+
uniform float uBloomIntensity;
|
| 381 |
+
uniform float uBloomSize;
|
| 382 |
+
uniform float uCrtEnabled;
|
| 383 |
+
uniform float uCrtCurvature;
|
| 384 |
+
uniform float uCrtScanlines;
|
| 385 |
+
uniform float uCrtVignette;
|
| 386 |
+
uniform float uCrtChroma;
|
| 387 |
+
uniform float uDitherEnabled;
|
| 388 |
+
uniform float uTime;
|
| 389 |
+
varying vec2 vUv;
|
| 390 |
+
|
| 391 |
+
vec2 crtDistort(vec2 uv, float k) {
|
| 392 |
+
vec2 cc = uv - 0.5;
|
| 393 |
+
float r2 = dot(cc, cc);
|
| 394 |
+
float f = 1.0 + r2 * k * 0.01;
|
| 395 |
+
return cc * f + 0.5;
|
| 396 |
+
}
|
| 397 |
+
|
| 398 |
+
void main() {
|
| 399 |
+
vec2 uv = vUv;
|
| 400 |
+
if (uCrtEnabled > 0.5) {
|
| 401 |
+
uv = crtDistort(uv, uCrtCurvature);
|
| 402 |
+
if (uv.x < 0.0 || uv.x > 1.0 || uv.y < 0.0 || uv.y > 1.0) {
|
| 403 |
+
gl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);
|
| 404 |
+
return;
|
| 405 |
+
}
|
| 406 |
+
}
|
| 407 |
+
vec3 col;
|
| 408 |
+
if (uCrtEnabled > 0.5 && uCrtChroma > 0.01) {
|
| 409 |
+
vec2 dir = (uv - 0.5) * uCrtChroma * 0.002;
|
| 410 |
+
col.r = texture2D(tDiffuse, uv + dir).r;
|
| 411 |
+
col.g = texture2D(tDiffuse, uv).g;
|
| 412 |
+
col.b = texture2D(tDiffuse, uv - dir).b;
|
| 413 |
+
} else {
|
| 414 |
+
col = texture2D(tDiffuse, uv).rgb;
|
| 415 |
+
}
|
| 416 |
+
if (uDitherEnabled < 0.5) {
|
| 417 |
+
if (uCrtEnabled > 0.5 && uCrtScanlines > 0.001) {
|
| 418 |
+
float scanline = sin(uv.y * uResolution.y * 0.8) * 0.5 + 0.5;
|
| 419 |
+
col *= 1.0 - uCrtScanlines * (1.0 - scanline);
|
| 420 |
+
}
|
| 421 |
+
if (uCrtEnabled > 0.5 && uCrtVignette > 0.001) {
|
| 422 |
+
vec2 vig = uv * (1.0 - uv);
|
| 423 |
+
float vigMask = pow(vig.x * vig.y * 16.0, uCrtVignette * 0.3);
|
| 424 |
+
col *= vigMask;
|
| 425 |
+
}
|
| 426 |
+
gl_FragColor = vec4(col, 1.0);
|
| 427 |
+
return;
|
| 428 |
+
}
|
| 429 |
+
vec2 pixelCoord = uv * uResolution;
|
| 430 |
+
float spacing = uDotSize + uDotGap;
|
| 431 |
+
vec2 cell = floor(pixelCoord / spacing);
|
| 432 |
+
vec2 cellCenter = (cell + 0.5) * spacing;
|
| 433 |
+
vec2 sampleUV = cellCenter / uResolution;
|
| 434 |
+
vec3 cellCol;
|
| 435 |
+
if (uCrtEnabled > 0.5 && uCrtChroma > 0.01) {
|
| 436 |
+
vec2 dir = (sampleUV - 0.5) * uCrtChroma * 0.002;
|
| 437 |
+
cellCol.r = texture2D(tDiffuse, sampleUV + dir).r;
|
| 438 |
+
cellCol.g = texture2D(tDiffuse, sampleUV).g;
|
| 439 |
+
cellCol.b = texture2D(tDiffuse, sampleUV - dir).b;
|
| 440 |
+
} else {
|
| 441 |
+
cellCol = texture2D(tDiffuse, sampleUV).rgb;
|
| 442 |
+
}
|
| 443 |
+
float lum = dot(cellCol, vec3(0.299, 0.587, 0.114));
|
| 444 |
+
lum *= uBrightness;
|
| 445 |
+
lum = (lum - 0.5) * (1.0 / uContrast) + 0.5;
|
| 446 |
+
lum = clamp(lum, 0.0, 1.0);
|
| 447 |
+
vec3 bgColor = uBgColor;
|
| 448 |
+
if (lum < uThreshold) {
|
| 449 |
+
vec3 result = bgColor;
|
| 450 |
+
if (uCrtEnabled > 0.5 && uCrtScanlines > 0.001) {
|
| 451 |
+
float scanline = sin(uv.y * uResolution.y * 0.8) * 0.5 + 0.5;
|
| 452 |
+
result *= 1.0 - uCrtScanlines * (1.0 - scanline) * 0.3;
|
| 453 |
+
}
|
| 454 |
+
if (uCrtEnabled > 0.5 && uCrtVignette > 0.001) {
|
| 455 |
+
vec2 vig = uv * (1.0 - uv);
|
| 456 |
+
float vigMask = pow(vig.x * vig.y * 16.0, uCrtVignette * 0.3);
|
| 457 |
+
result *= vigMask;
|
| 458 |
+
}
|
| 459 |
+
gl_FragColor = vec4(result, 1.0);
|
| 460 |
+
return;
|
| 461 |
+
}
|
| 462 |
+
float maxRadius = uDotSize * 0.5;
|
| 463 |
+
float minRadius = 0.4;
|
| 464 |
+
float lumCurve = pow(lum, uContrast);
|
| 465 |
+
float dotRadius = mix(minRadius, maxRadius, lumCurve);
|
| 466 |
+
vec2 d = pixelCoord - cellCenter;
|
| 467 |
+
vec2 absD = abs(d);
|
| 468 |
+
float cornerRadius = mix(0.8, 0.2, lumCurve);
|
| 469 |
+
float squareness = smoothstep(0.15, 0.7, lumCurve);
|
| 470 |
+
float circleDist = length(d);
|
| 471 |
+
float circleEdge = 1.0 - smoothstep(dotRadius - 0.5, dotRadius + 0.5, circleDist);
|
| 472 |
+
vec2 qd = absD - vec2(dotRadius - cornerRadius);
|
| 473 |
+
float rsDist = length(max(qd, 0.0)) + min(max(qd.x, qd.y), 0.0) - cornerRadius;
|
| 474 |
+
float squareEdge = 1.0 - smoothstep(-0.5, 0.5, rsDist);
|
| 475 |
+
float dotMask = mix(circleEdge, squareEdge, squareness);
|
| 476 |
+
vec3 brightColor = uDotColor;
|
| 477 |
+
vec3 midColor = uDotColor * 0.7;
|
| 478 |
+
vec3 dimColor = uDotColor * 0.25;
|
| 479 |
+
vec3 colNorm = cellCol / (max(max(cellCol.r, cellCol.g), cellCol.b) + 0.001);
|
| 480 |
+
vec3 dotColor;
|
| 481 |
+
if (lum > 0.65) {
|
| 482 |
+
dotColor = mix(brightColor, brightColor * colNorm * 1.5, 0.2);
|
| 483 |
+
dotColor *= 1.0 + (lum - 0.65) * 1.5;
|
| 484 |
+
} else if (lum > 0.25) {
|
| 485 |
+
float mt = (lum - 0.25) / 0.4;
|
| 486 |
+
dotColor = mix(midColor, brightColor, mt);
|
| 487 |
+
dotColor = mix(dotColor, dotColor * colNorm * 1.2, 0.15);
|
| 488 |
+
} else {
|
| 489 |
+
float st = lum / 0.25;
|
| 490 |
+
dotColor = mix(dimColor * 0.5, dimColor, st);
|
| 491 |
+
}
|
| 492 |
+
float shadowCrosshatch = 0.0;
|
| 493 |
+
if (uCrossEnabled > 0.5 && lum < 0.35) {
|
| 494 |
+
float crossSpacing = spacing * 0.7;
|
| 495 |
+
float ca = cos(uCrossAngle);
|
| 496 |
+
float sa = sin(uCrossAngle);
|
| 497 |
+
vec2 rotP = vec2(ca * pixelCoord.x - sa * pixelCoord.y, sa * pixelCoord.x + ca * pixelCoord.y);
|
| 498 |
+
vec2 crossCell = floor(rotP / crossSpacing);
|
| 499 |
+
vec2 crossCenter = (crossCell + 0.5) * crossSpacing;
|
| 500 |
+
float crossDist = length(rotP - crossCenter);
|
| 501 |
+
float shadowIntensity = smoothstep(0.35, 0.05, lum);
|
| 502 |
+
float crossRadius = mix(0.3, maxRadius * 0.35, shadowIntensity);
|
| 503 |
+
shadowCrosshatch = 1.0 - smoothstep(crossRadius - 0.4, crossRadius + 0.4, crossDist);
|
| 504 |
+
shadowCrosshatch *= shadowIntensity * uCrossIntensity;
|
| 505 |
+
}
|
| 506 |
+
float bloomMask = 0.0;
|
| 507 |
+
if (uBloomEnabled > 0.5 && lum > 0.6) {
|
| 508 |
+
float bloomRadius = dotRadius * uBloomSize;
|
| 509 |
+
float bloomDist = length(d);
|
| 510 |
+
bloomMask = (1.0 - smoothstep(bloomRadius - 1.0, bloomRadius + 1.0, bloomDist));
|
| 511 |
+
bloomMask *= smoothstep(0.6, 1.0, lum) * uBloomIntensity * 0.5;
|
| 512 |
+
}
|
| 513 |
+
vec3 result = bgColor;
|
| 514 |
+
vec3 crossColor = dimColor * 0.4;
|
| 515 |
+
result = mix(result, crossColor, shadowCrosshatch);
|
| 516 |
+
result += brightColor * bloomMask;
|
| 517 |
+
result = mix(result, dotColor, dotMask);
|
| 518 |
+
float innerMask = 0.0;
|
| 519 |
+
if (squareness > 0.5) {
|
| 520 |
+
vec2 qd2 = absD - vec2(dotRadius * 0.85 - cornerRadius);
|
| 521 |
+
float rsDist2 = length(max(qd2, 0.0)) + min(max(qd2.x, qd2.y), 0.0) - cornerRadius;
|
| 522 |
+
innerMask = 1.0 - smoothstep(-0.5, 0.5, rsDist2);
|
| 523 |
+
} else {
|
| 524 |
+
innerMask = 1.0 - smoothstep(dotRadius * 0.7 - 0.5, dotRadius * 0.7 + 0.5, circleDist);
|
| 525 |
+
}
|
| 526 |
+
float phosphorEdge = max(dotMask - innerMask, 0.0);
|
| 527 |
+
result += brightColor * phosphorEdge * 0.15 * lum;
|
| 528 |
+
if (uCrtEnabled > 0.5 && uCrtScanlines > 0.001) {
|
| 529 |
+
float scanline = sin(uv.y * uResolution.y * 0.8) * 0.5 + 0.5;
|
| 530 |
+
result *= 1.0 - uCrtScanlines * (1.0 - scanline);
|
| 531 |
+
}
|
| 532 |
+
if (uCrtEnabled > 0.5 && uCrtVignette > 0.001) {
|
| 533 |
+
vec2 vig = uv * (1.0 - uv);
|
| 534 |
+
float vigMask = pow(vig.x * vig.y * 16.0, uCrtVignette * 0.3);
|
| 535 |
+
result *= vigMask;
|
| 536 |
+
}
|
| 537 |
+
if (uCrtEnabled > 0.5) {
|
| 538 |
+
result = result;
|
| 539 |
+
}
|
| 540 |
+
gl_FragColor = vec4(result, 1.0);
|
| 541 |
+
}
|
| 542 |
+
`
|
| 543 |
+
};
|
| 544 |
+
|
| 545 |
+
// ============ POST PROCESSING ============
|
| 546 |
+
// Use a standard RenderPass for the quad scene — the raymarching resolution
|
| 547 |
+
// is controlled by uResolution on the quad material (set to half-res),
|
| 548 |
+
// while the composer and dot-matrix shader run at full native resolution.
|
| 549 |
+
const composer = new EffectComposer(renderer);
|
| 550 |
+
composer.setSize(size.width, size.height);
|
| 551 |
+
|
| 552 |
+
const renderPass = new RenderPass(quadScene, quadCamera);
|
| 553 |
+
composer.addPass(renderPass);
|
| 554 |
+
|
| 555 |
+
const dotMatrixPass = new ShaderPass(DotMatrixShader);
|
| 556 |
+
composer.addPass(dotMatrixPass);
|
| 557 |
+
const outputPass = new OutputPass();
|
| 558 |
+
composer.addPass(outputPass);
|
| 559 |
+
|
| 560 |
+
// Dot matrix runs at full resolution for crisp patterns
|
| 561 |
+
dotMatrixPass.uniforms.uResolution.value.set(size.width, size.height);
|
| 562 |
+
|
| 563 |
+
// ============ SCROLL PARALLAX ============
|
| 564 |
+
let scrollY = 0;
|
| 565 |
+
let smoothScrollY = 0;
|
| 566 |
+
|
| 567 |
+
window.addEventListener('scroll', () => {
|
| 568 |
+
scrollY = window.scrollY;
|
| 569 |
+
}, { passive: true });
|
| 570 |
+
|
| 571 |
+
// ============ ANIMATION LOOP ============
|
| 572 |
+
const clock = new THREE.Clock();
|
| 573 |
+
const raycaster = new THREE.Raycaster();
|
| 574 |
+
const _forward = new THREE.Vector3();
|
| 575 |
+
let resizeTimeout = null;
|
| 576 |
+
|
| 577 |
+
// ============ FPS WATCHDOG — auto-downgrade if <30fps ============
|
| 578 |
+
const tierOrder = ['high', 'mid', 'low'];
|
| 579 |
+
let fpsFrames = 0;
|
| 580 |
+
let fpsStartTime = performance.now();
|
| 581 |
+
let fpsWatchdogActive = true;
|
| 582 |
+
const FPS_SAMPLE_WINDOW = 2000; // 2 seconds
|
| 583 |
+
const FPS_THRESHOLD = 30;
|
| 584 |
+
|
| 585 |
+
function downgradeQuality() {
|
| 586 |
+
const currentIndex = tierOrder.indexOf(currentTier);
|
| 587 |
+
if (currentIndex >= tierOrder.length - 1) {
|
| 588 |
+
// Already at lowest tier
|
| 589 |
+
fpsWatchdogActive = false;
|
| 590 |
+
return;
|
| 591 |
+
}
|
| 592 |
+
const nextTier = tierOrder[currentIndex + 1];
|
| 593 |
+
currentTier = nextTier;
|
| 594 |
+
quality = { ...qualityPresets[currentTier] };
|
| 595 |
+
|
| 596 |
+
// Apply new quality — update pixel ratio
|
| 597 |
+
const pr = Math.min(window.devicePixelRatio, quality.pixelRatio);
|
| 598 |
+
renderer.setPixelRatio(pr);
|
| 599 |
+
renderer.setSize(size.width, size.height);
|
| 600 |
+
composer.setSize(size.width, size.height);
|
| 601 |
+
|
| 602 |
+
// Update dot matrix uniforms
|
| 603 |
+
dotMatrixPass.uniforms.uDotSize.value = quality.dotSize;
|
| 604 |
+
dotMatrixPass.uniforms.uDotGap.value = quality.dotGap;
|
| 605 |
+
dotMatrixPass.uniforms.uCrtScanlines.value = quality.scanlines;
|
| 606 |
+
dotMatrixPass.uniforms.uBloomEnabled.value = quality.bloomEnabled ? 1.0 : 0.0;
|
| 607 |
+
|
| 608 |
+
// Reset watchdog for another sample window
|
| 609 |
+
fpsFrames = 0;
|
| 610 |
+
fpsStartTime = performance.now();
|
| 611 |
+
|
| 612 |
+
// If we hit the lowest tier, stop watching
|
| 613 |
+
if (currentIndex + 1 >= tierOrder.length - 1) {
|
| 614 |
+
fpsWatchdogActive = false;
|
| 615 |
+
}
|
| 616 |
+
|
| 617 |
+
// Update tier display
|
| 618 |
+
const tierEl = document.getElementById('settings-tier');
|
| 619 |
+
if (tierEl) tierEl.textContent = `GPU Tier: ${currentTier} (auto)`;
|
| 620 |
+
}
|
| 621 |
+
|
| 622 |
+
function animate() {
|
| 623 |
+
// Skip rendering when the tab is hidden or the hero has scrolled off screen (see heroOnScreen).
|
| 624 |
+
if (!pageVisible || !heroOnScreen) return;
|
| 625 |
+
|
| 626 |
+
const dt = Math.min(clock.getDelta(), 0.05); // Clamp delta to avoid huge jumps
|
| 627 |
+
const elapsed = clock.elapsedTime;
|
| 628 |
+
controls.update();
|
| 629 |
+
|
| 630 |
+
const targetR = mouseInScene ? (mousePressed ? mouseSphereClickRadius : mouseSphereTargetRadius) : 0.0;
|
| 631 |
+
const fadeSpeed = mouseInScene ? (mousePressed ? 10.0 : 6.0) : 3.0;
|
| 632 |
+
const step = Math.min(1.0, fadeSpeed * dt);
|
| 633 |
+
mouseSphereRadius += (targetR - mouseSphereRadius) * step;
|
| 634 |
+
if (mouseSphereRadius < 0.005 && !mouseInScene) mouseSphereRadius = 0.0;
|
| 635 |
+
|
| 636 |
+
raycaster.setFromCamera(mouse, camera);
|
| 637 |
+
const rayDir = raycaster.ray.direction;
|
| 638 |
+
const rayOrigin = raycaster.ray.origin;
|
| 639 |
+
_forward.subVectors(controls.target, camera.position).normalize();
|
| 640 |
+
const dist = camera.position.distanceTo(controls.target);
|
| 641 |
+
const t = dist / rayDir.dot(_forward);
|
| 642 |
+
mouseWorldTarget.copy(rayOrigin).addScaledVector(rayDir, t);
|
| 643 |
+
mouseWorld.lerp(mouseWorldTarget, mouseDamping);
|
| 644 |
+
|
| 645 |
+
// Smooth scroll interpolation for parallax
|
| 646 |
+
smoothScrollY += (scrollY - smoothScrollY) * 0.1;
|
| 647 |
+
const vh = window.innerHeight;
|
| 648 |
+
const scrollProgress = Math.min(smoothScrollY / vh, 1.0);
|
| 649 |
+
|
| 650 |
+
// Parallax: shift camera subtly as user scrolls (3D depth effect)
|
| 651 |
+
const baseZ = 5;
|
| 652 |
+
const baseCamY = 0;
|
| 653 |
+
camera.position.y = baseCamY + scrollProgress * 1.5;
|
| 654 |
+
camera.position.z = baseZ + scrollProgress * 0.8;
|
| 655 |
+
controls.target.y = scrollProgress * 0.8;
|
| 656 |
+
|
| 657 |
+
quadMaterial.uniforms.uMouseSpherePos.value.copy(mouseWorld);
|
| 658 |
+
quadMaterial.uniforms.uMouseSphereRadius.value = mouseSphereRadius;
|
| 659 |
+
quadMaterial.uniforms.uTime.value = elapsed;
|
| 660 |
+
quadMaterial.uniforms.uCameraPos.value.copy(camera.position);
|
| 661 |
+
quadMaterial.uniforms.uCameraTarget.value.copy(controls.target);
|
| 662 |
+
dotMatrixPass.uniforms.uTime.value = elapsed;
|
| 663 |
+
|
| 664 |
+
// Composer renders the quad scene via RenderPass, then applies dot matrix + CRT
|
| 665 |
+
composer.render();
|
| 666 |
+
|
| 667 |
+
// FPS watchdog — sample for 2s windows, downgrade if below threshold
|
| 668 |
+
if (fpsWatchdogActive) {
|
| 669 |
+
fpsFrames++;
|
| 670 |
+
const elapsed_ms = performance.now() - fpsStartTime;
|
| 671 |
+
if (elapsed_ms >= FPS_SAMPLE_WINDOW) {
|
| 672 |
+
const avgFps = (fpsFrames / elapsed_ms) * 1000;
|
| 673 |
+
if (avgFps < FPS_THRESHOLD) {
|
| 674 |
+
downgradeQuality();
|
| 675 |
+
} else {
|
| 676 |
+
// Performance is fine, stop watching
|
| 677 |
+
fpsWatchdogActive = false;
|
| 678 |
+
}
|
| 679 |
+
}
|
| 680 |
+
}
|
| 681 |
+
}
|
| 682 |
+
|
| 683 |
+
renderer.setAnimationLoop(animate);
|
| 684 |
+
|
| 685 |
+
// ============ RESIZE (debounced — render loop never pauses) ============
|
| 686 |
+
function handleResize() {
|
| 687 |
+
size = getSize();
|
| 688 |
+
camera.aspect = size.width / size.height;
|
| 689 |
+
camera.updateProjectionMatrix();
|
| 690 |
+
|
| 691 |
+
const pr = Math.min(window.devicePixelRatio, quality.pixelRatio);
|
| 692 |
+
renderer.setPixelRatio(pr);
|
| 693 |
+
renderer.setSize(size.width, size.height);
|
| 694 |
+
|
| 695 |
+
quadMaterial.uniforms.uResolution.value.set(size.width, size.height);
|
| 696 |
+
quadMaterial.uniforms.uPixelRatio.value = pr;
|
| 697 |
+
dotMatrixPass.uniforms.uResolution.value.set(size.width, size.height);
|
| 698 |
+
|
| 699 |
+
composer.setSize(size.width, size.height);
|
| 700 |
+
}
|
| 701 |
+
|
| 702 |
+
window.addEventListener('resize', () => {
|
| 703 |
+
clearTimeout(resizeTimeout);
|
| 704 |
+
// Immediately update the canvas CSS size so it fills the window (no black gaps)
|
| 705 |
+
// but defer the expensive framebuffer reallocation
|
| 706 |
+
renderer.domElement.style.width = window.innerWidth + 'px';
|
| 707 |
+
renderer.domElement.style.height = window.innerHeight + 'px';
|
| 708 |
+
resizeTimeout = setTimeout(handleResize, 200);
|
| 709 |
+
}, { passive: true });
|
| 710 |
+
|
| 711 |
+
// ============ DEFERRED INIT — pre-warm the shader after first paint ============
|
| 712 |
+
// Force one render so the first real frame doesn't stutter on shader compile.
|
| 713 |
+
if ('requestIdleCallback' in window) {
|
| 714 |
+
requestIdleCallback(() => composer.render(), { timeout: 1000 });
|
|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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import {
|
| 2 |
+
AutoProcessor,
|
| 3 |
+
Gemma4ForConditionalGeneration,
|
| 4 |
+
InterruptableStoppingCriteria,
|
| 5 |
+
TextStreamer,
|
| 6 |
+
load_image,
|
| 7 |
+
read_audio,
|
| 8 |
+
} from "https://cdn.jsdelivr.net/npm/@huggingface/transformers@4.2.0";
|
| 9 |
+
|
| 10 |
+
const MODEL_IDS = {
|
| 11 |
+
"google/gemma-4-E2B-it-qat-mobile-transformers": "onnx-community/gemma-4-E2B-it-ONNX",
|
| 12 |
+
"google/gemma-4-E4B-it-qat-mobile-transformers": "onnx-community/gemma-4-E4B-it-ONNX",
|
| 13 |
+
"onnx-community/gemma-4-E2B-it-ONNX": "onnx-community/gemma-4-E2B-it-ONNX",
|
| 14 |
+
"onnx-community/gemma-4-E4B-it-ONNX": "onnx-community/gemma-4-E4B-it-ONNX",
|
| 15 |
+
};
|
| 16 |
+
|
| 17 |
+
export class Gemma4Multimodal {
|
| 18 |
+
static async load(requestedId, { onProgress = () => {} } = {}) {
|
| 19 |
+
const modelId = MODEL_IDS[requestedId] ?? requestedId;
|
| 20 |
+
onProgress({ status: "tokenizer", message: "Loading multimodal processor", fraction: 0 });
|
| 21 |
+
const processor = await AutoProcessor.from_pretrained(modelId, {
|
| 22 |
+
progress_callback: (info) => reportProgress(info, onProgress),
|
| 23 |
+
});
|
| 24 |
+
onProgress({ status: "weights", message: "Loading WebGPU model", fraction: 0 });
|
| 25 |
+
const model = await Gemma4ForConditionalGeneration.from_pretrained(modelId, {
|
| 26 |
+
dtype: "q4f16",
|
| 27 |
+
device: "webgpu",
|
| 28 |
+
progress_callback: (info) => reportProgress(info, onProgress),
|
| 29 |
+
});
|
| 30 |
+
onProgress({ status: "ready", message: "Ready", fraction: 1 });
|
| 31 |
+
return new Gemma4Multimodal(modelId, processor, model);
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
constructor(modelId, processor, model) {
|
| 35 |
+
this.modelId = modelId;
|
| 36 |
+
this.processor = processor;
|
| 37 |
+
this.model = model;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
async *generate(messages, { maxNewTokens = 512, signal } = {}) {
|
| 41 |
+
const prepared = await prepareInputs(this.processor, messages);
|
| 42 |
+
const stopping = new InterruptableStoppingCriteria();
|
| 43 |
+
const onAbort = () => stopping.interrupt();
|
| 44 |
+
signal?.addEventListener("abort", onAbort, { once: true });
|
| 45 |
+
if (signal?.aborted) stopping.interrupt();
|
| 46 |
+
|
| 47 |
+
const queue = [];
|
| 48 |
+
let wake = null;
|
| 49 |
+
let done = false;
|
| 50 |
+
let failure = null;
|
| 51 |
+
let fullText = "";
|
| 52 |
+
const push = (text) => {
|
| 53 |
+
if (!text) return;
|
| 54 |
+
fullText += text;
|
| 55 |
+
queue.push({ delta: text, text: fullText });
|
| 56 |
+
wake?.();
|
| 57 |
+
wake = null;
|
| 58 |
+
};
|
| 59 |
+
|
| 60 |
+
const streamer = new TextStreamer(this.processor.tokenizer, {
|
| 61 |
+
skip_prompt: true,
|
| 62 |
+
skip_special_tokens: true,
|
| 63 |
+
callback_function: push,
|
| 64 |
+
});
|
| 65 |
+
|
| 66 |
+
const generation = this.model.generate({
|
| 67 |
+
...prepared.inputs,
|
| 68 |
+
max_new_tokens: maxNewTokens,
|
| 69 |
+
do_sample: false,
|
| 70 |
+
streamer,
|
| 71 |
+
stopping_criteria: [stopping],
|
| 72 |
+
}).catch((error) => { failure = error; }).finally(() => {
|
| 73 |
+
done = true;
|
| 74 |
+
wake?.();
|
| 75 |
+
wake = null;
|
| 76 |
+
prepared.cleanup();
|
| 77 |
+
signal?.removeEventListener("abort", onAbort);
|
| 78 |
+
});
|
| 79 |
+
|
| 80 |
+
while (!done || queue.length) {
|
| 81 |
+
if (!queue.length) await new Promise((resolve) => { wake = resolve; });
|
| 82 |
+
while (queue.length) yield queue.shift();
|
| 83 |
+
}
|
| 84 |
+
await generation;
|
| 85 |
+
if (failure) throw failure;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
reset() {}
|
| 89 |
+
|
| 90 |
+
dispose() {
|
| 91 |
+
this.model?.dispose?.();
|
| 92 |
+
}
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
async function prepareInputs(processor, messages) {
|
| 96 |
+
const templated = [];
|
| 97 |
+
const imageUrls = [];
|
| 98 |
+
const audioSources = [];
|
| 99 |
+
const temporaryUrls = [];
|
| 100 |
+
// Transformers.js 4.2 currently merges one set of Gemma 4 multimodal
|
| 101 |
+
// features per generation call. Re-inserting media from earlier turns makes
|
| 102 |
+
// the number of placeholder tokens diverge from the newly encoded features.
|
| 103 |
+
// Keep earlier turns as text; the assistant response already preserves their
|
| 104 |
+
// conversational meaning. Only encode attachments from the newest media turn.
|
| 105 |
+
const lastIndex = messages.length - 1;
|
| 106 |
+
const activeMediaIndex = messages[lastIndex]?.role === "user" && messages[lastIndex]?.attachments?.length
|
| 107 |
+
? lastIndex
|
| 108 |
+
: -1;
|
| 109 |
+
|
| 110 |
+
for (let messageIndex = 0; messageIndex < messages.length; messageIndex++) {
|
| 111 |
+
const message = messages[messageIndex];
|
| 112 |
+
if (message.role !== "user" || !message.attachments?.length || messageIndex !== activeMediaIndex) {
|
| 113 |
+
const previousMedia = message.role === "user" && message.attachments?.length
|
| 114 |
+
? describePreviousMedia(message.attachments)
|
| 115 |
+
: "";
|
| 116 |
+
templated.push({ role: message.role, content: message.content || "" });
|
| 117 |
+
if (previousMedia && !message.content) templated[templated.length - 1].content = previousMedia;
|
| 118 |
+
continue;
|
| 119 |
+
}
|
| 120 |
+
|
| 121 |
+
const content = [];
|
| 122 |
+
for (const attachment of message.attachments.filter((item) => item.type === "image")) {
|
| 123 |
+
content.push({ type: "image" });
|
| 124 |
+
imageUrls.push(mediaUrl(attachment, temporaryUrls));
|
| 125 |
+
}
|
| 126 |
+
if (message.content) content.push({ type: "text", text: message.content });
|
| 127 |
+
for (const attachment of message.attachments.filter((item) => item.type === "audio")) {
|
| 128 |
+
content.push({ type: "audio" });
|
| 129 |
+
audioSources.push(attachment.pcm ?? mediaUrl(attachment, temporaryUrls));
|
| 130 |
+
}
|
| 131 |
+
templated.push({ role: "user", content });
|
| 132 |
+
}
|
| 133 |
+
|
| 134 |
+
const prompt = processor.apply_chat_template(templated, {
|
| 135 |
+
enable_thinking: false,
|
| 136 |
+
add_generation_prompt: true,
|
| 137 |
+
});
|
| 138 |
+
const images = await Promise.all(imageUrls.map((url) => load_image(url)));
|
| 139 |
+
const audios = await Promise.all(audioSources.map((source) =>
|
| 140 |
+
source instanceof Float32Array ? source : read_audio(source, 16000)
|
| 141 |
+
));
|
| 142 |
+
const inputs = await processor(
|
| 143 |
+
prompt,
|
| 144 |
+
images.length ? (images.length === 1 ? images[0] : images) : null,
|
| 145 |
+
audios.length ? (audios.length === 1 ? audios[0] : audios) : null,
|
| 146 |
+
{ add_special_tokens: false },
|
| 147 |
+
);
|
| 148 |
+
if (audioSources.length && !inputs.input_features) {
|
| 149 |
+
throw new Error("The Gemma 4 processor did not create audio features (input_features is missing).");
|
| 150 |
+
}
|
| 151 |
+
return {
|
| 152 |
+
inputs,
|
| 153 |
+
cleanup: () => temporaryUrls.forEach((url) => URL.revokeObjectURL(url)),
|
| 154 |
+
};
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
function describePreviousMedia(attachments) {
|
| 158 |
+
const images = attachments.filter((item) => item.type === "image").length;
|
| 159 |
+
const audios = attachments.filter((item) => item.type === "audio").length;
|
| 160 |
+
const parts = [];
|
| 161 |
+
if (images) parts.push(`[${images} previous image${images > 1 ? "s" : ""}]`);
|
| 162 |
+
if (audios) parts.push(`[${audios} previous audio message${audios > 1 ? "s" : ""}]`);
|
| 163 |
+
return parts.join(" ");
|
| 164 |
+
}
|
| 165 |
+
|
| 166 |
+
function mediaUrl(attachment, temporaryUrls) {
|
| 167 |
+
if (attachment.url) return attachment.url;
|
| 168 |
+
const source = attachment.file ?? attachment.blob;
|
| 169 |
+
if (!source) throw new Error(`Missing ${attachment.type} data`);
|
| 170 |
+
const url = URL.createObjectURL(source);
|
| 171 |
+
temporaryUrls.push(url);
|
| 172 |
+
return url;
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
function reportProgress(info, callback) {
|
| 176 |
+
if (info.status === "progress_total") {
|
| 177 |
+
callback({
|
| 178 |
+
status: "weights",
|
| 179 |
+
kind: "bytes",
|
| 180 |
+
loaded: info.loaded,
|
| 181 |
+
total: info.total,
|
| 182 |
+
fraction: Number.isFinite(info.progress) ? info.progress / 100 : undefined,
|
| 183 |
+
message: info.file ? `Loading ${info.file}` : "Loading model files",
|
| 184 |
+
});
|
| 185 |
+
} else if (info.status === "progress") {
|
| 186 |
+
callback({
|
| 187 |
+
status: "weights",
|
| 188 |
+
kind: "bytes",
|
| 189 |
+
loaded: info.loaded,
|
| 190 |
+
total: info.total,
|
| 191 |
+
fraction: Number.isFinite(info.progress) ? info.progress / 100 : undefined,
|
| 192 |
+
message: info.file ? `Loading ${info.file}` : "Loading model files",
|
| 193 |
+
});
|
| 194 |
+
}
|
| 195 |
+
}
|