@heycar/heycars-map 2.13.0-relay2 → 2.14.0-walkOptimize1

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 (37) hide show
  1. package/dist/v2/api/contants.d.ts +3 -0
  2. package/dist/v2/api/contants.js +6 -0
  3. package/dist/v2/business-components/AuxiliaryPassanger/AuxiliaryPassanger.d.ts +6 -0
  4. package/dist/v2/business-components/AuxiliaryPassanger/AuxiliaryPassanger.js +50 -0
  5. package/dist/v2/business-components/AuxiliaryPassanger/index.d.ts +1 -0
  6. package/dist/v2/business-components/AuxiliaryPassanger/index.js +4 -0
  7. package/dist/v2/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +6 -0
  8. package/dist/v2/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceSection.js +1 -3
  9. package/dist/v2/hooks/useMapGeometry.d.ts +3 -3
  10. package/dist/v2/hooks/useMapGeometry.js +3 -3
  11. package/dist/v2/hooks/useWalkingRoute.js +46 -4
  12. package/dist/v2/utils/geometry.d.ts +1 -0
  13. package/dist/v2/utils/geometry.js +4 -2
  14. package/dist/v2/utils/geometryPolygon.d.ts +5 -0
  15. package/dist/v2/utils/geometryPolygon.js +27 -0
  16. package/dist/v2/utils/log.js +11 -3
  17. package/dist/v2/utils/ttlCache.d.ts +34 -0
  18. package/dist/v2/utils/ttlCache.js +64 -0
  19. package/dist/v3/api/contants.d.ts +3 -0
  20. package/dist/v3/api/contants.js +6 -0
  21. package/dist/v3/business-components/AuxiliaryPassanger/AuxiliaryPassanger.d.ts +8 -0
  22. package/dist/v3/business-components/AuxiliaryPassanger/AuxiliaryPassanger.js +46 -0
  23. package/dist/v3/business-components/AuxiliaryPassanger/index.d.ts +1 -0
  24. package/dist/v3/business-components/AuxiliaryPassanger/index.js +4 -0
  25. package/dist/v3/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceMap.js +4 -0
  26. package/dist/v3/business-components/BusinessTaxiServiceMap/BusinessTaxiServiceSection.js +1 -3
  27. package/dist/v3/hooks/useMapGeometry.d.ts +3 -3
  28. package/dist/v3/hooks/useMapGeometry.js +3 -3
  29. package/dist/v3/hooks/useWalkingRoute.js +46 -4
  30. package/dist/v3/utils/geometry.d.ts +1 -0
  31. package/dist/v3/utils/geometry.js +4 -2
  32. package/dist/v3/utils/geometryPolygon.d.ts +5 -0
  33. package/dist/v3/utils/geometryPolygon.js +27 -0
  34. package/dist/v3/utils/log.js +11 -3
  35. package/dist/v3/utils/ttlCache.d.ts +34 -0
  36. package/dist/v3/utils/ttlCache.js +64 -0
  37. package/package.json +1 -1
@@ -5,7 +5,10 @@ export declare const ANIMATION_DURATION_FOR_100VW = 100;
5
5
  export declare const ANIMATION_DURATION_PER_ZOOM = 200;
6
6
  export declare const BEIJIN_POINT: Point;
7
7
  export declare const MAX_DEVIATION_DISTANCE = 30;
8
+ export declare const MAX_DEVIATION_DISTANCE_WALKING = 5;
8
9
  export declare const CAR_DISTANCE_MIN = 20;
10
+ export declare const PASSENGER_DISTANCE_MAX = 2000;
11
+ export declare const PASSENGER_DISTANCE_MIN = 20;
9
12
  export declare const ZINDEX_BUBBLE_LAYER = 50;
10
13
  export declare const ZINDEX_START_END_LOGO_LAYER = 40;
11
14
  export declare const ZINDEX_PLACE_LAYER = 30;
@@ -4,7 +4,10 @@ const ANIMATION_DURATION_FOR_100VW = 100;
4
4
  const ANIMATION_DURATION_PER_ZOOM = 200;
5
5
  const BEIJIN_POINT = [116.2317, 39.5427];
6
6
  const MAX_DEVIATION_DISTANCE = 30;
7
+ const MAX_DEVIATION_DISTANCE_WALKING = 5;
7
8
  const CAR_DISTANCE_MIN = 20;
9
+ const PASSENGER_DISTANCE_MAX = 2e3;
10
+ const PASSENGER_DISTANCE_MIN = 20;
8
11
  const ZINDEX_BUBBLE_LAYER = 50;
9
12
  const ZINDEX_START_END_LOGO_LAYER = 40;
10
13
  const ZINDEX_PLACE_LAYER = 30;
@@ -30,7 +33,10 @@ export {
30
33
  GET_RECOMMEND_PLACE_TIMEOUT,
31
34
  MAX_ANIMATION_DISTANCE_VW,
32
35
  MAX_DEVIATION_DISTANCE,
36
+ MAX_DEVIATION_DISTANCE_WALKING,
33
37
  MIN_ANIMATION_DURATION,
38
+ PASSENGER_DISTANCE_MAX,
39
+ PASSENGER_DISTANCE_MIN,
34
40
  REGEO_TIMEOUT,
35
41
  TRACKS_MATCH_MAX_LENGTH,
36
42
  ZINDEX_AUXILIARY_GRASP,
@@ -0,0 +1,6 @@
1
+ import type { DriverStatus, Point } from "../../types/interface";
2
+ export interface AuxiliaryPassangerProps {
3
+ status: DriverStatus;
4
+ passengerPosition?: Point;
5
+ }
6
+ export declare const AuxiliaryPassanger: import("vue-demi").DefineComponent<import("vue3").ComponentObjectPropsOptions<AuxiliaryPassangerProps>, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").EmitByProps<AuxiliaryPassangerProps, Required<AuxiliaryPassangerProps>>, never, AuxiliaryPassangerProps>;
@@ -0,0 +1,50 @@
1
+ import { h } from "vue";
2
+ import { ref } from "vue-demi";
3
+ import { MAX_DEVIATION_DISTANCE_WALKING } from "../../api/contants.js";
4
+ import { defineSetup } from "../../types/helper.js";
5
+ import { watchEffectForDeepOption } from "../../utils/compare.js";
6
+ import { AuxiliaryCircle } from "../AuxiliaryCircle/AuxiliaryCircle.js";
7
+ import { AuxiliaryLine } from "../AuxiliaryLine/AuxiliaryLine.js";
8
+ const usePositionHistory = (source, capacity) => {
9
+ const history = ref([]);
10
+ watchEffectForDeepOption(source, (point) => {
11
+ if (!point)
12
+ return;
13
+ history.value.push([...point]);
14
+ if (history.value.length > capacity) {
15
+ history.value.shift();
16
+ }
17
+ });
18
+ return history;
19
+ };
20
+ const AuxiliaryPassanger = defineSetup("AuxiliaryPassanger", function(props) {
21
+ const passengerPositionHistory = usePositionHistory(() => props.passengerPosition, 20);
22
+ return () => {
23
+ const {
24
+ status,
25
+ passengerPosition
26
+ } = props;
27
+ console.log("passengerPositionHistory = ", passengerPositionHistory.value);
28
+ const prevPositions = passengerPositionHistory.value.slice(0, -1);
29
+ if (status !== "assign" && status !== "confirmed" && status !== "driverStartRelayService" && status !== "dispatched" && status !== "driverStartService" && status !== "book-driverStartService" && status !== "book-dispatched" && status !== "driverArrived")
30
+ return;
31
+ return h("div", [!!passengerPosition && h(AuxiliaryCircle, {
32
+ "attrs": {
33
+ "center": passengerPosition,
34
+ "radius": MAX_DEVIATION_DISTANCE_WALKING,
35
+ "opacity": 0.2
36
+ }
37
+ }), prevPositions.length > 0 && h(AuxiliaryLine, {
38
+ "attrs": {
39
+ "path": prevPositions,
40
+ "type": "circle",
41
+ "color": "purple",
42
+ "scale": MAX_DEVIATION_DISTANCE_WALKING,
43
+ "opacity": 0.2
44
+ }
45
+ })]);
46
+ };
47
+ });
48
+ export {
49
+ AuxiliaryPassanger
50
+ };
@@ -0,0 +1 @@
1
+ export * from "./AuxiliaryPassanger";
@@ -0,0 +1,4 @@
1
+ import { AuxiliaryPassanger } from "./AuxiliaryPassanger.js";
2
+ export {
3
+ AuxiliaryPassanger
4
+ };
@@ -14,6 +14,7 @@ import { createAbortable, assertNotEmptyArray } from "../../utils/helper.js";
14
14
  import { place2point, pipeDefer, lnglat2point } from "../../utils/transform.js";
15
15
  import { toCoordinatePlaceType, toCoordinateTrackPoint } from "../../utils/typeChecking.js";
16
16
  import { AuxiliaryGraspRoad } from "../AuxiliaryGraspRoad/AuxiliaryGraspRoad.js";
17
+ import { AuxiliaryPassanger } from "../AuxiliaryPassanger/AuxiliaryPassanger.js";
17
18
  import { DeviceOrientation } from "../DeviceOrientation/DeviceOrientation.js";
18
19
  import { SectionDispatching, SectionConfirmed, SectionDriverStartRelayService, SectionDriverStartService, SectionBookDispatched, SectionInService, SectionDriverArrived, SectionCanceled, SectionEndService } from "./BusinessTaxiServiceSection.js";
19
20
  const STATUS_NEED_CAR_POSITION = ["book-driverStartService", "dispatched", "driverStartService", "driverStartRelayService", "inService", "driverArrived"];
@@ -247,6 +248,11 @@ const BusinessTaxiServiceMapInner = defineSetup("BusinessTaxiServiceMapInner", f
247
248
  "from": from,
248
249
  "to": to
249
250
  }
251
+ }), IS_ENABLE_AUXILIARY_GRASP_ROAD && h(AuxiliaryPassanger, {
252
+ "attrs": {
253
+ "status": driverStatus,
254
+ "passengerPosition": passengerPosition
255
+ }
250
256
  })]);
251
257
  };
252
258
  });
@@ -1,6 +1,6 @@
1
1
  import { h } from "vue";
2
2
  import { apiGetAuxiliaryGrapStatus } from "../../api/browser.js";
3
- import { MAX_DEVIATION_DISTANCE, CAR_DISTANCE_MIN } from "../../api/contants.js";
3
+ import { PASSENGER_DISTANCE_MAX, MAX_DEVIATION_DISTANCE, PASSENGER_DISTANCE_MIN, CAR_DISTANCE_MIN } from "../../api/contants.js";
4
4
  import { useMapGeometry } from "../../hooks/useMapGeometry.js";
5
5
  import { useMapSupplier } from "../../hooks/useMapSupplier.js";
6
6
  import { defineSetup } from "../../types/helper.js";
@@ -19,8 +19,6 @@ import { WalkingLine } from "../WalkingLine/WalkingLine.js";
19
19
  import { WalkingRoute } from "../WalkingRoute/WalkingRoute.js";
20
20
  import { WaveCircle } from "../WaveCircle/WaveCircle.js";
21
21
  const IS_ENABLE_AUXILIARY_GRASP_ROAD = apiGetAuxiliaryGrapStatus();
22
- const PASSENGER_DISTANCE_MAX = 2e3;
23
- const PASSENGER_DISTANCE_MIN = 20;
24
22
  const AUTO_FIT_VIEW_INTERVAL = IS_ENABLE_AUXILIARY_GRASP_ROAD ? 24 * 3600 * 1e3 : 15e3;
25
23
  const carDurationWithinMinDistance = (distance) => Math.floor(distance / 5);
26
24
  const SectionDispatching = defineSetup("SectionDispatching", function(props) {
@@ -1,17 +1,17 @@
1
1
  import type { Point } from "../types/interface";
2
2
  export declare const apiLocalIsPointInRing: (point: Point, path: Point[]) => boolean;
3
3
  export declare const useAmapGeometry: () => {
4
- apiMapDistance: (from: Point, to: Point) => number | undefined;
4
+ apiMapDistance: (from: Point, to: Point) => number;
5
5
  apiMapDistanceToLine: (from: Point, line: Point[]) => number | undefined;
6
6
  apiMapDistanceOfLine: (line: Point[]) => number | undefined;
7
7
  };
8
8
  export declare const useGmapGeometry: () => {
9
- apiMapDistance: (from: Point, to: Point) => number | undefined;
9
+ apiMapDistance: (from: Point, to: Point) => number;
10
10
  apiMapDistanceToLine: (from: Point, line: Point[]) => 0 | undefined;
11
11
  apiMapDistanceOfLine: (line: Point[]) => number | undefined;
12
12
  };
13
13
  export declare const useMapGeometry: () => {
14
- apiMapDistance: (from: Point, to: Point) => number | undefined;
14
+ apiMapDistance: (from: Point, to: Point) => number;
15
15
  apiMapDistanceToLine: (from: Point, line: Point[]) => number | undefined;
16
16
  apiMapDistanceOfLine: (line: Point[]) => number | undefined;
17
17
  };
@@ -1,4 +1,4 @@
1
- import { pointInPolygon } from "../utils/geometryPolygon.js";
1
+ import { pointInPolygon, distanceBetweenTwoPoints } from "../utils/geometryPolygon.js";
2
2
  import { vec2lnglat } from "../utils/transform.js";
3
3
  import { Status } from "./useMapLoader.js";
4
4
  import { useMapSupplier } from "./useMapSupplier.js";
@@ -7,7 +7,7 @@ const useAmapGeometry = () => {
7
7
  const payload = useMapSupplier();
8
8
  const apiMapDistance = (from, to) => {
9
9
  if (payload.status !== Status.SUCCESS)
10
- return void 0;
10
+ return distanceBetweenTwoPoints(from, to);
11
11
  return AMap.GeometryUtil.distance(from, to);
12
12
  };
13
13
  const apiMapDistanceToLine = (from, line) => {
@@ -26,7 +26,7 @@ const useGmapGeometry = () => {
26
26
  const payload = useMapSupplier();
27
27
  const apiMapDistance = (from, to) => {
28
28
  if (payload.status !== Status.SUCCESS)
29
- return void 0;
29
+ return distanceBetweenTwoPoints(from, to);
30
30
  return google.maps.geometry.spherical.computeDistanceBetween(vec2lnglat(from), vec2lnglat(to));
31
31
  };
32
32
  const apiMapDistanceToLine = (from, line) => {
@@ -1,15 +1,56 @@
1
1
  import { shallowRef } from "vue-demi";
2
+ import { MAX_DEVIATION_DISTANCE_WALKING } from "../api/contants.js";
2
3
  import { watchPostEffectForDeepOption } from "../utils/compare.js";
3
4
  import { googleServiceApiWalkingRoute, amapJsApiWalkingRoute, gaodeServiceApiWalkingRoute, gmapJsApiWalkingRoute } from "../utils/compatibleWalkingRoute.js";
5
+ import { findClosestPointInLine } from "../utils/geometry.js";
6
+ import { distanceBetweenTwoPoints } from "../utils/geometryPolygon.js";
7
+ import { spaceLog } from "../utils/log.js";
8
+ import { createMemoizeWithTTL } from "../utils/ttlCache.js";
4
9
  import { inTaiwan, inKorean } from "./useMapInChina.js";
5
10
  import { useMapSupplier } from "./useMapSupplier.js";
11
+ const WALKING_ROUTE_CACHE_TTL = 30 * 60 * 1e3;
12
+ const findBestContinuation = (args, cacheEntries) => {
13
+ const [from, to] = args;
14
+ let bestPath;
15
+ for (const [[cacheFrom, cacheTo], path] of cacheEntries) {
16
+ if (!path || path.length < 2)
17
+ continue;
18
+ const deviationOfEndPoint = distanceBetweenTwoPoints(cacheTo, to);
19
+ if (deviationOfEndPoint > MAX_DEVIATION_DISTANCE_WALKING)
20
+ continue;
21
+ {
22
+ const { distance: deviationOfStartPoint } = findClosestPointInLine(
23
+ from,
24
+ [cacheFrom, ...path],
25
+ distanceBetweenTwoPoints
26
+ );
27
+ if (deviationOfStartPoint > MAX_DEVIATION_DISTANCE_WALKING)
28
+ continue;
29
+ }
30
+ const { point: projectedPoint, index } = findClosestPointInLine(
31
+ from,
32
+ path,
33
+ distanceBetweenTwoPoints
34
+ );
35
+ const trimmedPath = [projectedPoint, ...path.slice(index + 1)];
36
+ if (trimmedPath.length < 2)
37
+ continue;
38
+ if (!bestPath || trimmedPath.length < bestPath.length) {
39
+ bestPath = trimmedPath;
40
+ }
41
+ }
42
+ return bestPath;
43
+ };
44
+ const memoizeAmapWalkingRoute = createMemoizeWithTTL(WALKING_ROUTE_CACHE_TTL, findBestContinuation);
45
+ const memoizeGmapWalkingRoute = createMemoizeWithTTL(WALKING_ROUTE_CACHE_TTL, findBestContinuation);
6
46
  const useAWalkingRoute = (props) => {
7
47
  const { googleRoutesProxyUrl } = useMapSupplier();
8
48
  const pathRef = shallowRef([]);
9
49
  const amapWalking = new AMap.Walking({});
10
- const apiMapWalkingRoute = (from, to) => {
50
+ const apiMapWalkingRoute = memoizeAmapWalkingRoute((from, to) => {
51
+ spaceLog("apiMapWalkingRoute", `amap from = ${from} to = ${to}`);
11
52
  return googleRoutesProxyUrl && inTaiwan(from) ? googleServiceApiWalkingRoute(from, to, googleRoutesProxyUrl) : amapJsApiWalkingRoute(from, to, amapWalking);
12
- };
53
+ });
13
54
  watchPostEffectForDeepOption(
14
55
  () => {
15
56
  const { from, to } = props;
@@ -27,11 +68,12 @@ const useGWalkingRoute = (props) => {
27
68
  const { gaodeDirectionWalkingProxyUrl, googleRoutesProxyUrl } = useMapSupplier();
28
69
  const pathRef = shallowRef([]);
29
70
  const gmapDirectionsService = new google.maps.DirectionsService();
30
- const apiMapWalkingRoute = (from, to) => {
71
+ const apiMapWalkingRoute = memoizeGmapWalkingRoute((from, to) => {
72
+ spaceLog("apiMapWalkingRoute", `gmap from = ${from} to = ${to}`);
31
73
  if (inKorean(from))
32
74
  return Promise.resolve([]);
33
75
  return gaodeDirectionWalkingProxyUrl && inKorean(from) ? gaodeServiceApiWalkingRoute(from, to, gaodeDirectionWalkingProxyUrl) : googleRoutesProxyUrl ? googleServiceApiWalkingRoute(from, to, googleRoutesProxyUrl) : gmapJsApiWalkingRoute(from, to, gmapDirectionsService);
34
- };
76
+ });
35
77
  watchPostEffectForDeepOption(
36
78
  () => {
37
79
  const { from, to } = props;
@@ -4,6 +4,7 @@ export declare const findClosestPointInSegment: (point: Point, segment: [Point,
4
4
  export declare const findClosestPointInLine: (point: Point, path: Point[], distanceFn: DistanceFn) => {
5
5
  point: Point;
6
6
  distance: number;
7
+ index: number;
7
8
  };
8
9
  export declare const isPointInSegment: (point: Point, segment: [Point, Point]) => boolean;
9
10
  export declare const isPointInHalfOpenSegment: (point: Point, segment: [Point, Point]) => boolean;
@@ -23,9 +23,10 @@ const findClosestPointInLine = (point, path, distanceFn) => {
23
23
  var _a, _b;
24
24
  let min = Infinity;
25
25
  let target;
26
+ let idx;
26
27
  assertPropNoEmptyArray(path, "findClosestPointInLine", "path");
27
28
  if (path.length === 1)
28
- return { point: path[0], distance: (_a = distanceFn(point, path[0])) != null ? _a : 0 };
29
+ return { point: path[0], distance: (_a = distanceFn(point, path[0])) != null ? _a : 0, index: 0 };
29
30
  for (let index = 0; index < path.length - 1; index++) {
30
31
  const closestPoint = findClosestPointInSegment(point, [path[index], path[index + 1]]);
31
32
  const distance = (_b = distanceFn(point, closestPoint)) != null ? _b : 0;
@@ -33,8 +34,9 @@ const findClosestPointInLine = (point, path, distanceFn) => {
33
34
  continue;
34
35
  target = closestPoint;
35
36
  min = distance;
37
+ idx = index;
36
38
  }
37
- return { point: target, distance: min };
39
+ return { point: target, distance: min, index: idx };
38
40
  };
39
41
  const floatEqual = (x1, x2) => {
40
42
  return Math.abs(x1 - x2) < 1e4 * Number.EPSILON;
@@ -4,3 +4,8 @@ import type { Point } from "../types/interface";
4
4
  * @returns 1 在内部, 0 边界上 , -1 在外部
5
5
  */
6
6
  export declare function pointInPolygon(point: Point, polygon: Point[]): 1 | 0 | -1;
7
+ export declare const distanceBetweenTwoPoints: (from: Point, to: Point) => number;
8
+ /**
9
+ * 计算折线(按顺序连接各点)总长度。
10
+ */
11
+ export declare const computeLineLength: (line: Point[]) => number;
@@ -22,6 +22,33 @@ function pointInPolygon(point, polygon) {
22
22
  }
23
23
  return inside ? 1 : -1;
24
24
  }
25
+ const distanceBetweenTwoPoints = (from, to) => {
26
+ const [lng1, lat1] = from;
27
+ const [lng2, lat2] = to;
28
+ if (lng1 === lng2 && lat1 === lat2)
29
+ return 0;
30
+ const toRad = (deg) => deg * Math.PI / 180;
31
+ const R = 6378137;
32
+ const phi1 = toRad(lat1);
33
+ const phi2 = toRad(lat2);
34
+ const dPhi = toRad(lat2 - lat1);
35
+ const dLambda = toRad(lng2 - lng1);
36
+ const a = Math.sin(dPhi / 2) * Math.sin(dPhi / 2) + Math.cos(phi1) * Math.cos(phi2) * Math.sin(dLambda / 2) * Math.sin(dLambda / 2);
37
+ const c = 2 * Math.asin(Math.min(1, Math.sqrt(a)));
38
+ return R * c;
39
+ };
40
+ const computeLineLength = (line) => {
41
+ var _a;
42
+ if (!Array.isArray(line) || line.length < 2)
43
+ return 0;
44
+ let totalLength = 0;
45
+ for (let i = 1; i < line.length; i++) {
46
+ totalLength += (_a = distanceBetweenTwoPoints(line[i - 1], line[i])) != null ? _a : 0;
47
+ }
48
+ return totalLength;
49
+ };
25
50
  export {
51
+ computeLineLength,
52
+ distanceBetweenTwoPoints,
26
53
  pointInPolygon
27
54
  };
@@ -1,11 +1,19 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.13.0-relay2";
3
+ const pkgVersion = "2.14.0-walkOptimize1";
4
+ const spaceLogSessionKey = "wiajlf;jwiatitruiq3jrlw";
5
+ const enableSessionLogKey = (key) => {
6
+ const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
7
+ sessionParam.set(`log-${key}`, "true");
8
+ sessionStorage.setItem(spaceLogSessionKey, sessionParam.toString());
9
+ };
4
10
  const isEnableLog = (name) => {
5
11
  const searchParam = new URLSearchParams(location.search);
6
- return searchParam.has(`log-${name}`);
12
+ const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
13
+ return searchParam.has(`log-${name}`) || sessionParam.has(`log-${name}`);
7
14
  };
8
- window.availableLogKeys = availableLogKeys;
15
+ window.heycarMapAvailableLogKeys = availableLogKeys;
16
+ window.heycarMapEnableSessionLogKey = enableSessionLogKey;
9
17
  const spaceLog = (logKey, ...args) => {
10
18
  availableLogKeys.add(logKey);
11
19
  if (!isEnableLog(logKey))
@@ -0,0 +1,34 @@
1
+ export type Milliseconds = number;
2
+ export interface TTLCache<K, V> {
3
+ get(key: K): V | undefined;
4
+ set(key: K, value: V): void;
5
+ delete(key: K): boolean;
6
+ clear(): void;
7
+ entries(): IterableIterator<[K, V]>;
8
+ }
9
+ /**
10
+ * 高性能 TTL Cache(固定 TTL,不支持动态变更)。
11
+ * - 仅提供最小接口:get/set/delete/clear/entries
12
+ * - 惰性过期:在访问时清理过期项,无额外定时器
13
+ */
14
+ export declare function createTTLCache<K, V>(ttlMs: Milliseconds): TTLCache<K, V>;
15
+ /**
16
+ * 异步函数的 TTL 记忆化工厂
17
+ *
18
+ * 命中策略(按顺序):
19
+ * 1. 精确命中:用 `computeKey(args)` 查缓存。
20
+ * 2. 近似命中:用 `selectFromCache(args, entries)` 在当前有效条目中挑选。
21
+ * 3. 未命中:执行原函数,结果写入缓存。
22
+ *
23
+ * 过期策略:惰性按 `ttlMs` 过期;`ttlMs <= 0` 表示不缓存;传 `Infinity` 视为永不过期。
24
+ *
25
+ * 参数:
26
+ * - `ttlMs`:缓存有效期(毫秒)。
27
+ * - `selectFromCache`:近似命中选择器,入参为本次 `args` 与有效缓存条目的迭代器,返回命中值或 `undefined`。
28
+ * - `computeKey`:精确命中的 key 生成函数,默认 `JSON.stringify`。
29
+ *
30
+ * 返回:`memoize(fn)`,将异步函数包装为带缓存的版本。
31
+ *
32
+ * 说明:不做并发合并;仅实现 TTL 驱逐(无容量上限);近似匹配会遍历有效条目。
33
+ */
34
+ export declare function createMemoizeWithTTL<A extends any[], R>(ttlMs: Milliseconds, selectFromCache: (args: A, cacheEntries: IterableIterator<[A, R]>) => R | undefined, computeKey?: (args: A) => string): (fn: (...args: A) => Promise<R>) => (...args: A) => Promise<R>;
@@ -0,0 +1,64 @@
1
+ function createTTLCache(ttlMs) {
2
+ const store = /* @__PURE__ */ new Map();
3
+ const get = (key) => {
4
+ const record = store.get(key);
5
+ if (!record)
6
+ return void 0;
7
+ const now = Date.now();
8
+ if (record.expireAt !== Infinity && record.expireAt <= now) {
9
+ store.delete(key);
10
+ return void 0;
11
+ }
12
+ return record.value;
13
+ };
14
+ const set = (key, value) => {
15
+ const now = Date.now();
16
+ const expireAt = Number.isFinite(ttlMs) ? now + ttlMs : Infinity;
17
+ if (Number.isFinite(ttlMs) && ttlMs <= 0) {
18
+ store.delete(key);
19
+ return;
20
+ }
21
+ store.set(key, { value, expireAt });
22
+ };
23
+ const del = (key) => store.delete(key);
24
+ const clear = () => {
25
+ store.clear();
26
+ };
27
+ function* entries() {
28
+ const now = Date.now();
29
+ for (const [key, record] of store) {
30
+ if (record.expireAt !== Infinity && record.expireAt <= now) {
31
+ store.delete(key);
32
+ continue;
33
+ }
34
+ yield [key, record.value];
35
+ }
36
+ }
37
+ return { get, set, delete: del, clear, entries };
38
+ }
39
+ function createMemoizeWithTTL(ttlMs, selectFromCache, computeKey = JSON.stringify) {
40
+ const cache = createTTLCache(ttlMs);
41
+ function* cacheEntries() {
42
+ for (const [, record] of cache.entries()) {
43
+ yield [record.args, record.value];
44
+ }
45
+ }
46
+ return function memoize(fn) {
47
+ return async function memoizedTTLFn(...args) {
48
+ const key = computeKey(args);
49
+ const direct = cache.get(key);
50
+ if (direct !== void 0)
51
+ return direct.value;
52
+ const hit = selectFromCache(args, cacheEntries());
53
+ if (hit !== void 0)
54
+ return hit;
55
+ const result = await fn(...args);
56
+ cache.set(key, { args, value: result });
57
+ return result;
58
+ };
59
+ };
60
+ }
61
+ export {
62
+ createMemoizeWithTTL,
63
+ createTTLCache
64
+ };
@@ -5,7 +5,10 @@ export declare const ANIMATION_DURATION_FOR_100VW = 100;
5
5
  export declare const ANIMATION_DURATION_PER_ZOOM = 200;
6
6
  export declare const BEIJIN_POINT: Point;
7
7
  export declare const MAX_DEVIATION_DISTANCE = 30;
8
+ export declare const MAX_DEVIATION_DISTANCE_WALKING = 5;
8
9
  export declare const CAR_DISTANCE_MIN = 20;
10
+ export declare const PASSENGER_DISTANCE_MAX = 2000;
11
+ export declare const PASSENGER_DISTANCE_MIN = 20;
9
12
  export declare const ZINDEX_BUBBLE_LAYER = 50;
10
13
  export declare const ZINDEX_START_END_LOGO_LAYER = 40;
11
14
  export declare const ZINDEX_PLACE_LAYER = 30;
@@ -4,7 +4,10 @@ const ANIMATION_DURATION_FOR_100VW = 100;
4
4
  const ANIMATION_DURATION_PER_ZOOM = 200;
5
5
  const BEIJIN_POINT = [116.2317, 39.5427];
6
6
  const MAX_DEVIATION_DISTANCE = 30;
7
+ const MAX_DEVIATION_DISTANCE_WALKING = 5;
7
8
  const CAR_DISTANCE_MIN = 20;
9
+ const PASSENGER_DISTANCE_MAX = 2e3;
10
+ const PASSENGER_DISTANCE_MIN = 20;
8
11
  const ZINDEX_BUBBLE_LAYER = 50;
9
12
  const ZINDEX_START_END_LOGO_LAYER = 40;
10
13
  const ZINDEX_PLACE_LAYER = 30;
@@ -30,7 +33,10 @@ export {
30
33
  GET_RECOMMEND_PLACE_TIMEOUT,
31
34
  MAX_ANIMATION_DISTANCE_VW,
32
35
  MAX_DEVIATION_DISTANCE,
36
+ MAX_DEVIATION_DISTANCE_WALKING,
33
37
  MIN_ANIMATION_DURATION,
38
+ PASSENGER_DISTANCE_MAX,
39
+ PASSENGER_DISTANCE_MIN,
34
40
  REGEO_TIMEOUT,
35
41
  TRACKS_MATCH_MAX_LENGTH,
36
42
  ZINDEX_AUXILIARY_GRASP,
@@ -0,0 +1,8 @@
1
+ import type { DriverStatus, Point } from "../../types/interface";
2
+ export interface AuxiliaryPassangerProps {
3
+ status: DriverStatus;
4
+ passengerPosition?: Point;
5
+ }
6
+ export declare const AuxiliaryPassanger: import("vue-demi").DefineComponent<import("vue-demi").ComponentObjectPropsOptions<AuxiliaryPassangerProps>, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").Empty, import("../../types/helper").EmitByProps<AuxiliaryPassangerProps, Required<AuxiliaryPassangerProps>>, never, import("vue-demi").PublicProps, AuxiliaryPassangerProps, AuxiliaryPassangerProps, import("vue-demi").SlotsType<{} & {
7
+ default?: import("../../demi-polyfill").Slot | undefined;
8
+ }>>;
@@ -0,0 +1,46 @@
1
+ import { createVNode } from "vue";
2
+ import { ref } from "vue-demi";
3
+ import { MAX_DEVIATION_DISTANCE_WALKING } from "../../api/contants.js";
4
+ import { defineSetup } from "../../types/helper.js";
5
+ import { watchEffectForDeepOption } from "../../utils/compare.js";
6
+ import { AuxiliaryCircle } from "../AuxiliaryCircle/AuxiliaryCircle.js";
7
+ import { AuxiliaryLine } from "../AuxiliaryLine/AuxiliaryLine.js";
8
+ const usePositionHistory = (source, capacity) => {
9
+ const history = ref([]);
10
+ watchEffectForDeepOption(source, (point) => {
11
+ if (!point)
12
+ return;
13
+ history.value.push([...point]);
14
+ if (history.value.length > capacity) {
15
+ history.value.shift();
16
+ }
17
+ });
18
+ return history;
19
+ };
20
+ const AuxiliaryPassanger = defineSetup("AuxiliaryPassanger", function(props) {
21
+ const passengerPositionHistory = usePositionHistory(() => props.passengerPosition, 20);
22
+ return () => {
23
+ const {
24
+ status,
25
+ passengerPosition
26
+ } = props;
27
+ console.log("passengerPositionHistory = ", passengerPositionHistory.value);
28
+ const prevPositions = passengerPositionHistory.value.slice(0, -1);
29
+ if (status !== "assign" && status !== "confirmed" && status !== "driverStartRelayService" && status !== "dispatched" && status !== "driverStartService" && status !== "book-driverStartService" && status !== "book-dispatched" && status !== "driverArrived")
30
+ return;
31
+ return createVNode("div", null, [!!passengerPosition && createVNode(AuxiliaryCircle, {
32
+ "center": passengerPosition,
33
+ "radius": MAX_DEVIATION_DISTANCE_WALKING,
34
+ "opacity": 0.2
35
+ }, null), prevPositions.length > 0 && createVNode(AuxiliaryLine, {
36
+ "path": prevPositions,
37
+ "type": "circle",
38
+ "color": "purple",
39
+ "scale": MAX_DEVIATION_DISTANCE_WALKING,
40
+ "opacity": 0.2
41
+ }, null)]);
42
+ };
43
+ });
44
+ export {
45
+ AuxiliaryPassanger
46
+ };
@@ -0,0 +1 @@
1
+ export * from "./AuxiliaryPassanger";
@@ -0,0 +1,4 @@
1
+ import { AuxiliaryPassanger } from "./AuxiliaryPassanger.js";
2
+ export {
3
+ AuxiliaryPassanger
4
+ };
@@ -14,6 +14,7 @@ import { createAbortable, assertNotEmptyArray } from "../../utils/helper.js";
14
14
  import { place2point, pipeDefer, lnglat2point } from "../../utils/transform.js";
15
15
  import { toCoordinatePlaceType, toCoordinateTrackPoint } from "../../utils/typeChecking.js";
16
16
  import { AuxiliaryGraspRoad } from "../AuxiliaryGraspRoad/AuxiliaryGraspRoad.js";
17
+ import { AuxiliaryPassanger } from "../AuxiliaryPassanger/AuxiliaryPassanger.js";
17
18
  import { DeviceOrientation } from "../DeviceOrientation/DeviceOrientation.js";
18
19
  import { SectionDispatching, SectionConfirmed, SectionDriverStartRelayService, SectionDriverStartService, SectionBookDispatched, SectionInService, SectionDriverArrived, SectionCanceled, SectionEndService } from "./BusinessTaxiServiceSection.js";
19
20
  const STATUS_NEED_CAR_POSITION = ["book-driverStartService", "dispatched", "driverStartService", "driverStartRelayService", "inService", "driverArrived"];
@@ -210,6 +211,9 @@ const BusinessTaxiServiceMapInner = defineSetup("BusinessTaxiServiceMapInner", f
210
211
  "trackPoints": carTrackPositions,
211
212
  "from": from,
212
213
  "to": to
214
+ }, null), IS_ENABLE_AUXILIARY_GRASP_ROAD && createVNode(AuxiliaryPassanger, {
215
+ "status": driverStatus,
216
+ "passengerPosition": passengerPosition
213
217
  }, null)]
214
218
  });
215
219
  };
@@ -1,6 +1,6 @@
1
1
  import { createVNode } from "vue";
2
2
  import { apiGetAuxiliaryGrapStatus } from "../../api/browser.js";
3
- import { MAX_DEVIATION_DISTANCE, CAR_DISTANCE_MIN } from "../../api/contants.js";
3
+ import { PASSENGER_DISTANCE_MAX, MAX_DEVIATION_DISTANCE, PASSENGER_DISTANCE_MIN, CAR_DISTANCE_MIN } from "../../api/contants.js";
4
4
  import { useMapGeometry } from "../../hooks/useMapGeometry.js";
5
5
  import { useMapSupplier } from "../../hooks/useMapSupplier.js";
6
6
  import { defineSetup } from "../../types/helper.js";
@@ -19,8 +19,6 @@ import { WalkingLine } from "../WalkingLine/WalkingLine.js";
19
19
  import { WalkingRoute } from "../WalkingRoute/WalkingRoute.js";
20
20
  import { WaveCircle } from "../WaveCircle/WaveCircle.js";
21
21
  const IS_ENABLE_AUXILIARY_GRASP_ROAD = apiGetAuxiliaryGrapStatus();
22
- const PASSENGER_DISTANCE_MAX = 2e3;
23
- const PASSENGER_DISTANCE_MIN = 20;
24
22
  const AUTO_FIT_VIEW_INTERVAL = IS_ENABLE_AUXILIARY_GRASP_ROAD ? 24 * 3600 * 1e3 : 15e3;
25
23
  const carDurationWithinMinDistance = (distance) => Math.floor(distance / 5);
26
24
  const SectionDispatching = defineSetup("SectionDispatching", function(props) {
@@ -1,17 +1,17 @@
1
1
  import type { Point } from "../types/interface";
2
2
  export declare const apiLocalIsPointInRing: (point: Point, path: Point[]) => boolean;
3
3
  export declare const useAmapGeometry: () => {
4
- apiMapDistance: (from: Point, to: Point) => number | undefined;
4
+ apiMapDistance: (from: Point, to: Point) => number;
5
5
  apiMapDistanceToLine: (from: Point, line: Point[]) => number | undefined;
6
6
  apiMapDistanceOfLine: (line: Point[]) => number | undefined;
7
7
  };
8
8
  export declare const useGmapGeometry: () => {
9
- apiMapDistance: (from: Point, to: Point) => number | undefined;
9
+ apiMapDistance: (from: Point, to: Point) => number;
10
10
  apiMapDistanceToLine: (from: Point, line: Point[]) => 0 | undefined;
11
11
  apiMapDistanceOfLine: (line: Point[]) => number | undefined;
12
12
  };
13
13
  export declare const useMapGeometry: () => {
14
- apiMapDistance: (from: Point, to: Point) => number | undefined;
14
+ apiMapDistance: (from: Point, to: Point) => number;
15
15
  apiMapDistanceToLine: (from: Point, line: Point[]) => number | undefined;
16
16
  apiMapDistanceOfLine: (line: Point[]) => number | undefined;
17
17
  };
@@ -1,4 +1,4 @@
1
- import { pointInPolygon } from "../utils/geometryPolygon.js";
1
+ import { pointInPolygon, distanceBetweenTwoPoints } from "../utils/geometryPolygon.js";
2
2
  import { vec2lnglat } from "../utils/transform.js";
3
3
  import { Status } from "./useMapLoader.js";
4
4
  import { useMapSupplier } from "./useMapSupplier.js";
@@ -7,7 +7,7 @@ const useAmapGeometry = () => {
7
7
  const payload = useMapSupplier();
8
8
  const apiMapDistance = (from, to) => {
9
9
  if (payload.status !== Status.SUCCESS)
10
- return void 0;
10
+ return distanceBetweenTwoPoints(from, to);
11
11
  return AMap.GeometryUtil.distance(from, to);
12
12
  };
13
13
  const apiMapDistanceToLine = (from, line) => {
@@ -26,7 +26,7 @@ const useGmapGeometry = () => {
26
26
  const payload = useMapSupplier();
27
27
  const apiMapDistance = (from, to) => {
28
28
  if (payload.status !== Status.SUCCESS)
29
- return void 0;
29
+ return distanceBetweenTwoPoints(from, to);
30
30
  return google.maps.geometry.spherical.computeDistanceBetween(vec2lnglat(from), vec2lnglat(to));
31
31
  };
32
32
  const apiMapDistanceToLine = (from, line) => {
@@ -1,15 +1,56 @@
1
1
  import { shallowRef } from "vue-demi";
2
+ import { MAX_DEVIATION_DISTANCE_WALKING } from "../api/contants.js";
2
3
  import { watchPostEffectForDeepOption } from "../utils/compare.js";
3
4
  import { googleServiceApiWalkingRoute, amapJsApiWalkingRoute, gaodeServiceApiWalkingRoute, gmapJsApiWalkingRoute } from "../utils/compatibleWalkingRoute.js";
5
+ import { findClosestPointInLine } from "../utils/geometry.js";
6
+ import { distanceBetweenTwoPoints } from "../utils/geometryPolygon.js";
7
+ import { spaceLog } from "../utils/log.js";
8
+ import { createMemoizeWithTTL } from "../utils/ttlCache.js";
4
9
  import { inTaiwan, inKorean } from "./useMapInChina.js";
5
10
  import { useMapSupplier } from "./useMapSupplier.js";
11
+ const WALKING_ROUTE_CACHE_TTL = 30 * 60 * 1e3;
12
+ const findBestContinuation = (args, cacheEntries) => {
13
+ const [from, to] = args;
14
+ let bestPath;
15
+ for (const [[cacheFrom, cacheTo], path] of cacheEntries) {
16
+ if (!path || path.length < 2)
17
+ continue;
18
+ const deviationOfEndPoint = distanceBetweenTwoPoints(cacheTo, to);
19
+ if (deviationOfEndPoint > MAX_DEVIATION_DISTANCE_WALKING)
20
+ continue;
21
+ {
22
+ const { distance: deviationOfStartPoint } = findClosestPointInLine(
23
+ from,
24
+ [cacheFrom, ...path],
25
+ distanceBetweenTwoPoints
26
+ );
27
+ if (deviationOfStartPoint > MAX_DEVIATION_DISTANCE_WALKING)
28
+ continue;
29
+ }
30
+ const { point: projectedPoint, index } = findClosestPointInLine(
31
+ from,
32
+ path,
33
+ distanceBetweenTwoPoints
34
+ );
35
+ const trimmedPath = [projectedPoint, ...path.slice(index + 1)];
36
+ if (trimmedPath.length < 2)
37
+ continue;
38
+ if (!bestPath || trimmedPath.length < bestPath.length) {
39
+ bestPath = trimmedPath;
40
+ }
41
+ }
42
+ return bestPath;
43
+ };
44
+ const memoizeAmapWalkingRoute = createMemoizeWithTTL(WALKING_ROUTE_CACHE_TTL, findBestContinuation);
45
+ const memoizeGmapWalkingRoute = createMemoizeWithTTL(WALKING_ROUTE_CACHE_TTL, findBestContinuation);
6
46
  const useAWalkingRoute = (props) => {
7
47
  const { googleRoutesProxyUrl } = useMapSupplier();
8
48
  const pathRef = shallowRef([]);
9
49
  const amapWalking = new AMap.Walking({});
10
- const apiMapWalkingRoute = (from, to) => {
50
+ const apiMapWalkingRoute = memoizeAmapWalkingRoute((from, to) => {
51
+ spaceLog("apiMapWalkingRoute", `amap from = ${from} to = ${to}`);
11
52
  return googleRoutesProxyUrl && inTaiwan(from) ? googleServiceApiWalkingRoute(from, to, googleRoutesProxyUrl) : amapJsApiWalkingRoute(from, to, amapWalking);
12
- };
53
+ });
13
54
  watchPostEffectForDeepOption(
14
55
  () => {
15
56
  const { from, to } = props;
@@ -27,11 +68,12 @@ const useGWalkingRoute = (props) => {
27
68
  const { gaodeDirectionWalkingProxyUrl, googleRoutesProxyUrl } = useMapSupplier();
28
69
  const pathRef = shallowRef([]);
29
70
  const gmapDirectionsService = new google.maps.DirectionsService();
30
- const apiMapWalkingRoute = (from, to) => {
71
+ const apiMapWalkingRoute = memoizeGmapWalkingRoute((from, to) => {
72
+ spaceLog("apiMapWalkingRoute", `gmap from = ${from} to = ${to}`);
31
73
  if (inKorean(from))
32
74
  return Promise.resolve([]);
33
75
  return gaodeDirectionWalkingProxyUrl && inKorean(from) ? gaodeServiceApiWalkingRoute(from, to, gaodeDirectionWalkingProxyUrl) : googleRoutesProxyUrl ? googleServiceApiWalkingRoute(from, to, googleRoutesProxyUrl) : gmapJsApiWalkingRoute(from, to, gmapDirectionsService);
34
- };
76
+ });
35
77
  watchPostEffectForDeepOption(
36
78
  () => {
37
79
  const { from, to } = props;
@@ -4,6 +4,7 @@ export declare const findClosestPointInSegment: (point: Point, segment: [Point,
4
4
  export declare const findClosestPointInLine: (point: Point, path: Point[], distanceFn: DistanceFn) => {
5
5
  point: Point;
6
6
  distance: number;
7
+ index: number;
7
8
  };
8
9
  export declare const isPointInSegment: (point: Point, segment: [Point, Point]) => boolean;
9
10
  export declare const isPointInHalfOpenSegment: (point: Point, segment: [Point, Point]) => boolean;
@@ -23,9 +23,10 @@ const findClosestPointInLine = (point, path, distanceFn) => {
23
23
  var _a, _b;
24
24
  let min = Infinity;
25
25
  let target;
26
+ let idx;
26
27
  assertPropNoEmptyArray(path, "findClosestPointInLine", "path");
27
28
  if (path.length === 1)
28
- return { point: path[0], distance: (_a = distanceFn(point, path[0])) != null ? _a : 0 };
29
+ return { point: path[0], distance: (_a = distanceFn(point, path[0])) != null ? _a : 0, index: 0 };
29
30
  for (let index = 0; index < path.length - 1; index++) {
30
31
  const closestPoint = findClosestPointInSegment(point, [path[index], path[index + 1]]);
31
32
  const distance = (_b = distanceFn(point, closestPoint)) != null ? _b : 0;
@@ -33,8 +34,9 @@ const findClosestPointInLine = (point, path, distanceFn) => {
33
34
  continue;
34
35
  target = closestPoint;
35
36
  min = distance;
37
+ idx = index;
36
38
  }
37
- return { point: target, distance: min };
39
+ return { point: target, distance: min, index: idx };
38
40
  };
39
41
  const floatEqual = (x1, x2) => {
40
42
  return Math.abs(x1 - x2) < 1e4 * Number.EPSILON;
@@ -4,3 +4,8 @@ import type { Point } from "../types/interface";
4
4
  * @returns 1 在内部, 0 边界上 , -1 在外部
5
5
  */
6
6
  export declare function pointInPolygon(point: Point, polygon: Point[]): 1 | 0 | -1;
7
+ export declare const distanceBetweenTwoPoints: (from: Point, to: Point) => number;
8
+ /**
9
+ * 计算折线(按顺序连接各点)总长度。
10
+ */
11
+ export declare const computeLineLength: (line: Point[]) => number;
@@ -22,6 +22,33 @@ function pointInPolygon(point, polygon) {
22
22
  }
23
23
  return inside ? 1 : -1;
24
24
  }
25
+ const distanceBetweenTwoPoints = (from, to) => {
26
+ const [lng1, lat1] = from;
27
+ const [lng2, lat2] = to;
28
+ if (lng1 === lng2 && lat1 === lat2)
29
+ return 0;
30
+ const toRad = (deg) => deg * Math.PI / 180;
31
+ const R = 6378137;
32
+ const phi1 = toRad(lat1);
33
+ const phi2 = toRad(lat2);
34
+ const dPhi = toRad(lat2 - lat1);
35
+ const dLambda = toRad(lng2 - lng1);
36
+ const a = Math.sin(dPhi / 2) * Math.sin(dPhi / 2) + Math.cos(phi1) * Math.cos(phi2) * Math.sin(dLambda / 2) * Math.sin(dLambda / 2);
37
+ const c = 2 * Math.asin(Math.min(1, Math.sqrt(a)));
38
+ return R * c;
39
+ };
40
+ const computeLineLength = (line) => {
41
+ var _a;
42
+ if (!Array.isArray(line) || line.length < 2)
43
+ return 0;
44
+ let totalLength = 0;
45
+ for (let i = 1; i < line.length; i++) {
46
+ totalLength += (_a = distanceBetweenTwoPoints(line[i - 1], line[i])) != null ? _a : 0;
47
+ }
48
+ return totalLength;
49
+ };
25
50
  export {
51
+ computeLineLength,
52
+ distanceBetweenTwoPoints,
26
53
  pointInPolygon
27
54
  };
@@ -1,11 +1,19 @@
1
1
  const availableLogKeys = /* @__PURE__ */ new Set();
2
2
  const pkgName = "@heycar/heycars-map";
3
- const pkgVersion = "2.13.0-relay2";
3
+ const pkgVersion = "2.14.0-walkOptimize1";
4
+ const spaceLogSessionKey = "wiajlf;jwiatitruiq3jrlw";
5
+ const enableSessionLogKey = (key) => {
6
+ const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
7
+ sessionParam.set(`log-${key}`, "true");
8
+ sessionStorage.setItem(spaceLogSessionKey, sessionParam.toString());
9
+ };
4
10
  const isEnableLog = (name) => {
5
11
  const searchParam = new URLSearchParams(location.search);
6
- return searchParam.has(`log-${name}`);
12
+ const sessionParam = new URLSearchParams(sessionStorage.getItem(spaceLogSessionKey) || void 0);
13
+ return searchParam.has(`log-${name}`) || sessionParam.has(`log-${name}`);
7
14
  };
8
- window.availableLogKeys = availableLogKeys;
15
+ window.heycarMapAvailableLogKeys = availableLogKeys;
16
+ window.heycarMapEnableSessionLogKey = enableSessionLogKey;
9
17
  const spaceLog = (logKey, ...args) => {
10
18
  availableLogKeys.add(logKey);
11
19
  if (!isEnableLog(logKey))
@@ -0,0 +1,34 @@
1
+ export type Milliseconds = number;
2
+ export interface TTLCache<K, V> {
3
+ get(key: K): V | undefined;
4
+ set(key: K, value: V): void;
5
+ delete(key: K): boolean;
6
+ clear(): void;
7
+ entries(): IterableIterator<[K, V]>;
8
+ }
9
+ /**
10
+ * 高性能 TTL Cache(固定 TTL,不支持动态变更)。
11
+ * - 仅提供最小接口:get/set/delete/clear/entries
12
+ * - 惰性过期:在访问时清理过期项,无额外定时器
13
+ */
14
+ export declare function createTTLCache<K, V>(ttlMs: Milliseconds): TTLCache<K, V>;
15
+ /**
16
+ * 异步函数的 TTL 记忆化工厂
17
+ *
18
+ * 命中策略(按顺序):
19
+ * 1. 精确命中:用 `computeKey(args)` 查缓存。
20
+ * 2. 近似命中:用 `selectFromCache(args, entries)` 在当前有效条目中挑选。
21
+ * 3. 未命中:执行原函数,结果写入缓存。
22
+ *
23
+ * 过期策略:惰性按 `ttlMs` 过期;`ttlMs <= 0` 表示不缓存;传 `Infinity` 视为永不过期。
24
+ *
25
+ * 参数:
26
+ * - `ttlMs`:缓存有效期(毫秒)。
27
+ * - `selectFromCache`:近似命中选择器,入参为本次 `args` 与有效缓存条目的迭代器,返回命中值或 `undefined`。
28
+ * - `computeKey`:精确命中的 key 生成函数,默认 `JSON.stringify`。
29
+ *
30
+ * 返回:`memoize(fn)`,将异步函数包装为带缓存的版本。
31
+ *
32
+ * 说明:不做并发合并;仅实现 TTL 驱逐(无容量上限);近似匹配会遍历有效条目。
33
+ */
34
+ export declare function createMemoizeWithTTL<A extends any[], R>(ttlMs: Milliseconds, selectFromCache: (args: A, cacheEntries: IterableIterator<[A, R]>) => R | undefined, computeKey?: (args: A) => string): (fn: (...args: A) => Promise<R>) => (...args: A) => Promise<R>;
@@ -0,0 +1,64 @@
1
+ function createTTLCache(ttlMs) {
2
+ const store = /* @__PURE__ */ new Map();
3
+ const get = (key) => {
4
+ const record = store.get(key);
5
+ if (!record)
6
+ return void 0;
7
+ const now = Date.now();
8
+ if (record.expireAt !== Infinity && record.expireAt <= now) {
9
+ store.delete(key);
10
+ return void 0;
11
+ }
12
+ return record.value;
13
+ };
14
+ const set = (key, value) => {
15
+ const now = Date.now();
16
+ const expireAt = Number.isFinite(ttlMs) ? now + ttlMs : Infinity;
17
+ if (Number.isFinite(ttlMs) && ttlMs <= 0) {
18
+ store.delete(key);
19
+ return;
20
+ }
21
+ store.set(key, { value, expireAt });
22
+ };
23
+ const del = (key) => store.delete(key);
24
+ const clear = () => {
25
+ store.clear();
26
+ };
27
+ function* entries() {
28
+ const now = Date.now();
29
+ for (const [key, record] of store) {
30
+ if (record.expireAt !== Infinity && record.expireAt <= now) {
31
+ store.delete(key);
32
+ continue;
33
+ }
34
+ yield [key, record.value];
35
+ }
36
+ }
37
+ return { get, set, delete: del, clear, entries };
38
+ }
39
+ function createMemoizeWithTTL(ttlMs, selectFromCache, computeKey = JSON.stringify) {
40
+ const cache = createTTLCache(ttlMs);
41
+ function* cacheEntries() {
42
+ for (const [, record] of cache.entries()) {
43
+ yield [record.args, record.value];
44
+ }
45
+ }
46
+ return function memoize(fn) {
47
+ return async function memoizedTTLFn(...args) {
48
+ const key = computeKey(args);
49
+ const direct = cache.get(key);
50
+ if (direct !== void 0)
51
+ return direct.value;
52
+ const hit = selectFromCache(args, cacheEntries());
53
+ if (hit !== void 0)
54
+ return hit;
55
+ const result = await fn(...args);
56
+ cache.set(key, { args, value: result });
57
+ return result;
58
+ };
59
+ };
60
+ }
61
+ export {
62
+ createMemoizeWithTTL,
63
+ createTTLCache
64
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@heycar/heycars-map",
3
- "version": "2.13.0-relay2",
3
+ "version": "2.14.0-walkOptimize1",
4
4
  "type": "module",
5
5
  "bin": {
6
6
  "checkVersion": "./bin/checkVersion.js",