@sciexpr/vue 0.2.1 → 0.2.2

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/index.mjs DELETED
@@ -1,943 +0,0 @@
1
- import { ref as v, watch as B, shallowRef as te, defineComponent as E, useSlots as ae, openBlock as i, createElementBlock as m, normalizeClass as N, unref as S, toDisplayString as w, computed as F, inject as Y, provide as K, Fragment as C, renderList as $, createCommentVNode as M, renderSlot as oe, createTextVNode as le, createElementVNode as h, createBlock as G, Teleport as ne, normalizeStyle as H, withDirectives as D, vModelText as j, createVNode as se, nextTick as V, createStaticVNode as ce, vShow as Z, onMounted as ie, onUnmounted as re } from "vue";
2
- import { KatexRenderer as Q, UnicodeRenderer as ue, MathMLRenderer as de } from "@sciexpr/renderer";
3
- import { ParserRegistry as U } from "@sciexpr/parser";
4
- import { AIPipeline as O } from "@sciexpr/ai";
5
- import { ExpressionKind as me } from "@sciexpr/core";
6
- function ut(e) {
7
- const o = v(""), l = v(""), n = v(""), c = v(null), r = new U(), u = e.katexRenderer ?? new Q(), a = new ue(), s = new de();
8
- function d(t) {
9
- var b;
10
- try {
11
- const y = r.parse(t, { hint: "auto" });
12
- if (!y || y.children.length === 0) {
13
- o.value = "", c.value = null;
14
- return;
15
- }
16
- const g = u.render(y, {
17
- displayMode: e.displayMode,
18
- ...e.renderOptions
19
- });
20
- o.value = g.value, (b = g.warnings) != null && b.length, l.value = s.render(y).value, n.value = a.render(y).value, c.value = null;
21
- } catch (y) {
22
- c.value = {
23
- message: y instanceof Error ? y.message : String(y)
24
- }, o.value = "";
25
- }
26
- }
27
- return B(e.source, (t) => {
28
- d(t);
29
- }, { immediate: !0 }), u.ready.then(() => {
30
- d(e.source.value);
31
- }), {
32
- html: o,
33
- mathml: l,
34
- unicode: n,
35
- error: c,
36
- render: d
37
- };
38
- }
39
- function J(e) {
40
- const o = v(""), l = v(null), n = te(null), c = new U(), r = new Q();
41
- function u(a) {
42
- var s;
43
- try {
44
- const d = c.parse(a, { hint: "auto" });
45
- if (n.value = d, !d || d.children.length === 0) {
46
- o.value = "", l.value = null;
47
- return;
48
- }
49
- const t = r.render(d, {
50
- displayMode: ((s = e.displayMode) == null ? void 0 : s.value) ?? !1
51
- });
52
- o.value = t.value, l.value = null;
53
- } catch (d) {
54
- l.value = {
55
- message: d instanceof Error ? d.message : String(d)
56
- }, o.value = a;
57
- }
58
- }
59
- return B([e.source, e.displayMode ?? v(!1)], ([a]) => {
60
- u(a);
61
- }, { immediate: !0 }), r.ready.then(() => {
62
- u(e.source.value);
63
- }), { html: o, error: l, ast: n, render: u };
64
- }
65
- const pe = ["data-source"], be = ["title"], xe = ["innerHTML"], ve = /* @__PURE__ */ E({
66
- __name: "Formula",
67
- props: {
68
- source: { default: "" },
69
- displayMode: { type: Boolean, default: !1 },
70
- throwOnError: { type: Boolean, default: !1 },
71
- className: { default: "" },
72
- fallbackText: { default: "" }
73
- },
74
- setup(e) {
75
- var s, d, t;
76
- const o = e, l = ae(), n = (t = (d = (s = l.default) == null ? void 0 : s.call(l)) == null ? void 0 : d[0]) == null ? void 0 : t.children, c = v(o.source || n || "");
77
- B(() => o.source, (b) => {
78
- c.value = b || n || "";
79
- });
80
- const r = v(o.displayMode);
81
- B(() => o.displayMode, (b) => {
82
- r.value = b;
83
- });
84
- const { html: u, error: a } = J({
85
- source: c,
86
- displayMode: r
87
- });
88
- return (b, y) => (i(), m("span", {
89
- class: N(["sciexpr-formula", o.className, {
90
- "sciexpr-display": o.displayMode,
91
- "sciexpr-error": S(a)
92
- }]),
93
- "data-source": c.value
94
- }, [
95
- S(a) ? (i(), m("span", {
96
- key: 0,
97
- class: "sciexpr-formula-error",
98
- title: S(a).message
99
- }, w(e.fallbackText || c.value), 9, be)) : (i(), m("span", {
100
- key: 1,
101
- innerHTML: S(u),
102
- class: "sciexpr-formula-content"
103
- }, null, 8, xe))
104
- ], 10, pe));
105
- }
106
- }), A = (e, o) => {
107
- const l = e.__vccOpts || e;
108
- for (const [n, c] of o)
109
- l[n] = c;
110
- return l;
111
- }, dt = /* @__PURE__ */ A(ve, [["__scopeId", "data-v-557e5ff9"]]);
112
- function fe(e) {
113
- const o = v(e.initialValue ?? ""), l = v(0), n = v(""), c = v(null), r = v(null), u = new U();
114
- function a(g, I) {
115
- o.value = g, I !== void 0 && (l.value = I);
116
- }
117
- function s(g) {
118
- const I = o.value.slice(0, l.value), T = o.value.slice(l.value);
119
- o.value = I + g + T, l.value += g.length;
120
- }
121
- function d(g, I) {
122
- const T = o.value;
123
- o.value = g + T + I, l.value = o.value.length;
124
- }
125
- function t() {
126
- try {
127
- const g = u.parse(o.value, { hint: "auto" });
128
- return r.value = g, g;
129
- } catch {
130
- return r.value = null, null;
131
- }
132
- }
133
- const b = F(() => o.value.trim().length === 0), y = F(() => o.value);
134
- return {
135
- // State
136
- value: o,
137
- cursor: l,
138
- html: n,
139
- ast: r,
140
- error: c,
141
- // Computed
142
- isEmpty: b,
143
- latexSource: y,
144
- // Actions
145
- handleInput: a,
146
- insertText: s,
147
- wrapSelection: d,
148
- parse: t
149
- };
150
- }
151
- function ye(e) {
152
- const o = v([]), l = v(!1), n = v(0), c = v(""), r = e.pipeline ?? new O(), u = e.config ?? { enabled: !0, minTriggerLength: 2, maxItems: 10 };
153
- async function a(b, y) {
154
- if (!u.enabled) {
155
- l.value = !1;
156
- return;
157
- }
158
- const g = he(b, y);
159
- if (!g || g.length < (u.minTriggerLength ?? 2)) {
160
- l.value = !1;
161
- return;
162
- }
163
- c.value = g;
164
- const I = {
165
- currentInput: b,
166
- cursorPosition: y,
167
- expressionType: me.Math
168
- }, T = await r.getCompletions(I);
169
- o.value = T.items.slice(0, u.maxItems ?? 10), l.value = o.value.length > 0, n.value = 0;
170
- }
171
- function s(b) {
172
- return l.value = !1, b.text;
173
- }
174
- function d(b) {
175
- b === "up" ? n.value = Math.max(0, n.value - 1) : n.value = Math.min(o.value.length - 1, n.value + 1);
176
- }
177
- function t() {
178
- l.value = !1, o.value = [];
179
- }
180
- return {
181
- suggestions: o,
182
- visible: l,
183
- selectedIndex: n,
184
- query: c,
185
- trigger: a,
186
- select: s,
187
- moveSelection: d,
188
- close: t
189
- };
190
- }
191
- function he(e, o) {
192
- const l = e.slice(0, o), n = l.lastIndexOf("\\");
193
- if (n !== -1) {
194
- const u = l.slice(n).match(/^\\[a-zA-Z]*$/);
195
- if (u) return u[0];
196
- }
197
- const c = l.match(/([a-zA-Z_]+)$/);
198
- return c ? c[1] : "";
199
- }
200
- const q = Symbol("sciexpr-ai-pipeline");
201
- function ge(e) {
202
- const o = e ? new O(e) : Y(q, null);
203
- function l(r) {
204
- const u = new O(r);
205
- K(q, u);
206
- }
207
- function n(r) {
208
- o && K(q, new O({ completionProvider: r }));
209
- }
210
- function c(r) {
211
- o && K(q, new O({ knowledgeBaseProvider: r }));
212
- }
213
- return {
214
- pipeline: o,
215
- provideAI: l,
216
- setCompletionProvider: n,
217
- setKnowledgeBase: c
218
- };
219
- }
220
- const we = {
221
- key: 0,
222
- class: "sciexpr-toolbar-group-label"
223
- }, ke = ["title", "disabled", "onClick"], Ce = /* @__PURE__ */ E({
224
- __name: "Toolbar",
225
- props: {
226
- categories: {},
227
- disabled: { type: Boolean },
228
- compact: { type: Boolean }
229
- },
230
- emits: ["insert"],
231
- setup(e, { emit: o }) {
232
- const l = o, n = [
233
- {
234
- id: "fraction",
235
- label: "Fraction & Script",
236
- icon: "📐",
237
- commands: [
238
- { latex: "\\frac{}{}", label: "⅟", description: "Fraction" },
239
- { latex: "^{}", label: "x²", description: "Superscript" },
240
- { latex: "_{}", label: "x₂", description: "Subscript" },
241
- { latex: "^{}_{}", label: "x²₁", description: "Both scripts" }
242
- ]
243
- },
244
- {
245
- id: "radical",
246
- label: "Radicals",
247
- icon: "√",
248
- commands: [
249
- { latex: "\\sqrt{}", label: "√x", description: "Square root" },
250
- { latex: "\\sqrt[3]{}", label: "∛x", description: "Cube root" },
251
- { latex: "\\sqrt[n]{}", label: "ⁿ√x", description: "Nth root" }
252
- ]
253
- },
254
- {
255
- id: "symbol",
256
- label: "Operators",
257
- icon: "∑",
258
- commands: [
259
- { latex: "\\sum_{}^{}", label: "∑", description: "Summation" },
260
- { latex: "\\prod_{}^{}", label: "∏", description: "Product" },
261
- { latex: "\\int_{}^{}", label: "∫", description: "Integral" },
262
- { latex: "\\lim_{x \\to }{}", label: "lim", description: "Limit" },
263
- { latex: "\\infty", label: "∞", description: "Infinity" },
264
- { latex: "\\partial", label: "∂", description: "Partial derivative" }
265
- ]
266
- },
267
- {
268
- id: "greek",
269
- label: "Greek",
270
- icon: "α",
271
- commands: [
272
- { latex: "\\alpha", label: "α", description: "Alpha" },
273
- { latex: "\\beta", label: "β", description: "Beta" },
274
- { latex: "\\gamma", label: "γ", description: "Gamma" },
275
- { latex: "\\delta", label: "δ", description: "Delta" },
276
- { latex: "\\theta", label: "θ", description: "Theta" },
277
- { latex: "\\lambda", label: "λ", description: "Lambda" },
278
- { latex: "\\mu", label: "μ", description: "Mu" },
279
- { latex: "\\pi", label: "π", description: "Pi" },
280
- { latex: "\\sigma", label: "σ", description: "Sigma" },
281
- { latex: "\\phi", label: "φ", description: "Phi" },
282
- { latex: "\\omega", label: "ω", description: "Omega" }
283
- ]
284
- },
285
- {
286
- id: "matrix",
287
- label: "Matrix",
288
- icon: "▦",
289
- commands: [
290
- { latex: "\\begin{pmatrix} & \\\\ & \\end{pmatrix}", label: "( )", description: "pmatrix" },
291
- { latex: "\\begin{bmatrix} & \\\\ & \\end{bmatrix}", label: "[ ]", description: "bmatrix" },
292
- { latex: "\\begin{vmatrix} & \\\\ & \\end{vmatrix}", label: "| |", description: "vmatrix" }
293
- ]
294
- },
295
- {
296
- id: "chemistry",
297
- label: "Chemistry",
298
- icon: "⚗",
299
- commands: [
300
- { latex: "\\ce{H2O}", label: "H₂O", description: "Water" },
301
- { latex: "\\ce{->}", label: "→", description: "Reaction arrow" },
302
- { latex: "\\ce{<=>}", label: "⇌", description: "Equilibrium" },
303
- { latex: "^{n+}", label: "ⁿ⁺", description: "Charge" }
304
- ]
305
- }
306
- ];
307
- function c(r) {
308
- l("insert", r);
309
- }
310
- return (r, u) => (i(), m("div", {
311
- class: N(["sciexpr-toolbar", { "sciexpr-toolbar-compact": e.compact }]),
312
- role: "toolbar",
313
- "aria-label": "Formula toolbar"
314
- }, [
315
- (i(), m(C, null, $(n, (a) => (i(), m(C, {
316
- key: a.id
317
- }, [
318
- !e.categories || e.categories.includes(a.id) ? (i(), m("div", {
319
- key: 0,
320
- class: N(["sciexpr-toolbar-group", { "sciexpr-toolbar-group-compact": e.compact }])
321
- }, [
322
- e.compact ? M("", !0) : (i(), m("span", we, w(a.icon) + " " + w(a.label), 1)),
323
- (i(!0), m(C, null, $(a.commands, (s) => (i(), m("button", {
324
- key: s.latex,
325
- class: N(["sciexpr-toolbar-btn", { "sciexpr-toolbar-btn-compact": e.compact }]),
326
- title: s.description,
327
- disabled: e.disabled,
328
- type: "button",
329
- onClick: (d) => c(s.latex)
330
- }, [
331
- oe(r.$slots, `btn-${s.label}`, { command: s }, () => [
332
- le(w(s.label), 1)
333
- ], !0)
334
- ], 10, ke))), 128))
335
- ], 2)) : M("", !0)
336
- ], 64))), 64))
337
- ], 2));
338
- }
339
- }), Se = /* @__PURE__ */ A(Ce, [["__scopeId", "data-v-329eccb9"]]), Ne = {
340
- key: 0,
341
- class: "sciexpr-preview-error"
342
- }, _e = {
343
- key: 1,
344
- class: "sciexpr-preview-render"
345
- }, $e = ["innerHTML"], Me = {
346
- key: 2,
347
- class: "sciexpr-preview-empty"
348
- }, Ie = {
349
- key: 3,
350
- class: "sciexpr-preview-source"
351
- }, Le = /* @__PURE__ */ E({
352
- __name: "LivePreview",
353
- props: {
354
- source: {},
355
- displayMode: { type: Boolean, default: !1 },
356
- showSource: { type: Boolean, default: !1 }
357
- },
358
- setup(e) {
359
- const o = e, l = v(o.source), n = v(o.displayMode);
360
- B(() => o.source, (u) => {
361
- l.value = u;
362
- }), B(() => o.displayMode, (u) => {
363
- n.value = u;
364
- });
365
- const { html: c, error: r } = J({
366
- source: l,
367
- displayMode: n
368
- });
369
- return (u, a) => (i(), m("div", {
370
- class: N(["sciexpr-preview", { "sciexpr-preview-display": e.displayMode }])
371
- }, [
372
- S(r) ? (i(), m("div", Ne, [
373
- a[0] || (a[0] = h("span", { class: "sciexpr-preview-error-icon" }, "⚠", -1)),
374
- h("span", null, w(S(r).message), 1)
375
- ])) : S(c) ? (i(), m("div", _e, [
376
- h("span", { innerHTML: S(c) }, null, 8, $e)
377
- ])) : (i(), m("div", Me, [...a[1] || (a[1] = [
378
- h("span", { class: "sciexpr-preview-empty-text" }, "Preview", -1)
379
- ])])),
380
- e.showSource && e.source ? (i(), m("div", Ie, [
381
- h("code", null, w(e.source), 1)
382
- ])) : M("", !0)
383
- ], 2));
384
- }
385
- }), Pe = /* @__PURE__ */ A(Le, [["__scopeId", "data-v-b3730bc4"]]), Re = ["aria-selected", "onClick", "onMouseenter"], Te = { class: "sciexpr-autocomplete-label" }, Be = {
386
- key: 0,
387
- class: "sciexpr-autocomplete-desc"
388
- }, Ee = {
389
- key: 1,
390
- class: "sciexpr-autocomplete-source"
391
- }, Ae = /* @__PURE__ */ E({
392
- __name: "AutocompleteDropdown",
393
- props: {
394
- items: {},
395
- visible: { type: Boolean },
396
- selectedIndex: {},
397
- position: {}
398
- },
399
- emits: ["select", "close"],
400
- setup(e, { emit: o }) {
401
- const l = o, n = Y(q, null);
402
- function c(u) {
403
- l("select", u);
404
- }
405
- function r(u) {
406
- return {
407
- symbol: "#0d6efd",
408
- command: "#6f42c1",
409
- template: "#198754",
410
- correction: "#fd7e14",
411
- formula: "#d63384"
412
- }[u] ?? "#6c757d";
413
- }
414
- return (u, a) => (i(), G(ne, { to: "body" }, [
415
- e.visible && e.items.length > 0 ? (i(), m("div", {
416
- key: 0,
417
- class: "sciexpr-autocomplete",
418
- style: H(e.position ? { top: e.position.top + "px", left: e.position.left + "px" } : {}),
419
- role: "listbox"
420
- }, [
421
- (i(!0), m(C, null, $(e.items, (s, d) => (i(), m("div", {
422
- key: `${s.text}-${d}`,
423
- class: N(["sciexpr-autocomplete-item", { selected: d === e.selectedIndex }]),
424
- role: "option",
425
- "aria-selected": d === e.selectedIndex,
426
- onClick: (t) => c(s),
427
- onMouseenter: (t) => u.$emit("select", s)
428
- }, [
429
- h("span", {
430
- class: "sciexpr-autocomplete-category",
431
- style: H({ background: r(s.category) })
432
- }, w(s.category), 5),
433
- h("span", Te, w(s.label), 1),
434
- s.description ? (i(), m("span", Be, w(s.description), 1)) : M("", !0),
435
- S(n) ? (i(), m("span", Ee, w(s.previewHtml ? "AI" : ""), 1)) : M("", !0)
436
- ], 42, Re))), 128))
437
- ], 4)) : M("", !0)
438
- ]));
439
- }
440
- }), Oe = /* @__PURE__ */ A(Ae, [["__scopeId", "data-v-d18e03d1"]]), qe = { class: "sciexpr-editor-input-wrap" }, Fe = ["placeholder", "readonly", "rows"], He = /* @__PURE__ */ E({
441
- __name: "FormulaEditor",
442
- props: {
443
- value: { default: "" },
444
- displayMode: { type: Boolean, default: !1 },
445
- readonly: { type: Boolean, default: !1 },
446
- placeholder: { default: "Type LaTeX or chemical formula..." },
447
- toolbar: {},
448
- autocomplete: {},
449
- showPreview: { type: Boolean, default: !0 },
450
- showToolbar: { type: Boolean, default: !0 },
451
- rows: { default: 3 }
452
- },
453
- emits: ["update:value", "change", "error"],
454
- setup(e, { emit: o }) {
455
- const l = e, n = o, c = v(null), r = v(null), u = v({ top: 0, left: 0 }), a = v(l.value);
456
- B(() => l.value, (p) => {
457
- a.value = p;
458
- });
459
- const s = fe({ initialValue: a.value }), { pipeline: d } = ge(), t = ye({
460
- config: l.autocomplete,
461
- pipeline: d
462
- });
463
- function b(p) {
464
- const x = p.target, f = x.value, k = x.selectionStart;
465
- a.value = f, s.value.value = f, s.cursor.value = k, n("update:value", f), n("change", f), t.trigger(f, k), W();
466
- }
467
- function y(p) {
468
- if (t.visible.value) {
469
- if (p.key === "ArrowDown") {
470
- p.preventDefault(), t.moveSelection("down");
471
- return;
472
- }
473
- if (p.key === "ArrowUp") {
474
- p.preventDefault(), t.moveSelection("up");
475
- return;
476
- }
477
- if (p.key === "Enter" || p.key === "Tab") {
478
- p.preventDefault();
479
- const x = t.suggestions.value[t.selectedIndex.value];
480
- x && z(x.text);
481
- return;
482
- }
483
- if (p.key === "Escape") {
484
- t.close();
485
- return;
486
- }
487
- }
488
- (p.ctrlKey || p.metaKey) && (p.key === "b" && (p.preventDefault(), ee("\\mathbf{", "}")), p.key === "/" && (p.preventDefault(), T("\\frac{}{}")));
489
- }
490
- function g(p) {
491
- T(p);
492
- }
493
- function I(p) {
494
- z(p.text);
495
- }
496
- function T(p) {
497
- const x = c.value;
498
- if (!x) return;
499
- const f = x.selectionStart, k = x.selectionEnd, L = a.value.slice(0, f), P = a.value.slice(k);
500
- a.value = L + p + P, n("update:value", a.value), V(() => {
501
- x.focus();
502
- const _ = f + p.length;
503
- x.setSelectionRange(_, _), t.close();
504
- });
505
- }
506
- function z(p) {
507
- const x = c.value;
508
- if (!x) return;
509
- const f = x.selectionStart, k = a.value.slice(0, f), L = k.lastIndexOf("\\");
510
- let P;
511
- if (L !== -1 && f - L < 30)
512
- P = L;
513
- else {
514
- const R = k.match(/([a-zA-Z_]+)$/);
515
- P = R ? f - R[0].length : f;
516
- }
517
- const _ = a.value.slice(f);
518
- a.value = a.value.slice(0, P) + p + _, n("update:value", a.value), V(() => {
519
- x.focus();
520
- const R = P + p.length;
521
- x.setSelectionRange(R, R), t.close();
522
- });
523
- }
524
- function ee(p, x) {
525
- const f = c.value;
526
- if (!f) return;
527
- const k = f.selectionStart, L = f.selectionEnd, P = a.value.slice(k, L) || "", _ = a.value.slice(0, k) + p + P + x + a.value.slice(L);
528
- a.value = _, n("update:value", _), V(() => {
529
- f.focus();
530
- const R = k + p.length + P.length;
531
- f.setSelectionRange(R, R);
532
- });
533
- }
534
- function W() {
535
- const p = c.value;
536
- if (!p) return;
537
- const x = p.getBoundingClientRect(), f = p.selectionStart, k = 20, L = 8, _ = a.value.slice(0, f).split(`
538
- `), R = _[_.length - 1].length;
539
- u.value = {
540
- top: x.top + _.length * k + 24 + window.scrollY,
541
- left: x.left + R * L + window.scrollX
542
- };
543
- }
544
- return F(() => a.value.trim().length > 0), (p, x) => {
545
- var f;
546
- return i(), m("div", {
547
- ref_key: "editorRef",
548
- ref: r,
549
- class: N(["sciexpr-editor", { "sciexpr-editor-display": e.displayMode }])
550
- }, [
551
- e.showToolbar && !e.readonly ? (i(), G(Se, {
552
- key: 0,
553
- categories: (f = e.toolbar) == null ? void 0 : f.categories,
554
- onInsert: g
555
- }, null, 8, ["categories"])) : M("", !0),
556
- h("div", qe, [
557
- D(h("textarea", {
558
- ref_key: "textareaRef",
559
- ref: c,
560
- "onUpdate:modelValue": x[0] || (x[0] = (k) => a.value = k),
561
- class: N(["sciexpr-editor-textarea", {
562
- "sciexpr-editor-textarea-display": e.displayMode,
563
- "sciexpr-editor-textarea-readonly": e.readonly
564
- }]),
565
- placeholder: e.placeholder,
566
- readonly: e.readonly,
567
- rows: e.rows,
568
- "aria-label": "Formula input",
569
- spellcheck: "false",
570
- autocomplete: "off",
571
- autocorrect: "off",
572
- autocapitalize: "off",
573
- onInput: b,
574
- onKeydown: y,
575
- onFocus: W
576
- }, null, 42, Fe), [
577
- [j, a.value]
578
- ])
579
- ]),
580
- se(Oe, {
581
- items: S(t).suggestions.value,
582
- visible: S(t).visible.value,
583
- "selected-index": S(t).selectedIndex.value,
584
- position: u.value,
585
- onSelect: I,
586
- onClose: x[1] || (x[1] = (k) => S(t).close())
587
- }, null, 8, ["items", "visible", "selected-index", "position"]),
588
- e.showPreview ? (i(), G(Pe, {
589
- key: 1,
590
- source: a.value,
591
- "display-mode": e.displayMode,
592
- "show-source": !1
593
- }, null, 8, ["source", "display-mode"])) : M("", !0)
594
- ], 2);
595
- };
596
- }
597
- }), mt = /* @__PURE__ */ A(He, [["__scopeId", "data-v-d6181c80"]]), De = { class: "sciexpr-symbol-panel" }, Ke = { class: "sciexpr-symbol-search" }, Ve = { class: "sciexpr-symbol-tabs" }, Ge = ["onClick"], Ue = { class: "sciexpr-symbol-grid" }, ze = ["title", "disabled", "onClick"], We = { class: "sciexpr-symbol-unicode" }, Ze = { class: "sciexpr-symbol-name" }, Xe = ["title", "disabled", "onClick"], Ye = { class: "sciexpr-symbol-unicode" }, je = { class: "sciexpr-symbol-name" }, Qe = /* @__PURE__ */ E({
598
- __name: "SymbolPanel",
599
- props: {
600
- disabled: { type: Boolean }
601
- },
602
- emits: ["insert"],
603
- setup(e, { emit: o }) {
604
- const l = o, n = [
605
- {
606
- id: "greek-lower",
607
- label: "Greek Lowercase",
608
- symbols: [
609
- { latex: "\\alpha", unicode: "α", name: "alpha" },
610
- { latex: "\\beta", unicode: "β", name: "beta" },
611
- { latex: "\\gamma", unicode: "γ", name: "gamma" },
612
- { latex: "\\delta", unicode: "δ", name: "delta" },
613
- { latex: "\\epsilon", unicode: "ε", name: "epsilon" },
614
- { latex: "\\zeta", unicode: "ζ", name: "zeta" },
615
- { latex: "\\eta", unicode: "η", name: "eta" },
616
- { latex: "\\theta", unicode: "θ", name: "theta" },
617
- { latex: "\\iota", unicode: "ι", name: "iota" },
618
- { latex: "\\kappa", unicode: "κ", name: "kappa" },
619
- { latex: "\\lambda", unicode: "λ", name: "lambda" },
620
- { latex: "\\mu", unicode: "μ", name: "mu" },
621
- { latex: "\\nu", unicode: "ν", name: "nu" },
622
- { latex: "\\xi", unicode: "ξ", name: "xi" },
623
- { latex: "\\pi", unicode: "π", name: "pi" },
624
- { latex: "\\rho", unicode: "ρ", name: "rho" },
625
- { latex: "\\sigma", unicode: "σ", name: "sigma" },
626
- { latex: "\\tau", unicode: "τ", name: "tau" },
627
- { latex: "\\phi", unicode: "φ", name: "phi" },
628
- { latex: "\\chi", unicode: "χ", name: "chi" },
629
- { latex: "\\psi", unicode: "ψ", name: "psi" },
630
- { latex: "\\omega", unicode: "ω", name: "omega" }
631
- ]
632
- },
633
- {
634
- id: "greek-upper",
635
- label: "Greek Uppercase",
636
- symbols: [
637
- { latex: "\\Gamma", unicode: "Γ", name: "Gamma" },
638
- { latex: "\\Delta", unicode: "Δ", name: "Delta" },
639
- { latex: "\\Theta", unicode: "Θ", name: "Theta" },
640
- { latex: "\\Lambda", unicode: "Λ", name: "Lambda" },
641
- { latex: "\\Xi", unicode: "Ξ", name: "Xi" },
642
- { latex: "\\Pi", unicode: "Π", name: "Pi" },
643
- { latex: "\\Sigma", unicode: "Σ", name: "Sigma" },
644
- { latex: "\\Upsilon", unicode: "Υ", name: "Upsilon" },
645
- { latex: "\\Phi", unicode: "Φ", name: "Phi" },
646
- { latex: "\\Psi", unicode: "Ψ", name: "Psi" },
647
- { latex: "\\Omega", unicode: "Ω", name: "Omega" }
648
- ]
649
- },
650
- {
651
- id: "operators",
652
- label: "Operators & Relations",
653
- symbols: [
654
- { latex: "\\times", unicode: "×", name: "times" },
655
- { latex: "\\div", unicode: "÷", name: "divide" },
656
- { latex: "\\cdot", unicode: "·", name: "dot" },
657
- { latex: "\\pm", unicode: "±", name: "plus-minus" },
658
- { latex: "\\mp", unicode: "∓", name: "minus-plus" },
659
- { latex: "\\leq", unicode: "≤", name: "leq" },
660
- { latex: "\\geq", unicode: "≥", name: "geq" },
661
- { latex: "\\neq", unicode: "≠", name: "neq" },
662
- { latex: "\\approx", unicode: "≈", name: "approx" },
663
- { latex: "\\equiv", unicode: "≡", name: "equiv" },
664
- { latex: "\\sim", unicode: "∼", name: "sim" },
665
- { latex: "\\propto", unicode: "∝", name: "propto" },
666
- { latex: "\\ll", unicode: "≪", name: "ll" },
667
- { latex: "\\gg", unicode: "≫", name: "gg" }
668
- ]
669
- },
670
- {
671
- id: "arrows",
672
- label: "Arrows",
673
- symbols: [
674
- { latex: "\\to", unicode: "→", name: "to" },
675
- { latex: "\\rightarrow", unicode: "→", name: "rightarrow" },
676
- { latex: "\\leftarrow", unicode: "←", name: "leftarrow" },
677
- { latex: "\\Rightarrow", unicode: "⇒", name: "Rightarrow" },
678
- { latex: "\\Leftarrow", unicode: "⇐", name: "Leftarrow" },
679
- { latex: "\\Leftrightarrow", unicode: "⇔", name: "Leftrightarrow" },
680
- { latex: "\\mapsto", unicode: "↦", name: "mapsto" },
681
- { latex: "\\uparrow", unicode: "↑", name: "uparrow" },
682
- { latex: "\\downarrow", unicode: "↓", name: "downarrow" }
683
- ]
684
- },
685
- {
686
- id: "misc",
687
- label: "Misc",
688
- symbols: [
689
- { latex: "\\infty", unicode: "∞", name: "infinity" },
690
- { latex: "\\partial", unicode: "∂", name: "partial" },
691
- { latex: "\\nabla", unicode: "∇", name: "nabla" },
692
- { latex: "\\forall", unicode: "∀", name: "forall" },
693
- { latex: "\\exists", unicode: "∃", name: "exists" },
694
- { latex: "\\emptyset", unicode: "∅", name: "emptyset" },
695
- { latex: "\\neg", unicode: "¬", name: "neg" },
696
- { latex: "\\angle", unicode: "∠", name: "angle" },
697
- { latex: "\\triangle", unicode: "△", name: "triangle" },
698
- { latex: "\\square", unicode: "□", name: "square" },
699
- { latex: "\\circ", unicode: "∘", name: "circle" },
700
- { latex: "\\star", unicode: "★", name: "star" }
701
- ]
702
- },
703
- {
704
- id: "chemistry",
705
- label: "Chemistry",
706
- symbols: [
707
- { latex: "\\ce{H2O}", unicode: "H₂O", name: "Water" },
708
- { latex: "\\ce{CO2}", unicode: "CO₂", name: "Carbon dioxide" },
709
- { latex: "\\ce{->}", unicode: "→", name: "Arrow right" },
710
- { latex: "\\ce{<-}", unicode: "←", name: "Arrow left" },
711
- { latex: "\\ce{<=>}", unicode: "⇌", name: "Equilibrium" },
712
- { latex: "\\ce{<->}", unicode: "⇄", name: "Resonance" },
713
- { latex: "\\ce{->[H2O]}", unicode: "→[H₂O]", name: "With condition" }
714
- ]
715
- }
716
- ], c = v(n[0].id), r = v(""), u = F(() => {
717
- if (!r.value) return n;
718
- const s = r.value.toLowerCase();
719
- return n.map((d) => ({
720
- ...d,
721
- symbols: d.symbols.filter(
722
- (t) => t.name.toLowerCase().includes(s) || t.latex.toLowerCase().includes(s)
723
- )
724
- })).filter((d) => d.symbols.length > 0);
725
- });
726
- function a(s) {
727
- l("insert", s);
728
- }
729
- return (s, d) => (i(), m("div", De, [
730
- h("div", Ke, [
731
- D(h("input", {
732
- "onUpdate:modelValue": d[0] || (d[0] = (t) => r.value = t),
733
- type: "text",
734
- class: "sciexpr-symbol-search-input",
735
- placeholder: "Search symbols..."
736
- }, null, 512), [
737
- [j, r.value]
738
- ])
739
- ]),
740
- h("div", Ve, [
741
- (i(), m(C, null, $(n, (t) => h("button", {
742
- key: t.id,
743
- class: N(["sciexpr-symbol-tab", { active: c.value === t.id }]),
744
- onClick: (b) => c.value = t.id,
745
- type: "button"
746
- }, w(t.label), 11, Ge)), 64))
747
- ]),
748
- h("div", Ue, [
749
- r.value ? (i(!0), m(C, { key: 0 }, $(u.value, (t) => (i(), m(C, {
750
- key: t.id
751
- }, [
752
- (i(!0), m(C, null, $(t.symbols, (b) => (i(), m("button", {
753
- key: b.latex,
754
- class: N(["sciexpr-symbol-btn", { "sciexpr-symbol-btn-disabled": e.disabled }]),
755
- title: `${b.name} — ${b.latex}`,
756
- disabled: e.disabled,
757
- type: "button",
758
- onClick: (y) => a(b.latex)
759
- }, [
760
- h("span", We, w(b.unicode), 1),
761
- h("span", Ze, w(b.name), 1)
762
- ], 10, ze))), 128))
763
- ], 64))), 128)) : (i(), m(C, { key: 1 }, $(n, (t) => (i(), m(C, {
764
- key: t.id
765
- }, [
766
- c.value === t.id ? (i(!0), m(C, { key: 0 }, $(t.symbols, (b) => (i(), m("button", {
767
- key: b.latex,
768
- class: N(["sciexpr-symbol-btn", { "sciexpr-symbol-btn-disabled": e.disabled }]),
769
- title: `${b.name} — ${b.latex}`,
770
- disabled: e.disabled,
771
- type: "button",
772
- onClick: (y) => a(b.latex)
773
- }, [
774
- h("span", Ye, w(b.unicode), 1),
775
- h("span", je, w(b.name), 1)
776
- ], 10, Xe))), 128)) : M("", !0)
777
- ], 64))), 64))
778
- ])
779
- ]));
780
- }
781
- }), pt = /* @__PURE__ */ A(Qe, [["__scopeId", "data-v-8a9ec119"]]), Je = { class: "sciexpr-element-grid" }, et = ["title", "disabled", "onClick"], tt = {
782
- key: 0,
783
- class: "sciexpr-element-number"
784
- }, at = {
785
- key: 1,
786
- class: "sciexpr-element-symbol"
787
- }, X = 18, ot = 6, lt = /* @__PURE__ */ E({
788
- __name: "ElementTable",
789
- props: {
790
- disabled: { type: Boolean },
791
- compact: { type: Boolean }
792
- },
793
- emits: ["insert"],
794
- setup(e, { emit: o }) {
795
- const l = o, n = [
796
- // Row 1
797
- { symbol: "H", name: "Hydrogen", atomicNumber: 1, row: 1, col: 1, block: "s" },
798
- { symbol: "He", name: "Helium", atomicNumber: 2, row: 1, col: 18, block: "s" },
799
- // Row 2
800
- { symbol: "Li", name: "Lithium", atomicNumber: 3, row: 2, col: 1, block: "s" },
801
- { symbol: "Be", name: "Beryllium", atomicNumber: 4, row: 2, col: 2, block: "s" },
802
- { symbol: "B", name: "Boron", atomicNumber: 5, row: 2, col: 13, block: "p" },
803
- { symbol: "C", name: "Carbon", atomicNumber: 6, row: 2, col: 14, block: "p" },
804
- { symbol: "N", name: "Nitrogen", atomicNumber: 7, row: 2, col: 15, block: "p" },
805
- { symbol: "O", name: "Oxygen", atomicNumber: 8, row: 2, col: 16, block: "p" },
806
- { symbol: "F", name: "Fluorine", atomicNumber: 9, row: 2, col: 17, block: "p" },
807
- { symbol: "Ne", name: "Neon", atomicNumber: 10, row: 2, col: 18, block: "p" },
808
- // Row 3
809
- { symbol: "Na", name: "Sodium", atomicNumber: 11, row: 3, col: 1, block: "s" },
810
- { symbol: "Mg", name: "Magnesium", atomicNumber: 12, row: 3, col: 2, block: "s" },
811
- { symbol: "Al", name: "Aluminium", atomicNumber: 13, row: 3, col: 13, block: "p" },
812
- { symbol: "Si", name: "Silicon", atomicNumber: 14, row: 3, col: 14, block: "p" },
813
- { symbol: "P", name: "Phosphorus", atomicNumber: 15, row: 3, col: 15, block: "p" },
814
- { symbol: "S", name: "Sulfur", atomicNumber: 16, row: 3, col: 16, block: "p" },
815
- { symbol: "Cl", name: "Chlorine", atomicNumber: 17, row: 3, col: 17, block: "p" },
816
- { symbol: "Ar", name: "Argon", atomicNumber: 18, row: 3, col: 18, block: "p" },
817
- // Row 4
818
- { symbol: "K", name: "Potassium", atomicNumber: 19, row: 4, col: 1, block: "s" },
819
- { symbol: "Ca", name: "Calcium", atomicNumber: 20, row: 4, col: 2, block: "s" },
820
- // Transition metals (simplified)
821
- { symbol: "Cr", name: "Chromium", atomicNumber: 24, row: 4, col: 6, block: "d" },
822
- { symbol: "Mn", name: "Manganese", atomicNumber: 25, row: 4, col: 7, block: "d" },
823
- { symbol: "Fe", name: "Iron", atomicNumber: 26, row: 4, col: 8, block: "d" },
824
- { symbol: "Co", name: "Cobalt", atomicNumber: 27, row: 4, col: 9, block: "d" },
825
- { symbol: "Ni", name: "Nickel", atomicNumber: 28, row: 4, col: 10, block: "d" },
826
- { symbol: "Cu", name: "Copper", atomicNumber: 29, row: 4, col: 11, block: "d" },
827
- { symbol: "Zn", name: "Zinc", atomicNumber: 30, row: 4, col: 12, block: "d" },
828
- // P-block continued
829
- { symbol: "Br", name: "Bromine", atomicNumber: 35, row: 4, col: 17, block: "p" },
830
- // Row 5
831
- { symbol: "Ag", name: "Silver", atomicNumber: 47, row: 5, col: 11, block: "d" },
832
- { symbol: "Au", name: "Gold", atomicNumber: 79, row: 5, col: 11, block: "d" },
833
- { symbol: "Hg", name: "Mercury", atomicNumber: 80, row: 5, col: 12, block: "d" },
834
- { symbol: "I", name: "Iodine", atomicNumber: 53, row: 5, col: 17, block: "p" },
835
- // Row 6
836
- { symbol: "Pt", name: "Platinum", atomicNumber: 78, row: 6, col: 10, block: "d" },
837
- { symbol: "Pb", name: "Lead", atomicNumber: 82, row: 6, col: 14, block: "p" }
838
- ], c = F(() => {
839
- const a = [];
840
- for (let s = 0; s < ot; s++)
841
- a.push(new Array(X).fill(null));
842
- for (const s of n)
843
- a[s.row - 1][s.col - 1] = s;
844
- return a;
845
- });
846
- function r(a) {
847
- return {
848
- s: "#ff6b6b",
849
- p: "#ffd93d",
850
- d: "#6bcb77",
851
- f: "#4d96ff"
852
- }[a] ?? "#adb5bd";
853
- }
854
- function u(a) {
855
- l("insert", a);
856
- }
857
- return (a, s) => (i(), m("div", {
858
- class: N(["sciexpr-element-table", { "sciexpr-element-table-compact": e.compact }])
859
- }, [
860
- s[0] || (s[0] = ce('<div class="sciexpr-element-legend" data-v-a5437c7c><span class="legend-item" data-v-a5437c7c><span class="legend-dot" style="background:#ff6b6b;" data-v-a5437c7c></span> s-block</span><span class="legend-item" data-v-a5437c7c><span class="legend-dot" style="background:#ffd93d;" data-v-a5437c7c></span> p-block</span><span class="legend-item" data-v-a5437c7c><span class="legend-dot" style="background:#6bcb77;" data-v-a5437c7c></span> d-block</span><span class="legend-item" data-v-a5437c7c><span class="legend-dot" style="background:#4d96ff;" data-v-a5437c7c></span> f-block</span></div>', 1)),
861
- h("div", Je, [
862
- (i(!0), m(C, null, $(c.value, (d) => (i(), m(C, {
863
- key: c.value.indexOf(d)
864
- }, [
865
- (i(!0), m(C, null, $(d, (t, b) => D((i(), m("button", {
866
- key: b,
867
- class: N(["sciexpr-element-cell", {
868
- "sciexpr-element-cell-compact": e.compact,
869
- "sciexpr-element-cell-disabled": e.disabled
870
- }]),
871
- style: H(t ? {
872
- gridRow: t.row,
873
- gridColumn: t.col,
874
- "--block-color": r(t.block)
875
- } : {}),
876
- title: t ? `${t.name} (${t.atomicNumber})` : "",
877
- disabled: e.disabled,
878
- type: "button",
879
- onClick: (y) => t && u(t.symbol)
880
- }, [
881
- t ? (i(), m("span", tt, w(t.atomicNumber), 1)) : M("", !0),
882
- t ? (i(), m("span", at, w(t.symbol), 1)) : M("", !0)
883
- ], 14, et)), [
884
- [Z, t !== null]
885
- ])), 128)),
886
- (i(), m(C, null, $(X, (t) => D(h("div", {
887
- key: "empty-" + t,
888
- class: "sciexpr-element-cell sciexpr-element-empty",
889
- style: H({ gridRow: c.value.indexOf(d) + 1, gridColumn: t })
890
- }, null, 4), [
891
- [Z, !d[t - 1]]
892
- ])), 64))
893
- ], 64))), 128))
894
- ])
895
- ], 2));
896
- }
897
- }), bt = /* @__PURE__ */ A(lt, [["__scopeId", "data-v-a5437c7c"]]);
898
- function xt(e) {
899
- function o(l) {
900
- for (const n of e) {
901
- const c = l.key.toLowerCase() === n.key.toLowerCase(), r = !!n.ctrl === (l.ctrlKey || l.metaKey), u = !!n.shift === l.shiftKey, a = !!n.alt === l.altKey;
902
- if (c && r && u && a) {
903
- l.preventDefault(), n.action();
904
- return;
905
- }
906
- }
907
- }
908
- ie(() => {
909
- window.addEventListener("keydown", o);
910
- }), re(() => {
911
- window.removeEventListener("keydown", o);
912
- });
913
- }
914
- const vt = [
915
- { key: "b", ctrl: !0, action: () => {
916
- }, description: "Bold (\\mathbf{})" },
917
- { key: "/", ctrl: !0, action: () => {
918
- }, description: "Fraction (\\frac{}{})" },
919
- { key: "s", ctrl: !0, shift: !0, action: () => {
920
- }, description: "Square root (\\sqrt{})" },
921
- { key: "1", ctrl: !0, action: () => {
922
- }, description: "Subscript (_)" },
923
- { key: "2", ctrl: !0, action: () => {
924
- }, description: "Superscript (^)" }
925
- ];
926
- export {
927
- q as AI_PIPELINE_KEY,
928
- Oe as AutocompleteDropdown,
929
- vt as BUILTIN_SHORTCUTS,
930
- bt as ElementTable,
931
- dt as Formula,
932
- mt as FormulaEditor,
933
- Se as FormulaToolbar,
934
- Pe as LivePreview,
935
- pt as SymbolPanel,
936
- ge as useAIProvider,
937
- ye as useAutocomplete,
938
- J as useFormula,
939
- fe as useFormulaEditor,
940
- ut as useFormulaRender,
941
- xt as useShortcuts
942
- };
943
- //# sourceMappingURL=index.mjs.map