@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,215 @@
1
+ import { localeFormatTime } from "../../strings.js";
2
+ import { createStationFeedStore, createStationStore } from "../../client/stores.js";
3
+ import { STATION_FEED_CONTEXT_KEY } from "../lib/ambient.js";
4
+ import { numberAttribute, parseThresholdsAttribute, unitAttribute } from "../lib/attributes.js";
5
+ import { provideContext } from "../lib/context.js";
6
+ import { MeteoElement } from "../lib/base.js";
7
+ //#region src/elements/elements/StationFeedElement.ts
8
+ var StationFeedElement = class extends MeteoElement {
9
+ static observedAttributes = [
10
+ "current-poll-seconds",
11
+ "locale",
12
+ "paused",
13
+ "poll-seconds",
14
+ "src",
15
+ "station",
16
+ "thresholds",
17
+ "unit"
18
+ ];
19
+ #feed = null;
20
+ #receivedAtMs = null;
21
+ #strings;
22
+ #formatTime;
23
+ #thresholds;
24
+ #fetchInit;
25
+ #store = null;
26
+ #storeKey = null;
27
+ #unsubscribeStore = null;
28
+ #lastFeed = null;
29
+ #lastError = null;
30
+ #listeners = /* @__PURE__ */ new Set();
31
+ constructor() {
32
+ super();
33
+ for (const name of [
34
+ "feed",
35
+ "receivedAtMs",
36
+ "strings",
37
+ "formatTime",
38
+ "thresholds",
39
+ "fetchInit"
40
+ ]) this.upgradeProperty(name);
41
+ }
42
+ #ambientValue() {
43
+ const snapshot = this.#store?.feedSnapshot();
44
+ const locale = this.getAttribute("locale");
45
+ return {
46
+ feed: snapshot != null ? snapshot.feed : this.#feed,
47
+ receivedAtMs: snapshot != null ? snapshot.receivedAtMs : this.#receivedAtMs,
48
+ strings: this.#strings,
49
+ unit: unitAttribute(this.getAttribute("unit")),
50
+ formatTime: this.#formatTime ?? (locale != null ? localeFormatTime(locale) : void 0),
51
+ thresholds: this.#thresholds ?? parseThresholdsAttribute(this.getAttribute("thresholds")) ?? void 0
52
+ };
53
+ }
54
+ #notify() {
55
+ for (const listener of [...this.#listeners]) listener();
56
+ }
57
+ get feed() {
58
+ return this.#ambientValue().feed;
59
+ }
60
+ set feed(value) {
61
+ this.#feed = value;
62
+ this.#notify();
63
+ }
64
+ get receivedAtMs() {
65
+ return this.#ambientValue().receivedAtMs;
66
+ }
67
+ set receivedAtMs(value) {
68
+ this.#receivedAtMs = value;
69
+ this.#notify();
70
+ }
71
+ get strings() {
72
+ return this.#strings;
73
+ }
74
+ set strings(value) {
75
+ this.#strings = value;
76
+ this.#notify();
77
+ }
78
+ get formatTime() {
79
+ return this.#formatTime;
80
+ }
81
+ set formatTime(value) {
82
+ this.#formatTime = value;
83
+ this.#notify();
84
+ }
85
+ get thresholds() {
86
+ return this.#thresholds;
87
+ }
88
+ set thresholds(value) {
89
+ this.#thresholds = value;
90
+ this.#notify();
91
+ }
92
+ get fetchInit() {
93
+ return this.#fetchInit;
94
+ }
95
+ set fetchInit(value) {
96
+ this.#fetchInit = value;
97
+ }
98
+ get error() {
99
+ return this.#store?.feedSnapshot().error ?? null;
100
+ }
101
+ refresh() {
102
+ this.#store?.refresh();
103
+ }
104
+ connected() {
105
+ this.addCleanup(provideContext(this, STATION_FEED_CONTEXT_KEY, {
106
+ getValue: () => this.#ambientValue(),
107
+ subscribe: (listener) => {
108
+ this.#listeners.add(listener);
109
+ return () => this.#listeners.delete(listener);
110
+ }
111
+ }));
112
+ this.#syncStore();
113
+ this.addCleanup(() => this.#teardownStore());
114
+ }
115
+ attributeChangedCallback(name) {
116
+ if (!this.isConnected) return;
117
+ if ([
118
+ "current-poll-seconds",
119
+ "paused",
120
+ "poll-seconds",
121
+ "src",
122
+ "station"
123
+ ].includes(name)) this.#syncStore();
124
+ this.#notify();
125
+ }
126
+ render() {
127
+ this.#notify();
128
+ }
129
+ #teardownStore() {
130
+ this.#unsubscribeStore?.();
131
+ this.#unsubscribeStore = null;
132
+ this.#store?.stop();
133
+ this.#store = null;
134
+ this.#storeKey = null;
135
+ }
136
+ #syncStore() {
137
+ const src = this.getAttribute("src");
138
+ const stationId = this.getAttribute("station");
139
+ const pollSeconds = numberAttribute(this.getAttribute("poll-seconds"));
140
+ const currentPollSeconds = numberAttribute(this.getAttribute("current-poll-seconds"));
141
+ const key = src == null ? null : JSON.stringify([
142
+ src,
143
+ stationId,
144
+ pollSeconds ?? null,
145
+ currentPollSeconds ?? null
146
+ ]);
147
+ if (key !== this.#storeKey) {
148
+ this.#teardownStore();
149
+ this.#storeKey = key;
150
+ if (src != null) {
151
+ this.#store = this.#buildStore(src, stationId, pollSeconds, currentPollSeconds);
152
+ this.#unsubscribeStore = this.#store.subscribe(() => this.#onStoreChange());
153
+ }
154
+ }
155
+ if (this.#store != null) if (this.hasAttribute("paused")) this.#store.stop();
156
+ else this.#store.start();
157
+ }
158
+ #buildStore(src, stationId, pollSeconds, currentPollSeconds) {
159
+ const fetchInit = () => this.#fetchInit;
160
+ if (stationId != null) {
161
+ const store = createStationStore(src, stationId, {
162
+ ...pollSeconds != null ? { pollSeconds } : {},
163
+ ...currentPollSeconds != null ? { currentPollSeconds } : {},
164
+ fetchInit
165
+ });
166
+ return {
167
+ ...store,
168
+ feedSnapshot: () => {
169
+ const snapshot = store.getSnapshot();
170
+ return {
171
+ feed: snapshot.feed,
172
+ receivedAtMs: snapshot.receivedAtMs,
173
+ error: snapshot.error
174
+ };
175
+ }
176
+ };
177
+ }
178
+ const store = createStationFeedStore(src, {
179
+ ...pollSeconds != null ? { pollSeconds } : {},
180
+ fetchInit
181
+ });
182
+ return {
183
+ subscribe: store.subscribe,
184
+ start: store.start,
185
+ stop: store.stop,
186
+ refresh: store.refresh,
187
+ feedSnapshot: () => {
188
+ const snapshot = store.getSnapshot();
189
+ return {
190
+ feed: snapshot.data,
191
+ receivedAtMs: snapshot.receivedAtMs,
192
+ error: snapshot.error
193
+ };
194
+ }
195
+ };
196
+ }
197
+ #onStoreChange() {
198
+ const snapshot = this.#store?.feedSnapshot();
199
+ if (snapshot == null) return;
200
+ if (snapshot.feed !== this.#lastFeed && snapshot.feed != null) {
201
+ this.#lastFeed = snapshot.feed;
202
+ this.dispatchEvent(new CustomEvent("meteo-feed", { detail: {
203
+ feed: snapshot.feed,
204
+ receivedAtMs: snapshot.receivedAtMs
205
+ } }));
206
+ }
207
+ if (snapshot.error !== this.#lastError && snapshot.error != null) {
208
+ this.#lastError = snapshot.error;
209
+ this.dispatchEvent(new CustomEvent("meteo-error", { detail: { error: snapshot.error } }));
210
+ }
211
+ this.#notify();
212
+ }
213
+ };
214
+ //#endregion
215
+ export { StationFeedElement };
@@ -0,0 +1,9 @@
1
+ import { MeteoStationElement } from "../lib/base.js";
2
+ //#region src/elements/elements/StationStripElement.d.ts
3
+ declare class StationStripElement extends MeteoStationElement {
4
+ static readonly observedAttributes: string[];
5
+ protected connected(): void;
6
+ protected render(): void;
7
+ }
8
+ //#endregion
9
+ export { StationStripElement };
@@ -0,0 +1,43 @@
1
+ import { stationStripScene } from "../../scene/strip.js";
2
+ import { MeteoStationElement } from "../lib/base.js";
3
+ import { h } from "../lib/h.js";
4
+ import { directionCellNodes, freshnessBadgeSpan, stationNameNode } from "../lib/fragments.js";
5
+ //#region src/elements/elements/StationStripElement.ts
6
+ var StationStripElement = class extends MeteoStationElement {
7
+ static observedAttributes = [
8
+ "received-at-ms",
9
+ "served-at",
10
+ "station-id",
11
+ "unit"
12
+ ];
13
+ connected() {
14
+ this.watchFreshness();
15
+ }
16
+ render() {
17
+ const station = this.requiredStation("meteo-station-strip");
18
+ const { formatTime, unit, words } = this.display();
19
+ const status = this.freshnessOf(station);
20
+ const scene = stationStripScene({
21
+ formatTime,
22
+ station,
23
+ unit,
24
+ words
25
+ });
26
+ const { body } = scene;
27
+ const cells = body.kind === "reading" ? [
28
+ h("span", { class: body.wind.className }, h("strong", null, body.wind.value), h("small", null, body.wind.unitLabel)),
29
+ body.gustLull != null && [h("span", { class: body.gustLull.lull.className }, h("small", { class: body.gustLull.lull.labelClassName }, body.gustLull.lull.label), body.gustLull.lull.value), h("span", { class: body.gustLull.gust.className }, h("small", { class: body.gustLull.gust.labelClassName }, body.gustLull.gust.label), body.gustLull.gust.value)],
30
+ h("span", { class: body.from.className }, ...directionCellNodes(body.from.windAvgMps, body.from.windDirectionDeg, words)),
31
+ body.temperature != null && h("span", { class: body.temperature.className }, body.temperature.text),
32
+ h("span", { class: body.updated.className }, h("span", { class: body.updated.time.className }, body.updated.time.text), status != null && freshnessBadgeSpan(status, words))
33
+ ] : [h("span", { class: body.className }, body.text)];
34
+ this.replaceChildren(h("div", {
35
+ "aria-label": scene.root.ariaLabel,
36
+ class: scene.root.className,
37
+ "data-status": scene.root.status,
38
+ role: "group"
39
+ }, h("span", { class: scene.stationClassName }, stationNameNode(station)), ...cells));
40
+ }
41
+ };
42
+ //#endregion
43
+ export { StationStripElement };
@@ -0,0 +1,18 @@
1
+ import { Station } from "../../contract.js";
2
+ import "../../index.js";
3
+ import { MeteoStationElement } from "../lib/base.js";
4
+ //#region src/elements/elements/StationTableElement.d.ts
5
+ type StationMetaRenderer = (station: Station) => string | Node | null;
6
+ declare class StationTableElement extends MeteoStationElement {
7
+ #private;
8
+ static readonly observedAttributes: string[];
9
+ constructor();
10
+ get stations(): readonly Station[] | undefined;
11
+ set stations(value: readonly Station[] | undefined);
12
+ get stationMeta(): StationMetaRenderer | undefined;
13
+ set stationMeta(value: StationMetaRenderer | undefined);
14
+ protected connected(): void;
15
+ protected render(): void;
16
+ }
17
+ //#endregion
18
+ export { StationMetaRenderer, StationTableElement };
@@ -0,0 +1,102 @@
1
+ import { requireResolved } from "../../display.js";
2
+ import { stationTableRowScene, stationTableScene } from "../../scene/table.js";
3
+ import { ELEMENTS_AMBIENT_HINT } from "../lib/ambient.js";
4
+ import { MeteoStationElement } from "../lib/base.js";
5
+ import { h } from "../lib/h.js";
6
+ import { directionCellNodes, freshnessBadgeSpan, stationNameNode } from "../lib/fragments.js";
7
+ //#region src/elements/elements/StationTableElement.ts
8
+ var StationTableElement = class extends MeteoStationElement {
9
+ static observedAttributes = [
10
+ "received-at-ms",
11
+ "served-at",
12
+ "unit"
13
+ ];
14
+ #stations;
15
+ #stationMeta;
16
+ constructor() {
17
+ super();
18
+ for (const name of ["stations", "stationMeta"]) this.upgradeProperty(name);
19
+ }
20
+ get stations() {
21
+ return this.#stations;
22
+ }
23
+ set stations(value) {
24
+ this.#stations = value;
25
+ this.requestRender();
26
+ }
27
+ get stationMeta() {
28
+ return this.#stationMeta;
29
+ }
30
+ set stationMeta(value) {
31
+ this.#stationMeta = value;
32
+ this.requestRender();
33
+ }
34
+ connected() {
35
+ this.watchFreshness();
36
+ }
37
+ render() {
38
+ const stations = requireResolved("meteo-station-table", "stations", this.#stations ?? this.ambient()?.feed?.stations, ELEMENTS_AMBIENT_HINT);
39
+ const { formatTime, unit, words } = this.display();
40
+ const scene = stationTableScene(stations, words);
41
+ this.replaceChildren(h("div", {
42
+ "aria-label": scene.root.ariaLabel,
43
+ class: scene.root.className,
44
+ role: "table"
45
+ }, h("div", {
46
+ class: scene.head.className,
47
+ role: "row"
48
+ }, scene.head.columns.map((column) => h("span", { role: "columnheader" }, column))), h("div", {
49
+ class: scene.bodyClassName,
50
+ role: "rowgroup"
51
+ }, stations.map((station) => this.#row(station, unit, words, formatTime)))));
52
+ }
53
+ #row(station, unit, words, formatTime) {
54
+ const status = this.freshnessOf(station);
55
+ const meta = this.#stationMeta ? this.#stationMeta(station) : station.sourceLabel;
56
+ const row = stationTableRowScene({
57
+ formatTime,
58
+ station,
59
+ unit,
60
+ words
61
+ });
62
+ const { cells } = row;
63
+ return h("div", {
64
+ class: row.className,
65
+ "data-status": row.status,
66
+ role: "row"
67
+ }, h("span", {
68
+ class: row.stationCellClassName,
69
+ role: "cell"
70
+ }, h("strong", null, stationNameNode(station)), h("small", null, meta)), cells.kind === "reading" ? [
71
+ h("span", {
72
+ class: cells.wind.className,
73
+ role: "cell"
74
+ }, h("strong", null, cells.wind.value), h("small", null, cells.wind.unitLabel)),
75
+ h("span", {
76
+ class: cells.lull.className,
77
+ role: "cell"
78
+ }, cells.lull.value),
79
+ h("span", {
80
+ class: cells.gust.className,
81
+ role: "cell"
82
+ }, cells.gust.value),
83
+ h("span", {
84
+ class: cells.from.className,
85
+ role: "cell"
86
+ }, ...directionCellNodes(cells.from.windAvgMps, cells.from.windDirectionDeg, words)),
87
+ h("span", {
88
+ class: cells.temperature.className,
89
+ role: "cell"
90
+ }, cells.temperature.value),
91
+ h("span", {
92
+ class: cells.updated.className,
93
+ role: "cell"
94
+ }, h("span", { class: cells.updated.time.className }, cells.updated.time.text), status != null && freshnessBadgeSpan(status, words))
95
+ ] : h("span", {
96
+ class: cells.className,
97
+ role: "cell"
98
+ }, cells.text));
99
+ }
100
+ };
101
+ //#endregion
102
+ export { StationTableElement };
@@ -0,0 +1,10 @@
1
+ import { MeteoStationElement } from "../lib/base.js";
2
+ //#region src/elements/elements/TrendChartElement.d.ts
3
+ declare class TrendChartElement extends MeteoStationElement {
4
+ #private;
5
+ static readonly observedAttributes: string[];
6
+ protected disconnected(): void;
7
+ protected render(): void;
8
+ }
9
+ //#endregion
10
+ export { TrendChartElement };
@@ -0,0 +1,174 @@
1
+ import { requireResolved } from "../../display.js";
2
+ import { activeChartIndex, chartIndexAtClient, measuredChartWidth, readoutAriaLive, togglePinnedAt } from "../../scene/chart.js";
3
+ import { TREND_CLASS, trendGate, trendScene } from "../../scene/trend.js";
4
+ import { ELEMENTS_AMBIENT_HINT } from "../lib/ambient.js";
5
+ import { MeteoStationElement } from "../lib/base.js";
6
+ import { h, hs } from "../lib/h.js";
7
+ //#region src/elements/elements/TrendChartElement.ts
8
+ var TrendChartElement = class extends MeteoStationElement {
9
+ static observedAttributes = ["series", "station-id"];
10
+ #width = null;
11
+ #observer = null;
12
+ #pinnedAt = null;
13
+ #previewIndex = null;
14
+ #scene = null;
15
+ #readout = null;
16
+ #svg = null;
17
+ #hit = null;
18
+ disconnected() {
19
+ this.#observer?.disconnect();
20
+ this.#observer = null;
21
+ }
22
+ render() {
23
+ const station = this.requiredStation("meteo-trend-chart");
24
+ const series = requireResolved("meteo-trend-chart", "series", this.getAttribute("series") === "temperature" || this.getAttribute("series") === "pressure" ? this.getAttribute("series") : null, ELEMENTS_AMBIENT_HINT);
25
+ const { formatTime, words } = this.display();
26
+ const gate = trendGate(station, series, words);
27
+ if (gate.kind !== "draw") {
28
+ this.#observer?.disconnect();
29
+ this.#observer = null;
30
+ if (gate.kind === "hidden") this.replaceChildren();
31
+ else this.replaceChildren(h("div", {
32
+ class: gate.className,
33
+ role: "note"
34
+ }, gate.text));
35
+ return;
36
+ }
37
+ const wrap = h("div", { class: TREND_CLASS });
38
+ this.replaceChildren(wrap);
39
+ this.#observe(wrap);
40
+ if (this.#width == null) return;
41
+ this.#buildTrend(wrap, gate.history, series, words, formatTime, this.#width, station.name);
42
+ }
43
+ #observe(wrap) {
44
+ this.#observer?.disconnect();
45
+ if (typeof ResizeObserver === "undefined") {
46
+ this.#width = 360;
47
+ this.#observer = null;
48
+ return;
49
+ }
50
+ this.#observer = new ResizeObserver((entries) => {
51
+ const width = measuredChartWidth(entries[0]?.contentRect.width ?? 0);
52
+ if (width !== this.#width) {
53
+ this.#width = width;
54
+ this.requestRender();
55
+ }
56
+ });
57
+ this.#observer.observe(wrap);
58
+ }
59
+ #buildTrend(wrap, history, series, words, formatTime, width, stationName) {
60
+ const scene = trendScene({
61
+ formatTime,
62
+ history,
63
+ series,
64
+ stationName,
65
+ width,
66
+ words
67
+ });
68
+ this.#scene = scene;
69
+ const readout = h("output", {
70
+ "aria-label": scene.readout.ariaLabel,
71
+ class: scene.readout.className
72
+ });
73
+ this.#readout = readout;
74
+ const hit = hs("rect", {
75
+ class: scene.hit.className,
76
+ fill: scene.hit.fill,
77
+ height: scene.hit.height,
78
+ onclick: (event) => this.#handleClick(event),
79
+ onpointerleave: () => {
80
+ this.#previewIndex = null;
81
+ this.#updateCursor();
82
+ },
83
+ onpointermove: (event) => this.#handlePointerMove(event),
84
+ width: scene.hit.width,
85
+ x: scene.hit.x,
86
+ y: scene.hit.y
87
+ });
88
+ this.#hit = hit;
89
+ const svg = hs("svg", {
90
+ "aria-label": scene.svg.ariaLabel,
91
+ class: scene.svg.className,
92
+ height: scene.svg.height,
93
+ role: "img",
94
+ viewBox: scene.svg.viewBox,
95
+ width: scene.svg.width
96
+ }, scene.grid.map(({ line, label }) => hs("g", null, hs("line", {
97
+ class: line.className,
98
+ x1: line.x1,
99
+ x2: line.x2,
100
+ y1: line.y1,
101
+ y2: line.y2
102
+ }), hs("text", {
103
+ class: label.className,
104
+ "text-anchor": label.anchor,
105
+ x: label.x,
106
+ y: label.y
107
+ }, label.text))), scene.segments.map((segment) => segment.kind === "dot" ? hs("circle", {
108
+ class: segment.className,
109
+ cx: segment.cx,
110
+ cy: segment.cy,
111
+ r: segment.r
112
+ }) : hs("polyline", {
113
+ class: segment.className,
114
+ points: segment.points
115
+ })), scene.ticks.map((tick) => hs("text", {
116
+ class: tick.className,
117
+ "text-anchor": tick.anchor,
118
+ x: tick.x,
119
+ y: tick.y
120
+ }, tick.text)), hit);
121
+ this.#svg = svg;
122
+ wrap.replaceChildren(readout, svg);
123
+ this.#updateCursor();
124
+ }
125
+ #indexAtPoint(clientX) {
126
+ const scene = this.#scene;
127
+ const svg = this.#svg;
128
+ if (scene == null || svg == null) return null;
129
+ return chartIndexAtClient(scene.points, scene.frame, scene.scales, clientX, svg.getBoundingClientRect());
130
+ }
131
+ #handlePointerMove(event) {
132
+ if (event.pointerType === "touch") return;
133
+ this.#previewIndex = this.#indexAtPoint(event.clientX);
134
+ this.#updateCursor();
135
+ }
136
+ #handleClick(event) {
137
+ const index = this.#indexAtPoint(event.clientX);
138
+ if (index == null) return;
139
+ const observedAt = this.#scene?.points[index]?.observedAt;
140
+ if (observedAt == null) return;
141
+ this.#pinnedAt = togglePinnedAt(this.#pinnedAt, observedAt);
142
+ this.#previewIndex = null;
143
+ this.#updateCursor();
144
+ }
145
+ #updateCursor() {
146
+ const scene = this.#scene;
147
+ const readout = this.#readout;
148
+ const svg = this.#svg;
149
+ const hit = this.#hit;
150
+ if (scene == null || readout == null || svg == null || hit == null) return;
151
+ const inspection = scene.inspect(activeChartIndex(scene.points, this.#pinnedAt, this.#previewIndex));
152
+ readout.setAttribute("aria-live", readoutAriaLive(this.#previewIndex));
153
+ readout.replaceChildren(h("strong", null, inspection.readout.strong), h("span", null, inspection.readout.span));
154
+ for (const mark of [...svg.querySelectorAll(".meteo-cursor, .meteo-cursor-dot")]) mark.remove();
155
+ const cursor = inspection.cursor;
156
+ if (cursor != null) {
157
+ svg.insertBefore(hs("line", {
158
+ class: cursor.line.className,
159
+ x1: cursor.line.x1,
160
+ x2: cursor.line.x2,
161
+ y1: cursor.line.y1,
162
+ y2: cursor.line.y2
163
+ }), hit);
164
+ if (cursor.dot != null) svg.insertBefore(hs("circle", {
165
+ class: cursor.dot.className,
166
+ cx: cursor.dot.cx,
167
+ cy: cursor.dot.cy,
168
+ r: cursor.dot.r
169
+ }), hit);
170
+ }
171
+ }
172
+ };
173
+ //#endregion
174
+ export { TrendChartElement };
@@ -0,0 +1,8 @@
1
+ import { MeteoElement } from "../lib/base.js";
2
+ //#region src/elements/elements/WindArrowElement.d.ts
3
+ declare class WindArrowElement extends MeteoElement {
4
+ static readonly observedAttributes: string[];
5
+ protected render(): void;
6
+ }
7
+ //#endregion
8
+ export { WindArrowElement };
@@ -0,0 +1,14 @@
1
+ import { numberAttribute } from "../lib/attributes.js";
2
+ import { MeteoElement } from "../lib/base.js";
3
+ import { windArrowSvg } from "../lib/fragments.js";
4
+ //#region src/elements/elements/WindArrowElement.ts
5
+ var WindArrowElement = class extends MeteoElement {
6
+ static observedAttributes = ["deg", "size"];
7
+ render() {
8
+ const deg = numberAttribute(this.getAttribute("deg")) ?? 0;
9
+ const size = numberAttribute(this.getAttribute("size")) ?? 12;
10
+ this.replaceChildren(windArrowSvg(deg, size));
11
+ }
12
+ };
13
+ //#endregion
14
+ export { WindArrowElement };
@@ -0,0 +1,10 @@
1
+ import { MeteoStationElement } from "../lib/base.js";
2
+ //#region src/elements/elements/WindHistoryChartElement.d.ts
3
+ declare class WindHistoryChartElement extends MeteoStationElement {
4
+ #private;
5
+ static readonly observedAttributes: string[];
6
+ protected disconnected(): void;
7
+ protected render(): void;
8
+ }
9
+ //#endregion
10
+ export { WindHistoryChartElement };