From 6a2ef0097106a13a3b95692b60c05043b3f60f9c Mon Sep 17 00:00:00 2001 From: Claas Date: Sun, 12 Apr 2026 14:32:03 +0200 Subject: [PATCH] Experiment with API --- client/src/App.tsx | 143 ++++++++++++++------------------------- client/src/index.css | 111 ------------------------------ client/src/index.tsx | 3 +- client/tsconfig.app.json | 2 +- 4 files changed, 51 insertions(+), 208 deletions(-) diff --git a/client/src/App.tsx b/client/src/App.tsx index 140c3a3..5161460 100644 --- a/client/src/App.tsx +++ b/client/src/App.tsx @@ -1,102 +1,57 @@ -import { createSignal } from 'solid-js' -import solidLogo from './assets/solid.svg' -import viteLogo from './assets/vite.svg' -import heroImg from './assets/hero.png' -import './App.css' +import { createSignal, onCleanup, Show } from "solid-js"; -function App() { - const [count, setCount] = createSignal(0) - return ( - <> -
-
- - Solid logo - Vite logo -
-
-

Get started

-

- Edit src/App.tsx and save to test HMR -

-
- -
-
+type Orientation = + { isAbsolute: boolean, alpha: number | null, beta: number | null, gamma: number | null } + + +export default function App() { + const dismountAbortController = new AbortController(); + onCleanup(() => dismountAbortController.abort()); + + + const [orientation, setOrientation] = createSignal(); + + async function requestOrientation() { + if ("requestPermission" in DeviceOrientationEvent && typeof DeviceOrientationEvent.requestPermission === "function") { + const result = await DeviceOrientationEvent.requestPermission(); + if (result !== "granted") return; + } + + window.addEventListener("deviceorientation", (event) => { + console.debug("DeviceOrientationEvent", event); + + setOrientation({ + isAbsolute: event.absolute, + alpha: event.alpha, + beta: event.beta, + gamma: event.gamma, + }); + + }, { + signal: dismountAbortController.signal, + }) + } + + return ( +
+ + {(orientation) => (
+
isAbsolute
+
{orientation().isAbsolute.toString()}
+
alpha
+
{orientation().alpha?.toString() ?? "null"}
+
beta
+
{orientation().beta?.toString() ?? "null"}
+
gamma
+
{orientation().gamma?.toString() ?? "null"}
+
)} -
-
- -

Documentation

-

Your questions, answered

- -
-
- -

Connect with us

-

Join the Vite community

- -
-
+
-
-
- + +
) } -export default App diff --git a/client/src/index.css b/client/src/index.css index 2c84af0..e69de29 100644 --- a/client/src/index.css +++ b/client/src/index.css @@ -1,111 +0,0 @@ -:root { - --text: #6b6375; - --text-h: #08060d; - --bg: #fff; - --border: #e5e4e7; - --code-bg: #f4f3ec; - --accent: #aa3bff; - --accent-bg: rgba(170, 59, 255, 0.1); - --accent-border: rgba(170, 59, 255, 0.5); - --social-bg: rgba(244, 243, 236, 0.5); - --shadow: - rgba(0, 0, 0, 0.1) 0 10px 15px -3px, rgba(0, 0, 0, 0.05) 0 4px 6px -2px; - - --sans: system-ui, 'Segoe UI', Roboto, sans-serif; - --heading: system-ui, 'Segoe UI', Roboto, sans-serif; - --mono: ui-monospace, Consolas, monospace; - - font: 18px/145% var(--sans); - letter-spacing: 0.18px; - color-scheme: light dark; - color: var(--text); - background: var(--bg); - font-synthesis: none; - text-rendering: optimizeLegibility; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; - - @media (max-width: 1024px) { - font-size: 16px; - } -} - -@media (prefers-color-scheme: dark) { - :root { - --text: #9ca3af; - --text-h: #f3f4f6; - --bg: #16171d; - --border: #2e303a; - --code-bg: #1f2028; - --accent: #c084fc; - --accent-bg: rgba(192, 132, 252, 0.15); - --accent-border: rgba(192, 132, 252, 0.5); - --social-bg: rgba(47, 48, 58, 0.5); - --shadow: - rgba(0, 0, 0, 0.4) 0 10px 15px -3px, rgba(0, 0, 0, 0.25) 0 4px 6px -2px; - } - - #social .button-icon { - filter: invert(1) brightness(2); - } -} - -body { - margin: 0; -} - -#root { - width: 1126px; - max-width: 100%; - margin: 0 auto; - text-align: center; - border-inline: 1px solid var(--border); - min-height: 100svh; - display: flex; - flex-direction: column; - box-sizing: border-box; -} - -h1, -h2 { - font-family: var(--heading); - font-weight: 500; - color: var(--text-h); -} - -h1 { - font-size: 56px; - letter-spacing: -1.68px; - margin: 32px 0; - @media (max-width: 1024px) { - font-size: 36px; - margin: 20px 0; - } -} -h2 { - font-size: 24px; - line-height: 118%; - letter-spacing: -0.24px; - margin: 0 0 8px; - @media (max-width: 1024px) { - font-size: 20px; - } -} -p { - margin: 0; -} - -code, -.counter { - font-family: var(--mono); - display: inline-flex; - border-radius: 4px; - color: var(--text-h); -} - -code { - font-size: 15px; - line-height: 135%; - padding: 4px 8px; - background: var(--code-bg); -} diff --git a/client/src/index.tsx b/client/src/index.tsx index f67cd20..a46c1fd 100644 --- a/client/src/index.tsx +++ b/client/src/index.tsx @@ -3,6 +3,5 @@ import { render } from 'solid-js/web' import './index.css' import App from './App.tsx' -const root = document.getElementById('root') -render(() => , root!) +render(() => , document.body) diff --git a/client/tsconfig.app.json b/client/tsconfig.app.json index 6108f39..0aaff41 100644 --- a/client/tsconfig.app.json +++ b/client/tsconfig.app.json @@ -3,7 +3,7 @@ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo", "target": "es2023", "module": "esnext", - "lib": ["ES2023", "DOM", "DOM.Iterable"], + "lib": ["ES2025", "DOM", "DOM.Iterable"], "types": ["vite/client"], "skipLibCheck": true, -- 2.51.2