@pie-qti/item-player 0.1.18 → 0.1.20
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 +137 -427
- package/dist/catalog/applyGlossaryTriggers.d.ts +2 -1
- package/dist/catalog/applyGlossaryTriggers.js +4 -2
- package/dist/catalog/applyGlossaryTriggers.js.map +1 -1
- package/dist/components/utils/stimulusRender.d.ts +1 -2
- package/dist/components/utils/stimulusRender.js +2 -5
- package/dist/components/utils/stimulusRender.js.map +1 -1
- package/dist/core/AssessmentItemDefinition.d.ts +69 -0
- package/dist/core/AssessmentItemDefinition.js +149 -0
- package/dist/core/AssessmentItemDefinition.js.map +1 -0
- package/dist/core/ComponentRegistry.d.ts +11 -5
- package/dist/core/ComponentRegistry.js +44 -17
- package/dist/core/ComponentRegistry.js.map +1 -1
- package/dist/core/ItemSession.d.ts +58 -0
- package/dist/core/ItemSession.js +286 -0
- package/dist/core/ItemSession.js.map +1 -0
- package/dist/core/Player.d.ts +9 -8
- package/dist/core/Player.js +182 -163
- package/dist/core/Player.js.map +1 -1
- package/dist/core/sanitizer.js +33 -10
- package/dist/core/sanitizer.js.map +1 -1
- package/dist/document/AssessmentItemDocument.d.ts +32 -10
- package/dist/document/AssessmentItemDocument.js +80 -23
- package/dist/document/AssessmentItemDocument.js.map +1 -1
- package/dist/{element-class-C8OTgYHE.js → element-class-CILJ4Ls7.js} +3583 -2779
- package/dist/element-class-CILJ4Ls7.js.map +1 -0
- package/dist/element-class.d.ts +17 -13
- package/dist/element-class.js +1 -1
- package/dist/element.js +1 -1
- package/dist/extraction/ExtractionRegistry.d.ts +34 -11
- package/dist/extraction/ExtractionRegistry.js +122 -19
- package/dist/extraction/ExtractionRegistry.js.map +1 -1
- package/dist/extraction/createContext.d.ts +5 -6
- package/dist/extraction/createContext.js +2 -2
- package/dist/extraction/createContext.js.map +1 -1
- package/dist/extraction/deliveryTypes.d.ts +26 -0
- package/dist/extraction/deliveryTypes.js +7 -0
- package/dist/extraction/deliveryTypes.js.map +1 -0
- package/dist/extraction/index.d.ts +3 -3
- package/dist/extraction/index.js +1 -2
- package/dist/extraction/index.js.map +1 -1
- package/dist/extraction/interactionExtractionPipeline.d.ts +4 -4
- package/dist/extraction/interactionExtractionPipeline.js +27 -10
- package/dist/extraction/interactionExtractionPipeline.js.map +1 -1
- package/dist/extraction/interactionSecurity.d.ts +11 -2
- package/dist/extraction/interactionSecurity.js +105 -40
- package/dist/extraction/interactionSecurity.js.map +1 -1
- package/dist/extraction/types.d.ts +44 -7
- package/dist/extraction/types.js.map +1 -1
- package/dist/extraction/utils.js +4 -16
- package/dist/extraction/utils.js.map +1 -1
- package/dist/index.d.ts +9 -8
- package/dist/index.js +5 -7
- package/dist/index.js.map +1 -1
- package/dist/interactions/associate/extractor.js +1 -1
- package/dist/interactions/associate/extractor.js.map +1 -1
- package/dist/interactions/drawing/extractor.js +5 -4
- package/dist/interactions/drawing/extractor.js.map +1 -1
- package/dist/interactions/end-attempt/extractor.js +2 -2
- package/dist/interactions/end-attempt/extractor.js.map +1 -1
- package/dist/interactions/gap-match/extractor.js +4 -3
- package/dist/interactions/gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-associate/extractor.js +5 -4
- package/dist/interactions/graphic-associate/extractor.js.map +1 -1
- package/dist/interactions/graphic-gap-match/extractor.js +20 -17
- package/dist/interactions/graphic-gap-match/extractor.js.map +1 -1
- package/dist/interactions/graphic-order/extractor.js +5 -4
- package/dist/interactions/graphic-order/extractor.js.map +1 -1
- package/dist/interactions/hotspot/extractor.js +11 -10
- package/dist/interactions/hotspot/extractor.js.map +1 -1
- package/dist/interactions/inline/render-plan.d.ts +3 -5
- package/dist/interactions/inline/render-plan.js.map +1 -1
- package/dist/interactions/media/extractor.js +2 -2
- package/dist/interactions/media/extractor.js.map +1 -1
- package/dist/interactions/modules.d.ts +11 -91
- package/dist/interactions/modules.js +185 -45
- package/dist/interactions/modules.js.map +1 -1
- package/dist/interactions/portable-custom/extractor.d.ts +1 -1
- package/dist/interactions/portable-custom/extractor.js +1 -1
- package/dist/interactions/portable-custom/extractor.js.map +1 -1
- package/dist/interactions/position-object/extractor.js +3 -2
- package/dist/interactions/position-object/extractor.js.map +1 -1
- package/dist/interactions/select-point/extractor.js +7 -6
- package/dist/interactions/select-point/extractor.js.map +1 -1
- package/dist/interactions/shared/types.d.ts +59 -70
- package/dist/interactions/shared/types.js.map +1 -1
- package/dist/interactions/slider/extractor.js +2 -2
- package/dist/interactions/slider/extractor.js.map +1 -1
- package/dist/interactions/upload/extractor.js +2 -2
- package/dist/interactions/upload/extractor.js.map +1 -1
- package/dist/pci/types.d.ts +2 -3
- package/dist/pci/types.js.map +1 -1
- package/dist/presentation/itemPresentationPlan.d.ts +71 -38
- package/dist/presentation/itemPresentationPlan.js +78 -34
- package/dist/presentation/itemPresentationPlan.js.map +1 -1
- package/dist/security/index.d.ts +1 -1
- package/dist/security/index.js +1 -1
- package/dist/security/index.js.map +1 -1
- package/dist/security/styleValues.d.ts +20 -0
- package/dist/security/styleValues.js +49 -0
- package/dist/security/styleValues.js.map +1 -0
- package/dist/server.d.ts +188 -9
- package/dist/server.js +32 -7
- package/dist/server.js.map +1 -1
- package/dist/types/index.d.ts +1 -110
- package/dist/types/index.js.map +1 -1
- package/dist/web-components/QTIInteractionBase.d.ts +2 -2
- package/dist/web-components/QTIInteractionBase.js.map +1 -1
- package/dist/web-components/QTIInteractionElement.d.ts +3 -3
- package/dist/web-components/QTIInteractionElement.js.map +1 -1
- package/package.json +11 -11
- package/dist/core/Plugin.d.ts +0 -104
- package/dist/core/Plugin.js +0 -8
- package/dist/core/Plugin.js.map +0 -1
- package/dist/core/PluginManager.d.ts +0 -55
- package/dist/core/PluginManager.js +0 -148
- package/dist/core/PluginManager.js.map +0 -1
- package/dist/element-class-C8OTgYHE.js.map +0 -1
- package/dist/interactions/associate/index.d.ts +0 -2
- package/dist/interactions/associate/index.js +0 -2
- package/dist/interactions/associate/index.js.map +0 -1
- package/dist/interactions/associate/types.d.ts +0 -1
- package/dist/interactions/associate/types.js +0 -2
- package/dist/interactions/associate/types.js.map +0 -1
- package/dist/interactions/choice/index.d.ts +0 -2
- package/dist/interactions/choice/index.js +0 -2
- package/dist/interactions/choice/index.js.map +0 -1
- package/dist/interactions/choice/types.d.ts +0 -1
- package/dist/interactions/choice/types.js +0 -2
- package/dist/interactions/choice/types.js.map +0 -1
- package/dist/interactions/custom/index.d.ts +0 -2
- package/dist/interactions/custom/index.js +0 -2
- package/dist/interactions/custom/index.js.map +0 -1
- package/dist/interactions/custom/types.d.ts +0 -1
- package/dist/interactions/custom/types.js +0 -2
- package/dist/interactions/custom/types.js.map +0 -1
- package/dist/interactions/drawing/index.d.ts +0 -2
- package/dist/interactions/drawing/index.js +0 -2
- package/dist/interactions/drawing/index.js.map +0 -1
- package/dist/interactions/drawing/types.d.ts +0 -1
- package/dist/interactions/drawing/types.js +0 -2
- package/dist/interactions/drawing/types.js.map +0 -1
- package/dist/interactions/end-attempt/index.d.ts +0 -2
- package/dist/interactions/end-attempt/index.js +0 -2
- package/dist/interactions/end-attempt/index.js.map +0 -1
- package/dist/interactions/end-attempt/types.d.ts +0 -1
- package/dist/interactions/end-attempt/types.js +0 -2
- package/dist/interactions/end-attempt/types.js.map +0 -1
- package/dist/interactions/extended-text/index.d.ts +0 -3
- package/dist/interactions/extended-text/index.js +0 -3
- package/dist/interactions/extended-text/index.js.map +0 -1
- package/dist/interactions/extended-text/types.d.ts +0 -1
- package/dist/interactions/extended-text/types.js +0 -2
- package/dist/interactions/extended-text/types.js.map +0 -1
- package/dist/interactions/gap-match/index.d.ts +0 -2
- package/dist/interactions/gap-match/index.js +0 -2
- package/dist/interactions/gap-match/index.js.map +0 -1
- package/dist/interactions/gap-match/types.d.ts +0 -1
- package/dist/interactions/gap-match/types.js +0 -2
- package/dist/interactions/gap-match/types.js.map +0 -1
- package/dist/interactions/graphic-associate/index.d.ts +0 -2
- package/dist/interactions/graphic-associate/index.js +0 -2
- package/dist/interactions/graphic-associate/index.js.map +0 -1
- package/dist/interactions/graphic-associate/types.d.ts +0 -1
- package/dist/interactions/graphic-associate/types.js +0 -2
- package/dist/interactions/graphic-associate/types.js.map +0 -1
- package/dist/interactions/graphic-gap-match/index.d.ts +0 -2
- package/dist/interactions/graphic-gap-match/index.js +0 -2
- package/dist/interactions/graphic-gap-match/index.js.map +0 -1
- package/dist/interactions/graphic-gap-match/types.d.ts +0 -1
- package/dist/interactions/graphic-gap-match/types.js +0 -2
- package/dist/interactions/graphic-gap-match/types.js.map +0 -1
- package/dist/interactions/graphic-order/index.d.ts +0 -2
- package/dist/interactions/graphic-order/index.js +0 -2
- package/dist/interactions/graphic-order/index.js.map +0 -1
- package/dist/interactions/graphic-order/types.d.ts +0 -1
- package/dist/interactions/graphic-order/types.js +0 -2
- package/dist/interactions/graphic-order/types.js.map +0 -1
- package/dist/interactions/hotspot/index.d.ts +0 -2
- package/dist/interactions/hotspot/index.js +0 -2
- package/dist/interactions/hotspot/index.js.map +0 -1
- package/dist/interactions/hotspot/types.d.ts +0 -1
- package/dist/interactions/hotspot/types.js +0 -2
- package/dist/interactions/hotspot/types.js.map +0 -1
- package/dist/interactions/hottext/index.d.ts +0 -2
- package/dist/interactions/hottext/index.js +0 -2
- package/dist/interactions/hottext/index.js.map +0 -1
- package/dist/interactions/hottext/types.d.ts +0 -1
- package/dist/interactions/hottext/types.js +0 -2
- package/dist/interactions/hottext/types.js.map +0 -1
- package/dist/interactions/index.d.ts +0 -32
- package/dist/interactions/index.js +0 -31
- package/dist/interactions/index.js.map +0 -1
- package/dist/interactions/inline/index.d.ts +0 -1
- package/dist/interactions/inline/index.js +0 -2
- package/dist/interactions/inline/index.js.map +0 -1
- package/dist/interactions/inline-choice/index.d.ts +0 -2
- package/dist/interactions/inline-choice/index.js +0 -2
- package/dist/interactions/inline-choice/index.js.map +0 -1
- package/dist/interactions/inline-choice/types.d.ts +0 -1
- package/dist/interactions/inline-choice/types.js +0 -2
- package/dist/interactions/inline-choice/types.js.map +0 -1
- package/dist/interactions/match/index.d.ts +0 -2
- package/dist/interactions/match/index.js +0 -2
- package/dist/interactions/match/index.js.map +0 -1
- package/dist/interactions/match/types.d.ts +0 -1
- package/dist/interactions/match/types.js +0 -2
- package/dist/interactions/match/types.js.map +0 -1
- package/dist/interactions/media/index.d.ts +0 -2
- package/dist/interactions/media/index.js +0 -2
- package/dist/interactions/media/index.js.map +0 -1
- package/dist/interactions/media/types.d.ts +0 -1
- package/dist/interactions/media/types.js +0 -2
- package/dist/interactions/media/types.js.map +0 -1
- package/dist/interactions/order/index.d.ts +0 -2
- package/dist/interactions/order/index.js +0 -2
- package/dist/interactions/order/index.js.map +0 -1
- package/dist/interactions/order/types.d.ts +0 -1
- package/dist/interactions/order/types.js +0 -2
- package/dist/interactions/order/types.js.map +0 -1
- package/dist/interactions/portable-custom/index.d.ts +0 -2
- package/dist/interactions/portable-custom/index.js +0 -2
- package/dist/interactions/portable-custom/index.js.map +0 -1
- package/dist/interactions/portable-custom/types.d.ts +0 -1
- package/dist/interactions/portable-custom/types.js +0 -2
- package/dist/interactions/portable-custom/types.js.map +0 -1
- package/dist/interactions/position-object/index.d.ts +0 -2
- package/dist/interactions/position-object/index.js +0 -2
- package/dist/interactions/position-object/index.js.map +0 -1
- package/dist/interactions/position-object/types.d.ts +0 -1
- package/dist/interactions/position-object/types.js +0 -2
- package/dist/interactions/position-object/types.js.map +0 -1
- package/dist/interactions/select-point/index.d.ts +0 -2
- package/dist/interactions/select-point/index.js +0 -2
- package/dist/interactions/select-point/index.js.map +0 -1
- package/dist/interactions/select-point/types.d.ts +0 -1
- package/dist/interactions/select-point/types.js +0 -2
- package/dist/interactions/select-point/types.js.map +0 -1
- package/dist/interactions/shared/index.d.ts +0 -1
- package/dist/interactions/shared/index.js +0 -2
- package/dist/interactions/shared/index.js.map +0 -1
- package/dist/interactions/slider/index.d.ts +0 -2
- package/dist/interactions/slider/index.js +0 -2
- package/dist/interactions/slider/index.js.map +0 -1
- package/dist/interactions/slider/types.d.ts +0 -1
- package/dist/interactions/slider/types.js +0 -2
- package/dist/interactions/slider/types.js.map +0 -1
- package/dist/interactions/text-entry/index.d.ts +0 -2
- package/dist/interactions/text-entry/index.js +0 -2
- package/dist/interactions/text-entry/index.js.map +0 -1
- package/dist/interactions/text-entry/types.d.ts +0 -1
- package/dist/interactions/text-entry/types.js +0 -2
- package/dist/interactions/text-entry/types.js.map +0 -1
- package/dist/interactions/upload/index.d.ts +0 -2
- package/dist/interactions/upload/index.js +0 -2
- package/dist/interactions/upload/index.js.map +0 -1
- package/dist/interactions/upload/types.d.ts +0 -1
- package/dist/interactions/upload/types.js +0 -2
- package/dist/interactions/upload/types.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/extraction/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAK3D;;GAEG;AACH,SAAS,cAAc,CAAC,OAAsC;IAC7D,OAAO,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC3C,CAAC;AAED;;;GAGG;AACH,SAAS,cAAc,CAAC,OAAsC;IAC7D,MAAM,IAAI,GAAG,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAC9C,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC;AAClC,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CACxB,OAAsC,EACtC,OAAe;IAEf,OAAQ,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,UAAU,KAAK,OAAO,CAAkB,IAAI,EAAE,CAAC;AAC7F,CAAC;AAED;;GAEG;AACH,SAAS,0BAA0B,CAClC,OAA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CAAC;QACpE,CAAC;QAED,SAAS,CAAC,OAAmB;YAC5B,MAAM,aAAa,GAAG,0BAA0B,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;YACtF,OAAO,aAAa,CAAC,CAAC,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAC7D,CAAC;QAED,UAAU,CAAC,OAAmB;YAC7B,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;QAC5B,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Extraction utilities implementation\n *\n * Provides DOM manipulation and content extraction helpers for extractors\n */\n\nimport type { ElementNameMapper, AttributeNameMapper } from '@pie-qti/qti-common';\nimport { Qti2xElementNameMapper, Qti2xAttributeNameMapper } from '@pie-qti/qti-common';\nimport { sanitizeTextContent } from '../core/sanitizer.js';\nimport type { PlayerSecurityConfig } from '../types/index.js';\nimport type { QTIElement } from '../interactions/index.js';\nimport type { ExtractionUtils } from './types.js';\n\n/**\n * Extract text content from QTI elements\n */\nfunction getTextContent(element: QTIElement | null | undefined): string {\n\treturn element?.textContent?.trim() || '';\n}\n\n/**\n * Extract HTML content from QTI elements (preserves MathML and other markup)\n * Content is sanitized to prevent XSS attacks\n */\nfunction getHtmlContent(element: QTIElement | null | undefined): string {\n\tconst html = element?.innerHTML?.trim() || '';\n\treturn sanitizeTextContent(html);\n}\n\n/**\n * Get children by tag name from QTI elements\n * Note: This version does NOT handle QTI version mapping - use the one in ExtractionUtils instead\n */\nfunction getChildrenByTag(\n\telement: QTIElement | null | undefined,\n\ttagName: string\n): QTIElement[] {\n\treturn (element?.childNodes?.filter((n) => n.rawTagName === tagName) as QTIElement[]) || [];\n}\n\n/**\n * Get children by tag name with QTI version awareness\n */\nfunction getChildrenByTagWithMapper(\n\telement: QTIElement | null | undefined,\n\ttagName: string,\n\tmapper: ElementNameMapper\n): QTIElement[] {\n\tif (!element?.childNodes) return [];\n\treturn element.childNodes.filter((n) =>\n\t\tmatchesTagName((n as QTIElement).rawTagName, tagName, mapper)\n\t) as QTIElement[];\n}\n\n/**\n * Extract a boolean attribute from a QTI element\n * Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes\n */\nfunction getBooleanAttribute(\n\telement: QTIElement,\n\tname: string,\n\tdefaultValue = false,\n\tattributeMapper?: AttributeNameMapper\n): boolean {\n\tlet value = element.getAttribute(name);\n\n\t// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)\n\tif ((value === null || value === undefined) && attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(name);\n\t\tvalue = element.getAttribute(nativeName);\n\t}\n\n\tif (value === null || value === undefined) return defaultValue;\n\treturn value === 'true';\n}\n\n/**\n * Extract a number attribute from a QTI element\n * Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes\n */\nfunction getNumberAttribute(\n\telement: QTIElement,\n\tname: string,\n\tdefaultValue: number,\n\tattributeMapper?: AttributeNameMapper\n): number {\n\tlet value = element.getAttribute(name);\n\n\t// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)\n\tif ((value === null || value === undefined) && attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(name);\n\t\tvalue = element.getAttribute(nativeName);\n\t}\n\n\treturn value ? Number(value) : defaultValue;\n}\n\n/**\n * Extract a string attribute from a QTI element\n * Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes\n */\nfunction getStringAttribute(\n\telement: QTIElement,\n\tname: string,\n\tdefaultValue = '',\n\tattributeMapper?: AttributeNameMapper\n): string {\n\tlet value = element.getAttribute(name);\n\n\t// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)\n\tif ((value === null || value === undefined) && attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(name);\n\t\tvalue = element.getAttribute(nativeName);\n\t}\n\n\treturn value || defaultValue;\n}\n\n/**\n * Extract CSS classes from an element\n */\nfunction getClasses(element: QTIElement): string[] {\n\tconst classAttr = element.getAttribute('class');\n\treturn classAttr ? classAttr.split(/\\s+/).filter(Boolean) : [];\n}\n\n/**\n * Helper to check if an element's tag name matches a given QTI element name.\n * Handles both QTI 2.x and QTI 3.0 element naming conventions.\n *\n * @param rawTagName - The element's raw tag name from the HTML\n * @param expectedTagName - The tag name to check (in QTI 2.x format, e.g., 'simpleChoice')\n * @param mapper - Optional element name mapper for QTI version handling\n * @returns true if the tag name matches\n */\nfunction matchesTagName(\n\trawTagName: string | undefined,\n\texpectedTagName: string,\n\tmapper: ElementNameMapper\n): boolean {\n\tif (!rawTagName) return false;\n\n\t// Convert expected tag name to canonical form (lowercase)\n\tconst canonical = expectedTagName.toLowerCase();\n\n\t// Get the native form for this QTI version\n\tconst native = mapper.toNative(canonical);\n\n\t// Check if raw tag name matches the native form (case-insensitive)\n\treturn rawTagName.toLowerCase() === native.toLowerCase();\n}\n\n/**\n * Create extraction utilities instance\n * Provides standard helpers for extracting data from QTI elements.\n * Automatically handles both QTI 2.x and QTI 3.0 element and attribute naming conventions.\n */\nexport function createExtractionUtils(\n\tsecurity?: PlayerSecurityConfig,\n\tmapper?: ElementNameMapper,\n\tattributeMapper?: AttributeNameMapper\n): ExtractionUtils {\n\t// Default to QTI 2.x mappers (primary supported QTI format)\n\tconst elementMapper = mapper || new Qti2xElementNameMapper();\n\tconst attrMapper = attributeMapper || new Qti2xAttributeNameMapper();\n\treturn {\n\t\tgetChildrenByTag(element: QTIElement, tagName: string): QTIElement[] {\n\t\t\treturn getChildrenByTagWithMapper(element, tagName, elementMapper);\n\t\t},\n\n\t\tquerySelectorAll(element: QTIElement, selector: string): QTIElement[] {\n\t\t\t// Parse simple selectors like \"choiceInteraction simpleChoice\"\n\t\t\tconst parts = selector.split(/\\s+/);\n\t\t\tlet results: QTIElement[] = [element];\n\n\t\t\tfor (const part of parts) {\n\t\t\t\tconst nextResults: QTIElement[] = [];\n\t\t\t\tfor (const current of results) {\n\t\t\t\t\tif (matchesTagName(current.rawTagName, part, elementMapper)) {\n\t\t\t\t\t\tnextResults.push(current);\n\t\t\t\t\t}\n\t\t\t\t\tif (current.childNodes) {\n\t\t\t\t\t\tfor (const child of current.childNodes) {\n\t\t\t\t\t\t\tif (typeof child !== 'string' && matchesTagName((child as QTIElement).rawTagName, part, elementMapper)) {\n\t\t\t\t\t\t\t\tnextResults.push(child as QTIElement);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresults = nextResults;\n\t\t\t}\n\n\t\t\treturn results;\n\t\t},\n\n\t\tquerySelector(element: QTIElement, selector: string): QTIElement | null {\n\t\t\tconst results = this.querySelectorAll(element, selector);\n\t\t\treturn results.length > 0 ? results[0] : null;\n\t\t},\n\n\t\thasChildWithTag(element: QTIElement, tagName: string): boolean {\n\t\t\t// Fast boolean check without allocation\n\t\t\tif (!element.childNodes) return false;\n\n\t\t\tfor (const child of element.childNodes) {\n\t\t\t\tif (typeof child !== 'string' && matchesTagName((child as QTIElement).rawTagName, tagName, elementMapper)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\n\t\tgetHtmlContent(element: QTIElement): string {\n\t\t\tconst html = element?.innerHTML?.trim() || '';\n\t\t\treturn sanitizeTextContent(html, { security });\n\t\t},\n\n\t\tgetTextContent(element: QTIElement): string {\n\t\t\treturn getTextContent(element);\n\t\t},\n\n\t\tgetAttribute(element: QTIElement, name: string, defaultValue = ''): string {\n\t\t\treturn getStringAttribute(element, name, defaultValue, attrMapper);\n\t\t},\n\n\t\tgetBooleanAttribute(element: QTIElement, name: string, defaultValue = false): boolean {\n\t\t\treturn getBooleanAttribute(element, name, defaultValue, attrMapper);\n\t\t},\n\n\t\tgetNumberAttribute(element: QTIElement, name: string, defaultValue = 0): number {\n\t\t\treturn getNumberAttribute(element, name, defaultValue, attrMapper);\n\t\t},\n\n\t\tgetPrompt(element: QTIElement): string | null {\n\t\t\tconst promptElement = getChildrenByTagWithMapper(element, 'prompt', elementMapper)[0];\n\t\t\treturn promptElement ? getHtmlContent(promptElement) : null;\n\t\t},\n\n\t\tgetClasses(element: QTIElement): string[] {\n\t\t\treturn getClasses(element);\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/extraction/utils.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAK3D;;GAEG;AACH,SAAS,cAAc,CAAC,OAAsC;IAC7D,OAAO,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;AAC3C,CAAC;AAED;;GAEG;AACH,SAAS,0BAA0B,CAClC,OAAsC,EACtC,OAAe,EACf,MAAyB;IAEzB,IAAI,CAAC,OAAO,EAAE,UAAU;QAAE,OAAO,EAAE,CAAC;IACpC,OAAO,OAAO,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CACtC,cAAc,CAAE,CAAgB,CAAC,UAAU,EAAE,OAAO,EAAE,MAAM,CAAC,CAC7C,CAAC;AACnB,CAAC;AAED;;;GAGG;AACH,SAAS,mBAAmB,CAC3B,OAAmB,EACnB,IAAY,EACZ,YAAY,GAAG,KAAK,EACpB,eAAqC;IAErC,IAAI,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;IAEvC,gFAAgF;IAChF,IAAI,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,IAAI,eAAe,EAAE,CAAC;QAChE,MAAM,UAAU,GAAG,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QAClD,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC,UAAU,CAAC,CAAC;IAC1C,CAAC;IAED,IAAI,KAAK,KAAK,IAAI,IAAI,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OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;YAC9C,OAAO,mBAAmB,CAAC,IAAI,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;QAChD,CAAC;QAED,cAAc,CAAC,OAAmB;YACjC,OAAO,cAAc,CAAC,OAAO,CAAC,CAAC;QAChC,CAAC;QAED,YAAY,CAAC,OAAmB,EAAE,IAAY,EAAE,YAAY,GAAG,EAAE;YAChE,OAAO,kBAAkB,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QACpE,CAAC;QAED,mBAAmB,CAAC,OAAmB,EAAE,IAAY,EAAE,YAAY,GAAG,KAAK;YAC1E,OAAO,mBAAmB,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QACrE,CAAC;QAED,kBAAkB,CAAC,OAAmB,EAAE,IAAY,EAAE,YAAY,GAAG,CAAC;YACrE,OAAO,kBAAkB,CAAC,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,UAAU,CAAC,CAAC;QACpE,CAAC;QAED,SAAS,CAAC,OAAmB;YAC5B,MAAM,aAAa,GAAG,0BAA0B,CAAC,OAAO,EAAE,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC;YACtF,OAAO,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAClE,CAAC;QAED,UAAU,CAAC,OAAmB;YAC7B,OAAO,UAAU,CAAC,OAAO,CAAC,CAAC;QAC5B,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["/**\n * Extraction utilities implementation\n *\n * Provides DOM manipulation and content extraction helpers for extractors\n */\n\nimport type { ElementNameMapper, AttributeNameMapper } from '@pie-qti/qti-common';\nimport { Qti2xElementNameMapper, Qti2xAttributeNameMapper } from '@pie-qti/qti-common';\nimport { sanitizeTextContent } from '../core/sanitizer.js';\nimport type { PlayerSecurityConfig } from '../types/index.js';\nimport type { QTIElement } from '../interactions/shared/types.js';\nimport type { ExtractionUtils } from './types.js';\n\n/**\n * Extract text content from QTI elements\n */\nfunction getTextContent(element: QTIElement | null | undefined): string {\n\treturn element?.textContent?.trim() || '';\n}\n\n/**\n * Get children by tag name with QTI version awareness\n */\nfunction getChildrenByTagWithMapper(\n\telement: QTIElement | null | undefined,\n\ttagName: string,\n\tmapper: ElementNameMapper\n): QTIElement[] {\n\tif (!element?.childNodes) return [];\n\treturn element.childNodes.filter((n) =>\n\t\tmatchesTagName((n as QTIElement).rawTagName, tagName, mapper)\n\t) as QTIElement[];\n}\n\n/**\n * Extract a boolean attribute from a QTI element\n * Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes\n */\nfunction getBooleanAttribute(\n\telement: QTIElement,\n\tname: string,\n\tdefaultValue = false,\n\tattributeMapper?: AttributeNameMapper\n): boolean {\n\tlet value = element.getAttribute(name);\n\n\t// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)\n\tif ((value === null || value === undefined) && attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(name);\n\t\tvalue = element.getAttribute(nativeName);\n\t}\n\n\tif (value === null || value === undefined) return defaultValue;\n\treturn value === 'true';\n}\n\n/**\n * Extract a number attribute from a QTI element\n * Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes\n */\nfunction getNumberAttribute(\n\telement: QTIElement,\n\tname: string,\n\tdefaultValue: number,\n\tattributeMapper?: AttributeNameMapper\n): number {\n\tlet value = element.getAttribute(name);\n\n\t// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)\n\tif ((value === null || value === undefined) && attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(name);\n\t\tvalue = element.getAttribute(nativeName);\n\t}\n\n\treturn value ? Number(value) : defaultValue;\n}\n\n/**\n * Extract a string attribute from a QTI element\n * Supports both QTI 2.x (camelCase) and QTI 3.0 (kebab-case) attributes\n */\nfunction getStringAttribute(\n\telement: QTIElement,\n\tname: string,\n\tdefaultValue = '',\n\tattributeMapper?: AttributeNameMapper\n): string {\n\tlet value = element.getAttribute(name);\n\n\t// If not found and we have a mapper, try the native format (QTI 3.0 kebab-case)\n\tif ((value === null || value === undefined) && attributeMapper) {\n\t\tconst nativeName = attributeMapper.toNative(name);\n\t\tvalue = element.getAttribute(nativeName);\n\t}\n\n\treturn value || defaultValue;\n}\n\n/**\n * Extract CSS classes from an element\n */\nfunction getClasses(element: QTIElement): string[] {\n\tconst classAttr = element.getAttribute('class');\n\treturn classAttr ? classAttr.split(/\\s+/).filter(Boolean) : [];\n}\n\n/**\n * Helper to check if an element's tag name matches a given QTI element name.\n * Handles both QTI 2.x and QTI 3.0 element naming conventions.\n *\n * @param rawTagName - The element's raw tag name from the HTML\n * @param expectedTagName - The tag name to check (in QTI 2.x format, e.g., 'simpleChoice')\n * @param mapper - Optional element name mapper for QTI version handling\n * @returns true if the tag name matches\n */\nfunction matchesTagName(\n\trawTagName: string | undefined,\n\texpectedTagName: string,\n\tmapper: ElementNameMapper\n): boolean {\n\tif (!rawTagName) return false;\n\n\t// Convert expected tag name to canonical form (lowercase)\n\tconst canonical = expectedTagName.toLowerCase();\n\n\t// Get the native form for this QTI version\n\tconst native = mapper.toNative(canonical);\n\n\t// Check if raw tag name matches the native form (case-insensitive)\n\treturn rawTagName.toLowerCase() === native.toLowerCase();\n}\n\n/**\n * Create extraction utilities instance\n * Provides standard helpers for extracting data from QTI elements.\n * Automatically handles both QTI 2.x and QTI 3.0 element and attribute naming conventions.\n */\nexport function createExtractionUtils(\n\tsecurity?: PlayerSecurityConfig,\n\tmapper?: ElementNameMapper,\n\tattributeMapper?: AttributeNameMapper\n): ExtractionUtils {\n\t// Default to QTI 2.x mappers (primary supported QTI format)\n\tconst elementMapper = mapper || new Qti2xElementNameMapper();\n\tconst attrMapper = attributeMapper || new Qti2xAttributeNameMapper();\n\treturn {\n\t\tmatchesTag(element: QTIElement, tagName: string): boolean {\n\t\t\treturn matchesTagName(element.rawTagName, tagName, elementMapper);\n\t\t},\n\n\t\tgetChildrenByTag(element: QTIElement, tagName: string): QTIElement[] {\n\t\t\treturn getChildrenByTagWithMapper(element, tagName, elementMapper);\n\t\t},\n\n\t\tquerySelectorAll(element: QTIElement, selector: string): QTIElement[] {\n\t\t\t// Parse simple selectors like \"choiceInteraction simpleChoice\"\n\t\t\tconst parts = selector.split(/\\s+/);\n\t\t\tlet results: QTIElement[] = [element];\n\n\t\t\tfor (const part of parts) {\n\t\t\t\tconst nextResults: QTIElement[] = [];\n\t\t\t\tfor (const current of results) {\n\t\t\t\t\tif (matchesTagName(current.rawTagName, part, elementMapper)) {\n\t\t\t\t\t\tnextResults.push(current);\n\t\t\t\t\t}\n\t\t\t\t\tif (current.childNodes) {\n\t\t\t\t\t\tfor (const child of current.childNodes) {\n\t\t\t\t\t\t\tif (typeof child !== 'string' && matchesTagName((child as QTIElement).rawTagName, part, elementMapper)) {\n\t\t\t\t\t\t\t\tnextResults.push(child as QTIElement);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tresults = nextResults;\n\t\t\t}\n\n\t\t\treturn results;\n\t\t},\n\n\t\tquerySelector(element: QTIElement, selector: string): QTIElement | null {\n\t\t\tconst results = this.querySelectorAll(element, selector);\n\t\t\treturn results.length > 0 ? results[0] : null;\n\t\t},\n\n\t\thasChildWithTag(element: QTIElement, tagName: string): boolean {\n\t\t\t// Fast boolean check without allocation\n\t\t\tif (!element.childNodes) return false;\n\n\t\t\tfor (const child of element.childNodes) {\n\t\t\t\tif (typeof child !== 'string' && matchesTagName((child as QTIElement).rawTagName, tagName, elementMapper)) {\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn false;\n\t\t},\n\n\t\tgetHtmlContent(element: QTIElement): string {\n\t\t\tconst html = element?.innerHTML?.trim() || '';\n\t\t\treturn sanitizeTextContent(html, { security });\n\t\t},\n\n\t\tgetTextContent(element: QTIElement): string {\n\t\t\treturn getTextContent(element);\n\t\t},\n\n\t\tgetAttribute(element: QTIElement, name: string, defaultValue = ''): string {\n\t\t\treturn getStringAttribute(element, name, defaultValue, attrMapper);\n\t\t},\n\n\t\tgetBooleanAttribute(element: QTIElement, name: string, defaultValue = false): boolean {\n\t\t\treturn getBooleanAttribute(element, name, defaultValue, attrMapper);\n\t\t},\n\n\t\tgetNumberAttribute(element: QTIElement, name: string, defaultValue = 0): number {\n\t\t\treturn getNumberAttribute(element, name, defaultValue, attrMapper);\n\t\t},\n\n\t\tgetPrompt(element: QTIElement): string | null {\n\t\t\tconst promptElement = getChildrenByTagWithMapper(element, 'prompt', elementMapper)[0];\n\t\t\treturn promptElement ? this.getHtmlContent(promptElement) : null;\n\t\t},\n\n\t\tgetClasses(element: QTIElement): string[] {\n\t\t\treturn getClasses(element);\n\t\t},\n\t};\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,13 +6,14 @@ export { type ComponentConfig, type ComponentPlugin, ComponentRegistry, createCo
|
|
|
6
6
|
export * from './core/constants.js';
|
|
7
7
|
export * from './core/declarations.js';
|
|
8
8
|
export * from './utils/drawingUtils.js';
|
|
9
|
-
export {
|
|
9
|
+
export { createAssessmentItemDefinition, type AssessmentItemDefinition, type AssessmentItemDefinitionConfig, type AssessmentItemDefinitionPlugin, } from './core/AssessmentItemDefinition.js';
|
|
10
|
+
export { type ItemPresentationView, type ItemSession, type ItemSessionCommand, type ItemSessionEventCommand, type ItemSessionListener, type ItemSessionTransition, type ItemSessionView, type OpenItemSessionOptions, } from './core/ItemSession.js';
|
|
11
|
+
export type { FinalItemBodyHtml, ItemInteractionMount, ItemPresentation, ItemPresentationFlowNode, } from './presentation/itemPresentationPlan.js';
|
|
10
12
|
export { getRoleCapabilities, type RoleCapabilities } from './core/rolePolicy.js';
|
|
11
|
-
export
|
|
12
|
-
export {
|
|
13
|
-
export
|
|
14
|
-
export
|
|
15
|
-
export { createExtractionContext, createExtractionRegistry, createExtractionUtils, ExtractionError, ExtractionRegistry, isErrorResult, isSuccessResult, } from './extraction/index.js';
|
|
13
|
+
export type * from './interactions/shared/types.js';
|
|
14
|
+
export { createExtendedTextNumericRecord, createExtendedTextResponse, createExtendedTextStringResponse, extendedTextResponseToStrings, type ExtendedTextNumericRecord, type ExtendedTextRecordField, } from './interactions/extended-text/response.js';
|
|
15
|
+
export type { ElementExtractor, ExtractionContext, ExtractionDispatchResult, ExtractionResult, ExtractionUtils, InteractionDeliveryField, InteractionDeliveryPathSegment, InteractionDeliverySchema, ValidationResult, VariableDeclaration, } from './extraction/index.js';
|
|
16
|
+
export { createExtractionContext, createExtractionRegistry, createExtractionUtils, ExtractionError, ExtractionRegistry, htmlField, isErrorResult, isSuccessResult, urlField, } from './extraction/index.js';
|
|
16
17
|
export * from './types/index.js';
|
|
17
18
|
export { globalPerformanceMonitor, type PerformanceEntry, PerformanceMonitor, type PerformanceMonitorConfig, type PerformanceReport, } from './utils/PerformanceMonitor.js';
|
|
18
19
|
export { isResponseEmpty } from './utils/responseUtils.js';
|
|
@@ -30,8 +31,8 @@ export { normalizeHeuristicsConfig, applyFeedbackTextHeuristics, shouldUseLenien
|
|
|
30
31
|
/**
|
|
31
32
|
* NOTE (SSR safety):
|
|
32
33
|
* Web component base classes depend on DOM globals like `HTMLElement` and must not be
|
|
33
|
-
* re-exported from the main entrypoint
|
|
34
|
-
*
|
|
34
|
+
* re-exported from the main entrypoint. Item ownership flows through
|
|
35
|
+
* AssessmentItemDefinition and ItemSession in every deployment.
|
|
35
36
|
*
|
|
36
37
|
* Import web-components from the subpath entry instead:
|
|
37
38
|
* - `@pie-qti/item-player/web-components`
|
package/dist/index.js
CHANGED
|
@@ -8,12 +8,10 @@ export * from './core/constants.js';
|
|
|
8
8
|
export * from './core/declarations.js';
|
|
9
9
|
// Export drawing utilities
|
|
10
10
|
export * from './utils/drawingUtils.js';
|
|
11
|
-
export {
|
|
11
|
+
export { createAssessmentItemDefinition, } from './core/AssessmentItemDefinition.js';
|
|
12
12
|
export { getRoleCapabilities } from './core/rolePolicy.js';
|
|
13
|
-
export {
|
|
14
|
-
|
|
15
|
-
export * from './interactions/index.js';
|
|
16
|
-
export { createExtractionContext, createExtractionRegistry, createExtractionUtils, ExtractionError, ExtractionRegistry, isErrorResult, isSuccessResult, } from './extraction/index.js';
|
|
13
|
+
export { createExtendedTextNumericRecord, createExtendedTextResponse, createExtendedTextStringResponse, extendedTextResponseToStrings, } from './interactions/extended-text/response.js';
|
|
14
|
+
export { createExtractionContext, createExtractionRegistry, createExtractionUtils, ExtractionError, ExtractionRegistry, htmlField, isErrorResult, isSuccessResult, urlField, } from './extraction/index.js';
|
|
17
15
|
// NOTE:
|
|
18
16
|
// The player’s primary rendering contract is via web components and the Svelte component entrypoint.
|
|
19
17
|
// If you need non-web-component rendering, build it externally against the public extraction APIs.
|
|
@@ -34,8 +32,8 @@ export { normalizeHeuristicsConfig, applyFeedbackTextHeuristics, shouldUseLenien
|
|
|
34
32
|
/**
|
|
35
33
|
* NOTE (SSR safety):
|
|
36
34
|
* Web component base classes depend on DOM globals like `HTMLElement` and must not be
|
|
37
|
-
* re-exported from the main entrypoint
|
|
38
|
-
*
|
|
35
|
+
* re-exported from the main entrypoint. Item ownership flows through
|
|
36
|
+
* AssessmentItemDefinition and ItemSession in every deployment.
|
|
39
37
|
*
|
|
40
38
|
* Import web-components from the subpath entry instead:
|
|
41
39
|
* - `@pie-qti/item-player/web-components`
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,4DAA4D;AAC5D,OAAO,EAGN,iBAAiB,EACjB,uBAAuB,GACvB,MAAM,6BAA6B,CAAC;AACrC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,2BAA2B;AAC3B,cAAc,yBAAyB,CAAC;AACxC,OAAO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N,yBAAyB,EACzB,2BAA2B,EAC3B,0BAA0B,EAC1B,iCAAiC,EACjC,yBAAyB,EACzB,iBAAiB,EACjB,wBAAwB,GAGxB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;GAQG","sourcesContent":["/**\n * @pie-qti/item-player\n * Modern QTI player (2.2/3.0) - Framework-agnostic with web components\n */\n\n\n// Export web component registry for pluggable UI components\nexport {\n\ttype ComponentConfig,\n\ttype ComponentPlugin,\n\tComponentRegistry,\n\tcreateComponentRegistry,\n} from './core/ComponentRegistry.js';\nexport * from './core/constants.js';\nexport * from './core/declarations.js';\n// Export drawing utilities\nexport * from './utils/drawingUtils.js';\nexport {\n\tcreateAssessmentItemDefinition,\n\ttype AssessmentItemDefinition,\n\ttype AssessmentItemDefinitionConfig,\n\ttype AssessmentItemDefinitionPlugin,\n} from './core/AssessmentItemDefinition.js';\nexport {\n\ttype ItemPresentationView,\n\ttype ItemSession,\n\ttype ItemSessionCommand,\n\ttype ItemSessionEventCommand,\n\ttype ItemSessionListener,\n\ttype ItemSessionTransition,\n\ttype ItemSessionView,\n\ttype OpenItemSessionOptions,\n} from './core/ItemSession.js';\nexport type {\n\tFinalItemBodyHtml,\n\tItemInteractionMount,\n\tItemPresentation,\n\tItemPresentationFlowNode,\n} from './presentation/itemPresentationPlan.js';\nexport { getRoleCapabilities, type RoleCapabilities } from './core/rolePolicy.js';\n// Render-facing interaction contracts. Standard extractors remain implementation details.\nexport type * from './interactions/shared/types.js';\nexport {\n\tcreateExtendedTextNumericRecord,\n\tcreateExtendedTextResponse,\n\tcreateExtendedTextStringResponse,\n\textendedTextResponseToStrings,\n\ttype ExtendedTextNumericRecord,\n\ttype ExtendedTextRecordField,\n} from './interactions/extended-text/response.js';\nexport type {\n\tElementExtractor,\n\tExtractionContext,\n\tExtractionDispatchResult,\n\tExtractionResult,\n\tExtractionUtils,\n\tInteractionDeliveryField,\n\tInteractionDeliveryPathSegment,\n\tInteractionDeliverySchema,\n\tValidationResult,\n\tVariableDeclaration,\n} from './extraction/index.js';\nexport {\n\tcreateExtractionContext,\n\tcreateExtractionRegistry,\n\tcreateExtractionUtils,\n\tExtractionError,\n\tExtractionRegistry,\n\thtmlField,\n\tisErrorResult,\n\tisSuccessResult,\n\turlField,\n} from './extraction/index.js';\n// NOTE:\n// The player’s primary rendering contract is via web components and the Svelte component entrypoint.\n// If you need non-web-component rendering, build it externally against the public extraction APIs.\n// Export all types including adaptive item types\nexport * from './types/index.js';\n// Export utilities\nexport {\n\tglobalPerformanceMonitor,\n\ttype PerformanceEntry,\n\tPerformanceMonitor,\n\ttype PerformanceMonitorConfig,\n\ttype PerformanceReport,\n} from './utils/PerformanceMonitor.js';\n\nexport { isResponseEmpty } from './utils/responseUtils.js';\n\n// PNP profile (QTI 3.0 §6.2)\nexport type { PnpProfile } from './pnp/types.js';\nexport { applyPnpToRoot } from './pnp/applyPnp.js';\nexport { parsePnpXml } from './pnp/parsePnpXml.js';\n\n// Catalog (QTI 3.0 §6.3)\nexport type { CatalogIndex, CatalogCard, CatalogEntry } from './catalog/types.js';\nexport { extractCatalog, extractCatalogFromItemXml, mergeCatalogs } from './catalog/catalogExtractor.js';\nexport { getCatalogEntry } from './catalog/catalogLookup.js';\nexport type { ResolvedItemDeliveryContext } from '@pie-qti/ims-cp-core';\n\n// PCI — Portable Custom Interaction (QTI 3.0 §6.1)\nexport type {\n\tExtractedPci,\n\tPciBoundTo,\n\tPciConfiguration,\n\tPciHostController,\n\tPciHostOptions,\n\tPciModule,\n\tPciModulePathKind,\n\tPciModuleResolutionContext,\n\tPciModuleResolver,\n} from './pci/types.js';\nexport { PciLoadError, PciModuleResolverRequiredError } from './pci/types.js';\nexport { PciHost } from './pci/PciHost.js';\n\n// Re-export QTI heuristics from @pie-qti/ims-cp-core for convenience\n// (heuristics are now in the shared ingestion layer)\nexport {\n\tnormalizeHeuristicsConfig,\n\tapplyFeedbackTextHeuristics,\n\tshouldUseLenientImagePaths,\n\tshouldAutoPopulateFeedbackOutcome,\n\tDEFAULT_HEURISTICS_CONFIG,\n\tSTRICT_QTI_CONFIG,\n\tFEEDBACK_TEXT_TRANSFORMS,\n\ttype QtiHeuristicsConfig,\n\ttype TextTransform,\n} from '@pie-qti/ims-cp-core';\n\n/**\n * NOTE (SSR safety):\n * Web component base classes depend on DOM globals like `HTMLElement` and must not be\n * re-exported from the main entrypoint. Item ownership flows through\n * AssessmentItemDefinition and ItemSession in every deployment.\n *\n * Import web-components from the subpath entry instead:\n * - `@pie-qti/item-player/web-components`\n */\n"]}
|
|
@@ -16,7 +16,7 @@ export const standardAssociateExtractor = {
|
|
|
16
16
|
description: 'Extracts standard QTI associateInteraction (associating items)',
|
|
17
17
|
canHandle(element, context) {
|
|
18
18
|
// All associateInteraction elements with simpleAssociableChoice are standard
|
|
19
|
-
return (element
|
|
19
|
+
return (context.utils.matchesTag(element, 'associateInteraction') &&
|
|
20
20
|
context.utils.hasChildWithTag(element, 'simpleAssociableChoice'));
|
|
21
21
|
},
|
|
22
22
|
extract(element, context) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/associate/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAoBrD;;;GAGG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAoC;IAC1E,EAAE,EAAE,2BAA2B;IAC/B,IAAI,EAAE,oCAAoC;IAC1C,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,CAAC,sBAAsB,CAAC;IACtC,WAAW,EAAE,gEAAgE;IAE7E,SAAS,CAAC,OAAO,EAAE,OAAO;QACzB,6EAA6E;QAC7E,OAAO,CACN,OAAO,CAAC,UAAU,
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/associate/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,uB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AAI,CAAC,sCAAsC,CAAC,CAAC;QACrD,CAAC;QAED,2BAA2B;QAC3B,IAAI,IAAI,CAAC,eAAe,KAAK,SAAS,IAAI,IAAI,CAAC,eAAe,GAAG,CAAC,EAAE,CAAC;YACpE,MAAM,CAAC,IAAI,CAAC,sCAAsC,CAAC,CAAC;QACrD,CAAC;QAED,OAAO;YACN,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI associateInteraction extractor\n *\n * Extracts data from associateInteraction elements (associating items)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { maybeShuffle } from '../../core/shuffle.js';\n\n/**\n * Associate data extracted from associateInteraction elements\n */\nexport interface AssociateData {\n\tchoices: Array<{\n\t\tidentifier: string;\n\t\ttext: string;\n\t\tmatchMax: number;\n\t\tmatchMin?: number;\n\t\tmatchGroup?: string[];\n\t\tclasses?: string[];\n\t}>;\n\tshuffle: boolean;\n\tmaxAssociations: number;\n\tminAssociations?: number;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI associate interaction extractor\n * Handles associateInteraction elements (creating associations between items)\n */\nexport const standardAssociateExtractor: ElementExtractor<AssociateData> = {\n\tid: 'qti:associate-interaction',\n\tname: 'QTI Standard Associate Interaction',\n\tpriority: 10,\n\telementTypes: ['associateInteraction'],\n\tdescription: 'Extracts standard QTI associateInteraction (associating items)',\n\n\tcanHandle(element, context) {\n\t\t// All associateInteraction elements with simpleAssociableChoice are standard\n\t\treturn (\n\t\t\tcontext.utils.matchesTag(element, 'associateInteraction') &&\n\t\t\tcontext.utils.hasChildWithTag(element, 'simpleAssociableChoice')\n\t\t);\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract simpleAssociableChoice children\n\t\tconst choiceElements = utils.getChildrenByTag(element, 'simpleAssociableChoice');\n\t\tconst choices = choiceElements.map((choice) => {\n\t\t\tconst classes = utils.getClasses(choice);\n\t\t\tconst matchMax = utils.getNumberAttribute(choice, 'matchMax', 1);\n\t\t\tconst matchMin = utils.getNumberAttribute(choice, 'matchMin', 0);\n\t\t\tconst matchGroupRaw = utils.getAttribute(choice, 'matchGroup', '');\n\t\t\tconst matchGroup = matchGroupRaw.split(/\\s+/).filter(Boolean);\n\n\t\t\treturn {\n\t\t\t\tidentifier: utils.getAttribute(choice, 'identifier', ''),\n\t\t\t\ttext: utils.getHtmlContent(choice),\n\t\t\t\tmatchMax,\n\t\t\t\t...(matchMin > 0 ? { matchMin } : {}),\n\t\t\t\t...(matchGroup.length > 0 ? { matchGroup } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract attributes with proper defaults\n\t\tconst shuffle = utils.getBooleanAttribute(element, 'shuffle');\n\t\tconst maxAssociations = utils.getNumberAttribute(element, 'maxAssociations', 0);\n\t\tconst minAssociations = utils.getNumberAttribute(element, 'minAssociations', 0);\n\n\t\t// Extract prompt (optional)\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tconst prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;\n\n\t\treturn {\n\t\t\tchoices: maybeShuffle(choices, shuffle, context.shuffleRng),\n\t\t\tshuffle,\n\t\t\tmaxAssociations,\n\t\t\t...(minAssociations > 0 ? { minAssociations } : {}),\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\n\t\t// Validate choices exist\n\t\tif (!data.choices || data.choices.length < 2) {\n\t\t\terrors.push('associateInteraction must have at least 2 choices');\n\t\t}\n\n\t\t// Validate choice identifiers\n\t\tif (data.choices) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const choice of data.choices) {\n\t\t\t\tif (!choice.identifier) {\n\t\t\t\t\terrors.push('All choices must have an identifier');\n\t\t\t\t} else if (identifiers.has(choice.identifier)) {\n\t\t\t\t\terrors.push(`Duplicate choice identifier: ${choice.identifier}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(choice.identifier);\n\t\t\t\t}\n\n\t\t\t\t// Validate matchMax\n\t\t\t\tif (choice.matchMax < 0) {\n\t\t\t\t\terrors.push(`matchMax must be non-negative for choice ${choice.identifier}`);\n\t\t\t\t}\n\n\t\t\t\t// Validate matchMin\n\t\t\t\tif (choice.matchMin !== undefined && choice.matchMin < 0) {\n\t\t\t\t\terrors.push(`matchMin must be non-negative for choice ${choice.identifier}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate maxAssociations\n\t\tif (data.maxAssociations < 0) {\n\t\t\terrors.push('maxAssociations must be non-negative');\n\t\t}\n\n\t\t// Validate minAssociations\n\t\tif (data.minAssociations !== undefined && data.minAssociations < 0) {\n\t\t\terrors.push('minAssociations must be non-negative');\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t};\n\t},\n};\n"]}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Extracts data from drawingInteraction elements (drawing on canvas)
|
|
5
5
|
*/
|
|
6
|
+
import { normalizePixelDimension } from '../../security/styleValues.js';
|
|
6
7
|
/**
|
|
7
8
|
* Standard QTI drawing interaction extractor
|
|
8
9
|
* Handles drawingInteraction elements (drawing on a canvas)
|
|
@@ -13,9 +14,9 @@ export const standardDrawingExtractor = {
|
|
|
13
14
|
priority: 10,
|
|
14
15
|
elementTypes: ['drawingInteraction'],
|
|
15
16
|
description: 'Extracts standard QTI drawingInteraction (drawing on canvas)',
|
|
16
|
-
canHandle(element,
|
|
17
|
+
canHandle(element, context) {
|
|
17
18
|
// All drawingInteraction elements are standard
|
|
18
|
-
return element
|
|
19
|
+
return context.utils.matchesTag(element, 'drawingInteraction');
|
|
19
20
|
},
|
|
20
21
|
extract(element, context) {
|
|
21
22
|
const { utils } = context;
|
|
@@ -26,8 +27,8 @@ export const standardDrawingExtractor = {
|
|
|
26
27
|
const objectElement = objectElements[0];
|
|
27
28
|
const type = utils.getAttribute(objectElement, 'type', '');
|
|
28
29
|
const data = utils.getAttribute(objectElement, 'data', '');
|
|
29
|
-
const width = utils.getAttribute(objectElement, 'width', '');
|
|
30
|
-
const height = utils.getAttribute(objectElement, 'height', '');
|
|
30
|
+
const width = normalizePixelDimension(utils.getAttribute(objectElement, 'width', ''));
|
|
31
|
+
const height = normalizePixelDimension(utils.getAttribute(objectElement, 'height', ''));
|
|
31
32
|
if (type.startsWith('image/svg')) {
|
|
32
33
|
// Extract inline SVG content
|
|
33
34
|
const content = utils.getHtmlContent(objectElement);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/drawing/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/drawing/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAsBxE;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAkC;IACtE,EAAE,EAAE,yBAAyB;IAC7B,IAAI,EAAE,kCAAkC;IACxC,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,CAAC,oBAAoB,CAAC;IACpC,WAAW,EAAE,8DAA8D;IAE3E,SAAS,CAAC,OAAO,EAAE,OAAO;QACzB,+CAA+C;QAC/C,OAAO,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,oBAAoB,CAAC,CAAC;IAChE,CAAC;IAED,OAAO,CAAC,OAAO,EAAE,OAAO;QACvB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAE1B,+DAA+D;QAC/D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EAAE,CAAC;oBAC3B,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAC7B,CAAC;YACH,CAAC;QACF,CAAC;QAED,yBAAyB;QACzB,MAAM,aAAa,GAA2B,EAAE,CAAC;QACjD,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACxB,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;gBAC/D,aAAa,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YACpC,CAAC;QACF,CAAC;QAED,4BAA4B;QAC5B,MAAM,cAAc,GAAG,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACjE,MAAM,MAAM,GAAG,cAAc,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;QAE1F,OAAO;YACN,SAAS;YACT,aAAa;YACb,MAAM;SACN,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,IAAI;QACZ,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,8BAA8B;QAC9B,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACrB,QAAQ,CAAC,IAAI,CACZ,mFAAmF,CACnF,CAAC;QACH,CAAC;QAED,OAAO;YACN,KAAK,EAAE,IAAI;YACX,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI drawingInteraction extractor\n *\n * Extracts data from drawingInteraction elements (drawing on canvas)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { normalizePixelDimension } from '../../security/styleValues.js';\n\n/**\n * Image data for drawing interaction\n */\nexport interface ImageData {\n\ttype: 'image' | 'svg';\n\tsrc?: string;\n\tcontent?: string;\n\twidth?: string;\n\theight?: string;\n}\n\n/**\n * Drawing data extracted from drawingInteraction elements\n */\nexport interface DrawingData {\n\timageData: ImageData | null;\n\trawAttributes: Record<string, string>;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI drawing interaction extractor\n * Handles drawingInteraction elements (drawing on a canvas)\n */\nexport const standardDrawingExtractor: ElementExtractor<DrawingData> = {\n\tid: 'qti:drawing-interaction',\n\tname: 'QTI Standard Drawing Interaction',\n\tpriority: 10,\n\telementTypes: ['drawingInteraction'],\n\tdescription: 'Extracts standard QTI drawingInteraction (drawing on canvas)',\n\n\tcanHandle(element, context) {\n\t\t// All drawingInteraction elements are standard\n\t\treturn context.utils.matchesTag(element, 'drawingInteraction');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract background image data from object element (optional)\n\t\tconst objectElements = utils.getChildrenByTag(element, 'object');\n\t\tlet imageData: ImageData | null = null;\n\n\t\tif (objectElements.length > 0) {\n\t\t\tconst objectElement = objectElements[0];\n\t\t\tconst type = utils.getAttribute(objectElement, 'type', '');\n\t\t\tconst data = utils.getAttribute(objectElement, 'data', '');\n\t\t\tconst width = normalizePixelDimension(utils.getAttribute(objectElement, 'width', ''));\n\t\t\tconst height = normalizePixelDimension(utils.getAttribute(objectElement, 'height', ''));\n\n\t\t\tif (type.startsWith('image/svg')) {\n\t\t\t\t// Extract inline SVG content\n\t\t\t\tconst content = utils.getHtmlContent(objectElement);\n\t\t\t\timageData = {\n\t\t\t\t\ttype: 'svg',\n\t\t\t\t\tcontent,\n\t\t\t\t\t...(width ? { width } : {}),\n\t\t\t\t\t...(height ? { height } : {}),\n\t\t\t\t};\n\t\t\t} else if (data) {\n\t\t\t\t// External image reference\n\t\t\t\timageData = {\n\t\t\t\t\ttype: 'image',\n\t\t\t\t\tsrc: data,\n\t\t\t\t\t...(width ? { width } : {}),\n\t\t\t\t\t...(height ? { height } : {}),\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// Extract all attributes\n\t\tconst rawAttributes: Record<string, string> = {};\n\t\tif (element.attributes) {\n\t\t\tfor (const [key, value] of Object.entries(element.attributes)) {\n\t\t\t\trawAttributes[key] = String(value);\n\t\t\t}\n\t\t}\n\n\t\t// Extract prompt (optional)\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tconst prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;\n\n\t\treturn {\n\t\t\timageData,\n\t\t\trawAttributes,\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst warnings: string[] = [];\n\n\t\t// Warn if no background image\n\t\tif (!data.imageData) {\n\t\t\twarnings.push(\n\t\t\t\t'drawingInteraction has no background image - students will draw on a blank canvas'\n\t\t\t);\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: true,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
|
|
@@ -13,9 +13,9 @@ export const standardEndAttemptExtractor = {
|
|
|
13
13
|
priority: 10,
|
|
14
14
|
elementTypes: ['endAttemptInteraction'],
|
|
15
15
|
description: 'Extracts standard QTI endAttemptInteraction (end attempt button)',
|
|
16
|
-
canHandle(element,
|
|
16
|
+
canHandle(element, context) {
|
|
17
17
|
// All endAttemptInteraction elements are standard
|
|
18
|
-
return element
|
|
18
|
+
return context.utils.matchesTag(element, 'endAttemptInteraction');
|
|
19
19
|
},
|
|
20
20
|
extract(element, context) {
|
|
21
21
|
const { utils } = context;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/end-attempt/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAaH;;;GAGG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAqC;IAC5E,EAAE,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AK;YACL,YAAY;YACZ,MAAM;SACN,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,IAAI;QACZ,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,QAAQ,GAAa,EAAE,CAAC;QAE9B,8BAA8B;QAC9B,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC7C,MAAM,CAAC,IAAI,CAAC,yCAAyC,CAAC,CAAC;QACxD,CAAC;QAED,iDAAiD;QACjD,IAAI,IAAI,CAAC,YAAY,KAAK,KAAK,EAAE,CAAC;YACjC,QAAQ,CAAC,IAAI,CAAC,8EAA8E,CAAC,CAAC;QAC/F,CAAC;QAED,OAAO;YACN,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YAC9C,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI endAttemptInteraction extractor\n *\n * Extracts data from endAttemptInteraction elements (end attempt button)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\n\n/**\n * End attempt data extracted from endAttemptInteraction elements\n */\nexport interface EndAttemptData {\n\ttitle?: string;\n\tcountAttempt?: boolean;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI end attempt interaction extractor\n * Handles endAttemptInteraction elements (button to end the attempt)\n */\nexport const standardEndAttemptExtractor: ElementExtractor<EndAttemptData> = {\n\tid: 'qti:end-attempt-interaction',\n\tname: 'QTI Standard End Attempt Interaction',\n\tpriority: 10,\n\telementTypes: ['endAttemptInteraction'],\n\tdescription: 'Extracts standard QTI endAttemptInteraction (end attempt button)',\n\n\tcanHandle(element, context) {\n\t\t// All endAttemptInteraction elements are standard\n\t\treturn context.utils.matchesTag(element, 'endAttemptInteraction');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract attributes with defaults\n\t\tconst title = utils.getAttribute(element, 'title', 'End Attempt');\n\t\tconst countAttempt = element.hasAttribute('countAttempt')\n\t\t\t? utils.getBooleanAttribute(element, 'countAttempt')\n\t\t\t: true;\n\n\t\t// Extract prompt (optional)\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tconst prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;\n\n\t\treturn {\n\t\t\ttitle,\n\t\t\tcountAttempt,\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\t// Validate title is not empty\n\t\tif (!data.title || data.title.trim() === '') {\n\t\t\terrors.push('endAttemptInteraction must have a title');\n\t\t}\n\n\t\t// Warn if countAttempt is false (uncommon usage)\n\t\tif (data.countAttempt === false) {\n\t\t\twarnings.push('endAttemptInteraction has countAttempt=false - make sure this is intentional');\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* Extracts data from gapMatchInteraction elements (drag words into gaps)
|
|
5
5
|
*/
|
|
6
6
|
import { maybeShuffle } from '../../core/shuffle.js';
|
|
7
|
+
import { normalizeCssPixelLength } from '../../security/styleValues.js';
|
|
7
8
|
const GAP_ELEMENT_PATTERN = /<(?:qti-gap|gap)(?=[\s/>])([^>]*)\/?>/gi;
|
|
8
9
|
const GAP_CLOSE_PATTERN = /<\/(?:qti-gap|gap)>/gi;
|
|
9
10
|
const GAP_TEXT_PATTERN = /<(?:qti-gap-text|gapText)\b[\s\S]*?<\/(?:qti-gap-text|gapText)>/gi;
|
|
@@ -37,9 +38,9 @@ export const standardGapMatchExtractor = {
|
|
|
37
38
|
priority: 10,
|
|
38
39
|
elementTypes: ['gapMatchInteraction'],
|
|
39
40
|
description: 'Extracts standard QTI gapMatchInteraction (drag words into gaps)',
|
|
40
|
-
canHandle(element,
|
|
41
|
+
canHandle(element, context) {
|
|
41
42
|
// All gapMatchInteraction elements are standard
|
|
42
|
-
return element
|
|
43
|
+
return context.utils.matchesTag(element, 'gapMatchInteraction');
|
|
43
44
|
},
|
|
44
45
|
extract(element, context) {
|
|
45
46
|
const { utils } = context;
|
|
@@ -106,7 +107,7 @@ export const standardGapMatchExtractor = {
|
|
|
106
107
|
// Extract attributes
|
|
107
108
|
const shuffle = utils.getBooleanAttribute(element, 'shuffle');
|
|
108
109
|
const interactionClasses = utils.getClasses(element);
|
|
109
|
-
const choicesContainerWidth = utils.getAttribute(element, 'data-choices-container-width', '')
|
|
110
|
+
const choicesContainerWidth = normalizeCssPixelLength(utils.getAttribute(element, 'data-choices-container-width', ''));
|
|
110
111
|
const maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;
|
|
111
112
|
const minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;
|
|
112
113
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/gap-match/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAErD,MAAM,mBAAmB,GAAG,yCAAyC,CAAC;AACtE,MAAM,iBAAiB,GAAG,uBAAuB,CAAC;AAClD,MAAM,gBAAgB,GAAG,mEAAmE,CAAC;AAC7F,MAAM,sBAAsB,GAAG,6DAA6D,CAAC;AAC7F,MAAM,uBAAuB,GAAG,wDAAwD,CAAC;AACzF,MAAM,cAAc,GAAG,6DAA6D,CAAC;AAErF,SAAS,gBAAgB,CAAC,K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AED,oBAAoB;gBACpB,IAAI,OAAO,CAAC,QAAQ,GAAG,CAAC,EAAE,CAAC;oBAC1B,MAAM,CAAC,IAAI,CAAC,6CAA6C,OAAO,CAAC,UAAU,EAAE,CAAC,CAAC;gBAChF,CAAC;YACF,CAAC;QACF,CAAC;QAED,2BAA2B;QAC3B,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;YACf,MAAM,WAAW,GAAG,IAAI,GAAG,EAAU,CAAC;YACtC,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC;gBAC7B,IAAI,CAAC,GAAG,EAAE,CAAC;oBACV,MAAM,CAAC,IAAI,CAAC,kCAAkC,CAAC,CAAC;gBACjD,CAAC;qBAAM,IAAI,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;oBACjC,MAAM,CAAC,IAAI,CAAC,6BAA6B,GAAG,EAAE,CAAC,CAAC;gBACjD,CAAC;qBAAM,CAAC;oBACP,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACtB,CAAC;YACF,CAAC;QACF,CAAC;QAED,OAAO;YACN,KAAK,EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI gapMatchInteraction extractor\n *\n * Extracts data from gapMatchInteraction elements (drag words into gaps)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { maybeShuffle } from '../../core/shuffle.js';\n\nconst GAP_ELEMENT_PATTERN = /<(?:qti-gap|gap)(?=[\\s/>])([^>]*)\\/?>/gi;\nconst GAP_CLOSE_PATTERN = /<\\/(?:qti-gap|gap)>/gi;\nconst GAP_TEXT_PATTERN = /<(?:qti-gap-text|gapText)\\b[\\s\\S]*?<\\/(?:qti-gap-text|gapText)>/gi;\nconst GAP_MATCH_OPEN_PATTERN = /<(?:qti-gap-match-interaction|gapMatchInteraction)\\b[^>]*>/i;\nconst GAP_MATCH_CLOSE_PATTERN = /<\\/(?:qti-gap-match-interaction|gapMatchInteraction)>/i;\nconst PROMPT_PATTERN = /<(?:qti-prompt|prompt)\\b[\\s\\S]*?<\\/(?:qti-prompt|prompt)>/gi;\n\nfunction extractAttribute(attrs: string, name: string): string {\n\tconst match = new RegExp(`\\\\b${name}\\\\s*=\\\\s*(?:\"([^\"]*)\"|'([^']*)')`, 'i').exec(attrs);\n\treturn (match?.[1] ?? match?.[2] ?? '').trim();\n}\n\nfunction promptTextFromInteractionBody(interactionHtml: string): string {\n\treturn interactionHtml\n\t\t.replace(GAP_MATCH_OPEN_PATTERN, '')\n\t\t.replace(GAP_MATCH_CLOSE_PATTERN, '')\n\t\t.replace(PROMPT_PATTERN, '')\n\t\t.replace(GAP_TEXT_PATTERN, '')\n\t\t.replace(GAP_ELEMENT_PATTERN, (_match, attrs: string) => {\n\t\t\tconst id = extractAttribute(attrs, 'identifier');\n\t\t\treturn id ? `[GAP:${id}]` : '';\n\t\t})\n\t\t.replace(GAP_CLOSE_PATTERN, '')\n\t\t.trim();\n}\n\n/**\n * Gap match data extracted from gapMatchInteraction elements\n */\nexport interface GapMatchData {\n\tgapTexts: Array<{\n\t\tidentifier: string;\n\t\ttext: string;\n\t\tmatchMax: number;\n\t\tmatchMin?: number;\n\t\tmatchGroup?: string[];\n\t\tclasses?: string[];\n\t}>;\n\tgaps: string[];\n\tshuffle: boolean;\n\tprompt: string | null;\n\tpromptText: string;\n}\n\n/**\n * Standard QTI gap match interaction extractor\n * Handles gapMatchInteraction elements (drag words into gaps in text)\n */\nexport const standardGapMatchExtractor: ElementExtractor<GapMatchData> = {\n\tid: 'qti:gap-match-interaction',\n\tname: 'QTI Standard Gap Match Interaction',\n\tpriority: 10,\n\telementTypes: ['gapMatchInteraction'],\n\tdescription: 'Extracts standard QTI gapMatchInteraction (drag words into gaps)',\n\n\tcanHandle(element, _context) {\n\t\t// All gapMatchInteraction elements are standard\n\t\treturn element.rawTagName === 'gapMatchInteraction';\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract gapText children (draggable items)\n\t\tconst gapTextElements = utils.getChildrenByTag(element, 'gapText');\n\t\tconst gapTexts = gapTextElements.map((gapText) => {\n\t\t\tconst classes = utils.getClasses(gapText);\n\t\t\tconst matchMax = utils.getNumberAttribute(gapText, 'matchMax', 1);\n\t\t\tconst matchMin = utils.getNumberAttribute(gapText, 'matchMin', 0);\n\t\t\tconst matchGroupRaw = utils.getAttribute(gapText, 'matchGroup', '');\n\t\t\tconst matchGroup = matchGroupRaw.split(/\\s+/).filter(Boolean);\n\n\t\t\treturn {\n\t\t\t\tidentifier: utils.getAttribute(gapText, 'identifier', ''),\n\t\t\t\ttext: utils.getTextContent(gapText),\n\t\t\t\tmatchMax,\n\t\t\t\t...(matchMin > 0 ? { matchMin } : {}),\n\t\t\t\t...(matchGroup.length > 0 ? { matchGroup } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract prompt (optional) and process gap placeholders.\n\t\t// NOTE: Many QTI items place `<gap>` elements in the interaction content (e.g. a `<p>`/`<blockquote>`)\n\t\t// rather than inside a `<prompt>` element. Support both patterns.\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tlet prompt: string | null = null;\n\t\tlet promptText = '';\n\t\tconst gaps: string[] = [];\n\n\t\tif (promptElements.length > 0) {\n\t\t\tconst promptElement = promptElements[0];\n\t\t\tprompt = utils.getHtmlContent(promptElement);\n\n\t\t\t// Extract gap elements from prompt children\n\t\t\tconst gapElements = utils.getChildrenByTag(promptElement, 'gap');\n\t\t\tfor (const gap of gapElements) {\n\t\t\t\tgaps.push(utils.getAttribute(gap, 'identifier', ''));\n\t\t\t}\n\n\t\t\t// Replace gap elements with placeholders in the text\n\t\t\t// Derive renderable content only from the already-sanitized prompt. Using\n\t\t\t// outerHTML here would reintroduce event handlers and unsafe URLs that\n\t\t\t// getHtmlContent deliberately removed.\n\t\t\tpromptText = prompt\n\t\t\t\t.replace(GAP_ELEMENT_PATTERN, (_match, attrs: string) => {\n\t\t\t\t\tconst id = extractAttribute(attrs, 'identifier');\n\t\t\t\t\treturn id ? `[GAP:${id}]` : '';\n\t\t\t\t})\n\t\t\t\t.replace(GAP_CLOSE_PATTERN, '')\n\t\t\t\t.trim();\n\t\t}\n\n\t\t// If gaps were not found inside a <prompt>, search the full interaction body.\n\t\t// This handles items where <gap> elements appear in <p>/<blockquote> siblings of <prompt>.\n\t\tif (gaps.length === 0) {\n\t\t\t// Keep the fallback on the same sanitization boundary as prompt content.\n\t\t\tconst interactionHtml = utils.getHtmlContent(element);\n\t\t\tconst gapIdMatches = Array.from(interactionHtml.matchAll(GAP_ELEMENT_PATTERN));\n\t\t\tfor (const m of gapIdMatches) {\n\t\t\t\tconst id = extractAttribute(m[1] ?? '', 'identifier');\n\t\t\t\tif (id) gaps.push(id);\n\t\t\t}\n\n\t\t\tif (gaps.length > 0 && (!promptText || !promptText.includes('[GAP:'))) {\n\t\t\t\t// Build promptText from the interaction body when gaps are authored outside the prompt.\n\t\t\t\tpromptText = promptTextFromInteractionBody(interactionHtml);\n\t\t\t}\n\t\t}\n\n\t\t// Extract attributes\n\t\tconst shuffle = utils.getBooleanAttribute(element, 'shuffle');\n\t\tconst interactionClasses = utils.getClasses(element);\n\t\tconst choicesContainerWidth = utils.getAttribute(element, 'data-choices-container-width', '') || null;\n\t\tconst maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;\n\t\tconst minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;\n\n\t\treturn {\n\t\t\tgapTexts: maybeShuffle(gapTexts, shuffle, context.shuffleRng),\n\t\t\tgaps,\n\t\t\tshuffle,\n\t\t\tprompt,\n\t\t\tpromptText,\n\t\t\t...(interactionClasses.length > 0 ? { interactionClasses } : {}),\n\t\t\t...(choicesContainerWidth ? { choicesContainerWidth } : {}),\n\t\t\t...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),\n\t\t\t...(minSelectionsMessage ? { minSelectionsMessage } : {}),\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\n\t\t// Validate gapTexts exist\n\t\tif (!data.gapTexts || data.gapTexts.length === 0) {\n\t\t\terrors.push('gapMatchInteraction must have at least one gapText');\n\t\t}\n\n\t\t// Validate gaps exist\n\t\tif (!data.gaps || data.gaps.length === 0) {\n\t\t\terrors.push('gapMatchInteraction must have at least one gap in the prompt');\n\t\t}\n\n\t\t// Validate gapText identifiers\n\t\tif (data.gapTexts) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const gapText of data.gapTexts) {\n\t\t\t\tif (!gapText.identifier) {\n\t\t\t\t\terrors.push('All gapTexts must have an identifier');\n\t\t\t\t} else if (identifiers.has(gapText.identifier)) {\n\t\t\t\t\terrors.push(`Duplicate gapText identifier: ${gapText.identifier}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(gapText.identifier);\n\t\t\t\t}\n\n\t\t\t\t// Validate matchMax\n\t\t\t\tif (gapText.matchMax < 0) {\n\t\t\t\t\terrors.push(`matchMax must be non-negative for gapText ${gapText.identifier}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate gap identifiers\n\t\tif (data.gaps) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const gap of data.gaps) {\n\t\t\t\tif (!gap) {\n\t\t\t\t\terrors.push('All gaps must have an identifier');\n\t\t\t\t} else if (identifiers.has(gap)) {\n\t\t\t\t\terrors.push(`Duplicate gap identifier: ${gap}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(gap);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t};\n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EAAE,MAAM,CAAC,MAAM,KAAK,CAAC;YAC1B,MAAM,EAAE,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;SAC9C,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI gapMatchInteraction extractor\n *\n * Extracts data from gapMatchInteraction elements (drag words into gaps)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { maybeShuffle } from '../../core/shuffle.js';\nimport { normalizeCssPixelLength } from '../../security/styleValues.js';\n\nconst GAP_ELEMENT_PATTERN = /<(?:qti-gap|gap)(?=[\\s/>])([^>]*)\\/?>/gi;\nconst GAP_CLOSE_PATTERN = /<\\/(?:qti-gap|gap)>/gi;\nconst GAP_TEXT_PATTERN = /<(?:qti-gap-text|gapText)\\b[\\s\\S]*?<\\/(?:qti-gap-text|gapText)>/gi;\nconst GAP_MATCH_OPEN_PATTERN = /<(?:qti-gap-match-interaction|gapMatchInteraction)\\b[^>]*>/i;\nconst GAP_MATCH_CLOSE_PATTERN = /<\\/(?:qti-gap-match-interaction|gapMatchInteraction)>/i;\nconst PROMPT_PATTERN = /<(?:qti-prompt|prompt)\\b[\\s\\S]*?<\\/(?:qti-prompt|prompt)>/gi;\n\nfunction extractAttribute(attrs: string, name: string): string {\n\tconst match = new RegExp(`\\\\b${name}\\\\s*=\\\\s*(?:\"([^\"]*)\"|'([^']*)')`, 'i').exec(attrs);\n\treturn (match?.[1] ?? match?.[2] ?? '').trim();\n}\n\nfunction promptTextFromInteractionBody(interactionHtml: string): string {\n\treturn interactionHtml\n\t\t.replace(GAP_MATCH_OPEN_PATTERN, '')\n\t\t.replace(GAP_MATCH_CLOSE_PATTERN, '')\n\t\t.replace(PROMPT_PATTERN, '')\n\t\t.replace(GAP_TEXT_PATTERN, '')\n\t\t.replace(GAP_ELEMENT_PATTERN, (_match, attrs: string) => {\n\t\t\tconst id = extractAttribute(attrs, 'identifier');\n\t\t\treturn id ? `[GAP:${id}]` : '';\n\t\t})\n\t\t.replace(GAP_CLOSE_PATTERN, '')\n\t\t.trim();\n}\n\n/**\n * Gap match data extracted from gapMatchInteraction elements\n */\nexport interface GapMatchData {\n\tgapTexts: Array<{\n\t\tidentifier: string;\n\t\ttext: string;\n\t\tmatchMax: number;\n\t\tmatchMin?: number;\n\t\tmatchGroup?: string[];\n\t\tclasses?: string[];\n\t}>;\n\tgaps: string[];\n\tshuffle: boolean;\n\tprompt: string | null;\n\tpromptText: string;\n}\n\n/**\n * Standard QTI gap match interaction extractor\n * Handles gapMatchInteraction elements (drag words into gaps in text)\n */\nexport const standardGapMatchExtractor: ElementExtractor<GapMatchData> = {\n\tid: 'qti:gap-match-interaction',\n\tname: 'QTI Standard Gap Match Interaction',\n\tpriority: 10,\n\telementTypes: ['gapMatchInteraction'],\n\tdescription: 'Extracts standard QTI gapMatchInteraction (drag words into gaps)',\n\n\tcanHandle(element, context) {\n\t\t// All gapMatchInteraction elements are standard\n\t\treturn context.utils.matchesTag(element, 'gapMatchInteraction');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract gapText children (draggable items)\n\t\tconst gapTextElements = utils.getChildrenByTag(element, 'gapText');\n\t\tconst gapTexts = gapTextElements.map((gapText) => {\n\t\t\tconst classes = utils.getClasses(gapText);\n\t\t\tconst matchMax = utils.getNumberAttribute(gapText, 'matchMax', 1);\n\t\t\tconst matchMin = utils.getNumberAttribute(gapText, 'matchMin', 0);\n\t\t\tconst matchGroupRaw = utils.getAttribute(gapText, 'matchGroup', '');\n\t\t\tconst matchGroup = matchGroupRaw.split(/\\s+/).filter(Boolean);\n\n\t\t\treturn {\n\t\t\t\tidentifier: utils.getAttribute(gapText, 'identifier', ''),\n\t\t\t\ttext: utils.getTextContent(gapText),\n\t\t\t\tmatchMax,\n\t\t\t\t...(matchMin > 0 ? { matchMin } : {}),\n\t\t\t\t...(matchGroup.length > 0 ? { matchGroup } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract prompt (optional) and process gap placeholders.\n\t\t// NOTE: Many QTI items place `<gap>` elements in the interaction content (e.g. a `<p>`/`<blockquote>`)\n\t\t// rather than inside a `<prompt>` element. Support both patterns.\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tlet prompt: string | null = null;\n\t\tlet promptText = '';\n\t\tconst gaps: string[] = [];\n\n\t\tif (promptElements.length > 0) {\n\t\t\tconst promptElement = promptElements[0];\n\t\t\tprompt = utils.getHtmlContent(promptElement);\n\n\t\t\t// Extract gap elements from prompt children\n\t\t\tconst gapElements = utils.getChildrenByTag(promptElement, 'gap');\n\t\t\tfor (const gap of gapElements) {\n\t\t\t\tgaps.push(utils.getAttribute(gap, 'identifier', ''));\n\t\t\t}\n\n\t\t\t// Replace gap elements with placeholders in the text\n\t\t\t// Derive renderable content only from the already-sanitized prompt. Using\n\t\t\t// outerHTML here would reintroduce event handlers and unsafe URLs that\n\t\t\t// getHtmlContent deliberately removed.\n\t\t\tpromptText = prompt\n\t\t\t\t.replace(GAP_ELEMENT_PATTERN, (_match, attrs: string) => {\n\t\t\t\t\tconst id = extractAttribute(attrs, 'identifier');\n\t\t\t\t\treturn id ? `[GAP:${id}]` : '';\n\t\t\t\t})\n\t\t\t\t.replace(GAP_CLOSE_PATTERN, '')\n\t\t\t\t.trim();\n\t\t}\n\n\t\t// If gaps were not found inside a <prompt>, search the full interaction body.\n\t\t// This handles items where <gap> elements appear in <p>/<blockquote> siblings of <prompt>.\n\t\tif (gaps.length === 0) {\n\t\t\t// Keep the fallback on the same sanitization boundary as prompt content.\n\t\t\tconst interactionHtml = utils.getHtmlContent(element);\n\t\t\tconst gapIdMatches = Array.from(interactionHtml.matchAll(GAP_ELEMENT_PATTERN));\n\t\t\tfor (const m of gapIdMatches) {\n\t\t\t\tconst id = extractAttribute(m[1] ?? '', 'identifier');\n\t\t\t\tif (id) gaps.push(id);\n\t\t\t}\n\n\t\t\tif (gaps.length > 0 && (!promptText || !promptText.includes('[GAP:'))) {\n\t\t\t\t// Build promptText from the interaction body when gaps are authored outside the prompt.\n\t\t\t\tpromptText = promptTextFromInteractionBody(interactionHtml);\n\t\t\t}\n\t\t}\n\n\t\t// Extract attributes\n\t\tconst shuffle = utils.getBooleanAttribute(element, 'shuffle');\n\t\tconst interactionClasses = utils.getClasses(element);\n\t\tconst choicesContainerWidth = normalizeCssPixelLength(\n\t\t\tutils.getAttribute(element, 'data-choices-container-width', ''),\n\t\t);\n\t\tconst maxSelectionsMessage = utils.getAttribute(element, 'data-max-selections-message', '') || null;\n\t\tconst minSelectionsMessage = utils.getAttribute(element, 'data-min-selections-message', '') || null;\n\n\t\treturn {\n\t\t\tgapTexts: maybeShuffle(gapTexts, shuffle, context.shuffleRng),\n\t\t\tgaps,\n\t\t\tshuffle,\n\t\t\tprompt,\n\t\t\tpromptText,\n\t\t\t...(interactionClasses.length > 0 ? { interactionClasses } : {}),\n\t\t\t...(choicesContainerWidth ? { choicesContainerWidth } : {}),\n\t\t\t...(maxSelectionsMessage ? { maxSelectionsMessage } : {}),\n\t\t\t...(minSelectionsMessage ? { minSelectionsMessage } : {}),\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\n\t\t// Validate gapTexts exist\n\t\tif (!data.gapTexts || data.gapTexts.length === 0) {\n\t\t\terrors.push('gapMatchInteraction must have at least one gapText');\n\t\t}\n\n\t\t// Validate gaps exist\n\t\tif (!data.gaps || data.gaps.length === 0) {\n\t\t\terrors.push('gapMatchInteraction must have at least one gap in the prompt');\n\t\t}\n\n\t\t// Validate gapText identifiers\n\t\tif (data.gapTexts) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const gapText of data.gapTexts) {\n\t\t\t\tif (!gapText.identifier) {\n\t\t\t\t\terrors.push('All gapTexts must have an identifier');\n\t\t\t\t} else if (identifiers.has(gapText.identifier)) {\n\t\t\t\t\terrors.push(`Duplicate gapText identifier: ${gapText.identifier}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(gapText.identifier);\n\t\t\t\t}\n\n\t\t\t\t// Validate matchMax\n\t\t\t\tif (gapText.matchMax < 0) {\n\t\t\t\t\terrors.push(`matchMax must be non-negative for gapText ${gapText.identifier}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate gap identifiers\n\t\tif (data.gaps) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const gap of data.gaps) {\n\t\t\t\tif (!gap) {\n\t\t\t\t\terrors.push('All gaps must have an identifier');\n\t\t\t\t} else if (identifiers.has(gap)) {\n\t\t\t\t\terrors.push(`Duplicate gap identifier: ${gap}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(gap);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t};\n\t},\n};\n"]}
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Extracts data from graphicAssociateInteraction elements (associate items on image)
|
|
5
5
|
*/
|
|
6
|
+
import { normalizePixelDimension } from '../../security/styleValues.js';
|
|
6
7
|
/**
|
|
7
8
|
* Standard QTI graphic associate interaction extractor
|
|
8
9
|
* Handles graphicAssociateInteraction elements (creating associations between hotspots)
|
|
@@ -13,9 +14,9 @@ export const standardGraphicAssociateExtractor = {
|
|
|
13
14
|
priority: 10,
|
|
14
15
|
elementTypes: ['graphicAssociateInteraction'],
|
|
15
16
|
description: 'Extracts standard QTI graphicAssociateInteraction (associate items on image)',
|
|
16
|
-
canHandle(element,
|
|
17
|
+
canHandle(element, context) {
|
|
17
18
|
// All graphicAssociateInteraction elements are standard
|
|
18
|
-
return element
|
|
19
|
+
return context.utils.matchesTag(element, 'graphicAssociateInteraction');
|
|
19
20
|
},
|
|
20
21
|
extract(element, context) {
|
|
21
22
|
const { utils } = context;
|
|
@@ -26,8 +27,8 @@ export const standardGraphicAssociateExtractor = {
|
|
|
26
27
|
const objectElement = objectElements[0];
|
|
27
28
|
const type = utils.getAttribute(objectElement, 'type', '');
|
|
28
29
|
const data = utils.getAttribute(objectElement, 'data', '');
|
|
29
|
-
const width = utils.getAttribute(objectElement, 'width', '500');
|
|
30
|
-
const height = utils.getAttribute(objectElement, 'height', '300');
|
|
30
|
+
const width = normalizePixelDimension(utils.getAttribute(objectElement, 'width', ''), '500');
|
|
31
|
+
const height = normalizePixelDimension(utils.getAttribute(objectElement, 'height', ''), '300');
|
|
31
32
|
if (type.startsWith('image/svg')) {
|
|
32
33
|
// Extract inline SVG content - get full content including <svg> tag
|
|
33
34
|
const content = utils.getHtmlContent(objectElement);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/graphic-associate/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAmCH;;;GAGG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAA2C;IACxF,EAAE,EAAE,mCAAmC;IACvC,IAAI,EAAE,4CAA4C;IAClD,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,CAAC,6BAA6B,CAAC;IAC7C,WAAW,EAAE,8EAA8E;IAE3F,SAAS,CAAC,OAAO,EAAE,QAAQ;QAC1B,wDAAwD;QACxD,OAAO,OAAO,CAAC,UAAU,KAAK,6BAA6B,CAAC;IAC7D,CAAC;IAED,OAAO,CAAC,OAAO,EAAE,OAAO;QACvB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAE1B,yCAAyC;QACzC,MAAM,cAAc,GAAG,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACjE,IAAI,SAAS,GAAqB,IAAI,CAAC;QAEvC,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,MAAM,aAAa,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;YACx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AC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI graphicAssociateInteraction extractor\n *\n * Extracts data from graphicAssociateInteraction elements (associate items on image)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\n\n/**\n * Image data for graphic associate interaction\n */\nexport interface ImageData {\n\ttype: 'image' | 'svg';\n\tsrc?: string;\n\tcontent?: string;\n\twidth?: string;\n\theight?: string;\n}\n\n/**\n * Graphic associate data extracted from graphicAssociateInteraction elements\n */\nexport interface GraphicAssociateData {\n\timageData: ImageData | null;\n\tassociableHotspots: Array<{\n\t\tidentifier: string;\n\t\tlabel: string;\n\t\tshape: string;\n\t\tcoords: string;\n\t\tmatchMax: number;\n\t\tmatchMin?: number;\n\t\tmatchGroup?: string[];\n\t\tclasses?: string[];\n\t}>;\n\tmaxAssociations: number;\n\tminAssociations: number;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI graphic associate interaction extractor\n * Handles graphicAssociateInteraction elements (creating associations between hotspots)\n */\nexport const standardGraphicAssociateExtractor: ElementExtractor<GraphicAssociateData> = {\n\tid: 'qti:graphic-associate-interaction',\n\tname: 'QTI Standard Graphic Associate Interaction',\n\tpriority: 10,\n\telementTypes: ['graphicAssociateInteraction'],\n\tdescription: 'Extracts standard QTI graphicAssociateInteraction (associate items on image)',\n\n\tcanHandle(element, _context) {\n\t\t// All graphicAssociateInteraction elements are standard\n\t\treturn element.rawTagName === 'graphicAssociateInteraction';\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract image data from object element\n\t\tconst objectElements = utils.getChildrenByTag(element, 'object');\n\t\tlet imageData: ImageData | null = null;\n\n\t\tif (objectElements.length > 0) {\n\t\t\tconst objectElement = objectElements[0];\n\t\t\tconst type = utils.getAttribute(objectElement, 'type', '');\n\t\t\tconst data = utils.getAttribute(objectElement, 'data', '');\n\t\t\tconst width = utils.getAttribute(objectElement, 'width', '500');\n\t\t\tconst height = utils.getAttribute(objectElement, 'height', '300');\n\n\t\t\tif (type.startsWith('image/svg')) {\n\t\t\t\t// Extract inline SVG content - get full content including <svg> tag\n\t\t\t\tconst content = utils.getHtmlContent(objectElement);\n\t\t\t\timageData = {\n\t\t\t\t\ttype: 'svg',\n\t\t\t\t\tcontent,\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// External image reference\n\t\t\t\timageData = {\n\t\t\t\t\ttype: 'image',\n\t\t\t\t\tsrc: data,\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// Extract associableHotspot children\n\t\tconst hotspotElements = utils.getChildrenByTag(element, 'associableHotspot');\n\t\tconst associableHotspots = hotspotElements.map((hotspot) => {\n\t\t\tconst classes = utils.getClasses(hotspot);\n\t\t\tconst identifier = utils.getAttribute(hotspot, 'identifier', '');\n\t\t\tconst shape = utils.getAttribute(hotspot, 'shape', 'rect');\n\t\t\tconst coords = utils.getAttribute(hotspot, 'coords', '0,0,50,50');\n\t\t\tconst matchMax = utils.getNumberAttribute(hotspot, 'matchMax', 1);\n\t\t\tconst matchMin = utils.getNumberAttribute(hotspot, 'matchMin', 0);\n\t\t\tconst matchGroupRaw = utils.getAttribute(hotspot, 'matchGroup', '');\n\t\t\tconst matchGroup = matchGroupRaw.split(/\\s+/).filter(Boolean);\n\n\t\t\t// Get text content as label, use identifier as fallback\n\t\t\tconst textContent = utils.getTextContent(hotspot).trim();\n\t\t\tconst label = textContent || identifier;\n\n\t\t\treturn {\n\t\t\t\tidentifier,\n\t\t\t\tlabel,\n\t\t\t\tshape,\n\t\t\t\tcoords,\n\t\t\t\tmatchMax,\n\t\t\t\t...(matchMin > 0 ? { matchMin } : {}),\n\t\t\t\t...(matchGroup.length > 0 ? { matchGroup } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract attributes with proper defaults\n\t\tconst maxAssociations = utils.getNumberAttribute(element, 'maxAssociations', 1);\n\t\tconst minAssociations = utils.getNumberAttribute(element, 'minAssociations', 0);\n\n\t\t// Extract prompt (optional)\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tconst prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;\n\n\t\treturn {\n\t\t\timageData,\n\t\t\tassociableHotspots,\n\t\t\tmaxAssociations,\n\t\t\tminAssociations,\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\t// Validate image data\n\t\tif (!data.imageData) {\n\t\t\twarnings.push('graphicAssociateInteraction has no image data');\n\t\t} else if (data.imageData.type === 'image' && !data.imageData.src) {\n\t\t\terrors.push('graphicAssociateInteraction must have an image URL');\n\t\t} else if (data.imageData.type === 'svg' && !data.imageData.content) {\n\t\t\terrors.push('graphicAssociateInteraction must have SVG content');\n\t\t}\n\n\t\t// Validate hotspots exist\n\t\tif (!data.associableHotspots || data.associableHotspots.length < 2) {\n\t\t\terrors.push('graphicAssociateInteraction must have at least 2 hotspots');\n\t\t}\n\n\t\t// Validate hotspot identifiers and coords\n\t\tif (data.associableHotspots && data.associableHotspots.length > 0) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const hotspot of data.associableHotspots) {\n\t\t\t\tif (!hotspot.identifier) {\n\t\t\t\t\terrors.push('All hotspots must have an identifier');\n\t\t\t\t} else if (identifiers.has(hotspot.identifier)) {\n\t\t\t\t\terrors.push(`Duplicate hotspot identifier: ${hotspot.identifier}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(hotspot.identifier);\n\t\t\t\t}\n\n\t\t\t\tif (!hotspot.coords) {\n\t\t\t\t\terrors.push(`Hotspot ${hotspot.identifier} must have coords`);\n\t\t\t\t}\n\n\t\t\t\t// Validate matchMax\n\t\t\t\tif (hotspot.matchMax < 0) {\n\t\t\t\t\terrors.push(`matchMax must be non-negative for hotspot ${hotspot.identifier}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate maxAssociations\n\t\tif (data.maxAssociations < 0) {\n\t\t\terrors.push('maxAssociations must be non-negative');\n\t\t}\n\n\t\t// Validate minAssociations\n\t\tif (data.minAssociations < 0) {\n\t\t\terrors.push('minAssociations must be non-negative');\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
|
|
1
|
+
{"version":3,"file":"extractor.js","sourceRoot":"","sources":["../../../src/interactions/graphic-associate/extractor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AAiCxE;;;GAGG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAA2C;IACxF,EAAE,EAAE,mCAAmC;IACvC,IAAI,EAAE,4CAA4C;IAClD,QAAQ,EAAE,EAAE;IACZ,YAAY,EAAE,CAAC,6BAA6B,CAAC;IAC7C,WAAW,EAAE,8EAA8E;IAE3F,SAAS,CAAC,OAAO,EAAE,OAAO;QACzB,wDAAwD;QACxD,OAAO,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,EAAE,6BAA6B,CAAC,CAAC;IACzE,CAAC;IAED,OAAO,CAAC,OAAO,EAAE,OAAO;QACvB,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;QAE1B,yCAAyC;QACzC,MAAM,cAAc,GAAG,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;QACjE,IAAI,SAAS,GAAqB,IAAI,CAAC;QAEvC,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC/B,MAAM,aAAa,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC;YACx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AS;YAC9C,QAAQ,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS;SACpD,CAAC;IACH,CAAC;CACD,CAAC","sourcesContent":["/**\n * Standard QTI graphicAssociateInteraction extractor\n *\n * Extracts data from graphicAssociateInteraction elements (associate items on image)\n */\n\nimport type { ElementExtractor } from '../../extraction/types.js';\nimport { normalizePixelDimension } from '../../security/styleValues.js';\n\n/**\n * Image data for graphic associate interaction\n */\nexport interface ImageData {\n\ttype: 'image' | 'svg';\n\tsrc?: string;\n\tcontent?: string;\n\twidth?: string;\n\theight?: string;\n}\n\n/**\n * Graphic associate data extracted from graphicAssociateInteraction elements\n */\nexport interface GraphicAssociateData {\n\timageData: ImageData | null;\n\tassociableHotspots: Array<{\n\t\tidentifier: string;\n\t\tlabel: string;\n\t\tshape: string;\n\t\tcoords: string;\n\t\tmatchMax: number;\n\t\tmatchMin?: number;\n\t\tmatchGroup?: string[];\n\t\tclasses?: string[];\n\t}>;\n\tmaxAssociations: number;\n\tminAssociations: number;\n\tprompt: string | null;\n}\n\n/**\n * Standard QTI graphic associate interaction extractor\n * Handles graphicAssociateInteraction elements (creating associations between hotspots)\n */\nexport const standardGraphicAssociateExtractor: ElementExtractor<GraphicAssociateData> = {\n\tid: 'qti:graphic-associate-interaction',\n\tname: 'QTI Standard Graphic Associate Interaction',\n\tpriority: 10,\n\telementTypes: ['graphicAssociateInteraction'],\n\tdescription: 'Extracts standard QTI graphicAssociateInteraction (associate items on image)',\n\n\tcanHandle(element, context) {\n\t\t// All graphicAssociateInteraction elements are standard\n\t\treturn context.utils.matchesTag(element, 'graphicAssociateInteraction');\n\t},\n\n\textract(element, context) {\n\t\tconst { utils } = context;\n\n\t\t// Extract image data from object element\n\t\tconst objectElements = utils.getChildrenByTag(element, 'object');\n\t\tlet imageData: ImageData | null = null;\n\n\t\tif (objectElements.length > 0) {\n\t\t\tconst objectElement = objectElements[0];\n\t\t\tconst type = utils.getAttribute(objectElement, 'type', '');\n\t\t\tconst data = utils.getAttribute(objectElement, 'data', '');\n\t\t\tconst width = normalizePixelDimension(\n\t\t\t\tutils.getAttribute(objectElement, 'width', ''),\n\t\t\t\t'500',\n\t\t\t);\n\t\t\tconst height = normalizePixelDimension(\n\t\t\t\tutils.getAttribute(objectElement, 'height', ''),\n\t\t\t\t'300',\n\t\t\t);\n\n\t\t\tif (type.startsWith('image/svg')) {\n\t\t\t\t// Extract inline SVG content - get full content including <svg> tag\n\t\t\t\tconst content = utils.getHtmlContent(objectElement);\n\t\t\t\timageData = {\n\t\t\t\t\ttype: 'svg',\n\t\t\t\t\tcontent,\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t};\n\t\t\t} else {\n\t\t\t\t// External image reference\n\t\t\t\timageData = {\n\t\t\t\t\ttype: 'image',\n\t\t\t\t\tsrc: data,\n\t\t\t\t\twidth,\n\t\t\t\t\theight,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\t// Extract associableHotspot children\n\t\tconst hotspotElements = utils.getChildrenByTag(element, 'associableHotspot');\n\t\tconst associableHotspots = hotspotElements.map((hotspot) => {\n\t\t\tconst classes = utils.getClasses(hotspot);\n\t\t\tconst identifier = utils.getAttribute(hotspot, 'identifier', '');\n\t\t\tconst shape = utils.getAttribute(hotspot, 'shape', 'rect');\n\t\t\tconst coords = utils.getAttribute(hotspot, 'coords', '0,0,50,50');\n\t\t\tconst matchMax = utils.getNumberAttribute(hotspot, 'matchMax', 1);\n\t\t\tconst matchMin = utils.getNumberAttribute(hotspot, 'matchMin', 0);\n\t\t\tconst matchGroupRaw = utils.getAttribute(hotspot, 'matchGroup', '');\n\t\t\tconst matchGroup = matchGroupRaw.split(/\\s+/).filter(Boolean);\n\n\t\t\t// Get text content as label, use identifier as fallback\n\t\t\tconst textContent = utils.getTextContent(hotspot).trim();\n\t\t\tconst label = textContent || identifier;\n\n\t\t\treturn {\n\t\t\t\tidentifier,\n\t\t\t\tlabel,\n\t\t\t\tshape,\n\t\t\t\tcoords,\n\t\t\t\tmatchMax,\n\t\t\t\t...(matchMin > 0 ? { matchMin } : {}),\n\t\t\t\t...(matchGroup.length > 0 ? { matchGroup } : {}),\n\t\t\t\t...(classes.length > 0 ? { classes } : {}),\n\t\t\t};\n\t\t});\n\n\t\t// Extract attributes with proper defaults\n\t\tconst maxAssociations = utils.getNumberAttribute(element, 'maxAssociations', 1);\n\t\tconst minAssociations = utils.getNumberAttribute(element, 'minAssociations', 0);\n\n\t\t// Extract prompt (optional)\n\t\tconst promptElements = utils.getChildrenByTag(element, 'prompt');\n\t\tconst prompt = promptElements.length > 0 ? utils.getHtmlContent(promptElements[0]) : null;\n\n\t\treturn {\n\t\t\timageData,\n\t\t\tassociableHotspots,\n\t\t\tmaxAssociations,\n\t\t\tminAssociations,\n\t\t\tprompt,\n\t\t};\n\t},\n\n\tvalidate(data) {\n\t\tconst errors: string[] = [];\n\t\tconst warnings: string[] = [];\n\n\t\t// Validate image data\n\t\tif (!data.imageData) {\n\t\t\twarnings.push('graphicAssociateInteraction has no image data');\n\t\t} else if (data.imageData.type === 'image' && !data.imageData.src) {\n\t\t\terrors.push('graphicAssociateInteraction must have an image URL');\n\t\t} else if (data.imageData.type === 'svg' && !data.imageData.content) {\n\t\t\terrors.push('graphicAssociateInteraction must have SVG content');\n\t\t}\n\n\t\t// Validate hotspots exist\n\t\tif (!data.associableHotspots || data.associableHotspots.length < 2) {\n\t\t\terrors.push('graphicAssociateInteraction must have at least 2 hotspots');\n\t\t}\n\n\t\t// Validate hotspot identifiers and coords\n\t\tif (data.associableHotspots && data.associableHotspots.length > 0) {\n\t\t\tconst identifiers = new Set<string>();\n\t\t\tfor (const hotspot of data.associableHotspots) {\n\t\t\t\tif (!hotspot.identifier) {\n\t\t\t\t\terrors.push('All hotspots must have an identifier');\n\t\t\t\t} else if (identifiers.has(hotspot.identifier)) {\n\t\t\t\t\terrors.push(`Duplicate hotspot identifier: ${hotspot.identifier}`);\n\t\t\t\t} else {\n\t\t\t\t\tidentifiers.add(hotspot.identifier);\n\t\t\t\t}\n\n\t\t\t\tif (!hotspot.coords) {\n\t\t\t\t\terrors.push(`Hotspot ${hotspot.identifier} must have coords`);\n\t\t\t\t}\n\n\t\t\t\t// Validate matchMax\n\t\t\t\tif (hotspot.matchMax < 0) {\n\t\t\t\t\terrors.push(`matchMax must be non-negative for hotspot ${hotspot.identifier}`);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// Validate maxAssociations\n\t\tif (data.maxAssociations < 0) {\n\t\t\terrors.push('maxAssociations must be non-negative');\n\t\t}\n\n\t\t// Validate minAssociations\n\t\tif (data.minAssociations < 0) {\n\t\t\terrors.push('minAssociations must be non-negative');\n\t\t}\n\n\t\treturn {\n\t\t\tvalid: errors.length === 0,\n\t\t\terrors: errors.length > 0 ? errors : undefined,\n\t\t\twarnings: warnings.length > 0 ? warnings : undefined,\n\t\t};\n\t},\n};\n"]}
|