{"version":3,"file":"index.cjs","names":["textInputRule","Extension"],"sources":["../src/typography.ts","../src/index.ts"],"sourcesContent":["import { Extension, textInputRule } from '@tiptap/core'\n\n/**\n * Configuration for directional quotes (open/close pair).\n */\nexport interface DirectionalQuotes {\n  open: string\n  close: string\n}\n\nexport interface TypographyOptions {\n  /**\n   * The em dash character.\n   * @default '—'\n   */\n  emDash: false | string\n\n  /**\n   * The ellipsis character.\n   * @default '…'\n   */\n  ellipsis: false | string\n\n  /**\n   * The open double quote character.\n   * @default '“'\n   */\n  openDoubleQuote: false | string\n\n  /**\n   * The close double quote character.\n   * @default '”'\n   */\n  closeDoubleQuote: false | string\n\n  /**\n   * The open single quote character.\n   * @default '‘'\n   */\n  openSingleQuote: false | string\n\n  /**\n   * The close single quote character.\n   * @default '’'\n   */\n  closeSingleQuote: false | string\n\n  /**\n   * The left arrow character.\n   * @default '←'\n   */\n  leftArrow: false | string\n\n  /**\n   * The right arrow character.\n   * @default '→'\n   */\n  rightArrow: false | string\n\n  /**\n   * The copyright character.\n   * @default '©'\n   */\n  copyright: false | string\n\n  /**\n   * The trademark character.\n   * @default '™'\n   */\n  trademark: false | string\n\n  /**\n   * The servicemark character.\n   * @default '℠'\n   */\n  servicemark: false | string\n\n  /**\n   * The registered trademark character.\n   * @default '®'\n   */\n  registeredTrademark: false | string\n\n  /**\n   * The one half character.\n   * @default '½'\n   */\n  oneHalf: false | string\n\n  /**\n   * The plus minus character.\n   * @default '±'\n   */\n  plusMinus: false | string\n\n  /**\n   * The not equal character.\n   * @default '≠'\n   */\n  notEqual: false | string\n\n  /**\n   * The laquo character.\n   * @default '«'\n   */\n  laquo: false | string\n\n  /**\n   * The raquo character.\n   * @default '»'\n   */\n  raquo: false | string\n\n  /**\n   * The multiplication character.\n   * @default '×'\n   */\n  multiplication: false | string\n\n  /**\n   * The superscript two character.\n   * @default '²'\n   */\n  superscriptTwo: false | string\n\n  /**\n   * The superscript three character.\n   * @default '³'\n   */\n  superscriptThree: false | string\n\n  /**\n   * The one quarter character.\n   * @default '¼'\n   */\n  oneQuarter: false | string\n\n  /**\n   * The three quarters character.\n   * @default '¾'\n   */\n  threeQuarters: false | string\n\n  /**\n   * Directional double quotes configuration.\n   * Use this for explicit LTR/RTL quote control.\n   * When `rtl` is configured, RTL-specific quote rules are used instead of default LTR.\n   * @example\n   * ```ts\n   * Typography.configure({\n   *   doubleQuotes: {\n   *     rtl: { open: '\\u201D', close: '\\u201C' } // Swapped for RTL\n   *   }\n   * })\n   * ```\n   */\n  doubleQuotes?: {\n    rtl?: DirectionalQuotes\n  }\n\n  /**\n   * Directional single quotes configuration.\n   * Use this for explicit LTR/RTL quote control.\n   * When `rtl` is configured, RTL-specific quote rules are used instead of default LTR.\n   * @example\n   * ```ts\n   * Typography.configure({\n   *   singleQuotes: {\n   *     rtl: { open: '\\u2019', close: '\\u2018' } // Swapped for RTL\n   *   }\n   * })\n   * ```\n   */\n  singleQuotes?: {\n    rtl?: DirectionalQuotes\n  }\n}\n\nexport const emDash = (override?: string) =>\n  textInputRule({\n    find: /--$/,\n    replace: override ?? '—',\n  })\n\nexport const ellipsis = (override?: string) =>\n  textInputRule({\n    find: /\\.\\.\\.$/,\n    replace: override ?? '…',\n  })\n\nexport const openDoubleQuote = (override?: string) =>\n  textInputRule({\n    find: /(?:^|[\\s{[(<'\"\\u2018\\u201C])(\")$/,\n    replace: override ?? '“',\n  })\n\nexport const closeDoubleQuote = (override?: string) =>\n  textInputRule({\n    find: /\"$/,\n    replace: override ?? '”',\n  })\n\nexport const openSingleQuote = (override?: string) =>\n  textInputRule({\n    find: /(?:^|[\\s{[(<'\"\\u2018\\u201C])(')$/,\n    replace: override ?? '‘',\n  })\n\nexport const closeSingleQuote = (override?: string) =>\n  textInputRule({\n    find: /'$/,\n    replace: override ?? '’',\n  })\n\nexport const leftArrow = (override?: string) =>\n  textInputRule({\n    find: /<-$/,\n    replace: override ?? '←',\n  })\n\nexport const rightArrow = (override?: string) =>\n  textInputRule({\n    find: /->$/,\n    replace: override ?? '→',\n  })\n\nexport const copyright = (override?: string) =>\n  textInputRule({\n    find: /\\(c\\)$/,\n    replace: override ?? '©',\n  })\n\nexport const trademark = (override?: string) =>\n  textInputRule({\n    find: /\\(tm\\)$/,\n    replace: override ?? '™',\n  })\n\nexport const servicemark = (override?: string) =>\n  textInputRule({\n    find: /\\(sm\\)$/,\n    replace: override ?? '℠',\n  })\n\nexport const registeredTrademark = (override?: string) =>\n  textInputRule({\n    find: /\\(r\\)$/,\n    replace: override ?? '®',\n  })\n\nexport const oneHalf = (override?: string) =>\n  textInputRule({\n    find: /(?:^|\\s)(1\\/2)\\s$/,\n    replace: override ?? '½',\n  })\n\nexport const plusMinus = (override?: string) =>\n  textInputRule({\n    find: /\\+\\/-$/,\n    replace: override ?? '±',\n  })\n\nexport const notEqual = (override?: string) =>\n  textInputRule({\n    find: /!=$/,\n    replace: override ?? '≠',\n  })\n\nexport const laquo = (override?: string) =>\n  textInputRule({\n    find: /<<$/,\n    replace: override ?? '«',\n  })\n\nexport const raquo = (override?: string) =>\n  textInputRule({\n    find: />>$/,\n    replace: override ?? '»',\n  })\n\nexport const multiplication = (override?: string) =>\n  textInputRule({\n    find: /\\d+\\s?([*x])\\s?\\d+$/,\n    replace: override ?? '×',\n  })\n\nexport const superscriptTwo = (override?: string) =>\n  textInputRule({\n    find: /\\^2$/,\n    replace: override ?? '²',\n  })\n\nexport const superscriptThree = (override?: string) =>\n  textInputRule({\n    find: /\\^3$/,\n    replace: override ?? '³',\n  })\n\nexport const oneQuarter = (override?: string) =>\n  textInputRule({\n    find: /(?:^|\\s)(1\\/4)\\s$/,\n    replace: override ?? '¼',\n  })\n\nexport const threeQuarters = (override?: string) =>\n  textInputRule({\n    find: /(?:^|\\s)(3\\/4)\\s$/,\n    replace: override ?? '¾',\n  })\n\n/**\n * This extension allows you to add typography replacements for specific characters.\n * @see https://www.tiptap.dev/api/extensions/typography\n */\nexport const Typography = Extension.create<TypographyOptions>({\n  name: 'typography',\n\n  addOptions() {\n    return {\n      closeDoubleQuote: '”',\n      closeSingleQuote: '’',\n      copyright: '©',\n      ellipsis: '…',\n      emDash: '—',\n      laquo: '«',\n      leftArrow: '←',\n      multiplication: '×',\n      notEqual: '≠',\n      oneHalf: '½',\n      oneQuarter: '¼',\n      openDoubleQuote: '“',\n      openSingleQuote: '‘',\n      plusMinus: '±',\n      raquo: '»',\n      registeredTrademark: '®',\n      rightArrow: '→',\n      servicemark: '℠',\n      superscriptThree: '³',\n      superscriptTwo: '²',\n      threeQuarters: '¾',\n      trademark: '™',\n    }\n  },\n\n  addInputRules() {\n    const rules = []\n\n    if (this.options.emDash !== false) {\n      rules.push(emDash(this.options.emDash))\n    }\n\n    if (this.options.ellipsis !== false) {\n      rules.push(ellipsis(this.options.ellipsis))\n    }\n\n    // Determine if RTL mode is active based on explicit config or editor option\n    const isRTL = this.editor.options.textDirection === 'rtl'\n\n    // Double quotes: use explicit RTL config if provided, otherwise use automatic RTL detection\n    if (this.options.doubleQuotes?.rtl) {\n      const { open, close } = this.options.doubleQuotes.rtl\n\n      rules.push(openDoubleQuote(open))\n      rules.push(closeDoubleQuote(close))\n    } else if (isRTL) {\n      // Automatic RTL detection: swap open and close quotes\n      rules.push(openDoubleQuote('\\u201D')) // Right double quotation mark\n      rules.push(closeDoubleQuote('\\u201C')) // Left double quotation mark\n    } else {\n      if (this.options.openDoubleQuote !== false) {\n        rules.push(openDoubleQuote(this.options.openDoubleQuote))\n      }\n\n      if (this.options.closeDoubleQuote !== false) {\n        rules.push(closeDoubleQuote(this.options.closeDoubleQuote))\n      }\n    }\n\n    // Single quotes: use explicit RTL config if provided, otherwise use automatic RTL detection\n    if (this.options.singleQuotes?.rtl) {\n      const { open, close } = this.options.singleQuotes.rtl\n\n      rules.push(openSingleQuote(open))\n      rules.push(closeSingleQuote(close))\n    } else if (isRTL) {\n      // Automatic RTL detection: swap open and close quotes\n      rules.push(openSingleQuote('\\u2019')) // Right single quotation mark\n      rules.push(closeSingleQuote('\\u2018')) // Left single quotation mark\n    } else {\n      if (this.options.openSingleQuote !== false) {\n        rules.push(openSingleQuote(this.options.openSingleQuote))\n      }\n\n      if (this.options.closeSingleQuote !== false) {\n        rules.push(closeSingleQuote(this.options.closeSingleQuote))\n      }\n    }\n\n    if (this.options.leftArrow !== false) {\n      rules.push(leftArrow(this.options.leftArrow))\n    }\n\n    if (this.options.rightArrow !== false) {\n      rules.push(rightArrow(this.options.rightArrow))\n    }\n\n    if (this.options.copyright !== false) {\n      rules.push(copyright(this.options.copyright))\n    }\n\n    if (this.options.trademark !== false) {\n      rules.push(trademark(this.options.trademark))\n    }\n\n    if (this.options.servicemark !== false) {\n      rules.push(servicemark(this.options.servicemark))\n    }\n\n    if (this.options.registeredTrademark !== false) {\n      rules.push(registeredTrademark(this.options.registeredTrademark))\n    }\n\n    if (this.options.oneHalf !== false) {\n      rules.push(oneHalf(this.options.oneHalf))\n    }\n\n    if (this.options.plusMinus !== false) {\n      rules.push(plusMinus(this.options.plusMinus))\n    }\n\n    if (this.options.notEqual !== false) {\n      rules.push(notEqual(this.options.notEqual))\n    }\n\n    if (this.options.laquo !== false) {\n      rules.push(laquo(this.options.laquo))\n    }\n\n    if (this.options.raquo !== false) {\n      rules.push(raquo(this.options.raquo))\n    }\n\n    if (this.options.multiplication !== false) {\n      rules.push(multiplication(this.options.multiplication))\n    }\n\n    if (this.options.superscriptTwo !== false) {\n      rules.push(superscriptTwo(this.options.superscriptTwo))\n    }\n\n    if (this.options.superscriptThree !== false) {\n      rules.push(superscriptThree(this.options.superscriptThree))\n    }\n\n    if (this.options.oneQuarter !== false) {\n      rules.push(oneQuarter(this.options.oneQuarter))\n    }\n\n    if (this.options.threeQuarters !== false) {\n      rules.push(threeQuarters(this.options.threeQuarters))\n    }\n\n    return rules\n  },\n})\n","import { Typography } from './typography.js'\n\nexport * from './typography.js'\n\nexport default Typography\n"],"mappings":";;;;;;AAkLA,MAAa,UAAU,cAAA,GACrBA,aAAAA,cAAAA,CAAc;CACZ,M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