@pie-element/multiple-choice 13.2.1-next.2 → 13.2.2-next.0
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/configure.js +2 -0
- package/controller.js +1 -0
- package/dist/browser/_Uint8Array-CUOjhemR.js +396 -0
- package/dist/browser/_Uint8Array-CUOjhemR.js.map +1 -0
- package/dist/browser/_baseClone-fFvdZAu5.js +245 -0
- package/dist/browser/_baseClone-fFvdZAu5.js.map +1 -0
- package/dist/browser/author/index.js +40187 -0
- package/dist/browser/author/index.js.map +1 -0
- package/dist/browser/controller/index.js +199 -0
- package/dist/browser/controller/index.js.map +1 -0
- package/dist/browser/debounce-PkR6OuzU.js +9669 -0
- package/dist/browser/debounce-PkR6OuzU.js.map +1 -0
- package/dist/browser/delivery/index.js +250 -0
- package/dist/browser/delivery/index.js.map +1 -0
- package/dist/browser/isEqual-CnAlrBXo.js +182 -0
- package/dist/browser/isEqual-CnAlrBXo.js.map +1 -0
- package/dist/browser/isObject-B-uKF3Sg.js +38 -0
- package/dist/browser/isObject-B-uKF3Sg.js.map +1 -0
- package/dist/browser/main-CmP4Uwst.js +2440 -0
- package/dist/browser/main-CmP4Uwst.js.map +1 -0
- package/dist/browser/multiple-choice.css +2 -0
- package/dist/browser/print/index.js +48 -0
- package/dist/browser/print/index.js.map +1 -0
- package/package.json +34 -7
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import { n as e, t } from "../isEqual-CnAlrBXo.js";
|
|
2
|
+
//#region src/controller/utils.ts
|
|
3
|
+
var n = (e) => e.filter((e) => e.correct).map((e) => e.value).sort(), r = (e, r) => {
|
|
4
|
+
let i = n(e.choices);
|
|
5
|
+
return r && t((r.value || []).sort(), i);
|
|
6
|
+
}, i = {
|
|
7
|
+
choiceMode: "checkbox",
|
|
8
|
+
choicePrefix: "letters",
|
|
9
|
+
choices: [],
|
|
10
|
+
choicesLayout: "vertical",
|
|
11
|
+
feedbackEnabled: !1,
|
|
12
|
+
gridColumns: 2,
|
|
13
|
+
lockChoiceOrder: !0,
|
|
14
|
+
partialScoring: !0,
|
|
15
|
+
prompt: "",
|
|
16
|
+
promptEnabled: !0,
|
|
17
|
+
rationale: "",
|
|
18
|
+
rationaleEnabled: !0,
|
|
19
|
+
scoringType: "auto",
|
|
20
|
+
studentInstructionsEnabled: !0,
|
|
21
|
+
teacherInstructions: "",
|
|
22
|
+
teacherInstructionsEnabled: !0,
|
|
23
|
+
toolbarEditorPosition: "bottom",
|
|
24
|
+
selectedAnswerBackgroundColor: "initial",
|
|
25
|
+
selectedAnswerStrokeColor: "initial",
|
|
26
|
+
selectedAnswerStrokeWidth: "initial",
|
|
27
|
+
hoverAnswerBackgroundColor: "initial",
|
|
28
|
+
hoverAnswerStrokeColor: "initial",
|
|
29
|
+
hoverAnswerStrokeWidth: "initial",
|
|
30
|
+
keyboardEventsEnabled: !1
|
|
31
|
+
}, a = Object.defineProperty, o = (e, t) => {
|
|
32
|
+
let n = {};
|
|
33
|
+
for (var r in e) a(n, r, {
|
|
34
|
+
get: e[r],
|
|
35
|
+
enumerable: !0
|
|
36
|
+
});
|
|
37
|
+
return t || a(n, Symbol.toStringTag, { value: "Module" }), n;
|
|
38
|
+
};
|
|
39
|
+
function s(e) {
|
|
40
|
+
return Array.isArray(e) ? e.filter((e) => e != null) : [];
|
|
41
|
+
}
|
|
42
|
+
function c(e) {
|
|
43
|
+
let t = [...e];
|
|
44
|
+
for (let e = t.length - 1; e > 0; e--) {
|
|
45
|
+
let n = Math.floor(Math.random() * (e + 1));
|
|
46
|
+
[t[e], t[n]] = [t[n], t[e]];
|
|
47
|
+
}
|
|
48
|
+
return t;
|
|
49
|
+
}
|
|
50
|
+
function l(e) {
|
|
51
|
+
return e == null ? !0 : Array.isArray(e) ? e.length === 0 : typeof e == "object" ? Object.keys(e).length === 0 : !1;
|
|
52
|
+
}
|
|
53
|
+
async function u(e, t, n, r = "value") {
|
|
54
|
+
let i = s(t?.data?.shuffledValues ?? t?.shuffledValues ?? []);
|
|
55
|
+
if (!t) {
|
|
56
|
+
console.warn("Unable to save shuffled choices because there's no session.");
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
if (!l(i)) return s(i.map((t) => e.find((e) => e[r] === t)));
|
|
60
|
+
let a = c(e);
|
|
61
|
+
if (n && typeof n == "function") try {
|
|
62
|
+
let e = s(a.map((e) => e[r]));
|
|
63
|
+
l(e) ? console.error(`shuffledValues is an empty array - refusing to call updateSession. shuffledChoices: ${JSON.stringify(a)}, key: ${r}`) : t.id && t.element && await n(t.id, t.element, { shuffledValues: e });
|
|
64
|
+
} catch (e) {
|
|
65
|
+
console.warn("Unable to save shuffled order for choices"), console.error(e);
|
|
66
|
+
}
|
|
67
|
+
else console.warn("Unable to save shuffled choices, shuffle will happen every time.");
|
|
68
|
+
return a;
|
|
69
|
+
}
|
|
70
|
+
function d(e, t, n) {
|
|
71
|
+
return !!(e.lockChoiceOrder || n["@pie-element"]?.lockChoiceOrder || (n.role ?? "student") === "instructor");
|
|
72
|
+
}
|
|
73
|
+
var f = /* @__PURE__ */ o({ enabled: () => p });
|
|
74
|
+
function p(e, t, n) {
|
|
75
|
+
return e?.partialScoring === !1 || t?.partialScoring === !1 ? !1 : typeof n == "boolean" ? n : !0;
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/controller/index.ts
|
|
79
|
+
var m = (e, t, n) => (r) => {
|
|
80
|
+
let { role: i, mode: a } = t || {}, o = {
|
|
81
|
+
label: r.label,
|
|
82
|
+
value: r.value
|
|
83
|
+
};
|
|
84
|
+
if (i === "instructor" && (a === "view" || a === "evaluate") ? o.rationale = e.rationaleEnabled ? r.rationale : null : o.rationale = null, a === "evaluate" && (o.correct = !!r.correct, e.feedbackEnabled)) {
|
|
85
|
+
let e = r.feedback && r.feedback.type || "none";
|
|
86
|
+
e === "default" ? o.feedback = n[r.correct ? "correct" : "incorrect"] : e === "custom" && (o.feedback = r.feedback.value);
|
|
87
|
+
}
|
|
88
|
+
return o;
|
|
89
|
+
};
|
|
90
|
+
function h(e = {}) {
|
|
91
|
+
return new Promise((t) => t({
|
|
92
|
+
...i,
|
|
93
|
+
...e
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
var g = (e) => {
|
|
97
|
+
let { verticalMode: t, choicesLayout: n, ...r } = e || {};
|
|
98
|
+
return {
|
|
99
|
+
...i,
|
|
100
|
+
...r,
|
|
101
|
+
choicesLayout: n || t === !1 && "horizontal" || i.choicesLayout
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
async function _(e, t, n, i) {
|
|
105
|
+
let a = g(e), o = Object.assign({
|
|
106
|
+
correct: "Correct",
|
|
107
|
+
incorrect: "Incorrect"
|
|
108
|
+
}, a.defaultFeedback), s = (a.choices || []).map(m(a, n, o));
|
|
109
|
+
d(a, t, n) || (s = await u(s, t, i, "value"));
|
|
110
|
+
let c = {
|
|
111
|
+
disabled: n.mode !== "gather",
|
|
112
|
+
mode: n.mode,
|
|
113
|
+
prompt: a.promptEnabled ? a.prompt : null,
|
|
114
|
+
choicesLayout: a.choicesLayout,
|
|
115
|
+
gridColumns: a.gridColumns,
|
|
116
|
+
choiceMode: a.choiceMode,
|
|
117
|
+
keyMode: a.choicePrefix,
|
|
118
|
+
choices: s,
|
|
119
|
+
responseCorrect: n.mode === "evaluate" ? r(a, t) : void 0,
|
|
120
|
+
language: a.language,
|
|
121
|
+
extraCSSRules: a.extraCSSRules,
|
|
122
|
+
fontSizeFactor: a.fontSizeFactor,
|
|
123
|
+
isSelectionButtonBelow: a.isSelectionButtonBelow,
|
|
124
|
+
selectedAnswerBackgroundColor: a.selectedAnswerBackgroundColor || "initial",
|
|
125
|
+
selectedAnswerStrokeColor: a.selectedAnswerStrokeColor || "initial",
|
|
126
|
+
selectedAnswerStrokeWidth: a.selectedAnswerStrokeWidth || "initial",
|
|
127
|
+
hoverAnswerBackgroundColor: a.hoverAnswerBackgroundColor || "initial",
|
|
128
|
+
hoverAnswerStrokeColor: a.hoverAnswerStrokeColor || "initial",
|
|
129
|
+
hoverAnswerStrokeWidth: a.hoverAnswerStrokeWidth || "initial",
|
|
130
|
+
minSelections: a.minSelections,
|
|
131
|
+
maxSelections: a.maxSelections,
|
|
132
|
+
keyboardEventsEnabled: a.keyboardEventsEnabled,
|
|
133
|
+
autoplayAudioEnabled: a.autoplayAudioEnabled,
|
|
134
|
+
completeAudioEnabled: a.completeAudioEnabled,
|
|
135
|
+
customAudioButton: a.customAudioButton
|
|
136
|
+
}, { role: l, mode: f } = n || {};
|
|
137
|
+
return l === "instructor" && (f === "view" || f === "evaluate") ? c.teacherInstructions = a.teacherInstructionsEnabled ? a.teacherInstructions : null : c.teacherInstructions = null, c;
|
|
138
|
+
}
|
|
139
|
+
var v = (t, n) => {
|
|
140
|
+
if (!n || e(n)) return 0;
|
|
141
|
+
let r = n.value || [], i = (t.choices || []).filter((e) => e.correct), a = r.reduce((e, t) => e + +!!i.find((e) => e.value === t), 0);
|
|
142
|
+
i.length < r.length && (a -= r.length - i.length, a < 0 && (a = 0));
|
|
143
|
+
let o = i.length ? a / i.length : 0;
|
|
144
|
+
return parseFloat(o.toFixed(2));
|
|
145
|
+
}, y = (e, t, n) => {
|
|
146
|
+
let r = [], i = t?.value || [], a = e.choiceMode === "radio" ? "multiple-choice (radio)" : "multiple-select (checkbox)";
|
|
147
|
+
r.push(`Question type: ${a}.`), i.length ? r.push(`Student selected ${i.length} answer(s): ${i.join(", ")}.`) : r.push("Student did not select any answers.");
|
|
148
|
+
let o = (e.choices || []).filter((e) => e.correct), s = o.map((e) => e.value);
|
|
149
|
+
if (r.push(`${o.length} correct answer(s) are defined for this question.`), i.length) {
|
|
150
|
+
let e = i.filter((e) => s.includes(e)), t = i.filter((e) => !s.includes(e));
|
|
151
|
+
r.push(`Student selected ${e.length} correct and ${t.length} incorrect answer(s).`);
|
|
152
|
+
}
|
|
153
|
+
let c = f.enabled(e, n) && e.choiceMode !== "radio" ? "partial scoring" : "all-or-nothing scoring";
|
|
154
|
+
r.push(`Score calculated using ${c}.`);
|
|
155
|
+
let l = v(e, t);
|
|
156
|
+
return r.push(`Final score: ${l}.`), r;
|
|
157
|
+
};
|
|
158
|
+
function b(t, n, r) {
|
|
159
|
+
return new Promise((i) => {
|
|
160
|
+
if (!n || e(n)) i({
|
|
161
|
+
score: 0,
|
|
162
|
+
empty: !0,
|
|
163
|
+
traceLog: ["Student did not select any answers. Score is 0."]
|
|
164
|
+
});
|
|
165
|
+
else {
|
|
166
|
+
let e = y(t, n, r), a = v(t, n);
|
|
167
|
+
i({
|
|
168
|
+
score: f.enabled(t, r) && t.choiceMode !== "radio" ? a : +(a === 1),
|
|
169
|
+
empty: !1,
|
|
170
|
+
traceLog: e
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
var x = (e, t) => new Promise((n) => {
|
|
176
|
+
if (t.mode !== "evaluate" && t.role === "instructor") {
|
|
177
|
+
let { choices: t } = e || { choices: [] };
|
|
178
|
+
n({
|
|
179
|
+
id: "1",
|
|
180
|
+
value: t.filter((e) => e.correct).map((e) => e.value)
|
|
181
|
+
});
|
|
182
|
+
} else n(null);
|
|
183
|
+
}), S = (e) => (e || "").replace(/(<(?!img|iframe|source)([^>]+)>)/gi, ""), C = (t = {}, n = {}) => {
|
|
184
|
+
let { choices: r } = t, { minAnswerChoices: i = 2, maxAnswerChoices: a } = n, o = [...r || []].reverse(), s = {}, c = {}, l = {};
|
|
185
|
+
["teacherInstructions", "prompt"].forEach((e) => {
|
|
186
|
+
n[e]?.required && !S(t[e]) && (l[e] = "This field is required.");
|
|
187
|
+
});
|
|
188
|
+
let u = !1;
|
|
189
|
+
o.forEach((e, t) => {
|
|
190
|
+
let { correct: r, value: i, label: a, rationale: l } = e;
|
|
191
|
+
r && (u = !0), S(a) ? o.slice(t + 1).some((e) => e.label === a) && (s[i] = "Content should be unique.") : s[i] = "Content should not be empty.", n.rationale?.required && !S(l) && (c[i] = "This field is required.");
|
|
192
|
+
});
|
|
193
|
+
let d = (r || []).length;
|
|
194
|
+
return d < i ? l.answerChoices = `There should be at least ${i} choices defined.` : d > a && (l.answerChoices = `No more than ${a} choices should be defined.`), u || (l.correctResponse = "No correct response defined."), e(s) || (l.choices = s), e(c) || (l.rationale = c), l;
|
|
195
|
+
};
|
|
196
|
+
//#endregion
|
|
197
|
+
export { x as createCorrectResponseSession, h as createDefaultModel, y as getLogTrace, v as getScore, _ as model, g as normalize, b as outcome, C as validate };
|
|
198
|
+
|
|
199
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../src/controller/utils.ts","../../../src/controller/defaults.ts","../../../../../shared/controller-utils/dist/index.js","../../../src/controller/index.ts"],"sourcesContent":["// @ts-nocheck\n/**\n * @synced-from pie-elements/packages/multiple-choice/controller/src/utils.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 { isEqual } from 'lodash-es';\n\nexport const getCorrectResponse = (choices) =>\n choices\n .filter((c) => c.correct)\n .map((c) => c.value)\n .sort();\n\nexport const isResponseCorrect = (question, session) => {\n let correctResponse = getCorrectResponse(question.choices);\n return session && isEqual((session.value || []).sort(), correctResponse);\n};\n","// @ts-nocheck\n/**\n * @synced-from pie-elements/packages/multiple-choice/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\nexport default {\n choiceMode: 'checkbox',\n choicePrefix: 'letters',\n choices: [],\n choicesLayout: 'vertical',\n feedbackEnabled: false,\n gridColumns: 2,\n lockChoiceOrder: true,\n partialScoring: true,\n prompt: '',\n promptEnabled: true,\n rationale: '',\n rationaleEnabled: true,\n scoringType: 'auto',\n studentInstructionsEnabled: true,\n teacherInstructions: '',\n teacherInstructionsEnabled: true,\n toolbarEditorPosition: 'bottom',\n selectedAnswerBackgroundColor: 'initial',\n selectedAnswerStrokeColor: 'initial',\n selectedAnswerStrokeWidth: 'initial',\n hoverAnswerBackgroundColor: 'initial',\n hoverAnswerStrokeColor: 'initial',\n hoverAnswerStrokeWidth: 'initial',\n keyboardEventsEnabled: false,\n};\n","//#region \\0rolldown/runtime.js\nvar e = Object.defineProperty, t = (t, n) => {\n\tlet r = {};\n\tfor (var i in t) e(r, i, {\n\t\tget: t[i],\n\t\tenumerable: !0\n\t});\n\treturn n || e(r, Symbol.toStringTag, { value: \"Module\" }), r;\n};\n//#endregion\n//#region src/persistence.ts\nfunction n(e) {\n\treturn Array.isArray(e) ? e.filter((e) => e != null) : [];\n}\nfunction r(e) {\n\tlet t = [...e];\n\tfor (let e = t.length - 1; e > 0; e--) {\n\t\tlet n = Math.floor(Math.random() * (e + 1));\n\t\t[t[e], t[n]] = [t[n], t[e]];\n\t}\n\treturn t;\n}\nfunction i(e) {\n\treturn e == null ? !0 : Array.isArray(e) ? e.length === 0 : typeof e == \"object\" ? Object.keys(e).length === 0 : !1;\n}\nasync function a(e, t, a, o = \"value\") {\n\tlet s = n(t?.data?.shuffledValues ?? t?.shuffledValues ?? []);\n\tif (!t) {\n\t\tconsole.warn(\"Unable to save shuffled choices because there's no session.\");\n\t\treturn;\n\t}\n\tif (!i(s)) return n(s.map((t) => e.find((e) => e[o] === t)));\n\tlet c = r(e);\n\tif (a && typeof a == \"function\") try {\n\t\tlet e = n(c.map((e) => e[o]));\n\t\ti(e) ? console.error(`shuffledValues is an empty array - refusing to call updateSession. shuffledChoices: ${JSON.stringify(c)}, key: ${o}`) : t.id && t.element && await a(t.id, t.element, { shuffledValues: e });\n\t} catch (e) {\n\t\tconsole.warn(\"Unable to save shuffled order for choices\"), console.error(e);\n\t}\n\telse console.warn(\"Unable to save shuffled choices, shuffle will happen every time.\");\n\treturn c;\n}\nfunction o(e, t, n) {\n\treturn !!(e.lockChoiceOrder || n[\"@pie-element\"]?.lockChoiceOrder || (n.role ?? \"student\") === \"instructor\");\n}\n//#endregion\n//#region src/partial-scoring.ts\nvar s = /* @__PURE__ */ t({ enabled: () => c });\nfunction c(e, t, n) {\n\treturn e?.partialScoring === !1 || t?.partialScoring === !1 ? !1 : typeof n == \"boolean\" ? n : !0;\n}\n//#endregion\nexport { a as getShuffledChoices, o as lockChoices, s as partialScoring };\n","// @ts-nocheck\n/**\n * @synced-from pie-elements/packages/multiple-choice/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\n/* eslint-disable no-console */\nimport { isEmpty } from 'lodash-es';\nimport { isResponseCorrect } from './utils.js';\nimport defaults from './defaults.js';\nimport { lockChoices, partialScoring, getShuffledChoices } from '@pie-element/shared-controller-utils';\n\nconst prepareChoice = (model, env, defaultFeedback) => (choice) => {\n const { role, mode } = env || {};\n const out = {\n label: choice.label,\n value: choice.value,\n };\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.rationale = model.rationaleEnabled ? choice.rationale : null;\n } else {\n out.rationale = null;\n }\n\n if (mode === 'evaluate') {\n out.correct = !!choice.correct;\n\n if (model.feedbackEnabled) {\n const feedbackType = (choice.feedback && choice.feedback.type) || 'none';\n\n if (feedbackType === 'default') {\n out.feedback = defaultFeedback[choice.correct ? 'correct' : 'incorrect'];\n } else if (feedbackType === 'custom') {\n out.feedback = choice.feedback.value;\n }\n }\n }\n\n return out;\n};\n\nexport function createDefaultModel(model = {}) {\n return new Promise((resolve) => resolve({ ...defaults, ...model }));\n}\n\nexport const normalize = (question) => {\n const { verticalMode, choicesLayout, ...questionProps } = question || {};\n\n return {\n ...defaults,\n ...questionProps,\n // This is used for offering support for old models which have the property verticalMode\n // Same thing is set in authoring : packages/multiple-choice/configure/src/index.jsx - createDefaultModel\n choicesLayout: choicesLayout || (verticalMode === false && 'horizontal') || defaults.choicesLayout,\n };\n};\n\n/**\n *\n * @param {*} question\n * @param {*} session\n * @param {*} env\n * @param {*} updateSession - optional - a function that will set the properties passed into it on the session.\n */\nexport async function model(question, session, env, updateSession) {\n const normalizedQuestion = normalize(question);\n\n const defaultFeedback = Object.assign(\n { correct: 'Correct', incorrect: 'Incorrect' },\n normalizedQuestion.defaultFeedback,\n );\n\n let choices = (normalizedQuestion.choices || []).map(prepareChoice(normalizedQuestion, env, defaultFeedback));\n\n const lockChoiceOrder = lockChoices(normalizedQuestion, session, env);\n\n if (!lockChoiceOrder) {\n choices = await getShuffledChoices(choices, session, updateSession, 'value');\n }\n\n const out = {\n disabled: env.mode !== 'gather',\n mode: env.mode,\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n choicesLayout: normalizedQuestion.choicesLayout,\n gridColumns: normalizedQuestion.gridColumns,\n choiceMode: normalizedQuestion.choiceMode,\n keyMode: normalizedQuestion.choicePrefix,\n choices,\n responseCorrect: env.mode === 'evaluate' ? isResponseCorrect(normalizedQuestion, session) : undefined,\n language: normalizedQuestion.language,\n extraCSSRules: normalizedQuestion.extraCSSRules,\n fontSizeFactor: normalizedQuestion.fontSizeFactor,\n isSelectionButtonBelow: normalizedQuestion.isSelectionButtonBelow,\n selectedAnswerBackgroundColor: normalizedQuestion.selectedAnswerBackgroundColor || 'initial',\n selectedAnswerStrokeColor: normalizedQuestion.selectedAnswerStrokeColor || 'initial',\n selectedAnswerStrokeWidth: normalizedQuestion.selectedAnswerStrokeWidth || 'initial',\n hoverAnswerBackgroundColor: normalizedQuestion.hoverAnswerBackgroundColor || 'initial',\n hoverAnswerStrokeColor: normalizedQuestion.hoverAnswerStrokeColor || 'initial',\n hoverAnswerStrokeWidth: normalizedQuestion.hoverAnswerStrokeWidth || 'initial',\n minSelections: normalizedQuestion.minSelections,\n maxSelections: normalizedQuestion.maxSelections,\n keyboardEventsEnabled: normalizedQuestion.keyboardEventsEnabled,\n autoplayAudioEnabled: normalizedQuestion.autoplayAudioEnabled,\n completeAudioEnabled: normalizedQuestion.completeAudioEnabled,\n customAudioButton: normalizedQuestion.customAudioButton,\n };\n\n const { role, mode } = env || {};\n\n if (role === 'instructor' && (mode === 'view' || mode === 'evaluate')) {\n out.teacherInstructions = normalizedQuestion.teacherInstructionsEnabled\n ? normalizedQuestion.teacherInstructions\n : null;\n } else {\n out.teacherInstructions = null;\n }\n\n return out;\n}\n\nexport const getScore = (config, session) => {\n if (!session || isEmpty(session)) {\n return 0;\n }\n\n const selectedChoices = session.value || [];\n const correctChoices = (config.choices || []).filter((ch) => ch.correct);\n\n let score = selectedChoices.reduce(\n (acc, selectedChoice) => acc + (correctChoices.find((ch) => ch.value === selectedChoice) ? 1 : 0),\n 0,\n );\n\n if (correctChoices.length < selectedChoices.length) {\n score -= selectedChoices.length - correctChoices.length;\n\n if (score < 0) {\n score = 0;\n }\n }\n\n const str = correctChoices.length ? score / correctChoices.length : 0;\n\n return parseFloat(str.toFixed(2));\n};\n\n/**\n * Generates detailed trace log for scoring evaluation\n * @param {Object} model - the question model\n * @param {Object} session - the student session\n * @param {Object} env - the environment\n * @returns {Array} traceLog - array of trace messages\n */\nexport const getLogTrace = (model, session, env) => {\n const traceLog = [];\n const selected = session?.value || [];\n \n const questionType = model.choiceMode === 'radio' ? 'multiple-choice (radio)' : 'multiple-select (checkbox)';\n traceLog.push(`Question type: ${questionType}.`);\n \n if (selected.length) {\n traceLog.push(`Student selected ${selected.length} answer(s): ${selected.join(', ')}.`);\n } else {\n traceLog.push('Student did not select any answers.');\n }\n\n const correctChoices = (model.choices || []).filter((c) => c.correct);\n const correctValues = correctChoices.map((c) => c.value);\n traceLog.push(`${correctChoices.length} correct answer(s) are defined for this question.`);\n \n if (selected.length) {\n const correctSelected = selected.filter((v) => correctValues.includes(v));\n const incorrectSelected = selected.filter((v) => !correctValues.includes(v));\n traceLog.push(\n `Student selected ${correctSelected.length} correct and ${incorrectSelected.length} incorrect answer(s).`\n );\n }\n\n const partialScoringEnabled = partialScoring.enabled(model, env) && model.choiceMode !== 'radio';\n const scoringMethod = partialScoringEnabled ? 'partial scoring' : 'all-or-nothing scoring';\n traceLog.push(`Score calculated using ${scoringMethod}.`);\n\n const score = getScore(model, session);\n traceLog.push(`Final score: ${score}.`);\n\n return traceLog;\n};\n\n/**\n *\n * The score is partial by default for checkbox mode, allOrNothing for radio mode.\n * To disable partial scoring for checkbox mode you either set model.partialScoring = false or env.partialScoring = false. the value in `env` will\n * override the value in `model`.\n * @param {Object} model - the main model\n * @param {*} session\n * @param {Object} env\n */\nexport function outcome(model, session, env) {\n return new Promise((resolve) => {\n if (!session || isEmpty(session)) {\n resolve({ score: 0, empty: true, traceLog: ['Student did not select any answers. Score is 0.'] });\n } else {\n const traceLog = getLogTrace(model, session, env);\n const score = getScore(model, session);\n const partialScoringEnabled = partialScoring.enabled(model, env) && model.choiceMode !== 'radio';\n\n resolve({ \n score: partialScoringEnabled ? score : score === 1 ? 1 : 0, \n empty: false, \n traceLog \n });\n }\n });\n}\n\nexport const createCorrectResponseSession = (question, env) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n const { choices } = question || { choices: [] };\n\n resolve({\n id: '1',\n value: choices.filter((c) => c.correct).map((c) => c.value),\n });\n } else {\n resolve(null);\n }\n });\n};\n\n// remove all html tags\nconst getInnerText = (html) => (html || '').replaceAll(/<[^>]*>/g, '');\n\n// remove all html tags except img, iframe and source tag for audio\nconst getContent = (html) => (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '');\n\nexport const validate = (model = {}, config = {}) => {\n const { choices } = model;\n const { minAnswerChoices = 2, maxAnswerChoices } = config;\n const reversedChoices = [...(choices || [])].reverse();\n const choicesErrors = {};\n const rationaleErrors = {};\n const errors = {};\n\n ['teacherInstructions', 'prompt'].forEach((field) => {\n if (config[field]?.required && !getContent(model[field])) {\n errors[field] = 'This field is required.';\n }\n });\n\n let hasCorrectResponse = false;\n\n reversedChoices.forEach((choice, index) => {\n const { correct, value, label, rationale } = choice;\n\n if (correct) {\n hasCorrectResponse = true;\n }\n\n if (!getContent(label)) {\n choicesErrors[value] = 'Content should not be empty.';\n } else {\n const identicalAnswer = reversedChoices.slice(index + 1).some((c) => c.label === label);\n\n if (identicalAnswer) {\n choicesErrors[value] = 'Content should be unique.';\n }\n }\n\n if (config.rationale?.required && !getContent(rationale)) {\n rationaleErrors[value] = 'This field is required.';\n }\n });\n\n const nbOfChoices = (choices || []).length;\n\n if (nbOfChoices < minAnswerChoices) {\n errors.answerChoices = `There should be at least ${minAnswerChoices} choices defined.`;\n } else if (nbOfChoices > maxAnswerChoices) {\n errors.answerChoices = `No more than ${maxAnswerChoices} choices should be defined.`;\n }\n\n if (!hasCorrectResponse) {\n errors.correctResponse = 'No correct response defined.';\n }\n\n if (!isEmpty(choicesErrors)) {\n errors.choices = choicesErrors;\n }\n\n if (!isEmpty(rationaleErrors)) {\n errors.rationale = rationaleErrors;\n }\n\n return errors;\n};\n"],"mappings":";;AAYA,IAAa,KAAsB,MACjC,EACG,QAAQ,MAAM,EAAE,OAAO,EACvB,KAAK,MAAM,EAAE,KAAK,EAClB,KAAK,GAEG,KAAqB,GAAU,MAAY;CACtD,IAAI,IAAkB,EAAmB,EAAS,OAAO;CACzD,OAAO,KAAW,GAAS,EAAQ,SAAS,CAAC,GAAG,KAAK,GAAG,CAAe;AACzE,GCXA,IAAe;CACb,YAAY;CACZ,cAAc;CACd,SAAS,CAAC;CACV,eAAe;CACf,iBAAiB;CACjB,aAAa;CACb,iBAAiB;CACjB,gBAAgB;CAChB,QAAQ;CACR,eAAe;CACf,WAAW;CACX,kBAAkB;CAClB,aAAa;CACb,4BAA4B;CAC5B,qBAAqB;CACrB,4BAA4B;CAC5B,uBAAuB;CACvB,+BAA+B;CAC/B,2BAA2B;CAC3B,2BAA2B;CAC3B,4BAA4B;CAC5B,wBAAwB;CACxB,wBAAwB;CACxB,uBAAuB;AACzB,GCl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