@dev_bachani/math-editor 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mathex.js ADDED
@@ -0,0 +1,745 @@
1
+ import { jsx as t, jsxs as E } from "react/jsx-runtime";
2
+ import { createContext as G, useContext as Q, useState as A, useRef as M, useCallback as I, useMemo as W, useEffect as B } from "react";
3
+ const F = (p, s, b) => {
4
+ }, D = G(void 0), H = () => Q(D), j = ({
5
+ children: p,
6
+ theme: s = "light"
7
+ }) => {
8
+ const [b, N] = A(null), x = M(null);
9
+ x.current = b;
10
+ const c = M(/* @__PURE__ */ new Map()), U = I((d, r) => {
11
+ F("MathProvider", "registerInput", { totalRegistered: c.current.size + 1 }), c.current.set(d, r);
12
+ }, []), P = I((d) => {
13
+ F("MathProvider", "unregisterInput", { totalRemaining: c.current.size - 1 }), c.current.delete(d), N((r) => r === d ? null : r);
14
+ }, []), h = I((d) => {
15
+ N(d);
16
+ }, []), f = I(
17
+ (d) => {
18
+ const r = x.current;
19
+ if (F("MathProvider", "insertAtCursor called", {
20
+ hasCallback: r ? c.current.has(r) : !1,
21
+ registeredInputs: Array.from(c.current.keys())
22
+ }), !r) {
23
+ console.warn("No active input to insert LaTeX into");
24
+ return;
25
+ }
26
+ const R = c.current.get(r);
27
+ R && R(d);
28
+ },
29
+ []
30
+ // Empty deps - uses refs to access current values
31
+ ), O = {
32
+ activeInputId: b,
33
+ setActiveInput: h,
34
+ insertAtCursor: f,
35
+ registerInput: U,
36
+ unregisterInput: P,
37
+ theme: s
38
+ }, m = typeof s == "string" ? s : "custom";
39
+ return F("MathProvider", "rendering with contextValue", { registeredInputs: Array.from(c.current.keys()) }), /* @__PURE__ */ t(D.Provider, { value: O, children: /* @__PURE__ */ t("div", { "data-theme": m, className: "mathex-provider", children: p }) });
40
+ };
41
+ j.displayName = "MathProvider";
42
+ const L = (p, s, b) => {
43
+ }, V = () => typeof window < "u" && window.MathQuill ? window.MathQuill.getInterface(2) : null, Y = ({
44
+ value: p,
45
+ defaultValue: s = "",
46
+ onChange: b,
47
+ id: N,
48
+ placeholder: x = "Enter equation...",
49
+ disabled: c = !1,
50
+ className: U = "",
51
+ style: P,
52
+ autoFocus: h = !1,
53
+ readOnly: f = !1,
54
+ onError: O
55
+ }) => {
56
+ const m = p !== void 0, [d, r] = A(s), R = m ? p : d, [_, a] = A(!1), l = M(null), y = M(null), S = W(() => N || `math-input-${Math.random().toString(36).substr(2, 9)}`, [N]), u = H(), k = M(u), T = M(S);
57
+ B(() => {
58
+ k.current = u, T.current = S;
59
+ }, [u, S]), L("MathInput", "render", { activeInputId: u?.activeInputId }), B(() => {
60
+ if (!y.current || l.current) return;
61
+ const g = V();
62
+ if (!g) {
63
+ console.error("MathQuill is not loaded. Make sure to include MathQuill script in your HTML.");
64
+ return;
65
+ }
66
+ try {
67
+ const C = {
68
+ spaceBehavesLikeTab: !0,
69
+ leftRightIntoCmdGoes: "up",
70
+ restrictMismatchedBrackets: !0,
71
+ autoCommands: "pi theta sqrt sum prod int",
72
+ autoOperatorNames: "sin cos tan sec csc cot sinh cosh tanh log ln",
73
+ handlers: {
74
+ edit: (v) => {
75
+ const w = v.latex();
76
+ m || r(w), b?.(w);
77
+ },
78
+ enter: () => {
79
+ l.current?.blur();
80
+ }
81
+ }
82
+ }, e = g.MathField(y.current, C);
83
+ l.current = e, e.latex(R);
84
+ const i = y.current, n = () => {
85
+ const v = T.current, w = k.current;
86
+ L("MathInput", "focusin event fired", { inputId: v, hasContext: !!w }), a(!0), w ? (L("MathInput", "Setting active input from focusin", { inputId: v }), w.setActiveInput(v)) : L("MathInput", "WARNING: No mathContext available in focusin handler");
87
+ }, o = () => {
88
+ L("MathInput", "focusout event fired", { inputId: T.current }), a(!1);
89
+ };
90
+ return i.addEventListener("focusin", n), i.addEventListener("focusout", o), h && e.focus(), () => {
91
+ L("MathInput", "cleanup - removing listeners", { inputId: S }), i.removeEventListener("focusin", n), i.removeEventListener("focusout", o), e.revert(), l.current = null;
92
+ };
93
+ } catch (C) {
94
+ O && C instanceof Error && O(C), console.error("Failed to initialize MathQuill:", C);
95
+ }
96
+ }, []), B(() => {
97
+ l.current && m && l.current.latex() !== p && l.current.latex(p);
98
+ }, [p, m]);
99
+ const K = I(() => {
100
+ l.current && !c && !f && (l.current.focus(), u && u.setActiveInput(S));
101
+ }, [u, S, c, f]), z = I(
102
+ (g) => {
103
+ if (L("MathInput", "handleKeyboardInsertion called", {
104
+ hasMathField: !!l.current,
105
+ inputId: T.current
106
+ }), !!l.current)
107
+ switch (g) {
108
+ case "BACKSPACE":
109
+ l.current.keystroke("Backspace");
110
+ return;
111
+ case "ARROW_LEFT":
112
+ l.current.keystroke("Left");
113
+ return;
114
+ case "ARROW_RIGHT":
115
+ l.current.keystroke("Right");
116
+ return;
117
+ case "ENTER":
118
+ l.current.blur();
119
+ return;
120
+ default:
121
+ l.current.write(g), l.current.focus();
122
+ }
123
+ },
124
+ []
125
+ );
126
+ return B(() => {
127
+ const g = k.current, C = T.current;
128
+ if (g)
129
+ return g.registerInput(C, z), () => {
130
+ g.unregisterInput(C);
131
+ };
132
+ }, []), B(() => {
133
+ l.current && y.current && (c || f ? (y.current.setAttribute("contenteditable", "false"), y.current.style.pointerEvents = "none", y.current.style.opacity = "0.6") : (y.current.removeAttribute("contenteditable"), y.current.style.pointerEvents = "", y.current.style.opacity = ""));
134
+ }, [c, f]), /* @__PURE__ */ t(
135
+ "div",
136
+ {
137
+ className: `mathex-input mathex-input--mathquill ${_ ? "mathex-input--focused" : ""} ${c ? "mathex-input--disabled" : ""} ${U}`,
138
+ style: P,
139
+ onClick: K,
140
+ "data-id": N,
141
+ children: /* @__PURE__ */ t(
142
+ "div",
143
+ {
144
+ ref: y,
145
+ className: "mathex-mathquill-container",
146
+ "data-placeholder": R ? void 0 : x
147
+ }
148
+ )
149
+ }
150
+ );
151
+ };
152
+ Y.displayName = "MathInput";
153
+ const Z = [
154
+ [
155
+ { display: "x", latex: "x", type: "variable", style: "white" },
156
+ { display: "y", latex: "y", type: "variable", style: "white" },
157
+ { display: "a²", latex: "^{2}", type: "operator", style: "white" },
158
+ { display: "aᵇ", latex: "^{}", type: "operator", style: "white" }
159
+ ],
160
+ [
161
+ { display: "(", latex: "(", type: "symbol", style: "white" },
162
+ { display: ")", latex: ")", type: "symbol", style: "white" },
163
+ { display: "<", latex: "<", type: "operator", style: "white" },
164
+ { display: ">", latex: ">", type: "operator", style: "white" }
165
+ ],
166
+ [
167
+ { display: "|a|", latex: "||", type: "operator", style: "white" },
168
+ { display: ",", latex: ",", type: "symbol", style: "white" },
169
+ { display: "≤", latex: "\\leq ", type: "operator", style: "white" },
170
+ { display: "≥", latex: "\\geq ", type: "operator", style: "white" }
171
+ ],
172
+ [
173
+ { display: "A B C", latex: "ABC_MODE", type: "action", style: "gray-light" },
174
+ { display: "🔊", latex: "SPEAK", type: "action", style: "gray-light" },
175
+ { display: "√", latex: "\\sqrt{}", type: "function", style: "white" },
176
+ { display: "π", latex: "\\pi ", type: "symbol", style: "white" }
177
+ ]
178
+ ], X = [
179
+ [
180
+ { display: "7", latex: "7", type: "number", style: "gray-light" },
181
+ { display: "8", latex: "8", type: "number", style: "gray-light" },
182
+ { display: "9", latex: "9", type: "number", style: "gray-light" },
183
+ { display: "÷", latex: "\\div ", type: "operator", style: "white" }
184
+ ],
185
+ [
186
+ { display: "4", latex: "4", type: "number", style: "gray-light" },
187
+ { display: "5", latex: "5", type: "number", style: "gray-light" },
188
+ { display: "6", latex: "6", type: "number", style: "gray-light" },
189
+ { display: "×", latex: "\\times ", type: "operator", style: "white" }
190
+ ],
191
+ [
192
+ { display: "1", latex: "1", type: "number", style: "gray-light" },
193
+ { display: "2", latex: "2", type: "number", style: "gray-light" },
194
+ { display: "3", latex: "3", type: "number", style: "gray-light" },
195
+ { display: "−", latex: "-", type: "operator", style: "white" }
196
+ ],
197
+ [
198
+ { display: "0", latex: "0", type: "number", style: "gray-light" },
199
+ { display: ".", latex: ".", type: "number", style: "gray-light" },
200
+ { display: "=", latex: "=", type: "operator", style: "gray-light" },
201
+ { display: "+", latex: "+", type: "operator", style: "white" }
202
+ ]
203
+ ], J = [
204
+ [
205
+ { display: "functions", latex: "FUNCTIONS", type: "action", style: "gray-light", size: "extra-wide" }
206
+ ],
207
+ [
208
+ { display: "←", latex: "ARROW_LEFT", type: "action", style: "gray-light" },
209
+ { display: "→", latex: "ARROW_RIGHT", type: "action", style: "gray-light" }
210
+ ],
211
+ [
212
+ { display: "⌫", latex: "BACKSPACE", type: "action", style: "gray-light", size: "extra-wide" }
213
+ ],
214
+ [
215
+ { display: "↵", latex: "ENTER", type: "action", style: "blue", size: "extra-wide" }
216
+ ]
217
+ ], $ = [
218
+ // Row 1
219
+ [
220
+ { display: "q", latex: "q", type: "letter", style: "white" },
221
+ { display: "w", latex: "w", type: "letter", style: "white" },
222
+ { display: "e", latex: "e", type: "letter", style: "white" },
223
+ { display: "r", latex: "r", type: "letter", style: "white" },
224
+ { display: "t", latex: "t", type: "letter", style: "white" },
225
+ { display: "y", latex: "y", type: "letter", style: "white" },
226
+ { display: "u", latex: "u", type: "letter", style: "white" },
227
+ { display: "i", latex: "i", type: "letter", style: "white" },
228
+ { display: "o", latex: "o", type: "letter", style: "white" },
229
+ { display: "p", latex: "p", type: "letter", style: "white" }
230
+ ],
231
+ // Row 2
232
+ [
233
+ { display: "a", latex: "a", type: "letter", style: "white" },
234
+ { display: "s", latex: "s", type: "letter", style: "white" },
235
+ { display: "d", latex: "d", type: "letter", style: "white" },
236
+ { display: "f", latex: "f", type: "letter", style: "white" },
237
+ { display: "g", latex: "g", type: "letter", style: "white" },
238
+ { display: "h", latex: "h", type: "letter", style: "white" },
239
+ { display: "j", latex: "j", type: "letter", style: "white" },
240
+ { display: "k", latex: "k", type: "letter", style: "white" },
241
+ { display: "l", latex: "l", type: "letter", style: "white" },
242
+ { display: "θ", latex: "\\theta ", type: "symbol", style: "white" }
243
+ ],
244
+ // Row 3
245
+ [
246
+ { display: "⬆", latex: "SHIFT", type: "action", style: "gray-light", size: "wide" },
247
+ { display: "z", latex: "z", type: "letter", style: "white" },
248
+ { display: "x", latex: "x", type: "letter", style: "white" },
249
+ { display: "c", latex: "c", type: "letter", style: "white" },
250
+ { display: "v", latex: "v", type: "letter", style: "white" },
251
+ { display: "b", latex: "b", type: "letter", style: "white" },
252
+ { display: "n", latex: "n", type: "letter", style: "white" },
253
+ { display: "m", latex: "m", type: "letter", style: "white" },
254
+ { display: "⌫", latex: "BACKSPACE", type: "action", style: "gray-light", size: "wide" }
255
+ ],
256
+ // Row 4
257
+ [
258
+ { display: "1 2 3", latex: "123_MODE", type: "action", style: "gray-light", size: "wide" },
259
+ { display: "aᵦ", latex: "SUBSCRIPT", type: "action", style: "white" },
260
+ {
261
+ display: "! %",
262
+ latex: "DUAL_EXCLAIM_PERCENT",
263
+ type: "symbol",
264
+ style: "white",
265
+ dualChar: {
266
+ primary: "!",
267
+ primaryLatex: "!",
268
+ secondary: "%",
269
+ secondaryLatex: "%"
270
+ }
271
+ },
272
+ {
273
+ display: "[ ]",
274
+ latex: "DUAL_BRACKETS",
275
+ type: "symbol",
276
+ style: "white",
277
+ dualChar: {
278
+ primary: "[",
279
+ primaryLatex: "[",
280
+ secondary: "]",
281
+ secondaryLatex: "]"
282
+ }
283
+ },
284
+ {
285
+ display: "{ }",
286
+ latex: "DUAL_BRACES",
287
+ type: "symbol",
288
+ style: "white",
289
+ dualChar: {
290
+ primary: "{",
291
+ primaryLatex: "\\{",
292
+ secondary: "}",
293
+ secondaryLatex: "\\}"
294
+ }
295
+ },
296
+ {
297
+ display: "~ :",
298
+ latex: "DUAL_TILDE_COLON",
299
+ type: "symbol",
300
+ style: "white",
301
+ dualChar: {
302
+ primary: "~",
303
+ primaryLatex: "\\sim ",
304
+ secondary: ":",
305
+ secondaryLatex: ":"
306
+ }
307
+ },
308
+ {
309
+ display: ", '",
310
+ latex: "DUAL_COMMA_QUOTE",
311
+ type: "symbol",
312
+ style: "white",
313
+ dualChar: {
314
+ primary: ",",
315
+ primaryLatex: ",",
316
+ secondary: "'",
317
+ secondaryLatex: "'"
318
+ }
319
+ },
320
+ { display: "↵", latex: "ENTER", type: "action", style: "blue", size: "wide" }
321
+ ]
322
+ ], ee = [
323
+ // 1. TRIG FUNCTIONS
324
+ {
325
+ id: "trig",
326
+ name: "TRIG FUNCTIONS",
327
+ functions: [
328
+ { display: "sin", latex: "\\sin(", description: "Sine function" },
329
+ { display: "cos", latex: "\\cos(", description: "Cosine function" },
330
+ { display: "tan", latex: "\\tan(", description: "Tangent function" },
331
+ { display: "csc", latex: "\\csc(", description: "Cosecant function" },
332
+ { display: "sec", latex: "\\sec(", description: "Secant function" },
333
+ { display: "cot", latex: "\\cot(", description: "Cotangent function" }
334
+ ]
335
+ },
336
+ // 2. INVERSE TRIG FUNCTIONS
337
+ {
338
+ id: "inverse-trig",
339
+ name: "INVERSE TRIG FUNCTIONS",
340
+ functions: [
341
+ { display: "sin⁻¹", latex: "\\sin^{-1}(", description: "Inverse sine" },
342
+ { display: "cos⁻¹", latex: "\\cos^{-1}(", description: "Inverse cosine" },
343
+ { display: "tan⁻¹", latex: "\\tan^{-1}(", description: "Inverse tangent" },
344
+ { display: "csc⁻¹", latex: "\\csc^{-1}(", description: "Inverse cosecant" },
345
+ { display: "sec⁻¹", latex: "\\sec^{-1}(", description: "Inverse secant" },
346
+ { display: "cot⁻¹", latex: "\\cot^{-1}(", description: "Inverse cotangent" }
347
+ ]
348
+ },
349
+ // 3. STATISTICS
350
+ {
351
+ id: "statistics",
352
+ name: "STATISTICS",
353
+ functions: [
354
+ { display: "mean", latex: "\\text{mean}(", description: "Mean/average" },
355
+ { display: "median", latex: "\\text{median}(", description: "Median value" },
356
+ { display: "min", latex: "\\min(", description: "Minimum value" },
357
+ { display: "max", latex: "\\max(", description: "Maximum value" },
358
+ { display: "quartile", latex: "\\text{quartile}(", description: "Quartile" },
359
+ { display: "quantile", latex: "\\text{quantile}(", description: "Quantile" },
360
+ { display: "stdev", latex: "\\text{stdev}(", description: "Standard deviation" },
361
+ { display: "stdevp", latex: "\\text{stdevp}(", description: "Population std dev" },
362
+ { display: "var", latex: "\\text{var}(", description: "Variance" },
363
+ { display: "varp", latex: "\\text{varp}(", description: "Population variance" },
364
+ { display: "cov", latex: "\\text{cov}(", description: "Covariance" },
365
+ { display: "covp", latex: "\\text{covp}(", description: "Population covariance" },
366
+ { display: "mad", latex: "\\text{mad}(", description: "Mean absolute deviation" },
367
+ { display: "corr", latex: "\\text{corr}(", description: "Correlation" },
368
+ { display: "spearman", latex: "\\text{spearman}(", description: "Spearman correlation" },
369
+ { display: "stats", latex: "\\text{stats}(", description: "Statistics summary" },
370
+ { display: "count", latex: "\\text{count}(", description: "Count" },
371
+ { display: "total", latex: "\\text{total}(", description: "Total/sum" }
372
+ ]
373
+ },
374
+ // 4. LIST OPERATIONS
375
+ {
376
+ id: "list-operations",
377
+ name: "LIST OPERATIONS",
378
+ functions: [
379
+ { display: "repeat", latex: "\\text{repeat}(", description: "Repeat elements" },
380
+ { display: "join", latex: "\\text{join}(", description: "Join lists" },
381
+ { display: "sort", latex: "\\text{sort}(", description: "Sort list" },
382
+ { display: "shuffle", latex: "\\text{shuffle}(", description: "Shuffle list" },
383
+ { display: "unique", latex: "\\text{unique}(", description: "Unique elements" },
384
+ { display: "for", latex: "\\text{for}", description: "For loop" }
385
+ ]
386
+ },
387
+ // 5. VISUALIZATIONS
388
+ {
389
+ id: "visualizations",
390
+ name: "VISUALIZATIONS",
391
+ functions: [
392
+ { display: "histogram", latex: "\\text{histogram}(", description: "Histogram" },
393
+ { display: "dotplot", latex: "\\text{dotplot}(", description: "Dot plot" },
394
+ { display: "boxplot", latex: "\\text{boxplot}(", description: "Box plot" }
395
+ ]
396
+ },
397
+ // 6. PROBABILITY DISTRIBUTIONS
398
+ {
399
+ id: "distributions",
400
+ name: "PROBABILITY DISTRIBUTIONS",
401
+ functions: [
402
+ { display: "normaldist", latex: "\\text{normaldist}(", description: "Normal distribution" },
403
+ { display: "tdist", latex: "\\text{tdist}(", description: "T distribution" },
404
+ { display: "chisqdist", latex: "\\text{chisqdist}(", description: "Chi-squared distribution" },
405
+ { display: "uniformdist", latex: "\\text{uniformdist}(", description: "Uniform distribution" },
406
+ { display: "binomialdist", latex: "\\text{binomialdist}(", description: "Binomial distribution" },
407
+ { display: "poissondist", latex: "\\text{poissondist}(", description: "Poisson distribution" },
408
+ { display: "geodist", latex: "\\text{geodist}(", description: "Geometric distribution" },
409
+ { display: "pdf", latex: "\\text{pdf}(", description: "Probability density function" },
410
+ { display: "cdf", latex: "\\text{cdf}(", description: "Cumulative distribution function" },
411
+ { display: "inversecdf", latex: "\\text{inversecdf}(", description: "Inverse CDF" },
412
+ { display: "random", latex: "\\text{random}(", description: "Random number" }
413
+ ]
414
+ },
415
+ // 7. INFERENCE
416
+ {
417
+ id: "inference",
418
+ name: "INFERENCE",
419
+ functions: [
420
+ { display: "ztest", latex: "\\text{ztest}(", description: "Z-test" },
421
+ { display: "ttest", latex: "\\text{ttest}(", description: "T-test" },
422
+ { display: "zproptest", latex: "\\text{zproptest}(", description: "Z proportion test" },
423
+ { display: "chisqtest", latex: "\\text{chisqtest}(", description: "Chi-squared test" },
424
+ { display: "chisqgof", latex: "\\text{chisqgof}(", description: "Chi-squared goodness of fit" },
425
+ { display: "null", latex: "\\text{null}(", description: "Null hypothesis" },
426
+ { display: "p", latex: "\\text{p}(", description: "P-value" },
427
+ { display: "pleft", latex: "\\text{pleft}(", description: "Left p-value" },
428
+ { display: "pright", latex: "\\text{pright}(", description: "Right p-value" },
429
+ { display: "score", latex: "\\text{score}(", description: "Test score" },
430
+ { display: "dof", latex: "\\text{dof}(", description: "Degrees of freedom" },
431
+ { display: "stderr", latex: "\\text{stderr}(", description: "Standard error" },
432
+ { display: "conf", latex: "\\text{conf}(", description: "Confidence interval" },
433
+ { display: "lower", latex: "\\text{lower}(", description: "Lower bound" },
434
+ { display: "upper", latex: "\\text{upper}(", description: "Upper bound" },
435
+ { display: "estimate", latex: "\\text{estimate}(", description: "Point estimate" }
436
+ ]
437
+ },
438
+ // 8. CALCULUS
439
+ {
440
+ id: "calculus",
441
+ name: "CALCULUS",
442
+ functions: [
443
+ { display: "exp", latex: "e^{", description: "Exponential" },
444
+ { display: "ln", latex: "\\ln(", description: "Natural logarithm" },
445
+ { display: "log", latex: "\\log(", description: "Logarithm base 10" },
446
+ { display: "logₐ", latex: "\\log_{}(", description: "Logarithm base a" },
447
+ { display: "d/dx", latex: "\\frac{d}{dx}", description: "Derivative" },
448
+ { display: "f'", latex: "'", description: "Prime notation" },
449
+ { display: "∫", latex: "\\int_{}^{}", description: "Integral" },
450
+ { display: "Σ", latex: "\\sum_{}^{}", description: "Summation" },
451
+ { display: "Π", latex: "\\prod_{}^{}", description: "Product" }
452
+ ]
453
+ },
454
+ // 9. HYPERBOLIC TRIG FUNCTIONS
455
+ {
456
+ id: "hyperbolic-trig",
457
+ name: "HYPERBOLIC TRIG FUNCTIONS",
458
+ functions: [
459
+ { display: "sinh", latex: "\\sinh(", description: "Hyperbolic sine" },
460
+ { display: "cosh", latex: "\\cosh(", description: "Hyperbolic cosine" },
461
+ { display: "tanh", latex: "\\tanh(", description: "Hyperbolic tangent" },
462
+ { display: "csch", latex: "\\text{csch}(", description: "Hyperbolic cosecant" },
463
+ { display: "sech", latex: "\\text{sech}(", description: "Hyperbolic secant" },
464
+ { display: "coth", latex: "\\coth(", description: "Hyperbolic cotangent" }
465
+ ]
466
+ },
467
+ // 10. GEOMETRY
468
+ {
469
+ id: "geometry",
470
+ name: "GEOMETRY",
471
+ functions: [
472
+ { display: "polygon", latex: "\\text{polygon}(", description: "Polygon" },
473
+ { display: "distance", latex: "\\text{distance}(", description: "Distance" },
474
+ { display: "midpoint", latex: "\\text{midpoint}(", description: "Midpoint" }
475
+ ]
476
+ },
477
+ // 11. CUSTOM COLORS
478
+ {
479
+ id: "colors",
480
+ name: "CUSTOM COLORS",
481
+ functions: [
482
+ { display: "rgb", latex: "\\text{rgb}(", description: "RGB color" },
483
+ { display: "hsv", latex: "\\text{hsv}(", description: "HSV color" },
484
+ { display: "okhsv", latex: "\\text{okhsv}(", description: "OKHSV color" },
485
+ { display: "oklab", latex: "\\text{oklab}(", description: "OKLAB color" },
486
+ { display: "oklch", latex: "\\text{oklch}(", description: "OKLCH color" }
487
+ ]
488
+ },
489
+ // 12. SOUND
490
+ {
491
+ id: "sound",
492
+ name: "SOUND",
493
+ functions: [
494
+ { display: "tone", latex: "\\text{tone}(", description: "Generate tone" }
495
+ ]
496
+ },
497
+ // 13. NUMBER THEORY
498
+ {
499
+ id: "number-theory",
500
+ name: "NUMBER THEORY",
501
+ functions: [
502
+ { display: "lcm", latex: "\\text{lcm}(", description: "Least common multiple" },
503
+ { display: "gcd", latex: "\\gcd(", description: "Greatest common divisor" },
504
+ { display: "mod", latex: "\\mod ", description: "Modulo" },
505
+ { display: "ceil", latex: "\\lceil ", description: "Ceiling" },
506
+ { display: "floor", latex: "\\lfloor ", description: "Floor" },
507
+ { display: "round", latex: "\\text{round}(", description: "Round" },
508
+ { display: "sign", latex: "\\text{sign}(", description: "Sign function" },
509
+ { display: "ⁿ√", latex: "\\sqrt[]{}", description: "Nth root" },
510
+ { display: "nPr", latex: "P(", description: "Permutation" },
511
+ { display: "nCr", latex: "\\binom{}{}", description: "Combination" }
512
+ ]
513
+ }
514
+ ];
515
+ function te() {
516
+ return $.map(
517
+ (p) => p.map((s) => s.type === "letter" ? {
518
+ ...s,
519
+ display: s.display.toUpperCase(),
520
+ latex: s.latex.toUpperCase()
521
+ } : s.latex === "SUBSCRIPT" ? {
522
+ ...s,
523
+ display: "aᵇ",
524
+ latex: "SUPERSCRIPT"
525
+ } : s)
526
+ );
527
+ }
528
+ const q = (p, s, b) => {
529
+ }, ie = ({
530
+ defaultVisible: p = !1,
531
+ onVisibilityChange: s,
532
+ className: b = "",
533
+ style: N
534
+ }) => {
535
+ const [x, c] = A(p), [U, P] = A("default"), [h, f] = A(!1), [O, m] = A(!1), [d, r] = A("normal"), R = M(null), _ = M(null), a = H(), l = I(() => {
536
+ c((e) => {
537
+ const i = !e;
538
+ return s?.(i), i || m(!1), i;
539
+ });
540
+ }, [s]), y = I(
541
+ (e) => {
542
+ if (q("MathKeyboard", "handleButtonClick", {
543
+ latex: e.latex,
544
+ type: e.type,
545
+ activeInputId: a?.activeInputId
546
+ }), e.dualChar) {
547
+ const { primaryLatex: i, secondaryLatex: n } = e.dualChar, o = h ? n : i;
548
+ if (o === "SUBSCRIPT") {
549
+ r("subscript");
550
+ return;
551
+ }
552
+ if (o === "SUPERSCRIPT") {
553
+ r("superscript");
554
+ return;
555
+ }
556
+ if (d !== "normal") {
557
+ const v = d === "subscript" ? `_{${o}}` : `^{${o}}`;
558
+ a?.insertAtCursor(v), r("normal");
559
+ return;
560
+ }
561
+ a && a.insertAtCursor(o);
562
+ return;
563
+ }
564
+ switch (e.latex) {
565
+ case "ABC_MODE":
566
+ P("abc"), m(!1);
567
+ return;
568
+ case "123_MODE":
569
+ P("default"), f(!1), r("normal");
570
+ return;
571
+ case "SHIFT":
572
+ f((i) => !i);
573
+ return;
574
+ case "SUBSCRIPT":
575
+ r("subscript");
576
+ return;
577
+ case "SUPERSCRIPT":
578
+ r("superscript");
579
+ return;
580
+ case "FUNCTIONS":
581
+ m((i) => !i);
582
+ return;
583
+ case "SPEAK":
584
+ return;
585
+ case "ARROW_LEFT":
586
+ a && a.insertAtCursor("ARROW_LEFT");
587
+ return;
588
+ case "ARROW_RIGHT":
589
+ a && a.insertAtCursor("ARROW_RIGHT");
590
+ return;
591
+ case "BACKSPACE":
592
+ a && a.insertAtCursor("BACKSPACE");
593
+ return;
594
+ case "ENTER":
595
+ a && a.insertAtCursor("ENTER");
596
+ return;
597
+ }
598
+ if (d !== "normal" && (e.type === "letter" || e.type === "variable")) {
599
+ const i = d === "subscript" ? `_{${e.latex}}` : `^{${e.latex}}`;
600
+ a?.insertAtCursor(i), r("normal"), h && f(!1);
601
+ return;
602
+ }
603
+ a ? (q("MathKeyboard", "inserting standard latex via context", { latex: e.latex }), a.insertAtCursor(e.latex)) : q("MathKeyboard", "WARNING: No mathContext for standard insertion", { latex: e.latex }), e.type === "letter" && h && f(!1);
604
+ },
605
+ [a, h, d]
606
+ ), S = I(
607
+ (e) => {
608
+ q("MathKeyboard", "handleFunctionClick", {
609
+ activeInputId: a?.activeInputId
610
+ }), a && a.insertAtCursor(e), m(!1);
611
+ },
612
+ [a]
613
+ );
614
+ B(() => {
615
+ const e = (i) => {
616
+ if (!x) return;
617
+ const n = i.target;
618
+ R.current?.contains(n) || n.closest(".mathex-input") || (c(!1), m(!1), s?.(!1));
619
+ };
620
+ return document.addEventListener("mousedown", e), () => {
621
+ document.removeEventListener("mousedown", e);
622
+ };
623
+ }, [x, s]);
624
+ const u = I((e) => {
625
+ e.preventDefault();
626
+ }, []), k = (e, i) => {
627
+ const n = [
628
+ "dcg-keypad-btn-container",
629
+ e.size === "wide" && "dcg-wide",
630
+ e.size === "extra-wide" && "dcg-extra-wide"
631
+ ].filter(Boolean).join(" "), o = [
632
+ "dcg-keypad-btn",
633
+ e.style === "blue" && "dcg-btn-blue",
634
+ e.style === "gray-light" && "dcg-btn-light-gray",
635
+ e.style === "white" && "dcg-btn-white",
636
+ e.latex === "SHIFT" && h && "dcg-active",
637
+ e.latex === "SUBSCRIPT" && d === "subscript" && "dcg-active",
638
+ e.latex === "SUPERSCRIPT" && d === "superscript" && "dcg-active"
639
+ ].filter(Boolean).join(" ");
640
+ if (e.dualChar) {
641
+ const { primary: v, secondary: w } = e.dualChar;
642
+ return /* @__PURE__ */ t("div", { className: n, children: /* @__PURE__ */ t(
643
+ "button",
644
+ {
645
+ className: o,
646
+ onClick: () => y(e),
647
+ onMouseDown: u,
648
+ onTouchStart: u,
649
+ type: "button",
650
+ children: /* @__PURE__ */ E("span", { className: "dcg-keypad-btn-content dcg-dual-char", children: [
651
+ /* @__PURE__ */ t("span", { className: `dcg-dual-primary ${h ? "dcg-blurred" : "dcg-clear"}`, children: v }),
652
+ /* @__PURE__ */ t("span", { className: `dcg-dual-secondary ${h ? "dcg-clear" : "dcg-blurred"}`, children: w })
653
+ ] })
654
+ }
655
+ ) }, i);
656
+ }
657
+ return /* @__PURE__ */ t("div", { className: n, children: /* @__PURE__ */ t(
658
+ "button",
659
+ {
660
+ className: o,
661
+ onClick: () => y(e),
662
+ onMouseDown: u,
663
+ onTouchStart: u,
664
+ type: "button",
665
+ children: /* @__PURE__ */ t("span", { className: "dcg-keypad-btn-content", children: e.display })
666
+ }
667
+ ) }, i);
668
+ }, T = () => /* @__PURE__ */ t("div", { className: "dcg-basic-keypad dcg-default-mode", children: /* @__PURE__ */ E("div", { className: "dcg-audio-keypad-container", children: [
669
+ /* @__PURE__ */ t("div", { className: "dcg-audio-keypad-column dcg-left-section", children: Z.map((e, i) => /* @__PURE__ */ t("div", { className: "dcg-keypad-row", children: e.map((n, o) => k(n, o)) }, i)) }),
670
+ /* @__PURE__ */ t("div", { className: "dcg-audio-keypad-column dcg-middle-section", children: X.map((e, i) => /* @__PURE__ */ t("div", { className: "dcg-keypad-row", children: e.map((n, o) => k(n, o)) }, i)) }),
671
+ /* @__PURE__ */ t("div", { className: "dcg-audio-keypad-column dcg-right-section", children: J.map((e, i) => /* @__PURE__ */ t("div", { className: "dcg-keypad-row", children: e.map((n, o) => k(n, o)) }, i)) })
672
+ ] }) }), K = () => {
673
+ const e = h ? te() : $;
674
+ return /* @__PURE__ */ t("div", { className: "dcg-basic-keypad dcg-abc-mode", children: e.map((i, n) => /* @__PURE__ */ t("div", { className: `dcg-keypad-row dcg-abc-row-${n}`, children: i.map((o, v) => k(o, v)) }, n)) });
675
+ }, z = () => /* @__PURE__ */ t(
676
+ "div",
677
+ {
678
+ ref: _,
679
+ className: `dcg-functions-popover ${O ? "dcg-visible" : ""}`,
680
+ children: /* @__PURE__ */ t("div", { className: "dcg-popover-interior", children: ee.map((e) => /* @__PURE__ */ E("div", { className: "dcg-keypad-keys-section", children: [
681
+ /* @__PURE__ */ t("div", { className: "dcg-section-heading", children: e.name }),
682
+ /* @__PURE__ */ t("div", { className: "dcg-keypad-keys-buttons", children: e.functions.map((i, n) => /* @__PURE__ */ t("div", { className: "dcg-keypad-btn-container dcg-function-btn", children: /* @__PURE__ */ t(
683
+ "button",
684
+ {
685
+ className: "dcg-keypad-btn dcg-btn-white",
686
+ onClick: () => S(i.latex),
687
+ onMouseDown: u,
688
+ onTouchStart: u,
689
+ title: i.description,
690
+ type: "button",
691
+ children: /* @__PURE__ */ t("span", { className: "dcg-keypad-btn-content", children: i.display })
692
+ }
693
+ ) }, n)) })
694
+ ] }, e.id)) })
695
+ }
696
+ ), g = () => /* @__PURE__ */ t("div", { className: "dcg-show-keypad-container", children: /* @__PURE__ */ E(
697
+ "button",
698
+ {
699
+ className: "dcg-show-keypad dcg-btn-light-gray",
700
+ onClick: l,
701
+ type: "button",
702
+ "aria-label": x ? "Hide keyboard" : "Show keyboard",
703
+ children: [
704
+ /* @__PURE__ */ t("span", { className: "dcg-icon-keyboard", children: "⌨" }),
705
+ /* @__PURE__ */ t("span", { className: `dcg-icon-caret ${x ? "dcg-icon-caret-down" : "dcg-icon-caret-up"}`, children: x ? "▼" : "▲" })
706
+ ]
707
+ }
708
+ ) }), C = () => /* @__PURE__ */ t("div", { className: "dcg-minimize-keypad-container", children: /* @__PURE__ */ E(
709
+ "button",
710
+ {
711
+ className: "dcg-minimize-keypad dcg-btn-light-gray",
712
+ onClick: l,
713
+ type: "button",
714
+ "aria-label": "Hide keyboard",
715
+ children: [
716
+ /* @__PURE__ */ t("span", { className: "dcg-icon-keyboard", children: "⌨" }),
717
+ /* @__PURE__ */ t("span", { className: "dcg-icon-caret dcg-icon-caret-down", children: "▼" })
718
+ ]
719
+ }
720
+ ) });
721
+ return /* @__PURE__ */ E(
722
+ "div",
723
+ {
724
+ ref: R,
725
+ className: `dcg-keypad ${x ? "dcg-visible" : "dcg-hidden"} ${b}`,
726
+ style: N,
727
+ children: [
728
+ !x && g(),
729
+ x && /* @__PURE__ */ E("div", { className: "dcg-keys-container", children: [
730
+ C(),
731
+ /* @__PURE__ */ t("div", { className: "dcg-keys-background", children: /* @__PURE__ */ t("div", { className: "dcg-keys", children: U === "default" ? T() : K() }) }),
732
+ z()
733
+ ] })
734
+ ]
735
+ }
736
+ );
737
+ };
738
+ ie.displayName = "MathKeyboard";
739
+ export {
740
+ Y as MathInput,
741
+ ie as MathKeyboard,
742
+ j as MathProvider,
743
+ H as useMathContext
744
+ };
745
+ //# sourceMappingURL=mathex.js.map