@pie-qti/item-player 0.1.28 → 1.0.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +35 -6
- package/dist/catalog/applyGlossaryTriggers.js +8 -2
- package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
- package/dist/catalog/catalogExtractor.js +44 -7
- package/dist/catalog/catalogExtractor.js.map +1 -1
- package/dist/catalog/catalogLookup.d.ts +8 -0
- package/dist/catalog/catalogLookup.js +17 -0
- package/dist/catalog/catalogLookup.js.map +1 -1
- package/dist/catalog/types.d.ts +3 -3
- package/dist/catalog/types.js.map +1 -1
- package/dist/components/utils/feedbackUtils.d.ts +9 -4
- package/dist/components/utils/feedbackUtils.js +67 -34
- package/dist/components/utils/feedbackUtils.js.map +1 -1
- package/dist/core/AssessmentItemDefinition.js +35 -0
- package/dist/core/AssessmentItemDefinition.js.map +1 -1
- package/dist/core/ItemSession.d.ts +19 -1
- package/dist/core/ItemSession.js +12 -2
- package/dist/core/ItemSession.js.map +1 -1
- package/dist/core/Player.d.ts +41 -1
- package/dist/core/Player.js +216 -48
- package/dist/core/Player.js.map +1 -1
- package/dist/core/sanitizer.js +16 -3
- package/dist/core/sanitizer.js.map +1 -1
- package/dist/document/AssessmentItemDocument.d.ts +12 -5
- package/dist/document/AssessmentItemDocument.js +28 -19
- package/dist/document/AssessmentItemDocument.js.map +1 -1
- package/dist/document/contentPass.d.ts +17 -0
- package/dist/document/contentPass.js +40 -0
- package/dist/document/contentPass.js.map +1 -0
- package/dist/document/printedVariable.d.ts +35 -0
- package/dist/document/printedVariable.js +215 -0
- package/dist/document/printedVariable.js.map +1 -0
- package/dist/{element-class-BzATCyhV.js → element-class-D-kJi_w9.js} +3211 -2125
- package/dist/element-class-D-kJi_w9.js.map +1 -0
- package/dist/element-class.js +1 -1
- package/dist/element.js +1 -1
- package/dist/extraction/interactionAccessibility.d.ts +14 -0
- package/dist/extraction/interactionAccessibility.js +58 -0
- package/dist/extraction/interactionAccessibility.js.map +1 -0
- package/dist/extraction/interactionExtractionPipeline.d.ts +4 -1
- package/dist/extraction/interactionExtractionPipeline.js +7 -2
- package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
- package/dist/extraction/utils.js +20 -1
- package/dist/extraction/utils.js.map +1 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/interactions/order/extractor.js +2 -0
- package/dist/interactions/order/extractor.js.map +1 -1
- package/dist/interactions/portable-custom/extractor.js +47 -11
- package/dist/interactions/portable-custom/extractor.js.map +1 -1
- package/dist/interactions/shared/types.d.ts +16 -0
- package/dist/interactions/shared/types.js.map +1 -1
- package/dist/pci/PciHost.d.ts +85 -43
- package/dist/pci/PciHost.js +229 -148
- package/dist/pci/PciHost.js.map +1 -1
- package/dist/pci/allowlistResolver.d.ts +10 -1
- package/dist/pci/allowlistResolver.js +43 -4
- package/dist/pci/allowlistResolver.js.map +1 -1
- package/dist/pci/amdLoader.d.ts +23 -0
- package/dist/pci/amdLoader.js +190 -0
- package/dist/pci/amdLoader.js.map +1 -0
- package/dist/pci/index.d.ts +14 -3
- package/dist/pci/index.js +8 -1
- package/dist/pci/index.js.map +1 -1
- package/dist/pci/moduleSession.d.ts +41 -0
- package/dist/pci/moduleSession.js +2 -0
- package/dist/pci/moduleSession.js.map +1 -0
- package/dist/pci/pageRealmSession.d.ts +49 -0
- package/dist/pci/pageRealmSession.js +193 -0
- package/dist/pci/pageRealmSession.js.map +1 -0
- package/dist/pci/qtiVariableJson.d.ts +7 -0
- package/dist/pci/qtiVariableJson.js +93 -0
- package/dist/pci/qtiVariableJson.js.map +1 -0
- package/dist/pci/registry.d.ts +15 -0
- package/dist/pci/registry.js +77 -0
- package/dist/pci/registry.js.map +1 -0
- package/dist/pci/resolutionConfig.d.ts +23 -0
- package/dist/pci/resolutionConfig.js +63 -0
- package/dist/pci/resolutionConfig.js.map +1 -0
- package/dist/pci/sandbox/SandboxedPciSession.d.ts +78 -0
- package/dist/pci/sandbox/SandboxedPciSession.js +332 -0
- package/dist/pci/sandbox/SandboxedPciSession.js.map +1 -0
- package/dist/pci/sandbox/iframeConnector.d.ts +13 -0
- package/dist/pci/sandbox/iframeConnector.js +94 -0
- package/dist/pci/sandbox/iframeConnector.js.map +1 -0
- package/dist/pci/sandbox/protocol.d.ts +117 -0
- package/dist/pci/sandbox/protocol.js +49 -0
- package/dist/pci/sandbox/protocol.js.map +1 -0
- package/dist/pci/types.d.ts +213 -30
- package/dist/pci/types.js +8 -1
- package/dist/pci/types.js.map +1 -1
- package/dist/pnp/applyPnp.d.ts +3 -4
- package/dist/pnp/applyPnp.js +54 -8
- package/dist/pnp/applyPnp.js.map +1 -1
- package/dist/pnp/parsePnpXml.d.ts +2 -2
- package/dist/pnp/parsePnpXml.js +146 -4
- package/dist/pnp/parsePnpXml.js.map +1 -1
- package/dist/pnp/types.d.ts +57 -0
- package/dist/pnp/types.js.map +1 -1
- package/dist/presentation/itemPresentationPlan.d.ts +12 -1
- package/dist/presentation/itemPresentationPlan.js +11 -3
- package/dist/presentation/itemPresentationPlan.js.map +1 -1
- package/dist/server.d.ts +5 -0
- package/dist/server.js.map +1 -1
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js.map +1 -1
- package/package.json +6 -6
- package/dist/element-class-BzATCyhV.js.map +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PCI sandbox bridge protocol (host page ⇄ runner frame).
|
|
3
|
+
*
|
|
4
|
+
* The sandboxed engine runs a PCI module inside `<iframe sandbox="allow-scripts">`
|
|
5
|
+
* loaded from a dedicated runner origin (`@pie-qti/pci-runner`). The frame's
|
|
6
|
+
* document has an opaque origin, so every contract call crosses `postMessage`:
|
|
7
|
+
* this module defines the versioned envelope and payload shapes both sides
|
|
8
|
+
* speak. Like `src/iframe/protocol.ts`, it contains no DOM globals and can be
|
|
9
|
+
* imported anywhere.
|
|
10
|
+
*
|
|
11
|
+
* Origin locking is mutual and rooted at each side's structural facts:
|
|
12
|
+
*
|
|
13
|
+
* - The host accepts a message only when `event.origin` equals the runner
|
|
14
|
+
* URL's origin **and** `event.source` is the frame's `contentWindow`.
|
|
15
|
+
* - The runner accepts its first message only from its `window.parent`, locks
|
|
16
|
+
* to that message's `event.origin`, and sends everything to that origin.
|
|
17
|
+
*
|
|
18
|
+
* `runner-ready` is the one message posted without a locked origin (the runner
|
|
19
|
+
* cannot know its parent before the first exchange). It carries no secrets —
|
|
20
|
+
* it only announces the protocol version.
|
|
21
|
+
*/
|
|
22
|
+
export const PCI_SANDBOX_PROTOCOL = 'pie-qti-pci-sandbox';
|
|
23
|
+
export const PCI_SANDBOX_PROTOCOL_VERSION = '0.1.0';
|
|
24
|
+
export function createSandboxEnvelope(type, payload) {
|
|
25
|
+
return {
|
|
26
|
+
protocol: PCI_SANDBOX_PROTOCOL,
|
|
27
|
+
version: PCI_SANDBOX_PROTOCOL_VERSION,
|
|
28
|
+
type,
|
|
29
|
+
payload,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function isRecord(value) {
|
|
33
|
+
return typeof value === 'object' && value !== null;
|
|
34
|
+
}
|
|
35
|
+
/** Shallow envelope check; payload fields are validated where they are used. */
|
|
36
|
+
export function isPciSandboxEnvelope(value) {
|
|
37
|
+
if (!isRecord(value))
|
|
38
|
+
return false;
|
|
39
|
+
if (value.protocol !== PCI_SANDBOX_PROTOCOL)
|
|
40
|
+
return false;
|
|
41
|
+
if (value.version !== PCI_SANDBOX_PROTOCOL_VERSION)
|
|
42
|
+
return false;
|
|
43
|
+
if (typeof value.type !== 'string')
|
|
44
|
+
return false;
|
|
45
|
+
if (!('payload' in value))
|
|
46
|
+
return false;
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +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;AAgJ7D,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/** 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"]}
|
package/dist/pci/types.d.ts
CHANGED
|
@@ -1,34 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* QTI 3.0 Portable Custom Interaction (PCI) types.
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* The module-facing contract is the one QTI 3.0 §6.1 specifies: a module calls
|
|
5
|
+
* `qtiCustomInteractionContext.register(...)` with a `typeIdentifier` and a
|
|
6
|
+
* `getInstance(dom, configuration, state)` factory; the instance signals readiness
|
|
7
|
+
* through `configuration.onready(instance, state)` and completion through
|
|
8
|
+
* `configuration.ondone(...)`, and exposes `getResponse()` (QTI variable JSON) and
|
|
9
|
+
* optionally `getState()`. AMD is the documented default module resolution
|
|
10
|
+
* (phase 2); a host resolver decides whether a module is evaluated at all.
|
|
4
11
|
*/
|
|
5
12
|
import type { HtmlContent } from '../types/index.js';
|
|
13
|
+
import type { BaseType, Cardinality } from '@pie-qti/qti-processing';
|
|
14
|
+
/** QTI 3.0 §6.1 interaction status, fixed at instantiation. */
|
|
15
|
+
export type PciInteractionStatus = 'interacting' | 'closed' | 'solution' | 'review';
|
|
6
16
|
/**
|
|
7
|
-
*
|
|
17
|
+
* An instance a conformant `getInstance` factory returns. `getResponse()` answers in
|
|
18
|
+
* QTI variable JSON (`{ base: ... }` / `{ list: ... }` / `{ record: ... }`); `getState()`
|
|
19
|
+
* snapshots whatever the module needs to reconstruct itself, read back through the
|
|
20
|
+
* `state` argument of the next `getInstance`.
|
|
8
21
|
*/
|
|
9
|
-
export interface
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/** Called whenever the candidate's response changes. */
|
|
13
|
-
onResponseChange(value: unknown): void;
|
|
22
|
+
export interface QtiPciInstance {
|
|
23
|
+
getResponse(): unknown;
|
|
24
|
+
getState?(): unknown;
|
|
14
25
|
}
|
|
15
26
|
/**
|
|
16
|
-
*
|
|
17
|
-
*
|
|
27
|
+
* The configuration object the host passes to `getInstance`. `onready` reports the
|
|
28
|
+
* module ready (optionally with its initial state); `ondone` reports the interaction
|
|
29
|
+
* finished for the attempt, with its final response and state.
|
|
18
30
|
*/
|
|
19
|
-
export interface
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
export interface QtiPciConfiguration {
|
|
32
|
+
responseIdentifier: string;
|
|
33
|
+
status: PciInteractionStatus;
|
|
34
|
+
/** Key/value pairs from `qti-pci-properties`, keyed by their `identifier`. */
|
|
35
|
+
properties: Record<string, string>;
|
|
36
|
+
templateVariables?: Record<string, unknown>;
|
|
37
|
+
contextVariables?: Record<string, unknown>;
|
|
38
|
+
onready(instance: QtiPciInstance, state?: unknown): void;
|
|
39
|
+
ondone(instance: QtiPciInstance, state?: unknown): void;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* What a conformant PCI module registers: the global
|
|
43
|
+
* `qtiCustomInteractionContext.register(registration)` call.
|
|
44
|
+
*/
|
|
45
|
+
export interface QtiCustomInteractionRegistration {
|
|
46
|
+
typeIdentifier: string;
|
|
47
|
+
getInstance(dom: HTMLElement, configuration: QtiPciConfiguration, state?: unknown): QtiPciInstance | undefined;
|
|
48
|
+
}
|
|
49
|
+
/** The registry object the runtime installs as the page's `qtiCustomInteractionContext`. */
|
|
50
|
+
export interface PciCustomInteractionContext {
|
|
51
|
+
register(registration: QtiCustomInteractionRegistration): void;
|
|
32
52
|
}
|
|
33
53
|
/** Identifies which authored module path is currently being resolved. */
|
|
34
54
|
export type PciModulePathKind = 'primary' | 'fallback';
|
|
@@ -37,7 +57,9 @@ export type PciModulePathKind = 'primary' | 'fallback';
|
|
|
37
57
|
*
|
|
38
58
|
* PCI code executes with the authority of the page that loads it. The player therefore
|
|
39
59
|
* never imports an authored URL by itself; an embedding host must decide which URLs or
|
|
40
|
-
* package resources are trusted and return the loaded module explicitly.
|
|
60
|
+
* package resources are trusted and return the loaded module explicitly. The module
|
|
61
|
+
* registers itself as a side effect of evaluation, so the resolver's return value is
|
|
62
|
+
* informational — registration is what counts.
|
|
41
63
|
*/
|
|
42
64
|
export interface PciModuleResolutionContext {
|
|
43
65
|
/** Original path exactly as authored in the item. */
|
|
@@ -53,16 +75,105 @@ export interface PciModuleResolutionContext {
|
|
|
53
75
|
* Host-controlled PCI module resolution hook.
|
|
54
76
|
*
|
|
55
77
|
* The resolver may import an allow-listed URL, read a module from a verified content
|
|
56
|
-
* package, or
|
|
57
|
-
*
|
|
78
|
+
* package, or evaluate a pre-registered module. Whatever it returns, a conformant
|
|
79
|
+
* module registers against `qtiCustomInteractionContext` as it evaluates.
|
|
58
80
|
*/
|
|
59
81
|
export type PciModuleResolver = (resolvedUrl: string, context: PciModuleResolutionContext) => Promise<unknown> | unknown;
|
|
82
|
+
/**
|
|
83
|
+
* Host-controlled PCI module policy — the sandboxed engine's variant of the
|
|
84
|
+
* resolver. It decides *whether* an authored URL may be handed to the runner
|
|
85
|
+
* frame at all and never evaluates anything in the page realm: the return value
|
|
86
|
+
* is nothing, and throwing denies the module.
|
|
87
|
+
*/
|
|
88
|
+
export type PciModulePolicy = (resolvedUrl: string, context: PciModuleResolutionContext) => void;
|
|
89
|
+
/**
|
|
90
|
+
* Opt-in hardened execution for PCI modules (the sandboxed engine, plan
|
|
91
|
+
* Option C). The module runs inside `<iframe sandbox="allow-scripts">` loaded
|
|
92
|
+
* from a dedicated cookieless runner origin, so its document has an opaque
|
|
93
|
+
* origin: it shares no storage, cookies, or DOM with the player, while its
|
|
94
|
+
* base URL stays the runner URL so authored relative asset paths still
|
|
95
|
+
* resolve. `@pie-qti/pci-runner` is the deployable runner bundle.
|
|
96
|
+
*/
|
|
97
|
+
export interface PciSandboxConfiguration {
|
|
98
|
+
/**
|
|
99
|
+
* Absolute URL of the deployed runner page, for example
|
|
100
|
+
* `https://qti.pie-framework.org/pci-runner.html`. The runner origin must
|
|
101
|
+
* serve nothing else and set no cookies — there is nothing on it worth
|
|
102
|
+
* reaching, which is the security property.
|
|
103
|
+
*/
|
|
104
|
+
runnerUrl: string;
|
|
105
|
+
/**
|
|
106
|
+
* Milliseconds to wait for the runner handshake and the module's in-frame
|
|
107
|
+
* load. Default 15000; a frame that never becomes ready fails through
|
|
108
|
+
* `PciHostController.onError`.
|
|
109
|
+
*/
|
|
110
|
+
handshakeTimeoutMs?: number;
|
|
111
|
+
/**
|
|
112
|
+
* How often the runner re-reads the instance's `getResponse()`/`getState()`
|
|
113
|
+
* and pushes changes, in milliseconds. Default 250. `getResponse()` on the
|
|
114
|
+
* host stays synchronous, so a submit reads the cache this poll maintains:
|
|
115
|
+
* the response is at most one interval stale.
|
|
116
|
+
*/
|
|
117
|
+
pollIntervalMs?: number;
|
|
118
|
+
/**
|
|
119
|
+
* Milliseconds the runner waits for the module to register after its code
|
|
120
|
+
* evaluates. Default 5000; same semantics as the page-realm registration
|
|
121
|
+
* timeout.
|
|
122
|
+
*/
|
|
123
|
+
registrationTimeoutMs?: number;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* A connection to one runner frame. The default implementation creates the
|
|
127
|
+
* `<iframe sandbox="allow-scripts">` element and wires `window` messaging;
|
|
128
|
+
* tests inject an in-memory pair instead.
|
|
129
|
+
*/
|
|
130
|
+
export interface PciFrameConnection {
|
|
131
|
+
/** The origin every runner message must carry. */
|
|
132
|
+
readonly frameOrigin: string;
|
|
133
|
+
/** The identity an incoming event's `source` must be to count as the frame. */
|
|
134
|
+
readonly source: unknown;
|
|
135
|
+
/** Send a structured-cloneable message to the frame, locked to its origin. */
|
|
136
|
+
post(message: unknown): void;
|
|
137
|
+
/** Insert the frame into the interaction's mount node. */
|
|
138
|
+
appendTo(target: HTMLElement): void;
|
|
139
|
+
/** True while the frame's element is still in the document. */
|
|
140
|
+
isAttached(): boolean;
|
|
141
|
+
/** Messages from the frame, already filtered to its origin and source identity. */
|
|
142
|
+
onMessage(handler: (data: unknown) => void): () => void;
|
|
143
|
+
/** Remove the frame from the document and stop listening. */
|
|
144
|
+
dispose(): void;
|
|
145
|
+
/** Apply a runner-reported height, in CSS pixels. */
|
|
146
|
+
setHeight(height: number): void;
|
|
147
|
+
}
|
|
148
|
+
/** Creates the frame connection for a runner page URL. */
|
|
149
|
+
export type PciFrameConnector = (frameUrl: string, title: string) => PciFrameConnection;
|
|
60
150
|
/** Secure-by-default PCI runtime configuration. */
|
|
61
151
|
export interface PciConfiguration {
|
|
62
152
|
/** Directory URL used to resolve relative authored module paths. */
|
|
63
153
|
baseUrl?: string;
|
|
64
|
-
/**
|
|
65
|
-
|
|
154
|
+
/**
|
|
155
|
+
* The host trust decision for executing a PCI module in the page realm.
|
|
156
|
+
* Required unless `sandbox` is configured; a sandboxed engine never
|
|
157
|
+
* evaluates module code in the page, so there is nothing for a resolver to
|
|
158
|
+
* import. When both are configured the resolver is unused.
|
|
159
|
+
*/
|
|
160
|
+
moduleResolver?: PciModuleResolver;
|
|
161
|
+
/**
|
|
162
|
+
* Opt-in hardened execution in a sandboxed cross-origin frame. When set it
|
|
163
|
+
* takes precedence over `moduleResolver`: the runner frame executes the
|
|
164
|
+
* module with an opaque origin and the page never evaluates it.
|
|
165
|
+
*/
|
|
166
|
+
sandbox?: PciSandboxConfiguration;
|
|
167
|
+
/**
|
|
168
|
+
* Optional allow-list applied to the module URLs handed to the sandbox
|
|
169
|
+
* runner. Never evaluates anything; combine with `createAllowlistPciModulePolicy`.
|
|
170
|
+
*/
|
|
171
|
+
modulePolicy?: PciModulePolicy;
|
|
172
|
+
}
|
|
173
|
+
/** The response declaration shape a PCI's values convert against. */
|
|
174
|
+
export interface PciResponseDeclarationInfo {
|
|
175
|
+
baseType?: BaseType;
|
|
176
|
+
cardinality: Cardinality;
|
|
66
177
|
}
|
|
67
178
|
/**
|
|
68
179
|
* Low-level options accepted by PciHost.
|
|
@@ -73,6 +184,47 @@ export interface PciConfiguration {
|
|
|
73
184
|
export interface PciHostOptions {
|
|
74
185
|
baseUrl?: string;
|
|
75
186
|
moduleResolver?: PciModuleResolver;
|
|
187
|
+
/**
|
|
188
|
+
* Run the module in a sandboxed cross-origin runner frame instead of the
|
|
189
|
+
* page realm. Takes precedence over `moduleResolver`.
|
|
190
|
+
*/
|
|
191
|
+
sandbox?: PciSandboxConfiguration;
|
|
192
|
+
/**
|
|
193
|
+
* Policy gate for the module URLs handed to a sandbox runner. Never
|
|
194
|
+
* evaluates anything in the page; throwing denies the module.
|
|
195
|
+
*/
|
|
196
|
+
modulePolicy?: PciModulePolicy;
|
|
197
|
+
/** The bound response declaration, for QTI variable JSON conversion at the boundary. */
|
|
198
|
+
responseDeclaration?: PciResponseDeclarationInfo;
|
|
199
|
+
/**
|
|
200
|
+
* The interaction status `getInstance` receives, fixed at instantiation. A
|
|
201
|
+
* function is read at each instantiation, so a rebuild carries the current one.
|
|
202
|
+
*/
|
|
203
|
+
status?: PciInteractionStatus | (() => PciInteractionStatus);
|
|
204
|
+
/**
|
|
205
|
+
* Milliseconds to wait for a module to register after its code evaluates.
|
|
206
|
+
* Default 5000; a module that never registers fails the load. The sandboxed
|
|
207
|
+
* engine forwards it to the runner frame.
|
|
208
|
+
*/
|
|
209
|
+
registrationTimeoutMs?: number;
|
|
210
|
+
/** Registry observation override; tests inject one for isolation. */
|
|
211
|
+
registry?: PciRegistryObservation;
|
|
212
|
+
/** Frame connection override; tests inject one instead of a real iframe. */
|
|
213
|
+
frameConnector?: PciFrameConnector;
|
|
214
|
+
/** The page origin the runner locks to; defaults to `location.origin`. Tests inject one. */
|
|
215
|
+
parentOrigin?: () => string;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Registry observation: what the runtime uses to install the page's
|
|
219
|
+
* `qtiCustomInteractionContext` and await a module's registration.
|
|
220
|
+
*/
|
|
221
|
+
export interface PciRegistryObservation {
|
|
222
|
+
/** Resolves with the registration for `typeIdentifier`; never rejects. */
|
|
223
|
+
whenRegistered(typeIdentifier: string): Promise<QtiCustomInteractionRegistration>;
|
|
224
|
+
/** The typeIdentifiers registered so far, in registration order. */
|
|
225
|
+
registeredTypes(): string[];
|
|
226
|
+
/** Stop observing; pending `whenRegistered` promises stay pending. */
|
|
227
|
+
dispose(): void;
|
|
76
228
|
}
|
|
77
229
|
/**
|
|
78
230
|
* Public, structural contract exposed by a PCI host.
|
|
@@ -90,11 +242,20 @@ export interface PciHostController {
|
|
|
90
242
|
* `remount()`.
|
|
91
243
|
*/
|
|
92
244
|
onRemountRequest(callback: () => void): () => void;
|
|
245
|
+
/**
|
|
246
|
+
* Asynchronous failures that surface after `load()` resolved: the sandboxed
|
|
247
|
+
* engine's frame handshake, in-frame module load, or instance errors. The
|
|
248
|
+
* page-realm engine reports its failures by rejecting `load()` as before.
|
|
249
|
+
*/
|
|
250
|
+
onError(callback: (error: Error) => void): () => void;
|
|
93
251
|
load(): Promise<void>;
|
|
94
252
|
initialize(dom: HTMLElement): void;
|
|
95
253
|
/** Rebuild the module in place from the held response, after a scaffold reset. */
|
|
96
254
|
remount(dom: HTMLElement): Promise<void>;
|
|
255
|
+
/** The current response, in the player's runtime value shape. */
|
|
97
256
|
getResponse(): unknown;
|
|
257
|
+
/** The mounted module's state snapshot, when it exposes `getState()`. */
|
|
258
|
+
getState(): unknown;
|
|
98
259
|
/**
|
|
99
260
|
* Offer a response the player believes to be current. Declined, returning
|
|
100
261
|
* `false`, once a mounted module has reported a response of its own: a live
|
|
@@ -106,13 +267,21 @@ export interface PciHostController {
|
|
|
106
267
|
* state and returning ownership to the player. Session restore, reset to
|
|
107
268
|
* declaration default, and explicit host overrides use this. A mounted module
|
|
108
269
|
* is rebuilt through `onRemountRequest` where a renderer is wired to it, and
|
|
109
|
-
* otherwise
|
|
270
|
+
* otherwise re-instantiated on the last mount node — the QTI 3.0 PCI contract
|
|
271
|
+
* injects state at `getInstance` and offers no setter.
|
|
110
272
|
*/
|
|
111
273
|
restore(value: unknown): void;
|
|
112
274
|
disable(): void;
|
|
113
275
|
enable(): void;
|
|
114
276
|
destroy(): void;
|
|
115
277
|
}
|
|
278
|
+
/** One authored `qti-interaction-module` entry. */
|
|
279
|
+
export interface PciModuleEntry {
|
|
280
|
+
/** The module id other modules' AMD dependencies refer to. */
|
|
281
|
+
id: string;
|
|
282
|
+
primaryPath: string;
|
|
283
|
+
fallbackPath?: string;
|
|
284
|
+
}
|
|
116
285
|
/**
|
|
117
286
|
* Extracted data from a <qti-portable-custom-interaction> element.
|
|
118
287
|
*/
|
|
@@ -121,10 +290,24 @@ export interface ExtractedPci {
|
|
|
121
290
|
responseIdentifier: string;
|
|
122
291
|
/** customInteractionTypeIdentifier attribute value (URN identifying the PCI type). */
|
|
123
292
|
customInteractionTypeIdentifier: string;
|
|
124
|
-
/** Primary JS module path (required). */
|
|
293
|
+
/** Primary JS module path (required). The entry module's path. */
|
|
125
294
|
primaryPath: string;
|
|
126
|
-
/** Fallback JS module path (optional). */
|
|
295
|
+
/** Fallback JS module path (optional). The entry module's fallback. */
|
|
127
296
|
fallbackPath?: string;
|
|
297
|
+
/**
|
|
298
|
+
* All authored `qti-interaction-module` entries, in document order. A
|
|
299
|
+
* multi-module PCI loads them through the AMD loader, whose `define` wires
|
|
300
|
+
* the dependencies; the entry module is the one whose id matches the
|
|
301
|
+
* customInteractionTypeIdentifier's tail.
|
|
302
|
+
*/
|
|
303
|
+
modules: PciModuleEntry[];
|
|
304
|
+
/**
|
|
305
|
+
* The `qti-interaction-modules@primary-configuration` reference: a module
|
|
306
|
+
* resolution config file (RequireJS `paths` shape) that names the modules'
|
|
307
|
+
* paths. When absent, the runtime tries the defined default locations under
|
|
308
|
+
* the package base URL.
|
|
309
|
+
*/
|
|
310
|
+
resolutionConfigPath?: string;
|
|
128
311
|
/** Inner HTML of the <qti-interaction-markup> element. */
|
|
129
312
|
markup: HtmlContent;
|
|
130
313
|
/** Key/value pairs from <qti-pci-properties>/<qti-pci-property>. */
|
package/dist/pci/types.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* QTI 3.0 Portable Custom Interaction (PCI) types.
|
|
3
|
-
*
|
|
3
|
+
*
|
|
4
|
+
* The module-facing contract is the one QTI 3.0 §6.1 specifies: a module calls
|
|
5
|
+
* `qtiCustomInteractionContext.register(...)` with a `typeIdentifier` and a
|
|
6
|
+
* `getInstance(dom, configuration, state)` factory; the instance signals readiness
|
|
7
|
+
* through `configuration.onready(instance, state)` and completion through
|
|
8
|
+
* `configuration.ondone(...)`, and exposes `getResponse()` (QTI variable JSON) and
|
|
9
|
+
* optionally `getState()`. AMD is the documented default module resolution
|
|
10
|
+
* (phase 2); a host resolver decides whether a module is evaluated at all.
|
|
4
11
|
*/
|
|
5
12
|
/**
|
|
6
13
|
* Raised when PCI content is present but the embedding host has not opted into executing it.
|
package/dist/pci/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/pci/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA+IH;;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 * Based on IMS QTI 3.0 Portable Custom Interaction specification.\n */\n\nimport type { HtmlContent } from '../types/index.js';\n\n/**\n * Callbacks the player provides to a PCI module so it can signal state changes.\n */\nexport interface PciBoundTo {\n\t/** Called when the PCI has finished initializing and is ready to accept responses. */\n\tonReady(): void;\n\t/** Called whenever the candidate's response changes. */\n\tonResponseChange(value: unknown): void;\n}\n\n/**\n * Contract that every PCI module must fulfill.\n * The module's default export (or named `getInstance` export) must implement this interface.\n */\nexport interface PciModule {\n\t/** Initialize the PCI inside the given DOM element. */\n\tinitialize(dom: HTMLElement, config: Record<string, string>, boundTo: PciBoundTo): void;\n\t/** Return the current response value. */\n\tgetResponse(): unknown;\n\t/** Restore a previously-captured response value. */\n\tsetResponse(value: unknown): void;\n\t/** Disable candidate interaction (e.g. after submission or when role is not candidate). */\n\tdisable(): void;\n\t/** Re-enable candidate interaction. */\n\tenable(): void;\n\t/** Tear down: remove event listeners, cancel timers, free resources. */\n\tdestroy(): 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.\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 return a pre-registered module. Its return value may be a PciModule,\n * an ES-module namespace with a default export, or a namespace exposing getInstance().\n */\nexport type PciModuleResolver = (\n\tresolvedUrl: string,\n\tcontext: PciModuleResolutionContext\n) => Promise<unknown> | unknown;\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/** Required host trust decision for loading/executing a PCI module. */\n\tmoduleResolver: PciModuleResolver;\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}\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\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\tgetResponse(): 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 receives the value directly.\n\t */\n\trestore(value: unknown): void;\n\tdisable(): void;\n\tenable(): void;\n\tdestroy(): void;\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). */\n\tprimaryPath: string;\n\t/** Fallback JS module path (optional). */\n\tfallbackPath?: 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;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"]}
|
package/dist/pnp/applyPnp.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import type { PnpProfile } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Apply a PNP profile to the player root element
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* Magnification is intentionally deferred — host stylesheets / browser zoom are sufficient for now.
|
|
3
|
+
* Apply a PNP profile to the player root element as attributes and custom properties,
|
|
4
|
+
* which the default runtime stylesheet renders: color scheme, magnification, inverted
|
|
5
|
+
* polarity, single-column layout and text appearance.
|
|
7
6
|
*/
|
|
8
7
|
export declare function applyPnpToRoot(rootEl: HTMLElement, pnp: PnpProfile | undefined): void;
|
package/dist/pnp/applyPnp.js
CHANGED
|
@@ -1,27 +1,73 @@
|
|
|
1
1
|
const ATTR = 'data-qti-colorscheme';
|
|
2
2
|
const MAGNIFICATION_ATTR = 'data-qti-magnification';
|
|
3
|
+
const INVERT_POLARITY_ATTR = 'data-qti-invert-polarity';
|
|
4
|
+
const LAYOUT_ATTR = 'data-qti-layout';
|
|
5
|
+
const TEXT_APPEARANCE_ATTR = 'data-qti-text-appearance';
|
|
3
6
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
* Each text-appearance field, its token in `data-qti-text-appearance`, the custom property
|
|
8
|
+
* it sets (`--qti-<token>`) and its CSS unit.
|
|
9
|
+
*/
|
|
10
|
+
const TEXT_APPEARANCE_PROPERTIES = [
|
|
11
|
+
['fontSize', 'font-size', 'pt'],
|
|
12
|
+
['fontFamily', 'font-family', ''],
|
|
13
|
+
['fontColor', 'font-color', ''],
|
|
14
|
+
['backgroundColor', 'background-color', ''],
|
|
15
|
+
['lineHeight', 'line-height', ''],
|
|
16
|
+
['letterSpacing', 'letter-spacing', 'em'],
|
|
17
|
+
['wordSpacing', 'word-spacing', 'em'],
|
|
18
|
+
];
|
|
19
|
+
/**
|
|
20
|
+
* Apply a PNP profile to the player root element as attributes and custom properties,
|
|
21
|
+
* which the default runtime stylesheet renders: color scheme, magnification, inverted
|
|
22
|
+
* polarity, single-column layout and text appearance.
|
|
8
23
|
*/
|
|
9
24
|
export function applyPnpToRoot(rootEl, pnp) {
|
|
10
|
-
const
|
|
25
|
+
const display = pnp?.display;
|
|
26
|
+
const scheme = display?.colorScheme;
|
|
11
27
|
if (!scheme || scheme === 'default') {
|
|
12
28
|
rootEl.removeAttribute(ATTR);
|
|
13
29
|
}
|
|
14
30
|
else {
|
|
15
31
|
rootEl.setAttribute(ATTR, scheme);
|
|
16
32
|
}
|
|
17
|
-
const magnification =
|
|
33
|
+
const magnification = display?.magnification;
|
|
18
34
|
if (magnification !== undefined && Number.isFinite(magnification) && magnification > 0) {
|
|
19
35
|
rootEl.setAttribute(MAGNIFICATION_ATTR, String(magnification));
|
|
20
|
-
|
|
36
|
+
setProperty(rootEl, '--qti-magnification', String(magnification));
|
|
21
37
|
}
|
|
22
38
|
else {
|
|
23
39
|
rootEl.removeAttribute(MAGNIFICATION_ATTR);
|
|
24
|
-
rootEl
|
|
40
|
+
setProperty(rootEl, '--qti-magnification', undefined);
|
|
25
41
|
}
|
|
42
|
+
const polarity = display?.invertPolarity;
|
|
43
|
+
if (polarity)
|
|
44
|
+
rootEl.setAttribute(INVERT_POLARITY_ATTR, polarity.foreground || polarity.background ? 'colors' : 'invert');
|
|
45
|
+
else
|
|
46
|
+
rootEl.removeAttribute(INVERT_POLARITY_ATTR);
|
|
47
|
+
setProperty(rootEl, '--qti-invert-foreground', polarity?.foreground);
|
|
48
|
+
setProperty(rootEl, '--qti-invert-background', polarity?.background);
|
|
49
|
+
if (display?.singleColumn)
|
|
50
|
+
rootEl.setAttribute(LAYOUT_ATTR, 'single-column');
|
|
51
|
+
else
|
|
52
|
+
rootEl.removeAttribute(LAYOUT_ATTR);
|
|
53
|
+
const appearance = display?.textAppearance;
|
|
54
|
+
const tokens = [];
|
|
55
|
+
for (const [key, token, unit] of TEXT_APPEARANCE_PROPERTIES) {
|
|
56
|
+
const value = appearance?.[key];
|
|
57
|
+
const css = value === undefined || value === '' ? undefined : `${value}${unit}`;
|
|
58
|
+
if (css !== undefined)
|
|
59
|
+
tokens.push(token);
|
|
60
|
+
setProperty(rootEl, `--qti-${token}`, css);
|
|
61
|
+
}
|
|
62
|
+
if (tokens.length > 0)
|
|
63
|
+
rootEl.setAttribute(TEXT_APPEARANCE_ATTR, tokens.join(' '));
|
|
64
|
+
else
|
|
65
|
+
rootEl.removeAttribute(TEXT_APPEARANCE_ATTR);
|
|
66
|
+
}
|
|
67
|
+
function setProperty(rootEl, property, value) {
|
|
68
|
+
if (value === undefined)
|
|
69
|
+
rootEl.style?.removeProperty?.(property);
|
|
70
|
+
else
|
|
71
|
+
rootEl.style?.setProperty?.(property, value);
|
|
26
72
|
}
|
|
27
73
|
//# sourceMappingURL=applyPnp.js.map
|
package/dist/pnp/applyPnp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"applyPnp.js","sourceRoot":"","sources":["../../src/pnp/applyPnp.ts"],"names":[],"mappings":"AAEA,MAAM,IAAI,GAAG,sBAAsB,CAAC;AACpC,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"applyPnp.js","sourceRoot":"","sources":["../../src/pnp/applyPnp.ts"],"names":[],"mappings":"AAEA,MAAM,IAAI,GAAG,sBAAsB,CAAC;AACpC,MAAM,kBAAkB,GAAG,wBAAwB,CAAC;AACpD,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AACxD,MAAM,WAAW,GAAG,iBAAiB,CAAC;AACtC,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAExD;;;GAGG;AACH,MAAM,0BAA0B,GAA6D;IAC5F,CAAC,UAAU,EAAE,WAAW,EAAE,IAAI,CAAC;IAC/B,CAAC,YAAY,EAAE,aAAa,EAAE,EAAE,CAAC;IACjC,CAAC,WAAW,EAAE,YAAY,EAAE,EAAE,CAAC;IAC/B,CAAC,iBAAiB,EAAE,kBAAkB,EAAE,EAAE,CAAC;IAC3C,CAAC,YAAY,EAAE,aAAa,EAAE,EAAE,CAAC;IACjC,CAAC,eAAe,EAAE,gBAAgB,EAAE,IAAI,CAAC;IACzC,CAAC,aAAa,EAAE,cAAc,EAAE,IAAI,CAAC;CACrC,CAAC;AAEF;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,MAAmB,EAAE,GAA2B;IAC9E,MAAM,OAAO,GAAG,GAAG,EAAE,OAAO,CAAC;IAC7B,MAAM,MAAM,GAAG,OAAO,EAAE,WAAW,CAAC;IAEpC,IAAI,CAAC,MAAM,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QACrC,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;SAAM,CAAC;QACP,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;IACnC,CAAC;IAED,MAAM,aAAa,GAAG,OAAO,EAAE,aAAa,CAAC;IAC7C,IAAI,aAAa,KAAK,SAAS,IAAI,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,IAAI,aAAa,GAAG,CAAC,EAAE,CAAC;QACxF,MAAM,CAAC,YAAY,CAAC,kBAAkB,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;QAC/D,WAAW,CAAC,MAAM,EAAE,qBAAqB,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;IACnE,CAAC;SAAM,CAAC;QACP,MAAM,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;QAC3C,WAAW,CAAC,MAAM,EAAE,qBAAqB,EAAE,SAAS,CAAC,CAAC;IACvD,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,EAAE,cAAc,CAAC;IACzC,IAAI,QAAQ;QAAE,MAAM,CAAC,YAAY,CAAC,oBAAoB,EAAE,QAAQ,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC;;QACrH,MAAM,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC;IAClD,WAAW,CAAC,MAAM,EAAE,yBAAyB,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IACrE,WAAW,CAAC,MAAM,EAAE,yBAAyB,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;IAErE,IAAI,OAAO,EAAE,YAAY;QAAE,MAAM,CAAC,YAAY,CAAC,WAAW,EAAE,eAAe,CAAC,CAAC;;QACxE,MAAM,CAAC,eAAe,CAAC,WAAW,CAAC,CAAC;IAEzC,MAAM,UAAU,GAAG,OAAO,EAAE,cAAc,CAAC;IAC3C,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,EAAE,IAAI,CAAC,IAAI,0BAA0B,EAAE,CAAC;QAC7D,MAAM,KAAK,GAAG,UAAU,EAAE,CAAC,GAAG,CAAC,CAAC;QAChC,MAAM,GAAG,GAAG,KAAK,KAAK,SAAS,IAAI,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI,EAAE,CAAC;QAChF,IAAI,GAAG,KAAK,SAAS;YAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC1C,WAAW,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,EAAE,GAAG,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC;QAAE,MAAM,CAAC,YAAY,CAAC,oBAAoB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;;QAC9E,MAAM,CAAC,eAAe,CAAC,oBAAoB,CAAC,CAAC;AACnD,CAAC;AAED,SAAS,WAAW,CAAC,MAAmB,EAAE,QAAgB,EAAE,KAAyB;IACpF,IAAI,KAAK,KAAK,SAAS;QAAE,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,CAAC,QAAQ,CAAC,CAAC;;QAC7D,MAAM,CAAC,KAAK,EAAE,WAAW,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import type { PnpProfile, PnpTextAppearance } from './types.js';\n\nconst ATTR = 'data-qti-colorscheme';\nconst MAGNIFICATION_ATTR = 'data-qti-magnification';\nconst INVERT_POLARITY_ATTR = 'data-qti-invert-polarity';\nconst LAYOUT_ATTR = 'data-qti-layout';\nconst TEXT_APPEARANCE_ATTR = 'data-qti-text-appearance';\n\n/**\n * Each text-appearance field, its token in `data-qti-text-appearance`, the custom property\n * it sets (`--qti-<token>`) and its CSS unit.\n */\nconst TEXT_APPEARANCE_PROPERTIES: ReadonlyArray<[keyof PnpTextAppearance, string, string]> = [\n\t['fontSize', 'font-size', 'pt'],\n\t['fontFamily', 'font-family', ''],\n\t['fontColor', 'font-color', ''],\n\t['backgroundColor', 'background-color', ''],\n\t['lineHeight', 'line-height', ''],\n\t['letterSpacing', 'letter-spacing', 'em'],\n\t['wordSpacing', 'word-spacing', 'em'],\n];\n\n/**\n * Apply a PNP profile to the player root element as attributes and custom properties,\n * which the default runtime stylesheet renders: color scheme, magnification, inverted\n * polarity, single-column layout and text appearance.\n */\nexport function applyPnpToRoot(rootEl: HTMLElement, pnp: PnpProfile | undefined): void {\n\tconst display = pnp?.display;\n\tconst scheme = display?.colorScheme;\n\n\tif (!scheme || scheme === 'default') {\n\t\trootEl.removeAttribute(ATTR);\n\t} else {\n\t\trootEl.setAttribute(ATTR, scheme);\n\t}\n\n\tconst magnification = display?.magnification;\n\tif (magnification !== undefined && Number.isFinite(magnification) && magnification > 0) {\n\t\trootEl.setAttribute(MAGNIFICATION_ATTR, String(magnification));\n\t\tsetProperty(rootEl, '--qti-magnification', String(magnification));\n\t} else {\n\t\trootEl.removeAttribute(MAGNIFICATION_ATTR);\n\t\tsetProperty(rootEl, '--qti-magnification', undefined);\n\t}\n\n\tconst polarity = display?.invertPolarity;\n\tif (polarity) rootEl.setAttribute(INVERT_POLARITY_ATTR, polarity.foreground || polarity.background ? 'colors' : 'invert');\n\telse rootEl.removeAttribute(INVERT_POLARITY_ATTR);\n\tsetProperty(rootEl, '--qti-invert-foreground', polarity?.foreground);\n\tsetProperty(rootEl, '--qti-invert-background', polarity?.background);\n\n\tif (display?.singleColumn) rootEl.setAttribute(LAYOUT_ATTR, 'single-column');\n\telse rootEl.removeAttribute(LAYOUT_ATTR);\n\n\tconst appearance = display?.textAppearance;\n\tconst tokens: string[] = [];\n\tfor (const [key, token, unit] of TEXT_APPEARANCE_PROPERTIES) {\n\t\tconst value = appearance?.[key];\n\t\tconst css = value === undefined || value === '' ? undefined : `${value}${unit}`;\n\t\tif (css !== undefined) tokens.push(token);\n\t\tsetProperty(rootEl, `--qti-${token}`, css);\n\t}\n\tif (tokens.length > 0) rootEl.setAttribute(TEXT_APPEARANCE_ATTR, tokens.join(' '));\n\telse rootEl.removeAttribute(TEXT_APPEARANCE_ATTR);\n}\n\nfunction setProperty(rootEl: HTMLElement, property: string, value: string | undefined): void {\n\tif (value === undefined) rootEl.style?.removeProperty?.(property);\n\telse rootEl.style?.setProperty?.(property, value);\n}\n"]}
|
|
@@ -27,8 +27,8 @@ export declare function parseAfaPnpXml(xml: string | Element): AfaPnpRecord | nu
|
|
|
27
27
|
/**
|
|
28
28
|
* The part of an AfA record the item player renders. A feature counts when the record
|
|
29
29
|
* names it or one of its activation sets lists it, unless `prohibit-set` lists it.
|
|
30
|
-
* Features with no `PnpProfile` field stay in the record for the host
|
|
31
|
-
*
|
|
30
|
+
* Features with no `PnpProfile` field stay in the record for the host: `ext:` color
|
|
31
|
+
* themes, and the tool supports `tools` does not name.
|
|
32
32
|
*/
|
|
33
33
|
export declare function pnpProfileFromAfa(record: AfaPnpRecord): PnpProfile;
|
|
34
34
|
/**
|