"use strict";
const fs = require("fs");
const path = require("path");
const figlet = require("./figlet-DvMutUbn.cjs");
const url = require("url");
var _documentCurrentScript = typeof document !== "undefined" ? document.currentScript : null;
function _interopNamespaceDefault(e) {
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
  if (e) {
    for (const k in e) {
      if (k !== "default") {
        const d = Object.getOwnPropertyDescriptor(e, k);
        Object.defineProperty(n, k, d.get ? d : {
          enumerable: true,
          get: () => e[k]
        });
      }
    }
  }
  n.default = e;
  return Object.freeze(n);
}
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
const __filename$1 = url.fileURLToPath(typeof document === "undefined" ? require("url").pathToFileURL(__filename).href : _documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === "SCRIPT" && _documentCurrentScript.src || new URL("node-figlet.cjs", document.baseURI).href);
const __dirname$1 = path__namespace.dirname(__filename$1);
const fontPath = path__namespace.join(__dirname$1, "/../fonts/");
const nodeFiglet = figlet.figlet;
nodeFiglet.defaults({ fontPath });
nodeFiglet.loadFont = function(name, callback) {
  const actualFontName = figlet.getFontName(name);
  return new Promise((resolve, reject) => {
    if (nodeFiglet.figFonts[actualFontName]) {
      if (callback) {
        callback(null, nodeFiglet.figFonts[actualFontName].options);
      }
      resolve(nodeFiglet.figFonts[actualFontName].options);
      return;
    }
    fs__namespace.readFile(
      path__namespace.join(nodeFiglet.defaults().fontPath, actualFontName + ".flf"),
      { encoding: "utf-8" },
      (err, fontData) => {
        if (err) {
          if (callback) {
            callback(err);
          }
          reject(err);
          return;
        }
        fontData = fontData + "";
        try {
          const font = nodeFiglet.parseFont(
            actualFontName,
            fontData
          );
          if (callback) {
            callback(null, font);
          }
          resolve(font);
        } catch (error) {
          const typedError = error instanceof Error ? error : new Error(String(error));
          if (callback) {
            callback(typedError);
          }
          reject(typedError);
        }
      }
    );
  });
};
nodeFiglet.loadFontSync = function(font) {
  const actualFontName = figlet.getFontName(font);
  if (nodeFiglet.figFonts[actualFontName]) {
    return nodeFiglet.figFonts[actualFontName].options;
  }
  const fontData = fs__namespace.readFileSync(
    path__namespace.join(nodeFiglet.defaults().fontPath, actualFontName + ".flf"),
    {
      encoding: "utf-8"
    }
  ) + "";
  return nodeFiglet.parseFont(actualFontName, fontData);
};
nodeFiglet.fonts = function(next) {
  return new Promise((resolve, reject) => {
    const fontList = [];
    fs__namespace.readdir(
      nodeFiglet.defaults().fontPath,
      (err, files) => {
        if (err) {
          next && next(err);
          reject(err);
          return;
        }
        files.forEach((file) => {
          if (/\.flf$/.test(file)) {
            fontList.push(file.replace(/\.flf$/, ""));
          }
        });
        next && next(null, fontList);
        resolve(fontList);
      }
    );
  });
};
nodeFiglet.fontsSync = function() {
  const fontList = [];
  fs__namespace.readdirSync(nodeFiglet.defaults().fontPath).forEach((file) => {
    if (/\.flf$/.test(file)) {
      fontList.push(file.replace(/\.flf$/, ""));
    }
  });
  return fontList;
};
module.exports = nodeFiglet;
