@enspiredigital/xlms-headless 0.0.31 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,178 +1,178 @@
1
- import { useState as A, useRef as O, useEffect as D, useMemo as F, useCallback as B } from "react";
2
- import { jsx as z, Fragment as G } from "react/jsx-runtime";
3
- function E() {
4
- const [t, n] = A(null), [u, f] = A(null), [m, C] = A(0);
5
- function S(l) {
6
- n(!0), l !== void 0 && f(l), C((b) => b + 1);
1
+ import { useState as C, useRef as j, useEffect as D, useMemo as F, useCallback as B } from "react";
2
+ import { jsx as G, Fragment as $ } from "react/jsx-runtime";
3
+ function L() {
4
+ const [t, s] = C(null), [i, d] = C(null), [g, S] = C(0);
5
+ function x(f) {
6
+ s(!0), f !== void 0 && d(f), S((w) => w + 1);
7
7
  }
8
8
  function o() {
9
- n(!1), f(null);
9
+ s(!1), d(null);
10
10
  }
11
11
  return {
12
12
  // state
13
13
  submitted: t,
14
- isCorrect: u,
15
- attempts: m,
14
+ isCorrect: i,
15
+ attempts: g,
16
16
  // derived
17
17
  canAnswer: !t,
18
18
  // actions
19
- submitQuestion: S,
19
+ submitQuestion: x,
20
20
  resetQuestion: o
21
21
  };
22
22
  }
23
- function J(t, n) {
24
- if (t.length !== n.length) return !1;
25
- const u = new Set(t), f = new Set(n);
26
- if (u.size !== f.size) return !1;
27
- for (const m of u)
28
- if (!f.has(m)) return !1;
23
+ function J(t, s) {
24
+ if (t.length !== s.length) return !1;
25
+ const i = new Set(t), d = new Set(s);
26
+ if (i.size !== d.size) return !1;
27
+ for (const g of i)
28
+ if (!d.has(g)) return !1;
29
29
  return !0;
30
30
  }
31
31
  function V(t) {
32
- const n = [...t];
33
- for (let u = n.length - 1; u > 0; u--) {
34
- const f = Math.floor(Math.random() * (u + 1));
35
- [n[u], n[f]] = [n[f], n[u]];
32
+ const s = [...t];
33
+ for (let i = s.length - 1; i > 0; i--) {
34
+ const d = Math.floor(Math.random() * (i + 1));
35
+ [s[i], s[d]] = [s[d], s[i]];
36
36
  }
37
- return n;
37
+ return s;
38
38
  }
39
39
  function X(t) {
40
40
  const {
41
- canAnswer: n,
42
- submitted: u,
43
- isCorrect: f,
44
- attempts: m,
45
- resetQuestion: C,
46
- submitQuestion: S
47
- } = E(), [o, l] = A([]);
48
- function b(w) {
49
- l((p) => t.options.allowMultipleAnswers ? p.includes(w) ? p.filter((d) => d !== w) : [...p, w] : [w]);
41
+ canAnswer: s,
42
+ submitted: i,
43
+ isCorrect: d,
44
+ attempts: g,
45
+ resetQuestion: S,
46
+ submitQuestion: x
47
+ } = L(), [o, f] = C([]);
48
+ function w(b) {
49
+ f((m) => t.options.allowMultipleAnswers ? m.includes(b) ? m.filter((p) => p !== b) : [...m, b] : [b]);
50
50
  }
51
51
  function I() {
52
52
  if (o.length === 0) return;
53
- const w = t.options.answers.reduce(
54
- (d, x) => (x.is_correct && d.push(x.id), d),
53
+ const b = t.options.answers.reduce(
54
+ (p, A) => (A.is_correct && p.push(A.id), p),
55
55
  []
56
- ), p = J(o, w);
57
- S(p);
56
+ ), m = J(o, b);
57
+ x(m);
58
58
  }
59
- function Q() {
60
- l([]), C();
59
+ function k() {
60
+ f([]), S();
61
61
  }
62
62
  return {
63
63
  // data
64
64
  question: t,
65
65
  selectedIds: o,
66
66
  // actions
67
- select: b,
67
+ select: w,
68
68
  submit: I,
69
- reset: Q,
69
+ reset: k,
70
70
  // base
71
- submitted: u,
72
- isCorrect: f,
73
- attempts: m,
74
- canAnswer: n
71
+ submitted: i,
72
+ isCorrect: d,
73
+ attempts: g,
74
+ canAnswer: s
75
75
  };
76
76
  }
77
77
  function Y(t) {
78
78
  const {
79
- canAnswer: n,
80
- submitted: u,
81
- isCorrect: f,
82
- attempts: m,
83
- submitQuestion: C,
84
- resetQuestion: S
85
- } = E(), [o, l] = A([]), [b, I] = A(
79
+ canAnswer: s,
80
+ submitted: i,
81
+ isCorrect: d,
82
+ attempts: g,
83
+ submitQuestion: S,
84
+ resetQuestion: x
85
+ } = L(), [o, f] = C([]), [w, I] = C(
86
86
  []
87
- ), [Q, w] = A(
87
+ ), [k, b] = C(
88
88
  []
89
- ), p = O([]);
90
- function d(e, r) {
91
- l((c) => [
92
- ...c.filter(
93
- (g) => g.targetId !== e && g.sourceId !== r
89
+ ), m = j([]);
90
+ function p(n, e) {
91
+ f((r) => [
92
+ ...r.filter(
93
+ (l) => l.targetId !== n && l.sourceId !== e
94
94
  ),
95
- { targetId: e, sourceId: r }
95
+ { targetId: n, sourceId: e }
96
96
  ]);
97
97
  }
98
- function x(e, r) {
99
- l(
100
- (c) => c.filter((g) => g.targetId !== e || g.sourceId !== r)
98
+ function A(n, e) {
99
+ f(
100
+ (r) => r.filter((l) => l.targetId !== n || l.sourceId !== e)
101
101
  );
102
102
  }
103
103
  function h() {
104
- let e = 0, r = !0;
105
- return t.options.targets.forEach((c) => {
106
- const g = o.find((U) => U.targetId === c.id), v = t.options.sources[c.content.correct_position - 1];
107
- g && v && g.sourceId === v.id ? e += c.content.point : r = !1;
104
+ let n = 0, e = !0;
105
+ return t.options.targets.forEach((r) => {
106
+ const l = o.find((Q) => Q.targetId === r.id), v = t.options.sources[r.content.correct_position - 1];
107
+ l && v && l.sourceId === v.id ? n += r.content.point : e = !1;
108
108
  }), {
109
- isCorrect: r,
110
- score: e,
109
+ isCorrect: e,
110
+ score: n,
111
111
  maxScore: t.options.targets.reduce(
112
- (c, g) => c + g.content.point,
112
+ (r, l) => r + l.content.point,
113
113
  0
114
114
  )
115
115
  };
116
116
  }
117
- function s() {
118
- const e = h();
119
- return C(e.isCorrect), e;
117
+ function u() {
118
+ const n = h();
119
+ return S(n.isCorrect), n;
120
120
  }
121
- function a() {
122
- l([]), S();
121
+ function c() {
122
+ f([]), x();
123
123
  }
124
- function i(e) {
125
- const r = o.find((c) => c.sourceId === e)?.targetId;
126
- return t.options.targets.find((c) => c.id === r);
124
+ function a(n) {
125
+ const e = o.find((r) => r.sourceId === n)?.targetId;
126
+ return t.options.targets.find((r) => r.id === e);
127
127
  }
128
128
  return D(() => {
129
- const e = t.options.sources.filter(
130
- (r) => !o.some((c) => c.sourceId === r.id)
129
+ const n = t.options.sources.filter(
130
+ (e) => !o.some((r) => r.sourceId === e.id)
131
131
  );
132
- I(e);
132
+ I(n);
133
133
  }, [o, t.options.sources]), D(() => {
134
- if (p.current.length === 0) return;
135
- const e = p.current.filter(
136
- (r) => !o.some((c) => c.targetId === r.id)
134
+ if (m.current.length === 0) return;
135
+ const n = m.current.filter(
136
+ (e) => !o.some((r) => r.targetId === e.id)
137
137
  );
138
- w(e);
138
+ b(n);
139
139
  }, [o]), D(() => {
140
- p.current = V(t.options.targets);
140
+ m.current = V(t.options.targets);
141
141
  }, [t.options.targets]), {
142
142
  // data
143
143
  sources: t.options.sources,
144
144
  targets: t.options.targets,
145
145
  answers: o,
146
146
  question: t,
147
- availableSources: b,
148
- availableTargets: Q,
147
+ availableSources: w,
148
+ availableTargets: k,
149
149
  // base
150
- submitted: u,
151
- isCorrect: f,
152
- attempts: m,
153
- canAnswer: n,
150
+ submitted: i,
151
+ isCorrect: d,
152
+ attempts: g,
153
+ canAnswer: s,
154
154
  // actions
155
- getTargetBySourceId: i,
156
- select: d,
157
- remove: x,
158
- submit: s,
159
- reset: a
155
+ getTargetBySourceId: a,
156
+ select: p,
157
+ remove: A,
158
+ submit: u,
159
+ reset: c
160
160
  };
161
161
  }
162
162
  function Z(t) {
163
163
  const {
164
- canAnswer: n,
165
- submitted: u,
166
- isCorrect: f,
167
- attempts: m,
168
- resetQuestion: C,
169
- submitQuestion: S
170
- } = E();
164
+ canAnswer: s,
165
+ submitted: i,
166
+ isCorrect: d,
167
+ attempts: g,
168
+ resetQuestion: S,
169
+ submitQuestion: x
170
+ } = L();
171
171
  function o() {
172
- S(!0);
172
+ x(!0);
173
173
  }
174
- function l() {
175
- C();
174
+ function f() {
175
+ S();
176
176
  }
177
177
  return {
178
178
  // data
@@ -181,33 +181,30 @@ function Z(t) {
181
181
  type: t.options.urlType,
182
182
  // actions
183
183
  submit: o,
184
- reset: l,
184
+ reset: f,
185
185
  // base
186
- submitted: u,
187
- isCorrect: f,
188
- attempts: m,
189
- canAnswer: n
186
+ submitted: i,
187
+ isCorrect: d,
188
+ attempts: g,
189
+ canAnswer: s
190
190
  };
191
191
  }
192
192
  function K(t) {
193
193
  const {
194
- canAnswer: n,
195
- submitted: u,
196
- isCorrect: f,
197
- attempts: m,
198
- submitQuestion: C,
199
- resetQuestion: S
200
- } = E(), [o, l] = A([]), [b, I] = A(null), Q = O([]), w = F(() => {
201
- if (Q.current.length === 0) return;
194
+ canAnswer: s,
195
+ submitted: i,
196
+ isCorrect: d,
197
+ attempts: g,
198
+ submitQuestion: S,
199
+ resetQuestion: x
200
+ } = L(), [o, f] = C([]), [w, I] = C(null), [k, b] = C([]), m = F(() => {
202
201
  const e = new Set(o.map((r) => r.itemId));
203
- return Q.current.filter(
204
- (r) => !e.has(String(r.id))
205
- );
206
- }, [o]);
202
+ return k.filter((r) => !e.has(String(r.id)));
203
+ }, [o, k]);
207
204
  function p(e, r) {
208
- l((c) => [
209
- ...c.filter(
210
- (v) => v.blankIndex !== r && v.itemId !== e
205
+ f((l) => [
206
+ ...l.filter(
207
+ (Q) => Q.blankIndex !== r && Q.itemId !== e
211
208
  ),
212
209
  {
213
210
  itemId: e,
@@ -215,213 +212,212 @@ function K(t) {
215
212
  }
216
213
  ]);
217
214
  }
218
- function d(e) {
219
- l((r) => r.filter((c) => c.itemId !== e));
215
+ function A(e) {
216
+ f((r) => r.filter((l) => l.itemId !== e));
220
217
  }
221
- function x(e, r) {
218
+ function h(e, r) {
222
219
  p(e, r);
223
220
  }
224
- function h() {
225
- let e = 0, r = !0, c = 0;
226
- const g = t.correct_answers.list, v = new Map(o.map((U) => [U.blankIndex, U.itemId]));
227
- return Object.entries(g).forEach(([U, k]) => {
228
- const _ = U, T = v.get(_);
221
+ function u() {
222
+ let e = 0, r = !0, l = 0;
223
+ const v = t.correct_answers.list, Q = new Map(o.map((R) => [R.blankIndex, R.itemId]));
224
+ return Object.entries(v).forEach(([R, M]) => {
225
+ const _ = R, T = Q.get(_);
229
226
  if (!T) {
230
227
  r = !1;
231
228
  return;
232
229
  }
233
- const M = t.options.answers.find((j) => j.id === T);
234
- M && String(M.group_position) === String(k) ? (e++, c += M.point) : r = !1;
230
+ const E = t.options.answers.find((z) => z.id === T);
231
+ E && String(E.group_position) === String(M) ? (e++, l += E.point) : r = !1;
235
232
  }), {
236
233
  isCorrect: r,
237
234
  correctCount: e,
238
- totalCount: Object.keys(g).length,
235
+ totalCount: Object.keys(v).length,
239
236
  maxScore: t.metadata.points,
240
- score: c
237
+ score: l
241
238
  };
242
239
  }
243
- function s() {
244
- const e = h();
245
- return C(e.isCorrect), e;
240
+ function c() {
241
+ const e = u();
242
+ return S(e.isCorrect), e;
246
243
  }
247
244
  function a() {
248
- l([]), S();
245
+ f([]), x();
249
246
  }
250
- function i(e) {
251
- const r = o.find((c) => c.blankIndex === e)?.itemId;
252
- return t.options.answers.find((c) => c.id === r);
247
+ function n(e) {
248
+ const r = o.find((l) => l.blankIndex === e)?.itemId;
249
+ return t.options.answers.find((l) => l.id === r);
253
250
  }
254
251
  return D(() => {
255
- Q.current = V(t.options.answers);
252
+ b(V(t.options.answers));
256
253
  }, [t.options.answers]), {
257
254
  // data
258
255
  items: t.options.answers,
259
256
  groups: t.options.groups,
260
257
  answers: o,
261
- availableItems: w,
258
+ availableItems: m,
262
259
  question: t,
263
- draggingItemId: b,
260
+ draggingItemId: w,
264
261
  // base
265
- submitted: u,
266
- isCorrect: f,
267
- attempts: m,
268
- canAnswer: n,
262
+ submitted: i,
263
+ isCorrect: d,
264
+ attempts: g,
265
+ canAnswer: s,
269
266
  // actions
270
267
  dropItem: p,
271
- removeItem: d,
272
- moveItem: x,
268
+ removeItem: A,
269
+ moveItem: h,
273
270
  setDraggingItemId: I,
274
- getItemByBlankId: i,
275
- submit: s,
271
+ getItemByBlankId: n,
272
+ submit: c,
276
273
  reset: a
277
274
  };
278
275
  }
279
276
  function H(t) {
280
277
  const {
281
- canAnswer: n,
282
- submitted: u,
283
- isCorrect: f,
284
- attempts: m,
285
- submitQuestion: C,
286
- resetQuestion: S
287
- } = E(), [o, l] = A(() => V(
288
- t.options.answers.map((s) => String(s.id))
289
- )), b = F(() => o.map(
290
- (s) => t.options.answers.find((a) => String(a.id) === s)
291
- ).filter((s) => s !== void 0), [o, t.options.answers]);
292
- function I(s, a) {
293
- l((i) => {
294
- const e = [...i], [r] = e.splice(s, 1);
295
- return e.splice(a, 0, r), e;
278
+ canAnswer: s,
279
+ submitted: i,
280
+ isCorrect: d,
281
+ attempts: g,
282
+ submitQuestion: S,
283
+ resetQuestion: x
284
+ } = L(), [o, f] = C(() => V(
285
+ t.options.answers.map((u) => String(u.id))
286
+ )), w = F(() => o.map(
287
+ (u) => t.options.answers.find((c) => String(c.id) === u)
288
+ ).filter((u) => u !== void 0), [o, t.options.answers]);
289
+ function I(u, c) {
290
+ f((a) => {
291
+ const n = [...a], [e] = n.splice(u, 1);
292
+ return n.splice(c, 0, e), n;
296
293
  });
297
294
  }
298
- function Q(s) {
299
- const a = o.indexOf(s);
300
- a > 0 && I(a, a - 1);
295
+ function k(u) {
296
+ const c = o.indexOf(u);
297
+ c > 0 && I(c, c - 1);
301
298
  }
302
- function w(s) {
303
- const a = o.indexOf(s);
304
- a < o.length - 1 && I(a, a + 1);
299
+ function b(u) {
300
+ const c = o.indexOf(u);
301
+ c < o.length - 1 && I(c, c + 1);
305
302
  }
306
- function p(s, a) {
307
- const i = o.indexOf(s);
308
- i !== -1 && a >= 0 && a < o.length && I(i, a);
303
+ function m(u, c) {
304
+ const a = o.indexOf(u);
305
+ a !== -1 && c >= 0 && c < o.length && I(a, c);
309
306
  }
310
- function d() {
311
- let s = 0, a = !0;
312
- return t.options.answers.forEach((i, e) => {
313
- const r = o.indexOf(String(i.id));
314
- r !== -1 && r + 1 === i.correct_position ? s += i.point : a = !1;
307
+ function p() {
308
+ let u = 0, c = !0;
309
+ return t.options.answers.forEach((a, n) => {
310
+ const e = o.indexOf(String(a.id));
311
+ e !== -1 && e + 1 === a.correct_position ? u += a.point : c = !1;
315
312
  }), {
316
- isCorrect: a,
317
- score: s,
313
+ isCorrect: c,
314
+ score: u,
318
315
  maxScore: t.options.answers.reduce(
319
- (i, e) => i + e.point,
316
+ (a, n) => a + n.point,
320
317
  0
321
318
  )
322
319
  };
323
320
  }
324
- function x() {
325
- const s = d();
326
- return C(s.isCorrect), s;
321
+ function A() {
322
+ const u = p();
323
+ return S(u.isCorrect), u;
327
324
  }
328
325
  function h() {
329
- l(t.options.answers.map((s) => String(s.id))), S();
326
+ f(t.options.answers.map((u) => String(u.id))), x();
330
327
  }
331
328
  return {
332
329
  // data
333
330
  items: t.options.answers,
334
331
  groups: t.options.groups,
335
- orderedItems: b,
332
+ orderedItems: w,
336
333
  orderedItemIds: o,
337
334
  question: t,
338
335
  // base
339
- submitted: u,
340
- isCorrect: f,
341
- attempts: m,
342
- canAnswer: n,
336
+ submitted: i,
337
+ isCorrect: d,
338
+ attempts: g,
339
+ canAnswer: s,
343
340
  // actions
344
- setOrderedItemIds: l,
341
+ setOrderedItemIds: f,
345
342
  moveItem: I,
346
- moveUp: Q,
347
- moveDown: w,
348
- moveToPosition: p,
349
- submit: x,
343
+ moveUp: k,
344
+ moveDown: b,
345
+ moveToPosition: m,
346
+ submit: A,
350
347
  reset: h
351
348
  };
352
349
  }
353
350
  function q(t) {
354
351
  const {
355
- canAnswer: n,
356
- submitted: u,
357
- isCorrect: f,
358
- attempts: m,
359
- submitQuestion: C,
360
- resetQuestion: S
361
- } = E(), [o, l] = A([]), b = O([]), I = F(() => {
362
- if (b.current.length === 0) return;
363
- const i = new Set(o.map((e) => e.labelId));
364
- return b.current.filter(
365
- (e) => !i.has(String(e.id))
352
+ canAnswer: s,
353
+ submitted: i,
354
+ isCorrect: d,
355
+ attempts: g,
356
+ submitQuestion: S,
357
+ resetQuestion: x
358
+ } = L(), [o, f] = C([]), [w, I] = C([]), k = F(() => {
359
+ const n = new Set(o.map((e) => e.labelId));
360
+ return w.filter(
361
+ (e) => !n.has(String(e.id))
366
362
  );
367
- }, [o]);
368
- function Q(i, e, r, c) {
369
- const g = t.options.blanks.find((v) => String(v.id) === e);
370
- g && l((v) => [
371
- ...v.filter(
372
- (k) => k.labelId !== i && k.blankId !== e
363
+ }, [o, w]);
364
+ function b(n, e, r, l) {
365
+ const v = t.options.blanks.find((Q) => String(Q.id) === e);
366
+ v && f((Q) => [
367
+ ...Q.filter(
368
+ (M) => M.labelId !== n && M.blankId !== e
373
369
  ),
374
370
  {
375
- labelId: i,
371
+ labelId: n,
376
372
  blankId: e,
377
- x: r ?? g.coordinates.x,
378
- y: c ?? g.coordinates.y
373
+ x: r ?? v.coordinates.x,
374
+ y: l ?? v.coordinates.y
379
375
  }
380
376
  ]);
381
377
  }
382
- function w(i) {
383
- l((e) => e.filter((r) => r.labelId !== i));
378
+ function m(n) {
379
+ f((e) => e.filter((r) => r.labelId !== n));
384
380
  }
385
- function p(i, e, r, c) {
386
- Q(i, e, r, c);
381
+ function p(n, e, r, l) {
382
+ b(n, e, r, l);
387
383
  }
388
- function d(i) {
389
- const e = o.find((r) => r.blankId === i);
384
+ function A(n) {
385
+ const e = o.find((r) => r.blankId === n);
390
386
  return e && t.options.labels.find(
391
387
  (r) => String(r.id) === e.labelId
392
388
  ) || null;
393
389
  }
394
- function x(i) {
395
- const e = o.find((r) => r.labelId === i);
390
+ function h(n) {
391
+ const e = o.find((r) => r.labelId === n);
396
392
  return e ? e.blankId : null;
397
393
  }
398
- function h() {
399
- let i = 0, e = !0;
394
+ function u() {
395
+ let n = 0, e = !0;
400
396
  return t.options.labels.forEach((r) => {
401
- const c = o.find(
402
- (v) => String(v.labelId) === String(r.id)
403
- ), g = t.options.blanks.find(
404
- (v, U) => U + 1 === r.correct_position
397
+ const l = o.find(
398
+ (Q) => String(Q.labelId) === String(r.id)
399
+ ), v = t.options.blanks.find(
400
+ (Q, R) => R + 1 === r.correct_position
405
401
  );
406
- c && g && c.blankId === String(g.id) ? i += r.point : e = !1;
402
+ l && v && l.blankId === String(v.id) ? n += r.point : e = !1;
407
403
  }), {
408
404
  isCorrect: e,
409
- score: i,
405
+ score: n,
410
406
  maxScore: t.options.labels.reduce(
411
- (r, c) => r + c.point,
407
+ (r, l) => r + l.point,
412
408
  0
413
409
  )
414
410
  };
415
411
  }
416
- function s() {
417
- const i = h();
418
- return C(i.isCorrect), i;
412
+ function c() {
413
+ const n = u();
414
+ return S(n.isCorrect), n;
419
415
  }
420
416
  function a() {
421
- l([]), S();
417
+ f([]), x();
422
418
  }
423
419
  return D(() => {
424
- b.current = V(t.options.labels);
420
+ I(V(t.options.labels));
425
421
  }, [t.options.labels]), {
426
422
  // data
427
423
  labels: t.options.labels,
@@ -430,66 +426,66 @@ function q(t) {
430
426
  imageWidth: t.image_width,
431
427
  imageHeight: t.image_height,
432
428
  answers: o,
433
- availableLabels: I,
429
+ availableLabels: k,
434
430
  question: t,
435
431
  // base
436
- submitted: u,
437
- isCorrect: f,
438
- attempts: m,
439
- canAnswer: n,
432
+ submitted: i,
433
+ isCorrect: d,
434
+ attempts: g,
435
+ canAnswer: s,
440
436
  // actions
441
- attachLabel: Q,
442
- removeLabel: w,
437
+ attachLabel: b,
438
+ removeLabel: m,
443
439
  moveLabel: p,
444
- getLabelAtBlank: d,
445
- getBlankForLabel: x,
446
- submit: s,
440
+ getLabelAtBlank: A,
441
+ getBlankForLabel: h,
442
+ submit: c,
447
443
  reset: a
448
444
  };
449
445
  }
450
446
  function tt(t) {
451
447
  const {
452
- canAnswer: n,
453
- submitted: u,
454
- isCorrect: f,
455
- attempts: m,
456
- submitQuestion: C,
457
- resetQuestion: S
458
- } = E(), [o, l] = A([]);
459
- function b(p, d) {
460
- l((x) => {
461
- const h = x.findIndex((s) => s.blankId === p);
448
+ canAnswer: s,
449
+ submitted: i,
450
+ isCorrect: d,
451
+ attempts: g,
452
+ submitQuestion: S,
453
+ resetQuestion: x
454
+ } = L(), [o, f] = C([]);
455
+ function w(m, p) {
456
+ f((A) => {
457
+ const h = A.findIndex((u) => u.blankId === m);
462
458
  if (h >= 0) {
463
- const s = [...x];
464
- return s[h] = { blankId: p, value: d }, s;
459
+ const u = [...A];
460
+ return u[h] = { blankId: m, value: p }, u;
465
461
  }
466
- return [...x, { blankId: p, value: d }];
462
+ return [...A, { blankId: m, value: p }];
467
463
  });
468
464
  }
469
465
  function I() {
470
- let p = 0, d = 0, x = 0;
471
- const h = t.correct_answers.list || {}, s = Object.keys(h).length;
472
- Object.entries(h).forEach(([i, e]) => {
473
- const r = String(e).trim().toLowerCase(), c = t.options.answers.find(
474
- (k) => k.correct_position === Number(i)
475
- ), g = c && c.point || 1;
476
- x += g;
477
- const v = o.find((k) => k.blankId === i);
478
- (v ? String(v.value).trim().toLowerCase() : "") === r && (p += g, d++);
466
+ let m = 0, p = 0, A = 0;
467
+ const h = t.correct_answers.list || {}, u = Object.keys(h).length;
468
+ Object.entries(h).forEach(([a, n]) => {
469
+ const e = String(n).trim().toLowerCase(), r = t.options.answers.find(
470
+ (R) => R.correct_position === Number(a)
471
+ ), l = r && r.point || 1;
472
+ A += l;
473
+ const v = o.find((R) => R.blankId === a);
474
+ (v ? String(v.value).trim().toLowerCase() : "") === e && (m += l, p++);
479
475
  });
480
- const a = d === s && s > 0;
481
- return x === 0 && s > 0 && (x = s), {
482
- isCorrect: a,
483
- score: Math.round(p * 100) / 100,
484
- maxScore: Math.round(x * 100) / 100
476
+ const c = p === u && u > 0;
477
+ return A === 0 && u > 0 && (A = u), {
478
+ isCorrect: c,
479
+ score: Math.round(m * 100) / 100,
480
+ maxScore: Math.round(A * 100) / 100
485
481
  };
486
482
  }
487
- function Q() {
488
- const p = I();
489
- return C(p.isCorrect), p;
483
+ function k() {
484
+ const m = I();
485
+ return S(m.isCorrect), m;
490
486
  }
491
- function w() {
492
- l([]), S();
487
+ function b() {
488
+ f([]), x();
493
489
  }
494
490
  return {
495
491
  // data
@@ -497,108 +493,108 @@ function tt(t) {
497
493
  answers: o,
498
494
  question: t,
499
495
  // base
500
- submitted: u,
501
- isCorrect: f,
502
- attempts: m,
503
- canAnswer: n,
496
+ submitted: i,
497
+ isCorrect: d,
498
+ attempts: g,
499
+ canAnswer: s,
504
500
  // actions
505
- answer: b,
506
- submit: Q,
507
- reset: w
501
+ answer: w,
502
+ submit: k,
503
+ reset: b
508
504
  };
509
505
  }
510
506
  function et(t) {
511
507
  const {
512
- canAnswer: n,
513
- submitted: u,
514
- isCorrect: f,
515
- attempts: m,
516
- submitQuestion: C,
517
- resetQuestion: S
518
- } = E(), [o, l] = A([]), b = O([]);
519
- function I(s, a) {
520
- l((i) => {
521
- const e = i.findIndex((r) => r.itemId === s);
508
+ canAnswer: s,
509
+ submitted: i,
510
+ isCorrect: d,
511
+ attempts: g,
512
+ submitQuestion: S,
513
+ resetQuestion: x
514
+ } = L(), [o, f] = C([]), [w, I] = C([]);
515
+ function k(c, a) {
516
+ f((n) => {
517
+ const e = n.findIndex((r) => r.itemId === c);
522
518
  if (e >= 0) {
523
- const r = [...i];
524
- return r[e] = { itemId: s, categoryId: a }, r;
519
+ const r = [...n];
520
+ return r[e] = { itemId: c, categoryId: a }, r;
525
521
  }
526
- return [...i, { itemId: s, categoryId: a }];
522
+ return [...n, { itemId: c, categoryId: a }];
527
523
  });
528
524
  }
529
- function Q(s) {
530
- l((a) => a.filter((i) => i.itemId !== s));
525
+ function b(c) {
526
+ f((a) => a.filter((n) => n.itemId !== c));
531
527
  }
532
- function w() {
533
- let s = 0, a = 0;
528
+ function m() {
529
+ let c = 0, a = 0;
534
530
  const e = t.correct_answers.list || {}, r = Object.keys(e).length;
535
- let c = 0;
536
- return Object.entries(e).forEach(([v, U]) => {
537
- const k = t.options.items.find((M) => M.id === v), _ = k ? k.point : 0;
538
- c += _;
539
- const T = o.find((M) => M.itemId === v);
540
- T && T.categoryId === U && (s += _, a++);
541
- }), s = Math.round(s * 100) / 100, c = Math.round(c * 100) / 100, {
531
+ let l = 0;
532
+ return Object.entries(e).forEach(([Q, R]) => {
533
+ const M = t.options.items.find((E) => E.id === Q), _ = M ? M.point : 0;
534
+ l += _;
535
+ const T = o.find((E) => E.itemId === Q);
536
+ T && T.categoryId === R && (c += _, a++);
537
+ }), c = Math.round(c * 100) / 100, l = Math.round(l * 100) / 100, {
542
538
  isCorrect: a === r && r > 0,
543
- score: s,
544
- maxScore: c
539
+ score: c,
540
+ maxScore: l
545
541
  };
546
542
  }
547
543
  function p() {
548
- const s = w();
549
- return C(s.isCorrect), s;
544
+ const c = m();
545
+ return S(c.isCorrect), c;
550
546
  }
551
- function d() {
552
- l([]), S();
547
+ function A() {
548
+ f([]), x();
553
549
  }
554
- const x = F(() => b.current.filter(
555
- (s) => !o.some((a) => a.itemId === s.id)
556
- ), [o]), h = F(() => t.options.categories.map((s) => {
557
- const a = o.filter((i) => i.categoryId === s.id).map((i) => ({
558
- ...t.options.items.find((r) => r.id === i.itemId)
550
+ const h = F(() => w.filter(
551
+ (c) => !o.some((a) => a.itemId === c.id)
552
+ ), [o, w]), u = F(() => t.options.categories.map((c) => {
553
+ const a = o.filter((n) => n.categoryId === c.id).map((n) => ({
554
+ ...t.options.items.find((r) => r.id === n.itemId)
559
555
  }));
560
556
  return {
561
- ...s,
557
+ ...c,
562
558
  items: a
563
559
  };
564
560
  }), [t.options.categories, t.options.items, o]);
565
561
  return D(() => {
566
- b.current = V(t.options.items);
562
+ I(V(t.options.items));
567
563
  }, [t.options.items]), {
568
564
  // data
569
565
  categories: t.options.categories,
570
566
  allItems: t.options.items,
571
567
  question: t,
572
- categoriesWithItems: h,
568
+ categoriesWithItems: u,
573
569
  // state
574
570
  answers: o,
575
- unassignedItems: x,
571
+ unassignedItems: h,
576
572
  // base
577
- submitted: u,
578
- isCorrect: f,
579
- attempts: m,
580
- canAnswer: n,
573
+ submitted: i,
574
+ isCorrect: d,
575
+ attempts: g,
576
+ canAnswer: s,
581
577
  // actions
582
- move: I,
583
- remove: Q,
578
+ move: k,
579
+ remove: b,
584
580
  submit: p,
585
- reset: d
581
+ reset: A
586
582
  };
587
583
  }
588
584
  function rt(t) {
589
585
  const {
590
- canAnswer: n,
591
- submitted: u,
592
- isCorrect: f,
593
- attempts: m,
594
- resetQuestion: C,
595
- submitQuestion: S
596
- } = E();
586
+ canAnswer: s,
587
+ submitted: i,
588
+ isCorrect: d,
589
+ attempts: g,
590
+ resetQuestion: S,
591
+ submitQuestion: x
592
+ } = L();
597
593
  function o() {
598
- u || S(!0);
594
+ i || x(!0);
599
595
  }
600
- function l() {
601
- C();
596
+ function f() {
597
+ S();
602
598
  }
603
599
  return {
604
600
  // data
@@ -607,248 +603,248 @@ function rt(t) {
607
603
  type: t.options.urlType,
608
604
  // actions
609
605
  submit: o,
610
- reset: l,
606
+ reset: f,
611
607
  // base
612
- submitted: u,
613
- isCorrect: f,
614
- attempts: m,
615
- canAnswer: n
608
+ submitted: i,
609
+ isCorrect: d,
610
+ attempts: g,
611
+ canAnswer: s
616
612
  };
617
613
  }
618
- function nt(t, n) {
619
- const { canAnswer: u, submitted: f, attempts: m, submitQuestion: C, resetQuestion: S } = E(), [o, l] = A(""), [b, I] = A(void 0), [Q, w] = A(!1), [p, d] = A(void 0), x = B(
620
- async (e) => {
621
- if (n) {
622
- w(!0), d(void 0);
614
+ function nt(t, s) {
615
+ const { canAnswer: i, submitted: d, attempts: g, submitQuestion: S, resetQuestion: x } = L(), [o, f] = C(""), [w, I] = C(void 0), [k, b] = C(!1), [m, p] = C(void 0), A = B(
616
+ async (n) => {
617
+ if (s) {
618
+ b(!0), p(void 0);
623
619
  try {
624
- const r = await n(e, e.name);
625
- r.success && r.url ? I(r.url) : d(r.error || "Upload failed");
626
- } catch (r) {
627
- console.error("File upload failed:", r), d(
628
- r instanceof Error ? r.message : "File upload failed"
620
+ const e = await s(n, n.name);
621
+ e.success && e.url ? I(e.url) : p(e.error || "Upload failed");
622
+ } catch (e) {
623
+ console.error("File upload failed:", e), p(
624
+ e instanceof Error ? e.message : "File upload failed"
629
625
  );
630
626
  } finally {
631
- w(!1);
627
+ b(!1);
632
628
  }
633
629
  }
634
630
  },
635
- [n]
631
+ [s]
636
632
  ), h = B(async () => {
637
- if (!(!n || !o)) {
638
- w(!0), d(void 0);
633
+ if (!(!s || !o)) {
634
+ b(!0), p(void 0);
639
635
  try {
640
- const e = new Blob([o], { type: "text/plain; charset=utf-8" }), r = `writing-${Date.now()}.txt`, c = await n(e, r);
641
- c.success && c.url ? I(c.url) : d(c.error || "Upload failed");
642
- } catch (e) {
643
- console.error("Text upload failed:", e), d(
644
- e instanceof Error ? e.message : "Text upload failed"
636
+ const n = new Blob([o], { type: "text/plain; charset=utf-8" }), e = `writing-${Date.now()}.txt`, r = await s(n, e);
637
+ r.success && r.url ? I(r.url) : p(r.error || "Upload failed");
638
+ } catch (n) {
639
+ console.error("Text upload failed:", n), p(
640
+ n instanceof Error ? n.message : "Text upload failed"
645
641
  );
646
642
  } finally {
647
- w(!1);
643
+ b(!1);
648
644
  }
649
645
  }
650
- }, [o, n]), s = F(
646
+ }, [o, s]), u = F(
651
647
  () => ({
652
648
  type: "writing",
653
649
  text: o,
654
- fileUrl: b
650
+ fileUrl: w
655
651
  }),
656
- [o, b]
657
- ), a = B(() => (C(), s), [C, s]), i = B(() => {
658
- l(""), I(void 0), d(void 0), S();
659
- }, [S]);
652
+ [o, w]
653
+ ), c = B(() => (S(), u), [S, u]), a = B(() => {
654
+ f(""), I(void 0), p(void 0), x();
655
+ }, [x]);
660
656
  return {
661
657
  question: t,
662
- canAnswer: u,
663
- submitted: f,
664
- attempts: m,
658
+ canAnswer: i,
659
+ submitted: d,
660
+ attempts: g,
665
661
  text: o,
666
- setText: l,
667
- fileUrl: b,
662
+ setText: f,
663
+ fileUrl: w,
668
664
  setFileUrl: I,
669
- isUploading: Q,
670
- uploadError: p,
671
- uploadFile: x,
665
+ isUploading: k,
666
+ uploadError: m,
667
+ uploadFile: A,
672
668
  uploadText: h,
673
- submit: a,
674
- reset: i,
675
- payload: s
669
+ submit: c,
670
+ reset: a,
671
+ payload: u
676
672
  };
677
673
  }
678
- function st(t, n) {
679
- const { canAnswer: u, submitted: f, attempts: m, submitQuestion: C, resetQuestion: S } = E(), [o, l] = A(void 0), [b, I] = A("idle"), [Q, w] = A(0), [p, d] = A(!1), [x, h] = A(void 0), [s, a] = A(!1), i = O(null), e = O([]), r = O(null), c = O(null), g = B(async () => {
680
- a(!0);
674
+ function st(t, s) {
675
+ const { canAnswer: i, submitted: d, attempts: g, submitQuestion: S, resetQuestion: x } = L(), [o, f] = C(void 0), [w, I] = C("idle"), [k, b] = C(0), [m, p] = C(!1), [A, h] = C(void 0), [u, c] = C(!1), a = j(null), n = j([]), e = j(null), r = j(null), l = B(async () => {
676
+ c(!0);
681
677
  try {
682
678
  const y = await navigator.mediaDevices.getUserMedia({ audio: !0 });
683
- c.current = y;
684
- const R = new MediaRecorder(y);
685
- i.current = R, e.current = [], R.ondataavailable = (W) => {
686
- W.data.size > 0 && e.current.push(W.data);
687
- }, R.onstop = () => {
688
- const W = new Blob(e.current, {
679
+ r.current = y;
680
+ const U = new MediaRecorder(y);
681
+ a.current = U, n.current = [], U.ondataavailable = (W) => {
682
+ W.data.size > 0 && n.current.push(W.data);
683
+ }, U.onstop = () => {
684
+ const W = new Blob(n.current, {
689
685
  type: "audio/webm"
690
686
  }), P = URL.createObjectURL(W);
691
- l(P);
692
- }, R.start(), I("recording"), w(0);
693
- let L = 0;
694
- r.current = setInterval(() => {
695
- L++, w(L), L >= (t.metadata?.max_recording_time || 300) && k();
687
+ f(P);
688
+ }, U.start(), I("recording"), b(0);
689
+ let O = 0;
690
+ e.current = setInterval(() => {
691
+ O++, b(O), O >= (t.metadata?.max_recording_time || 300) && R();
696
692
  }, 1e3);
697
693
  } catch (y) {
698
694
  console.error("Failed to start recording:", y), h("Failed to access microphone");
699
695
  }
700
696
  }, []), v = B(() => {
701
- i.current && b === "recording" && (i.current.pause(), I("paused"), r.current && clearInterval(r.current));
702
- }, [b]), U = B(() => {
703
- i.current && b === "paused" && (i.current.resume(), I("recording"), r.current = setInterval(() => {
704
- w((y) => y + 1);
697
+ a.current && w === "recording" && (a.current.pause(), I("paused"), e.current && clearInterval(e.current));
698
+ }, [w]), Q = B(() => {
699
+ a.current && w === "paused" && (a.current.resume(), I("recording"), e.current = setInterval(() => {
700
+ b((y) => y + 1);
705
701
  }, 1e3));
706
- }, [b]), k = B(() => {
707
- i.current && i.current.state !== "inactive" && (i.current.stop(), a(!1), I("stopped"), r.current && clearInterval(r.current), c.current && c.current.getTracks().forEach((y) => y.stop()));
708
- }, []), _ = B(() => {
709
- s ? k() : g();
710
- }, [s, g, k]), T = B(async () => {
711
- if (!(!e.current.length || !n)) {
712
- d(!0), h(void 0);
702
+ }, [w]), R = B(() => {
703
+ a.current && a.current.state !== "inactive" && (a.current.stop(), c(!1), I("stopped"), e.current && clearInterval(e.current), r.current && r.current.getTracks().forEach((y) => y.stop()));
704
+ }, []), M = B(() => {
705
+ u ? R() : l();
706
+ }, [u, l, R]), _ = B(async () => {
707
+ if (!(!n.current.length || !s)) {
708
+ p(!0), h(void 0);
713
709
  try {
714
- const y = new Blob(e.current, {
710
+ const y = new Blob(n.current, {
715
711
  type: "audio/webm"
716
- }), R = `speaking-${Date.now()}.webm`, L = await n(y, R);
717
- L.success && L.url ? l(L.url) : h(L.error || "Upload failed");
712
+ }), U = `speaking-${Date.now()}.webm`, O = await s(y, U);
713
+ O.success && O.url ? f(O.url) : h(O.error || "Upload failed");
718
714
  } catch (y) {
719
715
  console.error("Upload failed:", y), h(y instanceof Error ? y.message : "Upload failed");
720
716
  } finally {
721
- d(!1);
717
+ p(!1);
722
718
  }
723
719
  }
724
- }, [t, n]), M = B(
720
+ }, [t, s]), T = B(
725
721
  async (y) => {
726
- if (n) {
727
- d(!0), h(void 0);
722
+ if (s) {
723
+ p(!0), h(void 0);
728
724
  try {
729
- const R = await n(y, y.name);
730
- R.success && R.url ? l(R.url) : h(R.error || "Upload failed");
731
- } catch (R) {
732
- console.error("File upload failed:", R), h(
733
- R instanceof Error ? R.message : "File upload failed"
725
+ const U = await s(y, y.name);
726
+ U.success && U.url ? f(U.url) : h(U.error || "Upload failed");
727
+ } catch (U) {
728
+ console.error("File upload failed:", U), h(
729
+ U instanceof Error ? U.message : "File upload failed"
734
730
  );
735
731
  } finally {
736
- d(!1);
732
+ p(!1);
737
733
  }
738
734
  }
739
735
  },
740
- [n]
741
- ), j = F(
736
+ [s]
737
+ ), E = F(
742
738
  () => ({
743
739
  type: "speaking",
744
740
  audioUrl: o
745
741
  }),
746
742
  [t, o]
747
- ), $ = B(() => (C(), j), [C, j]), N = B(() => {
748
- l(void 0), I("idle"), w(0), h(void 0), e.current = [], r.current && clearInterval(r.current), c.current && c.current.getTracks().forEach((y) => y.stop()), S();
749
- }, [S]);
743
+ ), z = B(() => (S(), E), [S, E]), N = B(() => {
744
+ f(void 0), I("idle"), b(0), h(void 0), n.current = [], e.current && clearInterval(e.current), r.current && r.current.getTracks().forEach((y) => y.stop()), x();
745
+ }, [x]);
750
746
  return {
751
747
  question: t,
752
- canAnswer: u,
753
- submitted: f,
754
- attempts: m,
748
+ canAnswer: i,
749
+ submitted: d,
750
+ attempts: g,
755
751
  audioUrl: o,
756
- recordingState: b,
757
- recordingTime: Q,
758
- isUploading: p,
759
- uploadError: x,
760
- isRecording: s,
761
- payload: j,
762
- setAudioUrl: l,
763
- startRecording: g,
752
+ recordingState: w,
753
+ recordingTime: k,
754
+ isUploading: m,
755
+ uploadError: A,
756
+ isRecording: u,
757
+ payload: E,
758
+ setAudioUrl: f,
759
+ startRecording: l,
764
760
  pauseRecording: v,
765
- resumeRecording: U,
766
- stopRecording: k,
767
- toggleRecording: _,
768
- uploadAudio: T,
769
- uploadFile: M,
770
- submit: $,
761
+ resumeRecording: Q,
762
+ stopRecording: R,
763
+ toggleRecording: M,
764
+ uploadAudio: _,
765
+ uploadFile: T,
766
+ submit: z,
771
767
  reset: N
772
768
  };
773
769
  }
774
770
  function ct({
775
771
  getData: t,
776
- children: n
772
+ children: s
777
773
  }) {
778
- const u = X(t());
779
- return n(u);
774
+ const i = X(t());
775
+ return s(i);
780
776
  }
781
777
  function ut({
782
778
  getData: t,
783
- children: n
779
+ children: s
784
780
  }) {
785
- const u = Y(t());
786
- return n(u);
781
+ const i = Y(t());
782
+ return s(i);
787
783
  }
788
784
  function at({
789
785
  getData: t,
790
- children: n
786
+ children: s
791
787
  }) {
792
- const u = Z(t());
793
- return n(u);
788
+ const i = Z(t());
789
+ return s(i);
794
790
  }
795
791
  function lt({
796
792
  getData: t,
797
- children: n
793
+ children: s
798
794
  }) {
799
- const u = K(t());
800
- return n(u);
795
+ const i = K(t());
796
+ return s(i);
801
797
  }
802
798
  function ft({
803
799
  getData: t,
804
- children: n
800
+ children: s
805
801
  }) {
806
- const u = H(t());
807
- return n(u);
802
+ const i = H(t());
803
+ return s(i);
808
804
  }
809
805
  function dt({
810
806
  getData: t,
811
- children: n
807
+ children: s
812
808
  }) {
813
- const u = q(t());
814
- return n(u);
809
+ const i = q(t());
810
+ return s(i);
815
811
  }
816
812
  function pt({
817
813
  getData: t,
818
- children: n
814
+ children: s
819
815
  }) {
820
- const u = tt(t());
821
- return n(u);
816
+ const i = tt(t());
817
+ return s(i);
822
818
  }
823
819
  function mt({
824
820
  getData: t,
825
- children: n
821
+ children: s
826
822
  }) {
827
- const u = et(t());
828
- return n(u);
823
+ const i = et(t());
824
+ return s(i);
829
825
  }
830
826
  function gt({
831
827
  getData: t,
832
- children: n
828
+ children: s
833
829
  }) {
834
- const u = rt(t());
835
- return n(u);
830
+ const i = rt(t());
831
+ return s(i);
836
832
  }
837
833
  function bt({
838
834
  getData: t,
839
- children: n,
840
- uploadHandler: u
835
+ children: s,
836
+ uploadHandler: i
841
837
  }) {
842
- const f = t(), m = nt(f, u);
843
- return /* @__PURE__ */ z(G, { children: n(m) });
838
+ const d = t(), g = nt(d, i);
839
+ return /* @__PURE__ */ G($, { children: s(g) });
844
840
  }
845
841
  function wt({
846
842
  getData: t,
847
- children: n,
848
- uploadHandler: u
843
+ children: s,
844
+ uploadHandler: i
849
845
  }) {
850
- const f = t(), m = st(f, u);
851
- return /* @__PURE__ */ z(G, { children: n(m) });
846
+ const d = t(), g = st(d, i);
847
+ return /* @__PURE__ */ G($, { children: s(g) });
852
848
  }
853
849
  export {
854
850
  lt as DragDropQuestion,
@@ -864,7 +860,7 @@ export {
864
860
  bt as WritingQuestion,
865
861
  J as isSameSet,
866
862
  V as shuffleArray,
867
- E as useBaseQuestion,
863
+ L as useBaseQuestion,
868
864
  K as useDragDrop,
869
865
  tt as useFillInBlank,
870
866
  et as useGrouping,