@heycar/heycars-map 0.6.6 → 0.6.7
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/hooks/useVisibilityState.d.ts +7 -0
- package/dist/index.cjs +17 -0
- package/dist/index.js +17 -0
- package/package.json +3 -20
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const useVisibilityState: () => {
|
|
2
|
+
visibilityStateRef: import("vue-demi").Ref<DocumentVisibilityState>;
|
|
3
|
+
};
|
|
4
|
+
export declare const watchVisibilityState: () => {
|
|
5
|
+
visibilityStateRef: import("vue-demi").Ref<DocumentVisibilityState>;
|
|
6
|
+
unwatchVisibilityState: () => void;
|
|
7
|
+
};
|
package/dist/index.cjs
CHANGED
|
@@ -3056,6 +3056,17 @@ const BusinessQuotingMap = defineLagecySetup(function BusinessQuotingMap2(props)
|
|
|
3056
3056
|
})]);
|
|
3057
3057
|
};
|
|
3058
3058
|
}).props(["fallback", "from", "loading", "mapRef", "registerOverlay", "renderDescription", "to", "fromDescription", "log"]);
|
|
3059
|
+
const watchVisibilityState = () => {
|
|
3060
|
+
const visibilityStateRef = Vue.ref(document.visibilityState);
|
|
3061
|
+
const handleVisibilityChange = () => {
|
|
3062
|
+
visibilityStateRef.value = document.visibilityState;
|
|
3063
|
+
};
|
|
3064
|
+
const unwatchVisibilityState = () => {
|
|
3065
|
+
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
3066
|
+
};
|
|
3067
|
+
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
3068
|
+
return { visibilityStateRef, unwatchVisibilityState };
|
|
3069
|
+
};
|
|
3059
3070
|
const WX_GET_LOCATION_INTERVAL_STILL = 10 * 1e3;
|
|
3060
3071
|
const WX_GET_LOCATION_INTERVAL_SLOW = 3 * 1e3;
|
|
3061
3072
|
const WX_GET_LOCATION_INTERVAL_FAST = 1 * 1e3;
|
|
@@ -3081,9 +3092,14 @@ function wechatWatchPosition(onSuccess, onError, option) {
|
|
|
3081
3092
|
let enable = true;
|
|
3082
3093
|
let interval = WX_GET_LOCATION_INTERVAL_STILL;
|
|
3083
3094
|
let prevGeoPosition = void 0;
|
|
3095
|
+
const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
|
|
3084
3096
|
const startWatch = async () => {
|
|
3085
3097
|
await wxReady();
|
|
3086
3098
|
do {
|
|
3099
|
+
if (visibilityStateRef.value === "hidden") {
|
|
3100
|
+
await sleep$1(WX_GET_LOCATION_INTERVAL_FAST);
|
|
3101
|
+
continue;
|
|
3102
|
+
}
|
|
3087
3103
|
const geoPosition = await new Promise((resolve, reject) => {
|
|
3088
3104
|
let isHandled = false;
|
|
3089
3105
|
wx.getLocation({
|
|
@@ -3123,6 +3139,7 @@ function wechatWatchPosition(onSuccess, onError, option) {
|
|
|
3123
3139
|
startWatch();
|
|
3124
3140
|
return () => {
|
|
3125
3141
|
enable = false;
|
|
3142
|
+
unwatchVisibilityState();
|
|
3126
3143
|
};
|
|
3127
3144
|
}
|
|
3128
3145
|
function compatibleWathPosition(onSuccess, onError, option) {
|
package/dist/index.js
CHANGED
|
@@ -3054,6 +3054,17 @@ const BusinessQuotingMap = defineLagecySetup(function BusinessQuotingMap2(props)
|
|
|
3054
3054
|
})]);
|
|
3055
3055
|
};
|
|
3056
3056
|
}).props(["fallback", "from", "loading", "mapRef", "registerOverlay", "renderDescription", "to", "fromDescription", "log"]);
|
|
3057
|
+
const watchVisibilityState = () => {
|
|
3058
|
+
const visibilityStateRef = ref(document.visibilityState);
|
|
3059
|
+
const handleVisibilityChange = () => {
|
|
3060
|
+
visibilityStateRef.value = document.visibilityState;
|
|
3061
|
+
};
|
|
3062
|
+
const unwatchVisibilityState = () => {
|
|
3063
|
+
document.removeEventListener("visibilitychange", handleVisibilityChange);
|
|
3064
|
+
};
|
|
3065
|
+
document.addEventListener("visibilitychange", handleVisibilityChange);
|
|
3066
|
+
return { visibilityStateRef, unwatchVisibilityState };
|
|
3067
|
+
};
|
|
3057
3068
|
const WX_GET_LOCATION_INTERVAL_STILL = 10 * 1e3;
|
|
3058
3069
|
const WX_GET_LOCATION_INTERVAL_SLOW = 3 * 1e3;
|
|
3059
3070
|
const WX_GET_LOCATION_INTERVAL_FAST = 1 * 1e3;
|
|
@@ -3079,9 +3090,14 @@ function wechatWatchPosition(onSuccess, onError, option) {
|
|
|
3079
3090
|
let enable = true;
|
|
3080
3091
|
let interval = WX_GET_LOCATION_INTERVAL_STILL;
|
|
3081
3092
|
let prevGeoPosition = void 0;
|
|
3093
|
+
const { visibilityStateRef, unwatchVisibilityState } = watchVisibilityState();
|
|
3082
3094
|
const startWatch = async () => {
|
|
3083
3095
|
await wxReady();
|
|
3084
3096
|
do {
|
|
3097
|
+
if (visibilityStateRef.value === "hidden") {
|
|
3098
|
+
await sleep$1(WX_GET_LOCATION_INTERVAL_FAST);
|
|
3099
|
+
continue;
|
|
3100
|
+
}
|
|
3085
3101
|
const geoPosition = await new Promise((resolve, reject) => {
|
|
3086
3102
|
let isHandled = false;
|
|
3087
3103
|
wx.getLocation({
|
|
@@ -3121,6 +3137,7 @@ function wechatWatchPosition(onSuccess, onError, option) {
|
|
|
3121
3137
|
startWatch();
|
|
3122
3138
|
return () => {
|
|
3123
3139
|
enable = false;
|
|
3140
|
+
unwatchVisibilityState();
|
|
3124
3141
|
};
|
|
3125
3142
|
}
|
|
3126
3143
|
function compatibleWathPosition(onSuccess, onError, option) {
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@heycar/heycars-map",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "vite -c vite.config.dev.ts",
|
|
7
7
|
"dev:lib": "concurrently \"vite build -c vite.config.dev.lib.ts --watch --emptyOutDir false\" \"tsc --declarationDir dist --emitDeclarationOnly --noEmit false --declaration --watch\"",
|
|
8
|
-
"build": "rm -rf dist && vite build && tsc --declarationDir dist --emitDeclarationOnly --noEmit false --declaration"
|
|
8
|
+
"build": "rm -rf dist && vite build && tsc --declarationDir dist --emitDeclarationOnly --noEmit false --declaration",
|
|
9
|
+
"lint": "eslint . --ext .js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore --report-unused-disable-directives --max-warnings 0"
|
|
9
10
|
},
|
|
10
11
|
"types": "./dist/index.d.ts",
|
|
11
12
|
"module": "./dist/index.js",
|
|
@@ -41,9 +42,6 @@
|
|
|
41
42
|
}
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
|
-
"@commitlint/cli": "^17.3.0",
|
|
45
|
-
"@commitlint/config-conventional": "^17.3.0",
|
|
46
|
-
"@commitlint/types": "^17.0.0",
|
|
47
45
|
"@types/google.maps": "^3.52.0",
|
|
48
46
|
"@types/lodash-es": "^4.17.6",
|
|
49
47
|
"@typescript-eslint/eslint-plugin": "^5.52.0",
|
|
@@ -63,9 +61,7 @@
|
|
|
63
61
|
"eslint-plugin-import": "^2.27.5",
|
|
64
62
|
"eslint-plugin-prettier": "^4.2.1",
|
|
65
63
|
"eslint-plugin-vue": "^9.9.0",
|
|
66
|
-
"lint-staged": "^13.1.2",
|
|
67
64
|
"prettier": "^2.8.4",
|
|
68
|
-
"simple-git-hooks": "^2.8.1",
|
|
69
65
|
"typescript": "^4.9.3",
|
|
70
66
|
"unplugin-vue-jsx": "^0.1.2",
|
|
71
67
|
"vite": "^4.1.0",
|
|
@@ -74,19 +70,6 @@
|
|
|
74
70
|
"vue": "2.7.14",
|
|
75
71
|
"vue-tsc": "^1.0.24"
|
|
76
72
|
},
|
|
77
|
-
"simple-git-hooks": {
|
|
78
|
-
"pre-commit": "pnpm exec lint-staged --concurrent false",
|
|
79
|
-
"commit-msg": "pnpm exec commitlint --edit ${1}"
|
|
80
|
-
},
|
|
81
|
-
"lint-staged": {
|
|
82
|
-
"*.{js,jsx,ts,tsx}": [
|
|
83
|
-
"eslint --fix",
|
|
84
|
-
"prettier --write"
|
|
85
|
-
],
|
|
86
|
-
"*.{md,json,yml,html,css}": [
|
|
87
|
-
"prettier --write"
|
|
88
|
-
]
|
|
89
|
-
},
|
|
90
73
|
"publishConfig": {
|
|
91
74
|
"registry": "https://registry.npmjs.com"
|
|
92
75
|
},
|