-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLanguage
634 lines (525 loc) · 12 KB
/
Language
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
// Copyright 2024 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// script.js
// Authors: kylephillips@ bencobley@
import * as aistudio from "./aistudio.js";
import * as mapsFunction from "./function-declarations.js";
import { presets } from "./presets.js";
import {
html,
render,
} from "https://cdn.jsdelivr.net/gh/lit/dist@3/core/lit-core.min.js";
const systemInstructions = mapsFunction.systemInstructions;
const functionDeclarations = mapsFunction.declarations.map(declaration => ({
...declaration,
callback: (args) => {
const { location, caption } = args;
renderPage(location, caption);
},
}));
let chat;
async function init() {
renderPage("%"); // Start by rendering with empty location query: shows earth
try {
const initResult = await aistudio.init({
systemInstructions,
functionDeclarations,
});
// Handle light or dark theme from parent
if (initResult.theme === "light") {
document.documentElement.setAttribute("data-theme", "light");
} else if (initResult.theme === "system") {
if (
window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches
) {
document.documentElement.removeAttribute("data-theme"); // Use default (dark)
} else {
document.documentElement.setAttribute("data-theme", "light");
}
}
aistudio.chat("Welcome to Map Explorer!");
chat = async (userText) => {
try {
const temperature = 2; // High temperature for answer variety
const response = await aistudio.generateContent({ userText, temperature });
console.log(response);
} catch (e) {
console.error(e);
}
};
} catch (error) {
console.error("Error initializing AI Studio:", error);
}
}
init();
function renderPage(location, caption = "") {
const root = document.querySelector("#root");
caption = caption.replace(/\\/g, '');
render(
html`
<div id="map">${mapsFunction.embed(location)}</div>
${caption
? html`<div id="caption"><p>${caption}</p></div>`
: ""}
<div id="presets-container">
<span id="take-me-somewhere">Take me somewhere...</span>
<div id="presets">
${presets.map(
([name, message]) =>
html`<button @click=${() => chat(message)} class="preset">
${name}
</button>`
)}
</div>
</div>
`,
root
);
}
// Copyright 2024 Google LLC
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// https://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vitejs.dev/config/
export default defineConfig({
base: './',
plugins: [react()],
})
@import './player.sass'
@import './chart.sass'
$baseFont: 'Space Mono', monospace
.light
--background: #F3F3F6
--text: #1A1C1E
--border: #C6C6C9
--highlight: #fff
--track: #86878A
--link: #2872E3
.dark
--background: #1A1C1E
--text: #fff
--border: #37393C
--highlight: #000
--track: #37393C
--link: #87A9FF
*
margin: 0
padding: 0
box-sizing: border-box
font-variant-ligatures: none
:root
--track-fill: #fff
--mid: #757575
font-family: $baseFont
#root
width: 100vw
height: 100vh
h1, h2, h3, h4, h5, h6
font-weight: normal
li
list-style: none
input, textarea
font-family: $baseFont
background: none
color: var(--text)
border: none
outline: none
font-size: 14px
resize: none
user-select: text
&::placeholder
user-select: none
textarea
width: 100%
background: var(--highlight)
border: 1px solid var(--border)
border-radius: 8px
font-size: 14px
padding: 10px 15px
margin-bottom: 10px
&.active
border-color: var(--text)
[role='button']
cursor: pointer
button
font-family: $baseFont
background: none
color: var(--text)
border: none
font-size: 14px
cursor: pointer
user-select: none
display: flex
align-items: center
gap: 5px
&:focus
outline: none
&[disabled]
opacity: .5
cursor: not-allowed
.icon
display: block
.button
padding: 8px 10px
border-radius: 6px
display: flex
align-items: center
justify-content: center
gap: 5px
&.inactive
opacity: .3
pointer-events: none
.icon
font-family: 'Material Symbols Outlined'
font-weight: 300
line-height: 1
main
max-width: 1200px
height: 100vh
display: flex
flex-direction: column
margin: 0 auto
overflow: hidden
background: var(--background)
color: var(--text)
.top
display: flex
min-height: 50vh
border-bottom: 1px solid var(--border)
.tools
display: flex
gap: 20px
flex: 1
overflow: hidden
transition: opacity .2s
&.inactive
opacity: .2
pointer-events: none
.collapseButton
border-left: 1px solid var(--border)
width: 20px
display: flex
align-items: center
justify-content: center
.icon
font-size: 24px
color: var(--text)
.modeSelector
display: flex
flex-direction: column
gap: 30px
overflow: hidden
width: 250px
&.hide
width: 0
> div
padding: 20px 15px
&:first-child
flex: 1
overflow: auto
&:last-child
border-top: 1px solid var(--border)
h2
font-size: 14px
color: var(--text)
white-space: nowrap
margin-bottom: 15px
&.inactive
opacity: .2
pointer-events: none
.modeList
flex-direction: column
display: flex
gap: 10px
.button
justify-content: flex-start
gap: 12px
transition: background .2s
background: none
outline: 1px solid var(--border)
white-space: nowrap
border-radius: 8px
min-width: fit-content
width: 100%
&:hover
background: var(--border)
&.active
outline: 2px solid var(--text)
+ textarea
margin-top: 10px
.generateButton
padding: 12px 20px
background: var(--highlight)
width: 100%
border: 1px solid var(--border)
.backButton
border-top: none !important
button
font-size: 14px
.output
flex: 1
padding: 20px 15px
overflow: auto
position: relative
&:hover
.sentence
opacity: .5
time
color: var(--link)
padding: 2px 5px
border-radius: 4px
font-size: inherit
text-decoration: underline
.sentence
font-size: 18px
line-height: 1.8
display: inline
cursor: pointer
transition: opacity .2s
&:hover
opacity: 1
time
margin-right: 8px
ul
display: flex
flex-direction: column
gap: 5px
button
font-size: 15px
display: flex
gap: 15px
text-align: left
padding: 10px 15px
border-radius: 6px
width: 100%
&:hover
background: var(--border)
p
font-size: 14px
.modeEmojis
.sentence
font-size: 40px
margin-right: 20px
time
top: -8px
.modeHaiku
.sentence
display: block
font-size: 20px
time
top: -5px
.modeTable
table
width: 100%
border-collapse: collapse
th
text-align: left
th, td
padding: 10px
tr
border-bottom: 1px solid var(--border)
display: table-row
thead tr:hover
background: transparent
.modelSelector
position: relative
margin-bottom: 10px
position: relative
&::after
content: '▾'
display: block
position: absolute
right: 10px
top: 50%
transform: translateY(-55%)
select
width: 100%
appearance: none
color: var(--text)
background: var(--border)
border: 1px solid var(--border)
border-radius: 6px
padding: 5px 10px
font-family: $baseFont
outline: none
.loading
span
display: inline-block
animation: loading steps(4, jump-none) 777ms infinite
width: 0
overflow: hidden
vertical-align: bottom
@keyframes loading
to
width: 30px
@import url("https://fonts.googleapis.com/css2?family=Space+Mono:ital,wght@0,400;0,700;1,400;1,700&display=swap");
:root {
--Neutral-00: #000;
--Neutral-5: #181a1b;
--Neutral-10: #1c1f21;
--Neutral-20: #2a2f31;
--Neutral-30: #404547;
--Neutral-40: #575c5f;
--Neutral-80: #c3c6c7;
--Neutral-99: #fdfcfb;
--Neutral-100: #fff;
--Blue-400: #80bbff;
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-variant-ligatures: none;
}
:root,
html,
body {
padding: 0;
margin: 0;
overflow: hidden;
}
#map {
height: 100vh;
}
#embed-map {
width: 100%;
height: 100%;
}
#caption {
position: absolute;
left: 50%;
bottom: 160px;
transform: translate(-50%, 0);
display: flex;
max-width: min(1000px, calc(100% - 200px));
padding: 6px 8px;
justify-content: center;
align-items: center;
gap: 10px;
border-radius: 2px;
background: var(--Neutral-00, #000);
color: var(--Neutral-100, #fff);
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1);
text-align: justify;
font-family: "Space Mono";
font-size: 14px;
font-style: normal;
font-weight: 400;
line-height: 22px; /* 157.143% */
letter-spacing: -0.14px;
}
#presets-container {
position: absolute;
left: 50%;
transform: translate(-50%, 0);
width: 100%;
max-width: min(1000px, calc(100% - 200px));
bottom: 16px;
display: inline-flex;
padding: 14px 12px 12px 12px;
flex-direction: column;
justify-content: center;
align-items: center;
gap: 14px;
border-radius: 14px;
box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1);
background: var(--Neutral-5, #181a1b);
z-index: 100;
}
#take-me-somewhere {
color: var(--Neutral-100, #fff);
font-family: "Space Mono";
font-size: 14px;
font-style: normal;
font-weight: 400;
line-height: 14px;
letter-spacing: -0.14px;
width: 100%;
}
#presets {
display: flex;
align-items: center;
gap: 6px;
align-self: stretch;
flex-wrap: wrap;
overflow: hidden;
height: 62px;
}
button {
color: var(--Neutral-100, #fff);
font-family: "Space Mono";
font-size: 13px;
font-style: normal;
font-weight: 400;
line-height: 24px; /* 184.615% */
letter-spacing: -0.13px;
display: inline-flex;
padding: 18px 15px 18px 14px;
justify-content: center;
align-items: center;
border-radius: 8px;
border: 1px solid var(--Neutral-40, #575c5f);
background: var(--Neutral-10, #1c1f21);
text-wrap: nowrap;
flex: 1;
}
button:hover {
border-radius: 8px;
border: 1px solid var(--Blue-400, #80bbff);
background: var(--Neutral-20, #2a2f31);
}
button:active {
border-radius: 8px;
border: 1px solid var(--Neutral-00, #000);
background: var(--Neutral-00, #000);
}
/* Light Theme */
[data-theme="light"] #caption {
background: var(--Neutral-100, #fff);
color: var(--Neutral-00, #000);
}
[data-theme="light"] #presets-container {
background: var(--Neutral-99, #fdfcfb);
}
[data-theme="light"] #take-me-somewhere {
color: var(--Neutral-00, #000);
}
[data-theme="light"] button {
color: var(--Neutral-00, #000);
border: 1px solid var(--Neutral-80, #c3c6c7);
background: var(--Neutral-100, #fff);
}
[data-theme="light"] button:hover {
background: var(--Neutral-80, #c3c6c7);
}
[data-theme="light"] button:active {
border: 1px solid var(--Neutral-80, #c3c6c7);
background: var(--Neutral-80, #c3c6c7);
}
<!doctype html>
<html>
<head>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="root"></div>
<script src="script.js" type="module"></script>
</body>
</html>