@pie-lib/math-rendering 3.22.2-next.11 → 3.22.2-next.172

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/esm/index.js CHANGED
@@ -1,19 +1,11 @@
1
1
  function _extends() {
2
- _extends = Object.assign || function (target) {
3
- for (var i = 1; i < arguments.length; i++) {
4
- var source = arguments[i];
5
-
6
- for (var key in source) {
7
- if (Object.prototype.hasOwnProperty.call(source, key)) {
8
- target[key] = source[key];
9
- }
10
- }
2
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
3
+ for (var e = 1; e < arguments.length; e++) {
4
+ var t = arguments[e];
5
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
11
6
  }
12
-
13
- return target;
14
- };
15
-
16
- return _extends.apply(this, arguments);
7
+ return n;
8
+ }, _extends.apply(null, arguments);
17
9
  }
18
10
 
19
11
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
@@ -66097,7 +66089,7 @@ function requireMhchemParser () {
66097
66089
  *************************************************************************
66098
66090
  *
66099
66091
  * mhchemParser.ts
66100
- * 4.1.1
66092
+ * 4.2.1
66101
66093
  *
66102
66094
  * Parser for the \ce command and \pu command for MathJax and Co.
66103
66095
  *
@@ -66106,7 +66098,7 @@ function requireMhchemParser () {
66106
66098
  *
66107
66099
  * ----------------------------------------------------------------------
66108
66100
  *
66109
- * Copyright (c) 2015-2021 Martin Hensel
66101
+ * Copyright (c) 2015-2023 Martin Hensel
66110
66102
  *
66111
66103
  * Licensed under the Apache License, Version 2.0 (the "License");
66112
66104
  * you may not use this file except in compliance with the License.
@@ -66354,9 +66346,8 @@ function requireMhchemParser () {
66354
66346
  },
66355
66347
  '\\ce{(...)}': function (input) { return _mhchemParser.patterns.findObserveGroups(input, "\\ce{", "", "", "}"); },
66356
66348
  '\\pu{(...)}': function (input) { return _mhchemParser.patterns.findObserveGroups(input, "\\pu{", "", "", "}"); },
66357
- 'oxidation$': /^(?:[+-][IVX]+|\\pm\s*0|\$\\pm\$\s*0)$/,
66358
- 'd-oxidation$': /^(?:[+-]?\s?[IVX]+|\\pm\s*0|\$\\pm\$\s*0)$/,
66359
- 'roman numeral': /^[IVX]+/,
66349
+ 'oxidation$': /^(?:[+-][IVX]+|(?:\\pm|\$\\pm\$|\+-|\+\/-)\s*0)$/,
66350
+ 'd-oxidation$': /^(?:[+-]?[IVX]+|(?:\\pm|\$\\pm\$|\+-|\+\/-)\s*0)$/,
66360
66351
  '1/2$': /^[+\-]?(?:[0-9]+|\$[a-z]\$|[a-z])\/[0-9]+(?:\$[a-z]\$|[a-z])?$/,
66361
66352
  'amount': function (input) {
66362
66353
  var match;
@@ -66491,6 +66482,7 @@ function requireMhchemParser () {
66491
66482
  'b=': function (buffer, m) { buffer.b = (buffer.b || "") + m; return undefined; },
66492
66483
  'p=': function (buffer, m) { buffer.p = (buffer.p || "") + m; return undefined; },
66493
66484
  'o=': function (buffer, m) { buffer.o = (buffer.o || "") + m; return undefined; },
66485
+ 'o=+p1': function (buffer, _m, a) { buffer.o = (buffer.o || "") + a; return undefined; },
66494
66486
  'q=': function (buffer, m) { buffer.q = (buffer.q || "") + m; return undefined; },
66495
66487
  'd=': function (buffer, m) { buffer.d = (buffer.d || "") + m; return undefined; },
66496
66488
  'rm=': function (buffer, m) { buffer.rm = (buffer.rm || "") + m; return undefined; },
@@ -67180,20 +67172,17 @@ function requireMhchemParser () {
67180
67172
  'oxidation': {
67181
67173
  transitions: _mhchemCreateTransitions({
67182
67174
  'empty': {
67183
- '*': { action_: [] }
67184
- },
67185
- 'roman numeral': {
67186
67175
  '*': { action_: 'roman-numeral' }
67187
67176
  },
67188
- '${(...)}$__$(...)$': {
67189
- '*': { action_: 'tex-math' }
67177
+ 'pm-operator': {
67178
+ '*': { action_: { type_: 'o=+p1', option: "\\pm" } }
67190
67179
  },
67191
67180
  'else': {
67192
- '*': { action_: 'copy' }
67181
+ '*': { action_: 'o=' }
67193
67182
  }
67194
67183
  }),
67195
67184
  actions: {
67196
- 'roman-numeral': function (_buffer, m) { return { type_: 'roman numeral', p1: m }; }
67185
+ 'roman-numeral': function (buffer) { return { type_: 'roman numeral', p1: buffer.o || "" }; }
67197
67186
  }
67198
67187
  },
67199
67188
  'tex-math': {
@@ -87424,19 +87413,15 @@ const reduceText = (acc, n) => {
87424
87413
  if (n.node && n.node.kind === 'text') {
87425
87414
  acc += n.node.text;
87426
87415
  }
87427
-
87428
87416
  return acc;
87429
87417
  };
87430
-
87431
87418
  class Line {
87432
87419
  constructor() {
87433
87420
  this.kind = 'line';
87434
87421
  }
87435
-
87436
87422
  get columns() {
87437
87423
  return [];
87438
87424
  }
87439
-
87440
87425
  }
87441
87426
  class Row {
87442
87427
  constructor(columns, operator) {
@@ -87444,113 +87429,92 @@ class Row {
87444
87429
  this.operator = operator;
87445
87430
  this.columns = columns;
87446
87431
  }
87447
-
87448
87432
  pad(count, direction = 'right') {
87449
87433
  if (count < this.columns.length) {
87450
87434
  throw new Error('no');
87451
87435
  }
87452
-
87453
87436
  const diff = count - this.columns.length;
87454
-
87455
87437
  const padding = _.times(diff).map(() => '__pad__');
87456
-
87457
87438
  return direction === 'right' ? [...padding, ...this.columns] : [...this.columns, ...padding];
87458
87439
  }
87459
-
87460
87440
  }
87461
-
87462
87441
  const mathNodeToCharArray = mn => {
87463
87442
  const text = mn.childNodes.reduce(reduceText, '');
87464
87443
  return text.split('');
87465
87444
  };
87445
+
87466
87446
  /**
87467
87447
  * Convert child a column entry
87468
87448
  * @param {*} child
87469
87449
  * @return an array of column content
87470
87450
  */
87471
-
87472
-
87473
87451
  const toColumnArray = child => {
87474
87452
  if (!child || !child.kind) {
87475
87453
  return [];
87476
87454
  }
87477
-
87478
87455
  if (child.kind === 'msrow') {
87479
87456
  throw new Error('msrow in msrow?');
87480
87457
  }
87481
-
87482
87458
  if (child.kind === 'mo') {
87483
87459
  // We are going to treat this operator as a text array.
87484
87460
  // It's probably going to be a decimal point
87485
87461
  // eslint-disable-next-line no-console
87486
87462
  console.warn('mo that is not 1st node in msrow?');
87487
- return mathNodeToCharArray(child); // throw new Error('mo must be first child of msrow');
87463
+ return mathNodeToCharArray(child);
87464
+ // throw new Error('mo must be first child of msrow');
87488
87465
  }
87489
-
87490
87466
  if (child.kind === 'mn') {
87491
87467
  return mathNodeToCharArray(child);
87492
87468
  }
87493
-
87494
87469
  if (child.toCHTML) {
87495
87470
  return child;
87496
87471
  }
87497
87472
  };
87473
+
87498
87474
  /**
87499
87475
  * convert mstack chtml childNodes into a Row
87500
87476
  * @param child chtml child node of mstack
87501
87477
  * @return Row | Line
87502
87478
  */
87503
-
87504
-
87505
87479
  const rowStack = child => {
87506
87480
  if (!child || !child.kind) {
87507
87481
  return;
87508
87482
  }
87509
-
87510
87483
  if (child.kind === 'msrow') {
87511
87484
  if (!child.childNodes || child.childNodes.length === 0) {
87512
87485
  return new Row([]);
87513
87486
  }
87514
-
87515
87487
  const f = _.first(child.childNodes);
87516
-
87517
87488
  const nodes = f && f.kind === 'mo' ? _.tail(child.childNodes) : child.childNodes;
87518
-
87519
87489
  const columns = _.flatten(nodes.map(toColumnArray));
87520
-
87521
87490
  return new Row(columns, f.kind === 'mo' ? f : undefined);
87522
87491
  }
87523
-
87524
87492
  if (child.kind === 'mn') {
87525
87493
  const columns = mathNodeToCharArray(child);
87526
87494
  return new Row(columns, undefined);
87527
87495
  }
87528
-
87529
87496
  if (child.kind === 'mo') {
87530
87497
  // eslint-disable-next-line no-console
87531
87498
  console.warn('mo on its own row?');
87532
87499
  return new Row([], child);
87533
87500
  }
87534
-
87535
87501
  if (child.kind === 'msline') {
87536
87502
  return new Line();
87537
87503
  }
87538
-
87539
87504
  if (child.toCHTML) {
87540
87505
  return new Row([child]);
87541
87506
  }
87542
87507
  };
87508
+
87543
87509
  /** convert MathJax chtml tree to Row[]
87544
87510
  * @param mstack the root of the mathjax chtml tree
87545
87511
  * @return Row[]
87546
87512
  */
87547
87513
 
87548
-
87549
87514
  const getStackData = mstack => {
87550
87515
  if (!mstack || !mstack.childNodes) {
87551
87516
  return [];
87552
87517
  }
87553
-
87554
87518
  return _.compact(mstack.childNodes.map(rowStack));
87555
87519
  };
87556
87520
  class CHTMLmstack extends WrapperExports.CHTMLWrapper {
@@ -87558,16 +87522,15 @@ class CHTMLmstack extends WrapperExports.CHTMLWrapper {
87558
87522
  super(factory, node, parent);
87559
87523
  this.ce = this.adaptor.document.createElement.bind(this.adaptor.document);
87560
87524
  }
87561
-
87562
87525
  toCHTML(parent) {
87563
87526
  const chtml = this.standardCHTMLnode(parent);
87564
- const stackData = getStackData(this); // console.log('stackData', stackData);
87527
+ const stackData = getStackData(this);
87565
87528
 
87529
+ // console.log('stackData', stackData);
87566
87530
  const maxCols = stackData.reduce((acc, r) => {
87567
87531
  if (r && r.columns.length > acc) {
87568
87532
  acc = r.columns.length;
87569
87533
  }
87570
-
87571
87534
  return acc;
87572
87535
  }, 0);
87573
87536
  const table = this.ce('table');
@@ -87575,24 +87538,21 @@ class CHTMLmstack extends WrapperExports.CHTMLWrapper {
87575
87538
  stackData.forEach(row => {
87576
87539
  const tr = this.ce('tr');
87577
87540
  table.appendChild(tr);
87578
-
87579
87541
  if (row.kind === 'row') {
87580
87542
  const td = this.ce('td');
87581
87543
  tr.appendChild(td);
87582
-
87583
87544
  if (row.operator && row.operator.toCHTML) {
87584
87545
  td.setAttribute('class', 'inner');
87585
87546
  row.operator.toCHTML(td);
87586
87547
  } else {
87587
87548
  td.textContent = '';
87588
- } // align right for now:
87589
-
87549
+ }
87590
87550
 
87551
+ // align right for now:
87591
87552
  const cols = row.pad(maxCols, 'right');
87592
87553
  cols.forEach(c => {
87593
87554
  const t = this.ce('td');
87594
87555
  tr.appendChild(t);
87595
-
87596
87556
  if (c === '__pad__') {
87597
87557
  t.textContent = '';
87598
87558
  } else if (typeof c === 'string') {
@@ -87613,7 +87573,6 @@ class CHTMLmstack extends WrapperExports.CHTMLWrapper {
87613
87573
  }
87614
87574
  });
87615
87575
  }
87616
-
87617
87576
  }
87618
87577
  CHTMLmstack.styles = {
87619
87578
  'mjx-mstack > table': {
@@ -87649,25 +87608,21 @@ class MmlNone extends MmlNodeExports.AbstractMmlNode {
87649
87608
  get kind() {
87650
87609
  return 'none';
87651
87610
  }
87652
-
87653
87611
  }
87654
87612
  class MmlMstack extends MmlNodeExports.AbstractMmlNode {
87655
87613
  get kind() {
87656
87614
  return 'mstack';
87657
87615
  }
87658
-
87659
87616
  }
87660
87617
  class MmlMsrow extends MmlNodeExports.AbstractMmlNode {
87661
87618
  get kind() {
87662
87619
  return 'msrow';
87663
87620
  }
87664
-
87665
87621
  }
87666
87622
  class MmlMsline extends MmlNodeExports.AbstractMmlNode {
87667
87623
  get kind() {
87668
87624
  return 'msline';
87669
87625
  }
87670
-
87671
87626
  }
87672
87627
 
87673
87628
  const chtmlNodes = {
@@ -87713,7 +87668,7 @@ function requireMs () {
87713
87668
  * @api public
87714
87669
  */
87715
87670
 
87716
- ms = function(val, options) {
87671
+ ms = function (val, options) {
87717
87672
  options = options || {};
87718
87673
  var type = typeof val;
87719
87674
  if (type === 'string' && val.length > 0) {
@@ -88026,24 +87981,62 @@ function requireCommon () {
88026
87981
  createDebug.names = [];
88027
87982
  createDebug.skips = [];
88028
87983
 
88029
- let i;
88030
- const split = (typeof namespaces === 'string' ? namespaces : '').split(/[\s,]+/);
88031
- const len = split.length;
87984
+ const split = (typeof namespaces === 'string' ? namespaces : '')
87985
+ .trim()
87986
+ .replace(/\s+/g, ',')
87987
+ .split(',')
87988
+ .filter(Boolean);
88032
87989
 
88033
- for (i = 0; i < len; i++) {
88034
- if (!split[i]) {
88035
- // ignore empty strings
88036
- continue;
87990
+ for (const ns of split) {
87991
+ if (ns[0] === '-') {
87992
+ createDebug.skips.push(ns.slice(1));
87993
+ } else {
87994
+ createDebug.names.push(ns);
88037
87995
  }
87996
+ }
87997
+ }
88038
87998
 
88039
- namespaces = split[i].replace(/\*/g, '.*?');
88040
-
88041
- if (namespaces[0] === '-') {
88042
- createDebug.skips.push(new RegExp('^' + namespaces.slice(1) + '$'));
87999
+ /**
88000
+ * Checks if the given string matches a namespace template, honoring
88001
+ * asterisks as wildcards.
88002
+ *
88003
+ * @param {String} search
88004
+ * @param {String} template
88005
+ * @return {Boolean}
88006
+ */
88007
+ function matchesTemplate(search, template) {
88008
+ let searchIndex = 0;
88009
+ let templateIndex = 0;
88010
+ let starIndex = -1;
88011
+ let matchIndex = 0;
88012
+
88013
+ while (searchIndex < search.length) {
88014
+ if (templateIndex < template.length && (template[templateIndex] === search[searchIndex] || template[templateIndex] === '*')) {
88015
+ // Match character or proceed with wildcard
88016
+ if (template[templateIndex] === '*') {
88017
+ starIndex = templateIndex;
88018
+ matchIndex = searchIndex;
88019
+ templateIndex++; // Skip the '*'
88020
+ } else {
88021
+ searchIndex++;
88022
+ templateIndex++;
88023
+ }
88024
+ } else if (starIndex !== -1) { // eslint-disable-line no-negated-condition
88025
+ // Backtrack to the last '*' and try to match more characters
88026
+ templateIndex = starIndex + 1;
88027
+ matchIndex++;
88028
+ searchIndex = matchIndex;
88043
88029
  } else {
88044
- createDebug.names.push(new RegExp('^' + namespaces + '$'));
88030
+ return false; // No match
88045
88031
  }
88046
88032
  }
88033
+
88034
+ // Handle trailing '*' in template
88035
+ while (templateIndex < template.length && template[templateIndex] === '*') {
88036
+ templateIndex++;
88037
+ }
88038
+
88039
+ return templateIndex === template.length;
88047
88040
  }
88048
88041
 
88049
88042
  /**
@@ -88054,8 +88047,8 @@ function requireCommon () {
88054
88047
  */
88055
88048
  function disable() {
88056
88049
  const namespaces = [
88057
- ...createDebug.names.map(toNamespace),
88058
- ...createDebug.skips.map(toNamespace).map(namespace => '-' + namespace)
88050
+ ...createDebug.names,
88051
+ ...createDebug.skips.map(namespace => '-' + namespace)
88059
88052
  ].join(',');
88060
88053
  createDebug.enable('');
88061
88054
  return namespaces;
@@ -88069,21 +88062,14 @@ function requireCommon () {
88069
88062
  * @api public
88070
88063
  */
88071
88064
  function enabled(name) {
88072
- if (name[name.length - 1] === '*') {
88073
- return true;
88074
- }
88075
-
88076
- let i;
88077
- let len;
88078
-
88079
- for (i = 0, len = createDebug.skips.length; i < len; i++) {
88080
- if (createDebug.skips[i].test(name)) {
88065
+ for (const skip of createDebug.skips) {
88066
+ if (matchesTemplate(name, skip)) {
88081
88067
  return false;
88082
88068
  }
88083
88069
  }
88084
88070
 
88085
- for (i = 0, len = createDebug.names.length; i < len; i++) {
88086
- if (createDebug.names[i].test(name)) {
88071
+ for (const ns of createDebug.names) {
88072
+ if (matchesTemplate(name, ns)) {
88087
88073
  return true;
88088
88074
  }
88089
88075
  }
@@ -88091,19 +88077,6 @@ function requireCommon () {
88091
88077
  return false;
88092
88078
  }
88093
88079
 
88094
- /**
88095
- * Convert regexp to namespace
88096
- *
88097
- * @param {RegExp} regxep
88098
- * @return {String} namespace
88099
- * @api private
88100
- */
88101
- function toNamespace(regexp) {
88102
- return regexp.toString()
88103
- .substring(2, regexp.toString().length - 2)
88104
- .replace(/\.\*\?$/, '*');
88105
- }
88106
-
88107
88080
  /**
88108
88081
  * Coerce `val`.
88109
88082
  *
@@ -88268,14 +88241,17 @@ function requireBrowser () {
88268
88241
  return false;
88269
88242
  }
88270
88243
 
88244
+ let m;
88245
+
88271
88246
  // Is webkit? http://stackoverflow.com/a/16459606/376773
88272
88247
  // document is undefined in react-native: https://github.com/facebook/react-native/pull/1632
88248
+ // eslint-disable-next-line no-return-assign
88273
88249
  return (typeof document !== 'undefined' && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance) ||
88274
88250
  // Is firebug? http://stackoverflow.com/a/398120/376773
88275
88251
  (typeof window !== 'undefined' && window.console && (window.console.firebug || (window.console.exception && window.console.table))) ||
88276
88252
  // Is firefox >= v31?
88277
88253
  // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages
88278
- (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/) && parseInt(RegExp.$1, 10) >= 31) ||
88254
+ (typeof navigator !== 'undefined' && navigator.userAgent && (m = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(m[1], 10) >= 31) ||
88279
88255
  // Double check webkit in userAgent just in case we are in a worker
88280
88256
  (typeof navigator !== 'undefined' && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/));
88281
88257
  }
@@ -88359,7 +88335,7 @@ function requireBrowser () {
88359
88335
  function load() {
88360
88336
  let r;
88361
88337
  try {
88362
- r = exports$1.storage.getItem('debug');
88338
+ r = exports$1.storage.getItem('debug') || exports$1.storage.getItem('DEBUG') ;
88363
88339
  } catch (error) {
88364
88340
  // Swallow
88365
88341
  // XXX (@Qix-) should we be logging these?
@@ -88431,60 +88407,47 @@ const PAIRS = {
88431
88407
  const wrapMath = (content, wrapType) => {
88432
88408
  if (wrapType === BracketTypes.SQUARE_BRACKETS) {
88433
88409
  console.warn('\\[...\\] is not supported yet'); // eslint-disable-line
88434
-
88435
88410
  wrapType = BracketTypes.ROUND_BRACKETS;
88436
88411
  }
88437
-
88438
88412
  if (wrapType === BracketTypes.DOUBLE_DOLLAR) {
88439
88413
  console.warn('$$...$$ is not supported yet'); // eslint-disable-line
88440
-
88441
88414
  wrapType = BracketTypes.DOLLAR;
88442
88415
  }
88443
-
88444
88416
  const [start, end] = PAIRS[wrapType] || PAIRS[BracketTypes.ROUND_BRACKETS];
88445
88417
  return `${start}${content}${end}`;
88446
88418
  };
88447
88419
  const unWrapMath = content => {
88448
88420
  const displayStyleIndex = content.indexOf('\\displaystyle');
88449
-
88450
88421
  if (displayStyleIndex !== -1) {
88451
88422
  console.warn('\\displaystyle is not supported - removing'); // eslint-disable-line
88452
-
88453
88423
  content = content.replace('\\displaystyle', '').trim();
88454
88424
  }
88455
-
88456
88425
  if (content.startsWith('$$') && content.endsWith('$$')) {
88457
88426
  console.warn('$$ syntax is not yet supported'); // eslint-disable-line
88458
-
88459
88427
  return {
88460
88428
  unwrapped: content.substring(2, content.length - 2),
88461
88429
  wrapType: BracketTypes.DOLLAR
88462
88430
  };
88463
88431
  }
88464
-
88465
88432
  if (content.startsWith('$') && content.endsWith('$')) {
88466
88433
  return {
88467
88434
  unwrapped: content.substring(1, content.length - 1),
88468
88435
  wrapType: BracketTypes.DOLLAR
88469
88436
  };
88470
88437
  }
88471
-
88472
88438
  if (content.startsWith('\\[') && content.endsWith('\\]')) {
88473
88439
  console.warn('\\[..\\] syntax is not yet supported'); // eslint-disable-line
88474
-
88475
88440
  return {
88476
88441
  unwrapped: content.substring(2, content.length - 2),
88477
88442
  wrapType: BracketTypes.ROUND_BRACKETS
88478
88443
  };
88479
88444
  }
88480
-
88481
88445
  if (content.startsWith('\\(') && content.endsWith('\\)')) {
88482
88446
  return {
88483
88447
  unwrapped: content.substring(2, content.length - 2),
88484
88448
  wrapType: BracketTypes.ROUND_BRACKETS
88485
88449
  };
88486
88450
  }
88487
-
88488
88451
  return {
88489
88452
  unwrapped: content,
88490
88453
  wrapType: BracketTypes.ROUND_BRACKETS
@@ -88504,39 +88467,35 @@ var HTMLDomStringsExports = requireHTMLDomStrings();
88504
88467
  if (typeof window !== 'undefined') {
88505
88468
  htmlExports.RegisterHTMLHandler(browserAdaptorExports.browserAdaptor());
88506
88469
  }
88507
-
88508
88470
  let sreReady = false;
88509
88471
  systemExports.engineReady().then(() => {
88510
88472
  sreReady = true;
88511
- }); // import pkg from '../../package.json';
88473
+ });
88512
88474
  const visitor = new SerializedMmlVisitorExports.SerializedMmlVisitor();
88513
-
88514
88475
  const toMMl = node => visitor.visitTree(node);
88515
-
88516
88476
  const log = debug('pie-lib:math-rendering');
88517
88477
  const NEWLINE_BLOCK_REGEX = /\\embed\{newLine\}\[\]/g;
88518
88478
  const NEWLINE_LATEX = '\\newline ';
88519
-
88520
88479
  const getGlobal = () => {
88521
88480
  // TODO does it make sense to use version?
88522
88481
  // const key = `${pkg.name}@${pkg.version.split('.')[0]}`;
88523
88482
  // It looks like Ed made this change when he switched from mathjax3 to mathjax-full
88524
88483
  // I think it was supposed to make sure version 1 (using mathjax3) is not used
88525
88484
  // in combination with version 2 (using mathjax-full)
88485
+
88526
88486
  // TODO higher level wrappers use this instance of math-rendering, and if 2 different instances are used, math rendering is not working
88527
88487
  // so I will hardcode this for now until a better solution is found
88528
88488
  const key = '@pie-lib/math-rendering@2';
88529
-
88530
88489
  if (typeof window !== 'undefined') {
88531
88490
  if (!window[key]) {
88532
88491
  window[key] = {};
88533
88492
  }
88534
-
88535
88493
  return window[key];
88536
88494
  } else {
88537
88495
  return {};
88538
88496
  }
88539
88497
  };
88498
+
88540
88499
  /** Add temporary support for a global singleDollar override
88541
88500
  * <code>
88542
88501
  * // This will enable single dollar rendering
@@ -88544,25 +88503,19 @@ const getGlobal = () => {
88544
88503
  * window.pie.mathRendering = {useSingleDollar: true };
88545
88504
  * </code>
88546
88505
  */
88547
-
88548
-
88549
88506
  const defaultOpts = () => getGlobal().opts || {};
88550
-
88551
88507
  const fixMathElement = element => {
88552
88508
  if (element.dataset.mathHandled) {
88553
88509
  return;
88554
88510
  }
88555
-
88556
88511
  let property = 'innerText';
88557
-
88558
88512
  if (element.textContent) {
88559
88513
  property = 'textContent';
88560
88514
  }
88561
-
88562
88515
  if (element[property]) {
88563
- element[property] = wrapMath(unWrapMath(element[property]).unwrapped); // because mathquill doesn't understand line breaks, sometimes we end up with custom elements on prompts/rationale/etc.
88516
+ element[property] = wrapMath(unWrapMath(element[property]).unwrapped);
88517
+ // because mathquill doesn't understand line breaks, sometimes we end up with custom elements on prompts/rationale/etc.
88564
88518
  // we need to replace the custom embedded elements with valid latex that Mathjax can understand
88565
-
88566
88519
  element[property] = element[property].replace(NEWLINE_BLOCK_REGEX, NEWLINE_LATEX);
88567
88520
  element.dataset.mathHandled = true;
88568
88521
  }
@@ -88571,39 +88524,31 @@ const fixMathElements = (el = document) => {
88571
88524
  const mathElements = el.querySelectorAll('[data-latex]');
88572
88525
  mathElements.forEach(item => fixMathElement(item));
88573
88526
  };
88574
-
88575
88527
  const adjustMathMLStyle = (el = document) => {
88576
88528
  const nodes = el.querySelectorAll('math');
88577
88529
  nodes.forEach(node => node.setAttribute('displaystyle', 'true'));
88578
88530
  };
88579
-
88580
88531
  class myFindMathML extends FindMathMLExports.FindMathML {
88581
88532
  processMath(set) {
88582
88533
  const adaptor = this.adaptor;
88583
-
88584
88534
  for (const mml of Array.from(set)) {
88585
88535
  if (adaptor.kind(adaptor.parent(mml)) === 'mjx-assistive-mml') {
88586
88536
  set.delete(mml);
88587
88537
  }
88588
88538
  }
88589
-
88590
88539
  return super.processMath(set);
88591
88540
  }
88592
-
88593
88541
  }
88594
-
88595
88542
  const createMathMLInstance = (opts, docProvided = document) => {
88596
88543
  opts = opts || defaultOpts();
88597
-
88598
88544
  if (opts.useSingleDollar) {
88599
88545
  // eslint-disable-next-line
88600
88546
  console.warn('[math-rendering] using $ is not advisable, please use $$..$$ or \\(...\\)');
88601
88547
  }
88602
-
88603
88548
  const packages = AllPackagesExports.AllPackages.filter(name => name !== 'bussproofs'); // Bussproofs needs an output jax
88549
+
88604
88550
  // The autoload extension predefines all the macros from the extensions that haven't been loaded already
88605
88551
  // so that they automatically load the needed extension when they are first used
88606
-
88607
88552
  packages.push('autoload');
88608
88553
  const macros = {
88609
88554
  parallelogram: '\\lower.2em{\\Huge\\unicode{x25B1}}',
@@ -88630,7 +88575,6 @@ const createMathMLInstance = (opts, docProvided = document) => {
88630
88575
  FindMathML: new myFindMathML()
88631
88576
  };
88632
88577
  let cachedMathjax;
88633
-
88634
88578
  if (globalExports.MathJax && globalExports.MathJax.version !== mathjaxExports.mathjax.version) {
88635
88579
  // handling other MathJax version on the page
88636
88580
  // replacing it temporarily with the version we have
@@ -88639,7 +88583,6 @@ const createMathMLInstance = (opts, docProvided = document) => {
88639
88583
  cachedMathjax = window.MathJax;
88640
88584
  Object.assign(globalExports.MathJax, mathjaxExports.mathjax);
88641
88585
  }
88642
-
88643
88586
  const fontURL = `https://unpkg.com/mathjax-full@${mathjaxExports.mathjax.version}/ts/output/chtml/fonts/tex-woff-v2`;
88644
88587
  const htmlConfig = {
88645
88588
  fontURL,
@@ -88651,14 +88594,14 @@ const createMathMLInstance = (opts, docProvided = document) => {
88651
88594
  const html = classFactory.create(docProvided, {
88652
88595
  compileError: (mj, math, err) => {
88653
88596
  // eslint-disable-next-line no-console
88654
- console.log('bad math?:', math); // eslint-disable-next-line no-console
88655
-
88597
+ console.log('bad math?:', math);
88598
+ // eslint-disable-next-line no-console
88656
88599
  console.error(err);
88657
88600
  },
88658
88601
  typesetError: function (doc, math, err) {
88659
88602
  // eslint-disable-next-line no-console
88660
- console.log('typeset error'); // eslint-disable-next-line no-console
88661
-
88603
+ console.log('typeset error');
88604
+ // eslint-disable-next-line no-console
88662
88605
  console.error(err);
88663
88606
  doc.typesetError(math, err);
88664
88607
  },
@@ -88671,52 +88614,62 @@ const createMathMLInstance = (opts, docProvided = document) => {
88671
88614
  DomStrings: new HTMLDomStringsExports.HTMLDomStrings({
88672
88615
  skipHtmlTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code', 'annotation', 'annotation-xml', 'mjx-assistive-mml', 'mjx-container']
88673
88616
  })
88674
- }); // Note: we must set this *after* mathjax.document (no idea why)
88617
+ });
88675
88618
 
88619
+ // Note: we must set this *after* mathjax.document (no idea why)
88676
88620
  mml.setMmlFactory(customMmlFactory);
88677
-
88678
88621
  if (cachedMathjax) {
88679
88622
  // if we have a cached version, we replace it here
88680
88623
  window.MathJax = cachedMathjax;
88681
88624
  }
88682
-
88683
88625
  return html;
88684
88626
  };
88685
-
88686
88627
  let enrichSpeechInitialized = false;
88687
-
88688
88628
  const bootstrap = opts => {
88689
88629
  if (typeof window === 'undefined') {
88690
88630
  return {
88691
88631
  Typeset: () => ({})
88692
88632
  };
88693
88633
  }
88694
-
88695
88634
  const html = createMathMLInstance(opts);
88696
88635
  return {
88697
88636
  version: mathjaxExports.mathjax.version,
88698
88637
  html: html,
88699
88638
  Typeset: function (...elements) {
88700
88639
  const attemptRender = (temporary = false) => {
88701
- var _updatedDocument$math, _updatedDocument$math2;
88702
-
88640
+ var _updatedDocument$math;
88703
88641
  let updatedDocument = this.html.findMath(elements.length ? {
88704
88642
  elements
88705
88643
  } : {}).compile();
88706
-
88707
88644
  if (!temporary && sreReady) {
88708
- updatedDocument = updatedDocument.enrich();
88645
+ try {
88646
+ updatedDocument = updatedDocument.enrich();
88647
+ } catch (e) {
88648
+ // If enrich fails, speech-rule-engine isn't actually ready yet
88649
+ // eslint-disable-next-line no-console
88650
+ console.warn('[math-rendering] Speech-rule-engine not fully initialized, skipping enrichment');
88651
+ sreReady = false;
88652
+ }
88709
88653
  }
88654
+ updatedDocument = updatedDocument.getMetrics().typeset();
88710
88655
 
88711
- updatedDocument = updatedDocument.getMetrics().typeset().assistiveMml().attachSpeech().addMenu().updateDocument();
88712
-
88713
- if (!enrichSpeechInitialized && typeof ((_updatedDocument$math = updatedDocument.math.list) == null ? void 0 : (_updatedDocument$math2 = _updatedDocument$math.next) == null ? void 0 : _updatedDocument$math2.data) === 'object') {
88656
+ // Only add assistive MML and speech if speech-rule-engine is ready and not in temporary mode
88657
+ if (!temporary && sreReady) {
88658
+ try {
88659
+ updatedDocument = updatedDocument.assistiveMml().attachSpeech();
88660
+ } catch (e) {
88661
+ // If this fails, speech-rule-engine isn't ready
88662
+ // eslint-disable-next-line no-console
88663
+ console.warn('[math-rendering] Speech-rule-engine not fully initialized, skipping assistive features');
88664
+ sreReady = false;
88665
+ }
88666
+ }
88667
+ updatedDocument = updatedDocument.addMenu().updateDocument();
88668
+ if (!enrichSpeechInitialized && typeof ((_updatedDocument$math = updatedDocument.math.list) == null || (_updatedDocument$math = _updatedDocument$math.next) == null ? void 0 : _updatedDocument$math.data) === 'object') {
88714
88669
  enrichSpeechInitialized = true;
88715
88670
  }
88716
-
88717
88671
  try {
88718
88672
  const list = updatedDocument.math.list;
88719
-
88720
88673
  if (list) {
88721
88674
  for (let item = list.next; typeof item.data !== 'symbol'; item = item.next) {
88722
88675
  const mathMl = toMMl(item.data.root);
@@ -88729,64 +88682,50 @@ const bootstrap = opts => {
88729
88682
  // eslint-disable-next-line no-console
88730
88683
  console.error(e.toString());
88731
88684
  }
88732
-
88733
88685
  updatedDocument.clear();
88734
88686
  };
88735
-
88736
88687
  if (!enrichSpeechInitialized) {
88737
88688
  attemptRender(true);
88738
88689
  }
88739
-
88740
88690
  mathjaxExports.mathjax.handleRetriesFor(() => {
88741
88691
  attemptRender();
88742
88692
  });
88743
88693
  }
88744
88694
  };
88745
88695
  };
88746
-
88747
88696
  const renderMath = (el, renderOpts) => {
88748
88697
  var _getGlobal$instance, _getGlobal$instance2;
88749
-
88750
88698
  if (window && window.MathJax && window.MathJax.customKey && window.MathJax.customKey == '@pie-lib/math-rendering-accessible@1') {
88751
88699
  return;
88752
88700
  }
88753
-
88754
88701
  const isString = typeof el === 'string';
88755
88702
  let executeOn = document.body;
88756
-
88757
88703
  if (isString) {
88758
88704
  const div = document.createElement('div');
88759
88705
  div.innerHTML = el;
88760
88706
  executeOn = div;
88761
88707
  }
88762
-
88763
88708
  fixMathElements(executeOn);
88764
88709
  adjustMathMLStyle(executeOn);
88765
-
88766
88710
  if (isString) {
88767
88711
  const html = createMathMLInstance(undefined, executeOn);
88768
88712
  const updatedDocument = html.findMath().compile().getMetrics().typeset().updateDocument();
88769
88713
  const list = updatedDocument.math.list;
88770
88714
  const item = list.next;
88771
-
88772
88715
  if (!item) {
88773
88716
  return '';
88774
88717
  }
88775
-
88776
88718
  const mathMl = toMMl(item.data.root);
88777
88719
  const parsedMathMl = mathMl.replaceAll('\n', '');
88778
88720
  return parsedMathMl;
88779
88721
  }
88780
-
88781
88722
  if (!getGlobal().instance) {
88782
88723
  getGlobal().instance = bootstrap(renderOpts);
88783
88724
  }
88784
-
88785
88725
  if (!el) {
88786
88726
  log('el is undefined');
88787
88727
  return;
88788
88728
  }
88789
-
88790
88729
  if (el instanceof Element && (_getGlobal$instance = getGlobal().instance) != null && _getGlobal$instance.Typeset) {
88791
88730
  getGlobal().instance.Typeset(el);
88792
88731
  } else if (el.length && (_getGlobal$instance2 = getGlobal().instance) != null && _getGlobal$instance2.Typeset) {
@@ -88794,6 +88733,7 @@ const renderMath = (el, renderOpts) => {
88794
88733
  getGlobal().instance.Typeset(...arr);
88795
88734
  }
88796
88735
  };
88736
+
88797
88737
  /**
88798
88738
  * This style is added to overried default styling of mjx-mspace Mathjax tag
88799
88739
  * In mathjax src code \newline latex gets parsed to <mjx-mspace></mjx-mspace>,
@@ -88803,8 +88743,6 @@ const renderMath = (el, renderOpts) => {
88803
88743
  "text-align": 'left'
88804
88744
  } which prevents it from showing as a newline value
88805
88745
  */
88806
-
88807
-
88808
88746
  mspaceExports.CHTMLmspace.styles = {
88809
88747
  'mjx-mspace': {
88810
88748
  display: 'block',
@@ -88831,7 +88769,7 @@ function requireBundle_min () {
88831
88769
 
88832
88770
  var bundle_minExports = requireBundle_min();
88833
88771
 
88834
- var mmlToLatex = (mathml => bundle_minExports.MathMLToLaTeX.convert(mathml));
88772
+ var mmlToLatex = mathml => bundle_minExports.MathMLToLaTeX.convert(mathml);
88835
88773
 
88836
88774
  export { mmlToLatex, renderMath, unWrapMath, wrapMath };
88837
88775
  //# sourceMappingURL=index.js.map