@d3-maps/vue 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/LICENCE +21 -0
- package/README.md +52 -0
- package/dist/index.d.ts +112 -0
- package/dist/index.iife.js +1 -0
- package/dist/index.js +310 -0
- package/package.json +69 -0
package/LICENCE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright © 2026 Georgii Bukharov
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# @d3-maps/vue
|
|
2
|
+
|
|
3
|
+
`@d3-maps/vue` provides Vue bindings for `@d3-maps/core` to build SVG maps with Vue, [d3](https://github.com/d3/d3) and [TopoJSON-client](https://github.com/TopoJSON/TopoJSON-client).
|
|
4
|
+
|
|
5
|
+
[docs](https://d3-maps.netlify.app/guide/) | [examples](https://d3-maps.netlify.app/examples/) _(being updated for the new package name)_
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
npm
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @d3-maps/vue
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
pnpm
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pnpm add @d3-maps/vue
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
bun
|
|
22
|
+
|
|
23
|
+
```bash
|
|
24
|
+
bun add @d3-maps/vue
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Usage
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
import { createApp } from 'vue'
|
|
31
|
+
import { plugin as D3MapsVue } from '@d3-maps/vue'
|
|
32
|
+
import App from './App.vue'
|
|
33
|
+
|
|
34
|
+
createApp(App)
|
|
35
|
+
.use(D3MapsVue)
|
|
36
|
+
.mount('#app')
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
_Nuxt 3_ \
|
|
40
|
+
Create `~/plugins/d3-maps-vue.client.ts`:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { plugin as D3MapsVue } from '@d3-maps/vue'
|
|
44
|
+
|
|
45
|
+
export default defineNuxtPlugin((nuxtApp) => {
|
|
46
|
+
nuxtApp.vueApp.use(D3MapsVue)
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## License
|
|
51
|
+
|
|
52
|
+
MIT licensed. Copyright © 2020 Georgii Bukharov. See [LICENSE](./LICENSE) for more details.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import "@d3-maps/core/index.css";
|
|
2
|
+
import * as vue16 from "vue";
|
|
3
|
+
import { App, StyleValue } from "vue";
|
|
4
|
+
import * as _d3_maps_core0 from "@d3-maps/core";
|
|
5
|
+
import { MapConfig, MapContext, MapFeatureProps, MapMarkerProps, ZoomEvent, ZoomProps } from "@d3-maps/core";
|
|
6
|
+
|
|
7
|
+
//#region src/components/Map.vue.d.ts
|
|
8
|
+
type __VLS_Slots$3 = {
|
|
9
|
+
default?: (props: MapContext) => unknown;
|
|
10
|
+
};
|
|
11
|
+
declare const __VLS_base$3: vue16.DefineComponent<MapConfig, {}, {}, {}, {}, vue16.ComponentOptionsMixin, vue16.ComponentOptionsMixin, {}, string, vue16.PublicProps, Readonly<MapConfig> & Readonly<{}>, {}, {}, {}, {}, string, vue16.ComponentProvideOptions, false, {}, any>;
|
|
12
|
+
declare const __VLS_export$4: __VLS_WithSlots$3<typeof __VLS_base$3, __VLS_Slots$3>;
|
|
13
|
+
declare const _default: typeof __VLS_export$4;
|
|
14
|
+
type __VLS_WithSlots$3<T, S> = T & {
|
|
15
|
+
new (): {
|
|
16
|
+
$slots: S;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
//#endregion
|
|
20
|
+
//#region src/components/MapFeature.vue.d.ts
|
|
21
|
+
type __VLS_Props$2 = MapFeatureProps<StyleValue>;
|
|
22
|
+
declare const __VLS_export$3: vue16.DefineComponent<__VLS_Props$2, {}, {}, {}, {}, vue16.ComponentOptionsMixin, vue16.ComponentOptionsMixin, {} & {
|
|
23
|
+
[x: string]: any;
|
|
24
|
+
}, string, vue16.PublicProps, Readonly<__VLS_Props$2> & Readonly<{
|
|
25
|
+
[x: `on${Capitalize<any>}`]: ((...args: any) => any) | undefined;
|
|
26
|
+
}>, {}, {}, {}, {}, string, vue16.ComponentProvideOptions, false, {}, any>;
|
|
27
|
+
declare const _default$1: typeof __VLS_export$3;
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/components/MapFeatures.vue.d.ts
|
|
30
|
+
interface Props {
|
|
31
|
+
idKey?: string;
|
|
32
|
+
fill?: string;
|
|
33
|
+
stroke?: string;
|
|
34
|
+
}
|
|
35
|
+
declare var __VLS_1$2: {
|
|
36
|
+
features: _d3_maps_core0.MapFeature[];
|
|
37
|
+
};
|
|
38
|
+
type __VLS_Slots$2 = {} & {
|
|
39
|
+
default?: (props: typeof __VLS_1$2) => any;
|
|
40
|
+
};
|
|
41
|
+
declare const __VLS_base$2: vue16.DefineComponent<Props, {}, {}, {}, {}, vue16.ComponentOptionsMixin, vue16.ComponentOptionsMixin, {}, string, vue16.PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
42
|
+
idKey: string;
|
|
43
|
+
}, {}, {}, {}, string, vue16.ComponentProvideOptions, false, {}, any>;
|
|
44
|
+
declare const __VLS_export$2: __VLS_WithSlots$2<typeof __VLS_base$2, __VLS_Slots$2>;
|
|
45
|
+
declare const _default$2: typeof __VLS_export$2;
|
|
46
|
+
type __VLS_WithSlots$2<T, S> = T & {
|
|
47
|
+
new (): {
|
|
48
|
+
$slots: S;
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/components/MapMarker.vue.d.ts
|
|
53
|
+
type __VLS_Props$1 = MapMarkerProps<StyleValue>;
|
|
54
|
+
declare var __VLS_1$1: {};
|
|
55
|
+
type __VLS_Slots$1 = {} & {
|
|
56
|
+
default?: (props: typeof __VLS_1$1) => any;
|
|
57
|
+
};
|
|
58
|
+
declare const __VLS_base$1: vue16.DefineComponent<__VLS_Props$1, {}, {}, {}, {}, vue16.ComponentOptionsMixin, vue16.ComponentOptionsMixin, {} & {
|
|
59
|
+
[x: string]: any;
|
|
60
|
+
}, string, vue16.PublicProps, Readonly<__VLS_Props$1> & Readonly<{
|
|
61
|
+
[x: `on${Capitalize<any>}`]: ((...args: any) => any) | undefined;
|
|
62
|
+
}>, {
|
|
63
|
+
coordinates: _d3_maps_core0.MapMarkerCoordinates;
|
|
64
|
+
}, {}, {}, {}, string, vue16.ComponentProvideOptions, false, {}, any>;
|
|
65
|
+
declare const __VLS_export$1: __VLS_WithSlots$1<typeof __VLS_base$1, __VLS_Slots$1>;
|
|
66
|
+
declare const _default$3: typeof __VLS_export$1;
|
|
67
|
+
type __VLS_WithSlots$1<T, S> = T & {
|
|
68
|
+
new (): {
|
|
69
|
+
$slots: S;
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
//#endregion
|
|
73
|
+
//#region src/components/MapZoom.vue.d.ts
|
|
74
|
+
type __VLS_Props = ZoomProps;
|
|
75
|
+
declare var __VLS_1: {};
|
|
76
|
+
type __VLS_Slots = {} & {
|
|
77
|
+
default?: (props: typeof __VLS_1) => any;
|
|
78
|
+
};
|
|
79
|
+
declare const __VLS_base: vue16.DefineComponent<__VLS_Props, {
|
|
80
|
+
container: vue16.Ref<SVGGElement | null, SVGGElement | null>;
|
|
81
|
+
zoomBehavior: vue16.ComputedRef<_d3_maps_core0.ZoomBehavior<SVGSVGElement, unknown>>;
|
|
82
|
+
}, {}, {}, {}, vue16.ComponentOptionsMixin, vue16.ComponentOptionsMixin, {} & {
|
|
83
|
+
zoom: (payload: ZoomEvent) => any;
|
|
84
|
+
zoomstart: (payload: ZoomEvent) => any;
|
|
85
|
+
zoomend: (payload: ZoomEvent) => any;
|
|
86
|
+
}, string, vue16.PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
87
|
+
onZoom?: ((payload: ZoomEvent) => any) | undefined;
|
|
88
|
+
onZoomstart?: ((payload: ZoomEvent) => any) | undefined;
|
|
89
|
+
onZoomend?: ((payload: ZoomEvent) => any) | undefined;
|
|
90
|
+
}>, {
|
|
91
|
+
center: [number, number];
|
|
92
|
+
zoom: number;
|
|
93
|
+
minZoom: number;
|
|
94
|
+
maxZoom: number;
|
|
95
|
+
}, {}, {}, {}, string, vue16.ComponentProvideOptions, false, {}, any>;
|
|
96
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
97
|
+
declare const _default$4: typeof __VLS_export;
|
|
98
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
99
|
+
new (): {
|
|
100
|
+
$slots: S;
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
//#endregion
|
|
104
|
+
//#region src/plugin.d.ts
|
|
105
|
+
/**
|
|
106
|
+
* Vue plugin that registers all d3-maps components globally.
|
|
107
|
+
*/
|
|
108
|
+
declare const plugin: {
|
|
109
|
+
install(app: App): void;
|
|
110
|
+
};
|
|
111
|
+
//#endregion
|
|
112
|
+
export { _default as Map, _default$1 as MapFeature, _default$2 as MapFeatures, _default$3 as MapMarker, _default$4 as MapZoom, plugin };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(e,t,n,r){var i=Object.defineProperty,a=(e,t)=>{let n={};for(var r in e)i(n,r,{get:e[r],enumerable:!0});return t&&i(n,Symbol.toStringTag,{value:`Module`}),n};let o=Symbol(`MapContext`),s=(0,n.defineComponent)((e,{slots:t})=>((0,n.provide)(o,e.context),()=>t.default?.()??null),{props:{context:{type:Object,required:!0}}});(0,n.defineComponent)({name:`MapConsumer`,setup(e,{slots:t}){let r=(0,n.inject)(o);return()=>t.default?t.default(r??{}):null}});function c(){return(0,n.inject)(o)}let l=[`viewBox`];var u=(0,n.defineComponent)({__name:`Map`,props:{width:{},height:{},aspectRatio:{},projection:{type:Function},projectionConfig:{},data:{},dataTransformer:{type:Function}},setup(e){let t=e,i=(0,n.computed)(()=>(0,r.makeMapContext)({width:t.width,height:t.height,aspectRatio:t.aspectRatio,projection:t.projection,projectionConfig:t.projectionConfig,data:t.data,dataTransformer:t.dataTransformer}));return(e,t)=>((0,n.openBlock)(),(0,n.createBlock)((0,n.unref)(s),{context:i.value},{default:(0,n.withCtx)(()=>[((0,n.openBlock)(),(0,n.createElementBlock)(`svg`,(0,n.mergeProps)({viewBox:`0 0 ${i.value.width} ${i.value.height}`},e.$attrs,{class:`d3-map`}),[(0,n.renderSlot)(e.$slots,`default`,(0,n.normalizeProps)((0,n.guardReactiveProps)(i.value)))],16,l))]),_:3},8,[`context`]))}});function d(e,t){let i=(0,n.ref)(`default`),a=t=>(n=>{i.value=(0,r.getObjectStateUpdate)(t),e(t,n)});return{computedStyle:(0,n.computed)(()=>(0,r.resolveObjectStyle)(i.value,(0,n.unref)(t))),onMouseEnter:a(`mouseenter`),onMouseLeave:a(`mouseleave`),onMouseDown:a(`mousedown`),onMouseUp:a(`mouseup`),onFocus:a(`focus`),onBlur:a(`blur`)}}let f=[`d`,`fill`,`stroke`];var p=(0,n.defineComponent)({__name:`MapFeature`,props:{data:{},styles:{},fill:{},stroke:{}},setup(e,{emit:t}){let r=e,i=t,a=c(),o=(0,n.computed)(()=>a?.renderPath(r.data)),{computedStyle:s,onMouseEnter:l,onMouseLeave:u,onMouseDown:p,onMouseUp:m,onFocus:h,onBlur:g}=d(i,(0,n.toRef)(r,`styles`));return(t,r)=>o.value?((0,n.openBlock)(),(0,n.createElementBlock)(`path`,(0,n.mergeProps)({key:0,d:o.value,style:(0,n.unref)(s),fill:e.fill,stroke:e.stroke,onMouseenter:r[0]||=(...e)=>(0,n.unref)(l)&&(0,n.unref)(l)(...e),onMouseleave:r[1]||=(...e)=>(0,n.unref)(u)&&(0,n.unref)(u)(...e),onMousedown:r[2]||=(...e)=>(0,n.unref)(p)&&(0,n.unref)(p)(...e),onMouseup:r[3]||=(...e)=>(0,n.unref)(m)&&(0,n.unref)(m)(...e),onClick:r[4]||=(...e)=>(0,n.unref)(m)&&(0,n.unref)(m)(...e),onFocus:r[5]||=(...e)=>(0,n.unref)(h)&&(0,n.unref)(h)(...e),onBlur:r[6]||=(...e)=>(0,n.unref)(g)&&(0,n.unref)(g)(...e)},t.$attrs),null,16,f)):(0,n.createCommentVNode)(`v-if`,!0)}}),m=(0,n.defineComponent)({__name:`MapFeatures`,props:{idKey:{default:`id`},fill:{},stroke:{}},setup(e){let t=c(),i=(0,n.computed)(()=>t?.features??[]);return(t,a)=>((0,n.openBlock)(),(0,n.createElementBlock)(`g`,null,[(0,n.renderSlot)(t.$slots,`default`,{features:i.value},()=>[((0,n.openBlock)(!0),(0,n.createElementBlock)(n.Fragment,null,(0,n.renderList)(i.value,(i,a)=>((0,n.openBlock)(),(0,n.createBlock)(p,(0,n.mergeProps)({key:(0,n.unref)(r.getFeatureKey)(i,e.idKey,a),data:i,fill:e.fill,stroke:e.stroke},{ref_for:!0},t.$attrs),null,16,[`data`,`fill`,`stroke`]))),128))])]))}});let h=[`transform`];var g=(0,n.defineComponent)({__name:`MapMarker`,props:{coordinates:{default:()=>[0,0]},styles:{}},setup(e,{emit:t}){let i=e,a=t,o=c(),s=(0,n.computed)(()=>(0,r.getMarkerTransform)(o,i.coordinates)),{computedStyle:l,onMouseEnter:u,onMouseLeave:f,onMouseDown:p,onMouseUp:m,onFocus:g,onBlur:_}=d(a,(0,n.toRef)(i,`styles`));return(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`g`,{transform:s.value,style:(0,n.normalizeStyle)((0,n.unref)(l)),onMouseenter:t[0]||=(...e)=>(0,n.unref)(u)&&(0,n.unref)(u)(...e),onMouseleave:t[1]||=(...e)=>(0,n.unref)(f)&&(0,n.unref)(f)(...e),onMousedown:t[2]||=(...e)=>(0,n.unref)(p)&&(0,n.unref)(p)(...e),onMouseup:t[3]||=(...e)=>(0,n.unref)(m)&&(0,n.unref)(m)(...e),onClick:t[4]||=(...e)=>(0,n.unref)(m)&&(0,n.unref)(m)(...e),onFocus:t[5]||=(...e)=>(0,n.unref)(g)&&(0,n.unref)(g)(...e),onBlur:t[6]||=(...e)=>(0,n.unref)(_)&&(0,n.unref)(_)(...e)},[(0,n.renderSlot)(e.$slots,`default`)],44,h))}}),_=(0,n.defineComponent)({__name:`MapZoom`,props:{center:{default:()=>[0,0]},zoom:{default:1},minZoom:{default:1},maxZoom:{default:8},translateExtent:{},modifiers:{}},emits:[`zoomstart`,`zoom`,`zoomend`],setup(e,{expose:t,emit:i}){let a=e,o=i,s=(0,n.ref)(null),l=c(),u=(0,n.computed)(()=>(0,r.createZoomBehavior)(l,{minZoom:a.minZoom,maxZoom:a.maxZoom,translateExtent:a.translateExtent,modifiers:a.modifiers,onZoomStart:e=>o(`zoomstart`,e),onZoom:e=>{s.value&&s.value.setAttribute(`transform`,e.transform.toString()),o(`zoom`,e)},onZoomEnd:e=>o(`zoomend`,e)}));return(0,n.onMounted)(()=>{(0,n.watch)(()=>[u],()=>(0,r.setupZoom)({element:s.value,behavior:u.value,center:a.center,zoom:a.zoom}),{immediate:!0}),(0,n.watch)(()=>[a.center[0],a.center[1],a.zoom],()=>(0,r.applyZoomTransform)({element:s.value,behavior:u.value,center:a.center,zoom:a.zoom}))}),t({container:s,zoomBehavior:u}),(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`g`,{ref_key:`container`,ref:s,class:`d3-map-zoom`},[(0,n.renderSlot)(e.$slots,`default`)],512))}}),v=a({Map:()=>u,MapFeature:()=>p,MapFeatures:()=>m,MapMarker:()=>g,MapZoom:()=>_});e.Map=u,e.MapFeature=p,e.MapFeatures=m,e.MapMarker=g,e.MapZoom=_,e.plugin={install(e){Object.entries(v).forEach(([t,n])=>{e.component(t,n)})}}})(this.D3Maps=this.D3Maps||{},_d3_maps_core_index_css,Vue,D3Maps);
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,310 @@
|
|
|
1
|
+
import "@d3-maps/core/index.css";
|
|
2
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, defineComponent, guardReactiveProps, inject, mergeProps, normalizeProps, normalizeStyle, onMounted, openBlock, provide, ref, renderList, renderSlot, toRef, unref, watch, withCtx } from "vue";
|
|
3
|
+
import { applyZoomTransform, createZoomBehavior, getFeatureKey, getMarkerTransform, getObjectStateUpdate, makeMapContext, resolveObjectStyle, setupZoom } from "@d3-maps/core";
|
|
4
|
+
|
|
5
|
+
//#region rolldown:runtime
|
|
6
|
+
var __defProp = Object.defineProperty;
|
|
7
|
+
var __exportAll = (all, symbols) => {
|
|
8
|
+
let target = {};
|
|
9
|
+
for (var name in all) {
|
|
10
|
+
__defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: true
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
if (symbols) {
|
|
16
|
+
__defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
//#endregion
|
|
22
|
+
//#region src/components/MapContext.ts
|
|
23
|
+
const mapContextKey = Symbol("MapContext");
|
|
24
|
+
const MapProvider = defineComponent((props, { slots }) => {
|
|
25
|
+
provide(mapContextKey, props.context);
|
|
26
|
+
return () => slots.default?.() ?? null;
|
|
27
|
+
}, { props: { context: {
|
|
28
|
+
type: Object,
|
|
29
|
+
required: true
|
|
30
|
+
} } });
|
|
31
|
+
const MapConsumer = defineComponent({
|
|
32
|
+
name: "MapConsumer",
|
|
33
|
+
setup(_, { slots }) {
|
|
34
|
+
const context = inject(mapContextKey);
|
|
35
|
+
return () => {
|
|
36
|
+
if (!slots.default) return null;
|
|
37
|
+
return slots.default(context ?? {});
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
function useMapContext() {
|
|
42
|
+
return inject(mapContextKey);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
//#endregion
|
|
46
|
+
//#region src/components/Map.vue?vue&type=script&setup=true&lang.ts
|
|
47
|
+
const _hoisted_1$2 = ["viewBox"];
|
|
48
|
+
var Map_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
49
|
+
__name: "Map",
|
|
50
|
+
props: {
|
|
51
|
+
width: {},
|
|
52
|
+
height: {},
|
|
53
|
+
aspectRatio: {},
|
|
54
|
+
projection: { type: Function },
|
|
55
|
+
projectionConfig: {},
|
|
56
|
+
data: {},
|
|
57
|
+
dataTransformer: { type: Function }
|
|
58
|
+
},
|
|
59
|
+
setup(__props) {
|
|
60
|
+
const props = __props;
|
|
61
|
+
const context = computed(() => makeMapContext({
|
|
62
|
+
width: props.width,
|
|
63
|
+
height: props.height,
|
|
64
|
+
aspectRatio: props.aspectRatio,
|
|
65
|
+
projection: props.projection,
|
|
66
|
+
projectionConfig: props.projectionConfig,
|
|
67
|
+
data: props.data,
|
|
68
|
+
dataTransformer: props.dataTransformer
|
|
69
|
+
}));
|
|
70
|
+
return (_ctx, _cache) => {
|
|
71
|
+
return openBlock(), createBlock(unref(MapProvider), { context: context.value }, {
|
|
72
|
+
default: withCtx(() => [(openBlock(), createElementBlock("svg", mergeProps({ viewBox: `0 0 ${context.value.width} ${context.value.height}` }, _ctx.$attrs, { class: "d3-map" }), [renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps(context.value)))], 16, _hoisted_1$2))]),
|
|
73
|
+
_: 3
|
|
74
|
+
}, 8, ["context"]);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/components/Map.vue
|
|
81
|
+
var Map_default = Map_vue_vue_type_script_setup_true_lang_default;
|
|
82
|
+
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/lib/useMapObject.ts
|
|
85
|
+
function useMapObject(emit, styles) {
|
|
86
|
+
const state = ref("default");
|
|
87
|
+
const eventCallbackFactory = (eventName) => ((event) => {
|
|
88
|
+
state.value = getObjectStateUpdate(eventName);
|
|
89
|
+
emit(eventName, event);
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
computedStyle: computed(() => resolveObjectStyle(state.value, unref(styles))),
|
|
93
|
+
onMouseEnter: eventCallbackFactory("mouseenter"),
|
|
94
|
+
onMouseLeave: eventCallbackFactory("mouseleave"),
|
|
95
|
+
onMouseDown: eventCallbackFactory("mousedown"),
|
|
96
|
+
onMouseUp: eventCallbackFactory("mouseup"),
|
|
97
|
+
onFocus: eventCallbackFactory("focus"),
|
|
98
|
+
onBlur: eventCallbackFactory("blur")
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
//#endregion
|
|
103
|
+
//#region src/components/MapFeature.vue?vue&type=script&setup=true&lang.ts
|
|
104
|
+
const _hoisted_1$1 = [
|
|
105
|
+
"d",
|
|
106
|
+
"fill",
|
|
107
|
+
"stroke"
|
|
108
|
+
];
|
|
109
|
+
var MapFeature_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
110
|
+
__name: "MapFeature",
|
|
111
|
+
props: {
|
|
112
|
+
data: {},
|
|
113
|
+
styles: {},
|
|
114
|
+
fill: {},
|
|
115
|
+
stroke: {}
|
|
116
|
+
},
|
|
117
|
+
setup(__props, { emit: __emit }) {
|
|
118
|
+
const props = __props;
|
|
119
|
+
const emit = __emit;
|
|
120
|
+
const context = useMapContext();
|
|
121
|
+
const path = computed(() => context?.renderPath(props.data));
|
|
122
|
+
const { computedStyle, onMouseEnter, onMouseLeave, onMouseDown, onMouseUp, onFocus, onBlur } = useMapObject(emit, toRef(props, "styles"));
|
|
123
|
+
return (_ctx, _cache) => {
|
|
124
|
+
return path.value ? (openBlock(), createElementBlock("path", mergeProps({
|
|
125
|
+
key: 0,
|
|
126
|
+
d: path.value,
|
|
127
|
+
style: unref(computedStyle),
|
|
128
|
+
fill: __props.fill,
|
|
129
|
+
stroke: __props.stroke,
|
|
130
|
+
onMouseenter: _cache[0] || (_cache[0] = (...args) => unref(onMouseEnter) && unref(onMouseEnter)(...args)),
|
|
131
|
+
onMouseleave: _cache[1] || (_cache[1] = (...args) => unref(onMouseLeave) && unref(onMouseLeave)(...args)),
|
|
132
|
+
onMousedown: _cache[2] || (_cache[2] = (...args) => unref(onMouseDown) && unref(onMouseDown)(...args)),
|
|
133
|
+
onMouseup: _cache[3] || (_cache[3] = (...args) => unref(onMouseUp) && unref(onMouseUp)(...args)),
|
|
134
|
+
onClick: _cache[4] || (_cache[4] = (...args) => unref(onMouseUp) && unref(onMouseUp)(...args)),
|
|
135
|
+
onFocus: _cache[5] || (_cache[5] = (...args) => unref(onFocus) && unref(onFocus)(...args)),
|
|
136
|
+
onBlur: _cache[6] || (_cache[6] = (...args) => unref(onBlur) && unref(onBlur)(...args))
|
|
137
|
+
}, _ctx.$attrs), null, 16, _hoisted_1$1)) : createCommentVNode("v-if", true);
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
//#endregion
|
|
143
|
+
//#region src/components/MapFeature.vue
|
|
144
|
+
var MapFeature_default = MapFeature_vue_vue_type_script_setup_true_lang_default;
|
|
145
|
+
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/components/MapFeatures.vue?vue&type=script&setup=true&lang.ts
|
|
148
|
+
var MapFeatures_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
149
|
+
__name: "MapFeatures",
|
|
150
|
+
props: {
|
|
151
|
+
idKey: { default: "id" },
|
|
152
|
+
fill: {},
|
|
153
|
+
stroke: {}
|
|
154
|
+
},
|
|
155
|
+
setup(__props) {
|
|
156
|
+
const context = useMapContext();
|
|
157
|
+
const features = computed(() => context?.features ?? []);
|
|
158
|
+
return (_ctx, _cache) => {
|
|
159
|
+
return openBlock(), createElementBlock("g", null, [renderSlot(_ctx.$slots, "default", { features: features.value }, () => [(openBlock(true), createElementBlock(Fragment, null, renderList(features.value, (feature, index) => {
|
|
160
|
+
return openBlock(), createBlock(MapFeature_default, mergeProps({
|
|
161
|
+
key: unref(getFeatureKey)(feature, __props.idKey, index),
|
|
162
|
+
data: feature,
|
|
163
|
+
fill: __props.fill,
|
|
164
|
+
stroke: __props.stroke
|
|
165
|
+
}, { ref_for: true }, _ctx.$attrs), null, 16, [
|
|
166
|
+
"data",
|
|
167
|
+
"fill",
|
|
168
|
+
"stroke"
|
|
169
|
+
]);
|
|
170
|
+
}), 128))])]);
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/components/MapFeatures.vue
|
|
177
|
+
var MapFeatures_default = MapFeatures_vue_vue_type_script_setup_true_lang_default;
|
|
178
|
+
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/components/MapMarker.vue?vue&type=script&setup=true&lang.ts
|
|
181
|
+
const _hoisted_1 = ["transform"];
|
|
182
|
+
var MapMarker_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
183
|
+
__name: "MapMarker",
|
|
184
|
+
props: {
|
|
185
|
+
coordinates: { default: () => [0, 0] },
|
|
186
|
+
styles: {}
|
|
187
|
+
},
|
|
188
|
+
setup(__props, { emit: __emit }) {
|
|
189
|
+
const props = __props;
|
|
190
|
+
const emit = __emit;
|
|
191
|
+
const context = useMapContext();
|
|
192
|
+
const transform = computed(() => {
|
|
193
|
+
return getMarkerTransform(context, props.coordinates);
|
|
194
|
+
});
|
|
195
|
+
const { computedStyle, onMouseEnter, onMouseLeave, onMouseDown, onMouseUp, onFocus, onBlur } = useMapObject(emit, toRef(props, "styles"));
|
|
196
|
+
return (_ctx, _cache) => {
|
|
197
|
+
return openBlock(), createElementBlock("g", {
|
|
198
|
+
transform: transform.value,
|
|
199
|
+
style: normalizeStyle(unref(computedStyle)),
|
|
200
|
+
onMouseenter: _cache[0] || (_cache[0] = (...args) => unref(onMouseEnter) && unref(onMouseEnter)(...args)),
|
|
201
|
+
onMouseleave: _cache[1] || (_cache[1] = (...args) => unref(onMouseLeave) && unref(onMouseLeave)(...args)),
|
|
202
|
+
onMousedown: _cache[2] || (_cache[2] = (...args) => unref(onMouseDown) && unref(onMouseDown)(...args)),
|
|
203
|
+
onMouseup: _cache[3] || (_cache[3] = (...args) => unref(onMouseUp) && unref(onMouseUp)(...args)),
|
|
204
|
+
onClick: _cache[4] || (_cache[4] = (...args) => unref(onMouseUp) && unref(onMouseUp)(...args)),
|
|
205
|
+
onFocus: _cache[5] || (_cache[5] = (...args) => unref(onFocus) && unref(onFocus)(...args)),
|
|
206
|
+
onBlur: _cache[6] || (_cache[6] = (...args) => unref(onBlur) && unref(onBlur)(...args))
|
|
207
|
+
}, [renderSlot(_ctx.$slots, "default")], 44, _hoisted_1);
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
//#endregion
|
|
213
|
+
//#region src/components/MapMarker.vue
|
|
214
|
+
var MapMarker_default = MapMarker_vue_vue_type_script_setup_true_lang_default;
|
|
215
|
+
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/components/MapZoom.vue?vue&type=script&setup=true&lang.ts
|
|
218
|
+
var MapZoom_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComponent({
|
|
219
|
+
__name: "MapZoom",
|
|
220
|
+
props: {
|
|
221
|
+
center: { default: () => [0, 0] },
|
|
222
|
+
zoom: { default: 1 },
|
|
223
|
+
minZoom: { default: 1 },
|
|
224
|
+
maxZoom: { default: 8 },
|
|
225
|
+
translateExtent: {},
|
|
226
|
+
modifiers: {}
|
|
227
|
+
},
|
|
228
|
+
emits: [
|
|
229
|
+
"zoomstart",
|
|
230
|
+
"zoom",
|
|
231
|
+
"zoomend"
|
|
232
|
+
],
|
|
233
|
+
setup(__props, { expose: __expose, emit: __emit }) {
|
|
234
|
+
const props = __props;
|
|
235
|
+
const emit = __emit;
|
|
236
|
+
const container = ref(null);
|
|
237
|
+
const context = useMapContext();
|
|
238
|
+
const zoomBehavior = computed(() => {
|
|
239
|
+
return createZoomBehavior(context, {
|
|
240
|
+
minZoom: props.minZoom,
|
|
241
|
+
maxZoom: props.maxZoom,
|
|
242
|
+
translateExtent: props.translateExtent,
|
|
243
|
+
modifiers: props.modifiers,
|
|
244
|
+
onZoomStart: (event) => emit("zoomstart", event),
|
|
245
|
+
onZoom: (event) => {
|
|
246
|
+
if (container.value) container.value.setAttribute("transform", event.transform.toString());
|
|
247
|
+
emit("zoom", event);
|
|
248
|
+
},
|
|
249
|
+
onZoomEnd: (event) => emit("zoomend", event)
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
onMounted(() => {
|
|
253
|
+
watch(() => [zoomBehavior], () => setupZoom({
|
|
254
|
+
element: container.value,
|
|
255
|
+
behavior: zoomBehavior.value,
|
|
256
|
+
center: props.center,
|
|
257
|
+
zoom: props.zoom
|
|
258
|
+
}), { immediate: true });
|
|
259
|
+
watch(() => [
|
|
260
|
+
props.center[0],
|
|
261
|
+
props.center[1],
|
|
262
|
+
props.zoom
|
|
263
|
+
], () => applyZoomTransform({
|
|
264
|
+
element: container.value,
|
|
265
|
+
behavior: zoomBehavior.value,
|
|
266
|
+
center: props.center,
|
|
267
|
+
zoom: props.zoom
|
|
268
|
+
}));
|
|
269
|
+
});
|
|
270
|
+
__expose({
|
|
271
|
+
container,
|
|
272
|
+
zoomBehavior
|
|
273
|
+
});
|
|
274
|
+
return (_ctx, _cache) => {
|
|
275
|
+
return openBlock(), createElementBlock("g", {
|
|
276
|
+
ref_key: "container",
|
|
277
|
+
ref: container,
|
|
278
|
+
class: "d3-map-zoom"
|
|
279
|
+
}, [renderSlot(_ctx.$slots, "default")], 512);
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
//#endregion
|
|
285
|
+
//#region src/components/MapZoom.vue
|
|
286
|
+
var MapZoom_default = MapZoom_vue_vue_type_script_setup_true_lang_default;
|
|
287
|
+
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/components/index.ts
|
|
290
|
+
var components_exports = /* @__PURE__ */ __exportAll({
|
|
291
|
+
Map: () => Map_default,
|
|
292
|
+
MapFeature: () => MapFeature_default,
|
|
293
|
+
MapFeatures: () => MapFeatures_default,
|
|
294
|
+
MapMarker: () => MapMarker_default,
|
|
295
|
+
MapZoom: () => MapZoom_default
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/plugin.ts
|
|
300
|
+
/**
|
|
301
|
+
* Vue plugin that registers all d3-maps components globally.
|
|
302
|
+
*/
|
|
303
|
+
const plugin = { install(app) {
|
|
304
|
+
Object.entries(components_exports).forEach(([name, component]) => {
|
|
305
|
+
app.component(name, component);
|
|
306
|
+
});
|
|
307
|
+
} };
|
|
308
|
+
|
|
309
|
+
//#endregion
|
|
310
|
+
export { Map_default as Map, MapFeature_default as MapFeature, MapFeatures_default as MapFeatures, MapMarker_default as MapMarker, MapZoom_default as MapZoom, plugin };
|
package/package.json
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@d3-maps/vue",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"private": false,
|
|
6
|
+
"description": "Vue bindings for @d3-maps/core to build reactive D3 SVG maps",
|
|
7
|
+
"author": "Georgii Bukharov <souljorje@gmail.com>",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"publishConfig": {
|
|
10
|
+
"access": "public"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://d3-maps.netlify.app",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "https://github.com/souljorje/d3-maps.git",
|
|
16
|
+
"directory": "packages/vue"
|
|
17
|
+
},
|
|
18
|
+
"bugs": {
|
|
19
|
+
"url": "https://github.com/souljorje/d3-maps/issues"
|
|
20
|
+
},
|
|
21
|
+
"keywords": [
|
|
22
|
+
"vue",
|
|
23
|
+
"d3",
|
|
24
|
+
"svg",
|
|
25
|
+
"map"
|
|
26
|
+
],
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"types": "./dist/index.d.ts",
|
|
30
|
+
"import": "./dist/index.js",
|
|
31
|
+
"browser": "./dist/index.iife.js"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"main": "dist/index.js",
|
|
35
|
+
"module": "dist/index.js",
|
|
36
|
+
"browser": "dist/index.iife.js",
|
|
37
|
+
"unpkg": "dist/index.iife.js",
|
|
38
|
+
"jsdelivr": "dist/index.iife.js",
|
|
39
|
+
"types": "dist/index.d.ts",
|
|
40
|
+
"files": [
|
|
41
|
+
"dist/*"
|
|
42
|
+
],
|
|
43
|
+
"peerDependencies": {
|
|
44
|
+
"vue": "3.5.25"
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"@d3-maps/core": "0.1.0"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/geojson": "^7946.0.16",
|
|
51
|
+
"@types/topojson-client": "^3.1.5",
|
|
52
|
+
"@types/topojson-specification": "^1.0.5",
|
|
53
|
+
"@vitejs/plugin-vue": "^6.0.2",
|
|
54
|
+
"@vue/test-utils": "^2.4.6",
|
|
55
|
+
"jsdom": "^27.3.0",
|
|
56
|
+
"tsdown": "0.19.0",
|
|
57
|
+
"typescript": "^5.9.3",
|
|
58
|
+
"vitest": "^4.0.15",
|
|
59
|
+
"vue": "3.5.25",
|
|
60
|
+
"vue-tsc": "^3.2.0",
|
|
61
|
+
"unplugin-vue": "^6.0.1"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"typecheck": "vue-tsc --noEmit",
|
|
65
|
+
"build": "pnpm run typecheck && tsdown",
|
|
66
|
+
"test": "vitest run",
|
|
67
|
+
"test:watch": "vitest"
|
|
68
|
+
}
|
|
69
|
+
}
|