forked from gongfudev/new-astro-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webapp.astro
75 lines (66 loc) · 2.22 KB
/
webapp.astro
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
---
import ShoelaceLayout from '../layouts/ShoelaceLayout.astro';
---
<ShoelaceLayout title="Signals › WebApp">
<h1>Signals</h1>
<div id="set01" class="controls">
<camera-control-hpr id="hpr01" angles="[90,30,0]"></camera-control-hpr>
<camera-control-position id="pos01" coord="[45,6,500]"></camera-control-position>
</div>
<div class="scene">
<scene-view angles="[90,30,0]" coord="[45,6,500]"></scene-view>
</div>
<div id="set02" class="controls">
<camera-control-hpr id="hpr02" angles="[90,30,0]"></camera-control-hpr>
<camera-control-position id="pos02" coord="[45,6,500]"></camera-control-position>
</div>
</ShoelaceLayout>
<script>
import { signal } from "@lit-labs/preact-signals";
import "../components/CameraControlHPR.js";
import "../components/CameraControlPosition.js";
import "../components/SceneView.js";
const sceneView = document.querySelector("scene-view");
const allCameraControlHPR = document.querySelectorAll("camera-control-hpr");
const allCameraControlPosition = document.querySelectorAll("camera-control-position");
const angles = signal([90, 30, 0]);
const coord = signal([45, 6, 500]);
sceneView.signals = { angles, coord };
allCameraControlHPR?.forEach((cameraControlHPR, index) => {
cameraControlHPR.signal = angles;
cameraControlHPR.addEventListener("angles-changed", (e) => {
console.log(`HPR ${String(index).padStart(2,'0')} angles changed to [${e.detail.join(",")}]`);
})
});
allCameraControlPosition?.forEach((cameraControlPosition, index) => {
cameraControlPosition.signal = coord;
cameraControlPosition.addEventListener("coord-changed", (e) => {
// how to add leading zeros to the numbers?
console.log(`POS ${String(index).padStart(2,'0')} coordinates changed to [${e.detail.join(",")}]`);
})
});
</script>
<style>
body {
margin: 0 1rem;
}
div.controls {
display: flex;
flex-direction: row;
gap: 1rem;
height: 15rem;
}
div.scene {
margin-top: 1rem; margin-bottom: 1rem;
}
camera-control-hpr,
camera-control-position {
background-color: aliceblue;
padding: 1rem;
width: 50%;
}
scene-view {
background-color: aliceblue;
width: 100%; height: 30rem;
}
</style>