@heycar/heycars-map 0.1.0
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/.eslintrc.json +15 -0
- package/README.md +18 -0
- package/dist/App.d.ts +1 -0
- package/dist/api/driving.d.ts +12 -0
- package/dist/api/geocoder.d.ts +16 -0
- package/dist/api/geometry.d.ts +20 -0
- package/dist/api/place.d.ts +16 -0
- package/dist/business-components/AddressBox/AddressBox.css.d.ts +7 -0
- package/dist/business-components/AddressBox/AddressBox.d.ts +10 -0
- package/dist/business-components/AddressBox/index.d.ts +1 -0
- package/dist/business-components/AddressLocator/AddressLocator.css.d.ts +1 -0
- package/dist/business-components/AddressLocator/AddressLocator.d.ts +7 -0
- package/dist/business-components/AddressLocator/index.d.ts +1 -0
- package/dist/business-components/DrivingLine/DrivingLine.css.d.ts +1 -0
- package/dist/business-components/DrivingLine/DrivingLine.d.ts +6 -0
- package/dist/business-components/DrivingLine/index.d.ts +1 -0
- package/dist/business-components/PassengerCircle/PassengerCircle.css.d.ts +1 -0
- package/dist/business-components/PassengerCircle/PassengerCircle.d.ts +7 -0
- package/dist/business-components/PassengerCircle/index.d.ts +1 -0
- package/dist/business-components/PlaceCircle/PlaceCircle.css.d.ts +5 -0
- package/dist/business-components/PlaceCircle/PlaceCircle.d.ts +8 -0
- package/dist/business-components/PlaceCircle/index.d.ts +1 -0
- package/dist/business-components/StartEndPoint/StartEndPoint.css.d.ts +20 -0
- package/dist/business-components/StartEndPoint/StartEndPoint.d.ts +9 -0
- package/dist/business-components/StartEndPoint/index.d.ts +1 -0
- package/dist/business-components/TaxiCar/TaxiCar.css.d.ts +3 -0
- package/dist/business-components/TaxiCar/TaxiCar.d.ts +8 -0
- package/dist/business-components/TaxiCar/index.d.ts +1 -0
- package/dist/business-components/WalkingLine/WalkingLine.d.ts +6 -0
- package/dist/business-components/WalkingLine/index.d.ts +1 -0
- package/dist/business-components/WaveCircle/WaveCircle.css.d.ts +4 -0
- package/dist/business-components/WaveCircle/WaveCircle.d.ts +6 -0
- package/dist/business-components/WaveCircle/index.d.ts +1 -0
- package/dist/components/Amap/Amap.css.d.ts +1 -0
- package/dist/components/Amap/Amap.d.ts +7 -0
- package/dist/components/Amap/index.d.ts +1 -0
- package/dist/components/Amap/useAmap.d.ts +399 -0
- package/dist/components/AmapInfoWindow/AmapInfoWindow.d.ts +4 -0
- package/dist/components/AmapInfoWindow/index.d.ts +1 -0
- package/dist/components/AmapLoader/AmapLoader.d.ts +20 -0
- package/dist/components/AmapLoader/index.d.ts +1 -0
- package/dist/components/AmapMarker/AmapMarker.d.ts +2 -0
- package/dist/components/AmapMarker/index.d.ts +1 -0
- package/dist/components/AmapPolygon/AmapPolygon.d.ts +2 -0
- package/dist/components/AmapPolygon/index.d.ts +1 -0
- package/dist/components/AmapPolyline/AmapPolyline.d.ts +2 -0
- package/dist/components/AmapPolyline/index.d.ts +1 -0
- package/dist/components/AmapText/AmapText.d.ts +2 -0
- package/dist/components/AmapText/index.d.ts +1 -0
- package/dist/components/Demo/BusinessDemo.d.ts +2 -0
- package/dist/components/Demo/Demo.css.d.ts +1 -0
- package/dist/components/Demo/Demo.d.ts +2 -0
- package/dist/components/Demo/Hello.d.ts +17 -0
- package/dist/components/Demo/HeycarDemo.d.ts +1 -0
- package/dist/components/Demo/index.d.ts +1 -0
- package/dist/components/Gmap/Gmap.d.ts +5 -0
- package/dist/components/Gmap/index.d.ts +1 -0
- package/dist/components/Gmap/useGmap.d.ts +5 -0
- package/dist/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.d.ts +3 -0
- package/dist/components/GmapAdvancedMarkerView/index.d.ts +1 -0
- package/dist/components/GmapInfoWindow/GmapInfoWindow.d.ts +5 -0
- package/dist/components/GmapInfoWindow/index.d.ts +1 -0
- package/dist/components/GmapLoader/GmapLoader.d.ts +37 -0
- package/dist/components/GmapLoader/index.d.ts +1 -0
- package/dist/components/GmapMarker/GmapMarker.d.ts +3 -0
- package/dist/components/GmapMarker/index.d.ts +1 -0
- package/dist/components/GmapPolygon/GmapPolygon.d.ts +3 -0
- package/dist/components/GmapPolygon/index.d.ts +1 -0
- package/dist/components/GmapPolyline/GmapPolyline.d.ts +3 -0
- package/dist/components/GmapPolyline/index.d.ts +1 -0
- package/dist/components/MapProvider/MapProvider.d.ts +7 -0
- package/dist/components/MapProvider/index.d.ts +1 -0
- package/dist/components/MapProvider/useMapSupplier.d.ts +11 -0
- package/dist/index.cjs +70 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +1498 -0
- package/dist/main.d.ts +1 -0
- package/dist/style.css +1 -0
- package/dist/types/amap/marker.d.ts +11 -0
- package/dist/types/helper.d.ts +30 -0
- package/dist/types/interface.d.ts +1 -0
- package/dist/utils/compare.d.ts +21 -0
- package/dist/utils/dom.d.ts +2 -0
- package/dist/utils/transform.d.ts +9 -0
- package/dist/vite.svg +1 -0
- package/esbuild.mjs +40 -0
- package/index.html +13 -0
- package/package.json +94 -0
- package/public/vite.svg +1 -0
- package/src/App.tsx +10 -0
- package/src/api/driving.ts +87 -0
- package/src/api/geocoder.ts +88 -0
- package/src/api/geometry.ts +44 -0
- package/src/api/place.ts +107 -0
- package/src/assets/icons/svg/address-locator.svg +1 -0
- package/src/assets/icons/svg/arrow-right.svg +1 -0
- package/src/assets/icons/svg/end-point.svg +1 -0
- package/src/assets/icons/svg/passenger-circle.svg +1 -0
- package/src/assets/icons/svg/place-circle.svg +22 -0
- package/src/assets/icons/svg/start-point.svg +1 -0
- package/src/assets/icons/svg/taxi-car.svg +1 -0
- package/src/assets/icons/svg/wave-circle.svg +1 -0
- package/src/business-components/AddressBox/AddressBox.css.ts +55 -0
- package/src/business-components/AddressBox/AddressBox.tsx +69 -0
- package/src/business-components/AddressBox/index.ts +1 -0
- package/src/business-components/AddressLocator/AddressLocator.css.ts +7 -0
- package/src/business-components/AddressLocator/AddressLocator.tsx +40 -0
- package/src/business-components/AddressLocator/index.ts +1 -0
- package/src/business-components/DrivingLine/DrivingLine.css.ts +10 -0
- package/src/business-components/DrivingLine/DrivingLine.tsx +124 -0
- package/src/business-components/DrivingLine/index.ts +1 -0
- package/src/business-components/PassengerCircle/PassengerCircle.css.ts +8 -0
- package/src/business-components/PassengerCircle/PassengerCircle.tsx +42 -0
- package/src/business-components/PassengerCircle/index.ts +1 -0
- package/src/business-components/PlaceCircle/PlaceCircle.css.ts +30 -0
- package/src/business-components/PlaceCircle/PlaceCircle.tsx +66 -0
- package/src/business-components/PlaceCircle/index.ts +1 -0
- package/src/business-components/StartEndPoint/StartEndPoint.css.ts +70 -0
- package/src/business-components/StartEndPoint/StartEndPoint.tsx +103 -0
- package/src/business-components/StartEndPoint/index.ts +1 -0
- package/src/business-components/TaxiCar/TaxiCar.css.ts +16 -0
- package/src/business-components/TaxiCar/TaxiCar.tsx +77 -0
- package/src/business-components/TaxiCar/index.ts +1 -0
- package/src/business-components/WalkingLine/WalkingLine.tsx +73 -0
- package/src/business-components/WalkingLine/index.ts +1 -0
- package/src/business-components/WaveCircle/WaveCircle.css.ts +54 -0
- package/src/business-components/WaveCircle/WaveCircle.tsx +56 -0
- package/src/business-components/WaveCircle/index.ts +1 -0
- package/src/components/Amap/Amap.css.ts +3 -0
- package/src/components/Amap/Amap.ts +58 -0
- package/src/components/Amap/index.ts +1 -0
- package/src/components/Amap/useAmap.ts +9 -0
- package/src/components/AmapInfoWindow/AmapInfoWindow.ts +45 -0
- package/src/components/AmapInfoWindow/index.ts +1 -0
- package/src/components/AmapLoader/AmapLoader.ts +68 -0
- package/src/components/AmapLoader/index.ts +1 -0
- package/src/components/AmapMarker/AmapMarker.ts +38 -0
- package/src/components/AmapMarker/index.ts +1 -0
- package/src/components/AmapPolygon/AmapPolygon.ts +41 -0
- package/src/components/AmapPolygon/index.ts +1 -0
- package/src/components/AmapPolyline/AmapPolyline.ts +40 -0
- package/src/components/AmapPolyline/index.ts +1 -0
- package/src/components/AmapText/AmapText.ts +39 -0
- package/src/components/AmapText/index.ts +1 -0
- package/src/components/Demo/BusinessDemo.tsx +117 -0
- package/src/components/Demo/Demo.css.ts +6 -0
- package/src/components/Demo/Demo.tsx +97 -0
- package/src/components/Demo/Hello.tsx +15 -0
- package/src/components/Demo/HeycarDemo.tsx +31 -0
- package/src/components/Demo/TemplateDemo.vue +11 -0
- package/src/components/Demo/index.ts +1 -0
- package/src/components/Gmap/Gmap.ts +34 -0
- package/src/components/Gmap/index.ts +1 -0
- package/src/components/Gmap/useGmap.ts +7 -0
- package/src/components/GmapAdvancedMarkerView/GmapAdvancedMarkerView.ts +48 -0
- package/src/components/GmapAdvancedMarkerView/index.ts +1 -0
- package/src/components/GmapInfoWindow/GmapInfoWindow.ts +38 -0
- package/src/components/GmapInfoWindow/index.ts +1 -0
- package/src/components/GmapLoader/GmapLoader.ts +79 -0
- package/src/components/GmapLoader/index.ts +1 -0
- package/src/components/GmapMarker/GmapMarker.ts +31 -0
- package/src/components/GmapMarker/index.ts +1 -0
- package/src/components/GmapPolygon/GmapPolygon.ts +29 -0
- package/src/components/GmapPolygon/index.ts +1 -0
- package/src/components/GmapPolyline/GmapPolyline.ts +29 -0
- package/src/components/GmapPolyline/index.ts +1 -0
- package/src/components/MapProvider/MapProvider.tsx +64 -0
- package/src/components/MapProvider/index.ts +1 -0
- package/src/components/MapProvider/useMapSupplier.ts +19 -0
- package/src/index.ts +14 -0
- package/src/main.ts +6 -0
- package/src/style.css +0 -0
- package/src/types/amap/autocomplete.d.ts +64 -0
- package/src/types/amap/driving.d.ts +168 -0
- package/src/types/amap/geocoder.d.ts +214 -0
- package/src/types/amap/marker.ts +11 -0
- package/src/types/amap/place.d.ts +114 -0
- package/src/types/amap/plugin.d.ts +27 -0
- package/src/types/amap/walking.d.ts +76 -0
- package/src/types/global.d.ts +10 -0
- package/src/types/helper.ts +139 -0
- package/src/types/interface.ts +1 -0
- package/src/utils/compare.ts +174 -0
- package/src/utils/dom.ts +14 -0
- package/src/utils/transform.ts +27 -0
- package/src/vite-env.d.ts +12 -0
- package/todo.md +1 -0
- package/tsconfig.json +25 -0
- package/tsconfig.node.json +9 -0
- package/vite.config.dev.ts +17 -0
- package/vite.config.ts +40 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
5
|
+
namespace AMap {
|
|
6
|
+
export interface WalkingOptions {
|
|
7
|
+
// 展现结果的地图实例。当指定此参数后,搜索结果的标注、线路等均会自动添加到此地图上。可选
|
|
8
|
+
map?: AMap.Map;
|
|
9
|
+
// 结果列表的HTML容器id或容器元素,提供此参数后,结果列表将在此容器中进行展示。可选
|
|
10
|
+
panel?: string | HTMLElement;
|
|
11
|
+
// 设置隐藏路径规划的起始点图标 设置为true:隐藏图标;设置false:显示图标\n默认值为:false 显示绿色代表畅通,黄色代表轻微拥堵,红色代表比较拥堵,灰色表示无路况信息。(default false)
|
|
12
|
+
hideMarkers?: boolean;
|
|
13
|
+
// 使用map属性时,绘制的规划线路是否显示描边。缺省为true
|
|
14
|
+
isOutline?: boolean;
|
|
15
|
+
// 使用map属性时,绘制的规划线路的描边颜色。缺省为'white'
|
|
16
|
+
outlineColor?: string;
|
|
17
|
+
// 用于控制在路径规划结束后,是否自动调整地图视野使绘制的路线处于视口的可见范围
|
|
18
|
+
autoFitView?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface WalkingRoute {
|
|
22
|
+
// 起点到终点总步行距离,单位:米
|
|
23
|
+
distance: number;
|
|
24
|
+
// 步行时间预计,单位:秒
|
|
25
|
+
time: number;
|
|
26
|
+
// 路段列表,以道路名称作为分段依据,将整个步行导航方案分隔成若干路段
|
|
27
|
+
steps: WalkStep[];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface WalkStep {
|
|
31
|
+
// 步行子路段描述,规则:沿 road步行 distance 米 action,例:”沿北京站街步行351米”
|
|
32
|
+
instruction: string;
|
|
33
|
+
// 步行子路段距离,单位:米
|
|
34
|
+
distance: number;
|
|
35
|
+
// 步行子路段预计使用时间,单位:秒
|
|
36
|
+
time: number;
|
|
37
|
+
// 步行子路段坐标集合
|
|
38
|
+
path: LngLat[];
|
|
39
|
+
// 道路
|
|
40
|
+
road: string;
|
|
41
|
+
// 本步行子路段完成后动作
|
|
42
|
+
action: string;
|
|
43
|
+
// 步行子路段完成后辅助动作,一般为到达某个公交站点或目的地时返回
|
|
44
|
+
assist_action: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface WalkingResult {
|
|
48
|
+
// 成功状态说明
|
|
49
|
+
info: string;
|
|
50
|
+
// 步行规划起点坐标
|
|
51
|
+
origin: LngLat;
|
|
52
|
+
// 步行规划终点坐标
|
|
53
|
+
destination: LngLat;
|
|
54
|
+
// 步行规划起点
|
|
55
|
+
start: POI;
|
|
56
|
+
// 步行规划终点
|
|
57
|
+
end: POI;
|
|
58
|
+
// 步行导航路段数目
|
|
59
|
+
count: number;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type WalkingCallback = (
|
|
63
|
+
// 返回信息状态 可取值:'complete': result 为 WalkingResult; 'error': result为错误信息;'no_data': result 为 0
|
|
64
|
+
status: "complete" | "error" | "no_data",
|
|
65
|
+
result: WalkingResult | Error | 0
|
|
66
|
+
) => void;
|
|
67
|
+
|
|
68
|
+
export class Walking {
|
|
69
|
+
constructor(option: WalkingOptions);
|
|
70
|
+
// 根据起点、终点坐标,实现步行路线规划
|
|
71
|
+
search(origin: LngLat, destination: LngLat, callback: WalkingCallback): void;
|
|
72
|
+
// 清除搜索的结果
|
|
73
|
+
clear(): void;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import "@amap/amap-jsapi-types";
|
|
2
|
+
import { DefineComponent, defineComponent, h, SetupContext, VNode } from "vue-demi";
|
|
3
|
+
|
|
4
|
+
// vue2
|
|
5
|
+
import type { VNodeChildren } from "vue/types/umd";
|
|
6
|
+
import type { ComponentOptionsBase } from "vue/types/v3-component-options";
|
|
7
|
+
import type { ComponentObjectPropsOptions } from "vue/types/v3-component-props";
|
|
8
|
+
import type { ObjectEmitsOptions, Slot } from "vue/types/v3-setup-context";
|
|
9
|
+
export type VNodeChild = VNode | VNodeChildren;
|
|
10
|
+
export type VueNode = VNode | null | undefined;
|
|
11
|
+
|
|
12
|
+
// vue3
|
|
13
|
+
// export type { VNodeChild } from "vue";
|
|
14
|
+
|
|
15
|
+
type LagecyPropNames<N> = N extends `on${string}` ? never : N;
|
|
16
|
+
export type EmitByProps<T, R = Required<T>> = {
|
|
17
|
+
[K in keyof R as K extends `on${infer N}` ? Uncapitalize<N> : never]: R[K];
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
type RenderFunction = (...args: any[]) => VNodeChild;
|
|
21
|
+
export type SC<P> = Omit<SetupContext<Extract<EmitByProps<P>, ObjectEmitsOptions>>, "slots"> & {
|
|
22
|
+
slots: {
|
|
23
|
+
[K in keyof P as Exclude<P[K], undefined> extends RenderFunction
|
|
24
|
+
? K extends `on${string}`
|
|
25
|
+
? never
|
|
26
|
+
: K
|
|
27
|
+
: never]: P[K];
|
|
28
|
+
} & { default?: Slot };
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type SetupOptions<P> = ComponentOptionsBase<
|
|
32
|
+
P,
|
|
33
|
+
Empty,
|
|
34
|
+
Empty,
|
|
35
|
+
Empty,
|
|
36
|
+
Empty,
|
|
37
|
+
Empty,
|
|
38
|
+
Empty,
|
|
39
|
+
Extract<EmitByProps<P>, ObjectEmitsOptions>,
|
|
40
|
+
Extract<keyof EmitByProps<P>, string>,
|
|
41
|
+
Empty
|
|
42
|
+
>;
|
|
43
|
+
|
|
44
|
+
export type Empty = Record<string, never>;
|
|
45
|
+
|
|
46
|
+
export function defineFc<P = Empty>(render: (props: P, ctx: SC<P>) => VueNode) {
|
|
47
|
+
return defineComponent({
|
|
48
|
+
name: render.name,
|
|
49
|
+
inheritAttrs: false,
|
|
50
|
+
setup(_, ctx) {
|
|
51
|
+
const { attrs, slots } = ctx;
|
|
52
|
+
const props = attrs as unknown as P;
|
|
53
|
+
// todo: 下面是实时订阅的实现,是否不需要。
|
|
54
|
+
const proxiedSlots = new Proxy(slots, {
|
|
55
|
+
get(target, name, receiver) {
|
|
56
|
+
return Reflect.get(target, name, receiver) ?? Reflect.get(props as any, name);
|
|
57
|
+
},
|
|
58
|
+
});
|
|
59
|
+
return () => render(props, { ...ctx, slots: proxiedSlots } as unknown as SC<P>);
|
|
60
|
+
},
|
|
61
|
+
}) as DefineComponent<
|
|
62
|
+
ComponentObjectPropsOptions<P>,
|
|
63
|
+
Empty,
|
|
64
|
+
Empty,
|
|
65
|
+
Empty,
|
|
66
|
+
Empty,
|
|
67
|
+
Empty,
|
|
68
|
+
Empty,
|
|
69
|
+
Extract<EmitByProps<P>, ObjectEmitsOptions>,
|
|
70
|
+
Extract<keyof EmitByProps<P>, string>,
|
|
71
|
+
P
|
|
72
|
+
>;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function defineSetup<P>(setup: (props: P, ctx: SC<P>) => () => VueNode) {
|
|
76
|
+
return defineComponent({
|
|
77
|
+
name: setup.name,
|
|
78
|
+
inheritAttrs: false,
|
|
79
|
+
setup(_, ctx) {
|
|
80
|
+
const { attrs, slots } = ctx;
|
|
81
|
+
const props = attrs as unknown as P;
|
|
82
|
+
const proxiedSlots = new Proxy(slots, {
|
|
83
|
+
get(target, name, receiver) {
|
|
84
|
+
return Reflect.get(target, name, receiver) ?? Reflect.get(props as any, name);
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
return setup(props, { ...ctx, slots: proxiedSlots } as unknown as SC<P>);
|
|
88
|
+
},
|
|
89
|
+
}) as DefineComponent<
|
|
90
|
+
ComponentObjectPropsOptions<P>,
|
|
91
|
+
Empty,
|
|
92
|
+
Empty,
|
|
93
|
+
Empty,
|
|
94
|
+
Empty,
|
|
95
|
+
Empty,
|
|
96
|
+
Empty,
|
|
97
|
+
Extract<EmitByProps<P>, ObjectEmitsOptions>,
|
|
98
|
+
Extract<keyof EmitByProps<P>, string>,
|
|
99
|
+
P
|
|
100
|
+
>;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export function defineLagecySetup<P>(setup: (props: P, ctx: SC<P>) => () => VueNode) {
|
|
104
|
+
return {
|
|
105
|
+
props: (propNames: LagecyPropNames<keyof P>[]) => {
|
|
106
|
+
return defineComponent({
|
|
107
|
+
name: setup.name,
|
|
108
|
+
inheritAttrs: false,
|
|
109
|
+
props: propNames as string[],
|
|
110
|
+
setup(setupProps, ctx) {
|
|
111
|
+
const props = setupProps as P;
|
|
112
|
+
const { slots } = ctx;
|
|
113
|
+
const proxiedSlots = new Proxy(slots, {
|
|
114
|
+
get(target, name, receiver) {
|
|
115
|
+
return Reflect.get(target, name, receiver) ?? Reflect.get(props as any, name);
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
return setup(props, { ...ctx, slots: proxiedSlots } as unknown as SC<P>);
|
|
119
|
+
},
|
|
120
|
+
}) as DefineComponent<
|
|
121
|
+
ComponentObjectPropsOptions<P>,
|
|
122
|
+
Empty,
|
|
123
|
+
Empty,
|
|
124
|
+
Empty,
|
|
125
|
+
Empty,
|
|
126
|
+
Empty,
|
|
127
|
+
Empty,
|
|
128
|
+
Extract<EmitByProps<P>, ObjectEmitsOptions>,
|
|
129
|
+
Extract<keyof EmitByProps<P>, string>,
|
|
130
|
+
P
|
|
131
|
+
>;
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
137
|
+
export function Noop() {}
|
|
138
|
+
|
|
139
|
+
export const createElement = h;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Point = [number, number];
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { isLatLngLiteral } from "@googlemaps/typescript-guards";
|
|
2
|
+
import { createCustomEqual } from "fast-equals";
|
|
3
|
+
import { watch, WatchCallback, watchPostEffect } from "vue-demi";
|
|
4
|
+
import type { Ref, ShallowRef, WatchOptions } from "vue/types/v3-generated";
|
|
5
|
+
import type { EmitFn } from "vue/types/v3-setup-context";
|
|
6
|
+
import type { EmitByProps } from "../types/helper";
|
|
7
|
+
import { property2emitEventName, property2mapEventName } from "./transform";
|
|
8
|
+
|
|
9
|
+
export const deepCompareEqualsForMaps = createCustomEqual((deepEqual) => (a, b) => {
|
|
10
|
+
if (isLatLngLiteral(a) || isLatLngLiteral(b)) {
|
|
11
|
+
return new google.maps.LatLng(a).equals(new google.maps.LatLng(b));
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// TODO extend to other types
|
|
15
|
+
|
|
16
|
+
// use fast-equals for other objects
|
|
17
|
+
return deepEqual(a, b);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export function createDeepCompareMemoize<T>() {
|
|
21
|
+
let prev: T | undefined = undefined;
|
|
22
|
+
|
|
23
|
+
return function memorizedFilter(value: T): T {
|
|
24
|
+
if (!deepCompareEqualsForMaps(value, prev)) {
|
|
25
|
+
prev = value;
|
|
26
|
+
}
|
|
27
|
+
return prev as T;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function useDeepCompareEffectForMaps(callback: () => () => any, dependencies: any[]) {
|
|
32
|
+
const memorizedGetters = dependencies.map(createDeepCompareMemoize);
|
|
33
|
+
watch(memorizedGetters, (value, prev, onClean) => {
|
|
34
|
+
onClean(callback());
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function watchNoneImmediatePostEffectForDeepOption<T>(
|
|
39
|
+
getOption: () => T,
|
|
40
|
+
callback: WatchCallback<T, T>,
|
|
41
|
+
watchOptions?: WatchOptions<false>
|
|
42
|
+
) {
|
|
43
|
+
const memorizedFilter = createDeepCompareMemoize<T>();
|
|
44
|
+
return watch<T, false>(() => memorizedFilter(getOption()), callback, {
|
|
45
|
+
immediate: false,
|
|
46
|
+
flush: "post",
|
|
47
|
+
...watchOptions,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function watchPostEffectForDeepOption<T>(
|
|
52
|
+
getOption: () => T,
|
|
53
|
+
callback: WatchCallback<T, T | undefined>,
|
|
54
|
+
watchOptions?: WatchOptions<true>
|
|
55
|
+
) {
|
|
56
|
+
const memorizedFilter = createDeepCompareMemoize<T>();
|
|
57
|
+
return watch<T, true>(() => memorizedFilter(getOption()), callback, {
|
|
58
|
+
immediate: true,
|
|
59
|
+
flush: "post",
|
|
60
|
+
...watchOptions,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function name2setterName<N extends string>(name: N) {
|
|
65
|
+
return `set${name.charAt(0).toUpperCase()}${name.slice(1)}`;
|
|
66
|
+
}
|
|
67
|
+
type AnyFunction = (...args: any[]) => any;
|
|
68
|
+
type PickSettableOptions<T, S, K extends keyof T = keyof T> = K extends `set${infer N}`
|
|
69
|
+
? Uncapitalize<N> extends S
|
|
70
|
+
? {
|
|
71
|
+
name: Uncapitalize<N>;
|
|
72
|
+
defaultValue?: T[K] extends AnyFunction ? Parameters<T[K]>[0] : never;
|
|
73
|
+
}
|
|
74
|
+
: never
|
|
75
|
+
: never;
|
|
76
|
+
|
|
77
|
+
export function watchPostEffectForMapProperty<T, P>(
|
|
78
|
+
targetRef: ShallowRef<T | undefined> | Ref<T | undefined>,
|
|
79
|
+
props: P,
|
|
80
|
+
nameOptions: PickSettableOptions<T, keyof P>[],
|
|
81
|
+
watchOptions?: WatchOptions<true>
|
|
82
|
+
) {
|
|
83
|
+
const deps = nameOptions.map(
|
|
84
|
+
({ name }) =>
|
|
85
|
+
() =>
|
|
86
|
+
props[name]
|
|
87
|
+
);
|
|
88
|
+
watch(
|
|
89
|
+
deps,
|
|
90
|
+
(values, prevValues) => {
|
|
91
|
+
const target = targetRef.value;
|
|
92
|
+
if (!target) return;
|
|
93
|
+
for (const [idx, value] of values.entries()) {
|
|
94
|
+
const { name, defaultValue } = nameOptions[idx];
|
|
95
|
+
const prev = prevValues[idx];
|
|
96
|
+
if (!deepCompareEqualsForMaps(value, prev)) {
|
|
97
|
+
(target[name2setterName(name) as keyof T] as any)(value ?? defaultValue);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
immediate: true,
|
|
103
|
+
flush: "post",
|
|
104
|
+
...watchOptions,
|
|
105
|
+
}
|
|
106
|
+
);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export function watchNoneImmediatePostEffectForMapProperty<T, P>(
|
|
110
|
+
targetRef: ShallowRef<T | undefined> | Ref<T | undefined>,
|
|
111
|
+
props: P,
|
|
112
|
+
nameOptions: PickSettableOptions<T, keyof P>[],
|
|
113
|
+
watchOptions?: WatchOptions<false>
|
|
114
|
+
) {
|
|
115
|
+
return watchPostEffectForMapProperty(targetRef, props, nameOptions, {
|
|
116
|
+
immediate: false,
|
|
117
|
+
...watchOptions,
|
|
118
|
+
} as unknown as WatchOptions<true>);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
type NamesRestrict<N, S extends string> = N extends `on${string}`
|
|
122
|
+
? Lowercase<N> extends `on${S}`
|
|
123
|
+
? N
|
|
124
|
+
: never
|
|
125
|
+
: never;
|
|
126
|
+
export function watchPostEffectForAMapEvent<
|
|
127
|
+
T extends AMap.Event,
|
|
128
|
+
P,
|
|
129
|
+
E extends string = AMap.EventType
|
|
130
|
+
>(
|
|
131
|
+
targetRef: ShallowRef<T | undefined> | Ref<T | undefined>,
|
|
132
|
+
props: P,
|
|
133
|
+
emit: EmitFn<EmitByProps<P>>,
|
|
134
|
+
propertyNames: NamesRestrict<keyof P, E>[]
|
|
135
|
+
) {
|
|
136
|
+
watchPostEffect((onCleanup) => {
|
|
137
|
+
const target = targetRef.value;
|
|
138
|
+
if (!target) return;
|
|
139
|
+
const cleanList: (() => void)[] = [];
|
|
140
|
+
for (const name of propertyNames) {
|
|
141
|
+
const emitEventName = property2emitEventName(name);
|
|
142
|
+
const eventName = property2mapEventName(name) as AMap.EventType;
|
|
143
|
+
const handler = (e: any) => (emit as EmitFn)(emitEventName, e);
|
|
144
|
+
target.on(eventName, handler);
|
|
145
|
+
cleanList.push(() => target?.off(eventName, handler));
|
|
146
|
+
}
|
|
147
|
+
onCleanup(() => {
|
|
148
|
+
for (const clean of cleanList) clean();
|
|
149
|
+
});
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function watchPostEffectForGMapEvent<T extends google.maps.MVCObject, P>(
|
|
154
|
+
targetRef: ShallowRef<T | undefined> | Ref<T | undefined>,
|
|
155
|
+
props: P,
|
|
156
|
+
emit: EmitFn<EmitByProps<P>>,
|
|
157
|
+
propertyNames: NamesRestrict<keyof P, string>[]
|
|
158
|
+
) {
|
|
159
|
+
watchPostEffect((onCleanup) => {
|
|
160
|
+
const target = targetRef.value;
|
|
161
|
+
if (!target) return;
|
|
162
|
+
const cleanList: (() => void)[] = [];
|
|
163
|
+
for (const name of propertyNames) {
|
|
164
|
+
const emitEventName = property2emitEventName(name);
|
|
165
|
+
const eventName = property2mapEventName(name);
|
|
166
|
+
const handler = (e: any) => (emit as EmitFn)(emitEventName, e);
|
|
167
|
+
const listener = target.addListener(eventName, handler);
|
|
168
|
+
cleanList.push(() => google.maps.event.removeListener(listener));
|
|
169
|
+
}
|
|
170
|
+
onCleanup(() => {
|
|
171
|
+
for (const clean of cleanList) clean();
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
}
|
package/src/utils/dom.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HTMLAttributes, ImgHTMLAttributes } from "vue/types/jsx";
|
|
2
|
+
|
|
3
|
+
export const createDom = (
|
|
4
|
+
tag: string,
|
|
5
|
+
props?: HTMLAttributes | ImgHTMLAttributes,
|
|
6
|
+
innerHtml?: string
|
|
7
|
+
) => {
|
|
8
|
+
const { class: className, ...restProps } = props ?? {};
|
|
9
|
+
const elm = document.createElement(tag);
|
|
10
|
+
if (className) elm.className = className;
|
|
11
|
+
Object.assign(elm, restProps);
|
|
12
|
+
if (innerHtml) elm.innerHTML = innerHtml;
|
|
13
|
+
return elm;
|
|
14
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export const vec2lnglat = ([lng, lat]: [number, number]): google.maps.LatLngLiteral => ({
|
|
2
|
+
lng,
|
|
3
|
+
lat,
|
|
4
|
+
});
|
|
5
|
+
|
|
6
|
+
export interface AsteriskItem {
|
|
7
|
+
type: "normal" | "emphasize";
|
|
8
|
+
value: string;
|
|
9
|
+
}
|
|
10
|
+
export const decodeAsterisk = (encodedValue: string): AsteriskItem[] => {
|
|
11
|
+
const result: AsteriskItem[] = [];
|
|
12
|
+
const tokens = encodedValue.split("*");
|
|
13
|
+
for (const [idx, token] of tokens.entries()) {
|
|
14
|
+
if (!token) continue;
|
|
15
|
+
result.push({ value: token, type: idx % 2 === 0 ? "normal" : "emphasize" });
|
|
16
|
+
}
|
|
17
|
+
return result;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
export const property2emitEventName = (propertyName: string) => {
|
|
21
|
+
const firstLetter = propertyName.charAt(2).toLocaleLowerCase();
|
|
22
|
+
return `${firstLetter}${propertyName.slice(3)}`;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const property2mapEventName = (propertyName: string) => {
|
|
26
|
+
return propertyName.slice(2).toLowerCase();
|
|
27
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
2
|
+
|
|
3
|
+
interface ImportMetaEnv {
|
|
4
|
+
readonly VITE_GMAP_API_KEY: string;
|
|
5
|
+
readonly VITE_GMAP_MAP_ID: string;
|
|
6
|
+
readonly VITE_AMAP_API_KEY: string;
|
|
7
|
+
readonly VITE_AMAP_API_SECRET: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface ImportMeta {
|
|
11
|
+
readonly env: ImportMetaEnv;
|
|
12
|
+
}
|
package/todo.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
https://dawchihliou.github.io/articles/building-custom-google-maps-marker-react-component-like-airbnb-in-nextjs
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ESNext",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"moduleResolution": "Node",
|
|
7
|
+
"strict": true,
|
|
8
|
+
"jsx": "preserve",
|
|
9
|
+
"resolveJsonModule": true,
|
|
10
|
+
"isolatedModules": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"lib": ["ESNext", "DOM"],
|
|
13
|
+
"skipLibCheck": true,
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"importsNotUsedAsValues": "error"
|
|
16
|
+
},
|
|
17
|
+
"include": [
|
|
18
|
+
"src/**/*.ts",
|
|
19
|
+
"src/**/*.d.ts",
|
|
20
|
+
"src/**/*.tsx",
|
|
21
|
+
"src/**/*.vue",
|
|
22
|
+
"../vite.config.dev.ts"
|
|
23
|
+
],
|
|
24
|
+
"references": [{ "path": "./tsconfig.node.json" }]
|
|
25
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
|
|
2
|
+
import pluginVue3 from "@vitejs/plugin-vue";
|
|
3
|
+
import vue3Jsx from "@vitejs/plugin-vue-jsx";
|
|
4
|
+
import pluginVue2 from "@vitejs/plugin-vue2";
|
|
5
|
+
import vue2Jsx from "@vitejs/plugin-vue2-jsx";
|
|
6
|
+
import { defineConfig } from "vite";
|
|
7
|
+
import checker from "vite-plugin-checker";
|
|
8
|
+
import eslint from "vite-plugin-eslint";
|
|
9
|
+
import { isVue2 } from "vue-demi";
|
|
10
|
+
|
|
11
|
+
const vueJsx = isVue2 ? vue2Jsx : vue3Jsx;
|
|
12
|
+
const pluginVue = isVue2 ? pluginVue2 : pluginVue3;
|
|
13
|
+
|
|
14
|
+
// https://vitejs.dev/config/
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
plugins: [pluginVue(), vueJsx(), checker({ typescript: true }), eslint(), vanillaExtractPlugin()],
|
|
17
|
+
});
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { vanillaExtractPlugin } from "@vanilla-extract/vite-plugin";
|
|
2
|
+
import pluginVue3 from "@vitejs/plugin-vue";
|
|
3
|
+
import vue3Jsx from "@vitejs/plugin-vue-jsx";
|
|
4
|
+
import pluginVue2 from "@vitejs/plugin-vue2";
|
|
5
|
+
import vue2Jsx from "@vitejs/plugin-vue2-jsx";
|
|
6
|
+
import { resolve } from "node:path";
|
|
7
|
+
import { defineConfig } from "vite";
|
|
8
|
+
import checker from "vite-plugin-checker";
|
|
9
|
+
import eslint from "vite-plugin-eslint";
|
|
10
|
+
import { isVue2 } from "vue-demi";
|
|
11
|
+
|
|
12
|
+
const vueJsx = isVue2 ? vue2Jsx : vue3Jsx;
|
|
13
|
+
const pluginVue = isVue2 ? pluginVue2 : pluginVue3;
|
|
14
|
+
|
|
15
|
+
// https://vitejs.dev/config/
|
|
16
|
+
export default defineConfig({
|
|
17
|
+
plugins: [pluginVue(), vueJsx(), checker({ typescript: true }), eslint(), vanillaExtractPlugin()],
|
|
18
|
+
build: {
|
|
19
|
+
lib: {
|
|
20
|
+
entry: resolve(__dirname, "src/index.ts"),
|
|
21
|
+
formats: ["es", "cjs"],
|
|
22
|
+
fileName: "index",
|
|
23
|
+
},
|
|
24
|
+
rollupOptions: {
|
|
25
|
+
// make sure to externalize deps that shouldn't be bundled
|
|
26
|
+
// into your library
|
|
27
|
+
external: ["vue"],
|
|
28
|
+
output: {
|
|
29
|
+
// Provide global variables to use in the UMD build
|
|
30
|
+
// for externalized deps
|
|
31
|
+
globals: {
|
|
32
|
+
vue: "Vue",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
optimizeDeps: {
|
|
38
|
+
exclude: ["vue-demi"],
|
|
39
|
+
},
|
|
40
|
+
});
|