@molecule/app-annotation-pin-vue
Vue annotation pin / hotspot overlay primitives.
Exports <AnnotationPin> (single click-to-toggle marker) and
<AnnotationLayer> (parent wrapper that manages many pins on a
surface). Reusable for 3d-model viewers, image annotations, map
pins, and hotspot tours. It is the Vue counterpart of
@molecule/app-annotation-pin-react: same props (React names) and the
same DOM for the same input, so an app switches framework by changing
only the package name in its imports.
Auto-generated, AI-first package reference for the molecule.dev ecosystem.
It is written to be read by coding agents as much as by people, and is generated from this
package's source — edit src/index.ts JSDoc, not this file.
Quick Start
import { defineComponent, h, ref } from 'vue'
import { AnnotationLayer, type Pin } from '@molecule/app-annotation-pin-vue'
const ImageAnnotator = defineComponent({
props: { src: { type: String, required: true } },
setup(props) {
const pins = ref<Pin[]>([])
const activeId = ref<string | null>(null)
const addPin = ({ x, y }: { x: number; y: number }): void => {
const id = crypto.randomUUID()
pins.value = [...pins.value, { id, position: { x, y }, label: pins.value.length + 1 }]
activeId.value = id
}
return () =>
h(
AnnotationLayer,
{
pins: pins.value,
activePinId: activeId.value,
onPinClick: (id: string) => {
activeId.value = id === activeId.value ? null : id
},
onSurfaceClick: addPin,
},
{
default: () => [
h('img', { src: props.src, alt: '', style: { width: '100%', display: 'block' } }),
],
},
)
},
})
Type
feature
Installation
npm install @molecule/app-annotation-pin-vue @molecule/app-ui @molecule/app-ui-vue @molecule/app-vue vue
API
Interfaces
Pin
A single pin to display on a parent surface. position is in the
parent's coordinate space — for image / 2D-canvas overlays this is
normalised 0..1 (so the pin re-anchors as the surface resizes); for
pixel-positioned overlays callers can pass raw px values and provide
their own style overrides via className.
The label/note are pure data — components handle render only. Surfaces
supply pin objects via <AnnotationLayer :pins="..."> (or render a
single pin directly if there is only one).
interface Pin {
/** Stable identifier (used as the Vue key). */
id: string
/** Position in the parent surface's coordinate space (typically normalised 0..1). */
position: { x: number; y: number }
/** Short label (e.g. an index or single-word tag) shown inside the pin marker. */
label?: VNodeChild
/** Longer note / description body, shown inside the popup when the pin is selected. */
note?: VNodeChild
}
AnnotationPinProps
<AnnotationPin> props.
interface AnnotationPinProps {
/** Position in the parent surface's coordinate space (typically normalised 0..1). */
position: { x: number; y: number }
/**
* Short label (e.g. an index or single-word tag) shown inside the marker.
* Passed as a prop or as the same-named slot — both work.
*/
label?: VNodeChild
/**
* Longer note shown inside the popup when the pin is selected. Passed as a
* prop or as the same-named slot — both work.
*/
note?: VNodeChild
/**
* Whether the pin is currently selected. When `true` the popup is
* rendered. Selection is controlled — callers manage state in
* `<AnnotationLayer>` (or themselves) and update via `onClick`.
*/
selected?: boolean
/** Click handler — fires when the pin marker is clicked. */
onClick?: () => void
/**
* Side the popup renders on, relative to the marker. Defaults to `'right'`.
*/
popupSide?: 'top' | 'bottom' | 'left' | 'right'
/** Extra classes merged onto the root wrapper. */
className?: string
/**
* Whether `position` is normalised (0..1) — when `true` the wrapper
* positions itself with `%` units so pins re-anchor on resize. When
* `false` the wrapper uses raw `px` values. Defaults to `true`.
*/
normalised?: boolean
}
AnnotationLayerProps
<AnnotationLayer> props.
interface AnnotationLayerProps {
/** Pins to render on the layer. */
pins: Pin[]
/**
* Optional layer content (the surface to annotate — image, canvas, map
* tile, etc.). The DEFAULT slot.
*/
children?: VNodeChild
/**
* The currently active (popup-open) pin id, or `null` for none. The
* layer is fully controlled — callers manage selection state.
*/
activePinId?: string | null
/** Called with the clicked pin id when a pin marker is clicked. */
onPinClick?: (pinId: string) => void
/**
* Called when the user clicks an empty area of the layer (i.e. not on
* a pin marker or a popup). Coordinates are in the same space as
* `Pin.position` — normalised 0..1 by default. Keyboard users get the
* same action: activating the layer's "add pin" button (Tab to it,
* then Enter / Space) places a pin at the surface centre.
*/
onSurfaceClick?: (position: { x: number; y: number }) => void
/**
* Whether positions are normalised (0..1) — when `true` the layer
* computes click coordinates as fractions of its bounding box; when
* `false` it returns raw pixel offsets. Defaults to `true`.
*/
normalised?: boolean
/**
* Side the popup renders on, relative to its marker. Defaults to `'right'`.
*/
popupSide?: 'top' | 'bottom' | 'left' | 'right'
/** Extra classes merged onto the layer root. */
className?: string
/** Inline style for the layer root, merged over the layer's own. */
style?: Record<string, string | number>
}
Constants
AnnotationLayer
Wrapper that manages multiple pins on a parent surface. Renders its
default slot (the surface — typically an <img>, <canvas>, or
map-tile element) and overlays each pins[] entry as a clickable
<AnnotationPin> marker.
Click behaviour:
- clicking a pin marker fires
onPinClick(pinId)
- clicking empty space on the layer fires
onSurfaceClick({ x, y }),
which callers typically use to add a new pin. That action lives on
an invisible "add annotation pin" button covering the surface (the
layer region itself is not interactive — it contains the pin
buttons and popups): pointer clicks place a pin at the click
position; activating the button with a keyboard (Tab to it, then
Enter / Space) or assistive tech places a pin at the surface centre.
The layer itself sets position: relative so absolute pin
positioning works without the caller having to provide a wrapper.
All styling routes through getClassMap(); all user-visible text
routes through t() so the layer translates via the companion
@molecule/app-locales-annotation-pin locale bond.
const AnnotationLayer: DefineComponent<
ExtractPropTypes<{
pins: { type: PropType<Pin[]>; required: true }
activePinId: { type: PropType<string | null | undefined>; default: undefined }
onPinClick: { type: PropType<(pinId: string) => void>; default: undefined }
onSurfaceClick: {
type: PropType<(position: { x: number; y: number }) => void>
default: undefined
}
normalised: { type: BooleanConstructor; default: boolean }
popupSide: { type: PropType<'top' | 'bottom' | 'left' | 'right'>; default: string }
className: StringConstructor
style: { type: PropType<Record<string, string | number>>; default: undefined }
}>,
() => VNodeChild,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
pins: { type: PropType<Pin[]>; required: true }
activePinId: { type: PropType<string | null | undefined>; default: undefined }
onPinClick: { type: PropType<(pinId: string) => void>; default: undefined }
onSurfaceClick: {
type: PropType<(position: { x: number; y: number }) => void>
default: undefined
}
normalised: { type: BooleanConstructor; default: boolean }
popupSide: { type: PropType<'top' | 'bottom' | 'left' | 'right'>; default: string }
className: StringConstructor
style: { type: PropType<Record<string, string | number>>; default: undefined }
}>
> &
Readonly<{}>,
{
activePinId: string | null | undefined
onPinClick: (pinId: string) => void
onSurfaceClick: (position: { x: number; y: number }) => void
normalised: boolean
popupSide: 'top' | 'bottom' | 'left' | 'right'
style: Record<string, string | number>
},
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props — Component props (see {@link AnnotationLayerProps}).
Returns: The annotation-layer component.
AnnotationPin
A single pin marker (small circle with optional label) rendered at
an absolute position on its parent. Clicking the marker toggles its
popup (which shows the note body) via the onClick handler.
Positioning is absolute relative to the nearest positioned ancestor —
callers must wrap the surface (image, canvas, map) in a
position: relative element. AnnotationLayer provides this
wrapper automatically.
All styling routes through getClassMap(); all user-visible text
(aria-labels, fallback note text) routes through t() so the marker
translates via the companion @molecule/app-locales-annotation-pin
locale bond.
const AnnotationPin: DefineComponent<
ExtractPropTypes<{
position: { type: PropType<{ x: number; y: number }>; required: true }
label: null
note: null
selected: { type: BooleanConstructor; default: boolean }
onClick: { type: PropType<() => void>; default: undefined }
popupSide: { type: PropType<'top' | 'bottom' | 'left' | 'right'>; default: string }
className: StringConstructor
normalised: { type: BooleanConstructor; default: boolean }
}>,
() => VNodeChild,
{},
{},
{},
ComponentOptionsMixin,
ComponentOptionsMixin,
{},
string,
PublicProps,
Readonly<
ExtractPropTypes<{
position: { type: PropType<{ x: number; y: number }>; required: true }
label: null
note: null
selected: { type: BooleanConstructor; default: boolean }
onClick: { type: PropType<() => void>; default: undefined }
popupSide: { type: PropType<'top' | 'bottom' | 'left' | 'right'>; default: string }
className: StringConstructor
normalised: { type: BooleanConstructor; default: boolean }
}>
> &
Readonly<{}>,
{
normalised: boolean
popupSide: 'top' | 'bottom' | 'left' | 'right'
selected: boolean
onClick: () => void
},
{},
{},
{},
string,
ComponentProvideOptions,
true,
{},
any
>
props — Component props (see {@link AnnotationPinProps}).
Returns: The pin component.
Injection Notes
Requirements
Peer dependencies:
@molecule/app-ui ^1.0.1
@molecule/app-ui-vue ^1.1.0
@molecule/app-vue ^3.13.0 || ^4.0.0
vue ^3.4.0
Runtime Dependencies
@molecule/app-ui
@molecule/app-ui-vue
@molecule/app-vue
vue
Selection is fully controlled — the layer never stores the active pin;
manage activePinId yourself and toggle it in onPinClick. position
is normalised 0..1 by default (fractions of the layer box, so pins
re-anchor on resize); pass normalised={false} for raw pixel offsets —
on BOTH <AnnotationLayer> and any directly-rendered <AnnotationPin>,
or clicks and markers will disagree. The layer wraps the default slot in
a position: relative box; a bare <AnnotationPin> needs its own
positioned ancestor. Node-valued props (label, note, the layer's
content) arrive as a prop AND a same-named slot; components accept
either. Translations come from the companion
@molecule/app-locales-annotation-pin locale bond.
Translations
Translation strings are provided by @molecule/app-locales-annotation-pin.