// 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 createUnicodeRangeClassifier(ranges) {
  return (char) => {
    const code = char.charCodeAt(0);
    return ranges.some(([start, end]) => code >= start && code <= end);
  };
}
function combineClassifiers(...classifiers) {
  return (char) => classifiers.some((fn) => fn(char));
}
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/japanese-normalizer.ts
var JAPANESE_SUFFIX_RULES = [
  // Conditional forms - very common for event handlers (longest first)
  // したら/すると/すれば are する verb conditionals
  { pattern: "\u3057\u305F\u3089", confidence: 0.88, conjugationType: "conditional-tara", minStemLength: 2 },
  { pattern: "\u3059\u308B\u3068", confidence: 0.88, conjugationType: "conditional-to", minStemLength: 2 },
  { pattern: "\u3059\u308C\u3070", confidence: 0.85, conjugationType: "conditional-ba", minStemLength: 2 },
  // たら/れば are regular verb conditionals
  { pattern: "\u305F\u3089", confidence: 0.85, conjugationType: "conditional-tara", minStemLength: 2 },
  { pattern: "\u308C\u3070", confidence: 0.82, conjugationType: "conditional-ba", minStemLength: 2 },
  // Compound forms (longest first)
  { pattern: "\u3066\u3044\u307E\u3057\u305F", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  { pattern: "\u3066\u3044\u307E\u3059", confidence: 0.85, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\u3066\u304F\u3060\u3055\u3044", confidence: 0.85, conjugationType: "request", minStemLength: 2 },
  { pattern: "\u3067\u304F\u3060\u3055\u3044", confidence: 0.85, conjugationType: "request", minStemLength: 2 },
  { pattern: "\u3066\u3044\u308B", confidence: 0.85, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\u3066\u304A\u304F", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\u3066\u307F\u308B", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  { pattern: "\u3066\u3042\u308B", confidence: 0.82, conjugationType: "progressive", minStemLength: 2 },
  // Casual request forms
  { pattern: "\u3066\u304F\u308C", confidence: 0.8, conjugationType: "casual-request", minStemLength: 2 },
  { pattern: "\u3067\u304F\u308C", confidence: 0.8, conjugationType: "casual-request", minStemLength: 2 },
  // Contracted/colloquial forms (ちゃう/じゃう = てしまう/でしまう)
  { pattern: "\u3061\u3083\u3063\u305F", confidence: 0.82, conjugationType: "contracted-past", minStemLength: 2 },
  { pattern: "\u3058\u3083\u3063\u305F", confidence: 0.82, conjugationType: "contracted-past", minStemLength: 2 },
  { pattern: "\u3061\u3083\u3046", confidence: 0.82, conjugationType: "contracted", minStemLength: 2 },
  { pattern: "\u3058\u3083\u3046", confidence: 0.82, conjugationType: "contracted", minStemLength: 2 },
  // Polite forms
  { pattern: "\u307E\u3057\u305F", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  { pattern: "\u307E\u305B\u3093", confidence: 0.85, conjugationType: "negative", minStemLength: 2 },
  { pattern: "\u307E\u3059", confidence: 0.85, conjugationType: "polite", minStemLength: 2 },
  // て/た forms (very common)
  { pattern: "\u3066", confidence: 0.85, conjugationType: "te-form", minStemLength: 2 },
  { pattern: "\u305F", confidence: 0.85, conjugationType: "past", minStemLength: 2 },
  // Negative forms
  { pattern: "\u306A\u3044", confidence: 0.82, conjugationType: "negative", minStemLength: 2 },
  { pattern: "\u306A\u304B\u3063\u305F", confidence: 0.82, conjugationType: "past", minStemLength: 2 },
  // Potential forms
  { pattern: "\u3089\u308C\u308B", confidence: 0.8, conjugationType: "potential", minStemLength: 2 },
  { pattern: "\u308C\u308B", confidence: 0.78, conjugationType: "potential", minStemLength: 2 },
  // Passive forms
  { pattern: "\u3089\u308C\u305F", confidence: 0.8, conjugationType: "passive", minStemLength: 2 },
  // Causative forms
  { pattern: "\u3055\u305B\u308B", confidence: 0.8, conjugationType: "causative", minStemLength: 2 },
  { pattern: "\u305B\u308B", confidence: 0.78, conjugationType: "causative", minStemLength: 2 },
  // Volitional forms
  { pattern: "\u3088\u3046", confidence: 0.8, conjugationType: "volitional", minStemLength: 2 },
  // Dictionary form ending (る-verbs) - lower confidence due to ambiguity
  { pattern: "\u308B", confidence: 0.75, conjugationType: "dictionary", minStemLength: 3 }
];
var SURU_PATTERNS = [
  // Conditional forms (most important for native idioms)
  { pattern: "\u3057\u305F\u3089", confidence: 0.88, conjugationType: "conditional-tara" },
  { pattern: "\u3059\u308B\u3068", confidence: 0.88, conjugationType: "conditional-to" },
  { pattern: "\u3059\u308C\u3070", confidence: 0.85, conjugationType: "conditional-ba" },
  // Progressive forms
  { pattern: "\u3057\u3066\u3044\u307E\u3059", confidence: 0.85, conjugationType: "progressive" },
  { pattern: "\u3057\u3066\u3044\u308B", confidence: 0.85, conjugationType: "progressive" },
  // Other forms
  { pattern: "\u3057\u307E\u3057\u305F", confidence: 0.85, conjugationType: "past" },
  { pattern: "\u3057\u307E\u3059", confidence: 0.85, conjugationType: "polite" },
  { pattern: "\u3057\u306A\u3044", confidence: 0.82, conjugationType: "negative" },
  { pattern: "\u3057\u3066", confidence: 0.85, conjugationType: "te-form" },
  { pattern: "\u3057\u305F", confidence: 0.85, conjugationType: "past" },
  { pattern: "\u3059\u308B", confidence: 0.88, conjugationType: "dictionary" }
];
function isHiragana(char) {
  const code = char.charCodeAt(0);
  return code >= 12352 && code <= 12447;
}
function isKatakana(char) {
  const code = char.charCodeAt(0);
  return code >= 12448 && code <= 12543;
}
function isKanji(char) {
  const code = char.charCodeAt(0);
  return code >= 19968 && code <= 40959 || code >= 13312 && code <= 19903;
}
function containsJapanese(word) {
  for (const char of word) {
    if (isHiragana(char) || isKatakana(char) || isKanji(char)) {
      return true;
    }
  }
  return false;
}
var JapaneseMorphologicalNormalizer = class {
  constructor() {
    this.language = "ja";
  }
  /**
   * Check if a word might be a Japanese verb that can be normalized.
   */
  isNormalizable(word) {
    if (!containsJapanese(word)) return false;
    if (word.length < 2) return false;
    const lastChar = word[word.length - 1];
    return isHiragana(lastChar);
  }
  /**
   * Normalize a Japanese word to its stem form.
   */
  normalize(word) {
    const compoundResult = this.normalizeCompound(word);
    if (compoundResult) return compoundResult;
    const suruResult = this.trySuruNormalization(word);
    if (suruResult) return suruResult;
    for (const rule of JAPANESE_SUFFIX_RULES) {
      if (word.endsWith(rule.pattern)) {
        const stem = word.slice(0, -rule.pattern.length);
        const minLength = rule.minStemLength ?? 2;
        if (stem.length < minLength) continue;
        const metadata = {
          removedSuffixes: [rule.pattern]
        };
        if (rule.conjugationType) {
          metadata.conjugationType = rule.conjugationType;
        }
        return normalized(stem, rule.confidence, metadata);
      }
    }
    return noChange(word);
  }
  /**
   * Try to normalize a する verb.
   */
  trySuruNormalization(word) {
    for (const pattern of SURU_PATTERNS) {
      if (word.endsWith(pattern.pattern)) {
        const stem = word.slice(0, -pattern.pattern.length);
        if (stem.length < 1) continue;
        return normalized(stem, pattern.confidence, {
          removedSuffixes: [pattern.pattern],
          conjugationType: pattern.conjugationType,
          originalForm: "suru-verb"
        });
      }
    }
    return null;
  }
  /**
   * Normalize compound conjugations (multi-layer suffixes).
   * These are combinations like ていなかった (was not doing), でいない (is not doing).
   * Handles cases that single-suffix rules miss.
   */
  normalizeCompound(word) {
    const compoundPatterns = [
      // Progressive negative past forms
      {
        pattern: "\u3066\u3044\u306A\u304B\u3063\u305F",
        suffixes: ["\u3066", "\u3044", "\u306A\u304B\u3063\u305F"],
        confidence: 0.8,
        minStemLength: 2
      },
      {
        pattern: "\u3067\u3044\u306A\u304B\u3063\u305F",
        suffixes: ["\u3067", "\u3044", "\u306A\u304B\u3063\u305F"],
        confidence: 0.8,
        minStemLength: 2
      },
      // Progressive negative forms
      { pattern: "\u3066\u3044\u306A\u3044", suffixes: ["\u3066", "\u3044", "\u306A\u3044"], confidence: 0.82, minStemLength: 2 },
      { pattern: "\u3067\u3044\u306A\u3044", suffixes: ["\u3067", "\u3044", "\u306A\u3044"], confidence: 0.82, minStemLength: 2 },
      // Progressive past forms
      { pattern: "\u3066\u3044\u305F", suffixes: ["\u3066", "\u3044", "\u305F"], confidence: 0.85, minStemLength: 2 },
      { pattern: "\u3067\u3044\u305F", suffixes: ["\u3067", "\u3044", "\u305F"], confidence: 0.85, minStemLength: 2 }
    ];
    for (const { pattern, suffixes, confidence, minStemLength } of compoundPatterns) {
      if (word.endsWith(pattern)) {
        const stem = word.slice(0, -pattern.length);
        if (stem.length < minStemLength) continue;
        return normalized(stem, confidence, {
          removedSuffixes: suffixes,
          conjugationType: "compound"
        });
      }
    }
    return null;
  }
};
var japaneseMorphologicalNormalizer = new JapaneseMorphologicalNormalizer();

// src/generators/profiles/japanese.ts
var japaneseProfile = {
  code: "ja",
  name: "Japanese",
  nativeName: "\u65E5\u672C\u8A9E",
  direction: "ltr",
  wordOrder: "SOV",
  markingStrategy: "particle",
  usesSpaces: false,
  // Japanese uses verb stem/masu-stem form, no clear infinitive/imperative distinction
  // for UI commands. Uses katakana loanwords (トグル) or native stems (切り替え)
  defaultVerbForm: "base",
  verb: {
    position: "end",
    suffixes: ["\u308B", "\u3066", "\u305F", "\u307E\u3059", "\u306A\u3044"],
    subjectDrop: true
  },
  references: {
    me: "\u81EA\u5206",
    // "self" - in hyperscript context, refers to current element
    it: "\u305D\u308C",
    // "it"
    you: "\u3042\u306A\u305F",
    // "you"
    result: "\u7D50\u679C",
    event: "\u30A4\u30D9\u30F3\u30C8",
    target: "\u30BF\u30FC\u30B2\u30C3\u30C8",
    body: "\u30DC\u30C7\u30A3"
  },
  possessive: {
    marker: "\u306E",
    markerPosition: "between",
    // In Japanese: 自分の value (jibun no value) = "my value"
    keywords: {
      \u79C1\u306E: "me",
      // watashi no (my)
      \u3042\u306A\u305F\u306E: "you",
      // anata no (your)
      \u305D\u306E: "it"
      // sono (its)
    }
  },
  roleMarkers: {
    patient: { primary: "\u3092", position: "after" },
    destination: { primary: "\u306B", alternatives: ["\u3078", "\u3067", "\u306E"], position: "after" },
    source: { primary: "\u304B\u3089", position: "after" },
    style: { primary: "\u3067", position: "after" },
    event: { primary: "\u3092", position: "after" }
    // Event as object marker
    // Possession marker for "X's Y" patterns
    // Note: の is used between target and patient: #button の .active
  },
  keywords: {
    // Class/Attribute operations
    toggle: {
      primary: "\u5207\u308A\u66FF\u3048",
      alternatives: ["\u5207\u308A\u66FF\u3048\u308B", "\u30C8\u30B0\u30EB", "\u30C8\u30B0\u30EB\u3059\u308B"],
      normalized: "toggle"
    },
    add: { primary: "\u8FFD\u52A0", alternatives: ["\u8FFD\u52A0\u3059\u308B", "\u52A0\u3048\u308B"], normalized: "add" },
    remove: { primary: "\u524A\u9664", alternatives: ["\u524A\u9664\u3059\u308B", "\u53D6\u308A\u9664\u304F"], normalized: "remove" },
    // Content operations
    put: { primary: "\u7F6E\u304F", alternatives: ["\u5165\u308C\u308B", "\u30BB\u30C3\u30C8"], normalized: "put" },
    append: { primary: "\u672B\u5C3E\u8FFD\u52A0", alternatives: ["\u672B\u5C3E\u306B\u8FFD\u52A0", "\u30A2\u30DA\u30F3\u30C9"], normalized: "append" },
    prepend: {
      primary: "\u5148\u982D\u8FFD\u52A0",
      alternatives: ["\u5148\u982D\u306B\u8FFD\u52A0", "\u30D7\u30EA\u30DA\u30F3\u30C9"],
      normalized: "prepend"
    },
    take: { primary: "\u53D6\u308B", normalized: "take" },
    // Removed 取得 (belongs to get)
    make: { primary: "\u4F5C\u308B", alternatives: ["\u4F5C\u6210"], normalized: "make" },
    clone: { primary: "\u8907\u88FD", alternatives: ["\u30AF\u30ED\u30FC\u30F3"], normalized: "clone" },
    swap: { primary: "\u4EA4\u63DB", alternatives: ["\u30B9\u30EF\u30C3\u30D7", "\u5165\u308C\u66FF\u3048"], normalized: "swap" },
    morph: { primary: "\u5909\u5F62", alternatives: ["\u30E2\u30FC\u30D5", "\u5909\u63DB"], normalized: "morph" },
    // Variable operations
    set: { primary: "\u8A2D\u5B9A", alternatives: ["\u8A2D\u5B9A\u3059\u308B", "\u30BB\u30C3\u30C8"], normalized: "set" },
    get: { primary: "\u53D6\u5F97", alternatives: ["\u53D6\u5F97\u3059\u308B", "\u30B2\u30C3\u30C8"], normalized: "get" },
    increment: {
      primary: "\u5897\u52A0",
      alternatives: ["\u5897\u3084\u3059", "\u30A4\u30F3\u30AF\u30EA\u30E1\u30F3\u30C8"],
      normalized: "increment"
    },
    decrement: {
      primary: "\u6E1B\u5C11",
      alternatives: ["\u6E1B\u3089\u3059", "\u30C7\u30AF\u30EA\u30E1\u30F3\u30C8"],
      normalized: "decrement"
    },
    log: { primary: "\u8A18\u9332", alternatives: ["\u30ED\u30B0", "\u51FA\u529B"], normalized: "log" },
    // Visibility
    show: { primary: "\u8868\u793A", alternatives: ["\u8868\u793A\u3059\u308B", "\u898B\u305B\u308B"], normalized: "show" },
    hide: { primary: "\u96A0\u3059", alternatives: ["\u975E\u8868\u793A", "\u975E\u8868\u793A\u306B\u3059\u308B"], normalized: "hide" },
    transition: {
      primary: "\u9077\u79FB",
      alternatives: ["\u30C8\u30E9\u30F3\u30B8\u30B7\u30E7\u30F3", "\u30A2\u30CB\u30E1\u30FC\u30B7\u30E7\u30F3"],
      normalized: "transition"
    },
    // Events
    on: { primary: "\u3067", alternatives: ["\u6642", "\u3068\u304D"], normalized: "on" },
    trigger: { primary: "\u5F15\u304D\u91D1", alternatives: ["\u767A\u706B", "\u30C8\u30EA\u30AC\u30FC"], normalized: "trigger" },
    send: { primary: "\u9001\u308B", alternatives: ["\u9001\u4FE1"], normalized: "send" },
    // DOM focus
    focus: { primary: "\u30D5\u30A9\u30FC\u30AB\u30B9", alternatives: ["\u96C6\u4E2D"], normalized: "focus" },
    blur: { primary: "\u307C\u304B\u3057", alternatives: ["\u30D5\u30A9\u30FC\u30AB\u30B9\u89E3\u9664"], normalized: "blur" },
    // Navigation
    go: { primary: "\u79FB\u52D5", alternatives: ["\u884C\u304F", "\u30CA\u30D3\u30B2\u30FC\u30C8"], normalized: "go" },
    // Async
    wait: { primary: "\u5F85\u3064", alternatives: ["\u5F85\u6A5F"], normalized: "wait" },
    fetch: { primary: "\u53D6\u5F97", alternatives: ["\u30D5\u30A7\u30C3\u30C1"], normalized: "fetch" },
    settle: { primary: "\u5B89\u5B9A", alternatives: ["\u843D\u3061\u7740\u304F"], normalized: "settle" },
    // Control flow
    if: { primary: "\u3082\u3057", alternatives: ["\u6761\u4EF6"], normalized: "if" },
    when: { primary: "\u3068\u304D", normalized: "when" },
    where: { primary: "\u3069\u3053", normalized: "where" },
    else: { primary: "\u305D\u3046\u3067\u306A\u3051\u308C\u3070", alternatives: ["\u305D\u308C\u4EE5\u5916"], normalized: "else" },
    repeat: { primary: "\u7E70\u308A\u8FD4\u3057", alternatives: ["\u7E70\u308A\u8FD4\u3059", "\u30EA\u30D4\u30FC\u30C8"], normalized: "repeat" },
    for: { primary: "\u305F\u3081\u306B", alternatives: ["\u5404"], normalized: "for" },
    while: { primary: "\u306E\u9593", alternatives: ["\u9593"], normalized: "while" },
    continue: { primary: "\u7D9A\u3051\u308B", alternatives: ["\u7D99\u7D9A"], normalized: "continue" },
    halt: { primary: "\u505C\u6B62", alternatives: ["\u6B62\u3081\u308B", "\u30CF\u30EB\u30C8"], normalized: "halt" },
    throw: { primary: "\u6295\u3052\u308B", alternatives: ["\u30B9\u30ED\u30FC"], normalized: "throw" },
    call: { primary: "\u547C\u3073\u51FA\u3057", alternatives: ["\u30B3\u30FC\u30EB", "\u547C\u3076"], normalized: "call" },
    return: { primary: "\u623B\u308B", alternatives: ["\u8FD4\u3059", "\u30EA\u30BF\u30FC\u30F3"], normalized: "return" },
    then: { primary: "\u305D\u308C\u304B\u3089", alternatives: ["\u6B21\u306B", "\u305D\u3057\u3066"], normalized: "then" },
    and: { primary: "\u305D\u3057\u3066", alternatives: ["\u3068", "\u307E\u305F"], normalized: "and" },
    end: { primary: "\u7D42\u308F\u308A", alternatives: ["\u7D42\u4E86", "\u304A\u308F\u308A"], normalized: "end" },
    // Advanced
    js: { primary: "JS\u5B9F\u884C", alternatives: ["js"], normalized: "js" },
    async: { primary: "\u975E\u540C\u671F", alternatives: ["\u30A2\u30B7\u30F3\u30AF"], normalized: "async" },
    tell: { primary: "\u4F1D\u3048\u308B", alternatives: ["\u30C6\u30EB"], normalized: "tell" },
    default: { primary: "\u65E2\u5B9A", alternatives: ["\u30C7\u30D5\u30A9\u30EB\u30C8"], normalized: "default" },
    init: { primary: "\u521D\u671F\u5316", alternatives: ["\u30A4\u30CB\u30C3\u30C8"], normalized: "init" },
    behavior: { primary: "\u632F\u308B\u821E\u3044", alternatives: ["\u30D3\u30D8\u30A4\u30D3\u30A2"], normalized: "behavior" },
    install: { primary: "\u30A4\u30F3\u30B9\u30C8\u30FC\u30EB", alternatives: ["\u5C0E\u5165"], normalized: "install" },
    measure: { primary: "\u6E2C\u5B9A", alternatives: ["\u8A08\u6E2C", "\u30E1\u30B8\u30E3\u30FC"], normalized: "measure" },
    // Modifiers
    into: { primary: "\u3078", alternatives: ["\u306B"], normalized: "into" },
    before: { primary: "\u524D\u306B", alternatives: ["\u524D"], normalized: "before" },
    after: { primary: "\u5F8C\u306B", alternatives: ["\u5F8C"], normalized: "after" },
    // Event modifiers (for repeat until event)
    until: { primary: "\u307E\u3067", alternatives: ["\u8FC4"], normalized: "until" },
    event: { primary: "\u30A4\u30D9\u30F3\u30C8", alternatives: ["\u4E8B\u8C61"], normalized: "event" },
    from: { primary: "\u304B\u3089", normalized: "from" }
  },
  tokenization: {
    particles: ["\u3092", "\u306B", "\u3067", "\u304B\u3089", "\u306E", "\u304C", "\u306F", "\u3082", "\u3078", "\u3068"],
    boundaryStrategy: "particle"
  },
  eventHandler: {
    // Event marker: で (at/on/when), used in SOV pattern
    // Pattern: [event] で [destination] の [patient] を [action]
    // Example: クリック で #button の .active を 切り替え
    // Note: に is NOT an event marker - it marks direction/destination
    // で specifically marks the means/method of action (by/via)
    eventMarker: { primary: "\u3067", position: "after" },
    temporalMarkers: ["\u6642", "\u3068\u304D"]
    // temporal markers that can optionally appear
  }
};

// src/tokenizers/japanese.ts
var isHiragana2 = createUnicodeRangeClassifier([[12352, 12447]]);
var isKatakana2 = createUnicodeRangeClassifier([[12448, 12543]]);
var isKanji2 = createUnicodeRangeClassifier([
  [19968, 40959],
  // CJK Unified Ideographs
  [13312, 19903]
  // CJK Unified Ideographs Extension A
]);
var isJapanese = combineClassifiers(isHiragana2, isKatakana2, isKanji2);
var PARTICLES = /* @__PURE__ */ new Set([
  "\u3092",
  // wo - object marker
  "\u306B",
  // ni - destination, time
  "\u3067",
  // de - location of action, means
  "\u304B\u3089",
  // kara - from
  "\u307E\u3067",
  // made - until
  "\u3078",
  // e - direction
  "\u3068",
  // to - and, with
  "\u306E",
  // no - possessive
  "\u304C",
  // ga - subject marker
  "\u306F",
  // wa - topic marker
  "\u3082",
  // mo - also
  "\u3088\u308A"
  // yori - than, from
]);
var SINGLE_CHAR_PARTICLES = /* @__PURE__ */ new Set(["\u3092", "\u306B", "\u3067", "\u3078", "\u3068", "\u306E", "\u304C", "\u306F", "\u3082"]);
var MULTI_CHAR_PARTICLES = ["\u304B\u3089", "\u307E\u3067", "\u3088\u308A"];
var PARTICLE_ROLES = /* @__PURE__ */ new Map([
  ["\u3092", { role: "patient", confidence: 0.95, description: "object marker" }],
  ["\u306B", { role: "destination", confidence: 0.85, description: "destination/time marker" }],
  ["\u3067", { role: "manner", confidence: 0.88, description: "means/location marker" }],
  ["\u304B\u3089", { role: "source", confidence: 0.9, description: "from/source marker" }],
  ["\u307E\u3067", { role: "destination", confidence: 0.75, description: "until/boundary marker" }],
  ["\u3078", { role: "destination", confidence: 0.9, description: "direction marker" }],
  ["\u3068", { role: "style", confidence: 0.7, description: "with/and marker" }],
  ["\u306E", { role: "destination", confidence: 0.75, description: "possessive/destination marker" }],
  ["\u304C", { role: "agent", confidence: 0.85, description: "subject marker" }],
  ["\u306F", { role: "agent", confidence: 0.75, description: "topic marker" }],
  ["\u3082", { role: "patient", confidence: 0.65, description: "also/too marker" }],
  ["\u3088\u308A", { role: "source", confidence: 0.85, description: "from/than marker" }]
]);
var JAPANESE_EXTRAS = [
  // Values/Literals
  { native: "\u771F", normalized: "true" },
  { native: "\u507D", normalized: "false" },
  { native: "\u30CC\u30EB", normalized: "null" },
  { native: "\u672A\u5B9A\u7FA9", normalized: "undefined" },
  // Positional
  { native: "\u6700\u521D", normalized: "first" },
  { native: "\u6700\u5F8C", normalized: "last" },
  { native: "\u6B21", normalized: "next" },
  { native: "\u524D", normalized: "previous" },
  { native: "\u6700\u3082\u8FD1\u3044", normalized: "closest" },
  { native: "\u89AA", normalized: "parent" },
  // Events
  { native: "\u30AF\u30EA\u30C3\u30AF", normalized: "click" },
  { native: "\u5909\u66F4", normalized: "change" },
  { native: "\u9001\u4FE1", normalized: "submit" },
  { native: "\u5165\u529B", normalized: "input" },
  { native: "\u30ED\u30FC\u30C9", normalized: "load" },
  { native: "\u30B9\u30AF\u30ED\u30FC\u30EB", normalized: "scroll" },
  { native: "\u30AD\u30FC\u30C0\u30A6\u30F3", normalized: "keydown" },
  { native: "\u30AD\u30FC\u30A2\u30C3\u30D7", normalized: "keyup" },
  { native: "\u30DE\u30A6\u30B9\u30AA\u30FC\u30D0\u30FC", normalized: "mouseover" },
  { native: "\u30DE\u30A6\u30B9\u30A2\u30A6\u30C8", normalized: "mouseout" },
  { native: "\u30D6\u30E9\u30FC", normalized: "blur" },
  // References (additional forms)
  { native: "\u79C1", normalized: "me" },
  { native: "\u79C1\u306E", normalized: "my" },
  { native: "\u305D\u306E", normalized: "its" },
  // Note: Attached particle forms (を切り替え, を追加, etc.) are intentionally NOT included
  // because they would cause ambiguous parsing. The separate particle + verb pattern
  // (を + 切り替え) is preferred for consistent semantic analysis.
  // Conditional event forms
  { native: "\u3057\u305F\u3089", normalized: "on" },
  { native: "\u3059\u308B\u3068", normalized: "on" },
  { native: "\u6642\u306B", normalized: "on" },
  // Control flow helpers
  { native: "\u3082\u3057", normalized: "if" },
  // Starts with particle も, needs explicit entry
  { native: "\u306A\u3089\u3070", normalized: "then" },
  { native: "\u306A\u3089", normalized: "then" },
  { native: "\u305D\u308C\u304B\u3089", normalized: "then" },
  // Chain connector
  { native: "\u305D\u3057\u3066", normalized: "and" },
  // Alternative connector
  // Time units
  { native: "\u79D2", normalized: "s" },
  { native: "\u30DF\u30EA\u79D2", normalized: "ms" },
  { native: "\u5206", normalized: "m" },
  { native: "\u6642\u9593", normalized: "h" }
];
var JAPANESE_TIME_UNITS = [
  { pattern: "\u30DF\u30EA\u79D2", suffix: "ms", length: 3 },
  { pattern: "\u6642\u9593", suffix: "h", length: 2 },
  { pattern: "\u79D2", suffix: "s", length: 1 },
  { pattern: "\u5206", suffix: "m", length: 1 }
];
var JapaneseTokenizer = class extends BaseTokenizer {
  constructor() {
    super();
    this.language = "ja";
    this.direction = "ltr";
    this.initializeKeywordsFromProfile(japaneseProfile, JAPANESE_EXTRAS);
    this.normalizer = new JapaneseMorphologicalNormalizer();
  }
  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.extractJapaneseNumber(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 multiParticle = this.tryMultiCharParticle(input, pos, MULTI_CHAR_PARTICLES);
      if (multiParticle) {
        const metadata = PARTICLE_ROLES.get(multiParticle.value);
        if (metadata) {
          tokens.push({
            ...multiParticle,
            metadata: {
              particleRole: metadata.role,
              particleConfidence: metadata.confidence
            }
          });
        } else {
          tokens.push(multiParticle);
        }
        pos = multiParticle.position.end;
        continue;
      }
      if (SINGLE_CHAR_PARTICLES.has(input[pos])) {
        const keywordToken = this.tryProfileKeyword(input, pos);
        if (keywordToken && keywordToken.value.length > 1) {
          tokens.push(keywordToken);
          pos = keywordToken.position.end;
          continue;
        }
        const particle = input[pos];
        const metadata = PARTICLE_ROLES.get(particle);
        if (metadata) {
          tokens.push({
            ...createToken(particle, "particle", createPosition(pos, pos + 1)),
            metadata: {
              particleRole: metadata.role,
              particleConfidence: metadata.confidence
            }
          });
        } else {
          tokens.push(createToken(particle, "particle", createPosition(pos, pos + 1)));
        }
        pos++;
        continue;
      }
      if (isJapanese(input[pos])) {
        const wordToken = this.extractJapaneseWord(input, pos);
        if (wordToken) {
          tokens.push(wordToken);
          pos = wordToken.position.end;
          continue;
        }
      }
      if (isAsciiIdentifierChar(input[pos])) {
        const asciiToken = this.extractAsciiWord(input, pos);
        if (asciiToken) {
          tokens.push(asciiToken);
          pos = asciiToken.position.end;
          continue;
        }
      }
      pos++;
    }
    return new TokenStreamImpl(tokens, "ja");
  }
  classifyToken(token) {
    if (PARTICLES.has(token)) return "particle";
    if (this.isKeyword(token)) return "keyword";
    if (token.startsWith("#") || token.startsWith(".") || token.startsWith("[")) return "selector";
    if (token.startsWith('"') || token.startsWith("'") || token.startsWith("\u300C")) return "literal";
    if (/^\d/.test(token)) return "literal";
    return "identifier";
  }
  /**
   * Extract a Japanese word (sequence of kanji/kana).
   * Stops at particles, ASCII, or whitespace.
   *
   * Uses morphological normalization to handle verb conjugations:
   * 1. First checks if the exact word is in the keyword map
   * 2. If not found, tries to strip conjugation suffixes and check again
   */
  extractJapaneseWord(input, startPos) {
    let pos = startPos;
    let word = "";
    while (pos < input.length) {
      const char = input[pos];
      if (SINGLE_CHAR_PARTICLES.has(char) && word.length > 0) {
        break;
      }
      let foundMulti = false;
      for (const particle of MULTI_CHAR_PARTICLES) {
        if (input.slice(pos, pos + particle.length) === particle && word.length > 0) {
          foundMulti = true;
          break;
        }
      }
      if (foundMulti) break;
      if (isJapanese(char)) {
        word += char;
        pos++;
      } else {
        break;
      }
    }
    if (!word) return null;
    const keywordEntry = this.lookupKeyword(word);
    if (keywordEntry) {
      return createToken(word, "keyword", createPosition(startPos, pos), keywordEntry.normalized);
    }
    const morphToken = this.tryMorphKeywordMatch(word, startPos, pos);
    if (morphToken) return morphToken;
    return createToken(word, "identifier", createPosition(startPos, pos));
  }
  /**
   * Extract an ASCII word (for mixed Japanese/English content).
   */
  extractAsciiWord(input, startPos) {
    let pos = startPos;
    let word = "";
    while (pos < input.length && isAsciiIdentifierChar(input[pos])) {
      word += input[pos++];
    }
    if (!word) return null;
    return createToken(word, "identifier", createPosition(startPos, pos));
  }
  /**
   * Extract a number, including Japanese time unit suffixes.
   * Japanese time units attach directly without whitespace.
   */
  extractJapaneseNumber(input, startPos) {
    return this.tryNumberWithTimeUnits(input, startPos, JAPANESE_TIME_UNITS, {
      allowSign: false,
      skipWhitespace: false
    });
  }
};
var japaneseTokenizer = new JapaneseTokenizer();

// src/languages/ja.ts
registerLanguage("ja", japaneseTokenizer, japaneseProfile);
export {
  japaneseProfile,
  japaneseTokenizer
};
//# sourceMappingURL=ja.js.map