@heycar/heycars-map 2.0.0-switchMap4 → 2.0.0-switchMap6

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 (51) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/v2/api/pingConnection.d.ts +9 -0
  4. package/dist/v2/api/pingConnection.js +107 -0
  5. package/dist/v2/chunks/{Loading.f2515cd7.js → Loading.492acbc2.js} +2 -2
  6. package/dist/v2/components/Loading/Loading.js +3 -3
  7. package/dist/v2/components/Loading/index.js +3 -3
  8. package/dist/v2/components/MapProvider/MapProvider.js +13 -10
  9. package/dist/v2/hooks/useDeviceOrientation.js +17 -1
  10. package/dist/v2/hooks/useDrivingRoute.js +4 -0
  11. package/dist/v2/hooks/useMapGCJ02.js +3 -31
  12. package/dist/v2/hooks/useMapLoader.d.ts +4 -2
  13. package/dist/v2/hooks/useMapLoader.js +110 -85
  14. package/dist/v2/hooks/useMapSupplier.d.ts +2 -0
  15. package/dist/v2/hooks/usePingConnection.d.ts +10 -0
  16. package/dist/v2/hooks/usePingConnection.js +26 -0
  17. package/dist/v2/types/global.d.ts +3 -0
  18. package/dist/v2/types/interface.d.ts +1 -1
  19. package/dist/v2/utils/helper.d.ts +1 -0
  20. package/dist/v2/utils/helper.js +12 -0
  21. package/dist/v2/utils/log.js +1 -1
  22. package/dist/v3/api/pingConnection.d.ts +9 -0
  23. package/dist/v3/api/pingConnection.js +107 -0
  24. package/dist/v3/chunks/{Loading.32ae3c98.js → Loading.21d8e759.js} +2 -2
  25. package/dist/v3/components/Loading/Loading.js +3 -3
  26. package/dist/v3/components/Loading/index.js +3 -3
  27. package/dist/v3/components/MapProvider/MapProvider.js +13 -10
  28. package/dist/v3/hooks/useDeviceOrientation.js +17 -1
  29. package/dist/v3/hooks/useDrivingRoute.js +4 -0
  30. package/dist/v3/hooks/useMapGCJ02.js +3 -31
  31. package/dist/v3/hooks/useMapLoader.d.ts +4 -2
  32. package/dist/v3/hooks/useMapLoader.js +110 -85
  33. package/dist/v3/hooks/useMapSupplier.d.ts +2 -0
  34. package/dist/v3/hooks/usePingConnection.d.ts +10 -0
  35. package/dist/v3/hooks/usePingConnection.js +26 -0
  36. package/dist/v3/types/global.d.ts +3 -0
  37. package/dist/v3/types/interface.d.ts +1 -1
  38. package/dist/v3/utils/helper.d.ts +1 -0
  39. package/dist/v3/utils/helper.js +12 -0
  40. package/dist/v3/utils/log.js +1 -1
  41. package/package.json +1 -1
  42. package/dist/v2/api/googleConnection.d.ts +0 -5
  43. package/dist/v2/api/googleConnection.js +0 -51
  44. package/dist/v2/chunks/throttle.8bdd8d3b.js +0 -20
  45. package/dist/v2/hooks/useGoogleConnection.d.ts +0 -7
  46. package/dist/v2/hooks/useGoogleConnection.js +0 -15
  47. package/dist/v3/api/googleConnection.d.ts +0 -5
  48. package/dist/v3/api/googleConnection.js +0 -51
  49. package/dist/v3/chunks/throttle.8bdd8d3b.js +0 -20
  50. package/dist/v3/hooks/useGoogleConnection.d.ts +0 -7
  51. package/dist/v3/hooks/useGoogleConnection.js +0 -15
@@ -20,3 +20,6 @@ declare global {
20
20
  deviceorientationabsolute: DeviceOrientationEvent;
21
21
  }
22
22
  }
23
+ declare module "@amap/amap-jsapi-loader" {
24
+ const reset: () => void;
25
+ }
@@ -93,7 +93,7 @@ export declare enum CenterPlaceStatus {
93
93
  SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
94
94
  OK = "OK"
95
95
  }
96
- export type GoogleConnectionStatus = "pending" | "connected" | "unconnected";
96
+ export type ConnectionStatus = "pending" | "connected" | "unconnected";
97
97
  export interface BusinessGeolocationPositionError extends GeolocationPositionError {
98
98
  isBusinessTimeout: boolean;
99
99
  }
@@ -22,6 +22,7 @@ export declare const pausableSleep: (milliSeconds: number) => {
22
22
  restart: () => void;
23
23
  };
24
24
  export declare const createRunOnce: <P extends any[], R>(fn: (...args: P) => R) => (...args: P) => R;
25
+ export declare const createOneConcurrent: <P extends any[], R>(fn: (...args: P) => Promise<R>) => (...args: P) => Promise<R> | undefined;
25
26
  export declare const createReadOnce: <T>(value: T) => () => T | undefined;
26
27
  export declare const createAsyncNoFailNonNullable: <P extends any[], R>(fn: (...args: P) => Promise<R>, defaultValue: NonNullable<R>) => (...args: P) => Promise<NonNullable<R>>;
27
28
  export declare const pipeTimeout: <P extends any[], R>(fn: (...args: P) => Promise<R>, defaultValue: R, timeout: number) => (...args: P) => Promise<R>;
@@ -93,6 +93,17 @@ const createRunOnce = (fn) => {
93
93
  return result;
94
94
  };
95
95
  };
96
+ const createOneConcurrent = (fn) => {
97
+ let isRunning = false;
98
+ return function runOneConcurrent(...args) {
99
+ if (isRunning)
100
+ return;
101
+ isRunning = true;
102
+ const result = fn(...args);
103
+ result.finally(() => isRunning = false);
104
+ return result;
105
+ };
106
+ };
96
107
  const createReadOnce = (value) => {
97
108
  let isRead = false;
98
109
  return function read() {
@@ -171,6 +182,7 @@ export {
171
182
  assertZone,
172
183
  createAbortable,
173
184
  createAsyncNoFailNonNullable,
185
+ createOneConcurrent,
174
186
  createReadOnce,
175
187
  createRunOnce,
176
188
  defered,
@@ -1,6 +1,6 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.0.0-switchMap4";
3
+ const pkgVersion = "2.0.0-switchMap6";
4
4
  const isEnableLog = (name) => {
5
5
  const searchParam = new URLSearchParams(location.search);
6
6
  return searchParam.has(`log-${name}`);
@@ -0,0 +1,9 @@
1
+ import type { ConnectionStatus } from "../types/interface";
2
+ export type PingConnectionOnChangeHandler = (status: ConnectionStatus) => void;
3
+ export type PingConnectionOnChangeCleanup = () => void;
4
+ export declare const apiGetPingAmapStatus: () => ConnectionStatus;
5
+ export declare const apiGetPingGmapStatus: () => ConnectionStatus;
6
+ export declare const apiPingAmap: () => Promise<ConnectionStatus>;
7
+ export declare const apiPingGmap: () => Promise<ConnectionStatus>;
8
+ export declare const apiSubscribePingAmapChange: (handler: PingConnectionOnChangeHandler) => PingConnectionOnChangeCleanup;
9
+ export declare const apiSubscribePingGmapChange: (handler: PingConnectionOnChangeHandler) => PingConnectionOnChangeCleanup;
@@ -0,0 +1,107 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { sleep } from "../utils/helper.js";
8
+ const PING_AMAP_URL = "https://webapi.amap.com/favicon.ico";
9
+ const PING_AMAP_TIMEOUT = 5e3;
10
+ const PING_AMAP_INTERVAL = 5e3;
11
+ const PING_GMAP_URL = "https://maps.googleapis.com/";
12
+ const PING_GMAP_TIMEOUT = 5e3;
13
+ const PING_GMAP_INTERVAL = 5e3;
14
+ const noop = () => {
15
+ };
16
+ const toUncachableUrl = (url, label = "") => {
17
+ const parsedUrl = new URL(url);
18
+ const randomKey = `ping${Date.now()}`;
19
+ parsedUrl.searchParams.set(randomKey, label);
20
+ return parsedUrl.toString();
21
+ };
22
+ class PingConnection {
23
+ constructor({ timeout, url }) {
24
+ __publicField(this, "timeout");
25
+ __publicField(this, "url");
26
+ __publicField(this, "status", "pending");
27
+ __publicField(this, "listeners", /* @__PURE__ */ new Set());
28
+ __publicField(this, "updatingPromise");
29
+ this.timeout = timeout;
30
+ this.url = url;
31
+ }
32
+ // 只有订阅了 onChange 事件,listen 才会更新状态
33
+ async listen(interval) {
34
+ while (true) {
35
+ if (this.listeners.size > 0)
36
+ await this.updateStatus();
37
+ await sleep(interval);
38
+ }
39
+ }
40
+ async updateStatus() {
41
+ const { url, timeout } = this;
42
+ if (this.updatingPromise)
43
+ return this.updatingPromise;
44
+ return this.updatingPromise = this.check(url, timeout).then((status) => {
45
+ this.status = status;
46
+ this.updatingPromise = void 0;
47
+ for (const handler of this.listeners) {
48
+ try {
49
+ handler(status);
50
+ } catch (err) {
51
+ console.error(err);
52
+ }
53
+ }
54
+ return status;
55
+ });
56
+ }
57
+ check(url, timeout) {
58
+ const controller = new AbortController();
59
+ const timer = setTimeout(() => controller.abort(), timeout);
60
+ return fetch(toUncachableUrl(url, timeout.toString()), {
61
+ signal: controller.signal,
62
+ method: "HEAD",
63
+ mode: "no-cors"
64
+ }).then(() => "connected").catch(() => "unconnected").finally(() => clearTimeout(timer));
65
+ }
66
+ onChange(handler) {
67
+ if (typeof handler !== "function")
68
+ return noop;
69
+ this.listeners.add(handler);
70
+ const clear = () => {
71
+ this.listeners.delete(handler);
72
+ };
73
+ return clear;
74
+ }
75
+ }
76
+ const pingAmapConnection = new PingConnection({
77
+ timeout: PING_AMAP_TIMEOUT,
78
+ url: PING_AMAP_URL
79
+ });
80
+ const pingGmapConnection = new PingConnection({
81
+ timeout: PING_GMAP_TIMEOUT,
82
+ url: PING_GMAP_URL
83
+ });
84
+ pingAmapConnection.listen(PING_AMAP_INTERVAL);
85
+ pingGmapConnection.listen(PING_GMAP_INTERVAL);
86
+ const apiGetPingAmapStatus = () => {
87
+ return pingAmapConnection.status;
88
+ };
89
+ const apiGetPingGmapStatus = () => {
90
+ return pingGmapConnection.status;
91
+ };
92
+ const apiPingAmap = () => {
93
+ return pingAmapConnection.updateStatus();
94
+ };
95
+ const apiPingGmap = () => {
96
+ return pingGmapConnection.updateStatus();
97
+ };
98
+ const apiSubscribePingAmapChange = (handler) => pingAmapConnection.onChange(handler);
99
+ const apiSubscribePingGmapChange = (handler) => pingGmapConnection.onChange(handler);
100
+ export {
101
+ apiGetPingAmapStatus,
102
+ apiGetPingGmapStatus,
103
+ apiPingAmap,
104
+ apiPingGmap,
105
+ apiSubscribePingAmapChange,
106
+ apiSubscribePingGmapChange
107
+ };
@@ -41,7 +41,7 @@ const LoadFailed = defineSetup("LoadFailed", function(props) {
41
41
  }, [props.description])])]);
42
42
  });
43
43
  export {
44
- Loading as L,
45
- LoadFailed as a,
44
+ LoadFailed as L,
45
+ Loading as a,
46
46
  imgGrid as i
47
47
  };
@@ -1,9 +1,9 @@
1
1
  import "vue";
2
2
  import "../../api/cdn.js";
3
- import { a, L } from "../../chunks/Loading.32ae3c98.js";
3
+ import { L, a } from "../../chunks/Loading.21d8e759.js";
4
4
  import "../../business-components/AbsoluteAddressBox/AbsoluteAddressBox.js";
5
5
  import "../../types/helper.js";
6
6
  export {
7
- a as LoadFailed,
8
- L as Loading
7
+ L as LoadFailed,
8
+ a as Loading
9
9
  };
@@ -1,5 +1,5 @@
1
- import { a, L } from "../../chunks/Loading.32ae3c98.js";
1
+ import { L, a } from "../../chunks/Loading.21d8e759.js";
2
2
  export {
3
- a as LoadFailed,
4
- L as Loading
3
+ L as LoadFailed,
4
+ a as Loading
5
5
  };
@@ -1,6 +1,6 @@
1
1
  import "../../css/MapProvider-156bfd53.css";
2
2
  import { createVNode, isVNode } from "vue";
3
- import { L as Loading, a as LoadFailed, i as imgGrid } from "../../chunks/Loading.32ae3c98.js";
3
+ import { L as LoadFailed, a as Loading, i as imgGrid } from "../../chunks/Loading.21d8e759.js";
4
4
  import { useMapLoader, Status } from "../../hooks/useMapLoader.js";
5
5
  import { provideMapSupplier, useMapSupplier } from "../../hooks/useMapSupplier.js";
6
6
  import { defineLagecySetup } from "../../types/helper.js";
@@ -29,6 +29,8 @@ const MapProvider = defineLagecySetup("MapProvider", function(props, {
29
29
  get(target, name, receiver) {
30
30
  if (name === "status")
31
31
  return payload.statusRef.value;
32
+ if (name === "pingStatus")
33
+ return payload.pingStatusRef.value;
32
34
  if (name === "readyPromise")
33
35
  return payload.readyPromise;
34
36
  return Reflect.get(target, name, receiver);
@@ -73,7 +75,8 @@ const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
73
75
  gmapId,
74
76
  gmapRasterId,
75
77
  language = "zh",
76
- status
78
+ status,
79
+ pingStatus
77
80
  } = payload;
78
81
  const {
79
82
  mapRef: setMap,
@@ -82,19 +85,19 @@ const HeycarMap = defineLagecySetup("HeycarMap", function(props, {
82
85
  touchEnable = true,
83
86
  touchZoomCenter
84
87
  } = props;
85
- if (status === Status.LOADING) {
86
- const node = (_a = slots.loading) == null ? void 0 : _a.call(slots);
87
- return node ? createVNode("div", null, [node]) : createVNode(Loading, null, null);
88
- }
89
- if (status === Status.FAILURE || status === Status.TIMEOUT) {
90
- const node = (_b = slots.fallback) == null ? void 0 : _b.call(slots);
91
- const title = (_c = payload.renderLoadFailedTitle) == null ? void 0 : _c.call(payload, status);
92
- const description = (_d = payload.renderLoadFailedDescription) == null ? void 0 : _d.call(payload, status);
88
+ if (status === Status.FAILURE || pingStatus === "unconnected") {
89
+ const node = (_a = slots.fallback) == null ? void 0 : _a.call(slots);
90
+ const title = (_b = payload.renderLoadFailedTitle) == null ? void 0 : _b.call(payload, status);
91
+ const description = (_c = payload.renderLoadFailedDescription) == null ? void 0 : _c.call(payload, status);
93
92
  return node ? createVNode("div", null, [node]) : createVNode(LoadFailed, {
94
93
  "title": title,
95
94
  "description": description
96
95
  }, null);
97
96
  }
97
+ if (status === Status.LOADING || status === Status.SUCCESS && pingStatus === "pending") {
98
+ const node = (_d = slots.loading) == null ? void 0 : _d.call(slots);
99
+ return node ? createVNode("div", null, [node]) : createVNode(Loading, null, null);
100
+ }
98
101
  const children = (_e = slots.default) == null ? void 0 : _e.call(slots);
99
102
  const outArea = (_f = slots.outerArea) == null ? void 0 : _f.call(slots);
100
103
  const mapId = patchGmapIdForAlipayCompatible({
@@ -1,7 +1,23 @@
1
1
  import { reactive, watch } from "vue-demi";
2
2
  import { MINI_PROGRAM_WEB_VIEW_CLOSE_EVENT } from "../utils/patchMiniprogram.js";
3
3
  import { OS_PLATFORM, detectOSPlatform } from "../utils/platform.js";
4
- import { t as throttle } from "../chunks/throttle.8bdd8d3b.js";
4
+ import { i as isObject, d as debounce } from "../chunks/debounce.5afe7867.js";
5
+ var FUNC_ERROR_TEXT = "Expected a function";
6
+ function throttle(func, wait, options) {
7
+ var leading = true, trailing = true;
8
+ if (typeof func != "function") {
9
+ throw new TypeError(FUNC_ERROR_TEXT);
10
+ }
11
+ if (isObject(options)) {
12
+ leading = "leading" in options ? !!options.leading : leading;
13
+ trailing = "trailing" in options ? !!options.trailing : trailing;
14
+ }
15
+ return debounce(func, wait, {
16
+ "leading": leading,
17
+ "maxWait": wait,
18
+ "trailing": trailing
19
+ });
20
+ }
5
21
  const DEVICE_ORIENTATION_INTERVAL = 200;
6
22
  const CSS_DEVICE_ORIENTATION_VAR_PREFIX = "--CSS_DEVICE_ORIENTATION_VAR_ROTATION_DEGREE_";
7
23
  const useDeviceOrientation = (props) => {
@@ -23,6 +23,8 @@ const useADrivingRoute = (props) => {
23
23
  const drivingResult = result;
24
24
  const routeSteps = [];
25
25
  const firstRoute = drivingResult.routes[0];
26
+ if (!firstRoute)
27
+ return resolve({ path: [], distance: 0, duration: 0, steps: [] });
26
28
  for (const step of firstRoute.steps) {
27
29
  const basicStep = step;
28
30
  const stepPath = basicStep.path.map(({ lng, lat }) => [lng, lat]);
@@ -83,6 +85,8 @@ const useGDrivingRoute = (props) => {
83
85
  let duration = 0;
84
86
  const routeSteps = [];
85
87
  const firstRoute = result.routes[0];
88
+ if (!firstRoute)
89
+ return resolve({ path: [], distance: 0, duration: 0, steps: [] });
86
90
  for (const leg of firstRoute.legs) {
87
91
  distance += (_b = (_a = leg.distance) == null ? void 0 : _a.value) != null ? _b : 0;
88
92
  duration += (_d = (_c = leg.duration) == null ? void 0 : _c.value) != null ? _d : 0;
@@ -1,5 +1,3 @@
1
- import { AMAP_TO_GCJ02_TIMEOUT } from "../api/contants.js";
2
- import { lnglat2point } from "../utils/transform.js";
3
1
  import { inChina, inHongkong, inMacau } from "./useMapInChina.js";
4
2
  import { useMapSupplier } from "./useMapSupplier.js";
5
3
  /**
@@ -514,7 +512,6 @@ const exported = Object.assign(Object.assign({}, CRSTypes), {
514
512
  transform
515
513
  });
516
514
  const useAmapGCJ02 = () => {
517
- const { readyPromise } = useMapSupplier();
518
515
  const toCoordinateType = (p) => {
519
516
  return inChina(p) ? "gcj02" : "wgs84";
520
517
  };
@@ -531,34 +528,9 @@ const useAmapGCJ02 = () => {
531
528
  }
532
529
  };
533
530
  const toLocalGcj02Points = (points) => points.map(toLocalGcj02);
534
- async function toGcj02Points(points) {
535
- await readyPromise;
536
- return new Promise((resolve) => {
537
- let isHandled = false;
538
- AMap.convertFrom(
539
- [...points],
540
- "gps",
541
- (_, result) => {
542
- if (isHandled)
543
- return;
544
- isHandled = true;
545
- if (result.info === "ok") {
546
- resolve(result.locations.map(lnglat2point));
547
- } else {
548
- console.warn("警告: 高德坐标转换请求失败,启用本地转换");
549
- resolve(toLocalGcj02Points(points));
550
- }
551
- }
552
- );
553
- setTimeout(() => {
554
- if (isHandled)
555
- return;
556
- isHandled = true;
557
- console.warn("警告: 高德坐标转换请求超时,启用本地转换");
558
- resolve(toLocalGcj02Points(points));
559
- }, AMAP_TO_GCJ02_TIMEOUT);
560
- });
561
- }
531
+ const toGcj02Points = async (points) => {
532
+ return toLocalGcj02Points(points);
533
+ };
562
534
  function toGcj02(point) {
563
535
  return toGcj02Points([point]).then(([result]) => result);
564
536
  }
@@ -2,12 +2,11 @@ import { load as loadAmap } from "@amap/amap-jsapi-loader";
2
2
  import { type LoaderOptions } from "@googlemaps/js-api-loader";
3
3
  import { type Ref } from "vue-demi";
4
4
  import type { VNodeChild } from "../demi-polyfill";
5
- import type { Language } from "../types/interface";
5
+ import type { ConnectionStatus, Language } from "../types/interface";
6
6
  export declare const DEFAULT_AMAP_PLUGINS: AmapLoaderProps["plugins"];
7
7
  export declare const DEFAULT_GMAP_LIBRARIES: LoaderOptions["libraries"];
8
8
  export declare enum Status {
9
9
  LOADING = "LOADING",
10
- TIMEOUT = "TIMEOUT",
11
10
  FAILURE = "FAILURE",
12
11
  SUCCESS = "SUCCESS"
13
12
  }
@@ -30,6 +29,7 @@ export interface AmapLoaderProps extends Pick<GmapLoaderProps, "fallback" | "loa
30
29
  }
31
30
  export declare const useAmapLoader: (props: AmapLoaderProps) => {
32
31
  statusRef: import("vue-demi").ShallowRef<Status>;
32
+ pingStatusRef: import("vue-demi").ShallowRef<ConnectionStatus>;
33
33
  readyPromise: Promise<undefined>;
34
34
  };
35
35
  export interface GmapLoaderProps extends LoaderOptions {
@@ -53,11 +53,13 @@ export interface GmapLoaderProps extends LoaderOptions {
53
53
  }
54
54
  export declare const useGmapLoader: (props: GmapLoaderProps) => {
55
55
  statusRef: import("vue-demi").ShallowRef<Status>;
56
+ pingStatusRef: import("vue-demi").ShallowRef<ConnectionStatus>;
56
57
  readyPromise: Promise<undefined>;
57
58
  };
58
59
  export type MapSupplier = "gmap" | "amap";
59
60
  export interface UseMapLoaderOutput {
60
61
  statusRef: Ref<Status>;
62
+ pingStatusRef: Ref<ConnectionStatus>;
61
63
  readyPromise: Promise<undefined>;
62
64
  }
63
65
  export interface UseMapLoaderProps {
@@ -1,8 +1,8 @@
1
- import { shallowRef, computed, ref } from "vue-demi";
1
+ import { shallowRef, computed } from "vue-demi";
2
+ import { apiPingAmap, apiPingGmap } from "../api/pingConnection.js";
2
3
  import { watchPostEffectForDeepOption } from "../utils/compare.js";
3
- import { createRunOnce } from "../utils/helper.js";
4
+ import { createOneConcurrent, sleep, createRunOnce } from "../utils/helper.js";
4
5
  import { patchGoogleMapLoader } from "../utils/patchGoogleMapLoader.js";
5
- import { t as throttle } from "../chunks/throttle.8bdd8d3b.js";
6
6
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
7
7
  var distExports = {};
8
8
  var dist = {
@@ -540,7 +540,6 @@ class Loader {
540
540
  }
541
541
  }
542
542
  const MIN_MAP_RELOAD_INTERVAL = 5e3;
543
- const GMAP_LOAD_TIMEOUT = 1e4;
544
543
  const DEFAULT_AMAP_PLUGINS = [
545
544
  "AMap.Geocoder",
546
545
  "AMap.Driving",
@@ -550,7 +549,6 @@ const DEFAULT_AMAP_PLUGINS = [
550
549
  const DEFAULT_GMAP_LIBRARIES = ["marker", "geometry"];
551
550
  var Status = /* @__PURE__ */ ((Status2) => {
552
551
  Status2["LOADING"] = "LOADING";
553
- Status2["TIMEOUT"] = "TIMEOUT";
554
552
  Status2["FAILURE"] = "FAILURE";
555
553
  Status2["SUCCESS"] = "SUCCESS";
556
554
  return Status2;
@@ -558,15 +556,14 @@ var Status = /* @__PURE__ */ ((Status2) => {
558
556
  const useAmapLoader = (props) => {
559
557
  const { disableRef, onSuccess, onFail } = props;
560
558
  let resolveLoader;
561
- let rejectLoader;
562
- const readyPromise = new Promise((resolve, reject) => {
559
+ const readyPromise = new Promise((resolve) => {
563
560
  resolveLoader = resolve;
564
- rejectLoader = reject;
565
561
  });
566
562
  const statusRef = shallowRef(
567
563
  "LOADING"
568
564
  /* LOADING */
569
565
  );
566
+ const pingStatusRef = shallowRef("connected");
570
567
  const optionsRef = computed(() => {
571
568
  const {
572
569
  onSuccess: onSuccess2,
@@ -586,102 +583,123 @@ const useAmapLoader = (props) => {
586
583
  serviceHost: props.apiServiceHost
587
584
  } : { securityJsCode: props.apiSecret };
588
585
  });
589
- const reload = throttle(
590
- (options) => {
591
- if (statusRef.value === "SUCCESS")
592
- return;
593
- statusRef.value = "LOADING";
594
- defineSecurityOnce();
595
- return distExports.load(options).then(
596
- () => {
597
- statusRef.value = "SUCCESS";
598
- resolveLoader();
599
- onSuccess == null ? void 0 : onSuccess();
600
- },
601
- () => {
602
- statusRef.value = "FAILURE";
603
- rejectLoader();
604
- onFail == null ? void 0 : onFail();
605
- }
606
- );
607
- },
608
- MIN_MAP_RELOAD_INTERVAL,
609
- { trailing: false }
610
- );
611
- watchPostEffectForDeepOption(
612
- () => [optionsRef.value, disableRef == null ? void 0 : disableRef.value],
613
- ([options, disable]) => {
614
- if (disable)
615
- return;
616
- reload(options);
586
+ const reload = createOneConcurrent((options) => {
587
+ if (statusRef.value === "SUCCESS")
588
+ return Promise.resolve();
589
+ defineSecurityOnce();
590
+ distExports.reset();
591
+ statusRef.value = "LOADING";
592
+ return distExports.load(options).then(
593
+ () => {
594
+ statusRef.value = "SUCCESS";
595
+ resolveLoader();
596
+ onSuccess == null ? void 0 : onSuccess();
597
+ },
598
+ () => {
599
+ statusRef.value = "FAILURE";
600
+ onFail == null ? void 0 : onFail();
601
+ }
602
+ );
603
+ });
604
+ const keepRetry = createOneConcurrent(async () => {
605
+ const options = optionsRef.value;
606
+ while (!(disableRef == null ? void 0 : disableRef.value) && statusRef.value !== "SUCCESS") {
607
+ if (statusRef.value === "LOADING") {
608
+ await reload(options);
609
+ continue;
610
+ }
611
+ await sleep(MIN_MAP_RELOAD_INTERVAL);
612
+ const pingStatus = await apiPingAmap();
613
+ if (pingStatus === "unconnected")
614
+ continue;
615
+ await reload(options);
617
616
  }
618
- );
619
- return { statusRef, readyPromise };
617
+ });
618
+ watchPostEffectForDeepOption(() => [optionsRef.value, disableRef == null ? void 0 : disableRef.value], keepRetry);
619
+ return { statusRef, pingStatusRef, readyPromise };
620
620
  };
621
621
  const useGmapLoader = (props) => {
622
622
  const { disableRef, onSuccess, onFail } = props;
623
623
  let resolveLoader;
624
- let rejectLoader;
625
- const readyPromise = new Promise((resolve, reject) => {
624
+ const readyPromise = new Promise((resolve) => {
626
625
  resolveLoader = resolve;
627
- rejectLoader = reject;
628
626
  });
629
627
  const statusRef = shallowRef(
630
628
  "LOADING"
631
629
  /* LOADING */
632
630
  );
631
+ const pingStatusRef = shallowRef("pending");
633
632
  const optionsRef = computed(() => {
634
633
  const { onSuccess: onSuccess2, onFail: onFail2, fallback, loading, language, ...options } = props;
635
634
  return options;
636
635
  });
637
- const timerRef = ref();
638
- const reload = throttle(
639
- (options) => {
640
- if (statusRef.value === "SUCCESS")
641
- return;
642
- const loader = new Loader(options);
643
- patchGoogleMapLoader(loader);
644
- clearTimeout(timerRef.value);
645
- timerRef.value = window.setTimeout(() => {
646
- statusRef.value = "TIMEOUT";
647
- }, GMAP_LOAD_TIMEOUT);
648
- if (loader.status !== LoaderStatus.INITIALIZED) {
649
- window.google = void 0;
650
- loader.reset();
636
+ const reload = createOneConcurrent((options, signal) => {
637
+ if (statusRef.value === "SUCCESS")
638
+ return Promise.resolve();
639
+ const loader = new Loader({ ...options, retries: 0 });
640
+ patchGoogleMapLoader(loader);
641
+ if (loader.status !== LoaderStatus.INITIALIZED) {
642
+ window.google = void 0;
643
+ loader.reset();
644
+ }
645
+ const abortPromise = new Promise((resolve) => signal == null ? void 0 : signal.addEventListener("abort", resolve));
646
+ statusRef.value = "LOADING";
647
+ const loadPromise = loader.load().then(
648
+ () => {
649
+ if (signal == null ? void 0 : signal.aborted)
650
+ return;
651
+ statusRef.value = "SUCCESS";
652
+ resolveLoader();
653
+ onSuccess == null ? void 0 : onSuccess();
654
+ },
655
+ () => {
656
+ if (signal == null ? void 0 : signal.aborted)
657
+ return;
658
+ statusRef.value = "FAILURE";
659
+ onFail == null ? void 0 : onFail();
660
+ }
661
+ );
662
+ return Promise.race([abortPromise, loadPromise]);
663
+ });
664
+ const keepRetry = createOneConcurrent(async () => {
665
+ if (statusRef.value === "SUCCESS") {
666
+ pingStatusRef.value = "pending";
667
+ while (pingStatusRef.value !== "connected") {
668
+ if (pingStatusRef.value === "unconnected")
669
+ await sleep(MIN_MAP_RELOAD_INTERVAL);
670
+ pingStatusRef.value = await apiPingGmap();
651
671
  }
652
- statusRef.value = "LOADING";
653
- return loader.load().then(
654
- () => {
655
- clearTimeout(timerRef.value);
656
- statusRef.value = "SUCCESS";
657
- resolveLoader();
658
- onSuccess == null ? void 0 : onSuccess();
659
- },
660
- () => {
661
- clearTimeout(timerRef.value);
662
- statusRef.value = "FAILURE";
663
- rejectLoader();
664
- onFail == null ? void 0 : onFail();
665
- }
666
- );
667
- },
668
- MIN_MAP_RELOAD_INTERVAL,
669
- { trailing: false }
670
- );
671
- watchPostEffectForDeepOption(
672
- () => [optionsRef.value, disableRef == null ? void 0 : disableRef.value],
673
- ([options, disable]) => {
674
- if (disable)
675
- return;
676
- const language = navigator.language;
677
- reload({ ...options, language });
678
672
  }
679
- );
680
- return { statusRef, readyPromise };
673
+ const language = navigator.language;
674
+ const options = { ...optionsRef.value, language };
675
+ while (!(disableRef == null ? void 0 : disableRef.value) && statusRef.value !== "SUCCESS") {
676
+ if (statusRef.value === "FAILURE" || pingStatusRef.value === "unconnected") {
677
+ await sleep(MIN_MAP_RELOAD_INTERVAL);
678
+ pingStatusRef.value = await apiPingGmap();
679
+ if (pingStatusRef.value === "connected")
680
+ statusRef.value = "LOADING";
681
+ continue;
682
+ }
683
+ const controller = new AbortController();
684
+ const reloadPromise = reload(options, controller.signal);
685
+ pingStatusRef.value = await apiPingGmap();
686
+ if (pingStatusRef.value === "unconnected") {
687
+ controller.abort();
688
+ continue;
689
+ }
690
+ await reloadPromise;
691
+ }
692
+ });
693
+ watchPostEffectForDeepOption(() => [optionsRef.value, disableRef == null ? void 0 : disableRef.value], keepRetry);
694
+ return { statusRef, pingStatusRef, readyPromise };
681
695
  };
682
696
  const useMapLoader = (props) => {
683
697
  const { gmapKey, amapKey, amapSecret, amapServiceHost, language, onSuccess, onFail } = props;
684
- const { statusRef: amapStatusRef, readyPromise: amapReadyPromise } = useAmapLoader({
698
+ const {
699
+ statusRef: amapStatusRef,
700
+ pingStatusRef: amapPingStatusRef,
701
+ readyPromise: amapReadyPromise
702
+ } = useAmapLoader({
685
703
  apiKey: amapKey,
686
704
  apiSecret: amapSecret,
687
705
  apiServiceHost: amapServiceHost,
@@ -690,7 +708,11 @@ const useMapLoader = (props) => {
690
708
  onSuccess,
691
709
  onFail
692
710
  });
693
- const { statusRef: gmapStatusRef, readyPromise: gmapReadyPromise } = useGmapLoader({
711
+ const {
712
+ statusRef: gmapStatusRef,
713
+ pingStatusRef: gmapPingStatusRef,
714
+ readyPromise: gmapReadyPromise
715
+ } = useGmapLoader({
694
716
  apiKey: gmapKey,
695
717
  language,
696
718
  version: "weekly",
@@ -705,6 +727,9 @@ const useMapLoader = (props) => {
705
727
  get statusRef() {
706
728
  return props.supplier === "gmap" ? gmapStatusRef : amapStatusRef;
707
729
  },
730
+ get pingStatusRef() {
731
+ return props.supplier === "gmap" ? gmapPingStatusRef : amapPingStatusRef;
732
+ },
708
733
  get readyPromise() {
709
734
  return props.supplier === "gmap" ? gmapReadyPromise : amapReadyPromise;
710
735
  }