@pie-players/pie-assessment-toolkit 0.3.74 → 1.0.0-beta.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 (257) hide show
  1. package/README.md +658 -714
  2. package/custom-elements.json +1315 -0
  3. package/dist/attempt/TestSession.d.ts +1 -21
  4. package/dist/attempt/TestSession.js +16 -102
  5. package/dist/components/ItemScope.custom-element.d.ts +1 -0
  6. package/dist/components/ItemScope.custom-element.js +1 -0
  7. package/dist/components/ItemToolBar.custom-element.js +1 -1
  8. package/dist/components/PieAssessmentToolkit.custom-element.js +14 -14
  9. package/dist/components/SectionToolBar.custom-element.js +1 -1
  10. package/dist/components/chunks/ItemToolBar-3zrc4p3d.js +4 -0
  11. package/dist/components/chunks/ItemToolBar-66hcwmfw.js +2 -0
  12. package/dist/components/chunks/ItemToolBar-9gqhfxtn.js +40 -0
  13. package/dist/components/chunks/ItemToolBar-hzc5wyjp.js +2 -0
  14. package/dist/components/chunks/{ItemToolBar-gmrryv2v.js → ItemToolBar-kkj69ptr.js} +1 -1
  15. package/dist/components/chunks/ItemToolBar-vdkyn9f3.js +2 -0
  16. package/dist/components/chunks/sre-engine-bj997w4b.js +1 -0
  17. package/dist/components/item-scope-element.d.ts +2 -0
  18. package/dist/components/item-scope-element.js +2 -0
  19. package/dist/context/assessment-toolkit-context.d.ts +33 -6
  20. package/dist/index.d.ts +25 -50
  21. package/dist/index.js +15 -45
  22. package/dist/policy/core/PolicySource.d.ts +2 -2
  23. package/dist/policy/core/ToolPolicyEngine.d.ts +118 -34
  24. package/dist/policy/core/ToolPolicyEngine.js +203 -56
  25. package/dist/policy/core/compose-decision.d.ts +28 -7
  26. package/dist/policy/core/compose-decision.js +95 -74
  27. package/dist/policy/core/decision-types.d.ts +98 -55
  28. package/dist/policy/core/feature-decision.d.ts +28 -19
  29. package/dist/policy/core/feature-decision.js +15 -11
  30. package/dist/policy/core/pnp-policy-inputs.d.ts +29 -35
  31. package/dist/policy/core/pnp-policy-inputs.js +40 -88
  32. package/dist/policy/core/provenance.d.ts +10 -5
  33. package/dist/policy/core/provenance.js +1 -1
  34. package/dist/policy/core/tool-parameters.d.ts +11 -0
  35. package/dist/policy/core/tool-parameters.js +15 -0
  36. package/dist/policy/engine.d.ts +7 -23
  37. package/dist/policy/engine.js +5 -20
  38. package/dist/policy/sources/PnpPolicySource.d.ts +43 -68
  39. package/dist/policy/sources/PnpPolicySource.js +133 -132
  40. package/dist/runtime/SectionControllerBinding.d.ts +283 -0
  41. package/dist/runtime/SectionControllerBinding.js +456 -0
  42. package/dist/runtime/SectionRuntimeEngine.d.ts +26 -289
  43. package/dist/runtime/SectionRuntimeEngine.js +30 -372
  44. package/dist/runtime/adapter/SectionEngineAdapter.d.ts +19 -80
  45. package/dist/runtime/adapter/SectionEngineAdapter.js +19 -92
  46. package/dist/runtime/adapter/dom-event-bridge.d.ts +15 -30
  47. package/dist/runtime/adapter/dom-event-bridge.js +17 -44
  48. package/dist/runtime/adapter/subscriber-fanout.d.ts +1 -3
  49. package/dist/runtime/adapter/subscriber-fanout.js +2 -6
  50. package/dist/runtime/catalog-context.d.ts +19 -0
  51. package/dist/runtime/catalog-context.js +28 -0
  52. package/dist/runtime/composition-emit-scheduler.d.ts +12 -18
  53. package/dist/runtime/composition-emit-scheduler.js +10 -16
  54. package/dist/runtime/content-language.d.ts +32 -0
  55. package/dist/runtime/content-language.js +46 -0
  56. package/dist/runtime/content-region.d.ts +13 -0
  57. package/dist/runtime/content-region.js +29 -0
  58. package/dist/runtime/content-registration.d.ts +13 -0
  59. package/dist/runtime/content-registration.js +25 -0
  60. package/dist/runtime/core/SectionEngineCore.d.ts +2 -4
  61. package/dist/runtime/core/SectionEngineCore.js +2 -6
  62. package/dist/runtime/core/cohort.d.ts +1 -6
  63. package/dist/runtime/core/cohort.js +1 -10
  64. package/dist/runtime/core/engine-input.d.ts +18 -30
  65. package/dist/runtime/core/engine-input.js +11 -12
  66. package/dist/runtime/core/engine-output.d.ts +17 -40
  67. package/dist/runtime/core/engine-output.js +9 -21
  68. package/dist/runtime/core/engine-readiness.d.ts +5 -37
  69. package/dist/runtime/core/engine-readiness.js +8 -41
  70. package/dist/runtime/core/engine-resolver.d.ts +46 -74
  71. package/dist/runtime/core/engine-resolver.js +18 -43
  72. package/dist/runtime/core/engine-state.d.ts +28 -36
  73. package/dist/runtime/core/engine-state.js +18 -21
  74. package/dist/runtime/core/engine-transition.d.ts +14 -19
  75. package/dist/runtime/core/engine-transition.js +74 -53
  76. package/dist/runtime/engine.d.ts +16 -19
  77. package/dist/runtime/engine.js +12 -19
  78. package/dist/runtime/page-warnings.d.ts +13 -0
  79. package/dist/runtime/page-warnings.js +22 -0
  80. package/dist/runtime/policy-input-forwarding.d.ts +25 -0
  81. package/dist/runtime/policy-input-forwarding.js +25 -0
  82. package/dist/runtime/registration-events.d.ts +22 -14
  83. package/dist/runtime/runtime-event-claim.d.ts +8 -0
  84. package/dist/runtime/runtime-event-claim.js +15 -0
  85. package/dist/runtime/runtime-id.d.ts +1 -1
  86. package/dist/runtime/runtime-id.js +1 -1
  87. package/dist/runtime/shell-event-bridge.d.ts +45 -0
  88. package/dist/runtime/shell-event-bridge.js +127 -0
  89. package/dist/runtime/shell-registration.d.ts +73 -0
  90. package/dist/runtime/shell-registration.js +95 -0
  91. package/dist/runtime/shell-scope.d.ts +68 -0
  92. package/dist/runtime/shell-scope.js +194 -0
  93. package/dist/runtime/tool-host-contract.d.ts +8 -14
  94. package/dist/runtime/tool-host-contract.js +12 -12
  95. package/dist/runtime/unclaimed-registration-watch.d.ts +7 -0
  96. package/dist/runtime/unclaimed-registration-watch.js +23 -0
  97. package/dist/services/AccessibilityCatalogResolver.d.ts +21 -31
  98. package/dist/services/AccessibilityCatalogResolver.js +29 -42
  99. package/dist/services/ElementToolStateStore.d.ts +42 -67
  100. package/dist/services/ElementToolStateStore.js +65 -71
  101. package/dist/services/HighlightCoordinator.d.ts +28 -40
  102. package/dist/services/HighlightCoordinator.js +459 -381
  103. package/dist/services/RangeSerializer.d.ts +11 -33
  104. package/dist/services/RangeSerializer.js +88 -59
  105. package/dist/services/SSMLExtractor.d.ts +8 -31
  106. package/dist/services/SSMLExtractor.js +18 -40
  107. package/dist/services/TTSService.d.ts +159 -119
  108. package/dist/services/TTSService.js +937 -822
  109. package/dist/services/ToolCoordinator.d.ts +42 -102
  110. package/dist/services/ToolCoordinator.js +178 -256
  111. package/dist/services/ToolRegistry.d.ts +152 -133
  112. package/dist/services/ToolRegistry.js +192 -178
  113. package/dist/services/ToolkitCoordinator.d.ts +233 -237
  114. package/dist/services/ToolkitCoordinator.js +615 -557
  115. package/dist/services/audio-handoff.d.ts +6 -7
  116. package/dist/services/audio-handoff.js +20 -14
  117. package/dist/services/catalog-owner.d.ts +0 -1
  118. package/dist/services/framework-error-bus.d.ts +3 -6
  119. package/dist/services/framework-error-bus.js +3 -6
  120. package/dist/services/framework-error.d.ts +51 -13
  121. package/dist/services/framework-error.js +19 -20
  122. package/dist/services/interfaces.d.ts +189 -184
  123. package/dist/services/section-controller-types.d.ts +7 -7
  124. package/dist/services/section-session-assignment.d.ts +21 -0
  125. package/dist/services/section-session-assignment.js +80 -0
  126. package/dist/services/spoken-audio-cards.d.ts +2 -6
  127. package/dist/services/spoken-audio-cards.js +2 -6
  128. package/dist/services/tool-config-defaults.d.ts +3 -3
  129. package/dist/services/tool-config-defaults.js +3 -3
  130. package/dist/services/tool-config-validation.d.ts +9 -12
  131. package/dist/services/tool-config-validation.js +47 -87
  132. package/dist/services/tool-context.d.ts +7 -31
  133. package/dist/services/tool-context.js +99 -65
  134. package/dist/services/tool-failure.d.ts +30 -0
  135. package/dist/services/tool-failure.js +11 -0
  136. package/dist/services/tool-icons.d.ts +5 -5
  137. package/dist/services/tool-icons.js +6 -5
  138. package/dist/services/tool-instance-id.d.ts +8 -7
  139. package/dist/services/tool-instance-id.js +12 -24
  140. package/dist/services/tool-providers/TTSToolProvider.d.ts +20 -58
  141. package/dist/services/tool-providers/TTSToolProvider.js +32 -85
  142. package/dist/services/tool-providers/ToolProviderApi.d.ts +10 -11
  143. package/dist/services/tool-providers/ToolProviderRegistry.d.ts +29 -60
  144. package/dist/services/tool-providers/ToolProviderRegistry.js +128 -144
  145. package/dist/services/tool-request.d.ts +31 -12
  146. package/dist/services/tool-request.js +31 -16
  147. package/dist/services/toolbar-decided-tools.d.ts +16 -0
  148. package/dist/services/toolbar-decided-tools.js +29 -0
  149. package/dist/services/toolbar-items.js +2 -5
  150. package/dist/services/tools-config-normalizer.d.ts +33 -29
  151. package/dist/services/tools-config-normalizer.js +26 -28
  152. package/dist/services/tts/browser-provider.d.ts +39 -6
  153. package/dist/services/tts/browser-provider.js +280 -160
  154. package/dist/services/tts/catalog-span-alignment.js +14 -7
  155. package/dist/services/tts/flat-tree.d.ts +64 -0
  156. package/dist/services/tts/flat-tree.js +269 -0
  157. package/dist/services/tts/generated-speech/assemble-plan.d.ts +3 -1
  158. package/dist/services/tts/generated-speech/assemble-plan.js +3 -1
  159. package/dist/services/tts/generated-speech/dom/build-dom-plan.d.ts +2 -0
  160. package/dist/services/tts/generated-speech/dom/build-dom-plan.js +1 -1
  161. package/dist/services/tts/generated-speech/dom/to-chunk-inputs.d.ts +2 -2
  162. package/dist/services/tts/generated-speech/index.d.ts +1 -1
  163. package/dist/services/tts/generated-speech/index.js +1 -1
  164. package/dist/services/tts/generated-speech/math-speech-cache.d.ts +3 -1
  165. package/dist/services/tts/generated-speech/math-speech-cache.js +5 -1
  166. package/dist/services/tts/generated-speech/types.d.ts +1 -1
  167. package/dist/services/tts/generated-speech/types.js +1 -1
  168. package/dist/services/tts/highlight-pipeline/create-highlight-plan.js +22 -16
  169. package/dist/services/tts/highlight-pipeline/prose-boundary-resolver.js +6 -4
  170. package/dist/services/tts/highlight-pipeline/readable-region.js +3 -2
  171. package/dist/services/tts/highlight-pipeline/types.d.ts +5 -0
  172. package/dist/services/tts/highlight-pipeline/visible-map-range.d.ts +12 -0
  173. package/dist/services/tts/highlight-pipeline/visible-map-range.js +73 -7
  174. package/dist/services/tts/highlight-target-resolver.d.ts +12 -0
  175. package/dist/services/tts/math-aware-text-processing.d.ts +5 -1
  176. package/dist/services/tts/math-aware-text-processing.js +42 -47
  177. package/dist/services/tts/math-control-names.d.ts +21 -0
  178. package/dist/services/tts/math-control-names.js +142 -0
  179. package/dist/services/tts/math-speech.d.ts +12 -1
  180. package/dist/services/tts/math-speech.js +54 -18
  181. package/dist/services/tts/mathml-sanitization.d.ts +7 -0
  182. package/dist/services/tts/mathml-sanitization.js +9 -1
  183. package/dist/services/tts/provider-options.d.ts +52 -0
  184. package/dist/services/tts/provider-options.js +1 -0
  185. package/dist/services/tts/ssml/spoken-text.d.ts +2 -26
  186. package/dist/services/tts/ssml/spoken-text.js +29 -0
  187. package/dist/services/tts/start-failure.d.ts +4 -0
  188. package/dist/services/tts/start-failure.js +19 -0
  189. package/dist/services/tts/text-processing.d.ts +9 -0
  190. package/dist/services/tts/text-processing.js +46 -33
  191. package/dist/services/tts/text-segmentation.d.ts +12 -0
  192. package/dist/services/tts/text-segmentation.js +60 -10
  193. package/dist/services/tts-runtime-config.d.ts +54 -26
  194. package/dist/services/tts-runtime-config.js +27 -112
  195. package/dist/tools/content-capability-resolution.d.ts +9 -11
  196. package/dist/tools/content-capability-resolution.js +8 -45
  197. package/dist/tools/registration.d.ts +59 -0
  198. package/dist/tools/registration.js +55 -0
  199. package/dist/tools/registrations/toolbar-registration-helpers.d.ts +6 -0
  200. package/dist/tools/registrations/toolbar-registration-helpers.js +8 -2
  201. package/dist/tools/tool-surface-host.d.ts +6 -10
  202. package/dist/tools/tool-surface-host.js +45 -50
  203. package/dist/tools/tool-tag-map.d.ts +5 -15
  204. package/dist/tools/tool-tag-map.js +6 -20
  205. package/dist/utils/structural-equality.d.ts +11 -0
  206. package/dist/utils/structural-equality.js +47 -0
  207. package/package.json +15 -29
  208. package/dist/attempt/adapters/activity-to-test-attempt-session.d.ts +0 -49
  209. package/dist/attempt/adapters/activity-to-test-attempt-session.js +0 -138
  210. package/dist/components/chunks/ItemToolBar-b9dz5jvd.js +0 -40
  211. package/dist/components/chunks/ItemToolBar-h4xap0t0.js +0 -4
  212. package/dist/components/chunks/ItemToolBar-wr2myaah.js +0 -2
  213. package/dist/components/chunks/sre-engine-wf9s43gg.js +0 -1
  214. package/dist/context/runtime-context-consumer.d.ts +0 -13
  215. package/dist/context/runtime-context-consumer.js +0 -18
  216. package/dist/item-loader.d.ts +0 -44
  217. package/dist/item-loader.js +0 -61
  218. package/dist/policy/core/engine-context.d.ts +0 -29
  219. package/dist/policy/core/engine-context.js +0 -27
  220. package/dist/policy/core/policy-source-tag.d.ts +0 -31
  221. package/dist/policy/core/policy-source-tag.js +0 -28
  222. package/dist/policy/internal.d.ts +0 -25
  223. package/dist/policy/internal.js +0 -25
  224. package/dist/runtime/adapter/coordinator-bridge.d.ts +0 -92
  225. package/dist/runtime/adapter/coordinator-bridge.js +0 -126
  226. package/dist/runtime/adapter/framework-error-bridge.d.ts +0 -36
  227. package/dist/runtime/adapter/framework-error-bridge.js +0 -46
  228. package/dist/runtime/adapter/instrumentation-bridge.d.ts +0 -31
  229. package/dist/runtime/adapter/instrumentation-bridge.js +0 -38
  230. package/dist/runtime/core/engine-stage-derivation.d.ts +0 -18
  231. package/dist/runtime/core/engine-stage-derivation.js +0 -29
  232. package/dist/runtime/engine-context.d.ts +0 -39
  233. package/dist/runtime/engine-context.js +0 -31
  234. package/dist/runtime/internal.d.ts +0 -43
  235. package/dist/runtime/internal.js +0 -45
  236. package/dist/runtime/section-runtime-engine-host-context.d.ts +0 -74
  237. package/dist/runtime/section-runtime-engine-host-context.js +0 -57
  238. package/dist/runtime/stage-emit-gate.d.ts +0 -92
  239. package/dist/runtime/stage-emit-gate.js +0 -82
  240. package/dist/services/ContextVariableStore.d.ts +0 -113
  241. package/dist/services/ContextVariableStore.js +0 -206
  242. package/dist/services/I18nService.d.ts +0 -47
  243. package/dist/services/I18nService.js +0 -84
  244. package/dist/services/ThemeProvider.d.ts +0 -95
  245. package/dist/services/ThemeProvider.js +0 -334
  246. package/dist/services/defaultPersonalNeedsProfile.d.ts +0 -21
  247. package/dist/services/defaultPersonalNeedsProfile.js +0 -26
  248. package/dist/services/pnp-standard-features.d.ts +0 -238
  249. package/dist/services/pnp-standard-features.js +0 -338
  250. package/dist/services/tts-control-events.d.ts +0 -13
  251. package/dist/services/tts-control-events.js +0 -7
  252. package/dist/tools/client.d.ts +0 -10
  253. package/dist/tools/client.js +0 -10
  254. package/dist/tools/internal.d.ts +0 -44
  255. package/dist/tools/internal.js +0 -39
  256. package/dist/utils/logger.d.ts +0 -6
  257. package/dist/utils/logger.js +0 -10
@@ -1,8 +1,3 @@
1
- export interface StorageLike {
2
- getItem(key: string): string | null;
3
- setItem(key: string, value: string): void;
4
- removeItem(key: string): void;
5
- }
6
1
  export interface TestAttemptSessionNavigationState {
7
2
  currentItemIndex: number;
8
3
  visitedItemIdentifiers: string[];
@@ -53,25 +48,9 @@ export interface TestAttemptSession {
53
48
  itemSessions: Record<string, TestAttemptItemSession>;
54
49
  /**
55
50
  * QTI 3.0 context variables (global assessment-level variables).
56
- * Managed by ContextVariableStore.
57
51
  */
58
52
  contextVariables?: Record<string, any>;
59
53
  }
60
- export declare function createMemoryStorage(initial?: Record<string, string>): StorageLike;
61
- export declare function getBrowserLocalStorage(): StorageLike | null;
62
- export declare function getOrCreateAnonymousDeviceId(storage: StorageLike): string;
63
- export declare function createTestAttemptSessionIdentifier(args: {
64
- assessmentId: string;
65
- assignmentId?: string | null;
66
- userId?: string | null;
67
- storage: StorageLike;
68
- }): {
69
- testAttemptSessionIdentifier: string;
70
- seed: string;
71
- };
72
- export declare function getTestAttemptSessionStorageKey(testAttemptSessionIdentifier: string): string;
73
- export declare function loadTestAttemptSession(storage: StorageLike, testAttemptSessionIdentifier: string): TestAttemptSession | null;
74
- export declare function saveTestAttemptSession(storage: StorageLike, session: TestAttemptSession): void;
75
54
  export declare function createNewTestAttemptSession(args: {
76
55
  testAttemptSessionIdentifier: string;
77
56
  assessmentId: string;
@@ -89,3 +68,4 @@ export declare function upsertItemSessionFromPieSessionChange(session: TestAttem
89
68
  isCompleted?: boolean;
90
69
  session?: unknown;
91
70
  }): TestAttemptSession;
71
+ export declare function toItemSessionsRecord(testAttemptSession: TestAttemptSession): Record<string, unknown>;
@@ -1,105 +1,15 @@
1
1
  const TEST_ATTEMPT_SESSION_VERSION = 1;
2
- const STORAGE_PREFIX = "pieoneer:testAttemptSession:v1:";
3
- const ANON_DEVICE_ID_KEY = "pieoneer:anonymousDeviceId:v1";
4
- export function createMemoryStorage(initial = {}) {
5
- const store = new Map(Object.entries(initial));
6
- return {
7
- getItem: (k) => (store.has(k) ? store.get(k) : null),
8
- setItem: (k, v) => {
9
- store.set(k, v);
10
- },
11
- removeItem: (k) => {
12
- store.delete(k);
13
- },
14
- };
15
- }
16
- export function getBrowserLocalStorage() {
17
- try {
18
- // eslint-disable-next-line no-undef
19
- if (typeof window === "undefined")
20
- return null;
21
- // eslint-disable-next-line no-undef
22
- if (!window.localStorage)
23
- return null;
24
- // eslint-disable-next-line no-undef
25
- return window.localStorage;
26
- }
27
- catch {
28
- return null;
29
- }
30
- }
31
2
  function nowIso() {
32
3
  return new Date().toISOString();
33
4
  }
34
- // Lightweight, deterministic hash for IDs (no crypto dependency).
35
- function fnv1a32Hex(input) {
36
- let hash = 0x811c9dc5; // offset basis
37
- for (let i = 0; i < input.length; i++) {
38
- hash ^= input.charCodeAt(i);
39
- // hash *= 16777619 (with 32-bit overflow)
40
- hash =
41
- (hash +
42
- ((hash << 1) +
43
- (hash << 4) +
44
- (hash << 7) +
45
- (hash << 8) +
46
- (hash << 24))) >>>
47
- 0;
48
- }
49
- return hash.toString(16).padStart(8, "0");
50
- }
51
- function randomId() {
52
- const cryptoAny = globalThis?.crypto;
53
- const uuid = cryptoAny?.randomUUID?.();
54
- if (typeof uuid === "string" && uuid.length > 0) {
55
- return uuid;
5
+ /** A PIE session id other than the one recorded starts another attempt. */
6
+ function nextAttemptCount(existing, pieSessionId) {
7
+ if (!existing)
8
+ return 1;
9
+ if (existing.pieSessionId && existing.pieSessionId !== pieSessionId) {
10
+ return existing.attemptCount + 1;
56
11
  }
57
- return `anon_${Math.random().toString(16).slice(2)}_${Date.now().toString(16)}`;
58
- }
59
- export function getOrCreateAnonymousDeviceId(storage) {
60
- const existing = storage.getItem(ANON_DEVICE_ID_KEY);
61
- if (existing)
62
- return existing;
63
- const created = randomId();
64
- storage.setItem(ANON_DEVICE_ID_KEY, created);
65
- return created;
66
- }
67
- export function createTestAttemptSessionIdentifier(args) {
68
- const { assessmentId, assignmentId, userId, storage } = args;
69
- if (!assessmentId) {
70
- throw new Error("assessmentId is required to create a TestSession identifier");
71
- }
72
- const subject = userId || getOrCreateAnonymousDeviceId(storage);
73
- const source = `v1|${assessmentId}|${assignmentId || ""}|${subject}`;
74
- const seed = fnv1a32Hex(source);
75
- return { testAttemptSessionIdentifier: `tas_v1_${seed}`, seed };
76
- }
77
- export function getTestAttemptSessionStorageKey(testAttemptSessionIdentifier) {
78
- return `${STORAGE_PREFIX}${testAttemptSessionIdentifier}`;
79
- }
80
- export function loadTestAttemptSession(storage, testAttemptSessionIdentifier) {
81
- const raw = storage.getItem(getTestAttemptSessionStorageKey(testAttemptSessionIdentifier));
82
- if (!raw)
83
- return null;
84
- try {
85
- const parsed = JSON.parse(raw);
86
- if (!parsed || parsed.version !== TEST_ATTEMPT_SESSION_VERSION)
87
- return null;
88
- if (parsed.testAttemptSessionIdentifier !== testAttemptSessionIdentifier) {
89
- return null;
90
- }
91
- return parsed;
92
- }
93
- catch {
94
- return null;
95
- }
96
- }
97
- export function saveTestAttemptSession(storage, session) {
98
- const updated = {
99
- ...session,
100
- updatedAt: nowIso(),
101
- };
102
- storage.setItem(getTestAttemptSessionStorageKey(session.testAttemptSessionIdentifier), JSON.stringify(updated));
12
+ return existing.attemptCount;
103
13
  }
104
14
  export function createNewTestAttemptSession(args) {
105
15
  const startedAt = nowIso();
@@ -149,11 +59,7 @@ export function upsertItemSessionFromPieSessionChange(session, args) {
149
59
  return session;
150
60
  const now = nowIso();
151
61
  const existing = session.itemSessions[itemIdentifier];
152
- const attemptCount = existing && existing.pieSessionId && existing.pieSessionId !== pieSessionId
153
- ? existing.attemptCount + 1
154
- : existing
155
- ? existing.attemptCount
156
- : 1;
62
+ const attemptCount = nextAttemptCount(existing, pieSessionId);
157
63
  const completed = !!(isCompleted ?? existing?.isCompleted);
158
64
  const next = {
159
65
  itemIdentifier,
@@ -173,3 +79,11 @@ export function upsertItemSessionFromPieSessionChange(session, args) {
173
79
  },
174
80
  };
175
81
  }
82
+ export function toItemSessionsRecord(testAttemptSession) {
83
+ return Object.entries(testAttemptSession.itemSessions).reduce((acc, [itemIdentifier, itemSession]) => {
84
+ if (itemSession.session) {
85
+ acc[itemIdentifier] = itemSession.session;
86
+ }
87
+ return acc;
88
+ }, {});
89
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1 @@
1
+ import{a as b,b as m,c as y,d as v,e as D,f as $,k as T}from"./chunks/ItemToolBar-vdkyn9f3.js";import{$ as YJ,A as e,D as JJ,F as QJ,G as I,I as H,M as ZJ,O as XJ,U as qJ,V as WJ,aa as L,ba as UJ,ea as d,fa as o,ga as C,ja as _,ka as g,la as MJ,ma as u,v as n,w as a,x as i,y as k,z as t}from"./chunks/ItemToolBar-3zrc4p3d.js";import"./chunks/ItemToolBar-kkj69ptr.js";import{commitPendingSessions as zJ,createPieLogger as KJ,normalizeItemSessionChange as xJ}from"@pie-players/pie-players-shared";function OJ(Q){let J=Q&&typeof Q==="object"?{...Q}:Q;if(J&&typeof J==="object")delete J.timestamp,delete J.sourceRuntimeId;try{return JSON.stringify(J)}catch{return String(J)}}var wJ=(Q)=>Boolean(Q&&typeof Q==="object"&&Q.sessionCommitReason);function h(Q){let{host:J,kind:Z,identity:W,mode:j,send:Y}=Q,U=KJ(J.localName||"pie-shell",()=>!1),z="",x=(B)=>{let{itemId:M,canonicalItemId:K}=W();if(!M)return;Y(y,{itemId:M,session:B});let X=xJ({itemId:M,sessionDetail:B});if(X.intent==="metadata-only"||!X.session)return;let q={itemId:M,canonicalItemId:K||M,session:X.session,...X.sessionCommitReason?{sessionCommitReason:X.sessionCommitReason}:{}};C(J,v,q)},O=(B)=>{if(j()!=="section")return;if(B.stopPropagation(),Z!=="item")return;let M=B.detail,K=OJ(M);if(!wJ(M)&&K===z)return;z=K,x(M)},w=(B)=>{if(j()==="section")B.stopPropagation();let{itemId:M,canonicalItemId:K,contentKind:G}=W();if(!M)return;let X={itemId:M,canonicalItemId:K||M,contentKind:G,detail:B.detail};Y(D,X)},A=(B)=>{if(j()==="section")B.stopPropagation();let{itemId:M,canonicalItemId:K,contentKind:G}=W();if(!M)return;let X={itemId:M,canonicalItemId:K||M,contentKind:G,error:B.detail};Y($,X)};return J.addEventListener("session-changed",O),J.addEventListener("load-complete",w),J.addEventListener("player-error",A),{disconnect:()=>{try{if(Z==="item"&&j()==="section")zJ(J,{reason:"teardown",logger:U})}finally{J.removeEventListener("session-changed",O),J.removeEventListener("load-complete",w),J.removeEventListener("player-error",A)}}}}import{ContextProvider as GJ}from"@pie-players/pie-context";function AJ(Q,J){return Q.kind===J.kind&&Q.host===J.host&&Q.itemId===J.itemId&&Q.canonicalItemId===J.canonicalItemId&&Q.contentKind===J.contentKind&&u(Q.settings,J.settings)}function p(Q){return T(Q.item,Q.kind)}function E(Q,J){return Q.isConnected||!J?Q:J.eventTarget}function N(Q,J,Z){let W={kind:J.kind,itemId:J.itemId,canonicalItemId:J.canonicalItemId,contentKind:J.contentKind,item:J.item,...J.settings?{settings:J.settings}:{},element:J.host,...Z?{runtimeId:Z.runtimeId}:{}};C(E(J.host,Z),Q,W)}function c(){let Q=null,J=null,Z;function W(){let Y=Q;if(!Y)return;let U=Z;Q=null,J=null,Z=void 0,N(m,Y,U)}function j(Y,U){if(!Y){W();return}if(Q&&Z?.runtimeId!==U?.runtimeId)W();if(Q&&AJ(Q,Y)){if(Q.item===Y.item)return;let z=p(Y);if(z!==null&&z===J){Q=Y;return}Q=Y,J=z,N(b,Y,U);return}Q=Y,J=p(Y),Z=U,N(b,Y,U)}return{sync:j,retire:W}}var fJ=50;function l(Q,J,Z){let W=new GJ(Q,{context:J,initialValue:Z});return W.connect(),{provider:W,value:Z}}function r(Q,J,Z){if(Z(Q.value,J))return;Q.value=J,Q.provider.setValue(J)}var kJ=(Q,J,Z)=>{if(Q===J)return!0;if(!Q||!J)return!1;if(Q.id!==J.id)return!1;let W=T(Q,Z);return W!==null&&W===T(J,Z)},LJ=(Q,J)=>Q.kind===J.kind&&Q.itemId===J.itemId&&Q.canonicalItemId===J.canonicalItemId&&Q.contentKind===J.contentKind&&Q.regionPolicy===J.regionPolicy&&Q.scopeElement===J.scopeElement&&kJ(Q.item,J.item,Q.kind),FJ=(Q,J)=>Q.scopeElement===J.scopeElement&&Q.ttsHighlightTargetResolver===J.ttsHighlightTargetResolver,S=(Q,J,Z)=>{if(Q.getAttribute(J)!==Z)Q.setAttribute(J,Z)};function s(){let Q=c(),J=Date.now(),Z=null,W=null,j=null,Y=null,U=null,z=null,x=[],O=null,w=()=>{if(U!==null)Q.sync(z,U)},A=(X,q)=>X.isConnected&&q.eventTarget.isConnected===!1;function B(X,q){if(X===D)O=q;if(Z&&U!==null&&!A(Z,U)){C(E(Z,U),X,{...q,runtimeId:U.runtimeId});return}if(x.push({type:X,detail:q}),x.length>fJ)x.shift()}function M(X){let q=U!==null&&X.runtimeId!==U.runtimeId;if(X.runtimeId!==U?.runtimeId)U={runtimeId:X.runtimeId,eventTarget:X.eventTarget},w();let F=x;x=[];for(let f of F)B(f.type,f.detail);let V=F.some((f)=>f.type===D);if(q&&O&&!V)B(D,O)}function K(){for(let X of[W,j])X?.provider.disconnect();Y?.(),Y=null,U=null,x=[],O=null,z=null,W=null,j=null,Z=null}function G(X){if(!X){Q.sync(null),K();return}if(X.host!==Z)K();Z=X.host;let q=X.canonicalItemId||X.itemId,F=X.regionPolicy||"default",V=X.scopeElement||X.host,f={kind:X.kind,itemId:X.itemId,canonicalItemId:q,contentKind:X.contentKind,regionPolicy:F,scopeElement:V,item:X.item??null,contextVersion:J};if(W)r(W,f,LJ);else W=l(Z,d,f);let R={scopeElement:V,ttsHighlightTargetResolver:X.ttsHighlightTargetResolver??null};if(j)r(j,R,FJ);else j=l(Z,o,R);S(Z,"data-item-id",X.itemId),S(Z,"data-canonical-item-id",q),S(Z,"data-pie-shell-root",X.kind),S(Z,"data-region-policy",F);let P=z;if(z=X.itemId?{kind:X.kind,host:Z,itemId:X.itemId,canonicalItemId:q,contentKind:X.contentKind,item:X.item??null,settings:X.settings??null}:null,P&&(P.itemId!==z?.itemId||P.canonicalItemId!==z?.canonicalItemId))O=null;Y??=_(Z,M),w()}return{publish:G,retire:Q.retire,disconnect:K,send:B}}var VJ=(Q,J)=>{if(customElements.get(Q))return;try{customElements.define(Q,J)}catch(Z){if(!(Z instanceof DOMException&&Z.name==="NotSupportedError"||Z&&typeof Z==="object"&&Z.name==="NotSupportedError")||!customElements.get(Q))throw Z}},HJ=ZJ('<div class="pie-item-scope-anchor svelte-980v5l" aria-hidden="true"></div> <!>',1),CJ={hash:"svelte-980v5l",code:".pie-item-scope-anchor.svelte-980v5l {display:none;}"};function BJ(Q,J){n(J,!0),WJ(Q,CJ);let Z=L(J,"itemId",7,""),W=L(J,"canonicalItemId",7,""),j=L(J,"contentKind",7,"assessment-item"),Y=L(J,"regionPolicy",7,"default"),U=L(J,"scopeElement",7,null),z=L(J,"ttsHighlightTargetResolver",7,null),x=L(J,"item",7,null),O=L(J,"settings",7,null),w=t(null),A=i(()=>{let q=H(w)?.getRootNode();return q instanceof ShadowRoot?q.host:null}),B=s();I(()=>{if(!H(A))return;let q=H(A),F=!1,V=!1,f=_(q,(jJ)=>{V=!0,F=jJ.sectionBound===!0}),R=setTimeout(()=>{if(V||!q.isConnected)return;MJ(q.ownerDocument,"itemScopeWithoutToolkit",`[pie-item-scope] No <pie-assessment-toolkit> has answered item "${Z()}" after ${g/1000} s, so the item is not registered and the tools inside the scope have no runtime. Place the scope inside the toolkit element; it keeps waiting for one. Reported once per page.`)},g),P=h({host:q,kind:"item",identity:()=>({itemId:Z(),canonicalItemId:W(),contentKind:j()}),mode:()=>F?"section":"plain",send:B.send});return()=>{clearTimeout(R);try{P.disconnect()}finally{f(),B.retire(),B.disconnect()}}}),I(()=>{B.publish(H(A)?{host:H(A),kind:"item",itemId:Z(),canonicalItemId:W(),contentKind:j(),regionPolicy:Y(),scopeElement:U(),ttsHighlightTargetResolver:z(),item:x(),settings:O()}:null)});var M={get itemId(){return Z()},set itemId(q){Z(q),k()},get canonicalItemId(){return W()},set canonicalItemId(q){W(q),k()},get contentKind(){return j()},set contentKind(q){j(q),k()},get regionPolicy(){return Y()},set regionPolicy(q){Y(q),k()},get scopeElement(){return U()},set scopeElement(q){U(q),k()},get ttsHighlightTargetResolver(){return z()},set ttsHighlightTargetResolver(q){z(q),k()},get item(){return x()},set item(q){x(q),k()},get settings(){return O()},set settings(q){O(q),k()}},K=HJ(),G=JJ(K);YJ(G,(q)=>e(w,q),()=>H(w));var X=QJ(G,2);return qJ(X,J,"default",{},null),XJ(Q,K),a(M)}VJ("pie-item-scope",UJ(BJ,{itemId:{attribute:"item-id",type:"String"},canonicalItemId:{attribute:"canonical-item-id",type:"String"},contentKind:{attribute:"content-kind",type:"String"},regionPolicy:{attribute:"region-policy",type:"String"},scopeElement:{type:"Object"},ttsHighlightTargetResolver:{type:"Object"},item:{type:"Object"},settings:{type:"Object"}},["default"],[],{mode:"open"}));export{BJ as default};
@@ -1 +1 @@
1
- import{a}from"./chunks/ItemToolBar-b9dz5jvd.js";import"./chunks/ItemToolBar-h4xap0t0.js";import"./chunks/ItemToolBar-gmrryv2v.js";export{a as default};
1
+ import{l as a}from"./chunks/ItemToolBar-9gqhfxtn.js";import"./chunks/ItemToolBar-hzc5wyjp.js";import"./chunks/ItemToolBar-3zrc4p3d.js";import"./chunks/ItemToolBar-kkj69ptr.js";export{a as default};