@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.
package/dist/react.mjs CHANGED
@@ -46,11 +46,11 @@ function createEditorNode(kind, expr) {
46
46
  columnAlignments: null
47
47
  };
48
48
  }
49
- function createDelimiterNode(leftDelimExpr, rightDelimExpr) {
49
+ function createDelimiterNode(leftDelimExpr2, rightDelimExpr2) {
50
50
  return {
51
51
  ...createEditorNode("delimiter", ""),
52
- leftDelimExpr,
53
- rightDelimExpr,
52
+ leftDelimExpr: leftDelimExpr2,
53
+ rightDelimExpr: rightDelimExpr2,
54
54
  innerExpr: createEditorChain()
55
55
  };
56
56
  }
@@ -3654,11 +3654,11 @@ function insertAtomicOperatorCommand(session, commandId) {
3654
3654
  appendDebug(next, "insertAtomicOperatorCommand", commandId);
3655
3655
  return next;
3656
3656
  }
3657
- function insertDelimiterPair(session, leftDelimExpr, rightDelimExpr) {
3657
+ function insertDelimiterPair(session, leftDelimExpr2, rightDelimExpr2) {
3658
3658
  const base = replaceSelectionFirst(session);
3659
3659
  const next = cloneEditorSession(base);
3660
- const englishNode = createDelimiterNode(leftDelimExpr, rightDelimExpr);
3661
- const arabicNode = createDelimiterNode(leftDelimExpr, rightDelimExpr);
3660
+ const englishNode = createDelimiterNode(leftDelimExpr2, rightDelimExpr2);
3661
+ const arabicNode = createDelimiterNode(leftDelimExpr2, rightDelimExpr2);
3662
3662
  arabicNode.id = englishNode.id;
3663
3663
  if (arabicNode.innerExpr && englishNode.innerExpr) {
3664
3664
  arabicNode.innerExpr.id = englishNode.innerExpr.id;
@@ -3670,7 +3670,7 @@ function insertDelimiterPair(session, leftDelimExpr, rightDelimExpr) {
3670
3670
  };
3671
3671
  next.selectedStructureNodeId = null;
3672
3672
  syncSelectionToCaret(next);
3673
- appendDebug(next, "insertDelimiterPair", `${leftDelimExpr}${rightDelimExpr}`);
3673
+ appendDebug(next, "insertDelimiterPair", `${leftDelimExpr2}${rightDelimExpr2}`);
3674
3674
  return next;
3675
3675
  }
3676
3676
  function insertFraction(session) {
@@ -4354,6 +4354,22 @@ var DELIMITER_CSS = `
4354
4354
  transform-origin: center;
4355
4355
  }
4356
4356
  `.trim();
4357
+ function escapeDelimiterExpr(value) {
4358
+ return value.replace(/[.*+?^$()|[\]\\]/g, "\\$&");
4359
+ }
4360
+ function buildDelimiterExpr(prefixes, delimiters) {
4361
+ const prefixExpr = prefixes.map(escapeDelimiterExpr).join("|");
4362
+ const delimiterExpr = delimiters.map(escapeDelimiterExpr).join("|");
4363
+ return new RegExp(`^(?:(?:${prefixExpr}))?(?:${delimiterExpr})$`);
4364
+ }
4365
+ var leftDelimExpr = buildDelimiterExpr(
4366
+ ["\\left", "\\bigl", "\\Bigl", "\\biggl", "\\Biggl"],
4367
+ ["(", "[", "\\{", "\\lfloor", "\\lceil", "\\langle", "`", "|", "\\lvert", "\\vert", "\\lVert", "\\Vert"]
4368
+ );
4369
+ var rightDelimExpr = buildDelimiterExpr(
4370
+ ["\\right", "\\bigr", "\\Bigr", "\\biggr", "\\Biggr"],
4371
+ [")", "]", "\\}", "\\rfloor", "\\rceil", "\\rangle", "`", "|", "\\rvert", "\\vert", "\\rVert", "\\Vert"]
4372
+ );
4357
4373
  var DELIMITER_BASE_HEIGHT_PX = 18;
4358
4374
  var DELIMITER_MAX_SCALE = 4.8;
4359
4375
  function clamp(value, min, max) {
@@ -4365,7 +4381,7 @@ function applyDelimiterScale(pair, inner) {
4365
4381
  pair.style.setProperty("--butex-delim-scale", scale.toFixed(3));
4366
4382
  }
4367
4383
  function visibleDelimiter(expr) {
4368
- return expr.replace("\\left", "").replace("\\right", "").replace("\\{", "{").replace("\\}", "}");
4384
+ return expr.replace(/\\\\(?:left|right|bigl|Bigl|biggl|Biggl|bigr|Bigr|biggr|Biggr)/, "").replace("\\{", "{").replace("\\}", "}").replace(/\\\\(?:lvert|rvert|vert)/, "|").replace(/\\\\(?:lVert|rVert|Vert)/, "\u2016");
4369
4385
  }
4370
4386
  function buildDelimiterNodeBody(node, buildChain) {
4371
4387
  const pair = document.createElement("span");
@@ -6195,8 +6211,12 @@ function createEditorRuntime(options) {
6195
6211
  applyStructural((prev) => insertDelimiterPair(prev, "\\left(", "\\right)"));
6196
6212
  } else if (kind === "bracket") {
6197
6213
  applyStructural((prev) => insertDelimiterPair(prev, "\\left[", "\\right]"));
6198
- } else {
6214
+ } else if (kind === "brace") {
6199
6215
  applyStructural((prev) => insertDelimiterPair(prev, "\\left\\{", "\\right\\}"));
6216
+ } else if (kind === "vert") {
6217
+ applyStructural((prev) => insertDelimiterPair(prev, "\\left\\lvert", "\\right\\rvert"));
6218
+ } else {
6219
+ applyStructural((prev) => insertDelimiterPair(prev, "\\left\\lVert", "\\right\\rVert"));
6200
6220
  }
6201
6221
  focusInput();
6202
6222
  },
@@ -8256,12 +8276,12 @@ var DelimiterNode = class extends BaseAstNode {
8256
8276
  leftDelimExpr;
8257
8277
  innerExpr;
8258
8278
  rightDelimExpr;
8259
- constructor(leftDelimExpr, innerExpr, rightDelimExpr, state = null) {
8279
+ constructor(leftDelimExpr2, innerExpr, rightDelimExpr2, state = null) {
8260
8280
  super(state);
8261
8281
  this.nodeType = "DelimiterObject";
8262
- this.leftDelimExpr = leftDelimExpr;
8282
+ this.leftDelimExpr = leftDelimExpr2;
8263
8283
  this.innerExpr = innerExpr;
8264
- this.rightDelimExpr = rightDelimExpr;
8284
+ this.rightDelimExpr = rightDelimExpr2;
8265
8285
  }
8266
8286
  latex() {
8267
8287
  return this.leftDelimExpr + this.innerExpr.latex() + this.rightDelimExpr + this.latexScripts();
@@ -9558,7 +9578,9 @@ function EquationMobileToolbar({
9558
9578
  sheetView === "delimiters" ? /* @__PURE__ */ jsx("div", { className: "butex-widget__sheet-command-grid butex-widget__sheet-command-grid--three", children: [
9559
9579
  { kind: "paren", label: "()", title: messages.insertParentheses },
9560
9580
  { kind: "bracket", label: "[]", title: messages.insertBrackets },
9561
- { kind: "brace", label: "{}", title: messages.insertBraces }
9581
+ { kind: "brace", label: "{}", title: messages.insertBraces },
9582
+ { kind: "vert", label: "| |", title: "| |" },
9583
+ { kind: "Vert", label: "\u2016 \u2016", title: "\u2016 \u2016" }
9562
9584
  ].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,
9563
9585
  sheetView === "structures" ? /* @__PURE__ */ jsxs(Fragment, { children: [
9564
9586
  /* @__PURE__ */ jsxs("div", { className: "butex-widget__sheet-command-grid", children: [
@@ -10531,6 +10553,42 @@ ${arabic || currentMessages.empty}`;
10531
10553
  },
10532
10554
  children: "{}"
10533
10555
  }
10556
+ ),
10557
+ /* @__PURE__ */ jsx2(
10558
+ "button",
10559
+ {
10560
+ className: "delimiter-command-option",
10561
+ "data-delim": "vert",
10562
+ type: "button",
10563
+ role: "menuitem",
10564
+ title: "| |",
10565
+ "aria-label": "| |",
10566
+ onMouseDown: (event) => event.preventDefault(),
10567
+ onClick: () => {
10568
+ runtimeRef.current?.insertDelimiterByKind("vert");
10569
+ setDelimiterMenuOpen(false);
10570
+ focusSurface();
10571
+ },
10572
+ children: "| |"
10573
+ }
10574
+ ),
10575
+ /* @__PURE__ */ jsx2(
10576
+ "button",
10577
+ {
10578
+ className: "delimiter-command-option",
10579
+ "data-delim": "Vert",
10580
+ type: "button",
10581
+ role: "menuitem",
10582
+ title: "\u2016 \u2016",
10583
+ "aria-label": "\u2016 \u2016",
10584
+ onMouseDown: (event) => event.preventDefault(),
10585
+ onClick: () => {
10586
+ runtimeRef.current?.insertDelimiterByKind("Vert");
10587
+ setDelimiterMenuOpen(false);
10588
+ focusSurface();
10589
+ },
10590
+ children: "\u2016 \u2016"
10591
+ }
10534
10592
  )
10535
10593
  ] })
10536
10594
  ]