@citolab/qti-components 7.0.6-beta.2 → 7.0.6-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import{a as ne,b as W,c as ae,e as le,f as K,g as $t,h as Ot,i as Be,j as It}from"./chunk-5BR5CJFH.js";import{a as Ht}from"./chunk-5FCXUJAG.js";import{a as Ue}from"./chunk-EHK76KRT.js";import{a as T}from"./chunk-XUJ7TXHW.js";import{a as x}from"./chunk-R33OODNX.js";import{a as Nt}from"./chunk-KWPDTFYH.js";import{a as V}from"./chunk-RXKI3AO4.js";import{a as q}from"./chunk-X2KBNXRO.js";import{a as f,b as d,c as C,d as Ye,e as Vt}from"./chunk-5GCSZ3CH.js";import{a as b,d as h,e as at,f as oe,g as k,i as y}from"./chunk-LZZB4VGC.js";import{a as R}from"./chunk-QQCGUVEV.js";import{a as Dt,b as D}from"./chunk-FRS2J3OS.js";import{a as o}from"./chunk-IAP2CEE7.js";var M=class extends y{constructor(){super();this.identifier="";this.adaptive="false";this.timeDependent=null;this._handleDisabledChange=(e,t)=>{this._interactionElements.forEach(i=>i.disabled=t)};this._handleReadonlyChange=(e,t)=>this._interactionElements.forEach(i=>i.readonly=t);this._context={identifier:this.getAttribute("identifier"),variables:Nt};this._initialContext={...this._context,variables:this._context.variables};this._feedbackElements=[];this._interactionElements=[];this.addEventListener("qti-register-variable",e=>{this._context={...this._context,variables:[...this._context.variables,e.detail.variable]},this._initialContext=this._context,e.stopPropagation()}),this.addEventListener("qti-register-feedback",e=>{e.stopPropagation();let t=e.detail;this._feedbackElements.push(t),(Number(this._context.variables.find(r=>r.identifier==="numAttempts")?.value)||0)>0&&t.checkShowFeedback(t.outcomeIdentifier)}),this.addEventListener("qti-register-interaction",e=>{e.stopPropagation();let t=e.composedPath();e.composedPath.length===1&&this._interactionElements.push(t[0])}),this.addEventListener("end-attempt",e=>{let{responseIdentifier:t,countAttempt:i}=e.detail;this.validate(),this.updateResponseVariable(t,"true"),this.processResponse(i)}),this.addEventListener("qti-set-outcome-value",e=>{let{outcomeIdentifier:t,value:i}=e.detail;this.updateOutcomeVariable(t,i),e.stopPropagation()}),this.addEventListener("qti-interaction-response",this.handleUpdateResponseVariable)}get variables(){return this._context.variables.map(e=>({identifier:e.identifier,value:e.value,type:e.type,...e.type==="outcome"&&e.identifier==="SCORE"?{externalScored:e.externalScored}:{}}))}set variables(e){if(!Array.isArray(e)||e.some(t=>!("identifier"in t))){console.warn("variables property should be an array of VariableDeclaration");return}this._context={...this._context,variables:this._context.variables.map(t=>{let i=e.find(r=>r.identifier===t.identifier);return i?{...t,...i}:t})},this._context.variables.forEach(t=>{if(t.type==="response"){let i=this._interactionElements.find(r=>r.responseIdentifier===t.identifier);i&&(i.value=t.value)}})}async connectedCallback(){super.connectedCallback(),await this.updateComplete,this._emit("qti-assessment-item-connected",this)}set responses(e){if(e)for(let t of e){this.getResponse(t.responseIdentifier)&&this.updateResponseVariable(t.responseIdentifier,t.response);let r=this._interactionElements.find(a=>a.getAttribute("response-identifier")===t.responseIdentifier);r&&(r.value=t.response)}}render(){return h`<slot></slot>`}showCorrectResponse(e){let i=this._context.variables.filter(r=>"correctResponse"in r&&r.correctResponse).map(r=>({responseIdentifier:r.identifier,response:r.correctResponse}));for(let r of i){let a=this._interactionElements.find(p=>p.getAttribute("response-identifier")===r.responseIdentifier);a&&(a.correctResponse=e?r.response:"")}}processResponse(e=!0){this.validate();let t=this.querySelector("qti-response-processing");return!t||!t.process?!1:(t.process(),this.adaptive==="false"&&this.updateOutcomeVariable("completionStatus",this._getCompletionStatus()),e&&this.updateOutcomeVariable("numAttempts",(+this._context.variables.find(i=>i.identifier==="numAttempts")?.value+1).toString()),this._emit("qti-response-processed"),!0)}resetResponses(){this._context=this._initialContext}getResponse(e){return this.getVariable(e)}getOutcome(e){return this.getVariable(e)}getVariable(e){return this._context.variables.find(t=>t.identifier===e)||null}handleUpdateResponseVariable(e){let{responseIdentifier:t,response:i}=e.detail;this.updateResponseVariable(t,i)}updateResponseVariable(e,t){this._context={...this._context,variables:this._context.variables.map(i=>i.identifier!==e?i:{...i,value:t})},this._emit("qti-interaction-changed",{item:this.identifier,responseIdentifier:e,response:Array.isArray(t)?[...t]:t}),this.adaptive==="false"&&this.updateOutcomeVariable("completionStatus",this._getCompletionStatus())}updateOutcomeVariable(e,t){let i=this.getOutcome(e);if(!i){console.warn(`Can not set qti-outcome-identifier: ${e}, it is not available`);return}this._context={...this._context,variables:this._context.variables.map(r=>r.identifier!==e?r:{...r,value:i.cardinality==="single"?t:[...r.value,t]})},this._feedbackElements.forEach(r=>r.checkShowFeedback(e)),this._emit("qti-outcome-changed",{item:this.identifier,outcomeIdentifier:e,value:this._context.variables.find(r=>r.identifier===e)?.value})}validate(){return this._interactionElements.every(e=>e.validate())?!0:this._interactionElements.some(e=>e.validate())?!1:null}_getCompletionStatus(){let e=this.validate();return e===!0?"completed":e===!1?"incomplete":"not_attempted"}_emit(e,t=null){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}};o([d({type:String})],M.prototype,"title",2),o([d({type:String})],M.prototype,"identifier",2),o([d({type:String})],M.prototype,"adaptive",2),o([d({type:String})],M.prototype,"timeDependent",2),o([d({type:Boolean})],M.prototype,"disabled",2),o([T("disabled",{waitUntilFirstUpdate:!0})],M.prototype,"_handleDisabledChange",2),o([d({type:Boolean})],M.prototype,"readonly",2),o([T("readonly",{waitUntilFirstUpdate:!0})],M.prototype,"_handleReadonlyChange",2),o([Dt({context:R})],M.prototype,"_context",2),M=o([f("qti-assessment-item")],M);var ce=class extends y{constructor(){super(...arguments);this.identifier="";this.href=""}async connectedCallback(){super.connectedCallback();let e=new Event("qti-assessment-stimulus-ref-connected",{cancelable:!0,bubbles:!0,composed:!0});if(this.dispatchEvent(e)){let r=this.closest("qti-assessment-item").querySelector(`[data-stimulus-idref=${this.identifier}]`);r?await this.updateStimulusRef(r):console.warn(`Stimulus with data-stimulus-idref ${this.identifier} not found`)}}async updateStimulusRef(e){let t=await Ht().load(this.href).then(i=>i.htmlDoc());if(t){let i=t.querySelectorAll("qti-stimulus-body, qti-stylesheet");e.innerHTML="",e.append(...i)}}};o([d({type:String})],ce.prototype,"identifier",2),o([d({type:String})],ce.prototype,"href",2),ce=o([f("qti-assessment-stimulus-ref")],ce);var Xe=class extends y{};Xe=o([f("qti-companion-materials-info")],Xe);var ye=class extends y{render(){return h`<slot @slotchange=${this.handleSlotChange}></slot>`}handleSlotChange(){let s=Array.from(this.firstElementChild?.childNodes??[]).find(e=>e.nodeType===Node.COMMENT_NODE);try{this.operatorFunction=new Function("context","fn","item",s?.textContent??"")}catch(e){console.error("custom-operator contains invalid javascript code",e)}}calculate(){let s={variable:t=>this._context?.variables.find(i=>i.identifier===t)?.value??"",correct:t=>this._context?.variables.find(i=>i.identifier===t)?.correctResponse??""},e={getVariable:t=>this._context?.variables.find(i=>i.identifier===t),updateOutcomeVariable:(t,i)=>{this.dispatchEvent(new CustomEvent("qti-set-outcome-value",{bubbles:!0,composed:!0,detail:{outcomeIdentifier:t,value:i}}))},updateResponseVariable:(t,i)=>{this.dispatchEvent(new CustomEvent("qti-interaction-response",{bubbles:!0,composed:!0,detail:{responseIdentifier:t,response:i}}))}};return this.operatorFunction(this._context,s,e)}};o([D({context:R,subscribe:!0}),C()],ye.prototype,"_context",2),ye=o([f("qti-custom-operator")],ye);var di=()=>new Intl.NumberFormat().format(.1).replace(/\d/g,""),xe=l=>{if(typeof l=="string")return l;let s=di();return s==="."?l.toLocaleString():l.toString().replace(".","").replace(s,".")};function lt(l){return l==null}function Ee(l){return l.replace(/([^:]\/)\/+/g,"$1").replace(/\/\//g,"/").replace("http:/","http://").replace("https:/","https://")}var S=class extends y{connectedCallback(){super.connectedCallback(),this.dispatchEvent(new CustomEvent("qti-register-feedback",{bubbles:!0,composed:!0,detail:this}))}checkShowFeedback(s){let e=this._context.variables.find(i=>i.identifier===s)||null;if(this.outcomeIdentifier!==s||!e)return;let t=!1;Array.isArray(e.value)?t=e.value.includes(this.identifier):t=!lt(this.identifier)&&!lt(e?.value)&&this.identifier===e.value||!1,this.showFeedback(t)}showFeedback(s){this.showStatus=s&&this.showHide==="show"||!s&&this.showHide==="hide"?"on":"off"}};o([d({type:String,attribute:"show-hide"})],S.prototype,"showHide",2),o([d({type:String,attribute:"outcome-identifier"})],S.prototype,"outcomeIdentifier",2),o([d({type:String})],S.prototype,"identifier",2),o([d({type:String,attribute:!1})],S.prototype,"showStatus",2),o([D({context:R,subscribe:!0}),C()],S.prototype,"_context",2);var Ce=class extends S{render(){return h` <slot part="feedback" class="feedback ${this.showStatus}"></slot> `}firstUpdated(s){this.checkShowFeedback(this.outcomeIdentifier)}};Ce.styles=b`
1
+ import{a as ne,b as W,c as ae,e as le,f as K,g as $t,h as Ot,i as Be,j as It}from"./chunk-5BR5CJFH.js";import{a as Ht}from"./chunk-5FCXUJAG.js";import{a as Ue}from"./chunk-EHK76KRT.js";import{a as T}from"./chunk-XUJ7TXHW.js";import{a as x}from"./chunk-UJP4TGD3.js";import{a as Nt}from"./chunk-KWPDTFYH.js";import{a as V}from"./chunk-RXKI3AO4.js";import{a as q}from"./chunk-X2KBNXRO.js";import{a as f,b as d,c as C,d as Ye,e as Vt}from"./chunk-5GCSZ3CH.js";import{a as b,d as h,e as at,f as oe,g as k,i as y}from"./chunk-LZZB4VGC.js";import{a as R}from"./chunk-QQCGUVEV.js";import{a as Dt,b as D}from"./chunk-FRS2J3OS.js";import{a as o}from"./chunk-IAP2CEE7.js";var M=class extends y{constructor(){super();this.identifier="";this.adaptive="false";this.timeDependent=null;this._handleDisabledChange=(e,t)=>{this._interactionElements.forEach(i=>i.disabled=t)};this._handleReadonlyChange=(e,t)=>this._interactionElements.forEach(i=>i.readonly=t);this._context={identifier:this.getAttribute("identifier"),variables:Nt};this._initialContext={...this._context,variables:this._context.variables};this._feedbackElements=[];this._interactionElements=[];this.addEventListener("qti-register-variable",e=>{this._context={...this._context,variables:[...this._context.variables,e.detail.variable]},this._initialContext=this._context,e.stopPropagation()}),this.addEventListener("qti-register-feedback",e=>{e.stopPropagation();let t=e.detail;this._feedbackElements.push(t),(Number(this._context.variables.find(r=>r.identifier==="numAttempts")?.value)||0)>0&&t.checkShowFeedback(t.outcomeIdentifier)}),this.addEventListener("qti-register-interaction",e=>{e.stopPropagation(),this._interactionElements.push(e.detail.interactionElement)}),this.addEventListener("end-attempt",e=>{let{responseIdentifier:t,countAttempt:i}=e.detail;this.validate(),this.updateResponseVariable(t,"true"),this.processResponse(i)}),this.addEventListener("qti-set-outcome-value",e=>{let{outcomeIdentifier:t,value:i}=e.detail;this.updateOutcomeVariable(t,i),e.stopPropagation()}),this.addEventListener("qti-interaction-response",this.handleUpdateResponseVariable)}get variables(){return this._context.variables.map(e=>({identifier:e.identifier,value:e.value,type:e.type,...e.type==="outcome"&&e.identifier==="SCORE"?{externalScored:e.externalScored}:{}}))}set variables(e){if(!Array.isArray(e)||e.some(t=>!("identifier"in t))){console.warn("variables property should be an array of VariableDeclaration");return}this._context={...this._context,variables:this._context.variables.map(t=>{let i=e.find(r=>r.identifier===t.identifier);return i?{...t,...i}:t})},this._context.variables.forEach(t=>{if(t.type==="response"){let i=this._interactionElements.find(r=>r.responseIdentifier===t.identifier);i&&(i.value=t.value)}})}async connectedCallback(){super.connectedCallback(),await this.updateComplete,this._emit("qti-assessment-item-connected",this)}set responses(e){if(e)for(let t of e){this.getResponse(t.responseIdentifier)&&this.updateResponseVariable(t.responseIdentifier,t.response);let r=this._interactionElements.find(a=>a.getAttribute("response-identifier")===t.responseIdentifier);r&&(r.value=t.response)}}render(){return h`<slot></slot>`}showCorrectResponse(e){let i=this._context.variables.filter(r=>"correctResponse"in r&&r.correctResponse).map(r=>({responseIdentifier:r.identifier,response:r.correctResponse}));for(let r of i){let a=this._interactionElements.find(p=>p.getAttribute("response-identifier")===r.responseIdentifier);a&&(a.correctResponse=e?r.response:"")}}processResponse(e=!0){this.validate();let t=this.querySelector("qti-response-processing");return!t||!t.process?!1:(t.process(),this.adaptive==="false"&&this.updateOutcomeVariable("completionStatus",this._getCompletionStatus()),e&&this.updateOutcomeVariable("numAttempts",(+this._context.variables.find(i=>i.identifier==="numAttempts")?.value+1).toString()),this._emit("qti-response-processed"),!0)}resetResponses(){this._context=this._initialContext}getResponse(e){return this.getVariable(e)}getOutcome(e){return this.getVariable(e)}getVariable(e){return this._context.variables.find(t=>t.identifier===e)||null}handleUpdateResponseVariable(e){let{responseIdentifier:t,response:i}=e.detail;this.updateResponseVariable(t,i)}updateResponseVariable(e,t){this._context={...this._context,variables:this._context.variables.map(i=>i.identifier!==e?i:{...i,value:t})},this._emit("qti-interaction-changed",{item:this.identifier,responseIdentifier:e,response:Array.isArray(t)?[...t]:t}),this.adaptive==="false"&&this.updateOutcomeVariable("completionStatus",this._getCompletionStatus())}updateOutcomeVariable(e,t){let i=this.getOutcome(e);if(!i){console.warn(`Can not set qti-outcome-identifier: ${e}, it is not available`);return}this._context={...this._context,variables:this._context.variables.map(r=>r.identifier!==e?r:{...r,value:i.cardinality==="single"?t:[...r.value,t]})},this._feedbackElements.forEach(r=>r.checkShowFeedback(e)),this._emit("qti-outcome-changed",{item:this.identifier,outcomeIdentifier:e,value:this._context.variables.find(r=>r.identifier===e)?.value})}validate(){return this._interactionElements.every(e=>e.validate())?!0:this._interactionElements.some(e=>e.validate())?!1:null}_getCompletionStatus(){let e=this.validate();return e===!0?"completed":e===!1?"incomplete":"not_attempted"}_emit(e,t=null){this.dispatchEvent(new CustomEvent(e,{bubbles:!0,composed:!0,detail:t}))}};o([d({type:String})],M.prototype,"title",2),o([d({type:String})],M.prototype,"identifier",2),o([d({type:String})],M.prototype,"adaptive",2),o([d({type:String})],M.prototype,"timeDependent",2),o([d({type:Boolean})],M.prototype,"disabled",2),o([T("disabled",{waitUntilFirstUpdate:!0})],M.prototype,"_handleDisabledChange",2),o([d({type:Boolean})],M.prototype,"readonly",2),o([T("readonly",{waitUntilFirstUpdate:!0})],M.prototype,"_handleReadonlyChange",2),o([Dt({context:R})],M.prototype,"_context",2),M=o([f("qti-assessment-item")],M);var ce=class extends y{constructor(){super(...arguments);this.identifier="";this.href=""}async connectedCallback(){super.connectedCallback();let e=new Event("qti-assessment-stimulus-ref-connected",{cancelable:!0,bubbles:!0,composed:!0});if(this.dispatchEvent(e)){let r=this.closest("qti-assessment-item").querySelector(`[data-stimulus-idref=${this.identifier}]`);r?await this.updateStimulusRef(r):console.warn(`Stimulus with data-stimulus-idref ${this.identifier} not found`)}}async updateStimulusRef(e){let t=await Ht().load(this.href).then(i=>i.htmlDoc());if(t){let i=t.querySelectorAll("qti-stimulus-body, qti-stylesheet");e.innerHTML="",e.append(...i)}}};o([d({type:String})],ce.prototype,"identifier",2),o([d({type:String})],ce.prototype,"href",2),ce=o([f("qti-assessment-stimulus-ref")],ce);var Xe=class extends y{};Xe=o([f("qti-companion-materials-info")],Xe);var ye=class extends y{render(){return h`<slot @slotchange=${this.handleSlotChange}></slot>`}handleSlotChange(){let s=Array.from(this.firstElementChild?.childNodes??[]).find(e=>e.nodeType===Node.COMMENT_NODE);try{this.operatorFunction=new Function("context","fn","item",s?.textContent??"")}catch(e){console.error("custom-operator contains invalid javascript code",e)}}calculate(){let s={variable:t=>this._context?.variables.find(i=>i.identifier===t)?.value??"",correct:t=>this._context?.variables.find(i=>i.identifier===t)?.correctResponse??""},e={getVariable:t=>this._context?.variables.find(i=>i.identifier===t),updateOutcomeVariable:(t,i)=>{this.dispatchEvent(new CustomEvent("qti-set-outcome-value",{bubbles:!0,composed:!0,detail:{outcomeIdentifier:t,value:i}}))},updateResponseVariable:(t,i)=>{this.dispatchEvent(new CustomEvent("qti-interaction-response",{bubbles:!0,composed:!0,detail:{responseIdentifier:t,response:i}}))}};return this.operatorFunction(this._context,s,e)}};o([D({context:R,subscribe:!0}),C()],ye.prototype,"_context",2),ye=o([f("qti-custom-operator")],ye);var di=()=>new Intl.NumberFormat().format(.1).replace(/\d/g,""),xe=l=>{if(typeof l=="string")return l;let s=di();return s==="."?l.toLocaleString():l.toString().replace(".","").replace(s,".")};function lt(l){return l==null}function Ee(l){return l.replace(/([^:]\/)\/+/g,"$1").replace(/\/\//g,"/").replace("http:/","http://").replace("https:/","https://")}var S=class extends y{connectedCallback(){super.connectedCallback(),this.dispatchEvent(new CustomEvent("qti-register-feedback",{bubbles:!0,composed:!0,detail:this}))}checkShowFeedback(s){let e=this._context.variables.find(i=>i.identifier===s)||null;if(this.outcomeIdentifier!==s||!e)return;let t=!1;Array.isArray(e.value)?t=e.value.includes(this.identifier):t=!lt(this.identifier)&&!lt(e?.value)&&this.identifier===e.value||!1,this.showFeedback(t)}showFeedback(s){this.showStatus=s&&this.showHide==="show"||!s&&this.showHide==="hide"?"on":"off"}};o([d({type:String,attribute:"show-hide"})],S.prototype,"showHide",2),o([d({type:String,attribute:"outcome-identifier"})],S.prototype,"outcomeIdentifier",2),o([d({type:String})],S.prototype,"identifier",2),o([d({type:String,attribute:!1})],S.prototype,"showStatus",2),o([D({context:R,subscribe:!0}),C()],S.prototype,"_context",2);var Ce=class extends S{render(){return h` <slot part="feedback" class="feedback ${this.showStatus}"></slot> `}firstUpdated(s){this.checkShowFeedback(this.outcomeIdentifier)}};Ce.styles=b`
2
2
  :host {
3
3
  display: block;
4
4
  }
@@ -77,7 +77,7 @@ import{a as ne,b as W,c as ae,e as le,f as K,g as $t,h as Ot,i as Be,j as It}fro
77
77
  user-select: none;
78
78
  position: absolute;
79
79
  }
80
- `,Te=o([f("qti-associable-hotspot")],Te);var Pt=(l,s,e)=>{class t extends l{}return t};var N=(l,s,e,t,i="default")=>{class r extends Pt(l,e,s){constructor(){super(...arguments);this.observer=null;this.droppableObsever=null;this.resizeObserver=null;this.draggables=[];this.droppables=[];this.dragContainers=[];this.dragClone=null;this.dragSource=null;this.touchStartPoint=null;this.isDraggable=!1;this.cloneOffset={x:0,y:0};this.isDragging=!1;this.rootNode=null;this.allDropzones=[];this.lastTarget=null;this.dropzoneOriginalParent=null;this.currentDropTarget=null;this.MIN_DRAG_DISTANCE=5;this.DRAG_CLONE_OPACITY=1;this.dataTransfer={data:{},setData(n,c){this.data[n]=c},getData(n){return this.data[n]},effectAllowed:"move"};this.configuration={copyStylesDragClone:!0,dragCanBePlacedBack:!0,dragOnClick:!1};this.minAssociations=1;this.maxAssociations=1;this.draggablesModified=(n,c)=>{for(let m of c)this.draggables.includes(m)&&(this.draggables=this.draggables.filter(g=>g!==m),m.removeAttribute("tabindex"),m.removeEventListener("touchstart",this.handleTouchStart.bind(this)),m.removeEventListener("mousedown",this.handleTouchStart.bind(this)));for(let m of n)this.draggables.includes(m)||(this.draggables.push(m),m.setAttribute("tabindex","0"),m.hasTouchStartListener||(m.addEventListener("touchstart",this.handleTouchStart.bind(this),{passive:!1}),m.addEventListener("mousedown",this.handleTouchStart.bind(this),{passive:!1}),m.hasTouchStartListener=!0));let u=0;this.draggables.forEach(m=>{m.style.viewTransitionName=`drag-${u}-${this.getAttribute("identifier")||crypto.randomUUID()}`,m.setAttribute("qti-draggable","true"),u++})};this.droppablesModified=(n,c)=>{for(let u of c)this.droppables.includes(u)&&(this.droppables=this.droppables.filter(m=>m!==u),this.allDropzones=this.allDropzones.filter(m=>m!==u));for(let u of n)this.droppables.includes(u)||(this.droppables.push(u),this.allDropzones.push(u));for(let u of this.droppables)this.dataset.choicesContainerWidth&&(u.style.width=`${this.dataset.choicesContainerWidth}px`,u.style.boxSizing="border-box")}}handleDraggableContainerChange(n,c){this.isMatchTabular()||(n.length>0||c.length>0)&&this.dragContainersModified(n||[],c||[])}dragContainersModified(n,c){for(let u of c)this.dragContainers.includes(u)&&(this.dragContainers=this.dragContainers.filter(m=>m!==u),this.allDropzones=this.allDropzones.filter(m=>m!==u));for(let u of n)this.dragContainers.includes(u)||(this.dragContainers.push(u),this.allDropzones.push(u))}handleDraggablesChange(n,c){this.isMatchTabular()||(n.length>0||c.length>0)&&this.draggablesModified(n||[],c||[])}handleDroppablesChange(n,c){this.isMatchTabular()||(n.length>0||c.length>0)&&this.droppablesModified(n||[],c||[])}firstUpdated(n){super.firstUpdated(n),this.hasAttribute("disabled")||(document.addEventListener("touchmove",this.handleTouchMove.bind(this),{passive:!1}),document.addEventListener("mousemove",this.handleTouchMove.bind(this),{passive:!1}),document.addEventListener("touchend",this.handleTouchEnd.bind(this),{passive:!1}),document.addEventListener("mouseup",this.handleTouchEnd.bind(this),{passive:!1}),document.addEventListener("touchcancel",this.handleTouchCancel.bind(this),{passive:!1}));let u=Array.from(this.querySelectorAll(s)||[]).concat(Array.from(this.shadowRoot?.querySelectorAll(s)||[])),m=Array.from(this.querySelectorAll(e)||[]).concat(Array.from(this.shadowRoot?.querySelectorAll(e)||[])),g=Array.from(this.querySelectorAll(t)||[]).concat(Array.from(this.shadowRoot?.querySelectorAll(t)||[]));this.dragContainersModified(g,[]),this.droppablesModified(m,[]),this.draggablesModified(u,[]),this.updateMinDimensionsForDropZones(),this.observer=new MutationObserver(()=>this.updateMinDimensionsForDropZones()),this.observer.observe(this,{childList:!0,subtree:!0}),this.resizeObserver=new ResizeObserver(()=>this.updateMinDimensionsForDropZones()),this.querySelectorAll("qti-gap-text").forEach(w=>this.resizeObserver?.observe(w))}async moveDraggableToDroppable(n,c){(()=>{n.style.transform="translate(0, 0)",c.tagName==="SLOT"?n.setAttribute("slot",c.getAttribute("name")):c.appendChild(n),this.checkAllMaxAssociations(),this.saveResponse()})()}activateDroppable(n){this.dragContainers.includes(n)?(this._internals.states.add("--dragzone-active"),n.setAttribute("active","")):(this._internals.states.delete("--dragzone-active"),n.setAttribute("active",""))}deactivateDroppable(n,c=!0){c&&this._internals.states.add("--dragzone-active"),n.removeAttribute("active")}connectedCallback(){super.connectedCallback()}isMatchTabular(){return this.classList.contains("qti-match-tabular")}updateMinDimensionsForDropZones(){let n=this.querySelectorAll(s),c=Array.from(this.querySelectorAll(e)).map(v=>v),u=0,m=0;n.forEach(v=>{let w=v.getBoundingClientRect();u=Math.max(u,w.height),m=Math.max(m,w.width)});let g=this.querySelector(t)||this.shadowRoot?.querySelector(t);g&&(g.style.minHeight=`${u}px`,g.style.minWidth=`${m}px`);for(let v of c)v.style.minHeight=`${u}px`,v.style.minWidth=`${m}px`}activateDroppables(n){this.dragContainers.forEach(u=>{u.setAttribute("enabled",""),u.hasAttribute("disabled")&&(u.contains(n)||u.shadowRoot&&u.shadowRoot.contains(n))&&u.removeAttribute("disabled")}),this.droppables.forEach(u=>{u.setAttribute("enabled",""),u.hasAttribute("disabled")&&(u.contains(n)||u.shadowRoot&&u.shadowRoot.contains(n))&&u.removeAttribute("disabled")})}activateDragLocation(){this._internals.states.add("--dragzone-enabled")}deactivateDragLocation(){this._internals.states.delete("--dragzone-enabled")}deactivateDroppables(){this.dragContainers.forEach(c=>{c.removeAttribute("enabled"),c.removeAttribute("active")}),this.droppables.forEach(c=>{c.removeAttribute("enabled"),c.removeAttribute("active")})}disconnectedCallback(){super.disconnectedCallback(),this.observer&&(this.observer.disconnect(),this.observer=null),this.droppableObsever&&(this.droppableObsever.disconnect(),this.droppableObsever=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),document.removeEventListener("touchmove",this.handleTouchMove),document.removeEventListener("mousemove",this.handleTouchMove),document.removeEventListener("touchend",this.handleTouchEnd),document.removeEventListener("mouseup",this.handleTouchEnd),document.removeEventListener("touchcancel",this.handleTouchCancel)}handleTouchMove(n){if(this.isDraggable&&this.dragClone){let{x:c,y:u}=this.getEventCoordinates(n),m={clientX:c,clientY:u};this.calculateDragDistance(m)>=this.MIN_DRAG_DISTANCE&&(this.isDragging=!0,this.updateDragClonePosition(m));let g=this.findClosestDropzone();this.currentDropTarget=g,g!==this.lastTarget&&(this.lastTarget&&(this.deactivateDroppable(this.lastTarget),this.dispatchCustomEvent(this.lastTarget,"dragleave")),g&&(this.activateDroppable(g),this.dispatchCustomEvent(g,"dragenter")),this.lastTarget=g),this.currentDropTarget&&this.dispatchCustomEvent(this.currentDropTarget,"dragover"),n.preventDefault()}}handleTouchEnd(n){if(this.isDragging){if(this.currentDropTarget){let c=this.dragClone;this.moveDraggableToDroppable(c,this.currentDropTarget)}this.resetDragState()}this._internals.states.delete("--dragzone-active"),this.checkAllMaxAssociations(),this._internals.states.delete("--dragzone-enabled"),this._internals.states.delete("--dragzone-active"),this.deactivateDragLocation(),this.deactivateDroppables(),this.dragClone.removeAttribute("dragging"),n.preventDefault()}handleTouchCancel(n){this.resetDragState()}validate(){if(!this.shadowRoot)return!1;let n=this.getValidAssociations(),c=!0,u="";this.maxAssociations>0&&n>this.maxAssociations?(c=!1,u=this.dataset.maxSelectionsMessage||`You've selected too many associations. Maximum allowed is ${this.maxAssociations}.`):this.minAssociations>0&&n<this.minAssociations&&(c=!1,u=this.dataset.minSelectionsMessage||`You haven't selected enough associations. Minimum required is ${this.minAssociations}.`);let m=this.lastElementChild;return this._internals.setValidity(c?{}:{customError:!0},u,m),this.reportValidity(),c}reportValidity(){let n=this.shadowRoot.querySelector("#validationMessage");return n&&(this._internals.validity.valid?(n.textContent="",n.style.display="none"):(n.textContent=this._internals.validationMessage,n.style.display="block")),this._internals.validity.valid}checkMaxAssociations(n){let c=this.getMatchMaxValue(n),u=n.querySelectorAll('[qti-draggable="true"]').length;return c===0||u>=c}resetDragState(){if(this.dragClone)if(!(this.currentDropTarget!==null)||this.dragContainers.includes(this.currentDropTarget))this.dragSource.style.opacity="1.0",this.dragSource.style.display="block",this.dragSource.style.pointerEvents="auto",this.dragClone.remove();else{let u=window.getComputedStyle(this.dragSource);for(let m=0;m<u.length;m++){let g=u[m];this.dragClone.style.setProperty(g,u.getPropertyValue(g))}this.dragClone.style.opacity="1.0",this.dragClone.style.display="block",this.dragClone.style.pointerEvents="auto"}this.isDragging=!1,this.isDraggable=!1,this.dragSource=null,this.dragClone=null,this.touchStartPoint=null,this.currentDropTarget=null,this.lastTarget=null}checkAllMaxAssociations(){this.droppables.forEach(n=>{this.checkMaxAssociations(n)?this.disableDroppable(n):this.enableDroppable(n)})}getMatchMaxValue(n){let c=n.getAttribute("match-max");return c?parseInt(c,10):1}disableDroppable(n){n.setAttribute("disabled","")}enableDroppable(n){n.removeAttribute("disabled")}get value(){return this.collectResponseData()}set value(n){if(!this.isMatchTabular())if(Array.isArray(n)){n?.forEach(u=>this.placeResponse(u));let c=new FormData;n.forEach(u=>{c.append(this.responseIdentifier,u)}),this._internals.setFormValue(c)}else this._internals.setFormValue(n||"")}placeResponse(n){let[c,...u]=n.split(" ").reverse(),m=this.findDroppableById(c);u.forEach(g=>this.placeDraggableInDroppable(g,m))}findDroppableById(n){return this.droppables.find(c=>c.getAttribute("identifier")===n)}async placeDraggableInDroppable(n,c){let u=this.querySelector(`[identifier=${n}]`);if(!c||!u){console.error(`Cannot find draggable or droppable with the given identifier: ${n}`);return}let m=()=>{u.style.transform="translate(0, 0)",c.appendChild(u),this.checkAllMaxAssociations()};document.startViewTransition?await document.startViewTransition(m).finished:m()}getValidAssociations(){return this.droppables.filter(n=>n.childElementCount>0).length}saveResponse(){this.validate();let n=this.collectResponseData();this.dispatchEvent(new CustomEvent("qti-interaction-response",{bubbles:!0,composed:!0,detail:{responseIdentifier:this.responseIdentifier,response:n}}))}collectResponseData(){return this.droppables.map(c=>{let u=c.querySelectorAll('[qti-draggable="true"]'),m=Array.from(u).map(v=>v.getAttribute("identifier")),g=c.getAttribute("identifier");return m.map(v=>`${v} ${g}`)}).flat()}reset(n=!0){n&&this.saveResponse()}updateDragClonePosition(n){if(!this.isDragging||!this.dragClone)return;let c=n.clientX-this.cloneOffset.x,u=n.clientY-this.cloneOffset.y,{newLeft:m,newTop:g}=this.applyBoundaries(c,u,this.dragClone);this.dragClone.style.left=`${m}px`,this.dragClone.style.top=`${g}px`}getEventCoordinates(n,c=!1){let u=n.touches?n.touches[0]:n;return{x:c?u.pageX:u.clientX,y:c?u.pageY:u.clientY}}calculateDragDistance(n){let c=Math.abs(n.clientX-this.touchStartPoint.x),u=Math.abs(n.clientY-this.touchStartPoint.y);return c+u}applyBoundaries(n,c,u){let m=new DOMRect(0,0,window.innerWidth,window.innerHeight);this.rootNode instanceof ShadowRoot?m=this.rootNode.host.getBoundingClientRect():this.rootNode instanceof Document&&(m=document.documentElement.getBoundingClientRect());let g=u.getBoundingClientRect(),v=g.width,w=g.height,E=Math.max(m.left,Math.min(n,m.right-v)),z=Math.max(m.top,Math.min(c,m.bottom-w));return{newLeft:E,newTop:z}}findClosestDropzone(){let n=this.allDropzones.filter(g=>!g.hasAttribute("disabled"));if(!this.dragClone||n.length===0)return null;let c=this.dragClone.getBoundingClientRect(),u=null,m=0;for(let g of n){let v=g.getBoundingClientRect(),w=this.calculateOverlapArea(c,v);w>m&&(m=w,u=g)}if(!u){let g=200;for(let v of n){let w=v.getBoundingClientRect(),E=Math.sqrt(Math.pow(c.left-w.left,2)+Math.pow(c.top-w.top,2));E<g&&(g=E,u=v)}}return u}calculateOverlapArea(n,c){let u=Math.max(0,Math.min(n.right,c.right)-Math.max(n.left,c.left)),m=Math.max(0,Math.min(n.bottom,c.bottom)-Math.max(n.top,c.top));return u*m}dispatchCustomEvent(n,c,u=!0){if(!n)return;let m=new CustomEvent(c,{bubbles:u,cancelable:!0});m.dataTransfer=this.dataTransfer,n.dispatchEvent(m)}appendClone(){let n=this.findParentInteractionElement(this.dragSource);i=="default"?n?n.appendChild(this.dragClone):this.rootNode instanceof ShadowRoot?this.rootNode.host.appendChild(this.dragClone):this.rootNode instanceof Document&&document.body.appendChild(this.dragClone):i=="interaction"?n?n.appendChild(this.dragClone):console.error("No interaction found to append the drag clone"):i=="host"?this.rootNode instanceof ShadowRoot?this.rootNode.host.appendChild(this.dragClone):console.error("No host found to append the drag clone"):i=="body"&&document.body.appendChild(this.dragClone)}handleTouchStart(n){let{x:c,y:u}=this.getEventCoordinates(n);this.dropzoneOriginalParent=n.currentTarget.parentElement,this.touchStartPoint={x:c,y:u},this.dragSource=n.currentTarget,this.isDraggable=!0,this.rootNode=this.dragSource.getRootNode(),this._internals.states.add("--dragzone-enabled"),this._internals.states.add("--dragzone-active"),this.dragSource.setAttribute("dragging",""),this.activateDragLocation(),this.activateDroppables(this.dragSource);let m=this.findDraggableInDraggableContainer(this.dragSource.getAttribute("identifier")),g=this.dragSource.parentElement;if(this.droppables.includes(g)){this.enableDroppable(g),this.dragClone=this.dragSource,this.dragSource=this.findDraggableInDraggableContainer(this.dragSource.getAttribute("identifier"));let v=this.dragClone.getBoundingClientRect();this.appendClone(),v&&this.setDragCloneStyles(v)}else{let v=m.getBoundingClientRect();this.cloneOffset.x=c-v.left,this.cloneOffset.y=u-v.top,this.dragClone=m.cloneNode(!0);let w=window.getComputedStyle(this.dragSource);for(let A=0;A<w.length;A++){let ze=w[A];this.dragClone.style.setProperty(ze,w.getPropertyValue(ze))}v&&this.setDragCloneStyles(v),this.appendClone();let E=this.getMatchMaxValue(this.dragSource),z=this.draggables.filter(A=>A.getAttribute("identifier")===this.dragSource.getAttribute("identifier"));E!==0&&z.length>=E?(m.style.opacity="0.0",m.style.pointerEvents="none"):m.style.opacity="1.0",n.preventDefault()}}findParentInteractionElement(n){let c=n.parentElement;for(;c&&!c.tagName?.toLowerCase().endsWith("-interaction");)c=c.parentElement;return c}findDraggableInDraggableContainer(n){let c=this.dragContainers.flat();for(let u of c){if(u.getAttribute("identifier")===n)return u;let m;u instanceof HTMLSlotElement?m=Array.from(u?.assignedElements()||[]):m=Array.from(u.querySelectorAll(s));let g=m.find(v=>v.getAttribute("identifier")===n);if(g)return g}}setDragCloneStyles(n){this.dragClone.style.position="fixed",this.dragClone.style.top=`${n.top}px`,this.dragClone.style.left=`${n.left}px`,this.dragClone.style.width=`${n.width}px`,this.dragClone.style.height=`${n.height}px`,this.dragClone.style.setProperty("box-sizing","border-box","important"),this.dragClone.style.zIndex="9999",this.dragClone.style.pointerEvents="none",this.dragClone.style.opacity=this.DRAG_CLONE_OPACITY.toString(),this.dragClone.style.display="block"}}return o([d({attribute:!1,type:Object})],r.prototype,"configuration",2),o([d({type:Number,reflect:!0,attribute:"min-associations"})],r.prototype,"minAssociations",2),o([d({type:Number,reflect:!0,attribute:"max-associations"})],r.prototype,"maxAssociations",2),o([Ue(t)],r.prototype,"handleDraggableContainerChange",1),o([Ue(s)],r.prototype,"handleDraggablesChange",1),o([Ue(e)],r.prototype,"handleDroppablesChange",1),r};var Ft=b`
80
+ `,Te=o([f("qti-associable-hotspot")],Te);var Pt=(l,s,e)=>{class t extends l{}return t};var N=(l,s,e,t,i="default")=>{class r extends Pt(l,e,s){constructor(){super(...arguments);this.observer=null;this.droppableObsever=null;this.resizeObserver=null;this.draggables=[];this.droppables=[];this.dragContainers=[];this.dragClone=null;this.dragSource=null;this.touchStartPoint=null;this.isDraggable=!1;this.cloneOffset={x:0,y:0};this.isDragging=!1;this.rootNode=null;this.allDropzones=[];this.lastTarget=null;this.dropzoneOriginalParent=null;this.currentDropTarget=null;this.MIN_DRAG_DISTANCE=5;this.DRAG_CLONE_OPACITY=1;this.dataTransfer={data:{},setData(n,c){this.data[n]=c},getData(n){return this.data[n]},effectAllowed:"move"};this.configuration={copyStylesDragClone:!0,dragCanBePlacedBack:!0,dragOnClick:!1};this.minAssociations=1;this.maxAssociations=1;this.draggablesModified=(n,c)=>{for(let m of c)this.draggables.includes(m)&&(this.draggables=this.draggables.filter(g=>g!==m),m.removeAttribute("tabindex"),m.removeEventListener("touchstart",this.handleTouchStart.bind(this)),m.removeEventListener("mousedown",this.handleTouchStart.bind(this)));for(let m of n)this.draggables.includes(m)||(this.draggables.push(m),m.setAttribute("tabindex","0"),m.hasTouchStartListener||(m.addEventListener("touchstart",this.handleTouchStart.bind(this),{passive:!1}),m.addEventListener("mousedown",this.handleTouchStart.bind(this),{passive:!1}),m.hasTouchStartListener=!0));let u=0;this.draggables.forEach(m=>{m.style.viewTransitionName=`drag-${u}-${this.getAttribute("identifier")||crypto.randomUUID()}`,m.setAttribute("qti-draggable","true"),u++})};this.droppablesModified=(n,c)=>{for(let u of c)this.droppables.includes(u)&&(this.droppables=this.droppables.filter(m=>m!==u),this.allDropzones=this.allDropzones.filter(m=>m!==u));for(let u of n)this.droppables.includes(u)||(this.droppables.push(u),this.allDropzones.push(u));for(let u of this.droppables)this.dataset.choicesContainerWidth&&(u.style.width=`${this.dataset.choicesContainerWidth}px`,u.style.boxSizing="border-box")}}handleDraggableContainerChange(n,c){this.isMatchTabular()||(n.length>0||c.length>0)&&this.dragContainersModified(n||[],c||[])}dragContainersModified(n,c){for(let u of c)this.dragContainers.includes(u)&&(this.dragContainers=this.dragContainers.filter(m=>m!==u),this.allDropzones=this.allDropzones.filter(m=>m!==u));for(let u of n)this.dragContainers.includes(u)||(this.dragContainers.push(u),this.allDropzones.push(u))}handleDraggablesChange(n,c){this.isMatchTabular()||(n.length>0||c.length>0)&&this.draggablesModified(n||[],c||[])}handleDroppablesChange(n,c){this.isMatchTabular()||(n.length>0||c.length>0)&&this.droppablesModified(n||[],c||[])}firstUpdated(n){super.firstUpdated(n),this.hasAttribute("disabled")||(document.addEventListener("touchmove",this.handleTouchMove.bind(this),{passive:!1}),document.addEventListener("mousemove",this.handleTouchMove.bind(this),{passive:!1}),document.addEventListener("touchend",this.handleTouchEnd.bind(this),{passive:!1}),document.addEventListener("mouseup",this.handleTouchEnd.bind(this),{passive:!1}),document.addEventListener("touchcancel",this.handleTouchCancel.bind(this),{passive:!1}));let u=Array.from(this.querySelectorAll(s)||[]).concat(Array.from(this.shadowRoot?.querySelectorAll(s)||[])),m=Array.from(this.querySelectorAll(e)||[]).concat(Array.from(this.shadowRoot?.querySelectorAll(e)||[])),g=Array.from(this.querySelectorAll(t)||[]).concat(Array.from(this.shadowRoot?.querySelectorAll(t)||[]));this.dragContainersModified(g,[]),this.droppablesModified(m,[]),this.draggablesModified(u,[]),this.updateMinDimensionsForDropZones(),this.observer=new MutationObserver(()=>this.updateMinDimensionsForDropZones()),this.observer.observe(this,{childList:!0,subtree:!0}),this.resizeObserver=new ResizeObserver(()=>this.updateMinDimensionsForDropZones()),this.querySelectorAll("qti-gap-text").forEach(w=>this.resizeObserver?.observe(w))}async moveDraggableToDroppable(n,c){(()=>{n.style.transform="translate(0, 0)",c.tagName==="SLOT"?n.setAttribute("slot",c.getAttribute("name")):c.appendChild(n),this.checkAllMaxAssociations(),this.saveResponse()})()}activateDroppable(n){this.dragContainers.includes(n)?(this._internals.states.add("--dragzone-active"),n.setAttribute("active","")):(this._internals.states.delete("--dragzone-active"),n.setAttribute("active",""))}deactivateDroppable(n,c=!0){c&&this._internals.states.add("--dragzone-active"),n.removeAttribute("active")}connectedCallback(){super.connectedCallback()}isMatchTabular(){return this.classList.contains("qti-match-tabular")}updateMinDimensionsForDropZones(){let n=this.querySelectorAll(s),c=Array.from(this.querySelectorAll(e)).map(v=>v),u=0,m=0;n.forEach(v=>{let w=v.getBoundingClientRect();u=Math.max(u,w.height),m=Math.max(m,w.width)});let g=this.querySelector(t)||this.shadowRoot?.querySelector(t);g&&(g.style.minHeight=`${u}px`,g.style.minWidth=`${m}px`);for(let v of c)v.style.minHeight=`${u}px`,v.style.minWidth=`${m}px`}activateDroppables(n){this.dragContainers.forEach(u=>{u.setAttribute("enabled",""),u.hasAttribute("disabled")&&(u.contains(n)||u.shadowRoot&&u.shadowRoot.contains(n))&&u.removeAttribute("disabled")}),this.droppables.forEach(u=>{u.setAttribute("enabled",""),u.hasAttribute("disabled")&&(u.contains(n)||u.shadowRoot&&u.shadowRoot.contains(n))&&u.removeAttribute("disabled")})}activateDragLocation(){this._internals.states.add("--dragzone-enabled")}deactivateDragLocation(){this._internals.states.delete("--dragzone-enabled")}deactivateDroppables(){this.dragContainers.forEach(c=>{c.removeAttribute("enabled"),c.removeAttribute("active")}),this.droppables.forEach(c=>{c.removeAttribute("enabled"),c.removeAttribute("active")})}disconnectedCallback(){super.disconnectedCallback(),this.observer&&(this.observer.disconnect(),this.observer=null),this.droppableObsever&&(this.droppableObsever.disconnect(),this.droppableObsever=null),this.resizeObserver&&(this.resizeObserver.disconnect(),this.resizeObserver=null),document.removeEventListener("touchmove",this.handleTouchMove),document.removeEventListener("mousemove",this.handleTouchMove),document.removeEventListener("touchend",this.handleTouchEnd),document.removeEventListener("mouseup",this.handleTouchEnd),document.removeEventListener("touchcancel",this.handleTouchCancel)}handleTouchMove(n){if(this.isDraggable&&this.dragClone){let{x:c,y:u}=this.getEventCoordinates(n),m={clientX:c,clientY:u};this.calculateDragDistance(m)>=this.MIN_DRAG_DISTANCE&&(this.isDragging=!0,this.updateDragClonePosition(m));let g=this.findClosestDropzone();this.currentDropTarget=g,g!==this.lastTarget&&(this.lastTarget&&(this.deactivateDroppable(this.lastTarget),this.dispatchCustomEvent(this.lastTarget,"dragleave")),g&&(this.activateDroppable(g),this.dispatchCustomEvent(g,"dragenter")),this.lastTarget=g),this.currentDropTarget&&this.dispatchCustomEvent(this.currentDropTarget,"dragover"),n.preventDefault()}}handleTouchEnd(n){if(this.isDragging){if(this.currentDropTarget){let c=this.dragClone;this.moveDraggableToDroppable(c,this.currentDropTarget)}this.resetDragState()}this._internals.states.delete("--dragzone-active"),this.checkAllMaxAssociations(),this._internals.states.delete("--dragzone-enabled"),this._internals.states.delete("--dragzone-active"),this.deactivateDragLocation(),this.deactivateDroppables(),this.dragClone?.removeAttribute("dragging"),n.preventDefault()}handleTouchCancel(n){this.resetDragState()}validate(){if(!this.shadowRoot)return!1;let n=this.getValidAssociations(),c=!0,u="";this.maxAssociations>0&&n>this.maxAssociations?(c=!1,u=this.dataset.maxSelectionsMessage||`You've selected too many associations. Maximum allowed is ${this.maxAssociations}.`):this.minAssociations>0&&n<this.minAssociations&&(c=!1,u=this.dataset.minSelectionsMessage||`You haven't selected enough associations. Minimum required is ${this.minAssociations}.`);let m=this.lastElementChild;return this._internals.setValidity(c?{}:{customError:!0},u,m),this.reportValidity(),c}reportValidity(){let n=this.shadowRoot.querySelector("#validationMessage");return n&&(this._internals.validity.valid?(n.textContent="",n.style.display="none"):(n.textContent=this._internals.validationMessage,n.style.display="block")),this._internals.validity.valid}checkMaxAssociations(n){let c=this.getMatchMaxValue(n),u=n.querySelectorAll('[qti-draggable="true"]').length;return c===0||u>=c}resetDragState(){if(this.dragClone)if(!(this.currentDropTarget!==null)||this.dragContainers.includes(this.currentDropTarget))this.dragSource.style.opacity="1.0",this.dragSource.style.display="block",this.dragSource.style.pointerEvents="auto",this.dragClone.remove();else{let u=window.getComputedStyle(this.dragSource);for(let m=0;m<u.length;m++){let g=u[m];this.dragClone.style.setProperty(g,u.getPropertyValue(g))}this.dragClone.style.opacity="1.0",this.dragClone.style.display="block",this.dragClone.style.pointerEvents="auto"}this.isDragging=!1,this.isDraggable=!1,this.dragSource=null,this.dragClone=null,this.touchStartPoint=null,this.currentDropTarget=null,this.lastTarget=null}checkAllMaxAssociations(){this.droppables.forEach(n=>{this.checkMaxAssociations(n)?this.disableDroppable(n):this.enableDroppable(n)})}getMatchMaxValue(n){let c=n.getAttribute("match-max");return c?parseInt(c,10):1}disableDroppable(n){n.setAttribute("disabled","")}enableDroppable(n){n.removeAttribute("disabled")}get value(){return this.collectResponseData()}set value(n){if(!this.isMatchTabular())if(Array.isArray(n)){n?.forEach(u=>this.placeResponse(u));let c=new FormData;n.forEach(u=>{c.append(this.responseIdentifier,u)}),this._internals.setFormValue(c)}else this._internals.setFormValue(n||"")}placeResponse(n){let[c,...u]=n.split(" ").reverse(),m=this.findDroppableById(c);u.forEach(g=>this.placeDraggableInDroppable(g,m))}findDroppableById(n){return this.droppables.find(c=>c.getAttribute("identifier")===n)}async placeDraggableInDroppable(n,c){let u=this.querySelector(`[identifier=${n}]`);if(!c||!u){console.error(`Cannot find draggable or droppable with the given identifier: ${n}`);return}let m=()=>{u.style.transform="translate(0, 0)",c.appendChild(u),this.checkAllMaxAssociations()};document.startViewTransition?await document.startViewTransition(m).finished:m()}getValidAssociations(){return this.droppables.filter(n=>n.childElementCount>0).length}saveResponse(){this.validate();let n=this.collectResponseData();this.dispatchEvent(new CustomEvent("qti-interaction-response",{bubbles:!0,composed:!0,detail:{responseIdentifier:this.responseIdentifier,response:n}}))}collectResponseData(){return this.droppables.map(c=>{let u=c.querySelectorAll('[qti-draggable="true"]'),m=Array.from(u).map(v=>v.getAttribute("identifier")),g=c.getAttribute("identifier");return m.map(v=>`${v} ${g}`)}).flat()}reset(n=!0){n&&this.saveResponse()}updateDragClonePosition(n){if(!this.isDragging||!this.dragClone)return;let c=n.clientX-this.cloneOffset.x,u=n.clientY-this.cloneOffset.y,{newLeft:m,newTop:g}=this.applyBoundaries(c,u,this.dragClone);this.dragClone.style.left=`${m}px`,this.dragClone.style.top=`${g}px`}getEventCoordinates(n,c=!1){let u=n.touches?n.touches[0]:n;return{x:c?u.pageX:u.clientX,y:c?u.pageY:u.clientY}}calculateDragDistance(n){let c=Math.abs(n.clientX-this.touchStartPoint.x),u=Math.abs(n.clientY-this.touchStartPoint.y);return c+u}applyBoundaries(n,c,u){let m=new DOMRect(0,0,window.innerWidth,window.innerHeight);this.rootNode instanceof ShadowRoot?m=this.rootNode.host.getBoundingClientRect():this.rootNode instanceof Document&&(m=document.documentElement.getBoundingClientRect());let g=u.getBoundingClientRect(),v=g.width,w=g.height,E=Math.max(m.left,Math.min(n,m.right-v)),z=Math.max(m.top,Math.min(c,m.bottom-w));return{newLeft:E,newTop:z}}findClosestDropzone(){let n=this.allDropzones.filter(g=>!g.hasAttribute("disabled"));if(!this.dragClone||n.length===0)return null;let c=this.dragClone.getBoundingClientRect(),u=null,m=0;for(let g of n){let v=g.getBoundingClientRect(),w=this.calculateOverlapArea(c,v);w>m&&(m=w,u=g)}if(!u){let g=200;for(let v of n){let w=v.getBoundingClientRect(),E=Math.sqrt(Math.pow(c.left-w.left,2)+Math.pow(c.top-w.top,2));E<g&&(g=E,u=v)}}return u}calculateOverlapArea(n,c){let u=Math.max(0,Math.min(n.right,c.right)-Math.max(n.left,c.left)),m=Math.max(0,Math.min(n.bottom,c.bottom)-Math.max(n.top,c.top));return u*m}dispatchCustomEvent(n,c,u=!0){if(!n)return;let m=new CustomEvent(c,{bubbles:u,cancelable:!0});m.dataTransfer=this.dataTransfer,n.dispatchEvent(m)}appendClone(){let n=this.findParentInteractionElement(this.dragSource);i=="default"?n?n.appendChild(this.dragClone):this.rootNode instanceof ShadowRoot?this.rootNode.host.appendChild(this.dragClone):this.rootNode instanceof Document&&document.body.appendChild(this.dragClone):i=="interaction"?n?n.appendChild(this.dragClone):console.error("No interaction found to append the drag clone"):i=="host"?this.rootNode instanceof ShadowRoot?this.rootNode.host.appendChild(this.dragClone):console.error("No host found to append the drag clone"):i=="body"&&document.body.appendChild(this.dragClone)}handleTouchStart(n){let{x:c,y:u}=this.getEventCoordinates(n);this.dropzoneOriginalParent=n.currentTarget.parentElement,this.touchStartPoint={x:c,y:u},this.dragSource=n.currentTarget,this.isDraggable=!0,this.rootNode=this.dragSource.getRootNode(),this._internals.states.add("--dragzone-enabled"),this._internals.states.add("--dragzone-active"),this.dragSource.setAttribute("dragging",""),this.activateDragLocation(),this.activateDroppables(this.dragSource);let m=this.findDraggableInDraggableContainer(this.dragSource.getAttribute("identifier")),g=this.dragSource.parentElement;if(this.droppables.includes(g)){this.enableDroppable(g),this.dragClone=this.dragSource,this.dragSource=this.findDraggableInDraggableContainer(this.dragSource.getAttribute("identifier"));let v=this.dragClone.getBoundingClientRect();this.appendClone(),v&&this.setDragCloneStyles(v)}else{let v=m.getBoundingClientRect();this.cloneOffset.x=c-v.left,this.cloneOffset.y=u-v.top,this.dragClone=m.cloneNode(!0);let w=window.getComputedStyle(this.dragSource);for(let A=0;A<w.length;A++){let ze=w[A];this.dragClone.style.setProperty(ze,w.getPropertyValue(ze))}v&&this.setDragCloneStyles(v),this.appendClone();let E=this.getMatchMaxValue(this.dragSource),z=this.draggables.filter(A=>A.getAttribute("identifier")===this.dragSource.getAttribute("identifier"));E!==0&&z.length>=E?(m.style.opacity="0.0",m.style.pointerEvents="none"):m.style.opacity="1.0",n.preventDefault()}}findParentInteractionElement(n){let c=n.parentElement;for(;c&&!c.tagName?.toLowerCase().endsWith("-interaction");)c=c.parentElement;return c}findDraggableInDraggableContainer(n){let c=this.dragContainers.flat();for(let u of c){if(u.getAttribute("identifier")===n)return u;let m;u instanceof HTMLSlotElement?m=Array.from(u?.assignedElements()||[]):m=Array.from(u.querySelectorAll(s));let g=m.find(v=>v.getAttribute("identifier")===n);if(g)return g}}setDragCloneStyles(n){this.dragClone.style.position="fixed",this.dragClone.style.top=`${n.top}px`,this.dragClone.style.left=`${n.left}px`,this.dragClone.style.width=`${n.width}px`,this.dragClone.style.height=`${n.height}px`,this.dragClone.style.setProperty("box-sizing","border-box","important"),this.dragClone.style.zIndex="9999",this.dragClone.style.pointerEvents="none",this.dragClone.style.opacity=this.DRAG_CLONE_OPACITY.toString(),this.dragClone.style.display="block"}}return o([d({attribute:!1,type:Object})],r.prototype,"configuration",2),o([d({type:Number,reflect:!0,attribute:"min-associations"})],r.prototype,"minAssociations",2),o([d({type:Number,reflect:!0,attribute:"max-associations"})],r.prototype,"maxAssociations",2),o([Ue(t)],r.prototype,"handleDraggableContainerChange",1),o([Ue(s)],r.prototype,"handleDraggablesChange",1),o([Ue(e)],r.prototype,"handleDroppablesChange",1),r};var Ft=b`
81
81
  :host {
82
82
  display: block; /* necessary to calculate scaling position */
83
83
  }
@@ -0,0 +1 @@
1
+ import{b as s,c as n}from"./chunk-5GCSZ3CH.js";import{i}from"./chunk-LZZB4VGC.js";import{a as r}from"./chunk-IAP2CEE7.js";var e=class extends i{constructor(){super();this.disabled=!1;this.readonly=!1;this._internals=this.attachInternals()}reportValidity(){return this._internals.reportValidity()}reset(){this.value=""}get correctResponse(){return this._correctResponse}set correctResponse(t){this._correctResponse=t}connectedCallback(){super.connectedCallback(),this.dispatchEvent(new CustomEvent("qti-register-interaction",{bubbles:!0,composed:!0,cancelable:!1,detail:{interactionElement:this,responseIdentifier:this.responseIdentifier}}))}saveResponse(t){this.dispatchEvent(new CustomEvent("qti-interaction-response",{bubbles:!0,composed:!0,cancelable:!1,detail:{responseIdentifier:this.responseIdentifier,response:Array.isArray(t)?[...t]:t}}))}};e.formAssociated=!0,r([s({type:String,attribute:"response-identifier"})],e.prototype,"responseIdentifier",2),r([s({reflect:!0,type:Boolean})],e.prototype,"disabled",2),r([s({reflect:!0,type:Boolean})],e.prototype,"readonly",2),r([n()],e.prototype,"_correctResponse",2);export{e as a};
@@ -1 +1 @@
1
- import{a}from"../chunks/chunk-R33OODNX.js";import"../chunks/chunk-5GCSZ3CH.js";import"../chunks/chunk-LZZB4VGC.js";import"../chunks/chunk-IAP2CEE7.js";export{a as Interaction};
1
+ import{a}from"../chunks/chunk-UJP4TGD3.js";import"../chunks/chunk-5GCSZ3CH.js";import"../chunks/chunk-LZZB4VGC.js";import"../chunks/chunk-IAP2CEE7.js";export{a as Interaction};