@notectl/core 1.7.0 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/chunks/{AttrRegistry-I-VdmRnN.mjs → AttrRegistry-D9Jx_RVb.mjs} +2 -2
- package/dist/chunks/{AttrRegistry-I-VdmRnN.mjs.map → AttrRegistry-D9Jx_RVb.mjs.map} +1 -1
- package/dist/chunks/AttributedMarkCommands-BtLea72z.mjs +80 -0
- package/dist/chunks/AttributedMarkCommands-BtLea72z.mjs.map +1 -0
- package/dist/chunks/{CaretNavigation-CAJXoaae.mjs → CaretNavigation-7JYpIKbs.mjs} +56 -56
- package/dist/chunks/{CaretNavigation-CAJXoaae.mjs.map → CaretNavigation-7JYpIKbs.mjs.map} +1 -1
- package/dist/chunks/ColorGrid-Dneqb8if.mjs +81 -0
- package/dist/chunks/ColorGrid-Dneqb8if.mjs.map +1 -0
- package/dist/chunks/ColorPickerPopup-CiCLBbe9.mjs +37 -0
- package/dist/chunks/ColorPickerPopup-CiCLBbe9.mjs.map +1 -0
- package/dist/chunks/ColorValidation-CV4f1wu6.mjs +39 -0
- package/dist/chunks/ColorValidation-CV4f1wu6.mjs.map +1 -0
- package/dist/chunks/{Document-CuwE73FF.mjs → Document-Brtw2jL1.mjs} +18 -18
- package/dist/chunks/{Document-CuwE73FF.mjs.map → Document-Brtw2jL1.mjs.map} +1 -1
- package/dist/chunks/MarkCommands-6RUJ4L3r.mjs +94 -0
- package/dist/chunks/MarkCommands-6RUJ4L3r.mjs.map +1 -0
- package/dist/chunks/{NavigationUtils-CyW0Vo8A.mjs → NavigationUtils-Cspt2ZrK.mjs} +3 -3
- package/dist/chunks/{NavigationUtils-CyW0Vo8A.mjs.map → NavigationUtils-Cspt2ZrK.mjs.map} +1 -1
- package/dist/chunks/{NodeResolver-B-wzthAQ.mjs → NodeResolver-C2XYkeOi.mjs} +2 -2
- package/dist/chunks/{NodeResolver-B-wzthAQ.mjs.map → NodeResolver-C2XYkeOi.mjs.map} +1 -1
- package/dist/chunks/PopupPositioning-BTT-_pQ3.mjs +32 -0
- package/dist/chunks/PopupPositioning-BTT-_pQ3.mjs.map +1 -0
- package/dist/chunks/RangeIterator-Bh4Vl_6D.mjs +16 -0
- package/dist/chunks/RangeIterator-Bh4Vl_6D.mjs.map +1 -0
- package/dist/chunks/{Selection-DmFDwiPJ.mjs → Selection-BRTab5hO.mjs} +7 -7
- package/dist/chunks/{Selection-DmFDwiPJ.mjs.map → Selection-BRTab5hO.mjs.map} +1 -1
- package/dist/chunks/StyleRuntime-ChRjVQwL.mjs +239 -0
- package/dist/chunks/StyleRuntime-ChRjVQwL.mjs.map +1 -0
- package/dist/chunks/ToolbarItem-BpZggUGo.mjs.map +1 -1
- package/dist/chunks/{ToolbarKeyboardNav-B32OMv8r.mjs → ToolbarKeyboardNav-DhpL8zNV.mjs} +3 -3
- package/dist/chunks/{ToolbarKeyboardNav-B32OMv8r.mjs.map → ToolbarKeyboardNav-DhpL8zNV.mjs.map} +1 -1
- package/dist/chunks/{ToolbarPlugin-B6JETWaw.mjs → ToolbarPlugin-DpLVJ71w.mjs} +348 -135
- package/dist/chunks/ToolbarPlugin-DpLVJ71w.mjs.map +1 -0
- package/dist/chunks/index--n1RGpq-.mjs +171 -0
- package/dist/chunks/index--n1RGpq-.mjs.map +1 -0
- package/dist/chunks/index-4or5UzNO.mjs +168 -0
- package/dist/chunks/index-4or5UzNO.mjs.map +1 -0
- package/dist/chunks/{index-pxbbDHVH.mjs → index-ABlTDvEX.mjs} +20 -19
- package/dist/chunks/index-ABlTDvEX.mjs.map +1 -0
- package/dist/chunks/{index--z_Txzej.mjs → index-BAke7kNL.mjs} +45 -45
- package/dist/chunks/{index--z_Txzej.mjs.map → index-BAke7kNL.mjs.map} +1 -1
- package/dist/chunks/{index-DMt3ojrY.mjs → index-BXtw5PNN.mjs} +2 -2
- package/dist/chunks/{index-DMt3ojrY.mjs.map → index-BXtw5PNN.mjs.map} +1 -1
- package/dist/chunks/{index-FlTg80Pk.mjs → index-BhDXjueu.mjs} +285 -325
- package/dist/chunks/index-BhDXjueu.mjs.map +1 -0
- package/dist/chunks/{index-D0s0Q8Wc.mjs → index-BqNUfq-y.mjs} +43 -35
- package/dist/chunks/index-BqNUfq-y.mjs.map +1 -0
- package/dist/chunks/{index-CflvcXSd.mjs → index-BvqkuEY1.mjs} +21 -17
- package/dist/chunks/index-BvqkuEY1.mjs.map +1 -0
- package/dist/chunks/{index-C9gc3Bws.mjs → index-C1opJocO.mjs} +32 -32
- package/dist/chunks/{index-C9gc3Bws.mjs.map → index-C1opJocO.mjs.map} +1 -1
- package/dist/chunks/index-CWltg1wK.mjs +124 -0
- package/dist/chunks/index-CWltg1wK.mjs.map +1 -0
- package/dist/chunks/{index-D8tbbW97.mjs → index-Cd3uJLP3.mjs} +2 -2
- package/dist/chunks/{index-D8tbbW97.mjs.map → index-Cd3uJLP3.mjs.map} +1 -1
- package/dist/chunks/{index-C0cEs7Jc.mjs → index-CluzpB2b.mjs} +10 -10
- package/dist/chunks/{index-C0cEs7Jc.mjs.map → index-CluzpB2b.mjs.map} +1 -1
- package/dist/chunks/{index-CoeD4T9-.mjs → index-D3NlpmT1.mjs} +15 -11
- package/dist/chunks/index-D3NlpmT1.mjs.map +1 -0
- package/dist/chunks/{index-CAV2N-fF.mjs → index-D515iymW.mjs} +75 -74
- package/dist/chunks/{index-CAV2N-fF.mjs.map → index-D515iymW.mjs.map} +1 -1
- package/dist/chunks/{index-B-NSeaM4.mjs → index-Dk49P9N4.mjs} +2 -2
- package/dist/chunks/{index-B-NSeaM4.mjs.map → index-Dk49P9N4.mjs.map} +1 -1
- package/dist/chunks/index-DyzigvbZ.mjs +410 -0
- package/dist/chunks/index-DyzigvbZ.mjs.map +1 -0
- package/dist/chunks/index-ErZ5_a1o.mjs +296 -0
- package/dist/chunks/index-ErZ5_a1o.mjs.map +1 -0
- package/dist/chunks/{index-CNs4QQ8l.mjs → index-fsVJLutn.mjs} +52 -64
- package/dist/chunks/index-fsVJLutn.mjs.map +1 -0
- package/dist/commands/AttributedMarkCommands.d.ts +46 -0
- package/dist/commands/AttributedMarkCommands.d.ts.map +1 -0
- package/dist/commands/CommandHelpers.d.ts +21 -0
- package/dist/commands/CommandHelpers.d.ts.map +1 -0
- package/dist/commands/Commands.d.ts +2 -8
- package/dist/commands/Commands.d.ts.map +1 -1
- package/dist/commands/DeleteCommands.d.ts.map +1 -1
- package/dist/commands/GapCursorCommands.d.ts.map +1 -1
- package/dist/commands/NodeSelectionCommands.d.ts.map +1 -1
- package/dist/commands/PasteCommand.d.ts.map +1 -1
- package/dist/commands/RangeIterator.d.ts +10 -0
- package/dist/commands/RangeIterator.d.ts.map +1 -0
- package/dist/editor/DocumentParser.d.ts.map +1 -1
- package/dist/editor/DocumentSerializer.d.ts +2 -0
- package/dist/editor/DocumentSerializer.d.ts.map +1 -1
- package/dist/editor/EditorThemeController.d.ts +3 -0
- package/dist/editor/EditorThemeController.d.ts.map +1 -1
- package/dist/editor/MarkSerializer.d.ts +11 -0
- package/dist/editor/MarkSerializer.d.ts.map +1 -0
- package/dist/editor/NotectlEditor.d.ts +19 -3
- package/dist/editor/NotectlEditor.d.ts.map +1 -1
- package/dist/editor/PaperLayoutController.d.ts +2 -0
- package/dist/editor/PaperLayoutController.d.ts.map +1 -1
- package/dist/editor/styles/font-select.d.ts +1 -1
- package/dist/editor/styles/font-select.d.ts.map +1 -1
- package/dist/editor/styles/font-size-select.d.ts +1 -1
- package/dist/editor/styles/font-size-select.d.ts.map +1 -1
- package/dist/editor/styles/heading-select.d.ts +1 -1
- package/dist/editor/styles/heading-select.d.ts.map +1 -1
- package/dist/editor/styles/toolbar.d.ts +1 -1
- package/dist/editor/styles/toolbar.d.ts.map +1 -1
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/input/ClipboardHandler.d.ts +0 -2
- package/dist/input/ClipboardHandler.d.ts.map +1 -1
- package/dist/input/LegacyHTMLNormalizer.d.ts.map +1 -1
- package/dist/model/MarkSpec.d.ts +6 -0
- package/dist/model/MarkSpec.d.ts.map +1 -1
- package/dist/notectl-core.mjs +2244 -2095
- package/dist/notectl-core.mjs.map +1 -1
- package/dist/notectl-core.umd.js +2862 -2415
- package/dist/notectl-core.umd.js.map +1 -1
- package/dist/plugins/PluginManager.d.ts +2 -0
- package/dist/plugins/PluginManager.d.ts.map +1 -1
- package/dist/plugins/alignment/AlignmentPlugin.d.ts.map +1 -1
- package/dist/plugins/alignment.mjs +1 -1
- package/dist/plugins/blockquote.mjs +1 -1
- package/dist/plugins/caret-navigation.mjs +1 -1
- package/dist/plugins/code-block/CodeBlockNodeView.d.ts.map +1 -1
- package/dist/plugins/code-block.mjs +1 -1
- package/dist/plugins/font/FontPlugin.d.ts +0 -6
- package/dist/plugins/font/FontPlugin.d.ts.map +1 -1
- package/dist/plugins/font-size/FontSizeOperations.d.ts.map +1 -1
- package/dist/plugins/font-size/FontSizePlugin.d.ts +0 -5
- package/dist/plugins/font-size/FontSizePlugin.d.ts.map +1 -1
- package/dist/plugins/font-size.mjs +1 -1
- package/dist/plugins/font.mjs +1 -1
- package/dist/plugins/gap-cursor.mjs +2 -2
- package/dist/plugins/hard-break.mjs +2 -25
- package/dist/plugins/hard-break.mjs.map +1 -1
- package/dist/plugins/heading/HeadingBlockTypePicker.d.ts +1 -7
- package/dist/plugins/heading/HeadingBlockTypePicker.d.ts.map +1 -1
- package/dist/plugins/heading/HeadingPlugin.d.ts +0 -6
- package/dist/plugins/heading/HeadingPlugin.d.ts.map +1 -1
- package/dist/plugins/heading.mjs +1 -1
- package/dist/plugins/highlight/HighlightPlugin.d.ts.map +1 -1
- package/dist/plugins/highlight.mjs +1 -1
- package/dist/plugins/horizontal-rule.mjs +1 -1
- package/dist/plugins/image/ImageNodeView.d.ts.map +1 -1
- package/dist/plugins/image/ImagePlugin.d.ts.map +1 -1
- package/dist/plugins/image.mjs +1 -1
- package/dist/plugins/link/LinkPlugin.d.ts.map +1 -1
- package/dist/plugins/link.mjs +1 -1
- package/dist/plugins/list/ListPlugin.d.ts.map +1 -1
- package/dist/plugins/list.mjs +1 -1
- package/dist/plugins/print/PrintContentPreparer.d.ts.map +1 -1
- package/dist/plugins/shared/ColorGrid.d.ts +25 -0
- package/dist/plugins/shared/ColorGrid.d.ts.map +1 -0
- package/dist/plugins/shared/ColorMarkOperations.d.ts.map +1 -1
- package/dist/plugins/shared/ColorPickerPopup.d.ts.map +1 -1
- package/dist/plugins/shared/ColorValidation.d.ts +13 -2
- package/dist/plugins/shared/ColorValidation.d.ts.map +1 -1
- package/dist/plugins/shared/PopupKeyboardPatterns.d.ts +43 -0
- package/dist/plugins/shared/PopupKeyboardPatterns.d.ts.map +1 -0
- package/dist/plugins/shared/PopupManager.d.ts +45 -0
- package/dist/plugins/shared/PopupManager.d.ts.map +1 -0
- package/dist/plugins/shared/PopupPositioning.d.ts +21 -0
- package/dist/plugins/shared/PopupPositioning.d.ts.map +1 -0
- package/dist/plugins/strikethrough.mjs +1 -1
- package/dist/plugins/super-sub.mjs +1 -1
- package/dist/plugins/table/TableBorderColor.d.ts.map +1 -1
- package/dist/plugins/table/TableContextMenu.d.ts +2 -1
- package/dist/plugins/table/TableContextMenu.d.ts.map +1 -1
- package/dist/plugins/table/TableControls.d.ts.map +1 -1
- package/dist/plugins/table/TableControlsDOM.d.ts.map +1 -1
- package/dist/plugins/table/TableControlsLayout.d.ts.map +1 -1
- package/dist/plugins/table/TableNodeViews.d.ts.map +1 -1
- package/dist/plugins/table.mjs +1 -1
- package/dist/plugins/text-color/TextColorPlugin.d.ts.map +1 -1
- package/dist/plugins/text-color.mjs +1 -1
- package/dist/plugins/text-formatting.mjs +1 -1
- package/dist/plugins/toolbar/ToolbarItem.d.ts +11 -2
- package/dist/plugins/toolbar/ToolbarItem.d.ts.map +1 -1
- package/dist/plugins/toolbar/ToolbarOverflowController.d.ts +5 -1
- package/dist/plugins/toolbar/ToolbarOverflowController.d.ts.map +1 -1
- package/dist/plugins/toolbar/ToolbarPlugin.d.ts +1 -0
- package/dist/plugins/toolbar/ToolbarPlugin.d.ts.map +1 -1
- package/dist/plugins/toolbar/ToolbarPopupController.d.ts +9 -1
- package/dist/plugins/toolbar/ToolbarPopupController.d.ts.map +1 -1
- package/dist/plugins/toolbar/ToolbarRenderers.d.ts.map +1 -1
- package/dist/plugins/toolbar/ToolbarTooltip.d.ts.map +1 -1
- package/dist/plugins/toolbar/index.d.ts +1 -1
- package/dist/plugins/toolbar/index.d.ts.map +1 -1
- package/dist/plugins/toolbar.mjs +1 -1
- package/dist/state/BlockTreeOps.d.ts +21 -0
- package/dist/state/BlockTreeOps.d.ts.map +1 -0
- package/dist/state/InlineContentOps.d.ts +37 -0
- package/dist/state/InlineContentOps.d.ts.map +1 -0
- package/dist/state/StepApplication.d.ts.map +1 -1
- package/dist/style/StyleRuntime.d.ts +38 -0
- package/dist/style/StyleRuntime.d.ts.map +1 -0
- package/dist/test/PluginTestUtils.d.ts +4 -0
- package/dist/test/PluginTestUtils.d.ts.map +1 -1
- package/dist/view/Reconciler.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/chunks/ColorNames-BdsHwA2f.mjs +0 -59
- package/dist/chunks/ColorNames-BdsHwA2f.mjs.map +0 -1
- package/dist/chunks/ColorPickerPopup-xL8ZUfpB.mjs +0 -125
- package/dist/chunks/ColorPickerPopup-xL8ZUfpB.mjs.map +0 -1
- package/dist/chunks/Commands-CicwYoTQ.mjs +0 -286
- package/dist/chunks/Commands-CicwYoTQ.mjs.map +0 -1
- package/dist/chunks/MarkCommands-CC37WA7Z.mjs +0 -94
- package/dist/chunks/MarkCommands-CC37WA7Z.mjs.map +0 -1
- package/dist/chunks/ToolbarPlugin-B6JETWaw.mjs.map +0 -1
- package/dist/chunks/index-B9GkDVsx.mjs +0 -187
- package/dist/chunks/index-B9GkDVsx.mjs.map +0 -1
- package/dist/chunks/index-CKPrAOr6.mjs +0 -209
- package/dist/chunks/index-CKPrAOr6.mjs.map +0 -1
- package/dist/chunks/index-CNs4QQ8l.mjs.map +0 -1
- package/dist/chunks/index-CflvcXSd.mjs.map +0 -1
- package/dist/chunks/index-CoeD4T9-.mjs.map +0 -1
- package/dist/chunks/index-D0s0Q8Wc.mjs.map +0 -1
- package/dist/chunks/index-DfzCof6H.mjs +0 -191
- package/dist/chunks/index-DfzCof6H.mjs.map +0 -1
- package/dist/chunks/index-DyIwN_67.mjs +0 -404
- package/dist/chunks/index-DyIwN_67.mjs.map +0 -1
- package/dist/chunks/index-FlTg80Pk.mjs.map +0 -1
- package/dist/chunks/index-pxbbDHVH.mjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-C9gc3Bws.mjs","sources":["../../src/plugins/super-sub/SuperSubLocale.ts","../../src/plugins/super-sub/SuperSubPlugin.ts"],"sourcesContent":["/**\n * Locale interface and default English locale for the SuperSubPlugin.\n */\n\n// --- Locale Interface ---\n\nexport interface SuperSubLocale {\n\treadonly superscriptLabel: string;\n\treadonly superscriptTooltip: (shortcut: string) => string;\n\treadonly subscriptLabel: string;\n\treadonly subscriptTooltip: (shortcut: string) => string;\n}\n\n// --- Default English Locale ---\n\nexport const SUPER_SUB_LOCALE_EN: SuperSubLocale = {\n\tsuperscriptLabel: 'Superscript',\n\tsuperscriptTooltip: (shortcut: string) => `Superscript (${shortcut})`,\n\tsubscriptLabel: 'Subscript',\n\tsubscriptTooltip: (shortcut: string) => `Subscript (${shortcut})`,\n};\n\n// --- German Locale ---\n\nexport const SUPER_SUB_LOCALE_DE: SuperSubLocale = {\n\tsuperscriptLabel: 'Hochgestellt',\n\tsuperscriptTooltip: (shortcut: string) => `Hochgestellt (${shortcut})`,\n\tsubscriptLabel: 'Tiefgestellt',\n\tsubscriptTooltip: (shortcut: string) => `Tiefgestellt (${shortcut})`,\n};\n\n// --- Spanish Locale ---\n\nexport const SUPER_SUB_LOCALE_ES: SuperSubLocale = {\n\tsuperscriptLabel: 'Superíndice',\n\tsuperscriptTooltip: (shortcut: string) => `Superíndice (${shortcut})`,\n\tsubscriptLabel: 'Subíndice',\n\tsubscriptTooltip: (shortcut: string) => `Subíndice (${shortcut})`,\n};\n\n// --- French Locale ---\n\nexport const SUPER_SUB_LOCALE_FR: SuperSubLocale = {\n\tsuperscriptLabel: 'Exposant',\n\tsuperscriptTooltip: (shortcut: string) => `Exposant (${shortcut})`,\n\tsubscriptLabel: 'Indice',\n\tsubscriptTooltip: (shortcut: string) => `Indice (${shortcut})`,\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const SUPER_SUB_LOCALE_ZH: SuperSubLocale = {\n\tsuperscriptLabel: '上标',\n\tsuperscriptTooltip: (shortcut: string) => `上标 (${shortcut})`,\n\tsubscriptLabel: '下标',\n\tsubscriptTooltip: (shortcut: string) => `下标 (${shortcut})`,\n};\n\n// --- Russian Locale ---\n\nexport const SUPER_SUB_LOCALE_RU: SuperSubLocale = {\n\tsuperscriptLabel: 'Надстрочный',\n\tsuperscriptTooltip: (shortcut: string) => `Надстрочный (${shortcut})`,\n\tsubscriptLabel: 'Подстрочный',\n\tsubscriptTooltip: (shortcut: string) => `Подстрочный (${shortcut})`,\n};\n\n// --- Arabic Locale ---\n\nexport const SUPER_SUB_LOCALE_AR: SuperSubLocale = {\n\tsuperscriptLabel: 'مرتفع',\n\tsuperscriptTooltip: (shortcut: string) => `مرتفع (${shortcut})`,\n\tsubscriptLabel: 'منخفض',\n\tsubscriptTooltip: (shortcut: string) => `منخفض (${shortcut})`,\n};\n\n// --- Hindi Locale ---\n\nexport const SUPER_SUB_LOCALE_HI: SuperSubLocale = {\n\tsuperscriptLabel: 'सुपरस्क्रिप्ट',\n\tsuperscriptTooltip: (shortcut: string) => `सुपरस्क्रिप्ट (${shortcut})`,\n\tsubscriptLabel: 'सबस्क्रिप्ट',\n\tsubscriptTooltip: (shortcut: string) => `सबस्क्रिप्ट (${shortcut})`,\n};\n\n// --- Locale Map ---\n\nexport const SUPER_SUB_LOCALES: Record<string, SuperSubLocale> = {\n\ten: SUPER_SUB_LOCALE_EN,\n\tde: SUPER_SUB_LOCALE_DE,\n\tes: SUPER_SUB_LOCALE_ES,\n\tfr: SUPER_SUB_LOCALE_FR,\n\tzh: SUPER_SUB_LOCALE_ZH,\n\tru: SUPER_SUB_LOCALE_RU,\n\tar: SUPER_SUB_LOCALE_AR,\n\thi: SUPER_SUB_LOCALE_HI,\n};\n","/**\n * SuperSubPlugin: registers superscript and subscript inline marks with\n * MarkSpecs, toggle commands, keyboard shortcuts, toolbar buttons, and\n * a middleware that enforces mutual exclusivity between the two marks.\n *\n * Data-driven — each mark type is defined declaratively and all\n * registrations are derived from the same definition table.\n */\n\nimport { isMarkActive, toggleMark } from '../../commands/Commands.js';\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport type { Mark } from '../../model/Document.js';\nimport type { ParseRule } from '../../model/ParseRule.js';\nimport type { SanitizeConfig } from '../../model/SanitizeConfig.js';\nimport { markType as mkType } from '../../model/TypeBrands.js';\nimport type { RemoveMarkStep, Step } from '../../state/Transaction.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { formatShortcut } from '../toolbar/ToolbarItem.js';\nimport { SUPER_SUB_LOCALES, type SuperSubLocale } from './SuperSubLocale.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface MarkAttrRegistry {\n\t\tsuperscript: Record<string, never>;\n\t\tsubscript: Record<string, never>;\n\t}\n}\n\n// --- Configuration ---\n\n/** Controls toolbar button visibility per mark. */\nexport interface SuperSubToolbarConfig {\n\treadonly superscript?: boolean;\n\treadonly subscript?: boolean;\n}\n\n/** Controls which marks are enabled and which toolbar buttons are shown. */\nexport interface SuperSubConfig {\n\treadonly superscript: boolean;\n\treadonly subscript: boolean;\n\treadonly toolbar?: SuperSubToolbarConfig;\n\t/** When true, a separator is rendered after the last toolbar item. */\n\treadonly separatorAfter?: boolean;\n\treadonly locale?: SuperSubLocale;\n}\n\nconst DEFAULT_CONFIG: SuperSubConfig = {\n\tsuperscript: true,\n\tsubscript: true,\n};\n\n// --- Mark Definitions ---\n\ninterface MarkDefinition {\n\treadonly type: 'superscript' | 'subscript';\n\treadonly opposite: 'superscript' | 'subscript';\n\treadonly configKey: keyof Omit<SuperSubConfig, 'toolbar' | 'separatorAfter' | 'locale'>;\n\treadonly rank: number;\n\treadonly tag: string;\n\treadonly label: string;\n\treadonly icon: string;\n\treadonly keyBinding: string;\n\treadonly toolbarPriority: number;\n\treadonly toHTMLString: (content: string) => string;\n\treadonly parseHTML: readonly ParseRule[];\n\treadonly sanitize: SanitizeConfig;\n}\n\nconst SUPERSCRIPT_ICON: string = [\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">',\n\t'<path d=\"M16 7.41L11.41 12 16 16.59 14.59 18l-6-6 6-6z\"',\n\t' fill=\"none\"/>',\n\t'<path d=\"M9.64 7.64c.23-.5.36-1.05.36-1.64',\n\t' 0-2.21-1.79-4-4-4H2v14h4.36c2.34 0 4.24-1.9',\n\t' 4.24-4.24 0-1.6-.89-2.99-2.2-3.71zM4.5 4.5H6c.83',\n\t' 0 1.5.67 1.5 1.5S6.83 7.5 6 7.5H4.5v-3zm2 9H4.5v-3H6.5c.83',\n\t' 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z\" fill=\"none\"/>',\n\t'<path d=\"M15.97 3.84c0-.47.19-.91.53-1.21.34-.31.8-.49',\n\t' 1.3-.49.5 0 .95.18 1.28.48.32.3.5.7.51 1.15h1.59c-.02',\n\t'-.96-.43-1.83-1.13-2.42C19.36.77 18.45.44 17.5.44c-.88',\n\t' 0-1.74.28-2.39.8-.67.53-1.06 1.28-1.06 2.1 0 .76.34',\n\t' 1.47.93 1.97.59.49 1.41.84 2.32 1.15.7.24 1.26.5 1.62.8.35.3.53.64.53',\n\t' 1.02 0 .48-.2.93-.55 1.24-.36.3-.84.48-1.37.48-.55 0-1.04-.2-1.39-.54',\n\t'-.34-.33-.53-.8-.53-1.32h-1.58c.01 1.02.43 1.95 1.16 2.57.72.62 1.67.96',\n\t' 2.67.96.92 0 1.81-.3 2.46-.84.67-.56 1.04-1.33 1.04-2.18 0-.81-.36-1.56',\n\t'-.99-2.08-.62-.51-1.48-.88-2.43-1.2-.67-.23-1.2-.47-1.52-.75-.32-.27-.46',\n\t'-.59-.46-.94z\"/>',\n\t'<path d=\"M5.88 20h2.66l3.4-5.42L15.3 20h2.67l-4.73-7.38',\n\t' 4.37-6.62h-2.6l-3.07 4.98L8.92 6h-2.6l4.26 6.58z\"/>',\n\t'</svg>',\n].join('');\n\nconst SUBSCRIPT_ICON: string = [\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">',\n\t'<path d=\"M15.97 16.84c0-.47.19-.91.53-1.21.34-.31.8-.49',\n\t' 1.3-.49.5 0 .95.18 1.28.48.32.3.5.7.51 1.15h1.59c-.02',\n\t'-.96-.43-1.83-1.13-2.42-.7-.58-1.61-.91-2.56-.91-.88',\n\t' 0-1.74.28-2.39.8-.67.53-1.06 1.28-1.06 2.1 0 .76.34',\n\t' 1.47.93 1.97.59.49 1.41.84 2.32 1.15.7.24 1.26.5 1.62.8.35.3.53.64.53',\n\t' 1.02 0 .48-.2.93-.55 1.24-.36.3-.84.48-1.37.48-.55 0-1.04-.2-1.39-.54',\n\t'-.34-.33-.53-.8-.53-1.32h-1.58c.01 1.02.43 1.95 1.16 2.57.72.62 1.67.96',\n\t' 2.67.96.92 0 1.81-.3 2.46-.84.67-.56 1.04-1.33 1.04-2.18 0-.81-.36-1.56',\n\t'-.99-2.08-.62-.51-1.48-.88-2.43-1.2-.67-.23-1.2-.47-1.52-.75-.32-.27-.46',\n\t'-.59-.46-.94z\"/>',\n\t'<path d=\"M5.88 18h2.66l3.4-5.42L15.3 18h2.67l-4.73-7.38',\n\t' 4.37-6.62h-2.6l-3.07 4.98L8.92 4h-2.6l4.26 6.58z\"/>',\n\t'</svg>',\n].join('');\n\nconst MARK_DEFINITIONS: readonly MarkDefinition[] = [\n\t{\n\t\ttype: 'superscript',\n\t\topposite: 'subscript',\n\t\tconfigKey: 'superscript',\n\t\trank: 4,\n\t\ttag: 'sup',\n\t\tlabel: 'Superscript',\n\t\ticon: SUPERSCRIPT_ICON,\n\t\tkeyBinding: 'Mod-.',\n\t\ttoolbarPriority: 50,\n\t\ttoHTMLString: (content) => `<sup>${content}</sup>`,\n\t\tparseHTML: [{ tag: 'sup' }],\n\t\tsanitize: { tags: ['sup'] },\n\t},\n\t{\n\t\ttype: 'subscript',\n\t\topposite: 'superscript',\n\t\tconfigKey: 'subscript',\n\t\trank: 4,\n\t\ttag: 'sub',\n\t\tlabel: 'Subscript',\n\t\ticon: SUBSCRIPT_ICON,\n\t\tkeyBinding: 'Mod-,',\n\t\ttoolbarPriority: 51,\n\t\ttoHTMLString: (content) => `<sub>${content}</sub>`,\n\t\tparseHTML: [{ tag: 'sub' }],\n\t\tsanitize: { tags: ['sub'] },\n\t},\n];\n\n// --- Plugin ---\n\nexport class SuperSubPlugin implements Plugin {\n\treadonly id = 'super-sub';\n\treadonly name = 'Superscript & Subscript';\n\treadonly priority = 23;\n\n\tprivate readonly config: SuperSubConfig;\n\tprivate locale!: SuperSubLocale;\n\n\tconstructor(config?: Partial<SuperSubConfig>) {\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(SUPER_SUB_LOCALES, context, this.config.locale);\n\n\t\tconst enabledMarks: MarkDefinition[] = MARK_DEFINITIONS.filter(\n\t\t\t(def) => this.config[def.configKey],\n\t\t);\n\n\t\tconst visibleToolbarMarks: MarkDefinition[] = enabledMarks.filter((def) =>\n\t\t\tthis.isToolbarVisible(def.configKey),\n\t\t);\n\t\tconst lastVisibleMark: MarkDefinition | undefined = visibleToolbarMarks.at(-1);\n\n\t\tfor (const def of enabledMarks) {\n\t\t\tconst isSeparatorTarget: boolean = !!this.config.separatorAfter && def === lastVisibleMark;\n\t\t\tthis.registerMark(context, def, isSeparatorTarget);\n\t\t}\n\n\t\tthis.registerKeymaps(context, enabledMarks);\n\t\tthis.registerExclusivityMiddleware(context, enabledMarks);\n\t\tthis.registerDisabledToolbarItems(context);\n\t}\n\n\tprivate registerMark(context: PluginContext, def: MarkDefinition, separatorAfter: boolean): void {\n\t\tconst commandName: string = toCommandName(def.type);\n\t\tconst toolbarVisible: boolean = this.isToolbarVisible(def.configKey);\n\n\t\tcontext.registerMarkSpec({\n\t\t\ttype: def.type,\n\t\t\trank: def.rank,\n\t\t\ttoDOM() {\n\t\t\t\treturn document.createElement(def.tag);\n\t\t\t},\n\t\t\ttoHTMLString: (_mark, content) => def.toHTMLString(content),\n\t\t\tparseHTML: def.parseHTML,\n\t\t\tsanitize: def.sanitize,\n\t\t});\n\n\t\tcontext.registerCommand(commandName, () => {\n\t\t\tconst tr = toggleMark(context.getState(), mkType(def.type));\n\t\t\tif (tr) {\n\t\t\t\tcontext.dispatch(tr);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t});\n\n\t\tif (toolbarVisible) {\n\t\t\tconst label: string =\n\t\t\t\tdef.type === 'superscript' ? this.locale.superscriptLabel : this.locale.subscriptLabel;\n\t\t\tconst tooltip: string =\n\t\t\t\tdef.type === 'superscript'\n\t\t\t\t\t? this.locale.superscriptTooltip(formatShortcut(def.keyBinding))\n\t\t\t\t\t: this.locale.subscriptTooltip(formatShortcut(def.keyBinding));\n\t\t\tcontext.registerToolbarItem({\n\t\t\t\tid: def.type,\n\t\t\t\tgroup: 'format',\n\t\t\t\ticon: def.icon,\n\t\t\t\tlabel,\n\t\t\t\ttooltip,\n\t\t\t\tcommand: commandName,\n\t\t\t\tpriority: def.toolbarPriority,\n\t\t\t\tseparatorAfter,\n\t\t\t\tisActive: (state) => isMarkActive(state, mkType(def.type)),\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate registerKeymaps(context: PluginContext, marks: readonly MarkDefinition[]): void {\n\t\tconst keymap: Record<string, () => boolean> = {};\n\t\tfor (const def of marks) {\n\t\t\tconst commandName: string = toCommandName(def.type);\n\t\t\tkeymap[def.keyBinding] = () => context.executeCommand(commandName);\n\t\t}\n\t\tif (Object.keys(keymap).length > 0) {\n\t\t\tcontext.registerKeymap(keymap);\n\t\t}\n\t}\n\n\t/**\n\t * Ensures superscript and subscript are mutually exclusive.\n\t * When an addMark step for one type is found, a removeMark step\n\t * for the opposite type is injected. For stored marks, the opposite\n\t * mark is filtered out.\n\t */\n\tprivate registerExclusivityMiddleware(\n\t\tcontext: PluginContext,\n\t\tenabledMarks: readonly MarkDefinition[],\n\t): void {\n\t\tconst bothEnabled: boolean =\n\t\t\tenabledMarks.some((d) => d.type === 'superscript') &&\n\t\t\tenabledMarks.some((d) => d.type === 'subscript');\n\n\t\tif (!bothEnabled) return;\n\n\t\tcontext.registerMiddleware(\n\t\t\t(tr, _state, next) => {\n\t\t\t\tlet patched = false;\n\n\t\t\t\t// Handle addMark steps: inject removeMark for the opposite type\n\t\t\t\tconst patchedSteps: Step[] = [];\n\t\t\t\tfor (const step of tr.steps) {\n\t\t\t\t\tif (step.type !== 'addMark') {\n\t\t\t\t\t\tpatchedSteps.push(step);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst markName: string = step.mark.type;\n\t\t\t\t\tconst def: MarkDefinition | undefined = MARK_DEFINITIONS.find((d) => d.type === markName);\n\t\t\t\t\tif (!def) {\n\t\t\t\t\t\tpatchedSteps.push(step);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tpatched = true;\n\t\t\t\t\tconst removeStep: RemoveMarkStep = {\n\t\t\t\t\t\ttype: 'removeMark',\n\t\t\t\t\t\tblockId: step.blockId,\n\t\t\t\t\t\tfrom: step.from,\n\t\t\t\t\t\tto: step.to,\n\t\t\t\t\t\tmark: { type: mkType(def.opposite) },\n\t\t\t\t\t\t...(step.path ? { path: step.path } : {}),\n\t\t\t\t\t};\n\t\t\t\t\tpatchedSteps.push(removeStep, step);\n\t\t\t\t}\n\n\t\t\t\t// Handle stored marks: remove the opposite mark\n\t\t\t\tlet storedMarksAfter: readonly Mark[] | null = tr.storedMarksAfter;\n\t\t\t\tif (storedMarksAfter) {\n\t\t\t\t\tconst hasSup: boolean = storedMarksAfter.some((m) => m.type === 'superscript');\n\t\t\t\t\tconst hasSub: boolean = storedMarksAfter.some((m) => m.type === 'subscript');\n\n\t\t\t\t\tif (hasSup && hasSub) {\n\t\t\t\t\t\t// Keep the one that was most recently added (last in array)\n\t\t\t\t\t\tconst lastSupIdx: number = storedMarksAfter.findLastIndex(\n\t\t\t\t\t\t\t(m) => m.type === 'superscript',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst lastSubIdx: number = storedMarksAfter.findLastIndex(\n\t\t\t\t\t\t\t(m) => m.type === 'subscript',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst removeType: string = lastSupIdx > lastSubIdx ? 'subscript' : 'superscript';\n\n\t\t\t\t\t\tstoredMarksAfter = storedMarksAfter.filter((m) => m.type !== removeType);\n\t\t\t\t\t\tpatched = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tnext(patched ? { ...tr, steps: patchedSteps, storedMarksAfter } : tr);\n\t\t\t},\n\t\t\t{ name: 'super-sub:exclusivity' },\n\t\t);\n\t}\n\n\t/**\n\t * Registers disabled toolbar buttons for marks whose feature is disabled\n\t * but whose toolbar button is explicitly requested.\n\t */\n\tprivate registerDisabledToolbarItems(context: PluginContext): void {\n\t\tif (!this.config.toolbar) return;\n\n\t\tfor (const def of MARK_DEFINITIONS) {\n\t\t\tconst featureEnabled: boolean = this.config[def.configKey];\n\t\t\tconst toolbarVisible: boolean = this.config.toolbar[def.configKey] ?? true;\n\n\t\t\tif (!featureEnabled && toolbarVisible) {\n\t\t\t\tconst label: string =\n\t\t\t\t\tdef.type === 'superscript' ? this.locale.superscriptLabel : this.locale.subscriptLabel;\n\t\t\t\tcontext.registerToolbarItem({\n\t\t\t\t\tid: def.type,\n\t\t\t\t\tgroup: 'format',\n\t\t\t\t\ticon: def.icon,\n\t\t\t\t\tlabel,\n\t\t\t\t\tcommand: toCommandName(def.type),\n\t\t\t\t\tpriority: def.toolbarPriority,\n\t\t\t\t\tisEnabled: () => false,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate isToolbarVisible(\n\t\tconfigKey: keyof Omit<SuperSubConfig, 'toolbar' | 'separatorAfter' | 'locale'>,\n\t): boolean {\n\t\tif (!this.config.toolbar) return true;\n\t\treturn this.config.toolbar[configKey] ?? true;\n\t}\n}\n\n/** Converts a mark type to its toggle command name (e.g. 'superscript' → 'toggleSuperscript'). */\nfunction toCommandName(markType: string): string {\n\treturn `toggle${markType.charAt(0).toUpperCase()}${markType.slice(1)}`;\n}\n"],"names":["SUPER_SUB_LOCALE_EN","superscriptLabel","superscriptTooltip","shortcut","subscriptLabel","subscriptTooltip","SUPER_SUB_LOCALES","en","de","es","fr","zh","ru","ar","hi","DEFAULT_CONFIG","superscript","subscript","MARK_DEFINITIONS","type","opposite","configKey","rank","tag","label","icon","join","keyBinding","toolbarPriority","toHTMLString","content","parseHTML","sanitize","tags","SuperSubPlugin","id","name","priority","config","locale","this","context","resolvePluginLocale","enabledMarks","filter","def","lastVisibleMark","isToolbarVisible","at","isSeparatorTarget","separatorAfter","registerMark","registerKeymaps","registerExclusivityMiddleware","registerDisabledToolbarItems","commandName","toCommandName","toolbarVisible","registerMarkSpec","toDOM","document","createElement","_mark","registerCommand","tr","toggleMark","getState","mkType","dispatch","tooltip","formatShortcut","registerToolbarItem","group","command","isActive","state","isMarkActive","marks","keymap","executeCommand","Object","keys","length","registerKeymap","some","d","registerMiddleware","_state","next","patched","patchedSteps","step","steps","push","markName","mark","find","removeStep","blockId","from","to","path","storedMarksAfter","hasSup","m","hasSub","removeType","findLastIndex","toolbar","featureEnabled","isEnabled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AA,MAAM,CAAA;AAAA,MAEnB;AAAA,IACD;AAAA,EACD;AAAA,EAEQ,iBACPzF,IAAAA;AAEA,YAAKmB,KAAKF,OAAOsE,YACVpE,KAAKF,OAAOsE,QAAQvF,EAAAA,KAAAA;AAAAA,EAC5B;AAAA;AAID,SAASmC,EAAcuD,IAAAA;AACtB,SAAO,SAASA,GAASC,OAAO,GAAGC,YAAAA,CAAAA,GAAgBF,GAASG,MAAM,CAAA,CAAA;AACnE;"}
|
|
1
|
+
{"version":3,"file":"index-C1opJocO.mjs","sources":["../../src/plugins/super-sub/SuperSubLocale.ts","../../src/plugins/super-sub/SuperSubPlugin.ts"],"sourcesContent":["/**\n * Locale interface and default English locale for the SuperSubPlugin.\n */\n\n// --- Locale Interface ---\n\nexport interface SuperSubLocale {\n\treadonly superscriptLabel: string;\n\treadonly superscriptTooltip: (shortcut: string) => string;\n\treadonly subscriptLabel: string;\n\treadonly subscriptTooltip: (shortcut: string) => string;\n}\n\n// --- Default English Locale ---\n\nexport const SUPER_SUB_LOCALE_EN: SuperSubLocale = {\n\tsuperscriptLabel: 'Superscript',\n\tsuperscriptTooltip: (shortcut: string) => `Superscript (${shortcut})`,\n\tsubscriptLabel: 'Subscript',\n\tsubscriptTooltip: (shortcut: string) => `Subscript (${shortcut})`,\n};\n\n// --- German Locale ---\n\nexport const SUPER_SUB_LOCALE_DE: SuperSubLocale = {\n\tsuperscriptLabel: 'Hochgestellt',\n\tsuperscriptTooltip: (shortcut: string) => `Hochgestellt (${shortcut})`,\n\tsubscriptLabel: 'Tiefgestellt',\n\tsubscriptTooltip: (shortcut: string) => `Tiefgestellt (${shortcut})`,\n};\n\n// --- Spanish Locale ---\n\nexport const SUPER_SUB_LOCALE_ES: SuperSubLocale = {\n\tsuperscriptLabel: 'Superíndice',\n\tsuperscriptTooltip: (shortcut: string) => `Superíndice (${shortcut})`,\n\tsubscriptLabel: 'Subíndice',\n\tsubscriptTooltip: (shortcut: string) => `Subíndice (${shortcut})`,\n};\n\n// --- French Locale ---\n\nexport const SUPER_SUB_LOCALE_FR: SuperSubLocale = {\n\tsuperscriptLabel: 'Exposant',\n\tsuperscriptTooltip: (shortcut: string) => `Exposant (${shortcut})`,\n\tsubscriptLabel: 'Indice',\n\tsubscriptTooltip: (shortcut: string) => `Indice (${shortcut})`,\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const SUPER_SUB_LOCALE_ZH: SuperSubLocale = {\n\tsuperscriptLabel: '上标',\n\tsuperscriptTooltip: (shortcut: string) => `上标 (${shortcut})`,\n\tsubscriptLabel: '下标',\n\tsubscriptTooltip: (shortcut: string) => `下标 (${shortcut})`,\n};\n\n// --- Russian Locale ---\n\nexport const SUPER_SUB_LOCALE_RU: SuperSubLocale = {\n\tsuperscriptLabel: 'Надстрочный',\n\tsuperscriptTooltip: (shortcut: string) => `Надстрочный (${shortcut})`,\n\tsubscriptLabel: 'Подстрочный',\n\tsubscriptTooltip: (shortcut: string) => `Подстрочный (${shortcut})`,\n};\n\n// --- Arabic Locale ---\n\nexport const SUPER_SUB_LOCALE_AR: SuperSubLocale = {\n\tsuperscriptLabel: 'مرتفع',\n\tsuperscriptTooltip: (shortcut: string) => `مرتفع (${shortcut})`,\n\tsubscriptLabel: 'منخفض',\n\tsubscriptTooltip: (shortcut: string) => `منخفض (${shortcut})`,\n};\n\n// --- Hindi Locale ---\n\nexport const SUPER_SUB_LOCALE_HI: SuperSubLocale = {\n\tsuperscriptLabel: 'सुपरस्क्रिप्ट',\n\tsuperscriptTooltip: (shortcut: string) => `सुपरस्क्रिप्ट (${shortcut})`,\n\tsubscriptLabel: 'सबस्क्रिप्ट',\n\tsubscriptTooltip: (shortcut: string) => `सबस्क्रिप्ट (${shortcut})`,\n};\n\n// --- Locale Map ---\n\nexport const SUPER_SUB_LOCALES: Record<string, SuperSubLocale> = {\n\ten: SUPER_SUB_LOCALE_EN,\n\tde: SUPER_SUB_LOCALE_DE,\n\tes: SUPER_SUB_LOCALE_ES,\n\tfr: SUPER_SUB_LOCALE_FR,\n\tzh: SUPER_SUB_LOCALE_ZH,\n\tru: SUPER_SUB_LOCALE_RU,\n\tar: SUPER_SUB_LOCALE_AR,\n\thi: SUPER_SUB_LOCALE_HI,\n};\n","/**\n * SuperSubPlugin: registers superscript and subscript inline marks with\n * MarkSpecs, toggle commands, keyboard shortcuts, toolbar buttons, and\n * a middleware that enforces mutual exclusivity between the two marks.\n *\n * Data-driven — each mark type is defined declaratively and all\n * registrations are derived from the same definition table.\n */\n\nimport { isMarkActive, toggleMark } from '../../commands/Commands.js';\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport type { Mark } from '../../model/Document.js';\nimport type { ParseRule } from '../../model/ParseRule.js';\nimport type { SanitizeConfig } from '../../model/SanitizeConfig.js';\nimport { markType as mkType } from '../../model/TypeBrands.js';\nimport type { RemoveMarkStep, Step } from '../../state/Transaction.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { formatShortcut } from '../toolbar/ToolbarItem.js';\nimport { SUPER_SUB_LOCALES, type SuperSubLocale } from './SuperSubLocale.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface MarkAttrRegistry {\n\t\tsuperscript: Record<string, never>;\n\t\tsubscript: Record<string, never>;\n\t}\n}\n\n// --- Configuration ---\n\n/** Controls toolbar button visibility per mark. */\nexport interface SuperSubToolbarConfig {\n\treadonly superscript?: boolean;\n\treadonly subscript?: boolean;\n}\n\n/** Controls which marks are enabled and which toolbar buttons are shown. */\nexport interface SuperSubConfig {\n\treadonly superscript: boolean;\n\treadonly subscript: boolean;\n\treadonly toolbar?: SuperSubToolbarConfig;\n\t/** When true, a separator is rendered after the last toolbar item. */\n\treadonly separatorAfter?: boolean;\n\treadonly locale?: SuperSubLocale;\n}\n\nconst DEFAULT_CONFIG: SuperSubConfig = {\n\tsuperscript: true,\n\tsubscript: true,\n};\n\n// --- Mark Definitions ---\n\ninterface MarkDefinition {\n\treadonly type: 'superscript' | 'subscript';\n\treadonly opposite: 'superscript' | 'subscript';\n\treadonly configKey: keyof Omit<SuperSubConfig, 'toolbar' | 'separatorAfter' | 'locale'>;\n\treadonly rank: number;\n\treadonly tag: string;\n\treadonly label: string;\n\treadonly icon: string;\n\treadonly keyBinding: string;\n\treadonly toolbarPriority: number;\n\treadonly toHTMLString: (content: string) => string;\n\treadonly parseHTML: readonly ParseRule[];\n\treadonly sanitize: SanitizeConfig;\n}\n\nconst SUPERSCRIPT_ICON: string = [\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">',\n\t'<path d=\"M16 7.41L11.41 12 16 16.59 14.59 18l-6-6 6-6z\"',\n\t' fill=\"none\"/>',\n\t'<path d=\"M9.64 7.64c.23-.5.36-1.05.36-1.64',\n\t' 0-2.21-1.79-4-4-4H2v14h4.36c2.34 0 4.24-1.9',\n\t' 4.24-4.24 0-1.6-.89-2.99-2.2-3.71zM4.5 4.5H6c.83',\n\t' 0 1.5.67 1.5 1.5S6.83 7.5 6 7.5H4.5v-3zm2 9H4.5v-3H6.5c.83',\n\t' 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z\" fill=\"none\"/>',\n\t'<path d=\"M15.97 3.84c0-.47.19-.91.53-1.21.34-.31.8-.49',\n\t' 1.3-.49.5 0 .95.18 1.28.48.32.3.5.7.51 1.15h1.59c-.02',\n\t'-.96-.43-1.83-1.13-2.42C19.36.77 18.45.44 17.5.44c-.88',\n\t' 0-1.74.28-2.39.8-.67.53-1.06 1.28-1.06 2.1 0 .76.34',\n\t' 1.47.93 1.97.59.49 1.41.84 2.32 1.15.7.24 1.26.5 1.62.8.35.3.53.64.53',\n\t' 1.02 0 .48-.2.93-.55 1.24-.36.3-.84.48-1.37.48-.55 0-1.04-.2-1.39-.54',\n\t'-.34-.33-.53-.8-.53-1.32h-1.58c.01 1.02.43 1.95 1.16 2.57.72.62 1.67.96',\n\t' 2.67.96.92 0 1.81-.3 2.46-.84.67-.56 1.04-1.33 1.04-2.18 0-.81-.36-1.56',\n\t'-.99-2.08-.62-.51-1.48-.88-2.43-1.2-.67-.23-1.2-.47-1.52-.75-.32-.27-.46',\n\t'-.59-.46-.94z\"/>',\n\t'<path d=\"M5.88 20h2.66l3.4-5.42L15.3 20h2.67l-4.73-7.38',\n\t' 4.37-6.62h-2.6l-3.07 4.98L8.92 6h-2.6l4.26 6.58z\"/>',\n\t'</svg>',\n].join('');\n\nconst SUBSCRIPT_ICON: string = [\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\">',\n\t'<path d=\"M15.97 16.84c0-.47.19-.91.53-1.21.34-.31.8-.49',\n\t' 1.3-.49.5 0 .95.18 1.28.48.32.3.5.7.51 1.15h1.59c-.02',\n\t'-.96-.43-1.83-1.13-2.42-.7-.58-1.61-.91-2.56-.91-.88',\n\t' 0-1.74.28-2.39.8-.67.53-1.06 1.28-1.06 2.1 0 .76.34',\n\t' 1.47.93 1.97.59.49 1.41.84 2.32 1.15.7.24 1.26.5 1.62.8.35.3.53.64.53',\n\t' 1.02 0 .48-.2.93-.55 1.24-.36.3-.84.48-1.37.48-.55 0-1.04-.2-1.39-.54',\n\t'-.34-.33-.53-.8-.53-1.32h-1.58c.01 1.02.43 1.95 1.16 2.57.72.62 1.67.96',\n\t' 2.67.96.92 0 1.81-.3 2.46-.84.67-.56 1.04-1.33 1.04-2.18 0-.81-.36-1.56',\n\t'-.99-2.08-.62-.51-1.48-.88-2.43-1.2-.67-.23-1.2-.47-1.52-.75-.32-.27-.46',\n\t'-.59-.46-.94z\"/>',\n\t'<path d=\"M5.88 18h2.66l3.4-5.42L15.3 18h2.67l-4.73-7.38',\n\t' 4.37-6.62h-2.6l-3.07 4.98L8.92 4h-2.6l4.26 6.58z\"/>',\n\t'</svg>',\n].join('');\n\nconst MARK_DEFINITIONS: readonly MarkDefinition[] = [\n\t{\n\t\ttype: 'superscript',\n\t\topposite: 'subscript',\n\t\tconfigKey: 'superscript',\n\t\trank: 4,\n\t\ttag: 'sup',\n\t\tlabel: 'Superscript',\n\t\ticon: SUPERSCRIPT_ICON,\n\t\tkeyBinding: 'Mod-.',\n\t\ttoolbarPriority: 50,\n\t\ttoHTMLString: (content) => `<sup>${content}</sup>`,\n\t\tparseHTML: [{ tag: 'sup' }],\n\t\tsanitize: { tags: ['sup'] },\n\t},\n\t{\n\t\ttype: 'subscript',\n\t\topposite: 'superscript',\n\t\tconfigKey: 'subscript',\n\t\trank: 4,\n\t\ttag: 'sub',\n\t\tlabel: 'Subscript',\n\t\ticon: SUBSCRIPT_ICON,\n\t\tkeyBinding: 'Mod-,',\n\t\ttoolbarPriority: 51,\n\t\ttoHTMLString: (content) => `<sub>${content}</sub>`,\n\t\tparseHTML: [{ tag: 'sub' }],\n\t\tsanitize: { tags: ['sub'] },\n\t},\n];\n\n// --- Plugin ---\n\nexport class SuperSubPlugin implements Plugin {\n\treadonly id = 'super-sub';\n\treadonly name = 'Superscript & Subscript';\n\treadonly priority = 23;\n\n\tprivate readonly config: SuperSubConfig;\n\tprivate locale!: SuperSubLocale;\n\n\tconstructor(config?: Partial<SuperSubConfig>) {\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(SUPER_SUB_LOCALES, context, this.config.locale);\n\n\t\tconst enabledMarks: MarkDefinition[] = MARK_DEFINITIONS.filter(\n\t\t\t(def) => this.config[def.configKey],\n\t\t);\n\n\t\tconst visibleToolbarMarks: MarkDefinition[] = enabledMarks.filter((def) =>\n\t\t\tthis.isToolbarVisible(def.configKey),\n\t\t);\n\t\tconst lastVisibleMark: MarkDefinition | undefined = visibleToolbarMarks.at(-1);\n\n\t\tfor (const def of enabledMarks) {\n\t\t\tconst isSeparatorTarget: boolean = !!this.config.separatorAfter && def === lastVisibleMark;\n\t\t\tthis.registerMark(context, def, isSeparatorTarget);\n\t\t}\n\n\t\tthis.registerKeymaps(context, enabledMarks);\n\t\tthis.registerExclusivityMiddleware(context, enabledMarks);\n\t\tthis.registerDisabledToolbarItems(context);\n\t}\n\n\tprivate registerMark(context: PluginContext, def: MarkDefinition, separatorAfter: boolean): void {\n\t\tconst commandName: string = toCommandName(def.type);\n\t\tconst toolbarVisible: boolean = this.isToolbarVisible(def.configKey);\n\n\t\tcontext.registerMarkSpec({\n\t\t\ttype: def.type,\n\t\t\trank: def.rank,\n\t\t\ttoDOM() {\n\t\t\t\treturn document.createElement(def.tag);\n\t\t\t},\n\t\t\ttoHTMLString: (_mark, content) => def.toHTMLString(content),\n\t\t\tparseHTML: def.parseHTML,\n\t\t\tsanitize: def.sanitize,\n\t\t});\n\n\t\tcontext.registerCommand(commandName, () => {\n\t\t\tconst tr = toggleMark(context.getState(), mkType(def.type));\n\t\t\tif (tr) {\n\t\t\t\tcontext.dispatch(tr);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t});\n\n\t\tif (toolbarVisible) {\n\t\t\tconst label: string =\n\t\t\t\tdef.type === 'superscript' ? this.locale.superscriptLabel : this.locale.subscriptLabel;\n\t\t\tconst tooltip: string =\n\t\t\t\tdef.type === 'superscript'\n\t\t\t\t\t? this.locale.superscriptTooltip(formatShortcut(def.keyBinding))\n\t\t\t\t\t: this.locale.subscriptTooltip(formatShortcut(def.keyBinding));\n\t\t\tcontext.registerToolbarItem({\n\t\t\t\tid: def.type,\n\t\t\t\tgroup: 'format',\n\t\t\t\ticon: def.icon,\n\t\t\t\tlabel,\n\t\t\t\ttooltip,\n\t\t\t\tcommand: commandName,\n\t\t\t\tpriority: def.toolbarPriority,\n\t\t\t\tseparatorAfter,\n\t\t\t\tisActive: (state) => isMarkActive(state, mkType(def.type)),\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate registerKeymaps(context: PluginContext, marks: readonly MarkDefinition[]): void {\n\t\tconst keymap: Record<string, () => boolean> = {};\n\t\tfor (const def of marks) {\n\t\t\tconst commandName: string = toCommandName(def.type);\n\t\t\tkeymap[def.keyBinding] = () => context.executeCommand(commandName);\n\t\t}\n\t\tif (Object.keys(keymap).length > 0) {\n\t\t\tcontext.registerKeymap(keymap);\n\t\t}\n\t}\n\n\t/**\n\t * Ensures superscript and subscript are mutually exclusive.\n\t * When an addMark step for one type is found, a removeMark step\n\t * for the opposite type is injected. For stored marks, the opposite\n\t * mark is filtered out.\n\t */\n\tprivate registerExclusivityMiddleware(\n\t\tcontext: PluginContext,\n\t\tenabledMarks: readonly MarkDefinition[],\n\t): void {\n\t\tconst bothEnabled: boolean =\n\t\t\tenabledMarks.some((d) => d.type === 'superscript') &&\n\t\t\tenabledMarks.some((d) => d.type === 'subscript');\n\n\t\tif (!bothEnabled) return;\n\n\t\tcontext.registerMiddleware(\n\t\t\t(tr, _state, next) => {\n\t\t\t\tlet patched = false;\n\n\t\t\t\t// Handle addMark steps: inject removeMark for the opposite type\n\t\t\t\tconst patchedSteps: Step[] = [];\n\t\t\t\tfor (const step of tr.steps) {\n\t\t\t\t\tif (step.type !== 'addMark') {\n\t\t\t\t\t\tpatchedSteps.push(step);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst markName: string = step.mark.type;\n\t\t\t\t\tconst def: MarkDefinition | undefined = MARK_DEFINITIONS.find((d) => d.type === markName);\n\t\t\t\t\tif (!def) {\n\t\t\t\t\t\tpatchedSteps.push(step);\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tpatched = true;\n\t\t\t\t\tconst removeStep: RemoveMarkStep = {\n\t\t\t\t\t\ttype: 'removeMark',\n\t\t\t\t\t\tblockId: step.blockId,\n\t\t\t\t\t\tfrom: step.from,\n\t\t\t\t\t\tto: step.to,\n\t\t\t\t\t\tmark: { type: mkType(def.opposite) },\n\t\t\t\t\t\t...(step.path ? { path: step.path } : {}),\n\t\t\t\t\t};\n\t\t\t\t\tpatchedSteps.push(removeStep, step);\n\t\t\t\t}\n\n\t\t\t\t// Handle stored marks: remove the opposite mark\n\t\t\t\tlet storedMarksAfter: readonly Mark[] | null = tr.storedMarksAfter;\n\t\t\t\tif (storedMarksAfter) {\n\t\t\t\t\tconst hasSup: boolean = storedMarksAfter.some((m) => m.type === 'superscript');\n\t\t\t\t\tconst hasSub: boolean = storedMarksAfter.some((m) => m.type === 'subscript');\n\n\t\t\t\t\tif (hasSup && hasSub) {\n\t\t\t\t\t\t// Keep the one that was most recently added (last in array)\n\t\t\t\t\t\tconst lastSupIdx: number = storedMarksAfter.findLastIndex(\n\t\t\t\t\t\t\t(m) => m.type === 'superscript',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst lastSubIdx: number = storedMarksAfter.findLastIndex(\n\t\t\t\t\t\t\t(m) => m.type === 'subscript',\n\t\t\t\t\t\t);\n\t\t\t\t\t\tconst removeType: string = lastSupIdx > lastSubIdx ? 'subscript' : 'superscript';\n\n\t\t\t\t\t\tstoredMarksAfter = storedMarksAfter.filter((m) => m.type !== removeType);\n\t\t\t\t\t\tpatched = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tnext(patched ? { ...tr, steps: patchedSteps, storedMarksAfter } : tr);\n\t\t\t},\n\t\t\t{ name: 'super-sub:exclusivity' },\n\t\t);\n\t}\n\n\t/**\n\t * Registers disabled toolbar buttons for marks whose feature is disabled\n\t * but whose toolbar button is explicitly requested.\n\t */\n\tprivate registerDisabledToolbarItems(context: PluginContext): void {\n\t\tif (!this.config.toolbar) return;\n\n\t\tfor (const def of MARK_DEFINITIONS) {\n\t\t\tconst featureEnabled: boolean = this.config[def.configKey];\n\t\t\tconst toolbarVisible: boolean = this.config.toolbar[def.configKey] ?? true;\n\n\t\t\tif (!featureEnabled && toolbarVisible) {\n\t\t\t\tconst label: string =\n\t\t\t\t\tdef.type === 'superscript' ? this.locale.superscriptLabel : this.locale.subscriptLabel;\n\t\t\t\tcontext.registerToolbarItem({\n\t\t\t\t\tid: def.type,\n\t\t\t\t\tgroup: 'format',\n\t\t\t\t\ticon: def.icon,\n\t\t\t\t\tlabel,\n\t\t\t\t\tcommand: toCommandName(def.type),\n\t\t\t\t\tpriority: def.toolbarPriority,\n\t\t\t\t\tisEnabled: () => false,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate isToolbarVisible(\n\t\tconfigKey: keyof Omit<SuperSubConfig, 'toolbar' | 'separatorAfter' | 'locale'>,\n\t): boolean {\n\t\tif (!this.config.toolbar) return true;\n\t\treturn this.config.toolbar[configKey] ?? true;\n\t}\n}\n\n/** Converts a mark type to its toggle command name (e.g. 'superscript' → 'toggleSuperscript'). */\nfunction toCommandName(markType: string): string {\n\treturn `toggle${markType.charAt(0).toUpperCase()}${markType.slice(1)}`;\n}\n"],"names":["SUPER_SUB_LOCALE_EN","superscriptLabel","superscriptTooltip","shortcut","subscriptLabel","subscriptTooltip","SUPER_SUB_LOCALES","en","de","es","fr","zh","ru","ar","hi","DEFAULT_CONFIG","superscript","subscript","MARK_DEFINITIONS","type","opposite","configKey","rank","tag","label","icon","join","keyBinding","toolbarPriority","toHTMLString","content","parseHTML","sanitize","tags","SuperSubPlugin","id","name","priority","config","locale","this","context","resolvePluginLocale","enabledMarks","filter","def","lastVisibleMark","isToolbarVisible","at","isSeparatorTarget","separatorAfter","registerMark","registerKeymaps","registerExclusivityMiddleware","registerDisabledToolbarItems","commandName","toCommandName","toolbarVisible","registerMarkSpec","toDOM","document","createElement","_mark","registerCommand","tr","toggleMark","getState","mkType","dispatch","tooltip","formatShortcut","registerToolbarItem","group","command","isActive","state","isMarkActive","marks","keymap","executeCommand","Object","keys","length","registerKeymap","some","d","registerMiddleware","_state","next","patched","patchedSteps","step","steps","push","markName","mark","find","removeStep","blockId","from","to","path","storedMarksAfter","hasSup","m","hasSub","removeType","findLastIndex","toolbar","featureEnabled","isEnabled","markType","charAt","toUpperCase","slice"],"mappings":";;;;AAeO,MAAMA,IAAsC,EAClDC,kBAAkB,eAClBC,oBAAqBC,CAAAA,OAAqB,gBAAgBA,EAAAA,KAC1D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OAAOsE,QAAQvF,EAAAA,KAAAA;AAAAA,EAC5B;AAAA;AAID,SAASmC,EAAcuD,IAAAA;AACtB,SAAO,SAASA,GAASC,OAAO,GAAGC,YAAAA,CAAAA,GAAgBF,GAASG,MAAM,CAAA,CAAA;AACnE;"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { i as t, g as e, a as n, r as o } from "./AttributedMarkCommands-BtLea72z.mjs";
|
|
2
|
+
import { r as i } from "./resolvePluginLocale-B4w1OkPy.mjs";
|
|
3
|
+
import { e as r } from "./HTMLUtils-DTqQzcKR.mjs";
|
|
4
|
+
import { m as a } from "./TypeBrands-C09nE2qO.mjs";
|
|
5
|
+
import { a as s, g as l } from "./StyleRuntime-ChRjVQwL.mjs";
|
|
6
|
+
import { b as c } from "./ColorValidation-CV4f1wu6.mjs";
|
|
7
|
+
import { a as p } from "./ToolbarPlugin-DpLVJ71w.mjs";
|
|
8
|
+
const m = { label: "Font", tooltip: "Font Family" }, f = { en: m, de: { label: "Schriftart", tooltip: "Schriftfamilie" }, es: { label: "Fuente", tooltip: "Familia de fuente" }, fr: { label: "Police", tooltip: "Famille de police" }, zh: { label: "字体", tooltip: "字体系列" }, ru: { label: "Шрифт", tooltip: "Семейство шрифтов" }, ar: { label: "الخط", tooltip: "عائلة الخط" }, hi: { label: "फ़ॉन्ट", tooltip: "फ़ॉन्ट परिवार" } };
|
|
9
|
+
class d {
|
|
10
|
+
id = "font";
|
|
11
|
+
name = "Font";
|
|
12
|
+
priority = 22;
|
|
13
|
+
config;
|
|
14
|
+
locale;
|
|
15
|
+
injectedStyleElement = null;
|
|
16
|
+
context = null;
|
|
17
|
+
constructor(t2) {
|
|
18
|
+
this.config = t2;
|
|
19
|
+
}
|
|
20
|
+
init(t2) {
|
|
21
|
+
this.locale = i(f, t2, this.config.locale), t2.registerStyleSheet("\n/* Font Select — Width overrides for combobox button */\n.notectl-toolbar-btn--font {\n min-width: 100px;\n max-width: 160px;\n}\n\n/* Font Picker Popup */\n.notectl-font-picker {\n min-width: 200px;\n max-height: 320px;\n overflow-y: auto;\n}\n\n.notectl-font-picker__list {\n padding: 4px 0;\n}\n\n.notectl-font-picker__item {\n display: flex;\n align-items: center;\n gap: 8px;\n width: 100%;\n padding: 7px 12px;\n border: none;\n background: none;\n cursor: pointer;\n font-size: 14px;\n color: var(--notectl-fg);\n line-height: 1.4;\n text-align: left;\n white-space: nowrap;\n font-family: inherit;\n transition: background 0.1s;\n}\n\n.notectl-font-picker__item:hover {\n background: var(--notectl-hover-bg);\n}\n\n.notectl-font-picker__item--active {\n background: var(--notectl-active-bg);\n color: var(--notectl-primary-fg);\n}\n\n.notectl-font-picker__item--active:hover {\n background: var(--notectl-active-bg);\n}\n\n.notectl-font-picker__check {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 16px;\n flex-shrink: 0;\n font-size: 13px;\n font-weight: 600;\n color: var(--notectl-primary-fg);\n}\n\n.notectl-font-picker__label {\n flex: 1;\n}\n\n.notectl-font-picker__separator {\n height: 1px;\n background: var(--notectl-border);\n margin: 4px 8px;\n}\n"), this.context = t2, this.registerMarkSpec(t2), this.registerCommands(t2), this.registerToolbarItem(t2), this.injectFontFaces();
|
|
22
|
+
}
|
|
23
|
+
destroy() {
|
|
24
|
+
this.injectedStyleElement?.remove(), this.injectedStyleElement = null, this.context = null;
|
|
25
|
+
}
|
|
26
|
+
registerMarkSpec(t2) {
|
|
27
|
+
t2.registerMarkSpec({ type: "font", rank: 6, attrs: { family: { default: "" } }, toDOM(t3) {
|
|
28
|
+
const e2 = document.createElement("span"), n2 = t3.attrs?.family ?? "";
|
|
29
|
+
return n2 && s(e2, "fontFamily", n2), e2;
|
|
30
|
+
}, toHTMLString: (t3, e2) => {
|
|
31
|
+
const n2 = String(t3.attrs?.family ?? "");
|
|
32
|
+
return n2 && c(n2) ? `<span style="font-family: ${r(n2)}">${e2}</span>` : e2;
|
|
33
|
+
}, toHTMLStyle: (t3) => {
|
|
34
|
+
const e2 = String(t3.attrs?.family ?? "");
|
|
35
|
+
return e2 && c(e2) ? `font-family: ${r(e2)}` : null;
|
|
36
|
+
}, parseHTML: [{ tag: "span", getAttrs: (t3) => {
|
|
37
|
+
const e2 = t3.style.fontFamily;
|
|
38
|
+
return !!e2 && { family: e2 };
|
|
39
|
+
} }], sanitize: { tags: ["span"] } });
|
|
40
|
+
}
|
|
41
|
+
registerCommands(t2) {
|
|
42
|
+
t2.registerCommand("removeFont", () => {
|
|
43
|
+
const e2 = t2.getState();
|
|
44
|
+
return this.removeFont(t2, e2);
|
|
45
|
+
}), t2.registerCommand("setFont", () => false);
|
|
46
|
+
}
|
|
47
|
+
get defaultFont() {
|
|
48
|
+
if (this.config.defaultFont) {
|
|
49
|
+
const t3 = this.config.fonts.find((t4) => t4.name === this.config.defaultFont);
|
|
50
|
+
if (t3) return t3;
|
|
51
|
+
}
|
|
52
|
+
const t2 = this.config.fonts[0];
|
|
53
|
+
if (!t2) throw new Error("FontPlugin: fonts list is empty");
|
|
54
|
+
return t2;
|
|
55
|
+
}
|
|
56
|
+
registerToolbarItem(t2) {
|
|
57
|
+
t2.registerToolbarItem({ id: "font", group: "format", label: this.locale.label, tooltip: this.locale.tooltip, command: "removeFont", priority: 5, popupType: "combobox", separatorAfter: this.config.separatorAfter, getLabel: (t3) => this.resolveFontName(this.getActiveFont(t3)), renderPopup: (t3, e2) => {
|
|
58
|
+
this.renderFontPopup(t3, e2);
|
|
59
|
+
}, isActive: (t3) => this.isFontActive(t3) });
|
|
60
|
+
}
|
|
61
|
+
resolveFontName(t2) {
|
|
62
|
+
if (!t2) return this.defaultFont.name;
|
|
63
|
+
const e2 = this.config.fonts.find((e3) => e3.family === t2);
|
|
64
|
+
return e2?.name ?? (t2.split(",")[0] ?? "").trim().replace(/'/g, "");
|
|
65
|
+
}
|
|
66
|
+
isFontActive(e2) {
|
|
67
|
+
return t(e2, "font");
|
|
68
|
+
}
|
|
69
|
+
getActiveFont(t2) {
|
|
70
|
+
return e(t2, "font", (t3) => t3.attrs.family ?? null);
|
|
71
|
+
}
|
|
72
|
+
applyFont(t2, e2, o2) {
|
|
73
|
+
const i2 = { type: a("font"), attrs: { family: o2 } }, r2 = n(e2, i2);
|
|
74
|
+
return !!r2 && (t2.dispatch(r2), true);
|
|
75
|
+
}
|
|
76
|
+
removeFont(t2, e2) {
|
|
77
|
+
const n2 = o(e2, a("font"));
|
|
78
|
+
return !!n2 && (t2.dispatch(n2), true);
|
|
79
|
+
}
|
|
80
|
+
injectFontFaces() {
|
|
81
|
+
const t2 = [];
|
|
82
|
+
for (const e3 of this.config.fonts) if (e3.fontFaces?.length) for (const n3 of e3.fontFaces) {
|
|
83
|
+
const o2 = [`font-family: '${(e3.family.split(",")[0] ?? "").trim().replace(/'/g, "")}'`, `src: ${n3.src}`];
|
|
84
|
+
n3.weight && o2.push(`font-weight: ${n3.weight}`), n3.style && o2.push(`font-style: ${n3.style}`), o2.push(`font-display: ${n3.display ?? "swap"}`), t2.push(`@font-face {
|
|
85
|
+
${o2.join(";\n ")};
|
|
86
|
+
}`);
|
|
87
|
+
}
|
|
88
|
+
if (0 === t2.length) return;
|
|
89
|
+
const e2 = document.createElement("style");
|
|
90
|
+
e2.setAttribute("data-notectl-fonts", "");
|
|
91
|
+
const n2 = this.context ? l(this.context.getContainer()) : void 0;
|
|
92
|
+
n2 && e2.setAttribute("nonce", n2), e2.textContent = t2.join("\n\n"), document.head.appendChild(e2), this.injectedStyleElement = e2;
|
|
93
|
+
}
|
|
94
|
+
dismissPopup() {
|
|
95
|
+
const t2 = this.context?.getService(p);
|
|
96
|
+
t2?.closePopup();
|
|
97
|
+
}
|
|
98
|
+
renderFontPopup(t2, e2) {
|
|
99
|
+
t2.classList.add("notectl-font-picker");
|
|
100
|
+
const n2 = e2.getState(), o2 = this.getActiveFont(n2), i2 = this.defaultFont.family, r2 = document.createElement("div");
|
|
101
|
+
r2.className = "notectl-font-picker__list", r2.setAttribute("role", "listbox"), r2.setAttribute("aria-label", this.locale.label);
|
|
102
|
+
for (const t3 of this.config.fonts) {
|
|
103
|
+
const n3 = t3.family === i2, a2 = n3 && !o2 || o2 === t3.family, s2 = this.createFontItem(t3.name, t3.family, a2, (o3) => {
|
|
104
|
+
o3.preventDefault(), o3.stopPropagation(), n3 ? e2.executeCommand("removeFont") : this.applyFont(e2, e2.getState(), t3.family), this.dismissPopup();
|
|
105
|
+
});
|
|
106
|
+
t3.category && s2.setAttribute("data-category", t3.category), r2.appendChild(s2);
|
|
107
|
+
}
|
|
108
|
+
t2.appendChild(r2);
|
|
109
|
+
}
|
|
110
|
+
createFontItem(t2, e2, n2, o2) {
|
|
111
|
+
const i2 = document.createElement("button");
|
|
112
|
+
i2.type = "button", i2.className = "notectl-font-picker__item", i2.setAttribute("role", "option"), i2.setAttribute("aria-selected", String(n2)), n2 && i2.classList.add("notectl-font-picker__item--active");
|
|
113
|
+
const r2 = document.createElement("span");
|
|
114
|
+
r2.className = "notectl-font-picker__check", r2.textContent = n2 ? "✓" : "", i2.appendChild(r2);
|
|
115
|
+
const a2 = document.createElement("span");
|
|
116
|
+
return a2.className = "notectl-font-picker__label", a2.textContent = t2, e2 && s(a2, "fontFamily", e2), i2.appendChild(a2), i2.addEventListener("mousedown", o2), i2;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
export {
|
|
120
|
+
d as F,
|
|
121
|
+
f as a,
|
|
122
|
+
m as b
|
|
123
|
+
};
|
|
124
|
+
//# sourceMappingURL=index-CWltg1wK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-CWltg1wK.mjs","sources":["../../src/editor/styles/font-select.ts","../../src/plugins/font/FontLocale.ts","../../src/plugins/font/FontPlugin.ts"],"sourcesContent":["/** Font picker toolbar combobox + popup styles. */\nexport const FONT_SELECT_CSS = `\n/* Font Select — Width overrides for combobox button */\n.notectl-toolbar-btn--font {\n\tmin-width: 100px;\n\tmax-width: 160px;\n}\n\n/* Font Picker Popup */\n.notectl-font-picker {\n\tmin-width: 200px;\n\tmax-height: 320px;\n\toverflow-y: auto;\n}\n\n.notectl-font-picker__list {\n\tpadding: 4px 0;\n}\n\n.notectl-font-picker__item {\n\tdisplay: flex;\n\talign-items: center;\n\tgap: 8px;\n\twidth: 100%;\n\tpadding: 7px 12px;\n\tborder: none;\n\tbackground: none;\n\tcursor: pointer;\n\tfont-size: 14px;\n\tcolor: var(--notectl-fg);\n\tline-height: 1.4;\n\ttext-align: left;\n\twhite-space: nowrap;\n\tfont-family: inherit;\n\ttransition: background 0.1s;\n}\n\n.notectl-font-picker__item:hover {\n\tbackground: var(--notectl-hover-bg);\n}\n\n.notectl-font-picker__item--active {\n\tbackground: var(--notectl-active-bg);\n\tcolor: var(--notectl-primary-fg);\n}\n\n.notectl-font-picker__item--active:hover {\n\tbackground: var(--notectl-active-bg);\n}\n\n.notectl-font-picker__check {\n\tdisplay: inline-flex;\n\talign-items: center;\n\tjustify-content: center;\n\twidth: 16px;\n\tflex-shrink: 0;\n\tfont-size: 13px;\n\tfont-weight: 600;\n\tcolor: var(--notectl-primary-fg);\n}\n\n.notectl-font-picker__label {\n\tflex: 1;\n}\n\n.notectl-font-picker__separator {\n\theight: 1px;\n\tbackground: var(--notectl-border);\n\tmargin: 4px 8px;\n}\n`;\n","/** Locale interface and default English locale for the FontPlugin. */\n\n// --- Locale Interface ---\n\nexport interface FontLocale {\n\treadonly label: string;\n\treadonly tooltip: string;\n}\n\n// --- Default English Locale ---\n\nexport const FONT_LOCALE_EN: FontLocale = {\n\tlabel: 'Font',\n\ttooltip: 'Font Family',\n};\n\n// --- German Locale ---\n\nexport const FONT_LOCALE_DE: FontLocale = {\n\tlabel: 'Schriftart',\n\ttooltip: 'Schriftfamilie',\n};\n\n// --- Spanish Locale ---\n\nexport const FONT_LOCALE_ES: FontLocale = {\n\tlabel: 'Fuente',\n\ttooltip: 'Familia de fuente',\n};\n\n// --- French Locale ---\n\nexport const FONT_LOCALE_FR: FontLocale = {\n\tlabel: 'Police',\n\ttooltip: 'Famille de police',\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const FONT_LOCALE_ZH: FontLocale = {\n\tlabel: '字体',\n\ttooltip: '字体系列',\n};\n\n// --- Russian Locale ---\n\nexport const FONT_LOCALE_RU: FontLocale = {\n\tlabel: 'Шрифт',\n\ttooltip: 'Семейство шрифтов',\n};\n\n// --- Arabic Locale ---\n\nexport const FONT_LOCALE_AR: FontLocale = {\n\tlabel: 'الخط',\n\ttooltip: 'عائلة الخط',\n};\n\n// --- Hindi Locale ---\n\nexport const FONT_LOCALE_HI: FontLocale = {\n\tlabel: 'फ़ॉन्ट',\n\ttooltip: 'फ़ॉन्ट परिवार',\n};\n\n// --- Locale Map ---\n\nexport const FONT_LOCALES: Record<string, FontLocale> = {\n\ten: FONT_LOCALE_EN,\n\tde: FONT_LOCALE_DE,\n\tes: FONT_LOCALE_ES,\n\tfr: FONT_LOCALE_FR,\n\tzh: FONT_LOCALE_ZH,\n\tru: FONT_LOCALE_RU,\n\tar: FONT_LOCALE_AR,\n\thi: FONT_LOCALE_HI,\n};\n","/**\n * FontPlugin: registers a font-family mark, a combobox-style toolbar selector\n * for font selection, and a developer-friendly API for registering custom fonts\n * (WOFF2, TTF, OTF).\n */\n\nimport {\n\tapplyAttributedMark,\n\tgetMarkAttrAtSelection,\n\tisAttributedMarkActive,\n\tremoveAttributedMark,\n} from '../../commands/AttributedMarkCommands.js';\nimport { FONT_SELECT_CSS } from '../../editor/styles/font-select.js';\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport { escapeHTML } from '../../model/HTMLUtils.js';\nimport { markType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport { getStyleNonceForNode, setStyleProperty } from '../../style/StyleRuntime.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { isValidCSSFontFamily } from '../shared/ColorValidation.js';\nimport { ToolbarServiceKey } from '../toolbar/ToolbarPlugin.js';\nimport { FONT_LOCALES, type FontLocale } from './FontLocale.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface MarkAttrRegistry {\n\t\tfont: { family: string };\n\t}\n}\n\n// --- Public Types ---\n\n/** Describes a single @font-face source. */\nexport interface FontFaceDescriptor {\n\t/** CSS `src` value, e.g. `\"url('/fonts/My.woff2') format('woff2')\"`. */\n\treadonly src: string;\n\t/** Font weight, e.g. `'400'` or `'300 700'` for variable fonts. */\n\treadonly weight?: string;\n\t/** Font style, e.g. `'normal'` or `'italic'`. */\n\treadonly style?: string;\n\t/** Font display strategy. Defaults to `'swap'`. */\n\treadonly display?: string;\n}\n\n/** Defines a font available in the editor. */\nexport interface FontDefinition {\n\t/** Display name shown in the toolbar dropdown. */\n\treadonly name: string;\n\t/** CSS `font-family` value, e.g. `\"'Fira Code', monospace\"`. */\n\treadonly family: string;\n\t/** Font category for grouping in the UI. */\n\treadonly category?: 'serif' | 'sans-serif' | 'monospace' | 'display' | 'handwriting';\n\t/**\n\t * Optional `@font-face` descriptors. When provided, the plugin\n\t * auto-injects the corresponding CSS rules into the document.\n\t */\n\treadonly fontFaces?: readonly FontFaceDescriptor[];\n}\n\n// --- Configuration ---\n\nexport interface FontConfig {\n\t/**\n\t * Fonts available in the editor. System fonts require no `fontFaces`.\n\t * Custom fonts with `fontFaces` get their `@font-face` rules auto-injected.\n\t *\n\t * Use `STARTER_FONTS` for a pre-configured set of fonts:\n\t * ```ts\n\t * new FontPlugin({ fonts: [...STARTER_FONTS] })\n\t * ```\n\t */\n\treadonly fonts: readonly FontDefinition[];\n\t/**\n\t * Name of the font that acts as the editor's default.\n\t * Selecting this font removes the mark (since the editor already uses it).\n\t * Defaults to the first font in the list.\n\t */\n\treadonly defaultFont?: string;\n\t/** When true, a separator is rendered after the font toolbar item. */\n\treadonly separatorAfter?: boolean;\n\treadonly locale?: FontLocale;\n}\n\n// --- Plugin ---\n\nexport class FontPlugin implements Plugin {\n\treadonly id = 'font';\n\treadonly name = 'Font';\n\treadonly priority = 22;\n\n\tprivate readonly config: FontConfig;\n\tprivate locale!: FontLocale;\n\tprivate injectedStyleElement: HTMLStyleElement | null = null;\n\tprivate context: PluginContext | null = null;\n\n\tconstructor(config: FontConfig) {\n\t\tthis.config = config;\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(FONT_LOCALES, context, this.config.locale);\n\n\t\tcontext.registerStyleSheet(FONT_SELECT_CSS);\n\t\tthis.context = context;\n\t\tthis.registerMarkSpec(context);\n\t\tthis.registerCommands(context);\n\t\tthis.registerToolbarItem(context);\n\t\tthis.injectFontFaces();\n\t}\n\n\tdestroy(): void {\n\t\tthis.injectedStyleElement?.remove();\n\t\tthis.injectedStyleElement = null;\n\t\tthis.context = null;\n\t}\n\n\t// --- Schema ---\n\n\tprivate registerMarkSpec(context: PluginContext): void {\n\t\tcontext.registerMarkSpec({\n\t\t\ttype: 'font',\n\t\t\trank: 6,\n\t\t\tattrs: {\n\t\t\t\tfamily: { default: '' },\n\t\t\t},\n\t\t\ttoDOM(mark) {\n\t\t\t\tconst span: HTMLElement = document.createElement('span');\n\t\t\t\tconst family: string = mark.attrs?.family ?? '';\n\t\t\t\tif (family) {\n\t\t\t\t\tsetStyleProperty(span, 'fontFamily', family);\n\t\t\t\t}\n\t\t\t\treturn span;\n\t\t\t},\n\t\t\ttoHTMLString: (mark, content) => {\n\t\t\t\tconst family: string = String(mark.attrs?.family ?? '');\n\t\t\t\tif (!family || !isValidCSSFontFamily(family)) return content;\n\t\t\t\treturn `<span style=\"font-family: ${escapeHTML(family)}\">${content}</span>`;\n\t\t\t},\n\t\t\ttoHTMLStyle: (mark) => {\n\t\t\t\tconst family: string = String(mark.attrs?.family ?? '');\n\t\t\t\tif (!family || !isValidCSSFontFamily(family)) return null;\n\t\t\t\treturn `font-family: ${escapeHTML(family)}`;\n\t\t\t},\n\t\t\tparseHTML: [\n\t\t\t\t{\n\t\t\t\t\ttag: 'span',\n\t\t\t\t\tgetAttrs: (el) => {\n\t\t\t\t\t\tconst family: string = el.style.fontFamily;\n\t\t\t\t\t\tif (!family) return false;\n\t\t\t\t\t\treturn { family };\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t],\n\t\t\tsanitize: { tags: ['span'] },\n\t\t});\n\t}\n\n\t// --- Commands ---\n\n\tprivate registerCommands(context: PluginContext): void {\n\t\tcontext.registerCommand('removeFont', () => {\n\t\t\tconst state: EditorState = context.getState();\n\t\t\treturn this.removeFont(context, state);\n\t\t});\n\n\t\tcontext.registerCommand('setFont', () => {\n\t\t\treturn false;\n\t\t});\n\t}\n\n\t// --- Toolbar ---\n\n\tprivate get defaultFont(): FontDefinition {\n\t\tif (this.config.defaultFont) {\n\t\t\tconst found: FontDefinition | undefined = this.config.fonts.find(\n\t\t\t\t(f) => f.name === this.config.defaultFont,\n\t\t\t);\n\t\t\tif (found) return found;\n\t\t}\n\t\tconst first: FontDefinition | undefined = this.config.fonts[0];\n\t\tif (!first) throw new Error('FontPlugin: fonts list is empty');\n\t\treturn first;\n\t}\n\n\tprivate registerToolbarItem(context: PluginContext): void {\n\t\tcontext.registerToolbarItem({\n\t\t\tid: 'font',\n\t\t\tgroup: 'format',\n\t\t\tlabel: this.locale.label,\n\t\t\ttooltip: this.locale.tooltip,\n\t\t\tcommand: 'removeFont',\n\t\t\tpriority: 5,\n\t\t\tpopupType: 'combobox',\n\t\t\tseparatorAfter: this.config.separatorAfter,\n\t\t\tgetLabel: (state: EditorState): string => this.resolveFontName(this.getActiveFont(state)),\n\t\t\trenderPopup: (container, ctx) => {\n\t\t\t\tthis.renderFontPopup(container, ctx);\n\t\t\t},\n\t\t\tisActive: (state) => this.isFontActive(state),\n\t\t});\n\t}\n\n\tprivate resolveFontName(family: string | null): string {\n\t\tif (!family) return this.defaultFont.name;\n\t\tconst match: FontDefinition | undefined = this.config.fonts.find((f) => f.family === family);\n\t\treturn match?.name ?? (family.split(',')[0] ?? '').trim().replace(/'/g, '');\n\t}\n\n\t// --- State Queries ---\n\n\tprivate isFontActive(state: EditorState): boolean {\n\t\treturn isAttributedMarkActive(state, 'font');\n\t}\n\n\tgetActiveFont(state: EditorState): string | null {\n\t\treturn getMarkAttrAtSelection(state, 'font', (m) => m.attrs.family ?? null);\n\t}\n\n\t// --- Font Application ---\n\n\tapplyFont(context: PluginContext, state: EditorState, family: string): boolean {\n\t\tconst mark = { type: markType('font'), attrs: { family } };\n\t\tconst tr = applyAttributedMark(state, mark);\n\t\tif (!tr) return false;\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n\n\tprivate removeFont(context: PluginContext, state: EditorState): boolean {\n\t\tconst tr = removeAttributedMark(state, markType('font'));\n\t\tif (!tr) return false;\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n\n\t// --- @font-face Injection ---\n\n\tprivate injectFontFaces(): void {\n\t\tconst rules: string[] = [];\n\n\t\tfor (const font of this.config.fonts) {\n\t\t\tif (!font.fontFaces?.length) continue;\n\n\t\t\tfor (const face of font.fontFaces) {\n\t\t\t\tconst familyName: string = (font.family.split(',')[0] ?? '').trim().replace(/'/g, '');\n\t\t\t\tconst declarations: string[] = [`font-family: '${familyName}'`, `src: ${face.src}`];\n\t\t\t\tif (face.weight) {\n\t\t\t\t\tdeclarations.push(`font-weight: ${face.weight}`);\n\t\t\t\t}\n\t\t\t\tif (face.style) {\n\t\t\t\t\tdeclarations.push(`font-style: ${face.style}`);\n\t\t\t\t}\n\t\t\t\tdeclarations.push(`font-display: ${face.display ?? 'swap'}`);\n\n\t\t\t\trules.push(`@font-face {\\n\\t${declarations.join(';\\n\\t')};\\n}`);\n\t\t\t}\n\t\t}\n\n\t\tif (rules.length === 0) return;\n\n\t\tconst style: HTMLStyleElement = document.createElement('style');\n\t\tstyle.setAttribute('data-notectl-fonts', '');\n\t\tconst nonce = this.context ? getStyleNonceForNode(this.context.getContainer()) : undefined;\n\t\tif (nonce) {\n\t\t\tstyle.setAttribute('nonce', nonce);\n\t\t}\n\t\tstyle.textContent = rules.join('\\n\\n');\n\t\tdocument.head.appendChild(style);\n\t\tthis.injectedStyleElement = style;\n\t}\n\n\t// --- Popup Rendering ---\n\n\tprivate dismissPopup(): void {\n\t\tconst toolbar = this.context?.getService(ToolbarServiceKey);\n\t\ttoolbar?.closePopup();\n\t}\n\n\tprivate renderFontPopup(container: HTMLElement, context: PluginContext): void {\n\t\tcontainer.classList.add('notectl-font-picker');\n\n\t\tconst state: EditorState = context.getState();\n\t\tconst activeFont: string | null = this.getActiveFont(state);\n\t\tconst defaultFamily: string = this.defaultFont.family;\n\n\t\tconst list: HTMLDivElement = document.createElement('div');\n\t\tlist.className = 'notectl-font-picker__list';\n\t\tlist.setAttribute('role', 'listbox');\n\t\tlist.setAttribute('aria-label', this.locale.label);\n\n\t\tfor (const font of this.config.fonts) {\n\t\t\tconst isDefault: boolean = font.family === defaultFamily;\n\t\t\tconst isActive: boolean = isDefault\n\t\t\t\t? !activeFont || activeFont === font.family\n\t\t\t\t: activeFont === font.family;\n\n\t\t\tconst item: HTMLButtonElement = this.createFontItem(\n\t\t\t\tfont.name,\n\t\t\t\tfont.family,\n\t\t\t\tisActive,\n\t\t\t\t(e: MouseEvent) => {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\te.stopPropagation();\n\t\t\t\t\tif (isDefault) {\n\t\t\t\t\t\tcontext.executeCommand('removeFont');\n\t\t\t\t\t} else {\n\t\t\t\t\t\tthis.applyFont(context, context.getState(), font.family);\n\t\t\t\t\t}\n\t\t\t\t\tthis.dismissPopup();\n\t\t\t\t},\n\t\t\t);\n\n\t\t\tif (font.category) {\n\t\t\t\titem.setAttribute('data-category', font.category);\n\t\t\t}\n\n\t\t\tlist.appendChild(item);\n\t\t}\n\n\t\tcontainer.appendChild(list);\n\t}\n\n\tprivate createFontItem(\n\t\tname: string,\n\t\tfamily: string,\n\t\tisActive: boolean,\n\t\thandler: (e: MouseEvent) => void,\n\t): HTMLButtonElement {\n\t\tconst item: HTMLButtonElement = document.createElement('button');\n\t\titem.type = 'button';\n\t\titem.className = 'notectl-font-picker__item';\n\t\titem.setAttribute('role', 'option');\n\t\titem.setAttribute('aria-selected', String(isActive));\n\n\t\tif (isActive) {\n\t\t\titem.classList.add('notectl-font-picker__item--active');\n\t\t}\n\n\t\t// Checkmark indicator\n\t\tconst check: HTMLSpanElement = document.createElement('span');\n\t\tcheck.className = 'notectl-font-picker__check';\n\t\tcheck.textContent = isActive ? '\\u2713' : '';\n\t\titem.appendChild(check);\n\n\t\t// Font name label (rendered in the font itself for preview)\n\t\tconst label: HTMLSpanElement = document.createElement('span');\n\t\tlabel.className = 'notectl-font-picker__label';\n\t\tlabel.textContent = name;\n\t\tif (family) {\n\t\t\tsetStyleProperty(label, 'fontFamily', family);\n\t\t}\n\t\titem.appendChild(label);\n\n\t\titem.addEventListener('mousedown', handler);\n\t\treturn item;\n\t}\n}\n"],"names":["FONT_LOCALE_EN","label","tooltip","FONT_LOCALES","en","de","es","fr","zh","ru","ar","hi","FontPlugin","id","name","priority","config","locale","injectedStyleElement","context","this","resolvePluginLocale","registerStyleSheet","registerMarkSpec","registerCommands","registerToolbarItem","injectFontFaces","remove","type","rank","attrs","family","default","mark","span","document","createElement","setStyleProperty","toHTMLString","content","String","isValidCSSFontFamily","escapeHTML","toHTMLStyle","parseHTML","tag","getAttrs","el","style","fontFamily","sanitize","tags","registerCommand","state","getState","removeFont","defaultFont","found","fonts","find","f","first","Error","group","command","popupType","separatorAfter","getLabel","resolveFontName","getActiveFont","renderPopup","container","ctx","renderFontPopup","isActive","isFontActive","match","split","trim","replace","isAttributedMarkActive","getMarkAttrAtSelection","m","markType","tr","applyAttributedMark","dispatch","removeAttributedMark","rules","font","fontFaces","length","face","declarations","src","weight","push","display","join","setAttribute","nonce","getStyleNonceForNode","getContainer","textContent","head","appendChild","dismissPopup","toolbar","getService","ToolbarServiceKey","closePopup","classList","add","activeFont","defaultFamily","list","className","isDefault","item","createFontItem","e","preventDefault","stopPropagation","executeCommand","applyFont","category","handler","check","addEventList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AEvCuF,GAAKb,YAAYxG,EAAAA,GAEjBqH,GAAKU,iBAAiB,aAAaF,KAC5BR;AAAAA,EACR;AAAA;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { r as e } from "./resolvePluginLocale-B4w1OkPy.mjs";
|
|
2
2
|
import { m as t } from "./TypeBrands-C09nE2qO.mjs";
|
|
3
3
|
import { f as i } from "./ToolbarItem-BpZggUGo.mjs";
|
|
4
|
-
import { e as a, b as r } from "./MarkCommands-
|
|
4
|
+
import { e as a, b as r } from "./MarkCommands-6RUJ4L3r.mjs";
|
|
5
5
|
const o = { boldLabel: "Bold", italicLabel: "Italic", underlineLabel: "Underline" }, n = { en: o, de: { boldLabel: "Fett", italicLabel: "Kursiv", underlineLabel: "Unterstrichen" }, es: { boldLabel: "Negrita", italicLabel: "Cursiva", underlineLabel: "Subrayado" }, fr: { boldLabel: "Gras", italicLabel: "Italique", underlineLabel: "Souligné" }, zh: { boldLabel: "粗体", italicLabel: "斜体", underlineLabel: "下划线" }, ru: { boldLabel: "Жирный", italicLabel: "Курсив", underlineLabel: "Подчёркнутый" }, ar: { boldLabel: "غامق", italicLabel: "مائل", underlineLabel: "تحته خط" }, hi: { boldLabel: "बोल्ड", italicLabel: "इटैलिक", underlineLabel: "अंडरलाइन" } }, s = { bold: true, italic: true, underline: true }, l = [{ type: "bold", configKey: "bold", rank: 0, tag: "strong", label: "Bold", icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z"/></svg>', keyBinding: "Mod-B", toHTMLString: (e2) => `<strong>${e2}</strong>`, parseHTML: [{ tag: "strong" }, { tag: "b", getAttrs: (e2) => {
|
|
6
6
|
const t2 = e2.style.fontWeight;
|
|
7
7
|
return "normal" !== t2 && "400" !== t2 && {};
|
|
@@ -70,4 +70,4 @@ export {
|
|
|
70
70
|
n as a,
|
|
71
71
|
o as b
|
|
72
72
|
};
|
|
73
|
-
//# sourceMappingURL=index-
|
|
73
|
+
//# sourceMappingURL=index-Cd3uJLP3.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-D8tbbW97.mjs","sources":["../../src/plugins/text-formatting/TextFormattingLocale.ts","../../src/plugins/text-formatting/TextFormattingPlugin.ts"],"sourcesContent":["/**\n * Locale interface and default English locale for the TextFormattingPlugin.\n */\n\n// --- Locale Interface ---\n\nexport interface TextFormattingLocale {\n\treadonly boldLabel: string;\n\treadonly italicLabel: string;\n\treadonly underlineLabel: string;\n}\n\n// --- Default English Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_EN: TextFormattingLocale = {\n\tboldLabel: 'Bold',\n\titalicLabel: 'Italic',\n\tunderlineLabel: 'Underline',\n};\n\n// --- German Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_DE: TextFormattingLocale = {\n\tboldLabel: 'Fett',\n\titalicLabel: 'Kursiv',\n\tunderlineLabel: 'Unterstrichen',\n};\n\n// --- Spanish Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_ES: TextFormattingLocale = {\n\tboldLabel: 'Negrita',\n\titalicLabel: 'Cursiva',\n\tunderlineLabel: 'Subrayado',\n};\n\n// --- French Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_FR: TextFormattingLocale = {\n\tboldLabel: 'Gras',\n\titalicLabel: 'Italique',\n\tunderlineLabel: 'Souligné',\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_ZH: TextFormattingLocale = {\n\tboldLabel: '粗体',\n\titalicLabel: '斜体',\n\tunderlineLabel: '下划线',\n};\n\n// --- Russian Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_RU: TextFormattingLocale = {\n\tboldLabel: 'Жирный',\n\titalicLabel: 'Курсив',\n\tunderlineLabel: 'Подчёркнутый',\n};\n\n// --- Arabic Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_AR: TextFormattingLocale = {\n\tboldLabel: 'غامق',\n\titalicLabel: 'مائل',\n\tunderlineLabel: 'تحته خط',\n};\n\n// --- Hindi Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_HI: TextFormattingLocale = {\n\tboldLabel: 'बोल्ड',\n\titalicLabel: 'इटैलिक',\n\tunderlineLabel: 'अंडरलाइन',\n};\n\n// --- Locale Map ---\n\nexport const TEXT_FORMATTING_LOCALES: Record<string, TextFormattingLocale> = {\n\ten: TEXT_FORMATTING_LOCALE_EN,\n\tde: TEXT_FORMATTING_LOCALE_DE,\n\tes: TEXT_FORMATTING_LOCALE_ES,\n\tfr: TEXT_FORMATTING_LOCALE_FR,\n\tzh: TEXT_FORMATTING_LOCALE_ZH,\n\tru: TEXT_FORMATTING_LOCALE_RU,\n\tar: TEXT_FORMATTING_LOCALE_AR,\n\thi: TEXT_FORMATTING_LOCALE_HI,\n};\n","/**\n * TextFormattingPlugin: registers inline marks (bold, italic, underline)\n * with their MarkSpecs, toggle commands, keyboard shortcuts, and toolbar items.\n *\n * This plugin is data-driven — each mark type is defined declaratively and\n * all registrations (MarkSpec, command, keymap, toolbar item) are derived\n * from the same definition.\n *\n * Supports two separate config dimensions:\n * - Feature config (bold/italic/underline): controls whether the mark is\n * registered in the schema. When disabled, the keyboard shortcut does nothing.\n * - Toolbar config: controls whether the toolbar button is visible.\n * When a feature is disabled but toolbar is enabled, the button renders as disabled.\n */\n\nimport { isMarkActive, toggleMark } from '../../commands/Commands.js';\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport type { ParseRule } from '../../model/ParseRule.js';\nimport type { SanitizeConfig } from '../../model/SanitizeConfig.js';\nimport { markType as mkType } from '../../model/TypeBrands.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { formatShortcut } from '../toolbar/ToolbarItem.js';\nimport { TEXT_FORMATTING_LOCALES, type TextFormattingLocale } from './TextFormattingLocale.js';\n\n// --- Configuration ---\n\n/** Controls toolbar button visibility per mark. */\nexport interface TextFormattingToolbarConfig {\n\treadonly bold?: boolean;\n\treadonly italic?: boolean;\n\treadonly underline?: boolean;\n}\n\n/** Controls which inline marks are enabled and which toolbar buttons are shown. */\nexport interface TextFormattingConfig {\n\treadonly bold: boolean;\n\treadonly italic: boolean;\n\treadonly underline: boolean;\n\treadonly toolbar?: TextFormattingToolbarConfig;\n\t/** When true, a separator is rendered after the last text-formatting toolbar item. */\n\treadonly separatorAfter?: boolean;\n\treadonly locale?: TextFormattingLocale;\n}\n\nconst DEFAULT_CONFIG: TextFormattingConfig = {\n\tbold: true,\n\titalic: true,\n\tunderline: true,\n};\n\n// --- Mark Definitions ---\n\ninterface MarkDefinition {\n\treadonly type: string;\n\treadonly configKey: keyof Omit<TextFormattingConfig, 'toolbar' | 'separatorAfter' | 'locale'>;\n\treadonly rank: number;\n\treadonly tag: string;\n\treadonly label: string;\n\treadonly icon: string;\n\treadonly keyBinding: string;\n\treadonly toHTMLString: (content: string) => string;\n\treadonly parseHTML: readonly ParseRule[];\n\treadonly sanitize: SanitizeConfig;\n}\n\nconst BOLD_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z\"/></svg>';\nconst ITALIC_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z\"/></svg>';\nconst UNDERLINE_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M12 17c3.31 0 6-2.69 6-6V3h-2.5v8c0 1.93-1.57 3.5-3.5 3.5S8.5 12.93 8.5 11V3H6v8c0 3.31 2.69 6 6 6zm-7 2v2h14v-2H5z\"/></svg>';\n\nconst MARK_DEFINITIONS: readonly MarkDefinition[] = [\n\t{\n\t\ttype: 'bold',\n\t\tconfigKey: 'bold',\n\t\trank: 0,\n\t\ttag: 'strong',\n\t\tlabel: 'Bold',\n\t\ticon: BOLD_ICON,\n\t\tkeyBinding: 'Mod-B',\n\t\ttoHTMLString: (content) => `<strong>${content}</strong>`,\n\t\tparseHTML: [\n\t\t\t{ tag: 'strong' },\n\t\t\t{\n\t\t\t\ttag: 'b',\n\t\t\t\tgetAttrs: (el: HTMLElement) => {\n\t\t\t\t\tconst fw: string = el.style.fontWeight;\n\t\t\t\t\treturn fw === 'normal' || fw === '400' ? false : {};\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttag: 'span',\n\t\t\t\tgetAttrs: (el: HTMLElement) => {\n\t\t\t\t\tconst fw: string = el.style.fontWeight;\n\t\t\t\t\tif (!fw) return false;\n\t\t\t\t\tif (fw === 'bold') return {};\n\t\t\t\t\tconst numeric: number = Number.parseInt(fw, 10);\n\t\t\t\t\treturn !Number.isNaN(numeric) && numeric >= 700 ? {} : false;\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tsanitize: { tags: ['strong', 'b'] },\n\t},\n\t{\n\t\ttype: 'italic',\n\t\tconfigKey: 'italic',\n\t\trank: 1,\n\t\ttag: 'em',\n\t\tlabel: 'Italic',\n\t\ticon: ITALIC_ICON,\n\t\tkeyBinding: 'Mod-I',\n\t\ttoHTMLString: (content) => `<em>${content}</em>`,\n\t\tparseHTML: [\n\t\t\t{ tag: 'em' },\n\t\t\t{ tag: 'i' },\n\t\t\t{\n\t\t\t\ttag: 'span',\n\t\t\t\tgetAttrs: (el: HTMLElement) => {\n\t\t\t\t\treturn el.style.fontStyle === 'italic' ? {} : false;\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tsanitize: { tags: ['em', 'i'] },\n\t},\n\t{\n\t\ttype: 'underline',\n\t\tconfigKey: 'underline',\n\t\trank: 2,\n\t\ttag: 'u',\n\t\tlabel: 'Underline',\n\t\ticon: UNDERLINE_ICON,\n\t\tkeyBinding: 'Mod-U',\n\t\ttoHTMLString: (content) => `<u>${content}</u>`,\n\t\tparseHTML: [\n\t\t\t{ tag: 'u' },\n\t\t\t{\n\t\t\t\ttag: 'span',\n\t\t\t\tgetAttrs: (el: HTMLElement) => {\n\t\t\t\t\treturn el.style.textDecoration.includes('underline') ? {} : false;\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tsanitize: { tags: ['u'] },\n\t},\n];\n\n// --- Plugin ---\n\nexport class TextFormattingPlugin implements Plugin {\n\treadonly id = 'text-formatting';\n\treadonly name = 'Text Formatting';\n\treadonly priority = 20;\n\n\tprivate readonly config: TextFormattingConfig;\n\tprivate locale!: TextFormattingLocale;\n\n\tconstructor(config?: Partial<TextFormattingConfig>) {\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(TEXT_FORMATTING_LOCALES, context, this.config.locale);\n\n\t\tconst enabledMarks = MARK_DEFINITIONS.filter((def) => this.config[def.configKey]);\n\n\t\t// Determine which marks will have visible toolbar items\n\t\tconst visibleToolbarMarks = enabledMarks.filter((def) => this.isToolbarVisible(def.configKey));\n\t\tconst lastVisibleMark = visibleToolbarMarks.at(-1);\n\n\t\tfor (const def of enabledMarks) {\n\t\t\tconst isSeparatorTarget = this.config.separatorAfter && def === lastVisibleMark;\n\t\t\tthis.registerMark(context, def, isSeparatorTarget);\n\t\t}\n\n\t\tthis.registerKeymaps(context, enabledMarks);\n\n\t\t// Register disabled placeholder buttons for marks that are disabled\n\t\t// as features but explicitly requested in the toolbar config\n\t\tthis.registerDisabledToolbarItems(context);\n\t}\n\n\tprivate registerMark(\n\t\tcontext: PluginContext,\n\t\tdef: MarkDefinition,\n\t\tseparatorAfter?: boolean,\n\t): void {\n\t\tconst commandName = toCommandName(def.type);\n\t\tconst toolbarVisible = this.isToolbarVisible(def.configKey);\n\n\t\tcontext.registerMarkSpec({\n\t\t\ttype: def.type,\n\t\t\trank: def.rank,\n\t\t\ttoDOM() {\n\t\t\t\treturn document.createElement(def.tag);\n\t\t\t},\n\t\t\ttoHTMLString: (_mark, content) => def.toHTMLString(content),\n\t\t\tparseHTML: def.parseHTML,\n\t\t\tsanitize: def.sanitize,\n\t\t});\n\n\t\tcontext.registerCommand(commandName, () => {\n\t\t\tconst tr = toggleMark(context.getState(), mkType(def.type));\n\t\t\tif (tr) {\n\t\t\t\tcontext.dispatch(tr);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t});\n\n\t\tif (toolbarVisible) {\n\t\t\tconst label: string = this.getMarkLabel(def.type);\n\t\t\tcontext.registerToolbarItem({\n\t\t\t\tid: def.type,\n\t\t\t\tgroup: 'format',\n\t\t\t\ticon: def.icon,\n\t\t\t\tlabel,\n\t\t\t\ttooltip: `${label} (${formatShortcut(def.keyBinding)})`,\n\t\t\t\tcommand: commandName,\n\t\t\t\tpriority: def.rank * 10 + 10,\n\t\t\t\tseparatorAfter,\n\t\t\t\tisActive: (state) => isMarkActive(state, mkType(def.type)),\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate registerKeymaps(context: PluginContext, marks: readonly MarkDefinition[]): void {\n\t\tconst keymap: Record<string, () => boolean> = {};\n\t\tfor (const def of marks) {\n\t\t\tconst commandName = toCommandName(def.type);\n\t\t\tkeymap[def.keyBinding] = () => context.executeCommand(commandName);\n\t\t}\n\t\tif (Object.keys(keymap).length > 0) {\n\t\t\tcontext.registerKeymap(keymap);\n\t\t}\n\t}\n\n\t/**\n\t * Registers disabled toolbar buttons for marks whose feature is disabled\n\t * but whose toolbar button is explicitly requested.\n\t */\n\tprivate registerDisabledToolbarItems(context: PluginContext): void {\n\t\tif (!this.config.toolbar) return;\n\n\t\tfor (const def of MARK_DEFINITIONS) {\n\t\t\tconst featureEnabled = this.config[def.configKey];\n\t\t\tconst toolbarVisible = this.config.toolbar[def.configKey] ?? true;\n\n\t\t\tif (!featureEnabled && toolbarVisible) {\n\t\t\t\tcontext.registerToolbarItem({\n\t\t\t\t\tid: def.type,\n\t\t\t\t\tgroup: 'format',\n\t\t\t\t\ticon: def.icon,\n\t\t\t\t\tlabel: this.getMarkLabel(def.type),\n\t\t\t\t\tcommand: toCommandName(def.type),\n\t\t\t\t\tpriority: def.rank * 10 + 10,\n\t\t\t\t\tisEnabled: () => false,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getMarkLabel(type: string): string {\n\t\tconst key = `${type}Label` as keyof TextFormattingLocale;\n\t\treturn this.locale[key] as string;\n\t}\n\n\t/** Checks if a toolbar button should be visible for a given mark. */\n\tprivate isToolbarVisible(\n\t\tconfigKey: keyof Omit<TextFormattingConfig, 'toolbar' | 'separatorAfter' | 'locale'>,\n\t): boolean {\n\t\tif (!this.config.toolbar) return true;\n\t\treturn this.config.toolbar[configKey] ?? true;\n\t}\n}\n\n/** Converts a mark type to its toggle command name (e.g. 'bold' → 'toggleBold'). */\nfunction toCommandName(markType: string): string {\n\treturn `toggle${markType.charAt(0).toUpperCase()}${markType.slice(1)}`;\n}\n"],"names":["TEXT_FORMATTING_LOCALE_EN","boldLabel","italicLabel","underlineLabel","TEXT_FORMATTING_LOCALES","en","de","es","fr","zh","ru","ar","hi","DEFAULT_CONFIG","bold","italic","underline","MARK_DEFINITIONS","type","configKey","rank","tag","label","icon","keyBinding","toHTMLString","content","parseHTML","getAttrs","el","fw","style","fontWeight","numeric","Number","parseInt","isNaN","sanitize","tags","fontStyle","textDecoration","includes","TextFormattingPlugin","id","name","priority","config","locale","this","context","resolvePluginLocale","enabledMarks","filter","def","lastVisibleMark","isToolbarVisible","at","isSeparatorTarget","separatorAfter","registerMark","registerKeymaps","registerDisabledToolbarItems","commandName","toCommandName","toolbarVisible","registerMarkSpec","toDOM","document","createElement","_mark","registerCommand","tr","toggleMark","getState","mkType","dispatch","getMarkLabel","registerToolbarItem","group","tooltip","formatShortcut","command","isActive","state","isMarkActive","marks","keymap","executeCommand","Object","keys","length","registerKeymap","toolbar","featureEnabled","isEnabled","key","markType","charAt","toUpperCase","slice"],"mappings":";;;;AAcO,MAAMA,IAAkD,EAC9DC,WAAW,QACXC,aAAa,UACbC,gBAAgB,YAAA,GA6DJC,IAAgE,EAC5EC,IAAIL,GACJM,IA1D8D,EAC9DL,WAAW,QACXC,aAAa,UACbC,gBAAgB,gBAAA,GAwDhBI,IAnD8D,EAC9DN,WAAW,WACXC,aAAa,WACbC,gBAAgB,YAAA,GAiDhBK,IA5C8D,EAC9DP,WAAW,QACXC,aAAa,YACbC,gBAAgB,WAAA,GA0ChBM,IArC8D,EAC9DR,WAAW,MACXC,aAAa,MACbC,gBAAgB,MAAA,GAmChBO,IA9B8D,EAC9DT,WAAW,UACXC,aAAa,UACbC,gBAAgB,eAAA,GA4BhBQ,IAvB8D,EAC9DV,WAAW,QACXC,aAAa,QACbC,gBAAgB,UAAA,GAqBhBS,IAhB8D,EAC9DX,WAAW,SACXC,aAAa,UACbC,gBAAgB,WAAA,EAAA,GC7BXU,IAAuC,EAC5CC,MAAAA,MACAC,QAAAA,MACAC,gBAAW,GAyBNC,IAA8C,CACnD,EACCC,MAAM,QACNC,WAAW,QACXC,MAAM,GACNC,KAAK,UACLC,OAAO,QACPC,MAbD,uTAcCC,YAAY,SACZC,cAAeC,CAAAA,OAAY,WAAWA,EAAAA,aACtCC,WAAW,CACV,EAAEN,KAAK,YACP,EACCA,KAAK,KACLO,UAAWC,CAAAA,OAAAA;AACV,QAAMC,KAAa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B;AAAA,EAGQ,iBACP5E,IAAAA;AAEA,WAAA,CAAK6B,KAAKF,OAAO8C,YACV5C,KAAKF,OAAO8C,QAAQzE,EAAAA,KAAAA;AAAAA,EAC5B;AAAA;AAID,SAAS4C,EAAciC,IAAAA;AACtB,SAAO,SAASA,GAASC,OAAO,CAAA,EAAGC,YAAAA,CAAAA,GAAgBF,GAASG,MAAM,CAAA,CAAA;AACnE;"}
|
|
1
|
+
{"version":3,"file":"index-Cd3uJLP3.mjs","sources":["../../src/plugins/text-formatting/TextFormattingLocale.ts","../../src/plugins/text-formatting/TextFormattingPlugin.ts"],"sourcesContent":["/**\n * Locale interface and default English locale for the TextFormattingPlugin.\n */\n\n// --- Locale Interface ---\n\nexport interface TextFormattingLocale {\n\treadonly boldLabel: string;\n\treadonly italicLabel: string;\n\treadonly underlineLabel: string;\n}\n\n// --- Default English Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_EN: TextFormattingLocale = {\n\tboldLabel: 'Bold',\n\titalicLabel: 'Italic',\n\tunderlineLabel: 'Underline',\n};\n\n// --- German Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_DE: TextFormattingLocale = {\n\tboldLabel: 'Fett',\n\titalicLabel: 'Kursiv',\n\tunderlineLabel: 'Unterstrichen',\n};\n\n// --- Spanish Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_ES: TextFormattingLocale = {\n\tboldLabel: 'Negrita',\n\titalicLabel: 'Cursiva',\n\tunderlineLabel: 'Subrayado',\n};\n\n// --- French Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_FR: TextFormattingLocale = {\n\tboldLabel: 'Gras',\n\titalicLabel: 'Italique',\n\tunderlineLabel: 'Souligné',\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_ZH: TextFormattingLocale = {\n\tboldLabel: '粗体',\n\titalicLabel: '斜体',\n\tunderlineLabel: '下划线',\n};\n\n// --- Russian Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_RU: TextFormattingLocale = {\n\tboldLabel: 'Жирный',\n\titalicLabel: 'Курсив',\n\tunderlineLabel: 'Подчёркнутый',\n};\n\n// --- Arabic Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_AR: TextFormattingLocale = {\n\tboldLabel: 'غامق',\n\titalicLabel: 'مائل',\n\tunderlineLabel: 'تحته خط',\n};\n\n// --- Hindi Locale ---\n\nexport const TEXT_FORMATTING_LOCALE_HI: TextFormattingLocale = {\n\tboldLabel: 'बोल्ड',\n\titalicLabel: 'इटैलिक',\n\tunderlineLabel: 'अंडरलाइन',\n};\n\n// --- Locale Map ---\n\nexport const TEXT_FORMATTING_LOCALES: Record<string, TextFormattingLocale> = {\n\ten: TEXT_FORMATTING_LOCALE_EN,\n\tde: TEXT_FORMATTING_LOCALE_DE,\n\tes: TEXT_FORMATTING_LOCALE_ES,\n\tfr: TEXT_FORMATTING_LOCALE_FR,\n\tzh: TEXT_FORMATTING_LOCALE_ZH,\n\tru: TEXT_FORMATTING_LOCALE_RU,\n\tar: TEXT_FORMATTING_LOCALE_AR,\n\thi: TEXT_FORMATTING_LOCALE_HI,\n};\n","/**\n * TextFormattingPlugin: registers inline marks (bold, italic, underline)\n * with their MarkSpecs, toggle commands, keyboard shortcuts, and toolbar items.\n *\n * This plugin is data-driven — each mark type is defined declaratively and\n * all registrations (MarkSpec, command, keymap, toolbar item) are derived\n * from the same definition.\n *\n * Supports two separate config dimensions:\n * - Feature config (bold/italic/underline): controls whether the mark is\n * registered in the schema. When disabled, the keyboard shortcut does nothing.\n * - Toolbar config: controls whether the toolbar button is visible.\n * When a feature is disabled but toolbar is enabled, the button renders as disabled.\n */\n\nimport { isMarkActive, toggleMark } from '../../commands/Commands.js';\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport type { ParseRule } from '../../model/ParseRule.js';\nimport type { SanitizeConfig } from '../../model/SanitizeConfig.js';\nimport { markType as mkType } from '../../model/TypeBrands.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { formatShortcut } from '../toolbar/ToolbarItem.js';\nimport { TEXT_FORMATTING_LOCALES, type TextFormattingLocale } from './TextFormattingLocale.js';\n\n// --- Configuration ---\n\n/** Controls toolbar button visibility per mark. */\nexport interface TextFormattingToolbarConfig {\n\treadonly bold?: boolean;\n\treadonly italic?: boolean;\n\treadonly underline?: boolean;\n}\n\n/** Controls which inline marks are enabled and which toolbar buttons are shown. */\nexport interface TextFormattingConfig {\n\treadonly bold: boolean;\n\treadonly italic: boolean;\n\treadonly underline: boolean;\n\treadonly toolbar?: TextFormattingToolbarConfig;\n\t/** When true, a separator is rendered after the last text-formatting toolbar item. */\n\treadonly separatorAfter?: boolean;\n\treadonly locale?: TextFormattingLocale;\n}\n\nconst DEFAULT_CONFIG: TextFormattingConfig = {\n\tbold: true,\n\titalic: true,\n\tunderline: true,\n};\n\n// --- Mark Definitions ---\n\ninterface MarkDefinition {\n\treadonly type: string;\n\treadonly configKey: keyof Omit<TextFormattingConfig, 'toolbar' | 'separatorAfter' | 'locale'>;\n\treadonly rank: number;\n\treadonly tag: string;\n\treadonly label: string;\n\treadonly icon: string;\n\treadonly keyBinding: string;\n\treadonly toHTMLString: (content: string) => string;\n\treadonly parseHTML: readonly ParseRule[];\n\treadonly sanitize: SanitizeConfig;\n}\n\nconst BOLD_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M15.6 10.79c.97-.67 1.65-1.77 1.65-2.79 0-2.26-1.75-4-4-4H7v14h7.04c2.09 0 3.71-1.7 3.71-3.79 0-1.52-.86-2.82-2.15-3.42zM10 6.5h3c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5h-3v-3zm3.5 9H10v-3h3.5c.83 0 1.5.67 1.5 1.5s-.67 1.5-1.5 1.5z\"/></svg>';\nconst ITALIC_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M10 4v3h2.21l-3.42 8H6v3h8v-3h-2.21l3.42-8H18V4z\"/></svg>';\nconst UNDERLINE_ICON =\n\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M12 17c3.31 0 6-2.69 6-6V3h-2.5v8c0 1.93-1.57 3.5-3.5 3.5S8.5 12.93 8.5 11V3H6v8c0 3.31 2.69 6 6 6zm-7 2v2h14v-2H5z\"/></svg>';\n\nconst MARK_DEFINITIONS: readonly MarkDefinition[] = [\n\t{\n\t\ttype: 'bold',\n\t\tconfigKey: 'bold',\n\t\trank: 0,\n\t\ttag: 'strong',\n\t\tlabel: 'Bold',\n\t\ticon: BOLD_ICON,\n\t\tkeyBinding: 'Mod-B',\n\t\ttoHTMLString: (content) => `<strong>${content}</strong>`,\n\t\tparseHTML: [\n\t\t\t{ tag: 'strong' },\n\t\t\t{\n\t\t\t\ttag: 'b',\n\t\t\t\tgetAttrs: (el: HTMLElement) => {\n\t\t\t\t\tconst fw: string = el.style.fontWeight;\n\t\t\t\t\treturn fw === 'normal' || fw === '400' ? false : {};\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\ttag: 'span',\n\t\t\t\tgetAttrs: (el: HTMLElement) => {\n\t\t\t\t\tconst fw: string = el.style.fontWeight;\n\t\t\t\t\tif (!fw) return false;\n\t\t\t\t\tif (fw === 'bold') return {};\n\t\t\t\t\tconst numeric: number = Number.parseInt(fw, 10);\n\t\t\t\t\treturn !Number.isNaN(numeric) && numeric >= 700 ? {} : false;\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tsanitize: { tags: ['strong', 'b'] },\n\t},\n\t{\n\t\ttype: 'italic',\n\t\tconfigKey: 'italic',\n\t\trank: 1,\n\t\ttag: 'em',\n\t\tlabel: 'Italic',\n\t\ticon: ITALIC_ICON,\n\t\tkeyBinding: 'Mod-I',\n\t\ttoHTMLString: (content) => `<em>${content}</em>`,\n\t\tparseHTML: [\n\t\t\t{ tag: 'em' },\n\t\t\t{ tag: 'i' },\n\t\t\t{\n\t\t\t\ttag: 'span',\n\t\t\t\tgetAttrs: (el: HTMLElement) => {\n\t\t\t\t\treturn el.style.fontStyle === 'italic' ? {} : false;\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tsanitize: { tags: ['em', 'i'] },\n\t},\n\t{\n\t\ttype: 'underline',\n\t\tconfigKey: 'underline',\n\t\trank: 2,\n\t\ttag: 'u',\n\t\tlabel: 'Underline',\n\t\ticon: UNDERLINE_ICON,\n\t\tkeyBinding: 'Mod-U',\n\t\ttoHTMLString: (content) => `<u>${content}</u>`,\n\t\tparseHTML: [\n\t\t\t{ tag: 'u' },\n\t\t\t{\n\t\t\t\ttag: 'span',\n\t\t\t\tgetAttrs: (el: HTMLElement) => {\n\t\t\t\t\treturn el.style.textDecoration.includes('underline') ? {} : false;\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t\tsanitize: { tags: ['u'] },\n\t},\n];\n\n// --- Plugin ---\n\nexport class TextFormattingPlugin implements Plugin {\n\treadonly id = 'text-formatting';\n\treadonly name = 'Text Formatting';\n\treadonly priority = 20;\n\n\tprivate readonly config: TextFormattingConfig;\n\tprivate locale!: TextFormattingLocale;\n\n\tconstructor(config?: Partial<TextFormattingConfig>) {\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(TEXT_FORMATTING_LOCALES, context, this.config.locale);\n\n\t\tconst enabledMarks = MARK_DEFINITIONS.filter((def) => this.config[def.configKey]);\n\n\t\t// Determine which marks will have visible toolbar items\n\t\tconst visibleToolbarMarks = enabledMarks.filter((def) => this.isToolbarVisible(def.configKey));\n\t\tconst lastVisibleMark = visibleToolbarMarks.at(-1);\n\n\t\tfor (const def of enabledMarks) {\n\t\t\tconst isSeparatorTarget = this.config.separatorAfter && def === lastVisibleMark;\n\t\t\tthis.registerMark(context, def, isSeparatorTarget);\n\t\t}\n\n\t\tthis.registerKeymaps(context, enabledMarks);\n\n\t\t// Register disabled placeholder buttons for marks that are disabled\n\t\t// as features but explicitly requested in the toolbar config\n\t\tthis.registerDisabledToolbarItems(context);\n\t}\n\n\tprivate registerMark(\n\t\tcontext: PluginContext,\n\t\tdef: MarkDefinition,\n\t\tseparatorAfter?: boolean,\n\t): void {\n\t\tconst commandName = toCommandName(def.type);\n\t\tconst toolbarVisible = this.isToolbarVisible(def.configKey);\n\n\t\tcontext.registerMarkSpec({\n\t\t\ttype: def.type,\n\t\t\trank: def.rank,\n\t\t\ttoDOM() {\n\t\t\t\treturn document.createElement(def.tag);\n\t\t\t},\n\t\t\ttoHTMLString: (_mark, content) => def.toHTMLString(content),\n\t\t\tparseHTML: def.parseHTML,\n\t\t\tsanitize: def.sanitize,\n\t\t});\n\n\t\tcontext.registerCommand(commandName, () => {\n\t\t\tconst tr = toggleMark(context.getState(), mkType(def.type));\n\t\t\tif (tr) {\n\t\t\t\tcontext.dispatch(tr);\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\treturn false;\n\t\t});\n\n\t\tif (toolbarVisible) {\n\t\t\tconst label: string = this.getMarkLabel(def.type);\n\t\t\tcontext.registerToolbarItem({\n\t\t\t\tid: def.type,\n\t\t\t\tgroup: 'format',\n\t\t\t\ticon: def.icon,\n\t\t\t\tlabel,\n\t\t\t\ttooltip: `${label} (${formatShortcut(def.keyBinding)})`,\n\t\t\t\tcommand: commandName,\n\t\t\t\tpriority: def.rank * 10 + 10,\n\t\t\t\tseparatorAfter,\n\t\t\t\tisActive: (state) => isMarkActive(state, mkType(def.type)),\n\t\t\t});\n\t\t}\n\t}\n\n\tprivate registerKeymaps(context: PluginContext, marks: readonly MarkDefinition[]): void {\n\t\tconst keymap: Record<string, () => boolean> = {};\n\t\tfor (const def of marks) {\n\t\t\tconst commandName = toCommandName(def.type);\n\t\t\tkeymap[def.keyBinding] = () => context.executeCommand(commandName);\n\t\t}\n\t\tif (Object.keys(keymap).length > 0) {\n\t\t\tcontext.registerKeymap(keymap);\n\t\t}\n\t}\n\n\t/**\n\t * Registers disabled toolbar buttons for marks whose feature is disabled\n\t * but whose toolbar button is explicitly requested.\n\t */\n\tprivate registerDisabledToolbarItems(context: PluginContext): void {\n\t\tif (!this.config.toolbar) return;\n\n\t\tfor (const def of MARK_DEFINITIONS) {\n\t\t\tconst featureEnabled = this.config[def.configKey];\n\t\t\tconst toolbarVisible = this.config.toolbar[def.configKey] ?? true;\n\n\t\t\tif (!featureEnabled && toolbarVisible) {\n\t\t\t\tcontext.registerToolbarItem({\n\t\t\t\t\tid: def.type,\n\t\t\t\t\tgroup: 'format',\n\t\t\t\t\ticon: def.icon,\n\t\t\t\t\tlabel: this.getMarkLabel(def.type),\n\t\t\t\t\tcommand: toCommandName(def.type),\n\t\t\t\t\tpriority: def.rank * 10 + 10,\n\t\t\t\t\tisEnabled: () => false,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate getMarkLabel(type: string): string {\n\t\tconst key = `${type}Label` as keyof TextFormattingLocale;\n\t\treturn this.locale[key] as string;\n\t}\n\n\t/** Checks if a toolbar button should be visible for a given mark. */\n\tprivate isToolbarVisible(\n\t\tconfigKey: keyof Omit<TextFormattingConfig, 'toolbar' | 'separatorAfter' | 'locale'>,\n\t): boolean {\n\t\tif (!this.config.toolbar) return true;\n\t\treturn this.config.toolbar[configKey] ?? true;\n\t}\n}\n\n/** Converts a mark type to its toggle command name (e.g. 'bold' → 'toggleBold'). */\nfunction toCommandName(markType: string): string {\n\treturn `toggle${markType.charAt(0).toUpperCase()}${markType.slice(1)}`;\n}\n"],"names":["TEXT_FORMATTING_LOCALE_EN","boldLabel","italicLabel","underlineLabel","TEXT_FORMATTING_LOCALES","en","de","es","fr","zh","ru","ar","hi","DEFAULT_CONFIG","bold","italic","underline","MARK_DEFINITIONS","type","configKey","rank","tag","label","icon","keyBinding","toHTMLString","content","parseHTML","getAttrs","el","fw","style","fontWeight","numeric","Number","parseInt","isNaN","sanitize","tags","fontStyle","textDecoration","includes","TextFormattingPlugin","id","name","priority","config","locale","this","context","resolvePluginLocale","enabledMarks","filter","def","lastVisibleMark","isToolbarVisible","at","isSeparatorTarget","separatorAfter","registerMark","registerKeymaps","registerDisabledToolbarItems","commandName","toCommandName","toolbarVisible","registerMarkSpec","toDOM","document","createElement","_mark","registerCommand","tr","toggleMark","getState","mkType","dispatch","getMarkLabel","registerToolbarItem","group","tooltip","formatShortcut","command","isActive","state","isMarkActive","marks","keymap","executeCommand","Object","keys","length","registerKeymap","toolbar","featureEnabled","isEnabled","key","markType","charAt","toUpperCase","slice"],"mappings":";;;;AAcO,MAAMA,IAAkD,EAC9DC,WAAW,QACXC,aAAa,UACbC,gBAAgB,YAAA,GA6DJC,IAAgE,EAC5EC,IAAIL,GACJM,IA1D8D,EAC9DL,WAAW,QACXC,aAAa,UACbC,gBAAgB,gBAAA,GAwDhBI,IAnD8D,EAC9DN,WAAW,WACXC,aAAa,WACbC,gBAAgB,YAAA,GAiDhBK,IA5C8D,EAC9DP,WAAW,QACXC,aAAa,YACbC,gBAAgB,WAAA,GA0ChBM,IArC8D,EAC9DR,WAAW,MACXC,aAAa,MACbC,gBAAgB,MAAA,GAmChBO,IA9B8D,EAC9DT,WAAW,UACXC,aAAa,UACbC,gBAAgB,eAAA,GA4BhBQ,IAvB8D,EAC9DV,WAAW,QACXC,aAAa,QACbC,gBAAgB,UAAA,GAqBhBS,IAhB8D,EAC9DX,WAAW,SACXC,aAAa,UACbC,gBAAgB,WAAA,EAAA,GC7BXU,IAAuC,EAC5CC,MAAAA,MACAC,QAAAA,MACAC,gBAAW,GAyBNC,IAA8C,CACnD,EACCC,MAAM,QACNC,WAAW,QACXC,MAAM,GACNC,KAAK,UACLC,OAAO,QACPC,MAbD,uTAcCC,YAAY,SACZC,cAAeC,CAAAA,OAAY,WAAWA,EAAAA,aACtCC,WAAW,CACV,EAAEN,KAAK,YACP,EACCA,KAAK,KACLO,UAAWC,CAAAA,OAAAA;AACV,QAAMC,KAAaD,GAAGE,MAAMC;AA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P5E,IAAAA;AAEA,WAAA,CAAK6B,KAAKF,OAAO8C,YACV5C,KAAKF,OAAO8C,QAAQzE,EAAAA,KAAAA;AAAAA,EAC5B;AAAA;AAID,SAAS4C,EAAciC,IAAAA;AACtB,SAAO,SAASA,GAASC,OAAO,CAAA,EAAGC,YAAAA,CAAAA,GAAgBF,GAASG,MAAM,CAAA,CAAA;AACnE;"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { r as e } from "./resolvePluginLocale-B4w1OkPy.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { k as t } from "./Document-Brtw2jL1.mjs";
|
|
3
3
|
import { c as o } from "./NodeSpec-NZVvcCuH.mjs";
|
|
4
|
-
import { i as r, a as i, b as l,
|
|
4
|
+
import { i as r, a as i, b as l, d as n } from "./Selection-BRTab5hO.mjs";
|
|
5
5
|
import { n as a } from "./TypeBrands-C09nE2qO.mjs";
|
|
6
6
|
import { f as s } from "./ToolbarItem-BpZggUGo.mjs";
|
|
7
|
-
const c = { label: "Horizontal Rule", tooltip: (e2) => `Horizontal Rule (${e2})` }, p = { en: c, de: { label: "Trennlinie", tooltip: (e2) => `Trennlinie (${e2})` }, es: { label: "Línea horizontal", tooltip: (e2) => `Línea horizontal (${e2})` }, fr: { label: "Ligne horizontale", tooltip: (e2) => `Ligne horizontale (${e2})` }, zh: { label: "分隔线", tooltip: (e2) => `分隔线 (${e2})` }, ru: { label: "Горизонтальная линия", tooltip: (e2) => `Горизонтальная линия (${e2})` }, ar: { label: "خط أفقي", tooltip: (e2) => `خط أفقي (${e2})` }, hi: { label: "क्षैतिज रेखा", tooltip: (e2) => `क्षैतिज रेखा (${e2})` } },
|
|
8
|
-
function
|
|
7
|
+
const c = { label: "Horizontal Rule", tooltip: (e2) => `Horizontal Rule (${e2})` }, p = { en: c, de: { label: "Trennlinie", tooltip: (e2) => `Trennlinie (${e2})` }, es: { label: "Línea horizontal", tooltip: (e2) => `Línea horizontal (${e2})` }, fr: { label: "Ligne horizontale", tooltip: (e2) => `Ligne horizontale (${e2})` }, zh: { label: "分隔线", tooltip: (e2) => `分隔线 (${e2})` }, ru: { label: "Горизонтальная линия", tooltip: (e2) => `Горизонтальная линия (${e2})` }, ar: { label: "خط أفقي", tooltip: (e2) => `خط أفقي (${e2})` }, hi: { label: "क्षैतिज रेखा", tooltip: (e2) => `क्षैतिज रेखा (${e2})` } }, u = {};
|
|
8
|
+
function h(e2) {
|
|
9
9
|
const t2 = e2.selection;
|
|
10
10
|
return r(t2) || i(t2) ? -1 : e2.doc.children.findIndex((e3) => e3.id === t2.anchor.blockId);
|
|
11
11
|
}
|
|
@@ -16,7 +16,7 @@ class m {
|
|
|
16
16
|
config;
|
|
17
17
|
locale;
|
|
18
18
|
constructor(e2) {
|
|
19
|
-
this.config = { ...
|
|
19
|
+
this.config = { ...u, ...e2 };
|
|
20
20
|
}
|
|
21
21
|
init(t2) {
|
|
22
22
|
this.locale = e(p, t2, this.config.locale), this.registerNodeSpec(t2), this.registerCommands(t2), this.registerKeymap(t2), this.registerInputRule(t2), this.registerToolbarItem(t2);
|
|
@@ -35,9 +35,9 @@ class m {
|
|
|
35
35
|
const p2 = e3.selection;
|
|
36
36
|
if (r(p2) || i(p2)) return null;
|
|
37
37
|
if (!l(p2)) return null;
|
|
38
|
-
const
|
|
39
|
-
if (!
|
|
40
|
-
const m2 =
|
|
38
|
+
const u2 = e3.getBlock(p2.anchor.blockId);
|
|
39
|
+
if (!u2 || "paragraph" !== u2.type) return null;
|
|
40
|
+
const m2 = h(e3);
|
|
41
41
|
if (-1 === m2) return null;
|
|
42
42
|
const d = t(a("paragraph"));
|
|
43
43
|
return e3.transaction("input").deleteTextAt(p2.anchor.blockId, 0, c2).setBlockType(p2.anchor.blockId, a("horizontal_rule")).insertNode([], m2 + 1, d).setSelection(n(d.id, 0)).build();
|
|
@@ -49,7 +49,7 @@ class m {
|
|
|
49
49
|
insertHorizontalRule(e2) {
|
|
50
50
|
const o2 = e2.getState();
|
|
51
51
|
if (r(o2.selection) || i(o2.selection)) return false;
|
|
52
|
-
const l2 =
|
|
52
|
+
const l2 = h(o2);
|
|
53
53
|
if (-1 === l2) return false;
|
|
54
54
|
const s2 = t(a("horizontal_rule")), c2 = t(a("paragraph")), p2 = o2.transaction("command").insertNode([], l2 + 1, s2).insertNode([], l2 + 2, c2).setSelection(n(c2.id, 0)).build();
|
|
55
55
|
return e2.dispatch(p2), true;
|
|
@@ -60,4 +60,4 @@ export {
|
|
|
60
60
|
p as a,
|
|
61
61
|
c as b
|
|
62
62
|
};
|
|
63
|
-
//# sourceMappingURL=index-
|
|
63
|
+
//# sourceMappingURL=index-CluzpB2b.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-C0cEs7Jc.mjs","sources":["../../src/plugins/horizontal-rule/HorizontalRuleLocale.ts","../../src/plugins/horizontal-rule/HorizontalRulePlugin.ts"],"sourcesContent":["/** Locale interface and default English locale for the HorizontalRulePlugin. */\n\n// --- Locale Interface ---\n\nexport interface HorizontalRuleLocale {\n\treadonly label: string;\n\treadonly tooltip: (shortcut: string) => string;\n}\n\n// --- Default English Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_EN: HorizontalRuleLocale = {\n\tlabel: 'Horizontal Rule',\n\ttooltip: (shortcut: string) => `Horizontal Rule (${shortcut})`,\n};\n\n// --- German Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_DE: HorizontalRuleLocale = {\n\tlabel: 'Trennlinie',\n\ttooltip: (shortcut: string) => `Trennlinie (${shortcut})`,\n};\n\n// --- Spanish Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_ES: HorizontalRuleLocale = {\n\tlabel: 'Línea horizontal',\n\ttooltip: (shortcut: string) => `Línea horizontal (${shortcut})`,\n};\n\n// --- French Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_FR: HorizontalRuleLocale = {\n\tlabel: 'Ligne horizontale',\n\ttooltip: (shortcut: string) => `Ligne horizontale (${shortcut})`,\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_ZH: HorizontalRuleLocale = {\n\tlabel: '分隔线',\n\ttooltip: (shortcut: string) => `分隔线 (${shortcut})`,\n};\n\n// --- Russian Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_RU: HorizontalRuleLocale = {\n\tlabel: 'Горизонтальная линия',\n\ttooltip: (shortcut: string) => `Горизонтальная линия (${shortcut})`,\n};\n\n// --- Arabic Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_AR: HorizontalRuleLocale = {\n\tlabel: 'خط أفقي',\n\ttooltip: (shortcut: string) => `خط أفقي (${shortcut})`,\n};\n\n// --- Hindi Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_HI: HorizontalRuleLocale = {\n\tlabel: 'क्षैतिज रेखा',\n\ttooltip: (shortcut: string) => `क्षैतिज रेखा (${shortcut})`,\n};\n\n// --- Locale Map ---\n\nexport const HORIZONTAL_RULE_LOCALES: Record<string, HorizontalRuleLocale> = {\n\ten: HORIZONTAL_RULE_LOCALE_EN,\n\tde: HORIZONTAL_RULE_LOCALE_DE,\n\tes: HORIZONTAL_RULE_LOCALE_ES,\n\tfr: HORIZONTAL_RULE_LOCALE_FR,\n\tzh: HORIZONTAL_RULE_LOCALE_ZH,\n\tru: HORIZONTAL_RULE_LOCALE_RU,\n\tar: HORIZONTAL_RULE_LOCALE_AR,\n\thi: HORIZONTAL_RULE_LOCALE_HI,\n};\n","/**\n * HorizontalRulePlugin: registers a horizontal rule (divider) void block type\n * with NodeSpec, insert command, input rule, keyboard shortcut, and toolbar button.\n */\n\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport { createBlockNode } from '../../model/Document.js';\nimport { createBlockElement } from '../../model/NodeSpec.js';\nimport {\n\tcreateCollapsedSelection,\n\tisCollapsed,\n\tisGapCursor,\n\tisNodeSelection,\n} from '../../model/Selection.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { formatShortcut } from '../toolbar/ToolbarItem.js';\nimport { HORIZONTAL_RULE_LOCALES, type HorizontalRuleLocale } from './HorizontalRuleLocale.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface NodeAttrRegistry {\n\t\thorizontal_rule: Record<string, never>;\n\t}\n}\n\n// --- Configuration ---\n\nexport interface HorizontalRuleConfig {\n\t/** When true, a separator is rendered after the toolbar item. */\n\treadonly separatorAfter?: boolean;\n\t/** Locale override for user-facing strings. */\n\treadonly locale?: HorizontalRuleLocale;\n}\n\nconst DEFAULT_CONFIG: HorizontalRuleConfig = {};\n\n// --- Helpers ---\n\n/** Finds the index of the cursor's block among top-level document children. */\nfunction findBlockIndexForCursor(state: EditorState): number {\n\tconst sel = state.selection;\n\tif (isNodeSelection(sel) || isGapCursor(sel)) return -1;\n\treturn state.doc.children.findIndex((b) => b.id === sel.anchor.blockId);\n}\n\n// --- Plugin ---\n\nexport class HorizontalRulePlugin implements Plugin {\n\treadonly id = 'horizontal-rule';\n\treadonly name = 'Horizontal Rule';\n\treadonly priority = 40;\n\n\tprivate readonly config: HorizontalRuleConfig;\n\tprivate locale!: HorizontalRuleLocale;\n\n\tconstructor(config?: Partial<HorizontalRuleConfig>) {\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(HORIZONTAL_RULE_LOCALES, context, this.config.locale);\n\t\tthis.registerNodeSpec(context);\n\t\tthis.registerCommands(context);\n\t\tthis.registerKeymap(context);\n\t\tthis.registerInputRule(context);\n\t\tthis.registerToolbarItem(context);\n\t}\n\n\tprivate registerNodeSpec(context: PluginContext): void {\n\t\tcontext.registerNodeSpec({\n\t\t\ttype: 'horizontal_rule',\n\t\t\tgroup: 'block',\n\t\t\tisVoid: true,\n\t\t\ttoDOM(node) {\n\t\t\t\treturn createBlockElement('hr', node.id);\n\t\t\t},\n\t\t\ttoHTML() {\n\t\t\t\treturn '<hr>';\n\t\t\t},\n\t\t\tparseHTML: [{ tag: 'hr' }],\n\t\t\tsanitize: { tags: ['hr'] },\n\t\t});\n\t}\n\n\tprivate registerCommands(context: PluginContext): void {\n\t\tcontext.registerCommand('insertHorizontalRule', () => {\n\t\t\treturn this.insertHorizontalRule(context);\n\t\t});\n\t}\n\n\tprivate registerKeymap(context: PluginContext): void {\n\t\tcontext.registerKeymap({\n\t\t\t'Mod-Shift-H': () => context.executeCommand('insertHorizontalRule'),\n\t\t});\n\t}\n\n\tprivate registerInputRule(context: PluginContext): void {\n\t\tcontext.registerInputRule({\n\t\t\tpattern: /^-{3,} $/,\n\t\t\thandler(state, _match, _start, end) {\n\t\t\t\tconst sel = state.selection;\n\t\t\t\tif (isNodeSelection(sel) || isGapCursor(sel)) return null;\n\t\t\t\tif (!isCollapsed(sel)) return null;\n\n\t\t\t\tconst block = state.getBlock(sel.anchor.blockId);\n\t\t\t\tif (!block || block.type !== 'paragraph') return null;\n\n\t\t\t\tconst blockIndex: number = findBlockIndexForCursor(state);\n\t\t\t\tif (blockIndex === -1) return null;\n\n\t\t\t\tconst newParagraph = createBlockNode(nodeType('paragraph'));\n\n\t\t\t\treturn state\n\t\t\t\t\t.transaction('input')\n\t\t\t\t\t.deleteTextAt(sel.anchor.blockId, 0, end)\n\t\t\t\t\t.setBlockType(sel.anchor.blockId, nodeType('horizontal_rule'))\n\t\t\t\t\t.insertNode([], blockIndex + 1, newParagraph)\n\t\t\t\t\t.setSelection(createCollapsedSelection(newParagraph.id, 0))\n\t\t\t\t\t.build();\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate registerToolbarItem(context: PluginContext): void {\n\t\tconst icon =\n\t\t\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M4 11h16v2H4z\"/></svg>';\n\n\t\tcontext.registerToolbarItem({\n\t\t\tid: 'horizontal-rule',\n\t\t\tgroup: 'block',\n\t\t\ticon,\n\t\t\tlabel: this.locale.label,\n\t\t\ttooltip: this.locale.tooltip(formatShortcut('Mod-Shift-H')),\n\t\t\tcommand: 'insertHorizontalRule',\n\t\t\tpriority: 60,\n\t\t\tseparatorAfter: this.config.separatorAfter,\n\t\t\tisActive: () => false,\n\t\t});\n\t}\n\n\t/**\n\t * Inserts a horizontal rule after the current block,\n\t * followed by a new paragraph for continued editing.\n\t */\n\tprivate insertHorizontalRule(context: PluginContext): boolean {\n\t\tconst state: EditorState = context.getState();\n\t\tif (isNodeSelection(state.selection) || isGapCursor(state.selection)) return false;\n\t\tconst blockIndex: number = findBlockIndexForCursor(state);\n\t\tif (blockIndex === -1) return false;\n\n\t\tconst hrBlock = createBlockNode(nodeType('horizontal_rule'));\n\t\tconst newParagraph = createBlockNode(nodeType('paragraph'));\n\n\t\tconst tr = state\n\t\t\t.transaction('command')\n\t\t\t.insertNode([], blockIndex + 1, hrBlock)\n\t\t\t.insertNode([], blockIndex + 2, newParagraph)\n\t\t\t.setSelection(createCollapsedSelection(newParagraph.id, 0))\n\t\t\t.build();\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n}\n"],"names":["HORIZONTAL_RULE_LOCALE_EN","label","tooltip","shortcut","HORIZONTAL_RULE_LOCALES","en","de","es","fr","zh","ru","ar","hi","DEFAULT_CONFIG","findBlockIndexForCursor","state","sel","selection","isNodeSelection","isGapCursor","doc","children","findIndex","b","id","anchor","blockId","HorizontalRulePlugin","name","priority","config","locale","this","context","resolvePluginLocale","registerNodeSpec","registerCommands","registerKeymap","registerInputRule","registerToolbarItem","type","group","isVoid","toDOM","node","createBlockElement","toHTML","parseHTML","tag","sanitize","tags","registerCommand","insertHorizontalRule","executeCommand","pattern","_match","_start","end","isCollapsed","block","getBlock","blockIndex","newParagraph","createBlockNode","nodeType","transaction","deleteTextAt","setBlockType","insertNode","setSelection","createCollapsedSelection","build","icon","formatShortcut","command","separatorAfter","isActive","getState","hrBl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,iBAAA,CAAA,EAC1CI,WAAW,CAAA,GAAIP,KAAa,GAAGC,CAAAA,EAC/BO,aAAaC,EAAyBR,EAAatC,IAAI,CAAA,CAAA,EACvD+C;IACH,EAAA,CAAA;AAAA,EAEF;AAAA,EAEQ,oBAAoBtC,IAAAA;AAI3BA,IAAAA,GAAQM,oBAAoB,EAC3Bf,IAAI,mBACJiB,OAAO,SACP+B,MALA,+FAMAvE,OAAO+B,KAAKD,OAAO9B,OACnBC,SAAS8B,KAAKD,OAAO7B,QAAQuE,EAAe,aAAA,CAAA,GAC5CC,SAAS,wBACT7C,UAAU,IACV8C,gBAAgB3C,KAAKF,OAAO6C,gBAC5BC,UAAU,YAAM,CAAA;AAAA,EAElB;AAAA,EAMQ,qBAAqB3C,IAAAA;AAC5B,UAAMlB,KAAqBkB,GAAQ4C;AACnC,QAAI3D,EAAgBH,GAAME,SAAAA,KAAcE,EAAYJ,GAAME,WAAY,QAAA;AACtE,UAAM4C,KAAqB/C,EAAwBC;AACnD,QAAA,OAAI8C,GAAmB,QAAA;AAEvB,UAAMiB,KAAUf,EAAgBC,EAAS,iBAAA,CAAA,GACnCF,KAAeC,EAAgBC,EAAS,WAAA,CAAA,GAExCe,KAAKhE,GACTkD,YAAY,SAAA,EACZG,WAAW,CAAA,GAAIP,KAAa,GAAGiB,EAAAA,EAC/BV,WAAW,IAAIP,KAAa,GAAGC,IAC/BO,aAAaC,EAAyBR,GAAatC,IAAI,CAAA,CAAA,EACvD+C;AAGF,WADAtC,GAAQ+C,SAASD,EAAAA,GAAAA;AAAAA,EAElB;AAAA;"}
|
|
1
|
+
{"version":3,"file":"index-CluzpB2b.mjs","sources":["../../src/plugins/horizontal-rule/HorizontalRuleLocale.ts","../../src/plugins/horizontal-rule/HorizontalRulePlugin.ts"],"sourcesContent":["/** Locale interface and default English locale for the HorizontalRulePlugin. */\n\n// --- Locale Interface ---\n\nexport interface HorizontalRuleLocale {\n\treadonly label: string;\n\treadonly tooltip: (shortcut: string) => string;\n}\n\n// --- Default English Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_EN: HorizontalRuleLocale = {\n\tlabel: 'Horizontal Rule',\n\ttooltip: (shortcut: string) => `Horizontal Rule (${shortcut})`,\n};\n\n// --- German Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_DE: HorizontalRuleLocale = {\n\tlabel: 'Trennlinie',\n\ttooltip: (shortcut: string) => `Trennlinie (${shortcut})`,\n};\n\n// --- Spanish Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_ES: HorizontalRuleLocale = {\n\tlabel: 'Línea horizontal',\n\ttooltip: (shortcut: string) => `Línea horizontal (${shortcut})`,\n};\n\n// --- French Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_FR: HorizontalRuleLocale = {\n\tlabel: 'Ligne horizontale',\n\ttooltip: (shortcut: string) => `Ligne horizontale (${shortcut})`,\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_ZH: HorizontalRuleLocale = {\n\tlabel: '分隔线',\n\ttooltip: (shortcut: string) => `分隔线 (${shortcut})`,\n};\n\n// --- Russian Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_RU: HorizontalRuleLocale = {\n\tlabel: 'Горизонтальная линия',\n\ttooltip: (shortcut: string) => `Горизонтальная линия (${shortcut})`,\n};\n\n// --- Arabic Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_AR: HorizontalRuleLocale = {\n\tlabel: 'خط أفقي',\n\ttooltip: (shortcut: string) => `خط أفقي (${shortcut})`,\n};\n\n// --- Hindi Locale ---\n\nexport const HORIZONTAL_RULE_LOCALE_HI: HorizontalRuleLocale = {\n\tlabel: 'क्षैतिज रेखा',\n\ttooltip: (shortcut: string) => `क्षैतिज रेखा (${shortcut})`,\n};\n\n// --- Locale Map ---\n\nexport const HORIZONTAL_RULE_LOCALES: Record<string, HorizontalRuleLocale> = {\n\ten: HORIZONTAL_RULE_LOCALE_EN,\n\tde: HORIZONTAL_RULE_LOCALE_DE,\n\tes: HORIZONTAL_RULE_LOCALE_ES,\n\tfr: HORIZONTAL_RULE_LOCALE_FR,\n\tzh: HORIZONTAL_RULE_LOCALE_ZH,\n\tru: HORIZONTAL_RULE_LOCALE_RU,\n\tar: HORIZONTAL_RULE_LOCALE_AR,\n\thi: HORIZONTAL_RULE_LOCALE_HI,\n};\n","/**\n * HorizontalRulePlugin: registers a horizontal rule (divider) void block type\n * with NodeSpec, insert command, input rule, keyboard shortcut, and toolbar button.\n */\n\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport { createBlockNode } from '../../model/Document.js';\nimport { createBlockElement } from '../../model/NodeSpec.js';\nimport {\n\tcreateCollapsedSelection,\n\tisCollapsed,\n\tisGapCursor,\n\tisNodeSelection,\n} from '../../model/Selection.js';\nimport { nodeType } from '../../model/TypeBrands.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { formatShortcut } from '../toolbar/ToolbarItem.js';\nimport { HORIZONTAL_RULE_LOCALES, type HorizontalRuleLocale } from './HorizontalRuleLocale.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface NodeAttrRegistry {\n\t\thorizontal_rule: Record<string, never>;\n\t}\n}\n\n// --- Configuration ---\n\nexport interface HorizontalRuleConfig {\n\t/** When true, a separator is rendered after the toolbar item. */\n\treadonly separatorAfter?: boolean;\n\t/** Locale override for user-facing strings. */\n\treadonly locale?: HorizontalRuleLocale;\n}\n\nconst DEFAULT_CONFIG: HorizontalRuleConfig = {};\n\n// --- Helpers ---\n\n/** Finds the index of the cursor's block among top-level document children. */\nfunction findBlockIndexForCursor(state: EditorState): number {\n\tconst sel = state.selection;\n\tif (isNodeSelection(sel) || isGapCursor(sel)) return -1;\n\treturn state.doc.children.findIndex((b) => b.id === sel.anchor.blockId);\n}\n\n// --- Plugin ---\n\nexport class HorizontalRulePlugin implements Plugin {\n\treadonly id = 'horizontal-rule';\n\treadonly name = 'Horizontal Rule';\n\treadonly priority = 40;\n\n\tprivate readonly config: HorizontalRuleConfig;\n\tprivate locale!: HorizontalRuleLocale;\n\n\tconstructor(config?: Partial<HorizontalRuleConfig>) {\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(HORIZONTAL_RULE_LOCALES, context, this.config.locale);\n\t\tthis.registerNodeSpec(context);\n\t\tthis.registerCommands(context);\n\t\tthis.registerKeymap(context);\n\t\tthis.registerInputRule(context);\n\t\tthis.registerToolbarItem(context);\n\t}\n\n\tprivate registerNodeSpec(context: PluginContext): void {\n\t\tcontext.registerNodeSpec({\n\t\t\ttype: 'horizontal_rule',\n\t\t\tgroup: 'block',\n\t\t\tisVoid: true,\n\t\t\ttoDOM(node) {\n\t\t\t\treturn createBlockElement('hr', node.id);\n\t\t\t},\n\t\t\ttoHTML() {\n\t\t\t\treturn '<hr>';\n\t\t\t},\n\t\t\tparseHTML: [{ tag: 'hr' }],\n\t\t\tsanitize: { tags: ['hr'] },\n\t\t});\n\t}\n\n\tprivate registerCommands(context: PluginContext): void {\n\t\tcontext.registerCommand('insertHorizontalRule', () => {\n\t\t\treturn this.insertHorizontalRule(context);\n\t\t});\n\t}\n\n\tprivate registerKeymap(context: PluginContext): void {\n\t\tcontext.registerKeymap({\n\t\t\t'Mod-Shift-H': () => context.executeCommand('insertHorizontalRule'),\n\t\t});\n\t}\n\n\tprivate registerInputRule(context: PluginContext): void {\n\t\tcontext.registerInputRule({\n\t\t\tpattern: /^-{3,} $/,\n\t\t\thandler(state, _match, _start, end) {\n\t\t\t\tconst sel = state.selection;\n\t\t\t\tif (isNodeSelection(sel) || isGapCursor(sel)) return null;\n\t\t\t\tif (!isCollapsed(sel)) return null;\n\n\t\t\t\tconst block = state.getBlock(sel.anchor.blockId);\n\t\t\t\tif (!block || block.type !== 'paragraph') return null;\n\n\t\t\t\tconst blockIndex: number = findBlockIndexForCursor(state);\n\t\t\t\tif (blockIndex === -1) return null;\n\n\t\t\t\tconst newParagraph = createBlockNode(nodeType('paragraph'));\n\n\t\t\t\treturn state\n\t\t\t\t\t.transaction('input')\n\t\t\t\t\t.deleteTextAt(sel.anchor.blockId, 0, end)\n\t\t\t\t\t.setBlockType(sel.anchor.blockId, nodeType('horizontal_rule'))\n\t\t\t\t\t.insertNode([], blockIndex + 1, newParagraph)\n\t\t\t\t\t.setSelection(createCollapsedSelection(newParagraph.id, 0))\n\t\t\t\t\t.build();\n\t\t\t},\n\t\t});\n\t}\n\n\tprivate registerToolbarItem(context: PluginContext): void {\n\t\tconst icon =\n\t\t\t'<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 24 24\"><path d=\"M4 11h16v2H4z\"/></svg>';\n\n\t\tcontext.registerToolbarItem({\n\t\t\tid: 'horizontal-rule',\n\t\t\tgroup: 'block',\n\t\t\ticon,\n\t\t\tlabel: this.locale.label,\n\t\t\ttooltip: this.locale.tooltip(formatShortcut('Mod-Shift-H')),\n\t\t\tcommand: 'insertHorizontalRule',\n\t\t\tpriority: 60,\n\t\t\tseparatorAfter: this.config.separatorAfter,\n\t\t\tisActive: () => false,\n\t\t});\n\t}\n\n\t/**\n\t * Inserts a horizontal rule after the current block,\n\t * followed by a new paragraph for continued editing.\n\t */\n\tprivate insertHorizontalRule(context: PluginContext): boolean {\n\t\tconst state: EditorState = context.getState();\n\t\tif (isNodeSelection(state.selection) || isGapCursor(state.selection)) return false;\n\t\tconst blockIndex: number = findBlockIndexForCursor(state);\n\t\tif (blockIndex === -1) return false;\n\n\t\tconst hrBlock = createBlockNode(nodeType('horizontal_rule'));\n\t\tconst newParagraph = createBlockNode(nodeType('paragraph'));\n\n\t\tconst tr = state\n\t\t\t.transaction('command')\n\t\t\t.insertNode([], blockIndex + 1, hrBlock)\n\t\t\t.insertNode([], blockIndex + 2, newParagraph)\n\t\t\t.setSelection(createCollapsedSelection(newParagraph.id, 0))\n\t\t\t.build();\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n}\n"],"names":["HORIZONTAL_RULE_LOCALE_EN","label","tooltip","shortcut","HORIZONTAL_RULE_LOCALES","en","de","es","fr","zh","ru","ar","hi","DEFAULT_CONFIG","findBlockIndexForCursor","state","sel","selection","isNodeSelection","isGapCursor","doc","children","findIndex","b","id","anchor","blockId","HorizontalRulePlugin","name","priority","config","locale","this","context","resolvePluginLocale","registerNodeSpec","registerCommands","registerKeymap","registerInputRule","registerToolbarItem","type","group","isVoid","toDOM","node","createBlockElement","toHTML","parseHTML","tag","sanitize","tags","registerCommand","insertHorizontalRule","executeCommand","pattern","_match","_start","end","isCollapsed","block","getBlock","blockIndex","newParagraph","createBlockNode","nodeType","transaction","deleteTextAt","setBlockType","insertNode","setSelection","createCollapsedSelection","build","icon","formatShortcut","command","separatorAfter","isActive","getState","hrBlock","tr","dispatch"],"mappings":";;;;;;AAWO,MAAMA,IAAkD,EAC9DC,OAAO,mBACPC,SAAUC,CAAAA,OAAqB,oBAAoBA,SAsDvCC,IAAgE,EAC5EC,IAAIL,GACJM,IAnD8D,EAC9DL,OAAO,cACPC,SAAUC,CAAAA,OAAqB,eAAeA,SAkD9CI,IA7C8D,EAC9DN,OAAO,oBACPC,SAAUC,CAAAA,OAAqB,qBAAqBA,EAAAA,IAAAA,GA4CpDK,IAvC8D,EAC9DP,OAAO,qBACPC,SAAUC,CAAAA,OAAqB,sBAAsBA,SAsCrDM,IAjC8D,EAC9DR,OAAO,OACPC,SAAUC,CAAAA,OAAqB,QAAQA,EAAAA,IAAAA,GAgCvCO,IA3B8D,EAC9DT,OAAO,wBACPC,SAAUC,CAAAA,OAAqB,yBAAyBA,EAAAA,IAAAA,GA0BxDQ,IArB8D,EAC9DV,OAAO,WACPC,SAAUC,CAAAA,OAAqB,YAAYA,EAAAA,IAAAA,GAoB3CS,IAf8D,EAC9DX,OAAO,gBACPC,SAAUC,CAAAA,OAAqB,iBAAiBA,EAAAA,IAA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AAS,iBAAA,CAAA,GACnCF,KAAeC,EAAgBC,EAAS,WAAA,CAAA,GAExCe,KAAKhE,GACTkD,YAAY,SAAA,EACZG,WAAW,CAAA,GAAIP,KAAa,GAAGiB,EAAAA,EAC/BV,WAAW,IAAIP,KAAa,GAAGC,IAC/BO,aAAaC,EAAyBR,GAAatC,IAAI,CAAA,CAAA,EACvD+C;AAGF,WADAtC,GAAQ+C,SAASD,EAAAA,GAAAA;AAAAA,EAElB;AAAA;"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { C as e, r, i as a, a as t } from "./ColorPickerPopup-
|
|
1
|
+
import { C as e, r, i as a, a as t } from "./ColorPickerPopup-CiCLBbe9.mjs";
|
|
2
2
|
import { r as o } from "./resolvePluginLocale-B4w1OkPy.mjs";
|
|
3
3
|
import { e as l } from "./HTMLUtils-DTqQzcKR.mjs";
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { a as i } from "./StyleRuntime-ChRjVQwL.mjs";
|
|
5
|
+
import { r as s, i as f } from "./ColorValidation-CV4f1wu6.mjs";
|
|
6
|
+
const c = { label: "Highlight", tooltip: "Highlight Color", resetLabel: "None", ariaLabelPrefix: "Highlight color" }, g = { en: c, de: { label: "Hervorhebung", tooltip: "Hervorhebungsfarbe", resetLabel: "Keine", ariaLabelPrefix: "Hervorhebungsfarbe" }, es: { label: "Resaltado", tooltip: "Color de resaltado", resetLabel: "Ninguno", ariaLabelPrefix: "Color de resaltado" }, fr: { label: "Surlignage", tooltip: "Couleur de surlignage", resetLabel: "Aucun", ariaLabelPrefix: "Couleur de surlignage" }, zh: { label: "高亮", tooltip: "高亮颜色", resetLabel: "无", ariaLabelPrefix: "高亮颜色" }, ru: { label: "Выделение", tooltip: "Цвет выделения", resetLabel: "Нет", ariaLabelPrefix: "Цвет выделения" }, ar: { label: "تمييز", tooltip: "لون التمييز", resetLabel: "بدون", ariaLabelPrefix: "لون التمييز" }, hi: { label: "हाइलाइट", tooltip: "हाइलाइट रंग", resetLabel: "कोई नहीं", ariaLabelPrefix: "हाइलाइट रंग" } }, h = ["#fff176", "#aed581", "#4dd0e1", "#64b5f6", "#ce93d8", "#f48fb1", "#ffab91", "#ff8a65", "#e6ee9c", "#80cbc4", "#fff9c4", "#dcedc8", "#e0f7fa", "#e3f2fd", "#f3e5f5", "#fce4ec", "#fff3e0", "#fbe9e7", "#f9fbe7", "#e0f2f1", "#fff59d", "#c5e1a5", "#80deea", "#90caf9", "#e1bee7", "#f8bbd0", "#ffcc80", "#ffab91", "#e6ee9c", "#a5d6a7", "#ffee58", "#9ccc65", "#26c6da", "#42a5f5", "#ab47bc", "#ec407a", "#ffa726", "#ff7043", "#d4e157", "#66bb6a", "#ffffff", "#fafafa", "#f5f5f5", "#eeeeee", "#e0e0e0", "#bdbdbd", "#e8eaf6", "#efebe9", "#eceff1", "#fafafa"];
|
|
7
|
+
class b {
|
|
7
8
|
id = "highlight";
|
|
8
9
|
name = "Highlight";
|
|
9
10
|
priority = 24;
|
|
@@ -11,7 +12,7 @@ class h {
|
|
|
11
12
|
colors;
|
|
12
13
|
locale;
|
|
13
14
|
constructor(e2) {
|
|
14
|
-
this.config = { ...e2 }, this.colors =
|
|
15
|
+
this.config = { ...e2 }, this.colors = s(e2?.colors, h, "HighlightPlugin");
|
|
15
16
|
}
|
|
16
17
|
init(r2) {
|
|
17
18
|
this.locale = o(g, r2, this.config.locale), r2.registerStyleSheet(e), this.registerMarkSpec(r2), this.registerCommands(r2), this.registerToolbarItem(r2);
|
|
@@ -19,13 +20,16 @@ class h {
|
|
|
19
20
|
registerMarkSpec(e2) {
|
|
20
21
|
e2.registerMarkSpec({ type: "highlight", rank: 4, attrs: { color: { default: "" } }, toDOM(e3) {
|
|
21
22
|
const r2 = document.createElement("span"), a2 = e3.attrs?.color ?? "";
|
|
22
|
-
return r2
|
|
23
|
+
return i(r2, "backgroundColor", a2), r2;
|
|
23
24
|
}, toHTMLString: (e3, r2) => {
|
|
24
25
|
const a2 = String(e3.attrs?.color ?? "");
|
|
25
|
-
return a2 &&
|
|
26
|
+
return a2 && f(a2) ? `<span style="background-color: ${l(a2)}">${r2}</span>` : r2;
|
|
27
|
+
}, toHTMLStyle: (e3) => {
|
|
28
|
+
const r2 = String(e3.attrs?.color ?? "");
|
|
29
|
+
return r2 && f(r2) ? `background-color: ${l(r2)}` : null;
|
|
26
30
|
}, parseHTML: [{ tag: "span", getAttrs: (e3) => {
|
|
27
31
|
const r2 = e3.style.backgroundColor;
|
|
28
|
-
return !(!r2 || !
|
|
32
|
+
return !(!r2 || !f(r2)) && { color: r2 };
|
|
29
33
|
} }], sanitize: { tags: ["span"] } });
|
|
30
34
|
}
|
|
31
35
|
registerCommands(e2) {
|
|
@@ -39,8 +43,8 @@ class h {
|
|
|
39
43
|
}
|
|
40
44
|
}
|
|
41
45
|
export {
|
|
42
|
-
|
|
46
|
+
b as H,
|
|
43
47
|
g as a,
|
|
44
|
-
|
|
48
|
+
c as b
|
|
45
49
|
};
|
|
46
|
-
//# sourceMappingURL=index-
|
|
50
|
+
//# sourceMappingURL=index-D3NlpmT1.mjs.map
|