@morfira-dev/wysiwyg-core 1.5.1 → 1.6.0
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/chunk-X5IUYCDN.js +2 -0
- package/dist/chunk-X5IUYCDN.js.map +7 -0
- package/dist/chunk-YFIJ4ED5.js +2 -0
- package/dist/chunk-YFIJ4ED5.js.map +7 -0
- package/dist/commands/index.d.ts +5 -0
- package/dist/commands/internal-types.d.ts +18 -0
- package/dist/commands/types.d.ts +25 -0
- package/dist/document/index.d.ts +3 -2
- package/dist/document/internal-types.d.ts +2 -0
- package/dist/document/security.d.ts +1 -0
- package/dist/editor/html-snapshots.d.ts +1 -1
- package/dist/editor/types.d.ts +12 -1
- package/dist/events/types.d.ts +2 -0
- package/dist/formatting/index.d.ts +2 -1
- package/dist/formatting/links.d.ts +2 -1
- package/dist/formatting/local-inline.d.ts +2 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +4 -4
- package/dist/input/block-boundaries.d.ts +3 -0
- package/dist/input/index.d.ts +1 -0
- package/dist/localization/index.d.ts +7 -0
- package/dist/localization/messages.d.ts +11 -0
- package/dist/localization/types.d.ts +8 -0
- package/dist/private-editor-messages.js +2 -0
- package/dist/private-editor-messages.js.map +7 -0
- package/dist/private-toolbar-messages.js +2 -0
- package/dist/private-toolbar-messages.js.map +7 -0
- package/dist/schema/index.d.ts +3 -0
- package/dist/schema/internal-types.d.ts +9 -0
- package/dist/schema/types.d.ts +32 -0
- package/dist/ui/toolbar/index.d.ts +1 -1
- package/dist/ui/toolbar/messages.d.ts +32 -0
- package/dist/ui/toolbar/types.d.ts +5 -0
- package/package.json +1 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var o=Object.freeze({en:Object.freeze({"toolbar.label":"Formatting","toolbar.undo":"Undo","toolbar.redo":"Redo","toolbar.bold":"Bold","toolbar.italic":"Italic","toolbar.underline":"Underline","toolbar.header":"Heading","toolbar.bulletList":"Bulleted list","toolbar.orderedList":"Numbered list","toolbar.indent":"Increase indent","toolbar.outdent":"Decrease indent","toolbar.blockquote":"Block quote","toolbar.clear":"Clear formatting"}),ru:Object.freeze({"toolbar.label":"\u0424\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435","toolbar.undo":"\u041E\u0442\u043C\u0435\u043D\u0438\u0442\u044C","toolbar.redo":"\u041F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u044C","toolbar.bold":"\u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439","toolbar.italic":"\u041A\u0443\u0440\u0441\u0438\u0432","toolbar.underline":"\u041F\u043E\u0434\u0447\u0451\u0440\u043A\u043D\u0443\u0442\u044B\u0439","toolbar.header":"\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A","toolbar.bulletList":"\u041C\u0430\u0440\u043A\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A","toolbar.orderedList":"\u041D\u0443\u043C\u0435\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A","toolbar.indent":"\u0423\u0432\u0435\u043B\u0438\u0447\u0438\u0442\u044C \u043E\u0442\u0441\u0442\u0443\u043F","toolbar.outdent":"\u0423\u043C\u0435\u043D\u044C\u0448\u0438\u0442\u044C \u043E\u0442\u0441\u0442\u0443\u043F","toolbar.blockquote":"\u0426\u0438\u0442\u0430\u0442\u0430","toolbar.clear":"\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C \u0444\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435"})});export{o as a};
|
|
2
|
+
//# sourceMappingURL=chunk-X5IUYCDN.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/ui/toolbar/messages.ts"],
|
|
4
|
+
"sourcesContent": ["export const toolbarMessages = /* @__PURE__ */ Object.freeze({\n en: /* @__PURE__ */ Object.freeze({\n 'toolbar.label': 'Formatting',\n 'toolbar.undo': 'Undo',\n 'toolbar.redo': 'Redo',\n 'toolbar.bold': 'Bold',\n 'toolbar.italic': 'Italic',\n 'toolbar.underline': 'Underline',\n 'toolbar.header': 'Heading',\n 'toolbar.bulletList': 'Bulleted list',\n 'toolbar.orderedList': 'Numbered list',\n 'toolbar.indent': 'Increase indent',\n 'toolbar.outdent': 'Decrease indent',\n 'toolbar.blockquote': 'Block quote',\n 'toolbar.clear': 'Clear formatting',\n }),\n ru: /* @__PURE__ */ Object.freeze({\n 'toolbar.label': '\u0424\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435',\n 'toolbar.undo': '\u041E\u0442\u043C\u0435\u043D\u0438\u0442\u044C',\n 'toolbar.redo': '\u041F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u044C',\n 'toolbar.bold': '\u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439',\n 'toolbar.italic': '\u041A\u0443\u0440\u0441\u0438\u0432',\n 'toolbar.underline': '\u041F\u043E\u0434\u0447\u0451\u0440\u043A\u043D\u0443\u0442\u044B\u0439',\n 'toolbar.header': '\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A',\n 'toolbar.bulletList': '\u041C\u0430\u0440\u043A\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A',\n 'toolbar.orderedList': '\u041D\u0443\u043C\u0435\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A',\n 'toolbar.indent': '\u0423\u0432\u0435\u043B\u0438\u0447\u0438\u0442\u044C \u043E\u0442\u0441\u0442\u0443\u043F',\n 'toolbar.outdent': '\u0423\u043C\u0435\u043D\u044C\u0448\u0438\u0442\u044C \u043E\u0442\u0441\u0442\u0443\u043F',\n 'toolbar.blockquote': '\u0426\u0438\u0442\u0430\u0442\u0430',\n 'toolbar.clear': '\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C \u0444\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435',\n }),\n});\n"],
|
|
5
|
+
"mappings": "AAAO,IAAMA,EAAkC,OAAO,OAAO,CAC3D,GAAoB,OAAO,OAAO,CAChC,gBAAiB,aACjB,eAAgB,OAChB,eAAgB,OAChB,eAAgB,OAChB,iBAAkB,SAClB,oBAAqB,YACrB,iBAAkB,UAClB,qBAAsB,gBACtB,sBAAuB,gBACvB,iBAAkB,kBAClB,kBAAmB,kBACnB,qBAAsB,cACtB,gBAAiB,kBACnB,CAAC,EACD,GAAoB,OAAO,OAAO,CAChC,gBAAiB,uFACjB,eAAgB,mDAChB,eAAgB,yDAChB,eAAgB,+DAChB,iBAAkB,uCAClB,oBAAqB,2EACrB,iBAAkB,yDAClB,qBAAsB,sHACtB,sBAAuB,gHACvB,iBAAkB,8FAClB,kBAAmB,8FACnB,qBAAsB,uCACtB,gBAAiB,uIACnB,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["toolbarMessages"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var e=Object.freeze({en:Object.freeze({"editor.label":"Text editor","editor.placeholder":"Start writing\u2026"}),ru:Object.freeze({"editor.label":"\u0422\u0435\u043A\u0441\u0442\u043E\u0432\u044B\u0439 \u0440\u0435\u0434\u0430\u043A\u0442\u043E\u0440","editor.placeholder":"\u041D\u0430\u0447\u043D\u0438\u0442\u0435 \u043F\u0438\u0441\u0430\u0442\u044C\u2026"})});export{e as a};
|
|
2
|
+
//# sourceMappingURL=chunk-YFIJ4ED5.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/localization/messages.ts"],
|
|
4
|
+
"sourcesContent": ["/** Core-only copy. Optional UI and plugins own their dictionaries. */\nexport const editorMessages = /* @__PURE__ */ Object.freeze({\n en: /* @__PURE__ */ Object.freeze({\n 'editor.label': 'Text editor',\n 'editor.placeholder': 'Start writing\u2026',\n }),\n ru: /* @__PURE__ */ Object.freeze({\n 'editor.label': '\u0422\u0435\u043A\u0441\u0442\u043E\u0432\u044B\u0439 \u0440\u0435\u0434\u0430\u043A\u0442\u043E\u0440',\n 'editor.placeholder': '\u041D\u0430\u0447\u043D\u0438\u0442\u0435 \u043F\u0438\u0441\u0430\u0442\u044C\u2026',\n }),\n});\n"],
|
|
5
|
+
"mappings": "AACO,IAAMA,EAAiC,OAAO,OAAO,CAC1D,GAAoB,OAAO,OAAO,CAChC,eAAgB,cAChB,qBAAsB,qBACxB,CAAC,EACD,GAAoB,OAAO,OAAO,CAChC,eAAgB,0GAChB,qBAAsB,uFACxB,CAAC,CACH,CAAC",
|
|
6
|
+
"names": ["editorMessages"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { CommandRegistry, CommandRegistryOptions } from './internal-types.js';
|
|
2
|
+
import type { EditorCommand } from './types.js';
|
|
3
|
+
export type { EditorCommand, EditorCommandDefinition, EditorCommandState, EditorCommands } from './types.js';
|
|
4
|
+
export declare const createEditorCommand: <T>(name: string) => EditorCommand<T>;
|
|
5
|
+
export declare const createCommandRegistry: (options: CommandRegistryOptions) => CommandRegistry;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Editor } from '../editor/types.js';
|
|
2
|
+
import type { EditorCommands } from './types.js';
|
|
3
|
+
export interface CommandRegistryOptions {
|
|
4
|
+
editor: () => Editor;
|
|
5
|
+
isComposing: () => boolean;
|
|
6
|
+
assertActive: () => void;
|
|
7
|
+
}
|
|
8
|
+
export interface CommandRegistry {
|
|
9
|
+
commands: EditorCommands;
|
|
10
|
+
destroy: () => void;
|
|
11
|
+
}
|
|
12
|
+
export interface RegisteredCommand {
|
|
13
|
+
validate: (payload: unknown) => unknown;
|
|
14
|
+
execute: (editor: Editor, payload: unknown) => unknown;
|
|
15
|
+
isEnabled?: (editor: Editor) => boolean;
|
|
16
|
+
isActive?: (editor: Editor) => boolean;
|
|
17
|
+
isMixed?: (editor: Editor) => boolean;
|
|
18
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { Editor } from '../editor/types.js';
|
|
2
|
+
declare const commandPayload: unique symbol;
|
|
3
|
+
/** Object identity selects the command; the name is diagnostic only. */
|
|
4
|
+
export interface EditorCommand<T> {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly [commandPayload]: (payload: T) => T;
|
|
7
|
+
}
|
|
8
|
+
export interface EditorCommandDefinition<T> {
|
|
9
|
+
readonly validate: (payload: unknown) => T;
|
|
10
|
+
readonly execute: (editor: Editor, payload: T) => void;
|
|
11
|
+
readonly isEnabled?: (editor: Editor) => boolean;
|
|
12
|
+
readonly isActive?: (editor: Editor) => boolean;
|
|
13
|
+
readonly isMixed?: (editor: Editor) => boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface EditorCommandState {
|
|
16
|
+
readonly enabled: boolean;
|
|
17
|
+
readonly active: boolean;
|
|
18
|
+
readonly mixed: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface EditorCommands {
|
|
21
|
+
register<T>(command: EditorCommand<T>, definition: EditorCommandDefinition<NoInfer<T>>): () => void;
|
|
22
|
+
execute<T>(command: EditorCommand<T>, payload: NoInfer<T>): boolean;
|
|
23
|
+
getState<T>(command: EditorCommand<T>): EditorCommandState;
|
|
24
|
+
}
|
|
25
|
+
export {};
|
package/dist/document/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import type { DocumentAttributeResolver } from './internal-types.js';
|
|
1
2
|
import type { EditorDocument } from './types.js';
|
|
2
3
|
export type { DocumentTag, TextNode, ElementNode, DocumentNode, EditorDocument } from './types.js';
|
|
3
4
|
/** Versioned, framework-independent document tree. Only supported HTML semantics are stored. */
|
|
4
5
|
export declare const documentTags: readonly ["p", "h1", "h2", "h3", "h4", "h5", "h6", "blockquote", "pre", "code", "strong", "em", "u", "s", "sub", "sup", "a", "span", "br", "hr", "ul", "ol", "li", "img", "figure", "figcaption", "table", "caption", "colgroup", "col", "thead", "tbody", "tfoot", "tr", "td", "th"];
|
|
5
|
-
export declare const parseHTML: (html: string) => EditorDocument;
|
|
6
|
-
export declare const validateDocument: (input: unknown) => EditorDocument;
|
|
6
|
+
export declare const parseHTML: (html: string, resolve?: DocumentAttributeResolver) => EditorDocument;
|
|
7
|
+
export declare const validateDocument: (input: unknown, resolve?: DocumentAttributeResolver) => EditorDocument;
|
|
7
8
|
export declare const renderDocument: (value: EditorDocument) => DocumentFragment;
|
|
8
9
|
export declare const documentHTML: (value: EditorDocument) => string;
|
|
9
10
|
export declare const sanitizeHTML: (html: string) => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const safeURL: (value: string, image: boolean) => string | undefined;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/** Reuse only a successfully validated string for the exact current serialized DOM. */
|
|
2
|
-
export declare const createHTMLSnapshots: (surface: HTMLElement) => {
|
|
2
|
+
export declare const createHTMLSnapshots: (surface: HTMLElement, sanitize?: (html: string) => string) => {
|
|
3
3
|
read: () => string;
|
|
4
4
|
clear: () => void;
|
|
5
5
|
};
|
package/dist/editor/types.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import type { DocumentSchema, SchemaNodeSpec } from '../schema/types.js';
|
|
2
|
+
import type { EditorCommands } from '../commands/types.js';
|
|
1
3
|
import type { EditorDocument } from '../document/index.js';
|
|
2
4
|
import type { SelectionBookmark, TextSelection } from '../selection/index.js';
|
|
3
5
|
import type { EditorEvents } from '../events/types.js';
|
|
6
|
+
import type { EditorLocale, EditorTranslations } from '../localization/types.js';
|
|
4
7
|
export interface EditorChange {
|
|
5
8
|
html: string;
|
|
6
9
|
text: string;
|
|
@@ -8,14 +11,18 @@ export interface EditorChange {
|
|
|
8
11
|
}
|
|
9
12
|
export interface EditorPlugin {
|
|
10
13
|
name: string;
|
|
14
|
+
schema?: readonly SchemaNodeSpec[];
|
|
11
15
|
setup(editor: Editor): void | (() => void);
|
|
12
16
|
}
|
|
13
17
|
export interface EditorOptions {
|
|
18
|
+
locale?: string;
|
|
19
|
+
translations?: EditorTranslations;
|
|
14
20
|
value?: string;
|
|
15
21
|
placeholder?: string;
|
|
16
22
|
readOnly?: boolean;
|
|
17
23
|
label?: string;
|
|
18
24
|
plugins?: EditorPlugin[];
|
|
25
|
+
schema?: readonly SchemaNodeSpec[];
|
|
19
26
|
onChange?: (change: EditorChange) => void;
|
|
20
27
|
historyLimit?: number;
|
|
21
28
|
}
|
|
@@ -23,6 +30,10 @@ export interface Editor {
|
|
|
23
30
|
readonly element: HTMLElement;
|
|
24
31
|
readonly surface: HTMLElement;
|
|
25
32
|
readonly events: EditorEvents;
|
|
33
|
+
readonly schema: DocumentSchema;
|
|
34
|
+
readonly commands: EditorCommands;
|
|
35
|
+
getLocale(): EditorLocale;
|
|
36
|
+
setLocale(locale: string, translations?: EditorTranslations): void;
|
|
26
37
|
getHTML(): string;
|
|
27
38
|
getText(): string;
|
|
28
39
|
getJSON(): EditorDocument;
|
|
@@ -40,7 +51,7 @@ export interface Editor {
|
|
|
40
51
|
redo(): void;
|
|
41
52
|
canUndo(): boolean;
|
|
42
53
|
canRedo(): boolean;
|
|
43
|
-
/** Execute
|
|
54
|
+
/** Execute one undoable plugin edit. Read-only and active composition block it. */
|
|
44
55
|
transact(mutate: (surface: HTMLElement) => void): void;
|
|
45
56
|
providePlugin<T>(name: string, api: T): () => void;
|
|
46
57
|
getPlugin<T>(name: string): T | undefined;
|
package/dist/events/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { EditorChange } from '../editor/types.js';
|
|
2
2
|
import type { TextSelection } from '../selection/index.js';
|
|
3
|
+
import type { EditorLocale } from '../localization/types.js';
|
|
3
4
|
declare const eventType: unique symbol;
|
|
4
5
|
export interface PluginEvent<T> {
|
|
5
6
|
readonly name: string;
|
|
@@ -9,6 +10,7 @@ export interface EditorEventMap {
|
|
|
9
10
|
change: EditorChange;
|
|
10
11
|
selectionchange: TextSelection | undefined;
|
|
11
12
|
readonlychange: boolean;
|
|
13
|
+
localechange: EditorLocale;
|
|
12
14
|
destroy: void;
|
|
13
15
|
}
|
|
14
16
|
export interface EditorEvents {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
+
import type { DocumentSchema } from '../schema/types.js';
|
|
1
2
|
import type { DocumentTag } from '../document/index.js';
|
|
2
3
|
export declare const inlineFormats: Record<string, DocumentTag>;
|
|
3
4
|
export declare const readFormats: (root: HTMLElement) => Record<string, unknown>;
|
|
4
|
-
export declare const applyFormat: (root: HTMLElement, name: string, value: unknown) => void;
|
|
5
|
+
export declare const applyFormat: (root: HTMLElement, name: string, value: unknown, schema?: DocumentSchema) => void;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import type { DocumentSchema } from '../schema/types.js';
|
|
2
|
+
export declare const applyLink: (root: HTMLElement, value: unknown, schema?: DocumentSchema) => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DocumentSchema } from '../schema/types.js';
|
|
1
2
|
import type { DocumentTag } from '../document/index.js';
|
|
2
3
|
/** Transform one schema-validated leaf while keeping unrelated editor DOM connected. */
|
|
3
|
-
export declare const applyLocalInline: (root: HTMLElement, range: Range, tag: DocumentTag, enabled: boolean) => boolean;
|
|
4
|
+
export declare const applyLocalInline: (root: HTMLElement, range: Range, tag: DocumentTag, enabled: boolean, schema?: DocumentSchema) => boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -8,3 +8,11 @@ export { createToolbar } from './ui/toolbar/index.js';
|
|
|
8
8
|
export type { ToolbarAction, ToolbarOptions } from './ui/toolbar/types.js';
|
|
9
9
|
export { createPluginEvent } from './events/index.js';
|
|
10
10
|
export type { EditorEvents, EditorEventMap, PluginEvent } from './events/types.js';
|
|
11
|
+
export { localize, editorMessages } from './localization/index.js';
|
|
12
|
+
export type { EditorLocale, EditorTranslations, LocaleDictionaries, EditorTranslationKey } from './localization/types.js';
|
|
13
|
+
export { toolbarMessages } from './ui/toolbar/messages.js';
|
|
14
|
+
export type { ToolbarTranslationKey } from './ui/toolbar/types.js';
|
|
15
|
+
export { createDocumentSchema } from './schema/index.js';
|
|
16
|
+
export type { DocumentSchema, SchemaNodeSpec, SchemaAttributeSpec } from './schema/types.js';
|
|
17
|
+
export { createEditorCommand } from './commands/index.js';
|
|
18
|
+
export type { EditorCommand, EditorCommandDefinition, EditorCommandState, EditorCommands } from './commands/types.js';
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var ut=["p","h1","h2","h3","h4","h5","h6","blockquote","pre","code","strong","em","u","s","sub","sup","a","span","br","hr","ul","ol","li","img","figure","figcaption","table","caption","colgroup","col","thead","tbody","tfoot","tr","td","th"],De=new Set(ut),ft=new Set(["script","style","iframe","object","embed","svg","math","template","form","input","button","textarea","select","noscript","link","meta","base"]),mt={b:"strong",i:"em",strike:"s",div:"p"},Oe=1e5,Re=100,pt=(e,r)=>{let t=e.trim();if(!t||/[\u0000-\u0020\u007f]/.test(t))return;let n=/^([a-z][a-z\d+.-]*):/i.exec(t)?.[1].toLowerCase();if(!(n&&!(r?["http","https"]:["http","https","mailto","tel"]).includes(n))&&!(t.startsWith("\\")||t.startsWith("//")))return t},ht=e=>{let r=[];for(let t of e.split(";")){let n=t.indexOf(":");if(n<0)continue;let o=t.slice(0,n).trim().toLowerCase(),s=t.slice(n+1).trim().toLowerCase(),i=/^(#[a-f\d]{3,8}|[a-z]{1,24}|(?:rgb|rgba|hsl|hsla)\([\d\s.,%+-]+\))$/,c=/^(?:\d{1,4}(?:\.\d{1,3})?)(?:px|%|em|rem)$/;(["color","background-color","border-color"].includes(o)?i.test(s):["width","height","font-size"].includes(o)?c.test(s):o==="text-align"?["left","center","right","justify"].includes(s):o==="font-weight"?/^(bold|normal|[1-9]00)$/.test(s):o==="font-style"?["italic","normal"].includes(s):o==="text-decoration"?/^(underline|line-through|none)$/.test(s):!1)&&r.push(`${o}: ${s}`)}return r.join("; ")},je=(e,r)=>{let t={};for(let[n,o]of Object.entries(r))if(!(typeof o!="string"||o.length>2e4))if(n==="style"){let s=ht(o);s&&(t.style=s)}else if(n==="title"||e==="img"&&n==="alt")t[n]=o;else if(e==="a"&&n==="href"||e==="img"&&n==="src"){let s=pt(o,e==="img");s&&(t[n]=s)}else if(["td","th"].includes(e)&&["rowspan","colspan"].includes(n)||["img","col","table"].includes(e)&&["width","height","span"].includes(n))/^\d{1,4}$/.test(o)&&Number(o)>0&&Number(o)<=1e3&&(t[n]=o);else if(e==="a"&&n==="target"&&["_self","_blank"].includes(o))t.target=o;else if(e==="a"&&n==="rel"){let s=[...new Set(o.toLowerCase().split(/\s+/).filter(i=>["noopener","noreferrer"].includes(i)))];s.length&&(t.rel=s.join(" "))}else e==="th"&&n==="scope"&&["row","col","rowgroup","colgroup"].includes(o)&&(t[n]=o);if(e==="img"&&(t.width||t.height)){let n=["width","height"].filter(s=>t[s]),o=(t.style??"").split(";").map(s=>s.trim()).filter(s=>s&&!n.includes(s.slice(0,s.indexOf(":")).trim()));t.style=[...o,...n.map(s=>`${s}: ${t[s]}px`)].join("; ")}return e==="a"&&t.target==="_blank"&&(t.rel="noopener noreferrer"),t},Ie=(e,r,t)=>{if(++t.count>Oe||r>Re)throw new RangeError("Document exceeds structural limits.");if(e.nodeType===3)return[{type:"text",text:e.textContent??""}];if(e.nodeType!==1)return[];let n=e,o=n.localName.toLowerCase();if(n.namespaceURI!=="http://www.w3.org/1999/xhtml"||ft.has(o))return[];let s=[...n.childNodes].flatMap(a=>Ie(a,r+1,t)),i=mt[o]??o;if(!De.has(i))return s;let c=je(i,Object.fromEntries([...n.attributes].map(a=>[a.name,a.value])));return i==="img"&&!c.src?[]:[{type:"element",tag:i,attributes:c,children:s}]},S=e=>{if(e.length>5e6)throw new RangeError("HTML exceeds the document size limit.");let r=document.createElement("template");r.innerHTML=e;let t={count:0};return{version:1,children:[...r.content.childNodes].flatMap(n=>Ie(n,0,t))}},fe=e=>{if(!e||typeof e!="object"||!("version"in e)||e.version!==1||!("children"in e)||!Array.isArray(e.children))throw new TypeError("Expected a version 1 document.");let r=0,t=0,n=(o,s)=>{if(++r>Oe||s>Re)throw new RangeError("Document exceeds structural limits.");if(!o||typeof o!="object"||!("type"in o))throw new TypeError("Invalid document node.");if(o.type==="text"&&"text"in o&&typeof o.text=="string"){if(t+=o.text.length,t>5e6)throw new RangeError("Document text exceeds size limit.");return{type:"text",text:o.text}}if(o.type!=="element"||!("tag"in o)||typeof o.tag!="string"||!De.has(o.tag)||!("children"in o)||!Array.isArray(o.children))throw new TypeError("Invalid document element.");let i="attributes"in o&&o.attributes&&typeof o.attributes=="object"&&!Array.isArray(o.attributes)?o.attributes:{};return{type:"element",tag:o.tag,attributes:je(o.tag,i),children:o.children.map(c=>n(c,s+1))}};return{version:1,children:e.children.map(o=>n(o,0))}},J=e=>{let r=document.createDocumentFragment(),t=(n,o)=>{if(o.type==="text"){n.appendChild(document.createTextNode(o.text));return}let s=document.createElement(o.tag);for(let[i,c]of Object.entries(o.attributes))s.setAttribute(i,c);for(let i of o.children)t(s,i);n.appendChild(s)};for(let n of e.children)t(r,n);return r},I=e=>{let r=document.createElement("div");return r.append(J(e)),r.innerHTML},xe=e=>I(S(e));var N=e=>{let r=e.ownerDocument.getSelection();if(!r?.rangeCount)return;let t=r.getRangeAt(0);if(!(!e.contains(t.startContainer)||!e.contains(t.endContainer)))return t.cloneRange()},Be=(e,r)=>{let t=[],n=r;for(;n!==e&&n.parentNode;)t.unshift([...n.parentNode.childNodes].indexOf(n)),n=n.parentNode;return t},ee=e=>{let r=N(e);if(!r)return;let t=e.ownerDocument.getSelection();return{start:Be(e,r.startContainer),startOffset:r.startOffset,end:Be(e,r.endContainer),endOffset:r.endOffset,backward:!r.collapsed&&t.anchorNode===r.endContainer&&t.anchorOffset===r.endOffset}},U=(e,r)=>{if(!r)return;let t=d=>d.reduce((u,f)=>u.childNodes[f]??u,e),n=t(r.start),o=t(r.end),s=(d,u)=>Math.min(u,d.nodeType===3?d.textContent?.length??0:d.childNodes.length),i=e.ownerDocument.getSelection();if(!i)return;let c=s(n,r.startOffset),a=s(o,r.endOffset);r.backward?i.setBaseAndExtent(o,a,n,c):i.setBaseAndExtent(n,c,o,a)},H=e=>{let r=N(e);if(!r)return;let t=e.ownerDocument.createRange();return t.selectNodeContents(e),t.setEnd(r.startContainer,r.startOffset),{index:t.toString().length,length:r.toString().length}},C=(e,r,t=0)=>{if(![r,t].every(g=>Number.isInteger(g)&&g>=0))throw new RangeError("Selection offsets must be non-negative integers.");let n=e.ownerDocument.createTreeWalker(e,4),o=[],s;for(;s=n.nextNode();)o.push(s);let i=g=>{for(let b of o){if(g<=b.length)return[b,g];g-=b.length}let m=o.at(-1);return m?[m,m.length]:[e.querySelector("p,h1,h2,h3,h4,h5,h6,li,blockquote,pre")??e,0]},[c,a]=i(r),[d,u]=i(r+t),f=e.ownerDocument.createRange();f.setStart(c,a),f.setEnd(d,u),e.focus({preventScroll:!0});let h=e.ownerDocument.getSelection();h?.removeAllRanges(),h?.addRange(f)},me=(e,r=!1)=>{let t=e.ownerDocument.createRange();t.selectNodeContents(e),t.collapse(!r);let n=e.ownerDocument.getSelection();n?.removeAllRanges(),n?.addRange(t)},P=(e,r)=>{let t=N(e);if(!t)return;let n=e.ownerDocument.getSelection(),o=!t.collapsed&&n.anchorNode===t.endContainer&&n.anchorOffset===t.endOffset,s=e.ownerDocument.createComment("mw-start"),i=t.collapsed?void 0:e.ownerDocument.createComment("mw-end");if(i){let a=t.cloneRange();a.collapse(!1),a.insertNode(i)}let c=t.cloneRange();c.collapse(!0),c.insertNode(s);try{if(r(),e.contains(s)&&(!i||e.contains(i))){let a=e.ownerDocument.createRange();a.setStartBefore(s),i?a.setEndBefore(i):a.collapse(!0),s.remove(),i?.remove(),e.normalize(),o?n.setBaseAndExtent(a.endContainer,a.endOffset,a.startContainer,a.startOffset):(n.removeAllRanges(),n.addRange(a))}}finally{s.remove(),i?.remove()}};var Fe="p,h1,h2,h3,h4,h5,h6,blockquote,pre,li",D=e=>!!e&&/^(ul|ol)$/.test(e.localName),gt=e=>e instanceof Element?e:e.parentElement,re=(e,r,t=!0)=>{let n=gt(r),o=n?.closest("li"),s=(t&&o&&e.contains(o)?o:void 0)??n?.closest(Fe);return s&&e.contains(s)?s:void 0},bt=(e,r)=>{let t=r.ownerDocument.createRange();r.nodeType===3?t.selectNodeContents(r):t.selectNode(r);let n=e.cloneRange();n.collapse(!0);let o=e.cloneRange();o.collapse(!1);let s=t.cloneRange();s.collapse(!0);let i=t.cloneRange();return i.collapse(!1),n.compareBoundaryPoints(Range.START_TO_START,i)<0&&o.compareBoundaryPoints(Range.START_TO_START,s)>0},X=(e,r=N(e),t=!0)=>{if(!r)return[];if(r.collapsed){let i=re(e,r.startContainer,t);return i?[i]:[]}let n=new Set,o=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),s;for(;s=o.nextNode();)if(!(!(s.nodeType===3&&s.textContent)&&!(s instanceof Element&&/^(br|img|hr)$/.test(s.localName)))&&bt(r,s)){let i=re(e,s,t);i&&n.add(i)}return[...e.querySelectorAll(Fe)].filter(i=>n.has(i))},$e=e=>e.filter(r=>!e.some(t=>t!==r&&t.contains(r))),ze=e=>{let r=$e(X(e));if(!r.length||r.some(o=>o.localName!=="li"||!D(o.parentElement)))return[];let t=r[0].parentElement;if(r.some(o=>o.parentElement!==t))return[];let n=[...t.children];return n.indexOf(r.at(-1))-n.indexOf(r[0])+1!==r.length?[]:r},Pe=(e,r)=>{let t=0,n=r.parentElement;for(;n&&n!==e;)D(n)&&t++,n=n.parentElement;return t},Ke=(e,r)=>!!e&&e.localName===r.localName&&D(e)&&e.getAttribute("style")===r.getAttribute("style"),te=e=>{for(let r of[...e.querySelectorAll("ul,ol")]){if(!e.contains(r))continue;let t=r.previousSibling;t instanceof Element&&Ke(t,r)&&(t.append(...r.childNodes),r.remove())}},_e=(e,r)=>{let t=e.parentElement,n=t.cloneNode(!1);for(;e.nextSibling;)n.append(e.nextSibling);e.remove(),t.after(...r,...n.childNodes.length?[n]:[]),t.childNodes.length||t.remove()},ne=e=>[...e.childNodes].filter(r=>!(r instanceof Element&&D(r))),Ue=(e,r=!1)=>{let t=()=>{let c=document.createElement("p");return e.hasAttribute("style")&&c.setAttribute("style",e.getAttribute("style")),c},n=t(),o=[...e.children].filter(D),s=ne(e),i=[];for(let c of s)r&&c instanceof HTMLElement&&/^(p|h[1-6]|blockquote|pre)$/.test(c.localName)?n.append(...c.childNodes):c instanceof HTMLElement&&/^(p|h[1-6]|blockquote|pre)$/.test(c.localName)?(n.childNodes.length&&i.push(n),n=t(),i.push(c)):n.append(c);(n.childNodes.length||!i.length)&&(n.childNodes.length||n.append(document.createElement("br")),i.push(n)),_e(e,[...i,...o])},pe=e=>{let r=e[0].parentElement,t=r.parentElement;if(t?.localName!=="li"||!D(t.parentElement)){for(let o of e)Ue(o);return}let n=r.cloneNode(!1);for(;e.at(-1).nextSibling;)n.append(e.at(-1).nextSibling);n.childNodes.length&&e.at(-1).append(n),t.after(...e),r.childNodes.length||r.remove()},oe=e=>{let r=ze(e),t=!!r.length&&r[0].previousElementSibling?.localName==="li"&&r.every(n=>[n,...n.querySelectorAll("li")].every(o=>Pe(e,o)<8));return{listDepth:r.length?Pe(e,r[0]):0,canIndent:t,canOutdent:!!r.length}},he=(e,r)=>{if(r!==1&&r!==-1)throw new TypeError("List indentation requires 1 or -1.");let t=ze(e);if(!t.length)throw new RangeError("Select consecutive items in the same list.");r===1&&!oe(e).canIndent||P(e,()=>{if(r===-1)pe(t);else{let n=t[0].parentElement,o=t[0].previousElementSibling,s=o.lastElementChild;Ke(s,n)||(s=n.cloneNode(!1),o.append(s)),s.append(...t)}te(e)})},We=(e,r)=>{if(r!==!1&&r!=="bullet"&&r!=="ordered")throw new TypeError("Expected bullet, ordered or false.");let t=$e(X(e));if(t.some(n=>n.localName==="li"&&!D(n.parentElement)))throw new RangeError("A list item must belong to a list.");P(e,()=>{for(let n of t){if(!r){n.localName==="li"&&pe([n]);continue}let o=r==="bullet"?"ul":"ol";if(n.localName==="li"){if(n.parentElement.localName===o)continue;let s=document.createElement(o);n.parentElement.hasAttribute("style")&&s.setAttribute("style",n.parentElement.getAttribute("style")),_e(n,[s]),s.append(n)}else{let s=document.createElement(o),i=document.createElement("li");n.hasAttribute("style")&&i.setAttribute("style",n.getAttribute("style")),i.append(...n.childNodes),s.append(i),n.replaceWith(s)}}te(e)})},yt=e=>!e.textContent?.trim()&&!e.querySelector("img,hr,ul,ol"),qe=e=>{ne(e).some(n=>n.textContent||n instanceof Element&&(n.matches("br,img,hr")||n.querySelector("br,img,hr")))||([...e.children].some(D)?e.prepend(Object.assign(document.createElement("p"),{innerHTML:"<br>"})):e.append(document.createElement("br")))},Et=(e,r)=>{let t=r.cloneRange();return t.selectNodeContents(e),t.setEnd(r.startContainer,r.startOffset),!t.toString()&&!t.cloneContents().querySelector("img,hr,br")},Te=(e,r)=>{let t=N(e);if(!t)return!1;let n=re(e,t.startContainer);return n?.localName!=="li"||!D(n.parentElement)||re(e,t.endContainer)!==n?!1:["insertParagraph","insertLineBreak"].includes(r)||r==="deleteContentBackward"&&t.collapsed&&Et(n,t)},we=(e,r)=>{let t=N(e),n=re(e,t.startContainer);if(r==="insertParagraph"){if(yt(n)){P(e,()=>{let a=n.parentElement.parentElement;a?.localName==="li"&&D(a.parentElement)?pe([n]):Ue(n,!0)}),te(e);return}t.deleteContents();let o=t.cloneRange();o.selectNodeContents(n),o.setStart(t.startContainer,t.startOffset);let s=n.cloneNode(!1);s.append(o.extractContents()),n.after(s),qe(n),qe(s);let i=document.createTreeWalker(s,NodeFilter.SHOW_TEXT),c;do c=i.nextNode();while(c&&(!c.textContent||c.parentElement?.closest("li")!==s));if(c){let a=document.createRange();a.setStart(c,0),a.collapse(!0);let d=document.getSelection();d?.removeAllRanges(),d?.addRange(a)}else me(s.querySelector("p,h1,h2,h3,h4,h5,h6,pre")??s)}else if(r==="insertLineBreak"){t.deleteContents();let o=document.createElement("br");t.insertNode(o),o.nextSibling||o.after(document.createElement("br")),t.setStartAfter(o),t.collapse(!0);let s=document.getSelection();s?.removeAllRanges(),s?.addRange(t)}else{let o=n.previousElementSibling;if(o&&o.localName!=="li")return;if(!o){P(e,()=>pe([n])),te(e);return}if(!ne(o).some(h=>h.textContent||h instanceof Element&&(h.localName==="img"||h.querySelector("img"))))for(let h of[...o.querySelectorAll("br")])h.closest("li")===o&&h.remove();let s=document.createComment("mw-join"),c=ne(o).at(-1),a=c instanceof HTMLElement&&/^(p|h[1-6]|blockquote|pre)$/.test(c.localName)?c:o;a===o?o.insertBefore(s,[...o.children].find(D)??null):a.append(s);let d=ne(n);d[0]instanceof HTMLElement&&/^(p|h[1-6])$/.test(d[0].localName)&&d.splice(0,1,...d[0].childNodes),s.after(...d);for(let h of[...n.children].filter(D))o.append(h);n.remove(),te(e);let u=document.createRange();u.setStartBefore(s),u.collapse(!0),s.remove();let f=document.getSelection();f?.removeAllRanges(),f?.addRange(u)}};var R={color:"color",background:"background-color"},Xe=new Set(["p","h1","h2","h3","h4","h5","h6","blockquote","pre","ul","ol","li","table","thead","tbody","tfoot","tr","td","th","caption","colgroup","figure","figcaption"]),Le=(e,r)=>fe({version:1,children:[{type:"element",tag:e,attributes:r,children:[]}]}).children[0].attributes,Q=(e,r)=>{if(r===!1)return!1;if(typeof r!="string"||!r.trim()||r.length>128||/[;{}]/.test(r))throw new TypeError("Expected a CSS color or false.");let t=R[e],n=Le("span",{style:`${t}: ${r}`}),o=document.createElement("span");o.setAttribute("style",n.style??"");let s=o.style.getPropertyValue(t);if(!s)throw new TypeError("Unsupported or invalid CSS color.");return s},Qe=e=>{if(e===!1)return!1;let r=typeof e=="string"?{href:e}:e;if(!r||typeof r!="object"||Array.isArray(r)||!("href"in r)||typeof r.href!="string")throw new TypeError("Expected a link URL, LinkFormat or false.");let t=r,n={href:r.href};if(t.title!==void 0){if(typeof t.title!="string"||t.title.length>1024)throw new TypeError("Link title must be a string up to 1024 characters.");n.title=t.title}if(t.target!==void 0){if(t.target!=="_self"&&t.target!=="_blank")throw new TypeError("Link target must be _self or _blank.");n.target=t.target}if(t.text!==void 0&&(typeof t.text!="string"||!t.text.length||t.text.length>2e4))throw new TypeError("New link text must contain 1\u201320000 characters.");let o=Le("a",n);if(!o.href)throw new TypeError("Unsupported or unsafe link URL.");return{attributes:o,...typeof t.text=="string"?{text:t.text}:{}}},Ne=(e,r)=>{let t={...e,...r};return t.title||delete t.title,r.target==="_self"&&delete t.rel,Le("a",t)},Ve=(e,r)=>JSON.stringify(Object.entries(e??{}).sort())===JSON.stringify(Object.entries(r??{}).sort()),xt=(e,r)=>{let t={...e},n=(t.style??"").split(";").map(o=>o.trim()).filter(o=>o&&o.slice(0,o.indexOf(":")).trim()!==r).join("; ");return n?t.style=n:delete t.style,t},Je=e=>{let r=[];for(let t of e){let n=r.at(-1);n&&n.selected===t.selected&&Ve(n.link,t.link)?n.pieces.push(t):r.push({pieces:[t],selected:t.selected,link:t.link})}return r},ke=e=>{let r=[];for(let t of e){let n=t.type==="element"?{...t,children:ke(t.children)}:t,o=r.at(-1);n.type==="text"&&o?.type==="text"?o.text+=n.text:n.type==="element"&&o?.type==="element"&&!Xe.has(n.tag)&&!["img","br","hr"].includes(n.tag)&&o.tag===n.tag&&Ve(o.attributes,n.attributes)?o.children=ke([...o.children,...n.children]):r.push(n)}return r},ge=(e,r,t,n)=>{let o=0,s=c=>Je(c).flatMap(a=>{let d=a.pieces.map(f=>f.node);if(n.kind==="style")return a.selected&&n.value!==!1?[{type:"element",tag:"span",attributes:{style:`${n.property}: ${n.value}`},children:d}]:d;let u=a.selected?n.attributes===!1?void 0:Ne(a.link??{},n.attributes):a.link;return u?[{type:"element",tag:"a",attributes:u,children:d}]:d}),i=(c,a)=>{if(c.type==="text"){let f=o;o+=c.text.length;let h=Math.max(0,Math.min(c.text.length,r-f)),g=Math.max(h,Math.min(c.text.length,t-f));return[[0,h,!1],[h,g,!0],[g,c.text.length,!1]].flatMap(([m,b,x])=>{let T=c.text.slice(m,b);return T?[{node:{type:"text",text:T},selected:!!x,link:a}]:[]})}let d=n.kind==="link"&&c.tag==="a"?c.attributes:a;if(!c.children.length)return[{node:c,selected:o>=r&&o<t,link:d}];let u=c.children.flatMap(f=>i(f,d));return n.kind==="link"&&c.tag==="a"?u:Xe.has(c.tag)?[{node:{...c,children:s(u)},selected:!1}]:Je(u).flatMap(f=>{let h=n.kind==="style"&&f.selected?xt(c.attributes,n.property):c.attributes,g=f.pieces.map(m=>m.node);return c.tag==="span"&&!Object.keys(h).length?f.pieces:[{node:{...c,attributes:h,children:g},selected:f.selected,link:f.link}]})};return{version:1,children:ke(s(e.children.flatMap(c=>i(c))))}};var Ge=(e,r)=>{let t=Qe(r),n=N(e);if(!n)return;let o=H(e),s=n.startContainer.nodeType===1?n.startContainer:n.startContainer.parentElement,i=s?.closest("a"),c=i&&e.contains(i)?i:void 0;if(t&&t.text!==void 0&&(!n.collapsed||c))throw new TypeError("Link text is only supported for insertion at a caret outside links.");if(!n.collapsed){e.innerHTML=I(ge(S(e.innerHTML),o.index,o.index+o.length,{kind:"link",attributes:t&&t.attributes})),C(e,o.index,o.length);return}if(c){let h=t&&Ne(Object.fromEntries([...c.attributes].map(g=>[g.name,g.value])),t.attributes);P(e,()=>{if(!h)c.replaceWith(...c.childNodes);else{for(let g of[...c.attributes])c.removeAttribute(g.name);for(let[g,m]of Object.entries(h))c.setAttribute(g,m)}});return}if(!t||t.text===void 0)return;let a=e.ownerDocument.createElement("a");for(let[h,g]of Object.entries(t.attributes))a.setAttribute(h,g);a.textContent=t.text;let d=s?.closest("p,li,h1,h2,h3,h4,h5,h6,blockquote,pre,td,th");d?.childNodes.length===1&&d.firstChild instanceof HTMLBRElement&&(d.firstChild.remove(),n.setStart(d,0)),n.insertNode(a);let u=e.ownerDocument.createTextNode("");a.after(u),n.setStart(u,0),n.collapse(!0);let f=e.ownerDocument.getSelection();f?.removeAllRanges(),f?.addRange(n)};var Tt=new Set(["p","h1","h2","h3","h4","h5","h6","blockquote","pre","ul","ol","li","table","thead","tbody","tfoot","tr","td","th","caption","colgroup","figure","figcaption"]),Ye=e=>e.type==="text"?e.text.length:e.children.reduce((r,t)=>r+Ye(t),0),se=(e,r,t,n,o)=>{let s=0,i=c=>{if(c.type==="text"){let u=s;s+=c.text.length;let f=Math.max(0,Math.min(c.text.length,r-u)),h=Math.max(f,Math.min(c.text.length,t-u));return[[0,f,!1],[f,h,!0],[h,c.text.length,!1]].flatMap(([g,m,b])=>{let x=c.text.slice(g,m);if(!x)return[];let T={type:"text",text:x};return[{node:b&&o?{type:"element",tag:n,attributes:{},children:[T]}:T,selected:!!b}]})}if(o&&c.tag===n)return s+=Ye(c),[{node:c,selected:!1}];let a=c.children.flatMap(i);if(Tt.has(c.tag))return[{node:{...c,children:a.map(u=>u.node)},selected:!1}];if(!a.length)return[{node:c,selected:!1}];let d=[];for(let u of a){let f=d.at(-1);f?.selected===u.selected?f.children.push(u.node):d.push({selected:u.selected,children:[u.node]})}return d.flatMap(u=>c.tag===n&&!o&&u.selected?u.children.map(f=>({node:f,selected:!0})):[{node:{...c,children:u.children},selected:u.selected}])};return{version:1,children:e.children.flatMap(i).map(c=>c.node)}};var Ze="p,h1,h2,h3,h4,h5,h6",wt=new Set(["strong","em","u","s","sub","sup","a","span","code"]),kt=new Set(["blockquote","ul","ol","li","table","thead","tbody","tfoot","tr","td","th"]),et=e=>e.nodeType===1?e:e.parentElement,tt=e=>{for(let r of e.childNodes){if(r.nodeType===3)continue;if(r.nodeType!==1)return!1;let t=r;if(t.namespaceURI!=="http://www.w3.org/1999/xhtml"||!wt.has(t.localName)||!tt(t))return!1}return!0},nt=(e,r,t,n)=>{let o=et(r.startContainer)?.closest(Ze);if(!o||!e.contains(o)||o.namespaceURI!=="http://www.w3.org/1999/xhtml"||et(r.endContainer)?.closest(Ze)!==o||!tt(o))return!1;for(let g=o.parentElement;g&&g!==e;g=g.parentElement)if(g.namespaceURI!=="http://www.w3.org/1999/xhtml"||!kt.has(g.localName))return!1;let s=e.ownerDocument.createRange();s.selectNodeContents(o),s.setEnd(r.startContainer,r.startOffset);let i=s.toString().length,c=r.toString().length;if(!c||i+c>(o.textContent?.length??0))return!1;let a=e.ownerDocument.getSelection(),d=a?.anchorNode===r.endContainer&&a.anchorOffset===r.endOffset,u=se(S(o.outerHTML),i,i+c,t,n),f=J(u),h=f.firstElementChild;if(f.childNodes.length!==1||!(h instanceof HTMLElement)||h.localName!==o.localName)return!1;if(h.normalize(),h.outerHTML===o.outerHTML)return!0;if(o.replaceWith(f),C(h,i,c),e.focus({preventScroll:!0}),d&&a?.rangeCount){let g=a.getRangeAt(0);a.setBaseAndExtent(g.endContainer,g.endOffset,g.startContainer,g.startOffset)}return!0};var V={bold:"strong",italic:"em",underline:"u",strike:"s",code:"code",subscript:"sub",superscript:"sup"},Lt=e=>e.nodeType===1?e:e.parentElement,rt=(e,r)=>{let t=Lt(r),n={};for(;t&&t!==e;){for(let[o,s]of Object.entries(V))t.localName===s&&(n[o]=!0);if(/^h[1-6]$/.test(t.localName)&&n.header===void 0&&(n.header=Number(t.localName[1])),t.localName==="blockquote"&&(n.blockquote=!0),t.localName==="pre"&&(n["code-block"]=!0),(t.localName==="ul"||t.localName==="ol")&&n.list===void 0&&(n.list=t.localName==="ul"?"bullet":"ordered"),t.localName==="a"&&n.link===void 0&&(n.link=t.getAttribute("href"),n.linkTitle=t.getAttribute("title")??"",n.linkTarget=t.getAttribute("target")??"_self"),t instanceof HTMLElement)for(let[o,s]of Object.entries(R))n[o]===void 0&&t.style.getPropertyValue(s)&&(n[o]=t.style.getPropertyValue(s));t instanceof HTMLElement&&t.style.textAlign&&n.align===void 0&&(n.align=t.style.textAlign),t=t.parentElement}return n},be=e=>{let r=N(e);if(!r)return{};let t=rt(e,r.startContainer),n=new Set;if(!r.collapsed){let{index:o,length:s}=H(e),i=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),c=0,a,d=[];for(;a=i.nextNode();){let h=c+a.textContent.length;h>o&&c<o+s&&d.push(rt(e,a)),c=h}d.length&&(t=d[0]);let u=[...Object.keys(V),"header","list","blockquote","code-block","link","linkTitle","linkTarget","color","background","align"],f=(h,g)=>h[g]??(g==="align"?"left":g==="header"?0:!1);for(let h of u)d.some(g=>f(g,h)!==f(d[0],h))&&n.add(h)}return{...t,align:t.align??"left",mixed:[...n],...oe(e)}},Me=(e,r,t)=>{let n=N(e);if(!n)return;let o=V[r];if(o&&!n.collapsed&&nt(e,n,o,!!t))return;let s=H(e);if(r==="list"){We(e,t);return}if(r==="indent"){he(e,t);return}if(r==="clear"){if(t!==!0||!s.length)return;let c=S(e.innerHTML);for(let a of[...Object.values(V),"a","span"])c=se(c,s.index,s.index+s.length,a,!1);e.innerHTML=I(c),C(e,s.index,s.length);return}if(o){if(n.collapsed)return;e.innerHTML=I(se(S(e.innerHTML),s.index,s.index+s.length,o,!!t)),C(e,s.index,s.length);return}if(r==="link"){Ge(e,t);return}if(Object.hasOwn(R,r)){let c=Q(r,t);if(!s.length)return;e.innerHTML=I(ge(S(e.innerHTML),s.index,s.index+s.length,{kind:"style",property:R[r],value:c})),C(e,s.index,s.length);return}let i=X(e,n,!1);if(!i.length){let c=document.createElement("p");c.append(n.extractContents()),c.childNodes.length||c.append(document.createElement("br")),n.insertNode(c),i=[c]}P(e,()=>{for(let c of i){if(r==="align"&&["left","center","right","justify",!1].includes(t)){c.style.textAlign=t?String(t):"";continue}let a=r==="header"?Number.isInteger(t)&&Number(t)>=1&&Number(t)<=6?`h${t}`:"p":r==="blockquote"?t?"blockquote":"p":r==="code-block"?t?"pre":"p":void 0;if(a){let d=document.createElement(a);if(c.localName==="li"){let u=[...c.childNodes].filter(f=>!(f instanceof Element&&/^(ul|ol|p|h[1-6]|pre|blockquote)$/.test(f.localName)));d.append(...u),c.prepend(d)}else d.append(...c.childNodes),d.setAttribute("style",c.getAttribute("style")??""),c.replaceWith(d)}}})};var st=new WeakSet,Nt=new Set(["change","selectionchange","readonlychange","destroy"]),Mt=e=>{if(typeof e!="string"||!e.trim()||e.length>200)throw new TypeError("Expected an event name with 1\u2013200 characters.");let r=Object.freeze({name:e});return st.add(r),r},ot=e=>{if(!e||typeof e!="object"||!st.has(e))throw new TypeError("Expected a plugin event token. Core events cannot be emitted publicly.");return e},it=()=>{let e=new Map,r=[],t=0,n=!1,o=!1,s=a=>{if(o&&a.key!=="destroy"||(r.push(a),n))return;n=!0;let d=[];try{for(;r.length;){let u=r.shift();if(o&&u.key!=="destroy")continue;let f=e.get(u.key);for(let[h,g]of[...f??[]])if(!(o&&u.key!=="destroy"||f?.get(h)!==g))try{let m=u.core&&u.payload&&typeof u.payload=="object"?{...u.payload}:u.payload;h(m)}catch(m){d.push(m)}u.key==="destroy"&&(e.clear(),r.length=0)}}finally{n=!1}if(d.length)throw new AggregateError(d,"Editor event listeners failed.")};return{events:{on:(a,d)=>{if(o)throw new Error("Editor events have been destroyed.");if(typeof d!="function")throw new TypeError("Expected an event listener.");let u=typeof a=="string"&&Nt.has(a)?a:ot(a),f=e.get(u);f||(f=new Map,e.set(u,f)),f.has(d)||f.set(d,++t);let h=f.get(d);return()=>{f.get(d)===h&&(f.delete(d),!f.size&&e.get(u)===f&&e.delete(u))}},emit:(a,d)=>{if(o)throw new Error("Editor events have been destroyed.");s({key:ot(a),payload:d,core:!1})}},notify:(a,d)=>s({key:a,payload:d,core:!0}),destroy:()=>{o||(o=!0,r.length=0,s({key:"destroy",payload:void 0,core:!0}))}}};var lt=e=>{let r,t="";return{read:()=>{let s=e.innerHTML;if(s===r)return t;let i=xe(s);return r=s,t=i,i},clear:()=>{r=void 0,t=""}}};var ie=e=>{let r=!1;e.childNodes.length||(e.innerHTML="<p><br></p>",r=!0);let t;for(let n of[...e.childNodes])n.nodeType===3||n.nodeType===1&&/^(strong|em|u|s|a|span|code|img|br|sub|sup)$/.test(n.localName)?(t||(t=document.createElement("p"),e.insertBefore(t,n)),t.append(n),r=!0):t=void 0;return["table","figure"].includes(e.lastElementChild?.localName??"")&&e.append(Object.assign(document.createElement("p"),{innerHTML:"<br>"})),e.dataset.empty=String(!e.textContent&&!e.querySelector("table,img,hr")),r},St=(e,r)=>{let t=N(e);if(!t)return;let n=J(S(r));if(!n.childNodes.length)return;t.deleteContents();let s=(t.startContainer.nodeType===1?t.startContainer:t.startContainer.parentElement)?.closest("p,h1,h2,h3,h4,h5,h6,li,blockquote,pre");if(n.childNodes.length===1&&n.firstChild instanceof HTMLParagraphElement&&s){let u=n.firstChild;n.replaceChildren(...u.childNodes)}let i=[...n.childNodes].some(u=>u instanceof HTMLElement&&/^(p|h[1-6]|ul|ol|table|figure|blockquote|pre)$/.test(u.localName)),c=n.lastChild;if(i&&s&&e.contains(s)){let u=document.createRange();u.selectNodeContents(s),u.setStart(t.startContainer,t.startOffset);let f=s.cloneNode(!1);f.append(u.extractContents()),s.after(n),(f.textContent||f.querySelector("img,br"))&&c.after(f),!s.textContent&&!s.querySelector("img")&&s.remove()}else t.insertNode(n);let a=document.createRange();a.setStartAfter(c),a.collapse(!0);let d=document.getSelection();d?.removeAllRanges(),d?.addRange(a)},Ht=(e,r={})=>{if(e.childNodes.length)throw new Error("Editor host must be empty. Pass initial HTML through value.");let t=r.plugins??[];if(new Set(t.map(l=>l.name)).size!==t.length)throw new Error("Duplicate editor plugin.");let n=r.historyLimit??100;if(!Number.isInteger(n)||n<1||n>1e4)throw new RangeError("historyLimit must be an integer from 1 to 10000.");let o=S(r.value??""),s=document.createElement("div");s.className="mw-editor";let i=document.createElement("div");i.className="mw-content",i.setAttribute("role","textbox"),i.setAttribute("aria-multiline","true"),i.setAttribute("aria-label",r.label??"\u0422\u0435\u043A\u0441\u0442\u043E\u0432\u044B\u0439 \u0440\u0435\u0434\u0430\u043A\u0442\u043E\u0440"),i.dataset.placeholder=r.placeholder??"\u041D\u0430\u0447\u043D\u0438\u0442\u0435 \u043F\u0438\u0441\u0430\u0442\u044C\u2026",s.append(i),e.append(s),i.append(J(o)),ie(i);let c=!1,a=r.readOnly??!1,d=!1,u,f,h=0,g="",m={},b,x=()=>{m={},b=void 0},T=()=>{let l=H(i);return l?.length===0&&l.index===b},L=[],v=[],B=it(),q=0,le=!1,ce,G=!1,Y=new Map,ae=[];r.onChange&&B.events.on("change",r.onChange);let w=()=>{if(c)throw new Error("Editor has been destroyed.")},$=l=>{if(!q)return;let p=new Error(`${l} is unavailable inside a transaction.`);throw le=!0,ce=p,p},ct={on:B.events.on,emit:(l,p)=>{w(),$("events.emit"),B.events.emit(l,p)}},ye=lt(i),j=()=>({html:ye.read(),selection:ee(i),...b!==void 0&&Object.keys(m).length&&T()?{typing:{offset:b,formats:{...m}}}:{}}),Se=l=>{x();let p=H(i);l.typing&&p?.length===0&&p.index===l.typing.offset&&(b=l.typing.offset,m={...l.typing.formats})},A=j(),z=A.selection,K=()=>{if(c)return;if(q){G=!0;return}H(i)&&!T()&&x();let l=ee(i);l&&(z=l,A.selection=l),B.notify("selectionchange",H(i))},de=l=>{let p={html:k.getHTML(),text:k.getText(),source:l},y=[];try{B.notify("change",p)}catch(E){y.push(E)}try{K()}catch(E){y.push(E)}if(y.length)throw new AggregateError(y,"Editor change notification failed.")},He=(l,p="")=>{let y=H(i);ie(i)&&y&&C(i,y.index,y.length);let E=j();if(E.html===l.html)return A=E,!1;let M=Date.now();return p===g&&["insertText","deleteContentBackward","deleteContentForward"].includes(p)&&M-h<600&&l.selection&&A.selection&&JSON.stringify(l.selection)===JSON.stringify(A.selection)||(L.push(l),L.length>n&&L.shift()),v.length=0,A=E,h=p?M:0,g=p,!0},ve=(l,p="")=>{He(l,p)&&de("user")},Ce=l=>{x(),i.innerHTML=l.html,ie(i),i.focus({preventScroll:!0}),U(i,l.selection),Se(l),A=j(),z=A.selection,h=0,de("user")},Z=(l,p="")=>{if(w(),a)return;let y=()=>{if(typeof l!="function"||l.constructor.name==="AsyncFunction")throw new TypeError("Transactions require a synchronous callback.");let O=l(i);if(O&&(typeof O=="object"||typeof O=="function")&&typeof O.then=="function")throw O instanceof Promise&&O.catch(()=>{}),new TypeError("Transaction callbacks must not return a thenable.")};if(q){q++;try{y()}catch(O){throw le=!0,ce=O,O}finally{q--}return}k.focus();let E=j(),M=[...L],Ee=[...v],F=h,W=g,ue=f,at=z;q=1,le=!1,ce=void 0,G=!1;let Ae=!1;try{if(y(),le)throw ce;Ae=He(E,p)}catch(O){throw i.innerHTML=E.html,ie(i),U(i,E.selection),Se(E),A=j(),z=at,f=ue,L.splice(0,L.length,...M),v.splice(0,v.length,...Ee),h=F,g=W,q=0,G=!1,O}finally{q=0}let dt=G;G=!1,Ae?de("user"):dt&&K()},k={element:s,surface:i,events:ct,getHTML:()=>(w(),ye.read()),getText:()=>(w(),i.innerText),getJSON:()=>(w(),S(i.innerHTML)),setHTML:l=>{w(),$("setHTML");let p=I(S(l));p!==k.getHTML()&&(x(),i.innerHTML=p,ie(i),L.length=0,v.length=0,h=0,z=void 0,A=j(),de("api"))},setJSON:l=>{w(),$("setJSON");let p=fe(l);k.setHTML(I(p))},getSelection:()=>(w(),H(i)),setSelection:(l,p=0)=>{w(),C(i,l,p),K()},getFormats:()=>(w(),{...be(i),...T()?m:{}}),setReadOnly:l=>{w(),$("setReadOnly");let p=a!==l;a=l,i.contentEditable=String(!l),i.setAttribute("aria-readonly",String(l)),s.dataset.readonly=String(l);let y=[];if(p)try{B.notify("readonlychange",l)}catch(E){y.push(E)}try{K()}catch(E){y.push(E)}if(y.length)throw new AggregateError(y,"Editor state notification failed.")},isReadOnly:()=>(w(),a),format:(l,p)=>{if(w(),a)return;k.focus();let y=H(i);if(y?.length===0&&(Object.hasOwn(V,l)||Object.hasOwn(R,l))){T()||x(),b=y.index,m[l]=Object.hasOwn(R,l)?Q(l,p):!!p,K();return}x(),k.transact(()=>Me(i,l,p))},insertHTML:l=>k.transact(()=>St(i,l)),focus:()=>{w(),i.focus({preventScroll:!0}),N(i)||(z?U(i,z):me(i.firstElementChild??i,!0))},undo:()=>{if(w(),$("undo"),a)return;let l=L.pop();l&&(v.push(j()),Ce(l))},redo:()=>{if(w(),$("redo"),a)return;let l=v.pop();l&&(L.push(j()),Ce(l))},canUndo:()=>(w(),L.length>0),canRedo:()=>(w(),v.length>0),transact:l=>Z(l),providePlugin:(l,p)=>{if(w(),Y.has(l))throw new Error(`Plugin API already registered: ${l}`);return Y.set(l,p),()=>{Y.delete(l)}},getPlugin:l=>(w(),Y.get(l)),subscribe:l=>(w(),B.events.on("change",l)),onSelectionChange:l=>(w(),B.events.on("selectionchange",l)),destroy:()=>{if(c)return;$("destroy"),c=!0;let l=[];try{B.destroy()}catch(p){l.push(p)}for(let p of ae.reverse())try{p()}catch(y){l.push(y)}if(Y.clear(),L.length=0,v.length=0,ye.clear(),s.remove(),l.length)throw new AggregateError(l,"Editor cleanup failed.")}},_=(l,p)=>{i.addEventListener(l,p),ae.push(()=>i.removeEventListener(l,p))};_("beforeinput",l=>{if(a){l.preventDefault();return}if(l.inputType==="historyUndo"||l.inputType==="historyRedo"){l.preventDefault(),l.inputType==="historyUndo"?k.undo():k.redo();return}if(!d&&!l.isComposing&&Te(i,l.inputType)){l.preventDefault(),x(),f=void 0,Z(()=>we(i,l.inputType));return}if(l.inputType==="insertText"&&l.data&&!d&&!l.isComposing&&T()&&Object.keys(m).length){l.preventDefault();let p=H(i).index,y=l.data,E={...m};Z(()=>{let M=N(i),F=(M.startContainer instanceof Element?M.startContainer:M.startContainer.parentElement)?.closest("p,h1,h2,h3,h4,h5,h6,li,blockquote,pre");F&&!F.textContent&&F.childNodes.length===1&&F.firstChild instanceof HTMLBRElement&&(F.replaceChildren(),M.selectNodeContents(F),M.collapse(!0)),M.insertNode(document.createTextNode(y)),C(i,p,y.length);for(let[W,ue]of Object.entries(E))(Object.hasOwn(R,W)?be(i)[W]??!1:!!be(i)[W])!==ue&&Me(i,W,ue);C(i,p+y.length),b=p+y.length},"insertText"),f=void 0;return}f=j()}),_("input",l=>{let p=l;if(a){i.innerHTML=A.html;return}if(d||p.isComposing)return;let y=f??A;f=void 0,ve(y,p.inputType)}),_("compositionstart",()=>{x(),d=!0,u=j()}),_("compositionend",()=>{d=!1;let l=u;u=void 0,f=void 0,l&&ve(l)}),_("paste",l=>{if(l.preventDefault(),a||!l.clipboardData)return;k.focus();let p=l.clipboardData.getData("text/html");if(p)k.insertHTML(p);else{let y=l.clipboardData.getData("text/plain"),E=document.createElement("div");E.textContent=y,k.insertHTML(E.innerHTML.replace(/\r?\n/g,"<br>"))}}),_("drop",l=>{l.preventDefault()}),_("keydown",l=>{if(!d&&!l.isComposing&&!a&&!l.ctrlKey&&!l.metaKey&&!l.altKey&&(l.key==="Enter"||l.key==="Backspace")){let E=l.key==="Backspace"?"deleteContentBackward":l.shiftKey?"insertLineBreak":"insertParagraph";if(Te(i,E)){l.preventDefault(),x(),f=void 0,Z(()=>we(i,E));return}}if(!d&&!l.isComposing&&!a&&l.key==="Tab"&&!l.ctrlKey&&!l.metaKey&&!l.altKey){let E=X(i);if(E.length&&E.every(M=>M.localName==="li"&&!M.closest("td,th"))&&oe(i).canOutdent){l.preventDefault(),x(),Z(()=>he(i,l.shiftKey?-1:1));return}}if(d||l.isComposing||a||!(l.ctrlKey||l.metaKey)||l.altKey)return;let p=l.key.toLowerCase();(p==="z"||p==="y")&&(l.preventDefault(),p==="y"||l.shiftKey?k.redo():k.undo());let y={b:"bold",i:"italic",u:"underline"}[p];y&&(l.preventDefault(),k.format(y,k.getFormats().mixed?.includes(y)||!k.getFormats()[y]))}),document.addEventListener("selectionchange",K),ae.push(()=>document.removeEventListener("selectionchange",K));try{k.setReadOnly(a);for(let l of t){let p=l.setup(k);p&&ae.push(p)}return k}catch(l){throw k.destroy(),l}};var vt=[{label:"\u041E\u0442\u043C\u0435\u043D\u0438\u0442\u044C",text:"\u21B6",run:e=>e.undo(),enabled:e=>e.canUndo()},{label:"\u041F\u043E\u0432\u0442\u043E\u0440\u0438\u0442\u044C",text:"\u21B7",run:e=>e.redo(),enabled:e=>e.canRedo()},{label:"\u041F\u043E\u043B\u0443\u0436\u0438\u0440\u043D\u044B\u0439",text:"B",format:"bold"},{label:"\u041A\u0443\u0440\u0441\u0438\u0432",text:"I",format:"italic"},{label:"\u041F\u043E\u0434\u0447\u0451\u0440\u043A\u043D\u0443\u0442\u044B\u0439",text:"U",format:"underline"},{label:"\u0417\u0430\u0433\u043E\u043B\u043E\u0432\u043E\u043A",text:"H\u2082",format:"header",value:2},{label:"\u041C\u0430\u0440\u043A\u0438\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A",text:"\u2637",format:"list",value:"bullet"},{label:"\u041D\u0443\u043C\u0435\u0440\u043E\u0432\u0430\u043D\u043D\u044B\u0439 \u0441\u043F\u0438\u0441\u043E\u043A",text:"1.",format:"list",value:"ordered"},{label:"\u0423\u0432\u0435\u043B\u0438\u0447\u0438\u0442\u044C \u043E\u0442\u0441\u0442\u0443\u043F",text:"\u21E5",format:"indent",value:1,enabled:e=>!!e.getFormats().canIndent},{label:"\u0423\u043C\u0435\u043D\u044C\u0448\u0438\u0442\u044C \u043E\u0442\u0441\u0442\u0443\u043F",text:"\u21E4",format:"indent",value:-1,enabled:e=>!!e.getFormats().canOutdent},{label:"\u0426\u0438\u0442\u0430\u0442\u0430",text:"\u275D",format:"blockquote"},{label:"\u041E\u0447\u0438\u0441\u0442\u0438\u0442\u044C \u0444\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435",text:"Tx",format:"clear",enabled:e=>!!e.getSelection()?.length}],Ct=(e,r,t=vt,n={})=>{t=t.map(m=>m.format&&Object.hasOwn(R,m.format)?{...m,value:Q(m.format,m.value)}:m);let o=document.createElement("div");o.className="mw-toolbar",o.setAttribute("role","toolbar"),o.setAttribute("aria-label",n.label??"\u0424\u043E\u0440\u043C\u0430\u0442\u0438\u0440\u043E\u0432\u0430\u043D\u0438\u0435");let s,i=!1,c=0,a=[],d=t.map(m=>{let b=document.createElement("button");b.type="button",b.textContent=m.text,b.title=m.label,b.setAttribute("aria-label",m.label);let x=L=>L.preventDefault(),T=()=>{if(!(i||b.disabled||r.isReadOnly())&&(r.focus(),s&&U(r.surface,s),!(m.enabled&&!m.enabled(r)))){if(m.run)m.run(r);else if(m.format){let L=r.getFormats(),v=L.mixed?.includes(m.format);r.format(m.format,!v&&L[m.format]===(m.value??!0)?!1:m.value??!0)}u()}};return b.addEventListener("mousedown",x),b.addEventListener("click",T),a.push(()=>{b.removeEventListener("mousedown",x),b.removeEventListener("click",T)}),o.append(b),b}),u=()=>{if(i)return;s=ee(r.surface)??s;let m=r.getFormats();d.forEach((b,x)=>{let T=t[x];b.disabled=r.isReadOnly()||(T.enabled?!T.enabled(r):!1),T.format&&!["indent","clear"].includes(T.format)&&b.setAttribute("aria-pressed",m.mixed?.includes(T.format)?"mixed":String(m[T.format]===(T.value??!0)))}),(d[c]?.disabled||!d[c])&&(c=d.findIndex(b=>!b.disabled)),d.forEach((b,x)=>{b.tabIndex=x===c?0:-1})},f=m=>{let b=d.filter(v=>!v.disabled);if(!b.length)return;let x=b.indexOf(document.activeElement);if(x<0||m.ctrlKey||m.metaKey||m.altKey)return;if(m.key==="Escape"){m.preventDefault(),r.focus(),s&&U(r.surface,s);return}let T=getComputedStyle(o).direction==="rtl"?-1:1,L=m.key==="Home"?0:m.key==="End"?b.length-1:m.key==="ArrowRight"?(x+T+b.length)%b.length:m.key==="ArrowLeft"?(x-T+b.length)%b.length:-1;L>=0&&(m.preventDefault(),c=d.indexOf(b[L]),u(),b[L].focus())};o.addEventListener("keydown",f);let h=r.subscribe(m=>{m.source==="api"&&(s=void 0),u()}),g=r.onSelectionChange(u);return e.append(o),u(),()=>{if(!i){i=!0,h(),g(),o.removeEventListener("keydown",f);for(let m of a)m();o.remove()}}};export{Ht as createEditor,Mt as createPluginEvent,Ct as createToolbar,xe as sanitizeHTML};
|
|
1
|
+
import{a as me}from"./chunk-YFIJ4ED5.js";import{a as O}from"./chunk-X5IUYCDN.js";var Ce=(e,n)=>{let t=e.trim();if(!t||/[\u0000-\u0020\u007f]/.test(t))return;let r=/^([a-z][a-z\d+.-]*):/i.exec(t)?.[1].toLowerCase();if(!(r&&!(n?["http","https"]:["http","https","mailto","tel"]).includes(r))&&!(t.startsWith("\\")||t.startsWith("//")))return t};var $t=["p","h1","h2","h3","h4","h5","h6","blockquote","pre","code","strong","em","u","s","sub","sup","a","span","br","hr","ul","ol","li","img","figure","figcaption","table","caption","colgroup","col","thead","tbody","tfoot","tr","td","th"],tt=new Set($t),Ut=new Set(["script","style","iframe","object","embed","svg","math","template","form","input","button","textarea","select","noscript","link","meta","base"]),Wt={b:"strong",i:"em",strike:"s",div:"p"},nt=1e5,rt=100,_t=e=>{let n=[];for(let t of e.split(";")){let r=t.indexOf(":");if(r<0)continue;let s=t.slice(0,r).trim().toLowerCase(),i=t.slice(r+1).trim().toLowerCase(),c=/^(#[a-f\d]{3,8}|[a-z]{1,24}|(?:rgb|rgba|hsl|hsla)\([\d\s.,%+-]+\))$/,a=/^(?:\d{1,4}(?:\.\d{1,3})?)(?:px|%|em|rem)$/;(["color","background-color","border-color"].includes(s)?c.test(i):["width","height","font-size"].includes(s)?a.test(i):s==="text-align"?["left","center","right","justify"].includes(i):s==="font-weight"?/^(bold|normal|[1-9]00)$/.test(i):s==="font-style"?["italic","normal"].includes(i):s==="text-decoration"?/^(underline|line-through|none)$/.test(i):!1)&&n.push(`${s}: ${i}`)}return n.join("; ")},ot=(e,n,t,r,s)=>{let i={};for(let[c,a]of Object.entries(n))if(!(typeof a!="string"||a.length>2e4))if(c==="style"){let o=_t(a);o&&(i.style=o)}else if(c==="title"||e==="img"&&c==="alt")i[c]=a;else if(e==="a"&&c==="href"||e==="img"&&c==="src"){let o=Ce(a,e==="img");o&&(i[c]=o)}else if(["td","th"].includes(e)&&["rowspan","colspan"].includes(c)||["img","col","table"].includes(e)&&["width","height","span"].includes(c))/^\d{1,4}$/.test(a)&&Number(a)>0&&Number(a)<=1e3&&(i[c]=a);else if(e==="a"&&c==="target"&&["_self","_blank"].includes(a))i.target=a;else if(e==="a"&&c==="rel"){let o=[...new Set(a.toLowerCase().split(/\s+/).filter(d=>["noopener","noreferrer"].includes(d)))];o.length&&(i.rel=o.join(" "))}else e==="th"&&c==="scope"&&["row","col","rowgroup","colgroup"].includes(a)&&(i[c]=a);if(e==="img"&&(i.width||i.height)){let c=["width","height"].filter(o=>i[o]),a=(i.style??"").split(";").map(o=>o.trim()).filter(o=>o&&!c.includes(o.slice(0,o.indexOf(":")).trim()));i.style=[...a,...c.map(o=>`${o}: ${i[o]}px`)].join("; ")}if(e==="a"&&i.target==="_blank"&&(i.rel="noopener noreferrer"),r)Object.assign(i,r(e,n,t,s));else if(t==="json"&&Object.hasOwn(n,"data-mw-node"))throw new TypeError("Unregistered schema node.");return i},st=(e,n,t,r)=>{if(++t.count>nt||n>rt)throw new RangeError("Document exceeds structural limits.");if(e.nodeType===3)return[{type:"text",text:e.textContent??""}];if(e.nodeType!==1)return[];let s=e,i=s.localName.toLowerCase();if(s.namespaceURI!=="http://www.w3.org/1999/xhtml"||Ut.has(i))return[];let c=[...s.childNodes].flatMap(d=>st(d,n+1,t,r)),a=Wt[i]??i;if(!tt.has(a))return r&&s.hasAttribute("data-mw-node")&&r(a,Object.fromEntries([...s.attributes].map(d=>[d.name,d.value])),"html",i),c;let o=ot(a,Object.fromEntries([...s.attributes].map(d=>[d.name,d.value])),"html",r,i);return a==="img"&&!o.src?[]:[{type:"element",tag:a,attributes:o,children:c}]},z=(e,n)=>{if(e.length>5e6)throw new RangeError("HTML exceeds the document size limit.");let t=document.createElement("template");t.innerHTML=e;let r={count:0};return{version:1,children:[...t.content.childNodes].flatMap(s=>st(s,0,r,n))}},He=(e,n)=>{if(!e||typeof e!="object"||!("version"in e)||e.version!==1||!("children"in e)||!Array.isArray(e.children))throw new TypeError("Expected a version 1 document.");let t=0,r=0,s=(i,c)=>{if(++t>nt||c>rt)throw new RangeError("Document exceeds structural limits.");if(!i||typeof i!="object"||!("type"in i))throw new TypeError("Invalid document node.");if(i.type==="text"&&"text"in i&&typeof i.text=="string"){if(r+=i.text.length,r>5e6)throw new RangeError("Document text exceeds size limit.");return{type:"text",text:i.text}}if(i.type!=="element"||!("tag"in i)||typeof i.tag!="string"||!tt.has(i.tag)||!("children"in i)||!Array.isArray(i.children))throw new TypeError("Invalid document element.");let a="attributes"in i&&i.attributes&&typeof i.attributes=="object"&&!Array.isArray(i.attributes)?i.attributes:{};return{type:"element",tag:i.tag,attributes:ot(i.tag,a,"json",n),children:i.children.map(o=>s(o,c+1))}};return{version:1,children:e.children.map(i=>s(i,0))}},fe=e=>{let n=document.createDocumentFragment(),t=(r,s)=>{if(s.type==="text"){r.appendChild(document.createTextNode(s.text));return}let i=document.createElement(s.tag);for(let[c,a]of Object.entries(s.attributes))i.setAttribute(c,a);for(let c of s.children)t(i,c);r.appendChild(i)};for(let r of e.children)t(n,r);return n},U=e=>{let n=document.createElement("div");return n.append(fe(e)),n.innerHTML},Be=e=>U(z(e));var Jt=["span","strong","em","u","s","sub","sup","code"],Xt=["p","h1","h2","h3","h4","h5","h6","blockquote","pre","figure","figcaption"],Vt=(e,n)=>typeof n=="string"&&(e==="block"?Xt:e==="inline"?Jt:[]).includes(n),qe=e=>!!e&&typeof e=="object"&&!Array.isArray(e)&&(Object.getPrototypeOf(e)===Object.prototype||Object.getPrototypeOf(e)===null),pe=(e,n)=>{if(Object.keys(e).some(t=>!n.includes(t)))throw new TypeError("Unknown schema definition field.")},Qt=e=>{if(!qe(e))throw new TypeError("Schema attribute must be an object.");if(e.required!==void 0&&typeof e.required!="boolean")throw new TypeError("Schema attribute required must be boolean.");let n=e.required===!0,t;if(e.type==="text"){pe(e,["type","required","maxLength"]);let r=e.maxLength??256;if(typeof r!="number"||!Number.isInteger(r)||r<0||r>2e4)throw new RangeError("Schema text maxLength must be from 0 to 20000.");t=s=>{if(s.length>r)throw new RangeError("Schema text exceeds its maximum length.");return s}}else if(e.type==="enum"){if(pe(e,["type","required","values"]),!Array.isArray(e.values)||!e.values.length||e.values.length>64||e.values.some(s=>typeof s!="string"||s.length>2e4))throw new TypeError("Schema enum needs 1 to 64 bounded string values.");let r=new Set(e.values);t=s=>{if(!r.has(s))throw new TypeError("Invalid schema enum value.");return s}}else if(e.type==="integer"){pe(e,["type","required","min","max"]);let r=e.min,s=e.max;if(typeof r!="number"||typeof s!="number"||!Number.isSafeInteger(r)||!Number.isSafeInteger(s)||r>s)throw new RangeError("Schema integer bounds must be safe ordered integers.");t=i=>{let c=Number(i);if(!/^-?\d+$/.test(i)||!Number.isSafeInteger(c)||c<r||c>s)throw new RangeError("Schema integer is outside its bounds.");return String(c)}}else if(e.type==="url")pe(e,["type","required"]),t=r=>{let s=Ce(r,!1);if(s===void 0)throw new TypeError("Unsupported or unsafe schema URL.");return s};else throw new TypeError("Unknown schema attribute type.");return Object.freeze({required:n,read:r=>{if(typeof r!="string"||r.length>2e4)throw new TypeError("Schema attribute must be a bounded string.");return t(r)}})},Pe=(e=[])=>{if(!Array.isArray(e)||e.length>128)throw new TypeError("Schema nodes must be an array of at most 128 definitions.");let n=new Map;for(let i of e){if(!qe(i))throw new TypeError("Schema node must be an object.");if(pe(i,["name","kind","tag","attributes"]),typeof i.name!="string"||i.name.length>128||!/^[a-z][a-z0-9-]*(?::[a-z][a-z0-9-]*)+$/.test(i.name))throw new TypeError("Schema node names must be bounded namespaced identifiers.");if(n.has(i.name))throw new Error(`Duplicate schema node: ${i.name}`);if(!Vt(i.kind,i.tag))throw new TypeError("Schema node tag must match its supported block or inline kind.");let c=i.attributes??{};if(!qe(c)||Object.keys(c).length>64)throw new TypeError("Schema node attributes must be a bounded record.");let a=new Map;for(let[o,d]of Object.entries(c)){if(!/^data-[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/.test(o)||o.startsWith("data-mw-"))throw new TypeError("Schema attributes must use non-reserved lowercase data-* names.");a.set(o,Qt(d))}n.set(i.name,Object.freeze({tag:i.tag,attributes:a}))}let t=(i,c,a,o)=>{if(!Object.hasOwn(c,"data-mw-node"))return{};let d=c["data-mw-node"],u=typeof d=="string"?n.get(d):void 0;if(typeof d!="string"||!u){if(a==="json")throw new TypeError("Unregistered schema node.");return{}}if(i!==u.tag||o!==void 0&&o!==u.tag)throw new TypeError("Schema node marker does not match its tag.");let f={"data-mw-node":d};for(let[m,g]of u.attributes)if(Object.hasOwn(c,m))f[m]=g.read(c[m]);else if(g.required)throw new TypeError(`Missing required schema attribute: ${m}`);return f},r=i=>He(i,t),s=i=>z(i,t);return Object.freeze({parseHTML:s,validateDocument:r,renderDocument:i=>fe(r(i)),documentHTML:i=>U(r(i)),sanitizeHTML:i=>U(s(i))})};var lt=new WeakSet,Gt=e=>{if(typeof e!="string"||!e.trim()||e.length>200)throw new TypeError("Expected a command name with 1\u2013200 characters.");let n=Object.freeze({name:e});return lt.add(n),n},it=e=>{if(!e||typeof e!="object"||!lt.has(e))throw new TypeError("Expected an editor command token.");return e},ze=e=>{if(typeof e!="function"||e.constructor.name==="AsyncFunction")throw new TypeError("Command callbacks must be synchronous functions.")},at=e=>{if(e&&(typeof e=="object"||typeof e=="function")&&typeof e.then=="function")throw e instanceof Promise&&e.catch(()=>{}),new TypeError("Command callbacks must not return a thenable.")},ct=e=>{let n=new Map,t=!1,r=()=>{if(e.assertActive(),t)throw new Error("Editor commands have been destroyed.")},s=o=>{r();let d=n.get(it(o));if(!d)throw new Error(`Command is not registered: ${o.name}`);return d},i=(o,d)=>{if(!o)return d;let u=o(e.editor());if(at(u),typeof u!="boolean")throw new TypeError("Command state callbacks must return a boolean.");return u},c=o=>!e.editor().isReadOnly()&&!e.isComposing()&&i(o.isEnabled,!0);return{commands:{register:(o,d)=>{r();let u=it(o);if(n.has(u))throw new Error(`Command is already registered: ${o.name}`);if(!d||typeof d!="object")throw new TypeError("Expected a command definition.");let{validate:f,execute:m,isEnabled:g,isActive:h,isMixed:x}=d;ze(f),ze(m);for(let w of[g,h,x])w!==void 0&&ze(w);let N={validate:f,execute:(w,F)=>m(w,F),isEnabled:g,isActive:h,isMixed:x};return n.set(u,N),()=>{n.get(u)===N&&n.delete(u)}},execute:(o,d)=>{let u=s(o);if(!c(u))return!1;let f=e.editor();return f.transact(()=>{let m=u.validate(d);return at(m),u.execute(f,m)}),!0},getState:o=>{let d=s(o);return{enabled:c(d),active:i(d.isActive,!1),mixed:i(d.isMixed,!1)}}},destroy:()=>{t||(t=!0,n.clear())}}};var C=e=>{let n=e.ownerDocument.getSelection();if(!n?.rangeCount)return;let t=n.getRangeAt(0);if(!(!e.contains(t.startContainer)||!e.contains(t.endContainer)))return t.cloneRange()},dt=(e,n)=>{let t=[],r=n;for(;r!==e&&r.parentNode;)t.unshift([...r.parentNode.childNodes].indexOf(r)),r=r.parentNode;return t},ut=(e,n)=>e.nodeType===3&&e.textContent===""&&e.parentNode?[e.parentNode,[...e.parentNode.childNodes].indexOf(e)]:[e,n],he=e=>{let n=C(e);if(!n)return;let t=e.ownerDocument.getSelection(),[r,s]=ut(n.startContainer,n.startOffset),[i,c]=ut(n.endContainer,n.endOffset);return{start:dt(e,r),startOffset:s,end:dt(e,i),endOffset:c,backward:!n.collapsed&&t.anchorNode===n.endContainer&&t.anchorOffset===n.endOffset}},_=(e,n)=>{if(!n)return;let t=d=>d.reduce((u,f)=>u.childNodes[f]??u,e),r=t(n.start),s=t(n.end),i=(d,u)=>Math.min(u,d.nodeType===3?d.textContent?.length??0:d.childNodes.length),c=e.ownerDocument.getSelection();if(!c)return;let a=i(r,n.startOffset),o=i(s,n.endOffset);n.backward?c.setBaseAndExtent(s,o,r,a):c.setBaseAndExtent(r,a,s,o)},v=e=>{let n=C(e);if(!n)return;let t=e.ownerDocument.createRange();return t.selectNodeContents(e),t.setEnd(n.startContainer,n.startOffset),{index:t.toString().length,length:n.toString().length}},j=(e,n,t=0)=>{if(![n,t].every(g=>Number.isInteger(g)&&g>=0))throw new RangeError("Selection offsets must be non-negative integers.");let r=e.ownerDocument.createTreeWalker(e,4),s=[],i;for(;i=r.nextNode();)s.push(i);let c=g=>{for(let x of s){if(g<=x.length)return[x,g];g-=x.length}let h=s.at(-1);return h?[h,h.length]:[e.querySelector("p,h1,h2,h3,h4,h5,h6,li,blockquote,pre")??e,0]},[a,o]=c(n),[d,u]=c(n+t),f=e.ownerDocument.createRange();f.setStart(a,o),f.setEnd(d,u),e.focus({preventScroll:!0});let m=e.ownerDocument.getSelection();m?.removeAllRanges(),m?.addRange(f)},ne=(e,n=!1)=>{let t=e.ownerDocument.createRange();t.selectNodeContents(e),t.collapse(!n);let r=e.ownerDocument.getSelection();r?.removeAllRanges(),r?.addRange(t)},J=(e,n)=>{let t=C(e);if(!t)return;let r=e.ownerDocument.getSelection(),s=!t.collapsed&&r.anchorNode===t.endContainer&&r.anchorOffset===t.endOffset,i=e.ownerDocument.createComment("mw-start"),c=t.collapsed?void 0:e.ownerDocument.createComment("mw-end");if(c){let o=t.cloneRange();o.collapse(!1),o.insertNode(c)}let a=t.cloneRange();a.collapse(!0),a.insertNode(i);try{if(n(),e.contains(i)&&(!c||e.contains(c))){let o=e.ownerDocument.createRange();o.setStartBefore(i),c?o.setEndBefore(c):o.collapse(!0),i.remove(),c?.remove(),e.normalize(),s?r.setBaseAndExtent(o.endContainer,o.endOffset,o.startContainer,o.startOffset):(r.removeAllRanges(),r.addRange(o))}}finally{i.remove(),c?.remove()}};var pt="p,h1,h2,h3,h4,h5,h6,blockquote,pre,li",I=e=>!!e&&/^(ul|ol)$/.test(e.localName),Yt=e=>e instanceof Element?e:e.parentElement,ye=(e,n,t=!0)=>{let r=Yt(n),s=r?.closest("li"),i=(t&&s&&e.contains(s)?s:void 0)??r?.closest(pt);return i&&e.contains(i)?i:void 0},Zt=(e,n)=>{let t=n.ownerDocument.createRange();n.nodeType===3?t.selectNodeContents(n):t.selectNode(n);let r=e.cloneRange();r.collapse(!0);let s=e.cloneRange();s.collapse(!1);let i=t.cloneRange();i.collapse(!0);let c=t.cloneRange();return c.collapse(!1),r.compareBoundaryPoints(Range.START_TO_START,c)<0&&s.compareBoundaryPoints(Range.START_TO_START,i)>0},ae=(e,n=C(e),t=!0)=>{if(!n)return[];if(n.collapsed){let c=ye(e,n.startContainer,t);return c?[c]:[]}let r=new Set,s=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT|NodeFilter.SHOW_ELEMENT),i;for(;i=s.nextNode();)if(!(!(i.nodeType===3&&i.textContent)&&!(i instanceof Element&&/^(br|img|hr)$/.test(i.localName)))&&Zt(n,i)){let c=ye(e,i,t);c&&r.add(c)}return[...e.querySelectorAll(pt)].filter(c=>r.has(c))},ht=e=>e.filter(n=>!e.some(t=>t!==n&&t.contains(n))),gt=e=>{let n=ht(ae(e));if(!n.length||n.some(s=>s.localName!=="li"||!I(s.parentElement)))return[];let t=n[0].parentElement;if(n.some(s=>s.parentElement!==t))return[];let r=[...t.children];return r.indexOf(n.at(-1))-r.indexOf(n[0])+1!==n.length?[]:n},mt=(e,n)=>{let t=0,r=n.parentElement;for(;r&&r!==e;)I(r)&&t++,r=r.parentElement;return t},bt=(e,n)=>!!e&&e.localName===n.localName&&I(e)&&e.getAttribute("style")===n.getAttribute("style"),ge=e=>{for(let n of[...e.querySelectorAll("ul,ol")]){if(!e.contains(n))continue;let t=n.previousSibling;t instanceof Element&&bt(t,n)&&(t.append(...n.childNodes),n.remove())}},yt=(e,n)=>{let t=e.parentElement,r=t.cloneNode(!1);for(;e.nextSibling;)r.append(e.nextSibling);e.remove(),t.after(...n,...r.childNodes.length?[r]:[]),t.childNodes.length||t.remove()},be=e=>[...e.childNodes].filter(n=>!(n instanceof Element&&I(n))),Et=(e,n=!1)=>{let t=()=>{let a=document.createElement("p");return e.hasAttribute("style")&&a.setAttribute("style",e.getAttribute("style")),a},r=t(),s=[...e.children].filter(I),i=be(e),c=[];for(let a of i)n&&a instanceof HTMLElement&&/^(p|h[1-6]|blockquote|pre)$/.test(a.localName)?r.append(...a.childNodes):a instanceof HTMLElement&&/^(p|h[1-6]|blockquote|pre)$/.test(a.localName)?(r.childNodes.length&&c.push(r),r=t(),c.push(a)):r.append(a);(r.childNodes.length||!c.length)&&(r.childNodes.length||r.append(document.createElement("br")),c.push(r)),yt(e,[...c,...s])},De=e=>{let n=e[0].parentElement,t=n.parentElement;if(t?.localName!=="li"||!I(t.parentElement)){for(let s of e)Et(s);return}let r=n.cloneNode(!1);for(;e.at(-1).nextSibling;)r.append(e.at(-1).nextSibling);r.childNodes.length&&e.at(-1).append(r),t.after(...e),n.childNodes.length||n.remove()},Ee=e=>{let n=gt(e),t=!!n.length&&n[0].previousElementSibling?.localName==="li"&&n.every(r=>[r,...r.querySelectorAll("li")].every(s=>mt(e,s)<8));return{listDepth:n.length?mt(e,n[0]):0,canIndent:t,canOutdent:!!n.length}},Ae=(e,n)=>{if(n!==1&&n!==-1)throw new TypeError("List indentation requires 1 or -1.");let t=gt(e);if(!t.length)throw new RangeError("Select consecutive items in the same list.");n===1&&!Ee(e).canIndent||J(e,()=>{if(n===-1)De(t);else{let r=t[0].parentElement,s=t[0].previousElementSibling,i=s.lastElementChild;bt(i,r)||(i=r.cloneNode(!1),s.append(i)),i.append(...t)}ge(e)})},Tt=(e,n)=>{if(n!==!1&&n!=="bullet"&&n!=="ordered")throw new TypeError("Expected bullet, ordered or false.");let t=ht(ae(e));if(t.some(r=>r.localName==="li"&&!I(r.parentElement)))throw new RangeError("A list item must belong to a list.");J(e,()=>{for(let r of t){if(!n){r.localName==="li"&&De([r]);continue}let s=n==="bullet"?"ul":"ol";if(r.localName==="li"){if(r.parentElement.localName===s)continue;let i=document.createElement(s);r.parentElement.hasAttribute("style")&&i.setAttribute("style",r.parentElement.getAttribute("style")),yt(r,[i]),i.append(r)}else{let i=document.createElement(s),c=document.createElement("li");r.hasAttribute("style")&&c.setAttribute("style",r.getAttribute("style")),c.append(...r.childNodes),i.append(c),r.replaceWith(i)}}ge(e)})},en=e=>!e.textContent?.trim()&&!e.querySelector("img,hr,ul,ol"),ft=e=>{be(e).some(r=>r.textContent||r instanceof Element&&(r.matches("br,img,hr")||r.querySelector("br,img,hr")))||([...e.children].some(I)?e.prepend(Object.assign(document.createElement("p"),{innerHTML:"<br>"})):e.append(document.createElement("br")))},tn=(e,n)=>{let t=n.cloneRange();return t.selectNodeContents(e),t.setEnd(n.startContainer,n.startOffset),!t.toString()&&!t.cloneContents().querySelector("img,hr,br")},Ke=(e,n)=>{let t=C(e);if(!t)return!1;let r=ye(e,t.startContainer);return r?.localName!=="li"||!I(r.parentElement)||ye(e,t.endContainer)!==r?!1:["insertParagraph","insertLineBreak"].includes(n)||n==="deleteContentBackward"&&t.collapsed&&tn(r,t)},Fe=(e,n)=>{let t=C(e),r=ye(e,t.startContainer);if(n==="insertParagraph"){if(en(r)){J(e,()=>{let o=r.parentElement.parentElement;o?.localName==="li"&&I(o.parentElement)?De([r]):Et(r,!0)}),ge(e);return}t.deleteContents();let s=t.cloneRange();s.selectNodeContents(r),s.setStart(t.startContainer,t.startOffset);let i=r.cloneNode(!1);i.append(s.extractContents()),r.after(i),ft(r),ft(i);let c=document.createTreeWalker(i,NodeFilter.SHOW_TEXT),a;do a=c.nextNode();while(a&&(!a.textContent||a.parentElement?.closest("li")!==i));if(a){let o=document.createRange();o.setStart(a,0),o.collapse(!0);let d=document.getSelection();d?.removeAllRanges(),d?.addRange(o)}else ne(i.querySelector("p,h1,h2,h3,h4,h5,h6,pre")??i)}else if(n==="insertLineBreak"){t.deleteContents();let s=document.createElement("br");t.insertNode(s),s.nextSibling||s.after(document.createElement("br")),t.setStartAfter(s),t.collapse(!0);let i=document.getSelection();i?.removeAllRanges(),i?.addRange(t)}else{let s=r.previousElementSibling;if(s&&s.localName!=="li")return;if(!s){J(e,()=>De([r])),ge(e);return}if(!be(s).some(m=>m.textContent||m instanceof Element&&(m.localName==="img"||m.querySelector("img"))))for(let m of[...s.querySelectorAll("br")])m.closest("li")===s&&m.remove();let i=document.createComment("mw-join"),a=be(s).at(-1),o=a instanceof HTMLElement&&/^(p|h[1-6]|blockquote|pre)$/.test(a.localName)?a:s;o===s?s.insertBefore(i,[...s.children].find(I)??null):o.append(i);let d=be(r);d[0]instanceof HTMLElement&&/^(p|h[1-6])$/.test(d[0].localName)&&d.splice(0,1,...d[0].childNodes),i.after(...d);for(let m of[...r.children].filter(I))s.append(m);r.remove(),ge(e);let u=document.createRange();u.setStartBefore(i),u.collapse(!0),i.remove();let f=document.getSelection();f?.removeAllRanges(),f?.addRange(u)}};var nn=new Set(["p","h1","h2","h3","h4","h5","h6"]),rn=new Set(["strong","em","u","s","sub","sup","a","span","code","br"]),wt=e=>[...e.childNodes].every(n=>n.nodeType===3||n instanceof HTMLElement&&rn.has(n.localName)&&wt(n)),on=e=>e.nodeType===1?e:e.parentElement,$e=(e,n)=>{let t=on(n)?.closest("p,h1,h2,h3,h4,h5,h6");if(!(t instanceof HTMLElement)||t.namespaceURI!=="http://www.w3.org/1999/xhtml"||!e.contains(t)||t.closest("li,figure,pre")||!wt(t))return;let r=t.parentElement;if(!(r!==e&&!["blockquote","td","th"].includes(r?.localName??"")))return t},xt=e=>!!(e.textContent||e.querySelector("br")),kt=e=>{let n=C(e);if(!n)return;let t=$e(e,n.startContainer);return t&&$e(e,n.endContainer)===t?t:void 0},Ue=(e,n,t)=>{if(!e.textContent&&e.querySelectorAll("br").length<=1)return!0;let r=e.ownerDocument.createRange();r.selectNodeContents(e),t?r.setStart(n.endContainer,n.endOffset):r.setEnd(n.startContainer,n.startOffset);let s=r.cloneContents();return!xt(s)},sn=(e,n,t)=>{let r=t?n.nextSibling:n.previousSibling;return r instanceof HTMLElement&&nn.has(r.localName)&&$e(e,r)===r?r:void 0},Te=(e,n)=>{let t=kt(e),r=C(e);return!t||!r?!1:n==="insertParagraph"||n==="insertLineBreak"?!0:r.collapsed?n==="deleteContentBackward"?Ue(t,r,!1):n==="deleteContentForward"?Ue(t,r,!0):!1:!1},Re=(e,n)=>{let t=kt(e),r=C(e);if(!t||!r||!Te(e,n))return;let s=e.ownerDocument;if(n==="insertParagraph"){r.deleteContents();let f=s.createRange();f.selectNodeContents(t),f.setStart(r.startContainer,r.startOffset);let m=f.extractContents(),g=t.localName!=="p"&&!t.textContent&&!m.textContent&&t.querySelectorAll("br").length+m.querySelectorAll("br").length<=1,h=t.localName!=="p"&&(!xt(m)||g);if(g){let N=s.createElement("p");for(let w of t.attributes)N.setAttribute(w.name,w.value);N.append(s.createElement("br")),t.replaceWith(N),ne(N);return}let x=h?s.createElement("p"):t.cloneNode(!1);if(h)for(let N of t.attributes)x.setAttribute(N.name,N.value);x.append(m),!x.textContent&&!x.querySelector("br")&&x.replaceChildren(s.createElement("br")),!t.textContent&&!t.querySelector("br")&&t.replaceChildren(s.createElement("br")),t.after(x),ne(x);return}if(n==="insertLineBreak"){r.deleteContents(),!t.textContent&&t.querySelectorAll("br").length<=1&&(t.replaceChildren(),r.selectNodeContents(t),r.collapse(!0));let f=Ue(t,r,!0),m=s.createElement("br");r.insertNode(m),f&&m.after(s.createElement("br"));let g=s.createRange();g.setStartAfter(m),g.collapse(!0);let h=s.getSelection();h?.removeAllRanges(),h?.addRange(g);return}let i=n==="deleteContentForward",c=sn(e,t,i);if(!c)return;let a=i?t:c,o=i?c:t;!a.textContent&&a.childNodes.length===1&&a.firstChild instanceof HTMLBRElement&&a.replaceChildren(),!o.textContent&&o.childNodes.length===1&&o.firstChild instanceof HTMLBRElement&&o.replaceChildren();let d=s.createRange();d.selectNodeContents(a),d.collapse(!1),a.append(...o.childNodes),o.remove(),a.childNodes.length||a.append(s.createElement("br")),a.normalize();let u=s.getSelection();u?.removeAllRanges(),u?.addRange(d)};var K={color:"color",background:"background-color"},St=new Set(["p","h1","h2","h3","h4","h5","h6","blockquote","pre","ul","ol","li","table","thead","tbody","tfoot","tr","td","th","caption","colgroup","figure","figcaption"]),_e=(e,n)=>He({version:1,children:[{type:"element",tag:e,attributes:n,children:[]}]}).children[0].attributes,le=(e,n)=>{if(n===!1)return!1;if(typeof n!="string"||!n.trim()||n.length>128||/[;{}]/.test(n))throw new TypeError("Expected a CSS color or false.");let t=K[e],r=_e("span",{style:`${t}: ${n}`}),s=document.createElement("span");s.setAttribute("style",r.style??"");let i=s.style.getPropertyValue(t);if(!i)throw new TypeError("Unsupported or invalid CSS color.");return i},Nt=e=>{if(e===!1)return!1;let n=typeof e=="string"?{href:e}:e;if(!n||typeof n!="object"||Array.isArray(n)||!("href"in n)||typeof n.href!="string")throw new TypeError("Expected a link URL, LinkFormat or false.");let t=n,r={href:n.href};if(t.title!==void 0){if(typeof t.title!="string"||t.title.length>1024)throw new TypeError("Link title must be a string up to 1024 characters.");r.title=t.title}if(t.target!==void 0){if(t.target!=="_self"&&t.target!=="_blank")throw new TypeError("Link target must be _self or _blank.");r.target=t.target}if(t.text!==void 0&&(typeof t.text!="string"||!t.text.length||t.text.length>2e4))throw new TypeError("New link text must contain 1\u201320000 characters.");let s=_e("a",r);if(!s.href)throw new TypeError("Unsupported or unsafe link URL.");return{attributes:s,...typeof t.text=="string"?{text:t.text}:{}}},Je=(e,n)=>{let t={...e,...n};return t.title||delete t.title,n.target==="_self"&&delete t.rel,_e("a",t)},Mt=(e,n)=>JSON.stringify(Object.entries(e??{}).sort())===JSON.stringify(Object.entries(n??{}).sort()),an=(e,n)=>{let t={...e},r=(t.style??"").split(";").map(s=>s.trim()).filter(s=>s&&s.slice(0,s.indexOf(":")).trim()!==n).join("; ");return r?t.style=r:delete t.style,t},Lt=e=>{let n=[];for(let t of e){let r=n.at(-1);r&&r.selected===t.selected&&Mt(r.link,t.link)?r.pieces.push(t):n.push({pieces:[t],selected:t.selected,link:t.link})}return n},We=e=>{let n=[];for(let t of e){let r=t.type==="element"?{...t,children:We(t.children)}:t,s=n.at(-1);r.type==="text"&&s?.type==="text"?s.text+=r.text:r.type==="element"&&s?.type==="element"&&!St.has(r.tag)&&!r.attributes["data-mw-node"]&&!["img","br","hr"].includes(r.tag)&&s.tag===r.tag&&Mt(s.attributes,r.attributes)?s.children=We([...s.children,...r.children]):n.push(r)}return n},Oe=(e,n,t,r)=>{let s=0,i=a=>Lt(a).flatMap(o=>{let d=o.pieces.map(f=>f.node);if(r.kind==="style")return o.selected&&r.value!==!1?[{type:"element",tag:"span",attributes:{style:`${r.property}: ${r.value}`},children:d}]:d;let u=o.selected?r.attributes===!1?void 0:Je(o.link??{},r.attributes):o.link;return u?[{type:"element",tag:"a",attributes:u,children:d}]:d}),c=(a,o)=>{if(a.type==="text"){let f=s;s+=a.text.length;let m=Math.max(0,Math.min(a.text.length,n-f)),g=Math.max(m,Math.min(a.text.length,t-f));return[[0,m,!1],[m,g,!0],[g,a.text.length,!1]].flatMap(([h,x,N])=>{let w=a.text.slice(h,x);return w?[{node:{type:"text",text:w},selected:!!N,link:o}]:[]})}let d=r.kind==="link"&&a.tag==="a"?a.attributes:o;if(!a.children.length)return[{node:a,selected:s>=n&&s<t,link:d}];let u=a.children.flatMap(f=>c(f,d));return r.kind==="link"&&a.tag==="a"?u:St.has(a.tag)||a.attributes["data-mw-node"]?[{node:{...a,children:i(u)},selected:!1}]:Lt(u).flatMap(f=>{let m=r.kind==="style"&&f.selected?an(a.attributes,r.property):a.attributes,g=f.pieces.map(h=>h.node);return a.tag==="span"&&!Object.keys(m).length?f.pieces:[{node:{...a,attributes:m,children:g},selected:f.selected,link:f.link}]})};return{version:1,children:We(i(e.children.flatMap(a=>c(a))))}};var Ct=(e,n,t)=>{let r=Nt(n),s=C(e);if(!s)return;let i=v(e),c=s.startContainer.nodeType===1?s.startContainer:s.startContainer.parentElement,a=c?.closest("a"),o=a&&e.contains(a)?a:void 0;if(r&&r.text!==void 0&&(!s.collapsed||o))throw new TypeError("Link text is only supported for insertion at a caret outside links.");if(!s.collapsed){e.innerHTML=(t?.documentHTML??U)(Oe((t?.parseHTML??z)(e.innerHTML),i.index,i.index+i.length,{kind:"link",attributes:r&&r.attributes})),j(e,i.index,i.length);return}if(o){let g=r&&Je(Object.fromEntries([...o.attributes].map(h=>[h.name,h.value])),r.attributes);J(e,()=>{if(!g)o.replaceWith(...o.childNodes);else{for(let h of[...o.attributes])o.removeAttribute(h.name);for(let[h,x]of Object.entries(g))o.setAttribute(h,x)}});return}if(!r||r.text===void 0)return;let d=e.ownerDocument.createElement("a");for(let[g,h]of Object.entries(r.attributes))d.setAttribute(g,h);d.textContent=r.text;let u=c?.closest("p,li,h1,h2,h3,h4,h5,h6,blockquote,pre,td,th");u?.childNodes.length===1&&u.firstChild instanceof HTMLBRElement&&(u.firstChild.remove(),s.setStart(u,0)),s.insertNode(d);let f=e.ownerDocument.createTextNode("");d.after(f),s.setStart(f,0),s.collapse(!0);let m=e.ownerDocument.getSelection();m?.removeAllRanges(),m?.addRange(s)};var ln=new Set(["p","h1","h2","h3","h4","h5","h6","blockquote","pre","ul","ol","li","table","thead","tbody","tfoot","tr","td","th","caption","colgroup","figure","figcaption"]),Ht=e=>e.type==="text"?e.text.length:e.children.reduce((n,t)=>n+Ht(t),0),we=(e,n,t,r,s)=>{let i=0,c=a=>{if(a.type==="text"){let u=i;i+=a.text.length;let f=Math.max(0,Math.min(a.text.length,n-u)),m=Math.max(f,Math.min(a.text.length,t-u));return[[0,f,!1],[f,m,!0],[m,a.text.length,!1]].flatMap(([g,h,x])=>{let N=a.text.slice(g,h);if(!N)return[];let w={type:"text",text:N};return[{node:x&&s?{type:"element",tag:r,attributes:{},children:[w]}:w,selected:!!x}]})}if(s&&a.tag===r)return i+=Ht(a),[{node:a,selected:!1}];let o=a.children.flatMap(c);if(ln.has(a.tag)||a.attributes["data-mw-node"])return[{node:{...a,children:o.map(u=>u.node)},selected:!1}];if(!o.length)return[{node:a,selected:!1}];let d=[];for(let u of o){let f=d.at(-1);f?.selected===u.selected?f.children.push(u.node):d.push({selected:u.selected,children:[u.node]})}return d.flatMap(u=>a.tag===r&&!s&&u.selected?u.children.map(f=>({node:f,selected:!0})):[{node:{...a,children:u.children},selected:u.selected}])};return{version:1,children:e.children.flatMap(c).map(a=>a.node)}};var Dt="p,h1,h2,h3,h4,h5,h6",cn=new Set(["strong","em","u","s","sub","sup","a","span","code"]),dn=new Set(["blockquote","ul","ol","li","table","thead","tbody","tfoot","tr","td","th"]),At=e=>e.nodeType===1?e:e.parentElement,Rt=e=>{for(let n of e.childNodes){if(n.nodeType===3)continue;if(n.nodeType!==1)return!1;let t=n;if(t.namespaceURI!=="http://www.w3.org/1999/xhtml"||!cn.has(t.localName)||!Rt(t))return!1}return!0},Ot=(e,n,t,r,s)=>{let i=At(n.startContainer)?.closest(Dt);if(!i||!e.contains(i)||i.namespaceURI!=="http://www.w3.org/1999/xhtml"||At(n.endContainer)?.closest(Dt)!==i||!Rt(i))return!1;for(let h=i.parentElement;h&&h!==e;h=h.parentElement)if(h.namespaceURI!=="http://www.w3.org/1999/xhtml"||!dn.has(h.localName))return!1;let c=e.ownerDocument.createRange();c.selectNodeContents(i),c.setEnd(n.startContainer,n.startOffset);let a=c.toString().length,o=n.toString().length;if(!o||a+o>(i.textContent?.length??0))return!1;let d=e.ownerDocument.getSelection(),u=d?.anchorNode===n.endContainer&&d.anchorOffset===n.endOffset,f=we((s?.parseHTML??z)(i.outerHTML),a,a+o,t,r),m=(s?.renderDocument??fe)(f),g=m.firstElementChild;if(m.childNodes.length!==1||!(g instanceof HTMLElement)||g.localName!==i.localName)return!1;if(g.normalize(),g.outerHTML===i.outerHTML)return!0;if(i.replaceWith(m),j(g,a,o),e.focus({preventScroll:!0}),u&&d?.rangeCount){let h=d.getRangeAt(0);d.setBaseAndExtent(h.endContainer,h.endOffset,h.startContainer,h.startOffset)}return!0};var ce={bold:"strong",italic:"em",underline:"u",strike:"s",code:"code",subscript:"sub",superscript:"sup"},un=e=>e.nodeType===1?e:e.parentElement,vt=(e,n)=>{let t=un(n),r={};for(;t&&t!==e;){for(let[s,i]of Object.entries(ce))t.localName===i&&(r[s]=!0);if(/^h[1-6]$/.test(t.localName)&&r.header===void 0&&(r.header=Number(t.localName[1])),t.localName==="blockquote"&&(r.blockquote=!0),t.localName==="pre"&&(r["code-block"]=!0),(t.localName==="ul"||t.localName==="ol")&&r.list===void 0&&(r.list=t.localName==="ul"?"bullet":"ordered"),t.localName==="a"&&r.link===void 0&&(r.link=t.getAttribute("href"),r.linkTitle=t.getAttribute("title")??"",r.linkTarget=t.getAttribute("target")??"_self"),t instanceof HTMLElement)for(let[s,i]of Object.entries(K))r[s]===void 0&&t.style.getPropertyValue(i)&&(r[s]=t.style.getPropertyValue(i));t instanceof HTMLElement&&t.style.textAlign&&r.align===void 0&&(r.align=t.style.textAlign),t=t.parentElement}return r},ve=e=>{let n=C(e);if(!n)return{};let t=vt(e,n.startContainer),r=new Set;if(!n.collapsed){let{index:s,length:i}=v(e),c=e.ownerDocument.createTreeWalker(e,NodeFilter.SHOW_TEXT),a=0,o,d=[];for(;o=c.nextNode();){let m=a+o.textContent.length;m>s&&a<s+i&&d.push(vt(e,o)),a=m}d.length&&(t=d[0]);let u=[...Object.keys(ce),"header","list","blockquote","code-block","link","linkTitle","linkTarget","color","background","align"],f=(m,g)=>m[g]??(g==="align"?"left":g==="header"?0:!1);for(let m of u)d.some(g=>f(g,m)!==f(d[0],m))&&r.add(m)}return{...t,align:t.align??"left",mixed:[...r],...Ee(e)}},Xe=(e,n,t,r)=>{let s=C(e);if(!s)return;let i=ce[n];if(i&&!s.collapsed&&Ot(e,s,i,!!t,r))return;let c=v(e);if(n==="list"){Tt(e,t);return}if(n==="indent"){Ae(e,t);return}if(n==="clear"){if(t!==!0||!c.length)return;let o=(r?.parseHTML??z)(e.innerHTML);for(let d of[...Object.values(ce),"a","span"])o=we(o,c.index,c.index+c.length,d,!1);e.innerHTML=(r?.documentHTML??U)(o),j(e,c.index,c.length);return}if(i){if(s.collapsed)return;e.innerHTML=(r?.documentHTML??U)(we((r?.parseHTML??z)(e.innerHTML),c.index,c.index+c.length,i,!!t)),j(e,c.index,c.length);return}if(n==="link"){Ct(e,t,r);return}if(Object.hasOwn(K,n)){let o=le(n,t);if(!c.length)return;e.innerHTML=(r?.documentHTML??U)(Oe((r?.parseHTML??z)(e.innerHTML),c.index,c.index+c.length,{kind:"style",property:K[n],value:o})),j(e,c.index,c.length);return}let a=ae(e,s,!1);if(!a.length){let o=document.createElement("p");o.append(s.extractContents()),o.childNodes.length||o.append(document.createElement("br")),s.insertNode(o),a=[o]}J(e,()=>{for(let o of a){if(n==="align"&&["left","center","right","justify",!1].includes(t)){o.style.textAlign=t?String(t):"";continue}let d=n==="header"?Number.isInteger(t)&&Number(t)>=1&&Number(t)<=6?`h${t}`:"p":n==="blockquote"?t?"blockquote":"p":n==="code-block"?t?"pre":"p":void 0;if(d){if(o.hasAttribute("data-mw-node")&&o.localName!==d)throw new RangeError("Cannot change the tag of a registered semantic node.");let u=document.createElement(d);if(o.localName==="li"){let f=[...o.childNodes].filter(m=>!(m instanceof Element&&/^(ul|ol|p|h[1-6]|pre|blockquote)$/.test(m.localName)));u.append(...f),o.prepend(u)}else u.append(...o.childNodes),u.setAttribute("style",o.getAttribute("style")??""),o.replaceWith(u)}}})};var It=new WeakSet,mn=new Set(["change","selectionchange","readonlychange","localechange","destroy"]),fn=e=>{if(typeof e!="string"||!e.trim()||e.length>200)throw new TypeError("Expected an event name with 1\u2013200 characters.");let n=Object.freeze({name:e});return It.add(n),n},jt=e=>{if(!e||typeof e!="object"||!It.has(e))throw new TypeError("Expected a plugin event token. Core events cannot be emitted publicly.");return e},Bt=()=>{let e=new Map,n=[],t=0,r=!1,s=!1,i=o=>{if(s&&o.key!=="destroy"||(n.push(o),r))return;r=!0;let d=[];try{for(;n.length;){let u=n.shift();if(s&&u.key!=="destroy")continue;let f=e.get(u.key);for(let[m,g]of[...f??[]])if(!(s&&u.key!=="destroy"||f?.get(m)!==g))try{let h=u.core&&u.payload&&typeof u.payload=="object"?u.key==="localechange"?{...u.payload,translations:{...u.payload.translations}}:{...u.payload}:u.payload;m(h)}catch(h){d.push(h)}u.key==="destroy"&&(e.clear(),n.length=0)}}finally{r=!1}if(d.length)throw new AggregateError(d,"Editor event listeners failed.")};return{events:{on:(o,d)=>{if(s)throw new Error("Editor events have been destroyed.");if(typeof d!="function")throw new TypeError("Expected an event listener.");let u=typeof o=="string"&&mn.has(o)?o:jt(o),f=e.get(u);f||(f=new Map,e.set(u,f)),f.has(d)||f.set(d,++t);let m=f.get(d);return()=>{f.get(d)===m&&(f.delete(d),!f.size&&e.get(u)===f&&e.delete(u))}},emit:(o,d)=>{if(s)throw new Error("Editor events have been destroyed.");i({key:jt(o),payload:d,core:!1})}},notify:(o,d)=>i({key:o,payload:d,core:!0}),destroy:()=>{s||(s=!0,n.length=0,i({key:"destroy",payload:void 0,core:!0}))}}};var qt=(e,n=Be)=>{let t,r="";return{read:()=>{let c=e.innerHTML;if(c===t)return r;let a=n(c);return t=c,r=a,a},clear:()=>{t=void 0,r=""}}};var Ve=(e,n={})=>{if(typeof e!="string"||!e||e.length>100)throw new TypeError("Expected a language tag with 1\u2013100 characters.");let t=Intl.getCanonicalLocales(e)[0];if(!t)throw new RangeError("Expected a valid language tag.");if(!n||typeof n!="object"||Array.isArray(n))throw new TypeError("Translations must be a record of strings.");let r=Object.getPrototypeOf(n);if(r!==Object.prototype&&r!==null)throw new TypeError("Translations must be a plain record of strings.");let s=Object.entries(n);if(s.some(([i,c])=>!i||typeof c!="string"))throw new TypeError("Translation keys must be nonempty and values must be strings.");return{locale:t,translations:Object.fromEntries(s)}},re=(e,n,t)=>{let r=Object.hasOwn(e.translations,n)?e.translations[n]:void 0,s=Object.hasOwn(t,e.locale)?t[e.locale]:void 0,i=e.locale.split("-")[0],c=Object.hasOwn(t,i)?t[i]:void 0,a=d=>d&&Object.hasOwn(d,n)?d[n]:void 0,o=r??a(s)??a(c)??a(t.en);if(typeof o!="string")throw new Error(`Missing English fallback for translation: ${n}`);return o};var Pt=e=>e.isComposing||e.inputType==="insertCompositionText"||e.inputType==="insertFromComposition"||e.inputType==="deleteCompositionText",oe=e=>{let n=!1;e.childNodes.length||(e.innerHTML="<p><br></p>",n=!0);let t;for(let r of[...e.childNodes])r.nodeType===3||r.nodeType===1&&/^(strong|em|u|s|a|span|code|img|br|sub|sup)$/.test(r.localName)?(t||(t=document.createElement("p"),e.insertBefore(t,r)),t.append(r),n=!0):t=void 0;return["table","figure"].includes(e.lastElementChild?.localName??"")&&e.append(Object.assign(document.createElement("p"),{innerHTML:"<br>"})),e.dataset.empty=String(!e.textContent&&!e.querySelector("table,img,hr")),n},pn=(e,n,t)=>{let r=C(e);if(!r)return;let s=t.renderDocument(t.parseHTML(n));if(!s.childNodes.length)return;r.deleteContents();let c=(r.startContainer.nodeType===1?r.startContainer:r.startContainer.parentElement)?.closest("p,h1,h2,h3,h4,h5,h6,li,blockquote,pre");if(s.childNodes.length===1&&s.firstChild instanceof HTMLParagraphElement&&c){let f=s.firstChild;s.replaceChildren(...f.childNodes)}let a=[...s.childNodes].some(f=>f instanceof HTMLElement&&/^(p|h[1-6]|ul|ol|table|figure|blockquote|pre)$/.test(f.localName)),o=s.lastChild;if(a&&c&&e.contains(c)){let f=document.createRange();f.selectNodeContents(c),f.setStart(r.startContainer,r.startOffset);let m=c.cloneNode(!1);m.append(f.extractContents()),c.after(s),(m.textContent||m.querySelector("img,br"))&&o.after(m),!c.textContent&&!c.querySelector("img")&&c.remove()}else r.insertNode(s);let d=document.createRange();d.setStartAfter(o),d.collapse(!0);let u=document.getSelection();u?.removeAllRanges(),u?.addRange(d)},hn=(e,n={})=>{if(e.childNodes.length)throw new Error("Editor host must be empty. Pass initial HTML through value.");let t=n.plugins??[];if(new Set(t.map(l=>l.name)).size!==t.length)throw new Error("Duplicate editor plugin.");let r=n.historyLimit??100;if(!Number.isInteger(r)||r<1||r>1e4)throw new RangeError("historyLimit must be an integer from 1 to 10000.");let s=Pe([...n.schema??[],...t.flatMap(l=>l.schema??[])]),i=s.parseHTML(n.value??""),c=Ve(n.locale??"ru",n.translations),a=document.createElement("div");a.className="mw-editor";let o=document.createElement("div");o.className="mw-content",o.setAttribute("role","textbox"),o.setAttribute("aria-multiline","true");let d=()=>{o.setAttribute("aria-label",n.label??re(c,"editor.label",me)),o.dataset.placeholder=n.placeholder??re(c,"editor.placeholder",me)};d(),a.append(o),e.append(a),o.append(s.renderDocument(i)),oe(o);let u=!1,f=n.readOnly??!1,m=!1,g,h=!1,x,N=!1,w,F=0,b="",y={},M,k=()=>{y={},M=void 0},H=()=>{let l=v(o);return l?.length===0&&l.index===M},D=[],W=[],$=Bt(),X=0,xe=!1,ke,de=!1,ue=new Map,Le=[];n.onChange&&$.events.on("change",n.onChange);let L=()=>{if(u)throw new Error("Editor has been destroyed.")},V=l=>{if(!X)return;let p=new Error(`${l} is unavailable inside a transaction.`);throw xe=!0,ke=p,p},zt={on:$.events.on,emit:(l,p)=>{L(),V("events.emit"),$.events.emit(l,p)}},Se=qt(o,s.sanitizeHTML),B=()=>({html:Se.read(),selection:he(o),...M!==void 0&&Object.keys(y).length&&H()?{typing:{offset:M,formats:{...y}}}:{}}),je=l=>{k();let p=v(o);l.typing&&p?.length===0&&p.index===l.typing.offset&&(M=l.typing.offset,y={...l.typing.formats})},A=B(),Q=A.selection,G=()=>{x=void 0,N=!1},Ie=l=>{let p=g;h=h||m||x!==void 0,m=!1,g=void 0,w=void 0,G(),l&&p&&(o.innerHTML=p.html,oe(o),_(o,p.selection),je(p),A=B(),Q=A.selection)},Qe=()=>{o.innerHTML=A.html,oe(o),_(o,A.selection)},Z=()=>{if(u)return;if(X){de=!0;return}v(o)&&!H()&&k();let l=he(o);l&&(Q=l,A.selection=l),$.notify("selectionchange",v(o))},se=l=>{let p={html:S.getHTML(),text:S.getText(),source:l},E=[];try{$.notify("change",p)}catch(T){E.push(T)}try{Z()}catch(T){E.push(T)}if(E.length)throw new AggregateError(E,"Editor change notification failed.")},Ne=(l,p="")=>{let E=v(o);oe(o)&&E&&j(o,E.index,E.length);let T=B();if(T.html===l.html)return A=T,!1;let R=Date.now();return p===b&&["insertText","deleteContentBackward","deleteContentForward"].includes(p)&&R-F<600&&l.selection&&A.selection&&JSON.stringify(l.selection)===JSON.stringify(A.selection)||(D.push(l),D.length>r&&D.shift()),W.length=0,A=T,F=p?R:0,b=p,!0},Kt=(l,p="")=>{Ne(l,p)&&se("user")},Ge=l=>{k(),o.innerHTML=l.html,oe(o),o.focus({preventScroll:!0}),_(o,l.selection),je(l),A=B(),Q=A.selection,F=0,se("user")},ee=(l,p="")=>{if(L(),f||m)return;G();let E=()=>{if(typeof l!="function"||l.constructor.name==="AsyncFunction")throw new TypeError("Transactions require a synchronous callback.");let P=l(o);if(P&&(typeof P=="object"||typeof P=="function")&&typeof P.then=="function")throw P instanceof Promise&&P.catch(()=>{}),new TypeError("Transaction callbacks must not return a thenable.")};if(X){X++;try{E()}catch(P){throw xe=!0,ke=P,P}finally{X--}return}S.focus();let T=B(),R=[...D],q=[...W],Ze=F,Y=b,ie=w,Me=Q;X=1,xe=!1,ke=void 0,de=!1;let et=!1;try{if(E(),xe)throw ke;et=Ne(T,p)}catch(P){throw o.innerHTML=T.html,oe(o),_(o,T.selection),je(T),A=B(),Q=Me,w=ie,D.splice(0,D.length,...R),W.splice(0,W.length,...q),F=Ze,b=Y,X=0,de=!1,P}finally{X=0}let Ft=de;de=!1,et?se("user"):Ft&&Z()},Ye=ct({editor:()=>S,isComposing:()=>m,assertActive:L}),S={element:a,surface:o,events:zt,schema:s,commands:Ye.commands,getLocale:()=>(L(),{locale:c.locale,translations:{...c.translations}}),setLocale:(l,p)=>{L(),V("setLocale");let E=Ve(l,p),T=Object.keys(E.translations);c.locale===E.locale&&T.length===Object.keys(c.translations).length&&T.every(R=>Object.hasOwn(c.translations,R)&&c.translations[R]===E.translations[R])||(c=E,d(),$.notify("localechange",S.getLocale()))},getHTML:()=>(L(),Se.read()),getText:()=>(L(),o.innerText),getJSON:()=>(L(),s.parseHTML(o.innerHTML)),setHTML:l=>{L(),V("setHTML");let p=s.documentHTML(s.parseHTML(l));p!==S.getHTML()&&(Ie(!1),k(),o.innerHTML=p,oe(o),D.length=0,W.length=0,F=0,Q=void 0,A=B(),se("api"))},setJSON:l=>{L(),V("setJSON");let p=s.validateDocument(l);S.setHTML(s.documentHTML(p))},getSelection:()=>(L(),v(o)),setSelection:(l,p=0)=>{L(),j(o,l,p),Z()},getFormats:()=>(L(),{...ve(o),...H()?y:{}}),setReadOnly:l=>{L(),V("setReadOnly");let p=f!==l;p&&l&&Ie(!0),f=l,o.contentEditable=String(!l),o.setAttribute("aria-readonly",String(l)),a.dataset.readonly=String(l);let E=[];if(p)try{$.notify("readonlychange",l)}catch(T){E.push(T)}try{Z()}catch(T){E.push(T)}if(E.length)throw new AggregateError(E,"Editor state notification failed.")},isReadOnly:()=>(L(),f),format:(l,p)=>{if(L(),f||m)return;G(),S.focus();let E=v(o);if(E?.length===0&&(Object.hasOwn(ce,l)||Object.hasOwn(K,l))){H()||k(),M=E.index,y[l]=Object.hasOwn(K,l)?le(l,p):!!p,Z();return}k(),S.transact(()=>Xe(o,l,p,s))},insertHTML:l=>S.transact(()=>pn(o,l,s)),focus:()=>{L(),o.focus({preventScroll:!0}),C(o)||(Q?_(o,Q):ne(o.firstElementChild??o,!0))},undo:()=>{if(L(),V("undo"),f||m)return;G();let l=D.pop();l&&(W.push(B()),Ge(l))},redo:()=>{if(L(),V("redo"),f||m)return;G();let l=W.pop();l&&(D.push(B()),Ge(l))},canUndo:()=>(L(),D.length>0),canRedo:()=>(L(),W.length>0),transact:l=>ee(l),providePlugin:(l,p)=>{if(L(),ue.has(l))throw new Error(`Plugin API already registered: ${l}`);return ue.set(l,p),()=>{ue.delete(l)}},getPlugin:l=>(L(),ue.get(l)),subscribe:l=>(L(),$.events.on("change",l)),onSelectionChange:l=>(L(),$.events.on("selectionchange",l)),destroy:()=>{if(u)return;V("destroy"),Ie(!1),u=!0;let l=[];try{$.destroy()}catch(p){l.push(p)}for(let p of Le.reverse())try{p()}catch(E){l.push(E)}if(Ye.destroy(),ue.clear(),D.length=0,W.length=0,Se.clear(),a.remove(),l.length)throw new AggregateError(l,"Editor cleanup failed.")}},te=(l,p)=>{o.addEventListener(l,p),Le.push(()=>o.removeEventListener(l,p))};te("beforeinput",l=>{if(l.defaultPrevented)return;if(f){l.preventDefault();return}let p=Pt(l);if(h&&p){l.preventDefault();return}if(!(m||l.isComposing)){if(p||(h=!1,G()),l.inputType==="historyUndo"||l.inputType==="historyRedo"){l.preventDefault(),l.inputType==="historyUndo"?S.undo():S.redo();return}if(!m&&!l.isComposing&&Ke(o,l.inputType)){l.preventDefault(),k(),w=void 0,ee(()=>Fe(o,l.inputType));return}if(Te(o,l.inputType)){l.preventDefault(),k(),w=void 0,ee(()=>Re(o,l.inputType));return}if(l.inputType==="insertText"&&l.data&&!m&&!l.isComposing&&H()&&Object.keys(y).length){l.preventDefault();let E=v(o).index,T=l.data,R={...y};ee(()=>{let q=C(o),Y=(q.startContainer instanceof Element?q.startContainer:q.startContainer.parentElement)?.closest("p,h1,h2,h3,h4,h5,h6,li,blockquote,pre");Y&&!Y.textContent&&Y.childNodes.length===1&&Y.firstChild instanceof HTMLBRElement&&(Y.replaceChildren(),q.selectNodeContents(Y),q.collapse(!0)),q.insertNode(document.createTextNode(T)),j(o,E,T.length);for(let[ie,Me]of Object.entries(R))(Object.hasOwn(K,ie)?ve(o)[ie]??!1:!!ve(o)[ie])!==Me&&Xe(o,ie,Me,s);j(o,E+T.length),M=E+T.length},"insertText"),w=void 0;return}w=B()}}),te("input",l=>{let p=l,E=Pt(p);if(f||h&&E){Qe();return}if(m||p.isComposing)return;if(x&&E){let R=x,q=Se.read()!==A.html;if(w=void 0,!q)return;N&&D.at(-1)===R&&D.pop(),N=Ne(R),se("user");return}h=!1,G();let T=w??A;w=void 0,Kt(T,p.inputType)}),te("compositionstart",()=>{if(f){h=!0;return}m||(k(),G(),w=void 0,h=!1,g=B(),m=!0)}),te("compositionend",()=>{if(h){w=void 0,Qe();return}m=!1;let l=g;g=void 0,w=void 0,l&&(x=l,N=Ne(l),N&&se("user"))}),te("paste",l=>{if(l.preventDefault(),f||m||!l.clipboardData)return;S.focus();let p=l.clipboardData.getData("text/html");if(p)S.insertHTML(p);else{let E=l.clipboardData.getData("text/plain"),T=document.createElement("div");T.textContent=E,S.insertHTML(T.innerHTML.replace(/\r?\n/g,"<br>"))}}),te("drop",l=>{l.preventDefault()}),te("keydown",l=>{if(l.keyCode===229)return;if(!m&&!l.isComposing&&!f&&!l.ctrlKey&&!l.metaKey&&!l.altKey&&(l.key==="Enter"||l.key==="Backspace"||l.key==="Delete")){let T=l.key==="Backspace"?"deleteContentBackward":l.key==="Delete"?"deleteContentForward":l.shiftKey?"insertLineBreak":"insertParagraph";if(Ke(o,T)){l.preventDefault(),k(),w=void 0,ee(()=>Fe(o,T));return}if((l.key!=="Enter"||l.shiftKey)&&Te(o,T)){l.preventDefault(),k(),w=void 0,ee(()=>Re(o,T));return}}if(!m&&!l.isComposing&&!f&&l.key==="Tab"&&!l.ctrlKey&&!l.metaKey&&!l.altKey){let T=ae(o);if(T.length&&T.every(R=>R.localName==="li"&&!R.closest("td,th"))&&Ee(o).canOutdent){l.preventDefault(),k(),ee(()=>Ae(o,l.shiftKey?-1:1));return}}if(m||l.isComposing||f||!(l.ctrlKey||l.metaKey)||l.altKey)return;let p=l.key.toLowerCase();(p==="z"||p==="y")&&(l.preventDefault(),p==="y"||l.shiftKey?S.redo():S.undo());let E={b:"bold",i:"italic",u:"underline"}[p];E&&(l.preventDefault(),S.format(E,S.getFormats().mixed?.includes(E)||!S.getFormats()[E]))}),document.addEventListener("selectionchange",Z),Le.push(()=>document.removeEventListener("selectionchange",Z));try{S.setReadOnly(f);for(let l of t){let p=l.setup(S);p&&Le.push(p)}return S}catch(l){throw S.destroy(),l}};var gn=()=>[{translationKey:"toolbar.undo",label:O.ru["toolbar.undo"],text:"\u21B6",run:e=>e.undo(),enabled:e=>e.canUndo()},{translationKey:"toolbar.redo",label:O.ru["toolbar.redo"],text:"\u21B7",run:e=>e.redo(),enabled:e=>e.canRedo()},{translationKey:"toolbar.bold",label:O.ru["toolbar.bold"],text:"B",format:"bold"},{translationKey:"toolbar.italic",label:O.ru["toolbar.italic"],text:"I",format:"italic"},{translationKey:"toolbar.underline",label:O.ru["toolbar.underline"],text:"U",format:"underline"},{translationKey:"toolbar.header",label:O.ru["toolbar.header"],text:"H\u2082",format:"header",value:2},{translationKey:"toolbar.bulletList",label:O.ru["toolbar.bulletList"],text:"\u2637",format:"list",value:"bullet"},{translationKey:"toolbar.orderedList",label:O.ru["toolbar.orderedList"],text:"1.",format:"list",value:"ordered"},{translationKey:"toolbar.indent",label:O.ru["toolbar.indent"],text:"\u21E5",format:"indent",value:1,enabled:e=>!!e.getFormats().canIndent},{translationKey:"toolbar.outdent",label:O.ru["toolbar.outdent"],text:"\u21E4",format:"indent",value:-1,enabled:e=>!!e.getFormats().canOutdent},{translationKey:"toolbar.blockquote",label:O.ru["toolbar.blockquote"],text:"\u275D",format:"blockquote"},{translationKey:"toolbar.clear",label:O.ru["toolbar.clear"],text:"Tx",format:"clear",enabled:e=>!!e.getSelection()?.length}],bn=(e,n,t,r={})=>{let s=t===void 0?gn():[],i=s.map(b=>b.translationKey),c=(t??s).map(b=>b.format&&Object.hasOwn(K,b.format)?{...b,value:le(b.format,b.value)}:b),a=document.createElement("div");a.className="mw-toolbar",a.setAttribute("role","toolbar");let o,d=!1,u=0,f=[],m=c.map(b=>{let y=document.createElement("button");y.type="button",y.textContent=b.text,y.title=b.label,y.setAttribute("aria-label",b.label);let M=H=>H.preventDefault(),k=()=>{if(!(d||y.disabled||n.isReadOnly())&&(n.focus(),o&&_(n.surface,o),!(b.enabled&&!b.enabled(n)))){if(b.run)b.run(n);else if(b.format){let H=n.getFormats(),D=H.mixed?.includes(b.format);n.format(b.format,!D&&H[b.format]===(b.value??!0)?!1:b.value??!0)}h()}};return y.addEventListener("mousedown",M),y.addEventListener("click",k),f.push(()=>{y.removeEventListener("mousedown",M),y.removeEventListener("click",k)}),a.append(y),y}),g=(b=n.getLocale())=>{d||(a.setAttribute("aria-label",r.label??re(b,"toolbar.label",O)),m.forEach((y,M)=>{let k=i[M],H=k?re(b,k,O):c[M].label;y.title=H,y.setAttribute("aria-label",H)}))},h=()=>{if(d)return;o=he(n.surface)??o;let b=n.getFormats();m.forEach((y,M)=>{let k=c[M];y.disabled=n.isReadOnly()||(k.enabled?!k.enabled(n):!1),k.format&&!["indent","clear"].includes(k.format)&&y.setAttribute("aria-pressed",b.mixed?.includes(k.format)?"mixed":String(b[k.format]===(k.value??!0)))}),(m[u]?.disabled||!m[u])&&(u=m.findIndex(y=>!y.disabled)),m.forEach((y,M)=>{y.tabIndex=M===u?0:-1})},x=b=>{let y=m.filter(D=>!D.disabled);if(!y.length)return;let M=y.indexOf(document.activeElement);if(M<0||b.ctrlKey||b.metaKey||b.altKey)return;if(b.key==="Escape"){b.preventDefault(),n.focus(),o&&_(n.surface,o);return}let k=getComputedStyle(a).direction==="rtl"?-1:1,H=b.key==="Home"?0:b.key==="End"?y.length-1:b.key==="ArrowRight"?(M+k+y.length)%y.length:b.key==="ArrowLeft"?(M-k+y.length)%y.length:-1;H>=0&&(b.preventDefault(),u=m.indexOf(y[H]),h(),y[H].focus())};a.addEventListener("keydown",x);let N=n.subscribe(b=>{b.source==="api"&&(o=void 0),h()}),w=n.onSelectionChange(h),F=n.events.on("localechange",g);return e.append(a),g(),h(),()=>{if(!d){d=!0,N(),w(),F(),a.removeEventListener("keydown",x);for(let b of f)b();a.remove()}}};export{Pe as createDocumentSchema,hn as createEditor,Gt as createEditorCommand,fn as createPluginEvent,bn as createToolbar,me as editorMessages,re as localize,Be as sanitizeHTML,O as toolbarMessages};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|