@pie-qti/player-elements 0.1.17 → 0.1.19

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.
@@ -1,5 +1,5 @@
1
1
  import { a as e, n as t, o as n, r, t as i } from "./chunk-foFoljWS.js";
2
- import { F as a, a as o, c as s, i as c, n as l, r as u, t as d } from "./element-class-BLaOCHDu-CqAiNXSq.js";
2
+ import { F as a, a as o, c as s, i as c, n as l, r as u, t as d } from "./element-class-BEpwHdcP-BHKRGZoi.js";
3
3
  //#region src/constants.ts
4
4
  var f = "pie-qti-item-player", p = "pie-qti-assessment-player", ee = "pie-qti-section-player-splitpane", te = "pie-qti-section-player-vertical";
5
5
  //#endregion
@@ -6627,7 +6627,20 @@ function zl(e) {
6627
6627
  });
6628
6628
  return r || !n || /url\(/i.test(i);
6629
6629
  }
6630
- function Bl(e, t, n, r) {
6630
+ function Bl(e) {
6631
+ let t = e.parentNode;
6632
+ for (; t;) {
6633
+ if (t.rawTagName?.toLowerCase() === "svg") return !0;
6634
+ t = t.parentNode;
6635
+ }
6636
+ return !1;
6637
+ }
6638
+ function Vl(e, t, n, r) {
6639
+ let i = [...e.childNodes];
6640
+ for (let e of i) e.rawTagName && Hl(e, t, n, r + 1);
6641
+ e.replaceWith(...e.childNodes);
6642
+ }
6643
+ function Hl(e, t, n, r) {
6631
6644
  if (n.enabled) {
6632
6645
  if (r > n.maxDepth) throw new Tl(`HTML depth exceeds maxHtmlDepth (${r} > ${n.maxDepth})`);
6633
6646
  if (n.nodes++, n.nodes > n.maxNodes) throw new Tl(`HTML node count exceeds maxHtmlNodes (${n.nodes} > ${n.maxNodes})`);
@@ -6638,7 +6651,11 @@ function Bl(e, t, n, r) {
6638
6651
  return;
6639
6652
  }
6640
6653
  if (i && Rl.has(i)) {
6641
- e.remove();
6654
+ if (Bl(e)) {
6655
+ e.remove();
6656
+ return;
6657
+ }
6658
+ Vl(e, t, n, r);
6642
6659
  return;
6643
6660
  }
6644
6661
  if (i === "iframe" && !Ol(t)) {
@@ -6646,7 +6663,7 @@ function Bl(e, t, n, r) {
6646
6663
  return;
6647
6664
  }
6648
6665
  if ((i === "object" || i === "embed") && !Dl(t)) {
6649
- let n = Ul(e, t);
6666
+ let n = Gl(e, t);
6650
6667
  if (n) {
6651
6668
  e.replaceWith(n);
6652
6669
  return;
@@ -6659,9 +6676,7 @@ function Bl(e, t, n, r) {
6659
6676
  return;
6660
6677
  }
6661
6678
  if (i?.includes("-") && !Il(i)) {
6662
- let i = [...e.childNodes];
6663
- for (let e of i) e.rawTagName && Bl(e, t, n, r + 1);
6664
- e.replaceWith(...e.childNodes);
6679
+ Vl(e, t, n, r);
6665
6680
  return;
6666
6681
  }
6667
6682
  let a = e.attributes || {};
@@ -6706,9 +6721,9 @@ function Bl(e, t, n, r) {
6706
6721
  }
6707
6722
  }
6708
6723
  let o = e.childNodes.filter((e) => e.rawTagName);
6709
- for (let e of o) Bl(e, t, n, r + 1);
6724
+ for (let e of o) Hl(e, t, n, r + 1);
6710
6725
  }
6711
- function Vl(e, t) {
6726
+ function Ul(e, t) {
6712
6727
  if (!e || typeof e != "string") return "";
6713
6728
  try {
6714
6729
  let n = pl(t?.security);
@@ -6722,16 +6737,16 @@ function Vl(e, t) {
6722
6737
  maxNodes: n.maxHtmlNodes,
6723
6738
  maxDepth: n.maxHtmlDepth
6724
6739
  };
6725
- for (let e of i) Bl(e, t, a, 1);
6740
+ for (let e of i) Hl(e, t, a, 1);
6726
6741
  return r.toString();
6727
6742
  } catch (e) {
6728
6743
  return e instanceof Tl || console.error("HTML sanitization failed:", e), "";
6729
6744
  }
6730
6745
  }
6731
- function Hl(e, t) {
6732
- return !e || typeof e != "string" ? "" : /<[^>]+>/.test(e) ? Vl(e, t) : e;
6746
+ function Wl(e, t) {
6747
+ return !e || typeof e != "string" ? "" : /<[^>]+>/.test(e) ? Ul(e, t) : e;
6733
6748
  }
6734
- function Ul(e, t) {
6749
+ function Gl(e, t) {
6735
6750
  if (e.rawTagName?.toLowerCase() !== "object") return null;
6736
6751
  let n = e.getAttribute("type")?.trim().toLowerCase() ?? "", r = e.getAttribute("data")?.trim() ?? "";
6737
6752
  if (!n || !r) return null;
@@ -6756,26 +6771,26 @@ function Ul(e, t) {
6756
6771
  }
6757
6772
  //#endregion
6758
6773
  //#region ../item-player/dist/core/trustedTypes.js
6759
- function Wl() {
6774
+ function Kl() {
6760
6775
  return globalThis.trustedTypes;
6761
6776
  }
6762
- var Gl = /* @__PURE__ */ new Map();
6763
- function Kl(e) {
6764
- let t = Gl.get(e);
6777
+ var ql = /* @__PURE__ */ new Map();
6778
+ function Jl(e) {
6779
+ let t = ql.get(e);
6765
6780
  if (t) return t;
6766
- let n = Wl();
6781
+ let n = Kl();
6767
6782
  if (!n?.createPolicy) return null;
6768
6783
  try {
6769
6784
  let t = n.createPolicy(e, { createHTML: (e) => e });
6770
- return t?.createHTML ? (Gl.set(e, t), t) : null;
6785
+ return t?.createHTML ? (ql.set(e, t), t) : null;
6771
6786
  } catch {
6772
6787
  return null;
6773
6788
  }
6774
6789
  }
6775
- function ql(e, t) {
6790
+ function Yl(e, t) {
6776
6791
  if (!t) return e;
6777
6792
  if (!e) return "";
6778
- let n = Kl(t);
6793
+ let n = Jl(t);
6779
6794
  if (!n) return e;
6780
6795
  try {
6781
6796
  return n.createHTML(e);
@@ -6783,35 +6798,35 @@ function ql(e, t) {
6783
6798
  return e;
6784
6799
  }
6785
6800
  }
6786
- function Jl(e) {
6801
+ function Xl(e) {
6787
6802
  return typeof e == "string" ? e : String(e);
6788
6803
  }
6789
6804
  //#endregion
6790
6805
  //#region ../item-player/dist/extraction/interactionSecurity.js
6791
- function Yl(e, t) {
6806
+ function Zl(e, t) {
6792
6807
  let n = t?.urlPolicy, r = t?.allowObjectEmbeds === !0, i = t?.trustedTypesPolicyName;
6793
6808
  for (let t of e) {
6794
- if (t.type === "choiceInteraction" && Array.isArray(t.choices)) for (let e of t.choices) typeof e?.text == "string" && (e.text = ql(e.text, i));
6795
- if (t.imageData?.src && (t.imageData.src = xl(t.imageData.src, n, "img") ?? ""), t.imageData?.content && typeof t.imageData.content == "string" && (t.imageData.content = ql(t.imageData.content, i)), Array.isArray(t.positionObjectStages)) for (let e of t.positionObjectStages) e?.objectData?.src && (e.objectData.src = xl(e.objectData.src, n, "img") ?? ""), e?.objectData?.content && typeof e.objectData.content == "string" && (e.objectData.content = ql(e.objectData.content, i));
6809
+ if (t.type === "choiceInteraction" && Array.isArray(t.choices)) for (let e of t.choices) typeof e?.text == "string" && (e.text = Yl(e.text, i));
6810
+ if (t.imageData?.src && (t.imageData.src = xl(t.imageData.src, n, "img") ?? ""), t.imageData?.content && typeof t.imageData.content == "string" && (t.imageData.content = Yl(t.imageData.content, i)), Array.isArray(t.positionObjectStages)) for (let e of t.positionObjectStages) e?.objectData?.src && (e.objectData.src = xl(e.objectData.src, n, "img") ?? ""), e?.objectData?.content && typeof e.objectData.content == "string" && (e.objectData.content = Yl(e.objectData.content, i));
6796
6811
  if (t.type === "mediaInteraction" && t.mediaElement?.src) {
6797
6812
  let e = t.mediaElement.type === "object" ? "object" : "media";
6798
6813
  t.mediaElement.src = xl(t.mediaElement.src, n, e) ?? "", t.allowObjectEmbeds = r;
6799
6814
  }
6800
- t.type === "hottextInteraction" && typeof t.contentHtml == "string" && (t.contentHtml = ql(t.contentHtml, i));
6815
+ t.type === "hottextInteraction" && typeof t.contentHtml == "string" && (t.contentHtml = Yl(t.contentHtml, i));
6801
6816
  }
6802
6817
  return e;
6803
6818
  }
6804
6819
  //#endregion
6805
6820
  //#region ../item-player/dist/security/index.js
6806
- function Xl(e, t, n) {
6807
- return ql(Vl(e, {
6821
+ function Ql(e, t, n) {
6822
+ return Yl(Ul(e, {
6808
6823
  security: t,
6809
6824
  sanitizeUrl: n?.sanitizeUrl
6810
6825
  }), t?.trustedTypesPolicyName);
6811
6826
  }
6812
6827
  //#endregion
6813
6828
  //#region src/qti/resolveItems.ts
6814
- var Zl = {
6829
+ var $l = {
6815
6830
  maxItems: 500,
6816
6831
  maxItemBytes: 1e7,
6817
6832
  maxTotalBytes: 1e8,
@@ -6819,18 +6834,18 @@ var Zl = {
6819
6834
  timeoutMs: 15e3,
6820
6835
  allowOutsideBase: !1
6821
6836
  };
6822
- function Ql(e) {
6837
+ function eu(e) {
6823
6838
  if (!e) return [];
6824
6839
  let t = [];
6825
- for (let n of e) n.assessmentItemRefs && t.push(...n.assessmentItemRefs), n.sections && t.push(...Ql(n.sections));
6840
+ for (let n of e) n.assessmentItemRefs && t.push(...n.assessmentItemRefs), n.sections && t.push(...eu(n.sections));
6826
6841
  return t;
6827
6842
  }
6828
- function $l(e) {
6843
+ function tu(e) {
6829
6844
  let t = e.testParts ?? [], n = [];
6830
- for (let e of t) n.push(...Ql(e.sections));
6845
+ for (let e of t) n.push(...eu(e.sections));
6831
6846
  return n;
6832
6847
  }
6833
- function eu(e, t, n, r) {
6848
+ function nu(e, t, n, r) {
6834
6849
  let i = e.testParts ?? [];
6835
6850
  for (let e of i) {
6836
6851
  let i = [...e.sections ?? []];
@@ -6841,7 +6856,7 @@ function eu(e, t, n, r) {
6841
6856
  }
6842
6857
  }
6843
6858
  }
6844
- function tu(e) {
6859
+ function ru(e) {
6845
6860
  try {
6846
6861
  let t = globalThis.location?.href ?? "http://localhost/";
6847
6862
  return new URL(e, t).toString();
@@ -6849,12 +6864,12 @@ function tu(e) {
6849
6864
  throw Error(`Invalid QTI item base URL: ${e}`);
6850
6865
  }
6851
6866
  }
6852
- function nu(e, t) {
6867
+ function iu(e, t) {
6853
6868
  if (e.origin !== t.origin) return !1;
6854
6869
  let n = t.pathname.endsWith("/") ? t.pathname : `${t.pathname}/`;
6855
6870
  return e.pathname === t.pathname || e.pathname.startsWith(n);
6856
6871
  }
6857
- function ru(e) {
6872
+ function au(e) {
6858
6873
  let t = e;
6859
6874
  for (let e = 0; e < 3; e++) {
6860
6875
  if (/%(?:2e|2f|5c)/i.test(t)) return !0;
@@ -6868,8 +6883,8 @@ function ru(e) {
6868
6883
  }
6869
6884
  return /%(?:2e|2f|5c)/i.test(t);
6870
6885
  }
6871
- function iu(e, t, n, r) {
6872
- if (ru(e)) throw Error(`QTI item URL contains an unsafe encoded path token: ${e}`);
6886
+ function ou(e, t, n, r) {
6887
+ if (au(e)) throw Error(`QTI item URL contains an unsafe encoded path token: ${e}`);
6873
6888
  let i = new URL(t), a = xl(e, {
6874
6889
  ...n?.urlPolicy ?? {},
6875
6890
  assetBaseUrl: t
@@ -6883,19 +6898,19 @@ function iu(e, t, n, r) {
6883
6898
  }
6884
6899
  let s = xl(o.toString(), n?.urlPolicy, "any");
6885
6900
  if (!s) throw Error(`Blocked resolved QTI item URL by security policy: ${o.toString()}`);
6886
- if (o = new URL(s), !r && !nu(o, i)) throw Error(`QTI item URL escapes itemBaseUrl: ${e}`);
6901
+ if (o = new URL(s), !r && !iu(o, i)) throw Error(`QTI item URL escapes itemBaseUrl: ${e}`);
6887
6902
  return o.toString();
6888
6903
  }
6889
- function au(e) {
6904
+ function su(e) {
6890
6905
  return new TextEncoder().encode(e).byteLength;
6891
6906
  }
6892
- async function ou(e, t, n) {
6907
+ async function cu(e, t, n) {
6893
6908
  let r = Number(e.headers.get("content-length"));
6894
6909
  if (Number.isFinite(r) && r > n) throw Error(`QTI item exceeds maxItemBytes: ${t} (${r} > ${n})`);
6895
6910
  let i = e.headers.get("content-type")?.split(";", 1)[0]?.trim().toLowerCase();
6896
6911
  if (i && i !== "application/xml" && i !== "text/xml" && i !== "text/plain" && i !== "text/css" && !i.endsWith("+xml")) throw Error(`Unexpected QTI item content type "${i}" for ${t}`);
6897
6912
  if (!e.body) {
6898
- let r = await e.text(), i = au(r);
6913
+ let r = await e.text(), i = su(r);
6899
6914
  if (i > n) throw Error(`QTI item exceeds maxItemBytes: ${t} (${i} > ${n})`);
6900
6915
  return r;
6901
6916
  }
@@ -6914,7 +6929,7 @@ async function ou(e, t, n) {
6914
6929
  for (let e of o) c.set(e, l), l += e.byteLength;
6915
6930
  return new TextDecoder().decode(c);
6916
6931
  }
6917
- async function su(e, t, n, r) {
6932
+ async function lu(e, t, n, r) {
6918
6933
  if (r?.aborted) throw Error(`Cancelled QTI resource request: ${e}`);
6919
6934
  let i = new AbortController(), a = () => i.abort(r?.reason);
6920
6935
  r?.addEventListener("abort", a, { once: !0 });
@@ -6926,21 +6941,21 @@ async function su(e, t, n, r) {
6926
6941
  redirect: "error"
6927
6942
  });
6928
6943
  if (!r.ok) throw Error(`Failed to fetch QTI item: ${e} (${r.status})`);
6929
- return await ou(r, e, n.maxItemBytes);
6944
+ return await cu(r, e, n.maxItemBytes);
6930
6945
  } catch (t) {
6931
6946
  throw r?.aborted ? Error(`Cancelled QTI resource request: ${e}`) : i.signal.aborted ? Error(`Timed out fetching QTI item after ${n.timeoutMs}ms: ${e}`) : t;
6932
6947
  } finally {
6933
6948
  globalThis.clearTimeout(o), r?.removeEventListener("abort", a);
6934
6949
  }
6935
6950
  }
6936
- function cu(e = {}) {
6951
+ function uu(e = {}) {
6937
6952
  let t = {
6938
- maxItems: e.maxItems ?? Zl.maxItems,
6939
- maxItemBytes: e.maxItemBytes ?? Zl.maxItemBytes,
6940
- maxTotalBytes: e.maxTotalBytes ?? Zl.maxTotalBytes,
6941
- concurrency: e.concurrency ?? Zl.concurrency,
6942
- timeoutMs: e.timeoutMs ?? Zl.timeoutMs,
6943
- allowOutsideBase: e.allowOutsideBase ?? Zl.allowOutsideBase
6953
+ maxItems: e.maxItems ?? $l.maxItems,
6954
+ maxItemBytes: e.maxItemBytes ?? $l.maxItemBytes,
6955
+ maxTotalBytes: e.maxTotalBytes ?? $l.maxTotalBytes,
6956
+ concurrency: e.concurrency ?? $l.concurrency,
6957
+ timeoutMs: e.timeoutMs ?? $l.timeoutMs,
6958
+ allowOutsideBase: e.allowOutsideBase ?? $l.allowOutsideBase
6944
6959
  };
6945
6960
  if (!Number.isInteger(t.maxItems) || t.maxItems < 0) throw Error("fetchPolicy.maxItems must be a non-negative integer");
6946
6961
  if (!Number.isInteger(t.maxItemBytes) || t.maxItemBytes < 1) throw Error("fetchPolicy.maxItemBytes must be a positive integer");
@@ -6949,8 +6964,8 @@ function cu(e = {}) {
6949
6964
  if (!Number.isFinite(t.timeoutMs) || t.timeoutMs < 1) throw Error("fetchPolicy.timeoutMs must be positive");
6950
6965
  return t;
6951
6966
  }
6952
- function lu(e) {
6953
- let t = cu(e.fetchPolicy), n = e.itemBaseUrl ? tu(e.itemBaseUrl) : void 0, r = e.fetch ?? globalThis.fetch, i = /* @__PURE__ */ new Map(), a = 0, o = 0, s = 0, c = [], l = async (e) => {
6967
+ function du(e) {
6968
+ let t = uu(e.fetchPolicy), n = e.itemBaseUrl ? ru(e.itemBaseUrl) : void 0, r = e.fetch ?? globalThis.fetch, i = /* @__PURE__ */ new Map(), a = 0, o = 0, s = 0, c = [], l = async (e) => {
6954
6969
  s >= t.concurrency && await new Promise((e) => c.push(e)), s++;
6955
6970
  try {
6956
6971
  return await e();
@@ -6958,14 +6973,14 @@ function lu(e) {
6958
6973
  s--, c.shift()?.();
6959
6974
  }
6960
6975
  }, u = (e, n) => {
6961
- let r = au(n);
6976
+ let r = su(n);
6962
6977
  if (r > t.maxItemBytes) throw Error(`QTI resource exceeds maxItemBytes: ${e} (${r} > ${t.maxItemBytes})`);
6963
6978
  if (o + r > t.maxTotalBytes) throw Error(`Assessment resources exceed maxTotalBytes (${o + r} > ${t.maxTotalBytes})`);
6964
6979
  return o += r, n;
6965
6980
  };
6966
6981
  return async (o) => {
6967
6982
  if (e.signal?.aborted) throw Error(`Cancelled QTI resource request: ${o}`);
6968
- let s = e.items?.[o], c = n ? iu(o, n, e.security, t.allowOutsideBase) : void 0, d = c ?? `supplied:${o}`, f = i.get(d);
6983
+ let s = e.items?.[o], c = n ? ou(o, n, e.security, t.allowOutsideBase) : void 0, d = c ?? `supplied:${o}`, f = i.get(d);
6969
6984
  if (f) return f;
6970
6985
  if (a >= t.maxItems) throw Error(`Assessment references too many distinct QTI resources (limit ${t.maxItems})`);
6971
6986
  if (a++, s !== void 0) {
@@ -6979,7 +6994,7 @@ function lu(e) {
6979
6994
  }
6980
6995
  if (!n || !c) throw Error(`No itemBaseUrl or supplied resource for QTI href: ${o}`);
6981
6996
  if (typeof r != "function") throw Error("No fetch implementation is available to resolve QTI resources");
6982
- let p = l(async () => u(d, await su(c, r, t, e.signal)));
6997
+ let p = l(async () => u(d, await lu(c, r, t, e.signal)));
6983
6998
  i.set(d, p);
6984
6999
  try {
6985
7000
  return await p;
@@ -6988,7 +7003,7 @@ function lu(e) {
6988
7003
  }
6989
7004
  };
6990
7005
  }
6991
- async function uu(e, t) {
7006
+ async function fu(e, t) {
6992
7007
  let n = 0, r = Array.from({ length: Math.min(t, e.length) }, async () => {
6993
7008
  for (; n < e.length;) {
6994
7009
  let t = e[n++];
@@ -6997,12 +7012,12 @@ async function uu(e, t) {
6997
7012
  });
6998
7013
  await Promise.all(r);
6999
7014
  }
7000
- async function du(e) {
7001
- let { assessment: t, items: n } = e, r = cu(e.fetchPolicy), i = $l(t), a = n ? { ...n } : void 0;
7015
+ async function pu(e) {
7016
+ let { assessment: t, items: n } = e, r = uu(e.fetchPolicy), i = tu(t), a = n ? { ...n } : void 0;
7002
7017
  for (let e of i) a && e.href && a[e.href] === void 0 && a[e.identifier] !== void 0 && (a[e.href] = a[e.identifier]);
7003
7018
  let o = i.filter((e) => !e.itemXml && !(a && (a[e.href ?? ""] ?? a[e.identifier])));
7004
7019
  if (o.length > r.maxItems) throw Error(`Assessment references too many remote QTI items (${o.length} > ${r.maxItems})`);
7005
- let s = e.resourceResolver ?? lu({
7020
+ let s = e.resourceResolver ?? du({
7006
7021
  itemBaseUrl: e.itemBaseUrl,
7007
7022
  items: a,
7008
7023
  security: e.security,
@@ -7010,21 +7025,21 @@ async function du(e) {
7010
7025
  fetch: e.fetch,
7011
7026
  signal: e.signal
7012
7027
  });
7013
- return await uu(i.map((e) => async () => {
7028
+ return await fu(i.map((e) => async () => {
7014
7029
  if (e.itemXml) return;
7015
7030
  if (e.href) {
7016
7031
  let n = await s(e.href);
7017
- eu(t, e.identifier, e.href, n);
7032
+ nu(t, e.identifier, e.href, n);
7018
7033
  return;
7019
7034
  }
7020
7035
  let i = n?.[e.identifier];
7021
7036
  if (i !== void 0) {
7022
- if (au(i) > r.maxItemBytes) throw Error(`QTI resource exceeds maxItemBytes: ${e.identifier}`);
7037
+ if (su(i) > r.maxItemBytes) throw Error(`QTI resource exceeds maxItemBytes: ${e.identifier}`);
7023
7038
  e.itemXml = i;
7024
7039
  }
7025
7040
  }), r.concurrency), t;
7026
7041
  }
7027
7042
  //#endregion
7028
- export { Jl as a, Hl as c, ul as d, m as f, te as g, ee as h, Yl as i, xl as l, f as m, du as n, ql as o, p, Xl as r, Vl as s, lu as t, ml as u };
7043
+ export { Xl as a, Wl as c, ul as d, m as f, te as g, ee as h, Zl as i, xl as l, f as m, pu as n, Yl as o, p, Ql as r, Ul as s, du as t, ml as u };
7029
7044
 
7030
- //# sourceMappingURL=resolveItems-I0_HsCib.js.map
7045
+ //# sourceMappingURL=resolveItems-CLMM7L3B.js.map