flight-indicators 1.0.1 → 1.1.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/dist/index.js CHANGED
@@ -372,12 +372,862 @@ function TurnCoordinator({ turnRate = 0, slip = 0, ...props }) {
372
372
  ] });
373
373
  }
374
374
  var xy = ([x, y]) => ({ x, y });
375
+
376
+ // src/components/WindIndicator.tsx
377
+ import { jsx as jsx8, jsxs as jsxs8 } from "react/jsx-runtime";
378
+ var CARDINALS2 = { 0: "N", 90: "E", 180: "S", 270: "W" };
379
+ var MIRROR = { L: "R", C: "C", R: "L" };
380
+ var WIND = "#3cc8ff";
381
+ var AMBER = "#ffb000";
382
+ var GREEN = "#3ddc84";
383
+ var norm = (deg) => (deg % 360 + 360) % 360;
384
+ function designator(heading) {
385
+ const n = Math.round(norm(heading) / 10) % 36;
386
+ return String(n === 0 ? 36 : n).padStart(2, "0");
387
+ }
388
+ var HALF_LEN = 96;
389
+ var HALF_W = 17;
390
+ var TOP = CENTER - HALF_LEN;
391
+ var BOTTOM = CENTER + HALF_LEN;
392
+ var LEFT = CENTER - HALF_W;
393
+ var RIGHT = CENTER + HALF_W;
394
+ function Threshold({ number, side, active }) {
395
+ return /* @__PURE__ */ jsxs8("g", { children: [
396
+ [-13, -8, -3, 3, 8, 13].map((dx) => /* @__PURE__ */ jsx8("rect", { x: CENTER + dx - 1.5, y: BOTTOM - 16, width: "3", height: "12", fill: "#e8e8e8" }, dx)),
397
+ /* @__PURE__ */ jsx8(
398
+ "text",
399
+ {
400
+ x: CENTER,
401
+ y: BOTTOM - 30,
402
+ fill: active ? "#fff" : "#8a8a8a",
403
+ fontSize: "18",
404
+ fontWeight: "bold",
405
+ textAnchor: "middle",
406
+ dominantBaseline: "central",
407
+ children: number
408
+ }
409
+ ),
410
+ side && /* @__PURE__ */ jsx8(
411
+ "text",
412
+ {
413
+ x: CENTER,
414
+ y: BOTTOM - 48,
415
+ fill: active ? "#fff" : "#8a8a8a",
416
+ fontSize: "16",
417
+ fontWeight: "bold",
418
+ textAnchor: "middle",
419
+ dominantBaseline: "central",
420
+ children: side
421
+ }
422
+ ),
423
+ /* @__PURE__ */ jsx8(
424
+ "g",
425
+ {
426
+ fill: "none",
427
+ stroke: GREEN,
428
+ strokeWidth: "3.5",
429
+ strokeLinecap: "round",
430
+ strokeLinejoin: "round",
431
+ opacity: active ? 1 : 0,
432
+ style: { transition: "opacity 300ms ease-out" },
433
+ children: [0, 1, 2].map((i) => /* @__PURE__ */ jsx8(
434
+ "path",
435
+ {
436
+ d: `M ${CENTER - 10} ${BOTTOM + 14 + i * 11} L ${CENTER} ${BOTTOM + 6 + i * 11} L ${CENTER + 10} ${BOTTOM + 14 + i * 11}`,
437
+ opacity: 1 - i * 0.3
438
+ },
439
+ i
440
+ ))
441
+ }
442
+ )
443
+ ] });
444
+ }
445
+ function Readout({
446
+ dx,
447
+ dy,
448
+ duration,
449
+ testId,
450
+ children
451
+ }) {
452
+ return /* @__PURE__ */ jsxs8("g", { style: motionStyle(`translate(${dx}px, ${dy}px)`, duration), children: [
453
+ /* @__PURE__ */ jsx8("rect", { x: CENTER - 56, y: CENTER - 13, width: "112", height: "26", rx: "4", fill: "#000", stroke: "#555", strokeWidth: "2" }),
454
+ /* @__PURE__ */ jsx8(
455
+ "text",
456
+ {
457
+ "data-testid": testId,
458
+ x: CENTER,
459
+ y: CENTER + 1,
460
+ fontSize: "15",
461
+ fontFamily: "monospace",
462
+ fontWeight: "bold",
463
+ textAnchor: "middle",
464
+ dominantBaseline: "central",
465
+ children
466
+ }
467
+ )
468
+ ] });
469
+ }
470
+ function WindIndicator({
471
+ runway = 0,
472
+ runwaySide,
473
+ windDirection = 0,
474
+ windSpeed = 0,
475
+ windGust,
476
+ crosswindLimit = 15,
477
+ ...props
478
+ }) {
479
+ const duration = props.animationDuration ?? DEFAULT_ANIMATION_MS;
480
+ const rwy = finite(runway);
481
+ const dir = finite(windDirection);
482
+ const speed = Math.max(0, finite(windSpeed));
483
+ const gust = Math.max(0, finite(windGust));
484
+ const calm = speed < 1;
485
+ const hasGust = !calm && Math.round(gust) > Math.round(speed);
486
+ const headOnGiven = speed * Math.cos((dir - rwy) * Math.PI / 180);
487
+ const reversed = !calm && headOnGiven < -1e-9;
488
+ const landing = reversed ? rwy + 180 : rwy;
489
+ const rel = (dir - landing) * Math.PI / 180;
490
+ const headwind = Math.round(speed * Math.cos(rel));
491
+ const crosswind = Math.round(speed * Math.sin(rel));
492
+ const peakCrosswind = Math.abs((hasGust ? gust : speed) * Math.sin(rel));
493
+ const overLimit = peakCrosswind > crosswindLimit;
494
+ const baseNumber = designator(rwy);
495
+ const oppositeNumber = designator(rwy + 180);
496
+ const activeNumber = reversed ? oppositeNumber : baseNumber;
497
+ const activeSide = runwaySide && (reversed ? MIRROR[runwaySide] : runwaySide);
498
+ const displayRunway = useContinuousAngle(rwy);
499
+ const displayWind = useContinuousAngle(dir);
500
+ const perpendicular = norm(rwy) % 180 - 90;
501
+ const [wx, wy] = polar(78, perpendicular);
502
+ const [cx, cy] = polar(78, perpendicular + 180);
503
+ const dirText = String(Math.round(norm(dir)) || 360).padStart(3, "0");
504
+ const windText = calm ? "CALM" : `${dirText}\xB0 ${Math.round(speed)}${hasGust ? `G${Math.round(gust)}` : ""}KT`;
505
+ const crossText = crosswind === 0 ? "0" : `${Math.abs(crosswind)}${crosswind > 0 ? "R" : "L"}`;
506
+ const label = `Wind: ${calm ? "calm" : `${dirText}\xB0 at ${Math.round(speed)}${hasGust ? ` gusting ${Math.round(gust)}` : ""} knots`}, runway ${activeNumber}${activeSide ?? ""} in use, ${headwind < 0 ? "tailwind" : "headwind"} ${Math.abs(headwind)}, crosswind ${Math.abs(crosswind)}${crosswind === 0 ? "" : crosswind > 0 ? " from the right" : " from the left"}`;
507
+ return /* @__PURE__ */ jsxs8(InstrumentFrame, { ...props, label, children: [
508
+ /* @__PURE__ */ jsx8("g", { stroke: "#fff", strokeLinecap: "round", children: range(0, 350, 10).map((a) => /* @__PURE__ */ jsx8("path", { d: tickPath(176, a % 30 === 0 ? 162 : 168, a), strokeWidth: a % 30 === 0 ? 3 : 2, opacity: a % 30 === 0 ? 1 : 0.7 }, a)) }),
509
+ range(0, 330, 30).map((a) => {
510
+ const [x, y] = polar(146, a);
511
+ return /* @__PURE__ */ jsx8(
512
+ "text",
513
+ {
514
+ x,
515
+ y,
516
+ transform: `rotate(${a} ${x} ${y})`,
517
+ fill: a % 90 === 0 ? AMBER : "#fff",
518
+ fontSize: a % 90 === 0 ? 22 : 18,
519
+ fontWeight: "bold",
520
+ textAnchor: "middle",
521
+ dominantBaseline: "central",
522
+ children: CARDINALS2[a] ?? String(a / 10)
523
+ },
524
+ a
525
+ );
526
+ }),
527
+ /* @__PURE__ */ jsx8("g", { style: { ...motionStyle(`rotate(${displayWind}deg)`, duration), opacity: calm ? 0 : 1 }, children: /* @__PURE__ */ jsx8(
528
+ "path",
529
+ {
530
+ d: `M ${CENTER} ${CENTER - 132} V ${CENTER + 120}`,
531
+ stroke: WIND,
532
+ strokeWidth: "2",
533
+ strokeDasharray: "2 8",
534
+ strokeLinecap: "round",
535
+ opacity: "0.45"
536
+ }
537
+ ) }),
538
+ /* @__PURE__ */ jsxs8("g", { "data-testid": "wind-runway", style: motionStyle(`rotate(${displayRunway}deg)`, duration), children: [
539
+ /* @__PURE__ */ jsx8("rect", { x: LEFT - 2, y: TOP - 2, width: HALF_W * 2 + 4, height: HALF_LEN * 2 + 4, rx: "3", fill: "#000", opacity: "0.5" }),
540
+ /* @__PURE__ */ jsx8("rect", { x: LEFT, y: TOP, width: HALF_W * 2, height: HALF_LEN * 2, rx: "2", fill: "#34373c", stroke: "#5c6066", strokeWidth: "1" }),
541
+ /* @__PURE__ */ jsx8("g", { stroke: "#e8e8e8", strokeWidth: "1.2", children: /* @__PURE__ */ jsx8("path", { d: `M ${LEFT + 2.5} ${TOP + 2} V ${BOTTOM - 2} M ${RIGHT - 2.5} ${TOP + 2} V ${BOTTOM - 2}` }) }),
542
+ /* @__PURE__ */ jsx8("g", { fill: "#e8e8e8", children: range(TOP + 62, BOTTOM - 70, 16).map((y) => /* @__PURE__ */ jsx8("rect", { x: CENTER - 1, y, width: "2", height: "9" }, y)) }),
543
+ /* @__PURE__ */ jsx8(Threshold, { number: baseNumber, side: runwaySide, active: !reversed }),
544
+ /* @__PURE__ */ jsx8("g", { transform: `rotate(180 ${CENTER} ${CENTER})`, children: /* @__PURE__ */ jsx8(Threshold, { number: oppositeNumber, side: runwaySide && MIRROR[runwaySide], active: reversed }) })
545
+ ] }),
546
+ /* @__PURE__ */ jsx8(Readout, { dx: wx - CENTER, dy: wy - CENTER, duration, testId: "wind-readout", children: /* @__PURE__ */ jsx8("tspan", { fill: WIND, children: windText }) }),
547
+ /* @__PURE__ */ jsxs8(Readout, { dx: cx - CENTER, dy: cy - CENTER, duration, testId: "wind-components", children: [
548
+ /* @__PURE__ */ jsx8("tspan", { fill: headwind < 0 ? AMBER : "#fff", children: `${headwind < 0 ? "TW" : "HW"} ${Math.abs(headwind)}` }),
549
+ /* @__PURE__ */ jsx8("tspan", { dx: "14", fill: overLimit ? AMBER : "#fff", children: `XW ${crossText}` })
550
+ ] }),
551
+ /* @__PURE__ */ jsx8("g", { "data-testid": "wind-arrow", style: { ...motionStyle(`rotate(${displayWind}deg)`, duration), opacity: calm ? 0 : 1 }, children: /* @__PURE__ */ jsx8(
552
+ "path",
553
+ {
554
+ d: `M ${CENTER} ${CENTER - 134} L ${CENTER - 20} ${CENTER - 168} L ${CENTER - 6} ${CENTER - 162} L ${CENTER - 6} ${CENTER - 192} L ${CENTER + 6} ${CENTER - 192} L ${CENTER + 6} ${CENTER - 162} L ${CENTER + 20} ${CENTER - 168} Z`,
555
+ fill: WIND,
556
+ stroke: "#00121a",
557
+ strokeWidth: "3",
558
+ strokeLinejoin: "round"
559
+ }
560
+ ) })
561
+ ] });
562
+ }
563
+
564
+ // src/components/VorIndicator.tsx
565
+ import { jsx as jsx9, jsxs as jsxs9 } from "react/jsx-runtime";
566
+ var CARDINALS3 = { 0: "N", 90: "E", 180: "S", 270: "W" };
567
+ var AMBER2 = "#ffb000";
568
+ var FULL_SCALE_DEG = 10;
569
+ var DOT_SPACING = 22;
570
+ var FULL_SCALE_PX = DOT_SPACING * 5;
571
+ var norm2 = (deg) => (deg % 360 + 360) % 360;
572
+ var signedDiff = (a, b) => ((a - b) % 360 + 540) % 360 - 180;
573
+ function vorDeviation(course, radial) {
574
+ const d = signedDiff(radial, course);
575
+ return Math.abs(d) <= 90 ? { deviation: -d, toFrom: "FROM" } : { deviation: signedDiff(d, 180), toFrom: "TO" };
576
+ }
577
+ function Flag({ y, up, visible, testId }) {
578
+ const dir = up ? -1 : 1;
579
+ const tip = y + dir * 17;
580
+ const headBase = y + dir * 1;
581
+ const tail = y - dir * 15;
582
+ return /* @__PURE__ */ jsxs9("g", { "data-testid": testId, opacity: visible ? 1 : 0, style: { transition: "opacity 200ms ease-out" }, children: [
583
+ /* @__PURE__ */ jsx9(
584
+ "path",
585
+ {
586
+ d: `M ${CENTER} ${tip} L ${CENTER - 13} ${headBase} H ${CENTER - 4} V ${tail} H ${CENTER + 4} V ${headBase} H ${CENTER + 13} Z`,
587
+ fill: "#fff",
588
+ stroke: "#000",
589
+ strokeWidth: "1.5",
590
+ strokeLinejoin: "round"
591
+ }
592
+ ),
593
+ /* @__PURE__ */ jsx9("text", { x: CENTER + 22, y, fill: "#fff", fontSize: "15", fontWeight: "bold", dominantBaseline: "central", children: up ? "TO" : "FROM" })
594
+ ] });
595
+ }
596
+ function VorIndicator({ course = 0, radial, deviation, toFrom, signal = true, ...props }) {
597
+ const duration = props.animationDuration ?? DEFAULT_ANIMATION_MS;
598
+ const crs = finite(course);
599
+ const computed = typeof radial === "number" && Number.isFinite(radial) ? vorDeviation(crs, radial) : void 0;
600
+ const rawDeviation = finite(deviation, computed?.deviation ?? 0);
601
+ const dev = signal ? clamp(rawDeviation, -FULL_SCALE_DEG, FULL_SCALE_DEG) : 0;
602
+ const flag = !signal ? "OFF" : toFrom ?? computed?.toFrom ?? "OFF";
603
+ const displayCourse = useContinuousAngle(crs);
604
+ const courseText = String(Math.round(norm2(crs)) || 360).padStart(3, "0");
605
+ const needleX = dev / FULL_SCALE_DEG * FULL_SCALE_PX;
606
+ const devText = Math.abs(dev) < 0.05 ? "centred" : `${Math.abs(dev).toFixed(1)}\xB0 ${dev > 0 ? "right" : "left"}`;
607
+ const label = signal ? `VOR indicator: course ${courseText}\xB0, needle ${devText}, ${flag === "OFF" ? "no TO/FROM indication" : flag}` : `VOR indicator: course ${courseText}\xB0, no signal`;
608
+ return /* @__PURE__ */ jsxs9(InstrumentFrame, { ...props, label, children: [
609
+ /* @__PURE__ */ jsxs9("g", { "data-testid": "vor-card", style: motionStyle(`rotate(${-displayCourse}deg)`, duration), children: [
610
+ /* @__PURE__ */ jsx9("g", { stroke: "#fff", strokeLinecap: "round", children: range(0, 355, 5).map((a) => /* @__PURE__ */ jsx9("path", { d: tickPath(176, a % 10 === 0 ? 152 : 164, a), strokeWidth: a % 10 === 0 ? 3 : 2 }, a)) }),
611
+ range(0, 330, 30).map((a) => {
612
+ const [x, y] = polar(132, a);
613
+ return /* @__PURE__ */ jsx9(
614
+ "text",
615
+ {
616
+ x,
617
+ y,
618
+ transform: `rotate(${a} ${x} ${y})`,
619
+ fill: a % 90 === 0 ? AMBER2 : "#fff",
620
+ fontSize: a % 90 === 0 ? 28 : 24,
621
+ fontWeight: "bold",
622
+ textAnchor: "middle",
623
+ dominantBaseline: "central",
624
+ children: CARDINALS3[a] ?? String(a / 10)
625
+ },
626
+ a
627
+ );
628
+ })
629
+ ] }),
630
+ /* @__PURE__ */ jsx9("path", { d: `M ${CENTER} ${CENTER - 150} l -10 -28 h 20 z`, fill: AMBER2, stroke: "#000", strokeWidth: "1.5" }),
631
+ /* @__PURE__ */ jsx9("path", { d: `M ${CENTER} ${CENTER + 150} l -8 24 h 16 z`, fill: "#fff", stroke: "#000", strokeWidth: "1.5" }),
632
+ /* @__PURE__ */ jsx9("g", { stroke: AMBER2, strokeWidth: "4", strokeLinecap: "round", children: [45, 90, 135, 225, 270, 315].map((a) => /* @__PURE__ */ jsx9("path", { d: tickPath(192, 178, a) }, a)) }),
633
+ /* @__PURE__ */ jsx9("g", { fill: "#fff", stroke: "#000", strokeWidth: "1", children: range(1, 5, 1).flatMap((i) => [-i, i]).map((i) => /* @__PURE__ */ jsx9("circle", { cx: CENTER + i * DOT_SPACING, cy: CENTER, r: "5" }, i)) }),
634
+ /* @__PURE__ */ jsx9("circle", { cx: CENTER, cy: CENTER, r: "9", fill: "none", stroke: "#fff", strokeWidth: "2.5" }),
635
+ /* @__PURE__ */ jsx9(Flag, { y: CENTER - 54, up: true, visible: flag === "TO", testId: "vor-to" }),
636
+ /* @__PURE__ */ jsx9(Flag, { y: CENTER + 54, up: false, visible: flag === "FROM", testId: "vor-from" }),
637
+ /* @__PURE__ */ jsx9("g", { "data-testid": "vor-needle", style: motionStyle(`translate(${needleX}px, 0px)`, duration), children: /* @__PURE__ */ jsx9("rect", { x: CENTER - 3, y: CENTER - 68, width: "6", height: "136", rx: "3", fill: "#fff", stroke: "#000", strokeWidth: "1.5" }) }),
638
+ /* @__PURE__ */ jsx9("rect", { x: CENTER - 44, y: CENTER + 72, width: "88", height: "26", rx: "4", fill: "#000", stroke: "#555", strokeWidth: "2" }),
639
+ /* @__PURE__ */ jsxs9(
640
+ "text",
641
+ {
642
+ "data-testid": "vor-course",
643
+ x: CENTER,
644
+ y: CENTER + 86,
645
+ fill: "#fff",
646
+ fontSize: "17",
647
+ fontFamily: "monospace",
648
+ fontWeight: "bold",
649
+ textAnchor: "middle",
650
+ dominantBaseline: "central",
651
+ children: [
652
+ /* @__PURE__ */ jsx9("tspan", { fill: "#ccc", children: "CRS " }),
653
+ courseText
654
+ ]
655
+ }
656
+ ),
657
+ /* @__PURE__ */ jsxs9("g", { "data-testid": "vor-nav-flag", opacity: signal ? 0 : 1, style: { transition: "opacity 200ms ease-out" }, children: [
658
+ /* @__PURE__ */ jsx9("rect", { x: CENTER - 28, y: CENTER - 98, width: "56", height: "24", rx: "3", fill: "#d42626", stroke: "#000", strokeWidth: "1.5" }),
659
+ /* @__PURE__ */ jsx9("text", { x: CENTER, y: CENTER - 85, fill: "#fff", fontSize: "15", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: "NAV" })
660
+ ] })
661
+ ] });
662
+ }
663
+
664
+ // src/components/DataPanel.tsx
665
+ import { jsx as jsx10, jsxs as jsxs10 } from "react/jsx-runtime";
666
+ var MAX_FIELDS = 6;
667
+ var SIDE = 252;
668
+ var PAD = 8;
669
+ var GAP = 8;
670
+ var ORIGIN = CENTER - SIDE / 2;
671
+ var VALUE_SIZE = { 1: 52, 2: 36, 3: 27 };
672
+ function formatValue(field) {
673
+ if (typeof field.value === "string") return field.value;
674
+ const n = finite(field.value, NaN);
675
+ return Number.isNaN(n) ? "---" : n.toFixed(Math.max(0, Math.floor(finite(field.decimals, 0))));
676
+ }
677
+ function DataPanel({ fields = [], heading, ...props }) {
678
+ const shown = fields.slice(0, MAX_FIELDS);
679
+ const cols = shown.length <= 2 ? 1 : 2;
680
+ const rows = Math.max(1, Math.ceil(shown.length / cols));
681
+ const cellW = (SIDE - PAD * 2 - GAP * (cols - 1)) / cols;
682
+ const cellH = (SIDE - PAD * 2 - GAP * (rows - 1)) / rows;
683
+ const valueSize = VALUE_SIZE[rows] ?? 27;
684
+ const label = `${heading ?? "Data panel"}: ` + (shown.length ? shown.map((f) => `${f.name} ${formatValue(f)}${f.unit ? ` ${f.unit}` : ""}`).join(", ") : "no data");
685
+ return /* @__PURE__ */ jsxs10(InstrumentFrame, { ...props, label, children: [
686
+ heading && /* @__PURE__ */ jsx10("text", { x: CENTER, y: ORIGIN - 14, fill: "#ccc", fontSize: "13", fontWeight: "bold", letterSpacing: "2", textAnchor: "middle", dominantBaseline: "central", children: heading.toUpperCase() }),
687
+ /* @__PURE__ */ jsx10("rect", { x: ORIGIN, y: ORIGIN, width: SIDE, height: SIDE, rx: "10", fill: "#1c1f24", stroke: "#3a3f47", strokeWidth: "2" }),
688
+ shown.map((f, i) => {
689
+ const col = i % cols;
690
+ const row = Math.floor(i / cols);
691
+ const x = ORIGIN + PAD + col * (cellW + GAP);
692
+ const y = ORIGIN + PAD + row * (cellH + GAP);
693
+ const value = formatValue(f);
694
+ const fit = Math.min(valueSize, (cellW - 16) / (0.62 * Math.max(1, value.length)));
695
+ return /* @__PURE__ */ jsxs10("g", { "data-testid": `data-field-${i}`, children: [
696
+ /* @__PURE__ */ jsx10("rect", { x, y, width: cellW, height: cellH, rx: "6", fill: "#000", stroke: "#262a30", strokeWidth: "1" }),
697
+ /* @__PURE__ */ jsx10("text", { x: x + 8, y: y + 12, fill: "#9aa4b1", fontSize: "12", fontWeight: "bold", letterSpacing: "1", dominantBaseline: "central", children: f.name.toUpperCase() }),
698
+ /* @__PURE__ */ jsx10(
699
+ "text",
700
+ {
701
+ "data-testid": `data-value-${i}`,
702
+ x: x + cellW / 2,
703
+ y: y + cellH / 2 + 7,
704
+ fill: f.color ?? "#fff",
705
+ fontSize: fit,
706
+ fontFamily: "monospace",
707
+ fontWeight: "bold",
708
+ textAnchor: "middle",
709
+ dominantBaseline: "central",
710
+ children: value
711
+ }
712
+ ),
713
+ f.unit && /* @__PURE__ */ jsx10("text", { x: x + cellW - 8, y: y + cellH - 12, fill: "#9aa4b1", fontSize: "12", textAnchor: "end", dominantBaseline: "central", children: f.unit })
714
+ ] }, i);
715
+ })
716
+ ] });
717
+ }
718
+
719
+ // src/components/FuelIndicator.tsx
720
+ import { jsx as jsx11, jsxs as jsxs11 } from "react/jsx-runtime";
721
+ var MAX_TANKS = 4;
722
+ var GREEN2 = "#2ee05a";
723
+ var RED = "#ff3b3b";
724
+ var GREY = "#9aa4b1";
725
+ var SIDE2 = 252;
726
+ var PAD2 = 6;
727
+ var ORIGIN2 = CENTER - SIDE2 / 2;
728
+ var INNER_LEFT = ORIGIN2 + PAD2;
729
+ var INNER_W = SIDE2 - PAD2 * 2;
730
+ var FOOTER_Y = ORIGIN2 + SIDE2 - 36;
731
+ var BAR_TOP = ORIGIN2 + 38;
732
+ var BAR_H = 114;
733
+ var BAR_BOTTOM = BAR_TOP + BAR_H;
734
+ var DEFAULT_TANKS = [
735
+ { name: "LEFT", quantity: 0 },
736
+ { name: "RIGHT", quantity: 0 }
737
+ ];
738
+ function FuelIndicator({
739
+ tanks = DEFAULT_TANKS,
740
+ capacity = 50,
741
+ unit = "gal",
742
+ low,
743
+ decimals = 1,
744
+ label = "FUEL",
745
+ ...props
746
+ }) {
747
+ const duration = props.animationDuration ?? DEFAULT_ANIMATION_MS;
748
+ const places = Math.max(0, Math.floor(finite(decimals, 1)));
749
+ const shown = tanks.slice(0, MAX_TANKS);
750
+ const cols = Math.max(1, shown.length);
751
+ const colW = INNER_W / cols;
752
+ const barW = clamp(colW / 8, 8, 16);
753
+ const valueSize = Math.min(26, colW / 4.4);
754
+ const readings = shown.map((t) => {
755
+ const cap = Math.max(1e-9, finite(t.capacity, finite(capacity, 50)));
756
+ const qty = clamp(finite(t.quantity), 0, cap);
757
+ const fraction = qty / cap;
758
+ const full = fraction >= 0.995;
759
+ const isLow = qty <= finite(low, cap * 0.1);
760
+ return { name: t.name, qty, cap, fraction, full, isLow, text: full ? "FULL" : qty.toFixed(places) };
761
+ });
762
+ const title = `${label}: ` + (readings.length ? readings.map((r) => `${r.name} ${r.full ? "full" : `${r.text} of ${r.cap.toFixed(places)} ${unit}`}${r.isLow ? " (low)" : ""}`).join(", ") : "no tanks");
763
+ return /* @__PURE__ */ jsxs11(InstrumentFrame, { ...props, label: title, children: [
764
+ /* @__PURE__ */ jsx11("rect", { x: ORIGIN2, y: ORIGIN2, width: SIDE2, height: SIDE2, rx: "10", fill: "#000", stroke: "#3a3f47", strokeWidth: "2" }),
765
+ readings.map((r, i) => {
766
+ const cx = INNER_LEFT + colW * (i + 0.5);
767
+ const color = r.isLow ? RED : GREEN2;
768
+ const tickX = cx - barW / 2 - 14;
769
+ return /* @__PURE__ */ jsxs11("g", { "data-testid": `fuel-tank-${i}`, children: [
770
+ i > 0 && /* @__PURE__ */ jsx11("path", { d: `M ${INNER_LEFT + colW * i} ${ORIGIN2 + 10} V ${FOOTER_Y}`, stroke: "#555", strokeWidth: "1.5" }),
771
+ /* @__PURE__ */ jsx11("text", { x: cx, y: ORIGIN2 + 22, fill: "#fff", fontSize: Math.min(17, colW / 5), fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: r.name.toUpperCase() }),
772
+ /* @__PURE__ */ jsx11("g", { strokeWidth: "2.5", strokeLinecap: "round", children: [0, 0.25, 0.5, 0.75, 1].map((f) => /* @__PURE__ */ jsx11(
773
+ "path",
774
+ {
775
+ d: `M ${tickX - 7} ${BAR_BOTTOM - f * BAR_H} h 7`,
776
+ stroke: f === 1 ? GREEN2 : f === 0 ? RED : GREY
777
+ },
778
+ f
779
+ )) }),
780
+ /* @__PURE__ */ jsx11("rect", { x: cx - barW / 2, y: BAR_TOP, width: barW, height: BAR_H, fill: "#15181c" }),
781
+ /* @__PURE__ */ jsx11("g", { "data-testid": `fuel-bar-${i}`, style: motionStyle(`scaleY(${r.fraction})`, duration, cx, BAR_BOTTOM), children: /* @__PURE__ */ jsx11("rect", { x: cx - barW / 2, y: BAR_TOP, width: barW, height: BAR_H, fill: color }) }),
782
+ /* @__PURE__ */ jsx11(
783
+ "text",
784
+ {
785
+ "data-testid": `fuel-value-${i}`,
786
+ x: cx,
787
+ y: BAR_BOTTOM + 22,
788
+ fill: r.isLow ? RED : "#fff",
789
+ fontSize: valueSize,
790
+ fontFamily: "monospace",
791
+ fontWeight: "bold",
792
+ textAnchor: "middle",
793
+ dominantBaseline: "central",
794
+ children: r.text
795
+ }
796
+ ),
797
+ /* @__PURE__ */ jsx11("text", { x: cx, y: BAR_BOTTOM + 44, fill: "#fff", fontSize: "13", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: unit })
798
+ ] }, i);
799
+ }),
800
+ /* @__PURE__ */ jsx11("path", { d: `M ${ORIGIN2 + 8} ${FOOTER_Y} H ${ORIGIN2 + SIDE2 - 8}`, stroke: "#555", strokeWidth: "1.5" }),
801
+ /* @__PURE__ */ jsx11("text", { x: CENTER, y: FOOTER_Y + 19, fill: "#fff", fontSize: "24", fontWeight: "bold", letterSpacing: "2", textAnchor: "middle", dominantBaseline: "central", children: label.toUpperCase() })
802
+ ] });
803
+ }
804
+
805
+ // src/components/EngineIndicator.tsx
806
+ import { jsx as jsx12, jsxs as jsxs12 } from "react/jsx-runtime";
807
+ var MAX_CYLINDERS = 6;
808
+ var MAX_BAR_GAUGES = 4;
809
+ var GREEN3 = "#5fe04a";
810
+ var YELLOW = "#ffd400";
811
+ var RED2 = "#ff3030";
812
+ var BLUE = "#4fb7e8";
813
+ var LABEL = "#b9c8e6";
814
+ var LINE = "#8a8f99";
815
+ var round2 = (n) => Math.round(n * 100) / 100;
816
+ var DIAL_R = 182;
817
+ function chord(y, inset = 8) {
818
+ const half = Math.sqrt(Math.max(0, DIAL_R * DIAL_R - (y - CENTER) ** 2)) - inset;
819
+ return `M ${round2(CENTER - half)} ${y} H ${round2(CENTER + half)}`;
820
+ }
821
+ var DEFAULT_MANIFOLD = { min: 10, max: 35, green: [15, 29], yellow: [29, 31], high: 31, unit: "IN", decimals: 1 };
822
+ var DEFAULT_RPM = { min: 0, max: 3e3, green: [800, 2500], yellow: [2500, 2700], high: 2700, decimals: 0 };
823
+ var DEFAULT_BAR_GAUGES = [
824
+ { label: "Oil P", min: 0, max: 100, green: [30, 60], low: 10, high: 95, unit: "PSI" },
825
+ { label: "Oil T", min: 0, max: 250, green: [75, 240], high: 240, unit: "\xB0F" },
826
+ { label: "Fuel P", min: 0, max: 30, low: 1, high: 28, unit: "PSI", decimals: 1 },
827
+ { label: "Fuel F", min: 0, max: 30, green: [8, 20], unit: "GPH", decimals: 1 }
828
+ ];
829
+ function resolve(g, defaults = {}) {
830
+ const min = finite(g.min, finite(defaults.min, 0));
831
+ const max = Math.max(min + 1e-9, finite(g.max, finite(defaults.max, 100)));
832
+ const value = clamp(finite(g.value), min, max);
833
+ const fraction = (value - min) / (max - min);
834
+ const decimals = Math.max(0, Math.floor(finite(g.decimals, finite(defaults.decimals, 0))));
835
+ const low = g.low ?? defaults.low;
836
+ const high = g.high ?? defaults.high;
837
+ const yellow = g.yellow ?? defaults.yellow;
838
+ const inRed = low !== void 0 && value <= low || high !== void 0 && value >= high;
839
+ const inYellow = yellow !== void 0 && value >= yellow[0] && value <= yellow[1];
840
+ return {
841
+ value,
842
+ min,
843
+ max,
844
+ fraction,
845
+ color: inRed ? RED2 : inYellow ? YELLOW : "#fff",
846
+ text: value.toFixed(decimals),
847
+ unit: g.unit ?? defaults.unit,
848
+ green: g.green ?? defaults.green,
849
+ yellow,
850
+ low,
851
+ high
852
+ };
853
+ }
854
+ var ARC_R = 46;
855
+ var ARC_SWEEP = 100;
856
+ var ARC_Y = 112;
857
+ function arcAt(cx, cy, r, a0, a1) {
858
+ const [x0, y0] = polar(r, a0, cx, cy);
859
+ const [x1, y1] = polar(r, a1, cx, cy);
860
+ return `M ${x0} ${y0} A ${r} ${r} 0 ${a1 - a0 > 180 ? 1 : 0} 1 ${x1} ${y1}`;
861
+ }
862
+ function ArcGauge({ cx, label, g, duration, testId }) {
863
+ const span = g.max - g.min;
864
+ const angle = (v) => round2(-ARC_SWEEP + 2 * ARC_SWEEP * clamp((v - g.min) / span, 0, 1));
865
+ const band = (from, to, color) => /* @__PURE__ */ jsx12("path", { d: arcAt(cx, ARC_Y, ARC_R, angle(from), angle(to)), stroke: color, strokeWidth: "6", fill: "none" });
866
+ const [tipX, tipY] = polar(ARC_R - 4, 0, cx, ARC_Y);
867
+ const [lx, ly] = polar(ARC_R - 16, -7, cx, ARC_Y);
868
+ const [rx, ry] = polar(ARC_R - 16, 7, cx, ARC_Y);
869
+ return /* @__PURE__ */ jsxs12("g", { children: [
870
+ /* @__PURE__ */ jsx12("path", { d: arcAt(cx, ARC_Y, ARC_R, -ARC_SWEEP, ARC_SWEEP), stroke: "#fff", strokeWidth: "1.5", fill: "none" }),
871
+ g.green && band(g.green[0], g.green[1], GREEN3),
872
+ g.yellow && band(g.yellow[0], g.yellow[1], YELLOW),
873
+ g.low !== void 0 && band(g.min, g.low, RED2),
874
+ g.high !== void 0 && band(g.high, g.max, RED2),
875
+ /* @__PURE__ */ jsx12("g", { "data-testid": testId, style: motionStyle(`rotate(${angle(g.value)}deg)`, duration, cx, ARC_Y), children: /* @__PURE__ */ jsx12("path", { d: `M ${tipX} ${tipY} L ${lx} ${ly} L ${rx} ${ry} Z`, fill: "#fff", stroke: "#000", strokeWidth: "1" }) }),
876
+ /* @__PURE__ */ jsx12("text", { x: cx, y: ARC_Y - 20, fill: LABEL, fontSize: "14", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: label }),
877
+ /* @__PURE__ */ jsxs12("text", { x: cx, y: ARC_Y + 4, fill: g.color, fontSize: "28", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: [
878
+ g.text,
879
+ g.unit && /* @__PURE__ */ jsx12("tspan", { fontSize: "11", dx: "2", children: g.unit })
880
+ ] })
881
+ ] });
882
+ }
883
+ var BAR_X0 = 210;
884
+ var BAR_X1 = 296;
885
+ var BAR_ROW_H = 39;
886
+ var BAR_TOP2 = 137;
887
+ function BarGauge({ top, g, label, duration, testId }) {
888
+ const y = top + 14;
889
+ const at = (v) => round2(BAR_X0 + (BAR_X1 - BAR_X0) * clamp((v - g.min) / (g.max - g.min), 0, 1));
890
+ const seg = (from, to, color, w = 7) => /* @__PURE__ */ jsx12("path", { d: `M ${at(from)} ${y} H ${at(to)}`, stroke: color, strokeWidth: w });
891
+ return /* @__PURE__ */ jsxs12("g", { children: [
892
+ /* @__PURE__ */ jsx12("path", { d: `M ${BAR_X0} ${y} H ${BAR_X1}`, stroke: "#fff", strokeWidth: "2" }),
893
+ /* @__PURE__ */ jsx12("path", { d: `M ${BAR_X0} ${y - 4} v 8 M ${BAR_X1} ${y - 4} v 8`, stroke: "#fff", strokeWidth: "2" }),
894
+ g.green && seg(g.green[0], g.green[1], GREEN3),
895
+ g.yellow && seg(g.yellow[0], g.yellow[1], YELLOW),
896
+ g.low !== void 0 && seg(g.min, g.low, RED2),
897
+ g.high !== void 0 && seg(g.high, g.max, RED2),
898
+ /* @__PURE__ */ jsx12("g", { "data-testid": testId, style: motionStyle(`translate(${round2(at(g.value) - BAR_X0)}px, 0px)`, duration), children: /* @__PURE__ */ jsx12("path", { d: `M ${BAR_X0} ${y - 3} l -5 -9 h 10 z`, fill: "#fff", stroke: "#000", strokeWidth: "1" }) }),
899
+ /* @__PURE__ */ jsx12("text", { x: BAR_X0, y: top + 31, fill: LABEL, fontSize: "13", fontWeight: "bold", dominantBaseline: "central", children: label }),
900
+ /* @__PURE__ */ jsx12("text", { x: 350, y: top + 15, fill: g.color, fontSize: "20", fontWeight: "bold", textAnchor: "end", dominantBaseline: "central", children: g.text }),
901
+ g.unit && /* @__PURE__ */ jsx12("text", { x: 350, y: top + 31, fill: LABEL, fontSize: "10", fontWeight: "bold", textAnchor: "end", dominantBaseline: "central", children: g.unit })
902
+ ] });
903
+ }
904
+ function Tank({ x, fraction, duration, testId }) {
905
+ const top = 304;
906
+ const h = 40;
907
+ return /* @__PURE__ */ jsxs12("g", { children: [
908
+ /* @__PURE__ */ jsx12("rect", { x: x - 7, y: top, width: "14", height: h, rx: "3", fill: "#000", stroke: "#fff", strokeWidth: "1.5" }),
909
+ /* @__PURE__ */ jsx12("g", { "data-testid": testId, style: motionStyle(`scaleY(${fraction})`, duration, x, top + h - 2), children: /* @__PURE__ */ jsx12("rect", { x: x - 5.5, y: top + 2, width: "11", height: h - 4, fill: BLUE }) }),
910
+ /* @__PURE__ */ jsx12("rect", { x: x - 5.5, y: top + h - 5, width: "11", height: "3", fill: RED2 })
911
+ ] });
912
+ }
913
+ var hottest = (values) => {
914
+ const finite_ = values.map((v) => finite(v, NaN)).filter((v) => !Number.isNaN(v));
915
+ return finite_.length ? Math.max(...finite_) : void 0;
916
+ };
917
+ function EngineIndicator({
918
+ power,
919
+ manifold = {},
920
+ rpm = {},
921
+ cht = [],
922
+ egt = [],
923
+ tit,
924
+ chtLimit = 400,
925
+ chtScale = 500,
926
+ egtScale = 1700,
927
+ temperatureUnit = "\xB0F",
928
+ gauges = DEFAULT_BAR_GAUGES,
929
+ amps,
930
+ volts,
931
+ fuelLeft,
932
+ fuelRight,
933
+ fuelCapacity = 30,
934
+ fuelUnit = "GAL",
935
+ ...props
936
+ }) {
937
+ const duration = props.animationDuration ?? DEFAULT_ANIMATION_MS;
938
+ const man = resolve(manifold, DEFAULT_MANIFOLD);
939
+ const speed = resolve(rpm, DEFAULT_RPM);
940
+ const bars = gauges.slice(0, MAX_BAR_GAUGES).map((g) => ({ label: g.label, g: resolve(g) }));
941
+ const chtValues = cht.slice(0, MAX_CYLINDERS);
942
+ const egtValues = egt.slice(0, MAX_CYLINDERS);
943
+ const cylinders = Math.max(chtValues.length, egtValues.length);
944
+ const hasTit = typeof tit === "number" && Number.isFinite(tit);
945
+ const columns = cylinders + (hasTit ? 1 : 0);
946
+ const chtMax = hottest(chtValues);
947
+ const egtMax = hottest(egtValues);
948
+ const chartX0 = 50;
949
+ const chartX1 = 192;
950
+ const chartBase = 284;
951
+ const chartH = 88;
952
+ const colW = columns > 0 ? (chartX1 - chartX0) / columns : 0;
953
+ const barW = clamp(colW * 0.35, 4, 9);
954
+ const chtFrac = (v) => clamp(finite(v) / Math.max(1e-9, finite(chtScale, 500)), 0, 1);
955
+ const egtFrac = (v) => clamp(finite(v) / Math.max(1e-9, finite(egtScale, 1700)), 0, 1);
956
+ const limitY = chartBase - chartH * chtFrac(chtLimit);
957
+ const cap = Math.max(1e-9, finite(fuelCapacity, 30));
958
+ const left = clamp(finite(fuelLeft), 0, cap);
959
+ const right = clamp(finite(fuelRight), 0, cap);
960
+ const fmt = (v, d = 0) => typeof v === "number" && Number.isFinite(v) ? v.toFixed(d) : "---";
961
+ const readouts = [
962
+ { name: "CHT", value: chtMax, color: GREEN3, x: 62 },
963
+ { name: "EGT", value: egtMax, color: BLUE, x: 118 },
964
+ { name: "TIT", value: hasTit ? tit : void 0, color: "#fff", x: 170 }
965
+ ].filter((r) => r.value !== void 0);
966
+ const label = "Engine: " + [
967
+ power !== void 0 ? `power ${fmt(power)}%` : null,
968
+ `MAN ${man.text}${man.unit ? ` ${man.unit}` : ""}`,
969
+ `RPM ${speed.text}`,
970
+ chtMax !== void 0 ? `CHT ${fmt(chtMax)}${temperatureUnit}` : null,
971
+ egtMax !== void 0 ? `EGT ${fmt(egtMax)}${temperatureUnit}` : null,
972
+ hasTit ? `TIT ${fmt(tit)}${temperatureUnit}` : null,
973
+ ...bars.map((b) => `${b.label} ${b.g.text}${b.g.unit ? ` ${b.g.unit}` : ""}`),
974
+ amps !== void 0 ? `${fmt(amps)} A` : null,
975
+ fuelLeft !== void 0 || fuelRight !== void 0 ? `fuel ${fmt(fuelLeft)}/${fmt(fuelRight)} ${fuelUnit}` : null,
976
+ volts !== void 0 ? `${fmt(volts, 1)} V` : null
977
+ ].filter(Boolean).join(", ");
978
+ return /* @__PURE__ */ jsxs12(InstrumentFrame, { ...props, label, children: [
979
+ power !== void 0 && /* @__PURE__ */ jsxs12("text", { x: CENTER, y: 44, fill: "#fff", fontSize: "18", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: [
980
+ /* @__PURE__ */ jsxs12("tspan", { fill: LABEL, fontSize: "11", children: [
981
+ "POWER",
982
+ " "
983
+ ] }),
984
+ fmt(power),
985
+ /* @__PURE__ */ jsx12("tspan", { fontSize: "11", children: "%" })
986
+ ] }),
987
+ /* @__PURE__ */ jsx12(ArcGauge, { cx: 118, label: "MAN", g: man, duration, testId: "engine-man" }),
988
+ /* @__PURE__ */ jsx12(ArcGauge, { cx: 282, label: "RPM", g: speed, duration, testId: "engine-rpm" }),
989
+ /* @__PURE__ */ jsxs12("g", { stroke: LINE, strokeWidth: "1.5", children: [
990
+ /* @__PURE__ */ jsx12("path", { d: chord(133) }),
991
+ /* @__PURE__ */ jsx12("path", { d: "M 200 133 V 298" }),
992
+ /* @__PURE__ */ jsx12("path", { d: chord(298) }),
993
+ /* @__PURE__ */ jsx12("path", { d: "M 136 298 V 348 M 264 298 V 348" })
994
+ ] }),
995
+ /* @__PURE__ */ jsx12("g", { fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: readouts.map((r) => /* @__PURE__ */ jsxs12("g", { children: [
996
+ /* @__PURE__ */ jsxs12("text", { x: r.x, y: 144, fill: LABEL, fontSize: "13", children: [
997
+ r.name,
998
+ /* @__PURE__ */ jsx12("tspan", { fontSize: "9", children: temperatureUnit })
999
+ ] }),
1000
+ /* @__PURE__ */ jsx12("text", { "data-testid": `engine-${r.name.toLowerCase()}`, x: r.x, y: 165, fill: r.color, fontSize: "22", children: fmt(r.value) })
1001
+ ] }, r.name)) }),
1002
+ /* @__PURE__ */ jsx12("path", { d: "M 40 178 H 190", stroke: LINE, strokeWidth: "1" }),
1003
+ columns > 0 && /* @__PURE__ */ jsxs12("g", { children: [
1004
+ /* @__PURE__ */ jsx12("path", { d: `M ${chartX0} ${limitY} H ${chartX1}`, stroke: RED2, strokeWidth: "1.5", strokeDasharray: "5 4" }),
1005
+ /* @__PURE__ */ jsx12("text", { x: chartX0 - 4, y: limitY, fill: "#fff", fontSize: "10", fontWeight: "bold", textAnchor: "end", dominantBaseline: "central", children: "CHT" }),
1006
+ Array.from({ length: cylinders }, (_, i) => {
1007
+ const x0 = chartX0 + colW * i;
1008
+ const mid = x0 + colW / 2;
1009
+ const c = chtValues[i];
1010
+ const e = egtValues[i];
1011
+ return /* @__PURE__ */ jsxs12("g", { children: [
1012
+ c !== void 0 && /* @__PURE__ */ jsx12("g", { "data-testid": `engine-cht-${i}`, style: motionStyle(`scaleY(${chtFrac(c)})`, duration, mid, chartBase), children: /* @__PURE__ */ jsx12("rect", { x: mid - barW - 1, y: chartBase - chartH, width: barW, height: chartH, fill: GREEN3 }) }),
1013
+ e !== void 0 && /* @__PURE__ */ jsx12("g", { "data-testid": `engine-egt-${i}`, style: motionStyle(`scaleY(${egtFrac(e)})`, duration, mid, chartBase), children: /* @__PURE__ */ jsx12("rect", { x: mid + 1, y: chartBase - chartH, width: barW, height: chartH, fill: BLUE }) }),
1014
+ /* @__PURE__ */ jsx12("text", { x: mid, y: 294, fill: "#fff", fontSize: "12", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: i + 1 })
1015
+ ] }, i);
1016
+ }),
1017
+ hasTit && /* @__PURE__ */ jsxs12("g", { children: [
1018
+ /* @__PURE__ */ jsx12("g", { "data-testid": "engine-tit-bar", style: motionStyle(`scaleY(${egtFrac(tit)})`, duration, chartX1 - colW / 2, chartBase), children: /* @__PURE__ */ jsx12("rect", { x: chartX1 - colW / 2 - barW / 2, y: chartBase - chartH, width: barW, height: chartH, fill: "#fff" }) }),
1019
+ /* @__PURE__ */ jsx12("text", { x: chartX1 - colW / 2, y: 294, fill: "#fff", fontSize: "12", fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: "T" })
1020
+ ] })
1021
+ ] }),
1022
+ bars.map((b, i) => /* @__PURE__ */ jsxs12("g", { children: [
1023
+ i > 0 && /* @__PURE__ */ jsx12("path", { d: `M 206 ${BAR_TOP2 + BAR_ROW_H * i - 2} H 352`, stroke: LINE, strokeWidth: "1" }),
1024
+ /* @__PURE__ */ jsx12(BarGauge, { top: BAR_TOP2 + BAR_ROW_H * i, g: b.g, label: b.label, duration, testId: `engine-bar-${i}` })
1025
+ ] }, b.label)),
1026
+ /* @__PURE__ */ jsxs12("g", { fontWeight: "bold", textAnchor: "middle", dominantBaseline: "central", children: [
1027
+ /* @__PURE__ */ jsxs12("text", { "data-testid": "engine-amps", x: 104, y: 318, fill: "#fff", fontSize: "20", children: [
1028
+ fmt(amps),
1029
+ /* @__PURE__ */ jsx12("tspan", { fontSize: "11", dx: "2", children: "A" })
1030
+ ] }),
1031
+ /* @__PURE__ */ jsx12("text", { x: 104, y: 338, fill: LABEL, fontSize: "13", children: "ALT" }),
1032
+ /* @__PURE__ */ jsx12(Tank, { x: 152, fraction: left / cap, duration, testId: "engine-fuel-left" }),
1033
+ /* @__PURE__ */ jsx12(Tank, { x: 248, fraction: right / cap, duration, testId: "engine-fuel-right" }),
1034
+ /* @__PURE__ */ jsxs12("text", { "data-testid": "engine-fuel", x: 200, y: 316, fill: "#fff", fontSize: "20", children: [
1035
+ fmt(left),
1036
+ /* @__PURE__ */ jsx12("tspan", { dx: "14", children: fmt(right) })
1037
+ ] }),
1038
+ /* @__PURE__ */ jsx12("text", { x: 200, y: 335, fill: LABEL, fontSize: "13", children: "Fuel" }),
1039
+ /* @__PURE__ */ jsx12("text", { x: 200, y: 348, fill: LABEL, fontSize: "9", children: fuelUnit }),
1040
+ /* @__PURE__ */ jsxs12("text", { "data-testid": "engine-volts", x: 296, y: 318, fill: "#fff", fontSize: "20", children: [
1041
+ fmt(volts, 1),
1042
+ /* @__PURE__ */ jsx12("tspan", { fontSize: "11", dx: "2", children: "V" })
1043
+ ] }),
1044
+ /* @__PURE__ */ jsx12("text", { x: 296, y: 338, fill: LABEL, fontSize: "13", children: "BATT" })
1045
+ ] })
1046
+ ] });
1047
+ }
1048
+
1049
+ // src/components/FlapIndicator.tsx
1050
+ import { jsx as jsx13, jsxs as jsxs13 } from "react/jsx-runtime";
1051
+ var GREEN4 = "#3ddc3d";
1052
+ var YELLOW2 = "#ffd400";
1053
+ var ORANGE = "#ff8a00";
1054
+ var RED3 = "#ff2a2a";
1055
+ var BAR_X = 226;
1056
+ var BAR_W = 30;
1057
+ var BAR_TOP3 = 78;
1058
+ var BAR_BOTTOM2 = 302;
1059
+ var BAR_H2 = BAR_BOTTOM2 - BAR_TOP3;
1060
+ function segmentColor(fraction) {
1061
+ if (fraction < 0.25) return GREEN4;
1062
+ if (fraction < 0.5) return YELLOW2;
1063
+ if (fraction < 0.75) return ORANGE;
1064
+ return RED3;
1065
+ }
1066
+ function FlapIndicator({
1067
+ flaps = 0,
1068
+ max = 40,
1069
+ detents,
1070
+ segments = 20,
1071
+ speedLimits,
1072
+ airspeed,
1073
+ label = "WING FLAP",
1074
+ ...props
1075
+ }) {
1076
+ const duration = props.animationDuration ?? DEFAULT_ANIMATION_MS;
1077
+ const full = Math.max(1e-9, finite(max, 40));
1078
+ const position = clamp(finite(flaps), 0, full);
1079
+ const fraction = position / full;
1080
+ const count = Math.max(1, Math.floor(finite(segments, 20)));
1081
+ const lit = Math.round(fraction * count);
1082
+ const scale = (detents ?? Array.from({ length: Math.floor(full / 10) + 1 }, (_, i) => i * 10)).filter((d) => d >= 0 && d <= full);
1083
+ const yAt = (deg) => Math.round((BAR_TOP3 + deg / full * BAR_H2) * 100) / 100;
1084
+ const limit = (speedLimits ?? []).filter((l) => Number.isFinite(l.flaps) && Number.isFinite(l.speed) && l.flaps <= position).sort((a, b) => b.flaps - a.flaps)[0];
1085
+ const ias = finite(airspeed, NaN);
1086
+ const overspeed = limit !== void 0 && !Number.isNaN(ias) && ias > limit.speed;
1087
+ const segH = BAR_H2 / count;
1088
+ const title = `${label}: ${Math.round(position)}\xB0 of ${Math.round(full)}\xB0` + (limit ? `, max ${Math.round(limit.speed)} knots${overspeed ? " (overspeed)" : ""}` : "");
1089
+ return /* @__PURE__ */ jsxs13(InstrumentFrame, { ...props, label: title, children: [
1090
+ /* @__PURE__ */ jsx13("rect", { x: BAR_X - BAR_W / 2 - 4, y: BAR_TOP3 - 4, width: BAR_W + 8, height: BAR_H2 + 8, rx: "4", fill: "#000", stroke: "#333", strokeWidth: "1.5" }),
1091
+ Array.from({ length: count }, (_, i) => {
1092
+ const y = BAR_TOP3 + i * segH;
1093
+ const on = i < lit;
1094
+ return /* @__PURE__ */ jsx13(
1095
+ "rect",
1096
+ {
1097
+ "data-testid": `flap-segment-${i}`,
1098
+ "data-lit": on ? "true" : "false",
1099
+ x: BAR_X - BAR_W / 2,
1100
+ y: y + 1,
1101
+ width: BAR_W,
1102
+ height: Math.max(1, segH - 2),
1103
+ rx: "1.5",
1104
+ fill: segmentColor((i + 0.5) / count),
1105
+ opacity: on ? 1 : 0.18,
1106
+ style: { transition: "opacity 150ms ease-out" }
1107
+ },
1108
+ i
1109
+ );
1110
+ }),
1111
+ /* @__PURE__ */ jsx13("g", { fill: "#fff", fontSize: "18", fontWeight: "bold", dominantBaseline: "central", children: scale.map((d) => /* @__PURE__ */ jsxs13("g", { children: [
1112
+ /* @__PURE__ */ jsx13("path", { d: `M ${BAR_X + BAR_W / 2 + 8} ${yAt(d)} h 8`, stroke: "#fff", strokeWidth: "2" }),
1113
+ /* @__PURE__ */ jsx13("text", { x: BAR_X + BAR_W / 2 + 22, y: yAt(d), children: d })
1114
+ ] }, d)) }),
1115
+ /* @__PURE__ */ jsx13("g", { "data-testid": "flap-pointer", style: motionStyle(`translate(0px, ${yAt(position) - BAR_TOP3}px)`, duration), children: /* @__PURE__ */ jsx13("path", { d: `M ${BAR_X - BAR_W / 2 - 8} ${BAR_TOP3} l -14 -8 v 16 z`, fill: "#fff", stroke: "#000", strokeWidth: "1" }) }),
1116
+ limit && /* @__PURE__ */ jsxs13("g", { textAnchor: "middle", dominantBaseline: "central", fill: overspeed ? RED3 : "#fff", children: [
1117
+ /* @__PURE__ */ jsxs13("text", { "data-testid": "flap-speed", x: 118, y: 176, fontSize: "36", fontWeight: "bold", children: [
1118
+ Math.round(limit.speed),
1119
+ /* @__PURE__ */ jsx13("tspan", { fontSize: "13", dx: "3", children: "KTS" })
1120
+ ] }),
1121
+ /* @__PURE__ */ jsx13("text", { x: 118, y: 212, fontSize: "13", fontWeight: "bold", fill: "#bbb", letterSpacing: "2", children: "MAX" })
1122
+ ] }),
1123
+ /* @__PURE__ */ jsx13("text", { x: CENTER, y: 345, fill: "#ccc", fontSize: "16", textAnchor: "middle", children: label.toUpperCase() })
1124
+ ] });
1125
+ }
1126
+
1127
+ // src/components/AoaIndicator.tsx
1128
+ import { Fragment as Fragment2, jsx as jsx14, jsxs as jsxs14 } from "react/jsx-runtime";
1129
+ var GREEN5 = "#3ddc3d";
1130
+ var AMBER3 = "#ffb000";
1131
+ var RED4 = "#ff2a2a";
1132
+ var UNLIT_OPACITY = 0.15;
1133
+ var ROWS = [
1134
+ { shape: "bar", color: GREEN5, y: 300 },
1135
+ { shape: "bar", color: GREEN5, y: 278 },
1136
+ { shape: "bar", color: GREEN5, y: 256 },
1137
+ { shape: "bar", color: GREEN5, y: 234 },
1138
+ { shape: "donut", color: GREEN5, y: 208 },
1139
+ { shape: "bar", color: AMBER3, y: 182 },
1140
+ { shape: "split", color: AMBER3, y: 160 },
1141
+ { shape: "chevron", color: AMBER3, y: 125 },
1142
+ { shape: "chevron", color: AMBER3, y: 103 },
1143
+ { shape: "chevron", color: RED4, y: 74 },
1144
+ { shape: "chevron", color: RED4, y: 52 }
1145
+ ];
1146
+ var DONUT = ROWS.findIndex((r) => r.shape === "donut");
1147
+ var ABOVE = ROWS.length - 1 - DONUT;
1148
+ var HALF = 70;
1149
+ var BAR_H3 = 12;
1150
+ var CHEVRON_DEPTH = 26;
1151
+ function RowShape({ shape, y }) {
1152
+ const l = CENTER - HALF;
1153
+ const r = CENTER + HALF;
1154
+ switch (shape) {
1155
+ case "bar":
1156
+ return /* @__PURE__ */ jsx14("rect", { x: l, y: y - BAR_H3 / 2, width: HALF * 2, height: BAR_H3, rx: "2" });
1157
+ case "split":
1158
+ return /* @__PURE__ */ jsxs14(Fragment2, { children: [
1159
+ /* @__PURE__ */ jsx14("rect", { x: l, y: y - BAR_H3 / 2, width: 50, height: BAR_H3, rx: "2" }),
1160
+ /* @__PURE__ */ jsx14("rect", { x: r - 50, y: y - BAR_H3 / 2, width: 50, height: BAR_H3, rx: "2" })
1161
+ ] });
1162
+ case "donut":
1163
+ return /* @__PURE__ */ jsxs14(Fragment2, { children: [
1164
+ /* @__PURE__ */ jsx14("rect", { x: l, y: y - BAR_H3 / 2, width: HALF - 24, height: BAR_H3, rx: "2" }),
1165
+ /* @__PURE__ */ jsx14("rect", { x: CENTER + 24, y: y - BAR_H3 / 2, width: HALF - 24, height: BAR_H3, rx: "2" }),
1166
+ /* @__PURE__ */ jsx14("circle", { cx: CENTER, cy: y, r: 13, fill: "none", strokeWidth: "7" })
1167
+ ] });
1168
+ case "chevron":
1169
+ return /* @__PURE__ */ jsx14("path", { d: `M ${l} ${y} L ${CENTER} ${y + CHEVRON_DEPTH} L ${r} ${y}`, fill: "none", strokeWidth: "11", strokeLinejoin: "miter" });
1170
+ }
1171
+ }
1172
+ function AoaIndicator({ aoa = 0, min = 0, optimum, max = 20, showValue = false, label = "AOA", ...props }) {
1173
+ const lo = finite(min, 0);
1174
+ const hi = Math.max(lo + 1e-6, finite(max, 20));
1175
+ const opt = clamp(finite(optimum, (lo + hi) / 2), lo, hi);
1176
+ const value = finite(aoa, NaN);
1177
+ const thresholds = ROWS.map((_, i) => i <= DONUT ? lo + i / DONUT * (opt - lo) : opt + (i - DONUT) / ABOVE * (hi - opt));
1178
+ const lit = Number.isNaN(value) ? 0 : thresholds.filter((t) => value >= t - 1e-9).length;
1179
+ const stall = lit === ROWS.length;
1180
+ const reading = Number.isNaN(value) ? "---" : `${value.toFixed(1)}\xB0`;
1181
+ const state = stall ? " (stall warning)" : lit > DONUT + 1 ? " (high)" : lit === DONUT + 1 ? " (optimum)" : "";
1182
+ const title = `${label}: ${reading}${Number.isNaN(value) ? "" : state}`;
1183
+ return /* @__PURE__ */ jsxs14(InstrumentFrame, { ...props, label: title, children: [
1184
+ /* @__PURE__ */ jsx14("rect", { x: CENTER - HALF - 10, y: 40, width: (HALF + 10) * 2, height: 278, rx: "10", fill: "#000", stroke: "#333", strokeWidth: "1.5" }),
1185
+ ROWS.map((row, i) => {
1186
+ const on = i < lit;
1187
+ return /* @__PURE__ */ jsxs14(
1188
+ "g",
1189
+ {
1190
+ "data-testid": `aoa-row-${i}`,
1191
+ "data-lit": on ? "true" : "false",
1192
+ fill: row.color,
1193
+ stroke: row.color,
1194
+ strokeWidth: "0",
1195
+ opacity: on ? 1 : UNLIT_OPACITY,
1196
+ style: { transition: "opacity 150ms ease-out" },
1197
+ children: [
1198
+ /* @__PURE__ */ jsx14(RowShape, { shape: row.shape, y: row.y }),
1199
+ on && stall && row.shape === "chevron" && /* @__PURE__ */ jsx14("animate", { attributeName: "opacity", values: "1;0.25;1", dur: "0.6s", repeatCount: "indefinite" })
1200
+ ]
1201
+ },
1202
+ i
1203
+ );
1204
+ }),
1205
+ showValue && /* @__PURE__ */ jsx14("text", { "data-testid": "aoa-value", x: CENTER, y: 340, fill: "#fff", fontSize: "18", fontWeight: "bold", textAnchor: "middle", children: reading }),
1206
+ /* @__PURE__ */ jsx14("text", { x: CENTER, y: showValue ? 362 : 345, fill: "#ccc", fontSize: "16", textAnchor: "middle", children: label.toUpperCase() })
1207
+ ] });
1208
+ }
375
1209
  export {
376
1210
  Airspeed,
377
1211
  Altimeter,
1212
+ AoaIndicator,
378
1213
  AttitudeIndicator,
1214
+ DEFAULT_BAR_GAUGES,
1215
+ DEFAULT_MANIFOLD,
1216
+ DEFAULT_RPM,
1217
+ DataPanel,
1218
+ EngineIndicator,
1219
+ FlapIndicator,
1220
+ FuelIndicator,
379
1221
  HeadingIndicator,
1222
+ MAX_BAR_GAUGES,
1223
+ MAX_CYLINDERS,
1224
+ MAX_FIELDS,
1225
+ MAX_TANKS,
380
1226
  TurnCoordinator,
381
- VerticalSpeed
1227
+ VerticalSpeed,
1228
+ VorIndicator,
1229
+ WindIndicator,
1230
+ formatValue,
1231
+ vorDeviation
382
1232
  };
383
1233
  //# sourceMappingURL=index.js.map