@drghaliasri/butex 4.4.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -34,7 +34,7 @@ __export(react_document2_entry_exports, {
34
34
  module.exports = __toCommonJS(react_document2_entry_exports);
35
35
 
36
36
  // src/react-document2/ButexDocumentEditor2.tsx
37
- var import_react6 = require("react");
37
+ var import_react9 = require("react");
38
38
 
39
39
  // src/document2/ids.ts
40
40
  var nextId = 1;
@@ -44,6 +44,100 @@ function document2Id(prefix) {
44
44
  return id;
45
45
  }
46
46
 
47
+ // src/editor/digits.ts
48
+ var WESTERN = "0123456789";
49
+ var ARABIC_INDIC = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
50
+ var PERSIAN_INDIC = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
51
+ var digitSets = {
52
+ western: WESTERN,
53
+ arabicIndic: ARABIC_INDIC,
54
+ persianIndic: PERSIAN_INDIC
55
+ };
56
+ function digitValue(char) {
57
+ const western = WESTERN.indexOf(char);
58
+ if (western >= 0) {
59
+ return western;
60
+ }
61
+ const arabicIndic = ARABIC_INDIC.indexOf(char);
62
+ if (arabicIndic >= 0) {
63
+ return arabicIndic;
64
+ }
65
+ return PERSIAN_INDIC.indexOf(char);
66
+ }
67
+ function formatDigits(value, digitForm = "western") {
68
+ const target = digitSets[digitForm];
69
+ return Array.from(value, (char) => {
70
+ const value2 = digitValue(char);
71
+ return value2 >= 0 ? target[value2] : char;
72
+ }).join("");
73
+ }
74
+
75
+ // src/document2/citations.ts
76
+ function referenceNumberMap(references) {
77
+ const map = /* @__PURE__ */ new Map();
78
+ references.forEach((reference, index) => {
79
+ if (!map.has(reference.key)) {
80
+ map.set(reference.key, index + 1);
81
+ }
82
+ });
83
+ return map;
84
+ }
85
+ function resolveCiteNumbers(keys, references) {
86
+ const map = referenceNumberMap(references);
87
+ return keys.map((key) => map.get(key) ?? null);
88
+ }
89
+ function formatCiteLabel(keys, references, options = {}) {
90
+ const documentDirection = options.documentDirection ?? "rtl";
91
+ const digitForm = options.digitForm ?? (documentDirection === "rtl" ? "arabicIndic" : "western");
92
+ const numbers = resolveCiteNumbers(keys, references).map((value) => value === null ? "?" : String(value));
93
+ const display = documentDirection === "rtl" ? [...numbers].reverse() : numbers;
94
+ const separator = documentDirection === "rtl" ? "\u060C" : ", ";
95
+ const body = display.map((part) => formatDigits(part, digitForm)).join(separator);
96
+ return `[${body}]`;
97
+ }
98
+ function formatBibliographyNumber(index, options = {}) {
99
+ const documentDirection = options.documentDirection ?? "rtl";
100
+ const digitForm = options.digitForm ?? (documentDirection === "rtl" ? "arabicIndic" : "western");
101
+ return formatDigits(String(index), digitForm);
102
+ }
103
+ function parseCiteKeys(source) {
104
+ const match = /^\\cite\{([^}]*)\}$/.exec(source.trim());
105
+ if (!match) {
106
+ return [];
107
+ }
108
+ return (match[1] ?? "").split(",").map((key) => key.trim()).filter((key) => key.length > 0);
109
+ }
110
+ function citeTokenLatex(keys) {
111
+ return `\\cite{${keys.join(",")}}`;
112
+ }
113
+ function referenceFromJson(json) {
114
+ return {
115
+ id: document2Id("ref"),
116
+ key: json.key,
117
+ authors: typeof json.authors === "string" ? json.authors : "",
118
+ title: typeof json.title === "string" ? json.title : "",
119
+ year: typeof json.year === "string" ? json.year : "",
120
+ url: typeof json.url === "string" ? json.url : "",
121
+ venue: typeof json.venue === "string" ? json.venue : ""
122
+ };
123
+ }
124
+ function createEmptyReference2(partial = {}) {
125
+ return referenceFromJson({
126
+ key: partial.key ?? `ref${String(Date.now()).slice(-4)}`,
127
+ authors: partial.authors,
128
+ title: partial.title,
129
+ year: partial.year,
130
+ url: partial.url,
131
+ venue: partial.venue
132
+ });
133
+ }
134
+ function bibliographyEntryLatex(reference) {
135
+ const parts = [reference.authors, reference.title, reference.venue, reference.year].filter((part) => part.trim().length > 0);
136
+ const body = parts.join(", ");
137
+ const url = reference.url.trim().length > 0 ? ` \\url{${reference.url}}` : "";
138
+ return `\\bibitem{${reference.key}} ${body}${url}`.trim();
139
+ }
140
+
47
141
  // src/ast/commands/index.ts
48
142
  function renderCommandCore(context) {
49
143
  const optional = context.optionalArgs.map((arg) => `[${context.renderChain(arg)}]`).join("");
@@ -462,53 +556,84 @@ function environmentSpan(value, start) {
462
556
  const end = closingStart + closing.length;
463
557
  return { start, end, source: value.slice(start, end), opening, closing, display: true };
464
558
  }
465
- function detectMathSpans2(value) {
466
- const spans = [];
467
- let i = 0;
468
- while (i < value.length) {
469
- if (value.startsWith("\\begin{", i)) {
470
- const span = environmentSpan(value, i);
471
- if (span) {
472
- spans.push(span);
473
- i = span.end;
474
- continue;
475
- }
559
+ function citeSpan(value, start) {
560
+ if (!value.startsWith("\\cite{", start) || isEscaped(value, start)) {
561
+ return null;
562
+ }
563
+ const openBrace = start + "\\cite".length;
564
+ if (value[openBrace] !== "{") {
565
+ return null;
566
+ }
567
+ let depth = 0;
568
+ for (let i = openBrace; i < value.length; i += 1) {
569
+ const char = value[i];
570
+ if (char === "{" && !isEscaped(value, i)) {
571
+ depth += 1;
572
+ continue;
476
573
  }
477
- if (value.startsWith("\\(", i)) {
478
- const close = value.indexOf("\\)", i + 2);
479
- if (close >= 0) {
480
- const end = close + 2;
481
- spans.push({ start: i, end, source: value.slice(i, end), opening: "\\(", closing: "\\)", display: false });
482
- i = end;
483
- continue;
574
+ if (char === "}" && !isEscaped(value, i)) {
575
+ depth -= 1;
576
+ if (depth === 0) {
577
+ const end = i + 1;
578
+ const source = value.slice(start, end);
579
+ return { kind: "cite", start, end, source, keys: parseCiteKeys(source) };
484
580
  }
485
581
  }
486
- if (value.startsWith("\\[", i)) {
487
- const close = value.indexOf("\\]", i + 2);
488
- if (close >= 0) {
489
- const end = close + 2;
490
- spans.push({ start: i, end, source: value.slice(i, end), opening: "\\[", closing: "\\]", display: true });
491
- i = end;
492
- continue;
493
- }
582
+ }
583
+ return null;
584
+ }
585
+ function mathSpanAt(value, i) {
586
+ if (value.startsWith("\\begin{", i)) {
587
+ return environmentSpan(value, i);
588
+ }
589
+ if (value.startsWith("\\(", i)) {
590
+ const close = value.indexOf("\\)", i + 2);
591
+ if (close >= 0) {
592
+ const end = close + 2;
593
+ return { start: i, end, source: value.slice(i, end), opening: "\\(", closing: "\\)", display: false };
494
594
  }
495
- if (value.startsWith("$$", i) && !isEscaped(value, i)) {
496
- const close = value.indexOf("$$", i + 2);
497
- if (close >= 0) {
498
- const end = close + 2;
499
- spans.push({ start: i, end, source: value.slice(i, end), opening: "$$", closing: "$$", display: true });
500
- i = end;
501
- continue;
502
- }
595
+ }
596
+ if (value.startsWith("\\[", i)) {
597
+ const close = value.indexOf("\\]", i + 2);
598
+ if (close >= 0) {
599
+ const end = close + 2;
600
+ return { start: i, end, source: value.slice(i, end), opening: "\\[", closing: "\\]", display: true };
503
601
  }
504
- if (value[i] === "$" && !isEscaped(value, i)) {
505
- const close = findClosingDollar(value, i + 1);
506
- if (close >= 0) {
507
- const end = close + 1;
508
- spans.push({ start: i, end, source: value.slice(i, end), opening: "$", closing: "$", display: false });
509
- i = end;
510
- continue;
511
- }
602
+ }
603
+ if (value.startsWith("$$", i) && !isEscaped(value, i)) {
604
+ const close = value.indexOf("$$", i + 2);
605
+ if (close >= 0) {
606
+ const end = close + 2;
607
+ return { start: i, end, source: value.slice(i, end), opening: "$$", closing: "$$", display: true };
608
+ }
609
+ }
610
+ if (value[i] === "$" && !isEscaped(value, i)) {
611
+ const close = findClosingDollar(value, i + 1);
612
+ if (close >= 0) {
613
+ const end = close + 1;
614
+ return { start: i, end, source: value.slice(i, end), opening: "$", closing: "$", display: false };
615
+ }
616
+ }
617
+ return null;
618
+ }
619
+ function detectMathSpans2(value) {
620
+ return detectInlineSpans2(value).filter((span) => span.kind === "math").map(({ kind: _kind, ...span }) => span);
621
+ }
622
+ function detectInlineSpans2(value) {
623
+ const spans = [];
624
+ let i = 0;
625
+ while (i < value.length) {
626
+ const cite = citeSpan(value, i);
627
+ if (cite) {
628
+ spans.push(cite);
629
+ i = cite.end;
630
+ continue;
631
+ }
632
+ const math = mathSpanAt(value, i);
633
+ if (math) {
634
+ spans.push({ kind: "math", ...math });
635
+ i = math.end;
636
+ continue;
512
637
  }
513
638
  i += 1;
514
639
  }
@@ -545,19 +670,53 @@ function pushDiagnostic(diagnostics, options, path, message) {
545
670
  }
546
671
  diagnostics.push({ code: "math_alignment", message, path });
547
672
  }
673
+ function parseReferences(json) {
674
+ if (!Array.isArray(json)) {
675
+ return [];
676
+ }
677
+ const references = [];
678
+ for (const entry of json) {
679
+ if (!isObject2(entry) || typeof entry.key !== "string" || entry.key.trim().length === 0) {
680
+ continue;
681
+ }
682
+ references.push(
683
+ referenceFromJson({
684
+ key: entry.key.trim(),
685
+ authors: typeof entry.authors === "string" ? entry.authors : void 0,
686
+ title: typeof entry.title === "string" ? entry.title : void 0,
687
+ year: typeof entry.year === "string" ? entry.year : void 0,
688
+ url: typeof entry.url === "string" ? entry.url : void 0,
689
+ venue: typeof entry.venue === "string" ? entry.venue : void 0
690
+ })
691
+ );
692
+ }
693
+ return references;
694
+ }
548
695
  function createInlineField2(value = "", mathObjects = [], options = {}, path = "$", diagnostics = []) {
549
696
  const mode = options.mode ?? "english";
550
- const spans = detectMathSpans2(value);
697
+ const spans = detectInlineSpans2(value);
698
+ const mathSpans = spans.filter((span) => span.kind === "math");
551
699
  const tokens = [];
552
700
  let index = 0;
553
- if (mathObjects.length > 0 && mathObjects.length !== spans.length) {
554
- pushDiagnostic(diagnostics, options, path, `math_objects count mismatch: detected ${String(spans.length)}, got ${String(mathObjects.length)}`);
701
+ let mathObjectIndex = 0;
702
+ if (mathObjects.length > 0 && mathObjects.length !== mathSpans.length) {
703
+ pushDiagnostic(diagnostics, options, path, `math_objects count mismatch: detected ${String(mathSpans.length)}, got ${String(mathObjects.length)}`);
555
704
  }
556
- spans.forEach((span, spanIndex) => {
705
+ for (const span of spans) {
557
706
  if (span.start > index) {
558
707
  tokens.push({ id: document2Id("text"), kind: "text", text: value.slice(index, span.start) });
559
708
  }
560
- const mathJson = mathObjects[spanIndex];
709
+ if (span.kind === "cite") {
710
+ tokens.push({
711
+ id: document2Id("cite"),
712
+ kind: "cite",
713
+ keys: span.keys.length > 0 ? span.keys : []
714
+ });
715
+ index = span.end;
716
+ continue;
717
+ }
718
+ const mathJson = mathObjects[mathObjectIndex];
719
+ mathObjectIndex += 1;
561
720
  if (mathJson && (mathJson.math_mode !== span.opening || mathJson.closing !== span.closing)) {
562
721
  pushDiagnostic(diagnostics, options, path, "math_objects order mismatch");
563
722
  }
@@ -589,7 +748,7 @@ function createInlineField2(value = "", mathObjects = [], options = {}, path = "
589
748
  });
590
749
  }
591
750
  index = span.end;
592
- });
751
+ }
593
752
  if (index < value.length || tokens.length === 0) {
594
753
  tokens.push({ id: document2Id("text"), kind: "text", text: value.slice(index) });
595
754
  }
@@ -661,11 +820,14 @@ function parseTableBlock(json, options, path, diagnostics) {
661
820
  };
662
821
  }
663
822
  function parseImageBlock(json) {
823
+ const assetId = typeof json.asset_id === "string" && json.asset_id.length > 0 ? json.asset_id : void 0;
824
+ const value = assetId !== void 0 ? typeof json.value === "string" ? json.value : "" : requireString(json.value, "\\includegraphics requires string value");
664
825
  return {
665
826
  id: document2Id("block"),
666
827
  kind: "image",
667
828
  command: "\\includegraphics",
668
- value: requireString(json.value, "\\includegraphics requires string value"),
829
+ value,
830
+ ...assetId !== void 0 ? { assetId } : {},
669
831
  options: isRecordOfStrings(json.options) ? json.options : {}
670
832
  };
671
833
  }
@@ -677,6 +839,14 @@ function parseRawBlock(json) {
677
839
  value: typeof json.value === "string" ? json.value : ""
678
840
  };
679
841
  }
842
+ function parseBibliographyBlock() {
843
+ return {
844
+ id: document2Id("block"),
845
+ kind: "bibliography",
846
+ command: "\\begin{thebibliography}",
847
+ closing: "\\end{thebibliography}"
848
+ };
849
+ }
680
850
  function parseBlock(json, options, path, diagnostics) {
681
851
  if (TEXT_COMMANDS.has(json.command)) {
682
852
  return parseTextBlock(json, options, path, diagnostics);
@@ -690,6 +860,9 @@ function parseBlock(json, options, path, diagnostics) {
690
860
  if (json.command === "\\includegraphics") {
691
861
  return parseImageBlock(json);
692
862
  }
863
+ if (json.command === "\\begin{thebibliography}" || json.command === "\\bibliography") {
864
+ return parseBibliographyBlock();
865
+ }
693
866
  if (json.command === "\\raw") {
694
867
  return parseRawBlock(json);
695
868
  }
@@ -710,12 +883,13 @@ function fromDocumentJson2(json, options = {}) {
710
883
  const diagnostics = [];
711
884
  return {
712
885
  nodeType: "DocumentObject",
886
+ references: parseReferences(json.references),
713
887
  blocks: json.blocks.map((block, index) => parseBlock(asBlockJson(block), options, `$.blocks[${String(index)}]`, diagnostics)),
714
888
  diagnostics
715
889
  };
716
890
  }
717
891
  function createEmptyDocument2() {
718
- return { nodeType: "DocumentObject", blocks: [], diagnostics: [] };
892
+ return { nodeType: "DocumentObject", references: [], blocks: [], diagnostics: [] };
719
893
  }
720
894
 
721
895
  // src/editor/atomicCommands.ts
@@ -1819,34 +1993,6 @@ function renderDivideOperatorLatex(side) {
1819
1993
  return side === "arabic" ? "\\backslash" : DIVIDE_OPERATOR_EN;
1820
1994
  }
1821
1995
 
1822
- // src/editor/digits.ts
1823
- var WESTERN = "0123456789";
1824
- var ARABIC_INDIC = "\u0660\u0661\u0662\u0663\u0664\u0665\u0666\u0667\u0668\u0669";
1825
- var PERSIAN_INDIC = "\u06F0\u06F1\u06F2\u06F3\u06F4\u06F5\u06F6\u06F7\u06F8\u06F9";
1826
- var digitSets = {
1827
- western: WESTERN,
1828
- arabicIndic: ARABIC_INDIC,
1829
- persianIndic: PERSIAN_INDIC
1830
- };
1831
- function digitValue(char) {
1832
- const western = WESTERN.indexOf(char);
1833
- if (western >= 0) {
1834
- return western;
1835
- }
1836
- const arabicIndic = ARABIC_INDIC.indexOf(char);
1837
- if (arabicIndic >= 0) {
1838
- return arabicIndic;
1839
- }
1840
- return PERSIAN_INDIC.indexOf(char);
1841
- }
1842
- function formatDigits(value, digitForm = "western") {
1843
- const target = digitSets[digitForm];
1844
- return Array.from(value, (char) => {
1845
- const value2 = digitValue(char);
1846
- return value2 >= 0 ? target[value2] : char;
1847
- }).join("");
1848
- }
1849
-
1850
1996
  // src/editor/render.ts
1851
1997
  function selectedDigitForm(options) {
1852
1998
  return options?.digitForm ?? "western";
@@ -6405,6 +6551,7 @@ function cloneBlock(block) {
6405
6551
  function cloneDocument(document2) {
6406
6552
  return {
6407
6553
  nodeType: "DocumentObject",
6554
+ references: document2.references.map((reference) => ({ ...reference })),
6408
6555
  blocks: document2.blocks.map(cloneBlock),
6409
6556
  diagnostics: document2.diagnostics.map((diagnostic) => ({ ...diagnostic }))
6410
6557
  };
@@ -6687,12 +6834,335 @@ function removeDocument2ListItem(document2, listBlockId, itemId) {
6687
6834
  });
6688
6835
  return next;
6689
6836
  }
6837
+ function citeTokenFromKeys(keys) {
6838
+ return { id: document2Id("cite"), kind: "cite", keys: [...keys] };
6839
+ }
6840
+ function insertCiteTokenAtCaret(document2, fieldId, textTokenId, caretOffset, keys) {
6841
+ if (keys.length === 0) {
6842
+ return document2;
6843
+ }
6844
+ const next = cloneDocument(document2);
6845
+ const citeToken = citeTokenFromKeys(keys);
6846
+ visitFields(next.blocks, (field) => {
6847
+ if (field.id !== fieldId) {
6848
+ return false;
6849
+ }
6850
+ const textIndex = textTokenId ? field.tokens.findIndex((token) => token.id === textTokenId && token.kind === "text") : field.tokens.findIndex((token) => token.kind === "text");
6851
+ if (textIndex < 0) {
6852
+ field.tokens.push(citeToken);
6853
+ field.tokens.push({ id: document2Id("text"), kind: "text", text: "" });
6854
+ return true;
6855
+ }
6856
+ const current = field.tokens[textIndex];
6857
+ const [before, after] = splitTextTokenAt(current, caretOffset);
6858
+ const parts = [...field.tokens.slice(0, textIndex)];
6859
+ if (before.text.length > 0) {
6860
+ parts.push(before);
6861
+ }
6862
+ parts.push(citeToken);
6863
+ parts.push(after);
6864
+ parts.push(...field.tokens.slice(textIndex + 1));
6865
+ field.tokens = normalizeFieldTokens(parts);
6866
+ return true;
6867
+ });
6868
+ return next;
6869
+ }
6870
+ function updateCiteTokenKeys(document2, tokenId, keys) {
6871
+ if (keys.length === 0) {
6872
+ return document2;
6873
+ }
6874
+ const next = cloneDocument(document2);
6875
+ visitFields(next.blocks, (field) => {
6876
+ const token = field.tokens.find((entry) => entry.id === tokenId && entry.kind === "cite");
6877
+ if (!token) {
6878
+ return false;
6879
+ }
6880
+ token.keys = [...keys];
6881
+ return true;
6882
+ });
6883
+ return next;
6884
+ }
6885
+ function removeCiteTokenById(document2, tokenId) {
6886
+ const next = cloneDocument(document2);
6887
+ visitFields(next.blocks, (field) => {
6888
+ const index = field.tokens.findIndex((token) => token.id === tokenId && token.kind === "cite");
6889
+ if (index < 0) {
6890
+ return false;
6891
+ }
6892
+ field.tokens = normalizeFieldTokens(stitchTextAroundRemovedToken(field.tokens, index));
6893
+ return true;
6894
+ });
6895
+ return next;
6896
+ }
6897
+ function ensureDocument2BibliographyBlock(document2, afterBlockId) {
6898
+ if (document2.blocks.some((block2) => block2.kind === "bibliography")) {
6899
+ return document2;
6900
+ }
6901
+ const block = {
6902
+ id: document2Id("block"),
6903
+ kind: "bibliography",
6904
+ command: "\\begin{thebibliography}",
6905
+ closing: "\\end{thebibliography}"
6906
+ };
6907
+ return insertDocument2BlockAfter(document2, afterBlockId ?? null, block);
6908
+ }
6909
+ function addDocument2Reference(document2, partial = {}) {
6910
+ const next = cloneDocument(document2);
6911
+ next.references.push(createEmptyReference2(partial));
6912
+ return next;
6913
+ }
6914
+ function updateDocument2Reference(document2, referenceId, patch) {
6915
+ const next = cloneDocument(document2);
6916
+ const reference = next.references.find((entry) => entry.id === referenceId);
6917
+ if (!reference) {
6918
+ return document2;
6919
+ }
6920
+ if (typeof patch.key === "string" && patch.key.trim().length > 0) {
6921
+ reference.key = patch.key.trim();
6922
+ }
6923
+ if (typeof patch.authors === "string") {
6924
+ reference.authors = patch.authors;
6925
+ }
6926
+ if (typeof patch.title === "string") {
6927
+ reference.title = patch.title;
6928
+ }
6929
+ if (typeof patch.year === "string") {
6930
+ reference.year = patch.year;
6931
+ }
6932
+ if (typeof patch.url === "string") {
6933
+ reference.url = patch.url;
6934
+ }
6935
+ if (typeof patch.venue === "string") {
6936
+ reference.venue = patch.venue;
6937
+ }
6938
+ return next;
6939
+ }
6940
+ function removeDocument2Reference(document2, referenceId) {
6941
+ const next = cloneDocument(document2);
6942
+ next.references = next.references.filter((reference) => reference.id !== referenceId);
6943
+ return next;
6944
+ }
6945
+ function moveDocument2Reference(document2, referenceId, direction) {
6946
+ const next = cloneDocument(document2);
6947
+ const index = next.references.findIndex((reference2) => reference2.id === referenceId);
6948
+ const targetIndex = index + direction;
6949
+ if (index < 0 || targetIndex < 0 || targetIndex >= next.references.length) {
6950
+ return document2;
6951
+ }
6952
+ const [reference] = next.references.splice(index, 1);
6953
+ if (!reference) {
6954
+ return document2;
6955
+ }
6956
+ next.references.splice(targetIndex, 0, reference);
6957
+ return next;
6958
+ }
6959
+
6960
+ // src/document2/arabicPreamble.ts
6961
+ function arabicXeLatexPreamblePkg() {
6962
+ return String.raw`
6963
+ \documentclass[12pt,a4paper]{article}
6964
+ \usepackage{amsmath,amsfonts,amssymb,mathrsfs,tikz,fancyhdr, mathtools}
6965
+ \usepackage{fontspec} % For loading OpenType fonts
6966
+ \usepackage{unicode-math} % For setting the math font
6967
+ \usepackage{polyglossia} % For Arabic support
6968
+ \usepackage{array}
6969
+ \usepackage{cancel}
6970
+ \usepackage{bidi} % For bidirectional text handling
6971
+ \usepackage{multirow}
6972
+ \usepackage{booktabs}
6973
+ \usepackage{graphicx} % For \reflectbox
6974
+ \usepackage{xcolor}
6975
+ \usepackage{tikz}
6976
+ \usepackage{tcolorbox} % For tcolorbox environment
6977
+ \usepackage{textcomp} % For \textrightarrow command
6978
+
6979
+
6980
+ % visit : https://www.symbolcopy.com/punctuation-symbol.html
6981
+ % for inversed punctuation
6982
+
6983
+ % save inverted comma for use - copy paste -> ،
6984
+ % save back tick for use - copy paste -> ` + "`";
6985
+ }
6986
+ function arabicXeLatexPreambleFont(digitsMapping = "arabicdigits") {
6987
+ return `
6988
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6989
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
6990
+ % Toggle between eastern and western digits by changing the Mapping in the below fonts (inside math font as well) between "arabicdigits" and "digits"
6991
+ \\setdefaultlanguage[calendar=gregorian]{arabic} % from polyglossia
6992
+ \\setmainfont[Script=Arabic , Mapping=${digitsMapping}]{Amiri}
6993
+ \\newfontfamily\\diwani[Script=Arabic,Mapping=${digitsMapping}]{Diwani Letter}
6994
+ \\newfontfamily\\diwanioutlineshaded[Script=Arabic,Mapping=${digitsMapping}]{Diwani Outline Shaded}
6995
+ \\newfontfamily\\takween[Script=Arabic,Mapping=${digitsMapping}]{Takween}
6996
+ \\newfontfamily\\boldarabic[Script=Arabic,Mapping=${digitsMapping}]{Amiri Bold}
6997
+ \\newfontfamily\\italicarabic[Script=Arabic,Mapping=${digitsMapping}]{Amiri Italic}
6998
+
6999
+ % Explicitly set math font to XITS Math
7000
+ % Remove "Script=Arabic" to cancel reflected symbols and other RTL symbols
7001
+ \\setmathfont[Script=Arabic , Mapping=${digitsMapping}]{XITS Math} % Ensure XITS Math is correctly installed and available
7002
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7003
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7004
+ `;
7005
+ }
7006
+ function arabicXeLatexPreambleCmd() {
7007
+ return String.raw`
7008
+ % Run with XeLaTeX compiler
7009
+ \newcommand{\butextakween}[1]{\text{\takween{#1}}}
7010
+ \newcommand{\butexdiwani}[1]{\text{\diwani{#1}}}
7011
+ \newcommand{\butexdiwanioutline}[1]{\text{\diwanioutlineshaded{#1}}}
7012
+
7013
+ \newcommand{\arabN}{\text{\diwanioutlineshaded{ط}}}
7014
+ \newcommand{\arabZ}{\text{\diwanioutlineshaded{ص}}}
7015
+ \newcommand{\arabQ}{\text{\diwanioutlineshaded{ن}}}
7016
+ \newcommand{\arabR}{\text{\diwanioutlineshaded{ح}}}
7017
+ \newcommand{\arabC}{\text{\diwanioutlineshaded{ع}}}
7018
+ \newcommand{\arabH}{\text{\diwanioutlineshaded{ر}}}
7019
+
7020
+
7021
+ \newcommand{\lowerscript}[1]{\raisebox{-4pt}{\scriptsize #1}}
7022
+ \newcommand{\llowerscript}[1]{\raisebox{-8pt}{\scriptsize #1}}
7023
+ \newcommand{\lllowerscript}[2]{\raisebox{#2pt}{\scriptsize #1}}
7024
+
7025
+ \newcommand{\arabdsub}[3]{\prescript{}{#1}{\prescript{}{#2}{#3}}} % arabic double subscript
7026
+ \newcommand{\arabsub}[2]{\prescript{}{#1}{#2}} % arabic single subscript
7027
+
7028
+
7029
+
7030
+ \newcommand{\upperscript}[1]{\raisebox{8pt}{\scriptsize #1}}
7031
+ \newcommand{\uupperscript}[2]{\raisebox{#2pt}{\scriptsize #1}}
7032
+ \newcommand{\vertbar}{\rule[-1ex]{0.5pt}{2.5ex}}
7033
+ \newcommand{\horzbar}{\rule[.5ex]{2.5ex}{0.5pt}}
7034
+
7035
+ \newcommand{\arabsqrt}[2]{\reflectbox{\(\sqrt[\reflectbox{\(#1\)}]{\reflectbox{\(#2\)}}\)}}
7036
+ \newcommand{\arabvec}[1]{\reflectbox{$\vec{\reflectbox{$#1$}}$}}
7037
+
7038
+ \newcommand{\arabexp}[1]{{}^{#1}\!\raisebox{-4.5pt}{\text{\diwani{ه}}}}
7039
+ \newcommand{\arablog}[2]{\left(\text{#2}\right)\!\prescript{}{\text{#1}}{\text{\diwani{لو}}}}
7040
+ \newcommand{\arabnlog}[1]{\left(\text{#1}\right)\!\prescript{}{\text{\diwani{ه}}}{\text{\diwani{لو}}}}
7041
+
7042
+ \newcommand{\arabcos}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{جتا}}}}
7043
+ \newcommand{\arabsin}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{جا}}}}
7044
+ \newcommand{\arabtan}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{ظا}}}}
7045
+ \newcommand{\arabcot}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{ظتا}}}}
7046
+ \newcommand{\arabsec}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قا}}}}
7047
+ \newcommand{\arabcsc}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قتا}}}}
7048
+
7049
+ \newcommand{\arabacos}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قجتا}}}}
7050
+ \newcommand{\arabasin}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قجا}}}}
7051
+ \newcommand{\arabatan}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قظا}}}}
7052
+ \newcommand{\arabacot}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{قظتا}}}}
7053
+ \newcommand{\arabasec}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{ققا}}}}
7054
+ \newcommand{\arabacsc}[1]{\left(#1\right)\!\!\raisebox{-2.5pt}{\text{\diwani{ققتا}}}}
7055
+
7056
+
7057
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7058
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7059
+ % summation
7060
+ \newcommand{\arablim}[2]{\underset{#2 \leftarrow #1}{\text{نـــــها}}}
7061
+ \newcommand{\arabsum}[2]{\underset{#1}{\overset{#2}{\text{مجـــ}}}}
7062
+ \newcommand{\arabprod}[2]{\underset{#1}{\overset{#2}{\text{جـــذ}}}}
7063
+ \newcommand{\arabint}[2]{\prescript{#2}{#1\!\!\!}\int}
7064
+
7065
+
7066
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7067
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7068
+ % we define this command to make it ease for change of notation later
7069
+ \newcommand{\ad}[0]{\text{ء}} % "ad" for arabic differentiation or derivative (ء" لإشتقاق")
7070
+ \newcommand{\arpi}[0]{\!\text{\diwani{ط}}}
7071
+
7072
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7073
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7074
+ % differentials
7075
+
7076
+ \newcommand{\arabdiff}[2]{\frac{#1\ad}{#2\ad}} % arabic differential
7077
+ \newcommand{\arabddiff}[2]{\frac{#1{}^{2}\ad}{{}^{2}#2\ad}} % arabic second differential
7078
+
7079
+ \newcommand{\arabode}[2][-5pt]{\stackrel{\raisebox{#1}{$\cdot$}}{\text{#2}}}
7080
+ \newcommand{\arabodde}[2][-5pt]{\stackrel{\raisebox{#1}{$\vcenter{\hbox{$\cdot\!\cdot$}}$}}{\text{#2}}}
7081
+ \newcommand{\araboddde}[2][-5pt]{\stackrel{\raisebox{#1}{$\vcenter{\hbox{$\cdot\!\cdot\!\cdot$}}$}}{\text{#2}}}
7082
+ \newcommand{\arabpde}[1]{\prescript{}{#1\!\!}{\nabla}} % arabic partial differential equation (PDE)
7083
+
7084
+ \newcommand{\arabprime}[0]{\reflectbox{$\prime$}\!} % arabic prime notation
7085
+ \newcommand{\arabpprime}[0]{\reflectbox{$\prime$}\reflectbox{$\prime$}\!} % arabic prime notation
7086
+ \newcommand{\arabppprime}[0]{\reflectbox{$\prime$}\reflectbox{$\prime$}\reflectbox{$\prime$}\!} % arabic prime notation
7087
+
7088
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7089
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7090
+ % probability
7091
+ \newcommand{\ap}[0]{\!\text{\diwani{حـ}}} % arabic Probability - used a lot so short form
7092
+ \newcommand{\arabExpct}[0]{\text{\diwani{توقـ}}} % arabic Expectation
7093
+ \newcommand{\arabVar}[0]{\!\text{\diwani{با}}} % arabic Variance
7094
+ \newcommand{\arabCov}[0]{\!\text{\diwani{ت}}} % arabic Covariance
7095
+
7096
+
7097
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7098
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7099
+ % custom commands specific to lesson
7100
+ \newcommand{\lagrange}[2]{\left(#2\right)\!\prescript{}{#1}{\text{\diwani{لا}}}}
7101
+ \newcommand{\xii}[0]{\left(\prescript{}{\text{يـ}}{\text{س}}\right)\!}
7102
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7103
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7104
+
7105
+
7106
+ \newcommand{\arsqrt}[2][]{\reflectbox{\(\sqrt[\reflectbox{\(#1\)}]{\reflectbox{\(#2\)}}\)}}
7107
+ \newcommand{\arexp}[0]{\!\raisebox{-4.5pt}{\text{\diwani{ه}}}}
7108
+ \newcommand{\arlog}[0]{\!\!\text{\diwani{لو}}}
7109
+ \newcommand{\arln}[0]{\!\!\prescript{}{\text{\diwani{ه}}}{\text{\diwani{لو}}}}
7110
+ \newcommand{\ardet}[0]{\!\!\text{\diwani{محدد}}}
7111
+
7112
+ \newcommand{\arsum}[0]{\text{مجـــ}}
7113
+ \newcommand{\arprod}[0]{\text{جـــذ}}
7114
+
7115
+ \newcommand{\arlim}[0]{\text{نـــــها}}
7116
+ \newcommand{\armax}[0]{\text{أكبر}}
7117
+ \newcommand{\armin}[0]{\text{أصغر}}
7118
+ \newcommand{\arsup}[0]{\text{أعلى}}
7119
+ \newcommand{\arinf}[0]{\text{أدنى}}
7120
+
7121
+ \newcommand{\arsin}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{جا}}}}
7122
+ \newcommand{\arcos}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{جتا}}}}
7123
+ \newcommand{\artan}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ظا}}}}
7124
+ \newcommand{\arcot}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ظتا}}}}
7125
+ \newcommand{\arsec}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قا}}}}
7126
+ \newcommand{\arcsc}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قتا}}}}
7127
+
7128
+ \newcommand{\arasin}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قجا}}}}
7129
+ \newcommand{\aracos}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قجتا}}}}
7130
+ \newcommand{\aratan}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قظا}}}}
7131
+ \newcommand{\aracot}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قظتا}}}}
7132
+ \newcommand{\arasec}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ققا}}}}
7133
+ \newcommand{\aracsc}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ققتا}}}}
7134
+
7135
+ \newcommand{\arsinh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{جزا}}}}
7136
+ \newcommand{\arcosh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{جتزا}}}}
7137
+ \newcommand{\artanh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ظزا}}}}
7138
+ \newcommand{\arcoth}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ظتزا}}}}
7139
+ \newcommand{\arsech}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قزا}}}}
7140
+ \newcommand{\arcsch}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قتزا}}}}
7141
+
7142
+ \newcommand{\arasinh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قجزا}}}}
7143
+ \newcommand{\aracosh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قجتزا}}}}
7144
+ \newcommand{\aratanh}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قظزا}}}}
7145
+ \newcommand{\aracoth}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{قظتزا}}}}
7146
+ \newcommand{\arasech}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ققزا}}}}
7147
+ \newcommand{\aracsch}[0]{\!\!\raisebox{-2.5pt}{\text{\diwani{ققتزا}}}}
7148
+
7149
+ \newcommand{\unit}[1]{\text{#1}}
7150
+ \newcommand{\idx}[1]{#1}
7151
+ \newcommand{\arbinom}[2]{\left(\begin{array}{c} #1 \\ #2 \end{array} \right)}
7152
+ `;
7153
+ }
7154
+ function getArabicXeLatexPreamble(digitsMapping = "arabicdigits") {
7155
+ return arabicXeLatexPreamblePkg() + arabicXeLatexPreambleFont(digitsMapping) + arabicXeLatexPreambleCmd();
7156
+ }
6690
7157
 
6691
7158
  // src/document2/exportLatex.ts
6692
7159
  function tokenLatex(token) {
6693
7160
  if (token.kind === "text") {
6694
7161
  return token.text;
6695
7162
  }
7163
+ if (token.kind === "cite") {
7164
+ return citeTokenLatex(token.keys);
7165
+ }
6696
7166
  if (!token.math || token.sourceOwner === "raw" || token.sourceOwner === "editor") {
6697
7167
  return token.source;
6698
7168
  }
@@ -6707,9 +7177,9 @@ function textBlockLatex(block) {
6707
7177
  function indent(value) {
6708
7178
  return value.split("\n").map((line) => ` ${line}`).join("\n");
6709
7179
  }
6710
- function listBlockLatex(block) {
7180
+ function listBlockLatex(block, references) {
6711
7181
  const items = block.items.map((item) => {
6712
- const nested = item.blocks.map((child) => "\n" + indent(blockLatex(child))).join("");
7182
+ const nested = item.blocks.map((child) => "\n" + indent(blockLatex(child, references))).join("");
6713
7183
  return ` \\item ${inlineFieldLatex(item.field)}${nested}`;
6714
7184
  }).join("\n");
6715
7185
  return `${block.command}
@@ -6729,12 +7199,12 @@ function imageOptionsLatex(block) {
6729
7199
  }
6730
7200
  return `[${entries.map(([key, value]) => `${key}=${value}`).join(",")}]`;
6731
7201
  }
6732
- function blockLatex(block) {
7202
+ function blockLatex(block, references) {
6733
7203
  if (block.kind === "textBlock") {
6734
7204
  return textBlockLatex(block);
6735
7205
  }
6736
7206
  if (block.kind === "list") {
6737
- return listBlockLatex(block);
7207
+ return listBlockLatex(block, references);
6738
7208
  }
6739
7209
  if (block.kind === "table") {
6740
7210
  return tableBlockLatex(block);
@@ -6742,10 +7212,29 @@ function blockLatex(block) {
6742
7212
  if (block.kind === "image") {
6743
7213
  return `${block.command}${imageOptionsLatex(block)}{${block.value}}`;
6744
7214
  }
7215
+ if (block.kind === "bibliography") {
7216
+ const width = String(Math.max(references.length, 9));
7217
+ const items = references.map((reference) => ` ${bibliographyEntryLatex(reference)}`).join("\n");
7218
+ return `${block.command}{${width}}
7219
+ ${items}
7220
+ ${block.closing}`;
7221
+ }
6745
7222
  return block.value;
6746
7223
  }
6747
- function document2Latex(document2) {
6748
- return document2.blocks.map((block) => blockLatex(block)).join("\n\n");
7224
+ function document2Latex(document2, options = {}) {
7225
+ const body = document2.blocks.map((block) => blockLatex(block, document2.references)).join("\n\n");
7226
+ const wrapDocument = options.wrapDocument !== false;
7227
+ if (!wrapDocument) {
7228
+ return body;
7229
+ }
7230
+ const preamble = getArabicXeLatexPreamble(options.digitsMapping ?? "arabicdigits");
7231
+ return `${preamble}
7232
+ \\begin{document}
7233
+
7234
+ ${body}
7235
+
7236
+ \\end{document}
7237
+ `;
6749
7238
  }
6750
7239
 
6751
7240
  // src/document2/history.ts
@@ -6783,16 +7272,24 @@ function document2HistoryCanRedo(stacks) {
6783
7272
 
6784
7273
  // src/document2/previewModel.ts
6785
7274
  function mathTex(token, equationSide) {
6786
- if (token.kind === "text") {
6787
- return token.text;
6788
- }
6789
7275
  return mathTokenSourceForSide(token, equationSide);
6790
7276
  }
6791
- function previewInlines(field, islands, output, equationSide) {
7277
+ function previewInlines(field, islands, output, equationSide, document2, previewOptions) {
6792
7278
  return field.tokens.map((token) => {
6793
7279
  if (token.kind === "text") {
6794
7280
  return { kind: "text", text: token.text };
6795
7281
  }
7282
+ if (token.kind === "cite") {
7283
+ return {
7284
+ kind: "cite",
7285
+ id: token.id,
7286
+ keys: [...token.keys],
7287
+ label: formatCiteLabel(token.keys, document2.references, {
7288
+ documentDirection: previewOptions.documentDirection,
7289
+ digitForm: previewOptions.digitForm
7290
+ })
7291
+ };
7292
+ }
6796
7293
  const island = {
6797
7294
  id: token.id,
6798
7295
  tex: mathTex(token, equationSide),
@@ -6804,21 +7301,22 @@ function previewInlines(field, islands, output, equationSide) {
6804
7301
  return { kind: "math", ...island };
6805
7302
  });
6806
7303
  }
6807
- function textBlockPreview(block, islands, output, equationSide) {
7304
+ function textBlockPreview(block, islands, output, equationSide, document2, previewOptions) {
7305
+ const inlines = previewInlines(block.field, islands, output, equationSide, document2, previewOptions);
6808
7306
  if (block.command === "\\section") {
6809
- return { kind: "heading", id: block.id, level: 1, inlines: previewInlines(block.field, islands, output, equationSide) };
7307
+ return { kind: "heading", id: block.id, level: 1, inlines };
6810
7308
  }
6811
7309
  if (block.command === "\\subsection") {
6812
- return { kind: "heading", id: block.id, level: 2, inlines: previewInlines(block.field, islands, output, equationSide) };
7310
+ return { kind: "heading", id: block.id, level: 2, inlines };
6813
7311
  }
6814
7312
  if (block.command === "\\subsubsection") {
6815
- return { kind: "heading", id: block.id, level: 3, inlines: previewInlines(block.field, islands, output, equationSide) };
7313
+ return { kind: "heading", id: block.id, level: 3, inlines };
6816
7314
  }
6817
- return { kind: "paragraph", id: block.id, inlines: previewInlines(block.field, islands, output, equationSide) };
7315
+ return { kind: "paragraph", id: block.id, inlines };
6818
7316
  }
6819
- function blockPreview(block, islands, output, equationSide) {
7317
+ function blockPreview(block, islands, output, equationSide, document2, previewOptions) {
6820
7318
  if (block.kind === "textBlock") {
6821
- return textBlockPreview(block, islands, output, equationSide);
7319
+ return textBlockPreview(block, islands, output, equationSide, document2, previewOptions);
6822
7320
  }
6823
7321
  if (block.kind === "list") {
6824
7322
  return {
@@ -6827,23 +7325,56 @@ function blockPreview(block, islands, output, equationSide) {
6827
7325
  ordered: block.command === "\\begin{enumerate}",
6828
7326
  items: block.items.map((item) => ({
6829
7327
  id: item.id,
6830
- inlines: previewInlines(item.field, islands, output, equationSide),
6831
- blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide))
7328
+ inlines: previewInlines(item.field, islands, output, equationSide, document2, previewOptions),
7329
+ blocks: item.blocks.map((child) => blockPreview(child, islands, output, equationSide, document2, previewOptions))
6832
7330
  }))
6833
7331
  };
6834
7332
  }
6835
7333
  if (block.kind === "table") {
6836
- return { kind: "table", id: block.id, rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide))) };
7334
+ return {
7335
+ kind: "table",
7336
+ id: block.id,
7337
+ rows: block.rows.map((row) => row.map((cell) => previewInlines(cell, islands, output, equationSide, document2, previewOptions)))
7338
+ };
6837
7339
  }
6838
7340
  if (block.kind === "image") {
6839
- return { kind: "image", id: block.id, src: block.value, options: block.options };
7341
+ return {
7342
+ kind: "image",
7343
+ id: block.id,
7344
+ src: block.value,
7345
+ ...block.assetId !== void 0 ? { assetId: block.assetId } : {},
7346
+ options: block.options
7347
+ };
7348
+ }
7349
+ if (block.kind === "bibliography") {
7350
+ return {
7351
+ kind: "bibliography",
7352
+ id: block.id,
7353
+ items: document2.references.map((reference, index) => ({
7354
+ id: reference.id,
7355
+ numberLabel: formatBibliographyNumber(index + 1, {
7356
+ documentDirection: previewOptions.documentDirection,
7357
+ digitForm: previewOptions.digitForm
7358
+ }),
7359
+ key: reference.key,
7360
+ authors: reference.authors,
7361
+ title: reference.title,
7362
+ year: reference.year,
7363
+ url: reference.url,
7364
+ venue: reference.venue
7365
+ }))
7366
+ };
6840
7367
  }
6841
7368
  return { kind: "omit", id: block.id };
6842
7369
  }
6843
- function document2Preview(document2, output = "svg", equationSide = "arabic") {
7370
+ function document2Preview(document2, output = "svg", equationSide = "arabic", previewOptions = {}) {
6844
7371
  const mathIslands = [];
7372
+ const options = {
7373
+ documentDirection: previewOptions.documentDirection ?? "rtl",
7374
+ digitForm: previewOptions.digitForm ?? (previewOptions.documentDirection === "ltr" ? "western" : "arabicIndic")
7375
+ };
6845
7376
  return {
6846
- blocks: document2.blocks.map((block) => blockPreview(block, mathIslands, output, equationSide)),
7377
+ blocks: document2.blocks.map((block) => blockPreview(block, mathIslands, output, equationSide, document2, options)),
6847
7378
  mathIslands
6848
7379
  };
6849
7380
  }
@@ -6851,19 +7382,282 @@ function document2Preview(document2, output = "svg", equationSide = "arabic") {
6851
7382
  // src/react-document2/InlineField.tsx
6852
7383
  var import_react2 = require("react");
6853
7384
 
6854
- // src/react-document2/MathIsland.tsx
6855
- var import_react = require("react");
6856
-
6857
- // src/mathjax/svgPatcher.ts
6858
- var SVG_ARABSQRT_SELECTOR = 'mjx-container[jax="SVG"] svg .mjx-rtl-mirror[data-mjx-rtl-root="true"]';
6859
- var ARABSQRT_SELECTOR = '.mjx-rtl-mirror[data-mjx-rtl-root="true"]';
6860
- var PATCHED_ATTR = "data-butex-svg-arabsqrt";
6861
- var ROOT_INDEX_SCALE = 0.72;
6862
- var ROOT_INDEX_GAP_FACTOR = 0.08;
6863
- var ROOT_INDEX_MIN_GAP = 2;
6864
- var ROOT_INDEX_Y_RAISE = 18;
6865
- var ROOT_INDEX_LEFT_SHIFT = 360;
6866
- var VIEWBOX_PADDING = 20;
7385
+ // src/react-document2/uiMessages.ts
7386
+ var DOCUMENT2_MESSAGES = {
7387
+ ar: {
7388
+ undoRedo: "\u062A\u0631\u0627\u062C\u0639 \u0648\u0625\u0639\u0627\u062F\u0629",
7389
+ undo: "\u062A\u0631\u0627\u062C\u0639",
7390
+ redo: "\u0625\u0639\u0627\u062F\u0629",
7391
+ structure: "\u0647\u064A\u0643\u0644",
7392
+ content: "\u0645\u062D\u062A\u0648\u0649",
7393
+ addSection: "\u0625\u0636\u0627\u0641\u0629 \u0642\u0633\u0645",
7394
+ addSubsection: "\u0625\u0636\u0627\u0641\u0629 \u0641\u0631\u0639",
7395
+ addSubsubsection: "\u0625\u0636\u0627\u0641\u0629 \u0641\u0631\u0639 \u0635\u063A\u064A\u0631",
7396
+ addParagraph: "\u0625\u0636\u0627\u0641\u0629 \u0641\u0642\u0631\u0629",
7397
+ inlineEquation: "\u0645\u0639\u0627\u062F\u0644\u0629 \u062F\u0627\u062E\u0644 \u0627\u0644\u0633\u0637\u0631",
7398
+ displayEquation: "\u0645\u0639\u0627\u062F\u0644\u0629 \u0645\u0639\u0631\u0648\u0636\u0629",
7399
+ bulletedList: "\u0642\u0627\u0626\u0645\u0629 \u0646\u0642\u0637\u064A\u0629",
7400
+ numberedList: "\u0642\u0627\u0626\u0645\u0629 \u0645\u0631\u0642\u0645\u0629",
7401
+ insertImage: "\u0625\u062F\u0631\u0627\u062C \u0635\u0648\u0631\u0629",
7402
+ insertTable: "\u0625\u062F\u0631\u0627\u062C \u062C\u062F\u0648\u0644",
7403
+ tableSize: "\u062D\u062C\u0645 \u0627\u0644\u062C\u062F\u0648\u0644",
7404
+ rows: "\u0635\u0641\u0648\u0641",
7405
+ columns: "\u0623\u0639\u0645\u062F\u0629",
7406
+ insert: "\u0625\u062F\u0631\u0627\u062C",
7407
+ panels: "\u0627\u0644\u0644\u0648\u062D\u0627\u062A",
7408
+ hideEditor: "\u0625\u062E\u0641\u0627\u0621 \u0627\u0644\u062A\u062D\u0631\u064A\u0631",
7409
+ editor: "\u062A\u062D\u0631\u064A\u0631",
7410
+ hidePreview: "\u0625\u062E\u0641\u0627\u0621 \u0627\u0644\u0645\u0639\u0627\u064A\u0646\u0629",
7411
+ preview: "\u0645\u0639\u0627\u064A\u0646\u0629",
7412
+ collapseBlocks: "\u0637\u064A \u0627\u0644\u0643\u062A\u0644",
7413
+ collapseAll: "\u0637\u064A \u0627\u0644\u0643\u0644",
7414
+ openAll: "\u0641\u062A\u062D \u0627\u0644\u0643\u0644",
7415
+ documentEditor: "\u062A\u062D\u0631\u064A\u0631 \u0627\u0644\u0645\u0633\u062A\u0646\u062F",
7416
+ documentPreview: "\u0645\u0639\u0627\u064A\u0646\u0629 \u0627\u0644\u0645\u0633\u062A\u0646\u062F",
7417
+ importWarnings: "\u062A\u0646\u0628\u064A\u0647\u0627\u062A \u0627\u0644\u0627\u0633\u062A\u064A\u0631\u0627\u062F (\u0648\u0636\u0639 \u0627\u0644\u062A\u0637\u0648\u064A\u0631)",
7418
+ emptyDocument: "\u0627\u0644\u0645\u0633\u062A\u0646\u062F \u0641\u0627\u0631\u063A",
7419
+ text: "\u0646\u0635",
7420
+ editEquation: "\u062A\u062D\u0631\u064A\u0631 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629",
7421
+ rawEquation: "\u0645\u0639\u0627\u062F\u0644\u0629 \u062E\u0627\u0645",
7422
+ deleteEquation: "\u062D\u0630\u0641 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629",
7423
+ equationUnavailable: "\u0647\u0630\u0647 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629 \u063A\u064A\u0631 \u0645\u062A\u0627\u062D\u0629 \u0644\u0644\u062A\u062D\u0631\u064A\u0631 \u062D\u0627\u0644\u064A\u0627",
7424
+ closeEquationDialog: "\u0625\u063A\u0644\u0627\u0642 \u0646\u0627\u0641\u0630\u0629 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629",
7425
+ equationEditorTitle: "\u062A\u062D\u0631\u064A\u0631 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629",
7426
+ close: "\u0625\u063A\u0644\u0627\u0642",
7427
+ equationType: "\u0646\u0648\u0639 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629",
7428
+ inline: "\u062F\u0627\u062E\u0644 \u0627\u0644\u0633\u0637\u0631",
7429
+ displayed: "\u0645\u0639\u0631\u0648\u0636\u0629",
7430
+ saveEquation: "\u062D\u0641\u0638 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629",
7431
+ section: "\u0642\u0633\u0645",
7432
+ subsection: "\u0641\u0631\u0639",
7433
+ subsubsection: "\u0641\u0631\u0639 \u0635\u063A\u064A\u0631",
7434
+ paragraph: "\u0641\u0642\u0631\u0629",
7435
+ list: "\u0642\u0627\u0626\u0645\u0629",
7436
+ table: "\u062C\u062F\u0648\u0644",
7437
+ image: "\u0635\u0648\u0631\u0629",
7438
+ raw: "\u062E\u0627\u0645",
7439
+ bibliography: "\u0627\u0644\u0645\u0631\u0627\u062C\u0639",
7440
+ openBlock: "\u0641\u062A\u062D \u0627\u0644\u0643\u062A\u0644\u0629",
7441
+ collapseBlock: "\u0637\u064A \u0627\u0644\u0643\u062A\u0644\u0629",
7442
+ moveUp: "\u0646\u0642\u0644 \u0644\u0623\u0639\u0644\u0649",
7443
+ moveDown: "\u0646\u0642\u0644 \u0644\u0623\u0633\u0641\u0644",
7444
+ deleteBlock: "\u062D\u0630\u0641 \u0627\u0644\u0643\u062A\u0644\u0629",
7445
+ item: "\u0639\u0646\u0635\u0631",
7446
+ deleteItem: "\u062D\u0630\u0641 \u0627\u0644\u0639\u0646\u0635\u0631",
7447
+ addItem: "\u0639\u0646\u0635\u0631",
7448
+ imagePath: "\u0645\u0633\u0627\u0631 \u0627\u0644\u0645\u0644\u0641 (\\includegraphics)",
7449
+ imagePathLabel: "\u0645\u0633\u0627\u0631 \u0627\u0644\u0635\u0648\u0631\u0629",
7450
+ loadDocumentError: "\u062A\u0639\u0630\u0631 \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u0633\u062A\u0646\u062F",
7451
+ importOrderMismatch: "\u062A\u0631\u062A\u064A\u0628 \u0623\u0648 \u0623\u0646\u0648\u0627\u0639 \u0627\u0644\u0645\u062D\u062F\u062F\u0627\u062A \u0641\u064A math_objects \u0644\u0627 \u062A\u0637\u0627\u0628\u0642 \u0645\u0627 \u0648\u0631\u062F \u0641\u064A \u0627\u0644\u0646\u0635.",
7452
+ importCountMismatch: "\u0639\u062F\u0645 \u062A\u0637\u0627\u0628\u0642 \u0628\u064A\u0646 \u0627\u0644\u0645\u0648\u0627\u0636\u0639 \u0627\u0644\u0631\u064A\u0627\u0636\u064A\u0629 \u0627\u0644\u0645\u0633\u062A\u062E\u0631\u062C\u0629 \u0645\u0646 \u0627\u0644\u0646\u0635 \u0648\u0639\u062F\u062F \u0639\u0646\u0627\u0635\u0631 math_objects.",
7453
+ importWarning: "\u062A\u0646\u0628\u064A\u0647 \u0627\u0644\u0627\u0633\u062A\u064A\u0631\u0627\u062F",
7454
+ path: "\u0627\u0644\u0645\u0633\u0627\u0631",
7455
+ sectionGlyph: "\u0642",
7456
+ subsectionGlyph: "\u0641",
7457
+ subsubsectionGlyph: "\u0635",
7458
+ paragraphGlyph: "\u0623\u0628\u062C",
7459
+ insertCitation: "\u0625\u062F\u0631\u0627\u062C \u0627\u0642\u062A\u0628\u0627\u0633",
7460
+ insertBibliography: "\u0625\u062F\u0631\u0627\u062C \u0642\u0627\u0626\u0645\u0629 \u0627\u0644\u0645\u0631\u0627\u062C\u0639",
7461
+ manageReferences: "\u0625\u062F\u0627\u0631\u0629 \u0627\u0644\u0645\u0631\u0627\u062C\u0639",
7462
+ citePickerTitle: "\u0627\u062E\u062A\u064A\u0627\u0631 \u0627\u0644\u0645\u0631\u0627\u062C\u0639",
7463
+ noReferencesYet: "\u0644\u0627 \u062A\u0648\u062C\u062F \u0645\u0631\u0627\u062C\u0639 \u0628\u0639\u062F. \u0623\u0636\u0641 \u0645\u0631\u062C\u0639\u0627\u064B \u0623\u0648\u0644\u0627\u064B.",
7464
+ editCitation: "\u062A\u062D\u0631\u064A\u0631 \u0627\u0644\u0627\u0642\u062A\u0628\u0627\u0633",
7465
+ deleteCitation: "\u062D\u0630\u0641 \u0627\u0644\u0627\u0642\u062A\u0628\u0627\u0633",
7466
+ referencesTitle: "\u0627\u0644\u0645\u0631\u0627\u062C\u0639",
7467
+ addReference: "\u0625\u0636\u0627\u0641\u0629 \u0645\u0631\u062C\u0639",
7468
+ deleteReference: "\u062D\u0630\u0641 \u0627\u0644\u0645\u0631\u062C\u0639",
7469
+ referenceKey: "\u0627\u0644\u0645\u0641\u062A\u0627\u062D",
7470
+ referenceAuthors: "\u0627\u0644\u0645\u0624\u0644\u0641\u0648\u0646",
7471
+ referenceTitle: "\u0627\u0644\u0639\u0646\u0648\u0627\u0646",
7472
+ referenceYear: "\u0627\u0644\u0633\u0646\u0629",
7473
+ referenceVenue: "\u0627\u0644\u0645\u062C\u0644\u0629 / \u0627\u0644\u0645\u0624\u062A\u0645\u0631",
7474
+ referenceUrl: "\u0627\u0644\u0631\u0627\u0628\u0637",
7475
+ chooseDigitForm: "\u0634\u0643\u0644 \u0627\u0644\u0623\u0631\u0642\u0627\u0645",
7476
+ westernDigits: "\u0623\u0631\u0642\u0627\u0645 \u063A\u0631\u0628\u064A\u0629",
7477
+ arabicIndicDigits: "\u0623\u0631\u0642\u0627\u0645 \u0639\u0631\u0628\u064A\u0629 \u0647\u0646\u062F\u064A\u0629",
7478
+ persianIndicDigits: "\u0623\u0631\u0642\u0627\u0645 \u0641\u0627\u0631\u0633\u064A\u0629"
7479
+ },
7480
+ en: {
7481
+ undoRedo: "Undo and redo",
7482
+ undo: "Undo",
7483
+ redo: "Redo",
7484
+ structure: "Structure",
7485
+ content: "Content",
7486
+ addSection: "Add section",
7487
+ addSubsection: "Add subsection",
7488
+ addSubsubsection: "Add subsubsection",
7489
+ addParagraph: "Add paragraph",
7490
+ inlineEquation: "Inline equation",
7491
+ displayEquation: "Display equation",
7492
+ bulletedList: "Bulleted list",
7493
+ numberedList: "Numbered list",
7494
+ insertImage: "Insert image",
7495
+ insertTable: "Insert table",
7496
+ tableSize: "Table size",
7497
+ rows: "Rows",
7498
+ columns: "Columns",
7499
+ insert: "Insert",
7500
+ panels: "Panels",
7501
+ hideEditor: "Hide editor",
7502
+ editor: "Editor",
7503
+ hidePreview: "Hide preview",
7504
+ preview: "Preview",
7505
+ collapseBlocks: "Collapse blocks",
7506
+ collapseAll: "Collapse all",
7507
+ openAll: "Open all",
7508
+ documentEditor: "Document editor",
7509
+ documentPreview: "Document preview",
7510
+ importWarnings: "Import warnings (development mode)",
7511
+ emptyDocument: "The document is empty",
7512
+ text: "Text",
7513
+ editEquation: "Edit equation",
7514
+ rawEquation: "Raw equation",
7515
+ deleteEquation: "Delete equation",
7516
+ equationUnavailable: "This equation is not currently available for editing",
7517
+ closeEquationDialog: "Close equation dialog",
7518
+ equationEditorTitle: "Edit equation",
7519
+ close: "Close",
7520
+ equationType: "Equation type",
7521
+ inline: "Inline",
7522
+ displayed: "Displayed",
7523
+ saveEquation: "Save equation",
7524
+ section: "Section",
7525
+ subsection: "Subsection",
7526
+ subsubsection: "Subsubsection",
7527
+ paragraph: "Paragraph",
7528
+ list: "List",
7529
+ table: "Table",
7530
+ image: "Image",
7531
+ raw: "Raw",
7532
+ bibliography: "Bibliography",
7533
+ openBlock: "Open block",
7534
+ collapseBlock: "Collapse block",
7535
+ moveUp: "Move up",
7536
+ moveDown: "Move down",
7537
+ deleteBlock: "Delete block",
7538
+ item: "Item",
7539
+ deleteItem: "Delete item",
7540
+ addItem: "Item",
7541
+ imagePath: "File path (\\includegraphics)",
7542
+ imagePathLabel: "Image path",
7543
+ loadDocumentError: "Could not load document",
7544
+ importOrderMismatch: "The math_objects delimiter order or types do not match the document text.",
7545
+ importCountMismatch: "The detected math positions do not match the number of math_objects entries.",
7546
+ importWarning: "Import warning",
7547
+ path: "Path",
7548
+ sectionGlyph: "H1",
7549
+ subsectionGlyph: "H2",
7550
+ subsubsectionGlyph: "H3",
7551
+ paragraphGlyph: "P",
7552
+ insertCitation: "Insert citation",
7553
+ insertBibliography: "Insert bibliography",
7554
+ manageReferences: "Manage references",
7555
+ citePickerTitle: "Select references",
7556
+ noReferencesYet: "No references yet. Add a reference first.",
7557
+ editCitation: "Edit citation",
7558
+ deleteCitation: "Delete citation",
7559
+ referencesTitle: "References",
7560
+ addReference: "Add reference",
7561
+ deleteReference: "Delete reference",
7562
+ referenceKey: "Key",
7563
+ referenceAuthors: "Authors",
7564
+ referenceTitle: "Title",
7565
+ referenceYear: "Year",
7566
+ referenceVenue: "Journal / conference",
7567
+ referenceUrl: "URL",
7568
+ chooseDigitForm: "Digit form",
7569
+ westernDigits: "Western digits",
7570
+ arabicIndicDigits: "Arabic-Indic digits",
7571
+ persianIndicDigits: "Persian digits"
7572
+ }
7573
+ };
7574
+ function document2Messages(locale) {
7575
+ return DOCUMENT2_MESSAGES[locale];
7576
+ }
7577
+
7578
+ // src/react-document2/CiteChip.tsx
7579
+ var import_jsx_runtime = require("react/jsx-runtime");
7580
+ function CiteChip({
7581
+ token,
7582
+ references,
7583
+ documentDirection = "rtl",
7584
+ digitForm,
7585
+ editable = true,
7586
+ uiLocale = "ar",
7587
+ buttonRef,
7588
+ onOpen,
7589
+ onDelete,
7590
+ onFocus,
7591
+ onRequestTextFocus
7592
+ }) {
7593
+ const messages = document2Messages(uiLocale);
7594
+ const label = formatCiteLabel(token.keys, references, { documentDirection, digitForm });
7595
+ const forwardArrowKey = documentDirection === "rtl" ? "ArrowLeft" : "ArrowRight";
7596
+ const backwardArrowKey = documentDirection === "rtl" ? "ArrowRight" : "ArrowLeft";
7597
+ if (!editable) {
7598
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "butex-document2-widget__cite-chip-wrap", children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "butex-document2-widget__cite-chip", "data-editable": "false", children: label }) });
7599
+ }
7600
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { className: "butex-document2-widget__cite-chip-wrap", children: [
7601
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
7602
+ "button",
7603
+ {
7604
+ type: "button",
7605
+ className: "butex-document2-widget__cite-chip",
7606
+ "data-editable": "true",
7607
+ "data-cite-token-id": token.id,
7608
+ ref: buttonRef,
7609
+ title: messages.editCitation,
7610
+ onClick: () => onOpen(token),
7611
+ onFocus: () => onFocus?.(token.id),
7612
+ onKeyDown: (event) => {
7613
+ if (event.key === "Enter") {
7614
+ event.preventDefault();
7615
+ onOpen(token);
7616
+ return;
7617
+ }
7618
+ if (event.key === forwardArrowKey) {
7619
+ event.preventDefault();
7620
+ onRequestTextFocus?.(token.id, 1);
7621
+ return;
7622
+ }
7623
+ if (event.key === backwardArrowKey) {
7624
+ event.preventDefault();
7625
+ onRequestTextFocus?.(token.id, -1);
7626
+ }
7627
+ },
7628
+ children: label
7629
+ }
7630
+ ),
7631
+ onDelete ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
7632
+ "button",
7633
+ {
7634
+ type: "button",
7635
+ className: "butex-document2-widget__cite-chip-delete",
7636
+ title: messages.deleteCitation,
7637
+ "aria-label": messages.deleteCitation,
7638
+ onClick: (event) => {
7639
+ event.stopPropagation();
7640
+ onDelete(token.id);
7641
+ },
7642
+ children: "\xD7"
7643
+ }
7644
+ ) : null
7645
+ ] });
7646
+ }
7647
+
7648
+ // src/react-document2/MathIsland.tsx
7649
+ var import_react = require("react");
7650
+
7651
+ // src/mathjax/svgPatcher.ts
7652
+ var SVG_ARABSQRT_SELECTOR = 'mjx-container[jax="SVG"] svg .mjx-rtl-mirror[data-mjx-rtl-root="true"]';
7653
+ var ARABSQRT_SELECTOR = '.mjx-rtl-mirror[data-mjx-rtl-root="true"]';
7654
+ var PATCHED_ATTR = "data-butex-svg-arabsqrt";
7655
+ var ROOT_INDEX_SCALE = 0.72;
7656
+ var ROOT_INDEX_GAP_FACTOR = 0.08;
7657
+ var ROOT_INDEX_MIN_GAP = 2;
7658
+ var ROOT_INDEX_Y_RAISE = 18;
7659
+ var ROOT_INDEX_LEFT_SHIFT = 360;
7660
+ var VIEWBOX_PADDING = 20;
6867
7661
  function closestArabSqrtRoot(element) {
6868
7662
  return element.closest('.mjx-rtl-mirror[data-mjx-rtl-root="true"]');
6869
7663
  }
@@ -7213,7 +8007,7 @@ async function renderBuTeXMathIsland(tex, options = {}) {
7213
8007
  }
7214
8008
 
7215
8009
  // src/react-document2/MathIsland.tsx
7216
- var import_jsx_runtime = require("react/jsx-runtime");
8010
+ var import_jsx_runtime2 = require("react/jsx-runtime");
7217
8011
  function MathIsland({ id, tex, display, output = "svg" }) {
7218
8012
  const ref = (0, import_react.useRef)(null);
7219
8013
  const version = (0, import_react.useRef)(0);
@@ -7264,7 +8058,7 @@ function MathIsland({ id, tex, display, output = "svg" }) {
7264
8058
  cancelled = true;
7265
8059
  };
7266
8060
  }, [display, output, tex]);
7267
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
8061
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
7268
8062
  "span",
7269
8063
  {
7270
8064
  ref,
@@ -7278,159 +8072,8 @@ function MathIsland({ id, tex, display, output = "svg" }) {
7278
8072
  );
7279
8073
  }
7280
8074
 
7281
- // src/react-document2/uiMessages.ts
7282
- var DOCUMENT2_MESSAGES = {
7283
- ar: {
7284
- undoRedo: "\u062A\u0631\u0627\u062C\u0639 \u0648\u0625\u0639\u0627\u062F\u0629",
7285
- undo: "\u062A\u0631\u0627\u062C\u0639",
7286
- redo: "\u0625\u0639\u0627\u062F\u0629",
7287
- structure: "\u0647\u064A\u0643\u0644",
7288
- content: "\u0645\u062D\u062A\u0648\u0649",
7289
- addSection: "\u0625\u0636\u0627\u0641\u0629 \u0642\u0633\u0645",
7290
- addSubsection: "\u0625\u0636\u0627\u0641\u0629 \u0641\u0631\u0639",
7291
- addSubsubsection: "\u0625\u0636\u0627\u0641\u0629 \u0641\u0631\u0639 \u0635\u063A\u064A\u0631",
7292
- addParagraph: "\u0625\u0636\u0627\u0641\u0629 \u0641\u0642\u0631\u0629",
7293
- inlineEquation: "\u0645\u0639\u0627\u062F\u0644\u0629 \u062F\u0627\u062E\u0644 \u0627\u0644\u0633\u0637\u0631",
7294
- displayEquation: "\u0645\u0639\u0627\u062F\u0644\u0629 \u0645\u0639\u0631\u0648\u0636\u0629",
7295
- bulletedList: "\u0642\u0627\u0626\u0645\u0629 \u0646\u0642\u0637\u064A\u0629",
7296
- numberedList: "\u0642\u0627\u0626\u0645\u0629 \u0645\u0631\u0642\u0645\u0629",
7297
- insertImage: "\u0625\u062F\u0631\u0627\u062C \u0635\u0648\u0631\u0629",
7298
- insertTable: "\u0625\u062F\u0631\u0627\u062C \u062C\u062F\u0648\u0644",
7299
- tableSize: "\u062D\u062C\u0645 \u0627\u0644\u062C\u062F\u0648\u0644",
7300
- rows: "\u0635\u0641\u0648\u0641",
7301
- columns: "\u0623\u0639\u0645\u062F\u0629",
7302
- insert: "\u0625\u062F\u0631\u0627\u062C",
7303
- panels: "\u0627\u0644\u0644\u0648\u062D\u0627\u062A",
7304
- hideEditor: "\u0625\u062E\u0641\u0627\u0621 \u0627\u0644\u062A\u062D\u0631\u064A\u0631",
7305
- editor: "\u062A\u062D\u0631\u064A\u0631",
7306
- hidePreview: "\u0625\u062E\u0641\u0627\u0621 \u0627\u0644\u0645\u0639\u0627\u064A\u0646\u0629",
7307
- preview: "\u0645\u0639\u0627\u064A\u0646\u0629",
7308
- collapseBlocks: "\u0637\u064A \u0627\u0644\u0643\u062A\u0644",
7309
- collapseAll: "\u0637\u064A \u0627\u0644\u0643\u0644",
7310
- openAll: "\u0641\u062A\u062D \u0627\u0644\u0643\u0644",
7311
- documentEditor: "\u062A\u062D\u0631\u064A\u0631 \u0627\u0644\u0645\u0633\u062A\u0646\u062F",
7312
- documentPreview: "\u0645\u0639\u0627\u064A\u0646\u0629 \u0627\u0644\u0645\u0633\u062A\u0646\u062F",
7313
- importWarnings: "\u062A\u0646\u0628\u064A\u0647\u0627\u062A \u0627\u0644\u0627\u0633\u062A\u064A\u0631\u0627\u062F (\u0648\u0636\u0639 \u0627\u0644\u062A\u0637\u0648\u064A\u0631)",
7314
- emptyDocument: "\u0627\u0644\u0645\u0633\u062A\u0646\u062F \u0641\u0627\u0631\u063A",
7315
- text: "\u0646\u0635",
7316
- editEquation: "\u062A\u062D\u0631\u064A\u0631 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629",
7317
- rawEquation: "\u0645\u0639\u0627\u062F\u0644\u0629 \u062E\u0627\u0645",
7318
- deleteEquation: "\u062D\u0630\u0641 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629",
7319
- equationUnavailable: "\u0647\u0630\u0647 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629 \u063A\u064A\u0631 \u0645\u062A\u0627\u062D\u0629 \u0644\u0644\u062A\u062D\u0631\u064A\u0631 \u062D\u0627\u0644\u064A\u0627",
7320
- closeEquationDialog: "\u0625\u063A\u0644\u0627\u0642 \u0646\u0627\u0641\u0630\u0629 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629",
7321
- equationEditorTitle: "\u062A\u062D\u0631\u064A\u0631 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629",
7322
- close: "\u0625\u063A\u0644\u0627\u0642",
7323
- equationType: "\u0646\u0648\u0639 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629",
7324
- inline: "\u062F\u0627\u062E\u0644 \u0627\u0644\u0633\u0637\u0631",
7325
- displayed: "\u0645\u0639\u0631\u0648\u0636\u0629",
7326
- saveEquation: "\u062D\u0641\u0638 \u0627\u0644\u0645\u0639\u0627\u062F\u0644\u0629",
7327
- section: "\u0642\u0633\u0645",
7328
- subsection: "\u0641\u0631\u0639",
7329
- subsubsection: "\u0641\u0631\u0639 \u0635\u063A\u064A\u0631",
7330
- paragraph: "\u0641\u0642\u0631\u0629",
7331
- list: "\u0642\u0627\u0626\u0645\u0629",
7332
- table: "\u062C\u062F\u0648\u0644",
7333
- image: "\u0635\u0648\u0631\u0629",
7334
- raw: "\u062E\u0627\u0645",
7335
- openBlock: "\u0641\u062A\u062D \u0627\u0644\u0643\u062A\u0644\u0629",
7336
- collapseBlock: "\u0637\u064A \u0627\u0644\u0643\u062A\u0644\u0629",
7337
- moveUp: "\u0646\u0642\u0644 \u0644\u0623\u0639\u0644\u0649",
7338
- moveDown: "\u0646\u0642\u0644 \u0644\u0623\u0633\u0641\u0644",
7339
- deleteBlock: "\u062D\u0630\u0641 \u0627\u0644\u0643\u062A\u0644\u0629",
7340
- item: "\u0639\u0646\u0635\u0631",
7341
- deleteItem: "\u062D\u0630\u0641 \u0627\u0644\u0639\u0646\u0635\u0631",
7342
- addItem: "\u0639\u0646\u0635\u0631",
7343
- imagePath: "\u0645\u0633\u0627\u0631 \u0627\u0644\u0645\u0644\u0641 (\\includegraphics)",
7344
- imagePathLabel: "\u0645\u0633\u0627\u0631 \u0627\u0644\u0635\u0648\u0631\u0629",
7345
- loadDocumentError: "\u062A\u0639\u0630\u0631 \u062A\u062D\u0645\u064A\u0644 \u0627\u0644\u0645\u0633\u062A\u0646\u062F",
7346
- importOrderMismatch: "\u062A\u0631\u062A\u064A\u0628 \u0623\u0648 \u0623\u0646\u0648\u0627\u0639 \u0627\u0644\u0645\u062D\u062F\u062F\u0627\u062A \u0641\u064A math_objects \u0644\u0627 \u062A\u0637\u0627\u0628\u0642 \u0645\u0627 \u0648\u0631\u062F \u0641\u064A \u0627\u0644\u0646\u0635.",
7347
- importCountMismatch: "\u0639\u062F\u0645 \u062A\u0637\u0627\u0628\u0642 \u0628\u064A\u0646 \u0627\u0644\u0645\u0648\u0627\u0636\u0639 \u0627\u0644\u0631\u064A\u0627\u0636\u064A\u0629 \u0627\u0644\u0645\u0633\u062A\u062E\u0631\u062C\u0629 \u0645\u0646 \u0627\u0644\u0646\u0635 \u0648\u0639\u062F\u062F \u0639\u0646\u0627\u0635\u0631 math_objects.",
7348
- importWarning: "\u062A\u0646\u0628\u064A\u0647 \u0627\u0644\u0627\u0633\u062A\u064A\u0631\u0627\u062F",
7349
- path: "\u0627\u0644\u0645\u0633\u0627\u0631",
7350
- sectionGlyph: "\u0642",
7351
- subsectionGlyph: "\u0641",
7352
- subsubsectionGlyph: "\u0635",
7353
- paragraphGlyph: "\u0623\u0628\u062C"
7354
- },
7355
- en: {
7356
- undoRedo: "Undo and redo",
7357
- undo: "Undo",
7358
- redo: "Redo",
7359
- structure: "Structure",
7360
- content: "Content",
7361
- addSection: "Add section",
7362
- addSubsection: "Add subsection",
7363
- addSubsubsection: "Add subsubsection",
7364
- addParagraph: "Add paragraph",
7365
- inlineEquation: "Inline equation",
7366
- displayEquation: "Display equation",
7367
- bulletedList: "Bulleted list",
7368
- numberedList: "Numbered list",
7369
- insertImage: "Insert image",
7370
- insertTable: "Insert table",
7371
- tableSize: "Table size",
7372
- rows: "Rows",
7373
- columns: "Columns",
7374
- insert: "Insert",
7375
- panels: "Panels",
7376
- hideEditor: "Hide editor",
7377
- editor: "Editor",
7378
- hidePreview: "Hide preview",
7379
- preview: "Preview",
7380
- collapseBlocks: "Collapse blocks",
7381
- collapseAll: "Collapse all",
7382
- openAll: "Open all",
7383
- documentEditor: "Document editor",
7384
- documentPreview: "Document preview",
7385
- importWarnings: "Import warnings (development mode)",
7386
- emptyDocument: "The document is empty",
7387
- text: "Text",
7388
- editEquation: "Edit equation",
7389
- rawEquation: "Raw equation",
7390
- deleteEquation: "Delete equation",
7391
- equationUnavailable: "This equation is not currently available for editing",
7392
- closeEquationDialog: "Close equation dialog",
7393
- equationEditorTitle: "Edit equation",
7394
- close: "Close",
7395
- equationType: "Equation type",
7396
- inline: "Inline",
7397
- displayed: "Displayed",
7398
- saveEquation: "Save equation",
7399
- section: "Section",
7400
- subsection: "Subsection",
7401
- subsubsection: "Subsubsection",
7402
- paragraph: "Paragraph",
7403
- list: "List",
7404
- table: "Table",
7405
- image: "Image",
7406
- raw: "Raw",
7407
- openBlock: "Open block",
7408
- collapseBlock: "Collapse block",
7409
- moveUp: "Move up",
7410
- moveDown: "Move down",
7411
- deleteBlock: "Delete block",
7412
- item: "Item",
7413
- deleteItem: "Delete item",
7414
- addItem: "Item",
7415
- imagePath: "File path (\\includegraphics)",
7416
- imagePathLabel: "Image path",
7417
- loadDocumentError: "Could not load document",
7418
- importOrderMismatch: "The math_objects delimiter order or types do not match the document text.",
7419
- importCountMismatch: "The detected math positions do not match the number of math_objects entries.",
7420
- importWarning: "Import warning",
7421
- path: "Path",
7422
- sectionGlyph: "H1",
7423
- subsectionGlyph: "H2",
7424
- subsubsectionGlyph: "H3",
7425
- paragraphGlyph: "P"
7426
- }
7427
- };
7428
- function document2Messages(locale) {
7429
- return DOCUMENT2_MESSAGES[locale];
7430
- }
7431
-
7432
8075
  // src/react-document2/MathChip.tsx
7433
- var import_jsx_runtime2 = require("react/jsx-runtime");
8076
+ var import_jsx_runtime3 = require("react/jsx-runtime");
7434
8077
  function MathChip({
7435
8078
  token,
7436
8079
  output = "svg",
@@ -7449,12 +8092,12 @@ function MathChip({
7449
8092
  const tex = mathTokenSourceForSide(token, equationSide);
7450
8093
  const forwardArrowKey = documentDirection === "rtl" ? "ArrowLeft" : "ArrowRight";
7451
8094
  const backwardArrowKey = documentDirection === "rtl" ? "ArrowRight" : "ArrowLeft";
7452
- const island = /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(MathIsland, { id: token.id, tex, display: token.display, output });
8095
+ const island = /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MathIsland, { id: token.id, tex, display: token.display, output });
7453
8096
  if (!editable) {
7454
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "butex-document2-widget__math-chip-wrap", "data-display": token.display ? "true" : "false", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "butex-document2-widget__math-chip", "data-editable": "false", "data-display": token.display ? "true" : "false", children: island }) });
8097
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "butex-document2-widget__math-chip-wrap", "data-display": token.display ? "true" : "false", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "butex-document2-widget__math-chip", "data-editable": "false", "data-display": token.display ? "true" : "false", children: island }) });
7455
8098
  }
7456
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { className: "butex-document2-widget__math-chip-wrap", "data-display": token.display ? "true" : "false", children: [
7457
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8099
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { className: "butex-document2-widget__math-chip-wrap", "data-display": token.display ? "true" : "false", children: [
8100
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7458
8101
  "button",
7459
8102
  {
7460
8103
  type: "button",
@@ -7496,7 +8139,7 @@ function MathChip({
7496
8139
  children: island
7497
8140
  }
7498
8141
  ),
7499
- onDelete ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
8142
+ onDelete ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7500
8143
  "button",
7501
8144
  {
7502
8145
  type: "button",
@@ -7514,7 +8157,7 @@ function MathChip({
7514
8157
  }
7515
8158
 
7516
8159
  // src/react-document2/InlineField.tsx
7517
- var import_jsx_runtime3 = require("react/jsx-runtime");
8160
+ var import_jsx_runtime4 = require("react/jsx-runtime");
7518
8161
  function rememberCaret(element, blockId, fieldId, tokenId, onFieldFocus) {
7519
8162
  if (!blockId || !onFieldFocus) {
7520
8163
  return;
@@ -7533,21 +8176,28 @@ function fitTextareaHeight(element) {
7533
8176
  function InlineField({
7534
8177
  field,
7535
8178
  blockId,
8179
+ references = [],
7536
8180
  documentDirection = "rtl",
8181
+ digitForm,
7537
8182
  mathOutput = "svg",
7538
8183
  equationSide = "arabic",
7539
8184
  editableEquations = true,
8185
+ editableCitations = true,
7540
8186
  uiLocale = "ar",
7541
8187
  onTextChange,
7542
8188
  onOpenMath,
7543
8189
  onDeleteMath,
8190
+ onOpenCite,
8191
+ onDeleteCite,
7544
8192
  onFieldFocus,
7545
8193
  onMathFocus,
8194
+ onCiteFocus,
7546
8195
  onFieldBlur
7547
8196
  }) {
7548
8197
  const messages = document2Messages(uiLocale);
7549
8198
  const textRefs = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
7550
8199
  const mathRefs = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
8200
+ const citeRefs = (0, import_react2.useRef)(/* @__PURE__ */ new Map());
7551
8201
  function textTokenOffset(tokenId, fallback) {
7552
8202
  const token = field.tokens.find((entry) => entry.id === tokenId && entry.kind === "text");
7553
8203
  if (!token || token.kind !== "text") {
@@ -7573,6 +8223,11 @@ function InlineField({
7573
8223
  mathRefs.current.get(tokenId)?.focus();
7574
8224
  });
7575
8225
  }
8226
+ function focusCiteToken(tokenId) {
8227
+ requestAnimationFrame(() => {
8228
+ citeRefs.current.get(tokenId)?.focus();
8229
+ });
8230
+ }
7576
8231
  function adjacentTokenId(tokenId, direction, kind) {
7577
8232
  const index = field.tokens.findIndex((token) => token.id === tokenId);
7578
8233
  if (index < 0) {
@@ -7586,7 +8241,20 @@ function InlineField({
7586
8241
  }
7587
8242
  return null;
7588
8243
  }
7589
- function focusTextNearMath(tokenId, direction) {
8244
+ function adjacentIslandId(tokenId, direction) {
8245
+ const index = field.tokens.findIndex((token) => token.id === tokenId);
8246
+ if (index < 0) {
8247
+ return null;
8248
+ }
8249
+ for (let i = index + direction; i >= 0 && i < field.tokens.length; i += direction) {
8250
+ const token = field.tokens[i];
8251
+ if (token?.kind === "math" || token?.kind === "cite") {
8252
+ return { kind: token.kind, id: token.id };
8253
+ }
8254
+ }
8255
+ return null;
8256
+ }
8257
+ function focusTextNearIsland(tokenId, direction) {
7590
8258
  const fallbackDirection = direction === 1 ? -1 : 1;
7591
8259
  const textTokenId = adjacentTokenId(tokenId, direction, "text") ?? adjacentTokenId(tokenId, fallbackDirection, "text");
7592
8260
  if (!textTokenId) {
@@ -7611,60 +8279,100 @@ function InlineField({
7611
8279
  }
7612
8280
  const forwardArrowKey = documentDirection === "rtl" ? "ArrowLeft" : "ArrowRight";
7613
8281
  const backwardArrowKey = documentDirection === "rtl" ? "ArrowRight" : "ArrowLeft";
7614
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "butex-document2-widget__inline-field", dir: documentDirection, "data-document-direction": documentDirection, children: field.tokens.map(
7615
- (token) => token.kind === "text" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
7616
- "textarea",
7617
- {
7618
- className: "butex-document2-widget__inline-text",
7619
- value: token.text,
7620
- dir: documentDirection,
7621
- "aria-label": messages.text,
7622
- rows: 1,
7623
- "data-field-id": field.id,
7624
- "data-text-token-id": token.id,
7625
- ref: (element) => {
7626
- if (element) {
7627
- textRefs.current.set(token.id, element);
7628
- fitTextareaHeight(element);
7629
- } else {
7630
- textRefs.current.delete(token.id);
7631
- }
7632
- },
7633
- onChange: (event) => {
7634
- onTextChange(field.id, token.id, event.currentTarget.value);
7635
- fitTextareaHeight(event.currentTarget);
7636
- },
7637
- onKeyDown: (event) => {
7638
- const element = event.currentTarget;
7639
- const collapsed = element.selectionStart === element.selectionEnd;
7640
- if (!collapsed) {
7641
- return;
7642
- }
7643
- if (editableEquations && event.key === forwardArrowKey && element.selectionStart === element.value.length) {
7644
- const nextMathId = adjacentTokenId(token.id, 1, "math");
7645
- if (nextMathId) {
7646
- event.preventDefault();
7647
- focusMathToken(nextMathId);
8282
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "butex-document2-widget__inline-field", dir: documentDirection, "data-document-direction": documentDirection, children: field.tokens.map((token) => {
8283
+ if (token.kind === "text") {
8284
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
8285
+ "textarea",
8286
+ {
8287
+ className: "butex-document2-widget__inline-text",
8288
+ value: token.text,
8289
+ dir: documentDirection,
8290
+ "aria-label": messages.text,
8291
+ rows: 1,
8292
+ "data-field-id": field.id,
8293
+ "data-text-token-id": token.id,
8294
+ ref: (element) => {
8295
+ if (element) {
8296
+ textRefs.current.set(token.id, element);
8297
+ fitTextareaHeight(element);
8298
+ } else {
8299
+ textRefs.current.delete(token.id);
7648
8300
  }
7649
- } else if (editableEquations && event.key === backwardArrowKey && element.selectionStart === 0) {
7650
- const previousMathId = adjacentTokenId(token.id, -1, "math");
7651
- if (previousMathId) {
7652
- event.preventDefault();
7653
- focusMathToken(previousMathId);
8301
+ },
8302
+ onChange: (event) => {
8303
+ onTextChange(field.id, token.id, event.currentTarget.value);
8304
+ fitTextareaHeight(event.currentTarget);
8305
+ },
8306
+ onKeyDown: (event) => {
8307
+ const element = event.currentTarget;
8308
+ const collapsed = element.selectionStart === element.selectionEnd;
8309
+ if (!collapsed) {
8310
+ return;
7654
8311
  }
7655
- }
8312
+ if (event.key === forwardArrowKey && element.selectionStart === element.value.length) {
8313
+ const next = adjacentIslandId(token.id, 1);
8314
+ if (next) {
8315
+ event.preventDefault();
8316
+ if (next.kind === "math") {
8317
+ focusMathToken(next.id);
8318
+ } else {
8319
+ focusCiteToken(next.id);
8320
+ }
8321
+ }
8322
+ } else if (event.key === backwardArrowKey && element.selectionStart === 0) {
8323
+ const previous = adjacentIslandId(token.id, -1);
8324
+ if (previous) {
8325
+ event.preventDefault();
8326
+ if (previous.kind === "math") {
8327
+ focusMathToken(previous.id);
8328
+ } else {
8329
+ focusCiteToken(previous.id);
8330
+ }
8331
+ }
8332
+ }
8333
+ },
8334
+ onFocus: (event) => rememberCaret(event.currentTarget, blockId, field.id, token.id, onFieldFocus),
8335
+ onClick: (event) => rememberCaret(event.currentTarget, blockId, field.id, token.id, onFieldFocus),
8336
+ onKeyUp: (event) => {
8337
+ rememberCaret(event.currentTarget, blockId, field.id, token.id, onFieldFocus);
8338
+ fitTextareaHeight(event.currentTarget);
8339
+ },
8340
+ onSelect: (event) => rememberCaret(event.currentTarget, blockId, field.id, token.id, onFieldFocus),
8341
+ onBlur: () => onFieldBlur?.()
7656
8342
  },
7657
- onFocus: (event) => rememberCaret(event.currentTarget, blockId, field.id, token.id, onFieldFocus),
7658
- onClick: (event) => rememberCaret(event.currentTarget, blockId, field.id, token.id, onFieldFocus),
7659
- onKeyUp: (event) => {
7660
- rememberCaret(event.currentTarget, blockId, field.id, token.id, onFieldFocus);
7661
- fitTextareaHeight(event.currentTarget);
8343
+ token.id
8344
+ );
8345
+ }
8346
+ if (token.kind === "cite") {
8347
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
8348
+ CiteChip,
8349
+ {
8350
+ token,
8351
+ references,
8352
+ documentDirection,
8353
+ digitForm,
8354
+ editable: editableCitations,
8355
+ uiLocale,
8356
+ buttonRef: (element) => {
8357
+ if (element) {
8358
+ citeRefs.current.set(token.id, element);
8359
+ } else {
8360
+ citeRefs.current.delete(token.id);
8361
+ }
8362
+ },
8363
+ onOpen: (citeToken) => onOpenCite?.(citeToken),
8364
+ onDelete: editableCitations ? onDeleteCite : void 0,
8365
+ onFocus: (tokenId) => {
8366
+ if (blockId && onCiteFocus) {
8367
+ onCiteFocus(blockId, field.id, tokenId);
8368
+ }
8369
+ },
8370
+ onRequestTextFocus: focusTextNearIsland
7662
8371
  },
7663
- onSelect: (event) => rememberCaret(event.currentTarget, blockId, field.id, token.id, onFieldFocus),
7664
- onBlur: () => onFieldBlur?.()
7665
- },
7666
- token.id
7667
- ) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
8372
+ token.id
8373
+ );
8374
+ }
8375
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
7668
8376
  MathChip,
7669
8377
  {
7670
8378
  token,
@@ -7687,16 +8395,16 @@ function InlineField({
7687
8395
  onMathFocus(blockId, field.id, tokenId);
7688
8396
  }
7689
8397
  },
7690
- onRequestTextFocus: focusTextNearMath,
8398
+ onRequestTextFocus: focusTextNearIsland,
7691
8399
  onTextInputFromFocus: typeFromMath
7692
8400
  },
7693
8401
  token.id
7694
- )
7695
- ) });
8402
+ );
8403
+ }) });
7696
8404
  }
7697
8405
 
7698
8406
  // src/react-document2/BlockEditor.tsx
7699
- var import_jsx_runtime4 = require("react/jsx-runtime");
8407
+ var import_jsx_runtime5 = require("react/jsx-runtime");
7700
8408
  function blockChromeClass(block) {
7701
8409
  const root = "butex-document2-widget__block";
7702
8410
  if (block.kind === "textBlock") {
@@ -7720,6 +8428,9 @@ function blockChromeClass(block) {
7720
8428
  if (block.kind === "image") {
7721
8429
  return `${root} ${root}--image`;
7722
8430
  }
8431
+ if (block.kind === "bibliography") {
8432
+ return `${root} ${root}--bibliography`;
8433
+ }
7723
8434
  return `${root} ${root}--raw`;
7724
8435
  }
7725
8436
  function blockLabel(block, messages) {
@@ -7744,6 +8455,9 @@ function blockLabel(block, messages) {
7744
8455
  if (block.kind === "image") {
7745
8456
  return messages.image;
7746
8457
  }
8458
+ if (block.kind === "bibliography") {
8459
+ return messages.bibliography;
8460
+ }
7747
8461
  return messages.raw;
7748
8462
  }
7749
8463
  function truncateSummary(value) {
@@ -7758,10 +8472,18 @@ function truncateSummary(value) {
7758
8472
  }
7759
8473
  function inlineFieldSummary(field) {
7760
8474
  return truncateSummary(
7761
- field.tokens.map((token) => token.kind === "text" ? token.text : " [math] ").join("")
8475
+ field.tokens.map((token) => {
8476
+ if (token.kind === "text") {
8477
+ return token.text;
8478
+ }
8479
+ if (token.kind === "cite") {
8480
+ return " [cite] ";
8481
+ }
8482
+ return " [math] ";
8483
+ }).join("")
7762
8484
  );
7763
8485
  }
7764
- function blockSummary(block) {
8486
+ function blockSummary(block, referenceCount) {
7765
8487
  if (block.kind === "textBlock") {
7766
8488
  return inlineFieldSummary(block.field);
7767
8489
  }
@@ -7774,6 +8496,9 @@ function blockSummary(block) {
7774
8496
  if (block.kind === "image") {
7775
8497
  return truncateSummary(block.value || "empty image path");
7776
8498
  }
8499
+ if (block.kind === "bibliography") {
8500
+ return `${String(referenceCount)} ref${referenceCount === 1 ? "" : "s"}`;
8501
+ }
7777
8502
  return truncateSummary(block.value);
7778
8503
  }
7779
8504
  function BlockEditor({
@@ -7781,46 +8506,59 @@ function BlockEditor({
7781
8506
  depth = 0,
7782
8507
  blockIndex = 0,
7783
8508
  blockCount = 1,
8509
+ references = [],
7784
8510
  documentDirection = "rtl",
8511
+ digitForm,
7785
8512
  mathOutput = "svg",
7786
8513
  equationSide = "arabic",
7787
8514
  editableEquations = true,
8515
+ editableCitations = true,
7788
8516
  uiLocale = "ar",
7789
8517
  isCollapsed = false,
7790
8518
  onTextChange,
7791
8519
  onOpenMath,
7792
8520
  onDeleteMath,
8521
+ onOpenCite,
8522
+ onDeleteCite,
7793
8523
  onRemoveBlock,
7794
8524
  onMoveBlock,
7795
8525
  onToggleCollapse,
7796
8526
  onBlockFocus,
7797
8527
  onFieldFocus,
7798
8528
  onMathFocus,
8529
+ onCiteFocus,
7799
8530
  onFieldBlur,
7800
8531
  onImageSrcChange,
7801
8532
  onAddListItem,
7802
- onRemoveListItem
8533
+ onRemoveListItem,
8534
+ onManageReferences
7803
8535
  }) {
7804
8536
  const messages = document2Messages(uiLocale);
7805
8537
  const showChrome = depth === 0;
7806
8538
  const chromeClass = [blockChromeClass(block), isCollapsed ? "butex-document2-widget__block--collapsed" : ""].filter(Boolean).join(" ");
7807
8539
  const fieldProps = {
7808
8540
  blockId: block.id,
8541
+ references,
7809
8542
  documentDirection,
8543
+ digitForm,
7810
8544
  mathOutput,
7811
8545
  equationSide,
7812
8546
  editableEquations,
8547
+ editableCitations,
7813
8548
  uiLocale,
7814
8549
  onTextChange,
7815
8550
  onOpenMath,
7816
8551
  onDeleteMath,
8552
+ onOpenCite,
8553
+ onDeleteCite,
7817
8554
  onFieldFocus,
7818
8555
  onMathFocus,
8556
+ onCiteFocus,
7819
8557
  onFieldBlur
7820
8558
  };
7821
- const header = showChrome ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "butex-document2-widget__block-header", onClick: () => onBlockFocus?.(block.id), children: [
7822
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "butex-document2-widget__block-title", children: [
7823
- onToggleCollapse ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
8559
+ const header = showChrome ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "butex-document2-widget__block-header", onClick: () => onBlockFocus?.(block.id), children: [
8560
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "butex-document2-widget__block-title", children: [
8561
+ onToggleCollapse ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
7824
8562
  "button",
7825
8563
  {
7826
8564
  type: "button",
@@ -7834,78 +8572,85 @@ function BlockEditor({
7834
8572
  children: isCollapsed ? "+" : "-"
7835
8573
  }
7836
8574
  ) : null,
7837
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { children: blockLabel(block, messages) })
8575
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: blockLabel(block, messages) })
7838
8576
  ] }),
7839
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("span", { className: "butex-document2-widget__block-actions", children: [
7840
- onMoveBlock ? /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
7841
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", title: messages.moveUp, "aria-label": messages.moveUp, disabled: blockIndex <= 0, onClick: () => onMoveBlock(block.id, -1), children: "\u2191" }),
7842
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", title: messages.moveDown, "aria-label": messages.moveDown, disabled: blockIndex >= blockCount - 1, onClick: () => onMoveBlock(block.id, 1), children: "\u2193" })
8577
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("span", { className: "butex-document2-widget__block-actions", children: [
8578
+ onMoveBlock ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
8579
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", title: messages.moveUp, "aria-label": messages.moveUp, disabled: blockIndex <= 0, onClick: () => onMoveBlock(block.id, -1), children: "\u2191" }),
8580
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", title: messages.moveDown, "aria-label": messages.moveDown, disabled: blockIndex >= blockCount - 1, onClick: () => onMoveBlock(block.id, 1), children: "\u2193" })
7843
8581
  ] }) : null,
7844
- onRemoveBlock ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "butex-document2-widget__button--danger", onClick: () => onRemoveBlock(block.id), children: messages.deleteBlock }) : null
8582
+ onRemoveBlock ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "butex-document2-widget__button--danger", onClick: () => onRemoveBlock(block.id), children: messages.deleteBlock }) : null
7845
8583
  ] })
7846
8584
  ] }) : null;
7847
8585
  if (isCollapsed && showChrome) {
7848
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: chromeClass, children: [
8586
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: chromeClass, children: [
7849
8587
  header,
7850
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "butex-document2-widget__block-summary", children: blockSummary(block) })
8588
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "butex-document2-widget__block-summary", children: blockSummary(block, references.length) })
7851
8589
  ] });
7852
8590
  }
7853
8591
  if (block.kind === "textBlock") {
7854
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: chromeClass, children: [
8592
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: chromeClass, children: [
7855
8593
  header,
7856
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(InlineField, { field: block.field, ...fieldProps })
8594
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(InlineField, { field: block.field, ...fieldProps })
7857
8595
  ] });
7858
8596
  }
7859
8597
  if (block.kind === "list") {
7860
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: chromeClass, children: [
8598
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: chromeClass, children: [
7861
8599
  header,
7862
- block.items.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "butex-document2-widget__field", dir: "rtl", children: [
7863
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("span", { className: "butex-document2-widget__toolbar-label", children: block.command === "\\begin{enumerate}" ? `${messages.item} ${String(index + 1)}` : messages.item }),
7864
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("div", { className: "butex-document2-widget__list-item-content", dir: documentDirection, children: [
7865
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(InlineField, { field: item.field, ...fieldProps }),
7866
- item.blocks.map((child) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
8600
+ block.items.map((item, index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "butex-document2-widget__field", dir: "rtl", children: [
8601
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { className: "butex-document2-widget__toolbar-label", children: block.command === "\\begin{enumerate}" ? `${messages.item} ${String(index + 1)}` : messages.item }),
8602
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "butex-document2-widget__list-item-content", dir: documentDirection, children: [
8603
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(InlineField, { field: item.field, ...fieldProps }),
8604
+ item.blocks.map((child) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
7867
8605
  BlockEditor,
7868
8606
  {
7869
8607
  block: child,
7870
8608
  depth: depth + 1,
8609
+ references,
7871
8610
  documentDirection,
8611
+ digitForm,
7872
8612
  mathOutput,
7873
8613
  equationSide,
7874
8614
  editableEquations,
8615
+ editableCitations,
7875
8616
  uiLocale,
7876
8617
  onTextChange,
7877
8618
  onOpenMath,
7878
8619
  onDeleteMath,
8620
+ onOpenCite,
8621
+ onDeleteCite,
7879
8622
  onFieldFocus,
7880
8623
  onMathFocus,
8624
+ onCiteFocus,
7881
8625
  onFieldBlur,
7882
8626
  onImageSrcChange,
7883
8627
  onAddListItem,
7884
- onRemoveListItem
8628
+ onRemoveListItem,
8629
+ onManageReferences
7885
8630
  },
7886
8631
  child.id
7887
8632
  ))
7888
8633
  ] }),
7889
- onRemoveListItem && block.items.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "butex-document2-widget__list-item-actions", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("button", { type: "button", className: "butex-document2-widget__button--danger", onClick: () => onRemoveListItem(block.id, item.id), children: messages.deleteItem }) }) : null
8634
+ onRemoveListItem && block.items.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "butex-document2-widget__list-item-actions", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", className: "butex-document2-widget__button--danger", onClick: () => onRemoveListItem(block.id, item.id), children: messages.deleteItem }) }) : null
7890
8635
  ] }, item.id)),
7891
- onAddListItem ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "butex-document2-widget__list-footer", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("button", { type: "button", onClick: () => onAddListItem(block.id), children: [
8636
+ onAddListItem ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "butex-document2-widget__list-footer", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("button", { type: "button", onClick: () => onAddListItem(block.id), children: [
7892
8637
  "+ ",
7893
8638
  messages.addItem
7894
8639
  ] }) }) : null
7895
8640
  ] });
7896
8641
  }
7897
8642
  if (block.kind === "table") {
7898
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: chromeClass, children: [
8643
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: chromeClass, children: [
7899
8644
  header,
7900
- block.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "butex-document2-widget__row", dir: documentDirection, children: row.map((cell) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: "butex-document2-widget__table-cell", dir: documentDirection, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(InlineField, { field: cell, ...fieldProps }) }, cell.id)) }, rowIndex))
8645
+ block.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "butex-document2-widget__row", dir: documentDirection, children: row.map((cell) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { className: "butex-document2-widget__table-cell", dir: documentDirection, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(InlineField, { field: cell, ...fieldProps }) }, cell.id)) }, rowIndex))
7901
8646
  ] });
7902
8647
  }
7903
8648
  if (block.kind === "image") {
7904
8649
  const imageFieldId = `butex-d2-img-${block.id}`;
7905
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: chromeClass, children: [
8650
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: chromeClass, children: [
7906
8651
  header,
7907
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("label", { className: "butex-document2-widget__image-src-label", htmlFor: imageFieldId, children: messages.imagePath }),
7908
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
8652
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("label", { className: "butex-document2-widget__image-src-label", htmlFor: imageFieldId, children: messages.imagePath }),
8653
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
7909
8654
  "textarea",
7910
8655
  {
7911
8656
  id: imageFieldId,
@@ -7930,22 +8675,112 @@ function BlockEditor({
7930
8675
  )
7931
8676
  ] });
7932
8677
  }
7933
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)("section", { className: chromeClass, children: [
8678
+ if (block.kind === "bibliography") {
8679
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: chromeClass, children: [
8680
+ header,
8681
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("ol", { className: "butex-document2-widget__bibliography-editor", dir: documentDirection, children: references.map((reference, index) => /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("li", { children: [
8682
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("strong", { children: [
8683
+ "[",
8684
+ index + 1,
8685
+ "] ",
8686
+ reference.key
8687
+ ] }),
8688
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { children: [reference.authors, reference.title, reference.venue, reference.year].filter(Boolean).join(" \u2014 ") })
8689
+ ] }, reference.id)) }),
8690
+ onManageReferences ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", onClick: onManageReferences, children: messages.manageReferences }) : null
8691
+ ] });
8692
+ }
8693
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("section", { className: chromeClass, children: [
7934
8694
  header,
7935
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("pre", { className: "butex-document2-widget__raw", children: block.value })
8695
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("pre", { className: "butex-document2-widget__raw", children: block.value })
7936
8696
  ] });
7937
8697
  }
7938
8698
 
7939
- // src/react-document2/TableInsertPopover.tsx
8699
+ // src/react-document2/CitePickerPopover.tsx
7940
8700
  var import_react3 = require("react");
7941
- var import_jsx_runtime5 = require("react/jsx-runtime");
7942
- function TableInsertPopover({ uiLocale = "ar", onConfirm }) {
8701
+ var import_jsx_runtime6 = require("react/jsx-runtime");
8702
+ function CitePickerPopover({
8703
+ open,
8704
+ references,
8705
+ initialKeys = [],
8706
+ uiLocale = "ar",
8707
+ onClose,
8708
+ onConfirm,
8709
+ onManageReferences
8710
+ }) {
7943
8711
  const messages = document2Messages(uiLocale);
7944
- const [open, setOpen] = (0, import_react3.useState)(false);
7945
- const [rows, setRows] = (0, import_react3.useState)("3");
7946
- const [cols, setCols] = (0, import_react3.useState)("3");
7947
- const rootRef = (0, import_react3.useRef)(null);
8712
+ const [selected, setSelected] = (0, import_react3.useState)(initialKeys);
7948
8713
  (0, import_react3.useEffect)(() => {
8714
+ if (open) {
8715
+ setSelected(initialKeys);
8716
+ }
8717
+ }, [open, initialKeys]);
8718
+ if (!open) {
8719
+ return null;
8720
+ }
8721
+ function toggleKey(key) {
8722
+ setSelected((current) => current.includes(key) ? current.filter((entry) => entry !== key) : [...current, key]);
8723
+ }
8724
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("div", { className: "butex-document2-widget__cite-picker-backdrop", role: "presentation", onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
8725
+ "div",
8726
+ {
8727
+ className: "butex-document2-widget__cite-picker",
8728
+ role: "dialog",
8729
+ "aria-label": messages.citePickerTitle,
8730
+ onClick: (event) => event.stopPropagation(),
8731
+ children: [
8732
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("header", { className: "butex-document2-widget__cite-picker-header", children: [
8733
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("strong", { children: messages.citePickerTitle }),
8734
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.close, "aria-label": messages.close, onClick: onClose, children: "\xD7" })
8735
+ ] }),
8736
+ references.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("p", { className: "butex-document2-widget__cite-picker-empty", children: messages.noReferencesYet }) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("ul", { className: "butex-document2-widget__cite-picker-list", children: references.map((reference, index) => {
8737
+ const checked = selected.includes(reference.key);
8738
+ const subtitle = [reference.authors, reference.title].filter(Boolean).join(" \u2014 ");
8739
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("li", { children: /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("label", { className: "butex-document2-widget__cite-picker-item", children: [
8740
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("input", { type: "checkbox", checked, onChange: () => toggleKey(reference.key) }),
8741
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { children: [
8742
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("strong", { children: [
8743
+ "[",
8744
+ index + 1,
8745
+ "] ",
8746
+ reference.key
8747
+ ] }),
8748
+ subtitle ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "butex-document2-widget__cite-picker-meta", children: subtitle }) : null
8749
+ ] })
8750
+ ] }) }, reference.id);
8751
+ }) }),
8752
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("footer", { className: "butex-document2-widget__cite-picker-footer", children: [
8753
+ onManageReferences ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", onClick: onManageReferences, children: messages.manageReferences }) : null,
8754
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", onClick: onClose, children: messages.close }),
8755
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
8756
+ "button",
8757
+ {
8758
+ type: "button",
8759
+ className: "butex-document2-widget__primary-btn",
8760
+ disabled: selected.length === 0,
8761
+ onClick: () => onConfirm(selected),
8762
+ children: messages.insertCitation
8763
+ }
8764
+ )
8765
+ ] })
8766
+ ]
8767
+ }
8768
+ ) });
8769
+ }
8770
+
8771
+ // src/react-document2/DocumentInsertToolbar.tsx
8772
+ var import_react5 = require("react");
8773
+
8774
+ // src/react-document2/TableInsertPopover.tsx
8775
+ var import_react4 = require("react");
8776
+ var import_jsx_runtime7 = require("react/jsx-runtime");
8777
+ function TableInsertPopover({ uiLocale = "ar", onConfirm }) {
8778
+ const messages = document2Messages(uiLocale);
8779
+ const [open, setOpen] = (0, import_react4.useState)(false);
8780
+ const [rows, setRows] = (0, import_react4.useState)("3");
8781
+ const [cols, setCols] = (0, import_react4.useState)("3");
8782
+ const rootRef = (0, import_react4.useRef)(null);
8783
+ (0, import_react4.useEffect)(() => {
7949
8784
  if (!open) {
7950
8785
  return;
7951
8786
  }
@@ -7963,8 +8798,8 @@ function TableInsertPopover({ uiLocale = "ar", onConfirm }) {
7963
8798
  onConfirm(rowCount, colCount);
7964
8799
  setOpen(false);
7965
8800
  }
7966
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "butex-document2-widget__table-popover", ref: rootRef, children: [
7967
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
8801
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "butex-document2-widget__table-popover", ref: rootRef, children: [
8802
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
7968
8803
  "button",
7969
8804
  {
7970
8805
  type: "button",
@@ -7977,27 +8812,38 @@ function TableInsertPopover({ uiLocale = "ar", onConfirm }) {
7977
8812
  children: "\u229E"
7978
8813
  }
7979
8814
  ),
7980
- open ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { className: "butex-document2-widget__table-popover-panel", role: "dialog", "aria-label": messages.tableSize, children: [
7981
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
8815
+ open ? /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "butex-document2-widget__table-popover-panel", role: "dialog", "aria-label": messages.tableSize, children: [
8816
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("label", { children: [
7982
8817
  messages.rows,
7983
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { type: "number", min: 1, max: 20, value: rows, onChange: (event) => setRows(event.currentTarget.value) })
8818
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("input", { type: "number", min: 1, max: 20, value: rows, onChange: (event) => setRows(event.currentTarget.value) })
7984
8819
  ] }),
7985
- /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("label", { children: [
8820
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("label", { children: [
7986
8821
  messages.columns,
7987
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("input", { type: "number", min: 1, max: 10, value: cols, onChange: (event) => setCols(event.currentTarget.value) })
8822
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("input", { type: "number", min: 1, max: 10, value: cols, onChange: (event) => setCols(event.currentTarget.value) })
7988
8823
  ] }),
7989
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "button", onClick: confirm, children: messages.insert })
8824
+ /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("button", { type: "button", onClick: confirm, children: messages.insert })
7990
8825
  ] }) : null
7991
8826
  ] });
7992
8827
  }
7993
8828
 
7994
8829
  // src/react-document2/DocumentInsertToolbar.tsx
7995
- var import_jsx_runtime6 = require("react/jsx-runtime");
8830
+ var import_jsx_runtime8 = require("react/jsx-runtime");
8831
+ var DIGIT_FORMS = ["western", "arabicIndic", "persianIndic"];
8832
+ function digitFormLabel(digitForm) {
8833
+ if (digitForm === "arabicIndic") {
8834
+ return "\u0664\u0665\u0666";
8835
+ }
8836
+ if (digitForm === "persianIndic") {
8837
+ return "\u06F4\u06F5\u06F6";
8838
+ }
8839
+ return "456";
8840
+ }
7996
8841
  function DocumentInsertToolbar({
7997
8842
  canUndo,
7998
8843
  canRedo,
7999
8844
  editableEquations = true,
8000
8845
  uiLocale = "ar",
8846
+ digitForm = "western",
8001
8847
  onUndo,
8002
8848
  onRedo,
8003
8849
  onAddSection,
@@ -8009,61 +8855,135 @@ function DocumentInsertToolbar({
8009
8855
  onAddTable,
8010
8856
  onAddList,
8011
8857
  onAddEnumerate,
8012
- onAddFigure
8858
+ onAddFigure,
8859
+ onInsertCitation,
8860
+ onInsertBibliography,
8861
+ onManageReferences,
8862
+ onDigitFormChange
8013
8863
  }) {
8014
8864
  const messages = document2Messages(uiLocale);
8015
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "butex-document2-widget__toolbar-insert", children: [
8016
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "butex-document2-widget__toolbar-group", role: "group", "aria-label": messages.undoRedo, children: [
8017
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: `${messages.undo} (Ctrl+Z)`, "aria-label": messages.undo, disabled: !canUndo, onClick: onUndo, children: "\u21B6" }),
8018
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: `${messages.redo} (Ctrl+Shift+Z)`, "aria-label": messages.redo, disabled: !canRedo, onClick: onRedo, children: "\u21B7" })
8865
+ const [digitMenuOpen, setDigitMenuOpen] = (0, import_react5.useState)(false);
8866
+ function digitTitle(id) {
8867
+ if (id === "arabicIndic") {
8868
+ return messages.arabicIndicDigits;
8869
+ }
8870
+ if (id === "persianIndic") {
8871
+ return messages.persianIndicDigits;
8872
+ }
8873
+ return messages.westernDigits;
8874
+ }
8875
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "butex-document2-widget__toolbar-insert", children: [
8876
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "butex-document2-widget__toolbar-group", role: "group", "aria-label": messages.undoRedo, children: [
8877
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: `${messages.undo} (Ctrl+Z)`, "aria-label": messages.undo, disabled: !canUndo, onClick: onUndo, children: "\u21B6" }),
8878
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: `${messages.redo} (Ctrl+Shift+Z)`, "aria-label": messages.redo, disabled: !canRedo, onClick: onRedo, children: "\u21B7" })
8019
8879
  ] }),
8020
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "butex-document2-widget__toolbar-group", role: "group", "aria-label": messages.structure, children: [
8021
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn butex-document2-widget__icon-btn--h1", title: messages.addSection, "aria-label": messages.addSection, onClick: onAddSection, children: messages.sectionGlyph }),
8022
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn butex-document2-widget__icon-btn--h2", title: messages.addSubsection, "aria-label": messages.addSubsection, onClick: onAddSubsection, children: messages.subsectionGlyph }),
8023
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn butex-document2-widget__icon-btn--h3", title: messages.addSubsubsection, "aria-label": messages.addSubsubsection, onClick: onAddSubsubsection, children: messages.subsubsectionGlyph }),
8024
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.addParagraph, "aria-label": messages.addParagraph, onClick: onAddParagraph, children: messages.paragraphGlyph })
8880
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "butex-document2-widget__toolbar-group", role: "group", "aria-label": messages.structure, children: [
8881
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn butex-document2-widget__icon-btn--h1", title: messages.addSection, "aria-label": messages.addSection, onClick: onAddSection, children: messages.sectionGlyph }),
8882
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn butex-document2-widget__icon-btn--h2", title: messages.addSubsection, "aria-label": messages.addSubsection, onClick: onAddSubsection, children: messages.subsectionGlyph }),
8883
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn butex-document2-widget__icon-btn--h3", title: messages.addSubsubsection, "aria-label": messages.addSubsubsection, onClick: onAddSubsubsection, children: messages.subsubsectionGlyph }),
8884
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.addParagraph, "aria-label": messages.addParagraph, onClick: onAddParagraph, children: messages.paragraphGlyph })
8025
8885
  ] }),
8026
- /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("div", { className: "butex-document2-widget__toolbar-group", role: "group", "aria-label": messages.content, children: [
8027
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: `${messages.inlineEquation} ($\u2026$)`, "aria-label": messages.inlineEquation, disabled: !editableEquations, onClick: onAddInlineEquation, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "butex-document2-widget__icon-math-inline", "aria-hidden": "true", children: "$=$" }) }),
8028
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: `${messages.displayEquation} (\\[\u2026\\])`, "aria-label": messages.displayEquation, disabled: !editableEquations, onClick: onAddDisplayEquation, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "butex-document2-widget__icon-math-display", "aria-hidden": "true", children: "\\[\xF7\\]" }) }),
8029
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(TableInsertPopover, { uiLocale, onConfirm: onAddTable }),
8030
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.bulletedList, "aria-label": messages.bulletedList, onClick: onAddList, children: "\u2022\u2261" }),
8031
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.numberedList, "aria-label": messages.numberedList, onClick: onAddEnumerate, children: "1." }),
8032
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.insertImage, "aria-label": messages.insertImage, onClick: onAddFigure, children: "\u{1F5BC}" })
8886
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "butex-document2-widget__toolbar-group", role: "group", "aria-label": messages.content, children: [
8887
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: `${messages.inlineEquation} ($\u2026$)`, "aria-label": messages.inlineEquation, disabled: !editableEquations, onClick: onAddInlineEquation, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "butex-document2-widget__icon-math-inline", "aria-hidden": "true", children: "$=$" }) }),
8888
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: `${messages.displayEquation} (\\[\u2026\\])`, "aria-label": messages.displayEquation, disabled: !editableEquations, onClick: onAddDisplayEquation, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "butex-document2-widget__icon-math-display", "aria-hidden": "true", children: "\\[\xF7\\]" }) }),
8889
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.insertCitation, "aria-label": messages.insertCitation, onClick: onInsertCitation, children: "[]" }),
8890
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.insertBibliography, "aria-label": messages.insertBibliography, onClick: onInsertBibliography, children: "Ref" }),
8891
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.manageReferences, "aria-label": messages.manageReferences, onClick: onManageReferences, children: "\u2630" }),
8892
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(TableInsertPopover, { uiLocale, onConfirm: onAddTable }),
8893
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.bulletedList, "aria-label": messages.bulletedList, onClick: onAddList, children: "\u2022\u2261" }),
8894
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.numberedList, "aria-label": messages.numberedList, onClick: onAddEnumerate, children: "1." }),
8895
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.insertImage, "aria-label": messages.insertImage, onClick: onAddFigure, children: "\u{1F5BC}" }),
8896
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "butex-document2-widget__digit-form-menu", children: [
8897
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
8898
+ "button",
8899
+ {
8900
+ type: "button",
8901
+ className: "butex-document2-widget__icon-btn",
8902
+ title: messages.chooseDigitForm,
8903
+ "aria-label": messages.chooseDigitForm,
8904
+ "aria-expanded": digitMenuOpen,
8905
+ onClick: () => setDigitMenuOpen((open) => !open),
8906
+ children: digitFormLabel(digitForm)
8907
+ }
8908
+ ),
8909
+ digitMenuOpen ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "butex-document2-widget__digit-form-options", role: "listbox", "aria-label": messages.chooseDigitForm, children: DIGIT_FORMS.map((id) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
8910
+ "button",
8911
+ {
8912
+ type: "button",
8913
+ role: "option",
8914
+ "aria-selected": digitForm === id,
8915
+ title: digitTitle(id),
8916
+ className: "butex-document2-widget__digit-form-option",
8917
+ onClick: () => {
8918
+ onDigitFormChange(id);
8919
+ setDigitMenuOpen(false);
8920
+ },
8921
+ children: digitFormLabel(id)
8922
+ },
8923
+ id
8924
+ )) }) : null
8925
+ ] })
8033
8926
  ] })
8034
8927
  ] });
8035
8928
  }
8036
8929
 
8037
8930
  // src/react-document2/DocumentPreview.tsx
8038
- var import_jsx_runtime7 = require("react/jsx-runtime");
8931
+ var import_jsx_runtime9 = require("react/jsx-runtime");
8039
8932
  function PreviewInlines({ inlines, output }) {
8040
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_jsx_runtime7.Fragment, { children: inlines.map(
8041
- (inline, index) => inline.kind === "text" ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { children: inline.text }, index) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(MathIsland, { id: inline.id, tex: inline.tex, display: inline.display, output }, inline.id)
8042
- ) });
8933
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_jsx_runtime9.Fragment, { children: inlines.map((inline, index) => {
8934
+ if (inline.kind === "text") {
8935
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: inline.text }, index);
8936
+ }
8937
+ if (inline.kind === "cite") {
8938
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "butex-document2-widget__preview-cite", children: inline.label }, inline.id);
8939
+ }
8940
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(MathIsland, { id: inline.id, tex: inline.tex, display: inline.display, output }, inline.id);
8941
+ }) });
8043
8942
  }
8044
- function PreviewBlock({ block, output }) {
8943
+ function PreviewBlock({
8944
+ block,
8945
+ output,
8946
+ resolveImageUrl
8947
+ }) {
8045
8948
  if (block.kind === "heading") {
8046
8949
  const Tag = block.level === 1 ? "h1" : block.level === 2 ? "h2" : "h3";
8047
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Tag, { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PreviewInlines, { inlines: block.inlines, output }) });
8950
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Tag, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PreviewInlines, { inlines: block.inlines, output }) });
8048
8951
  }
8049
8952
  if (block.kind === "paragraph") {
8050
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PreviewInlines, { inlines: block.inlines, output }) });
8953
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PreviewInlines, { inlines: block.inlines, output }) });
8051
8954
  }
8052
8955
  if (block.kind === "list") {
8053
8956
  const Tag = block.ordered ? "ol" : "ul";
8054
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(Tag, { children: block.items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("li", { children: [
8055
- /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PreviewInlines, { inlines: item.inlines, output }),
8056
- item.blocks.map((child) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PreviewBlock, { block: child, output }, child.id))
8957
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(Tag, { children: block.items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("li", { children: [
8958
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PreviewInlines, { inlines: item.inlines, output }),
8959
+ item.blocks.map((child) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PreviewBlock, { block: child, output, resolveImageUrl }, child.id))
8057
8960
  ] }, item.id)) });
8058
8961
  }
8059
8962
  if (block.kind === "omit") {
8060
8963
  return null;
8061
8964
  }
8062
8965
  if (block.kind === "table") {
8063
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("table", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("tbody", { children: block.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("tr", { children: row.map((cell, columnIndex) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PreviewInlines, { inlines: cell, output }) }, columnIndex)) }, rowIndex)) }) });
8966
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("table", { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("tbody", { children: block.rows.map((row, rowIndex) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("tr", { children: row.map((cell, columnIndex) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("td", { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PreviewInlines, { inlines: cell, output }) }, columnIndex)) }, rowIndex)) }) });
8064
8967
  }
8065
8968
  if (block.kind === "image") {
8066
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src: block.src, alt: "" });
8969
+ const src = resolveImageUrl ? resolveImageUrl({ assetId: block.assetId, value: block.src }) : block.src;
8970
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("img", { src, alt: "" });
8971
+ }
8972
+ if (block.kind === "bibliography") {
8973
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("ol", { className: "butex-document2-widget__preview-bibliography", children: block.items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("li", { children: [
8974
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { className: "butex-document2-widget__preview-bib-number", children: [
8975
+ item.numberLabel,
8976
+ "."
8977
+ ] }),
8978
+ " ",
8979
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { children: [
8980
+ [item.authors, item.title, item.venue, item.year].filter(Boolean).join(", "),
8981
+ item.url ? /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_jsx_runtime9.Fragment, { children: [
8982
+ " ",
8983
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("a", { href: item.url, target: "_blank", rel: "noreferrer", children: item.url })
8984
+ ] }) : null
8985
+ ] })
8986
+ ] }, item.id)) });
8067
8987
  }
8068
8988
  return null;
8069
8989
  }
@@ -8071,17 +8991,18 @@ function DocumentPreview({
8071
8991
  blocks,
8072
8992
  output,
8073
8993
  documentDirection = "rtl",
8074
- uiLocale = "ar"
8994
+ uiLocale = "ar",
8995
+ resolveImageUrl
8075
8996
  }) {
8076
8997
  const messages = document2Messages(uiLocale);
8077
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "butex-document2-widget__preview", dir: documentDirection, children: blocks.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("p", { children: messages.emptyDocument }) : blocks.map((block) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PreviewBlock, { block, output }, block.id)) });
8998
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "butex-document2-widget__preview", dir: documentDirection, children: blocks.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { children: messages.emptyDocument }) : blocks.map((block) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(PreviewBlock, { block, output, resolveImageUrl }, block.id)) });
8078
8999
  }
8079
9000
 
8080
9001
  // src/react-document2/EquationDrawer.tsx
8081
- var import_react5 = require("react");
9002
+ var import_react7 = require("react");
8082
9003
 
8083
9004
  // src/react/ButexEditor.tsx
8084
- var import_react4 = require("react");
9005
+ var import_react6 = require("react");
8085
9006
 
8086
9007
  // src/react/widgetChromeCss.ts
8087
9008
  var WIDGET_CHROME_CSS = `
@@ -9014,7 +9935,7 @@ function uiLocaleDirection(locale) {
9014
9935
  }
9015
9936
 
9016
9937
  // src/react/ButexEditor.tsx
9017
- var import_jsx_runtime8 = require("react/jsx-runtime");
9938
+ var import_jsx_runtime10 = require("react/jsx-runtime");
9018
9939
  var DIGIT_FORM_OPTIONS = [
9019
9940
  { id: "western", label: "456" },
9020
9941
  { id: "arabicIndic", label: "\u0664\u0665\u0666" },
@@ -9056,7 +9977,7 @@ function matrixSizeLabel(rows, columns, messages) {
9056
9977
  function clampMatrixSize(value) {
9057
9978
  return Math.max(1, Math.min(12, Math.trunc(value)));
9058
9979
  }
9059
- function digitFormLabel(digitForm) {
9980
+ function digitFormLabel2(digitForm) {
9060
9981
  return DIGIT_FORM_OPTIONS.find((option) => option.id === digitForm)?.label ?? "456";
9061
9982
  }
9062
9983
  function characterFontOption(fontId) {
@@ -9097,16 +10018,16 @@ function renderArabicCommandLabel(command) {
9097
10018
  if (command.id !== "ln") {
9098
10019
  return command.arabicLabel;
9099
10020
  }
9100
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "function-command-label-with-sub", "aria-hidden": "true", children: [
9101
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "function-command-label-with-sub__base", children: command.arabicLabel }),
9102
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "function-command-label-with-sub__sub", children: "\u0647\u0640" })
10021
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "function-command-label-with-sub", "aria-hidden": "true", children: [
10022
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "function-command-label-with-sub__base", children: command.arabicLabel }),
10023
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "function-command-label-with-sub__sub", children: "\u0647\u0640" })
9103
10024
  ] });
9104
10025
  }
9105
10026
  function renderOperatorCommandLabel(command) {
9106
10027
  if (!command.svg_path) {
9107
10028
  return command.Label;
9108
10029
  }
9109
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10030
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9110
10031
  "span",
9111
10032
  {
9112
10033
  className: "operator-command-svg-label",
@@ -9122,7 +10043,7 @@ function renderOperatorMenuButtonLabel(command, fallback) {
9122
10043
  if (!command) {
9123
10044
  return fallback;
9124
10045
  }
9125
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: shouldMirrorOperatorDisplay(command) ? "operator-command-label operator-command-label--mirror" : "operator-command-label", children: renderOperatorCommandLabel(command) });
10046
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: shouldMirrorOperatorDisplay(command) ? "operator-command-label operator-command-label--mirror" : "operator-command-label", children: renderOperatorCommandLabel(command) });
9126
10047
  }
9127
10048
  function passiveTreeText(session, messages) {
9128
10049
  const passive = session.activeSide === "arabic" ? session.englishTree : session.arabicTree;
@@ -9132,61 +10053,61 @@ function passiveTreeText(session, messages) {
9132
10053
 
9133
10054
  ${latex || messages.empty}`;
9134
10055
  }
9135
- var ButexEditor = (0, import_react4.forwardRef)(
10056
+ var ButexEditor = (0, import_react6.forwardRef)(
9136
10057
  function ButexEditor2({ className, debug = false, defaultSide, uiLocale = "ar", initialSession, onSessionChange }, ref) {
9137
10058
  const messages = equationEditorMessages(uiLocale);
9138
- const wrapperRef = (0, import_react4.useRef)(null);
9139
- const surfaceRef = (0, import_react4.useRef)(null);
9140
- const mathOutputRef = (0, import_react4.useRef)(null);
9141
- const renderErrorRef = (0, import_react4.useRef)(null);
9142
- const latexLinesRef = (0, import_react4.useRef)(null);
9143
- const passivePreviewRef = (0, import_react4.useRef)(null);
9144
- const debugLogRef = (0, import_react4.useRef)(null);
9145
- const undoBtnRef = (0, import_react4.useRef)(null);
9146
- const redoBtnRef = (0, import_react4.useRef)(null);
9147
- const copyBtnRef = (0, import_react4.useRef)(null);
9148
- const cutBtnRef = (0, import_react4.useRef)(null);
9149
- const splitTypingBtnRef = (0, import_react4.useRef)(null);
9150
- const characterFontBtnRef = (0, import_react4.useRef)(null);
9151
- const digitFormBtnRef = (0, import_react4.useRef)(null);
9152
- const runtimeRef = (0, import_react4.useRef)(null);
9153
- const debugRef = (0, import_react4.useRef)(debug);
10059
+ const wrapperRef = (0, import_react6.useRef)(null);
10060
+ const surfaceRef = (0, import_react6.useRef)(null);
10061
+ const mathOutputRef = (0, import_react6.useRef)(null);
10062
+ const renderErrorRef = (0, import_react6.useRef)(null);
10063
+ const latexLinesRef = (0, import_react6.useRef)(null);
10064
+ const passivePreviewRef = (0, import_react6.useRef)(null);
10065
+ const debugLogRef = (0, import_react6.useRef)(null);
10066
+ const undoBtnRef = (0, import_react6.useRef)(null);
10067
+ const redoBtnRef = (0, import_react6.useRef)(null);
10068
+ const copyBtnRef = (0, import_react6.useRef)(null);
10069
+ const cutBtnRef = (0, import_react6.useRef)(null);
10070
+ const splitTypingBtnRef = (0, import_react6.useRef)(null);
10071
+ const characterFontBtnRef = (0, import_react6.useRef)(null);
10072
+ const digitFormBtnRef = (0, import_react6.useRef)(null);
10073
+ const runtimeRef = (0, import_react6.useRef)(null);
10074
+ const debugRef = (0, import_react6.useRef)(debug);
9154
10075
  debugRef.current = debug;
9155
- const uiLocaleRef = (0, import_react4.useRef)(uiLocale);
10076
+ const uiLocaleRef = (0, import_react6.useRef)(uiLocale);
9156
10077
  uiLocaleRef.current = uiLocale;
9157
- const onSessionChangeRef = (0, import_react4.useRef)(onSessionChange);
10078
+ const onSessionChangeRef = (0, import_react6.useRef)(onSessionChange);
9158
10079
  onSessionChangeRef.current = onSessionChange;
9159
- const debugBodyHiddenRef = (0, import_react4.useRef)(false);
9160
- const [debugBodyHidden, setDebugBodyHidden] = (0, import_react4.useState)(false);
10080
+ const debugBodyHiddenRef = (0, import_react6.useRef)(false);
10081
+ const [debugBodyHidden, setDebugBodyHidden] = (0, import_react6.useState)(false);
9161
10082
  debugBodyHiddenRef.current = debugBodyHidden;
9162
- const [digitMenuOpen, setDigitMenuOpen] = (0, import_react4.useState)(false);
9163
- const [characterFontMenuOpen, setCharacterFontMenuOpen] = (0, import_react4.useState)(false);
9164
- const [delimiterMenuOpen, setDelimiterMenuOpen] = (0, import_react4.useState)(false);
9165
- const [matrixMenuOpen, setMatrixMenuOpen] = (0, import_react4.useState)(false);
9166
- const [spacingMenuOpen, setSpacingMenuOpen] = (0, import_react4.useState)(false);
9167
- const [functionMenuOpen, setFunctionMenuOpen] = (0, import_react4.useState)(false);
9168
- const [limitsSeriesMenuOpen, setLimitsSeriesMenuOpen] = (0, import_react4.useState)(false);
9169
- const [function2MenuOpen, setFunction2MenuOpen] = (0, import_react4.useState)(false);
9170
- const [derivativeMenuOpen, setDerivativeMenuOpen] = (0, import_react4.useState)(false);
9171
- const [groupMenuOpen, setGroupMenuOpen] = (0, import_react4.useState)(false);
9172
- const [operatorMenuOpen, setOperatorMenuOpen] = (0, import_react4.useState)(false);
9173
- const [operator2MenuOpen, setOperator2MenuOpen] = (0, import_react4.useState)(false);
9174
- const [operator3MenuOpen, setOperator3MenuOpen] = (0, import_react4.useState)(false);
9175
- const [dotMenuOpen, setDotMenuOpen] = (0, import_react4.useState)(false);
9176
- const [integralMenuOpen, setIntegralMenuOpen] = (0, import_react4.useState)(false);
9177
- const [selectedDigitForm2, setSelectedDigitForm] = (0, import_react4.useState)("western");
9178
- const [selectedCharacterFont, setSelectedCharacterFont] = (0, import_react4.useState)("default");
9179
- const [activeEditorSide, setActiveEditorSide] = (0, import_react4.useState)("arabic");
9180
- const [envPaletteMode, setEnvPaletteMode] = (0, import_react4.useState)("matrix");
9181
- const [matrixStyle, setMatrixStyle] = (0, import_react4.useState)("pmatrix");
9182
- const [matrixRows, setMatrixRows] = (0, import_react4.useState)(2);
9183
- const [matrixColumns, setMatrixColumns] = (0, import_react4.useState)(2);
9184
- const [matrixHover, setMatrixHover] = (0, import_react4.useState)(null);
9185
- const [arrayAlignmentColumn, setArrayAlignmentColumn] = (0, import_react4.useState)(1);
9186
- (0, import_react4.useImperativeHandle)(ref, () => ({
10083
+ const [digitMenuOpen, setDigitMenuOpen] = (0, import_react6.useState)(false);
10084
+ const [characterFontMenuOpen, setCharacterFontMenuOpen] = (0, import_react6.useState)(false);
10085
+ const [delimiterMenuOpen, setDelimiterMenuOpen] = (0, import_react6.useState)(false);
10086
+ const [matrixMenuOpen, setMatrixMenuOpen] = (0, import_react6.useState)(false);
10087
+ const [spacingMenuOpen, setSpacingMenuOpen] = (0, import_react6.useState)(false);
10088
+ const [functionMenuOpen, setFunctionMenuOpen] = (0, import_react6.useState)(false);
10089
+ const [limitsSeriesMenuOpen, setLimitsSeriesMenuOpen] = (0, import_react6.useState)(false);
10090
+ const [function2MenuOpen, setFunction2MenuOpen] = (0, import_react6.useState)(false);
10091
+ const [derivativeMenuOpen, setDerivativeMenuOpen] = (0, import_react6.useState)(false);
10092
+ const [groupMenuOpen, setGroupMenuOpen] = (0, import_react6.useState)(false);
10093
+ const [operatorMenuOpen, setOperatorMenuOpen] = (0, import_react6.useState)(false);
10094
+ const [operator2MenuOpen, setOperator2MenuOpen] = (0, import_react6.useState)(false);
10095
+ const [operator3MenuOpen, setOperator3MenuOpen] = (0, import_react6.useState)(false);
10096
+ const [dotMenuOpen, setDotMenuOpen] = (0, import_react6.useState)(false);
10097
+ const [integralMenuOpen, setIntegralMenuOpen] = (0, import_react6.useState)(false);
10098
+ const [selectedDigitForm2, setSelectedDigitForm] = (0, import_react6.useState)("western");
10099
+ const [selectedCharacterFont, setSelectedCharacterFont] = (0, import_react6.useState)("default");
10100
+ const [activeEditorSide, setActiveEditorSide] = (0, import_react6.useState)("arabic");
10101
+ const [envPaletteMode, setEnvPaletteMode] = (0, import_react6.useState)("matrix");
10102
+ const [matrixStyle, setMatrixStyle] = (0, import_react6.useState)("pmatrix");
10103
+ const [matrixRows, setMatrixRows] = (0, import_react6.useState)(2);
10104
+ const [matrixColumns, setMatrixColumns] = (0, import_react6.useState)(2);
10105
+ const [matrixHover, setMatrixHover] = (0, import_react6.useState)(null);
10106
+ const [arrayAlignmentColumn, setArrayAlignmentColumn] = (0, import_react6.useState)(1);
10107
+ (0, import_react6.useImperativeHandle)(ref, () => ({
9187
10108
  getRuntime: () => runtimeRef.current
9188
10109
  }));
9189
- const updatePreview = (0, import_react4.useCallback)(async (session) => {
10110
+ const updatePreview = (0, import_react6.useCallback)(async (session) => {
9190
10111
  const mathOutputEl = mathOutputRef.current;
9191
10112
  const renderErrorEl = renderErrorRef.current;
9192
10113
  const latexLinesEl = latexLinesRef.current;
@@ -9236,9 +10157,9 @@ ${arabic || currentMessages.empty}`;
9236
10157
  }
9237
10158
  }
9238
10159
  }, []);
9239
- const updatePreviewRef = (0, import_react4.useRef)(updatePreview);
10160
+ const updatePreviewRef = (0, import_react6.useRef)(updatePreview);
9240
10161
  updatePreviewRef.current = updatePreview;
9241
- (0, import_react4.useEffect)(() => {
10162
+ (0, import_react6.useEffect)(() => {
9242
10163
  injectWidgetChromeCss();
9243
10164
  injectBuTeXEditorStyles(typeof document !== "undefined" ? document : void 0);
9244
10165
  const surfaceEl = surfaceRef.current;
@@ -9294,7 +10215,7 @@ ${arabic || currentMessages.empty}`;
9294
10215
  runtimeRef.current = null;
9295
10216
  };
9296
10217
  }, []);
9297
- (0, import_react4.useEffect)(() => {
10218
+ (0, import_react6.useEffect)(() => {
9298
10219
  runtimeRef.current?.setUiLocale(uiLocale);
9299
10220
  const session = runtimeRef.current?.getSession();
9300
10221
  if (session) {
@@ -9313,24 +10234,24 @@ ${arabic || currentMessages.empty}`;
9313
10234
  runtimeRef.current?.insertMatrixEnv(matrixStyle, rows, columns);
9314
10235
  }
9315
10236
  }
9316
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10237
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9317
10238
  "div",
9318
10239
  {
9319
10240
  ref: wrapperRef,
9320
10241
  className: `butex-widget ${className ?? ""}`.trim(),
9321
10242
  dir: uiLocaleDirection(uiLocale),
9322
10243
  lang: uiLocale,
9323
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "butex-widget-layout", children: [
9324
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("section", { className: "panel", children: [
9325
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "toolbar", children: [
9326
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "toolbar-group toolbar-history", role: "group", "aria-label": messages.undoRedo, children: [
9327
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { ref: undoBtnRef, id: "btn-undo", type: "button", className: "icon-btn", title: messages.undo, "aria-label": messages.undo, children: "\u21B7" }),
9328
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { ref: redoBtnRef, id: "btn-redo", type: "button", className: "icon-btn", title: messages.redo, "aria-label": messages.redo, children: "\u21B6" })
10244
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "butex-widget-layout", children: [
10245
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("section", { className: "panel", children: [
10246
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "toolbar", children: [
10247
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "toolbar-group toolbar-history", role: "group", "aria-label": messages.undoRedo, children: [
10248
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { ref: undoBtnRef, id: "btn-undo", type: "button", className: "icon-btn", title: messages.undo, "aria-label": messages.undo, children: "\u21B7" }),
10249
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { ref: redoBtnRef, id: "btn-redo", type: "button", className: "icon-btn", title: messages.redo, "aria-label": messages.redo, children: "\u21B6" })
9329
10250
  ] }),
9330
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "toolbar-group toolbar-clipboard", role: "group", "aria-label": messages.clipboard, children: [
9331
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { ref: copyBtnRef, id: "btn-copy", type: "button", className: "icon-btn", title: messages.copy, "aria-label": messages.copy, disabled: true, children: "\u29C9" }),
9332
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { ref: cutBtnRef, id: "btn-cut", type: "button", className: "icon-btn", title: messages.cut, "aria-label": messages.cut, disabled: true, children: "\u2702" }),
9333
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10251
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "toolbar-group toolbar-clipboard", role: "group", "aria-label": messages.clipboard, children: [
10252
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { ref: copyBtnRef, id: "btn-copy", type: "button", className: "icon-btn", title: messages.copy, "aria-label": messages.copy, disabled: true, children: "\u29C9" }),
10253
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { ref: cutBtnRef, id: "btn-cut", type: "button", className: "icon-btn", title: messages.cut, "aria-label": messages.cut, disabled: true, children: "\u2702" }),
10254
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9334
10255
  "button",
9335
10256
  {
9336
10257
  id: "btn-paste",
@@ -9347,9 +10268,9 @@ ${arabic || currentMessages.empty}`;
9347
10268
  }
9348
10269
  )
9349
10270
  ] }),
9350
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "toolbar-group toolbar-settings", role: "group", "aria-label": messages.editorSettings, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { className: "icon-btn accent", type: "button", title: messages.toggleSide, "aria-label": messages.toggleSide, onClick: () => runtimeRef.current?.toggleSide(), children: "\u21C4" }) }),
9351
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "toolbar-group toolbar-structures", role: "group", "aria-label": messages.structures, children: [
9352
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
10271
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "toolbar-group toolbar-settings", role: "group", "aria-label": messages.editorSettings, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { className: "icon-btn accent", type: "button", title: messages.toggleSide, "aria-label": messages.toggleSide, onClick: () => runtimeRef.current?.toggleSide(), children: "\u21C4" }) }),
10272
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "toolbar-group toolbar-structures", role: "group", "aria-label": messages.structures, children: [
10273
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
9353
10274
  "div",
9354
10275
  {
9355
10276
  className: "delimiter-command-menu",
@@ -9360,7 +10281,7 @@ ${arabic || currentMessages.empty}`;
9360
10281
  }
9361
10282
  },
9362
10283
  children: [
9363
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10284
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9364
10285
  "button",
9365
10286
  {
9366
10287
  className: "icon-btn delimiter-command-btn",
@@ -9373,8 +10294,8 @@ ${arabic || currentMessages.empty}`;
9373
10294
  children: "()"
9374
10295
  }
9375
10296
  ),
9376
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "delimiter-command-options", role: "listbox", "aria-label": messages.insertDelimiters, hidden: !delimiterMenuOpen, children: [
9377
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10297
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "delimiter-command-options", role: "listbox", "aria-label": messages.insertDelimiters, hidden: !delimiterMenuOpen, children: [
10298
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9378
10299
  "button",
9379
10300
  {
9380
10301
  className: "delimiter-command-option",
@@ -9392,7 +10313,7 @@ ${arabic || currentMessages.empty}`;
9392
10313
  children: "()"
9393
10314
  }
9394
10315
  ),
9395
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10316
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9396
10317
  "button",
9397
10318
  {
9398
10319
  className: "delimiter-command-option",
@@ -9410,7 +10331,7 @@ ${arabic || currentMessages.empty}`;
9410
10331
  children: "[]"
9411
10332
  }
9412
10333
  ),
9413
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10334
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9414
10335
  "button",
9415
10336
  {
9416
10337
  className: "delimiter-command-option",
@@ -9432,19 +10353,19 @@ ${arabic || currentMessages.empty}`;
9432
10353
  ]
9433
10354
  }
9434
10355
  ),
9435
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { id: "insert-frac", className: "icon-btn frac-icon-btn", type: "button", title: messages.insertFraction, "aria-label": messages.insertFraction, onClick: () => {
10356
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { id: "insert-frac", className: "icon-btn frac-icon-btn", type: "button", title: messages.insertFraction, "aria-label": messages.insertFraction, onClick: () => {
9436
10357
  runtimeRef.current?.insertFraction();
9437
10358
  focusSurface();
9438
- }, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "toolbar-frac-icon", "aria-hidden": "true", children: [
9439
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "\u0623" }),
9440
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "\u0628" })
10359
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "toolbar-frac-icon", "aria-hidden": "true", children: [
10360
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "\u0623" }),
10361
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "\u0628" })
9441
10362
  ] }) }),
9442
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { id: "insert-sqrt", className: "icon-btn", type: "button", title: messages.insertRoot, "aria-label": messages.insertRoot, onClick: () => {
10363
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { id: "insert-sqrt", className: "icon-btn", type: "button", title: messages.insertRoot, "aria-label": messages.insertRoot, onClick: () => {
9443
10364
  runtimeRef.current?.insertSqrt();
9444
10365
  focusSurface();
9445
- }, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "toolbar-sqrt-icon", "aria-hidden": "true", children: "\u221A" }) })
10366
+ }, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "toolbar-sqrt-icon", "aria-hidden": "true", children: "\u221A" }) })
9446
10367
  ] }),
9447
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "toolbar-group toolbar-environments", role: "group", "aria-label": messages.environments, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
10368
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "toolbar-group toolbar-environments", role: "group", "aria-label": messages.environments, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
9448
10369
  "div",
9449
10370
  {
9450
10371
  className: "matrix-command-menu",
@@ -9455,7 +10376,7 @@ ${arabic || currentMessages.empty}`;
9455
10376
  }
9456
10377
  },
9457
10378
  children: [
9458
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10379
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9459
10380
  "button",
9460
10381
  {
9461
10382
  className: "icon-btn matrix-command-btn",
@@ -9465,20 +10386,20 @@ ${arabic || currentMessages.empty}`;
9465
10386
  "aria-haspopup": "dialog",
9466
10387
  "aria-expanded": matrixMenuOpen,
9467
10388
  onClick: () => setMatrixMenuOpen((open) => !open),
9468
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "toolbar-matrix-icon", "aria-hidden": "true", children: [
9469
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", {}),
9470
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", {}),
9471
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", {}),
9472
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", {})
10389
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "toolbar-matrix-icon", "aria-hidden": "true", children: [
10390
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", {}),
10391
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", {}),
10392
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", {}),
10393
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", {})
9473
10394
  ] })
9474
10395
  }
9475
10396
  ),
9476
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "matrix-command-popover", role: "dialog", "aria-label": messages.insertEnvironment, hidden: !matrixMenuOpen, children: [
9477
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "matrix-style-options", role: "listbox", "aria-label": messages.environmentType, children: [
10397
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "matrix-command-popover", role: "dialog", "aria-label": messages.insertEnvironment, hidden: !matrixMenuOpen, children: [
10398
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "matrix-style-options", role: "listbox", "aria-label": messages.environmentType, children: [
9478
10399
  { id: "matrix", label: messages.matrix },
9479
10400
  { id: "array", label: messages.array },
9480
10401
  { id: "aligned", label: messages.aligned }
9481
- ].map((option) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10402
+ ].map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9482
10403
  "button",
9483
10404
  {
9484
10405
  type: "button",
@@ -9496,7 +10417,7 @@ ${arabic || currentMessages.empty}`;
9496
10417
  },
9497
10418
  option.id
9498
10419
  )) }),
9499
- envPaletteMode === "matrix" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "matrix-style-options", role: "listbox", "aria-label": messages.matrixType, children: MATRIX_STYLES.map((style) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10420
+ envPaletteMode === "matrix" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "matrix-style-options", role: "listbox", "aria-label": messages.matrixType, children: MATRIX_STYLES.map((style) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9500
10421
  "button",
9501
10422
  {
9502
10423
  type: "button",
@@ -9512,15 +10433,15 @@ ${arabic || currentMessages.empty}`;
9512
10433
  },
9513
10434
  style.id
9514
10435
  )) }) : null,
9515
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "matrix-size-readout", children: matrixHover ? matrixSizeLabel(matrixHover.rows, matrixHover.columns, messages) : matrixSizeLabel(matrixRows, matrixColumns, messages) }),
9516
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "matrix-grid-picker", "aria-label": messages.chooseEnvironmentSize, children: Array.from(
10436
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "matrix-size-readout", children: matrixHover ? matrixSizeLabel(matrixHover.rows, matrixHover.columns, messages) : matrixSizeLabel(matrixRows, matrixColumns, messages) }),
10437
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "matrix-grid-picker", "aria-label": messages.chooseEnvironmentSize, children: Array.from(
9517
10438
  { length: 8 },
9518
10439
  (_, rowIndex) => Array.from({ length: 8 }, (_2, columnIndex) => {
9519
10440
  const rows = rowIndex + 1;
9520
10441
  const columns = columnIndex + 1;
9521
10442
  const activeRows = matrixHover?.rows ?? matrixRows;
9522
10443
  const activeColumns = matrixHover?.columns ?? matrixColumns;
9523
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10444
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9524
10445
  "button",
9525
10446
  {
9526
10447
  type: "button",
@@ -9542,10 +10463,10 @@ ${arabic || currentMessages.empty}`;
9542
10463
  );
9543
10464
  })
9544
10465
  ) }),
9545
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "matrix-custom-size", children: [
9546
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { children: [
10466
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "matrix-custom-size", children: [
10467
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("label", { children: [
9547
10468
  messages.row,
9548
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10469
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9549
10470
  "input",
9550
10471
  {
9551
10472
  type: "number",
@@ -9556,9 +10477,9 @@ ${arabic || currentMessages.empty}`;
9556
10477
  }
9557
10478
  )
9558
10479
  ] }),
9559
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { children: [
10480
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("label", { children: [
9560
10481
  messages.column,
9561
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10482
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9562
10483
  "input",
9563
10484
  {
9564
10485
  type: "number",
@@ -9569,7 +10490,7 @@ ${arabic || currentMessages.empty}`;
9569
10490
  }
9570
10491
  )
9571
10492
  ] }),
9572
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10493
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9573
10494
  "button",
9574
10495
  {
9575
10496
  type: "button",
@@ -9587,12 +10508,12 @@ ${arabic || currentMessages.empty}`;
9587
10508
  }
9588
10509
  )
9589
10510
  ] }),
9590
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "matrix-edit-actions", "aria-label": messages.editSelectedEnvironment, children: [
9591
- envPaletteMode === "matrix" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { type: "button", title: messages.applySelectedMatrixStyle, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.setMatrixEnvStyle(matrixStyle), children: messages.applyStyle }) : null,
9592
- envPaletteMode === "array" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
9593
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("label", { children: [
10511
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "matrix-edit-actions", "aria-label": messages.editSelectedEnvironment, children: [
10512
+ envPaletteMode === "matrix" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", title: messages.applySelectedMatrixStyle, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.setMatrixEnvStyle(matrixStyle), children: messages.applyStyle }) : null,
10513
+ envPaletteMode === "array" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
10514
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("label", { children: [
9594
10515
  messages.column,
9595
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10516
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9596
10517
  "input",
9597
10518
  {
9598
10519
  type: "number",
@@ -9603,7 +10524,7 @@ ${arabic || currentMessages.empty}`;
9603
10524
  }
9604
10525
  )
9605
10526
  ] }),
9606
- ARRAY_ALIGNMENTS.map((alignment) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10527
+ ARRAY_ALIGNMENTS.map((alignment) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9607
10528
  "button",
9608
10529
  {
9609
10530
  type: "button",
@@ -9615,19 +10536,19 @@ ${arabic || currentMessages.empty}`;
9615
10536
  alignment.id
9616
10537
  ))
9617
10538
  ] }) : null,
9618
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("button", { type: "button", title: messages.addRow, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.addMatrixRow(), children: [
10539
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", title: messages.addRow, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.addMatrixRow(), children: [
9619
10540
  "+",
9620
10541
  messages.row
9621
10542
  ] }),
9622
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("button", { type: "button", title: messages.removeRow, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.removeMatrixRow(), children: [
10543
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", title: messages.removeRow, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.removeMatrixRow(), children: [
9623
10544
  "-",
9624
10545
  messages.row
9625
10546
  ] }),
9626
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("button", { type: "button", title: messages.addColumn, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.addMatrixColumn(), children: [
10547
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", title: messages.addColumn, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.addMatrixColumn(), children: [
9627
10548
  "+",
9628
10549
  messages.column
9629
10550
  ] }),
9630
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("button", { type: "button", title: messages.removeColumn, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.removeMatrixColumn(), children: [
10551
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("button", { type: "button", title: messages.removeColumn, onMouseDown: (event) => event.preventDefault(), onClick: () => runtimeRef.current?.removeMatrixColumn(), children: [
9631
10552
  "-",
9632
10553
  messages.column
9633
10554
  ] })
@@ -9636,7 +10557,7 @@ ${arabic || currentMessages.empty}`;
9636
10557
  ]
9637
10558
  }
9638
10559
  ) }),
9639
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "toolbar-group toolbar-settings", role: "group", "aria-label": messages.spaces, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
10560
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "toolbar-group toolbar-settings", role: "group", "aria-label": messages.spaces, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
9640
10561
  "div",
9641
10562
  {
9642
10563
  className: `spacing-command-menu spacing-command-menu--${activeEditorSide}`,
@@ -9647,7 +10568,7 @@ ${arabic || currentMessages.empty}`;
9647
10568
  }
9648
10569
  },
9649
10570
  children: [
9650
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10571
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9651
10572
  "button",
9652
10573
  {
9653
10574
  className: "icon-btn spacing-command-btn",
@@ -9657,13 +10578,13 @@ ${arabic || currentMessages.empty}`;
9657
10578
  "aria-haspopup": "listbox",
9658
10579
  "aria-expanded": spacingMenuOpen,
9659
10580
  onClick: () => setSpacingMenuOpen((open) => !open),
9660
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "spacing-command-glyph spacing-command-glyph--positive spacing-command-glyph--level-2", "aria-hidden": "true", children: [
9661
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "spacing-command-glyph__bar" }),
9662
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "spacing-command-glyph__arrow", children: activeEditorSide === "arabic" ? "\u2190" : "\u2192" })
10581
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "spacing-command-glyph spacing-command-glyph--positive spacing-command-glyph--level-2", "aria-hidden": "true", children: [
10582
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "spacing-command-glyph__bar" }),
10583
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "spacing-command-glyph__arrow", children: activeEditorSide === "arabic" ? "\u2190" : "\u2192" })
9663
10584
  ] })
9664
10585
  }
9665
10586
  ),
9666
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "spacing-command-options", role: "listbox", "aria-label": messages.insertSpace, hidden: !spacingMenuOpen, children: SPACING_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
10587
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "spacing-command-options", role: "listbox", "aria-label": messages.insertSpace, hidden: !spacingMenuOpen, children: SPACING_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
9667
10588
  "button",
9668
10589
  {
9669
10590
  type: "button",
@@ -9677,12 +10598,12 @@ ${arabic || currentMessages.empty}`;
9677
10598
  focusSurface();
9678
10599
  },
9679
10600
  children: [
9680
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: `spacing-command-glyph spacing-command-glyph--${command.spacing.direction} spacing-command-glyph--level-${String(command.spacing.level)}`, "aria-hidden": "true", children: [
9681
- command.spacing.direction === "negative" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "spacing-command-glyph__arrow", children: spacingArrow(command, activeEditorSide) }) : null,
9682
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "spacing-command-glyph__bar" }),
9683
- command.spacing.direction === "positive" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "spacing-command-glyph__arrow", children: spacingArrow(command, activeEditorSide) }) : null
10601
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: `spacing-command-glyph spacing-command-glyph--${command.spacing.direction} spacing-command-glyph--level-${String(command.spacing.level)}`, "aria-hidden": "true", children: [
10602
+ command.spacing.direction === "negative" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "spacing-command-glyph__arrow", children: spacingArrow(command, activeEditorSide) }) : null,
10603
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "spacing-command-glyph__bar" }),
10604
+ command.spacing.direction === "positive" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "spacing-command-glyph__arrow", children: spacingArrow(command, activeEditorSide) }) : null
9684
10605
  ] }),
9685
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "spacing-command-option__name", children: atomicCommandTitle(command, uiLocale) })
10606
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "spacing-command-option__name", children: atomicCommandTitle(command, uiLocale) })
9686
10607
  ]
9687
10608
  },
9688
10609
  command.id
@@ -9690,8 +10611,8 @@ ${arabic || currentMessages.empty}`;
9690
10611
  ]
9691
10612
  }
9692
10613
  ) }),
9693
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "toolbar-group toolbar-functions", role: "group", "aria-label": messages.functions, children: [
9694
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
10614
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "toolbar-group toolbar-functions", role: "group", "aria-label": messages.functions, children: [
10615
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
9695
10616
  "div",
9696
10617
  {
9697
10618
  className: "function-command-menu",
@@ -9702,7 +10623,7 @@ ${arabic || currentMessages.empty}`;
9702
10623
  }
9703
10624
  },
9704
10625
  children: [
9705
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10626
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9706
10627
  "button",
9707
10628
  {
9708
10629
  className: "icon-btn function-command-btn",
@@ -9715,7 +10636,7 @@ ${arabic || currentMessages.empty}`;
9715
10636
  children: FUNCTION_COMMANDS[0]?.arabicLabel ?? "\u062F"
9716
10637
  }
9717
10638
  ),
9718
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "function-command-options", role: "listbox", "aria-label": messages.insertFunction, hidden: !functionMenuOpen, children: FUNCTION_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10639
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "function-command-options", role: "listbox", "aria-label": messages.insertFunction, hidden: !functionMenuOpen, children: FUNCTION_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9719
10640
  "button",
9720
10641
  {
9721
10642
  className: "function-command-option",
@@ -9736,7 +10657,7 @@ ${arabic || currentMessages.empty}`;
9736
10657
  ]
9737
10658
  }
9738
10659
  ),
9739
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
10660
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
9740
10661
  "div",
9741
10662
  {
9742
10663
  className: "function-command-menu function-command-menu--limits-series",
@@ -9747,7 +10668,7 @@ ${arabic || currentMessages.empty}`;
9747
10668
  }
9748
10669
  },
9749
10670
  children: [
9750
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10671
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9751
10672
  "button",
9752
10673
  {
9753
10674
  className: "icon-btn function-command-btn",
@@ -9760,7 +10681,7 @@ ${arabic || currentMessages.empty}`;
9760
10681
  children: LIMITS_SERIES_COMMANDS[0]?.arabicLabel ?? "\u062D\u062F"
9761
10682
  }
9762
10683
  ),
9763
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "function-command-options", role: "listbox", "aria-label": messages.insertLimitsSeries, hidden: !limitsSeriesMenuOpen, children: LIMITS_SERIES_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10684
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "function-command-options", role: "listbox", "aria-label": messages.insertLimitsSeries, hidden: !limitsSeriesMenuOpen, children: LIMITS_SERIES_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9764
10685
  "button",
9765
10686
  {
9766
10687
  className: "function-command-option",
@@ -9781,7 +10702,7 @@ ${arabic || currentMessages.empty}`;
9781
10702
  ]
9782
10703
  }
9783
10704
  ),
9784
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
10705
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
9785
10706
  "div",
9786
10707
  {
9787
10708
  className: "function-command-menu function-command-menu--function2",
@@ -9792,7 +10713,7 @@ ${arabic || currentMessages.empty}`;
9792
10713
  }
9793
10714
  },
9794
10715
  children: [
9795
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10716
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9796
10717
  "button",
9797
10718
  {
9798
10719
  className: "icon-btn function-command-btn",
@@ -9805,7 +10726,7 @@ ${arabic || currentMessages.empty}`;
9805
10726
  children: FUNCTION2_COMMANDS[0]?.arabicLabel ?? "\u062F"
9806
10727
  }
9807
10728
  ),
9808
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "function-command-options", role: "listbox", "aria-label": messages.insertAdditionalFunctions, hidden: !function2MenuOpen, children: FUNCTION2_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10729
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "function-command-options", role: "listbox", "aria-label": messages.insertAdditionalFunctions, hidden: !function2MenuOpen, children: FUNCTION2_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9809
10730
  "button",
9810
10731
  {
9811
10732
  className: "function-command-option",
@@ -9826,7 +10747,7 @@ ${arabic || currentMessages.empty}`;
9826
10747
  ]
9827
10748
  }
9828
10749
  ),
9829
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
10750
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
9830
10751
  "div",
9831
10752
  {
9832
10753
  className: "function-command-menu function-command-menu--derivative",
@@ -9837,7 +10758,7 @@ ${arabic || currentMessages.empty}`;
9837
10758
  }
9838
10759
  },
9839
10760
  children: [
9840
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10761
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9841
10762
  "button",
9842
10763
  {
9843
10764
  className: "icon-btn function-command-btn",
@@ -9850,8 +10771,8 @@ ${arabic || currentMessages.empty}`;
9850
10771
  children: DERIVATIVE_COMMANDS[0]?.arabicLabel ?? "\u0621"
9851
10772
  }
9852
10773
  ),
9853
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "function-command-options", role: "listbox", "aria-label": messages.insertDerivative, hidden: !derivativeMenuOpen, children: [
9854
- DERIVATIVE_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10774
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "function-command-options", role: "listbox", "aria-label": messages.insertDerivative, hidden: !derivativeMenuOpen, children: [
10775
+ DERIVATIVE_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9855
10776
  "button",
9856
10777
  {
9857
10778
  className: "function-command-option",
@@ -9869,7 +10790,7 @@ ${arabic || currentMessages.empty}`;
9869
10790
  },
9870
10791
  command.id
9871
10792
  )),
9872
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10793
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9873
10794
  "button",
9874
10795
  {
9875
10796
  className: "function-command-option",
@@ -9886,7 +10807,7 @@ ${arabic || currentMessages.empty}`;
9886
10807
  children: "\u0621/\u0633"
9887
10808
  }
9888
10809
  ),
9889
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10810
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9890
10811
  "button",
9891
10812
  {
9892
10813
  className: "function-command-option",
@@ -9907,7 +10828,7 @@ ${arabic || currentMessages.empty}`;
9907
10828
  ]
9908
10829
  }
9909
10830
  ),
9910
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
10831
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
9911
10832
  "div",
9912
10833
  {
9913
10834
  className: "function-command-menu function-command-menu--groups",
@@ -9918,7 +10839,7 @@ ${arabic || currentMessages.empty}`;
9918
10839
  }
9919
10840
  },
9920
10841
  children: [
9921
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10842
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9922
10843
  "button",
9923
10844
  {
9924
10845
  className: "icon-btn function-command-btn",
@@ -9931,7 +10852,7 @@ ${arabic || currentMessages.empty}`;
9931
10852
  children: GROUP_COMMANDS[0]?.arabicLabel ?? "\u0645"
9932
10853
  }
9933
10854
  ),
9934
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "function-command-options", role: "listbox", "aria-label": messages.insertNumberSets, hidden: !groupMenuOpen, children: GROUP_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10855
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "function-command-options", role: "listbox", "aria-label": messages.insertNumberSets, hidden: !groupMenuOpen, children: GROUP_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9935
10856
  "button",
9936
10857
  {
9937
10858
  className: "function-command-option",
@@ -9953,8 +10874,8 @@ ${arabic || currentMessages.empty}`;
9953
10874
  }
9954
10875
  )
9955
10876
  ] }),
9956
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "toolbar-group toolbar-operators", role: "group", "aria-label": messages.operations, children: [
9957
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
10877
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "toolbar-group toolbar-operators", role: "group", "aria-label": messages.operations, children: [
10878
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
9958
10879
  "div",
9959
10880
  {
9960
10881
  className: "function-command-menu operator-command-menu",
@@ -9965,7 +10886,7 @@ ${arabic || currentMessages.empty}`;
9965
10886
  }
9966
10887
  },
9967
10888
  children: [
9968
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10889
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9969
10890
  "button",
9970
10891
  {
9971
10892
  className: "icon-btn function-command-btn operator-command-btn",
@@ -9978,7 +10899,7 @@ ${arabic || currentMessages.empty}`;
9978
10899
  children: renderOperatorMenuButtonLabel(OPERATOR_COMMANDS[0], "\u2217")
9979
10900
  }
9980
10901
  ),
9981
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "function-command-options operator-command-options", role: "listbox", "aria-label": messages.insertOperation, hidden: !operatorMenuOpen, children: OPERATOR_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10902
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "function-command-options operator-command-options", role: "listbox", "aria-label": messages.insertOperation, hidden: !operatorMenuOpen, children: OPERATOR_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
9982
10903
  "button",
9983
10904
  {
9984
10905
  className: "function-command-option operator-command-option",
@@ -9992,14 +10913,14 @@ ${arabic || currentMessages.empty}`;
9992
10913
  setOperatorMenuOpen(false);
9993
10914
  focusSurface();
9994
10915
  },
9995
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: shouldMirrorOperatorDisplay(command) ? "operator-command-label operator-command-label--mirror" : "operator-command-label", children: renderOperatorCommandLabel(command) })
10916
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: shouldMirrorOperatorDisplay(command) ? "operator-command-label operator-command-label--mirror" : "operator-command-label", children: renderOperatorCommandLabel(command) })
9996
10917
  },
9997
10918
  command.id
9998
10919
  )) })
9999
10920
  ]
10000
10921
  }
10001
10922
  ),
10002
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
10923
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10003
10924
  "div",
10004
10925
  {
10005
10926
  className: "function-command-menu operator-command-menu",
@@ -10010,7 +10931,7 @@ ${arabic || currentMessages.empty}`;
10010
10931
  }
10011
10932
  },
10012
10933
  children: [
10013
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10934
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10014
10935
  "button",
10015
10936
  {
10016
10937
  className: "icon-btn function-command-btn operator-command-btn",
@@ -10023,7 +10944,7 @@ ${arabic || currentMessages.empty}`;
10023
10944
  children: "\u2229"
10024
10945
  }
10025
10946
  ),
10026
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "function-command-options operator-command-options", role: "listbox", "aria-label": messages.insertRelationsSets, hidden: !operator2MenuOpen, children: OPERATOR2_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10947
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "function-command-options operator-command-options", role: "listbox", "aria-label": messages.insertRelationsSets, hidden: !operator2MenuOpen, children: OPERATOR2_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10027
10948
  "button",
10028
10949
  {
10029
10950
  className: "function-command-option operator-command-option",
@@ -10037,14 +10958,14 @@ ${arabic || currentMessages.empty}`;
10037
10958
  setOperator2MenuOpen(false);
10038
10959
  focusSurface();
10039
10960
  },
10040
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: shouldMirrorOperatorDisplay(command) ? "operator-command-label operator-command-label--mirror" : "operator-command-label", children: renderOperatorCommandLabel(command) })
10961
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: shouldMirrorOperatorDisplay(command) ? "operator-command-label operator-command-label--mirror" : "operator-command-label", children: renderOperatorCommandLabel(command) })
10041
10962
  },
10042
10963
  command.id
10043
10964
  )) })
10044
10965
  ]
10045
10966
  }
10046
10967
  ),
10047
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
10968
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10048
10969
  "div",
10049
10970
  {
10050
10971
  className: "function-command-menu operator-command-menu",
@@ -10055,7 +10976,7 @@ ${arabic || currentMessages.empty}`;
10055
10976
  }
10056
10977
  },
10057
10978
  children: [
10058
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10979
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10059
10980
  "button",
10060
10981
  {
10061
10982
  className: "icon-btn function-command-btn operator-command-btn",
@@ -10068,7 +10989,7 @@ ${arabic || currentMessages.empty}`;
10068
10989
  children: renderOperatorMenuButtonLabel(OPERATOR3_COMMANDS[0], "\u21D2")
10069
10990
  }
10070
10991
  ),
10071
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "function-command-options operator-command-options", role: "listbox", "aria-label": messages.insertArrows, hidden: !operator3MenuOpen, children: OPERATOR3_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
10992
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "function-command-options operator-command-options", role: "listbox", "aria-label": messages.insertArrows, hidden: !operator3MenuOpen, children: OPERATOR3_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10072
10993
  "button",
10073
10994
  {
10074
10995
  className: "function-command-option operator-command-option",
@@ -10082,14 +11003,14 @@ ${arabic || currentMessages.empty}`;
10082
11003
  setOperator3MenuOpen(false);
10083
11004
  focusSurface();
10084
11005
  },
10085
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: shouldMirrorOperatorDisplay(command) ? "operator-command-label operator-command-label--mirror" : "operator-command-label", children: renderOperatorCommandLabel(command) })
11006
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: shouldMirrorOperatorDisplay(command) ? "operator-command-label operator-command-label--mirror" : "operator-command-label", children: renderOperatorCommandLabel(command) })
10086
11007
  },
10087
11008
  command.id
10088
11009
  )) })
10089
11010
  ]
10090
11011
  }
10091
11012
  ),
10092
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
11013
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10093
11014
  "div",
10094
11015
  {
10095
11016
  className: "function-command-menu operator-command-menu",
@@ -10100,7 +11021,7 @@ ${arabic || currentMessages.empty}`;
10100
11021
  }
10101
11022
  },
10102
11023
  children: [
10103
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
11024
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10104
11025
  "button",
10105
11026
  {
10106
11027
  className: "icon-btn function-command-btn operator-command-btn",
@@ -10113,7 +11034,7 @@ ${arabic || currentMessages.empty}`;
10113
11034
  children: renderOperatorMenuButtonLabel(DOT_COMMANDS[0], "\u2026")
10114
11035
  }
10115
11036
  ),
10116
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "function-command-options operator-command-options", role: "listbox", "aria-label": messages.insertDots, hidden: !dotMenuOpen, children: DOT_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
11037
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "function-command-options operator-command-options", role: "listbox", "aria-label": messages.insertDots, hidden: !dotMenuOpen, children: DOT_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10117
11038
  "button",
10118
11039
  {
10119
11040
  className: "function-command-option operator-command-option",
@@ -10127,14 +11048,14 @@ ${arabic || currentMessages.empty}`;
10127
11048
  setDotMenuOpen(false);
10128
11049
  focusSurface();
10129
11050
  },
10130
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: shouldMirrorOperatorDisplay(command) ? "operator-command-label operator-command-label--mirror" : "operator-command-label", children: renderOperatorCommandLabel(command) })
11051
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: shouldMirrorOperatorDisplay(command) ? "operator-command-label operator-command-label--mirror" : "operator-command-label", children: renderOperatorCommandLabel(command) })
10131
11052
  },
10132
11053
  command.id
10133
11054
  )) })
10134
11055
  ]
10135
11056
  }
10136
11057
  ),
10137
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
11058
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10138
11059
  "div",
10139
11060
  {
10140
11061
  className: "function-command-menu operator-command-menu",
@@ -10145,7 +11066,7 @@ ${arabic || currentMessages.empty}`;
10145
11066
  }
10146
11067
  },
10147
11068
  children: [
10148
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
11069
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10149
11070
  "button",
10150
11071
  {
10151
11072
  className: "icon-btn function-command-btn operator-command-btn",
@@ -10158,7 +11079,7 @@ ${arabic || currentMessages.empty}`;
10158
11079
  children: renderOperatorMenuButtonLabel(INTEGRAL_COMMANDS[0], "\u222B")
10159
11080
  }
10160
11081
  ),
10161
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "function-command-options operator-command-options", role: "listbox", "aria-label": messages.insertIntegrals, hidden: !integralMenuOpen, children: INTEGRAL_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
11082
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "function-command-options operator-command-options", role: "listbox", "aria-label": messages.insertIntegrals, hidden: !integralMenuOpen, children: INTEGRAL_COMMANDS.map((command) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10162
11083
  "button",
10163
11084
  {
10164
11085
  className: "function-command-option operator-command-option",
@@ -10172,7 +11093,7 @@ ${arabic || currentMessages.empty}`;
10172
11093
  setIntegralMenuOpen(false);
10173
11094
  focusSurface();
10174
11095
  },
10175
- children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: shouldMirrorOperatorDisplay(command) ? "operator-command-label operator-command-label--mirror" : "operator-command-label", children: renderOperatorCommandLabel(command) })
11096
+ children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: shouldMirrorOperatorDisplay(command) ? "operator-command-label operator-command-label--mirror" : "operator-command-label", children: renderOperatorCommandLabel(command) })
10176
11097
  },
10177
11098
  command.id
10178
11099
  )) })
@@ -10180,28 +11101,28 @@ ${arabic || currentMessages.empty}`;
10180
11101
  }
10181
11102
  )
10182
11103
  ] }),
10183
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "toolbar-group toolbar-scripts", role: "group", "aria-label": messages.scripts, children: [
10184
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { className: "icon-btn script-icon-btn", type: "button", title: messages.addSuperscript, "aria-label": messages.addSuperscript, onClick: () => runtimeRef.current?.addSup(), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "toolbar-script-icon toolbar-script-icon--sup", "aria-hidden": "true", children: [
10185
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "\u0646" }),
10186
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "\u0633" })
11104
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "toolbar-group toolbar-scripts", role: "group", "aria-label": messages.scripts, children: [
11105
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { className: "icon-btn script-icon-btn", type: "button", title: messages.addSuperscript, "aria-label": messages.addSuperscript, onClick: () => runtimeRef.current?.addSup(), children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "toolbar-script-icon toolbar-script-icon--sup", "aria-hidden": "true", children: [
11106
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "\u0646" }),
11107
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "\u0633" })
10187
11108
  ] }) }),
10188
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { className: "icon-btn script-icon-btn", type: "button", title: messages.addSubscript, "aria-label": messages.addSubscript, onClick: () => runtimeRef.current?.addSub(), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "toolbar-script-icon toolbar-script-icon--sub", "aria-hidden": "true", children: [
10189
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "\u0646" }),
10190
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "\u0633" })
11109
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { className: "icon-btn script-icon-btn", type: "button", title: messages.addSubscript, "aria-label": messages.addSubscript, onClick: () => runtimeRef.current?.addSub(), children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "toolbar-script-icon toolbar-script-icon--sub", "aria-hidden": "true", children: [
11110
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "\u0646" }),
11111
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "\u0633" })
10191
11112
  ] }) }),
10192
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { className: "icon-btn script-icon-btn remove-script-btn", type: "button", title: messages.removeSuperscript, "aria-label": messages.removeSuperscript, onClick: () => runtimeRef.current?.removeSup(), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "toolbar-remove-script-icon toolbar-remove-script-icon--sup", "aria-hidden": "true", children: [
10193
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "\u0646" }),
10194
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "\xD7" })
11113
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { className: "icon-btn script-icon-btn remove-script-btn", type: "button", title: messages.removeSuperscript, "aria-label": messages.removeSuperscript, onClick: () => runtimeRef.current?.removeSup(), children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "toolbar-remove-script-icon toolbar-remove-script-icon--sup", "aria-hidden": "true", children: [
11114
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "\u0646" }),
11115
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "\xD7" })
10195
11116
  ] }) }),
10196
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { className: "icon-btn script-icon-btn remove-script-btn", type: "button", title: messages.removeSubscript, "aria-label": messages.removeSubscript, onClick: () => runtimeRef.current?.removeSub(), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("span", { className: "toolbar-remove-script-icon toolbar-remove-script-icon--sub", "aria-hidden": "true", children: [
10197
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "\u0646" }),
10198
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { children: "\xD7" })
11117
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { className: "icon-btn script-icon-btn remove-script-btn", type: "button", title: messages.removeSubscript, "aria-label": messages.removeSubscript, onClick: () => runtimeRef.current?.removeSub(), children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("span", { className: "toolbar-remove-script-icon toolbar-remove-script-icon--sub", "aria-hidden": "true", children: [
11118
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "\u0646" }),
11119
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { children: "\xD7" })
10199
11120
  ] }) })
10200
11121
  ] }),
10201
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "toolbar-group toolbar-settings", role: "group", "aria-label": messages.inputStyles, children: [
10202
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { className: "icon-btn delete-node-btn", type: "button", title: messages.deleteSelectedStructure, "aria-label": messages.deleteSelectedStructure, onClick: () => runtimeRef.current?.deleteStructure(), children: "\xD7" }),
10203
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("button", { ref: splitTypingBtnRef, id: "toggle-split-leaf-typing", className: "icon-btn ligature-btn", type: "button", title: messages.toggleLetterMerging, "aria-label": messages.toggleLetterMerging, onClick: () => runtimeRef.current?.toggleSplitLeafTyping(), children: "\u0633\u0635\u0639" }),
10204
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
11122
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "toolbar-group toolbar-settings", role: "group", "aria-label": messages.inputStyles, children: [
11123
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { className: "icon-btn delete-node-btn", type: "button", title: messages.deleteSelectedStructure, "aria-label": messages.deleteSelectedStructure, onClick: () => runtimeRef.current?.deleteStructure(), children: "\xD7" }),
11124
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { ref: splitTypingBtnRef, id: "toggle-split-leaf-typing", className: "icon-btn ligature-btn", type: "button", title: messages.toggleLetterMerging, "aria-label": messages.toggleLetterMerging, onClick: () => runtimeRef.current?.toggleSplitLeafTyping(), children: "\u0633\u0635\u0639" }),
11125
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10205
11126
  "div",
10206
11127
  {
10207
11128
  className: "character-font-menu",
@@ -10212,7 +11133,7 @@ ${arabic || currentMessages.empty}`;
10212
11133
  }
10213
11134
  },
10214
11135
  children: [
10215
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
11136
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10216
11137
  "button",
10217
11138
  {
10218
11139
  ref: characterFontBtnRef,
@@ -10227,7 +11148,7 @@ ${arabic || currentMessages.empty}`;
10227
11148
  children: characterFontOption(selectedCharacterFont).label
10228
11149
  }
10229
11150
  ),
10230
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "character-font-options", role: "listbox", "aria-label": messages.chooseWritingFont, hidden: !characterFontMenuOpen, children: CHARACTER_FONT_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
11151
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "character-font-options", role: "listbox", "aria-label": messages.chooseWritingFont, hidden: !characterFontMenuOpen, children: CHARACTER_FONT_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10231
11152
  "button",
10232
11153
  {
10233
11154
  type: "button",
@@ -10249,7 +11170,7 @@ ${arabic || currentMessages.empty}`;
10249
11170
  ]
10250
11171
  }
10251
11172
  ),
10252
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
11173
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
10253
11174
  "div",
10254
11175
  {
10255
11176
  className: "digit-form-menu",
@@ -10260,7 +11181,7 @@ ${arabic || currentMessages.empty}`;
10260
11181
  }
10261
11182
  },
10262
11183
  children: [
10263
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
11184
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10264
11185
  "button",
10265
11186
  {
10266
11187
  ref: digitFormBtnRef,
@@ -10272,10 +11193,10 @@ ${arabic || currentMessages.empty}`;
10272
11193
  "aria-haspopup": "listbox",
10273
11194
  "aria-expanded": digitMenuOpen,
10274
11195
  onClick: () => setDigitMenuOpen((open) => !open),
10275
- children: digitFormLabel(selectedDigitForm2)
11196
+ children: digitFormLabel2(selectedDigitForm2)
10276
11197
  }
10277
11198
  ),
10278
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "digit-form-options", role: "listbox", "aria-label": messages.chooseDigitForm, hidden: !digitMenuOpen, children: DIGIT_FORM_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
11199
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "digit-form-options", role: "listbox", "aria-label": messages.chooseDigitForm, hidden: !digitMenuOpen, children: DIGIT_FORM_OPTIONS.map((option) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10279
11200
  "button",
10280
11201
  {
10281
11202
  type: "button",
@@ -10299,7 +11220,7 @@ ${arabic || currentMessages.empty}`;
10299
11220
  )
10300
11221
  ] })
10301
11222
  ] }),
10302
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
11223
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10303
11224
  "div",
10304
11225
  {
10305
11226
  ref: surfaceRef,
@@ -10309,18 +11230,18 @@ ${arabic || currentMessages.empty}`;
10309
11230
  "aria-label": messages.equationEditor
10310
11231
  }
10311
11232
  ),
10312
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { ref: renderErrorRef, className: "error", hidden: true })
11233
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { ref: renderErrorRef, className: "error", hidden: true })
10313
11234
  ] }),
10314
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("section", { className: "panel panel-preview", "aria-label": messages.renderPreview, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { ref: mathOutputRef, className: "preview-box" }) }),
10315
- debug ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("section", { className: "panel", children: [
10316
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "dev-strip", children: [
10317
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: "dev-badge", children: messages.development }),
10318
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { ref: latexLinesRef, className: "ascii" }),
10319
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { ref: passivePreviewRef, className: "passive-preview-text" })
11235
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("section", { className: "panel panel-preview", "aria-label": messages.renderPreview, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { ref: mathOutputRef, className: "preview-box" }) }),
11236
+ debug ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("section", { className: "panel", children: [
11237
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "dev-strip", children: [
11238
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: "dev-badge", children: messages.development }),
11239
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { ref: latexLinesRef, className: "ascii" }),
11240
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { ref: passivePreviewRef, className: "passive-preview-text" })
10320
11241
  ] }),
10321
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { style: { marginTop: 12 }, children: [
10322
- /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)("div", { className: "debug-head", children: [
10323
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
11242
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { style: { marginTop: 12 }, children: [
11243
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "debug-head", children: [
11244
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10324
11245
  "button",
10325
11246
  {
10326
11247
  type: "button",
@@ -10340,7 +11261,7 @@ ${arabic || currentMessages.empty}`;
10340
11261
  children: debugBodyHidden ? messages.showDebugLog : messages.hideDebugLog
10341
11262
  }
10342
11263
  ),
10343
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
11264
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
10344
11265
  "button",
10345
11266
  {
10346
11267
  type: "button",
@@ -10355,7 +11276,7 @@ ${arabic || currentMessages.empty}`;
10355
11276
  }
10356
11277
  )
10357
11278
  ] }),
10358
- /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { ref: debugLogRef, className: "debug-log" })
11279
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { ref: debugLogRef, className: "debug-log" })
10359
11280
  ] })
10360
11281
  ] }) : null
10361
11282
  ] })
@@ -10366,7 +11287,7 @@ ${arabic || currentMessages.empty}`;
10366
11287
  ButexEditor.displayName = "ButexEditor";
10367
11288
 
10368
11289
  // src/react-document2/EquationDrawer.tsx
10369
- var import_jsx_runtime9 = require("react/jsx-runtime");
11290
+ var import_jsx_runtime11 = require("react/jsx-runtime");
10370
11291
  function EquationDrawer({
10371
11292
  session,
10372
11293
  reason,
@@ -10380,8 +11301,8 @@ function EquationDrawer({
10380
11301
  onDelete
10381
11302
  }) {
10382
11303
  const messages = document2Messages(uiLocale);
10383
- const latestSession = (0, import_react5.useRef)(session);
10384
- (0, import_react5.useEffect)(() => {
11304
+ const latestSession = (0, import_react7.useRef)(session);
11305
+ (0, import_react7.useEffect)(() => {
10385
11306
  const onKeyDown = (event) => {
10386
11307
  if (event.key === "Escape") {
10387
11308
  onClose();
@@ -10390,8 +11311,8 @@ function EquationDrawer({
10390
11311
  window.addEventListener("keydown", onKeyDown);
10391
11312
  return () => window.removeEventListener("keydown", onKeyDown);
10392
11313
  }, [onClose]);
10393
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "butex-document2-widget__equation-modal", role: "presentation", children: [
10394
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
11314
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "butex-document2-widget__equation-modal", role: "presentation", children: [
11315
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
10395
11316
  "button",
10396
11317
  {
10397
11318
  type: "button",
@@ -10400,7 +11321,7 @@ function EquationDrawer({
10400
11321
  onClick: onClose
10401
11322
  }
10402
11323
  ),
10403
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
11324
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(
10404
11325
  "div",
10405
11326
  {
10406
11327
  className: "butex-document2-widget__equation-modal-panel",
@@ -10410,22 +11331,22 @@ function EquationDrawer({
10410
11331
  dir: uiLocaleDirection(uiLocale),
10411
11332
  lang: uiLocale,
10412
11333
  children: [
10413
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "butex-document2-widget__row", children: [
10414
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("strong", { id: "butex-document2-equation-modal-title", children: messages.equationEditorTitle }),
10415
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { type: "button", onClick: onClose, children: messages.close })
11334
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "butex-document2-widget__row", children: [
11335
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("strong", { id: "butex-document2-equation-modal-title", children: messages.equationEditorTitle }),
11336
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: onClose, children: messages.close })
10416
11337
  ] }),
10417
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "butex-document2-widget__row", role: "group", "aria-label": messages.equationType, children: [
10418
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("button", { type: "button", "aria-pressed": mathMode === "inline", onClick: () => onMathModeChange("inline"), children: [
11338
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "butex-document2-widget__row", role: "group", "aria-label": messages.equationType, children: [
11339
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("button", { type: "button", "aria-pressed": mathMode === "inline", onClick: () => onMathModeChange("inline"), children: [
10419
11340
  messages.inline,
10420
11341
  " ($)"
10421
11342
  ] }),
10422
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("button", { type: "button", "aria-pressed": mathMode === "display", onClick: () => onMathModeChange("display"), children: [
11343
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("button", { type: "button", "aria-pressed": mathMode === "display", onClick: () => onMathModeChange("display"), children: [
10423
11344
  messages.displayed,
10424
11345
  " (\\\\[)"
10425
11346
  ] })
10426
11347
  ] }),
10427
- reason ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "butex-document2-widget__error", children: uiLocale === "en" ? messages.equationUnavailable : reason }) : null,
10428
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
11348
+ reason ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("p", { className: "butex-document2-widget__error", children: uiLocale === "en" ? messages.equationUnavailable : reason }) : null,
11349
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
10429
11350
  ButexEditor,
10430
11351
  {
10431
11352
  debug: false,
@@ -10437,9 +11358,9 @@ function EquationDrawer({
10437
11358
  }
10438
11359
  }
10439
11360
  ),
10440
- /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "butex-document2-widget__row", children: [
10441
- canDelete && onDelete ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { type: "button", className: "butex-document2-widget__button--danger", onClick: onDelete, children: messages.deleteEquation }) : null,
10442
- /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("button", { type: "button", onClick: () => onSave({ ...latestSession.current, activeSide: equationSide }), children: messages.saveEquation })
11361
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "butex-document2-widget__row", children: [
11362
+ canDelete && onDelete ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", className: "butex-document2-widget__button--danger", onClick: onDelete, children: messages.deleteEquation }) : null,
11363
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: () => onSave({ ...latestSession.current, activeSide: equationSide }), children: messages.saveEquation })
10443
11364
  ] })
10444
11365
  ]
10445
11366
  }
@@ -10447,6 +11368,108 @@ function EquationDrawer({
10447
11368
  ] });
10448
11369
  }
10449
11370
 
11371
+ // src/react-document2/ReferencesPanel.tsx
11372
+ var import_react8 = require("react");
11373
+ var import_jsx_runtime12 = require("react/jsx-runtime");
11374
+ var EMPTY_DRAFT = { key: "", authors: "", title: "", year: "", url: "", venue: "" };
11375
+ function ReferencesPanel({
11376
+ open,
11377
+ references,
11378
+ uiLocale = "ar",
11379
+ onClose,
11380
+ onAdd,
11381
+ onUpdate,
11382
+ onRemove,
11383
+ onMove
11384
+ }) {
11385
+ const messages = document2Messages(uiLocale);
11386
+ const [draft, setDraft] = (0, import_react8.useState)(EMPTY_DRAFT);
11387
+ if (!open) {
11388
+ return null;
11389
+ }
11390
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "butex-document2-widget__refs-backdrop", role: "presentation", onClick: onClose, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "butex-document2-widget__refs-panel", role: "dialog", "aria-label": messages.referencesTitle, onClick: (event) => event.stopPropagation(), children: [
11391
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("header", { className: "butex-document2-widget__refs-header", children: [
11392
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("strong", { children: messages.referencesTitle }),
11393
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("button", { type: "button", className: "butex-document2-widget__icon-btn", title: messages.close, "aria-label": messages.close, onClick: onClose, children: "\xD7" })
11394
+ ] }),
11395
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "butex-document2-widget__refs-add", children: [
11396
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("h3", { children: messages.addReference }),
11397
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "butex-document2-widget__refs-grid", children: [
11398
+ ["key", messages.referenceKey],
11399
+ ["authors", messages.referenceAuthors],
11400
+ ["title", messages.referenceTitle],
11401
+ ["year", messages.referenceYear],
11402
+ ["venue", messages.referenceVenue],
11403
+ ["url", messages.referenceUrl]
11404
+ ].map(([field, label]) => /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("label", { className: "butex-document2-widget__refs-field", children: [
11405
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { children: label }),
11406
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
11407
+ "input",
11408
+ {
11409
+ value: draft[field] ?? "",
11410
+ onChange: (event) => setDraft((current) => ({ ...current, [field]: event.currentTarget.value }))
11411
+ }
11412
+ )
11413
+ ] }, field)) }),
11414
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
11415
+ "button",
11416
+ {
11417
+ type: "button",
11418
+ className: "butex-document2-widget__primary-btn",
11419
+ disabled: !draft.key?.trim(),
11420
+ onClick: () => {
11421
+ onAdd(draft);
11422
+ setDraft(EMPTY_DRAFT);
11423
+ },
11424
+ children: messages.addReference
11425
+ }
11426
+ )
11427
+ ] }),
11428
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("ul", { className: "butex-document2-widget__refs-list", children: references.map((reference, index) => /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("li", { className: "butex-document2-widget__refs-item", children: [
11429
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "butex-document2-widget__refs-item-head", children: [
11430
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("strong", { children: [
11431
+ "[",
11432
+ index + 1,
11433
+ "] ",
11434
+ reference.key
11435
+ ] }),
11436
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "butex-document2-widget__refs-item-actions", children: [
11437
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("button", { type: "button", title: messages.moveUp, "aria-label": messages.moveUp, disabled: index === 0, onClick: () => onMove(reference.id, -1), children: "\u2191" }),
11438
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
11439
+ "button",
11440
+ {
11441
+ type: "button",
11442
+ title: messages.moveDown,
11443
+ "aria-label": messages.moveDown,
11444
+ disabled: index === references.length - 1,
11445
+ onClick: () => onMove(reference.id, 1),
11446
+ children: "\u2193"
11447
+ }
11448
+ ),
11449
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("button", { type: "button", title: messages.deleteReference, "aria-label": messages.deleteReference, onClick: () => onRemove(reference.id), children: "\xD7" })
11450
+ ] })
11451
+ ] }),
11452
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: "butex-document2-widget__refs-grid", children: [
11453
+ ["key", messages.referenceKey],
11454
+ ["authors", messages.referenceAuthors],
11455
+ ["title", messages.referenceTitle],
11456
+ ["year", messages.referenceYear],
11457
+ ["venue", messages.referenceVenue],
11458
+ ["url", messages.referenceUrl]
11459
+ ].map(([field, label]) => /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("label", { className: "butex-document2-widget__refs-field", children: [
11460
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("span", { children: label }),
11461
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
11462
+ "input",
11463
+ {
11464
+ value: reference[field],
11465
+ onChange: (event) => onUpdate(reference.id, { [field]: event.currentTarget.value })
11466
+ }
11467
+ )
11468
+ ] }, field)) })
11469
+ ] }, reference.id)) })
11470
+ ] }) });
11471
+ }
11472
+
10450
11473
  // src/react-document2/editorFocus.ts
10451
11474
  function createEmptyDocument2EditorFocus() {
10452
11475
  return { blockId: null, fieldId: null, textTokenId: null, caretOffset: 0 };
@@ -11342,6 +12365,223 @@ var DOCUMENT2_WIDGET_CSS = `
11342
12365
  transition: none;
11343
12366
  }
11344
12367
  }
12368
+
12369
+ .butex-document2-widget__cite-chip-wrap {
12370
+ align-items: center;
12371
+ display: inline-flex;
12372
+ gap: 2px;
12373
+ margin-inline: 2px;
12374
+ max-width: 100%;
12375
+ vertical-align: baseline;
12376
+ }
12377
+
12378
+ .butex-document2-widget__cite-chip {
12379
+ background: color-mix(in srgb, var(--butex-document2-accent) 8%, var(--butex-document2-panel));
12380
+ border: 1.5px solid color-mix(in srgb, var(--butex-document2-accent) 45%, var(--butex-document2-border));
12381
+ border-radius: 6px;
12382
+ color: inherit;
12383
+ cursor: pointer;
12384
+ display: inline-flex;
12385
+ font: inherit;
12386
+ font-variant-numeric: tabular-nums;
12387
+ line-height: 1.3;
12388
+ min-height: 28px;
12389
+ padding: 2px 8px;
12390
+ }
12391
+
12392
+ .butex-document2-widget__cite-chip[data-editable="false"] {
12393
+ border-style: dashed;
12394
+ cursor: default;
12395
+ }
12396
+
12397
+ .butex-document2-widget__cite-chip:hover,
12398
+ .butex-document2-widget__cite-chip:focus-visible {
12399
+ background: color-mix(in srgb, var(--butex-document2-accent) 14%, var(--butex-document2-panel));
12400
+ border-color: var(--butex-document2-accent);
12401
+ }
12402
+
12403
+ .butex-document2-widget__cite-chip-delete {
12404
+ background: transparent;
12405
+ border: none;
12406
+ color: var(--butex-document2-muted);
12407
+ cursor: pointer;
12408
+ font: inherit;
12409
+ line-height: 1;
12410
+ padding: 0 4px;
12411
+ }
12412
+
12413
+ .butex-document2-widget__preview-cite {
12414
+ color: inherit;
12415
+ font-variant-numeric: tabular-nums;
12416
+ white-space: nowrap;
12417
+ }
12418
+
12419
+ .butex-document2-widget__preview-bibliography,
12420
+ .butex-document2-widget__bibliography-editor {
12421
+ display: grid;
12422
+ gap: 0.5rem;
12423
+ list-style: none;
12424
+ margin: 0;
12425
+ padding: 0;
12426
+ }
12427
+
12428
+ .butex-document2-widget__preview-bibliography li,
12429
+ .butex-document2-widget__bibliography-editor li {
12430
+ display: grid;
12431
+ gap: 0.25rem;
12432
+ grid-template-columns: auto 1fr;
12433
+ }
12434
+
12435
+ .butex-document2-widget__preview-bib-number {
12436
+ font-variant-numeric: tabular-nums;
12437
+ }
12438
+
12439
+ .butex-document2-widget__block--bibliography {
12440
+ border-color: color-mix(in srgb, var(--butex-document2-accent) 35%, var(--butex-document2-border));
12441
+ }
12442
+
12443
+ .butex-document2-widget__digit-form-menu {
12444
+ position: relative;
12445
+ }
12446
+
12447
+ .butex-document2-widget__digit-form-options {
12448
+ background: var(--butex-document2-panel);
12449
+ border: 1px solid var(--butex-document2-border);
12450
+ border-radius: 8px;
12451
+ box-shadow: 0 8px 24px color-mix(in srgb, #000 16%, transparent);
12452
+ display: grid;
12453
+ gap: 2px;
12454
+ inset-inline-start: 0;
12455
+ margin-top: 4px;
12456
+ padding: 4px;
12457
+ position: absolute;
12458
+ top: 100%;
12459
+ z-index: 5;
12460
+ }
12461
+
12462
+ .butex-document2-widget__digit-form-option {
12463
+ background: transparent;
12464
+ border: none;
12465
+ border-radius: 6px;
12466
+ color: inherit;
12467
+ cursor: pointer;
12468
+ font: inherit;
12469
+ padding: 6px 10px;
12470
+ text-align: start;
12471
+ }
12472
+
12473
+ .butex-document2-widget__digit-form-option[aria-selected="true"],
12474
+ .butex-document2-widget__digit-form-option:hover {
12475
+ background: color-mix(in srgb, var(--butex-document2-accent) 12%, var(--butex-document2-panel));
12476
+ }
12477
+
12478
+ .butex-document2-widget__cite-picker-backdrop,
12479
+ .butex-document2-widget__refs-backdrop {
12480
+ align-items: center;
12481
+ background: color-mix(in srgb, #000 35%, transparent);
12482
+ display: flex;
12483
+ inset: 0;
12484
+ justify-content: center;
12485
+ padding: 1rem;
12486
+ position: fixed;
12487
+ z-index: 40;
12488
+ }
12489
+
12490
+ .butex-document2-widget__cite-picker,
12491
+ .butex-document2-widget__refs-panel {
12492
+ background: var(--butex-document2-panel);
12493
+ border: 1px solid var(--butex-document2-border);
12494
+ border-radius: 12px;
12495
+ box-shadow: 0 16px 40px color-mix(in srgb, #000 22%, transparent);
12496
+ display: grid;
12497
+ gap: 0.75rem;
12498
+ max-height: min(80vh, 640px);
12499
+ max-width: 560px;
12500
+ overflow: auto;
12501
+ padding: 1rem;
12502
+ width: min(100%, 560px);
12503
+ }
12504
+
12505
+ .butex-document2-widget__cite-picker-header,
12506
+ .butex-document2-widget__refs-header,
12507
+ .butex-document2-widget__cite-picker-footer,
12508
+ .butex-document2-widget__refs-item-head {
12509
+ align-items: center;
12510
+ display: flex;
12511
+ gap: 0.5rem;
12512
+ justify-content: space-between;
12513
+ }
12514
+
12515
+ .butex-document2-widget__cite-picker-list,
12516
+ .butex-document2-widget__refs-list {
12517
+ display: grid;
12518
+ gap: 0.5rem;
12519
+ list-style: none;
12520
+ margin: 0;
12521
+ padding: 0;
12522
+ }
12523
+
12524
+ .butex-document2-widget__cite-picker-item,
12525
+ .butex-document2-widget__refs-field {
12526
+ display: grid;
12527
+ gap: 0.25rem;
12528
+ }
12529
+
12530
+ .butex-document2-widget__cite-picker-item {
12531
+ align-items: start;
12532
+ grid-template-columns: auto 1fr;
12533
+ }
12534
+
12535
+ .butex-document2-widget__cite-picker-meta,
12536
+ .butex-document2-widget__cite-picker-empty {
12537
+ color: var(--butex-document2-muted);
12538
+ display: block;
12539
+ font-size: 0.92em;
12540
+ }
12541
+
12542
+ .butex-document2-widget__refs-grid {
12543
+ display: grid;
12544
+ gap: 0.5rem;
12545
+ grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
12546
+ }
12547
+
12548
+ .butex-document2-widget__refs-field input {
12549
+ background: var(--butex-document2-input-bg, var(--butex-document2-panel));
12550
+ border: 1px solid var(--butex-document2-border);
12551
+ border-radius: 6px;
12552
+ color: inherit;
12553
+ font: inherit;
12554
+ padding: 0.4rem 0.55rem;
12555
+ width: 100%;
12556
+ }
12557
+
12558
+ .butex-document2-widget__refs-item {
12559
+ border: 1px solid var(--butex-document2-border);
12560
+ border-radius: 10px;
12561
+ display: grid;
12562
+ gap: 0.5rem;
12563
+ padding: 0.75rem;
12564
+ }
12565
+
12566
+ .butex-document2-widget__refs-item-actions {
12567
+ display: inline-flex;
12568
+ gap: 0.25rem;
12569
+ }
12570
+
12571
+ .butex-document2-widget__primary-btn {
12572
+ background: var(--butex-document2-accent);
12573
+ border: none;
12574
+ border-radius: 8px;
12575
+ color: #fff;
12576
+ cursor: pointer;
12577
+ font: inherit;
12578
+ padding: 0.45rem 0.8rem;
12579
+ }
12580
+
12581
+ .butex-document2-widget__primary-btn:disabled {
12582
+ cursor: not-allowed;
12583
+ opacity: 0.55;
12584
+ }
11345
12585
  `;
11346
12586
  function injectBuTeXDocument2Styles(doc) {
11347
12587
  const d = doc ?? (typeof document !== "undefined" ? document : void 0);
@@ -11359,7 +12599,7 @@ function injectBuTeXDocument2Styles(doc) {
11359
12599
  }
11360
12600
 
11361
12601
  // src/react-document2/ButexDocumentEditor2.tsx
11362
- var import_jsx_runtime10 = require("react/jsx-runtime");
12602
+ var import_jsx_runtime13 = require("react/jsx-runtime");
11363
12603
  function mathDelimiters(mode) {
11364
12604
  return mode === "inline" ? { opening: "$", closing: "$" } : { opening: "\\[", closing: "\\]" };
11365
12605
  }
@@ -11540,32 +12780,42 @@ function ButexDocumentEditor2({
11540
12780
  previewOnly = false,
11541
12781
  uiLocale = "ar",
11542
12782
  mathOutput = "svg",
12783
+ digitForm: digitFormProp,
12784
+ onDigitFormChange,
12785
+ resolveImageUrl,
11543
12786
  onDocumentChange,
11544
12787
  onLatexChange
11545
12788
  }) {
11546
12789
  const messages = document2Messages(uiLocale);
11547
- const initialState = (0, import_react6.useMemo)(() => resolveInitialDocument2(initialDocument, uiLocale), [initialDocument]);
11548
- const [documentNode, setDocumentNode] = (0, import_react6.useState)(initialState.document);
11549
- const [error, setError] = (0, import_react6.useState)(initialState.error);
11550
- const [editorOpen, setEditorOpen] = (0, import_react6.useState)(true);
11551
- const [previewOpen, setPreviewOpen] = (0, import_react6.useState)(true);
11552
- const [selectedMath, setSelectedMath] = (0, import_react6.useState)(null);
11553
- const [editorFocus, setEditorFocus] = (0, import_react6.useState)(createEmptyDocument2EditorFocus());
11554
- const [collapsedBlockIds, setCollapsedBlockIds] = (0, import_react6.useState)(() => /* @__PURE__ */ new Set());
11555
- const [historyTick, setHistoryTick] = (0, import_react6.useState)(0);
11556
- const historyRef = (0, import_react6.useRef)(createDocument2History());
11557
- const documentRef = (0, import_react6.useRef)(documentNode);
11558
- const textSnapshotArmedRef = (0, import_react6.useRef)(false);
11559
- const textDebounceRef = (0, import_react6.useRef)(null);
11560
- const widgetRef = (0, import_react6.useRef)(null);
11561
- const pendingFocusRef = (0, import_react6.useRef)(null);
12790
+ const initialState = (0, import_react9.useMemo)(() => resolveInitialDocument2(initialDocument, uiLocale), [initialDocument]);
12791
+ const [documentNode, setDocumentNode] = (0, import_react9.useState)(initialState.document);
12792
+ const [error, setError] = (0, import_react9.useState)(initialState.error);
12793
+ const [editorOpen, setEditorOpen] = (0, import_react9.useState)(true);
12794
+ const [previewOpen, setPreviewOpen] = (0, import_react9.useState)(true);
12795
+ const [selectedMath, setSelectedMath] = (0, import_react9.useState)(null);
12796
+ const [citePicker, setCitePicker] = (0, import_react9.useState)(null);
12797
+ const [referencesOpen, setReferencesOpen] = (0, import_react9.useState)(false);
12798
+ const [digitFormState, setDigitFormState] = (0, import_react9.useState)(null);
12799
+ const [editorFocus, setEditorFocus] = (0, import_react9.useState)(createEmptyDocument2EditorFocus());
12800
+ const [collapsedBlockIds, setCollapsedBlockIds] = (0, import_react9.useState)(() => /* @__PURE__ */ new Set());
12801
+ const [historyTick, setHistoryTick] = (0, import_react9.useState)(0);
12802
+ const digitForm = digitFormProp ?? digitFormState ?? (documentDirection === "rtl" ? "arabicIndic" : "western");
12803
+ const historyRef = (0, import_react9.useRef)(createDocument2History());
12804
+ const documentRef = (0, import_react9.useRef)(documentNode);
12805
+ const textSnapshotArmedRef = (0, import_react9.useRef)(false);
12806
+ const textDebounceRef = (0, import_react9.useRef)(null);
12807
+ const widgetRef = (0, import_react9.useRef)(null);
12808
+ const pendingFocusRef = (0, import_react9.useRef)(null);
11562
12809
  documentRef.current = documentNode;
11563
12810
  const latex = document2Latex(documentNode);
11564
- const preview = (0, import_react6.useMemo)(
11565
- () => document2Preview(documentNode, mathOutput, equationSide),
11566
- [documentNode, equationSide, mathOutput]
12811
+ const preview = (0, import_react9.useMemo)(
12812
+ () => document2Preview(documentNode, mathOutput, equationSide, {
12813
+ documentDirection,
12814
+ digitForm
12815
+ }),
12816
+ [documentNode, documentDirection, digitForm, equationSide, mathOutput]
11567
12817
  );
11568
- const debugEnabled = (0, import_react6.useMemo)(() => {
12818
+ const debugEnabled = (0, import_react9.useMemo)(() => {
11569
12819
  if (debug) {
11570
12820
  return true;
11571
12821
  }
@@ -11574,17 +12824,17 @@ function ButexDocumentEditor2({
11574
12824
  }
11575
12825
  return new URLSearchParams(window.location.search).get("debug") === "1";
11576
12826
  }, [debug]);
11577
- const canUndo = (0, import_react6.useMemo)(() => document2HistoryCanUndo(historyRef.current), [historyTick, documentNode]);
11578
- const canRedo = (0, import_react6.useMemo)(() => document2HistoryCanRedo(historyRef.current), [historyTick, documentNode]);
11579
- (0, import_react6.useEffect)(() => {
12827
+ const canUndo = (0, import_react9.useMemo)(() => document2HistoryCanUndo(historyRef.current), [historyTick, documentNode]);
12828
+ const canRedo = (0, import_react9.useMemo)(() => document2HistoryCanRedo(historyRef.current), [historyTick, documentNode]);
12829
+ (0, import_react9.useEffect)(() => {
11580
12830
  injectBuTeXDocument2Styles();
11581
12831
  }, []);
11582
- (0, import_react6.useEffect)(() => {
12832
+ (0, import_react9.useEffect)(() => {
11583
12833
  if (!editableEquations || previewOnly) {
11584
12834
  setSelectedMath(null);
11585
12835
  }
11586
12836
  }, [editableEquations, previewOnly]);
11587
- (0, import_react6.useEffect)(() => {
12837
+ (0, import_react9.useEffect)(() => {
11588
12838
  const next = resolveInitialDocument2(initialDocument, uiLocale);
11589
12839
  setDocumentNode(next.document);
11590
12840
  setError(next.error);
@@ -11593,13 +12843,13 @@ function ButexDocumentEditor2({
11593
12843
  historyRef.current = createDocument2History();
11594
12844
  setHistoryTick((tick) => tick + 1);
11595
12845
  }, [initialDocument]);
11596
- (0, import_react6.useEffect)(() => {
12846
+ (0, import_react9.useEffect)(() => {
11597
12847
  onDocumentChange?.(documentNode);
11598
12848
  }, [documentNode, onDocumentChange]);
11599
- (0, import_react6.useEffect)(() => {
12849
+ (0, import_react9.useEffect)(() => {
11600
12850
  onLatexChange?.(latex);
11601
12851
  }, [latex, onLatexChange]);
11602
- (0, import_react6.useEffect)(() => {
12852
+ (0, import_react9.useEffect)(() => {
11603
12853
  const pending = pendingFocusRef.current;
11604
12854
  const root = widgetRef.current;
11605
12855
  if (!pending || !root) {
@@ -11614,6 +12864,13 @@ function ButexDocumentEditor2({
11614
12864
  mathButton?.focus();
11615
12865
  return;
11616
12866
  }
12867
+ if (pending.kind === "cite") {
12868
+ const citeButton = Array.from(root.querySelectorAll("[data-cite-token-id]")).find(
12869
+ (button) => button.dataset.citeTokenId === pending.tokenId
12870
+ );
12871
+ citeButton?.focus();
12872
+ return;
12873
+ }
11617
12874
  const textarea = Array.from(root.querySelectorAll("textarea[data-field-id][data-text-token-id]")).find(
11618
12875
  (element) => element.dataset.fieldId === pending.fieldId && element.dataset.textTokenId === pending.textTokenId
11619
12876
  );
@@ -11625,10 +12882,10 @@ function ButexDocumentEditor2({
11625
12882
  textarea.setSelectionRange(safeOffset, safeOffset);
11626
12883
  });
11627
12884
  }, [documentNode]);
11628
- const bumpHistoryUi = (0, import_react6.useCallback)(() => {
12885
+ const bumpHistoryUi = (0, import_react9.useCallback)(() => {
11629
12886
  setHistoryTick((tick) => tick + 1);
11630
12887
  }, []);
11631
- const applyDocument = (0, import_react6.useCallback)(
12888
+ const applyDocument = (0, import_react9.useCallback)(
11632
12889
  (next, mode = "immediate") => {
11633
12890
  if (mode === "immediate") {
11634
12891
  pushDocument2Snapshot(historyRef.current, documentRef.current);
@@ -11650,7 +12907,7 @@ function ButexDocumentEditor2({
11650
12907
  },
11651
12908
  [bumpHistoryUi]
11652
12909
  );
11653
- const afterBlockId = (0, import_react6.useCallback)(() => resolveInsertAfterBlockId(documentRef.current, editorFocus), [editorFocus]);
12910
+ const afterBlockId = (0, import_react9.useCallback)(() => resolveInsertAfterBlockId(documentRef.current, editorFocus), [editorFocus]);
11654
12911
  function undoDocument() {
11655
12912
  const restored = restoreDocument2Undo(historyRef.current, documentRef.current);
11656
12913
  if (!restored) {
@@ -11699,7 +12956,7 @@ function ButexDocumentEditor2({
11699
12956
  function openAllBlocks() {
11700
12957
  setCollapsedBlockIds(/* @__PURE__ */ new Set());
11701
12958
  }
11702
- (0, import_react6.useEffect)(() => {
12959
+ (0, import_react9.useEffect)(() => {
11703
12960
  const root = widgetRef.current;
11704
12961
  if (!root) {
11705
12962
  return;
@@ -11872,24 +13129,70 @@ function ButexDocumentEditor2({
11872
13129
  pendingFocusRef.current = focusAfterDeletedMath(current, next, tokenId);
11873
13130
  applyDocument(next, "immediate");
11874
13131
  }
13132
+ function openCitePickerForInsert() {
13133
+ const target = resolveInsertField(documentRef.current, editorFocus);
13134
+ setCitePicker({
13135
+ tokenId: null,
13136
+ fieldId: target?.fieldId ?? null,
13137
+ textTokenId: target?.textTokenId ?? editorFocus.textTokenId,
13138
+ caretOffset: target?.caretOffset ?? editorFocus.caretOffset,
13139
+ keys: []
13140
+ });
13141
+ }
13142
+ function openCite(token) {
13143
+ setCitePicker({
13144
+ tokenId: token.id,
13145
+ fieldId: null,
13146
+ textTokenId: null,
13147
+ caretOffset: 0,
13148
+ keys: [...token.keys]
13149
+ });
13150
+ }
13151
+ function confirmCiteKeys(keys) {
13152
+ if (!citePicker || keys.length === 0) {
13153
+ setCitePicker(null);
13154
+ return;
13155
+ }
13156
+ if (citePicker.tokenId) {
13157
+ applyDocument(updateCiteTokenKeys(documentRef.current, citePicker.tokenId, keys), "immediate");
13158
+ pendingFocusRef.current = { kind: "cite", tokenId: citePicker.tokenId };
13159
+ setCitePicker(null);
13160
+ return;
13161
+ }
13162
+ const target = resolveInsertField(documentRef.current, editorFocus);
13163
+ const fieldId = citePicker.fieldId ?? target?.fieldId;
13164
+ if (!fieldId) {
13165
+ setCitePicker(null);
13166
+ return;
13167
+ }
13168
+ const textTokenId = citePicker.textTokenId ?? target?.textTokenId ?? null;
13169
+ const caretOffset = citePicker.caretOffset ?? target?.caretOffset ?? 0;
13170
+ const next = insertCiteTokenAtCaret(documentRef.current, fieldId, textTokenId, caretOffset, keys);
13171
+ applyDocument(next, "immediate");
13172
+ setCitePicker(null);
13173
+ }
13174
+ function deleteCiteToken(tokenId) {
13175
+ applyDocument(removeCiteTokenById(documentRef.current, tokenId), "immediate");
13176
+ }
11875
13177
  const showEditorPanel = !previewOnly && editorOpen;
11876
13178
  const showPreviewPanel = previewOnly || previewOpen;
11877
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
13179
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
11878
13180
  "div",
11879
13181
  {
11880
13182
  ref: widgetRef,
11881
13183
  className: ["butex-document2-widget", className].filter(Boolean).join(" "),
11882
13184
  dir: uiLocaleDirection(uiLocale),
11883
13185
  lang: uiLocale,
11884
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "butex-document2-widget__shell", children: [
11885
- !previewOnly ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "butex-document2-widget__toolbar", children: [
11886
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
13186
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "butex-document2-widget__shell", children: [
13187
+ !previewOnly ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "butex-document2-widget__toolbar", children: [
13188
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
11887
13189
  DocumentInsertToolbar,
11888
13190
  {
11889
13191
  canUndo,
11890
13192
  canRedo,
11891
13193
  editableEquations,
11892
13194
  uiLocale,
13195
+ digitForm,
11893
13196
  onUndo: undoDocument,
11894
13197
  onRedo: redoDocument,
11895
13198
  onAddSection: () => applyDocument(addDocument2TextBlock(documentRef.current, "\\section", afterBlockId()), "immediate"),
@@ -11901,45 +13204,57 @@ function ButexDocumentEditor2({
11901
13204
  onAddTable: (rowCount, colCount) => applyDocument(addDocument2TableBlock(documentRef.current, "l".repeat(colCount), rowCount, colCount, afterBlockId()), "immediate"),
11902
13205
  onAddList: () => applyDocument(addDocument2ListBlock(documentRef.current, false, afterBlockId()), "immediate"),
11903
13206
  onAddEnumerate: () => applyDocument(addDocument2ListBlock(documentRef.current, true, afterBlockId()), "immediate"),
11904
- onAddFigure: () => applyDocument(addDocument2ImageBlock(documentRef.current, "", afterBlockId()), "immediate")
13207
+ onAddFigure: () => applyDocument(addDocument2ImageBlock(documentRef.current, "", afterBlockId()), "immediate"),
13208
+ onInsertCitation: openCitePickerForInsert,
13209
+ onInsertBibliography: () => applyDocument(ensureDocument2BibliographyBlock(documentRef.current, afterBlockId()), "immediate"),
13210
+ onManageReferences: () => setReferencesOpen(true),
13211
+ onDigitFormChange: (next) => {
13212
+ setDigitFormState(next);
13213
+ onDigitFormChange?.(next);
13214
+ }
11905
13215
  }
11906
13216
  ),
11907
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "butex-document2-widget__toolbar-group", role: "group", "aria-label": messages.panels, children: [
11908
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", "aria-pressed": editorOpen, onClick: toggleEditorPanel, children: editorOpen ? messages.hideEditor : messages.editor }),
11909
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", "aria-pressed": previewOpen, onClick: togglePreviewPanel, children: previewOpen ? messages.hidePreview : messages.preview })
13217
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "butex-document2-widget__toolbar-group", role: "group", "aria-label": messages.panels, children: [
13218
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", "aria-pressed": editorOpen, onClick: toggleEditorPanel, children: editorOpen ? messages.hideEditor : messages.editor }),
13219
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", "aria-pressed": previewOpen, onClick: togglePreviewPanel, children: previewOpen ? messages.hidePreview : messages.preview })
11910
13220
  ] }),
11911
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "butex-document2-widget__toolbar-group", role: "group", "aria-label": messages.collapseBlocks, children: [
11912
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", onClick: collapseAllBlocks, children: messages.collapseAll }),
11913
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("button", { type: "button", onClick: openAllBlocks, children: messages.openAll })
13221
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "butex-document2-widget__toolbar-group", role: "group", "aria-label": messages.collapseBlocks, children: [
13222
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", onClick: collapseAllBlocks, children: messages.collapseAll }),
13223
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("button", { type: "button", onClick: openAllBlocks, children: messages.openAll })
11914
13224
  ] })
11915
13225
  ] }) : null,
11916
- error ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "butex-document2-widget__error", children: error }) : null,
11917
- /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
13226
+ error ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "butex-document2-widget__error", children: error }) : null,
13227
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
11918
13228
  "div",
11919
13229
  {
11920
13230
  className: `butex-document2-widget__layout butex-document2-widget__layout--editor-${showEditorPanel ? "open" : "closed"} butex-document2-widget__layout--preview-${showPreviewPanel ? "open" : "closed"}`,
11921
13231
  children: [
11922
- !previewOnly ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
13232
+ !previewOnly ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
11923
13233
  "section",
11924
13234
  {
11925
13235
  className: "butex-document2-widget__panel butex-document2-widget__editor-panel",
11926
13236
  "aria-label": messages.documentEditor,
11927
13237
  "aria-hidden": !showEditorPanel,
11928
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "butex-document2-widget__blocks", children: documentNode.blocks.map((block, blockIndex) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
13238
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "butex-document2-widget__blocks", children: documentNode.blocks.map((block, blockIndex) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
11929
13239
  BlockEditor,
11930
13240
  {
11931
13241
  block,
11932
13242
  blockIndex,
11933
13243
  blockCount: documentNode.blocks.length,
13244
+ references: documentNode.references,
11934
13245
  documentDirection,
13246
+ digitForm,
11935
13247
  mathOutput,
11936
13248
  equationSide,
11937
13249
  editableEquations,
13250
+ editableCitations: !previewOnly,
11938
13251
  uiLocale,
11939
13252
  isCollapsed: collapsedBlockIds.has(block.id),
11940
13253
  onTextChange: (fieldId, tokenId, text) => applyDocument(updateTextToken(documentRef.current, fieldId, tokenId, text), "text"),
11941
13254
  onOpenMath: openMath,
11942
13255
  onDeleteMath: editableEquations ? deleteMathToken : void 0,
13256
+ onOpenCite: openCite,
13257
+ onDeleteCite: deleteCiteToken,
11943
13258
  onRemoveBlock: (blockId) => applyDocument(removeDocument2BlockById(documentRef.current, blockId), "immediate"),
11944
13259
  onMoveBlock: (blockId, direction) => applyDocument(moveDocument2BlockById(documentRef.current, blockId, direction), "immediate"),
11945
13260
  onToggleCollapse: toggleBlockCollapse,
@@ -11949,35 +13264,45 @@ function ButexDocumentEditor2({
11949
13264
  onFieldBlur,
11950
13265
  onImageSrcChange: (blockId, value) => applyDocument(updateDocument2ImageValue(documentRef.current, blockId, value), "text"),
11951
13266
  onAddListItem: (listBlockId) => applyDocument(addDocument2ListItem(documentRef.current, listBlockId), "immediate"),
11952
- onRemoveListItem: (listBlockId, itemId) => applyDocument(removeDocument2ListItem(documentRef.current, listBlockId, itemId), "immediate")
13267
+ onRemoveListItem: (listBlockId, itemId) => applyDocument(removeDocument2ListItem(documentRef.current, listBlockId, itemId), "immediate"),
13268
+ onManageReferences: () => setReferencesOpen(true)
11953
13269
  },
11954
13270
  block.id
11955
13271
  )) })
11956
13272
  }
11957
13273
  ) : null,
11958
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
13274
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
11959
13275
  "section",
11960
13276
  {
11961
13277
  className: "butex-document2-widget__panel butex-document2-widget__preview-panel",
11962
13278
  "aria-label": messages.documentPreview,
11963
13279
  "aria-hidden": !showPreviewPanel,
11964
- children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(DocumentPreview, { blocks: preview.blocks, output: mathOutput, documentDirection, uiLocale })
13280
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
13281
+ DocumentPreview,
13282
+ {
13283
+ blocks: preview.blocks,
13284
+ output: mathOutput,
13285
+ documentDirection,
13286
+ uiLocale,
13287
+ resolveImageUrl
13288
+ }
13289
+ )
11965
13290
  }
11966
13291
  )
11967
13292
  ]
11968
13293
  }
11969
13294
  ),
11970
- debugEnabled ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "butex-document2-widget__dev", children: [
11971
- debugEnabled && documentNode.diagnostics.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_jsx_runtime10.Fragment, { children: [
11972
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("strong", { children: messages.importWarnings }),
11973
- documentNode.diagnostics.map((diagnostic) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "butex-document2-widget__dev-diagnostic", children: formatDocument2Diagnostic(diagnostic, messages) }, `${diagnostic.path}-${diagnostic.message}`))
13295
+ debugEnabled ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "butex-document2-widget__dev", children: [
13296
+ debugEnabled && documentNode.diagnostics.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
13297
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("strong", { children: messages.importWarnings }),
13298
+ documentNode.diagnostics.map((diagnostic) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "butex-document2-widget__dev-diagnostic", children: formatDocument2Diagnostic(diagnostic, messages) }, `${diagnostic.path}-${diagnostic.message}`))
11974
13299
  ] }) : null,
11975
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("strong", { children: "LaTeX" }),
11976
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("pre", { children: latex }),
11977
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("strong", { children: "AST" }),
11978
- /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("pre", { children: JSON.stringify(documentNode, null, 2) })
13300
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("strong", { children: "LaTeX" }),
13301
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("pre", { children: latex }),
13302
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("strong", { children: "AST" }),
13303
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("pre", { children: JSON.stringify(documentNode, null, 2) })
11979
13304
  ] }) : null,
11980
- !previewOnly && selectedMath ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
13305
+ !previewOnly && selectedMath ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
11981
13306
  EquationDrawer,
11982
13307
  {
11983
13308
  session: selectedMath.session,
@@ -11991,6 +13316,34 @@ function ButexDocumentEditor2({
11991
13316
  onSave: saveEquation,
11992
13317
  onDelete: deleteSelectedEquation
11993
13318
  }
13319
+ ) : null,
13320
+ !previewOnly ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
13321
+ CitePickerPopover,
13322
+ {
13323
+ open: citePicker !== null,
13324
+ references: documentNode.references,
13325
+ initialKeys: citePicker?.keys ?? [],
13326
+ uiLocale,
13327
+ onClose: () => setCitePicker(null),
13328
+ onConfirm: confirmCiteKeys,
13329
+ onManageReferences: () => {
13330
+ setCitePicker(null);
13331
+ setReferencesOpen(true);
13332
+ }
13333
+ }
13334
+ ) : null,
13335
+ !previewOnly ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
13336
+ ReferencesPanel,
13337
+ {
13338
+ open: referencesOpen,
13339
+ references: documentNode.references,
13340
+ uiLocale,
13341
+ onClose: () => setReferencesOpen(false),
13342
+ onAdd: (partial) => applyDocument(addDocument2Reference(documentRef.current, partial), "immediate"),
13343
+ onUpdate: (referenceId, patch) => applyDocument(updateDocument2Reference(documentRef.current, referenceId, patch), "immediate"),
13344
+ onRemove: (referenceId) => applyDocument(removeDocument2Reference(documentRef.current, referenceId), "immediate"),
13345
+ onMove: (referenceId, direction) => applyDocument(moveDocument2Reference(documentRef.current, referenceId, direction), "immediate")
13346
+ }
11994
13347
  ) : null
11995
13348
  ] })
11996
13349
  }