@pie-players/pie-assessment-toolkit 0.2.7 → 0.2.10

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 (249) hide show
  1. package/README.md +200 -67
  2. package/dist/attempt/TestSession.d.ts +23 -21
  3. package/dist/attempt/TestSession.d.ts.map +1 -1
  4. package/dist/attempt/TestSession.js +17 -15
  5. package/dist/attempt/TestSession.js.map +1 -1
  6. package/dist/attempt/adapters/activity-to-test-attempt-session.d.ts +50 -0
  7. package/dist/attempt/adapters/activity-to-test-attempt-session.d.ts.map +1 -0
  8. package/dist/attempt/adapters/activity-to-test-attempt-session.js +135 -0
  9. package/dist/attempt/adapters/activity-to-test-attempt-session.js.map +1 -0
  10. package/dist/components/ItemToolBar.custom-element.js +953 -0
  11. package/dist/components/PieAssessmentToolkit.custom-element.js +757 -0
  12. package/dist/components/SectionToolBar.custom-element.js +162 -0
  13. package/dist/components/item-toolbar-element.d.ts +3 -0
  14. package/dist/components/item-toolbar-element.d.ts.map +1 -0
  15. package/dist/components/item-toolbar-element.js +2 -0
  16. package/dist/components/item-toolbar-element.js.map +1 -0
  17. package/dist/components/pie-assessment-toolkit-element.d.ts +3 -0
  18. package/dist/components/pie-assessment-toolkit-element.d.ts.map +1 -0
  19. package/dist/components/pie-assessment-toolkit-element.js +2 -0
  20. package/dist/components/pie-assessment-toolkit-element.js.map +1 -0
  21. package/dist/components/section-toolbar-element.d.ts +3 -0
  22. package/dist/components/section-toolbar-element.d.ts.map +1 -0
  23. package/dist/components/section-toolbar-element.js +2 -0
  24. package/dist/components/section-toolbar-element.js.map +1 -0
  25. package/dist/context/assessment-toolkit-context.d.ts +52 -0
  26. package/dist/context/assessment-toolkit-context.d.ts.map +1 -0
  27. package/dist/context/assessment-toolkit-context.js +6 -0
  28. package/dist/context/assessment-toolkit-context.js.map +1 -0
  29. package/dist/context/runtime-context-consumer.d.ts +14 -0
  30. package/dist/context/runtime-context-consumer.d.ts.map +1 -0
  31. package/dist/context/runtime-context-consumer.js +52 -0
  32. package/dist/context/runtime-context-consumer.js.map +1 -0
  33. package/dist/index.d.ts +19 -6
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +14 -11
  36. package/dist/index.js.map +1 -1
  37. package/dist/runtime/RuntimeRegistry.d.ts +13 -0
  38. package/dist/runtime/RuntimeRegistry.d.ts.map +1 -0
  39. package/dist/runtime/RuntimeRegistry.js +50 -0
  40. package/dist/runtime/RuntimeRegistry.js.map +1 -0
  41. package/dist/runtime/SectionRuntimeEngine.d.ts +45 -0
  42. package/dist/runtime/SectionRuntimeEngine.d.ts.map +1 -0
  43. package/dist/runtime/SectionRuntimeEngine.js +81 -0
  44. package/dist/runtime/SectionRuntimeEngine.js.map +1 -0
  45. package/dist/runtime/registration-events.d.ts +19 -0
  46. package/dist/runtime/registration-events.d.ts.map +1 -0
  47. package/dist/runtime/registration-events.js +4 -0
  48. package/dist/runtime/registration-events.js.map +1 -0
  49. package/dist/runtime/runtime-event-guards.d.ts +3 -0
  50. package/dist/runtime/runtime-event-guards.d.ts.map +1 -0
  51. package/dist/runtime/runtime-event-guards.js +9 -0
  52. package/dist/runtime/runtime-event-guards.js.map +1 -0
  53. package/dist/runtime/tool-host-contract.d.ts +30 -0
  54. package/dist/runtime/tool-host-contract.d.ts.map +1 -0
  55. package/dist/runtime/tool-host-contract.js +48 -0
  56. package/dist/runtime/tool-host-contract.js.map +1 -0
  57. package/dist/services/HighlightCoordinator.d.ts +9 -0
  58. package/dist/services/HighlightCoordinator.d.ts.map +1 -1
  59. package/dist/services/HighlightCoordinator.js +196 -55
  60. package/dist/services/HighlightCoordinator.js.map +1 -1
  61. package/dist/services/TTSService.d.ts +21 -1
  62. package/dist/services/TTSService.d.ts.map +1 -1
  63. package/dist/services/TTSService.js +356 -117
  64. package/dist/services/TTSService.js.map +1 -1
  65. package/dist/services/ThemeProvider.d.ts +1 -0
  66. package/dist/services/ThemeProvider.d.ts.map +1 -1
  67. package/dist/services/ThemeProvider.js +82 -46
  68. package/dist/services/ThemeProvider.js.map +1 -1
  69. package/dist/services/ToolConfigResolver.d.ts +1 -1
  70. package/dist/services/ToolConfigResolver.js +1 -1
  71. package/dist/services/ToolCoordinator.d.ts +1 -1
  72. package/dist/services/ToolCoordinator.d.ts.map +1 -1
  73. package/dist/services/ToolRegistry.d.ts +76 -67
  74. package/dist/services/ToolRegistry.d.ts.map +1 -1
  75. package/dist/services/ToolRegistry.js +73 -22
  76. package/dist/services/ToolRegistry.js.map +1 -1
  77. package/dist/services/ToolkitCoordinator.d.ts +126 -8
  78. package/dist/services/ToolkitCoordinator.d.ts.map +1 -1
  79. package/dist/services/ToolkitCoordinator.js +607 -72
  80. package/dist/services/ToolkitCoordinator.js.map +1 -1
  81. package/dist/services/createDefaultToolRegistry.d.ts +11 -12
  82. package/dist/services/createDefaultToolRegistry.d.ts.map +1 -1
  83. package/dist/services/createDefaultToolRegistry.js +9 -56
  84. package/dist/services/createDefaultToolRegistry.js.map +1 -1
  85. package/dist/services/defaultPersonalNeedsProfile.d.ts +4 -0
  86. package/dist/services/defaultPersonalNeedsProfile.d.ts.map +1 -0
  87. package/dist/services/defaultPersonalNeedsProfile.js +25 -0
  88. package/dist/services/defaultPersonalNeedsProfile.js.map +1 -0
  89. package/dist/services/interfaces.d.ts +62 -2
  90. package/dist/services/interfaces.d.ts.map +1 -1
  91. package/dist/services/interfaces.js.map +1 -1
  92. package/dist/services/pnp-standard-features.d.ts +3 -4
  93. package/dist/services/pnp-standard-features.d.ts.map +1 -1
  94. package/dist/services/pnp-standard-features.js +0 -3
  95. package/dist/services/pnp-standard-features.js.map +1 -1
  96. package/dist/services/section-controller-types.d.ts +37 -0
  97. package/dist/services/section-controller-types.d.ts.map +1 -0
  98. package/dist/services/section-controller-types.js +2 -0
  99. package/dist/services/section-controller-types.js.map +1 -0
  100. package/dist/services/tool-config-defaults.d.ts +14 -0
  101. package/dist/services/tool-config-defaults.d.ts.map +1 -0
  102. package/dist/services/tool-config-defaults.js +23 -0
  103. package/dist/services/tool-config-defaults.js.map +1 -0
  104. package/dist/services/tool-context.d.ts +4 -4
  105. package/dist/services/tool-context.d.ts.map +1 -1
  106. package/dist/services/tool-context.js +156 -20
  107. package/dist/services/tool-context.js.map +1 -1
  108. package/dist/services/tool-instance-id.d.ts +15 -0
  109. package/dist/services/tool-instance-id.d.ts.map +1 -0
  110. package/dist/services/tool-instance-id.js +55 -0
  111. package/dist/services/tool-instance-id.js.map +1 -0
  112. package/dist/services/tool-providers/IToolProvider.d.ts +2 -3
  113. package/dist/services/tool-providers/IToolProvider.d.ts.map +1 -1
  114. package/dist/services/tool-providers/IToolProvider.js +1 -2
  115. package/dist/services/tool-providers/IToolProvider.js.map +1 -1
  116. package/dist/services/tool-providers/MathJsToolProvider.d.ts +25 -0
  117. package/dist/services/tool-providers/MathJsToolProvider.d.ts.map +1 -0
  118. package/dist/services/tool-providers/MathJsToolProvider.js +53 -0
  119. package/dist/services/tool-providers/MathJsToolProvider.js.map +1 -0
  120. package/dist/services/tool-providers/index.d.ts +2 -0
  121. package/dist/services/tool-providers/index.d.ts.map +1 -1
  122. package/dist/services/tool-providers/index.js +1 -0
  123. package/dist/services/tool-providers/index.js.map +1 -1
  124. package/dist/services/toolbar-items.d.ts +26 -0
  125. package/dist/services/toolbar-items.d.ts.map +1 -0
  126. package/dist/services/toolbar-items.js +10 -0
  127. package/dist/services/toolbar-items.js.map +1 -0
  128. package/dist/services/tools-config-normalizer.d.ts +26 -0
  129. package/dist/services/tools-config-normalizer.d.ts.map +1 -0
  130. package/dist/services/tools-config-normalizer.js +62 -0
  131. package/dist/services/tools-config-normalizer.js.map +1 -0
  132. package/dist/services/tts/browser-provider.d.ts.map +1 -1
  133. package/dist/services/tts/browser-provider.js +201 -34
  134. package/dist/services/tts/browser-provider.js.map +1 -1
  135. package/dist/services/tts/text-processing.d.ts +17 -0
  136. package/dist/services/tts/text-processing.d.ts.map +1 -0
  137. package/dist/services/tts/text-processing.js +144 -0
  138. package/dist/services/tts/text-processing.js.map +1 -0
  139. package/dist/tools/calculators/ti-provider.d.ts.map +1 -1
  140. package/dist/tools/calculators/ti-provider.js +127 -4
  141. package/dist/tools/calculators/ti-provider.js.map +1 -1
  142. package/dist/tools/client.d.ts +2 -1
  143. package/dist/tools/client.d.ts.map +1 -1
  144. package/dist/tools/client.js +2 -1
  145. package/dist/tools/client.js.map +1 -1
  146. package/dist/tools/default-tool-module-loaders.d.ts +9 -0
  147. package/dist/tools/default-tool-module-loaders.d.ts.map +1 -0
  148. package/dist/tools/default-tool-module-loaders.js +11 -0
  149. package/dist/tools/default-tool-module-loaders.js.map +1 -0
  150. package/dist/tools/index.d.ts +2 -1
  151. package/dist/tools/index.d.ts.map +1 -1
  152. package/dist/tools/index.js +2 -1
  153. package/dist/tools/index.js.map +1 -1
  154. package/dist/tools/library-loader.d.ts +1 -1
  155. package/dist/tools/library-loader.d.ts.map +1 -1
  156. package/dist/tools/library-loader.js +7 -2
  157. package/dist/tools/library-loader.js.map +1 -1
  158. package/dist/tools/registrations/accessibility-tools.d.ts +8 -11
  159. package/dist/tools/registrations/accessibility-tools.d.ts.map +1 -1
  160. package/dist/tools/registrations/accessibility-tools.js +108 -120
  161. package/dist/tools/registrations/accessibility-tools.js.map +1 -1
  162. package/dist/tools/registrations/calculator.d.ts +2 -2
  163. package/dist/tools/registrations/calculator.d.ts.map +1 -1
  164. package/dist/tools/registrations/calculator.js +42 -55
  165. package/dist/tools/registrations/calculator.js.map +1 -1
  166. package/dist/tools/registrations/interaction-tools.d.ts.map +1 -1
  167. package/dist/tools/registrations/interaction-tools.js +77 -52
  168. package/dist/tools/registrations/interaction-tools.js.map +1 -1
  169. package/dist/tools/registrations/measurement-tools.d.ts.map +1 -1
  170. package/dist/tools/registrations/measurement-tools.js +63 -38
  171. package/dist/tools/registrations/measurement-tools.js.map +1 -1
  172. package/dist/tools/registrations/subject-specific-tools.d.ts.map +1 -1
  173. package/dist/tools/registrations/subject-specific-tools.js +63 -38
  174. package/dist/tools/registrations/subject-specific-tools.js.map +1 -1
  175. package/dist/tools/registrations/tts.d.ts +1 -1
  176. package/dist/tools/registrations/tts.d.ts.map +1 -1
  177. package/dist/tools/registrations/tts.js +171 -41
  178. package/dist/tools/registrations/tts.js.map +1 -1
  179. package/dist/tools/response-discovery.d.ts +12 -14
  180. package/dist/tools/response-discovery.d.ts.map +1 -1
  181. package/dist/tools/response-discovery.js +23 -80
  182. package/dist/tools/response-discovery.js.map +1 -1
  183. package/dist/tools/tool-tag-map.d.ts +3 -3
  184. package/dist/tools/tool-tag-map.d.ts.map +1 -1
  185. package/dist/tools/tool-tag-map.js +4 -4
  186. package/dist/tools/tool-tag-map.js.map +1 -1
  187. package/dist/tools/types.d.ts +3 -1
  188. package/dist/tools/types.d.ts.map +1 -1
  189. package/package.json +28 -27
  190. package/src/README.md +16 -32
  191. package/src/components/ItemToolBar.svelte +701 -0
  192. package/src/components/PieAssessmentToolkit.svelte +610 -0
  193. package/src/components/SectionToolBar.svelte +58 -0
  194. package/src/components/ToolButton.svelte +11 -11
  195. package/src/components/ToolButtonGroup.svelte +27 -11
  196. package/src/tools/README.md +6 -5
  197. package/src/tools/calculators/README.md +4 -4
  198. package/dist/player/AssessmentPlayer.d.ts +0 -397
  199. package/dist/player/AssessmentPlayer.d.ts.map +0 -1
  200. package/dist/player/AssessmentPlayer.js +0 -974
  201. package/dist/player/AssessmentPlayer.js.map +0 -1
  202. package/dist/player/index.d.ts +0 -17
  203. package/dist/player/index.d.ts.map +0 -1
  204. package/dist/player/index.js +0 -15
  205. package/dist/player/index.js.map +0 -1
  206. package/dist/player/navigation-types.d.ts +0 -63
  207. package/dist/player/navigation-types.d.ts.map +0 -1
  208. package/dist/player/navigation-types.js +0 -7
  209. package/dist/player/navigation-types.js.map +0 -1
  210. package/dist/player/qti-navigation.d.ts +0 -29
  211. package/dist/player/qti-navigation.d.ts.map +0 -1
  212. package/dist/player/qti-navigation.js +0 -160
  213. package/dist/player/qti-navigation.js.map +0 -1
  214. package/dist/reference-layout/index.d.ts +0 -19
  215. package/dist/reference-layout/index.d.ts.map +0 -1
  216. package/dist/reference-layout/index.js +0 -20
  217. package/dist/reference-layout/index.js.map +0 -1
  218. package/dist/services/AnnotationToolbarConfig.d.ts +0 -134
  219. package/dist/services/AnnotationToolbarConfig.d.ts.map +0 -1
  220. package/dist/services/AnnotationToolbarConfig.js +0 -100
  221. package/dist/services/AnnotationToolbarConfig.js.map +0 -1
  222. package/dist/services/AssessmentAuthoringService.d.ts +0 -60
  223. package/dist/services/AssessmentAuthoringService.d.ts.map +0 -1
  224. package/dist/services/AssessmentAuthoringService.js +0 -183
  225. package/dist/services/AssessmentAuthoringService.js.map +0 -1
  226. package/dist/services/PNPMapper.d.ts +0 -81
  227. package/dist/services/PNPMapper.d.ts.map +0 -1
  228. package/dist/services/PNPMapper.js +0 -108
  229. package/dist/services/PNPMapper.js.map +0 -1
  230. package/dist/services/tts/provider-interface.d.ts +0 -131
  231. package/dist/services/tts/provider-interface.d.ts.map +0 -1
  232. package/dist/services/tts/provider-interface.js +0 -10
  233. package/dist/services/tts/provider-interface.js.map +0 -1
  234. package/src/components/PNPProfileTester.example.svelte +0 -188
  235. package/src/components/PNPProfileTester.svelte +0 -397
  236. package/src/components/PNPProvenanceViewer.svelte +0 -260
  237. package/src/components/QuestionToolBar.svelte +0 -483
  238. package/src/player/AssessmentLayout.svelte +0 -68
  239. package/src/player/README.md +0 -154
  240. package/src/reference-layout/README.md +0 -135
  241. package/src/reference-layout/ReferenceLayout.svelte +0 -201
  242. package/src/reference-layout/components/AssessmentContent.svelte +0 -259
  243. package/src/reference-layout/components/AssessmentFooter.svelte +0 -89
  244. package/src/reference-layout/components/AssessmentHeader.svelte +0 -250
  245. package/src/reference-layout/components/AssessmentNavigation.svelte +0 -134
  246. package/src/reference-layout/components/AssessmentToolsBar.svelte +0 -176
  247. package/src/reference-layout/components/ItemPanel.svelte +0 -200
  248. package/src/reference-layout/components/NotesPanel.svelte +0 -179
  249. package/src/reference-layout/components/PassagePanel.svelte +0 -76
@@ -0,0 +1,757 @@
1
+ // @ts-nocheck
2
+ import 'svelte/internal/disclose-version';
3
+ import * as $ from 'svelte/internal/client';
4
+ import { ContextProvider, ContextRoot, requestContext } from "@pie-players/pie-context";
5
+
6
+ import {
7
+ assessmentToolkitHostRuntimeContext,
8
+ assessmentToolkitRuntimeContext
9
+ } from "../context/assessment-toolkit-context.js";
10
+
11
+ import { connectAssessmentToolkitHostRuntimeContext } from "../context/runtime-context-consumer.js";
12
+ import { ToolkitCoordinator } from "../services/ToolkitCoordinator.js";
13
+
14
+ import {
15
+ PIE_ITEM_SESSION_CHANGED_EVENT,
16
+ PIE_REGISTER_EVENT,
17
+ PIE_UNREGISTER_EVENT
18
+ } from "../runtime/registration-events.js";
19
+
20
+ import { dispatchCrossBoundaryEvent } from "../runtime/tool-host-contract.js";
21
+ import { SectionRuntimeEngine } from "../runtime/SectionRuntimeEngine.js";
22
+ import { createRuntimeId, shouldHandleBySourceRuntime } from "../runtime/runtime-event-guards.js";
23
+
24
+ var root = $.from_html(`<div class="pie-assessment-toolkit-anchor svelte-vpe4u2" aria-hidden="true"></div> <!>`, 1);
25
+
26
+ const $$css = {
27
+ hash: 'svelte-vpe4u2',
28
+ code: '.pie-assessment-toolkit-anchor.svelte-vpe4u2 {display:none;}'
29
+ };
30
+
31
+ export default function PieAssessmentToolkit($$anchor, $$props) {
32
+ $.push($$props, true);
33
+ $.append_styles($$anchor, $$css);
34
+
35
+ const runtimeId = createRuntimeId("toolkit");
36
+ const sectionEngine = new SectionRuntimeEngine();
37
+ const DEFAULT_ENV = { mode: "gather", role: "student" };
38
+
39
+ const DEFAULT_ITEM_PLAYER_BY_TYPE = {
40
+ iife: "pie-item-player",
41
+ esm: "pie-item-player",
42
+ preloaded: "pie-item-player",
43
+ custom: ""
44
+ };
45
+
46
+ let assessmentId = $.prop($$props, 'assessmentId', 7, ""),
47
+ section = $.prop($$props, 'section', 7, null),
48
+ sectionId = $.prop($$props, 'sectionId', 7, ""),
49
+ attemptId = $.prop($$props, 'attemptId', 7, ""),
50
+ view = $.prop($$props, 'view', 7, "candidate"),
51
+ env = $.prop($$props, 'env', 23, () => ({})),
52
+ lazyInit = $.prop($$props, 'lazyInit', 7, true),
53
+ tools = $.prop($$props, 'tools', 23, () => ({})),
54
+ accessibility = $.prop($$props, 'accessibility', 23, () => ({})),
55
+ player = $.prop($$props, 'player', 7, null),
56
+ playerType = $.prop($$props, 'playerType', 7, ""),
57
+ coordinator = $.prop($$props, 'coordinator', 7, null),
58
+ createSectionController = $.prop($$props, 'createSectionController', 7, null),
59
+ isolation = $.prop($$props, 'isolation', 7, "inherit");
60
+
61
+ let anchor = $.state(null);
62
+ let ownedCoordinator = $.state(null);
63
+ let inheritedRuntime = $.state(null);
64
+ let lastOwnership = $.state(null);
65
+ let provider = null;
66
+ let contextRoot = null;
67
+ let hostRuntimeProvider = null;
68
+ let hostRuntimeRoot = null;
69
+ let compositionVersion = $.state(0);
70
+ let compositionModel = $.state(null);
71
+ let runtimeError = $.state(null);
72
+ let lastCompositionRevisionKey = $.state("");
73
+ let pendingCompositionModel = null;
74
+ let pendingCompositionEmit = false;
75
+ let compositionEmitRaf = null;
76
+
77
+ function getHostElement() {
78
+ if (!$.get(anchor)) return null;
79
+
80
+ const rootNode = $.get(anchor).getRootNode();
81
+
82
+ if (rootNode && "host" in rootNode) {
83
+ return rootNode.host;
84
+ }
85
+
86
+ return $.get(anchor).parentElement;
87
+ }
88
+
89
+ const host = $.derived(() => getHostElement());
90
+
91
+ function emit(name, detail) {
92
+ if (!$.get(host)) return;
93
+
94
+ dispatchCrossBoundaryEvent($.get(host), name, detail);
95
+ }
96
+
97
+ function hashString(input) {
98
+ let hash = 5381;
99
+
100
+ for (let index = 0; index < input.length; index += 1) {
101
+ hash = (hash << 5) + hash ^ input.charCodeAt(index);
102
+ }
103
+
104
+ return (hash >>> 0).toString(36);
105
+ }
106
+
107
+ function getCompositionRevisionKey(model) {
108
+ const typed = model || {};
109
+ const sectionId = typed.section?.identifier || typed.sectionId || "";
110
+ const currentItemIndex = typeof typed.currentItemIndex === "number" ? typed.currentItemIndex : -1;
111
+ const renderables = Array.isArray(typed.renderables) ? typed.renderables : [];
112
+
113
+ const renderableSignature = renderables.map((entry, index) => {
114
+ const row = entry || {};
115
+ const entity = row.entity || {};
116
+ const entityId = typeof entity.id === "string" && entity.id || `renderable-${index}`;
117
+ const entityVersion = typeof entity.version === "string" && entity.version || (typeof entity.version === "number" ? String(entity.version) : "") || (typeof entity.config?.version === "string" ? entity.config.version : "");
118
+
119
+ return `${entityId}:${entityVersion}`;
120
+ }).join("|");
121
+
122
+ const sessionsByItem = typed.itemSessionsByItemId || {};
123
+
124
+ const itemSessionSignature = Object.keys(sessionsByItem).sort((left, right) => left.localeCompare(right)).map((itemId) => {
125
+ const session = sessionsByItem[itemId];
126
+ const sessionId = typeof session?.id === "string" && session.id || "";
127
+ const dataPayload = Array.isArray(session?.data) ? session.data : [];
128
+ let payloadSignature = "";
129
+
130
+ try {
131
+ payloadSignature = hashString(JSON.stringify(dataPayload));
132
+ } catch {
133
+ payloadSignature = String(dataPayload.length);
134
+ }
135
+
136
+ return `${itemId}:${sessionId}:${payloadSignature}`;
137
+ }).join("|");
138
+
139
+ return `${sectionId}|${currentItemIndex}|${renderableSignature}|${itemSessionSignature}`;
140
+ }
141
+
142
+ function isKnownPlayerType(value) {
143
+ return value === "iife" || value === "esm" || value === "preloaded" || value === "custom";
144
+ }
145
+
146
+ function normalizeItemPlayerConfig(hostPlayer, hostPlayerType) {
147
+ const typeFromConfig = hostPlayer?.type;
148
+
149
+ const rawType = isKnownPlayerType(typeFromConfig)
150
+ ? typeFromConfig
151
+ : isKnownPlayerType(hostPlayerType)
152
+ ? hostPlayerType
153
+ : hostPlayer?.tagName ? "custom" : "iife";
154
+
155
+ const requestedTagName = hostPlayer?.tagName?.trim();
156
+
157
+ if (rawType === "custom" && !requestedTagName) {
158
+ return {
159
+ type: "iife",
160
+ tagName: DEFAULT_ITEM_PLAYER_BY_TYPE.iife,
161
+ version: undefined,
162
+ source: undefined,
163
+ isDefault: true
164
+ };
165
+ }
166
+
167
+ return {
168
+ type: rawType,
169
+ tagName: requestedTagName || DEFAULT_ITEM_PLAYER_BY_TYPE[rawType],
170
+ version: hostPlayer?.version,
171
+ source: hostPlayer?.source,
172
+ isDefault: !hostPlayer && !hostPlayerType
173
+ };
174
+ }
175
+
176
+ function normalizeEnv(input) {
177
+ const envValue = input || {} || {};
178
+ const mode = typeof envValue.mode === "string" && envValue.mode.trim() ? envValue.mode.trim() : DEFAULT_ENV.mode;
179
+ const role = typeof envValue.role === "string" && envValue.role.trim() ? envValue.role.trim() : DEFAULT_ENV.role;
180
+
181
+ return { mode, role };
182
+ }
183
+
184
+ function resolveSectionViewFromEnv(input) {
185
+ const resolvedEnv = normalizeEnv(input);
186
+
187
+ if (resolvedEnv.mode === "author") return "author";
188
+ if (resolvedEnv.role === "instructor") return "scorer";
189
+
190
+ return "candidate";
191
+ }
192
+
193
+ async function createDefaultSectionController() {
194
+ if (createSectionController()) {
195
+ return createSectionController()();
196
+ }
197
+
198
+ throw new Error("pie-assessment-toolkit requires createSectionController when no coordinator hook provides one");
199
+ }
200
+
201
+ function buildOwnedCoordinator() {
202
+ const fallbackAssessmentId = assessmentId() || section()?.identifier || `assessment-${Math.random().toString(16).slice(2)}`;
203
+
204
+ return new ToolkitCoordinator({
205
+ assessmentId: fallbackAssessmentId,
206
+ lazyInit: lazyInit(),
207
+ tools: tools(),
208
+ accessibility: accessibility()
209
+ });
210
+ }
211
+
212
+ const effectiveCoordinator = $.derived(() => {
213
+ if (isolation() !== "force" && $.get(inheritedRuntime)?.coordinator) {
214
+ return $.get(inheritedRuntime).coordinator;
215
+ }
216
+
217
+ return coordinator() || $.get(ownedCoordinator);
218
+ });
219
+
220
+ $.user_effect(() => {
221
+ if (coordinator()) {
222
+ if ($.get(ownedCoordinator)) {
223
+ $.set(ownedCoordinator, null);
224
+ }
225
+
226
+ return;
227
+ }
228
+
229
+ if (isolation() !== "force" && $.get(inheritedRuntime)?.coordinator) {
230
+ if ($.get(ownedCoordinator)) {
231
+ $.set(ownedCoordinator, null);
232
+ }
233
+
234
+ return;
235
+ }
236
+
237
+ if (!$.get(ownedCoordinator)) {
238
+ $.set(ownedCoordinator, buildOwnedCoordinator(), true);
239
+ }
240
+ });
241
+
242
+ const effectiveAssessmentId = $.derived(() => assessmentId() || $.get(effectiveCoordinator)?.assessmentId || "");
243
+ const effectiveSectionId = $.derived(() => sectionId() || section()?.identifier || `section-${$.get(effectiveAssessmentId) || "default"}`);
244
+ const effectiveEnv = $.derived(() => normalizeEnv(env()));
245
+ const effectiveSectionView = $.derived(() => resolveSectionViewFromEnv($.get(effectiveEnv)));
246
+ const effectiveItemPlayer = $.derived(() => normalizeItemPlayerConfig(player(), playerType()));
247
+
248
+ const runtimeContextValue = $.derived(() => {
249
+ if (!$.get(effectiveCoordinator)) return null;
250
+
251
+ const services = $.get(effectiveCoordinator).getServiceBundle();
252
+
253
+ return {
254
+ toolkitCoordinator: $.get(effectiveCoordinator),
255
+ toolCoordinator: $.get(effectiveCoordinator).toolCoordinator,
256
+ ttsService: services.ttsService,
257
+ highlightCoordinator: services.highlightCoordinator,
258
+ catalogResolver: services.catalogResolver,
259
+ elementToolStateStore: services.elementToolStateStore,
260
+ assessmentId: $.get(effectiveAssessmentId),
261
+ sectionId: $.get(effectiveSectionId),
262
+ itemPlayer: $.get(effectiveItemPlayer),
263
+ reportSessionChanged: (itemId, detail) => {
264
+ const result = sectionEngine.handleItemSessionChanged(itemId, detail);
265
+
266
+ emitNormalizedSessionChanged({ itemId, result, fallbackSession: detail });
267
+ }
268
+ };
269
+ });
270
+
271
+ const hostRuntimeContextValue = $.derived(() => {
272
+ if (!$.get(effectiveCoordinator)) return null;
273
+
274
+ return { runtimeId, coordinator: $.get(effectiveCoordinator) };
275
+ });
276
+
277
+ function flushCompositionChanged(nextModel) {
278
+ const nextRevisionKey = getCompositionRevisionKey(nextModel);
279
+
280
+ if (nextRevisionKey === $.get(lastCompositionRevisionKey)) {
281
+ return;
282
+ }
283
+
284
+ $.set(lastCompositionRevisionKey, nextRevisionKey, true);
285
+ $.set(compositionVersion, $.get(compositionVersion) + 1);
286
+ $.set(compositionModel, nextModel, true);
287
+
288
+ emit("composition-changed", {
289
+ composition: $.get(compositionModel),
290
+ version: $.get(compositionVersion)
291
+ });
292
+ }
293
+
294
+ function emitCompositionChanged(nextModel) {
295
+ pendingCompositionModel = nextModel ?? sectionEngine.getCompositionModel();
296
+
297
+ if (pendingCompositionEmit) return;
298
+
299
+ pendingCompositionEmit = true;
300
+
301
+ const flush = () => {
302
+ pendingCompositionEmit = false;
303
+ compositionEmitRaf = null;
304
+ flushCompositionChanged(pendingCompositionModel);
305
+ };
306
+
307
+ if (typeof window !== "undefined" && typeof window.requestAnimationFrame === "function") {
308
+ compositionEmitRaf = window.requestAnimationFrame(flush);
309
+
310
+ return;
311
+ }
312
+
313
+ queueMicrotask(flush);
314
+ }
315
+
316
+ function emitNormalizedSessionChanged(args) {
317
+ const normalized = args.result?.eventDetail || args.fallbackSession;
318
+
319
+ emit("session-changed", {
320
+ ...normalized,
321
+ itemId: args.itemId,
322
+ canonicalItemId: args.canonicalItemId || args.itemId,
323
+ sourceRuntimeId: runtimeId
324
+ });
325
+ }
326
+
327
+ function isLocalToCurrentRuntime(eventTarget) {
328
+ if (!(eventTarget instanceof HTMLElement)) return false;
329
+
330
+ const sourceRuntime = requestContext(eventTarget, assessmentToolkitHostRuntimeContext);
331
+
332
+ return sourceRuntime?.runtimeId === runtimeId;
333
+ }
334
+
335
+ $.user_effect(() => {
336
+ if (!$.get(host)) return;
337
+
338
+ if (isolation() === "force") {
339
+ $.set(inheritedRuntime, null);
340
+
341
+ return;
342
+ }
343
+
344
+ return connectAssessmentToolkitHostRuntimeContext($.get(host), (value) => {
345
+ if (value.runtimeId === runtimeId) {
346
+ return;
347
+ }
348
+
349
+ $.set(inheritedRuntime, value, true);
350
+ });
351
+ });
352
+
353
+ $.user_effect(() => {
354
+ const parentRuntimeId = isolation() !== "force" && $.get(inheritedRuntime) ? $.get(inheritedRuntime).runtimeId : null;
355
+ const ownership = parentRuntimeId ? "inherited" : "owned";
356
+
357
+ if (ownership !== $.get(lastOwnership)) {
358
+ $.set(lastOwnership, ownership, true);
359
+ emit(ownership === "inherited" ? "runtime-inherited" : "runtime-owned", { runtimeId, parentRuntimeId });
360
+ }
361
+ });
362
+
363
+ $.user_effect(() => {
364
+ if (!$.get(host) || !$.get(hostRuntimeContextValue)) return;
365
+
366
+ hostRuntimeProvider = new ContextProvider($.get(host), {
367
+ context: assessmentToolkitHostRuntimeContext,
368
+ initialValue: $.get(hostRuntimeContextValue)
369
+ });
370
+
371
+ hostRuntimeProvider.connect();
372
+ hostRuntimeRoot = new ContextRoot($.get(host));
373
+ hostRuntimeRoot.attach();
374
+
375
+ return () => {
376
+ hostRuntimeRoot?.detach();
377
+ hostRuntimeRoot = null;
378
+ hostRuntimeProvider?.disconnect();
379
+ hostRuntimeProvider = null;
380
+ };
381
+ });
382
+
383
+ $.user_effect(() => {
384
+ if (!$.get(hostRuntimeContextValue)) return;
385
+
386
+ hostRuntimeProvider?.setValue($.get(hostRuntimeContextValue));
387
+ });
388
+
389
+ $.user_effect(() => {
390
+ if (!$.get(host)) return;
391
+
392
+ $.get(host).setAttribute("data-item-player-type", $.get(effectiveItemPlayer).type);
393
+ $.get(host).setAttribute("data-item-player-tag", $.get(effectiveItemPlayer).tagName);
394
+ $.get(host).setAttribute("data-env-mode", String($.get(effectiveEnv)?.mode || ""));
395
+ $.get(host).setAttribute("data-env-role", String($.get(effectiveEnv)?.role || ""));
396
+ });
397
+
398
+ $.user_effect(() => {
399
+ if (!$.get(host) || !$.get(runtimeContextValue)) return;
400
+
401
+ provider = new ContextProvider($.get(host), {
402
+ context: assessmentToolkitRuntimeContext,
403
+ initialValue: $.get(runtimeContextValue)
404
+ });
405
+
406
+ provider.connect();
407
+ contextRoot = new ContextRoot($.get(host));
408
+ contextRoot.attach();
409
+
410
+ return () => {
411
+ contextRoot?.detach();
412
+ contextRoot = null;
413
+ provider?.disconnect();
414
+ provider = null;
415
+ };
416
+ });
417
+
418
+ $.user_effect(() => {
419
+ if ($.get(runtimeContextValue)) {
420
+ provider?.setValue($.get(runtimeContextValue));
421
+ }
422
+ });
423
+
424
+ $.user_effect(() => {
425
+ if (!section() || !$.get(effectiveCoordinator)) return;
426
+
427
+ let cancelled = false;
428
+
429
+ void sectionEngine.initialize({
430
+ coordinator: $.get(effectiveCoordinator),
431
+ section: section(),
432
+ sectionId: $.get(effectiveSectionId),
433
+ assessmentId: $.get(effectiveAssessmentId),
434
+ attemptId: attemptId() || undefined,
435
+ view: $.get(effectiveSectionView),
436
+ createDefaultController: createDefaultSectionController,
437
+ onCompositionChanged: (nextComposition) => {
438
+ if (cancelled) return;
439
+
440
+ emitCompositionChanged(nextComposition);
441
+ }
442
+ }).then(() => {
443
+ if (cancelled) return;
444
+
445
+ emit("toolkit-ready", {
446
+ runtimeId,
447
+ assessmentId: $.get(effectiveAssessmentId),
448
+ sectionId: $.get(effectiveSectionId),
449
+ itemPlayer: $.get(effectiveItemPlayer),
450
+ coordinator: $.get(effectiveCoordinator)
451
+ });
452
+
453
+ emit("section-ready", { sectionId: $.get(effectiveSectionId) });
454
+ }).catch((error) => {
455
+ $.set(runtimeError, error, true);
456
+ emit("runtime-error", { runtimeId, error });
457
+ });
458
+
459
+ return () => {
460
+ cancelled = true;
461
+ };
462
+ });
463
+
464
+ $.user_effect(() => {
465
+ if (!$.get(host)) return;
466
+
467
+ const localHost = $.get(host);
468
+
469
+ const onRegister = (event) => {
470
+ if (!isLocalToCurrentRuntime(event.target)) return;
471
+
472
+ const detail = event.detail;
473
+
474
+ if (!detail?.element || !detail?.itemId) return;
475
+
476
+ const changed = sectionEngine.register(detail);
477
+
478
+ if (changed) emitCompositionChanged();
479
+ };
480
+
481
+ const onUnregister = (event) => {
482
+ if (!isLocalToCurrentRuntime(event.target)) return;
483
+
484
+ const detail = event.detail;
485
+ const changed = detail?.element ? sectionEngine.unregister(detail.element) : false;
486
+
487
+ if (changed) emitCompositionChanged();
488
+ };
489
+
490
+ const onItemSessionChanged = (event) => {
491
+ if (!isLocalToCurrentRuntime(event.target)) return;
492
+
493
+ const detail = event.detail;
494
+
495
+ if (!detail?.itemId) return;
496
+ if (!shouldHandleBySourceRuntime(detail.sourceRuntimeId, runtimeId)) return;
497
+
498
+ const result = sectionEngine.handleItemSessionChanged(detail.itemId, detail.session);
499
+
500
+ emitNormalizedSessionChanged({
501
+ itemId: detail.itemId,
502
+ canonicalItemId: detail.canonicalItemId,
503
+ result,
504
+ fallbackSession: detail.session
505
+ });
506
+ };
507
+
508
+ localHost.addEventListener(PIE_REGISTER_EVENT, onRegister);
509
+ localHost.addEventListener(PIE_UNREGISTER_EVENT, onUnregister);
510
+ localHost.addEventListener(PIE_ITEM_SESSION_CHANGED_EVENT, onItemSessionChanged);
511
+
512
+ return () => {
513
+ localHost.removeEventListener(PIE_REGISTER_EVENT, onRegister);
514
+ localHost.removeEventListener(PIE_UNREGISTER_EVENT, onUnregister);
515
+ localHost.removeEventListener(PIE_ITEM_SESSION_CHANGED_EVENT, onItemSessionChanged);
516
+ };
517
+ });
518
+
519
+ async function waitUntilReady() {
520
+ if (!$.get(effectiveCoordinator)) {
521
+ throw new Error("Coordinator not initialized");
522
+ }
523
+
524
+ await $.get(effectiveCoordinator).waitUntilReady();
525
+ }
526
+
527
+ function getServiceBundle() {
528
+ if (!$.get(effectiveCoordinator)) {
529
+ throw new Error("Coordinator not initialized");
530
+ }
531
+
532
+ return $.get(effectiveCoordinator).getServiceBundle();
533
+ }
534
+
535
+ function setHooks(hooks) {
536
+ if (!$.get(effectiveCoordinator)) {
537
+ throw new Error("Coordinator not initialized");
538
+ }
539
+
540
+ $.get(effectiveCoordinator).setHooks(hooks);
541
+ }
542
+
543
+ function navigateToItem(index) {
544
+ return sectionEngine.navigateToItem(index);
545
+ }
546
+
547
+ function getCompositionModel() {
548
+ return sectionEngine.getCompositionModel();
549
+ }
550
+
551
+ function getItemPlayerConfig() {
552
+ return $.get(effectiveItemPlayer);
553
+ }
554
+
555
+ async function persist() {
556
+ await sectionEngine.persist();
557
+ }
558
+
559
+ async function hydrate() {
560
+ await sectionEngine.hydrate();
561
+ }
562
+
563
+ $.user_effect(() => {
564
+ return () => {
565
+ if (compositionEmitRaf !== null && typeof window !== "undefined") {
566
+ window.cancelAnimationFrame(compositionEmitRaf);
567
+ compositionEmitRaf = null;
568
+ }
569
+
570
+ pendingCompositionEmit = false;
571
+
572
+ void sectionEngine.dispose().catch((error) => {
573
+ $.set(runtimeError, error, true);
574
+ });
575
+ };
576
+ });
577
+
578
+ var $$exports = {
579
+ waitUntilReady,
580
+ getServiceBundle,
581
+ setHooks,
582
+ navigateToItem,
583
+ getCompositionModel,
584
+ getItemPlayerConfig,
585
+ persist,
586
+ hydrate,
587
+ get assessmentId() {
588
+ return assessmentId();
589
+ },
590
+
591
+ set assessmentId($$value) {
592
+ assessmentId($$value);
593
+ $.flush();
594
+ },
595
+
596
+ get section() {
597
+ return section();
598
+ },
599
+
600
+ set section($$value) {
601
+ section($$value);
602
+ $.flush();
603
+ },
604
+
605
+ get sectionId() {
606
+ return sectionId();
607
+ },
608
+
609
+ set sectionId($$value) {
610
+ sectionId($$value);
611
+ $.flush();
612
+ },
613
+
614
+ get attemptId() {
615
+ return attemptId();
616
+ },
617
+
618
+ set attemptId($$value) {
619
+ attemptId($$value);
620
+ $.flush();
621
+ },
622
+
623
+ get view() {
624
+ return view();
625
+ },
626
+
627
+ set view($$value) {
628
+ view($$value);
629
+ $.flush();
630
+ },
631
+
632
+ get env() {
633
+ return env();
634
+ },
635
+
636
+ set env($$value) {
637
+ env($$value);
638
+ $.flush();
639
+ },
640
+
641
+ get lazyInit() {
642
+ return lazyInit();
643
+ },
644
+
645
+ set lazyInit($$value) {
646
+ lazyInit($$value);
647
+ $.flush();
648
+ },
649
+
650
+ get tools() {
651
+ return tools();
652
+ },
653
+
654
+ set tools($$value) {
655
+ tools($$value);
656
+ $.flush();
657
+ },
658
+
659
+ get accessibility() {
660
+ return accessibility();
661
+ },
662
+
663
+ set accessibility($$value) {
664
+ accessibility($$value);
665
+ $.flush();
666
+ },
667
+
668
+ get player() {
669
+ return player();
670
+ },
671
+
672
+ set player($$value) {
673
+ player($$value);
674
+ $.flush();
675
+ },
676
+
677
+ get playerType() {
678
+ return playerType();
679
+ },
680
+
681
+ set playerType($$value) {
682
+ playerType($$value);
683
+ $.flush();
684
+ },
685
+
686
+ get coordinator() {
687
+ return coordinator();
688
+ },
689
+
690
+ set coordinator($$value) {
691
+ coordinator($$value);
692
+ $.flush();
693
+ },
694
+
695
+ get createSectionController() {
696
+ return createSectionController();
697
+ },
698
+
699
+ set createSectionController($$value) {
700
+ createSectionController($$value);
701
+ $.flush();
702
+ },
703
+
704
+ get isolation() {
705
+ return isolation();
706
+ },
707
+
708
+ set isolation($$value) {
709
+ isolation($$value);
710
+ $.flush();
711
+ }
712
+ };
713
+
714
+ var fragment = root();
715
+ var div = $.first_child(fragment);
716
+
717
+ $.bind_this(div, ($$value) => $.set(anchor, $$value), () => $.get(anchor));
718
+
719
+ var node = $.sibling(div, 2);
720
+
721
+ $.slot(node, $$props, 'default', {}, null);
722
+ $.append($$anchor, fragment);
723
+
724
+ return $.pop($$exports);
725
+ }
726
+
727
+ customElements.define('pie-assessment-toolkit', $.create_custom_element(
728
+ PieAssessmentToolkit,
729
+ {
730
+ assessmentId: { attribute: 'assessment-id', type: 'String' },
731
+ section: { attribute: 'section', type: 'Object' },
732
+ sectionId: { attribute: 'section-id', type: 'String' },
733
+ attemptId: { attribute: 'attempt-id', type: 'String' },
734
+ view: { attribute: 'view', type: 'String' },
735
+ env: { attribute: 'env', type: 'Object' },
736
+ lazyInit: { attribute: 'lazy-init', type: 'Boolean' },
737
+ tools: { attribute: 'tools', type: 'Object' },
738
+ accessibility: { attribute: 'accessibility', type: 'Object' },
739
+ player: { attribute: 'player', type: 'Object' },
740
+ playerType: { attribute: 'player-type', type: 'String' },
741
+ coordinator: { type: 'Object' },
742
+ createSectionController: { type: 'Object' },
743
+ isolation: { attribute: 'isolation', type: 'String' }
744
+ },
745
+ ['default'],
746
+ [
747
+ 'waitUntilReady',
748
+ 'getServiceBundle',
749
+ 'setHooks',
750
+ 'navigateToItem',
751
+ 'getCompositionModel',
752
+ 'getItemPlayerConfig',
753
+ 'persist',
754
+ 'hydrate'
755
+ ],
756
+ { mode: 'open' }
757
+ ));