@intellectif/lk-react 2.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/README.md +3 -1
  2. package/dist/WrittenResponse-Dkg7FUt-.d.ts +87 -0
  3. package/dist/WrittenResponse-DqQ0NjPK.d.cts +87 -0
  4. package/dist/{chunk-3X7MYAFT.js → chunk-3DNJDP73.js} +11 -9
  5. package/dist/chunk-3DNJDP73.js.map +1 -0
  6. package/dist/chunk-4HZ7LQIH.cjs +40 -0
  7. package/dist/chunk-4HZ7LQIH.cjs.map +1 -0
  8. package/dist/chunk-525EWDUT.cjs +249 -0
  9. package/dist/chunk-525EWDUT.cjs.map +1 -0
  10. package/dist/{chunk-ZVFWJTT4.js → chunk-5SYL5CJ2.js} +10 -28
  11. package/dist/chunk-5SYL5CJ2.js.map +1 -0
  12. package/dist/{chunk-UXO6KYSZ.cjs → chunk-67RIIDZX.cjs} +17 -15
  13. package/dist/chunk-67RIIDZX.cjs.map +1 -0
  14. package/dist/chunk-6F4X2NKL.js +54 -0
  15. package/dist/chunk-6F4X2NKL.js.map +1 -0
  16. package/dist/chunk-GB5URWM4.js +38 -0
  17. package/dist/chunk-GB5URWM4.js.map +1 -0
  18. package/dist/chunk-GMU77L52.js +247 -0
  19. package/dist/chunk-GMU77L52.js.map +1 -0
  20. package/dist/chunk-NEWGUDA5.cjs +49 -0
  21. package/dist/chunk-NEWGUDA5.cjs.map +1 -0
  22. package/dist/{chunk-QHOV2A6M.cjs → chunk-PGEG7UZJ.cjs} +2 -34
  23. package/dist/chunk-PGEG7UZJ.cjs.map +1 -0
  24. package/dist/{chunk-XTJ22JAP.js → chunk-SWZRB3VY.js} +48 -14
  25. package/dist/chunk-SWZRB3VY.js.map +1 -0
  26. package/dist/chunk-UQ3BBEIT.js +47 -0
  27. package/dist/chunk-UQ3BBEIT.js.map +1 -0
  28. package/dist/{chunk-W6BH2YMZ.cjs → chunk-WCVD5LVG.cjs} +16 -34
  29. package/dist/chunk-WCVD5LVG.cjs.map +1 -0
  30. package/dist/{chunk-7BT6OXAR.cjs → chunk-XQJFLAMD.cjs} +53 -19
  31. package/dist/chunk-XQJFLAMD.cjs.map +1 -0
  32. package/dist/components/ActivitySequence.cjs +8 -5
  33. package/dist/components/ActivitySequence.d.cts +134 -8
  34. package/dist/components/ActivitySequence.d.ts +134 -8
  35. package/dist/components/ActivitySequence.js +7 -4
  36. package/dist/components/FillInTheBlanks.cjs +4 -3
  37. package/dist/components/FillInTheBlanks.d.cts +1 -1
  38. package/dist/components/FillInTheBlanks.d.ts +1 -1
  39. package/dist/components/FillInTheBlanks.js +3 -2
  40. package/dist/components/MultipleChoice.cjs +4 -3
  41. package/dist/components/MultipleChoice.d.cts +1 -1
  42. package/dist/components/MultipleChoice.d.ts +1 -1
  43. package/dist/components/MultipleChoice.js +3 -2
  44. package/dist/components/StimulusPanel.cjs +13 -0
  45. package/dist/components/StimulusPanel.cjs.map +1 -0
  46. package/dist/components/StimulusPanel.d.cts +30 -0
  47. package/dist/components/StimulusPanel.d.ts +30 -0
  48. package/dist/components/StimulusPanel.js +4 -0
  49. package/dist/components/StimulusPanel.js.map +1 -0
  50. package/dist/components/WrittenResponse.cjs +4 -3
  51. package/dist/components/WrittenResponse.d.cts +5 -86
  52. package/dist/components/WrittenResponse.d.ts +5 -86
  53. package/dist/components/WrittenResponse.js +3 -2
  54. package/dist/index.cjs +36 -26
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.d.cts +6 -4
  57. package/dist/index.d.ts +6 -4
  58. package/dist/index.js +12 -7
  59. package/dist/index.js.map +1 -1
  60. package/dist/theme/skin.css +124 -0
  61. package/dist/{types-CNmjqD6M.d.cts → types-CrURyd9-.d.cts} +51 -3
  62. package/dist/{types-CNmjqD6M.d.ts → types-CrURyd9-.d.ts} +51 -3
  63. package/package.json +81 -28
  64. package/dist/chunk-3X7MYAFT.js.map +0 -1
  65. package/dist/chunk-7BT6OXAR.cjs.map +0 -1
  66. package/dist/chunk-QHOV2A6M.cjs.map +0 -1
  67. package/dist/chunk-STLRKR2I.cjs +0 -111
  68. package/dist/chunk-STLRKR2I.cjs.map +0 -1
  69. package/dist/chunk-UASXUWHH.js +0 -109
  70. package/dist/chunk-UASXUWHH.js.map +0 -1
  71. package/dist/chunk-UIGIYYGY.js +0 -85
  72. package/dist/chunk-UIGIYYGY.js.map +0 -1
  73. package/dist/chunk-UXO6KYSZ.cjs.map +0 -1
  74. package/dist/chunk-W6BH2YMZ.cjs.map +0 -1
  75. package/dist/chunk-XTJ22JAP.js.map +0 -1
  76. package/dist/chunk-ZVFWJTT4.js.map +0 -1
package/README.md CHANGED
@@ -64,7 +64,8 @@ export function Demo() {
64
64
 
65
65
  - **`<MultipleChoice>`** — single / multi select, all-or-nothing or partial scoring, deterministic per-session shuffle, per-option `feedback`.
66
66
  - **`<FillInTheBlanks>`** — `{{id}}` placeholders, case/whitespace options, per-blank `hint` (Show/Hide toggle as an icon), per-blank `feedback` shown inline on submit with a learner-controlled **Hide/Show feedback** toggle, optional `showCorrectAnswers`.
67
- - **`<ActivitySequence>`** — in-place "question set" pager (Previous/Next, "Question X of N", no scrolling, focus-managed).
67
+ - **`<ActivitySequence>`** — in-place "question set" pager (Previous/Next, "Question X of N", no scrolling, focus-managed). Accepts item groups and keeps their stimulus beside every question; `onSubmit` reports every raw answer with its `slotId`, which is the only response channel an `exam` sequence has.
68
+ - **`<StimulusPanel>`** — a shared passage / recording / image (an item group's stimulus) as a landmark region; the sequence uses it, and a custom runner can too.
68
69
  - **Media per question** — optional `image` / `audio` / `video` / `embed` (YouTube/Vimeo iframe) above the question; alt-text required for `image`/`embed` (WCAG).
69
70
  - **Activity-level overall feedback** — `{ correct, incorrect }` shown after submit (h5p "Overall Feedback" parity).
70
71
  - **`useXAPI(config)`** — fire-and-forget LRS delivery with retry/backoff for 5xx/network (1 s / 2 s / 4 s), immediate fail on 4xx, never throws.
@@ -82,6 +83,7 @@ export function Demo() {
82
83
  | `@intellectif/lk-react/components/MultipleChoice` | `<MultipleChoice>` (boundary-wrapped) |
83
84
  | `@intellectif/lk-react/components/FillInTheBlanks` | `<FillInTheBlanks>` (boundary-wrapped) |
84
85
  | `@intellectif/lk-react/components/ActivitySequence` | `<ActivitySequence>` question-set pager |
86
+ | `@intellectif/lk-react/components/StimulusPanel` | `<StimulusPanel>` shared-stimulus region |
85
87
  | `@intellectif/lk-react/hooks/useActivityState` | Lifecycle + timing |
86
88
  | `@intellectif/lk-react/hooks/useXAPI` | LRS delivery (retry, never-throws) |
87
89
  | `@intellectif/lk-react/theme/ThemeProvider` | `<ThemeProvider>`, `darkTheme`, `useTheme`, `createTailwindTheme` |
@@ -0,0 +1,87 @@
1
+ import { XAPIStatement, WrittenResponseData, LearnerResponse, ItemOutcome, InteractionEvent, ThemeTokens } from '@intellectif/lk-core';
2
+ import { a as Renderable, R as RenderMode, H as HtmlSanitizer } from './types-CrURyd9-.js';
3
+
4
+ /**
5
+ * Payload delivered when the learner submits a written response. Grading is
6
+ * DEFERRED (asynchronous AI/human grading), so there is no score here — and
7
+ * deliberately no fake one: an ungraded submission must never be shown or
8
+ * stored as a 0. The consumer persists `text` and grades it out-of-band.
9
+ */
10
+ interface WrittenResponseSubmission {
11
+ /** The submitted text, verbatim. */
12
+ text: string;
13
+ /** Word count of `text`, recomputed with the canonical `countWords()`. */
14
+ wordCount: number;
15
+ /** Whether `wordCount` falls within the activity's `[minWords, maxWords]`. */
16
+ withinWordBounds: boolean;
17
+ /** Time in milliseconds from first interaction to submission. */
18
+ timeSpent: number;
19
+ /** The SUBMITTED-verb xAPI statement built for this submission (no score fields). */
20
+ xapiStatement: XAPIStatement;
21
+ }
22
+ /**
23
+ * Props for {@link WrittenResponse}. Mirrors `ActivityProps` except for the
24
+ * completion callback: a deferred-grading activity completes with a
25
+ * {@link WrittenResponseSubmission} (`onSubmitted`), not a scored
26
+ * `ActivityResult` (`onComplete`) — deviation from Req 22.8 recorded in the
27
+ * roadmap (§3.1): fabricating a score of 0 for ungraded work is the exact
28
+ * bug this type exists to fix. Everything else — controlled value, render
29
+ * mode, server outcome, rich text — follows the shared `ActivityProps`
30
+ * contract verbatim.
31
+ */
32
+ interface WrittenResponseProps {
33
+ /** Activity content. Accepts a `redact()` projection in `exam` mode. */
34
+ data: Renderable<WrittenResponseData>;
35
+ /**
36
+ * Called on submit with the ungraded submission (text, recomputed word
37
+ * count, bounds flag, timing, xAPI statement). Fires in `practice` and
38
+ * `exam` mode, after `onSubmit`; never in `review`.
39
+ *
40
+ * Optional since v0.4 so a `review`-mode render (which has no submit
41
+ * control) and an exam runner that only wants the raw response through
42
+ * `onSubmit` do not have to pass a no-op. Supply it in `practice`/`exam`
43
+ * unless `onSubmit` already captures everything you persist.
44
+ */
45
+ onSubmitted?: (submission: WrittenResponseSubmission) => void;
46
+ /**
47
+ * Called on submit with the raw learner response and no grade, BEFORE
48
+ * `onSubmitted`. This is the only submit callback an exam runner needs:
49
+ * the server grades the text and returns an {@link ItemOutcome} later.
50
+ */
51
+ onSubmit?: (response: LearnerResponse) => void;
52
+ /**
53
+ * Controlled value: the learner's current response. When present the
54
+ * textarea renders from it (never from internal state) and every keystroke
55
+ * goes out through `onChange` — restore an in-progress attempt, autosave a
56
+ * delta, or drive a review render with it.
57
+ */
58
+ value?: LearnerResponse;
59
+ /** Initial response for an uncontrolled component (ignored when `value` is set). */
60
+ defaultValue?: LearnerResponse;
61
+ /** Fires on every change to the learner's response. Required for a controlled component. */
62
+ onChange?: (response: LearnerResponse) => void;
63
+ /**
64
+ * Presentation mode, default `practice`. `practice` and `exam` are nearly
65
+ * identical here — a written response is never graded client-side, so
66
+ * there is no local score to withhold; `exam` additionally never calls
67
+ * `evaluate()` and renders happily from a `redact()` projection.
68
+ * `review` is read-only and shows the server's `outcome`.
69
+ */
70
+ renderMode?: RenderMode;
71
+ /**
72
+ * Server-computed outcome, rendered by `review` mode: `deferred` shows a
73
+ * "not graded yet" affordance, `scored` shows the returned grade and
74
+ * feedback. Ignored in other modes — this component never manufactures an
75
+ * outcome of its own.
76
+ */
77
+ outcome?: ItemOutcome;
78
+ /** Renders `data.promptHtml` when provided. See `HtmlSanitizer`. */
79
+ sanitizeHtml?: HtmlSanitizer;
80
+ onInteraction?: (event: InteractionEvent) => void;
81
+ /** Per-instance token overrides, applied as inline CSS vars on the root. */
82
+ theme?: Partial<ThemeTokens>;
83
+ locale?: string;
84
+ disabled?: boolean;
85
+ }
86
+
87
+ export type { WrittenResponseProps as W, WrittenResponseSubmission as a };
@@ -0,0 +1,87 @@
1
+ import { XAPIStatement, WrittenResponseData, LearnerResponse, ItemOutcome, InteractionEvent, ThemeTokens } from '@intellectif/lk-core';
2
+ import { a as Renderable, R as RenderMode, H as HtmlSanitizer } from './types-CrURyd9-.cjs';
3
+
4
+ /**
5
+ * Payload delivered when the learner submits a written response. Grading is
6
+ * DEFERRED (asynchronous AI/human grading), so there is no score here — and
7
+ * deliberately no fake one: an ungraded submission must never be shown or
8
+ * stored as a 0. The consumer persists `text` and grades it out-of-band.
9
+ */
10
+ interface WrittenResponseSubmission {
11
+ /** The submitted text, verbatim. */
12
+ text: string;
13
+ /** Word count of `text`, recomputed with the canonical `countWords()`. */
14
+ wordCount: number;
15
+ /** Whether `wordCount` falls within the activity's `[minWords, maxWords]`. */
16
+ withinWordBounds: boolean;
17
+ /** Time in milliseconds from first interaction to submission. */
18
+ timeSpent: number;
19
+ /** The SUBMITTED-verb xAPI statement built for this submission (no score fields). */
20
+ xapiStatement: XAPIStatement;
21
+ }
22
+ /**
23
+ * Props for {@link WrittenResponse}. Mirrors `ActivityProps` except for the
24
+ * completion callback: a deferred-grading activity completes with a
25
+ * {@link WrittenResponseSubmission} (`onSubmitted`), not a scored
26
+ * `ActivityResult` (`onComplete`) — deviation from Req 22.8 recorded in the
27
+ * roadmap (§3.1): fabricating a score of 0 for ungraded work is the exact
28
+ * bug this type exists to fix. Everything else — controlled value, render
29
+ * mode, server outcome, rich text — follows the shared `ActivityProps`
30
+ * contract verbatim.
31
+ */
32
+ interface WrittenResponseProps {
33
+ /** Activity content. Accepts a `redact()` projection in `exam` mode. */
34
+ data: Renderable<WrittenResponseData>;
35
+ /**
36
+ * Called on submit with the ungraded submission (text, recomputed word
37
+ * count, bounds flag, timing, xAPI statement). Fires in `practice` and
38
+ * `exam` mode, after `onSubmit`; never in `review`.
39
+ *
40
+ * Optional since v0.4 so a `review`-mode render (which has no submit
41
+ * control) and an exam runner that only wants the raw response through
42
+ * `onSubmit` do not have to pass a no-op. Supply it in `practice`/`exam`
43
+ * unless `onSubmit` already captures everything you persist.
44
+ */
45
+ onSubmitted?: (submission: WrittenResponseSubmission) => void;
46
+ /**
47
+ * Called on submit with the raw learner response and no grade, BEFORE
48
+ * `onSubmitted`. This is the only submit callback an exam runner needs:
49
+ * the server grades the text and returns an {@link ItemOutcome} later.
50
+ */
51
+ onSubmit?: (response: LearnerResponse) => void;
52
+ /**
53
+ * Controlled value: the learner's current response. When present the
54
+ * textarea renders from it (never from internal state) and every keystroke
55
+ * goes out through `onChange` — restore an in-progress attempt, autosave a
56
+ * delta, or drive a review render with it.
57
+ */
58
+ value?: LearnerResponse;
59
+ /** Initial response for an uncontrolled component (ignored when `value` is set). */
60
+ defaultValue?: LearnerResponse;
61
+ /** Fires on every change to the learner's response. Required for a controlled component. */
62
+ onChange?: (response: LearnerResponse) => void;
63
+ /**
64
+ * Presentation mode, default `practice`. `practice` and `exam` are nearly
65
+ * identical here — a written response is never graded client-side, so
66
+ * there is no local score to withhold; `exam` additionally never calls
67
+ * `evaluate()` and renders happily from a `redact()` projection.
68
+ * `review` is read-only and shows the server's `outcome`.
69
+ */
70
+ renderMode?: RenderMode;
71
+ /**
72
+ * Server-computed outcome, rendered by `review` mode: `deferred` shows a
73
+ * "not graded yet" affordance, `scored` shows the returned grade and
74
+ * feedback. Ignored in other modes — this component never manufactures an
75
+ * outcome of its own.
76
+ */
77
+ outcome?: ItemOutcome;
78
+ /** Renders `data.promptHtml` when provided. See `HtmlSanitizer`. */
79
+ sanitizeHtml?: HtmlSanitizer;
80
+ onInteraction?: (event: InteractionEvent) => void;
81
+ /** Per-instance token overrides, applied as inline CSS vars on the root. */
82
+ theme?: Partial<ThemeTokens>;
83
+ locale?: string;
84
+ disabled?: boolean;
85
+ }
86
+
87
+ export type { WrittenResponseProps as W, WrittenResponseSubmission as a };
@@ -1,6 +1,7 @@
1
- import { ActivityErrorBoundary, isDevelopment, ActivityMedia, FeedbackRegion, ANONYMOUS_ACTOR, objectIdFor } from './chunk-UIGIYYGY.js';
1
+ import { ActivityErrorBoundary, isDevelopment, FeedbackRegion, ANONYMOUS_ACTOR, objectIdFor } from './chunk-6F4X2NKL.js';
2
+ import { ActivityMedia } from './chunk-GB5URWM4.js';
2
3
  import { useActivityState } from './chunk-5HVUKXF3.js';
3
- import { assertRedacted, validateActivity, ActivitySchemaError, score, xAPIBuilder } from '@intellectif/lk-core';
4
+ import { assertRedacted, validateActivity, ActivitySchemaError, score, xAPIBuilder, xapiDefinitionFor } from '@intellectif/lk-core';
4
5
  import { useMemo, useState, useRef, useEffect } from 'react';
5
6
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
6
7
 
@@ -106,6 +107,11 @@ function FillInTheBlanks({
106
107
  if (devError) {
107
108
  throw devError;
108
109
  }
110
+ if (data.redacted === true && renderMode === "practice") {
111
+ throw new Error(
112
+ `Fill-in-the-Blanks "${data.id}" received redacted activity data in renderMode "practice", which grades locally and has no answer key to grade against. Render redacted data with renderMode="exam" (server grades) or "review" (pass \`outcome\`).`
113
+ );
114
+ }
109
115
  const submitted = state === "completed";
110
116
  const inactive = disabled === true || submitted || isReview;
111
117
  const revealing = isReview ? outcome?.status === "scored" : !isExam && submitted;
@@ -167,11 +173,7 @@ function FillInTheBlanks({
167
173
  object: {
168
174
  id: objectIdFor(data.id),
169
175
  name: { [data.locale ?? "en-US"]: data.title },
170
- type: "http://adlnet.gov/expapi/activities/cmi.interaction",
171
- interactionType: "fill-in",
172
- correctResponsesPattern: [
173
- data.blanks.map((blank) => blank.acceptedAnswers[0] ?? "").join("[,]")
174
- ]
176
+ ...xapiDefinitionFor(data)
175
177
  },
176
178
  scoringResult,
177
179
  timeSpentMs: timeSpent,
@@ -317,5 +319,5 @@ function FillInTheBlanks2(props) {
317
319
  }
318
320
 
319
321
  export { FillInTheBlanks2 as FillInTheBlanks };
320
- //# sourceMappingURL=chunk-3X7MYAFT.js.map
321
- //# sourceMappingURL=chunk-3X7MYAFT.js.map
322
+ //# sourceMappingURL=chunk-3DNJDP73.js.map
323
+ //# sourceMappingURL=chunk-3DNJDP73.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/FillInTheBlanks/FillInTheBlanks.tsx","../src/components/FillInTheBlanks/index.tsx"],"names":["result","FillInTheBlanks","jsx"],"mappings":";;;;;;;AAqCA,IAAM,WAAA,GAAc,0BAAA;AAIpB,SAAS,aAAa,OAAA,EAA4B;AAChD,EAAA,MAAM,WAAsB,EAAC;AAC7B,EAAA,MAAM,EAAA,GAAK,IAAI,MAAA,CAAO,WAAW,CAAA;AACjC,EAAA,IAAI,IAAA,GAAO,CAAA;AACX,EAAA,IAAI,OAAA,GAAU,CAAA;AACd,EAAA,IAAI,KAAA,GAAQ,EAAA,CAAG,IAAA,CAAK,OAAO,CAAA;AAC3B,EAAA,OAAO,UAAU,IAAA,EAAM;AACrB,IAAA,IAAI,KAAA,CAAM,QAAQ,IAAA,EAAM;AACtB,MAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,MAAA,EAAQ,KAAA,EAAO,OAAA,CAAQ,KAAA,CAAM,IAAA,EAAM,KAAA,CAAM,KAAK,CAAA,EAAG,CAAA;AAAA,IACzE;AACA,IAAA,OAAA,IAAW,CAAA;AACX,IAAA,QAAA,CAAS,IAAA,CAAK,EAAE,IAAA,EAAM,OAAA,EAAS,IAAI,KAAA,CAAM,CAAC,CAAA,EAAa,OAAA,EAAS,CAAA;AAChE,IAAA,IA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AA,EAA6B;AAC3D,EAAA,uBACEC,GAAAA,CAAC,qBAAA,EAAA,EAAsB,aAAA,EAAe,KAAA,CAAM,IAAA,EAAM,KAAA,EAChD,QAAA,kBAAAA,GAAAA,CAAC,eAAA,EAAA,EAAqB,GAAG,KAAA,EAAO,CAAA,EAClC,CAAA;AAEJ","file":"chunk-3DNJDP73.js","sourcesContent":["'use client';\n\nimport {\n ActivitySchemaError,\n assertRedacted,\n type FillInTheBlanksData,\n type FillInTheBlanksLearnerResponse,\n type LearnerResponse,\n type ScoringDetail,\n type ScoringResult,\n score,\n validateActivity,\n xAPIBuilder,\n xapiDefinitionFor,\n} from '@intellectif/lk-core';\nimport { type CSSProperties, useEffect, useMemo, useRef, useState } from 'react';\nimport { useActivityState } from '../../hooks/useActivityState.js';\nimport { ANONYMOUS_ACTOR, isDevelopment, objectIdFor } from '../_internal.js';\nimport { ActivityMedia } from '../shared/ActivityMedia.js';\nimport { FeedbackRegion } from '../shared/FeedbackRegion.js';\nimport type { ActivityProps } from '../types.js';\n\nexport interface FillInTheBlanksProps extends ActivityProps<FillInTheBlanksData> {\n /**\n * After submission, replace each incorrectly-answered blank with its first\n * accepted answer, styled distinctly (Req 5.7). Component-specific prop: it\n * is presentation, not activity data, and is outside the fixed Req-3.1 set.\n *\n * Ignored in `exam` mode — revealing the key is precisely what an exam must\n * not do, and on a `redact()` projection there is no key to reveal. In\n * `review` mode it applies only to blanks the supplied `outcome` marks\n * incorrect, and only when the caller passed data that still carries the key\n * (e.g. `redact(data, { reveal: 'after-submit' })`).\n */\n showCorrectAnswers?: boolean;\n}\n\nconst PLACEHOLDER = /\\{\\{\\s*([^{}]+?)\\s*\\}\\}/g;\n\ntype Segment = { kind: 'text'; value: string } | { kind: 'blank'; id: string; ordinal: number };\n\nfunction parsePassage(passage: string): Segment[] {\n const segments: Segment[] = [];\n const re = new RegExp(PLACEHOLDER);\n let last = 0;\n let ordinal = 0;\n let match = re.exec(passage);\n while (match !== null) {\n if (match.index > last) {\n segments.push({ kind: 'text', value: passage.slice(last, match.index) });\n }\n ordinal += 1;\n segments.push({ kind: 'blank', id: match[1] as string, ordinal });\n last = match.index + match[0].length;\n match = re.exec(passage);\n }\n if (last < passage.length) {\n segments.push({ kind: 'text', value: passage.slice(last) });\n }\n return segments;\n}\n\n/** Shared empty map: keeps the \"no response supplied\" path allocation-free. */\nconst NO_ANSWERS: Record<string, string> = {};\n\n/**\n * Reads the answer map out of a `LearnerResponse`. A response of another\n * activity type is treated as \"no answers\" rather than throwing: a controlled\n * host that has not yet swapped its state on an activity change would\n * otherwise crash the attempt.\n */\nfunction answersOf(response: LearnerResponse | undefined): Record<string, string> {\n return response !== undefined && response.type === 'fill-in-the-blanks'\n ? response.answers\n : NO_ANSWERS;\n}\n\n/**\n * Per-item correctness keyed by blank id. Prefers the unambiguous `outcome`\n * field (always written by the built-in scorers since lk-core 0.3.0) and\n * falls back to the deprecated `correct` boolean so a 0.2-era\n * consumer-constructed `ItemOutcome` still marks correctly in `review`.\n */\nfunction correctnessByItem(details: readonly ScoringDetail[]): Map<string, boolean> {\n const map = new Map<string, boolean>();\n for (const detail of details) {\n map.set(\n detail.itemId,\n detail.outcome !== undefined ? detail.outcome === 'correct' : detail.correct,\n );\n }\n return map;\n}\n\nexport function FillInTheBlanks({\n data,\n onComplete,\n onSubmit,\n onChange,\n onInteraction,\n value,\n defaultValue,\n renderMode = 'practice',\n outcome,\n sanitizeHtml,\n theme,\n locale,\n disabled,\n showCorrectAnswers,\n}: FillInTheBlanksProps) {\n const isExam = renderMode === 'exam';\n const isReview = renderMode === 'review';\n\n // Dev-only boundary validation (Req 2.3); throws in render so the wrapping\n // ActivityErrorBoundary catches it. Re-runs only when data changes.\n const devError = useMemo(() => {\n if (!isDevelopment()) {\n return null;\n }\n if (data.redacted === true) {\n // A redact() projection cannot satisfy the full content schema — the\n // answer key is gone by design. Validate it against the STRICT redacted\n // schema instead, which additionally proves the payload is learner-safe.\n try {\n assertRedacted(data);\n return null;\n } catch (error) {\n return error instanceof Error ? error : new Error(String(error));\n }\n }\n const result = validateActivity('fill-in-the-blanks', data);\n return result.success ? null : new ActivitySchemaError('fill-in-the-blanks', result.errors);\n }, [data]);\n\n const { state, start, complete, getTimeSpent, reset } = useActivityState();\n // Controlled when `value` is supplied: the answers rendered are ALWAYS the\n // caller's, and internal state is never read. Uncontrolled otherwise,\n // seeded from `defaultValue`.\n const isControlled = value !== undefined;\n const [internalAnswers, setInternalAnswers] = useState<Record<string, string>>(() =>\n answersOf(defaultValue),\n );\n const [revealed, setRevealed] = useState<Set<string>>(() => new Set());\n const [result, setResult] = useState<ScoringResult | null>(null);\n const [summary, setSummary] = useState<string | null>(null);\n const [feedbackHidden, setFeedbackHidden] = useState(false);\n\n const answers = isControlled ? answersOf(value) : internalAnswers;\n\n // `defaultValue` is read only by the reset effect, and it is commonly an\n // inline object literal — putting it in that effect's deps would re-seed\n // (and wipe) the learner's typing on every render. Mirror it into a ref in\n // its own effect, which commits before the reset effect below.\n const defaultValueRef = useRef(defaultValue);\n useEffect(() => {\n defaultValueRef.current = defaultValue;\n }, [defaultValue]);\n\n // `data` is an intentional reset trigger (Req 3.7), not read in the body.\n // biome-ignore lint/correctness/useExhaustiveDependencies: data is the reset trigger (Req 3.7)\n useEffect(() => {\n setInternalAnswers(answersOf(defaultValueRef.current));\n setRevealed(new Set());\n setResult(null);\n setSummary(null);\n setFeedbackHidden(false);\n reset();\n }, [data, reset]);\n\n /*\n * RICH TEXT — deliberate, documented limitation (see `sanitizeHtml`).\n *\n * Every other activity can render its `*Html` field through the caller's\n * sanitiser, because the rich text is a LEAF: the sanitised string is\n * handed to one `dangerouslySetInnerHTML` node and nothing is inserted into\n * it. A fill-in-the-blanks passage is not a leaf — it is the CONTAINER of\n * the React-controlled `<input>`s, one per `{{id}}` placeholder.\n *\n * Placing those inputs inside sanitised HTML means slicing the sanitised\n * string at the placeholders and injecting each slice as its own HTML\n * fragment, which is unsafe and broken on both counts:\n * 1. Broken: the slices are unbalanced. `<p>A {{x}} B</p>` yields `<p>A `\n * and ` B</p>`; the fragment parser auto-closes both, so the input\n * lands OUTSIDE the paragraph and the authored block structure is\n * destroyed.\n * 2. Unsafe: the sanitiser's guarantee covers the document it returned,\n * not arbitrary substrings of it. A placeholder inside an attribute\n * (`<img alt=\"{{x}}\">`) splits mid-attribute, and re-parsing the\n * halves in a fresh context is exactly the mutation (mXSS) class of\n * transformation that voids a sanitiser's output guarantee. An exam\n * runner must never depend on that.\n *\n * The safe alternative — parse the sanitised string once into a detached\n * DOM, split only TEXT nodes at placeholders, and portal the inputs into\n * anchors — needs a DOM at render time (no SSR) and a large imperative\n * subsystem. Until that lands, the plain-text `passage` is rendered (always\n * escaped by React), which is correct, answerable, and safe in every mode.\n * `data.passageHtml` is carried and redacted by lk-core regardless, so no\n * authored content is lost — only this component declines to render it.\n */\n useEffect(() => {\n if (isDevelopment() && sanitizeHtml !== undefined && data.passageHtml !== undefined) {\n console.warn(\n '[lk-react] FillInTheBlanks ignores `passageHtml`: the passage hosts the answer inputs, ' +\n 'so rich HTML cannot be split at {{placeholders}} without voiding the sanitiser. ' +\n 'Rendering the plain `passage` instead.',\n );\n }\n }, [sanitizeHtml, data.passageHtml]);\n\n const segments = useMemo(() => parsePassage(data.passage), [data.passage]);\n const blankById = useMemo(() => new Map(data.blanks.map((b) => [b.id, b])), [data.blanks]);\n\n if (devError) {\n throw devError;\n }\n // Practice grades locally, which a redacted projection cannot support: the\n // submit handler below calls `score()`, which throws RedactedScoringError —\n // from an event handler, where no error boundary can catch it, AFTER the\n // learner has typed their answers. Fail loudly at render instead, in\n // production too. This mirrors the identical guard in MultipleChoice;\n // without it the two built-ins disagreed about the same accident, and\n // wiring an exam item into the self-grading mode is precisely what\n // `renderMode` exists to prevent.\n if (data.redacted === true && renderMode === 'practice') {\n throw new Error(\n `Fill-in-the-Blanks \"${data.id}\" received redacted activity data in renderMode \"practice\", ` +\n 'which grades locally and has no answer key to grade against. ' +\n 'Render redacted data with renderMode=\"exam\" (server grades) or \"review\" (pass `outcome`).',\n );\n }\n\n const submitted = state === 'completed';\n const inactive = disabled === true || submitted || isReview;\n\n /**\n * Whether the component may show answer-key-derived information (per-blank\n * correctness, authored feedback, correct answers). NEVER in `exam`; in\n * `practice` only after the component scored locally; in `review` only once\n * the caller supplies a SCORED outcome — an item that is still awaiting a\n * grade must not have its key revealed just because it is being read back.\n */\n const revealing = isReview ? outcome?.status === 'scored' : !isExam && submitted;\n\n const fireInteraction = (\n type: 'blank-filled' | 'hint-requested' | 'submitted',\n payload: Record<string, unknown>,\n ): void => {\n onInteraction?.({ type, activityId: data.id, timestamp: Date.now(), payload });\n };\n\n const handleChange = (blankId: string, text: string): void => {\n if (inactive) {\n return;\n }\n if (state === 'idle') {\n start();\n }\n const next = { ...answers, [blankId]: text };\n if (!isControlled) {\n setInternalAnswers(next);\n }\n onChange?.({ type: 'fill-in-the-blanks', answers: next });\n fireInteraction('blank-filled', { blankId, value: text });\n };\n\n const toggleHint = (blankId: string): void => {\n if (inactive) {\n return;\n }\n if (state === 'idle') {\n start();\n }\n setRevealed((prev) => {\n const next = new Set(prev);\n if (next.has(blankId)) {\n next.delete(blankId);\n return next;\n }\n next.add(blankId);\n return next;\n });\n // Only a reveal is a \"hint requested\"; hiding is not a new request.\n if (!revealed.has(blankId)) {\n fireInteraction('hint-requested', { blankId });\n }\n };\n\n const handleSubmit = (event: React.FormEvent): void => {\n event.preventDefault();\n if (inactive) {\n return;\n }\n const response: FillInTheBlanksLearnerResponse = { type: 'fill-in-the-blanks', answers };\n // Fires in every submitting mode and always BEFORE onComplete, so an exam\n // runner can persist the raw response regardless of local grading.\n onSubmit?.(response);\n\n if (isExam) {\n // EXAM: the client neither grades nor reveals. No score()/evaluate(), no\n // read of any answer-key field, no onComplete — and no xAPI statement,\n // because its `correctResponsesPattern` IS the answer key. The server\n // owns the grade; it emits the statement.\n complete();\n setSummary('Answer submitted.');\n fireInteraction('submitted', { answers });\n return;\n }\n\n // PRACTICE: unchanged v1 behaviour. `data` carries the key here — exam\n // mode is the only path that may be handed a redact() projection.\n const scoringResult = score('fill-in-the-blanks', data as FillInTheBlanksData, response);\n complete();\n const timeSpent = getTimeSpent();\n const xapiStatement = xAPIBuilder.buildAnsweredStatement({\n actor: ANONYMOUS_ACTOR,\n object: {\n id: objectIdFor(data.id),\n name: { [data.locale ?? 'en-US']: data.title },\n ...xapiDefinitionFor(data),\n },\n scoringResult,\n timeSpentMs: timeSpent,\n response: JSON.stringify(answers),\n });\n setResult(scoringResult);\n onComplete?.({\n score: scoringResult.score,\n maxScore: scoringResult.maxScore,\n passed: scoringResult.passed,\n timeSpent,\n xapiStatement,\n });\n // Core selects the authored overall feedback on `passed` (B3 fix).\n const overall = scoringResult.feedback;\n setSummary(\n `Answer submitted. Score ${Math.round(scoringResult.score * 100)}%. ${\n scoringResult.passed ? 'Passed.' : 'Not passed.'\n }${overall ? ` ${overall}` : ''}`,\n );\n fireInteraction('submitted', { answers, score: scoringResult.score });\n };\n\n const correctByBlank = useMemo(() => {\n if (isExam) {\n // Nothing is ever marked client-side in an exam.\n return new Map<string, boolean>();\n }\n if (isReview) {\n // Correctness comes ONLY from the server-computed outcome; the component\n // never scores in review, so an absent/ungraded outcome marks nothing.\n return outcome?.status === 'scored'\n ? correctnessByItem(outcome.details)\n : new Map<string, boolean>();\n }\n return correctnessByItem(result?.details ?? []);\n }, [isExam, isReview, outcome, result]);\n\n /** Review has no local score: its summary is read off `outcome`, or nothing. */\n const reviewSummary = useMemo(() => {\n if (!isReview || outcome === undefined) {\n return null;\n }\n if (outcome.status === 'scored') {\n return `Score ${Math.round(outcome.score * 100)}%. ${\n outcome.passed ? 'Passed.' : 'Not passed.'\n }${outcome.feedback ? ` ${outcome.feedback}` : ''}`;\n }\n return outcome.status === 'deferred' ? 'Not graded yet.' : 'No grade available.';\n }, [isReview, outcome]);\n\n return (\n <form\n className=\"lk-fib\"\n aria-label={data.title}\n lang={locale}\n data-render-mode={renderMode}\n style={theme as CSSProperties | undefined}\n onSubmit={handleSubmit}\n >\n {data.media ? <ActivityMedia media={data.media} /> : null}\n <fieldset disabled={inactive}>\n <p className=\"lk-fib-passage\">\n {segments.map((seg, i) => {\n if (seg.kind === 'text') {\n // biome-ignore lint/suspicious/noArrayIndexKey: passage segments are positional and static\n return <span key={`t${i}`}>{seg.value}</span>;\n }\n const blank = blankById.get(seg.id);\n if (!blank) {\n return null;\n }\n // `Renderable` only widens `scoringStrategy` at the type level, so\n // the answer-key fields still LOOK required here while a redact()\n // projection omits them at runtime. Read them defensively, and\n // never at all in exam mode.\n const acceptedAnswers: string[] | undefined = isExam\n ? undefined\n : blank.acceptedAnswers;\n const blankFeedback = isExam ? undefined : blank.feedback;\n const correctness = correctByBlank.get(seg.id);\n const hintId = `${data.id}-hint-${seg.id}`;\n const correctAnswer = acceptedAnswers?.[0];\n if (revealing && showCorrectAnswers && correctness === false && correctAnswer) {\n return (\n <span key={seg.id} className=\"lk-fib-answer\" data-correct=\"false\">\n {correctAnswer}\n </span>\n );\n }\n return (\n <span key={seg.id} className=\"lk-fib-blank\">\n <input\n type=\"text\"\n aria-label={`Fill in blank ${seg.ordinal}`}\n aria-describedby={blank.hint ? hintId : undefined}\n value={answers[seg.id] ?? ''}\n disabled={inactive}\n aria-disabled={inactive || undefined}\n data-correct={\n revealing && correctness !== undefined ? String(correctness) : undefined\n }\n onChange={(e) => handleChange(seg.id, e.target.value)}\n />\n {/*\n Hints stay available in exam mode by design: lk-core's field\n policy classifies `blanks.hint` as `public`, so it survives\n redact() and is not part of the answer key.\n */}\n {blank.hint ? (\n <>\n {/*\n Default affordance is an icon; the accessible NAME stays\n text via aria-label (screen readers + tests rely on it).\n The glyph is restylable/replaceable via .lk-fib-hint-btn.\n */}\n <button\n type=\"button\"\n className=\"lk-fib-hint-btn\"\n aria-controls={hintId}\n aria-expanded={revealed.has(seg.id)}\n aria-label={revealed.has(seg.id) ? 'Hide hint' : 'Show hint'}\n disabled={inactive}\n onClick={() => toggleHint(seg.id)}\n >\n <svg\n className=\"lk-fib-hint-icon\"\n viewBox=\"0 0 24 24\"\n width=\"16\"\n height=\"16\"\n aria-hidden=\"true\"\n focusable=\"false\"\n >\n <path\n fill=\"currentColor\"\n d=\"M9 21h6v-1H9v1Zm3-19a7 7 0 0 0-4 12.74V17h8v-2.26A7 7 0 0 0 12 2Z\"\n />\n </svg>\n </button>\n {/*\n Not role=\"tooltip\": a real ARIA tooltip is a named\n hover/focus popup with strict WCAG 1.4.13 constraints.\n This is an accessible click-to-toggle disclosure that is\n the input's aria-describedby target and is announced via\n aria-live; the skin gives it a tooltip-like *visual*\n without the tooltip *semantics*. (Refines Task 15.3.)\n */}\n <span id={hintId} aria-live=\"polite\">\n {revealed.has(seg.id) ? blank.hint : ''}\n </span>\n </>\n ) : null}\n {revealing && !feedbackHidden && blankFeedback ? (\n <span\n className=\"lk-fib-blank-feedback\"\n role=\"note\"\n data-correct={correctness !== undefined ? String(correctness) : undefined}\n >\n {blankFeedback}\n </span>\n ) : null}\n </span>\n );\n })}\n </p>\n {/* Review is read-only: there is nothing to submit. */}\n {isReview ? null : (\n <button type=\"submit\" disabled={inactive}>\n {isExam ? 'Submit answers' : 'Check answers'}\n </button>\n )}\n </fieldset>\n {revealing && data.blanks.some((b) => b.feedback) ? (\n <button\n type=\"button\"\n className=\"lk-fib-feedback-toggle\"\n aria-expanded={!feedbackHidden}\n onClick={() => setFeedbackHidden((h) => !h)}\n >\n {feedbackHidden ? 'Show feedback' : 'Hide feedback'}\n </button>\n ) : null}\n <FeedbackRegion id={`${data.id}-feedback`}>\n {isReview ? reviewSummary : summary}\n </FeedbackRegion>\n </form>\n );\n}\n","'use client';\n\nimport { ActivityErrorBoundary } from '../ActivityErrorBoundary.js';\nimport {\n FillInTheBlanks as FillInTheBlanksCore,\n type FillInTheBlanksProps,\n} from './FillInTheBlanks.js';\n\nexport type { FillInTheBlanksProps } from './FillInTheBlanks.js';\n\n/**\n * Public Fill-in-the-Blanks activity: the core wrapped in\n * `ActivityErrorBoundary` so a render failure (incl. the dev schema-validation\n * throw) degrades to an accessible fallback instead of crashing the host.\n */\nexport function FillInTheBlanks(props: FillInTheBlanksProps) {\n return (\n <ActivityErrorBoundary activityTitle={props.data?.title}>\n <FillInTheBlanksCore {...props} />\n </ActivityErrorBoundary>\n );\n}\n"]}
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+
5
+ // src/components/shared/ActivityMedia.tsx
6
+ function ActivityMedia({ media }) {
7
+ const { type, url, alt, captionsUrl } = media;
8
+ if (type === "image") {
9
+ return /* @__PURE__ */ jsxRuntime.jsx("figure", { className: "lk-media", children: /* @__PURE__ */ jsxRuntime.jsx("img", { className: "lk-media-el", src: url, alt: alt ?? "" }) });
10
+ }
11
+ if (type === "audio") {
12
+ return /* @__PURE__ */ jsxRuntime.jsx("figure", { className: "lk-media", children: /* @__PURE__ */ jsxRuntime.jsxs("audio", { className: "lk-media-el", controls: true, "aria-label": alt || void 0, children: [
13
+ /* @__PURE__ */ jsxRuntime.jsx("source", { src: url }),
14
+ captionsUrl ? /* @__PURE__ */ jsxRuntime.jsx("track", { kind: "captions", src: captionsUrl, default: true }) : null
15
+ ] }) });
16
+ }
17
+ if (type === "embed") {
18
+ return /* @__PURE__ */ jsxRuntime.jsx("figure", { className: "lk-media", children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "lk-media-embed", children: /* @__PURE__ */ jsxRuntime.jsx(
19
+ "iframe",
20
+ {
21
+ className: "lk-media-el",
22
+ src: url,
23
+ title: alt ?? "Embedded media",
24
+ loading: "lazy",
25
+ referrerPolicy: "strict-origin-when-cross-origin",
26
+ sandbox: "allow-scripts allow-same-origin allow-presentation",
27
+ allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share",
28
+ allowFullScreen: true
29
+ }
30
+ ) }) });
31
+ }
32
+ return /* @__PURE__ */ jsxRuntime.jsx("figure", { className: "lk-media", children: /* @__PURE__ */ jsxRuntime.jsxs("video", { className: "lk-media-el", controls: true, "aria-label": alt || void 0, children: [
33
+ /* @__PURE__ */ jsxRuntime.jsx("source", { src: url }),
34
+ captionsUrl ? /* @__PURE__ */ jsxRuntime.jsx("track", { kind: "captions", src: captionsUrl, default: true }) : null
35
+ ] }) });
36
+ }
37
+
38
+ exports.ActivityMedia = ActivityMedia;
39
+ //# sourceMappingURL=chunk-4HZ7LQIH.cjs.map
40
+ //# sourceMappingURL=chunk-4HZ7LQIH.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/components/shared/ActivityMedia.tsx"],"names":["jsx","jsxs"],"mappings":";;;;;AAUO,SAAS,aAAA,CAAc,EAAE,KAAA,EAAM,EAAoD;AACxF,EAAA,MAAM,EAAE,IAAA,EAAM,GAAA,EAAK,GAAA,EAAK,aAAY,GAAI,KAAA;AAExC,EAAA,IAAI,SAAS,OAAA,EAAS;AACpB,IAAA,uBACEA,cAAA,CAAC,QAAA,EAAA,EAAO,SAAA,EAAU,UAAA,EAChB,QAAA,kBAAAA,cAAA,CAAC,KAAA,EAAA,EAAI,SAAA,EAAU,aAAA,EAAc,GAAA,EAAK,GAAA,EAAK,GAAA,EAAK,GAAA,IAAO,IAAI,CAAA,EACzD,CAAA;AAAA,EAEJ;AAEA,EAAA,IAAI,SAAS,OAAA,EAAS;AACpB,IAAA,uBACEA,cAAA,CAAC,QAAA,EAAA,EAAO,SAAA,EAAU,UAAA,EAEhB,QAAA,kBAAAC,eAAA,CAAC,OAAA,EAAA,EAAM,SAAA,EAAU,aAAA,EAAc,QAAA,EAAQ,IAAA,EAAC,YAAA,EAAY,GAAA,IAAO,MAAA,EACzD,QAAA,EAAA;AAAA,sBAAAD,cAAA,CAAC,QAAA,EAAA,EAAO,KAAK,GAAA,EAAK,CAAA;AAAA,MACjB,WAAA,kCAAe,OAAA,EAAA,EAAM,IAAA,EAAK,YAAW,GAAA,EAAK,WAAA,EAAa,OAAA,EAAO,IAAA,EAAC,CAAA,GAAK;AAAA,KAAA,EACvE,CAAA,EACF,CAAA;AAAA,EAEJ;AAEA,EAAA,IAAI,SAAS,OAAA,EAAS;AACpB,IAAA,sCACG,QAAA,EAAA,EAAO,SAAA,EAAU,YAChB,QAAA,kBAAAA,cAAA,CAAC,KAAA,EAAA,EAAI,WAAU,gBAAA,EACb,QAAA,kBAAAA,cAAA;AAAA,MAAC,QAAA;AAAA,MAAA;AAAA,QACC,SAAA,EAAU,aAAA;AAAA,QACV,GAAA,EAAK,GAAA;AAAA,QACL,OAAO,GAAA,IAAO,gBAAA;AAAA,QACd,OAAA,EAAQ,MAAA;AAAA,QACR,cAAA,EAAe,iCAAA;AAAA,QAMf,OAAA,EAAQ,oDAAA;AAAA,QACR,KAAA,EAAM,qGAAA;AAAA,QACN,eAAA,EAAe;AAAA;AAAA,OAEnB,CAAA,EACF,CAAA;AAAA,EAEJ;AAEA,EAAA,uBACEA,cAAA,CAAC,QAAA,EAAA,EAAO,SAAA,EAAU,UAAA,EAEhB,QAAA,kBAAAC,eAAA,CAAC,OAAA,EAAA,EAAM,SAAA,EAAU,aAAA,EAAc,QAAA,EAAQ,IAAA,EAAC,YAAA,EAAY,GAAA,IAAO,MAAA,EACzD,QAAA,EAAA;AAAA,oBAAAD,cAAA,CAAC,QAAA,EAAA,EAAO,KAAK,GAAA,EAAK,CAAA;AAAA,IACjB,WAAA,kCAAe,OAAA,EAAA,EAAM,IAAA,EAAK,YAAW,GAAA,EAAK,WAAA,EAAa,OAAA,EAAO,IAAA,EAAC,CAAA,GAAK;AAAA,GAAA,EACvE,CAAA,EACF,CAAA;AAEJ","file":"chunk-4HZ7LQIH.cjs","sourcesContent":["import type { ActivityMedia as ActivityMediaData } from '@intellectif/lk-core';\n\n/**\n * Presentational media block shown above a question or passage. URL-only:\n * the SDK does not host media (consumer responsibility). Accessibility:\n * images use `alt` (schema requires it non-empty); audio/video expose an\n * optional label and a captions `<track>` when `captionsUrl` is provided;\n * `embed` renders a responsive sandboxed iframe with `alt` as its required\n * accessible `title` (Req 14.5).\n */\nexport function ActivityMedia({ media }: { media: ActivityMediaData }): React.JSX.Element {\n const { type, url, alt, captionsUrl } = media;\n\n if (type === 'image') {\n return (\n <figure className=\"lk-media\">\n <img className=\"lk-media-el\" src={url} alt={alt ?? ''} />\n </figure>\n );\n }\n\n if (type === 'audio') {\n return (\n <figure className=\"lk-media\">\n {/* biome-ignore lint/a11y/useMediaCaption: captions are optional in the data contract — a <track> is rendered when captionsUrl is provided; absence is the author's documented choice (Req 14.5) */}\n <audio className=\"lk-media-el\" controls aria-label={alt || undefined}>\n <source src={url} />\n {captionsUrl ? <track kind=\"captions\" src={captionsUrl} default /> : null}\n </audio>\n </figure>\n );\n }\n\n if (type === 'embed') {\n return (\n <figure className=\"lk-media\">\n <div className=\"lk-media-embed\">\n <iframe\n className=\"lk-media-el\"\n src={url}\n title={alt ?? 'Embedded media'}\n loading=\"lazy\"\n referrerPolicy=\"strict-origin-when-cross-origin\"\n // The docblock always promised a sandboxed iframe; now it is one.\n // allow-scripts + allow-same-origin are required by provider\n // players (YouTube/Vimeo); top-navigation, forms, downloads and\n // popups stay blocked. Scheme allow-listing in MediaSchema is the\n // primary defense; this is depth.\n sandbox=\"allow-scripts allow-same-origin allow-presentation\"\n allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\"\n allowFullScreen\n />\n </div>\n </figure>\n );\n }\n\n return (\n <figure className=\"lk-media\">\n {/* biome-ignore lint/a11y/useMediaCaption: captions are optional in the data contract — a <track> is rendered when captionsUrl is provided; absence is the author's documented choice (Req 14.5) */}\n <video className=\"lk-media-el\" controls aria-label={alt || undefined}>\n <source src={url} />\n {captionsUrl ? <track kind=\"captions\" src={captionsUrl} default /> : null}\n </video>\n </figure>\n );\n}\n"]}
@@ -0,0 +1,249 @@
1
+ 'use strict';
2
+
3
+ var chunkWCVD5LVG_cjs = require('./chunk-WCVD5LVG.cjs');
4
+ var chunk67RIIDZX_cjs = require('./chunk-67RIIDZX.cjs');
5
+ var chunkXQJFLAMD_cjs = require('./chunk-XQJFLAMD.cjs');
6
+ var chunkPGEG7UZJ_cjs = require('./chunk-PGEG7UZJ.cjs');
7
+ var chunkNEWGUDA5_cjs = require('./chunk-NEWGUDA5.cjs');
8
+ var lkCore = require('@intellectif/lk-core');
9
+ var react = require('react');
10
+ var jsxRuntime = require('react/jsx-runtime');
11
+
12
+ function entryKeyOf(slot) {
13
+ return slot.slotId.split(".")[0] ?? slot.slotId;
14
+ }
15
+ function SequencePane({
16
+ className,
17
+ hidden,
18
+ children
19
+ }) {
20
+ const ref = react.useRef(null);
21
+ react.useEffect(() => {
22
+ if (!hidden) {
23
+ return;
24
+ }
25
+ const node = ref.current;
26
+ if (node === null) {
27
+ return;
28
+ }
29
+ for (const media of node.querySelectorAll("audio, video")) {
30
+ const element = media;
31
+ if (!element.paused) {
32
+ element.pause();
33
+ }
34
+ }
35
+ }, [hidden]);
36
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className, hidden, ref, children });
37
+ }
38
+ function ActivitySequence({
39
+ activities,
40
+ renderers,
41
+ onActivityComplete,
42
+ onComplete,
43
+ onFinished,
44
+ onSubmit,
45
+ onInteraction,
46
+ renderMode = "practice",
47
+ shuffle,
48
+ shuffleSeed,
49
+ sanitizeHtml,
50
+ theme,
51
+ locale,
52
+ disabled
53
+ }) {
54
+ const sessionIdRef = react.useRef(null);
55
+ const shuffleEntries = shuffle === "entries";
56
+ const needsSeed = shuffleEntries || activities.some((entry) => lkCore.isItemGroup(entry) && entry.shuffle === "within-group");
57
+ if (needsSeed && shuffleSeed === void 0 && renderMode !== "practice") {
58
+ throw new Error(
59
+ `ActivitySequence: renderMode "${renderMode}" requires a \`shuffleSeed\` when shuffling (shuffle="entries", or a group with shuffle: "within-group"). Pass the attempt id, so the server's flattenSequence(entries, { seed }) reproduces the order the learner saw.`
60
+ );
61
+ }
62
+ const seed = needsSeed ? (
63
+ // biome-ignore lint/suspicious/noAssignInExpressions: sanctioned lazy ref initialization
64
+ shuffleSeed ?? (sessionIdRef.current ??= chunkPGEG7UZJ_cjs.randomSessionId())
65
+ ) : void 0;
66
+ const slots = react.useMemo(
67
+ () => lkCore.flattenSequence(activities, { shuffleEntries, ...seed !== void 0 ? { seed } : {} }),
68
+ [activities, shuffleEntries, seed]
69
+ );
70
+ const [index, setIndex] = react.useState(0);
71
+ const outcomesRef = react.useRef(null);
72
+ if (outcomesRef.current === null) {
73
+ outcomesRef.current = slots.map(() => null);
74
+ }
75
+ const regionRef = react.useRef(null);
76
+ const mountedRef = react.useRef(false);
77
+ const setKey = JSON.stringify(slots.map((slot) => [slot.slotId, slot.activity.id]));
78
+ const [prevSetKey, setPrevSetKey] = react.useState(setKey);
79
+ if (prevSetKey !== setKey) {
80
+ setPrevSetKey(setKey);
81
+ setIndex(0);
82
+ outcomesRef.current = slots.map(() => null);
83
+ }
84
+ react.useEffect(() => {
85
+ if (mountedRef.current) {
86
+ regionRef.current?.focus();
87
+ } else {
88
+ mountedRef.current = true;
89
+ }
90
+ }, [index]);
91
+ const stimulusMounts = react.useMemo(() => {
92
+ const mounts = /* @__PURE__ */ new Map();
93
+ for (const slot of slots) {
94
+ if (slot.group === void 0) {
95
+ continue;
96
+ }
97
+ const entryKey = entryKeyOf(slot);
98
+ const existing = mounts.get(entryKey);
99
+ if (existing === void 0) {
100
+ mounts.set(entryKey, { entryKey, group: slot.group, first: slot.index, last: slot.index });
101
+ } else {
102
+ existing.last = slot.index;
103
+ }
104
+ }
105
+ return [...mounts.values()];
106
+ }, [slots]);
107
+ const total = slots.length;
108
+ const current = slots[index];
109
+ const go = (next) => {
110
+ setIndex(next);
111
+ };
112
+ const record = (outcome) => {
113
+ const current2 = outcomesRef.current;
114
+ if (current2 === null || current2[outcome.index] != null) {
115
+ return;
116
+ }
117
+ const next = current2.slice();
118
+ next[outcome.index] = outcome;
119
+ outcomesRef.current = next;
120
+ if (outcome.kind === "scored") {
121
+ onActivityComplete?.(outcome.result, outcome.index, outcome.slotId);
122
+ }
123
+ if (!next.every((item) => item !== null)) {
124
+ return;
125
+ }
126
+ onFinished?.(next);
127
+ const scored = [];
128
+ for (const item of next) {
129
+ if (item.kind !== "scored") {
130
+ return;
131
+ }
132
+ scored.push(item.result);
133
+ }
134
+ onComplete?.(scored);
135
+ };
136
+ if (!current) {
137
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "lk-seq" });
138
+ }
139
+ const forwarded = {
140
+ ...onInteraction ? { onInteraction } : {},
141
+ renderMode,
142
+ ...sanitizeHtml ? { sanitizeHtml } : {},
143
+ ...theme ? { theme } : {},
144
+ ...locale ? { locale } : {},
145
+ ...disabled ? { disabled } : {}
146
+ };
147
+ const renderSlot = (slot) => {
148
+ const activity = slot.activity;
149
+ const { slotId, index: slotIndex } = slot;
150
+ const activityId = activity.id;
151
+ const childProps = {
152
+ onComplete: (result) => record({ kind: "scored", index: slotIndex, slotId, activityId, result }),
153
+ onSubmit: (response) => {
154
+ onSubmit?.(response, { slotId, index: slotIndex, activityId });
155
+ if (renderMode !== "practice" && activity.type !== "written-response") {
156
+ record({ kind: "responded", index: slotIndex, slotId, activityId, response });
157
+ }
158
+ },
159
+ ...forwarded
160
+ };
161
+ const CustomRenderer = renderers?.[activity.type];
162
+ if (CustomRenderer) {
163
+ return /* @__PURE__ */ jsxRuntime.jsx(CustomRenderer, { data: activity, ...childProps });
164
+ }
165
+ if (activity.type === "multiple-choice") {
166
+ return /* @__PURE__ */ jsxRuntime.jsx(chunkWCVD5LVG_cjs.MultipleChoice, { data: activity, ...childProps });
167
+ }
168
+ if (activity.type === "fill-in-the-blanks") {
169
+ return /* @__PURE__ */ jsxRuntime.jsx(chunk67RIIDZX_cjs.FillInTheBlanks, { data: activity, ...childProps });
170
+ }
171
+ if (activity.type === "written-response") {
172
+ return /* @__PURE__ */ jsxRuntime.jsx(
173
+ chunkXQJFLAMD_cjs.WrittenResponse,
174
+ {
175
+ data: activity,
176
+ onSubmitted: (submission) => record({ kind: "submitted", index: slotIndex, slotId, activityId, submission }),
177
+ onSubmit: childProps.onSubmit,
178
+ ...forwarded
179
+ }
180
+ );
181
+ }
182
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "lk-seq-unsupported", role: "note", children: "This activity type has no renderer. Supply one through the renderers prop." });
183
+ };
184
+ const currentEntryKey = entryKeyOf(current);
185
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "lk-seq", lang: locale, children: [
186
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "lk-seq-progress", "aria-live": "polite", role: "status", children: [
187
+ "Question ",
188
+ index + 1,
189
+ " of ",
190
+ total
191
+ ] }),
192
+ stimulusMounts.map(({ entryKey, group, first, last }) => /* @__PURE__ */ jsxRuntime.jsx(
193
+ SequencePane,
194
+ {
195
+ className: "lk-seq-stimulus",
196
+ hidden: entryKey !== currentEntryKey,
197
+ children: /* @__PURE__ */ jsxRuntime.jsx(
198
+ chunkNEWGUDA5_cjs.StimulusPanel,
199
+ {
200
+ stimulus: group.stimulus,
201
+ range: { first: first + 1, last: last + 1 },
202
+ ...sanitizeHtml ? { sanitizeHtml } : {},
203
+ ...locale ? { locale } : {}
204
+ }
205
+ )
206
+ },
207
+ `group-${entryKey}`
208
+ )),
209
+ /* @__PURE__ */ jsxRuntime.jsx(
210
+ "section",
211
+ {
212
+ className: "lk-seq-question",
213
+ ref: regionRef,
214
+ tabIndex: -1,
215
+ "aria-label": `Question ${index + 1} of ${total}`,
216
+ children: slots.map((slot) => {
217
+ const slotKey = `${setKey}::slot-${slot.slotId}-${slot.activity.id}`;
218
+ return /* @__PURE__ */ jsxRuntime.jsx(SequencePane, { className: "lk-seq-slot", hidden: slot.index !== index, children: renderSlot(slot) }, slotKey);
219
+ })
220
+ }
221
+ ),
222
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "lk-seq-nav", children: [
223
+ /* @__PURE__ */ jsxRuntime.jsx(
224
+ "button",
225
+ {
226
+ type: "button",
227
+ className: "lk-seq-prev",
228
+ onClick: () => go(index - 1),
229
+ disabled: index === 0,
230
+ children: "Previous"
231
+ }
232
+ ),
233
+ /* @__PURE__ */ jsxRuntime.jsx(
234
+ "button",
235
+ {
236
+ type: "button",
237
+ className: "lk-seq-next",
238
+ onClick: () => go(index + 1),
239
+ disabled: index === total - 1,
240
+ children: "Next"
241
+ }
242
+ )
243
+ ] })
244
+ ] });
245
+ }
246
+
247
+ exports.ActivitySequence = ActivitySequence;
248
+ //# sourceMappingURL=chunk-525EWDUT.cjs.map
249
+ //# sourceMappingURL=chunk-525EWDUT.cjs.map