"use strict";
var __getOwnPropNames = Object.getOwnPropertyNames;
var __commonJS = (cb, mod) => function __require() {
  return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
};

// node_modules/conventional-changelog-conventionalcommits/constants.js
var require_constants = __commonJS({
  "node_modules/conventional-changelog-conventionalcommits/constants.js"(exports2) {
    "use strict";
    var DEFAULT_COMMIT_TYPES = Object.freeze([
      { type: "feat", section: "Features" },
      { type: "feature", section: "Features" },
      { type: "fix", section: "Bug Fixes" },
      { type: "perf", section: "Performance Improvements" },
      { type: "revert", section: "Reverts" },
      { type: "docs", section: "Documentation", hidden: true },
      { type: "style", section: "Styles", hidden: true },
      { type: "chore", section: "Miscellaneous Chores", hidden: true },
      { type: "refactor", section: "Code Refactoring", hidden: true },
      { type: "test", section: "Tests", hidden: true },
      { type: "build", section: "Build System", hidden: true },
      { type: "ci", section: "Continuous Integration", hidden: true }
    ].map(Object.freeze));
    exports2.DEFAULT_COMMIT_TYPES = DEFAULT_COMMIT_TYPES;
  }
});

// node_modules/conventional-changelog-conventionalcommits/utils.js
var require_utils = __commonJS({
  "node_modules/conventional-changelog-conventionalcommits/utils.js"(exports2, module2) {
    var breakingHeaderPattern = /^(\w*)(?:\((.*)\))?!: (.*)$/;
    module2.exports.breakingHeaderPattern = breakingHeaderPattern;
    function addBangNotes(commit) {
      const match = commit.header.match(breakingHeaderPattern);
      if (match && commit.notes.length === 0) {
        const noteText = match[3];
        commit.notes.push({
          text: noteText
        });
      }
    }
    module2.exports.addBangNotes = addBangNotes;
  }
});

// node_modules/conventional-changelog-conventionalcommits/parserOpts.js
var require_parserOpts = __commonJS({
  "node_modules/conventional-changelog-conventionalcommits/parserOpts.js"(exports2, module2) {
    "use strict";
    var { breakingHeaderPattern } = require_utils();
    function createParserOpts(config) {
      return {
        headerPattern: /^(\w*)(?:\((.*)\))?!?: (.*)$/,
        breakingHeaderPattern,
        headerCorrespondence: [
          "type",
          "scope",
          "subject"
        ],
        noteKeywords: ["BREAKING CHANGE", "BREAKING-CHANGE"],
        revertPattern: /^(?:Revert|revert:)\s"?([\s\S]+?)"?\s*This reverts commit (\w*)\./i,
        revertCorrespondence: ["header", "hash"],
        issuePrefixes: config?.issuePrefixes || ["#"]
      };
    }
    module2.exports.createParserOpts = createParserOpts;
  }
});

// node_modules/array-ify/index.js
var require_array_ify = __commonJS({
  "node_modules/array-ify/index.js"(exports2, module2) {
    "use strict";
    module2.exports = function(val) {
      return Array.isArray(val) ? val : [val];
    };
  }
});

// node_modules/dot-prop/node_modules/is-obj/index.js
var require_is_obj = __commonJS({
  "node_modules/dot-prop/node_modules/is-obj/index.js"(exports2, module2) {
    "use strict";
    module2.exports = (value) => {
      const type = typeof value;
      return value !== null && (type === "object" || type === "function");
    };
  }
});

// node_modules/dot-prop/index.js
var require_dot_prop = __commonJS({
  "node_modules/dot-prop/index.js"(exports2, module2) {
    "use strict";
    var isObj = require_is_obj();
    var disallowedKeys = [
      "__proto__",
      "prototype",
      "constructor"
    ];
    var isValidPath = (pathSegments) => !pathSegments.some((segment) => disallowedKeys.includes(segment));
    function getPathSegments(path) {
      const pathArray = path.split(".");
      const parts = [];
      for (let i = 0; i < pathArray.length; i++) {
        let p = pathArray[i];
        while (p[p.length - 1] === "\\" && pathArray[i + 1] !== void 0) {
          p = p.slice(0, -1) + ".";
          p += pathArray[++i];
        }
        parts.push(p);
      }
      if (!isValidPath(parts)) {
        return [];
      }
      return parts;
    }
    module2.exports = {
      get(object, path, value) {
        if (!isObj(object) || typeof path !== "string") {
          return value === void 0 ? object : value;
        }
        const pathArray = getPathSegments(path);
        if (pathArray.length === 0) {
          return;
        }
        for (let i = 0; i < pathArray.length; i++) {
          if (!Object.prototype.propertyIsEnumerable.call(object, pathArray[i])) {
            return value;
          }
          object = object[pathArray[i]];
          if (object === void 0 || object === null) {
            if (i !== pathArray.length - 1) {
              return value;
            }
            break;
          }
        }
        return object;
      },
      set(object, path, value) {
        if (!isObj(object) || typeof path !== "string") {
          return object;
        }
        const root = object;
        const pathArray = getPathSegments(path);
        for (let i = 0; i < pathArray.length; i++) {
          const p = pathArray[i];
          if (!isObj(object[p])) {
            object[p] = {};
          }
          if (i === pathArray.length - 1) {
            object[p] = value;
          }
          object = object[p];
        }
        return root;
      },
      delete(object, path) {
        if (!isObj(object) || typeof path !== "string") {
          return false;
        }
        const pathArray = getPathSegments(path);
        for (let i = 0; i < pathArray.length; i++) {
          const p = pathArray[i];
          if (i === pathArray.length - 1) {
            delete object[p];
            return true;
          }
          object = object[p];
          if (!isObj(object)) {
            return false;
          }
        }
      },
      has(object, path) {
        if (!isObj(object) || typeof path !== "string") {
          return false;
        }
        const pathArray = getPathSegments(path);
        if (pathArray.length === 0) {
          return false;
        }
        for (let i = 0; i < pathArray.length; i++) {
          if (isObj(object)) {
            if (!(pathArray[i] in object)) {
              return false;
            }
            object = object[pathArray[i]];
          } else {
            return false;
          }
        }
        return true;
      }
    };
  }
});

// node_modules/compare-func/index.js
var require_compare_func = __commonJS({
  "node_modules/compare-func/index.js"(exports2, module2) {
    "use strict";
    var arrayify = require_array_ify();
    var dotPropGet = require_dot_prop().get;
    function compareFunc(prop) {
      return function(a, b) {
        var ret = 0;
        arrayify(prop).some(function(el) {
          var x;
          var y;
          if (typeof el === "function") {
            x = el(a);
            y = el(b);
          } else if (typeof el === "string") {
            x = dotPropGet(a, el);
            y = dotPropGet(b, el);
          } else {
            x = a;
            y = b;
          }
          if (x === y) {
            ret = 0;
            return;
          }
          if (typeof x === "string" && typeof y === "string") {
            ret = x.localeCompare(y);
            return ret !== 0;
          }
          ret = x < y ? -1 : 1;
          return true;
        });
        return ret;
      };
    }
    module2.exports = compareFunc;
  }
});

// node_modules/conventional-changelog-conventionalcommits/writerOpts.js
var require_writerOpts = __commonJS({
  "node_modules/conventional-changelog-conventionalcommits/writerOpts.js"(exports2, module2) {
    "use strict";
    var compareFunc = require_compare_func();
    var { readFile } = require("fs").promises;
    var { resolve } = require("path");
    var { DEFAULT_COMMIT_TYPES } = require_constants();
    var { addBangNotes } = require_utils();
    var releaseAsRegex = /release-as:\s*\w*@?([0-9]+\.[0-9]+\.[0-9a-z]+(-[0-9a-z.]+)?)\s*/i;
    var owner = "{{#if this.owner}}{{~this.owner}}{{else}}{{~@root.owner}}{{/if}}";
    var host = "{{~@root.host}}";
    var repository = "{{#if this.repository}}{{~this.repository}}{{else}}{{~@root.repository}}{{/if}}";
    async function createWriterOpts(config) {
      const finalConfig = {
        types: DEFAULT_COMMIT_TYPES,
        issueUrlFormat: "{{host}}/{{owner}}/{{repository}}/issues/{{id}}",
        commitUrlFormat: "{{host}}/{{owner}}/{{repository}}/commit/{{hash}}",
        compareUrlFormat: "{{host}}/{{owner}}/{{repository}}/compare/{{previousTag}}...{{currentTag}}",
        userUrlFormat: "{{host}}/{{user}}",
        issuePrefixes: ["#"],
        ...config
      };
      const commitUrlFormat = expandTemplate(finalConfig.commitUrlFormat, {
        host,
        owner,
        repository
      });
      const compareUrlFormat = expandTemplate(finalConfig.compareUrlFormat, {
        host,
        owner,
        repository
      });
      const issueUrlFormat = expandTemplate(finalConfig.issueUrlFormat, {
        host,
        owner,
        repository,
        id: "{{this.issue}}",
        prefix: "{{this.prefix}}"
      });
      const [
        template,
        header,
        commit,
        footer
      ] = await Promise.all([
        readFile(resolve(__dirname, "./templates/template.hbs"), "utf-8"),
        readFile(resolve(__dirname, "./templates/header.hbs"), "utf-8"),
        readFile(resolve(__dirname, "./templates/commit.hbs"), "utf-8"),
        readFile(resolve(__dirname, "./templates/footer.hbs"), "utf-8")
      ]);
      const writerOpts = getWriterOpts(finalConfig);
      writerOpts.mainTemplate = template;
      writerOpts.headerPartial = header.replace(/{{compareUrlFormat}}/g, compareUrlFormat);
      writerOpts.commitPartial = commit.replace(/{{commitUrlFormat}}/g, commitUrlFormat).replace(/{{issueUrlFormat}}/g, issueUrlFormat);
      writerOpts.footerPartial = footer;
      return writerOpts;
    }
    module2.exports.createWriterOpts = createWriterOpts;
    function getWriterOpts(config) {
      const commitGroupOrder = config.types.flatMap((t) => t.section).filter((t) => t);
      return {
        transform: (commit, context) => {
          let discard = true;
          const issues = [];
          const entry = findTypeEntry(config.types, commit);
          addBangNotes(commit);
          if (commit.footer && releaseAsRegex.test(commit.footer) || commit.body && releaseAsRegex.test(commit.body)) {
            discard = false;
          }
          commit.notes.forEach((note) => {
            note.title = "BREAKING CHANGES";
            discard = false;
          });
          if (discard && (entry === void 0 || entry.hidden))
            return;
          if (entry)
            commit.type = entry.section;
          if (commit.scope === "*") {
            commit.scope = "";
          }
          if (typeof commit.hash === "string") {
            commit.shortHash = commit.hash.substring(0, 7);
          }
          if (typeof commit.subject === "string") {
            config.issuePrefixes.join("|");
            const issueRegEx = "(" + config.issuePrefixes.join("|") + ")([a-z0-9]+)";
            const re = new RegExp(issueRegEx, "g");
            commit.subject = commit.subject.replace(re, (_, prefix, issue) => {
              issues.push(prefix + issue);
              const url = expandTemplate(config.issueUrlFormat, {
                host: context.host,
                owner: context.owner,
                repository: context.repository,
                id: issue,
                prefix
              });
              return `[${prefix}${issue}](${url})`;
            });
            commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, user) => {
              if (user.includes("/")) {
                return `@${user}`;
              }
              const usernameUrl = expandTemplate(config.userUrlFormat, {
                host: context.host,
                owner: context.owner,
                repository: context.repository,
                user
              });
              return `[@${user}](${usernameUrl})`;
            });
          }
          commit.references = commit.references.filter((reference) => {
            if (issues.indexOf(reference.prefix + reference.issue) === -1) {
              return true;
            }
            return false;
          });
          return commit;
        },
        groupBy: "type",
        // the groupings of commit messages, e.g., Features vs., Bug Fixes, are
        // sorted based on their probable importance:
        commitGroupsSort: (a, b) => {
          const gRankA = commitGroupOrder.indexOf(a.title);
          const gRankB = commitGroupOrder.indexOf(b.title);
          return gRankA - gRankB;
        },
        commitsSort: ["scope", "subject"],
        noteGroupsSort: "title",
        notesSort: compareFunc
      };
    }
    function findTypeEntry(types, commit) {
      const typeKey = (commit.revert ? "revert" : commit.type || "").toLowerCase();
      return types.find((entry) => {
        if (entry.type !== typeKey) {
          return false;
        }
        if (entry.scope && entry.scope !== commit.scope) {
          return false;
        }
        return true;
      });
    }
    function expandTemplate(template, context) {
      let expanded = template;
      Object.keys(context).forEach((key) => {
        expanded = expanded.replace(new RegExp(`{{${key}}}`, "g"), context[key]);
      });
      return expanded;
    }
  }
});

// node_modules/conventional-changelog-conventionalcommits/conventionalChangelog.js
var require_conventionalChangelog = __commonJS({
  "node_modules/conventional-changelog-conventionalcommits/conventionalChangelog.js"(exports2, module2) {
    "use strict";
    function createConventionalChangelogOpts(parserOpts, writerOpts) {
      return {
        parserOpts,
        writerOpts
      };
    }
    module2.exports.createConventionalChangelogOpts = createConventionalChangelogOpts;
  }
});

// node_modules/conventional-changelog-conventionalcommits/conventionalRecommendedBump.js
var require_conventionalRecommendedBump = __commonJS({
  "node_modules/conventional-changelog-conventionalcommits/conventionalRecommendedBump.js"(exports2, module2) {
    "use strict";
    var { addBangNotes } = require_utils();
    function createConventionalRecommendedBumpOpts(config, parserOpts) {
      return {
        parserOpts,
        whatBump(commits) {
          let level = 2;
          let breakings = 0;
          let features = 0;
          commits.forEach((commit) => {
            addBangNotes(commit);
            if (commit.notes.length > 0) {
              breakings += commit.notes.length;
              level = 0;
            } else if (commit.type === "feat" || commit.type === "feature") {
              features += 1;
              if (level === 2) {
                level = 1;
              }
            }
          });
          if (config?.preMajor && level < 2) {
            level++;
          }
          return {
            level,
            reason: breakings === 1 ? `There is ${breakings} BREAKING CHANGE and ${features} features` : `There are ${breakings} BREAKING CHANGES and ${features} features`
          };
        }
      };
    }
    module2.exports.createConventionalRecommendedBumpOpts = createConventionalRecommendedBumpOpts;
  }
});

// node_modules/conventional-changelog-conventionalcommits/index.js
var require_conventional_changelog_conventionalcommits = __commonJS({
  "node_modules/conventional-changelog-conventionalcommits/index.js"(exports2, module2) {
    "use strict";
    var { DEFAULT_COMMIT_TYPES } = require_constants();
    var { createParserOpts } = require_parserOpts();
    var { createWriterOpts } = require_writerOpts();
    var { createConventionalChangelogOpts } = require_conventionalChangelog();
    var { createConventionalRecommendedBumpOpts } = require_conventionalRecommendedBump();
    async function createPreset(config) {
      const parserOpts = createParserOpts(config);
      const writerOpts = await createWriterOpts(config);
      const recommendedBumpOpts = createConventionalRecommendedBumpOpts(config, parserOpts);
      const conventionalChangelog = createConventionalChangelogOpts(parserOpts, writerOpts);
      return {
        gitRawCommitsOpts: {
          ignore: config?.ignoreCommits,
          noMerges: null
        },
        parserOpts,
        writerOpts,
        recommendedBumpOpts,
        conventionalChangelog
      };
    }
    module2.exports = createPreset;
    module2.exports.DEFAULT_COMMIT_TYPES = DEFAULT_COMMIT_TYPES;
  }
});

// src/parser-preset.ts
module.exports = require_conventional_changelog_conventionalcommits();
