@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 +22 -0
- package/README.zh-CN.md +22 -0
- package/dist/index.cjs +134 -122
- package/dist/index.cjs.map +1 -1
- package/dist/index.global.js +134 -122
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +134 -122
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -117,6 +117,7 @@ function openFormulaXTiptapModal(input) {
|
|
|
117
117
|
var FORMULAX_NODE_NAME = "formulaX";
|
|
118
118
|
function resolveOptions(options = {}) {
|
|
119
119
|
return {
|
|
120
|
+
name: options.name ?? FORMULAX_NODE_NAME,
|
|
120
121
|
formulaClassName: options.formulaClassName ?? DEFAULT_FORMULA_CLASS,
|
|
121
122
|
formulaAttributeName: options.formulaAttributeName ?? DEFAULT_FORMULA_ATTRIBUTE,
|
|
122
123
|
cursorStyle: options.cursorStyle ?? "pointer",
|
|
@@ -138,140 +139,151 @@ function resolveOptions(options = {}) {
|
|
|
138
139
|
}
|
|
139
140
|
};
|
|
140
141
|
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
142
|
+
function warnDuplicateNodeName(extension) {
|
|
143
|
+
const extensions = extension.editor?.extensionManager?.extensions ?? [];
|
|
144
|
+
const duplicates = extensions.filter((item) => item?.name === extension.name);
|
|
145
|
+
if (duplicates.length > 1) {
|
|
146
|
+
console.warn(
|
|
147
|
+
`[FormulaX] TipTap node name "${extension.name}" is already registered. Pass a unique "name" option to avoid schema collisions.`
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function createFormulaXNodeConfig(options) {
|
|
152
|
+
return {
|
|
153
|
+
name: options.name,
|
|
154
|
+
group: "inline",
|
|
155
|
+
inline: true,
|
|
156
|
+
atom: true,
|
|
157
|
+
selectable: true,
|
|
158
|
+
addOptions() {
|
|
159
|
+
return options;
|
|
160
|
+
},
|
|
161
|
+
onCreate() {
|
|
162
|
+
warnDuplicateNodeName(this);
|
|
163
|
+
if (typeof document !== "undefined") {
|
|
164
|
+
ensureFormulaXModalStyles2(document);
|
|
159
165
|
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
getAttrs: (element) => {
|
|
166
|
-
if (!(element instanceof HTMLElement)) {
|
|
167
|
-
return false;
|
|
166
|
+
},
|
|
167
|
+
addAttributes() {
|
|
168
|
+
return {
|
|
169
|
+
latex: {
|
|
170
|
+
default: ""
|
|
168
171
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return [
|
|
178
|
-
"span",
|
|
179
|
-
{
|
|
180
|
-
"data-formulax": "true",
|
|
181
|
-
[this.options.formulaAttributeName]: node.attrs.latex,
|
|
182
|
-
"data-latex": node.attrs.latex
|
|
183
|
-
},
|
|
184
|
-
node.attrs.latex || "\\square"
|
|
185
|
-
];
|
|
186
|
-
}
|
|
187
|
-
return createFormulaDomElement(document, node.attrs, this.options);
|
|
188
|
-
},
|
|
189
|
-
addCommands() {
|
|
190
|
-
return {
|
|
191
|
-
openFormulaX: () => () => {
|
|
192
|
-
const selectedFormula = getSelectedFormula(this.editor);
|
|
193
|
-
const initialLatex = selectedFormula?.attrs.latex ?? this.options.initialLatex;
|
|
194
|
-
void openFormulaXTiptapModal({
|
|
195
|
-
initialLatex,
|
|
196
|
-
isUpdate: Boolean(selectedFormula),
|
|
197
|
-
options: this.options
|
|
198
|
-
}).then((payload) => {
|
|
199
|
-
if (!payload) {
|
|
200
|
-
return;
|
|
172
|
+
};
|
|
173
|
+
},
|
|
174
|
+
parseHTML() {
|
|
175
|
+
return [{
|
|
176
|
+
tag: "span[data-formulax]",
|
|
177
|
+
getAttrs: (element) => {
|
|
178
|
+
if (!(element instanceof HTMLElement)) {
|
|
179
|
+
return false;
|
|
201
180
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
return true;
|
|
206
|
-
}
|
|
207
|
-
};
|
|
208
|
-
},
|
|
209
|
-
addKeyboardShortcuts() {
|
|
210
|
-
return {
|
|
211
|
-
Enter: () => {
|
|
212
|
-
if (!getSelectedFormula(this.editor)) {
|
|
213
|
-
return false;
|
|
214
|
-
}
|
|
215
|
-
return this.editor.commands.openFormulaX();
|
|
216
|
-
},
|
|
217
|
-
Space: () => {
|
|
218
|
-
if (!getSelectedFormula(this.editor)) {
|
|
219
|
-
return false;
|
|
181
|
+
return {
|
|
182
|
+
latex: getFormulaLatexFromElement(element, this.options.formulaAttributeName)
|
|
183
|
+
};
|
|
220
184
|
}
|
|
221
|
-
|
|
185
|
+
}];
|
|
186
|
+
},
|
|
187
|
+
renderHTML({ node }) {
|
|
188
|
+
if (typeof document === "undefined") {
|
|
189
|
+
return [
|
|
190
|
+
"span",
|
|
191
|
+
{
|
|
192
|
+
"data-formulax": "true",
|
|
193
|
+
[this.options.formulaAttributeName]: node.attrs.latex,
|
|
194
|
+
"data-latex": node.attrs.latex
|
|
195
|
+
},
|
|
196
|
+
node.attrs.latex || "\\square"
|
|
197
|
+
];
|
|
222
198
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
199
|
+
return createFormulaDomElement(document, node.attrs, this.options);
|
|
200
|
+
},
|
|
201
|
+
addCommands() {
|
|
202
|
+
return {
|
|
203
|
+
openFormulaX: () => () => {
|
|
204
|
+
const selectedFormula = getSelectedFormula(this.editor, this.name);
|
|
205
|
+
const initialLatex = selectedFormula?.attrs.latex ?? this.options.initialLatex;
|
|
206
|
+
void openFormulaXTiptapModal({
|
|
207
|
+
initialLatex,
|
|
208
|
+
isUpdate: Boolean(selectedFormula),
|
|
209
|
+
options: this.options
|
|
210
|
+
}).then((payload) => {
|
|
211
|
+
if (!payload) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
applyFormulaPayload(this.editor, payload, selectedFormula, this.name);
|
|
215
|
+
this.editor.commands.focus();
|
|
216
|
+
});
|
|
217
|
+
return true;
|
|
234
218
|
}
|
|
235
|
-
editor.commands.setNodeSelection?.(position);
|
|
236
219
|
};
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
selectNode();
|
|
240
|
-
});
|
|
241
|
-
dom.addEventListener("dblclick", (event) => {
|
|
242
|
-
event.preventDefault();
|
|
243
|
-
event.stopPropagation();
|
|
244
|
-
selectNode();
|
|
245
|
-
editor.commands.openFormulaX();
|
|
246
|
-
});
|
|
220
|
+
},
|
|
221
|
+
addKeyboardShortcuts() {
|
|
247
222
|
return {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
if (updatedNode.type.name !== FORMULAX_NODE_NAME) {
|
|
223
|
+
Enter: () => {
|
|
224
|
+
if (!getSelectedFormula(this.editor, this.name)) {
|
|
251
225
|
return false;
|
|
252
226
|
}
|
|
253
|
-
|
|
254
|
-
void renderFormulaIntoElement(dom, updatedNode.attrs, this.options);
|
|
255
|
-
return true;
|
|
256
|
-
},
|
|
257
|
-
selectNode: () => {
|
|
258
|
-
dom.classList.add("ProseMirror-selectednode");
|
|
227
|
+
return this.editor.commands.openFormulaX();
|
|
259
228
|
},
|
|
260
|
-
|
|
261
|
-
|
|
229
|
+
Space: () => {
|
|
230
|
+
if (!getSelectedFormula(this.editor, this.name)) {
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
return this.editor.commands.openFormulaX();
|
|
262
234
|
}
|
|
263
235
|
};
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
}
|
|
236
|
+
},
|
|
237
|
+
addNodeView() {
|
|
238
|
+
return ({ editor, getPos, node }) => {
|
|
239
|
+
const dom = createFormulaDomElement(document, node.attrs, this.options) ?? document.createElement("span");
|
|
240
|
+
dom.classList.add("formulax-math--interactive");
|
|
241
|
+
void renderFormulaIntoElement(dom, node.attrs, this.options);
|
|
242
|
+
const selectNode = () => {
|
|
243
|
+
const position = getPos();
|
|
244
|
+
if (typeof position !== "number") {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
editor.commands.setNodeSelection?.(position);
|
|
248
|
+
};
|
|
249
|
+
dom.addEventListener("click", (event) => {
|
|
250
|
+
event.preventDefault();
|
|
251
|
+
selectNode();
|
|
252
|
+
});
|
|
253
|
+
dom.addEventListener("dblclick", (event) => {
|
|
254
|
+
event.preventDefault();
|
|
255
|
+
event.stopPropagation();
|
|
256
|
+
selectNode();
|
|
257
|
+
editor.commands.openFormulaX();
|
|
258
|
+
});
|
|
259
|
+
return {
|
|
260
|
+
dom,
|
|
261
|
+
update: (updatedNode) => {
|
|
262
|
+
if (updatedNode.type.name !== this.name) {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
syncFormulaDomElement(dom, updatedNode.attrs, this.options);
|
|
266
|
+
void renderFormulaIntoElement(dom, updatedNode.attrs, this.options);
|
|
267
|
+
return true;
|
|
268
|
+
},
|
|
269
|
+
selectNode: () => {
|
|
270
|
+
dom.classList.add("ProseMirror-selectednode");
|
|
271
|
+
},
|
|
272
|
+
deselectNode: () => {
|
|
273
|
+
dom.classList.remove("ProseMirror-selectednode");
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
};
|
|
279
|
+
}
|
|
267
280
|
function createFormulaXNode(nodeFactory = Node, options) {
|
|
268
|
-
|
|
269
|
-
return options ? extension.configure(options) : extension;
|
|
281
|
+
return nodeFactory.create(createFormulaXNodeConfig(resolveOptions(options)));
|
|
270
282
|
}
|
|
271
283
|
var FormulaXNode = createFormulaXNode();
|
|
272
284
|
var createFormulaXPayload = (latex) => parseLatex(latex);
|
|
273
285
|
var serializeFormulaXPayload = (doc) => serializeLatex(doc);
|
|
274
|
-
function applyFormulaPayload(editor, payload, selectedFormula) {
|
|
286
|
+
function applyFormulaPayload(editor, payload, selectedFormula, nodeName) {
|
|
275
287
|
const latex = payload.latex.trim();
|
|
276
288
|
if (selectedFormula) {
|
|
277
289
|
if (!latex) {
|
|
@@ -286,19 +298,19 @@ function applyFormulaPayload(editor, payload, selectedFormula) {
|
|
|
286
298
|
from: selectedFormula.from,
|
|
287
299
|
to: selectedFormula.to
|
|
288
300
|
},
|
|
289
|
-
createFormulaNodeContent(payload)
|
|
301
|
+
createFormulaNodeContent(payload, nodeName)
|
|
290
302
|
).run();
|
|
291
303
|
return;
|
|
292
304
|
}
|
|
293
305
|
if (!latex) {
|
|
294
306
|
return;
|
|
295
307
|
}
|
|
296
|
-
editor.chain().focus().insertContent(createFormulaNodeContent(payload)).run();
|
|
308
|
+
editor.chain().focus().insertContent(createFormulaNodeContent(payload, nodeName)).run();
|
|
297
309
|
}
|
|
298
|
-
function getSelectedFormula(editor) {
|
|
310
|
+
function getSelectedFormula(editor, nodeName) {
|
|
299
311
|
const { selection } = editor.state;
|
|
300
312
|
const node = selection.node;
|
|
301
|
-
if (node?.type?.name !==
|
|
313
|
+
if (node?.type?.name !== nodeName) {
|
|
302
314
|
return null;
|
|
303
315
|
}
|
|
304
316
|
return {
|
|
@@ -309,9 +321,9 @@ function getSelectedFormula(editor) {
|
|
|
309
321
|
}
|
|
310
322
|
};
|
|
311
323
|
}
|
|
312
|
-
function createFormulaNodeContent(payload) {
|
|
324
|
+
function createFormulaNodeContent(payload, nodeName = FORMULAX_NODE_NAME) {
|
|
313
325
|
return {
|
|
314
|
-
type:
|
|
326
|
+
type: nodeName,
|
|
315
327
|
attrs: {
|
|
316
328
|
latex: payload.latex
|
|
317
329
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -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,SAAS,YAAY;AACrB,SAAS,YAAY,sBAAuC;AAC5D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,6BAAAA;AAAA,EACA;AAAA,EACA,2BAAAC;AAAA,OACK;;;ACTP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AASA,SAAS,wBACd,OACiC;AACjC,4BAA0B,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,gFAE6D,gBAAgB,MAAM,QAAQ,MAAM,KAAK,CAAC;AAAA;AAAA,8CAE5E,WAAW,MAAM,QAAQ,MAAM,KAAK,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sFAOG,WAAW,MAAM,QAAQ,MAAM,UAAU,CAAC;AA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;AAAA,IACjC;AAAA,EACF,CAAC;AACD,SAAO;AACT;","names":["ensureFormulaXModalStyles","mountFormulaXKityEditor","ensureFormulaXModalStyles","mountFormulaXKityEditor"]}
|
|
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,SAAS,YAAY;AACrB,SAAS,YAAY,sBAAuC;AAC5D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,6BAAAA;AAAA,EACA;AAAA,EACA,2BAAAC;AAAA,OACK;;;ACTP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AASA,SAAS,wBACd,OACiC;AACjC,4BAA0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