// @wuys/map · layers/base.js
//
// Layer interface. A layer is a visual component that participates in the
// build-once / patch-per-frame lifecycle.
//
// @typedef {Object} Layer
// @property {string} id
// @property {(ctx: BuildContext) => void} build      — Create DOM/canvas elements once.
// @property {(ctx: PatchContext) => void} patch      — Update visuals each frame.
// @property {() => void} destroy
// @property {(x: number, y: number) => HitResult | null} [hitTest]
//
// `BuildContext` and `PatchContext` are renderer-specific. SVG renderer passes
// `{ root: SVGGElement, state, projection, viewport }`.

const REGISTRY = new Map();

export function registerLayer(id, factory) { REGISTRY.set(id, factory); }
export function createLayer(id, args) {
  const factory = REGISTRY.get(id);
  if (!factory) throw new Error("[wuys/map] Unknown layer: " + id);
  return factory(args);
}
export function listLayers() { return [...REGISTRY.keys()]; }
