@d3-maps/vue 0.3.0 → 0.4.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/README.md +6 -0
- package/dist/index.d.ts +49 -27
- package/dist/index.iife.js +1 -1
- package/dist/index.js +32 -44
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -47,6 +47,12 @@ export default defineNuxtPlugin((nuxtApp) => {
|
|
|
47
47
|
})
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
## Styling
|
|
51
|
+
|
|
52
|
+
Importing `@d3-maps/vue` automatically includes `@d3-maps/core/index.css`
|
|
53
|
+
|
|
54
|
+
If you need strict stylesheet ordering, load your global reset/theme styles before importing the adapter entry
|
|
55
|
+
|
|
50
56
|
## License
|
|
51
57
|
|
|
52
58
|
MIT licensed. Copyright © 2020 Georgii Bukharov. See [LICENSE](./LICENSE) for more details.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import "@d3-maps/core/index.css";
|
|
2
|
-
import * as
|
|
3
|
-
import { App, StyleValue } from "vue";
|
|
2
|
+
import * as vue6 from "vue";
|
|
3
|
+
import { App, ComputedRef, InjectionKey, MaybeRef, StyleValue } from "vue";
|
|
4
4
|
import { ExtendedFeature, ExtendedFeatureCollection, GeoPath, GeoProjection } from "d3-geo";
|
|
5
5
|
import { Topology } from "topojson-specification";
|
|
6
6
|
import { mesh } from "topojson-client";
|
|
7
7
|
import { D3ZoomEvent, ZoomBehavior } from "d3-zoom";
|
|
8
8
|
|
|
9
9
|
//#region ../core/src/lib/mapObject.d.ts
|
|
10
|
+
type MapObjectFocusEventType = 'focus' | 'blur';
|
|
11
|
+
type MapObjectMouseEventType = 'mouseenter' | 'mouseleave' | 'mousedown' | 'mouseup';
|
|
12
|
+
type MapObjectEventType = MapObjectFocusEventType | MapObjectMouseEventType;
|
|
13
|
+
type MapObjectEvent<E> = E extends MapObjectFocusEventType ? FocusEvent : MouseEvent;
|
|
10
14
|
/**
|
|
11
15
|
* Supported interaction states for map objects.
|
|
12
16
|
*/
|
|
13
17
|
declare const mapObjectState: readonly ["default", "hover", "active"];
|
|
14
18
|
type MapObjectState = typeof mapObjectState[number];
|
|
15
|
-
type MapObjectStyles<TStyle> = Partial<Record<MapObjectState, TStyle>>;
|
|
19
|
+
type MapObjectStyles$1<TStyle> = Partial<Record<MapObjectState, TStyle>>;
|
|
16
20
|
//#endregion
|
|
17
21
|
//#region ../core/src/lib/feature.d.ts
|
|
18
22
|
/**
|
|
@@ -26,7 +30,7 @@ type MapFeature = (ExtendedFeature & Record<string, unknown>) | ExtendedFeature;
|
|
|
26
30
|
*/
|
|
27
31
|
interface MapFeatureProps<TStyle = unknown> {
|
|
28
32
|
data: MapFeature;
|
|
29
|
-
styles?: MapObjectStyles<TStyle>;
|
|
33
|
+
styles?: MapObjectStyles$1<TStyle>;
|
|
30
34
|
fill?: string;
|
|
31
35
|
stroke?: string;
|
|
32
36
|
}
|
|
@@ -124,7 +128,7 @@ interface MapConfig {
|
|
|
124
128
|
/**
|
|
125
129
|
* Projection factory from d3-geo (or a compatible implementation).
|
|
126
130
|
*
|
|
127
|
-
* Example: `
|
|
131
|
+
* Example: `geoNaturalEarth1`.
|
|
128
132
|
*/
|
|
129
133
|
projection?: () => GeoProjection;
|
|
130
134
|
/**
|
|
@@ -165,7 +169,7 @@ type MapMarkerCoordinates = [number, number];
|
|
|
165
169
|
*/
|
|
166
170
|
interface MapMarkerProps<TStyle = unknown> {
|
|
167
171
|
coordinates?: MapMarkerCoordinates;
|
|
168
|
-
styles?: MapObjectStyles<TStyle>;
|
|
172
|
+
styles?: MapObjectStyles$1<TStyle>;
|
|
169
173
|
}
|
|
170
174
|
//#endregion
|
|
171
175
|
//#region ../core/src/lib/zoom.d.ts
|
|
@@ -192,7 +196,7 @@ interface ZoomEvent extends D3ZoomEvent<SVGSVGElement, unknown> {}
|
|
|
192
196
|
type __VLS_Slots$3 = {
|
|
193
197
|
default?: (props: MapContext) => unknown;
|
|
194
198
|
};
|
|
195
|
-
declare const __VLS_base$3:
|
|
199
|
+
declare const __VLS_base$3: vue6.DefineComponent<MapConfig, {}, {}, {}, {}, vue6.ComponentOptionsMixin, vue6.ComponentOptionsMixin, {}, string, vue6.PublicProps, Readonly<MapConfig> & Readonly<{}>, {}, {}, {}, {}, string, vue6.ComponentProvideOptions, false, {}, any>;
|
|
196
200
|
declare const __VLS_export$5: __VLS_WithSlots$3<typeof __VLS_base$3, __VLS_Slots$3>;
|
|
197
201
|
declare const _default: typeof __VLS_export$5;
|
|
198
202
|
type __VLS_WithSlots$3<T, S> = T & {
|
|
@@ -203,19 +207,33 @@ type __VLS_WithSlots$3<T, S> = T & {
|
|
|
203
207
|
//#endregion
|
|
204
208
|
//#region src/components/MapFeature.vue.d.ts
|
|
205
209
|
type __VLS_Props$1 = MapFeatureProps<StyleValue>;
|
|
206
|
-
declare const __VLS_export$4:
|
|
210
|
+
declare const __VLS_export$4: vue6.DefineComponent<__VLS_Props$1, {}, {}, {}, {}, vue6.ComponentOptionsMixin, vue6.ComponentOptionsMixin, {} & {
|
|
207
211
|
[x: string]: any;
|
|
208
|
-
}, string,
|
|
212
|
+
}, string, vue6.PublicProps, Readonly<__VLS_Props$1> & Readonly<{
|
|
209
213
|
[x: `on${Capitalize<any>}`]: ((...args: any) => any) | undefined;
|
|
210
|
-
}>, {}, {}, {}, {}, string,
|
|
214
|
+
}>, {}, {}, {}, {}, string, vue6.ComponentProvideOptions, false, {}, any>;
|
|
211
215
|
declare const _default$1: typeof __VLS_export$4;
|
|
212
216
|
//#endregion
|
|
217
|
+
//#region src/hooks/useMapObject.d.ts
|
|
218
|
+
type MapObjectStyles = MapObjectStyles$1<StyleValue>;
|
|
219
|
+
type MapObjectEmit = <E extends MapObjectEventType>(event: E, payload: MapObjectEvent<E>) => void;
|
|
220
|
+
interface UseMapObjectResult {
|
|
221
|
+
computedStyle: ComputedRef<StyleValue | undefined>;
|
|
222
|
+
onMouseEnter: (event: MouseEvent) => void;
|
|
223
|
+
onMouseLeave: (event: MouseEvent) => void;
|
|
224
|
+
onMouseDown: (event: MouseEvent) => void;
|
|
225
|
+
onMouseUp: (event: MouseEvent) => void;
|
|
226
|
+
onFocus: (event: FocusEvent) => void;
|
|
227
|
+
onBlur: (event: FocusEvent) => void;
|
|
228
|
+
}
|
|
229
|
+
declare function useMapObject(emit: MapObjectEmit, styles: MaybeRef<MapObjectStyles | undefined>): UseMapObjectResult;
|
|
230
|
+
//#endregion
|
|
213
231
|
//#region src/components/MapFeatures.vue.d.ts
|
|
214
232
|
interface Props$1 {
|
|
215
233
|
idKey?: string;
|
|
216
234
|
fill?: string;
|
|
217
235
|
stroke?: string;
|
|
218
|
-
styles?: MapObjectStyles
|
|
236
|
+
styles?: MapObjectStyles;
|
|
219
237
|
}
|
|
220
238
|
declare var __VLS_1$2: {
|
|
221
239
|
features: MapFeature[];
|
|
@@ -223,9 +241,9 @@ declare var __VLS_1$2: {
|
|
|
223
241
|
type __VLS_Slots$2 = {} & {
|
|
224
242
|
default?: (props: typeof __VLS_1$2) => any;
|
|
225
243
|
};
|
|
226
|
-
declare const __VLS_base$2:
|
|
244
|
+
declare const __VLS_base$2: vue6.DefineComponent<Props$1, {}, {}, {}, {}, vue6.ComponentOptionsMixin, vue6.ComponentOptionsMixin, {}, string, vue6.PublicProps, Readonly<Props$1> & Readonly<{}>, {
|
|
227
245
|
idKey: string;
|
|
228
|
-
}, {}, {}, {}, string,
|
|
246
|
+
}, {}, {}, {}, string, vue6.ComponentProvideOptions, false, {}, any>;
|
|
229
247
|
declare const __VLS_export$3: __VLS_WithSlots$2<typeof __VLS_base$2, __VLS_Slots$2>;
|
|
230
248
|
declare const _default$2: typeof __VLS_export$3;
|
|
231
249
|
type __VLS_WithSlots$2<T, S> = T & {
|
|
@@ -240,13 +258,13 @@ declare var __VLS_1$1: {};
|
|
|
240
258
|
type __VLS_Slots$1 = {} & {
|
|
241
259
|
default?: (props: typeof __VLS_1$1) => any;
|
|
242
260
|
};
|
|
243
|
-
declare const __VLS_base$1:
|
|
261
|
+
declare const __VLS_base$1: vue6.DefineComponent<__VLS_Props, {}, {}, {}, {}, vue6.ComponentOptionsMixin, vue6.ComponentOptionsMixin, {} & {
|
|
244
262
|
[x: string]: any;
|
|
245
|
-
}, string,
|
|
263
|
+
}, string, vue6.PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
246
264
|
[x: `on${Capitalize<any>}`]: ((...args: any) => any) | undefined;
|
|
247
265
|
}>, {
|
|
248
266
|
coordinates: MapMarkerCoordinates;
|
|
249
|
-
}, {}, {}, {}, string,
|
|
267
|
+
}, {}, {}, {}, string, vue6.ComponentProvideOptions, false, {}, any>;
|
|
250
268
|
declare const __VLS_export$2: __VLS_WithSlots$1<typeof __VLS_base$1, __VLS_Slots$1>;
|
|
251
269
|
declare const _default$3: typeof __VLS_export$2;
|
|
252
270
|
type __VLS_WithSlots$1<T, S> = T & {
|
|
@@ -259,15 +277,15 @@ type __VLS_WithSlots$1<T, S> = T & {
|
|
|
259
277
|
interface Props {
|
|
260
278
|
fill?: string;
|
|
261
279
|
stroke?: string;
|
|
262
|
-
styles?: MapObjectStyles
|
|
280
|
+
styles?: MapObjectStyles;
|
|
263
281
|
}
|
|
264
|
-
declare const __VLS_export$1:
|
|
282
|
+
declare const __VLS_export$1: vue6.DefineComponent<Props, {}, {}, {}, {}, vue6.ComponentOptionsMixin, vue6.ComponentOptionsMixin, {} & {
|
|
265
283
|
[x: string]: any;
|
|
266
|
-
}, string,
|
|
284
|
+
}, string, vue6.PublicProps, Readonly<Props> & Readonly<{
|
|
267
285
|
[x: `on${Capitalize<any>}`]: ((...args: any) => any) | undefined;
|
|
268
286
|
}>, {
|
|
269
287
|
fill: string;
|
|
270
|
-
}, {}, {}, {}, string,
|
|
288
|
+
}, {}, {}, {}, string, vue6.ComponentProvideOptions, false, {}, any>;
|
|
271
289
|
declare const _default$4: typeof __VLS_export$1;
|
|
272
290
|
//#endregion
|
|
273
291
|
//#region src/components/MapZoom.vue.d.ts
|
|
@@ -275,14 +293,14 @@ declare var __VLS_1: {};
|
|
|
275
293
|
type __VLS_Slots = {} & {
|
|
276
294
|
default?: (props: typeof __VLS_1) => any;
|
|
277
295
|
};
|
|
278
|
-
declare const __VLS_base:
|
|
279
|
-
container:
|
|
280
|
-
zoomBehavior:
|
|
281
|
-
}, {}, {}, {},
|
|
296
|
+
declare const __VLS_base: vue6.DefineComponent<ZoomProps, {
|
|
297
|
+
container: vue6.Ref<SVGGElement | null, SVGGElement | null>;
|
|
298
|
+
zoomBehavior: vue6.ComputedRef<DefaultZoomBehavior>;
|
|
299
|
+
}, {}, {}, {}, vue6.ComponentOptionsMixin, vue6.ComponentOptionsMixin, {} & {
|
|
282
300
|
zoom: (payload: ZoomEvent) => any;
|
|
283
301
|
zoomstart: (payload: ZoomEvent) => any;
|
|
284
302
|
zoomend: (payload: ZoomEvent) => any;
|
|
285
|
-
}, string,
|
|
303
|
+
}, string, vue6.PublicProps, Readonly<ZoomProps> & Readonly<{
|
|
286
304
|
onZoom?: ((payload: ZoomEvent) => any) | undefined;
|
|
287
305
|
onZoomstart?: ((payload: ZoomEvent) => any) | undefined;
|
|
288
306
|
onZoomend?: ((payload: ZoomEvent) => any) | undefined;
|
|
@@ -291,7 +309,7 @@ declare const __VLS_base: vue4.DefineComponent<ZoomProps, {
|
|
|
291
309
|
zoom: number;
|
|
292
310
|
minZoom: number;
|
|
293
311
|
maxZoom: number;
|
|
294
|
-
}, {}, {}, {}, string,
|
|
312
|
+
}, {}, {}, {}, string, vue6.ComponentProvideOptions, false, {}, any>;
|
|
295
313
|
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
296
314
|
declare const _default$5: typeof __VLS_export;
|
|
297
315
|
type __VLS_WithSlots<T, S> = T & {
|
|
@@ -300,6 +318,10 @@ type __VLS_WithSlots<T, S> = T & {
|
|
|
300
318
|
};
|
|
301
319
|
};
|
|
302
320
|
//#endregion
|
|
321
|
+
//#region src/hooks/useMapContext.d.ts
|
|
322
|
+
declare const mapContextKey: InjectionKey<ComputedRef<MapContext>>;
|
|
323
|
+
declare function useMapContext(): ComputedRef<MapContext> | undefined;
|
|
324
|
+
//#endregion
|
|
303
325
|
//#region src/plugin.d.ts
|
|
304
326
|
/**
|
|
305
327
|
* Vue plugin that registers all d3-maps components globally.
|
|
@@ -308,4 +330,4 @@ declare const plugin: {
|
|
|
308
330
|
install(app: App): void;
|
|
309
331
|
};
|
|
310
332
|
//#endregion
|
|
311
|
-
export { _default as Map, _default$1 as MapFeature, _default$2 as MapFeatures, _default$3 as MapMarker, _default$4 as MapMesh, _default$5 as MapZoom, plugin };
|
|
333
|
+
export { _default as Map, _default$1 as MapFeature, _default$2 as MapFeatures, _default$3 as MapMarker, _default$4 as MapMesh, MapObjectEmit, MapObjectStyles, _default$5 as MapZoom, UseMapObjectResult, mapContextKey, plugin, useMapContext, useMapObject };
|
package/dist/index.iife.js
CHANGED
|
@@ -1 +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`)
|
|
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`);function s(){return(0,n.inject)(o)}let c=[`viewBox`];var l=(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(0,n.provide)(o,i),(e,t)=>((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,c))}});function u(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 d=[`d`,`fill`,`stroke`];var f=(0,n.defineComponent)({__name:`MapFeature`,props:{data:{},styles:{},fill:{},stroke:{}},setup(e,{emit:t}){let r=e,i=t,a=s(),o=(0,n.computed)(()=>a?.value.renderPath(r.data)),{computedStyle:c,onMouseEnter:l,onMouseLeave:f,onMouseDown:p,onMouseUp:m,onFocus:h,onBlur:g}=u(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)(c),fill:e.fill,stroke:e.stroke},t.$attrs,{onMouseenter:r[0]||=(...e)=>(0,n.unref)(l)&&(0,n.unref)(l)(...e),onMouseleave:r[1]||=(...e)=>(0,n.unref)(f)&&(0,n.unref)(f)(...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)}),null,16,d)):(0,n.createCommentVNode)(`v-if`,!0)}}),p=(0,n.defineComponent)({__name:`MapFeatures`,props:{idKey:{default:`id`},fill:{},stroke:{},styles:{}},setup(e){let t=s(),i=(0,n.computed)(()=>t?.value.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)(f,(0,n.mergeProps)({key:(0,n.unref)(r.getFeatureKey)(i,e.idKey,a),data:i,fill:e.fill,stroke:e.stroke,styles:e.styles},{ref_for:!0},t.$attrs),null,16,[`data`,`fill`,`stroke`,`styles`]))),128))])]))}});let m=[`transform`];var h=(0,n.defineComponent)({__name:`MapMarker`,props:{coordinates:{default:()=>[0,0]},styles:{}},setup(e,{emit:t}){let i=e,a=t,o=s(),c=(0,n.computed)(()=>(0,r.getMarkerTransform)(o?.value,i.coordinates)),{computedStyle:l,onMouseEnter:d,onMouseLeave:f,onMouseDown:p,onMouseUp:h,onFocus:g,onBlur:_}=u(a,(0,n.toRef)(i,`styles`));return(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`g`,{transform:c.value,style:(0,n.normalizeStyle)((0,n.unref)(l)),onMouseenter:t[0]||=(...e)=>(0,n.unref)(d)&&(0,n.unref)(d)(...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)(h)&&(0,n.unref)(h)(...e),onClick:t[4]||=(...e)=>(0,n.unref)(h)&&(0,n.unref)(h)(...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,m))}});let g=[`d`,`fill`,`stroke`];var _=(0,n.defineComponent)({__name:`MapMesh`,props:{fill:{default:`none`},stroke:{},styles:{}},setup(e,{emit:t}){let r=e,i=t,a=s(),o=(0,n.computed)(()=>a?.value.renderMesh()),{computedStyle:c,onMouseEnter:l,onMouseLeave:d,onMouseDown:f,onMouseUp:p,onFocus:m,onBlur:h}=u(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)(c),fill:e.fill,stroke:e.stroke},t.$attrs,{onMouseenter:r[0]||=(...e)=>(0,n.unref)(l)&&(0,n.unref)(l)(...e),onMouseleave:r[1]||=(...e)=>(0,n.unref)(d)&&(0,n.unref)(d)(...e),onMousedown:r[2]||=(...e)=>(0,n.unref)(f)&&(0,n.unref)(f)(...e),onMouseup:r[3]||=(...e)=>(0,n.unref)(p)&&(0,n.unref)(p)(...e),onClick:r[4]||=(...e)=>(0,n.unref)(p)&&(0,n.unref)(p)(...e),onFocus:r[5]||=(...e)=>(0,n.unref)(m)&&(0,n.unref)(m)(...e),onBlur:r[6]||=(...e)=>(0,n.unref)(h)&&(0,n.unref)(h)(...e)}),null,16,g)):(0,n.createCommentVNode)(`v-if`,!0)}}),v=(0,n.defineComponent)({__name:`MapZoom`,props:{center:{default:()=>[0,0]},zoom:{default:1},minZoom:{default:1},maxZoom:{default:8},config:{}},emits:[`zoomstart`,`zoom`,`zoomend`],setup(e,{expose:t,emit:i}){let a=e,o=i,c=(0,n.ref)(null),l=s(),u=(0,n.computed)(()=>(0,r.createZoomBehavior)(l?.value,{minZoom:a.minZoom,maxZoom:a.maxZoom,config:a.config,onZoomStart:e=>o(`zoomstart`,e),onZoom:e=>{(0,r.applyZoomGroupTransform)(c.value,e.transform),o(`zoom`,e)},onZoomEnd:e=>o(`zoomend`,e)}));return(0,n.onMounted)(()=>{(0,n.watch)(u,e=>{c.value&&(0,r.setupZoom)({element:c.value,behavior:e,center:a.center,zoom:a.zoom})},{immediate:!0}),(0,n.watch)(()=>[u.value,a.center[0],a.center[1],a.zoom],()=>{c.value&&(0,r.applyZoomTransform)({element:c.value,behavior:u.value,center:a.center,zoom:a.zoom})})}),t({container:c,zoomBehavior:u}),(e,t)=>((0,n.openBlock)(),(0,n.createElementBlock)(`g`,{ref_key:`container`,ref:c,class:`d3-map-zoom`},[(0,n.renderSlot)(e.$slots,`default`)],512))}}),y=a({Map:()=>l,MapFeature:()=>f,MapFeatures:()=>p,MapMarker:()=>h,MapMesh:()=>_,MapZoom:()=>v});e.Map=l,e.MapFeature=f,e.MapFeatures=p,e.MapMarker=h,e.MapMesh=_,e.MapZoom=v,e.mapContextKey=o,e.plugin={install(e){Object.entries(y).forEach(([t,n])=>{e.component(t,n)})}},e.useMapContext=s,e.useMapObject=u})(this.D3Maps=this.D3Maps||{},_d3_maps_core_index_css,Vue,D3Maps);
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
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
|
|
3
|
-
import { applyZoomTransform, createZoomBehavior, getFeatureKey, getMarkerTransform, getObjectStateUpdate, makeMapContext, resolveObjectStyle, setupZoom } from "@d3-maps/core";
|
|
2
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, defineComponent, guardReactiveProps, inject, mergeProps, normalizeProps, normalizeStyle, onMounted, openBlock, provide, ref, renderList, renderSlot, toRef, unref, watch } from "vue";
|
|
3
|
+
import { applyZoomGroupTransform, applyZoomTransform, createZoomBehavior, getFeatureKey, getMarkerTransform, getObjectStateUpdate, makeMapContext, resolveObjectStyle, setupZoom } from "@d3-maps/core";
|
|
4
4
|
|
|
5
5
|
//#region rolldown:runtime
|
|
6
6
|
var __defProp = Object.defineProperty;
|
|
@@ -19,25 +19,8 @@ var __exportAll = (all, symbols) => {
|
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
//#endregion
|
|
22
|
-
//#region src/
|
|
22
|
+
//#region src/hooks/useMapContext.ts
|
|
23
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
24
|
function useMapContext() {
|
|
42
25
|
return inject(mapContextKey);
|
|
43
26
|
}
|
|
@@ -67,11 +50,9 @@ var Map_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComp
|
|
|
67
50
|
data: props.data,
|
|
68
51
|
dataTransformer: props.dataTransformer
|
|
69
52
|
}));
|
|
53
|
+
provide(mapContextKey, context);
|
|
70
54
|
return (_ctx, _cache) => {
|
|
71
|
-
return openBlock(),
|
|
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$3))]),
|
|
73
|
-
_: 3
|
|
74
|
-
}, 8, ["context"]);
|
|
55
|
+
return 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$3);
|
|
75
56
|
};
|
|
76
57
|
}
|
|
77
58
|
});
|
|
@@ -81,7 +62,7 @@ var Map_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComp
|
|
|
81
62
|
var Map_default = Map_vue_vue_type_script_setup_true_lang_default;
|
|
82
63
|
|
|
83
64
|
//#endregion
|
|
84
|
-
//#region src/
|
|
65
|
+
//#region src/hooks/useMapObject.ts
|
|
85
66
|
function useMapObject(emit, styles) {
|
|
86
67
|
const state = ref("default");
|
|
87
68
|
const eventCallbackFactory = (eventName) => (event) => {
|
|
@@ -118,7 +99,7 @@ var MapFeature_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
118
99
|
const props = __props;
|
|
119
100
|
const emit = __emit;
|
|
120
101
|
const context = useMapContext();
|
|
121
|
-
const path = computed(() => context?.renderPath(props.data));
|
|
102
|
+
const path = computed(() => context?.value.renderPath(props.data));
|
|
122
103
|
const { computedStyle, onMouseEnter, onMouseLeave, onMouseDown, onMouseUp, onFocus, onBlur } = useMapObject(emit, toRef(props, "styles"));
|
|
123
104
|
return (_ctx, _cache) => {
|
|
124
105
|
return path.value ? (openBlock(), createElementBlock("path", mergeProps({
|
|
@@ -156,7 +137,7 @@ var MapFeatures_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ de
|
|
|
156
137
|
},
|
|
157
138
|
setup(__props) {
|
|
158
139
|
const context = useMapContext();
|
|
159
|
-
const features = computed(() => context?.features ?? []);
|
|
140
|
+
const features = computed(() => context?.value.features ?? []);
|
|
160
141
|
return (_ctx, _cache) => {
|
|
161
142
|
return openBlock(), createElementBlock("g", null, [renderSlot(_ctx.$slots, "default", { features: features.value }, () => [(openBlock(true), createElementBlock(Fragment, null, renderList(features.value, (feature, index) => {
|
|
162
143
|
return openBlock(), createBlock(MapFeature_default, mergeProps({
|
|
@@ -194,7 +175,7 @@ var MapMarker_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defi
|
|
|
194
175
|
const emit = __emit;
|
|
195
176
|
const context = useMapContext();
|
|
196
177
|
const transform = computed(() => {
|
|
197
|
-
return getMarkerTransform(context, props.coordinates);
|
|
178
|
+
return getMarkerTransform(context?.value, props.coordinates);
|
|
198
179
|
});
|
|
199
180
|
const { computedStyle, onMouseEnter, onMouseLeave, onMouseDown, onMouseUp, onFocus, onBlur } = useMapObject(emit, toRef(props, "styles"));
|
|
200
181
|
return (_ctx, _cache) => {
|
|
@@ -235,7 +216,7 @@ var MapMesh_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ define
|
|
|
235
216
|
const props = __props;
|
|
236
217
|
const emit = __emit;
|
|
237
218
|
const context = useMapContext();
|
|
238
|
-
const path = computed(() => context?.renderMesh());
|
|
219
|
+
const path = computed(() => context?.value.renderMesh());
|
|
239
220
|
const { computedStyle, onMouseEnter, onMouseLeave, onMouseDown, onMouseUp, onFocus, onBlur } = useMapObject(emit, toRef(props, "styles"));
|
|
240
221
|
return (_ctx, _cache) => {
|
|
241
222
|
return path.value ? (openBlock(), createElementBlock("path", mergeProps({
|
|
@@ -283,35 +264,42 @@ var MapZoom_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ define
|
|
|
283
264
|
const container = ref(null);
|
|
284
265
|
const context = useMapContext();
|
|
285
266
|
const zoomBehavior = computed(() => {
|
|
286
|
-
return createZoomBehavior(context, {
|
|
267
|
+
return createZoomBehavior(context?.value, {
|
|
287
268
|
minZoom: props.minZoom,
|
|
288
269
|
maxZoom: props.maxZoom,
|
|
289
270
|
config: props.config,
|
|
290
271
|
onZoomStart: (event) => emit("zoomstart", event),
|
|
291
272
|
onZoom: (event) => {
|
|
292
|
-
|
|
273
|
+
applyZoomGroupTransform(container.value, event.transform);
|
|
293
274
|
emit("zoom", event);
|
|
294
275
|
},
|
|
295
276
|
onZoomEnd: (event) => emit("zoomend", event)
|
|
296
277
|
});
|
|
297
278
|
});
|
|
298
279
|
onMounted(() => {
|
|
299
|
-
watch(
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
280
|
+
watch(zoomBehavior, (behavior) => {
|
|
281
|
+
if (!container.value) return;
|
|
282
|
+
setupZoom({
|
|
283
|
+
element: container.value,
|
|
284
|
+
behavior,
|
|
285
|
+
center: props.center,
|
|
286
|
+
zoom: props.zoom
|
|
287
|
+
});
|
|
288
|
+
}, { immediate: true });
|
|
305
289
|
watch(() => [
|
|
290
|
+
zoomBehavior.value,
|
|
306
291
|
props.center[0],
|
|
307
292
|
props.center[1],
|
|
308
293
|
props.zoom
|
|
309
|
-
], () =>
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
294
|
+
], () => {
|
|
295
|
+
if (!container.value) return;
|
|
296
|
+
applyZoomTransform({
|
|
297
|
+
element: container.value,
|
|
298
|
+
behavior: zoomBehavior.value,
|
|
299
|
+
center: props.center,
|
|
300
|
+
zoom: props.zoom
|
|
301
|
+
});
|
|
302
|
+
});
|
|
315
303
|
});
|
|
316
304
|
__expose({
|
|
317
305
|
container,
|
|
@@ -354,4 +342,4 @@ const plugin = { install(app) {
|
|
|
354
342
|
} };
|
|
355
343
|
|
|
356
344
|
//#endregion
|
|
357
|
-
export { Map_default as Map, MapFeature_default as MapFeature, MapFeatures_default as MapFeatures, MapMarker_default as MapMarker, MapMesh_default as MapMesh, MapZoom_default as MapZoom, plugin };
|
|
345
|
+
export { Map_default as Map, MapFeature_default as MapFeature, MapFeatures_default as MapFeatures, MapMarker_default as MapMarker, MapMesh_default as MapMesh, MapZoom_default as MapZoom, mapContextKey, plugin, useMapContext, useMapObject };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@d3-maps/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.0",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Vue bindings for @d3-maps/core to build reactive D3 SVG maps",
|
|
7
7
|
"author": "Georgii Bukharov <souljorje@gmail.com>",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"vue": "3.5.25"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@d3-maps/core": "0.
|
|
47
|
+
"@d3-maps/core": "0.4.0"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@types/geojson": "^7946.0.16",
|