@pie-players/pie-players-shared 0.3.47 → 0.3.49

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 (65) hide show
  1. package/README.md +30 -0
  2. package/dist/i18n/simple-i18n.js.map +1 -1
  3. package/dist/index.d.ts +1 -1
  4. package/dist/index.js.map +1 -1
  5. package/dist/instrumentation/debug-panel-stream.js.map +1 -1
  6. package/dist/instrumentation/providers/CompositeInstrumentationProvider.js.map +1 -1
  7. package/dist/instrumentation/providers/DebugPanelInstrumentationProvider.js +2 -1
  8. package/dist/instrumentation/providers/DebugPanelInstrumentationProvider.js.map +1 -1
  9. package/dist/loaders/ElementLoader.js +2 -1
  10. package/dist/loaders/ElementLoader.js.map +1 -1
  11. package/dist/loaders/element-loader.js +28 -4
  12. package/dist/loaders/element-loader.js.map +1 -1
  13. package/dist/loaders/esm-adapter.d.ts +22 -5
  14. package/dist/loaders/esm-adapter.js +320 -60
  15. package/dist/loaders/esm-adapter.js.map +1 -1
  16. package/dist/loaders/iife-adapter.js +1 -2
  17. package/dist/loaders/iife-adapter.js.map +1 -1
  18. package/dist/loaders/index.d.ts +1 -1
  19. package/dist/loaders/index.js.map +1 -1
  20. package/dist/pie/authoring.js +4 -2
  21. package/dist/pie/authoring.js.map +1 -1
  22. package/dist/pie/config.js +4 -1
  23. package/dist/pie/config.js.map +1 -1
  24. package/dist/pie/configure-initialization.js.map +1 -1
  25. package/dist/pie/correct-response-env.js.map +1 -1
  26. package/dist/pie/index.d.ts +1 -1
  27. package/dist/pie/index.js +1 -1
  28. package/dist/pie/index.js.map +1 -1
  29. package/dist/pie/initialization.js +2 -1
  30. package/dist/pie/initialization.js.map +1 -1
  31. package/dist/pie/instrumentation-event-bridge.js.map +1 -1
  32. package/dist/pie/instrumentation-event-map.js.map +1 -1
  33. package/dist/pie/instrumentation-provider-resolution.js.map +1 -1
  34. package/dist/pie/item-controller-storage.js.map +1 -1
  35. package/dist/pie/item-controller.d.ts +15 -0
  36. package/dist/pie/item-controller.js +22 -2
  37. package/dist/pie/item-controller.js.map +1 -1
  38. package/dist/pie/item-session-contract.d.ts +1 -0
  39. package/dist/pie/item-session-contract.js +28 -13
  40. package/dist/pie/item-session-contract.js.map +1 -1
  41. package/dist/pie/math-rendering.js.map +1 -1
  42. package/dist/pie/overrides.js +2 -1
  43. package/dist/pie/overrides.js.map +1 -1
  44. package/dist/pie/resource-monitor.js.map +1 -1
  45. package/dist/pie/stage-tracker.js.map +1 -1
  46. package/dist/pie/types.d.ts +7 -0
  47. package/dist/pie/types.js.map +1 -1
  48. package/dist/pie/updates.d.ts +3 -3
  49. package/dist/pie/updates.js +48 -25
  50. package/dist/pie/updates.js.map +1 -1
  51. package/dist/security/index.d.ts +1 -0
  52. package/dist/security/index.js +1 -0
  53. package/dist/security/index.js.map +1 -1
  54. package/dist/security/sanitize-item-markup.js.map +1 -1
  55. package/dist/security/wrap-model-rich-content.d.ts +1 -0
  56. package/dist/security/wrap-model-rich-content.js +41 -0
  57. package/dist/security/wrap-model-rich-content.js.map +1 -0
  58. package/dist/security/wrap-overwide-images.js +1 -2
  59. package/dist/security/wrap-overwide-images.js.map +1 -1
  60. package/dist/security/wrap-overwide-tables.js +1 -2
  61. package/dist/security/wrap-overwide-tables.js.map +1 -1
  62. package/dist/server/npm-registry.js.map +1 -1
  63. package/dist/types/index.d.ts +15 -3
  64. package/dist/types/index.js.map +1 -1
  65. package/package.json +1 -1
package/dist/pie/index.js CHANGED
@@ -24,7 +24,7 @@ export { resolveInstrumentationProvider } from "./instrumentation-provider-resol
24
24
  export { STAGES, applicableStages, stageOrdinal, } from "./stages.js";
25
25
  export { createStageTracker } from "./stage-tracker.js";
26
26
  export { ASSESSMENT_INSTRUMENTATION_EVENT_MAP, SECTION_INSTRUMENTATION_EVENT_MAP, TOOLKIT_INSTRUMENTATION_EVENT_MAP, } from "./instrumentation-event-map.js";
27
- export { ItemController, normalizeItemSessionContainer } from "./item-controller.js";
27
+ export { ItemController, normalizeItemSessionContainer, } from "./item-controller.js";
28
28
  export { hasResponseValue, normalizeItemSessionChange, } from "./item-session-contract.js";
29
29
  export { MemoryItemSessionStorage, SessionStorageItemSessionStorage, } from "./item-controller-storage.js";
30
30
  export { createPieLogger, isGlobalDebugEnabled } from "./logger.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pie/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,SAAS;AACT,OAAO,EACN,uBAAuB,EACvB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,yBAAyB,GACzB,MAAM,aAAa,CAAC;AACrB,2EAA2E;AAC3E,qEAAqE;AACrE,iBAAiB;AACjB,OAAO,EACN,8BAA8B,EAC9B,oBAAoB,EACpB,aAAa,EACb,uBAAuB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,gCAAgC,EAChC,6BAA6B,EAC7B,6BAA6B,EAC7B,uBAAuB,GACvB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EACN,uBAAuB,EACvB,UAAU,EACV,eAAe,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AAErF,OAAO,EAAE,8BAA8B,EAAE,MAAM,0CAA0C,CAAC;AAC1F,qEAAqE;AACrE,yDAAyD;AACzD,mEAAmE;AACnE,OAAO,EACN,MAAM,EACN,gBAAgB,EAChB,YAAY,GACZ,MAAM,aAAa,CAAC;AAQrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAKxD,OAAO,EACN,oCAAoC,EACpC,iCAAiC,EACjC,iCAAiC,GACjC,MAAM,gCAAgC,CAAC;AAIxC,OAAO,EAAE,cAAc,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAMrF,OAAO,EACN,gBAAgB,EAChB,0BAA0B,GAC1B,MAAM,4BAA4B,CAAC;AAKpC,OAAO,EACN,wBAAwB,EACxB,gCAAgC,GAChC,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAOpE,OAAO,EACN,cAAc,EACd,sBAAsB,EACtB,qBAAqB,EACrB,oBAAoB,EACpB,aAAa,EACb,mBAAmB,GACnB,MAAM,yBAAyB,CAAC;AACjC,WAAW;AACX,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,UAAU;AACV,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAW/D,OAAO,EACN,UAAU,EACV,wBAAwB,EACxB,0BAA0B;AAC1B,0BAA0B;AAC1B,cAAc,EACd,sBAAsB,EACtB,MAAM,GACN,MAAM,YAAY,CAAC;AACpB,qBAAqB;AACrB,OAAO,EACN,yBAAyB,GAGzB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACN,gBAAgB,EAChB,SAAS,EACT,wBAAwB,EACxB,eAAe,GACf,MAAM,gBAAgB,CAAC;AAExB,UAAU;AACV,OAAO,EACN,gBAAgB,EAChB,iBAAiB,EACjB,uBAAuB,GACvB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACN,wBAAwB,EACxB,qBAAqB,EACrB,wCAAwC,EACxC,kBAAkB,EAClB,0BAA0B,EAC1B,mCAAmC,EACnC,4BAA4B,GAC5B,MAAM,gBAAgB,CAAC;AACxB,QAAQ;AACR,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,uBAAuB,EACvB,gBAAgB,GAChB,MAAM,YAAY,CAAC","sourcesContent":["/**\n * PIE Utilities Index\n *\n * Barrel export for public PIE runtime utilities.\n * Public consumers should import from this aggregate. The only supported\n * deep `pie/*` subpath is `pie/tag-names` for tag helper reuse.\n *\n * - `pie` - PIE runtime utilities, interfaces, and helpers\n * - `pie/tag-names` - Custom element tag naming helpers\n */\n\n// Config\nexport {\n\tassertPieConfigContract,\n\taddMarkupForPackage,\n\taddRubricIfNeeded,\n\telementForPackage,\n\tmakeUniqueTags,\n\tmodelsForPackage,\n\tvalidatePieConfigContract,\n} from \"./config.js\";\n// Loaders — the deep `ElementLoader` primitive (async `ensureRegistered` /\n// sync `assertRegistered`) lives under `pie-players-shared/loaders`.\n// Initialization\nexport {\n\tinitializePiesFromLoadedBundle,\n\tloadBundleFromString,\n\tloadPieModule,\n\tloadPieModuleFromString,\n} from \"./initialization.js\";\nexport {\n\tcreateAuthoringAssetEventManager,\n\tinitializeAuthoringConfigures,\n\tresolveConfigureConfiguration,\n\tvalidateAuthoringModels,\n} from \"./authoring.js\";\nexport type {\n\tAuthoringMediaHandlers,\n\tAuthoringValidationResult,\n\tInitializedConfigureModel,\n} from \"./authoring.js\";\nexport {\n\tinitializeMathRendering,\n\trenderMath,\n\tsetMathRenderer,\n} from \"./math-rendering.js\";\nexport { attachInstrumentationEventBridge } from \"./instrumentation-event-bridge.js\";\nexport type { AttachInstrumentationEventBridgeArgs } from \"./instrumentation-event-bridge.js\";\nexport { resolveInstrumentationProvider } from \"./instrumentation-provider-resolution.js\";\n// Canonical stage vocabulary (M6). Both `<pie-section-player-*>` and\n// `<pie-assessment-toolkit>` share this primitive so the\n// `pie-stage-change` event family stays coherent across CE shapes.\nexport {\n\tSTAGES,\n\tapplicableStages,\n\tstageOrdinal,\n} from \"./stages.js\";\nexport type {\n\tLoadingCompleteDetail,\n\tStage,\n\tStageChangeDetail,\n\tStageSourceCe,\n\tStageStatus,\n} from \"./stages.js\";\nexport { createStageTracker } from \"./stage-tracker.js\";\nexport type {\n\tCreateStageTrackerOptions,\n\tStageTracker,\n} from \"./stage-tracker.js\";\nexport {\n\tASSESSMENT_INSTRUMENTATION_EVENT_MAP,\n\tSECTION_INSTRUMENTATION_EVENT_MAP,\n\tTOOLKIT_INSTRUMENTATION_EVENT_MAP,\n} from \"./instrumentation-event-map.js\";\nexport type { InstrumentationEventMapping } from \"./instrumentation-event-map.js\";\n// Item controller\nexport type { ItemControllerOptions } from \"./item-controller.js\";\nexport { ItemController, normalizeItemSessionContainer } from \"./item-controller.js\";\nexport type {\n\tItemSessionContainer as CanonicalItemSessionContainer,\n\tItemSessionUpdateIntent,\n\tNormalizedItemSessionChange,\n} from \"./item-session-contract.js\";\nexport {\n\thasResponseValue,\n\tnormalizeItemSessionChange,\n} from \"./item-session-contract.js\";\nexport type {\n\tItemSessionContainer,\n\tItemSessionStorageStrategy,\n} from \"./item-controller-storage.js\";\nexport {\n\tMemoryItemSessionStorage,\n\tSessionStorageItemSessionStorage,\n} from \"./item-controller-storage.js\";\n// Logging\nexport type { PieLogger } from \"./logger.js\";\nexport { createPieLogger, isGlobalDebugEnabled } from \"./logger.js\";\n// Player bootstrap helpers (used by inline/preloaded players)\nexport type {\n\tItemData,\n\tPiePlayerConfig,\n\tPiePlayerElements,\n} from \"./player-initializer.js\";\nexport {\n\tbuildApiParams,\n\tbuildEventListenersMap,\n\tensurePiePlayerLoaded,\n\textractPassageMarkup,\n\tfetchItemData,\n\tinitializePiePlayer,\n} from \"./player-initializer.js\";\n// Registry\nexport { pieRegistry } from \"./registry.js\";\n// Scoring\nexport { findPieController, scorePieItem } from \"./scoring.js\";\n// Types and interfaces\nexport type {\n\tEntry,\n\tEventListeners,\n\tEventListenersMap,\n\tLoadPieElementsOptions,\n\tPieElement,\n\tPieRegistry,\n\tUpdatePieElementOptions,\n} from \"./types.js\";\nexport {\n\tBundleType,\n\tdefaultPieElementOptions,\n\tisCustomElementConstructor,\n\t// Type guards (functions)\n\tisPieAvailable,\n\tisPieRegistryAvailable,\n\tStatus,\n} from \"./types.js\";\n// Tag naming helpers\nexport {\n\tdefineCustomElementSafely,\n\ttype SafeDefineResult,\n\ttype SafeDefineStatus,\n} from \"./custom-element-define.js\";\nexport {\n\ttoPrintHashedTag,\n\ttoViewTag,\n\tvalidateCustomElementTag,\n\tVIEW_TAG_SUFFIX,\n} from \"./tag-names.js\";\nexport type { PieViewMode } from \"./tag-names.js\";\n// Updates\nexport {\n\tupdatePieElement,\n\tupdatePieElements,\n\tupdatePieElementWithRef,\n} from \"./updates.js\";\n// URL / element override helpers\nexport type { ElementOverrides } from \"./overrides.js\";\nexport {\n\taddOrUpdateOverrideInUrl,\n\tapplyElementOverrides,\n\tapplyElementVersionOverridesPreserveTags,\n\textractPackageInfo,\n\tformatElementOverrideParam,\n\tparseElementOverridesFromCurrentUrl,\n\tparseElementOverridesFromUrl,\n} from \"./overrides.js\";\n// Utils\nexport {\n\tfindOrAddSession,\n\tgetPackageWithoutVersion,\n\tgetPieElementBundlesUrl,\n\tparsePackageName,\n} from \"./utils.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/pie/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,SAAS;AACT,OAAO,EACN,uBAAuB,EACvB,mBAAmB,EACnB,iBAAiB,EACjB,iBAAiB,EACjB,cAAc,EACd,gBAAgB,EAChB,yBAAyB,GACzB,MAAM,aAAa,CAAC;AACrB,2EAA2E;AAC3E,qEAAqE;AACrE,iBAAiB;AACjB,OAAO,EACN,8BAA8B,EAC9B,oBAAoB,EACpB,aAAa,EACb,uBAAuB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,gCAAgC,EAChC,6BAA6B,EAC7B,6BAA6B,EAC7B,uBAAuB,GACvB,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EACN,uBAAuB,EACvB,UAAU,EACV,eAAe,GACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AAErF,OAAO,EAAE,8BAA8B,EAAE,MAAM,0CAA0C,CAAC;AAC1F,qEAAqE;AACrE,yDAAyD;AACzD,mEAAmE;AACnE,OAAO,EACN,MAAM,EACN,gBAAgB,EAChB,YAAY,GACZ,MAAM,aAAa,CAAC;AAQrB,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAKxD,OAAO,EAC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\n * Barrel export for public PIE runtime utilities.\n * Public consumers should import from this aggregate. The only supported\n * deep `pie/*` subpath is `pie/tag-names` for tag helper reuse.\n *\n * - `pie` - PIE runtime utilities, interfaces, and helpers\n * - `pie/tag-names` - Custom element tag naming helpers\n */\n\n// Config\nexport {\n\tassertPieConfigContract,\n\taddMarkupForPackage,\n\taddRubricIfNeeded,\n\telementForPackage,\n\tmakeUniqueTags,\n\tmodelsForPackage,\n\tvalidatePieConfigContract,\n} from \"./config.js\";\n// Loaders — the deep `ElementLoader` primitive (async `ensureRegistered` /\n// sync `assertRegistered`) lives under `pie-players-shared/loaders`.\n// Initialization\nexport {\n\tinitializePiesFromLoadedBundle,\n\tloadBundleFromString,\n\tloadPieModule,\n\tloadPieModuleFromString,\n} from \"./initialization.js\";\nexport {\n\tcreateAuthoringAssetEventManager,\n\tinitializeAuthoringConfigures,\n\tresolveConfigureConfiguration,\n\tvalidateAuthoringModels,\n} from \"./authoring.js\";\nexport type {\n\tAuthoringMediaHandlers,\n\tAuthoringValidationResult,\n\tInitializedConfigureModel,\n} from \"./authoring.js\";\nexport {\n\tinitializeMathRendering,\n\trenderMath,\n\tsetMathRenderer,\n} from \"./math-rendering.js\";\nexport { attachInstrumentationEventBridge } from \"./instrumentation-event-bridge.js\";\nexport type { AttachInstrumentationEventBridgeArgs } from \"./instrumentation-event-bridge.js\";\nexport { resolveInstrumentationProvider } from \"./instrumentation-provider-resolution.js\";\n// Canonical stage vocabulary (M6). Both `<pie-section-player-*>` and\n// `<pie-assessment-toolkit>` share this primitive so the\n// `pie-stage-change` event family stays coherent across CE shapes.\nexport {\n\tSTAGES,\n\tapplicableStages,\n\tstageOrdinal,\n} from \"./stages.js\";\nexport type {\n\tLoadingCompleteDetail,\n\tStage,\n\tStageChangeDetail,\n\tStageSourceCe,\n\tStageStatus,\n} from \"./stages.js\";\nexport { createStageTracker } from \"./stage-tracker.js\";\nexport type {\n\tCreateStageTrackerOptions,\n\tStageTracker,\n} from \"./stage-tracker.js\";\nexport {\n\tASSESSMENT_INSTRUMENTATION_EVENT_MAP,\n\tSECTION_INSTRUMENTATION_EVENT_MAP,\n\tTOOLKIT_INSTRUMENTATION_EVENT_MAP,\n} from \"./instrumentation-event-map.js\";\nexport type { InstrumentationEventMapping } from \"./instrumentation-event-map.js\";\n// Item controller\nexport type { ItemControllerOptions } from \"./item-controller.js\";\nexport {\n\tItemController,\n\tnormalizeItemSessionContainer,\n} from \"./item-controller.js\";\nexport type {\n\tItemSessionContainer as CanonicalItemSessionContainer,\n\tItemSessionUpdateIntent,\n\tNormalizedItemSessionChange,\n} from \"./item-session-contract.js\";\nexport {\n\thasResponseValue,\n\tnormalizeItemSessionChange,\n} from \"./item-session-contract.js\";\nexport type {\n\tItemSessionContainer,\n\tItemSessionStorageStrategy,\n} from \"./item-controller-storage.js\";\nexport {\n\tMemoryItemSessionStorage,\n\tSessionStorageItemSessionStorage,\n} from \"./item-controller-storage.js\";\n// Logging\nexport type { PieLogger } from \"./logger.js\";\nexport { createPieLogger, isGlobalDebugEnabled } from \"./logger.js\";\n// Player bootstrap helpers (used by inline/preloaded players)\nexport type {\n\tItemData,\n\tPiePlayerConfig,\n\tPiePlayerElements,\n} from \"./player-initializer.js\";\nexport {\n\tbuildApiParams,\n\tbuildEventListenersMap,\n\tensurePiePlayerLoaded,\n\textractPassageMarkup,\n\tfetchItemData,\n\tinitializePiePlayer,\n} from \"./player-initializer.js\";\n// Registry\nexport { pieRegistry } from \"./registry.js\";\n// Scoring\nexport { findPieController, scorePieItem } from \"./scoring.js\";\n// Types and interfaces\nexport type {\n\tEntry,\n\tEventListeners,\n\tEventListenersMap,\n\tLoadPieElementsOptions,\n\tPieElement,\n\tPieRegistry,\n\tUpdatePieElementOptions,\n} from \"./types.js\";\nexport {\n\tBundleType,\n\tdefaultPieElementOptions,\n\tisCustomElementConstructor,\n\t// Type guards (functions)\n\tisPieAvailable,\n\tisPieRegistryAvailable,\n\tStatus,\n} from \"./types.js\";\n// Tag naming helpers\nexport {\n\tdefineCustomElementSafely,\n\ttype SafeDefineResult,\n\ttype SafeDefineStatus,\n} from \"./custom-element-define.js\";\nexport {\n\ttoPrintHashedTag,\n\ttoViewTag,\n\tvalidateCustomElementTag,\n\tVIEW_TAG_SUFFIX,\n} from \"./tag-names.js\";\nexport type { PieViewMode } from \"./tag-names.js\";\n// Updates\nexport {\n\tupdatePieElement,\n\tupdatePieElements,\n\tupdatePieElementWithRef,\n} from \"./updates.js\";\n// URL / element override helpers\nexport type { ElementOverrides } from \"./overrides.js\";\nexport {\n\taddOrUpdateOverrideInUrl,\n\tapplyElementOverrides,\n\tapplyElementVersionOverridesPreserveTags,\n\textractPackageInfo,\n\tformatElementOverrideParam,\n\tparseElementOverridesFromCurrentUrl,\n\tparseElementOverridesFromUrl,\n} from \"./overrides.js\";\n// Utils\nexport {\n\tfindOrAddSession,\n\tgetPackageWithoutVersion,\n\tgetPieElementBundlesUrl,\n\tparsePackageName,\n} from \"./utils.js\";\n"]}
@@ -6,6 +6,7 @@
6
6
  */
7
7
  import { BUILDER_BUNDLE_URL } from "../config/profile.js";
8
8
  import { mergeObjectsIgnoringNullUndefined } from "../object/index.js";
9
+ import { wrapModelRichContent } from "../security/wrap-model-rich-content.js";
9
10
  import { editorPostFix } from "../types/index.js";
10
11
  import { createPieLogger, isGlobalDebugEnabled } from "./logger.js";
11
12
  import { initializeMathRendering } from "./math-rendering.js";
@@ -68,7 +69,7 @@ const initializePieElement = (element, options) => {
68
69
  role: env.role,
69
70
  });
70
71
  // Set model directly - server already processed it
71
- element.model = model;
72
+ element.model = wrapModelRichContent(model);
72
73
  }
73
74
  else {
74
75
  // Controller available - run client-side processing (client-player.js bundle)
@@ -1 +1 @@
1
- {"version":3,"file":"initialization.js","sourceRoot":"","sources":["../../src/pie/initialization.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iCAAiC,EAAE,MAAM,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AAC,MAAM,EAAE,OAAO,EAAE,EAAE,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;IAC9D,CAAC,CAAC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,iBAAiB,GAAG,KAAK,EAC9B,QAAgB,EAChB,OAA4C,EAC5C,GAAsC,EACzB,EAAE;IACf,MAAM,MAAM,GAAG,OAAO,CAAC,qBAAqB;QAC3C,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,6BAA6B,EAAE,EAAE,CAAC;QACrD,CAAC,CAAC,QAAQ,CAAC;IACZ,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC,CAAC;IACpE,MAAM,SAAS,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,CAAC;QACJ,OAAO,MAAM,GAAG,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;YAAS,CAAC;QACV,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;AACF,CAAC,CAAC","sourcesContent":["/**\n * PIE Initialization Module\n *\n * Bundle loading and element initialization logic.\n * This is the core of the PIE player system.\n */\n\nimport { BUILDER_BUNDLE_URL } from \"../config/profile.js\";\nimport { mergeObjectsIgnoringNullUndefined } from \"../object/index.js\";\nimport type { ConfigEntity, Env, PieModel } from \"../types/index.js\";\nimport { editorPostFix } from \"../types/index.js\";\nimport { createPieLogger, isGlobalDebugEnabled } from \"./logger.js\";\nimport { initializeMathRendering } from \"./math-rendering.js\";\nimport { pieRegistry } from \"./registry.js\";\nimport { findPieController } from \"./scoring.js\";\nimport { defineCustomElementSafely } from \"./custom-element-define.js\";\nimport { validateCustomElementTag } from \"./tag-names.js\";\nimport type {\n\tEventListeners,\n\tLoadPieElementsOptions,\n\tPieElement,\n\tPieRegistry,\n} from \"./types.js\";\nimport {\n\tBundleType,\n\tisCustomElementConstructor,\n\tisPieAvailable,\n\tStatus,\n} from \"./types.js\";\nimport { updatePieElement } from \"./updates.js\";\nimport {\n\tfindOrAddSession,\n\tgetPackageWithoutVersion,\n\tgetPieElementBundlesUrl,\n} from \"./utils.js\";\n\n// Create module-level logger (respects global debug flag - pass function for dynamic checking)\nconst logger = createPieLogger(\"pie-initialization\", () =>\n\tisGlobalDebugEnabled(),\n);\n\n// Default options for loading PIE elements\nconst defaultOptions: LoadPieElementsOptions = {\n\tbuildServiceBase: BUILDER_BUNDLE_URL,\n\tbundleType: BundleType.player, // Default to player.js (no controllers, server-processed models)\n\tenv: { mode: \"gather\", role: \"student\" },\n};\n\n// Add this to your window types\ndeclare global {\n\tinterface Window {\n\t\t_pieElementObserver?: MutationObserver;\n\t\t_pieCurrentContext?: {\n\t\t\tconfig: ConfigEntity;\n\t\t\tsession: any[];\n\t\t\tenv?: Env;\n\t\t\tcontainer?: Element | Document;\n\t\t};\n\t}\n}\n\n/**\n * Helper function to initialize a PIE element\n */\nconst initializePieElement = (\n\telement: PieElement,\n\toptions: {\n\t\tconfig: ConfigEntity;\n\t\tsession: any[];\n\t\tenv?: Env;\n\t\teventListeners?: EventListeners;\n\t},\n): void => {\n\tconst { config, session, env, eventListeners } = options;\n\tif ((element as any).__pieInitialized) {\n\t\treturn;\n\t}\n\tconst tagName = element.tagName.toLowerCase();\n\n\tlogger.debug(`[initializePieElement] Initializing ${tagName}#${element.id}`);\n\n\t// Find model for this element\n\tlet model = config?.models?.find((m) => m.id === element.id) as PieModel;\n\tif (!model) {\n\t\t// Only warn if this element is from a client-player.js bundle (where models are expected)\n\t\t// player.js bundles use server-processed models, so missing models are expected there\n\t\tconst registry = pieRegistry();\n\t\tconst registryEntry = registry[tagName];\n\n\t\tif (registryEntry && registryEntry.bundleType === BundleType.clientPlayer) {\n\t\t\tlogger.warn(\n\t\t\t\t`[initializePieElement] Model not found for PIE element ${tagName}#${element.id} (client-player.js bundle)`,\n\t\t\t);\n\t\t}\n\t\treturn;\n\t}\n\n\t// Set session (with element property for updateSession callback)\n\tconst elementSession = findOrAddSession(session, model.id, model.element);\n\telement.session = elementSession;\n\t(element as any).__pieInitialized = true;\n\tlogger.debug(\n\t\t`[initializePieElement] Session set for ${tagName}#${element.id}:`,\n\t\telementSession,\n\t);\n\n\t// Set model - use controller if available (client-player.js), or use server-processed model (player.js)\n\tconst controller = findPieController(tagName);\n\n\tif (!env) {\n\t\tlogger.error(\n\t\t\t`[initializePieElement] ❌ FATAL: No env provided for ${tagName}`,\n\t\t);\n\t\tthrow new Error(\n\t\t\t`No env provided for ${tagName}. PIE elements require an env object with mode and role.`,\n\t\t);\n\t}\n\n\tif (!controller) {\n\t\t// No controller available - using server-processed model (player.js bundle)\n\t\tlogger.debug(\n\t\t\t`[initializePieElement] ℹ️ No controller for ${tagName}, using server-processed model`,\n\t\t);\n\t\tlogger.debug(`[initializePieElement] Model already processed by server:`, {\n\t\t\tid: model.id,\n\t\t\telement: model.element,\n\t\t\thasCorrectResponse: \"correctResponse\" in model,\n\t\t\tmode: env.mode,\n\t\t\trole: env.role,\n\t\t});\n\n\t\t// Set model directly - server already processed it\n\t\telement.model = model;\n\t} else {\n\t\t// Controller available - run client-side processing (client-player.js bundle)\n\t\t// Note: updatePieElementWithRef handles controller invocation\n\t\tlogger.debug(\n\t\t\t`[initializePieElement] Controller found for ${tagName}, will invoke model() function`,\n\t\t);\n\t}\n\n\t// Add event listeners\n\tif (eventListeners) {\n\t\tObject.entries(eventListeners).forEach(([evt, fn]) => {\n\t\t\telement.addEventListener(evt as any, fn);\n\t\t});\n\t}\n};\n\nconst getEditorElementTagName = (elementTagName: string, pkg: string): string =>\n\tvalidateCustomElementTag(\n\t\telementTagName + editorPostFix,\n\t\t`editor element tag for ${pkg}`,\n\t);\n\nconst updateRegisteredElement = (\n\telementTagName: string,\n\tconfig: ConfigEntity,\n\tsession: any[],\n\toptions: LoadPieElementsOptions,\n\tomitEnv = false,\n): void => {\n\tupdatePieElement(elementTagName, {\n\t\tconfig,\n\t\tsession,\n\t\t...(omitEnv ? {} : { env: options.env }),\n\t\tcontainer: options.container,\n\t\t...(options.eventListeners?.[elementTagName] && {\n\t\t\teventListeners: options.eventListeners[elementTagName],\n\t\t}),\n\t});\n};\n\n/**\n * Shared element registration logic\n * Extracted from initializePiesFromLoadedBundle and loadPieModule to eliminate ~200 lines of duplication\n * Also fixes MutationObserver memory leak by storing latest config/session in window context\n *\n * `elementModule` may be `null`. In that case we cannot register *new*\n * tags (no element constructor source), but we can still update tags\n * that another loader (e.g. the section-player's IIFE adapter) has\n * already registered with `customElements`. This is the common case\n * when `pie-item-player` mounts inside `pie-section-player`: the\n * section player has already pre-warmed the bundle through the deep\n * `ElementLoader` primitive, so the `window.pie.default` bundle-global\n * path is not required for those tags.\n */\nconst registerPieElementsFromBundle = (\n\telementModule: any | null,\n\tconfig: ConfigEntity,\n\tsession: any[],\n\tregistry: PieRegistry,\n\toptions: LoadPieElementsOptions,\n): Promise<void>[] => {\n\tconst promises: Promise<void>[] = [];\n\tconst isNodeWithinContainer = (\n\t\tnode: Node,\n\t\tcontainer?: Element | Document,\n\t): boolean => {\n\t\tif (!container || container === document) return true;\n\t\treturn node instanceof Node && container.contains(node);\n\t};\n\n\tif (elementModule) {\n\t\tlogger.debug(\n\t\t\t\"[registerPieElementsFromBundle] Available packages in bundle:\",\n\t\t\tObject.keys(elementModule),\n\t\t);\n\t} else {\n\t\tlogger.debug(\n\t\t\t\"[registerPieElementsFromBundle] No bundle module supplied; will only update tags already registered with customElements.\",\n\t\t);\n\t}\n\tlogger.debug(\n\t\t\"[registerPieElementsFromBundle] config.elements:\",\n\t\tconfig.elements,\n\t);\n\n\t// Store latest config/session in window so MutationObserver can access current values\n\tif (typeof window !== \"undefined\") {\n\t\twindow._pieCurrentContext = {\n\t\t\tconfig,\n\t\t\tsession,\n\t\t\tenv: options.env,\n\t\t\tcontainer: options.container,\n\t\t};\n\t}\n\n\tObject.entries(config.elements).forEach(([elName, pkg]) => {\n\t\tconst elementTagName = validateCustomElementTag(\n\t\t\telName,\n\t\t\t`element tag in config.elements for ${String(pkg)}`,\n\t\t);\n\t\tlogger.debug(\n\t\t\t`[registerPieElementsFromBundle] Processing element: ${elementTagName} -> ${pkg}`,\n\t\t);\n\n\t\t// Fast path — the tag is already registered with customElements\n\t\t// (typically by the host's pre-warm pipeline). We can update its\n\t\t// session/model bindings without needing the bundle module at all.\n\t\t// This branch is also the one that runs when `elementModule` is\n\t\t// `null` because `window.pie` was missing.\n\t\tif (customElements.get(elementTagName)) {\n\t\t\tupdateRegisteredElement(elementTagName, config, session, options);\n\n\t\t\tif (options.bundleType === BundleType.editor) {\n\t\t\t\tconst editorElName = getEditorElementTagName(\n\t\t\t\t\telementTagName,\n\t\t\t\t\tString(pkg),\n\t\t\t\t);\n\t\t\t\tupdateRegisteredElement(\n\t\t\t\t\teditorElName,\n\t\t\t\t\tconfig,\n\t\t\t\t\tsession,\n\t\t\t\t\toptions,\n\t\t\t\t\ttrue,\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// From here on we are in the \"register a new tag\" branch, which\n\t\t// requires a bundle module to read the element constructor from.\n\t\tif (!elementModule) {\n\t\t\t// A missing bundle module + an unregistered tag is *not*\n\t\t\t// always an error: in the section-player composition the\n\t\t\t// host's own `ElementLoader` may register this tag\n\t\t\t// out-of-band moments later, in which case `updatePieElement`\n\t\t\t// will pick it up on the next reactive pass via the\n\t\t\t// MutationObserver / `whenDefined` paths. Log at warn so the\n\t\t\t// transient miss is still visible during diagnostics without\n\t\t\t// printing a red stack trace for a routine timing condition.\n\t\t\tlogger.warn(\n\t\t\t\t`[registerPieElementsFromBundle] Skipping \"${elementTagName}\" — no bundle module available and the tag is not yet registered. Will bind on next update if the host's loader registers it.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst pkgStripped = getPackageWithoutVersion(pkg as string);\n\t\tlogger.debug(\n\t\t\t`[registerPieElementsFromBundle] Package without version: \"${pkgStripped}\"`,\n\t\t);\n\n\t\tconst elementData = elementModule[pkgStripped];\n\t\tlogger.debug(\n\t\t\t`[registerPieElementsFromBundle] elementData result:`,\n\t\t\telementData ? \"FOUND\" : \"UNDEFINED\",\n\t\t);\n\n\t\tif (!elementData) {\n\t\t\tlogger.error(\n\t\t\t\t`[registerPieElementsFromBundle] ❌ Package \"${pkgStripped}\" not found in bundle!`,\n\t\t\t);\n\t\t\tlogger.error(\n\t\t\t\t`[registerPieElementsFromBundle] Lookup key: \"${pkgStripped}\"`,\n\t\t\t);\n\t\t\tlogger.error(\n\t\t\t\t`[registerPieElementsFromBundle] Available packages:`,\n\t\t\t\tObject.keys(elementModule),\n\t\t\t);\n\t\t\tthrow new Error(\n\t\t\t\t`pie ${pkgStripped} not found in ${Object.keys(elementModule)}`,\n\t\t\t);\n\t\t}\n\n\t\tlogger.debug(\n\t\t\t`[registerPieElementsFromBundle] elementData for ${pkgStripped}:`,\n\t\t\t{\n\t\t\t\thasController: !!elementData.controller,\n\t\t\t\thasElement: !!elementData.Element,\n\t\t\t\thasConfig: !!elementData.config,\n\t\t\t\tcontrollerKeys: elementData.controller\n\t\t\t\t\t? Object.keys(elementData.controller)\n\t\t\t\t\t: [],\n\t\t\t\tbundleType: options.bundleType,\n\t\t\t},\n\t\t);\n\n\t\t// Validate controller presence based on bundle type\n\t\tif (!elementData.controller) {\n\t\t\tif (options.bundleType === BundleType.clientPlayer) {\n\t\t\t\tlogger.error(\n\t\t\t\t\t`[registerPieElementsFromBundle] ❌ CRITICAL: No controller found for ${pkgStripped}!`,\n\t\t\t\t);\n\t\t\t\tlogger.error(\n\t\t\t\t\t`[registerPieElementsFromBundle] Bundle type: ${options.bundleType} (controllers required)`,\n\t\t\t\t);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`No controller found for ${pkgStripped}. client-player.js bundles MUST include controllers!`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tlogger.debug(\n\t\t\t\t\t`[registerPieElementsFromBundle] ℹ️ No controller found for ${pkgStripped} - using server-processed models (player.js bundle)`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t{\n\t\t\t// Register the element in our registry\n\t\t\tlogger.debug(\n\t\t\t\t`[registerPieElementsFromBundle] Registering ${elName} in registry${\n\t\t\t\t\telementData.controller\n\t\t\t\t\t\t? \" with controller\"\n\t\t\t\t\t\t: \" (no controller - server-processed models)\"\n\t\t\t\t}`,\n\t\t\t);\n\t\t\tregistry[elementTagName] = {\n\t\t\t\tpackage: pkg as string,\n\t\t\t\tstatus: Status.loading,\n\t\t\t\ttagName: elementTagName,\n\t\t\t\tcontroller: elementData.controller || null,\n\t\t\t\tconfig: elementData.config,\n\t\t\t\tbundleType: options.bundleType,\n\t\t\t};\n\n\t\t\tif (isCustomElementConstructor(elementData.Element)) {\n\t\t\t\tdefineCustomElementSafely(\n\t\t\t\t\telementTagName,\n\t\t\t\t\telementData.Element,\n\t\t\t\t\t`element tag in config.elements for ${String(pkg)}`,\n\t\t\t\t);\n\n\t\t\t\t// Initialize existing elements\n\t\t\t\tconst searchRoot = options.container || document;\n\t\t\t\tconst elements = searchRoot.querySelectorAll(elementTagName);\n\t\t\t\tlogger.debug(\n\t\t\t\t\t`[registerPieElementsFromBundle] Found ${elements.length} elements for tag '${elementTagName}'`,\n\t\t\t\t);\n\n\t\t\t\telements.forEach((el) => {\n\t\t\t\t\tinitializePieElement(el as PieElement, {\n\t\t\t\t\t\tconfig,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tenv: options.env,\n\t\t\t\t\t\teventListeners: options.eventListeners?.[elementTagName],\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\t\t// Update registry status\n\t\t\t\tregistry[elementTagName] = {\n\t\t\t\t\t...registry[elementTagName],\n\t\t\t\t\tstatus: Status.loaded,\n\t\t\t\t};\n\n\t\t\t\tpromises.push(\n\t\t\t\t\tcustomElements.whenDefined(elementTagName).then(() => {\n\t\t\t\t\t\tlogger.debug(\n\t\t\t\t\t\t\t\"[registerPieElementsFromBundle] defined custom PIE element: %s\",\n\t\t\t\t\t\t\telementTagName,\n\t\t\t\t\t\t);\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\t// Setup MutationObserver that uses current context (only once)\n\t\t\t\tif (!window._pieElementObserver) {\n\t\t\t\t\twindow._pieElementObserver = new MutationObserver((mutations) => {\n\t\t\t\t\t\t// Use current context from window instead of stale closure\n\t\t\t\t\t\tconst context = window._pieCurrentContext;\n\t\t\t\t\t\tif (!context) {\n\t\t\t\t\t\t\tlogger.warn(\"[MutationObserver] No current context available\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tmutations.forEach((mutation) => {\n\t\t\t\t\t\t\tif (mutation.type === \"childList\") {\n\t\t\t\t\t\t\t\tmutation.addedNodes.forEach((node) => {\n\t\t\t\t\t\t\t\t\tif (node.nodeType === Node.ELEMENT_NODE) {\n\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t!isNodeWithinContainer(\n\t\t\t\t\t\t\t\t\t\t\t\tnode,\n\t\t\t\t\t\t\t\t\t\t\t\tcontext.container,\n\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tconst tagName = (node as Element).tagName.toLowerCase();\n\t\t\t\t\t\t\t\t\t\tif (registry[tagName]) {\n\t\t\t\t\t\t\t\t\t\t\tinitializePieElement(node as PieElement, {\n\t\t\t\t\t\t\t\t\t\t\t\tconfig: context.config,\n\t\t\t\t\t\t\t\t\t\t\t\tsession: context.session,\n\t\t\t\t\t\t\t\t\t\t\t\tenv: context.env,\n\t\t\t\t\t\t\t\t\t\t\t\teventListeners: options.eventListeners?.[tagName],\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t// Check children of added nodes\n\t\t\t\t\t\t\t\t\t\t(node as Element)\n\t\t\t\t\t\t\t\t\t\t\t.querySelectorAll(\"*\")\n\t\t\t\t\t\t\t\t\t\t\t.forEach((childNode) => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t\t!isNodeWithinContainer(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tchildNode,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcontext.container,\n\t\t\t\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\tconst childTagName = childNode.tagName.toLowerCase();\n\t\t\t\t\t\t\t\t\t\t\t\tif (registry[childTagName]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tinitializePieElement(childNode as PieElement, {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tconfig: context.config,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsession: context.session,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tenv: context.env,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\teventListeners:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\toptions.eventListeners?.[childTagName],\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\n\t\t\t\t\twindow._pieElementObserver.observe(document.body, {\n\t\t\t\t\t\tchildList: true,\n\t\t\t\t\t\tsubtree: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Handle editor elements if needed\n\t\t\t\tif (options.bundleType === BundleType.editor) {\n\t\t\t\t\tif (isCustomElementConstructor(elementData.Configure)) {\n\t\t\t\t\t\tconst editorElName = getEditorElementTagName(\n\t\t\t\t\t\t\telementTagName,\n\t\t\t\t\t\t\tString(pkg),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdefineCustomElementSafely(\n\t\t\t\t\t\t\teditorElName,\n\t\t\t\t\t\t\telementData.Configure,\n\t\t\t\t\t\t\t`editor element tag for ${String(pkg)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tpromises.push(\n\t\t\t\t\t\t\tcustomElements.whenDefined(editorElName).then(() => {\n\t\t\t\t\t\t\t\tlogger.debug(\n\t\t\t\t\t\t\t\t\t`[registerPieElementsFromBundle] defined custom PIE editor element: ${editorElName}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t\t`[registerPieElementsFromBundle] pie.Configure for ${pkgStripped} is not a valid custom element constructor.`,\n\t\t\t\t\t\t\telementData.configure,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlogger.error(\n\t\t\t\t\t`[registerPieElementsFromBundle] pie.Element for ${pkgStripped} is not a valid custom element constructor.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t});\n\n\treturn promises;\n};\n\n/**\n * Initialize PIE elements from a bundle that may already be loaded.\n *\n * `window.pie` is the IIFE bundle-loading global populated by\n * `loadPieModule` / `loadBundleFromString`. When the host loaded the\n * bundle through the deep `ElementLoader` primitive instead — as\n * `pie-section-player` does — the global is irrelevant: the loader\n * registers tags directly with `customElements`, so this function only\n * needs to bind models/sessions to whatever is already registered.\n *\n * Behavior:\n * - `window.pie` available → register any new tags from the bundle and\n * update bindings for already-registered tags.\n * - `window.pie` missing → fall back to the update-only path. Tags that\n * are already registered get their model/session updated; tags that\n * are not yet registered are logged at `warn` and left alone — the\n * host's loader is expected to register them imminently, after which\n * the existing `MutationObserver` / `updatePieElements` flow binds\n * them on the next reactive pass.\n *\n * The original blanket `window.pie not found; was the bundle inlined\n * correctly?` error has been removed: in the section-player + item-player\n * composition it produced a confusing red stack trace for a routine\n * timing condition that the host already handles. Genuine failures\n * (bundle not loaded by *anyone*) still surface — every unregistered tag\n * gets its own warning, and `updatePieElements` later reports any tag\n * that never resolves.\n */\nexport const initializePiesFromLoadedBundle = (\n\tconfig: ConfigEntity,\n\tsession: any[],\n\topts: LoadPieElementsOptions = {},\n): void => {\n\tconst registry = pieRegistry();\n\tconst options = mergeObjectsIgnoringNullUndefined(defaultOptions, opts);\n\n\tif (isPieAvailable(window)) {\n\t\tlogger.debug(\"[initializePiesFromLoadedBundle] window.pie available\");\n\t\tconst elementModule = window.pie.default;\n\t\tregisterPieElementsFromBundle(\n\t\t\telementModule,\n\t\t\tconfig,\n\t\t\tsession,\n\t\t\tregistry,\n\t\t\toptions,\n\t\t);\n\t\treturn;\n\t}\n\n\tlogger.debug(\n\t\t\"[initializePiesFromLoadedBundle] window.pie not present; using update-only path. Already-registered tags will be bound now; missing tags are expected to be registered by the host's loader and will bind on the next update pass.\",\n\t);\n\tregisterPieElementsFromBundle(null, config, session, registry, options);\n};\n\n/**\n * Load a PIE bundle from a URL and initialize elements\n */\nexport const loadPieModule = async (\n\tconfig: ConfigEntity,\n\tsession: any[],\n\topts: LoadPieElementsOptions = {},\n): Promise<{\n\tsession: any[];\n}> => {\n\tif (!session) {\n\t\tthrow new Error(\"session is required\");\n\t}\n\n\t// Initialize math-rendering module (required by PIE elements)\n\tawait initializeMathRendering();\n\n\tconst registry = pieRegistry();\n\tconst options = mergeObjectsIgnoringNullUndefined(defaultOptions, opts);\n\tconst url = opts.bundleUrl || getPieElementBundlesUrl(config, options);\n\tconst script = document.createElement(\"script\");\n\tscript.src = url;\n\tscript.defer = true;\n\tscript.onerror = () => {\n\t\tthrow new Error(`failed to load script: ${url}`);\n\t};\n\n\tconst loadPromise = new Promise<void>((loadResolve) => {\n\t\tscript.addEventListener(\"load\", () => {\n\t\t\tlogger.debug(\"[loadPieModule] Script loaded from:\", url);\n\t\t\tif (isPieAvailable(window)) {\n\t\t\t\tlogger.debug(\"[loadPieModule] window.pie available\");\n\t\t\t\tconst elementModule = window.pie.default;\n\n\t\t\t\t// Use shared registration logic (returns array of promises)\n\t\t\t\tconst registrationPromises = registerPieElementsFromBundle(\n\t\t\t\t\telementModule,\n\t\t\t\t\tconfig,\n\t\t\t\t\tsession,\n\t\t\t\t\tregistry,\n\t\t\t\t\toptions,\n\t\t\t\t);\n\n\t\t\t\t// Wait for all element definitions to complete\n\t\t\t\tPromise.all(registrationPromises).then(() => loadResolve());\n\t\t\t} else {\n\t\t\t\tlogger.error(\n\t\t\t\t\t\"[loadPieModule] pie var not found; is %s a proper PIE IIFE module?\",\n\t\t\t\t\turl,\n\t\t\t\t);\n\t\t\t\tloadResolve();\n\t\t\t}\n\t\t});\n\t});\n\n\tdocument.head.appendChild(script);\n\tawait loadPromise;\n\treturn { session };\n};\n\n/**\n * Load a PIE bundle from a JavaScript string into window.pie (IIFE bundles only)\n * This only registers elements and controllers - does NOT initialize them.\n * For initialization, use initializePiesFromLoadedBundle after loading.\n */\nexport const loadBundleFromString = async (bundleJs: string): Promise<void> => {\n\tawait initializeMathRendering();\n\tawait withBlobBundleUrl(\n\t\tbundleJs,\n\t\t{ stripSourceMapComment: true },\n\t\tasync (bundleUrl) => {\n\t\t\t// Create a script tag to execute the bundle\n\t\t\tconst script = document.createElement(\"script\");\n\t\t\tscript.src = bundleUrl;\n\t\t\tscript.type = \"text/javascript\"; // IIFE bundles are standard JS\n\n\t\t\t// Wait for script to load\n\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\tscript.onload = () => resolve();\n\t\t\t\tscript.onerror = () => reject(new Error(\"Failed to load bundle\"));\n\t\t\t\tdocument.head.appendChild(script);\n\t\t\t});\n\n\t\t\tlogger.debug(\"[loadBundleFromString] Bundle loaded into window.pie\");\n\t\t},\n\t);\n};\n\n/**\n * Load a PIE bundle from a JavaScript string and initialize elements\n * Convenience wrapper around loadBundleFromString + loadPieModule\n */\nexport const loadPieModuleFromString = async (\n\tbundleJs: string,\n\tconfig: ConfigEntity,\n\tsession: any[],\n\topts: LoadPieElementsOptions = {},\n): Promise<void> => {\n\tawait withBlobBundleUrl(bundleJs, {}, async (bundleUrl) => {\n\t\t// Use existing loadPieModule with the blob URL\n\t\tawait loadPieModule(config, session, { ...opts, bundleUrl });\n\t});\n};\n\nconst withBlobBundleUrl = async <T>(\n\tbundleJs: string,\n\toptions: { stripSourceMapComment?: boolean },\n\trun: (bundleUrl: string) => Promise<T>,\n): Promise<T> => {\n\tconst source = options.stripSourceMapComment\n\t\t? bundleJs.replace(/\\/\\/# sourceMappingURL=.*$/m, \"\")\n\t\t: bundleJs;\n\tconst blob = new Blob([source], { type: \"application/javascript\" });\n\tconst bundleUrl = URL.createObjectURL(blob);\n\ttry {\n\t\treturn await run(bundleUrl);\n\t} finally {\n\t\tURL.revokeObjectURL(bundleUrl);\n\t}\n};\n"]}
1
+ {"version":3,"file":"initialization.js","sourceRoot":"","sources":["../../src/pie/initialization.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,iCAAiC,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,oBAAoB,EAAE,MAAM,wCAAwC,CAAC;AAE9E,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACpE,OAAO,EAAE,uBAAuB,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACjD,OAAO,EAAE,yBAAyB,EAAE,MAAM,4BAA4B,CAAC;A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AAE,EAAE,CAAC;QACrD,CAAC,CAAC,QAAQ,CAAC;IACZ,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,EAAE,wBAAwB,EAAE,CAAC,CAAC;IACpE,MAAM,SAAS,GAAG,GAAG,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC5C,IAAI,CAAC;QACJ,OAAO,MAAM,GAAG,CAAC,SAAS,CAAC,CAAC;IAC7B,CAAC;YAAS,CAAC;QACV,GAAG,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IAChC,CAAC;AACF,CAAC,CAAC","sourcesContent":["/**\n * PIE Initialization Module\n *\n * Bundle loading and element initialization logic.\n * This is the core of the PIE player system.\n */\n\nimport { BUILDER_BUNDLE_URL } from \"../config/profile.js\";\nimport { mergeObjectsIgnoringNullUndefined } from \"../object/index.js\";\nimport { wrapModelRichContent } from \"../security/wrap-model-rich-content.js\";\nimport type { ConfigEntity, Env, PieModel } from \"../types/index.js\";\nimport { editorPostFix } from \"../types/index.js\";\nimport { createPieLogger, isGlobalDebugEnabled } from \"./logger.js\";\nimport { initializeMathRendering } from \"./math-rendering.js\";\nimport { pieRegistry } from \"./registry.js\";\nimport { findPieController } from \"./scoring.js\";\nimport { defineCustomElementSafely } from \"./custom-element-define.js\";\nimport { validateCustomElementTag } from \"./tag-names.js\";\nimport type {\n\tEventListeners,\n\tLoadPieElementsOptions,\n\tPieElement,\n\tPieRegistry,\n} from \"./types.js\";\nimport {\n\tBundleType,\n\tisCustomElementConstructor,\n\tisPieAvailable,\n\tStatus,\n} from \"./types.js\";\nimport { updatePieElement } from \"./updates.js\";\nimport {\n\tfindOrAddSession,\n\tgetPackageWithoutVersion,\n\tgetPieElementBundlesUrl,\n} from \"./utils.js\";\n\n// Create module-level logger (respects global debug flag - pass function for dynamic checking)\nconst logger = createPieLogger(\"pie-initialization\", () =>\n\tisGlobalDebugEnabled(),\n);\n\n// Default options for loading PIE elements\nconst defaultOptions: LoadPieElementsOptions = {\n\tbuildServiceBase: BUILDER_BUNDLE_URL,\n\tbundleType: BundleType.player, // Default to player.js (no controllers, server-processed models)\n\tenv: { mode: \"gather\", role: \"student\" },\n};\n\n// Add this to your window types\ndeclare global {\n\tinterface Window {\n\t\t_pieElementObserver?: MutationObserver;\n\t\t_pieCurrentContext?: {\n\t\t\tconfig: ConfigEntity;\n\t\t\tsession: any[];\n\t\t\tenv?: Env;\n\t\t\tcontainer?: Element | Document;\n\t\t};\n\t}\n}\n\n/**\n * Helper function to initialize a PIE element\n */\nconst initializePieElement = (\n\telement: PieElement,\n\toptions: {\n\t\tconfig: ConfigEntity;\n\t\tsession: any[];\n\t\tenv?: Env;\n\t\teventListeners?: EventListeners;\n\t},\n): void => {\n\tconst { config, session, env, eventListeners } = options;\n\tif ((element as any).__pieInitialized) {\n\t\treturn;\n\t}\n\tconst tagName = element.tagName.toLowerCase();\n\n\tlogger.debug(`[initializePieElement] Initializing ${tagName}#${element.id}`);\n\n\t// Find model for this element\n\tlet model = config?.models?.find((m) => m.id === element.id) as PieModel;\n\tif (!model) {\n\t\t// Only warn if this element is from a client-player.js bundle (where models are expected)\n\t\t// player.js bundles use server-processed models, so missing models are expected there\n\t\tconst registry = pieRegistry();\n\t\tconst registryEntry = registry[tagName];\n\n\t\tif (registryEntry && registryEntry.bundleType === BundleType.clientPlayer) {\n\t\t\tlogger.warn(\n\t\t\t\t`[initializePieElement] Model not found for PIE element ${tagName}#${element.id} (client-player.js bundle)`,\n\t\t\t);\n\t\t}\n\t\treturn;\n\t}\n\n\t// Set session (with element property for updateSession callback)\n\tconst elementSession = findOrAddSession(session, model.id, model.element);\n\telement.session = elementSession;\n\t(element as any).__pieInitialized = true;\n\tlogger.debug(\n\t\t`[initializePieElement] Session set for ${tagName}#${element.id}:`,\n\t\telementSession,\n\t);\n\n\t// Set model - use controller if available (client-player.js), or use server-processed model (player.js)\n\tconst controller = findPieController(tagName);\n\n\tif (!env) {\n\t\tlogger.error(\n\t\t\t`[initializePieElement] ❌ FATAL: No env provided for ${tagName}`,\n\t\t);\n\t\tthrow new Error(\n\t\t\t`No env provided for ${tagName}. PIE elements require an env object with mode and role.`,\n\t\t);\n\t}\n\n\tif (!controller) {\n\t\t// No controller available - using server-processed model (player.js bundle)\n\t\tlogger.debug(\n\t\t\t`[initializePieElement] ℹ️ No controller for ${tagName}, using server-processed model`,\n\t\t);\n\t\tlogger.debug(`[initializePieElement] Model already processed by server:`, {\n\t\t\tid: model.id,\n\t\t\telement: model.element,\n\t\t\thasCorrectResponse: \"correctResponse\" in model,\n\t\t\tmode: env.mode,\n\t\t\trole: env.role,\n\t\t});\n\n\t\t// Set model directly - server already processed it\n\t\telement.model = wrapModelRichContent(model);\n\t} else {\n\t\t// Controller available - run client-side processing (client-player.js bundle)\n\t\t// Note: updatePieElementWithRef handles controller invocation\n\t\tlogger.debug(\n\t\t\t`[initializePieElement] Controller found for ${tagName}, will invoke model() function`,\n\t\t);\n\t}\n\n\t// Add event listeners\n\tif (eventListeners) {\n\t\tObject.entries(eventListeners).forEach(([evt, fn]) => {\n\t\t\telement.addEventListener(evt as any, fn);\n\t\t});\n\t}\n};\n\nconst getEditorElementTagName = (elementTagName: string, pkg: string): string =>\n\tvalidateCustomElementTag(\n\t\telementTagName + editorPostFix,\n\t\t`editor element tag for ${pkg}`,\n\t);\n\nconst updateRegisteredElement = (\n\telementTagName: string,\n\tconfig: ConfigEntity,\n\tsession: any[],\n\toptions: LoadPieElementsOptions,\n\tomitEnv = false,\n): void => {\n\tupdatePieElement(elementTagName, {\n\t\tconfig,\n\t\tsession,\n\t\t...(omitEnv ? {} : { env: options.env }),\n\t\tcontainer: options.container,\n\t\t...(options.eventListeners?.[elementTagName] && {\n\t\t\teventListeners: options.eventListeners[elementTagName],\n\t\t}),\n\t});\n};\n\n/**\n * Shared element registration logic\n * Extracted from initializePiesFromLoadedBundle and loadPieModule to eliminate ~200 lines of duplication\n * Also fixes MutationObserver memory leak by storing latest config/session in window context\n *\n * `elementModule` may be `null`. In that case we cannot register *new*\n * tags (no element constructor source), but we can still update tags\n * that another loader (e.g. the section-player's IIFE adapter) has\n * already registered with `customElements`. This is the common case\n * when `pie-item-player` mounts inside `pie-section-player`: the\n * section player has already pre-warmed the bundle through the deep\n * `ElementLoader` primitive, so the `window.pie.default` bundle-global\n * path is not required for those tags.\n */\nconst registerPieElementsFromBundle = (\n\telementModule: any | null,\n\tconfig: ConfigEntity,\n\tsession: any[],\n\tregistry: PieRegistry,\n\toptions: LoadPieElementsOptions,\n): Promise<void>[] => {\n\tconst promises: Promise<void>[] = [];\n\tconst isNodeWithinContainer = (\n\t\tnode: Node,\n\t\tcontainer?: Element | Document,\n\t): boolean => {\n\t\tif (!container || container === document) return true;\n\t\treturn node instanceof Node && container.contains(node);\n\t};\n\n\tif (elementModule) {\n\t\tlogger.debug(\n\t\t\t\"[registerPieElementsFromBundle] Available packages in bundle:\",\n\t\t\tObject.keys(elementModule),\n\t\t);\n\t} else {\n\t\tlogger.debug(\n\t\t\t\"[registerPieElementsFromBundle] No bundle module supplied; will only update tags already registered with customElements.\",\n\t\t);\n\t}\n\tlogger.debug(\n\t\t\"[registerPieElementsFromBundle] config.elements:\",\n\t\tconfig.elements,\n\t);\n\n\t// Store latest config/session in window so MutationObserver can access current values\n\tif (typeof window !== \"undefined\") {\n\t\twindow._pieCurrentContext = {\n\t\t\tconfig,\n\t\t\tsession,\n\t\t\tenv: options.env,\n\t\t\tcontainer: options.container,\n\t\t};\n\t}\n\n\tObject.entries(config.elements).forEach(([elName, pkg]) => {\n\t\tconst elementTagName = validateCustomElementTag(\n\t\t\telName,\n\t\t\t`element tag in config.elements for ${String(pkg)}`,\n\t\t);\n\t\tlogger.debug(\n\t\t\t`[registerPieElementsFromBundle] Processing element: ${elementTagName} -> ${pkg}`,\n\t\t);\n\n\t\t// Fast path — the tag is already registered with customElements\n\t\t// (typically by the host's pre-warm pipeline). We can update its\n\t\t// session/model bindings without needing the bundle module at all.\n\t\t// This branch is also the one that runs when `elementModule` is\n\t\t// `null` because `window.pie` was missing.\n\t\tif (customElements.get(elementTagName)) {\n\t\t\tupdateRegisteredElement(elementTagName, config, session, options);\n\n\t\t\tif (options.bundleType === BundleType.editor) {\n\t\t\t\tconst editorElName = getEditorElementTagName(\n\t\t\t\t\telementTagName,\n\t\t\t\t\tString(pkg),\n\t\t\t\t);\n\t\t\t\tupdateRegisteredElement(editorElName, config, session, options, true);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// From here on we are in the \"register a new tag\" branch, which\n\t\t// requires a bundle module to read the element constructor from.\n\t\tif (!elementModule) {\n\t\t\t// A missing bundle module + an unregistered tag is *not*\n\t\t\t// always an error: in the section-player composition the\n\t\t\t// host's own `ElementLoader` may register this tag\n\t\t\t// out-of-band moments later, in which case `updatePieElement`\n\t\t\t// will pick it up on the next reactive pass via the\n\t\t\t// MutationObserver / `whenDefined` paths. Log at warn so the\n\t\t\t// transient miss is still visible during diagnostics without\n\t\t\t// printing a red stack trace for a routine timing condition.\n\t\t\tlogger.warn(\n\t\t\t\t`[registerPieElementsFromBundle] Skipping \"${elementTagName}\" — no bundle module available and the tag is not yet registered. Will bind on next update if the host's loader registers it.`,\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tconst pkgStripped = getPackageWithoutVersion(pkg as string);\n\t\tlogger.debug(\n\t\t\t`[registerPieElementsFromBundle] Package without version: \"${pkgStripped}\"`,\n\t\t);\n\n\t\tconst elementData = elementModule[pkgStripped];\n\t\tlogger.debug(\n\t\t\t`[registerPieElementsFromBundle] elementData result:`,\n\t\t\telementData ? \"FOUND\" : \"UNDEFINED\",\n\t\t);\n\n\t\tif (!elementData) {\n\t\t\tlogger.error(\n\t\t\t\t`[registerPieElementsFromBundle] ❌ Package \"${pkgStripped}\" not found in bundle!`,\n\t\t\t);\n\t\t\tlogger.error(\n\t\t\t\t`[registerPieElementsFromBundle] Lookup key: \"${pkgStripped}\"`,\n\t\t\t);\n\t\t\tlogger.error(\n\t\t\t\t`[registerPieElementsFromBundle] Available packages:`,\n\t\t\t\tObject.keys(elementModule),\n\t\t\t);\n\t\t\tthrow new Error(\n\t\t\t\t`pie ${pkgStripped} not found in ${Object.keys(elementModule)}`,\n\t\t\t);\n\t\t}\n\n\t\tlogger.debug(\n\t\t\t`[registerPieElementsFromBundle] elementData for ${pkgStripped}:`,\n\t\t\t{\n\t\t\t\thasController: !!elementData.controller,\n\t\t\t\thasElement: !!elementData.Element,\n\t\t\t\thasConfig: !!elementData.config,\n\t\t\t\tcontrollerKeys: elementData.controller\n\t\t\t\t\t? Object.keys(elementData.controller)\n\t\t\t\t\t: [],\n\t\t\t\tbundleType: options.bundleType,\n\t\t\t},\n\t\t);\n\n\t\t// Validate controller presence based on bundle type\n\t\tif (!elementData.controller) {\n\t\t\tif (options.bundleType === BundleType.clientPlayer) {\n\t\t\t\tlogger.error(\n\t\t\t\t\t`[registerPieElementsFromBundle] ❌ CRITICAL: No controller found for ${pkgStripped}!`,\n\t\t\t\t);\n\t\t\t\tlogger.error(\n\t\t\t\t\t`[registerPieElementsFromBundle] Bundle type: ${options.bundleType} (controllers required)`,\n\t\t\t\t);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`No controller found for ${pkgStripped}. client-player.js bundles MUST include controllers!`,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tlogger.debug(\n\t\t\t\t\t`[registerPieElementsFromBundle] ℹ️ No controller found for ${pkgStripped} - using server-processed models (player.js bundle)`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\t{\n\t\t\t// Register the element in our registry\n\t\t\tlogger.debug(\n\t\t\t\t`[registerPieElementsFromBundle] Registering ${elName} in registry${\n\t\t\t\t\telementData.controller\n\t\t\t\t\t\t? \" with controller\"\n\t\t\t\t\t\t: \" (no controller - server-processed models)\"\n\t\t\t\t}`,\n\t\t\t);\n\t\t\tregistry[elementTagName] = {\n\t\t\t\tpackage: pkg as string,\n\t\t\t\tstatus: Status.loading,\n\t\t\t\ttagName: elementTagName,\n\t\t\t\tcontroller: elementData.controller || null,\n\t\t\t\tconfig: elementData.config,\n\t\t\t\tbundleType: options.bundleType,\n\t\t\t};\n\n\t\t\tif (isCustomElementConstructor(elementData.Element)) {\n\t\t\t\tdefineCustomElementSafely(\n\t\t\t\t\telementTagName,\n\t\t\t\t\telementData.Element,\n\t\t\t\t\t`element tag in config.elements for ${String(pkg)}`,\n\t\t\t\t);\n\n\t\t\t\t// Initialize existing elements\n\t\t\t\tconst searchRoot = options.container || document;\n\t\t\t\tconst elements = searchRoot.querySelectorAll(elementTagName);\n\t\t\t\tlogger.debug(\n\t\t\t\t\t`[registerPieElementsFromBundle] Found ${elements.length} elements for tag '${elementTagName}'`,\n\t\t\t\t);\n\n\t\t\t\telements.forEach((el) => {\n\t\t\t\t\tinitializePieElement(el as PieElement, {\n\t\t\t\t\t\tconfig,\n\t\t\t\t\t\tsession,\n\t\t\t\t\t\tenv: options.env,\n\t\t\t\t\t\teventListeners: options.eventListeners?.[elementTagName],\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\t\t// Update registry status\n\t\t\t\tregistry[elementTagName] = {\n\t\t\t\t\t...registry[elementTagName],\n\t\t\t\t\tstatus: Status.loaded,\n\t\t\t\t};\n\n\t\t\t\tpromises.push(\n\t\t\t\t\tcustomElements.whenDefined(elementTagName).then(() => {\n\t\t\t\t\t\tlogger.debug(\n\t\t\t\t\t\t\t\"[registerPieElementsFromBundle] defined custom PIE element: %s\",\n\t\t\t\t\t\t\telementTagName,\n\t\t\t\t\t\t);\n\t\t\t\t\t}),\n\t\t\t\t);\n\n\t\t\t\t// Setup MutationObserver that uses current context (only once)\n\t\t\t\tif (!window._pieElementObserver) {\n\t\t\t\t\twindow._pieElementObserver = new MutationObserver((mutations) => {\n\t\t\t\t\t\t// Use current context from window instead of stale closure\n\t\t\t\t\t\tconst context = window._pieCurrentContext;\n\t\t\t\t\t\tif (!context) {\n\t\t\t\t\t\t\tlogger.warn(\"[MutationObserver] No current context available\");\n\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tmutations.forEach((mutation) => {\n\t\t\t\t\t\t\tif (mutation.type === \"childList\") {\n\t\t\t\t\t\t\t\tmutation.addedNodes.forEach((node) => {\n\t\t\t\t\t\t\t\t\tif (node.nodeType === Node.ELEMENT_NODE) {\n\t\t\t\t\t\t\t\t\t\tif (!isNodeWithinContainer(node, context.container)) {\n\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tconst tagName = (node as Element).tagName.toLowerCase();\n\t\t\t\t\t\t\t\t\t\tif (registry[tagName]) {\n\t\t\t\t\t\t\t\t\t\t\tinitializePieElement(node as PieElement, {\n\t\t\t\t\t\t\t\t\t\t\t\tconfig: context.config,\n\t\t\t\t\t\t\t\t\t\t\t\tsession: context.session,\n\t\t\t\t\t\t\t\t\t\t\t\tenv: context.env,\n\t\t\t\t\t\t\t\t\t\t\t\teventListeners: options.eventListeners?.[tagName],\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t// Check children of added nodes\n\t\t\t\t\t\t\t\t\t\t(node as Element)\n\t\t\t\t\t\t\t\t\t\t\t.querySelectorAll(\"*\")\n\t\t\t\t\t\t\t\t\t\t\t.forEach((childNode) => {\n\t\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t\t!isNodeWithinContainer(childNode, context.container)\n\t\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\tconst childTagName = childNode.tagName.toLowerCase();\n\t\t\t\t\t\t\t\t\t\t\t\tif (registry[childTagName]) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tinitializePieElement(childNode as PieElement, {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tconfig: context.config,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsession: context.session,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tenv: context.env,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\teventListeners:\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\toptions.eventListeners?.[childTagName],\n\t\t\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\n\t\t\t\t\twindow._pieElementObserver.observe(document.body, {\n\t\t\t\t\t\tchildList: true,\n\t\t\t\t\t\tsubtree: true,\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\t// Handle editor elements if needed\n\t\t\t\tif (options.bundleType === BundleType.editor) {\n\t\t\t\t\tif (isCustomElementConstructor(elementData.Configure)) {\n\t\t\t\t\t\tconst editorElName = getEditorElementTagName(\n\t\t\t\t\t\t\telementTagName,\n\t\t\t\t\t\t\tString(pkg),\n\t\t\t\t\t\t);\n\t\t\t\t\t\tdefineCustomElementSafely(\n\t\t\t\t\t\t\teditorElName,\n\t\t\t\t\t\t\telementData.Configure,\n\t\t\t\t\t\t\t`editor element tag for ${String(pkg)}`,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tpromises.push(\n\t\t\t\t\t\t\tcustomElements.whenDefined(editorElName).then(() => {\n\t\t\t\t\t\t\t\tlogger.debug(\n\t\t\t\t\t\t\t\t\t`[registerPieElementsFromBundle] defined custom PIE editor element: ${editorElName}`,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tlogger.error(\n\t\t\t\t\t\t\t`[registerPieElementsFromBundle] pie.Configure for ${pkgStripped} is not a valid custom element constructor.`,\n\t\t\t\t\t\t\telementData.configure,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tlogger.error(\n\t\t\t\t\t`[registerPieElementsFromBundle] pie.Element for ${pkgStripped} is not a valid custom element constructor.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t});\n\n\treturn promises;\n};\n\n/**\n * Initialize PIE elements from a bundle that may already be loaded.\n *\n * `window.pie` is the IIFE bundle-loading global populated by\n * `loadPieModule` / `loadBundleFromString`. When the host loaded the\n * bundle through the deep `ElementLoader` primitive instead — as\n * `pie-section-player` does — the global is irrelevant: the loader\n * registers tags directly with `customElements`, so this function only\n * needs to bind models/sessions to whatever is already registered.\n *\n * Behavior:\n * - `window.pie` available → register any new tags from the bundle and\n * update bindings for already-registered tags.\n * - `window.pie` missing → fall back to the update-only path. Tags that\n * are already registered get their model/session updated; tags that\n * are not yet registered are logged at `warn` and left alone — the\n * host's loader is expected to register them imminently, after which\n * the existing `MutationObserver` / `updatePieElements` flow binds\n * them on the next reactive pass.\n *\n * The original blanket `window.pie not found; was the bundle inlined\n * correctly?` error has been removed: in the section-player + item-player\n * composition it produced a confusing red stack trace for a routine\n * timing condition that the host already handles. Genuine failures\n * (bundle not loaded by *anyone*) still surface — every unregistered tag\n * gets its own warning, and `updatePieElements` later reports any tag\n * that never resolves.\n */\nexport const initializePiesFromLoadedBundle = (\n\tconfig: ConfigEntity,\n\tsession: any[],\n\topts: LoadPieElementsOptions = {},\n): void => {\n\tconst registry = pieRegistry();\n\tconst options = mergeObjectsIgnoringNullUndefined(defaultOptions, opts);\n\n\tif (isPieAvailable(window)) {\n\t\tlogger.debug(\"[initializePiesFromLoadedBundle] window.pie available\");\n\t\tconst elementModule = window.pie.default;\n\t\tregisterPieElementsFromBundle(\n\t\t\telementModule,\n\t\t\tconfig,\n\t\t\tsession,\n\t\t\tregistry,\n\t\t\toptions,\n\t\t);\n\t\treturn;\n\t}\n\n\tlogger.debug(\n\t\t\"[initializePiesFromLoadedBundle] window.pie not present; using update-only path. Already-registered tags will be bound now; missing tags are expected to be registered by the host's loader and will bind on the next update pass.\",\n\t);\n\tregisterPieElementsFromBundle(null, config, session, registry, options);\n};\n\n/**\n * Load a PIE bundle from a URL and initialize elements\n */\nexport const loadPieModule = async (\n\tconfig: ConfigEntity,\n\tsession: any[],\n\topts: LoadPieElementsOptions = {},\n): Promise<{\n\tsession: any[];\n}> => {\n\tif (!session) {\n\t\tthrow new Error(\"session is required\");\n\t}\n\n\t// Initialize math-rendering module (required by PIE elements)\n\tawait initializeMathRendering();\n\n\tconst registry = pieRegistry();\n\tconst options = mergeObjectsIgnoringNullUndefined(defaultOptions, opts);\n\tconst url = opts.bundleUrl || getPieElementBundlesUrl(config, options);\n\tconst script = document.createElement(\"script\");\n\tscript.src = url;\n\tscript.defer = true;\n\tscript.onerror = () => {\n\t\tthrow new Error(`failed to load script: ${url}`);\n\t};\n\n\tconst loadPromise = new Promise<void>((loadResolve) => {\n\t\tscript.addEventListener(\"load\", () => {\n\t\t\tlogger.debug(\"[loadPieModule] Script loaded from:\", url);\n\t\t\tif (isPieAvailable(window)) {\n\t\t\t\tlogger.debug(\"[loadPieModule] window.pie available\");\n\t\t\t\tconst elementModule = window.pie.default;\n\n\t\t\t\t// Use shared registration logic (returns array of promises)\n\t\t\t\tconst registrationPromises = registerPieElementsFromBundle(\n\t\t\t\t\telementModule,\n\t\t\t\t\tconfig,\n\t\t\t\t\tsession,\n\t\t\t\t\tregistry,\n\t\t\t\t\toptions,\n\t\t\t\t);\n\n\t\t\t\t// Wait for all element definitions to complete\n\t\t\t\tPromise.all(registrationPromises).then(() => loadResolve());\n\t\t\t} else {\n\t\t\t\tlogger.error(\n\t\t\t\t\t\"[loadPieModule] pie var not found; is %s a proper PIE IIFE module?\",\n\t\t\t\t\turl,\n\t\t\t\t);\n\t\t\t\tloadResolve();\n\t\t\t}\n\t\t});\n\t});\n\n\tdocument.head.appendChild(script);\n\tawait loadPromise;\n\treturn { session };\n};\n\n/**\n * Load a PIE bundle from a JavaScript string into window.pie (IIFE bundles only)\n * This only registers elements and controllers - does NOT initialize them.\n * For initialization, use initializePiesFromLoadedBundle after loading.\n */\nexport const loadBundleFromString = async (bundleJs: string): Promise<void> => {\n\tawait initializeMathRendering();\n\tawait withBlobBundleUrl(\n\t\tbundleJs,\n\t\t{ stripSourceMapComment: true },\n\t\tasync (bundleUrl) => {\n\t\t\t// Create a script tag to execute the bundle\n\t\t\tconst script = document.createElement(\"script\");\n\t\t\tscript.src = bundleUrl;\n\t\t\tscript.type = \"text/javascript\"; // IIFE bundles are standard JS\n\n\t\t\t// Wait for script to load\n\t\t\tawait new Promise<void>((resolve, reject) => {\n\t\t\t\tscript.onload = () => resolve();\n\t\t\t\tscript.onerror = () => reject(new Error(\"Failed to load bundle\"));\n\t\t\t\tdocument.head.appendChild(script);\n\t\t\t});\n\n\t\t\tlogger.debug(\"[loadBundleFromString] Bundle loaded into window.pie\");\n\t\t},\n\t);\n};\n\n/**\n * Load a PIE bundle from a JavaScript string and initialize elements\n * Convenience wrapper around loadBundleFromString + loadPieModule\n */\nexport const loadPieModuleFromString = async (\n\tbundleJs: string,\n\tconfig: ConfigEntity,\n\tsession: any[],\n\topts: LoadPieElementsOptions = {},\n): Promise<void> => {\n\tawait withBlobBundleUrl(bundleJs, {}, async (bundleUrl) => {\n\t\t// Use existing loadPieModule with the blob URL\n\t\tawait loadPieModule(config, session, { ...opts, bundleUrl });\n\t});\n};\n\nconst withBlobBundleUrl = async <T>(\n\tbundleJs: string,\n\toptions: { stripSourceMapComment?: boolean },\n\trun: (bundleUrl: string) => Promise<T>,\n): Promise<T> => {\n\tconst source = options.stripSourceMapComment\n\t\t? bundleJs.replace(/\\/\\/# sourceMappingURL=.*$/m, \"\")\n\t\t: bundleJs;\n\tconst blob = new Blob([source], { type: \"application/javascript\" });\n\tconst bundleUrl = URL.createObjectURL(blob);\n\ttry {\n\t\treturn await run(bundleUrl);\n\t} finally {\n\t\tURL.revokeObjectURL(bundleUrl);\n\t}\n};\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation-event-bridge.js","sourceRoot":"","sources":["../../src/pie/instrumentation-event-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAGlF,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEpE,MAAM,MAAM,GAAG,eAAe,CAAC,8BAA8B,EAAE,GAAG,EAAE,CACnE,oBAAoB,EAAE,CACtB,CAAC;AAaF,SAAS,oBAAoB,CAAC,MAAe;IAC5C,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC1C,OAAO,MAAiC,CAAC;IAC1C,CAAC;IACD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QACnC,OAAO,EAAE,CAAC;IACX,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC;AAED,SAAS,mBAAmB,CAAC,SAAiB;IAC7C,MAAM,CAAC,IAAI,CACV,+BAA+B,SAAS,wFAAwF,CAChI,CAAC;AACH,CAAC;AAED,SAAS,gBAAgB,CAAC,IAKzB;IACA,IAAI,CAAC;QACJ,IAAI,CAAC,QAAQ,CAAC,UAAU,CACvB,IAAI,CAAC,KAAK,YAAY,KAAK;YAC1B,CAAC,CAAC,IAAI,CAAC,KAAK;YACZ,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,IAAI,sCAAsC,CAAC,CAAC,EAC1E;YACC,SAAS,EAAE,IAAI,CAAC,SAAS;YACzB,SAAS,EAAE,4BAA4B;YACvC,eAAe,EAAE,IAAI,CAAC,eAAe;SACrC,CACD,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACR,0EAA0E;IAC3E,CAAC;AACF,CAAC;AAED,MAAM,UAAU,gCAAgC,CAC/C,I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AAC,CAAC;YACJ,CAAC;QACF,CAAC,CAAC;QAEF,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,OAAO,CAAC,eAAe,EAAE,OAAwB,CAAC,CAAC;QAC9E,eAAe,CAAC,IAAI,CAAC,GAAG,EAAE;YACzB,IAAI,CAAC,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC,eAAe,EAAE,OAAwB,CAAC,CAAC;QACnF,CAAC,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,GAAG,EAAE;QACX,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;YAC9C,cAAc,EAAE,CAAC;QAClB,CAAC;IACF,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { isInstrumentationProvider } from \"../instrumentation/provider-guards.js\";\nimport type { InstrumentationProvider } from \"../instrumentation/types.js\";\nimport type { InstrumentationEventMapping } from \"./instrumentation-event-map.js\";\nimport { createPieLogger, isGlobalDebugEnabled } from \"./logger.js\";\n\nconst logger = createPieLogger(\"instrumentation-event-bridge\", () =>\n\tisGlobalDebugEnabled(),\n);\n\nexport type AttachInstrumentationEventBridgeArgs = {\n\thost: EventTarget | null | undefined;\n\tinstrumentationProvider?: unknown;\n\tcomponent: string;\n\teventMap: InstrumentationEventMapping[];\n\tstaticAttributes?: Record<string, unknown>;\n\tdebug?: boolean;\n\tdedupeWindowMs?: number;\n\tshouldTrackEvent?: (event: Event) => boolean;\n};\n\nfunction normalizeEventDetail(detail: unknown): Record<string, unknown> {\n\tif (detail && typeof detail === \"object\") {\n\t\treturn detail as Record<string, unknown>;\n\t}\n\tif (typeof detail === \"undefined\") {\n\t\treturn {};\n\t}\n\treturn { value: detail };\n}\n\nfunction warnInvalidProvider(component: string): void {\n\tlogger.warn(\n\t\t`[InstrumentationEventBridge:${component}] Ignoring invalid instrumentation provider; expected InstrumentationProvider contract`,\n\t);\n}\n\nfunction trackBridgeError(args: {\n\tprovider: InstrumentationProvider;\n\tcomponent: string;\n\terror: unknown;\n\tsourceEventName: string;\n}): void {\n\ttry {\n\t\targs.provider.trackError(\n\t\t\targs.error instanceof Error\n\t\t\t\t? args.error\n\t\t\t\t: new Error(String(args.error ?? \"Unknown instrumentation bridge error\")),\n\t\t\t{\n\t\t\t\tcomponent: args.component,\n\t\t\t\terrorType: \"InstrumentationBridgeError\",\n\t\t\t\tsourceEventName: args.sourceEventName,\n\t\t\t},\n\t\t);\n\t} catch {\n\t\t// Avoid recursive failures while reporting instrumentation bridge errors.\n\t}\n}\n\nexport function attachInstrumentationEventBridge(\n\targs: AttachInstrumentationEventBridgeArgs,\n): () => void {\n\tif (!args.host || !args.eventMap.length) return () => {};\n\tif (!args.instrumentationProvider) return () => {};\n\tif (!isInstrumentationProvider(args.instrumentationProvider)) {\n\t\tif (args.debug) {\n\t\t\twarnInvalidProvider(args.component);\n\t\t}\n\t\treturn () => {};\n\t}\n\n\tconst provider = args.instrumentationProvider;\n\tconst removeListeners: Array<() => void> = [];\n\tconst dedupeWindowMs = Math.max(0, args.dedupeWindowMs ?? 0);\n\tconst recentEventMap = new Map<string, number>();\n\n\tconst computeDedupeKey = (\n\t\tmapping: InstrumentationEventMapping,\n\t\tdetail: Record<string, unknown>,\n\t): string => {\n\t\tconst summary = [\n\t\t\tdetail.assessmentId,\n\t\t\tdetail.sectionId,\n\t\t\tdetail.attemptId,\n\t\t\tdetail.itemId,\n\t\t\tdetail.canonicalItemId,\n\t\t\tdetail.sourceRuntimeId,\n\t\t]\n\t\t\t.map((value) => String(value ?? \"\"))\n\t\t\t.join(\"|\");\n\t\treturn `${mapping.instrumentationEventName}|${summary}`;\n\t};\n\n\tfor (const mapping of args.eventMap) {\n\t\tconst handler = (event: Event) => {\n\t\t\ttry {\n\t\t\t\tif (!provider.isReady()) return;\n\t\t\t\tif (args.shouldTrackEvent && !args.shouldTrackEvent(event)) return;\n\t\t\t\tconst customEvent = event as CustomEvent<unknown>;\n\t\t\t\tconst detail = normalizeEventDetail(customEvent.detail);\n\t\t\t\tconst timestamp = new Date().toISOString();\n\t\t\t\tconst mergedAttributes = {\n\t\t\t\t\t...detail,\n\t\t\t\t\t...args.staticAttributes,\n\t\t\t\t\tcomponent: args.component,\n\t\t\t\t\tsourceEventName: mapping.sourceEventName,\n\t\t\t\t\ttimestamp,\n\t\t\t\t};\n\t\t\t\tif (dedupeWindowMs > 0) {\n\t\t\t\t\tconst now = Date.now();\n\t\t\t\t\tconst dedupeKey = computeDedupeKey(mapping, mergedAttributes);\n\t\t\t\t\tconst previousTimestamp = recentEventMap.get(dedupeKey);\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof previousTimestamp === \"number\" &&\n\t\t\t\t\t\tnow - previousTimestamp < dedupeWindowMs\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\trecentEventMap.set(dedupeKey, now);\n\t\t\t\t}\n\t\t\t\tprovider.trackEvent(mapping.instrumentationEventName, {\n\t\t\t\t\t...mergedAttributes,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\ttrackBridgeError({\n\t\t\t\t\tprovider,\n\t\t\t\t\tcomponent: args.component,\n\t\t\t\t\terror,\n\t\t\t\t\tsourceEventName: mapping.sourceEventName,\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\n\t\targs.host.addEventListener(mapping.sourceEventName, handler as EventListener);\n\t\tremoveListeners.push(() => {\n\t\t\targs.host?.removeEventListener(mapping.sourceEventName, handler as EventListener);\n\t\t});\n\t}\n\n\treturn () => {\n\t\tfor (const removeListener of removeListeners) {\n\t\t\tremoveListener();\n\t\t}\n\t};\n}\n"]}
1
+ {"version":3,"file":"instrumentation-event-bridge.js","sourceRoot":"","sources":["../../src/pie/instrumentation-event-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAGlF,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEpE,MAAM,MAAM,GAAG,eAAe,CAAC,8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X,KAAK,MAAM,cAAc,IAAI,eAAe,EAAE,CAAC;YAC9C,cAAc,EAAE,CAAC;QAClB,CAAC;IACF,CAAC,CAAC;AACH,CAAC","sourcesContent":["import { isInstrumentationProvider } from \"../instrumentation/provider-guards.js\";\nimport type { InstrumentationProvider } from \"../instrumentation/types.js\";\nimport type { InstrumentationEventMapping } from \"./instrumentation-event-map.js\";\nimport { createPieLogger, isGlobalDebugEnabled } from \"./logger.js\";\n\nconst logger = createPieLogger(\"instrumentation-event-bridge\", () =>\n\tisGlobalDebugEnabled(),\n);\n\nexport type AttachInstrumentationEventBridgeArgs = {\n\thost: EventTarget | null | undefined;\n\tinstrumentationProvider?: unknown;\n\tcomponent: string;\n\teventMap: InstrumentationEventMapping[];\n\tstaticAttributes?: Record<string, unknown>;\n\tdebug?: boolean;\n\tdedupeWindowMs?: number;\n\tshouldTrackEvent?: (event: Event) => boolean;\n};\n\nfunction normalizeEventDetail(detail: unknown): Record<string, unknown> {\n\tif (detail && typeof detail === \"object\") {\n\t\treturn detail as Record<string, unknown>;\n\t}\n\tif (typeof detail === \"undefined\") {\n\t\treturn {};\n\t}\n\treturn { value: detail };\n}\n\nfunction warnInvalidProvider(component: string): void {\n\tlogger.warn(\n\t\t`[InstrumentationEventBridge:${component}] Ignoring invalid instrumentation provider; expected InstrumentationProvider contract`,\n\t);\n}\n\nfunction trackBridgeError(args: {\n\tprovider: InstrumentationProvider;\n\tcomponent: string;\n\terror: unknown;\n\tsourceEventName: string;\n}): void {\n\ttry {\n\t\targs.provider.trackError(\n\t\t\targs.error instanceof Error\n\t\t\t\t? args.error\n\t\t\t\t: new Error(\n\t\t\t\t\t\tString(args.error ?? \"Unknown instrumentation bridge error\"),\n\t\t\t\t\t),\n\t\t\t{\n\t\t\t\tcomponent: args.component,\n\t\t\t\terrorType: \"InstrumentationBridgeError\",\n\t\t\t\tsourceEventName: args.sourceEventName,\n\t\t\t},\n\t\t);\n\t} catch {\n\t\t// Avoid recursive failures while reporting instrumentation bridge errors.\n\t}\n}\n\nexport function attachInstrumentationEventBridge(\n\targs: AttachInstrumentationEventBridgeArgs,\n): () => void {\n\tif (!args.host || !args.eventMap.length) return () => {};\n\tif (!args.instrumentationProvider) return () => {};\n\tif (!isInstrumentationProvider(args.instrumentationProvider)) {\n\t\tif (args.debug) {\n\t\t\twarnInvalidProvider(args.component);\n\t\t}\n\t\treturn () => {};\n\t}\n\n\tconst provider = args.instrumentationProvider;\n\tconst removeListeners: Array<() => void> = [];\n\tconst dedupeWindowMs = Math.max(0, args.dedupeWindowMs ?? 0);\n\tconst recentEventMap = new Map<string, number>();\n\n\tconst computeDedupeKey = (\n\t\tmapping: InstrumentationEventMapping,\n\t\tdetail: Record<string, unknown>,\n\t): string => {\n\t\tconst summary = [\n\t\t\tdetail.assessmentId,\n\t\t\tdetail.sectionId,\n\t\t\tdetail.attemptId,\n\t\t\tdetail.itemId,\n\t\t\tdetail.canonicalItemId,\n\t\t\tdetail.sourceRuntimeId,\n\t\t]\n\t\t\t.map((value) => String(value ?? \"\"))\n\t\t\t.join(\"|\");\n\t\treturn `${mapping.instrumentationEventName}|${summary}`;\n\t};\n\n\tfor (const mapping of args.eventMap) {\n\t\tconst handler = (event: Event) => {\n\t\t\ttry {\n\t\t\t\tif (!provider.isReady()) return;\n\t\t\t\tif (args.shouldTrackEvent && !args.shouldTrackEvent(event)) return;\n\t\t\t\tconst customEvent = event as CustomEvent<unknown>;\n\t\t\t\tconst detail = normalizeEventDetail(customEvent.detail);\n\t\t\t\tconst timestamp = new Date().toISOString();\n\t\t\t\tconst mergedAttributes = {\n\t\t\t\t\t...detail,\n\t\t\t\t\t...args.staticAttributes,\n\t\t\t\t\tcomponent: args.component,\n\t\t\t\t\tsourceEventName: mapping.sourceEventName,\n\t\t\t\t\ttimestamp,\n\t\t\t\t};\n\t\t\t\tif (dedupeWindowMs > 0) {\n\t\t\t\t\tconst now = Date.now();\n\t\t\t\t\tconst dedupeKey = computeDedupeKey(mapping, mergedAttributes);\n\t\t\t\t\tconst previousTimestamp = recentEventMap.get(dedupeKey);\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof previousTimestamp === \"number\" &&\n\t\t\t\t\t\tnow - previousTimestamp < dedupeWindowMs\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\trecentEventMap.set(dedupeKey, now);\n\t\t\t\t}\n\t\t\t\tprovider.trackEvent(mapping.instrumentationEventName, {\n\t\t\t\t\t...mergedAttributes,\n\t\t\t\t});\n\t\t\t} catch (error) {\n\t\t\t\ttrackBridgeError({\n\t\t\t\t\tprovider,\n\t\t\t\t\tcomponent: args.component,\n\t\t\t\t\terror,\n\t\t\t\t\tsourceEventName: mapping.sourceEventName,\n\t\t\t\t});\n\t\t\t}\n\t\t};\n\n\t\targs.host.addEventListener(\n\t\t\tmapping.sourceEventName,\n\t\t\thandler as EventListener,\n\t\t);\n\t\tremoveListeners.push(() => {\n\t\t\targs.host?.removeEventListener(\n\t\t\t\tmapping.sourceEventName,\n\t\t\t\thandler as EventListener,\n\t\t\t);\n\t\t});\n\t}\n\n\treturn () => {\n\t\tfor (const removeListener of removeListeners) {\n\t\t\tremoveListener();\n\t\t}\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation-event-map.js","sourceRoot":"","sources":["../../src/pie/instrumentation-event-map.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,iCAAiC,GAAkC;IAC/E,mEAAmE;IACnE,uEAAuE;IACvE,sEAAsE;IACtE,qEAAqE;IACrE,gEAAgE;IAChE,uEAAuE;IACvE,8CAA8C;IAC9C;QACC,eAAe,EAAE,kBAAkB;QACnC,wBAAwB,EAAE,0BAA0B;KACpD;IACD;QACC,eAAe,EAAE,eAAe;QAChC,wBAAwB,EAAE,2BAA2B;KACrD;IACD;QACC,eAAe,EAAE,mBAAmB;QACpC,wBAAwB,EAAE,+BAA+B;KACzD;IACD;QACC,eAAe,EAAE,eAAe;QAChC,w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AAqC;QACtD,wBAAwB,EAAE,yCAAyC;KACnE;IACD;QACC,eAAe,EAAE,kBAAkB;QACnC,wBAAwB,EAAE,sBAAsB;KAChD;CACD,CAAC","sourcesContent":["export type InstrumentationEventMapping = {\n\tsourceEventName: string;\n\tinstrumentationEventName: string;\n};\n\nexport const TOOLKIT_INSTRUMENTATION_EVENT_MAP: InstrumentationEventMapping[] = [\n\t// M6 canonical readiness vocabulary. The four-stage canonical list\n\t// (`composed`, `engine-ready`, `interactive`, `disposed`) is identical\n\t// across the toolkit CE and the layout CEs — the M6 retro removed the\n\t// `attached`, `runtime-bound`, and `ui-rendered` stages because they\n\t// had zero internal or external consumers. Hosts listen for the\n\t// DOM-prefixed name directly (`pie-stage-change`); the instrumentation\n\t// bridge forwards the same name to telemetry.\n\t{\n\t\tsourceEventName: \"pie-stage-change\",\n\t\tinstrumentationEventName: \"pie-toolkit-stage-change\",\n\t},\n\t{\n\t\tsourceEventName: \"runtime-owned\",\n\t\tinstrumentationEventName: \"pie-toolkit-runtime-owned\",\n\t},\n\t{\n\t\tsourceEventName: \"runtime-inherited\",\n\t\tinstrumentationEventName: \"pie-toolkit-runtime-inherited\",\n\t},\n\t{\n\t\tsourceEventName: \"toolkit-ready\",\n\t\tinstrumentationEventName: \"pie-toolkit-ready\",\n\t},\n\t{\n\t\tsourceEventName: \"section-ready\",\n\t\tinstrumentationEventName: \"pie-toolkit-section-ready\",\n\t},\n\t{\n\t\tsourceEventName: \"framework-error\",\n\t\tinstrumentationEventName: \"pie-toolkit-framework-error\",\n\t},\n];\n\nexport const SECTION_INSTRUMENTATION_EVENT_MAP: InstrumentationEventMapping[] = [\n\t// M6 canonical readiness vocabulary. Hosts listen for the DOM-prefixed\n\t// names directly (`pie-stage-change`, `pie-loading-complete`); the\n\t// instrumentation bridge forwards the same names to telemetry. The\n\t// readiness alias mappings (`readiness-change`, `interaction-ready`,\n\t// `ready`) and the `section-controller-ready` mapping were removed\n\t// alongside their DOM-event surfaces.\n\t{\n\t\tsourceEventName: \"pie-stage-change\",\n\t\tinstrumentationEventName: \"pie-section-stage-change\",\n\t},\n\t{\n\t\tsourceEventName: \"pie-loading-complete\",\n\t\tinstrumentationEventName: \"pie-section-loading-complete\",\n\t},\n\t{\n\t\tsourceEventName: \"session-changed\",\n\t\tinstrumentationEventName: \"pie-section-session-changed\",\n\t},\n\t{\n\t\tsourceEventName: \"composition-changed\",\n\t\tinstrumentationEventName: \"pie-section-composition-changed\",\n\t},\n\t{\n\t\tsourceEventName: \"framework-error\",\n\t\tinstrumentationEventName: \"pie-section-framework-error\",\n\t},\n\t{\n\t\tsourceEventName: \"element-preload-retry\",\n\t\tinstrumentationEventName: \"pie-section-element-preload-retry\",\n\t},\n\t{\n\t\tsourceEventName: \"element-preload-error\",\n\t\tinstrumentationEventName: \"pie-section-element-preload-error\",\n\t},\n];\n\nexport const ASSESSMENT_INSTRUMENTATION_EVENT_MAP: InstrumentationEventMapping[] = [\n\t{\n\t\tsourceEventName: \"assessment-controller-ready\",\n\t\tinstrumentationEventName: \"pie-assessment-controller-ready\",\n\t},\n\t{\n\t\tsourceEventName: \"assessment-navigation-requested\",\n\t\tinstrumentationEventName: \"pie-assessment-navigation-requested\",\n\t},\n\t{\n\t\tsourceEventName: \"assessment-route-changed\",\n\t\tinstrumentationEventName: \"pie-assessment-route-changed\",\n\t},\n\t{\n\t\tsourceEventName: \"assessment-session-applied\",\n\t\tinstrumentationEventName: \"pie-assessment-session-applied\",\n\t},\n\t{\n\t\tsourceEventName: \"assessment-session-changed\",\n\t\tinstrumentationEventName: \"pie-assessment-session-changed\",\n\t},\n\t{\n\t\tsourceEventName: \"assessment-progress-changed\",\n\t\tinstrumentationEventName: \"pie-assessment-progress-changed\",\n\t},\n\t{\n\t\tsourceEventName: \"assessment-submission-state-changed\",\n\t\tinstrumentationEventName: \"pie-assessment-submission-state-changed\",\n\t},\n\t{\n\t\tsourceEventName: \"assessment-error\",\n\t\tinstrumentationEventName: \"pie-assessment-error\",\n\t},\n];\n"]}
1
+ {"version":3,"file":"instrumentation-event-map.js","sourceRoot":"","sources":["../../src/pie/instrumentation-event-map.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,iCAAiC,GAC7C;IACC,mEAAmE;IACnE,uEAAuE;IACvE,sEAAsE;IACtE,qEAAqE;IACrE,gEAAgE;IAChE,uEAAuE;IACvE,8CAA8C;IAC9C;QACC,eAAe,EAAE,kBAAkB;QACnC,wBAAwB,EAAE,0BAA0B;KACpD;IACD;QACC,eAAe,EAAE,eAAe;QAChC,wBAAwB,EAAE,2BAA2B;KACrD;IACD;QACC,eAAe,EAAE,mBAAmB;QACpC,wBAAwB,EAAE,+BAA+B;KACzD;IACD;QACC,eAAe,EAAE,eAAe;QAChC,wBAAwB,EAAE,mBAAmB;KAC7C;IACD;QACC,eAAe,EAAE,eAAe;QAChC,wBAAwB,EAAE,2BAA2B;KACrD;IACD;QACC,eAAe,EAAE,iBAAiB;QAClC,wBAAwB,EAAE,6BAA6B;KACvD;CACD,CAAC;AAEH,MAAM,CAAC,MAAM,iCAAiC,GAC7C;IACC,uEAAuE;IACvE,mEAAmE;IACnE,mEAAmE;IACnE,qEAAqE;IACrE,mEAAmE;IACnE,sCAAsC;IACtC;QACC,eAAe,EAAE,kBAAkB;QACnC,wBAAwB,EAAE,0BAA0B;KACpD;IACD;QACC,eAAe,EAAE,sBAAsB;QACvC,wBAAwB,EAAE,8BAA8B;KACxD;IACD;QACC,eAAe,EAAE,iBAAiB;QAClC,wBAAwB,EAAE,6BAA6B;KACvD;IACD;QACC,eAAe,EAAE,qBAAqB;QACtC,wBAAwB,EAAE,iCAAiC;KAC3D;IACD;QACC,eAAe,EAAE,iBAAiB;QAClC,wBAAwB,EAAE,6BAA6B;KACvD;IACD;QACC,eAAe,EAAE,uBAAuB;QACxC,wBAAwB,EAAE,mCAAmC;KAC7D;IACD;QACC,eAAe,EAAE,uBAAuB;QACxC,wBAAwB,EAAE,mCAAmC;KAC7D;CACD,CAAC;AAEH,MAAM,CAAC,MAAM,oCAAoC,GAChD;IACC;QACC,eAAe,EAAE,6BAA6B;QAC9C,wBAAwB,EAAE,iCAAiC;KAC3D;IACD;QACC,eAAe,EAAE,iCAAiC;QAClD,wBAAwB,EAAE,qCAAqC;KAC/D;IACD;QACC,eAAe,EAAE,0BAA0B;QAC3C,wBAAwB,EAAE,8BAA8B;KACxD;IACD;QACC,eAAe,EAAE,4BAA4B;QAC7C,wBAAwB,EAAE,gCAAgC;KAC1D;IACD;QACC,eAAe,EAAE,4BAA4B;QAC7C,wBAAwB,EAAE,gCAAgC;KAC1D;IACD;QACC,eAAe,EAAE,6BAA6B;QAC9C,wBAAwB,EAAE,iCAAiC;KAC3D;IACD;QACC,eAAe,EAAE,qCAAqC;QACtD,wBAAwB,EAAE,yCAAyC;KACnE;IACD;QACC,eAAe,EAAE,kBAAkB;QACnC,wBAAwB,EAAE,sBAAsB;KAChD;CACD,CAAC","sourcesContent":["export type InstrumentationEventMapping = {\n\tsourceEventName: string;\n\tinstrumentationEventName: string;\n};\n\nexport const TOOLKIT_INSTRUMENTATION_EVENT_MAP: InstrumentationEventMapping[] =\n\t[\n\t\t// M6 canonical readiness vocabulary. The four-stage canonical list\n\t\t// (`composed`, `engine-ready`, `interactive`, `disposed`) is identical\n\t\t// across the toolkit CE and the layout CEs — the M6 retro removed the\n\t\t// `attached`, `runtime-bound`, and `ui-rendered` stages because they\n\t\t// had zero internal or external consumers. Hosts listen for the\n\t\t// DOM-prefixed name directly (`pie-stage-change`); the instrumentation\n\t\t// bridge forwards the same name to telemetry.\n\t\t{\n\t\t\tsourceEventName: \"pie-stage-change\",\n\t\t\tinstrumentationEventName: \"pie-toolkit-stage-change\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"runtime-owned\",\n\t\t\tinstrumentationEventName: \"pie-toolkit-runtime-owned\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"runtime-inherited\",\n\t\t\tinstrumentationEventName: \"pie-toolkit-runtime-inherited\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"toolkit-ready\",\n\t\t\tinstrumentationEventName: \"pie-toolkit-ready\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"section-ready\",\n\t\t\tinstrumentationEventName: \"pie-toolkit-section-ready\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"framework-error\",\n\t\t\tinstrumentationEventName: \"pie-toolkit-framework-error\",\n\t\t},\n\t];\n\nexport const SECTION_INSTRUMENTATION_EVENT_MAP: InstrumentationEventMapping[] =\n\t[\n\t\t// M6 canonical readiness vocabulary. Hosts listen for the DOM-prefixed\n\t\t// names directly (`pie-stage-change`, `pie-loading-complete`); the\n\t\t// instrumentation bridge forwards the same names to telemetry. The\n\t\t// readiness alias mappings (`readiness-change`, `interaction-ready`,\n\t\t// `ready`) and the `section-controller-ready` mapping were removed\n\t\t// alongside their DOM-event surfaces.\n\t\t{\n\t\t\tsourceEventName: \"pie-stage-change\",\n\t\t\tinstrumentationEventName: \"pie-section-stage-change\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"pie-loading-complete\",\n\t\t\tinstrumentationEventName: \"pie-section-loading-complete\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"session-changed\",\n\t\t\tinstrumentationEventName: \"pie-section-session-changed\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"composition-changed\",\n\t\t\tinstrumentationEventName: \"pie-section-composition-changed\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"framework-error\",\n\t\t\tinstrumentationEventName: \"pie-section-framework-error\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"element-preload-retry\",\n\t\t\tinstrumentationEventName: \"pie-section-element-preload-retry\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"element-preload-error\",\n\t\t\tinstrumentationEventName: \"pie-section-element-preload-error\",\n\t\t},\n\t];\n\nexport const ASSESSMENT_INSTRUMENTATION_EVENT_MAP: InstrumentationEventMapping[] =\n\t[\n\t\t{\n\t\t\tsourceEventName: \"assessment-controller-ready\",\n\t\t\tinstrumentationEventName: \"pie-assessment-controller-ready\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"assessment-navigation-requested\",\n\t\t\tinstrumentationEventName: \"pie-assessment-navigation-requested\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"assessment-route-changed\",\n\t\t\tinstrumentationEventName: \"pie-assessment-route-changed\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"assessment-session-applied\",\n\t\t\tinstrumentationEventName: \"pie-assessment-session-applied\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"assessment-session-changed\",\n\t\t\tinstrumentationEventName: \"pie-assessment-session-changed\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"assessment-progress-changed\",\n\t\t\tinstrumentationEventName: \"pie-assessment-progress-changed\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"assessment-submission-state-changed\",\n\t\t\tinstrumentationEventName: \"pie-assessment-submission-state-changed\",\n\t\t},\n\t\t{\n\t\t\tsourceEventName: \"assessment-error\",\n\t\t\tinstrumentationEventName: \"pie-assessment-error\",\n\t\t},\n\t];\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"instrumentation-provider-resolution.js","sourceRoot":"","sources":["../../src/pie/instrumentation-provider-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,yBAAyB,EAAE,MAAM,uCAAuC,CAAC;AAClF,OAAO,EAAE,+BAA+B,EAAE,MAAM,iEAAiE,CAAC;AAClH,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAQpE,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAE,KAAuB,CAAC,CAAC,CAAC,EAAE,CAAC;AAC3E,CAAC;AAED,SAAS,mBAAmB,CAAC,UAAmB;IAC/C,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,C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IAAI,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,MAAM,CAAC,IAAI,CACV,GAAG,MAAM,sFAAsF,CAC/F,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import { isInstrumentationProvider } from \"../instrumentation/provider-guards.js\";\nimport { NewRelicInstrumentationProvider } from \"../instrumentation/providers/NewRelicInstrumentationProvider.js\";\nimport { createPieLogger, isGlobalDebugEnabled } from \"./logger.js\";\n\ntype UnknownRecord = Record<string, unknown>;\ntype ProviderCandidate =\n\t| { kind: \"unset\" }\n\t| { kind: \"null\" }\n\t| { kind: \"value\"; value: unknown };\n\nfunction asRecord(value: unknown): UnknownRecord {\n\treturn value && typeof value === \"object\" ? (value as UnknownRecord) : {};\n}\n\nfunction resolveLoaderConfig(playerLike: unknown): UnknownRecord | null {\n\tconst player = asRecord(playerLike);\n\tconst loaderConfig = asRecord(player.loaderConfig);\n\treturn Object.keys(loaderConfig).length > 0 ? loaderConfig : null;\n}\n\nfunction resolveProviderFromLoaderConfig(loaderConfig: UnknownRecord | null): ProviderCandidate {\n\tif (!loaderConfig || !(\"instrumentationProvider\" in loaderConfig)) {\n\t\treturn { kind: \"unset\" };\n\t}\n\tconst provider = loaderConfig.instrumentationProvider;\n\tif (provider === null) return { kind: \"null\" };\n\tif (typeof provider === \"undefined\") return { kind: \"unset\" };\n\treturn { kind: \"value\", value: provider };\n}\n\nfunction resolveTrackPageActionsFromLoaderConfig(\n\tloaderConfig: UnknownRecord | null,\n): boolean | undefined {\n\tif (!loaderConfig || !(\"trackPageActions\" in loaderConfig)) return undefined;\n\tconst trackPageActions = loaderConfig.trackPageActions;\n\treturn typeof trackPageActions === \"boolean\" ? trackPageActions : undefined;\n}\n\nfunction selectProviderCandidate(\n\truntimeCandidate: ProviderCandidate,\n\ttopLevelCandidate: ProviderCandidate,\n): ProviderCandidate {\n\tif (runtimeCandidate.kind === \"value\" || runtimeCandidate.kind === \"null\") {\n\t\treturn runtimeCandidate;\n\t}\n\treturn topLevelCandidate;\n}\n\nlet defaultProvider: NewRelicInstrumentationProvider | undefined;\nconst logger = createPieLogger(\"instrumentation-provider-resolution\", () =>\n\tisGlobalDebugEnabled(),\n);\n\nfunction getDefaultInstrumentationProvider(): NewRelicInstrumentationProvider {\n\tif (!defaultProvider) {\n\t\tdefaultProvider = new NewRelicInstrumentationProvider();\n\t\t// New Relic provider sets readiness based on window.newrelic.\n\t\tvoid defaultProvider.initialize();\n\t}\n\treturn defaultProvider;\n}\n\nexport function resolveInstrumentationProvider(args: {\n\truntimePlayer?: unknown;\n\tplayer?: unknown;\n\tdebug?: boolean;\n\tcomponent?: string;\n}): unknown {\n\tconst runtimeLoaderConfig = resolveLoaderConfig(args.runtimePlayer);\n\tconst topLevelLoaderConfig = resolveLoaderConfig(args.player);\n\tconst runtimeTrackPageActions =\n\t\tresolveTrackPageActionsFromLoaderConfig(runtimeLoaderConfig);\n\tconst topLevelTrackPageActions =\n\t\tresolveTrackPageActionsFromLoaderConfig(topLevelLoaderConfig);\n\tconst trackPageActions =\n\t\truntimeTrackPageActions ?? topLevelTrackPageActions ?? false;\n\tconst candidateProvider = selectProviderCandidate(\n\t\tresolveProviderFromLoaderConfig(runtimeLoaderConfig),\n\t\tresolveProviderFromLoaderConfig(topLevelLoaderConfig),\n\t);\n\tif (candidateProvider.kind === \"null\") return undefined;\n\tif (candidateProvider.kind === \"unset\") {\n\t\treturn trackPageActions ? getDefaultInstrumentationProvider() : undefined;\n\t}\n\tif (isInstrumentationProvider(candidateProvider.value)) {\n\t\treturn candidateProvider.value;\n\t}\n\tif (args.debug) {\n\t\tconst prefix = args.component ? `[${args.component}] ` : \"\";\n\t\tlogger.warn(\n\t\t\t`${prefix}Ignoring invalid instrumentation provider; expected InstrumentationProvider contract`,\n\t\t);\n\t}\n\treturn undefined;\n}\n"]}
1
+ {"version":3,"file":"instrumentation-provider-resolution.js","sourceRoot":"","sources":["../../src/pie/instrumentation-prov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AAiB,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,SAAS,CAAC;IACxD,IAAI,iBAAiB,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;QACxC,OAAO,gBAAgB,CAAC,CAAC,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;IAC3E,CAAC;IACD,IAAI,yBAAyB,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,CAAC;QACxD,OAAO,iBAAiB,CAAC,KAAK,CAAC;IAChC,CAAC;IACD,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;QAChB,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,MAAM,CAAC,IAAI,CACV,GAAG,MAAM,sFAAsF,CAC/F,CAAC;IACH,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import { isInstrumentationProvider } from \"../instrumentation/provider-guards.js\";\nimport { NewRelicInstrumentationProvider } from \"../instrumentation/providers/NewRelicInstrumentationProvider.js\";\nimport { createPieLogger, isGlobalDebugEnabled } from \"./logger.js\";\n\ntype UnknownRecord = Record<string, unknown>;\ntype ProviderCandidate =\n\t| { kind: \"unset\" }\n\t| { kind: \"null\" }\n\t| { kind: \"value\"; value: unknown };\n\nfunction asRecord(value: unknown): UnknownRecord {\n\treturn value && typeof value === \"object\" ? (value as UnknownRecord) : {};\n}\n\nfunction resolveLoaderConfig(playerLike: unknown): UnknownRecord | null {\n\tconst player = asRecord(playerLike);\n\tconst loaderConfig = asRecord(player.loaderConfig);\n\treturn Object.keys(loaderConfig).length > 0 ? loaderConfig : null;\n}\n\nfunction resolveProviderFromLoaderConfig(\n\tloaderConfig: UnknownRecord | null,\n): ProviderCandidate {\n\tif (!loaderConfig || !(\"instrumentationProvider\" in loaderConfig)) {\n\t\treturn { kind: \"unset\" };\n\t}\n\tconst provider = loaderConfig.instrumentationProvider;\n\tif (provider === null) return { kind: \"null\" };\n\tif (typeof provider === \"undefined\") return { kind: \"unset\" };\n\treturn { kind: \"value\", value: provider };\n}\n\nfunction resolveTrackPageActionsFromLoaderConfig(\n\tloaderConfig: UnknownRecord | null,\n): boolean | undefined {\n\tif (!loaderConfig || !(\"trackPageActions\" in loaderConfig)) return undefined;\n\tconst trackPageActions = loaderConfig.trackPageActions;\n\treturn typeof trackPageActions === \"boolean\" ? trackPageActions : undefined;\n}\n\nfunction selectProviderCandidate(\n\truntimeCandidate: ProviderCandidate,\n\ttopLevelCandidate: ProviderCandidate,\n): ProviderCandidate {\n\tif (runtimeCandidate.kind === \"value\" || runtimeCandidate.kind === \"null\") {\n\t\treturn runtimeCandidate;\n\t}\n\treturn topLevelCandidate;\n}\n\nlet defaultProvider: NewRelicInstrumentationProvider | undefined;\nconst logger = createPieLogger(\"instrumentation-provider-resolution\", () =>\n\tisGlobalDebugEnabled(),\n);\n\nfunction getDefaultInstrumentationProvider(): NewRelicInstrumentationProvider {\n\tif (!defaultProvider) {\n\t\tdefaultProvider = new NewRelicInstrumentationProvider();\n\t\t// New Relic provider sets readiness based on window.newrelic.\n\t\tvoid defaultProvider.initialize();\n\t}\n\treturn defaultProvider;\n}\n\nexport function resolveInstrumentationProvider(args: {\n\truntimePlayer?: unknown;\n\tplayer?: unknown;\n\tdebug?: boolean;\n\tcomponent?: string;\n}): unknown {\n\tconst runtimeLoaderConfig = resolveLoaderConfig(args.runtimePlayer);\n\tconst topLevelLoaderConfig = resolveLoaderConfig(args.player);\n\tconst runtimeTrackPageActions =\n\t\tresolveTrackPageActionsFromLoaderConfig(runtimeLoaderConfig);\n\tconst topLevelTrackPageActions =\n\t\tresolveTrackPageActionsFromLoaderConfig(topLevelLoaderConfig);\n\tconst trackPageActions =\n\t\truntimeTrackPageActions ?? topLevelTrackPageActions ?? false;\n\tconst candidateProvider = selectProviderCandidate(\n\t\tresolveProviderFromLoaderConfig(runtimeLoaderConfig),\n\t\tresolveProviderFromLoaderConfig(topLevelLoaderConfig),\n\t);\n\tif (candidateProvider.kind === \"null\") return undefined;\n\tif (candidateProvider.kind === \"unset\") {\n\t\treturn trackPageActions ? getDefaultInstrumentationProvider() : undefined;\n\t}\n\tif (isInstrumentationProvider(candidateProvider.value)) {\n\t\treturn candidateProvider.value;\n\t}\n\tif (args.debug) {\n\t\tconst prefix = args.component ? `[${args.component}] ` : \"\";\n\t\tlogger.warn(\n\t\t\t`${prefix}Ignoring invalid instrumentation provider; expected InstrumentationProvider contract`,\n\t\t);\n\t}\n\treturn undefined;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"item-controller-storage.js","sourceRoot":"","sources":["../../src/pie/item-controller-storage.ts"],"names":[],"mappings":"AAcA,MAAM,OAAO,wBAAwB;IAC5B,KAAK,GAAG,IAAI,GAAG,EAAgC,CAAC;IAExD,IAAI,CAAC,GAAW;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IACpC,CAAC;IAED,IAAI,CAAC,GAAW,EAAE,OAA6B;QAC9C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,GAAW;QAChB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;CACD;AAED,MAAM,OAAO,gCAAgC;IAG5C,IAAI,CAAC,GAAW;QACf,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAC/C,IAAI,CAAC;YACJ,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAC/C,IAAI,CAAC,GAAG;gBAAE,OAAO,IAAI,CAAC;YACtB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC;QAChD,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IAED,IAAI,CAAC,GAAW,EAAE,OAA6B;QAC9C,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAC1C,IAAI,CAAC;YACJ,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7D,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;IAED,KAAK,CAAC,GAAW;QAChB,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAC1C,IAAI,CAAC;YACJ,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACvC,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;CACD","sourcesContent":["export type ItemSessionContainer = {\n\tid: string;\n\tdata: any[];\n};\n\nexport interface ItemSessionStorageStrategy {\n\tload(key: string): ItemSessionContainer | null | Promise<ItemSessionContainer | null>;\n\tsave(\n\t\tkey: string,\n\t\tsession: ItemSessionContainer,\n\t): void | Promise<void>;\n\tclear?(key: string): void | Promise<void>;\n}\n\nexport class MemoryItemSessionStorage implements ItemSessionStorageStrategy {\n\tprivate store = new Map<string, ItemSessionContainer>();\n\n\tload(key: string): ItemSessionContainer | null {\n\t\treturn this.store.get(key) ?? null;\n\t}\n\n\tsave(key: string, session: ItemSessionContainer): void {\n\t\tthis.store.set(key, session);\n\t}\n\n\tclear(key: string): void {\n\t\tthis.store.delete(key);\n\t}\n}\n\nexport class SessionStorageItemSessionStorage\n\timplements ItemSessionStorageStrategy\n{\n\tload(key: string): ItemSessionContainer | null {\n\t\tif (typeof window === \"undefined\") return null;\n\t\ttry {\n\t\t\tconst raw = window.sessionStorage.getItem(key);\n\t\t\tif (!raw) return null;\n\t\t\treturn JSON.parse(raw) as ItemSessionContainer;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tsave(key: string, session: ItemSessionContainer): void {\n\t\tif (typeof window === \"undefined\") return;\n\t\ttry {\n\t\t\twindow.sessionStorage.setItem(key, JSON.stringify(session));\n\t\t} catch {}\n\t}\n\n\tclear(key: string): void {\n\t\tif (typeof window === \"undefined\") return;\n\t\ttry {\n\t\t\twindow.sessionStorage.removeItem(key);\n\t\t} catch {}\n\t}\n}\n"]}
1
+ {"version":3,"file":"item-controller-storage.js","sourceRoot":"","sources":["../../src/pie/item-controller-storage.ts"],"names":[],"mappings":"AAaA,MAAM,OAAO,wBAAwB;IAC5B,KAAK,GAAG,IAAI,GAAG,EAAgC,CAAC;IAExD,IAAI,CAAC,GAAW;QACf,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC;IACpC,CAAC;IAED,IAAI,CAAC,GAAW,EAAE,OAA6B;QAC9C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,GAAW;QAChB,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACxB,CAAC;CACD;AAED,MAAM,OAAO,gCAAgC;IAG5C,IAAI,CAAC,GAAW;QACf,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO,IAAI,CAAC;QAC/C,IAAI,CAAC;YACJ,MAAM,GAAG,GAAG,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;YAC/C,IAAI,CAAC,GAAG;gBAAE,OAAO,IAAI,CAAC;YACtB,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC;QAChD,CAAC;QAAC,MAAM,CAAC;YACR,OAAO,IAAI,CAAC;QACb,CAAC;IACF,CAAC;IAED,IAAI,CAAC,GAAW,EAAE,OAA6B;QAC9C,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAC1C,IAAI,CAAC;YACJ,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;QAC7D,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;IAED,KAAK,CAAC,GAAW;QAChB,IAAI,OAAO,MAAM,KAAK,WAAW;YAAE,OAAO;QAC1C,IAAI,CAAC;YACJ,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;QACvC,CAAC;QAAC,MAAM,CAAC,CAAA,CAAC;IACX,CAAC;CACD","sourcesContent":["export type ItemSessionContainer = {\n\tid: string;\n\tdata: any[];\n};\n\nexport interface ItemSessionStorageStrategy {\n\tload(\n\t\tkey: string,\n\t): ItemSessionContainer | null | Promise<ItemSessionContainer | null>;\n\tsave(key: string, session: ItemSessionContainer): void | Promise<void>;\n\tclear?(key: string): void | Promise<void>;\n}\n\nexport class MemoryItemSessionStorage implements ItemSessionStorageStrategy {\n\tprivate store = new Map<string, ItemSessionContainer>();\n\n\tload(key: string): ItemSessionContainer | null {\n\t\treturn this.store.get(key) ?? null;\n\t}\n\n\tsave(key: string, session: ItemSessionContainer): void {\n\t\tthis.store.set(key, session);\n\t}\n\n\tclear(key: string): void {\n\t\tthis.store.delete(key);\n\t}\n}\n\nexport class SessionStorageItemSessionStorage\n\timplements ItemSessionStorageStrategy\n{\n\tload(key: string): ItemSessionContainer | null {\n\t\tif (typeof window === \"undefined\") return null;\n\t\ttry {\n\t\t\tconst raw = window.sessionStorage.getItem(key);\n\t\t\tif (!raw) return null;\n\t\t\treturn JSON.parse(raw) as ItemSessionContainer;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t}\n\n\tsave(key: string, session: ItemSessionContainer): void {\n\t\tif (typeof window === \"undefined\") return;\n\t\ttry {\n\t\t\twindow.sessionStorage.setItem(key, JSON.stringify(session));\n\t\t} catch {}\n\t}\n\n\tclear(key: string): void {\n\t\tif (typeof window === \"undefined\") return;\n\t\ttry {\n\t\t\twindow.sessionStorage.removeItem(key);\n\t\t} catch {}\n\t}\n}\n"]}
@@ -22,6 +22,21 @@ export declare class ItemController {
22
22
  clearPersisted(): Promise<void>;
23
23
  getSession(): ItemSessionContainer;
24
24
  setSession(input: unknown, options?: SetSessionOptions): ItemSessionContainer;
25
+ /**
26
+ * Merge derived, non-response element state (e.g. a controller's persisted
27
+ * shuffle order) into the authoritative session for a single element entry.
28
+ *
29
+ * Unlike {@link setSession}, this deliberately bypasses the response-protection
30
+ * guard: the merged `properties` are element-derived metadata (no `value`), so
31
+ * they must never be blocked by, nor mistaken for, a student response. The
32
+ * shallow merge preserves any existing response on the entry.
33
+ *
34
+ * Defaults to `persist: false` — shuffle order rides along with the next genuine
35
+ * response save rather than triggering its own persistence.
36
+ */
37
+ mergeElementSession(elementId: string, properties: Record<string, unknown>, options?: {
38
+ persist?: boolean;
39
+ }): ItemSessionContainer;
25
40
  updateFromEventDetail(detail: unknown, options?: SetSessionOptions): ItemSessionContainer;
26
41
  }
27
42
  export declare const normalizeItemSessionContainer: typeof normalizeSessionContainer;
@@ -1,5 +1,5 @@
1
1
  import { MemoryItemSessionStorage, } from "./item-controller-storage.js";
2
- import { hasResponseField, hasResponseValue, normalizeItemSessionContainer as normalizeSessionContainer, } from "./item-session-contract.js";
2
+ import { hasResponseField, hasResponseValue, mergeElementIntoSession, normalizeItemSessionContainer as normalizeSessionContainer, } from "./item-session-contract.js";
3
3
  const DEFAULT_SESSION_ID = "";
4
4
  function cloneSession(session) {
5
5
  try {
@@ -19,7 +19,8 @@ export class ItemController {
19
19
  sessionId;
20
20
  constructor(options) {
21
21
  this.storage = options.storage ?? new MemoryItemSessionStorage();
22
- this.storageKey = options.storageKey ?? `pie:item-controller:v1:${options.itemId}`;
22
+ this.storageKey =
23
+ options.storageKey ?? `pie:item-controller:v1:${options.itemId}`;
23
24
  this.sessionId = options.sessionId ?? DEFAULT_SESSION_ID;
24
25
  this.session = normalizeSessionContainer(options.initialSession, this.sessionId);
25
26
  }
@@ -54,6 +55,25 @@ export class ItemController {
54
55
  }
55
56
  return this.getSession();
56
57
  }
58
+ /**
59
+ * Merge derived, non-response element state (e.g. a controller's persisted
60
+ * shuffle order) into the authoritative session for a single element entry.
61
+ *
62
+ * Unlike {@link setSession}, this deliberately bypasses the response-protection
63
+ * guard: the merged `properties` are element-derived metadata (no `value`), so
64
+ * they must never be blocked by, nor mistaken for, a student response. The
65
+ * shallow merge preserves any existing response on the entry.
66
+ *
67
+ * Defaults to `persist: false` — shuffle order rides along with the next genuine
68
+ * response save rather than triggering its own persistence.
69
+ */
70
+ mergeElementSession(elementId, properties, options = {}) {
71
+ this.session = mergeElementIntoSession(this.session.id || this.sessionId, this.session, elementId, { id: elementId, ...properties });
72
+ if (options.persist === true) {
73
+ void this.persist();
74
+ }
75
+ return this.getSession();
76
+ }
57
77
  updateFromEventDetail(detail, options = {}) {
58
78
  const payload = detail?.session ?? detail;
59
79
  return this.setSession(payload, options);
@@ -1 +1 @@
1
- {"version":3,"file":"item-controller.js","sourceRoot":"","sources":["../../src/pie/item-controller.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,wBAAwB,GAGxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,6BAA6B,IAAI,yBAAyB,GAC1D,MAAM,4BAA4B,CAAC;AAepC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAE9B,SAAS,YAAY,CAAC,OAA6B;IAClD,IAAI,CAAC;QACJ,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC;IACjC,CAAC;IAAC,MAAM,CAAC;QACR,OAAO;YACN,EAAE,EAAE,OAAO,CAAC,EAAE;YACd,IAAI,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;SACpD,CAAC;IACH,CAAC;AACF,CAAC;AAED,MAAM,OAAO,cAAc;IAClB,OAAO,CAA6B;IACpC,OAAO,CAAuB;IAC9B,UAAU,CAAS;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sBAAsB;YACvB,gBAAgB,CAAC,IAAI,CAAC,OAAO,CAAC;YAC9B,CAAC,gBAAgB,CAAC,IAAI,CAAC;YACvB,CAAC,gBAAgB,CAAC,IAAI,CAAC,EACtB,CAAC;YACF,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;QAC1B,CAAC;QACD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACpB,IAAI,OAAO,CAAC,OAAO,KAAK,KAAK,EAAE,CAAC;YAC/B,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC1B,CAAC;IAED,qBAAqB,CACpB,MAAe,EACf,UAA6B,EAAE;QAE/B,MAAM,OAAO,GAAI,MAAc,EAAE,OAAO,IAAI,MAAM,CAAC;QACnD,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;CACD;AAED,MAAM,CAAC,MAAM,6BAA6B,GAAG,yBAAyB,CAAC","sourcesContent":["import {\n\tMemoryItemSessionStorage,\n\ttype ItemSessionContainer,\n\ttype ItemSessionStorageStrategy,\n} from \"./item-controller-storage.js\";\nimport {\n\thasResponseField,\n\thasResponseValue,\n\tnormalizeItemSessionContainer as normalizeSessionContainer,\n} from \"./item-session-contract.js\";\n\nexport type ItemControllerOptions = {\n\titemId: string;\n\tstorageKey?: string;\n\tsessionId?: string;\n\tinitialSession?: unknown;\n\tstorage?: ItemSessionStorageStrategy;\n};\n\ntype SetSessionOptions = {\n\tpersist?: boolean;\n\tallowMetadataOverwrite?: boolean;\n};\n\nconst DEFAULT_SESSION_ID = \"\";\n\nfunction cloneSession(session: ItemSessionContainer): ItemSessionContainer {\n\ttry {\n\t\treturn structuredClone(session);\n\t} catch {\n\t\treturn {\n\t\t\tid: session.id,\n\t\t\tdata: JSON.parse(JSON.stringify(session.data ?? [])),\n\t\t};\n\t}\n}\n\nexport class ItemController {\n\tprivate storage: ItemSessionStorageStrategy;\n\tprivate session: ItemSessionContainer;\n\tprivate storageKey: string;\n\tprivate sessionId: string;\n\n\tconstructor(options: ItemControllerOptions) {\n\t\tthis.storage = options.storage ?? new MemoryItemSessionStorage();\n\t\tthis.storageKey = options.storageKey ?? `pie:item-controller:v1:${options.itemId}`;\n\t\tthis.sessionId = options.sessionId ?? DEFAULT_SESSION_ID;\n\t\tthis.session = normalizeSessionContainer(options.initialSession, this.sessionId);\n\t}\n\n\tasync hydrate(): Promise<ItemSessionContainer> {\n\t\tconst loaded = await this.storage.load(this.storageKey);\n\t\tif (loaded) {\n\t\t\tthis.session = normalizeSessionContainer(loaded, this.sessionId);\n\t\t}\n\t\treturn this.getSession();\n\t}\n\n\tasync persist(): Promise<void> {\n\t\tawait this.storage.save(this.storageKey, this.session);\n\t}\n\n\tasync clearPersisted(): Promise<void> {\n\t\tawait this.storage.clear?.(this.storageKey);\n\t}\n\n\tgetSession(): ItemSessionContainer {\n\t\treturn cloneSession(this.session);\n\t}\n\n\tsetSession(input: unknown, options: SetSessionOptions = {}): ItemSessionContainer {\n\t\tconst next = normalizeSessionContainer(input, this.sessionId);\n\t\tconst allowMetadataOverwrite = options.allowMetadataOverwrite ?? false;\n\t\tif (\n\t\t\t!allowMetadataOverwrite &&\n\t\t\thasResponseValue(this.session) &&\n\t\t\t!hasResponseValue(next) &&\n\t\t\t!hasResponseField(next)\n\t\t) {\n\t\t\treturn this.getSession();\n\t\t}\n\t\tthis.session = next;\n\t\tif (options.persist !== false) {\n\t\t\tvoid this.persist();\n\t\t}\n\t\treturn this.getSession();\n\t}\n\n\tupdateFromEventDetail(\n\t\tdetail: unknown,\n\t\toptions: SetSessionOptions = {},\n\t): ItemSessionContainer {\n\t\tconst payload = (detail as any)?.session ?? detail;\n\t\treturn this.setSession(payload, options);\n\t}\n}\n\nexport const normalizeItemSessionContainer = normalizeSessionContainer;\n"]}
1
+ {"version":3,"file":"item-controller.js","sourceRoot":"","sources":["../../src/pie/item-controller.ts"],"names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E,EAAE,SAAS,EAAE,GAAG,UAAU,EAAE,CAChC,CAAC;QACF,IAAI,OAAO,CAAC,OAAO,KAAK,IAAI,EAAE,CAAC;YAC9B,KAAK,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,CAAC;QACD,OAAO,IAAI,CAAC,UAAU,EAAE,CAAC;IAC1B,CAAC;IAED,qBAAqB,CACpB,MAAe,EACf,UAA6B,EAAE;QAE/B,MAAM,OAAO,GAAI,MAAc,EAAE,OAAO,IAAI,MAAM,CAAC;QACnD,OAAO,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC1C,CAAC;CACD;AAED,MAAM,CAAC,MAAM,6BAA6B,GAAG,yBAAyB,CAAC","sourcesContent":["import {\n\tMemoryItemSessionStorage,\n\ttype ItemSessionContainer,\n\ttype ItemSessionStorageStrategy,\n} from \"./item-controller-storage.js\";\nimport {\n\thasResponseField,\n\thasResponseValue,\n\tmergeElementIntoSession,\n\tnormalizeItemSessionContainer as normalizeSessionContainer,\n} from \"./item-session-contract.js\";\n\nexport type ItemControllerOptions = {\n\titemId: string;\n\tstorageKey?: string;\n\tsessionId?: string;\n\tinitialSession?: unknown;\n\tstorage?: ItemSessionStorageStrategy;\n};\n\ntype SetSessionOptions = {\n\tpersist?: boolean;\n\tallowMetadataOverwrite?: boolean;\n};\n\nconst DEFAULT_SESSION_ID = \"\";\n\nfunction cloneSession(session: ItemSessionContainer): ItemSessionContainer {\n\ttry {\n\t\treturn structuredClone(session);\n\t} catch {\n\t\treturn {\n\t\t\tid: session.id,\n\t\t\tdata: JSON.parse(JSON.stringify(session.data ?? [])),\n\t\t};\n\t}\n}\n\nexport class ItemController {\n\tprivate storage: ItemSessionStorageStrategy;\n\tprivate session: ItemSessionContainer;\n\tprivate storageKey: string;\n\tprivate sessionId: string;\n\n\tconstructor(options: ItemControllerOptions) {\n\t\tthis.storage = options.storage ?? new MemoryItemSessionStorage();\n\t\tthis.storageKey =\n\t\t\toptions.storageKey ?? `pie:item-controller:v1:${options.itemId}`;\n\t\tthis.sessionId = options.sessionId ?? DEFAULT_SESSION_ID;\n\t\tthis.session = normalizeSessionContainer(\n\t\t\toptions.initialSession,\n\t\t\tthis.sessionId,\n\t\t);\n\t}\n\n\tasync hydrate(): Promise<ItemSessionContainer> {\n\t\tconst loaded = await this.storage.load(this.storageKey);\n\t\tif (loaded) {\n\t\t\tthis.session = normalizeSessionContainer(loaded, this.sessionId);\n\t\t}\n\t\treturn this.getSession();\n\t}\n\n\tasync persist(): Promise<void> {\n\t\tawait this.storage.save(this.storageKey, this.session);\n\t}\n\n\tasync clearPersisted(): Promise<void> {\n\t\tawait this.storage.clear?.(this.storageKey);\n\t}\n\n\tgetSession(): ItemSessionContainer {\n\t\treturn cloneSession(this.session);\n\t}\n\n\tsetSession(\n\t\tinput: unknown,\n\t\toptions: SetSessionOptions = {},\n\t): ItemSessionContainer {\n\t\tconst next = normalizeSessionContainer(input, this.sessionId);\n\t\tconst allowMetadataOverwrite = options.allowMetadataOverwrite ?? false;\n\t\tif (\n\t\t\t!allowMetadataOverwrite &&\n\t\t\thasResponseValue(this.session) &&\n\t\t\t!hasResponseValue(next) &&\n\t\t\t!hasResponseField(next)\n\t\t) {\n\t\t\treturn this.getSession();\n\t\t}\n\t\tthis.session = next;\n\t\tif (options.persist !== false) {\n\t\t\tvoid this.persist();\n\t\t}\n\t\treturn this.getSession();\n\t}\n\n\t/**\n\t * Merge derived, non-response element state (e.g. a controller's persisted\n\t * shuffle order) into the authoritative session for a single element entry.\n\t *\n\t * Unlike {@link setSession}, this deliberately bypasses the response-protection\n\t * guard: the merged `properties` are element-derived metadata (no `value`), so\n\t * they must never be blocked by, nor mistaken for, a student response. The\n\t * shallow merge preserves any existing response on the entry.\n\t *\n\t * Defaults to `persist: false` — shuffle order rides along with the next genuine\n\t * response save rather than triggering its own persistence.\n\t */\n\tmergeElementSession(\n\t\telementId: string,\n\t\tproperties: Record<string, unknown>,\n\t\toptions: { persist?: boolean } = {},\n\t): ItemSessionContainer {\n\t\tthis.session = mergeElementIntoSession(\n\t\t\tthis.session.id || this.sessionId,\n\t\t\tthis.session,\n\t\t\telementId,\n\t\t\t{ id: elementId, ...properties },\n\t\t);\n\t\tif (options.persist === true) {\n\t\t\tvoid this.persist();\n\t\t}\n\t\treturn this.getSession();\n\t}\n\n\tupdateFromEventDetail(\n\t\tdetail: unknown,\n\t\toptions: SetSessionOptions = {},\n\t): ItemSessionContainer {\n\t\tconst payload = (detail as any)?.session ?? detail;\n\t\treturn this.setSession(payload, options);\n\t}\n}\n\nexport const normalizeItemSessionContainer = normalizeSessionContainer;\n"]}
@@ -13,6 +13,7 @@ export type NormalizedItemSessionChange = {
13
13
  export declare function normalizeItemSessionContainer(input: unknown, fallbackSessionId?: string): ItemSessionContainer;
14
14
  export declare function hasResponseValue(value: unknown): boolean;
15
15
  export declare function hasResponseField(value: unknown): boolean;
16
+ export declare function mergeElementIntoSession(itemId: string, previousItemSession: unknown, entryId: string, entry: Record<string, unknown>): ItemSessionContainer;
16
17
  export declare function normalizeItemSessionChange(args: {
17
18
  itemId: string;
18
19
  sessionDetail: unknown;
@@ -18,9 +18,7 @@ export function normalizeItemSessionContainer(input, fallbackSessionId = DEFAULT
18
18
  const candidate = input;
19
19
  if (Array.isArray(candidate.data)) {
20
20
  return {
21
- id: typeof candidate.id === "string"
22
- ? candidate.id
23
- : fallbackSessionId,
21
+ id: typeof candidate.id === "string" ? candidate.id : fallbackSessionId,
24
22
  data: candidate.data,
25
23
  };
26
24
  }
@@ -70,7 +68,7 @@ export function hasResponseField(value) {
70
68
  }
71
69
  return false;
72
70
  }
73
- function mergeElementIntoSession(itemId, previousItemSession, entryId, entry) {
71
+ export function mergeElementIntoSession(itemId, previousItemSession, entryId, entry) {
74
72
  const previous = normalizeItemSessionContainer(previousItemSession, itemId);
75
73
  const nextData = [...previous.data];
76
74
  const existingIndex = nextData.findIndex((candidate) => {
@@ -95,12 +93,15 @@ function mergeElementIntoSession(itemId, previousItemSession, entryId, entry) {
95
93
  }
96
94
  export function normalizeItemSessionChange(args) {
97
95
  const sessionDetail = (args.sessionDetail || {});
98
- const actualSession = sessionDetail && typeof sessionDetail === "object" && "session" in sessionDetail
96
+ const actualSession = sessionDetail &&
97
+ typeof sessionDetail === "object" &&
98
+ "session" in sessionDetail
99
99
  ? sessionDetail.session
100
100
  : args.sessionDetail;
101
101
  const safeItemId = typeof args.itemId === "string" && args.itemId
102
102
  ? args.itemId
103
- : typeof actualSession?.id === "string"
103
+ : typeof actualSession?.id ===
104
+ "string"
104
105
  ? String(actualSession.id)
105
106
  : "";
106
107
  if (!actualSession || typeof actualSession !== "object") {
@@ -108,8 +109,12 @@ export function normalizeItemSessionChange(args) {
108
109
  itemId: safeItemId,
109
110
  session: null,
110
111
  intent: "metadata-only",
111
- component: typeof sessionDetail.component === "string" ? sessionDetail.component : undefined,
112
- complete: typeof sessionDetail.complete === "boolean" ? sessionDetail.complete : undefined,
112
+ component: typeof sessionDetail.component === "string"
113
+ ? sessionDetail.component
114
+ : undefined,
115
+ complete: typeof sessionDetail.complete === "boolean"
116
+ ? sessionDetail.complete
117
+ : undefined,
113
118
  };
114
119
  }
115
120
  const candidate = actualSession;
@@ -144,8 +149,12 @@ export function normalizeItemSessionChange(args) {
144
149
  itemId: safeItemId,
145
150
  session: normalizedCandidate,
146
151
  intent: "replace-item-session",
147
- component: typeof sessionDetail.component === "string" ? sessionDetail.component : undefined,
148
- complete: typeof sessionDetail.complete === "boolean" ? sessionDetail.complete : undefined,
152
+ component: typeof sessionDetail.component === "string"
153
+ ? sessionDetail.component
154
+ : undefined,
155
+ complete: typeof sessionDetail.complete === "boolean"
156
+ ? sessionDetail.complete
157
+ : undefined,
149
158
  };
150
159
  }
151
160
  const candidateKeys = Object.keys(candidate);
@@ -159,8 +168,12 @@ export function normalizeItemSessionChange(args) {
159
168
  itemId: safeItemId,
160
169
  session: null,
161
170
  intent: "metadata-only",
162
- component: typeof sessionDetail.component === "string" ? sessionDetail.component : undefined,
163
- complete: typeof sessionDetail.complete === "boolean" ? sessionDetail.complete : undefined,
171
+ component: typeof sessionDetail.component === "string"
172
+ ? sessionDetail.component
173
+ : undefined,
174
+ complete: typeof sessionDetail.complete === "boolean"
175
+ ? sessionDetail.complete
176
+ : undefined,
164
177
  };
165
178
  }
166
179
  const component = typeof sessionDetail.component === "string"
@@ -175,7 +188,9 @@ export function normalizeItemSessionChange(args) {
175
188
  session: merged,
176
189
  intent: "merge-element-session",
177
190
  component,
178
- complete: typeof sessionDetail.complete === "boolean" ? sessionDetail.complete : undefined,
191
+ complete: typeof sessionDetail.complete === "boolean"
192
+ ? sessionDetail.complete
193
+ : undefined,
179
194
  };
180
195
  }
181
196
  //# sourceMappingURL=item-session-contract.js.map