@azohra/meteo.station 0.3.0 → 0.4.2

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 (139) hide show
  1. package/README.md +2 -2
  2. package/dist/client/climatology.d.ts +27 -0
  3. package/dist/client/climatology.js +83 -0
  4. package/dist/client/history.d.ts +53 -0
  5. package/dist/client/history.js +114 -0
  6. package/dist/client/index.d.ts +3 -1
  7. package/dist/client/index.js +3 -1
  8. package/dist/client/live.js +15 -0
  9. package/dist/climatology.d.ts +61 -0
  10. package/dist/climatology.js +208 -0
  11. package/dist/connectivity.d.ts +46 -0
  12. package/dist/connectivity.js +44 -0
  13. package/dist/contract-climatology.d.ts +69 -0
  14. package/dist/contract-climatology.js +50 -0
  15. package/dist/contract.d.ts +234 -1
  16. package/dist/contract.js +52 -4
  17. package/dist/derive.d.ts +23 -1
  18. package/dist/derive.js +43 -4
  19. package/dist/display.d.ts +4 -0
  20. package/dist/display.js +2 -1
  21. package/dist/elements/elements/AirExtremesElement.d.ts +8 -0
  22. package/dist/elements/elements/AirExtremesElement.js +33 -0
  23. package/dist/elements/elements/ClimatologyDailyPatternElement.d.ts +15 -0
  24. package/dist/elements/elements/ClimatologyDailyPatternElement.js +84 -0
  25. package/dist/elements/elements/ClimatologyRoseElement.d.ts +14 -0
  26. package/dist/elements/elements/ClimatologyRoseElement.js +51 -0
  27. package/dist/elements/elements/CompassFanElement.d.ts +14 -0
  28. package/dist/elements/elements/CompassFanElement.js +92 -0
  29. package/dist/elements/elements/DailyPatternElement.d.ts +1 -0
  30. package/dist/elements/elements/DailyPatternElement.js +20 -12
  31. package/dist/elements/elements/DialElement.js +14 -3
  32. package/dist/elements/elements/FavorableShareElement.d.ts +14 -0
  33. package/dist/elements/elements/FavorableShareElement.js +47 -0
  34. package/dist/elements/elements/RecentSummariesElement.d.ts +14 -0
  35. package/dist/elements/elements/RecentSummariesElement.js +54 -0
  36. package/dist/elements/elements/StationFeedElement.d.ts +3 -0
  37. package/dist/elements/elements/StationFeedElement.js +13 -2
  38. package/dist/elements/elements/WindHistoryChartElement.js +16 -3
  39. package/dist/elements/elements/WindRoseElement.d.ts +1 -3
  40. package/dist/elements/elements/WindRoseElement.js +60 -62
  41. package/dist/elements/elements/atoms.js +3 -3
  42. package/dist/elements/index.d.ts +13 -1
  43. package/dist/elements/index.js +15 -3
  44. package/dist/elements/lib/ambient.d.ts +2 -0
  45. package/dist/elements/lib/attributes.js +24 -1
  46. package/dist/elements/lib/base.d.ts +3 -0
  47. package/dist/elements/lib/base.js +14 -2
  48. package/dist/endpoints.d.ts +7 -1
  49. package/dist/endpoints.js +13 -1
  50. package/dist/geometry.d.ts +22 -3
  51. package/dist/geometry.js +41 -5
  52. package/dist/index.d.ts +9 -6
  53. package/dist/index.js +9 -6
  54. package/dist/instruments.d.ts +7 -5
  55. package/dist/instruments.js +20 -7
  56. package/dist/merge-current.js +2 -1
  57. package/dist/react/components/AirExtremes.d.ts +16 -0
  58. package/dist/react/components/AirExtremes.js +38 -0
  59. package/dist/react/components/ClimatologyDailyPattern.d.ts +20 -0
  60. package/dist/react/components/ClimatologyDailyPattern.js +59 -0
  61. package/dist/react/components/ClimatologyRose.d.ts +18 -0
  62. package/dist/react/components/ClimatologyRose.js +45 -0
  63. package/dist/react/components/CompassFan.d.ts +17 -0
  64. package/dist/react/components/CompassFan.js +93 -0
  65. package/dist/react/components/DailyPattern.d.ts +4 -1
  66. package/dist/react/components/DailyPattern.js +13 -6
  67. package/dist/react/components/Dial.d.ts +3 -1
  68. package/dist/react/components/Dial.js +13 -2
  69. package/dist/react/components/FavorableShare.d.ts +14 -0
  70. package/dist/react/components/FavorableShare.js +43 -0
  71. package/dist/react/components/RecentSummaries.d.ts +19 -0
  72. package/dist/react/components/RecentSummaries.js +65 -0
  73. package/dist/react/components/StationFeedProvider.d.ts +4 -1
  74. package/dist/react/components/StationFeedProvider.js +5 -3
  75. package/dist/react/components/WindHistoryChart.d.ts +6 -1
  76. package/dist/react/components/WindHistoryChart.js +18 -3
  77. package/dist/react/components/WindRose.d.ts +4 -2
  78. package/dist/react/components/WindRose.js +80 -71
  79. package/dist/react/components/WindSampleStrip.d.ts +3 -1
  80. package/dist/react/components/WindSampleStrip.js +6 -3
  81. package/dist/react/components/atoms.d.ts +4 -1
  82. package/dist/react/components/atoms.js +6 -3
  83. package/dist/react/hooks/useStationClimatology.d.ts +18 -0
  84. package/dist/react/hooks/useStationClimatology.js +25 -0
  85. package/dist/react/index.d.ts +10 -3
  86. package/dist/react/index.js +9 -2
  87. package/dist/scene/air-extremes.d.ts +2 -0
  88. package/dist/scene/air-extremes.js +42 -0
  89. package/dist/scene/atoms.d.ts +2 -1
  90. package/dist/scene/atoms.js +6 -4
  91. package/dist/scene/climatology-pattern.d.ts +6 -0
  92. package/dist/scene/climatology-pattern.js +35 -0
  93. package/dist/scene/climatology-rose.d.ts +5 -0
  94. package/dist/scene/climatology-rose.js +49 -0
  95. package/dist/scene/compass-fan.d.ts +3 -0
  96. package/dist/scene/compass-fan.js +115 -0
  97. package/dist/scene/daily-pattern.d.ts +1 -0
  98. package/dist/scene/daily-pattern.js +20 -6
  99. package/dist/scene/dial.d.ts +1 -0
  100. package/dist/scene/dial.js +16 -3
  101. package/dist/scene/favorable-share.d.ts +3 -0
  102. package/dist/scene/favorable-share.js +41 -0
  103. package/dist/scene/index.d.ts +9 -3
  104. package/dist/scene/recent-summaries.d.ts +4 -0
  105. package/dist/scene/recent-summaries.js +75 -0
  106. package/dist/scene/rose.d.ts +2 -1
  107. package/dist/scene/rose.js +18 -3
  108. package/dist/scene/sample-strip.d.ts +1 -0
  109. package/dist/scene/sample-strip.js +1 -1
  110. package/dist/scene/wind-history.d.ts +1 -0
  111. package/dist/scene/wind-history.js +4 -3
  112. package/dist/scene/wind-plot.d.ts +1 -0
  113. package/dist/scene/wind-plot.js +30 -3
  114. package/dist/server/adapter.d.ts +2 -1
  115. package/dist/server/adapter.js +2 -1
  116. package/dist/server/adapters/windnerd-climatology.d.ts +33 -0
  117. package/dist/server/adapters/windnerd-climatology.js +81 -0
  118. package/dist/server/adapters/windnerd-live.js +21 -13
  119. package/dist/server/adapters/windnerd.d.ts +31 -4
  120. package/dist/server/adapters/windnerd.js +197 -19
  121. package/dist/server/feed.d.ts +44 -2
  122. package/dist/server/feed.js +63 -2
  123. package/dist/server/handler.d.ts +11 -1
  124. package/dist/server/handler.js +83 -2
  125. package/dist/server/hologram.d.ts +22 -0
  126. package/dist/server/hologram.js +113 -0
  127. package/dist/server/index.d.ts +5 -3
  128. package/dist/server/index.js +5 -3
  129. package/dist/strings.d.ts +12 -0
  130. package/dist/strings.js +12 -0
  131. package/package.json +2 -2
  132. package/schema/example-climatology.json +86 -0
  133. package/schema/example-history.json +38 -0
  134. package/schema/stationclimatology.schema.json +195 -0
  135. package/schema/stationcurrent.schema.json +173 -0
  136. package/schema/stationfeed.schema.json +173 -0
  137. package/schema/stationhistory.schema.json +186 -0
  138. package/schema/stationlive.schema.json +202 -0
  139. package/styles.css +215 -0
package/dist/contract.js CHANGED
@@ -43,12 +43,22 @@ const historyPointSchema = z.object({
43
43
  windLullMps: speedMps.nullable(),
44
44
  windDirectionDeg: windDirectionDeg.nullable().describe("Degrees FROM; null exactly when the period was calm (below 0.5 m/s)."),
45
45
  temperatureC: z.number().finite().nullable(),
46
- seaLevelPressureHpa: z.number().finite().positive().nullish()
46
+ seaLevelPressureHpa: z.number().finite().positive().nullish(),
47
+ windVectorAvgMps: speedMps.nullish().describe("Vector-mean m/s over the period — the honest input for further vector re-aggregation; at most windAvgMps. Absent or null reads as 'not published here'."),
48
+ temperatureMinC: z.number().finite().nullish(),
49
+ temperatureMaxC: z.number().finite().nullish(),
50
+ seaLevelPressureMinHpa: z.number().finite().positive().nullish(),
51
+ seaLevelPressureMaxHpa: z.number().finite().positive().nullish()
47
52
  }).meta({ id: "HistoryPoint" });
48
53
  const historySchema = z.object({
49
54
  periodMinutes: z.number().finite().positive().describe("Minutes each point covers. Wind run, vane thinning, and dropout detection are functions of it."),
50
55
  points: z.array(historyPointSchema).describe("A dropout is an ABSENT record, never a zeroed one — gaps carry no points.")
51
56
  }).meta({ id: "History" });
57
+ const recentSummarySchema = z.object({
58
+ windowMinutes: z.number().finite().positive().describe("The rolling window this summarises."),
59
+ stepMinutes: z.number().finite().positive().describe("Minutes each point covers."),
60
+ points: z.array(historyPointSchema).describe("Oldest first, one per filled step; a step the source left empty is ABSENT.")
61
+ }).meta({ id: "RecentSummary" });
52
62
  const liveSampleSchema = z.object({
53
63
  observedAt: isoTime,
54
64
  windMps: speedMps.describe("Instantaneous m/s — a single anemometer sample, not a period mean."),
@@ -64,8 +74,13 @@ const capabilitiesSchema = z.object({
64
74
  conditions: z.boolean(),
65
75
  history: z.boolean(),
66
76
  live: z.boolean().nullish().describe("The station has a live sample stream; absent or null reads as false."),
67
- battery: z.boolean().nullish().describe("The station reports battery telemetry; absent or null reads as false.")
77
+ battery: z.boolean().nullish().describe("The station reports battery telemetry; absent or null reads as false."),
78
+ recentSummaries: z.boolean().nullish().describe("The source maintains pre-digested rolling step summaries; absent or null reads as false.")
68
79
  }).describe("Declared from what the hardware carries, never inferred from data. Capabilities gate client UI structure; a dark sensor keeps its structure and reports null.").meta({ id: "StationCapabilities" });
80
+ const directionArcSchema = z.object({
81
+ fromDeg: z.number().finite().describe("Degrees FROM, clockwise from north."),
82
+ toDeg: z.number().finite().describe("Degrees FROM; fromDeg > toDeg wraps through north, boundaries inclusive.")
83
+ }).describe("One arc of favorable FROM bearings — core's DirectionArc shape on the wire.").meta({ id: "DirectionArc" });
69
84
  const stationMetaShape = {
70
85
  id: z.string().min(1),
71
86
  name: z.string().min(1),
@@ -75,6 +90,8 @@ const stationMetaShape = {
75
90
  longitude: z.number().finite().min(-180).lt(180).nullable(),
76
91
  timeZone: z.string().min(1).nullable(),
77
92
  elevationM: z.number().finite().nullable(),
93
+ declaredFavorableDirections: z.array(directionArcSchema).nullish(),
94
+ broadcastDelaySeconds: z.number().finite().min(0).nullish().describe("The source's own live-playback delay, seconds; absent or null when the vendor states none."),
78
95
  capabilities: capabilitiesSchema,
79
96
  samplingWindowSeconds: z.number().finite().positive().nullable(),
80
97
  recommendedPollSeconds: z.number().finite().positive()
@@ -86,7 +103,8 @@ const stationSchema = z.discriminatedUnion("status", [z.object({
86
103
  reading: readingSchema,
87
104
  history: historySchema.nullable(),
88
105
  telemetry: telemetrySchema.nullish(),
89
- samples: liveSamplesSchema.nullish()
106
+ samples: liveSamplesSchema.nullish(),
107
+ recentSummaries: z.array(recentSummarySchema).nullish()
90
108
  }), z.object({
91
109
  ...stationMetaShape,
92
110
  status: z.literal("unavailable"),
@@ -105,6 +123,23 @@ const stationCurrentSchema = z.object({
105
123
  servedAt: isoTime,
106
124
  station: stationSchema
107
125
  });
126
+ const stationHistorySchema = z.object({
127
+ schemaVersion: z.literal(2),
128
+ servedAt: isoTime,
129
+ stationId: z.string().min(1),
130
+ history: historySchema.describe("The window's records at the served resolution; periodMinutes echoes what the source actually supplied, which may differ from the request when the vendor snapped it.")
131
+ }).meta({ id: "StationHistory" });
132
+ function parseStationHistory(value) {
133
+ const result = stationHistorySchema.safeParse(value);
134
+ return result.success ? result.data : null;
135
+ }
136
+ function parseStationHistoryJson(text) {
137
+ try {
138
+ return parseStationHistory(JSON.parse(text));
139
+ } catch {
140
+ return null;
141
+ }
142
+ }
108
143
  const stationLiveFrameSchema = z.discriminatedUnion("type", [
109
144
  z.object({
110
145
  type: z.literal("init"),
@@ -124,6 +159,12 @@ const stationLiveFrameSchema = z.discriminatedUnion("type", [
124
159
  reading: readingSchema,
125
160
  telemetry: telemetrySchema.nullable()
126
161
  }),
162
+ z.object({
163
+ type: z.literal("summaries"),
164
+ stationId: z.string().min(1),
165
+ servedAt: isoTime,
166
+ summaries: z.array(recentSummarySchema)
167
+ }),
127
168
  z.object({
128
169
  type: z.literal("ping"),
129
170
  servedAt: isoTime
@@ -193,5 +234,12 @@ function unavailableStation(meta, reason) {
193
234
  history: null
194
235
  };
195
236
  }
237
+ /** The source's declared favorable sectors, or null when it declares nothing
238
+ * knowable. Data, not judgment: no component reads the meta field itself —
239
+ * a consumer opts in, e.g.
240
+ * `favorableDirections={declaredFavorableDirections(station) ?? ownArcs}`. */
241
+ function declaredFavorableDirections(station) {
242
+ return station.declaredFavorableDirections ?? null;
243
+ }
196
244
  //#endregion
197
- export { STATION_SCHEMA_VERSION, UNAVAILABLE_REASONS, airConditionsSchema, capabilitiesSchema, emptyConditions, historyPointSchema, historySchema, liveSampleSchema, liveSamplesSchema, parseStationCurrent, parseStationCurrentJson, parseStationFeed, parseStationFeedJson, parseStationLiveFrame, parseStationLiveFrameJson, readingSchema, stationCurrentSchema, stationFeedSchema, stationLiveFrameSchema, stationMetaSchema, stationSchema, telemetrySchema, unavailableStation };
245
+ export { STATION_SCHEMA_VERSION, UNAVAILABLE_REASONS, airConditionsSchema, capabilitiesSchema, declaredFavorableDirections, directionArcSchema, emptyConditions, historyPointSchema, historySchema, liveSampleSchema, liveSamplesSchema, parseStationCurrent, parseStationCurrentJson, parseStationFeed, parseStationFeedJson, parseStationHistory, parseStationHistoryJson, parseStationLiveFrame, parseStationLiveFrameJson, readingSchema, recentSummarySchema, stationCurrentSchema, stationFeedSchema, stationHistorySchema, stationLiveFrameSchema, stationMetaSchema, stationSchema, telemetrySchema, unavailableStation };
package/dist/derive.d.ts CHANGED
@@ -31,6 +31,16 @@ type PeriodSummary = {
31
31
  declare function periodSummary(history: History): PeriodSummary | null;
32
32
  declare function seaLevelPressureHpa(stationPressureHpa: number, elevationM: number, temperatureC?: number | null): number;
33
33
  type PressureTendency = "falling" | "rising" | "steady";
34
+ /** The signed sea-level pressure change over the trailing window, hPa —
35
+ * the number behind the tendency word. The reference is the carried point
36
+ * nearest the window's start, and a record covering under 60% of the
37
+ * window returns null rather than a delta over a shorter span. */
38
+ declare function pressureDeltaHpa(points: ReadonlyArray<{
39
+ observedAt: string;
40
+ seaLevelPressureHpa?: number | null;
41
+ }>, { windowHours }?: {
42
+ windowHours?: number;
43
+ }): number | null;
34
44
  declare function pressureTendency(points: ReadonlyArray<{
35
45
  observedAt: string;
36
46
  seaLevelPressureHpa?: number | null;
@@ -38,6 +48,18 @@ declare function pressureTendency(points: ReadonlyArray<{
38
48
  windowHours?: number;
39
49
  thresholdHpa?: number;
40
50
  }): PressureTendency | null;
51
+ /** The lowest temperature of the most recent completed night — the previous
52
+ * sunset to the latest sunrise, from real astronomy. Null without
53
+ * coordinates (never a guessed night), under a polar sky, or when no
54
+ * carried temperature falls inside the window. */
55
+ declare function lastNightLowC(points: ReadonlyArray<{
56
+ observedAt: string;
57
+ temperatureC?: number | null;
58
+ }>, latitude: number | null, longitude: number | null, nowMs: number): {
59
+ lowC: number;
60
+ fromMs: number;
61
+ toMs: number;
62
+ } | null;
41
63
  type FreshnessStatus = "live" | "aging" | "stale";
42
64
  type FreshnessThresholds = {
43
65
  currentForMs: number;
@@ -51,4 +73,4 @@ declare function freshness(input: {
51
73
  nowMs: number;
52
74
  }, thresholds?: FreshnessThresholds): FreshnessStatus;
53
75
  //#endregion
54
- export { CALM_THRESHOLD_MPS, COMPASS_POINTS, CompassPoint, FreshnessStatus, FreshnessThresholds, PeriodSummary, PressureTendency, SPEED_UNITS, SpeedThresholds, SpeedUnit, compassDirection, freshness, isCalm, normalizeDegrees, periodSummary, pressureTendency, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps };
76
+ export { CALM_THRESHOLD_MPS, COMPASS_POINTS, CompassPoint, FreshnessStatus, FreshnessThresholds, PeriodSummary, PressureTendency, SPEED_UNITS, SpeedThresholds, SpeedUnit, compassDirection, freshness, isCalm, lastNightLowC, normalizeDegrees, periodSummary, pressureDeltaHpa, pressureTendency, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps };
package/dist/derive.js CHANGED
@@ -1,4 +1,4 @@
1
- import { KMH_PER_MPS, degreesToRadians, normalizeDegrees } from "@azohra/meteo.core";
1
+ import { KMH_PER_MPS, degreesToRadians, normalizeDegrees, solarEventsForDate } from "@azohra/meteo.core";
2
2
  //#region src/derive.ts
3
3
  const CALM_THRESHOLD_MPS = .5;
4
4
  function isCalm(speedMps) {
@@ -97,7 +97,11 @@ function seaLevelPressureHpa(stationPressureHpa, elevationM, temperatureC = 15)
97
97
  const factor = 1 - .0065 * elevationM / (temperature + .0065 * elevationM + 273.15);
98
98
  return stationPressureHpa * Math.pow(factor, -5.257);
99
99
  }
100
- function pressureTendency(points, { windowHours = 3, thresholdHpa = 1.5 } = {}) {
100
+ /** The signed sea-level pressure change over the trailing window, hPa —
101
+ * the number behind the tendency word. The reference is the carried point
102
+ * nearest the window's start, and a record covering under 60% of the
103
+ * window returns null rather than a delta over a shorter span. */
104
+ function pressureDeltaHpa(points, { windowHours = 3 } = {}) {
101
105
  const carrying = points.filter((point) => point.seaLevelPressureHpa != null);
102
106
  const last = carrying[carrying.length - 1];
103
107
  if (!last) return null;
@@ -105,11 +109,46 @@ function pressureTendency(points, { windowHours = 3, thresholdHpa = 1.5 } = {})
105
109
  let reference = null;
106
110
  for (const point of carrying) if (reference == null || Math.abs(Date.parse(point.observedAt) - targetMs) < Math.abs(Date.parse(reference.observedAt) - targetMs)) reference = point;
107
111
  if (reference == null || Date.parse(last.observedAt) - Date.parse(reference.observedAt) < windowHours * 36e5 * .6) return null;
108
- const delta = last.seaLevelPressureHpa - reference.seaLevelPressureHpa;
112
+ return last.seaLevelPressureHpa - reference.seaLevelPressureHpa;
113
+ }
114
+ function pressureTendency(points, { windowHours = 3, thresholdHpa = 1.5 } = {}) {
115
+ const delta = pressureDeltaHpa(points, { windowHours });
116
+ if (delta == null) return null;
109
117
  if (delta >= thresholdHpa) return "rising";
110
118
  if (delta <= -thresholdHpa) return "falling";
111
119
  return "steady";
112
120
  }
121
+ /** The lowest temperature of the most recent completed night — the previous
122
+ * sunset to the latest sunrise, from real astronomy. Null without
123
+ * coordinates (never a guessed night), under a polar sky, or when no
124
+ * carried temperature falls inside the window. */
125
+ function lastNightLowC(points, latitude, longitude, nowMs) {
126
+ if (latitude == null || longitude == null) return null;
127
+ const dayMs = 864e5;
128
+ const dateKey = (ms) => new Date(ms).toISOString().slice(0, 10);
129
+ for (let dayStart = Math.floor(nowMs / dayMs) * dayMs; dayStart >= nowMs - 3 * dayMs; dayStart -= dayMs) {
130
+ const today = solarEventsForDate(dateKey(dayStart), latitude, longitude);
131
+ if (today == null) return null;
132
+ if (today.sunrise.getTime() > nowMs) continue;
133
+ const yesterday = solarEventsForDate(dateKey(dayStart - dayMs), latitude, longitude);
134
+ if (yesterday == null) return null;
135
+ const fromMs = yesterday.sunset.getTime();
136
+ const toMs = today.sunrise.getTime();
137
+ let lowC = null;
138
+ for (const point of points) {
139
+ if (point.temperatureC == null) continue;
140
+ const observedMs = Date.parse(point.observedAt);
141
+ if (observedMs < fromMs || observedMs > toMs) continue;
142
+ lowC = lowC == null ? point.temperatureC : Math.min(lowC, point.temperatureC);
143
+ }
144
+ return lowC == null ? null : {
145
+ lowC,
146
+ fromMs,
147
+ toMs
148
+ };
149
+ }
150
+ return null;
151
+ }
113
152
  const DEFAULT_FRESHNESS_THRESHOLDS = {
114
153
  currentForMs: 10 * 6e4,
115
154
  staleAfterMs: 45 * 6e4
@@ -131,4 +170,4 @@ function freshness(input, thresholds = DEFAULT_FRESHNESS_THRESHOLDS) {
131
170
  return "stale";
132
171
  }
133
172
  //#endregion
134
- export { CALM_THRESHOLD_MPS, COMPASS_POINTS, DEFAULT_FRESHNESS_THRESHOLDS, KMH_PER_MPS, SPEED_UNITS, compassDirection, freshness, isCalm, normalizeDegrees, periodSummary, pressureTendency, radians, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps };
173
+ export { CALM_THRESHOLD_MPS, COMPASS_POINTS, DEFAULT_FRESHNESS_THRESHOLDS, KMH_PER_MPS, SPEED_UNITS, compassDirection, freshness, isCalm, lastNightLowC, normalizeDegrees, periodSummary, pressureDeltaHpa, pressureTendency, radians, seaLevelPressureHpa, speedFromMps, speedToMps, speedUnitLabel, stationFreshnessThresholds, thresholdsToMps };
package/dist/display.d.ts CHANGED
@@ -1,18 +1,21 @@
1
1
  import { Station, StationFeed } from "./contract.js";
2
2
  import { SpeedThresholds, SpeedUnit } from "./derive.js";
3
3
  import { FormatTime, StationStringOverrides, StationStrings } from "./strings.js";
4
+ import { FavorableDirection } from "./instruments.js";
4
5
  //#region src/display.d.ts
5
6
  type DisplayDefaults = {
6
7
  strings?: StationStringOverrides | undefined;
7
8
  unit?: SpeedUnit | undefined;
8
9
  formatTime?: FormatTime | undefined;
9
10
  thresholds?: SpeedThresholds | undefined;
11
+ favorableDirections?: FavorableDirection[] | undefined;
10
12
  };
11
13
  type DisplayProps = {
12
14
  strings?: StationStringOverrides | undefined;
13
15
  unit?: SpeedUnit | undefined;
14
16
  formatTime?: FormatTime | undefined;
15
17
  thresholds?: SpeedThresholds | null | undefined;
18
+ favorableDirections?: FavorableDirection[] | null | undefined;
16
19
  };
17
20
  type ResolvedDisplay = {
18
21
  strings: StationStringOverrides | undefined;
@@ -20,6 +23,7 @@ type ResolvedDisplay = {
20
23
  unit: SpeedUnit;
21
24
  formatTime: FormatTime;
22
25
  thresholds: SpeedThresholds | undefined;
26
+ favorableDirections: FavorableDirection[] | undefined;
23
27
  };
24
28
  declare function resolveDisplay(defaults: DisplayDefaults | null | undefined, props: DisplayProps): ResolvedDisplay;
25
29
  declare function resolveStation(feed: StationFeed | null | undefined, stationId: string | undefined): Station | null;
package/dist/display.js CHANGED
@@ -7,7 +7,8 @@ function resolveDisplay(defaults, props) {
7
7
  words: resolveStrings(strings),
8
8
  unit: props.unit ?? defaults?.unit ?? "kmh",
9
9
  formatTime: props.formatTime ?? defaults?.formatTime ?? defaultFormatTime,
10
- thresholds: props.thresholds === void 0 ? defaults?.thresholds : props.thresholds ?? void 0
10
+ thresholds: props.thresholds === void 0 ? defaults?.thresholds : props.thresholds ?? void 0,
11
+ favorableDirections: props.favorableDirections === void 0 ? defaults?.favorableDirections : props.favorableDirections ?? void 0
11
12
  };
12
13
  }
13
14
  function resolveStation(feed, stationId) {
@@ -0,0 +1,8 @@
1
+ import { MeteoStationElement } from "../lib/base.js";
2
+ //#region src/elements/elements/AirExtremesElement.d.ts
3
+ declare class AirExtremesElement extends MeteoStationElement {
4
+ static readonly observedAttributes: string[];
5
+ protected render(): void;
6
+ }
7
+ //#endregion
8
+ export { AirExtremesElement };
@@ -0,0 +1,33 @@
1
+ import { resolveStation } from "../../display.js";
2
+ import { airExtremesGate, airExtremesScene } from "../../scene/air-extremes.js";
3
+ import { MeteoStationElement } from "../lib/base.js";
4
+ import { h } from "../lib/h.js";
5
+ //#region src/elements/elements/AirExtremesElement.ts
6
+ var AirExtremesElement = class extends MeteoStationElement {
7
+ static observedAttributes = ["now-ms", "station-id"];
8
+ render() {
9
+ const station = this.station ?? resolveStation(this.ambient()?.feed ?? null, this.getAttribute("station-id") ?? void 0) ?? void 0;
10
+ const { words } = this.display();
11
+ const gate = airExtremesGate(station);
12
+ if (gate.kind === "hidden") {
13
+ this.replaceChildren();
14
+ return;
15
+ }
16
+ const nowAttribute = Number(this.getAttribute("now-ms"));
17
+ const scene = airExtremesScene({
18
+ nowMs: Number.isFinite(nowAttribute) && nowAttribute > 0 ? nowAttribute : Date.now(),
19
+ station: gate.station,
20
+ words
21
+ });
22
+ if (scene == null) {
23
+ this.replaceChildren();
24
+ return;
25
+ }
26
+ this.replaceChildren(h("dl", {
27
+ "aria-label": scene.ariaLabel,
28
+ class: scene.className
29
+ }, scene.tiles.map((tile) => h("div", { class: tile.className }, h("dt", { class: "meteo-microlabel" }, tile.label), h("dd", { class: "meteo-air-extremes-value" }, tile.value)))));
30
+ }
31
+ };
32
+ //#endregion
33
+ export { AirExtremesElement };
@@ -0,0 +1,15 @@
1
+ import { StationClimatology } from "../../contract-climatology.js";
2
+ import "../../index.js";
3
+ import { MeteoStationElement } from "../lib/base.js";
4
+ //#region src/elements/elements/ClimatologyDailyPatternElement.d.ts
5
+ declare class ClimatologyDailyPatternElement extends MeteoStationElement {
6
+ #private;
7
+ static readonly observedAttributes: string[];
8
+ constructor();
9
+ get document(): StationClimatology | null | undefined;
10
+ set document(value: StationClimatology | null | undefined);
11
+ protected disconnected(): void;
12
+ protected render(): void;
13
+ }
14
+ //#endregion
15
+ export { ClimatologyDailyPatternElement };
@@ -0,0 +1,84 @@
1
+ import { measuredChartWidth } from "../../geometry.js";
2
+ import { CLIMATOLOGY_PATTERN_CLASS, climatologyPatternGate, climatologyPatternScene } from "../../scene/climatology-pattern.js";
3
+ import { numberAttribute, parseMonthsAttribute } from "../lib/attributes.js";
4
+ import { MeteoStationElement } from "../lib/base.js";
5
+ import { h } from "../lib/h.js";
6
+ import { dailyPatternSceneDom } from "./DailyPatternElement.js";
7
+ //#region src/elements/elements/ClimatologyDailyPatternElement.ts
8
+ let hatchCounter = 0;
9
+ var ClimatologyDailyPatternElement = class extends MeteoStationElement {
10
+ static observedAttributes = [
11
+ "favorable-directions",
12
+ "months",
13
+ "plot-height",
14
+ "station-name",
15
+ "thresholds",
16
+ "unit"
17
+ ];
18
+ #document;
19
+ #width = null;
20
+ #observer = null;
21
+ constructor() {
22
+ super();
23
+ for (const name of ["document"]) this.upgradeProperty(name);
24
+ }
25
+ get document() {
26
+ return this.#document;
27
+ }
28
+ set document(value) {
29
+ this.#document = value;
30
+ this.requestRender();
31
+ }
32
+ disconnected() {
33
+ this.#observer?.disconnect();
34
+ this.#observer = null;
35
+ }
36
+ render() {
37
+ const { favorableDirections, thresholds, unit, words } = this.display();
38
+ const gate = climatologyPatternGate(this.#document, words);
39
+ if (gate.kind === "note") {
40
+ this.#observer?.disconnect();
41
+ this.#observer = null;
42
+ this.replaceChildren(h("div", {
43
+ class: gate.className,
44
+ role: "note"
45
+ }, gate.text));
46
+ return;
47
+ }
48
+ const wrap = h("div", { class: CLIMATOLOGY_PATTERN_CLASS });
49
+ this.replaceChildren(wrap);
50
+ this.#observe(wrap);
51
+ if (this.#width == null) return;
52
+ const { caption, svg } = dailyPatternSceneDom(climatologyPatternScene({
53
+ document: gate.document,
54
+ favorableDirections,
55
+ filters: { months: parseMonthsAttribute(this.getAttribute("months")) },
56
+ hatchId: `meteo-climatology-hatch-e${++hatchCounter}`,
57
+ plotHeight: numberAttribute(this.getAttribute("plot-height")),
58
+ stationName: this.getAttribute("station-name") ?? void 0,
59
+ thresholds,
60
+ unit,
61
+ width: this.#width,
62
+ words
63
+ }));
64
+ wrap.replaceChildren(caption, svg);
65
+ }
66
+ #observe(wrap) {
67
+ this.#observer?.disconnect();
68
+ if (typeof ResizeObserver === "undefined") {
69
+ this.#width = 360;
70
+ this.#observer = null;
71
+ return;
72
+ }
73
+ this.#observer = new ResizeObserver((entries) => {
74
+ const width = measuredChartWidth(entries[0]?.contentRect.width ?? 0);
75
+ if (width !== this.#width) {
76
+ this.#width = width;
77
+ this.requestRender();
78
+ }
79
+ });
80
+ this.#observer.observe(wrap);
81
+ }
82
+ };
83
+ //#endregion
84
+ export { ClimatologyDailyPatternElement };
@@ -0,0 +1,14 @@
1
+ import { StationClimatology } from "../../contract-climatology.js";
2
+ import "../../index.js";
3
+ import { MeteoStationElement } from "../lib/base.js";
4
+ //#region src/elements/elements/ClimatologyRoseElement.d.ts
5
+ declare class ClimatologyRoseElement extends MeteoStationElement {
6
+ #private;
7
+ static readonly observedAttributes: string[];
8
+ constructor();
9
+ get document(): StationClimatology | null | undefined;
10
+ set document(value: StationClimatology | null | undefined);
11
+ protected render(): void;
12
+ }
13
+ //#endregion
14
+ export { ClimatologyRoseElement };
@@ -0,0 +1,51 @@
1
+ import { climatologyRoseGate, climatologyRoseScene } from "../../scene/climatology-rose.js";
2
+ import { parseMonthsAttribute, parseSlotsAttribute } from "../lib/attributes.js";
3
+ import { MeteoStationElement } from "../lib/base.js";
4
+ import { h } from "../lib/h.js";
5
+ import { windRoseSceneDom } from "./WindRoseElement.js";
6
+ //#region src/elements/elements/ClimatologyRoseElement.ts
7
+ var ClimatologyRoseElement = class extends MeteoStationElement {
8
+ static observedAttributes = [
9
+ "favorable-directions",
10
+ "months",
11
+ "slots",
12
+ "station-name"
13
+ ];
14
+ #document;
15
+ constructor() {
16
+ super();
17
+ for (const name of ["document"]) this.upgradeProperty(name);
18
+ }
19
+ get document() {
20
+ return this.#document;
21
+ }
22
+ set document(value) {
23
+ this.#document = value;
24
+ this.requestRender();
25
+ }
26
+ render() {
27
+ const { favorableDirections, words } = this.display();
28
+ const gate = climatologyRoseGate(this.#document, words);
29
+ if (gate.kind === "note") {
30
+ this.replaceChildren(h("div", {
31
+ class: gate.className,
32
+ role: "note"
33
+ }, gate.text));
34
+ return;
35
+ }
36
+ const filters = {
37
+ months: parseMonthsAttribute(this.getAttribute("months")),
38
+ slots: parseSlotsAttribute(this.getAttribute("slots"))
39
+ };
40
+ const scene = climatologyRoseScene({
41
+ document: gate.document,
42
+ favorableDirections,
43
+ filters,
44
+ stationName: this.getAttribute("station-name") ?? void 0,
45
+ words
46
+ });
47
+ this.replaceChildren(h("div", { class: scene.className }, windRoseSceneDom(scene.rose, ...scene.captions.map((caption) => h("p", { class: caption.className }, caption.text)))));
48
+ }
49
+ };
50
+ //#endregion
51
+ export { ClimatologyRoseElement };
@@ -0,0 +1,14 @@
1
+ import { LiveSamples } from "../../contract.js";
2
+ import "../../index.js";
3
+ import { MeteoStationElement } from "../lib/base.js";
4
+ //#region src/elements/elements/CompassFanElement.d.ts
5
+ declare class CompassFanElement extends MeteoStationElement {
6
+ #private;
7
+ static readonly observedAttributes: string[];
8
+ constructor();
9
+ get samples(): LiveSamples | null | undefined;
10
+ set samples(value: LiveSamples | null | undefined);
11
+ protected render(): void;
12
+ }
13
+ //#endregion
14
+ export { CompassFanElement };
@@ -0,0 +1,92 @@
1
+ import { resolveStation } from "../../display.js";
2
+ import { compassFanGate, compassFanScene, compassFanSource } from "../../scene/compass-fan.js";
3
+ import { MeteoStationElement } from "../lib/base.js";
4
+ import { h, hs } from "../lib/h.js";
5
+ //#region src/elements/elements/CompassFanElement.ts
6
+ var CompassFanElement = class extends MeteoStationElement {
7
+ static observedAttributes = ["favorable-directions", "station-id"];
8
+ #samples;
9
+ constructor() {
10
+ super();
11
+ for (const name of ["samples"]) this.upgradeProperty(name);
12
+ }
13
+ get samples() {
14
+ return this.#samples;
15
+ }
16
+ set samples(value) {
17
+ this.#samples = value;
18
+ this.requestRender();
19
+ }
20
+ render() {
21
+ const station = this.station ?? (this.#samples == null ? resolveStation(this.ambient()?.feed ?? null, this.getAttribute("station-id") ?? void 0) ?? void 0 : void 0);
22
+ const { favorableDirections, words } = this.display();
23
+ const gate = compassFanGate(compassFanSource(this.#samples, station), station, words);
24
+ if (gate.kind === "hidden") {
25
+ this.replaceChildren();
26
+ return;
27
+ }
28
+ if (gate.kind === "note") {
29
+ this.replaceChildren(h("div", {
30
+ class: gate.className,
31
+ role: "note"
32
+ }, gate.text));
33
+ return;
34
+ }
35
+ const scene = compassFanScene({
36
+ favorableDirections,
37
+ samples: gate.samples,
38
+ stationName: station?.name,
39
+ words
40
+ });
41
+ this.replaceChildren(hs("svg", {
42
+ "aria-label": scene.svg.ariaLabel,
43
+ class: scene.svg.className,
44
+ height: scene.svg.height,
45
+ role: "img",
46
+ viewBox: scene.svg.viewBox,
47
+ width: scene.svg.width
48
+ }, hs("circle", {
49
+ class: scene.ring.className,
50
+ cx: scene.ring.cx,
51
+ cy: scene.ring.cy,
52
+ r: scene.ring.r
53
+ }), scene.verdictRing != null ? [hs("circle", {
54
+ class: scene.verdictRing.unfavorable.className,
55
+ cx: scene.verdictRing.unfavorable.cx,
56
+ cy: scene.verdictRing.unfavorable.cy,
57
+ r: scene.verdictRing.unfavorable.r
58
+ }), scene.verdictRing.favorable.map((arc) => hs("path", {
59
+ class: arc.className,
60
+ d: arc.d
61
+ }))] : null, scene.ticks.map((tick) => hs("line", {
62
+ class: tick.className,
63
+ x1: tick.x1,
64
+ x2: tick.x2,
65
+ y1: tick.y1,
66
+ y2: tick.y2
67
+ })), scene.letters.map((letter) => hs("text", {
68
+ class: letter.className,
69
+ "text-anchor": letter.anchor,
70
+ x: letter.x,
71
+ y: letter.y
72
+ }, letter.text)), scene.ghosts.map((ghost) => hs("path", {
73
+ class: ghost.className,
74
+ d: ghost.d
75
+ })), scene.needle != null && hs("g", { class: scene.needle.className }, hs("polygon", {
76
+ class: scene.needle.blade.className,
77
+ points: scene.needle.blade.points
78
+ }), hs("circle", {
79
+ class: scene.needle.counterweight.className,
80
+ cx: scene.needle.counterweight.cx,
81
+ cy: scene.needle.counterweight.cy,
82
+ r: scene.needle.counterweight.r
83
+ })), hs("circle", {
84
+ class: scene.hub.className,
85
+ cx: scene.hub.cx,
86
+ cy: scene.hub.cy,
87
+ r: scene.hub.r
88
+ })));
89
+ }
90
+ };
91
+ //#endregion
92
+ export { CompassFanElement };
@@ -1,6 +1,7 @@
1
1
  import { HistoryPoint } from "../../contract.js";
2
2
  import "../../index.js";
3
3
  import { MeteoStationElement } from "../lib/base.js";
4
+ import "../../scene/index.js";
4
5
  //#region src/elements/elements/DailyPatternElement.d.ts
5
6
  declare class DailyPatternElement extends MeteoStationElement {
6
7
  #private;
@@ -8,6 +8,7 @@ import { h, hs } from "../lib/h.js";
8
8
  let hatchCounter = 0;
9
9
  var DailyPatternElement = class extends MeteoStationElement {
10
10
  static observedAttributes = [
11
+ "favorable-directions",
11
12
  "plot-height",
12
13
  "slot-minutes",
13
14
  "station-id",
@@ -35,7 +36,7 @@ var DailyPatternElement = class extends MeteoStationElement {
35
36
  }
36
37
  render() {
37
38
  const station = this.station ?? (this.#points == null ? resolveStation(this.ambient()?.feed ?? null, this.getAttribute("station-id") ?? void 0) ?? void 0 : void 0);
38
- const { thresholds, unit, words } = this.display();
39
+ const { favorableDirections, thresholds, unit, words } = this.display();
39
40
  const { source, periodMinutes } = dailyPatternSource(this.#points, station);
40
41
  const gate = dailyPatternGate(source, words);
41
42
  if (gate.kind === "note") {
@@ -51,7 +52,7 @@ var DailyPatternElement = class extends MeteoStationElement {
51
52
  this.replaceChildren(wrap);
52
53
  this.#observe(wrap);
53
54
  if (this.#width == null) return;
54
- this.#buildChart(wrap, source, periodMinutes, thresholds, unit, words, this.#width, station?.name);
55
+ this.#buildChart(wrap, source, periodMinutes, thresholds, favorableDirections, unit, words, this.#width, station?.name);
55
56
  }
56
57
  #observe(wrap) {
57
58
  this.#observer?.disconnect();
@@ -69,8 +70,9 @@ var DailyPatternElement = class extends MeteoStationElement {
69
70
  });
70
71
  this.#observer.observe(wrap);
71
72
  }
72
- #buildChart(wrap, points, periodMinutes, thresholds, unit, words, width, stationName) {
73
- const scene = dailyPatternScene({
73
+ #buildChart(wrap, points, periodMinutes, thresholds, favorableDirections, unit, words, width, stationName) {
74
+ const { caption, svg } = dailyPatternSceneDom(dailyPatternScene({
75
+ favorableDirections,
74
76
  hatchId: `meteo-daily-pattern-hatch-e${++hatchCounter}`,
75
77
  periodMinutes,
76
78
  plotHeight: numberAttribute(this.getAttribute("plot-height")),
@@ -82,9 +84,16 @@ var DailyPatternElement = class extends MeteoStationElement {
82
84
  utcOffsetMinutes: numberAttribute(this.getAttribute("utc-offset-minutes")) ?? 0,
83
85
  width,
84
86
  words
85
- });
86
- const caption = h("output", { class: scene.caption.className }, scene.caption.text);
87
- const svg = hs("svg", {
87
+ }));
88
+ wrap.replaceChildren(caption, svg);
89
+ }
90
+ };
91
+ /** One scene, one drawing — shared by the history-fed pattern above and the
92
+ * climatology-fed twin. */
93
+ function dailyPatternSceneDom(scene) {
94
+ return {
95
+ caption: h("output", { class: scene.caption.className }, scene.caption.text),
96
+ svg: hs("svg", {
88
97
  "aria-label": scene.svg.ariaLabel,
89
98
  class: scene.svg.className,
90
99
  height: scene.svg.height,
@@ -191,9 +200,8 @@ var DailyPatternElement = class extends MeteoStationElement {
191
200
  "text-anchor": tick.anchor,
192
201
  x: tick.x,
193
202
  y: tick.y
194
- }, tick.text)));
195
- wrap.replaceChildren(caption, svg);
196
- }
197
- };
203
+ }, tick.text)))
204
+ };
205
+ }
198
206
  //#endregion
199
- export { DailyPatternElement };
207
+ export { DailyPatternElement, dailyPatternSceneDom };