@pie-element/passage 7.1.2-next.3 → 7.1.2-next.30
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/author.js +2 -0
- package/dist/author/common.js +6 -5
- package/dist/author/design.js +2 -2
- package/dist/author/index.js +2 -2
- package/dist/author/passage.js +1 -1
- package/dist/browser/assets/Symbola-4c507403.woff2 +0 -0
- package/dist/browser/author/index.js +24624 -35152
- package/dist/browser/author/index.js.map +1 -1
- package/dist/browser/controller/index.js +1 -1
- package/dist/browser/controller/index.js.map +1 -1
- package/dist/browser/delivery/index.js +3 -3
- package/dist/browser/delivery/index.js.map +1 -1
- package/dist/browser/{dist-BC24ne2o.js → dist-CiWlBjsz.js} +6 -2
- package/dist/browser/dist-CiWlBjsz.js.map +1 -0
- package/dist/browser/{dist-ByX3voUB.js → dist-DM6OmxJY.js} +2844 -2764
- package/dist/browser/dist-DM6OmxJY.js.map +1 -0
- package/dist/browser/editor-runtime/assets/Symbola-4c507403.woff2 +0 -0
- package/dist/browser/editor-runtime/author/index.js +17751 -0
- package/dist/browser/editor-runtime/author/index.js.map +1 -0
- package/dist/browser/editor-runtime/controller/index.js +64 -0
- package/dist/browser/editor-runtime/controller/index.js.map +1 -0
- package/dist/browser/editor-runtime/delivery/index.js +117 -0
- package/dist/browser/editor-runtime/delivery/index.js.map +1 -0
- package/dist/browser/editor-runtime/dist-BefbTFbR.js +9698 -0
- package/dist/browser/editor-runtime/dist-BefbTFbR.js.map +1 -0
- package/dist/browser/editor-runtime/dist-CiWlBjsz.js +92 -0
- package/dist/browser/editor-runtime/dist-CiWlBjsz.js.map +1 -0
- package/dist/browser/editor-runtime/print/index.js +51 -0
- package/dist/browser/editor-runtime/print/index.js.map +1 -0
- package/dist/browser/editor-runtime/rolldown-runtime-CHQKHQ89.js +32 -0
- package/dist/browser/{stimulus-tabs-CxiQ79gz.js → editor-runtime/stimulus-tabs-BQw9OIkn.js} +81 -43
- package/dist/browser/editor-runtime/stimulus-tabs-BQw9OIkn.js.map +1 -0
- package/dist/browser/print/index.js +8 -5
- package/dist/browser/print/index.js.map +1 -1
- package/dist/browser/rolldown-runtime-CWhphoD1.js +32 -0
- package/dist/browser/stimulus-tabs-BMKDR3ku.js +256 -0
- package/dist/browser/stimulus-tabs-BMKDR3ku.js.map +1 -0
- package/dist/delivery/index.js +1 -1
- package/dist/delivery/stimulus-tabs.d.ts +7 -0
- package/dist/delivery/stimulus-tabs.js +69 -32
- package/dist/index.iife.js +30 -30
- package/dist/print/index.js +4 -2
- package/module/print.js +15912 -0
- package/module/print.js.map +1 -0
- package/package.json +41 -24
- package/print.js +2 -0
- package/dist/browser/dist-BC24ne2o.js.map +0 -1
- package/dist/browser/dist-ByX3voUB.js.map +0 -1
- package/dist/browser/passage.css +0 -2
- package/dist/browser/stimulus-tabs-CxiQ79gz.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { i as e } from "../dist-CiWlBjsz.js";
|
|
2
|
+
//#region src/controller/defaults.ts
|
|
3
|
+
var t = {
|
|
4
|
+
authorEnabled: !1,
|
|
5
|
+
passages: [{
|
|
6
|
+
teacherInstructions: "",
|
|
7
|
+
title: "",
|
|
8
|
+
subtitle: "",
|
|
9
|
+
author: "",
|
|
10
|
+
text: ""
|
|
11
|
+
}],
|
|
12
|
+
subtitleEnabled: !0,
|
|
13
|
+
teacherInstructionsEnabled: !0,
|
|
14
|
+
textEnabled: !0,
|
|
15
|
+
titleEnabled: !0
|
|
16
|
+
}, n = (e) => (e || "").replace(/(<(?!img|iframe|source)([^>]+)>)/gi, ""), r = (e) => e != null, i = (e, t) => r(e) ? e : t;
|
|
17
|
+
function a(e = {}) {
|
|
18
|
+
return new Promise((n) => {
|
|
19
|
+
n({
|
|
20
|
+
...t,
|
|
21
|
+
...e
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
var o = (e) => ({
|
|
26
|
+
...t,
|
|
27
|
+
...e
|
|
28
|
+
}), s = (e, t) => {
|
|
29
|
+
let { role: n, mode: r } = t;
|
|
30
|
+
return n === "instructor" && (r === "view" || r === "evaluate") && e || "";
|
|
31
|
+
};
|
|
32
|
+
async function c(e, t, r) {
|
|
33
|
+
let a = o(e), c = a.passages.map((e, t) => ({
|
|
34
|
+
teacherInstructions: i(e.teacherInstructionsEnabled, a.teacherInstructionsEnabled) ? s(e.teacherInstructions, r) : "",
|
|
35
|
+
label: n(e.title) ? e.title : `Passage ${t + 1}`,
|
|
36
|
+
title: i(e.titleEnabled, a.titleEnabled) && e.title || "",
|
|
37
|
+
subtitle: i(e.subtitleEnabled, a.subtitleEnabled) && e.subtitle || "",
|
|
38
|
+
author: i(e.authorEnabled, a.authorEnabled) && e.author || "",
|
|
39
|
+
text: i(e.textEnabled, a.textEnabled) && e.text || ""
|
|
40
|
+
}));
|
|
41
|
+
return {
|
|
42
|
+
...a,
|
|
43
|
+
passages: c
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
var l = (t = {}, r = {}) => {
|
|
47
|
+
let i = {}, a = {};
|
|
48
|
+
return (t.passages || []).forEach((t, i) => {
|
|
49
|
+
let o = {};
|
|
50
|
+
[
|
|
51
|
+
"teacherInstructions",
|
|
52
|
+
"title",
|
|
53
|
+
"subtitle",
|
|
54
|
+
"author",
|
|
55
|
+
"text"
|
|
56
|
+
].forEach((e) => {
|
|
57
|
+
r[e]?.required && !n(t[e]) && (o[e] = "This field is required.");
|
|
58
|
+
}), e(o) || (a[i] = o);
|
|
59
|
+
}), e(a) || (i.passages = a), i;
|
|
60
|
+
};
|
|
61
|
+
//#endregion
|
|
62
|
+
export { a as createDefaultModel, c as model, o as normalize, l as validate };
|
|
63
|
+
|
|
64
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/controller/defaults.ts","../../../../src/controller/index.ts"],"sourcesContent":["// @ts-nocheck\n/**\n * @synced-from pie-elements/packages/passage/controller/src/defaults.js\n * @auto-generated\n *\n * This file is automatically synced from pie-elements and converted to TypeScript.\n * Manual edits will be overwritten on next sync.\n * To make changes, edit the upstream JavaScript file and run sync again.\n */\n\n// TODO: also update '../../configure/src/defaults.js' and '../../src/print.js' when updating defaults\nexport default {\n authorEnabled: false, // TODO: should be set to true when all Studio content is updated\n passages: [\n {\n teacherInstructions: '',\n title: '',\n subtitle: '',\n author: '',\n text: '',\n },\n ],\n subtitleEnabled: true,\n teacherInstructionsEnabled: true,\n textEnabled: true,\n titleEnabled: true,\n};\n","// @ts-nocheck\n/**\n * @synced-from pie-elements/packages/passage/controller/src/index.js\n * @auto-generated\n *\n * This file is automatically synced from pie-elements and converted to TypeScript.\n * Manual edits will be overwritten on next sync.\n * To make changes, edit the upstream JavaScript file and run sync again.\n */\n\nimport { isEmpty } from '@pie-element/shared-lodash';\n\nimport defaults from './defaults.js';\n\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nconst checkNullish = (value) => value !== null && value !== undefined;\n\nconst isEnabled = (value, defaultValue) => (checkNullish(value) ? value : defaultValue);\n\nexport function createDefaultModel(model = {}) {\n return new Promise((resolve) => {\n resolve({ ...defaults, ...model });\n });\n}\n\nexport const normalize = (question) => ({ ...defaults, ...question });\n\nconst normalizeTeacherInstructions = (instructions, env) => {\n const { role, mode } = env;\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n return instructions || '';\n }\n\n return '';\n};\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n */\nexport async function model(question, session, env) {\n const normalizedQuestion = normalize(question);\n\n const normalizedPassages = normalizedQuestion.passages.map((passage, index) => ({\n teacherInstructions: isEnabled(passage.teacherInstructionsEnabled, normalizedQuestion.teacherInstructionsEnabled)\n ? normalizeTeacherInstructions(passage.teacherInstructions, env)\n : '',\n label: getContent(passage.title) ? passage.title : `Passage ${index + 1}`,\n title: isEnabled(passage.titleEnabled, normalizedQuestion.titleEnabled) ? passage.title || '' : '',\n subtitle: isEnabled(passage.subtitleEnabled, normalizedQuestion.subtitleEnabled) ? passage.subtitle || '' : '',\n author: isEnabled(passage.authorEnabled, normalizedQuestion.authorEnabled) ? passage.author || '' : '',\n text: isEnabled(passage.textEnabled, normalizedQuestion.textEnabled) ? passage.text || '' : '',\n }));\n\n return {\n ...normalizedQuestion,\n passages: normalizedPassages,\n };\n}\n\nexport const validate = (model = {}, config = {}) => {\n const errors = {};\n const passagesErrors = {};\n\n (model.passages || []).forEach((passage, index) => {\n const err = {};\n\n ['teacherInstructions', 'title', 'subtitle', 'author', 'text'].forEach((field) => {\n if (config[field]?.required && !getContent(passage[field])) {\n err[field] = 'This field is required.';\n }\n });\n\n if (!isEmpty(err)) {\n passagesErrors[index] = err;\n }\n });\n\n if (!isEmpty(passagesErrors)) {\n errors.passages = passagesErrors;\n }\n\n return errors;\n};\n"],"mappings":";;AAWA,IAAA,IAAe;CACb,eAAe;CACf,UAAU,CACR;EACE,qBAAqB;EACrB,OAAO;EACP,UAAU;EACV,QAAQ;EACR,MAAM;CACR,CACF;CACA,iBAAiB;CACjB,4BAA4B;CAC5B,aAAa;CACb,cAAc;AAChB,GCZM,KAAc,OAAU,KAAQ,GAAA,CAAI,QAAQ,sCAAsC,EAAE,GAEpF,KAAgB,MAAU,KAAU,MAEpC,KAAa,GAAO,MAAkB,EAAa,CAAK,IAAI,IAAQ;AAE1E,SAAgB,EAAmB,IAAQ,CAAC,GAAG;CAC7C,OAAO,IAAI,SAAS,MAAY;EAC9B,EAAQ;GAAE,GAAG;GAAU,GAAG;EAAM,CAAC;CACnC,CAAC;AACH;AAEA,IAAa,KAAa,OAAc;CAAE,GAAG;CAAU,GAAG;AAAS,IAE7D,KAAgC,GAAc,MAAQ;CAC1D,IAAM,EAAE,SAAM,YAAS;CAMvB,OAJI,MAAS,iBAAiB,MAAS,UAAU,MAAS,eACjD,KAGF;AACT;AAQA,eAAsB,EAAM,GAAU,GAAS,GAAK;CAClD,IAAM,IAAqB,EAAU,CAAQ,GAEvC,IAAqB,EAAmB,SAAS,KAAK,GAAS,OAAW;EAC9E,qBAAqB,EAAU,EAAQ,4BAA4B,EAAmB,0BAA0B,IAC5G,EAA6B,EAAQ,qBAAqB,CAAG,IAC7D;EACJ,OAAO,EAAW,EAAQ,KAAK,IAAI,EAAQ,QAAQ,WAAW,IAAQ;EACtE,OAAO,EAAU,EAAQ,cAAc,EAAmB,YAAY,KAAI,EAAQ,SAAc;EAChG,UAAU,EAAU,EAAQ,iBAAiB,EAAmB,eAAe,KAAI,EAAQ,YAAiB;EAC5G,QAAQ,EAAU,EAAQ,eAAe,EAAmB,aAAa,KAAI,EAAQ,UAAe;EACpG,MAAM,EAAU,EAAQ,aAAa,EAAmB,WAAW,KAAI,EAAQ,QAAa;CAC9F,EAAE;CAEF,OAAO;EACL,GAAG;EACH,UAAU;CACZ;AACF;AAEA,IAAa,KAAY,IAAQ,CAAC,GAAG,IAAS,CAAC,MAAM;CACnD,IAAM,IAAS,CAAC,GACV,IAAiB,CAAC;CAoBxB,QAlBC,EAAM,YAAY,CAAC,EAAA,CAAG,SAAS,GAAS,MAAU;EACjD,IAAM,IAAM,CAAC;EAQb,AANA;GAAC;GAAuB;GAAS;GAAY;GAAU;EAAM,CAAC,CAAC,SAAS,MAAU;GAChF,AAAI,EAAO,EAAM,EAAE,YAAY,CAAC,EAAW,EAAQ,EAAM,MACvD,EAAI,KAAS;EAEjB,CAAC,GAEI,EAAQ,CAAG,MACd,EAAe,KAAS;CAE5B,CAAC,GAEI,EAAQ,CAAc,MACzB,EAAO,WAAW,IAGb;AACT"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { Tt as e } from "../dist-BefbTFbR.js";
|
|
2
|
+
import { t } from "../stimulus-tabs-BQw9OIkn.js";
|
|
3
|
+
import n from "react";
|
|
4
|
+
import { createRoot as r } from "react-dom/client";
|
|
5
|
+
//#region ../../shared/player-events/dist/index.js
|
|
6
|
+
var i = class e extends CustomEvent {
|
|
7
|
+
static {
|
|
8
|
+
this.TYPE = "model-set";
|
|
9
|
+
}
|
|
10
|
+
constructor(t, n, r) {
|
|
11
|
+
super(e.TYPE, {
|
|
12
|
+
bubbles: !0,
|
|
13
|
+
composed: !0,
|
|
14
|
+
detail: {
|
|
15
|
+
complete: n,
|
|
16
|
+
component: t,
|
|
17
|
+
hasModel: r
|
|
18
|
+
}
|
|
19
|
+
}), this.component = t, this.complete = n;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
(class e extends CustomEvent {
|
|
23
|
+
static {
|
|
24
|
+
this.TYPE = "session-changed";
|
|
25
|
+
}
|
|
26
|
+
constructor(t, n) {
|
|
27
|
+
super(e.TYPE, {
|
|
28
|
+
bubbles: !0,
|
|
29
|
+
composed: !0,
|
|
30
|
+
detail: {
|
|
31
|
+
complete: n,
|
|
32
|
+
component: t
|
|
33
|
+
}
|
|
34
|
+
}), this.component = t, this.complete = n;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/delivery/index.ts
|
|
39
|
+
function a(e) {
|
|
40
|
+
let t = e.closest("pie-player") || e.closest("pie-item-player");
|
|
41
|
+
if (t) {
|
|
42
|
+
let e = t.baseHeadingLevel;
|
|
43
|
+
e ??= t.getAttribute("base-heading-level") ?? t.getAttribute("baseheadinglevel");
|
|
44
|
+
let n = parseInt(e, 10);
|
|
45
|
+
if (Number.isFinite(n) && n >= 1 && n <= 6) return n;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
var o = class extends HTMLElement {
|
|
49
|
+
constructor() {
|
|
50
|
+
super(), this._model = { passages: [] }, this._session = null, this._root = null, this._mathObserver = null, this._mathRenderPending = !1, this._playerObserver = null;
|
|
51
|
+
}
|
|
52
|
+
setLangAttribute() {
|
|
53
|
+
let e = this._model && typeof this._model.language ? this._model.language : "", t = e ? e.slice(0, 2) : "en";
|
|
54
|
+
this.setAttribute("lang", t);
|
|
55
|
+
}
|
|
56
|
+
_scheduleMathRender = () => {
|
|
57
|
+
this._mathRenderPending || (this._mathRenderPending = !0, requestAnimationFrame(() => {
|
|
58
|
+
this._mathObserver && this._mathObserver.disconnect(), e(this), this._mathRenderPending = !1, setTimeout(() => {
|
|
59
|
+
this._mathObserver && this._mathObserver.observe(this, {
|
|
60
|
+
childList: !0,
|
|
61
|
+
subtree: !0
|
|
62
|
+
});
|
|
63
|
+
}, 50);
|
|
64
|
+
}));
|
|
65
|
+
};
|
|
66
|
+
_initMathObserver() {
|
|
67
|
+
this._mathObserver || (this._mathObserver = new MutationObserver(this._scheduleMathRender), this._mathObserver.observe(this, {
|
|
68
|
+
childList: !0,
|
|
69
|
+
subtree: !0
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
_disconnectMathObserver() {
|
|
73
|
+
this._mathObserver &&= (this._mathObserver.disconnect(), null);
|
|
74
|
+
}
|
|
75
|
+
set model(e) {
|
|
76
|
+
this._model = e, this.dispatchEvent(new i(this.tagName.toLowerCase(), this._session, !!this._model)), this.setLangAttribute(), this._render();
|
|
77
|
+
}
|
|
78
|
+
set session(e) {
|
|
79
|
+
this._session = e;
|
|
80
|
+
}
|
|
81
|
+
connectedCallback() {
|
|
82
|
+
this.setAttribute("aria-label", "Passage"), this.setAttribute("role", "region"), this._initMathObserver(), this._initPlayerObserver(), this._render();
|
|
83
|
+
}
|
|
84
|
+
_render() {
|
|
85
|
+
let { passages: e = [] } = this._model;
|
|
86
|
+
if (this._model.passages.length > 0) {
|
|
87
|
+
let i = e.map((e, t) => ({
|
|
88
|
+
id: t,
|
|
89
|
+
...e
|
|
90
|
+
})), o = n.createElement(t, {
|
|
91
|
+
tabs: i,
|
|
92
|
+
model: this._model,
|
|
93
|
+
baseHeadingLevel: a(this)
|
|
94
|
+
});
|
|
95
|
+
this._root ||= r(this), this._root.render(o), this._initMathObserver();
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
_initPlayerObserver() {
|
|
99
|
+
let e = this.closest("pie-player") || this.closest("pie-item-player");
|
|
100
|
+
e && (this._playerObserver = new MutationObserver(() => {
|
|
101
|
+
this._render();
|
|
102
|
+
}), this._playerObserver.observe(e, {
|
|
103
|
+
attributes: !0,
|
|
104
|
+
attributeFilter: ["base-heading-level"]
|
|
105
|
+
}));
|
|
106
|
+
}
|
|
107
|
+
_disconnectPlayerObserver() {
|
|
108
|
+
this._playerObserver &&= (this._playerObserver.disconnect(), null);
|
|
109
|
+
}
|
|
110
|
+
disconnectedCallback() {
|
|
111
|
+
this._disconnectMathObserver(), this._disconnectPlayerObserver(), this._root &&= (this._root.unmount(), null);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
115
|
+
export { o as default };
|
|
116
|
+
|
|
117
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../../../shared/player-events/dist/index.js","../../../../src/delivery/index.ts"],"sourcesContent":["//#region src/session-notifier.ts\nvar e = \"commitPendingSession\", t = /* @__PURE__ */ new WeakMap();\nfunction n(e, n) {\n\tlet r = t.get(e);\n\tr || (r = /* @__PURE__ */ new Set(), t.set(e, r)), r.add(n);\n}\nfunction r(t) {\n\treturn Object.getOwnPropertyDescriptor(t, e) !== void 0;\n}\nfunction i(t) {\n\tif (r(t)) return;\n\tlet n = t[e];\n\tObject.defineProperty(t, e, {\n\t\tvalue: () => {\n\t\t\tif (typeof n == \"function\") try {\n\t\t\t\tn.call(t);\n\t\t\t} catch {}\n\t\t\to(t);\n\t\t},\n\t\tconfigurable: !0,\n\t\tenumerable: !1,\n\t\twritable: !0\n\t});\n}\nfunction a(e, t, r = {}) {\n\tlet a = r.delayMs, o = typeof a == \"function\" ? a : () => a ?? 0, s = r.maxWaitMs, c = null, l = null, u = !1, d = () => {\n\t\tc !== null && (clearTimeout(c), c = null), l !== null && (clearTimeout(l), l = null);\n\t}, f = () => {\n\t\td(), u && (u = !1, t());\n\t}, p = {\n\t\tnotify() {\n\t\t\tu = !0, c !== null && clearTimeout(c), c = setTimeout(f, Math.max(0, o())), s !== void 0 && l === null && (l = setTimeout(f, Math.max(0, s)));\n\t\t},\n\t\tflush() {\n\t\t\tif (!u) {\n\t\t\t\td();\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tf();\n\t\t\t} catch (e) {\n\t\t\t\tconsole.warn(\"[session-notifier] a committed session-changed dispatch threw\", e);\n\t\t\t}\n\t\t}\n\t};\n\treturn n(e, p), i(e), p;\n}\nfunction o(e) {\n\tlet n = t.get(e);\n\tif (n) for (let e of [...n]) e.flush();\n}\n//#endregion\n//#region src/index.ts\nvar s = class e extends CustomEvent {\n\tstatic {\n\t\tthis.TYPE = \"model-set\";\n\t}\n\tconstructor(t, n, r) {\n\t\tsuper(e.TYPE, {\n\t\t\tbubbles: !0,\n\t\t\tcomposed: !0,\n\t\t\tdetail: {\n\t\t\t\tcomplete: n,\n\t\t\t\tcomponent: t,\n\t\t\t\thasModel: r\n\t\t\t}\n\t\t}), this.component = t, this.complete = n;\n\t}\n}, c = class e extends CustomEvent {\n\tstatic {\n\t\tthis.TYPE = \"session-changed\";\n\t}\n\tconstructor(t, n) {\n\t\tsuper(e.TYPE, {\n\t\t\tbubbles: !0,\n\t\t\tcomposed: !0,\n\t\t\tdetail: {\n\t\t\t\tcomplete: n,\n\t\t\t\tcomponent: t\n\t\t\t}\n\t\t}), this.component = t, this.complete = n;\n\t}\n};\n//#endregion\nexport { s as ModelSetEvent, e as SESSION_COMMIT_METHOD, c as SessionChangedEvent, a as createSessionNotifier, o as flushSessionNotifiers };\n","// @ts-nocheck\n/**\n * @synced-from pie-elements/packages/passage/src/index.js\n * @auto-generated\n *\n * This file is automatically synced from pie-elements and converted to TypeScript.\n * Manual edits will be overwritten on next sync.\n * To make changes, edit the upstream JavaScript file and run sync again.\n */\n\nimport { ModelSetEvent } from '@pie-element/shared-player-events';\nimport { renderMath } from '@pie-element/shared-math-rendering-mathjax';\nimport React from 'react';\nimport { createRoot } from 'react-dom/client';\n\nimport StimulusTabs from './stimulus-tabs.js';\n\nfunction getBaseHeadingLevel(element) {\n const player =\n element.closest('pie-player') ||\n element.closest('pie-item-player');\n\n if (player) {\n let raw = player.baseHeadingLevel;\n\n // fallback in case someone sets via HTML attribute manually\n if (raw == null) {\n raw =\n player.getAttribute('base-heading-level') ??\n player.getAttribute('baseheadinglevel');\n }\n\n const playerLevel = parseInt(raw, 10);\n\n if (Number.isFinite(playerLevel) && playerLevel >= 1 && playerLevel <= 6) {\n return playerLevel;\n }\n }\n\n return undefined;\n}\n\nexport default class PiePassage extends HTMLElement {\n constructor() {\n super();\n this._model = {\n passages: [],\n };\n this._session = null;\n this._root = null;\n this._mathObserver = null;\n this._mathRenderPending = false;\n this._playerObserver = null;\n }\n\n setLangAttribute() {\n const language = this._model && typeof this._model.language ? this._model.language : '';\n const lang = language ? language.slice(0, 2) : 'en';\n this.setAttribute('lang', lang);\n }\n\n _scheduleMathRender: any = () => {\n if (this._mathRenderPending) return;\n this._mathRenderPending = true;\n\n requestAnimationFrame(() => {\n if (this._mathObserver) {\n this._mathObserver.disconnect();\n }\n renderMath(this);\n this._mathRenderPending = false;\n setTimeout(() => {\n if (this._mathObserver) {\n this._mathObserver.observe(this, { childList: true, subtree: true });\n }\n }, 50);\n });\n };\n\n _initMathObserver() {\n if (this._mathObserver) return;\n this._mathObserver = new MutationObserver(this._scheduleMathRender);\n this._mathObserver.observe(this, { childList: true, subtree: true });\n }\n\n _disconnectMathObserver() {\n if (this._mathObserver) {\n this._mathObserver.disconnect();\n this._mathObserver = null;\n }\n }\n\n set model(s) {\n this._model = s;\n this.dispatchEvent(new ModelSetEvent(this.tagName.toLowerCase(), this._session, !!this._model));\n this.setLangAttribute();\n\n this._render();\n }\n\n set session(s) {\n this._session = s;\n }\n\n connectedCallback() {\n this.setAttribute('aria-label', 'Passage');\n this.setAttribute('role', 'region');\n this._initMathObserver();\n this._initPlayerObserver();\n this._render();\n }\n\n _render() {\n const { passages = [] } = this._model;\n\n if (this._model.passages.length > 0) {\n const passagesTabs = passages.map((passage, index) => ({\n id: index,\n ...passage,\n }));\n\n const elem = React.createElement(StimulusTabs, {\n tabs: passagesTabs,\n model: this._model,\n baseHeadingLevel: getBaseHeadingLevel(this),\n });\n\n if (!this._root) {\n this._root = createRoot(this);\n }\n this._root.render(elem);\n\n this._initMathObserver();\n }\n }\n\n _initPlayerObserver() {\n const player = this.closest('pie-player') || this.closest('pie-item-player');\n if (!player) return;\n\n this._playerObserver = new MutationObserver(() => {\n this._render();\n });\n this._playerObserver.observe(player, { attributes: true, attributeFilter: ['base-heading-level'] });\n }\n\n _disconnectPlayerObserver() {\n if (this._playerObserver) {\n this._playerObserver.disconnect();\n this._playerObserver = null;\n }\n }\n\n disconnectedCallback() {\n this._disconnectMathObserver();\n this._disconnectPlayerObserver();\n if (this._root) {\n this._root.unmount();\n this._root = null;\n }\n }\n}\n"],"mappings":";;;;;AAqDA,IAAI,IAAI,MAAM,UAAU,YAAY;CACnC;EACC,KAAK,OAAO;CACb;CACA,YAAY,GAAG,GAAG,GAAG;EACpB,MAAM,EAAE,MAAM;GACb,SAAS,CAAC;GACV,UAAU,CAAC;GACX,QAAQ;IACP,UAAU;IACV,WAAW;IACX,UAAU;GACX;EACD,CAAC,GAAG,KAAK,YAAY,GAAG,KAAK,WAAW;CACzC;AACD;CAAO,MAAM,UAAU,YAAY;CAClC;EACC,KAAK,OAAO;CACb;CACA,YAAY,GAAG,GAAG;EACjB,MAAM,EAAE,MAAM;GACb,SAAS,CAAC;GACV,UAAU,CAAC;GACX,QAAQ;IACP,UAAU;IACV,WAAW;GACZ;EACD,CAAC,GAAG,KAAK,YAAY,GAAG,KAAK,WAAW;CACzC;AACD;;;ACjEA,SAAS,EAAoB,GAAS;CACpC,IAAM,IACJ,EAAQ,QAAQ,YAAY,KAC5B,EAAQ,QAAQ,iBAAiB;CAEnC,IAAI,GAAQ;EACV,IAA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