-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview.html
More file actions
613 lines (568 loc) · 21.6 KB
/
preview.html
File metadata and controls
613 lines (568 loc) · 21.6 KB
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
<!DOCTYPE html>
<html lang="cs">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Compass Card Preview</title>
<script src="./compass-card.js"></script>
<style>
:root {
font-family: "Segoe UI", sans-serif;
--preview-bg:
radial-gradient(circle at top, rgba(71, 173, 194, 0.25), transparent 35%),
linear-gradient(160deg, #0d1a28 0%, #071019 100%);
--preview-text: #ecf5f8;
--preview-panel-bg: rgba(10, 20, 31, 0.7);
--preview-panel-shadow: rgba(0, 0, 0, 0.24);
--preview-panel-highlight: rgba(255, 255, 255, 0.05);
--preview-input-bg: rgba(255, 255, 255, 0.08);
--preview-input-border: rgba(180, 210, 220, 0.18);
--preview-muted: rgba(236, 245, 248, 0.7);
--preview-value: rgba(236, 245, 248, 0.76);
color-scheme: dark;
background: var(--preview-bg);
}
:root[data-theme="light"] {
--preview-bg:
radial-gradient(circle at top, rgba(83, 179, 201, 0.16), transparent 34%),
linear-gradient(160deg, #eef6fb 0%, #dfeef6 100%);
--preview-text: #163042;
--preview-panel-bg: rgba(255, 255, 255, 0.78);
--preview-panel-shadow: rgba(76, 112, 135, 0.14);
--preview-panel-highlight: rgba(255, 255, 255, 0.72);
--preview-input-bg: rgba(23, 64, 88, 0.06);
--preview-input-border: rgba(34, 88, 112, 0.18);
--preview-muted: rgba(22, 48, 66, 0.66);
--preview-value: rgba(22, 48, 66, 0.76);
color-scheme: light;
}
:root[data-theme="dark"] {
color-scheme: dark;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
display: grid;
grid-template-columns: minmax(280px, 420px) minmax(320px, 420px);
gap: 24px;
align-items: start;
justify-content: center;
padding: 32px;
color: var(--preview-text);
background: var(--preview-bg);
}
.panel {
padding: 22px;
border-radius: 28px;
background: var(--preview-panel-bg);
box-shadow:
inset 0 1px 0 var(--preview-panel-highlight),
0 18px 40px var(--preview-panel-shadow);
backdrop-filter: blur(12px);
}
h1 {
margin: 0 0 10px;
font-size: 1.2rem;
letter-spacing: 0.04em;
text-transform: uppercase;
}
p {
margin: 0 0 18px;
color: var(--preview-muted);
line-height: 1.45;
}
.controls {
display: grid;
gap: 14px;
}
label {
display: grid;
gap: 6px;
font-size: 0.92rem;
font-weight: 600;
}
input,
select {
width: 100%;
padding: 10px 12px;
border: 1px solid var(--preview-input-border);
border-radius: 12px;
background: var(--preview-input-bg);
color: var(--preview-text);
font: inherit;
}
input[type="range"] {
padding: 0;
}
.row {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 12px;
}
.preview-wrap {
display: grid;
place-items: center;
min-height: 560px;
}
compass-card {
width: min(100%, 380px);
}
ha-card {
display: block;
}
.value {
color: var(--preview-value);
font-size: 0.82rem;
}
@media (max-width: 900px) {
body {
grid-template-columns: 1fr;
padding: 20px;
}
.preview-wrap {
min-height: auto;
}
}
</style>
</head>
<body>
<section class="panel">
<h1>Preview</h1>
<p>Simulace vzhledu mimo Home Assistant. Muzeš menit smer, rychlost i textovy vstup smeru.</p>
<div class="controls">
<label>
Nadpis
<input id="title" type="text" value="Smer vetru">
</label>
<div class="row">
<label>
Rezim preview
<select id="theme-mode">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
</div>
<div class="row">
<label>
Smer ve stupnich
<input id="direction" type="range" min="0" max="359" step="1" value="248">
<span id="direction-value" class="value">248°</span>
</label>
<label>
Rychlost
<input id="speed" type="range" min="0" max="150" step="0.1" value="23.4">
<span id="speed-value" class="value">23.4 km/h</span>
</label>
</div>
<div class="row">
<label>
Rezim kompasu
<select id="compass-mode">
<option value="north_locked" selected>Zamknout sever</option>
<option value="follow_compass">Otacet podle kompasu</option>
</select>
</label>
<label>
Heading kompasu
<input id="compass-heading" type="range" min="0" max="359" step="1" value="32">
<span id="compass-heading-value" class="value">32°</span>
</label>
</div>
<div class="row">
<label>
Smer slunce ve stupnich
<input id="sun-direction" type="range" min="0" max="359" step="1" value="170">
<span id="sun-direction-value" class="value">170°</span>
</label>
<label>
Vyska slunce
<input id="sun-elevation" type="range" min="-20" max="80" step="0.1" value="4">
<span id="sun-elevation-value" class="value">4.0°</span>
</label>
</div>
<div class="row">
<label>
Smer mesice ve stupnich
<input id="moon-direction" type="range" min="0" max="359" step="1" value="112">
<span id="moon-direction-value" class="value">112°</span>
</label>
<label>
Vyska mesice
<input id="moon-elevation" type="range" min="-20" max="80" step="0.1" value="18">
<span id="moon-elevation-value" class="value">18.0°</span>
</label>
</div>
<div class="row">
<label>
Pohyb slunce
<select id="sun-rising">
<option value="true" selected>Vychod</option>
<option value="false">Zapad</option>
</select>
</label>
<label>
Faze mesice
<select id="moon-phase">
<option value="new_moon">New moon</option>
<option value="waxing_crescent">Waxing crescent</option>
<option value="first_quarter">First quarter</option>
<option value="waxing_gibbous" selected>Waxing gibbous</option>
<option value="full_moon">Full moon</option>
<option value="waning_gibbous">Waning gibbous</option>
<option value="last_quarter">Last quarter</option>
<option value="waning_crescent">Waning crescent</option>
</select>
</label>
</div>
<div class="row">
<label>
Zobrazit mesic
<select id="show-moon">
<option value="true" selected>Ano</option>
<option value="false">Ne</option>
</select>
</label>
<label>
Zdroj polohy mesice
<select id="moon-position-source">
<option value="entity" selected>Entita</option>
<option value="observer">Vypocet</option>
</select>
</label>
</div>
<div class="row">
<label>
Latitude pozorovatele
<input id="observer-latitude" type="number" min="-90" max="90" step="0.0001" value="49.1951">
</label>
<label>
Longitude pozorovatele
<input id="observer-longitude" type="number" min="-180" max="180" step="0.0001" value="16.6068">
</label>
</div>
<div class="row">
<label>
Observer entity
<select id="observer-entity">
<option value="zone.home" selected>zone.home</option>
<option value="zone.preview_home">zone.preview_home</option>
</select>
</label>
</div>
<div class="row">
<label>
Textovy smer
<select id="direction-mode">
<option value="degrees" selected>Stupne</option>
<option value="text">Text</option>
</select>
</label>
</div>
<div class="row">
<label>
Text smeru
<select id="direction-text">
<option value="N">N</option>
<option value="NE">NE</option>
<option value="E">E</option>
<option value="SE">SE</option>
<option value="S">S</option>
<option value="SW" selected>SW</option>
<option value="W">W</option>
<option value="NW">NW</option>
<option value="Severovychod">Severovychod</option>
<option value="Jihozapad">Jihozapad</option>
</select>
</label>
</div>
<div class="row">
<label>
Jednotka
<input id="unit" type="text" value="km/h">
</label>
<label>
Oznaceni smeru
<select id="direction-language">
<option value="en">English</option>
<option value="cs">Cestina</option>
</select>
</label>
</div>
<div class="row">
<label>
Zobrazit slunce
<select id="show-sun">
<option value="true" selected>Ano</option>
<option value="false">Ne</option>
</select>
</label>
<label>
Zobrazit stupne
<select id="show-degrees">
<option value="true" selected>Ano</option>
<option value="false">Ne</option>
</select>
</label>
</div>
</div>
</section>
<section class="preview-wrap">
<compass-card id="card"></compass-card>
</section>
<script>
const card = document.getElementById("card");
const titleInput = document.getElementById("title");
const themeModeInput = document.getElementById("theme-mode");
const directionInput = document.getElementById("direction");
const speedInput = document.getElementById("speed");
const compassModeInput = document.getElementById("compass-mode");
const compassHeadingInput = document.getElementById("compass-heading");
const sunDirectionInput = document.getElementById("sun-direction");
const sunElevationInput = document.getElementById("sun-elevation");
const sunRisingInput = document.getElementById("sun-rising");
const moonDirectionInput = document.getElementById("moon-direction");
const moonElevationInput = document.getElementById("moon-elevation");
const moonPhaseInput = document.getElementById("moon-phase");
const showMoonInput = document.getElementById("show-moon");
const moonPositionSourceInput = document.getElementById("moon-position-source");
const observerLatitudeInput = document.getElementById("observer-latitude");
const observerLongitudeInput = document.getElementById("observer-longitude");
const observerEntityInput = document.getElementById("observer-entity");
const unitInput = document.getElementById("unit");
const directionLanguageInput = document.getElementById("direction-language");
const showSunInput = document.getElementById("show-sun");
const directionModeInput = document.getElementById("direction-mode");
const directionTextInput = document.getElementById("direction-text");
const showDegreesInput = document.getElementById("show-degrees");
const directionValue = document.getElementById("direction-value");
const speedValue = document.getElementById("speed-value");
const compassHeadingValue = document.getElementById("compass-heading-value");
const sunDirectionValue = document.getElementById("sun-direction-value");
const sunElevationValue = document.getElementById("sun-elevation-value");
const moonDirectionValue = document.getElementById("moon-direction-value");
const moonElevationValue = document.getElementById("moon-elevation-value");
const config = {
type: "custom:compass-card",
title: "Smer vetru",
direction_entity: "sensor.preview_wind_direction",
speed_entity: "sensor.preview_wind_speed",
speed_decimals: 1,
degree_decimals: 0,
show_degrees: true,
};
card.setConfig(config);
const themeOverrides = {
light: {
"--compass-card-bg":
"radial-gradient(circle at 50% 38%, rgba(39, 163, 190, 0.16), transparent 42%), linear-gradient(165deg, rgba(243, 250, 255, 0.98) 0%, rgba(221, 237, 247, 0.98) 100%)",
"--compass-ring": "rgba(34, 88, 112, 0.12)",
"--compass-ring-strong": "rgba(34, 88, 112, 0.24)",
"--compass-card-text-color": "#173042",
"--compass-card-muted-color": "rgba(23, 48, 66, 0.62)",
"--compass-center": "rgba(255, 255, 255, 0.9)",
"--compass-chip-bg": "rgba(22, 58, 79, 0.08)",
"--compass-shell-border": "rgba(31, 92, 122, 0.1)",
"--compass-highlight": "rgba(255, 255, 255, 0.72)",
"--compass-shadow": "rgba(65, 104, 128, 0.18)",
"--compass-surface-shadow": "rgba(87, 125, 149, 0.18)",
"--compass-svg-shadow": "rgba(58, 93, 122, 0.12)",
"--compass-tick": "rgba(31, 92, 122, 0.32)",
"--compass-tick-strong": "rgba(23, 72, 98, 0.58)",
"--compass-cardinal": "rgba(25, 74, 100, 0.8)",
"--compass-cardinal-stroke": "rgba(245, 251, 255, 0.92)",
},
dark: {
"--compass-card-bg":
"radial-gradient(circle at 50% 42%, rgba(57, 192, 181, 0.26), transparent 42%), linear-gradient(160deg, rgba(18, 30, 44, 0.96) 0%, rgba(8, 18, 29, 0.98) 100%)",
"--compass-ring": "rgba(176, 229, 224, 0.18)",
"--compass-ring-strong": "rgba(176, 229, 224, 0.34)",
"--compass-card-text-color": "#f3f8fb",
"--compass-card-muted-color": "rgba(243, 248, 251, 0.64)",
"--compass-center": "rgba(11, 28, 39, 0.92)",
"--compass-chip-bg": "rgba(255, 255, 255, 0.08)",
"--compass-shell-border": "rgba(255, 255, 255, 0.05)",
"--compass-highlight": "rgba(255, 255, 255, 0.08)",
"--compass-shadow": "rgba(0, 0, 0, 0.22)",
"--compass-surface-shadow": "rgba(0, 0, 0, 0.28)",
"--compass-svg-shadow": "rgba(0, 0, 0, 0.22)",
"--compass-tick": "rgba(230, 252, 249, 0.28)",
"--compass-tick-strong": "rgba(230, 252, 249, 0.54)",
"--compass-cardinal": "rgba(244, 251, 255, 0.96)",
"--compass-cardinal-stroke": "rgba(3, 12, 20, 0.96)",
},
};
function applyPreviewTheme() {
const selectedTheme = themeModeInput.value;
const themeValue = selectedTheme === "auto" ? "" : selectedTheme;
document.documentElement.dataset.theme = themeValue;
document.body.dataset.theme = themeValue;
Object.keys(themeOverrides.dark).forEach((property) => {
card.style.removeProperty(property);
});
if (selectedTheme === "light" || selectedTheme === "dark") {
Object.entries(themeOverrides[selectedTheme]).forEach(([property, value]) => {
card.style.setProperty(property, value);
});
}
}
function renderCard() {
const directionDegrees = Number(directionInput.value);
const speed = Number(speedInput.value);
const compassMode = compassModeInput.value;
const compassHeading = Number(compassHeadingInput.value);
const sunDegrees = Number(sunDirectionInput.value);
const sunElevation = Number(sunElevationInput.value);
const sunRising = sunRisingInput.value === "true";
const moonDegrees = Number(moonDirectionInput.value);
const moonElevation = Number(moonElevationInput.value);
const moonPhase = moonPhaseInput.value;
const showMoon = showMoonInput.value === "true";
const moonPositionSource = moonPositionSourceInput.value;
const moonUsesComputedPosition = moonPositionSource === "observer";
const observerLatitude = Number(observerLatitudeInput.value);
const observerLongitude = Number(observerLongitudeInput.value);
const observerEntity = observerEntityInput.value || "zone.home";
const useTextDirection = directionModeInput.value === "text";
const directionState = useTextDirection ? directionTextInput.value : String(directionDegrees);
directionValue.textContent = `${directionDegrees}°`;
speedValue.textContent = `${speed.toFixed(1)} ${unitInput.value || "km/h"}`;
compassHeadingValue.textContent = `${compassHeading}°`;
sunDirectionValue.textContent = `${sunDegrees}°`;
sunElevationValue.textContent = `${sunElevation.toFixed(1)}°`;
moonDirectionValue.textContent = `${moonDegrees}°`;
moonElevationValue.textContent = `${moonElevation.toFixed(1)}°`;
card.setConfig({
...config,
title: titleInput.value || "Smer vetru",
direction_language: directionLanguageInput.value,
compass_mode: compassMode,
compass_entity: "sensor.preview_compass_heading",
compass_attribute: "heading",
show_sun: showSunInput.value === "true",
show_moon: showMoon,
sun_entity: "sun.sun",
sun_attribute: "azimuth",
moon_phase_entity: "sensor.moon",
moon_position_entity: moonUsesComputedPosition ? "" : "sensor.preview_moon_position",
moon_azimuth_attribute: "azimuth",
moon_elevation_attribute: "elevation",
observer_entity: observerEntity,
speed_unit: unitInput.value || "",
show_degrees: showDegreesInput.value === "true",
});
card.hass = {
states: {
"sensor.preview_wind_direction": {
entity_id: "sensor.preview_wind_direction",
state: directionState,
attributes: {
friendly_name: "Preview Wind Direction",
unit_of_measurement: useTextDirection ? "" : "°",
},
},
"sensor.preview_wind_speed": {
entity_id: "sensor.preview_wind_speed",
state: speed.toFixed(1),
attributes: {
friendly_name: "Preview Wind Speed",
unit_of_measurement: unitInput.value || "km/h",
},
},
"sensor.preview_compass_heading": {
entity_id: "sensor.preview_compass_heading",
state: String(compassHeading),
attributes: {
friendly_name: "Preview Compass Heading",
heading: compassHeading,
unit_of_measurement: "°",
},
},
"sun.sun": {
entity_id: "sun.sun",
state: sunElevation >= -0.8 ? "above_horizon" : "below_horizon",
attributes: {
friendly_name: "Sun",
azimuth: sunDegrees,
elevation: sunElevation,
rising: sunRising,
},
},
"sensor.moon": {
entity_id: "sensor.moon",
state: moonPhase,
attributes: {
friendly_name: "Moon",
},
},
"sensor.preview_moon_position": {
entity_id: "sensor.preview_moon_position",
state: moonDegrees.toFixed(0),
attributes: {
friendly_name: "Preview Moon Position",
azimuth: moonDegrees,
elevation: moonElevation,
},
},
"zone.home": {
entity_id: "zone.home",
state: "zoning",
attributes: {
friendly_name: "Home",
latitude: observerLatitude,
longitude: observerLongitude,
},
},
"zone.preview_home": {
entity_id: "zone.preview_home",
state: "zoning",
attributes: {
friendly_name: "Preview Home",
latitude: observerLatitude,
longitude: observerLongitude,
},
},
},
config: {
latitude: observerLatitude,
longitude: observerLongitude,
},
};
}
[
titleInput,
themeModeInput,
directionInput,
speedInput,
compassModeInput,
compassHeadingInput,
sunDirectionInput,
sunElevationInput,
sunRisingInput,
moonDirectionInput,
moonElevationInput,
moonPhaseInput,
showMoonInput,
moonPositionSourceInput,
observerLatitudeInput,
observerLongitudeInput,
observerEntityInput,
unitInput,
directionLanguageInput,
showSunInput,
directionModeInput,
directionTextInput,
showDegreesInput,
].forEach((element) => element.addEventListener("input", () => {
applyPreviewTheme();
renderCard();
}));
applyPreviewTheme();
renderCard();
</script>
</body>
</html>