@drghaliasri/butex 7.1.1 → 7.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -483,12 +483,12 @@ var DelimiterNode = class extends BaseAstNode {
483
483
  leftDelimExpr;
484
484
  innerExpr;
485
485
  rightDelimExpr;
486
- constructor(leftDelimExpr, innerExpr, rightDelimExpr, state = null) {
486
+ constructor(leftDelimExpr2, innerExpr, rightDelimExpr2, state = null) {
487
487
  super(state);
488
488
  this.nodeType = "DelimiterObject";
489
- this.leftDelimExpr = leftDelimExpr;
489
+ this.leftDelimExpr = leftDelimExpr2;
490
490
  this.innerExpr = innerExpr;
491
- this.rightDelimExpr = rightDelimExpr;
491
+ this.rightDelimExpr = rightDelimExpr2;
492
492
  }
493
493
  latex() {
494
494
  return this.leftDelimExpr + this.innerExpr.latex() + this.rightDelimExpr + this.latexScripts();
@@ -2832,11 +2832,11 @@ function createEditorNode(kind, expr) {
2832
2832
  columnAlignments: null
2833
2833
  };
2834
2834
  }
2835
- function createDelimiterNode(leftDelimExpr, rightDelimExpr) {
2835
+ function createDelimiterNode(leftDelimExpr2, rightDelimExpr2) {
2836
2836
  return {
2837
2837
  ...createEditorNode("delimiter", ""),
2838
- leftDelimExpr,
2839
- rightDelimExpr,
2838
+ leftDelimExpr: leftDelimExpr2,
2839
+ rightDelimExpr: rightDelimExpr2,
2840
2840
  innerExpr: createEditorChain()
2841
2841
  };
2842
2842
  }
@@ -5263,11 +5263,11 @@ function insertAtomicOperatorCommand(session, commandId) {
5263
5263
  appendDebug(next, "insertAtomicOperatorCommand", commandId);
5264
5264
  return next;
5265
5265
  }
5266
- function insertDelimiterPair(session, leftDelimExpr, rightDelimExpr) {
5266
+ function insertDelimiterPair(session, leftDelimExpr2, rightDelimExpr2) {
5267
5267
  const base = replaceSelectionFirst(session);
5268
5268
  const next = cloneEditorSession(base);
5269
- const englishNode = createDelimiterNode(leftDelimExpr, rightDelimExpr);
5270
- const arabicNode = createDelimiterNode(leftDelimExpr, rightDelimExpr);
5269
+ const englishNode = createDelimiterNode(leftDelimExpr2, rightDelimExpr2);
5270
+ const arabicNode = createDelimiterNode(leftDelimExpr2, rightDelimExpr2);
5271
5271
  arabicNode.id = englishNode.id;
5272
5272
  if (arabicNode.innerExpr && englishNode.innerExpr) {
5273
5273
  arabicNode.innerExpr.id = englishNode.innerExpr.id;
@@ -5279,7 +5279,7 @@ function insertDelimiterPair(session, leftDelimExpr, rightDelimExpr) {
5279
5279
  };
5280
5280
  next.selectedStructureNodeId = null;
5281
5281
  syncSelectionToCaret(next);
5282
- appendDebug(next, "insertDelimiterPair", `${leftDelimExpr}${rightDelimExpr}`);
5282
+ appendDebug(next, "insertDelimiterPair", `${leftDelimExpr2}${rightDelimExpr2}`);
5283
5283
  return next;
5284
5284
  }
5285
5285
  function insertFraction(session) {
@@ -5963,6 +5963,22 @@ var DELIMITER_CSS = `
5963
5963
  transform-origin: center;
5964
5964
  }
5965
5965
  `.trim();
5966
+ function escapeDelimiterExpr(value) {
5967
+ return value.replace(/[.*+?^$()|[\]\\]/g, "\\$&");
5968
+ }
5969
+ function buildDelimiterExpr(prefixes, delimiters) {
5970
+ const prefixExpr = prefixes.map(escapeDelimiterExpr).join("|");
5971
+ const delimiterExpr = delimiters.map(escapeDelimiterExpr).join("|");
5972
+ return new RegExp(`^(?:(?:${prefixExpr}))?(?:${delimiterExpr})$`);
5973
+ }
5974
+ var leftDelimExpr = buildDelimiterExpr(
5975
+ ["\\left", "\\bigl", "\\Bigl", "\\biggl", "\\Biggl"],
5976
+ ["(", "[", "\\{", "\\lfloor", "\\lceil", "\\langle", "`", "|", "\\lvert", "\\vert", "\\lVert", "\\Vert"]
5977
+ );
5978
+ var rightDelimExpr = buildDelimiterExpr(
5979
+ ["\\right", "\\bigr", "\\Bigr", "\\biggr", "\\Biggr"],
5980
+ [")", "]", "\\}", "\\rfloor", "\\rceil", "\\rangle", "`", "|", "\\rvert", "\\vert", "\\rVert", "\\Vert"]
5981
+ );
5966
5982
  var DELIMITER_BASE_HEIGHT_PX = 18;
5967
5983
  var DELIMITER_MAX_SCALE = 4.8;
5968
5984
  function clamp(value, min, max) {
@@ -5974,7 +5990,7 @@ function applyDelimiterScale(pair, inner) {
5974
5990
  pair.style.setProperty("--butex-delim-scale", scale.toFixed(3));
5975
5991
  }
5976
5992
  function visibleDelimiter(expr) {
5977
- return expr.replace("\\left", "").replace("\\right", "").replace("\\{", "{").replace("\\}", "}");
5993
+ return expr.replace(/\\\\(?:left|right|bigl|Bigl|biggl|Biggl|bigr|Bigr|biggr|Biggr)/, "").replace("\\{", "{").replace("\\}", "}").replace(/\\\\(?:lvert|rvert|vert)/, "|").replace(/\\\\(?:lVert|rVert|Vert)/, "\u2016");
5978
5994
  }
5979
5995
  function buildDelimiterNodeBody(node, buildChain) {
5980
5996
  const pair = document.createElement("span");
@@ -7804,8 +7820,12 @@ function createEditorRuntime(options) {
7804
7820
  applyStructural((prev) => insertDelimiterPair(prev, "\\left(", "\\right)"));
7805
7821
  } else if (kind === "bracket") {
7806
7822
  applyStructural((prev) => insertDelimiterPair(prev, "\\left[", "\\right]"));
7807
- } else {
7823
+ } else if (kind === "brace") {
7808
7824
  applyStructural((prev) => insertDelimiterPair(prev, "\\left\\{", "\\right\\}"));
7825
+ } else if (kind === "vert") {
7826
+ applyStructural((prev) => insertDelimiterPair(prev, "\\left\\lvert", "\\right\\rvert"));
7827
+ } else {
7828
+ applyStructural((prev) => insertDelimiterPair(prev, "\\left\\lVert", "\\right\\rVert"));
7809
7829
  }
7810
7830
  focusInput();
7811
7831
  },
@@ -15700,7 +15720,9 @@ function EquationMobileToolbar({
15700
15720
  sheetView === "delimiters" ? /* @__PURE__ */ jsx13("div", { className: "butex-widget__sheet-command-grid butex-widget__sheet-command-grid--three", children: [
15701
15721
  { kind: "paren", label: "()", title: messages.insertParentheses },
15702
15722
  { kind: "bracket", label: "[]", title: messages.insertBrackets },
15703
- { kind: "brace", label: "{}", title: messages.insertBraces }
15723
+ { kind: "brace", label: "{}", title: messages.insertBraces },
15724
+ { kind: "vert", label: "| |", title: "| |" },
15725
+ { kind: "Vert", label: "\u2016 \u2016", title: "\u2016 \u2016" }
15704
15726
  ].map((option) => /* @__PURE__ */ jsx13("button", { type: "button", "aria-label": option.title, title: option.title, onClick: () => runAndClose((runtime) => runtime.insertDelimiterByKind(option.kind)), children: option.label }, option.kind)) }) : null,
15705
15727
  sheetView === "structures" ? /* @__PURE__ */ jsxs12(Fragment5, { children: [
15706
15728
  /* @__PURE__ */ jsxs12("div", { className: "butex-widget__sheet-command-grid", children: [
@@ -16673,6 +16695,42 @@ ${arabic || currentMessages.empty}`;
16673
16695
  },
16674
16696
  children: "{}"
16675
16697
  }
16698
+ ),
16699
+ /* @__PURE__ */ jsx14(
16700
+ "button",
16701
+ {
16702
+ className: "delimiter-command-option",
16703
+ "data-delim": "vert",
16704
+ type: "button",
16705
+ role: "menuitem",
16706
+ title: "| |",
16707
+ "aria-label": "| |",
16708
+ onMouseDown: (event) => event.preventDefault(),
16709
+ onClick: () => {
16710
+ runtimeRef.current?.insertDelimiterByKind("vert");
16711
+ setDelimiterMenuOpen(false);
16712
+ focusSurface();
16713
+ },
16714
+ children: "| |"
16715
+ }
16716
+ ),
16717
+ /* @__PURE__ */ jsx14(
16718
+ "button",
16719
+ {
16720
+ className: "delimiter-command-option",
16721
+ "data-delim": "Vert",
16722
+ type: "button",
16723
+ role: "menuitem",
16724
+ title: "\u2016 \u2016",
16725
+ "aria-label": "\u2016 \u2016",
16726
+ onMouseDown: (event) => event.preventDefault(),
16727
+ onClick: () => {
16728
+ runtimeRef.current?.insertDelimiterByKind("Vert");
16729
+ setDelimiterMenuOpen(false);
16730
+ focusSurface();
16731
+ },
16732
+ children: "\u2016 \u2016"
16733
+ }
16676
16734
  )
16677
16735
  ] })
16678
16736
  ]