{"version":3,"file":"texture-registry-oBuiVRIL.cjs","names":["svgToTexture"],"sources":["../../phaser/dist/utils/texture-registry.js"],"sourcesContent":["import { svgToTexture } from \"./svg-texture.js\";\nclass TextureRegistry {\n  // Map of scene -> textures in that scene\n  sceneTextures = /* @__PURE__ */ new Map();\n  /**\n   * Get or create texture map for a scene\n   */\n  getTextureMap(scene) {\n    let textures = this.sceneTextures.get(scene);\n    if (!textures) {\n      textures = /* @__PURE__ */ new Map();\n      this.sceneTextures.set(scene, textures);\n    }\n    return textures;\n  }\n  /**\n   * Request a texture in a specific scene, incrementing reference count\n   * Loads the texture if it's the first request in this scene\n   */\n  async requestTexture(scene, request) {\n    const { key } = request;\n    const textures = this.getTextureMap(scene);\n    let entry = textures.get(key);\n    if (!entry) {\n      entry = {\n        refCount: 0,\n        promise: null,\n        loaded: false\n      };\n      textures.set(key, entry);\n    }\n    entry.refCount++;\n    if (!entry.loaded && !entry.promise) {\n      entry.promise = svgToTexture(scene, request.key, request.svg, request.width, request.height).then(() => {\n        if (entry) {\n          entry.loaded = true;\n          entry.promise = null;\n        }\n      }).catch((err) => {\n        if (entry) {\n          entry.promise = null;\n        }\n        throw err;\n      });\n    }\n    if (entry.promise) {\n      await entry.promise;\n    }\n  }\n  /**\n   * Release a texture in a specific scene, decrementing reference count\n   * Removes the texture if reference count reaches zero\n   */\n  releaseTexture(scene, key) {\n    const textures = this.sceneTextures.get(scene);\n    if (!textures) return;\n    const entry = textures.get(key);\n    if (!entry) return;\n    entry.refCount--;\n    if (entry.refCount <= 0) {\n      if (scene.textures.exists(key)) {\n        scene.textures.remove(key);\n      }\n      textures.delete(key);\n    }\n  }\n  /**\n   * Check if a texture is loaded in a specific scene\n   */\n  isTextureLoaded(scene, key) {\n    const textures = this.sceneTextures.get(scene);\n    if (!textures) return false;\n    const entry = textures.get(key);\n    return entry?.loaded ?? false;\n  }\n  /**\n   * Get all loaded textures in a specific scene\n   */\n  getLoadedTextures(scene) {\n    const textures = this.sceneTextures.get(scene);\n    if (!textures) return [];\n    return Array.from(textures.entries()).filter(([, entry]) => entry.loaded).map(([key]) => key);\n  }\n  /**\n   * Release all textures in a specific scene\n   * Called automatically when scene shuts down\n   */\n  releaseScene(scene) {\n    const textures = this.sceneTextures.get(scene);\n    if (!textures) return;\n    for (const key of textures.keys()) {\n      if (scene.textures.exists(key)) {\n        scene.textures.remove(key);\n      }\n    }\n    this.sceneTextures.delete(scene);\n  }\n  /**\n   * Release all textures from all scenes\n   * Use with caution - removes all textures from all Phaser scenes\n   */\n  releaseAll() {\n    for (const [scene, textures] of this.sceneTextures.entries()) {\n      for (const key of textures.keys()) {\n        if (scene.textures.exists(key)) {\n          scene.textures.remove(key);\n        }\n      }\n    }\n    this.sceneTextures.clear();\n  }\n}\nconst textureRegistry = new TextureRegistry();\nexport {\n  textureRegistry\n};\n//# sourceMappingURL=texture-registry.js.map\n"],"mappings":";;AACA,IAAM,kBAAN,MAAsB;CAEpB,gCAAgC,IAAI,IAAI;;;;CAIxC,cAAc,OAAO;EACnB,IAAI,WAAW,KAAK,cAAc,IAAI,KAAK;EAC3C,IAAI,CAAC,UAAU;GACb,2BAA2B,IAAI,IAAI;GACnC,KAAK,cAAc,IAAI,OAAO,QAAQ;EACxC;EACA,OAAO;CACT;;;;;CAKA,MAAM,eAAe,OAAO,SAAS;EACnC,MAAM,EAAE,QAAQ;EAChB,MAAM,WAAW,KAAK,cAAc,KAAK;EACzC,IAAI,QAAQ,SAAS,IAAI,GAAG;EAC5B,IAAI,CAAC,OAAO;GACV,QAAQ;IACN,UAAU;IACV,SAAS;IACT,QAAQ;GACV;GACA,SAAS,IAAI,KAAK,KAAK;EACzB;EACA,MAAM;EACN,IAAI,CAAC,MAAM,UAAU,CAAC,MAAM,SAC1B,MAAM,UAAUA,aAAAA,aAAa,OAAO,QAAQ,KAAK,QAAQ,KAAK,QAAQ,OAAO,QAAQ,MAAM,EAAE,WAAW;GACtG,IAAI,OAAO;IACT,MAAM,SAAS;IACf,MAAM,UAAU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