@azohra/meteo.station 0.1.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.
Files changed (160) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +53 -0
  3. package/dist/air.d.ts +13 -0
  4. package/dist/air.js +76 -0
  5. package/dist/client/index.d.ts +4 -0
  6. package/dist/client/index.js +4 -0
  7. package/dist/client/poll.d.ts +42 -0
  8. package/dist/client/poll.js +121 -0
  9. package/dist/client/stores.d.ts +46 -0
  10. package/dist/client/stores.js +128 -0
  11. package/dist/client/ticker.d.ts +4 -0
  12. package/dist/client/ticker.js +19 -0
  13. package/dist/contract.d.ts +381 -0
  14. package/dist/contract.js +143 -0
  15. package/dist/derive.d.ts +54 -0
  16. package/dist/derive.js +134 -0
  17. package/dist/display.d.ts +28 -0
  18. package/dist/display.js +27 -0
  19. package/dist/elements/elements/AirMatrixElement.d.ts +14 -0
  20. package/dist/elements/elements/AirMatrixElement.js +83 -0
  21. package/dist/elements/elements/CurrentConditionsElement.d.ts +9 -0
  22. package/dist/elements/elements/CurrentConditionsElement.js +52 -0
  23. package/dist/elements/elements/DailyPatternElement.d.ts +15 -0
  24. package/dist/elements/elements/DailyPatternElement.js +200 -0
  25. package/dist/elements/elements/DialElement.d.ts +9 -0
  26. package/dist/elements/elements/DialElement.js +128 -0
  27. package/dist/elements/elements/FreshnessBadgeElement.d.ts +8 -0
  28. package/dist/elements/elements/FreshnessBadgeElement.js +22 -0
  29. package/dist/elements/elements/SparklineElement.d.ts +9 -0
  30. package/dist/elements/elements/SparklineElement.js +74 -0
  31. package/dist/elements/elements/StationCardElement.d.ts +53 -0
  32. package/dist/elements/elements/StationCardElement.js +211 -0
  33. package/dist/elements/elements/StationFeedElement.d.ts +32 -0
  34. package/dist/elements/elements/StationFeedElement.js +215 -0
  35. package/dist/elements/elements/StationStripElement.d.ts +9 -0
  36. package/dist/elements/elements/StationStripElement.js +43 -0
  37. package/dist/elements/elements/StationTableElement.d.ts +18 -0
  38. package/dist/elements/elements/StationTableElement.js +102 -0
  39. package/dist/elements/elements/TrendChartElement.d.ts +10 -0
  40. package/dist/elements/elements/TrendChartElement.js +174 -0
  41. package/dist/elements/elements/WindArrowElement.d.ts +8 -0
  42. package/dist/elements/elements/WindArrowElement.js +14 -0
  43. package/dist/elements/elements/WindHistoryChartElement.d.ts +10 -0
  44. package/dist/elements/elements/WindHistoryChartElement.js +277 -0
  45. package/dist/elements/elements/WindRoseElement.d.ts +17 -0
  46. package/dist/elements/elements/WindRoseElement.js +106 -0
  47. package/dist/elements/elements/atoms.d.ts +48 -0
  48. package/dist/elements/elements/atoms.js +131 -0
  49. package/dist/elements/index.d.ts +48 -0
  50. package/dist/elements/index.js +57 -0
  51. package/dist/elements/lib/ambient.d.ts +15 -0
  52. package/dist/elements/lib/ambient.js +5 -0
  53. package/dist/elements/lib/attributes.js +21 -0
  54. package/dist/elements/lib/base.d.ts +45 -0
  55. package/dist/elements/lib/base.js +152 -0
  56. package/dist/elements/lib/context.js +28 -0
  57. package/dist/elements/lib/fragments.js +45 -0
  58. package/dist/elements/lib/h.js +35 -0
  59. package/dist/elements/register.d.ts +1 -0
  60. package/dist/elements/register.js +5 -0
  61. package/dist/endpoints.d.ts +5 -0
  62. package/dist/endpoints.js +10 -0
  63. package/dist/fixtures.d.ts +23 -0
  64. package/dist/fixtures.js +67 -0
  65. package/dist/format.d.ts +31 -0
  66. package/dist/format.js +82 -0
  67. package/dist/geometry.d.ts +84 -0
  68. package/dist/geometry.js +333 -0
  69. package/dist/index.d.ts +12 -0
  70. package/dist/index.js +12 -0
  71. package/dist/instruments.d.ts +75 -0
  72. package/dist/instruments.js +173 -0
  73. package/dist/merge-current.d.ts +13 -0
  74. package/dist/merge-current.js +54 -0
  75. package/dist/react/components/AirMatrix.d.ts +11 -0
  76. package/dist/react/components/AirMatrix.js +82 -0
  77. package/dist/react/components/CurrentConditions.d.ts +17 -0
  78. package/dist/react/components/CurrentConditions.js +98 -0
  79. package/dist/react/components/DailyPattern.d.ts +19 -0
  80. package/dist/react/components/DailyPattern.js +212 -0
  81. package/dist/react/components/Dial.d.ts +17 -0
  82. package/dist/react/components/Dial.js +133 -0
  83. package/dist/react/components/FreshnessBadge.d.ts +10 -0
  84. package/dist/react/components/FreshnessBadge.js +20 -0
  85. package/dist/react/components/Sparkline.d.ts +17 -0
  86. package/dist/react/components/Sparkline.js +60 -0
  87. package/dist/react/components/StationCard.d.ts +46 -0
  88. package/dist/react/components/StationCard.js +140 -0
  89. package/dist/react/components/StationFeedProvider.d.ts +27 -0
  90. package/dist/react/components/StationFeedProvider.js +40 -0
  91. package/dist/react/components/StationStrip.d.ts +16 -0
  92. package/dist/react/components/StationStrip.js +84 -0
  93. package/dist/react/components/StationTable.d.ts +18 -0
  94. package/dist/react/components/StationTable.js +115 -0
  95. package/dist/react/components/TrendChart.d.ts +14 -0
  96. package/dist/react/components/TrendChart.js +150 -0
  97. package/dist/react/components/WindArrow.d.ts +7 -0
  98. package/dist/react/components/WindArrow.js +21 -0
  99. package/dist/react/components/WindHistoryChart.d.ts +18 -0
  100. package/dist/react/components/WindHistoryChart.js +278 -0
  101. package/dist/react/components/WindRose.d.ts +17 -0
  102. package/dist/react/components/WindRose.js +99 -0
  103. package/dist/react/components/atoms.d.ts +33 -0
  104. package/dist/react/components/atoms.js +136 -0
  105. package/dist/react/hooks/useFreshness.d.ts +6 -0
  106. package/dist/react/hooks/useFreshness.js +21 -0
  107. package/dist/react/hooks/usePolledJson.js +17 -0
  108. package/dist/react/hooks/useStation.d.ts +23 -0
  109. package/dist/react/hooks/useStation.js +42 -0
  110. package/dist/react/hooks/useStationCurrent.d.ts +23 -0
  111. package/dist/react/hooks/useStationCurrent.js +32 -0
  112. package/dist/react/hooks/useStationFeed.d.ts +22 -0
  113. package/dist/react/hooks/useStationFeed.js +28 -0
  114. package/dist/react/index.d.ts +20 -0
  115. package/dist/react/index.js +21 -0
  116. package/dist/react/lib/cells.js +29 -0
  117. package/dist/scene/air-matrix.js +71 -0
  118. package/dist/scene/atoms.js +102 -0
  119. package/dist/scene/card.js +54 -0
  120. package/dist/scene/chart.js +28 -0
  121. package/dist/scene/current.js +66 -0
  122. package/dist/scene/daily-pattern.js +81 -0
  123. package/dist/scene/dial.js +141 -0
  124. package/dist/scene/glyphs.js +24 -0
  125. package/dist/scene/rose.js +120 -0
  126. package/dist/scene/sparkline.js +73 -0
  127. package/dist/scene/strip.js +63 -0
  128. package/dist/scene/table.js +76 -0
  129. package/dist/scene/trend.js +160 -0
  130. package/dist/scene/wind-history.js +148 -0
  131. package/dist/scene/wind-plot.js +214 -0
  132. package/dist/server/adapter.d.ts +28 -0
  133. package/dist/server/adapter.js +32 -0
  134. package/dist/server/adapters/campbell.d.ts +112 -0
  135. package/dist/server/adapters/campbell.js +414 -0
  136. package/dist/server/adapters/tempest.d.ts +27 -0
  137. package/dist/server/adapters/tempest.js +137 -0
  138. package/dist/server/adapters/windnerd.d.ts +39 -0
  139. package/dist/server/adapters/windnerd.js +159 -0
  140. package/dist/server/config.d.ts +135 -0
  141. package/dist/server/config.js +57 -0
  142. package/dist/server/environment.d.ts +48 -0
  143. package/dist/server/environment.js +128 -0
  144. package/dist/server/feed.d.ts +31 -0
  145. package/dist/server/feed.js +216 -0
  146. package/dist/server/handler.d.ts +17 -0
  147. package/dist/server/handler.js +133 -0
  148. package/dist/server/index.d.ts +10 -0
  149. package/dist/server/index.js +10 -0
  150. package/dist/strings.d.ts +118 -0
  151. package/dist/strings.js +237 -0
  152. package/dist/windnerd.d.ts +5 -0
  153. package/dist/windnerd.js +25 -0
  154. package/package.json +97 -0
  155. package/schema/README.md +14 -0
  156. package/schema/example-current.json +48 -0
  157. package/schema/example-feed.json +147 -0
  158. package/schema/stationcurrent.schema.json +641 -0
  159. package/schema/stationfeed.schema.json +656 -0
  160. package/styles.css +1141 -0
@@ -0,0 +1,28 @@
1
+ import { nearestIndex } from "../geometry.js";
2
+ //#region src/scene/chart.ts
3
+ function tickAnchor(index, lastIndex) {
4
+ return index === 0 ? "start" : index === lastIndex ? "end" : "middle";
5
+ }
6
+ function measuredChartWidth(measured) {
7
+ return measured > 0 ? Math.round(measured) : 360;
8
+ }
9
+ function pinnedIndexOf(points, pinnedAt) {
10
+ if (pinnedAt == null) return null;
11
+ const found = points.findIndex((point) => point.observedAt === pinnedAt);
12
+ return found === -1 ? null : found;
13
+ }
14
+ function activeChartIndex(points, pinnedAt, previewIndex) {
15
+ return previewIndex ?? pinnedIndexOf(points, pinnedAt);
16
+ }
17
+ function chartIndexAtClient(points, frame, scales, clientX, bounds) {
18
+ if (bounds.width === 0) return null;
19
+ return nearestIndex(points, (clientX - bounds.left) / bounds.width * frame.width, frame, scales);
20
+ }
21
+ function togglePinnedAt(current, observedAt) {
22
+ return current === observedAt ? null : observedAt;
23
+ }
24
+ function readoutAriaLive(previewIndex) {
25
+ return previewIndex == null ? "polite" : "off";
26
+ }
27
+ //#endregion
28
+ export { activeChartIndex, chartIndexAtClient, measuredChartWidth, pinnedIndexOf, readoutAriaLive, tickAnchor, togglePinnedAt };
@@ -0,0 +1,66 @@
1
+ import { compassDirection, isCalm } from "../derive.js";
2
+ import { roundSpeed, temperatureText, temperatureValue } from "../format.js";
3
+ //#region src/scene/current.ts
4
+ function currentConditionsScene(input) {
5
+ const { formatTime, station, unit, words } = input;
6
+ const reading = station.status === "ok" ? station.reading : null;
7
+ const calm = reading != null && isCalm(reading.windAvgMps);
8
+ const blowing = reading != null && !calm && reading.windDirectionDeg != null;
9
+ const flankValue = (valueMps) => valueMps == null ? "—" : String(roundSpeed(valueMps, unit));
10
+ return {
11
+ root: {
12
+ ariaLabel: words.aria.current(station.name),
13
+ className: "meteo-current",
14
+ status: station.status
15
+ },
16
+ instrumentClassName: "meteo-current-instrument",
17
+ flanks: station.capabilities.gustLull ? {
18
+ lull: {
19
+ className: "meteo-current-flank meteo-current-flank-lull",
20
+ labelClassName: "meteo-microlabel",
21
+ label: words.lullLabel,
22
+ value: flankValue(reading?.windLullMps)
23
+ },
24
+ gust: {
25
+ className: "meteo-current-flank meteo-current-flank-gust",
26
+ labelClassName: "meteo-microlabel",
27
+ label: words.gustLabel,
28
+ value: flankValue(reading?.windGustMps)
29
+ }
30
+ } : null,
31
+ direction: {
32
+ className: "meteo-current-direction",
33
+ content: station.status === "unavailable" ? {
34
+ kind: "text",
35
+ text: words.reasons[station.reason]
36
+ } : blowing && reading.windDirectionDeg != null ? {
37
+ kind: "from",
38
+ labelClassName: "meteo-current-from-label",
39
+ label: words.fromLabel,
40
+ deg: reading.windDirectionDeg,
41
+ compass: compassDirection(reading.windDirectionDeg),
42
+ tail: ` ${Math.round(reading.windDirectionDeg)}°`
43
+ } : {
44
+ kind: "text",
45
+ text: calm ? words.calm : "—"
46
+ }
47
+ },
48
+ temperature: station.capabilities.temperature ? {
49
+ className: "meteo-current-temp",
50
+ text: temperatureText(reading?.temperatureC ?? null, words),
51
+ chill: reading?.windChillC != null ? {
52
+ className: "meteo-current-chill",
53
+ text: ` · ${words.feelsLikeLabel} ${temperatureValue(reading.windChillC)} ${words.degC}`
54
+ } : null
55
+ } : null,
56
+ footer: {
57
+ className: "meteo-current-footer",
58
+ observed: {
59
+ className: "meteo-current-observed",
60
+ text: reading == null ? "—" : formatTime(new Date(reading.observedAt))
61
+ }
62
+ }
63
+ };
64
+ }
65
+ //#endregion
66
+ export { currentConditionsScene };
@@ -0,0 +1,81 @@
1
+ import { isCalm, thresholdsToMps } from "../derive.js";
2
+ import { roundSpeed } from "../format.js";
3
+ import { dailyPattern, thinVanes } from "../geometry.js";
4
+ import { calmNoteText, displaySpeedScales, gapHatchPattern, gapHatchRect, gradedMeanTrace, speedGridLines, stretchedChartFrame, vaneCells, vaneGuideLines, vaneTickTexts, windRowLabels, windThresholdGuides, windZoneRects } from "./wind-plot.js";
5
+ //#region src/scene/daily-pattern.ts
6
+ const DAILY_PATTERN_CLASS = "meteo-daily-pattern";
7
+ const SYNTHETIC_EPOCH_MS = Date.parse("2000-01-01T00:00:00Z");
8
+ function dailyPatternSource(points, station) {
9
+ return {
10
+ source: points ?? (station?.status === "ok" ? station.history?.points ?? null : null) ?? [],
11
+ periodMinutes: points == null && station?.status === "ok" ? station.history?.periodMinutes ?? null : null
12
+ };
13
+ }
14
+ function dailyPatternGate(source, words) {
15
+ if (source.length === 0) return {
16
+ kind: "note",
17
+ className: `${DAILY_PATTERN_CLASS} meteo-daily-pattern-na`,
18
+ text: words.noHistory
19
+ };
20
+ return { kind: "draw" };
21
+ }
22
+ function slotPoint(slot, slotMinutes) {
23
+ return {
24
+ observedAt: new Date(SYNTHETIC_EPOCH_MS + (slot.startMinuteOfDay + slotMinutes / 2) * 6e4).toISOString(),
25
+ windAvgMps: slot.speedMps,
26
+ windGustMps: null,
27
+ windLullMps: null,
28
+ windDirectionDeg: slot.windDirectionDeg,
29
+ temperatureC: null
30
+ };
31
+ }
32
+ function formatMinuteOfDay(minuteOfDay) {
33
+ const clamped = (Math.round(minuteOfDay) % 1440 + 1440) % 1440;
34
+ return `${String(Math.floor(clamped / 60)).padStart(2, "0")}:${String(clamped % 60).padStart(2, "0")}`;
35
+ }
36
+ function dailyPatternScene(input) {
37
+ const { hatchId, periodMinutes, plotHeight, points, slotMinutes, stationName, thresholds, unit, utcOffsetMinutes, width, words } = input;
38
+ const shown = (speedMps) => roundSpeed(speedMps, unit);
39
+ const slots = dailyPattern(points, {
40
+ slotMinutes,
41
+ utcOffsetMinutes
42
+ });
43
+ const synthetic = slots.map((slot) => slotPoint(slot, slotMinutes));
44
+ const totalSamples = slots.reduce((sum, slot) => sum + slot.sampleCount, 0);
45
+ const daysSpanned = points.length < 2 ? null : (Date.parse(points[points.length - 1].observedAt) - Date.parse(points[0].observedAt)) / 864e5;
46
+ const expectedSamples = periodMinutes != null && daysSpanned != null && daysSpanned > 0 ? Math.round(slotMinutes / periodMinutes * daysSpanned * slots.length) : null;
47
+ const frame = stretchedChartFrame(width, plotHeight);
48
+ const scales = displaySpeedScales(synthetic, frame, unit);
49
+ const vanes = thinVanes(synthetic);
50
+ const calm = synthetic.every((point) => isCalm(point.windAvgMps));
51
+ const boundsMps = thresholds == null ? null : thresholdsToMps(thresholds);
52
+ const voidSpans = slots.filter((slot) => slot.sampleCount === 0).map((slot) => [scales.xAtMs(SYNTHETIC_EPOCH_MS + slot.startMinuteOfDay * 6e4), scales.xAtMs(SYNTHETIC_EPOCH_MS + (slot.startMinuteOfDay + slotMinutes) * 6e4)]);
53
+ return {
54
+ frame,
55
+ scales,
56
+ caption: {
57
+ className: "meteo-daily-pattern-caption",
58
+ text: expectedSamples != null ? words.dailyPatternCoverage(totalSamples, expectedSamples) : words.dailyPatternSamples(totalSamples)
59
+ },
60
+ svg: {
61
+ ariaLabel: stationName ? words.aria.dailyPattern(stationName) : words.aria.dailyPatternGeneric,
62
+ className: "meteo-daily-pattern-svg",
63
+ height: frame.height,
64
+ viewBox: `0 0 ${frame.width} ${frame.height}`,
65
+ width: frame.width
66
+ },
67
+ defs: { pattern: gapHatchPattern(hatchId) },
68
+ zones: windZoneRects(boundsMps, frame, scales),
69
+ grid: speedGridLines(frame, scales, shown),
70
+ thresholdGuides: windThresholdGuides(thresholds, boundsMps, unit, frame, scales, shown),
71
+ vaneGuides: vaneGuideLines(vanes, frame, scales),
72
+ gaps: voidSpans.map(([startX, endX]) => gapHatchRect(hatchId, frame, startX, startX, endX - startX)),
73
+ mean: gradedMeanTrace(synthetic, scales, boundsMps),
74
+ calmNote: calm ? calmNoteText(frame, words) : null,
75
+ rowLabels: windRowLabels(frame, words),
76
+ vanes: vaneCells(vanes, frame, scales, (vane) => slots.slice(vane.startIndex, vane.endIndex).every((slot) => slot.sampleCount === 0) ? "—" : String(shown(vane.windAvgMps))),
77
+ ticks: vaneTickTexts(vanes, frame, scales, (timeMs) => formatMinuteOfDay((timeMs - SYNTHETIC_EPOCH_MS) / 6e4))
78
+ };
79
+ }
80
+ //#endregion
81
+ export { DAILY_PATTERN_CLASS, dailyPatternGate, dailyPatternScene, dailyPatternSource };
@@ -0,0 +1,141 @@
1
+ import { isCalm, thresholdsToMps } from "../derive.js";
2
+ import { roundSpeed } from "../format.js";
3
+ import { speedBand } from "../geometry.js";
4
+ import { DIAL_CARDINALS, DIAL_COUNTERWEIGHT_RADIUS, dialNeedlePoints, dialPolar, dialScaleMaxMps, dialSpeedArcPath } from "../instruments.js";
5
+ //#region src/scene/dial.ts
6
+ function dialScene(input) {
7
+ const { bezelId, calmWord, size, station, thresholds, unit, words } = input;
8
+ const shown = (windAvgMps) => roundSpeed(windAvgMps, unit);
9
+ const unitLabel = words.speedUnits[unit];
10
+ const reading = station.status === "ok" ? station.reading : null;
11
+ const calm = reading != null && isCalm(reading.windAvgMps);
12
+ const blowing = reading != null && !calm && reading.windDirectionDeg != null;
13
+ const dialMax = dialScaleMaxMps(reading?.windAvgMps ?? null, reading?.windGustMps ?? null, unit);
14
+ const arcFraction = reading == null ? 0 : Math.min(1, Math.max(0, reading.windAvgMps) / dialMax);
15
+ const boundsMps = thresholds == null ? null : thresholdsToMps(thresholds);
16
+ const arcBand = reading != null && boundsMps != null ? speedBand(reading.windAvgMps, boundsMps) : null;
17
+ return {
18
+ svg: {
19
+ ariaLabel: station.status === "unavailable" ? `${station.name}: ${words.reasons[station.reason]}` : calm ? `${station.name}: ${words.calm}, ${shown(station.reading.windAvgMps)} ${unitLabel}` : `${station.name}: ${shown(station.reading.windAvgMps)} ${unitLabel}`,
20
+ className: station.status === "unavailable" ? "meteo-wind-dial meteo-wind-dial-unavailable" : "meteo-wind-dial",
21
+ height: size,
22
+ viewBox: `0 0 160 160`,
23
+ width: size
24
+ },
25
+ gradient: {
26
+ id: bezelId,
27
+ cx: "50%",
28
+ cy: "42%",
29
+ r: "68%",
30
+ stops: [{
31
+ className: "meteo-wind-dial-bezel-in",
32
+ offset: "55%"
33
+ }, {
34
+ className: "meteo-wind-dial-bezel-out",
35
+ offset: "100%"
36
+ }]
37
+ },
38
+ face: {
39
+ className: "meteo-wind-dial-face",
40
+ cx: 80,
41
+ cy: 80,
42
+ r: 70
43
+ },
44
+ bezel: {
45
+ className: "meteo-wind-dial-bezel",
46
+ cx: 80,
47
+ cy: 80,
48
+ fill: `url(#${bezelId})`,
49
+ r: 70
50
+ },
51
+ ring: {
52
+ className: "meteo-wind-dial-ring",
53
+ cx: 80,
54
+ cy: 80,
55
+ r: 70
56
+ },
57
+ arc: reading != null && arcFraction > 0 ? {
58
+ className: arcBand == null ? "meteo-wind-dial-arc" : `meteo-wind-dial-arc meteo-band-${arcBand}`,
59
+ d: dialSpeedArcPath(arcFraction)
60
+ } : null,
61
+ ticks: Array.from({ length: 16 }, (_, index) => {
62
+ const bearing = index * 22.5;
63
+ const cardinal = index % 4 === 0;
64
+ const [x1, y1] = dialPolar(bearing, 70);
65
+ const [x2, y2] = dialPolar(bearing, cardinal ? 58 : 64);
66
+ return {
67
+ key: bearing,
68
+ className: cardinal ? "meteo-wind-dial-tick meteo-wind-dial-tick-cardinal" : "meteo-wind-dial-tick",
69
+ x1,
70
+ x2,
71
+ y1,
72
+ y2
73
+ };
74
+ }),
75
+ letters: DIAL_CARDINALS.map(({ bearing, letter }) => {
76
+ const [x, y] = dialPolar(bearing, 46);
77
+ return {
78
+ key: letter,
79
+ className: "meteo-wind-dial-letter",
80
+ anchor: "middle",
81
+ x,
82
+ y: y + 3.5,
83
+ text: letter
84
+ };
85
+ }),
86
+ needle: blowing && reading.windDirectionDeg != null ? {
87
+ className: "meteo-wind-needle",
88
+ blade: {
89
+ className: "meteo-wind-needle-blade",
90
+ points: dialNeedlePoints(reading.windDirectionDeg)
91
+ },
92
+ counterweight: {
93
+ className: "meteo-wind-needle-counterweight",
94
+ cx: dialPolar(reading.windDirectionDeg, 46)[0],
95
+ cy: dialPolar(reading.windDirectionDeg, 46)[1],
96
+ r: DIAL_COUNTERWEIGHT_RADIUS
97
+ }
98
+ } : null,
99
+ hub: {
100
+ className: "meteo-wind-dial-hub",
101
+ cx: 80,
102
+ cy: 80,
103
+ r: 36
104
+ },
105
+ centre: reading == null ? {
106
+ kind: "reason",
107
+ text: {
108
+ className: "meteo-wind-dial-reason",
109
+ anchor: "middle",
110
+ x: 80,
111
+ y: 84,
112
+ text: words.notReporting
113
+ }
114
+ } : {
115
+ kind: "reading",
116
+ calmWord: calm && calmWord ? {
117
+ className: "meteo-wind-dial-reason",
118
+ anchor: "middle",
119
+ x: 80,
120
+ y: 58,
121
+ text: words.calm
122
+ } : null,
123
+ speed: {
124
+ className: "meteo-wind-dial-speed",
125
+ anchor: "middle",
126
+ x: 80,
127
+ y: 88,
128
+ text: String(shown(reading.windAvgMps))
129
+ },
130
+ unit: {
131
+ className: "meteo-wind-dial-unit",
132
+ anchor: "middle",
133
+ x: 80,
134
+ y: 106,
135
+ text: unitLabel
136
+ }
137
+ }
138
+ };
139
+ }
140
+ //#endregion
141
+ export { dialScene };
@@ -0,0 +1,24 @@
1
+ //#region src/scene/glyphs.ts
2
+ function windArrowSpec(deg, size = 12) {
3
+ return {
4
+ className: "meteo-wind-arrow",
5
+ height: size,
6
+ width: size,
7
+ viewBox: "0 0 16 16",
8
+ transform: `rotate(${deg + 180}deg)`,
9
+ path: {
10
+ d: "M8 1 L13 14 L8 10.6 L3 14 Z",
11
+ fill: "currentColor"
12
+ }
13
+ };
14
+ }
15
+ function freshnessBadgeSpec(status, words) {
16
+ return {
17
+ className: "meteo-freshness",
18
+ status,
19
+ dot: { className: "meteo-freshness-dot" },
20
+ text: words.freshness[status]
21
+ };
22
+ }
23
+ //#endregion
24
+ export { freshnessBadgeSpec, windArrowSpec };
@@ -0,0 +1,120 @@
1
+ import { normalizeDegrees, thresholdsToMps } from "../derive.js";
2
+ import { speedBand, windRose } from "../geometry.js";
3
+ import { ROSE_CARDINAL_LETTERS, ROSE_INTERCARDINAL_BEARINGS, ROSE_PETAL_FILL, rosePetalPath, rosePolar, roseRingArcPath } from "../instruments.js";
4
+ //#region src/scene/rose.ts
5
+ const WIND_ROSE_CLASS = "meteo-wind-rose";
6
+ function windRoseSource(points, station) {
7
+ return points ?? (station?.status === "ok" ? station.history?.points ?? null : null) ?? [];
8
+ }
9
+ function windRoseGate(source, words) {
10
+ if (source.length === 0) return {
11
+ kind: "note",
12
+ className: `${WIND_ROSE_CLASS} meteo-wind-rose-na`,
13
+ text: words.noHistory
14
+ };
15
+ return { kind: "draw" };
16
+ }
17
+ function windRoseScene(input) {
18
+ const { favorableDirections, sectorCount, source, stationName, thresholds, words } = input;
19
+ const boundsMps = thresholds == null ? null : thresholdsToMps(thresholds);
20
+ const rose = windRose(source, sectorCount);
21
+ const maxFrequency = Math.max(...rose.sectors.map((sector) => sector.frequency));
22
+ const halfWidthDeg = 360 / sectorCount / 2 * ROSE_PETAL_FILL;
23
+ const calmPercent = Math.round(rose.calmFraction * 100);
24
+ const [ringLabelX, ringLabelY] = rosePolar(135, 70);
25
+ const favorable = favorableDirections != null && favorableDirections.length > 0;
26
+ const baseLabel = stationName != null ? words.aria.rose(stationName) : words.aria.roseGeneric;
27
+ const roseLabel = favorable && favorableDirections != null ? `${baseLabel} ${words.aria.roseFavorable(favorableDirections.map((sector) => `${Math.round(normalizeDegrees(sector.fromDeg))}°–${Math.round(normalizeDegrees(sector.toDeg))}°`).join(", "))}` : baseLabel;
28
+ return {
29
+ className: WIND_ROSE_CLASS,
30
+ svg: {
31
+ ariaLabel: roseLabel,
32
+ className: "meteo-wind-rose-svg",
33
+ height: 190,
34
+ viewBox: `0 0 190 190`,
35
+ width: 190
36
+ },
37
+ gridCircles: [
38
+ 1,
39
+ 2 / 3,
40
+ 1 / 3
41
+ ].map((fraction) => ({
42
+ key: fraction,
43
+ className: "meteo-wind-rose-grid",
44
+ cx: 95,
45
+ cy: 95,
46
+ r: 70 * fraction
47
+ })),
48
+ ring: favorable && favorableDirections != null ? {
49
+ unfavorable: {
50
+ className: "meteo-wind-rose-ring-unfavorable",
51
+ cx: 95,
52
+ cy: 95,
53
+ r: 75
54
+ },
55
+ favorable: favorableDirections.map((sector) => ({
56
+ key: `${sector.fromDeg}-${sector.toDeg}`,
57
+ className: "meteo-wind-rose-ring-favorable",
58
+ d: roseRingArcPath(sector)
59
+ }))
60
+ } : null,
61
+ ticks: ROSE_INTERCARDINAL_BEARINGS.map((bearing) => {
62
+ const [x1, y1] = rosePolar(bearing, 66);
63
+ const [x2, y2] = rosePolar(bearing, 74);
64
+ return {
65
+ key: bearing,
66
+ className: "meteo-wind-rose-tick",
67
+ x1,
68
+ x2,
69
+ y1,
70
+ y2
71
+ };
72
+ }),
73
+ letters: ROSE_CARDINAL_LETTERS.map(({ bearing, letter }) => {
74
+ const [x, y] = rosePolar(bearing, 82);
75
+ return {
76
+ key: letter,
77
+ className: "meteo-wind-rose-letter",
78
+ anchor: "middle",
79
+ x,
80
+ y: y + 4,
81
+ text: letter
82
+ };
83
+ }),
84
+ petals: rose.sectors.flatMap((sector) => {
85
+ if (sector.count === 0 || maxFrequency === 0) return [];
86
+ const radius = 16 + sector.frequency / maxFrequency * 54;
87
+ const banded = boundsMps != null && sector.meanSpeedMps != null ? ` meteo-band-${speedBand(sector.meanSpeedMps, boundsMps)}` : "";
88
+ return [{
89
+ key: sector.bearingDeg,
90
+ className: `meteo-wind-rose-petal${banded}`,
91
+ d: rosePetalPath(sector.bearingDeg, radius, halfWidthDeg)
92
+ }];
93
+ }),
94
+ ringLabel: maxFrequency > 0 ? {
95
+ className: "meteo-wind-rose-ring-label",
96
+ anchor: "start",
97
+ x: ringLabelX + 3,
98
+ y: ringLabelY + 9,
99
+ text: words.percentShare(Math.round(maxFrequency * 100))
100
+ } : null,
101
+ hub: {
102
+ className: "meteo-wind-rose-hub",
103
+ cx: 95,
104
+ cy: 95,
105
+ r: 16
106
+ },
107
+ dot: {
108
+ className: "meteo-wind-rose-dot",
109
+ cx: 95,
110
+ cy: 95,
111
+ r: 3
112
+ },
113
+ calmCaption: rose.calmFraction > 0 ? {
114
+ className: "meteo-wind-rose-calm",
115
+ text: words.percentCalm(calmPercent)
116
+ } : null
117
+ };
118
+ }
119
+ //#endregion
120
+ export { WIND_ROSE_CLASS, windRoseGate, windRoseScene, windRoseSource };
@@ -0,0 +1,73 @@
1
+ import { thresholdsToMps } from "../derive.js";
2
+ import { speedBand } from "../geometry.js";
3
+ import { bandStrips, historyRuns, sparklineScale } from "../instruments.js";
4
+ //#region src/scene/sparkline.ts
5
+ const coordinate = (x, y) => `${x.toFixed(1)},${y.toFixed(1)}`;
6
+ function sparklineScene(input) {
7
+ const { height, showBand, station, thresholds, width, words } = input;
8
+ const label = words.aria.sparkline(station.name);
9
+ const history = station.status === "ok" ? station.history : null;
10
+ if (!(station.capabilities.history && history != null && history.points.length >= 2) || history == null) return {
11
+ kind: "placeholder",
12
+ ariaLabel: label,
13
+ className: "meteo-sparkline meteo-sparkline-na",
14
+ height,
15
+ text: "—",
16
+ width
17
+ };
18
+ const points = history.points;
19
+ const { xAt, yAt } = sparklineScale(points, width, height);
20
+ const runs = historyRuns(points, history.periodMinutes);
21
+ const strips = showBand ? bandStrips(runs) : [];
22
+ const boundsMps = thresholds == null ? null : thresholdsToMps(thresholds);
23
+ const trace = boundsMps == null ? runs.map((segment) => segment.points.length === 1 ? {
24
+ kind: "dot",
25
+ key: segment.startedAt,
26
+ className: "meteo-sparkline-dot",
27
+ cx: xAt(Date.parse(segment.points[0].observedAt)),
28
+ cy: yAt(segment.points[0].windAvgMps),
29
+ r: 1.5
30
+ } : {
31
+ kind: "polyline",
32
+ key: segment.startedAt,
33
+ className: "meteo-sparkline-line",
34
+ points: segment.points.map((point) => coordinate(xAt(Date.parse(point.observedAt)), yAt(point.windAvgMps))).join(" ")
35
+ }) : runs.flatMap((segment) => segment.points.length === 1 ? [{
36
+ kind: "dot",
37
+ key: segment.startedAt,
38
+ className: `meteo-sparkline-dot meteo-band-${speedBand(segment.points[0].windAvgMps, boundsMps)}`,
39
+ cx: xAt(Date.parse(segment.points[0].observedAt)),
40
+ cy: yAt(segment.points[0].windAvgMps),
41
+ r: 1.5
42
+ }] : segment.points.slice(1).map((point, index) => {
43
+ const previous = segment.points[index];
44
+ const band = speedBand((previous.windAvgMps + point.windAvgMps) / 2, boundsMps);
45
+ return {
46
+ kind: "segment",
47
+ key: point.observedAt,
48
+ className: `meteo-sparkline-segment meteo-band-${band}`,
49
+ x1: xAt(Date.parse(previous.observedAt)),
50
+ x2: xAt(Date.parse(point.observedAt)),
51
+ y1: yAt(previous.windAvgMps),
52
+ y2: yAt(point.windAvgMps)
53
+ };
54
+ }));
55
+ return {
56
+ kind: "draw",
57
+ svg: {
58
+ ariaLabel: label,
59
+ className: "meteo-sparkline",
60
+ height,
61
+ viewBox: `0 0 ${width} ${height}`,
62
+ width
63
+ },
64
+ bands: strips.filter((strip) => strip.points.length >= 2).map((strip) => ({
65
+ key: strip.startedAt,
66
+ className: "meteo-sparkline-band",
67
+ points: [...strip.points.map((point) => coordinate(xAt(Date.parse(point.observedAt)), yAt(point.windGustMps))), ...[...strip.points].reverse().map((point) => coordinate(xAt(Date.parse(point.observedAt)), yAt(point.windLullMps)))].join(" ")
68
+ })),
69
+ trace
70
+ };
71
+ }
72
+ //#endregion
73
+ export { sparklineScene };
@@ -0,0 +1,63 @@
1
+ import { optionalSpeed, roundSpeed, temperatureText } from "../format.js";
2
+ //#region src/scene/strip.ts
3
+ function stationStripScene(input) {
4
+ const { formatTime, station, unit, words } = input;
5
+ const root = {
6
+ ariaLabel: words.aria.strip(station.name),
7
+ className: "meteo-strip",
8
+ status: station.status
9
+ };
10
+ if (station.status !== "ok") return {
11
+ root,
12
+ stationClassName: "meteo-strip-station",
13
+ body: {
14
+ kind: "reason",
15
+ className: "meteo-strip-reason",
16
+ text: words.reasons[station.reason]
17
+ }
18
+ };
19
+ return {
20
+ root,
21
+ stationClassName: "meteo-strip-station",
22
+ body: {
23
+ kind: "reading",
24
+ wind: {
25
+ className: "meteo-strip-wind",
26
+ value: String(roundSpeed(station.reading.windAvgMps, unit)),
27
+ unitLabel: words.speedUnits[unit]
28
+ },
29
+ gustLull: station.capabilities.gustLull ? {
30
+ lull: {
31
+ className: "meteo-strip-lull",
32
+ labelClassName: "meteo-microlabel",
33
+ label: words.lullLabel,
34
+ value: optionalSpeed(station.reading.windLullMps, unit)
35
+ },
36
+ gust: {
37
+ className: "meteo-strip-gust",
38
+ labelClassName: "meteo-microlabel",
39
+ label: words.gustLabel,
40
+ value: optionalSpeed(station.reading.windGustMps, unit)
41
+ }
42
+ } : null,
43
+ from: {
44
+ className: "meteo-strip-from",
45
+ windAvgMps: station.reading.windAvgMps,
46
+ windDirectionDeg: station.reading.windDirectionDeg
47
+ },
48
+ temperature: station.capabilities.temperature ? {
49
+ className: "meteo-strip-temp",
50
+ text: temperatureText(station.reading.temperatureC, words)
51
+ } : null,
52
+ updated: {
53
+ className: "meteo-strip-updated",
54
+ time: {
55
+ className: "meteo-strip-time",
56
+ text: formatTime(new Date(station.reading.observedAt))
57
+ }
58
+ }
59
+ }
60
+ };
61
+ }
62
+ //#endregion
63
+ export { stationStripScene };
@@ -0,0 +1,76 @@
1
+ import { optionalSpeed, roundSpeed, temperatureText } from "../format.js";
2
+ //#region src/scene/table.ts
3
+ function stationTableScene(stations, words) {
4
+ return {
5
+ root: {
6
+ ariaLabel: words.aria.table(stations.length),
7
+ className: "meteo-station-table"
8
+ },
9
+ head: {
10
+ className: "meteo-station-table-row meteo-station-table-head meteo-microlabel",
11
+ columns: [
12
+ words.table.station,
13
+ words.table.wind,
14
+ words.table.lull,
15
+ words.table.gust,
16
+ words.table.from,
17
+ words.table.temp,
18
+ words.table.updated
19
+ ]
20
+ },
21
+ bodyClassName: "meteo-station-table-body"
22
+ };
23
+ }
24
+ function stationTableRowScene(input) {
25
+ const { formatTime, station, unit, words } = input;
26
+ const base = {
27
+ className: "meteo-station-table-row",
28
+ status: station.status,
29
+ stationCellClassName: "meteo-station-table-station"
30
+ };
31
+ if (station.status !== "ok") return {
32
+ ...base,
33
+ cells: {
34
+ kind: "reason",
35
+ className: "meteo-station-table-reason",
36
+ text: words.reasons[station.reason]
37
+ }
38
+ };
39
+ return {
40
+ ...base,
41
+ cells: {
42
+ kind: "reading",
43
+ wind: {
44
+ className: "meteo-station-table-wind",
45
+ value: String(roundSpeed(station.reading.windAvgMps, unit)),
46
+ unitLabel: words.speedUnits[unit]
47
+ },
48
+ lull: {
49
+ className: "meteo-station-table-lull",
50
+ value: optionalSpeed(station.reading.windLullMps, unit)
51
+ },
52
+ gust: {
53
+ className: "meteo-station-table-gust",
54
+ value: optionalSpeed(station.reading.windGustMps, unit)
55
+ },
56
+ from: {
57
+ className: "meteo-station-table-from",
58
+ windAvgMps: station.reading.windAvgMps,
59
+ windDirectionDeg: station.reading.windDirectionDeg
60
+ },
61
+ temperature: {
62
+ className: "meteo-station-table-temp",
63
+ value: temperatureText(station.reading.temperatureC, words)
64
+ },
65
+ updated: {
66
+ className: "meteo-station-table-updated",
67
+ time: {
68
+ className: "meteo-station-table-time",
69
+ text: formatTime(new Date(station.reading.observedAt))
70
+ }
71
+ }
72
+ }
73
+ };
74
+ }
75
+ //#endregion
76
+ export { stationTableRowScene, stationTableScene };