@pie-element/mc-populated-blank 0.2.13 → 0.3.0-next.11

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.
Files changed (69) hide show
  1. package/README.md +9 -6
  2. package/author.js +2 -0
  3. package/configure.js +2 -0
  4. package/dist/author/defaults.d.ts +74 -0
  5. package/dist/author/index.d.ts +0 -1
  6. package/dist/author/index.js +1732 -1553
  7. package/dist/author/index.js.map +1 -1
  8. package/dist/browser/McPopulatedBlank-DbmR6UWn.js +2542 -0
  9. package/dist/browser/McPopulatedBlank-DbmR6UWn.js.map +1 -0
  10. package/dist/browser/author/index.js +41 -0
  11. package/dist/browser/author/index.js.map +1 -0
  12. package/dist/browser/client-CWh3mUUV.js +2385 -0
  13. package/dist/browser/client-CWh3mUUV.js.map +1 -0
  14. package/dist/browser/controller/index.js +2 -0
  15. package/dist/browser/controller-D_ITRCYG.js +209 -0
  16. package/dist/browser/controller-D_ITRCYG.js.map +1 -0
  17. package/dist/browser/delivery/index.js +124 -0
  18. package/dist/browser/delivery/index.js.map +1 -0
  19. package/dist/browser/layoutLimits-Bp17YP2V.js +42 -0
  20. package/dist/browser/layoutLimits-Bp17YP2V.js.map +1 -0
  21. package/dist/browser/print/index.js +129 -0
  22. package/dist/browser/print/index.js.map +1 -0
  23. package/dist/controller/defaults.d.ts +8 -30
  24. package/dist/controller/index.d.ts +79 -63
  25. package/dist/controller/index.js +108 -85
  26. package/dist/controller/index.js.map +1 -1
  27. package/dist/delivery/computeAudioMode.d.ts +0 -1
  28. package/dist/delivery/computeChoiceCorrectness.d.ts +0 -1
  29. package/dist/delivery/computeDisplayState.d.ts +7 -8
  30. package/dist/delivery/computeLayoutProfile.d.ts +0 -1
  31. package/dist/delivery/computeLayoutStyle.d.ts +0 -2
  32. package/dist/delivery/i18n.d.ts +8 -0
  33. package/dist/delivery/index.d.ts +8 -17
  34. package/dist/delivery/index.js +6138 -3662
  35. package/dist/delivery/index.js.map +1 -1
  36. package/dist/delivery/variant-css-map.d.ts +15 -2
  37. package/dist/index.d.ts +0 -1
  38. package/dist/index.iife.d.ts +0 -156
  39. package/dist/index.iife.js +139 -38
  40. package/dist/index.js +2 -6811
  41. package/dist/print/index.d.ts +4 -1
  42. package/dist/print/index.js +8158 -3655
  43. package/dist/print/index.js.map +1 -1
  44. package/dist/print/preparePrint.d.ts +15 -0
  45. package/dist/runtime-support.d.ts +12 -0
  46. package/dist/runtime-support.js +14 -0
  47. package/dist/runtime-support.js.map +1 -0
  48. package/dist/shared/layoutLimits.d.ts +1 -2
  49. package/dist/shared/types.d.ts +21 -19
  50. package/module/print.js +5192 -0
  51. package/module/print.js.map +1 -0
  52. package/package.json +42 -14
  53. package/print.js +2 -0
  54. package/dist/author/index.d.ts.map +0 -1
  55. package/dist/controller/defaults.d.ts.map +0 -1
  56. package/dist/controller/index.d.ts.map +0 -1
  57. package/dist/delivery/computeAudioMode.d.ts.map +0 -1
  58. package/dist/delivery/computeChoiceCorrectness.d.ts.map +0 -1
  59. package/dist/delivery/computeDisplayState.d.ts.map +0 -1
  60. package/dist/delivery/computeLayoutProfile.d.ts.map +0 -1
  61. package/dist/delivery/computeLayoutStyle.d.ts.map +0 -1
  62. package/dist/delivery/index.d.ts.map +0 -1
  63. package/dist/delivery/variant-css-map.d.ts.map +0 -1
  64. package/dist/index.d.ts.map +0 -1
  65. package/dist/index.iife.d.ts.map +0 -1
  66. package/dist/index.js.map +0 -1
  67. package/dist/print/index.d.ts.map +0 -1
  68. package/dist/shared/layoutLimits.d.ts.map +0 -1
  69. package/dist/shared/types.d.ts.map +0 -1
@@ -0,0 +1,2 @@
1
+ import { a as e, c as t, i as n, l as r, n as i, o as a, r as o, s, t as c, u as l } from "../controller-D_ITRCYG.js";
2
+ export { c as countBlankTokens, i as createCorrectResponseSession, o as createDefaultModel, n as getCorrectness, e as getPartialScore, a as model, s as normalize, t as normalizeSession, r as outcome, l as validate };
@@ -0,0 +1,209 @@
1
+ import { t as e } from "./layoutLimits-Bp17YP2V.js";
2
+ //#region src/controller/defaults.ts
3
+ var t = "{{blank}}", n = { model: {
4
+ prompt: "",
5
+ promptEnabled: !0,
6
+ interactionMode: "populate_blank",
7
+ layoutProfile: "",
8
+ choiceLayout: "",
9
+ layoutProfilePresets: {},
10
+ layoutLimits: { ...e },
11
+ audioButtonSkin: null,
12
+ audioButtonSkinsByLocale: {},
13
+ sentenceHtml: "",
14
+ template: "",
15
+ choiceMode: "text",
16
+ choices: [],
17
+ choiceGroupLabel: "",
18
+ correctChoiceId: "",
19
+ hasAudio: !1,
20
+ autoplayAudioEnabled: !1,
21
+ completeAudioEnabled: !1,
22
+ audioUrl: "",
23
+ audioTranscript: "",
24
+ locale: "",
25
+ teacherInstructions: "",
26
+ teacherInstructionsEnabled: !0
27
+ } }, r = {
28
+ model: {
29
+ ...n.model,
30
+ prompt: "<p><strong>Demo prompt</strong></p>",
31
+ template: `<p>The answer is ${t}.</p>`,
32
+ choices: [
33
+ {
34
+ id: "c1",
35
+ labelHtml: "<p>Option A</p>"
36
+ },
37
+ {
38
+ id: "c2",
39
+ labelHtml: "<p>Option B</p>"
40
+ },
41
+ {
42
+ id: "c3",
43
+ labelHtml: "<p>Option C</p>"
44
+ }
45
+ ],
46
+ correctChoiceId: "c2"
47
+ },
48
+ configuration: { prompt: {
49
+ label: "Prompt",
50
+ settings: !0
51
+ } }
52
+ }, i = (e) => !!e && typeof e == "object" && !Array.isArray(e) && Object.keys(e).length === 0;
53
+ function a(e) {
54
+ return e ? (e.match(/\{\{blank\}\}/g) || []).length : 0;
55
+ }
56
+ var o = (e, t) => {
57
+ if (!t?.choiceId) return "unanswered";
58
+ let n = e?.correctChoiceId || "";
59
+ return t.choiceId === n ? "correct" : "incorrect";
60
+ }, s = (e, t) => +(o(e, t) === "correct"), c = (e, t, n) => new Promise((r) => {
61
+ if (!t || i(t)) {
62
+ r({
63
+ score: 0,
64
+ empty: !0,
65
+ traceLog: ["Student did not select any answers. Score is 0."]
66
+ });
67
+ return;
68
+ }
69
+ t = f(t);
70
+ let a = d(e);
71
+ if (o(a, t) === "unanswered") {
72
+ r({
73
+ score: 0,
74
+ empty: !0,
75
+ traceLog: ["Student did not select any answers. Score is 0."]
76
+ });
77
+ return;
78
+ }
79
+ let c = s(a, t);
80
+ r({
81
+ score: c,
82
+ empty: !1,
83
+ traceLog: [
84
+ `Mode: ${n?.mode || "unknown"}.`,
85
+ `Student selected choice: ${t.choiceId}.`,
86
+ `Correct choice: ${a.correctChoiceId || "none"}.`,
87
+ `Final score: ${c}.`
88
+ ]
89
+ });
90
+ }), l = (t, n = {}) => ({
91
+ ...t,
92
+ ...n,
93
+ layoutLimits: {
94
+ ...e,
95
+ ...n?.layoutLimits || {}
96
+ }
97
+ }), u = (e = {}) => l(r.model, e), d = (e = {}) => {
98
+ let { shuffle: t, ...r } = e || {};
99
+ return {
100
+ ...l(n.model, r),
101
+ lockChoiceOrder: typeof r.lockChoiceOrder == "boolean" ? r.lockChoiceOrder : t !== !0
102
+ };
103
+ }, f = (e) => ({ ...e }), p = (e, t) => e?.lockChoiceOrder || t?.["@pie-element"]?.lockChoiceOrder ? !0 : t?.role === "instructor";
104
+ function m(e) {
105
+ let t = [...e];
106
+ for (let e = t.length - 1; e > 0; e--) {
107
+ let n = Math.floor(Math.random() * (e + 1));
108
+ [t[e], t[n]] = [t[n], t[e]];
109
+ }
110
+ return t;
111
+ }
112
+ var h = ({ id: e, labelHtml: t, imageUrl: n, imageAlt: r }) => ({
113
+ id: e,
114
+ ...t === void 0 ? {} : { labelHtml: t },
115
+ ...n === void 0 ? {} : { imageUrl: n },
116
+ ...r === void 0 ? {} : { imageAlt: r }
117
+ }), g = (e) => Array.isArray(e?.data?.shuffledValues) ? e.data.shuffledValues : Array.isArray(e?.shuffledValues) ? e.shuffledValues : [], _ = (e, t, n) => {
118
+ let r = t.map((t) => e.find((e) => e?.[n] === t)).filter((e) => !!e);
119
+ if (r.length === e.length) return r;
120
+ let i = new Set(r.map((e) => e[n])), a = e.filter((e) => !i.has(e?.[n]));
121
+ return [...r, ...a];
122
+ }, v = async (e, t, n, r) => {
123
+ let i = Array.isArray(e?.choices) ? [...e.choices] : [];
124
+ if (!i.length || p(e, n || {})) return i;
125
+ let a = g(t);
126
+ if (a.length) return _(i, a, "id");
127
+ let o = m(i);
128
+ if (r && typeof r == "function" && t?.id && t?.element) {
129
+ let e = o.map((e) => e?.id).filter(Boolean);
130
+ e.length && await r(t.id, t.element, { shuffledValues: e });
131
+ }
132
+ return o;
133
+ }, y = async (t, n, r, i) => {
134
+ let a = n || {}, s = r || {}, c = d(t), l = (await v(c, a, s, i)).filter((e) => !!e && typeof e == "object").map(h), u = {
135
+ prompt: c.promptEnabled ? c.prompt : null,
136
+ interactionMode: c.interactionMode || "populate_blank",
137
+ layoutProfile: c.layoutProfile || "",
138
+ choiceLayout: c.choiceLayout || "",
139
+ layoutProfilePresets: c.layoutProfilePresets && typeof c.layoutProfilePresets == "object" ? c.layoutProfilePresets : {},
140
+ layoutLimits: c.layoutLimits || { ...e },
141
+ audioButtonSkin: c.audioButtonSkin && typeof c.audioButtonSkin == "object" ? c.audioButtonSkin : null,
142
+ audioButtonSkinsByLocale: c.audioButtonSkinsByLocale && typeof c.audioButtonSkinsByLocale == "object" ? c.audioButtonSkinsByLocale : {},
143
+ sentenceHtml: c.sentenceHtml || null,
144
+ template: c.template,
145
+ choiceMode: c.choiceMode,
146
+ choices: l,
147
+ choiceGroupLabel: c.choiceGroupLabel || "",
148
+ hasAudio: c.hasAudio,
149
+ autoplayAudioEnabled: !!c.autoplayAudioEnabled,
150
+ completeAudioEnabled: !!c.completeAudioEnabled,
151
+ audioUrl: c.hasAudio ? c.audioUrl : null,
152
+ audioTranscript: c.hasAudio ? c.audioTranscript : null,
153
+ customType: c.customType || "",
154
+ useFeatureButtonAudio: typeof c.useFeatureButtonAudio == "boolean" ? c.useFeatureButtonAudio : void 0,
155
+ locale: c.locale || "",
156
+ language: c.language || c.locale || void 0,
157
+ disabled: s.mode !== "gather",
158
+ mode: s.mode
159
+ };
160
+ if (s.mode === "evaluate") {
161
+ let e = o(c, a);
162
+ u.correctness = e, u.responseCorrect = e === "correct", u.correctChoiceId = c.correctChoiceId;
163
+ }
164
+ return s.role === "instructor" && (s.mode === "view" || s.mode === "evaluate") ? u.teacherInstructions = c.teacherInstructionsEnabled ? c.teacherInstructions : null : u.teacherInstructions = null, u;
165
+ }, b = (e, t) => new Promise((n) => {
166
+ t.mode !== "evaluate" && t.role === "instructor" ? n({
167
+ id: "1",
168
+ choiceId: e?.correctChoiceId || ""
169
+ }) : n(null);
170
+ }), x = (e) => (e || "").replace(/(<(?!img|iframe|source)([^>]+)>)/gi, "").trim(), S = (e = {}, n = {}) => {
171
+ let r = {}, { minAnswerChoices: i = 2, maxAnswerChoices: o } = n;
172
+ (e.promptEnabled || n.prompt?.required) && !x(e.prompt) && (r.prompt = "This field is required."), n.teacherInstructions?.required && !x(e.teacherInstructions) && (r.teacherInstructions = "This field is required.");
173
+ let s = e.interactionMode || "populate_blank", c = a(e.template || "");
174
+ s === "audio_mc_only" ? c > 0 && (r.template = `Template cannot contain ${t} in audio-only mode`) : s === "populate_blank" ? c === 0 ? r.template = `Template must contain exactly one ${t} placeholder` : c > 1 && (r.template = `Template must contain only one ${t} placeholder`) : r.interactionMode = "Unknown interaction mode";
175
+ let l = Array.isArray(e.choices) ? e.choices : [];
176
+ l.length < i ? r.answerChoices = `There should be at least ${i} choices defined.` : o != null && l.length > o && (r.answerChoices = `No more than ${o} choices should be defined.`);
177
+ let u = e.choiceMode || "text", d = {}, f = /* @__PURE__ */ new Set(), p = /* @__PURE__ */ new Set();
178
+ l.forEach((e, t) => {
179
+ let n = e?.id || String(t);
180
+ if (!e?.id) {
181
+ d[n] = "Choice needs an id.";
182
+ return;
183
+ }
184
+ if (f.has(e.id)) {
185
+ d[n] = "Choice id should be unique.";
186
+ return;
187
+ }
188
+ if (f.add(e.id), u === "text") {
189
+ let t = x(e.labelHtml);
190
+ t ? p.has(t) && (d[n] = "Content should be unique.") : d[n] = "Content should not be empty.", p.add(t);
191
+ } else e.imageUrl?.trim() ? e.imageAlt?.trim() || (d[n] = "Image alt text is required.") : d[n] = "An image is required.";
192
+ }), Object.keys(d).length && (r.choices = d);
193
+ let m = e.correctChoiceId;
194
+ m ? l.some((e) => e?.id === m) || (r.correctResponse = "The correct response must be one of the choices.") : r.correctResponse = "No correct response defined.", e.hasAudio && (e.audioUrl?.trim() || (r.audioUrl = "A playable audio URL is required when audio is enabled"));
195
+ let h = e?.layoutLimits;
196
+ if (h && typeof h == "object") for (let e of /* @__PURE__ */ "blankStandaloneWidthRem.blankWideWidthRem.blankUnderlineWidthPx.blankUnderlineWideWidthPx.horizontalChoiceWidthPx.horizontalChoiceWidthVw.horizontalChoiceTileMinHeightRem.horizontalChoiceContentMinHeightRem.choiceImageMaxHeightRem.choiceImageMaxWidthRem.listenButtonSizePx.stimulusMinColumnPx.textMinColumnPx.legendMaxChars.choiceGroupGapRem.choiceRowGapRem.toggleButtonGapRem.horizontalChoiceRadioTopMarginRem.audioBlankTemplateMarginTopRem.audioBlankTemplateMarginBottomRem.audioInstructionsMaxWidthPx.narrowHorizontalChoiceMaxWidthPx.stimulusGridColumnGapRem.stimulusGridRowGapRem.stimulusSentenceMarginTopRem.stimulusChoicesMarginTopRem.tokenGridColumnGapRem.tokenGridRowGapRem.tokenTemplateMarginTopRem.tokenInlineTokenGapRem.tokenChoicesMarginTopRem.inlineGridColumnGapRem.inlineGridRowGapRem.inlineTemplateMarginTopRem.inlineChoicesMarginTopRem".split(".")) {
197
+ if (h[e] === void 0 || h[e] === null) continue;
198
+ let t = Number(h[e]);
199
+ if (!Number.isFinite(t) || t <= 0) {
200
+ r.layoutLimits = `${e} must be a positive number when provided`;
201
+ break;
202
+ }
203
+ }
204
+ return r;
205
+ };
206
+ //#endregion
207
+ export { s as a, f as c, o as i, c as l, b as n, y as o, u as r, d as s, a as t, S as u };
208
+
209
+ //# sourceMappingURL=controller-D_ITRCYG.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller-D_ITRCYG.js","names":[],"sources":["../../src/controller/defaults.ts","../../src/author/defaults.ts","../../src/controller/index.ts"],"sourcesContent":["import { DEFAULT_LAYOUT_LIMITS } from '../shared/layoutLimits';\n\nexport { DEFAULT_LAYOUT_LIMITS };\n\n/** Token authors must include exactly once in `template` (HTML). */\nexport const BLANK_TOKEN = '{{blank}}';\n\n/**\n * The values `normalize` fills in for fields an item leaves out. They carry no\n * content and no `id` or `element`: those come from the item config, and a\n * default here would stand in for a field the author never set.\n */\nexport default {\n model: {\n prompt: '',\n promptEnabled: true,\n interactionMode: 'populate_blank' as const,\n layoutProfile: '',\n choiceLayout: '',\n layoutProfilePresets: {},\n layoutLimits: { ...DEFAULT_LAYOUT_LIMITS },\n audioButtonSkin: null,\n audioButtonSkinsByLocale: {},\n sentenceHtml: '',\n template: '',\n choiceMode: 'text' as const,\n choices: [],\n choiceGroupLabel: '',\n correctChoiceId: '',\n hasAudio: false,\n autoplayAudioEnabled: false,\n completeAudioEnabled: false,\n audioUrl: '',\n audioTranscript: '',\n locale: '',\n teacherInstructions: '',\n teacherInstructionsEnabled: true,\n },\n};\n","import controllerDefaults, { BLANK_TOKEN } from '../controller/defaults';\n\n/** The model a new item starts from: a valid question an author edits in place. */\nexport default {\n model: {\n ...controllerDefaults.model,\n prompt: '<p><strong>Demo prompt</strong></p>',\n template: `<p>The answer is ${BLANK_TOKEN}.</p>`,\n choices: [\n { id: 'c1', labelHtml: '<p>Option A</p>' },\n { id: 'c2', labelHtml: '<p>Option B</p>' },\n { id: 'c3', labelHtml: '<p>Option C</p>' },\n ],\n correctChoiceId: 'c2',\n },\n configuration: {\n prompt: {\n label: 'Prompt',\n settings: true,\n },\n },\n};\n","import authorDefaults from '../author/defaults';\nimport defaults, { BLANK_TOKEN, DEFAULT_LAYOUT_LIMITS } from './defaults';\nimport type {\n McpbChoice,\n McpbQuestion,\n McpbSession,\n McpbEnv,\n McpbCorrectness,\n} from '../shared/types';\n\nconst isEmptyObject = (value: unknown): boolean =>\n !!value &&\n typeof value === 'object' &&\n !Array.isArray(value) &&\n Object.keys(value as Record<string, unknown>).length === 0;\n\nexport function countBlankTokens(template: string): number {\n if (!template) return 0;\n const re = /\\{\\{blank\\}\\}/g;\n return (template.match(re) || []).length;\n}\n\nexport const getCorrectness = (question: McpbQuestion, session: McpbSession): McpbCorrectness => {\n if (!session?.choiceId) {\n return 'unanswered';\n }\n const correct = question?.correctChoiceId || '';\n if (session.choiceId === correct) {\n return 'correct';\n }\n return 'incorrect';\n};\n\n/** One blank, one key: an answered session scores 1 only when it picked the key. */\nexport const getPartialScore = (question: McpbQuestion, session: McpbSession) =>\n getCorrectness(question, session) === 'correct' ? 1 : 0;\n\nexport const outcome = (question: McpbQuestion, session: McpbSession, env: McpbEnv) =>\n new Promise((resolve) => {\n if (!session || isEmptyObject(session)) {\n resolve({\n score: 0,\n empty: true,\n traceLog: ['Student did not select any answers. Score is 0.'],\n });\n return;\n }\n\n session = normalizeSession(session);\n const normalizedQuestion = normalize(question);\n const correctness = getCorrectness(normalizedQuestion, session);\n\n if (correctness === 'unanswered') {\n resolve({\n score: 0,\n empty: true,\n traceLog: ['Student did not select any answers. Score is 0.'],\n });\n return;\n }\n\n const score = getPartialScore(normalizedQuestion, session);\n const traceLog = [\n `Mode: ${env?.mode || 'unknown'}.`,\n `Student selected choice: ${session.choiceId}.`,\n `Correct choice: ${normalizedQuestion.correctChoiceId || 'none'}.`,\n `Final score: ${score}.`,\n ];\n resolve({ score, empty: false, traceLog });\n });\n\nconst withDefaults = (base: McpbQuestion, model: McpbQuestion = {}) => ({\n ...base,\n ...model,\n layoutLimits: {\n ...DEFAULT_LAYOUT_LIMITS,\n ...(model?.layoutLimits || {}),\n },\n});\n\n/** The authoring starting point: a question that passes `validate()` as it stands. */\nexport const createDefaultModel = (model: McpbQuestion = {}) =>\n withDefaults(authorDefaults.model, model);\n\n/**\n * What `model()` and `outcome()` read: the item's own fields, with neutral\n * values for the rest. Starter content here would reach a learner as the\n * item's prompt or choices.\n */\nexport const normalize = (question: McpbQuestion = {}) => {\n const { shuffle, ...rest } = question || {};\n return {\n ...withDefaults(defaults.model, rest),\n // `lockChoiceOrder` alone decides the order, as in multiple-choice. Older items\n // spell an unlocked order `shuffle: true`, which counts only when it is unset.\n lockChoiceOrder:\n typeof rest.lockChoiceOrder === 'boolean' ? rest.lockChoiceOrder : shuffle !== true,\n };\n};\n\nexport const normalizeSession = (s: McpbSession): McpbSession => ({ ...s });\n\nconst shouldLockChoices = (question: McpbQuestion, env: McpbEnv) => {\n if (question?.lockChoiceOrder) return true;\n if (env?.['@pie-element']?.lockChoiceOrder) return true;\n return env?.role === 'instructor';\n};\n\nfunction shuffleArray<T>(items: T[]): T[] {\n const out = [...items];\n for (let i = out.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n [out[i], out[j]] = [out[j], out[i]];\n }\n return out;\n}\n\n/**\n * The fields delivery renders. An imported choice can carry more, such as a\n * correctness flag or feedback, which must not reach a learner's browser.\n */\nconst toDeliveryChoice = ({ id, labelHtml, imageUrl, imageAlt }: McpbChoice): McpbChoice => ({\n id,\n ...(labelHtml !== undefined ? { labelHtml } : {}),\n ...(imageUrl !== undefined ? { imageUrl } : {}),\n ...(imageAlt !== undefined ? { imageAlt } : {}),\n});\n\nconst getStoredShuffle = (session: McpbSession): string[] =>\n Array.isArray(session?.data?.shuffledValues)\n ? session.data.shuffledValues\n : Array.isArray(session?.shuffledValues)\n ? session.shuffledValues\n : [];\n\nconst applyShuffledValues = (\n choices: McpbChoice[],\n shuffledValues: string[],\n choiceKey: keyof McpbChoice\n) => {\n const orderedChoices = shuffledValues\n .map((value) => choices.find((choice) => choice?.[choiceKey] === value))\n .filter((c): c is McpbChoice => !!c);\n\n if (orderedChoices.length === choices.length) {\n return orderedChoices;\n }\n\n const orderedValues = new Set(orderedChoices.map((choice) => choice[choiceKey]));\n const leftovers = choices.filter((choice) => !orderedValues.has(choice?.[choiceKey]));\n return [...orderedChoices, ...leftovers];\n};\n\ntype UpdateSessionFn = (\n id: string,\n element: string,\n data: { shuffledValues: string[] }\n) => Promise<void>;\n\nconst getOrderedChoices = async (\n question: McpbQuestion,\n session: McpbSession,\n env: McpbEnv,\n updateSession?: UpdateSessionFn\n) => {\n const choices = Array.isArray(question?.choices) ? [...question.choices] : [];\n if (!choices.length || shouldLockChoices(question, env || {})) {\n return choices;\n }\n\n const shuffledValues = getStoredShuffle(session);\n if (shuffledValues.length) {\n return applyShuffledValues(choices, shuffledValues, 'id');\n }\n\n const shuffledChoices = shuffleArray(choices);\n\n if (updateSession && typeof updateSession === 'function' && session?.id && session?.element) {\n const shuffledIds = shuffledChoices.map((choice) => choice?.id).filter(Boolean);\n if (shuffledIds.length) {\n await updateSession(session.id, session.element, { shuffledValues: shuffledIds });\n }\n }\n\n return shuffledChoices;\n};\n\nexport const model = async (\n question: McpbQuestion,\n session: McpbSession | null,\n env: McpbEnv | null,\n updateSession?: UpdateSessionFn\n) => {\n const safeSession: McpbSession = session || {};\n const safeEnv: McpbEnv = env || {};\n const normalizedQuestion = normalize(question);\n const choices = (await getOrderedChoices(normalizedQuestion, safeSession, safeEnv, updateSession))\n .filter((c): c is McpbChoice => !!c && typeof c === 'object')\n .map(toDeliveryChoice);\n\n const out: Record<string, unknown> = {\n prompt: normalizedQuestion.promptEnabled ? normalizedQuestion.prompt : null,\n interactionMode: normalizedQuestion.interactionMode || 'populate_blank',\n layoutProfile: normalizedQuestion.layoutProfile || '',\n choiceLayout: normalizedQuestion.choiceLayout || '',\n layoutProfilePresets:\n normalizedQuestion.layoutProfilePresets &&\n typeof normalizedQuestion.layoutProfilePresets === 'object'\n ? normalizedQuestion.layoutProfilePresets\n : {},\n layoutLimits: normalizedQuestion.layoutLimits || { ...DEFAULT_LAYOUT_LIMITS },\n audioButtonSkin:\n normalizedQuestion.audioButtonSkin && typeof normalizedQuestion.audioButtonSkin === 'object'\n ? normalizedQuestion.audioButtonSkin\n : null,\n audioButtonSkinsByLocale:\n normalizedQuestion.audioButtonSkinsByLocale &&\n typeof normalizedQuestion.audioButtonSkinsByLocale === 'object'\n ? normalizedQuestion.audioButtonSkinsByLocale\n : {},\n sentenceHtml: normalizedQuestion.sentenceHtml || null,\n template: normalizedQuestion.template,\n choiceMode: normalizedQuestion.choiceMode,\n choices,\n choiceGroupLabel: normalizedQuestion.choiceGroupLabel || '',\n hasAudio: normalizedQuestion.hasAudio,\n autoplayAudioEnabled: !!normalizedQuestion.autoplayAudioEnabled,\n completeAudioEnabled: !!normalizedQuestion.completeAudioEnabled,\n audioUrl: normalizedQuestion.hasAudio ? normalizedQuestion.audioUrl : null,\n audioTranscript: normalizedQuestion.hasAudio ? normalizedQuestion.audioTranscript : null,\n customType: normalizedQuestion.customType || '',\n useFeatureButtonAudio:\n typeof normalizedQuestion.useFeatureButtonAudio === 'boolean'\n ? normalizedQuestion.useFeatureButtonAudio\n : undefined,\n locale: normalizedQuestion.locale || '',\n language: normalizedQuestion.language || normalizedQuestion.locale || undefined,\n disabled: safeEnv.mode !== 'gather',\n mode: safeEnv.mode,\n };\n\n if (safeEnv.mode === 'evaluate') {\n const correctness = getCorrectness(normalizedQuestion, safeSession);\n out.correctness = correctness;\n out.responseCorrect = correctness === 'correct';\n out.correctChoiceId = normalizedQuestion.correctChoiceId;\n }\n\n if (safeEnv.role === 'instructor' && (safeEnv.mode === 'view' || safeEnv.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 createCorrectResponseSession = (question: McpbQuestion, env: McpbEnv) => {\n return new Promise((resolve) => {\n if (env.mode !== 'evaluate' && env.role === 'instructor') {\n // The player sets `id` and `element` on the entry from the item config.\n resolve({\n id: '1',\n choiceId: question?.correctChoiceId || '',\n });\n } else {\n resolve(null);\n }\n });\n};\n\n/** Markup with its tags removed, keeping media an author can answer from. */\nconst getContent = (html?: string) =>\n (html || '').replace(/(<(?!img|iframe|source)([^>]+)>)/gi, '').trim();\n\ntype ValidateConfig = {\n minAnswerChoices?: number;\n maxAnswerChoices?: number;\n prompt?: { required?: boolean };\n teacherInstructions?: { required?: boolean };\n};\n\n/**\n * Authoring errors in multiple-choice's shape: a message per field, and under\n * `choices` a message per choice keyed by its id.\n */\nexport const validate = (question: McpbQuestion = {}, config: ValidateConfig = {}) => {\n const errors: Record<string, string | Record<string, string>> = {};\n const { minAnswerChoices = 2, maxAnswerChoices } = config;\n\n if ((question.promptEnabled || config.prompt?.required) && !getContent(question.prompt)) {\n errors.prompt = 'This field is required.';\n }\n\n if (config.teacherInstructions?.required && !getContent(question.teacherInstructions)) {\n errors.teacherInstructions = 'This field is required.';\n }\n\n const interactionMode = question.interactionMode || 'populate_blank';\n const template = question.template || '';\n const n = countBlankTokens(template);\n if (interactionMode === 'audio_mc_only') {\n if (n > 0) {\n errors.template = `Template cannot contain ${BLANK_TOKEN} in audio-only mode`;\n }\n } else if (interactionMode === 'populate_blank') {\n if (n === 0) {\n errors.template = `Template must contain exactly one ${BLANK_TOKEN} placeholder`;\n } else if (n > 1) {\n errors.template = `Template must contain only one ${BLANK_TOKEN} placeholder`;\n }\n } else {\n errors.interactionMode = 'Unknown interaction mode';\n }\n\n const choices = Array.isArray(question.choices) ? question.choices : [];\n if (choices.length < minAnswerChoices) {\n errors.answerChoices = `There should be at least ${minAnswerChoices} choices defined.`;\n } else if (maxAnswerChoices != null && choices.length > maxAnswerChoices) {\n errors.answerChoices = `No more than ${maxAnswerChoices} choices should be defined.`;\n }\n\n const mode = question.choiceMode || 'text';\n const choicesErrors: Record<string, string> = {};\n const seenIds = new Set<string>();\n const seenLabels = new Set<string>();\n choices.forEach((c, i) => {\n const key = c?.id || String(i);\n if (!c?.id) {\n choicesErrors[key] = 'Choice needs an id.';\n return;\n }\n // The session stores the picked id, so two choices sharing one cannot be told apart.\n if (seenIds.has(c.id)) {\n choicesErrors[key] = 'Choice id should be unique.';\n return;\n }\n seenIds.add(c.id);\n if (mode === 'text') {\n const label = getContent(c.labelHtml);\n if (!label) {\n choicesErrors[key] = 'Content should not be empty.';\n } else if (seenLabels.has(label)) {\n choicesErrors[key] = 'Content should be unique.';\n }\n seenLabels.add(label);\n } else if (!c.imageUrl?.trim()) {\n choicesErrors[key] = 'An image is required.';\n } else if (!c.imageAlt?.trim()) {\n choicesErrors[key] = 'Image alt text is required.';\n }\n });\n if (Object.keys(choicesErrors).length) {\n errors.choices = choicesErrors;\n }\n\n const correct = question.correctChoiceId;\n if (!correct) {\n errors.correctResponse = 'No correct response defined.';\n } else if (!choices.some((c) => c?.id === correct)) {\n errors.correctResponse = 'The correct response must be one of the choices.';\n }\n\n if (question.hasAudio) {\n const hasAudioUrl = !!question.audioUrl?.trim();\n if (!hasAudioUrl) {\n errors.audioUrl = 'A playable audio URL is required when audio is enabled';\n }\n }\n\n const limits = question?.layoutLimits;\n if (limits && typeof limits === 'object') {\n const numericLimitKeys = [\n 'blankStandaloneWidthRem',\n 'blankWideWidthRem',\n 'blankUnderlineWidthPx',\n 'blankUnderlineWideWidthPx',\n 'horizontalChoiceWidthPx',\n 'horizontalChoiceWidthVw',\n 'horizontalChoiceTileMinHeightRem',\n 'horizontalChoiceContentMinHeightRem',\n 'choiceImageMaxHeightRem',\n 'choiceImageMaxWidthRem',\n 'listenButtonSizePx',\n 'stimulusMinColumnPx',\n 'textMinColumnPx',\n 'legendMaxChars',\n 'choiceGroupGapRem',\n 'choiceRowGapRem',\n 'toggleButtonGapRem',\n 'horizontalChoiceRadioTopMarginRem',\n 'audioBlankTemplateMarginTopRem',\n 'audioBlankTemplateMarginBottomRem',\n 'audioInstructionsMaxWidthPx',\n 'narrowHorizontalChoiceMaxWidthPx',\n 'stimulusGridColumnGapRem',\n 'stimulusGridRowGapRem',\n 'stimulusSentenceMarginTopRem',\n 'stimulusChoicesMarginTopRem',\n 'tokenGridColumnGapRem',\n 'tokenGridRowGapRem',\n 'tokenTemplateMarginTopRem',\n 'tokenInlineTokenGapRem',\n 'tokenChoicesMarginTopRem',\n 'inlineGridColumnGapRem',\n 'inlineGridRowGapRem',\n 'inlineTemplateMarginTopRem',\n 'inlineChoicesMarginTopRem',\n ] as const;\n for (const key of numericLimitKeys) {\n if (limits[key] === undefined || limits[key] === null) continue;\n const value = Number(limits[key]);\n if (!Number.isFinite(value) || value <= 0) {\n errors.layoutLimits = `${key} must be a positive number when provided`;\n break;\n }\n }\n }\n\n return errors;\n};\n"],"mappings":";;AAKA,IAAa,IAAc,aAO3B,IAAe,EACb,OAAO;CACL,QAAQ;CACR,eAAe;CACf,iBAAiB;CACjB,eAAe;CACf,cAAc;CACd,sBAAsB,CAAC;CACvB,cAAc,EAAE,GAAG,EAAsB;CACzC,iBAAiB;CACjB,0BAA0B,CAAC;CAC3B,cAAc;CACd,UAAU;CACV,YAAY;CACZ,SAAS,CAAC;CACV,kBAAkB;CAClB,iBAAiB;CACjB,UAAU;CACV,sBAAsB;CACtB,sBAAsB;CACtB,UAAU;CACV,iBAAiB;CACjB,QAAQ;CACR,qBAAqB;CACrB,4BAA4B;AAC9B,EACF,GCnCA,IAAe;CACb,OAAO;EACL,GAAG,EAAmB;EACtB,QAAQ;EACR,UAAU,oBAAoB,EAAY;EAC1C,SAAS;GACP;IAAE,IAAI;IAAM,WAAW;GAAkB;GACzC;IAAE,IAAI;IAAM,WAAW;GAAkB;GACzC;IAAE,IAAI;IAAM,WAAW;GAAkB;EAC3C;EACA,iBAAiB;CACnB;CACA,eAAe,EACb,QAAQ;EACN,OAAO;EACP,UAAU;CACZ,EACF;AACF,GCXM,KAAiB,MACrB,CAAC,CAAC,KACF,OAAO,KAAU,YACjB,CAAC,MAAM,QAAQ,CAAK,KACpB,OAAO,KAAK,CAAgC,CAAC,CAAC,WAAW;AAE3D,SAAgB,EAAiB,GAA0B;CAGzD,OAFK,KAEG,EAAS,MAAM,gBAAE,KAAK,CAAC,EAAA,CAAG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B,EAAO,kBAAkB,gCAKvB,EAAS,aACW,EAAS,UAAU,KAAK,MAE5C,EAAO,WAAW;CAItB,IAAM,IAAS,GAAU;CACzB,IAAI,KAAU,OAAO,KAAW,UAsC9B,KAAK,IAAM,KAAO,+2BAAA,GAAkB;EAClC,IAAI,EAAO,OAAS,KAAA,KAAa,EAAO,OAAS,MAAM;EACvD,IAAM,IAAQ,OAAO,EAAO,EAAI;EAChC,IAAI,CAAC,OAAO,SAAS,CAAK,KAAK,KAAS,GAAG;GACzC,EAAO,eAAe,GAAG,EAAI;GAC7B;EACF;CACF;CAGF,OAAO;AACT"}
@@ -0,0 +1,124 @@
1
+ import { t as e } from "../McPopulatedBlank-DbmR6UWn.js";
2
+ //#region ../../lib-svelte/delivery-events/dist/index2.js
3
+ function t(e) {
4
+ return !!e && typeof e == "object" && !Array.isArray(e);
5
+ }
6
+ function n(e, n) {
7
+ if (e === n) return e;
8
+ if (!t(e) || !t(n) || Object.isFrozen(e) || !Object.isExtensible(e)) return n;
9
+ try {
10
+ for (let t of Object.keys(e)) t in n || delete e[t];
11
+ Object.assign(e, n);
12
+ } catch {
13
+ return n;
14
+ }
15
+ return e;
16
+ }
17
+ //#endregion
18
+ //#region ../../shared/player-events/dist/index.js
19
+ var r = class e extends CustomEvent {
20
+ static {
21
+ this.TYPE = "model-set";
22
+ }
23
+ constructor(t, n, r) {
24
+ super(e.TYPE, {
25
+ bubbles: !0,
26
+ composed: !0,
27
+ detail: {
28
+ complete: n,
29
+ component: t,
30
+ hasModel: r
31
+ }
32
+ }), this.component = t, this.complete = n;
33
+ }
34
+ }, i = class e extends CustomEvent {
35
+ static {
36
+ this.TYPE = "session-changed";
37
+ }
38
+ constructor(t, n) {
39
+ super(e.TYPE, {
40
+ bubbles: !0,
41
+ composed: !0,
42
+ detail: {
43
+ complete: n,
44
+ component: t
45
+ }
46
+ }), this.component = t, this.complete = n;
47
+ }
48
+ };
49
+ //#endregion
50
+ //#region ../../lib-svelte/delivery-events/dist/index3.js
51
+ function a(e, t) {
52
+ let a = e.element;
53
+ if (!a) throw TypeError("defineDeliveryElement: the component was not compiled with `customElement`");
54
+ class o extends a {
55
+ #e;
56
+ #t;
57
+ constructor() {
58
+ super(), this.onSessionChange = (e) => {
59
+ this.writeSession(e), this.dispatchSessionChanged();
60
+ };
61
+ }
62
+ set model(e) {
63
+ this.#e = e, super.model = e, queueMicrotask(() => {
64
+ this.dispatchEvent(new r(this.tagName.toLowerCase(), this.isComplete(), this.#e !== void 0));
65
+ });
66
+ }
67
+ get model() {
68
+ return this.#e;
69
+ }
70
+ set session(e) {
71
+ this.#t = e, super.session = e, this.dispatchSessionChanged();
72
+ }
73
+ get session() {
74
+ return this.#t;
75
+ }
76
+ isComplete() {
77
+ return t.isComplete(this.#e, this.#t);
78
+ }
79
+ writeSession(e) {
80
+ this.#t = n(this.#t, e), super.session = e;
81
+ }
82
+ dispatchSessionChanged() {
83
+ this.dispatchEvent(new i(this.tagName.toLowerCase(), this.isComplete()));
84
+ }
85
+ }
86
+ return o;
87
+ }
88
+ //#endregion
89
+ //#region src/delivery/index.ts
90
+ var o = a(e, { isComplete: (e, t) => !!t?.choiceId });
91
+ function s(e) {
92
+ return !!e?.autoplayAudioEnabled && !!e?.completeAudioEnabled && !!e?.hasAudio;
93
+ }
94
+ var c = class extends o {
95
+ audioComplete = !1;
96
+ constructor() {
97
+ super(), this.onAudioStarted = () => {
98
+ this.#e({ audioStartTime: Date.now() });
99
+ }, this.onAudioEnded = () => {
100
+ this.audioComplete = !0, this.#e({ audioEndTime: Date.now() }), this.dispatchSessionChanged();
101
+ };
102
+ }
103
+ set model(e) {
104
+ e?.audioUrl !== this.model?.audioUrl && (this.audioComplete = !1), super.model = e;
105
+ }
106
+ get model() {
107
+ return super.model;
108
+ }
109
+ isComplete() {
110
+ return super.isComplete() && (this.audioComplete || !s(this.model));
111
+ }
112
+ #e(e) {
113
+ let t = this.session || {}, n = t.audioStartTime || e.audioStartTime, r = t.audioEndTime || e.audioEndTime, i = {
114
+ ...t,
115
+ ...n ? { audioStartTime: n } : {},
116
+ ...r ? { audioEndTime: r } : {}
117
+ };
118
+ !i.waitTime && n && r && (i.waitTime = r - n), this.writeSession(i);
119
+ }
120
+ };
121
+ //#endregion
122
+ export { c as default };
123
+
124
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["#e","t","#t","e","n","#writeAudioTiming"],"sources":["../../../../../lib-svelte/delivery-events/dist/index2.js","../../../../../shared/player-events/dist/index.js","../../../../../lib-svelte/delivery-events/dist/index3.js","../../../src/delivery/index.ts"],"sourcesContent":["//#region src/write-session-in-place.ts\nfunction e(e) {\n\treturn !!e && typeof e == \"object\" && !Array.isArray(e);\n}\nfunction t(t, n) {\n\tif (t === n) return t;\n\tif (!e(t) || !e(n) || Object.isFrozen(t) || !Object.isExtensible(t)) return n;\n\ttry {\n\t\tfor (let e of Object.keys(t)) e in n || delete t[e];\n\t\tObject.assign(t, n);\n\t} catch {\n\t\treturn n;\n\t}\n\treturn t;\n}\n//#endregion\nexport { t as writeSessionInPlace };\n","//#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","import { writeSessionInPlace as e } from \"./index2.js\";\nimport { ModelSetEvent as t, SessionChangedEvent as n } from \"@pie-element/shared-player-events\";\n//#region src/delivery-element.ts\nfunction r(r, i) {\n\tlet a = r.element;\n\tif (!a) throw TypeError(\"defineDeliveryElement: the component was not compiled with `customElement`\");\n\tclass o extends a {\n\t\t#e;\n\t\t#t;\n\t\tconstructor() {\n\t\t\tsuper(), this.onSessionChange = (e) => {\n\t\t\t\tthis.writeSession(e), this.dispatchSessionChanged();\n\t\t\t};\n\t\t}\n\t\tset model(e) {\n\t\t\tthis.#e = e, super.model = e, queueMicrotask(() => {\n\t\t\t\tthis.dispatchEvent(new t(this.tagName.toLowerCase(), this.isComplete(), this.#e !== void 0));\n\t\t\t});\n\t\t}\n\t\tget model() {\n\t\t\treturn this.#e;\n\t\t}\n\t\tset session(e) {\n\t\t\tthis.#t = e, super.session = e, this.dispatchSessionChanged();\n\t\t}\n\t\tget session() {\n\t\t\treturn this.#t;\n\t\t}\n\t\tisComplete() {\n\t\t\treturn i.isComplete(this.#e, this.#t);\n\t\t}\n\t\twriteSession(t) {\n\t\t\tthis.#t = e(this.#t, t), super.session = t;\n\t\t}\n\t\tdispatchSessionChanged() {\n\t\t\tthis.dispatchEvent(new n(this.tagName.toLowerCase(), this.isComplete()));\n\t\t}\n\t}\n\treturn o;\n}\n//#endregion\nexport { r as defineDeliveryElement };\n","import McPopulatedBlankComponent from './McPopulatedBlank.svelte';\nimport { defineDeliveryElement } from '@pie-lib/delivery-events-svelte';\nimport type { McpbQuestion, McpbSession } from '../shared/types.js';\n\nconst DeliveryElement = defineDeliveryElement<McpbQuestion, McpbSession>(\n McPopulatedBlankComponent,\n { isComplete: (_model, session) => !!session?.choiceId }\n);\n\n/** Autoplayed audio the learner must hear to the end before a pick counts as complete. */\nfunction requiresAudioCompletion(model: McpbQuestion | undefined): boolean {\n return !!model?.autoplayAudioEnabled && !!model?.completeAudioEnabled && !!model?.hasAudio;\n}\n\nclass McPopulatedBlankElement extends DeliveryElement {\n audioComplete = false;\n declare onAudioStarted: () => void;\n declare onAudioEnded: () => void;\n\n constructor() {\n super();\n this.onAudioStarted = () => {\n this.#writeAudioTiming({ audioStartTime: Date.now() });\n };\n this.onAudioEnded = () => {\n this.audioComplete = true;\n this.#writeAudioTiming({ audioEndTime: Date.now() });\n this.dispatchSessionChanged();\n };\n }\n\n set model(m: McpbQuestion | undefined) {\n // Autoplay re-fires only for a new `audioUrl`, so a re-set of the same\n // model must keep a finished playback counted.\n if (m?.audioUrl !== this.model?.audioUrl) this.audioComplete = false;\n super.model = m;\n }\n\n get model(): McpbQuestion | undefined {\n return super.model;\n }\n\n isComplete(): boolean {\n return super.isComplete() && (this.audioComplete || !requiresAudioCompletion(this.model));\n }\n\n /**\n * The first playback's timing, as multiple-choice's `updateSessionMetadata`\n * records it: a replay does not move either timestamp, and `waitTime` is set\n * once both exist. It reaches the component too, which builds the learner's\n * next pick from the session it renders.\n */\n #writeAudioTiming(timing: { audioStartTime?: number; audioEndTime?: number }) {\n const session: McpbSession = this.session || {};\n const audioStartTime = session.audioStartTime || timing.audioStartTime;\n const audioEndTime = session.audioEndTime || timing.audioEndTime;\n const next: McpbSession = {\n ...session,\n ...(audioStartTime ? { audioStartTime } : {}),\n ...(audioEndTime ? { audioEndTime } : {}),\n };\n if (!next.waitTime && audioStartTime && audioEndTime) {\n next.waitTime = audioEndTime - audioStartTime;\n }\n this.writeSession(next);\n }\n}\n\nexport default McPopulatedBlankElement;\n"],"mappings":";;AACA,SAAS,EAAE,GAAG;CACb,OAAO,CAAC,CAAC,KAAK,OAAO,KAAK,YAAY,CAAC,MAAM,QAAQ,CAAC;AACvD;AACA,SAAS,EAAE,GAAG,GAAG;CAChB,IAAI,MAAM,GAAG,OAAO;CACpB,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,OAAO,SAAS,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,GAAG,OAAO;CAC5E,IAAI;EACH,KAAK,IAAI,KAAK,OAAO,KAAK,CAAC,GAAG,KAAK,KAAK,OAAO,EAAE;EACjD,OAAO,OAAO,GAAG,CAAC;CACnB,QAAQ;EACP,OAAO;CACR;CACA,OAAO;AACR;;;ACuCA,IAAI,IAAI,M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42 @@
1
+ //#region src/shared/layoutLimits.ts
2
+ var e = {
3
+ blankStandaloneWidthRem: 7,
4
+ blankWideWidthRem: 10,
5
+ blankUnderlineWidthPx: 2,
6
+ blankUnderlineWideWidthPx: 4,
7
+ horizontalChoiceWidthPx: 170,
8
+ horizontalChoiceWidthVw: 30,
9
+ horizontalChoiceTileMinHeightRem: 11,
10
+ horizontalChoiceContentMinHeightRem: 7.5,
11
+ choiceImageMaxHeightRem: 9.375,
12
+ choiceImageMaxWidthRem: 9.375,
13
+ listenButtonSizePx: 128,
14
+ stimulusMinColumnPx: 210,
15
+ textMinColumnPx: 260,
16
+ legendMaxChars: 120,
17
+ choiceGroupGapRem: .5,
18
+ choiceRowGapRem: .5,
19
+ toggleButtonGapRem: .5,
20
+ horizontalChoiceRadioTopMarginRem: .5,
21
+ audioBlankTemplateMarginTopRem: .8,
22
+ audioBlankTemplateMarginBottomRem: 1.8,
23
+ audioInstructionsMaxWidthPx: 875,
24
+ narrowHorizontalChoiceMaxWidthPx: 230,
25
+ stimulusGridColumnGapRem: 2,
26
+ stimulusGridRowGapRem: .7,
27
+ stimulusSentenceMarginTopRem: .2,
28
+ stimulusChoicesMarginTopRem: .9,
29
+ tokenGridColumnGapRem: 1.5,
30
+ tokenGridRowGapRem: .8,
31
+ tokenTemplateMarginTopRem: .6,
32
+ tokenInlineTokenGapRem: .35,
33
+ tokenChoicesMarginTopRem: .2,
34
+ inlineGridColumnGapRem: 1.5,
35
+ inlineGridRowGapRem: .65,
36
+ inlineTemplateMarginTopRem: .45,
37
+ inlineChoicesMarginTopRem: .25
38
+ };
39
+ //#endregion
40
+ export { e as t };
41
+
42
+ //# sourceMappingURL=layoutLimits-Bp17YP2V.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"layoutLimits-Bp17YP2V.js","names":[],"sources":["../../src/shared/layoutLimits.ts"],"sourcesContent":["export type LayoutLimits = {\n blankStandaloneWidthRem: number;\n blankWideWidthRem: number;\n blankUnderlineWidthPx: number;\n blankUnderlineWideWidthPx: number;\n horizontalChoiceWidthPx: number;\n horizontalChoiceWidthVw: number;\n horizontalChoiceTileMinHeightRem: number;\n horizontalChoiceContentMinHeightRem: number;\n choiceImageMaxHeightRem: number;\n choiceImageMaxWidthRem: number;\n listenButtonSizePx: number;\n stimulusMinColumnPx: number;\n textMinColumnPx: number;\n legendMaxChars: number;\n choiceGroupGapRem: number;\n choiceRowGapRem: number;\n toggleButtonGapRem: number;\n horizontalChoiceRadioTopMarginRem: number;\n audioBlankTemplateMarginTopRem: number;\n audioBlankTemplateMarginBottomRem: number;\n audioInstructionsMaxWidthPx: number;\n narrowHorizontalChoiceMaxWidthPx: number;\n stimulusGridColumnGapRem: number;\n stimulusGridRowGapRem: number;\n stimulusSentenceMarginTopRem: number;\n stimulusChoicesMarginTopRem: number;\n tokenGridColumnGapRem: number;\n tokenGridRowGapRem: number;\n tokenTemplateMarginTopRem: number;\n tokenInlineTokenGapRem: number;\n tokenChoicesMarginTopRem: number;\n inlineGridColumnGapRem: number;\n inlineGridRowGapRem: number;\n inlineTemplateMarginTopRem: number;\n inlineChoicesMarginTopRem: number;\n};\n\n/** Baseline values tuned to match historical CQT visuals; override via model.layoutLimits. */\nexport const DEFAULT_LAYOUT_LIMITS: LayoutLimits = {\n blankStandaloneWidthRem: 7,\n blankWideWidthRem: 10,\n blankUnderlineWidthPx: 2,\n blankUnderlineWideWidthPx: 4,\n horizontalChoiceWidthPx: 170,\n horizontalChoiceWidthVw: 30,\n horizontalChoiceTileMinHeightRem: 11,\n horizontalChoiceContentMinHeightRem: 7.5,\n // 9.375rem = 150px at the standard 16px root font size — Learnosity graphic-choice\n // SVGs are authored at 150x150; images up to that size must render at full size.\n // Shared by the choice tile image and the selected-answer image inside the cloze\n // blank, so the same choice image always renders at the same size in both places.\n choiceImageMaxHeightRem: 9.375,\n choiceImageMaxWidthRem: 9.375,\n listenButtonSizePx: 128,\n stimulusMinColumnPx: 210,\n textMinColumnPx: 260,\n legendMaxChars: 120,\n choiceGroupGapRem: 0.5,\n choiceRowGapRem: 0.5,\n toggleButtonGapRem: 0.5,\n horizontalChoiceRadioTopMarginRem: 0.5,\n audioBlankTemplateMarginTopRem: 0.8,\n audioBlankTemplateMarginBottomRem: 1.8,\n audioInstructionsMaxWidthPx: 875,\n narrowHorizontalChoiceMaxWidthPx: 230,\n stimulusGridColumnGapRem: 2,\n stimulusGridRowGapRem: 0.7,\n stimulusSentenceMarginTopRem: 0.2,\n stimulusChoicesMarginTopRem: 0.9,\n tokenGridColumnGapRem: 1.5,\n tokenGridRowGapRem: 0.8,\n tokenTemplateMarginTopRem: 0.6,\n tokenInlineTokenGapRem: 0.35,\n tokenChoicesMarginTopRem: 0.2,\n inlineGridColumnGapRem: 1.5,\n inlineGridRowGapRem: 0.65,\n inlineTemplateMarginTopRem: 0.45,\n inlineChoicesMarginTopRem: 0.25,\n};\n"],"mappings":";AAuCA,IAAa,IAAsC;CACjD,yBAAyB;CACzB,mBAAmB;CACnB,uBAAuB;CACvB,2BAA2B;CAC3B,yBAAyB;CACzB,yBAAyB;CACzB,kCAAkC;CAClC,qCAAqC;CAKrC,yBAAyB;CACzB,wBAAwB;CACxB,oBAAoB;CACpB,qBAAqB;CACrB,iBAAiB;CACjB,gBAAgB;CAChB,mBAAmB;CACnB,iBAAiB;CACjB,oBAAoB;CACpB,mCAAmC;CACnC,gCAAgC;CAChC,mCAAmC;CACnC,6BAA6B;CAC7B,kCAAkC;CAClC,0BAA0B;CAC1B,uBAAuB;CACvB,8BAA8B;CAC9B,6BAA6B;CAC7B,uBAAuB;CACvB,oBAAoB;CACpB,2BAA2B;CAC3B,wBAAwB;CACxB,0BAA0B;CAC1B,wBAAwB;CACxB,qBAAqB;CACrB,4BAA4B;CAC5B,2BAA2B;AAC7B"}
@@ -0,0 +1,129 @@
1
+ import { A as e, C as t, D as n, E as r, F as i, N as a, P as o, S as s, T as c, _ as l, d as u, g as d, h as f, j as p, k as m, m as h, n as g, p as _, t as v, u as y, w as b, x } from "../client-CWh3mUUV.js";
2
+ import { n as S, t as C } from "../McPopulatedBlank-DbmR6UWn.js";
3
+ import { n as w, o as T } from "../controller-D_ITRCYG.js";
4
+ //#region src/print/preparePrint.ts
5
+ async function E(e, t) {
6
+ let n = {
7
+ mode: "view",
8
+ role: t
9
+ }, r = await T({
10
+ ...e,
11
+ lockChoiceOrder: !0
12
+ }, null, n), i = e.printAnswerKey === !1 ? null : await w(e, n), { teacherInstructions: a, audioUrl: o, audioTranscript: s, ...c } = r;
13
+ return {
14
+ model: {
15
+ ...c,
16
+ teacherInstructions: null,
17
+ hasAudio: !1
18
+ },
19
+ session: i,
20
+ teacherInstructions: String(a || ""),
21
+ audioUrl: String(o || ""),
22
+ audioTranscript: String(s || "")
23
+ };
24
+ }
25
+ //#endregion
26
+ //#region src/print/Print.svelte
27
+ var D = l("<div class=\"mpb-print-block mpb-print-teacher-instructions svelte-1fx5wwa\"></div>"), O = l("<div><strong> </strong> </div>"), k = l("<div class=\"mpb-print-block mpb-print-audio svelte-1fx5wwa\"><!> <!></div>"), A = l("<div class=\"mpb-print\"><!> <!> <!></div>"), j = {
28
+ hash: "svelte-1fx5wwa",
29
+ code: "\n /* Inset to line up with the delivery root's padding. */.mpb-print-block.svelte-1fx5wwa {padding:0 1rem;margin:1rem 0;}.mpb-print-teacher-instructions.svelte-1fx5wwa p {margin:0.5em 0;}.mpb-print-audio.svelte-1fx5wwa {font-size:0.875rem;line-height:1.25rem;}"
30
+ };
31
+ function M(l, v) {
32
+ o(v, !0), y(l, j);
33
+ let w = g(v, "model", 7, null), T = g(v, "options", 7, null), M = e(null);
34
+ t(() => {
35
+ let e = w(), t = T()?.role;
36
+ if (!e) {
37
+ m(M, null);
38
+ return;
39
+ }
40
+ let n = !0;
41
+ return E(e, t).then((e) => {
42
+ n && m(M, e, !0);
43
+ }), () => {
44
+ n = !1;
45
+ };
46
+ });
47
+ let N = (e) => S(e, x(M)?.model.language || void 0);
48
+ var P = {
49
+ get model() {
50
+ return w();
51
+ },
52
+ set model(e = null) {
53
+ w(e), p();
54
+ },
55
+ get options() {
56
+ return T();
57
+ },
58
+ set options(e = null) {
59
+ T(e), p();
60
+ }
61
+ }, F = d(), I = c(F), L = (e) => {
62
+ var t = A(), a = b(t), o = (e) => {
63
+ var t = D();
64
+ u(t, () => x(M).teacherInstructions, !0), i(t), f(e, t);
65
+ };
66
+ _(a, (e) => {
67
+ x(M).teacherInstructions && e(o);
68
+ });
69
+ var c = n(a, 2), l = (e) => {
70
+ var t = k(), a = b(t), o = (e) => {
71
+ var t = O(), a = b(t), o = r(a, !0), c = n(a);
72
+ i(t), s((e) => {
73
+ h(o, e), h(c, ` ${x(M).audioUrl ?? ""}`);
74
+ }, [() => N("printAudio")]), f(e, t);
75
+ };
76
+ _(a, (e) => {
77
+ x(M).audioUrl && e(o);
78
+ });
79
+ var c = n(a, 2), l = (e) => {
80
+ var t = O(), a = b(t), o = r(a, !0), c = n(a);
81
+ i(t), s((e) => {
82
+ h(o, e), h(c, ` ${x(M).audioTranscript ?? ""}`);
83
+ }, [() => N("printTranscript")]), f(e, t);
84
+ };
85
+ _(c, (e) => {
86
+ x(M).audioTranscript && e(l);
87
+ }), i(t), f(e, t);
88
+ };
89
+ _(c, (e) => {
90
+ (x(M).audioUrl || x(M).audioTranscript) && e(l);
91
+ }), C(n(c, 2), {
92
+ get model() {
93
+ return x(M).model;
94
+ },
95
+ get session() {
96
+ return x(M).session;
97
+ }
98
+ }), i(t), f(e, t);
99
+ };
100
+ return _(I, (e) => {
101
+ x(M) && e(L);
102
+ }), f(l, F), a(P);
103
+ }
104
+ v(M, {
105
+ model: { type: "Object" },
106
+ options: { type: "Object" }
107
+ }, [], []);
108
+ //#endregion
109
+ //#region src/print/index.ts
110
+ var N = M.element, P = class extends N {
111
+ _model = null;
112
+ _options = null;
113
+ set model(e) {
114
+ this._model = e, super.model = e;
115
+ }
116
+ get model() {
117
+ return this._model;
118
+ }
119
+ set options(e) {
120
+ this._options = e, super.options = e;
121
+ }
122
+ get options() {
123
+ return this._options;
124
+ }
125
+ };
126
+ //#endregion
127
+ export { P as default };
128
+
129
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/print/preparePrint.ts","../../../src/print/Print.svelte","../../../src/print/index.ts"],"sourcesContent":["import { createCorrectResponseSession, model as toViewModel } from '../controller';\nimport type { McpbQuestion, McpbRole, McpbSession } from '../shared/types';\n\nexport interface PrintView {\n model: Record<string, unknown>;\n session: McpbSession | null;\n teacherInstructions: string;\n audioUrl: string;\n audioTranscript: string;\n}\n\n/**\n * `pie-print` hands over the item's own model and `options.role`, so print asks\n * the controller for what a player shows that role in `view` mode, in the\n * authored choice order. An instructor's key is the correct-response session,\n * the same path a player shows it through; `printAnswerKey: false` withholds it.\n */\nexport async function preparePrint(\n question: McpbQuestion,\n role: McpbRole | undefined\n): Promise<PrintView> {\n const env = { mode: 'view' as const, role };\n const viewModel = await toViewModel({ ...question, lockChoiceOrder: true }, null, env);\n const key =\n question.printAnswerKey === false\n ? null\n : ((await createCorrectResponseSession(question, env)) as McpbSession | null);\n const { teacherInstructions, audioUrl, audioTranscript, ...model } = viewModel;\n return {\n // Delivery renders these as a collapsed toggle and a player; print writes them out.\n model: { ...model, teacherInstructions: null, hasAudio: false },\n session: key,\n teacherInstructions: String(teacherInstructions || ''),\n audioUrl: String(audioUrl || ''),\n audioTranscript: String(audioTranscript || ''),\n };\n}\n","<svelte:options\n customElement={{\n shadow: 'none',\n props: {\n model: { type: 'Object' },\n options: { type: 'Object' },\n },\n }}\n/>\n\n<script lang=\"ts\">\nimport McPopulatedBlank from '../delivery/McPopulatedBlank.svelte';\nimport { t as translate } from '../delivery/i18n';\nimport { preparePrint, type PrintView } from './preparePrint';\n\nlet { model = null, options = null }: { model?: any; options?: any } = $props();\n\nlet view = $state<PrintView | null>(null);\n\n$effect(() => {\n const question = model;\n const role = options?.role;\n if (!question) {\n view = null;\n return;\n }\n let current = true;\n preparePrint(question, role).then((next) => {\n if (current) view = next;\n });\n return () => {\n current = false;\n };\n});\n\nconst t = (key: string) => translate(key, (view?.model.language as string) || undefined);\n</script>\n\n{#if view}\n <div class=\"mpb-print\">\n {#if view.teacherInstructions}\n <div class=\"mpb-print-block mpb-print-teacher-instructions\">{@html view.teacherInstructions}</div>\n {/if}\n\n {#if view.audioUrl || view.audioTranscript}\n <div class=\"mpb-print-block mpb-print-audio\">\n {#if view.audioUrl}\n <div><strong>{t('printAudio')}</strong> {view.audioUrl}</div>\n {/if}\n {#if view.audioTranscript}\n <div><strong>{t('printTranscript')}</strong> {view.audioTranscript}</div>\n {/if}\n </div>\n {/if}\n\n <McPopulatedBlank model={view.model} session={view.session} />\n </div>\n{/if}\n\n<style>\n /* Inset to line up with the delivery root's padding. */\n .mpb-print-block {\n padding: 0 1rem;\n margin: 1rem 0;\n }\n\n .mpb-print-teacher-instructions :global(p) {\n margin: 0.5em 0;\n }\n\n .mpb-print-audio {\n font-size: 0.875rem;\n line-height: 1.25rem;\n }\n</style>\n","import PrintComponent from './Print.svelte';\n\nconst SvelteElementClass = (PrintComponent as any).element;\n\nclass McPopulatedBlankPrint extends SvelteElementClass {\n private _model: any = null;\n private _options: any = null;\n\n set model(m: any) {\n this._model = m;\n super.model = m;\n }\n\n get model() {\n return this._model;\n }\n\n /** `pie-print` sets these before the model; `role` decides whether the key prints. */\n set options(o: any) {\n this._options = o;\n super.options = o;\n }\n\n get options() {\n return this._options;\n }\n}\n\nexport default McPopulatedBlankPrint;\n"],"mappings":";;;;AAiBA,eAAsB,EACpB,GACA,GACoB;CACpB,IAAM,IAAM;EAAE,MAAM;EAAiB;CAAK,GACpC,IAAY,MAAM,EAAY;EAAE,GAAG;EAAU,iBAAiB;CAAK,GAAG,MAAM,CAAG,GAC/E,IACJ,EAAS,mBAAmB,KACxB,OACE,MAAM,EAA6B,GAAU,CAAG,GAClD,EAAE,wBAAqB,aAAU,oBAAiB,GAAG,MAAU;CACrE,OAAO;EAEL,OAA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