{"version":3,"sources":["../src/api.ts","../src/types.ts","../src/SceneRenderTree.ts"],"sourcesContent":["export { RendererKey } from \"./types.js\";\nexport type { RendererConfig } from \"./types.js\";\nexport {\n  SceneRenderTreeKey,\n  SceneRenderTreeProviderKey,\n} from \"./SceneRenderTree.js\";\nexport type {\n  SceneRenderTree,\n  SceneRenderTreeProvider,\n} from \"./SceneRenderTree.js\";\nexport type { LayerDef } from \"./LayerDef.js\";\n","import { ServiceKey } from \"@yagejs/core\";\nimport type { RendererPlugin } from \"./RendererPlugin.js\";\nimport type { ApplicationOptions, TextStyle } from \"./public-types.js\";\n\n/** Service key for the RendererPlugin. */\nexport const RendererKey = new ServiceKey<RendererPlugin>(\"renderer\");\n\n/**\n * Scale mode for the responsive-fit API.\n * - `letterbox` — preserve aspect, fit inside the host, paint bars with the background color.\n * - `expand` — same scaling as `letterbox` (virtual rect always fully visible), but\n *   the bar region is left to the game to draw into. Pair with\n *   `RendererPlugin.extendedVirtualRects` / `visibleCanvasRect` to render fog, parallax,\n *   or a decorative backdrop into the extra space.\n * - `cover` — preserve aspect, fill the host; content overflows the virtual rect on the long axis.\n * - `stretch` — non-uniform scale; the virtual rect is squashed/pulled to match the host.\n */\nexport type FitMode = \"letterbox\" | \"expand\" | \"cover\" | \"stretch\";\n\n/** Options for the responsive-fit API. */\nexport interface RendererFitOptions {\n  /** Scale mode. See {@link FitMode}. */\n  mode: FitMode;\n  /**\n   * Element whose size the canvas matches. Defaults, in order:\n   * {@link RendererConfig.container}, then `canvas.parentElement`. If neither\n   * is available the controller falls back to a one-shot transform against\n   * the initial `width × height` and installs no `ResizeObserver` — pass\n   * `{ target: document.body }` explicitly for full-page fit.\n   */\n  target?: HTMLElement;\n}\n\n/** Configuration for the renderer plugin. */\nexport interface RendererConfig {\n  /** Initial canvas width in CSS pixels before responsive `fit` takes over. Backing-store size is `width × resolution`. */\n  width: number;\n  /** Initial canvas height in CSS pixels before responsive `fit` takes over. Backing-store size is `height × resolution`. */\n  height: number;\n  /** Game coordinate width (default: width). */\n  virtualWidth?: number;\n  /** Game coordinate height (default: height). */\n  virtualHeight?: number;\n  /** Background color as a hex number. */\n  backgroundColor?: number;\n  /** Existing canvas element to use. */\n  canvas?: HTMLCanvasElement;\n  /** Container element — canvas will be auto-appended here. */\n  container?: HTMLElement;\n  /** Device pixel ratio. Defaults to `window.devicePixelRatio` for crisp rendering on HiDPI displays. Set to 1 to disable. */\n  resolution?: number;\n  /** Additional PixiJS Application options. */\n  pixi?: Partial<ApplicationOptions>;\n  /**\n   * Responsive fit. Defaults to `{ mode: \"letterbox\" }` against the resolved\n   * target (see {@link RendererFitOptions.target}), so the canvas is\n   * responsive out of the box — override to change mode or pin to a specific\n   * host. See {@link RendererFitOptions}.\n   */\n  fit?: RendererFitOptions;\n  /**\n   * One-flag preset for pixel-art games. When `true`, the plugin:\n   *\n   * - Sets `TextureStyle.defaultOptions.scaleMode = \"nearest\"` so freshly\n   *   loaded textures sample without bilinear blur.\n   * - Enables `roundPixels` on the Pixi `Application` so subpixel transforms\n   *   don't smear sprite edges.\n   * - Applies `image-rendering: pixelated` (with `-webkit-optimize-contrast`\n   *   for Safari) to the canvas element so the browser scales the backing\n   *   store with nearest-neighbor, not bicubic.\n   *\n   * Composes with `pixi`: explicit `pixi.roundPixels: false` wins over the\n   * preset. Default: `false`.\n   */\n  pixelArtPreset?: boolean;\n  /**\n   * Engine-level default text style, applied as the base under every\n   * `TextComponent` / `UIText` `style` (per-text values win). Lets you set an\n   * app-wide font / fill without importing pixi to touch\n   * `TextStyle.defaultTextStyle`. `resolution` is not a style property — pass it\n   * per `TextComponent`. `@yagejs/ui`'s `UIPlugin({ defaultTextStyle })`\n   * can layer a UI-only override on top.\n   */\n  defaultTextStyle?: TextStyle;\n}\n","import { ServiceKey } from \"@yagejs/core\";\nimport type { Scene } from \"@yagejs/core\";\nimport type { LayerDef } from \"./LayerDef.js\";\nimport type { RenderLayer, CreateLayerOptions } from \"./RenderLayer.js\";\nimport type { EffectFactory } from \"./effects/Effect.js\";\nimport type { EffectHandle } from \"./effects/EffectHandle.js\";\nimport type { EffectsHost } from \"./effects/EffectsHost.js\";\nimport type { MaskFactory } from \"./masks/MaskFactory.js\";\nimport type { MaskHandle } from \"./masks/MaskHandle.js\";\nimport type { DisplayContainer } from \"./public-types.js\";\n\n/**\n * Options for `ensureLayer` beyond the declarative `LayerDef`. Used by\n * plugins (e.g. UI) to auto-provision screen-space layers so they stay\n * fixed to the viewport under the default camera.\n */\nexport type EnsureLayerOptions = Pick<\n  CreateLayerOptions,\n  \"space\" | \"eventMode\"\n>;\n\n/**\n * Scene-owned render tree. Created by `SceneRenderTreeProvider` when a scene\n * enters. Scoped DI: components resolve via `this.use(SceneRenderTreeKey)`.\n */\nexport interface SceneRenderTree {\n  /** The single root container for the scene. Lives under the renderer's\n   * world-root container (which sits under `app.stage` and holds the fit\n   * transform). */\n  readonly root: DisplayContainer;\n  /** Get a layer by name. Throws if not found. */\n  get(name: string): RenderLayer;\n  /** Get a layer by name, or undefined if not found. */\n  tryGet(name: string): RenderLayer | undefined;\n  /** All layers, sorted by draw order. */\n  getAll(): readonly RenderLayer[];\n  /** The auto-created \"default\" layer (order 0). */\n  readonly defaultLayer: RenderLayer;\n  /**\n   * Get an existing layer or create it from the given definition. Used by\n   * plugins like UI that auto-provision a layer if the game didn't declare\n   * one explicitly. Pass `{ space: \"screen\" }` so a default camera leaves\n   * the layer fixed to the viewport (e.g. screen-space HUD).\n   * Existing layers keep their settings. A differing requested order warns in\n   * development once per tree, layer name, and expected order.\n   */\n  ensureLayer(def: LayerDef, opts?: EnsureLayerOptions): RenderLayer;\n  /**\n   * Scene-scope effects host — `.fx.addEffect(...)` attaches a filter to the\n   * entire per-scene root container, after layer-scope effects have composited.\n   * Common use: scene-wide CRT, color grade, vignette. Survives until the\n   * scene exits or the handle is `.remove()`d.\n   *\n   * `.fx.findEffect(definition)` finds an attached effect when the caller no\n   * longer has its original handle.\n   */\n  readonly fx: EffectsHost;\n  /**\n   * Attach one effect to several layers and control it through one handle.\n   * The factory is called once per layer, so this is one filter pass per\n   * listed layer: N fullscreen layers cost N fullscreen passes per frame. For\n   * a single layer prefer `tree.get(name).fx.addEffect(...)`.\n   *\n   * Handle methods fan out to every layer; values (`enabled`, return values\n   * of extras such as `trigger`) come from the first listed layer. Layers\n   * with different camera bindings receive the same layer-local arguments.\n   * Throws when `layers` is empty or names a layer the scene does not have.\n   *\n   * ```ts\n   * const grade = tree.addLayerEffect(colorGrade({ preset: \"night\" }), [\n   *   \"background\",\n   *   \"world\",\n   *   \"props\",\n   * ]);\n   * grade.fadeOut(1); // fades on all three\n   * ```\n   */\n  addLayerEffect<H extends EffectHandle>(\n    factory: EffectFactory<H>,\n    layers: readonly string[],\n  ): H;\n  /**\n   * Attach a scene-scope mask, replacing any existing one. Clips the entire\n   * per-scene root. Torn down on scene exit.\n   */\n  setMask(factory: MaskFactory): MaskHandle;\n  /** Detach and destroy the scene-scope mask, if any. */\n  clearMask(): void;\n  /**\n   * Draw `node` after this scene's layers, outside every layer- and\n   * scene-scope effect and mask, while it keeps its logical parent (position,\n   * alpha, visibility, camera). Screen-scope effects still cover it. Draw\n   * order among nodes attached this way is attach order. `node` must be in\n   * this scene's tree.\n   *\n   * Visual components expose the same thing as\n   * `VisualComponentOptions.renderAboveEffects`; use this for a display\n   * object the game parents into the tree itself.\n   */\n  renderAboveEffects(node: DisplayContainer): void;\n  /** Undo `renderAboveEffects`. No-op when `node` is not attached. */\n  renderWithEffects(node: DisplayContainer): void;\n}\n\n/**\n * Provider that materializes and tears down per-scene render trees. Held\n * engine-globally so the inspector and renderer-owned tools can enumerate\n * trees.\n */\nexport interface SceneRenderTreeProvider {\n  createForScene(scene: Scene): SceneRenderTree;\n  destroyForScene(scene: Scene): void;\n  /** Look up the render tree for a given scene. */\n  getTree(scene: Scene): SceneRenderTree | undefined;\n  /** Iterate every live scene/tree pair. */\n  allTrees(): Iterable<[Scene, SceneRenderTree]>;\n  /** Reorder the scene's container to render on top of its root peers. */\n  bringSceneToFront?(scene: Scene): void;\n}\n\n/**\n * Engine-scope key for the render-tree provider. Used by cross-scene tools\n * (inspector, debug plugin, tests) to enumerate or ensure layers.\n */\nexport const SceneRenderTreeProviderKey =\n  new ServiceKey<SceneRenderTreeProvider>(\"sceneRenderTreeProvider\");\n\n/**\n * Scene-scope key for the active scene's render tree. Registered by the\n * renderer's `beforeEnter` hook; components resolve with `this.use()`.\n */\nexport const SceneRenderTreeKey = new ServiceKey<SceneRenderTree>(\n  \"sceneRenderTree\",\n  { scope: \"scene\" },\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kBAA2B;AAKpB,IAAM,cAAc,IAAI,uBAA2B,UAAU;;;ACLpE,IAAAA,eAA2B;AA4HpB,IAAM,6BACX,IAAI,wBAAoC,yBAAyB;AAM5D,IAAM,qBAAqB,IAAI;AAAA,EACpC;AAAA,EACA,EAAE,OAAO,QAAQ;AACnB;","names":["import_core"]}