@doenet/doenetml-iframe 0.7.27-dev.768 → 0.7.27-dev.770

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/index.d.ts CHANGED
@@ -63,7 +63,10 @@ export declare type DoenetEditorIframeProps = DoenetEditorProps & {
63
63
  /**
64
64
  * If `true`, look for a xmlns attribute in an outer `<document>` tag
65
65
  * and use that for the doenetmlVersion,
66
- * overwriting any doenetmlVersion or urls provided
66
+ * overwriting any doenetmlVersion or urls provided.
67
+ * If the bundle for the detected version fails to load (e.g. the version
68
+ * is mistyped or was never published), fall back to the provided urls,
69
+ * or else to doenetmlVersion or the latest version, and warn.
67
70
  */
68
71
  autodetectVersion?: boolean;
69
72
  /**
@@ -129,7 +132,10 @@ export declare type DoenetViewerIframeProps = DoenetViewerProps & {
129
132
  /**
130
133
  * If `true`, look for a xmlns attribute in an outer `<document>` tag
131
134
  * and use that for the doenetmlVersion,
132
- * overwriting any doenetmlVersion or urls provided
135
+ * overwriting any doenetmlVersion or urls provided.
136
+ * If the bundle for the detected version fails to load (e.g. the version
137
+ * is mistyped or was never published), fall back to the provided urls,
138
+ * or else to doenetmlVersion or the latest version, and warn.
133
139
  */
134
140
  autodetectVersion?: boolean;
135
141
  /**
package/index.js CHANGED
@@ -59180,63 +59180,6 @@ const guarded = new Proxy(glue, {
59180
59180
  s$2(guarded);
59181
59181
  Q.dopri;
59182
59182
  const context = Q;
59183
- function getLineCharRange(position2, allNewlines) {
59184
- let { begin, end } = getBeginEndFromDoenetMLRange(position2);
59185
- if (begin === void 0 || end === void 0) {
59186
- return {};
59187
- }
59188
- let { line: lineBegin, character: charBegin } = findLineCharInfo(
59189
- begin,
59190
- allNewlines
59191
- );
59192
- let { line: lineEnd, character: charEnd } = findLineCharInfo(
59193
- end,
59194
- allNewlines
59195
- );
59196
- return { lineBegin, charBegin, lineEnd, charEnd };
59197
- }
59198
- function getBeginEndFromDoenetMLRange(position2) {
59199
- let begin, end;
59200
- if (position2) {
59201
- if (position2.begin !== void 0) {
59202
- begin = position2.begin;
59203
- end = position2.end;
59204
- } else if (position2.selfCloseBegin !== void 0) {
59205
- begin = position2.selfCloseBegin;
59206
- end = position2.selfCloseEnd;
59207
- } else if (position2.openBegin !== void 0) {
59208
- begin = position2.openBegin;
59209
- end = position2.closeEnd;
59210
- }
59211
- position2.begin = begin;
59212
- position2.end = end;
59213
- }
59214
- return { begin, end };
59215
- }
59216
- function findAllNewlines(inText) {
59217
- let allNewlines = [];
59218
- for (let i3 = 0; i3 < inText.length; i3++) {
59219
- if (inText[i3] == "\n") {
59220
- allNewlines.push(i3 + 1);
59221
- }
59222
- }
59223
- return allNewlines;
59224
- }
59225
- function findLineCharInfo(pos, allNewlines) {
59226
- for (let i3 = 0; i3 < allNewlines.length; i3++) {
59227
- if (pos <= allNewlines[i3]) {
59228
- if (i3 === 0) {
59229
- return { line: 1, character: pos };
59230
- } else {
59231
- return { line: i3 + 1, character: pos - allNewlines[i3 - 1] };
59232
- }
59233
- }
59234
- }
59235
- return {
59236
- line: allNewlines.length + 1,
59237
- character: pos - (allNewlines[allNewlines.length - 1] || 0)
59238
- };
59239
- }
59240
59183
  var base32$1$1 = { exports: {} };
59241
59184
  var hasRequiredBase32$1;
59242
59185
  function requireBase32$1() {
@@ -59882,7 +59825,7 @@ function requireCssesc$1() {
59882
59825
  return cssesc_1$1;
59883
59826
  }
59884
59827
  requireCssesc$1();
59885
- const viewerIframeJsSource = '(function() {\n "use strict";\n const proxyMarker = /* @__PURE__ */ Symbol("Comlink.proxy");\n const createEndpoint = /* @__PURE__ */ Symbol("Comlink.endpoint");\n const releaseProxy = /* @__PURE__ */ Symbol("Comlink.releaseProxy");\n const finalizer = /* @__PURE__ */ Symbol("Comlink.finalizer");\n const throwMarker = /* @__PURE__ */ Symbol("Comlink.thrown");\n const isObject = (val) => typeof val === "object" && val !== null || typeof val === "function";\n const proxyTransferHandler = {\n canHandle: (val) => isObject(val) && val[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n }\n };\n const throwTransferHandler = {\n canHandle: (value) => isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack\n }\n };\n } else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(new Error(serialized.value.message), serialized.value);\n }\n throw serialized.value;\n }\n };\n const transferHandlers = /* @__PURE__ */ new Map([\n ["proxy", proxyTransferHandler],\n ["throw", throwTransferHandler]\n ]);\n function isAllowedOrigin(allowedOrigins, origin) {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === "*") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n }\n function expose(obj, ep = globalThis, allowedOrigins = ["*"]) {\n ep.addEventListener("message", function callback(ev) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin \'${ev.origin}\' for comlink proxy`);\n return;\n }\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj2, prop) => obj2[prop], obj);\n const rawValue = path.reduce((obj2, prop) => obj2[prop], obj);\n switch (type) {\n case "GET":\n {\n returnValue = rawValue;\n }\n break;\n case "SET":\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case "APPLY":\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case "CONSTRUCT":\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case "ENDPOINT":\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case "RELEASE":\n {\n returnValue = void 0;\n }\n break;\n default:\n return;\n }\n } catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue).catch((value) => {\n return { value, [throwMarker]: 0 };\n }).then((returnValue2) => {\n const [wireValue, transferables] = toWireValue(returnValue2);\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n if (type === "RELEASE") {\n ep.removeEventListener("message", callback);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === "function") {\n obj[finalizer]();\n }\n }\n }).catch((error) => {\n const [wireValue, transferables] = toWireValue({\n value: new TypeError("Unserializable return value"),\n [throwMarker]: 0\n });\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n });\n });\n if (ep.start) {\n ep.start();\n }\n }\n function isMessagePort(endpoint) {\n return endpoint.constructor.name === "MessagePort";\n }\n function closeEndPoint(endpoint) {\n if (isMessagePort(endpoint))\n endpoint.close();\n }\n function wrap(ep, target) {\n const pendingListeners = /* @__PURE__ */ new Map();\n ep.addEventListener("message", function handleMessage(ev) {\n const { data } = ev;\n if (!data || !data.id) {\n return;\n }\n const resolver = pendingListeners.get(data.id);\n if (!resolver) {\n return;\n }\n try {\n resolver(data);\n } finally {\n pendingListeners.delete(data.id);\n }\n });\n return createProxy(ep, pendingListeners, [], target);\n }\n function throwIfProxyReleased(isReleased) {\n if (isReleased) {\n throw new Error("Proxy has been released and is not useable");\n }\n }\n function releaseEndpoint(ep) {\n return requestResponseMessage(ep, /* @__PURE__ */ new Map(), {\n type: "RELEASE"\n }).then(() => {\n closeEndPoint(ep);\n });\n }\n const proxyCounter = /* @__PURE__ */ new WeakMap();\n const proxyFinalizers = "FinalizationRegistry" in globalThis && new FinalizationRegistry((ep) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\n function registerProxy(proxy2, ep) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy2, ep, proxy2);\n }\n }\n function unregisterProxy(proxy2) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy2);\n }\n }\n function createProxy(ep, pendingListeners, path = [], target = function() {\n }) {\n let isProxyReleased = false;\n const proxy2 = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy2);\n releaseEndpoint(ep);\n pendingListeners.clear();\n isProxyReleased = true;\n };\n }\n if (prop === "then") {\n if (path.length === 0) {\n return { then: () => proxy2 };\n }\n const r = requestResponseMessage(ep, pendingListeners, {\n type: "GET",\n path: path.map((p) => p.toString())\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, pendingListeners, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(ep, pendingListeners, {\n type: "SET",\n path: [...path, prop].map((p) => p.toString()),\n value\n }, transferables).then(fromWireValue);\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if (last === createEndpoint) {\n return requestResponseMessage(ep, pendingListeners, {\n type: "ENDPOINT"\n }).then(fromWireValue);\n }\n if (last === "bind") {\n return createProxy(ep, pendingListeners, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: "APPLY",\n path: path.map((p) => p.toString()),\n argumentList\n }, transferables).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: "CONSTRUCT",\n path: path.map((p) => p.toString()),\n argumentList\n }, transferables).then(fromWireValue);\n }\n });\n registerProxy(proxy2, ep);\n return proxy2;\n }\n function myFlat(arr) {\n return Array.prototype.concat.apply([], arr);\n }\n function processArguments(argumentList) {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n }\n const transferCache = /* @__PURE__ */ new WeakMap();\n function transfer(obj, transfers) {\n transferCache.set(obj, transfers);\n return obj;\n }\n function proxy(obj) {\n return Object.assign(obj, { [proxyMarker]: true });\n }\n function windowEndpoint(w, context = globalThis, targetOrigin = "*") {\n return {\n postMessage: (msg, transferables) => w.postMessage(msg, targetOrigin, transferables),\n addEventListener: context.addEventListener.bind(context),\n removeEventListener: context.removeEventListener.bind(context)\n };\n }\n function toWireValue(value) {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: "HANDLER",\n name,\n value: serializedValue\n },\n transferables\n ];\n }\n }\n return [\n {\n type: "RAW",\n value\n },\n transferCache.get(value) || []\n ];\n }\n function fromWireValue(value) {\n switch (value.type) {\n case "HANDLER":\n return transferHandlers.get(value.name).deserialize(value.value);\n case "RAW":\n return value.value;\n }\n }\n function requestResponseMessage(ep, pendingListeners, msg, transfers) {\n return new Promise((resolve) => {\n const id = generateUUID();\n pendingListeners.set(id, resolve);\n if (ep.start) {\n ep.start();\n }\n ep.postMessage(Object.assign({ id }, msg), transfers);\n });\n }\n function generateUUID() {\n return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");\n }\n let lastAugmentedProps = null;\n let currentFunctionProps = {};\n const functionPropDispatchers = {};\n function getFunctionPropDispatcher(key) {\n let dispatcher = functionPropDispatchers[key];\n if (!dispatcher) {\n if (key === "reportScoreAndStateCallback" && typeof doenetWindowedViewer !== "undefined" && doenetWindowedViewer) {\n dispatcher = (report) => messageParentFromViewer({\n type: "reportScoreAndState",\n report\n });\n } else {\n dispatcher = (...callArgs) => currentFunctionProps[key]?.(...callArgs);\n }\n functionPropDispatchers[key] = dispatcher;\n }\n return dispatcher;\n }\n function functionPropArgsToMap(args) {\n const map = {};\n for (let i = 0; i < args.length; i += 2) {\n const key = args[i];\n const fn = args[i + 1];\n if (typeof key === "string" && typeof fn === "function") {\n map[key] = fn;\n }\n }\n return map;\n }\n function releaseFunctionProxy(fn) {\n try {\n fn?.[releaseProxy]?.();\n } catch (e) {\n console.warn(\n "iframe DoenetViewer: failed to release stale Comlink proxy",\n e\n );\n }\n }\n function setCurrentFunctionProps(incoming) {\n for (const [key, fn] of Object.entries(currentFunctionProps)) {\n if (incoming[key] !== fn) {\n releaseFunctionProxy(fn);\n }\n }\n currentFunctionProps = incoming;\n }\n function defaultRequestScrollTo(offset) {\n messageParentFromViewer({ type: "scrollTo", offset });\n }\n function syncAugmentedFunctionProps() {\n if (!lastAugmentedProps) {\n return;\n }\n const next = {};\n for (const [key, val] of Object.entries(lastAugmentedProps)) {\n if (typeof val !== "function") {\n next[key] = val;\n }\n }\n for (const key of Object.keys(currentFunctionProps)) {\n next[key] = getFunctionPropDispatcher(key);\n }\n if (!("requestScrollTo" in next)) {\n next.requestScrollTo = defaultRequestScrollTo;\n }\n lastAugmentedProps = next;\n }\n let currentDoenetMLSource = null;\n function resolveDoenetMLSource(root) {\n if (currentDoenetMLSource !== null) {\n return currentDoenetMLSource;\n }\n const scriptTag = root.querySelector(\'script[type="text/doenetml"]\');\n currentDoenetMLSource = scriptTag?.innerHTML ?? "";\n return currentDoenetMLSource;\n }\n async function waitForStandaloneBundle(timeoutMs) {\n function bundleReady() {\n const render = window.renderDoenetViewerToContainer;\n return typeof render === "function" && !render.__doenetPendingRenderStub;\n }\n if (bundleReady()) {\n return true;\n }\n const deadline = Date.now() + timeoutMs;\n while (Date.now() < deadline) {\n await new Promise((resolve) => setTimeout(resolve, 50));\n if (bundleReady()) {\n return true;\n }\n }\n return false;\n }\n expose(\n {\n renderViewerWithFunctionProps,\n updateViewerProps(updatedSerializableProps) {\n if (!lastAugmentedProps) {\n console.warn(\n "iframe DoenetViewer: updateViewerProps arrived before renderViewerWithFunctionProps completed — likely a bug in the iframe wrapper\'s queue/replay sequencing."\n );\n return;\n }\n const { doenetML, ...rest } = updatedSerializableProps;\n if (typeof doenetML === "string") {\n currentDoenetMLSource = doenetML;\n }\n lastAugmentedProps = {\n ...lastAugmentedProps,\n ...rest\n };\n renderWithLastAugmentedProps();\n },\n updateViewerFunctionProps(...args) {\n if (!lastAugmentedProps) {\n console.warn(\n "iframe DoenetViewer: updateViewerFunctionProps arrived before renderViewerWithFunctionProps completed — likely a bug in the iframe wrapper\'s queue/replay sequencing."\n );\n return;\n }\n const incoming = functionPropArgsToMap(args);\n const prevKeys = Object.keys(currentFunctionProps).sort();\n const nextKeys = Object.keys(incoming).sort();\n const keysChanged = prevKeys.length !== nextKeys.length || prevKeys.some((key, i) => key !== nextKeys[i]);\n setCurrentFunctionProps(incoming);\n if (keysChanged) {\n syncAugmentedFunctionProps();\n renderWithLastAugmentedProps();\n }\n }\n },\n windowEndpoint(globalThis.parent)\n );\n function renderViewerWithFunctionProps(...args) {\n setCurrentFunctionProps(functionPropArgsToMap(args));\n const augmentedDoenetViewerProps = { ...doenetViewerProps };\n augmentedDoenetViewerProps.externalVirtualKeyboardProvided = true;\n for (const propName of doenetViewerPropsSpecified) {\n if (!(propName in doenetViewerProps) && propName in currentFunctionProps) {\n augmentedDoenetViewerProps[propName] = getFunctionPropDispatcher(propName);\n }\n }\n if (!doenetViewerPropsSpecified.includes("requestScrollTo")) {\n augmentedDoenetViewerProps.requestScrollTo = defaultRequestScrollTo;\n }\n lastAugmentedProps = augmentedDoenetViewerProps;\n renderWithLastAugmentedProps();\n }\n function renderWithLastAugmentedProps() {\n const root = document.getElementById("root");\n window.renderDoenetViewerToContainer(\n root,\n resolveDoenetMLSource(root),\n lastAugmentedProps\n );\n }\n function installSharedCorePortProvider() {\n let coreCounter = 0;\n window.doenetGlobalConfig.createExternalCoreWorkerPort = () => {\n const coreId = `${viewerId}-core-${++coreCounter}`;\n const channel = new MessageChannel();\n window.parent.postMessage(\n { origin: viewerId, data: { type: "createSharedCore", coreId } },\n window.parent.origin,\n [channel.port2]\n );\n return {\n port: channel.port1,\n destroy: (suspectWedge) => {\n messageParentFromViewer({\n type: "destroySharedCore",\n coreId,\n suspectWedge: Boolean(suspectWedge)\n });\n }\n };\n };\n }\n (async () => {\n if (await waitForStandaloneBundle(6e4)) {\n if (typeof doenetSharedCoreWorker !== "undefined" && doenetSharedCoreWorker) {\n installSharedCorePortProvider();\n }\n messageParentFromViewer({\n iframeReady: true,\n stylePalettes: readStylePalettesFromBundle()\n });\n } else {\n messageParentFromViewer({\n error: "Invalid DoenetML version or DoenetML package not found"\n });\n }\n })().catch((err) => {\n console.error(\n "iframe DoenetViewer: unexpected failure while signalling iframeReady",\n err\n );\n try {\n messageParentFromViewer({\n error: "iframe viewer failed to initialize"\n });\n } catch {\n }\n });\n function readStylePalettesFromBundle() {\n try {\n return window.getDoenetStylePalettes?.() ?? null;\n } catch (err) {\n console.error(\n "iframe DoenetML: failed to read style palettes from the standalone bundle",\n err\n );\n return null;\n }\n }\n function messageParentFromViewer(data) {\n window.parent.postMessage(\n {\n origin: viewerId,\n data\n },\n window.parent.origin\n );\n }\n})();\n';
59828
+ const viewerIframeJsSource = '(function() {\n "use strict";\n const proxyMarker = /* @__PURE__ */ Symbol("Comlink.proxy");\n const createEndpoint = /* @__PURE__ */ Symbol("Comlink.endpoint");\n const releaseProxy = /* @__PURE__ */ Symbol("Comlink.releaseProxy");\n const finalizer = /* @__PURE__ */ Symbol("Comlink.finalizer");\n const throwMarker = /* @__PURE__ */ Symbol("Comlink.thrown");\n const isObject = (val) => typeof val === "object" && val !== null || typeof val === "function";\n const proxyTransferHandler = {\n canHandle: (val) => isObject(val) && val[proxyMarker],\n serialize(obj) {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port1);\n return [port2, [port2]];\n },\n deserialize(port) {\n port.start();\n return wrap(port);\n }\n };\n const throwTransferHandler = {\n canHandle: (value) => isObject(value) && throwMarker in value,\n serialize({ value }) {\n let serialized;\n if (value instanceof Error) {\n serialized = {\n isError: true,\n value: {\n message: value.message,\n name: value.name,\n stack: value.stack\n }\n };\n } else {\n serialized = { isError: false, value };\n }\n return [serialized, []];\n },\n deserialize(serialized) {\n if (serialized.isError) {\n throw Object.assign(new Error(serialized.value.message), serialized.value);\n }\n throw serialized.value;\n }\n };\n const transferHandlers = /* @__PURE__ */ new Map([\n ["proxy", proxyTransferHandler],\n ["throw", throwTransferHandler]\n ]);\n function isAllowedOrigin(allowedOrigins, origin) {\n for (const allowedOrigin of allowedOrigins) {\n if (origin === allowedOrigin || allowedOrigin === "*") {\n return true;\n }\n if (allowedOrigin instanceof RegExp && allowedOrigin.test(origin)) {\n return true;\n }\n }\n return false;\n }\n function expose(obj, ep = globalThis, allowedOrigins = ["*"]) {\n ep.addEventListener("message", function callback(ev) {\n if (!ev || !ev.data) {\n return;\n }\n if (!isAllowedOrigin(allowedOrigins, ev.origin)) {\n console.warn(`Invalid origin \'${ev.origin}\' for comlink proxy`);\n return;\n }\n const { id, type, path } = Object.assign({ path: [] }, ev.data);\n const argumentList = (ev.data.argumentList || []).map(fromWireValue);\n let returnValue;\n try {\n const parent = path.slice(0, -1).reduce((obj2, prop) => obj2[prop], obj);\n const rawValue = path.reduce((obj2, prop) => obj2[prop], obj);\n switch (type) {\n case "GET":\n {\n returnValue = rawValue;\n }\n break;\n case "SET":\n {\n parent[path.slice(-1)[0]] = fromWireValue(ev.data.value);\n returnValue = true;\n }\n break;\n case "APPLY":\n {\n returnValue = rawValue.apply(parent, argumentList);\n }\n break;\n case "CONSTRUCT":\n {\n const value = new rawValue(...argumentList);\n returnValue = proxy(value);\n }\n break;\n case "ENDPOINT":\n {\n const { port1, port2 } = new MessageChannel();\n expose(obj, port2);\n returnValue = transfer(port1, [port1]);\n }\n break;\n case "RELEASE":\n {\n returnValue = void 0;\n }\n break;\n default:\n return;\n }\n } catch (value) {\n returnValue = { value, [throwMarker]: 0 };\n }\n Promise.resolve(returnValue).catch((value) => {\n return { value, [throwMarker]: 0 };\n }).then((returnValue2) => {\n const [wireValue, transferables] = toWireValue(returnValue2);\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n if (type === "RELEASE") {\n ep.removeEventListener("message", callback);\n closeEndPoint(ep);\n if (finalizer in obj && typeof obj[finalizer] === "function") {\n obj[finalizer]();\n }\n }\n }).catch((error) => {\n const [wireValue, transferables] = toWireValue({\n value: new TypeError("Unserializable return value"),\n [throwMarker]: 0\n });\n ep.postMessage(Object.assign(Object.assign({}, wireValue), { id }), transferables);\n });\n });\n if (ep.start) {\n ep.start();\n }\n }\n function isMessagePort(endpoint) {\n return endpoint.constructor.name === "MessagePort";\n }\n function closeEndPoint(endpoint) {\n if (isMessagePort(endpoint))\n endpoint.close();\n }\n function wrap(ep, target) {\n const pendingListeners = /* @__PURE__ */ new Map();\n ep.addEventListener("message", function handleMessage(ev) {\n const { data } = ev;\n if (!data || !data.id) {\n return;\n }\n const resolver = pendingListeners.get(data.id);\n if (!resolver) {\n return;\n }\n try {\n resolver(data);\n } finally {\n pendingListeners.delete(data.id);\n }\n });\n return createProxy(ep, pendingListeners, [], target);\n }\n function throwIfProxyReleased(isReleased) {\n if (isReleased) {\n throw new Error("Proxy has been released and is not useable");\n }\n }\n function releaseEndpoint(ep) {\n return requestResponseMessage(ep, /* @__PURE__ */ new Map(), {\n type: "RELEASE"\n }).then(() => {\n closeEndPoint(ep);\n });\n }\n const proxyCounter = /* @__PURE__ */ new WeakMap();\n const proxyFinalizers = "FinalizationRegistry" in globalThis && new FinalizationRegistry((ep) => {\n const newCount = (proxyCounter.get(ep) || 0) - 1;\n proxyCounter.set(ep, newCount);\n if (newCount === 0) {\n releaseEndpoint(ep);\n }\n });\n function registerProxy(proxy2, ep) {\n const newCount = (proxyCounter.get(ep) || 0) + 1;\n proxyCounter.set(ep, newCount);\n if (proxyFinalizers) {\n proxyFinalizers.register(proxy2, ep, proxy2);\n }\n }\n function unregisterProxy(proxy2) {\n if (proxyFinalizers) {\n proxyFinalizers.unregister(proxy2);\n }\n }\n function createProxy(ep, pendingListeners, path = [], target = function() {\n }) {\n let isProxyReleased = false;\n const proxy2 = new Proxy(target, {\n get(_target, prop) {\n throwIfProxyReleased(isProxyReleased);\n if (prop === releaseProxy) {\n return () => {\n unregisterProxy(proxy2);\n releaseEndpoint(ep);\n pendingListeners.clear();\n isProxyReleased = true;\n };\n }\n if (prop === "then") {\n if (path.length === 0) {\n return { then: () => proxy2 };\n }\n const r = requestResponseMessage(ep, pendingListeners, {\n type: "GET",\n path: path.map((p) => p.toString())\n }).then(fromWireValue);\n return r.then.bind(r);\n }\n return createProxy(ep, pendingListeners, [...path, prop]);\n },\n set(_target, prop, rawValue) {\n throwIfProxyReleased(isProxyReleased);\n const [value, transferables] = toWireValue(rawValue);\n return requestResponseMessage(ep, pendingListeners, {\n type: "SET",\n path: [...path, prop].map((p) => p.toString()),\n value\n }, transferables).then(fromWireValue);\n },\n apply(_target, _thisArg, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const last = path[path.length - 1];\n if (last === createEndpoint) {\n return requestResponseMessage(ep, pendingListeners, {\n type: "ENDPOINT"\n }).then(fromWireValue);\n }\n if (last === "bind") {\n return createProxy(ep, pendingListeners, path.slice(0, -1));\n }\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: "APPLY",\n path: path.map((p) => p.toString()),\n argumentList\n }, transferables).then(fromWireValue);\n },\n construct(_target, rawArgumentList) {\n throwIfProxyReleased(isProxyReleased);\n const [argumentList, transferables] = processArguments(rawArgumentList);\n return requestResponseMessage(ep, pendingListeners, {\n type: "CONSTRUCT",\n path: path.map((p) => p.toString()),\n argumentList\n }, transferables).then(fromWireValue);\n }\n });\n registerProxy(proxy2, ep);\n return proxy2;\n }\n function myFlat(arr) {\n return Array.prototype.concat.apply([], arr);\n }\n function processArguments(argumentList) {\n const processed = argumentList.map(toWireValue);\n return [processed.map((v) => v[0]), myFlat(processed.map((v) => v[1]))];\n }\n const transferCache = /* @__PURE__ */ new WeakMap();\n function transfer(obj, transfers) {\n transferCache.set(obj, transfers);\n return obj;\n }\n function proxy(obj) {\n return Object.assign(obj, { [proxyMarker]: true });\n }\n function windowEndpoint(w, context = globalThis, targetOrigin = "*") {\n return {\n postMessage: (msg, transferables) => w.postMessage(msg, targetOrigin, transferables),\n addEventListener: context.addEventListener.bind(context),\n removeEventListener: context.removeEventListener.bind(context)\n };\n }\n function toWireValue(value) {\n for (const [name, handler] of transferHandlers) {\n if (handler.canHandle(value)) {\n const [serializedValue, transferables] = handler.serialize(value);\n return [\n {\n type: "HANDLER",\n name,\n value: serializedValue\n },\n transferables\n ];\n }\n }\n return [\n {\n type: "RAW",\n value\n },\n transferCache.get(value) || []\n ];\n }\n function fromWireValue(value) {\n switch (value.type) {\n case "HANDLER":\n return transferHandlers.get(value.name).deserialize(value.value);\n case "RAW":\n return value.value;\n }\n }\n function requestResponseMessage(ep, pendingListeners, msg, transfers) {\n return new Promise((resolve) => {\n const id = generateUUID();\n pendingListeners.set(id, resolve);\n if (ep.start) {\n ep.start();\n }\n ep.postMessage(Object.assign({ id }, msg), transfers);\n });\n }\n function generateUUID() {\n return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");\n }\n const STANDALONE_LOAD_FAILED_FLAG = "__doenetStandaloneLoadFailed";\n let lastAugmentedProps = null;\n let currentFunctionProps = {};\n const functionPropDispatchers = {};\n function getFunctionPropDispatcher(key) {\n let dispatcher = functionPropDispatchers[key];\n if (!dispatcher) {\n if (key === "reportScoreAndStateCallback" && typeof doenetWindowedViewer !== "undefined" && doenetWindowedViewer) {\n dispatcher = (report) => messageParentFromViewer({\n type: "reportScoreAndState",\n report\n });\n } else {\n dispatcher = (...callArgs) => currentFunctionProps[key]?.(...callArgs);\n }\n functionPropDispatchers[key] = dispatcher;\n }\n return dispatcher;\n }\n function functionPropArgsToMap(args) {\n const map = {};\n for (let i = 0; i < args.length; i += 2) {\n const key = args[i];\n const fn = args[i + 1];\n if (typeof key === "string" && typeof fn === "function") {\n map[key] = fn;\n }\n }\n return map;\n }\n function releaseFunctionProxy(fn) {\n try {\n fn?.[releaseProxy]?.();\n } catch (e) {\n console.warn(\n "iframe DoenetViewer: failed to release stale Comlink proxy",\n e\n );\n }\n }\n function setCurrentFunctionProps(incoming) {\n for (const [key, fn] of Object.entries(currentFunctionProps)) {\n if (incoming[key] !== fn) {\n releaseFunctionProxy(fn);\n }\n }\n currentFunctionProps = incoming;\n }\n function defaultRequestScrollTo(offset) {\n messageParentFromViewer({ type: "scrollTo", offset });\n }\n function syncAugmentedFunctionProps() {\n if (!lastAugmentedProps) {\n return;\n }\n const next = {};\n for (const [key, val] of Object.entries(lastAugmentedProps)) {\n if (typeof val !== "function") {\n next[key] = val;\n }\n }\n for (const key of Object.keys(currentFunctionProps)) {\n next[key] = getFunctionPropDispatcher(key);\n }\n if (!("requestScrollTo" in next)) {\n next.requestScrollTo = defaultRequestScrollTo;\n }\n lastAugmentedProps = next;\n }\n let currentDoenetMLSource = null;\n function resolveDoenetMLSource(root) {\n if (currentDoenetMLSource !== null) {\n return currentDoenetMLSource;\n }\n const scriptTag = root.querySelector(\'script[type="text/doenetml"]\');\n currentDoenetMLSource = scriptTag?.innerHTML ?? "";\n return currentDoenetMLSource;\n }\n async function waitForStandaloneBundle(timeoutMs) {\n function bundleReady() {\n const render = window.renderDoenetViewerToContainer;\n return typeof render === "function" && !render.__doenetPendingRenderStub;\n }\n if (bundleReady()) {\n return true;\n }\n const deadline = Date.now() + timeoutMs;\n while (Date.now() < deadline) {\n await new Promise((resolve) => setTimeout(resolve, 50));\n if (bundleReady()) {\n return true;\n }\n if (bundleLoadFailed()) {\n return false;\n }\n }\n return false;\n }\n function bundleLoadFailed() {\n return Boolean(\n window[STANDALONE_LOAD_FAILED_FLAG]\n );\n }\n expose(\n {\n renderViewerWithFunctionProps,\n updateViewerProps(updatedSerializableProps) {\n if (!lastAugmentedProps) {\n console.warn(\n "iframe DoenetViewer: updateViewerProps arrived before renderViewerWithFunctionProps completed — likely a bug in the iframe wrapper\'s queue/replay sequencing."\n );\n return;\n }\n const { doenetML, ...rest } = updatedSerializableProps;\n if (typeof doenetML === "string") {\n currentDoenetMLSource = doenetML;\n }\n lastAugmentedProps = {\n ...lastAugmentedProps,\n ...rest\n };\n renderWithLastAugmentedProps();\n },\n updateViewerFunctionProps(...args) {\n if (!lastAugmentedProps) {\n console.warn(\n "iframe DoenetViewer: updateViewerFunctionProps arrived before renderViewerWithFunctionProps completed — likely a bug in the iframe wrapper\'s queue/replay sequencing."\n );\n return;\n }\n const incoming = functionPropArgsToMap(args);\n const prevKeys = Object.keys(currentFunctionProps).sort();\n const nextKeys = Object.keys(incoming).sort();\n const keysChanged = prevKeys.length !== nextKeys.length || prevKeys.some((key, i) => key !== nextKeys[i]);\n setCurrentFunctionProps(incoming);\n if (keysChanged) {\n syncAugmentedFunctionProps();\n renderWithLastAugmentedProps();\n }\n }\n },\n windowEndpoint(globalThis.parent)\n );\n function renderViewerWithFunctionProps(...args) {\n setCurrentFunctionProps(functionPropArgsToMap(args));\n const augmentedDoenetViewerProps = { ...doenetViewerProps };\n augmentedDoenetViewerProps.externalVirtualKeyboardProvided = true;\n for (const propName of doenetViewerPropsSpecified) {\n if (!(propName in doenetViewerProps) && propName in currentFunctionProps) {\n augmentedDoenetViewerProps[propName] = getFunctionPropDispatcher(propName);\n }\n }\n if (!doenetViewerPropsSpecified.includes("requestScrollTo")) {\n augmentedDoenetViewerProps.requestScrollTo = defaultRequestScrollTo;\n }\n lastAugmentedProps = augmentedDoenetViewerProps;\n renderWithLastAugmentedProps();\n }\n function renderWithLastAugmentedProps() {\n const root = document.getElementById("root");\n window.renderDoenetViewerToContainer(\n root,\n resolveDoenetMLSource(root),\n lastAugmentedProps\n );\n }\n function installSharedCorePortProvider() {\n let coreCounter = 0;\n window.doenetGlobalConfig.createExternalCoreWorkerPort = () => {\n const coreId = `${viewerId}-core-${++coreCounter}`;\n const channel = new MessageChannel();\n window.parent.postMessage(\n { origin: viewerId, data: { type: "createSharedCore", coreId } },\n window.parent.origin,\n [channel.port2]\n );\n return {\n port: channel.port1,\n destroy: (suspectWedge) => {\n messageParentFromViewer({\n type: "destroySharedCore",\n coreId,\n suspectWedge: Boolean(suspectWedge)\n });\n }\n };\n };\n }\n (async () => {\n if (await waitForStandaloneBundle(6e4)) {\n if (typeof doenetSharedCoreWorker !== "undefined" && doenetSharedCoreWorker) {\n installSharedCorePortProvider();\n }\n messageParentFromViewer({\n iframeReady: true,\n stylePalettes: readStylePalettesFromBundle()\n });\n } else {\n messageParentFromViewer({\n error: "Invalid DoenetML version or DoenetML package not found"\n });\n }\n })().catch((err) => {\n console.error(\n "iframe DoenetViewer: unexpected failure while signalling iframeReady",\n err\n );\n try {\n messageParentFromViewer({\n error: "iframe viewer failed to initialize"\n });\n } catch {\n }\n });\n function readStylePalettesFromBundle() {\n try {\n return window.getDoenetStylePalettes?.() ?? null;\n } catch (err) {\n console.error(\n "iframe DoenetML: failed to read style palettes from the standalone bundle",\n err\n );\n return null;\n }\n }\n function messageParentFromViewer(data) {\n window.parent.postMessage(\n {\n origin: viewerId,\n data\n },\n window.parent.origin\n );\n }\n})();\n';
59886
59829
  const editorIframeJsSource = `(function() {
59887
59830
  "use strict";
59888
59831
  const proxyMarker = /* @__PURE__ */ Symbol("Comlink.proxy");
@@ -60212,6 +60155,7 @@ const editorIframeJsSource = `(function() {
60212
60155
  function generateUUID() {
60213
60156
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
60214
60157
  }
60158
+ const STANDALONE_LOAD_FAILED_FLAG = "__doenetStandaloneLoadFailed";
60215
60159
  let editorControlHandle = null;
60216
60160
  let lastAugmentedProps = null;
60217
60161
  let currentFunctionProps = {};
@@ -60291,9 +60235,17 @@ const editorIframeJsSource = `(function() {
60291
60235
  if (bundleReady()) {
60292
60236
  return true;
60293
60237
  }
60238
+ if (bundleLoadFailed()) {
60239
+ return false;
60240
+ }
60294
60241
  }
60295
60242
  return false;
60296
60243
  }
60244
+ function bundleLoadFailed() {
60245
+ return Boolean(
60246
+ window[STANDALONE_LOAD_FAILED_FLAG]
60247
+ );
60248
+ }
60297
60249
  expose(
60298
60250
  {
60299
60251
  renderEditorWithFunctionProps,
@@ -60425,6 +60377,7 @@ const editorIframeJsSource = `(function() {
60425
60377
  }
60426
60378
  })();
60427
60379
  `;
60380
+ const STANDALONE_LOAD_FAILED_FLAG = "__doenetStandaloneLoadFailed";
60428
60381
  const DARK_CANVAS = "#121212";
60429
60382
  const LIGHT_CANVAS = "white";
60430
60383
  const BODY_BACKGROUND_ATTRIBUTE = "data-doenet-body-background";
@@ -60457,7 +60410,7 @@ function setIframeBodyBackground(body, darkMode) {
60457
60410
  function createIframeHead(standaloneUrl, cssUrl) {
60458
60411
  return `
60459
60412
  <head>
60460
- <script type="module" src="${standaloneUrl}"><\/script>
60413
+ <script type="module" src="${standaloneUrl}" onerror="window.${STANDALONE_LOAD_FAILED_FLAG} = true"><\/script>
60461
60414
  <link rel="stylesheet" href="${cssUrl}">
60462
60415
  ${BODY_BACKGROUND_STYLE_BLOCK}
60463
60416
  </head>`;
@@ -76370,8 +76323,11 @@ function ExternalVirtualKeyboard({
76370
76323
  }
76371
76324
  );
76372
76325
  }
76373
- const version = "0.7.27-dev.768";
76326
+ const version = "0.7.27-dev.770";
76374
76327
  const latestDoenetmlVersion = version;
76328
+ function versionLabel(doenetmlVersion) {
76329
+ return /^\d/.test(doenetmlVersion) ? `v${doenetmlVersion}` : doenetmlVersion;
76330
+ }
76375
76331
  function subscribeToPinnedTheme() {
76376
76332
  return () => {
76377
76333
  };
@@ -76475,7 +76431,7 @@ function DoenetViewer({
76475
76431
  }
76476
76432
  const [height, setHeight] = React__default.useState("500px");
76477
76433
  const [inErrorState, setInErrorState] = React__default.useState(null);
76478
- const [ignoreDetectedVersion, setIgnoreDetectedVersion] = React__default.useState(false);
76434
+ const [failedDetectedVersion, setFailedDetectedVersion] = React__default.useState(null);
76479
76435
  const resolvedTheme = useResolvedTheme(
76480
76436
  doenetViewerProps.darkMode ?? "system"
76481
76437
  );
@@ -76491,9 +76447,9 @@ function DoenetViewer({
76491
76447
  let standaloneUrl, cssUrl;
76492
76448
  let foundAutoVersion = false;
76493
76449
  let detectedVersion;
76494
- if (autodetectVersion && !ignoreDetectedVersion) {
76450
+ if (autodetectVersion) {
76495
76451
  let result = detectVersionFromDoenetML(doenetML);
76496
- if (result?.version !== void 0) {
76452
+ if (result?.version !== void 0 && "v" + result.version !== failedDetectedVersion) {
76497
76453
  foundAutoVersion = true;
76498
76454
  detectedVersion = "v" + result.version;
76499
76455
  }
@@ -76661,7 +76617,10 @@ function DoenetViewer({
76661
76617
  if (windowed) {
76662
76618
  relinquishBootSlot();
76663
76619
  }
76664
- return setInErrorState(data.error);
76620
+ return setInErrorState({
76621
+ message: String(data.error),
76622
+ standaloneUrl: standaloneUrlRef.current
76623
+ });
76665
76624
  } else if (data.iframeReady) {
76666
76625
  onStylePalettesRef.current?.(
76667
76626
  data.stylePalettes ?? null
@@ -76940,10 +76899,17 @@ function DoenetViewer({
76940
76899
  keepLiveRef.current = keepLive;
76941
76900
  updateEffectiveVisibility();
76942
76901
  }, [windowed, keepLive]);
76902
+ if (inErrorState && inErrorState.standaloneUrl !== standaloneUrl) {
76903
+ setInErrorState(null);
76904
+ return null;
76905
+ }
76943
76906
  if (inErrorState) {
76944
76907
  if (foundAutoVersion) {
76945
- setIgnoreDetectedVersion(true);
76946
- setInErrorState("");
76908
+ console.warn(
76909
+ `DoenetViewer: the xmlns names DoenetML version \`${detectedVersion}\`, which could not be loaded; using ${specifiedStandaloneUrl ? "the host-specified standalone bundle" : `version \`${versionLabel(specifiedDoenetmlVersion ?? latestDoenetmlVersion)}\``} instead.`
76910
+ );
76911
+ setFailedDetectedVersion(detectedVersion);
76912
+ setInErrorState(null);
76947
76913
  return null;
76948
76914
  }
76949
76915
  let errorIcon = /* @__PURE__ */ React__default.createElement(
@@ -76971,7 +76937,7 @@ function DoenetViewer({
76971
76937
  },
76972
76938
  errorIcon,
76973
76939
  " ",
76974
- inErrorState
76940
+ inErrorState.message
76975
76941
  );
76976
76942
  }
76977
76943
  const viewerContent = parked ? (
@@ -77031,6 +76997,20 @@ function serializePropsSnapshot(seed, props) {
77031
76997
  }
77032
76998
  return JSON.stringify(snapshot);
77033
76999
  }
77000
+ function offsetRangeToPosition(source, range2) {
77001
+ function offsetToPoint(offset) {
77002
+ let line = 1;
77003
+ let lineStart = 0;
77004
+ for (let i2 = 0; i2 < offset; i2++) {
77005
+ if (source[i2] === "\n") {
77006
+ line++;
77007
+ lineStart = i2 + 1;
77008
+ }
77009
+ }
77010
+ return { line, column: offset - lineStart + 1, offset };
77011
+ }
77012
+ return { start: offsetToPoint(range2.begin), end: offsetToPoint(range2.end) };
77013
+ }
77034
77014
  function logComlinkError(component, method) {
77035
77015
  return (err) => {
77036
77016
  console.warn(`iframe ${component}: ${method} failed`, err);
@@ -77133,7 +77113,8 @@ const DoenetEditor = React__default.forwardRef(function DoenetEditor2({
77133
77113
  }
77134
77114
  let standaloneUrl, cssUrl;
77135
77115
  let foundAutoVersion = false;
77136
- let detectedVersion, detectedDoenetMLrange;
77116
+ let detectedVersion;
77117
+ let detectedDoenetMLrange;
77137
77118
  if (autodetectVersion && !ignoreDetectedVersion) {
77138
77119
  let result = detectVersionFromDoenetML(doenetML);
77139
77120
  if (result?.version !== void 0) {
@@ -77308,18 +77289,19 @@ const DoenetEditor = React__default.forwardRef(function DoenetEditor2({
77308
77289
  code: "doenet-e0006",
77309
77290
  args: {
77310
77291
  version: String(detectedVersion),
77311
- fallback: specifiedStandaloneUrl ? "none" : String(
77292
+ fallback: specifiedStandaloneUrl ? "none" : versionLabel(
77312
77293
  specifiedDoenetmlVersion ?? latestDoenetmlVersion
77313
77294
  )
77314
77295
  }
77315
77296
  });
77316
- let allNewlines = findAllNewlines(doenetML);
77317
- Object.assign(
77318
- detectedDoenetMLrange,
77319
- getLineCharRange(detectedDoenetMLrange, allNewlines)
77320
- );
77321
77297
  setInitialDiagnostics([
77322
- { ...versionDiagnostic, position: detectedDoenetMLrange }
77298
+ {
77299
+ ...versionDiagnostic,
77300
+ position: offsetRangeToPosition(
77301
+ doenetML,
77302
+ detectedDoenetMLrange
77303
+ )
77304
+ }
77323
77305
  ]);
77324
77306
  return null;
77325
77307
  }