@enspiredigital/xlms-headless 0.0.28 → 0.0.30

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 +1 @@
1
- {"version":3,"file":"useSpeaking.d.ts","sourceRoot":"","sources":["../../src/hooks/useSpeaking.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzE,MAAM,MAAM,qBAAqB,GAAG,CAClC,SAAS,EAAE,IAAI,EACf,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEjE,wBAAgB,WAAW,CACzB,QAAQ,EAAE,oBAAoB,EAC9B,aAAa,CAAC,EAAE,qBAAqB;;;;;;;;;;;;;;;;;;;uBAiItB,IAAI;;;EAkFpB"}
1
+ {"version":3,"file":"useSpeaking.d.ts","sourceRoot":"","sources":["../../src/hooks/useSpeaking.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,MAAM,qBAAqB,GAAG;IAClC,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzE,MAAM,MAAM,qBAAqB,GAAG,CAClC,SAAS,EAAE,IAAI,EACf,QAAQ,CAAC,EAAE,MAAM,KACd,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAEjE,wBAAgB,WAAW,CACzB,QAAQ,EAAE,oBAAoB,EAC9B,aAAa,CAAC,EAAE,qBAAqB;;;;;;;;;;;;;;;;;;;uBAwItB,IAAI;;;EAkFpB"}
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { useState as A, useRef as F, useEffect as V, useMemo as T, useCallback as R } from "react";
1
+ import { useState as A, useRef as F, useEffect as V, useMemo as T, useCallback as U } from "react";
2
2
  import { jsx as W, Fragment as z } from "react/jsx-runtime";
3
3
  function E() {
4
- const [t, n] = A(null), [u, f] = A(null), [b, C] = A(0);
5
- function S(d) {
6
- n(!0), d !== void 0 && f(d), C((h) => h + 1);
4
+ const [t, n] = A(null), [u, f] = A(null), [b, h] = A(0);
5
+ function C(d) {
6
+ n(!0), d !== void 0 && f(d), h((S) => S + 1);
7
7
  }
8
8
  function o() {
9
9
  n(!1), f(null);
@@ -16,7 +16,7 @@ function E() {
16
16
  // derived
17
17
  canAnswer: !t,
18
18
  // actions
19
- submitQuestion: S,
19
+ submitQuestion: C,
20
20
  resetQuestion: o
21
21
  };
22
22
  }
@@ -42,31 +42,31 @@ function X(t) {
42
42
  submitted: u,
43
43
  isCorrect: f,
44
44
  attempts: b,
45
- resetQuestion: C,
46
- submitQuestion: S
45
+ resetQuestion: h,
46
+ submitQuestion: C
47
47
  } = E(), [o, d] = A([]);
48
- function h(w) {
49
- d((m) => t.options.allowMultipleAnswers ? m.includes(w) ? m.filter((p) => p !== w) : [...m, w] : [w]);
48
+ function S(w) {
49
+ d((g) => t.options.allowMultipleAnswers ? g.includes(w) ? g.filter((p) => p !== w) : [...g, w] : [w]);
50
50
  }
51
51
  function I() {
52
52
  if (o.length === 0) return;
53
53
  const w = t.options.answers.reduce(
54
54
  (p, x) => (x.is_correct && p.push(x.id), p),
55
55
  []
56
- ), m = J(o, w);
57
- S(m);
56
+ ), g = J(o, w);
57
+ C(g);
58
58
  }
59
- function v() {
60
- d([]), C();
59
+ function Q() {
60
+ d([]), h();
61
61
  }
62
62
  return {
63
63
  // data
64
64
  question: t,
65
65
  selectedIds: o,
66
66
  // actions
67
- select: h,
67
+ select: S,
68
68
  submit: I,
69
- reset: v,
69
+ reset: Q,
70
70
  // base
71
71
  submitted: u,
72
72
  isCorrect: f,
@@ -80,46 +80,46 @@ function Y(t) {
80
80
  submitted: u,
81
81
  isCorrect: f,
82
82
  attempts: b,
83
- submitQuestion: C,
84
- resetQuestion: S
85
- } = E(), [o, d] = A([]), [h, I] = A(
83
+ submitQuestion: h,
84
+ resetQuestion: C
85
+ } = E(), [o, d] = A([]), [S, I] = A(
86
86
  []
87
- ), [v, w] = A(
87
+ ), [Q, w] = A(
88
88
  []
89
- ), m = F([]);
89
+ ), g = F([]);
90
90
  function p(e, s) {
91
91
  d((l) => [
92
92
  ...l.filter(
93
- (g) => g.targetId !== e && g.sourceId !== s
93
+ (m) => m.targetId !== e && m.sourceId !== s
94
94
  ),
95
95
  { targetId: e, sourceId: s }
96
96
  ]);
97
97
  }
98
98
  function x(e, s) {
99
99
  d(
100
- (l) => l.filter((g) => g.targetId !== e || g.sourceId !== s)
100
+ (l) => l.filter((m) => m.targetId !== e || m.sourceId !== s)
101
101
  );
102
102
  }
103
103
  function a() {
104
104
  let e = 0, s = !0;
105
105
  return t.options.targets.forEach((l) => {
106
- const g = o.find((U) => U.targetId === l.id), y = t.options.sources[l.content.correct_position - 1];
107
- g && y && g.sourceId === y.id ? e += l.content.point : s = !1;
106
+ const m = o.find((B) => B.targetId === l.id), y = t.options.sources[l.content.correct_position - 1];
107
+ m && y && m.sourceId === y.id ? e += l.content.point : s = !1;
108
108
  }), {
109
109
  isCorrect: s,
110
110
  score: e,
111
111
  maxScore: t.options.targets.reduce(
112
- (l, g) => l + g.content.point,
112
+ (l, m) => l + m.content.point,
113
113
  0
114
114
  )
115
115
  };
116
116
  }
117
117
  function c() {
118
118
  const e = a();
119
- return C(e.isCorrect), e;
119
+ return h(e.isCorrect), e;
120
120
  }
121
121
  function i() {
122
- d([]), S();
122
+ d([]), C();
123
123
  }
124
124
  function r(e) {
125
125
  const s = o.find((l) => l.sourceId === e)?.targetId;
@@ -131,21 +131,21 @@ function Y(t) {
131
131
  );
132
132
  I(e);
133
133
  }, [o, t.options.sources]), V(() => {
134
- if (m.current.length === 0) return;
135
- const e = m.current.filter(
134
+ if (g.current.length === 0) return;
135
+ const e = g.current.filter(
136
136
  (s) => !o.some((l) => l.targetId === s.id)
137
137
  );
138
138
  w(e);
139
139
  }, [o]), V(() => {
140
- m.current = G(t.options.targets);
140
+ g.current = G(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: h,
148
- availableTargets: v,
147
+ availableSources: S,
148
+ availableTargets: Q,
149
149
  // base
150
150
  submitted: u,
151
151
  isCorrect: f,
@@ -165,14 +165,14 @@ function Z(t) {
165
165
  submitted: u,
166
166
  isCorrect: f,
167
167
  attempts: b,
168
- resetQuestion: C,
169
- submitQuestion: S
168
+ resetQuestion: h,
169
+ submitQuestion: C
170
170
  } = E();
171
171
  function o() {
172
- S(!0);
172
+ C(!0);
173
173
  }
174
174
  function d() {
175
- C();
175
+ h();
176
176
  }
177
177
  return {
178
178
  // data
@@ -195,9 +195,9 @@ function K(t) {
195
195
  submitted: u,
196
196
  isCorrect: f,
197
197
  attempts: b,
198
- submitQuestion: C,
199
- resetQuestion: S
200
- } = E(), [o, d] = A([]), [h, I] = A(null), v = T(() => {
198
+ submitQuestion: h,
199
+ resetQuestion: C
200
+ } = E(), [o, d] = A([]), [S, I] = A(null), Q = T(() => {
201
201
  const r = new Set(o.map((e) => e.itemId));
202
202
  return t.options.answers.filter(
203
203
  (e) => !r.has(String(e.id))
@@ -206,7 +206,7 @@ function K(t) {
206
206
  function w(r, e) {
207
207
  d((s) => [
208
208
  ...s.filter(
209
- (g) => g.blankIndex !== e && g.itemId !== r
209
+ (m) => m.blankIndex !== e && m.itemId !== r
210
210
  ),
211
211
  {
212
212
  itemId: r,
@@ -214,7 +214,7 @@ function K(t) {
214
214
  }
215
215
  ]);
216
216
  }
217
- function m(r) {
217
+ function g(r) {
218
218
  d((e) => e.filter((s) => s.itemId !== r));
219
219
  }
220
220
  function p(r, e) {
@@ -222,15 +222,15 @@ function K(t) {
222
222
  }
223
223
  function x() {
224
224
  let r = 0, e = !0, s = 0;
225
- const l = t.correct_answers.list, g = new Map(o.map((y) => [y.blankIndex, y.itemId]));
226
- return Object.entries(l).forEach(([y, U]) => {
227
- const B = y, O = g.get(B);
225
+ const l = t.correct_answers.list, m = new Map(o.map((y) => [y.blankIndex, y.itemId]));
226
+ return Object.entries(l).forEach(([y, B]) => {
227
+ const R = y, O = m.get(R);
228
228
  if (!O) {
229
229
  e = !1;
230
230
  return;
231
231
  }
232
232
  const M = t.options.answers.find((D) => D.id === O);
233
- M && String(M.group_position) === String(U) ? (r++, s += M.point) : e = !1;
233
+ M && String(M.group_position) === String(B) ? (r++, s += M.point) : e = !1;
234
234
  }), {
235
235
  isCorrect: e,
236
236
  correctCount: r,
@@ -241,10 +241,10 @@ function K(t) {
241
241
  }
242
242
  function a() {
243
243
  const r = x();
244
- return C(r.isCorrect), r;
244
+ return h(r.isCorrect), r;
245
245
  }
246
246
  function c() {
247
- d([]), S();
247
+ d([]), C();
248
248
  }
249
249
  function i(r) {
250
250
  const e = o.find((s) => s.blankIndex === r)?.itemId;
@@ -255,9 +255,9 @@ function K(t) {
255
255
  items: t.options.answers,
256
256
  groups: t.options.groups,
257
257
  answers: o,
258
- availableItems: v,
258
+ availableItems: Q,
259
259
  question: t,
260
- draggingItemId: h,
260
+ draggingItemId: S,
261
261
  // base
262
262
  submitted: u,
263
263
  isCorrect: f,
@@ -265,7 +265,7 @@ function K(t) {
265
265
  canAnswer: n,
266
266
  // actions
267
267
  dropItem: w,
268
- removeItem: m,
268
+ removeItem: g,
269
269
  moveItem: p,
270
270
  setDraggingItemId: I,
271
271
  getItemByBlankId: i,
@@ -279,11 +279,11 @@ function H(t) {
279
279
  submitted: u,
280
280
  isCorrect: f,
281
281
  attempts: b,
282
- submitQuestion: C,
283
- resetQuestion: S
282
+ submitQuestion: h,
283
+ resetQuestion: C
284
284
  } = E(), [o, d] = A(() => G(
285
285
  t.options.answers.map((c) => String(c.id))
286
- )), h = T(() => o.map(
286
+ )), S = T(() => o.map(
287
287
  (c) => t.options.answers.find((i) => String(i.id) === c)
288
288
  ).filter((c) => c !== void 0), [o, t.options.answers]);
289
289
  function I(c, i) {
@@ -292,7 +292,7 @@ function H(t) {
292
292
  return e.splice(i, 0, s), e;
293
293
  });
294
294
  }
295
- function v(c) {
295
+ function Q(c) {
296
296
  const i = o.indexOf(c);
297
297
  i > 0 && I(i, i - 1);
298
298
  }
@@ -300,7 +300,7 @@ function H(t) {
300
300
  const i = o.indexOf(c);
301
301
  i < o.length - 1 && I(i, i + 1);
302
302
  }
303
- function m(c, i) {
303
+ function g(c, i) {
304
304
  const r = o.indexOf(c);
305
305
  r !== -1 && i >= 0 && i < o.length && I(r, i);
306
306
  }
@@ -320,16 +320,16 @@ function H(t) {
320
320
  }
321
321
  function x() {
322
322
  const c = p();
323
- return C(c.isCorrect), c;
323
+ return h(c.isCorrect), c;
324
324
  }
325
325
  function a() {
326
- d(t.options.answers.map((c) => String(c.id))), S();
326
+ d(t.options.answers.map((c) => String(c.id))), C();
327
327
  }
328
328
  return {
329
329
  // data
330
330
  items: t.options.answers,
331
331
  groups: t.options.groups,
332
- orderedItems: h,
332
+ orderedItems: S,
333
333
  orderedItemIds: o,
334
334
  question: t,
335
335
  // base
@@ -340,9 +340,9 @@ function H(t) {
340
340
  // actions
341
341
  setOrderedItemIds: d,
342
342
  moveItem: I,
343
- moveUp: v,
343
+ moveUp: Q,
344
344
  moveDown: w,
345
- moveToPosition: m,
345
+ moveToPosition: g,
346
346
  submit: x,
347
347
  reset: a
348
348
  };
@@ -353,19 +353,19 @@ function q(t) {
353
353
  submitted: u,
354
354
  isCorrect: f,
355
355
  attempts: b,
356
- submitQuestion: C,
357
- resetQuestion: S
358
- } = E(), [o, d] = A([]), h = T(() => {
356
+ submitQuestion: h,
357
+ resetQuestion: C
358
+ } = E(), [o, d] = A([]), S = T(() => {
359
359
  const i = new Set(o.map((r) => r.labelId));
360
360
  return t.options.labels.filter(
361
361
  (r) => !i.has(String(r.id))
362
362
  );
363
363
  }, [o, t.options.labels]);
364
364
  function I(i, r, e, s) {
365
- const l = t.options.blanks.find((g) => String(g.id) === r);
366
- l && d((g) => [
367
- ...g.filter(
368
- (U) => U.labelId !== i && U.blankId !== r
365
+ const l = t.options.blanks.find((m) => String(m.id) === r);
366
+ l && d((m) => [
367
+ ...m.filter(
368
+ (B) => B.labelId !== i && B.blankId !== r
369
369
  ),
370
370
  {
371
371
  labelId: i,
@@ -375,13 +375,13 @@ function q(t) {
375
375
  }
376
376
  ]);
377
377
  }
378
- function v(i) {
378
+ function Q(i) {
379
379
  d((r) => r.filter((e) => e.labelId !== i));
380
380
  }
381
381
  function w(i, r, e, s) {
382
382
  I(i, r, e, s);
383
383
  }
384
- function m(i) {
384
+ function g(i) {
385
385
  const r = o.find((e) => e.blankId === i);
386
386
  return r && t.options.labels.find(
387
387
  (e) => String(e.id) === r.labelId
@@ -395,9 +395,9 @@ function q(t) {
395
395
  let i = 0, r = !0;
396
396
  return t.options.labels.forEach((e) => {
397
397
  const s = o.find(
398
- (g) => String(g.labelId) === String(e.id)
398
+ (m) => String(m.labelId) === String(e.id)
399
399
  ), l = t.options.blanks.find(
400
- (g, y) => y + 1 === e.correct_position
400
+ (m, y) => y + 1 === e.correct_position
401
401
  );
402
402
  s && l && s.blankId === String(l.id) ? i += e.point : r = !1;
403
403
  }), {
@@ -411,10 +411,10 @@ function q(t) {
411
411
  }
412
412
  function a() {
413
413
  const i = x();
414
- return C(i.isCorrect), i;
414
+ return h(i.isCorrect), i;
415
415
  }
416
416
  function c() {
417
- d([]), S();
417
+ d([]), C();
418
418
  }
419
419
  return {
420
420
  // data
@@ -424,7 +424,7 @@ function q(t) {
424
424
  imageWidth: t.image_width,
425
425
  imageHeight: t.image_height,
426
426
  answers: o,
427
- availableLabels: h,
427
+ availableLabels: S,
428
428
  question: t,
429
429
  // base
430
430
  submitted: u,
@@ -433,9 +433,9 @@ function q(t) {
433
433
  canAnswer: n,
434
434
  // actions
435
435
  attachLabel: I,
436
- removeLabel: v,
436
+ removeLabel: Q,
437
437
  moveLabel: w,
438
- getLabelAtBlank: m,
438
+ getLabelAtBlank: g,
439
439
  getBlankForLabel: p,
440
440
  submit: a,
441
441
  reset: c
@@ -447,43 +447,43 @@ function tt(t) {
447
447
  submitted: u,
448
448
  isCorrect: f,
449
449
  attempts: b,
450
- submitQuestion: C,
451
- resetQuestion: S
450
+ submitQuestion: h,
451
+ resetQuestion: C
452
452
  } = E(), [o, d] = A([]);
453
- function h(m, p) {
453
+ function S(g, p) {
454
454
  d((x) => {
455
- const a = x.findIndex((c) => c.blankId === m);
455
+ const a = x.findIndex((c) => c.blankId === g);
456
456
  if (a >= 0) {
457
457
  const c = [...x];
458
- return c[a] = { blankId: m, value: p }, c;
458
+ return c[a] = { blankId: g, value: p }, c;
459
459
  }
460
- return [...x, { blankId: m, value: p }];
460
+ return [...x, { blankId: g, value: p }];
461
461
  });
462
462
  }
463
463
  function I() {
464
- let m = 0, p = 0, x = 0;
464
+ let g = 0, p = 0, x = 0;
465
465
  const a = t.correct_answers.list || {}, c = Object.keys(a).length;
466
466
  Object.entries(a).forEach(([r, e]) => {
467
467
  const s = String(e).trim().toLowerCase(), l = t.options.answers.find(
468
- (B) => B.correct_position === Number(r)
469
- ), g = l && l.point || 1;
470
- x += g;
471
- const y = o.find((B) => B.blankId === r);
472
- (y ? String(y.value).trim().toLowerCase() : "") === s && (m += g, p++);
468
+ (R) => R.correct_position === Number(r)
469
+ ), m = l && l.point || 1;
470
+ x += m;
471
+ const y = o.find((R) => R.blankId === r);
472
+ (y ? String(y.value).trim().toLowerCase() : "") === s && (g += m, p++);
473
473
  });
474
474
  const i = p === c && c > 0;
475
475
  return x === 0 && c > 0 && (x = c), {
476
476
  isCorrect: i,
477
- score: Math.round(m * 100) / 100,
477
+ score: Math.round(g * 100) / 100,
478
478
  maxScore: Math.round(x * 100) / 100
479
479
  };
480
480
  }
481
- function v() {
482
- const m = I();
483
- return C(m.isCorrect), m;
481
+ function Q() {
482
+ const g = I();
483
+ return h(g.isCorrect), g;
484
484
  }
485
485
  function w() {
486
- d([]), S();
486
+ d([]), C();
487
487
  }
488
488
  return {
489
489
  // data
@@ -496,8 +496,8 @@ function tt(t) {
496
496
  attempts: b,
497
497
  canAnswer: n,
498
498
  // actions
499
- answer: h,
500
- submit: v,
499
+ answer: S,
500
+ submit: Q,
501
501
  reset: w
502
502
  };
503
503
  }
@@ -507,10 +507,10 @@ function et(t) {
507
507
  submitted: u,
508
508
  isCorrect: f,
509
509
  attempts: b,
510
- submitQuestion: C,
511
- resetQuestion: S
510
+ submitQuestion: h,
511
+ resetQuestion: C
512
512
  } = E(), [o, d] = A([]);
513
- function h(a, c) {
513
+ function S(a, c) {
514
514
  d((i) => {
515
515
  const r = i.findIndex((e) => e.itemId === a);
516
516
  if (r >= 0) {
@@ -523,15 +523,15 @@ function et(t) {
523
523
  function I(a) {
524
524
  d((c) => c.filter((i) => i.itemId !== a));
525
525
  }
526
- function v() {
526
+ function Q() {
527
527
  let a = 0, c = 0;
528
528
  const r = t.correct_answers.list || {}, e = Object.keys(r).length;
529
529
  let s = 0;
530
- return Object.entries(r).forEach(([g, y]) => {
531
- const U = t.options.items.find((M) => M.id === g), B = U ? U.point : 0;
532
- s += B;
533
- const O = o.find((M) => M.itemId === g);
534
- O && O.categoryId === y && (a += B, c++);
530
+ return Object.entries(r).forEach(([m, y]) => {
531
+ const B = t.options.items.find((M) => M.id === m), R = B ? B.point : 0;
532
+ s += R;
533
+ const O = o.find((M) => M.itemId === m);
534
+ O && O.categoryId === y && (a += R, c++);
535
535
  }), a = Math.round(a * 100) / 100, s = Math.round(s * 100) / 100, {
536
536
  isCorrect: c === e && e > 0,
537
537
  score: a,
@@ -539,11 +539,11 @@ function et(t) {
539
539
  };
540
540
  }
541
541
  function w() {
542
- const a = v();
543
- return C(a.isCorrect), a;
542
+ const a = Q();
543
+ return h(a.isCorrect), a;
544
544
  }
545
- function m() {
546
- d([]), S();
545
+ function g() {
546
+ d([]), C();
547
547
  }
548
548
  const p = T(() => t.options.items.filter(
549
549
  (a) => !o.some((c) => c.itemId === a.id)
@@ -571,10 +571,10 @@ function et(t) {
571
571
  attempts: b,
572
572
  canAnswer: n,
573
573
  // actions
574
- move: h,
574
+ move: S,
575
575
  remove: I,
576
576
  submit: w,
577
- reset: m
577
+ reset: g
578
578
  };
579
579
  }
580
580
  function rt(t) {
@@ -583,14 +583,14 @@ function rt(t) {
583
583
  submitted: u,
584
584
  isCorrect: f,
585
585
  attempts: b,
586
- resetQuestion: C,
587
- submitQuestion: S
586
+ resetQuestion: h,
587
+ submitQuestion: C
588
588
  } = E();
589
589
  function o() {
590
- u || S(!0);
590
+ u || C(!0);
591
591
  }
592
592
  function d() {
593
- C();
593
+ h();
594
594
  }
595
595
  return {
596
596
  // data
@@ -608,7 +608,7 @@ function rt(t) {
608
608
  };
609
609
  }
610
610
  function nt(t, n) {
611
- const { canAnswer: u, submitted: f, attempts: b, submitQuestion: C, resetQuestion: S } = E(), [o, d] = A(""), [h, I] = A(void 0), [v, w] = A(!1), [m, p] = A(void 0), x = R(
611
+ const { canAnswer: u, submitted: f, attempts: b, submitQuestion: h, resetQuestion: C } = E(), [o, d] = A(""), [S, I] = A(void 0), [Q, w] = A(!1), [g, p] = A(void 0), x = U(
612
612
  async (e) => {
613
613
  if (n) {
614
614
  w(!0), p(void 0);
@@ -625,7 +625,7 @@ function nt(t, n) {
625
625
  }
626
626
  },
627
627
  [n]
628
- ), a = R(async () => {
628
+ ), a = U(async () => {
629
629
  if (!(!n || !o)) {
630
630
  w(!0), p(void 0);
631
631
  try {
@@ -643,12 +643,12 @@ function nt(t, n) {
643
643
  () => ({
644
644
  type: "writing",
645
645
  text: o,
646
- fileUrl: h
646
+ fileUrl: S
647
647
  }),
648
- [o, h]
649
- ), i = R(() => (C(), c), [C, c]), r = R(() => {
650
- d(""), I(void 0), p(void 0), S();
651
- }, [S]);
648
+ [o, S]
649
+ ), i = U(() => (h(), c), [h, c]), r = U(() => {
650
+ d(""), I(void 0), p(void 0), C();
651
+ }, [C]);
652
652
  return {
653
653
  question: t,
654
654
  canAnswer: u,
@@ -656,10 +656,10 @@ function nt(t, n) {
656
656
  attempts: b,
657
657
  text: o,
658
658
  setText: d,
659
- fileUrl: h,
659
+ fileUrl: S,
660
660
  setFileUrl: I,
661
- isUploading: v,
662
- uploadError: m,
661
+ isUploading: Q,
662
+ uploadError: g,
663
663
  uploadFile: x,
664
664
  uploadText: a,
665
665
  submit: i,
@@ -668,12 +668,12 @@ function nt(t, n) {
668
668
  };
669
669
  }
670
670
  function st(t, n) {
671
- const { canAnswer: u, submitted: f, attempts: b, submitQuestion: C, resetQuestion: S } = E(), [o, d] = A(void 0), [h, I] = A("idle"), [v, w] = A(0), [m, p] = A(!1), [x, a] = A(void 0), [c, i] = A(!1), r = F(null), e = F([]), s = F(null), l = F(null), g = R(async () => {
671
+ const { canAnswer: u, submitted: f, attempts: b, submitQuestion: h, resetQuestion: C } = E(), [o, d] = A(void 0), [S, I] = A("idle"), [Q, w] = A(0), [g, p] = A(!1), [x, a] = A(void 0), [c, i] = A(!1), r = F(null), e = F([]), s = F(null), l = F(null), m = U(async () => {
672
672
  i(!0);
673
673
  try {
674
- const Q = await navigator.mediaDevices.getUserMedia({ audio: !0 });
675
- l.current = Q;
676
- const k = new MediaRecorder(Q);
674
+ const v = await navigator.mediaDevices.getUserMedia({ audio: !0 });
675
+ l.current = v;
676
+ const k = new MediaRecorder(v);
677
677
  r.current = k, e.current = [], k.ondataavailable = (_) => {
678
678
  _.data.size > 0 && e.current.push(_.data);
679
679
  }, k.onstop = () => {
@@ -684,41 +684,41 @@ function st(t, n) {
684
684
  }, k.start(), I("recording"), w(0);
685
685
  let L = 0;
686
686
  s.current = setInterval(() => {
687
- L++, w(L), L >= (t.metadata?.max_recording_time || 300) && B();
687
+ L++, w(L), L >= (t.metadata?.max_recording_time || 300) && R();
688
688
  }, 1e3);
689
- } catch (Q) {
690
- console.error("Failed to start recording:", Q), a("Failed to access microphone");
689
+ } catch (v) {
690
+ console.error("Failed to start recording:", v), a("Failed to access microphone");
691
691
  }
692
- }, []), y = R(() => {
693
- r.current && h === "recording" && (r.current.pause(), I("paused"), s.current && clearInterval(s.current));
694
- }, [h]), U = R(() => {
695
- r.current && h === "paused" && (r.current.resume(), I("recording"), s.current = setInterval(() => {
696
- w((Q) => Q + 1);
692
+ }, []), y = U(() => {
693
+ r.current && S === "recording" && (r.current.pause(), I("paused"), s.current && clearInterval(s.current));
694
+ }, [S]), B = U(() => {
695
+ r.current && S === "paused" && (r.current.resume(), I("recording"), s.current = setInterval(() => {
696
+ w((v) => v + 1);
697
697
  }, 1e3));
698
- }, [h]), B = R(() => {
699
- r.current && h !== "idle" && (r.current.stop(), i(!1), I("stopped"), s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((Q) => Q.stop()));
700
- }, [h]), O = R(() => {
701
- c ? B() : g();
702
- }, [c]), M = R(async () => {
698
+ }, [S]), R = U(() => {
699
+ r.current && r.current.state !== "inactive" && (r.current.stop(), i(!1), I("stopped"), s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((v) => v.stop()));
700
+ }, []), O = U(() => {
701
+ c ? R() : m();
702
+ }, [c, m, R]), M = U(async () => {
703
703
  if (!(!e.current.length || !n)) {
704
704
  p(!0), a(void 0);
705
705
  try {
706
- const Q = new Blob(e.current, {
706
+ const v = new Blob(e.current, {
707
707
  type: "audio/webm"
708
- }), k = `speaking-${Date.now()}.webm`, L = await n(Q, k);
708
+ }), k = `speaking-${Date.now()}.webm`, L = await n(v, k);
709
709
  L.success && L.url ? d(L.url) : a(L.error || "Upload failed");
710
- } catch (Q) {
711
- console.error("Upload failed:", Q), a(Q instanceof Error ? Q.message : "Upload failed");
710
+ } catch (v) {
711
+ console.error("Upload failed:", v), a(v instanceof Error ? v.message : "Upload failed");
712
712
  } finally {
713
713
  p(!1);
714
714
  }
715
715
  }
716
- }, [t, n]), D = R(
717
- async (Q) => {
716
+ }, [t, n]), D = U(
717
+ async (v) => {
718
718
  if (n) {
719
719
  p(!0), a(void 0);
720
720
  try {
721
- const k = await n(Q, Q.name);
721
+ const k = await n(v, v.name);
722
722
  k.success && k.url ? d(k.url) : a(k.error || "Upload failed");
723
723
  } catch (k) {
724
724
  console.error("File upload failed:", k), a(
@@ -736,26 +736,26 @@ function st(t, n) {
736
736
  audioUrl: o
737
737
  }),
738
738
  [t, o]
739
- ), $ = R(() => (C(), j), [C, j]), N = R(() => {
740
- d(void 0), I("idle"), w(0), a(void 0), e.current = [], s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((Q) => Q.stop()), S();
741
- }, [S]);
739
+ ), $ = U(() => (h(), j), [h, j]), N = U(() => {
740
+ d(void 0), I("idle"), w(0), a(void 0), e.current = [], s.current && clearInterval(s.current), l.current && l.current.getTracks().forEach((v) => v.stop()), C();
741
+ }, [C]);
742
742
  return {
743
743
  question: t,
744
744
  canAnswer: u,
745
745
  submitted: f,
746
746
  attempts: b,
747
747
  audioUrl: o,
748
- recordingState: h,
749
- recordingTime: v,
750
- isUploading: m,
748
+ recordingState: S,
749
+ recordingTime: Q,
750
+ isUploading: g,
751
751
  uploadError: x,
752
752
  isRecording: c,
753
753
  payload: j,
754
754
  setAudioUrl: d,
755
- startRecording: g,
755
+ startRecording: m,
756
756
  pauseRecording: y,
757
- resumeRecording: U,
758
- stopRecording: B,
757
+ resumeRecording: B,
758
+ stopRecording: R,
759
759
  toggleRecording: O,
760
760
  uploadAudio: M,
761
761
  uploadFile: D,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@enspiredigital/xlms-headless",
3
- "version": "0.0.28",
3
+ "version": "0.0.30",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",