@matinfo/vitepress-plugin-quiz 1.0.4 → 1.1.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.
@@ -1,451 +1,641 @@
1
- import { defineComponent as F, computed as _, ref as M, inject as $, watch as D, onMounted as X, openBlock as a, createElementBlock as o, normalizeClass as N, unref as g, createElementVNode as z, Fragment as q, renderList as R, toDisplayString as c, createTextVNode as V, createCommentVNode as I, withKeys as O, withModifiers as L, withDirectives as ee, vModelText as te, provide as E, normalizeStyle as re, renderSlot as ne } from "vue";
2
- const se = ".quiz-progress-bar{position:sticky;top:var(--vp-nav-height, 64px);z-index:20;display:flex;align-items:center;gap:12px;margin:-20px -24px 24px;padding:12px 24px;background:var(--vp-c-bg);border-bottom:1px solid var(--vp-c-divider)}@media(max-width:959px){.quiz-progress-bar{top:calc(var(--vp-nav-height, 64px) - 16px)}}.quiz-progress-track{flex:1;height:8px;background:var(--vp-c-bg-soft);border-radius:4px;overflow:hidden}.quiz-progress-fill{height:100%;background:var(--vp-c-brand-1);border-radius:4px;transition:width .35s ease}.quiz-progress-fill.complete{background:var(--vp-c-green-1, #10b981)}.quiz-progress-label{font-size:13px;color:var(--vp-c-text-2);white-space:nowrap}.quiz-question{border:1px solid var(--vp-c-divider);border-radius:8px;padding:20px 24px;margin-bottom:16px;background:var(--vp-c-bg);transition:border-color .2s}.quiz-question-title{font-weight:600;font-size:15px;margin:0 0 6px;padding:0 5px;color:var(--vp-c-text-1);float:none;width:auto}.quiz-hint{font-size:13px;color:var(--vp-c-text-3);margin:0 0 10px;font-style:italic}.quiz-answers{list-style:none;padding:0;margin:0}.quiz-answer{display:flex;align-items:baseline;gap:10px;padding:8px 12px;margin:4px 0;border:1px solid transparent;border-radius:6px;cursor:pointer;transition:background-color .15s,border-color .15s;user-select:none;font-size:14px;color:var(--vp-c-text-1)}.quiz-answer:hover:not(.correct):not(.wrong):not(.missed){background:var(--vp-c-bg-soft)}.quiz-answer.selected{border-color:var(--vp-c-brand-1);background:var(--vp-c-brand-soft)}.quiz-answer.correct{border-color:var(--vp-c-green-1, #10b981);background:var(--vp-c-green-soft, rgba(16, 185, 129, .12));cursor:default}.quiz-answer.wrong{border-color:var(--vp-c-red-1, #ef4444);background:var(--vp-c-red-soft, rgba(239, 68, 68, .12));cursor:default}.quiz-answer.missed{border-color:var(--vp-c-yellow-1, #f59e0b);background:var(--vp-c-yellow-soft, rgba(245, 158, 11, .1));cursor:default}.validated .quiz-answer{pointer-events:none}.quiz-indicator{flex-shrink:0;width:18px;text-align:center;font-size:15px;line-height:1}.quiz-empty{color:var(--vp-c-text-3)}.quiz-check{color:var(--vp-c-brand-1)}.quiz-answer.correct .quiz-check{color:var(--vp-c-green-1, #10b981)}.quiz-answer.wrong .quiz-check{color:var(--vp-c-red-1, #ef4444)}.quiz-answer-text code{font-family:var(--vp-font-family-mono);font-size:13px;padding:1px 5px;border-radius:4px;background:var(--vp-c-bg-soft);color:var(--vp-c-text-1)}.quiz-explanation{margin-top:12px;padding:10px 14px;border-left:3px solid var(--vp-c-brand-1);background:var(--vp-c-bg-soft);border-radius:0 6px 6px 0;font-size:13px;color:var(--vp-c-text-2)}.quiz-actions{display:flex;flex-wrap:wrap;align-items:center;gap:16px;margin-top:24px;padding-top:20px;border-top:1px solid var(--vp-c-divider)}.quiz-btn{display:inline-flex;align-items:center;justify-content:center;padding:10px 28px;font-size:14px;font-weight:600;border:1px solid transparent;border-radius:8px;cursor:pointer;transition:opacity .2s,background .2s}.quiz-btn:disabled{opacity:.45;cursor:not-allowed}.quiz-btn-validate{background:var(--vp-c-brand-1);color:var(--vp-c-white, #fff)}.quiz-btn-validate:hover:not(:disabled){opacity:.88}.quiz-btn-reset{background:var(--vp-c-bg-soft);border-color:var(--vp-c-divider);color:var(--vp-c-text-1)}.quiz-btn-reset:hover{background:var(--vp-c-bg-mute)}.quiz-score{display:flex;align-items:baseline;gap:8px}.quiz-score-value{font-size:22px;font-weight:700;color:var(--vp-c-brand-1)}.quiz-score-label{font-size:14px;color:var(--vp-c-text-2)}.quiz-input-wrapper{margin-top:8px}.quiz-input{width:100%;max-width:400px;padding:8px 12px;font-size:14px;font-family:var(--vp-font-family-mono);border:1px solid var(--vp-c-divider);border-radius:6px;background:var(--vp-c-bg);color:var(--vp-c-text-1);outline:none;transition:border-color .15s}.quiz-input:focus{border-color:var(--vp-c-brand-1)}.quiz-input:disabled{cursor:not-allowed;opacity:.8}.quiz-input.correct{border-color:var(--vp-c-green-1, #10b981);background:var(--vp-c-green-soft, rgba(16, 185, 129, .12))}.quiz-input.wrong{border-color:var(--vp-c-red-1, #ef4444);background:var(--vp-c-red-soft, rgba(239, 68, 68, .12))}.quiz-expected{margin-top:6px;font-size:13px;color:var(--vp-c-text-2)}.quiz-expected code{font-family:var(--vp-font-family-mono);font-size:13px;padding:1px 5px;border-radius:4px;background:var(--vp-c-bg-soft);color:var(--vp-c-green-1, #10b981)}";
3
- let j = !1;
4
- function ie() {
5
- if (typeof document > "u" || j) return;
6
- const e = "vitepress-plugin-quiz-styles";
7
- if (document.getElementById(e)) {
8
- j = !0;
1
+ import { defineComponent as te, computed as I, ref as M, inject as H, onUnmounted as ie, watch as Z, onMounted as le, openBlock as o, createElementBlock as a, normalizeClass as V, unref as x, createElementVNode as b, Fragment as q, renderList as N, toDisplayString as c, createTextVNode as O, createCommentVNode as P, withKeys as U, withModifiers as G, withDirectives as ue, vModelText as ce, provide as R, normalizeStyle as pe, renderSlot as de } from "vue";
2
+ const ve = ".quiz-progress-bar{position:sticky;top:var(--vp-nav-height, 64px);z-index:20;display:flex;align-items:center;gap:12px;margin:-20px -24px 24px;padding:12px 24px;background:var(--vp-c-bg);border-bottom:1px solid var(--vp-c-divider)}@media(max-width:959px){.quiz-progress-bar{top:calc(var(--vp-nav-height, 64px) - 16px)}}.quiz-progress-track{flex:1;height:8px;background:var(--vp-c-bg-soft);border-radius:4px;overflow:hidden}.quiz-progress-fill{height:100%;background:var(--vp-c-brand-1);border-radius:4px;transition:width .35s ease}.quiz-progress-fill.complete{background:var(--vp-c-green-1, #10b981)}.quiz-progress-label{font-size:13px;color:var(--vp-c-text-2);white-space:nowrap}.quiz-question{border:1px solid var(--vp-c-divider);border-radius:8px;padding:20px 24px;margin-bottom:16px;background:var(--vp-c-bg);transition:border-color .2s}.quiz-question-title{font-weight:600;font-size:15px;margin:0 0 6px;padding:0 5px;color:var(--vp-c-text-1);float:none;width:auto}.quiz-hint{font-size:13px;color:var(--vp-c-text-3);margin:0 0 10px;font-style:italic}.quiz-answers{list-style:none;padding:0;margin:0}.quiz-answer{display:flex;align-items:baseline;gap:10px;padding:8px 12px;margin:4px 0;border:1px solid transparent;border-radius:6px;cursor:pointer;transition:background-color .15s,border-color .15s;user-select:none;font-size:14px;color:var(--vp-c-text-1)}.quiz-answer:hover:not(.correct):not(.wrong):not(.missed){background:var(--vp-c-bg-soft)}.quiz-answer.selected{border-color:var(--vp-c-brand-1);background:var(--vp-c-brand-soft)}.quiz-answer.correct{border-color:var(--vp-c-green-1, #10b981);background:var(--vp-c-green-soft, rgba(16, 185, 129, .12));cursor:default}.quiz-answer.wrong{border-color:var(--vp-c-red-1, #ef4444);background:var(--vp-c-red-soft, rgba(239, 68, 68, .12));cursor:default}.quiz-answer.missed{border-color:var(--vp-c-yellow-1, #f59e0b);background:var(--vp-c-yellow-soft, rgba(245, 158, 11, .1));cursor:default}.validated .quiz-answer{pointer-events:none}.quiz-indicator{flex-shrink:0;width:18px;text-align:center;font-size:15px;line-height:1}.quiz-empty{color:var(--vp-c-text-3)}.quiz-check{color:var(--vp-c-brand-1)}.quiz-answer.correct .quiz-check{color:var(--vp-c-green-1, #10b981)}.quiz-answer.wrong .quiz-check{color:var(--vp-c-red-1, #ef4444)}.quiz-answer-text code{font-family:var(--vp-font-family-mono);font-size:13px;padding:1px 5px;border-radius:4px;background:var(--vp-c-bg-soft);color:var(--vp-c-text-1)}.quiz-explanation{margin-top:12px;padding:10px 14px;border-left:3px solid var(--vp-c-brand-1);background:var(--vp-c-bg-soft);border-radius:0 6px 6px 0;font-size:13px;color:var(--vp-c-text-2)}.quiz-actions{display:flex;flex-wrap:wrap;align-items:center;gap:16px;margin-top:24px;padding-top:20px;border-top:1px solid var(--vp-c-divider)}.quiz-btn{display:inline-flex;align-items:center;justify-content:center;padding:10px 28px;font-size:14px;font-weight:600;border:1px solid transparent;border-radius:8px;cursor:pointer;transition:opacity .2s,background .2s}.quiz-btn:disabled{opacity:.45;cursor:not-allowed}.quiz-btn-validate{background:var(--vp-c-brand-1);color:var(--vp-c-white, #fff)}.quiz-btn-validate:hover:not(:disabled){opacity:.88}.quiz-btn-reset{background:var(--vp-c-bg-soft);border-color:var(--vp-c-divider);color:var(--vp-c-text-1)}.quiz-btn-reset:hover{background:var(--vp-c-bg-mute)}.quiz-score{display:flex;align-items:baseline;gap:8px}.quiz-score-value{font-size:22px;font-weight:700;color:var(--vp-c-brand-1)}.quiz-score-label{font-size:14px;color:var(--vp-c-text-2)}.quiz-input-wrapper{margin-top:8px}.quiz-input{width:100%;max-width:400px;padding:8px 12px;font-size:14px;font-family:var(--vp-font-family-mono);border:1px solid var(--vp-c-divider);border-radius:6px;background:var(--vp-c-bg);color:var(--vp-c-text-1);outline:none;transition:border-color .15s}.quiz-input:focus{border-color:var(--vp-c-brand-1)}.quiz-input:disabled{cursor:not-allowed;opacity:.8}.quiz-input.correct{border-color:var(--vp-c-green-1, #10b981);background:var(--vp-c-green-soft, rgba(16, 185, 129, .12))}.quiz-input.wrong{border-color:var(--vp-c-red-1, #ef4444);background:var(--vp-c-red-soft, rgba(239, 68, 68, .12))}.quiz-expected{margin-top:6px;font-size:13px;color:var(--vp-c-text-2)}.quiz-expected code{font-family:var(--vp-font-family-mono);font-size:13px;padding:1px 5px;border-radius:4px;background:var(--vp-c-bg-soft);color:var(--vp-c-green-1, #10b981)}.quiz-association{display:grid;grid-template-columns:minmax(0,1fr) minmax(0,1fr);gap:10px 16px;align-items:start;margin-top:8px}.quiz-assoc-label{padding-top:8px;font-size:15px;color:var(--vp-c-text-1)}.quiz-assoc-select{width:100%;padding:8px 12px;font-size:14px;border:1px solid var(--vp-c-divider);border-radius:6px;background:var(--vp-c-bg);color:var(--vp-c-text-1);outline:none;transition:border-color .15s}.quiz-assoc-select:focus{border-color:var(--vp-c-brand-1)}.quiz-assoc-select:disabled{cursor:not-allowed;opacity:.8}.quiz-assoc-select.correct{border-color:var(--vp-c-green-1, #10b981);background:var(--vp-c-green-soft, rgba(16, 185, 129, .12))}.quiz-assoc-select.wrong{border-color:var(--vp-c-red-1, #ef4444);background:var(--vp-c-red-soft, rgba(239, 68, 68, .12))}@media(max-width:640px){.quiz-association{grid-template-columns:minmax(0,1fr);gap:4px}.quiz-assoc-label{padding-top:8px}.quiz-assoc-cell{margin-bottom:8px}}";
3
+ let W = !1;
4
+ function fe() {
5
+ if (typeof document > "u" || W) return;
6
+ const t = "vitepress-plugin-quiz-styles";
7
+ if (document.getElementById(t)) {
8
+ W = !0;
9
9
  return;
10
10
  }
11
- const t = document.createElement("style");
12
- t.id = e, t.textContent = se, document.head.appendChild(t), j = !0;
11
+ const i = document.createElement("style");
12
+ i.id = t, i.textContent = ve, document.head.appendChild(i), W = !0;
13
13
  }
14
- const ae = /^:::quiz\s*$/, oe = /^:::\s*$/;
15
- function Fe(e) {
16
- const t = e.utils.escapeHtml;
17
- e.block.ruler.before(
14
+ const ge = /^:::quiz\s*$/, he = /^:::\s*$/, xe = /^([A-Za-z-]+):(.*)$/, be = /* @__PURE__ */ new Set([
15
+ "question",
16
+ "answer",
17
+ "answer-correct",
18
+ "answer-input",
19
+ "pair",
20
+ "distractor",
21
+ "explanation",
22
+ "explication",
23
+ "shuffle"
24
+ ]);
25
+ function xt(t) {
26
+ const i = t.utils.escapeHtml;
27
+ t.block.ruler.before(
18
28
  "fence",
19
29
  "quiz",
20
- (r, u, n, w) => le(r, u, n, w, t),
30
+ (n, v, u, _) => ze(n, v, u, _, i),
21
31
  { alt: ["paragraph", "reference", "blockquote", "list"] }
22
- ), e.renderer.rules.quiz = (r, u) => r[u].content, e.core.ruler.push("quiz_page_wrap", (r) => {
23
- if (!r.tokens.some((v) => v.type === "quiz")) return;
24
- const n = new r.Token("html_block", "", 0);
25
- n.content = `<QuizPage>
26
- `, n.block = !0;
27
- const w = new r.Token("html_block", "", 0);
28
- w.content = `</QuizPage>
29
- `, w.block = !0, r.tokens.unshift(n), r.tokens.push(w);
32
+ ), t.renderer.rules.quiz = (n, v) => n[v].content, t.core.ruler.push("quiz_page_wrap", (n) => {
33
+ if (!n.tokens.some((y) => y.type === "quiz")) return;
34
+ const u = new n.Token("html_block", "", 0);
35
+ u.content = `<QuizPage>
36
+ `, u.block = !0;
37
+ const _ = new n.Token("html_block", "", 0);
38
+ _.content = `</QuizPage>
39
+ `, _.block = !0, n.tokens.unshift(u), n.tokens.push(_);
30
40
  });
31
41
  }
32
- function le(e, t, r, u, n) {
33
- const w = e.bMarks[t] + e.tShift[t], v = e.eMarks[t], i = e.src.slice(w, v);
34
- if (!ae.test(i)) return !1;
35
- if (u) return !0;
36
- let x = t + 1, k = !1;
37
- for (; x < r; ) {
38
- const h = e.bMarks[x] + e.tShift[x], P = e.eMarks[x], S = e.src.slice(h, P);
39
- if (oe.test(S)) {
40
- k = !0;
42
+ function ze(t, i, n, v, u) {
43
+ if (t.sCount[i] - t.blkIndent >= 4) return !1;
44
+ const _ = t.bMarks[i] + t.tShift[i], y = t.eMarks[i], h = t.src.slice(_, y);
45
+ if (!ge.test(h)) return !1;
46
+ if (v) return !0;
47
+ let p = i + 1, A = !1;
48
+ for (; p < n; ) {
49
+ const g = t.bMarks[p] + t.tShift[p], $ = t.eMarks[p], f = t.src.slice(g, $);
50
+ if (he.test(f)) {
51
+ A = !0;
41
52
  break;
42
53
  }
43
- x++;
54
+ p++;
44
55
  }
45
- if (!k) return !1;
46
- const f = [];
47
- for (let h = t + 1; h < x; h++) {
48
- const P = e.bMarks[h] + e.tShift[h], S = e.eMarks[h];
49
- f.push(e.src.slice(P, S));
56
+ if (!A) return !1;
57
+ const S = [];
58
+ for (let g = i + 1; g < p; g++) {
59
+ const $ = t.bMarks[g] + t.tShift[g], f = t.eMarks[g];
60
+ S.push(t.src.slice($, f));
50
61
  }
51
- const m = ue(f);
52
- if (!m) return !1;
53
- const C = e.push("quiz", "", 0);
54
- return C.content = ce(m, n), C.map = [t, x + 1], C.block = !0, e.line = x + 1, !0;
62
+ const z = we(S);
63
+ if (z?.type === "choice" && !z.answers.some((g) => g.correct) && console.warn(
64
+ `[vitepress-plugin-quiz] :quiz block at line ${i + 1} has no 'answer-correct:'; it can never be answered correctly.`
65
+ ), !z)
66
+ return console.warn(
67
+ `[vitepress-plugin-quiz] Ignored invalid :::quiz block at line ${i + 1}: needs a 'question:' and at least one 'answer:'/'answer-correct:', 'answer-input:', or two 'pair: A => B' lines.`
68
+ ), !1;
69
+ const w = t.push("quiz", "", 0);
70
+ return w.content = qe(z, u), w.map = [i, p + 1], w.block = !0, t.line = p + 1, !0;
55
71
  }
56
- function ue(e) {
57
- let t = "";
58
- const r = [];
59
- let u = "";
72
+ function we(t) {
73
+ let i = "";
60
74
  const n = [];
61
- let w = !1;
62
- for (const v of e) {
63
- const i = v.trim();
64
- i && (i.startsWith("question:") ? t = i.slice(9).trim() : i.startsWith("answer-correct:") ? r.push({ text: i.slice(15).trim(), correct: !0 }) : i.startsWith("answer-input:") ? n.push(i.slice(13).trim()) : i.startsWith("answer:") ? r.push({ text: i.slice(7).trim(), correct: !1 }) : i.startsWith("explanation:") || i.startsWith("explication:") ? u = i.slice(12).trim() : i.startsWith("shuffle:") && (w = i.slice(8).trim().toLowerCase() === "true"));
75
+ let v = "";
76
+ const u = [], _ = [], y = [];
77
+ let h = !1, p = null;
78
+ for (const A of t) {
79
+ const S = A.trim();
80
+ if (!S) continue;
81
+ const z = xe.exec(S), w = z?.[1].toLowerCase();
82
+ if (!z || !w || !be.has(w)) {
83
+ p?.(S);
84
+ continue;
85
+ }
86
+ const g = z[2].trim(), $ = (f, C) => f ? `${f} ${C}` : C;
87
+ switch (w) {
88
+ case "question":
89
+ i = g, p = (f) => i = $(i, f);
90
+ break;
91
+ case "answer-correct":
92
+ case "answer": {
93
+ const f = { text: g, correct: w === "answer-correct" };
94
+ n.push(f), p = (C) => f.text = $(f.text, C);
95
+ break;
96
+ }
97
+ case "answer-input":
98
+ g && u.push(g), p = null;
99
+ break;
100
+ case "pair": {
101
+ let f = g.indexOf("=>"), C = 2;
102
+ if (f < 0 && (f = g.indexOf("-->"), C = 3), f < 0) {
103
+ console.warn(`[vitepress-plugin-quiz] Ignored 'pair:' without '=>' or '-->': "${g}"`), p = null;
104
+ break;
105
+ }
106
+ const l = {
107
+ left: g.slice(0, f).trim(),
108
+ right: g.slice(f + C).trim()
109
+ };
110
+ l.left && l.right && _.push(l), p = null;
111
+ break;
112
+ }
113
+ case "distractor":
114
+ g && y.push(g), p = null;
115
+ break;
116
+ case "explanation":
117
+ case "explication":
118
+ v = g, p = (f) => v = $(v, f);
119
+ break;
120
+ case "shuffle":
121
+ h = g.toLowerCase() === "true", p = null;
122
+ break;
123
+ }
124
+ }
125
+ if (!i) return null;
126
+ if (u.length > 0)
127
+ return {
128
+ question: i,
129
+ type: "input",
130
+ answers: [],
131
+ expected: u,
132
+ pairs: [],
133
+ options: [],
134
+ explanation: v,
135
+ shuffle: !1
136
+ };
137
+ if (_.length >= 2) {
138
+ const A = [.../* @__PURE__ */ new Set([..._.map((S) => S.right), ...y])];
139
+ return {
140
+ question: i,
141
+ type: "association",
142
+ answers: [],
143
+ expected: [],
144
+ pairs: _,
145
+ options: A,
146
+ explanation: v,
147
+ shuffle: h
148
+ };
65
149
  }
66
- return t ? n.length > 0 ? { question: t, type: "input", answers: [], expected: n, explanation: u, shuffle: !1 } : r.length === 0 ? null : { question: t, type: "choice", answers: r, expected: [], explanation: u, shuffle: w } : null;
150
+ return n.length === 0 ? null : {
151
+ question: i,
152
+ type: "choice",
153
+ answers: n,
154
+ expected: [],
155
+ pairs: [],
156
+ options: [],
157
+ explanation: v,
158
+ shuffle: h
159
+ };
67
160
  }
68
- function ce(e, t) {
69
- const r = JSON.stringify(e);
70
- return `<QuizQuestion data-quiz="${t(r)}" />
161
+ function qe(t, i) {
162
+ const n = JSON.stringify(t);
163
+ return `<QuizQuestion data-quiz="${i(n)}" />
71
164
  `;
72
165
  }
73
- const U = {
166
+ const X = {
74
167
  en: {
75
168
  answered: "answered",
76
169
  validate: "Validate",
77
170
  reset: "Restart",
78
- correctAnswers: (e) => `correct answer${e !== 1 ? "s" : ""}`,
171
+ correctAnswers: (t) => `correct answer${t !== 1 ? "s" : ""}`,
79
172
  multipleHint: "Multiple answers possible",
80
173
  explanation: "Explanation: ",
81
174
  inputHint: "Type your answer",
82
175
  inputPlaceholder: "Your answer…",
83
- expectedAnswer: "Expected answer:"
176
+ expectedAnswer: "Expected answer:",
177
+ associationHint: "Match each item with its answer",
178
+ associationPlaceholder: "Choose…"
84
179
  },
85
180
  fr: {
86
181
  answered: "répondue(s)",
87
182
  validate: "Valider",
88
183
  reset: "Recommencer",
89
- correctAnswers: (e) => `réponse${e > 1 ? "s" : ""} correcte${e > 1 ? "s" : ""}`,
184
+ correctAnswers: (t) => `réponse${t > 1 ? "s" : ""} correcte${t > 1 ? "s" : ""}`,
90
185
  multipleHint: "Plusieurs réponses possibles",
91
186
  explanation: "Explication : ",
92
187
  inputHint: "Saisissez votre réponse",
93
188
  inputPlaceholder: "Votre réponse…",
94
- expectedAnswer: "Réponse attendue :"
189
+ expectedAnswer: "Réponse attendue :",
190
+ associationHint: "Associez chaque élément à sa réponse",
191
+ associationPlaceholder: "Choisir…"
95
192
  },
96
193
  de: {
97
194
  answered: "beantwortet",
98
195
  validate: "Überprüfen",
99
196
  reset: "Neu starten",
100
- correctAnswers: (e) => `richtige Antwort${e !== 1 ? "en" : ""}`,
197
+ correctAnswers: (t) => `richtige Antwort${t !== 1 ? "en" : ""}`,
101
198
  multipleHint: "Mehrere Antworten möglich",
102
199
  explanation: "Erklärung:",
103
200
  inputHint: "Geben Sie Ihre Antwort ein",
104
201
  inputPlaceholder: "Ihre Antwort…",
105
- expectedAnswer: "Erwartete Antwort:"
202
+ expectedAnswer: "Erwartete Antwort:",
203
+ associationHint: "Ordnen Sie jedem Element die passende Antwort zu",
204
+ associationPlaceholder: "Auswählen…"
106
205
  },
107
206
  it: {
108
207
  answered: "risposta/e",
109
208
  validate: "Verifica",
110
209
  reset: "Ricominciare",
111
- correctAnswers: (e) => `rispost${e !== 1 ? "e corrette" : "a corretta"}`,
210
+ correctAnswers: (t) => `rispost${t !== 1 ? "e corrette" : "a corretta"}`,
112
211
  multipleHint: "Più risposte possibili",
113
212
  explanation: "Spiegazione: ",
114
213
  inputHint: "Digita la tua risposta",
115
214
  inputPlaceholder: "La tua risposta…",
116
- expectedAnswer: "Risposta attesa:"
215
+ expectedAnswer: "Risposta attesa:",
216
+ associationHint: "Abbina ogni elemento alla risposta corretta",
217
+ associationPlaceholder: "Scegli…"
117
218
  },
118
219
  es: {
119
220
  answered: "respondida(s)",
120
221
  validate: "Validar",
121
222
  reset: "Reiniciar",
122
- correctAnswers: (e) => `respuesta${e !== 1 ? "s correctas" : " correcta"}`,
223
+ correctAnswers: (t) => `respuesta${t !== 1 ? "s correctas" : " correcta"}`,
123
224
  multipleHint: "Varias respuestas posibles",
124
225
  explanation: "Explicación: ",
125
226
  inputHint: "Escribe tu respuesta",
126
227
  inputPlaceholder: "Tu respuesta…",
127
- expectedAnswer: "Respuesta esperada:"
228
+ expectedAnswer: "Respuesta esperada:",
229
+ associationHint: "Asocia cada elemento con su respuesta",
230
+ associationPlaceholder: "Elegir…"
128
231
  }
129
232
  };
130
- function pe(e = "en") {
131
- return U[e] ?? U.en;
233
+ function me(t = "en") {
234
+ return X[t] ?? X.en;
235
+ }
236
+ function j(t) {
237
+ const i = [], n = /(\*\*(?!\s)(.+?)\*\*)|(\*(?!\s)(.+?)(?<!\s)\*)|(`([^`]+)`)/g;
238
+ let v = 0, u;
239
+ for (; (u = n.exec(t)) !== null; )
240
+ u.index > v && i.push({ type: "text", value: t.slice(v, u.index) }), u[2] ? i.push({ type: "bold", value: u[2] }) : u[4] ? i.push({ type: "italic", value: u[4] }) : u[6] && i.push({ type: "code", value: u[6] }), v = n.lastIndex;
241
+ return v < t.length && i.push({ type: "text", value: t.slice(v) }), i;
132
242
  }
133
- function J(e) {
134
- const t = [], r = /(\*\*(.+?)\*\*)|(\*(.+?)\*)|(`([^`]+)`)/g;
135
- let u = 0, n;
136
- for (; (n = r.exec(e)) !== null; )
137
- n.index > u && t.push({ type: "text", value: e.slice(u, n.index) }), n[2] ? t.push({ type: "bold", value: n[2] }) : n[4] ? t.push({ type: "italic", value: n[4] }) : n[6] && t.push({ type: "code", value: n[6] }), u = r.lastIndex;
138
- return u < e.length && t.push({ type: "text", value: e.slice(u) }), t;
243
+ function ee(t) {
244
+ return t.normalize("NFD").replace(/\p{M}/gu, "").trim().replace(/\s+/g, " ").toLowerCase();
139
245
  }
140
- const de = ["aria-label"], ve = { class: "quiz-question-title" }, fe = { key: 0 }, he = { key: 1 }, ge = { key: 2 }, ze = {
246
+ const ye = ["aria-label"], ke = { class: "quiz-question-title" }, _e = { key: 0 }, Se = { key: 1 }, Ae = { key: 2 }, Ie = {
141
247
  key: 0,
142
248
  class: "quiz-hint"
143
- }, be = ["aria-multiselectable"], xe = ["onClick", "aria-selected", "onKeydown"], we = {
249
+ }, $e = ["aria-multiselectable"], Ce = ["onClick", "aria-selected", "onKeydown"], Qe = {
144
250
  class: "quiz-indicator",
145
251
  "aria-hidden": "true"
146
- }, qe = {
252
+ }, Pe = {
147
253
  key: 0,
148
254
  class: "quiz-check"
149
- }, me = {
255
+ }, Me = {
150
256
  key: 1,
151
257
  class: "quiz-empty"
152
- }, ye = {
258
+ }, Ee = {
153
259
  key: 0,
154
260
  class: "quiz-check"
155
- }, ke = {
261
+ }, He = {
156
262
  key: 1,
157
263
  class: "quiz-empty"
158
- }, _e = { class: "quiz-answer-text" }, Se = { key: 0 }, Ae = { key: 1 }, Qe = { key: 2 }, Ce = { class: "quiz-hint" }, $e = { class: "quiz-input-wrapper" }, Ie = ["disabled", "placeholder", "aria-label"], Me = {
264
+ }, Ne = { class: "quiz-answer-text" }, Oe = { key: 0 }, Re = { key: 1 }, Ve = { key: 2 }, Te = { class: "quiz-hint" }, je = { class: "quiz-association" }, Ke = ["for"], Be = { key: 0 }, Je = { key: 1 }, De = { key: 2 }, Ue = { class: "quiz-assoc-cell" }, We = ["id", "value", "disabled", "onChange"], Ye = { value: "" }, Fe = ["value"], Le = {
159
265
  key: 0,
160
266
  class: "quiz-expected"
161
- }, Pe = {
162
- key: 2,
267
+ }, Ze = { class: "quiz-hint" }, Ge = { class: "quiz-input-wrapper" }, Xe = ["disabled", "placeholder", "aria-label"], et = {
268
+ key: 0,
269
+ class: "quiz-expected"
270
+ }, tt = {
271
+ key: 3,
163
272
  class: "quiz-explanation",
164
273
  role: "note"
165
- }, Ee = { key: 0 }, He = { key: 1 }, Re = { key: 2 }, Ve = /* @__PURE__ */ F({
274
+ }, nt = { key: 0 }, rt = { key: 1 }, st = { key: 2 }, ot = /* @__PURE__ */ te({
166
275
  __name: "QuizQuestion",
167
276
  props: {
168
277
  dataQuiz: { type: String, required: !0 }
169
278
  },
170
- setup(e) {
171
- const t = e, r = _(() => {
279
+ setup(t) {
280
+ const i = t, n = I(() => {
172
281
  try {
173
- return JSON.parse(t.dataQuiz);
282
+ return JSON.parse(i.dataQuiz);
174
283
  } catch {
175
284
  return null;
176
285
  }
177
286
  });
178
- function u(p) {
179
- const l = [...p];
180
- for (let s = l.length - 1; s > 0; s--) {
181
- const y = Math.floor(Math.random() * (s + 1));
182
- [l[s], l[y]] = [l[y], l[s]];
287
+ function v(r) {
288
+ const s = [...r];
289
+ for (let e = s.length - 1; e > 0; e--) {
290
+ const d = Math.floor(Math.random() * (e + 1));
291
+ [s[e], s[d]] = [s[d], s[e]];
183
292
  }
184
- return l;
293
+ return s;
185
294
  }
186
- const n = M([]);
187
- function w() {
188
- if (!r.value || r.value.type === "input") {
189
- n.value = [];
295
+ const u = M([]);
296
+ function _() {
297
+ if (!n.value || n.value.type !== "choice") {
298
+ u.value = [];
299
+ return;
300
+ }
301
+ const r = n.value.answers.map((s, e) => ({ ...s, originalIndex: e }));
302
+ u.value = n.value.shuffle ? v(r) : r;
303
+ }
304
+ const y = I(() => n.value ? {
305
+ ...n.value,
306
+ answers: u.value
307
+ } : null), h = I(() => n.value?.type === "input"), p = I(() => n.value?.type === "association"), A = I(
308
+ () => y.value && !h.value && !p.value ? y.value.answers.filter((r) => r.correct).length : 0
309
+ ), S = I(() => A.value > 1), z = M(/* @__PURE__ */ new Set()), w = M([]), g = M([]);
310
+ function $() {
311
+ const r = n.value;
312
+ if (!r || r.type !== "association") {
313
+ w.value = [], g.value = [];
190
314
  return;
191
315
  }
192
- const p = r.value.answers.map((l, s) => ({ ...l, originalIndex: s }));
193
- n.value = r.value.shuffle ? u(p) : p;
316
+ w.value = r.pairs.map(() => null);
317
+ const s = r.options.map((e, d) => d);
318
+ g.value = r.shuffle ? v(s) : s;
194
319
  }
195
- const v = _(() => r.value ? {
196
- ...r.value,
197
- answers: n.value
198
- } : null), i = _(() => r.value?.type === "input"), x = _(
199
- () => v.value && !i.value ? v.value.answers.filter((p) => p.correct).length : 0
200
- ), k = _(() => x.value > 1), f = M(/* @__PURE__ */ new Set()), m = M(""), C = $("quiz-register", null), h = $("quiz-validated", M(!1)), P = $("quiz-reset", M(0)), S = $("quiz-locale"), H = $("quiz-question-id", null), d = $("quiz-save-answer", null), b = $("quiz-get-answer", null), Q = H ? H() : null, B = _(() => i.value ? m.value.trim().length > 0 : f.value.size > 0), T = _(() => {
201
- if (!v.value || !B.value) return !1;
202
- if (i.value) {
203
- const l = m.value.trim().toLowerCase();
204
- return r.value.expected.some((s) => l === s.trim().toLowerCase());
320
+ const f = M(""), C = H("quiz-register", null), l = H("quiz-validated", M(!1)), k = H("quiz-reset", M(0)), Q = H("quiz-locale"), Y = H("quiz-question-id", null), T = H("quiz-save-answer", null), F = H("quiz-get-answer", null), E = Y ? Y() : null, L = I(() => p.value ? w.value.length > 0 && w.value.every((r) => r !== null) : h.value ? f.value.trim().length > 0 : z.value.size > 0), K = I(() => {
321
+ if (!y.value || !L.value) return !1;
322
+ if (h.value) {
323
+ const s = ee(f.value);
324
+ return n.value.expected.some((e) => s === ee(e));
205
325
  }
206
- const p = new Set(
207
- v.value.answers.map((l, s) => l.correct ? s : -1).filter((l) => l >= 0)
326
+ if (p.value)
327
+ return n.value.pairs.every((s, e) => B(e));
328
+ const r = new Set(
329
+ n.value.answers.map((s, e) => s.correct ? e : -1).filter((s) => s >= 0)
208
330
  );
209
- if (f.value.size !== p.size) return !1;
210
- for (const l of f.value)
211
- if (!p.has(l)) return !1;
331
+ if (z.value.size !== r.size) return !1;
332
+ for (const s of z.value)
333
+ if (!r.has(s)) return !1;
212
334
  return !0;
213
335
  });
214
- C && C({ answered: B, isCorrect: T }), D(P, () => {
215
- f.value = /* @__PURE__ */ new Set(), m.value = "", w();
216
- }), X(() => {
217
- if (w(), b && Q !== null) {
218
- const p = b(Q);
219
- p && (p.type === "input" ? m.value = p.input : p.type === "choice" && (f.value = new Set(p.selected)));
336
+ function B(r) {
337
+ const s = n.value, e = w.value[r];
338
+ return !s || e === null || e === void 0 ? !1 : s.options[e] === s.pairs[r].right;
339
+ }
340
+ if (C && n.value) {
341
+ const r = C({ answered: L, isCorrect: K });
342
+ ie(r);
343
+ }
344
+ Z(k, () => {
345
+ z.value = /* @__PURE__ */ new Set(), f.value = "", _(), $();
346
+ }), le(() => {
347
+ if (_(), $(), F && E !== null) {
348
+ const r = F(E);
349
+ if (r) {
350
+ if (r.type === "input" && h.value && typeof r.input == "string")
351
+ f.value = r.input;
352
+ else if (r.type === "association" && p.value && Array.isArray(r.chosen)) {
353
+ const s = n.value?.options.length ?? 0;
354
+ w.value = w.value.map((e, d) => {
355
+ const m = r.chosen[d];
356
+ return typeof m == "number" && Number.isInteger(m) && m >= 0 && m < s ? m : null;
357
+ });
358
+ } else if (r.type === "choice" && !p.value && !h.value && Array.isArray(r.selected)) {
359
+ const s = n.value?.answers.length ?? 0;
360
+ z.value = new Set(
361
+ r.selected.filter((e) => Number.isInteger(e) && e >= 0 && e < s)
362
+ );
363
+ }
364
+ }
220
365
  }
221
366
  });
222
- function W(p) {
223
- if (h.value) return;
224
- const l = new Set(f.value);
225
- k.value ? l.has(p) ? l.delete(p) : l.add(p) : (l.clear(), l.add(p)), f.value = l, K();
367
+ function ne(r, s) {
368
+ if (l.value) return;
369
+ const e = s.target.value, d = [...w.value];
370
+ d[r] = e === "" ? null : Number(e), w.value = d, D();
371
+ }
372
+ function J(r) {
373
+ if (l.value) return;
374
+ const s = new Set(z.value);
375
+ S.value ? s.has(r) ? s.delete(r) : s.add(r) : (s.clear(), s.add(r)), z.value = s, D();
226
376
  }
227
- D(m, () => {
228
- h.value || K();
377
+ Z(f, () => {
378
+ l.value || D();
229
379
  });
230
- function K() {
231
- !d || Q === null || (i.value ? d(Q, { type: "input", input: m.value }) : d(Q, { type: "choice", selected: [...f.value] }));
380
+ function D() {
381
+ !T || E === null || (p.value ? T(E, { type: "association", chosen: [...w.value] }) : h.value ? T(E, { type: "input", input: f.value }) : T(E, { type: "choice", selected: [...z.value] }));
382
+ }
383
+ function re(r) {
384
+ const s = z.value.has(r.originalIndex);
385
+ return l.value ? r.correct && s ? "quiz-answer correct" : r.correct && !s ? "quiz-answer missed" : !r.correct && s ? "quiz-answer wrong" : "quiz-answer" : s ? "quiz-answer selected" : "quiz-answer";
232
386
  }
233
- function G(p) {
234
- if (!h.value)
235
- return f.value.has(p) ? "quiz-answer selected" : "quiz-answer";
236
- const l = v.value.answers[p], s = f.value.has(p);
237
- return l.correct && s ? "quiz-answer correct" : l.correct && !s ? "quiz-answer missed" : !l.correct && s ? "quiz-answer wrong" : "quiz-answer";
387
+ function se(r) {
388
+ return l.value ? B(r) ? "quiz-assoc-select correct" : "quiz-assoc-select wrong" : "quiz-assoc-select";
238
389
  }
239
- const Y = _(() => h.value ? T.value ? "quiz-input correct" : "quiz-input wrong" : "quiz-input");
240
- return (p, l) => v.value ? (a(), o("fieldset", {
390
+ const oe = I(() => l.value ? K.value ? "quiz-input correct" : "quiz-input wrong" : "quiz-input");
391
+ return (r, s) => y.value ? (o(), a("fieldset", {
241
392
  key: 0,
242
- class: N(["quiz-question", { validated: g(h) }]),
243
- "aria-label": v.value.question
393
+ class: V(["quiz-question", { validated: x(l) }]),
394
+ "aria-label": y.value.question
244
395
  }, [
245
- z("legend", ve, [
246
- (a(!0), o(q, null, R(g(J)(v.value.question), (s, y) => (a(), o(q, { key: y }, [
247
- s.type === "bold" ? (a(), o("strong", fe, c(s.value), 1)) : s.type === "italic" ? (a(), o("em", he, c(s.value), 1)) : s.type === "code" ? (a(), o("code", ge, c(s.value), 1)) : (a(), o(q, { key: 3 }, [
248
- V(c(s.value), 1)
396
+ b("legend", ke, [
397
+ (o(!0), a(q, null, N(x(j)(y.value.question), (e, d) => (o(), a(q, { key: d }, [
398
+ e.type === "bold" ? (o(), a("strong", _e, c(e.value), 1)) : e.type === "italic" ? (o(), a("em", Se, c(e.value), 1)) : e.type === "code" ? (o(), a("code", Ae, c(e.value), 1)) : (o(), a(q, { key: 3 }, [
399
+ O(c(e.value), 1)
249
400
  ], 64))
250
401
  ], 64))), 128))
251
402
  ]),
252
- i.value ? I("", !0) : (a(), o(q, { key: 0 }, [
253
- k.value ? (a(), o("p", ze, c(g(S).multipleHint), 1)) : I("", !0),
254
- z("ul", {
403
+ !h.value && !p.value ? (o(), a(q, { key: 0 }, [
404
+ S.value ? (o(), a("p", Ie, c(x(Q).multipleHint), 1)) : P("", !0),
405
+ b("ul", {
255
406
  class: "quiz-answers",
256
407
  role: "listbox",
257
- "aria-multiselectable": k.value
408
+ "aria-multiselectable": S.value
258
409
  }, [
259
- (a(!0), o(q, null, R(v.value.answers, (s, y) => (a(), o("li", {
260
- key: s.originalIndex,
261
- class: N(G(y)),
262
- onClick: (A) => W(y),
410
+ (o(!0), a(q, null, N(y.value.answers, (e) => (o(), a("li", {
411
+ key: e.originalIndex,
412
+ class: V(re(e)),
413
+ onClick: (d) => J(e.originalIndex),
263
414
  role: "option",
264
- "aria-selected": f.value.has(y),
415
+ "aria-selected": z.value.has(e.originalIndex),
265
416
  tabindex: "0",
266
417
  onKeydown: [
267
- O((A) => W(y), ["enter"]),
268
- O(L((A) => W(y), ["prevent"]), ["space"])
418
+ U((d) => J(e.originalIndex), ["enter"]),
419
+ U(G((d) => J(e.originalIndex), ["prevent"]), ["space"])
269
420
  ]
270
421
  }, [
271
- z("span", we, [
272
- k.value ? (a(), o(q, { key: 0 }, [
273
- f.value.has(y) ? (a(), o("span", qe, "✓")) : (a(), o("span", me, "☐"))
274
- ], 64)) : (a(), o(q, { key: 1 }, [
275
- f.value.has(y) ? (a(), o("span", ye, "●")) : (a(), o("span", ke, "○"))
422
+ b("span", Qe, [
423
+ S.value ? (o(), a(q, { key: 0 }, [
424
+ z.value.has(e.originalIndex) ? (o(), a("span", Pe, "✓")) : (o(), a("span", Me, "☐"))
425
+ ], 64)) : (o(), a(q, { key: 1 }, [
426
+ z.value.has(e.originalIndex) ? (o(), a("span", Ee, "●")) : (o(), a("span", He, "○"))
276
427
  ], 64))
277
428
  ]),
278
- z("span", _e, [
279
- (a(!0), o(q, null, R(g(J)(s.text), (A, Z) => (a(), o(q, { key: Z }, [
280
- A.type === "bold" ? (a(), o("strong", Se, c(A.value), 1)) : A.type === "italic" ? (a(), o("em", Ae, c(A.value), 1)) : A.type === "code" ? (a(), o("code", Qe, c(A.value), 1)) : (a(), o(q, { key: 3 }, [
281
- V(c(A.value), 1)
429
+ b("span", Ne, [
430
+ (o(!0), a(q, null, N(x(j)(e.text), (d, m) => (o(), a(q, { key: m }, [
431
+ d.type === "bold" ? (o(), a("strong", Oe, c(d.value), 1)) : d.type === "italic" ? (o(), a("em", Re, c(d.value), 1)) : d.type === "code" ? (o(), a("code", Ve, c(d.value), 1)) : (o(), a(q, { key: 3 }, [
432
+ O(c(d.value), 1)
282
433
  ], 64))
283
434
  ], 64))), 128))
284
435
  ])
285
- ], 42, xe))), 128))
286
- ], 8, be)
287
- ], 64)),
288
- i.value ? (a(), o(q, { key: 1 }, [
289
- z("p", Ce, c(g(S).inputHint), 1),
290
- z("div", $e, [
291
- ee(z("input", {
292
- "onUpdate:modelValue": l[0] || (l[0] = (s) => m.value = s),
293
- class: N(Y.value),
436
+ ], 42, Ce))), 128))
437
+ ], 8, $e)
438
+ ], 64)) : P("", !0),
439
+ p.value && n.value ? (o(), a(q, { key: 1 }, [
440
+ b("p", Te, c(x(Q).associationHint), 1),
441
+ b("div", je, [
442
+ (o(!0), a(q, null, N(n.value.pairs, (e, d) => (o(), a(q, { key: d }, [
443
+ b("label", {
444
+ class: "quiz-assoc-label",
445
+ for: `quiz-assoc-${x(E)}-${d}`
446
+ }, [
447
+ (o(!0), a(q, null, N(x(j)(e.left), (m, ae) => (o(), a(q, { key: ae }, [
448
+ m.type === "bold" ? (o(), a("strong", Be, c(m.value), 1)) : m.type === "italic" ? (o(), a("em", Je, c(m.value), 1)) : m.type === "code" ? (o(), a("code", De, c(m.value), 1)) : (o(), a(q, { key: 3 }, [
449
+ O(c(m.value), 1)
450
+ ], 64))
451
+ ], 64))), 128))
452
+ ], 8, Ke),
453
+ b("div", Ue, [
454
+ b("select", {
455
+ id: `quiz-assoc-${x(E)}-${d}`,
456
+ class: V(se(d)),
457
+ value: w.value[d] === null || w.value[d] === void 0 ? "" : String(w.value[d]),
458
+ disabled: x(l),
459
+ onChange: (m) => ne(d, m)
460
+ }, [
461
+ b("option", Ye, c(x(Q).associationPlaceholder), 1),
462
+ (o(!0), a(q, null, N(g.value, (m) => (o(), a("option", {
463
+ key: m,
464
+ value: String(m)
465
+ }, c(n.value.options[m]), 9, Fe))), 128))
466
+ ], 42, We),
467
+ x(l) && !B(d) ? (o(), a("p", Le, [
468
+ O(c(x(Q).expectedAnswer) + " ", 1),
469
+ b("code", null, c(e.right), 1)
470
+ ])) : P("", !0)
471
+ ])
472
+ ], 64))), 128))
473
+ ])
474
+ ], 64)) : P("", !0),
475
+ h.value && !p.value ? (o(), a(q, { key: 2 }, [
476
+ b("p", Ze, c(x(Q).inputHint), 1),
477
+ b("div", Ge, [
478
+ ue(b("input", {
479
+ "onUpdate:modelValue": s[0] || (s[0] = (e) => f.value = e),
480
+ class: V(oe.value),
294
481
  type: "text",
295
- disabled: g(h),
296
- placeholder: g(S).inputPlaceholder,
297
- "aria-label": v.value.question,
482
+ disabled: x(l),
483
+ placeholder: x(Q).inputPlaceholder,
484
+ "aria-label": y.value.question,
298
485
  autocomplete: "off",
299
486
  spellcheck: "false",
300
- onKeydown: l[1] || (l[1] = O(L(() => {
487
+ onKeydown: s[1] || (s[1] = U(G(() => {
301
488
  }, ["prevent"]), ["enter"]))
302
- }, null, 42, Ie), [
303
- [te, m.value]
489
+ }, null, 42, Xe), [
490
+ [ce, f.value]
304
491
  ]),
305
- g(h) && !T.value ? (a(), o("p", Me, [
306
- V(c(g(S).expectedAnswer) + " ", 1),
307
- z("code", null, c(r.value?.expected[0]), 1)
308
- ])) : I("", !0)
492
+ x(l) && !K.value ? (o(), a("p", et, [
493
+ O(c(x(Q).expectedAnswer) + " ", 1),
494
+ b("code", null, c(n.value?.expected[0]), 1)
495
+ ])) : P("", !0)
309
496
  ])
310
- ], 64)) : I("", !0),
311
- g(h) && v.value.explanation ? (a(), o("div", Pe, [
312
- z("strong", null, c(g(S).explanation), 1),
313
- (a(!0), o(q, null, R(g(J)(v.value.explanation), (s, y) => (a(), o(q, { key: y }, [
314
- s.type === "bold" ? (a(), o("strong", Ee, c(s.value), 1)) : s.type === "italic" ? (a(), o("em", He, c(s.value), 1)) : s.type === "code" ? (a(), o("code", Re, c(s.value), 1)) : (a(), o(q, { key: 3 }, [
315
- V(c(s.value), 1)
497
+ ], 64)) : P("", !0),
498
+ x(l) && y.value.explanation ? (o(), a("div", tt, [
499
+ b("strong", null, c(x(Q).explanation), 1),
500
+ (o(!0), a(q, null, N(x(j)(y.value.explanation), (e, d) => (o(), a(q, { key: d }, [
501
+ e.type === "bold" ? (o(), a("strong", nt, c(e.value), 1)) : e.type === "italic" ? (o(), a("em", rt, c(e.value), 1)) : e.type === "code" ? (o(), a("code", st, c(e.value), 1)) : (o(), a(q, { key: 3 }, [
502
+ O(c(e.value), 1)
316
503
  ], 64))
317
504
  ], 64))), 128))
318
- ])) : I("", !0)
319
- ], 10, de)) : I("", !0);
505
+ ])) : P("", !0)
506
+ ], 10, ye)) : P("", !0);
320
507
  }
321
- }), Ne = {
508
+ }), at = {
322
509
  class: "quiz-page",
323
510
  role: "region",
324
511
  "aria-label": "Quiz"
325
- }, Te = ["aria-valuenow", "aria-valuemax", "aria-label"], We = { class: "quiz-progress-track" }, Oe = {
512
+ }, it = ["aria-valuenow", "aria-valuemax", "aria-label"], lt = { class: "quiz-progress-track" }, ut = {
326
513
  class: "quiz-progress-label",
327
514
  "aria-live": "polite"
328
- }, je = { class: "quiz-actions" }, Je = ["disabled"], Be = ["aria-label"], Ke = { class: "quiz-score-value" }, De = { class: "quiz-score-label" }, Le = /* @__PURE__ */ F({
515
+ }, ct = { class: "quiz-actions" }, pt = ["disabled"], dt = ["aria-label"], vt = { class: "quiz-score-value" }, ft = { class: "quiz-score-label" }, gt = /* @__PURE__ */ te({
329
516
  __name: "QuizPage",
330
- setup(e) {
331
- const t = $("quiz-locale"), r = M([]), u = M(!1), n = typeof window < "u" ? "quiz-state:" + window.location.pathname : "";
332
- S();
333
- let w = 0;
334
- E("quiz-validated", u), E("quiz-register", (d) => {
335
- r.value.push(d);
336
- }), E("quiz-question-id", () => w++), E("quiz-save-answer", (d, b) => {
337
- if (n)
517
+ setup(t) {
518
+ const i = H("quiz-locale"), n = M([]), v = M(!1), u = typeof window < "u" ? "quiz-state:" + window.location.pathname : "";
519
+ f();
520
+ let _ = 0;
521
+ R("quiz-validated", v), R("quiz-register", (l) => (n.value.push(l), () => {
522
+ const k = n.value.indexOf(l);
523
+ k >= 0 && n.value.splice(k, 1);
524
+ })), R("quiz-question-id", () => _++), R("quiz-save-answer", (l, k) => {
525
+ if (u)
338
526
  try {
339
- sessionStorage.setItem(n + ":q" + d, JSON.stringify(b));
527
+ sessionStorage.setItem(u + ":q" + l, JSON.stringify(k));
340
528
  } catch {
341
529
  }
342
- }), E("quiz-get-answer", (d) => {
343
- if (!n) return null;
530
+ }), R("quiz-get-answer", (l) => {
531
+ if (!u) return null;
344
532
  try {
345
- const b = sessionStorage.getItem(n + ":q" + d);
346
- return b ? JSON.parse(b) : null;
533
+ const k = sessionStorage.getItem(u + ":q" + l);
534
+ return k ? JSON.parse(k) : null;
347
535
  } catch {
348
536
  return null;
349
537
  }
350
538
  });
351
- const v = M(0);
352
- E("quiz-reset", v);
353
- const i = _(() => r.value.length), x = _(
354
- () => r.value.filter((d) => d.answered).length
355
- ), k = _(
356
- () => r.value.filter((d) => d.isCorrect).length
357
- ), f = _(() => x.value === i.value), m = _(
358
- () => i.value ? Math.round(x.value / i.value * 100) : 0
539
+ const y = M(0);
540
+ R("quiz-reset", y);
541
+ const h = I(() => n.value.length), p = I(
542
+ () => n.value.filter((l) => l.answered).length
543
+ ), A = I(
544
+ () => n.value.filter((l) => l.isCorrect).length
545
+ ), S = I(
546
+ () => h.value > 0 && p.value === h.value
547
+ ), z = I(
548
+ () => h.value ? Math.round(p.value / h.value * 100) : 0
359
549
  );
360
- function C() {
361
- u.value = !0, P();
550
+ function w() {
551
+ v.value = !0, $();
362
552
  }
363
- function h() {
364
- u.value = !1, v.value++, H();
553
+ function g() {
554
+ v.value = !1, y.value++, C();
365
555
  }
366
- function P() {
367
- if (n)
556
+ function $() {
557
+ if (u)
368
558
  try {
369
- const d = { validated: u.value, ts: Date.now() };
370
- sessionStorage.setItem(n, JSON.stringify(d));
559
+ const l = { validated: v.value, ts: Date.now() };
560
+ sessionStorage.setItem(u, JSON.stringify(l));
371
561
  } catch {
372
562
  }
373
563
  }
374
- function S() {
375
- if (n)
564
+ function f() {
565
+ if (u)
376
566
  try {
377
- const d = sessionStorage.getItem(n);
378
- if (!d) return;
379
- const b = JSON.parse(d);
380
- b && b.validated && (u.value = !0);
567
+ const l = sessionStorage.getItem(u);
568
+ if (!l) return;
569
+ const k = JSON.parse(l);
570
+ k && k.validated && (v.value = !0);
381
571
  } catch {
382
572
  }
383
573
  }
384
- function H() {
385
- if (n)
574
+ function C() {
575
+ if (u)
386
576
  try {
387
- const d = [];
388
- for (let b = 0; b < sessionStorage.length; b++) {
389
- const Q = sessionStorage.key(b);
390
- Q && Q.startsWith(n) && d.push(Q);
577
+ const l = [];
578
+ for (let k = 0; k < sessionStorage.length; k++) {
579
+ const Q = sessionStorage.key(k);
580
+ Q && Q.startsWith(u) && l.push(Q);
391
581
  }
392
- d.forEach((b) => sessionStorage.removeItem(b));
582
+ l.forEach((k) => sessionStorage.removeItem(k));
393
583
  } catch {
394
584
  }
395
585
  }
396
- return (d, b) => (a(), o("div", Ne, [
397
- z("div", {
586
+ return (l, k) => (o(), a("div", at, [
587
+ b("div", {
398
588
  class: "quiz-progress-bar",
399
589
  role: "progressbar",
400
- "aria-valuenow": x.value,
590
+ "aria-valuenow": p.value,
401
591
  "aria-valuemin": 0,
402
- "aria-valuemax": i.value,
403
- "aria-label": x.value + " / " + i.value + " " + g(t).answered
592
+ "aria-valuemax": h.value,
593
+ "aria-label": p.value + " / " + h.value + " " + x(i).answered
404
594
  }, [
405
- z("div", We, [
406
- z("div", {
407
- class: N(["quiz-progress-fill", { complete: m.value === 100 }]),
408
- style: re({ width: m.value + "%" })
595
+ b("div", lt, [
596
+ b("div", {
597
+ class: V(["quiz-progress-fill", { complete: z.value === 100 }]),
598
+ style: pe({ width: z.value + "%" })
409
599
  }, null, 6)
410
600
  ]),
411
- z("span", Oe, c(x.value) + " / " + c(i.value) + " " + c(g(t).answered), 1)
412
- ], 8, Te),
413
- ne(d.$slots, "default"),
414
- z("div", je, [
415
- u.value ? I("", !0) : (a(), o("button", {
601
+ b("span", ut, c(p.value) + " / " + c(h.value) + " " + c(x(i).answered), 1)
602
+ ], 8, it),
603
+ de(l.$slots, "default"),
604
+ b("div", ct, [
605
+ v.value ? P("", !0) : (o(), a("button", {
416
606
  key: 0,
417
607
  class: "quiz-btn quiz-btn-validate",
418
- disabled: !f.value,
419
- onClick: C
420
- }, c(g(t).validate), 9, Je)),
421
- u.value ? (a(), o(q, { key: 1 }, [
422
- z("div", {
608
+ disabled: !S.value,
609
+ onClick: w
610
+ }, c(x(i).validate), 9, pt)),
611
+ v.value ? (o(), a(q, { key: 1 }, [
612
+ b("div", {
423
613
  class: "quiz-score",
424
614
  role: "status",
425
615
  "aria-live": "polite",
426
- "aria-label": k.value + " / " + i.value + " " + g(t).correctAnswers(k.value)
616
+ "aria-label": A.value + " / " + h.value + " " + x(i).correctAnswers(A.value)
427
617
  }, [
428
- z("span", Ke, c(k.value) + " / " + c(i.value), 1),
429
- z("span", De, c(g(t).correctAnswers(k.value)) + " (" + c(i.value ? Math.round(k.value / i.value * 100) : 0) + "%) ", 1)
430
- ], 8, Be),
431
- z("button", {
618
+ b("span", vt, c(A.value) + " / " + c(h.value), 1),
619
+ b("span", ft, c(x(i).correctAnswers(A.value)) + " (" + c(h.value ? Math.round(A.value / h.value * 100) : 0) + "%) ", 1)
620
+ ], 8, dt),
621
+ b("button", {
432
622
  class: "quiz-btn quiz-btn-reset",
433
- onClick: h
434
- }, c(g(t).reset), 1)
435
- ], 64)) : I("", !0)
623
+ onClick: g
624
+ }, c(x(i).reset), 1)
625
+ ], 64)) : P("", !0)
436
626
  ])
437
627
  ]));
438
628
  }
439
629
  });
440
- function Ge(e, t = "en") {
441
- ie(), e.provide("quiz-locale", pe(t)), e.component("QuizQuestion", Ve), e.component("QuizPage", Le);
630
+ function bt(t, i = "en") {
631
+ fe(), t.provide("quiz-locale", me(i)), t.component("QuizQuestion", ot), t.component("QuizPage", gt);
442
632
  }
443
633
  export {
444
- Le as QuizPage,
445
- Ve as QuizQuestion,
446
- Ge as enhanceAppWithQuiz,
447
- pe as getLocale,
448
- U as locales,
449
- Fe as quizMarkdownPlugin
634
+ gt as QuizPage,
635
+ ot as QuizQuestion,
636
+ bt as enhanceAppWithQuiz,
637
+ me as getLocale,
638
+ X as locales,
639
+ xt as quizMarkdownPlugin
450
640
  };
451
641
  //# sourceMappingURL=vitepress-plugin-quiz.js.map