@escape-game-over/atlas 0.1.72 → 0.1.73

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@escape-game-over/atlas",
3
- "version": "0.1.72",
3
+ "version": "0.1.73",
4
4
  "type": "module",
5
5
  "description": "Typed, data-driven machinery for static multi-locale, multi-deployment Astro sites.",
6
6
  "private": false,
package/src/index.ts CHANGED
@@ -175,7 +175,7 @@ export {
175
175
  type LlmsItem,
176
176
  type LlmsSection,
177
177
  } from "./llms.ts";
178
- export type { MapPlace } from "./map.ts";
178
+ export { googleMapsUrl, type MapPlace, type MapsTarget } from "./map.ts";
179
179
  export {
180
180
  type ArticleContent,
181
181
  buildMeta,
package/src/map.ts CHANGED
@@ -29,6 +29,61 @@ export type MapFrame =
29
29
  readonly east: number;
30
30
  };
31
31
 
32
+ /** What a Google Maps link opens on. */
33
+ export interface MapsTarget {
34
+ /**
35
+ * The place's name, or where it is.
36
+ *
37
+ * Required even with a `placeId`: Google's link format takes the id as a
38
+ * refinement of a search rather than instead of one, and falls back to the
39
+ * search when it cannot use the id. A name searches better than a pair of
40
+ * numbers, so pass one where there is one.
41
+ */
42
+ readonly query: string | Coordinates;
43
+ /**
44
+ * Google's Place ID (`ChIJ…`): the listing itself, with its reviews and
45
+ * directions, rather than whatever a search turns up first. A short
46
+ * `maps.app.goo.gl` link points at the same listing, but cannot be built,
47
+ * checked or told apart from a link to the mall next door.
48
+ */
49
+ readonly placeId?: string;
50
+ }
51
+
52
+ /**
53
+ * A link that opens Google Maps on a place: its listing when it has a Place ID,
54
+ * otherwise a search.
55
+ *
56
+ * Google's documented, key-free format, so it works without the Maps
57
+ * JavaScript API and outlives any short link.
58
+ *
59
+ * @see https://developers.google.com/maps/documentation/urls/get-started#search-action
60
+ */
61
+ export function googleMapsUrl(target: MapsTarget): HttpsUrl {
62
+ let query: string;
63
+ if (typeof target.query === "string") {
64
+ query = target.query.trim();
65
+ if (query === "") {
66
+ throw new Error(
67
+ "googleMapsUrl: an empty query searches for nothing."
68
+ );
69
+ }
70
+ } else {
71
+ assertCoordinates(target.query, "googleMapsUrl");
72
+ query = `${target.query.latitude},${target.query.longitude}`;
73
+ }
74
+
75
+ const params = new URLSearchParams({ api: "1", query });
76
+ if (target.placeId !== undefined) {
77
+ if (target.placeId.trim() === "") {
78
+ throw new Error(
79
+ `googleMapsUrl: "${query}" has an empty Place ID; leave it out to search instead.`
80
+ );
81
+ }
82
+ params.set("query_place_id", target.placeId);
83
+ }
84
+ return `https://www.google.com/maps/search/?${params.toString()}`;
85
+ }
86
+
32
87
  /** Street level: close enough to find the door. */
33
88
  const POINT_ZOOM = 15;
34
89