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