@citolab/qti-components 7.20.2 → 7.20.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.
@@ -1567,32 +1567,49 @@ window.CES = {
1567
1567
  CES.load();
1568
1568
  `;
1569
1569
  var ciBootstrap = `
1570
- window.onload = function () {
1570
+ (function() {
1571
+ var blobUrlReceived = null;
1572
+
1573
+ const createIframe = () => {
1574
+ if (!blobUrlReceived || !document.body) return;
1575
+ var n = document.createElement('iframe');
1576
+ n.frameBorder = '0';
1577
+ n.scrolling = 'no';
1578
+ n.src = blobUrlReceived;
1579
+ n.style.width = '100%';
1580
+ n.style.height = '100%';
1581
+ document.body.appendChild(n);
1582
+ };
1583
+
1571
1584
  const handleMessage = (event) => {
1572
1585
  if (event.data.type === 'blobUrl') {
1573
- const blobUrl = event.data.data;
1574
- var n = document.createElement('iframe');
1575
- n.frameBorder = '0';
1576
- n.scrolling = 'no';
1577
- n.src = blobUrl;
1578
- n.style.width = '100%';
1579
- n.style.height = '100%';
1580
- document.body.appendChild(n);
1586
+ blobUrlReceived = event.data.data;
1581
1587
  window.removeEventListener('message', handleMessage);
1588
+ createIframe();
1582
1589
  }
1583
1590
  };
1591
+
1584
1592
  window.addEventListener('message', handleMessage);
1585
- // Request the blob URL from parent
1586
- let w = window.parent;
1587
- while (w) {
1588
- w.postMessage({ type: 'getBlobUrl' }, '*');
1589
- if (w !== w.parent) {
1590
- w = w.parent;
1591
- } else {
1592
- w = null;
1593
+
1594
+ // Wait for document ready before requesting blobUrl
1595
+ const requestBlobUrl = () => {
1596
+ let w = window.parent;
1597
+ while (w) {
1598
+ w.postMessage({ type: 'getBlobUrl' }, '*');
1599
+ if (w !== w.parent) {
1600
+ w = w.parent;
1601
+ } else {
1602
+ w = null;
1603
+ }
1593
1604
  }
1605
+ };
1606
+
1607
+ if (document.readyState === 'loading') {
1608
+ document.addEventListener('DOMContentLoaded', requestBlobUrl);
1609
+ } else {
1610
+ requestBlobUrl();
1594
1611
  }
1595
- };
1612
+ })();
1596
1613
  `;
1597
1614
  var QtiCustomInteraction = class extends Interaction {
1598
1615
  constructor() {
@@ -1673,17 +1690,12 @@ var QtiCustomInteraction = class extends Interaction {
1673
1690
  }
1674
1691
  const cssRef = this.manifest.style[0];
1675
1692
  const baseCandidates = this.getBaseCandidates();
1676
- console.debug("[qti-custom-interaction] manifest url", this._manifestUrl);
1677
- console.debug("[qti-custom-interaction] base candidates", baseCandidates);
1678
- console.debug("[qti-custom-interaction] refs", { cssRef, media: this.manifest.media });
1679
1693
  const cssResolved = await this.resolveResourceWithFallback(cssRef, baseCandidates);
1680
1694
  const cssUrl = cssResolved.url;
1681
1695
  if (cssResolved.baseUrl && !this._resourceBaseUrl) {
1682
1696
  this._resourceBaseUrl = cssResolved.baseUrl;
1683
1697
  }
1684
- console.debug("[qti-custom-interaction] css resolved", cssResolved);
1685
1698
  const usesCES = true;
1686
- console.debug("[qti-custom-interaction] using built-in ciBootstrap (skipping server bootstrap.js)");
1687
1699
  if (usesCES) {
1688
1700
  let indexUrl = "";
1689
1701
  if (this.manifest.media && this.manifest.media.length > 0) {
@@ -1695,19 +1707,17 @@ var QtiCustomInteraction = class extends Interaction {
1695
1707
  if (indexResolved.baseUrl && !this._resourceBaseUrl) {
1696
1708
  this._resourceBaseUrl = indexResolved.baseUrl;
1697
1709
  }
1698
- console.debug("[qti-custom-interaction] index resolved (media)", {
1699
- url: indexResolved.url,
1700
- baseUrl: indexResolved.baseUrl,
1701
- hasText: Boolean(indexResolved.text)
1702
- });
1703
1710
  if (indexResolved.text) {
1704
1711
  let html = indexResolved.text;
1705
- const cesScript = "<script>" + registerCES + "</script>";
1706
- const headIndex = html.indexOf("<head>");
1707
- if (headIndex !== -1) {
1708
- html = html.slice(0, headIndex + 6) + cesScript + html.slice(headIndex + 6);
1709
- } else {
1710
- html = cesScript + html;
1712
+ const alreadyModified = html.includes("postToParentWindows") || html.includes("window.CES");
1713
+ if (!alreadyModified) {
1714
+ const cesScript = "<script>" + registerCES + "</script>";
1715
+ const headIndex = html.indexOf("<head>");
1716
+ if (headIndex !== -1) {
1717
+ html = html.slice(0, headIndex + 6) + cesScript + html.slice(headIndex + 6);
1718
+ } else {
1719
+ html = cesScript + html;
1720
+ }
1711
1721
  }
1712
1722
  const blob = new Blob([html], { type: "text/html" });
1713
1723
  this._contentBlobUrl = URL.createObjectURL(blob);
@@ -1723,19 +1733,17 @@ var QtiCustomInteraction = class extends Interaction {
1723
1733
  if (indexResolved.baseUrl && !this._resourceBaseUrl) {
1724
1734
  this._resourceBaseUrl = indexResolved.baseUrl;
1725
1735
  }
1726
- console.debug("[qti-custom-interaction] index resolved (fallback)", {
1727
- url: indexResolved.url,
1728
- baseUrl: indexResolved.baseUrl,
1729
- hasText: Boolean(indexResolved.text)
1730
- });
1731
1736
  if (indexResolved.text) {
1732
1737
  let html = indexResolved.text;
1733
- const cesScript = "<script>" + registerCES + "</script>";
1734
- const headIndex = html.indexOf("<head>");
1735
- if (headIndex !== -1) {
1736
- html = html.slice(0, headIndex + 6) + cesScript + html.slice(headIndex + 6);
1737
- } else {
1738
- html = cesScript + html;
1738
+ const alreadyModified = html.includes("postToParentWindows") || html.includes("window.CES");
1739
+ if (!alreadyModified) {
1740
+ const cesScript = "<script>" + registerCES + "</script>";
1741
+ const headIndex = html.indexOf("<head>");
1742
+ if (headIndex !== -1) {
1743
+ html = html.slice(0, headIndex + 6) + cesScript + html.slice(headIndex + 6);
1744
+ } else {
1745
+ html = cesScript + html;
1746
+ }
1739
1747
  }
1740
1748
  const blob = new Blob([html], { type: "text/html" });
1741
1749
  this._contentBlobUrl = URL.createObjectURL(blob);
@@ -1746,12 +1754,15 @@ var QtiCustomInteraction = class extends Interaction {
1746
1754
  const indexResponse = await fetch(indexUrl);
1747
1755
  if (indexResponse.ok) {
1748
1756
  let html = await indexResponse.text();
1749
- const cesScript = "<script>" + registerCES + "</script>";
1750
- const headIndex = html.indexOf("<head>");
1751
- if (headIndex !== -1) {
1752
- html = html.slice(0, headIndex + 6) + cesScript + html.slice(headIndex + 6);
1753
- } else {
1754
- html = cesScript + html;
1757
+ const alreadyModified = html.includes("postToParentWindows") || html.includes("window.CES");
1758
+ if (!alreadyModified) {
1759
+ const cesScript = "<script>" + registerCES + "</script>";
1760
+ const headIndex = html.indexOf("<head>");
1761
+ if (headIndex !== -1) {
1762
+ html = html.slice(0, headIndex + 6) + cesScript + html.slice(headIndex + 6);
1763
+ } else {
1764
+ html = cesScript + html;
1765
+ }
1755
1766
  }
1756
1767
  const blob = new Blob([html], { type: "text/html" });
1757
1768
  this._contentBlobUrl = URL.createObjectURL(blob);
@@ -1764,10 +1775,9 @@ var QtiCustomInteraction = class extends Interaction {
1764
1775
  }
1765
1776
  }
1766
1777
  const inlineScript = `<script>${ciBootstrap}</script>`;
1767
- console.debug("[qti-custom-interaction] using ciBootstrap inline script");
1768
1778
  window.addEventListener("message", this.handlePostMessage);
1769
- iframeDoc.open();
1770
- iframeDoc.write(`
1779
+ const htmlContent = `
1780
+ <!DOCTYPE html>
1771
1781
  <html>
1772
1782
  <head>
1773
1783
  ${cssUrl ? `<link href='${cssUrl}' rel="stylesheet" />` : ""}
@@ -1775,8 +1785,8 @@ var QtiCustomInteraction = class extends Interaction {
1775
1785
  </head>
1776
1786
  <body></body>
1777
1787
  </html>
1778
- `);
1779
- iframeDoc.close();
1788
+ `;
1789
+ iframe.srcdoc = htmlContent;
1780
1790
  }
1781
1791
  getIFrames() {
1782
1792
  const iframesInShadowRoot = this.shadowRoot.querySelectorAll("iframe");
@@ -1833,9 +1843,6 @@ var QtiCustomInteraction = class extends Interaction {
1833
1843
  }
1834
1844
  handlePostMessage(event) {
1835
1845
  const { type, data } = event.data;
1836
- if (type && type !== "setResponse") {
1837
- console.debug("[qti-custom-interaction] postMessage", { type, data });
1838
- }
1839
1846
  switch (type) {
1840
1847
  case "setResponse":
1841
1848
  if (data === null || !(Array.isArray(data) && data.length === 1 && data[0] === "")) {
@@ -1850,6 +1857,9 @@ var QtiCustomInteraction = class extends Interaction {
1850
1857
  case "getBlobUrl": {
1851
1858
  if (this._contentBlobUrl) {
1852
1859
  this.postToWindowAndIframes("blobUrl", this._contentBlobUrl);
1860
+ if (event.source && event.source !== window) {
1861
+ event.source.postMessage({ type: "blobUrl", data: this._contentBlobUrl }, "*");
1862
+ }
1853
1863
  }
1854
1864
  break;
1855
1865
  }
@@ -1865,7 +1875,6 @@ var QtiCustomInteraction = class extends Interaction {
1865
1875
  }
1866
1876
  return new URL(media, baseUrl.endsWith("/") ? baseUrl : `${baseUrl}/`).toString();
1867
1877
  });
1868
- console.debug("[qti-custom-interaction] mediaData", mediaData);
1869
1878
  this.postToWindowAndIframes("mediaData", mediaData);
1870
1879
  break;
1871
1880
  }
@@ -7295,4 +7304,4 @@ lit-html/node/directives/ref.js:
7295
7304
  * SPDX-License-Identifier: BSD-3-Clause
7296
7305
  *)
7297
7306
  */
7298
- //# sourceMappingURL=chunk-5R3SZ6YB.js.map
7307
+ //# sourceMappingURL=chunk-VEPXXFFW.js.map