@pie-qti/item-player 1.0.0-beta.5 → 1.0.0-beta.6
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 +1 -1
- package/dist/core/Player.js +3 -0
- package/dist/core/Player.js.map +1 -1
- package/dist/element-class-BUFpUrJP.js +3792 -0
- package/dist/element-class-BUFpUrJP.js.map +1 -0
- package/dist/element-class.js +1 -1
- package/dist/element.js +2 -3
- package/dist/interactions/portable-custom/extractor.js +14 -12
- package/dist/interactions/portable-custom/extractor.js.map +1 -1
- package/dist/pci/types.d.ts +2 -2
- package/dist/pci/types.js.map +1 -1
- package/package.json +13 -13
- package/dist/element-class-BbF4Dj7F.js +0 -3773
- package/dist/element-class-BbF4Dj7F.js.map +0 -1
package/dist/element-class.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as PieQtiItemPlayerElement } from "./element-class-
|
|
1
|
+
export { t as PieQtiItemPlayerElement } from "./element-class-BUFpUrJP.js";
|
package/dist/element.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { t as e } from "./element-class-
|
|
2
|
-
|
|
1
|
+
import { t as e } from "./element-class-BUFpUrJP.js";
|
|
2
|
+
// src/element.ts
|
|
3
3
|
var t = "pie-qti-item-player";
|
|
4
4
|
globalThis.customElements && !customElements.get(t) && customElements.define(t, e);
|
|
5
|
-
//#endregion
|
|
6
5
|
export { e as PieQtiItemPlayerElement };
|
|
7
6
|
|
|
8
7
|
//# sourceMappingURL=element.js.map
|
|
@@ -89,19 +89,14 @@ export const portableCustomExtractor = {
|
|
|
89
89
|
// the authored DOM scaffold that the resolved module initializes.
|
|
90
90
|
const markupSource = markupEl ?? instanceEl;
|
|
91
91
|
const markup = markupSource ? utils.getHtmlContent(markupSource) : '';
|
|
92
|
-
// --- Config
|
|
93
|
-
//
|
|
94
|
-
//
|
|
92
|
+
// --- Config ---
|
|
93
|
+
// QTI 3.0 carries PCI configuration as data-* attributes on the interaction element, named
|
|
94
|
+
// as HTMLElement.dataset names them.
|
|
95
95
|
const config = {};
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const key = utils.getAttribute(propEl, 'key') || utils.getAttribute(propEl, 'name') || '';
|
|
101
|
-
const value = utils.getAttribute(propEl, 'value') || (propEl.textContent ?? '').trim() || '';
|
|
102
|
-
if (key)
|
|
103
|
-
config[key] = value;
|
|
104
|
-
}
|
|
96
|
+
for (const [name, value] of Object.entries(pciElement.attributes ?? {})) {
|
|
97
|
+
const key = datasetKey(name);
|
|
98
|
+
if (key)
|
|
99
|
+
config[key] = value;
|
|
105
100
|
}
|
|
106
101
|
return {
|
|
107
102
|
responseIdentifier,
|
|
@@ -150,6 +145,13 @@ function pickEntryModule(modules, customInteractionTypeIdentifier) {
|
|
|
150
145
|
}
|
|
151
146
|
return modules[modules.length - 1];
|
|
152
147
|
}
|
|
148
|
+
/** The HTMLElement.dataset key for a `data-*` attribute name, or undefined for any other attribute. */
|
|
149
|
+
function datasetKey(attributeName) {
|
|
150
|
+
const name = attributeName.toLowerCase();
|
|
151
|
+
if (!name.startsWith('data-') || name.length === 5)
|
|
152
|
+
return undefined;
|
|
153
|
+
return name.slice(5).replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
154
|
+
}
|
|
153
155
|
function localTagName(element) {
|
|
154
156
|
const raw = element.rawTagName?.toLowerCase() ?? '';
|
|
155
157
|
return raw.includes(':') ? raw.slice(raw.lastIndexOf(':') + 1) : raw;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/portable-custom/extractor.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAGhC;IACH,EAAE,EAAE,iCAAiC;IACrC,IAAI,EAAE,iCAAiC;IACvC,UAAU,EAAE,2BAA2B;IACvC,QAAQ,EAAE,EAAE;IACZ,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UAA6B;IAE7B,MAAM,QAAQ,GAAG,IAAI,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC;IACvE,MAAM,OAAO,GAAyB,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,CAAC,MAA0B,EAAE,EAAE;QAC5C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;YAC7C,MAAM,SAAS,GAAG,KAA2B,CAAC;YAC9C,IAAI,CAAC,SAAS,CAAC,UAAU;gBAAE,SAAS;YACpC,IAAI,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;gBAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACnE,KAAK,CAAC,SAAS,CAAC,CAAC;QAClB,CAAC;IACF,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,CAAC;IACf,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type { ElementExtractor } from '../../extraction/types.js';\nimport type { ExtractedPci } from '../../pci/types.js';\n\n/**\n * Extractor for <qti-portable-custom-interaction> (QTI 3.0) and the\n * namespaced <pci:portableCustomInteraction> payload inside a QTI 2.x\n * <customInteraction> wrapper.\n *\n * Extracts the module paths, markup, and config properties needed by PciHost\n * to load and initialize the PCI JavaScript module.\n *\n * Priority 20 > standardCustomExtractor priority 10, so this runs first when\n * both would match the same element.\n */\nexport const portableCustomExtractor: ElementExtractor<\n\tExtractedPci,\n\t'portableCustomInteraction'\n> = {\n\tid: 'qti:portable-custom-interaction',\n\tname: 'QTI Portable Custom Interaction',\n\toutputType: 'portableCustomInteraction',\n\tpriority: 20,\n\telementTypes: [\n\t\t'customInteraction',\n\t\t'portableCustomInteraction',\n\t\t'qti-portable-custom-interaction',\n\t],\n\tdescription: 'Extracts QTI 2.x/3.0 portable custom interaction module paths, markup, and config',\n\n\tcanHandle(element, _context) {\n\t\tconst tag = localTagName(element);\n\t\treturn (\n\t\t\ttag === 'portablecustominteraction' ||\n\t\t\ttag === 'qti-portable-custom-interaction' ||\n\t\t\t(tag === 'custominteraction' && findDescendant(element, ['portablecustominteraction']) !== null)\n\t\t);\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\t\tconst outerTag = localTagName(element);\n\t\tconst pciElement =\n\t\t\touterTag === 'custominteraction'\n\t\t\t\t? findDescendant(element, ['portablecustominteraction'])\n\t\t\t\t: element;\n\n\t\tif (!pciElement) {\n\t\t\tthrow new Error('customInteraction does not contain a portableCustomInteraction payload');\n\t\t}\n\n\t\tconst responseIdentifier =\n\t\t\tutils.getAttribute(element, 'responseIdentifier') ||\n\t\t\tutils.getAttribute(element, 'response-identifier') ||\n\t\t\tcontext.responseId ||\n\t\t\t'';\n\n\t\t// The schema-defined name only: `customInteractionTypeIdentifier` (QTI 2.x\n\t\t// camelCase) and its QTI 3.0 kebab form. No QTI or PCI version defines the\n\t\t// `customInteractionIdentifierType` spellings some earlier content used;\n\t\t// hosts passing those must use the schema name.\n\t\tconst customInteractionTypeIdentifier =\n\t\t\tutils.getAttribute(pciElement, 'customInteractionTypeIdentifier') ||\n\t\t\tutils.getAttribute(pciElement, 'custom-interaction-type-identifier') ||\n\t\t\t'';\n\n\t\t// --- Module paths from <qti-interaction-modules>/<qti-interaction-module> ---\n\t\t// These element names ARE in the standard QTI 3.0 element mapper so utils.querySelector works.\n\t\t// Every authored entry is kept; the entry module — the one whose id matches the\n\t\t// customInteractionTypeIdentifier's tail, else the last one — fills primaryPath.\n\t\tconst modules: ExtractedPci['modules'] = [];\n\t\tlet resolutionConfigPath: string | undefined;\n\n\t\tconst modulesEl = findDescendant(pciElement, ['interactionmodules', 'qti-interaction-modules']);\n\n\t\tif (modulesEl) {\n\t\t\tconst configuration =\n\t\t\t\tutils.getAttribute(modulesEl, 'primaryConfiguration') ||\n\t\t\t\tutils.getAttribute(modulesEl, 'primary-configuration') ||\n\t\t\t\t'';\n\t\t\tif (configuration) resolutionConfigPath = configuration;\n\n\t\t\tfor (const moduleEl of findDescendants(modulesEl, ['interactionmodule', 'qti-interaction-module'])) {\n\t\t\t\tconst primary =\n\t\t\t\t\tutils.getAttribute(moduleEl, 'primaryPath') ||\n\t\t\t\t\tutils.getAttribute(moduleEl, 'primary-path') ||\n\t\t\t\t\t'';\n\t\t\t\tconst fallback =\n\t\t\t\t\tutils.getAttribute(moduleEl, 'fallbackPath') ||\n\t\t\t\t\tutils.getAttribute(moduleEl, 'fallback-path') ||\n\t\t\t\t\t'';\n\t\t\t\tmodules.push({\n\t\t\t\t\tid: utils.getAttribute(moduleEl, 'id') || '',\n\t\t\t\t\tprimaryPath: primary,\n\t\t\t\t\t...(fallback ? { fallbackPath: fallback } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst entry = pickEntryModule(modules, customInteractionTypeIdentifier);\n\t\tlet primaryPath = entry?.primaryPath ?? '';\n\t\tlet fallbackPath = entry?.fallbackPath;\n\n\t\t// QTI 2.x PCI v1.0 embeds one or more script hooks in <pci:instance>.\n\t\t// The first external script identifies the resource a host resolver must map.\n\t\tconst instanceEl = findDescendant(pciElement, ['instance']);\n\t\tif (!primaryPath && instanceEl) {\n\t\t\tconst externalScript = findDescendants(instanceEl, ['script']).find((script) =>\n\t\t\t\tBoolean(utils.getAttribute(script, 'src'))\n\t\t\t);\n\t\t\tprimaryPath = externalScript ? utils.getAttribute(externalScript, 'src') : '';\n\t\t}\n\n\t\t// --- Markup from <qti-interaction-markup> ---\n\t\tconst markupEl = findDescendant(pciElement, ['interactionmarkup', 'qti-interaction-markup']);\n\n\t\t// sanitizeHtml removes script hooks from the QTI 2.x instance while preserving\n\t\t// the authored DOM scaffold that the resolved module initializes.\n\t\tconst markupSource = markupEl ?? instanceEl;\n\t\tconst markup = markupSource ? utils.getHtmlContent(markupSource) : '';\n\n\t\t// --- Config from <qti-pci-properties>/<qti-pci-property> ---\n\t\t// qti-pci-properties is NOT in the standard QTI 3.0 element mapper, so we use the\n\t\t// native node-html-parser querySelector (available as element.querySelector on the raw element).\n\t\tconst config: Record<string, string> = {};\n\n\t\tconst propsEl = findDescendant(pciElement, ['pciproperties', 'qti-pci-properties']);\n\n\t\tif (propsEl) {\n\t\t\tconst propEls = findDescendants(propsEl, ['pciproperty', 'qti-pci-property']);\n\t\t\tfor (const propEl of propEls) {\n\t\t\t\tconst key = utils.getAttribute(propEl, 'key') || utils.getAttribute(propEl, 'name') || '';\n\t\t\t\tconst value = utils.getAttribute(propEl, 'value') || (propEl.textContent ?? '').trim() || '';\n\t\t\t\tif (key) config[key] = value;\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tresponseIdentifier,\n\t\t\tcustomInteractionTypeIdentifier,\n\t\t\tprimaryPath,\n\t\t\tfallbackPath,\n\t\t\tmodules,\n\t\t\t...(resolutionConfigPath ? { resolutionConfigPath } : {}),\n\t\t\tmarkup,\n\t\t\tconfig,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\tif (!data.responseIdentifier) {\n\t\t\terrors.push('portableCustomInteraction is missing responseIdentifier');\n\t\t}\n\t\tif (!data.customInteractionTypeIdentifier) {\n\t\t\twarnings.push('portableCustomInteraction is missing customInteractionTypeIdentifier');\n\t\t}\n\t\tif (!data.primaryPath) {\n\t\t\terrors.push('portableCustomInteraction has no primaryPath in qti-interaction-modules');\n\t\t}\n\n\t\treturn { valid: errors.length === 0, errors: errors.length ? errors : undefined, warnings: warnings.length ? warnings : undefined };\n\t},\n};\n\ntype ExtractableElement = Parameters<typeof portableCustomExtractor.canHandle>[0];\n\n/**\n * The entry module: the one whose id matches the customInteractionTypeIdentifier's\n * tail (`urn:...:pci:shading` → `shading`), else the last entry with a path, else\n * the last entry. Only the id match is specified; the rest keeps single-module\n * content authored without ids loading.\n */\nfunction pickEntryModule(\n\tmodules: ExtractedPci['modules'],\n\tcustomInteractionTypeIdentifier: string\n): ExtractedPci['modules'][number] | undefined {\n\tif (modules.length === 0) return undefined;\n\tconst tail = customInteractionTypeIdentifier.split(':').pop()?.trim();\n\tif (tail) {\n\t\tconst byId = modules.find((module) => module.id === tail);\n\t\tif (byId) return byId;\n\t}\n\tfor (let index = modules.length - 1; index >= 0; index -= 1) {\n\t\tif (modules[index].primaryPath) return modules[index];\n\t}\n\treturn modules[modules.length - 1];\n}\n\nfunction localTagName(element: ExtractableElement): string {\n\tconst raw = element.rawTagName?.toLowerCase() ?? '';\n\treturn raw.includes(':') ? raw.slice(raw.lastIndexOf(':') + 1) : raw;\n}\n\nfunction findDescendant(\n\telement: ExtractableElement,\n\tlocalNames: readonly string[]\n): ExtractableElement | null {\n\treturn findDescendants(element, localNames)[0] ?? null;\n}\n\nfunction findDescendants(\n\telement: ExtractableElement,\n\tlocalNames: readonly string[]\n): ExtractableElement[] {\n\tconst expected = new Set(localNames.map((name) => name.toLowerCase()));\n\tconst matches: ExtractableElement[] = [];\n\tconst visit = (parent: ExtractableElement) => {\n\t\tfor (const child of parent.childNodes ?? []) {\n\t\t\tconst candidate = child as ExtractableElement;\n\t\t\tif (!candidate.rawTagName) continue;\n\t\t\tif (expected.has(localTagName(candidate))) matches.push(candidate);\n\t\t\tvisit(candidate);\n\t\t}\n\t};\n\tvisit(element);\n\treturn matches;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/portable-custom/extractor.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAGhC;IACH,EAAE,EAAE,iCAAiC;IACrC,IAAI,EAAE,iCAAiC;IACvC,UAAU,EAAE,2BAA2B;IACvC,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE;QACb,mBAAmB;QACnB,2BAA2B;QAC3B,iCAAiC;KACjC;IACD,WAAW,EAAE,mFAAmF;IAEhG,SAAS,CAAC,OAAO,EAAE,QAA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CAAC;IACvE,MAAM,OAAO,GAAyB,EAAE,CAAC;IACzC,MAAM,KAAK,GAAG,CAAC,MAA0B,EAAE,EAAE;QAC5C,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,UAAU,IAAI,EAAE,EAAE,CAAC;YAC7C,MAAM,SAAS,GAAG,KAA2B,CAAC;YAC9C,IAAI,CAAC,SAAS,CAAC,UAAU;gBAAE,SAAS;YACpC,IAAI,QAAQ,CAAC,GAAG,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC;gBAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YACnE,KAAK,CAAC,SAAS,CAAC,CAAC;QAClB,CAAC;IACF,CAAC,CAAC;IACF,KAAK,CAAC,OAAO,CAAC,CAAC;IACf,OAAO,OAAO,CAAC;AAChB,CAAC","sourcesContent":["import type { ElementExtractor } from '../../extraction/types.js';\nimport type { ExtractedPci } from '../../pci/types.js';\n\n/**\n * Extractor for <qti-portable-custom-interaction> (QTI 3.0) and the\n * namespaced <pci:portableCustomInteraction> payload inside a QTI 2.x\n * <customInteraction> wrapper.\n *\n * Extracts the module paths, markup, and config properties needed by PciHost\n * to load and initialize the PCI JavaScript module.\n *\n * Priority 20 > standardCustomExtractor priority 10, so this runs first when\n * both would match the same element.\n */\nexport const portableCustomExtractor: ElementExtractor<\n\tExtractedPci,\n\t'portableCustomInteraction'\n> = {\n\tid: 'qti:portable-custom-interaction',\n\tname: 'QTI Portable Custom Interaction',\n\toutputType: 'portableCustomInteraction',\n\tpriority: 20,\n\telementTypes: [\n\t\t'customInteraction',\n\t\t'portableCustomInteraction',\n\t\t'qti-portable-custom-interaction',\n\t],\n\tdescription: 'Extracts QTI 2.x/3.0 portable custom interaction module paths, markup, and config',\n\n\tcanHandle(element, _context) {\n\t\tconst tag = localTagName(element);\n\t\treturn (\n\t\t\ttag === 'portablecustominteraction' ||\n\t\t\ttag === 'qti-portable-custom-interaction' ||\n\t\t\t(tag === 'custominteraction' && findDescendant(element, ['portablecustominteraction']) !== null)\n\t\t);\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\t\tconst outerTag = localTagName(element);\n\t\tconst pciElement =\n\t\t\touterTag === 'custominteraction'\n\t\t\t\t? findDescendant(element, ['portablecustominteraction'])\n\t\t\t\t: element;\n\n\t\tif (!pciElement) {\n\t\t\tthrow new Error('customInteraction does not contain a portableCustomInteraction payload');\n\t\t}\n\n\t\tconst responseIdentifier =\n\t\t\tutils.getAttribute(element, 'responseIdentifier') ||\n\t\t\tutils.getAttribute(element, 'response-identifier') ||\n\t\t\tcontext.responseId ||\n\t\t\t'';\n\n\t\t// The schema-defined name only: `customInteractionTypeIdentifier` (QTI 2.x\n\t\t// camelCase) and its QTI 3.0 kebab form. No QTI or PCI version defines the\n\t\t// `customInteractionIdentifierType` spellings some earlier content used;\n\t\t// hosts passing those must use the schema name.\n\t\tconst customInteractionTypeIdentifier =\n\t\t\tutils.getAttribute(pciElement, 'customInteractionTypeIdentifier') ||\n\t\t\tutils.getAttribute(pciElement, 'custom-interaction-type-identifier') ||\n\t\t\t'';\n\n\t\t// --- Module paths from <qti-interaction-modules>/<qti-interaction-module> ---\n\t\t// These element names ARE in the standard QTI 3.0 element mapper so utils.querySelector works.\n\t\t// Every authored entry is kept; the entry module — the one whose id matches the\n\t\t// customInteractionTypeIdentifier's tail, else the last one — fills primaryPath.\n\t\tconst modules: ExtractedPci['modules'] = [];\n\t\tlet resolutionConfigPath: string | undefined;\n\n\t\tconst modulesEl = findDescendant(pciElement, ['interactionmodules', 'qti-interaction-modules']);\n\n\t\tif (modulesEl) {\n\t\t\tconst configuration =\n\t\t\t\tutils.getAttribute(modulesEl, 'primaryConfiguration') ||\n\t\t\t\tutils.getAttribute(modulesEl, 'primary-configuration') ||\n\t\t\t\t'';\n\t\t\tif (configuration) resolutionConfigPath = configuration;\n\n\t\t\tfor (const moduleEl of findDescendants(modulesEl, ['interactionmodule', 'qti-interaction-module'])) {\n\t\t\t\tconst primary =\n\t\t\t\t\tutils.getAttribute(moduleEl, 'primaryPath') ||\n\t\t\t\t\tutils.getAttribute(moduleEl, 'primary-path') ||\n\t\t\t\t\t'';\n\t\t\t\tconst fallback =\n\t\t\t\t\tutils.getAttribute(moduleEl, 'fallbackPath') ||\n\t\t\t\t\tutils.getAttribute(moduleEl, 'fallback-path') ||\n\t\t\t\t\t'';\n\t\t\t\tmodules.push({\n\t\t\t\t\tid: utils.getAttribute(moduleEl, 'id') || '',\n\t\t\t\t\tprimaryPath: primary,\n\t\t\t\t\t...(fallback ? { fallbackPath: fallback } : {}),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tconst entry = pickEntryModule(modules, customInteractionTypeIdentifier);\n\t\tlet primaryPath = entry?.primaryPath ?? '';\n\t\tlet fallbackPath = entry?.fallbackPath;\n\n\t\t// QTI 2.x PCI v1.0 embeds one or more script hooks in <pci:instance>.\n\t\t// The first external script identifies the resource a host resolver must map.\n\t\tconst instanceEl = findDescendant(pciElement, ['instance']);\n\t\tif (!primaryPath && instanceEl) {\n\t\t\tconst externalScript = findDescendants(instanceEl, ['script']).find((script) =>\n\t\t\t\tBoolean(utils.getAttribute(script, 'src'))\n\t\t\t);\n\t\t\tprimaryPath = externalScript ? utils.getAttribute(externalScript, 'src') : '';\n\t\t}\n\n\t\t// --- Markup from <qti-interaction-markup> ---\n\t\tconst markupEl = findDescendant(pciElement, ['interactionmarkup', 'qti-interaction-markup']);\n\n\t\t// sanitizeHtml removes script hooks from the QTI 2.x instance while preserving\n\t\t// the authored DOM scaffold that the resolved module initializes.\n\t\tconst markupSource = markupEl ?? instanceEl;\n\t\tconst markup = markupSource ? utils.getHtmlContent(markupSource) : '';\n\n\t\t// --- Config ---\n\t\t// QTI 3.0 carries PCI configuration as data-* attributes on the interaction element, named\n\t\t// as HTMLElement.dataset names them.\n\t\tconst config: Record<string, string> = {};\n\t\tfor (const [name, value] of Object.entries(pciElement.attributes ?? {})) {\n\t\t\tconst key = datasetKey(name);\n\t\t\tif (key) config[key] = value;\n\t\t}\n\n\t\treturn {\n\t\t\tresponseIdentifier,\n\t\t\tcustomInteractionTypeIdentifier,\n\t\t\tprimaryPath,\n\t\t\tfallbackPath,\n\t\t\tmodules,\n\t\t\t...(resolutionConfigPath ? { resolutionConfigPath } : {}),\n\t\t\tmarkup,\n\t\t\tconfig,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\tif (!data.responseIdentifier) {\n\t\t\terrors.push('portableCustomInteraction is missing responseIdentifier');\n\t\t}\n\t\tif (!data.customInteractionTypeIdentifier) {\n\t\t\twarnings.push('portableCustomInteraction is missing customInteractionTypeIdentifier');\n\t\t}\n\t\tif (!data.primaryPath) {\n\t\t\terrors.push('portableCustomInteraction has no primaryPath in qti-interaction-modules');\n\t\t}\n\n\t\treturn { valid: errors.length === 0, errors: errors.length ? errors : undefined, warnings: warnings.length ? warnings : undefined };\n\t},\n};\n\ntype ExtractableElement = Parameters<typeof portableCustomExtractor.canHandle>[0];\n\n/**\n * The entry module: the one whose id matches the customInteractionTypeIdentifier's\n * tail (`urn:...:pci:shading` → `shading`), else the last entry with a path, else\n * the last entry. Only the id match is specified; the rest keeps single-module\n * content authored without ids loading.\n */\nfunction pickEntryModule(\n\tmodules: ExtractedPci['modules'],\n\tcustomInteractionTypeIdentifier: string\n): ExtractedPci['modules'][number] | undefined {\n\tif (modules.length === 0) return undefined;\n\tconst tail = customInteractionTypeIdentifier.split(':').pop()?.trim();\n\tif (tail) {\n\t\tconst byId = modules.find((module) => module.id === tail);\n\t\tif (byId) return byId;\n\t}\n\tfor (let index = modules.length - 1; index >= 0; index -= 1) {\n\t\tif (modules[index].primaryPath) return modules[index];\n\t}\n\treturn modules[modules.length - 1];\n}\n\n/** The HTMLElement.dataset key for a `data-*` attribute name, or undefined for any other attribute. */\nfunction datasetKey(attributeName: string): string | undefined {\n\tconst name = attributeName.toLowerCase();\n\tif (!name.startsWith('data-') || name.length === 5) return undefined;\n\treturn name.slice(5).replace(/-([a-z])/g, (_, letter: string) => letter.toUpperCase());\n}\n\nfunction localTagName(element: ExtractableElement): string {\n\tconst raw = element.rawTagName?.toLowerCase() ?? '';\n\treturn raw.includes(':') ? raw.slice(raw.lastIndexOf(':') + 1) : raw;\n}\n\nfunction findDescendant(\n\telement: ExtractableElement,\n\tlocalNames: readonly string[]\n): ExtractableElement | null {\n\treturn findDescendants(element, localNames)[0] ?? null;\n}\n\nfunction findDescendants(\n\telement: ExtractableElement,\n\tlocalNames: readonly string[]\n): ExtractableElement[] {\n\tconst expected = new Set(localNames.map((name) => name.toLowerCase()));\n\tconst matches: ExtractableElement[] = [];\n\tconst visit = (parent: ExtractableElement) => {\n\t\tfor (const child of parent.childNodes ?? []) {\n\t\t\tconst candidate = child as ExtractableElement;\n\t\t\tif (!candidate.rawTagName) continue;\n\t\t\tif (expected.has(localTagName(candidate))) matches.push(candidate);\n\t\t\tvisit(candidate);\n\t\t}\n\t};\n\tvisit(element);\n\treturn matches;\n}\n"]}
|
package/dist/pci/types.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export interface QtiPciInstance {
|
|
|
31
31
|
export interface QtiPciConfiguration {
|
|
32
32
|
responseIdentifier: string;
|
|
33
33
|
status: PciInteractionStatus;
|
|
34
|
-
/**
|
|
34
|
+
/** Configuration from the interaction's `data-*` attributes, under their dataset names. */
|
|
35
35
|
properties: Record<string, string>;
|
|
36
36
|
templateVariables?: Record<string, unknown>;
|
|
37
37
|
contextVariables?: Record<string, unknown>;
|
|
@@ -316,7 +316,7 @@ export interface ExtractedPci {
|
|
|
316
316
|
resolutionConfigPath?: string;
|
|
317
317
|
/** Inner HTML of the <qti-interaction-markup> element. */
|
|
318
318
|
markup: HtmlContent;
|
|
319
|
-
/**
|
|
319
|
+
/** Configuration from the interaction's `data-*` attributes, under their dataset names. */
|
|
320
320
|
config: Record<string, string>;
|
|
321
321
|
}
|
|
322
322
|
/**
|
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;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"]}
|
|
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/** Configuration from the interaction's `data-*` attributes, under their dataset names. */\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/** Configuration from the interaction's `data-*` attributes, under their dataset names. */\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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-qti/item-player",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.6",
|
|
4
4
|
"description": "Modern QTI player supporting QTI 2.2 and 3.0 - Client-side with optional backend hooks",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -28,24 +28,24 @@
|
|
|
28
28
|
],
|
|
29
29
|
"license": "MIT",
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@pie-qti/i18n": "1.0.0-beta.
|
|
32
|
-
"@pie-qti/ims-cp-core": "1.0.0-beta.
|
|
33
|
-
"@pie-qti/qti-common": "1.0.0-beta.
|
|
34
|
-
"@pie-qti/qti-processing": "1.0.0-beta.
|
|
35
|
-
"node-html-parser": "^9.0.
|
|
31
|
+
"@pie-qti/i18n": "1.0.0-beta.6",
|
|
32
|
+
"@pie-qti/ims-cp-core": "1.0.0-beta.6",
|
|
33
|
+
"@pie-qti/qti-common": "1.0.0-beta.6",
|
|
34
|
+
"@pie-qti/qti-processing": "1.0.0-beta.6",
|
|
35
|
+
"node-html-parser": "^9.0.7"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@biomejs/biome": "^2.6.
|
|
38
|
+
"@biomejs/biome": "^2.6.8",
|
|
39
39
|
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
40
40
|
"@types/node": "^26.6.6",
|
|
41
|
-
"jsdom": "^
|
|
41
|
+
"jsdom": "^31.0.1",
|
|
42
42
|
"linkedom": "^0.18.13",
|
|
43
|
-
"svelte": "^5.57.
|
|
44
|
-
"svelte-check": "^4.7.
|
|
45
|
-
"typescript": "^
|
|
46
|
-
"vite": "^8.3.
|
|
43
|
+
"svelte": "^5.57.3",
|
|
44
|
+
"svelte-check": "^4.7.8",
|
|
45
|
+
"typescript": "^6.0.3",
|
|
46
|
+
"vite": "^8.3.8",
|
|
47
47
|
"vite-plugin-dts": "^5.1.2",
|
|
48
|
-
"vitest": "^5.0
|
|
48
|
+
"vitest": "^5.1.0"
|
|
49
49
|
},
|
|
50
50
|
"exports": {
|
|
51
51
|
".": {
|