{"version":3,"sources":["../src/api.ts","../src/types.ts"],"sourcesContent":["export { DebugRegistryKey } from \"./types.js\";\nexport type {\n  DebugGraphics,\n  WorldDebugApi,\n  SceneWorldDebugApi,\n  HudDebugApi,\n  StatsApi,\n  DebugContributor,\n  DebugRegistry,\n  DebugVectorProvider,\n  DebugVectorOptions,\n} from \"./types.js\";\n","import { ServiceKey } from \"@yagejs/core\";\nimport type { Entity, Scene, Vec2Like } from \"@yagejs/core\";\n\n/**\n * Minimal subset of PixiJS Graphics used by debug drawing.\n * Avoids a runtime pixi.js dependency in the ./api subpath.\n */\nexport interface DebugGraphics {\n  position: { x: number; y: number };\n  rotation: number;\n  visible: boolean;\n  clear(): DebugGraphics;\n  rect(x: number, y: number, width: number, height: number): DebugGraphics;\n  roundRect(\n    x: number,\n    y: number,\n    width: number,\n    height: number,\n    radius: number,\n  ): DebugGraphics;\n  circle(x: number, y: number, radius: number): DebugGraphics;\n  moveTo(x: number, y: number): DebugGraphics;\n  lineTo(x: number, y: number): DebugGraphics;\n  stroke(style: {\n    width: number;\n    color: number;\n    alpha?: number;\n  }): DebugGraphics;\n  fill(style: { color: number; alpha?: number }): DebugGraphics;\n}\n\n/** Camera-space drawing API passed to contributors. */\nexport interface SceneWorldDebugApi {\n  acquireGraphics(): DebugGraphics | undefined;\n  readonly cameraZoom: number;\n}\n\nexport interface WorldDebugApi extends SceneWorldDebugApi {\n  isFlagEnabled(flag: string): boolean;\n  /** Drawing for a visible scene, or undefined while hidden or off the stack. */\n  forScene(scene: Scene): SceneWorldDebugApi | undefined;\n}\n\n/** Screen-space HUD API passed to contributors. */\nexport interface HudDebugApi {\n  addLine(text: string): void;\n  isFlagEnabled(flag: string): boolean;\n  readonly screenWidth: number;\n  readonly screenHeight: number;\n}\n\n/** Rolling-window statistics collector. */\nexport interface StatsApi {\n  push(key: string, value: number): void;\n  average(key: string): number;\n  latest(key: string): number;\n  min(key: string): number;\n  max(key: string): number;\n}\n\n/** A debug contributor that registers drawing/sampling callbacks. */\nexport interface DebugContributor {\n  readonly name: string;\n  readonly flags: readonly string[];\n  drawWorld?(api: WorldDebugApi): void;\n  drawHud?(api: HudDebugApi): void;\n  sample?(stats: StatsApi, dt: number): void;\n  dispose?(): void;\n}\n\n/**\n * Supplies the vector to draw this frame, in the entity's world space. Return\n * `null` or `undefined` to draw nothing this frame.\n */\nexport type DebugVectorProvider = () => Vec2Like | null | undefined;\n\n/** Appearance and cutoff options for {@link DebugRegistry.drawVector}. */\nexport interface DebugVectorOptions {\n  /** Pixels of arrow per unit of the vector. Default 1. */\n  scale?: number;\n  /** Arrow color. Default `0xffffff`. */\n  color?: number;\n  /** Arrow opacity, 0-1. Default 0.9. */\n  alpha?: number;\n  /**\n   * World-space pixel offset added to the entity's position, so the arrow can\n   * start at a muzzle or a hand instead of the entity's origin. Not rotated by\n   * the entity. Default `{ x: 0, y: 0 }`.\n   */\n  origin?: Vec2Like;\n  /**\n   * Draw nothing while the vector is shorter than this. Measured on the value\n   * the provider returns, before `scale` is applied, so the cutoff is in the\n   * vector's own units (px/s for a velocity). Default 0 — a zero-length vector\n   * never draws either way, since it has no direction. */\n  minLength?: number;\n  /** Shaft thickness in screen pixels, held constant across camera zoom. Default 2. */\n  width?: number;\n  /** Arrowhead length in screen pixels, held constant across camera zoom. Default 8. */\n  headSize?: number;\n}\n\n/** Service interface for the debug registry. */\nexport interface DebugRegistry {\n  register(contributor: DebugContributor): void;\n  isEnabled(): boolean;\n  /** Switch all debug drawing on or off. */\n  toggle(): void;\n  isFlagEnabled(contributorName: string, flag: string): boolean;\n  /** Set whether a contributor's named view is drawn. */\n  setFlag(contributorName: string, flag: string, value: boolean): void;\n  /**\n   * Draw an arrow on `entity` for a vector that is read fresh every frame —\n   * velocity, aim direction, knockback, steering output.\n   *\n   * ```ts\n   * // tryResolve, not use(): use() throws without DebugPlugin installed.\n   * const debug = this.context.tryResolve(DebugRegistryKey);\n   * this.stopArrow = debug?.drawVector(this.entity, () => agent.velocity, {\n   *   scale: 0.35,\n   *   color: 0x4ade80,\n   *   minLength: 1,\n   * });\n   * ```\n   *\n   * The arrow starts at the entity's world position (plus `options.origin`)\n   * and points along the vector. Nothing is retained but the provider itself:\n   * it is called once per frame while the overlay is on and the `vectors`\n   * contributor's `arrows` flag is enabled, and not at all otherwise — a\n   * `drawVector` call in a hot path costs nothing while debug is off.\n   *\n   * Returns a disposer that stops the drawing. Calling it twice is harmless.\n   * The registration is also dropped when the entity's life ends — destroyed,\n   * or a pool member whose lease ended — so a provider closure never outlives\n   * the entity it draws for, and a per-lease registration never accumulates.\n   */\n  drawVector(\n    entity: Entity,\n    vector: DebugVectorProvider,\n    options?: DebugVectorOptions,\n  ): () => void;\n}\n\n/** Service key for resolving the DebugRegistry via DI. */\nexport const DebugRegistryKey = new ServiceKey<DebugRegistry>(\"debugRegistry\");\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA2B;AAgJpB,IAAM,mBAAmB,IAAI,uBAA0B,eAAe;","names":[]}