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

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

// src/generators/profiles/chinese.ts
var chineseProfile = {
  code: "zh",
  name: "Chinese",
  nativeName: "\u4E2D\u6587",
  direction: "ltr",
  wordOrder: "SVO",
  markingStrategy: "preposition",
  // Uses prepositions but often implicit
  usesSpaces: false,
  verb: {
    position: "second",
    subjectDrop: true
  },
  references: {
    me: "\u6211",
    // "I/me"
    it: "\u5B83",
    // "it"
    you: "\u4F60",
    // "you"
    result: "\u7ED3\u679C",
    event: "\u4E8B\u4EF6",
    target: "\u76EE\u6807",
    body: "\u4E3B\u4F53"
  },
  possessive: {
    marker: "\u7684",
    // Possessive particle (de)
    markerPosition: "between",
    // Chinese: 我的 value (wǒ de value) = "my value"
    keywords: {
      // Compound possessive forms (pronoun + 的)
      \u6211\u7684: "me",
      // wǒ de (my)
      \u4F60\u7684: "you",
      // nǐ de (your)
      \u5B83\u7684: "it",
      // tā de (its)
      \u4ED6\u7684: "it",
      // tā de (his)
      \u5979\u7684: "it"
      // tā de (her)
    }
  },
  roleMarkers: {
    destination: { primary: "\u5728", alternatives: ["\u5230", "\u4E8E"], position: "before" },
    source: { primary: "\u4ECE", alternatives: ["\u7531"], position: "before" },
    patient: { primary: "\u628A", position: "before" },
    // BA construction
    style: { primary: "\u7528", alternatives: ["\u4EE5"], position: "before" }
  },
  keywords: {
    // Class/Attribute operations
    toggle: { primary: "\u5207\u6362", normalized: "toggle" },
    add: { primary: "\u6DFB\u52A0", alternatives: ["\u52A0"], normalized: "add" },
    remove: { primary: "\u79FB\u9664", alternatives: ["\u5220\u9664", "\u53BB\u6389"], normalized: "remove" },
    // Content operations
    put: { primary: "\u653E\u7F6E", alternatives: ["\u653E", "\u653E\u5165"], normalized: "put" },
    append: { primary: "\u8FFD\u52A0", alternatives: ["\u9644\u52A0"], normalized: "append" },
    prepend: { primary: "\u524D\u7F6E", alternatives: ["\u9884\u7F6E"], normalized: "prepend" },
    take: { primary: "\u83B7\u53D6", normalized: "take" },
    make: { primary: "\u5236\u4F5C", normalized: "make" },
    clone: { primary: "\u590D\u5236", normalized: "clone" },
    swap: { primary: "\u4EA4\u6362", normalized: "swap" },
    morph: { primary: "\u53D8\u5F62", alternatives: ["\u8F6C\u6362"], normalized: "morph" },
    // Variable operations
    set: { primary: "\u8BBE\u7F6E", alternatives: ["\u8BBE\u5B9A"], normalized: "set" },
    get: { primary: "\u83B7\u5F97", alternatives: ["\u83B7\u53D6", "\u53D6\u5F97"], normalized: "get" },
    increment: { primary: "\u589E\u52A0", normalized: "increment" },
    decrement: { primary: "\u51CF\u5C11", normalized: "decrement" },
    log: { primary: "\u65E5\u5FD7", normalized: "log" },
    // Visibility
    show: { primary: "\u663E\u793A", alternatives: ["\u5C55\u793A"], normalized: "show" },
    hide: { primary: "\u9690\u85CF", normalized: "hide" },
    transition: { primary: "\u8FC7\u6E21", normalized: "transition" },
    // Events
    on: { primary: "\u5F53", alternatives: ["\u5728...\u65F6"], normalized: "on" },
    trigger: { primary: "\u89E6\u53D1", normalized: "trigger" },
    send: { primary: "\u53D1\u9001", normalized: "send" },
    // DOM focus
    focus: { primary: "\u805A\u7126", normalized: "focus" },
    blur: { primary: "\u5931\u7126", normalized: "blur" },
    // Common event names (for event handler patterns)
    click: { primary: "\u70B9\u51FB", normalized: "click" },
    hover: { primary: "\u60AC\u505C", alternatives: ["\u60AC\u6D6E"], normalized: "hover" },
    submit: { primary: "\u63D0\u4EA4", normalized: "submit" },
    input: { primary: "\u8F93\u5165", normalized: "input" },
    change: { primary: "\u6539\u53D8", alternatives: ["\u53D8\u5316"], normalized: "change" },
    // Navigation
    go: { primary: "\u524D\u5F80", normalized: "go" },
    // Async
    wait: { primary: "\u7B49\u5F85", normalized: "wait" },
    fetch: { primary: "\u83B7\u53D6", normalized: "fetch" },
    settle: { primary: "\u7A33\u5B9A", normalized: "settle" },
    // Control flow
    if: { primary: "\u5982\u679C", normalized: "if" },
    when: { primary: "\u5F53", normalized: "when" },
    where: { primary: "\u54EA\u91CC", normalized: "where" },
    else: { primary: "\u5426\u5219", normalized: "else" },
    repeat: { primary: "\u91CD\u590D", normalized: "repeat" },
    for: { primary: "\u4E3A", normalized: "for" },
    while: { primary: "\u5F53", normalized: "while" },
    continue: { primary: "\u7EE7\u7EED", normalized: "continue" },
    halt: { primary: "\u505C\u6B62", normalized: "halt" },
    throw: { primary: "\u629B\u51FA", normalized: "throw" },
    call: { primary: "\u8C03\u7528", normalized: "call" },
    return: { primary: "\u8FD4\u56DE", normalized: "return" },
    then: { primary: "\u7136\u540E", alternatives: ["\u63A5\u7740", "\u4E4B\u540E"], normalized: "then" },
    and: { primary: "\u5E76\u4E14", alternatives: ["\u548C", "\u800C\u4E14"], normalized: "and" },
    end: { primary: "\u7ED3\u675F", alternatives: ["\u7EC8\u6B62", "\u5B8C"], normalized: "end" },
    // Advanced
    js: { primary: "JS\u6267\u884C", alternatives: ["js"], normalized: "js" },
    async: { primary: "\u5F02\u6B65", normalized: "async" },
    tell: { primary: "\u544A\u8BC9", normalized: "tell" },
    default: { primary: "\u9ED8\u8BA4", normalized: "default" },
    init: { primary: "\u521D\u59CB\u5316", normalized: "init" },
    behavior: { primary: "\u884C\u4E3A", normalized: "behavior" },
    install: { primary: "\u5B89\u88C5", normalized: "install" },
    measure: { primary: "\u6D4B\u91CF", normalized: "measure" },
    // Modifiers
    into: { primary: "\u8FDB\u5165", normalized: "into" },
    before: { primary: "\u4E4B\u524D", normalized: "before" },
    after: { primary: "\u4E4B\u540E", normalized: "after" },
    // Event modifiers (for repeat until event)
    until: { primary: "\u76F4\u5230", normalized: "until" },
    event: { primary: "\u4E8B\u4EF6", normalized: "event" },
    from: { primary: "\u4ECE", normalized: "from" }
  },
  tokenization: {
    boundaryStrategy: "character"
  },
  eventHandler: {
    keyword: { primary: "\u5F53", alternatives: ["\u5728...\u65F6"], normalized: "on" },
    sourceMarker: { primary: "\u4ECE", position: "before" },
    // Event marker: 当 (when), used in SVO pattern
    // Pattern: 当 [event] [verb] [patient] 在 [destination?]
    // Example: 当 点击 切换 .active 在 #button
    eventMarker: { primary: "\u5F53", alternatives: ["\u5728"], position: "before" },
    temporalMarkers: ["\u5F53", "\u5728...\u65F6"]
    // temporal conjunctions (when)
  }
};

// src/tokenizers/chinese.ts
var isChinese = createUnicodeRangeClassifier([
  [19968, 40959],
  // CJK Unified Ideographs
  [13312, 19903],
  // CJK Unified Ideographs Extension A
  [131072, 173791],
  // CJK Unified Ideographs Extension B
  [63744, 64255],
  // CJK Compatibility Ideographs
  [194560, 195103]
  // CJK Compatibility Ideographs Supplement
]);
var PARTICLES = /* @__PURE__ */ new Set([
  "\u628A",
  // ba - marks direct object (BA construction)
  "\u5728",
  // zai - at, in, on (location)
  "\u4ECE",
  // cong - from
  "\u5230",
  // dao - to, until
  "\u5411",
  // xiang - towards
  "\u7ED9",
  // gei - to, for (recipient)
  "\u5BF9",
  // dui - to, towards
  "\u7528",
  // yong - with, using
  "\u88AB",
  // bei - by (passive)
  "\u8BA9",
  // rang - let, allow
  "\u7684",
  // de - possessive/attributive
  "\u5730",
  // de - adverbial marker
  "\u5F97",
  // de - complement marker
  "\u4E86",
  // le - completion marker
  "\u7740",
  // zhe - progressive marker
  "\u8FC7",
  // guo - experiential marker
  "\u5417",
  // ma - question particle
  "\u5462",
  // ne - question/emphasis particle
  "\u5427"
  // ba - suggestion particle
]);
var MULTI_CHAR_PARTICLES = ["\u7136\u540E", "\u63A5\u7740", "\u5E76\u4E14", "\u6216\u8005", "\u5982\u679C", "\u90A3\u4E48", "\u5426\u5219"];
var CHINESE_EXTRAS = [
  // Values/Literals
  { native: "\u771F", normalized: "true" },
  { native: "\u5047", normalized: "false" },
  { native: "\u7A7A", normalized: "null" },
  { native: "\u672A\u5B9A\u4E49", normalized: "undefined" },
  // Positional
  { native: "\u7B2C\u4E00\u4E2A", normalized: "first" },
  { native: "\u9996\u4E2A", normalized: "first" },
  { native: "\u6700\u540E\u4E00\u4E2A", normalized: "last" },
  { native: "\u672B\u4E2A", normalized: "last" },
  { native: "\u4E0B\u4E00\u4E2A", normalized: "next" },
  { native: "\u4E0A\u4E00\u4E2A", normalized: "previous" },
  { native: "\u6700\u8FD1\u7684", normalized: "closest" },
  { native: "\u7236\u7EA7", normalized: "parent" },
  // Events
  { native: "\u70B9\u51FB", normalized: "click" },
  { native: "\u53CC\u51FB", normalized: "dblclick" },
  { native: "\u8F93\u5165", normalized: "input" },
  { native: "\u53D8\u66F4", normalized: "change" },
  { native: "\u6539\u53D8", normalized: "change" },
  { native: "\u63D0\u4EA4", normalized: "submit" },
  { native: "\u6309\u952E", normalized: "keydown" },
  { native: "\u91CA\u653E\u952E", normalized: "keyup" },
  { native: "\u9F20\u6807\u79FB\u5165", normalized: "mouseover" },
  { native: "\u9F20\u6807\u79FB\u51FA", normalized: "mouseout" },
  { native: "\u83B7\u5F97\u7126\u70B9", normalized: "focus" },
  { native: "\u5931\u53BB\u7126\u70B9", normalized: "blur" },
  { native: "\u52A0\u8F7D", normalized: "load" },
  { native: "\u6EDA\u52A8", normalized: "scroll" },
  // Additional references
  { native: "\u6211\u7684", normalized: "my" },
  { native: "\u5B83\u7684", normalized: "its" },
  // Time units
  { native: "\u79D2", normalized: "s" },
  { native: "\u6BEB\u79D2", normalized: "ms" },
  { native: "\u5206\u949F", normalized: "m" },
  { native: "\u5C0F\u65F6", normalized: "h" },
  // Logical operators
  { native: "\u548C", normalized: "and" },
  { native: "\u6216\u8005", normalized: "or" },
  { native: "\u6216", normalized: "or" },
  { native: "\u4E0D", normalized: "not" },
  { native: "\u975E", normalized: "not" },
  { native: "\u662F", normalized: "is" },
  // Additional synonyms not in profile
  { native: "\u82E5", normalized: "if" },
  { native: "\u4E0D\u7136", normalized: "else" },
  { native: "\u5FAA\u73AF", normalized: "repeat" },
  { native: "\u904D\u5386", normalized: "for" },
  { native: "\u6BCF\u4E2A", normalized: "for" },
  { native: "\u4E3A\u6BCF", normalized: "for" },
  { native: "\u4E2D\u6B62", normalized: "halt" },
  { native: "\u629B", normalized: "throw" },
  { native: "\u547C\u53EB", normalized: "call" },
  { native: "\u56DE", normalized: "return" },
  { native: "\u811A\u672C", normalized: "js" },
  { native: "\u901A\u77E5", normalized: "tell" },
  { native: "\u7F3A\u7701", normalized: "default" },
  { native: "\u521D\u59CB", normalized: "init" },
  { native: "\u52A8\u4F5C", normalized: "behavior" },
  { native: "\u6FC0\u53D1", normalized: "trigger" },
  { native: "\u5BF9\u7126", normalized: "focus" },
  { native: "\u6A21\u7CCA", normalized: "blur" },
  { native: "\u8DF3\u8F6C", normalized: "go" },
  { native: "\u5BFC\u822A", normalized: "go" },
  { native: "\u6293\u53D6", normalized: "fetch" },
  { native: "\u83B7\u53D6\u6570\u636E", normalized: "fetch" },
  { native: "\u5B89\u5B9A", normalized: "settle" },
  { native: "\u62FF\u53D6", normalized: "take" },
  { native: "\u53D6", normalized: "take" },
  { native: "\u521B\u5EFA", normalized: "make" },
  { native: "\u514B\u9686", normalized: "clone" },
  { native: "\u8BB0\u5F55", normalized: "log" },
  { native: "\u6253\u5370", normalized: "log" },
  { native: "\u52A8\u753B", normalized: "transition" },
  // Modifiers
  { native: "\u5230\u91CC\u9762", normalized: "into" },
  { native: "\u91CC", normalized: "into" },
  { native: "\u524D", normalized: "before" },
  { native: "\u540E", normalized: "after" },
  { native: "\u90A3\u4E48", normalized: "then" },
  { native: "\u5B8C", normalized: "end" }
];
var CHINESE_TIME_UNITS = [
  { pattern: "\u6BEB\u79D2", suffix: "ms", length: 2 },
  { pattern: "\u5206\u949F", suffix: "m", length: 2 },
  { pattern: "\u5C0F\u65F6", suffix: "h", length: 2 },
  { pattern: "\u79D2", suffix: "s", length: 1 },
  { pattern: "\u5206", suffix: "m", length: 1 }
];
var ChineseTokenizer = class extends BaseTokenizer {
  constructor() {
    super();
    this.language = "zh";
    this.direction = "ltr";
    this.initializeKeywordsFromProfile(chineseProfile, CHINESE_EXTRAS);
  }
  tokenize(input) {
    const tokens = [];
    let pos = 0;
    while (pos < input.length) {
      if (isWhitespace(input[pos])) {
        pos++;
        continue;
      }
      if (isSelectorStart(input[pos])) {
        const modifierToken = this.tryEventModifier(input, pos);
        if (modifierToken) {
          tokens.push(modifierToken);
          pos = modifierToken.position.end;
          continue;
        }
        const selectorToken = this.trySelector(input, pos);
        if (selectorToken) {
          tokens.push(selectorToken);
          pos = selectorToken.position.end;
          continue;
        }
      }
      if (isQuote(input[pos]) || input[pos] === "\u201C" || input[pos] === "\u201D" || input[pos] === "\u2018" || input[pos] === "\u2019") {
        const stringToken = this.tryChineseString(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.extractChineseNumber(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) {
        tokens.push(multiParticle);
        pos = multiParticle.position.end;
        continue;
      }
      if (isChinese(input[pos])) {
        const wordToken = this.extractChineseWord(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, "zh");
  }
  classifyToken(token) {
    if (PARTICLES.has(token)) return "particle";
    if (this.isKeyword(token)) return "keyword";
    if (token.startsWith("#") || token.startsWith(".") || token.startsWith("[") || token.startsWith("<"))
      return "selector";
    if (token.startsWith('"') || token.startsWith("'") || token.startsWith("\u201C") || token.startsWith("\u2018"))
      return "literal";
    if (/^\d/.test(token)) return "literal";
    return "identifier";
  }
  /**
   * Extract a Chinese word.
   * Uses greedy matching to find the longest known keyword.
   * Chinese doesn't have inflection, so we don't need morphological normalization.
   * profileKeywords is already sorted longest-first, enabling greedy matching.
   */
  extractChineseWord(input, startPos) {
    for (const entry of this.profileKeywords) {
      const keyword = entry.native;
      const candidate = input.slice(startPos, startPos + keyword.length);
      if (candidate === keyword) {
        let allChinese = true;
        for (let i = 0; i < keyword.length; i++) {
          if (!isChinese(keyword[i])) {
            allChinese = false;
            break;
          }
        }
        if (allChinese) {
          return createToken(
            candidate,
            "keyword",
            createPosition(startPos, startPos + keyword.length),
            entry.normalized
          );
        }
      }
    }
    let pos = startPos;
    let word = "";
    while (pos < input.length) {
      const char = input[pos];
      if (PARTICLES.has(char) && word.length > 0) {
        break;
      }
      if (isChinese(char)) {
        word += char;
        pos++;
      } else {
        break;
      }
    }
    if (!word) return null;
    if (PARTICLES.has(word)) {
      return createToken(word, "particle", createPosition(startPos, pos));
    }
    return createToken(word, "identifier", createPosition(startPos, pos));
  }
  /**
   * Extract an ASCII word (for mixed Chinese/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));
  }
  /**
   * Try to extract a string literal, including Chinese quotes.
   * Chinese quotes: \u201C " (open) \u201D " (close) \u2018 ' (open) \u2019 ' (close)
   */
  tryChineseString(input, pos) {
    const char = input[pos];
    if (char === '"' || char === "'" || char === "`") {
      return this.tryString(input, pos);
    }
    if (char === "\u201C") {
      let endPos = pos + 1;
      while (endPos < input.length && input[endPos] !== "\u201D") {
        endPos++;
      }
      if (endPos >= input.length) return null;
      const value = input.slice(pos, endPos + 1);
      return createToken(value, "literal", createPosition(pos, endPos + 1));
    }
    if (char === "\u2018") {
      let endPos = pos + 1;
      while (endPos < input.length && input[endPos] !== "\u2019") {
        endPos++;
      }
      if (endPos >= input.length) return null;
      const value = input.slice(pos, endPos + 1);
      return createToken(value, "literal", createPosition(pos, endPos + 1));
    }
    return null;
  }
  /**
   * Extract a number, including Chinese time unit suffixes.
   * Chinese time units attach directly without whitespace.
   */
  extractChineseNumber(input, startPos) {
    return this.tryNumberWithTimeUnits(input, startPos, CHINESE_TIME_UNITS, {
      allowSign: false,
      skipWhitespace: false
    });
  }
};
var chineseTokenizer = new ChineseTokenizer();

// src/languages/zh.ts
registerLanguage("zh", chineseTokenizer, chineseProfile);
export {
  chineseProfile,
  chineseTokenizer
};
//# sourceMappingURL=zh.js.map