Files
il/resources/public/js/cljs-runtime/module$node_modules$pixi_DOT_js$lib$scene$text$shared$AbstractTextSystem.js
2026-07-01 22:38:29 -06:00

81 lines
5.0 KiB
JavaScript

shadow$provide.module$node_modules$pixi_DOT_js$lib$scene$text$shared$AbstractTextSystem = function(global, require, module, exports) {
var TexturePool = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$texture$TexturePool"), TextureStyle = require("module$node_modules$pixi_DOT_js$lib$rendering$renderers$shared$texture$TextureStyle"), deprecation = require("module$node_modules$pixi_DOT_js$lib$utils$logging$deprecation"), CanvasTextGenerator = require("module$node_modules$pixi_DOT_js$lib$scene$text$canvas$CanvasTextGenerator"), TextStyle = require("module$node_modules$pixi_DOT_js$lib$scene$text$TextStyle"),
getPo2TextureFromSource = require("module$node_modules$pixi_DOT_js$lib$scene$text$utils$getPo2TextureFromSource");
"use strict";
class AbstractTextSystem {
constructor(renderer, retainCanvasContext) {
this._activeTextures = {};
this._renderer = renderer;
this._retainCanvasContext = retainCanvasContext;
}
getTexture(options, _resolution, _style, _textKey) {
"string" === typeof options && (deprecation.deprecation("8.0.0", "CanvasTextSystem.getTexture: Use object TextOptions instead of separate arguments"), options = {text:options, style:_style, resolution:_resolution});
options.style instanceof TextStyle.TextStyle || (options.style = new TextStyle.TextStyle(options.style));
options.textureStyle instanceof TextureStyle.TextureStyle || (options.textureStyle = new TextureStyle.TextureStyle(options.textureStyle));
"string" !== typeof options.text && (options.text = options.text.toString());
const {text, style, textureStyle, autoGenerateMipmaps} = options;
_resolution = options.resolution ?? this._renderer.resolution;
const {frame, canvasAndContext} = CanvasTextGenerator.CanvasTextGenerator.getCanvasAndContext({text, style, resolution:_resolution});
options = getPo2TextureFromSource.getPo2TextureFromSource(canvasAndContext.canvas, frame.width, frame.height, _resolution, autoGenerateMipmaps);
textureStyle && (options.source.style = textureStyle);
style.trim && (frame.pad(style.padding), options.frame.copyFrom(frame), options.frame.scale(1 / _resolution), options.updateUvs());
if (style.filters) {
return _resolution = this._applyFilters(options, style.filters), this.returnTexture(options), CanvasTextGenerator.CanvasTextGenerator.returnCanvasAndContext(canvasAndContext), _resolution;
}
this._renderer.texture.initSource(options._source);
this._retainCanvasContext || CanvasTextGenerator.CanvasTextGenerator.returnCanvasAndContext(canvasAndContext);
return options;
}
returnTexture(texture) {
const source = texture.source, resource = source.resource;
if (this._retainCanvasContext && resource?.getContext) {
const context = resource.getContext("2d");
context && CanvasTextGenerator.CanvasTextGenerator.returnCanvasAndContext({canvas:resource, context});
}
source.resource = null;
source.uploadMethodId = "unknown";
source.alphaMode = "no-premultiply-alpha";
TexturePool.TexturePool.returnTexture(texture, !0);
}
renderTextToCanvas() {
deprecation.deprecation("8.10.0", "CanvasTextSystem.renderTextToCanvas: no longer supported, use CanvasTextSystem.getTexture instead");
}
getManagedTexture(text) {
text._resolution = text._autoResolution ? this._renderer.resolution : text.resolution;
const textKey = text.styleKey;
if (this._activeTextures[textKey]) {
return this._increaseReferenceCount(textKey), this._activeTextures[textKey].texture;
}
text = this.getTexture({text:text.text, style:text.style, resolution:text._resolution, textureStyle:text.textureStyle, autoGenerateMipmaps:text.autoGenerateMipmaps});
this._activeTextures[textKey] = {texture:text, usageCount:1};
return text;
}
decreaseReferenceCount(textKey) {
const activeTexture = this._activeTextures[textKey];
activeTexture && (activeTexture.usageCount--, 0 === activeTexture.usageCount && (this.returnTexture(activeTexture.texture), this._activeTextures[textKey] = null));
}
getReferenceCount(textKey) {
return this._activeTextures[textKey]?.usageCount ?? 0;
}
_increaseReferenceCount(textKey) {
this._activeTextures[textKey].usageCount++;
}
_applyFilters(texture, filters) {
const currentRenderTarget = this._renderer.renderTarget.renderTarget;
texture = this._renderer.filter.generateFilteredTexture({texture, filters});
this._renderer.renderTarget.bind(currentRenderTarget, !1);
return texture;
}
destroy() {
this._renderer = null;
for (const key in this._activeTextures) {
this._activeTextures[key] && this.returnTexture(this._activeTextures[key].texture);
}
this._activeTextures = null;
}
}
exports.AbstractTextSystem = AbstractTextSystem;
};
//# sourceMappingURL=module$node_modules$pixi_DOT_js$lib$scene$text$shared$AbstractTextSystem.js.map