@pie-lib/math-input-mathlive 1.1.5-beta.9 → 2.0.1-next.20261107131445

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.
Files changed (195) hide show
  1. package/README.md +84 -109
  2. package/dist/_virtual/_rolldown/runtime.js +11 -0
  3. package/dist/horizontal-keypad.d.ts +22 -0
  4. package/dist/horizontal-keypad.js +54 -0
  5. package/dist/index.d.ts +20 -0
  6. package/dist/index.js +12 -0
  7. package/dist/keypad/index.d.ts +40 -0
  8. package/dist/keypad/index.js +245 -0
  9. package/dist/keypad/keys-layout.d.ts +7 -0
  10. package/dist/keypad/keys-layout.js +5 -0
  11. package/dist/keys/basic-operators.d.ts +5 -0
  12. package/dist/keys/basic-operators.js +30 -0
  13. package/dist/keys/chars.d.ts +5 -0
  14. package/dist/keys/comparison.d.ts +4 -0
  15. package/dist/keys/comparison.js +32 -0
  16. package/dist/keys/constants.d.ts +4 -0
  17. package/dist/keys/constants.js +35 -0
  18. package/dist/keys/digits.d.ts +15 -0
  19. package/dist/keys/digits.js +34 -0
  20. package/dist/keys/edit.d.ts +6 -0
  21. package/dist/keys/edit.js +9 -0
  22. package/dist/keys/exponent.d.ts +4 -0
  23. package/dist/keys/exponent.js +28 -0
  24. package/dist/keys/fractions.d.ts +3 -0
  25. package/dist/keys/fractions.js +27 -0
  26. package/dist/keys/geometry.d.ts +23 -0
  27. package/dist/keys/geometry.js +127 -0
  28. package/dist/keys/grades.d.ts +9 -0
  29. package/dist/keys/grades.js +414 -0
  30. package/dist/keys/index.d.ts +6 -0
  31. package/dist/keys/index.js +50 -0
  32. package/dist/keys/log.d.ts +3 -0
  33. package/dist/keys/log.js +25 -0
  34. package/dist/keys/logic.d.ts +2 -0
  35. package/dist/keys/logic.js +13 -0
  36. package/dist/keys/matrices.d.ts +2 -0
  37. package/dist/keys/matrices.js +17 -0
  38. package/dist/keys/misc.d.ts +10 -0
  39. package/dist/keys/misc.js +60 -0
  40. package/dist/keys/navigation.d.ts +2 -0
  41. package/dist/keys/navigation.js +13 -0
  42. package/dist/keys/operators.d.ts +1 -0
  43. package/dist/keys/operators.js +11 -0
  44. package/dist/keys/statistics.d.ts +5 -0
  45. package/dist/keys/statistics.js +38 -0
  46. package/dist/keys/sub-sup.d.ts +2 -0
  47. package/dist/keys/sub-sup.js +17 -0
  48. package/dist/keys/trigonometry.d.ts +6 -0
  49. package/dist/keys/trigonometry.js +43 -0
  50. package/dist/keys/utils.d.ts +5 -0
  51. package/dist/keys/utils.js +24 -0
  52. package/dist/keys/vars.d.ts +3 -0
  53. package/dist/keys/vars.js +22 -0
  54. package/dist/latex-bridge.d.ts +197 -0
  55. package/dist/latex-bridge.js +210 -0
  56. package/dist/longdiv.d.ts +24 -0
  57. package/dist/longdiv.js +43 -0
  58. package/dist/math-input.d.ts +26 -0
  59. package/dist/math-input.js +74 -0
  60. package/dist/mathlive-instance.d.ts +221 -0
  61. package/dist/mathlive-instance.js +159 -0
  62. package/dist/mf/common-styles.d.ts +594 -0
  63. package/dist/mf/common-styles.js +80 -0
  64. package/dist/mf/field-label.d.ts +16 -0
  65. package/dist/mf/field-label.js +13 -0
  66. package/dist/mf/index.d.ts +4 -0
  67. package/dist/mf/index.js +21 -0
  68. package/dist/mf/input.d.ts +94 -0
  69. package/dist/mf/input.js +127 -0
  70. package/dist/mf/static.d.ts +143 -0
  71. package/dist/mf/static.js +230 -0
  72. package/dist/selection.d.ts +43 -0
  73. package/dist/selection.js +39 -0
  74. package/package.json +32 -18
  75. package/lib/__tests__/composites.test.js +0 -255
  76. package/lib/__tests__/drop-in-compat.test.js +0 -133
  77. package/lib/__tests__/embedded-fonts.test.js +0 -121
  78. package/lib/__tests__/index.test.js +0 -118
  79. package/lib/__tests__/input-imperative.test.js +0 -155
  80. package/lib/__tests__/keypad-label.test.js +0 -231
  81. package/lib/__tests__/keypad-render.test.js +0 -206
  82. package/lib/__tests__/latex-bridge.test.js +0 -386
  83. package/lib/__tests__/mathlive-instance.test.js +0 -419
  84. package/lib/__tests__/mount-race.test.js +0 -218
  85. package/lib/__tests__/static-prompts.test.js +0 -405
  86. package/lib/__tests__/tmp-markup.test.js +0 -26
  87. package/lib/horizontal-keypad.js +0 -101
  88. package/lib/horizontal-keypad.js.map +0 -1
  89. package/lib/index.js +0 -143
  90. package/lib/index.js.map +0 -1
  91. package/lib/keypad/index.js +0 -431
  92. package/lib/keypad/index.js.map +0 -1
  93. package/lib/keypad/keys-layout.js +0 -22
  94. package/lib/keypad/keys-layout.js.map +0 -1
  95. package/lib/keys/basic-operators.js +0 -33
  96. package/lib/keys/basic-operators.js.map +0 -1
  97. package/lib/keys/chars.js +0 -12
  98. package/lib/keys/chars.js.map +0 -1
  99. package/lib/keys/comparison.js +0 -39
  100. package/lib/keys/comparison.js.map +0 -1
  101. package/lib/keys/constants.js +0 -37
  102. package/lib/keys/constants.js.map +0 -1
  103. package/lib/keys/digits.js +0 -46
  104. package/lib/keys/digits.js.map +0 -1
  105. package/lib/keys/edit.js +0 -14
  106. package/lib/keys/edit.js.map +0 -1
  107. package/lib/keys/exponent.js +0 -30
  108. package/lib/keys/exponent.js.map +0 -1
  109. package/lib/keys/fractions.js +0 -29
  110. package/lib/keys/fractions.js.map +0 -1
  111. package/lib/keys/geometry.js +0 -143
  112. package/lib/keys/geometry.js.map +0 -1
  113. package/lib/keys/grades.js +0 -259
  114. package/lib/keys/grades.js.map +0 -1
  115. package/lib/keys/index.js +0 -35
  116. package/lib/keys/index.js.map +0 -1
  117. package/lib/keys/log.js +0 -27
  118. package/lib/keys/log.js.map +0 -1
  119. package/lib/keys/logic.js +0 -19
  120. package/lib/keys/logic.js.map +0 -1
  121. package/lib/keys/matrices.js +0 -19
  122. package/lib/keys/matrices.js.map +0 -1
  123. package/lib/keys/misc.js +0 -69
  124. package/lib/keys/misc.js.map +0 -1
  125. package/lib/keys/navigation.js +0 -20
  126. package/lib/keys/navigation.js.map +0 -1
  127. package/lib/keys/operators.js +0 -15
  128. package/lib/keys/operators.js.map +0 -1
  129. package/lib/keys/statistics.js +0 -40
  130. package/lib/keys/statistics.js.map +0 -1
  131. package/lib/keys/sub-sup.js +0 -19
  132. package/lib/keys/sub-sup.js.map +0 -1
  133. package/lib/keys/trigonometry.js +0 -45
  134. package/lib/keys/trigonometry.js.map +0 -1
  135. package/lib/keys/utils.js +0 -87
  136. package/lib/keys/utils.js.map +0 -1
  137. package/lib/keys/vars.js +0 -24
  138. package/lib/keys/vars.js.map +0 -1
  139. package/lib/latex-bridge.js +0 -508
  140. package/lib/latex-bridge.js.map +0 -1
  141. package/lib/math-input.js +0 -143
  142. package/lib/math-input.js.map +0 -1
  143. package/lib/mathlive-instance.js +0 -585
  144. package/lib/mathlive-instance.js.map +0 -1
  145. package/lib/mf/common-styles.js +0 -203
  146. package/lib/mf/common-styles.js.map +0 -1
  147. package/lib/mf/index.js +0 -84
  148. package/lib/mf/index.js.map +0 -1
  149. package/lib/mf/input.js +0 -364
  150. package/lib/mf/input.js.map +0 -1
  151. package/lib/mf/static.js +0 -500
  152. package/lib/mf/static.js.map +0 -1
  153. package/src/__tests__/composites.test.jsx +0 -220
  154. package/src/__tests__/drop-in-compat.test.jsx +0 -112
  155. package/src/__tests__/index.test.jsx +0 -109
  156. package/src/__tests__/input-imperative.test.jsx +0 -144
  157. package/src/__tests__/keypad-label.test.jsx +0 -283
  158. package/src/__tests__/keypad-render.test.jsx +0 -123
  159. package/src/__tests__/latex-bridge.test.js +0 -389
  160. package/src/__tests__/mathlive-instance.test.js +0 -418
  161. package/src/__tests__/mount-race.test.jsx +0 -142
  162. package/src/__tests__/static-prompts.test.jsx +0 -364
  163. package/src/horizontal-keypad.jsx +0 -73
  164. package/src/index.jsx +0 -63
  165. package/src/keypad/index.jsx +0 -386
  166. package/src/keypad/keys-layout.js +0 -16
  167. package/src/keys/basic-operators.js +0 -32
  168. package/src/keys/chars.js +0 -5
  169. package/src/keys/comparison.js +0 -28
  170. package/src/keys/constants.js +0 -35
  171. package/src/keys/digits.js +0 -40
  172. package/src/keys/edit.js +0 -3
  173. package/src/keys/exponent.js +0 -28
  174. package/src/keys/fractions.js +0 -26
  175. package/src/keys/geometry.js +0 -149
  176. package/src/keys/grades.js +0 -367
  177. package/src/keys/index.js +0 -20
  178. package/src/keys/log.js +0 -22
  179. package/src/keys/logic.js +0 -15
  180. package/src/keys/matrices.js +0 -15
  181. package/src/keys/misc.js +0 -71
  182. package/src/keys/navigation.js +0 -8
  183. package/src/keys/operators.js +0 -10
  184. package/src/keys/statistics.js +0 -38
  185. package/src/keys/sub-sup.js +0 -15
  186. package/src/keys/trigonometry.js +0 -15
  187. package/src/keys/utils.js +0 -66
  188. package/src/keys/vars.js +0 -19
  189. package/src/latex-bridge.js +0 -524
  190. package/src/math-input.jsx +0 -115
  191. package/src/mathlive-instance.js +0 -582
  192. package/src/mf/common-styles.js +0 -210
  193. package/src/mf/index.js +0 -30
  194. package/src/mf/input.jsx +0 -319
  195. package/src/mf/static.jsx +0 -479
@@ -0,0 +1,74 @@
1
+ import { baseSet as e } from "./keys/index.js";
2
+ import { keyToAction as t } from "./latex-bridge.js";
3
+ import { Input as n } from "./mf/input.js";
4
+ import { KeyPad as r } from "./keypad/index.js";
5
+ import i from "react";
6
+ import a from "prop-types";
7
+ import { styled as o } from "@mui/material/styles";
8
+ import s from "debug";
9
+ import { jsx as c, jsxs as l } from "react/jsx-runtime";
10
+ //#region src/math-input.tsx
11
+ var u = s("pie-lib:math-input-mathlive"), d = "rgba(0, 0, 0, 0.23)", f = o("div")(({ theme: e, focused: t }) => ({
12
+ borderRadius: "4px",
13
+ border: `solid 1px ${t ? e.palette.primary.main : d}`,
14
+ marginTop: e.spacing(1),
15
+ marginBottom: e.spacing(1),
16
+ transition: "border 200ms linear"
17
+ })), p = o("div")({
18
+ width: "100%",
19
+ display: "flex"
20
+ }), m = o(n)(({ theme: e }) => ({
21
+ width: "100%",
22
+ transition: "border 200ms linear",
23
+ padding: e.spacing(1),
24
+ "& math-field:focus-within": {
25
+ outline: "none",
26
+ boxShadow: "none"
27
+ }
28
+ })), h = class extends i.Component {
29
+ static propTypes = {
30
+ className: a.string,
31
+ keyset: a.array,
32
+ displayMode: a.oneOf(["block", "block-on-focus"]),
33
+ latex: a.string,
34
+ onChange: a.func
35
+ };
36
+ static defaultProps = {
37
+ keyset: [],
38
+ displayMode: "block"
39
+ };
40
+ constructor(e) {
41
+ super(e), this.state = { focused: !1 };
42
+ }
43
+ keypadPress = (e) => {
44
+ if (u("[keypadPress] key:", e), !this.input) return;
45
+ let n = t(e);
46
+ n && (n.type === "command" ? this.input.keystroke(n.value) : this.input.write(n.value));
47
+ };
48
+ inputFocus = () => this.setState({ focused: !0 });
49
+ inputBlur = () => this.setState({ focused: !1 });
50
+ changeLatex = (e) => {
51
+ let { onChange: t } = this.props;
52
+ t && e !== this.props.latex && (u("[changeLatex]", e, this.props.latex), t(e));
53
+ };
54
+ render() {
55
+ let { className: t, keyset: n, latex: i } = this.props, { focused: a } = this.state;
56
+ return /* @__PURE__ */ l(f, {
57
+ className: t,
58
+ focused: a,
59
+ children: [/* @__PURE__ */ c(m, {
60
+ innerRef: (e) => this.input = e,
61
+ onFocus: this.inputFocus,
62
+ onBlur: this.inputBlur,
63
+ latex: i,
64
+ onChange: this.changeLatex
65
+ }), /* @__PURE__ */ c(p, { children: /* @__PURE__ */ c(r, {
66
+ baseSet: e,
67
+ additionalKeys: n,
68
+ onPress: this.keypadPress
69
+ }) })]
70
+ });
71
+ }
72
+ };
73
+ //#endregion
74
+ export { h as MathInput, h as default };
@@ -0,0 +1,221 @@
1
+ import { NEWLINE_EMBED } from './latex-bridge.js';
2
+ /**
3
+ * Tell the package where the MathLive fonts are served from.
4
+ *
5
+ * Call before `loadMathLive()`.
6
+ *
7
+ * - a path/URL: served by you, no third-party request
8
+ * - `null`: skip font loading; note `\\neq`, `\\nsim` and `\\ncong` then
9
+ * render incorrectly, being built from Private Use Area glyphs
10
+ * - not called: falls back to a version-pinned CDN
11
+ *
12
+ * The fonts ship inside the `mathlive` package (`node_modules/mathlive/fonts`)
13
+ * ready to copy into whatever the host app serves statically.
14
+ *
15
+ * @param {string|null} [dir]
16
+ */
17
+ export declare const configureFonts: (dir: any) => void;
18
+ /**
19
+ * What the spacebar inserts in math mode.
20
+ *
21
+ * MathLive's `mathModeSpace` defaults to an empty string, which makes the
22
+ * spacebar a no-op - users cannot type a space at all. `\\ ` (a LaTeX control
23
+ * space) is what MathQuill serialised spaces as, so existing content and the
24
+ * MathJax renderer in @pie-lib/math-rendering both already understand it.
25
+ *
26
+ * A literal " " is not usable: LaTeX skips raw whitespace.
27
+ */
28
+ export declare const MATH_MODE_SPACE = "\\ ";
29
+ /**
30
+ * Custom macros for the pie-specific commands that the MathQuill fork
31
+ * understood but stock LaTeX does not.
32
+ *
33
+ * Kept deliberately in sync with the MathJax macros in
34
+ * @pie-lib/math-rendering (`render-math.js`) so the same latex renders the same
35
+ * way in the editor and in the static renderer.
36
+ */
37
+ export declare const PIE_MACROS: {
38
+ parallelogram: string;
39
+ parallel: string;
40
+ napprox: string;
41
+ nsim: string;
42
+ ncong: string;
43
+ nparallel: string;
44
+ perpendicular: string;
45
+ divide: string;
46
+ degree: string;
47
+ square: string;
48
+ longdiv: string;
49
+ overarc: string;
50
+ abs: string;
51
+ answerBlock: {
52
+ args: number;
53
+ def: string;
54
+ captureSelection: boolean;
55
+ expand: boolean;
56
+ };
57
+ };
58
+ /**
59
+ * CSS that has to live *inside* a mathfield's shadow root.
60
+ *
61
+ * A live `<math-field>` renders in shadow DOM (`attachShadow({mode:'open'})`),
62
+ * so nothing in the host page's stylesheets reaches it. The stretchy-accent
63
+ * problem therefore needs fixing twice: once for static markup (see
64
+ * `placeholderStyles`) and once here for the editor.
65
+ *
66
+ * MathLive centres an accent with `margin-left: <half the content width>` as an
67
+ * inline style. For a stretchy accent that also shrinks its containing block
68
+ * (`.ML__center` is position:relative), so the arc ends up half-width and offset
69
+ * - visibly failing to span the text underneath.
70
+ *
71
+ * `:has(.ML__stretchy)` keeps the fix to stretchy accents; single-glyph accents
72
+ * (`\hat{x}`, `\vec{x}`) still need their centring offset.
73
+ */
74
+ /**
75
+ * Marker put on the host `<math-field>` while a `\placeholder{}` is selected,
76
+ * so the caret rules below apply to a placeholder and nothing else.
77
+ */
78
+ export declare const PLACEHOLDER_CARET_CLASS = "pie-caret-in-placeholder";
79
+ /**
80
+ * Keep {@link PLACEHOLDER_CARET_CLASS} in step with the selection.
81
+ *
82
+ * Gating on the class is what keeps the caret specific to placeholders: an
83
+ * ordinary selection (`x+1`) must not sprout one. MathLive fires
84
+ * `selection-change` for every caret move, including the one that lands on the
85
+ * placeholder straight after an insert.
86
+ *
87
+ * @param {HTMLElement} mathField
88
+ * @returns {function|undefined} teardown, to call on unmount
89
+ */
90
+ export declare const trackPlaceholderCaret: (mathField: any) => (() => any) | undefined;
91
+ /**
92
+ * Apply {@link SHADOW_CSS} inside a mathfield's shadow root.
93
+ *
94
+ * Uses `adoptedStyleSheets` when available (which is how MathLive loads its own
95
+ * stylesheets) and falls back to appending a <style> node.
96
+ *
97
+ * @param {HTMLElement} mathField
98
+ */
99
+ export declare const applyShadowStyles: (mathField: any) => void;
100
+ /**
101
+ * The loaded MathLive, starting the load if it has not begun.
102
+ *
103
+ * This package is ESM, so there is no synchronous `require`: a caller that runs
104
+ * synchronously (applyStaticMath, keypad labels) gets undefined on the first
105
+ * pass and is expected to retry once {@link loadMathLive} resolves.
106
+ *
107
+ * Returns undefined during SSR or until the module has loaded.
108
+ *
109
+ * @returns {object|undefined}
110
+ */
111
+ export declare const loadMathLiveSync: () => any;
112
+ /**
113
+ * Load MathLive with a dynamic import. Resolves to undefined during SSR.
114
+ *
115
+ * `webpackMode: "eager"` keeps MathLive inside a webpack host's bundle: a
116
+ * separate chunk 404s on deployments that do not serve it, leaving every
117
+ * mathfield and keypad label blank with no obvious cause.
118
+ *
119
+ * @returns {Promise<object|undefined>}
120
+ */
121
+ export declare const loadMathLive: () => Promise<any>;
122
+ /**
123
+ * Synchronous accessor for an already-loaded MathLive.
124
+ * @returns {object|undefined}
125
+ */
126
+ export declare const getMathLive: () => any;
127
+ /**
128
+ * The macro dictionary to hand to a mathfield: pie macros plus anything
129
+ * registered through `registerEmbed`.
130
+ *
131
+ * @returns {object}
132
+ */
133
+ export declare const getMacros: () => {
134
+ parallelogram: string;
135
+ parallel: string;
136
+ napprox: string;
137
+ nsim: string;
138
+ ncong: string;
139
+ nparallel: string;
140
+ perpendicular: string;
141
+ divide: string;
142
+ degree: string;
143
+ square: string;
144
+ longdiv: string;
145
+ overarc: string;
146
+ abs: string;
147
+ answerBlock: {
148
+ args: number;
149
+ def: string;
150
+ captureSelection: boolean;
151
+ expand: boolean;
152
+ };
153
+ };
154
+ /**
155
+ * Register an embed. API-compatible with @pie-lib/math-input's `registerEmbed`
156
+ * so existing callers do not change.
157
+ *
158
+ * MathQuill's factory returns `{ htmlString, text, latex }`. Only the
159
+ * declarative parts survive: `latex` round-trips through a macro and the
160
+ * styling hook becomes a `data-embed` attribute. Arbitrary DOM injection via
161
+ * `htmlString` has no MathLive equivalent and is ignored.
162
+ *
163
+ * @param {string} name
164
+ * @param {Function} factory
165
+ */
166
+ export declare function registerEmbed(name: any, factory: any): void;
167
+ /**
168
+ * Embeds registered so far. Exposed for tests/diagnostics.
169
+ * @returns {string[]}
170
+ */
171
+ export declare const registeredEmbeds: () => any[];
172
+ /** Reset the embed registry. Test helper. */
173
+ export declare const __resetEmbeds: () => void;
174
+ /** Inject a stub MathLive instance. Test helper. */
175
+ export declare const __setMathLiveForTest: (stub: any) => void;
176
+ /**
177
+ * Render static math into an element. API-compatible with
178
+ * @pie-lib/math-input's `applyStaticMath`.
179
+ *
180
+ * Callers written against MathQuill invoke this synchronously from lifecycle
181
+ * methods, where MathLive (a dynamic import) may not have loaded yet. Rather
182
+ * than silently rendering nothing, this kicks off the load and re-applies once
183
+ * the engine is ready, so the element fills in on the next tick.
184
+ *
185
+ * @param {HTMLElement} element
186
+ * @param {string} [latex] assigned to the element before rendering
187
+ * @param {object} [options] `{ macros }` overrides
188
+ * @returns {HTMLElement|undefined} the element, or undefined if deferred
189
+ */
190
+ export declare function applyStaticMath(element: any, latex: any, options?: {}): any;
191
+ /**
192
+ * Convert latex to markup using the pie macro set. Used for keypad labels and
193
+ * any read-only rendering that does not need a live mathfield.
194
+ *
195
+ * @param {string} latex
196
+ * @param {object} [options]
197
+ * @returns {string} HTML markup, or '' if MathLive is not loaded
198
+ */
199
+ export declare function latexToMarkup(latex: any, options?: {}): any;
200
+ /**
201
+ * Latex as MathML, for a text alternative to static markup, which has none of
202
+ * its own: a screen reader reads its glyphs in DOM order, so `\frac12` came out
203
+ * as "2 1".
204
+ *
205
+ * @param {string} latex stored latex
206
+ * @returns {string} a `<math>` element, or '' if MathLive is not loaded
207
+ */
208
+ export declare function latexToMathMl(latex: any): string;
209
+ /**
210
+ * A new `<math-field>`, configured with the pie macros.
211
+ *
212
+ * Built through the registry, not with `new MathfieldElement()`: every IIFE
213
+ * bundle carries its own MathLive, and only the first one to load registers
214
+ * `math-field`. Constructing another copy's unregistered class throws "Illegal
215
+ * constructor", while `createElement` returns the registered one.
216
+ *
217
+ * @param {object} ml the loaded MathLive module
218
+ * @returns {HTMLElement}
219
+ */
220
+ export declare function createMathField(ml: any): any;
221
+ export { NEWLINE_EMBED };
@@ -0,0 +1,159 @@
1
+ import { toAccessibleLatex as e, toMathLive as t, withVisibleEmptySlots as n } from "./latex-bridge.js";
2
+ import { PARALLEL_CSS as r, ROOT_INDEX_CSS as i } from "./mf/common-styles.js";
3
+ import { fixLongDivisionWhenReady as a } from "./longdiv.js";
4
+ import o from "debug";
5
+ //#region src/mathlive-instance.ts
6
+ var s = o("pie-lib:math-input-mathlive:instance"), c, l, u = (e) => {
7
+ if (!e || /^(?:[a-z+]+:)?\/\//i.test(e)) return e;
8
+ try {
9
+ return new URL(e, document.baseURI).href;
10
+ } catch (t) {
11
+ return s("could not resolve fontsDirectory \"%s\": %s", e, t && t.message), null;
12
+ }
13
+ }, d = "0.110.0", f = () => `https://unpkg.com/mathlive@${c && c.version && c.version.mathlive || d}/fonts`, p = (e) => {
14
+ l = e, c && (c.MathfieldElement.fontsDirectory = e === void 0 ? f() : u(e));
15
+ }, m = {
16
+ parallelogram: "\\htmlData{pie-macro=parallelogram}{\\unicode{\"25B1}}",
17
+ parallel: "\\htmlData{pie-macro=parallel}{\\unicode{\"2225}}",
18
+ napprox: "\\not\\approx",
19
+ nsim: "\\not\\sim",
20
+ ncong: "\\not\\cong",
21
+ nparallel: "\\not\\parallel",
22
+ perpendicular: "\\perp",
23
+ divide: "\\div",
24
+ degree: "^{\\circ}",
25
+ square: "\\unicode{\"25A1}",
26
+ longdiv: "\\enclose{longdiv}{#1}",
27
+ overarc: "\\overparen{#1}",
28
+ abs: "\\left|#1\\right|",
29
+ answerBlock: {
30
+ args: 1,
31
+ def: "\\htmlData{response-area=#1}{\\boxed{\\textsf{Response}}}",
32
+ captureSelection: !0,
33
+ expand: !1
34
+ }
35
+ }, h = /* @__PURE__ */ new Map(), g = {
36
+ newLine: "",
37
+ answerBlock: ""
38
+ }, _ = !1, v = () => {
39
+ l === void 0 && s("no fontsDirectory configured - falling back to the CDN (%s). Serve the fonts yourself and call configureFonts(\"/path/to/fonts\") to avoid the network request, or configureFonts(null) to opt out.", f()), c.MathfieldElement.fontsDirectory = l === void 0 ? f() : u(l), D();
40
+ }, y = "pie-caret-in-placeholder", b = "\\placeholder{}", x = [
41
+ `:host(.${y}) .ML__selected:not(:has(.ML__selected)){position:relative}`,
42
+ `:host(.${y}) .ML__selected:not(:has(.ML__selected))::after{`,
43
+ "content:\"\";position:absolute;left:50%;top:12%;height:76%;",
44
+ "border-right:2px solid var(--_caret-color, currentColor);",
45
+ "animation:ML__caret-blink 1.05s step-end forwards infinite}"
46
+ ].join(""), S = "url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 522' preserveAspectRatio='none'%3E%3Crect y='241' width='100' height='40'/%3E%3C/svg%3E\") 0 0/100% 100% no-repeat", C = `.ML__latex .overline>.ML__vlist-t>.ML__vlist-r>.ML__vlist>span:has(>.overline-line){top:-4.07em !important}.ML__latex .overline:has(>.ML__vlist-t>.ML__vlist-r>.ML__vlist>span>span[style*="height:0.9em"])>.ML__vlist-t>.ML__vlist-r>.ML__vlist>span:has(>.overline-line){top:-4.1em !important}.ML__latex .overline{position:relative;top:-0.06em}.ML__latex .overline>.ML__vlist-t>.ML__vlist-r>.ML__vlist>span:has(>span[style*="height:0.9em"]){top:-2.97em !important}.ML__latex .overline .overline-line{position:relative}.ML__latex .overline .overline-line:before{content:"";display:block;position:absolute;left:0;right:0;top:-0.241em;height:0.522em !important;border:0 !important;background:currentColor;-webkit-mask:${S};mask:${S}}.ML__latex .overline .overline-line:after{display:none !important}.ML__latex:has(.overline)>.ML__strut{height:1.37em !important}`, w = ".ML__latex .ML__center:has(.ML__stretchy){margin-left:0 !important}" + i + r + C + ".ML__latex .ML__mfrac:has(.ML__vlist>.ML__center:first-child span[style*=\"height:0.9em\"]) .ML__frac-line{position:relative;top:-0.025em}.ML__latex .ML__mfrac:not(:has(span[style*=\"height:0.9em\"])) .ML__frac-line{position:relative;top:0.04em}" + x, T = (e) => {
47
+ if (!e || typeof e.addEventListener != "function") return;
48
+ let t = () => {
49
+ let t = "";
50
+ try {
51
+ !e.selectionIsCollapsed && e.selection && (t = e.getValue(e.selection, "latex"));
52
+ } catch (e) {
53
+ s("could not read the selection: %s", e && e.message);
54
+ }
55
+ e.classList && e.classList.toggle(y, t === b);
56
+ };
57
+ return e.addEventListener("selection-change", t), t(), () => e.removeEventListener("selection-change", t);
58
+ }, E = (e) => {
59
+ let t = e && e.shadowRoot;
60
+ if (t) try {
61
+ if ("adoptedStyleSheets" in t && typeof CSSStyleSheet < "u") {
62
+ if (t.__pieAccentSheet) return;
63
+ let e = new CSSStyleSheet();
64
+ e.replaceSync(w), t.adoptedStyleSheets = [...t.adoptedStyleSheets, e], t.__pieAccentSheet = e;
65
+ return;
66
+ }
67
+ if (!t.querySelector("style[data-pie-accent]")) {
68
+ let e = document.createElement("style");
69
+ e.setAttribute("data-pie-accent", ""), e.textContent = w, t.appendChild(e);
70
+ }
71
+ } catch (e) {
72
+ s("could not apply shadow styles to the mathfield: %s", e && e.message);
73
+ }
74
+ }, D = () => {
75
+ if (typeof document < "u" && c && c.renderMathInElement) try {
76
+ c.renderMathInElement(document.createElement("span"));
77
+ } catch (e) {
78
+ s("could not trigger MathLive core stylesheet injection: %s", e && e.message);
79
+ }
80
+ }, O, k = () => {
81
+ if (typeof window < "u") return c || A(), c;
82
+ }, A = async () => {
83
+ if (typeof window < "u") {
84
+ if (c) return c;
85
+ O ??= import(
86
+ /* webpackMode: "eager" */
87
+ "mathlive"
88
+ );
89
+ try {
90
+ let e = await O;
91
+ c || (c = e, v());
92
+ } catch (e) {
93
+ O = void 0, !_ && globalThis.process?.env?.NODE_ENV !== "test" && (_ = !0, console.warn("[@pie-lib/math-input-mathlive] MathLive could not be loaded; math input will not render. If this is a bundling issue, ensure \"mathlive\" is resolvable from the host bundle. Cause: " + (e && e.message)));
94
+ return;
95
+ }
96
+ return c;
97
+ }
98
+ }, j = () => c, M = () => {
99
+ let e = { ...m };
100
+ return h.forEach(({ latex: t }, n) => {
101
+ Object.prototype.hasOwnProperty.call(m, n) || (e[n] = `\\htmlData{embed=${n}}{${t}}`);
102
+ }), e;
103
+ };
104
+ function N(e, t) {
105
+ if (!e || typeof t != "function") return;
106
+ let n = {};
107
+ try {
108
+ n = t() || {};
109
+ } catch (t) {
110
+ s("embed factory threw for \"%s\": %s", e, t.message);
111
+ }
112
+ let r = Object.prototype.hasOwnProperty.call(g, e) ? g[e] : n.mathliveLatex || "\\placeholder{}";
113
+ !Object.prototype.hasOwnProperty.call(g, e) && !n.mathliveLatex && s("embed \"%s\" is not natively supported by MathLive; rendering as a placeholder. Provide `mathliveLatex` in the factory result to control this.", e), h.set(e, {
114
+ factory: t,
115
+ latex: r
116
+ });
117
+ }
118
+ function P(e, r, i = {}) {
119
+ if (!e || typeof window > "u") return;
120
+ let o = r ?? e.textContent, c = j() || k();
121
+ if (!c) s("applyStaticMath called before MathLive loaded - deferring until it is ready"), A().then((t) => {
122
+ t && e.isConnected !== !1 && P(e, o, i);
123
+ });
124
+ else return e.innerHTML = c.convertLatexToMarkup(n(t(o)), { macros: {
125
+ ...M(),
126
+ ...i.macros || {}
127
+ } }), a(e), e;
128
+ }
129
+ function F(e, r = {}) {
130
+ let i = j() || k();
131
+ if (!i || !e) return "";
132
+ try {
133
+ return i.convertLatexToMarkup(n(t(e)), {
134
+ ...r,
135
+ macros: {
136
+ ...M(),
137
+ ...r.macros || {}
138
+ }
139
+ });
140
+ } catch (t) {
141
+ return s("convertLatexToMarkup failed for \"%s\": %s", e, t.message), "";
142
+ }
143
+ }
144
+ function I(n) {
145
+ let r = j();
146
+ if (!r?.convertLatexToMathMl || !n) return "";
147
+ try {
148
+ let i = r.convertLatexToMathMl(e(t(n)));
149
+ return i ? `<math xmlns="http://www.w3.org/1998/Math/MathML">${i}</math>` : "";
150
+ } catch (e) {
151
+ return s("convertLatexToMathMl failed for \"%s\": %s", n, e.message), "";
152
+ }
153
+ }
154
+ function L(e) {
155
+ let t = typeof customElements < "u" && customElements.get("math-field") ? document.createElement("math-field") : new e.MathfieldElement();
156
+ return t.macros = M(), t;
157
+ }
158
+ //#endregion
159
+ export { m as PIE_MACROS, y as PLACEHOLDER_CARET_CLASS, E as applyShadowStyles, P as applyStaticMath, p as configureFonts, L as createMathField, M as getMacros, j as getMathLive, F as latexToMarkup, I as latexToMathMl, A as loadMathLive, k as loadMathLiveSync, N as registerEmbed, T as trackPlaceholderCaret };