// src/registry.ts
var tokenizers = /* @__PURE__ */ new Map();
var profiles = /* @__PURE__ */ new Map();
var patternCache = /* @__PURE__ */ new Map();
function registerLanguage(code, tokenizer, profile) {
  tokenizers.set(code, tokenizer);
  profiles.set(code, profile);
  patternCache.delete(code);
}

// src/tokenizers/base.ts
var TokenStreamImpl = class {
  constructor(tokens, language) {
    this.pos = 0;
    this.tokens = tokens;
    this.language = language;
  }
  peek(offset = 0) {
    const index = this.pos + offset;
    if (index < 0 || index >= this.tokens.length) {
      return null;
    }
    return this.tokens[index];
  }
  advance() {
    if (this.isAtEnd()) {
      throw new Error("Unexpected end of token stream");
    }
    return this.tokens[this.pos++];
  }
  isAtEnd() {
    return this.pos >= this.tokens.length;
  }
  mark() {
    return { position: this.pos };
  }
  reset(mark) {
    this.pos = mark.position;
  }
  position() {
    return this.pos;
  }
  /**
   * Get remaining tokens as an array.
   */
  remaining() {
    return this.tokens.slice(this.pos);
  }
  /**
   * Consume tokens while predicate is true.
   */
  takeWhile(predicate) {
    const result = [];
    while (!this.isAtEnd() && predicate(this.peek())) {
      result.push(this.advance());
    }
    return result;
  }
  /**
   * Skip tokens while predicate is true.
   */
  skipWhile(predicate) {
    while (!this.isAtEnd() && predicate(this.peek())) {
      this.advance();
    }
  }
};
function createPosition(start, end) {
  return { start, end };
}
function createToken(value, kind, position, normalizedOrOptions) {
  if (typeof normalizedOrOptions === "string") {
    return { value, kind, position, normalized: normalizedOrOptions };
  }
  if (normalizedOrOptions) {
    const { normalized, stem, stemConfidence } = normalizedOrOptions;
    const token = { value, kind, position };
    if (normalized !== void 0) {
      token.normalized = normalized;
    }
    if (stem !== void 0) {
      token.stem = stem;
      if (stemConfidence !== void 0) {
        token.stemConfidence = stemConfidence;
      }
    }
    return token;
  }
  return { value, kind, position };
}
function isWhitespace(char) {
  return /\s/.test(char);
}
function isSelectorStart(char) {
  return char === "#" || char === "." || char === "[" || char === "@" || char === "*" || char === "<";
}
function isQuote(char) {
  return char === '"' || char === "'" || char === "`" || char === "\u300C" || char === "\u300D";
}
function isDigit(char) {
  return /\d/.test(char);
}
function isAsciiLetter(char) {
  return /[a-zA-Z]/.test(char);
}
function isAsciiIdentifierChar(char) {
  return /[a-zA-Z0-9_-]/.test(char);
}
function createLatinCharClassifiers(letterPattern) {
  const isLetter = (char) => letterPattern.test(char);
  const isIdentifierChar = (char) => isLetter(char) || /[0-9_-]/.test(char);
  return { isLetter, isIdentifierChar };
}
function extractCssSelector(input, startPos) {
  if (startPos >= input.length) return null;
  const char = input[startPos];
  if (!isSelectorStart(char)) return null;
  let pos = startPos;
  let selector = "";
  if (char === "#" || char === ".") {
    selector += input[pos++];
    while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
      selector += input[pos++];
    }
    if (selector.length <= 1) return null;
    if (pos < input.length && input[pos] === "." && char === "#") {
      const methodStart = pos + 1;
      let methodEnd = methodStart;
      while (methodEnd < input.length && isAsciiIdentifierChar(input[methodEnd])) {
        methodEnd++;
      }
      if (methodEnd < input.length && input[methodEnd] === "(") {
        return selector;
      }
    }
  } else if (char === "[") {
    let depth = 1;
    let inQuote = false;
    let quoteChar = null;
    let escaped = false;
    selector += input[pos++];
    while (pos < input.length && depth > 0) {
      const c = input[pos];
      selector += c;
      if (escaped) {
        escaped = false;
      } else if (c === "\\") {
        escaped = true;
      } else if (inQuote) {
        if (c === quoteChar) {
          inQuote = false;
          quoteChar = null;
        }
      } else {
        if (c === '"' || c === "'" || c === "`") {
          inQuote = true;
          quoteChar = c;
        } else if (c === "[") {
          depth++;
        } else if (c === "]") {
          depth--;
        }
      }
      pos++;
    }
    if (depth !== 0) return null;
  } else if (char === "@") {
    selector += input[pos++];
    while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
      selector += input[pos++];
    }
    if (selector.length <= 1) return null;
  } else if (char === "*") {
    selector += input[pos++];
    while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
      selector += input[pos++];
    }
    if (selector.length <= 1) return null;
  } else if (char === "<") {
    selector += input[pos++];
    if (pos >= input.length || !isAsciiLetter(input[pos])) return null;
    while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
      selector += input[pos++];
    }
    while (pos < input.length) {
      const modChar = input[pos];
      if (modChar === ".") {
        selector += input[pos++];
        if (pos >= input.length || !isAsciiIdentifierChar(input[pos])) {
          return null;
        }
        while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
          selector += input[pos++];
        }
      } else if (modChar === "#") {
        selector += input[pos++];
        if (pos >= input.length || !isAsciiIdentifierChar(input[pos])) {
          return null;
        }
        while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
          selector += input[pos++];
        }
      } else if (modChar === "[") {
        let depth = 1;
        let inQuote = false;
        let quoteChar = null;
        let escaped = false;
        selector += input[pos++];
        while (pos < input.length && depth > 0) {
          const c = input[pos];
          selector += c;
          if (escaped) {
            escaped = false;
          } else if (c === "\\") {
            escaped = true;
          } else if (inQuote) {
            if (c === quoteChar) {
              inQuote = false;
              quoteChar = null;
            }
          } else {
            if (c === '"' || c === "'" || c === "`") {
              inQuote = true;
              quoteChar = c;
            } else if (c === "[") {
              depth++;
            } else if (c === "]") {
              depth--;
            }
          }
          pos++;
        }
        if (depth !== 0) return null;
      } else {
        break;
      }
    }
    while (pos < input.length && isWhitespace(input[pos])) {
      selector += input[pos++];
    }
    if (pos < input.length && input[pos] === "/") {
      selector += input[pos++];
      while (pos < input.length && isWhitespace(input[pos])) {
        selector += input[pos++];
      }
    }
    if (pos >= input.length || input[pos] !== ">") return null;
    selector += input[pos++];
  }
  return selector || null;
}
function isPossessiveMarker(input, pos) {
  if (pos >= input.length || input[pos] !== "'") return false;
  if (pos + 1 >= input.length) return false;
  const nextChar = input[pos + 1].toLowerCase();
  if (nextChar !== "s") return false;
  if (pos + 2 >= input.length) return true;
  const afterS = input[pos + 2];
  return isWhitespace(afterS) || afterS === "*" || !isAsciiIdentifierChar(afterS);
}
function extractStringLiteral(input, startPos) {
  if (startPos >= input.length) return null;
  const openQuote = input[startPos];
  if (!isQuote(openQuote)) return null;
  if (openQuote === "'" && isPossessiveMarker(input, startPos)) {
    return null;
  }
  const closeQuoteMap = {
    '"': '"',
    "'": "'",
    "`": "`",
    "\u300C": "\u300D"
  };
  const closeQuote = closeQuoteMap[openQuote];
  if (!closeQuote) return null;
  let pos = startPos + 1;
  let literal = openQuote;
  let escaped = false;
  while (pos < input.length) {
    const char = input[pos];
    literal += char;
    if (escaped) {
      escaped = false;
    } else if (char === "\\") {
      escaped = true;
    } else if (char === closeQuote) {
      return literal;
    }
    pos++;
  }
  return literal;
}
function isUrlStart(input, pos) {
  if (pos >= input.length) return false;
  const char = input[pos];
  const next = input[pos + 1] || "";
  const third = input[pos + 2] || "";
  if (char === "/" && next !== "/" && /[a-zA-Z0-9._-]/.test(next)) {
    return true;
  }
  if (char === "/" && next === "/" && /[a-zA-Z]/.test(third)) {
    return true;
  }
  if (char === "." && (next === "/" || next === "." && third === "/")) {
    return true;
  }
  const slice = input.slice(pos, pos + 8).toLowerCase();
  if (slice.startsWith("http://") || slice.startsWith("https://")) {
    return true;
  }
  return false;
}
function extractUrl(input, startPos) {
  if (!isUrlStart(input, startPos)) return null;
  let pos = startPos;
  let url = "";
  const urlChars = /[a-zA-Z0-9/:._\-?&=%@+~!$'()*,;[\]]/;
  while (pos < input.length) {
    const char = input[pos];
    if (char === "#") {
      if (url.length > 0 && /[a-zA-Z0-9/.]$/.test(url)) {
        url += char;
        pos++;
        while (pos < input.length && /[a-zA-Z0-9_-]/.test(input[pos])) {
          url += input[pos++];
        }
      }
      break;
    }
    if (urlChars.test(char)) {
      url += char;
      pos++;
    } else {
      break;
    }
  }
  if (url.length < 2) return null;
  return url;
}
function extractNumber(input, startPos) {
  if (startPos >= input.length) return null;
  const char = input[startPos];
  if (!isDigit(char) && char !== "-" && char !== "+") return null;
  let pos = startPos;
  let number = "";
  if (input[pos] === "-" || input[pos] === "+") {
    number += input[pos++];
  }
  if (pos >= input.length || !isDigit(input[pos])) {
    return null;
  }
  while (pos < input.length && isDigit(input[pos])) {
    number += input[pos++];
  }
  if (pos < input.length && input[pos] === ".") {
    number += input[pos++];
    while (pos < input.length && isDigit(input[pos])) {
      number += input[pos++];
    }
  }
  if (pos < input.length) {
    const suffix = input.slice(pos, pos + 2);
    if (suffix === "ms") {
      number += "ms";
    } else if (input[pos] === "s" || input[pos] === "m" || input[pos] === "h") {
      number += input[pos];
    }
  }
  return number;
}
var _BaseTokenizer = class _BaseTokenizer {
  constructor() {
    /** Keywords derived from profile, sorted longest-first for greedy matching */
    this.profileKeywords = [];
    /** Map for O(1) keyword lookups by lowercase native word */
    this.profileKeywordMap = /* @__PURE__ */ new Map();
  }
  /**
   * Initialize keyword mappings from a language profile.
   * Builds a list of native→english mappings from:
   * - profile.keywords (primary + alternatives)
   * - profile.references (me, it, you, etc.)
   * - profile.roleMarkers (into, from, with, etc.)
   *
   * Results are sorted longest-first for greedy matching (important for non-space languages).
   * Extras take precedence over profile entries when there are duplicates.
   *
   * @param profile - Language profile containing keyword translations
   * @param extras - Additional keyword entries to include (literals, positional, events)
   */
  initializeKeywordsFromProfile(profile, extras = []) {
    const keywordMap = /* @__PURE__ */ new Map();
    if (profile.keywords) {
      for (const [normalized, translation] of Object.entries(profile.keywords)) {
        keywordMap.set(translation.primary, {
          native: translation.primary,
          normalized: translation.normalized || normalized
        });
        if (translation.alternatives) {
          for (const alt of translation.alternatives) {
            keywordMap.set(alt, {
              native: alt,
              normalized: translation.normalized || normalized
            });
          }
        }
      }
    }
    if (profile.references) {
      for (const [normalized, native] of Object.entries(profile.references)) {
        keywordMap.set(native, { native, normalized });
      }
    }
    if (profile.roleMarkers) {
      for (const [role, marker] of Object.entries(profile.roleMarkers)) {
        if (marker.primary) {
          keywordMap.set(marker.primary, { native: marker.primary, normalized: role });
        }
        if (marker.alternatives) {
          for (const alt of marker.alternatives) {
            keywordMap.set(alt, { native: alt, normalized: role });
          }
        }
      }
    }
    for (const extra of extras) {
      keywordMap.set(extra.native, extra);
    }
    this.profileKeywords = Array.from(keywordMap.values()).sort(
      (a, b) => b.native.length - a.native.length
    );
    this.profileKeywordMap = /* @__PURE__ */ new Map();
    for (const keyword of this.profileKeywords) {
      this.profileKeywordMap.set(keyword.native.toLowerCase(), keyword);
      const normalized = this.removeDiacritics(keyword.native);
      if (normalized !== keyword.native && !this.profileKeywordMap.has(normalized.toLowerCase())) {
        this.profileKeywordMap.set(normalized.toLowerCase(), keyword);
      }
    }
  }
  /**
   * Remove diacritical marks from a word for normalization.
   * Primarily for Arabic (shadda, fatha, kasra, damma, sukun, etc.)
   * but could be extended for other languages.
   *
   * @param word - Word to normalize
   * @returns Word without diacritics
   */
  removeDiacritics(word) {
    return word.replace(/[\u064B-\u0652\u0670]/g, "");
  }
  /**
   * Try to match a keyword from profile at the current position.
   * Uses longest-first greedy matching (important for non-space languages).
   *
   * @param input - Input string
   * @param pos - Current position
   * @returns Token if matched, null otherwise
   */
  tryProfileKeyword(input, pos) {
    for (const entry of this.profileKeywords) {
      if (input.slice(pos).startsWith(entry.native)) {
        return createToken(
          entry.native,
          "keyword",
          createPosition(pos, pos + entry.native.length),
          entry.normalized
        );
      }
    }
    return null;
  }
  /**
   * Check if the remaining input starts with any known keyword.
   * Useful for non-space languages to detect word boundaries.
   *
   * @param input - Input string
   * @param pos - Current position
   * @returns true if a keyword starts at this position
   */
  isKeywordStart(input, pos) {
    const remaining = input.slice(pos);
    return this.profileKeywords.some((entry) => remaining.startsWith(entry.native));
  }
  /**
   * Look up a keyword by native word (case-insensitive).
   * O(1) lookup using the keyword map.
   *
   * @param native - Native word to look up
   * @returns KeywordEntry if found, undefined otherwise
   */
  lookupKeyword(native) {
    return this.profileKeywordMap.get(native.toLowerCase());
  }
  /**
   * Check if a word is a known keyword (case-insensitive).
   * O(1) lookup using the keyword map.
   *
   * @param native - Native word to check
   * @returns true if the word is a keyword
   */
  isKeyword(native) {
    return this.profileKeywordMap.has(native.toLowerCase());
  }
  /**
   * Set the morphological normalizer for this tokenizer.
   */
  setNormalizer(normalizer) {
    this.normalizer = normalizer;
  }
  /**
   * Try to normalize a word using the morphological normalizer.
   * Returns null if no normalizer is set or normalization fails.
   *
   * Note: We don't check isNormalizable() here because the individual tokenizers
   * historically called normalize() directly without that check. The normalize()
   * method itself handles returning noChange() for words that can't be normalized.
   */
  tryNormalize(word) {
    if (!this.normalizer) return null;
    const result = this.normalizer.normalize(word);
    if (result.stem !== word && result.confidence >= 0.7) {
      return result;
    }
    return null;
  }
  /**
   * Try morphological normalization and keyword lookup.
   *
   * If the word can be normalized to a stem that matches a known keyword,
   * returns a keyword token with morphological metadata (stem, stemConfidence).
   *
   * This is the common pattern for handling conjugated verbs across languages:
   * 1. Normalize the word (e.g., "toggled" → "toggle")
   * 2. Look up the stem in the keyword map
   * 3. Create a token with both the original form and stem metadata
   *
   * @param word - The word to normalize and look up
   * @param startPos - Start position for the token
   * @param endPos - End position for the token
   * @returns Token if stem matches a keyword, null otherwise
   */
  tryMorphKeywordMatch(word, startPos, endPos) {
    const result = this.tryNormalize(word);
    if (!result) return null;
    const stemEntry = this.lookupKeyword(result.stem);
    if (!stemEntry) return null;
    const tokenOptions = {
      normalized: stemEntry.normalized,
      stem: result.stem,
      stemConfidence: result.confidence
    };
    return createToken(word, "keyword", createPosition(startPos, endPos), tokenOptions);
  }
  /**
   * Try to extract a CSS selector at the current position.
   */
  trySelector(input, pos) {
    const selector = extractCssSelector(input, pos);
    if (selector) {
      return createToken(selector, "selector", createPosition(pos, pos + selector.length));
    }
    return null;
  }
  /**
   * Try to extract an event modifier at the current position.
   * Event modifiers are .once, .debounce(N), .throttle(N), .queue(strategy)
   */
  tryEventModifier(input, pos) {
    if (input[pos] !== ".") {
      return null;
    }
    const match = input.slice(pos).match(/^\.(?:once|debounce|throttle|queue)(?:\(([^)]+)\))?(?:\s|$|\.)/);
    if (!match) {
      return null;
    }
    const fullMatch = match[0].replace(/(\s|\.)$/, "");
    const modifierName = fullMatch.slice(1).split("(")[0];
    const value = match[1];
    const token = createToken(
      fullMatch,
      "event-modifier",
      createPosition(pos, pos + fullMatch.length)
    );
    return {
      ...token,
      metadata: {
        modifierName,
        value: value ? modifierName === "queue" ? value : parseInt(value, 10) : void 0
      }
    };
  }
  /**
   * Try to extract a string literal at the current position.
   */
  tryString(input, pos) {
    const literal = extractStringLiteral(input, pos);
    if (literal) {
      return createToken(literal, "literal", createPosition(pos, pos + literal.length));
    }
    return null;
  }
  /**
   * Try to extract a number at the current position.
   */
  tryNumber(input, pos) {
    const number = extractNumber(input, pos);
    if (number) {
      return createToken(number, "literal", createPosition(pos, pos + number.length));
    }
    return null;
  }
  /**
   * Try to match a time unit from a list of patterns.
   *
   * @param input - Input string
   * @param pos - Position after the number
   * @param timeUnits - Array of time unit mappings (native pattern → standard suffix)
   * @param skipWhitespace - Whether to skip whitespace before time unit (default: false)
   * @returns Object with matched suffix and new position, or null if no match
   */
  tryMatchTimeUnit(input, pos, timeUnits, skipWhitespace = false) {
    let unitPos = pos;
    if (skipWhitespace) {
      while (unitPos < input.length && isWhitespace(input[unitPos])) {
        unitPos++;
      }
    }
    const remaining = input.slice(unitPos);
    for (const unit of timeUnits) {
      const candidate = remaining.slice(0, unit.length);
      const matches = unit.caseInsensitive ? candidate.toLowerCase() === unit.pattern.toLowerCase() : candidate === unit.pattern;
      if (matches) {
        if (unit.notFollowedBy) {
          const nextChar = remaining[unit.length] || "";
          if (nextChar === unit.notFollowedBy) continue;
        }
        if (unit.checkBoundary) {
          const nextChar = remaining[unit.length] || "";
          if (isAsciiIdentifierChar(nextChar)) continue;
        }
        return { suffix: unit.suffix, endPos: unitPos + unit.length };
      }
    }
    return null;
  }
  /**
   * Parse a base number (sign, integer, decimal) without time units.
   * Returns the number string and end position.
   *
   * @param input - Input string
   * @param startPos - Start position
   * @param allowSign - Whether to allow +/- sign (default: true)
   * @returns Object with number string and end position, or null
   */
  parseBaseNumber(input, startPos, allowSign = true) {
    let pos = startPos;
    let number = "";
    if (allowSign && (input[pos] === "-" || input[pos] === "+")) {
      number += input[pos++];
    }
    if (pos >= input.length || !isDigit(input[pos])) {
      return null;
    }
    while (pos < input.length && isDigit(input[pos])) {
      number += input[pos++];
    }
    if (pos < input.length && input[pos] === ".") {
      number += input[pos++];
      while (pos < input.length && isDigit(input[pos])) {
        number += input[pos++];
      }
    }
    if (!number || number === "-" || number === "+") return null;
    return { number, endPos: pos };
  }
  /**
   * Try to extract a number with native language time units.
   *
   * This is a template method that handles the common pattern:
   * 1. Parse the base number (sign, integer, decimal)
   * 2. Try to match native language time units
   * 3. Fall back to standard time units (ms, s, m, h)
   *
   * @param input - Input string
   * @param pos - Start position
   * @param nativeTimeUnits - Language-specific time unit mappings
   * @param options - Configuration options
   * @returns Token if number found, null otherwise
   */
  tryNumberWithTimeUnits(input, pos, nativeTimeUnits, options = {}) {
    const { allowSign = true, skipWhitespace = false } = options;
    const baseResult = this.parseBaseNumber(input, pos, allowSign);
    if (!baseResult) return null;
    let { number, endPos } = baseResult;
    const allUnits = [...nativeTimeUnits, ..._BaseTokenizer.STANDARD_TIME_UNITS];
    const timeMatch = this.tryMatchTimeUnit(input, endPos, allUnits, skipWhitespace);
    if (timeMatch) {
      number += timeMatch.suffix;
      endPos = timeMatch.endPos;
    }
    return createToken(number, "literal", createPosition(pos, endPos));
  }
  /**
   * Try to extract a URL at the current position.
   * Handles /path, ./path, ../path, //domain.com, http://, https://
   */
  tryUrl(input, pos) {
    const url = extractUrl(input, pos);
    if (url) {
      return createToken(url, "url", createPosition(pos, pos + url.length));
    }
    return null;
  }
  /**
   * Try to extract a variable reference (:varname) at the current position.
   * In hyperscript, :x refers to a local variable named x.
   */
  tryVariableRef(input, pos) {
    if (input[pos] !== ":") return null;
    if (pos + 1 >= input.length) return null;
    if (!isAsciiIdentifierChar(input[pos + 1])) return null;
    let endPos = pos + 1;
    while (endPos < input.length && isAsciiIdentifierChar(input[endPos])) {
      endPos++;
    }
    const varRef = input.slice(pos, endPos);
    return createToken(varRef, "identifier", createPosition(pos, endPos));
  }
  /**
   * Try to extract an operator or punctuation token at the current position.
   * Handles two-character operators (==, !=, etc.) and single-character operators.
   */
  tryOperator(input, pos) {
    const twoChar = input.slice(pos, pos + 2);
    if (["==", "!=", "<=", ">=", "&&", "||", "->"].includes(twoChar)) {
      return createToken(twoChar, "operator", createPosition(pos, pos + 2));
    }
    const oneChar = input[pos];
    if (["<", ">", "!", "+", "-", "*", "/", "="].includes(oneChar)) {
      return createToken(oneChar, "operator", createPosition(pos, pos + 1));
    }
    if (["(", ")", "{", "}", ",", ";", ":"].includes(oneChar)) {
      return createToken(oneChar, "punctuation", createPosition(pos, pos + 1));
    }
    return null;
  }
  /**
   * Try to match a multi-character particle from a list.
   *
   * Used by languages like Japanese, Korean, and Chinese that have
   * multi-character particles (e.g., Japanese から, まで, より).
   *
   * @param input - Input string
   * @param pos - Current position
   * @param particles - Array of multi-character particles to match
   * @returns Token if matched, null otherwise
   */
  tryMultiCharParticle(input, pos, particles) {
    for (const particle of particles) {
      if (input.slice(pos, pos + particle.length) === particle) {
        return createToken(particle, "particle", createPosition(pos, pos + particle.length));
      }
    }
    return null;
  }
};
/**
 * Configuration for native language time units.
 * Maps patterns to their standard suffix (ms, s, m, h).
 */
_BaseTokenizer.STANDARD_TIME_UNITS = [
  { pattern: "ms", suffix: "ms", length: 2 },
  { pattern: "s", suffix: "s", length: 1, checkBoundary: true },
  { pattern: "m", suffix: "m", length: 1, checkBoundary: true, notFollowedBy: "s" },
  { pattern: "h", suffix: "h", length: 1, checkBoundary: true }
];
var BaseTokenizer = _BaseTokenizer;

// src/generators/profiles/vietnamese.ts
var vietnameseProfile = {
  code: "vi",
  name: "Vietnamese",
  nativeName: "Ti\u1EBFng Vi\u1EC7t",
  direction: "ltr",
  wordOrder: "SVO",
  markingStrategy: "preposition",
  usesSpaces: true,
  // Vietnamese uses base/dictionary form for commands
  defaultVerbForm: "base",
  verb: {
    position: "start",
    subjectDrop: true
  },
  references: {
    me: "t\xF4i",
    // "I/me"
    it: "n\xF3",
    // "it"
    you: "b\u1EA1n",
    // "you"
    result: "k\u1EBFt qu\u1EA3",
    event: "s\u1EF1 ki\u1EC7n",
    target: "m\u1EE5c ti\xEAu",
    body: "body"
  },
  possessive: {
    marker: "c\u1EE7a",
    // Vietnamese uses "của" for possession (của tôi = my)
    markerPosition: "between",
    specialForms: {
      me: "c\u1EE7a t\xF4i",
      // "my"
      it: "c\u1EE7a n\xF3",
      // "its"
      you: "c\u1EE7a b\u1EA1n"
      // "your"
    },
    keywords: {
      // Multi-word possessive phrases
      // Note: These may require tokenizer support for multi-word recognition
      "c\u1EE7a t\xF4i": "me",
      // my
      "c\u1EE7a b\u1EA1n": "you",
      // your (informal)
      "c\u1EE7a anh": "you",
      // your (male speaker, formal)
      "c\u1EE7a ch\u1ECB": "you",
      // your (female speaker, formal)
      "c\u1EE7a n\xF3": "it"
      // its
    }
  },
  roleMarkers: {
    destination: { primary: "v\xE0o", alternatives: ["cho", "\u0111\u1EBFn"], position: "before" },
    source: { primary: "t\u1EEB", alternatives: ["kh\u1ECFi"], position: "before" },
    patient: { primary: "", position: "before" },
    style: { primary: "v\u1EDBi", position: "before" }
  },
  keywords: {
    // Class/Attribute operations
    toggle: { primary: "chuy\u1EC3n \u0111\u1ED5i", alternatives: ["b\u1EADt t\u1EAFt", "chuy\u1EC3n"], normalized: "toggle" },
    add: { primary: "th\xEAm", alternatives: ["b\u1ED5 sung"], normalized: "add" },
    remove: { primary: "x\xF3a", alternatives: ["g\u1EE1 b\u1ECF", "lo\u1EA1i b\u1ECF", "b\u1ECF"], normalized: "remove" },
    // Content operations
    put: { primary: "\u0111\u1EB7t", alternatives: ["\u0111\u1EC3", "\u0111\u01B0a"], normalized: "put" },
    append: { primary: "n\u1ED1i", normalized: "append" },
    prepend: { primary: "th\xEAm v\xE0o \u0111\u1EA7u", normalized: "prepend" },
    take: { primary: "l\u1EA5y", normalized: "take" },
    make: { primary: "t\u1EA1o", normalized: "make" },
    clone: { primary: "sao ch\xE9p", normalized: "clone" },
    swap: { primary: "ho\xE1n \u0111\u1ED5i", normalized: "swap" },
    morph: { primary: "bi\u1EBFn \u0111\u1ED5i", normalized: "morph" },
    // Variable operations
    set: { primary: "g\xE1n", alternatives: ["thi\u1EBFt l\u1EADp", "\u0111\u1EB7t"], normalized: "set" },
    get: { primary: "l\u1EA5y gi\xE1 tr\u1ECB", alternatives: ["nh\u1EADn", "l\u1EA5y"], normalized: "get" },
    increment: { primary: "t\u0103ng", alternatives: ["t\u0103ng l\xEAn"], normalized: "increment" },
    decrement: { primary: "gi\u1EA3m", alternatives: ["gi\u1EA3m \u0111i"], normalized: "decrement" },
    log: { primary: "in ra", normalized: "log" },
    // Visibility
    show: { primary: "hi\u1EC3n th\u1ECB", alternatives: ["hi\u1EC7n"], normalized: "show" },
    hide: { primary: "\u1EA9n", alternatives: ["che", "gi\u1EA5u"], normalized: "hide" },
    transition: { primary: "chuy\u1EC3n ti\u1EBFp", normalized: "transition" },
    // Events
    on: { primary: "khi", alternatives: ["l\xFAc", "tr\xEAn"], normalized: "on" },
    trigger: { primary: "k\xEDch ho\u1EA1t", normalized: "trigger" },
    send: { primary: "g\u1EEDi", normalized: "send" },
    // DOM focus
    focus: { primary: "t\u1EADp trung", normalized: "focus" },
    blur: { primary: "m\u1EA5t t\u1EADp trung", normalized: "blur" },
    // Common event names (for event handler patterns)
    click: { primary: "nh\u1EA5p", alternatives: ["b\u1EA5m"], normalized: "click" },
    hover: { primary: "di chu\u1ED9t", alternatives: ["r\xEA chu\u1ED9t"], normalized: "hover" },
    submit: { primary: "g\u1EEDi", alternatives: ["n\u1ED9p"], normalized: "submit" },
    input: { primary: "nh\u1EADp", alternatives: ["nh\u1EADp li\u1EC7u"], normalized: "input" },
    change: { primary: "thay \u0111\u1ED5i", alternatives: ["\u0111\u1ED5i"], normalized: "change" },
    // Navigation
    go: { primary: "\u0111i \u0111\u1EBFn", alternatives: ["\u0111i"], normalized: "go" },
    // Async
    wait: { primary: "ch\u1EDD", alternatives: ["\u0111\u1EE3i"], normalized: "wait" },
    fetch: { primary: "t\u1EA3i", normalized: "fetch" },
    settle: { primary: "\u1ED5n \u0111\u1ECBnh", normalized: "settle" },
    // Control flow
    if: { primary: "n\u1EBFu", normalized: "if" },
    when: { primary: "khi", normalized: "when" },
    where: { primary: "\u1EDF_\u0111\xE2u", normalized: "where" },
    else: { primary: "kh\xF4ng th\xEC", alternatives: ["n\u1EBFu kh\xF4ng"], normalized: "else" },
    repeat: { primary: "l\u1EB7p l\u1EA1i", normalized: "repeat" },
    for: { primary: "v\u1EDBi m\u1ED7i", normalized: "for" },
    while: { primary: "trong khi", normalized: "while" },
    continue: { primary: "ti\u1EBFp t\u1EE5c", normalized: "continue" },
    halt: { primary: "d\u1EEBng", alternatives: ["d\u1EEBng l\u1EA1i"], normalized: "halt" },
    throw: { primary: "n\xE9m", normalized: "throw" },
    call: { primary: "g\u1ECDi", normalized: "call" },
    return: { primary: "tr\u1EA3 v\u1EC1", normalized: "return" },
    then: { primary: "r\u1ED3i", alternatives: ["sau \u0111\xF3", "th\xEC"], normalized: "then" },
    and: { primary: "v\xE0", normalized: "and" },
    end: { primary: "k\u1EBFt th\xFAc", normalized: "end" },
    // Advanced
    js: { primary: "js", normalized: "js" },
    async: { primary: "b\u1EA5t \u0111\u1ED3ng b\u1ED9", normalized: "async" },
    tell: { primary: "n\xF3i v\u1EDBi", normalized: "tell" },
    default: { primary: "m\u1EB7c \u0111\u1ECBnh", normalized: "default" },
    init: { primary: "kh\u1EDFi t\u1EA1o", normalized: "init" },
    behavior: { primary: "h\xE0nh vi", normalized: "behavior" },
    install: { primary: "c\xE0i \u0111\u1EB7t", normalized: "install" },
    measure: { primary: "\u0111o l\u01B0\u1EDDng", normalized: "measure" },
    // Modifiers
    into: { primary: "v\xE0o", alternatives: ["v\xE0o trong"], normalized: "into" },
    before: { primary: "tr\u01B0\u1EDBc", alternatives: ["tr\u01B0\u1EDBc khi"], normalized: "before" },
    after: { primary: "sau", alternatives: ["sau khi"], normalized: "after" },
    // Event modifiers
    until: { primary: "cho \u0111\u1EBFn khi", normalized: "until" },
    event: { primary: "s\u1EF1 ki\u1EC7n", normalized: "event" },
    from: { primary: "t\u1EEB", alternatives: ["kh\u1ECFi"], normalized: "from" }
  },
  eventHandler: {
    keyword: { primary: "khi", alternatives: ["l\xFAc", "tr\xEAn"], normalized: "on" },
    sourceMarker: { primary: "tr\xEAn", alternatives: ["t\u1EA1i"], position: "before" },
    // Event marker: khi (when), used in SVO pattern
    // Pattern: khi [event] [verb] [patient] vào [destination?]
    // Example: khi nhấp chuyển đổi .active vào #button
    eventMarker: { primary: "khi", alternatives: ["l\xFAc"], position: "before" },
    temporalMarkers: ["khi", "l\xFAc"]
    // temporal conjunctions (when)
  }
};

// src/tokenizers/vietnamese.ts
var { isLetter: isVietnameseLetter, isIdentifierChar: isVietnameseIdentifierChar } = createLatinCharClassifiers(
  /[a-zA-ZàáảãạăằắẳẵặâầấẩẫậèéẻẽẹêềếểễệìíỉĩịòóỏõọôồốổỗộơờớởỡợùúủũụưừứửữựỳýỷỹỵđÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÈÉẺẼẸÊỀẾỂỄỆÌÍỈĨỊÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢÙÚỦŨỤƯỪỨỬỮỰỲÝỶỸỴĐ]/
);
var PREPOSITIONS = /* @__PURE__ */ new Set([
  "trong",
  // in, inside
  "ngo\xE0i",
  // outside
  "tr\xEAn",
  // on, above
  "d\u01B0\u1EDBi",
  // under, below
  "v\xE0o",
  // into
  "ra",
  // out
  "\u0111\u1EBFn",
  // to
  "t\u1EEB",
  // from
  "v\u1EDBi",
  // with
  "cho",
  // for, to
  "b\u1EDFi",
  // by
  "qua",
  // through
  "tr\u01B0\u1EDBc",
  // before
  "sau",
  // after
  "gi\u1EEFa",
  // between
  "b\xEAn",
  // beside
  "theo",
  // according to, along
  "v\u1EC1",
  // about, towards
  "t\u1EDBi",
  // to, towards
  "l\xEAn",
  // up
  "xu\u1ED1ng"
  // down
]);
var VIETNAMESE_EXTRAS = [
  // Values/Literals
  { native: "\u0111\xFAng", normalized: "true" },
  { native: "sai", normalized: "false" },
  { native: "null", normalized: "null" },
  { native: "kh\xF4ng x\xE1c \u0111\u1ECBnh", normalized: "undefined" },
  // Positional
  { native: "\u0111\u1EA7u ti\xEAn", normalized: "first" },
  { native: "cu\u1ED1i c\xF9ng", normalized: "last" },
  { native: "ti\u1EBFp theo", normalized: "next" },
  { native: "tr\u01B0\u1EDBc \u0111\xF3", normalized: "previous" },
  { native: "g\u1EA7n nh\u1EA5t", normalized: "closest" },
  { native: "cha", normalized: "parent" },
  // Events
  { native: "nh\u1EA5p", normalized: "click" },
  { native: "nh\u1EA5p chu\u1ED9t", normalized: "click" },
  { native: "click", normalized: "click" },
  { native: "nh\u1EA5p \u0111\xFAp", normalized: "dblclick" },
  { native: "nh\u1EADp", normalized: "input" },
  { native: "thay \u0111\u1ED5i", normalized: "change" },
  { native: "g\u1EEDi bi\u1EC3u m\u1EABu", normalized: "submit" },
  { native: "ph\xEDm xu\u1ED1ng", normalized: "keydown" },
  { native: "ph\xEDm l\xEAn", normalized: "keyup" },
  { native: "chu\u1ED9t v\xE0o", normalized: "mouseover" },
  { native: "chu\u1ED9t ra", normalized: "mouseout" },
  { native: "t\u1EA3i trang", normalized: "load" },
  { native: "cu\u1ED9n", normalized: "scroll" },
  // References - possessive forms
  { native: "c\u1EE7a t\xF4i", normalized: "my" },
  { native: "c\u1EE7a n\xF3", normalized: "its" },
  // Time units
  { native: "gi\xE2y", normalized: "s" },
  { native: "mili gi\xE2y", normalized: "ms" },
  { native: "ph\xFAt", normalized: "m" },
  { native: "gi\u1EDD", normalized: "h" },
  // Additional multi-word phrases not in profile
  { native: "th\xEAm v\xE0o cu\u1ED1i", normalized: "append" },
  { native: "nh\xE2n b\u1EA3n", normalized: "clone" },
  { native: "t\u1EA1o ra", normalized: "make" },
  { native: "\u0111\u1EB7t gi\xE1 tr\u1ECB", normalized: "set" },
  { native: "ghi nh\u1EADt k\xFD", normalized: "log" },
  { native: "chuy\u1EC3n t\u1EDBi", normalized: "go" },
  { native: "ng\u01B0\u1EE3c l\u1EA1i", normalized: "else" },
  { native: "l\u1EB7p", normalized: "repeat" },
  // Logical/conditional
  { native: "ho\u1EB7c", normalized: "or" },
  { native: "kh\xF4ng", normalized: "not" },
  { native: "l\xE0", normalized: "is" },
  { native: "t\u1ED3n t\u1EA1i", normalized: "exists" },
  { native: "r\u1ED7ng", normalized: "empty" },
  // English synonyms
  { native: "javascript", normalized: "js" }
];
var VietnameseTokenizer = class extends BaseTokenizer {
  constructor() {
    super();
    this.language = "vi";
    this.direction = "ltr";
    this.initializeKeywordsFromProfile(vietnameseProfile, VIETNAMESE_EXTRAS);
  }
  tokenize(input) {
    const tokens = [];
    let pos = 0;
    while (pos < input.length) {
      if (isWhitespace(input[pos])) {
        pos++;
        continue;
      }
      if (isSelectorStart(input[pos])) {
        const modifierToken = this.tryEventModifier(input, pos);
        if (modifierToken) {
          tokens.push(modifierToken);
          pos = modifierToken.position.end;
          continue;
        }
        const selectorToken = this.trySelector(input, pos);
        if (selectorToken) {
          tokens.push(selectorToken);
          pos = selectorToken.position.end;
          continue;
        }
      }
      if (isQuote(input[pos])) {
        const stringToken = this.tryString(input, pos);
        if (stringToken) {
          tokens.push(stringToken);
          pos = stringToken.position.end;
          continue;
        }
      }
      if (isUrlStart(input, pos)) {
        const urlToken = this.tryUrl(input, pos);
        if (urlToken) {
          tokens.push(urlToken);
          pos = urlToken.position.end;
          continue;
        }
      }
      if (isDigit(input[pos])) {
        const numberToken = this.extractVietnameseNumber(input, pos);
        if (numberToken) {
          tokens.push(numberToken);
          pos = numberToken.position.end;
          continue;
        }
      }
      const varToken = this.tryVariableRef(input, pos);
      if (varToken) {
        tokens.push(varToken);
        pos = varToken.position.end;
        continue;
      }
      const opToken = this.tryOperator(input, pos);
      if (opToken) {
        tokens.push(opToken);
        pos = opToken.position.end;
        continue;
      }
      const phraseToken = this.tryMultiWordPhrase(input, pos);
      if (phraseToken) {
        tokens.push(phraseToken);
        pos = phraseToken.position.end;
        continue;
      }
      if (isVietnameseLetter(input[pos])) {
        const wordToken = this.extractVietnameseWord(input, pos);
        if (wordToken) {
          tokens.push(wordToken);
          pos = wordToken.position.end;
          continue;
        }
      }
      pos++;
    }
    return new TokenStreamImpl(tokens, "vi");
  }
  classifyToken(token) {
    const lower = token.toLowerCase();
    if (PREPOSITIONS.has(lower)) return "particle";
    if (this.isKeyword(lower)) return "keyword";
    if (token.startsWith("#") || token.startsWith(".") || token.startsWith("[") || token.startsWith("<"))
      return "selector";
    if (token.startsWith('"') || token.startsWith("'")) return "literal";
    if (/^\d/.test(token)) return "literal";
    return "identifier";
  }
  /**
   * Try to match a multi-word phrase.
   * Multi-word phrases are included in profileKeywords and sorted longest-first.
   */
  tryMultiWordPhrase(input, pos) {
    for (const entry of this.profileKeywords) {
      if (!entry.native.includes(" ")) continue;
      const phrase = entry.native;
      const candidate = input.slice(pos, pos + phrase.length).toLowerCase();
      if (candidate === phrase.toLowerCase()) {
        const nextChar = input[pos + phrase.length];
        if (nextChar && isVietnameseLetter(nextChar)) continue;
        return createToken(
          input.slice(pos, pos + phrase.length),
          "keyword",
          createPosition(pos, pos + phrase.length),
          entry.normalized
        );
      }
    }
    return null;
  }
  /**
   * Extract a Vietnamese word (single syllable/word).
   */
  extractVietnameseWord(input, startPos) {
    let pos = startPos;
    let word = "";
    while (pos < input.length && isVietnameseIdentifierChar(input[pos])) {
      word += input[pos++];
    }
    if (!word) return null;
    const lower = word.toLowerCase();
    if (PREPOSITIONS.has(lower)) {
      return createToken(word, "particle", createPosition(startPos, pos));
    }
    const keywordEntry = this.lookupKeyword(lower);
    if (keywordEntry) {
      return createToken(word, "keyword", createPosition(startPos, pos), keywordEntry.normalized);
    }
    return createToken(word, "identifier", createPosition(startPos, pos));
  }
  /**
   * Extract a number, including time unit suffixes.
   */
  extractVietnameseNumber(input, startPos) {
    let pos = startPos;
    let number = "";
    while (pos < input.length && isDigit(input[pos])) {
      number += input[pos++];
    }
    if (pos < input.length && input[pos] === ".") {
      number += input[pos++];
      while (pos < input.length && isDigit(input[pos])) {
        number += input[pos++];
      }
    }
    if (pos < input.length) {
      const remaining = input.slice(pos).toLowerCase();
      if (remaining.startsWith(" mili gi\xE2y") || remaining.startsWith(" miligi\xE2y")) {
        number += "ms";
        pos += remaining.startsWith(" mili gi\xE2y") ? 10 : 9;
      } else if (remaining.startsWith(" gi\xE2y")) {
        number += "s";
        pos += 5;
      } else if (remaining.startsWith(" ph\xFAt")) {
        number += "m";
        pos += 5;
      } else if (remaining.startsWith(" gi\u1EDD")) {
        number += "h";
        pos += 4;
      } else if (remaining.startsWith("ms")) {
        number += "ms";
        pos += 2;
      } else if (remaining[0] === "s" && !isVietnameseLetter(remaining[1] || "")) {
        number += "s";
        pos += 1;
      } else if (remaining[0] === "m" && remaining[1] !== "s" && !isVietnameseLetter(remaining[1] || "")) {
        number += "m";
        pos += 1;
      } else if (remaining[0] === "h" && !isVietnameseLetter(remaining[1] || "")) {
        number += "h";
        pos += 1;
      }
    }
    if (!number) return null;
    return createToken(number, "literal", createPosition(startPos, pos));
  }
};
var vietnameseTokenizer = new VietnameseTokenizer();

// src/languages/vi.ts
registerLanguage("vi", vietnameseTokenizer, vietnameseProfile);
export {
  vietnameseProfile,
  vietnameseTokenizer
};
//# sourceMappingURL=vi.js.map