/**
* Shared, **engine-agnostic** implementation of the anchored marker-widget primitive
* (see {@link MarkerWidget}). One implementation serves all three engines: the card is a
* DOM element that each engine **anchors at a lon/lat** via its native overlay primitive
* (MapLibre `Marker`, OpenLayers `Overlay`, Leaflet `divIcon` marker) — which gives
* per-frame tracking + correct zoom animation for free. This module owns everything else:
* building the card from the box-layout tree, **reconciling it in place** (so a focused
* input keeps focus/caret across re-`setWidgets`), the editable `` control, the
* live `coord` line, and routing card clicks/drags into the adapter's `onPointer` stream
* as a `{ overlay: "widget", props: { id } }` hit.
*
* Each engine provides a small {@link WidgetHost} (mount / unproject / emit); the rest is here.
*/
import type { LatLng, MarkerWidget, PointerEvent, WidgetBox, WidgetDial, WidgetEdit, WidgetGauge } from "./index.js";
/** A handle to one engine-anchored card mount. The card DOM lives inside `el`. */
export interface WidgetMount {
/** The engine-anchored element (its top-left tracks the anchor); the card is appended here. */
readonly el: HTMLElement;
/** Move the mount to a new anchor. */
setAnchor(anchor: LatLng): void;
/** Detach the mount from the map. */
remove(): void;
/** Set the CSS z-index of the engine overlay so this mount stacks above (z>0) or at default (z=0). */
setZIndex(z: number): void;
}
/** What each engine adapter supplies so the shared layer can place + wire cards. */
export interface WidgetHost {
/** Create an engine-anchored mount whose top-left tracks `anchor`. */
createMount(anchor: LatLng): WidgetMount;
/** Client (viewport) px → lon/lat, via the engine's container + `unproject`. */
unprojectClient(clientX: number, clientY: number): LatLng | null;
/** Emit a synthetic pointer event into the adapter's `onPointer` stream. */
emit(ev: PointerEvent): void;
/** Return keyboard focus to the map (its key-listening element) after a card button took it —
* so `onKey`/Escape keeps working. No-op while an editable field is focused. */
focus(): void;
}
/**
* Apply a {@link WidgetBox}'s optional frame (`bg`/`border`/`borderWidth`/`radius`/`padding`) — the
* same presets as the root card, so a sub-column can outline/fill itself. Border + padding sit in the
* content box, so they reserve room in the flex flow (siblings shift); `bg` paints behind the children.
* Every property is (re)written each update — boxes are reconciled in place, so unset fields must be
* cleared, not left stale. `border` as an object draws only the named sides (an absent side = no edge),
* letting two boxes drop their shared edge to compose a continuous L-shaped outline.
*/
export declare function applyBoxFrame(s: CSSStyleDeclaration, box: WidgetBox): void;
/** Reachable `[lo, hi]` for a gauge incl. the optional one-step `beyond` notches. */
export declare function gaugeBounds(g: WidgetGauge): {
lo: number;
hi: number;
};
/** Snap + clamp a dragged cursor: inside the bounds, and never past its neighbours (no crossing). */
export declare function clampCursor(raw: number, index: number, g: WidgetGauge): number;
/** Dial angle (deg) for a value, per the FIXED convention. */
export declare function dialAngle(value: number, d: WidgetDial): number;
/** Map a pointer angle (deg, screen convention) to a dial value — a drag into the bottom gap clamps
* to the nearer end. */
export declare function dialValueFromAngle(angleDeg: number, d: WidgetDial): number;
/** Resolve a `boxShape` to its normalized polygon, or `null` for the plain rectangle (the CSS box). */
export declare function resolveBoxShape(shape: MarkerWidget["boxShape"]): number[][] | null;
export interface ShapeLayout {
over: {
t: number;
r: number;
b: number;
l: number;
};
svgW: number;
svgH: number;
inset: number;
points: string;
}
/** Geometry for a shaped frame from the measured content+padding box `W×H` and border width `bw`:
* the overshoot margins (px) that grow the card, the svg size, and the polygon `points` string.
* Pure (DOM-free) so it's unit-testable. */
export declare function boxShapeLayout(points: number[][], W: number, H: number, bw: number): ShapeLayout;
export declare class WidgetLayer {
private readonly host;
private readonly cards;
private editCb;
private deleteCb;
private actionCb;
private coordFmt;
private currentWidgets;
private resizeObserver;
constructor(host: WidgetHost);
setWidgets(widgets: MarkerWidget[]): void;
/**
* Re-position all satellite cards that declare `anchorTo`: compute the px offset that puts
* their perpendicular edge flush against their target's measured edge (+ gap), then apply it
* as an extra CSS translation on top of the %-based origin transform.
*
* Called after the full setWidgets update loop, and from the ResizeObserver when a reference
* card's size changes. In jsdom (getBoundingClientRect returns zero), this is a safe no-op.
*/
private repositionAnchoredCards;
/** Watch reference cards with a ResizeObserver so satellites re-snap when the main card's
* content changes its size (e.g. a new label line appears). */
private updateResizeObserver;
onWidgetEdit(cb: (e: WidgetEdit) => void): void;
onWidgetDelete(cb: (e: {
id: string;
}) => void): void;
onWidgetAction(cb: (e: {
id: string;
event: string;
}) => void): void;
setCoordFormat(fn: (ll: LatLng) => string): void;
/** The live card roots + their anchors — for the snapshot pass to composite a static copy. */
snapshotCards(): {
root: HTMLElement;
anchor: LatLng;
}[];
destroy(): void;
}
/** Inline computed styles across the clone, and swap each editable `` for a static
* `` carrying its current value (the "non-selected" look wanted in the export). */
export declare function inlineStatic(src: HTMLElement, clone: HTMLElement): void;
/**
* Composite the marker cards onto a captured map canvas and return a PNG Blob. Cards are
* drawn in their **static** form (each editable input becomes a span showing its value).
*
* **Safe by design.** The card-less blob is produced from `mapCanvas` *before* any
* `foreignObject` is drawn, on a separate compositing canvas. If compositing or its encoding
* fails — most notably a `foreignObject`-**tainted** canvas (Safety/WebKit security), where
* `toBlob` throws — we return that clean base blob. So enabling widgets can never turn a
* working snapshot into a failure; worst case the cards are simply absent from the PNG.
*
* `mapCanvas` = the rendered map at output resolution, with NO widgets drawn on it;
* `project` maps lon/lat → CSS px; `scale` = output px per CSS px.
*/
export declare function snapshotWithWidgets(mapCanvas: HTMLCanvasElement, cards: {
root: HTMLElement;
anchor: LatLng;
}[], project: (ll: LatLng) => [number, number] | null, scale: number): Promise;
//# sourceMappingURL=widget.d.ts.map