"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.char = char;
exports.char_ = char_;
exports.fromFile = fromFile;
exports.process = process;
exports.process_ = process_;
exports.zero = zero;

var C = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Collections/Immutable/Chunk"));

var Map = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Collections/Immutable/Map"));

var Set = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Collections/Immutable/Set"));

var E = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Either"));

var _Function = /*#__PURE__*/require("@effect-ts/core/Function");

var O = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect-ts/core/Option"));

var FC = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../FigCharacter/index.js"));

var SL = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("../SubLines/index.js"));

var _builder = /*#__PURE__*/require("./builder.js");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

// -----------------------------------------------------------------------------
// Operations
// -----------------------------------------------------------------------------

/**
 * Creates a new `FigFont` by parsing an input collection of lines representing
 * a Figlet font file.
 *
 * @param file The file that contains the `FigFont` definition.
 * @param lines A `Chunk` that contains all the lines representing an Figlet
 * font file that defines the `FigFont`.
 * @return A `FigletResult` containing the new `FigFont`, or a list of errors
 * accumulated during creation of the `FigFont`.
 */
function fromFile(file, lines) {
  return E.chain_(C.reduce_(C.zipWithIndex(lines), E.right(new _builder.FontBuilderState({
    file,
    header: O.none,
    commentLines: C.empty(),
    loadedNames: Set.empty,
    loadedChars: C.empty(),
    loadedCharLines: C.empty(),
    processTaggedFonts: false,
    hash: ""
  })), (state, {
    tuple: [line, index]
  }) => E.isLeft(state) ? state : (0, _builder.processLine)(state.right, line, index)), _builder.buildFont);
}
/**
 * The empty character (as in the Unicode character `"\u0000"`).
 */


function zero(self) {
  return new FC.FigCharacter({
    fontId: self.id,
    name: "\u0000",
    lines: SL.zero(self.header.height),
    endmark: "@",
    width: 0,
    comment: O.none,
    position: -1
  });
}
/**
 * Returns a `FigCharacter` representation of the given char.
 *
 * If the requested character is not present, the `FigCharacter` `"0"` (as in
 * Unicode character `"\u0000"`) will be returned instead.
 *
 * @param char The character to process into a `FigCharacter`.
 * @returns The `FigCharacter` that represent the given input character.
 */


function char_(self, char) {
  return O.getOrElse_(Map.lookup_(self.characters, char), () => zero(self));
}
/**
 * Returns a `FigCharacter` representation of the given char.
 *
 * If the requested character is not present, the `FigCharacter` `"0"` (as in
 * Unicode character `"\u0000"`) will be returned instead.
 *
 * @ets_data_first char_
 * @param char The character to process into a `FigCharacter`.
 * @returns The `FigCharacter` that represent the given input character.
 */


function char(char) {
  return self => char_(self, char);
}
/**
 * Retrieves the `FigFont` representation of a character as a string.
 *
 * @param char The character to process into a `FigCharacter` and render.
 * @returns The string representation of the `FigCharacter` that represents
 * the specified input character.
 */


function process_(self, char) {
  return SL.replace_(char_(self, char).lines, self.header.hardblank, " ").value;
}
/**
 * Retrieves the `FigFont` representation of a character as a string.
 *
 * @ets_data_first process_
 * @param char The character to process into a `FigCharacter` and render.
 * @returns The string representation of the `FigCharacter` that represents
 * the specified input character.
 */


function process(char) {
  return self => process_(self, char);
}
//# sourceMappingURL=operations.js.map