@intellectif/lk-react 6.0.0 → 6.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/CHANGELOG.md +330 -0
  2. package/README.md +43 -12
  3. package/dist/{WrittenResponse-C3GIWErG.d.ts → WrittenResponse-BXHidIaK.d.cts} +2 -2
  4. package/dist/{WrittenResponse-BfpzfLlR.d.cts → WrittenResponse-DJYGuMKk.d.ts} +2 -2
  5. package/dist/{chunk-E4MNA2IQ.js → chunk-2TW6WLBC.js} +3 -2
  6. package/dist/chunk-2TW6WLBC.js.map +1 -0
  7. package/dist/chunk-4HZ7LQIH.cjs +1 -0
  8. package/dist/chunk-57E3E2H4.js +1 -0
  9. package/dist/chunk-6F4X2NKL.js +1 -0
  10. package/dist/chunk-6N43WDVG.js +1 -0
  11. package/dist/{chunk-CPF2JJG6.cjs → chunk-AMGK7DDM.cjs} +32 -2
  12. package/dist/chunk-AMGK7DDM.cjs.map +1 -0
  13. package/dist/{chunk-YXG3UJVG.cjs → chunk-BE7R2X3S.cjs} +3 -2
  14. package/dist/chunk-BE7R2X3S.cjs.map +1 -0
  15. package/dist/{chunk-B3FUUKZ2.js → chunk-DQNVAXG6.js} +32 -3
  16. package/dist/chunk-DQNVAXG6.js.map +1 -0
  17. package/dist/{chunk-PBVMEOWI.cjs → chunk-DUIWK272.cjs} +7 -6
  18. package/dist/chunk-DUIWK272.cjs.map +1 -0
  19. package/dist/chunk-GB5URWM4.js +1 -0
  20. package/dist/{chunk-OQGBAQL2.js → chunk-IUODGQXE.js} +5 -4
  21. package/dist/chunk-IUODGQXE.js.map +1 -0
  22. package/dist/{chunk-R3OZ6JHQ.cjs → chunk-MDYKYDRN.cjs} +3 -2
  23. package/dist/chunk-MDYKYDRN.cjs.map +1 -0
  24. package/dist/{chunk-BQHDQ33H.js → chunk-MDZMKC27.js} +3 -2
  25. package/dist/chunk-MDZMKC27.js.map +1 -0
  26. package/dist/chunk-NEWGUDA5.cjs +1 -0
  27. package/dist/chunk-NPY2F7F6.cjs +1 -0
  28. package/dist/chunk-PGEG7UZJ.cjs +1 -0
  29. package/dist/{chunk-IYLQSNLE.cjs → chunk-PNNUPUH4.cjs} +3 -2
  30. package/dist/chunk-PNNUPUH4.cjs.map +1 -0
  31. package/dist/chunk-UQ3BBEIT.js +1 -0
  32. package/dist/chunk-XOR4MPEN.cjs +1 -0
  33. package/dist/{chunk-5TUTJ4R3.js → chunk-ZLUMUJUQ.js} +3 -2
  34. package/dist/chunk-ZLUMUJUQ.js.map +1 -0
  35. package/dist/components/ActivitySequence.cjs +5 -4
  36. package/dist/components/ActivitySequence.d.cts +18 -10
  37. package/dist/components/ActivitySequence.d.ts +18 -10
  38. package/dist/components/ActivitySequence.js +4 -3
  39. package/dist/components/FillInTheBlanks.cjs +1 -0
  40. package/dist/components/FillInTheBlanks.d.cts +1 -1
  41. package/dist/components/FillInTheBlanks.d.ts +1 -1
  42. package/dist/components/FillInTheBlanks.js +1 -0
  43. package/dist/components/MultipleChoice.cjs +3 -2
  44. package/dist/components/MultipleChoice.d.cts +2 -2
  45. package/dist/components/MultipleChoice.d.ts +2 -2
  46. package/dist/components/MultipleChoice.js +2 -1
  47. package/dist/components/StimulusPanel.cjs +1 -0
  48. package/dist/components/StimulusPanel.d.cts +1 -1
  49. package/dist/components/StimulusPanel.d.ts +1 -1
  50. package/dist/components/StimulusPanel.js +1 -0
  51. package/dist/components/WrittenResponse.cjs +3 -2
  52. package/dist/components/WrittenResponse.d.cts +3 -3
  53. package/dist/components/WrittenResponse.d.ts +3 -3
  54. package/dist/components/WrittenResponse.js +2 -1
  55. package/dist/hooks/useActivityState.cjs +1 -0
  56. package/dist/hooks/useActivityState.js +1 -0
  57. package/dist/hooks/useXAPI.cjs +3 -2
  58. package/dist/hooks/useXAPI.d.cts +31 -0
  59. package/dist/hooks/useXAPI.d.ts +31 -0
  60. package/dist/hooks/useXAPI.js +2 -1
  61. package/dist/index.cjs +18 -13
  62. package/dist/index.cjs.map +1 -1
  63. package/dist/index.d.cts +3 -3
  64. package/dist/index.d.ts +3 -3
  65. package/dist/index.js +6 -5
  66. package/dist/index.js.map +1 -1
  67. package/dist/theme/ThemeProvider.cjs +10 -5
  68. package/dist/theme/ThemeProvider.d.cts +21 -1
  69. package/dist/theme/ThemeProvider.d.ts +21 -1
  70. package/dist/theme/ThemeProvider.js +2 -1
  71. package/dist/theme/skin.css +7 -7
  72. package/dist/{types-DlHmPLbD.d.cts → types-9iS1Vs2I.d.cts} +29 -13
  73. package/dist/{types-DlHmPLbD.d.ts → types-9iS1Vs2I.d.ts} +29 -13
  74. package/package.json +28 -5
  75. package/dist/chunk-5TUTJ4R3.js.map +0 -1
  76. package/dist/chunk-B3FUUKZ2.js.map +0 -1
  77. package/dist/chunk-BQHDQ33H.js.map +0 -1
  78. package/dist/chunk-CPF2JJG6.cjs.map +0 -1
  79. package/dist/chunk-E4MNA2IQ.js.map +0 -1
  80. package/dist/chunk-IYLQSNLE.cjs.map +0 -1
  81. package/dist/chunk-OQGBAQL2.js.map +0 -1
  82. package/dist/chunk-PBVMEOWI.cjs.map +0 -1
  83. package/dist/chunk-R3OZ6JHQ.cjs.map +0 -1
  84. package/dist/chunk-YXG3UJVG.cjs.map +0 -1
@@ -10,6 +10,37 @@ interface UseXAPIResult {
10
10
  */
11
11
  sendStatement: (statement: XAPIStatement) => Promise<void>;
12
12
  }
13
+ /**
14
+ * Delivers xAPI statements to a Learning Record Store, fire-and-forget.
15
+ *
16
+ * Telemetry must never break the learner's attempt, so
17
+ * {@link UseXAPIResult.sendStatement} **never rejects**: network errors and 5xx
18
+ * responses are retried (backoff 1s / 2s / 4s, up to 3 retries), a 4xx fails
19
+ * immediately, and any final failure is reported to `config.onError` instead of
20
+ * throwing. See `XAPIConfig` in `@intellectif/lk-core` for the options.
21
+ *
22
+ * The hook is also where learner identity is applied. Activity components
23
+ * cannot know who the learner is, so they emit an anonymous placeholder actor
24
+ * and a `urn:learning-kit:activity:*` object id; this hook substitutes
25
+ * `config.actor` and `config.activityId` on the way out — and only while those
26
+ * placeholders are still in place, so a statement you rewrote yourself is left
27
+ * alone.
28
+ *
29
+ * `sendStatement` keeps a stable identity across renders even when `config` is
30
+ * an inline object, so it is safe in a dependency array.
31
+ *
32
+ * ```tsx
33
+ * const { sendStatement } = useXAPI({
34
+ * endpoint: 'https://your-lrs.example/xapi/statements',
35
+ * auth: { type: 'bearer', token: 'YOUR_TOKEN' },
36
+ * activityId: 'https://your-app.example/quiz/capital-jp',
37
+ * actor: { objectType: 'Agent', mbox: 'mailto:learner@example.com' },
38
+ * onError: (e) => console.error('xAPI send failed', e),
39
+ * });
40
+ *
41
+ * <MultipleChoice data={quiz} onComplete={(r) => void sendStatement(r.xapiStatement)} />
42
+ * ```
43
+ */
13
44
  declare function useXAPI(config: XAPIConfig): UseXAPIResult;
14
45
 
15
46
  export { type UseXAPIResult, useXAPI };
@@ -1,3 +1,4 @@
1
- export { useXAPI } from '../chunk-E4MNA2IQ.js';
1
+ 'use client';
2
+ export { useXAPI } from '../chunk-2TW6WLBC.js';
2
3
  //# sourceMappingURL=useXAPI.js.map
3
4
  //# sourceMappingURL=useXAPI.js.map
package/dist/index.cjs CHANGED
@@ -1,15 +1,16 @@
1
+ 'use client';
1
2
  'use strict';
2
3
 
3
- var chunkCPF2JJG6_cjs = require('./chunk-CPF2JJG6.cjs');
4
- var chunkPBVMEOWI_cjs = require('./chunk-PBVMEOWI.cjs');
5
- var chunkYXG3UJVG_cjs = require('./chunk-YXG3UJVG.cjs');
4
+ var chunkAMGK7DDM_cjs = require('./chunk-AMGK7DDM.cjs');
5
+ var chunkDUIWK272_cjs = require('./chunk-DUIWK272.cjs');
6
+ var chunkBE7R2X3S_cjs = require('./chunk-BE7R2X3S.cjs');
6
7
  var chunkNPY2F7F6_cjs = require('./chunk-NPY2F7F6.cjs');
7
- var chunkR3OZ6JHQ_cjs = require('./chunk-R3OZ6JHQ.cjs');
8
+ var chunkMDYKYDRN_cjs = require('./chunk-MDYKYDRN.cjs');
8
9
  require('./chunk-PGEG7UZJ.cjs');
9
10
  var chunkNEWGUDA5_cjs = require('./chunk-NEWGUDA5.cjs');
10
11
  require('./chunk-4HZ7LQIH.cjs');
11
12
  var chunkXOR4MPEN_cjs = require('./chunk-XOR4MPEN.cjs');
12
- var chunkIYLQSNLE_cjs = require('./chunk-IYLQSNLE.cjs');
13
+ var chunkPNNUPUH4_cjs = require('./chunk-PNNUPUH4.cjs');
13
14
 
14
15
  // src/components/types.ts
15
16
  function asRenderable(redacted) {
@@ -21,27 +22,31 @@ function asRenderableSequence(entries) {
21
22
 
22
23
  Object.defineProperty(exports, "ThemeProvider", {
23
24
  enumerable: true,
24
- get: function () { return chunkCPF2JJG6_cjs.ThemeProvider; }
25
+ get: function () { return chunkAMGK7DDM_cjs.ThemeProvider; }
26
+ });
27
+ Object.defineProperty(exports, "createTailwindTheme", {
28
+ enumerable: true,
29
+ get: function () { return chunkAMGK7DDM_cjs.createTailwindTheme; }
25
30
  });
26
31
  Object.defineProperty(exports, "darkTheme", {
27
32
  enumerable: true,
28
- get: function () { return chunkCPF2JJG6_cjs.darkTheme; }
33
+ get: function () { return chunkAMGK7DDM_cjs.darkTheme; }
29
34
  });
30
35
  Object.defineProperty(exports, "defaultTheme", {
31
36
  enumerable: true,
32
- get: function () { return chunkCPF2JJG6_cjs.defaultTheme; }
37
+ get: function () { return chunkAMGK7DDM_cjs.defaultTheme; }
33
38
  });
34
39
  Object.defineProperty(exports, "useTheme", {
35
40
  enumerable: true,
36
- get: function () { return chunkCPF2JJG6_cjs.useTheme; }
41
+ get: function () { return chunkAMGK7DDM_cjs.useTheme; }
37
42
  });
38
43
  Object.defineProperty(exports, "ActivitySequence", {
39
44
  enumerable: true,
40
- get: function () { return chunkPBVMEOWI_cjs.ActivitySequence; }
45
+ get: function () { return chunkDUIWK272_cjs.ActivitySequence; }
41
46
  });
42
47
  Object.defineProperty(exports, "MultipleChoice", {
43
48
  enumerable: true,
44
- get: function () { return chunkYXG3UJVG_cjs.MultipleChoice; }
49
+ get: function () { return chunkBE7R2X3S_cjs.MultipleChoice; }
45
50
  });
46
51
  Object.defineProperty(exports, "FillInTheBlanks", {
47
52
  enumerable: true,
@@ -49,7 +54,7 @@ Object.defineProperty(exports, "FillInTheBlanks", {
49
54
  });
50
55
  Object.defineProperty(exports, "WrittenResponse", {
51
56
  enumerable: true,
52
- get: function () { return chunkR3OZ6JHQ_cjs.WrittenResponse; }
57
+ get: function () { return chunkMDYKYDRN_cjs.WrittenResponse; }
53
58
  });
54
59
  Object.defineProperty(exports, "StimulusPanel", {
55
60
  enumerable: true,
@@ -61,7 +66,7 @@ Object.defineProperty(exports, "useActivityState", {
61
66
  });
62
67
  Object.defineProperty(exports, "useXAPI", {
63
68
  enumerable: true,
64
- get: function () { return chunkIYLQSNLE_cjs.useXAPI; }
69
+ get: function () { return chunkPNNUPUH4_cjs.useXAPI; }
65
70
  });
66
71
  exports.asRenderable = asRenderable;
67
72
  exports.asRenderableSequence = asRenderableSequence;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAoJO,SAAS,aACd,QAAA,EACmB;AACnB,EAAA,OAAO,QAAA;AACT;AA4BO,SAAS,qBACd,OAAA,EAC8C;AAC9C,EAAA,OAAO,OAAA;AACT","file":"index.cjs","sourcesContent":["import type {\n ActivityData,\n ActivityResult,\n InteractionEvent,\n ItemGroup,\n ItemOutcome,\n LearnerResponse,\n RedactedActivityData,\n SequenceEntry,\n ThemeTokens,\n} from '@intellectif/lk-core';\n\n/**\n * How an activity is being presented. This is the single switch that decides\n * whether the component may grade, reveal, or submit — the three things a\n * summative exam must take away from the client.\n *\n * - `practice` (default, v1 behaviour): the component owns the attempt. It\n * scores locally on submit, reveals correctness and feedback, and calls\n * `onComplete` with a full {@link ActivityResult}.\n * - `exam`: the component NEVER scores and NEVER reveals correctness. Submit\n * emits the raw learner response through `onSubmit`; the server grades it.\n * Safe to render redacted data, because nothing here needs the answer key.\n * - `review`: read-only. Renders the learner's submitted answer, and marks\n * correctness only from an `outcome` the caller supplies (which the server\n * computed). Nothing is submittable.\n */\nexport type RenderMode = 'practice' | 'exam' | 'review';\n\n/**\n * Makes the answer-key-bearing parts of an activity optional, so a component\n * can render either full activity data OR a `redact()` projection with the\n * same props. Fields the SDK classifies `answer-key` become optional here;\n * a component in `exam` mode must not read them at all.\n */\nexport type Renderable<TData> = Omit<TData, 'scoringStrategy'> & {\n scoringStrategy?: unknown;\n /** Present on a `redact()` projection. */\n redacted?: true;\n};\n\n/**\n * {@link Renderable} DISTRIBUTED over a union of activity types.\n *\n * This distinction is load-bearing, not cosmetic. `Renderable<T>` is built on\n * `Omit`, and `Omit` does not distribute: `Omit<A | B, K>` collapses to the\n * keys A and B have IN COMMON, so `Renderable<ActivityData>` is a single\n * object type carrying only the fields every activity shares. Narrowing it\n * dies with it — after `if (data.type === 'multiple-choice')` the compiler\n * still refuses `data.options`, because the union it would narrow to no\n * longer exists.\n *\n * The conditional below re-distributes, so `RenderableActivity` is a real\n * union of per-type renderables and `.type` narrows again. Anything that\n * accepts \"some renderable activity, I don't know which\" — a custom renderer,\n * a sequence entry — must use THIS, not `Renderable<ActivityData>`.\n */\nexport type RenderableActivity<TData extends ActivityData = ActivityData> = TData extends unknown\n ? Renderable<TData>\n : never;\n\n/**\n * Sanitiser for author-supplied rich text (`questionHtml`, `passageHtml`,\n * `promptHtml`). The SDK deliberately ships NO sanitiser — that would add a\n * dependency and, worse, a false promise. Rich text is rendered only when you\n * supply this function; without it the component falls back to the plain-text\n * field, which is always escaped. Fail-safe by construction: the SDK never\n * injects HTML it was not explicitly given a sanitiser for.\n */\nexport type HtmlSanitizer = (html: string) => string;\n\n/**\n * The prop contract shared by every activity component (Req 3.1). Defined\n * here (React-specific) rather than in lk-core, which is React-free.\n *\n * Controlled / uncontrolled follows the React convention: pass `value` +\n * `onChange` to own the learner's answer (restore an in-progress attempt,\n * autosave a delta, drive a review); pass `defaultValue` to seed an\n * uncontrolled component; pass neither for the v1 behaviour.\n */\nexport interface ActivityProps<TData extends ActivityData = ActivityData> {\n /** Activity content. Accepts a `redact()` projection in `exam` mode. */\n data: RenderableActivity<TData>;\n /**\n * Called when the component scored the attempt itself. Only ever fires in\n * `practice` mode — in `exam` mode the client does not grade, so there is\n * no `ActivityResult` to give you; use `onSubmit`.\n */\n onComplete?: (result: ActivityResult) => void;\n /**\n * Called on submit with the raw learner response and no grade. Fires in\n * every mode, before `onComplete`, so an exam runner can persist the\n * response and let the server score it.\n */\n onSubmit?: (response: LearnerResponse) => void;\n /** Controlled value: the learner's current response. */\n value?: LearnerResponse;\n /** Initial response for an uncontrolled component (ignored when `value` is set). */\n defaultValue?: LearnerResponse;\n /**\n * Mount the component as already submitted — read at mount only, like any\n * `default*` prop.\n *\n * Restoring an attempt without it reopens a question the learner had already\n * submitted as answerable, so on a summative paper they can change and\n * re-submit it. `AttemptState.submittedSlotIds` is what this consumes.\n */\n defaultSubmitted?: boolean;\n /** Fires on every change to the learner's response. Required for a controlled component. */\n onChange?: (response: LearnerResponse) => void;\n /** Presentation mode. Defaults to `practice`. */\n renderMode?: RenderMode;\n /**\n * Server-computed outcome, used by `review` mode to mark correctness\n * without the client ever scoring. Ignored in other modes.\n */\n outcome?: ItemOutcome;\n /** Renders author-supplied rich text when provided. See {@link HtmlSanitizer}. */\n sanitizeHtml?: HtmlSanitizer;\n onInteraction?: (event: InteractionEvent) => void;\n /** Per-instance token overrides, applied as inline CSS vars on the root. */\n theme?: Partial<ThemeTokens>;\n locale?: string;\n disabled?: boolean;\n}\n\n/**\n * Bridges a server-produced `redact()` projection into the `data` prop.\n *\n * `RedactedActivityData` is deliberately index-signature typed in lk-core — it\n * proves a payload is learner-safe, not what shape it has — so TypeScript\n * cannot know it still carries the public fields a renderer needs. This is the\n * SDK's single, documented crossing of that gap, so an exam runner does not\n * have to write `as unknown as` at every call site:\n *\n * ```tsx\n * <MultipleChoice\n * data={asRenderable<MultipleChoiceData>(redactedFromServer)}\n * renderMode=\"exam\"\n * onSubmit={persist}\n * />\n * ```\n *\n * Safe because `exam` mode reads only public fields; the answer-key fields the\n * type claims are exactly the ones the component is forbidden to touch there.\n * A future release will derive per-type redacted interfaces so this becomes\n * unnecessary.\n */\nexport function asRenderable<TData extends ActivityData>(\n redacted: RedactedActivityData,\n): Renderable<TData> {\n return redacted as unknown as Renderable<TData>;\n}\n\n/**\n * The same bridge as {@link asRenderable}, for a whole sequence: activities\n * and item groups as a server hands them over, ready for `<ActivitySequence>`.\n *\n * Needed for the same reason and no other. `redactItemGroup` returns\n * `ItemGroup<RedactedActivityData>`, and `RedactedActivityData` is an\n * index-signature type whose fields are all `unknown` — so its `question` is\n * not a `string` and it satisfies no per-type renderable, however the prop is\n * widened. Widening alone cannot fix this; a crossing point is required, and\n * having exactly one keeps `as unknown as` out of consumer code.\n *\n * ```tsx\n * const entries = await fetchExam(); // redacted, server-side\n * <ActivitySequence\n * activities={asRenderableSequence(entries)}\n * renderMode=\"exam\" // REQUIRED: see below\n * shuffleSeed={attemptId}\n * onSubmit={persist}\n * />\n * ```\n *\n * Pass `renderMode=\"exam\"` (or `\"review\"`). Redacted data has no answer key,\n * and the default `practice` mode grades locally — the built-in components\n * throw at render rather than fail at submit time, so a mis-wired exam item is\n * loud, not silent.\n */\nexport function asRenderableSequence(\n entries: readonly (RedactedActivityData | RedactedItemGroupData)[],\n): readonly SequenceEntry<RenderableActivity>[] {\n return entries as unknown as readonly SequenceEntry<RenderableActivity>[];\n}\n\n/** Structural shape of a `redactItemGroup()` projection, as it arrives from a server. */\ntype RedactedItemGroupData = ItemGroup<RedactedActivityData> & { redacted: true };\n"]}
1
+ {"version":3,"sources":["../src/components/types.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAgKO,SAAS,aACd,QAAA,EACmB;AACnB,EAAA,OAAO,QAAA;AACT;AAgCO,SAAS,qBACd,OAAA,EAC8C;AAC9C,EAAA,OAAO,OAAA;AACT","file":"index.cjs","sourcesContent":["import type {\n ActivityData,\n ActivityResult,\n InteractionEvent,\n ItemGroup,\n ItemOutcome,\n LearnerResponse,\n RedactedActivityData,\n SequenceEntry,\n ThemeTokens,\n} from '@intellectif/lk-core';\n\n/**\n * How an activity is being presented. This is the single switch that decides\n * whether the component may grade, reveal, or submit — the three things a\n * summative exam must take away from the client.\n *\n * - `practice` (default, and the only behaviour before `renderMode` existed):\n * the component owns the attempt. It\n * scores locally on submit, reveals correctness and feedback, and calls\n * `onComplete` with a full {@link ActivityResult}.\n * - `exam`: the component NEVER scores and NEVER reveals correctness. Submit\n * emits the raw learner response through `onSubmit`; the server grades it.\n * Safe to render redacted data, because nothing here needs the answer key.\n * - `review`: read-only. Renders the learner's submitted answer, and marks\n * correctness only from an `outcome` the caller supplies (which the server\n * computed). Nothing is submittable.\n */\nexport type RenderMode = 'practice' | 'exam' | 'review';\n\n/**\n * Makes the answer-key-bearing parts of an activity optional, so a component\n * can render either full activity data OR a `redact()` projection with the\n * same props. Fields the SDK classifies `answer-key` become optional here;\n * a component in `exam` mode must not read them at all.\n */\nexport type Renderable<TData> = Omit<TData, 'scoringStrategy'> & {\n scoringStrategy?: unknown;\n /** Present on a `redact()` projection. */\n redacted?: true;\n};\n\n/**\n * {@link Renderable} DISTRIBUTED over a union of activity types.\n *\n * This distinction is load-bearing, not cosmetic. `Renderable<T>` is built on\n * `Omit`, and `Omit` does not distribute: `Omit<A | B, K>` collapses to the\n * keys A and B have IN COMMON, so `Renderable<ActivityData>` is a single\n * object type carrying only the fields every activity shares. Narrowing it\n * dies with it — after `if (data.type === 'multiple-choice')` the compiler\n * still refuses `data.options`, because the union it would narrow to no\n * longer exists.\n *\n * The conditional below re-distributes, so `RenderableActivity` is a real\n * union of per-type renderables and `.type` narrows again. Anything that\n * accepts \"some renderable activity, I don't know which\" — a custom renderer,\n * a sequence entry — must use THIS, not `Renderable<ActivityData>`.\n */\nexport type RenderableActivity<TData extends ActivityData = ActivityData> = TData extends unknown\n ? Renderable<TData>\n : never;\n\n/**\n * Sanitiser for author-supplied rich text (`questionHtml`, `promptHtml`, and a\n * stimulus's `bodyHtml`). The SDK deliberately ships NO sanitiser — that would\n * add a dependency and, worse, a false promise. Rich text is rendered only when\n * you supply this function; without it the component falls back to the\n * plain-text field, which is always escaped. Fail-safe by construction: the SDK\n * never injects HTML it was not explicitly given a sanitiser for.\n *\n * `FillInTheBlanks.passageHtml` is the one exception, and is **never**\n * rendered: the passage hosts the answer inputs, so it cannot be split at the\n * `{{blank}}` placeholders without voiding the sanitiser. The plain `passage`\n * is always used, and passing `passageHtml` warns in development.\n */\nexport type HtmlSanitizer = (html: string) => string;\n\n/**\n * The prop contract shared by every activity component (Req 3.1). Defined\n * here (React-specific) rather than in lk-core, which is React-free.\n *\n * Controlled / uncontrolled follows the React convention: pass `value` +\n * `onChange` to own the learner's answer (restore an in-progress attempt,\n * autosave a delta, drive a review); pass `defaultValue` to seed an\n * uncontrolled component; pass neither to keep the pre-2.1.0 behaviour, where\n * the component owns the answer outright.\n */\nexport interface ActivityProps<TData extends ActivityData = ActivityData> {\n /** Activity content. Accepts a `redact()` projection in `exam` mode. */\n data: RenderableActivity<TData>;\n /**\n * Called when the component scored the attempt itself. Only ever fires in\n * `practice` mode — in `exam` mode the client does not grade, so there is\n * no `ActivityResult` to give you; use `onSubmit`.\n */\n onComplete?: (result: ActivityResult) => void;\n /**\n * Called on submit with the raw learner response and no grade. Fires in\n * every mode, before `onComplete`, so an exam runner can persist the\n * response and let the server score it.\n */\n onSubmit?: (response: LearnerResponse) => void;\n /** Controlled value: the learner's current response. */\n value?: LearnerResponse;\n /** Initial response for an uncontrolled component (ignored when `value` is set). */\n defaultValue?: LearnerResponse;\n /**\n * Mount the component as already submitted — read at mount only, like any\n * `default*` prop.\n *\n * Restoring an attempt without it reopens a question the learner had already\n * submitted as answerable, so on a summative paper they can change and\n * re-submit it. `AttemptState.submittedSlotIds` is what this consumes.\n */\n defaultSubmitted?: boolean;\n /** Fires on every change to the learner's response. Required for a controlled component. */\n onChange?: (response: LearnerResponse) => void;\n /** Presentation mode. Defaults to `practice`. */\n renderMode?: RenderMode;\n /**\n * Server-computed outcome, used by `review` mode to mark correctness\n * without the client ever scoring. Ignored in other modes.\n */\n outcome?: ItemOutcome;\n /** Renders author-supplied rich text when provided. See {@link HtmlSanitizer}. */\n sanitizeHtml?: HtmlSanitizer;\n onInteraction?: (event: InteractionEvent) => void;\n /** Per-instance token overrides, applied as inline CSS vars on the root. */\n theme?: Partial<ThemeTokens>;\n locale?: string;\n disabled?: boolean;\n}\n\n/**\n * Bridges a server-produced `redact()` projection into the `data` prop.\n *\n * `RedactedActivityData` is deliberately index-signature typed in lk-core — it\n * proves a payload is learner-safe, not what shape it has — so TypeScript\n * cannot know it still carries the public fields a renderer needs. This is the\n * SDK's single, documented crossing of that gap, so an exam runner does not\n * have to write `as unknown as` at every call site:\n *\n * ```tsx\n * <MultipleChoice\n * data={asRenderable<MultipleChoiceData>(redactedFromServer)}\n * renderMode=\"exam\"\n * onSubmit={persist}\n * />\n * ```\n *\n * Safe because `exam` mode reads only public fields; the answer-key fields the\n * type claims are exactly the ones the component is forbidden to touch there.\n *\n * Per-type redacted interfaces (`RedactedMultipleChoiceData`, …) ship from\n * lk-core since 0.6.0, but they are not yet *assignable* to `data`:\n * {@link Renderable} widens `scoringStrategy` and leaves nested answer-key\n * fields (`options[].isCorrect`, `blanks[].acceptedAnswers`) required, so a\n * real redacted payload still needs this bridge. Closing that gap is tracked\n * in the roadmap.\n */\nexport function asRenderable<TData extends ActivityData>(\n redacted: RedactedActivityData,\n): Renderable<TData> {\n return redacted as unknown as Renderable<TData>;\n}\n\n/**\n * The same bridge as {@link asRenderable}, for a whole sequence: activities\n * and item groups as a server hands them over, ready for `<ActivitySequence>`.\n *\n * Needed for the same reason and no other. `redactItemGroup` returns\n * `ItemGroup<RedactedActivityData>`, and `RedactedActivityData` is an\n * index-signature type whose fields are all `unknown` — so its `question` is\n * not a `string` and it satisfies no per-type renderable, however the prop is\n * widened. Widening alone cannot fix this; a crossing point is required, and\n * having exactly one keeps `as unknown as` out of consumer code.\n *\n * ```tsx\n * const entries = await fetchExam(); // redacted, server-side\n * <ActivitySequence\n * activities={asRenderableSequence(entries)}\n * renderMode=\"exam\" // REQUIRED: see below\n * shuffleSeed={attemptId}\n * onSubmit={persist}\n * />\n * ```\n *\n * Pass `renderMode=\"exam\"` (or `\"review\"`). Redacted data has no answer key,\n * and the default `practice` mode grades locally — so `<MultipleChoice>` and\n * `<FillInTheBlanks>` throw at render rather than fail at submit time.\n *\n * `<WrittenResponse>` is the exception: it never grades on the client and has\n * no such guard, so a redacted essay renders and stays answerable in\n * `practice`. A mis-wired essay item is therefore SILENT — set `renderMode`\n * explicitly rather than relying on the throw.\n */\nexport function asRenderableSequence(\n entries: readonly (RedactedActivityData | RedactedItemGroupData)[],\n): readonly SequenceEntry<RenderableActivity>[] {\n return entries as unknown as readonly SequenceEntry<RenderableActivity>[];\n}\n\n/** Structural shape of a `redactItemGroup()` projection, as it arrives from a server. */\ntype RedactedItemGroupData = ItemGroup<RedactedActivityData> & { redacted: true };\n"]}
package/dist/index.d.cts CHANGED
@@ -2,12 +2,12 @@ export { ActivityRenderer, ActivitySequence, ActivitySequenceProps, SequenceItem
2
2
  export { FillInTheBlanks, FillInTheBlanksProps } from './components/FillInTheBlanks.cjs';
3
3
  export { MultipleChoice, MultipleChoiceProps } from './components/MultipleChoice.cjs';
4
4
  export { StimulusPanel, StimulusPanelProps } from './components/StimulusPanel.cjs';
5
- export { A as ActivityProps, H as HtmlSanitizer, R as RenderMode, a as Renderable, b as RenderableActivity, c as asRenderable, d as asRenderableSequence } from './types-DlHmPLbD.cjs';
5
+ export { A as ActivityProps, H as HtmlSanitizer, R as RenderMode, a as Renderable, b as RenderableActivity, c as asRenderable, d as asRenderableSequence } from './types-9iS1Vs2I.cjs';
6
6
  export { WrittenResponse } from './components/WrittenResponse.cjs';
7
7
  export { ActivityState, UseActivityStateResult, useActivityState } from './hooks/useActivityState.cjs';
8
8
  export { UseXAPIResult, useXAPI } from './hooks/useXAPI.cjs';
9
- export { ThemeProvider, ThemeProviderProps, darkTheme, defaultTheme, useTheme } from './theme/ThemeProvider.cjs';
10
- export { W as WrittenResponseProps, a as WrittenResponseSubmission } from './WrittenResponse-BfpzfLlR.cjs';
9
+ export { TailwindThemeExtension, ThemeProvider, ThemeProviderProps, createTailwindTheme, darkTheme, defaultTheme, useTheme } from './theme/ThemeProvider.cjs';
10
+ export { W as WrittenResponseProps, a as WrittenResponseSubmission } from './WrittenResponse-BXHidIaK.cjs';
11
11
  import '@intellectif/lk-core';
12
12
  import 'react';
13
13
  import 'react/jsx-runtime';
package/dist/index.d.ts CHANGED
@@ -2,12 +2,12 @@ export { ActivityRenderer, ActivitySequence, ActivitySequenceProps, SequenceItem
2
2
  export { FillInTheBlanks, FillInTheBlanksProps } from './components/FillInTheBlanks.js';
3
3
  export { MultipleChoice, MultipleChoiceProps } from './components/MultipleChoice.js';
4
4
  export { StimulusPanel, StimulusPanelProps } from './components/StimulusPanel.js';
5
- export { A as ActivityProps, H as HtmlSanitizer, R as RenderMode, a as Renderable, b as RenderableActivity, c as asRenderable, d as asRenderableSequence } from './types-DlHmPLbD.js';
5
+ export { A as ActivityProps, H as HtmlSanitizer, R as RenderMode, a as Renderable, b as RenderableActivity, c as asRenderable, d as asRenderableSequence } from './types-9iS1Vs2I.js';
6
6
  export { WrittenResponse } from './components/WrittenResponse.js';
7
7
  export { ActivityState, UseActivityStateResult, useActivityState } from './hooks/useActivityState.js';
8
8
  export { UseXAPIResult, useXAPI } from './hooks/useXAPI.js';
9
- export { ThemeProvider, ThemeProviderProps, darkTheme, defaultTheme, useTheme } from './theme/ThemeProvider.js';
10
- export { W as WrittenResponseProps, a as WrittenResponseSubmission } from './WrittenResponse-C3GIWErG.js';
9
+ export { TailwindThemeExtension, ThemeProvider, ThemeProviderProps, createTailwindTheme, darkTheme, defaultTheme, useTheme } from './theme/ThemeProvider.js';
10
+ export { W as WrittenResponseProps, a as WrittenResponseSubmission } from './WrittenResponse-DJYGuMKk.js';
11
11
  import '@intellectif/lk-core';
12
12
  import 'react';
13
13
  import 'react/jsx-runtime';
package/dist/index.js CHANGED
@@ -1,13 +1,14 @@
1
- export { ThemeProvider, darkTheme, defaultTheme, useTheme } from './chunk-B3FUUKZ2.js';
2
- export { ActivitySequence } from './chunk-OQGBAQL2.js';
3
- export { MultipleChoice } from './chunk-5TUTJ4R3.js';
1
+ 'use client';
2
+ export { ThemeProvider, createTailwindTheme, darkTheme, defaultTheme, useTheme } from './chunk-DQNVAXG6.js';
3
+ export { ActivitySequence } from './chunk-IUODGQXE.js';
4
+ export { MultipleChoice } from './chunk-ZLUMUJUQ.js';
4
5
  export { FillInTheBlanks } from './chunk-57E3E2H4.js';
5
- export { WrittenResponse } from './chunk-BQHDQ33H.js';
6
+ export { WrittenResponse } from './chunk-MDZMKC27.js';
6
7
  import './chunk-6F4X2NKL.js';
7
8
  export { StimulusPanel } from './chunk-UQ3BBEIT.js';
8
9
  import './chunk-GB5URWM4.js';
9
10
  export { useActivityState } from './chunk-6N43WDVG.js';
10
- export { useXAPI } from './chunk-E4MNA2IQ.js';
11
+ export { useXAPI } from './chunk-2TW6WLBC.js';
11
12
 
12
13
  // src/components/types.ts
13
14
  function asRenderable(redacted) {
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/components/types.ts"],"names":[],"mappings":";;;;;;;;;;;;AAoJO,SAAS,aACd,QAAA,EACmB;AACnB,EAAA,OAAO,QAAA;AACT;AA4BO,SAAS,qBACd,OAAA,EAC8C;AAC9C,EAAA,OAAO,OAAA;AACT","file":"index.js","sourcesContent":["import type {\n ActivityData,\n ActivityResult,\n InteractionEvent,\n ItemGroup,\n ItemOutcome,\n LearnerResponse,\n RedactedActivityData,\n SequenceEntry,\n ThemeTokens,\n} from '@intellectif/lk-core';\n\n/**\n * How an activity is being presented. This is the single switch that decides\n * whether the component may grade, reveal, or submit — the three things a\n * summative exam must take away from the client.\n *\n * - `practice` (default, v1 behaviour): the component owns the attempt. It\n * scores locally on submit, reveals correctness and feedback, and calls\n * `onComplete` with a full {@link ActivityResult}.\n * - `exam`: the component NEVER scores and NEVER reveals correctness. Submit\n * emits the raw learner response through `onSubmit`; the server grades it.\n * Safe to render redacted data, because nothing here needs the answer key.\n * - `review`: read-only. Renders the learner's submitted answer, and marks\n * correctness only from an `outcome` the caller supplies (which the server\n * computed). Nothing is submittable.\n */\nexport type RenderMode = 'practice' | 'exam' | 'review';\n\n/**\n * Makes the answer-key-bearing parts of an activity optional, so a component\n * can render either full activity data OR a `redact()` projection with the\n * same props. Fields the SDK classifies `answer-key` become optional here;\n * a component in `exam` mode must not read them at all.\n */\nexport type Renderable<TData> = Omit<TData, 'scoringStrategy'> & {\n scoringStrategy?: unknown;\n /** Present on a `redact()` projection. */\n redacted?: true;\n};\n\n/**\n * {@link Renderable} DISTRIBUTED over a union of activity types.\n *\n * This distinction is load-bearing, not cosmetic. `Renderable<T>` is built on\n * `Omit`, and `Omit` does not distribute: `Omit<A | B, K>` collapses to the\n * keys A and B have IN COMMON, so `Renderable<ActivityData>` is a single\n * object type carrying only the fields every activity shares. Narrowing it\n * dies with it — after `if (data.type === 'multiple-choice')` the compiler\n * still refuses `data.options`, because the union it would narrow to no\n * longer exists.\n *\n * The conditional below re-distributes, so `RenderableActivity` is a real\n * union of per-type renderables and `.type` narrows again. Anything that\n * accepts \"some renderable activity, I don't know which\" — a custom renderer,\n * a sequence entry — must use THIS, not `Renderable<ActivityData>`.\n */\nexport type RenderableActivity<TData extends ActivityData = ActivityData> = TData extends unknown\n ? Renderable<TData>\n : never;\n\n/**\n * Sanitiser for author-supplied rich text (`questionHtml`, `passageHtml`,\n * `promptHtml`). The SDK deliberately ships NO sanitiser — that would add a\n * dependency and, worse, a false promise. Rich text is rendered only when you\n * supply this function; without it the component falls back to the plain-text\n * field, which is always escaped. Fail-safe by construction: the SDK never\n * injects HTML it was not explicitly given a sanitiser for.\n */\nexport type HtmlSanitizer = (html: string) => string;\n\n/**\n * The prop contract shared by every activity component (Req 3.1). Defined\n * here (React-specific) rather than in lk-core, which is React-free.\n *\n * Controlled / uncontrolled follows the React convention: pass `value` +\n * `onChange` to own the learner's answer (restore an in-progress attempt,\n * autosave a delta, drive a review); pass `defaultValue` to seed an\n * uncontrolled component; pass neither for the v1 behaviour.\n */\nexport interface ActivityProps<TData extends ActivityData = ActivityData> {\n /** Activity content. Accepts a `redact()` projection in `exam` mode. */\n data: RenderableActivity<TData>;\n /**\n * Called when the component scored the attempt itself. Only ever fires in\n * `practice` mode — in `exam` mode the client does not grade, so there is\n * no `ActivityResult` to give you; use `onSubmit`.\n */\n onComplete?: (result: ActivityResult) => void;\n /**\n * Called on submit with the raw learner response and no grade. Fires in\n * every mode, before `onComplete`, so an exam runner can persist the\n * response and let the server score it.\n */\n onSubmit?: (response: LearnerResponse) => void;\n /** Controlled value: the learner's current response. */\n value?: LearnerResponse;\n /** Initial response for an uncontrolled component (ignored when `value` is set). */\n defaultValue?: LearnerResponse;\n /**\n * Mount the component as already submitted — read at mount only, like any\n * `default*` prop.\n *\n * Restoring an attempt without it reopens a question the learner had already\n * submitted as answerable, so on a summative paper they can change and\n * re-submit it. `AttemptState.submittedSlotIds` is what this consumes.\n */\n defaultSubmitted?: boolean;\n /** Fires on every change to the learner's response. Required for a controlled component. */\n onChange?: (response: LearnerResponse) => void;\n /** Presentation mode. Defaults to `practice`. */\n renderMode?: RenderMode;\n /**\n * Server-computed outcome, used by `review` mode to mark correctness\n * without the client ever scoring. Ignored in other modes.\n */\n outcome?: ItemOutcome;\n /** Renders author-supplied rich text when provided. See {@link HtmlSanitizer}. */\n sanitizeHtml?: HtmlSanitizer;\n onInteraction?: (event: InteractionEvent) => void;\n /** Per-instance token overrides, applied as inline CSS vars on the root. */\n theme?: Partial<ThemeTokens>;\n locale?: string;\n disabled?: boolean;\n}\n\n/**\n * Bridges a server-produced `redact()` projection into the `data` prop.\n *\n * `RedactedActivityData` is deliberately index-signature typed in lk-core — it\n * proves a payload is learner-safe, not what shape it has — so TypeScript\n * cannot know it still carries the public fields a renderer needs. This is the\n * SDK's single, documented crossing of that gap, so an exam runner does not\n * have to write `as unknown as` at every call site:\n *\n * ```tsx\n * <MultipleChoice\n * data={asRenderable<MultipleChoiceData>(redactedFromServer)}\n * renderMode=\"exam\"\n * onSubmit={persist}\n * />\n * ```\n *\n * Safe because `exam` mode reads only public fields; the answer-key fields the\n * type claims are exactly the ones the component is forbidden to touch there.\n * A future release will derive per-type redacted interfaces so this becomes\n * unnecessary.\n */\nexport function asRenderable<TData extends ActivityData>(\n redacted: RedactedActivityData,\n): Renderable<TData> {\n return redacted as unknown as Renderable<TData>;\n}\n\n/**\n * The same bridge as {@link asRenderable}, for a whole sequence: activities\n * and item groups as a server hands them over, ready for `<ActivitySequence>`.\n *\n * Needed for the same reason and no other. `redactItemGroup` returns\n * `ItemGroup<RedactedActivityData>`, and `RedactedActivityData` is an\n * index-signature type whose fields are all `unknown` — so its `question` is\n * not a `string` and it satisfies no per-type renderable, however the prop is\n * widened. Widening alone cannot fix this; a crossing point is required, and\n * having exactly one keeps `as unknown as` out of consumer code.\n *\n * ```tsx\n * const entries = await fetchExam(); // redacted, server-side\n * <ActivitySequence\n * activities={asRenderableSequence(entries)}\n * renderMode=\"exam\" // REQUIRED: see below\n * shuffleSeed={attemptId}\n * onSubmit={persist}\n * />\n * ```\n *\n * Pass `renderMode=\"exam\"` (or `\"review\"`). Redacted data has no answer key,\n * and the default `practice` mode grades locally — the built-in components\n * throw at render rather than fail at submit time, so a mis-wired exam item is\n * loud, not silent.\n */\nexport function asRenderableSequence(\n entries: readonly (RedactedActivityData | RedactedItemGroupData)[],\n): readonly SequenceEntry<RenderableActivity>[] {\n return entries as unknown as readonly SequenceEntry<RenderableActivity>[];\n}\n\n/** Structural shape of a `redactItemGroup()` projection, as it arrives from a server. */\ntype RedactedItemGroupData = ItemGroup<RedactedActivityData> & { redacted: true };\n"]}
1
+ {"version":3,"sources":["../src/components/types.ts"],"names":[],"mappings":";;;;;;;;;;;;AAgKO,SAAS,aACd,QAAA,EACmB;AACnB,EAAA,OAAO,QAAA;AACT;AAgCO,SAAS,qBACd,OAAA,EAC8C;AAC9C,EAAA,OAAO,OAAA;AACT","file":"index.js","sourcesContent":["import type {\n ActivityData,\n ActivityResult,\n InteractionEvent,\n ItemGroup,\n ItemOutcome,\n LearnerResponse,\n RedactedActivityData,\n SequenceEntry,\n ThemeTokens,\n} from '@intellectif/lk-core';\n\n/**\n * How an activity is being presented. This is the single switch that decides\n * whether the component may grade, reveal, or submit — the three things a\n * summative exam must take away from the client.\n *\n * - `practice` (default, and the only behaviour before `renderMode` existed):\n * the component owns the attempt. It\n * scores locally on submit, reveals correctness and feedback, and calls\n * `onComplete` with a full {@link ActivityResult}.\n * - `exam`: the component NEVER scores and NEVER reveals correctness. Submit\n * emits the raw learner response through `onSubmit`; the server grades it.\n * Safe to render redacted data, because nothing here needs the answer key.\n * - `review`: read-only. Renders the learner's submitted answer, and marks\n * correctness only from an `outcome` the caller supplies (which the server\n * computed). Nothing is submittable.\n */\nexport type RenderMode = 'practice' | 'exam' | 'review';\n\n/**\n * Makes the answer-key-bearing parts of an activity optional, so a component\n * can render either full activity data OR a `redact()` projection with the\n * same props. Fields the SDK classifies `answer-key` become optional here;\n * a component in `exam` mode must not read them at all.\n */\nexport type Renderable<TData> = Omit<TData, 'scoringStrategy'> & {\n scoringStrategy?: unknown;\n /** Present on a `redact()` projection. */\n redacted?: true;\n};\n\n/**\n * {@link Renderable} DISTRIBUTED over a union of activity types.\n *\n * This distinction is load-bearing, not cosmetic. `Renderable<T>` is built on\n * `Omit`, and `Omit` does not distribute: `Omit<A | B, K>` collapses to the\n * keys A and B have IN COMMON, so `Renderable<ActivityData>` is a single\n * object type carrying only the fields every activity shares. Narrowing it\n * dies with it — after `if (data.type === 'multiple-choice')` the compiler\n * still refuses `data.options`, because the union it would narrow to no\n * longer exists.\n *\n * The conditional below re-distributes, so `RenderableActivity` is a real\n * union of per-type renderables and `.type` narrows again. Anything that\n * accepts \"some renderable activity, I don't know which\" — a custom renderer,\n * a sequence entry — must use THIS, not `Renderable<ActivityData>`.\n */\nexport type RenderableActivity<TData extends ActivityData = ActivityData> = TData extends unknown\n ? Renderable<TData>\n : never;\n\n/**\n * Sanitiser for author-supplied rich text (`questionHtml`, `promptHtml`, and a\n * stimulus's `bodyHtml`). The SDK deliberately ships NO sanitiser — that would\n * add a dependency and, worse, a false promise. Rich text is rendered only when\n * you supply this function; without it the component falls back to the\n * plain-text field, which is always escaped. Fail-safe by construction: the SDK\n * never injects HTML it was not explicitly given a sanitiser for.\n *\n * `FillInTheBlanks.passageHtml` is the one exception, and is **never**\n * rendered: the passage hosts the answer inputs, so it cannot be split at the\n * `{{blank}}` placeholders without voiding the sanitiser. The plain `passage`\n * is always used, and passing `passageHtml` warns in development.\n */\nexport type HtmlSanitizer = (html: string) => string;\n\n/**\n * The prop contract shared by every activity component (Req 3.1). Defined\n * here (React-specific) rather than in lk-core, which is React-free.\n *\n * Controlled / uncontrolled follows the React convention: pass `value` +\n * `onChange` to own the learner's answer (restore an in-progress attempt,\n * autosave a delta, drive a review); pass `defaultValue` to seed an\n * uncontrolled component; pass neither to keep the pre-2.1.0 behaviour, where\n * the component owns the answer outright.\n */\nexport interface ActivityProps<TData extends ActivityData = ActivityData> {\n /** Activity content. Accepts a `redact()` projection in `exam` mode. */\n data: RenderableActivity<TData>;\n /**\n * Called when the component scored the attempt itself. Only ever fires in\n * `practice` mode — in `exam` mode the client does not grade, so there is\n * no `ActivityResult` to give you; use `onSubmit`.\n */\n onComplete?: (result: ActivityResult) => void;\n /**\n * Called on submit with the raw learner response and no grade. Fires in\n * every mode, before `onComplete`, so an exam runner can persist the\n * response and let the server score it.\n */\n onSubmit?: (response: LearnerResponse) => void;\n /** Controlled value: the learner's current response. */\n value?: LearnerResponse;\n /** Initial response for an uncontrolled component (ignored when `value` is set). */\n defaultValue?: LearnerResponse;\n /**\n * Mount the component as already submitted — read at mount only, like any\n * `default*` prop.\n *\n * Restoring an attempt without it reopens a question the learner had already\n * submitted as answerable, so on a summative paper they can change and\n * re-submit it. `AttemptState.submittedSlotIds` is what this consumes.\n */\n defaultSubmitted?: boolean;\n /** Fires on every change to the learner's response. Required for a controlled component. */\n onChange?: (response: LearnerResponse) => void;\n /** Presentation mode. Defaults to `practice`. */\n renderMode?: RenderMode;\n /**\n * Server-computed outcome, used by `review` mode to mark correctness\n * without the client ever scoring. Ignored in other modes.\n */\n outcome?: ItemOutcome;\n /** Renders author-supplied rich text when provided. See {@link HtmlSanitizer}. */\n sanitizeHtml?: HtmlSanitizer;\n onInteraction?: (event: InteractionEvent) => void;\n /** Per-instance token overrides, applied as inline CSS vars on the root. */\n theme?: Partial<ThemeTokens>;\n locale?: string;\n disabled?: boolean;\n}\n\n/**\n * Bridges a server-produced `redact()` projection into the `data` prop.\n *\n * `RedactedActivityData` is deliberately index-signature typed in lk-core — it\n * proves a payload is learner-safe, not what shape it has — so TypeScript\n * cannot know it still carries the public fields a renderer needs. This is the\n * SDK's single, documented crossing of that gap, so an exam runner does not\n * have to write `as unknown as` at every call site:\n *\n * ```tsx\n * <MultipleChoice\n * data={asRenderable<MultipleChoiceData>(redactedFromServer)}\n * renderMode=\"exam\"\n * onSubmit={persist}\n * />\n * ```\n *\n * Safe because `exam` mode reads only public fields; the answer-key fields the\n * type claims are exactly the ones the component is forbidden to touch there.\n *\n * Per-type redacted interfaces (`RedactedMultipleChoiceData`, …) ship from\n * lk-core since 0.6.0, but they are not yet *assignable* to `data`:\n * {@link Renderable} widens `scoringStrategy` and leaves nested answer-key\n * fields (`options[].isCorrect`, `blanks[].acceptedAnswers`) required, so a\n * real redacted payload still needs this bridge. Closing that gap is tracked\n * in the roadmap.\n */\nexport function asRenderable<TData extends ActivityData>(\n redacted: RedactedActivityData,\n): Renderable<TData> {\n return redacted as unknown as Renderable<TData>;\n}\n\n/**\n * The same bridge as {@link asRenderable}, for a whole sequence: activities\n * and item groups as a server hands them over, ready for `<ActivitySequence>`.\n *\n * Needed for the same reason and no other. `redactItemGroup` returns\n * `ItemGroup<RedactedActivityData>`, and `RedactedActivityData` is an\n * index-signature type whose fields are all `unknown` — so its `question` is\n * not a `string` and it satisfies no per-type renderable, however the prop is\n * widened. Widening alone cannot fix this; a crossing point is required, and\n * having exactly one keeps `as unknown as` out of consumer code.\n *\n * ```tsx\n * const entries = await fetchExam(); // redacted, server-side\n * <ActivitySequence\n * activities={asRenderableSequence(entries)}\n * renderMode=\"exam\" // REQUIRED: see below\n * shuffleSeed={attemptId}\n * onSubmit={persist}\n * />\n * ```\n *\n * Pass `renderMode=\"exam\"` (or `\"review\"`). Redacted data has no answer key,\n * and the default `practice` mode grades locally — so `<MultipleChoice>` and\n * `<FillInTheBlanks>` throw at render rather than fail at submit time.\n *\n * `<WrittenResponse>` is the exception: it never grades on the client and has\n * no such guard, so a redacted essay renders and stays answerable in\n * `practice`. A mis-wired essay item is therefore SILENT — set `renderMode`\n * explicitly rather than relying on the throw.\n */\nexport function asRenderableSequence(\n entries: readonly (RedactedActivityData | RedactedItemGroupData)[],\n): readonly SequenceEntry<RenderableActivity>[] {\n return entries as unknown as readonly SequenceEntry<RenderableActivity>[];\n}\n\n/** Structural shape of a `redactItemGroup()` projection, as it arrives from a server. */\ntype RedactedItemGroupData = ItemGroup<RedactedActivityData> & { redacted: true };\n"]}
@@ -1,24 +1,29 @@
1
+ 'use client';
1
2
  'use strict';
2
3
 
3
- var chunkCPF2JJG6_cjs = require('../chunk-CPF2JJG6.cjs');
4
+ var chunkAMGK7DDM_cjs = require('../chunk-AMGK7DDM.cjs');
4
5
 
5
6
 
6
7
 
7
8
  Object.defineProperty(exports, "ThemeProvider", {
8
9
  enumerable: true,
9
- get: function () { return chunkCPF2JJG6_cjs.ThemeProvider; }
10
+ get: function () { return chunkAMGK7DDM_cjs.ThemeProvider; }
11
+ });
12
+ Object.defineProperty(exports, "createTailwindTheme", {
13
+ enumerable: true,
14
+ get: function () { return chunkAMGK7DDM_cjs.createTailwindTheme; }
10
15
  });
11
16
  Object.defineProperty(exports, "darkTheme", {
12
17
  enumerable: true,
13
- get: function () { return chunkCPF2JJG6_cjs.darkTheme; }
18
+ get: function () { return chunkAMGK7DDM_cjs.darkTheme; }
14
19
  });
15
20
  Object.defineProperty(exports, "defaultTheme", {
16
21
  enumerable: true,
17
- get: function () { return chunkCPF2JJG6_cjs.defaultTheme; }
22
+ get: function () { return chunkAMGK7DDM_cjs.defaultTheme; }
18
23
  });
19
24
  Object.defineProperty(exports, "useTheme", {
20
25
  enumerable: true,
21
- get: function () { return chunkCPF2JJG6_cjs.useTheme; }
26
+ get: function () { return chunkAMGK7DDM_cjs.useTheme; }
22
27
  });
23
28
  //# sourceMappingURL=ThemeProvider.cjs.map
24
29
  //# sourceMappingURL=ThemeProvider.cjs.map
@@ -9,6 +9,26 @@ import { ReactNode } from 'react';
9
9
  */
10
10
  declare const darkTheme: Partial<ThemeTokens>;
11
11
 
12
+ /**
13
+ * Shape consumed by a Tailwind config's `theme.extend`. Every entry is a
14
+ * `var(--lk-token, <fallback>)` reference: the var keeps utilities live
15
+ * (ThemeProvider / dark-mode override at runtime); the fallback makes them
16
+ * work with zero setup (no provider, no `defaults.css` import).
17
+ */
18
+ interface TailwindThemeExtension {
19
+ colors: Record<string, string>;
20
+ spacing: Record<string, string>;
21
+ borderRadius: Record<string, string>;
22
+ fontFamily: Record<string, string>;
23
+ fontSize: Record<string, string>;
24
+ }
25
+ /**
26
+ * Converts SDK theme tokens into a Tailwind `theme.extend` object so Tailwind
27
+ * projects consume the same `--lk-*` tokens as the components — one shared
28
+ * source of truth rather than a parallel, conflicting palette.
29
+ */
30
+ declare function createTailwindTheme(theme: Partial<ThemeTokens>): TailwindThemeExtension;
31
+
12
32
  /**
13
33
  * Canonical default theme token values. `defaults.css` mirrors these exactly.
14
34
  * Palette is a neutral monochrome (ElevenLabs-like) so the SDK is brand-neutral
@@ -36,4 +56,4 @@ declare function ThemeProvider({ theme, children }: ThemeProviderProps): react_j
36
56
  /** Returns the currently active theme tokens (defaults when no provider). */
37
57
  declare function useTheme(): ThemeTokens;
38
58
 
39
- export { ThemeProvider, type ThemeProviderProps, darkTheme, defaultTheme, useTheme };
59
+ export { type TailwindThemeExtension, ThemeProvider, type ThemeProviderProps, createTailwindTheme, darkTheme, defaultTheme, useTheme };
@@ -9,6 +9,26 @@ import { ReactNode } from 'react';
9
9
  */
10
10
  declare const darkTheme: Partial<ThemeTokens>;
11
11
 
12
+ /**
13
+ * Shape consumed by a Tailwind config's `theme.extend`. Every entry is a
14
+ * `var(--lk-token, <fallback>)` reference: the var keeps utilities live
15
+ * (ThemeProvider / dark-mode override at runtime); the fallback makes them
16
+ * work with zero setup (no provider, no `defaults.css` import).
17
+ */
18
+ interface TailwindThemeExtension {
19
+ colors: Record<string, string>;
20
+ spacing: Record<string, string>;
21
+ borderRadius: Record<string, string>;
22
+ fontFamily: Record<string, string>;
23
+ fontSize: Record<string, string>;
24
+ }
25
+ /**
26
+ * Converts SDK theme tokens into a Tailwind `theme.extend` object so Tailwind
27
+ * projects consume the same `--lk-*` tokens as the components — one shared
28
+ * source of truth rather than a parallel, conflicting palette.
29
+ */
30
+ declare function createTailwindTheme(theme: Partial<ThemeTokens>): TailwindThemeExtension;
31
+
12
32
  /**
13
33
  * Canonical default theme token values. `defaults.css` mirrors these exactly.
14
34
  * Palette is a neutral monochrome (ElevenLabs-like) so the SDK is brand-neutral
@@ -36,4 +56,4 @@ declare function ThemeProvider({ theme, children }: ThemeProviderProps): react_j
36
56
  /** Returns the currently active theme tokens (defaults when no provider). */
37
57
  declare function useTheme(): ThemeTokens;
38
58
 
39
- export { ThemeProvider, type ThemeProviderProps, darkTheme, defaultTheme, useTheme };
59
+ export { type TailwindThemeExtension, ThemeProvider, type ThemeProviderProps, createTailwindTheme, darkTheme, defaultTheme, useTheme };
@@ -1,3 +1,4 @@
1
- export { ThemeProvider, darkTheme, defaultTheme, useTheme } from '../chunk-B3FUUKZ2.js';
1
+ 'use client';
2
+ export { ThemeProvider, createTailwindTheme, darkTheme, defaultTheme, useTheme } from '../chunk-DQNVAXG6.js';
2
3
  //# sourceMappingURL=ThemeProvider.js.map
3
4
  //# sourceMappingURL=ThemeProvider.js.map
@@ -409,7 +409,7 @@
409
409
  .lk-wr-prompt {
410
410
  margin: 0;
411
411
  color: var(--lk-color-text);
412
- font-family: var(--lk-font-family);
412
+ font-family: var(--lk-font-family-base);
413
413
  font-size: var(--lk-font-size-base);
414
414
  line-height: 1.6;
415
415
  }
@@ -418,10 +418,10 @@
418
418
  width: 100%;
419
419
  padding: var(--lk-spacing-sm) var(--lk-spacing-md);
420
420
  border: 1px solid var(--lk-color-border);
421
- border-radius: var(--lk-border-radius-md);
421
+ border-radius: var(--lk-radius-base);
422
422
  background: var(--lk-color-surface);
423
423
  color: var(--lk-color-text);
424
- font-family: var(--lk-font-family);
424
+ font-family: var(--lk-font-family-base);
425
425
  font-size: var(--lk-font-size-base);
426
426
  line-height: 1.5;
427
427
  resize: vertical;
@@ -445,10 +445,10 @@
445
445
  align-self: flex-start;
446
446
  padding: var(--lk-spacing-sm) var(--lk-spacing-lg);
447
447
  border: none;
448
- border-radius: var(--lk-border-radius-md);
448
+ border-radius: var(--lk-radius-base);
449
449
  background: var(--lk-color-primary);
450
- color: var(--lk-color-on-primary);
451
- font-family: var(--lk-font-family);
450
+ color: var(--lk-color-surface);
451
+ font-family: var(--lk-font-family-base);
452
452
  font-size: var(--lk-font-size-base);
453
453
  cursor: pointer;
454
454
  transition: var(--lk-transition-fast);
@@ -493,7 +493,7 @@
493
493
  gap: var(--lk-spacing-sm);
494
494
  padding: var(--lk-spacing-md);
495
495
  border: 1px solid var(--lk-color-border);
496
- border-radius: var(--lk-border-radius-md);
496
+ border-radius: var(--lk-radius-base);
497
497
  background: var(--lk-color-surface);
498
498
  }
499
499
 
@@ -5,7 +5,8 @@ import { ActivityData, ActivityResult, LearnerResponse, ItemOutcome, Interaction
5
5
  * whether the component may grade, reveal, or submit — the three things a
6
6
  * summative exam must take away from the client.
7
7
  *
8
- * - `practice` (default, v1 behaviour): the component owns the attempt. It
8
+ * - `practice` (default, and the only behaviour before `renderMode` existed):
9
+ * the component owns the attempt. It
9
10
  * scores locally on submit, reveals correctness and feedback, and calls
10
11
  * `onComplete` with a full {@link ActivityResult}.
11
12
  * - `exam`: the component NEVER scores and NEVER reveals correctness. Submit
@@ -45,12 +46,17 @@ type Renderable<TData> = Omit<TData, 'scoringStrategy'> & {
45
46
  */
46
47
  type RenderableActivity<TData extends ActivityData = ActivityData> = TData extends unknown ? Renderable<TData> : never;
47
48
  /**
48
- * Sanitiser for author-supplied rich text (`questionHtml`, `passageHtml`,
49
- * `promptHtml`). The SDK deliberately ships NO sanitiser — that would add a
50
- * dependency and, worse, a false promise. Rich text is rendered only when you
51
- * supply this function; without it the component falls back to the plain-text
52
- * field, which is always escaped. Fail-safe by construction: the SDK never
53
- * injects HTML it was not explicitly given a sanitiser for.
49
+ * Sanitiser for author-supplied rich text (`questionHtml`, `promptHtml`, and a
50
+ * stimulus's `bodyHtml`). The SDK deliberately ships NO sanitiser — that would
51
+ * add a dependency and, worse, a false promise. Rich text is rendered only when
52
+ * you supply this function; without it the component falls back to the
53
+ * plain-text field, which is always escaped. Fail-safe by construction: the SDK
54
+ * never injects HTML it was not explicitly given a sanitiser for.
55
+ *
56
+ * `FillInTheBlanks.passageHtml` is the one exception, and is **never**
57
+ * rendered: the passage hosts the answer inputs, so it cannot be split at the
58
+ * `{{blank}}` placeholders without voiding the sanitiser. The plain `passage`
59
+ * is always used, and passing `passageHtml` warns in development.
54
60
  */
55
61
  type HtmlSanitizer = (html: string) => string;
56
62
  /**
@@ -60,7 +66,8 @@ type HtmlSanitizer = (html: string) => string;
60
66
  * Controlled / uncontrolled follows the React convention: pass `value` +
61
67
  * `onChange` to own the learner's answer (restore an in-progress attempt,
62
68
  * autosave a delta, drive a review); pass `defaultValue` to seed an
63
- * uncontrolled component; pass neither for the v1 behaviour.
69
+ * uncontrolled component; pass neither to keep the pre-2.1.0 behaviour, where
70
+ * the component owns the answer outright.
64
71
  */
65
72
  interface ActivityProps<TData extends ActivityData = ActivityData> {
66
73
  /** Activity content. Accepts a `redact()` projection in `exam` mode. */
@@ -126,8 +133,13 @@ interface ActivityProps<TData extends ActivityData = ActivityData> {
126
133
  *
127
134
  * Safe because `exam` mode reads only public fields; the answer-key fields the
128
135
  * type claims are exactly the ones the component is forbidden to touch there.
129
- * A future release will derive per-type redacted interfaces so this becomes
130
- * unnecessary.
136
+ *
137
+ * Per-type redacted interfaces (`RedactedMultipleChoiceData`, …) ship from
138
+ * lk-core since 0.6.0, but they are not yet *assignable* to `data`:
139
+ * {@link Renderable} widens `scoringStrategy` and leaves nested answer-key
140
+ * fields (`options[].isCorrect`, `blanks[].acceptedAnswers`) required, so a
141
+ * real redacted payload still needs this bridge. Closing that gap is tracked
142
+ * in the roadmap.
131
143
  */
132
144
  declare function asRenderable<TData extends ActivityData>(redacted: RedactedActivityData): Renderable<TData>;
133
145
  /**
@@ -152,9 +164,13 @@ declare function asRenderable<TData extends ActivityData>(redacted: RedactedActi
152
164
  * ```
153
165
  *
154
166
  * Pass `renderMode="exam"` (or `"review"`). Redacted data has no answer key,
155
- * and the default `practice` mode grades locally — the built-in components
156
- * throw at render rather than fail at submit time, so a mis-wired exam item is
157
- * loud, not silent.
167
+ * and the default `practice` mode grades locally — so `<MultipleChoice>` and
168
+ * `<FillInTheBlanks>` throw at render rather than fail at submit time.
169
+ *
170
+ * `<WrittenResponse>` is the exception: it never grades on the client and has
171
+ * no such guard, so a redacted essay renders and stays answerable in
172
+ * `practice`. A mis-wired essay item is therefore SILENT — set `renderMode`
173
+ * explicitly rather than relying on the throw.
158
174
  */
159
175
  declare function asRenderableSequence(entries: readonly (RedactedActivityData | RedactedItemGroupData)[]): readonly SequenceEntry<RenderableActivity>[];
160
176
  /** Structural shape of a `redactItemGroup()` projection, as it arrives from a server. */
@@ -5,7 +5,8 @@ import { ActivityData, ActivityResult, LearnerResponse, ItemOutcome, Interaction
5
5
  * whether the component may grade, reveal, or submit — the three things a
6
6
  * summative exam must take away from the client.
7
7
  *
8
- * - `practice` (default, v1 behaviour): the component owns the attempt. It
8
+ * - `practice` (default, and the only behaviour before `renderMode` existed):
9
+ * the component owns the attempt. It
9
10
  * scores locally on submit, reveals correctness and feedback, and calls
10
11
  * `onComplete` with a full {@link ActivityResult}.
11
12
  * - `exam`: the component NEVER scores and NEVER reveals correctness. Submit
@@ -45,12 +46,17 @@ type Renderable<TData> = Omit<TData, 'scoringStrategy'> & {
45
46
  */
46
47
  type RenderableActivity<TData extends ActivityData = ActivityData> = TData extends unknown ? Renderable<TData> : never;
47
48
  /**
48
- * Sanitiser for author-supplied rich text (`questionHtml`, `passageHtml`,
49
- * `promptHtml`). The SDK deliberately ships NO sanitiser — that would add a
50
- * dependency and, worse, a false promise. Rich text is rendered only when you
51
- * supply this function; without it the component falls back to the plain-text
52
- * field, which is always escaped. Fail-safe by construction: the SDK never
53
- * injects HTML it was not explicitly given a sanitiser for.
49
+ * Sanitiser for author-supplied rich text (`questionHtml`, `promptHtml`, and a
50
+ * stimulus's `bodyHtml`). The SDK deliberately ships NO sanitiser — that would
51
+ * add a dependency and, worse, a false promise. Rich text is rendered only when
52
+ * you supply this function; without it the component falls back to the
53
+ * plain-text field, which is always escaped. Fail-safe by construction: the SDK
54
+ * never injects HTML it was not explicitly given a sanitiser for.
55
+ *
56
+ * `FillInTheBlanks.passageHtml` is the one exception, and is **never**
57
+ * rendered: the passage hosts the answer inputs, so it cannot be split at the
58
+ * `{{blank}}` placeholders without voiding the sanitiser. The plain `passage`
59
+ * is always used, and passing `passageHtml` warns in development.
54
60
  */
55
61
  type HtmlSanitizer = (html: string) => string;
56
62
  /**
@@ -60,7 +66,8 @@ type HtmlSanitizer = (html: string) => string;
60
66
  * Controlled / uncontrolled follows the React convention: pass `value` +
61
67
  * `onChange` to own the learner's answer (restore an in-progress attempt,
62
68
  * autosave a delta, drive a review); pass `defaultValue` to seed an
63
- * uncontrolled component; pass neither for the v1 behaviour.
69
+ * uncontrolled component; pass neither to keep the pre-2.1.0 behaviour, where
70
+ * the component owns the answer outright.
64
71
  */
65
72
  interface ActivityProps<TData extends ActivityData = ActivityData> {
66
73
  /** Activity content. Accepts a `redact()` projection in `exam` mode. */
@@ -126,8 +133,13 @@ interface ActivityProps<TData extends ActivityData = ActivityData> {
126
133
  *
127
134
  * Safe because `exam` mode reads only public fields; the answer-key fields the
128
135
  * type claims are exactly the ones the component is forbidden to touch there.
129
- * A future release will derive per-type redacted interfaces so this becomes
130
- * unnecessary.
136
+ *
137
+ * Per-type redacted interfaces (`RedactedMultipleChoiceData`, …) ship from
138
+ * lk-core since 0.6.0, but they are not yet *assignable* to `data`:
139
+ * {@link Renderable} widens `scoringStrategy` and leaves nested answer-key
140
+ * fields (`options[].isCorrect`, `blanks[].acceptedAnswers`) required, so a
141
+ * real redacted payload still needs this bridge. Closing that gap is tracked
142
+ * in the roadmap.
131
143
  */
132
144
  declare function asRenderable<TData extends ActivityData>(redacted: RedactedActivityData): Renderable<TData>;
133
145
  /**
@@ -152,9 +164,13 @@ declare function asRenderable<TData extends ActivityData>(redacted: RedactedActi
152
164
  * ```
153
165
  *
154
166
  * Pass `renderMode="exam"` (or `"review"`). Redacted data has no answer key,
155
- * and the default `practice` mode grades locally — the built-in components
156
- * throw at render rather than fail at submit time, so a mis-wired exam item is
157
- * loud, not silent.
167
+ * and the default `practice` mode grades locally — so `<MultipleChoice>` and
168
+ * `<FillInTheBlanks>` throw at render rather than fail at submit time.
169
+ *
170
+ * `<WrittenResponse>` is the exception: it never grades on the client and has
171
+ * no such guard, so a redacted essay renders and stays answerable in
172
+ * `practice`. A mis-wired essay item is therefore SILENT — set `renderMode`
173
+ * explicitly rather than relying on the throw.
158
174
  */
159
175
  declare function asRenderableSequence(entries: readonly (RedactedActivityData | RedactedItemGroupData)[]): readonly SequenceEntry<RenderableActivity>[];
160
176
  /** Structural shape of a `redactItemGroup()` projection, as it arrives from a server. */