@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/README.md CHANGED
@@ -1,3 +1,551 @@
1
- # Temporary Holding Version
1
+ <!--
2
+ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
+ Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
+ Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
+ To change this document, edit the module-level JSDoc in src/index.ts.
6
+ Generated: 2026-11-18T20:21:43.154Z
7
+ -->
2
8
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
9
+ # @molecule/app-map-drawing-vue
10
+
11
+ Vue map drawing — toolbar + interaction surface for authoring geofences
12
+ (polygons, circles, pins, lines) on top of any `@molecule/app-maps` backend.
13
+
14
+ The Vue counterpart of `@molecule/app-map-drawing-react`: it exports the same
15
+ names, takes the same props (React names) and renders the same DOM for the
16
+ same input. Exports `<MapDrawing>`, `<MapDrawingToolbar>`, geometry helpers
17
+ (`haversineDistanceMeters`, `closeRing`, `identityBackend`, `pointInRect`,
18
+ `toRadians`), and the `MapShape` / `MapDrawingProps` / `MapDrawingBackend`
19
+ types.
20
+
21
+ Composes with `@molecule/app-maps` via two props: `mapSlot` (render the map
22
+ element underneath the drawing overlay — as a prop or a same-named slot) and
23
+ `mapBackend` (a 3-function projection adapter: `project`, `unproject`,
24
+ `distanceMeters`). There is no prebuilt adapter — build one from your map
25
+ instance as in the example.
26
+
27
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
28
+ > It is written to be read by coding agents as much as by people, and is generated from this
29
+ > package's source — edit `src/index.ts` JSDoc, not this file.
30
+
31
+ ## Quick Start
32
+
33
+ ```ts
34
+ import { createApp, defineComponent, h } from 'vue'
35
+ import { haversineDistanceMeters, MapDrawing } from '@molecule/app-map-drawing-vue'
36
+ import type { MapDrawingBackend } from '@molecule/app-map-drawing-vue'
37
+
38
+ // Adapt any map instance into a drawing backend:
39
+ const backend: MapDrawingBackend = {
40
+ project: ([lng, lat]) => ({ x: lng, y: lat }),
41
+ unproject: (point) => [point.x, point.y],
42
+ distanceMeters: haversineDistanceMeters,
43
+ }
44
+
45
+ const Zones = defineComponent({
46
+ setup() {
47
+ return () =>
48
+ h(MapDrawing, {
49
+ tools: ['polygon', 'circle', 'pin'],
50
+ height: 500,
51
+ mapBackend: backend,
52
+ onChange: (shapes) => console.log(shapes),
53
+ })
54
+ },
55
+ })
56
+
57
+ createApp(Zones).mount('#app')
58
+ ```
59
+
60
+ ## Type
61
+
62
+ `feature`
63
+
64
+ ## Installation
65
+
66
+ ```bash
67
+ npm install @molecule/app-map-drawing-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue
68
+ ```
69
+
70
+ ## API
71
+
72
+ ### Interfaces
73
+
74
+ #### `MapDrawingProps`
75
+
76
+ MapDrawing component props.
77
+
78
+ ```typescript
79
+ interface MapDrawingProps {
80
+ /** Initial shapes to seed the surface with. */
81
+ initialShapes?: MapShape[]
82
+ /** Called whenever the shape list changes (add / edit / delete). */
83
+ onChange: (shapes: MapShape[]) => void
84
+ /** Drawing tools to expose. Defaults to the four built-in tools. */
85
+ tools?: DrawingTool[]
86
+ /** Externally controlled active tool. When omitted, the component manages tool state internally. */
87
+ activeTool?: ActiveTool
88
+ /** Called when the active tool changes (drives the toolbar regardless of internal/external state). */
89
+ onActiveToolChange?: (tool: ActiveTool) => void
90
+ /**
91
+ * Map backend used to project between geographic and screen coordinates.
92
+ * Defaults to an identity backend that treats `lng → x`, `lat → y` so
93
+ * the component can be exercised in tests without a real map provider.
94
+ */
95
+ mapBackend?: MapDrawingBackend
96
+ /** Optional content for the map background (e.g. a `<MapView />`), prop or slot. */
97
+ mapSlot?: VNodeChild
98
+ /** Width of the surface (CSS) — defaults to `100%`. */
99
+ width?: number | string
100
+ /** Height of the surface (CSS) — defaults to `400`. */
101
+ height?: number | string
102
+ /** Extra classes merged onto the root element. */
103
+ className?: string
104
+ }
105
+ ```
106
+
107
+ #### `MapDrawingToolbarProps`
108
+
109
+ MapDrawingToolbar component props.
110
+
111
+ ```typescript
112
+ interface MapDrawingToolbarProps {
113
+ /** Drawing tools to expose (in declaration order). */
114
+ tools: DrawingTool[]
115
+ /** Currently active tool. */
116
+ activeTool: ActiveTool
117
+ /** Called when the user clicks a tool button. */
118
+ onActiveToolChange: (tool: ActiveTool) => void
119
+ /** Called when the user clicks the delete-selected button. */
120
+ onDeleteSelected: () => void
121
+ /** Whether anything is currently selected (drives delete-button enabled state). */
122
+ hasSelection: boolean
123
+ /** Whether a draft (path vertices, circle or marquee) is in progress (drives cancel-button enabled state). */
124
+ hasDraft: boolean
125
+ /** Called when the user clicks the cancel-draft button. */
126
+ onCancelDraft: () => void
127
+ }
128
+ ```
129
+
130
+ #### `GeoJsonPoint`
131
+
132
+ GeoJSON Point — `[lng, lat]` (longitude first, per the spec).
133
+
134
+ ```typescript
135
+ interface GeoJsonPoint {
136
+ /** Geometry type discriminator. */
137
+ type: 'Point'
138
+ /** Single position — `[lng, lat]`. */
139
+ coordinates: [number, number]
140
+ }
141
+ ```
142
+
143
+ #### `GeoJsonLineString`
144
+
145
+ GeoJSON LineString — sequence of two-or-more positions.
146
+
147
+ ```typescript
148
+ interface GeoJsonLineString {
149
+ /** Geometry type discriminator. */
150
+ type: 'LineString'
151
+ /** Ordered list of positions — `[lng, lat]` pairs. */
152
+ coordinates: [number, number][]
153
+ }
154
+ ```
155
+
156
+ #### `GeoJsonPolygon`
157
+
158
+ GeoJSON Polygon — outer ring + optional holes. The drawing surface
159
+ only authors the outer ring; holes are preserved verbatim if present
160
+ on `initialShapes`.
161
+
162
+ ```typescript
163
+ interface GeoJsonPolygon {
164
+ /** Geometry type discriminator. */
165
+ type: 'Polygon'
166
+ /**
167
+ * Array of linear rings. The first ring is the outer boundary; any
168
+ * subsequent rings are holes. Each ring is a closed sequence of
169
+ * `[lng, lat]` positions where the first and last positions are
170
+ * identical.
171
+ */
172
+ coordinates: [number, number][][]
173
+ }
174
+ ```
175
+
176
+ #### `MapShape`
177
+
178
+ Drawn shape carried by the component. The `kind` discriminator is
179
+ kept independent of the GeoJSON `type` because circles share the
180
+ `Point` geometry (a radius lives in `properties`).
181
+
182
+ ```typescript
183
+ interface MapShape {
184
+ /** Stable identifier for the shape (used as the component key). */
185
+ id: string
186
+ /** Logical shape kind. Drives toolbar selection + rendering style. */
187
+ kind: 'polygon' | 'circle' | 'pin' | 'line'
188
+ /** GeoJSON geometry. */
189
+ geometry: GeoJsonGeometry
190
+ /**
191
+ * Free-form caller properties carried alongside the geometry. The
192
+ * `radiusMeters` key is reserved for circle shapes and is required
193
+ * when `kind === 'circle'`.
194
+ */
195
+ properties?: Record<string, unknown> & { radiusMeters?: number }
196
+ }
197
+ ```
198
+
199
+ #### `ScreenPoint`
200
+
201
+ Screen-space point in CSS pixels relative to the drawing surface's
202
+ bounding box. `(0, 0)` is the top-left corner.
203
+
204
+ ```typescript
205
+ interface ScreenPoint {
206
+ /** Horizontal offset in CSS pixels. */
207
+ x: number
208
+ /** Vertical offset in CSS pixels. */
209
+ y: number
210
+ }
211
+ ```
212
+
213
+ #### `MapDrawingBackend`
214
+
215
+ Backend the drawing surface delegates projection + great-circle
216
+ distance to. Production callers pass an adapter wired to
217
+ `@molecule/app-maps`'s `MapInstance` (`project` / `unproject`); test
218
+ callers can pass a stub backend that uses identity projection.
219
+
220
+ The backend abstraction means the component never depends on a
221
+ specific map provider — swap Mapbox for Google Maps for Leaflet by
222
+ swapping the backend, not the drawing surface.
223
+
224
+ ```typescript
225
+ interface MapDrawingBackend {
226
+ /**
227
+ * Project a `[lng, lat]` position to a screen-space pixel coordinate
228
+ * inside the drawing surface's bounding box.
229
+ *
230
+ * @param coordinates - `[lng, lat]` position.
231
+ * @returns Pixel offset relative to the drawing surface.
232
+ */
233
+ project(coordinates: [number, number]): ScreenPoint
234
+
235
+ /**
236
+ * Unproject a screen-space pixel coordinate back to `[lng, lat]`.
237
+ *
238
+ * @param point - Pixel offset relative to the drawing surface.
239
+ * @returns Geographic position in `[lng, lat]` order.
240
+ */
241
+ unproject(point: ScreenPoint): [number, number]
242
+
243
+ /**
244
+ * Distance in meters between two `[lng, lat]` positions. Used to
245
+ * compute circle radii from drag distance. Production backends
246
+ * should use the Haversine great-circle formula; the default
247
+ * fallback uses an equirectangular approximation that is fine for
248
+ * small drag deltas at non-polar latitudes.
249
+ *
250
+ * @param a - First position.
251
+ * @param b - Second position.
252
+ * @returns Distance in meters.
253
+ */
254
+ distanceMeters(a: [number, number], b: [number, number]): number
255
+ }
256
+ ```
257
+
258
+ ### Types
259
+
260
+ #### `GeoJsonGeometry`
261
+
262
+ Union of GeoJSON geometry kinds the drawing surface understands.
263
+
264
+ ```typescript
265
+ type GeoJsonGeometry = GeoJsonPoint | GeoJsonLineString | GeoJsonPolygon
266
+ ```
267
+
268
+ #### `DrawingTool`
269
+
270
+ Tools the toolbar may show. The fixed set is the four drawing tools
271
+ plus two action tools (`select`, `delete`). The component renders
272
+ the four drawing tools by default (`tools` prop) and always shows
273
+ `select` + `delete` because they have no opt-out semantic.
274
+
275
+ ```typescript
276
+ type DrawingTool = 'polygon' | 'circle' | 'pin' | 'line'
277
+ ```
278
+
279
+ #### `ActiveTool`
280
+
281
+ Active tool — either one of the drawing tools or one of the action
282
+ modes (`select`).
283
+
284
+ ```typescript
285
+ type ActiveTool = DrawingTool | 'select'
286
+ ```
287
+
288
+ #### `ShapeSelection`
289
+
290
+ Selection set — keyed by shape id. Stored as a `Set<string>` so
291
+ delete operations stay O(1) regardless of how many shapes are drawn.
292
+
293
+ ```typescript
294
+ type ShapeSelection = ReadonlySet<string>
295
+ ```
296
+
297
+ ### Functions
298
+
299
+ #### `toRadians(degrees)`
300
+
301
+ Convert degrees to radians.
302
+
303
+ ```typescript
304
+ function toRadians(degrees: number): number
305
+ ```
306
+
307
+ - `degrees` — Angle in degrees.
308
+
309
+ **Returns:** Angle in radians.
310
+
311
+ #### `haversineDistanceMeters(a, b)`
312
+
313
+ Great-circle distance between two `[lng, lat]` positions in meters
314
+ using the Haversine formula (uses the WGS84 equatorial radius,
315
+ 6378137 m), so the
316
+ radius computed during drag agrees with what a geographic backend
317
+ will project back to the user.
318
+
319
+ ```typescript
320
+ function haversineDistanceMeters(a: [number, number], b: [number, number]): number
321
+ ```
322
+
323
+ - `a` — First position.
324
+ - `b` — Second position.
325
+
326
+ **Returns:** Distance in meters.
327
+
328
+ #### `closeRing(vertices)`
329
+
330
+ Snap an open ring (the in-progress polygon vertex list) into a
331
+ GeoJSON-compliant closed ring by repeating the first point at the
332
+ end. Returns `null` when the ring has fewer than three vertices,
333
+ since polygons require a minimum of three distinct points plus the
334
+ closing repeat.
335
+
336
+ ```typescript
337
+ function closeRing(vertices: [number, number][]): [number, number][] | null
338
+ ```
339
+
340
+ - `vertices` — Open ring of `[lng, lat]` pairs.
341
+
342
+ **Returns:** Closed ring, or `null` when there are not enough points.
343
+
344
+ #### `pointInRect(point, a, b)`
345
+
346
+ Check whether a screen-space point lies inside the given selection
347
+ rectangle (axis-aligned, inclusive bounds).
348
+
349
+ ```typescript
350
+ function pointInRect(point: ScreenPoint, a: ScreenPoint, b: ScreenPoint): boolean
351
+ ```
352
+
353
+ - `point` — Point under test.
354
+ - `a` — One corner of the selection rectangle.
355
+ - `b` — Opposite corner of the selection rectangle.
356
+
357
+ **Returns:** `true` when the point lies inside the rectangle.
358
+
359
+ ### Constants
360
+
361
+ #### `MapDrawing`
362
+
363
+ Map-drawing surface for geofence editing. Renders a toolbar plus an
364
+ interaction layer overlaid on top of the (optional) map slot. The
365
+ component handles four drawing tools — polygon, circle, pin, line —
366
+ plus a select / delete action group.
367
+
368
+ Drawing semantics:
369
+
370
+ - **polygon / line**: click adds vertices; double-click finalises.
371
+ - **circle**: pointer-down sets the center; pointer-up commits with
372
+ radius equal to the great-circle distance from center to release.
373
+ - **pin**: each pointer-down adds one new pin shape.
374
+ - **select**: pointer-drag draws a marquee; any shape whose anchor
375
+ point lies inside the marquee is added to the selection.
376
+
377
+ ```typescript
378
+ const MapDrawing: DefineComponent<
379
+ ExtractPropTypes<{
380
+ initialShapes: { type: PropType<MapShape[]>; default: undefined }
381
+ onChange: { type: PropType<MapDrawingProps['onChange']>; required: true }
382
+ tools: { type: PropType<DrawingTool[]>; default: () => DrawingTool[] }
383
+ activeTool: { type: PropType<ActiveTool | undefined>; default: undefined }
384
+ onActiveToolChange: {
385
+ type: PropType<MapDrawingProps['onActiveToolChange']>
386
+ default: undefined
387
+ }
388
+ mapBackend: { type: PropType<MapDrawingBackend>; default: undefined }
389
+ mapSlot: null
390
+ width: { type: PropType<number | string>; default: string }
391
+ height: { type: PropType<number | string>; default: number }
392
+ className: { type: PropType<string | undefined>; default: undefined }
393
+ }>,
394
+ () => VNode,
395
+ {},
396
+ {},
397
+ {},
398
+ ComponentOptionsMixin,
399
+ ComponentOptionsMixin,
400
+ {},
401
+ string,
402
+ PublicProps,
403
+ Readonly<
404
+ ExtractPropTypes<{
405
+ initialShapes: { type: PropType<MapShape[]>; default: undefined }
406
+ onChange: { type: PropType<MapDrawingProps['onChange']>; required: true }
407
+ tools: { type: PropType<DrawingTool[]>; default: () => DrawingTool[] }
408
+ activeTool: { type: PropType<ActiveTool | undefined>; default: undefined }
409
+ onActiveToolChange: {
410
+ type: PropType<MapDrawingProps['onActiveToolChange']>
411
+ default: undefined
412
+ }
413
+ mapBackend: { type: PropType<MapDrawingBackend>; default: undefined }
414
+ mapSlot: null
415
+ width: { type: PropType<number | string>; default: string }
416
+ height: { type: PropType<number | string>; default: number }
417
+ className: { type: PropType<string | undefined>; default: undefined }
418
+ }>
419
+ > &
420
+ Readonly<{}>,
421
+ {
422
+ onActiveToolChange: ((tool: ActiveTool) => void) | undefined
423
+ initialShapes: MapShape[]
424
+ tools: DrawingTool[]
425
+ activeTool: ActiveTool | undefined
426
+ mapBackend: MapDrawingBackend
427
+ width: string | number
428
+ height: string | number
429
+ className: string | undefined
430
+ },
431
+ {},
432
+ {},
433
+ {},
434
+ string,
435
+ ComponentProvideOptions,
436
+ true,
437
+ {},
438
+ any
439
+ >
440
+ ```
441
+
442
+ - `props` — Component props (see {@link MapDrawingProps}).
443
+
444
+ **Returns:** The map-drawing component.
445
+
446
+ #### `MapDrawingToolbar`
447
+
448
+ Toolbar with one button per drawing tool plus `select` and `delete`.
449
+ All button labels route through `t()` so the toolbar translates via the
450
+ companion `@molecule/app-locales-feature-map-drawing` bond.
451
+
452
+ ```typescript
453
+ const MapDrawingToolbar: DefineComponent<
454
+ ExtractPropTypes<{
455
+ tools: { type: PropType<DrawingTool[]>; required: true }
456
+ activeTool: { type: PropType<ActiveTool>; required: true }
457
+ onActiveToolChange: {
458
+ type: PropType<MapDrawingToolbarProps['onActiveToolChange']>
459
+ required: true
460
+ }
461
+ onDeleteSelected: { type: PropType<MapDrawingToolbarProps['onDeleteSelected']>; required: true }
462
+ hasSelection: { type: BooleanConstructor; required: true }
463
+ hasDraft: { type: BooleanConstructor; required: true }
464
+ onCancelDraft: { type: PropType<MapDrawingToolbarProps['onCancelDraft']>; required: true }
465
+ }>,
466
+ () => VNode,
467
+ {},
468
+ {},
469
+ {},
470
+ ComponentOptionsMixin,
471
+ ComponentOptionsMixin,
472
+ {},
473
+ string,
474
+ PublicProps,
475
+ Readonly<
476
+ ExtractPropTypes<{
477
+ tools: { type: PropType<DrawingTool[]>; required: true }
478
+ activeTool: { type: PropType<ActiveTool>; required: true }
479
+ onActiveToolChange: {
480
+ type: PropType<MapDrawingToolbarProps['onActiveToolChange']>
481
+ required: true
482
+ }
483
+ onDeleteSelected: {
484
+ type: PropType<MapDrawingToolbarProps['onDeleteSelected']>
485
+ required: true
486
+ }
487
+ hasSelection: { type: BooleanConstructor; required: true }
488
+ hasDraft: { type: BooleanConstructor; required: true }
489
+ onCancelDraft: { type: PropType<MapDrawingToolbarProps['onCancelDraft']>; required: true }
490
+ }>
491
+ > &
492
+ Readonly<{}>,
493
+ {},
494
+ {},
495
+ {},
496
+ {},
497
+ string,
498
+ ComponentProvideOptions,
499
+ true,
500
+ {},
501
+ any
502
+ >
503
+ ```
504
+
505
+ - `props` — Toolbar props (see {@link MapDrawingToolbarProps}).
506
+
507
+ **Returns:** The toolbar component.
508
+
509
+ #### `identityBackend`
510
+
511
+ Identity drawing backend — used when no real map is mounted (tests,
512
+ SSR, demo storyboards). Projection is `lng → x`, `lat → y` so
513
+ fixtures can be authored in pixel space and round-trip cleanly. The
514
+ distance metric is Euclidean pixels rather than meters; callers that
515
+ care about a real radius should always pass a real backend.
516
+
517
+ ```typescript
518
+ const identityBackend: MapDrawingBackend
519
+ ```
520
+
521
+ ## Injection Notes
522
+
523
+ ### Requirements
524
+
525
+ Peer dependencies:
526
+
527
+ - `@molecule/app-ui` ^1.0.1
528
+ - `@molecule/app-ui-vue` ^1.1.0
529
+ - `@molecule/app-vue` ^3.5.0
530
+ - `vue` ^3.4.0
531
+
532
+ ### Runtime Dependencies
533
+
534
+ - `@molecule/app-ui`
535
+ - `@molecule/app-ui-vue`
536
+ - `@molecule/app-vue`
537
+ - `vue`
538
+
539
+ - When `mapBackend` is omitted, the IDENTITY backend is used: lng maps to x
540
+ pixels and lat to y pixels, and "radiusMeters" is Euclidean pixels. That is
541
+ intended for tests/storyboards only — always pass a real backend when shapes
542
+ must be geographic.
543
+ - polygon/line: click adds vertices, double-click finalises (polygons need 3+
544
+ vertices); circle: drag from center, release commits; pin: one per click;
545
+ select: marquee-drag, then the toolbar's delete button removes the
546
+ selection; the cancel-draft button discards an in-progress draft.
547
+ - Toolbar and surface labels route through `t()` under `mapDrawing.` — the
548
+ registered companion bond is `@molecule/app-locales-feature-map-drawing`.
549
+ - Note `@molecule/app-maps` currently ships only a placeholder provider (no
550
+ real tiles); the drawing overlay works regardless, but the `mapSlot`
551
+ background will be a placeholder until a real map provider is wired.