// 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: normalized2, stem, stemConfidence } = normalizedOrOptions;
    const token = { value, kind, position };
    if (normalized2 !== void 0) {
      token.normalized = normalized2;
    }
    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 [normalized2, translation] of Object.entries(profile.keywords)) {
        keywordMap.set(translation.primary, {
          native: translation.primary,
          normalized: translation.normalized || normalized2
        });
        if (translation.alternatives) {
          for (const alt of translation.alternatives) {
            keywordMap.set(alt, {
              native: alt,
              normalized: translation.normalized || normalized2
            });
          }
        }
      }
    }
    if (profile.references) {
      for (const [normalized2, native] of Object.entries(profile.references)) {
        keywordMap.set(native, { native, normalized: normalized2 });
      }
    }
    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 normalized2 = this.removeDiacritics(keyword.native);
      if (normalized2 !== keyword.native && !this.profileKeywordMap.has(normalized2.toLowerCase())) {
        this.profileKeywordMap.set(normalized2.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/tokenizers/morphology/types.ts
function noChange(word) {
  return { stem: word, confidence: 1 };
}
function normalized(stem, confidence, metadata) {
  if (metadata) {
    return { stem, confidence, metadata };
  }
  return { stem, confidence };
}

// src/tokenizers/morphology/turkish-normalizer.ts
function isTurkishLetter(char) {
  const code = char.charCodeAt(0);
  if (code >= 65 && code <= 90 || code >= 97 && code <= 122) {
    return true;
  }
  const turkishChars = "\xE7\xC7\u011F\u011E\u0131\u0130\xF6\xD6\u015F\u015E\xFC\xDC";
  return turkishChars.includes(char);
}
function containsTurkish(word) {
  for (const char of word) {
    if (isTurkishLetter(char)) return true;
  }
  return false;
}
function isBackVowel(char) {
  return "a\u0131ouAIOU".includes(char);
}
function isFrontVowel(char) {
  return "ei\xF6\xFCE\u0130\xD6\xDC".includes(char);
}
function isVowel(char) {
  return isBackVowel(char) || isFrontVowel(char);
}
function getLastVowel(word) {
  for (let i = word.length - 1; i >= 0; i--) {
    if (isVowel(word[i])) {
      return word[i];
    }
  }
  return null;
}
function matchesVowelHarmony(stem, suffix) {
  const stemLastVowel = getLastVowel(stem);
  if (!stemLastVowel) return true;
  const suffixFirstVowel = suffix.split("").find((c) => isVowel(c));
  if (!suffixFirstVowel) return true;
  if (isBackVowel(stemLastVowel)) {
    return isBackVowel(suffixFirstVowel);
  }
  return isFrontVowel(suffixFirstVowel);
}
var TURKISH_SUFFIX_RULES = [
  // Compound tense + person (longest patterns first)
  // Present continuous + person
  { pattern: "iyorsunuz", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\u0131yorsunuz", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\xFCyorsunuz", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "uyorsunuz", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "iyorsun", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\u0131yorsun", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\xFCyorsun", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "uyorsun", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "iyoruz", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\u0131yoruz", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\xFCyoruz", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "uyoruz", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "iyorum", confidence: 0.85, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\u0131yorum", confidence: 0.85, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\xFCyorum", confidence: 0.85, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "uyorum", confidence: 0.85, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "iyorlar", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\u0131yorlar", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\xFCyorlar", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "uyorlar", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  // Future tense + person
  { pattern: "eceksiniz", confidence: 0.82, conjugationType: "future", minStemLength: 2 },
  { pattern: "acaks\u0131n\u0131z", confidence: 0.82, conjugationType: "future", minStemLength: 2 },
  { pattern: "eceksin", confidence: 0.82, conjugationType: "future", minStemLength: 2 },
  { pattern: "acaks\u0131n", confidence: 0.82, conjugationType: "future", minStemLength: 2 },
  { pattern: "ece\u011Fiz", confidence: 0.82, conjugationType: "future", minStemLength: 2 },
  { pattern: "aca\u011F\u0131z", confidence: 0.82, conjugationType: "future", minStemLength: 2 },
  { pattern: "ece\u011Fim", confidence: 0.85, conjugationType: "future", minStemLength: 2 },
  { pattern: "aca\u011F\u0131m", confidence: 0.85, conjugationType: "future", minStemLength: 2 },
  { pattern: "ecekler", confidence: 0.82, conjugationType: "future", minStemLength: 2 },
  { pattern: "acaklar", confidence: 0.82, conjugationType: "future", minStemLength: 2 },
  // Reported past + person
  { pattern: "mi\u015Fsiniz", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "m\u0131\u015Fs\u0131n\u0131z", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "m\xFC\u015Fs\xFCn\xFCz", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "mu\u015Fsunuz", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "mi\u015Fsin", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "m\u0131\u015Fs\u0131n", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "m\xFC\u015Fs\xFCn", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "mu\u015Fsun", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "mi\u015Fiz", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "m\u0131\u015F\u0131z", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "m\xFC\u015F\xFCz", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "mu\u015Fuz", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "mi\u015Fim", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "m\u0131\u015F\u0131m", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "m\xFC\u015F\xFCm", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "mu\u015Fum", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "mi\u015Fler", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "m\u0131\u015Flar", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "m\xFC\u015Fler", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "mu\u015Flar", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  // Past tense + person
  { pattern: "diniz", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "d\u0131n\u0131z", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "d\xFCn\xFCz", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "dunuz", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "tiniz", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "t\u0131n\u0131z", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "t\xFCn\xFCz", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "tunuz", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "diler", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "d\u0131lar", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "d\xFCler", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "dular", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "tiler", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "t\u0131lar", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "t\xFCler", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "tular", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "din", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "d\u0131n", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "d\xFCn", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "dun", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "tin", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "t\u0131n", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "t\xFCn", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "tun", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "dik", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "d\u0131k", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "d\xFCk", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "duk", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "tik", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "t\u0131k", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "t\xFCk", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "tuk", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "dim", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "d\u0131m", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "d\xFCm", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "dum", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "tim", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "t\u0131m", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "t\xFCm", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "tum", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  // Present continuous (no person - 3rd person singular)
  { pattern: "iyor", confidence: 0.85, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\u0131yor", confidence: 0.85, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\xFCyor", confidence: 0.85, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "uyor", confidence: 0.85, conjugationType: "progressive", minStemLength: 2 },
  // Future (no person - 3rd person singular)
  { pattern: "ecek", confidence: 0.85, conjugationType: "future", minStemLength: 2 },
  { pattern: "acak", confidence: 0.85, conjugationType: "future", minStemLength: 2 },
  // Reported past (no person - 3rd person singular)
  { pattern: "mi\u015F", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "m\u0131\u015F", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "m\xFC\u015F", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "mu\u015F", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  // Simple past (no person - 3rd person singular)
  { pattern: "di", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "d\u0131", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "d\xFC", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "du", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "ti", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "t\u0131", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "t\xFC", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "tu", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  // Infinitive
  { pattern: "mek", confidence: 0.88, conjugationType: "dictionary", minStemLength: 2 },
  { pattern: "mak", confidence: 0.88, conjugationType: "dictionary", minStemLength: 2 },
  // Optative mood (let me/us...) - -eyim/-ayım/-elim/-alım
  { pattern: "eyelim", confidence: 0.82, conjugationType: "optative", minStemLength: 2 },
  { pattern: "ayal\u0131m", confidence: 0.82, conjugationType: "optative", minStemLength: 2 },
  { pattern: "eyim", confidence: 0.82, conjugationType: "optative", minStemLength: 2 },
  { pattern: "ay\u0131m", confidence: 0.82, conjugationType: "optative", minStemLength: 2 },
  { pattern: "elim", confidence: 0.82, conjugationType: "optative", minStemLength: 2 },
  { pattern: "al\u0131m", confidence: 0.82, conjugationType: "optative", minStemLength: 2 },
  // Necessitative (must/should) - -meli/-malı
  { pattern: "melisiniz", confidence: 0.82, conjugationType: "necessitative", minStemLength: 2 },
  { pattern: "mal\u0131s\u0131n\u0131z", confidence: 0.82, conjugationType: "necessitative", minStemLength: 2 },
  { pattern: "melisin", confidence: 0.82, conjugationType: "necessitative", minStemLength: 2 },
  { pattern: "mal\u0131s\u0131n", confidence: 0.82, conjugationType: "necessitative", minStemLength: 2 },
  { pattern: "meliyiz", confidence: 0.82, conjugationType: "necessitative", minStemLength: 2 },
  { pattern: "mal\u0131y\u0131z", confidence: 0.82, conjugationType: "necessitative", minStemLength: 2 },
  { pattern: "meliyim", confidence: 0.85, conjugationType: "necessitative", minStemLength: 2 },
  { pattern: "mal\u0131y\u0131m", confidence: 0.85, conjugationType: "necessitative", minStemLength: 2 },
  { pattern: "meliler", confidence: 0.82, conjugationType: "necessitative", minStemLength: 2 },
  { pattern: "mal\u0131lar", confidence: 0.82, conjugationType: "necessitative", minStemLength: 2 },
  { pattern: "meli", confidence: 0.85, conjugationType: "necessitative", minStemLength: 2 },
  { pattern: "mal\u0131", confidence: 0.85, conjugationType: "necessitative", minStemLength: 2 },
  // Ability (can) - -ebil/-abil + tense suffixes
  { pattern: "ebiliyor", confidence: 0.82, conjugationType: "potential", minStemLength: 2 },
  { pattern: "abiliyor", confidence: 0.82, conjugationType: "potential", minStemLength: 2 },
  { pattern: "ebilir", confidence: 0.85, conjugationType: "potential", minStemLength: 2 },
  { pattern: "abilir", confidence: 0.85, conjugationType: "potential", minStemLength: 2 },
  { pattern: "ebildi", confidence: 0.82, conjugationType: "potential", minStemLength: 2 },
  { pattern: "abildi", confidence: 0.82, conjugationType: "potential", minStemLength: 2 },
  { pattern: "ebilmek", confidence: 0.85, conjugationType: "potential", minStemLength: 2 },
  { pattern: "abilmek", confidence: 0.85, conjugationType: "potential", minStemLength: 2 },
  // Imperative (2nd person singular is just stem, 2nd person plural has suffix)
  { pattern: "iniz", confidence: 0.82, conjugationType: "imperative", minStemLength: 2 },
  { pattern: "\u0131n\u0131z", confidence: 0.82, conjugationType: "imperative", minStemLength: 2 },
  { pattern: "\xFCn\xFCz", confidence: 0.82, conjugationType: "imperative", minStemLength: 2 },
  { pattern: "unuz", confidence: 0.82, conjugationType: "imperative", minStemLength: 2 },
  { pattern: "in", confidence: 0.8, conjugationType: "imperative", minStemLength: 2 },
  { pattern: "\u0131n", confidence: 0.8, conjugationType: "imperative", minStemLength: 2 },
  { pattern: "\xFCn", confidence: 0.8, conjugationType: "imperative", minStemLength: 2 },
  { pattern: "un", confidence: 0.8, conjugationType: "imperative", minStemLength: 2 },
  // Passive voice
  { pattern: "ildi", confidence: 0.82, conjugationType: "passive", minStemLength: 2 },
  { pattern: "\u0131ld\u0131", confidence: 0.82, conjugationType: "passive", minStemLength: 2 },
  { pattern: "\xFCld\xFC", confidence: 0.82, conjugationType: "passive", minStemLength: 2 },
  { pattern: "uldu", confidence: 0.82, conjugationType: "passive", minStemLength: 2 },
  { pattern: "ilir", confidence: 0.82, conjugationType: "passive", minStemLength: 2 },
  { pattern: "\u0131l\u0131r", confidence: 0.82, conjugationType: "passive", minStemLength: 2 },
  { pattern: "\xFCl\xFCr", confidence: 0.82, conjugationType: "passive", minStemLength: 2 },
  { pattern: "ulur", confidence: 0.82, conjugationType: "passive", minStemLength: 2 },
  // Causative
  { pattern: "tirmek", confidence: 0.82, conjugationType: "causative", minStemLength: 2 },
  { pattern: "t\u0131rmak", confidence: 0.82, conjugationType: "causative", minStemLength: 2 },
  { pattern: "t\xFCrmek", confidence: 0.82, conjugationType: "causative", minStemLength: 2 },
  { pattern: "turmak", confidence: 0.82, conjugationType: "causative", minStemLength: 2 },
  { pattern: "dirmek", confidence: 0.82, conjugationType: "causative", minStemLength: 2 },
  { pattern: "d\u0131rmak", confidence: 0.82, conjugationType: "causative", minStemLength: 2 },
  { pattern: "d\xFCrmek", confidence: 0.82, conjugationType: "causative", minStemLength: 2 },
  { pattern: "durmak", confidence: 0.82, conjugationType: "causative", minStemLength: 2 },
  // Negation + tense combinations (very common)
  { pattern: "miyorsunuz", confidence: 0.8, conjugationType: "negative", minStemLength: 2 },
  { pattern: "m\u0131yorsunuz", confidence: 0.8, conjugationType: "negative", minStemLength: 2 },
  { pattern: "m\xFCyorsunuz", confidence: 0.8, conjugationType: "negative", minStemLength: 2 },
  { pattern: "muyorsunuz", confidence: 0.8, conjugationType: "negative", minStemLength: 2 },
  { pattern: "miyorsun", confidence: 0.8, conjugationType: "negative", minStemLength: 2 },
  { pattern: "m\u0131yorsun", confidence: 0.8, conjugationType: "negative", minStemLength: 2 },
  { pattern: "m\xFCyorsun", confidence: 0.8, conjugationType: "negative", minStemLength: 2 },
  { pattern: "muyorsun", confidence: 0.8, conjugationType: "negative", minStemLength: 2 },
  { pattern: "miyoruz", confidence: 0.8, conjugationType: "negative", minStemLength: 2 },
  { pattern: "m\u0131yoruz", confidence: 0.8, conjugationType: "negative", minStemLength: 2 },
  { pattern: "m\xFCyoruz", confidence: 0.8, conjugationType: "negative", minStemLength: 2 },
  { pattern: "muyoruz", confidence: 0.8, conjugationType: "negative", minStemLength: 2 },
  { pattern: "miyorum", confidence: 0.82, conjugationType: "negative", minStemLength: 2 },
  { pattern: "m\u0131yorum", confidence: 0.82, conjugationType: "negative", minStemLength: 2 },
  { pattern: "m\xFCyorum", confidence: 0.82, conjugationType: "negative", minStemLength: 2 },
  { pattern: "muyorum", confidence: 0.82, conjugationType: "negative", minStemLength: 2 },
  { pattern: "miyor", confidence: 0.82, conjugationType: "negative", minStemLength: 2 },
  { pattern: "m\u0131yor", confidence: 0.82, conjugationType: "negative", minStemLength: 2 },
  { pattern: "m\xFCyor", confidence: 0.82, conjugationType: "negative", minStemLength: 2 },
  { pattern: "muyor", confidence: 0.82, conjugationType: "negative", minStemLength: 2 },
  { pattern: "medi", confidence: 0.82, conjugationType: "negative", minStemLength: 2 },
  { pattern: "mad\u0131", confidence: 0.82, conjugationType: "negative", minStemLength: 2 },
  { pattern: "me", confidence: 0.75, conjugationType: "negative", minStemLength: 3 },
  { pattern: "ma", confidence: 0.75, conjugationType: "negative", minStemLength: 3 }
];
var TurkishMorphologicalNormalizer = class {
  constructor() {
    this.language = "tr";
  }
  /**
   * Check if a word might be a Turkish verb that can be normalized.
   */
  isNormalizable(word) {
    if (!containsTurkish(word)) return false;
    if (word.length < 3) return false;
    return true;
  }
  /**
   * Normalize a Turkish word to its stem form.
   */
  normalize(word) {
    const lowerWord = word.toLowerCase();
    for (const rule of TURKISH_SUFFIX_RULES) {
      if (lowerWord.endsWith(rule.pattern)) {
        const stem = lowerWord.slice(0, -rule.pattern.length);
        const minLength = rule.minStemLength ?? 2;
        if (stem.length < minLength) continue;
        if (!matchesVowelHarmony(stem, rule.pattern)) {
          const adjustedConfidence = rule.confidence * 0.9;
          const metadata2 = {
            removedSuffixes: [rule.pattern]
          };
          if (rule.conjugationType) {
            metadata2.conjugationType = rule.conjugationType;
          }
          return normalized(stem, adjustedConfidence, metadata2);
        }
        const metadata = {
          removedSuffixes: [rule.pattern]
        };
        if (rule.conjugationType) {
          metadata.conjugationType = rule.conjugationType;
        }
        return normalized(stem, rule.confidence, metadata);
      }
    }
    return noChange(word);
  }
};
var turkishMorphologicalNormalizer = new TurkishMorphologicalNormalizer();

// src/generators/profiles/turkish.ts
var turkishProfile = {
  code: "tr",
  name: "Turkish",
  nativeName: "T\xFCrk\xE7e",
  direction: "ltr",
  wordOrder: "SOV",
  markingStrategy: "case-suffix",
  usesSpaces: true,
  verb: {
    position: "end",
    suffixes: ["mek", "mak", "yor", "di", "mi\u015F"],
    subjectDrop: true
  },
  references: {
    me: "ben",
    // "I/me"
    it: "o",
    // "it"
    you: "sen",
    // "you"
    result: "sonu\xE7",
    event: "olay",
    target: "hedef",
    body: "g\xF6vde"
  },
  possessive: {
    marker: "",
    // Turkish uses genitive suffix -in/-ın + possessive suffix
    markerPosition: "after-object",
    usePossessiveAdjectives: true,
    specialForms: {
      me: "benim",
      // "my" (genitive of "ben")
      it: "onun",
      // "its"
      you: "senin"
      // "your"
    },
    keywords: {
      benim: "me",
      // my
      senin: "you",
      // your
      onun: "it"
      // its
    }
  },
  roleMarkers: {
    patient: {
      primary: "i",
      alternatives: ["\u0131", "u", "\xFC", "yi", "y\u0131", "yu", "y\xFC", "ni", "n\u0131", "nu", "n\xFC"],
      position: "after"
    },
    // Accusative (with buffer consonants y/n)
    destination: {
      primary: "e",
      // Include both dative (e/a) and genitive (ın/in/un/ün) for possessive patterns
      // Genitive is used in "X's Y" patterns: #button ın .active = "#button's .active"
      alternatives: [
        "a",
        "ye",
        "ya",
        "ne",
        "na",
        "de",
        "da",
        "te",
        "ta",
        "\u0131n",
        "in",
        "un",
        "\xFCn",
        "n\u0131n",
        "nin",
        "nun",
        "n\xFCn"
      ],
      position: "after"
    },
    // Dative/Locative + Genitive (with buffer consonants)
    source: { primary: "den", alternatives: ["dan", "ten", "tan"], position: "after" },
    // Ablative
    style: { primary: "le", alternatives: ["la", "yle", "yla"], position: "after" },
    // Instrumental
    event: { primary: "i", alternatives: ["\u0131", "u", "\xFC"], position: "after" }
    // Event as accusative
  },
  keywords: {
    // Class/Attribute operations
    toggle: { primary: "de\u011Fi\u015Ftir", alternatives: ["a\xE7/kapat"], normalized: "toggle" },
    add: { primary: "ekle", normalized: "add" },
    remove: { primary: "kald\u0131r", alternatives: ["sil"], normalized: "remove" },
    // Content operations
    put: { primary: "koy", normalized: "put" },
    append: { primary: "ekle", normalized: "append" },
    take: { primary: "tut", normalized: "take" },
    // al removed to avoid collision with get
    make: { primary: "yap", normalized: "make" },
    clone: { primary: "kopyala", normalized: "clone" },
    swap: { primary: "takas", normalized: "swap" },
    // Removed değiştir alternative to avoid collision with toggle
    morph: { primary: "d\xF6n\xFC\u015Ft\xFCr", alternatives: ["\u015Fekil de\u011Fi\u015Ftir"], normalized: "morph" },
    // Variable operations
    set: { primary: "ayarla", alternatives: ["yap", "belirle"], normalized: "set" },
    get: { primary: "al", normalized: "get" },
    increment: { primary: "art\u0131r", normalized: "increment" },
    decrement: { primary: "azalt", normalized: "decrement" },
    log: { primary: "kaydet", normalized: "log" },
    // Visibility
    show: { primary: "g\xF6ster", normalized: "show" },
    hide: { primary: "gizle", normalized: "hide" },
    transition: { primary: "ge\xE7i\u015F", normalized: "transition" },
    // Events
    on: { primary: "\xFCzerinde", alternatives: ["oldu\u011Funda", "zaman"], normalized: "on" },
    trigger: { primary: "tetikle", normalized: "trigger" },
    send: { primary: "g\xF6nder", normalized: "send" },
    // DOM focus
    focus: { primary: "odak", alternatives: ["odaklanma"], normalized: "focus" },
    blur: { primary: "bulan\u0131k", alternatives: ["bulan\u0131kl\u0131k"], normalized: "blur" },
    // Common event names (for event handler patterns)
    click: { primary: "t\u0131klama", alternatives: ["t\u0131kla"], normalized: "click" },
    hover: { primary: "\xFCzerine gelme", alternatives: ["\xFCzerinde gezinme"], normalized: "hover" },
    submit: { primary: "g\xF6nderme", alternatives: ["g\xF6nder"], normalized: "submit" },
    input: { primary: "giri\u015F", alternatives: ["girdi"], normalized: "input" },
    change: { primary: "de\u011Fi\u015Fiklik", alternatives: ["de\u011Fi\u015Fim"], normalized: "change" },
    // Navigation
    go: { primary: "git", normalized: "go" },
    // Async
    wait: { primary: "bekle", normalized: "wait" },
    fetch: { primary: "getir", normalized: "fetch" },
    settle: { primary: "sabitlen", normalized: "settle" },
    // Control flow
    if: { primary: "e\u011Fer", normalized: "if" },
    when: { primary: "iken", alternatives: ["durumunda", "oldu\u011Funda"], normalized: "when" },
    where: { primary: "nerede", normalized: "where" },
    else: { primary: "yoksa", normalized: "else" },
    repeat: { primary: "tekrarla", normalized: "repeat" },
    for: { primary: "i\xE7in", normalized: "for" },
    while: { primary: "iken", normalized: "while" },
    continue: { primary: "devam", normalized: "continue" },
    halt: { primary: "durdur", normalized: "halt" },
    throw: { primary: "f\u0131rlat", normalized: "throw" },
    call: { primary: "\xE7a\u011F\u0131r", normalized: "call" },
    return: { primary: "d\xF6n", normalized: "return" },
    then: { primary: "sonra", alternatives: ["ard\u0131ndan", "daha sonra"], normalized: "then" },
    and: { primary: "ve", alternatives: ["ayr\u0131ca", "hem de"], normalized: "and" },
    end: { primary: "son", alternatives: ["biti\u015F", "bitti"], normalized: "end" },
    // Advanced
    js: { primary: "js", normalized: "js" },
    async: { primary: "asenkron", normalized: "async" },
    tell: { primary: "s\xF6yle", normalized: "tell" },
    default: { primary: "varsay\u0131lan", normalized: "default" },
    init: { primary: "ba\u015Flat", normalized: "init" },
    behavior: { primary: "davran\u0131\u015F", normalized: "behavior" },
    install: { primary: "y\xFCkle", normalized: "install" },
    measure: { primary: "\xF6l\xE7", normalized: "measure" },
    // Modifiers
    into: { primary: "i\xE7ine", normalized: "into" },
    before: { primary: "\xF6nce", normalized: "before" },
    after: { primary: "sonra", normalized: "after" },
    // Event modifiers (for repeat until event)
    until: { primary: "kadar", normalized: "until" },
    event: { primary: "olay", normalized: "event" },
    from: { primary: "den", alternatives: ["dan"], normalized: "from" }
  },
  eventHandler: {
    // Event marker: da/de/ta/te (locative case suffix with vowel harmony), used in SOV pattern
    // Pattern: [event] da [patient] i [action]
    // Example: tıklama da .active i değiştir
    // Note: Vowel harmony variants (da/de/ta/te) should be handled by vowel harmony expansion
    eventMarker: { primary: "da", alternatives: ["de", "ta", "te"], position: "after" },
    temporalMarkers: ["d\u0131\u011F\u0131nda", "di\u011Finde"]
    // temporal converb suffixes (when)
  }
};

// src/tokenizers/turkish.ts
var { isLetter: isTurkishLetter2 } = createLatinCharClassifiers(/[a-zA-ZçÇğĞıİöÖşŞüÜ]/);
var POSTPOSITIONS = /* @__PURE__ */ new Set([
  "ile",
  // with
  "i\xE7in",
  // for
  "kadar",
  // until, as far as
  "gibi",
  // like
  "sonra",
  // after
  "\xF6nce",
  // before
  "\xFCzerinde",
  // on, above
  "alt\u0131nda",
  // under
  "i\xE7inde",
  // inside
  "d\u0131\u015F\u0131nda",
  // outside
  "aras\u0131nda",
  // between
  "kar\u015F\u0131",
  // against, towards
  "g\xF6re",
  // according to
  "ra\u011Fmen",
  // despite
  "do\u011Fru",
  // towards
  "boyunca"
  // along, throughout
]);
var CASE_SUFFIXES = /* @__PURE__ */ new Set([
  "de",
  "da",
  "te",
  "ta",
  // locative (at, in)
  "den",
  "dan",
  "ten",
  "tan",
  // ablative (from)
  "e",
  "a",
  "ye",
  "ya",
  // dative (to)
  "i",
  "\u0131",
  "u",
  "\xFC",
  // accusative (object)
  "in",
  "\u0131n",
  "un",
  "\xFCn",
  // genitive (of)
  "le",
  "la",
  "yle",
  "yla"
  // instrumental (with)
]);
var TURKISH_EXTRAS = [
  // Values/Literals
  { native: "do\u011Fru", normalized: "true" },
  { native: "dogru", normalized: "true" },
  { native: "yanl\u0131\u015F", normalized: "false" },
  { native: "yanlis", normalized: "false" },
  { native: "null", normalized: "null" },
  { native: "bo\u015F", normalized: "null" },
  { native: "bos", normalized: "null" },
  { native: "tan\u0131ms\u0131z", normalized: "undefined" },
  { native: "tanimsiz", normalized: "undefined" },
  // Positional
  { native: "ilk", normalized: "first" },
  { native: "son", normalized: "last" },
  { native: "sonraki", normalized: "next" },
  { native: "\xF6nceki", normalized: "previous" },
  { native: "onceki", normalized: "previous" },
  { native: "en_yak\u0131n", normalized: "closest" },
  { native: "en_yakin", normalized: "closest" },
  { native: "ebeveyn", normalized: "parent" },
  // Events
  { native: "t\u0131klama", normalized: "click" },
  { native: "tiklama", normalized: "click" },
  { native: "t\u0131k", normalized: "click" },
  { native: "tik", normalized: "click" },
  { native: "giri\u015F", normalized: "input" },
  { native: "giris", normalized: "input" },
  { native: "de\u011Fi\u015Fim", normalized: "change" },
  { native: "degisim", normalized: "change" },
  { native: "odak", normalized: "focus" },
  { native: "bulan\u0131k", normalized: "blur" },
  { native: "bulanik", normalized: "blur" },
  { native: "fare \xFCzerinde", normalized: "mouseover" },
  { native: "fare uzerinde", normalized: "mouseover" },
  { native: "fare d\u0131\u015F\u0131nda", normalized: "mouseout" },
  { native: "fare disinda", normalized: "mouseout" },
  { native: "kayd\u0131r", normalized: "scroll" },
  { native: "kaydir", normalized: "scroll" },
  { native: "tu\u015F_bas", normalized: "keydown" },
  { native: "tus_bas", normalized: "keydown" },
  { native: "tu\u015F_b\u0131rak", normalized: "keyup" },
  { native: "tus_birak", normalized: "keyup" },
  // References (possessive forms not in profile)
  { native: "benim", normalized: "my" },
  { native: "onun", normalized: "its" },
  // Time units
  { native: "saniye", normalized: "s" },
  { native: "milisaniye", normalized: "ms" },
  { native: "dakika", normalized: "m" },
  { native: "saat", normalized: "h" },
  // Logical
  { native: "ve", normalized: "and" },
  { native: "veya", normalized: "or" },
  { native: "de\u011Fil", normalized: "not" },
  { native: "degil", normalized: "not" }
  // Note: Command synonyms and diacritic-free variants should be in profile alternatives.
  // Event triggers (üzerinde, olduğunda) should be in profile as 'on' alternatives.
];
var TURKISH_TIME_UNITS = [
  { pattern: "milisaniye", suffix: "ms", length: 10, caseInsensitive: true },
  { pattern: "dakika", suffix: "m", length: 6, caseInsensitive: true },
  { pattern: "saniye", suffix: "s", length: 6, caseInsensitive: true },
  { pattern: "saat", suffix: "h", length: 4, caseInsensitive: true },
  { pattern: "dk", suffix: "m", length: 2, checkBoundary: true },
  // Common abbreviation for dakika
  { pattern: "sa", suffix: "h", length: 2, checkBoundary: true }
  // Common abbreviation for saat
];
var TurkishTokenizer = class extends BaseTokenizer {
  constructor() {
    super();
    this.language = "tr";
    this.direction = "ltr";
    this.initializeKeywordsFromProfile(turkishProfile, TURKISH_EXTRAS);
    this.normalizer = new TurkishMorphologicalNormalizer();
  }
  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.extractTurkishNumber(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 phraseToken = this.tryMultiWordPhrase(input, pos);
      if (phraseToken) {
        tokens.push(phraseToken);
        pos = phraseToken.position.end;
        continue;
      }
      if (isTurkishLetter2(input[pos])) {
        const wordToken = this.extractTurkishWord(input, pos);
        if (wordToken) {
          tokens.push(wordToken);
          pos = wordToken.position.end;
          continue;
        }
      }
      pos++;
    }
    return new TokenStreamImpl(tokens, "tr");
  }
  classifyToken(token) {
    const lower = token.toLowerCase();
    if (POSTPOSITIONS.has(lower)) return "particle";
    if (CASE_SUFFIXES.has(lower)) return "particle";
    if (this.isKeyword(lower)) return "keyword";
    if (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 multi-word phrases that function as single units.
   * Multi-word phrases are included in profileKeywords and sorted longest-first,
   * so they'll be matched before their constituent words.
   *
   * Examples: "üzerine gelme" (hover), "fare üzerinde" (mouseover)
   */
  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 nextPos = pos + phrase.length;
        if (nextPos >= input.length || isWhitespace(input[nextPos]) || !isTurkishLetter2(input[nextPos])) {
          return createToken(
            input.slice(pos, pos + phrase.length),
            "keyword",
            createPosition(pos, nextPos),
            entry.normalized
          );
        }
      }
    }
    return null;
  }
  /**
   * Extract a Turkish word.
   * Uses morphological normalization to handle verb conjugations.
   */
  extractTurkishWord(input, startPos) {
    let pos = startPos;
    let word = "";
    while (pos < input.length && (isTurkishLetter2(input[pos]) || input[pos] === "_")) {
      word += input[pos++];
    }
    if (!word) return null;
    const lowerWord = word.toLowerCase();
    if (CASE_SUFFIXES.has(lowerWord)) {
      return createToken(word, "particle", createPosition(startPos, pos));
    }
    if (POSTPOSITIONS.has(lowerWord)) {
      return createToken(word, "particle", createPosition(startPos, pos));
    }
    const keywordEntry = this.lookupKeyword(lowerWord);
    if (keywordEntry) {
      return createToken(word, "keyword", createPosition(startPos, pos), keywordEntry.normalized);
    }
    const morphToken = this.tryMorphKeywordMatch(lowerWord, startPos, pos);
    if (morphToken) return morphToken;
    return createToken(word, "identifier", createPosition(startPos, pos));
  }
  /**
   * Extract a number, including Turkish time unit suffixes.
   */
  extractTurkishNumber(input, startPos) {
    return this.tryNumberWithTimeUnits(input, startPos, TURKISH_TIME_UNITS, {
      allowSign: false,
      skipWhitespace: true
    });
  }
};
var turkishTokenizer = new TurkishTokenizer();

// src/languages/tr.ts
registerLanguage("tr", turkishTokenizer, turkishProfile);
export {
  turkishProfile,
  turkishTokenizer
};
//# sourceMappingURL=tr.js.map