@pie-qti/item-player 1.0.0-beta.3 → 1.0.0-beta.5
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.
- package/README.md +33 -5
- package/dist/catalog/applyGlossaryTriggers.js +14 -2
- package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
- package/dist/catalog/catalogExtractor.js +2 -4
- package/dist/catalog/catalogExtractor.js.map +1 -1
- package/dist/catalog/sessionCatalog.d.ts +46 -0
- package/dist/catalog/sessionCatalog.js +87 -0
- package/dist/catalog/sessionCatalog.js.map +1 -0
- package/dist/components/utils/endAttempt.d.ts +16 -0
- package/dist/components/utils/endAttempt.js +28 -0
- package/dist/components/utils/endAttempt.js.map +1 -0
- package/dist/components/utils/focus.d.ts +19 -0
- package/dist/components/utils/focus.js +67 -0
- package/dist/components/utils/focus.js.map +1 -0
- package/dist/components/utils/itemBodyRenderer.d.ts +44 -0
- package/dist/components/utils/itemBodyRenderer.js +177 -0
- package/dist/components/utils/itemBodyRenderer.js.map +1 -0
- package/dist/components/utils/sentenceContext.d.ts +6 -0
- package/dist/components/utils/sentenceContext.js +16 -0
- package/dist/components/utils/sentenceContext.js.map +1 -0
- package/dist/core/AssessmentItemDefinition.d.ts +20 -1
- package/dist/core/AssessmentItemDefinition.js +12 -31
- package/dist/core/AssessmentItemDefinition.js.map +1 -1
- package/dist/core/ComponentRegistry.d.ts +92 -0
- package/dist/core/ComponentRegistry.js +7 -1
- package/dist/core/ComponentRegistry.js.map +1 -1
- package/dist/core/ItemSession.d.ts +18 -1
- package/dist/core/ItemSession.js +79 -41
- package/dist/core/ItemSession.js.map +1 -1
- package/dist/core/Player.d.ts +118 -141
- package/dist/core/Player.js +387 -1233
- package/dist/core/Player.js.map +1 -1
- package/dist/core/compliance.d.ts +72 -0
- package/dist/core/compliance.js +147 -0
- package/dist/core/compliance.js.map +1 -0
- package/dist/core/declarations/declarationBuilder.d.ts +29 -0
- package/dist/core/declarations/declarationBuilder.js +284 -0
- package/dist/core/declarations/declarationBuilder.js.map +1 -0
- package/dist/core/declarations/declarationValues.d.ts +11 -0
- package/dist/core/declarations/declarationValues.js +168 -0
- package/dist/core/declarations/declarationValues.js.map +1 -0
- package/dist/core/matchGroups.d.ts +36 -0
- package/dist/core/matchGroups.js +100 -0
- package/dist/core/matchGroups.js.map +1 -0
- package/dist/core/nameMappers.d.ts +35 -0
- package/dist/core/nameMappers.js +47 -0
- package/dist/core/nameMappers.js.map +1 -0
- package/dist/core/parsingLimits.d.ts +4 -0
- package/dist/core/parsingLimits.js +5 -2
- package/dist/core/parsingLimits.js.map +1 -1
- package/dist/core/processing/responseProcessing.d.ts +88 -0
- package/dist/core/processing/responseProcessing.js +317 -0
- package/dist/core/processing/responseProcessing.js.map +1 -0
- package/dist/core/processing/responseValidation.d.ts +55 -0
- package/dist/core/processing/responseValidation.js +335 -0
- package/dist/core/processing/responseValidation.js.map +1 -0
- package/dist/core/rendering/contentPass.d.ts +31 -0
- package/dist/core/rendering/contentPass.js +152 -0
- package/dist/core/rendering/contentPass.js.map +1 -0
- package/dist/core/rendering/htmlRender.d.ts +21 -0
- package/dist/core/rendering/htmlRender.js +56 -0
- package/dist/core/rendering/htmlRender.js.map +1 -0
- package/dist/core/responseProcessingTemplates.d.ts +23 -0
- package/dist/core/responseProcessingTemplates.js +45 -0
- package/dist/core/responseProcessingTemplates.js.map +1 -0
- package/dist/core/rolePolicy.d.ts +5 -0
- package/dist/core/rolePolicy.js +21 -0
- package/dist/core/rolePolicy.js.map +1 -1
- package/dist/core/sanitizer.js +8 -14
- package/dist/core/sanitizer.js.map +1 -1
- package/dist/core/serialization/sessionState.d.ts +56 -0
- package/dist/core/serialization/sessionState.js +139 -0
- package/dist/core/serialization/sessionState.js.map +1 -0
- package/dist/core/serialization/valueForms.d.ts +32 -0
- package/dist/core/serialization/valueForms.js +112 -0
- package/dist/core/serialization/valueForms.js.map +1 -0
- package/dist/document/AssessmentItemDocument.d.ts +27 -1
- package/dist/document/AssessmentItemDocument.js +67 -31
- package/dist/document/AssessmentItemDocument.js.map +1 -1
- package/dist/element-class-BbF4Dj7F.js +3773 -0
- package/dist/element-class-BbF4Dj7F.js.map +1 -0
- package/dist/element-class.d.ts +34 -1
- package/dist/element-class.js +1 -1
- package/dist/element.js +1 -1
- package/dist/extraction/ExtractionRegistry.js +6 -12
- package/dist/extraction/ExtractionRegistry.js.map +1 -1
- package/dist/extraction/createContext.d.ts +2 -2
- package/dist/extraction/createContext.js.map +1 -1
- package/dist/extraction/index.d.ts +2 -2
- package/dist/extraction/index.js +1 -1
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/interactionCoverage.d.ts +31 -0
- package/dist/extraction/interactionCoverage.js +40 -0
- package/dist/extraction/interactionCoverage.js.map +1 -0
- package/dist/extraction/interactionExtractionPipeline.js +5 -10
- package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
- package/dist/extraction/interactionSecurity.js +1 -28
- package/dist/extraction/interactionSecurity.js.map +1 -1
- package/dist/extraction/mergeDeliveryFields.d.ts +13 -0
- package/dist/extraction/mergeDeliveryFields.js +17 -0
- package/dist/extraction/mergeDeliveryFields.js.map +1 -0
- package/dist/extraction/responseIdentifier.d.ts +19 -0
- package/dist/extraction/responseIdentifier.js +29 -0
- package/dist/extraction/responseIdentifier.js.map +1 -0
- package/dist/extraction/types.d.ts +11 -18
- package/dist/extraction/types.js +0 -12
- package/dist/extraction/types.js.map +1 -1
- package/dist/extraction/utils.d.ts +14 -0
- package/dist/extraction/utils.js +35 -5
- package/dist/extraction/utils.js.map +1 -1
- package/dist/index.d.ts +16 -10
- package/dist/index.js +19 -8
- package/dist/index.js.map +1 -1
- package/dist/interactions/associate/extractor.d.ts +1 -0
- package/dist/interactions/associate/extractor.js +10 -12
- package/dist/interactions/associate/extractor.js.map +1 -1
- package/dist/interactions/choice/extractor.js +6 -13
- package/dist/interactions/choice/extractor.js.map +1 -1
- package/dist/interactions/drawing/extractor.d.ts +6 -0
- package/dist/interactions/drawing/extractor.js +30 -9
- package/dist/interactions/drawing/extractor.js.map +1 -1
- package/dist/interactions/end-attempt/extractor.js +2 -1
- package/dist/interactions/end-attempt/extractor.js.map +1 -1
- package/dist/interactions/extended-text/extractor.d.ts +6 -1
- package/dist/interactions/extended-text/extractor.js +10 -5
- package/dist/interactions/extended-text/extractor.js.map +1 -1
- package/dist/interactions/extended-text/response.js +18 -18
- package/dist/interactions/extended-text/response.js.map +1 -1
- package/dist/interactions/gap-match/extractor.d.ts +40 -2
- package/dist/interactions/gap-match/extractor.js +197 -39
- package/dist/interactions/gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-associate/extractor.d.ts +11 -0
- package/dist/interactions/graphic-associate/extractor.js +35 -24
- package/dist/interactions/graphic-associate/extractor.js.map +1 -1
- package/dist/interactions/graphic-gap-match/extractor.d.ts +21 -0
- package/dist/interactions/graphic-gap-match/extractor.js +79 -43
- package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-order/extractor.d.ts +15 -0
- package/dist/interactions/graphic-order/extractor.js +39 -24
- package/dist/interactions/graphic-order/extractor.js.map +1 -1
- package/dist/interactions/hotspot/extractor.d.ts +6 -0
- package/dist/interactions/hotspot/extractor.js +31 -16
- package/dist/interactions/hotspot/extractor.js.map +1 -1
- package/dist/interactions/hottext/extractor.js +2 -12
- package/dist/interactions/hottext/extractor.js.map +1 -1
- package/dist/interactions/inline/accessibleName.d.ts +29 -0
- package/dist/interactions/inline/accessibleName.js +35 -0
- package/dist/interactions/inline/accessibleName.js.map +1 -0
- package/dist/interactions/inline/render-plan.d.ts +5 -14
- package/dist/interactions/inline/render-plan.js +5 -56
- package/dist/interactions/inline/render-plan.js.map +1 -1
- package/dist/interactions/inline-choice/extractor.d.ts +4 -0
- package/dist/interactions/inline-choice/extractor.js +13 -12
- package/dist/interactions/inline-choice/extractor.js.map +1 -1
- package/dist/interactions/match/extractor.d.ts +2 -0
- package/dist/interactions/match/extractor.js +14 -28
- package/dist/interactions/match/extractor.js.map +1 -1
- package/dist/interactions/media/extractor.d.ts +5 -11
- package/dist/interactions/media/extractor.js +100 -36
- package/dist/interactions/media/extractor.js.map +1 -1
- package/dist/interactions/modules.js +8 -2
- package/dist/interactions/modules.js.map +1 -1
- package/dist/interactions/order/extractor.d.ts +2 -0
- package/dist/interactions/order/extractor.js +8 -12
- package/dist/interactions/order/extractor.js.map +1 -1
- package/dist/interactions/order/limits.d.ts +29 -0
- package/dist/interactions/order/limits.js +28 -0
- package/dist/interactions/order/limits.js.map +1 -0
- package/dist/interactions/portable-custom/extractor.js +4 -2
- package/dist/interactions/portable-custom/extractor.js.map +1 -1
- package/dist/interactions/position-object/extractor.d.ts +18 -1
- package/dist/interactions/position-object/extractor.js +81 -22
- package/dist/interactions/position-object/extractor.js.map +1 -1
- package/dist/interactions/select-point/extractor.d.ts +6 -0
- package/dist/interactions/select-point/extractor.js +31 -19
- package/dist/interactions/select-point/extractor.js.map +1 -1
- package/dist/interactions/shared/imageAlt.d.ts +54 -0
- package/dist/interactions/shared/imageAlt.js +84 -0
- package/dist/interactions/shared/imageAlt.js.map +1 -0
- package/dist/interactions/shared/interactionImage.d.ts +32 -0
- package/dist/interactions/shared/interactionImage.js +39 -0
- package/dist/interactions/shared/interactionImage.js.map +1 -0
- package/dist/interactions/shared/specDefaults.d.ts +20 -0
- package/dist/interactions/shared/specDefaults.js +25 -0
- package/dist/interactions/shared/specDefaults.js.map +1 -0
- package/dist/interactions/shared/types.d.ts +212 -40
- package/dist/interactions/shared/types.js.map +1 -1
- package/dist/interactions/text-entry/extractor.d.ts +9 -0
- package/dist/interactions/text-entry/extractor.js +9 -0
- package/dist/interactions/text-entry/extractor.js.map +1 -1
- package/dist/interactions/text-entry/inlineInputStyle.d.ts +10 -0
- package/dist/interactions/text-entry/inlineInputStyle.js +12 -0
- package/dist/interactions/text-entry/inlineInputStyle.js.map +1 -0
- package/dist/interactions/text-entry/inputMode.d.ts +35 -0
- package/dist/interactions/text-entry/inputMode.js +134 -0
- package/dist/interactions/text-entry/inputMode.js.map +1 -0
- package/dist/interactions/text-entry/response.d.ts +15 -0
- package/dist/interactions/text-entry/response.js +25 -0
- package/dist/interactions/text-entry/response.js.map +1 -0
- package/dist/interactions/upload/extractor.js +2 -2
- package/dist/interactions/upload/extractor.js.map +1 -1
- package/dist/pci/PciHost.d.ts +1 -1
- package/dist/pci/PciHost.js +11 -11
- package/dist/pci/PciHost.js.map +1 -1
- package/dist/pci/index.d.ts +1 -0
- package/dist/pci/index.js.map +1 -1
- package/dist/pci/modulePaths.d.ts +16 -0
- package/dist/pci/modulePaths.js +33 -0
- package/dist/pci/modulePaths.js.map +1 -0
- package/dist/pci/pageRealmSession.js +3 -15
- package/dist/pci/pageRealmSession.js.map +1 -1
- package/dist/pci/qtiVariableJson.d.ts +46 -3
- package/dist/pci/qtiVariableJson.js +247 -53
- package/dist/pci/qtiVariableJson.js.map +1 -1
- package/dist/pci/sandbox/SandboxedPciSession.d.ts +3 -0
- package/dist/pci/sandbox/SandboxedPciSession.js +15 -14
- package/dist/pci/sandbox/SandboxedPciSession.js.map +1 -1
- package/dist/pci/sandbox/iframeConnector.d.ts +18 -4
- package/dist/pci/sandbox/iframeConnector.js +35 -6
- package/dist/pci/sandbox/iframeConnector.js.map +1 -1
- package/dist/pci/sandbox/protocol.d.ts +14 -0
- package/dist/pci/sandbox/protocol.js.map +1 -1
- package/dist/pci/sessionHosts.d.ts +47 -0
- package/dist/pci/sessionHosts.js +66 -0
- package/dist/pci/sessionHosts.js.map +1 -0
- package/dist/pci/types.d.ts +7 -1
- package/dist/pci/types.js.map +1 -1
- package/dist/pnp/applyPnp.d.ts +20 -3
- package/dist/pnp/applyPnp.js +84 -9
- package/dist/pnp/applyPnp.js.map +1 -1
- package/dist/pnp/parsePnpXml.js +2 -0
- package/dist/pnp/parsePnpXml.js.map +1 -1
- package/dist/pnp/types.d.ts +16 -8
- package/dist/pnp/types.js.map +1 -1
- package/dist/presentation/feedbackAnnouncement.d.ts +56 -0
- package/dist/presentation/feedbackAnnouncement.js +150 -0
- package/dist/presentation/feedbackAnnouncement.js.map +1 -0
- package/dist/presentation/interactionSlots.d.ts +31 -0
- package/dist/presentation/interactionSlots.js +101 -0
- package/dist/presentation/interactionSlots.js.map +1 -0
- package/dist/presentation/itemPresentationPlan.d.ts +69 -6
- package/dist/presentation/itemPresentationPlan.js +93 -81
- package/dist/presentation/itemPresentationPlan.js.map +1 -1
- package/dist/{components/utils → presentation}/stimulusRender.js +3 -12
- package/dist/presentation/stimulusRender.js.map +1 -0
- package/dist/presentation/stylesheetRender.js.map +1 -0
- package/dist/security/escapeHtml.d.ts +15 -0
- package/dist/security/escapeHtml.js +22 -0
- package/dist/security/escapeHtml.js.map +1 -0
- package/dist/security/index.d.ts +1 -0
- package/dist/security/index.js +1 -0
- package/dist/security/index.js.map +1 -1
- package/dist/server.d.ts +8 -1
- package/dist/server.js.map +1 -1
- package/dist/session-inputs.d.ts +108 -0
- package/dist/session-inputs.js +130 -0
- package/dist/session-inputs.js.map +1 -0
- package/dist/types/index.d.ts +67 -35
- package/dist/types/index.js.map +1 -1
- package/dist/utils/cloneFreeze.d.ts +52 -0
- package/dist/utils/cloneFreeze.js +113 -0
- package/dist/utils/cloneFreeze.js.map +1 -0
- package/dist/utils/htmlAttributes.d.ts +13 -0
- package/dist/utils/htmlAttributes.js +22 -0
- package/dist/utils/htmlAttributes.js.map +1 -0
- package/dist/web-components/QTIInteractionElement.d.ts +0 -29
- package/dist/web-components/QTIInteractionElement.js +0 -32
- package/dist/web-components/QTIInteractionElement.js.map +1 -1
- package/dist/web-components/index.d.ts +1 -2
- package/dist/web-components/index.js +2 -3
- package/dist/web-components/index.js.map +1 -1
- package/package.json +15 -18
- package/dist/components/utils/feedbackUtils.d.ts +0 -77
- package/dist/components/utils/feedbackUtils.js +0 -138
- package/dist/components/utils/feedbackUtils.js.map +0 -1
- package/dist/components/utils/index.d.ts +0 -4
- package/dist/components/utils/index.js +0 -5
- package/dist/components/utils/index.js.map +0 -1
- package/dist/components/utils/stimulusRender.js.map +0 -1
- package/dist/components/utils/stylesheetRender.js.map +0 -1
- package/dist/core/constants.d.ts +0 -65
- package/dist/core/constants.js +0 -74
- package/dist/core/constants.js.map +0 -1
- package/dist/element-class-X2XXDa29.js +0 -9299
- package/dist/element-class-X2XXDa29.js.map +0 -1
- package/dist/extensions/MathLiveEditor.d.ts +0 -31
- package/dist/extensions/MathLiveEditor.js +0 -248
- package/dist/extensions/MathLiveEditor.js.map +0 -1
- package/dist/utils/PerformanceMonitor.d.ts +0 -169
- package/dist/utils/PerformanceMonitor.js +0 -243
- package/dist/utils/PerformanceMonitor.js.map +0 -1
- package/dist/utils/responseUtils.d.ts +0 -15
- package/dist/utils/responseUtils.js +0 -46
- package/dist/utils/responseUtils.js.map +0 -1
- package/dist/web-components/QTIInteractionBase.d.ts +0 -119
- package/dist/web-components/QTIInteractionBase.js +0 -244
- package/dist/web-components/QTIInteractionBase.js.map +0 -1
- /package/dist/{components/utils → presentation}/stimulusRender.d.ts +0 -0
- /package/dist/{components/utils → presentation}/stylesheetRender.d.ts +0 -0
- /package/dist/{components/utils → presentation}/stylesheetRender.js +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SandboxedPciSession.js","sourceRoot":"","sources":["../../../src/pci/sandbox/SandboxedPciSession.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC3E,OAAO,EAAE,0BAA0B,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EACN,qBAAqB,EACrB,oBAAoB,GAIpB,MAAM,eAAe,CAAC;AAEvB,MAAM,4BAA4B,GAAG,KAAK,CAAC;AAC3C,MAAM,wBAAwB,GAAG,GAAG,CAAC;AACrC,MAAM,+BAA+B,GAAG,IAAI,CAAC;AAiB7C;;;;;;;;;;GAUG;AACH,M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AAS,UAAU,CAAC,IAAkB;IACrC,MAAM,cAAc,GAAG,IAAI,CAAC,+BAA+B,CAAC;IAC5D,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC;IACjD,OAAO,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,wBAAwB,IAAI,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAAC;AACzF,CAAC","sourcesContent":["import type { PciLoadContext, PciModuleSession } from '../moduleSession.js';\nimport type {\n\tExtractedPci,\n\tPciFrameConnector,\n\tPciModulePolicy,\n\tPciSandboxConfiguration,\n\tQtiPciConfiguration,\n\tQtiPciInstance,\n} from '../types.js';\nimport { PciLoadError } from '../types.js';\nimport { htmlToString, sanitizeSharedHtml } from '../../security/index.js';\nimport { createIframeFrameConnector } from './iframeConnector.js';\nimport {\n\tcreateSandboxEnvelope,\n\tisPciSandboxEnvelope,\n\ttype PciSandboxInitPayload,\n\ttype PciSandboxInstantiatePayload,\n\ttype PciSandboxModuleEntryPayload,\n} from './protocol.js';\n\nconst DEFAULT_HANDSHAKE_TIMEOUT_MS = 15000;\nconst DEFAULT_POLL_INTERVAL_MS = 250;\nconst DEFAULT_REGISTRATION_TIMEOUT_MS = 5000;\n\nexport interface SandboxedSessionOptions {\n\tsandbox: PciSandboxConfiguration;\n\tdata: ExtractedPci;\n\tbaseUrl: string;\n\t/** Policy gate applied to module URLs before anything is handed to the frame. */\n\tmodulePolicy?: PciModulePolicy;\n\t/** The page origin the runner locks to; injectable for tests. */\n\tparentOrigin?: () => string;\n\t/** Frame connection factory; defaults to a real sandboxed iframe. */\n\tframeConnector?: PciFrameConnector;\n}\n\ntype RemoteReportHandler = (report: { state?: unknown }) => void;\ntype ErrorHandler = (error: Error) => void;\n\n/**\n * The sandboxed engine: the module runs in a cross-origin runner frame\n * (`@pie-qti/pci-runner` deployed on a cookieless origin) and every contract\n * call crosses the postMessage bridge.\n *\n * Nothing here evaluates module code. Module URLs are resolved against the\n * package base, checked against the optional policy, and handed to the runner,\n * which loads them in its own opaque-origin document. `getResponse()` stays\n * synchronous for `PciHost` by answering from a cache the runner maintains:\n * pushes on every observed change, plus a bounded poll as the freshness floor.\n */\nexport class SandboxedPciSession implements PciModuleSession {\n\tprivate readonly runnerUrl: string;\n\tprivate readonly handshakeTimeoutMs: number;\n\tprivate readonly pollIntervalMs: number;\n\tprivate readonly registrationTimeoutMs: number;\n\tprivate readonly data: ExtractedPci;\n\tprivate readonly baseUrl: string;\n\tprivate readonly modulePolicy: PciModulePolicy | undefined;\n\tprivate readonly parentOrigin: () => string;\n\tprivate readonly connector: PciFrameConnector;\n\n\tprivate connection: ReturnType<PciFrameConnector> | null = null;\n\tprivate pendingInit: PciSandboxInitPayload | null = null;\n\tprivate handshook = false;\n\tprivate moduleReady = false;\n\tprivate handshakeTimer: ReturnType<typeof setTimeout> | undefined;\n\tprivate queuedInstantiate: PciSandboxInstantiatePayload | null = null;\n\tprivate currentConfiguration: QtiPciConfiguration | null = null;\n\t/** The proxy `PciHost`'s state machine talks to; reads answer from the cache. */\n\tprivate proxy: (QtiPciInstance & { disable?(): void; enable?(): void }) | null = null;\n\tprivate readonly cache: { response: unknown; state: unknown } = { response: null, state: undefined };\n\tprivate readonly reportHandlers = new Set<RemoteReportHandler>();\n\tprivate readonly errorHandlers = new Set<ErrorHandler>();\n\tprivate stopMessages: (() => void) | null = null;\n\tprivate disposed = false;\n\n\tconstructor(options: SandboxedSessionOptions) {\n\t\tthis.runnerUrl = options.sandbox.runnerUrl;\n\t\tthis.handshakeTimeoutMs = options.sandbox.handshakeTimeoutMs ?? DEFAULT_HANDSHAKE_TIMEOUT_MS;\n\t\tthis.pollIntervalMs = options.sandbox.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n\t\tthis.registrationTimeoutMs =\n\t\t\toptions.sandbox.registrationTimeoutMs ?? DEFAULT_REGISTRATION_TIMEOUT_MS;\n\t\tthis.data = options.data;\n\t\tthis.baseUrl = options.baseUrl;\n\t\tthis.modulePolicy = options.modulePolicy;\n\t\tthis.parentOrigin = options.parentOrigin ?? defaultParentOrigin;\n\t\tthis.connector = options.frameConnector ?? createIframeFrameConnector();\n\n\t\t// Config errors surface at construction, before any frame exists.\n\t\tlet runnerOrigin: URL;\n\t\ttry {\n\t\t\trunnerOrigin = new URL(this.runnerUrl);\n\t\t} catch {\n\t\t\tthrow new Error(`PCI sandbox runnerUrl must be an absolute URL: '${this.runnerUrl}'`);\n\t\t}\n\t\tif (runnerOrigin.protocol !== 'https:' && runnerOrigin.protocol !== 'http:') {\n\t\t\tthrow new Error(`PCI sandbox runnerUrl must be http(s): '${this.runnerUrl}'`);\n\t\t}\n\t}\n\n\t/** {@inheritdoc PciModuleSession.load} */\n\tpublic async load(_context: PciLoadContext): Promise<void> {\n\t\tif (this.disposed) throw new Error('Cannot load a destroyed PciHost');\n\t\t// Preparing the init payload resolves every authored path and runs the\n\t\t// policy gate before a frame exists; the module itself loads in the frame,\n\t\t// and its failures surface through onError.\n\t\tthis.pendingInit = this.buildInitPayload();\n\t}\n\n\t/** {@inheritdoc PciModuleSession.instantiate} */\n\tpublic instantiate(\n\t\tdom: HTMLElement,\n\t\tconfiguration: QtiPciConfiguration,\n\t\tstate: unknown\n\t): QtiPciInstance | undefined {\n\t\tif (this.disposed || !this.pendingInit) return undefined;\n\t\tthis.currentConfiguration = configuration;\n\n\t\tif (!this.connection || !this.connection.isAttached()) {\n\t\t\t// First mount, or the renderer's scaffold reset removed the frame.\n\t\t\tthis.resetConnection();\n\t\t\tthis.connection = this.connector(this.runnerUrl, frameTitle(this.data));\n\t\t\tthis.stopMessages = this.connection.onMessage((data) => this.handleMessage(data));\n\t\t\tdom.replaceChildren();\n\t\t\tthis.connection.appendTo(dom);\n\t\t\tthis.armHandshakeTimeout();\n\t\t}\n\n\t\t// A fresh read of the seeded state keeps the proxy honest before the\n\t\t// instance's first report arrives.\n\t\tthis.cache.response = null;\n\t\tthis.cache.state = undefined;\n\t\tthis.proxy = {\n\t\t\tgetResponse: () => this.cache.response,\n\t\t\tgetState: () => this.cache.state,\n\t\t\tdisable: () => this.post('set-enabled', { enabled: false }),\n\t\t\tenable: () => this.post('set-enabled', { enabled: true }),\n\t\t};\n\n\t\tconst payload: PciSandboxInstantiatePayload = {\n\t\t\tresponseIdentifier: configuration.responseIdentifier,\n\t\t\tstatus: configuration.status,\n\t\t\tproperties: configuration.properties,\n\t\t\t...(configuration.templateVariables !== undefined\n\t\t\t\t? { templateVariables: configuration.templateVariables }\n\t\t\t\t: {}),\n\t\t\t...(configuration.contextVariables !== undefined\n\t\t\t\t? { contextVariables: configuration.contextVariables }\n\t\t\t\t: {}),\n\t\t\t...(state !== undefined ? { state } : {}),\n\t\t};\n\t\tif (this.moduleReady) {\n\t\t\t// Runner messages are handled in arrival order, so an in-frame instance\n\t\t\t// from a previous instantiation is torn down before this one is created.\n\t\t\tthis.post('teardown-instance', {});\n\t\t\tthis.post('instantiate', payload);\n\t\t} else {\n\t\t\tthis.queuedInstantiate = payload;\n\t\t}\n\t\treturn this.proxy;\n\t}\n\n\t/** {@inheritdoc PciModuleSession.destroyInstance} */\n\tpublic destroyInstance(_instance: QtiPciInstance): void {\n\t\tif (this.connection && this.moduleReady) {\n\t\t\tthis.post('teardown-instance', {});\n\t\t}\n\t\tthis.cache.response = null;\n\t\tthis.cache.state = undefined;\n\t\tthis.proxy = null;\n\t}\n\n\t/** {@inheritdoc PciModuleSession.dispose} */\n\tpublic dispose(): void {\n\t\tif (this.connection) {\n\t\t\tthis.post('dispose', {});\n\t\t}\n\t\tthis.resetConnection();\n\t\tthis.disposed = true;\n\t\tthis.pendingInit = null;\n\t\tthis.currentConfiguration = null;\n\t\tthis.queuedInstantiate = null;\n\t}\n\n\t/** {@inheritdoc PciModuleSession.onRemoteReport} */\n\tpublic onRemoteReport(handler: RemoteReportHandler): () => void {\n\t\tthis.reportHandlers.add(handler);\n\t\treturn () => this.reportHandlers.delete(handler);\n\t}\n\n\t/** {@inheritdoc PciModuleSession.onError} */\n\tpublic onError(handler: ErrorHandler): () => void {\n\t\tthis.errorHandlers.add(handler);\n\t\treturn () => this.errorHandlers.delete(handler);\n\t}\n\n\t// ---------------------------------------------------------------------------\n\t// Private helpers\n\t// ---------------------------------------------------------------------------\n\n\tprivate buildInitPayload(): PciSandboxInitPayload {\n\t\tconst entries: PciSandboxModuleEntryPayload[] = this.data.modules\n\t\t\t.filter((module) => module.primaryPath)\n\t\t\t.map((module) => {\n\t\t\t\tconst primaryUrl = this.resolveChecked(module.primaryPath, 'primary');\n\t\t\t\treturn {\n\t\t\t\t\tid: module.id || module.primaryPath,\n\t\t\t\t\tprimaryUrl,\n\t\t\t\t\t...(module.fallbackPath\n\t\t\t\t\t\t? { fallbackUrl: this.resolveChecked(module.fallbackPath, 'fallback') }\n\t\t\t\t\t\t: {}),\n\t\t\t\t};\n\t\t\t});\n\t\tconst entry =\n\t\t\tthis.data.modules.find((module) => module.primaryPath === this.data.primaryPath) ??\n\t\t\tthis.data.modules[this.data.modules.length - 1];\n\t\tconst markup = this.data.markup;\n\t\treturn {\n\t\t\ttypeIdentifier: this.data.customInteractionTypeIdentifier,\n\t\t\tmodules: entries,\n\t\t\tentryId: entry?.id || this.data.primaryPath,\n\t\t\t...(this.data.resolutionConfigPath\n\t\t\t\t? { resolutionConfigUrl: this.resolveUrl(this.data.resolutionConfigPath) }\n\t\t\t\t: {}),\n\t\t\tbaseUrl: this.baseUrl,\n\t\t\t// The frame renders this as its interaction markup; the same sanitizer\n\t\t\t// the page-realm scaffold uses runs before it crosses the bridge.\n\t\t\tmarkup: htmlToString(sanitizeSharedHtml(htmlToString(markup))),\n\t\t\tregistrationTimeoutMs: this.registrationTimeoutMs,\n\t\t\tpollIntervalMs: this.pollIntervalMs,\n\t\t};\n\t}\n\n\t/** Resolve one authored path and run the policy gate on the absolute URL. */\n\tprivate resolveChecked(path: string, kind: 'primary' | 'fallback'): string {\n\t\tconst resolved = this.resolveUrl(path);\n\t\tif (this.modulePolicy) {\n\t\t\tthis.modulePolicy(resolved, {\n\t\t\t\tauthoredPath: path,\n\t\t\t\tkind,\n\t\t\t\tresponseIdentifier: this.data.responseIdentifier,\n\t\t\t\tcustomInteractionTypeIdentifier: this.data.customInteractionTypeIdentifier,\n\t\t\t});\n\t\t}\n\t\treturn resolved;\n\t}\n\n\tprivate resolveUrl(path: string): string {\n\t\tif (/^[a-z][a-z\\d+.-]*:/i.test(path) || path.startsWith('//') || path.startsWith('/')) {\n\t\t\treturn path;\n\t\t}\n\t\tif (!this.baseUrl) return path;\n\t\tconst base = this.baseUrl.endsWith('/') ? this.baseUrl : this.baseUrl + '/';\n\t\ttry {\n\t\t\treturn new URL(path, base).href;\n\t\t} catch {\n\t\t\treturn base + path;\n\t\t}\n\t}\n\n\tprivate post(type: Parameters<typeof createSandboxEnvelope>[0], payload: unknown): void {\n\t\tif (!this.connection) return;\n\t\tthis.connection.post(createSandboxEnvelope(type, payload));\n\t}\n\n\tprivate resetConnection(): void {\n\t\tif (this.handshakeTimer !== undefined) {\n\t\t\tclearTimeout(this.handshakeTimer);\n\t\t\tthis.handshakeTimer = undefined;\n\t\t}\n\t\tthis.stopMessages?.();\n\t\tthis.stopMessages = null;\n\t\tthis.connection?.dispose();\n\t\tthis.connection = null;\n\t\tthis.handshook = false;\n\t\tthis.moduleReady = false;\n\t}\n\n\tprivate armHandshakeTimeout(): void {\n\t\tif (this.handshakeTimer !== undefined) clearTimeout(this.handshakeTimer);\n\t\tthis.handshakeTimer = setTimeout(() => {\n\t\t\tthis.handshakeTimer = undefined;\n\t\t\tif (this.disposed || this.moduleReady) return;\n\t\t\t// A frame that never became ready (or a module that never loaded) is\n\t\t\t// reported but not torn down: a late load still recovers the interaction.\n\t\t\t// Not a PciLoadError — no authored path was attempted yet.\n\t\t\tthis.emitError(\n\t\t\t\tnew Error(`PCI runner frame did not become ready within ${this.handshakeTimeoutMs}ms`)\n\t\t\t);\n\t\t}, this.handshakeTimeoutMs);\n\t}\n\n\tprivate emitError(error: Error): void {\n\t\tfor (const handler of this.errorHandlers) handler(error);\n\t}\n\n\tprivate handleMessage(data: unknown): void {\n\t\tif (!isPciSandboxEnvelope(data)) return;\n\t\tswitch (data.type) {\n\t\t\tcase 'runner-ready': {\n\t\t\t\tif (this.handshook) return;\n\t\t\t\tthis.handshook = true;\n\t\t\t\t// Sent in order: the runner locks on `hello` before `init` arrives.\n\t\t\t\tthis.post('hello', { parentOrigin: this.parentOrigin() });\n\t\t\t\tif (this.pendingInit) this.post('init', this.pendingInit);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'module-loaded': {\n\t\t\t\tthis.moduleReady = true;\n\t\t\t\tif (this.handshakeTimer !== undefined) {\n\t\t\t\t\tclearTimeout(this.handshakeTimer);\n\t\t\t\t\tthis.handshakeTimer = undefined;\n\t\t\t\t}\n\t\t\t\tif (this.queuedInstantiate) {\n\t\t\t\t\tthis.post('instantiate', this.queuedInstantiate);\n\t\t\t\t\tthis.queuedInstantiate = null;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'module-error': {\n\t\t\t\tconst message =\n\t\t\t\t\ttypeof (data.payload as { message?: unknown })?.message === 'string'\n\t\t\t\t\t\t? (data.payload as { message: string }).message\n\t\t\t\t\t\t: 'unknown error';\n\t\t\t\tthis.emitError(\n\t\t\t\t\tnew PciLoadError(\n\t\t\t\t\t\tthis.data.primaryPath,\n\t\t\t\t\t\tthis.data.fallbackPath,\n\t\t\t\t\t\tnew Error(message)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'instance-ready': {\n\t\t\t\tthis.applySnapshot(data.payload);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'ready': {\n\t\t\t\tthis.applySnapshot(data.payload);\n\t\t\t\tif (this.proxy) {\n\t\t\t\t\tthis.currentConfiguration?.onready(this.proxy, (data.payload as { state?: unknown }).state);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'done': {\n\t\t\t\tthis.applySnapshot(data.payload);\n\t\t\t\tif (this.proxy) {\n\t\t\t\t\tthis.currentConfiguration?.ondone(this.proxy, (data.payload as { state?: unknown }).state);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'response-change': {\n\t\t\t\tthis.applySnapshot(data.payload);\n\t\t\t\tconst state = (data.payload as { state?: unknown }).state;\n\t\t\t\tfor (const handler of this.reportHandlers) handler({ state });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'instance-error': {\n\t\t\t\tconst message =\n\t\t\t\t\ttypeof (data.payload as { message?: unknown })?.message === 'string'\n\t\t\t\t\t\t? (data.payload as { message: string }).message\n\t\t\t\t\t\t: 'unknown error';\n\t\t\t\tthis.emitError(new Error(`PCI runner failed to instantiate: ${message}`));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'resize': {\n\t\t\t\tconst height = (data.payload as { height?: unknown })?.height;\n\t\t\t\tif (typeof height === 'number') this.connection?.setHeight(height);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t}\n\n\t/** Take a bridge snapshot into the cache the proxy reads from. */\n\tprivate applySnapshot(payload: unknown): void {\n\t\tif (typeof payload !== 'object' || payload === null) return;\n\t\tconst snapshot = payload as { response?: unknown; state?: unknown };\n\t\tif ('response' in snapshot) this.cache.response = snapshot.response ?? null;\n\t\tif ('state' in snapshot && snapshot.state !== undefined) this.cache.state = snapshot.state;\n\t}\n}\n\nfunction defaultParentOrigin(): string {\n\treturn globalThis.location?.origin ?? '';\n}\n\n/** The frame's accessible name: the PCI type's tail, locale-neutral by nature. */\nfunction frameTitle(data: ExtractedPci): string {\n\tconst typeIdentifier = data.customInteractionTypeIdentifier;\n\tconst tail = typeIdentifier.split(/[/:#]/).pop();\n\treturn tail && tail.length > 0 ? `Interactive content: ${tail}` : 'Interactive content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QAAQ,IAAI,QAAQ,CAAC,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,CAAC,KAAK,GAAG,QAAQ,CAAC,KAAK,CAAC;IAC5F,CAAC;CACD;AAED,SAAS,mBAAmB;IAC3B,OAAO,UAAU,CAAC,QAAQ,EAAE,MAAM,IAAI,EAAE,CAAC;AAC1C,CAAC;AAED,kFAAkF;AAClF,SAAS,UAAU,CAAC,IAAkB;IACrC,MAAM,cAAc,GAAG,IAAI,CAAC,+BAA+B,CAAC;IAC5D,MAAM,IAAI,GAAG,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC;IACjD,OAAO,IAAI,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,wBAAwB,IAAI,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAAC;AACzF,CAAC","sourcesContent":["import type { PciLoadContext, PciModuleSession } from '../moduleSession.js';\nimport type {\n\tExtractedPci,\n\tPciFrameConnector,\n\tPciModulePolicy,\n\tPciSandboxConfiguration,\n\tQtiPciConfiguration,\n\tQtiPciInstance,\n} from '../types.js';\nimport { PciLoadError } from '../types.js';\nimport { htmlToString, sanitizeSharedHtml } from '../../security/index.js';\nimport { createIframeFrameConnector } from './iframeConnector.js';\nimport { pciEntryModule, resolvePciModuleUrl } from '../modulePaths.js';\nimport { languageDirection } from '@pie-qti/i18n';\nimport {\n\tcreateSandboxEnvelope,\n\tisPciSandboxEnvelope,\n\ttype PciSandboxInitPayload,\n\ttype PciSandboxInstantiatePayload,\n\ttype PciSandboxModuleEntryPayload,\n} from './protocol.js';\n\nconst DEFAULT_HANDSHAKE_TIMEOUT_MS = 15000;\nconst DEFAULT_POLL_INTERVAL_MS = 250;\nconst DEFAULT_REGISTRATION_TIMEOUT_MS = 5000;\n\nexport interface SandboxedSessionOptions {\n\tsandbox: PciSandboxConfiguration;\n\tdata: ExtractedPci;\n\tbaseUrl: string;\n\t/** Policy gate applied to module URLs before anything is handed to the frame. */\n\tmodulePolicy?: PciModulePolicy;\n\t/** The page origin the runner locks to; injectable for tests. */\n\tparentOrigin?: () => string;\n\t/** Frame connection factory; defaults to a real sandboxed iframe. */\n\tframeConnector?: PciFrameConnector;\n\t/** The item's content language; the frame document states it instead of assuming English. */\n\tcontentLanguage?: string;\n}\n\ntype RemoteReportHandler = (report: { state?: unknown }) => void;\ntype ErrorHandler = (error: Error) => void;\n\n/**\n * The sandboxed engine: the module runs in a cross-origin runner frame\n * (`@pie-qti/pci-runner` deployed on a cookieless origin) and every contract\n * call crosses the postMessage bridge.\n *\n * Nothing here evaluates module code. Module URLs are resolved against the\n * package base, checked against the optional policy, and handed to the runner,\n * which loads them in its own opaque-origin document. `getResponse()` stays\n * synchronous for `PciHost` by answering from a cache the runner maintains:\n * pushes on every observed change, plus a bounded poll as the freshness floor.\n */\nexport class SandboxedPciSession implements PciModuleSession {\n\tprivate readonly runnerUrl: string;\n\tprivate readonly handshakeTimeoutMs: number;\n\tprivate readonly pollIntervalMs: number;\n\tprivate readonly registrationTimeoutMs: number;\n\tprivate readonly data: ExtractedPci;\n\tprivate readonly baseUrl: string;\n\tprivate readonly modulePolicy: PciModulePolicy | undefined;\n\tprivate readonly parentOrigin: () => string;\n\tprivate readonly connector: PciFrameConnector;\n\tprivate readonly contentLanguage: string | undefined;\n\n\tprivate connection: ReturnType<PciFrameConnector> | null = null;\n\tprivate pendingInit: PciSandboxInitPayload | null = null;\n\tprivate handshook = false;\n\tprivate moduleReady = false;\n\tprivate handshakeTimer: ReturnType<typeof setTimeout> | undefined;\n\tprivate queuedInstantiate: PciSandboxInstantiatePayload | null = null;\n\tprivate currentConfiguration: QtiPciConfiguration | null = null;\n\t/** The proxy `PciHost`'s state machine talks to; reads answer from the cache. */\n\tprivate proxy: (QtiPciInstance & { disable?(): void; enable?(): void }) | null = null;\n\tprivate readonly cache: { response: unknown; state: unknown } = { response: null, state: undefined };\n\tprivate readonly reportHandlers = new Set<RemoteReportHandler>();\n\tprivate readonly errorHandlers = new Set<ErrorHandler>();\n\tprivate stopMessages: (() => void) | null = null;\n\tprivate disposed = false;\n\n\tconstructor(options: SandboxedSessionOptions) {\n\t\tthis.runnerUrl = options.sandbox.runnerUrl;\n\t\tthis.handshakeTimeoutMs = options.sandbox.handshakeTimeoutMs ?? DEFAULT_HANDSHAKE_TIMEOUT_MS;\n\t\tthis.pollIntervalMs = options.sandbox.pollIntervalMs ?? DEFAULT_POLL_INTERVAL_MS;\n\t\tthis.registrationTimeoutMs =\n\t\t\toptions.sandbox.registrationTimeoutMs ?? DEFAULT_REGISTRATION_TIMEOUT_MS;\n\t\tthis.data = options.data;\n\t\tthis.baseUrl = options.baseUrl;\n\t\tthis.modulePolicy = options.modulePolicy;\n\t\tthis.parentOrigin = options.parentOrigin ?? defaultParentOrigin;\n\t\tthis.connector = options.frameConnector ?? createIframeFrameConnector();\n\t\tthis.contentLanguage = options.contentLanguage;\n\n\t\t// Config errors surface at construction, before any frame exists.\n\t\tlet runnerOrigin: URL;\n\t\ttry {\n\t\t\trunnerOrigin = new URL(this.runnerUrl);\n\t\t} catch {\n\t\t\tthrow new Error(`PCI sandbox runnerUrl must be an absolute URL: '${this.runnerUrl}'`);\n\t\t}\n\t\tif (runnerOrigin.protocol !== 'https:' && runnerOrigin.protocol !== 'http:') {\n\t\t\tthrow new Error(`PCI sandbox runnerUrl must be http(s): '${this.runnerUrl}'`);\n\t\t}\n\t}\n\n\t/** {@inheritdoc PciModuleSession.load} */\n\tpublic async load(_context: PciLoadContext): Promise<void> {\n\t\tif (this.disposed) throw new Error('Cannot load a destroyed PciHost');\n\t\t// Preparing the init payload resolves every authored path and runs the\n\t\t// policy gate before a frame exists; the module itself loads in the frame,\n\t\t// and its failures surface through onError.\n\t\tthis.pendingInit = this.buildInitPayload();\n\t}\n\n\t/** {@inheritdoc PciModuleSession.instantiate} */\n\tpublic instantiate(\n\t\tdom: HTMLElement,\n\t\tconfiguration: QtiPciConfiguration,\n\t\tstate: unknown\n\t): QtiPciInstance | undefined {\n\t\tif (this.disposed || !this.pendingInit) return undefined;\n\t\tthis.currentConfiguration = configuration;\n\n\t\tif (!this.connection || !this.connection.isAttached()) {\n\t\t\t// First mount, or the renderer's scaffold reset removed the frame.\n\t\t\tthis.resetConnection();\n\t\t\tthis.connection = this.connector(this.runnerUrl, frameTitle(this.data));\n\t\t\tthis.stopMessages = this.connection.onMessage((data) => this.handleMessage(data));\n\t\t\tdom.replaceChildren();\n\t\t\tthis.connection.appendTo(dom);\n\t\t\tthis.armHandshakeTimeout();\n\t\t}\n\n\t\t// A fresh read of the seeded state keeps the proxy honest before the\n\t\t// instance's first report arrives.\n\t\tthis.cache.response = null;\n\t\tthis.cache.state = undefined;\n\t\tthis.proxy = {\n\t\t\tgetResponse: () => this.cache.response,\n\t\t\tgetState: () => this.cache.state,\n\t\t\tdisable: () => this.post('set-enabled', { enabled: false }),\n\t\t\tenable: () => this.post('set-enabled', { enabled: true }),\n\t\t};\n\n\t\tconst payload: PciSandboxInstantiatePayload = {\n\t\t\tresponseIdentifier: configuration.responseIdentifier,\n\t\t\tstatus: configuration.status,\n\t\t\tproperties: configuration.properties,\n\t\t\t...(configuration.templateVariables !== undefined\n\t\t\t\t? { templateVariables: configuration.templateVariables }\n\t\t\t\t: {}),\n\t\t\t...(configuration.contextVariables !== undefined\n\t\t\t\t? { contextVariables: configuration.contextVariables }\n\t\t\t\t: {}),\n\t\t\t...(state !== undefined ? { state } : {}),\n\t\t};\n\t\tif (this.moduleReady) {\n\t\t\t// Runner messages are handled in arrival order, so an in-frame instance\n\t\t\t// from a previous instantiation is torn down before this one is created.\n\t\t\tthis.post('teardown-instance', {});\n\t\t\tthis.post('instantiate', payload);\n\t\t} else {\n\t\t\tthis.queuedInstantiate = payload;\n\t\t}\n\t\treturn this.proxy;\n\t}\n\n\t/** {@inheritdoc PciModuleSession.destroyInstance} */\n\tpublic destroyInstance(_instance: QtiPciInstance): void {\n\t\tif (this.connection && this.moduleReady) {\n\t\t\tthis.post('teardown-instance', {});\n\t\t}\n\t\tthis.cache.response = null;\n\t\tthis.cache.state = undefined;\n\t\tthis.proxy = null;\n\t}\n\n\t/** {@inheritdoc PciModuleSession.dispose} */\n\tpublic dispose(): void {\n\t\tif (this.connection) {\n\t\t\tthis.post('dispose', {});\n\t\t}\n\t\tthis.resetConnection();\n\t\tthis.disposed = true;\n\t\tthis.pendingInit = null;\n\t\tthis.currentConfiguration = null;\n\t\tthis.queuedInstantiate = null;\n\t}\n\n\t/** {@inheritdoc PciModuleSession.onRemoteReport} */\n\tpublic onRemoteReport(handler: RemoteReportHandler): () => void {\n\t\tthis.reportHandlers.add(handler);\n\t\treturn () => this.reportHandlers.delete(handler);\n\t}\n\n\t/** {@inheritdoc PciModuleSession.onError} */\n\tpublic onError(handler: ErrorHandler): () => void {\n\t\tthis.errorHandlers.add(handler);\n\t\treturn () => this.errorHandlers.delete(handler);\n\t}\n\n\t// ---------------------------------------------------------------------------\n\t// Private helpers\n\t// ---------------------------------------------------------------------------\n\n\tprivate buildInitPayload(): PciSandboxInitPayload {\n\t\tconst entries: PciSandboxModuleEntryPayload[] = this.data.modules\n\t\t\t.filter((module) => module.primaryPath)\n\t\t\t.map((module) => {\n\t\t\t\tconst primaryUrl = this.resolveChecked(module.primaryPath, 'primary');\n\t\t\t\treturn {\n\t\t\t\t\tid: module.id || module.primaryPath,\n\t\t\t\t\tprimaryUrl,\n\t\t\t\t\t...(module.fallbackPath\n\t\t\t\t\t\t? { fallbackUrl: this.resolveChecked(module.fallbackPath, 'fallback') }\n\t\t\t\t\t\t: {}),\n\t\t\t\t};\n\t\t\t});\n\t\tconst entry = pciEntryModule(this.data);\n\t\tconst markup = this.data.markup;\n\t\treturn {\n\t\t\ttypeIdentifier: this.data.customInteractionTypeIdentifier,\n\t\t\tmodules: entries,\n\t\t\tentryId: entry?.id || this.data.primaryPath,\n\t\t\t...(this.data.resolutionConfigPath\n\t\t\t\t? { resolutionConfigUrl: this.resolveUrl(this.data.resolutionConfigPath) }\n\t\t\t\t: {}),\n\t\t\tbaseUrl: this.baseUrl,\n\t\t\t// The frame states the item's content language and direction instead of\n\t\t\t// assuming English/LTR (WCAG 3.1.1, 3.1.2), and carries the same title the\n\t\t\t// page-realm scaffold gives the frame element.\n\t\t\t...(this.contentLanguage\n\t\t\t\t? {\n\t\t\t\t\t\tlanguage: this.contentLanguage,\n\t\t\t\t\t\tdirection: languageDirection(this.contentLanguage),\n\t\t\t\t\t\tframeTitle: frameTitle(this.data),\n\t\t\t\t\t}\n\t\t\t\t: {}),\n\t\t\t// The frame renders this as its interaction markup; the same sanitizer\n\t\t\t// the page-realm scaffold uses runs before it crosses the bridge.\n\t\t\tmarkup: htmlToString(sanitizeSharedHtml(htmlToString(markup))),\n\t\t\tregistrationTimeoutMs: this.registrationTimeoutMs,\n\t\t\tpollIntervalMs: this.pollIntervalMs,\n\t\t};\n\t}\n\n\t/** Resolve one authored path and run the policy gate on the absolute URL. */\n\tprivate resolveChecked(path: string, kind: 'primary' | 'fallback'): string {\n\t\tconst resolved = this.resolveUrl(path);\n\t\tif (this.modulePolicy) {\n\t\t\tthis.modulePolicy(resolved, {\n\t\t\t\tauthoredPath: path,\n\t\t\t\tkind,\n\t\t\t\tresponseIdentifier: this.data.responseIdentifier,\n\t\t\t\tcustomInteractionTypeIdentifier: this.data.customInteractionTypeIdentifier,\n\t\t\t});\n\t\t}\n\t\treturn resolved;\n\t}\n\n\tprivate resolveUrl(path: string): string {\n\t\treturn resolvePciModuleUrl(path, this.baseUrl);\n\t}\n\n\tprivate post(type: Parameters<typeof createSandboxEnvelope>[0], payload: unknown): void {\n\t\tif (!this.connection) return;\n\t\tthis.connection.post(createSandboxEnvelope(type, payload));\n\t}\n\n\tprivate resetConnection(): void {\n\t\tif (this.handshakeTimer !== undefined) {\n\t\t\tclearTimeout(this.handshakeTimer);\n\t\t\tthis.handshakeTimer = undefined;\n\t\t}\n\t\tthis.stopMessages?.();\n\t\tthis.stopMessages = null;\n\t\tthis.connection?.dispose();\n\t\tthis.connection = null;\n\t\tthis.handshook = false;\n\t\tthis.moduleReady = false;\n\t}\n\n\tprivate armHandshakeTimeout(): void {\n\t\tif (this.handshakeTimer !== undefined) clearTimeout(this.handshakeTimer);\n\t\tthis.handshakeTimer = setTimeout(() => {\n\t\t\tthis.handshakeTimer = undefined;\n\t\t\tif (this.disposed || this.moduleReady) return;\n\t\t\t// A frame that never became ready (or a module that never loaded) is\n\t\t\t// reported but not torn down: a late load still recovers the interaction.\n\t\t\t// Not a PciLoadError — no authored path was attempted yet.\n\t\t\tthis.emitError(\n\t\t\t\tnew Error(`PCI runner frame did not become ready within ${this.handshakeTimeoutMs}ms`)\n\t\t\t);\n\t\t}, this.handshakeTimeoutMs);\n\t}\n\n\tprivate emitError(error: Error): void {\n\t\tfor (const handler of this.errorHandlers) handler(error);\n\t}\n\n\tprivate handleMessage(data: unknown): void {\n\t\tif (!isPciSandboxEnvelope(data)) return;\n\t\tswitch (data.type) {\n\t\t\tcase 'runner-ready': {\n\t\t\t\tif (this.handshook) return;\n\t\t\t\tthis.handshook = true;\n\t\t\t\t// Sent in order: the runner locks on `hello` before `init` arrives.\n\t\t\t\tthis.post('hello', { parentOrigin: this.parentOrigin() });\n\t\t\t\tif (this.pendingInit) this.post('init', this.pendingInit);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'module-loaded': {\n\t\t\t\tthis.moduleReady = true;\n\t\t\t\tif (this.handshakeTimer !== undefined) {\n\t\t\t\t\tclearTimeout(this.handshakeTimer);\n\t\t\t\t\tthis.handshakeTimer = undefined;\n\t\t\t\t}\n\t\t\t\tif (this.queuedInstantiate) {\n\t\t\t\t\tthis.post('instantiate', this.queuedInstantiate);\n\t\t\t\t\tthis.queuedInstantiate = null;\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'module-error': {\n\t\t\t\tconst message =\n\t\t\t\t\ttypeof (data.payload as { message?: unknown })?.message === 'string'\n\t\t\t\t\t\t? (data.payload as { message: string }).message\n\t\t\t\t\t\t: 'unknown error';\n\t\t\t\tthis.emitError(\n\t\t\t\t\tnew PciLoadError(\n\t\t\t\t\t\tthis.data.primaryPath,\n\t\t\t\t\t\tthis.data.fallbackPath,\n\t\t\t\t\t\tnew Error(message)\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'instance-ready': {\n\t\t\t\tthis.applySnapshot(data.payload);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'ready': {\n\t\t\t\tthis.applySnapshot(data.payload);\n\t\t\t\tif (this.proxy) {\n\t\t\t\t\tthis.currentConfiguration?.onready(this.proxy, (data.payload as { state?: unknown }).state);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'done': {\n\t\t\t\tthis.applySnapshot(data.payload);\n\t\t\t\tif (this.proxy) {\n\t\t\t\t\tthis.currentConfiguration?.ondone(this.proxy, (data.payload as { state?: unknown }).state);\n\t\t\t\t}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'response-change': {\n\t\t\t\tthis.applySnapshot(data.payload);\n\t\t\t\tconst state = (data.payload as { state?: unknown }).state;\n\t\t\t\tfor (const handler of this.reportHandlers) handler({ state });\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'instance-error': {\n\t\t\t\tconst message =\n\t\t\t\t\ttypeof (data.payload as { message?: unknown })?.message === 'string'\n\t\t\t\t\t\t? (data.payload as { message: string }).message\n\t\t\t\t\t\t: 'unknown error';\n\t\t\t\tthis.emitError(new Error(`PCI runner failed to instantiate: ${message}`));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcase 'resize': {\n\t\t\t\tconst height = (data.payload as { height?: unknown })?.height;\n\t\t\t\tif (typeof height === 'number') this.connection?.setHeight(height);\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\treturn;\n\t\t}\n\t}\n\n\t/** Take a bridge snapshot into the cache the proxy reads from. */\n\tprivate applySnapshot(payload: unknown): void {\n\t\tif (typeof payload !== 'object' || payload === null) return;\n\t\tconst snapshot = payload as { response?: unknown; state?: unknown };\n\t\tif ('response' in snapshot) this.cache.response = snapshot.response ?? null;\n\t\tif ('state' in snapshot && snapshot.state !== undefined) this.cache.state = snapshot.state;\n\t}\n}\n\nfunction defaultParentOrigin(): string {\n\treturn globalThis.location?.origin ?? '';\n}\n\n/** The frame's accessible name: the PCI type's tail, locale-neutral by nature. */\nfunction frameTitle(data: ExtractedPci): string {\n\tconst typeIdentifier = data.customInteractionTypeIdentifier;\n\tconst tail = typeIdentifier.split(/[/:#]/).pop();\n\treturn tail && tail.length > 0 ? `Interactive content: ${tail}` : 'Interactive content';\n}\n"]}
|
|
@@ -4,10 +4,24 @@ import type { PciFrameConnector } from '../types.js';
|
|
|
4
4
|
* per PCI, loaded from the runner origin. Without `allow-same-origin` the
|
|
5
5
|
* frame's document has an opaque origin — it shares no storage, cookies, or
|
|
6
6
|
* DOM with the player — while its base URL stays the runner URL, so authored
|
|
7
|
-
* relative asset paths still resolve inside it.
|
|
7
|
+
* relative asset paths still resolve inside it. An opaque origin serializes as
|
|
8
|
+
* the string `"null"` and never compares equal to a tuple origin.
|
|
8
9
|
*
|
|
9
|
-
* Incoming messages are accepted only when `event.
|
|
10
|
-
*
|
|
11
|
-
*
|
|
10
|
+
* Incoming messages are accepted only when `event.source` is this frame's
|
|
11
|
+
* `contentWindow` — the identity anchor, because a sender cannot forge a
|
|
12
|
+
* source window — and `event.origin` is the runner origin or the opaque
|
|
13
|
+
* `"null"` serialization. This frame is always `allow-scripts`-only, so every
|
|
14
|
+
* message it sends carries `"null"`; filtering both spellings keeps the origin
|
|
15
|
+
* check meaningful (a foreign origin is still rejected) without dropping the
|
|
16
|
+
* only origin this frame can ever produce.
|
|
17
|
+
*
|
|
18
|
+
* Outgoing messages are posted to this frame's `contentWindow` with target
|
|
19
|
+
* origin `'*'`. A tuple target origin can never match the frame's opaque
|
|
20
|
+
* origin, so a locked target would silently drop every message and the
|
|
21
|
+
* handshake could never complete. The recipient is bounded by the target
|
|
22
|
+
* window: only this frame receives it, and a scripts-only sandboxed frame has
|
|
23
|
+
* no access to parent state. The runner answers through the same window it was
|
|
24
|
+
* reached by, and the `hello` handshake carries the parent origin so the frame
|
|
25
|
+
* can verify where it talks to.
|
|
12
26
|
*/
|
|
13
27
|
export declare function createIframeFrameConnector(): PciFrameConnector;
|
|
@@ -1,13 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a sandboxed frame's opaque origin serializes in `event.origin`. Without
|
|
3
|
+
* `allow-same-origin` the frame's document has no tuple origin at all, so it
|
|
4
|
+
* never equals the runner origin this connector is built from.
|
|
5
|
+
*/
|
|
6
|
+
const OPAQUE_ORIGIN = 'null';
|
|
1
7
|
/**
|
|
2
8
|
* The production `PciFrameConnector`: one `<iframe sandbox="allow-scripts">`
|
|
3
9
|
* per PCI, loaded from the runner origin. Without `allow-same-origin` the
|
|
4
10
|
* frame's document has an opaque origin — it shares no storage, cookies, or
|
|
5
11
|
* DOM with the player — while its base URL stays the runner URL, so authored
|
|
6
|
-
* relative asset paths still resolve inside it.
|
|
12
|
+
* relative asset paths still resolve inside it. An opaque origin serializes as
|
|
13
|
+
* the string `"null"` and never compares equal to a tuple origin.
|
|
14
|
+
*
|
|
15
|
+
* Incoming messages are accepted only when `event.source` is this frame's
|
|
16
|
+
* `contentWindow` — the identity anchor, because a sender cannot forge a
|
|
17
|
+
* source window — and `event.origin` is the runner origin or the opaque
|
|
18
|
+
* `"null"` serialization. This frame is always `allow-scripts`-only, so every
|
|
19
|
+
* message it sends carries `"null"`; filtering both spellings keeps the origin
|
|
20
|
+
* check meaningful (a foreign origin is still rejected) without dropping the
|
|
21
|
+
* only origin this frame can ever produce.
|
|
7
22
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
23
|
+
* Outgoing messages are posted to this frame's `contentWindow` with target
|
|
24
|
+
* origin `'*'`. A tuple target origin can never match the frame's opaque
|
|
25
|
+
* origin, so a locked target would silently drop every message and the
|
|
26
|
+
* handshake could never complete. The recipient is bounded by the target
|
|
27
|
+
* window: only this frame receives it, and a scripts-only sandboxed frame has
|
|
28
|
+
* no access to parent state. The runner answers through the same window it was
|
|
29
|
+
* reached by, and the `hello` handshake carries the parent origin so the frame
|
|
30
|
+
* can verify where it talks to.
|
|
11
31
|
*/
|
|
12
32
|
export function createIframeFrameConnector() {
|
|
13
33
|
return (frameUrl, title) => new IframeFrameConnection(frameUrl, title);
|
|
@@ -47,9 +67,14 @@ class IframeFrameConnection {
|
|
|
47
67
|
this.windowListener = (event) => {
|
|
48
68
|
if (this.disposed)
|
|
49
69
|
return;
|
|
70
|
+
// Identity anchor: only this frame's window may be the source — a sender
|
|
71
|
+
// cannot forge it. The origin comparison is the secondary check: this
|
|
72
|
+
// frame's opaque origin serializes as "null" and never equals the runner
|
|
73
|
+
// tuple origin, so a frame message legitimately arrives under either
|
|
74
|
+
// spelling while a foreign origin still matches neither.
|
|
50
75
|
if (event.source !== this.frame.contentWindow)
|
|
51
76
|
return;
|
|
52
|
-
if (event.origin !== this.frameOrigin)
|
|
77
|
+
if (event.origin !== this.frameOrigin && event.origin !== OPAQUE_ORIGIN)
|
|
53
78
|
return;
|
|
54
79
|
for (const handler of this.handlers)
|
|
55
80
|
handler(event.data);
|
|
@@ -60,7 +85,11 @@ class IframeFrameConnection {
|
|
|
60
85
|
}
|
|
61
86
|
/** {@inheritdoc PciFrameConnection.post} */
|
|
62
87
|
post(message) {
|
|
63
|
-
|
|
88
|
+
// Target origin '*': the frame's origin is opaque, so no tuple target can
|
|
89
|
+
// ever match it and a locked target would drop every message. The recipient
|
|
90
|
+
// is bounded by posting to this frame's contentWindow only, and identity in
|
|
91
|
+
// the reply direction is anchored on `event.source`, not the target origin.
|
|
92
|
+
this.frame.contentWindow?.postMessage(message, '*');
|
|
64
93
|
}
|
|
65
94
|
/** {@inheritdoc PciFrameConnection.appendTo} */
|
|
66
95
|
appendTo(target) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"iframeConnector.js","sourceRoot":"","sources":["../../../src/pci/sandbox/iframeConnector.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"iframeConnector.js","sourceRoot":"","sources":["../../../src/pci/sandbox/iframeConnector.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,aAAa,GAAG,MAAM,CAAC;AAE7B;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,0BAA0B;IACzC,OAAO,CAAC,QAAgB,EAAE,KAAa,EAAE,EAAE,CAAC,IAAI,qBAAqB,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AACxF,CAAC;AAED,MAAM,qBAAqB;IAG1B,8EAA8E;IAC9E,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC;IACjC,CAAC;IAOD,YAAY,QAAgB,EAAE,KAAa;QAJ1B,aAAQ,GAAG,IAAI,GAAG,EAA2B,CAAC;QAEvD,aAAQ,GAAG,KAAK,CAAC;QAGxB,IAAI,GAAQ,CAAC;QACb,IAAI,CAAC;YACJ,GAAG,GAAG,IAAI,GAAG,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;QAAC,MAAM,CAAC;YACR,MAAM,IAAI,KAAK,CAAC,mDAAmD,QAAQ,GAAG,CAAC,CAAC;QACjF,CAAC;QACD,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,EAAE,CAAC;YAC3D,MAAM,IAAI,KAAK,CAAC,2CAA2C,QAAQ,GAAG,CAAC,CAAC;QACzE,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC;QAE9B,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAC/C,+EAA+E;QAC/E,yCAAyC;QACzC,KAAK,CA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;IACrD,CAAC;IAED,gDAAgD;IACzC,QAAQ,CAAC,MAAmB;QAClC,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED,kDAAkD;IAC3C,UAAU;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC;IAC/B,CAAC;IAED,iDAAiD;IAC1C,SAAS,CAAC,MAAc;QAC9B,IAAI,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,MAAM,IAAI,CAAC,EAAE,CAAC;YAC5C,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;QACpD,CAAC;IACF,CAAC;IAED,iDAAiD;IAC1C,SAAS,CAAC,OAAgC;QAChD,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3B,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAC5C,CAAC;IAED,+CAA+C;IACxC,OAAO;QACb,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,CAAC;QACtB,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;YACnC,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,CAAC;QAC5D,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;IACrB,CAAC;CACD","sourcesContent":["import type { PciFrameConnection, PciFrameConnector } from '../types.js';\n\n/**\n * How a sandboxed frame's opaque origin serializes in `event.origin`. Without\n * `allow-same-origin` the frame's document has no tuple origin at all, so it\n * never equals the runner origin this connector is built from.\n */\nconst OPAQUE_ORIGIN = 'null';\n\n/**\n * The production `PciFrameConnector`: one `<iframe sandbox=\"allow-scripts\">`\n * per PCI, loaded from the runner origin. Without `allow-same-origin` the\n * frame's document has an opaque origin — it shares no storage, cookies, or\n * DOM with the player — while its base URL stays the runner URL, so authored\n * relative asset paths still resolve inside it. An opaque origin serializes as\n * the string `\"null\"` and never compares equal to a tuple origin.\n *\n * Incoming messages are accepted only when `event.source` is this frame's\n * `contentWindow` — the identity anchor, because a sender cannot forge a\n * source window — and `event.origin` is the runner origin or the opaque\n * `\"null\"` serialization. This frame is always `allow-scripts`-only, so every\n * message it sends carries `\"null\"`; filtering both spellings keeps the origin\n * check meaningful (a foreign origin is still rejected) without dropping the\n * only origin this frame can ever produce.\n *\n * Outgoing messages are posted to this frame's `contentWindow` with target\n * origin `'*'`. A tuple target origin can never match the frame's opaque\n * origin, so a locked target would silently drop every message and the\n * handshake could never complete. The recipient is bounded by the target\n * window: only this frame receives it, and a scripts-only sandboxed frame has\n * no access to parent state. The runner answers through the same window it was\n * reached by, and the `hello` handshake carries the parent origin so the frame\n * can verify where it talks to.\n */\nexport function createIframeFrameConnector(): PciFrameConnector {\n\treturn (frameUrl: string, title: string) => new IframeFrameConnection(frameUrl, title);\n}\n\nclass IframeFrameConnection implements PciFrameConnection {\n\tpublic readonly frameOrigin: string;\n\n\t/** The identity incoming events are filtered against: this frame's window. */\n\tpublic get source(): unknown {\n\t\treturn this.frame.contentWindow;\n\t}\n\n\tprivate readonly frame: HTMLIFrameElement;\n\tprivate readonly handlers = new Set<(data: unknown) => void>();\n\tprivate readonly windowListener: (event: MessageEvent) => void;\n\tprivate disposed = false;\n\n\tconstructor(frameUrl: string, title: string) {\n\t\tlet url: URL;\n\t\ttry {\n\t\t\turl = new URL(frameUrl);\n\t\t} catch {\n\t\t\tthrow new Error(`PCI sandbox runnerUrl must be an absolute URL: '${frameUrl}'`);\n\t\t}\n\t\tif (url.protocol !== 'https:' && url.protocol !== 'http:') {\n\t\t\tthrow new Error(`PCI sandbox runnerUrl must be http(s): '${frameUrl}'`);\n\t\t}\n\t\tthis.frameOrigin = url.origin;\n\n\t\tconst frame = document.createElement('iframe');\n\t\t// `allow-scripts` alone: a frame carrying it together with `allow-same-origin`\n\t\t// could strip its own sandbox attribute.\n\t\tframe.setAttribute('sandbox', 'allow-scripts');\n\t\tframe.src = frameUrl;\n\t\tframe.title = title;\n\t\tframe.style.width = '100%';\n\t\tframe.style.border = '0';\n\t\tframe.style.display = 'block';\n\t\t// The runner reports the interaction's height; until then the frame stays\n\t\t// out of the layout's way.\n\t\tframe.style.height = '0px';\n\t\tthis.frame = frame;\n\n\t\tthis.windowListener = (event: MessageEvent) => {\n\t\t\tif (this.disposed) return;\n\t\t\t// Identity anchor: only this frame's window may be the source — a sender\n\t\t\t// cannot forge it. The origin comparison is the secondary check: this\n\t\t\t// frame's opaque origin serializes as \"null\" and never equals the runner\n\t\t\t// tuple origin, so a frame message legitimately arrives under either\n\t\t\t// spelling while a foreign origin still matches neither.\n\t\t\tif (event.source !== this.frame.contentWindow) return;\n\t\t\tif (event.origin !== this.frameOrigin && event.origin !== OPAQUE_ORIGIN) return;\n\t\t\tfor (const handler of this.handlers) handler(event.data);\n\t\t};\n\t\tif (typeof window !== 'undefined') {\n\t\t\twindow.addEventListener('message', this.windowListener);\n\t\t}\n\t}\n\n\t/** {@inheritdoc PciFrameConnection.post} */\n\tpublic post(message: unknown): void {\n\t\t// Target origin '*': the frame's origin is opaque, so no tuple target can\n\t\t// ever match it and a locked target would drop every message. The recipient\n\t\t// is bounded by posting to this frame's contentWindow only, and identity in\n\t\t// the reply direction is anchored on `event.source`, not the target origin.\n\t\tthis.frame.contentWindow?.postMessage(message, '*');\n\t}\n\n\t/** {@inheritdoc PciFrameConnection.appendTo} */\n\tpublic appendTo(target: HTMLElement): void {\n\t\ttarget.appendChild(this.frame);\n\t}\n\n\t/** {@inheritdoc PciFrameConnection.isAttached} */\n\tpublic isAttached(): boolean {\n\t\treturn this.frame.isConnected;\n\t}\n\n\t/** {@inheritdoc PciFrameConnection.setHeight} */\n\tpublic setHeight(height: number): void {\n\t\tif (Number.isFinite(height) && height >= 0) {\n\t\t\tthis.frame.style.height = `${Math.ceil(height)}px`;\n\t\t}\n\t}\n\n\t/** {@inheritdoc PciFrameConnection.onMessage} */\n\tpublic onMessage(handler: (data: unknown) => void): () => void {\n\t\tthis.handlers.add(handler);\n\t\treturn () => this.handlers.delete(handler);\n\t}\n\n\t/** {@inheritdoc PciFrameConnection.dispose} */\n\tpublic dispose(): void {\n\t\tthis.disposed = true;\n\t\tthis.handlers.clear();\n\t\tif (typeof window !== 'undefined') {\n\t\t\twindow.removeEventListener('message', this.windowListener);\n\t\t}\n\t\tthis.frame.remove();\n\t}\n}\n"]}
|
|
@@ -60,6 +60,20 @@ export interface PciSandboxInitPayload {
|
|
|
60
60
|
baseUrl: string;
|
|
61
61
|
/** The interaction markup, already sanitized by the host. */
|
|
62
62
|
markup: string;
|
|
63
|
+
/**
|
|
64
|
+
* The language tag the runner frame's document is written in (the item's content
|
|
65
|
+
* language), so the frame states its language instead of assuming one (WCAG 3.1.1).
|
|
66
|
+
* Absent when the item declares no content language: the frame then keeps the runner
|
|
67
|
+
* page's static language.
|
|
68
|
+
*/
|
|
69
|
+
language?: string;
|
|
70
|
+
/** The directionality of the frame's content, set on the frame document with `language`. */
|
|
71
|
+
direction?: 'ltr' | 'rtl';
|
|
72
|
+
/**
|
|
73
|
+
* The frame document's accessible name, localized by the host (the runner cannot
|
|
74
|
+
* reach i18n catalogs). Optional: absent leaves the runner's static title.
|
|
75
|
+
*/
|
|
76
|
+
frameTitle?: string;
|
|
63
77
|
/** Milliseconds the runner waits for the module to register. */
|
|
64
78
|
registrationTimeoutMs: number;
|
|
65
79
|
/** How often the runner pushes response/state reads. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/pci/sandbox/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAA8B,CAAC;AACnE,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../../../src/pci/sandbox/protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,MAAM,CAAC,MAAM,oBAAoB,GAAG,qBAA8B,CAAC;AACnE,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAgB,CAAC;AA8J7D,MAAM,UAAU,qBAAqB,CACpC,IAAW,EACX,OAAiB;IAEjB,OAAO;QACN,QAAQ,EAAE,oBAAoB;QAC9B,OAAO,EAAE,4BAA4B;QACrC,IAAI;QACJ,OAAO;KACP,CAAC;AACH,CAAC;AAED,SAAS,QAAQ,CAAC,KAAc;IAC/B,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACpD,CAAC;AAED,gFAAgF;AAChF,MAAM,UAAU,oBAAoB,CAAC,KAAc;IAClD,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACnC,IAAI,KAAK,CAAC,QAAQ,KAAK,oBAAoB;QAAE,OAAO,KAAK,CAAC;IAC1D,IAAI,KAAK,CAAC,OAAO,KAAK,4BAA4B;QAAE,OAAO,KAAK,CAAC;IACjE,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IACjD,IAAI,CAAC,CAAC,SAAS,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACxC,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/**\n * PCI sandbox bridge protocol (host page ⇄ runner frame).\n *\n * The sandboxed engine runs a PCI module inside `<iframe sandbox=\"allow-scripts\">`\n * loaded from a dedicated runner origin (`@pie-qti/pci-runner`). The frame's\n * document has an opaque origin, so every contract call crosses `postMessage`:\n * this module defines the versioned envelope and payload shapes both sides\n * speak. Like `src/iframe/protocol.ts`, it contains no DOM globals and can be\n * imported anywhere.\n *\n * Origin locking is mutual and rooted at each side's structural facts:\n *\n * - The host accepts a message only when `event.origin` equals the runner\n * URL's origin **and** `event.source` is the frame's `contentWindow`.\n * - The runner accepts its first message only from its `window.parent`, locks\n * to that message's `event.origin`, and sends everything to that origin.\n *\n * `runner-ready` is the one message posted without a locked origin (the runner\n * cannot know its parent before the first exchange). It carries no secrets —\n * it only announces the protocol version.\n */\n\nexport const PCI_SANDBOX_PROTOCOL = 'pie-qti-pci-sandbox' as const;\nexport const PCI_SANDBOX_PROTOCOL_VERSION = '0.1.0' as const;\n\nexport type PciSandboxProtocolVersion = typeof PCI_SANDBOX_PROTOCOL_VERSION;\n\nexport type PciSandboxHostToRunnerType =\n\t| 'hello'\n\t| 'init'\n\t| 'instantiate'\n\t| 'set-enabled'\n\t| 'teardown-instance'\n\t| 'dispose';\n\nexport type PciSandboxRunnerToHostType =\n\t| 'runner-ready'\n\t| 'module-loaded'\n\t| 'module-error'\n\t| 'instance-ready'\n\t| 'instance-error'\n\t| 'ready'\n\t| 'done'\n\t| 'response-change'\n\t| 'resize';\n\nexport type PciSandboxMessageType = PciSandboxHostToRunnerType | PciSandboxRunnerToHostType;\n\nexport interface PciSandboxEnvelope<\n\tTType extends PciSandboxMessageType = PciSandboxMessageType,\n\tTPayload = unknown,\n> {\n\tprotocol: typeof PCI_SANDBOX_PROTOCOL;\n\tversion: PciSandboxProtocolVersion;\n\ttype: TType;\n\tpayload: TPayload;\n}\n\n/** runner → host, immediately when the runner page loads. */\nexport interface PciSandboxRunnerReadyPayload {\n\truntime?: string;\n}\n\n/** host → runner, locking the runner to the page's origin. */\nexport interface PciSandboxHelloPayload {\n\t/** The origin the runner must send every subsequent message to. */\n\tparentOrigin: string;\n}\n\n/** One authored `qti-interaction-module` entry, resolved to absolute URLs. */\nexport interface PciSandboxModuleEntryPayload {\n\tid: string;\n\tprimaryUrl: string;\n\tfallbackUrl?: string;\n}\n\n/** host → runner: load the resolution config and the entry module. */\nexport interface PciSandboxInitPayload {\n\t/** The `customInteractionTypeIdentifier` whose registration instantiates. */\n\ttypeIdentifier: string;\n\t/** Authored module entries, paths resolved to absolute URLs. */\n\tmodules: PciSandboxModuleEntryPayload[];\n\t/** The id of the entry module whose registration instantiates. */\n\tentryId: string;\n\t/** Absolute resolution-config URL, when the item authored one. */\n\tresolutionConfigUrl?: string;\n\t/** Package base URL; relative config paths and module assets resolve against it. */\n\tbaseUrl: string;\n\t/** The interaction markup, already sanitized by the host. */\n\tmarkup: string;\n\t/**\n\t * The language tag the runner frame's document is written in (the item's content\n\t * language), so the frame states its language instead of assuming one (WCAG 3.1.1).\n\t * Absent when the item declares no content language: the frame then keeps the runner\n\t * page's static language.\n\t */\n\tlanguage?: string;\n\t/** The directionality of the frame's content, set on the frame document with `language`. */\n\tdirection?: 'ltr' | 'rtl';\n\t/**\n\t * The frame document's accessible name, localized by the host (the runner cannot\n\t * reach i18n catalogs). Optional: absent leaves the runner's static title.\n\t */\n\tframeTitle?: string;\n\t/** Milliseconds the runner waits for the module to register. */\n\tregistrationTimeoutMs: number;\n\t/** How often the runner pushes response/state reads. */\n\tpollIntervalMs: number;\n}\n\n/** host → runner: instantiate the interaction. */\nexport interface PciSandboxInstantiatePayload {\n\tresponseIdentifier: string;\n\tstatus: string;\n\tproperties: Record<string, string>;\n\ttemplateVariables?: Record<string, unknown>;\n\tcontextVariables?: Record<string, unknown>;\n\t/** The QTI variable JSON (or module state) this instantiation is seeded with. */\n\tstate?: unknown;\n}\n\n/** host → runner. */\nexport interface PciSandboxSetEnabledPayload {\n\tenabled: boolean;\n}\n\n/** Response and state exactly as the module reports them (QTI variable JSON). */\nexport interface PciSandboxSnapshotPayload {\n\tresponse: unknown;\n\tstate?: unknown;\n}\n\n/** runner → host: the module registered. */\nexport interface PciSandboxModuleLoadedPayload {\n\ttypeIdentifier: string;\n}\n\n/** runner → host: module load or registration failed. */\nexport interface PciSandboxModuleErrorPayload {\n\tmessage: string;\n}\n\n/** runner → host: `getInstance` returned. */\nexport interface PciSandboxInstanceReadyPayload extends PciSandboxSnapshotPayload {}\n\n/** runner → host: `getInstance` threw. */\nexport interface PciSandboxInstanceErrorPayload {\n\tmessage: string;\n}\n\n/** runner → host: the module called `onready`/`ondone`. */\nexport interface PciSandboxLifecyclePayload extends PciSandboxSnapshotPayload {\n\t/** The state argument the module passed, if any. */\n\tstate?: unknown;\n}\n\n/** runner → host: poll or lifecycle observed a changed read. */\nexport interface PciSandboxResponseChangePayload extends PciSandboxSnapshotPayload {}\n\n/** runner → host: the interaction's content resized. */\nexport interface PciSandboxResizePayload {\n\theight: number;\n}\n\nexport type PciSandboxMessage =\n\t| PciSandboxEnvelope<'runner-ready', PciSandboxRunnerReadyPayload>\n\t| PciSandboxEnvelope<'hello', PciSandboxHelloPayload>\n\t| PciSandboxEnvelope<'init', PciSandboxInitPayload>\n\t| PciSandboxEnvelope<'instantiate', PciSandboxInstantiatePayload>\n\t| PciSandboxEnvelope<'set-enabled', PciSandboxSetEnabledPayload>\n\t| PciSandboxEnvelope<'teardown-instance', Record<string, never>>\n\t| PciSandboxEnvelope<'dispose', Record<string, never>>\n\t| PciSandboxEnvelope<'module-loaded', PciSandboxModuleLoadedPayload>\n\t| PciSandboxEnvelope<'module-error', PciSandboxModuleErrorPayload>\n\t| PciSandboxEnvelope<'instance-ready', PciSandboxInstanceReadyPayload>\n\t| PciSandboxEnvelope<'instance-error', PciSandboxInstanceErrorPayload>\n\t| PciSandboxEnvelope<'ready', PciSandboxLifecyclePayload>\n\t| PciSandboxEnvelope<'done', PciSandboxLifecyclePayload>\n\t| PciSandboxEnvelope<'response-change', PciSandboxResponseChangePayload>\n\t| PciSandboxEnvelope<'resize', PciSandboxResizePayload>;\n\nexport function createSandboxEnvelope<TType extends PciSandboxMessageType, TPayload>(\n\ttype: TType,\n\tpayload: TPayload\n): PciSandboxEnvelope<TType, TPayload> {\n\treturn {\n\t\tprotocol: PCI_SANDBOX_PROTOCOL,\n\t\tversion: PCI_SANDBOX_PROTOCOL_VERSION,\n\t\ttype,\n\t\tpayload,\n\t};\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n\treturn typeof value === 'object' && value !== null;\n}\n\n/** Shallow envelope check; payload fields are validated where they are used. */\nexport function isPciSandboxEnvelope(value: unknown): value is PciSandboxEnvelope {\n\tif (!isRecord(value)) return false;\n\tif (value.protocol !== PCI_SANDBOX_PROTOCOL) return false;\n\tif (value.version !== PCI_SANDBOX_PROTOCOL_VERSION) return false;\n\tif (typeof value.type !== 'string') return false;\n\tif (!('payload' in value)) return false;\n\treturn true;\n}\n"]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The session-side PCI host registry: the PciHost a mounted custom interaction uses,
|
|
3
|
+
* its response write-back into the session's declarations, and teardown.
|
|
4
|
+
*/
|
|
5
|
+
import type { BaseType, Cardinality, DeclarationMap, QtiValue } from '@pie-qti/qti-processing';
|
|
6
|
+
import type { ItemLifecycleStatus } from '../types/index.js';
|
|
7
|
+
import { PciHost } from './PciHost.js';
|
|
8
|
+
import type { ExtractedPci, PciConfiguration, PciInteractionStatus } from './types.js';
|
|
9
|
+
/** What the PCI session registry reads from the session engine. */
|
|
10
|
+
export interface PciSessionContext {
|
|
11
|
+
readonly pci?: PciConfiguration;
|
|
12
|
+
readonly decls: DeclarationMap;
|
|
13
|
+
/** The session's lifecycle stage, read when a module reports a response. */
|
|
14
|
+
lifecycleStatus(): ItemLifecycleStatus;
|
|
15
|
+
/** The QTI 3.0 §6.1 interaction status a host instantiates with. */
|
|
16
|
+
interactionStatus(): PciInteractionStatus;
|
|
17
|
+
contentLanguage(): string | undefined;
|
|
18
|
+
coerceToDeclarationValue(baseType: BaseType | undefined, cardinality: Cardinality, raw: unknown, identifier?: string): QtiValue;
|
|
19
|
+
/** Called after a module's response was written into the declarations. */
|
|
20
|
+
onResponseApplied?(responseIdentifier: string): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The PciHosts of one item session, by response identifier. Created as presentation
|
|
24
|
+
* mounts custom interactions; destroyed with the session.
|
|
25
|
+
*/
|
|
26
|
+
export declare class PciHostSession {
|
|
27
|
+
private readonly hosts;
|
|
28
|
+
get(responseIdentifier: string): PciHost | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Create a PciHost for an extracted PCI and register it for response tracking.
|
|
31
|
+
* The caller is responsible for calling host.load() and
|
|
32
|
+
* host.initialize(domNode) once the DOM element is available.
|
|
33
|
+
*/
|
|
34
|
+
create(data: ExtractedPci, context: PciSessionContext): PciHost;
|
|
35
|
+
/**
|
|
36
|
+
* Offer a response value to the PCI identified by responseIdentifier. A
|
|
37
|
+
* mounted module that has already reported a response keeps it.
|
|
38
|
+
*/
|
|
39
|
+
offer(responseIdentifier: string, value: unknown): void;
|
|
40
|
+
/**
|
|
41
|
+
* Authoritatively replace a PCI's response, discarding in-progress candidate
|
|
42
|
+
* state. Session restore and reset-to-default use this.
|
|
43
|
+
*/
|
|
44
|
+
restore(responseIdentifier: string, value: unknown): void;
|
|
45
|
+
/** Destroy all PCI hosts. Call on session teardown. */
|
|
46
|
+
destroyAll(): void;
|
|
47
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { PciHost } from './PciHost.js';
|
|
2
|
+
/**
|
|
3
|
+
* The PciHosts of one item session, by response identifier. Created as presentation
|
|
4
|
+
* mounts custom interactions; destroyed with the session.
|
|
5
|
+
*/
|
|
6
|
+
export class PciHostSession {
|
|
7
|
+
constructor() {
|
|
8
|
+
this.hosts = new Map();
|
|
9
|
+
}
|
|
10
|
+
get(responseIdentifier) {
|
|
11
|
+
return this.hosts.get(responseIdentifier);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Create a PciHost for an extracted PCI and register it for response tracking.
|
|
15
|
+
* The caller is responsible for calling host.load() and
|
|
16
|
+
* host.initialize(domNode) once the DOM element is available.
|
|
17
|
+
*/
|
|
18
|
+
create(data, context) {
|
|
19
|
+
const host = new PciHost(data, {
|
|
20
|
+
baseUrl: context.pci?.baseUrl,
|
|
21
|
+
moduleResolver: context.pci?.moduleResolver,
|
|
22
|
+
sandbox: context.pci?.sandbox,
|
|
23
|
+
modulePolicy: context.pci?.modulePolicy,
|
|
24
|
+
responseDeclaration: (() => {
|
|
25
|
+
const d = context.decls[data.responseIdentifier];
|
|
26
|
+
return d ? { baseType: d.baseType, cardinality: d.cardinality } : undefined;
|
|
27
|
+
})(),
|
|
28
|
+
status: () => context.interactionStatus(),
|
|
29
|
+
contentLanguage: context.contentLanguage(),
|
|
30
|
+
});
|
|
31
|
+
// Wire response changes back into the player's declaration context
|
|
32
|
+
host.onResponseChange((responseId, value) => {
|
|
33
|
+
if (context.lifecycleStatus() !== 'initial' && context.lifecycleStatus() !== 'interacting')
|
|
34
|
+
return;
|
|
35
|
+
const d = context.decls[responseId];
|
|
36
|
+
if (d) {
|
|
37
|
+
d.value = context.coerceToDeclarationValue(d.baseType, d.cardinality, value, d.identifier);
|
|
38
|
+
context.onResponseApplied?.(responseId);
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
this.hosts.set(data.responseIdentifier, host);
|
|
42
|
+
return host;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Offer a response value to the PCI identified by responseIdentifier. A
|
|
46
|
+
* mounted module that has already reported a response keeps it.
|
|
47
|
+
*/
|
|
48
|
+
offer(responseIdentifier, value) {
|
|
49
|
+
this.hosts.get(responseIdentifier)?.offerResponse(value);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Authoritatively replace a PCI's response, discarding in-progress candidate
|
|
53
|
+
* state. Session restore and reset-to-default use this.
|
|
54
|
+
*/
|
|
55
|
+
restore(responseIdentifier, value) {
|
|
56
|
+
this.hosts.get(responseIdentifier)?.restore(value);
|
|
57
|
+
}
|
|
58
|
+
/** Destroy all PCI hosts. Call on session teardown. */
|
|
59
|
+
destroyAll() {
|
|
60
|
+
for (const host of this.hosts.values()) {
|
|
61
|
+
host.destroy();
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,gBAAgB,CAAC,CAAC,UAAkB,EAAE,KAAc,EAAE,EAAE;YAC5D,IAAI,OAAO,CAAC,eAAe,EAAE,KAAK,SAAS,IAAI,OAAO,CAAC,eAAe,EAAE,KAAK,aAAa;gBAAE,OAAO;YACnG,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACpC,IAAI,CAAC,EAAE,CAAC;gBACP,CAAC,CAAC,KAAK,GAAG,OAAO,CAAC,wBAAwB,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC,UAAU,CAAC,CAAC;gBAC3F,OAAO,CAAC,iBAAiB,EAAE,CAAC,UAAU,CAAC,CAAC;YACzC,CAAC;QACF,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,kBAAkB,EAAE,IAAI,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IACb,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,kBAA0B,EAAE,KAAc;QAC/C,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,aAAa,CAAC,KAAK,CAAC,CAAC;IAC1D,CAAC;IAED;;;OAGG;IACH,OAAO,CAAC,kBAA0B,EAAE,KAAc;QACjD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;IACpD,CAAC;IAED,uDAAuD;IACvD,UAAU;QACT,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,CAAC;YACxC,IAAI,CAAC,OAAO,EAAE,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACpB,CAAC;CACD","sourcesContent":["/**\n * The session-side PCI host registry: the PciHost a mounted custom interaction uses,\n * its response write-back into the session's declarations, and teardown.\n */\nimport type { BaseType, Cardinality, DeclarationMap, QtiValue } from '@pie-qti/qti-processing';\nimport type { ItemLifecycleStatus } from '../types/index.js';\nimport { PciHost } from './PciHost.js';\nimport type { ExtractedPci, PciConfiguration, PciInteractionStatus } from './types.js';\n\n/** What the PCI session registry reads from the session engine. */\nexport interface PciSessionContext {\n\treadonly pci?: PciConfiguration;\n\treadonly decls: DeclarationMap;\n\t/** The session's lifecycle stage, read when a module reports a response. */\n\tlifecycleStatus(): ItemLifecycleStatus;\n\t/** The QTI 3.0 §6.1 interaction status a host instantiates with. */\n\tinteractionStatus(): PciInteractionStatus;\n\tcontentLanguage(): string | undefined;\n\tcoerceToDeclarationValue(\n\t\tbaseType: BaseType | undefined,\n\t\tcardinality: Cardinality,\n\t\traw: unknown,\n\t\tidentifier?: string,\n\t): QtiValue;\n\t/** Called after a module's response was written into the declarations. */\n\tonResponseApplied?(responseIdentifier: string): void;\n}\n\n/**\n * The PciHosts of one item session, by response identifier. Created as presentation\n * mounts custom interactions; destroyed with the session.\n */\nexport class PciHostSession {\n\tprivate readonly hosts = new Map<string, PciHost>();\n\n\tget(responseIdentifier: string): PciHost | undefined {\n\t\treturn this.hosts.get(responseIdentifier);\n\t}\n\n\t/**\n\t * Create a PciHost for an extracted PCI and register it for response tracking.\n\t * The caller is responsible for calling host.load() and\n\t * host.initialize(domNode) once the DOM element is available.\n\t */\n\tcreate(data: ExtractedPci, context: PciSessionContext): PciHost {\n\t\tconst host = new PciHost(data, {\n\t\t\tbaseUrl: context.pci?.baseUrl,\n\t\t\tmoduleResolver: context.pci?.moduleResolver,\n\t\t\tsandbox: context.pci?.sandbox,\n\t\t\tmodulePolicy: context.pci?.modulePolicy,\n\t\t\tresponseDeclaration: (() => {\n\t\t\t\tconst d = context.decls[data.responseIdentifier];\n\t\t\t\treturn d ? { baseType: d.baseType, cardinality: d.cardinality } : undefined;\n\t\t\t})(),\n\t\t\tstatus: () => context.interactionStatus(),\n\t\t\tcontentLanguage: context.contentLanguage(),\n\t\t});\n\n\t\t// Wire response changes back into the player's declaration context\n\t\thost.onResponseChange((responseId: string, value: unknown) => {\n\t\t\tif (context.lifecycleStatus() !== 'initial' && context.lifecycleStatus() !== 'interacting') return;\n\t\t\tconst d = context.decls[responseId];\n\t\t\tif (d) {\n\t\t\t\td.value = context.coerceToDeclarationValue(d.baseType, d.cardinality, value, d.identifier);\n\t\t\t\tcontext.onResponseApplied?.(responseId);\n\t\t\t}\n\t\t});\n\n\t\tthis.hosts.set(data.responseIdentifier, host);\n\t\treturn host;\n\t}\n\n\t/**\n\t * Offer a response value to the PCI identified by responseIdentifier. A\n\t * mounted module that has already reported a response keeps it.\n\t */\n\toffer(responseIdentifier: string, value: unknown): void {\n\t\tthis.hosts.get(responseIdentifier)?.offerResponse(value);\n\t}\n\n\t/**\n\t * Authoritatively replace a PCI's response, discarding in-progress candidate\n\t * state. Session restore and reset-to-default use this.\n\t */\n\trestore(responseIdentifier: string, value: unknown): void {\n\t\tthis.hosts.get(responseIdentifier)?.restore(value);\n\t}\n\n\t/** Destroy all PCI hosts. Call on session teardown. */\n\tdestroyAll(): void {\n\t\tfor (const host of this.hosts.values()) {\n\t\t\thost.destroy();\n\t\t}\n\t\tthis.hosts.clear();\n\t}\n}\n"]}
|
package/dist/pci/types.d.ts
CHANGED
|
@@ -194,7 +194,7 @@ export interface PciHostOptions {
|
|
|
194
194
|
* evaluates anything in the page; throwing denies the module.
|
|
195
195
|
*/
|
|
196
196
|
modulePolicy?: PciModulePolicy;
|
|
197
|
-
/** The bound response declaration
|
|
197
|
+
/** The bound response declaration; the held response seeds `getInstance` as QTI variable JSON by it. */
|
|
198
198
|
responseDeclaration?: PciResponseDeclarationInfo;
|
|
199
199
|
/**
|
|
200
200
|
* The interaction status `getInstance` receives, fixed at instantiation. A
|
|
@@ -213,6 +213,12 @@ export interface PciHostOptions {
|
|
|
213
213
|
frameConnector?: PciFrameConnector;
|
|
214
214
|
/** The page origin the runner locks to; defaults to `location.origin`. Tests inject one. */
|
|
215
215
|
parentOrigin?: () => string;
|
|
216
|
+
/**
|
|
217
|
+
* The item's content language, handed to a sandbox runner frame so its document
|
|
218
|
+
* states the language and direction instead of assuming English/LTR (WCAG 3.1.1,
|
|
219
|
+
* 3.1.2). The page realm needs no threading: content inherits the item's `lang`.
|
|
220
|
+
*/
|
|
221
|
+
contentLanguage?: string;
|
|
216
222
|
}
|
|
217
223
|
/**
|
|
218
224
|
* Registry observation: what the runtime uses to install the page's
|
package/dist/pci/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pci/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAgVH;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IACxD,YACiB,kBAA0B,EAC1B,YAAoB;QAEpC,KAAK,CACJ,gDAAgD,kBAAkB,KAAK;YACtE,4DAA4D,YAAY,IAAI,CAC7E,CAAC;QANc,uBAAkB,GAAlB,kBAAkB,CAAQ;QAC1B,iBAAY,GAAZ,YAAY,CAAQ;QAMpC,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC9C,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YACiB,WAAmB,EACnB,YAAgC,EAChD,KAAa;QAEb,KAAK,CACJ,YAAY;YACX,CAAC,CAAC,mCAAmC,WAAW,mBAAmB,YAAY,GAAG;YAClF,CAAC,CAAC,mCAAmC,WAAW,GAAG,CACpD,CAAC;QARc,gBAAW,GAAX,WAAW,CAAQ;QACnB,iBAAY,GAAZ,YAAY,CAAoB;QAQhD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,KAAK;YAAE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;IACvG,CAAC;CACD","sourcesContent":["/**\n * QTI 3.0 Portable Custom Interaction (PCI) types.\n *\n * The module-facing contract is the one QTI 3.0 §6.1 specifies: a module calls\n * `qtiCustomInteractionContext.register(...)` with a `typeIdentifier` and a\n * `getInstance(dom, configuration, state)` factory; the instance signals readiness\n * through `configuration.onready(instance, state)` and completion through\n * `configuration.ondone(...)`, and exposes `getResponse()` (QTI variable JSON) and\n * optionally `getState()`. AMD is the documented default module resolution\n * (phase 2); a host resolver decides whether a module is evaluated at all.\n */\n\nimport type { HtmlContent } from '../types/index.js';\nimport type { BaseType, Cardinality } from '@pie-qti/qti-processing';\n\n/** QTI 3.0 §6.1 interaction status, fixed at instantiation. */\nexport type PciInteractionStatus = 'interacting' | 'closed' | 'solution' | 'review';\n\n/**\n * An instance a conformant `getInstance` factory returns. `getResponse()` answers in\n * QTI variable JSON (`{ base: ... }` / `{ list: ... }` / `{ record: ... }`); `getState()`\n * snapshots whatever the module needs to reconstruct itself, read back through the\n * `state` argument of the next `getInstance`.\n */\nexport interface QtiPciInstance {\n\tgetResponse(): unknown;\n\tgetState?(): unknown;\n}\n\n/**\n * The configuration object the host passes to `getInstance`. `onready` reports the\n * module ready (optionally with its initial state); `ondone` reports the interaction\n * finished for the attempt, with its final response and state.\n */\nexport interface QtiPciConfiguration {\n\tresponseIdentifier: string;\n\tstatus: PciInteractionStatus;\n\t/** Key/value pairs from `qti-pci-properties`, keyed by their `identifier`. */\n\tproperties: Record<string, string>;\n\ttemplateVariables?: Record<string, unknown>;\n\tcontextVariables?: Record<string, unknown>;\n\tonready(instance: QtiPciInstance, state?: unknown): void;\n\tondone(instance: QtiPciInstance, state?: unknown): void;\n}\n\n/**\n * What a conformant PCI module registers: the global\n * `qtiCustomInteractionContext.register(registration)` call.\n */\nexport interface QtiCustomInteractionRegistration {\n\ttypeIdentifier: string;\n\tgetInstance(\n\t\tdom: HTMLElement,\n\t\tconfiguration: QtiPciConfiguration,\n\t\tstate?: unknown\n\t): QtiPciInstance | undefined;\n}\n\n/** The registry object the runtime installs as the page's `qtiCustomInteractionContext`. */\nexport interface PciCustomInteractionContext {\n\tregister(registration: QtiCustomInteractionRegistration): void;\n}\n\n/** Identifies which authored module path is currently being resolved. */\nexport type PciModulePathKind = 'primary' | 'fallback';\n\n/**\n * Context supplied to a host-owned PCI module resolver.\n *\n * PCI code executes with the authority of the page that loads it. The player therefore\n * never imports an authored URL by itself; an embedding host must decide which URLs or\n * package resources are trusted and return the loaded module explicitly. The module\n * registers itself as a side effect of evaluation, so the resolver's return value is\n * informational — registration is what counts.\n */\nexport interface PciModuleResolutionContext {\n\t/** Original path exactly as authored in the item. */\n\tauthoredPath: string;\n\t/** Whether this is the primary module or the authored fallback. */\n\tkind: PciModulePathKind;\n\t/** Response variable bound to the interaction. */\n\tresponseIdentifier: string;\n\t/** Portable interaction type identifier/URN. */\n\tcustomInteractionTypeIdentifier: string;\n}\n\n/**\n * Host-controlled PCI module resolution hook.\n *\n * The resolver may import an allow-listed URL, read a module from a verified content\n * package, or evaluate a pre-registered module. Whatever it returns, a conformant\n * module registers against `qtiCustomInteractionContext` as it evaluates.\n */\nexport type PciModuleResolver = (\n\tresolvedUrl: string,\n\tcontext: PciModuleResolutionContext\n) => Promise<unknown> | unknown;\n\n/**\n * Host-controlled PCI module policy — the sandboxed engine's variant of the\n * resolver. It decides *whether* an authored URL may be handed to the runner\n * frame at all and never evaluates anything in the page realm: the return value\n * is nothing, and throwing denies the module.\n */\nexport type PciModulePolicy = (\n\tresolvedUrl: string,\n\tcontext: PciModuleResolutionContext\n) => void;\n\n/**\n * Opt-in hardened execution for PCI modules (the sandboxed engine, plan\n * Option C). The module runs inside `<iframe sandbox=\"allow-scripts\">` loaded\n * from a dedicated cookieless runner origin, so its document has an opaque\n * origin: it shares no storage, cookies, or DOM with the player, while its\n * base URL stays the runner URL so authored relative asset paths still\n * resolve. `@pie-qti/pci-runner` is the deployable runner bundle.\n */\nexport interface PciSandboxConfiguration {\n\t/**\n\t * Absolute URL of the deployed runner page, for example\n\t * `https://qti.pie-framework.org/pci-runner.html`. The runner origin must\n\t * serve nothing else and set no cookies — there is nothing on it worth\n\t * reaching, which is the security property.\n\t */\n\trunnerUrl: string;\n\t/**\n\t * Milliseconds to wait for the runner handshake and the module's in-frame\n\t * load. Default 15000; a frame that never becomes ready fails through\n\t * `PciHostController.onError`.\n\t */\n\thandshakeTimeoutMs?: number;\n\t/**\n\t * How often the runner re-reads the instance's `getResponse()`/`getState()`\n\t * and pushes changes, in milliseconds. Default 250. `getResponse()` on the\n\t * host stays synchronous, so a submit reads the cache this poll maintains:\n\t * the response is at most one interval stale.\n\t */\n\tpollIntervalMs?: number;\n\t/**\n\t * Milliseconds the runner waits for the module to register after its code\n\t * evaluates. Default 5000; same semantics as the page-realm registration\n\t * timeout.\n\t */\n\tregistrationTimeoutMs?: number;\n}\n\n/**\n * A connection to one runner frame. The default implementation creates the\n * `<iframe sandbox=\"allow-scripts\">` element and wires `window` messaging;\n * tests inject an in-memory pair instead.\n */\nexport interface PciFrameConnection {\n\t/** The origin every runner message must carry. */\n\treadonly frameOrigin: string;\n\t/** The identity an incoming event's `source` must be to count as the frame. */\n\treadonly source: unknown;\n\t/** Send a structured-cloneable message to the frame, locked to its origin. */\n\tpost(message: unknown): void;\n\t/** Insert the frame into the interaction's mount node. */\n\tappendTo(target: HTMLElement): void;\n\t/** True while the frame's element is still in the document. */\n\tisAttached(): boolean;\n\t/** Messages from the frame, already filtered to its origin and source identity. */\n\tonMessage(handler: (data: unknown) => void): () => void;\n\t/** Remove the frame from the document and stop listening. */\n\tdispose(): void;\n\t/** Apply a runner-reported height, in CSS pixels. */\n\tsetHeight(height: number): void;\n}\n\n/** Creates the frame connection for a runner page URL. */\nexport type PciFrameConnector = (frameUrl: string, title: string) => PciFrameConnection;\n\n/** Secure-by-default PCI runtime configuration. */\nexport interface PciConfiguration {\n\t/** Directory URL used to resolve relative authored module paths. */\n\tbaseUrl?: string;\n\t/**\n\t * The host trust decision for executing a PCI module in the page realm.\n\t * Required unless `sandbox` is configured; a sandboxed engine never\n\t * evaluates module code in the page, so there is nothing for a resolver to\n\t * import. When both are configured the resolver is unused.\n\t */\n\tmoduleResolver?: PciModuleResolver;\n\t/**\n\t * Opt-in hardened execution in a sandboxed cross-origin frame. When set it\n\t * takes precedence over `moduleResolver`: the runner frame executes the\n\t * module with an opaque origin and the page never evaluates it.\n\t */\n\tsandbox?: PciSandboxConfiguration;\n\t/**\n\t * Optional allow-list applied to the module URLs handed to the sandbox\n\t * runner. Never evaluates anything; combine with `createAllowlistPciModulePolicy`.\n\t */\n\tmodulePolicy?: PciModulePolicy;\n}\n\n/** The response declaration shape a PCI's values convert against. */\nexport interface PciResponseDeclarationInfo {\n\tbaseType?: BaseType;\n\tcardinality: Cardinality;\n}\n\n/**\n * Low-level options accepted by PciHost.\n *\n * `moduleResolver` remains optional here so an unconfigured host can report the\n * secure-default error at load time. Public player configuration requires it.\n */\nexport interface PciHostOptions {\n\tbaseUrl?: string;\n\tmoduleResolver?: PciModuleResolver;\n\t/**\n\t * Run the module in a sandboxed cross-origin runner frame instead of the\n\t * page realm. Takes precedence over `moduleResolver`.\n\t */\n\tsandbox?: PciSandboxConfiguration;\n\t/**\n\t * Policy gate for the module URLs handed to a sandbox runner. Never\n\t * evaluates anything in the page; throwing denies the module.\n\t */\n\tmodulePolicy?: PciModulePolicy;\n\t/** The bound response declaration, for QTI variable JSON conversion at the boundary. */\n\tresponseDeclaration?: PciResponseDeclarationInfo;\n\t/**\n\t * The interaction status `getInstance` receives, fixed at instantiation. A\n\t * function is read at each instantiation, so a rebuild carries the current one.\n\t */\n\tstatus?: PciInteractionStatus | (() => PciInteractionStatus);\n\t/**\n\t * Milliseconds to wait for a module to register after its code evaluates.\n\t * Default 5000; a module that never registers fails the load. The sandboxed\n\t * engine forwards it to the runner frame.\n\t */\n\tregistrationTimeoutMs?: number;\n\t/** Registry observation override; tests inject one for isolation. */\n\tregistry?: PciRegistryObservation;\n\t/** Frame connection override; tests inject one instead of a real iframe. */\n\tframeConnector?: PciFrameConnector;\n\t/** The page origin the runner locks to; defaults to `location.origin`. Tests inject one. */\n\tparentOrigin?: () => string;\n}\n\n/**\n * Registry observation: what the runtime uses to install the page's\n * `qtiCustomInteractionContext` and await a module's registration.\n */\nexport interface PciRegistryObservation {\n\t/** Resolves with the registration for `typeIdentifier`; never rejects. */\n\twhenRegistered(typeIdentifier: string): Promise<QtiCustomInteractionRegistration>;\n\t/** The typeIdentifiers registered so far, in registration order. */\n\tregisteredTypes(): string[];\n\t/** Stop observing; pending `whenRegistered` promises stay pending. */\n\tdispose(): void;\n}\n\n/**\n * Public, structural contract exposed by a PCI host.\n *\n * Keep component boundaries typed against this interface rather than the concrete\n * PciHost class. That allows consumers to combine source and published package\n * entrypoints without TypeScript treating the class's private state as part of\n * the compatibility check.\n */\nexport interface PciHostController {\n\tonResponseChange(callback: (responseId: string, value: unknown) => void): () => void;\n\t/**\n\t * Fired when an authoritative `restore()` lands on a mounted module. The\n\t * renderer owns scaffold sanitization, so it resets the markup and calls\n\t * `remount()`.\n\t */\n\tonRemountRequest(callback: () => void): () => void;\n\t/**\n\t * Asynchronous failures that surface after `load()` resolved: the sandboxed\n\t * engine's frame handshake, in-frame module load, or instance errors. The\n\t * page-realm engine reports its failures by rejecting `load()` as before.\n\t */\n\tonError(callback: (error: Error) => void): () => void;\n\tload(): Promise<void>;\n\tinitialize(dom: HTMLElement): void;\n\t/** Rebuild the module in place from the held response, after a scaffold reset. */\n\tremount(dom: HTMLElement): Promise<void>;\n\t/** The current response, in the player's runtime value shape. */\n\tgetResponse(): unknown;\n\t/** The mounted module's state snapshot, when it exposes `getState()`. */\n\tgetState(): unknown;\n\t/**\n\t * Offer a response the player believes to be current. Declined, returning\n\t * `false`, once a mounted module has reported a response of its own: a live\n\t * interaction owns its response until something authoritative replaces it.\n\t */\n\tofferResponse(value: unknown): boolean;\n\t/**\n\t * Authoritatively replace the response, discarding in-progress candidate\n\t * state and returning ownership to the player. Session restore, reset to\n\t * declaration default, and explicit host overrides use this. A mounted module\n\t * is rebuilt through `onRemountRequest` where a renderer is wired to it, and\n\t * otherwise re-instantiated on the last mount node — the QTI 3.0 PCI contract\n\t * injects state at `getInstance` and offers no setter.\n\t */\n\trestore(value: unknown): void;\n\tdisable(): void;\n\tenable(): void;\n\tdestroy(): void;\n}\n\n/** One authored `qti-interaction-module` entry. */\nexport interface PciModuleEntry {\n\t/** The module id other modules' AMD dependencies refer to. */\n\tid: string;\n\tprimaryPath: string;\n\tfallbackPath?: string;\n}\n\n/**\n * Extracted data from a <qti-portable-custom-interaction> element.\n */\nexport interface ExtractedPci {\n\t/** responseIdentifier attribute value. */\n\tresponseIdentifier: string;\n\t/** customInteractionTypeIdentifier attribute value (URN identifying the PCI type). */\n\tcustomInteractionTypeIdentifier: string;\n\t/** Primary JS module path (required). The entry module's path. */\n\tprimaryPath: string;\n\t/** Fallback JS module path (optional). The entry module's fallback. */\n\tfallbackPath?: string;\n\t/**\n\t * All authored `qti-interaction-module` entries, in document order. A\n\t * multi-module PCI loads them through the AMD loader, whose `define` wires\n\t * the dependencies; the entry module is the one whose id matches the\n\t * customInteractionTypeIdentifier's tail.\n\t */\n\tmodules: PciModuleEntry[];\n\t/**\n\t * The `qti-interaction-modules@primary-configuration` reference: a module\n\t * resolution config file (RequireJS `paths` shape) that names the modules'\n\t * paths. When absent, the runtime tries the defined default locations under\n\t * the package base URL.\n\t */\n\tresolutionConfigPath?: string;\n\t/** Inner HTML of the <qti-interaction-markup> element. */\n\tmarkup: HtmlContent;\n\t/** Key/value pairs from <qti-pci-properties>/<qti-pci-property>. */\n\tconfig: Record<string, string>;\n}\n\n/**\n * Raised when PCI content is present but the embedding host has not opted into executing it.\n */\nexport class PciModuleResolverRequiredError extends Error {\n\tconstructor(\n\t\tpublic readonly responseIdentifier: string,\n\t\tpublic readonly authoredPath: string\n\t) {\n\t\tsuper(\n\t\t\t`PCI module loading is disabled for response '${responseIdentifier}'. ` +\n\t\t\t\t`Provide a host-controlled moduleResolver before loading '${authoredPath}'.`\n\t\t);\n\t\tthis.name = 'PciModuleResolverRequiredError';\n\t}\n}\n\n/**\n * Thrown when a PCI module fails to load from both primary and fallback paths.\n */\nexport class PciLoadError extends Error {\n\tconstructor(\n\t\tpublic readonly primaryPath: string,\n\t\tpublic readonly fallbackPath: string | undefined,\n\t\tcause?: Error\n\t) {\n\t\tsuper(\n\t\t\tfallbackPath\n\t\t\t\t? `PCI module failed to load from '${primaryPath}' and fallback '${fallbackPath}'`\n\t\t\t\t: `PCI module failed to load from '${primaryPath}'`\n\t\t);\n\t\tthis.name = 'PciLoadError';\n\t\tif (cause) Object.defineProperty(this, 'cause', { value: cause, writable: true, configurable: true });\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pci/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAsVH;;GAEG;AACH,MAAM,OAAO,8BAA+B,SAAQ,KAAK;IACxD,YACiB,kBAA0B,EAC1B,YAAoB;QAEpC,KAAK,CACJ,gDAAgD,kBAAkB,KAAK;YACtE,4DAA4D,YAAY,IAAI,CAC7E,CAAC;QANc,uBAAkB,GAAlB,kBAAkB,CAAQ;QAC1B,iBAAY,GAAZ,YAAY,CAAQ;QAMpC,IAAI,CAAC,IAAI,GAAG,gCAAgC,CAAC;IAC9C,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YACiB,WAAmB,EACnB,YAAgC,EAChD,KAAa;QAEb,KAAK,CACJ,YAAY;YACX,CAAC,CAAC,mCAAmC,WAAW,mBAAmB,YAAY,GAAG;YAClF,CAAC,CAAC,mCAAmC,WAAW,GAAG,CACpD,CAAC;QARc,gBAAW,GAAX,WAAW,CAAQ;QACnB,iBAAY,GAAZ,YAAY,CAAoB;QAQhD,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC3B,IAAI,KAAK;YAAE,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,OAAO,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC;IACvG,CAAC;CACD","sourcesContent":["/**\n * QTI 3.0 Portable Custom Interaction (PCI) types.\n *\n * The module-facing contract is the one QTI 3.0 §6.1 specifies: a module calls\n * `qtiCustomInteractionContext.register(...)` with a `typeIdentifier` and a\n * `getInstance(dom, configuration, state)` factory; the instance signals readiness\n * through `configuration.onready(instance, state)` and completion through\n * `configuration.ondone(...)`, and exposes `getResponse()` (QTI variable JSON) and\n * optionally `getState()`. AMD is the documented default module resolution\n * (phase 2); a host resolver decides whether a module is evaluated at all.\n */\n\nimport type { HtmlContent } from '../types/index.js';\nimport type { BaseType, Cardinality } from '@pie-qti/qti-processing';\n\n/** QTI 3.0 §6.1 interaction status, fixed at instantiation. */\nexport type PciInteractionStatus = 'interacting' | 'closed' | 'solution' | 'review';\n\n/**\n * An instance a conformant `getInstance` factory returns. `getResponse()` answers in\n * QTI variable JSON (`{ base: ... }` / `{ list: ... }` / `{ record: ... }`); `getState()`\n * snapshots whatever the module needs to reconstruct itself, read back through the\n * `state` argument of the next `getInstance`.\n */\nexport interface QtiPciInstance {\n\tgetResponse(): unknown;\n\tgetState?(): unknown;\n}\n\n/**\n * The configuration object the host passes to `getInstance`. `onready` reports the\n * module ready (optionally with its initial state); `ondone` reports the interaction\n * finished for the attempt, with its final response and state.\n */\nexport interface QtiPciConfiguration {\n\tresponseIdentifier: string;\n\tstatus: PciInteractionStatus;\n\t/** Key/value pairs from `qti-pci-properties`, keyed by their `identifier`. */\n\tproperties: Record<string, string>;\n\ttemplateVariables?: Record<string, unknown>;\n\tcontextVariables?: Record<string, unknown>;\n\tonready(instance: QtiPciInstance, state?: unknown): void;\n\tondone(instance: QtiPciInstance, state?: unknown): void;\n}\n\n/**\n * What a conformant PCI module registers: the global\n * `qtiCustomInteractionContext.register(registration)` call.\n */\nexport interface QtiCustomInteractionRegistration {\n\ttypeIdentifier: string;\n\tgetInstance(\n\t\tdom: HTMLElement,\n\t\tconfiguration: QtiPciConfiguration,\n\t\tstate?: unknown\n\t): QtiPciInstance | undefined;\n}\n\n/** The registry object the runtime installs as the page's `qtiCustomInteractionContext`. */\nexport interface PciCustomInteractionContext {\n\tregister(registration: QtiCustomInteractionRegistration): void;\n}\n\n/** Identifies which authored module path is currently being resolved. */\nexport type PciModulePathKind = 'primary' | 'fallback';\n\n/**\n * Context supplied to a host-owned PCI module resolver.\n *\n * PCI code executes with the authority of the page that loads it. The player therefore\n * never imports an authored URL by itself; an embedding host must decide which URLs or\n * package resources are trusted and return the loaded module explicitly. The module\n * registers itself as a side effect of evaluation, so the resolver's return value is\n * informational — registration is what counts.\n */\nexport interface PciModuleResolutionContext {\n\t/** Original path exactly as authored in the item. */\n\tauthoredPath: string;\n\t/** Whether this is the primary module or the authored fallback. */\n\tkind: PciModulePathKind;\n\t/** Response variable bound to the interaction. */\n\tresponseIdentifier: string;\n\t/** Portable interaction type identifier/URN. */\n\tcustomInteractionTypeIdentifier: string;\n}\n\n/**\n * Host-controlled PCI module resolution hook.\n *\n * The resolver may import an allow-listed URL, read a module from a verified content\n * package, or evaluate a pre-registered module. Whatever it returns, a conformant\n * module registers against `qtiCustomInteractionContext` as it evaluates.\n */\nexport type PciModuleResolver = (\n\tresolvedUrl: string,\n\tcontext: PciModuleResolutionContext\n) => Promise<unknown> | unknown;\n\n/**\n * Host-controlled PCI module policy — the sandboxed engine's variant of the\n * resolver. It decides *whether* an authored URL may be handed to the runner\n * frame at all and never evaluates anything in the page realm: the return value\n * is nothing, and throwing denies the module.\n */\nexport type PciModulePolicy = (\n\tresolvedUrl: string,\n\tcontext: PciModuleResolutionContext\n) => void;\n\n/**\n * Opt-in hardened execution for PCI modules (the sandboxed engine, plan\n * Option C). The module runs inside `<iframe sandbox=\"allow-scripts\">` loaded\n * from a dedicated cookieless runner origin, so its document has an opaque\n * origin: it shares no storage, cookies, or DOM with the player, while its\n * base URL stays the runner URL so authored relative asset paths still\n * resolve. `@pie-qti/pci-runner` is the deployable runner bundle.\n */\nexport interface PciSandboxConfiguration {\n\t/**\n\t * Absolute URL of the deployed runner page, for example\n\t * `https://qti.pie-framework.org/pci-runner.html`. The runner origin must\n\t * serve nothing else and set no cookies — there is nothing on it worth\n\t * reaching, which is the security property.\n\t */\n\trunnerUrl: string;\n\t/**\n\t * Milliseconds to wait for the runner handshake and the module's in-frame\n\t * load. Default 15000; a frame that never becomes ready fails through\n\t * `PciHostController.onError`.\n\t */\n\thandshakeTimeoutMs?: number;\n\t/**\n\t * How often the runner re-reads the instance's `getResponse()`/`getState()`\n\t * and pushes changes, in milliseconds. Default 250. `getResponse()` on the\n\t * host stays synchronous, so a submit reads the cache this poll maintains:\n\t * the response is at most one interval stale.\n\t */\n\tpollIntervalMs?: number;\n\t/**\n\t * Milliseconds the runner waits for the module to register after its code\n\t * evaluates. Default 5000; same semantics as the page-realm registration\n\t * timeout.\n\t */\n\tregistrationTimeoutMs?: number;\n}\n\n/**\n * A connection to one runner frame. The default implementation creates the\n * `<iframe sandbox=\"allow-scripts\">` element and wires `window` messaging;\n * tests inject an in-memory pair instead.\n */\nexport interface PciFrameConnection {\n\t/** The origin every runner message must carry. */\n\treadonly frameOrigin: string;\n\t/** The identity an incoming event's `source` must be to count as the frame. */\n\treadonly source: unknown;\n\t/** Send a structured-cloneable message to the frame, locked to its origin. */\n\tpost(message: unknown): void;\n\t/** Insert the frame into the interaction's mount node. */\n\tappendTo(target: HTMLElement): void;\n\t/** True while the frame's element is still in the document. */\n\tisAttached(): boolean;\n\t/** Messages from the frame, already filtered to its origin and source identity. */\n\tonMessage(handler: (data: unknown) => void): () => void;\n\t/** Remove the frame from the document and stop listening. */\n\tdispose(): void;\n\t/** Apply a runner-reported height, in CSS pixels. */\n\tsetHeight(height: number): void;\n}\n\n/** Creates the frame connection for a runner page URL. */\nexport type PciFrameConnector = (frameUrl: string, title: string) => PciFrameConnection;\n\n/** Secure-by-default PCI runtime configuration. */\nexport interface PciConfiguration {\n\t/** Directory URL used to resolve relative authored module paths. */\n\tbaseUrl?: string;\n\t/**\n\t * The host trust decision for executing a PCI module in the page realm.\n\t * Required unless `sandbox` is configured; a sandboxed engine never\n\t * evaluates module code in the page, so there is nothing for a resolver to\n\t * import. When both are configured the resolver is unused.\n\t */\n\tmoduleResolver?: PciModuleResolver;\n\t/**\n\t * Opt-in hardened execution in a sandboxed cross-origin frame. When set it\n\t * takes precedence over `moduleResolver`: the runner frame executes the\n\t * module with an opaque origin and the page never evaluates it.\n\t */\n\tsandbox?: PciSandboxConfiguration;\n\t/**\n\t * Optional allow-list applied to the module URLs handed to the sandbox\n\t * runner. Never evaluates anything; combine with `createAllowlistPciModulePolicy`.\n\t */\n\tmodulePolicy?: PciModulePolicy;\n}\n\n/** The response declaration shape a PCI's values convert against. */\nexport interface PciResponseDeclarationInfo {\n\tbaseType?: BaseType;\n\tcardinality: Cardinality;\n}\n\n/**\n * Low-level options accepted by PciHost.\n *\n * `moduleResolver` remains optional here so an unconfigured host can report the\n * secure-default error at load time. Public player configuration requires it.\n */\nexport interface PciHostOptions {\n\tbaseUrl?: string;\n\tmoduleResolver?: PciModuleResolver;\n\t/**\n\t * Run the module in a sandboxed cross-origin runner frame instead of the\n\t * page realm. Takes precedence over `moduleResolver`.\n\t */\n\tsandbox?: PciSandboxConfiguration;\n\t/**\n\t * Policy gate for the module URLs handed to a sandbox runner. Never\n\t * evaluates anything in the page; throwing denies the module.\n\t */\n\tmodulePolicy?: PciModulePolicy;\n\t/** The bound response declaration; the held response seeds `getInstance` as QTI variable JSON by it. */\n\tresponseDeclaration?: PciResponseDeclarationInfo;\n\t/**\n\t * The interaction status `getInstance` receives, fixed at instantiation. A\n\t * function is read at each instantiation, so a rebuild carries the current one.\n\t */\n\tstatus?: PciInteractionStatus | (() => PciInteractionStatus);\n\t/**\n\t * Milliseconds to wait for a module to register after its code evaluates.\n\t * Default 5000; a module that never registers fails the load. The sandboxed\n\t * engine forwards it to the runner frame.\n\t */\n\tregistrationTimeoutMs?: number;\n\t/** Registry observation override; tests inject one for isolation. */\n\tregistry?: PciRegistryObservation;\n\t/** Frame connection override; tests inject one instead of a real iframe. */\n\tframeConnector?: PciFrameConnector;\n\t/** The page origin the runner locks to; defaults to `location.origin`. Tests inject one. */\n\tparentOrigin?: () => string;\n\t/**\n\t * The item's content language, handed to a sandbox runner frame so its document\n\t * states the language and direction instead of assuming English/LTR (WCAG 3.1.1,\n\t * 3.1.2). The page realm needs no threading: content inherits the item's `lang`.\n\t */\n\tcontentLanguage?: string;\n}\n\n/**\n * Registry observation: what the runtime uses to install the page's\n * `qtiCustomInteractionContext` and await a module's registration.\n */\nexport interface PciRegistryObservation {\n\t/** Resolves with the registration for `typeIdentifier`; never rejects. */\n\twhenRegistered(typeIdentifier: string): Promise<QtiCustomInteractionRegistration>;\n\t/** The typeIdentifiers registered so far, in registration order. */\n\tregisteredTypes(): string[];\n\t/** Stop observing; pending `whenRegistered` promises stay pending. */\n\tdispose(): void;\n}\n\n/**\n * Public, structural contract exposed by a PCI host.\n *\n * Keep component boundaries typed against this interface rather than the concrete\n * PciHost class. That allows consumers to combine source and published package\n * entrypoints without TypeScript treating the class's private state as part of\n * the compatibility check.\n */\nexport interface PciHostController {\n\tonResponseChange(callback: (responseId: string, value: unknown) => void): () => void;\n\t/**\n\t * Fired when an authoritative `restore()` lands on a mounted module. The\n\t * renderer owns scaffold sanitization, so it resets the markup and calls\n\t * `remount()`.\n\t */\n\tonRemountRequest(callback: () => void): () => void;\n\t/**\n\t * Asynchronous failures that surface after `load()` resolved: the sandboxed\n\t * engine's frame handshake, in-frame module load, or instance errors. The\n\t * page-realm engine reports its failures by rejecting `load()` as before.\n\t */\n\tonError(callback: (error: Error) => void): () => void;\n\tload(): Promise<void>;\n\tinitialize(dom: HTMLElement): void;\n\t/** Rebuild the module in place from the held response, after a scaffold reset. */\n\tremount(dom: HTMLElement): Promise<void>;\n\t/** The current response, in the player's runtime value shape. */\n\tgetResponse(): unknown;\n\t/** The mounted module's state snapshot, when it exposes `getState()`. */\n\tgetState(): unknown;\n\t/**\n\t * Offer a response the player believes to be current. Declined, returning\n\t * `false`, once a mounted module has reported a response of its own: a live\n\t * interaction owns its response until something authoritative replaces it.\n\t */\n\tofferResponse(value: unknown): boolean;\n\t/**\n\t * Authoritatively replace the response, discarding in-progress candidate\n\t * state and returning ownership to the player. Session restore, reset to\n\t * declaration default, and explicit host overrides use this. A mounted module\n\t * is rebuilt through `onRemountRequest` where a renderer is wired to it, and\n\t * otherwise re-instantiated on the last mount node — the QTI 3.0 PCI contract\n\t * injects state at `getInstance` and offers no setter.\n\t */\n\trestore(value: unknown): void;\n\tdisable(): void;\n\tenable(): void;\n\tdestroy(): void;\n}\n\n/** One authored `qti-interaction-module` entry. */\nexport interface PciModuleEntry {\n\t/** The module id other modules' AMD dependencies refer to. */\n\tid: string;\n\tprimaryPath: string;\n\tfallbackPath?: string;\n}\n\n/**\n * Extracted data from a <qti-portable-custom-interaction> element.\n */\nexport interface ExtractedPci {\n\t/** responseIdentifier attribute value. */\n\tresponseIdentifier: string;\n\t/** customInteractionTypeIdentifier attribute value (URN identifying the PCI type). */\n\tcustomInteractionTypeIdentifier: string;\n\t/** Primary JS module path (required). The entry module's path. */\n\tprimaryPath: string;\n\t/** Fallback JS module path (optional). The entry module's fallback. */\n\tfallbackPath?: string;\n\t/**\n\t * All authored `qti-interaction-module` entries, in document order. A\n\t * multi-module PCI loads them through the AMD loader, whose `define` wires\n\t * the dependencies; the entry module is the one whose id matches the\n\t * customInteractionTypeIdentifier's tail.\n\t */\n\tmodules: PciModuleEntry[];\n\t/**\n\t * The `qti-interaction-modules@primary-configuration` reference: a module\n\t * resolution config file (RequireJS `paths` shape) that names the modules'\n\t * paths. When absent, the runtime tries the defined default locations under\n\t * the package base URL.\n\t */\n\tresolutionConfigPath?: string;\n\t/** Inner HTML of the <qti-interaction-markup> element. */\n\tmarkup: HtmlContent;\n\t/** Key/value pairs from <qti-pci-properties>/<qti-pci-property>. */\n\tconfig: Record<string, string>;\n}\n\n/**\n * Raised when PCI content is present but the embedding host has not opted into executing it.\n */\nexport class PciModuleResolverRequiredError extends Error {\n\tconstructor(\n\t\tpublic readonly responseIdentifier: string,\n\t\tpublic readonly authoredPath: string\n\t) {\n\t\tsuper(\n\t\t\t`PCI module loading is disabled for response '${responseIdentifier}'. ` +\n\t\t\t\t`Provide a host-controlled moduleResolver before loading '${authoredPath}'.`\n\t\t);\n\t\tthis.name = 'PciModuleResolverRequiredError';\n\t}\n}\n\n/**\n * Thrown when a PCI module fails to load from both primary and fallback paths.\n */\nexport class PciLoadError extends Error {\n\tconstructor(\n\t\tpublic readonly primaryPath: string,\n\t\tpublic readonly fallbackPath: string | undefined,\n\t\tcause?: Error\n\t) {\n\t\tsuper(\n\t\t\tfallbackPath\n\t\t\t\t? `PCI module failed to load from '${primaryPath}' and fallback '${fallbackPath}'`\n\t\t\t\t: `PCI module failed to load from '${primaryPath}'`\n\t\t);\n\t\tthis.name = 'PciLoadError';\n\t\tif (cause) Object.defineProperty(this, 'cause', { value: cause, writable: true, configurable: true });\n\t}\n}\n"]}
|
package/dist/pnp/applyPnp.d.ts
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
import type { PnpProfile } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Apply a PNP profile to the player root element as attributes and custom properties
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* Apply a PNP profile to the player root element as attributes and custom properties. The
|
|
4
|
+
* default runtime stylesheet renders color scheme, inverted polarity, single-column layout and
|
|
5
|
+
* text appearance; magnification is set for host stylesheets only.
|
|
6
6
|
*/
|
|
7
7
|
export declare function applyPnpToRoot(rootEl: HTMLElement, pnp: PnpProfile | undefined): void;
|
|
8
|
+
/**
|
|
9
|
+
* Marks a PNP surface: an element that applies the candidate's display needs to
|
|
10
|
+
* everything it renders, its item players included (a section player's layout).
|
|
11
|
+
*/
|
|
12
|
+
export declare const PNP_SURFACE_ATTRIBUTE = "data-qti-pnp-surface";
|
|
13
|
+
/**
|
|
14
|
+
* Apply a profile's display needs to a surface that renders more than one item's
|
|
15
|
+
* content — passages, rubrics, tool bars and items. Everything inside takes them
|
|
16
|
+
* from the surface: an item body inside one applies none of its own, so the surface
|
|
17
|
+
* decides one colour scheme, text appearance and polarity for all of it (and an
|
|
18
|
+
* inverting filter is never applied twice). Nothing outside the surface changes.
|
|
19
|
+
*/
|
|
20
|
+
export declare function applyPnpToSurface(surfaceEl: HTMLElement, pnp: PnpProfile | undefined): void;
|
|
21
|
+
/** Stop being a PNP surface: its display attributes go, and items inside apply their own again. */
|
|
22
|
+
export declare function clearPnpSurface(surfaceEl: HTMLElement): void;
|
|
23
|
+
/** Whether an ancestor of `el`, looking through shadow roots, is a PNP surface. */
|
|
24
|
+
export declare function isWithinPnpSurface(el: Element): boolean;
|