@doenet/doenetml-iframe 0.7.25-dev.502 → 0.7.25-dev.503

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.
Files changed (3) hide show
  1. package/index.js +70 -10
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -42078,23 +42078,71 @@ function loadMathJax(options = {}) {
42078
42078
  });
42079
42079
  return promise;
42080
42080
  }
42081
+ function isThenable(value) {
42082
+ return !!value && (typeof value === "object" || typeof value === "function") && typeof value.then === "function";
42083
+ }
42084
+ function untilAborted(promise, signal) {
42085
+ return new Promise((resolve, reject2) => {
42086
+ promise.then(
42087
+ (value) => {
42088
+ if (!signal.aborted) {
42089
+ resolve(value);
42090
+ }
42091
+ },
42092
+ (reason) => {
42093
+ if (!signal.aborted) {
42094
+ reject2(reason);
42095
+ }
42096
+ }
42097
+ );
42098
+ });
42099
+ }
42100
+ function untilAbortedEngine(engine, signal) {
42101
+ return new Proxy(engine, {
42102
+ get(target, property2, receiver) {
42103
+ const value = Reflect.get(target, property2, receiver);
42104
+ if (property2 === "startup" && value && // MathJax 4 exposes `startup` as a callable function with the
42105
+ // startup members attached; MathJax 3 as a plain object. Either
42106
+ // way, the recursion is what gates `startup.promise` below.
42107
+ (typeof value === "object" || typeof value === "function")) {
42108
+ return untilAbortedEngine(value, signal);
42109
+ }
42110
+ if (property2 === "promise" && isThenable(value)) {
42111
+ return untilAborted(Promise.resolve(value), signal);
42112
+ }
42113
+ if (typeof value === "function") {
42114
+ if (property2 === "typesetClear") {
42115
+ return (...args) => signal.aborted ? void 0 : value.apply(target, args);
42116
+ }
42117
+ if (property2 === "typesetPromise") {
42118
+ return (...args) => signal.aborted ? Promise.resolve() : value.apply(target, args);
42119
+ }
42120
+ }
42121
+ return value;
42122
+ }
42123
+ });
42124
+ }
42081
42125
  function MathJaxContext({
42082
42126
  config: config2,
42083
42127
  src,
42084
42128
  useExistingMathJax,
42085
42129
  timeoutMs,
42086
42130
  version: version2 = 4,
42131
+ signal,
42087
42132
  children
42088
42133
  }) {
42089
42134
  const value = useMemo(() => {
42090
- const promise = loadMathJax({
42135
+ const loaded = loadMathJax({
42091
42136
  config: config2,
42092
42137
  src,
42093
42138
  useExistingMathJax,
42094
42139
  timeoutMs
42095
42140
  });
42141
+ const promise = signal ? untilAborted(loaded, signal).then(
42142
+ (engine) => untilAbortedEngine(engine, signal)
42143
+ ) : loaded;
42096
42144
  return { version: version2, promise };
42097
- }, [config2, src, useExistingMathJax, timeoutMs, version2]);
42145
+ }, [config2, src, useExistingMathJax, timeoutMs, version2, signal]);
42098
42146
  return /* @__PURE__ */ React__default.createElement(MathJaxBaseContext.Provider, { value }, children);
42099
42147
  }
42100
42148
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
@@ -68252,6 +68300,7 @@ const virtualKeyboardState = globalThis$1?.virtualKeyboardState || {
68252
68300
  focusedMathInputSources: /* @__PURE__ */ new Set(),
68253
68301
  keyboardDomNode: null,
68254
68302
  keyboardReactRoot: null,
68303
+ keyboardMathJaxAbort: null,
68255
68304
  registrations: [],
68256
68305
  lastActiveRegistrationId: null,
68257
68306
  nextRegistrationId: 0
@@ -68390,14 +68439,22 @@ function TrayWithSharedOpenState({
68390
68439
  );
68391
68440
  }
68392
68441
  function renderTray(theme, translate, direction) {
68393
- return /* @__PURE__ */ React__default.createElement(MathJaxContext, { config: mathjaxConfig, version: 4 }, /* @__PURE__ */ React__default.createElement(
68394
- TrayWithSharedOpenState,
68442
+ return /* @__PURE__ */ React__default.createElement(
68443
+ MathJaxContext,
68395
68444
  {
68396
- theme,
68397
- translate,
68398
- direction
68399
- }
68400
- ));
68445
+ config: mathjaxConfig,
68446
+ version: 4,
68447
+ signal: virtualKeyboardState.keyboardMathJaxAbort?.signal
68448
+ },
68449
+ /* @__PURE__ */ React__default.createElement(
68450
+ TrayWithSharedOpenState,
68451
+ {
68452
+ theme,
68453
+ translate,
68454
+ direction
68455
+ }
68456
+ )
68457
+ );
68401
68458
  }
68402
68459
  function UniqueKeyboardTray({
68403
68460
  onClick,
@@ -68417,6 +68474,7 @@ function UniqueKeyboardTray({
68417
68474
  keyboardDomNode.id = "virtual-keyboard-dummy";
68418
68475
  document.body.appendChild(keyboardDomNode);
68419
68476
  virtualKeyboardState.keyboardDomNode = keyboardDomNode;
68477
+ virtualKeyboardState.keyboardMathJaxAbort = new AbortController();
68420
68478
  const root2 = createRoot(keyboardDomNode);
68421
68479
  virtualKeyboardState.keyboardReactRoot = root2;
68422
68480
  virtualKeyboardState.handleFocusChange = () => {
@@ -68454,6 +68512,8 @@ function UniqueKeyboardTray({
68454
68512
  );
68455
68513
  virtualKeyboardState.handleFocusChange = void 0;
68456
68514
  }
68515
+ virtualKeyboardState.keyboardMathJaxAbort?.abort();
68516
+ virtualKeyboardState.keyboardMathJaxAbort = null;
68457
68517
  if (virtualKeyboardState.keyboardReactRoot) {
68458
68518
  const root2 = virtualKeyboardState.keyboardReactRoot;
68459
68519
  setTimeout(() => {
@@ -68534,7 +68594,7 @@ function ExternalVirtualKeyboard({
68534
68594
  }
68535
68595
  );
68536
68596
  }
68537
- const version = "0.7.25-dev.502";
68597
+ const version = "0.7.25-dev.503";
68538
68598
  const latestDoenetmlVersion = version;
68539
68599
  function subscribeToPinnedTheme() {
68540
68600
  return () => {