@adminide-stack/yantra-mobile 12.0.137 → 12.0.139-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/CustomDrawer.js +17 -1
- package/lib/components/CustomDrawer.js.map +1 -1
- package/lib/compute.js +106 -1
- package/lib/compute.js.map +1 -1
- package/lib/config/env-config.js +12 -0
- package/lib/config/env-config.js.map +1 -1
- package/lib/features/chat/ChatTranscript.js +2 -2
- package/lib/features/chat/ChatTranscript.js.map +1 -1
- package/lib/features/chat/surfaceNotes.js +4 -0
- package/lib/features/chat/surfaceNotes.js.map +1 -0
- package/lib/features/devices/readings.js.map +1 -1
- package/lib/features/devices/session.js +2 -22
- package/lib/features/devices/session.js.map +1 -1
- package/lib/features/dictate/backgroundRecording.js.map +1 -1
- package/lib/features/dictate/useDictationRecorder.js +42 -1
- package/lib/features/dictate/useDictationRecorder.js.map +1 -1
- package/lib/features/home/useHomeWeather.js +85 -0
- package/lib/features/home/useHomeWeather.js.map +1 -0
- package/lib/features/home/weather.js +139 -0
- package/lib/features/home/weather.js.map +1 -0
- package/lib/features/notion/NotionPageView.js +819 -0
- package/lib/features/notion/NotionPageView.js.map +1 -0
- package/lib/features/notion/NotionSheets.js +452 -0
- package/lib/features/notion/NotionSheets.js.map +1 -0
- package/lib/features/notion/NotionTrashSheet.js +415 -0
- package/lib/features/notion/NotionTrashSheet.js.map +1 -0
- package/lib/features/notion/NotionWorkspaceView.js +837 -0
- package/lib/features/notion/NotionWorkspaceView.js.map +1 -0
- package/lib/features/notion/notionBlocks.js +203 -0
- package/lib/features/notion/notionBlocks.js.map +1 -0
- package/lib/features/notion/notionDocuments.js +182 -0
- package/lib/features/notion/notionDocuments.js.map +1 -0
- package/lib/features/notion/notionEditorModel.js +180 -0
- package/lib/features/notion/notionEditorModel.js.map +1 -0
- package/lib/features/notion/notionTemplates.js +406 -0
- package/lib/features/notion/notionTemplates.js.map +1 -0
- package/lib/features/notion/notionTheme.js +34 -0
- package/lib/features/notion/notionTheme.js.map +1 -0
- package/lib/features/notion/notionTrash.js +100 -0
- package/lib/features/notion/notionTrash.js.map +1 -0
- package/lib/features/notion/notionUi.js +310 -0
- package/lib/features/notion/notionUi.js.map +1 -0
- package/lib/features/notion/useNotionWorkspace.js +181 -0
- package/lib/features/notion/useNotionWorkspace.js.map +1 -0
- package/lib/features/webbuilder/buildFragments.js +15 -9
- package/lib/features/webbuilder/buildFragments.js.map +1 -1
- package/lib/features/webbuilder/buildJob.js +3 -3
- package/lib/features/webbuilder/buildJob.js.map +1 -1
- package/lib/features/webbuilder/publicSandboxDomain.js +5 -0
- package/lib/features/webbuilder/publicSandboxDomain.js.map +1 -0
- package/lib/features/webbuilder/sandboxPublicHost.js +74 -0
- package/lib/features/webbuilder/sandboxPublicHost.js.map +1 -0
- package/lib/features/webbuilder/siteAddress.js +2 -1
- package/lib/features/webbuilder/siteAddress.js.map +1 -1
- package/lib/features/webbuilder/webbuilderPrompts.js +3 -2
- package/lib/features/webbuilder/webbuilderPrompts.js.map +1 -1
- package/lib/features/webbuilder/workflow.js +2 -2
- package/lib/features/webbuilder/workflow.js.map +1 -1
- package/lib/hooks/useChatApi.js +15 -3
- package/lib/hooks/useChatApi.js.map +1 -1
- package/lib/hooks/usePrerequisiteIds.js +15 -2
- package/lib/hooks/usePrerequisiteIds.js.map +1 -1
- package/lib/routes.json +107 -0
- package/lib/screens/Devices/index.js +3 -205
- package/lib/screens/Devices/index.js.map +1 -1
- package/lib/screens/Home/HomeScreen.js +20 -5
- package/lib/screens/Home/HomeScreen.js.map +1 -1
- package/lib/screens/Home/components/HomeHero.js +117 -0
- package/lib/screens/Home/components/HomeHero.js.map +1 -0
- package/lib/screens/Home/components/HomeSuggestions.js +108 -85
- package/lib/screens/Home/components/HomeSuggestions.js.map +1 -1
- package/lib/screens/Home/components/HomeWash.js +44 -0
- package/lib/screens/Home/components/HomeWash.js.map +1 -0
- package/lib/screens/Home/components/homeCatalog.js +125 -0
- package/lib/screens/Home/components/homeCatalog.js.map +1 -0
- package/lib/screens/Notion/index.js +18 -0
- package/lib/screens/Notion/index.js.map +1 -0
- package/lib/screens/NotionPage/index.js +19 -0
- package/lib/screens/NotionPage/index.js.map +1 -0
- package/lib/screens/WebBuilderNative/sandboxProxyApi.js +2 -2
- package/lib/screens/WebBuilderNative/sandboxProxyApi.js.map +1 -1
- package/lib/screens/WebBuilderNative/useRestoredSandboxes.js +16 -8
- package/lib/screens/WebBuilderNative/useRestoredSandboxes.js.map +1 -1
- package/lib/screens/WebBuilderNative/useWebBuilderGallery.js +6 -5
- package/lib/screens/WebBuilderNative/useWebBuilderGallery.js.map +1 -1
- package/lib/screens/WebBuilderNative/useWebBuilderHost.js +5 -4
- package/lib/screens/WebBuilderNative/useWebBuilderHost.js.map +1 -1
- package/lib/screens/WebBuilderNative/webbuilderTransport.js +4 -3
- package/lib/screens/WebBuilderNative/webbuilderTransport.js.map +1 -1
- package/lib/services/savedWorkspace.js +44 -0
- package/lib/services/savedWorkspace.js.map +1 -0
- package/lib/theme/mobileTokens.js +1 -0
- package/lib/theme/mobileTokens.js.map +1 -1
- package/package.json +4 -4
- package/lib/features/devices/bodyComposition.js +0 -116
- package/lib/features/devices/bodyComposition.js.map +0 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {useMemo,useState,useEffect}from'react';import AsyncStorage from'@react-native-async-storage/async-storage';import {preferredTemperatureUnit,parsePlace,reverseGeocodeUrl,parseOpenMeteo,openMeteoUrl}from'./weather.js';const PLACE_KEY = "yantra.home.weather.place.v1";
|
|
2
|
+
const REPORT_KEY = "yantra.home.weather.report.v1";
|
|
3
|
+
const PLACE_TTL_MS = 12 * 60 * 6e4;
|
|
4
|
+
const REPORT_TTL_MS = 20 * 6e4;
|
|
5
|
+
const FETCH_TIMEOUT_MS = 1e4;
|
|
6
|
+
async function readCache(key, maxAgeMs) {
|
|
7
|
+
try {
|
|
8
|
+
const raw = await AsyncStorage.getItem(key);
|
|
9
|
+
const stamped = raw ? JSON.parse(raw) : null;
|
|
10
|
+
return stamped && Date.now() - stamped.at < maxAgeMs ? stamped.value : null;
|
|
11
|
+
} catch (e) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function writeCache(key, value) {
|
|
16
|
+
AsyncStorage.setItem(key, JSON.stringify({
|
|
17
|
+
at: Date.now(),
|
|
18
|
+
value
|
|
19
|
+
})).catch(() => void 0);
|
|
20
|
+
}
|
|
21
|
+
async function fetchJson(url) {
|
|
22
|
+
const controller = new AbortController();
|
|
23
|
+
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
24
|
+
try {
|
|
25
|
+
const response = await fetch(url, {
|
|
26
|
+
signal: controller.signal
|
|
27
|
+
});
|
|
28
|
+
if (!response.ok) throw new Error(`${response.status}`);
|
|
29
|
+
return await response.json();
|
|
30
|
+
} finally {
|
|
31
|
+
clearTimeout(timer);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function useHomeWeather(enabled = true) {
|
|
35
|
+
const unit = useMemo(() => preferredTemperatureUnit(), []);
|
|
36
|
+
const [place, setPlace] = useState();
|
|
37
|
+
const [report, setReport] = useState();
|
|
38
|
+
useEffect(() => {
|
|
39
|
+
if (!enabled || place) return void 0;
|
|
40
|
+
let cancelled = false;
|
|
41
|
+
(async () => {
|
|
42
|
+
const known = await readCache(PLACE_KEY, PLACE_TTL_MS);
|
|
43
|
+
if (known) {
|
|
44
|
+
if (!cancelled) setPlace(known);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const found = parsePlace(await fetchJson(reverseGeocodeUrl()), false);
|
|
48
|
+
if (!found || cancelled) return;
|
|
49
|
+
writeCache(PLACE_KEY, found);
|
|
50
|
+
setPlace(found);
|
|
51
|
+
})().catch(() => void 0);
|
|
52
|
+
return () => {
|
|
53
|
+
cancelled = true;
|
|
54
|
+
};
|
|
55
|
+
}, [enabled, place]);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!enabled || !place) return void 0;
|
|
58
|
+
let cancelled = false;
|
|
59
|
+
const key = `${place.latitude.toFixed(2)},${place.longitude.toFixed(2)},${unit}`;
|
|
60
|
+
const load = async () => {
|
|
61
|
+
const cached = await readCache(REPORT_KEY, REPORT_TTL_MS - 6e4);
|
|
62
|
+
if ((cached == null ? void 0 : cached.key) === key) {
|
|
63
|
+
if (!cancelled) setReport(cached.report);
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const next = parseOpenMeteo(await fetchJson(openMeteoUrl(place, unit)), unit);
|
|
67
|
+
if (!next || cancelled) return;
|
|
68
|
+
writeCache(REPORT_KEY, {
|
|
69
|
+
key,
|
|
70
|
+
report: next
|
|
71
|
+
});
|
|
72
|
+
setReport(next);
|
|
73
|
+
};
|
|
74
|
+
load().catch(() => void 0);
|
|
75
|
+
const timer = setInterval(() => load().catch(() => void 0), REPORT_TTL_MS);
|
|
76
|
+
return () => {
|
|
77
|
+
cancelled = true;
|
|
78
|
+
clearInterval(timer);
|
|
79
|
+
};
|
|
80
|
+
}, [enabled, place, unit]);
|
|
81
|
+
return {
|
|
82
|
+
place,
|
|
83
|
+
report
|
|
84
|
+
};
|
|
85
|
+
}export{useHomeWeather};//# sourceMappingURL=useHomeWeather.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useHomeWeather.js","sources":["../../../src/features/home/useHomeWeather.ts"],"sourcesContent":["/**\n * The place and weather for the chat home's ambient line, as the web's useWeather\n * (account/browser features/panels): the approximate place for the phone's network - so nothing\n * is asked - then Open-Meteo's conditions there, re-read every 20 minutes while the home is open.\n * Both are kept on the device (the place for 12 hours, the report for 20 minutes), so a cold\n * start paints them at once. Any failure just leaves them out of the line.\n */\nimport { useEffect, useMemo, useState } from 'react';\nimport AsyncStorage from '@react-native-async-storage/async-storage';\nimport {\n openMeteoUrl,\n parseOpenMeteo,\n parsePlace,\n preferredTemperatureUnit,\n reverseGeocodeUrl,\n type WeatherPlace,\n type WeatherReport,\n} from './weather';\n\nconst PLACE_KEY = 'yantra.home.weather.place.v1';\nconst REPORT_KEY = 'yantra.home.weather.report.v1';\nconst PLACE_TTL_MS = 12 * 60 * 60_000;\nconst REPORT_TTL_MS = 20 * 60_000;\nconst FETCH_TIMEOUT_MS = 10_000;\n\ninterface Stamped<T> {\n at: number;\n value: T;\n}\n\nasync function readCache<T>(key: string, maxAgeMs: number): Promise<T | null> {\n try {\n const raw = await AsyncStorage.getItem(key);\n const stamped = raw ? (JSON.parse(raw) as Stamped<T>) : null;\n return stamped && Date.now() - stamped.at < maxAgeMs ? stamped.value : null;\n } catch {\n return null;\n }\n}\n\nfunction writeCache<T>(key: string, value: T): void {\n AsyncStorage.setItem(key, JSON.stringify({ at: Date.now(), value })).catch(() => undefined);\n}\n\nasync function fetchJson(url: string): Promise<unknown> {\n const controller = new AbortController();\n const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);\n try {\n const response = await fetch(url, { signal: controller.signal });\n if (!response.ok) throw new Error(`${response.status}`);\n return await response.json();\n } finally {\n clearTimeout(timer);\n }\n}\n\nexport interface HomeWeather {\n place?: WeatherPlace;\n report?: WeatherReport;\n}\n\nexport function useHomeWeather(enabled = true): HomeWeather {\n const unit = useMemo(() => preferredTemperatureUnit(), []);\n const [place, setPlace] = useState<WeatherPlace>();\n const [report, setReport] = useState<WeatherReport>();\n\n // The place: the one kept on the device, else the approximate one for this network.\n useEffect(() => {\n if (!enabled || place) return undefined;\n let cancelled = false;\n (async () => {\n const known = await readCache<WeatherPlace>(PLACE_KEY, PLACE_TTL_MS);\n if (known) {\n if (!cancelled) setPlace(known);\n return;\n }\n const found = parsePlace(await fetchJson(reverseGeocodeUrl()), false);\n if (!found || cancelled) return;\n writeCache(PLACE_KEY, found);\n setPlace(found);\n })().catch(() => undefined);\n return () => {\n cancelled = true;\n };\n }, [enabled, place]);\n\n // The conditions there, re-read every 20 minutes while the home is open.\n useEffect(() => {\n if (!enabled || !place) return undefined;\n let cancelled = false;\n const key = `${place.latitude.toFixed(2)},${place.longitude.toFixed(2)},${unit}`;\n const load = async () => {\n // A minute short of the interval, so each tick reads fresh rather than its own last answer.\n const cached = await readCache<{ key: string; report: WeatherReport }>(REPORT_KEY, REPORT_TTL_MS - 60_000);\n if (cached?.key === key) {\n if (!cancelled) setReport(cached.report);\n return;\n }\n const next = parseOpenMeteo(await fetchJson(openMeteoUrl(place, unit)), unit);\n if (!next || cancelled) return;\n writeCache(REPORT_KEY, { key, report: next });\n setReport(next);\n };\n load().catch(() => undefined);\n const timer = setInterval(() => load().catch(() => undefined), REPORT_TTL_MS);\n return () => {\n cancelled = true;\n clearInterval(timer);\n };\n }, [enabled, place, unit]);\n\n return { place, report };\n}\n"],"names":[],"mappings":"gOAUA,MAAM,SAAY,GAAA,8BAAA;AAClB,MAAM,UAAa,GAAA,+BAAA;AACnB,MAAM,YAAA,GAAe,KAAK,EAAK,GAAA,GAAA;AAC/B,MAAM,gBAAgB,EAAK,GAAA,GAAA;AAC3B,MAAM,gBAAmB,GAAA,GAAA;AAKzB,eAAe,SAAA,CAAa,KAAa,QAAqC,EAAA;AAC5E,EAAI,IAAA;AACF,IAAA,MAAM,GAAM,GAAA,MAAM,YAAa,CAAA,OAAA,CAAQ,GAAG,CAAA;AAC1C,IAAA,MAAM,OAAU,GAAA,GAAA,GAAM,IAAK,CAAA,KAAA,CAAM,GAAG,CAAkB,GAAA,IAAA;AACtD,IAAO,OAAA,OAAA,IAAW,KAAK,GAAI,EAAA,GAAI,QAAQ,EAAK,GAAA,QAAA,GAAW,QAAQ,KAAQ,GAAA,IAAA;AAAA,GACjE,CAAA,OAAA,CAAA,EAAA;AACN,IAAO,OAAA,IAAA;AAAA;AAEX;AACA,SAAS,UAAA,CAAc,KAAa,KAAgB,EAAA;AAClD,EAAa,YAAA,CAAA,OAAA,CAAQ,GAAK,EAAA,IAAA,CAAK,SAAU,CAAA;AAAA,IACvC,EAAA,EAAI,KAAK,GAA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;AACA,IAAK,IAAA,EAAA,CAAE,KAAM,CAAA,MAAM,MAAS,CAAA;AAC5B,IAAM,MAAA,KAAA,GAAQ,YAAY,MAAM,IAAA,GAAO,KAAM,CAAA,MAAM,MAAS,CAAA,EAAG,aAAa,CAAA;AAC5E,IAAA,OAAO,MAAM;AACX,MAAY,SAAA,GAAA,IAAA;AACZ,MAAA,aAAA,CAAc,KAAK,CAAA;AAAA,KACrB;AAAA,GACC,EAAA,CAAC,OAAS,EAAA,KAAA,EAAO,IAAI,CAAC,CAAA;AACzB,EAAO,OAAA;AAAA,IACL,KAAA;AAAA,IACA;AAAA,GACF;AACF"}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
const BIGDATACLOUD_URL = "https://api.bigdatacloud.net/data/reverse-geocode-client";
|
|
21
|
+
const OPEN_METEO_URL = "https://api.open-meteo.com/v1/forecast";
|
|
22
|
+
const FAHRENHEIT_REGIONS = /* @__PURE__ */ new Set(["US", "BS", "BZ", "KY", "LR", "PW", "FM", "MH"]);
|
|
23
|
+
function preferredTemperatureUnit(locale) {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
let tag = "";
|
|
26
|
+
if (!tag) {
|
|
27
|
+
try {
|
|
28
|
+
tag = Intl.DateTimeFormat().resolvedOptions().locale;
|
|
29
|
+
} catch (e) {
|
|
30
|
+
tag = "en";
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
const region = (_b = (_a = tag.split(/[-_]/).slice(1).find((part) => /^[A-Za-z]{2}$/.test(part))) == null ? void 0 : _a.toUpperCase()) != null ? _b : "";
|
|
34
|
+
return FAHRENHEIT_REGIONS.has(region) ? "fahrenheit" : "celsius";
|
|
35
|
+
}
|
|
36
|
+
function query(params) {
|
|
37
|
+
return Object.entries(params).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join("&");
|
|
38
|
+
}
|
|
39
|
+
function reverseGeocodeUrl(coords) {
|
|
40
|
+
return `${BIGDATACLOUD_URL}?${query(__spreadProps(__spreadValues({}, {}), {
|
|
41
|
+
localityLanguage: "en"
|
|
42
|
+
}))}`;
|
|
43
|
+
}
|
|
44
|
+
const finite = (value) => typeof value === "number" && Number.isFinite(value) ? value : void 0;
|
|
45
|
+
const label = (value) => typeof value === "string" ? value.trim() : "";
|
|
46
|
+
function parsePlace(json, precise) {
|
|
47
|
+
const data = json != null ? json : {};
|
|
48
|
+
const latitude = finite(data.latitude);
|
|
49
|
+
const longitude = finite(data.longitude);
|
|
50
|
+
if (latitude === void 0 || longitude === void 0) return null;
|
|
51
|
+
if (Math.abs(latitude) > 90 || Math.abs(longitude) > 180 || latitude === 0 && longitude === 0) return null;
|
|
52
|
+
const town = label(data.locality) || label(data.city);
|
|
53
|
+
const region = label(data.principalSubdivision) || label(data.countryName) || label(data.countryCode);
|
|
54
|
+
const parts = [town, region].filter((part, index, all) => part && all.indexOf(part) === index);
|
|
55
|
+
return {
|
|
56
|
+
latitude,
|
|
57
|
+
longitude,
|
|
58
|
+
label: parts.join(", ") || "Your area",
|
|
59
|
+
precise
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function openMeteoUrl(place, unit) {
|
|
63
|
+
return `${OPEN_METEO_URL}?${query(__spreadValues({
|
|
64
|
+
// Two decimals (~1 km) is all a forecast needs, and keeps the cache key stable.
|
|
65
|
+
latitude: place.latitude.toFixed(2),
|
|
66
|
+
longitude: place.longitude.toFixed(2),
|
|
67
|
+
current: "temperature_2m,weather_code,is_day",
|
|
68
|
+
timezone: "auto",
|
|
69
|
+
forecast_days: "1"
|
|
70
|
+
}, unit === "fahrenheit" ? {
|
|
71
|
+
temperature_unit: "fahrenheit"
|
|
72
|
+
} : {}))}`;
|
|
73
|
+
}
|
|
74
|
+
function parseOpenMeteo(json, unit) {
|
|
75
|
+
var _a;
|
|
76
|
+
const current = (_a = (json != null ? json : {}).current) != null ? _a : {};
|
|
77
|
+
const temperature = finite(current.temperature_2m);
|
|
78
|
+
const code = finite(current.weather_code);
|
|
79
|
+
if (temperature === void 0 || code === void 0) return null;
|
|
80
|
+
return {
|
|
81
|
+
temperature,
|
|
82
|
+
code,
|
|
83
|
+
isDay: current.is_day !== 0,
|
|
84
|
+
unit
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function describeWeather(code, isDay) {
|
|
88
|
+
if (code === 0) return {
|
|
89
|
+
label: isDay ? "Sunny" : "Clear",
|
|
90
|
+
glyph: isDay ? "sun" : "moon"
|
|
91
|
+
};
|
|
92
|
+
if (code === 1) return {
|
|
93
|
+
label: "Mostly clear",
|
|
94
|
+
glyph: isDay ? "sun" : "moon"
|
|
95
|
+
};
|
|
96
|
+
if (code === 2) return {
|
|
97
|
+
label: "Partly cloudy",
|
|
98
|
+
glyph: isDay ? "cloud-sun" : "cloud-moon"
|
|
99
|
+
};
|
|
100
|
+
if (code === 3) return {
|
|
101
|
+
label: "Overcast",
|
|
102
|
+
glyph: "cloud"
|
|
103
|
+
};
|
|
104
|
+
if (code === 45 || code === 48) return {
|
|
105
|
+
label: "Foggy",
|
|
106
|
+
glyph: "fog"
|
|
107
|
+
};
|
|
108
|
+
if (code >= 51 && code <= 57) return {
|
|
109
|
+
label: "Drizzle",
|
|
110
|
+
glyph: "drizzle"
|
|
111
|
+
};
|
|
112
|
+
if (code >= 61 && code <= 67) return {
|
|
113
|
+
label: code >= 65 ? "Heavy rain" : "Rain",
|
|
114
|
+
glyph: "rain"
|
|
115
|
+
};
|
|
116
|
+
if (code >= 71 && code <= 77) return {
|
|
117
|
+
label: "Snow",
|
|
118
|
+
glyph: "snow"
|
|
119
|
+
};
|
|
120
|
+
if (code >= 80 && code <= 82) return {
|
|
121
|
+
label: "Showers",
|
|
122
|
+
glyph: "rain"
|
|
123
|
+
};
|
|
124
|
+
if (code === 85 || code === 86) return {
|
|
125
|
+
label: "Snow showers",
|
|
126
|
+
glyph: "snow"
|
|
127
|
+
};
|
|
128
|
+
if (code >= 95) return {
|
|
129
|
+
label: "Thunderstorms",
|
|
130
|
+
glyph: "storm"
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
label: "Cloudy",
|
|
134
|
+
glyph: "cloud"
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function degrees(value) {
|
|
138
|
+
return value === void 0 ? "\u2013" : `${Math.round(value)}\xB0`;
|
|
139
|
+
}export{BIGDATACLOUD_URL,OPEN_METEO_URL,degrees,describeWeather,openMeteoUrl,parseOpenMeteo,parsePlace,preferredTemperatureUnit,reverseGeocodeUrl};//# sourceMappingURL=weather.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"weather.js","sources":["../../../src/features/home/weather.ts"],"sourcesContent":["/**\n * The chat home's place and weather, as the web's (account/browser features/panels/weather.ts):\n * the place from BigDataCloud (its answer for the caller's network, so nothing is asked) and the\n * conditions from Open-Meteo - two keyless services. Pure helpers only; useHomeWeather fetches\n * and caches.\n *\n * Copied, not imported: mobile shares no code with the web shell. URLs are built by hand, since\n * React Native's `URL` polyfill throws on most of its API.\n */\n\nexport type TemperatureUnit = 'celsius' | 'fahrenheit';\n\nexport type WeatherGlyph =\n | 'sun'\n | 'moon'\n | 'cloud-sun'\n | 'cloud-moon'\n | 'cloud'\n | 'fog'\n | 'drizzle'\n | 'rain'\n | 'snow'\n | 'storm';\n\nexport interface WeatherPlace {\n latitude: number;\n longitude: number;\n /** \"Curchorem, Goa\". */\n label: string;\n /** From the person's own position (true) or their network's approximate one (false). */\n precise: boolean;\n}\n\nexport interface WeatherReport {\n temperature: number;\n code: number;\n isDay: boolean;\n unit: TemperatureUnit;\n}\n\nexport const BIGDATACLOUD_URL = 'https://api.bigdatacloud.net/data/reverse-geocode-client';\nexport const OPEN_METEO_URL = 'https://api.open-meteo.com/v1/forecast';\n\n/** Countries that read temperatures in Fahrenheit. */\nconst FAHRENHEIT_REGIONS = new Set(['US', 'BS', 'BZ', 'KY', 'LR', 'PW', 'FM', 'MH']);\n\n/** The device locale's region decides the unit, as the browser's language does on the web. */\nexport function preferredTemperatureUnit(locale?: string): TemperatureUnit {\n let tag = locale ?? '';\n if (!tag) {\n try {\n tag = Intl.DateTimeFormat().resolvedOptions().locale;\n } catch {\n tag = 'en';\n }\n }\n const region =\n tag\n .split(/[-_]/)\n .slice(1)\n .find((part) => /^[A-Za-z]{2}$/.test(part))\n ?.toUpperCase() ?? '';\n return FAHRENHEIT_REGIONS.has(region) ? 'fahrenheit' : 'celsius';\n}\n\nfunction query(params: Record<string, string>): string {\n return Object.entries(params)\n .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)\n .join('&');\n}\n\n/** With coordinates: reverse geocoding. Without: the service answers for the caller's network (approximate). */\nexport function reverseGeocodeUrl(coords?: { latitude: number; longitude: number }): string {\n return `${BIGDATACLOUD_URL}?${query({\n ...(coords ? { latitude: coords.latitude.toFixed(4), longitude: coords.longitude.toFixed(4) } : {}),\n localityLanguage: 'en',\n })}`;\n}\n\nconst finite = (value: unknown): number | undefined =>\n typeof value === 'number' && Number.isFinite(value) ? value : undefined;\n\nconst label = (value: unknown): string => (typeof value === 'string' ? value.trim() : '');\n\n/** A BigDataCloud answer as a place; null without usable coordinates. */\nexport function parsePlace(json: unknown, precise: boolean): WeatherPlace | null {\n const data = (json ?? {}) as Record<string, unknown>;\n const latitude = finite(data.latitude);\n const longitude = finite(data.longitude);\n if (latitude === undefined || longitude === undefined) return null;\n if (Math.abs(latitude) > 90 || Math.abs(longitude) > 180 || (latitude === 0 && longitude === 0)) return null;\n const town = label(data.locality) || label(data.city);\n const region = label(data.principalSubdivision) || label(data.countryName) || label(data.countryCode);\n const parts = [town, region].filter((part, index, all) => part && all.indexOf(part) === index);\n return { latitude, longitude, label: parts.join(', ') || 'Your area', precise };\n}\n\nexport function openMeteoUrl(place: Pick<WeatherPlace, 'latitude' | 'longitude'>, unit: TemperatureUnit): string {\n return `${OPEN_METEO_URL}?${query({\n // Two decimals (~1 km) is all a forecast needs, and keeps the cache key stable.\n latitude: place.latitude.toFixed(2),\n longitude: place.longitude.toFixed(2),\n current: 'temperature_2m,weather_code,is_day',\n timezone: 'auto',\n forecast_days: '1',\n ...(unit === 'fahrenheit' ? { temperature_unit: 'fahrenheit' } : {}),\n })}`;\n}\n\nexport function parseOpenMeteo(json: unknown, unit: TemperatureUnit): WeatherReport | null {\n const current = ((json ?? {}) as { current?: Record<string, unknown> }).current ?? {};\n const temperature = finite(current.temperature_2m);\n const code = finite(current.weather_code);\n if (temperature === undefined || code === undefined) return null;\n return { temperature, code, isDay: current.is_day !== 0, unit };\n}\n\n/** WMO weather interpretation codes (Open-Meteo's `weather_code`), in the web's words. */\nexport function describeWeather(code: number, isDay: boolean): { label: string; glyph: WeatherGlyph } {\n if (code === 0) return { label: isDay ? 'Sunny' : 'Clear', glyph: isDay ? 'sun' : 'moon' };\n if (code === 1) return { label: 'Mostly clear', glyph: isDay ? 'sun' : 'moon' };\n if (code === 2) return { label: 'Partly cloudy', glyph: isDay ? 'cloud-sun' : 'cloud-moon' };\n if (code === 3) return { label: 'Overcast', glyph: 'cloud' };\n if (code === 45 || code === 48) return { label: 'Foggy', glyph: 'fog' };\n if (code >= 51 && code <= 57) return { label: 'Drizzle', glyph: 'drizzle' };\n if (code >= 61 && code <= 67) return { label: code >= 65 ? 'Heavy rain' : 'Rain', glyph: 'rain' };\n if (code >= 71 && code <= 77) return { label: 'Snow', glyph: 'snow' };\n if (code >= 80 && code <= 82) return { label: 'Showers', glyph: 'rain' };\n if (code === 85 || code === 86) return { label: 'Snow showers', glyph: 'snow' };\n if (code >= 95) return { label: 'Thunderstorms', glyph: 'storm' };\n return { label: 'Cloudy', glyph: 'cloud' };\n}\n\n/** \"25°\" - whole degrees. */\nexport function degrees(value: number | undefined): string {\n return value === undefined ? '–' : `${Math.round(value)}°`;\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;AA0BO,MAAM,gBAAmB,GAAA;AACzB,MAAM,cAAiB,GAAA;AAG9B,MAAM,kBAAqB,mBAAA,IAAI,GAAI,CAAA,CAAC,IAAM,EAAA,IAAA,EAAM,IAAM,EAAA,IAAA,EAAM,IAAM,EAAA,IAAA,EAAM,IAAM,EAAA,IAAI,CAAC,CAAA;AAG5E,SAAS,yBAAyB,MAAkC,EAAA;AAjC3E,EAAA,IAAA,EAAA,EAAA,EAAA;AAkCE,EAAA,IAAI,MAAgB,EAAA;AACpB,EAAA,IAAI,CAAC,GAAK,EAAA;AACR,IAAI,IAAA;AACF,MAAA,GAAA,GAAM,IAAK,CAAA,cAAA,EAAiB,CAAA,eAAA,EAAkB,CAAA,MAAA;AAAA,KACxC,CAAA,OAAA,CAAA,EAAA;AACN,MAAM,GAAA,GAAA,IAAA;AAAA;AACR;AAEF,EAAA,MAAM,UAAS,EAAI,GAAA,CAAA,EAAA,GAAA,GAAA,CAAA,KAAA,CAAM,MAAM,CAAA,CAAE,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