@molecule/app-map-drawing-vue 0.0.0-stage → 0.0.1-stage
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/LICENSE +202 -0
- package/README.md +550 -2
- package/dist/MapDrawing.d.ts +163 -0
- package/dist/MapDrawing.d.ts.map +1 -0
- package/dist/MapDrawing.js +533 -0
- package/dist/MapDrawing.js.map +1 -0
- package/dist/MapDrawingToolbar.d.ts +111 -0
- package/dist/MapDrawingToolbar.d.ts.map +1 -0
- package/dist/MapDrawingToolbar.js +110 -0
- package/dist/MapDrawingToolbar.js.map +1 -0
- package/dist/geometry.d.ts +50 -0
- package/dist/geometry.d.ts.map +1 -0
- package/dist/geometry.js +94 -0
- package/dist/geometry.js.map +1 -0
- package/dist/index.d.ts +67 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +67 -0
- package/dist/index.js.map +1 -0
- package/dist/types.d.ts +140 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +16 -0
- package/dist/types.js.map +1 -0
- package/package.json +67 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapDrawingToolbar.d.ts","sourceRoot":"","sources":["../src/MapDrawingToolbar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAsB,KAAK,QAAQ,EAAE,KAAK,KAAK,EAAE,MAAM,KAAK,CAAA;AAKnE,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAEzD,yCAAyC;AACzC,MAAM,WAAW,sBAAsB;IACrC,sDAAsD;IACtD,KAAK,EAAE,WAAW,EAAE,CAAA;IACpB,6BAA6B;IAC7B,UAAU,EAAE,UAAU,CAAA;IACtB,iDAAiD;IACjD,kBAAkB,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,IAAI,CAAA;IAC9C,8DAA8D;IAC9D,gBAAgB,EAAE,MAAM,IAAI,CAAA;IAC5B,mFAAmF;IACnF,YAAY,EAAE,OAAO,CAAA;IACrB,8GAA8G;IAC9G,QAAQ,EAAE,OAAO,CAAA;IACjB,2DAA2D;IAC3D,aAAa,EAAE,MAAM,IAAI,CAAA;CAC1B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB;IAG1B,sDAAsD;;cAC9B,QAAQ,CAAC,WAAW,EAAE,CAAC;;;IAC/C,6BAA6B;;cACC,QAAQ,CAAC,UAAU,CAAC;;;IAClD,iDAAiD;;cAE7B,QAAQ,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;;;IAG1E,8DAA8D;;cAE1C,QAAQ,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;;;IAGxE,8CAA8C;;;;;IAE9C,sCAAsC;;;;;IAEtC,2DAA2D;;cAEvC,QAAQ,CAAC,sBAAsB,CAAC,eAAe,CAAC,CAAC;;;UAQ1D,KAAK;IA5BhB,sDAAsD;;cAC9B,QAAQ,CAAC,WAAW,EAAE,CAAC;;;IAC/C,6BAA6B;;cACC,QAAQ,CAAC,UAAU,CAAC;;;IAClD,iDAAiD;;cAE7B,QAAQ,CAAC,sBAAsB,CAAC,oBAAoB,CAAC,CAAC;;;IAG1E,8DAA8D;;cAE1C,QAAQ,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAC;;;IAGxE,8CAA8C;;;;;IAE9C,sCAAsC;;;;;IAEtC,2DAA2D;;cAEvC,QAAQ,CAAC,sBAAsB,CAAC,eAAe,CAAC,CAAC;;;iGAuFvE,CAAA"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue map-drawing toolbar: one button per drawing tool plus the select,
|
|
3
|
+
* cancel-draft and delete actions.
|
|
4
|
+
*
|
|
5
|
+
* Vue counterpart of `@molecule/app-map-drawing-react`'s
|
|
6
|
+
* `MapDrawingToolbar` — the same props (React names), the same ClassMap
|
|
7
|
+
* classes, and the same DOM for the same input.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
import { defineComponent, h } from 'vue';
|
|
12
|
+
import { getClassMap } from '@molecule/app-ui';
|
|
13
|
+
import { useTranslation } from '@molecule/app-vue';
|
|
14
|
+
/**
|
|
15
|
+
* Toolbar with one button per drawing tool plus `select` and `delete`.
|
|
16
|
+
* All button labels route through `t()` so the toolbar translates via the
|
|
17
|
+
* companion `@molecule/app-locales-feature-map-drawing` bond.
|
|
18
|
+
*
|
|
19
|
+
* @param props - Toolbar props (see {@link MapDrawingToolbarProps}).
|
|
20
|
+
* @returns The toolbar component.
|
|
21
|
+
*/
|
|
22
|
+
export const MapDrawingToolbar = defineComponent({
|
|
23
|
+
name: 'MapDrawingToolbar',
|
|
24
|
+
props: {
|
|
25
|
+
/** Drawing tools to expose (in declaration order). */
|
|
26
|
+
tools: { type: Array, required: true },
|
|
27
|
+
/** Currently active tool. */
|
|
28
|
+
activeTool: { type: String, required: true },
|
|
29
|
+
/** Called when the user clicks a tool button. */
|
|
30
|
+
onActiveToolChange: {
|
|
31
|
+
type: Function,
|
|
32
|
+
required: true,
|
|
33
|
+
},
|
|
34
|
+
/** Called when the user clicks the delete-selected button. */
|
|
35
|
+
onDeleteSelected: {
|
|
36
|
+
type: Function,
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
/** Whether anything is currently selected. */
|
|
40
|
+
hasSelection: { type: Boolean, required: true },
|
|
41
|
+
/** Whether a draft is in progress. */
|
|
42
|
+
hasDraft: { type: Boolean, required: true },
|
|
43
|
+
/** Called when the user clicks the cancel-draft button. */
|
|
44
|
+
onCancelDraft: {
|
|
45
|
+
type: Function,
|
|
46
|
+
required: true,
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
setup(props) {
|
|
50
|
+
const cm = getClassMap();
|
|
51
|
+
const { t } = useTranslation();
|
|
52
|
+
return () => {
|
|
53
|
+
const labels = {
|
|
54
|
+
polygon: t('mapDrawing.tool.polygon', {}, { defaultValue: 'Polygon' }),
|
|
55
|
+
circle: t('mapDrawing.tool.circle', {}, { defaultValue: 'Circle' }),
|
|
56
|
+
pin: t('mapDrawing.tool.pin', {}, { defaultValue: 'Pin' }),
|
|
57
|
+
line: t('mapDrawing.tool.line', {}, { defaultValue: 'Line' }),
|
|
58
|
+
select: t('mapDrawing.tool.select', {}, { defaultValue: 'Select' }),
|
|
59
|
+
cancelDraft: t('mapDrawing.tool.cancelDraft', {}, { defaultValue: 'Cancel draft' }),
|
|
60
|
+
delete: t('mapDrawing.tool.delete', {}, { defaultValue: 'Delete' }),
|
|
61
|
+
};
|
|
62
|
+
const ariaLabel = t('mapDrawing.toolbar.aria', {}, { defaultValue: 'Map drawing tools' });
|
|
63
|
+
const buttonClass = cm.cn(cm.button({ variant: 'ghost', size: 'sm' }));
|
|
64
|
+
return h('div', {
|
|
65
|
+
role: 'toolbar',
|
|
66
|
+
'aria-label': ariaLabel,
|
|
67
|
+
'data-mol-id': 'map-drawing-toolbar',
|
|
68
|
+
class: cm.cn(cm.flex({ align: 'center', gap: 'xs' }), cm.sp('p', 1)),
|
|
69
|
+
}, [
|
|
70
|
+
...props.tools.map((tool) => {
|
|
71
|
+
const active = props.activeTool === tool;
|
|
72
|
+
return h('button', {
|
|
73
|
+
key: tool,
|
|
74
|
+
type: 'button',
|
|
75
|
+
'aria-pressed': active,
|
|
76
|
+
'data-mol-id': `map-drawing-tool-${tool}`,
|
|
77
|
+
'data-active': active ? 'true' : 'false',
|
|
78
|
+
onClick: () => props.onActiveToolChange(tool),
|
|
79
|
+
class: buttonClass,
|
|
80
|
+
}, labels[tool]);
|
|
81
|
+
}),
|
|
82
|
+
h('button', {
|
|
83
|
+
type: 'button',
|
|
84
|
+
'aria-pressed': props.activeTool === 'select',
|
|
85
|
+
'data-mol-id': 'map-drawing-tool-select',
|
|
86
|
+
'data-active': props.activeTool === 'select' ? 'true' : 'false',
|
|
87
|
+
onClick: () => props.onActiveToolChange('select'),
|
|
88
|
+
class: buttonClass,
|
|
89
|
+
}, labels.select),
|
|
90
|
+
h('button', {
|
|
91
|
+
type: 'button',
|
|
92
|
+
'data-mol-id': 'map-drawing-tool-cancel-draft',
|
|
93
|
+
disabled: !props.hasDraft,
|
|
94
|
+
'aria-disabled': !props.hasDraft,
|
|
95
|
+
onClick: props.onCancelDraft,
|
|
96
|
+
class: buttonClass,
|
|
97
|
+
}, labels.cancelDraft),
|
|
98
|
+
h('button', {
|
|
99
|
+
type: 'button',
|
|
100
|
+
'data-mol-id': 'map-drawing-tool-delete',
|
|
101
|
+
disabled: !props.hasSelection,
|
|
102
|
+
'aria-disabled': !props.hasSelection,
|
|
103
|
+
onClick: props.onDeleteSelected,
|
|
104
|
+
class: buttonClass,
|
|
105
|
+
}, labels.delete),
|
|
106
|
+
]);
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
//# sourceMappingURL=MapDrawingToolbar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapDrawingToolbar.js","sourceRoot":"","sources":["../src/MapDrawingToolbar.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,eAAe,EAAE,CAAC,EAA6B,MAAM,KAAK,CAAA;AAEnE,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAA;AAsBlD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,eAAe,CAAC;IAC/C,IAAI,EAAE,mBAAmB;IACzB,KAAK,EAAE;QACL,sDAAsD;QACtD,KAAK,EAAE,EAAE,IAAI,EAAE,KAAgC,EAAE,QAAQ,EAAE,IAAI,EAAE;QACjE,6BAA6B;QAC7B,UAAU,EAAE,EAAE,IAAI,EAAE,MAA8B,EAAE,QAAQ,EAAE,IAAI,EAAE;QACpE,iDAAiD;QACjD,kBAAkB,EAAE;YAClB,IAAI,EAAE,QAAkE;YACxE,QAAQ,EAAE,IA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AAU,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO;oBAC/D,OAAO,EAAE,GAAG,EAAE,CAAC,KAAK,CAAC,kBAAkB,CAAC,QAAQ,CAAC;oBACjD,KAAK,EAAE,WAAW;iBACnB,EACD,MAAM,CAAC,MAAM,CACd;gBACD,CAAC,CACC,QAAQ,EACR;oBACE,IAAI,EAAE,QAAQ;oBACd,aAAa,EAAE,+BAA+B;oBAC9C,QAAQ,EAAE,CAAC,KAAK,CAAC,QAAQ;oBACzB,eAAe,EAAE,CAAC,KAAK,CAAC,QAAQ;oBAChC,OAAO,EAAE,KAAK,CAAC,aAAa;oBAC5B,KAAK,EAAE,WAAW;iBACnB,EACD,MAAM,CAAC,WAAW,CACnB;gBACD,CAAC,CACC,QAAQ,EACR;oBACE,IAAI,EAAE,QAAQ;oBACd,aAAa,EAAE,yBAAyB;oBACxC,QAAQ,EAAE,CAAC,KAAK,CAAC,YAAY;oBAC7B,eAAe,EAAE,CAAC,KAAK,CAAC,YAAY;oBACpC,OAAO,EAAE,KAAK,CAAC,gBAAgB;oBAC/B,KAAK,EAAE,WAAW;iBACnB,EACD,MAAM,CAAC,MAAM,CACd;aACF,CACF,CAAA;QACH,CAAC,CAAA;IACH,CAAC;CACF,CAAC,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { MapDrawingBackend, ScreenPoint } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Convert degrees to radians.
|
|
4
|
+
*
|
|
5
|
+
* @param degrees - Angle in degrees.
|
|
6
|
+
* @returns Angle in radians.
|
|
7
|
+
*/
|
|
8
|
+
export declare function toRadians(degrees: number): number;
|
|
9
|
+
/**
|
|
10
|
+
* Great-circle distance between two `[lng, lat]` positions in meters
|
|
11
|
+
* using the Haversine formula (uses the WGS84 equatorial radius,
|
|
12
|
+
* 6378137 m), so the
|
|
13
|
+
* radius computed during drag agrees with what a geographic backend
|
|
14
|
+
* will project back to the user.
|
|
15
|
+
*
|
|
16
|
+
* @param a - First position.
|
|
17
|
+
* @param b - Second position.
|
|
18
|
+
* @returns Distance in meters.
|
|
19
|
+
*/
|
|
20
|
+
export declare function haversineDistanceMeters(a: [number, number], b: [number, number]): number;
|
|
21
|
+
/**
|
|
22
|
+
* Identity drawing backend — used when no real map is mounted (tests,
|
|
23
|
+
* SSR, demo storyboards). Projection is `lng → x`, `lat → y` so
|
|
24
|
+
* fixtures can be authored in pixel space and round-trip cleanly. The
|
|
25
|
+
* distance metric is Euclidean pixels rather than meters; callers that
|
|
26
|
+
* care about a real radius should always pass a real backend.
|
|
27
|
+
*/
|
|
28
|
+
export declare const identityBackend: MapDrawingBackend;
|
|
29
|
+
/**
|
|
30
|
+
* Snap an open ring (the in-progress polygon vertex list) into a
|
|
31
|
+
* GeoJSON-compliant closed ring by repeating the first point at the
|
|
32
|
+
* end. Returns `null` when the ring has fewer than three vertices,
|
|
33
|
+
* since polygons require a minimum of three distinct points plus the
|
|
34
|
+
* closing repeat.
|
|
35
|
+
*
|
|
36
|
+
* @param vertices - Open ring of `[lng, lat]` pairs.
|
|
37
|
+
* @returns Closed ring, or `null` when there are not enough points.
|
|
38
|
+
*/
|
|
39
|
+
export declare function closeRing(vertices: [number, number][]): [number, number][] | null;
|
|
40
|
+
/**
|
|
41
|
+
* Check whether a screen-space point lies inside the given selection
|
|
42
|
+
* rectangle (axis-aligned, inclusive bounds).
|
|
43
|
+
*
|
|
44
|
+
* @param point - Point under test.
|
|
45
|
+
* @param a - One corner of the selection rectangle.
|
|
46
|
+
* @param b - Opposite corner of the selection rectangle.
|
|
47
|
+
* @returns `true` when the point lies inside the rectangle.
|
|
48
|
+
*/
|
|
49
|
+
export declare function pointInRect(point: ScreenPoint, a: ScreenPoint, b: ScreenPoint): boolean;
|
|
50
|
+
//# sourceMappingURL=geometry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.d.ts","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAOhE;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAYxF;AAED;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,iBAY7B,CAAA;AAED;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,IAAI,CAQjF;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAMvF"}
|
package/dist/geometry.js
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Earth radius in meters — used by the great-circle distance fallback.
|
|
3
|
+
*/
|
|
4
|
+
const EARTH_RADIUS_METERS = 6378137;
|
|
5
|
+
/**
|
|
6
|
+
* Convert degrees to radians.
|
|
7
|
+
*
|
|
8
|
+
* @param degrees - Angle in degrees.
|
|
9
|
+
* @returns Angle in radians.
|
|
10
|
+
*/
|
|
11
|
+
export function toRadians(degrees) {
|
|
12
|
+
return (degrees * Math.PI) / 180;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Great-circle distance between two `[lng, lat]` positions in meters
|
|
16
|
+
* using the Haversine formula (uses the WGS84 equatorial radius,
|
|
17
|
+
* 6378137 m), so the
|
|
18
|
+
* radius computed during drag agrees with what a geographic backend
|
|
19
|
+
* will project back to the user.
|
|
20
|
+
*
|
|
21
|
+
* @param a - First position.
|
|
22
|
+
* @param b - Second position.
|
|
23
|
+
* @returns Distance in meters.
|
|
24
|
+
*/
|
|
25
|
+
export function haversineDistanceMeters(a, b) {
|
|
26
|
+
const [lng1, lat1] = a;
|
|
27
|
+
const [lng2, lat2] = b;
|
|
28
|
+
const phi1 = toRadians(lat1);
|
|
29
|
+
const phi2 = toRadians(lat2);
|
|
30
|
+
const deltaPhi = toRadians(lat2 - lat1);
|
|
31
|
+
const deltaLambda = toRadians(lng2 - lng1);
|
|
32
|
+
const sinPhi = Math.sin(deltaPhi / 2);
|
|
33
|
+
const sinLambda = Math.sin(deltaLambda / 2);
|
|
34
|
+
const aTerm = sinPhi * sinPhi + Math.cos(phi1) * Math.cos(phi2) * sinLambda * sinLambda;
|
|
35
|
+
const cTerm = 2 * Math.atan2(Math.sqrt(aTerm), Math.sqrt(1 - aTerm));
|
|
36
|
+
return EARTH_RADIUS_METERS * cTerm;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Identity drawing backend — used when no real map is mounted (tests,
|
|
40
|
+
* SSR, demo storyboards). Projection is `lng → x`, `lat → y` so
|
|
41
|
+
* fixtures can be authored in pixel space and round-trip cleanly. The
|
|
42
|
+
* distance metric is Euclidean pixels rather than meters; callers that
|
|
43
|
+
* care about a real radius should always pass a real backend.
|
|
44
|
+
*/
|
|
45
|
+
export const identityBackend = {
|
|
46
|
+
project(coordinates) {
|
|
47
|
+
return { x: coordinates[0], y: coordinates[1] };
|
|
48
|
+
},
|
|
49
|
+
unproject(point) {
|
|
50
|
+
return [point.x, point.y];
|
|
51
|
+
},
|
|
52
|
+
distanceMeters(a, b) {
|
|
53
|
+
const dx = a[0] - b[0];
|
|
54
|
+
const dy = a[1] - b[1];
|
|
55
|
+
return Math.sqrt(dx * dx + dy * dy);
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Snap an open ring (the in-progress polygon vertex list) into a
|
|
60
|
+
* GeoJSON-compliant closed ring by repeating the first point at the
|
|
61
|
+
* end. Returns `null` when the ring has fewer than three vertices,
|
|
62
|
+
* since polygons require a minimum of three distinct points plus the
|
|
63
|
+
* closing repeat.
|
|
64
|
+
*
|
|
65
|
+
* @param vertices - Open ring of `[lng, lat]` pairs.
|
|
66
|
+
* @returns Closed ring, or `null` when there are not enough points.
|
|
67
|
+
*/
|
|
68
|
+
export function closeRing(vertices) {
|
|
69
|
+
if (vertices.length < 3)
|
|
70
|
+
return null;
|
|
71
|
+
const first = vertices[0];
|
|
72
|
+
const last = vertices[vertices.length - 1];
|
|
73
|
+
if (first[0] === last[0] && first[1] === last[1]) {
|
|
74
|
+
return vertices.slice();
|
|
75
|
+
}
|
|
76
|
+
return [...vertices, [first[0], first[1]]];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Check whether a screen-space point lies inside the given selection
|
|
80
|
+
* rectangle (axis-aligned, inclusive bounds).
|
|
81
|
+
*
|
|
82
|
+
* @param point - Point under test.
|
|
83
|
+
* @param a - One corner of the selection rectangle.
|
|
84
|
+
* @param b - Opposite corner of the selection rectangle.
|
|
85
|
+
* @returns `true` when the point lies inside the rectangle.
|
|
86
|
+
*/
|
|
87
|
+
export function pointInRect(point, a, b) {
|
|
88
|
+
const minX = Math.min(a.x, b.x);
|
|
89
|
+
const maxX = Math.max(a.x, b.x);
|
|
90
|
+
const minY = Math.min(a.y, b.y);
|
|
91
|
+
const maxY = Math.max(a.y, b.y);
|
|
92
|
+
return point.x >= minX && point.x <= maxX && point.y >= minY && point.y <= maxY;
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=geometry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"geometry.js","sourceRoot":"","sources":["../src/geometry.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,mBAAmB,GAAG,OAAO,CAAA;AAEnC;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,OAAe;IACvC,OAAO,C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AG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/B,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAC/B,OAAO,KAAK,CAAC,CAAC,IAAI,IAAI,IAAI,KAAK,CAAC,CAAC,IAAI,IAAI,IAAI,KAAK,CAAC,CAAC,IAAI,IAAI,IAAI,KAAK,CAAC,CAAC,IAAI,IAAI,CAAA;AACjF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue map drawing — toolbar + interaction surface for authoring geofences
|
|
3
|
+
* (polygons, circles, pins, lines) on top of any `@molecule/app-maps` backend.
|
|
4
|
+
*
|
|
5
|
+
* The Vue counterpart of `@molecule/app-map-drawing-react`: it exports the same
|
|
6
|
+
* names, takes the same props (React names) and renders the same DOM for the
|
|
7
|
+
* same input. Exports `<MapDrawing>`, `<MapDrawingToolbar>`, geometry helpers
|
|
8
|
+
* (`haversineDistanceMeters`, `closeRing`, `identityBackend`, `pointInRect`,
|
|
9
|
+
* `toRadians`), and the `MapShape` / `MapDrawingProps` / `MapDrawingBackend`
|
|
10
|
+
* types.
|
|
11
|
+
*
|
|
12
|
+
* Composes with `@molecule/app-maps` via two props: `mapSlot` (render the map
|
|
13
|
+
* element underneath the drawing overlay — as a prop or a same-named slot) and
|
|
14
|
+
* `mapBackend` (a 3-function projection adapter: `project`, `unproject`,
|
|
15
|
+
* `distanceMeters`). There is no prebuilt adapter — build one from your map
|
|
16
|
+
* instance as in the example.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* - When `mapBackend` is omitted, the IDENTITY backend is used: lng maps to x
|
|
20
|
+
* pixels and lat to y pixels, and "radiusMeters" is Euclidean pixels. That is
|
|
21
|
+
* intended for tests/storyboards only — always pass a real backend when shapes
|
|
22
|
+
* must be geographic.
|
|
23
|
+
* - polygon/line: click adds vertices, double-click finalises (polygons need 3+
|
|
24
|
+
* vertices); circle: drag from center, release commits; pin: one per click;
|
|
25
|
+
* select: marquee-drag, then the toolbar's delete button removes the
|
|
26
|
+
* selection; the cancel-draft button discards an in-progress draft.
|
|
27
|
+
* - Toolbar and surface labels route through `t()` under `mapDrawing.` — the
|
|
28
|
+
* registered companion bond is `@molecule/app-locales-feature-map-drawing`.
|
|
29
|
+
* - Note `@molecule/app-maps` currently ships only a placeholder provider (no
|
|
30
|
+
* real tiles); the drawing overlay works regardless, but the `mapSlot`
|
|
31
|
+
* background will be a placeholder until a real map provider is wired.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { createApp, defineComponent, h } from 'vue'
|
|
36
|
+
* import { haversineDistanceMeters, MapDrawing } from '@molecule/app-map-drawing-vue'
|
|
37
|
+
* import type { MapDrawingBackend } from '@molecule/app-map-drawing-vue'
|
|
38
|
+
*
|
|
39
|
+
* // Adapt any map instance into a drawing backend:
|
|
40
|
+
* const backend: MapDrawingBackend = {
|
|
41
|
+
* project: ([lng, lat]) => ({ x: lng, y: lat }),
|
|
42
|
+
* unproject: (point) => [point.x, point.y],
|
|
43
|
+
* distanceMeters: haversineDistanceMeters,
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* const Zones = defineComponent({
|
|
47
|
+
* setup() {
|
|
48
|
+
* return () =>
|
|
49
|
+
* h(MapDrawing, {
|
|
50
|
+
* tools: ['polygon', 'circle', 'pin'],
|
|
51
|
+
* height: 500,
|
|
52
|
+
* mapBackend: backend,
|
|
53
|
+
* onChange: (shapes) => console.log(shapes),
|
|
54
|
+
* })
|
|
55
|
+
* },
|
|
56
|
+
* })
|
|
57
|
+
*
|
|
58
|
+
* createApp(Zones).mount('#app')
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @module
|
|
62
|
+
*/
|
|
63
|
+
export * from './geometry.js';
|
|
64
|
+
export * from './MapDrawing.js';
|
|
65
|
+
export * from './MapDrawingToolbar.js';
|
|
66
|
+
export * from './types.js';
|
|
67
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue map drawing — toolbar + interaction surface for authoring geofences
|
|
3
|
+
* (polygons, circles, pins, lines) on top of any `@molecule/app-maps` backend.
|
|
4
|
+
*
|
|
5
|
+
* The Vue counterpart of `@molecule/app-map-drawing-react`: it exports the same
|
|
6
|
+
* names, takes the same props (React names) and renders the same DOM for the
|
|
7
|
+
* same input. Exports `<MapDrawing>`, `<MapDrawingToolbar>`, geometry helpers
|
|
8
|
+
* (`haversineDistanceMeters`, `closeRing`, `identityBackend`, `pointInRect`,
|
|
9
|
+
* `toRadians`), and the `MapShape` / `MapDrawingProps` / `MapDrawingBackend`
|
|
10
|
+
* types.
|
|
11
|
+
*
|
|
12
|
+
* Composes with `@molecule/app-maps` via two props: `mapSlot` (render the map
|
|
13
|
+
* element underneath the drawing overlay — as a prop or a same-named slot) and
|
|
14
|
+
* `mapBackend` (a 3-function projection adapter: `project`, `unproject`,
|
|
15
|
+
* `distanceMeters`). There is no prebuilt adapter — build one from your map
|
|
16
|
+
* instance as in the example.
|
|
17
|
+
*
|
|
18
|
+
* @remarks
|
|
19
|
+
* - When `mapBackend` is omitted, the IDENTITY backend is used: lng maps to x
|
|
20
|
+
* pixels and lat to y pixels, and "radiusMeters" is Euclidean pixels. That is
|
|
21
|
+
* intended for tests/storyboards only — always pass a real backend when shapes
|
|
22
|
+
* must be geographic.
|
|
23
|
+
* - polygon/line: click adds vertices, double-click finalises (polygons need 3+
|
|
24
|
+
* vertices); circle: drag from center, release commits; pin: one per click;
|
|
25
|
+
* select: marquee-drag, then the toolbar's delete button removes the
|
|
26
|
+
* selection; the cancel-draft button discards an in-progress draft.
|
|
27
|
+
* - Toolbar and surface labels route through `t()` under `mapDrawing.` — the
|
|
28
|
+
* registered companion bond is `@molecule/app-locales-feature-map-drawing`.
|
|
29
|
+
* - Note `@molecule/app-maps` currently ships only a placeholder provider (no
|
|
30
|
+
* real tiles); the drawing overlay works regardless, but the `mapSlot`
|
|
31
|
+
* background will be a placeholder until a real map provider is wired.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { createApp, defineComponent, h } from 'vue'
|
|
36
|
+
* import { haversineDistanceMeters, MapDrawing } from '@molecule/app-map-drawing-vue'
|
|
37
|
+
* import type { MapDrawingBackend } from '@molecule/app-map-drawing-vue'
|
|
38
|
+
*
|
|
39
|
+
* // Adapt any map instance into a drawing backend:
|
|
40
|
+
* const backend: MapDrawingBackend = {
|
|
41
|
+
* project: ([lng, lat]) => ({ x: lng, y: lat }),
|
|
42
|
+
* unproject: (point) => [point.x, point.y],
|
|
43
|
+
* distanceMeters: haversineDistanceMeters,
|
|
44
|
+
* }
|
|
45
|
+
*
|
|
46
|
+
* const Zones = defineComponent({
|
|
47
|
+
* setup() {
|
|
48
|
+
* return () =>
|
|
49
|
+
* h(MapDrawing, {
|
|
50
|
+
* tools: ['polygon', 'circle', 'pin'],
|
|
51
|
+
* height: 500,
|
|
52
|
+
* mapBackend: backend,
|
|
53
|
+
* onChange: (shapes) => console.log(shapes),
|
|
54
|
+
* })
|
|
55
|
+
* },
|
|
56
|
+
* })
|
|
57
|
+
*
|
|
58
|
+
* createApp(Zones).mount('#app')
|
|
59
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @module
|
|
62
|
+
*/
|
|
63
|
+
export * from './geometry.js';
|
|
64
|
+
export * from './MapDrawing.js';
|
|
65
|
+
export * from './MapDrawingToolbar.js';
|
|
66
|
+
export * from './types.js';
|
|
67
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6DG;AAEH,cAAc,eAAe,CAAA;AAC7B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,wBAAwB,CAAA;AACtC,cAAc,YAAY,CAAA"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for the map-drawing feature.
|
|
3
|
+
*
|
|
4
|
+
* Geometries follow the GeoJSON spec (RFC 7946) so shapes round-trip
|
|
5
|
+
* cleanly through any GeoJSON-aware backend (PostGIS, Mapbox, Leaflet,
|
|
6
|
+
* Google Maps, Turf, etc.). The component itself only needs the small
|
|
7
|
+
* subset of geometry types listed below — `Point` (pins), `LineString`
|
|
8
|
+
* (polylines), and `Polygon` (closed rings). Circles are non-standard
|
|
9
|
+
* in GeoJSON, so they are encoded as a `Point` plus a numeric
|
|
10
|
+
* `radiusMeters` in `properties` (the same convention Mapbox-GL-Draw
|
|
11
|
+
* uses).
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* GeoJSON Point — `[lng, lat]` (longitude first, per the spec).
|
|
17
|
+
*/
|
|
18
|
+
export interface GeoJsonPoint {
|
|
19
|
+
/** Geometry type discriminator. */
|
|
20
|
+
type: 'Point';
|
|
21
|
+
/** Single position — `[lng, lat]`. */
|
|
22
|
+
coordinates: [number, number];
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* GeoJSON LineString — sequence of two-or-more positions.
|
|
26
|
+
*/
|
|
27
|
+
export interface GeoJsonLineString {
|
|
28
|
+
/** Geometry type discriminator. */
|
|
29
|
+
type: 'LineString';
|
|
30
|
+
/** Ordered list of positions — `[lng, lat]` pairs. */
|
|
31
|
+
coordinates: [number, number][];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* GeoJSON Polygon — outer ring + optional holes. The drawing surface
|
|
35
|
+
* only authors the outer ring; holes are preserved verbatim if present
|
|
36
|
+
* on `initialShapes`.
|
|
37
|
+
*/
|
|
38
|
+
export interface GeoJsonPolygon {
|
|
39
|
+
/** Geometry type discriminator. */
|
|
40
|
+
type: 'Polygon';
|
|
41
|
+
/**
|
|
42
|
+
* Array of linear rings. The first ring is the outer boundary; any
|
|
43
|
+
* subsequent rings are holes. Each ring is a closed sequence of
|
|
44
|
+
* `[lng, lat]` positions where the first and last positions are
|
|
45
|
+
* identical.
|
|
46
|
+
*/
|
|
47
|
+
coordinates: [number, number][][];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Union of GeoJSON geometry kinds the drawing surface understands.
|
|
51
|
+
*/
|
|
52
|
+
export type GeoJsonGeometry = GeoJsonPoint | GeoJsonLineString | GeoJsonPolygon;
|
|
53
|
+
/**
|
|
54
|
+
* Drawn shape carried by the component. The `kind` discriminator is
|
|
55
|
+
* kept independent of the GeoJSON `type` because circles share the
|
|
56
|
+
* `Point` geometry (a radius lives in `properties`).
|
|
57
|
+
*/
|
|
58
|
+
export interface MapShape {
|
|
59
|
+
/** Stable identifier for the shape (used as the component key). */
|
|
60
|
+
id: string;
|
|
61
|
+
/** Logical shape kind. Drives toolbar selection + rendering style. */
|
|
62
|
+
kind: 'polygon' | 'circle' | 'pin' | 'line';
|
|
63
|
+
/** GeoJSON geometry. */
|
|
64
|
+
geometry: GeoJsonGeometry;
|
|
65
|
+
/**
|
|
66
|
+
* Free-form caller properties carried alongside the geometry. The
|
|
67
|
+
* `radiusMeters` key is reserved for circle shapes and is required
|
|
68
|
+
* when `kind === 'circle'`.
|
|
69
|
+
*/
|
|
70
|
+
properties?: Record<string, unknown> & {
|
|
71
|
+
radiusMeters?: number;
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Tools the toolbar may show. The fixed set is the four drawing tools
|
|
76
|
+
* plus two action tools (`select`, `delete`). The component renders
|
|
77
|
+
* the four drawing tools by default (`tools` prop) and always shows
|
|
78
|
+
* `select` + `delete` because they have no opt-out semantic.
|
|
79
|
+
*/
|
|
80
|
+
export type DrawingTool = 'polygon' | 'circle' | 'pin' | 'line';
|
|
81
|
+
/**
|
|
82
|
+
* Active tool — either one of the drawing tools or one of the action
|
|
83
|
+
* modes (`select`).
|
|
84
|
+
*/
|
|
85
|
+
export type ActiveTool = DrawingTool | 'select';
|
|
86
|
+
/**
|
|
87
|
+
* Screen-space point in CSS pixels relative to the drawing surface's
|
|
88
|
+
* bounding box. `(0, 0)` is the top-left corner.
|
|
89
|
+
*/
|
|
90
|
+
export interface ScreenPoint {
|
|
91
|
+
/** Horizontal offset in CSS pixels. */
|
|
92
|
+
x: number;
|
|
93
|
+
/** Vertical offset in CSS pixels. */
|
|
94
|
+
y: number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Backend the drawing surface delegates projection + great-circle
|
|
98
|
+
* distance to. Production callers pass an adapter wired to
|
|
99
|
+
* `@molecule/app-maps`'s `MapInstance` (`project` / `unproject`); test
|
|
100
|
+
* callers can pass a stub backend that uses identity projection.
|
|
101
|
+
*
|
|
102
|
+
* The backend abstraction means the component never depends on a
|
|
103
|
+
* specific map provider — swap Mapbox for Google Maps for Leaflet by
|
|
104
|
+
* swapping the backend, not the drawing surface.
|
|
105
|
+
*/
|
|
106
|
+
export interface MapDrawingBackend {
|
|
107
|
+
/**
|
|
108
|
+
* Project a `[lng, lat]` position to a screen-space pixel coordinate
|
|
109
|
+
* inside the drawing surface's bounding box.
|
|
110
|
+
*
|
|
111
|
+
* @param coordinates - `[lng, lat]` position.
|
|
112
|
+
* @returns Pixel offset relative to the drawing surface.
|
|
113
|
+
*/
|
|
114
|
+
project(coordinates: [number, number]): ScreenPoint;
|
|
115
|
+
/**
|
|
116
|
+
* Unproject a screen-space pixel coordinate back to `[lng, lat]`.
|
|
117
|
+
*
|
|
118
|
+
* @param point - Pixel offset relative to the drawing surface.
|
|
119
|
+
* @returns Geographic position in `[lng, lat]` order.
|
|
120
|
+
*/
|
|
121
|
+
unproject(point: ScreenPoint): [number, number];
|
|
122
|
+
/**
|
|
123
|
+
* Distance in meters between two `[lng, lat]` positions. Used to
|
|
124
|
+
* compute circle radii from drag distance. Production backends
|
|
125
|
+
* should use the Haversine great-circle formula; the default
|
|
126
|
+
* fallback uses an equirectangular approximation that is fine for
|
|
127
|
+
* small drag deltas at non-polar latitudes.
|
|
128
|
+
*
|
|
129
|
+
* @param a - First position.
|
|
130
|
+
* @param b - Second position.
|
|
131
|
+
* @returns Distance in meters.
|
|
132
|
+
*/
|
|
133
|
+
distanceMeters(a: [number, number], b: [number, number]): number;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Selection set — keyed by shape id. Stored as a `Set<string>` so
|
|
137
|
+
* delete operations stay O(1) regardless of how many shapes are drawn.
|
|
138
|
+
*/
|
|
139
|
+
export type ShapeSelection = ReadonlySet<string>;
|
|
140
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,mCAAmC;IACnC,IAAI,EAAE,OAAO,CAAA;IACb,sCAAsC;IACtC,WAAW,EAAE,CAAC,MAAM,E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;;;;OAKG;IACH,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAE/C;;;;;;;;;;OAUG;IACH,cAAc,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;CACjE;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,WAAW,CAAC,MAAM,CAAC,CAAA"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Public types for the map-drawing feature.
|
|
3
|
+
*
|
|
4
|
+
* Geometries follow the GeoJSON spec (RFC 7946) so shapes round-trip
|
|
5
|
+
* cleanly through any GeoJSON-aware backend (PostGIS, Mapbox, Leaflet,
|
|
6
|
+
* Google Maps, Turf, etc.). The component itself only needs the small
|
|
7
|
+
* subset of geometry types listed below — `Point` (pins), `LineString`
|
|
8
|
+
* (polylines), and `Polygon` (closed rings). Circles are non-standard
|
|
9
|
+
* in GeoJSON, so they are encoded as a `Point` plus a numeric
|
|
10
|
+
* `radiusMeters` in `properties` (the same convention Mapbox-GL-Draw
|
|
11
|
+
* uses).
|
|
12
|
+
*
|
|
13
|
+
* @module
|
|
14
|
+
*/
|
|
15
|
+
export {};
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@molecule/app-map-drawing-vue",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.1-stage",
|
|
4
|
+
"description": "Map polygon / circle / pin / line drawing primitives for geofence editing — composes with @molecule/app-maps for the underlying map backend",
|
|
5
|
+
"homepage": "https://www.molecule.dev/packages/app-map-drawing-vue",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "dist/index.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"dev": "vue-tsc --watch",
|
|
22
|
+
"test": "vitest run",
|
|
23
|
+
"test:watch": "vitest"
|
|
24
|
+
},
|
|
25
|
+
"keywords": [
|
|
26
|
+
"molecule",
|
|
27
|
+
"map-drawing",
|
|
28
|
+
"geofence",
|
|
29
|
+
"polygon",
|
|
30
|
+
"circle",
|
|
31
|
+
"pin",
|
|
32
|
+
"vue"
|
|
33
|
+
],
|
|
34
|
+
"author": "Molecule Dev, Inc. (https://molecule.dev)",
|
|
35
|
+
"license": "Apache-2.0",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/molecule-dev/molecule.git",
|
|
39
|
+
"directory": "packages/app/features/map-drawing-vue"
|
|
40
|
+
},
|
|
41
|
+
"engines": {
|
|
42
|
+
"node": ">=20"
|
|
43
|
+
},
|
|
44
|
+
"bugs": "https://github.com/molecule-dev/molecule/issues",
|
|
45
|
+
"publishConfig": {
|
|
46
|
+
"access": "public"
|
|
47
|
+
},
|
|
48
|
+
"peerDependencies": {
|
|
49
|
+
"@molecule/app-ui": "^1.0.1",
|
|
50
|
+
"@molecule/app-ui-vue": "^1.1.0",
|
|
51
|
+
"@molecule/app-vue": "^3.5.0",
|
|
52
|
+
"vue": "^3.4.0"
|
|
53
|
+
},
|
|
54
|
+
"devDependencies": {
|
|
55
|
+
"@molecule/app-framework-conformance": "0.0.0",
|
|
56
|
+
"@molecule/app-i18n": "1.2.2",
|
|
57
|
+
"@molecule/app-icons": "1.0.4",
|
|
58
|
+
"@molecule/app-ui": "1.4.0",
|
|
59
|
+
"@molecule/app-ui-vue": "1.1.4",
|
|
60
|
+
"@molecule/app-vue": "3.7.1",
|
|
61
|
+
"@types/node": "26.6.5",
|
|
62
|
+
"jsdom": "30.1.3",
|
|
63
|
+
"typescript": "6.0.3",
|
|
64
|
+
"vite": "8.3.5",
|
|
65
|
+
"vitest": "4.1.12",
|
|
66
|
+
"vue": "3.5.44",
|
|
67
|
+
"vue-tsc": "3.3.13"
|
|
68
|
+
}
|
|
69
|
+
}
|