"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var input_exports = {};
__export(input_exports, {
  ESC: () => ESC,
  FOCUS_IN: () => FOCUS_IN,
  FOCUS_OUT: () => FOCUS_OUT,
  SGR_EVENT_PREFIX: () => SGR_EVENT_PREFIX,
  SGR_MOUSE_REGEX: () => SGR_MOUSE_REGEX,
  X11_EVENT_PREFIX: () => X11_EVENT_PREFIX,
  X11_MOUSE_REGEX: () => X11_MOUSE_REGEX,
  couldBeMouseSequence: () => couldBeMouseSequence,
  couldBeSGRMouseSequence: () => couldBeSGRMouseSequence,
  getMouseSequenceLength: () => getMouseSequenceLength
});
module.exports = __toCommonJS(input_exports);
const ESC = "\x1B";
const SGR_EVENT_PREFIX = `${ESC}[<`;
const X11_EVENT_PREFIX = `${ESC}[M`;
const FOCUS_IN = `${ESC}[I`;
const FOCUS_OUT = `${ESC}[O`;
const ESC_CHAR = String.fromCharCode(27);
const SGR_MOUSE_REGEX = new RegExp(`^${ESC_CHAR}\\[<(\\d+);(\\d+);(\\d+)([mM])`);
const X11_MOUSE_REGEX = new RegExp(`^${ESC_CHAR}\\[M([\\s\\S]{3})`);
function couldBeSGRMouseSequence(buffer) {
  if (buffer.length === 0) return true;
  if (SGR_EVENT_PREFIX.startsWith(buffer)) return true;
  if (buffer.startsWith(SGR_EVENT_PREFIX)) return true;
  return false;
}
function couldBeMouseSequence(buffer) {
  if (buffer.length === 0) return true;
  if (SGR_EVENT_PREFIX.startsWith(buffer) || buffer.startsWith(SGR_EVENT_PREFIX)) return true;
  if (X11_EVENT_PREFIX.startsWith(buffer) || buffer.startsWith(X11_EVENT_PREFIX)) return true;
  return false;
}
function getMouseSequenceLength(buffer) {
  const sgrMatch = buffer.match(SGR_MOUSE_REGEX);
  if (sgrMatch) return sgrMatch[0].length;
  const x11Match = buffer.match(X11_MOUSE_REGEX);
  if (x11Match) return x11Match[0].length;
  return 0;
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ESC,
  FOCUS_IN,
  FOCUS_OUT,
  SGR_EVENT_PREFIX,
  SGR_MOUSE_REGEX,
  X11_EVENT_PREFIX,
  X11_MOUSE_REGEX,
  couldBeMouseSequence,
  couldBeSGRMouseSequence,
  getMouseSequenceLength
});
