sa2kit 3.7.0 → 3.9.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.
- package/dist/{chunk-ZJLS5JU5.mjs → chunk-6KD4CD7O.mjs} +7 -16
- package/dist/chunk-6KD4CD7O.mjs.map +1 -0
- package/dist/chunk-FV7IHC23.js +751 -0
- package/dist/chunk-FV7IHC23.js.map +1 -0
- package/dist/chunk-GJVEYCS4.js +12 -0
- package/dist/chunk-GJVEYCS4.js.map +1 -0
- package/dist/chunk-OOVINE7M.mjs +715 -0
- package/dist/chunk-OOVINE7M.mjs.map +1 -0
- package/dist/chunk-PPV4IEWR.mjs +8 -0
- package/dist/chunk-PPV4IEWR.mjs.map +1 -0
- package/dist/{chunk-XPY45Y75.js → chunk-VVHFMAE7.js} +9 -21
- package/dist/chunk-VVHFMAE7.js.map +1 -0
- package/dist/common/aiApi/client/index.d.mts +66 -4
- package/dist/common/aiApi/client/index.d.ts +66 -4
- package/dist/common/aiApi/client/index.js +360 -15
- package/dist/common/aiApi/client/index.js.map +1 -1
- package/dist/common/aiApi/client/index.mjs +345 -11
- package/dist/common/aiApi/client/index.mjs.map +1 -1
- package/dist/common/aiApi/index.d.mts +2 -2
- package/dist/common/aiApi/index.d.ts +2 -2
- package/dist/common/aiApi/index.js +63 -62
- package/dist/common/aiApi/index.mjs +2 -1
- package/dist/common/aiApi/server/index.d.mts +1 -1
- package/dist/common/aiApi/server/index.d.ts +1 -1
- package/dist/common/aiApi/server/index.js +63 -62
- package/dist/common/aiApi/server/index.mjs +2 -1
- package/dist/common/appLauncher/index.d.mts +32 -0
- package/dist/common/appLauncher/index.d.ts +32 -0
- package/dist/common/appLauncher/index.js +149 -0
- package/dist/common/appLauncher/index.js.map +1 -0
- package/dist/common/appLauncher/index.mjs +4 -0
- package/dist/common/appLauncher/index.mjs.map +1 -0
- package/dist/common/appLauncher/rn/index.d.mts +35 -0
- package/dist/common/appLauncher/rn/index.d.ts +35 -0
- package/dist/common/appLauncher/rn/index.js +100 -0
- package/dist/common/appLauncher/rn/index.js.map +1 -0
- package/dist/common/appLauncher/rn/index.mjs +31 -0
- package/dist/common/appLauncher/rn/index.mjs.map +1 -0
- package/dist/index-BHgDdlJW.d.mts +177 -0
- package/dist/index-BHgDdlJW.d.ts +177 -0
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +3 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -9
- package/dist/index.mjs.map +1 -1
- package/dist/{types-CiqMQ-uu.d.mts → types-DgbG0Of-.d.mts} +9 -1
- package/dist/{types-CiqMQ-uu.d.ts → types-DgbG0Of-.d.ts} +9 -1
- package/package.json +11 -1
- package/dist/chunk-XPY45Y75.js.map +0 -1
- package/dist/chunk-ZJLS5JU5.mjs.map +0 -1
|
@@ -0,0 +1,715 @@
|
|
|
1
|
+
import { __require } from './chunk-MAI35PU6.mjs';
|
|
2
|
+
|
|
3
|
+
// src/common/appLauncher/adapters/rn.ts
|
|
4
|
+
function createRnAppLaunchAdapter(linking) {
|
|
5
|
+
const platform = "rn";
|
|
6
|
+
return {
|
|
7
|
+
platform,
|
|
8
|
+
async canOpen(url) {
|
|
9
|
+
try {
|
|
10
|
+
return await linking.canOpenURL(url);
|
|
11
|
+
} catch {
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
async launch(urls, options) {
|
|
16
|
+
const baseResult = {
|
|
17
|
+
provider: options.provider,
|
|
18
|
+
action: options.action,
|
|
19
|
+
platform
|
|
20
|
+
};
|
|
21
|
+
const tryOpen = async (url) => {
|
|
22
|
+
const canOpen = await linking.canOpenURL(url).catch(() => false);
|
|
23
|
+
if (!canOpen) {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
await linking.openURL(url);
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
if (await tryOpen(urls.primary)) {
|
|
30
|
+
const result2 = {
|
|
31
|
+
...baseResult,
|
|
32
|
+
status: "opened",
|
|
33
|
+
url: urls.primary
|
|
34
|
+
};
|
|
35
|
+
options.callbacks?.onOpened?.(result2);
|
|
36
|
+
return result2;
|
|
37
|
+
}
|
|
38
|
+
if (urls.fallback && await tryOpen(urls.fallback)) {
|
|
39
|
+
const result2 = {
|
|
40
|
+
...baseResult,
|
|
41
|
+
status: "fallback",
|
|
42
|
+
url: urls.fallback
|
|
43
|
+
};
|
|
44
|
+
options.callbacks?.onFallback?.(result2);
|
|
45
|
+
return result2;
|
|
46
|
+
}
|
|
47
|
+
const result = {
|
|
48
|
+
...baseResult,
|
|
49
|
+
status: "unavailable",
|
|
50
|
+
url: urls.primary
|
|
51
|
+
};
|
|
52
|
+
options.callbacks?.onUnavailable?.(result);
|
|
53
|
+
return result;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
function createRnAppLaunchAdapterFromReactNative() {
|
|
58
|
+
let linking;
|
|
59
|
+
try {
|
|
60
|
+
linking = __require("react-native").Linking;
|
|
61
|
+
} catch {
|
|
62
|
+
throw new Error(
|
|
63
|
+
"[appLauncher/rn] \u672A\u627E\u5230 react-native\uFF0C\u8BF7\u4F7F\u7528 createRnAppLaunchAdapter(linking) \u624B\u52A8\u6CE8\u5165 Linking"
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
return createRnAppLaunchAdapter(linking);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/common/appLauncher/detect.ts
|
|
70
|
+
function isAndroid(userAgent = getUserAgent()) {
|
|
71
|
+
return /Android/i.test(userAgent);
|
|
72
|
+
}
|
|
73
|
+
function isIOS(userAgent = getUserAgent()) {
|
|
74
|
+
return /iPhone|iPad|iPod/i.test(userAgent);
|
|
75
|
+
}
|
|
76
|
+
function isMobileDevice(userAgent = getUserAgent()) {
|
|
77
|
+
return isAndroid(userAgent) || isIOS(userAgent);
|
|
78
|
+
}
|
|
79
|
+
function getUserAgent() {
|
|
80
|
+
if (typeof navigator === "undefined") {
|
|
81
|
+
return "";
|
|
82
|
+
}
|
|
83
|
+
return navigator.userAgent;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/common/appLauncher/adapters/web.ts
|
|
87
|
+
function dispatchCallbacks(options, result) {
|
|
88
|
+
const { callbacks } = options;
|
|
89
|
+
if (!callbacks) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
switch (result.status) {
|
|
93
|
+
case "opened":
|
|
94
|
+
callbacks.onOpened?.(result);
|
|
95
|
+
break;
|
|
96
|
+
case "fallback":
|
|
97
|
+
callbacks.onFallback?.(result);
|
|
98
|
+
break;
|
|
99
|
+
case "unavailable":
|
|
100
|
+
case "timeout":
|
|
101
|
+
case "cancelled":
|
|
102
|
+
callbacks.onUnavailable?.(result);
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
function openUrl(url, mobile) {
|
|
107
|
+
if (typeof window === "undefined") {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (mobile) {
|
|
111
|
+
window.location.assign(url);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
window.open(url, "_blank", "noopener,noreferrer");
|
|
115
|
+
}
|
|
116
|
+
function waitForAppOpen(timeoutMs) {
|
|
117
|
+
return new Promise((resolve) => {
|
|
118
|
+
if (typeof document === "undefined") {
|
|
119
|
+
resolve("opened");
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
let settled = false;
|
|
123
|
+
const finish = (status) => {
|
|
124
|
+
if (settled) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
settled = true;
|
|
128
|
+
document.removeEventListener("visibilitychange", onVisibilityChange);
|
|
129
|
+
window.clearTimeout(timer);
|
|
130
|
+
resolve(status);
|
|
131
|
+
};
|
|
132
|
+
const onVisibilityChange = () => {
|
|
133
|
+
if (document.hidden) {
|
|
134
|
+
finish("opened");
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
document.addEventListener("visibilitychange", onVisibilityChange);
|
|
138
|
+
const timer = window.setTimeout(() => finish("timeout"), timeoutMs);
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
function createWebAppLaunchAdapter() {
|
|
142
|
+
const platform = "web";
|
|
143
|
+
return {
|
|
144
|
+
platform,
|
|
145
|
+
async launch(urls, options) {
|
|
146
|
+
const mobile = isMobileDevice();
|
|
147
|
+
const baseResult = {
|
|
148
|
+
provider: options.provider,
|
|
149
|
+
action: options.action,
|
|
150
|
+
platform
|
|
151
|
+
};
|
|
152
|
+
openUrl(urls.primary, mobile);
|
|
153
|
+
if (mobile) {
|
|
154
|
+
const status = await waitForAppOpen(options.timeoutMs);
|
|
155
|
+
if (status === "opened") {
|
|
156
|
+
const result3 = {
|
|
157
|
+
...baseResult,
|
|
158
|
+
status: "opened",
|
|
159
|
+
url: urls.primary
|
|
160
|
+
};
|
|
161
|
+
dispatchCallbacks(options, result3);
|
|
162
|
+
return result3;
|
|
163
|
+
}
|
|
164
|
+
if (urls.fallback) {
|
|
165
|
+
openUrl(urls.fallback, true);
|
|
166
|
+
const result3 = {
|
|
167
|
+
...baseResult,
|
|
168
|
+
status: "fallback",
|
|
169
|
+
url: urls.fallback
|
|
170
|
+
};
|
|
171
|
+
dispatchCallbacks(options, result3);
|
|
172
|
+
return result3;
|
|
173
|
+
}
|
|
174
|
+
const result2 = {
|
|
175
|
+
...baseResult,
|
|
176
|
+
status: "timeout",
|
|
177
|
+
url: urls.primary
|
|
178
|
+
};
|
|
179
|
+
dispatchCallbacks(options, result2);
|
|
180
|
+
return result2;
|
|
181
|
+
}
|
|
182
|
+
const result = {
|
|
183
|
+
...baseResult,
|
|
184
|
+
status: "opened",
|
|
185
|
+
url: urls.primary
|
|
186
|
+
};
|
|
187
|
+
dispatchCallbacks(options, result);
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// src/common/appLauncher/core/config.ts
|
|
194
|
+
var defaultConfig = {
|
|
195
|
+
sourceApplication: "sa2kit"
|
|
196
|
+
};
|
|
197
|
+
var runtimeConfig = { ...defaultConfig };
|
|
198
|
+
function configureAppLauncher(patch) {
|
|
199
|
+
runtimeConfig = {
|
|
200
|
+
...runtimeConfig,
|
|
201
|
+
...patch,
|
|
202
|
+
defaultOptions: {
|
|
203
|
+
...runtimeConfig.defaultOptions,
|
|
204
|
+
...patch.defaultOptions
|
|
205
|
+
},
|
|
206
|
+
defaultCallbacks: {
|
|
207
|
+
...runtimeConfig.defaultCallbacks,
|
|
208
|
+
...patch.defaultCallbacks
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
return getAppLauncherConfig();
|
|
212
|
+
}
|
|
213
|
+
function getAppLauncherConfig() {
|
|
214
|
+
return runtimeConfig;
|
|
215
|
+
}
|
|
216
|
+
function resetAppLauncherConfig() {
|
|
217
|
+
runtimeConfig = { ...defaultConfig };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
// src/common/appLauncher/types.ts
|
|
221
|
+
var AppLaunchError = class extends Error {
|
|
222
|
+
constructor(code, message, details) {
|
|
223
|
+
super(message);
|
|
224
|
+
this.name = "AppLaunchError";
|
|
225
|
+
this.code = code;
|
|
226
|
+
this.details = details;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
// src/common/appLauncher/utils/query.ts
|
|
231
|
+
function requireNonEmptyString(value, field) {
|
|
232
|
+
if (typeof value !== "string" || !value.trim()) {
|
|
233
|
+
throw new AppLaunchError("INVALID_PARAMS", `${field} \u4E0D\u80FD\u4E3A\u7A7A`);
|
|
234
|
+
}
|
|
235
|
+
return value.trim();
|
|
236
|
+
}
|
|
237
|
+
function encodeQuery(value) {
|
|
238
|
+
return encodeURIComponent(value);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
// src/common/appLauncher/providers/amap.ts
|
|
242
|
+
function buildKeywordNavigationUrl(destination, sourceApplication) {
|
|
243
|
+
const keyword = encodeQuery(destination);
|
|
244
|
+
if (typeof navigator !== "undefined" && isAndroid()) {
|
|
245
|
+
return `androidamap://keywordNavi?sourceApplication=${encodeQuery(sourceApplication)}&keyword=${keyword}&style=2`;
|
|
246
|
+
}
|
|
247
|
+
return `https://uri.amap.com/navigation?to=,,${keyword}&mode=car&callnative=1`;
|
|
248
|
+
}
|
|
249
|
+
function buildCoordinateNavigationUrl(params, sourceApplication) {
|
|
250
|
+
const name = params.destination ? encodeQuery(params.destination) : "";
|
|
251
|
+
const mode = params.mode ?? "car";
|
|
252
|
+
const lon = params.longitude;
|
|
253
|
+
const lat = params.latitude;
|
|
254
|
+
const primary = typeof navigator !== "undefined" && isAndroid() ? `androidamap://route?sourceApplication=${encodeQuery(sourceApplication)}&dlat=${lat}&dlon=${lon}&dname=${name}&dev=0&t=0` : `iosamap://navi?sourceApplication=${encodeQuery(sourceApplication)}&lat=${lat}&lon=${lon}&dev=0&style=2`;
|
|
255
|
+
const fallback = `https://uri.amap.com/navigation?to=${lon},${lat},${name}&mode=${mode}&callnative=1`;
|
|
256
|
+
return { primary, fallback };
|
|
257
|
+
}
|
|
258
|
+
var amapProvider = {
|
|
259
|
+
id: "amap",
|
|
260
|
+
actions: ["navigate", "navigateByCoordinate"],
|
|
261
|
+
validateParams(action, params) {
|
|
262
|
+
if (action === "navigate") {
|
|
263
|
+
requireNonEmptyString(params.destination, "destination");
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (action === "navigateByCoordinate") {
|
|
267
|
+
if (typeof params.latitude !== "number" || typeof params.longitude !== "number") {
|
|
268
|
+
throw new AppLaunchError(
|
|
269
|
+
"INVALID_PARAMS",
|
|
270
|
+
"navigateByCoordinate \u9700\u8981 latitude \u4E0E longitude"
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
},
|
|
275
|
+
buildUrls(action, params, context) {
|
|
276
|
+
const sourceApplication = context.sourceApplication;
|
|
277
|
+
if (action === "navigate") {
|
|
278
|
+
const destination = requireNonEmptyString(params.destination, "destination");
|
|
279
|
+
const url = buildKeywordNavigationUrl(destination, sourceApplication);
|
|
280
|
+
const fallback = context.options.fallbackUrl ?? `https://uri.amap.com/search?keyword=${encodeQuery(destination)}&callnative=1`;
|
|
281
|
+
return { primary: url, fallback };
|
|
282
|
+
}
|
|
283
|
+
if (action === "navigateByCoordinate") {
|
|
284
|
+
const coordinateParams = {
|
|
285
|
+
latitude: params.latitude,
|
|
286
|
+
longitude: params.longitude,
|
|
287
|
+
destination: params.destination,
|
|
288
|
+
mode: params.mode
|
|
289
|
+
};
|
|
290
|
+
const urls = buildCoordinateNavigationUrl(coordinateParams, sourceApplication);
|
|
291
|
+
if (context.options.fallbackUrl) {
|
|
292
|
+
urls.fallback = context.options.fallbackUrl;
|
|
293
|
+
}
|
|
294
|
+
return urls;
|
|
295
|
+
}
|
|
296
|
+
throw new Error(`[amapProvider] \u4E0D\u652F\u6301 action: ${action}`);
|
|
297
|
+
}
|
|
298
|
+
};
|
|
299
|
+
function buildAmapNavigationUrl(destination, sourceApplication = "sa2kit") {
|
|
300
|
+
return buildKeywordNavigationUrl(destination, sourceApplication);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// src/common/appLauncher/providers/baidu.ts
|
|
304
|
+
function buildSrcParam(sourceApplication) {
|
|
305
|
+
const normalized = sourceApplication.replace(/[^a-zA-Z0-9._-]/g, "");
|
|
306
|
+
return `andr.web.${normalized || "sa2kit"}`;
|
|
307
|
+
}
|
|
308
|
+
function buildKeywordNavigationUrl2(destination, sourceApplication) {
|
|
309
|
+
const encodedDestination = encodeQuery(destination);
|
|
310
|
+
const src = encodeQuery(buildSrcParam(sourceApplication));
|
|
311
|
+
return [
|
|
312
|
+
"baidumap://map/navi",
|
|
313
|
+
`?destination=${encodedDestination}`,
|
|
314
|
+
"&mode=driving",
|
|
315
|
+
"&coord_type=gcj02",
|
|
316
|
+
`&src=${src}`
|
|
317
|
+
].join("");
|
|
318
|
+
}
|
|
319
|
+
var baiduProvider = {
|
|
320
|
+
id: "baidu",
|
|
321
|
+
actions: ["navigate", "navigateByCoordinate"],
|
|
322
|
+
validateParams(action, params) {
|
|
323
|
+
if (action === "navigate") {
|
|
324
|
+
requireNonEmptyString(params.destination, "destination");
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (action === "navigateByCoordinate") {
|
|
328
|
+
if (typeof params.latitude !== "number" || typeof params.longitude !== "number") {
|
|
329
|
+
throw new AppLaunchError(
|
|
330
|
+
"INVALID_PARAMS",
|
|
331
|
+
"navigateByCoordinate \u9700\u8981 latitude \u4E0E longitude"
|
|
332
|
+
);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
},
|
|
336
|
+
buildUrls(action, params, context) {
|
|
337
|
+
const sourceApplication = context.sourceApplication;
|
|
338
|
+
if (action === "navigate") {
|
|
339
|
+
const destination = requireNonEmptyString(params.destination, "destination");
|
|
340
|
+
const primary = buildKeywordNavigationUrl2(destination, sourceApplication);
|
|
341
|
+
const encodedDestination = encodeQuery(destination);
|
|
342
|
+
return {
|
|
343
|
+
primary,
|
|
344
|
+
fallback: context.options.fallbackUrl ?? `https://map.baidu.com/mobile/webapp/search/search/qt=na&wd=${encodedDestination}&mode=MAP_MODE&newmap=1`
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
if (action === "navigateByCoordinate") {
|
|
348
|
+
const latitude = String(params.latitude);
|
|
349
|
+
const longitude = String(params.longitude);
|
|
350
|
+
const name = params.destination ? encodeQuery(String(params.destination)) : "";
|
|
351
|
+
const src = encodeQuery(buildSrcParam(sourceApplication));
|
|
352
|
+
const destination = name ? `latlng:${latitude},${longitude}|name:${name}` : `latlng:${latitude},${longitude}`;
|
|
353
|
+
return {
|
|
354
|
+
primary: `baidumap://map/navi?destination=${encodeQuery(destination)}&mode=driving&coord_type=gcj02&src=${src}`,
|
|
355
|
+
fallback: context.options.fallbackUrl ?? `https://map.baidu.com/mobile/webapp/search/search/qt=na&wd=${encodeQuery(`${latitude},${longitude}`)}&mode=MAP_MODE&newmap=1`
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
throw new Error(`[baiduProvider] \u4E0D\u652F\u6301 action: ${action}`);
|
|
359
|
+
}
|
|
360
|
+
};
|
|
361
|
+
function buildBaiduNavigationUrl(destination, sourceApplication = "sa2kit") {
|
|
362
|
+
return buildKeywordNavigationUrl2(destination, sourceApplication);
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// src/common/appLauncher/providers/generic.ts
|
|
366
|
+
var genericProvider = {
|
|
367
|
+
id: "generic",
|
|
368
|
+
actions: ["open"],
|
|
369
|
+
validateParams(_action, params) {
|
|
370
|
+
requireNonEmptyString(params.url, "url");
|
|
371
|
+
},
|
|
372
|
+
buildUrls(_action, params, context) {
|
|
373
|
+
const url = requireNonEmptyString(params.url, "url");
|
|
374
|
+
const fallback = context.options.fallbackUrl ?? (typeof params.fallback === "string" ? params.fallback : void 0);
|
|
375
|
+
return { primary: url, fallback };
|
|
376
|
+
}
|
|
377
|
+
};
|
|
378
|
+
|
|
379
|
+
// src/common/appLauncher/providers/google.ts
|
|
380
|
+
function buildKeywordNavigationUrl3(destination) {
|
|
381
|
+
const encoded = encodeQuery(destination);
|
|
382
|
+
const primary = typeof navigator !== "undefined" && isAndroid() ? `google.navigation:q=${encoded}` : `comgooglemaps://?daddr=${encoded}&directionsmode=driving`;
|
|
383
|
+
return {
|
|
384
|
+
primary,
|
|
385
|
+
fallback: `https://www.google.com/maps/dir/?api=1&destination=${encoded}&travelmode=driving`
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
function buildCoordinateNavigationUrl2(latitude, longitude, destination) {
|
|
389
|
+
const coordinateQuery = destination ? encodeQuery(destination) : `${latitude},${longitude}`;
|
|
390
|
+
const primary = typeof navigator !== "undefined" && isAndroid() ? `google.navigation:q=${latitude},${longitude}` : `comgooglemaps://?daddr=${coordinateQuery}&directionsmode=driving`;
|
|
391
|
+
const fallbackDestination = destination ? encodeQuery(destination) : `${latitude},${longitude}`;
|
|
392
|
+
return {
|
|
393
|
+
primary,
|
|
394
|
+
fallback: `https://www.google.com/maps/dir/?api=1&destination=${fallbackDestination}&travelmode=driving`
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
var googleProvider = {
|
|
398
|
+
id: "google",
|
|
399
|
+
actions: ["navigate", "navigateByCoordinate"],
|
|
400
|
+
validateParams(action, params) {
|
|
401
|
+
if (action === "navigate") {
|
|
402
|
+
requireNonEmptyString(params.destination, "destination");
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (action === "navigateByCoordinate") {
|
|
406
|
+
if (typeof params.latitude !== "number" || typeof params.longitude !== "number") {
|
|
407
|
+
throw new AppLaunchError(
|
|
408
|
+
"INVALID_PARAMS",
|
|
409
|
+
"navigateByCoordinate \u9700\u8981 latitude \u4E0E longitude"
|
|
410
|
+
);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
},
|
|
414
|
+
buildUrls(action, params, context) {
|
|
415
|
+
if (action === "navigate") {
|
|
416
|
+
const destination = requireNonEmptyString(params.destination, "destination");
|
|
417
|
+
const urls = buildKeywordNavigationUrl3(destination);
|
|
418
|
+
if (context.options.fallbackUrl) {
|
|
419
|
+
urls.fallback = context.options.fallbackUrl;
|
|
420
|
+
}
|
|
421
|
+
return urls;
|
|
422
|
+
}
|
|
423
|
+
if (action === "navigateByCoordinate") {
|
|
424
|
+
const urls = buildCoordinateNavigationUrl2(
|
|
425
|
+
params.latitude,
|
|
426
|
+
params.longitude,
|
|
427
|
+
params.destination
|
|
428
|
+
);
|
|
429
|
+
if (context.options.fallbackUrl) {
|
|
430
|
+
urls.fallback = context.options.fallbackUrl;
|
|
431
|
+
}
|
|
432
|
+
return urls;
|
|
433
|
+
}
|
|
434
|
+
throw new Error(`[googleProvider] \u4E0D\u652F\u6301 action: ${action}`);
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
function buildGoogleNavigationUrl(destination) {
|
|
438
|
+
return buildKeywordNavigationUrl3(destination).primary;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// src/common/appLauncher/providers/qq.ts
|
|
442
|
+
var qqProvider = {
|
|
443
|
+
id: "qq",
|
|
444
|
+
actions: ["share", "open"],
|
|
445
|
+
validateParams(action, params) {
|
|
446
|
+
if (action === "open") {
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
requireNonEmptyString(params.title, "title");
|
|
450
|
+
requireNonEmptyString(params.url, "url");
|
|
451
|
+
},
|
|
452
|
+
buildUrls(action, params, context) {
|
|
453
|
+
if (action === "open") {
|
|
454
|
+
return {
|
|
455
|
+
primary: "mqqapi://",
|
|
456
|
+
fallback: context.options.fallbackUrl ?? "https://im.qq.com/"
|
|
457
|
+
};
|
|
458
|
+
}
|
|
459
|
+
const title = encodeQuery(requireNonEmptyString(params.title, "title"));
|
|
460
|
+
const summary = encodeQuery(
|
|
461
|
+
typeof params.summary === "string" ? params.summary : ""
|
|
462
|
+
);
|
|
463
|
+
const url = encodeQuery(requireNonEmptyString(params.url, "url"));
|
|
464
|
+
const imageUrl = params.imageUrl ? encodeQuery(String(params.imageUrl)) : "";
|
|
465
|
+
const primary = [
|
|
466
|
+
"mqqapi://share/to_fri",
|
|
467
|
+
"?src_type=web",
|
|
468
|
+
"&version=1",
|
|
469
|
+
"&file_type=news",
|
|
470
|
+
`&title=${title}`,
|
|
471
|
+
`&description=${summary}`,
|
|
472
|
+
`&url=${url}`,
|
|
473
|
+
imageUrl ? `&image_url=${imageUrl}` : ""
|
|
474
|
+
].join("");
|
|
475
|
+
return {
|
|
476
|
+
primary,
|
|
477
|
+
fallback: context.options.fallbackUrl ?? `https://connect.qq.com/`
|
|
478
|
+
};
|
|
479
|
+
}
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// src/common/appLauncher/providers/wechat.ts
|
|
483
|
+
var wechatProvider = {
|
|
484
|
+
id: "wechat",
|
|
485
|
+
actions: ["open", "share"],
|
|
486
|
+
validateParams(action, params) {
|
|
487
|
+
if (action === "open") {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
requireNonEmptyString(params.title, "title");
|
|
491
|
+
requireNonEmptyString(params.url, "url");
|
|
492
|
+
},
|
|
493
|
+
buildUrls(action, params, context) {
|
|
494
|
+
const sourceApplication = encodeQuery(context.sourceApplication);
|
|
495
|
+
if (action === "open") {
|
|
496
|
+
return {
|
|
497
|
+
primary: `weixin://`,
|
|
498
|
+
fallback: context.options.fallbackUrl ?? "https://weixin.qq.com/"
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
const title = encodeQuery(requireNonEmptyString(params.title, "title"));
|
|
502
|
+
const description = encodeQuery(
|
|
503
|
+
typeof params.description === "string" ? params.description : ""
|
|
504
|
+
);
|
|
505
|
+
const url = encodeQuery(requireNonEmptyString(params.url, "url"));
|
|
506
|
+
params.thumbUrl ? encodeQuery(String(params.thumbUrl)) : "";
|
|
507
|
+
const primary = `weixin://dl/businessWebview/link?appid=&url=${url}&title=${title}&description=${description}`;
|
|
508
|
+
return {
|
|
509
|
+
primary,
|
|
510
|
+
fallback: context.options.fallbackUrl ?? `https://open.weixin.qq.com/connect/oauth2/authorize?appid=APPID&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo&state=${sourceApplication}#wechat_redirect`
|
|
511
|
+
};
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
|
|
515
|
+
// src/common/appLauncher/providers/registry.ts
|
|
516
|
+
var builtinProviders = {
|
|
517
|
+
amap: amapProvider,
|
|
518
|
+
baidu: baiduProvider,
|
|
519
|
+
google: googleProvider,
|
|
520
|
+
wechat: wechatProvider,
|
|
521
|
+
qq: qqProvider,
|
|
522
|
+
generic: genericProvider
|
|
523
|
+
};
|
|
524
|
+
var customProviders = /* @__PURE__ */ new Map();
|
|
525
|
+
function registerAppProvider(provider) {
|
|
526
|
+
customProviders.set(provider.id, provider);
|
|
527
|
+
}
|
|
528
|
+
function getAppProvider(id) {
|
|
529
|
+
return customProviders.get(id) ?? builtinProviders[id];
|
|
530
|
+
}
|
|
531
|
+
function listAppProviders() {
|
|
532
|
+
const ids = /* @__PURE__ */ new Set([
|
|
533
|
+
...Object.keys(builtinProviders),
|
|
534
|
+
...customProviders.keys()
|
|
535
|
+
]);
|
|
536
|
+
return [...ids];
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// src/common/appLauncher/core/launcher.ts
|
|
540
|
+
function resolveAdapter(request) {
|
|
541
|
+
const config = getAppLauncherConfig();
|
|
542
|
+
const adapter = request.adapter ?? config.adapter;
|
|
543
|
+
if (adapter) {
|
|
544
|
+
return adapter;
|
|
545
|
+
}
|
|
546
|
+
if (typeof window !== "undefined") {
|
|
547
|
+
return createWebAppLaunchAdapter();
|
|
548
|
+
}
|
|
549
|
+
throw new AppLaunchError(
|
|
550
|
+
"ADAPTER_MISSING",
|
|
551
|
+
"\u672A\u914D\u7F6E AppLaunchAdapter\uFF0C\u8BF7\u5728\u5BBF\u4E3B\u542F\u52A8\u65F6\u8C03\u7528 configureAppLauncher({ adapter })"
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
async function launchApp(request) {
|
|
555
|
+
const config = getAppLauncherConfig();
|
|
556
|
+
const provider = getAppProvider(request.provider);
|
|
557
|
+
if (!provider) {
|
|
558
|
+
throw new AppLaunchError("UNKNOWN_PROVIDER", `\u672A\u77E5 provider: ${request.provider}`);
|
|
559
|
+
}
|
|
560
|
+
if (!provider.actions.includes(request.action)) {
|
|
561
|
+
throw new AppLaunchError(
|
|
562
|
+
"UNKNOWN_ACTION",
|
|
563
|
+
`provider "${request.provider}" \u4E0D\u652F\u6301 action "${request.action}"`,
|
|
564
|
+
{ supportedActions: [...provider.actions] }
|
|
565
|
+
);
|
|
566
|
+
}
|
|
567
|
+
const params = request.params ?? {};
|
|
568
|
+
provider.validateParams?.(request.action, params);
|
|
569
|
+
const mergedOptions = {
|
|
570
|
+
sourceApplication: config.sourceApplication,
|
|
571
|
+
timeoutMs: 1500,
|
|
572
|
+
...config.defaultOptions,
|
|
573
|
+
...request.options
|
|
574
|
+
};
|
|
575
|
+
const urls = provider.buildUrls(request.action, params, {
|
|
576
|
+
sourceApplication: mergedOptions.sourceApplication ?? config.sourceApplication,
|
|
577
|
+
options: mergedOptions
|
|
578
|
+
});
|
|
579
|
+
if (mergedOptions.fallbackUrl && !urls.fallback) {
|
|
580
|
+
urls.fallback = mergedOptions.fallbackUrl;
|
|
581
|
+
}
|
|
582
|
+
const adapter = resolveAdapter(request);
|
|
583
|
+
const callbacks = {
|
|
584
|
+
...config.defaultCallbacks,
|
|
585
|
+
...request.callbacks
|
|
586
|
+
};
|
|
587
|
+
try {
|
|
588
|
+
return await adapter.launch(urls, {
|
|
589
|
+
provider: request.provider,
|
|
590
|
+
action: request.action,
|
|
591
|
+
timeoutMs: mergedOptions.timeoutMs ?? 1500,
|
|
592
|
+
callbacks
|
|
593
|
+
});
|
|
594
|
+
} catch (error) {
|
|
595
|
+
const launchError = error instanceof AppLaunchError ? error : new AppLaunchError(
|
|
596
|
+
"OPEN_FAILED",
|
|
597
|
+
error instanceof Error ? error.message : "\u5524\u8D77\u7B2C\u4E09\u65B9 App \u5931\u8D25"
|
|
598
|
+
);
|
|
599
|
+
callbacks.onError?.(launchError);
|
|
600
|
+
throw launchError;
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
// src/common/appLauncher/core/return-handler.ts
|
|
605
|
+
function parseReturnUrl(url) {
|
|
606
|
+
let parsed;
|
|
607
|
+
try {
|
|
608
|
+
parsed = new URL(url);
|
|
609
|
+
} catch {
|
|
610
|
+
return { url, params: {} };
|
|
611
|
+
}
|
|
612
|
+
const params = {};
|
|
613
|
+
parsed.searchParams.forEach((value, key) => {
|
|
614
|
+
params[key] = value;
|
|
615
|
+
});
|
|
616
|
+
const provider = parsed.searchParams.get("provider");
|
|
617
|
+
return {
|
|
618
|
+
provider: provider ?? void 0,
|
|
619
|
+
action: parsed.searchParams.get("action") ?? void 0,
|
|
620
|
+
url,
|
|
621
|
+
params
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
625
|
+
function notifyAppReturn(payload) {
|
|
626
|
+
listeners.forEach((listener) => listener(payload));
|
|
627
|
+
}
|
|
628
|
+
function subscribeAppReturn(listener) {
|
|
629
|
+
listeners.add(listener);
|
|
630
|
+
return () => listeners.delete(listener);
|
|
631
|
+
}
|
|
632
|
+
function matchesReturnUrl(incomingUrl, expectedReturnUrl) {
|
|
633
|
+
if (!expectedReturnUrl) {
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
if (incomingUrl === expectedReturnUrl) {
|
|
637
|
+
return true;
|
|
638
|
+
}
|
|
639
|
+
try {
|
|
640
|
+
const incoming = new URL(incomingUrl);
|
|
641
|
+
const expected = new URL(expectedReturnUrl);
|
|
642
|
+
return incoming.protocol === expected.protocol && incoming.hostname === expected.hostname && incoming.pathname === expected.pathname;
|
|
643
|
+
} catch {
|
|
644
|
+
return incomingUrl.startsWith(expectedReturnUrl);
|
|
645
|
+
}
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
// src/common/appLauncher/shortcuts/map-navigation.ts
|
|
649
|
+
var MAP_NAVIGATION_OPTIONS = [
|
|
650
|
+
{ id: "amap", label: "\u9AD8\u5FB7\u5730\u56FE", description: "\u56FD\u5185\u5E38\u7528\uFF0C\u652F\u6301\u5173\u952E\u8BCD\u5BFC\u822A" },
|
|
651
|
+
{ id: "baidu", label: "\u767E\u5EA6\u5730\u56FE", description: "\u56FD\u5185\u5E38\u7528\uFF0C\u652F\u6301\u5173\u952E\u8BCD\u5BFC\u822A" },
|
|
652
|
+
{ id: "google", label: "\u8C37\u6B4C\u5730\u56FE", description: "\u6D77\u5916\u6216\u5DF2\u5B89\u88C5 Google Maps \u65F6\u9002\u7528" }
|
|
653
|
+
];
|
|
654
|
+
async function launchMapNavigation(provider, destination, options) {
|
|
655
|
+
const { callbacks, ...launchOptions } = options ?? {};
|
|
656
|
+
return launchApp({
|
|
657
|
+
provider,
|
|
658
|
+
action: "navigate",
|
|
659
|
+
params: { destination },
|
|
660
|
+
options: launchOptions,
|
|
661
|
+
callbacks
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
function openMapNavigation(provider, destination, options) {
|
|
665
|
+
void launchMapNavigation(provider, destination, options);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
// src/common/appLauncher/shortcuts/index.ts
|
|
669
|
+
async function launchAmapNavigation(destination, options) {
|
|
670
|
+
const { callbacks, ...launchOptions } = options ?? {};
|
|
671
|
+
return launchApp({
|
|
672
|
+
provider: "amap",
|
|
673
|
+
action: "navigate",
|
|
674
|
+
params: { destination },
|
|
675
|
+
options: launchOptions,
|
|
676
|
+
callbacks
|
|
677
|
+
});
|
|
678
|
+
}
|
|
679
|
+
function openAmapNavigation(destination, options) {
|
|
680
|
+
void launchAmapNavigation(destination, options);
|
|
681
|
+
}
|
|
682
|
+
async function launchWechatShare(options) {
|
|
683
|
+
const { callbacks, title, description, url, thumbUrl, ...launchOptions } = options;
|
|
684
|
+
return launchApp({
|
|
685
|
+
provider: "wechat",
|
|
686
|
+
action: "share",
|
|
687
|
+
params: { title, description, url, thumbUrl },
|
|
688
|
+
options: launchOptions,
|
|
689
|
+
callbacks
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
async function launchQqShare(options) {
|
|
693
|
+
const { callbacks, title, summary, url, imageUrl, ...launchOptions } = options;
|
|
694
|
+
return launchApp({
|
|
695
|
+
provider: "qq",
|
|
696
|
+
action: "share",
|
|
697
|
+
params: { title, summary, url, imageUrl },
|
|
698
|
+
options: launchOptions,
|
|
699
|
+
callbacks
|
|
700
|
+
});
|
|
701
|
+
}
|
|
702
|
+
async function launchGenericUrl(url, options) {
|
|
703
|
+
const { callbacks, fallback, ...launchOptions } = options ?? {};
|
|
704
|
+
return launchApp({
|
|
705
|
+
provider: "generic",
|
|
706
|
+
action: "open",
|
|
707
|
+
params: { url, fallback },
|
|
708
|
+
options: launchOptions,
|
|
709
|
+
callbacks
|
|
710
|
+
});
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
export { AppLaunchError, MAP_NAVIGATION_OPTIONS, amapProvider, baiduProvider, buildAmapNavigationUrl, buildBaiduNavigationUrl, buildGoogleNavigationUrl, configureAppLauncher, createRnAppLaunchAdapter, createRnAppLaunchAdapterFromReactNative, createWebAppLaunchAdapter, genericProvider, getAppLauncherConfig, getAppProvider, googleProvider, isAndroid, isIOS, isMobileDevice, launchAmapNavigation, launchApp, launchGenericUrl, launchMapNavigation, launchQqShare, launchWechatShare, listAppProviders, matchesReturnUrl, notifyAppReturn, openAmapNavigation, openMapNavigation, parseReturnUrl, qqProvider, registerAppProvider, resetAppLauncherConfig, subscribeAppReturn, wechatProvider };
|
|
714
|
+
//# sourceMappingURL=chunk-OOVINE7M.mjs.map
|
|
715
|
+
//# sourceMappingURL=chunk-OOVINE7M.mjs.map
|