@m3ui-vue/m3ui-vue 1.3.8 → 1.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (117) hide show
  1. package/dist/API.md +1102 -20
  2. package/dist/{MButton-D5eJiDza.js → MButton-DQMTIlaV.js} +2 -2
  3. package/dist/{MButton-D5eJiDza.js.map → MButton-DQMTIlaV.js.map} +1 -1
  4. package/dist/{MDialog-WqB0jewp.js → MDialog-cdgapGfZ.js} +2 -2
  5. package/dist/{MDialog-WqB0jewp.js.map → MDialog-cdgapGfZ.js.map} +1 -1
  6. package/dist/{MListItem-Cf-C2Ru-.js → MListItem-ZkSGIIrb.js} +2 -2
  7. package/dist/{MListItem-Cf-C2Ru-.js.map → MListItem-ZkSGIIrb.js.map} +1 -1
  8. package/dist/{MLoadingIndicator-D4GzEZoH.js → MLoadingIndicator-U6_oGx8z.js} +2 -2
  9. package/dist/{MLoadingIndicator-D4GzEZoH.js.map → MLoadingIndicator-U6_oGx8z.js.map} +1 -1
  10. package/dist/{MSeekBar-B19xoWE3.js → MSeekBar-DTZVizZg.js} +2 -2
  11. package/dist/{MSeekBar-B19xoWE3.js.map → MSeekBar-DTZVizZg.js.map} +1 -1
  12. package/dist/{MSlider-9RoiuebS.js → MSlider-CqJkEYRZ.js} +2 -2
  13. package/dist/{MSlider-9RoiuebS.js.map → MSlider-CqJkEYRZ.js.map} +1 -1
  14. package/dist/{MSpinner-BNF8MN-L.js → MSpinner-Btgc-0nb.js} +2 -2
  15. package/dist/{MSpinner-BNF8MN-L.js.map → MSpinner-Btgc-0nb.js.map} +1 -1
  16. package/dist/{MTextField-CuG0T3qh.js → MTextField-B6M0gJEO.js} +2 -2
  17. package/dist/{MTextField-CuG0T3qh.js.map → MTextField-B6M0gJEO.js.map} +1 -1
  18. package/dist/{MTooltip-Bv7yxngk.js → MTooltip-Dspji4XG.js} +4 -4
  19. package/dist/{MTooltip-Bv7yxngk.js.map → MTooltip-Dspji4XG.js.map} +1 -1
  20. package/dist/api.json +1 -1
  21. package/dist/code-editor.js +1 -1
  22. package/dist/components/MAudioPlayer.vue.d.ts +2 -2
  23. package/dist/components/MAvailabilityCalendar.vue.d.ts +83 -0
  24. package/dist/components/MBeforeAfter.vue.d.ts +61 -0
  25. package/dist/components/MBodyMap.vue.d.ts +70 -0
  26. package/dist/components/MCandlestickChart.vue.d.ts +82 -0
  27. package/dist/components/MCertificate.vue.d.ts +76 -0
  28. package/dist/components/MCountdown.vue.d.ts +80 -0
  29. package/dist/components/MCreditCardInput.vue.d.ts +75 -0
  30. package/dist/components/MMortgageCalculator.vue.d.ts +83 -0
  31. package/dist/components/MOdontogram.vue.d.ts +86 -0
  32. package/dist/components/MOrderBook.vue.d.ts +89 -0
  33. package/dist/components/MOrderTicket.vue.d.ts +91 -0
  34. package/dist/components/MPosKeypad.vue.d.ts +84 -0
  35. package/dist/components/MProductConfigurator.vue.d.ts +136 -0
  36. package/dist/components/MQuiz.vue.d.ts +102 -0
  37. package/dist/components/MReceipt.vue.d.ts +93 -0
  38. package/dist/components/MSeatMap.vue.d.ts +131 -0
  39. package/dist/components/MSeekBar.vue.d.ts +1 -1
  40. package/dist/components/MTicket.vue.d.ts +83 -0
  41. package/dist/components/MVideoPlayer.vue.d.ts +1 -1
  42. package/dist/components/MVitalsChart.vue.d.ts +73 -0
  43. package/dist/composables/_printElement.d.ts +9 -0
  44. package/dist/composables/cardBrand.d.ts +25 -0
  45. package/dist/composables/mortgage.d.ts +37 -0
  46. package/dist/composables/useLocale.d.ts +131 -0
  47. package/dist/draw.js +2 -2
  48. package/dist/flow.js +1 -1
  49. package/dist/gantt.js +1 -1
  50. package/dist/index.d.ts +37 -0
  51. package/dist/locales/index.js +924 -7
  52. package/dist/locales/index.js.map +1 -1
  53. package/dist/m3ui-vue.css +1 -1
  54. package/dist/m3ui.js +10125 -5263
  55. package/dist/m3ui.js.map +1 -1
  56. package/dist/map.js +5 -5
  57. package/dist/media.js +4 -4
  58. package/dist/pdf.js +4 -4
  59. package/dist/rich-text-editor.js +4 -4
  60. package/dist/styles.css +1 -1
  61. package/dist/{useLocale-D2ucaY-l.js → useLocale-DLKJIRFi.js} +133 -2
  62. package/dist/useLocale-DLKJIRFi.js.map +1 -0
  63. package/package.json +1 -1
  64. package/src/__tests__/MAvailabilityCalendar.test.ts +85 -0
  65. package/src/__tests__/MBeforeAfter.test.ts +79 -0
  66. package/src/__tests__/MBodyMap.test.ts +60 -0
  67. package/src/__tests__/MCandlestickChart.test.ts +66 -0
  68. package/src/__tests__/MCertificate.test.ts +32 -0
  69. package/src/__tests__/MCountdown.test.ts +75 -0
  70. package/src/__tests__/MCreditCardInput.test.ts +122 -0
  71. package/src/__tests__/MMortgageCalculator.test.ts +49 -0
  72. package/src/__tests__/MOdontogram.test.ts +93 -0
  73. package/src/__tests__/MOrderBook.test.ts +66 -0
  74. package/src/__tests__/MOrderTicket.test.ts +68 -0
  75. package/src/__tests__/MPosKeypad.test.ts +116 -0
  76. package/src/__tests__/MProductConfigurator.test.ts +73 -0
  77. package/src/__tests__/MQuiz.test.ts +104 -0
  78. package/src/__tests__/MReceipt.test.ts +52 -0
  79. package/src/__tests__/MSeatMap.test.ts +76 -0
  80. package/src/__tests__/MTicket.test.ts +38 -0
  81. package/src/__tests__/MVitalsChart.test.ts +49 -0
  82. package/src/__tests__/clearToNull.test.ts +30 -0
  83. package/src/__tests__/mortgage.test.ts +25 -0
  84. package/src/__tests__/ssr.test.ts +11 -0
  85. package/src/components/MAutocomplete.vue +2 -2
  86. package/src/components/MAvailabilityCalendar.vue +460 -0
  87. package/src/components/MBeforeAfter.vue +248 -0
  88. package/src/components/MBodyMap.vue +266 -0
  89. package/src/components/MCandlestickChart.vue +479 -0
  90. package/src/components/MCertificate.vue +351 -0
  91. package/src/components/MCountdown.vue +200 -0
  92. package/src/components/MCreditCardInput.vue +351 -0
  93. package/src/components/MMortgageCalculator.vue +258 -0
  94. package/src/components/MOdontogram.vue +462 -0
  95. package/src/components/MOrderBook.vue +287 -0
  96. package/src/components/MOrderTicket.vue +217 -0
  97. package/src/components/MPosKeypad.vue +406 -0
  98. package/src/components/MProductConfigurator.vue +412 -0
  99. package/src/components/MQuiz.vue +531 -0
  100. package/src/components/MReceipt.vue +249 -0
  101. package/src/components/MSeatMap.vue +431 -0
  102. package/src/components/MSelect.vue +2 -2
  103. package/src/components/MTicket.vue +209 -0
  104. package/src/components/MVitalsChart.vue +303 -0
  105. package/src/composables/_printElement.ts +36 -0
  106. package/src/composables/cardBrand.ts +104 -0
  107. package/src/composables/mortgage.ts +70 -0
  108. package/src/composables/useLocale.ts +277 -0
  109. package/src/index.ts +37 -0
  110. package/src/locales/de.ts +131 -0
  111. package/src/locales/es.ts +131 -0
  112. package/src/locales/fr.ts +131 -0
  113. package/src/locales/ja.ts +131 -0
  114. package/src/locales/ko.ts +131 -0
  115. package/src/locales/pt.ts +131 -0
  116. package/src/locales/zh.ts +131 -0
  117. package/dist/useLocale-D2ucaY-l.js.map +0 -1
@@ -0,0 +1,531 @@
1
+ <script lang="ts">
2
+ /**
3
+ * A question of an `MQuiz`.
4
+ * - `single`: `answer` is the index of the right option.
5
+ * - `multiple`: `answer` is the indices of every right option (all of them, and only them, to score).
6
+ * - `truefalse`: `answer` is a boolean.
7
+ * - `order`: `options` are given in the right order; the quiz shuffles them.
8
+ * - `text`: `answer` is the accepted answer(s); case, accents and extra spaces are ignored.
9
+ */
10
+ export interface QuizQuestion {
11
+ id: string | number
12
+ type?: 'single' | 'multiple' | 'truefalse' | 'order' | 'text'
13
+ prompt: string
14
+ /** An image shown with the prompt */
15
+ image?: string
16
+ options?: string[]
17
+ answer?: number | number[] | boolean | string | string[]
18
+ /** Shown after answering: why the answer is what it is */
19
+ explanation?: string
20
+ /** Points the question is worth */
21
+ points?: number
22
+ }
23
+
24
+ export type QuizAnswer = number | number[] | boolean | string
25
+
26
+ /** The outcome of a finished quiz. */
27
+ export interface QuizResult {
28
+ score: number
29
+ total: number
30
+ percent: number
31
+ /** Whether `percent` reached `passScore` (always true without one) */
32
+ passed: boolean
33
+ answers: Record<string, { value: QuizAnswer | undefined; correct: boolean }>
34
+ }
35
+ </script>
36
+
37
+ <script setup lang="ts">
38
+ /**
39
+ * A quiz for a course, an onboarding or a training: single and multiple choice, true/false, putting items in order
40
+ * and typed answers, one question at a time with a progress bar. With `feedback="immediate"` each answer is checked
41
+ * on the spot with its explanation; with `"end"` everything is revealed in the results. The results show the score,
42
+ * pass / fail against `passScore`, and a review of every question. An optional time limit ends the quiz when it
43
+ * runs out.
44
+ *
45
+ * @slot result Replaces the results screen. Slot props: `{ result, retry }`
46
+ * @event answer A question was answered (checked): `{ id, value, correct }`
47
+ * @event finish The quiz ended, with its `QuizResult`
48
+ */
49
+ import { computed, onBeforeUnmount, ref, watch } from 'vue'
50
+ import MButton from './MButton.vue'
51
+ import MIcon from './MIcon.vue'
52
+ import MIconButton from './MIconButton.vue'
53
+ import { useLocale } from '../composables/useLocale'
54
+ import { vRipple } from '../directives/vRipple'
55
+
56
+ const locale = useLocale()
57
+
58
+ const props = withDefaults(
59
+ defineProps<{
60
+ questions: QuizQuestion[]
61
+ /** Check each answer right away, or only reveal them in the results */
62
+ feedback?: 'immediate' | 'end'
63
+ /** Shuffles the questions on every attempt */
64
+ shuffle?: boolean
65
+ /** Shuffles the options of choice questions */
66
+ shuffleOptions?: boolean
67
+ /** Percent needed to pass, e.g. 70. Without it there's no pass / fail */
68
+ passScore?: number
69
+ /** Time limit for the whole quiz, in seconds */
70
+ timeLimit?: number
71
+ /** Lists every question with the given and the right answer in the results */
72
+ review?: boolean
73
+ /** Offers to try again from the results */
74
+ allowRetry?: boolean
75
+ }>(),
76
+ {
77
+ feedback: 'immediate',
78
+ shuffle: false,
79
+ shuffleOptions: false,
80
+ review: true,
81
+ allowRetry: true,
82
+ },
83
+ )
84
+
85
+ const emit = defineEmits<{
86
+ answer: [{ id: string | number; value: QuizAnswer | undefined; correct: boolean }]
87
+ finish: [QuizResult]
88
+ }>()
89
+
90
+ function shuffled<T>(list: T[]): T[] {
91
+ const a = [...list]
92
+ for (let i = a.length - 1; i > 0; i--) {
93
+ const j = Math.floor(Math.random() * (i + 1))
94
+ ;[a[i], a[j]] = [a[j]!, a[i]!]
95
+ }
96
+ return a
97
+ }
98
+
99
+ interface Item { q: QuizQuestion; type: NonNullable<QuizQuestion['type']>; /** original option indices in display order */ order: number[] }
100
+
101
+ const items = ref<Item[]>([])
102
+ const index = ref(0)
103
+ const answers = ref<Record<string, QuizAnswer | undefined>>({})
104
+ const checked = ref<Record<string, boolean>>({})
105
+ const finished = ref(false)
106
+
107
+ function setup() {
108
+ const qs = props.shuffle ? shuffled(props.questions) : props.questions
109
+ items.value = qs.map((q) => {
110
+ const type = q.type ?? 'single'
111
+ const idx = (q.options ?? []).map((_, i) => i)
112
+ let order = idx
113
+ if (type === 'order') {
114
+ order = shuffled(idx)
115
+ // never start already solved
116
+ if (order.length > 1 && order.every((v, i) => v === i)) order = [...order.slice(1), order[0]!]
117
+ } else if (props.shuffleOptions && (type === 'single' || type === 'multiple')) order = shuffled(idx)
118
+ return { q, type, order }
119
+ })
120
+ index.value = 0
121
+ answers.value = {}
122
+ checked.value = {}
123
+ finished.value = false
124
+ for (const it of items.value) if (it.type === 'order') answers.value[String(it.q.id)] = [...it.order]
125
+ startTimer()
126
+ }
127
+
128
+ const current = computed(() => items.value[index.value])
129
+ const key = (it: Item) => String(it.q.id)
130
+ const value = computed(() => (current.value ? answers.value[key(current.value)] : undefined))
131
+ const isChecked = computed(() => !!current.value && !!checked.value[key(current.value)])
132
+
133
+ function normalize(s: string) {
134
+ return s.normalize('NFD').replace(/\p{M}/gu, '').toLowerCase().replace(/\s+/g, ' ').trim()
135
+ }
136
+
137
+ function isCorrect(it: Item, v: QuizAnswer | undefined): boolean {
138
+ const a = it.q.answer
139
+ switch (it.type) {
140
+ case 'single':
141
+ return v === a
142
+ case 'multiple': {
143
+ const want = [...((a as number[]) ?? [])].sort()
144
+ const got = [...((v as number[]) ?? [])].sort()
145
+ return want.length === got.length && want.every((x, i) => x === got[i])
146
+ }
147
+ case 'truefalse':
148
+ return v === a
149
+ case 'order':
150
+ return Array.isArray(v) && v.every((x, i) => x === i)
151
+ case 'text': {
152
+ if (typeof v !== 'string' || !v.trim()) return false
153
+ const accepted = Array.isArray(a) ? a : [a as string]
154
+ return accepted.some((x) => normalize(String(x)) === normalize(v))
155
+ }
156
+ }
157
+ }
158
+
159
+ function answered(it: Item) {
160
+ const v = answers.value[key(it)]
161
+ if (it.type === 'multiple') return Array.isArray(v) && v.length > 0
162
+ if (it.type === 'text') return typeof v === 'string' && v.trim().length > 0
163
+ return v !== undefined
164
+ }
165
+
166
+ function set(v: QuizAnswer) {
167
+ if (!current.value || isChecked.value) return
168
+ answers.value = { ...answers.value, [key(current.value)]: v }
169
+ }
170
+
171
+ function toggleMulti(i: number) {
172
+ const cur = (value.value as number[] | undefined) ?? []
173
+ set(cur.includes(i) ? cur.filter((x) => x !== i) : [...cur, i])
174
+ }
175
+
176
+ function move(pos: number, d: number) {
177
+ const cur = [...(value.value as number[])]
178
+ const to = pos + d
179
+ if (to < 0 || to >= cur.length) return
180
+ ;[cur[pos], cur[to]] = [cur[to]!, cur[pos]!]
181
+ set(cur)
182
+ }
183
+
184
+ function check() {
185
+ const it = current.value
186
+ if (!it) return
187
+ checked.value = { ...checked.value, [key(it)]: true }
188
+ emit('answer', { id: it.q.id, value: answers.value[key(it)], correct: isCorrect(it, answers.value[key(it)]) })
189
+ }
190
+
191
+ function next() {
192
+ const it = current.value
193
+ if (it && props.feedback === 'end' && !checked.value[key(it)]) check()
194
+ if (index.value < items.value.length - 1) index.value++
195
+ else finish()
196
+ }
197
+
198
+ const result = computed<QuizResult>(() => {
199
+ let score = 0
200
+ let total = 0
201
+ const out: QuizResult['answers'] = {}
202
+ for (const it of items.value) {
203
+ const pts = it.q.points ?? 1
204
+ const v = answers.value[key(it)]
205
+ const ok = isCorrect(it, v)
206
+ total += pts
207
+ if (ok) score += pts
208
+ out[key(it)] = { value: v, correct: ok }
209
+ }
210
+ const percent = total ? Math.round((score / total) * 100) : 0
211
+ return { score, total, percent, passed: props.passScore === undefined || percent >= props.passScore, answers: out }
212
+ })
213
+
214
+ function finish() {
215
+ if (finished.value) return
216
+ // Unanswered questions still count, as wrong
217
+ for (const it of items.value) if (!checked.value[key(it)]) checked.value[key(it)] = true
218
+ finished.value = true
219
+ stopTimer()
220
+ emit('finish', result.value)
221
+ }
222
+
223
+ // ── timer ──
224
+ const remaining = ref<number | null>(null)
225
+ let timer: ReturnType<typeof setInterval> | null = null
226
+ function stopTimer() {
227
+ if (timer) clearInterval(timer)
228
+ timer = null
229
+ }
230
+ function startTimer() {
231
+ stopTimer()
232
+ if (!props.timeLimit) {
233
+ remaining.value = null
234
+ return
235
+ }
236
+ remaining.value = props.timeLimit
237
+ timer = setInterval(() => {
238
+ remaining.value = Math.max(0, (remaining.value ?? 0) - 1)
239
+ if (remaining.value === 0) finish()
240
+ }, 1000)
241
+ }
242
+ onBeforeUnmount(stopTimer)
243
+ const clock = computed(() => {
244
+ const s = remaining.value ?? 0
245
+ return `${Math.floor(s / 60)}:${String(s % 60).padStart(2, '0')}`
246
+ })
247
+
248
+ watch(() => props.questions, setup, { immediate: true })
249
+
250
+ // ── display helpers ──
251
+ function optionState(it: Item, i: number): 'correct' | 'wrong' | 'selected' | 'idle' {
252
+ const v = answers.value[key(it)]
253
+ const chosen = it.type === 'multiple' ? ((v as number[]) ?? []).includes(i) : v === i
254
+ if (checked.value[key(it)] && (props.feedback === 'immediate' || finished.value)) {
255
+ const right = it.type === 'multiple' ? ((it.q.answer as number[]) ?? []).includes(i) : it.q.answer === i
256
+ if (right) return 'correct'
257
+ if (chosen) return 'wrong'
258
+ return 'idle'
259
+ }
260
+ return chosen ? 'selected' : 'idle'
261
+ }
262
+
263
+ const showFeedback = computed(() => props.feedback === 'immediate' && isChecked.value && !!current.value)
264
+ const currentCorrect = computed(() => !!current.value && isCorrect(current.value, value.value))
265
+
266
+ function correctText(it: Item) {
267
+ const o = it.q.options ?? []
268
+ switch (it.type) {
269
+ case 'single': return o[it.q.answer as number] ?? ''
270
+ case 'multiple': return ((it.q.answer as number[]) ?? []).map((i) => o[i]).join(', ')
271
+ case 'truefalse': return it.q.answer ? locale.quizTrue : locale.quizFalse
272
+ case 'order': return o.join(' → ')
273
+ case 'text': return Array.isArray(it.q.answer) ? String(it.q.answer[0]) : String(it.q.answer ?? '')
274
+ }
275
+ }
276
+ function givenText(it: Item) {
277
+ const v = answers.value[key(it)]
278
+ const o = it.q.options ?? []
279
+ if (v === undefined || (Array.isArray(v) && !v.length) || v === '') return '—'
280
+ switch (it.type) {
281
+ case 'single': return o[v as number] ?? '—'
282
+ case 'multiple': return (v as number[]).map((i) => o[i]).join(', ')
283
+ case 'truefalse': return v ? locale.quizTrue : locale.quizFalse
284
+ case 'order': return (v as number[]).map((i) => o[i]).join(' → ')
285
+ case 'text': return String(v)
286
+ }
287
+ }
288
+
289
+ const progress = computed(() => (items.value.length ? ((index.value + (isChecked.value ? 1 : 0)) / items.value.length) * 100 : 0))
290
+
291
+ defineExpose({ restart: setup, result })
292
+ </script>
293
+
294
+ <template>
295
+ <div class="m3-quiz flex flex-col gap-4 text-on-surface">
296
+ <template v-if="!finished && current">
297
+ <div class="flex flex-col gap-2">
298
+ <div class="flex items-center gap-3 text-label-large text-on-surface-variant">
299
+ <span data-progress-text>{{ locale.quizQuestionOf.replace('{n}', String(index + 1)).replace('{total}', String(items.length)) }}</span>
300
+ <span
301
+ v-if="remaining !== null"
302
+ class="ms-auto flex items-center gap-1 tabular-nums"
303
+ :class="remaining <= 10 ? 'text-error' : ''"
304
+ role="timer"
305
+ :aria-label="`${locale.quizTimeLeft} ${clock}`"
306
+ data-timer
307
+ >
308
+ <MIcon name="timer" :size="18" />{{ clock }}
309
+ </span>
310
+ </div>
311
+ <div class="h-1 overflow-hidden rounded-full bg-secondary-container" role="progressbar" :aria-valuenow="Math.round(progress)" aria-valuemin="0" aria-valuemax="100">
312
+ <div class="h-full rounded-full bg-primary transition-[width] duration-300" :style="{ width: `${progress}%` }" />
313
+ </div>
314
+ </div>
315
+
316
+ <div :key="key(current)" class="m3-quiz__question flex flex-col gap-3">
317
+ <h3 class="text-title-large" data-prompt>{{ current.q.prompt }}</h3>
318
+ <img v-if="current.q.image" :src="current.q.image" alt="" class="max-h-64 w-full rounded-md object-cover" />
319
+ <p v-if="current.type === 'multiple'" class="text-body-medium text-on-surface-variant">{{ locale.quizSelectAll }}</p>
320
+ <p v-else-if="current.type === 'order'" class="text-body-medium text-on-surface-variant">{{ locale.quizOrderHint }}</p>
321
+
322
+ <!-- choices -->
323
+ <div
324
+ v-if="current.type === 'single' || current.type === 'multiple' || current.type === 'truefalse'"
325
+ class="flex gap-2"
326
+ :class="current.type === 'truefalse' ? 'flex-row' : 'flex-col'"
327
+ :role="current.type === 'multiple' ? 'group' : 'radiogroup'"
328
+ >
329
+ <template v-if="current.type === 'truefalse'">
330
+ <button
331
+ v-for="b in [true, false]"
332
+ :key="String(b)"
333
+ v-ripple
334
+ type="button"
335
+ role="radio"
336
+ :aria-checked="value === b"
337
+ class="m3-quiz__option relative flex flex-1 items-center justify-center gap-2 overflow-hidden rounded-md border px-4 py-3 text-body-large"
338
+ :data-state="isChecked && feedback === 'immediate' ? (current.q.answer === b ? 'correct' : value === b ? 'wrong' : 'idle') : value === b ? 'selected' : 'idle'"
339
+ :disabled="isChecked"
340
+ :data-option="String(b)"
341
+ @click="set(b)"
342
+ >
343
+ {{ b ? locale.quizTrue : locale.quizFalse }}
344
+ </button>
345
+ </template>
346
+ <button
347
+ v-for="i in current.order"
348
+ v-else
349
+ :key="i"
350
+ v-ripple
351
+ type="button"
352
+ :role="current.type === 'multiple' ? 'checkbox' : 'radio'"
353
+ :aria-checked="optionState(current, i) === 'selected' || (current.type === 'multiple' ? ((value as number[]) ?? []).includes(i) : value === i)"
354
+ class="m3-quiz__option relative flex items-center gap-3 overflow-hidden rounded-md border px-4 py-3 text-start text-body-large"
355
+ :data-state="optionState(current, i)"
356
+ :disabled="isChecked"
357
+ :data-option="i"
358
+ @click="current.type === 'multiple' ? toggleMulti(i) : set(i)"
359
+ >
360
+ <MIcon
361
+ :name="current.type === 'multiple'
362
+ ? (((value as number[]) ?? []).includes(i) ? 'check_box' : 'check_box_outline_blank')
363
+ : value === i ? 'radio_button_checked' : 'radio_button_unchecked'"
364
+ :size="22"
365
+ class="shrink-0"
366
+ />
367
+ <span class="flex-1">{{ current.q.options?.[i] }}</span>
368
+ <MIcon v-if="optionState(current, i) === 'correct'" name="check_circle" :size="22" class="text-success" />
369
+ <MIcon v-else-if="optionState(current, i) === 'wrong'" name="cancel" :size="22" class="text-error" />
370
+ </button>
371
+ </div>
372
+
373
+ <!-- order -->
374
+ <ol v-else-if="current.type === 'order'" class="flex flex-col gap-2">
375
+ <li
376
+ v-for="(opt, pos) in (value as number[])"
377
+ :key="opt"
378
+ class="m3-quiz__option flex items-center gap-2 rounded-md border px-3 py-1.5 text-body-large"
379
+ :data-state="isChecked && feedback === 'immediate' ? (opt === pos ? 'correct' : 'wrong') : 'idle'"
380
+ :data-order-item="opt"
381
+ >
382
+ <span class="w-6 text-center text-label-large text-on-surface-variant tabular-nums">{{ pos + 1 }}</span>
383
+ <span class="flex-1">{{ current.q.options?.[opt] }}</span>
384
+ <MIconButton icon="arrow_upward" size="sm" :aria-label="locale.quizMoveUp" :disabled="isChecked || pos === 0" data-move="up" @click="move(pos, -1)" />
385
+ <MIconButton icon="arrow_downward" size="sm" :aria-label="locale.quizMoveDown" :disabled="isChecked || pos === (value as number[]).length - 1" data-move="down" @click="move(pos, 1)" />
386
+ </li>
387
+ </ol>
388
+
389
+ <!-- text -->
390
+ <input
391
+ v-else
392
+ :value="(value as string) ?? ''"
393
+ type="text"
394
+ class="m3-quiz__input h-14 rounded-xs border border-outline bg-transparent px-4 text-body-large outline-none focus:border-2 focus:border-primary"
395
+ :class="isChecked && feedback === 'immediate' ? (currentCorrect ? 'border-success' : 'border-error') : ''"
396
+ :placeholder="locale.quizTypeAnswer"
397
+ :aria-label="locale.quizTypeAnswer"
398
+ :disabled="isChecked"
399
+ data-text-answer
400
+ @input="set(($event.target as HTMLInputElement).value)"
401
+ @keydown.enter="answered(current) && (feedback === 'immediate' && !isChecked ? check() : next())"
402
+ />
403
+
404
+ <div
405
+ v-if="showFeedback"
406
+ class="flex gap-3 rounded-md p-3"
407
+ :class="currentCorrect ? 'bg-success/12 text-on-surface' : 'bg-error-container text-on-error-container'"
408
+ role="status"
409
+ data-feedback
410
+ >
411
+ <MIcon :name="currentCorrect ? 'check_circle' : 'info'" :size="22" :class="currentCorrect ? 'text-success' : ''" />
412
+ <div class="flex flex-col gap-1">
413
+ <p class="text-title-small">{{ currentCorrect ? locale.quizCorrect : locale.quizIncorrect }}</p>
414
+ <p v-if="!currentCorrect && current.type !== 'single' && current.type !== 'multiple' && current.type !== 'truefalse'" class="text-body-medium">
415
+ {{ locale.quizCorrectAnswer.replace('{answer}', correctText(current)) }}
416
+ </p>
417
+ <p v-if="current.q.explanation" class="text-body-medium">{{ current.q.explanation }}</p>
418
+ </div>
419
+ </div>
420
+ </div>
421
+
422
+ <div class="flex justify-end gap-2">
423
+ <MButton
424
+ v-if="feedback === 'immediate' && !isChecked"
425
+ :disabled="!answered(current)"
426
+ data-action="check"
427
+ @click="check"
428
+ >{{ locale.quizCheck }}</MButton>
429
+ <MButton
430
+ v-else
431
+ :disabled="feedback === 'end' && !answered(current)"
432
+ :icon="index === items.length - 1 ? 'flag' : 'arrow_forward'"
433
+ data-action="next"
434
+ @click="next"
435
+ >{{ index === items.length - 1 ? locale.quizFinish : locale.quizNext }}</MButton>
436
+ </div>
437
+ </template>
438
+
439
+ <template v-else-if="finished">
440
+ <slot name="result" :result="result" :retry="setup">
441
+ <div class="flex flex-col items-center gap-2 py-4 text-center" data-result>
442
+ <div class="relative h-32 w-32">
443
+ <svg viewBox="0 0 36 36" class="h-full w-full -rotate-90">
444
+ <circle cx="18" cy="18" r="15.9" fill="none" class="stroke-secondary-container" stroke-width="3" />
445
+ <circle
446
+ cx="18"
447
+ cy="18"
448
+ r="15.9"
449
+ fill="none"
450
+ :class="result.passed ? 'stroke-primary' : 'stroke-error'"
451
+ stroke-width="3"
452
+ stroke-linecap="round"
453
+ :stroke-dasharray="`${result.percent} 100`"
454
+ />
455
+ </svg>
456
+ <span class="absolute inset-0 flex items-center justify-center text-headline-medium font-medium tabular-nums">{{ result.percent }}%</span>
457
+ </div>
458
+ <p v-if="passScore !== undefined" class="text-title-large" :class="result.passed ? 'text-primary' : 'text-error'" data-passed>
459
+ {{ result.passed ? locale.quizPassed : locale.quizFailed }}
460
+ </p>
461
+ <p class="text-body-large text-on-surface-variant" data-score>
462
+ {{ locale.quizScore.replace('{score}', String(result.score)).replace('{total}', String(result.total)) }}
463
+ </p>
464
+ <MButton v-if="allowRetry" variant="tonal" icon="replay" class="mt-2" data-action="retry" @click="setup">{{ locale.quizRetry }}</MButton>
465
+ </div>
466
+ </slot>
467
+
468
+ <div v-if="review" class="flex flex-col gap-2">
469
+ <h4 class="text-title-medium">{{ locale.quizReview }}</h4>
470
+ <ol class="flex flex-col divide-y divide-outline-variant rounded-md border border-outline-variant">
471
+ <li v-for="(it, i) in items" :key="key(it)" class="flex gap-3 p-3" :data-review="key(it)">
472
+ <MIcon
473
+ :name="result.answers[key(it)]?.correct ? 'check_circle' : 'cancel'"
474
+ :size="22"
475
+ :class="result.answers[key(it)]?.correct ? 'text-success' : 'text-error'"
476
+ />
477
+ <div class="flex min-w-0 flex-1 flex-col gap-0.5">
478
+ <p class="text-body-large">{{ i + 1 }}. {{ it.q.prompt }}</p>
479
+ <p class="text-body-medium text-on-surface-variant">{{ locale.quizTypeAnswer }}: {{ givenText(it) }}</p>
480
+ <p v-if="!result.answers[key(it)]?.correct" class="text-body-medium text-on-surface-variant">
481
+ {{ locale.quizCorrectAnswer.replace('{answer}', correctText(it)) }}
482
+ </p>
483
+ <p v-if="it.q.explanation" class="text-body-small text-on-surface-variant">{{ it.q.explanation }}</p>
484
+ </div>
485
+ </li>
486
+ </ol>
487
+ </div>
488
+ </template>
489
+ </div>
490
+ </template>
491
+
492
+ <style>
493
+ .m3-quiz__option {
494
+ border-color: var(--color-outline-variant);
495
+ transition: background-color 150ms ease, border-color 150ms ease;
496
+ }
497
+ .m3-quiz__option:not(:disabled):hover {
498
+ background-color: color-mix(in srgb, var(--color-on-surface) 8%, transparent);
499
+ }
500
+ .m3-quiz__option[data-state='selected'] {
501
+ border-color: var(--color-primary);
502
+ background-color: var(--color-secondary-container);
503
+ color: var(--color-on-secondary-container);
504
+ }
505
+ .m3-quiz__option[data-state='correct'] {
506
+ border-color: var(--color-success);
507
+ border-width: 2px;
508
+ background-color: color-mix(in srgb, var(--color-success) 12%, transparent);
509
+ }
510
+ .m3-quiz__option[data-state='wrong'] {
511
+ border-color: var(--color-error);
512
+ border-width: 2px;
513
+ background-color: color-mix(in srgb, var(--color-error) 10%, transparent);
514
+ }
515
+ .m3-quiz__option:disabled {
516
+ cursor: default;
517
+ }
518
+ .m3-quiz__option:focus-visible {
519
+ outline: 3px solid var(--color-secondary);
520
+ outline-offset: 2px;
521
+ }
522
+ .m3-quiz__question {
523
+ animation: m3-quiz-in 250ms cubic-bezier(0.2, 0, 0, 1);
524
+ }
525
+ @keyframes m3-quiz-in {
526
+ from { opacity: 0; transform: translateX(16px); }
527
+ }
528
+ @media (prefers-reduced-motion: reduce) {
529
+ .m3-quiz__question { animation: none; }
530
+ }
531
+ </style>