ink-framework-location 0.1.0-alpha.1 → 0.1.0-alpha.12

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/index.ts +23 -0
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "ink-framework-location",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.12",
4
4
  "exports": {
5
5
  ".": "./src/index.ts"
6
6
  },
7
7
  "peerDependencies": {
8
- "ink": "npm:ink-framework@0.1.0-alpha.1"
8
+ "ink": "npm:ink-framework@0.1.0-alpha.12"
9
9
  },
10
10
  "license": "MIT",
11
11
  "repository": {
package/src/index.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { callNative, NativeError } from "ink/native";
2
2
 
3
3
  export type LocationAccuracy = "balanced" | "high";
4
+ export interface DefaultLocation {
5
+ latitude: number;
6
+ longitude: number;
7
+ }
8
+
4
9
  export interface LocationFix {
5
10
  latitude: number;
6
11
  longitude: number;
@@ -59,6 +64,24 @@ function parseTracking(value: unknown): LocationTrackingState {
59
64
  }
60
65
 
61
66
  export const location = {
67
+ async default(): Promise<DefaultLocation | null> {
68
+ const version = await callNative("light-sdk", "version", "");
69
+ if (!/^\d+\.\d+\.\d+$/.test(version)) {
70
+ throw new NativeError("protocol", "Invalid Light SDK version");
71
+ }
72
+ const [major, minor, patch] = version.split(".").map(Number);
73
+ if (major === 0 && (minor < 1 || (minor === 1 && patch < 2))) {
74
+ throw new NativeError("unsupported", "LightOS default location requires Light SDK 0.1.2 or newer");
75
+ }
76
+ const value: unknown = JSON.parse(await callNative("light-sdk", "default-location", ""));
77
+ if (value === null) return null;
78
+ if (typeof value !== "object"
79
+ || !("latitude" in value) || typeof value.latitude !== "number" || !Number.isFinite(value.latitude) || Math.abs(value.latitude) > 90
80
+ || !("longitude" in value) || typeof value.longitude !== "number" || !Number.isFinite(value.longitude) || Math.abs(value.longitude) > 180) {
81
+ throw new NativeError("protocol", "Invalid default location");
82
+ }
83
+ return { latitude: value.latitude, longitude: value.longitude };
84
+ },
62
85
  async *watch(options: LocationWatchOptions = {}): AsyncGenerator<LocationFix> {
63
86
  const watch = Number(await callNative("location", "watch-start", updateOptions(options), { signal: options.signal }));
64
87
  if (!Number.isSafeInteger(watch) || watch <= 0) throw new NativeError("protocol", "Invalid location watch");