@formulaxjs/tiptap 0.1.0 → 0.2.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/README.md CHANGED
@@ -72,6 +72,26 @@ To open the FormulaX modal programmatically:
72
72
  editor.commands.openFormulaX();
73
73
  ```
74
74
 
75
+ ## Custom node names
76
+
77
+ The default Tiptap node name is `formulaX`.
78
+
79
+ If the host editor already uses that name, pass a custom `name` when creating the extension:
80
+
81
+ ```ts
82
+ const editor = new Editor({
83
+ element: document.querySelector('#editor')!,
84
+ extensions: [
85
+ StarterKit,
86
+ createFormulaXNode(undefined, {
87
+ name: 'inlineMath',
88
+ }),
89
+ ],
90
+ });
91
+ ```
92
+
93
+ If Tiptap detects that the configured node name is already registered, the extension logs a `console.warn` message so you can rename it before the schema collides.
94
+
75
95
  ## Persisted data
76
96
 
77
97
  The Tiptap node stores only the LaTeX source:
@@ -91,6 +111,7 @@ The node view renders formula SVG at runtime from the stored LaTeX. Generated DO
91
111
 
92
112
  ```ts
93
113
  interface FormulaXTiptapOptions {
114
+ name?: string;
94
115
  formulaClassName?: string;
95
116
  formulaAttributeName?: string;
96
117
  cursorStyle?: string;
@@ -115,6 +136,7 @@ interface FormulaXTiptapOptions {
115
136
 
116
137
  | Option | Default | Description |
117
138
  | --- | --- | --- |
139
+ | `name` | `formulaX` | Tiptap node name used in the document schema. |
118
140
  | `formulaClassName` | `formulax-math` | CSS class used by rendered formula nodes. |
119
141
  | `formulaAttributeName` | `data-formulax-latex` | Attribute used in rendered DOM for the source LaTeX. |
120
142
  | `cursorStyle` | `pointer` | Cursor style applied to rendered formula nodes. |
package/README.zh-CN.md CHANGED
@@ -72,6 +72,26 @@ const editor = new Editor({
72
72
  editor.commands.openFormulaX();
73
73
  ```
74
74
 
75
+ ## 自定义节点名称
76
+
77
+ 默认的 Tiptap 节点名是 `formulaX`。
78
+
79
+ 如果宿主编辑器里已经存在同名节点,可以在创建扩展时传入自定义 `name`:
80
+
81
+ ```ts
82
+ const editor = new Editor({
83
+ element: document.querySelector('#editor')!,
84
+ extensions: [
85
+ StarterKit,
86
+ createFormulaXNode(undefined, {
87
+ name: 'inlineMath',
88
+ }),
89
+ ],
90
+ });
91
+ ```
92
+
93
+ 如果 Tiptap 检测到配置的节点名已经被注册,扩展会输出一条 `console.warn`,提醒你尽快改成唯一名称,避免 schema 冲突。
94
+
75
95
  ## 持久化数据
76
96
 
77
97
  Tiptap 节点中只保存 LaTeX 源内容:
@@ -91,6 +111,7 @@ Tiptap 节点中只保存 LaTeX 源内容:
91
111
 
92
112
  ```ts
93
113
  interface FormulaXTiptapOptions {
114
+ name?: string;
94
115
  formulaClassName?: string;
95
116
  formulaAttributeName?: string;
96
117
  cursorStyle?: string;
@@ -115,6 +136,7 @@ interface FormulaXTiptapOptions {
115
136
 
116
137
  | 配置项 | 默认值 | 说明 |
117
138
  | --- | --- | --- |
139
+ | `name` | `formulaX` | 用于文档 schema 的 Tiptap 节点名。 |
118
140
  | `formulaClassName` | `formulax-math` | 渲染后公式节点使用的 CSS class。 |
119
141
  | `formulaAttributeName` | `data-formulax-latex` | 渲染后 DOM 中保存 LaTeX 源内容的属性名。 |
120
142
  | `cursorStyle` | `pointer` | 渲染后公式节点的鼠标光标样式。 |
package/dist/index.cjs CHANGED
@@ -135,6 +135,7 @@ function openFormulaXTiptapModal(input) {
135
135
  var FORMULAX_NODE_NAME = "formulaX";
136
136
  function resolveOptions(options = {}) {
137
137
  return {
138
+ name: options.name ?? FORMULAX_NODE_NAME,
138
139
  formulaClassName: options.formulaClassName ?? import_editor2.DEFAULT_FORMULA_CLASS,
139
140
  formulaAttributeName: options.formulaAttributeName ?? import_editor2.DEFAULT_FORMULA_ATTRIBUTE,
140
141
  cursorStyle: options.cursorStyle ?? "pointer",
@@ -156,140 +157,151 @@ function resolveOptions(options = {}) {
156
157
  }
157
158
  };
158
159
  }
159
- var formulaXNodeConfig = {
160
- name: FORMULAX_NODE_NAME,
161
- group: "inline",
162
- inline: true,
163
- atom: true,
164
- selectable: true,
165
- addOptions() {
166
- return resolveOptions();
167
- },
168
- onCreate() {
169
- if (typeof document !== "undefined") {
170
- (0, import_editor2.ensureFormulaXModalStyles)(document);
171
- }
172
- },
173
- addAttributes() {
174
- return {
175
- latex: {
176
- default: ""
160
+ function warnDuplicateNodeName(extension) {
161
+ const extensions = extension.editor?.extensionManager?.extensions ?? [];
162
+ const duplicates = extensions.filter((item) => item?.name === extension.name);
163
+ if (duplicates.length > 1) {
164
+ console.warn(
165
+ `[FormulaX] TipTap node name "${extension.name}" is already registered. Pass a unique "name" option to avoid schema collisions.`
166
+ );
167
+ }
168
+ }
169
+ function createFormulaXNodeConfig(options) {
170
+ return {
171
+ name: options.name,
172
+ group: "inline",
173
+ inline: true,
174
+ atom: true,
175
+ selectable: true,
176
+ addOptions() {
177
+ return options;
178
+ },
179
+ onCreate() {
180
+ warnDuplicateNodeName(this);
181
+ if (typeof document !== "undefined") {
182
+ (0, import_editor2.ensureFormulaXModalStyles)(document);
177
183
  }
178
- };
179
- },
180
- parseHTML() {
181
- return [{
182
- tag: "span[data-formulax]",
183
- getAttrs: (element) => {
184
- if (!(element instanceof HTMLElement)) {
185
- return false;
184
+ },
185
+ addAttributes() {
186
+ return {
187
+ latex: {
188
+ default: ""
186
189
  }
187
- return {
188
- latex: (0, import_editor2.getFormulaLatexFromElement)(element, this.options.formulaAttributeName)
189
- };
190
- }
191
- }];
192
- },
193
- renderHTML({ node }) {
194
- if (typeof document === "undefined") {
195
- return [
196
- "span",
197
- {
198
- "data-formulax": "true",
199
- [this.options.formulaAttributeName]: node.attrs.latex,
200
- "data-latex": node.attrs.latex
201
- },
202
- node.attrs.latex || "\\square"
203
- ];
204
- }
205
- return createFormulaDomElement(document, node.attrs, this.options);
206
- },
207
- addCommands() {
208
- return {
209
- openFormulaX: () => () => {
210
- const selectedFormula = getSelectedFormula(this.editor);
211
- const initialLatex = selectedFormula?.attrs.latex ?? this.options.initialLatex;
212
- void openFormulaXTiptapModal({
213
- initialLatex,
214
- isUpdate: Boolean(selectedFormula),
215
- options: this.options
216
- }).then((payload) => {
217
- if (!payload) {
218
- return;
190
+ };
191
+ },
192
+ parseHTML() {
193
+ return [{
194
+ tag: "span[data-formulax]",
195
+ getAttrs: (element) => {
196
+ if (!(element instanceof HTMLElement)) {
197
+ return false;
219
198
  }
220
- applyFormulaPayload(this.editor, payload, selectedFormula);
221
- this.editor.commands.focus();
222
- });
223
- return true;
224
- }
225
- };
226
- },
227
- addKeyboardShortcuts() {
228
- return {
229
- Enter: () => {
230
- if (!getSelectedFormula(this.editor)) {
231
- return false;
232
- }
233
- return this.editor.commands.openFormulaX();
234
- },
235
- Space: () => {
236
- if (!getSelectedFormula(this.editor)) {
237
- return false;
199
+ return {
200
+ latex: (0, import_editor2.getFormulaLatexFromElement)(element, this.options.formulaAttributeName)
201
+ };
238
202
  }
239
- return this.editor.commands.openFormulaX();
203
+ }];
204
+ },
205
+ renderHTML({ node }) {
206
+ if (typeof document === "undefined") {
207
+ return [
208
+ "span",
209
+ {
210
+ "data-formulax": "true",
211
+ [this.options.formulaAttributeName]: node.attrs.latex,
212
+ "data-latex": node.attrs.latex
213
+ },
214
+ node.attrs.latex || "\\square"
215
+ ];
240
216
  }
241
- };
242
- },
243
- addNodeView() {
244
- return ({ editor, getPos, node }) => {
245
- const dom = createFormulaDomElement(document, node.attrs, this.options) ?? document.createElement("span");
246
- dom.classList.add("formulax-math--interactive");
247
- void renderFormulaIntoElement(dom, node.attrs, this.options);
248
- const selectNode = () => {
249
- const position = getPos();
250
- if (typeof position !== "number") {
251
- return;
217
+ return createFormulaDomElement(document, node.attrs, this.options);
218
+ },
219
+ addCommands() {
220
+ return {
221
+ openFormulaX: () => () => {
222
+ const selectedFormula = getSelectedFormula(this.editor, this.name);
223
+ const initialLatex = selectedFormula?.attrs.latex ?? this.options.initialLatex;
224
+ void openFormulaXTiptapModal({
225
+ initialLatex,
226
+ isUpdate: Boolean(selectedFormula),
227
+ options: this.options
228
+ }).then((payload) => {
229
+ if (!payload) {
230
+ return;
231
+ }
232
+ applyFormulaPayload(this.editor, payload, selectedFormula, this.name);
233
+ this.editor.commands.focus();
234
+ });
235
+ return true;
252
236
  }
253
- editor.commands.setNodeSelection?.(position);
254
237
  };
255
- dom.addEventListener("click", (event) => {
256
- event.preventDefault();
257
- selectNode();
258
- });
259
- dom.addEventListener("dblclick", (event) => {
260
- event.preventDefault();
261
- event.stopPropagation();
262
- selectNode();
263
- editor.commands.openFormulaX();
264
- });
238
+ },
239
+ addKeyboardShortcuts() {
265
240
  return {
266
- dom,
267
- update: (updatedNode) => {
268
- if (updatedNode.type.name !== FORMULAX_NODE_NAME) {
241
+ Enter: () => {
242
+ if (!getSelectedFormula(this.editor, this.name)) {
269
243
  return false;
270
244
  }
271
- syncFormulaDomElement(dom, updatedNode.attrs, this.options);
272
- void renderFormulaIntoElement(dom, updatedNode.attrs, this.options);
273
- return true;
274
- },
275
- selectNode: () => {
276
- dom.classList.add("ProseMirror-selectednode");
245
+ return this.editor.commands.openFormulaX();
277
246
  },
278
- deselectNode: () => {
279
- dom.classList.remove("ProseMirror-selectednode");
247
+ Space: () => {
248
+ if (!getSelectedFormula(this.editor, this.name)) {
249
+ return false;
250
+ }
251
+ return this.editor.commands.openFormulaX();
280
252
  }
281
253
  };
282
- };
283
- }
284
- };
254
+ },
255
+ addNodeView() {
256
+ return ({ editor, getPos, node }) => {
257
+ const dom = createFormulaDomElement(document, node.attrs, this.options) ?? document.createElement("span");
258
+ dom.classList.add("formulax-math--interactive");
259
+ void renderFormulaIntoElement(dom, node.attrs, this.options);
260
+ const selectNode = () => {
261
+ const position = getPos();
262
+ if (typeof position !== "number") {
263
+ return;
264
+ }
265
+ editor.commands.setNodeSelection?.(position);
266
+ };
267
+ dom.addEventListener("click", (event) => {
268
+ event.preventDefault();
269
+ selectNode();
270
+ });
271
+ dom.addEventListener("dblclick", (event) => {
272
+ event.preventDefault();
273
+ event.stopPropagation();
274
+ selectNode();
275
+ editor.commands.openFormulaX();
276
+ });
277
+ return {
278
+ dom,
279
+ update: (updatedNode) => {
280
+ if (updatedNode.type.name !== this.name) {
281
+ return false;
282
+ }
283
+ syncFormulaDomElement(dom, updatedNode.attrs, this.options);
284
+ void renderFormulaIntoElement(dom, updatedNode.attrs, this.options);
285
+ return true;
286
+ },
287
+ selectNode: () => {
288
+ dom.classList.add("ProseMirror-selectednode");
289
+ },
290
+ deselectNode: () => {
291
+ dom.classList.remove("ProseMirror-selectednode");
292
+ }
293
+ };
294
+ };
295
+ }
296
+ };
297
+ }
285
298
  function createFormulaXNode(nodeFactory = import_core.Node, options) {
286
- const extension = nodeFactory.create(formulaXNodeConfig);
287
- return options ? extension.configure(options) : extension;
299
+ return nodeFactory.create(createFormulaXNodeConfig(resolveOptions(options)));
288
300
  }
289
301
  var FormulaXNode = createFormulaXNode();
290
302
  var createFormulaXPayload = (latex) => (0, import_core2.parseLatex)(latex);
291
303
  var serializeFormulaXPayload = (doc) => (0, import_core2.serializeLatex)(doc);
292
- function applyFormulaPayload(editor, payload, selectedFormula) {
304
+ function applyFormulaPayload(editor, payload, selectedFormula, nodeName) {
293
305
  const latex = payload.latex.trim();
294
306
  if (selectedFormula) {
295
307
  if (!latex) {
@@ -304,19 +316,19 @@ function applyFormulaPayload(editor, payload, selectedFormula) {
304
316
  from: selectedFormula.from,
305
317
  to: selectedFormula.to
306
318
  },
307
- createFormulaNodeContent(payload)
319
+ createFormulaNodeContent(payload, nodeName)
308
320
  ).run();
309
321
  return;
310
322
  }
311
323
  if (!latex) {
312
324
  return;
313
325
  }
314
- editor.chain().focus().insertContent(createFormulaNodeContent(payload)).run();
326
+ editor.chain().focus().insertContent(createFormulaNodeContent(payload, nodeName)).run();
315
327
  }
316
- function getSelectedFormula(editor) {
328
+ function getSelectedFormula(editor, nodeName) {
317
329
  const { selection } = editor.state;
318
330
  const node = selection.node;
319
- if (node?.type?.name !== FORMULAX_NODE_NAME) {
331
+ if (node?.type?.name !== nodeName) {
320
332
  return null;
321
333
  }
322
334
  return {
@@ -327,9 +339,9 @@ function getSelectedFormula(editor) {
327
339
  }
328
340
  };
329
341
  }
330
- function createFormulaNodeContent(payload) {
342
+ function createFormulaNodeContent(payload, nodeName = FORMULAX_NODE_NAME) {
331
343
  return {
332
- type: FORMULAX_NODE_NAME,
344
+ type: nodeName,
333
345
  attrs: {
334
346
  latex: payload.latex
335
347
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/modal.ts"],"sourcesContent":["import { Node } from '@tiptap/core';\nimport { parseLatex, serializeLatex, type FormulaDoc } from '@formulaxjs/core';\nimport {\n createFormulaElement,\n DEFAULT_FORMULA_ATTRIBUTE,\n DEFAULT_FORMULA_CLASS,\n ensureFormulaXModalStyles,\n getFormulaLatexFromElement,\n mountFormulaXKityEditor,\n} from '@formulaxjs/editor';\nimport { openFormulaXTiptapModal } from './modal';\nimport type { FormulaXPayload, FormulaXTiptapOptions, RequiredFormulaXTiptapOptions } from './types';\n\nexport interface FormulaXNodeAttributes {\n latex: string;\n}\n\nexport const FORMULAX_NODE_NAME = 'formulaX';\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n formulaX: {\n openFormulaX: () => ReturnType;\n };\n }\n}\n\nexport function resolveOptions(options: FormulaXTiptapOptions = {}): RequiredFormulaXTiptapOptions {\n return {\n formulaClassName: options.formulaClassName ?? DEFAULT_FORMULA_CLASS,\n formulaAttributeName: options.formulaAttributeName ?? DEFAULT_FORMULA_ATTRIBUTE,\n cursorStyle: options.cursorStyle ?? 'pointer',\n initialLatex: options.initialLatex ?? '',\n modal: {\n title: options.modal?.title ?? 'FormulaX Editor',\n insertText: options.modal?.insertText ?? 'Insert',\n updateText: options.modal?.updateText ?? 'Update',\n cancelText: options.modal?.cancelText ?? 'Cancel',\n closeOnBackdrop: options.modal?.closeOnBackdrop ?? true,\n },\n editor: {\n height: options.editor?.height ?? '100%',\n autofocus: options.editor?.autofocus ?? true,\n assets: options.editor?.assets ?? {},\n render: {\n fontsize: options.editor?.render?.fontsize ?? 40,\n },\n },\n };\n}\n\nconst formulaXNodeConfig: any = {\n name: FORMULAX_NODE_NAME,\n group: 'inline',\n inline: true,\n atom: true,\n selectable: true,\n addOptions() {\n return resolveOptions();\n },\n onCreate() {\n if (typeof document !== 'undefined') {\n ensureFormulaXModalStyles(document);\n }\n },\n addAttributes() {\n return {\n latex: {\n default: '',\n },\n };\n },\n parseHTML() {\n return [{\n tag: 'span[data-formulax]',\n getAttrs: (element: Node | string) => {\n if (!(element instanceof HTMLElement)) {\n return false;\n }\n\n return {\n latex: getFormulaLatexFromElement(element, this.options.formulaAttributeName),\n };\n },\n }];\n },\n renderHTML({ node }: { node: { attrs: FormulaXNodeAttributes } }) {\n if (typeof document === 'undefined') {\n return [\n 'span',\n {\n 'data-formulax': 'true',\n [this.options.formulaAttributeName]: node.attrs.latex,\n 'data-latex': node.attrs.latex,\n },\n node.attrs.latex || '\\\\square',\n ] as const;\n }\n\n return createFormulaDomElement(document, node.attrs, this.options);\n },\n addCommands() {\n return {\n openFormulaX: () => () => {\n const selectedFormula = getSelectedFormula(this.editor);\n const initialLatex = selectedFormula?.attrs.latex ?? this.options.initialLatex;\n\n void openFormulaXTiptapModal({\n initialLatex,\n isUpdate: Boolean(selectedFormula),\n options: this.options,\n }).then((payload) => {\n if (!payload) {\n return;\n }\n\n applyFormulaPayload(this.editor, payload, selectedFormula);\n this.editor.commands.focus();\n });\n\n return true;\n },\n };\n },\n addKeyboardShortcuts() {\n return {\n Enter: () => {\n if (!getSelectedFormula(this.editor)) {\n return false;\n }\n\n return this.editor.commands.openFormulaX();\n },\n Space: () => {\n if (!getSelectedFormula(this.editor)) {\n return false;\n }\n\n return this.editor.commands.openFormulaX();\n },\n };\n },\n addNodeView() {\n return ({ editor, getPos, node }: {\n editor: { commands: { openFormulaX: () => boolean; setNodeSelection?: (position: number) => boolean } };\n getPos: () => number;\n node: { attrs: FormulaXNodeAttributes };\n }) => {\n const dom = createFormulaDomElement(document, node.attrs, this.options) ?? document.createElement('span');\n dom.classList.add('formulax-math--interactive');\n void renderFormulaIntoElement(dom, node.attrs, this.options);\n\n const selectNode = (): void => {\n const position = getPos();\n if (typeof position !== 'number') {\n return;\n }\n\n editor.commands.setNodeSelection?.(position);\n };\n\n dom.addEventListener('click', (event) => {\n event.preventDefault();\n selectNode();\n });\n\n dom.addEventListener('dblclick', (event) => {\n event.preventDefault();\n event.stopPropagation();\n selectNode();\n editor.commands.openFormulaX();\n });\n\n return {\n dom,\n update: (updatedNode: { attrs: FormulaXNodeAttributes; type: { name: string } }) => {\n if (updatedNode.type.name !== FORMULAX_NODE_NAME) {\n return false;\n }\n\n syncFormulaDomElement(dom, updatedNode.attrs, this.options);\n void renderFormulaIntoElement(dom, updatedNode.attrs, this.options);\n return true;\n },\n selectNode: () => {\n dom.classList.add('ProseMirror-selectednode');\n },\n deselectNode: () => {\n dom.classList.remove('ProseMirror-selectednode');\n },\n };\n };\n },\n};\n\nexport interface TiptapNodeFactory {\n create: typeof Node.create;\n}\n\nexport function createFormulaXNode(\n nodeFactory: TiptapNodeFactory = Node,\n options?: FormulaXTiptapOptions,\n) {\n const extension = nodeFactory.create(formulaXNodeConfig) as any;\n return options ? extension.configure(options) : extension;\n}\n\nexport const FormulaXNode = createFormulaXNode();\n\nexport const createFormulaXPayload = (latex: string): FormulaDoc => parseLatex(latex);\n\nexport const serializeFormulaXPayload = (doc: FormulaDoc): string => serializeLatex(doc);\n\nfunction applyFormulaPayload(\n editor: {\n chain: () => {\n focus: () => {\n deleteRange: (range: { from: number; to: number }) => { run: () => boolean };\n insertContent: (content: unknown) => { run: () => boolean };\n insertContentAt: (range: { from: number; to: number }, content: unknown) => { run: () => boolean };\n };\n };\n },\n payload: FormulaXPayload,\n selectedFormula: SelectedFormula | null,\n): void {\n const latex = payload.latex.trim();\n\n if (selectedFormula) {\n if (!latex) {\n editor.chain().focus().deleteRange({\n from: selectedFormula.from,\n to: selectedFormula.to,\n }).run();\n return;\n }\n\n editor.chain().focus().insertContentAt(\n {\n from: selectedFormula.from,\n to: selectedFormula.to,\n },\n createFormulaNodeContent(payload),\n ).run();\n return;\n }\n\n if (!latex) {\n return;\n }\n\n editor.chain().focus().insertContent(createFormulaNodeContent(payload)).run();\n}\n\ninterface SelectedFormula {\n from: number;\n to: number;\n attrs: FormulaXNodeAttributes;\n}\n\nfunction getSelectedFormula(editor: {\n state: {\n selection: {\n from: number;\n to: number;\n node?: { type?: { name?: string }; attrs?: FormulaXNodeAttributes };\n };\n };\n}): SelectedFormula | null {\n const { selection } = editor.state;\n const node = selection.node;\n\n if (node?.type?.name !== FORMULAX_NODE_NAME) {\n return null;\n }\n\n return {\n from: selection.from,\n to: selection.to,\n attrs: {\n latex: node.attrs?.latex ?? '',\n },\n };\n}\n\nfunction createFormulaNodeContent(payload: FormulaXPayload): {\n type: string;\n attrs: FormulaXNodeAttributes;\n} {\n return {\n type: FORMULAX_NODE_NAME,\n attrs: {\n latex: payload.latex,\n },\n };\n}\n\nfunction createFormulaDomElement(\n ownerDocument: Document,\n attrs: FormulaXNodeAttributes,\n options: RequiredFormulaXTiptapOptions,\n): HTMLElement | null {\n return createFormulaElement(ownerDocument, attrs.latex, {\n attributeName: options.formulaAttributeName,\n className: options.formulaClassName,\n cursorStyle: options.cursorStyle,\n });\n}\n\nfunction syncFormulaDomElement(\n dom: HTMLElement,\n attrs: FormulaXNodeAttributes,\n options: RequiredFormulaXTiptapOptions,\n): void {\n const next = createFormulaDomElement(dom.ownerDocument ?? document, attrs, options);\n if (!next) {\n return;\n }\n\n dom.replaceChildren(...Array.from(next.childNodes));\n Array.from(dom.attributes).forEach((attribute) => {\n if (attribute.name === 'class') {\n return;\n }\n\n dom.removeAttribute(attribute.name);\n });\n\n Array.from(next.attributes).forEach((attribute) => {\n dom.setAttribute(attribute.name, attribute.value);\n });\n}\n\nconst formulaRenderCache = new Map<string, Promise<string>>();\n\nasync function renderFormulaIntoElement(\n dom: HTMLElement,\n attrs: FormulaXNodeAttributes,\n options: RequiredFormulaXTiptapOptions,\n): Promise<void> {\n const latex = attrs.latex.trim();\n const renderToken = `${latex}::${Date.now()}::${Math.random().toString(36).slice(2, 8)}`;\n dom.dataset.renderToken = renderToken;\n\n if (!latex) {\n const placeholder = dom.querySelector<HTMLElement>(`.${options.formulaClassName}__render`);\n if (placeholder) {\n placeholder.textContent = '\\\\square';\n }\n return;\n }\n\n try {\n const markup = await renderFormulaSvgMarkup(latex, options);\n if (dom.dataset.renderToken !== renderToken) {\n return;\n }\n\n dom.innerHTML = markup;\n } catch (error) {\n if (dom.dataset.renderToken !== renderToken) {\n return;\n }\n\n console.error('[FormulaX] Failed to render Tiptap formula node:', error);\n const placeholder = dom.querySelector<HTMLElement>(`.${options.formulaClassName}__render`);\n if (placeholder) {\n placeholder.textContent = latex;\n }\n }\n}\n\nfunction renderFormulaSvgMarkup(\n latex: string,\n options: RequiredFormulaXTiptapOptions,\n): Promise<string> {\n const cached = formulaRenderCache.get(latex);\n if (cached) {\n return cached;\n }\n\n const pending = (async () => {\n const host = document.createElement('div');\n host.style.position = 'fixed';\n host.style.left = '-100000px';\n host.style.top = '0';\n host.style.width = '1px';\n host.style.height = '1px';\n host.style.opacity = '0';\n host.style.pointerEvents = 'none';\n host.setAttribute('aria-hidden', 'true');\n document.body.appendChild(host);\n\n const mounted = mountFormulaXKityEditor(host, {\n initialLatex: latex,\n height: options.editor.height,\n autofocus: false,\n assets: options.editor.assets,\n render: {\n fontsize: options.editor.render.fontsize,\n },\n });\n\n try {\n return await mounted.getRenderHtml();\n } finally {\n mounted.destroy();\n host.remove();\n }\n })();\n\n formulaRenderCache.set(latex, pending);\n pending.catch(() => {\n if (formulaRenderCache.get(latex) === pending) {\n formulaRenderCache.delete(latex);\n }\n });\n return pending;\n}\n\nexport type { FormulaXPayload, FormulaXTiptapOptions, RequiredFormulaXTiptapOptions } from './types';\nexport { openFormulaXTiptapModal } from './modal';\n","import {\n ensureFormulaXModalStyles,\n escapeAttribute,\n escapeHtml,\n mountFormulaXKityEditor,\n} from '@formulaxjs/editor';\nimport type { FormulaXPayload, RequiredFormulaXTiptapOptions } from './types';\n\nexport interface OpenFormulaXTiptapModalInput {\n initialLatex: string;\n isUpdate: boolean;\n options: RequiredFormulaXTiptapOptions;\n}\n\nexport function openFormulaXTiptapModal(\n input: OpenFormulaXTiptapModalInput,\n): Promise<FormulaXPayload | null> {\n ensureFormulaXModalStyles(document);\n\n const root = document.createElement('div');\n root.className = 'fx-formula-modal-root';\n root.setAttribute('data-formulax-modal', 'true');\n\n const submitText = input.isUpdate ? input.options.modal.updateText : input.options.modal.insertText;\n\n root.innerHTML = `\n <div class=\"fx-formula-modal-backdrop\" data-action=\"backdrop\"></div>\n <div class=\"fx-formula-modal\" role=\"dialog\" aria-modal=\"true\" aria-label=\"${escapeAttribute(input.options.modal.title)}\">\n <header class=\"fx-formula-modal__header\">\n <h2 class=\"fx-formula-modal__title\">${escapeHtml(input.options.modal.title)}</h2>\n <button class=\"fx-formula-modal__close\" type=\"button\" data-action=\"close\" aria-label=\"Close\">×</button>\n </header>\n <section class=\"fx-formula-modal__body\">\n <div class=\"fx-formula-editor-host\"></div>\n </section>\n <footer class=\"fx-formula-modal__footer\">\n <button class=\"fx-formula-modal__button\" type=\"button\" data-action=\"cancel\">${escapeHtml(input.options.modal.cancelText)}</button>\n <button class=\"fx-formula-modal__button fx-formula-modal__button--primary\" type=\"button\" data-action=\"submit\">${escapeHtml(submitText)}</button>\n </footer>\n </div>\n `;\n\n document.body.appendChild(root);\n document.body.classList.add('fx-formula-modal-open');\n\n const host = root.querySelector<HTMLElement>('.fx-formula-editor-host');\n if (!host) {\n root.remove();\n return Promise.reject(new Error('[FormulaX] Tiptap modal host not found.'));\n }\n\n const mounted = mountFormulaXKityEditor(host, {\n initialLatex: input.initialLatex,\n height: input.options.editor.height,\n autofocus: input.options.editor.autofocus,\n assets: input.options.editor.assets,\n render: {\n fontsize: input.options.editor.render.fontsize,\n },\n });\n let closed = false;\n\n return new Promise((resolve) => {\n const close = (payload: FormulaXPayload | null): void => {\n if (closed) {\n return;\n }\n\n closed = true;\n mounted.destroy();\n root.removeEventListener('click', onClick);\n document.removeEventListener('keydown', onKeydown, true);\n root.remove();\n document.body.classList.remove('fx-formula-modal-open');\n resolve(payload);\n };\n\n const submit = async (): Promise<void> => {\n try {\n const latex = await mounted.getLatex();\n close({ latex });\n } catch (error) {\n host.innerHTML = `\n <div class=\"fx-formula-editor-error\">\n Failed to read FormulaX editor content.\n <pre>${escapeHtml(error instanceof Error ? error.message : String(error))}</pre>\n </div>\n `;\n }\n };\n\n function onClick(event: MouseEvent): void {\n const action = (event.target as HTMLElement).closest<HTMLElement>('[data-action]')?.dataset.action;\n if (!action) {\n return;\n }\n\n if (action === 'submit') {\n void submit();\n return;\n }\n\n if (action === 'cancel' || action === 'close') {\n close(null);\n return;\n }\n\n if (action === 'backdrop' && input.options.modal.closeOnBackdrop) {\n close(null);\n }\n }\n\n function onKeydown(event: KeyboardEvent): void {\n if (event.key === 'Escape') {\n event.preventDefault();\n close(null);\n }\n }\n\n root.addEventListener('click', onClick);\n document.addEventListener('keydown', onKeydown, true);\n\n queueMicrotask(() => {\n mounted.root.focus();\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AACrB,IAAAA,eAA4D;AAC5D,IAAAC,iBAOO;;;ACTP,oBAKO;AASA,SAAS,wBACd,OACiC;AACjC,+CAA0B,QAAQ;AAElC,QAAM,OAAO,SAAS,cAAc,KAAK;AACzC,OAAK,YAAY;AACjB,OAAK,aAAa,uBAAuB,MAAM;AAE/C,QAAM,aAAa,MAAM,WAAW,MAAM,QAAQ,MAAM,aAAa,MAAM,QAAQ,MAAM;AAEzF,OAAK,YAAY;AAAA;AAAA,oFAE6D,+BAAgB,MAAM,QAAQ,MAAM,KAAK,CAAC;AAAA;AAAA,kD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AG;AAEH,qBAAmB,IAAI,OAAO,OAAO;AACrC,UAAQ,MAAM,MAAM;AAClB,QAAI,mBAAmB,IAAI,KAAK,MAAM,SAAS;AAC7C,yBAAmB,OAAO,KAAK;AAAA,IACjC;AAAA,EACF,CAAC;AACD,SAAO;AACT;","names":["import_core","import_editor"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/modal.ts"],"sourcesContent":["import { Node } from '@tiptap/core';\nimport { parseLatex, serializeLatex, type FormulaDoc } from '@formulaxjs/core';\nimport {\n createFormulaElement,\n DEFAULT_FORMULA_ATTRIBUTE,\n DEFAULT_FORMULA_CLASS,\n ensureFormulaXModalStyles,\n getFormulaLatexFromElement,\n mountFormulaXKityEditor,\n} from '@formulaxjs/editor';\nimport { openFormulaXTiptapModal } from './modal';\nimport type { FormulaXPayload, FormulaXTiptapOptions, RequiredFormulaXTiptapOptions } from './types';\n\nexport interface FormulaXNodeAttributes {\n latex: string;\n}\n\nexport const FORMULAX_NODE_NAME = 'formulaX';\n\ndeclare module '@tiptap/core' {\n interface Commands<ReturnType> {\n formulaX: {\n openFormulaX: () => ReturnType;\n };\n }\n}\n\nexport function resolveOptions(options: FormulaXTiptapOptions = {}): RequiredFormulaXTiptapOptions {\n return {\n name: options.name ?? FORMULAX_NODE_NAME,\n formulaClassName: options.formulaClassName ?? DEFAULT_FORMULA_CLASS,\n formulaAttributeName: options.formulaAttributeName ?? DEFAULT_FORMULA_ATTRIBUTE,\n cursorStyle: options.cursorStyle ?? 'pointer',\n initialLatex: options.initialLatex ?? '',\n modal: {\n title: options.modal?.title ?? 'FormulaX Editor',\n insertText: options.modal?.insertText ?? 'Insert',\n updateText: options.modal?.updateText ?? 'Update',\n cancelText: options.modal?.cancelText ?? 'Cancel',\n closeOnBackdrop: options.modal?.closeOnBackdrop ?? true,\n },\n editor: {\n height: options.editor?.height ?? '100%',\n autofocus: options.editor?.autofocus ?? true,\n assets: options.editor?.assets ?? {},\n render: {\n fontsize: options.editor?.render?.fontsize ?? 40,\n },\n },\n };\n}\n\nfunction warnDuplicateNodeName(extension: {\n name: string;\n editor?: { extensionManager?: { extensions?: Array<{ name?: string }> } };\n}) {\n const extensions = extension.editor?.extensionManager?.extensions ?? [];\n const duplicates = extensions.filter((item) => item?.name === extension.name);\n\n if (duplicates.length > 1) {\n console.warn(\n `[FormulaX] TipTap node name \"${extension.name}\" is already registered. ` +\n 'Pass a unique \"name\" option to avoid schema collisions.',\n );\n }\n}\n\nfunction createFormulaXNodeConfig(options: RequiredFormulaXTiptapOptions): any {\n return {\n name: options.name,\n group: 'inline',\n inline: true,\n atom: true,\n selectable: true,\n addOptions() {\n return options;\n },\n onCreate() {\n warnDuplicateNodeName(this);\n\n if (typeof document !== 'undefined') {\n ensureFormulaXModalStyles(document);\n }\n },\n addAttributes() {\n return {\n latex: {\n default: '',\n },\n };\n },\n parseHTML() {\n return [{\n tag: 'span[data-formulax]',\n getAttrs: (element: Node | string) => {\n if (!(element instanceof HTMLElement)) {\n return false;\n }\n\n return {\n latex: getFormulaLatexFromElement(element, this.options.formulaAttributeName),\n };\n },\n }];\n },\n renderHTML({ node }: { node: { attrs: FormulaXNodeAttributes } }) {\n if (typeof document === 'undefined') {\n return [\n 'span',\n {\n 'data-formulax': 'true',\n [this.options.formulaAttributeName]: node.attrs.latex,\n 'data-latex': node.attrs.latex,\n },\n node.attrs.latex || '\\\\square',\n ] as const;\n }\n\n return createFormulaDomElement(document, node.attrs, this.options);\n },\n addCommands() {\n return {\n openFormulaX: () => () => {\n const selectedFormula = getSelectedFormula(this.editor, this.name);\n const initialLatex = selectedFormula?.attrs.latex ?? this.options.initialLatex;\n\n void openFormulaXTiptapModal({\n initialLatex,\n isUpdate: Boolean(selectedFormula),\n options: this.options,\n }).then((payload) => {\n if (!payload) {\n return;\n }\n\n applyFormulaPayload(this.editor, payload, selectedFormula, this.name);\n this.editor.commands.focus();\n });\n\n return true;\n },\n };\n },\n addKeyboardShortcuts() {\n return {\n Enter: () => {\n if (!getSelectedFormula(this.editor, this.name)) {\n return false;\n }\n\n return this.editor.commands.openFormulaX();\n },\n Space: () => {\n if (!getSelectedFormula(this.editor, this.name)) {\n return false;\n }\n\n return this.editor.commands.openFormulaX();\n },\n };\n },\n addNodeView() {\n return ({ editor, getPos, node }: {\n editor: { commands: { openFormulaX: () => boolean; setNodeSelection?: (position: number) => boolean } };\n getPos: () => number;\n node: { attrs: FormulaXNodeAttributes };\n }) => {\n const dom = createFormulaDomElement(document, node.attrs, this.options) ?? document.createElement('span');\n dom.classList.add('formulax-math--interactive');\n void renderFormulaIntoElement(dom, node.attrs, this.options);\n\n const selectNode = (): void => {\n const position = getPos();\n if (typeof position !== 'number') {\n return;\n }\n\n editor.commands.setNodeSelection?.(position);\n };\n\n dom.addEventListener('click', (event) => {\n event.preventDefault();\n selectNode();\n });\n\n dom.addEventListener('dblclick', (event) => {\n event.preventDefault();\n event.stopPropagation();\n selectNode();\n editor.commands.openFormulaX();\n });\n\n return {\n dom,\n update: (updatedNode: { attrs: FormulaXNodeAttributes; type: { name: string } }) => {\n if (updatedNode.type.name !== this.name) {\n return false;\n }\n\n syncFormulaDomElement(dom, updatedNode.attrs, this.options);\n void renderFormulaIntoElement(dom, updatedNode.attrs, this.options);\n return true;\n },\n selectNode: () => {\n dom.classList.add('ProseMirror-selectednode');\n },\n deselectNode: () => {\n dom.classList.remove('ProseMirror-selectednode');\n },\n };\n };\n },\n };\n}\n\nexport interface TiptapNodeFactory {\n create: typeof Node.create;\n}\n\nexport function createFormulaXNode(\n nodeFactory: TiptapNodeFactory = Node,\n options?: FormulaXTiptapOptions,\n) {\n return nodeFactory.create(createFormulaXNodeConfig(resolveOptions(options))) as any;\n}\n\nexport const FormulaXNode = createFormulaXNode();\n\nexport const createFormulaXPayload = (latex: string): FormulaDoc => parseLatex(latex);\n\nexport const serializeFormulaXPayload = (doc: FormulaDoc): string => serializeLatex(doc);\n\nfunction applyFormulaPayload(\n editor: {\n chain: () => {\n focus: () => {\n deleteRange: (range: { from: number; to: number }) => { run: () => boolean };\n insertContent: (content: unknown) => { run: () => boolean };\n insertContentAt: (range: { from: number; to: number }, content: unknown) => { run: () => boolean };\n };\n };\n },\n payload: FormulaXPayload,\n selectedFormula: SelectedFormula | null,\n nodeName: string,\n): void {\n const latex = payload.latex.trim();\n\n if (selectedFormula) {\n if (!latex) {\n editor.chain().focus().deleteRange({\n from: selectedFormula.from,\n to: selectedFormula.to,\n }).run();\n return;\n }\n\n editor.chain().focus().insertContentAt(\n {\n from: selectedFormula.from,\n to: selectedFormula.to,\n },\n createFormulaNodeContent(payload, nodeName),\n ).run();\n return;\n }\n\n if (!latex) {\n return;\n }\n\n editor.chain().focus().insertContent(createFormulaNodeContent(payload, nodeName)).run();\n}\n\ninterface SelectedFormula {\n from: number;\n to: number;\n attrs: FormulaXNodeAttributes;\n}\n\nfunction getSelectedFormula(editor: {\n state: {\n selection: {\n from: number;\n to: number;\n node?: { type?: { name?: string }; attrs?: FormulaXNodeAttributes };\n };\n };\n}, nodeName: string): SelectedFormula | null {\n const { selection } = editor.state;\n const node = selection.node;\n\n if (node?.type?.name !== nodeName) {\n return null;\n }\n\n return {\n from: selection.from,\n to: selection.to,\n attrs: {\n latex: node.attrs?.latex ?? '',\n },\n };\n}\n\nfunction createFormulaNodeContent(\n payload: FormulaXPayload,\n nodeName = FORMULAX_NODE_NAME,\n): {\n type: string;\n attrs: FormulaXNodeAttributes;\n} {\n return {\n type: nodeName,\n attrs: {\n latex: payload.latex,\n },\n };\n}\n\nfunction createFormulaDomElement(\n ownerDocument: Document,\n attrs: FormulaXNodeAttributes,\n options: RequiredFormulaXTiptapOptions,\n): HTMLElement | null {\n return createFormulaElement(ownerDocument, attrs.latex, {\n attributeName: options.formulaAttributeName,\n className: options.formulaClassName,\n cursorStyle: options.cursorStyle,\n });\n}\n\nfunction syncFormulaDomElement(\n dom: HTMLElement,\n attrs: FormulaXNodeAttributes,\n options: RequiredFormulaXTiptapOptions,\n): void {\n const next = createFormulaDomElement(dom.ownerDocument ?? document, attrs, options);\n if (!next) {\n return;\n }\n\n dom.replaceChildren(...Array.from(next.childNodes));\n Array.from(dom.attributes).forEach((attribute) => {\n if (attribute.name === 'class') {\n return;\n }\n\n dom.removeAttribute(attribute.name);\n });\n\n Array.from(next.attributes).forEach((attribute) => {\n dom.setAttribute(attribute.name, attribute.value);\n });\n}\n\nconst formulaRenderCache = new Map<string, Promise<string>>();\n\nasync function renderFormulaIntoElement(\n dom: HTMLElement,\n attrs: FormulaXNodeAttributes,\n options: RequiredFormulaXTiptapOptions,\n): Promise<void> {\n const latex = attrs.latex.trim();\n const renderToken = `${latex}::${Date.now()}::${Math.random().toString(36).slice(2, 8)}`;\n dom.dataset.renderToken = renderToken;\n\n if (!latex) {\n const placeholder = dom.querySelector<HTMLElement>(`.${options.formulaClassName}__render`);\n if (placeholder) {\n placeholder.textContent = '\\\\square';\n }\n return;\n }\n\n try {\n const markup = await renderFormulaSvgMarkup(latex, options);\n if (dom.dataset.renderToken !== renderToken) {\n return;\n }\n\n dom.innerHTML = markup;\n } catch (error) {\n if (dom.dataset.renderToken !== renderToken) {\n return;\n }\n\n console.error('[FormulaX] Failed to render Tiptap formula node:', error);\n const placeholder = dom.querySelector<HTMLElement>(`.${options.formulaClassName}__render`);\n if (placeholder) {\n placeholder.textContent = latex;\n }\n }\n}\n\nfunction renderFormulaSvgMarkup(\n latex: string,\n options: RequiredFormulaXTiptapOptions,\n): Promise<string> {\n const cached = formulaRenderCache.get(latex);\n if (cached) {\n return cached;\n }\n\n const pending = (async () => {\n const host = document.createElement('div');\n host.style.position = 'fixed';\n host.style.left = '-100000px';\n host.style.top = '0';\n host.style.width = '1px';\n host.style.height = '1px';\n host.style.opacity = '0';\n host.style.pointerEvents = 'none';\n host.setAttribute('aria-hidden', 'true');\n document.body.appendChild(host);\n\n const mounted = mountFormulaXKityEditor(host, {\n initialLatex: latex,\n height: options.editor.height,\n autofocus: false,\n assets: options.editor.assets,\n render: {\n fontsize: options.editor.render.fontsize,\n },\n });\n\n try {\n return await mounted.getRenderHtml();\n } finally {\n mounted.destroy();\n host.remove();\n }\n })();\n\n formulaRenderCache.set(latex, pending);\n pending.catch(() => {\n if (formulaRenderCache.get(latex) === pending) {\n formulaRenderCache.delete(latex);\n }\n });\n return pending;\n}\n\nexport type { FormulaXPayload, FormulaXTiptapOptions, RequiredFormulaXTiptapOptions } from './types';\nexport { openFormulaXTiptapModal } from './modal';\n","import {\n ensureFormulaXModalStyles,\n escapeAttribute,\n escapeHtml,\n mountFormulaXKityEditor,\n} from '@formulaxjs/editor';\nimport type { FormulaXPayload, RequiredFormulaXTiptapOptions } from './types';\n\nexport interface OpenFormulaXTiptapModalInput {\n initialLatex: string;\n isUpdate: boolean;\n options: RequiredFormulaXTiptapOptions;\n}\n\nexport function openFormulaXTiptapModal(\n input: OpenFormulaXTiptapModalInput,\n): Promise<FormulaXPayload | null> {\n ensureFormulaXModalStyles(document);\n\n const root = document.createElement('div');\n root.className = 'fx-formula-modal-root';\n root.setAttribute('data-formulax-modal', 'true');\n\n const submitText = input.isUpdate ? input.options.modal.updateText : input.options.modal.insertText;\n\n root.innerHTML = `\n <div class=\"fx-formula-modal-backdrop\" data-action=\"backdrop\"></div>\n <div class=\"fx-formula-modal\" role=\"dialog\" aria-modal=\"true\" aria-label=\"${escapeAttribute(input.options.modal.title)}\">\n <header class=\"fx-formula-modal__header\">\n <h2 class=\"fx-formula-modal__title\">${escapeHtml(input.options.modal.title)}</h2>\n <button class=\"fx-formula-modal__close\" type=\"button\" data-action=\"close\" aria-label=\"Close\">×</button>\n </header>\n <section class=\"fx-formula-modal__body\">\n <div class=\"fx-formula-editor-host\"></div>\n </section>\n <footer class=\"fx-formula-modal__footer\">\n <button class=\"fx-formula-modal__button\" type=\"button\" data-action=\"cancel\">${escapeHtml(input.options.modal.cancelText)}</button>\n <button class=\"fx-formula-modal__button fx-formula-modal__button--primary\" type=\"button\" data-action=\"submit\">${escapeHtml(submitText)}</button>\n </footer>\n </div>\n `;\n\n document.body.appendChild(root);\n document.body.classList.add('fx-formula-modal-open');\n\n const host = root.querySelector<HTMLElement>('.fx-formula-editor-host');\n if (!host) {\n root.remove();\n return Promise.reject(new Error('[FormulaX] Tiptap modal host not found.'));\n }\n\n const mounted = mountFormulaXKityEditor(host, {\n initialLatex: input.initialLatex,\n height: input.options.editor.height,\n autofocus: input.options.editor.autofocus,\n assets: input.options.editor.assets,\n render: {\n fontsize: input.options.editor.render.fontsize,\n },\n });\n let closed = false;\n\n return new Promise((resolve) => {\n const close = (payload: FormulaXPayload | null): void => {\n if (closed) {\n return;\n }\n\n closed = true;\n mounted.destroy();\n root.removeEventListener('click', onClick);\n document.removeEventListener('keydown', onKeydown, true);\n root.remove();\n document.body.classList.remove('fx-formula-modal-open');\n resolve(payload);\n };\n\n const submit = async (): Promise<void> => {\n try {\n const latex = await mounted.getLatex();\n close({ latex });\n } catch (error) {\n host.innerHTML = `\n <div class=\"fx-formula-editor-error\">\n Failed to read FormulaX editor content.\n <pre>${escapeHtml(error instanceof Error ? error.message : String(error))}</pre>\n </div>\n `;\n }\n };\n\n function onClick(event: MouseEvent): void {\n const action = (event.target as HTMLElement).closest<HTMLElement>('[data-action]')?.dataset.action;\n if (!action) {\n return;\n }\n\n if (action === 'submit') {\n void submit();\n return;\n }\n\n if (action === 'cancel' || action === 'close') {\n close(null);\n return;\n }\n\n if (action === 'backdrop' && input.options.modal.closeOnBackdrop) {\n close(null);\n }\n }\n\n function onKeydown(event: KeyboardEvent): void {\n if (event.key === 'Escape') {\n event.preventDefault();\n close(null);\n }\n }\n\n root.addEventListener('click', onClick);\n document.addEventListener('keydown', onKeydown, true);\n\n queueMicrotask(() => {\n mounted.root.focus();\n });\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAqB;AACrB,IAAAA,eAA4D;AAC5D,IAAAC,iBAOO;;;ACTP,oBAKO;AASA,SAAS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