@drghaliasri/butex 7.1.2 → 7.1.3

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.
@@ -6010,11 +6010,11 @@ function buildDelimiterExpr(prefixes, delimiters) {
6010
6010
  }
6011
6011
  var leftDelimExpr = buildDelimiterExpr(
6012
6012
  ["\\left", "\\bigl", "\\Bigl", "\\biggl", "\\Biggl"],
6013
- ["(", "[", "\\{", "\\lfloor", "\\lceil", "\\langle", "`", "|", "\\lvert", "\\vert", "\\lVert", "\\Vert"]
6013
+ ["(", "[", "\\{", "\\lfloor", "\\lceil", "\\langle", "`", "|", "\\|", "\\lvert", "\\vert", "\\lVert", "\\Vert"]
6014
6014
  );
6015
6015
  var rightDelimExpr = buildDelimiterExpr(
6016
6016
  ["\\right", "\\bigr", "\\Bigr", "\\biggr", "\\Biggr"],
6017
- [")", "]", "\\}", "\\rfloor", "\\rceil", "\\rangle", "`", "|", "\\rvert", "\\vert", "\\rVert", "\\Vert"]
6017
+ [")", "]", "\\}", "\\rfloor", "\\rceil", "\\rangle", "`", "|", "\\|", "\\rvert", "\\vert", "\\rVert", "\\Vert"]
6018
6018
  );
6019
6019
  var DELIMITER_BASE_HEIGHT_PX = 18;
6020
6020
  var DELIMITER_MAX_SCALE = 4.8;
@@ -6027,7 +6027,7 @@ function applyDelimiterScale(pair, inner) {
6027
6027
  pair.style.setProperty("--butex-delim-scale", scale.toFixed(3));
6028
6028
  }
6029
6029
  function visibleDelimiter(expr) {
6030
- return expr.replace(/\\\\(?:left|right|bigl|Bigl|biggl|Biggl|bigr|Bigr|biggr|Biggr)/, "").replace("\\{", "{").replace("\\}", "}").replace(/\\\\(?:lvert|rvert|vert)/, "|").replace(/\\\\(?:lVert|rVert|Vert)/, "\u2016");
6030
+ return expr.replace(/\\(?:left|right|bigl|Bigl|biggl|Biggl|bigr|Bigr|biggr|Biggr)/, "").replace("\\{", "{").replace("\\}", "}").replace(/\\(?:lvert|rvert|vert)/, "|").replace(/\\(?:lVert|rVert|Vert)/, "\u2016").replace("\\|", "\u2016");
6031
6031
  }
6032
6032
  function buildDelimiterNodeBody(node, buildChain) {
6033
6033
  const pair = document.createElement("span");
@@ -8344,9 +8344,56 @@ function astNodeToEditorNode(node) {
8344
8344
  }
8345
8345
  return { editable: false, reason: `\u0639\u0642\u062F\u0629 \u0631\u064A\u0627\u0636\u064A\u0629 \u063A\u064A\u0631 \u0645\u062F\u0639\u0648\u0645\u0629 \u062D\u0627\u0644\u064A\u0627: ${node.nodeType}` };
8346
8346
  }
8347
+ var VERTICAL_DELIMITER_COMMAND_PAIRS = {
8348
+ "\\vert": "\\vert",
8349
+ "\\lvert": "\\rvert",
8350
+ "\\Vert": "\\Vert",
8351
+ "\\lVert": "\\rVert",
8352
+ "\\|": "\\|"
8353
+ };
8354
+ function isBareCommand(node, name) {
8355
+ return node instanceof CommandNode && node.name === name && node.optionalArgs.length === 0 && node.mandatoryArgs.length === 0;
8356
+ }
8357
+ function normalizeVerticalDelimiterCommands(chain) {
8358
+ const normalized = [];
8359
+ for (let index = 0; index < chain.chain.length; index += 1) {
8360
+ const left = chain.chain[index];
8361
+ if (!(left instanceof CommandNode) || left.superscript || left.subscript) {
8362
+ normalized.push(left);
8363
+ continue;
8364
+ }
8365
+ const rightName = VERTICAL_DELIMITER_COMMAND_PAIRS[left.name];
8366
+ if (!rightName || left.optionalArgs.length > 0 || left.mandatoryArgs.length > 0) {
8367
+ normalized.push(left);
8368
+ continue;
8369
+ }
8370
+ let rightIndex = -1;
8371
+ for (let candidate = index + 1; candidate < chain.chain.length; candidate += 1) {
8372
+ if (isBareCommand(chain.chain[candidate], rightName)) {
8373
+ rightIndex = candidate;
8374
+ break;
8375
+ }
8376
+ }
8377
+ if (rightIndex < 0) {
8378
+ normalized.push(left);
8379
+ continue;
8380
+ }
8381
+ const right = chain.chain[rightIndex];
8382
+ const delimiter = new DelimiterNode(
8383
+ left.name,
8384
+ new ChainNode(chain.chain.slice(index + 1, rightIndex)),
8385
+ right.name
8386
+ );
8387
+ delimiter.superscript = right.superscript;
8388
+ delimiter.subscript = right.subscript;
8389
+ normalized.push(delimiter);
8390
+ index = rightIndex;
8391
+ }
8392
+ return new ChainNode(normalized);
8393
+ }
8347
8394
  function chainToEditorChain(chain) {
8348
8395
  const nodes = [];
8349
- for (const astNode of chain.chain) {
8396
+ for (const astNode of normalizeVerticalDelimiterCommands(chain).chain) {
8350
8397
  const converted = astNodeToEditorNode(astNode);
8351
8398
  if (!converted.editable) {
8352
8399
  return converted;