@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.
@@ -127,12 +127,12 @@ var DelimiterNode = class extends BaseAstNode {
127
127
  leftDelimExpr;
128
128
  innerExpr;
129
129
  rightDelimExpr;
130
- constructor(leftDelimExpr, innerExpr, rightDelimExpr, state = null) {
130
+ constructor(leftDelimExpr2, innerExpr, rightDelimExpr2, state = null) {
131
131
  super(state);
132
132
  this.nodeType = "DelimiterObject";
133
- this.leftDelimExpr = leftDelimExpr;
133
+ this.leftDelimExpr = leftDelimExpr2;
134
134
  this.innerExpr = innerExpr;
135
- this.rightDelimExpr = rightDelimExpr;
135
+ this.rightDelimExpr = rightDelimExpr2;
136
136
  }
137
137
  latex() {
138
138
  return this.leftDelimExpr + this.innerExpr.latex() + this.rightDelimExpr + this.latexScripts();
@@ -1911,11 +1911,11 @@ function createEditorNode(kind, expr) {
1911
1911
  columnAlignments: null
1912
1912
  };
1913
1913
  }
1914
- function createDelimiterNode(leftDelimExpr, rightDelimExpr) {
1914
+ function createDelimiterNode(leftDelimExpr2, rightDelimExpr2) {
1915
1915
  return {
1916
1916
  ...createEditorNode("delimiter", ""),
1917
- leftDelimExpr,
1918
- rightDelimExpr,
1917
+ leftDelimExpr: leftDelimExpr2,
1918
+ rightDelimExpr: rightDelimExpr2,
1919
1919
  innerExpr: createEditorChain()
1920
1920
  };
1921
1921
  }
@@ -4370,11 +4370,11 @@ function insertAtomicOperatorCommand(session, commandId) {
4370
4370
  appendDebug(next, "insertAtomicOperatorCommand", commandId);
4371
4371
  return next;
4372
4372
  }
4373
- function insertDelimiterPair(session, leftDelimExpr, rightDelimExpr) {
4373
+ function insertDelimiterPair(session, leftDelimExpr2, rightDelimExpr2) {
4374
4374
  const base = replaceSelectionFirst(session);
4375
4375
  const next = cloneEditorSession(base);
4376
- const englishNode = createDelimiterNode(leftDelimExpr, rightDelimExpr);
4377
- const arabicNode = createDelimiterNode(leftDelimExpr, rightDelimExpr);
4376
+ const englishNode = createDelimiterNode(leftDelimExpr2, rightDelimExpr2);
4377
+ const arabicNode = createDelimiterNode(leftDelimExpr2, rightDelimExpr2);
4378
4378
  arabicNode.id = englishNode.id;
4379
4379
  if (arabicNode.innerExpr && englishNode.innerExpr) {
4380
4380
  arabicNode.innerExpr.id = englishNode.innerExpr.id;
@@ -4386,7 +4386,7 @@ function insertDelimiterPair(session, leftDelimExpr, rightDelimExpr) {
4386
4386
  };
4387
4387
  next.selectedStructureNodeId = null;
4388
4388
  syncSelectionToCaret(next);
4389
- appendDebug(next, "insertDelimiterPair", `${leftDelimExpr}${rightDelimExpr}`);
4389
+ appendDebug(next, "insertDelimiterPair", `${leftDelimExpr2}${rightDelimExpr2}`);
4390
4390
  return next;
4391
4391
  }
4392
4392
  function insertFraction(session) {
@@ -5070,6 +5070,22 @@ var DELIMITER_CSS = `
5070
5070
  transform-origin: center;
5071
5071
  }
5072
5072
  `.trim();
5073
+ function escapeDelimiterExpr(value) {
5074
+ return value.replace(/[.*+?^$()|[\]\\]/g, "\\$&");
5075
+ }
5076
+ function buildDelimiterExpr(prefixes, delimiters) {
5077
+ const prefixExpr = prefixes.map(escapeDelimiterExpr).join("|");
5078
+ const delimiterExpr = delimiters.map(escapeDelimiterExpr).join("|");
5079
+ return new RegExp(`^(?:(?:${prefixExpr}))?(?:${delimiterExpr})$`);
5080
+ }
5081
+ var leftDelimExpr = buildDelimiterExpr(
5082
+ ["\\left", "\\bigl", "\\Bigl", "\\biggl", "\\Biggl"],
5083
+ ["(", "[", "\\{", "\\lfloor", "\\lceil", "\\langle", "`", "|", "\\lvert", "\\vert", "\\lVert", "\\Vert"]
5084
+ );
5085
+ var rightDelimExpr = buildDelimiterExpr(
5086
+ ["\\right", "\\bigr", "\\Bigr", "\\biggr", "\\Biggr"],
5087
+ [")", "]", "\\}", "\\rfloor", "\\rceil", "\\rangle", "`", "|", "\\rvert", "\\vert", "\\rVert", "\\Vert"]
5088
+ );
5073
5089
  var DELIMITER_BASE_HEIGHT_PX = 18;
5074
5090
  var DELIMITER_MAX_SCALE = 4.8;
5075
5091
  function clamp(value, min, max) {
@@ -5081,7 +5097,7 @@ function applyDelimiterScale(pair, inner) {
5081
5097
  pair.style.setProperty("--butex-delim-scale", scale.toFixed(3));
5082
5098
  }
5083
5099
  function visibleDelimiter(expr) {
5084
- return expr.replace("\\left", "").replace("\\right", "").replace("\\{", "{").replace("\\}", "}");
5100
+ return expr.replace(/\\\\(?:left|right|bigl|Bigl|biggl|Biggl|bigr|Bigr|biggr|Biggr)/, "").replace("\\{", "{").replace("\\}", "}").replace(/\\\\(?:lvert|rvert|vert)/, "|").replace(/\\\\(?:lVert|rVert|Vert)/, "\u2016");
5085
5101
  }
5086
5102
  function buildDelimiterNodeBody(node, buildChain) {
5087
5103
  const pair = document.createElement("span");
@@ -6911,8 +6927,12 @@ function createEditorRuntime(options) {
6911
6927
  applyStructural((prev) => insertDelimiterPair(prev, "\\left(", "\\right)"));
6912
6928
  } else if (kind === "bracket") {
6913
6929
  applyStructural((prev) => insertDelimiterPair(prev, "\\left[", "\\right]"));
6914
- } else {
6930
+ } else if (kind === "brace") {
6915
6931
  applyStructural((prev) => insertDelimiterPair(prev, "\\left\\{", "\\right\\}"));
6932
+ } else if (kind === "vert") {
6933
+ applyStructural((prev) => insertDelimiterPair(prev, "\\left\\lvert", "\\right\\rvert"));
6934
+ } else {
6935
+ applyStructural((prev) => insertDelimiterPair(prev, "\\left\\lVert", "\\right\\rVert"));
6916
6936
  }
6917
6937
  focusInput();
6918
6938
  },
@@ -10358,7 +10378,9 @@ function EquationMobileToolbar({
10358
10378
  sheetView === "delimiters" ? /* @__PURE__ */ jsx("div", { className: "butex-widget__sheet-command-grid butex-widget__sheet-command-grid--three", children: [
10359
10379
  { kind: "paren", label: "()", title: messages.insertParentheses },
10360
10380
  { kind: "bracket", label: "[]", title: messages.insertBrackets },
10361
- { kind: "brace", label: "{}", title: messages.insertBraces }
10381
+ { kind: "brace", label: "{}", title: messages.insertBraces },
10382
+ { kind: "vert", label: "| |", title: "| |" },
10383
+ { kind: "Vert", label: "\u2016 \u2016", title: "\u2016 \u2016" }
10362
10384
  ].map((option) => /* @__PURE__ */ jsx("button", { type: "button", "aria-label": option.title, title: option.title, onClick: () => runAndClose((runtime) => runtime.insertDelimiterByKind(option.kind)), children: option.label }, option.kind)) }) : null,
10363
10385
  sheetView === "structures" ? /* @__PURE__ */ jsxs(Fragment, { children: [
10364
10386
  /* @__PURE__ */ jsxs("div", { className: "butex-widget__sheet-command-grid", children: [
@@ -11331,6 +11353,42 @@ ${arabic || currentMessages.empty}`;
11331
11353
  },
11332
11354
  children: "{}"
11333
11355
  }
11356
+ ),
11357
+ /* @__PURE__ */ jsx2(
11358
+ "button",
11359
+ {
11360
+ className: "delimiter-command-option",
11361
+ "data-delim": "vert",
11362
+ type: "button",
11363
+ role: "menuitem",
11364
+ title: "| |",
11365
+ "aria-label": "| |",
11366
+ onMouseDown: (event) => event.preventDefault(),
11367
+ onClick: () => {
11368
+ runtimeRef.current?.insertDelimiterByKind("vert");
11369
+ setDelimiterMenuOpen(false);
11370
+ focusSurface();
11371
+ },
11372
+ children: "| |"
11373
+ }
11374
+ ),
11375
+ /* @__PURE__ */ jsx2(
11376
+ "button",
11377
+ {
11378
+ className: "delimiter-command-option",
11379
+ "data-delim": "Vert",
11380
+ type: "button",
11381
+ role: "menuitem",
11382
+ title: "\u2016 \u2016",
11383
+ "aria-label": "\u2016 \u2016",
11384
+ onMouseDown: (event) => event.preventDefault(),
11385
+ onClick: () => {
11386
+ runtimeRef.current?.insertDelimiterByKind("Vert");
11387
+ setDelimiterMenuOpen(false);
11388
+ focusSurface();
11389
+ },
11390
+ children: "\u2016 \u2016"
11391
+ }
11334
11392
  )
11335
11393
  ] })
11336
11394
  ]