// 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 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/arabic-normalizer.ts
function isArabic(char) {
  const code = char.charCodeAt(0);
  return code >= 1536 && code <= 1791 || // Arabic
  code >= 1872 && code <= 1919 || // Arabic Supplement
  code >= 2208 && code <= 2303 || // Arabic Extended-A
  code >= 64336 && code <= 65023 || // Arabic Presentation Forms-A
  code >= 65136 && code <= 65279;
}
function containsArabic(word) {
  for (const char of word) {
    if (isArabic(char)) return true;
  }
  return false;
}
function removeDiacritics(word) {
  return word.replace(/[\u064B-\u0652\u0670]/g, "");
}
var COMBINED_PREFIXES = [
  // Conjunction + article combinations (4 chars)
  { pattern: "\u0648\u0627\u0644", confidencePenalty: 0.15, prefixType: "conjunction" },
  // wa + al
  { pattern: "\u0641\u0627\u0644", confidencePenalty: 0.15, prefixType: "conjunction" },
  // fa + al
  { pattern: "\u0628\u0627\u0644", confidencePenalty: 0.15, prefixType: "preposition" },
  // bi + al
  { pattern: "\u0643\u0627\u0644", confidencePenalty: 0.15, prefixType: "preposition" },
  // ka + al
  { pattern: "\u0644\u0644", confidencePenalty: 0.12, prefixType: "preposition" }
  // li + al (assimilation)
];
var SINGLE_PREFIXES = [
  // Definite article (2 chars) - can leave 2-char stem
  { pattern: "\u0627\u0644", confidencePenalty: 0.08, prefixType: "article", minRemaining: 2 },
  // Conjunctions and prepositions (1 char) - need longer stem to be safe
  { pattern: "\u0648", confidencePenalty: 0.08, prefixType: "conjunction", minRemaining: 3 },
  // wa- (and)
  { pattern: "\u0641", confidencePenalty: 0.08, prefixType: "conjunction", minRemaining: 3 },
  // fa- (then/so)
  { pattern: "\u0628", confidencePenalty: 0.1, prefixType: "preposition", minRemaining: 3 },
  // bi- (with/by)
  { pattern: "\u0644", confidencePenalty: 0.1, prefixType: "preposition", minRemaining: 3 },
  // li- (to/for)
  { pattern: "\u0643", confidencePenalty: 0.1, prefixType: "preposition", minRemaining: 3 }
  // ka- (like/as)
];
var VERB_PREFIXES = [
  { pattern: "\u064A", confidencePenalty: 0.12, prefixType: "verb-marker", minRemaining: 3 },
  // ya- (he/it)
  { pattern: "\u062A", confidencePenalty: 0.12, prefixType: "verb-marker", minRemaining: 3 },
  // ta- (she/you)
  { pattern: "\u0646", confidencePenalty: 0.12, prefixType: "verb-marker", minRemaining: 3 },
  // na- (we)
  { pattern: "\u0623", confidencePenalty: 0.12, prefixType: "verb-marker", minRemaining: 3 },
  // a- (I)
  { pattern: "\u0627", confidencePenalty: 0.12, prefixType: "verb-marker", minRemaining: 3 }
  // a- without hamza
];
var SUFFIXES = [
  // Plural forms
  { pattern: "\u0648\u0646", confidencePenalty: 0.1, type: "masculine-plural" },
  { pattern: "\u064A\u0646", confidencePenalty: 0.1, type: "masculine-plural-accusative" },
  { pattern: "\u0627\u062A", confidencePenalty: 0.1, type: "feminine-plural" },
  // Dual forms
  { pattern: "\u0627\u0646", confidencePenalty: 0.1, type: "dual-nominative" },
  { pattern: "\u064A\u0646", confidencePenalty: 0.1, type: "dual-accusative" },
  // Pronoun suffixes
  { pattern: "\u0647\u0627", confidencePenalty: 0.1, type: "pronoun-her" },
  { pattern: "\u0647\u0645", confidencePenalty: 0.1, type: "pronoun-them" },
  { pattern: "\u0647\u0646", confidencePenalty: 0.1, type: "pronoun-them-f" },
  { pattern: "\u0646\u0627", confidencePenalty: 0.1, type: "pronoun-us" },
  { pattern: "\u0643\u0645", confidencePenalty: 0.1, type: "pronoun-you-pl" },
  { pattern: "\u0643", confidencePenalty: 0.08, type: "pronoun-you" },
  { pattern: "\u0647", confidencePenalty: 0.08, type: "pronoun-him" },
  { pattern: "\u064A", confidencePenalty: 0.08, type: "pronoun-me" },
  // Feminine marker
  { pattern: "\u0629", confidencePenalty: 0.08, type: "feminine" }
];
var ArabicMorphologicalNormalizer = class {
  constructor() {
    this.language = "ar";
  }
  /**
   * Check if a word might be an Arabic word that can be normalized.
   */
  isNormalizable(word) {
    if (!containsArabic(word)) return false;
    if (word.length < 2) return false;
    return true;
  }
  /**
   * Normalize an Arabic word by stripping prefixes and suffixes.
   */
  normalize(word) {
    let stem = removeDiacritics(word);
    let confidence = 1;
    const removedPrefixes = [];
    const removedSuffixes = [];
    for (const rule of COMBINED_PREFIXES) {
      if (stem.startsWith(rule.pattern)) {
        const remaining = stem.slice(rule.pattern.length);
        if (remaining.length >= 2) {
          stem = remaining;
          confidence -= rule.confidencePenalty;
          removedPrefixes.push(rule.pattern);
          break;
        }
      }
    }
    if (removedPrefixes.length === 0) {
      for (const rule of SINGLE_PREFIXES) {
        if (stem.startsWith(rule.pattern)) {
          const remaining = stem.slice(rule.pattern.length);
          const minLen = rule.minRemaining ?? 2;
          if (remaining.length >= minLen) {
            stem = remaining;
            confidence -= rule.confidencePenalty;
            removedPrefixes.push(rule.pattern);
            break;
          }
        }
      }
    }
    const looksLikeNoun = stem.endsWith("\u0627\u062A") || stem.endsWith("\u0629") || stem.endsWith("\u0648\u0646") || stem.endsWith("\u064A\u0646") || stem.endsWith("\u0647\u0627") || stem.endsWith("\u0647\u0645") || stem.endsWith("\u0647\u0646") || stem.endsWith("\u0646\u0627") || stem.endsWith("\u0643\u0645");
    if (!looksLikeNoun && (removedPrefixes.length === 0 || removedPrefixes[0] === "\u0648" || removedPrefixes[0] === "\u0641")) {
      for (const rule of VERB_PREFIXES) {
        if (stem.startsWith(rule.pattern)) {
          const remaining = stem.slice(rule.pattern.length);
          const minLen = rule.minRemaining ?? 3;
          if (remaining.length >= minLen) {
            stem = remaining;
            confidence -= rule.confidencePenalty;
            removedPrefixes.push(rule.pattern);
            break;
          }
        }
      }
    }
    for (const rule of SUFFIXES) {
      if (stem.endsWith(rule.pattern)) {
        const remaining = stem.slice(0, -rule.pattern.length);
        if (remaining.length >= 2) {
          stem = remaining;
          confidence -= rule.confidencePenalty;
          removedSuffixes.push(rule.pattern);
        }
      }
    }
    confidence = Math.max(0.5, confidence);
    if (removedPrefixes.length === 0 && removedSuffixes.length === 0) {
      return noChange(word);
    }
    return normalized(stem, confidence, {
      removedPrefixes,
      removedSuffixes
    });
  }
};
var arabicMorphologicalNormalizer = new ArabicMorphologicalNormalizer();

// src/generators/profiles/arabic.ts
var arabicProfile = {
  code: "ar",
  name: "Arabic",
  nativeName: "\u0627\u0644\u0639\u0631\u0628\u064A\u0629",
  direction: "rtl",
  wordOrder: "VSO",
  markingStrategy: "preposition",
  usesSpaces: true,
  verb: {
    position: "start",
    subjectDrop: true
  },
  references: {
    me: "\u0623\u0646\u0627",
    // "I/me" - first person
    it: "\u0647\u0648",
    // "it" (masculine)
    you: "\u0623\u0646\u062A",
    // "you"
    result: "\u0627\u0644\u0646\u062A\u064A\u062C\u0629",
    event: "\u0627\u0644\u062D\u062F\u062B",
    target: "\u0627\u0644\u0647\u062F\u0641",
    body: "\u0627\u0644\u062C\u0633\u0645"
  },
  possessive: {
    marker: "",
    // No explicit marker - uses possessive pronouns
    markerPosition: "after-object",
    usePossessiveAdjectives: true,
    specialForms: {
      // Arabic: "value لي" (value for-me) - possessive pronoun follows property
      me: "\u0644\u064A",
      // "for me" / "mine"
      it: "\u0644\u0647",
      // "for it" / "its"
      you: "\u0644\u0643"
      // "for you" / "yours"
    },
    keywords: {
      // "my" / "mine"
      \u0644\u064A: "me",
      // "your" / "yours"
      \u0644\u0643: "you",
      // "its/his/her"
      \u0644\u0647: "it",
      // his/its (masculine)
      \u0644\u0647\u0627: "it"
      // her/its (feminine)
    }
  },
  roleMarkers: {
    destination: { primary: "\u0639\u0644\u0649", alternatives: ["\u0641\u064A", "\u0625\u0644\u0649", "\u0628"], position: "before" },
    source: { primary: "\u0645\u0646", position: "before" },
    patient: { primary: "", position: "before" },
    style: { primary: "\u0628\u0640", alternatives: ["\u0628\u0627\u0633\u062A\u062E\u062F\u0627\u0645"], position: "before" }
  },
  keywords: {
    // Class/Attribute operations
    toggle: { primary: "\u0628\u062F\u0651\u0644", alternatives: ["\u0628\u062F\u0644", "\u063A\u064A\u0651\u0631", "\u063A\u064A\u0631"], normalized: "toggle" },
    add: { primary: "\u0623\u0636\u0641", alternatives: ["\u0627\u0636\u0641", "\u0632\u0650\u062F"], normalized: "add" },
    remove: { primary: "\u0627\u062D\u0630\u0641", alternatives: ["\u0623\u0632\u0644", "\u0627\u0645\u0633\u062D"], normalized: "remove" },
    // Content operations
    put: { primary: "\u0636\u0639", alternatives: ["\u0627\u062C\u0639\u0644"], normalized: "put" },
    append: { primary: "\u0623\u0644\u062D\u0642", normalized: "append" },
    prepend: { primary: "\u0633\u0628\u0642", normalized: "prepend" },
    take: { primary: "\u062E\u0630", normalized: "take" },
    // Removed احصل to avoid collision with get
    make: { primary: "\u0627\u0635\u0646\u0639", alternatives: ["\u0623\u0646\u0634\u0626"], normalized: "make" },
    clone: { primary: "\u0627\u0633\u062A\u0646\u0633\u062E", alternatives: ["\u0627\u0646\u0633\u062E"], normalized: "clone" },
    swap: { primary: "\u0627\u0633\u062A\u0628\u062F\u0644", alternatives: ["\u062A\u0628\u0627\u062F\u0644"], normalized: "swap" },
    morph: { primary: "\u062D\u0648\u0651\u0644", alternatives: ["\u063A\u064A\u0651\u0631"], normalized: "morph" },
    // Variable operations
    set: { primary: "\u0627\u0636\u0628\u0637", alternatives: ["\u0639\u064A\u0651\u0646", "\u062D\u062F\u062F"], normalized: "set" },
    get: { primary: "\u0627\u062D\u0635\u0644", normalized: "get" },
    // Removed خذ to avoid collision with take
    increment: { primary: "\u0632\u0650\u062F", alternatives: ["\u0632\u062F", "\u0627\u0631\u0641\u0639"], normalized: "increment" },
    decrement: { primary: "\u0623\u0646\u0642\u0635", alternatives: ["\u0627\u0646\u0642\u0635", "\u0642\u0644\u0644"], normalized: "decrement" },
    log: { primary: "\u0633\u062C\u0644", normalized: "log" },
    // Visibility
    show: { primary: "\u0627\u0638\u0647\u0631", alternatives: ["\u0623\u0638\u0647\u0631", "\u0627\u0639\u0631\u0636"], normalized: "show" },
    hide: { primary: "\u0627\u062E\u0641", alternatives: ["\u0623\u062E\u0641\u0650", "\u0627\u062E\u0641\u064A", "\u0623\u062E\u0641"], normalized: "hide" },
    // Added hamza variant
    transition: { primary: "\u0627\u0646\u062A\u0642\u0627\u0644", alternatives: ["\u0627\u0646\u062A\u0642\u0644"], normalized: "transition" },
    // Events
    on: { primary: "\u0639\u0644\u0649", alternatives: ["\u0639\u0646\u062F", "\u0644\u062F\u0649", "\u062D\u064A\u0646"], normalized: "on" },
    trigger: { primary: "\u062A\u0634\u063A\u064A\u0644", alternatives: ["\u0623\u0637\u0644\u0642", "\u0641\u0639\u0651\u0644"], normalized: "trigger" },
    send: { primary: "\u0623\u0631\u0633\u0644", normalized: "send" },
    // DOM focus
    focus: { primary: "\u062A\u0631\u0643\u064A\u0632", alternatives: ["\u0631\u0643\u0632"], normalized: "focus" },
    blur: { primary: "\u0636\u0628\u0627\u0628\u064A\u0629", alternatives: ["\u0634\u0648\u0634"], normalized: "blur" },
    // Navigation
    go: { primary: "\u0627\u0630\u0647\u0628", alternatives: ["\u0627\u0646\u062A\u0642\u0644"], normalized: "go" },
    // Async
    wait: { primary: "\u0627\u0646\u062A\u0638\u0631", normalized: "wait" },
    fetch: { primary: "\u0627\u062D\u0636\u0631", alternatives: ["\u062C\u0644\u0628"], normalized: "fetch" },
    settle: { primary: "\u0627\u0633\u062A\u0642\u0631", normalized: "settle" },
    // Control flow
    if: { primary: "\u0625\u0630\u0627", normalized: "if" },
    when: { primary: "\u0639\u0646\u062F\u0645\u0627", normalized: "when" },
    where: { primary: "\u0623\u064A\u0646", normalized: "where" },
    else: { primary: "\u0648\u0625\u0644\u0627", alternatives: ["\u062E\u0644\u0627\u0641 \u0630\u0644\u0643"], normalized: "else" },
    repeat: { primary: "\u0643\u0631\u0631", normalized: "repeat" },
    for: { primary: "\u0644\u0643\u0644", normalized: "for" },
    while: { primary: "\u0628\u064A\u0646\u0645\u0627", normalized: "while" },
    continue: { primary: "\u0648\u0627\u0635\u0644", normalized: "continue" },
    halt: { primary: "\u0623\u0648\u0642\u0641", alternatives: ["\u062A\u0648\u0642\u0641"], normalized: "halt" },
    throw: { primary: "\u0627\u0631\u0645", alternatives: ["\u0627\u0631\u0645\u0650"], normalized: "throw" },
    call: { primary: "\u0627\u0633\u062A\u062F\u0639", alternatives: ["\u0646\u0627\u062F\u0650"], normalized: "call" },
    return: { primary: "\u0627\u0631\u062C\u0639", alternatives: ["\u0639\u064F\u062F"], normalized: "return" },
    then: { primary: "\u062B\u0645", alternatives: ["\u0628\u0639\u062F\u0647\u0627", "\u062B\u0645\u0651"], normalized: "then" },
    and: { primary: "\u0648\u0623\u064A\u0636\u0627\u064B", alternatives: ["\u0623\u064A\u0636\u0627\u064B"], normalized: "and" },
    end: { primary: "\u0646\u0647\u0627\u064A\u0629", alternatives: ["\u0627\u0646\u062A\u0647\u0649", "\u0622\u062E\u0631"], normalized: "end" },
    // Advanced
    js: { primary: "\u062C\u0627\u0641\u0627\u0633\u0643\u0631\u0628\u062A", alternatives: ["js"], normalized: "js" },
    async: { primary: "\u0645\u062A\u0632\u0627\u0645\u0646", normalized: "async" },
    tell: { primary: "\u0623\u062E\u0628\u0631", normalized: "tell" },
    default: { primary: "\u0627\u0641\u062A\u0631\u0627\u0636\u064A", normalized: "default" },
    init: { primary: "\u062A\u0647\u064A\u0626\u0629", alternatives: ["\u0628\u062F\u0621"], normalized: "init" },
    behavior: { primary: "\u0633\u0644\u0648\u0643", normalized: "behavior" },
    install: { primary: "\u062A\u062B\u0628\u064A\u062A", alternatives: ["\u062B\u0628\u0651\u062A"], normalized: "install" },
    measure: { primary: "\u0642\u064A\u0627\u0633", alternatives: ["\u0642\u0650\u0633"], normalized: "measure" },
    // Modifiers
    into: { primary: "\u0641\u064A", alternatives: ["\u0625\u0644\u0649"], normalized: "into" },
    before: { primary: "\u0642\u0628\u0644", normalized: "before" },
    after: { primary: "\u0628\u0639\u062F", normalized: "after" },
    // Event modifiers (for repeat until event)
    until: { primary: "\u062D\u062A\u0649", normalized: "until" },
    event: { primary: "\u062D\u062F\u062B", normalized: "event" },
    from: { primary: "\u0645\u0646", normalized: "from" }
  },
  tokenization: {
    prefixes: ["\u0627\u0644", "\u0648", "\u0641", "\u0628", "\u0643", "\u0644"]
  },
  eventHandler: {
    // Event marker: عند (at/upon), used in VSO pattern
    // Pattern: عند [event] [action] [patient] [على destination]
    // Example: عند النقر بدّل .active على #button
    // Includes temporal conjunctions (عندما = formal "when", حين = neutral, لمّا = dialectal)
    eventMarker: {
      primary: "\u0639\u0646\u062F",
      alternatives: ["\u0641\u064A", "\u0644\u062F\u0649", "\u0639\u0646\u062F\u0645\u0627", "\u062D\u064A\u0646", "\u062D\u064A\u0646\u0645\u0627", "\u0644\u0645\u0651\u0627", "\u0644\u0645\u0627"],
      position: "before"
    },
    temporalMarkers: ["\u0639\u0646\u062F\u0645\u0627", "\u062D\u064A\u0646", "\u0644\u0645\u0651\u0627"],
    // kept for reference/documentation
    // Negation marker: عدم (not/lack of), used for negated events
    // Pattern: عند عدم [event] [action] [patient]
    // Example: عند عدم التركيز أخف #tooltip = "on blur hide #tooltip"
    negationMarker: { primary: "\u0639\u062F\u0645", alternatives: ["\u0639\u062F\u0645"], position: "before" }
  }
};

// src/tokenizers/arabic.ts
var isArabic2 = createUnicodeRangeClassifier([
  [1536, 1791],
  // Arabic
  [1872, 1919],
  // Arabic Supplement
  [2208, 2303],
  // Arabic Extended-A
  [64336, 65023],
  // Arabic Presentation Forms-A
  [65136, 65279]
  // Arabic Presentation Forms-B
]);
var ATTACHED_PREFIXES = /* @__PURE__ */ new Set([
  "\u0628\u0640",
  // bi- (with, by)
  "\u0644\u0640",
  // li- (to, for)
  "\u0643\u0640",
  // ka- (like, as)
  "\u0648\u0640"
  // wa- (and)
]);
var PROCLITICS = /* @__PURE__ */ new Map([
  // Conjunctions (single character)
  ["\u0648", { normalized: "and", type: "conjunction" }],
  // wa - conjunction "and"
  ["\u0641", { normalized: "then", type: "conjunction" }],
  // fa - conjunction "then/so"
  // Attached prefix prepositions
  ["\u0628", { normalized: "with", type: "preposition" }],
  // bi- (with, by)
  ["\u0644", { normalized: "to", type: "preposition" }],
  // li- (to, for)
  ["\u0643", { normalized: "like", type: "preposition" }],
  // ka- (like, as)
  // Multi-proclitic sequences (conjunction + preposition)
  ["\u0648\u0644", { normalized: "and-to", type: "conjunction" }],
  // wa + li-
  ["\u0648\u0628", { normalized: "and-with", type: "conjunction" }],
  // wa + bi-
  ["\u0648\u0643", { normalized: "and-like", type: "conjunction" }],
  // wa + ka-
  ["\u0641\u0644", { normalized: "then-to", type: "conjunction" }],
  // fa + li-
  ["\u0641\u0628", { normalized: "then-with", type: "conjunction" }],
  // fa + bi-
  ["\u0641\u0643", { normalized: "then-like", type: "conjunction" }]
  // fa + ka-
]);
var TEMPORAL_MARKERS = /* @__PURE__ */ new Map([
  [
    "\u0639\u0646\u062F\u0645\u0627",
    {
      normalized: "on",
      formality: "formal",
      confidence: 0.95,
      description: "when (formal MSA)"
    }
  ],
  [
    "\u062D\u064A\u0646\u0645\u0627",
    {
      normalized: "on",
      formality: "formal",
      confidence: 0.93,
      description: "when/whenever (formal)"
    }
  ],
  [
    "\u0639\u0646\u062F",
    {
      normalized: "on",
      formality: "neutral",
      confidence: 0.88,
      description: "at/when (neutral)"
    }
  ],
  [
    "\u062D\u064A\u0646",
    {
      normalized: "on",
      formality: "neutral",
      confidence: 0.85,
      description: "when/time (neutral)"
    }
  ],
  [
    "\u0644\u0645\u0651\u0627",
    {
      normalized: "on",
      formality: "dialectal",
      confidence: 0.7,
      description: "when (dialectal, with shadda)"
    }
  ],
  [
    "\u0644\u0645\u0627",
    {
      normalized: "on",
      formality: "dialectal",
      confidence: 0.68,
      description: "when (dialectal, no diacritic)"
    }
  ],
  [
    "\u0644\u062F\u0649",
    {
      normalized: "on",
      formality: "neutral",
      confidence: 0.82,
      description: "at/with (temporal)"
    }
  ]
]);
var PREPOSITIONS = /* @__PURE__ */ new Set([
  "\u0641\u064A",
  // fī (in)
  "\u0639\u0644\u0649",
  // ʿalā (on)
  "\u0645\u0646",
  // min (from)
  "\u0625\u0644\u0649",
  // ilā (to)
  "\u0627\u0644\u0649",
  // ilā (alternative spelling)
  // 'عند' removed - it's a temporal marker with metadata
  "\u0645\u0639",
  // maʿa (with)
  "\u0639\u0646",
  // ʿan (about, from)
  "\u0642\u0628\u0644",
  // qabl (before)
  "\u0628\u0639\u062F",
  // baʿd (after)
  "\u0628\u064A\u0646"
  // bayn (between)
]);
var ARABIC_EXTRAS = [
  // Values/Literals
  { native: "\u0635\u062D\u064A\u062D", normalized: "true" },
  { native: "\u062E\u0637\u0623", normalized: "false" },
  { native: "null", normalized: "null" },
  { native: "\u0641\u0627\u0631\u063A", normalized: "null" },
  { native: "\u063A\u064A\u0631 \u0645\u0639\u0631\u0641", normalized: "undefined" },
  // Positional
  { native: "\u0627\u0644\u0623\u0648\u0644", normalized: "first" },
  { native: "\u0623\u0648\u0644", normalized: "first" },
  { native: "\u0627\u0644\u0623\u062E\u064A\u0631", normalized: "last" },
  { native: "\u0622\u062E\u0631", normalized: "last" },
  { native: "\u0627\u0644\u062A\u0627\u0644\u064A", normalized: "next" },
  { native: "\u0627\u0644\u0633\u0627\u0628\u0642", normalized: "previous" },
  { native: "\u0627\u0644\u0623\u0642\u0631\u0628", normalized: "closest" },
  { native: "\u0627\u0644\u0623\u0628", normalized: "parent" },
  // Events
  { native: "\u0627\u0644\u0646\u0642\u0631", normalized: "click" },
  { native: "\u0646\u0642\u0631", normalized: "click" },
  { native: "\u0627\u0644\u0625\u062F\u062E\u0627\u0644", normalized: "input" },
  { native: "\u0625\u062F\u062E\u0627\u0644", normalized: "input" },
  { native: "\u0627\u0644\u062A\u063A\u064A\u064A\u0631", normalized: "change" },
  { native: "\u062A\u063A\u064A\u064A\u0631", normalized: "change" },
  { native: "\u0627\u0644\u0625\u0631\u0633\u0627\u0644", normalized: "submit" },
  { native: "\u0625\u0631\u0633\u0627\u0644", normalized: "submit" },
  { native: "\u0627\u0644\u062A\u0631\u0643\u064A\u0632", normalized: "focus" },
  { native: "\u0641\u0642\u062F\u0627\u0646 \u0627\u0644\u062A\u0631\u0643\u064A\u0632", normalized: "blur" },
  { native: "\u0636\u063A\u0637", normalized: "keydown" },
  { native: "\u0631\u0641\u0639", normalized: "keyup" },
  { native: "\u062A\u0645\u0631\u064A\u0631 \u0627\u0644\u0641\u0623\u0631\u0629", normalized: "mouseover" },
  { native: "\u0645\u063A\u0627\u062F\u0631\u0629 \u0627\u0644\u0641\u0623\u0631\u0629", normalized: "mouseout" },
  { native: "\u062A\u062D\u0645\u064A\u0644", normalized: "load" },
  { native: "\u062A\u0645\u0631\u064A\u0631", normalized: "scroll" },
  // References (feminine "it" not in profile)
  { native: "\u0647\u064A", normalized: "it" },
  // Time units
  { native: "\u062B\u0627\u0646\u064A\u0629", normalized: "s" },
  { native: "\u062B\u0648\u0627\u0646\u064A", normalized: "s" },
  { native: "\u0645\u0644\u064A \u062B\u0627\u0646\u064A\u0629", normalized: "ms" },
  { native: "\u062F\u0642\u064A\u0642\u0629", normalized: "m" },
  { native: "\u062F\u0642\u0627\u0626\u0642", normalized: "m" },
  { native: "\u0633\u0627\u0639\u0629", normalized: "h" },
  { native: "\u0633\u0627\u0639\u0627\u062A", normalized: "h" }
  // Note: Temporal markers (عندما, حينما, etc.) are in TEMPORAL_MARKERS map
  // with formality metadata, not in ARABIC_EXTRAS
  //
  // Command spelling variants are now in the profile alternatives:
  // - toggle: بدل, غيّر, غير (in profile)
  // - add: اضف, زِد (in profile)
  // - remove: أزل, امسح (in profile)
  // - etc.
];
var ARABIC_TIME_UNITS = [
  { pattern: "\u0645\u0644\u064A \u062B\u0627\u0646\u064A\u0629", suffix: "ms", length: 9, caseInsensitive: false },
  { pattern: "\u0645\u0644\u064A_\u062B\u0627\u0646\u064A\u0629", suffix: "ms", length: 8, caseInsensitive: false },
  { pattern: "\u062F\u0642\u0627\u0626\u0642", suffix: "m", length: 5, caseInsensitive: false },
  { pattern: "\u062F\u0642\u064A\u0642\u0629", suffix: "m", length: 5, caseInsensitive: false },
  { pattern: "\u062B\u0648\u0627\u0646\u064A", suffix: "s", length: 5, caseInsensitive: false },
  { pattern: "\u062B\u0627\u0646\u064A\u0629", suffix: "s", length: 5, caseInsensitive: false },
  { pattern: "\u0633\u0627\u0639\u0627\u062A", suffix: "h", length: 5, caseInsensitive: false },
  { pattern: "\u0633\u0627\u0639\u0629", suffix: "h", length: 4, caseInsensitive: false }
];
var ArabicTokenizer = class extends BaseTokenizer {
  constructor() {
    super();
    this.language = "ar";
    this.direction = "rtl";
    this.initializeKeywordsFromProfile(arabicProfile, ARABIC_EXTRAS);
    this.normalizer = new ArabicMorphologicalNormalizer();
  }
  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.extractArabicNumber(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 prepToken = this.tryPreposition(input, pos);
      if (prepToken) {
        tokens.push(prepToken);
        pos = prepToken.position.end;
        continue;
      }
      if (isArabic2(input[pos])) {
        const procliticResult = this.tryProclitic(input, pos);
        if (procliticResult) {
          tokens.push(procliticResult.conjunction);
          pos = procliticResult.conjunction.position.end;
          continue;
        }
        const wordToken = this.extractArabicWord(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, "ar");
  }
  classifyToken(token) {
    if (PREPOSITIONS.has(token)) return "particle";
    if (this.isKeyword(token)) return "keyword";
    if (token.startsWith("#") || token.startsWith(".") || token.startsWith("[")) return "selector";
    if (token.startsWith('"') || token.startsWith("'")) return "literal";
    if (/^\d/.test(token)) return "literal";
    return "identifier";
  }
  /**
   * Try to match an Arabic preposition.
   * Attaches prepositionValue metadata for disambiguation in pattern matching.
   */
  tryPreposition(input, pos) {
    const sortedPreps = Array.from(PREPOSITIONS).sort((a, b) => b.length - a.length);
    for (const prep of sortedPreps) {
      if (input.slice(pos, pos + prep.length) === prep) {
        const nextPos = pos + prep.length;
        if (nextPos >= input.length || isWhitespace(input[nextPos]) || !isArabic2(input[nextPos])) {
          const token = createToken(prep, "particle", createPosition(pos, nextPos));
          return {
            ...token,
            metadata: {
              prepositionValue: prep
            }
          };
        }
      }
    }
    return null;
  }
  /**
   * Try to extract a proclitic (conjunction or preposition) that's attached to the following word.
   *
   * Arabic proclitics attach directly to words without space:
   * - والنقر → و + النقر (and + the-click)
   * - فالتبديل → ف + التبديل (then + the-toggle)
   * - بالنقر → ب + النقر (with + the-click)
   * - ولالنقر → و + ل + النقر (and + to + the-click)
   *
   * This enables:
   * - Polysyndetic coordination: A وB وC
   * - Attached prepositions: بالنقر (with-the-click)
   * - Multi-proclitic sequences: ولالنقر (and-to-the-click)
   *
   * Returns null if:
   * - Not a proclitic character/sequence
   * - Proclitic is standalone (followed by space)
   * - Remaining word is too short (< 2 chars, to avoid false positives)
   * - Full word is a recognized keyword (e.g., بدل should NOT be split to ب + دل)
   *
   * @see NATIVE_REVIEW_NEEDED.md for implementation rationale
   */
  tryProclitic(input, pos) {
    let wordEnd = pos;
    while (wordEnd < input.length && (isArabic2(input[wordEnd]) || input[wordEnd] === "\u0640")) {
      wordEnd++;
    }
    const fullWord = input.slice(pos, wordEnd);
    if (this.lookupKeyword(fullWord)) {
      return null;
    }
    if (TEMPORAL_MARKERS.has(fullWord)) {
      return null;
    }
    if (PREPOSITIONS.has(fullWord)) {
      return null;
    }
    if (pos + 2 <= input.length) {
      const twoChar = input.slice(pos, pos + 2);
      const twoCharEntry = PROCLITICS.get(twoChar);
      if (twoCharEntry) {
        const nextPos2 = pos + 2;
        if (nextPos2 < input.length && isArabic2(input[nextPos2])) {
          let remainingLength2 = 0;
          let checkPos2 = nextPos2;
          while (checkPos2 < input.length && isArabic2(input[checkPos2])) {
            remainingLength2++;
            checkPos2++;
          }
          if (remainingLength2 >= 2) {
            const singleCharProclitic = PROCLITICS.get(input[pos]);
            if (singleCharProclitic) {
              const afterSingleChar = input.slice(pos + 1, wordEnd);
              if (this.lookupKeyword(afterSingleChar)) {
              } else {
                const tokenKind2 = twoCharEntry.type === "conjunction" ? "conjunction" : "particle";
                return {
                  conjunction: createToken(
                    twoChar,
                    tokenKind2,
                    createPosition(pos, nextPos2),
                    twoCharEntry.normalized
                  )
                };
              }
            } else {
              const tokenKind2 = twoCharEntry.type === "conjunction" ? "conjunction" : "particle";
              return {
                conjunction: createToken(
                  twoChar,
                  tokenKind2,
                  createPosition(pos, nextPos2),
                  twoCharEntry.normalized
                )
              };
            }
          }
        }
      }
    }
    const char = input[pos];
    const entry = PROCLITICS.get(char);
    if (!entry) return null;
    const nextPos = pos + 1;
    if (nextPos >= input.length || !isArabic2(input[nextPos])) {
      return null;
    }
    let remainingLength = 0;
    let checkPos = nextPos;
    while (checkPos < input.length && isArabic2(input[checkPos])) {
      remainingLength++;
      checkPos++;
    }
    if (remainingLength < 2) {
      return null;
    }
    const tokenKind = entry.type === "conjunction" ? "conjunction" : "particle";
    return {
      conjunction: createToken(char, tokenKind, createPosition(pos, nextPos), entry.normalized)
    };
  }
  /**
   * Extract an Arabic word.
   * Uses morphological normalization to handle prefix/suffix variations.
   * Attaches metadata for temporal markers (formality, confidence).
   */
  extractArabicWord(input, startPos) {
    let pos = startPos;
    let word = "";
    for (const prefix of ATTACHED_PREFIXES) {
      const basePrefix = prefix.replace("\u0640", "");
      if (input.slice(pos, pos + basePrefix.length) === basePrefix) {
      }
    }
    while (pos < input.length && (isArabic2(input[pos]) || input[pos] === "\u0640")) {
      word += input[pos++];
    }
    if (!word) return null;
    const temporalMarker = TEMPORAL_MARKERS.get(word);
    if (temporalMarker) {
      const token = createToken(
        word,
        "keyword",
        createPosition(startPos, pos),
        temporalMarker.normalized
      );
      return {
        ...token,
        metadata: {
          temporalFormality: temporalMarker.formality,
          temporalConfidence: temporalMarker.confidence
        }
      };
    }
    const keywordEntry = this.lookupKeyword(word);
    if (keywordEntry) {
      return createToken(word, "keyword", createPosition(startPos, pos), keywordEntry.normalized);
    }
    if (PREPOSITIONS.has(word)) {
      const token = createToken(word, "particle", createPosition(startPos, pos));
      return {
        ...token,
        metadata: {
          prepositionValue: word
        }
      };
    }
    const morphToken = this.tryMorphKeywordMatch(word, startPos, pos);
    if (morphToken) return morphToken;
    return createToken(word, "identifier", createPosition(startPos, pos));
  }
  /**
   * Extract an ASCII word.
   */
  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 Arabic time unit suffixes.
   * Arabic allows space between number and unit.
   */
  extractArabicNumber(input, startPos) {
    return this.tryNumberWithTimeUnits(input, startPos, ARABIC_TIME_UNITS, {
      allowSign: false,
      skipWhitespace: true
    });
  }
};
var arabicTokenizer = new ArabicTokenizer();

// src/languages/ar.ts
registerLanguage("ar", arabicTokenizer, arabicProfile);
export {
  arabicProfile,
  arabicTokenizer
};
//# sourceMappingURL=ar.js.map