@notectl/core 1.7.2 → 1.7.3
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/dist/chunks/{ColorGrid-Dneqb8if.mjs → ColorGrid--lBQ7jCK.mjs} +2 -2
- package/dist/chunks/{ColorGrid-Dneqb8if.mjs.map → ColorGrid--lBQ7jCK.mjs.map} +1 -1
- package/dist/chunks/{ColorPickerPopup-CiCLBbe9.mjs → ColorPickerPopup-TpIRlXc8.mjs} +8 -8
- package/dist/chunks/ColorPickerPopup-TpIRlXc8.mjs.map +1 -0
- package/dist/chunks/Document-Brtw2jL1.mjs.map +1 -1
- package/dist/chunks/MarkCommands-6RUJ4L3r.mjs.map +1 -1
- package/dist/chunks/NodeSpec-NZVvcCuH.mjs.map +1 -1
- package/dist/chunks/PopupPositioning-CgjgAKjp.mjs +34 -0
- package/dist/chunks/PopupPositioning-CgjgAKjp.mjs.map +1 -0
- package/dist/chunks/{StyleRuntime-ChRjVQwL.mjs → StyleRuntime-CP4NCwKT.mjs} +49 -53
- package/dist/chunks/StyleRuntime-CP4NCwKT.mjs.map +1 -0
- package/dist/chunks/ToolbarItem-BpZggUGo.mjs.map +1 -1
- package/dist/chunks/{index-D515iymW.mjs → index--7pBhSF4.mjs} +5 -5
- package/dist/chunks/index--7pBhSF4.mjs.map +1 -0
- package/dist/chunks/index-BXCkjDax.mjs +161 -0
- package/dist/chunks/index-BXCkjDax.mjs.map +1 -0
- package/dist/chunks/{ToolbarPlugin-DpLVJ71w.mjs → index-BcDRT4K2.mjs} +81 -93
- package/dist/chunks/index-BcDRT4K2.mjs.map +1 -0
- package/dist/chunks/{index--n1RGpq-.mjs → index-BjFBWBOC.mjs} +46 -49
- package/dist/chunks/index-BjFBWBOC.mjs.map +1 -0
- package/dist/chunks/{index-BqNUfq-y.mjs → index-CCyqQ0Dz.mjs} +2 -2
- package/dist/chunks/{index-BqNUfq-y.mjs.map → index-CCyqQ0Dz.mjs.map} +1 -1
- package/dist/chunks/{index-DyzigvbZ.mjs → index-DSAuGP4n.mjs} +50 -50
- package/dist/chunks/index-DSAuGP4n.mjs.map +1 -0
- package/dist/chunks/{index-BhDXjueu.mjs → index-DtRfqsq5.mjs} +14 -14
- package/dist/chunks/{index-BhDXjueu.mjs.map → index-DtRfqsq5.mjs.map} +1 -1
- package/dist/chunks/{index-Dk49P9N4.mjs → index-Dum8yE_t.mjs} +11 -11
- package/dist/chunks/{index-Dk49P9N4.mjs.map → index-Dum8yE_t.mjs.map} +1 -1
- package/dist/chunks/{index-CluzpB2b.mjs → index-DxbQirny.mjs} +7 -7
- package/dist/chunks/{index-CluzpB2b.mjs.map → index-DxbQirny.mjs.map} +1 -1
- package/dist/chunks/{index-CWltg1wK.mjs → index-WpbK_s_H.mjs} +20 -25
- package/dist/chunks/index-WpbK_s_H.mjs.map +1 -0
- package/dist/chunks/{index-D3NlpmT1.mjs → index-WrqH1wG8.mjs} +3 -3
- package/dist/chunks/{index-D3NlpmT1.mjs.map → index-WrqH1wG8.mjs.map} +1 -1
- package/dist/chunks/{index-BvqkuEY1.mjs → index-fx3KIap3.mjs} +3 -3
- package/dist/chunks/{index-BvqkuEY1.mjs.map → index-fx3KIap3.mjs.map} +1 -1
- package/dist/chunks/{index-BAke7kNL.mjs → index-oOJo-ywB.mjs} +41 -41
- package/dist/chunks/{index-BAke7kNL.mjs.map → index-oOJo-ywB.mjs.map} +1 -1
- package/dist/chunks/{index-ABlTDvEX.mjs → index-toj88jtL.mjs} +2 -2
- package/dist/chunks/{index-ABlTDvEX.mjs.map → index-toj88jtL.mjs.map} +1 -1
- package/dist/commands/MarkCommands.d.ts +3 -3
- package/dist/commands/MarkCommands.d.ts.map +1 -1
- package/dist/editor/CSSClassCollector.d.ts +36 -0
- package/dist/editor/CSSClassCollector.d.ts.map +1 -0
- package/dist/editor/ContentHTMLTypes.d.ts +29 -0
- package/dist/editor/ContentHTMLTypes.d.ts.map +1 -0
- package/dist/editor/ContentStyleInjector.d.ts +69 -0
- package/dist/editor/ContentStyleInjector.d.ts.map +1 -0
- package/dist/editor/DocumentParser.d.ts +9 -1
- package/dist/editor/DocumentParser.d.ts.map +1 -1
- package/dist/editor/DocumentSerializer.d.ts +6 -0
- package/dist/editor/DocumentSerializer.d.ts.map +1 -1
- package/dist/editor/MarkSerializer.d.ts +7 -0
- package/dist/editor/MarkSerializer.d.ts.map +1 -1
- package/dist/editor/NotectlEditor.d.ts +8 -11
- package/dist/editor/NotectlEditor.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 +10 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/model/Document.d.ts +0 -4
- package/dist/model/Document.d.ts.map +1 -1
- package/dist/model/NodeSpec.d.ts +19 -2
- package/dist/model/NodeSpec.d.ts.map +1 -1
- package/dist/notectl-core.mjs +460 -336
- package/dist/notectl-core.mjs.map +1 -1
- package/dist/notectl-core.umd.js +676 -587
- package/dist/notectl-core.umd.js.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/CodeBlockPlugin.d.ts +0 -1
- package/dist/plugins/code-block/CodeBlockPlugin.d.ts.map +1 -1
- package/dist/plugins/code-block/index.d.ts +2 -1
- package/dist/plugins/code-block/index.d.ts.map +1 -1
- package/dist/plugins/code-block.mjs +1 -1
- package/dist/plugins/font/FontPlugin.d.ts +0 -1
- package/dist/plugins/font/FontPlugin.d.ts.map +1 -1
- package/dist/plugins/font-size/FontSizePlugin.d.ts +0 -2
- package/dist/plugins/font-size/FontSizePlugin.d.ts.map +1 -1
- package/dist/plugins/font-size/FontSizePopup.d.ts +3 -1
- package/dist/plugins/font-size/FontSizePopup.d.ts.map +1 -1
- package/dist/plugins/font-size.mjs +1 -1
- package/dist/plugins/font.mjs +1 -1
- package/dist/plugins/heading.mjs +1 -1
- package/dist/plugins/highlight.mjs +1 -1
- package/dist/plugins/horizontal-rule.mjs +1 -1
- package/dist/plugins/image/ImagePlugin.d.ts.map +1 -1
- package/dist/plugins/image.mjs +1 -1
- package/dist/plugins/list.mjs +1 -1
- package/dist/plugins/shared/ColorPickerPopup.d.ts +2 -1
- package/dist/plugins/shared/ColorPickerPopup.d.ts.map +1 -1
- package/dist/plugins/shared/PopupManager.d.ts +12 -2
- package/dist/plugins/shared/PopupManager.d.ts.map +1 -1
- package/dist/plugins/shared/PopupPositioning.d.ts.map +1 -1
- package/dist/plugins/table/TablePlugin.d.ts.map +1 -1
- package/dist/plugins/table.mjs +1 -1
- package/dist/plugins/text-color.mjs +1 -1
- package/dist/plugins/toolbar/ToolbarItem.d.ts +3 -2
- package/dist/plugins/toolbar/ToolbarItem.d.ts.map +1 -1
- package/dist/plugins/toolbar/ToolbarPopupController.d.ts +0 -3
- package/dist/plugins/toolbar/ToolbarPopupController.d.ts.map +1 -1
- package/dist/plugins/toolbar.mjs +2 -2
- package/dist/presets/PresetTypes.d.ts +1 -1
- package/dist/presets/PresetTypes.d.ts.map +1 -1
- package/dist/style/StyleRuntime.d.ts +3 -7
- package/dist/style/StyleRuntime.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/chunks/ColorPickerPopup-CiCLBbe9.mjs.map +0 -1
- package/dist/chunks/PopupPositioning-BTT-_pQ3.mjs +0 -32
- package/dist/chunks/PopupPositioning-BTT-_pQ3.mjs.map +0 -1
- package/dist/chunks/StyleRuntime-ChRjVQwL.mjs.map +0 -1
- package/dist/chunks/ToolbarPlugin-DpLVJ71w.mjs.map +0 -1
- package/dist/chunks/index--n1RGpq-.mjs.map +0 -1
- package/dist/chunks/index-4or5UzNO.mjs +0 -168
- package/dist/chunks/index-4or5UzNO.mjs.map +0 -1
- package/dist/chunks/index-CWltg1wK.mjs.map +0 -1
- package/dist/chunks/index-D515iymW.mjs.map +0 -1
- package/dist/chunks/index-DyzigvbZ.mjs.map +0 -1
|
@@ -2,8 +2,8 @@ import { r as t } from "./resolvePluginLocale-B4w1OkPy.mjs";
|
|
|
2
2
|
import { c as e } from "./NodeSpec-NZVvcCuH.mjs";
|
|
3
3
|
import { i as o, a as l, b as r } from "./Selection-BRTab5hO.mjs";
|
|
4
4
|
import { n as i } from "./TypeBrands-C09nE2qO.mjs";
|
|
5
|
-
import { f as
|
|
6
|
-
const
|
|
5
|
+
import { f as s } from "./ToolbarItem-BpZggUGo.mjs";
|
|
6
|
+
const c = { label: "Blockquote", tooltip: (t2) => `Blockquote (${t2})` }, a = { en: c, de: { label: "Zitat", tooltip: (t2) => `Zitat (${t2})` }, es: { label: "Cita", tooltip: (t2) => `Cita (${t2})` }, fr: { label: "Citation", tooltip: (t2) => `Citation (${t2})` }, zh: { label: "引用", tooltip: (t2) => `引用 (${t2})` }, ru: { label: "Цитата", tooltip: (t2) => `Цитата (${t2})` }, ar: { label: "اقتباس", tooltip: (t2) => `اقتباس (${t2})` }, hi: { label: "उद्धरण", tooltip: (t2) => `उद्धरण (${t2})` } }, n = {};
|
|
7
7
|
class p {
|
|
8
8
|
id = "blockquote";
|
|
9
9
|
name = "Blockquote";
|
|
@@ -26,16 +26,16 @@ class p {
|
|
|
26
26
|
t2.registerKeymap({ "Mod-Shift->": () => t2.executeCommand("toggleBlockquote") });
|
|
27
27
|
}
|
|
28
28
|
registerInputRule(t2) {
|
|
29
|
-
t2.registerInputRule({ pattern: /^> $/, handler(t3, e2,
|
|
29
|
+
t2.registerInputRule({ pattern: /^> $/, handler(t3, e2, s2, c2) {
|
|
30
30
|
const a2 = t3.selection;
|
|
31
31
|
if (o(a2) || l(a2)) return null;
|
|
32
32
|
if (!r(a2)) return null;
|
|
33
33
|
const n2 = t3.getBlock(a2.anchor.blockId);
|
|
34
|
-
return n2 && "paragraph" === n2.type ? t3.transaction("input").deleteTextAt(a2.anchor.blockId,
|
|
34
|
+
return n2 && "paragraph" === n2.type ? t3.transaction("input").deleteTextAt(a2.anchor.blockId, s2, s2 + 2).setBlockType(a2.anchor.blockId, i("blockquote")).setSelection(a2).build() : null;
|
|
35
35
|
} });
|
|
36
36
|
}
|
|
37
37
|
registerToolbarItem(t2) {
|
|
38
|
-
t2.registerToolbarItem({ id: "blockquote", group: "block", icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z"/></svg>', label: this.locale.label, tooltip: this.locale.tooltip(
|
|
38
|
+
t2.registerToolbarItem({ id: "blockquote", group: "block", icon: '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z"/></svg>', label: this.locale.label, tooltip: this.locale.tooltip(s("Mod-Shift->")), command: "toggleBlockquote", priority: 55, separatorAfter: this.config.separatorAfter, isActive: (t3) => {
|
|
39
39
|
if (o(t3.selection) || l(t3.selection)) return false;
|
|
40
40
|
const e2 = t3.getBlock(t3.selection.anchor.blockId);
|
|
41
41
|
return "blockquote" === e2?.type;
|
|
@@ -48,15 +48,15 @@ class p {
|
|
|
48
48
|
return !!r2 && ("blockquote" === r2.type ? this.setBlockType(t2, i("paragraph")) : this.setBlockType(t2, i("blockquote")));
|
|
49
49
|
}
|
|
50
50
|
setBlockType(t2, e2, r2) {
|
|
51
|
-
const i2 = t2.getState(),
|
|
52
|
-
if (o(
|
|
53
|
-
const
|
|
54
|
-
return t2.dispatch(
|
|
51
|
+
const i2 = t2.getState(), s2 = i2.selection;
|
|
52
|
+
if (o(s2) || l(s2)) return false;
|
|
53
|
+
const c2 = i2.transaction("command").setBlockType(s2.anchor.blockId, e2, r2).setSelection(s2).build();
|
|
54
|
+
return t2.dispatch(c2), true;
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
export {
|
|
58
58
|
p as B,
|
|
59
59
|
a,
|
|
60
|
-
|
|
60
|
+
c as b
|
|
61
61
|
};
|
|
62
|
-
//# sourceMappingURL=index-
|
|
62
|
+
//# sourceMappingURL=index-Dum8yE_t.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-Dk49P9N4.mjs","sources":["../../src/plugins/blockquote/BlockquoteLocale.ts","../../src/plugins/blockquote/BlockquotePlugin.ts"],"sourcesContent":["/**\n * Locale interface and default English locale for the BlockquotePlugin.\n */\n\n// --- Locale Interface ---\n\nexport interface BlockquoteLocale {\n\treadonly label: string;\n\treadonly tooltip: (shortcut: string) => string;\n}\n\n// --- Default English Locale ---\n\nexport const BLOCKQUOTE_LOCALE_EN: BlockquoteLocale = {\n\tlabel: 'Blockquote',\n\ttooltip: (shortcut: string) => `Blockquote (${shortcut})`,\n};\n\n// --- German Locale ---\n\nexport const BLOCKQUOTE_LOCALE_DE: BlockquoteLocale = {\n\tlabel: 'Zitat',\n\ttooltip: (shortcut: string) => `Zitat (${shortcut})`,\n};\n\n// --- Spanish Locale ---\n\nexport const BLOCKQUOTE_LOCALE_ES: BlockquoteLocale = {\n\tlabel: 'Cita',\n\ttooltip: (shortcut: string) => `Cita (${shortcut})`,\n};\n\n// --- French Locale ---\n\nexport const BLOCKQUOTE_LOCALE_FR: BlockquoteLocale = {\n\tlabel: 'Citation',\n\ttooltip: (shortcut: string) => `Citation (${shortcut})`,\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const BLOCKQUOTE_LOCALE_ZH: BlockquoteLocale = {\n\tlabel: '引用',\n\ttooltip: (shortcut: string) => `引用 (${shortcut})`,\n};\n\n// --- Russian Locale ---\n\nexport const BLOCKQUOTE_LOCALE_RU: BlockquoteLocale = {\n\tlabel: 'Цитата',\n\ttooltip: (shortcut: string) => `Цитата (${shortcut})`,\n};\n\n// --- Arabic Locale ---\n\nexport const BLOCKQUOTE_LOCALE_AR: BlockquoteLocale = {\n\tlabel: 'اقتباس',\n\ttooltip: (shortcut: string) => `اقتباس (${shortcut})`,\n};\n\n// --- Hindi Locale ---\n\nexport const BLOCKQUOTE_LOCALE_HI: BlockquoteLocale = {\n\tlabel: 'उद्धरण',\n\ttooltip: (shortcut: string) => `उद्धरण (${shortcut})`,\n};\n\n// --- Locale Map ---\n\nexport const BLOCKQUOTE_LOCALES: Record<string, BlockquoteLocale> = {\n\ten: BLOCKQUOTE_LOCALE_EN,\n\tde: BLOCKQUOTE_LOCALE_DE,\n\tes: BLOCKQUOTE_LOCALE_ES,\n\tfr: BLOCKQUOTE_LOCALE_FR,\n\tzh: BLOCKQUOTE_LOCALE_ZH,\n\tru: BLOCKQUOTE_LOCALE_RU,\n\tar: BLOCKQUOTE_LOCALE_AR,\n\thi: BLOCKQUOTE_LOCALE_HI,\n};\n","/**\n * BlockquotePlugin: registers a blockquote block type with NodeSpec,\n * toggle command, keyboard shortcut, input rule, and a toolbar button.\n */\n\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport { createBlockElement } from '../../model/NodeSpec.js';\nimport { isCollapsed, isGapCursor, isNodeSelection } from '../../model/Selection.js';\nimport { type NodeTypeName, nodeType } from '../../model/TypeBrands.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { formatShortcut } from '../toolbar/ToolbarItem.js';\nimport { BLOCKQUOTE_LOCALES, type BlockquoteLocale } from './BlockquoteLocale.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface NodeAttrRegistry {\n\t\tblockquote: Record<string, never>;\n\t}\n}\n\n// --- Configuration ---\n\nexport interface BlockquoteConfig {\n\t/** When true, a separator is rendered after the blockquote toolbar item. */\n\treadonly separatorAfter?: boolean;\n\treadonly locale?: BlockquoteLocale;\n}\n\nconst DEFAULT_CONFIG: BlockquoteConfig = {};\n\n// --- Plugin ---\n\nexport class BlockquotePlugin implements Plugin {\n\treadonly id = 'blockquote';\n\treadonly name = 'Blockquote';\n\treadonly priority = 35;\n\n\tprivate readonly config: BlockquoteConfig;\n\tprivate locale!: BlockquoteLocale;\n\n\tconstructor(config?: Partial<BlockquoteConfig>) {\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(BLOCKQUOTE_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: 'blockquote',\n\t\t\tgroup: 'block',\n\t\t\tcontent: { allow: ['text'] },\n\t\t\ttoDOM(node) {\n\t\t\t\treturn createBlockElement('blockquote', node.id);\n\t\t\t},\n\t\t\ttoHTML(_node, content) {\n\t\t\t\treturn `<blockquote>${content || '<br>'}</blockquote>`;\n\t\t\t},\n\t\t\tparseHTML: [{ tag: 'blockquote' }],\n\t\t\tsanitize: { tags: ['blockquote'] },\n\t\t});\n\t}\n\n\tprivate registerCommands(context: PluginContext): void {\n\t\tcontext.registerCommand('toggleBlockquote', () => {\n\t\t\treturn this.toggleBlockquote(context);\n\t\t});\n\n\t\tcontext.registerCommand('setBlockquote', () => {\n\t\t\treturn this.setBlockType(context, nodeType('blockquote'));\n\t\t});\n\t}\n\n\tprivate registerKeymap(context: PluginContext): void {\n\t\tcontext.registerKeymap({\n\t\t\t'Mod-Shift->': () => context.executeCommand('toggleBlockquote'),\n\t\t});\n\t}\n\n\tprivate registerInputRule(context: PluginContext): void {\n\t\tcontext.registerInputRule({\n\t\t\tpattern: /^> $/,\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\treturn state\n\t\t\t\t\t.transaction('input')\n\t\t\t\t\t.deleteTextAt(sel.anchor.blockId, start, start + 2)\n\t\t\t\t\t.setBlockType(sel.anchor.blockId, nodeType('blockquote'))\n\t\t\t\t\t.setSelection(sel)\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=\"M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z\"/></svg>';\n\n\t\tcontext.registerToolbarItem({\n\t\t\tid: 'blockquote',\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->')),\n\t\t\tcommand: 'toggleBlockquote',\n\t\t\tpriority: 55,\n\t\t\tseparatorAfter: this.config.separatorAfter,\n\t\t\tisActive: (state) => {\n\t\t\t\tif (isNodeSelection(state.selection) || isGapCursor(state.selection)) return false;\n\t\t\t\tconst block = state.getBlock(state.selection.anchor.blockId);\n\t\t\t\treturn block?.type === 'blockquote';\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Toggles between blockquote and paragraph.\n\t * If the block is already a blockquote, resets to paragraph.\n\t */\n\tprivate toggleBlockquote(context: PluginContext): boolean {\n\t\tconst state = context.getState();\n\t\tif (isNodeSelection(state.selection) || isGapCursor(state.selection)) return false;\n\t\tconst block = state.getBlock(state.selection.anchor.blockId);\n\t\tif (!block) return false;\n\n\t\tif (block.type === 'blockquote') {\n\t\t\treturn this.setBlockType(context, nodeType('paragraph'));\n\t\t}\n\n\t\treturn this.setBlockType(context, nodeType('blockquote'));\n\t}\n\n\tprivate setBlockType(\n\t\tcontext: PluginContext,\n\t\ttype: NodeTypeName,\n\t\tattrs?: Record<string, string | number | boolean>,\n\t): boolean {\n\t\tconst state = context.getState();\n\t\tconst sel = state.selection;\n\t\tif (isNodeSelection(sel) || isGapCursor(sel)) return false;\n\n\t\tconst tr = state\n\t\t\t.transaction('command')\n\t\t\t.setBlockType(sel.anchor.blockId, type, attrs)\n\t\t\t.setSelection(sel)\n\t\t\t.build();\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n}\n"],"names":["BLOCKQUOTE_LOCALE_EN","label","tooltip","shortcut","BLOCKQUOTE_LOCALES","en","de","es","fr","zh","ru","ar","hi","DEFAULT_CONFIG","BlockquotePlugin","id","name","priority","config","locale","this","context","resolvePluginLocale","registerNodeSpec","registerCommands","registerKeymap","registerInputRule","registerToolbarItem","type","group","content","allow","toDOM","node","createBlockElement","toHTML","_node","parseHTML","tag","sanitize","tags","registerCommand","toggleBlockquote","setBlockType","nodeType","executeCommand","pattern","state","_match","start","_end","sel","selection","isNodeSelection","isGapCursor","isCollapsed","block","getBlock","anchor","blockId","transaction","deleteTextAt","setSelection","build","icon","formatShortcut","command","separatorAfter","isActive","getState","attrs","tr","dispatch"],"mappings":";;;;;AAaO,MAAMA,IAAyC,EACrDC,OAAO,cACPC,SAAUC,CAAAA,OAAqB,eAAeA,EAAAA,IAAAA,GAsDlCC,IAAuD,EACnEC,IAAIL,GACJM,IAnDqD,EACrDL,OAAO,SACPC,SAAUC,CAAAA,OAAqB,UAAUA,EAAAA,IAAAA,GAkDzCI,IA7CqD,EACrDN,OAAO,QACPC,SAAUC,CAAAA,OAAqB,SAASA,EAAAA,IAAAA,GA4CxCK,IAvCqD,EACrDP,OAAO,YACPC,SAAUC,CAAAA,OAAqB,aAAaA,EAAAA,IAAAA,GAsC5CM,IAjCqD,EACrDR,OAAO,MACPC,SAAUC,CAAAA,OAAqB,OAAOA,EAAAA,IAAAA,GAgCtCO,IA3Bq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A,EAAY,QAAA;AACtE,UAAMI,KAAQT,GAAMU,SAASV,GAAMK,UAAUM,OAAOC,OAAAA;AACpD,aAAKH,OAEc,iBAAfA,GAAM5B,OACFR,KAAKuB,aAAatB,IAASuB,EAAS,WAAA,CAAA,IAGrCxB,KAAKuB,aAAatB,IAASuB,EAAS,YAAA,CAAA;AAAA,EAC5C;AAAA,EAEQ,aACPvB,IACAO,IACA0C,IAAAA;AAEA,UAAMvB,KAAQ1B,GAAQgD,SAAAA,GAChBlB,KAAMJ,GAAMK;AAClB,QAAIC,EAAgBF,EAAAA,KAAQG,EAAYH,IAAM,QAAA;AAE9C,UAAMoB,KAAKxB,GACTa,YAAY,SAAA,EACZjB,aAAaQ,GAAIO,OAAOC,SAAS/B,IAAM0C,IACvCR,aAAaX,EAAAA,EACbY;AAGF,WADA1C,GAAQmD,SAASD,EAAAA,GAAAA;AAAAA,EAElB;AAAA;"}
|
|
1
|
+
{"version":3,"file":"index-Dum8yE_t.mjs","sources":["../../src/plugins/blockquote/BlockquoteLocale.ts","../../src/plugins/blockquote/BlockquotePlugin.ts"],"sourcesContent":["/**\n * Locale interface and default English locale for the BlockquotePlugin.\n */\n\n// --- Locale Interface ---\n\nexport interface BlockquoteLocale {\n\treadonly label: string;\n\treadonly tooltip: (shortcut: string) => string;\n}\n\n// --- Default English Locale ---\n\nexport const BLOCKQUOTE_LOCALE_EN: BlockquoteLocale = {\n\tlabel: 'Blockquote',\n\ttooltip: (shortcut: string) => `Blockquote (${shortcut})`,\n};\n\n// --- German Locale ---\n\nexport const BLOCKQUOTE_LOCALE_DE: BlockquoteLocale = {\n\tlabel: 'Zitat',\n\ttooltip: (shortcut: string) => `Zitat (${shortcut})`,\n};\n\n// --- Spanish Locale ---\n\nexport const BLOCKQUOTE_LOCALE_ES: BlockquoteLocale = {\n\tlabel: 'Cita',\n\ttooltip: (shortcut: string) => `Cita (${shortcut})`,\n};\n\n// --- French Locale ---\n\nexport const BLOCKQUOTE_LOCALE_FR: BlockquoteLocale = {\n\tlabel: 'Citation',\n\ttooltip: (shortcut: string) => `Citation (${shortcut})`,\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const BLOCKQUOTE_LOCALE_ZH: BlockquoteLocale = {\n\tlabel: '引用',\n\ttooltip: (shortcut: string) => `引用 (${shortcut})`,\n};\n\n// --- Russian Locale ---\n\nexport const BLOCKQUOTE_LOCALE_RU: BlockquoteLocale = {\n\tlabel: 'Цитата',\n\ttooltip: (shortcut: string) => `Цитата (${shortcut})`,\n};\n\n// --- Arabic Locale ---\n\nexport const BLOCKQUOTE_LOCALE_AR: BlockquoteLocale = {\n\tlabel: 'اقتباس',\n\ttooltip: (shortcut: string) => `اقتباس (${shortcut})`,\n};\n\n// --- Hindi Locale ---\n\nexport const BLOCKQUOTE_LOCALE_HI: BlockquoteLocale = {\n\tlabel: 'उद्धरण',\n\ttooltip: (shortcut: string) => `उद्धरण (${shortcut})`,\n};\n\n// --- Locale Map ---\n\nexport const BLOCKQUOTE_LOCALES: Record<string, BlockquoteLocale> = {\n\ten: BLOCKQUOTE_LOCALE_EN,\n\tde: BLOCKQUOTE_LOCALE_DE,\n\tes: BLOCKQUOTE_LOCALE_ES,\n\tfr: BLOCKQUOTE_LOCALE_FR,\n\tzh: BLOCKQUOTE_LOCALE_ZH,\n\tru: BLOCKQUOTE_LOCALE_RU,\n\tar: BLOCKQUOTE_LOCALE_AR,\n\thi: BLOCKQUOTE_LOCALE_HI,\n};\n","/**\n * BlockquotePlugin: registers a blockquote block type with NodeSpec,\n * toggle command, keyboard shortcut, input rule, and a toolbar button.\n */\n\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport { createBlockElement } from '../../model/NodeSpec.js';\nimport { isCollapsed, isGapCursor, isNodeSelection } from '../../model/Selection.js';\nimport { type NodeTypeName, nodeType } from '../../model/TypeBrands.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { formatShortcut } from '../toolbar/ToolbarItem.js';\nimport { BLOCKQUOTE_LOCALES, type BlockquoteLocale } from './BlockquoteLocale.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface NodeAttrRegistry {\n\t\tblockquote: Record<string, never>;\n\t}\n}\n\n// --- Configuration ---\n\nexport interface BlockquoteConfig {\n\t/** When true, a separator is rendered after the blockquote toolbar item. */\n\treadonly separatorAfter?: boolean;\n\treadonly locale?: BlockquoteLocale;\n}\n\nconst DEFAULT_CONFIG: BlockquoteConfig = {};\n\n// --- Plugin ---\n\nexport class BlockquotePlugin implements Plugin {\n\treadonly id = 'blockquote';\n\treadonly name = 'Blockquote';\n\treadonly priority = 35;\n\n\tprivate readonly config: BlockquoteConfig;\n\tprivate locale!: BlockquoteLocale;\n\n\tconstructor(config?: Partial<BlockquoteConfig>) {\n\t\tthis.config = { ...DEFAULT_CONFIG, ...config };\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(BLOCKQUOTE_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: 'blockquote',\n\t\t\tgroup: 'block',\n\t\t\tcontent: { allow: ['text'] },\n\t\t\ttoDOM(node) {\n\t\t\t\treturn createBlockElement('blockquote', node.id);\n\t\t\t},\n\t\t\ttoHTML(_node, content) {\n\t\t\t\treturn `<blockquote>${content || '<br>'}</blockquote>`;\n\t\t\t},\n\t\t\tparseHTML: [{ tag: 'blockquote' }],\n\t\t\tsanitize: { tags: ['blockquote'] },\n\t\t});\n\t}\n\n\tprivate registerCommands(context: PluginContext): void {\n\t\tcontext.registerCommand('toggleBlockquote', () => {\n\t\t\treturn this.toggleBlockquote(context);\n\t\t});\n\n\t\tcontext.registerCommand('setBlockquote', () => {\n\t\t\treturn this.setBlockType(context, nodeType('blockquote'));\n\t\t});\n\t}\n\n\tprivate registerKeymap(context: PluginContext): void {\n\t\tcontext.registerKeymap({\n\t\t\t'Mod-Shift->': () => context.executeCommand('toggleBlockquote'),\n\t\t});\n\t}\n\n\tprivate registerInputRule(context: PluginContext): void {\n\t\tcontext.registerInputRule({\n\t\t\tpattern: /^> $/,\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\treturn state\n\t\t\t\t\t.transaction('input')\n\t\t\t\t\t.deleteTextAt(sel.anchor.blockId, start, start + 2)\n\t\t\t\t\t.setBlockType(sel.anchor.blockId, nodeType('blockquote'))\n\t\t\t\t\t.setSelection(sel)\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=\"M6 17h3l2-4V7H5v6h3zm8 0h3l2-4V7h-6v6h3z\"/></svg>';\n\n\t\tcontext.registerToolbarItem({\n\t\t\tid: 'blockquote',\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->')),\n\t\t\tcommand: 'toggleBlockquote',\n\t\t\tpriority: 55,\n\t\t\tseparatorAfter: this.config.separatorAfter,\n\t\t\tisActive: (state) => {\n\t\t\t\tif (isNodeSelection(state.selection) || isGapCursor(state.selection)) return false;\n\t\t\t\tconst block = state.getBlock(state.selection.anchor.blockId);\n\t\t\t\treturn block?.type === 'blockquote';\n\t\t\t},\n\t\t});\n\t}\n\n\t/**\n\t * Toggles between blockquote and paragraph.\n\t * If the block is already a blockquote, resets to paragraph.\n\t */\n\tprivate toggleBlockquote(context: PluginContext): boolean {\n\t\tconst state = context.getState();\n\t\tif (isNodeSelection(state.selection) || isGapCursor(state.selection)) return false;\n\t\tconst block = state.getBlock(state.selection.anchor.blockId);\n\t\tif (!block) return false;\n\n\t\tif (block.type === 'blockquote') {\n\t\t\treturn this.setBlockType(context, nodeType('paragraph'));\n\t\t}\n\n\t\treturn this.setBlockType(context, nodeType('blockquote'));\n\t}\n\n\tprivate setBlockType(\n\t\tcontext: PluginContext,\n\t\ttype: NodeTypeName,\n\t\tattrs?: Record<string, string | number | boolean>,\n\t): boolean {\n\t\tconst state = context.getState();\n\t\tconst sel = state.selection;\n\t\tif (isNodeSelection(sel) || isGapCursor(sel)) return false;\n\n\t\tconst tr = state\n\t\t\t.transaction('command')\n\t\t\t.setBlockType(sel.anchor.blockId, type, attrs)\n\t\t\t.setSelection(sel)\n\t\t\t.build();\n\n\t\tcontext.dispatch(tr);\n\t\treturn true;\n\t}\n}\n"],"names":["BLOCKQUOTE_LOCALE_EN","label","tooltip","shortcut","BLOCKQUOTE_LOCALES","en","de","es","fr","zh","ru","ar","hi","DEFAULT_CONFIG","BlockquotePlugin","id","name","priority","config","locale","this","context","resolvePluginLocale","registerNodeSpec","registerCommands","registerKeymap","registerInputRule","registerToolbarItem","type","group","content","allow","toDOM","node","createBlockElement","toHTML","_node","parseHTML","tag","sanitize","tags","registerCommand","toggleBlockquote","setBlockType","nodeType","executeCommand","pattern","state","_match","start","_end","sel","selection","isNodeSelection","isGapCursor","isCollapsed","block","getBlock","anchor","blockId","transaction","deleteTextAt","setSelection","build","icon","formatShortcut","command","separatorAfter","isActive","getState","attrs","tr","dispatch"],"mappings":";;;;;AAaO,MAAMA,IAAyC,EACrDC,OAAO,cACPC,SAAUC,CAAAA,OAAqB,eAAeA,EAAAA,IAAAA,GAsDlCC,IAAuD,EACnEC,IAAIL,GACJM,IAnDqD,EACrDL,OAAO,SACPC,SAAU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AcE,EAAYP,GAAMK,WAAY,QAAA;AACtE,YAAMI,KAAQT,GAAMU,SAASV,GAAMK,UAAUM,OAAOC,OAAAA;AACpD,aAAuB,iBAAhBH,IAAO5B;AAAAA,IAAAA,EAAAA,CAAAA;AAAAA,EAGjB;AAAA,EAMQ,iBAAiBP,IAAAA;AACxB,UAAM0B,KAAQ1B,GAAQgD;AACtB,QAAIhB,EAAgBN,GAAMK,SAAAA,KAAcE,EAAYP,GAAMK,SAAAA,EAAY,QAAA;AACtE,UAAMI,KAAQT,GAAMU,SAASV,GAAMK,UAAUM,OAAOC,OAAAA;AACpD,aAAKH,OAEc,iBAAfA,GAAM5B,OACFR,KAAKuB,aAAatB,IAASuB,EAAS,WAAA,CAAA,IAGrCxB,KAAKuB,aAAatB,IAASuB,EAAS,YAAA,CAAA;AAAA,EAC5C;AAAA,EAEQ,aACPvB,IACAO,IACA0C,IAAAA;AAEA,UAAMvB,KAAQ1B,GAAQgD,SAAAA,GAChBlB,KAAMJ,GAAMK;AAClB,QAAIC,EAAgBF,EAAAA,KAAQG,EAAYH,IAAM,QAAA;AAE9C,UAAMoB,KAAKxB,GACTa,YAAY,SAAA,EACZjB,aAAaQ,GAAIO,OAAOC,SAAS/B,IAAM0C,IACvCR,aAAaX,EAAAA,EACbY;AAGF,WADA1C,GAAQmD,SAASD,EAAAA,GAAAA;AAAAA,EAElB;AAAA;"}
|
|
@@ -9,7 +9,7 @@ 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
|
}
|
|
12
|
-
class
|
|
12
|
+
class d {
|
|
13
13
|
id = "horizontal-rule";
|
|
14
14
|
name = "Horizontal Rule";
|
|
15
15
|
priority = 40;
|
|
@@ -37,10 +37,10 @@ class m {
|
|
|
37
37
|
if (!l(p2)) return null;
|
|
38
38
|
const u2 = e3.getBlock(p2.anchor.blockId);
|
|
39
39
|
if (!u2 || "paragraph" !== u2.type) return null;
|
|
40
|
-
const
|
|
41
|
-
if (-1 ===
|
|
42
|
-
const
|
|
43
|
-
return e3.transaction("input").deleteTextAt(p2.anchor.blockId, 0, c2).setBlockType(p2.anchor.blockId, a("horizontal_rule")).insertNode([],
|
|
40
|
+
const d2 = h(e3);
|
|
41
|
+
if (-1 === d2) return null;
|
|
42
|
+
const m = t(a("paragraph"));
|
|
43
|
+
return e3.transaction("input").deleteTextAt(p2.anchor.blockId, 0, c2).setBlockType(p2.anchor.blockId, a("horizontal_rule")).insertNode([], d2 + 1, m).setSelection(n(m.id, 0)).build();
|
|
44
44
|
} });
|
|
45
45
|
}
|
|
46
46
|
registerToolbarItem(e2) {
|
|
@@ -56,8 +56,8 @@ class m {
|
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
58
|
export {
|
|
59
|
-
|
|
59
|
+
d as H,
|
|
60
60
|
p as a,
|
|
61
61
|
c as b
|
|
62
62
|
};
|
|
63
|
-
//# sourceMappingURL=index-
|
|
63
|
+
//# sourceMappingURL=index-DxbQirny.mjs.map
|
|
@@ -1 +1 @@
|
|
|
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,IAAAA,EAAAA,GCzB3CU,IAAuC,CAAA;AAK7C,SAASC,EAAwBC,IAAAA;AAChC,QAAMC,KAAMD,GAAME;AAClB,SAAIC,EAAgBF,EAAAA,KAAQG,EAAYH,WACjCD,GAAMK,IAAIC,SAASC,UAAWC,CAAAA,OAAMA,GAAEC,OAAOR,GAAIS,OAAOC,OAAAA;AAChE;AAIO,MAAMC,EAAAA;AAAAA,EACHH,KAAK;AAAA,EACLI,OAAO;AAAA,EAC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AAAA;"}
|
|
1
|
+
{"version":3,"file":"index-DxbQirny.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,EAA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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;"}
|
|
@@ -2,11 +2,10 @@ import { i as t, g as e, a as n, r as o } from "./AttributedMarkCommands-BtLea72
|
|
|
2
2
|
import { r as i } from "./resolvePluginLocale-B4w1OkPy.mjs";
|
|
3
3
|
import { e as r } from "./HTMLUtils-DTqQzcKR.mjs";
|
|
4
4
|
import { m as a } from "./TypeBrands-C09nE2qO.mjs";
|
|
5
|
-
import { a as
|
|
5
|
+
import { a as l, g as s } from "./StyleRuntime-CP4NCwKT.mjs";
|
|
6
6
|
import { b as c } from "./ColorValidation-CV4f1wu6.mjs";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class d {
|
|
7
|
+
const f = { label: "Font", tooltip: "Font Family" }, m = { en: f, 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: "फ़ॉन्ट परिवार" } };
|
|
8
|
+
class p {
|
|
10
9
|
id = "font";
|
|
11
10
|
name = "Font";
|
|
12
11
|
priority = 22;
|
|
@@ -18,7 +17,7 @@ class d {
|
|
|
18
17
|
this.config = t2;
|
|
19
18
|
}
|
|
20
19
|
init(t2) {
|
|
21
|
-
this.locale = i(
|
|
20
|
+
this.locale = i(m, 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@media (hover: hover) {\n .notectl-font-picker__item:hover {\n background: var(--notectl-hover-bg);\n }\n}\n\n.notectl-font-picker__item--active {\n background: var(--notectl-active-bg);\n color: var(--notectl-primary-fg);\n}\n\n@media (hover: hover) {\n .notectl-font-picker__item--active:hover {\n background: var(--notectl-active-bg);\n }\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
21
|
}
|
|
23
22
|
destroy() {
|
|
24
23
|
this.injectedStyleElement?.remove(), this.injectedStyleElement = null, this.context = null;
|
|
@@ -26,7 +25,7 @@ class d {
|
|
|
26
25
|
registerMarkSpec(t2) {
|
|
27
26
|
t2.registerMarkSpec({ type: "font", rank: 6, attrs: { family: { default: "" } }, toDOM(t3) {
|
|
28
27
|
const e2 = document.createElement("span"), n2 = t3.attrs?.family ?? "";
|
|
29
|
-
return n2 &&
|
|
28
|
+
return n2 && l(e2, "fontFamily", n2), e2;
|
|
30
29
|
}, toHTMLString: (t3, e2) => {
|
|
31
30
|
const n2 = String(t3.attrs?.family ?? "");
|
|
32
31
|
return n2 && c(n2) ? `<span style="font-family: ${r(n2)}">${e2}</span>` : e2;
|
|
@@ -54,8 +53,8 @@ class d {
|
|
|
54
53
|
return t2;
|
|
55
54
|
}
|
|
56
55
|
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);
|
|
56
|
+
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, n2) => {
|
|
57
|
+
this.renderFontPopup(t3, e2, n2);
|
|
59
58
|
}, isActive: (t3) => this.isFontActive(t3) });
|
|
60
59
|
}
|
|
61
60
|
resolveFontName(t2) {
|
|
@@ -88,24 +87,20 @@ class d {
|
|
|
88
87
|
if (0 === t2.length) return;
|
|
89
88
|
const e2 = document.createElement("style");
|
|
90
89
|
e2.setAttribute("data-notectl-fonts", "");
|
|
91
|
-
const n2 = this.context ?
|
|
90
|
+
const n2 = this.context ? s(this.context.getContainer()) : void 0;
|
|
92
91
|
n2 && e2.setAttribute("nonce", n2), e2.textContent = t2.join("\n\n"), document.head.appendChild(e2), this.injectedStyleElement = e2;
|
|
93
92
|
}
|
|
94
|
-
|
|
95
|
-
const t2 = this.context?.getService(p);
|
|
96
|
-
t2?.closePopup();
|
|
97
|
-
}
|
|
98
|
-
renderFontPopup(t2, e2) {
|
|
93
|
+
renderFontPopup(t2, e2, n2) {
|
|
99
94
|
t2.classList.add("notectl-font-picker");
|
|
100
|
-
const
|
|
101
|
-
|
|
95
|
+
const o2 = e2.getState(), i2 = this.getActiveFont(o2), r2 = this.defaultFont.family, a2 = e2.getContainer(), l2 = document.createElement("div");
|
|
96
|
+
l2.className = "notectl-font-picker__list", l2.setAttribute("role", "listbox"), l2.setAttribute("aria-label", this.locale.label);
|
|
102
97
|
for (const t3 of this.config.fonts) {
|
|
103
|
-
const
|
|
104
|
-
|
|
98
|
+
const o3 = t3.family === r2, s2 = o3 && !i2 || i2 === t3.family, c2 = this.createFontItem(t3.name, t3.family, s2, (i3) => {
|
|
99
|
+
i3.preventDefault(), i3.stopPropagation(), o3 ? e2.executeCommand("removeFont") : this.applyFont(e2, e2.getState(), t3.family), n2({ restoreFocusTo: a2 });
|
|
105
100
|
});
|
|
106
|
-
t3.category &&
|
|
101
|
+
t3.category && c2.setAttribute("data-category", t3.category), l2.appendChild(c2);
|
|
107
102
|
}
|
|
108
|
-
t2.appendChild(
|
|
103
|
+
t2.appendChild(l2);
|
|
109
104
|
}
|
|
110
105
|
createFontItem(t2, e2, n2, o2) {
|
|
111
106
|
const i2 = document.createElement("button");
|
|
@@ -113,12 +108,12 @@ class d {
|
|
|
113
108
|
const r2 = document.createElement("span");
|
|
114
109
|
r2.className = "notectl-font-picker__check", r2.textContent = n2 ? "✓" : "", i2.appendChild(r2);
|
|
115
110
|
const a2 = document.createElement("span");
|
|
116
|
-
return a2.className = "notectl-font-picker__label", a2.textContent = t2, e2 &&
|
|
111
|
+
return a2.className = "notectl-font-picker__label", a2.textContent = t2, e2 && l(a2, "fontFamily", e2), i2.appendChild(a2), i2.addEventListener("mousedown", o2), i2;
|
|
117
112
|
}
|
|
118
113
|
}
|
|
119
114
|
export {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
115
|
+
p as F,
|
|
116
|
+
m as a,
|
|
117
|
+
f as b
|
|
123
118
|
};
|
|
124
|
-
//# sourceMappingURL=index-
|
|
119
|
+
//# sourceMappingURL=index-WpbK_s_H.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-WpbK_s_H.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@media (hover: hover) {\n\t.notectl-font-picker__item:hover {\n\t\tbackground: var(--notectl-hover-bg);\n\t}\n}\n\n.notectl-font-picker__item--active {\n\tbackground: var(--notectl-active-bg);\n\tcolor: var(--notectl-primary-fg);\n}\n\n@media (hover: hover) {\n\t.notectl-font-picker__item--active:hover {\n\t\tbackground: var(--notectl-active-bg);\n\t}\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 type { PopupCloseOptions } from '../shared/PopupManager.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, onClose) => {\n\t\t\t\tthis.renderFontPopup(container, ctx, onClose);\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 renderFontPopup(\n\t\tcontainer: HTMLElement,\n\t\tcontext: PluginContext,\n\t\tonClose: (options?: PopupCloseOptions) => void,\n\t): 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\t\tconst contentElement: HTMLElement = context.getContainer();\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\tonClose({ restoreFocusTo: contentElement });\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","destroy","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","onClose","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","classList","add","activeFont","defaultFamily","contentElement","list","className","isDefault","item","createFontItem","e","preventDefault","stopPropagation","executeCommand","applyFont","restoreFocusTo","category","handler","check","addEventListener"],"mappings":";;;;;;AACO,MCUMA,IAA6B,EACzCC,OAAO,QACPC,SAAS,cAAA,GAsDGC,IAA2C,EACvDC,IAAIJ,GACJK,IAnDyC,EACzCJ,OAAO,cACPC,SAAS,iBAAA,GAkDTI,IA7CyC,EACzCL,OAAO,UACPC,SAAS,oBAAA,GA4CTK,IAvCyC,EACzCN,OAAO,UACPC,SAAS,oBAAA,GAsCTM,IAjCyC,EACzCP,OAAO,MACPC,SAAS,OAAA,GAgCTO,IA3ByC,EACzCR,OAAO,SACPC,SAAS,uBA0BTQ,IArByC,EACzCT,OAAO,QACPC,SAAS,gBAoBTS,IAfyC,EACzCV,OAAO,UACPC,SAAS,gBAAA,EAAA;ACwBH,MAAMU;EACHC,KAAK;AAAA,EACLC,OAAO;AAAA,EACPC,WAAW;AAAA,EAEHC;AAAAA,EACTC;AAAAA,EACAC,uBAAgD;AAAA,EAChDC,UAAgC;AAAA,EAExC,YAAYH;AACXI,SAAKJ,SAASA;AAAAA,EACf;AAAA,EAEA,KAAKG,IAAAA;AACJC,SAAKH,SAASI,EAAo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+E,IAAAA,GAAKvF,OAAO,UACZuF,GAAKF,YAAY,6BACjBE,GAAKf,aAAa,QAAQ,QAAA,GAC1Be,GAAKf,aAAa,iBAAiB5D,OAAOmC,MAEtCA,MACHwC,GAAKR,UAAUC,IAAI,mCAAA;AAIpB,UAAMiB,KAAyB1F,SAASC,cAAc,MAAA;AACtDyF,IAAAA,GAAMZ,YAAY,8BAClBY,GAAMrB,cAAc7B,KAAW,MAAW,IAC1CwC,GAAKT,YAAYmB,EAAAA;AAGjB,UAAM7H,KAAyBmC,SAASC,cAAc,MAAA;AAStD,WARApC,GAAMiH,YAAY,8BAClBjH,GAAMwG,cAAc3F,IAChBkB,MACHM,EAAiBrC,IAAO,cAAc+B,EAAAA,GAEvCoF,GAAKT,YAAY1G,EAAAA,GAEjBmH,GAAKW,iBAAiB,aAAaF,KAC5BT;AAAAA,EACR;AAAA;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
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-TpIRlXc8.mjs";
|
|
2
2
|
import { r as o } from "./resolvePluginLocale-B4w1OkPy.mjs";
|
|
3
3
|
import { e as l } from "./HTMLUtils-DTqQzcKR.mjs";
|
|
4
|
-
import { a as i } from "./StyleRuntime-
|
|
4
|
+
import { a as i } from "./StyleRuntime-CP4NCwKT.mjs";
|
|
5
5
|
import { r as s, i as f } from "./ColorValidation-CV4f1wu6.mjs";
|
|
6
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
7
|
class b {
|
|
@@ -47,4 +47,4 @@ export {
|
|
|
47
47
|
g as a,
|
|
48
48
|
c as b
|
|
49
49
|
};
|
|
50
|
-
//# sourceMappingURL=index-
|
|
50
|
+
//# sourceMappingURL=index-WrqH1wG8.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-D3NlpmT1.mjs","sources":["../../src/plugins/highlight/HighlightLocale.ts","../../src/plugins/highlight/HighlightPlugin.ts"],"sourcesContent":["/** Locale interface and default English locale for the HighlightPlugin. */\n\n// --- Locale Interface ---\n\nexport interface HighlightLocale {\n\treadonly label: string;\n\treadonly tooltip: string;\n\treadonly resetLabel: string;\n\treadonly ariaLabelPrefix: string;\n}\n\n// --- Default English Locale ---\n\nexport const HIGHLIGHT_LOCALE_EN: HighlightLocale = {\n\tlabel: 'Highlight',\n\ttooltip: 'Highlight Color',\n\tresetLabel: 'None',\n\tariaLabelPrefix: 'Highlight color',\n};\n\n// --- German Locale ---\n\nexport const HIGHLIGHT_LOCALE_DE: HighlightLocale = {\n\tlabel: 'Hervorhebung',\n\ttooltip: 'Hervorhebungsfarbe',\n\tresetLabel: 'Keine',\n\tariaLabelPrefix: 'Hervorhebungsfarbe',\n};\n\n// --- Spanish Locale ---\n\nexport const HIGHLIGHT_LOCALE_ES: HighlightLocale = {\n\tlabel: 'Resaltado',\n\ttooltip: 'Color de resaltado',\n\tresetLabel: 'Ninguno',\n\tariaLabelPrefix: 'Color de resaltado',\n};\n\n// --- French Locale ---\n\nexport const HIGHLIGHT_LOCALE_FR: HighlightLocale = {\n\tlabel: 'Surlignage',\n\ttooltip: 'Couleur de surlignage',\n\tresetLabel: 'Aucun',\n\tariaLabelPrefix: 'Couleur de surlignage',\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const HIGHLIGHT_LOCALE_ZH: HighlightLocale = {\n\tlabel: '高亮',\n\ttooltip: '高亮颜色',\n\tresetLabel: '无',\n\tariaLabelPrefix: '高亮颜色',\n};\n\n// --- Russian Locale ---\n\nexport const HIGHLIGHT_LOCALE_RU: HighlightLocale = {\n\tlabel: 'Выделение',\n\ttooltip: 'Цвет выделения',\n\tresetLabel: 'Нет',\n\tariaLabelPrefix: 'Цвет выделения',\n};\n\n// --- Arabic Locale ---\n\nexport const HIGHLIGHT_LOCALE_AR: HighlightLocale = {\n\tlabel: 'تمييز',\n\ttooltip: 'لون التمييز',\n\tresetLabel: 'بدون',\n\tariaLabelPrefix: 'لون التمييز',\n};\n\n// --- Hindi Locale ---\n\nexport const HIGHLIGHT_LOCALE_HI: HighlightLocale = {\n\tlabel: 'हाइलाइट',\n\ttooltip: 'हाइलाइट रंग',\n\tresetLabel: 'कोई नहीं',\n\tariaLabelPrefix: 'हाइलाइट रंग',\n};\n\n// --- Locale Map ---\n\nexport const HIGHLIGHT_LOCALES: Record<string, HighlightLocale> = {\n\ten: HIGHLIGHT_LOCALE_EN,\n\tde: HIGHLIGHT_LOCALE_DE,\n\tes: HIGHLIGHT_LOCALE_ES,\n\tfr: HIGHLIGHT_LOCALE_FR,\n\tzh: HIGHLIGHT_LOCALE_ZH,\n\tru: HIGHLIGHT_LOCALE_RU,\n\tar: HIGHLIGHT_LOCALE_AR,\n\thi: HIGHLIGHT_LOCALE_HI,\n};\n","/**\n * HighlightPlugin: registers a highlight (background-color) mark with attrs,\n * toolbar button with a color picker popup, and removeHighlight command.\n */\n\nimport { COLOR_PICKER_CSS } from '../../editor/styles/color-picker.js';\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport { escapeHTML } from '../../model/HTMLUtils.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport { setStyleProperty } from '../../style/StyleRuntime.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { isColorMarkActive, removeColorMark } from '../shared/ColorMarkOperations.js';\nimport { renderColorPickerPopup } from '../shared/ColorPickerPopup.js';\nimport { isValidCSSColor, resolveColors } from '../shared/ColorValidation.js';\nimport { HIGHLIGHT_LOCALES, type HighlightLocale } from './HighlightLocale.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface MarkAttrRegistry {\n\t\thighlight: { color: string };\n\t}\n}\n\n// --- Configuration ---\n\nexport interface HighlightConfig {\n\t/**\n\t * Restricts the color picker to a specific set of hex colors.\n\t * Each value must be a valid hex color code (`#RGB` or `#RRGGBB`).\n\t * Duplicates are removed automatically (case-insensitive).\n\t * When omitted, the full default palette is shown.\n\t */\n\treadonly colors?: readonly string[];\n\t/** When true, a separator is rendered after the highlight toolbar item. */\n\treadonly separatorAfter?: boolean;\n\treadonly locale?: HighlightLocale;\n}\n\n// --- Color Palette (Highlight-optimized: 10 columns x 5 rows) ---\n\nconst HIGHLIGHT_PALETTE: readonly string[] = [\n\t// Row 1 — Classic highlighter colors (bright, vivid)\n\t'#fff176',\n\t'#aed581',\n\t'#4dd0e1',\n\t'#64b5f6',\n\t'#ce93d8',\n\t'#f48fb1',\n\t'#ffab91',\n\t'#ff8a65',\n\t'#e6ee9c',\n\t'#80cbc4',\n\t// Row 2 — Light pastels\n\t'#fff9c4',\n\t'#dcedc8',\n\t'#e0f7fa',\n\t'#e3f2fd',\n\t'#f3e5f5',\n\t'#fce4ec',\n\t'#fff3e0',\n\t'#fbe9e7',\n\t'#f9fbe7',\n\t'#e0f2f1',\n\t// Row 3 — Medium pastels\n\t'#fff59d',\n\t'#c5e1a5',\n\t'#80deea',\n\t'#90caf9',\n\t'#e1bee7',\n\t'#f8bbd0',\n\t'#ffcc80',\n\t'#ffab91',\n\t'#e6ee9c',\n\t'#a5d6a7',\n\t// Row 4 — Bold pastels\n\t'#ffee58',\n\t'#9ccc65',\n\t'#26c6da',\n\t'#42a5f5',\n\t'#ab47bc',\n\t'#ec407a',\n\t'#ffa726',\n\t'#ff7043',\n\t'#d4e157',\n\t'#66bb6a',\n\t// Row 5 — Grays and neutral highlights\n\t'#ffffff',\n\t'#fafafa',\n\t'#f5f5f5',\n\t'#eeeeee',\n\t'#e0e0e0',\n\t'#bdbdbd',\n\t'#e8eaf6',\n\t'#efebe9',\n\t'#eceff1',\n\t'#fafafa',\n];\n\n// --- Plugin ---\n\nexport class HighlightPlugin implements Plugin {\n\treadonly id = 'highlight';\n\treadonly name = 'Highlight';\n\treadonly priority = 24;\n\n\tprivate readonly config: HighlightConfig;\n\tprivate readonly colors: readonly string[];\n\tprivate locale!: HighlightLocale;\n\n\tconstructor(config?: Partial<HighlightConfig>) {\n\t\tthis.config = { ...config };\n\t\tthis.colors = resolveColors(config?.colors, HIGHLIGHT_PALETTE, 'HighlightPlugin');\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(HIGHLIGHT_LOCALES, context, this.config.locale);\n\n\t\tcontext.registerStyleSheet(COLOR_PICKER_CSS);\n\t\tthis.registerMarkSpec(context);\n\t\tthis.registerCommands(context);\n\t\tthis.registerToolbarItem(context);\n\t}\n\n\tprivate registerMarkSpec(context: PluginContext): void {\n\t\tcontext.registerMarkSpec({\n\t\t\ttype: 'highlight',\n\t\t\trank: 4,\n\t\t\tattrs: {\n\t\t\t\tcolor: { default: '' },\n\t\t\t},\n\t\t\ttoDOM(mark) {\n\t\t\t\tconst span = document.createElement('span');\n\t\t\t\tconst color = mark.attrs?.color ?? '';\n\t\t\t\tsetStyleProperty(span, 'backgroundColor', color);\n\t\t\t\treturn span;\n\t\t\t},\n\t\t\ttoHTMLString: (mark, content) => {\n\t\t\t\tconst color: string = String(mark.attrs?.color ?? '');\n\t\t\t\tif (!color || !isValidCSSColor(color)) return content;\n\t\t\t\treturn `<span style=\"background-color: ${escapeHTML(color)}\">${content}</span>`;\n\t\t\t},\n\t\t\ttoHTMLStyle: (mark) => {\n\t\t\t\tconst color: string = String(mark.attrs?.color ?? '');\n\t\t\t\tif (!color || !isValidCSSColor(color)) return null;\n\t\t\t\treturn `background-color: ${escapeHTML(color)}`;\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 color: string = el.style.backgroundColor;\n\t\t\t\t\t\tif (!color || !isValidCSSColor(color)) return false;\n\t\t\t\t\t\treturn { color };\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\tprivate registerCommands(context: PluginContext): void {\n\t\tcontext.registerCommand('removeHighlight', () => {\n\t\t\treturn removeColorMark(context, context.getState(), 'highlight');\n\t\t});\n\t}\n\n\tprivate registerToolbarItem(context: PluginContext): void {\n\t\tconst pathD =\n\t\t\t'M11 3L5.5 17h2.25l1.12-3h6.25l1.12 3h2.25L13 3h-2z' + 'm-1.38 9L12 5.67 14.38 12H9.62z';\n\t\tconst icon: string = [\n\t\t\t'<svg xmlns=\"http://www.w3.org/2000/svg\"',\n\t\t\t' viewBox=\"0 0 24 24\">',\n\t\t\t`<path d=\"${pathD}\"/>`,\n\t\t\t'<rect x=\"3\" y=\"17\" width=\"18\" height=\"6\"',\n\t\t\t' rx=\"0.5\" fill=\"#fff176\"/>',\n\t\t\t'</svg>',\n\t\t].join('');\n\n\t\tcontext.registerToolbarItem({\n\t\t\tid: 'highlight',\n\t\t\tgroup: 'format',\n\t\t\ticon,\n\t\t\tlabel: this.locale.label,\n\t\t\ttooltip: this.locale.tooltip,\n\t\t\tcommand: 'removeHighlight',\n\t\t\tpriority: 46,\n\t\t\tpopupType: 'custom',\n\t\t\tseparatorAfter: this.config.separatorAfter,\n\t\t\trenderPopup: (container, ctx, onClose) => {\n\t\t\t\trenderColorPickerPopup(container, ctx, {\n\t\t\t\t\tmarkType: 'highlight',\n\t\t\t\t\tcolors: this.colors,\n\t\t\t\t\tcolumns: 10,\n\t\t\t\t\tresetLabel: this.locale.resetLabel,\n\t\t\t\t\tresetCommand: 'removeHighlight',\n\t\t\t\t\tariaLabelPrefix: this.locale.ariaLabelPrefix,\n\t\t\t\t\tonClose,\n\t\t\t\t});\n\t\t\t},\n\t\t\tisActive: (state: EditorState) => isColorMarkActive(state, 'highlight'),\n\t\t});\n\t}\n}\n"],"names":["HIGHLIGHT_LOCALE_EN","label","tooltip","resetLabel","ariaLabelPrefix","HIGHLIGHT_LOCALES","en","de","es","fr","zh","ru","ar","hi","HIGHLIGHT_PALETTE","HighlightPlugin","id","name","priority","config","colors","locale","this","resolveColors","context","resolvePluginLocale","registerStyleSheet","COLOR_PICKER_CSS","registerMarkSpec","registerCommands","registerToolbarItem","type","rank","attrs","color","default","mark","span","document","createElement","setStyleProperty","toHTMLString","content","String","isValidCSSColor","escapeHTML","toHTMLStyle","parseHTML","tag","getAttrs","el","style","backgroundColor","sanitize","tags","registerCommand","removeColorMark","getState","icon","join","group","command","popupType","separatorAfter","renderPopup","container","ctx","onClose","renderColorPickerPopup","markType","columns","resetCommand","isActive","state","isColorMarkActive"],"mappings":";;;;;AAaO,MAAMA,IAAuC,EACnDC,OAAO,aACPC,SAAS,mBACTC,YAAY,QACZC,iBAAiB,kBAAA,GAoELC,IAAqD,EACjEC,IAAIN,GACJO,IAjEmD,EACnDN,OAAO,gBACPC,SAAS,sBACTC,YAAY,SACZC,iBAAiB,wBA8DjBI,IAzDmD,EACnDP,OAAO,aACPC,SAAS,sBACTC,YAAY,WACZC,iBAAiB,qBAAA,GAsDjBK,IAjDmD,EACnDR,OAAO,cACPC,SAAS,yBACTC,YAAY,SACZC,iBAAiB,wBAAA,GA8CjBM,IAzCmD,EACnDT,OAAO,MACPC,SAAS,QACTC,YAAY,KACZC,iBAAiB,UAsCjBO,IAjCmD,EACnDV,OAAO,aACPC,SAAS,kBACTC,YAAY,OACZC,iBAAiB,iBAAA,GA8BjBQ,IAzBmD,EACnDX,OAAO,SACPC,SAAS,eACTC,YAAY,QACZC,iBAAiB,cAAA,GAsBjBS,IAjBmD,EACnDZ,OAAO,WACPC,SAAS,eACTC,YAAY,YACZC,iBAAiB,cAAA,EAAA,GCvCZU,IAAuC,CAE5C,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA;AAKM,MAAMC,EAAAA;AAAAA,EACHC,KAAK;AAAA,EACLC,OAAO;AAAA,EACPC,WAAW;AAAA,EAEHC;AAAAA,EACAC;AAAAA,EACTC;AAAAA,EAER,YAAYF,IAAAA;AACXG,SAAKH,SAAS,EAAA,GAAKA,MACnBG,KAAKF,SAASG,EAAcJ,IAAQC,QAAQN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AAY,WAAA,CAAA;AAAA,EAEtD;AAAA,EAEQ,oBAAoBjC,IAAAA;AAC3B,UAEMkC,KAAe,CACpB,2CACA,yBACA,iGACA,4CACA,8BACA,QAAA,EACCC,KAAK,EAAA;AAEPnC,IAAAA,GAAQM,oBAAoB,EAC3Bd,IAAI,aACJ4C,OAAO,UACPF,UACAzD,OAAOqB,KAAKD,OAAOpB,OACnBC,SAASoB,KAAKD,OAAOnB,SACrB2D,SAAS,mBACT3C,UAAU,IACV4C,WAAW,UACXC,gBAAgBzC,KAAKH,OAAO4C,gBAC5BC,aAAa,CAACC,IAAWC,IAAKC,OAAAA;AAC7BC,QAAuBH,IAAWC,IAAK,EACtCG,UAAU,aACVjD,QAAQE,KAAKF,QACbkD,SAAS,IACTnE,YAAYmB,KAAKD,OAAOlB,YACxBoE,cAAc,mBACdnE,iBAAiBkB,KAAKD,OAAOjB,iBAC7B+D;OAGFK,UAAWC,CAAAA,OAAuBC,EAAkBD,IAAO,WAAA,EAAA,CAAA;AAAA,EAE7D;AAAA;"}
|
|
1
|
+
{"version":3,"file":"index-WrqH1wG8.mjs","sources":["../../src/plugins/highlight/HighlightLocale.ts","../../src/plugins/highlight/HighlightPlugin.ts"],"sourcesContent":["/** Locale interface and default English locale for the HighlightPlugin. */\n\n// --- Locale Interface ---\n\nexport interface HighlightLocale {\n\treadonly label: string;\n\treadonly tooltip: string;\n\treadonly resetLabel: string;\n\treadonly ariaLabelPrefix: string;\n}\n\n// --- Default English Locale ---\n\nexport const HIGHLIGHT_LOCALE_EN: HighlightLocale = {\n\tlabel: 'Highlight',\n\ttooltip: 'Highlight Color',\n\tresetLabel: 'None',\n\tariaLabelPrefix: 'Highlight color',\n};\n\n// --- German Locale ---\n\nexport const HIGHLIGHT_LOCALE_DE: HighlightLocale = {\n\tlabel: 'Hervorhebung',\n\ttooltip: 'Hervorhebungsfarbe',\n\tresetLabel: 'Keine',\n\tariaLabelPrefix: 'Hervorhebungsfarbe',\n};\n\n// --- Spanish Locale ---\n\nexport const HIGHLIGHT_LOCALE_ES: HighlightLocale = {\n\tlabel: 'Resaltado',\n\ttooltip: 'Color de resaltado',\n\tresetLabel: 'Ninguno',\n\tariaLabelPrefix: 'Color de resaltado',\n};\n\n// --- French Locale ---\n\nexport const HIGHLIGHT_LOCALE_FR: HighlightLocale = {\n\tlabel: 'Surlignage',\n\ttooltip: 'Couleur de surlignage',\n\tresetLabel: 'Aucun',\n\tariaLabelPrefix: 'Couleur de surlignage',\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const HIGHLIGHT_LOCALE_ZH: HighlightLocale = {\n\tlabel: '高亮',\n\ttooltip: '高亮颜色',\n\tresetLabel: '无',\n\tariaLabelPrefix: '高亮颜色',\n};\n\n// --- Russian Locale ---\n\nexport const HIGHLIGHT_LOCALE_RU: HighlightLocale = {\n\tlabel: 'Выделение',\n\ttooltip: 'Цвет выделения',\n\tresetLabel: 'Нет',\n\tariaLabelPrefix: 'Цвет выделения',\n};\n\n// --- Arabic Locale ---\n\nexport const HIGHLIGHT_LOCALE_AR: HighlightLocale = {\n\tlabel: 'تمييز',\n\ttooltip: 'لون التمييز',\n\tresetLabel: 'بدون',\n\tariaLabelPrefix: 'لون التمييز',\n};\n\n// --- Hindi Locale ---\n\nexport const HIGHLIGHT_LOCALE_HI: HighlightLocale = {\n\tlabel: 'हाइलाइट',\n\ttooltip: 'हाइलाइट रंग',\n\tresetLabel: 'कोई नहीं',\n\tariaLabelPrefix: 'हाइलाइट रंग',\n};\n\n// --- Locale Map ---\n\nexport const HIGHLIGHT_LOCALES: Record<string, HighlightLocale> = {\n\ten: HIGHLIGHT_LOCALE_EN,\n\tde: HIGHLIGHT_LOCALE_DE,\n\tes: HIGHLIGHT_LOCALE_ES,\n\tfr: HIGHLIGHT_LOCALE_FR,\n\tzh: HIGHLIGHT_LOCALE_ZH,\n\tru: HIGHLIGHT_LOCALE_RU,\n\tar: HIGHLIGHT_LOCALE_AR,\n\thi: HIGHLIGHT_LOCALE_HI,\n};\n","/**\n * HighlightPlugin: registers a highlight (background-color) mark with attrs,\n * toolbar button with a color picker popup, and removeHighlight command.\n */\n\nimport { COLOR_PICKER_CSS } from '../../editor/styles/color-picker.js';\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport { escapeHTML } from '../../model/HTMLUtils.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport { setStyleProperty } from '../../style/StyleRuntime.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { isColorMarkActive, removeColorMark } from '../shared/ColorMarkOperations.js';\nimport { renderColorPickerPopup } from '../shared/ColorPickerPopup.js';\nimport { isValidCSSColor, resolveColors } from '../shared/ColorValidation.js';\nimport { HIGHLIGHT_LOCALES, type HighlightLocale } from './HighlightLocale.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface MarkAttrRegistry {\n\t\thighlight: { color: string };\n\t}\n}\n\n// --- Configuration ---\n\nexport interface HighlightConfig {\n\t/**\n\t * Restricts the color picker to a specific set of hex colors.\n\t * Each value must be a valid hex color code (`#RGB` or `#RRGGBB`).\n\t * Duplicates are removed automatically (case-insensitive).\n\t * When omitted, the full default palette is shown.\n\t */\n\treadonly colors?: readonly string[];\n\t/** When true, a separator is rendered after the highlight toolbar item. */\n\treadonly separatorAfter?: boolean;\n\treadonly locale?: HighlightLocale;\n}\n\n// --- Color Palette (Highlight-optimized: 10 columns x 5 rows) ---\n\nconst HIGHLIGHT_PALETTE: readonly string[] = [\n\t// Row 1 — Classic highlighter colors (bright, vivid)\n\t'#fff176',\n\t'#aed581',\n\t'#4dd0e1',\n\t'#64b5f6',\n\t'#ce93d8',\n\t'#f48fb1',\n\t'#ffab91',\n\t'#ff8a65',\n\t'#e6ee9c',\n\t'#80cbc4',\n\t// Row 2 — Light pastels\n\t'#fff9c4',\n\t'#dcedc8',\n\t'#e0f7fa',\n\t'#e3f2fd',\n\t'#f3e5f5',\n\t'#fce4ec',\n\t'#fff3e0',\n\t'#fbe9e7',\n\t'#f9fbe7',\n\t'#e0f2f1',\n\t// Row 3 — Medium pastels\n\t'#fff59d',\n\t'#c5e1a5',\n\t'#80deea',\n\t'#90caf9',\n\t'#e1bee7',\n\t'#f8bbd0',\n\t'#ffcc80',\n\t'#ffab91',\n\t'#e6ee9c',\n\t'#a5d6a7',\n\t// Row 4 — Bold pastels\n\t'#ffee58',\n\t'#9ccc65',\n\t'#26c6da',\n\t'#42a5f5',\n\t'#ab47bc',\n\t'#ec407a',\n\t'#ffa726',\n\t'#ff7043',\n\t'#d4e157',\n\t'#66bb6a',\n\t// Row 5 — Grays and neutral highlights\n\t'#ffffff',\n\t'#fafafa',\n\t'#f5f5f5',\n\t'#eeeeee',\n\t'#e0e0e0',\n\t'#bdbdbd',\n\t'#e8eaf6',\n\t'#efebe9',\n\t'#eceff1',\n\t'#fafafa',\n];\n\n// --- Plugin ---\n\nexport class HighlightPlugin implements Plugin {\n\treadonly id = 'highlight';\n\treadonly name = 'Highlight';\n\treadonly priority = 24;\n\n\tprivate readonly config: HighlightConfig;\n\tprivate readonly colors: readonly string[];\n\tprivate locale!: HighlightLocale;\n\n\tconstructor(config?: Partial<HighlightConfig>) {\n\t\tthis.config = { ...config };\n\t\tthis.colors = resolveColors(config?.colors, HIGHLIGHT_PALETTE, 'HighlightPlugin');\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(HIGHLIGHT_LOCALES, context, this.config.locale);\n\n\t\tcontext.registerStyleSheet(COLOR_PICKER_CSS);\n\t\tthis.registerMarkSpec(context);\n\t\tthis.registerCommands(context);\n\t\tthis.registerToolbarItem(context);\n\t}\n\n\tprivate registerMarkSpec(context: PluginContext): void {\n\t\tcontext.registerMarkSpec({\n\t\t\ttype: 'highlight',\n\t\t\trank: 4,\n\t\t\tattrs: {\n\t\t\t\tcolor: { default: '' },\n\t\t\t},\n\t\t\ttoDOM(mark) {\n\t\t\t\tconst span = document.createElement('span');\n\t\t\t\tconst color = mark.attrs?.color ?? '';\n\t\t\t\tsetStyleProperty(span, 'backgroundColor', color);\n\t\t\t\treturn span;\n\t\t\t},\n\t\t\ttoHTMLString: (mark, content) => {\n\t\t\t\tconst color: string = String(mark.attrs?.color ?? '');\n\t\t\t\tif (!color || !isValidCSSColor(color)) return content;\n\t\t\t\treturn `<span style=\"background-color: ${escapeHTML(color)}\">${content}</span>`;\n\t\t\t},\n\t\t\ttoHTMLStyle: (mark) => {\n\t\t\t\tconst color: string = String(mark.attrs?.color ?? '');\n\t\t\t\tif (!color || !isValidCSSColor(color)) return null;\n\t\t\t\treturn `background-color: ${escapeHTML(color)}`;\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 color: string = el.style.backgroundColor;\n\t\t\t\t\t\tif (!color || !isValidCSSColor(color)) return false;\n\t\t\t\t\t\treturn { color };\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\tprivate registerCommands(context: PluginContext): void {\n\t\tcontext.registerCommand('removeHighlight', () => {\n\t\t\treturn removeColorMark(context, context.getState(), 'highlight');\n\t\t});\n\t}\n\n\tprivate registerToolbarItem(context: PluginContext): void {\n\t\tconst pathD =\n\t\t\t'M11 3L5.5 17h2.25l1.12-3h6.25l1.12 3h2.25L13 3h-2z' + 'm-1.38 9L12 5.67 14.38 12H9.62z';\n\t\tconst icon: string = [\n\t\t\t'<svg xmlns=\"http://www.w3.org/2000/svg\"',\n\t\t\t' viewBox=\"0 0 24 24\">',\n\t\t\t`<path d=\"${pathD}\"/>`,\n\t\t\t'<rect x=\"3\" y=\"17\" width=\"18\" height=\"6\"',\n\t\t\t' rx=\"0.5\" fill=\"#fff176\"/>',\n\t\t\t'</svg>',\n\t\t].join('');\n\n\t\tcontext.registerToolbarItem({\n\t\t\tid: 'highlight',\n\t\t\tgroup: 'format',\n\t\t\ticon,\n\t\t\tlabel: this.locale.label,\n\t\t\ttooltip: this.locale.tooltip,\n\t\t\tcommand: 'removeHighlight',\n\t\t\tpriority: 46,\n\t\t\tpopupType: 'custom',\n\t\t\tseparatorAfter: this.config.separatorAfter,\n\t\t\trenderPopup: (container, ctx, onClose) => {\n\t\t\t\trenderColorPickerPopup(container, ctx, {\n\t\t\t\t\tmarkType: 'highlight',\n\t\t\t\t\tcolors: this.colors,\n\t\t\t\t\tcolumns: 10,\n\t\t\t\t\tresetLabel: this.locale.resetLabel,\n\t\t\t\t\tresetCommand: 'removeHighlight',\n\t\t\t\t\tariaLabelPrefix: this.locale.ariaLabelPrefix,\n\t\t\t\t\tonClose,\n\t\t\t\t});\n\t\t\t},\n\t\t\tisActive: (state: EditorState) => isColorMarkActive(state, 'highlight'),\n\t\t});\n\t}\n}\n"],"names":["HIGHLIGHT_LOCALE_EN","label","tooltip","resetLabel","ariaLabelPrefix","HIGHLIGHT_LOCALES","en","de","es","fr","zh","ru","ar","hi","HIGHLIGHT_PALETTE","HighlightPlugin","id","name","priority","config","colors","locale","this","resolveColors","context","resolvePluginLocale","registerStyleSheet","COLOR_PICKER_CSS","registerMarkSpec","registerCommands","registerToolbarItem","type","rank","attrs","color","default","mark","span","document","createElement","setStyleProperty","toHTMLString","content","String","isValidCSSColor","escapeHTML","toHTMLStyle","parseHTML","tag","getAttrs","el","style","backgroundColor","sanitize","tags","registerCommand","removeColorMark","getState","icon","join","group","command","popupType","separatorAfter","renderPopup","container","ctx","onClose","renderColorPickerPopup","markType","columns","resetCommand","isActive","state","isColorMarkActive"],"mappings":";;;;;AAaO,MAAMA,IAAuC,EACnDC,OAAO,aACPC,SAAS,mBACTC,YAAY,QACZC,iBAAiB,kBAAA,GAoELC,IAAqD,EACjEC,IAAIN,GACJO,IAjEmD,EACnDN,OAAO,gBACPC,SAAS,sBACTC,YAAY,SACZC,iBAAiB,wBA8DjBI,IAzDmD,EACnDP,OAAO,aACPC,SAAS,s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AAKH,OAAO4C,gBAC5BC,aAAa,CAACC,IAAWC,IAAKC,OAAAA;AAC7BC,QAAuBH,IAAWC,IAAK,EACtCG,UAAU,aACVjD,QAAQE,KAAKF,QACbkD,SAAS,IACTnE,YAAYmB,KAAKD,OAAOlB,YACxBoE,cAAc,mBACdnE,iBAAiBkB,KAAKD,OAAOjB,iBAC7B+D;OAGFK,UAAWC,CAAAA,OAAuBC,EAAkBD,IAAO,WAAA,EAAA,CAAA;AAAA,EAE7D;AAAA;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { C as e, r as t, i as o, a as r } from "./ColorPickerPopup-
|
|
1
|
+
import { C as e, r as t, i as o, a as r } from "./ColorPickerPopup-TpIRlXc8.mjs";
|
|
2
2
|
import { r as a } from "./resolvePluginLocale-B4w1OkPy.mjs";
|
|
3
3
|
import { e as l } from "./HTMLUtils-DTqQzcKR.mjs";
|
|
4
|
-
import { a as s } from "./StyleRuntime-
|
|
4
|
+
import { a as s } from "./StyleRuntime-CP4NCwKT.mjs";
|
|
5
5
|
import { r as i, i as c } from "./ColorValidation-CV4f1wu6.mjs";
|
|
6
6
|
const f = { label: "Text Color", tooltip: "Text Color", resetLabel: "Default", ariaLabelPrefix: "Text color" }, b = { en: f, de: { label: "Textfarbe", tooltip: "Textfarbe", resetLabel: "Standard", ariaLabelPrefix: "Textfarbe" }, es: { label: "Color de texto", tooltip: "Color de texto", resetLabel: "Predeterminado", ariaLabelPrefix: "Color de texto" }, fr: { label: "Couleur du texte", tooltip: "Couleur du texte", resetLabel: "Par défaut", ariaLabelPrefix: "Couleur du texte" }, zh: { label: "文字颜色", tooltip: "文字颜色", resetLabel: "默认", ariaLabelPrefix: "文字颜色" }, ru: { label: "Цвет текста", tooltip: "Цвет текста", resetLabel: "По умолчанию", ariaLabelPrefix: "Цвет текста" }, ar: { label: "لون النص", tooltip: "لون النص", resetLabel: "افتراضي", ariaLabelPrefix: "لون النص" }, hi: { label: "टेक्स्ट रंग", tooltip: "टेक्स्ट रंग", resetLabel: "डिफ़ॉल्ट", ariaLabelPrefix: "टेक्स्ट रंग" } }, d = ["#000000", "#434343", "#666666", "#999999", "#b7b7b7", "#cccccc", "#d9d9d9", "#efefef", "#f3f3f3", "#ffffff", "#980000", "#ff0000", "#ff9900", "#ffff00", "#00ff00", "#00ffff", "#4a86e8", "#0000ff", "#9900ff", "#ff00ff", "#e6b8af", "#f4cccc", "#fce5cd", "#fff2cc", "#d9ead3", "#d0e0e3", "#c9daf8", "#cfe2f3", "#d9d2e9", "#ead1dc", "#dd7e6b", "#ea9999", "#f9cb9c", "#ffe599", "#b6d7a8", "#a2c4c9", "#a4c2f4", "#9fc5e8", "#b4a7d6", "#d5a6bd", "#cc4125", "#e06666", "#f6b26b", "#ffd966", "#93c47d", "#76a5af", "#6d9eeb", "#6fa8dc", "#8e7cc3", "#c27ba0", "#a61c00", "#cc0000", "#e69138", "#f1c232", "#6aa84f", "#45818e", "#3c78d8", "#3d85c6", "#674ea7", "#a64d79", "#85200c", "#990000", "#b45f06", "#bf9000", "#38761d", "#134f5c", "#1155cc", "#0b5394", "#351c75", "#741b47"];
|
|
7
7
|
class n {
|
|
@@ -47,4 +47,4 @@ export {
|
|
|
47
47
|
b as a,
|
|
48
48
|
f as b
|
|
49
49
|
};
|
|
50
|
-
//# sourceMappingURL=index-
|
|
50
|
+
//# sourceMappingURL=index-fx3KIap3.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index-BvqkuEY1.mjs","sources":["../../src/plugins/text-color/TextColorLocale.ts","../../src/plugins/text-color/TextColorPlugin.ts"],"sourcesContent":["/** Locale interface and default English locale for the TextColorPlugin. */\n\n// --- Locale Interface ---\n\nexport interface TextColorLocale {\n\treadonly label: string;\n\treadonly tooltip: string;\n\treadonly resetLabel: string;\n\treadonly ariaLabelPrefix: string;\n}\n\n// --- Default English Locale ---\n\nexport const TEXT_COLOR_LOCALE_EN: TextColorLocale = {\n\tlabel: 'Text Color',\n\ttooltip: 'Text Color',\n\tresetLabel: 'Default',\n\tariaLabelPrefix: 'Text color',\n};\n\n// --- German Locale ---\n\nexport const TEXT_COLOR_LOCALE_DE: TextColorLocale = {\n\tlabel: 'Textfarbe',\n\ttooltip: 'Textfarbe',\n\tresetLabel: 'Standard',\n\tariaLabelPrefix: 'Textfarbe',\n};\n\n// --- Spanish Locale ---\n\nexport const TEXT_COLOR_LOCALE_ES: TextColorLocale = {\n\tlabel: 'Color de texto',\n\ttooltip: 'Color de texto',\n\tresetLabel: 'Predeterminado',\n\tariaLabelPrefix: 'Color de texto',\n};\n\n// --- French Locale ---\n\nexport const TEXT_COLOR_LOCALE_FR: TextColorLocale = {\n\tlabel: 'Couleur du texte',\n\ttooltip: 'Couleur du texte',\n\tresetLabel: 'Par défaut',\n\tariaLabelPrefix: 'Couleur du texte',\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const TEXT_COLOR_LOCALE_ZH: TextColorLocale = {\n\tlabel: '文字颜色',\n\ttooltip: '文字颜色',\n\tresetLabel: '默认',\n\tariaLabelPrefix: '文字颜色',\n};\n\n// --- Russian Locale ---\n\nexport const TEXT_COLOR_LOCALE_RU: TextColorLocale = {\n\tlabel: 'Цвет текста',\n\ttooltip: 'Цвет текста',\n\tresetLabel: 'По умолчанию',\n\tariaLabelPrefix: 'Цвет текста',\n};\n\n// --- Arabic Locale ---\n\nexport const TEXT_COLOR_LOCALE_AR: TextColorLocale = {\n\tlabel: 'لون النص',\n\ttooltip: 'لون النص',\n\tresetLabel: 'افتراضي',\n\tariaLabelPrefix: 'لون النص',\n};\n\n// --- Hindi Locale ---\n\nexport const TEXT_COLOR_LOCALE_HI: TextColorLocale = {\n\tlabel: 'टेक्स्ट रंग',\n\ttooltip: 'टेक्स्ट रंग',\n\tresetLabel: 'डिफ़ॉल्ट',\n\tariaLabelPrefix: 'टेक्स्ट रंग',\n};\n\n// --- Locale Map ---\n\nexport const TEXT_COLOR_LOCALES: Record<string, TextColorLocale> = {\n\ten: TEXT_COLOR_LOCALE_EN,\n\tde: TEXT_COLOR_LOCALE_DE,\n\tes: TEXT_COLOR_LOCALE_ES,\n\tfr: TEXT_COLOR_LOCALE_FR,\n\tzh: TEXT_COLOR_LOCALE_ZH,\n\tru: TEXT_COLOR_LOCALE_RU,\n\tar: TEXT_COLOR_LOCALE_AR,\n\thi: TEXT_COLOR_LOCALE_HI,\n};\n","/**\n * TextColorPlugin: registers a text color mark with attrs,\n * toolbar button with a color picker popup, and removeTextColor command.\n */\n\nimport { COLOR_PICKER_CSS } from '../../editor/styles/color-picker.js';\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport { escapeHTML } from '../../model/HTMLUtils.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport { setStyleProperty } from '../../style/StyleRuntime.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { isColorMarkActive, removeColorMark } from '../shared/ColorMarkOperations.js';\nimport { renderColorPickerPopup } from '../shared/ColorPickerPopup.js';\nimport { isValidCSSColor, resolveColors } from '../shared/ColorValidation.js';\nimport { TEXT_COLOR_LOCALES, type TextColorLocale } from './TextColorLocale.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface MarkAttrRegistry {\n\t\ttextColor: { color: string };\n\t}\n}\n\n// --- Configuration ---\n\nexport interface TextColorConfig {\n\t/**\n\t * Restricts the color picker to a specific set of hex colors.\n\t * Each value must be a valid hex color code (`#RGB` or `#RRGGBB`).\n\t * Duplicates are removed automatically (case-insensitive).\n\t * When omitted, the full default palette is shown.\n\t */\n\treadonly colors?: readonly string[];\n\t/** When true, a separator is rendered after the textColor toolbar item. */\n\treadonly separatorAfter?: boolean;\n\treadonly locale?: TextColorLocale;\n}\n\n// --- Color Palette (Google Docs style: 10 columns x 7 rows) ---\n\nconst COLOR_PALETTE: readonly string[] = [\n\t// Row 1 — dark\n\t'#000000',\n\t'#434343',\n\t'#666666',\n\t'#999999',\n\t'#b7b7b7',\n\t'#cccccc',\n\t'#d9d9d9',\n\t'#efefef',\n\t'#f3f3f3',\n\t'#ffffff',\n\t// Row 2 — vivid\n\t'#980000',\n\t'#ff0000',\n\t'#ff9900',\n\t'#ffff00',\n\t'#00ff00',\n\t'#00ffff',\n\t'#4a86e8',\n\t'#0000ff',\n\t'#9900ff',\n\t'#ff00ff',\n\t// Row 3 — light 3\n\t'#e6b8af',\n\t'#f4cccc',\n\t'#fce5cd',\n\t'#fff2cc',\n\t'#d9ead3',\n\t'#d0e0e3',\n\t'#c9daf8',\n\t'#cfe2f3',\n\t'#d9d2e9',\n\t'#ead1dc',\n\t// Row 4 — light 2\n\t'#dd7e6b',\n\t'#ea9999',\n\t'#f9cb9c',\n\t'#ffe599',\n\t'#b6d7a8',\n\t'#a2c4c9',\n\t'#a4c2f4',\n\t'#9fc5e8',\n\t'#b4a7d6',\n\t'#d5a6bd',\n\t// Row 5 — light 1\n\t'#cc4125',\n\t'#e06666',\n\t'#f6b26b',\n\t'#ffd966',\n\t'#93c47d',\n\t'#76a5af',\n\t'#6d9eeb',\n\t'#6fa8dc',\n\t'#8e7cc3',\n\t'#c27ba0',\n\t// Row 6 — dark 1\n\t'#a61c00',\n\t'#cc0000',\n\t'#e69138',\n\t'#f1c232',\n\t'#6aa84f',\n\t'#45818e',\n\t'#3c78d8',\n\t'#3d85c6',\n\t'#674ea7',\n\t'#a64d79',\n\t// Row 7 — dark 2\n\t'#85200c',\n\t'#990000',\n\t'#b45f06',\n\t'#bf9000',\n\t'#38761d',\n\t'#134f5c',\n\t'#1155cc',\n\t'#0b5394',\n\t'#351c75',\n\t'#741b47',\n];\n\n// --- Plugin ---\n\nexport class TextColorPlugin implements Plugin {\n\treadonly id = 'textColor';\n\treadonly name = 'Text Color';\n\treadonly priority = 23;\n\n\tprivate readonly config: TextColorConfig;\n\tprivate readonly colors: readonly string[];\n\tprivate locale!: TextColorLocale;\n\n\tconstructor(config?: Partial<TextColorConfig>) {\n\t\tthis.config = { ...config };\n\t\tthis.colors = resolveColors(config?.colors, COLOR_PALETTE, 'TextColorPlugin');\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(TEXT_COLOR_LOCALES, context, this.config.locale);\n\n\t\tcontext.registerStyleSheet(COLOR_PICKER_CSS);\n\t\tthis.registerMarkSpec(context);\n\t\tthis.registerCommands(context);\n\t\tthis.registerToolbarItem(context);\n\t}\n\n\tprivate registerMarkSpec(context: PluginContext): void {\n\t\tcontext.registerMarkSpec({\n\t\t\ttype: 'textColor',\n\t\t\trank: 5,\n\t\t\tattrs: {\n\t\t\t\tcolor: { default: '' },\n\t\t\t},\n\t\t\ttoDOM(mark) {\n\t\t\t\tconst span = document.createElement('span');\n\t\t\t\tconst color = mark.attrs?.color ?? '';\n\t\t\t\tsetStyleProperty(span, 'color', color);\n\t\t\t\treturn span;\n\t\t\t},\n\t\t\ttoHTMLString: (mark, content) => {\n\t\t\t\tconst color: string = String(mark.attrs?.color ?? '');\n\t\t\t\tif (!color || !isValidCSSColor(color)) return content;\n\t\t\t\treturn `<span style=\"color: ${escapeHTML(color)}\">${content}</span>`;\n\t\t\t},\n\t\t\ttoHTMLStyle: (mark) => {\n\t\t\t\tconst color: string = String(mark.attrs?.color ?? '');\n\t\t\t\tif (!color || !isValidCSSColor(color)) return null;\n\t\t\t\treturn `color: ${escapeHTML(color)}`;\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 color: string = el.style.color;\n\t\t\t\t\t\tif (!color || !isValidCSSColor(color)) return false;\n\t\t\t\t\t\treturn { color };\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\tprivate registerCommands(context: PluginContext): void {\n\t\tcontext.registerCommand('removeTextColor', () => {\n\t\t\treturn removeColorMark(context, context.getState(), 'textColor');\n\t\t});\n\t}\n\n\tprivate registerToolbarItem(context: PluginContext): void {\n\t\tconst pathD =\n\t\t\t'M11 3L5.5 17h2.25l1.12-3h6.25l1.12 3h2.25L13 3h-2z' + 'm-1.38 9L12 5.67 14.38 12H9.62z';\n\t\tconst icon: string = [\n\t\t\t'<svg xmlns=\"http://www.w3.org/2000/svg\"',\n\t\t\t' viewBox=\"0 0 24 24\">',\n\t\t\t`<path d=\"${pathD}\"/>`,\n\t\t\t'<rect x=\"3\" y=\"19.5\" width=\"18\" height=\"3\"',\n\t\t\t' rx=\"0.5\" fill=\"#e53935\"/>',\n\t\t\t'</svg>',\n\t\t].join('');\n\n\t\tcontext.registerToolbarItem({\n\t\t\tid: 'textColor',\n\t\t\tgroup: 'format',\n\t\t\ticon,\n\t\t\tlabel: this.locale.label,\n\t\t\ttooltip: this.locale.tooltip,\n\t\t\tcommand: 'removeTextColor',\n\t\t\tpriority: 45,\n\t\t\tpopupType: 'custom',\n\t\t\tseparatorAfter: this.config.separatorAfter,\n\t\t\trenderPopup: (container, ctx, onClose) => {\n\t\t\t\trenderColorPickerPopup(container, ctx, {\n\t\t\t\t\tmarkType: 'textColor',\n\t\t\t\t\tcolors: this.colors,\n\t\t\t\t\tcolumns: 10,\n\t\t\t\t\tresetLabel: this.locale.resetLabel,\n\t\t\t\t\tresetCommand: 'removeTextColor',\n\t\t\t\t\tariaLabelPrefix: this.locale.ariaLabelPrefix,\n\t\t\t\t\tonClose,\n\t\t\t\t});\n\t\t\t},\n\t\t\tisActive: (state: EditorState) => isColorMarkActive(state, 'textColor'),\n\t\t});\n\t}\n}\n"],"names":["TEXT_COLOR_LOCALE_EN","label","tooltip","resetLabel","ariaLabelPrefix","TEXT_COLOR_LOCALES","en","de","es","fr","zh","ru","ar","hi","COLOR_PALETTE","TextColorPlugin","id","name","priority","config","colors","locale","this","resolveColors","context","resolvePluginLocale","registerStyleSheet","COLOR_PICKER_CSS","registerMarkSpec","registerCommands","registerToolbarItem","type","rank","attrs","color","default","mark","span","document","createElement","setStyleProperty","toHTMLString","content","String","isValidCSSColor","escapeHTML","toHTMLStyle","parseHTML","tag","getAttrs","el","style","sanitize","tags","registerCommand","removeColorMark","getState","icon","join","group","command","popupType","separatorAfter","renderPopup","container","ctx","onClose","renderColorPickerPopup","markType","columns","resetCommand","isActive","state","isColorMarkActive"],"mappings":";;;;;AAaO,MAAMA,IAAwC,EACpDC,OAAO,cACPC,SAAS,cACTC,YAAY,WACZC,iBAAiB,gBAoELC,IAAsD,EAClEC,IAAIN,GACJO,IAjEoD,EACpDN,OAAO,aACPC,SAAS,aACTC,YAAY,YACZC,iBAAiB,YAAA,GA8DjBI,IAzDoD,EACpDP,OAAO,kBACPC,SAAS,kBACTC,YAAY,kBACZC,iBAAiB,iBAAA,GAsDjBK,IAjDoD,EACpDR,OAAO,oBACPC,SAAS,oBACTC,YAAY,cACZC,iBAAiB,mBAAA,GA8CjBM,IAzCoD,EACpDT,OAAO,QACPC,SAAS,QACTC,YAAY,MACZC,iBAAiB,UAsCjBO,IAjCoD,EACpDV,OAAO,eACPC,SAAS,eACTC,YAAY,gBACZC,iBAAiB,iBA8BjBQ,IAzBoD,EACpDX,OAAO,YACPC,SAAS,YACTC,YAAY,WACZC,iBAAiB,cAsBjBS,IAjBoD,EACpDZ,OAAO,eACPC,SAAS,eACTC,YAAY,YACZC,iBAAiB,cAAA,EAAA,GCvCZU,IAAmC,CAExC,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA;AAKM,MAAMC,EAAAA;AAAAA,EACHC,K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B,EAAEA;UAIZkB,UAAU,EAAEC,MAAM,CAAC,MAAA,EAAA,EAAA,CAAA;AAAA,EAErB;AAAA,EAEQ,iBAAiB7B;AACxBA,IAAAA,GAAQ8B,gBAAgB,mBAAmB,MACnCC,EAAgB/B,IAASA,GAAQgC,SAAAA,GAAY,WAAA,CAAA;AAAA,EAEtD;AAAA,EAEQ,oBAAoBhC;AAC3B,UAEMiC,KAAe,CACpB,2CACA,yBACA,iGACA,8CACA,8BACA,QAAA,EACCC,KAAK,EAAA;AAEPlC,IAAAA,GAAQM,oBAAoB,EAC3Bd,IAAI,aACJ2C,OAAO,UACPF,MAAAA,IACAxD,OAAOqB,KAAKD,OAAOpB,OACnBC,SAASoB,KAAKD,OAAOnB,SACrB0D,SAAS,mBACT1C,UAAU,IACV2C,WAAW,UACXC,gBAAgBxC,KAAKH,OAAO2C,gBAC5BC,aAAa,CAACC,IAAWC,IAAKC,OAAAA;AAC7BC,QAAuBH,IAAWC,IAAK,EACtCG,UAAU,aACVhD,QAAQE,KAAKF,QACbiD,SAAS,IACTlE,YAAYmB,KAAKD,OAAOlB,YACxBmE,cAAc,mBACdlE,iBAAiBkB,KAAKD,OAAOjB,iBAC7B8D;OAGFK,UAAWC,CAAAA,OAAuBC,EAAkBD,IAAO,WAAA,EAAA,CAAA;AAAA,EAE7D;AAAA;"}
|
|
1
|
+
{"version":3,"file":"index-fx3KIap3.mjs","sources":["../../src/plugins/text-color/TextColorLocale.ts","../../src/plugins/text-color/TextColorPlugin.ts"],"sourcesContent":["/** Locale interface and default English locale for the TextColorPlugin. */\n\n// --- Locale Interface ---\n\nexport interface TextColorLocale {\n\treadonly label: string;\n\treadonly tooltip: string;\n\treadonly resetLabel: string;\n\treadonly ariaLabelPrefix: string;\n}\n\n// --- Default English Locale ---\n\nexport const TEXT_COLOR_LOCALE_EN: TextColorLocale = {\n\tlabel: 'Text Color',\n\ttooltip: 'Text Color',\n\tresetLabel: 'Default',\n\tariaLabelPrefix: 'Text color',\n};\n\n// --- German Locale ---\n\nexport const TEXT_COLOR_LOCALE_DE: TextColorLocale = {\n\tlabel: 'Textfarbe',\n\ttooltip: 'Textfarbe',\n\tresetLabel: 'Standard',\n\tariaLabelPrefix: 'Textfarbe',\n};\n\n// --- Spanish Locale ---\n\nexport const TEXT_COLOR_LOCALE_ES: TextColorLocale = {\n\tlabel: 'Color de texto',\n\ttooltip: 'Color de texto',\n\tresetLabel: 'Predeterminado',\n\tariaLabelPrefix: 'Color de texto',\n};\n\n// --- French Locale ---\n\nexport const TEXT_COLOR_LOCALE_FR: TextColorLocale = {\n\tlabel: 'Couleur du texte',\n\ttooltip: 'Couleur du texte',\n\tresetLabel: 'Par défaut',\n\tariaLabelPrefix: 'Couleur du texte',\n};\n\n// --- Chinese (Simplified) Locale ---\n\nexport const TEXT_COLOR_LOCALE_ZH: TextColorLocale = {\n\tlabel: '文字颜色',\n\ttooltip: '文字颜色',\n\tresetLabel: '默认',\n\tariaLabelPrefix: '文字颜色',\n};\n\n// --- Russian Locale ---\n\nexport const TEXT_COLOR_LOCALE_RU: TextColorLocale = {\n\tlabel: 'Цвет текста',\n\ttooltip: 'Цвет текста',\n\tresetLabel: 'По умолчанию',\n\tariaLabelPrefix: 'Цвет текста',\n};\n\n// --- Arabic Locale ---\n\nexport const TEXT_COLOR_LOCALE_AR: TextColorLocale = {\n\tlabel: 'لون النص',\n\ttooltip: 'لون النص',\n\tresetLabel: 'افتراضي',\n\tariaLabelPrefix: 'لون النص',\n};\n\n// --- Hindi Locale ---\n\nexport const TEXT_COLOR_LOCALE_HI: TextColorLocale = {\n\tlabel: 'टेक्स्ट रंग',\n\ttooltip: 'टेक्स्ट रंग',\n\tresetLabel: 'डिफ़ॉल्ट',\n\tariaLabelPrefix: 'टेक्स्ट रंग',\n};\n\n// --- Locale Map ---\n\nexport const TEXT_COLOR_LOCALES: Record<string, TextColorLocale> = {\n\ten: TEXT_COLOR_LOCALE_EN,\n\tde: TEXT_COLOR_LOCALE_DE,\n\tes: TEXT_COLOR_LOCALE_ES,\n\tfr: TEXT_COLOR_LOCALE_FR,\n\tzh: TEXT_COLOR_LOCALE_ZH,\n\tru: TEXT_COLOR_LOCALE_RU,\n\tar: TEXT_COLOR_LOCALE_AR,\n\thi: TEXT_COLOR_LOCALE_HI,\n};\n","/**\n * TextColorPlugin: registers a text color mark with attrs,\n * toolbar button with a color picker popup, and removeTextColor command.\n */\n\nimport { COLOR_PICKER_CSS } from '../../editor/styles/color-picker.js';\nimport { resolvePluginLocale } from '../../i18n/resolvePluginLocale.js';\nimport { escapeHTML } from '../../model/HTMLUtils.js';\nimport type { EditorState } from '../../state/EditorState.js';\nimport { setStyleProperty } from '../../style/StyleRuntime.js';\nimport type { Plugin, PluginContext } from '../Plugin.js';\nimport { isColorMarkActive, removeColorMark } from '../shared/ColorMarkOperations.js';\nimport { renderColorPickerPopup } from '../shared/ColorPickerPopup.js';\nimport { isValidCSSColor, resolveColors } from '../shared/ColorValidation.js';\nimport { TEXT_COLOR_LOCALES, type TextColorLocale } from './TextColorLocale.js';\n\n// --- Attribute Registry Augmentation ---\n\ndeclare module '../../model/AttrRegistry.js' {\n\tinterface MarkAttrRegistry {\n\t\ttextColor: { color: string };\n\t}\n}\n\n// --- Configuration ---\n\nexport interface TextColorConfig {\n\t/**\n\t * Restricts the color picker to a specific set of hex colors.\n\t * Each value must be a valid hex color code (`#RGB` or `#RRGGBB`).\n\t * Duplicates are removed automatically (case-insensitive).\n\t * When omitted, the full default palette is shown.\n\t */\n\treadonly colors?: readonly string[];\n\t/** When true, a separator is rendered after the textColor toolbar item. */\n\treadonly separatorAfter?: boolean;\n\treadonly locale?: TextColorLocale;\n}\n\n// --- Color Palette (Google Docs style: 10 columns x 7 rows) ---\n\nconst COLOR_PALETTE: readonly string[] = [\n\t// Row 1 — dark\n\t'#000000',\n\t'#434343',\n\t'#666666',\n\t'#999999',\n\t'#b7b7b7',\n\t'#cccccc',\n\t'#d9d9d9',\n\t'#efefef',\n\t'#f3f3f3',\n\t'#ffffff',\n\t// Row 2 — vivid\n\t'#980000',\n\t'#ff0000',\n\t'#ff9900',\n\t'#ffff00',\n\t'#00ff00',\n\t'#00ffff',\n\t'#4a86e8',\n\t'#0000ff',\n\t'#9900ff',\n\t'#ff00ff',\n\t// Row 3 — light 3\n\t'#e6b8af',\n\t'#f4cccc',\n\t'#fce5cd',\n\t'#fff2cc',\n\t'#d9ead3',\n\t'#d0e0e3',\n\t'#c9daf8',\n\t'#cfe2f3',\n\t'#d9d2e9',\n\t'#ead1dc',\n\t// Row 4 — light 2\n\t'#dd7e6b',\n\t'#ea9999',\n\t'#f9cb9c',\n\t'#ffe599',\n\t'#b6d7a8',\n\t'#a2c4c9',\n\t'#a4c2f4',\n\t'#9fc5e8',\n\t'#b4a7d6',\n\t'#d5a6bd',\n\t// Row 5 — light 1\n\t'#cc4125',\n\t'#e06666',\n\t'#f6b26b',\n\t'#ffd966',\n\t'#93c47d',\n\t'#76a5af',\n\t'#6d9eeb',\n\t'#6fa8dc',\n\t'#8e7cc3',\n\t'#c27ba0',\n\t// Row 6 — dark 1\n\t'#a61c00',\n\t'#cc0000',\n\t'#e69138',\n\t'#f1c232',\n\t'#6aa84f',\n\t'#45818e',\n\t'#3c78d8',\n\t'#3d85c6',\n\t'#674ea7',\n\t'#a64d79',\n\t// Row 7 — dark 2\n\t'#85200c',\n\t'#990000',\n\t'#b45f06',\n\t'#bf9000',\n\t'#38761d',\n\t'#134f5c',\n\t'#1155cc',\n\t'#0b5394',\n\t'#351c75',\n\t'#741b47',\n];\n\n// --- Plugin ---\n\nexport class TextColorPlugin implements Plugin {\n\treadonly id = 'textColor';\n\treadonly name = 'Text Color';\n\treadonly priority = 23;\n\n\tprivate readonly config: TextColorConfig;\n\tprivate readonly colors: readonly string[];\n\tprivate locale!: TextColorLocale;\n\n\tconstructor(config?: Partial<TextColorConfig>) {\n\t\tthis.config = { ...config };\n\t\tthis.colors = resolveColors(config?.colors, COLOR_PALETTE, 'TextColorPlugin');\n\t}\n\n\tinit(context: PluginContext): void {\n\t\tthis.locale = resolvePluginLocale(TEXT_COLOR_LOCALES, context, this.config.locale);\n\n\t\tcontext.registerStyleSheet(COLOR_PICKER_CSS);\n\t\tthis.registerMarkSpec(context);\n\t\tthis.registerCommands(context);\n\t\tthis.registerToolbarItem(context);\n\t}\n\n\tprivate registerMarkSpec(context: PluginContext): void {\n\t\tcontext.registerMarkSpec({\n\t\t\ttype: 'textColor',\n\t\t\trank: 5,\n\t\t\tattrs: {\n\t\t\t\tcolor: { default: '' },\n\t\t\t},\n\t\t\ttoDOM(mark) {\n\t\t\t\tconst span = document.createElement('span');\n\t\t\t\tconst color = mark.attrs?.color ?? '';\n\t\t\t\tsetStyleProperty(span, 'color', color);\n\t\t\t\treturn span;\n\t\t\t},\n\t\t\ttoHTMLString: (mark, content) => {\n\t\t\t\tconst color: string = String(mark.attrs?.color ?? '');\n\t\t\t\tif (!color || !isValidCSSColor(color)) return content;\n\t\t\t\treturn `<span style=\"color: ${escapeHTML(color)}\">${content}</span>`;\n\t\t\t},\n\t\t\ttoHTMLStyle: (mark) => {\n\t\t\t\tconst color: string = String(mark.attrs?.color ?? '');\n\t\t\t\tif (!color || !isValidCSSColor(color)) return null;\n\t\t\t\treturn `color: ${escapeHTML(color)}`;\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 color: string = el.style.color;\n\t\t\t\t\t\tif (!color || !isValidCSSColor(color)) return false;\n\t\t\t\t\t\treturn { color };\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\tprivate registerCommands(context: PluginContext): void {\n\t\tcontext.registerCommand('removeTextColor', () => {\n\t\t\treturn removeColorMark(context, context.getState(), 'textColor');\n\t\t});\n\t}\n\n\tprivate registerToolbarItem(context: PluginContext): void {\n\t\tconst pathD =\n\t\t\t'M11 3L5.5 17h2.25l1.12-3h6.25l1.12 3h2.25L13 3h-2z' + 'm-1.38 9L12 5.67 14.38 12H9.62z';\n\t\tconst icon: string = [\n\t\t\t'<svg xmlns=\"http://www.w3.org/2000/svg\"',\n\t\t\t' viewBox=\"0 0 24 24\">',\n\t\t\t`<path d=\"${pathD}\"/>`,\n\t\t\t'<rect x=\"3\" y=\"19.5\" width=\"18\" height=\"3\"',\n\t\t\t' rx=\"0.5\" fill=\"#e53935\"/>',\n\t\t\t'</svg>',\n\t\t].join('');\n\n\t\tcontext.registerToolbarItem({\n\t\t\tid: 'textColor',\n\t\t\tgroup: 'format',\n\t\t\ticon,\n\t\t\tlabel: this.locale.label,\n\t\t\ttooltip: this.locale.tooltip,\n\t\t\tcommand: 'removeTextColor',\n\t\t\tpriority: 45,\n\t\t\tpopupType: 'custom',\n\t\t\tseparatorAfter: this.config.separatorAfter,\n\t\t\trenderPopup: (container, ctx, onClose) => {\n\t\t\t\trenderColorPickerPopup(container, ctx, {\n\t\t\t\t\tmarkType: 'textColor',\n\t\t\t\t\tcolors: this.colors,\n\t\t\t\t\tcolumns: 10,\n\t\t\t\t\tresetLabel: this.locale.resetLabel,\n\t\t\t\t\tresetCommand: 'removeTextColor',\n\t\t\t\t\tariaLabelPrefix: this.locale.ariaLabelPrefix,\n\t\t\t\t\tonClose,\n\t\t\t\t});\n\t\t\t},\n\t\t\tisActive: (state: EditorState) => isColorMarkActive(state, 'textColor'),\n\t\t});\n\t}\n}\n"],"names":["TEXT_COLOR_LOCALE_EN","label","tooltip","resetLabel","ariaLabelPrefix","TEXT_COLOR_LOCALES","en","de","es","fr","zh","ru","ar","hi","COLOR_PALETTE","TextColorPlugin","id","name","priority","config","colors","locale","this","resolveColors","context","resolvePluginLocale","registerStyleSheet","COLOR_PICKER_CSS","registerMarkSpec","registerCommands","registerToolbarItem","type","rank","attrs","color","default","mark","span","document","createElement","setStyleProperty","toHTMLString","content","String","isValidCSSColor","escapeHTML","toHTMLStyle","parseHTML","tag","getAttrs","el","style","sanitize","tags","registerCommand","removeColorMark","getState","icon","join","group","command","popupType","separatorAfter","renderPopup","container","ctx","onClose","renderColorPickerPopup","markType","columns","resetCommand","isActive","state","isColorMarkActive"],"mappings":";;;;;AAaO,MAAMA,IAAwC,EACpDC,OAAO,cACPC,SAAS,cACTC,YAAY,WACZC,iBAAiB,gBAoELC,IAAsD,EAClEC,IAAIN,GACJO,IAjEoD,EACpDN,OAAO,aACPC,SAAS,aACTC,YAAY,YACZC,iBAAiB,YAAA,GA8DjBI,IAzDoD,EACpDP,OAAO,kBACPC,SAAS,kBACTC,YAAY,kBACZC,iBAAiB,iBAAA,GAsDjBK,IAjDoD,EACpDR,OAAO,oBACPC,SAAS,oBACTC,YAAY,cACZC,iBAAiB,mBAAA,GA8CjBM,IAzCoD,EACpDT,OAAO,QACPC,SAAS,QACTC,YAAY,MACZC,iBAAiB,UAsCjBO,IAjCoD,EACpDV,OAAO,eACPC,SAAS,eACTC,YAAY,gBACZC,iBAAiB,iBA8BjBQ,IAzBoD,EACpDX,OAAO,YACPC,SAAS,YACTC,YAAY,WACZC,iBAAiB,cAsBjBS,IAjBoD,EACpDZ,OAAO,eACPC,SAAS,eACTC,YAAY,YACZC,iBAAiB,cAAA,EAAA,GCvCZU,IAAmC,CAExC,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA;AAKM,MAAMC,EAAAA;AAAAA,EACHC,KAAK;AAAA,EACLC,OAAO;AAAA,EACPC,WAAW;AAAA,EAEHC;AAAAA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