import { t as javascript } from "./javascript-DzigE11c.js";
var ATTRS_NEST = {
  "{": "}",
  "(": ")",
  "[": "]"
};
function defaultCopyState(_) {
  if (typeof _ != "object") return _;
  let U2 = {};
  for (let W in _) {
    let G = _[W];
    U2[W] = G instanceof Array ? G.slice() : G;
  }
  return U2;
}
var State = class U {
  constructor(U2) {
    this.indentUnit = U2, this.javaScriptLine = false, this.javaScriptLineExcludesColon = false, this.javaScriptArguments = false, this.javaScriptArgumentsDepth = 0, this.isInterpolating = false, this.interpolationNesting = 0, this.jsState = javascript.startState(U2), this.restOfLine = "", this.isIncludeFiltered = false, this.isEach = false, this.lastTag = "", this.isAttrs = false, this.attrsNest = [], this.inAttributeName = true, this.attributeIsType = false, this.attrValue = "", this.indentOf = Infinity, this.indentToken = "";
  }
  copy() {
    var G = new U(this.indentUnit);
    return G.javaScriptLine = this.javaScriptLine, G.javaScriptLineExcludesColon = this.javaScriptLineExcludesColon, G.javaScriptArguments = this.javaScriptArguments, G.javaScriptArgumentsDepth = this.javaScriptArgumentsDepth, G.isInterpolating = this.isInterpolating, G.interpolationNesting = this.interpolationNesting, G.jsState = (javascript.copyState || defaultCopyState)(this.jsState), G.restOfLine = this.restOfLine, G.isIncludeFiltered = this.isIncludeFiltered, G.isEach = this.isEach, G.lastTag = this.lastTag, G.isAttrs = this.isAttrs, G.attrsNest = this.attrsNest.slice(), G.inAttributeName = this.inAttributeName, G.attributeIsType = this.attributeIsType, G.attrValue = this.attrValue, G.indentOf = this.indentOf, G.indentToken = this.indentToken, G;
  }
};
function javaScript(U2, W) {
  if (U2.sol() && (W.javaScriptLine = false, W.javaScriptLineExcludesColon = false), W.javaScriptLine) {
    if (W.javaScriptLineExcludesColon && U2.peek() === ":") {
      W.javaScriptLine = false, W.javaScriptLineExcludesColon = false;
      return;
    }
    var G = javascript.token(U2, W.jsState);
    return U2.eol() && (W.javaScriptLine = false), G || true;
  }
}
function javaScriptArguments(U2, W) {
  if (W.javaScriptArguments) {
    if (W.javaScriptArgumentsDepth === 0 && U2.peek() !== "(") {
      W.javaScriptArguments = false;
      return;
    }
    if (U2.peek() === "(" ? W.javaScriptArgumentsDepth++ : U2.peek() === ")" && W.javaScriptArgumentsDepth--, W.javaScriptArgumentsDepth === 0) {
      W.javaScriptArguments = false;
      return;
    }
    return javascript.token(U2, W.jsState) || true;
  }
}
function yieldStatement(_) {
  if (_.match(/^yield\b/)) return "keyword";
}
function doctype(_) {
  if (_.match(/^(?:doctype) *([^\n]+)?/)) return "meta";
}
function interpolation(_, U2) {
  if (_.match("#{")) return U2.isInterpolating = true, U2.interpolationNesting = 0, "punctuation";
}
function interpolationContinued(U2, W) {
  if (W.isInterpolating) {
    if (U2.peek() === "}") {
      if (W.interpolationNesting--, W.interpolationNesting < 0) return U2.next(), W.isInterpolating = false, "punctuation";
    } else U2.peek() === "{" && W.interpolationNesting++;
    return javascript.token(U2, W.jsState) || true;
  }
}
function caseStatement(_, U2) {
  if (_.match(/^case\b/)) return U2.javaScriptLine = true, "keyword";
}
function when(_, U2) {
  if (_.match(/^when\b/)) return U2.javaScriptLine = true, U2.javaScriptLineExcludesColon = true, "keyword";
}
function defaultStatement(_) {
  if (_.match(/^default\b/)) return "keyword";
}
function extendsStatement(_, U2) {
  if (_.match(/^extends?\b/)) return U2.restOfLine = "string", "keyword";
}
function append(_, U2) {
  if (_.match(/^append\b/)) return U2.restOfLine = "variable", "keyword";
}
function prepend(_, U2) {
  if (_.match(/^prepend\b/)) return U2.restOfLine = "variable", "keyword";
}
function block(_, U2) {
  if (_.match(/^block\b *(?:(prepend|append)\b)?/)) return U2.restOfLine = "variable", "keyword";
}
function include(_, U2) {
  if (_.match(/^include\b/)) return U2.restOfLine = "string", "keyword";
}
function includeFiltered(_, U2) {
  if (_.match(/^include:([a-zA-Z0-9\-]+)/, false) && _.match("include")) return U2.isIncludeFiltered = true, "keyword";
}
function includeFilteredContinued(_, U2) {
  if (U2.isIncludeFiltered) {
    var W = filter(_, U2);
    return U2.isIncludeFiltered = false, U2.restOfLine = "string", W;
  }
}
function mixin(_, U2) {
  if (_.match(/^mixin\b/)) return U2.javaScriptLine = true, "keyword";
}
function call(_, U2) {
  if (_.match(/^\+([-\w]+)/)) return _.match(/^\( *[-\w]+ *=/, false) || (U2.javaScriptArguments = true, U2.javaScriptArgumentsDepth = 0), "variable";
  if (_.match("+#{", false)) return _.next(), U2.mixinCallAfter = true, interpolation(_, U2);
}
function callArguments(_, U2) {
  if (U2.mixinCallAfter) return U2.mixinCallAfter = false, _.match(/^\( *[-\w]+ *=/, false) || (U2.javaScriptArguments = true, U2.javaScriptArgumentsDepth = 0), true;
}
function conditional(_, U2) {
  if (_.match(/^(if|unless|else if|else)\b/)) return U2.javaScriptLine = true, "keyword";
}
function each(_, U2) {
  if (_.match(/^(- *)?(each|for)\b/)) return U2.isEach = true, "keyword";
}
function eachContinued(_, U2) {
  if (U2.isEach) {
    if (_.match(/^ in\b/)) return U2.javaScriptLine = true, U2.isEach = false, "keyword";
    if (_.sol() || _.eol()) U2.isEach = false;
    else if (_.next()) {
      for (; !_.match(/^ in\b/, false) && _.next(); ) ;
      return "variable";
    }
  }
}
function whileStatement(_, U2) {
  if (_.match(/^while\b/)) return U2.javaScriptLine = true, "keyword";
}
function tag(_, U2) {
  var W;
  if (W = _.match(/^(\w(?:[-:\w]*\w)?)\/?/)) return U2.lastTag = W[1].toLowerCase(), "tag";
}
function filter(_, U2) {
  if (_.match(/^:([\w\-]+)/)) return setStringMode(_, U2), "atom";
}
function code(_, U2) {
  if (_.match(/^(!?=|-)/)) return U2.javaScriptLine = true, "punctuation";
}
function id(_) {
  if (_.match(/^#([\w-]+)/)) return "builtin";
}
function className(_) {
  if (_.match(/^\.([\w-]+)/)) return "className";
}
function attrs(_, U2) {
  if (_.peek() == "(") return _.next(), U2.isAttrs = true, U2.attrsNest = [], U2.inAttributeName = true, U2.attrValue = "", U2.attributeIsType = false, "punctuation";
}
function attrsContinued(W, G) {
  if (G.isAttrs) {
    if (ATTRS_NEST[W.peek()] && G.attrsNest.push(ATTRS_NEST[W.peek()]), G.attrsNest[G.attrsNest.length - 1] === W.peek()) G.attrsNest.pop();
    else if (W.eat(")")) return G.isAttrs = false, "punctuation";
    if (G.inAttributeName && W.match(/^[^=,\)!]+/)) return (W.peek() === "=" || W.peek() === "!") && (G.inAttributeName = false, G.jsState = javascript.startState(2), G.lastTag === "script" && W.current().trim().toLowerCase() === "type" ? G.attributeIsType = true : G.attributeIsType = false), "attribute";
    var K = javascript.token(W, G.jsState);
    if (G.attrsNest.length === 0 && (K === "string" || K === "variable" || K === "keyword")) try {
      return Function("", "var x " + G.attrValue.replace(/,\s*$/, "").replace(/^!/, "")), G.inAttributeName = true, G.attrValue = "", W.backUp(W.current().length), attrsContinued(W, G);
    } catch {
    }
    return G.attrValue += W.current(), K || true;
  }
}
function attributesBlock(_, U2) {
  if (_.match(/^&attributes\b/)) return U2.javaScriptArguments = true, U2.javaScriptArgumentsDepth = 0, "keyword";
}
function indent(_) {
  if (_.sol() && _.eatSpace()) return "indent";
}
function comment(_, U2) {
  if (_.match(/^ *\/\/(-)?([^\n]*)/)) return U2.indentOf = _.indentation(), U2.indentToken = "comment", "comment";
}
function colon(_) {
  if (_.match(/^: */)) return "colon";
}
function text(_, U2) {
  if (_.match(/^(?:\| ?| )([^\n]+)/)) return "string";
  if (_.match(/^(<[^\n]*)/, false)) return setStringMode(_, U2), _.skipToEnd(), U2.indentToken;
}
function dot(_, U2) {
  if (_.eat(".")) return setStringMode(_, U2), "dot";
}
function fail(_) {
  return _.next(), null;
}
function setStringMode(_, U2) {
  U2.indentOf = _.indentation(), U2.indentToken = "string";
}
function restOfLine(_, U2) {
  if (_.sol() && (U2.restOfLine = ""), U2.restOfLine) {
    _.skipToEnd();
    var W = U2.restOfLine;
    return U2.restOfLine = "", W;
  }
}
function startState(_) {
  return new State(_);
}
function copyState(_) {
  return _.copy();
}
function nextToken(_, U2) {
  var W = restOfLine(_, U2) || interpolationContinued(_, U2) || includeFilteredContinued(_, U2) || eachContinued(_, U2) || attrsContinued(_, U2) || javaScript(_, U2) || javaScriptArguments(_, U2) || callArguments(_, U2) || yieldStatement(_) || doctype(_) || interpolation(_, U2) || caseStatement(_, U2) || when(_, U2) || defaultStatement(_) || extendsStatement(_, U2) || append(_, U2) || prepend(_, U2) || block(_, U2) || include(_, U2) || includeFiltered(_, U2) || mixin(_, U2) || call(_, U2) || conditional(_, U2) || each(_, U2) || whileStatement(_, U2) || tag(_, U2) || filter(_, U2) || code(_, U2) || id(_) || className(_) || attrs(_, U2) || attributesBlock(_, U2) || indent(_) || text(_, U2) || comment(_, U2) || colon(_) || dot(_, U2) || fail(_);
  return W === true ? null : W;
}
const pug = {
  startState,
  copyState,
  token: nextToken
};
export {
  pug as t
};
