@classic-homes/maps-core 0.4.1 → 0.5.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.
@@ -179,15 +179,25 @@ function googleDirectionsUrl(stops, origin, travelmode) {
179
179
  if (travelmode) url += `&travelmode=${encodeURIComponent(travelmode)}`;
180
180
  return url;
181
181
  }
182
+ var APPLE_MODES = { d: "driving", w: "walking", r: "transit" };
182
183
  function appleDirectionsUrl(stops, origin, dirflg = "d") {
183
184
  const encoded = usableTargets(stops);
184
185
  if (encoded.length === 0) return "";
185
186
  const encodedOrigin = origin ? encodeTarget(origin) : null;
186
- const daddr = encoded[0];
187
- let url = `${APPLE_BASE}?`;
188
- if (encodedOrigin) url += `saddr=${encodedOrigin}&`;
189
- url += `daddr=${daddr}&dirflg=${encodeURIComponent(dirflg)}`;
190
- return url;
187
+ if (encoded.length === 1) {
188
+ let url = `${APPLE_BASE}?`;
189
+ if (encodedOrigin) url += `saddr=${encodedOrigin}&`;
190
+ url += `daddr=${encoded[0]}&dirflg=${encodeURIComponent(dirflg)}`;
191
+ return url;
192
+ }
193
+ const destination = encoded[encoded.length - 1];
194
+ const waypoints = encoded.slice(0, -1);
195
+ const mode = APPLE_MODES[dirflg] ?? APPLE_MODES.d;
196
+ const params = [];
197
+ if (encodedOrigin) params.push(`source=${encodedOrigin}`);
198
+ for (const waypoint of waypoints) params.push(`waypoint=${waypoint}`);
199
+ params.push(`destination=${destination}`, `mode=${mode}`);
200
+ return `${APPLE_BASE}directions?${params.join("&")}`;
191
201
  }
192
202
  function googleSearchUrl(query) {
193
203
  return `${GOOGLE_SEARCH_BASE}&query=${encodeURIComponent(query)}`;
@@ -112,13 +112,17 @@ declare const GOOGLE_MAX_LEG_STOPS: number;
112
112
  */
113
113
  declare function googleDirectionsUrl(stops: DirectionsTarget[], origin?: DirectionsTarget | null, travelmode?: TravelMode): string;
114
114
  /**
115
- * An Apple Maps URL.
115
+ * An Apple Maps directions URL.
116
116
  *
117
- * The maps.apple.com scheme has NO waypoint parameter - `saddr` and `daddr`
118
- * only. For a multi-stop input this deliberately returns the leg to the FIRST
119
- * stop rather than silently dropping the rest, and callers must label the
120
- * affordance accordingly ("Apple Maps (first stop)"). Returns '' when no
121
- * target is usable.
117
+ * With one stop this returns the legacy `saddr`/`daddr` form, exactly
118
+ * `https://maps.apple.com/?daddr=<lat>,<lng>&dirflg=d` with no origin - the
119
+ * form consumer apps already link to, and one every iOS version opens.
120
+ *
121
+ * With several stops it returns Apple's unified Maps URL (iOS 18.4, macOS 15.4
122
+ * and later): `/directions` with the last stop as `destination` and the rest as
123
+ * repeated `waypoint` parameters, in order. Apple documents no waypoint limit.
124
+ * Older OS versions predate the unified scheme, so what they do with a
125
+ * multi-stop link is not guaranteed. Returns '' when no target is usable.
122
126
  */
123
127
  declare function appleDirectionsUrl(stops: DirectionsTarget[], origin?: DirectionsTarget | null, dirflg?: 'd' | 'w' | 'r'): string;
124
128
  /** A Google Maps search URL - the fallback for a stop with no coordinate */
@@ -112,13 +112,17 @@ declare const GOOGLE_MAX_LEG_STOPS: number;
112
112
  */
113
113
  declare function googleDirectionsUrl(stops: DirectionsTarget[], origin?: DirectionsTarget | null, travelmode?: TravelMode): string;
114
114
  /**
115
- * An Apple Maps URL.
115
+ * An Apple Maps directions URL.
116
116
  *
117
- * The maps.apple.com scheme has NO waypoint parameter - `saddr` and `daddr`
118
- * only. For a multi-stop input this deliberately returns the leg to the FIRST
119
- * stop rather than silently dropping the rest, and callers must label the
120
- * affordance accordingly ("Apple Maps (first stop)"). Returns '' when no
121
- * target is usable.
117
+ * With one stop this returns the legacy `saddr`/`daddr` form, exactly
118
+ * `https://maps.apple.com/?daddr=<lat>,<lng>&dirflg=d` with no origin - the
119
+ * form consumer apps already link to, and one every iOS version opens.
120
+ *
121
+ * With several stops it returns Apple's unified Maps URL (iOS 18.4, macOS 15.4
122
+ * and later): `/directions` with the last stop as `destination` and the rest as
123
+ * repeated `waypoint` parameters, in order. Apple documents no waypoint limit.
124
+ * Older OS versions predate the unified scheme, so what they do with a
125
+ * multi-stop link is not guaranteed. Returns '' when no target is usable.
122
126
  */
123
127
  declare function appleDirectionsUrl(stops: DirectionsTarget[], origin?: DirectionsTarget | null, dirflg?: 'd' | 'w' | 'r'): string;
124
128
  /** A Google Maps search URL - the fallback for a stop with no coordinate */
@@ -164,15 +164,25 @@ function googleDirectionsUrl(stops, origin, travelmode) {
164
164
  if (travelmode) url += `&travelmode=${encodeURIComponent(travelmode)}`;
165
165
  return url;
166
166
  }
167
+ var APPLE_MODES = { d: "driving", w: "walking", r: "transit" };
167
168
  function appleDirectionsUrl(stops, origin, dirflg = "d") {
168
169
  const encoded = usableTargets(stops);
169
170
  if (encoded.length === 0) return "";
170
171
  const encodedOrigin = origin ? encodeTarget(origin) : null;
171
- const daddr = encoded[0];
172
- let url = `${APPLE_BASE}?`;
173
- if (encodedOrigin) url += `saddr=${encodedOrigin}&`;
174
- url += `daddr=${daddr}&dirflg=${encodeURIComponent(dirflg)}`;
175
- return url;
172
+ if (encoded.length === 1) {
173
+ let url = `${APPLE_BASE}?`;
174
+ if (encodedOrigin) url += `saddr=${encodedOrigin}&`;
175
+ url += `daddr=${encoded[0]}&dirflg=${encodeURIComponent(dirflg)}`;
176
+ return url;
177
+ }
178
+ const destination = encoded[encoded.length - 1];
179
+ const waypoints = encoded.slice(0, -1);
180
+ const mode = APPLE_MODES[dirflg] ?? APPLE_MODES.d;
181
+ const params = [];
182
+ if (encodedOrigin) params.push(`source=${encodedOrigin}`);
183
+ for (const waypoint of waypoints) params.push(`waypoint=${waypoint}`);
184
+ params.push(`destination=${destination}`, `mode=${mode}`);
185
+ return `${APPLE_BASE}directions?${params.join("&")}`;
176
186
  }
177
187
  function googleSearchUrl(query) {
178
188
  return `${GOOGLE_SEARCH_BASE}&query=${encodeURIComponent(query)}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/maps-core",
3
- "version": "0.4.1",
3
+ "version": "0.5.0",
4
4
  "description": "Core utilities and theme for Classic Theme maps",
5
5
  "keywords": [
6
6
  "maps",