qti3-item-player-vue3 0.2.8 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
@@ -164,7 +164,7 @@ ${El(this.code(t,i))}
|
|
164
164
|
</svg>`,e.redo=`<svg viewbox="0 0 18 18">
|
165
165
|
<polygon class="ql-fill ql-stroke" points="12 10 14 12 16 10 12 10"></polygon>
|
166
166
|
<path class="ql-stroke" d="M9.91,13.91A4.6,4.6,0,0,1,9,14a5,5,0,1,1,5-5"></path>
|
167
|
-
</svg>`;const t={theme:"snow",boundary:"div.qti-extended-text-interaction",modules:{toolbar:{container:[["undo","redo"],["bold","italic","underline"],["blockquote"],[{list:"ordered"},{list:"bullet"}]],handlers:{redo(){this.quill.history.redo()},undo(){this.quill.history.undo()}}},history:{delay:2e3,maxStack:100,userOnly:!1},keyboard:{bindings:{tab:{key:9,handler:function(){return!0}}}}},placeholder:this.placeholder,readOnly:!1};this.quill=new Y(this.$refs.editor,t),this.quill.root.setAttribute("spellcheck",!1),this.quill.on("text-change",this.textChangeHandler),this.updateCounter(this.getLength()),this.quill.enable(!0)}},setQuillEditorStyleProperties(){this.$refs.editor!=null&&this.$refs.editor.children!=null&&this.$refs.editor.children.length>0&&(this.$refs.editor.children[0].style=`width:${this.editorHeight};overflow-x:auto;`)},textChangeHandler(){let e=this.getText(),t=this.$refs.editor.children[0].innerHTML,i=this.getLength();if(this.expectedLength&&i>this.expectedLength){this.quill.deleteText(this.expectedLength,i);return}t==="<p><br></p>"&&(t=""),this.updateCounter(this.getLength()),this.$emit("input",{html:t,text:e})},updateCounter(e){if(this.showCounter){if(this.isCounterUp){this.counter=e;return}this.counter=this.computedExpectedLength-e}},getLength(){return this.quill.getLength()-1},getText(){return this.quill.getText()}},mounted(){this.initialize(),this.setQuillEditorStyleProperties(),this.$emit("editorReady",{node:this})},beforeUnmount(){this.$el&&this.quill.off("text-change",this.textChangeHandler),this.$el.remove(),this.quill=void 0}},ON={ref:"root",class:"quill-editor vertical-rl"},PN={key:0,"aria-hidden":"true",class:"ext-text-xhtml-vert-rl-counter"},BN={key:0};function DN(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",ON,[l.createElementVNode("div",{ref:"label",style:l.normalizeStyle(r.styleLabel),class:"ext-text-xhtml-vert-label qti-hidden"},null,4),l.createElementVNode("div",{ref:"editor",style:l.normalizeStyle(r.style)},null,4),r.showCounter?(l.openBlock(),l.createElementBlock("div",PN,[l.createTextVNode(l.toDisplayString(n.counter),1),r.isCounterUp?(l.openBlock(),l.createElementBlock("span",BN," / "+l.toDisplayString(i.expectedLength),1)):l.createCommentVNode("",!0)])):l.createCommentVNode("",!0)],512)}const QN={name:"ExtendedTextXhtmlVerticalRl",components:{EditorQuillVerticalRl:P(qN,[["render",DN]])},props:{responseIdentifier:{required:!0,type:String},expectedLength:{required:!1,type:String},placeholder:{required:!1,type:String,default:""},heightClass:{required:!1,type:String,default:""},counterStyle:{required:!1,type:String,default:"none"}},computed:{computedExpectedLength(){return typeof this.expectedLength<"u"?this.expectedLength:"400"},colorStyle(){return I.getItemContextPnp().getColorStyle()},editorHeight(){return this.heightClass==="qti-height-lines-15"?"25.9rem":this.heightClass==="qti-height-lines-6"?"11.5rem":"6.7rem"},labelHeight(){return this.heightClass==="qti-height-lines-15"?"29.7rem":this.heightClass==="qti-height-lines-6"?"12.3rem":"6.6rem"},maxLength(){return 1e4},disabled(){return this.isDisabled}},data(){return{response:"",content:"",state:null,editor:null,isDisabled:!1}},inheritAttrs:!1,methods:{getResponse(){return this.response},setResponse(e){if(e===null){this.response="",this.setContent("");return}this.setContent(e),this.response=e},updateResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},getContent(){return this.content},setContent(e){this.content=e},computeState(e){return{text:e}},setIsDisabled(e){this.isDisabled=e},handleInput(e){e.html&&(this.updateResponse(e.html),this.setState(this.computeState(e.text)),this.$parent.$emit("extendedTextUpdate",{response:this.getResponse()}))},handleEditorReady(e){this.node=e.node,this.$parent.$emit("extendedTextReady",{node:this})}},mounted(){}},HN={ref:"root"};function FN(e,t,i,s,n,r){const a=l.resolveComponent("EditorQuillVerticalRl");return l.openBlock(),l.createElementBlock("div",HN,[l.createVNode(a,{content:n.content,placeholder:i.placeholder,editorHeight:r.editorHeight,labelHeight:r.labelHeight,counterStyle:i.counterStyle,expectedLength:r.computedExpectedLength,disabled:r.disabled,onInput:r.handleInput,onEditorReady:r.handleEditorReady},null,8,["content","placeholder","editorHeight","labelHeight","counterStyle","expectedLength","disabled","onInput","onEditorReady"])],512)}const UN=P(QN,[["render",FN]]),jt={DEFAULT:"default-plain",DEFAULT_SBAC:"sbac-plain",DEFAULT_LRN:"lrn-plain",DEFAULT_VERTICAL_RL:"vertical-rl-plain",XHTML_DEFAULT:"default-xhtml",XHTML_SBAC:"sbac-xhtml",XHTML_VERTICAL_RL:"vertical-rl-xhtml"};function GN(e,t,i){switch(e){case jt.XHTML_DEFAULT:case jt.XHTML_SBAC:return{template:'<extended-text-xhtml-default response-identifier="'+t.responseIdentifier+'" '+_a(t)+Sa(t)+xa(t)+Ia(t)+Va(t)+Aa(t)+$a(i)+" />",components:{ExtendedTextXhtmlDefault:kN}};case jt.DEFAULT_LRN:return{template:'<extended-text-plain-lrn response-identifier="'+t.responseIdentifier+'" '+_a(t)+Sa(t)+xa(t)+Ia(t)+Va(t)+Aa(t)+$a(i)+" />",components:{ExtendedTextPlainLrn:J_}};case jt.DEFAULT_VERTICAL_RL:return{template:'<extended-text-plain-vertical-rl response-identifier="'+t.responseIdentifier+'" '+_a(t)+Sa(t)+xa(t)+Ia(t)+Va(t)+Aa(t)+$a(i)+" />",components:{ExtendedTextPlainVerticalRl:lV}};case jt.XHTML_VERTICAL_RL:return{template:'<extended-text-xhtml-vertical-rl response-identifier="'+t.responseIdentifier+'" '+_a(t)+Sa(t)+xa(t)+Ia(t)+Va(t)+Aa(t)+$a(i)+" />",components:{ExtendedTextXhtmlVerticalRl:UN}};default:return{template:'<extended-text-plain-default response-identifier="'+t.responseIdentifier+'" '+_a(t)+Sa(t)+xa(t)+Ia(t)+Va(t)+Aa(t)+$a(i)+" />",components:{ExtendedTextPlainDefault:H_}}}}function jN(e,t){const i=WN(e);if(i&&t==="plain")return jt.DEFAULT_SBAC;if(i&&t==="xhtml")return jt.XHTML_DEFAULT;if(zN(e)&&t==="plain")return jt.DEFAULT_LRN;const n=KN(e);return n&&t==="plain"?jt.DEFAULT_VERTICAL_RL:n&&t==="xhtml"?jt.XHTML_VERTICAL_RL:t==="plain"?jt.DEFAULT:t==="xhtml"?jt.XHTML_DEFAULT:jt.DEFAULT}function Sa(e){return typeof e.patternMask>"u"?"":'pattern-mask="'+e.patternMask+'" '}function xa(e){return'pattern-mask-message="'+e.patternMaskMessage+'" '}function Ia(e){return'placeholder="'+e.placeholder+'" '}function _a(e){return typeof e.expectedLength>"u"?"":'expected-length="'+e.expectedLength+'" '}function Va(e){return typeof e.heightClass>"u"?"":'height-class="'+e.heightClass+'" '}function Aa(e){return typeof e.counterStyle>"u"?"none":'counter-style="'+e.counterStyle+'" '}function $a(e){let t="";for(const[i,s]of Object.entries(e))t+=`${i}="${s}" `;return t}function WN(e){return typeof e>"u"||e===null||e.length==0?!1:kh("sbac",e)}function zN(e){return typeof e>"u"||e===null||e.length==0?!1:kh("lrn",e)}function KN(e){return typeof e>"u"||e===null||e.length==0?!1:kh("qti-writing-orientation-vertical-rl",e)}function kh(e,t){const i=t.split(" ");for(let s=0;s<i.length;s++)if(i[s]===e)return!0;return!1}const La=new G,YN=new ie,XN={name:"QtiExtendedTextInteraction",props:{responseIdentifier:{required:!0,type:String},expectedLength:{required:!1,type:String},patternMask:{required:!1,type:String},placeholderText:{required:!1,type:String},format:{required:!1,type:String,default:"plain"},dataPatternmaskMessage:{required:!1,type:String},minStrings:{required:!1,type:String,default:"0"},maxStrings:{required:!1,type:String,default:"0"}},computed:{interactionTemplate(){return GN(this.interactionSubType,this.createComponentProperties(),this.$attrs)},placeholder(){return La.validatePlaceholderText(this.placeholderText,"")},hasPatternMask(){return typeof this.patternMask<"u"},patternMaskMessage(){return La.validatePatternmaskMessage(this.dataPatternmaskMessage,"Invalid Input")}},data(){return{response:"",state:null,baseType:"string",cardinality:"single",interactionSubType:null,isValidResponse:!1,invalidResponseMessage:"Input Required",classAttribute:"",isDisabled:!1,isQtiValid:!0,hasPrompts:!1,presentationFactory:null,node:null,priorState:null}},methods:{getResponse(){return this.response.length===0?null:this.response},setResponse(e){e===null?this.response="":this.response=e,this.node.setResponse(this.response,!0)},updateResponse(e){e===null?this.response="":this.response=e},getState(){return this.state},setState(e){this.state=e,this.node.setState(this.state,!0)},updateState(e){this.state=e},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},setInteractionSubType(e){this.interactionSubType=e},getInteractionSubType(){return this.interactionSubType},disable(){this.toggleDisable(!0)},enable(){this.toggleDisable(!1)},toggleDisable(e){this.isDisabled=e,this.node.setIsDisabled(e)},getInvalidResponseMessage(){return this.invalidResponseMessage},initializeValue(){this.setResponse(null),this.setState(this.computeState()),this.setIsValid(this.computeIsValid())},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.setResponse(null),this.setState(this.computeState()),this.setIsValid(this.computeIsValid())},restoreValue(e){this.setResponse(e.value),this.setState(e.state),this.updateValidity(this.computeIsValid())},getCardinality(){return this.cardinality},computeState(){return{}},computeIsValid(){const e=this.minStrings*1;if(e===0)return!0;if(this.response===null)return!1;const t=this.response.trim();return!(t.length<1||YN.computeWordCount(t)<e)},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},detectInteractionSubType(e,t){return jN(e,t)},createComponentProperties(){return{responseIdentifier:this.responseIdentifier,expectedLength:this.presentationFactory.getExpectedLength(),placeholder:this.placeholder,patternMask:this.patternMask,patternMaskMessage:this.patternMaskMessage,heightClass:this.presentationFactory.getHeightClass(),counterStyle:this.presentationFactory.getCounterStyle()}},handleExtendedTextUpdate(e){this.updateResponse(e.response),"state"in e&&this.updateState(e.state),this.evaluateValidity()},handleExtendedTextReady(e){this.node=e.node,this.priorState===null?this.initializeValue():this.restoreValue(this.priorState)},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Extended Text Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Extended Text Interaction State Invalid. "state" property not found.');return t}},created(){try{this.responseDeclaration=La.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.setInteractionSubType(this.detectInteractionSubType(this.$.vnode.props.class,this.format)),this.presentationFactory=new X1(this.$.vnode.props.class,this.expectedLength),La.validateMaxMinStrings(this.maxStrings,this.minStrings),this.priorState=this.getPriorState(this.responseIdentifier),this.cardinality=this.getCardinality(),this.hasPrompts=this.getPrompts(this.$slots).length>0,this.appliedRegex=La.validatePattern("pattern-mask",this.patternMask)}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{I.defineInteraction({identifier:this.responseIdentifier,interactionType:"ExtendedText",interactionSubType:this.interactionSubType,node:this,resetValue:this.resetValue,isValidResponse:this.isValidResponse,invalidResponseMessage:this.getInvalidResponseMessage()}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},ZN={ref:"root",class:"qti-extended-text-interaction"},JN={ref:"prompt",class:"qti-prompt-wrapper"};function ek(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",ZN,[l.createElementVNode("div",JN,[l.renderSlot(e.$slots,"default")],512),(l.openBlock(),l.createBlock(l.resolveDynamicComponent(r.interactionTemplate),{ref:"textarea",onExtendedTextUpdate:r.handleExtendedTextUpdate,onExtendedTextReady:r.handleExtendedTextReady},null,40,["onExtendedTextUpdate","onExtendedTextReady"]))],512)}const tk=P(XN,[["render",ek]]);class ik{constructor(t){return this.constants={QTI_ORIENTATION_HORIZONTAL:"qti-orientation-horizontal",QTI_ORIENTATION_VERTICAL:"qti-orientation-vertical",QTI_INPUT_WIDTH_DEFAULT:"",QTI_INPUT_WIDTH_1:"qti-input-width-1",QTI_INPUT_WIDTH_2:"qti-input-width-2",QTI_INPUT_WIDTH_3:"qti-input-width-3",QTI_INPUT_WIDTH_4:"qti-input-width-4",QTI_INPUT_WIDTH_5:"qti-input-width-5",QTI_INPUT_WIDTH_6:"qti-input-width-6",QTI_INPUT_WIDTH_10:"qti-input-width-10",QTI_INPUT_WIDTH_15:"qti-input-width-15",QTI_INPUT_WIDTH_20:"qti-input-width-20",QTI_INPUT_WIDTH_25:"qti-input-width-25",QTI_INPUT_WIDTH_30:"qti-input-width-30",QTI_INPUT_WIDTH_35:"qti-input-width-35",QTI_INPUT_WIDTH_40:"qti-input-width-40",QTI_INPUT_WIDTH_45:"qti-input-width-45",QTI_INPUT_WIDTH_50:"qti-input-width-50",QTI_INPUT_WIDTH_72:"qti-input-width-72"},this.classList=t,this.presentation_OrientationClass=this.constants.QTI_ORIENTATION_HORIZONTAL,this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_DEFAULT,this.presentation_MaxLength=8,this.processClassAttribute(),this}processClassAttribute(){if(typeof this.classList>"u"||this.classList===null||this.classList.length==0)return;const t=this.classList.split(" ");for(let i=0;i<t.length;i++)switch(t[i]){case this.constants.QTI_ORIENTATION_VERTICAL:this.presentation_OrientationClass=this.constants.QTI_ORIENTATION_VERTICAL;break;case this.constants.QTI_ORIENTATION_HORIZONTAL:this.presentation_OrientationClass=this.constants.QTI_ORIENTATION_HORIZONTAL;break;case this.constants.QTI_INPUT_WIDTH_1:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_1,this.presentation_MaxLength=1;break;case this.constants.QTI_INPUT_WIDTH_2:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_2,this.presentation_MaxLength=2;break;case this.constants.QTI_INPUT_WIDTH_3:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_3,this.presentation_MaxLength=3;break;case this.constants.QTI_INPUT_WIDTH_4:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_4,this.presentation_MaxLength=4;break;case this.constants.QTI_INPUT_WIDTH_5:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_5,this.presentation_MaxLength=5;break;case this.constants.QTI_INPUT_WIDTH_6:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_6,this.presentation_MaxLength=6;break;case this.constants.QTI_INPUT_WIDTH_10:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_10,this.presentation_MaxLength=10;break;case this.constants.QTI_INPUT_WIDTH_15:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_15,this.presentation_MaxLength=15;break;case this.constants.QTI_INPUT_WIDTH_20:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_20,this.presentation_MaxLength=20;break;case this.constants.QTI_INPUT_WIDTH_25:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_25,this.presentation_MaxLength=25;break;case this.constants.QTI_INPUT_WIDTH_30:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_30,this.presentation_MaxLength=30;break;case this.constants.QTI_INPUT_WIDTH_35:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_35,this.presentation_MaxLength=35;break;case this.constants.QTI_INPUT_WIDTH_40:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_40,this.presentation_MaxLength=40;break;case this.constants.QTI_INPUT_WIDTH_45:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_45,this.presentation_MaxLength=45;break;case this.constants.QTI_INPUT_WIDTH_50:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_50,this.presentation_MaxLength=50;break;case this.constants.QTI_INPUT_WIDTH_72:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_72,this.presentation_MaxLength=500;break}}getOrientationClass(){return this.presentation_OrientationClass}isOrientationVertical(){return this.presentation_OrientationClass==this.constants.QTI_ORIENTATION_VERTICAL}getWidthClass(){return this.presentation_WidthClass}getVerticalMaxLength(){return this.presentation_MaxLength}}const sk=new G,nk={name:"TextEntryPlainDefault",emits:["textEntryReady","textEntryUpdate"],components:{Tooltip:sa},props:{responseIdentifier:{required:!0,type:String},expectedLength:{required:!1,type:String},placeholder:{required:!1,type:String,default:""},patternMask:{required:!1,type:String},patternMaskMessage:{required:!1,type:String,default:"Invalid Input"},spellcheck:{required:!1,type:String,default:"false"},maxlength:{required:!1,type:String,default:"500"}},computed:{computedExpectedLength(){return typeof this.expectedLength<"u"?this.expectedLength*1:400},hasPatternMask(){return typeof this.patternMask<"u"},colorStyle(){return I.getItemContextPnp().getColorStyle()},disabled(){return this.isDisabled}},data(){return{response:"",priorResponse:"",appliedRegex:null,displayMessage:!1,isDisabled:!1}},methods:{getResponse(){return this.response},setResponse(e){if(e===null){this.response="";return}this.response=e},getState(){return this.state},setState(e){this.state=e},setIsDisabled(e){if(this.isDisabled=e,e){const t=this.getResponse();this.$refs.label.innerHTML=t===null?"":t,this.$refs.label.classList.remove("qti-hidden"),this.$refs.label.setAttribute("tabIndex",0),this.$refs.input.classList.add("qti-hidden"),(t===null||t.length===0)&&(this.$refs.label.style.paddingRight="1.1rem")}else this.$refs.label.classList.add("qti-hidden"),this.$refs.label.setAttribute("tabIndex",-1),this.$refs.input.classList.remove("qti-hidden")},handleInput(e){e.preventDefault();let t=!0;this.appliedRegex!==null?t=this.applyPatternMask(this.$refs.input.value):this.setResponse(this.$refs.input.value),t&&(this.priorResponse=this.$refs.input.value,this.$parent.$emit("textEntryUpdate",{response:this.getResponse()}))},getLength(){return this.response.length},applyPatternMask(e){return this.appliedRegex.test(e)?(this.setResponse(e),this.priorResponse=e,!0):(this.showPatternMaskMessage(),this.setResponse(this.priorResponse),!1)},showPatternMaskMessage(){this.$refs.tooltip.show(),this.hidePatternMaskMessage()},hidePatternMaskMessage(e=3e3){setTimeout(()=>{this.$refs.tooltip.hide()},e)}},created(){this.appliedRegex=sk.validatePattern("pattern-mask",this.patternMask)},mounted(){this.$parent.$emit("textEntryReady",{node:this})}},rk={ref:"root"},ak={ref:"label",class:"text-entry-default-label qti-hidden"},ok=["placeholder","disabled","spellcheck","maxlength"];function lk(e,t,i,s,n,r){const a=l.resolveComponent("tooltip");return l.openBlock(),l.createElementBlock("span",rk,[l.createElementVNode("span",ak,null,512),l.withDirectives(l.createElementVNode("input",l.mergeProps({ref:"input",class:"text-entry-default"},e.$attrs,{"onUpdate:modelValue":t[0]||(t[0]=o=>n.response=o),type:"text",placeholder:i.placeholder,disabled:r.disabled,autocapitalize:"none",spellcheck:i.spellcheck,maxlength:i.maxlength,onInput:t[1]||(t[1]=(...o)=>r.handleInput&&r.handleInput(...o))}),null,16,ok),[[l.vModelText,n.response]]),r.hasPatternMask?(l.openBlock(),l.createBlock(a,{key:0,ref:"tooltip",target:()=>e.$refs.input,message:i.patternMaskMessage,"color-style":r.colorStyle},null,8,["target","message","color-style"])):l.createCommentVNode("",!0)],512)}const cw=P(nk,[["render",lk]]),ck=new G,uk={name:"TextEntryPlainDefaultVertical",emits:["textEntryReady","textEntryUpdate"],components:{Tooltip:sa},props:{responseIdentifier:{required:!0,type:String},expectedLength:{required:!1,type:String},placeholder:{required:!1,type:String,default:""},patternMask:{required:!1,type:String},patternMaskMessage:{required:!1,type:String,default:"Invalid Input"},spellcheck:{required:!1,type:String,default:"false"},widthClass:{required:!1,type:String,default:""},maxlength:{required:!1,type:String,default:"8"}},computed:{computedExpectedLength(){return typeof this.expectedLength<"u"?this.expectedLength*1:400},hasPatternMask(){return typeof this.patternMask<"u"},colorStyle(){return I.getItemContextPnp().getColorStyle()},disabled(){return this.isDisabled}},data(){return{response:"",priorResponse:"",appliedRegex:null,displayMessage:!1,caretIndex:0,maxlengthMessage:"",isDisabled:!1}},inheritAttrs:!1,methods:{getResponse(){return this.response},setResponse(e,t=!1){e===null?this.response="":this.response=e,t&&this.updateContent(this.response)},getState(){return this.state},setState(e){this.state=e},setIsDisabled(e){if(this.isDisabled=e,e){const t=this.getResponse();this.$refs.label.innerHTML=t===null?"":t,this.$refs.label.classList.remove("qti-hidden"),this.$refs.label.setAttribute("tabIndex",0),this.$refs.input.classList.add("qti-hidden"),this.hidePlaceholder()}else this.$refs.label.classList.add("qti-hidden"),this.$refs.label.setAttribute("tabIndex",-1),this.$refs.input.classList.remove("qti-hidden"),this.getContent().length===0?this.showPlaceholder():this.hidePlaceholder()},getContent(){return this.$refs.input.innerText},updateContent(e){this.$refs.input.innerText=e,e.length>0?this.hidePlaceholder():this.showPlaceholder()},getCaretIndex(){return this.caretIndex},setCaretIndex(e){this.caretIndex=e},handleInput(e){e.preventDefault();let t=!0;this.setCaretIndex(this.getCaretPos(this.$refs.input)-1);const i=this.getContent();i.length>0&&this.hidePlaceholder(),this.applyLimitCheck(i)&&(this.appliedRegex!==null?t=this.applyPatternMask(i):this.setResponse(i),t&&(i.length==0&&this.showPlaceholder(),this.priorResponse=i,this.$parent.$emit("textEntryUpdate",{response:this.getResponse()})))},handlePaste(e){e.preventDefault();const t=this.getRange();if(t===null)return;const i=this.getContent(),s=t.startOffset,n=t.endOffset;let r=e.clipboardData.getData("text/plain"),a=i.substring(0,s)+r+i.substring(n),o=!0;if(a.length>0&&this.hidePlaceholder(),a.length>this.maxlength){this.showMaxlengthMessage(),this.setResponse(this.priorResponse,!0),this.setCaretPos(this.$refs.input,s);return}this.appliedRegex!==null?o=this.applyPatternMask(a):this.setResponse(a,!0),o&&(this.setCaretIndex(s+r.length),this.setCaretPos(this.$refs.input,this.getCaretIndex()),this.priorResponse=a,this.$parent.$emit("textEntryUpdate",{response:this.getResponse()}))},handleDrop(e){e.preventDefault()},handleKeydown(e){switch(this.setCaretIndex(this.getCaretPos(this.$refs.input)),e.code){case"Enter":e.preventDefault();return;case"KeyI":case"KeyB":case"KeyU":e.ctrlKey&&e.preventDefault();return}},newDownRange(e){const t=e.firstChild,i=this.getRange();if(i===null)return;const s=i.startOffset,n=i.endOffset;if(n===this.getResponse().length)return;const r=window.getSelection();r.removeAllRanges();const a=document.createRange();a.setStart(t,s),a.setEnd(t,n+1),r.addRange(a)},newUpRange(e){const t=e.firstChild,i=this.getRange();if(i===null)return;const s=i.startOffset,n=i.endOffset;if(s===0)return;const r=window.getSelection();r.removeAllRanges();const a=document.createRange();a.setStart(t,s-1),a.setEnd(t,n),r.addRange(a)},getRange(){const e=document.getSelection();return e.rangeCount===0?null:e.getRangeAt(0)},getCaretPos(e){let t=0;if(typeof window.getSelection<"u"&&window.getSelection().rangeCount!==0){const n=window.getSelection().getRangeAt(0),r=n.cloneRange();r.selectNodeContents(e),r.setEnd(n.endContainer,n.endOffset),t=r.toString().length}return t},setCaretPos(e,t){e.focus(),e.childNodes.length===1&&document.getSelection().collapse(e.childNodes[0],t)},showPlaceholder(){this.$refs.placeholder.classList.remove("text-entry-ph-hidden")},hidePlaceholder(){this.$refs.placeholder.classList.add("text-entry-ph-hidden")},handleBlur(){this.$refs.root.classList.remove("focused")},handleFocus(){this.$refs.root.classList.add("focused")},getLength(){return this.response.length},applyLimitCheck(e){return e.length>this.maxlength?(this.showMaxlengthMessage(),this.setResponse(this.priorResponse,!0),this.setCaretPos(this.$refs.input,this.getCaretIndex()),!1):!0},applyPatternMask(e){return this.appliedRegex.test(e)?(this.setResponse(e),this.priorResponse=e,!0):(this.showPatternMaskMessage(),this.setResponse(this.priorResponse,!0),this.setCaretPos(this.$refs.input,this.getCaretIndex()),!1)},showPatternMaskMessage(){this.$refs.tooltip.show(),this.hidePatternMaskMessage()},hidePatternMaskMessage(e=3e3){setTimeout(()=>{this.$refs.tooltip.hide()},e)},showMaxlengthMessage(){this.$refs.tooltipMaxlength.show(),this.hideMaxlengthMessage()},hideMaxlengthMessage(e=1e3){setTimeout(()=>{this.$refs.tooltipMaxlength.hide()},e)},computeMaxlengthMessage(){this.maxlengthMessage=`Maximum of ${this.maxlength} character`+(this.maxlength==="1"?"":"s")}},created(){this.appliedRegex=ck.validatePattern("pattern-mask",this.patternMask),this.computeMaxlengthMessage()},mounted(){this.$parent.$emit("textEntryReady",{node:this})}},hk=["spellcheck","maxlength","disabled"];function dk(e,t,i,s,n,r){const a=l.resolveComponent("tooltip");return l.openBlock(),l.createElementBlock("div",l.mergeProps({ref:"root",class:"text-entry-default-vert-wrapper"},e.$attrs),[l.createElementVNode("div",{ref:"label",class:"text-entry-default-vert-label qti-hidden",onFocus:t[0]||(t[0]=(...o)=>r.handleFocus&&r.handleFocus(...o)),onBlur:t[1]||(t[1]=(...o)=>r.handleBlur&&r.handleBlur(...o))},null,544),l.createElementVNode("div",{ref:"input",class:"text-entry-default-vert",tabindex:"0",contenteditable:"true",autocapitalize:"false",spellcheck:i.spellcheck,maxlength:i.maxlength,disabled:r.disabled,onInput:t[2]||(t[2]=(...o)=>r.handleInput&&r.handleInput(...o)),onBlur:t[3]||(t[3]=(...o)=>r.handleBlur&&r.handleBlur(...o)),onFocus:t[4]||(t[4]=(...o)=>r.handleFocus&&r.handleFocus(...o)),onKeydown:t[5]||(t[5]=(...o)=>r.handleKeydown&&r.handleKeydown(...o)),onPaste:t[6]||(t[6]=(...o)=>r.handlePaste&&r.handlePaste(...o)),onDrop:t[7]||(t[7]=(...o)=>r.handleDrop&&r.handleDrop(...o))},null,40,hk),l.createElementVNode("label",{ref:"placeholder",class:"text-entry-default-vert-ph","aria-hidden":"true"},l.toDisplayString(i.placeholder),513),r.hasPatternMask?(l.openBlock(),l.createBlock(a,{key:0,ref:"tooltip",target:()=>e.$refs.input,message:i.patternMaskMessage,"color-style":r.colorStyle},null,8,["target","message","color-style"])):l.createCommentVNode("",!0),l.createVNode(a,{ref:"tooltipMaxlength",target:()=>e.$refs.input,message:n.maxlengthMessage,"color-style":r.colorStyle},null,8,["target","message","color-style"])],16)}const fk=P(uk,[["render",dk]]),Ll={DEFAULT:"default-plain-horizontal",DEFAULT_VERTICAL:"default-plain-vertical"};function pk(e,t,i){switch(e){case Ll.DEFAULT:return{template:'<text-entry-plain-default response-identifier="'+t.responseIdentifier+'" '+Bh(t)+qh(t)+Oh(t)+Ph(t)+Dh(t)+Qh(t)+uw(t)+Hh(i)+" />",components:{TextEntryPlainDefault:cw}};case Ll.DEFAULT_VERTICAL:return{template:'<text-entry-plain-default-vertical response-identifier="'+t.responseIdentifier+'" '+Bh(t)+qh(t)+Oh(t)+Ph(t)+Dh(t)+Qh(t)+gk(t)+yk(t)+Hh(i)+" />",components:{TextEntryPlainDefaultVertical:fk}};default:return{template:'<text-entry-plain-default response-identifier="'+t.responseIdentifier+'" '+Bh(t)+qh(t)+Oh(t)+Ph(t)+Dh(t)+Qh(t)+uw(t)+Hh(i)+" />",components:{TextEntryPlainDefault:cw}}}}function mk(e){return wk(e)?Ll.DEFAULT_VERTICAL:Ll.DEFAULT}function qh(e){return typeof e.patternMask>"u"?"":'pattern-mask="'+e.patternMask+'" '}function Oh(e){return'pattern-mask-message="'+e.patternMaskMessage+'" '}function Ph(e){return'placeholder="'+e.placeholder+'" '}function Bh(e){return typeof e.expectedLength>"u"?"":'expected-length="'+e.expectedLength+'" '}function Dh(e){return typeof e.format>"u"||e.format.length==0?"":'format="'+e.format+'" '}function Qh(e){return typeof e.spellcheck>"u"?"":'spellcheck="'+e.spellcheck+'" '}function uw(e){return typeof e.maxlength>"u"?"":'maxlength="'+e.maxlength+'" '}function gk(e){return typeof e.widthClass>"u"?"":'width-class="'+e.widthClass+'" '}function yk(e){return typeof e.verticalMaxlength>"u"?"":'maxlength="'+e.verticalMaxlength+'" '}function Hh(e){let t="";for(const[i,s]of Object.entries(e))t+=`${i}="${s}" `;return t}function wk(e){return typeof e>"u"||e===null||e.length==0?!1:hw("qti-writing-orientation-vertical-rl",e)?!0:hw("qti-orientation-vertical",e)}function hw(e,t){const i=t.split(" ");for(let s=0;s<i.length;s++)if(i[s]===e)return!0;return!1}const Ml=new G,bk={name:"QtiTextEntryInteraction",props:{responseIdentifier:{required:!0,type:String},expectedLength:{required:!1,type:String},patternMask:{required:!1,type:String},placeholderText:{required:!1,type:String},format:{required:!1,type:String,default:""},dataPatternmaskMessage:{required:!1,type:String},dataMaxlength:{required:!1,type:String},dataSpellcheck:{required:!1,type:String}},computed:{interactionTemplate(){return pk(this.interactionSubType,this.createComponentProperties(),this.$attrs)},placeholder(){return Ml.validatePlaceholderText(this.placeholderText,"")},hasPatternMask(){return typeof this.patternMask<"u"},patternMaskMessage(){return Ml.validatePatternmaskMessage(this.dataPatternmaskMessage,"Invalid Input")},colorStyle(){return I.getItemContextPnp().getColorStyle()},computeMaxlength(){return typeof this.dataMaxlength<"u"?this.dataMaxlength:500},computeSpellcheck(){return typeof this.dataSpellcheck<"u"?this.dataSpellcheck:!1}},data(){return{response:"",state:null,baseType:"string",cardinality:"single",interactionSubType:null,isValidResponse:!1,invalidResponseMessage:"Input Required",classAttribute:"",isDisabled:!1,isQtiValid:!0,presentationFactory:null,node:null,priorState:null}},methods:{getResponse(){return this.response.length===0?null:this.response},setResponse(e){e===null?this.response="":this.response=e,this.node.setResponse(this.response,!0)},updateResponse(e){e===null?this.response="":this.response=e},getState(){return this.state},setState(e){this.state=e},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},setInteractionSubType(e){this.interactionSubType=e},getInteractionSubType(){return this.interactionSubType},disable(){this.toggleDisable(!0)},enable(){this.toggleDisable(!1)},toggleDisable(e){this.isDisabled=e,this.node.setIsDisabled(e)},getInvalidResponseMessage(){return this.invalidResponseMessage},initializeValue(){this.setResponse(null),this.setState(this.computeState()),this.setIsValid(!1)},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.setResponse(null),this.setState(this.computeState()),this.setIsValid(!1)},restoreValue(e){this.setResponse(e.value),this.setState(e.state),this.updateValidity(this.computeIsValid())},getCardinality(){return this.cardinality},computeState(){return{}},computeIsValid(){return!(this.response===null||this.response.length<1)},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},detectInteractionSubType(e){return mk(e)},createComponentProperties(){return{responseIdentifier:this.responseIdentifier,placeholder:this.placeholder,patternMask:this.patternMask,patternMaskMessage:this.patternMaskMessage,spellcheck:this.computeSpellcheck,maxlength:this.computeMaxlength,widthClass:this.presentationFactory.getWidthClass(),verticalMaxlength:this.presentationFactory.getVerticalMaxLength(),format:this.format}},handleTextEntryUpdate(e){this.updateResponse(e.response),this.evaluateValidity()},handleTextEntryReady(e){this.node=e.node,this.priorState===null?this.initializeValue():this.restoreValue(this.priorState)},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Text Entry Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Text Entry Interaction State Invalid. "state" property not found.');return t}},created(){try{this.responseDeclaration=Ml.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.setInteractionSubType(this.detectInteractionSubType(this.$.vnode.props.class)),this.presentationFactory=new ik(this.$.vnode.props.class),this.priorState=this.getPriorState(this.responseIdentifier),this.cardinality=this.getCardinality(),this.appliedRegex=Ml.validatePattern("pattern-mask",this.patternMask)}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.priorState===null?this.initializeValue():this.restoreValue(this.priorState),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"TextEntry",node:this,resetValue:this.resetValue,isValidResponse:this.isValidResponse,invalidResponseMessage:this.getInvalidResponseMessage()}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}};function vk(e,t,i,s,n,r){return l.openBlock(),l.createBlock(l.resolveDynamicComponent(r.interactionTemplate),{ref:"input",class:"qti-text-entry-interaction",onTextEntryUpdate:r.handleTextEntryUpdate,onTextEntryReady:r.handleTextEntryReady},null,40,["onTextEntryUpdate","onTextEntryReady"])}const Ek=P(bk,[["render",vk]]),Ck=new G,Tk={name:"QtiMatchInteraction",props:{responseIdentifier:{required:!0,type:String},minAssociations:{required:!1,type:String,default:"0"},maxAssociations:{required:!1,type:String,default:"1"},shuffle:{required:!1,type:String,default:"false"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String},dataFirstColumnHeader:{required:!1,type:String,default:null}},data(){return{response:null,state:null,isValidResponse:!1,matchsets:[],orders:[],cardinality:"single",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,hasPrompts:!1,matchInteractionStaticClass:"",interactionSubType:"default",headerHidden:"false",rowCentric:"false",isQtiValid:!0,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},setInteractionSubType(e){this.interactionSubType=e},getInteractionSubType(){return this.interactionSubType},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},getInvalidResponseMessage(){return this.minSelectionsMessage},disable(){this.$refs.matchgroup.disable()},enable(){this.$refs.matchgroup.enable()},initializeValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.setResponse(null),this.setState(null),this.priorState=null,this.$refs.matchgroup.resetGroupUI()},restoreValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality:"single",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},handleMatchGroupReady(e){this.matchsets=e.matchsets,this.orders=e.orders,this.initializeValue(e.response)},handleMatchGroupUpdate(e){this.setResponse(e.response),this.updateValidity(this.computeIsValid())},handleAssociationsLimit(){I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage)},computeState(){return this.priorState!==null?this.priorState.state:{orders:this.orders}},computeIsValid(){const e=this.getResponse(),t=this.minAssociations*1;return t===0?!0:e===null?!1:this.cardinality==="single"||e.length>=t},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxAssociations*1==0?"":"You may make a maximum of "+this.maxAssociations+" match"+(this.maxAssociations*1>1?"es":"")+" for this question."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.minAssociations*1!=0&&(this.minSelectionsMessage="You must make at least "+this.minAssociations+" match"+(this.minAssociations*1>1?"es":"")+" for this question.")},detectInteractionSubType(e){return this.getMatchInteractionSubType(e)},getMatchInteractionSubType(e){let t="default";if(typeof e>"u"||e===null||e.length==0)return t;this.matchInteractionStaticClass=e;const i=e.split(" ");for(let s=0;s<i.length;s++)switch(i[s]){case"qti-match-tabular":t="matchtabular";break;case"qti-header-hidden":this.headerHidden="true";break;case"row-centric":this.rowCentric="true";break}return t},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Match Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Match Interaction State Invalid. "state" property not found.');if(!("orders"in t.state))throw new O('Match Interaction State Invalid. "orders" property not found.');return t}},created(){try{if(this.responseDeclaration=Ck.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.setInteractionSubType(this.detectInteractionSubType(this.$.vnode.props.class)),this.priorState=this.getPriorState(this.responseIdentifier),this.cardinality=this.getCardinality(),this.cardinality!=="single"&&this.cardinality!=="multiple")throw new c('qti-match-interaction cardinality must be "single" or "multiple"');if(this.maxAssociations*1!=1&&this.cardinality!=="multiple")throw new c('qti-match-interaction response variable must have "multiple" cardinality because max-associations is '+this.maxAssociations);if(this.minAssociations*1>1&&this.cardinality==="single")throw new c('qti-match-interaction response variable must have "multiple" cardinality because min-associations is '+this.minAssociations);this.hasPrompts=this.getPrompts(this.$slots).length>0,this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"Match",interactionSubType:this.interactionSubType,node:this,resetValue:this.resetValue,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},Sk={ref:"root",class:"qti-match-interaction"},xk={ref:"prompt",class:"qti-prompt-wrapper"};function Ik(e,t,i,s,n,r){const a=l.resolveComponent("MatchGroup");return l.openBlock(),l.createElementBlock("div",Sk,[l.createElementVNode("div",xk,null,512),l.createVNode(a,l.mergeProps({ref:"matchgroup",cardinality:n.cardinality,shuffle:i.shuffle,responseIdentifier:i.responseIdentifier,maxAssociations:i.maxAssociations,minAssociations:i.minAssociations,interactionSubType:n.interactionSubType,matchInteractionStaticClass:n.matchInteractionStaticClass,headerHidden:n.headerHidden,rowCentric:n.rowCentric,dataFirstColumnHeader:i.dataFirstColumnHeader,priorState:n.priorState,onMatchGroupReady:r.handleMatchGroupReady,onMatchGroupUpdate:r.handleMatchGroupUpdate,onMatchGroupAssociationsLimit:r.handleAssociationsLimit},e.$attrs),{default:l.withCtx(()=>[l.renderSlot(e.$slots,"default")]),_:3},16,["cardinality","shuffle","responseIdentifier","maxAssociations","minAssociations","interactionSubType","matchInteractionStaticClass","headerHidden","rowCentric","dataFirstColumnHeader","priorState","onMatchGroupReady","onMatchGroupUpdate","onMatchGroupAssociationsLimit"])],512)}const _k=P(Tk,[["render",Ik]]),Vk=new G,Ak={name:"QtiGapMatchInteraction",props:{responseIdentifier:{required:!0,type:String},minAssociations:{required:!1,type:String,default:"0"},maxAssociations:{required:!1,type:String,default:"1"},shuffle:{required:!1,type:String,default:"false"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String},dataChoicesContainerWidth:{required:!1,type:String,default:null}},data(){return{response:null,state:null,isValidResponse:!1,choices:[],order:[],cardinality:"single",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,hasPrompts:!1,gapMatchInteractionStaticClass:"",interactionSubType:"default",isQtiValid:!0,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},setInteractionSubType(e){this.interactionSubType=e},getInteractionSubType(){return this.interactionSubType},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},getInvalidResponseMessage(){return this.minSelectionsMessage},disable(){this.$refs.gapmatchgroup.disable()},enable(){this.$refs.gapmatchgroup.enable()},initializeValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.setResponse(null),this.setState(null),this.priorState=null,this.$refs.matchgroup.resetGroupUI()},restoreValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality:"single",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},handleGapMatchGroupReady(e){this.choices=e.choices,this.order=e.order,this.initializeValue(e.response)},handleGapMatchGroupUpdate(e){this.setResponse(e.response),this.updateValidity(this.computeIsValid())},handleAssociationsLimit(){I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage)},computeState(){return this.priorState!==null?this.priorState.state:{order:this.order}},computeIsValid(){const e=this.getResponse(),t=this.minAssociations*1;return t===0?!0:e===null?!1:this.cardinality==="single"||e.length>=t},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxAssociations*1==0?"":"You may make a maximum of "+this.maxAssociations+" match"+(this.maxAssociations*1>1?"es":"")+" for this question."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.minAssociations*1!=0&&(this.minSelectionsMessage="You must make at least "+this.minAssociations+" match"+(this.minAssociations*1>1?"es":"")+" for this question.")},detectInteractionSubType(e){return this.computeInteractionSubType(e)},computeInteractionSubType(e){let t="default";return typeof e>"u"||e===null||e.length==0||(this.gapMatchInteractionStaticClass=e),t},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Gap Match Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Gap Match Interaction State Invalid. "state" property not found.');if(!("order"in t.state))throw new O('Gap Match Interaction State Invalid. "order" property not found.');return t}},created(){try{if(this.responseDeclaration=Vk.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.setInteractionSubType(this.detectInteractionSubType(this.$.vnode.props.class)),this.priorState=this.getPriorState(this.responseIdentifier),this.cardinality=this.getCardinality(),this.cardinality!=="single"&&this.cardinality!=="multiple")throw new c('qti-gap-match-interaction cardinality must be "single" or "multiple"');if(this.maxAssociations*1!=1&&this.cardinality!=="multiple")throw new c('qti-gap-match-interaction response variable must have "multiple" cardinality because max-associations is '+this.maxAssociations);if(this.minAssociations*1>1&&this.cardinality==="single")throw new c('qti-gap-match-interaction response variable must have "multiple" cardinality because min-associations is '+this.minAssociations);this.hasPrompts=this.getPrompts(this.$slots).length>0,this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"GapMatch",interactionSubType:this.interactionSubType,node:this,resetValue:this.resetValue,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},$k={ref:"root",class:"qti-gap-match-interaction"},Lk={ref:"prompt",class:"qti-prompt-wrapper"};function Mk(e,t,i,s,n,r){const a=l.resolveComponent("GapMatchGroup");return l.openBlock(),l.createElementBlock("div",$k,[l.createElementVNode("div",Lk,null,512),l.createVNode(a,l.mergeProps({ref:"gapmatchgroup",cardinality:n.cardinality,shuffle:i.shuffle,responseIdentifier:i.responseIdentifier,maxAssociations:i.maxAssociations,minAssociations:i.minAssociations,interactionSubType:n.interactionSubType,gapMatchInteractionStaticClass:n.gapMatchInteractionStaticClass,dataChoicesContainerWidth:i.dataChoicesContainerWidth,priorState:n.priorState,onGapMatchGroupReady:r.handleGapMatchGroupReady,onGapMatchGroupUpdate:r.handleGapMatchGroupUpdate,onGapMatchGroupAssociationsLimit:r.handleAssociationsLimit},e.$attrs),{default:l.withCtx(()=>[l.renderSlot(e.$slots,"default")]),_:3},16,["cardinality","shuffle","responseIdentifier","maxAssociations","minAssociations","interactionSubType","gapMatchInteractionStaticClass","dataChoicesContainerWidth","priorState","onGapMatchGroupReady","onGapMatchGroupUpdate","onGapMatchGroupAssociationsLimit"])],512)}const Rk=P(Ak,[["render",Mk]]),Nk=new G,kk={name:"QtiGraphicGapMatchInteraction",props:{responseIdentifier:{required:!0,type:String},minAssociations:{required:!1,type:String,default:"0"},maxAssociations:{required:!1,type:String,default:"1"},shuffle:{required:!1,type:String,default:"false"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String},dataChoicesContainerWidth:{required:!1,type:String,default:null}},data(){return{response:null,state:null,isValidResponse:!1,choices:[],order:[],cardinality:"multiple",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,hasPrompts:!1,interactionStaticClass:"",interactionSubType:"default",isQtiValid:!0,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},setInteractionSubType(e){this.interactionSubType=e},getInteractionSubType(){return this.interactionSubType},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},getInvalidResponseMessage(){return this.minSelectionsMessage},disable(){this.$refs.ggmgroup.disable()},enable(){this.$refs.ggmgroup.enable()},initializeValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.setResponse(null),this.setState(null),this.priorState=null,this.$refs.matchgroup.resetGroupUI()},restoreValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality:"single",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},handleGraphicGapMatchGroupReady(e){this.choices=e.choices,this.order=e.order,this.initializeValue(e.response)},handleGraphicGapMatchGroupUpdate(e){this.setResponse(e.response),this.updateValidity(this.computeIsValid())},handleAssociationsLimit(){I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage)},computeState(){return this.priorState!==null?this.priorState.state:{order:this.order}},computeIsValid(){const e=this.getResponse(),t=this.minAssociations*1;return t===0?!0:e===null?!1:this.cardinality==="single"||e.length>=t},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxAssociations*1==0?"":"You may make a maximum of "+this.maxAssociations+" match"+(this.maxAssociations*1>1?"es":"")+" for this question."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.minAssociations*1!=0&&(this.minSelectionsMessage="You must make at least "+this.minAssociations+" match"+(this.minAssociations*1>1?"es":"")+" for this question.")},detectInteractionSubType(e){return this.computeInteractionSubType(e)},computeInteractionSubType(e){let t="default";return typeof e>"u"||e===null||e.length==0||(this.interactionStaticClass=e),t},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Gap Match Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Gap Match Interaction State Invalid. "state" property not found.');if(!("order"in t.state))throw new O('Gap Match Interaction State Invalid. "order" property not found.');return t}},created(){try{if(this.responseDeclaration=Nk.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.setInteractionSubType(this.detectInteractionSubType(this.$.vnode.props.class)),this.priorState=this.getPriorState(this.responseIdentifier),this.cardinality=this.getCardinality(),this.cardinality!=="multiple")throw new c('qti-graphic-gap-match-interaction cardinality must be "multiple"');this.hasPrompts=this.getPrompts(this.$slots).length>0,this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"GraphicGapMatch",interactionSubType:this.interactionSubType,node:this,resetValue:this.resetValue,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},qk={ref:"root",class:"qti-graphic-gap-match-interaction"},Ok={ref:"prompt",class:"qti-prompt-wrapper"};function Pk(e,t,i,s,n,r){const a=l.resolveComponent("GraphicGapMatchGroup");return l.openBlock(),l.createElementBlock("div",qk,[l.createElementVNode("div",Ok,null,512),l.createVNode(a,l.mergeProps({ref:"ggmgroup",cardinality:n.cardinality,shuffle:i.shuffle,responseIdentifier:i.responseIdentifier,maxAssociations:i.maxAssociations,minAssociations:i.minAssociations,interactionSubType:n.interactionSubType,interactionStaticClass:n.interactionStaticClass,dataChoicesContainerWidth:i.dataChoicesContainerWidth,priorState:n.priorState,onGgmGroupReady:r.handleGraphicGapMatchGroupReady,onGgmGroupUpdate:r.handleGraphicGapMatchGroupUpdate,onGgmGroupAssociationsLimit:r.handleAssociationsLimit},e.$attrs),{default:l.withCtx(()=>[l.renderSlot(e.$slots,"default")]),_:3},16,["cardinality","shuffle","responseIdentifier","maxAssociations","minAssociations","interactionSubType","interactionStaticClass","dataChoicesContainerWidth","priorState","onGgmGroupReady","onGgmGroupUpdate","onGgmGroupAssociationsLimit"])],512)}const Bk=P(kk,[["render",Pk]]),Dk={},Qk={ref:"root",class:"qti3-player-media-group"};function Hk(e,t){return l.openBlock(),l.createElementBlock("div",Qk,[l.renderSlot(e.$slots,"default")],512)}const dw=P(Dk,[["render",Hk]]),fw=new G,Fk={name:"QtiMediaInteraction",components:[dw],props:{responseIdentifier:{required:!0,type:String},autostart:{required:!0,type:String},minPlays:{required:!1,type:String,default:"0"},maxPlays:{required:!1,type:String,default:"0"},loop:{required:!1,type:String,default:"false"},coords:{required:!1,type:String},dataMaxPlaysMessage:{required:!1,type:String},dataMinPlaysMessage:{required:!1,type:String}},data(){return{response:null,state:null,isValidResponse:!1,cardinality:"single",minPlaysMessage:"",maxPlaysMessage:"",responseDeclaration:null,mediaType:"media",isAutostart:!1,isLoop:!1,isDisabled:!1,isQtiValid:!0,hasPrompts:!1,node:null,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},incrementPlays(){let e=this.getResponse();this.setResponse(e===null?1:e+1)},getState(){return this.state},setState(e){this.state=e},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},disable(){this.node!==null&&this.node.disable()},enable(){this.node!==null&&this.node.enable()},getInvalidResponseMessage(){return this.computeMinPlaysMessage(),this.minPlaysMessage},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.priorState=null,this.setResponse(null),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},restoreValue(e){e!==null&&(this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid()),this.evaluateMaxPlays())},getCardinality(){return this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},handleMediaMounted(e){this.node=e.node,this.mediaType=e.mediaType,e.mediaType==="audio"&&this.node.setAudioSubType("audioprogress"),this.evaluateMaxPlays()},handleMediaLoaded(e){this.node=e.node,this.evaluateMaxPlays(),this.evaluateAutostart()},handleMediaEnded(){this.incrementPlays(),this.evaluateValidity(),this.evaluateMaxPlays(),this.evaluateLoop()},computeState(){return{}},computeIsValid(){const e=this.minPlays*1;if(e===0)return!0;const t=this.getResponse();return t===null?!1:t>=e},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},evaluateMaxPlays(){this.checkMaxPlaysLimit()?this.disable():this.enable()},evaluateLoop(){this.isLoop&&(this.checkMaxPlaysLimit()||this.isDisabled||this.playMedia())},evaluateAutostart(){this.isAutostart&&(this.checkMaxPlaysLimit()||this.isDisabled||(console.log(`[${this.$options.name}][Identifier=${this.responseIdentifier}][AutoStart]`),this.playMedia()))},playMedia(){if(this.node!=null){if(this.mediaType==="audio")return this.node.playAudio();this.node.playVideo()}},checkMaxPlaysLimit(){if(this.maxPlays*1===0)return!1;const e=this.getResponse();return e!==null&&e==this.maxPlays*1},computeMaxPlaysMessage(){if(typeof this.dataMaxPlaysMessage<"u"){this.maxPlaysMessage=this.dataMaxPlaysMessage;return}const e=this.maxPlays*1;this.maxPlaysMessage=e===0?"":`You are permitted a maximum of ${this.maxPlays} play${e>1?"s":""} for this ${this.mediaType}.`},computeMinPlaysMessage(){if(typeof this.dataMinPlaysMessage<"u"){this.minPlaysMessage=this.dataMinPlaysMessage;return}const e=this.minPlays*1;this.minPlaysMessage=e===0?"":`You must play this ${this.mediaType} to the end at least ${this.minPlays} time${e>1?"s":""}.`},validateChildren(){},processChildren(){this.processMedia(),this.setIsValid(this.computeIsValid()),this.priorState!==null&&this.restoreValue(this.priorState.value)},processMedia(){let e=this.$refs.mediagroup.$el.getElementsByTagName("object");if(e.length!==0)throw new c("Unsupported Media Interaction element. The <object> elemnt is deprecated. Use <video> or <audio> instead.");if(e=this.$refs.mediagroup.$el.getElementsByTagName("video"),e.length===0&&(e=this.$refs.mediagroup.$el.getElementsByTagName("audio")),e.length!==1)throw new c("Media Interaction must have exactly one <video> or <audio> node.")},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Media Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Media Interaction State Invalid. "state" property not found.');return t}},created(){try{this.responseDeclaration=fw.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.validateChildren(),this.priorState=this.getPriorState(this.responseIdentifier),fw.validateMaxMinPlays(this.maxPlays,this.minPlays),this.hasPrompts=this.getPrompts(this.$slots).length>0,this.isAutostart=this.autostart==="true",this.isLoop=this.loop==="true",this.computeMaxPlaysMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),this.processChildren(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"Media",node:this,resetValue:this.resetValue,disable:this.disable,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxPlaysMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},Uk={ref:"root",class:"qti-media-interaction"},Gk={ref:"prompt",class:"qti-prompt-wrapper"};function jk(e,t,i,s,n,r){const a=l.resolveComponent("MediaGroup");return l.openBlock(),l.createElementBlock("div",Uk,[l.createElementVNode("div",Gk,null,512),l.createVNode(a,{ref:"mediagroup",onMediaMounted:r.handleMediaMounted,onMediaLoaded:r.handleMediaLoaded,onMediaEnded:r.handleMediaEnded},{default:l.withCtx(()=>[l.renderSlot(e.$slots,"default")]),_:3},8,["onMediaMounted","onMediaLoaded","onMediaEnded"])],512)}const Wk=P(Fk,[["render",jk]]),Fh=new G,zk={name:"QtiOrderInteraction",props:{responseIdentifier:{required:!0,type:String},minChoices:{required:!1,type:String},maxChoices:{required:!1,type:String},shuffle:{required:!1,type:String,default:"false"},orientation:{required:!1,type:String,default:"horizontal"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String},dataChoicesContainerWidth:{required:!1,type:String,default:null}},data(){return{response:null,state:null,isValidResponse:!1,cardinality:"ordered",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,interactionSubType:"default",choices:[],isShuffle:!1,hasPrompts:!1,minChoicesValue:null,maxChoicesValue:null,isMinChoicesSpecified:!1,isMaxChoicesSpecified:!1,isQtiValid:!0,priorState:null,originalOrder:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},setInteractionSubType(e){this.interactionSubType=e},getInteractionSubType(){return this.interactionSubType},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},getInvalidResponseMessage(){return this.minSelectionsMessage},disable(){this.$refs.ordergroup.disable()},enable(){this.$refs.ordergroup.enable()},initializeValue(e){this.setResponse(this.computeResponse(e)),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},initializeOriginalOrder(){if(this.originalOrder!==null)return;let e=[];this.choices.forEach(t=>{e.push(t.identifier)}),this.originalOrder=e},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.setResponse(null),this.setState(null),this.priorState=null,this.$refs.ordergroup.resetGroupUI()},restoreValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality:"ordered",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){this.hasPrompts&&this.$refs.prompt.appendChild(this.$refs.ordergroup.getPromptElement())},handleOrderGroupReady(e){this.choices=e.choices,this.isMinChoicesSpecified||(this.minChoicesValue=this.choices.length),this.originalOrder===null&&this.initializeOriginalOrder(),this.initializeValue(e.response)},handleOrderGroupUpdate(e){this.setResponse(this.computeResponse(e.response)),this.setState({order:e.response,oorder:this.originalOrder}),this.updateValidity(this.computeIsValid())},handleSelectionsLimit(){I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage)},computeResponse(e){let t=[];typeof e>"u"?this.choices.forEach(s=>{t.push(s.identifier)}):t=e;let i=0;switch(this.interactionSubType){case"default":for(let s=0;s<t.length;s++)t[s]!==this.originalOrder[s]&&(i+=1);break;case"ordermatch":for(let s=0;s<t.length;s++)t[s]!==null&&(i+=1);break}return i===0?null:t},computeOrder(){const e=[];return this.choices.forEach(t=>{e.push(t.identifier)}),e},computeState(){return this.priorState!==null?this.priorState.state:{order:this.computeOrder(),oorder:this.originalOrder}},computeIsValid(){const e=this.getResponse(),t=this.minChoicesValue;if(e===null||e.length!==this.originalOrder.length)return!1;let i=0;switch(this.interactionSubType){case"default":for(let s=0;s<e.length;s++)e[s]!==this.originalOrder[s]&&(i+=1);return this.isMinChoicesSpecified?i>=t:i===t;case"ordermatch":for(let s=0;s<e.length;s++)e[s]!==null&&(i+=1);return this.isMinChoicesSpecified?i>=t:i===e.length}return!1},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxChoicesValue===null?"":"You may set an order for a maximum of "+this.maxChoicesValue+" choice"+(this.maxChoicesValue>1?"s":"")+" for this question."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.isMinChoicesSpecified?this.minSelectionsMessage="You must set the order for at least "+this.minChoicesValue+" choice"+(this.minChoicesValue>1?"s":"")+" for this question.":this.minSelectionsMessage="You must set the order for all choices for this question."},detectInteractionSubType(e){return this.getOrderInteractionSubType(e)},getOrderInteractionSubType(e){if(typeof e>"u"||e===null||e.length==0)return"default";const t=e.split(" ");for(let i=0;i<t.length;i++)switch(t[i]){case"qti-choices-top":case"qti-choices-bottom":case"qti-choices-left":case"qti-choices-right":return"ordermatch"}return"default"},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Order Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Order Interaction State Invalid. "state" property not found.');if(!("order"in t.state))throw new O('Order Interaction State Invalid. "order" property not found.');if(!("oorder"in t.state))throw new O('Order Interaction State Invalid. "oorder" property not found.');return this.originalOrder=t.state.oorder,t}},created(){try{if(this.responseDeclaration=Fh.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.setInteractionSubType(this.detectInteractionSubType(this.$.vnode.props.class)),this.priorState=this.getPriorState(this.responseIdentifier),this.cardinality=this.getCardinality(),this.cardinality!=="ordered")throw new c('qti-order-interaction cardinality must be "ordered"');if(this.isShuffle=this.shuffle==="true",this.hasPrompts=this.getPrompts(this.$slots).length>0,typeof this.minChoices<"u"&&(this.isMinChoicesSpecified=!0),this.minChoicesValue=Fh.validateIntegerAttribute("min-choices",this.minChoices,!1,null),this.minChoicesValue===0)throw new c('qti-order-interaction "min-choices", when specified, must not be 0');if(this.isMinChoicesSpecified?(typeof this.maxChoices<"u"&&(this.isMaxChoicesSpecified=!0),this.maxChoicesValue=Fh.validateIntegerAttribute("max-choices",this.maxChoices,!1,null)):this.maxChoicesValue=null,this.isMinChoicesSpecified&&this.isMaxChoicesSpecified&&this.minChoicesValue>this.maxChoicesValue)throw new c('qti-order-interaction "min-choices" must not be greater than "max-choices"');this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"Order",node:this,resetValue:this.resetValue,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},Kk={ref:"root",class:"qti-order-interaction"},Yk={ref:"prompt",class:"qti-prompt-wrapper"};function Xk(e,t,i,s,n,r){const a=l.resolveComponent("OrderGroup");return l.openBlock(),l.createElementBlock("div",Kk,[l.createElementVNode("div",Yk,null,512),l.createVNode(a,l.mergeProps({ref:"ordergroup",cardinality:n.cardinality,shuffle:i.shuffle,responseIdentifier:i.responseIdentifier,orientation:i.orientation,maxChoices:n.maxChoicesValue,minChoices:n.minChoicesValue,interactionSubType:n.interactionSubType,dataChoicesContainerWidth:i.dataChoicesContainerWidth,priorState:n.priorState,onOrderGroupReady:r.handleOrderGroupReady,onOrderGroupUpdate:r.handleOrderGroupUpdate,onOrderGroupSelectionsLimit:r.handleSelectionsLimit},e.$attrs),{default:l.withCtx(()=>[l.renderSlot(e.$slots,"default")]),_:3},16,["cardinality","shuffle","responseIdentifier","orientation","maxChoices","minChoices","interactionSubType","dataChoicesContainerWidth","priorState","onOrderGroupReady","onOrderGroupUpdate","onOrderGroupSelectionsLimit"])],512)}const Zk=P(zk,[["render",Xk]]);class Jk{constructor(){this.nodes=[]}find(t,i){if(Array.isArray(t))return t.forEach(s=>{var n;if(s.component!==null&&((n=s.component.type)==null?void 0:n.name)===i){this.nodes.push(s.component.proxy);return}Array.isArray(s==null?void 0:s.children)&&this.find(s.children,i)}),this.nodes}findNodes(t,{within:i}){return this.find(i,t)}}class e2{constructor(t){return this.constants={QTI_UNSELECTED_HIDDEN:"qti-unselected-hidden"},this.classList=t,this.presentation_UnselectedHidden=!1,this.processClassAttribute(),this}processClassAttribute(){if(typeof this.classList>"u"||this.classList===null||this.classList.length==0)return;const t=this.classList.split(" ");for(let i=0;i<t.length;i++)switch(t[i]){case this.constants.QTI_UNSELECTED_HIDDEN:this.presentation_UnselectedHidden=!0;break}}getUnselectedHidden(){return this.presentation_UnselectedHidden}}const pw=new G,t2=new Jk,i2={name:"QtiHottextInteraction",props:{responseIdentifier:{required:!0,type:String},minChoices:{required:!1,type:String,default:"0"},maxChoices:{required:!1,type:String,default:"1"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String}},inheritAttrs:!0,data(){return{response:null,state:null,isValidResponse:!1,cardinality:"single",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,choices:[],currentChoice:null,isRadio:!0,isDisabled:!1,isQtiValid:!0,hasPrompts:!1,presentationFactory:null,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},disable(){this.toggleDisableChoices(!0)},enable(){this.toggleDisableChoices(!1)},toggleDisableChoices(e){this.isDisabled=e,this.choices.forEach(t=>{t.setIsDisabled(e)})},getInvalidResponseMessage(){return this.minSelectionsMessage},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.choices.forEach(e=>{e.setChecked(!1)}),this.currentChoice=null,this.priorState=null},restoreValue(e){e!==null&&(this.isRadio?this.handleSetChecked(new CustomEvent("setChecked",{bubbles:!1,detail:{identifier:e,checked:"true"}}),!0):e.forEach(t=>{this.handleSetChecked(new CustomEvent("setChecked",{bubbles:!1,detail:{identifier:t,checked:"true"}}),!0)},this),this.setResponse(this.computeResponse()),this.setState(this.computeState()),this.updateValidity(this.computeIsValid()))},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality!=="multiple"?"single":"multiple":"single",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},handleSetChecked(e,t=!1){const i=e.detail;this.choices.forEach(s=>{this.isRadio&&s.setChecked(!1),s.identifier===i.identifier&&(this.currentChoice=s)}),i.checked==="true"?this.checkMaxChoicesLimit()?this.currentChoice.setChecked(!1):this.currentChoice.setChecked(!0):this.currentChoice.setChecked(!1),t||(this.setResponse(this.computeResponse()),this.currentChoice.setFocus(),this.evaluateValidity())},computeResponse(){let e=this.isRadio?null:[];return this.choices.forEach(t=>{t.isChecked()&&(this.isRadio?e=t.identifier:e.push(t.identifier))}),this.isRadio?e:e.length===0?null:e},computeState(){return{}},computeIsValid(){return this.minChoices*1===0?!0:this.response===null?!1:this.cardinality==="single"||this.cardinality==="multiple"&&this.response.length>=this.minChoices*1},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},checkMaxChoicesLimit(){if(this.isRadio||this.maxChoices==0)return!1;const e=this.getResponse();return e!==null&&e.length==this.maxChoices?(I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage),!0):!1},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxChoices==0?"":"You are permitted a maximum of "+this.maxChoices+" selection"+(this.maxChoices>1?"s":"")+" for this question.<br/><br/>Please unselect one of your selections before making another selection."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.minSelectionsMessage=this.minChoices==0?"":"You must make at least "+this.minChoices+" selection"+(this.minChoices>1?"s":"")+" for this question."},validateChildren(){},processChildren(){const e=this.$.subTree===null?null:this.$.subTree.children[1].children;this.choices=t2.findNodes("QtiHottext",{within:e}),this.processGroupUI(),this.priorState!==null&&this.restoreValue(this.priorState.value)},processGroupUI(){this.setUnselectedHidden(),this.setResponse(null),this.setState(this.computeState()),this.setIsValid(this.computeIsValid())},setUnselectedHidden(){this.presentationFactory.getUnselectedHidden()&&this.$refs.hottextgroup.setAttribute("class","qti3-player-hottext-group qti-unselected-hidden")},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Hottext Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Hottext Interaction State Invalid. "state" property not found.');return t}},created(){try{this.responseDeclaration=pw.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.presentationFactory=new e2(this.$.vnode.props.class),this.validateChildren(),this.priorState=this.getPriorState(this.responseIdentifier),pw.validateMaxMinChoices(this.maxChoices,this.minChoices),this.isRadio=this.getCardinality()!=="multiple",this.hasPrompts=this.getPrompts(this.$slots).length>0,this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),this.processChildren(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"Hottext",node:this,resetValue:this.resetValue,disable:this.disable,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},s2={ref:"root",class:"qti-hottext-interaction"},n2={ref:"prompt",class:"qti-prompt-wrapper"};function r2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",s2,[l.createElementVNode("div",n2,null,512),l.createElementVNode("div",{ref:"hottextgroup","on:setChecked":t[0]||(t[0]=(...a)=>r.handleSetChecked&&r.handleSetChecked(...a)),class:"qti3-player-hottext-group"},[l.renderSlot(e.$slots,"default")],544)],512)}const a2=P(i2,[["render",r2]]);class o2{constructor(t){return this.constants={QTI_SELECTIONS_LIGHT:"qti-selections-light",QTI_SELECTIONS_DARK:"qti-selections-dark",QTI_UNSELECTED_HIDDEN:"qti-unselected-hidden",THEME_LIGHT:{selectedOpacity:"1.0",unselectedOpacity:"0.5",fillColor:"orange",fillOpacity:"0",strokeColor:"orange",strokeWidth:2,selectedStrokeWidth:4},THEME_DARK:{selectedOpacity:"1.0",unselectedOpacity:"0.5",fillColor:"#0088CC",fillOpacity:"0",strokeColor:"blue",strokeWidth:2,selectedStrokeWidth:4},THEME_HIDDEN_LIGHT:{selectedOpacity:"1.0",unselectedOpacity:"0",fillColor:"orange",fillOpacity:"0",strokeColor:"orange",strokeWidth:2,selectedStrokeWidth:4},THEME_HIDDEN_DARK:{selectedOpacity:"1.0",unselectedOpacity:"0",fillColor:"blue",fillOpacity:"0",strokeColor:"blue",strokeWidth:2,selectedStrokeWidth:4}},this.classList=t,this.presentation_Theme=this.constants.QTI_SELECTIONS_DARK,this.theme=this.constants.THEME_DARK,this.presentation_UnselectedHidden=!1,this.processClassAttribute(),this}processClassAttribute(){if(typeof this.classList>"u"||this.classList===null||this.classList.length==0)return;const t=this.classList.split(" ");for(let i=0;i<t.length;i++)switch(t[i]){case this.constants.QTI_SELECTIONS_DARK:this.presentation_Theme=this.constants.QTI_SELECTIONS_DARK;break;case this.constants.QTI_SELECTIONS_LIGHT:this.presentation_Theme=this.constants.QTI_SELECTIONS_LIGHT;break;case this.constants.QTI_UNSELECTED_HIDDEN:this.presentation_UnselectedHidden=!0;break}switch(this.presentation_Theme){case this.constants.QTI_SELECTIONS_DARK:this.presentation_UnselectedHidden&&(this.theme=this.constants.THEME_HIDDEN_DARK);break;case this.constants.QTI_SELECTIONS_LIGHT:this.presentation_UnselectedHidden?this.theme=this.constants.THEME_HIDDEN_LIGHT:this.theme=this.constants.THEME_LIGHT;break}}getThemeColors(){return this.theme}}const mw=new G,l2={name:"QtiHotspotInteraction",props:{responseIdentifier:{required:!0,type:String},minChoices:{required:!1,type:String,default:"0"},maxChoices:{required:!1,type:String,default:"1"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String}},data(){return{response:null,state:null,isValidResponse:!1,cardinality:"single",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,choices:[],currentChoice:null,shapeElements:[],currentElement:null,backgroundImage:null,backgroundImageWidth:"0",backgroundImageHeight:"0",isRadio:!0,isDisabled:!1,isQtiValid:!0,hasPrompts:!1,presentationFactory:null,shapeColorProperties:null,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},disable(){this.toggleDisableChoices(!0)},enable(){this.toggleDisableChoices(!1)},toggleDisableChoices(e){this.isDisabled=e},getInvalidResponseMessage(){return this.minSelectionsMessage},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier);for(let e=0;e<this.choices.length;e++)this.setChoiceUnChecked(this.choices[e],this.shapeElements[e]);this.currentChoice=null,this.currentElement=null,this.priorState=null,this.setResponse(null),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},restoreValue(e){e!==null&&(this.isRadio?this.handleSetChecked(new CustomEvent("setChecked",{bubbles:!1,detail:{identifier:e,checked:"true"}}),!0):e.forEach(t=>{this.handleSetChecked(new CustomEvent("setChecked",{bubbles:!1,detail:{identifier:t,checked:"true"}}),!0)},this),this.setResponse(this.computeResponse()),this.setState(this.computeState()),this.updateValidity(this.computeIsValid()))},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality!=="multiple"?"single":"multiple":"single",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},handleSetChecked(e,t=!1){const i=e.detail;for(let s=0;s<this.choices.length;s++)this.isRadio&&this.setChoiceUnChecked(this.choices[s],this.shapeElements[s]),this.choices[s].identifier===i.identifier&&(this.currentChoice=this.choices[s],this.currentElement=this.shapeElements[s]);i.checked==="true"?this.checkMaxChoicesLimit()?this.setChoiceUnChecked(this.currentChoice,this.currentElement):this.setChoiceChecked(this.currentChoice,this.currentElement):this.setChoiceUnChecked(this.currentChoice,this.currentElement),t||(this.setResponse(this.computeResponse()),this.currentElement.focus(),this.evaluateValidity())},computeResponse(){let e=this.isRadio?null:[];return this.choices.forEach(t=>{t.isChecked()&&(this.isRadio?e=t.identifier:e.push(t.identifier))}),this.isRadio?e:e.length===0?null:e},computeState(){return{}},computeIsValid(){return this.minChoices*1===0?!0:this.response===null?!1:this.cardinality==="single"||this.cardinality==="multiple"&&this.response.length>=this.minChoices*1},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},checkMaxChoicesLimit(){if(this.isRadio||this.maxChoices==0)return!1;const e=this.getResponse();return e!==null&&e.length==this.maxChoices?(I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage),!0):!1},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxChoices==0?"":"You are permitted a maximum of "+this.maxChoices+" selection"+(this.maxChoices>1?"s":"")+" for this question.<br/><br/>Please unselect one of your selections before making another selection."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.minSelectionsMessage=this.minChoices==0?"":"You must make at least "+this.minChoices+" selection"+(this.minChoices>1?"s":"")+" for this question."},validateChildren(){},processChildren(){this.processBackgroundImage(),this.$.subTree.children[1].children[0].dynamicChildren.forEach(t=>{if(t.component!==null&&t.type.name==="QtiHotspotChoice"){const i=t.component.proxy;this.choices.push(i);const s=i.getShapeElement();s!==null&&(this.addHotspotListeners(s),this.shapeElements.push(s),this.$refs.overlay.appendChild(s))}}),this.processGroupUI(),this.priorState!==null&&this.restoreValue(this.priorState.value)},addHotspotListeners(e){e.addEventListener("click",this.handleHotspotClick),e.addEventListener("keydown",this.handleHotspotKeydown)},removeHotspotListeners(e){e.removeEventListener("click",this.handleHotspotClick),e.removeEventListener("keydown",this.handleHotspotKeydown)},handleHotspotClick(e){if(e.preventDefault(),this.isDisabled)return;const t=e.target.getAttribute("data-identifier"),i=this.findChoiceByIdentifier(t);this.isRadio?this.triggerChecked(e.target.getAttribute("data-identifier"),"true"):(this.toggleChecked(i,e.target),this.triggerChecked(t,i.getChecked()))},handleHotspotKeydown(e){const t=e.target.getAttribute("data-identifier"),i=this.findChoiceByIdentifier(t);switch(e.code){case"Space":case"Enter":if(e.stopPropagation(),e.preventDefault(),this.isDisabled||i==null)return;this.toggleChecked(i,e.target),this.triggerChecked(t,i.getChecked());break}},findChoiceByIdentifier(e){for(let t=0;t<this.choices.length;t++)if(this.choices[t].identifier===e)return this.choices[t];return null},toggleChecked(e,t){if(e.toggleChecked(),t===null)return;const i=t.getAttribute("aria-checked");t.setAttribute("aria-checked",i==="true"?"false":"true")},triggerChecked(e,t){const i=new CustomEvent("setChecked",{bubbles:!0,cancelable:!0,detail:{identifier:e,checked:t}});this.$refs.hotspotgroup.dispatchEvent(i)},setChoiceUnChecked(e,t){e.setChecked(!1),t.setAttribute("aria-checked","false");const i=e.getShapeColorProperties();t.setAttribute("fill",`${i.fillColor}`),t.setAttribute("fill-opacity",`${i.fillOpacity}`),t.setAttribute("opacity",`${i.unselectedOpacity}`),t.setAttribute("stroke",`${i.strokeColor}`),t.setAttribute("stroke-width",`${i.strokeWidth}`)},setChoiceChecked(e,t){e.setChecked(!0),t.setAttribute("aria-checked","true");const i=e.getShapeColorProperties();t.setAttribute("fill",`${i.fillColor}`),t.setAttribute("fill-opacity",`${i.fillOpacity}`),t.setAttribute("opacity",`${i.selectedOpacity}`),t.setAttribute("stroke",`${i.strokeColor}`),t.setAttribute("stroke-width",`${i.selectedStrokeWidth}`)},processGroupUI(){this.setResponse(null),this.setState(this.computeState()),this.setIsValid(this.computeIsValid())},processBackgroundImage(){let e=this.$refs.hotspotgroup.getElementsByTagName("object");if(e.length===0&&(e=this.$refs.hotspotgroup.getElementsByTagName("img")),e.length===0&&(e=this.$refs.hotspotgroup.getElementsByTagName("picture")),e.length!==1)throw new c("Hotspot interaction must have exactly one <img>, <object>, or <picture> node");this.backgroundImage=e[0],this.backgroundImage.setAttribute("draggable","false"),this.backgroundImageWidth=`${e[0].clientWidth}`,this.backgroundImageHeight=`${e[0].clientHeight}`,this.$refs.overlay.setAttribute("viewBox",`0 0 ${this.backgroundImageWidth} ${this.backgroundImageHeight}`),this.$refs.overlay.setAttribute("tabindex","-1"),this.$refs.overlay.setAttribute("role","application"),this.$refs.overlay.setAttribute("focusable","false"),this.$refs.hotspotgroup.setAttribute("style",`width:${e[0].clientWidth};height:${e[0].clientHeight}`)},getShapeColorProperties(){return this.shapeColorProperties},setShapeColorProperties(e){this.shapeColorProperties=e},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Hotspot Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Hotspot Interaction State Invalid. "state" property not found.');return t}},created(){try{this.responseDeclaration=mw.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.presentationFactory=new o2(this.$.vnode.props.class),this.setShapeColorProperties(this.presentationFactory.getThemeColors()),this.validateChildren(),this.priorState=this.getPriorState(this.responseIdentifier),mw.validateMaxMinChoices(this.maxChoices,this.minChoices),this.isRadio=this.getCardinality()!=="multiple",this.hasPrompts=this.getPrompts(this.$slots).length>0,this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),this.processChildren(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"Hotspot",node:this,resetValue:this.resetValue,disable:this.disable,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}},beforeUnmount(){this.shapeElements.forEach(e=>{this.removeHotspotListeners(e)})}},c2={ref:"root",class:"qti-hotspot-interaction"},u2={ref:"prompt",class:"qti-prompt-wrapper"},h2={ref:"overlay",class:"qti3-player-hotspot-overlay"};function d2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",c2,[l.createElementVNode("div",u2,null,512),l.createElementVNode("div",{ref:"hotspotgroup","on:setChecked":t[0]||(t[0]=(...a)=>r.handleSetChecked&&r.handleSetChecked(...a)),class:"qti3-player-hotspot-group"},[l.renderSlot(e.$slots,"default"),(l.openBlock(),l.createElementBlock("svg",h2,null,512))],544)],512)}const f2=P(l2,[["render",d2]]);class p2{constructor(t,i,s){J(this,"moduleAttribute","");J(this,"modulesNode",null);J(this,"itemPathUri","");J(this,"modules",null);J(this,"constants",{BASE_CONFIG:{waitSeconds:60,paths:{}}});return this.moduleAttribute=t,this.modulesNode=i,this.itemPathUri=s,this}async getConfiguration(t){this.setModules(this.getInteractionModules());let i=null;this.moduleAttribute.length>0&&this.modulesNode===null?i=await this.getConfigurationFromUrl(this.getModules()):i=await this.resolveModules(this.getModules()),t&&t(i)}async resolveModules(t){let i=null;if(t===null)return i;let s=this.constants.BASE_CONFIG;return s=await this.initBaseConfiguration(s,t),i=await this.resolvePrimaryConfigurationModules(s,t),i!==null||(i=await this.resolveSecondaryConfigurationModules(s,t)),i}async initBaseConfiguration(t,i){const s=`${this.getItemPathUri()}modules/module_resolution.js`;if(typeof i.primaryconfiguration>"u"&&typeof i.secondaryConfiguration>"u"){const n=await this.fetchDefaultModuleResolution(s,!1);if(n!==null)return n}return t}async resolvePrimaryConfigurationModules(t,i){let s=[];if(typeof i.primaryconfiguration>"u"){for(let o=0;o<i.module.length;o++){if(typeof i.module[o].primarypath>"u")return null;s.push(this.addPathJs(i.module[o].primarypath)),t.paths[i.module[o].id]=this.stripPathJs(i.module[o].primarypath)}return await this.resolveConfigurationModules(s)?t:null}const n=await this.fetchConfiguration(i.primaryconfiguration,!0,!0);if(n===null)return null;for(const a in n.paths)n.paths[a]=this.stripPathJs(n.paths[a]);for(let a=0;a<i.module.length;a++)typeof i.module[a].primarypath<"u"&&(n.paths[i.module[a].id]=this.stripPathJs(this.addPathJs(i.module[a].primarypath)));return await this.resolveConfigurationPathUrls(n.paths)?n:null}async resolveSecondaryConfigurationModules(t,i){let s=[];if(typeof i.secondaryconfiguration>"u"){for(let o=0;o<i.module.length;o++){if(typeof i.module[o].fallbackpath>"u")return null;s.push(this.addPathJs(i.module[o].fallbackpath)),t.paths[i.module[o].id]=this.stripPathJs(i.module[o].fallbackpath)}return await this.resolveConfigurationModules(s)?t:null}const n=await this.fetchConfiguration(i.secondaryconfiguration,!1,!0);if(n===null)return null;for(const a in n.paths)n.paths[a]=this.stripPathJs(n.paths[a]);for(let a=0;a<i.module.length;a++)typeof i.module[a].fallbackpath<"u"&&(n.paths[i.module[a].id]=this.stripPathJs(this.addPathJs(i.module[a].fallbackpath)));return await this.resolveConfigurationPathUrls(n.paths)?n:null}async resolveConfigurationPathUrls(t){let i=[];for(let n=0;n<t.length;n++)i.push(t[n]);return await this.resolveConfigurationModules(i)}async resolveConfigurationModules(t){return await Promise.all(t.map(s=>fetch(s).then(n=>{if(n.ok)return console.log("[PCI Parent] Module Loader Success:",s),n;throw new Error(s)}))).catch(s=>(console.log("[PCI Parent] Module Loader Failure:",s.message),null))!==null}async getConfigurationFromUrl(t){let i=null;return t===null||(typeof t.primaryconfiguration<"u"&&(i=await this.fetchConfiguration(t.primaryconfiguration,!0,!1)),i!==null)||typeof t.secondaryconfiguration<"u"&&(i=await this.fetchConfiguration(t.secondaryconfiguration,!1,!1)),i}async fetchConfiguration(t,i,s){try{const n=await fetch(t);if(!n.ok)throw new Error(`HTTP error: ${n.status}`);const r=await n.json();let a=r.paths;for(let o in a)a[o]!==null&&!a[o].startsWith("http")&&(s?a[o]=`${this.getConfigurationRelativePath(t)}${a[o]}`:a[o]=`${this.getItemPathUri()}${a[o]}`);return r}catch(n){return console.log((i?"Primary":"Fallback")+" Configuration Fetch error:",n),null}}async fetchDefaultModuleResolution(t,i){try{const s=await fetch(t);if(!s.ok)throw new Error(`HTTP error: ${s.status}`);const n=await s.json();let r=n.paths;for(let a in r)r[a]!==null&&!r[a].startsWith("http")&&(i?r[a]=`${this.getConfigurationRelativePath(t)}${r[a]}`:r[a]=`${this.getItemPathUri()}${r[a]}`);return n}catch(s){return console.log("module_resolution.js Fetch error:",s),null}}getItemPathUri(){return this.itemPathUri}getModules(){return this.modules}setModules(t){this.modules=t}getInteractionModules(){let t={};if(this.modulesNode===null)return t={primaryconfiguration:"modules/module_resolution.js",secondaryconfiguration:"modules/fallback_module_resolution.js"},this.addPackagePath(t);const i=this.modulesNode.getPrimaryConfiguration();i.length>0&&(t.primaryconfiguration=i);const s=this.modulesNode.getSecondaryConfiguration();s.length>0&&(t.secondaryconfiguration=s),t.module=[];let n=this.modulesNode.getModules();for(let r=0;r<n.length;r++){let a={id:n[r].getId()};n[r].getPrimaryPath().length>0&&(a.primarypath=n[r].getPrimaryPath()),n[r].getFallbackPath().length>0&&(a.fallbackpath=n[r].getFallbackPath()),t.module.push(a)}return this.addPackagePath(t)}addPackagePath(t){for(let s in{primaryconfiguration:"",secondaryconfiguration:""})s in t&&t[s]!==null&&!t[s].startsWith("http")&&(t[s]=this.getAbsolutePath(this.getItemPathUri(),t[s]));let i=t.module;if(i!=null)for(let s=0;s<i.length;s++){let n=i[s];for(let r in{primarypath:"",fallbackpath:""})r in n&&n[r]!==null&&!n[r].startsWith("http")&&(n[r]=this.getAbsolutePath(this.getItemPathUri(),n[r]))}return t}getAbsolutePath(t,i){let s=t.split("/"),n=i.split("/");s.pop();for(var r=0;r<n.length;r++)n[r]!="."&&(n[r]==".."?s.pop():s.push(n[r]));return s.join("/")}getConfigurationRelativePath(t){if(t===null||t.length===0)return"";const i=t.lastIndexOf("/");return i<0?"":t.substring(0,i+1)}stripPathJs(t){return t===null?null:t.endsWith(".js")?t.slice(0,t.lastIndexOf(".")):t}addPathJs(t){return t===null?null:t.length>0&&!t.endsWith(".js")?`${t}.js`:t}}const Uh=new G,Rl=new ie,m2={name:"QtiPortableCustomInteraction",props:{responseIdentifier:{required:!0,type:String},customInteractionTypeIdentifier:{required:!0,type:String},module:{required:!1,type:String,default:""},dataItemPathUri:{required:!1,type:String,default:""}},inheritAttrs:!0,data(){return{response:null,state:null,baseType:null,cardinality:null,isValidResponse:!0,isQtiValid:!0,hasPrompts:!1,pciModuleResolver:null,loadIframeHandler:null,renderer:"",classAttribute:"",properties:{},modulesNode:null,modules:null,configuration:null,templateVariables:[],contextVariables:[],stylesheets:[],catalogInfoNode:null,uniqueId:null,pciIframe:null,isReady:!1,initialWidth:0,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},getStateRequest(){this.pciIframe.contentWindow.postMessage({message:"PciGetState_Request"},"*")},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},getInvalidResponseMessage(){return""},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.priorState=null},restoreValue(e,t){this.setResponse(e),this.setState(t)},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=e.cardinality,this.cardinality},getBaseType(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.baseType=e.baseType,this.baseType},getPrompts(e){let t=[];return e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},computeState(){return{}},computeIsValid(){return!0},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},validateChildren(){if(!this.$slots.default)return;let e=!1,t=!1,i=!1,s=!1,n=!1,r=!1,a=!1;this.$slots.default().forEach(o=>{if(Uh.isValidSlot(o)){if(o.type.name==="QtiPrompt"){if(t||i||s||n||r||a)throw new c("Invalid element order. qti-prompt must be the first element");if(!e)return e=!0;throw new c("Maximum of 1 qti-prompt element permitted")}if(o.type.name==="QtiInteractionModules"){if(t||s||n||r||a)throw new c("Invalid element order: qti-interaction-modules");if(!i)return i=!0;throw new c("Maximum of 1 qti-interaction-modules element permitted")}if(o.type.name==="QtiInteractionMarkup"){if(s||n||r||a)throw new c("Invalid element order: qti-interaction-markup");if(!t)return t=!0;throw new c("Maximum of 1 qti-interaction-markup element permitted")}if(o.type.name==="QtiTemplateVariable"){if(s||r||a)throw new c("Invalid element order: qti-template-variable");return n=!0}if(o.type.name==="QtiContextVariable"){if(r||a)throw new c("Invalid element order: qti-context-variable");return s=!0}if(o.type.name==="QtiStylesheet"){if(a)throw new c("Invalid element order: qti-stylesheet");return r=!0}if(o.type.name==="QtiCatalogInfo"){if(!a)return a=!0;throw new c("Maximum of 1 qti-catalog-info element permitted")}throw new c('Node is not permitted inside QtiPortableCustomInteraction: "'+o.type.name+'"')}})},processChildren(){const e=this.$.subTree.children[1].children[0].children;e!==null&&(e.forEach(t=>{if(t.component===null)return;const i=t.component.proxy;switch(t.type.name){case"QtiInteractionMarkup":this.markup=i.getMarkup();break;case"QtiInteractionModules":this.modulesNode=i;break;case"QtiTemplateVariable":this.templateVariables.push(i);break;case"QtiContextVariable":this.contextVariables.push(i);break;case"QtiStylesheet":this.stylesheets.push(i);break;case"QtiCatalogInfo":this.catalogInfoNode=i;break}}),this.priorState!==null&&this.restoreValue(this.priorState.value,this.priorState.state),this.initialWidth=this.$refs.root.clientWidth)},disable(){},enable(){},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('PCI State Invalid. "value" property not found.');if(!("state"in t))throw new O('PCI State Invalid. "state" property not found.');return t},createId(){return"pci_"+Uh.randomString(5,"a")},initialize(){this.setProperties(this.getPciProperties()),this.pciModuleResolver=new p2(this.module,this.modulesNode,this.dataItemPathUri),this.pciModuleResolver.getConfiguration((function(e){this.setConfiguration(e),console.log("[PCI Parent] PCI Configuration:",e),e!==null&&this.loadPciIframe(this.initialWidth)}).bind(this))},loadPciIframe(e){const t=document.createElement("iframe");t.name=this.uniqueId,t.id=this.uniqueId,t.setAttribute("scrolling","no"),t.style.border="none",t.style.width=`${e}px`,t.addEventListener("load",this.loadIframeHandler),t.src=`${this.renderer}?identifier=${this.responseIdentifier}&uniqueId=${this.uniqueId}`,this.$refs.ic.appendChild(t)},handleLoadIframe(e){this.pciIframe=e.target},getItemPathUri(){return this.dataItemPathUri},getPciProperties(){let e=this.$refs.root;const t={};for(let i in e.dataset)i!=="uniqueId"&&(t[i]=Rl.encodeBytesToBase64(e.dataset[i]));return t},getProperties(){return this.properties},setProperties(e){this.properties=e},getContextVariables(){let e={};for(let t=0;t<this.contextVariables.length;t++)e[this.contextVariables[t].getIdentifier()]=this.contextVariables[t].evaluate();return e},getTemplateVariables(){let e={};for(let t=0;t<this.templateVariables.length;t++)e[this.templateVariables[t].getIdentifier()]=this.templateVariables[t].evaluate();return e},getStylesheets(){let e=[];for(let t=0;t<this.stylesheets.length;t++){const i=this.stylesheets[t],s=Rl.encodeBytesToBase64(i.getRawCss());e.push({href:i.getHref(),type:i.getType(),css:`${s}`})}return e},getCatalogInfo(){return this.catalogInfoNode},getModules(){return this.modules},setModules(e){this.modules=e},getConfiguration(){return this.configuration},setConfiguration(e){this.configuration=e},getClassAttribute(){return this.classAttribute},setClassAttribute(e){this.classAttribute=e},copyAttributes(e,t,i){return e.forEach(function(s){let n=s.replace("-","");t[n]=i.getAttribute(s)}),t},getResponseVariable(){let e=Rl.valueToPciJson(this.getResponse(),this.baseType,this.cardinality),t={};return t[this.responseIdentifier]=e,t},pciInitialize(){let e={typeIdentifier:this.customInteractionTypeIdentifier,classAttribute:this.getClassAttribute(),markup:this.markup,properties:this.getProperties(),boundTo:this.getResponseVariable(),templateVariables:this.getTemplateVariables(),contextVariables:this.getContextVariables(),stylesheets:this.getStylesheets(),catalogInfo:this.getCatalogInfo(),module:this.module,modules:this.getModules(),moduleResolution:this.getConfiguration(),status:I.getItemLifecycleStatus()},t={message:"PciLoadInteraction",pci:JSON.stringify(e)};this.priorState!==null&&(t.state=JSON.stringify({response:Rl.valueToPciJson(this.getResponse(),this.baseType,this.cardinality),state:this.getState()})),this.pciIframe.contentWindow.postMessage(t,"*")},pciResizeIframe(e,t){this.pciIframe!==null&&(this.pciIframe.style.height=`${e}px`,this.pciIframe.style.width=`${t}px`)},pciResizeIframeWidthToContainer(){this.pciIframe!==null&&(this.pciIframe.style.width=`${this.$refs.ic.clientWidth}px`)},pciSaveState(e){const t=JSON.parse(e);typeof t.response<"u"?this.setResponse(t.response):this.setResponse(null),typeof t.state<"u"?this.setState(t.state):this.setState(null),this.notifyInteractionStateReady()},pciSetReady(){this.isReady=!0},pciIsReady(){return this.pciIframe!==null&&this.isReady},notifyInteractionStateReady(){I.NotifyInteractionStateReady({identifier:this.responseIdentifier})}},created(){try{this.responseDeclaration=Uh.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.validateChildren(),this.renderer=I.getPciContextRenderer(),this.loadIframeHandler=this.handleLoadIframe.bind(this);const e=typeof this.$.vnode.props.class<"u"?this.$.vnode.props.class:"";this.setClassAttribute(e),this.priorState=this.getPriorState(this.responseIdentifier),this.hasPrompts=this.getPrompts(this.$slots).length>0,this.cardinality=this.getCardinality(),this.baseType=this.getBaseType(),this.uniqueId=this.createId()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),this.processChildren(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"PortableCustom",node:this,resetValue:this.resetValue,disable:this.disable,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:""}),this.initialize(),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}},beforeUnmount(){this.pciIframe!==null&&this.pciIframe.removeEventListener("load",this.loadIframeHandler)}},g2={ref:"root",class:"qti-portable-custom-interaction"},y2={ref:"prompt",class:"qti-prompt-wrapper"},w2={ref:"pcigroup",class:"qti3-player-pci-group"},b2={ref:"ic",class:"qti3-player-pci-iframe-container"};function v2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",g2,[l.createElementVNode("div",y2,null,512),l.createElementVNode("div",w2,[l.renderSlot(e.$slots,"default")],512),l.createElementVNode("div",b2,null,512)],512)}const E2=P(m2,[["render",v2]]),Gh=new G,C2={name:"QtiSelectPointInteraction",props:{responseIdentifier:{required:!0,type:String},minChoices:{required:!1,type:String,default:"0"},maxChoices:{required:!1,type:String,default:"1"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String}},data(){return{response:null,state:null,isValidResponse:!1,cardinality:"single",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,pointElements:new Map,backgroundImage:null,backgroundImageWidth:"0",backgroundImageHeight:"0",bgImageProperties:null,overlayId:"",markerType:"default",isResponsive:!1,interactionClassAttribute:null,pointRadius:9,isSingle:!0,isDisabled:!1,isQtiValid:!0,hasPrompts:!1,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},disable(){this.toggleDisablePoints(!0)},enable(){this.toggleDisablePoints(!1)},toggleDisablePoints(e){this.isDisabled=e},getInvalidResponseMessage(){return this.minSelectionsMessage},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.priorState=null,this.setResponse(null),this.deleteAllPoints(),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},restoreValue(e){if(e===null)return;e.state.points.forEach(i=>{this.restorePointElement(i)}),this.setState(e.state),this.setResponse(this.computeResponse()),this.updateValidity(this.computeIsValid())},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality!=="multiple"?"single":"multiple":"single",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},computeResponse(){let e=this.isSingle?null:[];for(const t of this.pointElements.values()){const i=`${t.getAttribute("data-point")}`;this.isSingle?e=i:e.push(i)}return this.isSingle?e:e.length===0?null:e},computeState(){const e=[];for(const[t,i]of this.pointElements)e.push({id:t,marker:i.getAttribute("data-marker-type"),point:i.getAttribute("data-point"),static:i.getAttribute("class").includes("static")});return{points:e}},computeIsValid(){return this.minChoices*1===0?!0:this.response===null?!1:this.cardinality==="single"||this.cardinality==="multiple"&&this.response.length>=this.minChoices*1},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},checkMaxChoicesLimit(){return this.isSingle&&this.pointElements.size==0||!this.isSingle||this.maxChoices==0||!this.isSingle&&this.pointElements.size<this.maxChoices?!1:(I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage),!0)},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxChoices==0?"":"You are permitted a maximum of "+this.maxChoices+" point"+(this.maxChoices>1?"s":"")+" for this question.<br/><br/>Please remove one of your points before making another point."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.minSelectionsMessage=this.minChoices==0?"":"You must make at least "+this.minChoices+" point"+(this.minChoices>1?"s":"")+" for this question."},createId(e){return`${e}${Gh.randomString(5,"a")}`},processChildren(){this.processBackgroundImage(),this.processGroupUI(),this.priorState!==null&&this.restoreValue(this.priorState)},addPointFromClick(e){const t=this.createId("p_"),i=this.createPointElement(e,this.markerType,t);this.addPointListeners(i),this.pointElements.set(t,i),this.$refs.overlay.appendChild(i),this.setState(this.computeState()),this.setResponse(this.computeResponse()),this.evaluateValidity()},deleteAllPoints(){for(const[e,t]of this.pointElements.values())this.deletePoint(e,t)},deletePoint(e,t){this.removePointListeners(t),this.pointElements.delete(e),t.remove()},createPointElement(e,t,i){const s=this.convertPoint(e.x,e.y,!1);return this.newPointElement(i,e,s,t,!0)},restorePointElement(e){const t=e.point.split(" ");if(t.length!==2)return;const i=this.convertPoint(t[0],t[1],!0),s={x:t[0],y:t[1]},n=this.newPointElement(e.id,i,s,e.marker,e.static);this.addPointListeners(n),this.pointElements.set(e.id,n),this.$refs.overlay.appendChild(n)},convertPoint(e,t,i){const s=this.getScalingFactor();let n,r;return i?(n=Math.round(e/s),r=Math.round(t/s)):(n=Math.round(e*s),r=Math.round(t*s)),n<0&&(n=0),n>this.bgImageProperties.w&&(n=this.bgImageProperties.w),r<0&&(r=0),r>this.bgImageProperties.h&&(r=this.bgImageProperties.h),{x:n,y:r}},getScalingFactor(){return this.isResponsive?this.bgImageProperties.w/this.backgroundImageWidth:1},newPointElement(e,t,i,s,n){const r=document.createElementNS("http://www.w3.org/2000/svg","circle");return r.setAttribute("cx",t.x),r.setAttribute("cy",t.y),r.setAttribute("r",this.pointRadius),s==="default-light"?(r.setAttribute("fill","orange"),r.setAttribute("fill-opacity",".5"),r.setAttribute("stroke","orange")):(r.setAttribute("fill","#0088CC"),r.setAttribute("fill-opacity",".5"),r.setAttribute("stroke","blue")),r.setAttribute("opacity","1"),r.setAttribute("stroke-width","1"),r.setAttribute("data-marker-type",s),r.setAttribute("id",`${e}`),r.setAttribute("class",`qti3-player-select-point ${n?"static":""}`),r.setAttribute("tabindex","0"),r.setAttribute("data-point",`${i.x} ${i.y}`),r},handleOverlayClick(e){e.preventDefault(),this.checkMaxChoicesLimit()||this.addPointFromClick(this.getMousePosition(e))},handlePointClick(e){if(e.preventDefault(),e.stopPropagation(),this.isDisabled)return;const t=e.target,i=t.getAttribute("id");this.deletePoint(i,t),this.setState(this.computeState()),this.setResponse(this.computeResponse()),this.evaluateValidity()},getMousePosition(e){const t=this.$refs.overlay.getScreenCTM();e.touches&&(e=e.touches[0]);const i=(e.clientX-t.e)/t.a,s=(e.clientY-t.f)/t.d;return{x:i,y:s}},processGroupUI(){this.setResponse(null),this.setState(this.computeState()),this.setIsValid(this.computeIsValid())},processBackgroundImage(){if(this.bgImageProperties=this.computeBackgroundImageProperties(),console.log("Initial Dimensions, bgImageProperties:",this.bgImageProperties),this.bgImageProperties===null)throw new c("Select Point interaction must have exactly one <img>, <object>, or <picture> node");this.isResponsive?(this.backgroundImageWidth=`${this.bgImageProperties.element.offsetWidth}`,this.backgroundImageHeight=`${this.bgImageProperties.element.offsetHeight}`):(this.backgroundImageWidth=`${this.bgImageProperties.w}`,this.backgroundImageHeight=`${this.bgImageProperties.h}`,this.$refs.selectpointgroup.setAttribute("style",`width:${this.backgroundImageWidth};height:${this.backgroundImageHeight}`)),this.overlayId=this.createId("spi_"),this.$refs.overlay.setAttribute("id",this.overlayId),this.$refs.overlay.setAttribute("width",`${this.backgroundImageWidth}`),this.$refs.overlay.setAttribute("height",`${this.backgroundImageHeight}`),this.$refs.overlay.setAttribute("viewBox",`0 0 ${this.backgroundImageWidth} ${this.backgroundImageHeight}`),this.$refs.overlay.setAttribute("tabindex","-1"),this.$refs.overlay.setAttribute("role","application"),this.$refs.overlay.setAttribute("focusable","false"),this.createSvgImage(this.bgImageProperties,this.backgroundImageWidth,this.backgroundImageHeight),this.addOverlayListeners()},handleResize(){this.backgroundImageWidth=this.$refs.overlay.parentNode.offsetWidth,this.backgroundImageHeight=this.$refs.overlay.parentNode.offsetHeight,this.$refs.overlay.setAttribute("width",`${this.backgroundImageWidth}`),this.$refs.overlay.setAttribute("height",`${this.backgroundImageHeight}`)},computeBackgroundImageProperties(){let e=this.$refs.selectpointgroup.getElementsByTagName("img");if(e.length===1){const t=e[0].getAttribute("width"),i=e[0].getAttribute("height");return this.createImageProperties(e[0],e[0].src,"img",t,i)}if(e=this.$refs.selectpointgroup.getElementsByTagName("object"),e.length===1){const t=e[0].getAttribute("width"),i=e[0].getAttribute("height");return this.createImageProperties(e[0],e[0].data,"object",t,i)}return null},createImageProperties(e,t,i,s,n){let r=s===null||n===null?1:s/n;return{element:e,src:t,tag:i,w:s,h:n,ar:r}},createSvgImage(e,t,i){let s=document.createElementNS("http://www.w3.org/2000/svg","image");s.setAttribute("href",e.src),s.setAttribute("width",t),s.setAttribute("height",i),s.setAttribute("draggable",!1),this.$refs.overlay.appendChild(s),e.element.remove()},addOverlayListeners(){this.$refs.overlay.addEventListener("click",this.handleOverlayClick.bind(this))},removeOverlayListeners(){this.$refs.overlay.removeEventListener("click",this.handleOverlayClick)},addPointListeners(e){e.addEventListener("click",this.handlePointClick.bind(this))},removePointListeners(e){e.removeEventListener("click",this.handlePointClick)},processClassAttribute(e){if(typeof e>"u"||e===null||e.length==0)return;const t=e.split(" ");for(let i=0;i<t.length;i++)switch(t[i]){case"responsive":this.isResponsive=!0;break;case"marker-crosshair":this.markerType="crosshair";break;case"marker-default":this.markerType="default";break;case"marker-default-light":this.markerType="default-light";break}},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Select Point Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Select Point Interaction State Invalid. "state" property not found.');if(!("points"in t.state))throw new O('Select Point Interaction State Invalid. "points" property not found in State.');return t}},created(){try{this.responseDeclaration=Gh.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.processClassAttribute(this.$.vnode.props.class),this.priorState=this.getPriorState(this.responseIdentifier),Gh.validateMaxMinChoices(this.maxChoices,this.minChoices),this.isSingle=this.getCardinality()!=="multiple",this.hasPrompts=this.getPrompts(this.$slots).length>0,this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),this.processChildren(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"SelectPoint",node:this,resetValue:this.resetValue,disable:this.disable,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}},beforeUnmount(){this.removeOverlayListeners();for(const e of this.pointElements.values())this.removePointListeners(e)}},T2={ref:"root",class:"qti-select-point-interaction"},S2={ref:"prompt",class:"qti-prompt-wrapper"},x2={ref:"selectpointgroup",class:"select-point-group"},I2={ref:"overlay",class:"select-point-overlay"};function _2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",T2,[l.createElementVNode("div",S2,null,512),l.createElementVNode("div",x2,[l.renderSlot(e.$slots,"default"),(l.openBlock(),l.createElementBlock("svg",I2,null,512))],512)],512)}const V2=P(C2,[["render",_2]]),A2={name:"QtiPrompt"},$2={class:"qti-prompt"};function L2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",$2,[l.renderSlot(e.$slots,"default")])}const M2=P(A2,[["render",L2]]),R2=new G,N2={name:"QtiInlineChoice",props:{identifier:{required:!0,type:String},fixed:{required:!1,type:String,default:"false"},templateIdentifier:{required:!1,type:String},showHide:{required:!1,type:String,default:"show"}},data(){return{id:null}},inheritAttrs:!0,methods:{createId(){if(this.$refs.choice.hasAttribute("id")){this.id=this.$refs.choice.getAttribute("id");return}this.id="inlinechoice_"+R2.randomString(5,"a")+"_"+this.identifier,this.$refs.choice.setAttribute("id",this.id)}},created(){},mounted(){this.createId()}},k2=["data-identifier"];function q2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("li",{ref:"choice",role:"option","data-identifier":i.identifier,class:"qti-inline-choice"},[l.renderSlot(e.$slots,"default")],8,k2)}const O2=P(N2,[["render",q2]]),P2=new G,B2={name:"QtiSimpleChoice",emits:["setChecked","setFocusPreviousChoice","setFocusNextChoice","setActiveDescendant"],props:{identifier:{required:!0,type:String},fixed:{required:!1,type:String,default:"false"},templateIdentifier:{required:!1,type:String},showHide:{required:!1,type:String,default:"show"}},data(){return{id:null,checked:"false",isRadio:!0,role:"radio",tabIndex:"-1",hasMath:!1,isDisabled:!1,parentCardinality:"single"}},inheritAttrs:!0,methods:{handleClick(){if(!this.isDisabled)if(this.isRadio)this.$parent.$emit("setChecked",{identifier:this.identifier,checked:"true"});else{if(this.toggleChecked(),this.parentCardinality==="ordered")return;this.$parent.$emit("setChecked",{identifier:this.identifier,checked:this.checked})}},handleKeydown(e){let t=!1;switch(e.code){case"Space":if(!this.isDisabled){if(this.toggleChecked(),this.parentCardinality==="ordered")return;this.$parent.$emit("setChecked",{identifier:this.identifier,checked:this.checked})}t=!0;break;case"Enter":if(!this.isDisabled){if(this.toggleChecked(),this.parentCardinality==="ordered")return;this.$parent.$emit("setChecked",{identifier:this.identifier,checked:this.checked})}t=!0;break;case"ArrowUp":case"ArrowLeft":this.isRadio&&(this.$parent.$emit("setFocusPreviousChoice",this.identifier),t=!0);break;case"ArrowDown":case"ArrowRight":this.isRadio&&(this.$parent.$emit("setFocusNextChoice",this.identifier),t=!0);break}t&&(e.stopPropagation(),e.preventDefault())},handleFocus(){this.parentCardinality!=="ordered"&&this.$parent.$emit("setActiveDescendant",this.id)},handleBlur(){},setChecked(e){this.checked=e?"true":"false"},isChecked(){return this.checked==="true"},setTabIndex(e){this.tabIndex=e},setFocus(){this.$refs.choice.focus()},setBlur(){this.$refs.choice.blur()},toggleChecked(){this.checked=this.checked==="true"?"false":"true"},setLabel(e){this.$refs.label.innerText=e},hideLabel(){this.$refs.label.classList.add("qti-hidden")},showLabel(){this.$refs.label.classList.remove("qti-hidden")},setLabelSbac(e){this.$refs.choice.classList.add("sbac"),this.$refs.choice.setAttribute("data-label",e),this.$refs.label.innerText=e,this.$refs.label.classList.add("qti-visually-hidden")},setChoiceLrn(){this.$refs.choice.classList.add("lrn")},hideControl(){this.$refs.choice.classList.add("control-hidden")},setIsDisabled(e){this.isDisabled=e},initializeChoice(){switch(this.parentCardinality=this.$parent.cardinality,this.parentCardinality){case"ordered":this.role="button",this.isRadio=!1,this.tabIndex=0;break;case"multiple":this.role="checkbox",this.isRadio=!1,this.tabIndex=0;break;default:this.role="radio",this.isRadio=!0,this.tabIndex=-1;break}},initializeOrderChoice(){this.role==="button"&&(this.hideLabel(),this.hideControl())},createId(){if(this.$refs.choice.hasAttribute("id")){this.id=this.$refs.choice.getAttribute("id");return}this.id="choice_"+P2.randomString(5,"a")+"_"+this.identifier,this.$refs.choice.setAttribute("id",this.id)},setExpectedSolution(){this.$refs.choice.classList.add("player-show-solution","player-choice-expected")},setCorrectSolution(){this.$refs.choice.classList.add("player-show-solution","player-choice-correct")},setIncorrectSolution(){this.$refs.choice.classList.add("player-show-solution","player-choice-incorrect")},setIgnoreSolution(){this.$refs.choice.classList.remove("player-show-solution","player-choice-incorrect","player-choice-correct","player-choice-expected")}},created(){this.initializeChoice()},mounted(){this.initializeOrderChoice(),this.createId()}},D2=["role","aria-checked","tabindex","data-identifier"],Q2={ref:"label",class:"qti-choice-label"},H2={ref:"description",class:"qti-choice-description"};function F2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("li",{ref:"choice",role:n.role,"aria-checked":n.checked,tabindex:n.tabIndex,"data-identifier":i.identifier,onFocus:t[0]||(t[0]=(...a)=>r.handleFocus&&r.handleFocus(...a)),onBlur:t[1]||(t[1]=(...a)=>r.handleBlur&&r.handleBlur(...a)),onClick:t[2]||(t[2]=(...a)=>r.handleClick&&r.handleClick(...a)),onKeydown:t[3]||(t[3]=(...a)=>r.handleKeydown&&r.handleKeydown(...a)),class:l.normalizeClass(["qti-simple-choice",{source:n.role=="button"}])},[l.createElementVNode("div",{class:l.normalizeClass(["qti-simple-choice-wrapper",{draggable:n.role=="button"}]),style:{width:"100%"}},[l.createElementVNode("div",Q2,null,512),l.createElementVNode("div",H2,[l.renderSlot(e.$slots,"default")],512)],2)],42,D2)}const U2=P(B2,[["render",F2]]),G2=new G,j2={name:"QtiSimpleAssociableChoice",props:{identifier:{required:!0,type:String},fixed:{required:!1,type:String,default:"false"},templateIdentifier:{required:!1,type:String},showHide:{required:!1,type:String,default:"show"},matchGroup:{required:!1,type:String,default:""},matchMax:{required:!0,type:String},matchMin:{required:!1,type:String,default:"0"}},data(){return{id:null}},methods:{createId(){if(this.$refs.choice.hasAttribute("id")){this.id=this.$refs.choice.getAttribute("id");return}this.id="choice_"+G2.randomString(5,"a")+"_"+this.identifier,this.$refs.choice.setAttribute("id",this.id)}},mounted(){this.createId()}},W2=["data-identifier","data-match-max","data-match-min","data-match-group"],z2={ref:"description",class:"choice-description"};function K2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("li",{ref:"choice","data-identifier":i.identifier,"data-match-max":i.matchMax,"data-match-min":i.matchMin,"data-match-group":i.matchGroup,class:"qti-simple-associable-choice"},[l.createElementVNode("div",z2,[l.renderSlot(e.$slots,"default")],512)],8,W2)}const Y2=P(j2,[["render",K2]]),X2=new G,Z2={name:"QtiAssociableHotspot",props:{identifier:{required:!0,type:String},templateIdentifier:{required:!1,type:String},showHide:{required:!1,type:String,default:"show"},matchGroup:{required:!1,type:String,default:""},shape:{required:!0,type:String},coords:{required:!0,type:String},hotspotLabel:{required:!1,type:String,default:""},ariaLabel:{required:!1,type:String,default:""},matchMax:{required:!0,type:String},matchMin:{required:!1,type:String,default:"0"}},data(){return{shapeData:null,shapeColorProperties:null,isQtiValid:!0}},inheritAttrs:!0,methods:{getIdentifier(){return this.identifier},getShape(){return this.shape},getShapeData(){return this.shapeData},setShapeData(){const e=this.coords.split(",");switch(this.getShape()){case"circle":if(e.length!=3)return;this.shapeData=e;return;case"rect":if(e.length!==4)return;e[2]=parseInt(e[2])-parseInt(e[0]),e[3]=parseInt(e[3])-parseInt(e[1]),this.shapeData=e;return;case"poly":this.shapeData=this.transformPolyCoords(e);return;case"ellipse":if(e.length!=4)return;this.shapeData=e;return;case"default":this.shapeData="";return}},transformPolyCoords(e){let t=[];if(e.length%2!=0)return t;for(let i=0;i<e.length;i+=2)t.push(`${e[i]} ${e[i+1]}`);return t},initialize(){X2.validateShapeAttribute(this.shape),this.setShapeData()}},created(){try{this.initialize()}catch(e){if(this.isQtiValid=!1,e.name==="QtiValidationException")throw new c(e.message)}},mounted(){if(this.isQtiValid)try{console.log("["+this.$options.name+"][Identifier]",this.identifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},J2=["data-identifier","data-match-max","data-match-min","data-match-group"];function eq(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",{ref:"gap","data-identifier":i.identifier,"data-match-max":i.matchMax,"data-match-min":i.matchMin,"data-match-group":i.matchGroup,class:"ggm-gap"},null,8,J2)}const tq=P(Z2,[["render",eq]]),iq=new G,sq=new ie,nq={name:"QtiSimpleMatchSet",data(){return{choices:[],isShuffle:!1,isQtiValid:!0}},methods:{getChoices(){return this.choices},setIsShuffle(e){this.isShuffle=e},createContainer(e,t){let i=[];return e===null?(this.choices.forEach(n=>{i.push({fixed:n.fixed==="true",node:n})}),this.isShuffle&&sq.shuffleArrayFixed(i),i):(e.state.orders[t].forEach(n=>{const r=this.findChoiceByIdentifier(n,this.choices);r!==null&&i.push({fixed:r.fixed==="true",node:r})},this),i)},processContainerChoices(e){this.choices.splice(0,this.choices.length),this.$refs.matchset.innerHTML="",e.forEach(t=>{this.$refs.matchset.appendChild(t.node.$el),this.choices.push(t.node)},this)},validateChildren(){let e=0;if(!this.$slots.default)throw new c("Must have at least 1 qti-simple-associable-choice");if(this.$slots.default().forEach(t=>{if(iq.isValidSlot(t)){if(t.type.name==="QtiSimpleAssociableChoice")return e+=1;throw new c('Node is not a qti-simple-associable-choice: "'+t.type.name+'"')}}),e===0)throw new c("Must have at least 1 qti-simple-associable-choice")},processChildren(){this.$.subTree.children[0].children.forEach(t=>{t.component!==null&&this.choices.push(t.component.proxy)})},findChoiceByIdentifier(e,t){for(let i=0;i<t.length;i++)if(t[i].$el.getAttribute("data-identifier")===e)return t[i];throw new O('Match Interaction State Invalid. Choice identifier "'+e+'" not found.')}},created(){try{this.validateChildren()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.processChildren(),console.log("["+this.$options.name+"]")}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},rq={ref:"matchset",class:"qti-simple-match-set"};function aq(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("ul",rq,[l.renderSlot(e.$slots,"default")],512)}const oq=P(nq,[["render",aq]]);class lq{constructor(t){this.constants={QTI_CHOICES_TOP:"qti-choices-top",QTI_CHOICES_BOTTOM:"qti-choices-bottom",QTI_CHOICES_LEFT:"qti-choices-left",QTI_CHOICES_RIGHT:"qti-choices-right",DATA_MAX_SELECTIONS_MESSAGE:"data-max-selections-message",DATA_MIN_SELECTIONS_MESSAGE:"data-min-selections-message",DATA_CHOICES_CONTAINER_WIDTH:null},this.parentClass=t,this.clazzTokens=[],this.gapMatchGroupElement=null,this.gapChoiceWrapperElement=null,this.gapTargetWrapperElement=null,this.choicesContainerWidth=null,this.gapChoices=[],this.gaps=[],this.presentation_Choices_Orientation=null,this.presentation_MaxSelectionsMessage="",this.presentation_MinSelectionsMessage=""}initialize(t,i,s,n,r,a){this.gapMatchGroupElement=t,this.gapChoiceWrapperElement=i,this.gapTargetWrapperElement=s,this.choicesContainerWidth=n,this.gapChoices=r,this.gaps=a,this.processRootClassAttribute(this.parentClass),this.processPresentation()}processRootClassAttribute(t){const i=t.split(" ");for(let s=0;s<i.length;s++)switch(i[s]){case this.constants.QTI_CHOICES_TOP:case this.constants.QTI_CHOICES_BOTTOM:case this.constants.QTI_CHOICES_LEFT:case this.constants.QTI_CHOICES_RIGHT:this.presentation_Choices_Orientation=i[s];break}this.clazzTokens=i}processPresentation(){this.presentation_Choices_Orientation===null&&(this.presentation_Choices_Orientation=this.constants.QTI_CHOICES_TOP),this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_LEFT?(this.gapChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_LEFT),this.gapTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_LEFT),this.gapMatchGroupElement.classList.add(this.constants.QTI_CHOICES_LEFT)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_TOP?(this.gapChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_TOP),this.gapTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_TOP)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_RIGHT?(this.gapChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_RIGHT),this.gapTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_RIGHT),this.gapMatchGroupElement.classList.add(this.constants.QTI_CHOICES_RIGHT),this.gapMatchGroupElement.insertBefore(this.gapTargetWrapperElement,this.gapChoiceWrapperElement)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_BOTTOM&&(this.gapChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_BOTTOM),this.gapTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_BOTTOM),this.gapMatchGroupElement.insertBefore(this.gapTargetWrapperElement,this.gapChoiceWrapperElement)),this.processChoicesContainerWidth(),this.processGaps()}processChoicesContainerWidth(){this.choicesContainerWidth!==null&&(this.gapChoiceWrapperElement.style.width=`${this.choicesContainerWidth}px`)}processGaps(){for(let t=0;t<this.gaps.length;t++)this.gaps[t].classList.add("target")}}class cq{constructor(t,i){J(this,"options",{interactionSubType:"default",cardinality:"single",maxAssociations:0,response:null,onReady:null,onUpdate:null,onSelectionsLimit:null});return this.qtiAttributeValidation=new G,this.wrapper=t,this.sourcewrapper=this.wrapper.querySelector(".qti-gap-match-source-wrapper"),this.targetwrapper=this.wrapper.querySelector(".qti-gap-match-target-wrapper"),this.processOptions(i),this.handleDragStart=this.handleDragStart.bind(this),this.handleDragMove=this.handleDragMove.bind(this),this.handleDragEnd=this.handleDragEnd.bind(this),this.handleTouchStart=this.handleTouchStart.bind(this),this.handleTouchMove=this.handleTouchMove.bind(this),this.handleTouchEnd=this.handleTouchEnd.bind(this),this.itemTarget=null,this.itemStart=null,this.isItemStartSource=!0,this.initialX=0,this.initialY=0,this.offsetX=0,this.offsetY=0,this.startingX=0,this.startingY=0,this.currentAssociationsCount=0,this.isDisabled=!1,this.currentDragger=null,this.initializeSources(this.sourcewrapper),this.initializeTargets(this.targetwrapper),this.restoreResponse(this.options.response),this.notifyReady(),this}processOptions(t){"interactionSubType"in t&&(this.options.interactionSubType=t.interactionSubType),"cardinality"in t&&(this.options.cardinality=t.cardinality),"response"in t&&(this.options.response=t.response),"maxAssociations"in t&&(this.options.maxAssociations=t.maxAssociations),"onReady"in t&&(this.options.onReady=t.onReady),"onUpdate"in t&&(this.options.onUpdate=t.onUpdate),"onAssociationsLimit"in t&&(this.options.onAssociationsLimit=t.onAssociationsLimit)}notifyReady(){this.options.onReady!==null&&this.options.onReady({response:this.getResponse()})}notifyUpdate(){this.options.onUpdate!==null&&this.options.onUpdate({response:this.computeResponse()})}notifyAssociationsLimit(){this.options.onAssociationsLimit!==null&&this.options.onAssociationsLimit()}toggleDisable(t){this.isDisabled=t,this.draggers.forEach(i=>{t?i.classList.add("disabled"):i.classList.remove("disabled")})}handleDragStart(t){if(t.preventDefault(),!this.isDisabled&&t.button==0)return this.interactionStart(t.target,t.clientX,t.clientY,!1),!1}handleTouchStart(t){if(t.preventDefault(),!this.isDisabled)return t.targetTouches.length!=1||this.interactionStart(t.target,t.touches[0].pageX,t.touches[0].pageY,!0),!1}interactionStart(t,i,s,n){const r=this.getClosestElement(t,"draggable");this.itemStart=r.parentNode,this.isItemStartSource=this.itemStart.classList.contains("source"),this.identifyTargets(this.itemStart,!0),this.itemTarget=null;const a=r.getBoundingClientRect();this.initialX=i,this.initialY=s,this.startingX=a.left,this.startingY=a.top,this.offsetX=i-this.startingX,this.offsetY=s-this.startingY,this.addPlaceholder(r),r.style.userSelect="none",r.style.width=a.width+"px",r.style.height=a.height+"px",r.style.transform=`translateX(${a.left}px) translateY(${a.top}px) translateZ(0)`,r.classList.add("dragging"),this.setCurrentDragger(r),this.addListeners(r,n)}handleDragMove(t){t.preventDefault(),!this.isDisabled&&this.interactionMove(t.clientX,t.clientY)}handleTouchMove(t){t.preventDefault(),!this.isDisabled&&t.targetTouches.length==1&&this.interactionMove(t.touches[0].clientX,t.touches[0].clientY)}interactionMove(t,i){const s=this.currentDragger;this.offsetX=t-this.initialX,this.offsetY=i-this.initialY,this.constrainDraggerToWrapper(s,this.wrapper),s.style.transform=`translateX(${this.startingX+this.offsetX}px) translateY(${this.startingY+this.offsetY}px) translateZ(0) scale(1)`;const n=s.getBoundingClientRect();this.findDraggerItemTarget(s,n,this.targets),this.isItemStartSource||this.findSourceDraggerTarget(s,n)}constrainDraggerToWrapper(t,i){const s=t.getBoundingClientRect(),n=i.getBoundingClientRect(),r=this.startingX+this.offsetX-n.x,a=this.startingY+this.offsetY-n.y,o=this.startingX+s.width+this.offsetX-(n.x+n.width),u=this.startingY+s.height+this.offsetY-(n.y+n.height);r<0&&(this.offsetX=this.offsetX-r),o>0&&(this.offsetX=this.offsetX-o),a<0&&(this.offsetY=this.offsetY-a),u>0&&(this.offsetY=this.offsetY-u)}handleDragEnd(t){this.isDisabled||this.interactionEnd(t.clientX,t.clientY,!1)}handleTouchEnd(t){this.isDisabled||this.interactionEnd(t.changedTouches[0].clientX,t.changedTouches[0].clientY,!0)}interactionEnd(t,i,s){const n=this.currentDragger;if(this.itemTarget===null?n.style.transform=`translateX(${this.startingX}px) translateY(${this.startingY}px) translateZ(0)`:n.style.transform=`translateX(${this.startingX+this.offsetX}px) translateY(${this.startingY+this.offsetY}px) translateZ(0)`,n.removeAttribute("style"),n.classList.remove("dragging"),this.clearTargetHighlights(),this.itemTarget===null){this.resetDraggerToItemStart(this.itemStart,n),this.setCurrentDragger(null),this.removeListeners(n,s);return}if(this.itemTarget.classList.contains("active")){if(this.itemTarget.classList.remove("active"),this.isExceedingMaxAssociations(this.itemStart,this.itemTarget,n)){this.resetDraggerToItemStart(this.itemStart,n),this.notifyAssociationsLimit(),this.setCurrentDragger(null),this.removeListeners(n,s);return}if(this.itemStart.getAttribute("data-identifier")===this.itemTarget.getAttribute("data-identifier")){this.resetDraggerToItemStart(this.itemStart,n),this.setCurrentDragger(null),this.removeListeners(n,s);return}this.removePlaceholder(n),this.setDraggerToItemTarget(this.itemTarget,n),this.itemTarget.classList.contains("source")&&(this.itemTarget.classList.add("full"),this.itemTarget.dataset.matchMax*1>0&&this.incrementRemaining(this.itemTarget),this.decrementAssociationsCount(),this.sortContainerElements(this.sourcewrapper)),this.itemStart.classList.contains("source")&&(this.itemStart.dataset.matchMax*1>0&&this.decrementRemaining(this.itemStart)===0&&this.itemStart.classList.remove("full"),this.incrementAssociationsCount()),this.itemStart.classList.contains("target")&&(this.isTargetFull(this.itemStart)?this.itemStart.classList.add("full"):this.itemStart.classList.remove("full")),this.notifyUpdate()}this.setCurrentDragger(null),this.removeListeners(n,s)}setCurrentDragger(t){this.currentDragger=t}resetDraggerToItemStart(t,i){this.replacePlaceholder(i),t.classList.contains("source")||i.setAttribute("style","width:100%")}setDraggerToItemTarget(t,i){if(t.classList.contains("source")){if(t.classList.contains("full")){const s=t.querySelector(".draggable");s!=null&&t.replaceChild(i,s);return}t.append(i);return}t.append(i),i.setAttribute("style","width:100%"),this.isTargetFull(t)?t.classList.add("full"):t.classList.remove("full")}findDraggerItemTarget(t,i,s){this.itemTarget=null,s.forEach(n=>{const r=n.getBoundingClientRect();if(i.top+t.offsetHeight/2<r.bottom&&i.right-t.offsetWidth/2>r.left&&i.bottom-t.offsetHeight/2>r.top&&i.left+t.offsetWidth/2<r.right){if(this.isItemStartSource&&n.classList.contains("source")||n.classList.contains("full")||!this.hasMatchingMatchGroup(t.parentNode,n))return;n.classList.add("active"),this.itemTarget=n}else n.classList.remove("active")},this)}findSourceDraggerTarget(t,i){const s=this.sourcewrapper.getBoundingClientRect();if(i.top+t.offsetHeight/2<s.bottom&&i.right-t.offsetWidth/2>s.left&&i.bottom-t.offsetHeight/2>s.top&&i.left+t.offsetWidth/2<s.right){for(let n=0;n<this.sources.length;n++)if(this.sources[n].dataset.identifier===t.dataset.identifier){this.sources[n].classList.add("active"),this.itemTarget=this.sources[n];break}}else for(let n=0;n<this.sources.length;n++)this.sources[n].classList.contains("active")&&this.sources[n].classList.remove("active")}addPlaceholder(t){if(!t.parentNode.classList.contains("source")){this.addPlaceholderElement(t,!1);return}const i=t.parentNode.dataset.matchMax*1;if(i===1){this.addPlaceholderElement(t,!1);return}if(i===0){this.addPlaceholderElement(t,!0);return}if(this.getRemaining(t.parentNode)===1){this.addPlaceholderElement(t,!1);return}this.addPlaceholderElement(t,!0)}addPlaceholderElement(t,i){const s=t.cloneNode(!0);this.deepCloneId(s),i?(s.classList.add("clone"),s.addEventListener("mousedown",this.handleDragStart),s.addEventListener("touchstart",this.handleTouchStart)):s.classList.add("gm-dragger-placeholder"),s.classList.add("placeholder-fade"),t.parentNode.insertBefore(s,t)}removePlaceholder(t){if(t.parentNode.classList.contains("target")){const n=t.parentNode.querySelector(".gm-dragger-placeholder");if(n===null)return;t.parentNode.removeChild(n);return}const i=t.parentNode.dataset.matchMax*1,s=t.parentNode.querySelector(".gm-dragger-placeholder");if(s===null){const n=t.parentNode.querySelector(".clone");if(n===null)return;n.classList.remove("placeholder-fade");return}i!==0&&t.parentNode.removeChild(s)}replacePlaceholder(t){const i=t.parentNode;let s=i.querySelector(".gm-dragger-placeholder");if(i.classList.contains("source")){if(s==null&&(s=i.querySelector(".draggable")),s===null)return;i.replaceChild(t,s);return}s!==null&&i.replaceChild(t,s)}addClonePlaceholder(t){const i=t.cloneNode(!0);this.deepCloneId(i),i.classList.add("clone"),t.parentNode.insertBefore(i,t),i.addEventListener("mousedown",this.handleDragStart),i.addEventListener("touchstart",this.handleTouchStart)}initializeSources(t){this.sources=t.querySelectorAll(".source"),this.sources.forEach(i=>{i.classList.add("full");const s=i.dataset.matchMax*1;this.setRemaining(i,s===0?1e3:s)},this),this.draggers=t.querySelectorAll(".draggable"),this.draggers.forEach((i,s)=>{const n=i.parentNode.getAttribute("data-identifier");i.setAttribute("data-identifier",n),i.setAttribute("data-order",s),i.setAttribute("tabindex",0),i.addEventListener("mousedown",this.handleDragStart),i.addEventListener("touchstart",this.handleTouchStart)},this)}initializeTargets(t){this.targets=t.querySelectorAll(".target"),this.targets.forEach(i=>{i.setAttribute("tabindex",0)})}identifyTargets(t,i){this.targets.forEach(s=>{i&&!s.classList.contains("full")&&this.hasMatchingMatchGroup(t,s)&&s.classList.add("target-active")},this),i&&!this.isItemStartSource&&this.sourcewrapper.classList.add("target-active")}addListeners(t,i){i?(this.removeListeners(t,i),t.addEventListener("touchmove",this.handleTouchMove),t.addEventListener("touchend",this.handleTouchEnd)):(this.removeListeners(t,i),document.addEventListener("mousemove",this.handleDragMove),document.addEventListener("mouseup",this.handleDragEnd))}removeListeners(t,i){i?(t.removeEventListener("touchmove",this.handleTouchMove),t.removeEventListener("touchend",this.handleTouchEnd)):(document.removeEventListener("mousemove",this.handleDragMove),document.removeEventListener("mouseup",this.handleDragEnd))}clearTargetHighlights(){this.targets.forEach(t=>{t.classList.remove("target-active")},this),this.sourcewrapper.classList.remove("target-active")}getClosestElement(t,i){return t?t&&t.classList.contains(i)?t:this.getClosestElement(t.parentElement,i):!1}sortContainerElements(t){let i=[],s=t.children;for(let n=0;n<s.length;n++){const r=s[n].querySelector("div.draggable");r&&i.push([1*r.dataset.order,s[n]])}i.sort(function(n,r){return n[0]-r[0]});for(let n=0;n<i.length;n++)t.appendChild(i[n][1])}getResponse(){return this.computeResponse()}computeResponse(){let t=[];return this.targets.forEach(i=>{i.querySelectorAll(".draggable").forEach(s=>{t.push(`${s.dataset.identifier} ${i.dataset.identifier}`)})}),t.length===0?null:this.options.cardinality==="single"?t[0]:t}restoreResponse(t){t!==null&&(this.options.cardinality==="single"?this.restoreResponsePair(t):t.forEach(i=>{this.restoreResponsePair(i)},this))}restoreResponsePair(t){const i=this.getPair(t);if(i===null)return;const s=this.findSourceByIdentifier(i.source),n=this.findTargetGapByIdentifier(i.target);if(s===null||n===null)return;const r=s.querySelector(".draggable");r!==null&&(this.cloneOrEmptySourceDragger(s,r),this.restoreSourceDraggerToTarget(n,r))}cloneOrEmptySourceDragger(t,i){const s=t.dataset.matchMax*1;if(s===1){t.classList.remove("full"),this.decrementRemaining(t);return}if(s===0){this.addClonePlaceholder(i);return}if(this.getRemaining(t)===1){t.classList.remove("full"),this.decrementRemaining(t);return}this.decrementRemaining(t),this.addClonePlaceholder(i)}findSourceByIdentifier(t){for(let i=0;i<this.sources.length;i++)if(t===this.sources[i].dataset.identifier)return this.sources[i];return null}findTargetGapByIdentifier(t){for(let i=0;i<this.targets.length;i++)if(t===this.targets[i].dataset.identifier)return this.targets[i];return null}getPair(t){if(t===null)return null;const i=t.split(" ");return i.length!=2?null:{source:i[0],target:i[1]}}restoreSourceDraggerToTarget(t,i){t===null||i===null||(t.append(i),i.setAttribute("style","width:100%"),this.incrementAssociationsCount(),this.isTargetFull(t)&&t.classList.add("full"))}hasMatchingMatchGroup(t,i){return t===null||i===null?!1:t.dataset.matchGroup===i.dataset.matchGroup}isTargetFull(t){if(t==null)return!1;const i=t.querySelectorAll(".draggable"),s=t.dataset.matchMax*1;return s===0?!1:i.length>=s}isExceedingMaxAssociations(t,i){return!(this.options.maxAssociations===0||i.classList.contains("source")||t.classList.contains("target")||this.currentAssociationsCount<this.options.maxAssociations)}initializeAssociationsCount(){this.currentAssociationsCount=0}incrementAssociationsCount(){this.currentAssociationsCount+=1}decrementAssociationsCount(){this.currentAssociationsCount!==0&&(this.currentAssociationsCount-=1)}getRemaining(t){return t.dataset.remaining*1}setRemaining(t,i){t.setAttribute("data-remaining",i)}incrementRemaining(t){const i=t.dataset.remaining*1+1;return t.setAttribute("data-remaining",i),i}decrementRemaining(t){let i=t.dataset.remaining*1-1;return i=i>=0?i:0,t.setAttribute("data-remaining",i),i}deepCloneId(t){t.id&&(t.id=`clone_${this.qtiAttributeValidation.randomString(5,"a")}`);for(let i=0;i<t.children.length;i++)this.deepCloneId(t.children[i])}reset(){this.resetDraggersToSources(),this.initializeAssociationsCount(),this.destroy()}resetDraggersToSources(){this.targets.forEach(t=>{t.querySelectorAll(".draggable").forEach(s=>{const n=this.findSourceByIdentifier(s.getAttribute("data-identifier"));n.classList.contains("full")||(t.classList.remove("full"),n.classList.contains("full")?t.removeChild(s):(n.append(s),n.classList.add("full")))},this)},this)}destroy(){this.currentDragger!==null&&(document.removeEventListener("mousemove",this.handleDragMove),document.removeEventListener("mouseup",this.handleDragEnd)),this.wrapper.querySelectorAll(".draggable").forEach(i=>{i.removeEventListener("touchstart",this.handleTouchStart),i.removeEventListener("touchmove",this.handleTouchMove),i.removeEventListener("touchend",this.handleTouchEnd),i.removeEventListener("mousedown",this.handleDragStart)},this)}}const uq=new G,hq=new ie,dq={emits:["gapMatchGroupReady","gapMatchGroupUpdate","gapMatchGroupAssociationsLimit"],props:{responseIdentifier:{required:!0,type:String},cardinality:{required:!0,type:String},shuffle:{required:!1,type:String,default:"false"},maxAssociations:{required:!1,type:String,default:"1"},minAssociations:{required:!1,type:String,default:"0"},dataChoicesContainerWidth:{required:!1,type:String,default:null},interactionSubType:{required:!1,type:String,default:"default"},gapMatchInteractionStaticClass:{required:!0,type:String},priorState:{required:!1,type:Object,default:null}},data(){return{choices:[],order:[],gaps:[],response:null,isShuffle:null,hasPrompt:!1,gapMatchInteractionClassAttribute:null,presentationFactory:null,matchable:null,isQtiValid:!0}},computed:{computedMaxAssociations(){return this.maxAssociations*1}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},disable(){this.matchable!==null&&this.matchable.toggleDisable(!0)},enable(){this.matchable!==null&&this.matchable.toggleDisable(!1)},getChoices(){return this.choices},setIsShuffle(e){this.isShuffle=e},validateChildren(){let e=0;this.$slots.default()[0].children.forEach(t=>{if(uq.isValidSlot(t)){if(t.type.name==="QtiPrompt"){if(e>0)throw new c("Invalid element order. qti-prompt must come before qti-gap-text's, qti-gap-img's, or qti-gap's");if(!this.hasPrompt)return this.hasPrompt=!0;throw new c("Maximum of 1 qti-prompt element permitted")}if(t.type.name==="QtiGapText"||t.type.name==="QtiGapImg")return e+=1;throw new c('Node is not one of qti-gap-text or qti-gap-img: "'+t.type.name+'"')}})},processChildren(){this.$.subTree.children[0].children[0].children.forEach(i=>{i.component!==null&&(i.type.name==="QtiGapText"||i.type.name==="QtiGapImg")&&this.choices.push(i.component.proxy)}),this.$refs.root.querySelectorAll(".gap-match-gap").forEach(i=>{this.gaps.push(i)})},insertAfter(e,t){t.parentNode.insertBefore(e,t.nextSibling)},processGroupUI(e){let t=this.createGapChoiceWrapper();if(t==null)return;let i=this.createContainer(this.priorState);this.processContainerChoices(i,t),this.saveContainerOrder(i);let s=this.createGapTargetWrapper(t);this.presentationFactory.initialize(this.$refs.root,t,s,this.dataChoicesContainerWidth,this.choices,this.gaps),this.matchable=new cq(this.$refs.root,{interactionSubType:this.interactionSubType,cardinality:this.cardinality,maxAssociations:this.computedMaxAssociations,response:e,onReady:this.handleWidgetReady,onUpdate:this.handleWidgetUpdate,onAssociationsLimit:this.handleAssociationsLimit})},createGapChoiceWrapper(){let e=this.$refs.root.querySelector(".qti-gap-choice");if(e===null)return null;let t=document.createElement("ul");return t.classList.add("qti-gap-match-source-wrapper"),this.$refs.root.insertBefore(t,e),t},createGapTargetWrapper(e){const t=document.createElement("div");t.classList.add("qti-gap-match-target-wrapper"),this.insertAfter(t,e);const i=t.nextElementSibling;return i!=null&&t.append(i),t},createContainer(e){let t=[];return e===null?(this.choices.forEach(s=>{t.push({fixed:s.fixed==="true",node:s})}),this.isShuffle&&hq.shuffleArrayFixed(t),t):(e.state.order.forEach(s=>{const n=this.findChoiceByIdentifier(s,this.choices);n!==null&&t.push({fixed:n.fixed==="true",node:n})},this),t)},processContainerChoices(e,t){this.choices.splice(0,this.choices.length),t.innerHTML="",e.forEach(i=>{t.appendChild(i.node.$el),this.choices.push(i.node)},this)},saveContainerOrder(e){const t=[];e.forEach(i=>{t.push(i.node.identifier)}),this.order=t},findChoiceByIdentifier(e,t){for(let i=0;i<t.length;i++)if(t[i].$el.getAttribute("data-identifier")===e)return t[i];throw new O('Gap Match Interaction State Invalid. Choice identifier "'+e+'" not found.')},resetGroupUI(){this.processGroupUI(null)},handleWidgetReady(e){this.setResponse(e.response),this.$emit("gapMatchGroupReady",{response:this.getResponse(),order:this.order})},handleWidgetUpdate(e){this.setResponse(e.response),this.$emit("gapMatchGroupUpdate",{response:this.getResponse()})},handleAssociationsLimit(){this.$emit("gapMatchGroupAssociationsLimit")},initializeGapMatchGroup(){this.presentationFactory=new lq(this.gapMatchInteractionStaticClass)}},created(){try{if(typeof this.cardinality>"u")throw new c("Undefined qti-gap-match-interaction cardinality");if(this.cardinality!=="single"&&this.cardinality!=="multiple")throw new c('qti-gap-match-interaction cardinality must be "single" or "multiple"');this.setIsShuffle(this.shuffle==="true"),this.initializeGapMatchGroup(),this.validateChildren()}catch(e){throw this.isQtiValid=!1,console.log("[QtiGapMatchInteraction][ValidationError]",e.name,e.message),new c(e.message)}},mounted(){if(this.isQtiValid)try{this.processChildren(),this.processGroupUI(this.priorState===null?null:this.priorState.value)}catch(e){if(this.isQtiValid=!1,e.name==="QtiValidationException")throw console.log("[QtiGapMatchInteraction][ValidationException]",e.message),new c(e.message);if(e.name==="QtiEvaluationException")throw console.log("[QtiGapMatchInteraction][EvaluationException]",e.message),new O(e.message)}},beforeUnmount(){this.matchable!==null&&(this.matchable.destroy(),this.matchable=null)}},fq={ref:"root",class:"qti-gap-match-group-wrapper"};function pq(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",fq,[l.renderSlot(e.$slots,"default")],512)}const mq=P(dq,[["render",pq]]);class gq{constructor(t){this.constants={QTI_SELECTIONS_LIGHT:"qti-selections-light",QTI_SELECTIONS_DARK:"qti-selections-dark",QTI_UNSELECTED_HIDDEN:"qti-unselected-hidden",QTI_CHOICES_TOP:"qti-choices-top",QTI_CHOICES_BOTTOM:"qti-choices-bottom",QTI_CHOICES_LEFT:"qti-choices-left",QTI_CHOICES_RIGHT:"qti-choices-right",DATA_MAX_SELECTIONS_MESSAGE:"data-max-selections-message",DATA_MIN_SELECTIONS_MESSAGE:"data-min-selections-message",DATA_CHOICES_CONTAINER_WIDTH:null},this.parentClass=t,this.clazzTokens=[],this.ggmGroupElement=null,this.ggmChoiceWrapperElement=null,this.ggmTargetWrapperElement=null,this.image=null,this.choicesContainerWidth=null,this.gapChoices=[],this.gaps=[],this.presentation_Choices_Orientation=null,this.presentation_Theme=this.constants.QTI_SELECTIONS_DARK,this.presentation_UnselectedHidden=!1,this.presentation_MaxSelectionsMessage="",this.presentation_MinSelectionsMessage=""}initialize(t,i,s,n,r,a,o){this.ggmGroupElement=t,this.ggmChoiceWrapperElement=i,this.ggmTargetWrapperElement=s,this.image=n,this.choicesContainerWidth=r,this.gapChoices=a,this.gaps=o,this.processRootClassAttribute(this.parentClass),this.processPresentation()}processRootClassAttribute(t){const i=t.split(" ");for(let s=0;s<i.length;s++)switch(i[s]){case this.constants.QTI_CHOICES_TOP:case this.constants.QTI_CHOICES_BOTTOM:case this.constants.QTI_CHOICES_LEFT:case this.constants.QTI_CHOICES_RIGHT:this.presentation_Choices_Orientation=i[s];break;case this.constants.QTI_SELECTIONS_DARK:case this.constants.QTI_SELECTIONS_LIGHT:this.presentation_Theme=i[s];break;case this.constants.QTI_UNSELECTED_HIDDEN:this.presentation_UnselectedHidden=!0;break}this.clazzTokens=i}processPresentation(){this.presentation_Choices_Orientation===null&&(this.presentation_Choices_Orientation=this.constants.QTI_CHOICES_TOP),this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_LEFT?(this.ggmChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_LEFT),this.ggmTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_LEFT),this.ggmGroupElement.classList.add(this.constants.QTI_CHOICES_LEFT)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_TOP?(this.ggmChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_TOP),this.ggmTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_TOP)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_RIGHT?(this.ggmChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_RIGHT),this.ggmTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_RIGHT),this.ggmGroupElement.classList.add(this.constants.QTI_CHOICES_RIGHT),this.ggmGroupElement.insertBefore(this.ggmTargetWrapperElement,this.ggmChoiceWrapperElement)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_BOTTOM&&(this.ggmChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_BOTTOM),this.ggmTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_BOTTOM),this.ggmGroupElement.insertBefore(this.ggmTargetWrapperElement,this.ggmChoiceWrapperElement)),this.processBackgroundImage(),this.processChoicesContainerWidth(),this.processGaps()}processBackgroundImage(){if(this.image===null)return;this.image.setAttribute("draggable","false");const t=this.image.getBoundingClientRect();this.ggmTargetWrapperElement.style.width=`${t.width}px`,this.ggmTargetWrapperElement.style.height=`${t.height}px`}processChoicesContainerWidth(){this.choicesContainerWidth!==null&&(this.ggmChoiceWrapperElement.style.width=`${this.choicesContainerWidth}px`,this.ggmChoiceWrapperElement.style.textAlign="center")}processGaps(){for(let t=0;t<this.gaps.length;t++){const i=this.gaps[t];this.setGapStyle(i,i.getShape(),i.getShapeData()),this.gaps[t].$refs.gap.classList.add("target",this.presentation_Theme),this.presentation_UnselectedHidden&&this.gaps[t].$refs.gap.classList.add(this.constants.QTI_UNSELECTED_HIDDEN)}}setGapStyle(t,i,s){switch(i){case"rect":t.$refs.gap.style.left=`${s[0]}px`,t.$refs.gap.style.top=`${s[1]}px`,t.$refs.gap.style.width=`${s[2]}px`,t.$refs.gap.style.height=`${s[3]}px`;break}}}class yq{constructor(t,i){J(this,"options",{interactionSubType:"default",cardinality:"multiple",maxAssociations:0,response:null,onReady:null,onUpdate:null,onSelectionsLimit:null,zindex:1e3});return this.qtiAttributeValidation=new G,this.wrapper=t,this.sourcewrapper=this.wrapper.querySelector(".qti-ggm-source-wrapper"),this.targetwrapper=this.wrapper.querySelector(".qti-ggm-target-wrapper"),this.processOptions(i),this.handleDragStart=this.handleDragStart.bind(this),this.handleDragMove=this.handleDragMove.bind(this),this.handleDragEnd=this.handleDragEnd.bind(this),this.handleTouchStart=this.handleTouchStart.bind(this),this.handleTouchMove=this.handleTouchMove.bind(this),this.handleTouchEnd=this.handleTouchEnd.bind(this),this.itemTarget=null,this.itemStart=null,this.isItemStartSource=!0,this.savedGapZindex="",this.initialX=0,this.initialY=0,this.offsetX=0,this.offsetY=0,this.startingX=0,this.startingY=0,this.currentAssociationsCount=0,this.isDisabled=!1,this.currentDragger=null,this.initializeSources(this.sourcewrapper),this.initializeTargets(this.targetwrapper),this.restoreResponse(this.options.response),this.notifyReady(),this}processOptions(t){"interactionSubType"in t&&(this.options.interactionSubType=t.interactionSubType),"cardinality"in t&&(this.options.cardinality=t.cardinality),"response"in t&&(this.options.response=t.response),"maxAssociations"in t&&(this.options.maxAssociations=t.maxAssociations),"onReady"in t&&(this.options.onReady=t.onReady),"onUpdate"in t&&(this.options.onUpdate=t.onUpdate),"onAssociationsLimit"in t&&(this.options.onAssociationsLimit=t.onAssociationsLimit)}notifyReady(){this.options.onReady!==null&&this.options.onReady({response:this.getResponse()})}notifyUpdate(){this.options.onUpdate!==null&&this.options.onUpdate({response:this.computeResponse()})}notifyAssociationsLimit(){this.options.onAssociationsLimit!==null&&this.options.onAssociationsLimit()}toggleDisable(t){this.isDisabled=t,this.draggers.forEach(i=>{t?i.classList.add("disabled"):i.classList.remove("disabled")})}handleDragStart(t){if(t.preventDefault(),!this.isDisabled&&t.button==0)return this.interactionStart(t.target,t.clientX,t.clientY,!1),!1}handleTouchStart(t){if(t.preventDefault(),!this.isDisabled)return t.targetTouches.length!=1||this.interactionStart(t.target,t.touches[0].pageX,t.touches[0].pageY,!0),!1}interactionStart(t,i,s,n){const r=this.getClosestElement(t,"draggable");this.itemStart=r.parentNode,this.isItemStartSource=this.itemStart.classList.contains("source"),this.isItemStartSource||this.saveGapZindex(this.itemStart),this.identifyTargets(this.itemStart,!0),this.itemTarget=null;const a=r.getBoundingClientRect();this.initialX=i,this.initialY=s,this.startingX=a.left,this.startingY=a.top,this.offsetX=i-this.startingX,this.offsetY=s-this.startingY,this.addPlaceholder(r),r.classList.add("dragging"),r.style.userSelect="none",r.style.width=a.width+"px",r.style.height=a.height+"px",r.style.transform=`translateX(${a.left}px) translateY(${a.top}px) translateZ(0)`,this.setCurrentDragger(r),this.addListeners(r,n)}handleDragMove(t){t.preventDefault(),!this.isDisabled&&this.interactionMove(t.clientX,t.clientY)}handleTouchMove(t){t.preventDefault(),!this.isDisabled&&t.targetTouches.length==1&&this.interactionMove(t.touches[0].clientX,t.touches[0].clientY)}interactionMove(t,i){const s=this.currentDragger;this.offsetX=t-this.initialX,this.offsetY=i-this.initialY,this.constrainDraggerToWrapper(s,this.wrapper),s.style.transform=`translateX(${this.startingX+this.offsetX}px) translateY(${this.startingY+this.offsetY}px) translateZ(0) scale(1)`;const n=s.getBoundingClientRect();this.findDraggerItemTarget(s,n,this.targets),this.isItemStartSource||this.findSourceDraggerTarget(s,n)}constrainDraggerToWrapper(t,i){const s=t.getBoundingClientRect(),n=i.getBoundingClientRect(),r=this.startingX+this.offsetX-n.x,a=this.startingY+this.offsetY-n.y,o=this.startingX+s.width+this.offsetX-(n.x+n.width),u=this.startingY+s.height+this.offsetY-(n.y+n.height);r<0&&(this.offsetX=this.offsetX-r),o>0&&(this.offsetX=this.offsetX-o),a<0&&(this.offsetY=this.offsetY-a),u>0&&(this.offsetY=this.offsetY-u)}handleDragEnd(t){this.isDisabled||this.interactionEnd(t.clientX,t.clientY,!1)}handleTouchEnd(t){this.isDisabled||this.interactionEnd(t.changedTouches[0].clientX,t.changedTouches[0].clientY,!0)}interactionEnd(t,i,s){const n=this.currentDragger;if(this.itemTarget===null?n.style.transform=`translateX(${this.startingX}px) translateY(${this.startingY}px) translateZ(0)`:n.style.transform=`translateX(${this.startingX+this.offsetX}px) translateY(${this.startingY+this.offsetY}px) translateZ(0)`,n.removeAttribute("style"),n.classList.remove("dragging"),this.clearTargetHighlights(),this.itemTarget===null){this.resetDraggerToItemStart(this.itemStart,n),this.setCurrentDragger(null),this.removeListeners(n,s);return}if(this.itemTarget.classList.contains("active")){if(this.itemTarget.classList.remove("active"),this.isExceedingMaxAssociations(this.itemStart,this.itemTarget,n)){this.resetDraggerToItemStart(this.itemStart,n),this.notifyAssociationsLimit(),this.setCurrentDragger(null),this.removeListeners(n,s);return}if(this.itemStart.getAttribute("data-identifier")===this.itemTarget.getAttribute("data-identifier")){this.resetDraggerToItemStart(this.itemStart,n),this.setCurrentDragger(null),this.removeListeners(n,s);return}this.removePlaceholder(n),this.setDraggerToItemTarget(this.itemTarget,n),this.itemTarget.classList.contains("source")&&(this.itemTarget.classList.add("full"),this.itemTarget.dataset.matchMax*1>0&&this.incrementRemaining(this.itemTarget),this.decrementAssociationsCount(),this.sortContainerElements(this.sourcewrapper)),this.itemStart.classList.contains("source")&&(this.itemStart.dataset.matchMax*1>0&&this.decrementRemaining(this.itemStart)===0&&this.itemStart.classList.remove("full"),this.incrementAssociationsCount()),this.itemStart.classList.contains("target")&&(this.restoreGapZindex(this.itemStart),this.isTargetFull(this.itemStart)?this.itemStart.classList.add("full","contains-choice"):(this.itemStart.classList.remove("full"),this.containsChoices(this.itemStart)?this.itemStart.classList.add("contains-choice"):this.itemStart.classList.remove("contains-choice"))),this.notifyUpdate()}this.setCurrentDragger(null),this.removeListeners(n,s)}setCurrentDragger(t){this.currentDragger=t}resetDraggerToItemStart(t,i){t.classList.contains("target")&&this.restoreGapZindex(t),this.replacePlaceholder(i)}setDraggerToItemTarget(t,i){if(t.classList.contains("source")){this.appendDraggerToSourceTarget(t,i);return}this.appendDraggerToGapTarget(t,i),this.isTargetFull(t)?t.classList.add("full"):t.classList.remove("full")}appendDraggerToSourceTarget(t,i){if(t.classList.contains("full")){const s=t.querySelector(".draggable");s!=null&&t.replaceChild(i,s);return}t.append(i)}appendDraggerToGapTarget(t,i){t.classList.add("contains-choice"),t.append(i)}findDraggerItemTarget(t,i,s){this.itemTarget=null,s.forEach(n=>{const r=n.getBoundingClientRect();if(i.top+t.offsetHeight/2<r.bottom&&i.right-t.offsetWidth/2>r.left&&i.bottom-t.offsetHeight/2>r.top&&i.left+t.offsetWidth/2<r.right){if(this.isItemStartSource&&n.classList.contains("source")||n.classList.contains("full")||!this.hasMatchingMatchGroup(t.parentNode,n))return;n.classList.add("active"),this.itemTarget=n}else n.classList.remove("active")},this)}findSourceDraggerTarget(t,i){const s=this.sourcewrapper.getBoundingClientRect();if(i.top+t.offsetHeight/2<s.bottom&&i.right-t.offsetWidth/2>s.left&&i.bottom-t.offsetHeight/2>s.top&&i.left+t.offsetWidth/2<s.right){for(let n=0;n<this.sources.length;n++)if(this.sources[n].dataset.identifier===t.dataset.identifier){this.sources[n].classList.add("active"),this.itemTarget=this.sources[n];break}}else for(let n=0;n<this.sources.length;n++)this.sources[n].classList.contains("active")&&this.sources[n].classList.remove("active")}addPlaceholder(t){if(!t.parentNode.classList.contains("source")){this.addPlaceholderElement(t,!1);return}const i=t.parentNode.dataset.matchMax*1;if(i===1){this.addPlaceholderElement(t,!1);return}if(i===0){this.addPlaceholderElement(t,!0);return}if(this.getRemaining(t.parentNode)===1){this.addPlaceholderElement(t,!1);return}this.addPlaceholderElement(t,!0)}addPlaceholderElement(t,i){const s=t.cloneNode(!0);this.deepCloneId(s),i?(s.classList.add("clone"),s.addEventListener("mousedown",this.handleDragStart),s.addEventListener("touchstart",this.handleTouchStart)):s.classList.add("ggm-dragger-placeholder"),s.classList.add("placeholder-fade"),t.parentNode.insertBefore(s,t)}removePlaceholder(t){if(t.parentNode.classList.contains("target")){const n=t.parentNode.querySelector(".ggm-dragger-placeholder");if(n===null)return;t.parentNode.removeChild(n);return}const i=t.parentNode.dataset.matchMax*1,s=t.parentNode.querySelector(".ggm-dragger-placeholder");if(s===null){const n=t.parentNode.querySelector(".clone");if(n===null)return;n.classList.remove("placeholder-fade");return}i!==0&&t.parentNode.removeChild(s)}replacePlaceholder(t){const i=t.parentNode;let s=i.querySelector(".ggm-dragger-placeholder");if(i.classList.contains("source")){if(s==null&&(s=i.querySelector(".draggable")),s===null)return;i.replaceChild(t,s);return}s!==null&&i.replaceChild(t,s)}addClonePlaceholder(t){const i=t.cloneNode(!0);this.deepCloneId(i),i.classList.add("clone"),t.parentNode.insertBefore(i,t),i.addEventListener("mousedown",this.handleDragStart),i.addEventListener("touchstart",this.handleTouchStart)}initializeSources(t){this.sources=t.querySelectorAll(".source"),this.sources.forEach(i=>{i.classList.add("full");const s=i.dataset.matchMax*1;this.setRemaining(i,s===0?1e3:s)},this),this.draggers=t.querySelectorAll(".draggable"),this.draggers.forEach((i,s)=>{const n=i.parentNode.getAttribute("data-identifier");i.setAttribute("data-identifier",n),i.setAttribute("data-order",s),i.setAttribute("tabindex",0),i.addEventListener("mousedown",this.handleDragStart),i.addEventListener("touchstart",this.handleTouchStart)},this)}initializeTargets(t){this.targets=t.querySelectorAll(".target"),this.targets.forEach(i=>{i.setAttribute("tabindex",0)})}identifyTargets(t,i){this.targets.forEach(s=>{i&&!s.classList.contains("full")&&this.hasMatchingMatchGroup(t,s)&&s.classList.add("target-active")},this),i&&!this.isItemStartSource&&this.sourcewrapper.classList.add("target-active")}addListeners(t,i){i?(this.removeListeners(t,i),t.addEventListener("touchmove",this.handleTouchMove),t.addEventListener("touchend",this.handleTouchEnd)):(this.removeListeners(t,i),document.addEventListener("mousemove",this.handleDragMove),document.addEventListener("mouseup",this.handleDragEnd))}removeListeners(t,i){i?(t.removeEventListener("touchmove",this.handleTouchMove),t.removeEventListener("touchend",this.handleTouchEnd)):(document.removeEventListener("mousemove",this.handleDragMove),document.removeEventListener("mouseup",this.handleDragEnd))}clearTargetHighlights(){this.targets.forEach(t=>{t.classList.remove("target-active")},this),this.sourcewrapper.classList.remove("target-active")}getClosestElement(t,i){return t?t&&t.classList.contains(i)?t:this.getClosestElement(t.parentElement,i):!1}sortContainerElements(t){let i=[],s=t.children;for(let n=0;n<s.length;n++){const r=s[n].querySelector("div.draggable");r&&i.push([1*r.dataset.order,s[n]])}i.sort(function(n,r){return n[0]-r[0]});for(let n=0;n<i.length;n++)t.appendChild(i[n][1])}saveGapZindex(t){this.savedGapZindex=t.style.zIndex,t.style.zIndex=this.options.zindex}restoreGapZindex(t){t.style.zIndex=this.savedGapZindex}getResponse(){return this.computeResponse()}computeResponse(){let t=[];return this.targets.forEach(i=>{i.querySelectorAll(".draggable").forEach(s=>{t.push(`${s.dataset.identifier} ${i.dataset.identifier}`)})}),t.length===0?null:this.options.cardinality==="single"?t[0]:t}restoreResponse(t){t!==null&&(this.options.cardinality==="single"?this.restoreResponsePair(t):t.forEach(i=>{this.restoreResponsePair(i)},this))}restoreResponsePair(t){const i=this.getPair(t);if(i===null)return;const s=this.findSourceByIdentifier(i.source),n=this.findTargetGapByIdentifier(i.target);if(s===null||n===null)return;const r=s.querySelector(".draggable");r!==null&&(this.cloneOrEmptySourceDragger(s,r),this.restoreSourceDraggerToTarget(n,r))}cloneOrEmptySourceDragger(t,i){const s=t.dataset.matchMax*1;if(s===1){t.classList.remove("full"),this.decrementRemaining(t);return}if(s===0){this.addClonePlaceholder(i);return}if(this.getRemaining(t)===1){t.classList.remove("full"),this.decrementRemaining(t);return}this.decrementRemaining(t),this.addClonePlaceholder(i)}findSourceByIdentifier(t){for(let i=0;i<this.sources.length;i++)if(t===this.sources[i].dataset.identifier)return this.sources[i];return null}findTargetGapByIdentifier(t){for(let i=0;i<this.targets.length;i++)if(t===this.targets[i].dataset.identifier)return this.targets[i];return null}getPair(t){if(t===null)return null;const i=t.split(" ");return i.length!=2?null:{source:i[0],target:i[1]}}restoreSourceDraggerToTarget(t,i){t===null||i===null||(this.appendDraggerToGapTarget(t,i),this.incrementAssociationsCount(),this.isTargetFull(t)&&t.classList.add("full"))}hasMatchingMatchGroup(t,i){return t===null||i===null?!1:t.dataset.matchGroup===i.dataset.matchGroup}isTargetFull(t){if(t==null)return!1;const i=t.querySelectorAll(".draggable"),s=t.dataset.matchMax*1;return s===0?!1:i.length>=s}containsChoices(t){return t==null?!1:t.querySelectorAll(".draggable").length!==0}isExceedingMaxAssociations(t,i){return!(this.options.maxAssociations===0||i.classList.contains("source")||t.classList.contains("target")||this.currentAssociationsCount<this.options.maxAssociations)}initializeAssociationsCount(){this.currentAssociationsCount=0}incrementAssociationsCount(){this.currentAssociationsCount+=1}decrementAssociationsCount(){this.currentAssociationsCount!==0&&(this.currentAssociationsCount-=1)}getRemaining(t){return t.dataset.remaining*1}setRemaining(t,i){t.setAttribute("data-remaining",i)}incrementRemaining(t){const i=t.dataset.remaining*1+1;return t.setAttribute("data-remaining",i),i}decrementRemaining(t){let i=t.dataset.remaining*1-1;return i=i>=0?i:0,t.setAttribute("data-remaining",i),i}deepCloneId(t){t.id&&(t.id=`clone_${this.qtiAttributeValidation.randomString(5,"a")}`);for(let i=0;i<t.children.length;i++)this.deepCloneId(t.children[i])}reset(){this.resetDraggersToSources(),this.initializeAssociationsCount(),this.destroy()}resetDraggersToSources(){this.targets.forEach(t=>{t.querySelectorAll(".draggable").forEach(s=>{const n=this.findSourceByIdentifier(s.getAttribute("data-identifier"));n.classList.contains("full")||(n.classList.contains("full")?t.removeChild(s):(n.append(s),n.classList.add("full")))},this),t.classList.remove("full","contains-choice")},this)}destroy(){this.currentDragger!==null&&(document.removeEventListener("mousemove",this.handleDragMove),document.removeEventListener("mouseup",this.handleDragEnd)),this.wrapper.querySelectorAll(".draggable").forEach(i=>{i.removeEventListener("touchstart",this.handleTouchStart),i.removeEventListener("touchmove",this.handleTouchMove),i.removeEventListener("touchend",this.handleTouchEnd),i.removeEventListener("mousedown",this.handleDragStart)},this)}}const wq=new G,bq=new ie,vq={emits:["ggmGroupReady","ggmGroupUpdate","ggmGroupAssociationsLimit"],props:{responseIdentifier:{required:!0,type:String},cardinality:{required:!0,type:String},shuffle:{required:!1,type:String,default:"false"},maxAssociations:{required:!1,type:String,default:"1"},minAssociations:{required:!1,type:String,default:"0"},dataChoicesContainerWidth:{required:!1,type:String,default:null},interactionSubType:{required:!1,type:String,default:"default"},interactionStaticClass:{required:!0,type:String},priorState:{required:!1,type:Object,default:null}},data(){return{image:null,choices:[],order:[],gaps:[],response:null,isShuffle:null,hasPrompt:!1,interactionClassAttribute:null,presentationFactory:null,matchable:null,isQtiValid:!0}},computed:{computedMaxAssociations(){return this.maxAssociations*1}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},disable(){this.matchable!==null&&this.matchable.toggleDisable(!0)},enable(){this.matchable!==null&&this.matchable.toggleDisable(!1)},getChoices(){return this.choices},setIsShuffle(e){this.isShuffle=e},validateChildren(){let e=0,t=0,i=!1;this.$slots.default()[0].children.forEach(s=>{if(wq.isValidSlot(s)){if(s.type.name==="QtiPrompt"){if(e>0||t>0||i)throw new c("Invalid element order. qti-prompt must come before the background image, qti-gap-text's, qti-gap-img's, or qti-associable-hotspot's");if(!this.hasPrompt)return this.hasPrompt=!0;throw new c("Maximum of 1 qti-prompt element permitted")}if(s.type.name==="QtiGapText"||s.type.name==="QtiGapImg"){if(t>0)throw new c("Invalid element order. qti-gap-text's and qti-gap-img's must come before qti-associable-hotspot's");return e+=1}if(s.type.name==="QtiAssociableHotspot")return t+=1;throw new c('Node is not one of qti-gap-text, qti-gap-img, or qti-associable-hotspot: "'+s.type.name+'"')}else if(s.type==="img"||s.type==="object"||s.type==="picture"){if(e>0||t>0)throw new c("Invalid element order. Background image must preceed qti-gap-text's, qti-gap-img's and qti-associable-hotspot's");i=!0}})},processChildren(){this.$.subTree.children[0].children[0].children.forEach(t=>{if(t.type==="img"||t.type==="object"||t.type==="picture"){this.image=t.el;return}t.component!==null&&(t.type.name==="QtiGapText"||t.type.name==="QtiGapImg"?this.choices.push(t.component.proxy):t.type.name==="QtiAssociableHotspot"&&this.gaps.push(t.component.proxy))})},insertAfter(e,t){t.parentNode.insertBefore(e,t.nextSibling)},processGroupUI(e){let t=this.createGapChoiceWrapper();if(t==null)return;let i=this.createGapTargetWrapper(),s=this.createContainer(this.priorState);this.processContainerChoices(s,t),this.saveContainerOrder(s),this.presentationFactory.initialize(this.$refs.root,t,i,this.image,this.dataChoicesContainerWidth,this.choices,this.gaps),this.matchable=new yq(this.$refs.root,{interactionSubType:this.interactionSubType,cardinality:this.cardinality,maxAssociations:this.computedMaxAssociations,response:e,onReady:this.handleWidgetReady,onUpdate:this.handleWidgetUpdate,onAssociationsLimit:this.handleAssociationsLimit})},createGapChoiceWrapper(){let e=this.$refs.root.querySelector(".qti-gap-choice");if(e===null)return null;let t=document.createElement("ul");return t.classList.add("qti-ggm-source-wrapper"),this.$refs.root.insertBefore(t,e),t},createGapTargetWrapper(){let e=document.createElement("div");e.classList.add("qti-ggm-target-wrapper"),e.append(this.image);for(let t=0;t<this.gaps.length;t++)e.append(this.gaps[t].$el);return this.$refs.root.append(e),e},createContainer(e){let t=[];return e===null?(this.choices.forEach(s=>{t.push({fixed:s.fixed==="true",node:s})}),this.isShuffle&&bq.shuffleArrayFixed(t),t):(e.state.order.forEach(s=>{const n=this.findChoiceByIdentifier(s,this.choices);n!==null&&t.push({fixed:n.fixed==="true",node:n})},this),t)},processContainerChoices(e,t){this.choices.splice(0,this.choices.length),t.innerHTML="",e.forEach(i=>{t.appendChild(i.node.$el),this.choices.push(i.node)},this)},saveContainerOrder(e){const t=[];e.forEach(i=>{t.push(i.node.identifier)}),this.order=t},findChoiceByIdentifier(e,t){for(let i=0;i<t.length;i++)if(t[i].$el.getAttribute("data-identifier")===e)return t[i];throw new O('Gap Match Interaction State Invalid. Choice identifier "'+e+'" not found.')},resetGroupUI(){this.processGroupUI(null)},handleWidgetReady(e){this.setResponse(e.response),this.$emit("ggmGroupReady",{response:this.getResponse(),order:this.order})},handleWidgetUpdate(e){this.setResponse(e.response),this.$emit("ggmGroupUpdate",{response:this.getResponse()})},handleAssociationsLimit(){this.$emit("ggmGroupAssociationsLimit")},initializeGraphicGapMatchGroup(){this.presentationFactory=new gq(this.interactionStaticClass)}},created(){try{if(typeof this.cardinality>"u")throw new c("Undefined qti-graphic-gap-match-interaction cardinality");if(this.cardinality!=="multiple")throw new c('qti-graphic-gap-match-interaction cardinality must be "multiple"');this.setIsShuffle(this.shuffle==="true"),this.initializeGraphicGapMatchGroup(),this.validateChildren()}catch(e){throw this.isQtiValid=!1,console.log("[QtiGapMatchInteraction][ValidationError]",e.name,e.message),new c(e.message)}},mounted(){if(this.isQtiValid)try{this.processChildren(),this.processGroupUI(this.priorState===null?null:this.priorState.value)}catch(e){if(this.isQtiValid=!1,e.name==="QtiValidationException")throw console.log("[QtiGapMatchInteraction][ValidationException]",e.message),new c(e.message);if(e.name==="QtiEvaluationException")throw console.log("[QtiGapMatchInteraction][EvaluationException]",e.message),new O(e.message)}},beforeUnmount(){this.matchable!==null&&(this.matchable.destroy(),this.matchable=null)}},Eq={ref:"root",class:"qti-ggm-group-wrapper"};function Cq(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",Eq,[l.renderSlot(e.$slots,"default")],512)}const Tq=P(vq,[["render",Cq]]);class Sq{constructor(){this.constants={QTI_CHOICES_TOP:"qti-choices-top",QTI_CHOICES_BOTTOM:"qti-choices-bottom",QTI_CHOICES_LEFT:"qti-choices-left",QTI_CHOICES_RIGHT:"qti-choices-right",QTI_MATCH_TABULAR:"qti-match-tabular",QTI_HEADER_HIDDEN:"qti-header-hidden",ROW_CENTRIC:"row-centric",DATA_MAX_SELECTIONS_MESSAGE:"data-max-selections-message",DATA_MIN_SELECTIONS_MESSAGE:"data-min-selections-message",DATA_FIRST_COLUMN_HEADER:""},this.interactionSubType="default",this.parentClass="",this.clazzTokens=[],this.matchWrapperElement=null,this.matchGroupNode=null,this.matchSetNode1=null,this.matchSetNode2=null,this.choices1=[],this.choices2=[],this.presentation_Choices_Orientation=null,this.presentation_Header_Hidden=!1,this.presentation_Row_Centric=!1,this.presentation_MaxSelectionsMessage="",this.presentation_MinSelectionsMessage=""}initialize(t,i,s,n,r){this.interactionSubType=t,this.matchWrapperElement=i,this.matchGroupNode=s,this.parentClass=s.matchInteractionStaticClass,this.matchSetNode1=n,this.matchSetNode2=r,this.choices1=this.matchSetNode1.getChoices(),this.choices2=this.matchSetNode2.getChoices(),this.processRootClassAttribute(this.parentClass),this.processPresentation()}processRootClassAttribute(t){const i=t.split(" ");for(let s=0;s<i.length;s++)switch(i[s]){case this.constants.QTI_CHOICES_TOP:case this.constants.QTI_CHOICES_BOTTOM:case this.constants.QTI_CHOICES_LEFT:case this.constants.QTI_CHOICES_RIGHT:this.presentation_Choices_Orientation=i[s];break;case this.constants.QTI_MATCH_TABULAR:break;case this.constants.QTI_HEADER_HIDDEN:this.presentation_Header_Hidden=!0;break;case this.constants.ROW_CENTRIC:this.presentation_Row_Centric=!0;break}this.clazzTokens=i}processPresentation(){this.matchSetNode1.$refs.matchset.classList.add("qti-match-source-wrapper"),this.matchSetNode2.$refs.matchset.classList.add("qti-match-target-wrapper"),this.interactionSubType==="default"?(this.presentation_Choices_Orientation===null&&(this.presentation_Choices_Orientation=this.constants.QTI_CHOICES_TOP),this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_LEFT?(this.matchSetNode1.$refs.matchset.classList.add(this.constants.QTI_CHOICES_LEFT),this.matchSetNode2.$refs.matchset.classList.add(this.constants.QTI_CHOICES_LEFT)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_TOP?(this.matchSetNode1.$refs.matchset.classList.add(this.constants.QTI_CHOICES_TOP),this.matchSetNode2.$refs.matchset.classList.add(this.constants.QTI_CHOICES_TOP)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_RIGHT?(this.matchSetNode1.$refs.matchset.classList.add(this.constants.QTI_CHOICES_RIGHT),this.matchSetNode2.$refs.matchset.classList.add(this.constants.QTI_CHOICES_RIGHT),this.matchWrapperElement.insertBefore(this.matchSetNode2.$refs.matchset,this.matchSetNode1.$refs.matchset)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_BOTTOM&&(this.matchSetNode1.$refs.matchset.classList.add(this.constants.QTI_CHOICES_BOTTOM),this.matchSetNode2.$refs.matchset.classList.add(this.constants.QTI_CHOICES_BOTTOM),this.matchWrapperElement.insertBefore(this.matchSetNode2.$refs.matchset,this.matchSetNode1.$refs.matchset)),this.updateMatchSetChoices(this.matchSetNode1,!0),this.updateMatchSetChoices(this.matchSetNode2,!1)):this.interactionSubType==="matchtabular"&&(this.createMatchTable(),this.matchSetNode1.$refs.matchset.classList.add("matchset-hidden"),this.matchSetNode2.$refs.matchset.classList.add("matchset-hidden"))}updateMatchSetChoices(t,i){const s=t.getChoices();for(let n=0;n<s.length;n++)i?(s[n].$refs.choice.classList.add("source"),s[n].$refs.description.classList.add("draggable")):(s[n].$refs.choice.classList.add("target"),s[n].$refs.description.classList.add("match-target-label"))}createMatchTable(){const t=document.createElement("table");this.clazzTokens.forEach(i=>{t.classList.add(i)}),t.classList.add("matchtabular","table","table-bordered"),this.matchWrapperElement.insertBefore(t,this.matchSetNode1.$refs.matchset)}}class xq{constructor(t,i){J(this,"options",{interactionSubType:"default",cardinality:"single",maxAssociations:0,response:null,onReady:null,onUpdate:null,onSelectionsLimit:null});return this.qtiAttributeValidation=new G,this.wrapper=t,this.sourcewrapper=this.wrapper.querySelector(".qti-match-source-wrapper"),this.targetwrapper=this.wrapper.querySelector(".qti-match-target-wrapper"),this.processOptions(i),this.handleDragStart=this.handleDragStart.bind(this),this.handleDragMove=this.handleDragMove.bind(this),this.handleDragEnd=this.handleDragEnd.bind(this),this.handleTouchStart=this.handleTouchStart.bind(this),this.handleTouchMove=this.handleTouchMove.bind(this),this.handleTouchEnd=this.handleTouchEnd.bind(this),this.itemTarget=null,this.itemStart=null,this.isItemStartSource=!0,this.initialX=0,this.initialY=0,this.offsetX=0,this.offsetY=0,this.startingX=0,this.startingY=0,this.currentAssociationsCount=0,this.isDisabled=!1,this.currentDragger=null,this.initializeSources(this.sourcewrapper),this.initializeTargets(this.targetwrapper),this.restoreResponse(this.options.response),this.notifyReady(),this}processOptions(t){"interactionSubType"in t&&(this.options.interactionSubType=t.interactionSubType),"cardinality"in t&&(this.options.cardinality=t.cardinality),"response"in t&&(this.options.response=t.response),"maxAssociations"in t&&(this.options.maxAssociations=t.maxAssociations),"onReady"in t&&(this.options.onReady=t.onReady),"onUpdate"in t&&(this.options.onUpdate=t.onUpdate),"onAssociationsLimit"in t&&(this.options.onAssociationsLimit=t.onAssociationsLimit)}notifyReady(){this.options.onReady!==null&&this.options.onReady({response:this.getResponse()})}notifyUpdate(){this.options.onUpdate!==null&&this.options.onUpdate({response:this.computeResponse()})}notifyAssociationsLimit(){this.options.onAssociationsLimit!==null&&this.options.onAssociationsLimit()}toggleDisable(t){this.isDisabled=t,this.draggers.forEach(i=>{t?i.classList.add("disabled"):i.classList.remove("disabled")})}handleDragStart(t){if(t.preventDefault(),!this.isDisabled&&t.button==0)return this.interactionStart(t.target,t.clientX,t.clientY,!1),!1}handleTouchStart(t){if(t.preventDefault(),!this.isDisabled)return t.targetTouches.length!=1||this.interactionStart(t.target,t.touches[0].pageX,t.touches[0].pageY,!0),!1}interactionStart(t,i,s,n){const r=this.getClosestElement(t,"draggable");this.itemStart=r.parentNode,this.isItemStartSource=this.itemStart.classList.contains("source"),this.identifyTargets(this.itemStart,!0),this.itemTarget=null;const a=r.getBoundingClientRect();this.initialX=i,this.initialY=s,this.startingX=a.left,this.startingY=a.top,this.offsetX=i-this.startingX,this.offsetY=s-this.startingY,this.addPlaceholder(r),r.style.userSelect="none",r.style.width=a.width+"px",r.style.height=a.height+"px",r.style.transform=`translateX(${a.left}px) translateY(${a.top}px) translateZ(0)`,r.classList.add("dragging"),this.setCurrentDragger(r),this.addListeners(r,n)}handleDragMove(t){t.preventDefault(),!this.isDisabled&&this.interactionMove(t.clientX,t.clientY)}handleTouchMove(t){t.preventDefault(),!this.isDisabled&&t.targetTouches.length==1&&this.interactionMove(t.touches[0].clientX,t.touches[0].clientY)}interactionMove(t,i){const s=this.currentDragger;this.offsetX=t-this.initialX,this.offsetY=i-this.initialY,this.constrainDraggerToWrapper(s,this.wrapper),s.style.transform=`translateX(${this.startingX+this.offsetX}px) translateY(${this.startingY+this.offsetY}px) translateZ(0) scale(1)`;const n=s.getBoundingClientRect();this.findDraggerItemTarget(s,n,this.targets),this.isItemStartSource||this.findSourceDraggerTarget(s,n)}constrainDraggerToWrapper(t,i){const s=t.getBoundingClientRect(),n=i.getBoundingClientRect(),r=this.startingX+this.offsetX-n.x,a=this.startingY+this.offsetY-n.y,o=this.startingX+s.width+this.offsetX-(n.x+n.width),u=this.startingY+s.height+this.offsetY-(n.y+n.height);r<0&&(this.offsetX=this.offsetX-r),o>0&&(this.offsetX=this.offsetX-o),a<0&&(this.offsetY=this.offsetY-a),u>0&&(this.offsetY=this.offsetY-u)}handleDragEnd(t){this.isDisabled||this.interactionEnd(t.clientX,t.clientY,!1)}handleTouchEnd(t){this.isDisabled||this.interactionEnd(t.changedTouches[0].clientX,t.changedTouches[0].clientY,!0)}interactionEnd(t,i,s){const n=this.currentDragger;if(this.itemTarget===null?n.style.transform=`translateX(${this.startingX}px) translateY(${this.startingY}px) translateZ(0)`:n.style.transform=`translateX(${this.startingX+this.offsetX}px) translateY(${this.startingY+this.offsetY}px) translateZ(0)`,n.removeAttribute("style"),n.classList.remove("dragging"),this.clearTargetHighlights(),this.itemTarget===null){this.resetDraggerToItemStart(this.itemStart,n),this.setCurrentDragger(null),this.removeListeners(n,s);return}if(this.itemTarget.classList.contains("active")){if(this.itemTarget.classList.remove("active"),this.isExceedingMaxAssociations(this.itemStart,this.itemTarget,n)){this.resetDraggerToItemStart(this.itemStart,n),this.notifyAssociationsLimit(),this.setCurrentDragger(null),this.removeListeners(n,s);return}if(this.itemStart.getAttribute("data-identifier")===this.itemTarget.getAttribute("data-identifier")){this.resetDraggerToItemStart(this.itemStart,n),this.setCurrentDragger(null),this.removeListeners(n,s);return}this.removePlaceholder(n),this.setDraggerToItemTarget(this.itemTarget,n),this.itemTarget.classList.contains("source")&&(this.itemTarget.classList.add("full"),this.itemTarget.dataset.matchMax*1>0&&this.incrementRemaining(this.itemTarget),this.decrementAssociationsCount(),this.sortContainerElements(this.sourcewrapper)),this.itemStart.classList.contains("source")&&(this.itemStart.dataset.matchMax*1>0&&this.decrementRemaining(this.itemStart)===0&&this.itemStart.classList.remove("full"),this.incrementAssociationsCount()),this.itemStart.classList.contains("target")&&(this.isTargetFull(this.itemStart)?this.itemStart.classList.add("full"):this.itemStart.classList.remove("full")),this.notifyUpdate()}this.setCurrentDragger(null),this.removeListeners(n,s)}setCurrentDragger(t){this.currentDragger=t}resetDraggerToItemStart(t,i){this.replacePlaceholder(i),t.classList.contains("source")||i.setAttribute("style","width:100%")}setDraggerToItemTarget(t,i){if(t.classList.contains("source")){if(t.classList.contains("full")){const s=t.querySelector(".draggable");s!=null&&t.replaceChild(i,s);return}t.append(i);return}t.append(i),i.setAttribute("style","width:100%"),this.isTargetFull(t)?t.classList.add("full"):t.classList.remove("full")}findDraggerItemTarget(t,i,s){this.itemTarget=null,s.forEach(n=>{const r=n.getBoundingClientRect();if(i.top+t.offsetHeight/2<r.bottom&&i.right-t.offsetWidth/2>r.left&&i.bottom-t.offsetHeight/2>r.top&&i.left+t.offsetWidth/2<r.right){if(this.isItemStartSource&&n.classList.contains("source")||n.classList.contains("full")||!this.hasMatchingMatchGroup(t.parentNode,n))return;n.classList.add("active"),this.itemTarget=n}else n.classList.remove("active")},this)}findSourceDraggerTarget(t,i){const s=this.sourcewrapper.getBoundingClientRect();if(i.top+t.offsetHeight/2<s.bottom&&i.right-t.offsetWidth/2>s.left&&i.bottom-t.offsetHeight/2>s.top&&i.left+t.offsetWidth/2<s.right){for(let n=0;n<this.sources.length;n++)if(this.sources[n].dataset.identifier===t.dataset.identifier){this.sources[n].classList.add("active"),this.itemTarget=this.sources[n];break}}else for(let n=0;n<this.sources.length;n++)this.sources[n].classList.contains("active")&&this.sources[n].classList.remove("active")}addPlaceholder(t){if(!t.parentNode.classList.contains("source")){this.addPlaceholderElement(t,!1);return}const i=t.parentNode.dataset.matchMax*1;if(i===1){this.addPlaceholderElement(t,!1);return}if(i===0){this.addPlaceholderElement(t,!0);return}if(this.getRemaining(t.parentNode)===1){this.addPlaceholderElement(t,!1);return}this.addPlaceholderElement(t,!0)}addPlaceholderElement(t,i){const s=t.cloneNode(!0);this.deepCloneId(s),i?(s.classList.add("clone"),s.addEventListener("mousedown",this.handleDragStart),s.addEventListener("touchstart",this.handleTouchStart)):s.classList.add("match-dragger-placeholder"),s.classList.add("placeholder-fade"),t.parentNode.insertBefore(s,t)}removePlaceholder(t){if(t.parentNode.classList.contains("target")){const n=t.parentNode.querySelector(".match-dragger-placeholder");if(n===null)return;t.parentNode.removeChild(n);return}const i=t.parentNode.dataset.matchMax*1,s=t.parentNode.querySelector(".match-dragger-placeholder");if(s===null){const n=t.parentNode.querySelector(".clone");if(n===null)return;n.classList.remove("placeholder-fade");return}i!==0&&t.parentNode.removeChild(s)}replacePlaceholder(t){const i=t.parentNode;let s=i.querySelector(".match-dragger-placeholder");if(i.classList.contains("source")){if(s==null&&(s=i.querySelector(".draggable")),s===null)return;i.replaceChild(t,s);return}s!==null&&i.replaceChild(t,s)}addClonePlaceholder(t){const i=t.cloneNode(!0);this.deepCloneId(i),i.classList.add("clone"),t.parentNode.insertBefore(i,t),i.addEventListener("mousedown",this.handleDragStart),i.addEventListener("touchstart",this.handleTouchStart)}initializeSources(t){this.sources=t.querySelectorAll(".source"),this.sources.forEach(i=>{i.classList.add("full");const s=i.dataset.matchMax*1;this.setRemaining(i,s===0?1e3:s)},this),this.draggers=t.querySelectorAll(".draggable"),this.draggers.forEach((i,s)=>{const n=i.parentNode.getAttribute("data-identifier");i.setAttribute("data-identifier",n),i.setAttribute("data-order",s),i.setAttribute("tabindex",0),i.addEventListener("mousedown",this.handleDragStart),i.addEventListener("touchstart",this.handleTouchStart)},this)}initializeTargets(t){this.targets=t.querySelectorAll(".target"),this.targets.forEach(i=>{i.setAttribute("tabindex",0)})}identifyTargets(t,i){this.targets.forEach(s=>{i&&!s.classList.contains("full")&&this.hasMatchingMatchGroup(t,s)&&s.classList.add("target-active")},this),i&&!this.isItemStartSource&&this.sourcewrapper.classList.add("target-active")}addListeners(t,i){i?(this.removeListeners(t,i),t.addEventListener("touchmove",this.handleTouchMove),t.addEventListener("touchend",this.handleTouchEnd)):(this.removeListeners(t,i),document.addEventListener("mousemove",this.handleDragMove),document.addEventListener("mouseup",this.handleDragEnd))}removeListeners(t,i){i?(t.removeEventListener("touchmove",this.handleTouchMove),t.removeEventListener("touchend",this.handleTouchEnd)):(document.removeEventListener("mousemove",this.handleDragMove),document.removeEventListener("mouseup",this.handleDragEnd))}clearTargetHighlights(){this.targets.forEach(t=>{t.classList.remove("target-active")},this),this.sourcewrapper.classList.remove("target-active")}getClosestElement(t,i){return t?t&&t.classList.contains(i)?t:this.getClosestElement(t.parentElement,i):!1}sortContainerElements(t){let i=[],s=t.children;for(let n=0;n<s.length;n++){const r=s[n].querySelector("div.draggable");r&&i.push([1*r.dataset.order,s[n]])}i.sort(function(n,r){return n[0]-r[0]});for(let n=0;n<i.length;n++)t.appendChild(i[n][1])}getResponse(){return this.computeResponse()}computeResponse(){let t=[];return this.targets.forEach(i=>{i.querySelectorAll(".draggable").forEach(s=>{t.push(`${s.dataset.identifier} ${i.dataset.identifier}`)})}),t.length===0?null:this.options.cardinality==="single"?t[0]:t}restoreResponse(t){t!==null&&(this.options.cardinality==="single"?this.restoreResponsePair(t):t.forEach(i=>{this.restoreResponsePair(i)},this))}restoreResponsePair(t){const i=this.getPair(t);if(i===null)return;const s=this.findSourceByIdentifier(i.source),n=this.findTargetGapByIdentifier(i.target);if(s===null||n===null)return;const r=s.querySelector(".draggable");r!==null&&(this.cloneOrEmptySourceDragger(s,r),this.restoreSourceDraggerToTarget(n,r))}cloneOrEmptySourceDragger(t,i){const s=t.dataset.matchMax*1;if(s===1){t.classList.remove("full"),this.decrementRemaining(t);return}if(s===0){this.addClonePlaceholder(i);return}if(this.getRemaining(t)===1){t.classList.remove("full"),this.decrementRemaining(t);return}this.decrementRemaining(t),this.addClonePlaceholder(i)}findSourceByIdentifier(t){for(let i=0;i<this.sources.length;i++)if(t===this.sources[i].dataset.identifier)return this.sources[i];return null}findTargetGapByIdentifier(t){for(let i=0;i<this.targets.length;i++)if(t===this.targets[i].dataset.identifier)return this.targets[i];return null}getPair(t){if(t===null)return null;const i=t.split(" ");return i.length!=2?null:{source:i[0],target:i[1]}}restoreSourceDraggerToTarget(t,i){t===null||i===null||(t.append(i),i.setAttribute("style","width:100%"),this.incrementAssociationsCount(),this.isTargetFull(t)&&t.classList.add("full"))}hasMatchingMatchGroup(t,i){return t===null||i===null?!1:t.dataset.matchGroup===i.dataset.matchGroup}isTargetFull(t){if(t==null)return!1;const i=t.querySelectorAll(".draggable"),s=t.dataset.matchMax*1;return s===0?!1:i.length>=s}isExceedingMaxAssociations(t,i){return!(this.options.maxAssociations===0||i.classList.contains("source")||t.classList.contains("target")||this.currentAssociationsCount<this.options.maxAssociations)}initializeAssociationsCount(){this.currentAssociationsCount=0}incrementAssociationsCount(){this.currentAssociationsCount+=1}decrementAssociationsCount(){this.currentAssociationsCount!==0&&(this.currentAssociationsCount-=1)}getRemaining(t){return t.dataset.remaining*1}setRemaining(t,i){t.setAttribute("data-remaining",i)}incrementRemaining(t){const i=t.dataset.remaining*1+1;return t.setAttribute("data-remaining",i),i}decrementRemaining(t){let i=t.dataset.remaining*1-1;return i=i>=0?i:0,t.setAttribute("data-remaining",i),i}deepCloneId(t){t.id&&(t.id=`clone_${this.qtiAttributeValidation.randomString(5,"a")}`);for(let i=0;i<t.children.length;i++)this.deepCloneId(t.children[i])}reset(){this.resetDraggersToSources(),this.initializeAssociationsCount(),this.destroy()}resetDraggersToSources(){this.targets.forEach(t=>{t.querySelectorAll(".draggable").forEach(s=>{const n=this.findSourceByIdentifier(s.getAttribute("data-identifier"));n.classList.contains("full")||(t.classList.remove("full"),n.classList.contains("full")?t.removeChild(s):(n.append(s),n.classList.add("full")))},this)},this)}destroy(){this.currentDragger!==null&&(document.removeEventListener("mousemove",this.handleDragMove),document.removeEventListener("mouseup",this.handleDragEnd)),this.wrapper.querySelectorAll(".draggable").forEach(i=>{i.removeEventListener("touchstart",this.handleTouchStart),i.removeEventListener("touchmove",this.handleTouchMove),i.removeEventListener("touchend",this.handleTouchEnd),i.removeEventListener("mousedown",this.handleDragStart)},this)}}class Iq{constructor(t,i){J(this,"options",{interactionSubType:"matchtabular",isHeaderHidden:!1,isRowCentric:!1,firstColumnHeader:null,cardinality:"single",maxAssociations:0,response:null,onReady:null,onUpdate:null,onSelectionsLimit:null});J(this,"keyCodes",{Enter:13,Space:32,End:35,Home:36,ArrowLeft:37,ArrowUp:38,ArrowRight:39,ArrowDown:40});return this.wrapper=t,this.table=this.wrapper.querySelector("table.matchtabular"),this.sourcewrapper=this.wrapper.querySelector(".qti-match-source-wrapper"),this.targetwrapper=this.wrapper.querySelector(".qti-match-target-wrapper"),this.currentAssociationsCount=0,this.isDisabled=!1,this.processOptions(i),this.handleClick=this.handleClick.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.handleFocus=this.handleFocus.bind(this),this.handleBlur=this.handleBlur.bind(this),this.state=new Map,this.initializeTable(this.sourcewrapper,this.targetwrapper),this.restoreResponse(),this.notifyReady(),this}processOptions(t){"interactionSubType"in t&&(this.options.interactionSubType=t.interactionSubType),"isHeaderHidden"in t&&(this.options.isHeaderHidden=t.isHeaderHidden),"isRowCentric"in t&&(this.options.isRowCentric=t.isRowCentric),"firstColumnHeader"in t&&(this.options.firstColumnHeader=t.firstColumnHeader),"cardinality"in t&&(this.options.cardinality=t.cardinality),"response"in t&&(this.options.response=t.response),"maxAssociations"in t&&(this.options.maxAssociations=t.maxAssociations),"onReady"in t&&(this.options.onReady=t.onReady),"onUpdate"in t&&(this.options.onUpdate=t.onUpdate),"onAssociationsLimit"in t&&(this.options.onAssociationsLimit=t.onAssociationsLimit)}notifyReady(){this.options.onReady!==null&&this.options.onReady({response:this.getResponse()})}notifyUpdate(){this.options.onUpdate!==null&&this.options.onUpdate({response:this.computeResponse()})}notifyAssociationsLimit(){this.options.onAssociationsLimit!==null&&this.options.onAssociationsLimit()}toggleDisable(t){this.isDisabled=t,this.controls.forEach(i=>{t?i.classList.add("disabled"):i.classList.remove("disabled")})}handleClick(t){if(!this.isDisabled){if(this.isRadio(t.target)){this.setControlChecked(t.target);return}this.toggleControl(t.target)}}handleKeydown(t){let i=!1;switch(t.code){case"Space":case"Enter":this.isDisabled||this.toggleControl(t.target),i=!0;break;case"ArrowUp":case"ArrowLeft":i=!0;break;case"ArrowDown":case"ArrowRight":i=!0;break}i&&(t.stopPropagation(),t.preventDefault())}handleFocus(){}handleBlur(){}toggleControl(t){if(!this.isChecked(t)){if(this.isExceedingMaxAssociations()){this.notifyAssociationsLimit();return}if(this.isExceedingMatchMax(t.dataset.pair,t.dataset.sourceMax*1,!0)||this.isExceedingMatchMax(t.dataset.pair,t.dataset.targetMax*1,!1))return;this.updateState(t.dataset.pair,this.toggleChecked(t)),this.notifyUpdate();return}this.updateState(t.dataset.pair,this.toggleChecked(t)),this.notifyUpdate()}setControlChecked(t){if(!this.isChecked(t)){if(this.isExceedingMaxAssociations()){this.notifyAssociationsLimit();return}if(this.isExceedingMatchMax(t.dataset.pair,t.dataset.sourceMax*1,!0)||this.isExceedingMatchMax(t.dataset.pair,t.dataset.targetMax*1,!1))return;this.updateState(t.dataset.pair,this.setChecked(t,!0)),this.notifyUpdate();return}this.updateState(t.dataset.pair,this.setChecked(t,!0)),this.notifyUpdate()}setChecked(t,i){const s=i?"true":"false";return t.setAttribute("aria-checked",s),s}toggleChecked(t){const s=t.getAttribute("aria-checked")==="true"?"false":"true";return t.setAttribute("aria-checked",s),s}isRadio(t){return t===null?!1:t.getAttribute("role")==="radio"}isChecked(t){return t===null?!1:t.getAttribute("aria-checked")==="true"}setTabIndex(t){this.tabIndex=t}setFocus(){}setBlur(){}updateState(t,i){this.state.set(t,i),this.currentAssociationsCount=0;for(let s of this.state.values())s==="true"&&(this.currentAssociationsCount+=1)}initializeTable(t,i){this.sources=this.getChoices(t),this.targets=this.getChoices(i);const s=`width:${this.getColumnWidthPercentage(this.targets.length)}%`;this.table.innerHTML=`${this.getHeader(s)}${this.getBody(s)}`,this.controls=this.table.querySelectorAll(".control-cell"),this.controls.forEach(n=>{const r=n.getAttribute("data-pair");this.updateState(r,"false"),n.addEventListener("click",this.handleClick),n.addEventListener("keydown",this.handleKeydown),n.addEventListener("focus",this.handleFocus),n.addEventListener("blur",this.handleBlur)},this)}getHeader(t){if(this.options.isHeaderHidden)return"";let i=`<th scope="col" class="header-cell">${this.options.firstColumnHeader==null?"":this.options.firstColumnHeader}</th>`;return this.options.isRowCentric?(i+=this.getSourceHeader(t),`<thead>${i}</thead>`):(i+=this.getTargetHeader(t),`<thead>${i}</thead>`)}getTargetHeader(t){let i="";return this.targets.forEach(s=>{i+=`<th scope="col" class="header-cell" style="${t}">${s.innerHTML}</th>`}),i}getSourceHeader(t){let i="";return this.sources.forEach(s=>{i+=`<th scope="col" class="header-cell" style="${t}">${s.innerHTML}</th>`}),i}getBody(t){let i="";return this.options.isRowCentric?(this.targets.forEach(s=>{i+=`<tr><th scope="row" class="row-header-cell">${s.innerHTML}</th>`;const n=s.getAttribute("data-match-max");this.sources.forEach(r=>{const a=r.getAttribute("data-match-max"),o=r.getAttribute("data-identifier"),u=s.getAttribute("data-identifier"),h=`${o} ${u}`;i+=`<td class="table-cell" style="${t}">
|
167
|
+
</svg>`;const t={theme:"snow",boundary:"div.qti-extended-text-interaction",modules:{toolbar:{container:[["undo","redo"],["bold","italic","underline"],["blockquote"],[{list:"ordered"},{list:"bullet"}]],handlers:{redo(){this.quill.history.redo()},undo(){this.quill.history.undo()}}},history:{delay:2e3,maxStack:100,userOnly:!1},keyboard:{bindings:{tab:{key:9,handler:function(){return!0}}}}},placeholder:this.placeholder,readOnly:!1};this.quill=new Y(this.$refs.editor,t),this.quill.root.setAttribute("spellcheck",!1),this.quill.on("text-change",this.textChangeHandler),this.updateCounter(this.getLength()),this.quill.enable(!0)}},setQuillEditorStyleProperties(){this.$refs.editor!=null&&this.$refs.editor.children!=null&&this.$refs.editor.children.length>0&&(this.$refs.editor.children[0].style=`width:${this.editorHeight};overflow-x:auto;`)},textChangeHandler(){let e=this.getText(),t=this.$refs.editor.children[0].innerHTML,i=this.getLength();if(this.expectedLength&&i>this.expectedLength){this.quill.deleteText(this.expectedLength,i);return}t==="<p><br></p>"&&(t=""),this.updateCounter(this.getLength()),this.$emit("input",{html:t,text:e})},updateCounter(e){if(this.showCounter){if(this.isCounterUp){this.counter=e;return}this.counter=this.computedExpectedLength-e}},getLength(){return this.quill.getLength()-1},getText(){return this.quill.getText()}},mounted(){this.initialize(),this.setQuillEditorStyleProperties(),this.$emit("editorReady",{node:this})},beforeUnmount(){this.$el&&this.quill.off("text-change",this.textChangeHandler),this.$el.remove(),this.quill=void 0}},ON={ref:"root",class:"quill-editor vertical-rl"},PN={key:0,"aria-hidden":"true",class:"ext-text-xhtml-vert-rl-counter"},BN={key:0};function DN(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",ON,[l.createElementVNode("div",{ref:"label",style:l.normalizeStyle(r.styleLabel),class:"ext-text-xhtml-vert-label qti-hidden"},null,4),l.createElementVNode("div",{ref:"editor",style:l.normalizeStyle(r.style)},null,4),r.showCounter?(l.openBlock(),l.createElementBlock("div",PN,[l.createTextVNode(l.toDisplayString(n.counter),1),r.isCounterUp?(l.openBlock(),l.createElementBlock("span",BN," / "+l.toDisplayString(i.expectedLength),1)):l.createCommentVNode("",!0)])):l.createCommentVNode("",!0)],512)}const QN={name:"ExtendedTextXhtmlVerticalRl",components:{EditorQuillVerticalRl:P(qN,[["render",DN]])},props:{responseIdentifier:{required:!0,type:String},expectedLength:{required:!1,type:String},placeholder:{required:!1,type:String,default:""},heightClass:{required:!1,type:String,default:""},counterStyle:{required:!1,type:String,default:"none"}},computed:{computedExpectedLength(){return typeof this.expectedLength<"u"?this.expectedLength:"400"},colorStyle(){return I.getItemContextPnp().getColorStyle()},editorHeight(){return this.heightClass==="qti-height-lines-15"?"25.9rem":this.heightClass==="qti-height-lines-6"?"11.5rem":"6.7rem"},labelHeight(){return this.heightClass==="qti-height-lines-15"?"29.7rem":this.heightClass==="qti-height-lines-6"?"12.3rem":"6.6rem"},maxLength(){return 1e4},disabled(){return this.isDisabled}},data(){return{response:"",content:"",state:null,editor:null,isDisabled:!1}},inheritAttrs:!1,methods:{getResponse(){return this.response},setResponse(e){if(e===null){this.response="",this.setContent("");return}this.setContent(e),this.response=e},updateResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},getContent(){return this.content},setContent(e){this.content=e},computeState(e){return{text:e}},setIsDisabled(e){this.isDisabled=e},handleInput(e){e.html&&(this.updateResponse(e.html),this.setState(this.computeState(e.text)),this.$parent.$emit("extendedTextUpdate",{response:this.getResponse()}))},handleEditorReady(e){this.node=e.node,this.$parent.$emit("extendedTextReady",{node:this})}},mounted(){}},HN={ref:"root"};function FN(e,t,i,s,n,r){const a=l.resolveComponent("EditorQuillVerticalRl");return l.openBlock(),l.createElementBlock("div",HN,[l.createVNode(a,{content:n.content,placeholder:i.placeholder,editorHeight:r.editorHeight,labelHeight:r.labelHeight,counterStyle:i.counterStyle,expectedLength:r.computedExpectedLength,disabled:r.disabled,onInput:r.handleInput,onEditorReady:r.handleEditorReady},null,8,["content","placeholder","editorHeight","labelHeight","counterStyle","expectedLength","disabled","onInput","onEditorReady"])],512)}const UN=P(QN,[["render",FN]]),jt={DEFAULT:"default-plain",DEFAULT_SBAC:"sbac-plain",DEFAULT_LRN:"lrn-plain",DEFAULT_VERTICAL_RL:"vertical-rl-plain",XHTML_DEFAULT:"default-xhtml",XHTML_SBAC:"sbac-xhtml",XHTML_VERTICAL_RL:"vertical-rl-xhtml"};function GN(e,t,i){switch(e){case jt.XHTML_DEFAULT:case jt.XHTML_SBAC:return{template:'<extended-text-xhtml-default response-identifier="'+t.responseIdentifier+'" '+_a(t)+Sa(t)+xa(t)+Ia(t)+Va(t)+Aa(t)+$a(i)+" />",components:{ExtendedTextXhtmlDefault:kN}};case jt.DEFAULT_LRN:return{template:'<extended-text-plain-lrn response-identifier="'+t.responseIdentifier+'" '+_a(t)+Sa(t)+xa(t)+Ia(t)+Va(t)+Aa(t)+$a(i)+" />",components:{ExtendedTextPlainLrn:J_}};case jt.DEFAULT_VERTICAL_RL:return{template:'<extended-text-plain-vertical-rl response-identifier="'+t.responseIdentifier+'" '+_a(t)+Sa(t)+xa(t)+Ia(t)+Va(t)+Aa(t)+$a(i)+" />",components:{ExtendedTextPlainVerticalRl:lV}};case jt.XHTML_VERTICAL_RL:return{template:'<extended-text-xhtml-vertical-rl response-identifier="'+t.responseIdentifier+'" '+_a(t)+Sa(t)+xa(t)+Ia(t)+Va(t)+Aa(t)+$a(i)+" />",components:{ExtendedTextXhtmlVerticalRl:UN}};default:return{template:'<extended-text-plain-default response-identifier="'+t.responseIdentifier+'" '+_a(t)+Sa(t)+xa(t)+Ia(t)+Va(t)+Aa(t)+$a(i)+" />",components:{ExtendedTextPlainDefault:H_}}}}function jN(e,t){const i=WN(e);if(i&&t==="plain")return jt.DEFAULT_SBAC;if(i&&t==="xhtml")return jt.XHTML_DEFAULT;if(zN(e)&&t==="plain")return jt.DEFAULT_LRN;const n=KN(e);return n&&t==="plain"?jt.DEFAULT_VERTICAL_RL:n&&t==="xhtml"?jt.XHTML_VERTICAL_RL:t==="plain"?jt.DEFAULT:t==="xhtml"?jt.XHTML_DEFAULT:jt.DEFAULT}function Sa(e){return typeof e.patternMask>"u"?"":'pattern-mask="'+e.patternMask+'" '}function xa(e){return'pattern-mask-message="'+e.patternMaskMessage+'" '}function Ia(e){return'placeholder="'+e.placeholder+'" '}function _a(e){return typeof e.expectedLength>"u"?"":'expected-length="'+e.expectedLength+'" '}function Va(e){return typeof e.heightClass>"u"?"":'height-class="'+e.heightClass+'" '}function Aa(e){return typeof e.counterStyle>"u"?"none":'counter-style="'+e.counterStyle+'" '}function $a(e){let t="";for(const[i,s]of Object.entries(e))t+=`${i}="${s}" `;return t}function WN(e){return typeof e>"u"||e===null||e.length==0?!1:kh("sbac",e)}function zN(e){return typeof e>"u"||e===null||e.length==0?!1:kh("lrn",e)}function KN(e){return typeof e>"u"||e===null||e.length==0?!1:kh("qti-writing-orientation-vertical-rl",e)}function kh(e,t){const i=t.split(" ");for(let s=0;s<i.length;s++)if(i[s]===e)return!0;return!1}const La=new G,YN=new ie,XN={name:"QtiExtendedTextInteraction",props:{responseIdentifier:{required:!0,type:String},expectedLength:{required:!1,type:String},patternMask:{required:!1,type:String},placeholderText:{required:!1,type:String},format:{required:!1,type:String,default:"plain"},dataPatternmaskMessage:{required:!1,type:String},minStrings:{required:!1,type:String,default:"0"},maxStrings:{required:!1,type:String,default:"0"}},computed:{interactionTemplate(){return GN(this.interactionSubType,this.createComponentProperties(),this.$attrs)},placeholder(){return La.validatePlaceholderText(this.placeholderText,"")},hasPatternMask(){return typeof this.patternMask<"u"},patternMaskMessage(){return La.validatePatternmaskMessage(this.dataPatternmaskMessage,"Invalid Input")}},data(){return{response:"",state:null,baseType:"string",cardinality:"single",interactionSubType:null,isValidResponse:!1,invalidResponseMessage:"Input Required",classAttribute:"",isDisabled:!1,isQtiValid:!0,hasPrompts:!1,presentationFactory:null,node:null,priorState:null}},methods:{getResponse(){return this.response.length===0?null:this.response},setResponse(e){e===null?this.response="":this.response=e,this.node.setResponse(this.response,!0)},updateResponse(e){e===null?this.response="":this.response=e},getState(){return this.state},setState(e){this.state=e,this.node.setState(this.state,!0)},updateState(e){this.state=e},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},setInteractionSubType(e){this.interactionSubType=e},getInteractionSubType(){return this.interactionSubType},disable(){this.toggleDisable(!0)},enable(){this.toggleDisable(!1)},toggleDisable(e){this.isDisabled=e,this.node.setIsDisabled(e)},getInvalidResponseMessage(){return this.invalidResponseMessage},initializeValue(){this.setResponse(null),this.setState(this.computeState()),this.setIsValid(this.computeIsValid())},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.setResponse(null),this.setState(this.computeState()),this.setIsValid(this.computeIsValid())},restoreValue(e){this.setResponse(e.value),this.setState(e.state),this.updateValidity(this.computeIsValid())},getCardinality(){return this.cardinality},computeState(){return{}},computeIsValid(){const e=this.minStrings*1;if(e===0)return!0;if(this.response===null)return!1;const t=this.response.trim();return!(t.length<1||YN.computeWordCount(t)<e)},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},detectInteractionSubType(e,t){return jN(e,t)},createComponentProperties(){return{responseIdentifier:this.responseIdentifier,expectedLength:this.presentationFactory.getExpectedLength(),placeholder:this.placeholder,patternMask:this.patternMask,patternMaskMessage:this.patternMaskMessage,heightClass:this.presentationFactory.getHeightClass(),counterStyle:this.presentationFactory.getCounterStyle()}},handleExtendedTextUpdate(e){this.updateResponse(e.response),"state"in e&&this.updateState(e.state),this.evaluateValidity()},handleExtendedTextReady(e){this.node=e.node,this.priorState===null?this.initializeValue():this.restoreValue(this.priorState)},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Extended Text Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Extended Text Interaction State Invalid. "state" property not found.');return t}},created(){try{this.responseDeclaration=La.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.setInteractionSubType(this.detectInteractionSubType(this.$.vnode.props.class,this.format)),this.presentationFactory=new X1(this.$.vnode.props.class,this.expectedLength),La.validateMaxMinStrings(this.maxStrings,this.minStrings),this.priorState=this.getPriorState(this.responseIdentifier),this.cardinality=this.getCardinality(),this.hasPrompts=this.getPrompts(this.$slots).length>0,this.appliedRegex=La.validatePattern("pattern-mask",this.patternMask)}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{I.defineInteraction({identifier:this.responseIdentifier,interactionType:"ExtendedText",interactionSubType:this.interactionSubType,node:this,resetValue:this.resetValue,isValidResponse:this.isValidResponse,invalidResponseMessage:this.getInvalidResponseMessage()}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},ZN={ref:"root",class:"qti-extended-text-interaction"},JN={ref:"prompt",class:"qti-prompt-wrapper"};function ek(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",ZN,[l.createElementVNode("div",JN,[l.renderSlot(e.$slots,"default")],512),(l.openBlock(),l.createBlock(l.resolveDynamicComponent(r.interactionTemplate),{ref:"textarea",onExtendedTextUpdate:r.handleExtendedTextUpdate,onExtendedTextReady:r.handleExtendedTextReady},null,40,["onExtendedTextUpdate","onExtendedTextReady"]))],512)}const tk=P(XN,[["render",ek]]);class ik{constructor(t){return this.constants={QTI_ORIENTATION_HORIZONTAL:"qti-orientation-horizontal",QTI_ORIENTATION_VERTICAL:"qti-orientation-vertical",QTI_INPUT_WIDTH_DEFAULT:"",QTI_INPUT_WIDTH_1:"qti-input-width-1",QTI_INPUT_WIDTH_2:"qti-input-width-2",QTI_INPUT_WIDTH_3:"qti-input-width-3",QTI_INPUT_WIDTH_4:"qti-input-width-4",QTI_INPUT_WIDTH_5:"qti-input-width-5",QTI_INPUT_WIDTH_6:"qti-input-width-6",QTI_INPUT_WIDTH_10:"qti-input-width-10",QTI_INPUT_WIDTH_15:"qti-input-width-15",QTI_INPUT_WIDTH_20:"qti-input-width-20",QTI_INPUT_WIDTH_25:"qti-input-width-25",QTI_INPUT_WIDTH_30:"qti-input-width-30",QTI_INPUT_WIDTH_35:"qti-input-width-35",QTI_INPUT_WIDTH_40:"qti-input-width-40",QTI_INPUT_WIDTH_45:"qti-input-width-45",QTI_INPUT_WIDTH_50:"qti-input-width-50",QTI_INPUT_WIDTH_72:"qti-input-width-72"},this.classList=t,this.presentation_OrientationClass=this.constants.QTI_ORIENTATION_HORIZONTAL,this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_DEFAULT,this.presentation_MaxLength=8,this.processClassAttribute(),this}processClassAttribute(){if(typeof this.classList>"u"||this.classList===null||this.classList.length==0)return;const t=this.classList.split(" ");for(let i=0;i<t.length;i++)switch(t[i]){case this.constants.QTI_ORIENTATION_VERTICAL:this.presentation_OrientationClass=this.constants.QTI_ORIENTATION_VERTICAL;break;case this.constants.QTI_ORIENTATION_HORIZONTAL:this.presentation_OrientationClass=this.constants.QTI_ORIENTATION_HORIZONTAL;break;case this.constants.QTI_INPUT_WIDTH_1:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_1,this.presentation_MaxLength=1;break;case this.constants.QTI_INPUT_WIDTH_2:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_2,this.presentation_MaxLength=2;break;case this.constants.QTI_INPUT_WIDTH_3:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_3,this.presentation_MaxLength=3;break;case this.constants.QTI_INPUT_WIDTH_4:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_4,this.presentation_MaxLength=4;break;case this.constants.QTI_INPUT_WIDTH_5:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_5,this.presentation_MaxLength=5;break;case this.constants.QTI_INPUT_WIDTH_6:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_6,this.presentation_MaxLength=6;break;case this.constants.QTI_INPUT_WIDTH_10:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_10,this.presentation_MaxLength=10;break;case this.constants.QTI_INPUT_WIDTH_15:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_15,this.presentation_MaxLength=15;break;case this.constants.QTI_INPUT_WIDTH_20:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_20,this.presentation_MaxLength=20;break;case this.constants.QTI_INPUT_WIDTH_25:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_25,this.presentation_MaxLength=25;break;case this.constants.QTI_INPUT_WIDTH_30:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_30,this.presentation_MaxLength=30;break;case this.constants.QTI_INPUT_WIDTH_35:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_35,this.presentation_MaxLength=35;break;case this.constants.QTI_INPUT_WIDTH_40:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_40,this.presentation_MaxLength=40;break;case this.constants.QTI_INPUT_WIDTH_45:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_45,this.presentation_MaxLength=45;break;case this.constants.QTI_INPUT_WIDTH_50:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_50,this.presentation_MaxLength=50;break;case this.constants.QTI_INPUT_WIDTH_72:this.presentation_WidthClass=this.constants.QTI_INPUT_WIDTH_72,this.presentation_MaxLength=500;break}}getOrientationClass(){return this.presentation_OrientationClass}isOrientationVertical(){return this.presentation_OrientationClass==this.constants.QTI_ORIENTATION_VERTICAL}getWidthClass(){return this.presentation_WidthClass}getVerticalMaxLength(){return this.presentation_MaxLength}}const sk=new G,nk={name:"TextEntryPlainDefault",emits:["textEntryReady","textEntryUpdate"],components:{Tooltip:sa},props:{responseIdentifier:{required:!0,type:String},expectedLength:{required:!1,type:String},placeholder:{required:!1,type:String,default:""},patternMask:{required:!1,type:String},patternMaskMessage:{required:!1,type:String,default:"Invalid Input"},spellcheck:{required:!1,type:String,default:"false"},maxlength:{required:!1,type:String,default:"500"}},computed:{computedExpectedLength(){return typeof this.expectedLength<"u"?this.expectedLength*1:400},hasPatternMask(){return typeof this.patternMask<"u"},colorStyle(){return I.getItemContextPnp().getColorStyle()},disabled(){return this.isDisabled}},data(){return{response:"",priorResponse:"",appliedRegex:null,displayMessage:!1,isDisabled:!1}},methods:{getResponse(){return this.response},setResponse(e){if(e===null){this.response="";return}this.response=e},getState(){return this.state},setState(e){this.state=e},setIsDisabled(e){if(this.isDisabled=e,e){const t=this.getResponse();this.$refs.label.innerHTML=t===null?"":t,this.$refs.label.classList.remove("qti-hidden"),this.$refs.label.setAttribute("tabIndex",0),this.$refs.input.classList.add("qti-hidden"),(t===null||t.length===0)&&(this.$refs.label.style.paddingRight="1.1rem")}else this.$refs.label.classList.add("qti-hidden"),this.$refs.label.setAttribute("tabIndex",-1),this.$refs.input.classList.remove("qti-hidden")},handleInput(e){e.preventDefault();let t=!0;this.appliedRegex!==null?t=this.applyPatternMask(this.$refs.input.value):this.setResponse(this.$refs.input.value),t&&(this.priorResponse=this.$refs.input.value,this.$parent.$emit("textEntryUpdate",{response:this.getResponse()}))},getLength(){return this.response.length},applyPatternMask(e){return this.appliedRegex.test(e)?(this.setResponse(e),this.priorResponse=e,!0):(this.showPatternMaskMessage(),this.setResponse(this.priorResponse),!1)},showPatternMaskMessage(){this.$refs.tooltip.show(),this.hidePatternMaskMessage()},hidePatternMaskMessage(e=3e3){setTimeout(()=>{this.$refs.tooltip.hide()},e)}},created(){this.appliedRegex=sk.validatePattern("pattern-mask",this.patternMask)},mounted(){this.$parent.$emit("textEntryReady",{node:this})}},rk={ref:"root"},ak={ref:"label",class:"text-entry-default-label qti-hidden"},ok=["placeholder","disabled","spellcheck","maxlength"];function lk(e,t,i,s,n,r){const a=l.resolveComponent("tooltip");return l.openBlock(),l.createElementBlock("span",rk,[l.createElementVNode("span",ak,null,512),l.withDirectives(l.createElementVNode("input",l.mergeProps({ref:"input",class:"text-entry-default"},e.$attrs,{"onUpdate:modelValue":t[0]||(t[0]=o=>n.response=o),type:"text",placeholder:i.placeholder,disabled:r.disabled,autocapitalize:"none",spellcheck:i.spellcheck,maxlength:i.maxlength,onInput:t[1]||(t[1]=(...o)=>r.handleInput&&r.handleInput(...o))}),null,16,ok),[[l.vModelText,n.response]]),r.hasPatternMask?(l.openBlock(),l.createBlock(a,{key:0,ref:"tooltip",target:()=>e.$refs.input,message:i.patternMaskMessage,"color-style":r.colorStyle},null,8,["target","message","color-style"])):l.createCommentVNode("",!0)],512)}const cw=P(nk,[["render",lk]]),ck=new G,uk={name:"TextEntryPlainDefaultVertical",emits:["textEntryReady","textEntryUpdate"],components:{Tooltip:sa},props:{responseIdentifier:{required:!0,type:String},expectedLength:{required:!1,type:String},placeholder:{required:!1,type:String,default:""},patternMask:{required:!1,type:String},patternMaskMessage:{required:!1,type:String,default:"Invalid Input"},spellcheck:{required:!1,type:String,default:"false"},widthClass:{required:!1,type:String,default:""},maxlength:{required:!1,type:String,default:"8"}},computed:{computedExpectedLength(){return typeof this.expectedLength<"u"?this.expectedLength*1:400},hasPatternMask(){return typeof this.patternMask<"u"},colorStyle(){return I.getItemContextPnp().getColorStyle()},disabled(){return this.isDisabled}},data(){return{response:"",priorResponse:"",appliedRegex:null,displayMessage:!1,caretIndex:0,maxlengthMessage:"",isDisabled:!1}},inheritAttrs:!1,methods:{getResponse(){return this.response},setResponse(e,t=!1){e===null?this.response="":this.response=e,t&&this.updateContent(this.response)},getState(){return this.state},setState(e){this.state=e},setIsDisabled(e){if(this.isDisabled=e,e){const t=this.getResponse();this.$refs.label.innerHTML=t===null?"":t,this.$refs.label.classList.remove("qti-hidden"),this.$refs.label.setAttribute("tabIndex",0),this.$refs.input.classList.add("qti-hidden"),this.hidePlaceholder()}else this.$refs.label.classList.add("qti-hidden"),this.$refs.label.setAttribute("tabIndex",-1),this.$refs.input.classList.remove("qti-hidden"),this.getContent().length===0?this.showPlaceholder():this.hidePlaceholder()},getContent(){return this.$refs.input.innerText},updateContent(e){this.$refs.input.innerText=e,e.length>0?this.hidePlaceholder():this.showPlaceholder()},getCaretIndex(){return this.caretIndex},setCaretIndex(e){this.caretIndex=e},handleInput(e){e.preventDefault();let t=!0;this.setCaretIndex(this.getCaretPos(this.$refs.input)-1);const i=this.getContent();i.length>0&&this.hidePlaceholder(),this.applyLimitCheck(i)&&(this.appliedRegex!==null?t=this.applyPatternMask(i):this.setResponse(i),t&&(i.length==0&&this.showPlaceholder(),this.priorResponse=i,this.$parent.$emit("textEntryUpdate",{response:this.getResponse()})))},handlePaste(e){e.preventDefault();const t=this.getRange();if(t===null)return;const i=this.getContent(),s=t.startOffset,n=t.endOffset;let r=e.clipboardData.getData("text/plain"),a=i.substring(0,s)+r+i.substring(n),o=!0;if(a.length>0&&this.hidePlaceholder(),a.length>this.maxlength){this.showMaxlengthMessage(),this.setResponse(this.priorResponse,!0),this.setCaretPos(this.$refs.input,s);return}this.appliedRegex!==null?o=this.applyPatternMask(a):this.setResponse(a,!0),o&&(this.setCaretIndex(s+r.length),this.setCaretPos(this.$refs.input,this.getCaretIndex()),this.priorResponse=a,this.$parent.$emit("textEntryUpdate",{response:this.getResponse()}))},handleDrop(e){e.preventDefault()},handleKeydown(e){switch(this.setCaretIndex(this.getCaretPos(this.$refs.input)),e.code){case"Enter":e.preventDefault();return;case"KeyI":case"KeyB":case"KeyU":e.ctrlKey&&e.preventDefault();return}},newDownRange(e){const t=e.firstChild,i=this.getRange();if(i===null)return;const s=i.startOffset,n=i.endOffset;if(n===this.getResponse().length)return;const r=window.getSelection();r.removeAllRanges();const a=document.createRange();a.setStart(t,s),a.setEnd(t,n+1),r.addRange(a)},newUpRange(e){const t=e.firstChild,i=this.getRange();if(i===null)return;const s=i.startOffset,n=i.endOffset;if(s===0)return;const r=window.getSelection();r.removeAllRanges();const a=document.createRange();a.setStart(t,s-1),a.setEnd(t,n),r.addRange(a)},getRange(){const e=document.getSelection();return e.rangeCount===0?null:e.getRangeAt(0)},getCaretPos(e){let t=0;if(typeof window.getSelection<"u"&&window.getSelection().rangeCount!==0){const n=window.getSelection().getRangeAt(0),r=n.cloneRange();r.selectNodeContents(e),r.setEnd(n.endContainer,n.endOffset),t=r.toString().length}return t},setCaretPos(e,t){e.focus(),e.childNodes.length===1&&document.getSelection().collapse(e.childNodes[0],t)},showPlaceholder(){this.$refs.placeholder.classList.remove("text-entry-ph-hidden")},hidePlaceholder(){this.$refs.placeholder.classList.add("text-entry-ph-hidden")},handleBlur(){this.$refs.root.classList.remove("focused")},handleFocus(){this.$refs.root.classList.add("focused")},getLength(){return this.response.length},applyLimitCheck(e){return e.length>this.maxlength?(this.showMaxlengthMessage(),this.setResponse(this.priorResponse,!0),this.setCaretPos(this.$refs.input,this.getCaretIndex()),!1):!0},applyPatternMask(e){return this.appliedRegex.test(e)?(this.setResponse(e),this.priorResponse=e,!0):(this.showPatternMaskMessage(),this.setResponse(this.priorResponse,!0),this.setCaretPos(this.$refs.input,this.getCaretIndex()),!1)},showPatternMaskMessage(){this.$refs.tooltip.show(),this.hidePatternMaskMessage()},hidePatternMaskMessage(e=3e3){setTimeout(()=>{this.$refs.tooltip.hide()},e)},showMaxlengthMessage(){this.$refs.tooltipMaxlength.show(),this.hideMaxlengthMessage()},hideMaxlengthMessage(e=1e3){setTimeout(()=>{this.$refs.tooltipMaxlength.hide()},e)},computeMaxlengthMessage(){this.maxlengthMessage=`Maximum of ${this.maxlength} character`+(this.maxlength==="1"?"":"s")}},created(){this.appliedRegex=ck.validatePattern("pattern-mask",this.patternMask),this.computeMaxlengthMessage()},mounted(){this.$parent.$emit("textEntryReady",{node:this})}},hk=["spellcheck","maxlength","disabled"];function dk(e,t,i,s,n,r){const a=l.resolveComponent("tooltip");return l.openBlock(),l.createElementBlock("div",l.mergeProps({ref:"root",class:"text-entry-default-vert-wrapper"},e.$attrs),[l.createElementVNode("div",{ref:"label",class:"text-entry-default-vert-label qti-hidden",onFocus:t[0]||(t[0]=(...o)=>r.handleFocus&&r.handleFocus(...o)),onBlur:t[1]||(t[1]=(...o)=>r.handleBlur&&r.handleBlur(...o))},null,544),l.createElementVNode("div",{ref:"input",class:"text-entry-default-vert",tabindex:"0",contenteditable:"true",autocapitalize:"false",spellcheck:i.spellcheck,maxlength:i.maxlength,disabled:r.disabled,onInput:t[2]||(t[2]=(...o)=>r.handleInput&&r.handleInput(...o)),onBlur:t[3]||(t[3]=(...o)=>r.handleBlur&&r.handleBlur(...o)),onFocus:t[4]||(t[4]=(...o)=>r.handleFocus&&r.handleFocus(...o)),onKeydown:t[5]||(t[5]=(...o)=>r.handleKeydown&&r.handleKeydown(...o)),onPaste:t[6]||(t[6]=(...o)=>r.handlePaste&&r.handlePaste(...o)),onDrop:t[7]||(t[7]=(...o)=>r.handleDrop&&r.handleDrop(...o))},null,40,hk),l.createElementVNode("label",{ref:"placeholder",class:"text-entry-default-vert-ph","aria-hidden":"true"},l.toDisplayString(i.placeholder),513),r.hasPatternMask?(l.openBlock(),l.createBlock(a,{key:0,ref:"tooltip",target:()=>e.$refs.input,message:i.patternMaskMessage,"color-style":r.colorStyle},null,8,["target","message","color-style"])):l.createCommentVNode("",!0),l.createVNode(a,{ref:"tooltipMaxlength",target:()=>e.$refs.input,message:n.maxlengthMessage,"color-style":r.colorStyle},null,8,["target","message","color-style"])],16)}const fk=P(uk,[["render",dk]]),Ll={DEFAULT:"default-plain-horizontal",DEFAULT_VERTICAL:"default-plain-vertical"};function pk(e,t,i){switch(e){case Ll.DEFAULT:return{template:'<text-entry-plain-default response-identifier="'+t.responseIdentifier+'" '+Bh(t)+qh(t)+Oh(t)+Ph(t)+Dh(t)+Qh(t)+uw(t)+Hh(i)+" />",components:{TextEntryPlainDefault:cw}};case Ll.DEFAULT_VERTICAL:return{template:'<text-entry-plain-default-vertical response-identifier="'+t.responseIdentifier+'" '+Bh(t)+qh(t)+Oh(t)+Ph(t)+Dh(t)+Qh(t)+gk(t)+yk(t)+Hh(i)+" />",components:{TextEntryPlainDefaultVertical:fk}};default:return{template:'<text-entry-plain-default response-identifier="'+t.responseIdentifier+'" '+Bh(t)+qh(t)+Oh(t)+Ph(t)+Dh(t)+Qh(t)+uw(t)+Hh(i)+" />",components:{TextEntryPlainDefault:cw}}}}function mk(e){return wk(e)?Ll.DEFAULT_VERTICAL:Ll.DEFAULT}function qh(e){return typeof e.patternMask>"u"?"":'pattern-mask="'+e.patternMask+'" '}function Oh(e){return'pattern-mask-message="'+e.patternMaskMessage+'" '}function Ph(e){return'placeholder="'+e.placeholder+'" '}function Bh(e){return typeof e.expectedLength>"u"?"":'expected-length="'+e.expectedLength+'" '}function Dh(e){return typeof e.format>"u"||e.format.length==0?"":'format="'+e.format+'" '}function Qh(e){return typeof e.spellcheck>"u"?"":'spellcheck="'+e.spellcheck+'" '}function uw(e){return typeof e.maxlength>"u"?"":'maxlength="'+e.maxlength+'" '}function gk(e){return typeof e.widthClass>"u"?"":'width-class="'+e.widthClass+'" '}function yk(e){return typeof e.verticalMaxlength>"u"?"":'maxlength="'+e.verticalMaxlength+'" '}function Hh(e){let t="";for(const[i,s]of Object.entries(e))t+=`${i}="${s}" `;return t}function wk(e){return typeof e>"u"||e===null||e.length==0?!1:hw("qti-writing-orientation-vertical-rl",e)?!0:hw("qti-orientation-vertical",e)}function hw(e,t){const i=t.split(" ");for(let s=0;s<i.length;s++)if(i[s]===e)return!0;return!1}const Ml=new G,bk={name:"QtiTextEntryInteraction",props:{responseIdentifier:{required:!0,type:String},expectedLength:{required:!1,type:String},patternMask:{required:!1,type:String},placeholderText:{required:!1,type:String},format:{required:!1,type:String,default:""},dataPatternmaskMessage:{required:!1,type:String},dataMaxlength:{required:!1,type:String},dataSpellcheck:{required:!1,type:String}},computed:{interactionTemplate(){return pk(this.interactionSubType,this.createComponentProperties(),this.$attrs)},placeholder(){return Ml.validatePlaceholderText(this.placeholderText,"")},hasPatternMask(){return typeof this.patternMask<"u"},patternMaskMessage(){return Ml.validatePatternmaskMessage(this.dataPatternmaskMessage,"Invalid Input")},colorStyle(){return I.getItemContextPnp().getColorStyle()},computeMaxlength(){return typeof this.dataMaxlength<"u"?this.dataMaxlength:500},computeSpellcheck(){return typeof this.dataSpellcheck<"u"?this.dataSpellcheck:!1}},data(){return{response:"",state:null,baseType:"string",cardinality:"single",interactionSubType:null,isValidResponse:!1,invalidResponseMessage:"Input Required",classAttribute:"",isDisabled:!1,isQtiValid:!0,presentationFactory:null,node:null,priorState:null}},methods:{getResponse(){return this.response.length===0?null:this.response},setResponse(e){e===null?this.response="":this.response=e,this.node.setResponse(this.response,!0)},updateResponse(e){e===null?this.response="":this.response=e},getState(){return this.state},setState(e){this.state=e},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},setInteractionSubType(e){this.interactionSubType=e},getInteractionSubType(){return this.interactionSubType},disable(){this.toggleDisable(!0)},enable(){this.toggleDisable(!1)},toggleDisable(e){this.isDisabled=e,this.node.setIsDisabled(e)},getInvalidResponseMessage(){return this.invalidResponseMessage},initializeValue(){this.setResponse(null),this.setState(this.computeState()),this.setIsValid(!1)},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.setResponse(null),this.setState(this.computeState()),this.setIsValid(!1)},restoreValue(e){this.setResponse(e.value),this.setState(e.state),this.updateValidity(this.computeIsValid())},getCardinality(){return this.cardinality},computeState(){return{}},computeIsValid(){return!(this.response===null||this.response.length<1)},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},detectInteractionSubType(e){return mk(e)},createComponentProperties(){return{responseIdentifier:this.responseIdentifier,placeholder:this.placeholder,patternMask:this.patternMask,patternMaskMessage:this.patternMaskMessage,spellcheck:this.computeSpellcheck,maxlength:this.computeMaxlength,widthClass:this.presentationFactory.getWidthClass(),verticalMaxlength:this.presentationFactory.getVerticalMaxLength(),format:this.format}},handleTextEntryUpdate(e){this.updateResponse(e.response),this.evaluateValidity()},handleTextEntryReady(e){this.node=e.node,this.priorState===null?this.initializeValue():this.restoreValue(this.priorState)},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Text Entry Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Text Entry Interaction State Invalid. "state" property not found.');return t}},created(){try{this.responseDeclaration=Ml.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.setInteractionSubType(this.detectInteractionSubType(this.$.vnode.props.class)),this.presentationFactory=new ik(this.$.vnode.props.class),this.priorState=this.getPriorState(this.responseIdentifier),this.cardinality=this.getCardinality(),this.appliedRegex=Ml.validatePattern("pattern-mask",this.patternMask)}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.priorState===null?this.initializeValue():this.restoreValue(this.priorState),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"TextEntry",node:this,resetValue:this.resetValue,isValidResponse:this.isValidResponse,invalidResponseMessage:this.getInvalidResponseMessage()}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}};function vk(e,t,i,s,n,r){return l.openBlock(),l.createBlock(l.resolveDynamicComponent(r.interactionTemplate),{ref:"input",class:"qti-text-entry-interaction",onTextEntryUpdate:r.handleTextEntryUpdate,onTextEntryReady:r.handleTextEntryReady},null,40,["onTextEntryUpdate","onTextEntryReady"])}const Ek=P(bk,[["render",vk]]),Ck=new G,Tk={name:"QtiMatchInteraction",props:{responseIdentifier:{required:!0,type:String},minAssociations:{required:!1,type:String,default:"0"},maxAssociations:{required:!1,type:String,default:"1"},shuffle:{required:!1,type:String,default:"false"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String},dataFirstColumnHeader:{required:!1,type:String,default:null}},data(){return{response:null,state:null,isValidResponse:!1,matchsets:[],orders:[],cardinality:"single",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,hasPrompts:!1,matchInteractionStaticClass:"",interactionSubType:"default",headerHidden:"false",rowCentric:"false",isQtiValid:!0,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},setInteractionSubType(e){this.interactionSubType=e},getInteractionSubType(){return this.interactionSubType},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},getInvalidResponseMessage(){return this.minSelectionsMessage},disable(){this.$refs.matchgroup.disable()},enable(){this.$refs.matchgroup.enable()},initializeValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.setResponse(null),this.setState(null),this.priorState=null,this.$refs.matchgroup.resetGroupUI()},restoreValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality:"single",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},handleMatchGroupReady(e){this.matchsets=e.matchsets,this.orders=e.orders,this.initializeValue(e.response)},handleMatchGroupUpdate(e){this.setResponse(e.response),this.updateValidity(this.computeIsValid())},handleAssociationsLimit(){I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage)},computeState(){return this.priorState!==null?this.priorState.state:{orders:this.orders}},computeIsValid(){const e=this.getResponse(),t=this.minAssociations*1;return t===0?!0:e===null?!1:this.cardinality==="single"||e.length>=t},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxAssociations*1==0?"":"You may make a maximum of "+this.maxAssociations+" match"+(this.maxAssociations*1>1?"es":"")+" for this question."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.minAssociations*1!=0&&(this.minSelectionsMessage="You must make at least "+this.minAssociations+" match"+(this.minAssociations*1>1?"es":"")+" for this question.")},detectInteractionSubType(e){return this.getMatchInteractionSubType(e)},getMatchInteractionSubType(e){let t="default";if(typeof e>"u"||e===null||e.length==0)return t;this.matchInteractionStaticClass=e;const i=e.split(" ");for(let s=0;s<i.length;s++)switch(i[s]){case"qti-match-tabular":t="matchtabular";break;case"qti-header-hidden":this.headerHidden="true";break;case"row-centric":this.rowCentric="true";break}return t},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Match Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Match Interaction State Invalid. "state" property not found.');if(!("orders"in t.state))throw new O('Match Interaction State Invalid. "orders" property not found.');return t}},created(){try{if(this.responseDeclaration=Ck.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.setInteractionSubType(this.detectInteractionSubType(this.$.vnode.props.class)),this.priorState=this.getPriorState(this.responseIdentifier),this.cardinality=this.getCardinality(),this.cardinality!=="single"&&this.cardinality!=="multiple")throw new c('qti-match-interaction cardinality must be "single" or "multiple"');if(this.maxAssociations*1!=1&&this.cardinality!=="multiple")throw new c('qti-match-interaction response variable must have "multiple" cardinality because max-associations is '+this.maxAssociations);if(this.minAssociations*1>1&&this.cardinality==="single")throw new c('qti-match-interaction response variable must have "multiple" cardinality because min-associations is '+this.minAssociations);this.hasPrompts=this.getPrompts(this.$slots).length>0,this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"Match",interactionSubType:this.interactionSubType,node:this,resetValue:this.resetValue,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},Sk={ref:"root",class:"qti-match-interaction"},xk={ref:"prompt",class:"qti-prompt-wrapper"};function Ik(e,t,i,s,n,r){const a=l.resolveComponent("MatchGroup");return l.openBlock(),l.createElementBlock("div",Sk,[l.createElementVNode("div",xk,null,512),l.createVNode(a,l.mergeProps({ref:"matchgroup",cardinality:n.cardinality,shuffle:i.shuffle,responseIdentifier:i.responseIdentifier,maxAssociations:i.maxAssociations,minAssociations:i.minAssociations,interactionSubType:n.interactionSubType,matchInteractionStaticClass:n.matchInteractionStaticClass,headerHidden:n.headerHidden,rowCentric:n.rowCentric,dataFirstColumnHeader:i.dataFirstColumnHeader,priorState:n.priorState,onMatchGroupReady:r.handleMatchGroupReady,onMatchGroupUpdate:r.handleMatchGroupUpdate,onMatchGroupAssociationsLimit:r.handleAssociationsLimit},e.$attrs),{default:l.withCtx(()=>[l.renderSlot(e.$slots,"default")]),_:3},16,["cardinality","shuffle","responseIdentifier","maxAssociations","minAssociations","interactionSubType","matchInteractionStaticClass","headerHidden","rowCentric","dataFirstColumnHeader","priorState","onMatchGroupReady","onMatchGroupUpdate","onMatchGroupAssociationsLimit"])],512)}const _k=P(Tk,[["render",Ik]]),Vk=new G,Ak={name:"QtiGapMatchInteraction",props:{responseIdentifier:{required:!0,type:String},minAssociations:{required:!1,type:String,default:"0"},maxAssociations:{required:!1,type:String,default:"1"},shuffle:{required:!1,type:String,default:"false"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String},dataChoicesContainerWidth:{required:!1,type:String,default:null}},data(){return{response:null,state:null,isValidResponse:!1,choices:[],order:[],cardinality:"single",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,hasPrompts:!1,gapMatchInteractionStaticClass:"",interactionSubType:"default",isQtiValid:!0,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},setInteractionSubType(e){this.interactionSubType=e},getInteractionSubType(){return this.interactionSubType},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},getInvalidResponseMessage(){return this.minSelectionsMessage},disable(){this.$refs.gapmatchgroup.disable()},enable(){this.$refs.gapmatchgroup.enable()},initializeValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.setResponse(null),this.setState(null),this.priorState=null,this.$refs.matchgroup.resetGroupUI()},restoreValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality:"single",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},handleGapMatchGroupReady(e){this.choices=e.choices,this.order=e.order,this.initializeValue(e.response)},handleGapMatchGroupUpdate(e){this.setResponse(e.response),this.updateValidity(this.computeIsValid())},handleAssociationsLimit(){I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage)},computeState(){return this.priorState!==null?this.priorState.state:{order:this.order}},computeIsValid(){const e=this.getResponse(),t=this.minAssociations*1;return t===0?!0:e===null?!1:this.cardinality==="single"||e.length>=t},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxAssociations*1==0?"":"You may make a maximum of "+this.maxAssociations+" match"+(this.maxAssociations*1>1?"es":"")+" for this question."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.minAssociations*1!=0&&(this.minSelectionsMessage="You must make at least "+this.minAssociations+" match"+(this.minAssociations*1>1?"es":"")+" for this question.")},detectInteractionSubType(e){return this.computeInteractionSubType(e)},computeInteractionSubType(e){let t="default";return typeof e>"u"||e===null||e.length==0||(this.gapMatchInteractionStaticClass=e),t},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Gap Match Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Gap Match Interaction State Invalid. "state" property not found.');if(!("order"in t.state))throw new O('Gap Match Interaction State Invalid. "order" property not found.');return t}},created(){try{if(this.responseDeclaration=Vk.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.setInteractionSubType(this.detectInteractionSubType(this.$.vnode.props.class)),this.priorState=this.getPriorState(this.responseIdentifier),this.cardinality=this.getCardinality(),this.cardinality!=="single"&&this.cardinality!=="multiple")throw new c('qti-gap-match-interaction cardinality must be "single" or "multiple"');if(this.maxAssociations*1!=1&&this.cardinality!=="multiple")throw new c('qti-gap-match-interaction response variable must have "multiple" cardinality because max-associations is '+this.maxAssociations);if(this.minAssociations*1>1&&this.cardinality==="single")throw new c('qti-gap-match-interaction response variable must have "multiple" cardinality because min-associations is '+this.minAssociations);this.hasPrompts=this.getPrompts(this.$slots).length>0,this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"GapMatch",interactionSubType:this.interactionSubType,node:this,resetValue:this.resetValue,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},$k={ref:"root",class:"qti-gap-match-interaction"},Lk={ref:"prompt",class:"qti-prompt-wrapper"};function Mk(e,t,i,s,n,r){const a=l.resolveComponent("GapMatchGroup");return l.openBlock(),l.createElementBlock("div",$k,[l.createElementVNode("div",Lk,null,512),l.createVNode(a,l.mergeProps({ref:"gapmatchgroup",cardinality:n.cardinality,shuffle:i.shuffle,responseIdentifier:i.responseIdentifier,maxAssociations:i.maxAssociations,minAssociations:i.minAssociations,interactionSubType:n.interactionSubType,gapMatchInteractionStaticClass:n.gapMatchInteractionStaticClass,dataChoicesContainerWidth:i.dataChoicesContainerWidth,priorState:n.priorState,onGapMatchGroupReady:r.handleGapMatchGroupReady,onGapMatchGroupUpdate:r.handleGapMatchGroupUpdate,onGapMatchGroupAssociationsLimit:r.handleAssociationsLimit},e.$attrs),{default:l.withCtx(()=>[l.renderSlot(e.$slots,"default")]),_:3},16,["cardinality","shuffle","responseIdentifier","maxAssociations","minAssociations","interactionSubType","gapMatchInteractionStaticClass","dataChoicesContainerWidth","priorState","onGapMatchGroupReady","onGapMatchGroupUpdate","onGapMatchGroupAssociationsLimit"])],512)}const Rk=P(Ak,[["render",Mk]]),Nk=new G,kk={name:"QtiGraphicGapMatchInteraction",props:{responseIdentifier:{required:!0,type:String},minAssociations:{required:!1,type:String,default:"0"},maxAssociations:{required:!1,type:String,default:"1"},shuffle:{required:!1,type:String,default:"false"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String},dataChoicesContainerWidth:{required:!1,type:String,default:null}},data(){return{response:null,state:null,isValidResponse:!1,choices:[],order:[],cardinality:"multiple",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,hasPrompts:!1,interactionStaticClass:"",interactionSubType:"default",isQtiValid:!0,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},setInteractionSubType(e){this.interactionSubType=e},getInteractionSubType(){return this.interactionSubType},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},getInvalidResponseMessage(){return this.minSelectionsMessage},disable(){this.$refs.ggmgroup.disable()},enable(){this.$refs.ggmgroup.enable()},initializeValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.setResponse(null),this.setState(null),this.priorState=null,this.$refs.matchgroup.resetGroupUI()},restoreValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality:"single",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},handleGraphicGapMatchGroupReady(e){this.choices=e.choices,this.order=e.order,this.initializeValue(e.response)},handleGraphicGapMatchGroupUpdate(e){this.setResponse(e.response),this.updateValidity(this.computeIsValid())},handleAssociationsLimit(){I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage)},computeState(){return this.priorState!==null?this.priorState.state:{order:this.order}},computeIsValid(){const e=this.getResponse(),t=this.minAssociations*1;return t===0?!0:e===null?!1:this.cardinality==="single"||e.length>=t},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxAssociations*1==0?"":"You may make a maximum of "+this.maxAssociations+" match"+(this.maxAssociations*1>1?"es":"")+" for this question."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.minAssociations*1!=0&&(this.minSelectionsMessage="You must make at least "+this.minAssociations+" match"+(this.minAssociations*1>1?"es":"")+" for this question.")},detectInteractionSubType(e){return this.computeInteractionSubType(e)},computeInteractionSubType(e){let t="default";return typeof e>"u"||e===null||e.length==0||(this.interactionStaticClass=e),t},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Gap Match Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Gap Match Interaction State Invalid. "state" property not found.');if(!("order"in t.state))throw new O('Gap Match Interaction State Invalid. "order" property not found.');return t}},created(){try{if(this.responseDeclaration=Nk.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.setInteractionSubType(this.detectInteractionSubType(this.$.vnode.props.class)),this.priorState=this.getPriorState(this.responseIdentifier),this.cardinality=this.getCardinality(),this.cardinality!=="multiple")throw new c('qti-graphic-gap-match-interaction cardinality must be "multiple"');this.hasPrompts=this.getPrompts(this.$slots).length>0,this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"GraphicGapMatch",interactionSubType:this.interactionSubType,node:this,resetValue:this.resetValue,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},qk={ref:"root",class:"qti-graphic-gap-match-interaction"},Ok={ref:"prompt",class:"qti-prompt-wrapper"};function Pk(e,t,i,s,n,r){const a=l.resolveComponent("GraphicGapMatchGroup");return l.openBlock(),l.createElementBlock("div",qk,[l.createElementVNode("div",Ok,null,512),l.createVNode(a,l.mergeProps({ref:"ggmgroup",cardinality:n.cardinality,shuffle:i.shuffle,responseIdentifier:i.responseIdentifier,maxAssociations:i.maxAssociations,minAssociations:i.minAssociations,interactionSubType:n.interactionSubType,interactionStaticClass:n.interactionStaticClass,dataChoicesContainerWidth:i.dataChoicesContainerWidth,priorState:n.priorState,onGgmGroupReady:r.handleGraphicGapMatchGroupReady,onGgmGroupUpdate:r.handleGraphicGapMatchGroupUpdate,onGgmGroupAssociationsLimit:r.handleAssociationsLimit},e.$attrs),{default:l.withCtx(()=>[l.renderSlot(e.$slots,"default")]),_:3},16,["cardinality","shuffle","responseIdentifier","maxAssociations","minAssociations","interactionSubType","interactionStaticClass","dataChoicesContainerWidth","priorState","onGgmGroupReady","onGgmGroupUpdate","onGgmGroupAssociationsLimit"])],512)}const Bk=P(kk,[["render",Pk]]),Dk={},Qk={ref:"root",class:"qti3-player-media-group"};function Hk(e,t){return l.openBlock(),l.createElementBlock("div",Qk,[l.renderSlot(e.$slots,"default")],512)}const dw=P(Dk,[["render",Hk]]),fw=new G,Fk={name:"QtiMediaInteraction",components:[dw],props:{responseIdentifier:{required:!0,type:String},autostart:{required:!0,type:String},minPlays:{required:!1,type:String,default:"0"},maxPlays:{required:!1,type:String,default:"0"},loop:{required:!1,type:String,default:"false"},coords:{required:!1,type:String},dataMaxPlaysMessage:{required:!1,type:String},dataMinPlaysMessage:{required:!1,type:String}},data(){return{response:null,state:null,isValidResponse:!1,cardinality:"single",minPlaysMessage:"",maxPlaysMessage:"",responseDeclaration:null,mediaType:"media",isAutostart:!1,isLoop:!1,isDisabled:!1,isQtiValid:!0,hasPrompts:!1,node:null,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},incrementPlays(){let e=this.getResponse();this.setResponse(e===null?1:e+1)},getState(){return this.state},setState(e){this.state=e},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},disable(){this.node!==null&&this.node.disable()},enable(){this.node!==null&&this.node.enable()},getInvalidResponseMessage(){return this.computeMinPlaysMessage(),this.minPlaysMessage},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.priorState=null,this.setResponse(null),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},restoreValue(e){e!==null&&(this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid()),this.evaluateMaxPlays())},getCardinality(){return this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},handleMediaMounted(e){this.node=e.node,this.mediaType=e.mediaType,e.mediaType==="audio"&&this.node.setAudioSubType("audioprogress"),this.evaluateMaxPlays()},handleMediaLoaded(e){this.node=e.node,this.evaluateMaxPlays(),this.evaluateAutostart()},handleMediaEnded(){this.incrementPlays(),this.evaluateValidity(),this.evaluateMaxPlays(),this.evaluateLoop()},computeState(){return{}},computeIsValid(){const e=this.minPlays*1;if(e===0)return!0;const t=this.getResponse();return t===null?!1:t>=e},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},evaluateMaxPlays(){this.checkMaxPlaysLimit()?this.disable():this.enable()},evaluateLoop(){this.isLoop&&(this.checkMaxPlaysLimit()||this.isDisabled||this.playMedia())},evaluateAutostart(){this.isAutostart&&(this.checkMaxPlaysLimit()||this.isDisabled||(console.log(`[${this.$options.name}][Identifier=${this.responseIdentifier}][AutoStart]`),this.playMedia()))},playMedia(){if(this.node!=null){if(this.mediaType==="audio")return this.node.playAudio();this.node.playVideo()}},checkMaxPlaysLimit(){if(this.maxPlays*1===0)return!1;const e=this.getResponse();return e!==null&&e==this.maxPlays*1},computeMaxPlaysMessage(){if(typeof this.dataMaxPlaysMessage<"u"){this.maxPlaysMessage=this.dataMaxPlaysMessage;return}const e=this.maxPlays*1;this.maxPlaysMessage=e===0?"":`You are permitted a maximum of ${this.maxPlays} play${e>1?"s":""} for this ${this.mediaType}.`},computeMinPlaysMessage(){if(typeof this.dataMinPlaysMessage<"u"){this.minPlaysMessage=this.dataMinPlaysMessage;return}const e=this.minPlays*1;this.minPlaysMessage=e===0?"":`You must play this ${this.mediaType} to the end at least ${this.minPlays} time${e>1?"s":""}.`},validateChildren(){},processChildren(){this.processMedia(),this.setIsValid(this.computeIsValid()),this.priorState!==null&&this.restoreValue(this.priorState.value)},processMedia(){let e=this.$refs.mediagroup.$el.getElementsByTagName("object");if(e.length!==0)throw new c("Unsupported Media Interaction element. The <object> elemnt is deprecated. Use <video> or <audio> instead.");if(e=this.$refs.mediagroup.$el.getElementsByTagName("video"),e.length===0&&(e=this.$refs.mediagroup.$el.getElementsByTagName("audio")),e.length!==1)throw new c("Media Interaction must have exactly one <video> or <audio> node.")},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Media Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Media Interaction State Invalid. "state" property not found.');return t}},created(){try{this.responseDeclaration=fw.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.validateChildren(),this.priorState=this.getPriorState(this.responseIdentifier),fw.validateMaxMinPlays(this.maxPlays,this.minPlays),this.hasPrompts=this.getPrompts(this.$slots).length>0,this.isAutostart=this.autostart==="true",this.isLoop=this.loop==="true",this.computeMaxPlaysMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),this.processChildren(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"Media",node:this,resetValue:this.resetValue,disable:this.disable,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxPlaysMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},Uk={ref:"root",class:"qti-media-interaction"},Gk={ref:"prompt",class:"qti-prompt-wrapper"};function jk(e,t,i,s,n,r){const a=l.resolveComponent("MediaGroup");return l.openBlock(),l.createElementBlock("div",Uk,[l.createElementVNode("div",Gk,null,512),l.createVNode(a,{ref:"mediagroup",onMediaMounted:r.handleMediaMounted,onMediaLoaded:r.handleMediaLoaded,onMediaEnded:r.handleMediaEnded},{default:l.withCtx(()=>[l.renderSlot(e.$slots,"default")]),_:3},8,["onMediaMounted","onMediaLoaded","onMediaEnded"])],512)}const Wk=P(Fk,[["render",jk]]),Fh=new G,zk={name:"QtiOrderInteraction",props:{responseIdentifier:{required:!0,type:String},minChoices:{required:!1,type:String},maxChoices:{required:!1,type:String},shuffle:{required:!1,type:String,default:"false"},orientation:{required:!1,type:String,default:"horizontal"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String},dataChoicesContainerWidth:{required:!1,type:String,default:null}},data(){return{response:null,state:null,isValidResponse:!1,cardinality:"ordered",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,interactionSubType:"default",choices:[],isShuffle:!1,hasPrompts:!1,minChoicesValue:null,maxChoicesValue:null,isMinChoicesSpecified:!1,isMaxChoicesSpecified:!1,isQtiValid:!0,priorState:null,originalOrder:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},setInteractionSubType(e){this.interactionSubType=e},getInteractionSubType(){return this.interactionSubType},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},getInvalidResponseMessage(){return this.minSelectionsMessage},disable(){this.$refs.ordergroup.disable()},enable(){this.$refs.ordergroup.enable()},initializeValue(e){this.setResponse(this.computeResponse(e)),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},initializeOriginalOrder(){if(this.originalOrder!==null)return;let e=[];this.choices.forEach(t=>{e.push(t.identifier)}),this.originalOrder=e},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.setResponse(null),this.setState(null),this.priorState=null,this.$refs.ordergroup.resetGroupUI()},restoreValue(e){this.setResponse(e),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality:"ordered",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){this.hasPrompts&&this.$refs.prompt.appendChild(this.$refs.ordergroup.getPromptElement())},handleOrderGroupReady(e){this.choices=e.choices,this.isMinChoicesSpecified||(this.minChoicesValue=this.choices.length),this.originalOrder===null&&this.initializeOriginalOrder(),this.initializeValue(e.response)},handleOrderGroupUpdate(e){this.setResponse(this.computeResponse(e.response)),this.setState({order:e.response,oorder:this.originalOrder}),this.updateValidity(this.computeIsValid())},handleSelectionsLimit(){I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage)},computeResponse(e){let t=[];typeof e>"u"?this.choices.forEach(s=>{t.push(s.identifier)}):t=e;let i=0;switch(this.interactionSubType){case"default":for(let s=0;s<t.length;s++)t[s]!==this.originalOrder[s]&&(i+=1);break;case"ordermatch":for(let s=0;s<t.length;s++)t[s]!==null&&(i+=1);break}return i===0?null:t},computeOrder(){const e=[];return this.choices.forEach(t=>{e.push(t.identifier)}),e},computeState(){return this.priorState!==null?this.priorState.state:{order:this.computeOrder(),oorder:this.originalOrder}},computeIsValid(){const e=this.getResponse(),t=this.minChoicesValue;if(e===null||e.length!==this.originalOrder.length)return!1;let i=0;switch(this.interactionSubType){case"default":for(let s=0;s<e.length;s++)e[s]!==this.originalOrder[s]&&(i+=1);return this.isMinChoicesSpecified?i>=t:i===t;case"ordermatch":for(let s=0;s<e.length;s++)e[s]!==null&&(i+=1);return this.isMinChoicesSpecified?i>=t:i===e.length}return!1},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxChoicesValue===null?"":"You may set an order for a maximum of "+this.maxChoicesValue+" choice"+(this.maxChoicesValue>1?"s":"")+" for this question."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.isMinChoicesSpecified?this.minSelectionsMessage="You must set the order for at least "+this.minChoicesValue+" choice"+(this.minChoicesValue>1?"s":"")+" for this question.":this.minSelectionsMessage="You must set the order for all choices for this question."},detectInteractionSubType(e){return this.getOrderInteractionSubType(e)},getOrderInteractionSubType(e){if(typeof e>"u"||e===null||e.length==0)return"default";const t=e.split(" ");for(let i=0;i<t.length;i++)switch(t[i]){case"qti-choices-top":case"qti-choices-bottom":case"qti-choices-left":case"qti-choices-right":return"ordermatch"}return"default"},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Order Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Order Interaction State Invalid. "state" property not found.');if(!("order"in t.state))throw new O('Order Interaction State Invalid. "order" property not found.');if(!("oorder"in t.state))throw new O('Order Interaction State Invalid. "oorder" property not found.');return this.originalOrder=t.state.oorder,t}},created(){try{if(this.responseDeclaration=Fh.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.setInteractionSubType(this.detectInteractionSubType(this.$.vnode.props.class)),this.priorState=this.getPriorState(this.responseIdentifier),this.cardinality=this.getCardinality(),this.cardinality!=="ordered")throw new c('qti-order-interaction cardinality must be "ordered"');if(this.isShuffle=this.shuffle==="true",this.hasPrompts=this.getPrompts(this.$slots).length>0,typeof this.minChoices<"u"&&(this.isMinChoicesSpecified=!0),this.minChoicesValue=Fh.validateIntegerAttribute("min-choices",this.minChoices,!1,null),this.minChoicesValue===0)throw new c('qti-order-interaction "min-choices", when specified, must not be 0');if(this.isMinChoicesSpecified?(typeof this.maxChoices<"u"&&(this.isMaxChoicesSpecified=!0),this.maxChoicesValue=Fh.validateIntegerAttribute("max-choices",this.maxChoices,!1,null)):this.maxChoicesValue=null,this.isMinChoicesSpecified&&this.isMaxChoicesSpecified&&this.minChoicesValue>this.maxChoicesValue)throw new c('qti-order-interaction "min-choices" must not be greater than "max-choices"');this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"Order",node:this,resetValue:this.resetValue,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},Kk={ref:"root",class:"qti-order-interaction"},Yk={ref:"prompt",class:"qti-prompt-wrapper"};function Xk(e,t,i,s,n,r){const a=l.resolveComponent("OrderGroup");return l.openBlock(),l.createElementBlock("div",Kk,[l.createElementVNode("div",Yk,null,512),l.createVNode(a,l.mergeProps({ref:"ordergroup",cardinality:n.cardinality,shuffle:i.shuffle,responseIdentifier:i.responseIdentifier,orientation:i.orientation,maxChoices:n.maxChoicesValue,minChoices:n.minChoicesValue,interactionSubType:n.interactionSubType,dataChoicesContainerWidth:i.dataChoicesContainerWidth,priorState:n.priorState,onOrderGroupReady:r.handleOrderGroupReady,onOrderGroupUpdate:r.handleOrderGroupUpdate,onOrderGroupSelectionsLimit:r.handleSelectionsLimit},e.$attrs),{default:l.withCtx(()=>[l.renderSlot(e.$slots,"default")]),_:3},16,["cardinality","shuffle","responseIdentifier","orientation","maxChoices","minChoices","interactionSubType","dataChoicesContainerWidth","priorState","onOrderGroupReady","onOrderGroupUpdate","onOrderGroupSelectionsLimit"])],512)}const Zk=P(zk,[["render",Xk]]);class Jk{constructor(){this.nodes=[]}find(t,i){if(Array.isArray(t))return t.forEach(s=>{var n;if(s.component!==null&&((n=s.component.type)==null?void 0:n.name)===i){this.nodes.push(s.component.proxy);return}Array.isArray(s==null?void 0:s.children)&&this.find(s.children,i)}),this.nodes}findNodes(t,{within:i}){return this.find(i,t)}}class e2{constructor(t){return this.constants={QTI_UNSELECTED_HIDDEN:"qti-unselected-hidden"},this.classList=t,this.presentation_UnselectedHidden=!1,this.processClassAttribute(),this}processClassAttribute(){if(typeof this.classList>"u"||this.classList===null||this.classList.length==0)return;const t=this.classList.split(" ");for(let i=0;i<t.length;i++)switch(t[i]){case this.constants.QTI_UNSELECTED_HIDDEN:this.presentation_UnselectedHidden=!0;break}}getUnselectedHidden(){return this.presentation_UnselectedHidden}}const pw=new G,t2=new Jk,i2={name:"QtiHottextInteraction",props:{responseIdentifier:{required:!0,type:String},minChoices:{required:!1,type:String,default:"0"},maxChoices:{required:!1,type:String,default:"1"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String}},inheritAttrs:!0,data(){return{response:null,state:null,isValidResponse:!1,cardinality:"single",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,choices:[],currentChoice:null,isRadio:!0,isDisabled:!1,isQtiValid:!0,hasPrompts:!1,presentationFactory:null,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},disable(){this.toggleDisableChoices(!0)},enable(){this.toggleDisableChoices(!1)},toggleDisableChoices(e){this.isDisabled=e,this.choices.forEach(t=>{t.setIsDisabled(e)})},getInvalidResponseMessage(){return this.minSelectionsMessage},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.choices.forEach(e=>{e.setChecked(!1)}),this.currentChoice=null,this.priorState=null},restoreValue(e){e!==null&&(this.isRadio?this.handleSetChecked(new CustomEvent("setChecked",{bubbles:!1,detail:{identifier:e,checked:"true"}}),!0):e.forEach(t=>{this.handleSetChecked(new CustomEvent("setChecked",{bubbles:!1,detail:{identifier:t,checked:"true"}}),!0)},this),this.setResponse(this.computeResponse()),this.setState(this.computeState()),this.updateValidity(this.computeIsValid()))},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality!=="multiple"?"single":"multiple":"single",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},handleSetChecked(e,t=!1){const i=e.detail;this.choices.forEach(s=>{this.isRadio&&s.setChecked(!1),s.identifier===i.identifier&&(this.currentChoice=s)}),i.checked==="true"?this.checkMaxChoicesLimit()?this.currentChoice.setChecked(!1):this.currentChoice.setChecked(!0):this.currentChoice.setChecked(!1),t||(this.setResponse(this.computeResponse()),this.currentChoice.setFocus(),this.evaluateValidity())},computeResponse(){let e=this.isRadio?null:[];return this.choices.forEach(t=>{t.isChecked()&&(this.isRadio?e=t.identifier:e.push(t.identifier))}),this.isRadio?e:e.length===0?null:e},computeState(){return{}},computeIsValid(){return this.minChoices*1===0?!0:this.response===null?!1:this.cardinality==="single"||this.cardinality==="multiple"&&this.response.length>=this.minChoices*1},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},checkMaxChoicesLimit(){if(this.isRadio||this.maxChoices==0)return!1;const e=this.getResponse();return e!==null&&e.length==this.maxChoices?(I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage),!0):!1},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxChoices==0?"":"You are permitted a maximum of "+this.maxChoices+" selection"+(this.maxChoices>1?"s":"")+" for this question.<br/><br/>Please unselect one of your selections before making another selection."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.minSelectionsMessage=this.minChoices==0?"":"You must make at least "+this.minChoices+" selection"+(this.minChoices>1?"s":"")+" for this question."},validateChildren(){},processChildren(){const e=this.$.subTree===null?null:this.$.subTree.children[1].children;this.choices=t2.findNodes("QtiHottext",{within:e}),this.processGroupUI(),this.priorState!==null&&this.restoreValue(this.priorState.value)},processGroupUI(){this.setUnselectedHidden(),this.setResponse(null),this.setState(this.computeState()),this.setIsValid(this.computeIsValid())},setUnselectedHidden(){this.presentationFactory.getUnselectedHidden()&&this.$refs.hottextgroup.setAttribute("class","qti3-player-hottext-group qti-unselected-hidden")},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Hottext Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Hottext Interaction State Invalid. "state" property not found.');return t}},created(){try{this.responseDeclaration=pw.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.presentationFactory=new e2(this.$.vnode.props.class),this.validateChildren(),this.priorState=this.getPriorState(this.responseIdentifier),pw.validateMaxMinChoices(this.maxChoices,this.minChoices),this.isRadio=this.getCardinality()!=="multiple",this.hasPrompts=this.getPrompts(this.$slots).length>0,this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),this.processChildren(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"Hottext",node:this,resetValue:this.resetValue,disable:this.disable,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},s2={ref:"root",class:"qti-hottext-interaction"},n2={ref:"prompt",class:"qti-prompt-wrapper"};function r2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",s2,[l.createElementVNode("div",n2,null,512),l.createElementVNode("div",{ref:"hottextgroup","on:setChecked":t[0]||(t[0]=(...a)=>r.handleSetChecked&&r.handleSetChecked(...a)),class:"qti3-player-hottext-group"},[l.renderSlot(e.$slots,"default")],544)],512)}const a2=P(i2,[["render",r2]]);class o2{constructor(t){return this.constants={QTI_SELECTIONS_LIGHT:"qti-selections-light",QTI_SELECTIONS_DARK:"qti-selections-dark",QTI_UNSELECTED_HIDDEN:"qti-unselected-hidden",THEME_LIGHT:{selectedOpacity:"1.0",unselectedOpacity:"0.5",fillColor:"orange",fillOpacity:"0",strokeColor:"orange",strokeWidth:2,selectedStrokeWidth:4},THEME_DARK:{selectedOpacity:"1.0",unselectedOpacity:"0.5",fillColor:"#0088CC",fillOpacity:"0",strokeColor:"blue",strokeWidth:2,selectedStrokeWidth:4},THEME_HIDDEN_LIGHT:{selectedOpacity:"1.0",unselectedOpacity:"0",fillColor:"orange",fillOpacity:"0",strokeColor:"orange",strokeWidth:2,selectedStrokeWidth:4},THEME_HIDDEN_DARK:{selectedOpacity:"1.0",unselectedOpacity:"0",fillColor:"blue",fillOpacity:"0",strokeColor:"blue",strokeWidth:2,selectedStrokeWidth:4}},this.classList=t,this.presentation_Theme=this.constants.QTI_SELECTIONS_DARK,this.theme=this.constants.THEME_DARK,this.presentation_UnselectedHidden=!1,this.processClassAttribute(),this}processClassAttribute(){if(typeof this.classList>"u"||this.classList===null||this.classList.length==0)return;const t=this.classList.split(" ");for(let i=0;i<t.length;i++)switch(t[i]){case this.constants.QTI_SELECTIONS_DARK:this.presentation_Theme=this.constants.QTI_SELECTIONS_DARK;break;case this.constants.QTI_SELECTIONS_LIGHT:this.presentation_Theme=this.constants.QTI_SELECTIONS_LIGHT;break;case this.constants.QTI_UNSELECTED_HIDDEN:this.presentation_UnselectedHidden=!0;break}switch(this.presentation_Theme){case this.constants.QTI_SELECTIONS_DARK:this.presentation_UnselectedHidden&&(this.theme=this.constants.THEME_HIDDEN_DARK);break;case this.constants.QTI_SELECTIONS_LIGHT:this.presentation_UnselectedHidden?this.theme=this.constants.THEME_HIDDEN_LIGHT:this.theme=this.constants.THEME_LIGHT;break}}getThemeColors(){return this.theme}}const mw=new G,l2={name:"QtiHotspotInteraction",props:{responseIdentifier:{required:!0,type:String},minChoices:{required:!1,type:String,default:"0"},maxChoices:{required:!1,type:String,default:"1"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String}},data(){return{response:null,state:null,isValidResponse:!1,cardinality:"single",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,choices:[],currentChoice:null,shapeElements:[],currentElement:null,backgroundImage:null,backgroundImageWidth:"0",backgroundImageHeight:"0",isRadio:!0,isDisabled:!1,isQtiValid:!0,hasPrompts:!1,presentationFactory:null,shapeColorProperties:null,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},disable(){this.toggleDisableChoices(!0)},enable(){this.toggleDisableChoices(!1)},toggleDisableChoices(e){this.isDisabled=e},getInvalidResponseMessage(){return this.minSelectionsMessage},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier);for(let e=0;e<this.choices.length;e++)this.setChoiceUnChecked(this.choices[e],this.shapeElements[e]);this.currentChoice=null,this.currentElement=null,this.priorState=null,this.setResponse(null),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},restoreValue(e){e!==null&&(this.isRadio?this.handleSetChecked(new CustomEvent("setChecked",{bubbles:!1,detail:{identifier:e,checked:"true"}}),!0):e.forEach(t=>{this.handleSetChecked(new CustomEvent("setChecked",{bubbles:!1,detail:{identifier:t,checked:"true"}}),!0)},this),this.setResponse(this.computeResponse()),this.setState(this.computeState()),this.updateValidity(this.computeIsValid()))},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality!=="multiple"?"single":"multiple":"single",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},handleSetChecked(e,t=!1){const i=e.detail;for(let s=0;s<this.choices.length;s++)this.isRadio&&this.setChoiceUnChecked(this.choices[s],this.shapeElements[s]),this.choices[s].identifier===i.identifier&&(this.currentChoice=this.choices[s],this.currentElement=this.shapeElements[s]);i.checked==="true"?this.checkMaxChoicesLimit()?this.setChoiceUnChecked(this.currentChoice,this.currentElement):this.setChoiceChecked(this.currentChoice,this.currentElement):this.setChoiceUnChecked(this.currentChoice,this.currentElement),t||(this.setResponse(this.computeResponse()),this.currentElement.focus(),this.evaluateValidity())},computeResponse(){let e=this.isRadio?null:[];return this.choices.forEach(t=>{t.isChecked()&&(this.isRadio?e=t.identifier:e.push(t.identifier))}),this.isRadio?e:e.length===0?null:e},computeState(){return{}},computeIsValid(){return this.minChoices*1===0?!0:this.response===null?!1:this.cardinality==="single"||this.cardinality==="multiple"&&this.response.length>=this.minChoices*1},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},checkMaxChoicesLimit(){if(this.isRadio||this.maxChoices==0)return!1;const e=this.getResponse();return e!==null&&e.length==this.maxChoices?(I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage),!0):!1},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxChoices==0?"":"You are permitted a maximum of "+this.maxChoices+" selection"+(this.maxChoices>1?"s":"")+" for this question.<br/><br/>Please unselect one of your selections before making another selection."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.minSelectionsMessage=this.minChoices==0?"":"You must make at least "+this.minChoices+" selection"+(this.minChoices>1?"s":"")+" for this question."},validateChildren(){},processChildren(){this.processBackgroundImage(),this.$.subTree.children[1].children[0].children.forEach(t=>{if(t.component!==null&&t.type.name==="QtiHotspotChoice"){const i=t.component.proxy;this.choices.push(i);const s=i.getShapeElement();s!==null&&(this.addHotspotListeners(s),this.shapeElements.push(s),this.$refs.overlay.appendChild(s))}}),this.processGroupUI(),this.priorState!==null&&this.restoreValue(this.priorState.value)},addHotspotListeners(e){e.addEventListener("click",this.handleHotspotClick),e.addEventListener("keydown",this.handleHotspotKeydown)},removeHotspotListeners(e){e.removeEventListener("click",this.handleHotspotClick),e.removeEventListener("keydown",this.handleHotspotKeydown)},handleHotspotClick(e){if(e.preventDefault(),this.isDisabled)return;const t=e.target.getAttribute("data-identifier"),i=this.findChoiceByIdentifier(t);this.isRadio?this.triggerChecked(e.target.getAttribute("data-identifier"),"true"):(this.toggleChecked(i,e.target),this.triggerChecked(t,i.getChecked()))},handleHotspotKeydown(e){const t=e.target.getAttribute("data-identifier"),i=this.findChoiceByIdentifier(t);switch(e.code){case"Space":case"Enter":if(e.stopPropagation(),e.preventDefault(),this.isDisabled||i==null)return;this.toggleChecked(i,e.target),this.triggerChecked(t,i.getChecked());break}},findChoiceByIdentifier(e){for(let t=0;t<this.choices.length;t++)if(this.choices[t].identifier===e)return this.choices[t];return null},toggleChecked(e,t){if(e.toggleChecked(),t===null)return;const i=t.getAttribute("aria-checked");t.setAttribute("aria-checked",i==="true"?"false":"true")},triggerChecked(e,t){const i=new CustomEvent("setChecked",{bubbles:!0,cancelable:!0,detail:{identifier:e,checked:t}});this.$refs.hotspotgroup.dispatchEvent(i)},setChoiceUnChecked(e,t){e.setChecked(!1),t.setAttribute("aria-checked","false");const i=e.getShapeColorProperties();t.setAttribute("fill",`${i.fillColor}`),t.setAttribute("fill-opacity",`${i.fillOpacity}`),t.setAttribute("opacity",`${i.unselectedOpacity}`),t.setAttribute("stroke",`${i.strokeColor}`),t.setAttribute("stroke-width",`${i.strokeWidth}`)},setChoiceChecked(e,t){e.setChecked(!0),t.setAttribute("aria-checked","true");const i=e.getShapeColorProperties();t.setAttribute("fill",`${i.fillColor}`),t.setAttribute("fill-opacity",`${i.fillOpacity}`),t.setAttribute("opacity",`${i.selectedOpacity}`),t.setAttribute("stroke",`${i.strokeColor}`),t.setAttribute("stroke-width",`${i.selectedStrokeWidth}`)},processGroupUI(){this.setResponse(null),this.setState(this.computeState()),this.setIsValid(this.computeIsValid())},processBackgroundImage(){let e=this.$refs.hotspotgroup.getElementsByTagName("object");if(e.length===0&&(e=this.$refs.hotspotgroup.getElementsByTagName("img")),e.length===0&&(e=this.$refs.hotspotgroup.getElementsByTagName("picture")),e.length!==1)throw new c("Hotspot interaction must have exactly one <img>, <object>, or <picture> node");this.backgroundImage=e[0],this.backgroundImage.setAttribute("draggable","false"),this.backgroundImageWidth=`${e[0].clientWidth}`,this.backgroundImageHeight=`${e[0].clientHeight}`,this.$refs.overlay.setAttribute("viewBox",`0 0 ${this.backgroundImageWidth} ${this.backgroundImageHeight}`),this.$refs.overlay.setAttribute("tabindex","-1"),this.$refs.overlay.setAttribute("role","application"),this.$refs.overlay.setAttribute("focusable","false"),this.$refs.hotspotgroup.setAttribute("style",`width:${e[0].clientWidth};height:${e[0].clientHeight}`)},getShapeColorProperties(){return this.shapeColorProperties},setShapeColorProperties(e){this.shapeColorProperties=e},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Hotspot Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Hotspot Interaction State Invalid. "state" property not found.');return t}},created(){try{this.responseDeclaration=mw.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.presentationFactory=new o2(this.$.vnode.props.class),this.setShapeColorProperties(this.presentationFactory.getThemeColors()),this.validateChildren(),this.priorState=this.getPriorState(this.responseIdentifier),mw.validateMaxMinChoices(this.maxChoices,this.minChoices),this.isRadio=this.getCardinality()!=="multiple",this.hasPrompts=this.getPrompts(this.$slots).length>0,this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),this.processChildren(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"Hotspot",node:this,resetValue:this.resetValue,disable:this.disable,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}},beforeUnmount(){this.shapeElements.forEach(e=>{this.removeHotspotListeners(e)})}},c2={ref:"root",class:"qti-hotspot-interaction"},u2={ref:"prompt",class:"qti-prompt-wrapper"},h2={ref:"overlay",class:"qti3-player-hotspot-overlay"};function d2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",c2,[l.createElementVNode("div",u2,null,512),l.createElementVNode("div",{ref:"hotspotgroup","on:setChecked":t[0]||(t[0]=(...a)=>r.handleSetChecked&&r.handleSetChecked(...a)),class:"qti3-player-hotspot-group"},[l.renderSlot(e.$slots,"default"),(l.openBlock(),l.createElementBlock("svg",h2,null,512))],544)],512)}const f2=P(l2,[["render",d2]]);class p2{constructor(t,i,s){J(this,"moduleAttribute","");J(this,"modulesNode",null);J(this,"itemPathUri","");J(this,"modules",null);J(this,"constants",{BASE_CONFIG:{waitSeconds:60,paths:{}}});return this.moduleAttribute=t,this.modulesNode=i,this.itemPathUri=s,this}async getConfiguration(t){this.setModules(this.getInteractionModules());let i=null;this.moduleAttribute.length>0&&this.modulesNode===null?i=await this.getConfigurationFromUrl(this.getModules()):i=await this.resolveModules(this.getModules()),t&&t(i)}async resolveModules(t){let i=null;if(t===null)return i;let s=this.constants.BASE_CONFIG;return s=await this.initBaseConfiguration(s,t),i=await this.resolvePrimaryConfigurationModules(s,t),i!==null||(i=await this.resolveSecondaryConfigurationModules(s,t)),i}async initBaseConfiguration(t,i){const s=`${this.getItemPathUri()}modules/module_resolution.js`;if(typeof i.primaryconfiguration>"u"&&typeof i.secondaryConfiguration>"u"){const n=await this.fetchDefaultModuleResolution(s,!1);if(n!==null)return n}return t}async resolvePrimaryConfigurationModules(t,i){let s=[];if(typeof i.primaryconfiguration>"u"){for(let o=0;o<i.module.length;o++){if(typeof i.module[o].primarypath>"u")return null;s.push(this.addPathJs(i.module[o].primarypath)),t.paths[i.module[o].id]=this.stripPathJs(i.module[o].primarypath)}return await this.resolveConfigurationModules(s)?t:null}const n=await this.fetchConfiguration(i.primaryconfiguration,!0,!0);if(n===null)return null;for(const a in n.paths)n.paths[a]=this.stripPathJs(n.paths[a]);for(let a=0;a<i.module.length;a++)typeof i.module[a].primarypath<"u"&&(n.paths[i.module[a].id]=this.stripPathJs(this.addPathJs(i.module[a].primarypath)));return await this.resolveConfigurationPathUrls(n.paths)?n:null}async resolveSecondaryConfigurationModules(t,i){let s=[];if(typeof i.secondaryconfiguration>"u"){for(let o=0;o<i.module.length;o++){if(typeof i.module[o].fallbackpath>"u")return null;s.push(this.addPathJs(i.module[o].fallbackpath)),t.paths[i.module[o].id]=this.stripPathJs(i.module[o].fallbackpath)}return await this.resolveConfigurationModules(s)?t:null}const n=await this.fetchConfiguration(i.secondaryconfiguration,!1,!0);if(n===null)return null;for(const a in n.paths)n.paths[a]=this.stripPathJs(n.paths[a]);for(let a=0;a<i.module.length;a++)typeof i.module[a].fallbackpath<"u"&&(n.paths[i.module[a].id]=this.stripPathJs(this.addPathJs(i.module[a].fallbackpath)));return await this.resolveConfigurationPathUrls(n.paths)?n:null}async resolveConfigurationPathUrls(t){let i=[];for(let n=0;n<t.length;n++)i.push(t[n]);return await this.resolveConfigurationModules(i)}async resolveConfigurationModules(t){return await Promise.all(t.map(s=>fetch(s).then(n=>{if(n.ok)return console.log("[PCI Parent] Module Loader Success:",s),n;throw new Error(s)}))).catch(s=>(console.log("[PCI Parent] Module Loader Failure:",s.message),null))!==null}async getConfigurationFromUrl(t){let i=null;return t===null||(typeof t.primaryconfiguration<"u"&&(i=await this.fetchConfiguration(t.primaryconfiguration,!0,!1)),i!==null)||typeof t.secondaryconfiguration<"u"&&(i=await this.fetchConfiguration(t.secondaryconfiguration,!1,!1)),i}async fetchConfiguration(t,i,s){try{const n=await fetch(t);if(!n.ok)throw new Error(`HTTP error: ${n.status}`);const r=await n.json();let a=r.paths;for(let o in a)a[o]!==null&&!a[o].startsWith("http")&&(s?a[o]=`${this.getConfigurationRelativePath(t)}${a[o]}`:a[o]=`${this.getItemPathUri()}${a[o]}`);return r}catch(n){return console.log((i?"Primary":"Fallback")+" Configuration Fetch error:",n),null}}async fetchDefaultModuleResolution(t,i){try{const s=await fetch(t);if(!s.ok)throw new Error(`HTTP error: ${s.status}`);const n=await s.json();let r=n.paths;for(let a in r)r[a]!==null&&!r[a].startsWith("http")&&(i?r[a]=`${this.getConfigurationRelativePath(t)}${r[a]}`:r[a]=`${this.getItemPathUri()}${r[a]}`);return n}catch(s){return console.log("module_resolution.js Fetch error:",s),null}}getItemPathUri(){return this.itemPathUri}getModules(){return this.modules}setModules(t){this.modules=t}getInteractionModules(){let t={};if(this.modulesNode===null)return t={primaryconfiguration:"modules/module_resolution.js",secondaryconfiguration:"modules/fallback_module_resolution.js"},this.addPackagePath(t);const i=this.modulesNode.getPrimaryConfiguration();i.length>0&&(t.primaryconfiguration=i);const s=this.modulesNode.getSecondaryConfiguration();s.length>0&&(t.secondaryconfiguration=s),t.module=[];let n=this.modulesNode.getModules();for(let r=0;r<n.length;r++){let a={id:n[r].getId()};n[r].getPrimaryPath().length>0&&(a.primarypath=n[r].getPrimaryPath()),n[r].getFallbackPath().length>0&&(a.fallbackpath=n[r].getFallbackPath()),t.module.push(a)}return this.addPackagePath(t)}addPackagePath(t){for(let s in{primaryconfiguration:"",secondaryconfiguration:""})s in t&&t[s]!==null&&!t[s].startsWith("http")&&(t[s]=this.getAbsolutePath(this.getItemPathUri(),t[s]));let i=t.module;if(i!=null)for(let s=0;s<i.length;s++){let n=i[s];for(let r in{primarypath:"",fallbackpath:""})r in n&&n[r]!==null&&!n[r].startsWith("http")&&(n[r]=this.getAbsolutePath(this.getItemPathUri(),n[r]))}return t}getAbsolutePath(t,i){let s=t.split("/"),n=i.split("/");s.pop();for(var r=0;r<n.length;r++)n[r]!="."&&(n[r]==".."?s.pop():s.push(n[r]));return s.join("/")}getConfigurationRelativePath(t){if(t===null||t.length===0)return"";const i=t.lastIndexOf("/");return i<0?"":t.substring(0,i+1)}stripPathJs(t){return t===null?null:t.endsWith(".js")?t.slice(0,t.lastIndexOf(".")):t}addPathJs(t){return t===null?null:t.length>0&&!t.endsWith(".js")?`${t}.js`:t}}const Uh=new G,Rl=new ie,m2={name:"QtiPortableCustomInteraction",props:{responseIdentifier:{required:!0,type:String},customInteractionTypeIdentifier:{required:!0,type:String},module:{required:!1,type:String,default:""},dataItemPathUri:{required:!1,type:String,default:""}},inheritAttrs:!0,data(){return{response:null,state:null,baseType:null,cardinality:null,isValidResponse:!0,isQtiValid:!0,hasPrompts:!1,pciModuleResolver:null,loadIframeHandler:null,renderer:"",classAttribute:"",properties:{},modulesNode:null,modules:null,configuration:null,templateVariables:[],contextVariables:[],stylesheets:[],catalogInfoNode:null,uniqueId:null,pciIframe:null,isReady:!1,initialWidth:0,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},getStateRequest(){this.pciIframe.contentWindow.postMessage({message:"PciGetState_Request"},"*")},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},getInvalidResponseMessage(){return""},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.priorState=null},restoreValue(e,t){this.setResponse(e),this.setState(t)},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=e.cardinality,this.cardinality},getBaseType(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.baseType=e.baseType,this.baseType},getPrompts(e){let t=[];return e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},computeState(){return{}},computeIsValid(){return!0},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},validateChildren(){if(!this.$slots.default)return;let e=!1,t=!1,i=!1,s=!1,n=!1,r=!1,a=!1;this.$slots.default().forEach(o=>{if(Uh.isValidSlot(o)){if(o.type.name==="QtiPrompt"){if(t||i||s||n||r||a)throw new c("Invalid element order. qti-prompt must be the first element");if(!e)return e=!0;throw new c("Maximum of 1 qti-prompt element permitted")}if(o.type.name==="QtiInteractionModules"){if(t||s||n||r||a)throw new c("Invalid element order: qti-interaction-modules");if(!i)return i=!0;throw new c("Maximum of 1 qti-interaction-modules element permitted")}if(o.type.name==="QtiInteractionMarkup"){if(s||n||r||a)throw new c("Invalid element order: qti-interaction-markup");if(!t)return t=!0;throw new c("Maximum of 1 qti-interaction-markup element permitted")}if(o.type.name==="QtiTemplateVariable"){if(s||r||a)throw new c("Invalid element order: qti-template-variable");return n=!0}if(o.type.name==="QtiContextVariable"){if(r||a)throw new c("Invalid element order: qti-context-variable");return s=!0}if(o.type.name==="QtiStylesheet"){if(a)throw new c("Invalid element order: qti-stylesheet");return r=!0}if(o.type.name==="QtiCatalogInfo"){if(!a)return a=!0;throw new c("Maximum of 1 qti-catalog-info element permitted")}throw new c('Node is not permitted inside QtiPortableCustomInteraction: "'+o.type.name+'"')}})},processChildren(){const e=this.$.subTree.children[1].children[0].children;e!==null&&(e.forEach(t=>{if(t.component===null)return;const i=t.component.proxy;switch(t.type.name){case"QtiInteractionMarkup":this.markup=i.getMarkup();break;case"QtiInteractionModules":this.modulesNode=i;break;case"QtiTemplateVariable":this.templateVariables.push(i);break;case"QtiContextVariable":this.contextVariables.push(i);break;case"QtiStylesheet":this.stylesheets.push(i);break;case"QtiCatalogInfo":this.catalogInfoNode=i;break}}),this.priorState!==null&&this.restoreValue(this.priorState.value,this.priorState.state),this.initialWidth=this.$refs.root.clientWidth)},disable(){},enable(){},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('PCI State Invalid. "value" property not found.');if(!("state"in t))throw new O('PCI State Invalid. "state" property not found.');return t},createId(){return"pci_"+Uh.randomString(5,"a")},initialize(){this.setProperties(this.getPciProperties()),this.pciModuleResolver=new p2(this.module,this.modulesNode,this.dataItemPathUri),this.pciModuleResolver.getConfiguration((function(e){this.setConfiguration(e),console.log("[PCI Parent] PCI Configuration:",e),e!==null&&this.loadPciIframe(this.initialWidth)}).bind(this))},loadPciIframe(e){const t=document.createElement("iframe");t.name=this.uniqueId,t.id=this.uniqueId,t.setAttribute("scrolling","no"),t.style.border="none",t.style.width=`${e}px`,t.addEventListener("load",this.loadIframeHandler),t.src=`${this.renderer}?identifier=${this.responseIdentifier}&uniqueId=${this.uniqueId}`,this.$refs.ic.appendChild(t)},handleLoadIframe(e){this.pciIframe=e.target},getItemPathUri(){return this.dataItemPathUri},getPciProperties(){let e=this.$refs.root;const t={};for(let i in e.dataset)i!=="uniqueId"&&(t[i]=Rl.encodeBytesToBase64(e.dataset[i]));return t},getProperties(){return this.properties},setProperties(e){this.properties=e},getContextVariables(){let e={};for(let t=0;t<this.contextVariables.length;t++)e[this.contextVariables[t].getIdentifier()]=this.contextVariables[t].evaluate();return e},getTemplateVariables(){let e={};for(let t=0;t<this.templateVariables.length;t++)e[this.templateVariables[t].getIdentifier()]=this.templateVariables[t].evaluate();return e},getStylesheets(){let e=[];for(let t=0;t<this.stylesheets.length;t++){const i=this.stylesheets[t],s=Rl.encodeBytesToBase64(i.getRawCss());e.push({href:i.getHref(),type:i.getType(),css:`${s}`})}return e},getCatalogInfo(){return this.catalogInfoNode},getModules(){return this.modules},setModules(e){this.modules=e},getConfiguration(){return this.configuration},setConfiguration(e){this.configuration=e},getClassAttribute(){return this.classAttribute},setClassAttribute(e){this.classAttribute=e},copyAttributes(e,t,i){return e.forEach(function(s){let n=s.replace("-","");t[n]=i.getAttribute(s)}),t},getResponseVariable(){let e=Rl.valueToPciJson(this.getResponse(),this.baseType,this.cardinality),t={};return t[this.responseIdentifier]=e,t},pciInitialize(){let e={typeIdentifier:this.customInteractionTypeIdentifier,classAttribute:this.getClassAttribute(),markup:this.markup,properties:this.getProperties(),boundTo:this.getResponseVariable(),templateVariables:this.getTemplateVariables(),contextVariables:this.getContextVariables(),stylesheets:this.getStylesheets(),catalogInfo:this.getCatalogInfo(),module:this.module,modules:this.getModules(),moduleResolution:this.getConfiguration(),status:I.getItemLifecycleStatus()},t={message:"PciLoadInteraction",pci:JSON.stringify(e)};this.priorState!==null&&(t.state=JSON.stringify({response:Rl.valueToPciJson(this.getResponse(),this.baseType,this.cardinality),state:this.getState()})),this.pciIframe.contentWindow.postMessage(t,"*")},pciResizeIframe(e,t){this.pciIframe!==null&&(this.pciIframe.style.height=`${e}px`,this.pciIframe.style.width=`${t}px`)},pciResizeIframeWidthToContainer(){this.pciIframe!==null&&(this.pciIframe.style.width=`${this.$refs.ic.clientWidth}px`)},pciSaveState(e){const t=JSON.parse(e);typeof t.response<"u"?this.setResponse(t.response):this.setResponse(null),typeof t.state<"u"?this.setState(t.state):this.setState(null),this.notifyInteractionStateReady()},pciSetReady(){this.isReady=!0},pciIsReady(){return this.pciIframe!==null&&this.isReady},notifyInteractionStateReady(){I.NotifyInteractionStateReady({identifier:this.responseIdentifier})}},created(){try{this.responseDeclaration=Uh.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.validateChildren(),this.renderer=I.getPciContextRenderer(),this.loadIframeHandler=this.handleLoadIframe.bind(this);const e=typeof this.$.vnode.props.class<"u"?this.$.vnode.props.class:"";this.setClassAttribute(e),this.priorState=this.getPriorState(this.responseIdentifier),this.hasPrompts=this.getPrompts(this.$slots).length>0,this.cardinality=this.getCardinality(),this.baseType=this.getBaseType(),this.uniqueId=this.createId()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),this.processChildren(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"PortableCustom",node:this,resetValue:this.resetValue,disable:this.disable,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:""}),this.initialize(),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}},beforeUnmount(){this.pciIframe!==null&&this.pciIframe.removeEventListener("load",this.loadIframeHandler)}},g2={ref:"root",class:"qti-portable-custom-interaction"},y2={ref:"prompt",class:"qti-prompt-wrapper"},w2={ref:"pcigroup",class:"qti3-player-pci-group"},b2={ref:"ic",class:"qti3-player-pci-iframe-container"};function v2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",g2,[l.createElementVNode("div",y2,null,512),l.createElementVNode("div",w2,[l.renderSlot(e.$slots,"default")],512),l.createElementVNode("div",b2,null,512)],512)}const E2=P(m2,[["render",v2]]),Gh=new G,C2={name:"QtiSelectPointInteraction",props:{responseIdentifier:{required:!0,type:String},minChoices:{required:!1,type:String,default:"0"},maxChoices:{required:!1,type:String,default:"0"},dataMaxSelectionsMessage:{required:!1,type:String},dataMinSelectionsMessage:{required:!1,type:String}},data(){return{response:null,state:null,isValidResponse:!1,cardinality:"single",minSelectionsMessage:"",maxSelectionsMessage:"",responseDeclaration:null,pointElements:new Map,backgroundImage:null,backgroundImageWidth:"0",backgroundImageHeight:"0",bgImageProperties:null,overlayId:"",markerType:"default",isResponsive:!1,interactionClassAttribute:null,pointRadius:9,isSingle:!0,isDisabled:!1,isQtiValid:!0,hasPrompts:!1,priorState:null}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},getState(){return this.state},setState(e){this.state=e},getIsValid(){return this.isValidResponse},setIsValid(e){this.isValidResponse=e},disable(){this.toggleDisablePoints(!0)},enable(){this.toggleDisablePoints(!1)},toggleDisablePoints(e){this.isDisabled=e},getInvalidResponseMessage(){return this.minSelectionsMessage},resetValue(){console.log("[ResetValue][identifier]",this.responseIdentifier),this.priorState=null,this.setResponse(null),this.deleteAllPoints(),this.setState(this.computeState()),this.updateValidity(this.computeIsValid())},restoreValue(e){if(e===null)return;e.state.points.forEach(i=>{this.restorePointElement(i)}),this.setState(e.state),this.setResponse(this.computeResponse()),this.updateValidity(this.computeIsValid())},getCardinality(){let e=I.getResponseDeclaration(this.responseIdentifier);return this.cardinality=typeof e<"u"?e.cardinality!=="multiple"?"single":"multiple":"single",this.cardinality},getPrompts(e){let t=[];return e.default&&e.default().forEach(i=>{typeof i.type<"u"&&i.type.name==="QtiPrompt"&&t.push(i)}),t},movePrompt(){if(!this.hasPrompts)return;const e=this.$refs.root.querySelector(".qti-prompt");e!==null&&this.$refs.prompt.appendChild(e)},computeResponse(){let e=this.isSingle?null:[];for(const t of this.pointElements.values()){const i=`${t.getAttribute("data-point")}`;this.isSingle?e=i:e.push(i)}return this.isSingle?e:e.length===0?null:e},computeState(){const e=[];for(const[t,i]of this.pointElements)e.push({id:t,marker:i.getAttribute("data-marker-type"),point:i.getAttribute("data-point"),static:i.getAttribute("class").includes("static")});return{points:e}},computeIsValid(){return this.minChoices*1===0?!0:this.response===null?!1:this.cardinality==="single"||this.cardinality==="multiple"&&this.response.length>=this.minChoices*1},evaluateValidity(){const e=this.getIsValid(),t=this.computeIsValid();e!==t&&this.updateValidity(t)},updateValidity(e){this.setIsValid(e),I.setInteractionIsValidResponse({identifier:this.responseIdentifier,isValidResponse:e})},checkMaxChoicesLimit(){return this.isSingle&&this.pointElements.size==0||!this.isSingle&&this.maxChoices==0||!this.isSingle&&this.pointElements.size<this.maxChoices?!1:(I.NotifyInteractionSelectionsLimit(this.maxSelectionsMessage),!0)},computeMaxSelectionsMessage(){if(typeof this.dataMaxSelectionsMessage<"u"){this.maxSelectionsMessage=this.dataMaxSelectionsMessage;return}this.maxSelectionsMessage=this.maxChoices==0?"":"You are permitted a maximum of "+this.maxChoices+" point"+(this.maxChoices>1?"s":"")+" for this question.<br/><br/>Please remove one of your points before making another point."},computeMinSelectionsMessage(){if(typeof this.dataMinSelectionsMessage<"u"){this.minSelectionsMessage=this.dataMinSelectionsMessage;return}this.minSelectionsMessage=this.minChoices==0?"":"You must make at least "+this.minChoices+" point"+(this.minChoices>1?"s":"")+" for this question."},createId(e){return`${e}${Gh.randomString(5,"a")}`},processChildren(){this.processBackgroundImage(),this.processGroupUI(),this.priorState!==null&&this.restoreValue(this.priorState)},addPointFromClick(e){const t=this.createId("p_"),i=this.createPointElement(e,this.markerType,t);this.addPointListeners(i),this.pointElements.set(t,i),this.$refs.overlay.appendChild(i),this.setState(this.computeState()),this.setResponse(this.computeResponse()),this.evaluateValidity()},deleteAllPoints(){for(const[e,t]of this.pointElements.values())this.deletePoint(e,t)},deletePoint(e,t){this.removePointListeners(t),this.pointElements.delete(e),t.remove()},createPointElement(e,t,i){const s=this.convertPoint(e.x,e.y,!1);return this.newPointElement(i,e,s,t,!0)},restorePointElement(e){const t=e.point.split(" ");if(t.length!==2)return;const i=this.convertPoint(t[0],t[1],!0),s={x:t[0],y:t[1]},n=this.newPointElement(e.id,i,s,e.marker,e.static);this.addPointListeners(n),this.pointElements.set(e.id,n),this.$refs.overlay.appendChild(n)},convertPoint(e,t,i){const s=this.getScalingFactor();let n,r;return i?(n=Math.round(e/s),r=Math.round(t/s)):(n=Math.round(e*s),r=Math.round(t*s)),n<0&&(n=0),n>this.bgImageProperties.w&&(n=this.bgImageProperties.w),r<0&&(r=0),r>this.bgImageProperties.h&&(r=this.bgImageProperties.h),{x:n,y:r}},getScalingFactor(){return this.isResponsive?this.bgImageProperties.w/this.backgroundImageWidth:1},newPointElement(e,t,i,s,n){const r=document.createElementNS("http://www.w3.org/2000/svg","circle");return r.setAttribute("cx",t.x),r.setAttribute("cy",t.y),r.setAttribute("r",this.pointRadius),s==="default-light"?(r.setAttribute("fill","orange"),r.setAttribute("fill-opacity",".5"),r.setAttribute("stroke","orange")):(r.setAttribute("fill","#0088CC"),r.setAttribute("fill-opacity",".5"),r.setAttribute("stroke","blue")),r.setAttribute("opacity","1"),r.setAttribute("stroke-width","1"),r.setAttribute("data-marker-type",s),r.setAttribute("id",`${e}`),r.setAttribute("class",`qti3-player-select-point ${n?"static":""}`),r.setAttribute("tabindex","0"),r.setAttribute("data-point",`${i.x} ${i.y}`),r},handleOverlayClick(e){e.preventDefault(),this.checkMaxChoicesLimit()||this.addPointFromClick(this.getMousePosition(e))},handlePointClick(e){if(e.preventDefault(),e.stopPropagation(),this.isDisabled)return;const t=e.target,i=t.getAttribute("id");this.deletePoint(i,t),this.setState(this.computeState()),this.setResponse(this.computeResponse()),this.evaluateValidity()},getMousePosition(e){const t=this.$refs.overlay.getScreenCTM();e.touches&&(e=e.touches[0]);const i=(e.clientX-t.e)/t.a,s=(e.clientY-t.f)/t.d;return{x:i,y:s}},processGroupUI(){this.setResponse(null),this.setState(this.computeState()),this.setIsValid(this.computeIsValid())},processBackgroundImage(){if(this.bgImageProperties=this.computeBackgroundImageProperties(),this.bgImageProperties===null)throw new c("Select Point interaction must have exactly one <img>, <object>, or <picture> node");this.isResponsive?(this.backgroundImageWidth=`${this.bgImageProperties.element.offsetWidth}`,this.backgroundImageHeight=`${this.bgImageProperties.element.offsetHeight}`):(this.backgroundImageWidth=`${this.bgImageProperties.w}`,this.backgroundImageHeight=`${this.bgImageProperties.h}`,this.$refs.selectpointgroup.setAttribute("style",`width:${this.backgroundImageWidth};height:${this.backgroundImageHeight}`)),this.overlayId=this.createId("spi_"),this.$refs.overlay.setAttribute("id",this.overlayId),this.$refs.overlay.setAttribute("width",`${this.backgroundImageWidth}`),this.$refs.overlay.setAttribute("height",`${this.backgroundImageHeight}`),this.$refs.overlay.setAttribute("viewBox",`0 0 ${this.backgroundImageWidth} ${this.backgroundImageHeight}`),this.$refs.overlay.setAttribute("tabindex","-1"),this.$refs.overlay.setAttribute("role","application"),this.$refs.overlay.setAttribute("focusable","false"),this.createSvgImage(this.bgImageProperties,this.backgroundImageWidth,this.backgroundImageHeight),this.addOverlayListeners()},handleResize(){this.backgroundImageWidth=this.$refs.overlay.parentNode.offsetWidth,this.backgroundImageHeight=this.$refs.overlay.parentNode.offsetHeight,this.$refs.overlay.setAttribute("width",`${this.backgroundImageWidth}`),this.$refs.overlay.setAttribute("height",`${this.backgroundImageHeight}`)},computeBackgroundImageProperties(){let e=this.$refs.selectpointgroup.getElementsByTagName("img");if(e.length===1){const t=e[0].getAttribute("width"),i=e[0].getAttribute("height");return this.createImageProperties(e[0],e[0].src,"img",t,i)}if(e=this.$refs.selectpointgroup.getElementsByTagName("object"),e.length===1){const t=e[0].getAttribute("width"),i=e[0].getAttribute("height");return this.createImageProperties(e[0],e[0].data,"object",t,i)}return null},createImageProperties(e,t,i,s,n){let r=s===null||n===null?1:s/n;return{element:e,src:t,tag:i,w:s,h:n,ar:r}},createSvgImage(e,t,i){let s=document.createElementNS("http://www.w3.org/2000/svg","image");s.setAttribute("href",e.src),s.setAttribute("width",t),s.setAttribute("height",i),s.setAttribute("draggable",!1),this.$refs.overlay.appendChild(s),e.element.remove()},addOverlayListeners(){this.$refs.overlay.addEventListener("click",this.handleOverlayClick.bind(this))},removeOverlayListeners(){this.$refs.overlay.removeEventListener("click",this.handleOverlayClick)},addPointListeners(e){e.addEventListener("click",this.handlePointClick.bind(this))},removePointListeners(e){e.removeEventListener("click",this.handlePointClick)},processClassAttribute(e){if(typeof e>"u"||e===null||e.length==0)return;const t=e.split(" ");for(let i=0;i<t.length;i++)switch(t[i]){case"responsive":this.isResponsive=!0;break;case"marker-crosshair":this.markerType="crosshair";break;case"marker-default":this.markerType="default";break;case"marker-default-light":this.markerType="default-light";break}},getPriorState(e){const t=I.getItemContextStateVariable(e);if(t===null)return null;if(!("value"in t))throw new O('Select Point Interaction State Invalid. "value" property not found.');if(!("state"in t))throw new O('Select Point Interaction State Invalid. "state" property not found.');if(!("points"in t.state))throw new O('Select Point Interaction State Invalid. "points" property not found in State.');return t}},created(){try{if(this.responseDeclaration=Gh.validateResponseIdentifierAttribute(I,this.responseIdentifier),this.processClassAttribute(this.$.vnode.props.class),this.priorState=this.getPriorState(this.responseIdentifier),Gh.validateMaxMinChoices(this.maxChoices,this.minChoices),this.isSingle=this.getCardinality()!=="multiple",this.isSingle&&this.maxChoices!=1)throw new c('Invalid qti-select-point-interaction. cardinality: "single", max-choices attribute: "'+this.maxChoices+'"');this.hasPrompts=this.getPrompts(this.$slots).length>0,this.computeMinSelectionsMessage(),this.computeMaxSelectionsMessage()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):e.name==="QtiParseException"?new se(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.movePrompt(),this.processChildren(),I.defineInteraction({identifier:this.responseIdentifier,interactionType:"SelectPoint",node:this,resetValue:this.resetValue,disable:this.disable,isValidResponse:this.getIsValid(),invalidResponseMessage:this.getInvalidResponseMessage(),maxSelectionsMessage:this.maxSelectionsMessage}),console.log("["+this.$options.name+"][Identifier]",this.responseIdentifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}},beforeUnmount(){this.removeOverlayListeners();for(const e of this.pointElements.values())this.removePointListeners(e)}},T2={ref:"root",class:"qti-select-point-interaction"},S2={ref:"prompt",class:"qti-prompt-wrapper"},x2={ref:"selectpointgroup",class:"select-point-group"},I2={ref:"overlay",class:"select-point-overlay"};function _2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",T2,[l.createElementVNode("div",S2,null,512),l.createElementVNode("div",x2,[l.renderSlot(e.$slots,"default"),(l.openBlock(),l.createElementBlock("svg",I2,null,512))],512)],512)}const V2=P(C2,[["render",_2]]),A2={name:"QtiPrompt"},$2={class:"qti-prompt"};function L2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",$2,[l.renderSlot(e.$slots,"default")])}const M2=P(A2,[["render",L2]]),R2=new G,N2={name:"QtiInlineChoice",props:{identifier:{required:!0,type:String},fixed:{required:!1,type:String,default:"false"},templateIdentifier:{required:!1,type:String},showHide:{required:!1,type:String,default:"show"}},data(){return{id:null}},inheritAttrs:!0,methods:{createId(){if(this.$refs.choice.hasAttribute("id")){this.id=this.$refs.choice.getAttribute("id");return}this.id="inlinechoice_"+R2.randomString(5,"a")+"_"+this.identifier,this.$refs.choice.setAttribute("id",this.id)}},created(){},mounted(){this.createId()}},k2=["data-identifier"];function q2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("li",{ref:"choice",role:"option","data-identifier":i.identifier,class:"qti-inline-choice"},[l.renderSlot(e.$slots,"default")],8,k2)}const O2=P(N2,[["render",q2]]),P2=new G,B2={name:"QtiSimpleChoice",emits:["setChecked","setFocusPreviousChoice","setFocusNextChoice","setActiveDescendant"],props:{identifier:{required:!0,type:String},fixed:{required:!1,type:String,default:"false"},templateIdentifier:{required:!1,type:String},showHide:{required:!1,type:String,default:"show"}},data(){return{id:null,checked:"false",isRadio:!0,role:"radio",tabIndex:"-1",hasMath:!1,isDisabled:!1,parentCardinality:"single"}},inheritAttrs:!0,methods:{handleClick(){if(!this.isDisabled)if(this.isRadio)this.$parent.$emit("setChecked",{identifier:this.identifier,checked:"true"});else{if(this.toggleChecked(),this.parentCardinality==="ordered")return;this.$parent.$emit("setChecked",{identifier:this.identifier,checked:this.checked})}},handleKeydown(e){let t=!1;switch(e.code){case"Space":if(!this.isDisabled){if(this.toggleChecked(),this.parentCardinality==="ordered")return;this.$parent.$emit("setChecked",{identifier:this.identifier,checked:this.checked})}t=!0;break;case"Enter":if(!this.isDisabled){if(this.toggleChecked(),this.parentCardinality==="ordered")return;this.$parent.$emit("setChecked",{identifier:this.identifier,checked:this.checked})}t=!0;break;case"ArrowUp":case"ArrowLeft":this.isRadio&&(this.$parent.$emit("setFocusPreviousChoice",this.identifier),t=!0);break;case"ArrowDown":case"ArrowRight":this.isRadio&&(this.$parent.$emit("setFocusNextChoice",this.identifier),t=!0);break}t&&(e.stopPropagation(),e.preventDefault())},handleFocus(){this.parentCardinality!=="ordered"&&this.$parent.$emit("setActiveDescendant",this.id)},handleBlur(){},setChecked(e){this.checked=e?"true":"false"},isChecked(){return this.checked==="true"},setTabIndex(e){this.tabIndex=e},setFocus(){this.$refs.choice.focus()},setBlur(){this.$refs.choice.blur()},toggleChecked(){this.checked=this.checked==="true"?"false":"true"},setLabel(e){this.$refs.label.innerText=e},hideLabel(){this.$refs.label.classList.add("qti-hidden")},showLabel(){this.$refs.label.classList.remove("qti-hidden")},setLabelSbac(e){this.$refs.choice.classList.add("sbac"),this.$refs.choice.setAttribute("data-label",e),this.$refs.label.innerText=e,this.$refs.label.classList.add("qti-visually-hidden")},setChoiceLrn(){this.$refs.choice.classList.add("lrn")},hideControl(){this.$refs.choice.classList.add("control-hidden")},setIsDisabled(e){this.isDisabled=e},initializeChoice(){switch(this.parentCardinality=this.$parent.cardinality,this.parentCardinality){case"ordered":this.role="button",this.isRadio=!1,this.tabIndex=0;break;case"multiple":this.role="checkbox",this.isRadio=!1,this.tabIndex=0;break;default:this.role="radio",this.isRadio=!0,this.tabIndex=-1;break}},initializeOrderChoice(){this.role==="button"&&(this.hideLabel(),this.hideControl())},createId(){if(this.$refs.choice.hasAttribute("id")){this.id=this.$refs.choice.getAttribute("id");return}this.id="choice_"+P2.randomString(5,"a")+"_"+this.identifier,this.$refs.choice.setAttribute("id",this.id)},setExpectedSolution(){this.$refs.choice.classList.add("player-show-solution","player-choice-expected")},setCorrectSolution(){this.$refs.choice.classList.add("player-show-solution","player-choice-correct")},setIncorrectSolution(){this.$refs.choice.classList.add("player-show-solution","player-choice-incorrect")},setIgnoreSolution(){this.$refs.choice.classList.remove("player-show-solution","player-choice-incorrect","player-choice-correct","player-choice-expected")}},created(){this.initializeChoice()},mounted(){this.initializeOrderChoice(),this.createId()}},D2=["role","aria-checked","tabindex","data-identifier"],Q2={ref:"label",class:"qti-choice-label"},H2={ref:"description",class:"qti-choice-description"};function F2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("li",{ref:"choice",role:n.role,"aria-checked":n.checked,tabindex:n.tabIndex,"data-identifier":i.identifier,onFocus:t[0]||(t[0]=(...a)=>r.handleFocus&&r.handleFocus(...a)),onBlur:t[1]||(t[1]=(...a)=>r.handleBlur&&r.handleBlur(...a)),onClick:t[2]||(t[2]=(...a)=>r.handleClick&&r.handleClick(...a)),onKeydown:t[3]||(t[3]=(...a)=>r.handleKeydown&&r.handleKeydown(...a)),class:l.normalizeClass(["qti-simple-choice",{source:n.role=="button"}])},[l.createElementVNode("div",{class:l.normalizeClass(["qti-simple-choice-wrapper",{draggable:n.role=="button"}]),style:{width:"100%"}},[l.createElementVNode("div",Q2,null,512),l.createElementVNode("div",H2,[l.renderSlot(e.$slots,"default")],512)],2)],42,D2)}const U2=P(B2,[["render",F2]]),G2=new G,j2={name:"QtiSimpleAssociableChoice",props:{identifier:{required:!0,type:String},fixed:{required:!1,type:String,default:"false"},templateIdentifier:{required:!1,type:String},showHide:{required:!1,type:String,default:"show"},matchGroup:{required:!1,type:String,default:""},matchMax:{required:!0,type:String},matchMin:{required:!1,type:String,default:"0"}},data(){return{id:null}},methods:{createId(){if(this.$refs.choice.hasAttribute("id")){this.id=this.$refs.choice.getAttribute("id");return}this.id="choice_"+G2.randomString(5,"a")+"_"+this.identifier,this.$refs.choice.setAttribute("id",this.id)}},mounted(){this.createId()}},W2=["data-identifier","data-match-max","data-match-min","data-match-group"],z2={ref:"description",class:"choice-description"};function K2(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("li",{ref:"choice","data-identifier":i.identifier,"data-match-max":i.matchMax,"data-match-min":i.matchMin,"data-match-group":i.matchGroup,class:"qti-simple-associable-choice"},[l.createElementVNode("div",z2,[l.renderSlot(e.$slots,"default")],512)],8,W2)}const Y2=P(j2,[["render",K2]]),X2=new G,Z2={name:"QtiAssociableHotspot",props:{identifier:{required:!0,type:String},templateIdentifier:{required:!1,type:String},showHide:{required:!1,type:String,default:"show"},matchGroup:{required:!1,type:String,default:""},shape:{required:!0,type:String},coords:{required:!0,type:String},hotspotLabel:{required:!1,type:String,default:""},ariaLabel:{required:!1,type:String,default:""},matchMax:{required:!0,type:String},matchMin:{required:!1,type:String,default:"0"}},data(){return{shapeData:null,shapeColorProperties:null,isQtiValid:!0}},inheritAttrs:!0,methods:{getIdentifier(){return this.identifier},getShape(){return this.shape},getShapeData(){return this.shapeData},setShapeData(){const e=this.coords.split(",");switch(this.getShape()){case"circle":if(e.length!=3)return;this.shapeData=e;return;case"rect":if(e.length!==4)return;e[2]=parseInt(e[2])-parseInt(e[0]),e[3]=parseInt(e[3])-parseInt(e[1]),this.shapeData=e;return;case"poly":this.shapeData=this.transformPolyCoords(e);return;case"ellipse":if(e.length!=4)return;this.shapeData=e;return;case"default":this.shapeData="";return}},transformPolyCoords(e){let t=[];if(e.length%2!=0)return t;for(let i=0;i<e.length;i+=2)t.push(`${e[i]} ${e[i+1]}`);return t},initialize(){X2.validateShapeAttribute(this.shape),this.setShapeData()}},created(){try{this.initialize()}catch(e){if(this.isQtiValid=!1,e.name==="QtiValidationException")throw new c(e.message)}},mounted(){if(this.isQtiValid)try{console.log("["+this.$options.name+"][Identifier]",this.identifier)}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},J2=["data-identifier","data-match-max","data-match-min","data-match-group"];function eq(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",{ref:"gap","data-identifier":i.identifier,"data-match-max":i.matchMax,"data-match-min":i.matchMin,"data-match-group":i.matchGroup,class:"ggm-gap"},null,8,J2)}const tq=P(Z2,[["render",eq]]),iq=new G,sq=new ie,nq={name:"QtiSimpleMatchSet",data(){return{choices:[],isShuffle:!1,isQtiValid:!0}},methods:{getChoices(){return this.choices},setIsShuffle(e){this.isShuffle=e},createContainer(e,t){let i=[];return e===null?(this.choices.forEach(n=>{i.push({fixed:n.fixed==="true",node:n})}),this.isShuffle&&sq.shuffleArrayFixed(i),i):(e.state.orders[t].forEach(n=>{const r=this.findChoiceByIdentifier(n,this.choices);r!==null&&i.push({fixed:r.fixed==="true",node:r})},this),i)},processContainerChoices(e){this.choices.splice(0,this.choices.length),this.$refs.matchset.innerHTML="",e.forEach(t=>{this.$refs.matchset.appendChild(t.node.$el),this.choices.push(t.node)},this)},validateChildren(){let e=0;if(!this.$slots.default)throw new c("Must have at least 1 qti-simple-associable-choice");if(this.$slots.default().forEach(t=>{if(iq.isValidSlot(t)){if(t.type.name==="QtiSimpleAssociableChoice")return e+=1;throw new c('Node is not a qti-simple-associable-choice: "'+t.type.name+'"')}}),e===0)throw new c("Must have at least 1 qti-simple-associable-choice")},processChildren(){this.$.subTree.children[0].children.forEach(t=>{t.component!==null&&this.choices.push(t.component.proxy)})},findChoiceByIdentifier(e,t){for(let i=0;i<t.length;i++)if(t[i].$el.getAttribute("data-identifier")===e)return t[i];throw new O('Match Interaction State Invalid. Choice identifier "'+e+'" not found.')}},created(){try{this.validateChildren()}catch(e){throw this.isQtiValid=!1,e.name==="QtiValidationException"?new c(e.message):new Error(e.message)}},mounted(){if(this.isQtiValid)try{this.processChildren(),console.log("["+this.$options.name+"]")}catch(e){throw this.isQtiValid=!1,console.log("["+this.$options.name+"][ValidationError]",e.name,e.message),new c(e.message)}}},rq={ref:"matchset",class:"qti-simple-match-set"};function aq(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("ul",rq,[l.renderSlot(e.$slots,"default")],512)}const oq=P(nq,[["render",aq]]);class lq{constructor(t){this.constants={QTI_CHOICES_TOP:"qti-choices-top",QTI_CHOICES_BOTTOM:"qti-choices-bottom",QTI_CHOICES_LEFT:"qti-choices-left",QTI_CHOICES_RIGHT:"qti-choices-right",DATA_MAX_SELECTIONS_MESSAGE:"data-max-selections-message",DATA_MIN_SELECTIONS_MESSAGE:"data-min-selections-message",DATA_CHOICES_CONTAINER_WIDTH:null},this.parentClass=t,this.clazzTokens=[],this.gapMatchGroupElement=null,this.gapChoiceWrapperElement=null,this.gapTargetWrapperElement=null,this.choicesContainerWidth=null,this.gapChoices=[],this.gaps=[],this.presentation_Choices_Orientation=null,this.presentation_MaxSelectionsMessage="",this.presentation_MinSelectionsMessage=""}initialize(t,i,s,n,r,a){this.gapMatchGroupElement=t,this.gapChoiceWrapperElement=i,this.gapTargetWrapperElement=s,this.choicesContainerWidth=n,this.gapChoices=r,this.gaps=a,this.processRootClassAttribute(this.parentClass),this.processPresentation()}processRootClassAttribute(t){const i=t.split(" ");for(let s=0;s<i.length;s++)switch(i[s]){case this.constants.QTI_CHOICES_TOP:case this.constants.QTI_CHOICES_BOTTOM:case this.constants.QTI_CHOICES_LEFT:case this.constants.QTI_CHOICES_RIGHT:this.presentation_Choices_Orientation=i[s];break}this.clazzTokens=i}processPresentation(){this.presentation_Choices_Orientation===null&&(this.presentation_Choices_Orientation=this.constants.QTI_CHOICES_TOP),this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_LEFT?(this.gapChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_LEFT),this.gapTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_LEFT),this.gapMatchGroupElement.classList.add(this.constants.QTI_CHOICES_LEFT)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_TOP?(this.gapChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_TOP),this.gapTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_TOP)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_RIGHT?(this.gapChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_RIGHT),this.gapTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_RIGHT),this.gapMatchGroupElement.classList.add(this.constants.QTI_CHOICES_RIGHT),this.gapMatchGroupElement.insertBefore(this.gapTargetWrapperElement,this.gapChoiceWrapperElement)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_BOTTOM&&(this.gapChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_BOTTOM),this.gapTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_BOTTOM),this.gapMatchGroupElement.insertBefore(this.gapTargetWrapperElement,this.gapChoiceWrapperElement)),this.processChoicesContainerWidth(),this.processGaps()}processChoicesContainerWidth(){this.choicesContainerWidth!==null&&(this.gapChoiceWrapperElement.style.width=`${this.choicesContainerWidth}px`)}processGaps(){for(let t=0;t<this.gaps.length;t++)this.gaps[t].classList.add("target")}}class cq{constructor(t,i){J(this,"options",{interactionSubType:"default",cardinality:"single",maxAssociations:0,response:null,onReady:null,onUpdate:null,onSelectionsLimit:null});return this.qtiAttributeValidation=new G,this.wrapper=t,this.sourcewrapper=this.wrapper.querySelector(".qti-gap-match-source-wrapper"),this.targetwrapper=this.wrapper.querySelector(".qti-gap-match-target-wrapper"),this.processOptions(i),this.handleDragStart=this.handleDragStart.bind(this),this.handleDragMove=this.handleDragMove.bind(this),this.handleDragEnd=this.handleDragEnd.bind(this),this.handleTouchStart=this.handleTouchStart.bind(this),this.handleTouchMove=this.handleTouchMove.bind(this),this.handleTouchEnd=this.handleTouchEnd.bind(this),this.itemTarget=null,this.itemStart=null,this.isItemStartSource=!0,this.initialX=0,this.initialY=0,this.offsetX=0,this.offsetY=0,this.startingX=0,this.startingY=0,this.currentAssociationsCount=0,this.isDisabled=!1,this.currentDragger=null,this.initializeSources(this.sourcewrapper),this.initializeTargets(this.targetwrapper),this.restoreResponse(this.options.response),this.notifyReady(),this}processOptions(t){"interactionSubType"in t&&(this.options.interactionSubType=t.interactionSubType),"cardinality"in t&&(this.options.cardinality=t.cardinality),"response"in t&&(this.options.response=t.response),"maxAssociations"in t&&(this.options.maxAssociations=t.maxAssociations),"onReady"in t&&(this.options.onReady=t.onReady),"onUpdate"in t&&(this.options.onUpdate=t.onUpdate),"onAssociationsLimit"in t&&(this.options.onAssociationsLimit=t.onAssociationsLimit)}notifyReady(){this.options.onReady!==null&&this.options.onReady({response:this.getResponse()})}notifyUpdate(){this.options.onUpdate!==null&&this.options.onUpdate({response:this.computeResponse()})}notifyAssociationsLimit(){this.options.onAssociationsLimit!==null&&this.options.onAssociationsLimit()}toggleDisable(t){this.isDisabled=t,this.draggers.forEach(i=>{t?i.classList.add("disabled"):i.classList.remove("disabled")})}handleDragStart(t){if(t.preventDefault(),!this.isDisabled&&t.button==0)return this.interactionStart(t.target,t.clientX,t.clientY,!1),!1}handleTouchStart(t){if(t.preventDefault(),!this.isDisabled)return t.targetTouches.length!=1||this.interactionStart(t.target,t.touches[0].pageX,t.touches[0].pageY,!0),!1}interactionStart(t,i,s,n){const r=this.getClosestElement(t,"draggable");this.itemStart=r.parentNode,this.isItemStartSource=this.itemStart.classList.contains("source"),this.identifyTargets(this.itemStart,!0),this.itemTarget=null;const a=r.getBoundingClientRect();this.initialX=i,this.initialY=s,this.startingX=a.left,this.startingY=a.top,this.offsetX=i-this.startingX,this.offsetY=s-this.startingY,this.addPlaceholder(r),r.style.userSelect="none",r.style.width=a.width+"px",r.style.height=a.height+"px",r.style.transform=`translateX(${a.left}px) translateY(${a.top}px) translateZ(0)`,r.classList.add("dragging"),this.setCurrentDragger(r),this.addListeners(r,n)}handleDragMove(t){t.preventDefault(),!this.isDisabled&&this.interactionMove(t.clientX,t.clientY)}handleTouchMove(t){t.preventDefault(),!this.isDisabled&&t.targetTouches.length==1&&this.interactionMove(t.touches[0].clientX,t.touches[0].clientY)}interactionMove(t,i){const s=this.currentDragger;this.offsetX=t-this.initialX,this.offsetY=i-this.initialY,this.constrainDraggerToWrapper(s,this.wrapper),s.style.transform=`translateX(${this.startingX+this.offsetX}px) translateY(${this.startingY+this.offsetY}px) translateZ(0) scale(1)`;const n=s.getBoundingClientRect();this.findDraggerItemTarget(s,n,this.targets),this.isItemStartSource||this.findSourceDraggerTarget(s,n)}constrainDraggerToWrapper(t,i){const s=t.getBoundingClientRect(),n=i.getBoundingClientRect(),r=this.startingX+this.offsetX-n.x,a=this.startingY+this.offsetY-n.y,o=this.startingX+s.width+this.offsetX-(n.x+n.width),u=this.startingY+s.height+this.offsetY-(n.y+n.height);r<0&&(this.offsetX=this.offsetX-r),o>0&&(this.offsetX=this.offsetX-o),a<0&&(this.offsetY=this.offsetY-a),u>0&&(this.offsetY=this.offsetY-u)}handleDragEnd(t){this.isDisabled||this.interactionEnd(t.clientX,t.clientY,!1)}handleTouchEnd(t){this.isDisabled||this.interactionEnd(t.changedTouches[0].clientX,t.changedTouches[0].clientY,!0)}interactionEnd(t,i,s){const n=this.currentDragger;if(this.itemTarget===null?n.style.transform=`translateX(${this.startingX}px) translateY(${this.startingY}px) translateZ(0)`:n.style.transform=`translateX(${this.startingX+this.offsetX}px) translateY(${this.startingY+this.offsetY}px) translateZ(0)`,n.removeAttribute("style"),n.classList.remove("dragging"),this.clearTargetHighlights(),this.itemTarget===null){this.resetDraggerToItemStart(this.itemStart,n),this.setCurrentDragger(null),this.removeListeners(n,s);return}if(this.itemTarget.classList.contains("active")){if(this.itemTarget.classList.remove("active"),this.isExceedingMaxAssociations(this.itemStart,this.itemTarget,n)){this.resetDraggerToItemStart(this.itemStart,n),this.notifyAssociationsLimit(),this.setCurrentDragger(null),this.removeListeners(n,s);return}if(this.itemStart.getAttribute("data-identifier")===this.itemTarget.getAttribute("data-identifier")){this.resetDraggerToItemStart(this.itemStart,n),this.setCurrentDragger(null),this.removeListeners(n,s);return}this.removePlaceholder(n),this.setDraggerToItemTarget(this.itemTarget,n),this.itemTarget.classList.contains("source")&&(this.itemTarget.classList.add("full"),this.itemTarget.dataset.matchMax*1>0&&this.incrementRemaining(this.itemTarget),this.decrementAssociationsCount(),this.sortContainerElements(this.sourcewrapper)),this.itemStart.classList.contains("source")&&(this.itemStart.dataset.matchMax*1>0&&this.decrementRemaining(this.itemStart)===0&&this.itemStart.classList.remove("full"),this.incrementAssociationsCount()),this.itemStart.classList.contains("target")&&(this.isTargetFull(this.itemStart)?this.itemStart.classList.add("full"):this.itemStart.classList.remove("full")),this.notifyUpdate()}this.setCurrentDragger(null),this.removeListeners(n,s)}setCurrentDragger(t){this.currentDragger=t}resetDraggerToItemStart(t,i){this.replacePlaceholder(i),t.classList.contains("source")||i.setAttribute("style","width:100%")}setDraggerToItemTarget(t,i){if(t.classList.contains("source")){if(t.classList.contains("full")){const s=t.querySelector(".draggable");s!=null&&t.replaceChild(i,s);return}t.append(i);return}t.append(i),i.setAttribute("style","width:100%"),this.isTargetFull(t)?t.classList.add("full"):t.classList.remove("full")}findDraggerItemTarget(t,i,s){this.itemTarget=null,s.forEach(n=>{const r=n.getBoundingClientRect();if(i.top+t.offsetHeight/2<r.bottom&&i.right-t.offsetWidth/2>r.left&&i.bottom-t.offsetHeight/2>r.top&&i.left+t.offsetWidth/2<r.right){if(this.isItemStartSource&&n.classList.contains("source")||n.classList.contains("full")||!this.hasMatchingMatchGroup(t.parentNode,n))return;n.classList.add("active"),this.itemTarget=n}else n.classList.remove("active")},this)}findSourceDraggerTarget(t,i){const s=this.sourcewrapper.getBoundingClientRect();if(i.top+t.offsetHeight/2<s.bottom&&i.right-t.offsetWidth/2>s.left&&i.bottom-t.offsetHeight/2>s.top&&i.left+t.offsetWidth/2<s.right){for(let n=0;n<this.sources.length;n++)if(this.sources[n].dataset.identifier===t.dataset.identifier){this.sources[n].classList.add("active"),this.itemTarget=this.sources[n];break}}else for(let n=0;n<this.sources.length;n++)this.sources[n].classList.contains("active")&&this.sources[n].classList.remove("active")}addPlaceholder(t){if(!t.parentNode.classList.contains("source")){this.addPlaceholderElement(t,!1);return}const i=t.parentNode.dataset.matchMax*1;if(i===1){this.addPlaceholderElement(t,!1);return}if(i===0){this.addPlaceholderElement(t,!0);return}if(this.getRemaining(t.parentNode)===1){this.addPlaceholderElement(t,!1);return}this.addPlaceholderElement(t,!0)}addPlaceholderElement(t,i){const s=t.cloneNode(!0);this.deepCloneId(s),i?(s.classList.add("clone"),s.addEventListener("mousedown",this.handleDragStart),s.addEventListener("touchstart",this.handleTouchStart)):s.classList.add("gm-dragger-placeholder"),s.classList.add("placeholder-fade"),t.parentNode.insertBefore(s,t)}removePlaceholder(t){if(t.parentNode.classList.contains("target")){const n=t.parentNode.querySelector(".gm-dragger-placeholder");if(n===null)return;t.parentNode.removeChild(n);return}const i=t.parentNode.dataset.matchMax*1,s=t.parentNode.querySelector(".gm-dragger-placeholder");if(s===null){const n=t.parentNode.querySelector(".clone");if(n===null)return;n.classList.remove("placeholder-fade");return}i!==0&&t.parentNode.removeChild(s)}replacePlaceholder(t){const i=t.parentNode;let s=i.querySelector(".gm-dragger-placeholder");if(i.classList.contains("source")){if(s==null&&(s=i.querySelector(".draggable")),s===null)return;i.replaceChild(t,s);return}s!==null&&i.replaceChild(t,s)}addClonePlaceholder(t){const i=t.cloneNode(!0);this.deepCloneId(i),i.classList.add("clone"),t.parentNode.insertBefore(i,t),i.addEventListener("mousedown",this.handleDragStart),i.addEventListener("touchstart",this.handleTouchStart)}initializeSources(t){this.sources=t.querySelectorAll(".source"),this.sources.forEach(i=>{i.classList.add("full");const s=i.dataset.matchMax*1;this.setRemaining(i,s===0?1e3:s)},this),this.draggers=t.querySelectorAll(".draggable"),this.draggers.forEach((i,s)=>{const n=i.parentNode.getAttribute("data-identifier");i.setAttribute("data-identifier",n),i.setAttribute("data-order",s),i.setAttribute("tabindex",0),i.addEventListener("mousedown",this.handleDragStart),i.addEventListener("touchstart",this.handleTouchStart)},this)}initializeTargets(t){this.targets=t.querySelectorAll(".target"),this.targets.forEach(i=>{i.setAttribute("tabindex",0)})}identifyTargets(t,i){this.targets.forEach(s=>{i&&!s.classList.contains("full")&&this.hasMatchingMatchGroup(t,s)&&s.classList.add("target-active")},this),i&&!this.isItemStartSource&&this.sourcewrapper.classList.add("target-active")}addListeners(t,i){i?(this.removeListeners(t,i),t.addEventListener("touchmove",this.handleTouchMove),t.addEventListener("touchend",this.handleTouchEnd)):(this.removeListeners(t,i),document.addEventListener("mousemove",this.handleDragMove),document.addEventListener("mouseup",this.handleDragEnd))}removeListeners(t,i){i?(t.removeEventListener("touchmove",this.handleTouchMove),t.removeEventListener("touchend",this.handleTouchEnd)):(document.removeEventListener("mousemove",this.handleDragMove),document.removeEventListener("mouseup",this.handleDragEnd))}clearTargetHighlights(){this.targets.forEach(t=>{t.classList.remove("target-active")},this),this.sourcewrapper.classList.remove("target-active")}getClosestElement(t,i){return t?t&&t.classList.contains(i)?t:this.getClosestElement(t.parentElement,i):!1}sortContainerElements(t){let i=[],s=t.children;for(let n=0;n<s.length;n++){const r=s[n].querySelector("div.draggable");r&&i.push([1*r.dataset.order,s[n]])}i.sort(function(n,r){return n[0]-r[0]});for(let n=0;n<i.length;n++)t.appendChild(i[n][1])}getResponse(){return this.computeResponse()}computeResponse(){let t=[];return this.targets.forEach(i=>{i.querySelectorAll(".draggable").forEach(s=>{t.push(`${s.dataset.identifier} ${i.dataset.identifier}`)})}),t.length===0?null:this.options.cardinality==="single"?t[0]:t}restoreResponse(t){t!==null&&(this.options.cardinality==="single"?this.restoreResponsePair(t):t.forEach(i=>{this.restoreResponsePair(i)},this))}restoreResponsePair(t){const i=this.getPair(t);if(i===null)return;const s=this.findSourceByIdentifier(i.source),n=this.findTargetGapByIdentifier(i.target);if(s===null||n===null)return;const r=s.querySelector(".draggable");r!==null&&(this.cloneOrEmptySourceDragger(s,r),this.restoreSourceDraggerToTarget(n,r))}cloneOrEmptySourceDragger(t,i){const s=t.dataset.matchMax*1;if(s===1){t.classList.remove("full"),this.decrementRemaining(t);return}if(s===0){this.addClonePlaceholder(i);return}if(this.getRemaining(t)===1){t.classList.remove("full"),this.decrementRemaining(t);return}this.decrementRemaining(t),this.addClonePlaceholder(i)}findSourceByIdentifier(t){for(let i=0;i<this.sources.length;i++)if(t===this.sources[i].dataset.identifier)return this.sources[i];return null}findTargetGapByIdentifier(t){for(let i=0;i<this.targets.length;i++)if(t===this.targets[i].dataset.identifier)return this.targets[i];return null}getPair(t){if(t===null)return null;const i=t.split(" ");return i.length!=2?null:{source:i[0],target:i[1]}}restoreSourceDraggerToTarget(t,i){t===null||i===null||(t.append(i),i.setAttribute("style","width:100%"),this.incrementAssociationsCount(),this.isTargetFull(t)&&t.classList.add("full"))}hasMatchingMatchGroup(t,i){return t===null||i===null?!1:t.dataset.matchGroup===i.dataset.matchGroup}isTargetFull(t){if(t==null)return!1;const i=t.querySelectorAll(".draggable"),s=t.dataset.matchMax*1;return s===0?!1:i.length>=s}isExceedingMaxAssociations(t,i){return!(this.options.maxAssociations===0||i.classList.contains("source")||t.classList.contains("target")||this.currentAssociationsCount<this.options.maxAssociations)}initializeAssociationsCount(){this.currentAssociationsCount=0}incrementAssociationsCount(){this.currentAssociationsCount+=1}decrementAssociationsCount(){this.currentAssociationsCount!==0&&(this.currentAssociationsCount-=1)}getRemaining(t){return t.dataset.remaining*1}setRemaining(t,i){t.setAttribute("data-remaining",i)}incrementRemaining(t){const i=t.dataset.remaining*1+1;return t.setAttribute("data-remaining",i),i}decrementRemaining(t){let i=t.dataset.remaining*1-1;return i=i>=0?i:0,t.setAttribute("data-remaining",i),i}deepCloneId(t){t.id&&(t.id=`clone_${this.qtiAttributeValidation.randomString(5,"a")}`);for(let i=0;i<t.children.length;i++)this.deepCloneId(t.children[i])}reset(){this.resetDraggersToSources(),this.initializeAssociationsCount(),this.destroy()}resetDraggersToSources(){this.targets.forEach(t=>{t.querySelectorAll(".draggable").forEach(s=>{const n=this.findSourceByIdentifier(s.getAttribute("data-identifier"));n.classList.contains("full")||(t.classList.remove("full"),n.classList.contains("full")?t.removeChild(s):(n.append(s),n.classList.add("full")))},this)},this)}destroy(){this.currentDragger!==null&&(document.removeEventListener("mousemove",this.handleDragMove),document.removeEventListener("mouseup",this.handleDragEnd)),this.wrapper.querySelectorAll(".draggable").forEach(i=>{i.removeEventListener("touchstart",this.handleTouchStart),i.removeEventListener("touchmove",this.handleTouchMove),i.removeEventListener("touchend",this.handleTouchEnd),i.removeEventListener("mousedown",this.handleDragStart)},this)}}const uq=new G,hq=new ie,dq={emits:["gapMatchGroupReady","gapMatchGroupUpdate","gapMatchGroupAssociationsLimit"],props:{responseIdentifier:{required:!0,type:String},cardinality:{required:!0,type:String},shuffle:{required:!1,type:String,default:"false"},maxAssociations:{required:!1,type:String,default:"1"},minAssociations:{required:!1,type:String,default:"0"},dataChoicesContainerWidth:{required:!1,type:String,default:null},interactionSubType:{required:!1,type:String,default:"default"},gapMatchInteractionStaticClass:{required:!0,type:String},priorState:{required:!1,type:Object,default:null}},data(){return{choices:[],order:[],gaps:[],response:null,isShuffle:null,hasPrompt:!1,gapMatchInteractionClassAttribute:null,presentationFactory:null,matchable:null,isQtiValid:!0}},computed:{computedMaxAssociations(){return this.maxAssociations*1}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},disable(){this.matchable!==null&&this.matchable.toggleDisable(!0)},enable(){this.matchable!==null&&this.matchable.toggleDisable(!1)},getChoices(){return this.choices},setIsShuffle(e){this.isShuffle=e},validateChildren(){let e=0;this.$slots.default()[0].children.forEach(t=>{if(uq.isValidSlot(t)){if(t.type.name==="QtiPrompt"){if(e>0)throw new c("Invalid element order. qti-prompt must come before qti-gap-text's, qti-gap-img's, or qti-gap's");if(!this.hasPrompt)return this.hasPrompt=!0;throw new c("Maximum of 1 qti-prompt element permitted")}if(t.type.name==="QtiGapText"||t.type.name==="QtiGapImg")return e+=1;throw new c('Node is not one of qti-gap-text or qti-gap-img: "'+t.type.name+'"')}})},processChildren(){this.$.subTree.children[0].children[0].children.forEach(i=>{i.component!==null&&(i.type.name==="QtiGapText"||i.type.name==="QtiGapImg")&&this.choices.push(i.component.proxy)}),this.$refs.root.querySelectorAll(".gap-match-gap").forEach(i=>{this.gaps.push(i)})},insertAfter(e,t){t.parentNode.insertBefore(e,t.nextSibling)},processGroupUI(e){let t=this.createGapChoiceWrapper();if(t==null)return;let i=this.createContainer(this.priorState);this.processContainerChoices(i,t),this.saveContainerOrder(i);let s=this.createGapTargetWrapper(t);this.presentationFactory.initialize(this.$refs.root,t,s,this.dataChoicesContainerWidth,this.choices,this.gaps),this.matchable=new cq(this.$refs.root,{interactionSubType:this.interactionSubType,cardinality:this.cardinality,maxAssociations:this.computedMaxAssociations,response:e,onReady:this.handleWidgetReady,onUpdate:this.handleWidgetUpdate,onAssociationsLimit:this.handleAssociationsLimit})},createGapChoiceWrapper(){let e=this.$refs.root.querySelector(".qti-gap-choice");if(e===null)return null;let t=document.createElement("ul");return t.classList.add("qti-gap-match-source-wrapper"),this.$refs.root.insertBefore(t,e),t},createGapTargetWrapper(e){const t=document.createElement("div");t.classList.add("qti-gap-match-target-wrapper"),this.insertAfter(t,e);const i=t.nextElementSibling;return i!=null&&t.append(i),t},createContainer(e){let t=[];return e===null?(this.choices.forEach(s=>{t.push({fixed:s.fixed==="true",node:s})}),this.isShuffle&&hq.shuffleArrayFixed(t),t):(e.state.order.forEach(s=>{const n=this.findChoiceByIdentifier(s,this.choices);n!==null&&t.push({fixed:n.fixed==="true",node:n})},this),t)},processContainerChoices(e,t){this.choices.splice(0,this.choices.length),t.innerHTML="",e.forEach(i=>{t.appendChild(i.node.$el),this.choices.push(i.node)},this)},saveContainerOrder(e){const t=[];e.forEach(i=>{t.push(i.node.identifier)}),this.order=t},findChoiceByIdentifier(e,t){for(let i=0;i<t.length;i++)if(t[i].$el.getAttribute("data-identifier")===e)return t[i];throw new O('Gap Match Interaction State Invalid. Choice identifier "'+e+'" not found.')},resetGroupUI(){this.processGroupUI(null)},handleWidgetReady(e){this.setResponse(e.response),this.$emit("gapMatchGroupReady",{response:this.getResponse(),order:this.order})},handleWidgetUpdate(e){this.setResponse(e.response),this.$emit("gapMatchGroupUpdate",{response:this.getResponse()})},handleAssociationsLimit(){this.$emit("gapMatchGroupAssociationsLimit")},initializeGapMatchGroup(){this.presentationFactory=new lq(this.gapMatchInteractionStaticClass)}},created(){try{if(typeof this.cardinality>"u")throw new c("Undefined qti-gap-match-interaction cardinality");if(this.cardinality!=="single"&&this.cardinality!=="multiple")throw new c('qti-gap-match-interaction cardinality must be "single" or "multiple"');this.setIsShuffle(this.shuffle==="true"),this.initializeGapMatchGroup(),this.validateChildren()}catch(e){throw this.isQtiValid=!1,console.log("[QtiGapMatchInteraction][ValidationError]",e.name,e.message),new c(e.message)}},mounted(){if(this.isQtiValid)try{this.processChildren(),this.processGroupUI(this.priorState===null?null:this.priorState.value)}catch(e){if(this.isQtiValid=!1,e.name==="QtiValidationException")throw console.log("[QtiGapMatchInteraction][ValidationException]",e.message),new c(e.message);if(e.name==="QtiEvaluationException")throw console.log("[QtiGapMatchInteraction][EvaluationException]",e.message),new O(e.message)}},beforeUnmount(){this.matchable!==null&&(this.matchable.destroy(),this.matchable=null)}},fq={ref:"root",class:"qti-gap-match-group-wrapper"};function pq(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",fq,[l.renderSlot(e.$slots,"default")],512)}const mq=P(dq,[["render",pq]]);class gq{constructor(t){this.constants={QTI_SELECTIONS_LIGHT:"qti-selections-light",QTI_SELECTIONS_DARK:"qti-selections-dark",QTI_UNSELECTED_HIDDEN:"qti-unselected-hidden",QTI_CHOICES_TOP:"qti-choices-top",QTI_CHOICES_BOTTOM:"qti-choices-bottom",QTI_CHOICES_LEFT:"qti-choices-left",QTI_CHOICES_RIGHT:"qti-choices-right",DATA_MAX_SELECTIONS_MESSAGE:"data-max-selections-message",DATA_MIN_SELECTIONS_MESSAGE:"data-min-selections-message",DATA_CHOICES_CONTAINER_WIDTH:null},this.parentClass=t,this.clazzTokens=[],this.ggmGroupElement=null,this.ggmChoiceWrapperElement=null,this.ggmTargetWrapperElement=null,this.image=null,this.choicesContainerWidth=null,this.gapChoices=[],this.gaps=[],this.presentation_Choices_Orientation=null,this.presentation_Theme=this.constants.QTI_SELECTIONS_DARK,this.presentation_UnselectedHidden=!1,this.presentation_MaxSelectionsMessage="",this.presentation_MinSelectionsMessage=""}initialize(t,i,s,n,r,a,o){this.ggmGroupElement=t,this.ggmChoiceWrapperElement=i,this.ggmTargetWrapperElement=s,this.image=n,this.choicesContainerWidth=r,this.gapChoices=a,this.gaps=o,this.processRootClassAttribute(this.parentClass),this.processPresentation()}processRootClassAttribute(t){const i=t.split(" ");for(let s=0;s<i.length;s++)switch(i[s]){case this.constants.QTI_CHOICES_TOP:case this.constants.QTI_CHOICES_BOTTOM:case this.constants.QTI_CHOICES_LEFT:case this.constants.QTI_CHOICES_RIGHT:this.presentation_Choices_Orientation=i[s];break;case this.constants.QTI_SELECTIONS_DARK:case this.constants.QTI_SELECTIONS_LIGHT:this.presentation_Theme=i[s];break;case this.constants.QTI_UNSELECTED_HIDDEN:this.presentation_UnselectedHidden=!0;break}this.clazzTokens=i}processPresentation(){this.presentation_Choices_Orientation===null&&(this.presentation_Choices_Orientation=this.constants.QTI_CHOICES_TOP),this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_LEFT?(this.ggmChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_LEFT),this.ggmTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_LEFT),this.ggmGroupElement.classList.add(this.constants.QTI_CHOICES_LEFT)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_TOP?(this.ggmChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_TOP),this.ggmTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_TOP)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_RIGHT?(this.ggmChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_RIGHT),this.ggmTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_RIGHT),this.ggmGroupElement.classList.add(this.constants.QTI_CHOICES_RIGHT),this.ggmGroupElement.insertBefore(this.ggmTargetWrapperElement,this.ggmChoiceWrapperElement)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_BOTTOM&&(this.ggmChoiceWrapperElement.classList.add(this.constants.QTI_CHOICES_BOTTOM),this.ggmTargetWrapperElement.classList.add(this.constants.QTI_CHOICES_BOTTOM),this.ggmGroupElement.insertBefore(this.ggmTargetWrapperElement,this.ggmChoiceWrapperElement)),this.processBackgroundImage(),this.processChoicesContainerWidth(),this.processGaps()}processBackgroundImage(){if(this.image===null)return;this.image.setAttribute("draggable","false");const t=this.image.getBoundingClientRect();this.ggmTargetWrapperElement.style.width=`${t.width}px`,this.ggmTargetWrapperElement.style.height=`${t.height}px`}processChoicesContainerWidth(){this.choicesContainerWidth!==null&&(this.ggmChoiceWrapperElement.style.width=`${this.choicesContainerWidth}px`,this.ggmChoiceWrapperElement.style.textAlign="center")}processGaps(){for(let t=0;t<this.gaps.length;t++){const i=this.gaps[t];this.setGapStyle(i,i.getShape(),i.getShapeData()),this.gaps[t].$refs.gap.classList.add("target",this.presentation_Theme),this.presentation_UnselectedHidden&&this.gaps[t].$refs.gap.classList.add(this.constants.QTI_UNSELECTED_HIDDEN)}}setGapStyle(t,i,s){switch(i){case"rect":t.$refs.gap.style.left=`${s[0]}px`,t.$refs.gap.style.top=`${s[1]}px`,t.$refs.gap.style.width=`${s[2]}px`,t.$refs.gap.style.height=`${s[3]}px`;break}}}class yq{constructor(t,i){J(this,"options",{interactionSubType:"default",cardinality:"multiple",maxAssociations:0,response:null,onReady:null,onUpdate:null,onSelectionsLimit:null,zindex:1e3});return this.qtiAttributeValidation=new G,this.wrapper=t,this.sourcewrapper=this.wrapper.querySelector(".qti-ggm-source-wrapper"),this.targetwrapper=this.wrapper.querySelector(".qti-ggm-target-wrapper"),this.processOptions(i),this.handleDragStart=this.handleDragStart.bind(this),this.handleDragMove=this.handleDragMove.bind(this),this.handleDragEnd=this.handleDragEnd.bind(this),this.handleTouchStart=this.handleTouchStart.bind(this),this.handleTouchMove=this.handleTouchMove.bind(this),this.handleTouchEnd=this.handleTouchEnd.bind(this),this.itemTarget=null,this.itemStart=null,this.isItemStartSource=!0,this.savedGapZindex="",this.initialX=0,this.initialY=0,this.offsetX=0,this.offsetY=0,this.startingX=0,this.startingY=0,this.currentAssociationsCount=0,this.isDisabled=!1,this.currentDragger=null,this.initializeSources(this.sourcewrapper),this.initializeTargets(this.targetwrapper),this.restoreResponse(this.options.response),this.notifyReady(),this}processOptions(t){"interactionSubType"in t&&(this.options.interactionSubType=t.interactionSubType),"cardinality"in t&&(this.options.cardinality=t.cardinality),"response"in t&&(this.options.response=t.response),"maxAssociations"in t&&(this.options.maxAssociations=t.maxAssociations),"onReady"in t&&(this.options.onReady=t.onReady),"onUpdate"in t&&(this.options.onUpdate=t.onUpdate),"onAssociationsLimit"in t&&(this.options.onAssociationsLimit=t.onAssociationsLimit)}notifyReady(){this.options.onReady!==null&&this.options.onReady({response:this.getResponse()})}notifyUpdate(){this.options.onUpdate!==null&&this.options.onUpdate({response:this.computeResponse()})}notifyAssociationsLimit(){this.options.onAssociationsLimit!==null&&this.options.onAssociationsLimit()}toggleDisable(t){this.isDisabled=t,this.draggers.forEach(i=>{t?i.classList.add("disabled"):i.classList.remove("disabled")})}handleDragStart(t){if(t.preventDefault(),!this.isDisabled&&t.button==0)return this.interactionStart(t.target,t.clientX,t.clientY,!1),!1}handleTouchStart(t){if(t.preventDefault(),!this.isDisabled)return t.targetTouches.length!=1||this.interactionStart(t.target,t.touches[0].pageX,t.touches[0].pageY,!0),!1}interactionStart(t,i,s,n){const r=this.getClosestElement(t,"draggable");this.itemStart=r.parentNode,this.isItemStartSource=this.itemStart.classList.contains("source"),this.isItemStartSource||this.saveGapZindex(this.itemStart),this.identifyTargets(this.itemStart,!0),this.itemTarget=null;const a=r.getBoundingClientRect();this.initialX=i,this.initialY=s,this.startingX=a.left,this.startingY=a.top,this.offsetX=i-this.startingX,this.offsetY=s-this.startingY,this.addPlaceholder(r),r.classList.add("dragging"),r.style.userSelect="none",r.style.width=a.width+"px",r.style.height=a.height+"px",r.style.transform=`translateX(${a.left}px) translateY(${a.top}px) translateZ(0)`,this.setCurrentDragger(r),this.addListeners(r,n)}handleDragMove(t){t.preventDefault(),!this.isDisabled&&this.interactionMove(t.clientX,t.clientY)}handleTouchMove(t){t.preventDefault(),!this.isDisabled&&t.targetTouches.length==1&&this.interactionMove(t.touches[0].clientX,t.touches[0].clientY)}interactionMove(t,i){const s=this.currentDragger;this.offsetX=t-this.initialX,this.offsetY=i-this.initialY,this.constrainDraggerToWrapper(s,this.wrapper),s.style.transform=`translateX(${this.startingX+this.offsetX}px) translateY(${this.startingY+this.offsetY}px) translateZ(0) scale(1)`;const n=s.getBoundingClientRect();this.findDraggerItemTarget(s,n,this.targets),this.isItemStartSource||this.findSourceDraggerTarget(s,n)}constrainDraggerToWrapper(t,i){const s=t.getBoundingClientRect(),n=i.getBoundingClientRect(),r=this.startingX+this.offsetX-n.x,a=this.startingY+this.offsetY-n.y,o=this.startingX+s.width+this.offsetX-(n.x+n.width),u=this.startingY+s.height+this.offsetY-(n.y+n.height);r<0&&(this.offsetX=this.offsetX-r),o>0&&(this.offsetX=this.offsetX-o),a<0&&(this.offsetY=this.offsetY-a),u>0&&(this.offsetY=this.offsetY-u)}handleDragEnd(t){this.isDisabled||this.interactionEnd(t.clientX,t.clientY,!1)}handleTouchEnd(t){this.isDisabled||this.interactionEnd(t.changedTouches[0].clientX,t.changedTouches[0].clientY,!0)}interactionEnd(t,i,s){const n=this.currentDragger;if(this.itemTarget===null?n.style.transform=`translateX(${this.startingX}px) translateY(${this.startingY}px) translateZ(0)`:n.style.transform=`translateX(${this.startingX+this.offsetX}px) translateY(${this.startingY+this.offsetY}px) translateZ(0)`,n.removeAttribute("style"),n.classList.remove("dragging"),this.clearTargetHighlights(),this.itemTarget===null){this.resetDraggerToItemStart(this.itemStart,n),this.setCurrentDragger(null),this.removeListeners(n,s);return}if(this.itemTarget.classList.contains("active")){if(this.itemTarget.classList.remove("active"),this.isExceedingMaxAssociations(this.itemStart,this.itemTarget,n)){this.resetDraggerToItemStart(this.itemStart,n),this.notifyAssociationsLimit(),this.setCurrentDragger(null),this.removeListeners(n,s);return}if(this.itemStart.getAttribute("data-identifier")===this.itemTarget.getAttribute("data-identifier")){this.resetDraggerToItemStart(this.itemStart,n),this.setCurrentDragger(null),this.removeListeners(n,s);return}this.removePlaceholder(n),this.setDraggerToItemTarget(this.itemTarget,n),this.itemTarget.classList.contains("source")&&(this.itemTarget.classList.add("full"),this.itemTarget.dataset.matchMax*1>0&&this.incrementRemaining(this.itemTarget),this.decrementAssociationsCount(),this.sortContainerElements(this.sourcewrapper)),this.itemStart.classList.contains("source")&&(this.itemStart.dataset.matchMax*1>0&&this.decrementRemaining(this.itemStart)===0&&this.itemStart.classList.remove("full"),this.incrementAssociationsCount()),this.itemStart.classList.contains("target")&&(this.restoreGapZindex(this.itemStart),this.isTargetFull(this.itemStart)?this.itemStart.classList.add("full","contains-choice"):(this.itemStart.classList.remove("full"),this.containsChoices(this.itemStart)?this.itemStart.classList.add("contains-choice"):this.itemStart.classList.remove("contains-choice"))),this.notifyUpdate()}this.setCurrentDragger(null),this.removeListeners(n,s)}setCurrentDragger(t){this.currentDragger=t}resetDraggerToItemStart(t,i){t.classList.contains("target")&&this.restoreGapZindex(t),this.replacePlaceholder(i)}setDraggerToItemTarget(t,i){if(t.classList.contains("source")){this.appendDraggerToSourceTarget(t,i);return}this.appendDraggerToGapTarget(t,i),this.isTargetFull(t)?t.classList.add("full"):t.classList.remove("full")}appendDraggerToSourceTarget(t,i){if(t.classList.contains("full")){const s=t.querySelector(".draggable");s!=null&&t.replaceChild(i,s);return}t.append(i)}appendDraggerToGapTarget(t,i){t.classList.add("contains-choice"),t.append(i)}findDraggerItemTarget(t,i,s){this.itemTarget=null,s.forEach(n=>{const r=n.getBoundingClientRect();if(i.top+t.offsetHeight/2<r.bottom&&i.right-t.offsetWidth/2>r.left&&i.bottom-t.offsetHeight/2>r.top&&i.left+t.offsetWidth/2<r.right){if(this.isItemStartSource&&n.classList.contains("source")||n.classList.contains("full")||!this.hasMatchingMatchGroup(t.parentNode,n))return;n.classList.add("active"),this.itemTarget=n}else n.classList.remove("active")},this)}findSourceDraggerTarget(t,i){const s=this.sourcewrapper.getBoundingClientRect();if(i.top+t.offsetHeight/2<s.bottom&&i.right-t.offsetWidth/2>s.left&&i.bottom-t.offsetHeight/2>s.top&&i.left+t.offsetWidth/2<s.right){for(let n=0;n<this.sources.length;n++)if(this.sources[n].dataset.identifier===t.dataset.identifier){this.sources[n].classList.add("active"),this.itemTarget=this.sources[n];break}}else for(let n=0;n<this.sources.length;n++)this.sources[n].classList.contains("active")&&this.sources[n].classList.remove("active")}addPlaceholder(t){if(!t.parentNode.classList.contains("source")){this.addPlaceholderElement(t,!1);return}const i=t.parentNode.dataset.matchMax*1;if(i===1){this.addPlaceholderElement(t,!1);return}if(i===0){this.addPlaceholderElement(t,!0);return}if(this.getRemaining(t.parentNode)===1){this.addPlaceholderElement(t,!1);return}this.addPlaceholderElement(t,!0)}addPlaceholderElement(t,i){const s=t.cloneNode(!0);this.deepCloneId(s),i?(s.classList.add("clone"),s.addEventListener("mousedown",this.handleDragStart),s.addEventListener("touchstart",this.handleTouchStart)):s.classList.add("ggm-dragger-placeholder"),s.classList.add("placeholder-fade"),t.parentNode.insertBefore(s,t)}removePlaceholder(t){if(t.parentNode.classList.contains("target")){const n=t.parentNode.querySelector(".ggm-dragger-placeholder");if(n===null)return;t.parentNode.removeChild(n);return}const i=t.parentNode.dataset.matchMax*1,s=t.parentNode.querySelector(".ggm-dragger-placeholder");if(s===null){const n=t.parentNode.querySelector(".clone");if(n===null)return;n.classList.remove("placeholder-fade");return}i!==0&&t.parentNode.removeChild(s)}replacePlaceholder(t){const i=t.parentNode;let s=i.querySelector(".ggm-dragger-placeholder");if(i.classList.contains("source")){if(s==null&&(s=i.querySelector(".draggable")),s===null)return;i.replaceChild(t,s);return}s!==null&&i.replaceChild(t,s)}addClonePlaceholder(t){const i=t.cloneNode(!0);this.deepCloneId(i),i.classList.add("clone"),t.parentNode.insertBefore(i,t),i.addEventListener("mousedown",this.handleDragStart),i.addEventListener("touchstart",this.handleTouchStart)}initializeSources(t){this.sources=t.querySelectorAll(".source"),this.sources.forEach(i=>{i.classList.add("full");const s=i.dataset.matchMax*1;this.setRemaining(i,s===0?1e3:s)},this),this.draggers=t.querySelectorAll(".draggable"),this.draggers.forEach((i,s)=>{const n=i.parentNode.getAttribute("data-identifier");i.setAttribute("data-identifier",n),i.setAttribute("data-order",s),i.setAttribute("tabindex",0),i.addEventListener("mousedown",this.handleDragStart),i.addEventListener("touchstart",this.handleTouchStart)},this)}initializeTargets(t){this.targets=t.querySelectorAll(".target"),this.targets.forEach(i=>{i.setAttribute("tabindex",0)})}identifyTargets(t,i){this.targets.forEach(s=>{i&&!s.classList.contains("full")&&this.hasMatchingMatchGroup(t,s)&&s.classList.add("target-active")},this),i&&!this.isItemStartSource&&this.sourcewrapper.classList.add("target-active")}addListeners(t,i){i?(this.removeListeners(t,i),t.addEventListener("touchmove",this.handleTouchMove),t.addEventListener("touchend",this.handleTouchEnd)):(this.removeListeners(t,i),document.addEventListener("mousemove",this.handleDragMove),document.addEventListener("mouseup",this.handleDragEnd))}removeListeners(t,i){i?(t.removeEventListener("touchmove",this.handleTouchMove),t.removeEventListener("touchend",this.handleTouchEnd)):(document.removeEventListener("mousemove",this.handleDragMove),document.removeEventListener("mouseup",this.handleDragEnd))}clearTargetHighlights(){this.targets.forEach(t=>{t.classList.remove("target-active")},this),this.sourcewrapper.classList.remove("target-active")}getClosestElement(t,i){return t?t&&t.classList.contains(i)?t:this.getClosestElement(t.parentElement,i):!1}sortContainerElements(t){let i=[],s=t.children;for(let n=0;n<s.length;n++){const r=s[n].querySelector("div.draggable");r&&i.push([1*r.dataset.order,s[n]])}i.sort(function(n,r){return n[0]-r[0]});for(let n=0;n<i.length;n++)t.appendChild(i[n][1])}saveGapZindex(t){this.savedGapZindex=t.style.zIndex,t.style.zIndex=this.options.zindex}restoreGapZindex(t){t.style.zIndex=this.savedGapZindex}getResponse(){return this.computeResponse()}computeResponse(){let t=[];return this.targets.forEach(i=>{i.querySelectorAll(".draggable").forEach(s=>{t.push(`${s.dataset.identifier} ${i.dataset.identifier}`)})}),t.length===0?null:this.options.cardinality==="single"?t[0]:t}restoreResponse(t){t!==null&&(this.options.cardinality==="single"?this.restoreResponsePair(t):t.forEach(i=>{this.restoreResponsePair(i)},this))}restoreResponsePair(t){const i=this.getPair(t);if(i===null)return;const s=this.findSourceByIdentifier(i.source),n=this.findTargetGapByIdentifier(i.target);if(s===null||n===null)return;const r=s.querySelector(".draggable");r!==null&&(this.cloneOrEmptySourceDragger(s,r),this.restoreSourceDraggerToTarget(n,r))}cloneOrEmptySourceDragger(t,i){const s=t.dataset.matchMax*1;if(s===1){t.classList.remove("full"),this.decrementRemaining(t);return}if(s===0){this.addClonePlaceholder(i);return}if(this.getRemaining(t)===1){t.classList.remove("full"),this.decrementRemaining(t);return}this.decrementRemaining(t),this.addClonePlaceholder(i)}findSourceByIdentifier(t){for(let i=0;i<this.sources.length;i++)if(t===this.sources[i].dataset.identifier)return this.sources[i];return null}findTargetGapByIdentifier(t){for(let i=0;i<this.targets.length;i++)if(t===this.targets[i].dataset.identifier)return this.targets[i];return null}getPair(t){if(t===null)return null;const i=t.split(" ");return i.length!=2?null:{source:i[0],target:i[1]}}restoreSourceDraggerToTarget(t,i){t===null||i===null||(this.appendDraggerToGapTarget(t,i),this.incrementAssociationsCount(),this.isTargetFull(t)&&t.classList.add("full"))}hasMatchingMatchGroup(t,i){return t===null||i===null?!1:t.dataset.matchGroup===i.dataset.matchGroup}isTargetFull(t){if(t==null)return!1;const i=t.querySelectorAll(".draggable"),s=t.dataset.matchMax*1;return s===0?!1:i.length>=s}containsChoices(t){return t==null?!1:t.querySelectorAll(".draggable").length!==0}isExceedingMaxAssociations(t,i){return!(this.options.maxAssociations===0||i.classList.contains("source")||t.classList.contains("target")||this.currentAssociationsCount<this.options.maxAssociations)}initializeAssociationsCount(){this.currentAssociationsCount=0}incrementAssociationsCount(){this.currentAssociationsCount+=1}decrementAssociationsCount(){this.currentAssociationsCount!==0&&(this.currentAssociationsCount-=1)}getRemaining(t){return t.dataset.remaining*1}setRemaining(t,i){t.setAttribute("data-remaining",i)}incrementRemaining(t){const i=t.dataset.remaining*1+1;return t.setAttribute("data-remaining",i),i}decrementRemaining(t){let i=t.dataset.remaining*1-1;return i=i>=0?i:0,t.setAttribute("data-remaining",i),i}deepCloneId(t){t.id&&(t.id=`clone_${this.qtiAttributeValidation.randomString(5,"a")}`);for(let i=0;i<t.children.length;i++)this.deepCloneId(t.children[i])}reset(){this.resetDraggersToSources(),this.initializeAssociationsCount(),this.destroy()}resetDraggersToSources(){this.targets.forEach(t=>{t.querySelectorAll(".draggable").forEach(s=>{const n=this.findSourceByIdentifier(s.getAttribute("data-identifier"));n.classList.contains("full")||(n.classList.contains("full")?t.removeChild(s):(n.append(s),n.classList.add("full")))},this),t.classList.remove("full","contains-choice")},this)}destroy(){this.currentDragger!==null&&(document.removeEventListener("mousemove",this.handleDragMove),document.removeEventListener("mouseup",this.handleDragEnd)),this.wrapper.querySelectorAll(".draggable").forEach(i=>{i.removeEventListener("touchstart",this.handleTouchStart),i.removeEventListener("touchmove",this.handleTouchMove),i.removeEventListener("touchend",this.handleTouchEnd),i.removeEventListener("mousedown",this.handleDragStart)},this)}}const wq=new G,bq=new ie,vq={emits:["ggmGroupReady","ggmGroupUpdate","ggmGroupAssociationsLimit"],props:{responseIdentifier:{required:!0,type:String},cardinality:{required:!0,type:String},shuffle:{required:!1,type:String,default:"false"},maxAssociations:{required:!1,type:String,default:"1"},minAssociations:{required:!1,type:String,default:"0"},dataChoicesContainerWidth:{required:!1,type:String,default:null},interactionSubType:{required:!1,type:String,default:"default"},interactionStaticClass:{required:!0,type:String},priorState:{required:!1,type:Object,default:null}},data(){return{image:null,choices:[],order:[],gaps:[],response:null,isShuffle:null,hasPrompt:!1,interactionClassAttribute:null,presentationFactory:null,matchable:null,isQtiValid:!0}},computed:{computedMaxAssociations(){return this.maxAssociations*1}},methods:{getResponse(){return this.response},setResponse(e){this.response=e},disable(){this.matchable!==null&&this.matchable.toggleDisable(!0)},enable(){this.matchable!==null&&this.matchable.toggleDisable(!1)},getChoices(){return this.choices},setIsShuffle(e){this.isShuffle=e},validateChildren(){let e=0,t=0,i=!1;this.$slots.default()[0].children.forEach(s=>{if(wq.isValidSlot(s)){if(s.type.name==="QtiPrompt"){if(e>0||t>0||i)throw new c("Invalid element order. qti-prompt must come before the background image, qti-gap-text's, qti-gap-img's, or qti-associable-hotspot's");if(!this.hasPrompt)return this.hasPrompt=!0;throw new c("Maximum of 1 qti-prompt element permitted")}if(s.type.name==="QtiGapText"||s.type.name==="QtiGapImg"){if(t>0)throw new c("Invalid element order. qti-gap-text's and qti-gap-img's must come before qti-associable-hotspot's");return e+=1}if(s.type.name==="QtiAssociableHotspot")return t+=1;throw new c('Node is not one of qti-gap-text, qti-gap-img, or qti-associable-hotspot: "'+s.type.name+'"')}else if(s.type==="img"||s.type==="object"||s.type==="picture"){if(e>0||t>0)throw new c("Invalid element order. Background image must preceed qti-gap-text's, qti-gap-img's and qti-associable-hotspot's");i=!0}})},processChildren(){this.$.subTree.children[0].children[0].children.forEach(t=>{if(t.type==="img"||t.type==="object"||t.type==="picture"){this.image=t.el;return}t.component!==null&&(t.type.name==="QtiGapText"||t.type.name==="QtiGapImg"?this.choices.push(t.component.proxy):t.type.name==="QtiAssociableHotspot"&&this.gaps.push(t.component.proxy))})},insertAfter(e,t){t.parentNode.insertBefore(e,t.nextSibling)},processGroupUI(e){let t=this.createGapChoiceWrapper();if(t==null)return;let i=this.createGapTargetWrapper(),s=this.createContainer(this.priorState);this.processContainerChoices(s,t),this.saveContainerOrder(s),this.presentationFactory.initialize(this.$refs.root,t,i,this.image,this.dataChoicesContainerWidth,this.choices,this.gaps),this.matchable=new yq(this.$refs.root,{interactionSubType:this.interactionSubType,cardinality:this.cardinality,maxAssociations:this.computedMaxAssociations,response:e,onReady:this.handleWidgetReady,onUpdate:this.handleWidgetUpdate,onAssociationsLimit:this.handleAssociationsLimit})},createGapChoiceWrapper(){let e=this.$refs.root.querySelector(".qti-gap-choice");if(e===null)return null;let t=document.createElement("ul");return t.classList.add("qti-ggm-source-wrapper"),this.$refs.root.insertBefore(t,e),t},createGapTargetWrapper(){let e=document.createElement("div");e.classList.add("qti-ggm-target-wrapper"),e.append(this.image);for(let t=0;t<this.gaps.length;t++)e.append(this.gaps[t].$el);return this.$refs.root.append(e),e},createContainer(e){let t=[];return e===null?(this.choices.forEach(s=>{t.push({fixed:s.fixed==="true",node:s})}),this.isShuffle&&bq.shuffleArrayFixed(t),t):(e.state.order.forEach(s=>{const n=this.findChoiceByIdentifier(s,this.choices);n!==null&&t.push({fixed:n.fixed==="true",node:n})},this),t)},processContainerChoices(e,t){this.choices.splice(0,this.choices.length),t.innerHTML="",e.forEach(i=>{t.appendChild(i.node.$el),this.choices.push(i.node)},this)},saveContainerOrder(e){const t=[];e.forEach(i=>{t.push(i.node.identifier)}),this.order=t},findChoiceByIdentifier(e,t){for(let i=0;i<t.length;i++)if(t[i].$el.getAttribute("data-identifier")===e)return t[i];throw new O('Gap Match Interaction State Invalid. Choice identifier "'+e+'" not found.')},resetGroupUI(){this.processGroupUI(null)},handleWidgetReady(e){this.setResponse(e.response),this.$emit("ggmGroupReady",{response:this.getResponse(),order:this.order})},handleWidgetUpdate(e){this.setResponse(e.response),this.$emit("ggmGroupUpdate",{response:this.getResponse()})},handleAssociationsLimit(){this.$emit("ggmGroupAssociationsLimit")},initializeGraphicGapMatchGroup(){this.presentationFactory=new gq(this.interactionStaticClass)}},created(){try{if(typeof this.cardinality>"u")throw new c("Undefined qti-graphic-gap-match-interaction cardinality");if(this.cardinality!=="multiple")throw new c('qti-graphic-gap-match-interaction cardinality must be "multiple"');this.setIsShuffle(this.shuffle==="true"),this.initializeGraphicGapMatchGroup(),this.validateChildren()}catch(e){throw this.isQtiValid=!1,console.log("[QtiGapMatchInteraction][ValidationError]",e.name,e.message),new c(e.message)}},mounted(){if(this.isQtiValid)try{this.processChildren(),this.processGroupUI(this.priorState===null?null:this.priorState.value)}catch(e){if(this.isQtiValid=!1,e.name==="QtiValidationException")throw console.log("[QtiGapMatchInteraction][ValidationException]",e.message),new c(e.message);if(e.name==="QtiEvaluationException")throw console.log("[QtiGapMatchInteraction][EvaluationException]",e.message),new O(e.message)}},beforeUnmount(){this.matchable!==null&&(this.matchable.destroy(),this.matchable=null)}},Eq={ref:"root",class:"qti-ggm-group-wrapper"};function Cq(e,t,i,s,n,r){return l.openBlock(),l.createElementBlock("div",Eq,[l.renderSlot(e.$slots,"default")],512)}const Tq=P(vq,[["render",Cq]]);class Sq{constructor(){this.constants={QTI_CHOICES_TOP:"qti-choices-top",QTI_CHOICES_BOTTOM:"qti-choices-bottom",QTI_CHOICES_LEFT:"qti-choices-left",QTI_CHOICES_RIGHT:"qti-choices-right",QTI_MATCH_TABULAR:"qti-match-tabular",QTI_HEADER_HIDDEN:"qti-header-hidden",ROW_CENTRIC:"row-centric",DATA_MAX_SELECTIONS_MESSAGE:"data-max-selections-message",DATA_MIN_SELECTIONS_MESSAGE:"data-min-selections-message",DATA_FIRST_COLUMN_HEADER:""},this.interactionSubType="default",this.parentClass="",this.clazzTokens=[],this.matchWrapperElement=null,this.matchGroupNode=null,this.matchSetNode1=null,this.matchSetNode2=null,this.choices1=[],this.choices2=[],this.presentation_Choices_Orientation=null,this.presentation_Header_Hidden=!1,this.presentation_Row_Centric=!1,this.presentation_MaxSelectionsMessage="",this.presentation_MinSelectionsMessage=""}initialize(t,i,s,n,r){this.interactionSubType=t,this.matchWrapperElement=i,this.matchGroupNode=s,this.parentClass=s.matchInteractionStaticClass,this.matchSetNode1=n,this.matchSetNode2=r,this.choices1=this.matchSetNode1.getChoices(),this.choices2=this.matchSetNode2.getChoices(),this.processRootClassAttribute(this.parentClass),this.processPresentation()}processRootClassAttribute(t){const i=t.split(" ");for(let s=0;s<i.length;s++)switch(i[s]){case this.constants.QTI_CHOICES_TOP:case this.constants.QTI_CHOICES_BOTTOM:case this.constants.QTI_CHOICES_LEFT:case this.constants.QTI_CHOICES_RIGHT:this.presentation_Choices_Orientation=i[s];break;case this.constants.QTI_MATCH_TABULAR:break;case this.constants.QTI_HEADER_HIDDEN:this.presentation_Header_Hidden=!0;break;case this.constants.ROW_CENTRIC:this.presentation_Row_Centric=!0;break}this.clazzTokens=i}processPresentation(){this.matchSetNode1.$refs.matchset.classList.add("qti-match-source-wrapper"),this.matchSetNode2.$refs.matchset.classList.add("qti-match-target-wrapper"),this.interactionSubType==="default"?(this.presentation_Choices_Orientation===null&&(this.presentation_Choices_Orientation=this.constants.QTI_CHOICES_TOP),this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_LEFT?(this.matchSetNode1.$refs.matchset.classList.add(this.constants.QTI_CHOICES_LEFT),this.matchSetNode2.$refs.matchset.classList.add(this.constants.QTI_CHOICES_LEFT)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_TOP?(this.matchSetNode1.$refs.matchset.classList.add(this.constants.QTI_CHOICES_TOP),this.matchSetNode2.$refs.matchset.classList.add(this.constants.QTI_CHOICES_TOP)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_RIGHT?(this.matchSetNode1.$refs.matchset.classList.add(this.constants.QTI_CHOICES_RIGHT),this.matchSetNode2.$refs.matchset.classList.add(this.constants.QTI_CHOICES_RIGHT),this.matchWrapperElement.insertBefore(this.matchSetNode2.$refs.matchset,this.matchSetNode1.$refs.matchset)):this.presentation_Choices_Orientation===this.constants.QTI_CHOICES_BOTTOM&&(this.matchSetNode1.$refs.matchset.classList.add(this.constants.QTI_CHOICES_BOTTOM),this.matchSetNode2.$refs.matchset.classList.add(this.constants.QTI_CHOICES_BOTTOM),this.matchWrapperElement.insertBefore(this.matchSetNode2.$refs.matchset,this.matchSetNode1.$refs.matchset)),this.updateMatchSetChoices(this.matchSetNode1,!0),this.updateMatchSetChoices(this.matchSetNode2,!1)):this.interactionSubType==="matchtabular"&&(this.createMatchTable(),this.matchSetNode1.$refs.matchset.classList.add("matchset-hidden"),this.matchSetNode2.$refs.matchset.classList.add("matchset-hidden"))}updateMatchSetChoices(t,i){const s=t.getChoices();for(let n=0;n<s.length;n++)i?(s[n].$refs.choice.classList.add("source"),s[n].$refs.description.classList.add("draggable")):(s[n].$refs.choice.classList.add("target"),s[n].$refs.description.classList.add("match-target-label"))}createMatchTable(){const t=document.createElement("table");this.clazzTokens.forEach(i=>{t.classList.add(i)}),t.classList.add("matchtabular","table","table-bordered"),this.matchWrapperElement.insertBefore(t,this.matchSetNode1.$refs.matchset)}}class xq{constructor(t,i){J(this,"options",{interactionSubType:"default",cardinality:"single",maxAssociations:0,response:null,onReady:null,onUpdate:null,onSelectionsLimit:null});return this.qtiAttributeValidation=new G,this.wrapper=t,this.sourcewrapper=this.wrapper.querySelector(".qti-match-source-wrapper"),this.targetwrapper=this.wrapper.querySelector(".qti-match-target-wrapper"),this.processOptions(i),this.handleDragStart=this.handleDragStart.bind(this),this.handleDragMove=this.handleDragMove.bind(this),this.handleDragEnd=this.handleDragEnd.bind(this),this.handleTouchStart=this.handleTouchStart.bind(this),this.handleTouchMove=this.handleTouchMove.bind(this),this.handleTouchEnd=this.handleTouchEnd.bind(this),this.itemTarget=null,this.itemStart=null,this.isItemStartSource=!0,this.initialX=0,this.initialY=0,this.offsetX=0,this.offsetY=0,this.startingX=0,this.startingY=0,this.currentAssociationsCount=0,this.isDisabled=!1,this.currentDragger=null,this.initializeSources(this.sourcewrapper),this.initializeTargets(this.targetwrapper),this.restoreResponse(this.options.response),this.notifyReady(),this}processOptions(t){"interactionSubType"in t&&(this.options.interactionSubType=t.interactionSubType),"cardinality"in t&&(this.options.cardinality=t.cardinality),"response"in t&&(this.options.response=t.response),"maxAssociations"in t&&(this.options.maxAssociations=t.maxAssociations),"onReady"in t&&(this.options.onReady=t.onReady),"onUpdate"in t&&(this.options.onUpdate=t.onUpdate),"onAssociationsLimit"in t&&(this.options.onAssociationsLimit=t.onAssociationsLimit)}notifyReady(){this.options.onReady!==null&&this.options.onReady({response:this.getResponse()})}notifyUpdate(){this.options.onUpdate!==null&&this.options.onUpdate({response:this.computeResponse()})}notifyAssociationsLimit(){this.options.onAssociationsLimit!==null&&this.options.onAssociationsLimit()}toggleDisable(t){this.isDisabled=t,this.draggers.forEach(i=>{t?i.classList.add("disabled"):i.classList.remove("disabled")})}handleDragStart(t){if(t.preventDefault(),!this.isDisabled&&t.button==0)return this.interactionStart(t.target,t.clientX,t.clientY,!1),!1}handleTouchStart(t){if(t.preventDefault(),!this.isDisabled)return t.targetTouches.length!=1||this.interactionStart(t.target,t.touches[0].pageX,t.touches[0].pageY,!0),!1}interactionStart(t,i,s,n){const r=this.getClosestElement(t,"draggable");this.itemStart=r.parentNode,this.isItemStartSource=this.itemStart.classList.contains("source"),this.identifyTargets(this.itemStart,!0),this.itemTarget=null;const a=r.getBoundingClientRect();this.initialX=i,this.initialY=s,this.startingX=a.left,this.startingY=a.top,this.offsetX=i-this.startingX,this.offsetY=s-this.startingY,this.addPlaceholder(r),r.style.userSelect="none",r.style.width=a.width+"px",r.style.height=a.height+"px",r.style.transform=`translateX(${a.left}px) translateY(${a.top}px) translateZ(0)`,r.classList.add("dragging"),this.setCurrentDragger(r),this.addListeners(r,n)}handleDragMove(t){t.preventDefault(),!this.isDisabled&&this.interactionMove(t.clientX,t.clientY)}handleTouchMove(t){t.preventDefault(),!this.isDisabled&&t.targetTouches.length==1&&this.interactionMove(t.touches[0].clientX,t.touches[0].clientY)}interactionMove(t,i){const s=this.currentDragger;this.offsetX=t-this.initialX,this.offsetY=i-this.initialY,this.constrainDraggerToWrapper(s,this.wrapper),s.style.transform=`translateX(${this.startingX+this.offsetX}px) translateY(${this.startingY+this.offsetY}px) translateZ(0) scale(1)`;const n=s.getBoundingClientRect();this.findDraggerItemTarget(s,n,this.targets),this.isItemStartSource||this.findSourceDraggerTarget(s,n)}constrainDraggerToWrapper(t,i){const s=t.getBoundingClientRect(),n=i.getBoundingClientRect(),r=this.startingX+this.offsetX-n.x,a=this.startingY+this.offsetY-n.y,o=this.startingX+s.width+this.offsetX-(n.x+n.width),u=this.startingY+s.height+this.offsetY-(n.y+n.height);r<0&&(this.offsetX=this.offsetX-r),o>0&&(this.offsetX=this.offsetX-o),a<0&&(this.offsetY=this.offsetY-a),u>0&&(this.offsetY=this.offsetY-u)}handleDragEnd(t){this.isDisabled||this.interactionEnd(t.clientX,t.clientY,!1)}handleTouchEnd(t){this.isDisabled||this.interactionEnd(t.changedTouches[0].clientX,t.changedTouches[0].clientY,!0)}interactionEnd(t,i,s){const n=this.currentDragger;if(this.itemTarget===null?n.style.transform=`translateX(${this.startingX}px) translateY(${this.startingY}px) translateZ(0)`:n.style.transform=`translateX(${this.startingX+this.offsetX}px) translateY(${this.startingY+this.offsetY}px) translateZ(0)`,n.removeAttribute("style"),n.classList.remove("dragging"),this.clearTargetHighlights(),this.itemTarget===null){this.resetDraggerToItemStart(this.itemStart,n),this.setCurrentDragger(null),this.removeListeners(n,s);return}if(this.itemTarget.classList.contains("active")){if(this.itemTarget.classList.remove("active"),this.isExceedingMaxAssociations(this.itemStart,this.itemTarget,n)){this.resetDraggerToItemStart(this.itemStart,n),this.notifyAssociationsLimit(),this.setCurrentDragger(null),this.removeListeners(n,s);return}if(this.itemStart.getAttribute("data-identifier")===this.itemTarget.getAttribute("data-identifier")){this.resetDraggerToItemStart(this.itemStart,n),this.setCurrentDragger(null),this.removeListeners(n,s);return}this.removePlaceholder(n),this.setDraggerToItemTarget(this.itemTarget,n),this.itemTarget.classList.contains("source")&&(this.itemTarget.classList.add("full"),this.itemTarget.dataset.matchMax*1>0&&this.incrementRemaining(this.itemTarget),this.decrementAssociationsCount(),this.sortContainerElements(this.sourcewrapper)),this.itemStart.classList.contains("source")&&(this.itemStart.dataset.matchMax*1>0&&this.decrementRemaining(this.itemStart)===0&&this.itemStart.classList.remove("full"),this.incrementAssociationsCount()),this.itemStart.classList.contains("target")&&(this.isTargetFull(this.itemStart)?this.itemStart.classList.add("full"):this.itemStart.classList.remove("full")),this.notifyUpdate()}this.setCurrentDragger(null),this.removeListeners(n,s)}setCurrentDragger(t){this.currentDragger=t}resetDraggerToItemStart(t,i){this.replacePlaceholder(i),t.classList.contains("source")||i.setAttribute("style","width:100%")}setDraggerToItemTarget(t,i){if(t.classList.contains("source")){if(t.classList.contains("full")){const s=t.querySelector(".draggable");s!=null&&t.replaceChild(i,s);return}t.append(i);return}t.append(i),i.setAttribute("style","width:100%"),this.isTargetFull(t)?t.classList.add("full"):t.classList.remove("full")}findDraggerItemTarget(t,i,s){this.itemTarget=null,s.forEach(n=>{const r=n.getBoundingClientRect();if(i.top+t.offsetHeight/2<r.bottom&&i.right-t.offsetWidth/2>r.left&&i.bottom-t.offsetHeight/2>r.top&&i.left+t.offsetWidth/2<r.right){if(this.isItemStartSource&&n.classList.contains("source")||n.classList.contains("full")||!this.hasMatchingMatchGroup(t.parentNode,n))return;n.classList.add("active"),this.itemTarget=n}else n.classList.remove("active")},this)}findSourceDraggerTarget(t,i){const s=this.sourcewrapper.getBoundingClientRect();if(i.top+t.offsetHeight/2<s.bottom&&i.right-t.offsetWidth/2>s.left&&i.bottom-t.offsetHeight/2>s.top&&i.left+t.offsetWidth/2<s.right){for(let n=0;n<this.sources.length;n++)if(this.sources[n].dataset.identifier===t.dataset.identifier){this.sources[n].classList.add("active"),this.itemTarget=this.sources[n];break}}else for(let n=0;n<this.sources.length;n++)this.sources[n].classList.contains("active")&&this.sources[n].classList.remove("active")}addPlaceholder(t){if(!t.parentNode.classList.contains("source")){this.addPlaceholderElement(t,!1);return}const i=t.parentNode.dataset.matchMax*1;if(i===1){this.addPlaceholderElement(t,!1);return}if(i===0){this.addPlaceholderElement(t,!0);return}if(this.getRemaining(t.parentNode)===1){this.addPlaceholderElement(t,!1);return}this.addPlaceholderElement(t,!0)}addPlaceholderElement(t,i){const s=t.cloneNode(!0);this.deepCloneId(s),i?(s.classList.add("clone"),s.addEventListener("mousedown",this.handleDragStart),s.addEventListener("touchstart",this.handleTouchStart)):s.classList.add("match-dragger-placeholder"),s.classList.add("placeholder-fade"),t.parentNode.insertBefore(s,t)}removePlaceholder(t){if(t.parentNode.classList.contains("target")){const n=t.parentNode.querySelector(".match-dragger-placeholder");if(n===null)return;t.parentNode.removeChild(n);return}const i=t.parentNode.dataset.matchMax*1,s=t.parentNode.querySelector(".match-dragger-placeholder");if(s===null){const n=t.parentNode.querySelector(".clone");if(n===null)return;n.classList.remove("placeholder-fade");return}i!==0&&t.parentNode.removeChild(s)}replacePlaceholder(t){const i=t.parentNode;let s=i.querySelector(".match-dragger-placeholder");if(i.classList.contains("source")){if(s==null&&(s=i.querySelector(".draggable")),s===null)return;i.replaceChild(t,s);return}s!==null&&i.replaceChild(t,s)}addClonePlaceholder(t){const i=t.cloneNode(!0);this.deepCloneId(i),i.classList.add("clone"),t.parentNode.insertBefore(i,t),i.addEventListener("mousedown",this.handleDragStart),i.addEventListener("touchstart",this.handleTouchStart)}initializeSources(t){this.sources=t.querySelectorAll(".source"),this.sources.forEach(i=>{i.classList.add("full");const s=i.dataset.matchMax*1;this.setRemaining(i,s===0?1e3:s)},this),this.draggers=t.querySelectorAll(".draggable"),this.draggers.forEach((i,s)=>{const n=i.parentNode.getAttribute("data-identifier");i.setAttribute("data-identifier",n),i.setAttribute("data-order",s),i.setAttribute("tabindex",0),i.addEventListener("mousedown",this.handleDragStart),i.addEventListener("touchstart",this.handleTouchStart)},this)}initializeTargets(t){this.targets=t.querySelectorAll(".target"),this.targets.forEach(i=>{i.setAttribute("tabindex",0)})}identifyTargets(t,i){this.targets.forEach(s=>{i&&!s.classList.contains("full")&&this.hasMatchingMatchGroup(t,s)&&s.classList.add("target-active")},this),i&&!this.isItemStartSource&&this.sourcewrapper.classList.add("target-active")}addListeners(t,i){i?(this.removeListeners(t,i),t.addEventListener("touchmove",this.handleTouchMove),t.addEventListener("touchend",this.handleTouchEnd)):(this.removeListeners(t,i),document.addEventListener("mousemove",this.handleDragMove),document.addEventListener("mouseup",this.handleDragEnd))}removeListeners(t,i){i?(t.removeEventListener("touchmove",this.handleTouchMove),t.removeEventListener("touchend",this.handleTouchEnd)):(document.removeEventListener("mousemove",this.handleDragMove),document.removeEventListener("mouseup",this.handleDragEnd))}clearTargetHighlights(){this.targets.forEach(t=>{t.classList.remove("target-active")},this),this.sourcewrapper.classList.remove("target-active")}getClosestElement(t,i){return t?t&&t.classList.contains(i)?t:this.getClosestElement(t.parentElement,i):!1}sortContainerElements(t){let i=[],s=t.children;for(let n=0;n<s.length;n++){const r=s[n].querySelector("div.draggable");r&&i.push([1*r.dataset.order,s[n]])}i.sort(function(n,r){return n[0]-r[0]});for(let n=0;n<i.length;n++)t.appendChild(i[n][1])}getResponse(){return this.computeResponse()}computeResponse(){let t=[];return this.targets.forEach(i=>{i.querySelectorAll(".draggable").forEach(s=>{t.push(`${s.dataset.identifier} ${i.dataset.identifier}`)})}),t.length===0?null:this.options.cardinality==="single"?t[0]:t}restoreResponse(t){t!==null&&(this.options.cardinality==="single"?this.restoreResponsePair(t):t.forEach(i=>{this.restoreResponsePair(i)},this))}restoreResponsePair(t){const i=this.getPair(t);if(i===null)return;const s=this.findSourceByIdentifier(i.source),n=this.findTargetGapByIdentifier(i.target);if(s===null||n===null)return;const r=s.querySelector(".draggable");r!==null&&(this.cloneOrEmptySourceDragger(s,r),this.restoreSourceDraggerToTarget(n,r))}cloneOrEmptySourceDragger(t,i){const s=t.dataset.matchMax*1;if(s===1){t.classList.remove("full"),this.decrementRemaining(t);return}if(s===0){this.addClonePlaceholder(i);return}if(this.getRemaining(t)===1){t.classList.remove("full"),this.decrementRemaining(t);return}this.decrementRemaining(t),this.addClonePlaceholder(i)}findSourceByIdentifier(t){for(let i=0;i<this.sources.length;i++)if(t===this.sources[i].dataset.identifier)return this.sources[i];return null}findTargetGapByIdentifier(t){for(let i=0;i<this.targets.length;i++)if(t===this.targets[i].dataset.identifier)return this.targets[i];return null}getPair(t){if(t===null)return null;const i=t.split(" ");return i.length!=2?null:{source:i[0],target:i[1]}}restoreSourceDraggerToTarget(t,i){t===null||i===null||(t.append(i),i.setAttribute("style","width:100%"),this.incrementAssociationsCount(),this.isTargetFull(t)&&t.classList.add("full"))}hasMatchingMatchGroup(t,i){return t===null||i===null?!1:t.dataset.matchGroup===i.dataset.matchGroup}isTargetFull(t){if(t==null)return!1;const i=t.querySelectorAll(".draggable"),s=t.dataset.matchMax*1;return s===0?!1:i.length>=s}isExceedingMaxAssociations(t,i){return!(this.options.maxAssociations===0||i.classList.contains("source")||t.classList.contains("target")||this.currentAssociationsCount<this.options.maxAssociations)}initializeAssociationsCount(){this.currentAssociationsCount=0}incrementAssociationsCount(){this.currentAssociationsCount+=1}decrementAssociationsCount(){this.currentAssociationsCount!==0&&(this.currentAssociationsCount-=1)}getRemaining(t){return t.dataset.remaining*1}setRemaining(t,i){t.setAttribute("data-remaining",i)}incrementRemaining(t){const i=t.dataset.remaining*1+1;return t.setAttribute("data-remaining",i),i}decrementRemaining(t){let i=t.dataset.remaining*1-1;return i=i>=0?i:0,t.setAttribute("data-remaining",i),i}deepCloneId(t){t.id&&(t.id=`clone_${this.qtiAttributeValidation.randomString(5,"a")}`);for(let i=0;i<t.children.length;i++)this.deepCloneId(t.children[i])}reset(){this.resetDraggersToSources(),this.initializeAssociationsCount(),this.destroy()}resetDraggersToSources(){this.targets.forEach(t=>{t.querySelectorAll(".draggable").forEach(s=>{const n=this.findSourceByIdentifier(s.getAttribute("data-identifier"));n.classList.contains("full")||(t.classList.remove("full"),n.classList.contains("full")?t.removeChild(s):(n.append(s),n.classList.add("full")))},this)},this)}destroy(){this.currentDragger!==null&&(document.removeEventListener("mousemove",this.handleDragMove),document.removeEventListener("mouseup",this.handleDragEnd)),this.wrapper.querySelectorAll(".draggable").forEach(i=>{i.removeEventListener("touchstart",this.handleTouchStart),i.removeEventListener("touchmove",this.handleTouchMove),i.removeEventListener("touchend",this.handleTouchEnd),i.removeEventListener("mousedown",this.handleDragStart)},this)}}class Iq{constructor(t,i){J(this,"options",{interactionSubType:"matchtabular",isHeaderHidden:!1,isRowCentric:!1,firstColumnHeader:null,cardinality:"single",maxAssociations:0,response:null,onReady:null,onUpdate:null,onSelectionsLimit:null});J(this,"keyCodes",{Enter:13,Space:32,End:35,Home:36,ArrowLeft:37,ArrowUp:38,ArrowRight:39,ArrowDown:40});return this.wrapper=t,this.table=this.wrapper.querySelector("table.matchtabular"),this.sourcewrapper=this.wrapper.querySelector(".qti-match-source-wrapper"),this.targetwrapper=this.wrapper.querySelector(".qti-match-target-wrapper"),this.currentAssociationsCount=0,this.isDisabled=!1,this.processOptions(i),this.handleClick=this.handleClick.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.handleFocus=this.handleFocus.bind(this),this.handleBlur=this.handleBlur.bind(this),this.state=new Map,this.initializeTable(this.sourcewrapper,this.targetwrapper),this.restoreResponse(),this.notifyReady(),this}processOptions(t){"interactionSubType"in t&&(this.options.interactionSubType=t.interactionSubType),"isHeaderHidden"in t&&(this.options.isHeaderHidden=t.isHeaderHidden),"isRowCentric"in t&&(this.options.isRowCentric=t.isRowCentric),"firstColumnHeader"in t&&(this.options.firstColumnHeader=t.firstColumnHeader),"cardinality"in t&&(this.options.cardinality=t.cardinality),"response"in t&&(this.options.response=t.response),"maxAssociations"in t&&(this.options.maxAssociations=t.maxAssociations),"onReady"in t&&(this.options.onReady=t.onReady),"onUpdate"in t&&(this.options.onUpdate=t.onUpdate),"onAssociationsLimit"in t&&(this.options.onAssociationsLimit=t.onAssociationsLimit)}notifyReady(){this.options.onReady!==null&&this.options.onReady({response:this.getResponse()})}notifyUpdate(){this.options.onUpdate!==null&&this.options.onUpdate({response:this.computeResponse()})}notifyAssociationsLimit(){this.options.onAssociationsLimit!==null&&this.options.onAssociationsLimit()}toggleDisable(t){this.isDisabled=t,this.controls.forEach(i=>{t?i.classList.add("disabled"):i.classList.remove("disabled")})}handleClick(t){if(!this.isDisabled){if(this.isRadio(t.target)){this.setControlChecked(t.target);return}this.toggleControl(t.target)}}handleKeydown(t){let i=!1;switch(t.code){case"Space":case"Enter":this.isDisabled||this.toggleControl(t.target),i=!0;break;case"ArrowUp":case"ArrowLeft":i=!0;break;case"ArrowDown":case"ArrowRight":i=!0;break}i&&(t.stopPropagation(),t.preventDefault())}handleFocus(){}handleBlur(){}toggleControl(t){if(!this.isChecked(t)){if(this.isExceedingMaxAssociations()){this.notifyAssociationsLimit();return}if(this.isExceedingMatchMax(t.dataset.pair,t.dataset.sourceMax*1,!0)||this.isExceedingMatchMax(t.dataset.pair,t.dataset.targetMax*1,!1))return;this.updateState(t.dataset.pair,this.toggleChecked(t)),this.notifyUpdate();return}this.updateState(t.dataset.pair,this.toggleChecked(t)),this.notifyUpdate()}setControlChecked(t){if(!this.isChecked(t)){if(this.isExceedingMaxAssociations()){this.notifyAssociationsLimit();return}if(this.isExceedingMatchMax(t.dataset.pair,t.dataset.sourceMax*1,!0)||this.isExceedingMatchMax(t.dataset.pair,t.dataset.targetMax*1,!1))return;this.updateState(t.dataset.pair,this.setChecked(t,!0)),this.notifyUpdate();return}this.updateState(t.dataset.pair,this.setChecked(t,!0)),this.notifyUpdate()}setChecked(t,i){const s=i?"true":"false";return t.setAttribute("aria-checked",s),s}toggleChecked(t){const s=t.getAttribute("aria-checked")==="true"?"false":"true";return t.setAttribute("aria-checked",s),s}isRadio(t){return t===null?!1:t.getAttribute("role")==="radio"}isChecked(t){return t===null?!1:t.getAttribute("aria-checked")==="true"}setTabIndex(t){this.tabIndex=t}setFocus(){}setBlur(){}updateState(t,i){this.state.set(t,i),this.currentAssociationsCount=0;for(let s of this.state.values())s==="true"&&(this.currentAssociationsCount+=1)}initializeTable(t,i){this.sources=this.getChoices(t),this.targets=this.getChoices(i);const s=`width:${this.getColumnWidthPercentage(this.targets.length)}%`;this.table.innerHTML=`${this.getHeader(s)}${this.getBody(s)}`,this.controls=this.table.querySelectorAll(".control-cell"),this.controls.forEach(n=>{const r=n.getAttribute("data-pair");this.updateState(r,"false"),n.addEventListener("click",this.handleClick),n.addEventListener("keydown",this.handleKeydown),n.addEventListener("focus",this.handleFocus),n.addEventListener("blur",this.handleBlur)},this)}getHeader(t){if(this.options.isHeaderHidden)return"";let i=`<th scope="col" class="header-cell">${this.options.firstColumnHeader==null?"":this.options.firstColumnHeader}</th>`;return this.options.isRowCentric?(i+=this.getSourceHeader(t),`<thead>${i}</thead>`):(i+=this.getTargetHeader(t),`<thead>${i}</thead>`)}getTargetHeader(t){let i="";return this.targets.forEach(s=>{i+=`<th scope="col" class="header-cell" style="${t}">${s.innerHTML}</th>`}),i}getSourceHeader(t){let i="";return this.sources.forEach(s=>{i+=`<th scope="col" class="header-cell" style="${t}">${s.innerHTML}</th>`}),i}getBody(t){let i="";return this.options.isRowCentric?(this.targets.forEach(s=>{i+=`<tr><th scope="row" class="row-header-cell">${s.innerHTML}</th>`;const n=s.getAttribute("data-match-max");this.sources.forEach(r=>{const a=r.getAttribute("data-match-max"),o=r.getAttribute("data-identifier"),u=s.getAttribute("data-identifier"),h=`${o} ${u}`;i+=`<td class="table-cell" style="${t}">
|
168
168
|
<div class="control-cell" aria-checked="false" tabindex="0" role="checkbox"
|
169
169
|
data-source-max="${a}" data-target-max="${n}" data-pair="${h}"></div>
|
170
170
|
</td>`}),i+="</tr>"}),`<tbody>${i}</tbody>`):(this.sources.forEach(s=>{i+=`<tr><th scope="row" class="row-header-cell">${s.innerHTML}</th>`;const n=s.getAttribute("data-match-max");this.targets.forEach(r=>{const a=r.getAttribute("data-match-max"),o=s.getAttribute("data-identifier"),u=r.getAttribute("data-identifier"),h=`${o} ${u}`;i+=`<td class="table-cell" style="${t}">
|