@heycar/heycars-map 2.0.0-switchMap3 → 2.0.0-switchMap5

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 (75) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/v2/Demo/DemoBusinessRecomendPlace.js +1 -1
  4. package/dist/v2/api/pingConnection.d.ts +9 -0
  5. package/dist/v2/api/pingConnection.js +107 -0
  6. package/dist/v2/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +1 -1
  7. package/dist/v2/business-components/BusinessRecomendPlaceMap/index.js +1 -1
  8. package/dist/v2/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +1 -1
  9. package/dist/v2/chunks/{BusinessRecomendPlaceMap.f589ebf7.js → BusinessRecomendPlaceMap.4b641c71.js} +6 -3
  10. package/dist/v2/chunks/{Loading.da68a2a6.js → Loading.492acbc2.js} +10 -12
  11. package/dist/v2/components/Loading/Loading.css.d.ts +2 -2
  12. package/dist/v2/components/Loading/Loading.js +3 -3
  13. package/dist/v2/components/Loading/index.js +3 -3
  14. package/dist/v2/components/MapProvider/MapProvider.js +13 -10
  15. package/dist/v2/css/{Loading-0e058b68.css → Loading-49e58ced.css} +6 -11
  16. package/dist/v2/hooks/useDeviceOrientation.js +17 -1
  17. package/dist/v2/hooks/useMapGCJ02.js +0 -3
  18. package/dist/v2/hooks/useMapGeometry.d.ts +1 -3
  19. package/dist/v2/hooks/useMapGeometry.js +4 -4
  20. package/dist/v2/hooks/useMapLoader.d.ts +4 -2
  21. package/dist/v2/hooks/useMapLoader.js +110 -85
  22. package/dist/v2/hooks/useMapPlace.js +42 -35
  23. package/dist/v2/hooks/useMapRecomendPlace.js +4 -4
  24. package/dist/v2/hooks/useMapSupplier.d.ts +2 -0
  25. package/dist/v2/hooks/usePingConnection.d.ts +10 -0
  26. package/dist/v2/hooks/usePingConnection.js +26 -0
  27. package/dist/v2/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
  28. package/dist/v2/index.js +1 -1
  29. package/dist/v2/types/global.d.ts +3 -0
  30. package/dist/v2/types/interface.d.ts +1 -1
  31. package/dist/v2/utils/helper.d.ts +1 -0
  32. package/dist/v2/utils/helper.js +12 -0
  33. package/dist/v2/utils/log.js +1 -1
  34. package/dist/v3/Demo/DemoBusinessRecomendPlace.js +1 -1
  35. package/dist/v3/api/pingConnection.d.ts +9 -0
  36. package/dist/v3/api/pingConnection.js +107 -0
  37. package/dist/v3/business-components/BusinessRecomendPlaceMap/BusinessRecomendPlaceMap.js +1 -1
  38. package/dist/v3/business-components/BusinessRecomendPlaceMap/index.js +1 -1
  39. package/dist/v3/business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js +1 -1
  40. package/dist/v3/chunks/{BusinessRecomendPlaceMap.86e9c287.js → BusinessRecomendPlaceMap.4befb6c7.js} +6 -3
  41. package/dist/v3/chunks/{Loading.98d687c0.js → Loading.21d8e759.js} +10 -12
  42. package/dist/v3/components/Loading/Loading.css.d.ts +2 -2
  43. package/dist/v3/components/Loading/Loading.js +3 -3
  44. package/dist/v3/components/Loading/index.js +3 -3
  45. package/dist/v3/components/MapProvider/MapProvider.js +13 -10
  46. package/dist/v3/css/{Loading-0e058b68.css → Loading-49e58ced.css} +6 -11
  47. package/dist/v3/hooks/useDeviceOrientation.js +17 -1
  48. package/dist/v3/hooks/useMapGCJ02.js +0 -3
  49. package/dist/v3/hooks/useMapGeometry.d.ts +1 -3
  50. package/dist/v3/hooks/useMapGeometry.js +4 -4
  51. package/dist/v3/hooks/useMapLoader.d.ts +4 -2
  52. package/dist/v3/hooks/useMapLoader.js +110 -85
  53. package/dist/v3/hooks/useMapPlace.js +42 -35
  54. package/dist/v3/hooks/useMapRecomendPlace.js +4 -4
  55. package/dist/v3/hooks/useMapSupplier.d.ts +2 -0
  56. package/dist/v3/hooks/usePingConnection.d.ts +10 -0
  57. package/dist/v3/hooks/usePingConnection.js +26 -0
  58. package/dist/v3/hooks-business/useBusinessRecomendPlaceMap.js +1 -1
  59. package/dist/v3/index.js +1 -1
  60. package/dist/v3/types/global.d.ts +3 -0
  61. package/dist/v3/types/interface.d.ts +1 -1
  62. package/dist/v3/utils/helper.d.ts +1 -0
  63. package/dist/v3/utils/helper.js +12 -0
  64. package/dist/v3/utils/log.js +1 -1
  65. package/package.json +1 -1
  66. package/dist/v2/api/googleConnection.d.ts +0 -5
  67. package/dist/v2/api/googleConnection.js +0 -51
  68. package/dist/v2/chunks/throttle.8bdd8d3b.js +0 -20
  69. package/dist/v2/hooks/useGoogleConnection.d.ts +0 -7
  70. package/dist/v2/hooks/useGoogleConnection.js +0 -15
  71. package/dist/v3/api/googleConnection.d.ts +0 -5
  72. package/dist/v3/api/googleConnection.js +0 -51
  73. package/dist/v3/chunks/throttle.8bdd8d3b.js +0 -20
  74. package/dist/v3/hooks/useGoogleConnection.d.ts +0 -7
  75. package/dist/v3/hooks/useGoogleConnection.js +0 -15
@@ -31,32 +31,37 @@ const useAmapPlace = (props) => {
31
31
  };
32
32
  const getPlaceByRegeo = abortable(([lng, lat]) => {
33
33
  return new Promise((resolve) => {
34
- const geocoder = new AMap.Geocoder({ lang: language === "en" ? "en" : "zh_cn" });
35
- const pipeTw = createPipeTw(language === "zh-TW");
36
- const isChina = inChina([lng, lat]);
37
- geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
38
- switch (status) {
39
- case "complete": {
40
- const { formattedAddress, addressComponent } = result.regeocode;
41
- const name = formattedAddress ? formattedAddress : emptyPlaceName;
42
- const displayName = amapPlaceName2DisplayName(name, { isChina, ...addressComponent });
43
- resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
44
- return;
45
- }
46
- case "no_data":
47
- case "error": {
48
- const name = emptyPlaceName;
49
- const displayName = emptyPlaceName;
50
- resolve({ lng, lat, name, displayName });
51
- return;
52
- }
53
- }
54
- });
55
- setTimeout(() => {
56
- console.warn("高德逆地理请求超时!");
34
+ const handleFailed = () => {
57
35
  const name = emptyPlaceName;
58
36
  const displayName = emptyPlaceName;
59
37
  resolve({ lng, lat, name, displayName });
38
+ };
39
+ readyPromise.then(() => {
40
+ const geocoder = new AMap.Geocoder({ lang: language === "en" ? "en" : "zh_cn" });
41
+ const pipeTw = createPipeTw(language === "zh-TW");
42
+ const isChina = inChina([lng, lat]);
43
+ geocoder.getAddress(new AMap.LngLat(lng, lat), (status, result) => {
44
+ switch (status) {
45
+ case "complete": {
46
+ const { formattedAddress, addressComponent } = result.regeocode;
47
+ const name = formattedAddress ? formattedAddress : emptyPlaceName;
48
+ const displayName = amapPlaceName2DisplayName(name, {
49
+ isChina,
50
+ ...addressComponent
51
+ });
52
+ resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
53
+ return;
54
+ }
55
+ case "no_data":
56
+ case "error": {
57
+ handleFailed();
58
+ }
59
+ }
60
+ });
61
+ }, handleFailed);
62
+ setTimeout(() => {
63
+ console.warn("高德逆地理请求超时!");
64
+ handleFailed();
60
65
  }, REGEO_TIMEOUT);
61
66
  });
62
67
  });
@@ -96,23 +101,25 @@ const useGmapPlace = (props) => {
96
101
  };
97
102
  const getPlaceByRegeo = abortable(([lng, lat]) => {
98
103
  return new Promise((resolve) => {
99
- const geocoder = new google.maps.Geocoder();
100
- const pipeTw = createPipeTw(language === "zh-TW");
101
- geocoder.geocode({ language, location: { lng, lat } }).then(({ results }) => {
102
- const name = results[0].formatted_address ? results[0].formatted_address : emptyPlaceName;
103
- const displayName = gmapPlaceName2DisplayName(name, results[0].address_components);
104
- resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
105
- }).catch((err) => {
106
- console.error(err);
104
+ const handleFailed = (err) => {
105
+ if (err)
106
+ console.error(err);
107
107
  const name = emptyPlaceName;
108
108
  const displayName = emptyPlaceName;
109
109
  resolve({ lng, lat, name, displayName });
110
- });
110
+ };
111
+ readyPromise.then(() => {
112
+ const geocoder = new google.maps.Geocoder();
113
+ const pipeTw = createPipeTw(language === "zh-TW");
114
+ geocoder.geocode({ language, location: { lng, lat } }).then(({ results }) => {
115
+ const name = results[0].formatted_address ? results[0].formatted_address : emptyPlaceName;
116
+ const displayName = gmapPlaceName2DisplayName(name, results[0].address_components);
117
+ resolve({ lng, lat, name: pipeTw(name), displayName: pipeTw(displayName) });
118
+ }).catch(handleFailed);
119
+ }, handleFailed);
111
120
  setTimeout(() => {
112
121
  console.warn("谷歌逆地理请求超时!");
113
- const name = emptyPlaceName;
114
- const displayName = emptyPlaceName;
115
- resolve({ lng, lat, name, displayName });
122
+ handleFailed();
116
123
  }, REGEO_TIMEOUT);
117
124
  });
118
125
  });
@@ -3,7 +3,7 @@ import { GET_RECOMMEND_PLACE_TIMEOUT } from "../api/contants.js";
3
3
  import { logNoneManualAbortError } from "../utils/ManualAbortError.js";
4
4
  import { equalAssign, createAbortable, isPlacesInclude } from "../utils/helper.js";
5
5
  import { isZoneEqual, place2point, isPlaceEqual, businessCandidatesToAdsorptionPlace } from "../utils/transform.js";
6
- import { useMapGeometry } from "./useMapGeometry.js";
6
+ import { useMapGeometry, apiLocalIsPointInRing } from "./useMapGeometry.js";
7
7
  import { useMapPlace } from "./useMapPlace.js";
8
8
  function mergeGetRecommendPlaceAndGetAvailable(getRecomendPlace, getAvailable, timeout) {
9
9
  return function mergedGetRecommendPlace(place, context) {
@@ -53,7 +53,7 @@ const useMapRecomendPlace = (props) => {
53
53
  const placeCandidatesRef = ref([]);
54
54
  const zoneRef = ref();
55
55
  const abortable = createAbortable(signal);
56
- const { apiMapIsPointInRing, apiMapDistance } = useMapGeometry();
56
+ const { apiMapDistance } = useMapGeometry();
57
57
  const { getPlaceByRegeo } = useMapPlace({
58
58
  emptyPlaceName,
59
59
  pointRef: ref([...defaultPoint]),
@@ -99,7 +99,7 @@ const useMapRecomendPlace = (props) => {
99
99
  async (point, prevState) => {
100
100
  const [lng, lat] = point;
101
101
  const zone = zoneRef.value;
102
- if (!zone || !apiMapIsPointInRing(point, zone.path)) {
102
+ if (!zone || !apiLocalIsPointInRing(point, zone.path)) {
103
103
  const reGeoPlacePromise = getPlaceByRegeo(point);
104
104
  const {
105
105
  place: closestPlace,
@@ -130,7 +130,7 @@ const useMapRecomendPlace = (props) => {
130
130
  );
131
131
  const updateIntermediateQueryingState = (point) => {
132
132
  const zone = zoneRef.value;
133
- if (zone && apiMapIsPointInRing(point, zone.path))
133
+ if (zone && apiLocalIsPointInRing(point, zone.path))
134
134
  return;
135
135
  const [lng, lat] = point;
136
136
  const intermediateQueryingPlace = {
@@ -1,10 +1,12 @@
1
1
  import type { AnyFn } from "@vueuse/core";
2
+ import type { ConnectionStatus } from "../types/interface";
2
3
  import type { Status, UseMapLoaderOutput, UseMapLoaderProps } from "./useMapLoader";
3
4
  export interface MapSupplierPayolad extends UseMapLoaderProps {
4
5
  gmapRasterId: string;
5
6
  gmapId: string;
6
7
  readyPromise: UseMapLoaderOutput["readyPromise"];
7
8
  status: Status;
9
+ pingStatus: ConnectionStatus;
8
10
  renderLoadFailedTitle?: (status: Status) => string | undefined;
9
11
  renderLoadFailedDescription?: (status: Status) => string | undefined;
10
12
  }
@@ -0,0 +1,10 @@
1
+ import { type PingConnectionOnChangeHandler } from "../api/pingConnection";
2
+ export interface UsePingConnectionProps {
3
+ onChange?: PingConnectionOnChangeHandler;
4
+ }
5
+ export declare const usePingAmapConnection: (props?: UsePingConnectionProps) => {
6
+ connectionStatus: Readonly<import("vue-demi").Ref<import("..").ConnectionStatus>>;
7
+ };
8
+ export declare const usePingGmapConnection: (props?: UsePingConnectionProps) => {
9
+ connectionStatus: Readonly<import("vue-demi").Ref<import("..").ConnectionStatus>>;
10
+ };
@@ -0,0 +1,26 @@
1
+ import { ref, onUnmounted, readonly } from "vue-demi";
2
+ import { apiGetPingAmapStatus, apiSubscribePingAmapChange, apiGetPingGmapStatus, apiSubscribePingGmapChange } from "../api/pingConnection.js";
3
+ const usePingAmapConnection = (props) => {
4
+ const statusRef = ref(apiGetPingAmapStatus());
5
+ const unsubscribe = apiSubscribePingAmapChange((status) => {
6
+ var _a;
7
+ statusRef.value = status;
8
+ (_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, status);
9
+ });
10
+ onUnmounted(unsubscribe);
11
+ return { connectionStatus: readonly(statusRef) };
12
+ };
13
+ const usePingGmapConnection = (props) => {
14
+ const statusRef = ref(apiGetPingGmapStatus());
15
+ const unsubscribe = apiSubscribePingGmapChange((status) => {
16
+ var _a;
17
+ statusRef.value = status;
18
+ (_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, status);
19
+ });
20
+ onUnmounted(unsubscribe);
21
+ return { connectionStatus: readonly(statusRef) };
22
+ };
23
+ export {
24
+ usePingAmapConnection,
25
+ usePingGmapConnection
26
+ };
@@ -1,5 +1,5 @@
1
1
  import { reactive, ref, readonly } from "vue-demi";
2
- import { E as EMPTY_PLACE } from "../chunks/BusinessRecomendPlaceMap.86e9c287.js";
2
+ import { E as EMPTY_PLACE } from "../chunks/BusinessRecomendPlaceMap.4befb6c7.js";
3
3
  import { CenterPlaceStatus } from "../types/interface.js";
4
4
  import { proxyFunctionalProperty, assertAssingedBeforeUsed } from "../utils/helper.js";
5
5
  const useBusinessRecomendPlaceMap = () => {
package/dist/v3/index.js CHANGED
@@ -2,7 +2,7 @@ import "./utils/alipayPolyfill.js";
2
2
  import { AbsoluteAddressBox } from "./business-components/AbsoluteAddressBox/AbsoluteAddressBox.js";
3
3
  import { AddressBox } from "./business-components/AddressBox/AddressBox.js";
4
4
  import { BusinessQuotingMap } from "./business-components/BusinessQuotingMap/BusinessQuotingMap.js";
5
- import { B } from "./chunks/BusinessRecomendPlaceMap.86e9c287.js";
5
+ import { B } from "./chunks/BusinessRecomendPlaceMap.4befb6c7.js";
6
6
  import { BusinessReselectPlaceMap } from "./business-components/BusinessReselectPlaceMap/BusinessReselectPlaceMap.js";
7
7
  import { BusinessTaxiEndMap } from "./business-components/BusinessTaxiEndMap/BusinessTaxiEndMap.js";
8
8
  import { BusinessTaxiServiceMap } from "./business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js";
@@ -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-switchMap3";
3
+ const pkgVersion = "2.0.0-switchMap5";
4
4
  const isEnableLog = (name) => {
5
5
  const searchParam = new URLSearchParams(location.search);
6
6
  return searchParam.has(`log-${name}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "2.0.0-switchMap3",
3
+ "version": "2.0.0-switchMap5",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js",
@@ -1,5 +0,0 @@
1
- import type { GoogleConnectionStatus } from "../types/interface";
2
- export type GoogleConnectionOnChangeHandler = (status: GoogleConnectionStatus) => void;
3
- export type GoogleConnectionOnChangeCleanup = () => void;
4
- export declare const apiGoogleConnectionStatus: () => GoogleConnectionStatus;
5
- export declare const apiSubscribeGoogleConnectionChange: (handler: GoogleConnectionOnChangeHandler) => GoogleConnectionOnChangeCleanup;
@@ -1,51 +0,0 @@
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
- const GOOGLE_DNS_RESOLVER = "https://dns.google/resolve?name=maps.googleapis.com&type=A";
8
- const GOOGLE_CONNECTION_DEFAULT_TIMEOUT = 5e3;
9
- const noop = () => {
10
- };
11
- class GoogleConnection {
12
- constructor() {
13
- __publicField(this, "status", "pending");
14
- __publicField(this, "listeners", /* @__PURE__ */ new Set());
15
- this.start();
16
- }
17
- async start() {
18
- const status = await this.check();
19
- this.status = status;
20
- for (const handler of this.listeners) {
21
- try {
22
- handler(status);
23
- } catch (err) {
24
- console.error(err);
25
- }
26
- }
27
- }
28
- check(timeout = GOOGLE_CONNECTION_DEFAULT_TIMEOUT) {
29
- const controller = new AbortController();
30
- const timer = setTimeout(() => controller.abort(), timeout);
31
- return fetch(GOOGLE_DNS_RESOLVER, { signal: controller.signal }).then(() => "connected").catch(() => "unconnected").finally(() => clearTimeout(timer));
32
- }
33
- onChange(handler) {
34
- if (typeof handler !== "function")
35
- return noop;
36
- this.listeners.add(handler);
37
- const clear = () => {
38
- this.listeners.delete(handler);
39
- };
40
- return clear;
41
- }
42
- }
43
- const googleConnection = new GoogleConnection();
44
- const apiGoogleConnectionStatus = () => {
45
- return googleConnection.status;
46
- };
47
- const apiSubscribeGoogleConnectionChange = (handler) => googleConnection.onChange(handler);
48
- export {
49
- apiGoogleConnectionStatus,
50
- apiSubscribeGoogleConnectionChange
51
- };
@@ -1,20 +0,0 @@
1
- import { i as isObject, d as debounce } from "./debounce.5afe7867.js";
2
- var FUNC_ERROR_TEXT = "Expected a function";
3
- function throttle(func, wait, options) {
4
- var leading = true, trailing = true;
5
- if (typeof func != "function") {
6
- throw new TypeError(FUNC_ERROR_TEXT);
7
- }
8
- if (isObject(options)) {
9
- leading = "leading" in options ? !!options.leading : leading;
10
- trailing = "trailing" in options ? !!options.trailing : trailing;
11
- }
12
- return debounce(func, wait, {
13
- "leading": leading,
14
- "maxWait": wait,
15
- "trailing": trailing
16
- });
17
- }
18
- export {
19
- throttle as t
20
- };
@@ -1,7 +0,0 @@
1
- import { type GoogleConnectionOnChangeHandler } from "../api/googleConnection";
2
- export interface UseGoogleConnectionProps {
3
- onChange?: GoogleConnectionOnChangeHandler;
4
- }
5
- export declare const useGoogleConnection: (props?: UseGoogleConnectionProps) => {
6
- googleConnectionStatus: Readonly<import("vue-demi").Ref<import("..").GoogleConnectionStatus>>;
7
- };
@@ -1,15 +0,0 @@
1
- import { ref, onUnmounted, readonly } from "vue-demi";
2
- import { apiGoogleConnectionStatus, apiSubscribeGoogleConnectionChange } from "../api/googleConnection.js";
3
- const useGoogleConnection = (props) => {
4
- const statusRef = ref(apiGoogleConnectionStatus());
5
- const unsubscribe = apiSubscribeGoogleConnectionChange((status) => {
6
- var _a;
7
- statusRef.value = status;
8
- (_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, status);
9
- });
10
- onUnmounted(unsubscribe);
11
- return { googleConnectionStatus: readonly(statusRef) };
12
- };
13
- export {
14
- useGoogleConnection
15
- };
@@ -1,5 +0,0 @@
1
- import type { GoogleConnectionStatus } from "../types/interface";
2
- export type GoogleConnectionOnChangeHandler = (status: GoogleConnectionStatus) => void;
3
- export type GoogleConnectionOnChangeCleanup = () => void;
4
- export declare const apiGoogleConnectionStatus: () => GoogleConnectionStatus;
5
- export declare const apiSubscribeGoogleConnectionChange: (handler: GoogleConnectionOnChangeHandler) => GoogleConnectionOnChangeCleanup;
@@ -1,51 +0,0 @@
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
- const GOOGLE_DNS_RESOLVER = "https://dns.google/resolve?name=maps.googleapis.com&type=A";
8
- const GOOGLE_CONNECTION_DEFAULT_TIMEOUT = 5e3;
9
- const noop = () => {
10
- };
11
- class GoogleConnection {
12
- constructor() {
13
- __publicField(this, "status", "pending");
14
- __publicField(this, "listeners", /* @__PURE__ */ new Set());
15
- this.start();
16
- }
17
- async start() {
18
- const status = await this.check();
19
- this.status = status;
20
- for (const handler of this.listeners) {
21
- try {
22
- handler(status);
23
- } catch (err) {
24
- console.error(err);
25
- }
26
- }
27
- }
28
- check(timeout = GOOGLE_CONNECTION_DEFAULT_TIMEOUT) {
29
- const controller = new AbortController();
30
- const timer = setTimeout(() => controller.abort(), timeout);
31
- return fetch(GOOGLE_DNS_RESOLVER, { signal: controller.signal }).then(() => "connected").catch(() => "unconnected").finally(() => clearTimeout(timer));
32
- }
33
- onChange(handler) {
34
- if (typeof handler !== "function")
35
- return noop;
36
- this.listeners.add(handler);
37
- const clear = () => {
38
- this.listeners.delete(handler);
39
- };
40
- return clear;
41
- }
42
- }
43
- const googleConnection = new GoogleConnection();
44
- const apiGoogleConnectionStatus = () => {
45
- return googleConnection.status;
46
- };
47
- const apiSubscribeGoogleConnectionChange = (handler) => googleConnection.onChange(handler);
48
- export {
49
- apiGoogleConnectionStatus,
50
- apiSubscribeGoogleConnectionChange
51
- };
@@ -1,20 +0,0 @@
1
- import { i as isObject, d as debounce } from "./debounce.5afe7867.js";
2
- var FUNC_ERROR_TEXT = "Expected a function";
3
- function throttle(func, wait, options) {
4
- var leading = true, trailing = true;
5
- if (typeof func != "function") {
6
- throw new TypeError(FUNC_ERROR_TEXT);
7
- }
8
- if (isObject(options)) {
9
- leading = "leading" in options ? !!options.leading : leading;
10
- trailing = "trailing" in options ? !!options.trailing : trailing;
11
- }
12
- return debounce(func, wait, {
13
- "leading": leading,
14
- "maxWait": wait,
15
- "trailing": trailing
16
- });
17
- }
18
- export {
19
- throttle as t
20
- };
@@ -1,7 +0,0 @@
1
- import { type GoogleConnectionOnChangeHandler } from "../api/googleConnection";
2
- export interface UseGoogleConnectionProps {
3
- onChange?: GoogleConnectionOnChangeHandler;
4
- }
5
- export declare const useGoogleConnection: (props?: UseGoogleConnectionProps) => {
6
- googleConnectionStatus: Readonly<import("vue-demi").Ref<import("..").GoogleConnectionStatus>>;
7
- };
@@ -1,15 +0,0 @@
1
- import { ref, onUnmounted, readonly } from "vue-demi";
2
- import { apiGoogleConnectionStatus, apiSubscribeGoogleConnectionChange } from "../api/googleConnection.js";
3
- const useGoogleConnection = (props) => {
4
- const statusRef = ref(apiGoogleConnectionStatus());
5
- const unsubscribe = apiSubscribeGoogleConnectionChange((status) => {
6
- var _a;
7
- statusRef.value = status;
8
- (_a = props == null ? void 0 : props.onChange) == null ? void 0 : _a.call(props, status);
9
- });
10
- onUnmounted(unsubscribe);
11
- return { googleConnectionStatus: readonly(statusRef) };
12
- };
13
- export {
14
- useGoogleConnection
15
- };