@pie-lib/editable-html-tip-tap 3.1.3-next.20261116083926 → 3.1.3-next.20261116100657

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.
@@ -1,15 +1,8 @@
1
1
  import React from 'react';
2
2
  import { Node } from '@tiptap/core';
3
3
  import { Plugin } from 'prosemirror-state';
4
- /**
5
- * LaTeX for a MathML string, or null when there is none to give. A converter the page installed,
6
- * such as the legacy renderer's, answers first; `mmlToLatex` gives the input back when there is
7
- * none, and then this converts, so the ESM page, which installs only `renderMath`, converts too.
8
- * The converter belongs here, not in the math adapter: only authoring needs it, and every
9
- * element's delivery bundle carries the adapter. It answers an empty string for MathML it cannot
10
- * read and throws on some; neither is LaTeX, and neither may become a math node.
11
- */
12
- export declare const convertMathMlToLatex: (mathMl: any) => string | null;
4
+ import { convertMathMlToLatex } from '../utils/mathml-to-latex.js';
5
+ export { convertMathMlToLatex };
13
6
  /**
14
7
  * MathML for LaTeX, or null when there is none to give: MathJax has not started, or cannot read the
15
8
  * LaTeX. A caller keeps the LaTeX then. The MathML carries the LaTeX it was made from, so that
@@ -63,4 +56,3 @@ export declare const mathToolbarPosition: (anchor: Bounds, toolbar: {
63
56
  left: number;
64
57
  };
65
58
  export declare const MathNodeView: (props: any) => React.JSX.Element;
66
- export {};
@@ -1,63 +1,55 @@
1
- import { setToolbarOpened as e } from "../utils/toolbar.js";
2
- import { TOOLBAR_BACKGROUND as t } from "../constants.js";
3
- import { useEffect as n, useRef as r, useState as i } from "react";
4
- import { NodeViewWrapper as a, ReactNodeViewRenderer as o } from "@tiptap/react";
5
- import { Node as s } from "@tiptap/core";
6
- import { NodeSelection as c, Plugin as l, PluginKey as u, TextSelection as d } from "prosemirror-state";
7
- import f from "react-dom";
8
- import { jsx as p, jsxs as m } from "react/jsx-runtime";
9
- import { latexToMml as h, mmlToLatex as g, unWrapMath as _, wrapMath as v } from "@pie-element/shared-math-rendering-mathjax";
10
- import { MathMLToLaTeX as y } from "@pie-framework/mathml-to-latex";
11
- import { MathPreview as b, MathToolbar as x } from "@pie-lib/math-toolbar";
12
- import { inlineSideOfArrow as S, isRightToLeft as C } from "@pie-element/shared-utils";
1
+ import { convertMathMlToLatex as e } from "../utils/mathml-to-latex.js";
2
+ import { setToolbarOpened as t } from "../utils/toolbar.js";
3
+ import { TOOLBAR_BACKGROUND as n } from "../constants.js";
4
+ import { useEffect as r, useRef as i, useState as a } from "react";
5
+ import { NodeViewWrapper as o, ReactNodeViewRenderer as s } from "@tiptap/react";
6
+ import { Node as c } from "@tiptap/core";
7
+ import { NodeSelection as l, Plugin as u, PluginKey as d, TextSelection as f } from "prosemirror-state";
8
+ import p from "react-dom";
9
+ import { jsx as m, jsxs as h } from "react/jsx-runtime";
10
+ import { latexToMml as g, unWrapMath as _, wrapMath as v } from "@pie-element/shared-math-rendering-mathjax";
11
+ import { MathPreview as y, MathToolbar as b } from "@pie-lib/math-toolbar";
12
+ import { inlineSideOfArrow as x, isRightToLeft as S } from "@pie-element/shared-utils";
13
13
  // src/extensions/math.tsx
14
- var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
14
+ var C = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, w = {
15
15
  open: "\\[",
16
16
  close: "\\]"
17
- }, D = "data-pie-latex", O = (e) => e.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;"), k = (e) => typeof e == "string" ? e === "double_dollar" : ["$$", "\\["].includes(e?.open), A = (e) => {
18
- let t = e.replaceAll("&nbsp;", " "), n = g(t);
19
- if (n === t) try {
20
- n = y.convert(t);
21
- } catch {
22
- return null;
23
- }
24
- return !n || n === t ? null : n.replace(w, "") || null;
25
- }, j = (e, t) => {
26
- let n = h(e, { display: k(t) });
27
- return !n || !n.startsWith("<math") ? null : n.replace(T, "").replace("<math", () => `<math ${D}="${O(e)}"`);
28
- }, M = (e, t, n) => {
29
- if (!t?.mathMlOptions?.mmlEditing) return !1;
30
- let r = n?.getAttribute("display") === "block" ? E : null, i = (n?.getAttribute(D) ?? n?.getAttribute("data-latex"))?.trim();
31
- if (i) return {
32
- latex: i,
33
- wrapper: r
17
+ }, T = "data-pie-latex", E = (e) => e.replaceAll("&", "&amp;").replaceAll("\"", "&quot;").replaceAll("<", "&lt;").replaceAll(">", "&gt;"), D = (e) => typeof e == "string" ? e === "double_dollar" : ["$$", "\\["].includes(e?.open), O = (e, t) => {
18
+ let n = g(e, { display: D(t) });
19
+ return !n || !n.startsWith("<math") ? null : n.replace(C, "").replace("<math", () => `<math ${T}="${E(e)}"`);
20
+ }, k = (t, n, r) => {
21
+ if (!n?.mathMlOptions?.mmlEditing) return !1;
22
+ let i = r?.getAttribute("display") === "block" ? w : null, a = (r?.getAttribute(T) ?? r?.getAttribute("data-latex"))?.trim();
23
+ if (a) return {
24
+ latex: a,
25
+ wrapper: i
34
26
  };
35
- let a = A(e);
36
- if (a === null) return !1;
37
- let { unwrapped: o, wrapper: s } = _(a);
27
+ let o = e(t);
28
+ if (o === null) return !1;
29
+ let { unwrapped: s, wrapper: c } = _(o);
38
30
  return {
39
- latex: o,
40
- wrapper: s || r
31
+ latex: s,
32
+ wrapper: c || i
41
33
  };
42
- }, N = (e) => {
34
+ }, A = (e) => {
43
35
  let t = document.implementation.createHTMLDocument("").createElement("span");
44
36
  return t.setAttribute("data-type", "mathml"), t.innerHTML = e, t;
45
- }, P = new Set("math maction maligngroup malignmark menclose merror mfenced mfrac mglyph mi mlabeledtr mlongdiv mmultiscripts mn mo mover mpadded mphantom mprescripts mroot mrow ms mscarries mscarry msgroup msline mspace msqrt msrow mstack mstyle msub msubsup msup mtable mtd mtext mtr munder munderover semantics".split(" ")), F = (e) => {
46
- let t = N(e), n = (e) => {
47
- for (let t of Array.from(e.children)) if (!P.has(t.localName)) t.remove();
37
+ }, j = new Set("math maction maligngroup malignmark menclose merror mfenced mfrac mglyph mi mlabeledtr mlongdiv mmultiscripts mn mo mover mpadded mphantom mprescripts mroot mrow ms mscarries mscarry msgroup msline mspace msqrt msrow mstack mstyle msub msubsup msup mtable mtd mtext mtr munder munderover semantics".split(" ")), M = (e) => {
38
+ let t = A(e), n = (e) => {
39
+ for (let t of Array.from(e.children)) if (!j.has(t.localName)) t.remove();
48
40
  else {
49
41
  for (let { name: e, value: n } of Array.from(t.attributes)) (/^on/i.test(e) || /^\s*javascript:/i.test(n)) && t.removeAttribute(e);
50
42
  n(t);
51
43
  }
52
44
  };
53
45
  return n(t), t.innerHTML;
54
- }, I = new u("ensureTextAfterMath"), L = (e = []) => e.map((e) => ({
46
+ }, N = new d("ensureTextAfterMath"), P = (e = []) => e.map((e) => ({
55
47
  name: e,
56
48
  latex: e,
57
49
  write: e,
58
50
  label: e
59
- })), R = (e) => new l({
60
- key: I,
51
+ })), F = (e) => new u({
52
+ key: N,
61
53
  appendTransaction: (t, n, r) => {
62
54
  if (!t.some((e) => e.docChanged)) return null;
63
55
  let i = r.tr, a = !1;
@@ -68,7 +60,7 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
68
60
  }
69
61
  }), a ? i : null;
70
62
  }
71
- }), z = (e, t) => {
63
+ }), I = (e, t) => {
72
64
  let n;
73
65
  for (n = t; n > 0; n--) {
74
66
  let t = e.nodeAt(n);
@@ -76,30 +68,30 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
76
68
  if (t && t?.type?.name !== "text") break;
77
69
  }
78
70
  return n;
79
- }, B = (e, t) => {
71
+ }, L = (e, t) => {
80
72
  let { node: n } = e.domAtPos(t);
81
73
  return n.nodeType === 1 ? n : n.parentElement;
82
- }, V = new l({
83
- key: new u("zeroWidthSpaceHandling"),
74
+ }, R = new u({
75
+ key: new d("zeroWidthSpaceHandling"),
84
76
  props: { handleKeyDown(e, t) {
85
77
  let { state: n, dispatch: r } = e, { selection: i, doc: a } = n, { from: o, empty: s } = i;
86
78
  if (s && t.key === "Backspace" && o > 0) {
87
- let e = z(a, o);
79
+ let e = I(a, o);
88
80
  return e !== -1 && (r(n.tr.delete(e, o)), !0);
89
81
  }
90
- if (s && o > 0 && S(t.key, B(e, o)) === "inline-start") {
91
- let e = z(a, o);
82
+ if (s && o > 0 && x(t.key, L(e, o)) === "inline-start") {
83
+ let e = I(a, o);
92
84
  if (e === -1) return !1;
93
85
  let t = n.doc.resolve(e);
94
86
  if (t.nodeAfter || t.nodeBefore) {
95
87
  let t = n.doc.resolve(e);
96
- return r(n.tr.setSelection(c.create(n.doc, t.pos))), !0;
88
+ return r(n.tr.setSelection(l.create(n.doc, t.pos))), !0;
97
89
  }
98
- return r(n.tr.setSelection(d.create(n.doc, o - 2))), !0;
90
+ return r(n.tr.setSelection(f.create(n.doc, o - 2))), !0;
99
91
  }
100
92
  return !1;
101
93
  } }
102
- }), H = s.create({
94
+ }), z = c.create({
103
95
  name: "math",
104
96
  group: "inline",
105
97
  inline: !0,
@@ -112,7 +104,7 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
112
104
  };
113
105
  },
114
106
  addProseMirrorPlugins() {
115
- return [R(this.name), V];
107
+ return [F(this.name), R];
116
108
  },
117
109
  parseHTML() {
118
110
  return [
@@ -125,12 +117,12 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
125
117
  priority: 60,
126
118
  getAttrs: (e) => {
127
119
  let t = e.querySelector("math");
128
- return M(t?.outerHTML || e.innerHTML, this.options, t);
120
+ return k(t?.outerHTML || e.innerHTML, this.options, t);
129
121
  }
130
122
  },
131
123
  {
132
124
  tag: "math",
133
- getAttrs: (e) => M(e.outerHTML, this.options, e)
125
+ getAttrs: (e) => k(e.outerHTML, this.options, e)
134
126
  },
135
127
  {
136
128
  tag: "span[data-type=\"mathml\"]",
@@ -143,20 +135,20 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
143
135
  ];
144
136
  },
145
137
  addCommands() {
146
- return { insertMath: (t = "") => ({ tr: n, editor: r, dispatch: i }) => {
147
- let { state: a } = r.view, o = a.schema.nodes.math.create({ latex: t }), { selection: s } = a, l = s.$from.pos;
148
- if (n.insert(l, o), o?.type?.name === this.name) {
149
- let e = c.create(n.doc, s.$from.pos);
138
+ return { insertMath: (e = "") => ({ tr: n, editor: r, dispatch: i }) => {
139
+ let { state: a } = r.view, o = a.schema.nodes.math.create({ latex: e }), { selection: s } = a, c = s.$from.pos;
140
+ if (n.insert(c, o), o?.type?.name === this.name) {
141
+ let e = l.create(n.doc, s.$from.pos);
150
142
  n.setSelection(e);
151
143
  }
152
- return i(n), e(r, !0), !0;
144
+ return i(n), t(r, !0), !0;
153
145
  } };
154
146
  },
155
147
  renderHTML({ HTMLAttributes: e }) {
156
- if (e.html) return N(e.html);
148
+ if (e.html) return A(e.html);
157
149
  if (this.options.mathMlOptions?.mmlOutput) {
158
- let t = j(e.latex, e.wrapper);
159
- if (t) return N(t);
150
+ let t = O(e.latex, e.wrapper);
151
+ if (t) return A(t);
160
152
  }
161
153
  return [
162
154
  "span",
@@ -168,20 +160,20 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
168
160
  ];
169
161
  },
170
162
  addNodeView() {
171
- return o((e) => /* @__PURE__ */ p(q, {
163
+ return s((e) => /* @__PURE__ */ m(W, {
172
164
  ...e,
173
165
  options: this.options
174
166
  }));
175
167
  }
176
- }), U = (e, t, n, r, i) => {
168
+ }), B = (e, t, n, r, i) => {
177
169
  let a = n ? e.right - t : e.left;
178
170
  return Math.max(r.left + i, Math.min(a, r.right - t - i));
179
- }, W = (e) => [
171
+ }, V = (e) => [
180
172
  "auto",
181
173
  "scroll",
182
174
  "hidden",
183
175
  "clip"
184
- ].includes(e), G = (e) => {
176
+ ].includes(e), H = (e) => {
185
177
  let t = {
186
178
  top: 0,
187
179
  bottom: window.innerHeight,
@@ -190,14 +182,14 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
190
182
  };
191
183
  for (let n = e; n && n !== document.body && n !== document.documentElement; n = n.parentElement) {
192
184
  let { overflowX: e, overflowY: r, position: i } = window.getComputedStyle(n);
193
- if (W(e) || W(r)) {
185
+ if (V(e) || V(r)) {
194
186
  let i = n.getBoundingClientRect();
195
- W(r) && (t.top = Math.max(t.top, i.top), t.bottom = Math.min(t.bottom, i.bottom)), W(e) && (t.left = Math.max(t.left, i.left), t.right = Math.min(t.right, i.right));
187
+ V(r) && (t.top = Math.max(t.top, i.top), t.bottom = Math.min(t.bottom, i.bottom)), V(e) && (t.left = Math.max(t.left, i.left), t.right = Math.min(t.right, i.right));
196
188
  }
197
189
  if (i === "fixed") break;
198
190
  }
199
191
  return t;
200
- }, K = (e, t, n, r, i) => {
192
+ }, U = (e, t, n, r, i) => {
201
193
  let a = (e) => Math.max(r.top + i, Math.min(e, r.bottom - t.height - i)), o = r.right - e.right - i >= t.width, s = e.left - r.left - i >= t.width;
202
194
  if (o && (!n || !s)) return {
203
195
  top: a(e.top),
@@ -210,34 +202,34 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
210
202
  let c = r.bottom - e.bottom - i, l = e.top - r.top - i;
211
203
  return {
212
204
  top: a(t.height <= c || c >= l ? e.bottom : e.top - t.height),
213
- left: U(e, t.width, n, r, i)
205
+ left: B(e, t.width, n, r, i)
214
206
  };
215
- }, q = (o) => {
216
- let { node: s, updateAttributes: c, editor: l, selected: u, options: h, getPos: g } = o, [_, v] = i(u), y = r(null), S = r(null), w = r(Date.now()), [T, E] = i({
207
+ }, W = (e) => {
208
+ let { node: s, updateAttributes: c, editor: l, selected: u, options: d, getPos: g } = e, [_, v] = a(u), x = i(null), C = i(null), w = i(Date.now()), [T, E] = a({
217
209
  top: 0,
218
210
  left: 0
219
- }), { math: D = {} } = h || {}, { keypadMode: O, controlledKeypadMode: k = !0, customKeys: A = [], keyPadCharacterRef: j, setKeypadInteraction: M } = D, N = s.attrs.latex || "", P = (e) => {
211
+ }), { math: D = {} } = d || {}, { keypadMode: O, controlledKeypadMode: k = !0, customKeys: A = [], keyPadCharacterRef: j, setKeypadInteraction: N } = D, F = s.attrs.latex || "", I = (e) => {
220
212
  c({ latex: e });
221
- }, I = (e, { moveCursorAfterNode: t = !0 } = {}) => {
213
+ }, L = (e, { moveCursorAfterNode: t = !0 } = {}) => {
222
214
  if (c({ latex: e }), v(!1), t && typeof g == "function") {
223
- let e = g(), { doc: t } = l.state, n = d.create(t, e + s.nodeSize), r = l.state.tr.setSelection(n);
215
+ let e = g(), { doc: t } = l.state, n = f.create(t, e + s.nodeSize), r = l.state.tr.setSelection(n);
224
216
  l.view.dispatch(r);
225
217
  }
226
218
  l.commands.focus();
227
219
  };
228
- return n(() => {
220
+ return r(() => {
229
221
  if (!u) return;
230
222
  let { selection: e } = l.state;
231
223
  e.node?.type?.name === "math" && v(!0);
232
- }, [u, l]), n(() => {
233
- e(l, u || _);
224
+ }, [u, l]), r(() => {
225
+ t(l, u || _);
234
226
  }, [
235
227
  l,
236
228
  _,
237
229
  u
238
- ]), n(() => () => {
239
- l && !l.isDestroyed && e(l, !1);
240
- }, [l]), n(() => {
230
+ ]), r(() => () => {
231
+ l && !l.isDestroyed && t(l, !1);
232
+ }, [l]), r(() => {
241
233
  if (!l || !_) {
242
234
  E({
243
235
  top: 0,
@@ -246,16 +238,16 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
246
238
  return;
247
239
  }
248
240
  let e = () => {
249
- if (!y.current) return;
250
- let { from: e } = l.state.selection, t = l.view.coordsAtPos(e), n = S.current?.getBoundingClientRect?.(), r = C(S.current ?? l.view.dom), i = n?.height ? n.top : t.top, a = n?.height ? n.bottom : t.bottom ?? t.top, { left: o, right: s } = n?.width ? n : t, c = l._tiptapContainerEl || document.body, { top: u, left: d } = K({
241
+ if (!x.current) return;
242
+ let { from: e } = l.state.selection, t = l.view.coordsAtPos(e), n = C.current?.getBoundingClientRect?.(), r = S(C.current ?? l.view.dom), i = n?.height ? n.top : t.top, a = n?.height ? n.bottom : t.bottom ?? t.top, { left: o, right: s } = n?.width ? n : t, c = l._tiptapContainerEl || document.body, { top: u, left: d } = U({
251
243
  top: i,
252
244
  bottom: a,
253
245
  left: o,
254
246
  right: s
255
247
  }, {
256
- width: y.current.offsetWidth,
257
- height: y.current.offsetHeight
258
- }, r, G(c), 8), f = c.getBoundingClientRect();
248
+ width: x.current.offsetWidth,
249
+ height: x.current.offsetHeight
250
+ }, r, H(c), 8), f = c.getBoundingClientRect();
259
251
  E({
260
252
  top: u - f.top,
261
253
  left: d - f.left
@@ -271,20 +263,20 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
271
263
  t = null, e();
272
264
  }), window.addEventListener("scroll", n, !0), window.addEventListener("resize", n);
273
265
  let r = typeof ResizeObserver > "u" ? null : new ResizeObserver(n);
274
- return [y.current, S.current].forEach((e) => e && r?.observe(e)), () => {
266
+ return [x.current, C.current].forEach((e) => e && r?.observe(e)), () => {
275
267
  t !== null && cancelAnimationFrame(t), window.removeEventListener("scroll", n, !0), window.removeEventListener("resize", n), r?.disconnect();
276
268
  };
277
- }, [l, _]), n(() => {
269
+ }, [l, _]), r(() => {
278
270
  let e = performance.now(), t = !1, n = () => {
279
271
  t = !0;
280
272
  }, r = (n) => {
281
273
  let r = n?.detail === 0 ? n.timeStamp < e : !t;
282
274
  if (t = !1, r) return;
283
275
  let i = n?.target, a = (document.querySelectorAll?.("[id^=\"equation-editor-select\"][id*=\"listbox\"], [aria-labelledby=\"equation-editor-label\"][role=\"listbox\"]") || []).length > 0, o = !!(i?.id && i.id.includes("equation-editor-select")) || !!i?.closest?.("[id*=\"equation-editor-select\"]"), c = !!i?.closest?.(`.math-node-${w.current}`);
284
- if (y.current && !y.current.contains(i) && !i?.closest?.("[data-inline-node]") && !a && !o && !c) {
276
+ if (x.current && !x.current.contains(i) && !i?.closest?.("[data-inline-node]") && !a && !o && !c) {
285
277
  v(!1);
286
278
  let e = !!l?.view?.dom?.contains(i);
287
- I(s.attrs.latex, { moveCursorAfterNode: !e });
279
+ L(s.attrs.latex, { moveCursorAfterNode: !e });
288
280
  }
289
281
  };
290
282
  return _ && (document.addEventListener("mousedown", n, !0), document.addEventListener("click", r)), () => {
@@ -294,7 +286,7 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
294
286
  l,
295
287
  _,
296
288
  s
297
- ]), s.attrs.html && !N ? /* @__PURE__ */ p(a, {
289
+ ]), s.attrs.html && !F ? /* @__PURE__ */ m(o, {
298
290
  as: "span",
299
291
  "data-type": "mathml",
300
292
  style: {
@@ -302,8 +294,8 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
302
294
  margin: "0 4px"
303
295
  },
304
296
  contentEditable: !1,
305
- dangerouslySetInnerHTML: { __html: F(s.attrs.html) }
306
- }) : /* @__PURE__ */ m(a, {
297
+ dangerouslySetInnerHTML: { __html: M(s.attrs.html) }
298
+ }) : /* @__PURE__ */ h(o, {
307
299
  className: `math-node-${w.current}`,
308
300
  style: {
309
301
  display: "inline-flex",
@@ -311,34 +303,34 @@ var w = /\\left\.\s*|\\right\.\s*/g, T = /<mo(?: [^>]*)?>&#x2061;<\/mo>/g, E = {
311
303
  margin: "0 4px"
312
304
  },
313
305
  "data-selected": u,
314
- children: [/* @__PURE__ */ p("div", {
315
- ref: S,
306
+ children: [/* @__PURE__ */ m("div", {
307
+ ref: C,
316
308
  onClick: () => v(!0),
317
309
  contentEditable: !1,
318
- children: /* @__PURE__ */ p(b, { latex: N })
319
- }), _ && f.createPortal(/* @__PURE__ */ p("div", {
320
- ref: y,
310
+ children: /* @__PURE__ */ m(y, { latex: F })
311
+ }), _ && p.createPortal(/* @__PURE__ */ m("div", {
312
+ ref: x,
321
313
  "data-toolbar-for": l.instanceId,
322
314
  style: {
323
315
  position: "absolute",
324
316
  top: `${T.top}px`,
325
317
  left: `${T.left}px`,
326
318
  zIndex: 1e3,
327
- background: t,
319
+ background: n,
328
320
  boxShadow: "0px 1px 5px 0px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)"
329
321
  },
330
- children: /* @__PURE__ */ p(x, {
331
- latex: N,
322
+ children: /* @__PURE__ */ m(b, {
323
+ latex: F,
332
324
  autoFocus: !0,
333
- onChange: P,
334
- onDone: I,
325
+ onChange: I,
326
+ onDone: L,
335
327
  keypadMode: O,
336
328
  controlledKeypadMode: k,
337
- additionalKeys: L(A),
329
+ additionalKeys: P(A),
338
330
  keyPadCharacterRef: j,
339
- setKeypadInteraction: M
331
+ setKeypadInteraction: N
340
332
  })
341
333
  }), l?._tiptapContainerEl || document.body)]
342
334
  });
343
335
  };
344
- export { R as EnsureTextAfterMathPlugin, H as MathNode, q as MathNodeView, V as ZeroWidthSpaceHandlingPlugin, j as convertLatexToMathMl, A as convertMathMlToLatex, U as mathToolbarLeft, K as mathToolbarPosition, F as sanitizeMathMl, G as visibleBounds };
336
+ export { F as EnsureTextAfterMathPlugin, z as MathNode, W as MathNodeView, R as ZeroWidthSpaceHandlingPlugin, O as convertLatexToMathMl, e as convertMathMlToLatex, B as mathToolbarLeft, U as mathToolbarPosition, M as sanitizeMathMl, H as visibleBounds };
@@ -0,0 +1,10 @@
1
+ /**
2
+ * LaTeX for a MathML string, or null when there is none to give. A converter the page installed,
3
+ * such as the legacy renderer's, answers first; `mmlToLatex` gives the input back when there is
4
+ * none, and then this converts, so the ESM page, which installs only `renderMath`, converts too.
5
+ * The legacy renderer's converter is this one, so both read the rewritten MathML.
6
+ * The converter belongs here, not in the math adapter: only authoring needs it, and every
7
+ * element's delivery bundle carries the adapter. It answers an empty string for MathML it cannot
8
+ * read and throws on some; neither is LaTeX, and neither may become a math node.
9
+ */
10
+ export declare const convertMathMlToLatex: (mathMl: string) => string | null;
@@ -0,0 +1,70 @@
1
+ import { mmlToLatex as e } from "@pie-element/shared-math-rendering-mathjax";
2
+ import { MathMLToLaTeX as t } from "@pie-framework/mathml-to-latex";
3
+ // src/utils/mathml-to-latex.ts
4
+ var n = /^[⁡-⁤]$/, r = new Set("arccos arcsin arctan arg cos cosh cot coth csc deg det dim exp gcd hom inf ker lg lim ln log max min Pr sec sin sinh sup tan tanh".split(" ")), i = /_\{\}\^/g, a = /\\left\.\s*|\\right\.\s*/g, o = /\\over(right|leftright)arrow(?!\{)/g, s = /\\degree(?![a-zA-Z])/g, c = /\\_\{/g, l = /\\(left|right)(?![a-zA-Z])\s*(\\[a-zA-Z]+|\\.|[^\s\\])|\\(begin|end)\{[^}]*\}|\\[a-zA-Z]+|\\.|[{}]|[^\\{}]+/g, u = {
5
+ "{": "\\{",
6
+ "}": "\\}"
7
+ }, d = /* @__PURE__ */ new Set(["|", "\\|"]), f = (e) => {
8
+ let t = document.implementation.createHTMLDocument("").createElement("span");
9
+ return t.innerHTML = e, t;
10
+ }, p = (e) => {
11
+ let t = new XMLSerializer();
12
+ return e.map((e) => t.serializeToString(e)).join("").replaceAll("&nbsp;", "&#xA0;");
13
+ }, m = (e, t, n) => {
14
+ let r = e.ownerDocument.createElementNS(e.namespaceURI, t);
15
+ return n !== void 0 && (r.textContent = n), r;
16
+ }, h = (e) => e?.localName === "mo", g = (e) => {
17
+ for (let t of Array.from(e.querySelectorAll("mo"))) n.test(t.textContent?.trim() ?? "") && t.remove();
18
+ for (let t of Array.from(e.querySelectorAll("mi, mo"))) {
19
+ let e = t.textContent?.trim() ?? "";
20
+ r.has(e) && (t.textContent = `\\${e}`);
21
+ }
22
+ for (let t of Array.from(e.querySelectorAll("mfrac")).reverse()) {
23
+ if (t.children.length !== 2 || Number.parseFloat(t.getAttribute("linethickness") ?? "") !== 0) continue;
24
+ let [e, n] = Array.from(t.children, (e) => b(`<math>${p([e])}</math>`));
25
+ t.replaceWith(m(t, "mi", `{${e} \\atop ${n}}`));
26
+ }
27
+ for (let t of Array.from(e.querySelectorAll("msup"))) {
28
+ if (t.children.length !== 2) continue;
29
+ let [e, n] = Array.from(t.children), r = m(t, "munderover");
30
+ e.localName === "mrow" && e.children.length > 1 && !(h(e.firstElementChild) && h(e.lastElementChild)) && (e.prepend(m(t, "mo", "(")), e.append(m(t, "mo", ")"))), r.append(e, m(t, "mrow"), n), t.replaceWith(r);
31
+ }
32
+ for (let t of Array.from(e.querySelectorAll("mtable"))) {
33
+ if (t.parentElement?.closest("mtable, mfenced")) continue;
34
+ let e = m(t, "mtable"), n = m(t, "mtr"), r = m(t, "mtd");
35
+ e.append(n), n.append(r), t.replaceWith(e), r.append(t);
36
+ }
37
+ }, _ = (e) => {
38
+ let t = [], n = [{
39
+ start: 0,
40
+ open: []
41
+ }], r = (e) => t.push(...e.open.map(() => "\\right."));
42
+ for (let [i, a, o, s] of e.matchAll(l)) {
43
+ let e = n[n.length - 1];
44
+ if (a) {
45
+ let n = u[o] ?? o;
46
+ if (!(a === "right" || d.has(n) && e.open.at(-1) === n)) {
47
+ e.open.push(n), t.push(`\\left${n}`);
48
+ continue;
49
+ }
50
+ e.open.pop() || t.splice(e.start, 0, "\\left."), t.push(`\\right${n}`);
51
+ } else i === "{" || s === "begin" ? (t.push(i), n.push({
52
+ start: t.length,
53
+ open: []
54
+ })) : ((i === "}" || s === "end") && n.length > 1 && (r(e), n.pop()), t.push(i));
55
+ }
56
+ for (let e of n.reverse()) r(e);
57
+ return t.join("");
58
+ }, v = (e) => _(e.replace(i, "^").replace(a, "").replace(o, "\\$1arrow").replaceAll("^{\\degree}", "^{\\circ}").replace(s, "^{\\circ}").replace(c, "{}_{")), y = (e) => {
59
+ let t = f(e);
60
+ return g(t), p(Array.from(t.childNodes));
61
+ }, b = (e) => v(t.convert(y(e))), x = (n) => {
62
+ let r, i;
63
+ try {
64
+ r = y(n.replaceAll("&nbsp;", " ")), i = e(r), i === r && (i = t.convert(r));
65
+ } catch {
66
+ return null;
67
+ }
68
+ return !i || i === r ? null : v(i) || null;
69
+ };
70
+ export { x as convertMathMlToLatex };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pie-lib/editable-html-tip-tap",
3
- "version": "3.1.3-next.20261116083926",
3
+ "version": "3.1.3-next.20261116100657",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "repository": {