shadow$provide.module$node_modules$pixi_DOT_js$lib$scene$text_html$HTMLTextSystem = function(global, require, module, exports) {
  global = require("module$node_modules$pixi_DOT_js$lib$extensions$Extensions");
  var CanvasPool = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$texture$CanvasPool"), TexturePool = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$texture$TexturePool"), types = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$types"), isSafari = require("module$node_modules$pixi_DOT_js$lib$utils$browser$isSafari"), warn = require("module$node_modules$pixi_DOT_js$lib$utils$logging$warn"), PoolGroup = require("module$node_modules$pixi_DOT_js$lib$utils$pool$PoolGroup"), 
  getPo2TextureFromSource = require("module$node_modules$pixi_DOT_js$lib$scene$text$utils$getPo2TextureFromSource"), HTMLTextRenderData = require("module$node_modules$pixi_DOT_js$lib$scene$text_html$HTMLTextRenderData"), extractFontFamilies = require("module$node_modules$pixi_DOT_js$lib$scene$text_html$utils$extractFontFamilies"), getFontCss = require("module$node_modules$pixi_DOT_js$lib$scene$text_html$utils$getFontCss"), getSVGUrl = require("module$node_modules$pixi_DOT_js$lib$scene$text_html$utils$getSVGUrl"), 
  getTemporaryCanvasFromImage = require("module$node_modules$pixi_DOT_js$lib$scene$text_html$utils$getTemporaryCanvasFromImage"), loadSVGImage = require("module$node_modules$pixi_DOT_js$lib$scene$text_html$utils$loadSVGImage"), measureHtmlText = require("module$node_modules$pixi_DOT_js$lib$scene$text_html$utils$measureHtmlText");
  "use strict";
  class HTMLTextSystem {
    constructor(renderer) {
      this._activeTextures = {};
      this._renderer = renderer;
      this._createCanvas = renderer.type === types.RendererType.WEBGPU;
    }
    getTexture(options) {
      return this.getTexturePromise(options);
    }
    getManagedTexture(text) {
      const textKey = text.styleKey;
      if (this._activeTextures[textKey]) {
        return this._increaseReferenceCount(textKey), this._activeTextures[textKey].promise;
      }
      text = this._buildTexturePromise(text).then(texture => this._activeTextures[textKey].texture = texture);
      this._activeTextures[textKey] = {texture:null, promise:text, usageCount:1};
      return text;
    }
    getReferenceCount(textKey) {
      return this._activeTextures[textKey]?.usageCount ?? null;
    }
    _increaseReferenceCount(textKey) {
      this._activeTextures[textKey].usageCount++;
    }
    decreaseReferenceCount(textKey) {
      const activeTexture = this._activeTextures[textKey];
      activeTexture && (activeTexture.usageCount--, 0 === activeTexture.usageCount && (activeTexture.texture ? this._cleanUp(activeTexture.texture) : activeTexture.promise.then(texture => {
        activeTexture.texture = texture;
        this._cleanUp(activeTexture.texture);
      }).catch(() => {
        warn.warn("HTMLTextSystem: Failed to clean texture");
      }), this._activeTextures[textKey] = null));
    }
    getTexturePromise(options) {
      return this._buildTexturePromise(options);
    }
    async _buildTexturePromise(options) {
      const {text, style, resolution, textureStyle, autoGenerateMipmaps} = options;
      options = PoolGroup.BigPool.get(HTMLTextRenderData.HTMLTextRenderData);
      var fontFamilies = extractFontFamilies.extractFontFamilies(text, style), fontCSS = await getFontCss.getFontCss(fontFamilies);
      const measured = measureHtmlText.measureHtmlText(text, style, fontCSS, options), height = Math.ceil(Math.ceil(Math.max(1, measured.height) + 2 * style.padding) * resolution), image = options.image;
      image.width = (Math.ceil(Math.ceil(Math.max(1, measured.width) + 2 * style.padding) * resolution) | 0) + 2;
      image.height = (height | 0) + 2;
      fontCSS = getSVGUrl.getSVGUrl(text, style, resolution, fontCSS, options);
      await loadSVGImage.loadSVGImage(image, fontCSS, isSafari.isSafari() && 0 < fontFamilies.length);
      let canvasAndContext;
      this._createCanvas && (canvasAndContext = getTemporaryCanvasFromImage.getTemporaryCanvasFromImage(image, resolution));
      fontFamilies = getPo2TextureFromSource.getPo2TextureFromSource(canvasAndContext ? canvasAndContext.canvas : image, image.width - 2, image.height - 2, resolution, autoGenerateMipmaps);
      textureStyle && (fontFamilies.source.style = textureStyle);
      this._createCanvas && (this._renderer.texture.initSource(fontFamilies.source), CanvasPool.CanvasPool.returnCanvasAndContext(canvasAndContext));
      PoolGroup.BigPool.return(options);
      return fontFamilies;
    }
    returnTexturePromise(texturePromise) {
      texturePromise.then(texture => {
        this._cleanUp(texture);
      }).catch(() => {
        warn.warn("HTMLTextSystem: Failed to clean texture");
      });
    }
    _cleanUp(texture) {
      TexturePool.TexturePool.returnTexture(texture, !0);
      texture.source.resource = null;
      texture.source.uploadMethodId = "unknown";
    }
    destroy() {
      this._renderer = null;
      for (const key in this._activeTextures) {
        this._activeTextures[key] && this.returnTexturePromise(this._activeTextures[key].promise);
      }
      this._activeTextures = null;
    }
  }
  HTMLTextSystem.extension = {type:[global.ExtensionType.WebGLSystem, global.ExtensionType.WebGPUSystem, global.ExtensionType.CanvasSystem], name:"htmlText"};
  exports.HTMLTextSystem = HTMLTextSystem;
};

//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$scene$text_html$HTMLTextSystem.js.map
