flight-indicators 1.2.0 → 1.2.1
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/README.md +8 -0
- package/dist/index.cjs +92 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +98 -16
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -161,6 +161,7 @@ A VOR / course deviation indicator with an OBS card. The card turns so the selec
|
|
|
161
161
|
| `deviation` | `number` | | Course deviation in degrees, positive when the course is to the right. Clamped to ±10. Overrides `radial`. |
|
|
162
162
|
| `toFrom` | `"TO" \| "FROM" \| "OFF"` | | TO/FROM flag. Overrides `radial`. `"OFF"` hides both triangles. |
|
|
163
163
|
| `signal` | `boolean` | `true` | `false` shows the red NAV flag, centres the needle and hides TO/FROM. |
|
|
164
|
+
| `needle` | `"slide" \| "swing"` | `"slide"` | How the needle moves. `"slide"` moves a vertical bar sideways over a straight row of dots. `"swing"` hinges the needle just below the top index so it swings like a pendulum over a curved row of dots, as on older VOR heads, with a TO/FR window on the right. |
|
|
164
165
|
|
|
165
166
|
`vorDeviation(course, radial)` is exported too and returns `{ deviation, toFrom }` if you want the same maths without the drawing.
|
|
166
167
|
|
|
@@ -303,6 +304,13 @@ Each `DataField`:
|
|
|
303
304
|
| `decimals` | `number` | `0` | Decimal places for numeric values. |
|
|
304
305
|
| `color` | `string` | white | Colour of the value text, e.g. amber for a caution. |
|
|
305
306
|
|
|
307
|
+
## Examples
|
|
308
|
+
|
|
309
|
+
Examples live under [`examples/`](examples), one folder each:
|
|
310
|
+
|
|
311
|
+
- [`examples/instruments`](examples/instruments): the gallery behind the live demo, with every instrument on simulated flight data and sliders to drive each one by hand.
|
|
312
|
+
- [IFR trainer](https://github.com/fordnox/ifr-trainer) (separate repository): a radio navigation simulator built with this library.
|
|
313
|
+
|
|
306
314
|
## Development
|
|
307
315
|
|
|
308
316
|
```bash
|
package/dist/index.cjs
CHANGED
|
@@ -623,6 +623,11 @@ var AMBER2 = "#ffb000";
|
|
|
623
623
|
var FULL_SCALE_DEG = 10;
|
|
624
624
|
var DOT_SPACING = 22;
|
|
625
625
|
var FULL_SCALE_PX = DOT_SPACING * 5;
|
|
626
|
+
var PIVOT_Y = CENTER - 100;
|
|
627
|
+
var SWING_LENGTH = 165;
|
|
628
|
+
var SWING_DOT_RADIUS = 156;
|
|
629
|
+
var SWING_DEG_PER_DOT = 7.5;
|
|
630
|
+
var SWING_FULL_SCALE_DEG = SWING_DEG_PER_DOT * 5;
|
|
626
631
|
var norm2 = (deg) => (deg % 360 + 360) % 360;
|
|
627
632
|
var signedDiff = (a, b) => ((a - b) % 360 + 540) % 360 - 180;
|
|
628
633
|
function vorDeviation(course, radial) {
|
|
@@ -648,7 +653,7 @@ function Flag({ y, up, visible, testId }) {
|
|
|
648
653
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("text", { x: CENTER + 22, y, fill: "#fff", fontSize: "15", fontWeight: "bold", dominantBaseline: "central", children: up ? "TO" : "FROM" })
|
|
649
654
|
] });
|
|
650
655
|
}
|
|
651
|
-
function VorIndicator({ course = 0, radial, deviation, toFrom, signal = true, ...props }) {
|
|
656
|
+
function VorIndicator({ course = 0, radial, deviation, toFrom, signal = true, needle = "slide", ...props }) {
|
|
652
657
|
const duration = props.animationDuration ?? DEFAULT_ANIMATION_MS;
|
|
653
658
|
const crs = finite(course);
|
|
654
659
|
const computed = typeof radial === "number" && Number.isFinite(radial) ? vorDeviation(crs, radial) : void 0;
|
|
@@ -657,7 +662,9 @@ function VorIndicator({ course = 0, radial, deviation, toFrom, signal = true, ..
|
|
|
657
662
|
const flag = !signal ? "OFF" : toFrom ?? computed?.toFrom ?? "OFF";
|
|
658
663
|
const displayCourse = useContinuousAngle(crs);
|
|
659
664
|
const courseText = String(Math.round(norm2(crs)) || 360).padStart(3, "0");
|
|
665
|
+
const swing = needle === "swing";
|
|
660
666
|
const needleX = dev / FULL_SCALE_DEG * FULL_SCALE_PX;
|
|
667
|
+
const needleAngle = -(dev / FULL_SCALE_DEG) * SWING_FULL_SCALE_DEG;
|
|
661
668
|
const devText = Math.abs(dev) < 0.05 ? "centred" : `${Math.abs(dev).toFixed(1)}\xB0 ${dev > 0 ? "right" : "left"}`;
|
|
662
669
|
const label2 = signal ? `VOR indicator: course ${courseText}\xB0, needle ${devText}, ${flag === "OFF" ? "no TO/FROM indication" : flag}` : `VOR indicator: course ${courseText}\xB0, no signal`;
|
|
663
670
|
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(InstrumentFrame, { ...props, label: label2, children: [
|
|
@@ -685,11 +692,77 @@ function VorIndicator({ course = 0, radial, deviation, toFrom, signal = true, ..
|
|
|
685
692
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { d: `M ${CENTER} ${CENTER - 150} l -10 -28 h 20 z`, fill: AMBER2, stroke: "#000", strokeWidth: "1.5" }),
|
|
686
693
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { d: `M ${CENTER} ${CENTER + 150} l -8 24 h 16 z`, fill: "#fff", stroke: "#000", strokeWidth: "1.5" }),
|
|
687
694
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("g", { stroke: AMBER2, strokeWidth: "4", strokeLinecap: "round", children: [45, 90, 135, 225, 270, 315].map((a) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { d: tickPath(192, 178, a) }, a)) }),
|
|
688
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
695
|
+
swing ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
696
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("g", { fill: "#fff", stroke: "#000", strokeWidth: "1", children: range(1, 5, 1).flatMap((i) => [-i, i]).map((i) => {
|
|
697
|
+
const [x, y] = polar(SWING_DOT_RADIUS, 180 - i * SWING_DEG_PER_DOT, CENTER, PIVOT_Y);
|
|
698
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("circle", { cx: x, cy: y, r: "5" }, i);
|
|
699
|
+
}) }),
|
|
700
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
701
|
+
"rect",
|
|
702
|
+
{
|
|
703
|
+
x: CENTER - 6,
|
|
704
|
+
y: PIVOT_Y + SWING_DOT_RADIUS - 10,
|
|
705
|
+
width: "12",
|
|
706
|
+
height: "20",
|
|
707
|
+
rx: "2",
|
|
708
|
+
fill: "none",
|
|
709
|
+
stroke: "#fff",
|
|
710
|
+
strokeWidth: "2.5"
|
|
711
|
+
}
|
|
712
|
+
),
|
|
713
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("rect", { x: CENTER + 46, y: CENTER - 72, width: "46", height: "76", rx: "5", fill: "#000", stroke: "#555", strokeWidth: "2" }),
|
|
714
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("g", { fill: "#ccc", fontSize: "14", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: [
|
|
715
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("text", { x: CENTER + 69, y: CENTER - 59, children: "TO" }),
|
|
716
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("text", { x: CENTER + 69, y: CENTER - 9, children: "FR" })
|
|
717
|
+
] }),
|
|
718
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("g", { stroke: "#000", strokeWidth: "1.5", strokeLinejoin: "round", fill: "#fff", children: [
|
|
719
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
720
|
+
"path",
|
|
721
|
+
{
|
|
722
|
+
"data-testid": "vor-to",
|
|
723
|
+
d: `M ${CENTER + 69} ${CENTER - 44} l 11 18 h -22 z`,
|
|
724
|
+
opacity: flag === "TO" ? 1 : 0,
|
|
725
|
+
style: { transition: "opacity 200ms ease-out" }
|
|
726
|
+
}
|
|
727
|
+
),
|
|
728
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
729
|
+
"path",
|
|
730
|
+
{
|
|
731
|
+
"data-testid": "vor-from",
|
|
732
|
+
d: `M ${CENTER + 69} ${CENTER - 22} l 11 -18 h -22 z`,
|
|
733
|
+
opacity: flag === "FROM" ? 1 : 0,
|
|
734
|
+
style: { transition: "opacity 200ms ease-out" }
|
|
735
|
+
}
|
|
736
|
+
)
|
|
737
|
+
] }),
|
|
738
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("g", { "data-testid": "vor-needle", style: motionStyle(`rotate(${needleAngle}deg)`, duration, CENTER, PIVOT_Y), children: [
|
|
739
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
740
|
+
"path",
|
|
741
|
+
{
|
|
742
|
+
d: `M ${CENTER} ${PIVOT_Y} V ${PIVOT_Y + SWING_LENGTH}`,
|
|
743
|
+
stroke: "#000",
|
|
744
|
+
strokeWidth: "7",
|
|
745
|
+
strokeLinecap: "round"
|
|
746
|
+
}
|
|
747
|
+
),
|
|
748
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
749
|
+
"path",
|
|
750
|
+
{
|
|
751
|
+
d: `M ${CENTER} ${PIVOT_Y} V ${PIVOT_Y + SWING_LENGTH}`,
|
|
752
|
+
stroke: "#fff",
|
|
753
|
+
strokeWidth: "4",
|
|
754
|
+
strokeLinecap: "round"
|
|
755
|
+
}
|
|
756
|
+
)
|
|
757
|
+
] }),
|
|
758
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("circle", { cx: CENTER, cy: PIVOT_Y, r: "6", fill: "#333", stroke: "#fff", strokeWidth: "2" })
|
|
759
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
|
|
760
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("g", { fill: "#fff", stroke: "#000", strokeWidth: "1", children: range(1, 5, 1).flatMap((i) => [-i, i]).map((i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("circle", { cx: CENTER + i * DOT_SPACING, cy: CENTER, r: "5" }, i)) }),
|
|
761
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("circle", { cx: CENTER, cy: CENTER, r: "9", fill: "none", stroke: "#fff", strokeWidth: "2.5" }),
|
|
762
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Flag, { y: CENTER - 54, up: true, visible: flag === "TO", testId: "vor-to" }),
|
|
763
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Flag, { y: CENTER + 54, up: false, visible: flag === "FROM", testId: "vor-from" }),
|
|
764
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("g", { "data-testid": "vor-needle", style: motionStyle(`translate(${needleX}px, 0px)`, duration), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("rect", { x: CENTER - 3, y: CENTER - 68, width: "6", height: "136", rx: "3", fill: "#fff", stroke: "#000", strokeWidth: "1.5" }) })
|
|
765
|
+
] }),
|
|
693
766
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("rect", { x: CENTER - 44, y: CENTER + 72, width: "88", height: "26", rx: "4", fill: "#000", stroke: "#555", strokeWidth: "2" }),
|
|
694
767
|
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
695
768
|
"text",
|
|
@@ -709,10 +782,19 @@ function VorIndicator({ course = 0, radial, deviation, toFrom, signal = true, ..
|
|
|
709
782
|
]
|
|
710
783
|
}
|
|
711
784
|
),
|
|
712
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
785
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
786
|
+
"g",
|
|
787
|
+
{
|
|
788
|
+
"data-testid": "vor-nav-flag",
|
|
789
|
+
opacity: signal ? 0 : 1,
|
|
790
|
+
style: { transition: "opacity 200ms ease-out" },
|
|
791
|
+
transform: swing ? "translate(-64 52)" : void 0,
|
|
792
|
+
children: [
|
|
793
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("rect", { x: CENTER - 28, y: CENTER - 98, width: "56", height: "24", rx: "3", fill: "#d42626", stroke: "#000", strokeWidth: "1.5" }),
|
|
794
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("text", { x: CENTER, y: CENTER - 85, fill: "#fff", fontSize: "15", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: "NAV" })
|
|
795
|
+
]
|
|
796
|
+
}
|
|
797
|
+
)
|
|
716
798
|
] });
|
|
717
799
|
}
|
|
718
800
|
|