import { Extension, Range } from "@tiptap/core";

//#region src/index.d.ts

/**
 * All supported direction values.
 */
declare const DIRECTIONS: readonly ["ltr", "rtl", "auto"];
/**
 * Allowed text direction values.
 */
type Direction = (typeof DIRECTIONS)[number];
/**
 * Detect the text direction of a string based on its content.
 *
 * @param text - The text to analyze
 * @returns `"rtl"` if the text starts with a RTL character,
 *          `"ltr"` if the text starts with a LTR character,
 *          `null` if direction cannot be determined (e.g. empty string)
 */
declare function getTextDirection(text: string): "ltr" | "rtl" | null;
declare module "@tiptap/core" {
  interface Commands<ReturnType> {
    textDirection: {
      /**
       * Explicitly set the text direction for matching nodes within a range
       * or the current selection.
       *
       * @param direction - The direction to set: `"ltr"`, `"rtl"`, or `"auto"`
       * @param position - Optional document position or `{ from, to }` range.
       * If omitted, the current selection is used.
       *
       * @example editor.commands.setTextDirection("rtl")
       * @example editor.commands.setTextDirection("ltr", { from: 0, to: 10 })
       */
      setTextDirection: (direction: Direction, position?: number | Range) => ReturnType;
      /**
       * Remove the explicit text direction attribute from matching nodes.
       *
       * @param position - Optional document position or `{ from, to }` range.
       * If omitted, the current selection is used.
       *
       * @example editor.commands.unsetTextDirection()
       * @example editor.commands.unsetTextDirection({ from: 0, to: 10 })
       */
      unsetTextDirection: (position?: number | Range) => ReturnType;
    };
  }
}
/**
 * Configuration options for the TextDirection extension.
 */
interface TextDirectionOptions {
  /**
   * Node types that should receive a `dir` attribute.
   *
   * Example: `["paragraph", "heading"]`
   */
  types: Array<string>;
  /**
   * Default direction inherited from a parent element (e.g. `<html dir="rtl">`).
   *
   * When set, matching directions will not be rendered as explicit attributes.
   */
  defaultDirection: Direction | null;
}
/**
 * Tiptap extension that automatically detects and applies explicit text direction (`dir="ltr"` / `dir="rtl"`) to nodes.
 *
 * Unlike Tiptap’s built-in RTL support, this extension:
 * - Uses JavaScript-based language detection
 * - Avoids `dir="auto"`
 */
declare const TextDirection: Extension<TextDirectionOptions, any>;
//#endregion
export { TextDirection, TextDirection as default, TextDirectionOptions, getTextDirection };