flight-indicators 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,134 @@
1
- # Temporary Holding Version
1
+ # flight-indicators
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ![flight-indicators demo: airspeed, attitude, altimeter, turn coordinator, heading and vertical speed instruments](docs/demo.png)
4
+
5
+ Modern SVG flight instruments for React, with no runtime dependencies.
6
+
7
+ - Six instruments: **Attitude**, **Heading**, **Airspeed**, **Altimeter**, **Vertical speed** and **Turn coordinator**
8
+ - Pure SVG with no image files, so instruments stay sharp at any size and work with any bundler
9
+ - Written in TypeScript and ships its type declarations
10
+ - Ships ESM and CommonJS builds, works with server-side rendering, and is marked `"use client"` for the Next.js App Router
11
+ - Smooth CSS animation; the heading and roll take the shortest way round (359° → 1° moves 2°, not 358°)
12
+ - Bad input (`NaN`, `undefined`, out of range) is clamped instead of breaking the drawing
13
+ - Accessible: each instrument is an `role="img"` with a live text label (e.g. "Altimeter: 12340 feet, 29.92 inHg")
14
+
15
+ ## Install
16
+
17
+ ```bash
18
+ npm i flight-indicators
19
+ ```
20
+
21
+ Requires React 18 or newer.
22
+
23
+ ## Usage
24
+
25
+ ```tsx
26
+ import {
27
+ AttitudeIndicator,
28
+ HeadingIndicator,
29
+ Airspeed,
30
+ Altimeter,
31
+ VerticalSpeed,
32
+ TurnCoordinator,
33
+ } from 'flight-indicators';
34
+
35
+ export function Panel({ data }) {
36
+ return (
37
+ <div style={{ display: 'flex', flexWrap: 'wrap', gap: 12 }}>
38
+ <Airspeed speed={data.ias} />
39
+ <AttitudeIndicator roll={data.roll} pitch={data.pitch} />
40
+ <Altimeter altitude={data.altitude} pressure={1013} />
41
+ <TurnCoordinator turnRate={data.turnRate} slip={data.slip} />
42
+ <HeadingIndicator heading={data.heading} />
43
+ <VerticalSpeed verticalSpeed={data.vs} />
44
+ </div>
45
+ );
46
+ }
47
+ ```
48
+
49
+ ## Common props
50
+
51
+ Every instrument accepts these props:
52
+
53
+ | Prop | Type | Default | Description |
54
+ | ------------------- | ------------------ | ------- | --------------------------------------------------------- |
55
+ | `size` | `number \| string` | `200` | Width and height. A number means pixels; a string can be any CSS length, e.g. `"100%"`. |
56
+ | `showBox` | `boolean` | `true` | Draw the square mounting plate with screws. |
57
+ | `animationDuration` | `number` | `300` | Animation time in ms. `0` turns animation off. |
58
+ | `className` | `string` | | Class for the root `<svg>`. |
59
+ | `style` | `CSSProperties` | | Inline style for the root `<svg>`. |
60
+ | `title` | `string` | | Overrides the automatic accessible label. |
61
+
62
+ ## Instruments
63
+
64
+ ### `<AttitudeIndicator />`
65
+
66
+ | Prop | Type | Default | Description |
67
+ | ------------ | -------- | ------- | ------------------------------------------------ |
68
+ | `roll` | `number` | `0` | Bank angle in degrees. Positive means right wing down. |
69
+ | `pitch` | `number` | `0` | Pitch angle in degrees. Positive means nose up. |
70
+ | `pitchLimit` | `number` | `40` | Largest pitch the display shows, in degrees. |
71
+
72
+ ### `<HeadingIndicator />`
73
+
74
+ | Prop | Type | Default | Description |
75
+ | --------- | -------- | ------- | ------------------------------------------ |
76
+ | `heading` | `number` | `0` | Heading in degrees. Any value is accepted and wrapped to 0–359. |
77
+
78
+ ### `<Airspeed />`
79
+
80
+ | Prop | Type | Default | Description |
81
+ | ------- | -------------- | --------------- | --------------------------------------------- |
82
+ | `speed` | `number` | `0` | Indicated airspeed. Clamped to `0…max`. |
83
+ | `max` | `number` | `200` | Top of the scale. |
84
+ | `arcs` | `AirspeedArcs` | similar to a Cessna 172 | `{ white?: [min, max], green?: [min, max], yellow?: [min, max], red?: vne }`. Pass `{}` to hide all arcs. |
85
+ | `unit` | `string` | `"KNOTS"` | Unit text printed on the dial. |
86
+
87
+ ### `<Altimeter />`
88
+
89
+ | Prop | Type | Default | Description |
90
+ | -------------- | ----------------- | --------------- | -------------------------------------------- |
91
+ | `altitude` | `number` | `0` | Altitude in feet. Negative values work. |
92
+ | `pressure` | `number` | `1013` / `29.92` | Altimeter setting shown in the pressure (Kollsman) window. |
93
+ | `pressureUnit` | `"hPa" \| "inHg"` | `"hPa"` | Unit of `pressure`. |
94
+
95
+ ### `<VerticalSpeed />`
96
+
97
+ | Prop | Type | Default | Description |
98
+ | --------------- | -------- | ------- | ---------------------------------------------- |
99
+ | `verticalSpeed` | `number` | `0` | Vertical speed in ft/min. Positive means climbing. |
100
+ | `max` | `number` | `2000` | Full-scale value in ft/min. |
101
+
102
+ ### `<TurnCoordinator />`
103
+
104
+ | Prop | Type | Default | Description |
105
+ | ---------- | -------- | ------- | ------------------------------------------------------------------- |
106
+ | `turnRate` | `number` | `0` | Rate of turn in °/s. Positive means a right turn. At 3 °/s (a standard-rate turn) the wings line up with the L/R marks. |
107
+ | `slip` | `number` | `0` | Position of the slip ball, from `-1` (full left) to `1` (full right). |
108
+
109
+ ## Development
110
+
111
+ ```bash
112
+ npm install
113
+ npm run dev # interactive playground (Vite) at http://localhost:5173
114
+ npm test # unit tests (Vitest)
115
+ npm run typecheck
116
+ npm run build # outputs dist/ (ESM + CJS + .d.ts)
117
+ ```
118
+
119
+ ## Releasing
120
+
121
+ Releases run from GitHub Actions:
122
+
123
+ - **CI** (`ci.yml`) runs on every push and pull request. It typechecks, tests and builds on Node 22 and 24, then installs the packed tarball on Node 18, 20 and 22 and checks that every component renders.
124
+ - **Release** (`release.yml`) is started by hand from the Actions tab, where you choose `patch`, `minor` or `major`. It bumps the version, commits, tags, creates a GitHub release and then triggers Publish.
125
+ - **Publish** (`publish.yml`) publishes to npm with provenance using [trusted publishing](https://docs.npmjs.com/trusted-publishers), so no npm token is stored. It skips versions that are already on npm, so it is safe to re-run.
126
+
127
+ One-time setup:
128
+
129
+ 1. Publish the first version by hand (`npm login && npm publish`), because npm can only set a trusted publisher on a package that already exists.
130
+ 2. On npmjs.com, open the package's **Settings**, then **Trusted publishing**, and add GitHub Actions with this repository and the workflow file `publish.yml`.
131
+
132
+ ## License
133
+
134
+ MIT
package/dist/index.cjs ADDED
@@ -0,0 +1,414 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ Airspeed: () => Airspeed,
25
+ Altimeter: () => Altimeter,
26
+ AttitudeIndicator: () => AttitudeIndicator,
27
+ HeadingIndicator: () => HeadingIndicator,
28
+ TurnCoordinator: () => TurnCoordinator,
29
+ VerticalSpeed: () => VerticalSpeed
30
+ });
31
+ module.exports = __toCommonJS(index_exports);
32
+
33
+ // src/utils.ts
34
+ var import_react = require("react");
35
+ var CENTER = 200;
36
+ var DEFAULT_ANIMATION_MS = 300;
37
+ var clamp = (value, min, max) => Math.min(max, Math.max(min, value));
38
+ var finite = (value, fallback = 0) => typeof value === "number" && Number.isFinite(value) ? value : fallback;
39
+ var round = (n) => Math.round(n * 100) / 100;
40
+ function polar(r, deg, cx = CENTER, cy = CENTER) {
41
+ const a = deg * Math.PI / 180;
42
+ return [round(cx + r * Math.sin(a)), round(cy - r * Math.cos(a))];
43
+ }
44
+ function arcPath(r, startDeg, endDeg) {
45
+ const [x1, y1] = polar(r, startDeg);
46
+ const [x2, y2] = polar(r, endDeg);
47
+ const largeArc = Math.abs(endDeg - startDeg) > 180 ? 1 : 0;
48
+ const sweep = endDeg >= startDeg ? 1 : 0;
49
+ return `M ${x1} ${y1} A ${r} ${r} 0 ${largeArc} ${sweep} ${x2} ${y2}`;
50
+ }
51
+ function tickPath(r1, r2, deg) {
52
+ const [x1, y1] = polar(r1, deg);
53
+ const [x2, y2] = polar(r2, deg);
54
+ return `M ${x1} ${y1} L ${x2} ${y2}`;
55
+ }
56
+ function range(start, end, step) {
57
+ const out = [];
58
+ for (let v = start; v <= end + 1e-9; v += step) out.push(round(v));
59
+ return out;
60
+ }
61
+ function motionStyle(transform, durationMs, originX = CENTER, originY = CENTER) {
62
+ return {
63
+ transform,
64
+ transformOrigin: `${originX}px ${originY}px`,
65
+ transformBox: "view-box",
66
+ transition: durationMs > 0 ? `transform ${durationMs}ms ease-out` : void 0
67
+ };
68
+ }
69
+ function useContinuousAngle(angle) {
70
+ const previous = (0, import_react.useRef)(null);
71
+ let next = angle;
72
+ if (previous.current !== null) {
73
+ const delta = ((angle - previous.current) % 360 + 540) % 360 - 180;
74
+ next = previous.current + delta;
75
+ }
76
+ (0, import_react.useEffect)(() => {
77
+ previous.current = next;
78
+ });
79
+ return next;
80
+ }
81
+ function useSvgId(prefix) {
82
+ return `${prefix}-${(0, import_react.useId)().replace(/[^a-zA-Z0-9_-]/g, "")}`;
83
+ }
84
+
85
+ // src/components/Instrument.tsx
86
+ var import_jsx_runtime = require("react/jsx-runtime");
87
+ var SCREWS = [
88
+ [32, 32],
89
+ [368, 32],
90
+ [32, 368],
91
+ [368, 368]
92
+ ];
93
+ function InstrumentFrame({
94
+ size = 200,
95
+ showBox = true,
96
+ className,
97
+ style,
98
+ title,
99
+ label,
100
+ children
101
+ }) {
102
+ const titleId = useSvgId("fi-title");
103
+ const bezelId = useSvgId("fi-bezel");
104
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
105
+ "svg",
106
+ {
107
+ xmlns: "http://www.w3.org/2000/svg",
108
+ viewBox: "0 0 400 400",
109
+ width: size,
110
+ height: size,
111
+ role: "img",
112
+ "aria-labelledby": titleId,
113
+ className,
114
+ style: { display: "inline-block", userSelect: "none", ...style },
115
+ fontFamily: "'Helvetica Neue', Arial, sans-serif",
116
+ children: [
117
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("title", { id: titleId, children: title ?? label }),
118
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("linearGradient", { id: bezelId, x1: "0", y1: "0", x2: "0", y2: "1", children: [
119
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "0", stopColor: "#5a5a5a" }),
120
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("stop", { offset: "1", stopColor: "#1a1a1a" })
121
+ ] }) }),
122
+ showBox && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
123
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("rect", { x: "2", y: "2", width: "396", height: "396", rx: "36", fill: "#232323", stroke: "#0d0d0d", strokeWidth: "4" }),
124
+ SCREWS.map(([x, y]) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("g", { children: [
125
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: x, cy: y, r: "12", fill: "#3a3a3a", stroke: "#111", strokeWidth: "2" }),
126
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: `M ${x - 8} ${y + 3} L ${x + 8} ${y - 3}`, stroke: "#111", strokeWidth: "3" })
127
+ ] }, `${x}-${y}`))
128
+ ] }),
129
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: CENTER, cy: CENTER, r: "196", fill: `url(#${bezelId})` }),
130
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: CENTER, cy: CENTER, r: "182", fill: "#111", stroke: "#000", strokeWidth: "4" }),
131
+ children
132
+ ]
133
+ }
134
+ );
135
+ }
136
+ function Hub({ r = 14 }) {
137
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: CENTER, cy: CENTER, r, fill: "#2a2a2a", stroke: "#555", strokeWidth: "2" });
138
+ }
139
+
140
+ // src/components/AttitudeIndicator.tsx
141
+ var import_jsx_runtime2 = require("react/jsx-runtime");
142
+ var PX_PER_DEG = 4;
143
+ var FACE_R = 180;
144
+ var ROLL_MARKS = [
145
+ [10, 12],
146
+ [20, 12],
147
+ [30, 22],
148
+ [45, 12],
149
+ [60, 22]
150
+ ];
151
+ function AttitudeIndicator({ roll = 0, pitch = 0, pitchLimit = 40, ...props }) {
152
+ const duration = props.animationDuration ?? DEFAULT_ANIMATION_MS;
153
+ const limit = Math.abs(finite(pitchLimit, 40));
154
+ const safeRoll = finite(roll);
155
+ const safePitch = clamp(finite(pitch), -limit, limit);
156
+ const displayRoll = useContinuousAngle(safeRoll);
157
+ const clipId = useSvgId("fi-ai-clip");
158
+ const ladder = range(-90, 90, 5).filter((d) => d !== 0);
159
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
160
+ InstrumentFrame,
161
+ {
162
+ ...props,
163
+ label: `Attitude indicator: pitch ${Math.round(safePitch)}\xB0, roll ${Math.round(safeRoll)}\xB0`,
164
+ children: [
165
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("defs", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("clipPath", { id: clipId, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: CENTER, cy: CENTER, r: FACE_R }) }) }),
166
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("g", { clipPath: `url(#${clipId})`, children: [
167
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
168
+ "g",
169
+ {
170
+ "data-testid": "attitude-horizon",
171
+ style: motionStyle(`rotate(${-displayRoll}deg) translate(0px, ${safePitch * PX_PER_DEG}px)`, duration),
172
+ children: [
173
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: -400, y: -600, width: 1200, height: 800, fill: "#3b8fd6" }),
174
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("rect", { x: -400, y: CENTER, width: 1200, height: 800, fill: "#8a5a2b" }),
175
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: -400, y1: CENTER, x2: 800, y2: CENTER, stroke: "#fff", strokeWidth: "3" }),
176
+ ladder.map((d) => {
177
+ const y = CENTER - d * PX_PER_DEG;
178
+ const major = d % 10 === 0;
179
+ const half = major ? 50 : 22;
180
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("g", { children: [
181
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: CENTER - half, y1: y, x2: CENTER + half, y2: y, stroke: "#fff", strokeWidth: major ? 3 : 2 }),
182
+ major && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
183
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("text", { x: CENTER - half - 8, y: y + 6, fill: "#fff", fontSize: "17", fontWeight: "bold", textAnchor: "end", children: Math.abs(d) }),
184
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("text", { x: CENTER + half + 8, y: y + 6, fill: "#fff", fontSize: "17", fontWeight: "bold", children: Math.abs(d) })
185
+ ] })
186
+ ] }, d);
187
+ })
188
+ ]
189
+ }
190
+ ),
191
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("g", { stroke: "#fff", strokeWidth: "4", strokeLinecap: "round", children: ROLL_MARKS.flatMap(([deg, len]) => [
192
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: tickPath(FACE_R - 2, FACE_R - 2 - len, -deg) }, `l${deg}`),
193
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: tickPath(FACE_R - 2, FACE_R - 2 - len, deg) }, `r${deg}`)
194
+ ]) }),
195
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: `M ${CENTER} ${CENTER - 158} l -10 -18 h 20 z`, fill: "#fff" }),
196
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("g", { "data-testid": "attitude-roll-pointer", style: motionStyle(`rotate(${-displayRoll}deg)`, duration), children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: `M ${CENTER} ${CENTER - 156} l -10 18 h 20 z`, fill: "#ffb000" }) })
197
+ ] }),
198
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("g", { fill: "none", stroke: "#ffb000", strokeWidth: "8", strokeLinecap: "round", strokeLinejoin: "round", children: [
199
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: `M ${CENTER - 110} ${CENTER} H ${CENTER - 40} l 14 16` }),
200
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("path", { d: `M ${CENTER + 110} ${CENTER} H ${CENTER + 40} l -14 16` })
201
+ ] }),
202
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("circle", { cx: CENTER, cy: CENTER, r: "6", fill: "#ffb000" })
203
+ ]
204
+ }
205
+ );
206
+ }
207
+
208
+ // src/components/HeadingIndicator.tsx
209
+ var import_jsx_runtime3 = require("react/jsx-runtime");
210
+ var CARDINALS = { 0: "N", 90: "E", 180: "S", 270: "W" };
211
+ function HeadingIndicator({ heading = 0, ...props }) {
212
+ const duration = props.animationDuration ?? DEFAULT_ANIMATION_MS;
213
+ const safeHeading = finite(heading);
214
+ const normalised = (Math.round(safeHeading) % 360 + 360) % 360;
215
+ const displayHeading = useContinuousAngle(safeHeading);
216
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(InstrumentFrame, { ...props, label: `Heading indicator: ${String(normalised).padStart(3, "0")}\xB0`, children: [
217
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("g", { "data-testid": "heading-card", style: motionStyle(`rotate(${-displayHeading}deg)`, duration), children: [
218
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("g", { stroke: "#fff", strokeLinecap: "round", children: range(0, 355, 5).map((a) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: tickPath(176, a % 10 === 0 ? 152 : 164, a), strokeWidth: a % 10 === 0 ? 3 : 2 }, a)) }),
219
+ range(0, 330, 30).map((a) => {
220
+ const [x, y] = polar(132, a);
221
+ const label = CARDINALS[a] ?? String(a / 10);
222
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
223
+ "text",
224
+ {
225
+ x,
226
+ y,
227
+ transform: `rotate(${a} ${x} ${y})`,
228
+ fill: a % 90 === 0 ? "#ffb000" : "#fff",
229
+ fontSize: a % 90 === 0 ? 30 : 26,
230
+ fontWeight: "bold",
231
+ textAnchor: "middle",
232
+ dominantBaseline: "central",
233
+ children: label
234
+ },
235
+ a
236
+ );
237
+ })
238
+ ] }),
239
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("g", { stroke: "#ffb000", strokeWidth: "4", strokeLinecap: "round", children: [45, 135, 225, 315].map((a) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: tickPath(192, 178, a) }, a)) }),
240
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("path", { d: `M ${CENTER} ${CENTER - 150} l -9 -26 h 18 z`, fill: "#ffb000" }),
241
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
242
+ "path",
243
+ {
244
+ d: "M200 135 c6 0 8 8 8 16 v30 l52 18 v12 l-52 -8 v34 l18 12 v10 l-26 -6 l-26 6 v-10 l18 -12 v-34 l-52 8 v-12 l52 -18 v-30 c0 -8 2 -16 8 -16 z",
245
+ fill: "#ffb000",
246
+ stroke: "#000",
247
+ strokeWidth: "2"
248
+ }
249
+ )
250
+ ] });
251
+ }
252
+
253
+ // src/components/Airspeed.tsx
254
+ var import_jsx_runtime4 = require("react/jsx-runtime");
255
+ var SWEEP = 320;
256
+ var DEFAULT_ARCS = { white: [33, 85], green: [44, 129], yellow: [129, 163], red: 163 };
257
+ function labelStep(max) {
258
+ const raw = max / 10;
259
+ const steps = [5, 10, 20, 25, 50, 100, 200, 250, 500];
260
+ return steps.find((s) => s >= raw) ?? Math.ceil(raw / 100) * 100;
261
+ }
262
+ function Airspeed({ speed = 0, max = 200, arcs = DEFAULT_ARCS, unit = "KNOTS", ...props }) {
263
+ const duration = props.animationDuration ?? DEFAULT_ANIMATION_MS;
264
+ const safeMax = Math.max(1, finite(max, 200));
265
+ const safeSpeed = clamp(finite(speed), 0, safeMax);
266
+ const angle = (v) => clamp(v, 0, safeMax) / safeMax * SWEEP;
267
+ const step = labelStep(safeMax);
268
+ const minor = step / (step % 4 === 0 ? 4 : 5);
269
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(InstrumentFrame, { ...props, label: `Airspeed indicator: ${Math.round(safeSpeed)} ${unit.toLowerCase()}`, children: [
270
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("g", { fill: "none", children: [
271
+ arcs.white && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: arcPath(150, angle(arcs.white[0]), angle(arcs.white[1])), stroke: "#fff", strokeWidth: "8" }),
272
+ arcs.green && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: arcPath(166, angle(arcs.green[0]), angle(arcs.green[1])), stroke: "#2fb54a", strokeWidth: "12" }),
273
+ arcs.yellow && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: arcPath(166, angle(arcs.yellow[0]), angle(arcs.yellow[1])), stroke: "#f2c200", strokeWidth: "12" }),
274
+ arcs.red !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: tickPath(178, 146, angle(arcs.red)), stroke: "#e02020", strokeWidth: "6" })
275
+ ] }),
276
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("g", { stroke: "#fff", strokeLinecap: "round", children: range(0, safeMax, minor).map((v) => {
277
+ const major = Math.abs(v % step) < 1e-9;
278
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: tickPath(178, major ? 150 : 162, angle(v)), strokeWidth: major ? 3 : 2 }, v);
279
+ }) }),
280
+ range(0, safeMax, step).map((v) => {
281
+ const [x, y] = polar(124, angle(v));
282
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("text", { x, y, fill: "#fff", fontSize: "24", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: v }, v);
283
+ }),
284
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("text", { x: CENTER, y: CENTER - 42, fill: "#ccc", fontSize: "18", textAnchor: "middle", children: "AIRSPEED" }),
285
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("text", { x: CENTER, y: CENTER + 56, fill: "#ccc", fontSize: "16", textAnchor: "middle", children: unit }),
286
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("g", { "data-testid": "airspeed-needle", style: motionStyle(`rotate(${angle(safeSpeed)}deg)`, duration), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("path", { d: `M ${CENTER - 5} ${CENTER + 30} L ${CENTER - 4} ${CENTER - 140} L ${CENTER} ${CENTER - 165} L ${CENTER + 4} ${CENTER - 140} L ${CENTER + 5} ${CENTER + 30} Z`, fill: "#fff" }) }),
287
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Hub, {})
288
+ ] });
289
+ }
290
+
291
+ // src/components/Altimeter.tsx
292
+ var import_jsx_runtime5 = require("react/jsx-runtime");
293
+ var STANDARD = { hPa: 1013, inHg: 29.92 };
294
+ function Altimeter({ altitude = 0, pressure, pressureUnit = "hPa", ...props }) {
295
+ const duration = props.animationDuration ?? DEFAULT_ANIMATION_MS;
296
+ const alt = finite(altitude);
297
+ const qnh = finite(pressure, STANDARD[pressureUnit]);
298
+ const qnhText = pressureUnit === "inHg" ? qnh.toFixed(2) : Math.round(qnh).toString();
299
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(InstrumentFrame, { ...props, label: `Altimeter: ${Math.round(alt)} feet, ${qnhText} ${pressureUnit}`, children: [
300
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { stroke: "#fff", strokeLinecap: "round", children: range(0, 49, 1).map((i) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: tickPath(178, i % 5 === 0 ? 150 : 164, i * 7.2), strokeWidth: i % 5 === 0 ? 4 : 2 }, i)) }),
301
+ range(0, 9, 1).map((n) => {
302
+ const [x, y] = polar(126, n * 36);
303
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("text", { x, y, fill: "#fff", fontSize: "32", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: n }, n);
304
+ }),
305
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("text", { x: CENTER, y: CENTER - 58, fill: "#ccc", fontSize: "16", textAnchor: "middle", children: "ALT" }),
306
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("text", { x: CENTER, y: CENTER - 40, fill: "#ccc", fontSize: "12", textAnchor: "middle", children: "100 FEET" }),
307
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("rect", { x: CENTER + 30, y: CENTER - 16, width: "74", height: "32", rx: "4", fill: "#000", stroke: "#666", strokeWidth: "2" }),
308
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("text", { "data-testid": "altimeter-pressure", x: CENTER + 67, y: CENTER + 1, fill: "#fff", fontSize: "20", fontFamily: "monospace", textAnchor: "middle", dominantBaseline: "central", children: qnhText }),
309
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("text", { x: CENTER + 67, y: CENTER + 30, fill: "#ccc", fontSize: "12", textAnchor: "middle", children: pressureUnit }),
310
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("g", { "data-testid": "altimeter-10000", style: motionStyle(`rotate(${alt / 1e5 * 360}deg)`, duration), children: [
311
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: `M ${CENTER} ${CENTER} L ${CENTER} ${CENTER - 150}`, stroke: "#fff", strokeWidth: "3" }),
312
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: `M ${CENTER} ${CENTER - 178} l -10 22 h 20 z`, fill: "#fff" })
313
+ ] }),
314
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { "data-testid": "altimeter-1000", style: motionStyle(`rotate(${alt / 1e4 * 360}deg)`, duration), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: `M ${CENTER - 9} ${CENTER + 14} L ${CENTER - 12} ${CENTER - 70} L ${CENTER} ${CENTER - 100} L ${CENTER + 12} ${CENTER - 70} L ${CENTER + 9} ${CENTER + 14} Z`, fill: "#fff", stroke: "#000", strokeWidth: "1.5" }) }),
315
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("g", { "data-testid": "altimeter-100", style: motionStyle(`rotate(${alt / 1e3 * 360}deg)`, duration), children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("path", { d: `M ${CENTER - 5} ${CENTER + 30} L ${CENTER - 4} ${CENTER - 140} L ${CENTER} ${CENTER - 168} L ${CENTER + 4} ${CENTER - 140} L ${CENTER + 5} ${CENTER + 30} Z`, fill: "#fff", stroke: "#000", strokeWidth: "1.5" }) }),
316
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(Hub, {})
317
+ ] });
318
+ }
319
+
320
+ // src/components/VerticalSpeed.tsx
321
+ var import_jsx_runtime6 = require("react/jsx-runtime");
322
+ var HALF_SWEEP = 170;
323
+ var formatThousands = (v) => {
324
+ const s = String(Math.abs(v) / 1e3);
325
+ return s.startsWith("0.") ? s.slice(1) : s;
326
+ };
327
+ function VerticalSpeed({ verticalSpeed = 0, max = 2e3, ...props }) {
328
+ const duration = props.animationDuration ?? DEFAULT_ANIMATION_MS;
329
+ const safeMax = Math.max(100, Math.abs(finite(max, 2e3)));
330
+ const vs = clamp(finite(verticalSpeed), -safeMax, safeMax);
331
+ const angle = (v) => -90 + v / safeMax * HALF_SWEEP;
332
+ const step = safeMax <= 2e3 ? 500 : 1e3;
333
+ const minor = step / 5;
334
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(InstrumentFrame, { ...props, label: `Vertical speed indicator: ${Math.round(vs)} feet per minute`, children: [
335
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("g", { stroke: "#fff", strokeLinecap: "round", children: range(-safeMax, safeMax, minor).map((v) => {
336
+ const major = Math.abs(v % step) < 1e-9;
337
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: tickPath(178, major ? 150 : 164, angle(v)), strokeWidth: major ? 4 : 2 }, v);
338
+ }) }),
339
+ range(-safeMax, safeMax, step).map((v) => {
340
+ const [x, y] = polar(124, angle(v));
341
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("text", { x, y, fill: "#fff", fontSize: "28", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: v === 0 ? "0" : formatThousands(v) }, v);
342
+ }),
343
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("text", { x: CENTER - 80, y: CENTER - 40, fill: "#ccc", fontSize: "18", textAnchor: "middle", children: "UP" }),
344
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("text", { x: CENTER - 80, y: CENTER + 50, fill: "#ccc", fontSize: "18", textAnchor: "middle", children: "DN" }),
345
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("text", { x: CENTER + 10, y: CENTER - 75, fill: "#ccc", fontSize: "13", textAnchor: "middle", children: "VERTICAL SPEED" }),
346
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("text", { x: CENTER + 10, y: CENTER + 82, fill: "#ccc", fontSize: "12", textAnchor: "middle", children: "1000 FT PER MIN" }),
347
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("g", { "data-testid": "vsi-needle", style: motionStyle(`rotate(${angle(vs)}deg)`, duration), children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("path", { d: `M ${CENTER - 5} ${CENTER + 30} L ${CENTER - 4} ${CENTER - 140} L ${CENTER} ${CENTER - 165} L ${CENTER + 4} ${CENTER - 140} L ${CENTER + 5} ${CENTER + 30} Z`, fill: "#fff" }) }),
348
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(Hub, {})
349
+ ] });
350
+ }
351
+
352
+ // src/components/TurnCoordinator.tsx
353
+ var import_jsx_runtime7 = require("react/jsx-runtime");
354
+ var STANDARD_RATE = 3;
355
+ var STANDARD_RATE_TILT = 20;
356
+ var MAX_TILT = 35;
357
+ var TUBE_CY = 40;
358
+ var TUBE_R = 240;
359
+ var TUBE_SPAN = 16;
360
+ var BALL_TRAVEL = 13;
361
+ function tubePoint(deg) {
362
+ const a = deg * Math.PI / 180;
363
+ return [CENTER + TUBE_R * Math.sin(a), TUBE_CY + TUBE_R * Math.cos(a)];
364
+ }
365
+ function TurnCoordinator({ turnRate = 0, slip = 0, ...props }) {
366
+ const duration = props.animationDuration ?? DEFAULT_ANIMATION_MS;
367
+ const rate = finite(turnRate);
368
+ const ball = clamp(finite(slip), -1, 1);
369
+ const tilt = clamp(rate / STANDARD_RATE * STANDARD_RATE_TILT, -MAX_TILT, MAX_TILT);
370
+ const [tx1, ty1] = tubePoint(-TUBE_SPAN);
371
+ const [tx2, ty2] = tubePoint(TUBE_SPAN);
372
+ const wireOffset = 3.6;
373
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(InstrumentFrame, { ...props, label: `Turn coordinator: ${rate.toFixed(1)}\xB0 per second, slip ${ball.toFixed(2)}`, children: [
374
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("g", { stroke: "#fff", strokeWidth: "6", strokeLinecap: "round", children: [-90 - STANDARD_RATE_TILT, -90, 90, 90 + STANDARD_RATE_TILT].map((a) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: tickPath(178, 150, a) }, a)) }),
375
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("text", { ...xy(polar(128, -90 - STANDARD_RATE_TILT - 8)), fill: "#fff", fontSize: "26", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: "L" }),
376
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("text", { ...xy(polar(128, 90 + STANDARD_RATE_TILT + 8)), fill: "#fff", fontSize: "26", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: "R" }),
377
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("text", { x: CENTER, y: CENTER - 92, fill: "#ccc", fontSize: "16", textAnchor: "middle", children: "TURN COORDINATOR" }),
378
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("text", { x: CENTER, y: CENTER + 130, fill: "#ccc", fontSize: "16", textAnchor: "middle", children: "2 MIN" }),
379
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("text", { x: CENTER, y: CENTER + 150, fill: "#999", fontSize: "10", textAnchor: "middle", children: "NO PITCH INFORMATION" }),
380
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
381
+ "path",
382
+ {
383
+ d: `M ${tx1} ${ty1} A ${TUBE_R} ${TUBE_R} 0 0 0 ${tx2} ${ty2}`,
384
+ fill: "none",
385
+ stroke: "#dcdcdc",
386
+ strokeWidth: "30",
387
+ strokeLinecap: "round"
388
+ }
389
+ ),
390
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("g", { stroke: "#111", strokeWidth: "3", children: [-wireOffset, wireOffset].map((d) => {
391
+ const [x1, y1] = tubePoint(d);
392
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: `M ${x1} ${y1 - 15} V ${y1 + 15}` }, d);
393
+ }) }),
394
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("g", { "data-testid": "turn-ball", style: motionStyle(`rotate(${-ball * BALL_TRAVEL}deg)`, duration, CENTER, TUBE_CY), children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("circle", { cx: CENTER, cy: TUBE_CY + TUBE_R, r: "13", fill: "#111" }) }),
395
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("g", { "data-testid": "turn-aircraft", style: motionStyle(`rotate(${tilt}deg)`, duration), children: [
396
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: `M ${CENTER - 140} ${CENTER} H ${CENTER + 140}`, stroke: "#fff", strokeWidth: "10", strokeLinecap: "round" }),
397
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: `M ${CENTER} ${CENTER} V ${CENTER - 40}`, stroke: "#fff", strokeWidth: "6", strokeLinecap: "round" }),
398
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("path", { d: `M ${CENTER - 30} ${CENTER - 8} H ${CENTER + 30}`, stroke: "#fff", strokeWidth: "6", strokeLinecap: "round" }),
399
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("circle", { cx: CENTER, cy: CENTER, r: "18", fill: "#fff" })
400
+ ] }),
401
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Hub, { r: 8 })
402
+ ] });
403
+ }
404
+ var xy = ([x, y]) => ({ x, y });
405
+ // Annotate the CommonJS export names for ESM import in node:
406
+ 0 && (module.exports = {
407
+ Airspeed,
408
+ Altimeter,
409
+ AttitudeIndicator,
410
+ HeadingIndicator,
411
+ TurnCoordinator,
412
+ VerticalSpeed
413
+ });
414
+ //# sourceMappingURL=index.cjs.map