eat-js-sdk 2.3.3 → 2.3.4
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/interaction-builder.mjs +53 -0
- package/package.json +1 -1
|
@@ -5412,11 +5412,42 @@ const interactionUtils = {
|
|
|
5412
5412
|
return "standard";
|
|
5413
5413
|
}
|
|
5414
5414
|
};
|
|
5415
|
+
const EAT_EQ_OPEN = "[eat-eq]";
|
|
5416
|
+
const EAT_EQ_BLOCK_RE = /\[eat-eq\]([\s\S]*?)\[\/eat-eq\]/g;
|
|
5417
|
+
function hasMathJax(html2) {
|
|
5418
|
+
return html2.includes(EAT_EQ_OPEN) || html2.includes("\\(") || html2.includes("\\[");
|
|
5419
|
+
}
|
|
5420
|
+
const ALREADY_DELIMITED_RE = /^(\\[(]|\\[[]|\$\$|\$[^$])/;
|
|
5421
|
+
function processMathJax(html2) {
|
|
5422
|
+
if (!html2.includes(EAT_EQ_OPEN)) return html2;
|
|
5423
|
+
return html2.replace(EAT_EQ_BLOCK_RE, (_match, mathContent) => {
|
|
5424
|
+
const trimmed = mathContent.trim();
|
|
5425
|
+
if (ALREADY_DELIMITED_RE.test(trimmed)) return trimmed;
|
|
5426
|
+
return `\\(${trimmed}\\)`;
|
|
5427
|
+
});
|
|
5428
|
+
}
|
|
5429
|
+
async function typesetMathJax(element) {
|
|
5430
|
+
const mathJax = window.MathJax;
|
|
5431
|
+
if (!mathJax) return;
|
|
5432
|
+
if (mathJax.startup?.promise) await mathJax.startup.promise;
|
|
5433
|
+
if (typeof mathJax.typesetPromise === "function") {
|
|
5434
|
+
await mathJax.typesetPromise([element]);
|
|
5435
|
+
} else if (typeof mathJax.typeset === "function") {
|
|
5436
|
+
mathJax.typeset([element]);
|
|
5437
|
+
}
|
|
5438
|
+
}
|
|
5415
5439
|
var root_1$o = /* @__PURE__ */ from_html(`<div><!></div>`);
|
|
5416
5440
|
function CommonStringToHtml($$anchor, $$props) {
|
|
5417
5441
|
push($$props, true);
|
|
5418
5442
|
let htmlString = prop($$props, "htmlString", 7, ""), otherClass = prop($$props, "otherClass", 7, ""), ariaHidden = prop($$props, "ariaHidden", 7, false), htmlHeading = prop($$props, "htmlHeading", 7, ""), dataTestId = prop($$props, "dataTestId", 7);
|
|
5443
|
+
let hasMath = /* @__PURE__ */ user_derived(() => hasMathJax(htmlString() ?? ""));
|
|
5419
5444
|
let processedHtml = /* @__PURE__ */ user_derived(() => processHtmlString(htmlString(), htmlHeading()));
|
|
5445
|
+
let containerEl = /* @__PURE__ */ state(void 0);
|
|
5446
|
+
user_effect(() => {
|
|
5447
|
+
if (get$1(hasMath) && get$1(containerEl)) {
|
|
5448
|
+
typesetMathJax(get$1(containerEl));
|
|
5449
|
+
}
|
|
5450
|
+
});
|
|
5420
5451
|
function processHtmlString(html2, heading) {
|
|
5421
5452
|
if (html2 == null) return "";
|
|
5422
5453
|
if (typeof html2 !== "string") {
|
|
@@ -5428,6 +5459,9 @@ function CommonStringToHtml($$anchor, $$props) {
|
|
|
5428
5459
|
}
|
|
5429
5460
|
if (!html2) return "";
|
|
5430
5461
|
let cleaned = html2.replace(/<p><\/p>/g, "");
|
|
5462
|
+
if (hasMathJax(cleaned)) {
|
|
5463
|
+
cleaned = processMathJax(cleaned);
|
|
5464
|
+
}
|
|
5431
5465
|
if (heading) {
|
|
5432
5466
|
cleaned = `<${heading}>${cleaned}</${heading}>`;
|
|
5433
5467
|
}
|
|
@@ -5478,6 +5512,7 @@ function CommonStringToHtml($$anchor, $$props) {
|
|
|
5478
5512
|
var node_1 = child(div);
|
|
5479
5513
|
html(node_1, () => get$1(processedHtml));
|
|
5480
5514
|
reset(div);
|
|
5515
|
+
bind_this(div, ($$value) => set(containerEl, $$value), () => get$1(containerEl));
|
|
5481
5516
|
template_effect(() => {
|
|
5482
5517
|
set_class(div, 1, clsx(otherClass()));
|
|
5483
5518
|
set_attribute(div, "aria-hidden", ariaHidden());
|
|
@@ -20820,6 +20855,24 @@ function InteractionBuilder($$anchor, $$props) {
|
|
|
20820
20855
|
let mode = /* @__PURE__ */ user_derived(() => interactiveMode() === true ? MODES.INTERACTIVE : previewMode() === true ? MODES.PREVIEW : MODES.SESSION);
|
|
20821
20856
|
let skipUserValidationStr = /* @__PURE__ */ user_derived(() => get(skipUserValidation) ? "?skip_user_validation=true" : "");
|
|
20822
20857
|
useSetupAPI();
|
|
20858
|
+
user_effect(() => {
|
|
20859
|
+
if (typeof window === "undefined") return;
|
|
20860
|
+
if (window.MathJax) return;
|
|
20861
|
+
if (document.getElementById("MathJax-script")) return;
|
|
20862
|
+
window.MathJax = {
|
|
20863
|
+
loader: { load: ["[tex]/mhchem"] },
|
|
20864
|
+
tex: {
|
|
20865
|
+
packages: { "[+]": ["mhchem"] },
|
|
20866
|
+
inlineMath: [["\\(", "\\)"]],
|
|
20867
|
+
displayMath: [["\\[", "\\]"], ["$$", "$$"]]
|
|
20868
|
+
}
|
|
20869
|
+
};
|
|
20870
|
+
const script = document.createElement("script");
|
|
20871
|
+
script.id = "MathJax-script";
|
|
20872
|
+
script.async = true;
|
|
20873
|
+
script.src = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js";
|
|
20874
|
+
document.head.appendChild(script);
|
|
20875
|
+
});
|
|
20823
20876
|
user_effect(() => {
|
|
20824
20877
|
set(error, null);
|
|
20825
20878
|
set(isLoading, true);
|