@citolab/qti-components 3.0.51 → 3.0.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.css +3 -0
- package/index.js +17 -16
- package/index.umd.css +3 -0
- package/index.umd.js +7 -6
- package/lab/qti-test/qti-test.d.ts +1 -0
- package/package.json +2 -2
package/index.css
CHANGED
|
@@ -3692,6 +3692,7 @@ qti-test qti-test-nav {
|
|
|
3692
3692
|
qti-test qti-test-nav qti-test-check,
|
|
3693
3693
|
qti-test qti-test-nav qti-test-score,
|
|
3694
3694
|
qti-test qti-test-nav qti-test-prev,
|
|
3695
|
+
qti-test qti-test-nav qti-test-show-correct,
|
|
3695
3696
|
qti-test qti-test-nav qti-test-next {
|
|
3696
3697
|
display: flex;
|
|
3697
3698
|
align-items: center;
|
|
@@ -3712,6 +3713,7 @@ qti-test qti-test-nav qti-test-next {
|
|
|
3712
3713
|
qti-test qti-test-nav qti-test-check:hover,
|
|
3713
3714
|
qti-test qti-test-nav qti-test-score:hover,
|
|
3714
3715
|
qti-test qti-test-nav qti-test-prev:hover,
|
|
3716
|
+
qti-test qti-test-nav qti-test-show-correct:hover,
|
|
3715
3717
|
qti-test qti-test-nav qti-test-next:hover {
|
|
3716
3718
|
background: #dadada;
|
|
3717
3719
|
transition: all 0.3s ease;
|
|
@@ -3719,6 +3721,7 @@ qti-test qti-test-nav qti-test-next:hover {
|
|
|
3719
3721
|
qti-test qti-test-nav qti-test-check:active,
|
|
3720
3722
|
qti-test qti-test-nav qti-test-score:active,
|
|
3721
3723
|
qti-test qti-test-nav qti-test-prev:active,
|
|
3724
|
+
qti-test qti-test-nav qti-test-show-correct:active,
|
|
3722
3725
|
qti-test qti-test-nav qti-test-next:active {
|
|
3723
3726
|
background: #aeaeae;
|
|
3724
3727
|
}
|
package/index.js
CHANGED
|
@@ -4,7 +4,7 @@ import{LitElement as e,html as t,css as s,render as i}from"lit";import{customEle
|
|
|
4
4
|
:host {
|
|
5
5
|
display: block;
|
|
6
6
|
}
|
|
7
|
-
`,R=x([n("qti-item-body")],R);class k extends e{render(){return t` <slot></slot> `}connectedCallback(){this.parentElement.tagName.endsWith("INTERACTION")&&this.setAttribute("slot","prompt")}}function A(e,t){const s=Object.assign({waitUntilFirstUpdate:!1},t);return(t,i)=>{const{update:n}=t;if(e in t){const r=e;t.update=function(e){if(e.has(r)){const t=e.get(r),n=this[r];t!==n&&(s.waitUntilFirstUpdate&&!this.hasUpdated||this[i](t,n))}n.call(this,e)}}}}customElements.define("qti-prompt",k);const
|
|
7
|
+
`,R=x([n("qti-item-body")],R);class k extends e{render(){return t` <slot></slot> `}connectedCallback(){this.parentElement.tagName.endsWith("INTERACTION")&&this.setAttribute("slot","prompt")}}function A(e,t){const s=Object.assign({waitUntilFirstUpdate:!1},t);return(t,i)=>{const{update:n}=t;if(e in t){const r=e;t.update=function(e){if(e.has(r)){const t=e.get(r),n=this[r];t!==n&&(s.waitUntilFirstUpdate&&!this.hasUpdated||this[i](t,n))}n.call(this,e)}}}}customElements.define("qti-prompt",k);const w=32;let I=class extends _{constructor(){super(...arguments),this.tabindex=0,this.disabled=!1,this.readonly=!1,this.checked=!1}handleDisabledChange(e,t){t?(this.tabindex=void 0,this.blur()):this.tabIndex=0}connectedCallback(){super.connectedCallback(),this.addEventListener("keyup",this._onKeyUp),this.addEventListener("click",this._onClick),this.emit(f.ON_REGISTER_CHOICE)}disconnectedCallback(){this.removeEventListener("keyup",this._onKeyUp),this.removeEventListener("click",this._onClick),this.emit(f.ON_LOOSE_CHOICE)}reset(){this.checked=!1,this.disabled=!1}_onKeyUp(e){e.altKey||e.keyCode===w&&(e.preventDefault(),this._toggleChecked())}_onClick(){this._toggleChecked()}_toggleChecked(){this.disabled||this.readonly||(this.checked=!this.checked,this.emit(f.ON_CHOICE_ELEMENT_SELECTED,{detail:{identifier:this.identifier,checked:this.checked}}))}render(){return l` <slot></slot> `}};x([r({reflect:!0}),O("design:type",String)],I.prototype,"identifier",void 0),x([r({type:Number,reflect:!0}),O("design:type",Object)],I.prototype,"tabindex",void 0),x([r({type:Boolean,reflect:!0}),O("design:type",Object)],I.prototype,"disabled",void 0),x([r({type:Boolean,reflect:!0}),O("design:type",Object)],I.prototype,"readonly",void 0),x([r({reflect:!0,type:Boolean,attribute:"aria-checked",converter:{toAttribute:e=>`${e}`}}),O("design:type",Object)],I.prototype,"checked",void 0),x([A("disabled",{waitUntilFirstUpdate:!0}),O("design:type",Function),O("design:paramtypes",[Object,Boolean]),O("design:returntype",void 0)],I.prototype,"handleDisabledChange",null),I=x([n("qti-choice")],I);class N extends e{render(){return t``}}customElements.define("qti-variabledeclaration",N);class T extends N{connectedCallback(){super.connectedCallback();const e=new v({baseType:this.baseType,identifier:this.identifier,correctResponse:this.correctResponse,cardinality:this.cardinality||b.single,mapping:this.mapping});this.dispatchEvent(new CustomEvent(f.ON_REGISTER_VARIABLE,{bubbles:!0,composed:!0,detail:e}))}get correctResponse(){let e;const t=this.querySelector("qti-correct-response");if(t){const s=t.querySelectorAll("qti-value");if(1===s.length)e=s[0].textContent,s[0].remove();else{e=[];for(let t=0;t<s.length;t++)e.push(s[t].textContent),s[t].remove()}}return e}get mapping(){const e=this.querySelector("qti-mapping");if(e){const t=new Map,s=e.querySelectorAll("qti-map-entry");for(let e=0;e<s.length;e++){const i=s[e],n=i.getAttribute("map-key"),r=i.getAttribute("mapped-value");t.set(n,r?parseFloat(r):null)}return t}return null}}x([r({type:String,attribute:"base-type"}),O("design:type",String)],T.prototype,"baseType",void 0),x([r({type:String,attribute:"identifier"}),O("design:type",String)],T.prototype,"identifier",void 0),x([r({type:String,attribute:"cardinality"}),O("design:type",String)],T.prototype,"cardinality",void 0),customElements.define("qti-response-declaration",T);class L extends N{static get observedAttributes(){return["identifier","cardinality","base-type"]}connectedCallback(){super.connectedCallback();const e=this.getAttribute("identifier"),t=new E;t.identifier=e,this.dispatchEvent(new CustomEvent(f.ON_REGISTER_VARIABLE,{bubbles:!0,composed:!0,detail:t}))}}customElements.define("qti-outcome-declaration",L);let M=class extends _{};M=x([n("qti-companion-materials-info")],M);const H=c("logger");let $=class extends _{constructor(){super(...arguments),this.logger=new d(this,H,(e=>this.style.display=this.view===e.view?"block":"none"),!0)}handleclassNamesChange(e,t){this.classNames.split(" ").forEach((e=>{switch(e){case"qti-rubric-discretionary-placement":this.setAttribute("slot","qti-rubric-block");break;case"qti-rubric-inline":this.setAttribute("slot","")}}))}render(){return t`<slot></slot>`}connectedCallback(){super.connectedCallback(),this.setAttribute("slot","qti-rubric-block")}};$.styles=s`
|
|
8
8
|
:host {
|
|
9
9
|
display: block;
|
|
10
10
|
}
|
|
@@ -152,7 +152,7 @@ import{LitElement as e,html as t,css as s,render as i}from"lit";import{customEle
|
|
|
152
152
|
?disabled="${this.disabled}"
|
|
153
153
|
?readonly="${this.readonly}"
|
|
154
154
|
.value=${this.value}
|
|
155
|
-
></textarea>`}textChanged(e){if(this.disabled||this.readonly)return;const t=e.target;this.setEmptyAttribute(t.value),this.value=t.value,this.saveResponse({base:{string:t.value}})}reset(){this.value=""}setEmptyAttribute(e){this.setAttribute("empty",""===e?"true":"false")}}V.rowHeightClass=["","qti-height-lines-3","qti-height-lines-6","qti-height-lines-15"],x([r({type:Number,attribute:"expected-length"}),O("design:type",Object)],V.prototype,"expectedLength",void 0),x([r({type:String,attribute:"pattern-mask"}),O("design:type",Object)],V.prototype,"patternMask",void 0),x([r({type:String,attribute:"placeholder-text"}),O("design:type",Object)],V.prototype,"placeholderText",void 0),x([r({type:String}),O("design:type",Object)],V.prototype,"value",void 0),x([r({type:String,attribute:"class"}),O("design:type",Object)],V.prototype,"classNames",void 0),x([A("classNames",{waitUntilFirstUpdate:!0}),O("design:type",Function),O("design:paramtypes",[Object,Boolean]),O("design:returntype",void 0)],V.prototype,"handleclassNamesChange",null),customElements.define("qti-extended-text-interaction",V);let z=class extends
|
|
155
|
+
></textarea>`}textChanged(e){if(this.disabled||this.readonly)return;const t=e.target;this.setEmptyAttribute(t.value),this.value=t.value,this.saveResponse({base:{string:t.value}})}reset(){this.value=""}setEmptyAttribute(e){this.setAttribute("empty",""===e?"true":"false")}}V.rowHeightClass=["","qti-height-lines-3","qti-height-lines-6","qti-height-lines-15"],x([r({type:Number,attribute:"expected-length"}),O("design:type",Object)],V.prototype,"expectedLength",void 0),x([r({type:String,attribute:"pattern-mask"}),O("design:type",Object)],V.prototype,"patternMask",void 0),x([r({type:String,attribute:"placeholder-text"}),O("design:type",Object)],V.prototype,"placeholderText",void 0),x([r({type:String}),O("design:type",Object)],V.prototype,"value",void 0),x([r({type:String,attribute:"class"}),O("design:type",Object)],V.prototype,"classNames",void 0),x([A("classNames",{waitUntilFirstUpdate:!0}),O("design:type",Function),O("design:paramtypes",[Object,Boolean]),O("design:returntype",void 0)],V.prototype,"handleclassNamesChange",null),customElements.define("qti-extended-text-interaction",V);let z=class extends I{};z=x([n("qti-hottext")],z);class W extends F{constructor(){super(),this._choiceElements=[],this._minChoices=0,this._maxChoices=1,this._handleDisabledChange=(e,t)=>this._choiceElements.forEach((e=>e.disabled=t)),this._handleReadonlyChange=(e,t)=>this._choiceElements.forEach((e=>e.readonly=t)),this._handleMaxChoicesChange=()=>this._determineInputType(),this.addEventListener(f.ON_REGISTER_CHOICE,this._registerChoiceElement),this.addEventListener(f.ON_LOOSE_CHOICE,this._looseChoiceElement)}reset(){this._choiceElements.forEach((e=>{e.reset()}))}validate(){return this._choiceElements.reduce(((e,t)=>e+(!0===t.checked?1:0)),0)>=this._minChoices}set response(e){this._choiceElements.forEach((e=>{e.checked=!1}));(Array.isArray(e)?e:[e]).forEach((e=>{const t=this.querySelector("[identifier='"+e+"']");t&&(t.checked=!0)}))}connectedCallback(){super.connectedCallback(),this.addEventListener(f.ON_CHOICE_ELEMENT_SELECTED,this._choiceElementSelectedHandler)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener(f.ON_CHOICE_ELEMENT_SELECTED,this._choiceElementSelectedHandler),this.removeEventListener(f.ON_REGISTER_CHOICE,this._registerChoiceElement)}_registerChoiceElement(e){e.stopPropagation();const t=e.target;this._choiceElements.push(t),this._setInputType(t)}_looseChoiceElement(e){e.stopPropagation();const t=e.target;this._choiceElements.push(t),this._choiceElements=this._choiceElements.filter((e=>e!==t))}_determineInputType(){this._choiceElements.forEach((e=>{this._setInputType(e)}))}_setInputType(e){1===this._maxChoices?e.setAttribute("role","radio"):e.setAttribute("role","checkbox")}_choiceElementSelectedHandler(e){1===this._maxChoices&&this._choiceElements.filter((t=>t.identifier!==e.detail.identifier)).forEach((e=>{e.checked=!1})),this._choiceElementSelected()}_choiceElementSelected(){const e=this._choiceElements.filter((e=>1==e.checked)).map((e=>e.identifier));let t;this._maxChoices>1&&(this._maxChoices===e.length?this._choiceElements.forEach((e=>e.disabled=!(1==e.checked))):this._choiceElements.forEach((e=>e.disabled=!1))),t=1===this._maxChoices?{base:{identifier:e.length>0?e[0]:""}}:{list:{identifier:e}},this.saveResponse(t)}}x([r({type:Number,attribute:"min-choices"}),O("design:type",Number)],W.prototype,"_minChoices",void 0),x([r({type:Number,attribute:"max-choices"}),O("design:type",Number)],W.prototype,"_maxChoices",void 0),x([A("disabled",{waitUntilFirstUpdate:!0}),O("design:type",Object)],W.prototype,"_handleDisabledChange",void 0),x([A("readonly",{waitUntilFirstUpdate:!0}),O("design:type",Object)],W.prototype,"_handleReadonlyChange",void 0),x([A("_maxChoices",{waitUntilFirstUpdate:!0}),O("design:type",Object)],W.prototype,"_handleMaxChoicesChange",void 0);class K extends W{constructor(){super(...arguments),this.render=()=>t`<slot></slot>`}connectedCallback(){super.connectedCallback(),this.setAttribute("qti-hottext-interaction","")}}customElements.define("qti-hottext-interaction",K);class Q extends F{constructor(){super(),this.options=[],this.addEventListener(f.ON_DROPDOWN_SELECTED,this.choiceSelected);const e=Array.from(this.querySelectorAll("qti-inline-choice"));this.options=[{textContent:"select",value:"",selected:!1},...e.map((e=>({textContent:e.innerHTML,value:e.getAttribute("identifier"),selected:!1})))]}static get properties(){return Object.assign(Object.assign({},F.properties),{options:{type:Array,value:[],attribute:!1}})}connectedCallback(){super.connectedCallback()}static get styles(){return[B,s`
|
|
156
156
|
:host {
|
|
157
157
|
display: inline-block;
|
|
158
158
|
}
|
|
@@ -172,7 +172,7 @@ import{LitElement as e,html as t,css as s,render as i}from"lit";import{customEle
|
|
|
172
172
|
`))}
|
|
173
173
|
</select>`}validate(){const e=this.options.find((e=>e.selected));return!!e&&""!==e.value}reset(){this.options=this.options.map(((e,t)=>Object.assign(Object.assign({},e),{selected:0===t})))}set response(e){this.options=this.options.map((t=>(e===t.value&&(t.selected=!0),t)))}choiceSelected(e){const t=e.target.value;this.options=this.options.map((e=>Object.assign(Object.assign({},e),{selected:e.value===t}))),this.saveResponse({base:{string:t}})}}Q.inputWidthClass=["","qti-input-width-2","qti-input-width-1","qti-input-width-3","qti-input-width-4","qti-input-width-6","qti-input-width-10","qti-input-width-15","qti-input-width-20","qti-input-width-72"],customElements.define("qti-inline-choice-interaction",Q);class Y extends W{constructor(){super(...arguments),this._shuffle=!1,this.render=()=>t`
|
|
174
174
|
<slot name="prompt"></slot>
|
|
175
|
-
<slot></slot>`}}Y.layoutClass=["","qti-choices-stacking-2","qti-choices-stacking-3","qti-choices-stacking-4","qti-orientation-vertical","qti-orientation-horizontal"],Y.presentationClass=["","qti-input-control-hidden"],x([r({attribute:"orientation"}),O("design:type",String)],Y.prototype,"_orientation",void 0),x([r({attribute:"shuffle",type:Boolean}),O("design:type",Boolean)],Y.prototype,"_shuffle",void 0),customElements.define("qti-choice-interaction",Y);let X=class extends
|
|
175
|
+
<slot></slot>`}}Y.layoutClass=["","qti-choices-stacking-2","qti-choices-stacking-3","qti-choices-stacking-4","qti-orientation-vertical","qti-orientation-horizontal"],Y.presentationClass=["","qti-input-control-hidden"],x([r({attribute:"orientation"}),O("design:type",String)],Y.prototype,"_orientation",void 0),x([r({attribute:"shuffle",type:Boolean}),O("design:type",Boolean)],Y.prototype,"_shuffle",void 0),customElements.define("qti-choice-interaction",Y);let X=class extends I{};X=x([n("qti-simple-choice")],X);class J extends e{render(){return t`<slot></slot>`}static get observedAttributes(){return["identifier"]}process(){if(this.getAttribute("template")){const e=this.getAttribute("template").split("/"),t=e[e.length-1].replace(".xml","");switch(this.innerHTML="",t){case"map_response":this.appendChild(this.fragmentFromString('<qti-response-processing>\n <qti-response-condition>\n <qti-response-if>\n <qti-is-null>\n <qti-variable identifier="RESPONSE"></qti-variable>\n </qti-is-null>\n <qti-set-outcome-value identifier="SCORE">\n <qti-base-value base-type="float">0.0</qti-base-value>\n </qti-set-outcome-value>\n </qti-response-if>\n <qti-response-else>\n <qti-set-outcome-value identifier="SCORE">\n <qti-map-response identifier="RESPONSE"> </qti-map-response>\n </qti-set-outcome-value>\n </qti-response-else>\n </qti-response-condition>\n</qti-response-processing>'));break;case"map_response_point":this.appendChild(this.fragmentFromString('<qti-response-processing>\n <qti-response-condition>\n <qti-response-if>\n <qti-is-null>\n <qti-variable identifier="RESPONSE"></qti-variable>\n </qti-is-null>\n <qti-set-outcome-value identifier="SCORE">\n <qti-base-value base-type="float">0</qti-base-value>\n </qti-set-outcome-value>\n </qti-response-if>\n <qti-response-else>\n <qti-set-outcome-value identifier="SCORE">\n <qti-map-response-point identifier="RESPONSE"></qti-map-response-point>\n </qti-set-outcome-value>\n </qti-response-else>\n </qti-response-condition>\n</qti-response-processing>'));break;case"match_correct":this.appendChild(this.fragmentFromString('<qti-response-processing>\n <qti-response-condition>\n <qti-response-if>\n <qti-match>\n <qti-variable identifier="RESPONSE"></qti-variable>\n <qti-correct identifier="RESPONSE"></qti-correct>\n </qti-match>\n <qti-set-outcome-value identifier="SCORE">\n <qti-base-value base-type="float">1</qti-base-value>\n </qti-set-outcome-value>\n </qti-response-if>\n <qti-response-else>\n <qti-set-outcome-value identifier="SCORE">\n <qti-base-value base-type="float">0</qti-base-value>\n </qti-set-outcome-value>\n </qti-response-else>\n </qti-response-condition>\n</qti-response-processing>'))}}const e=[...this.children];for(let t=0;t<e.length;t++){e[t].process()}}fragmentFromString(e){return document.createRange().createContextualFragment(e)}}customElements.define("qti-response-processing",J);class Z extends e{render(){return t``}process(){throw new Error("Not implemented")}}customElements.define("qti-rule",Z);class ee extends Z{render(){return t`<slot></slot>`}process(){const e=[...this.children];for(let t=0;t<e.length;t++){const s=e[t];if(s.calculate())return void s.process()}}}customElements.define("qti-response-condition",ee);class te extends e{static get properties(){return{debugCalculateResult:{type:Object}}}render(){return t`
|
|
176
176
|
<slot></slot>`}calculate(){return this.debugCalculateResult=!0,!0}getSubRules(){return[...this.children]}process(){const e=this.getSubRules();for(let t=0;t<e.length;t++){e[t].process()}}}customElements.define("qti-response-else",te);class se extends te{render(){return t`${super.render()}`}calculate(){const e=this.firstElementChild.calculate();return this.debugCalculateResult=e,e}getSubRules(){const e=[];for(let t=1;t<this.children.length;t++)e.push(this.children[t]);return e}}customElements.define("qti-response-if",se);class ie extends se{render(){return t`${super.render()}`}}customElements.define("qti-response-else-if",ie);class ne extends _{render(){return t``}calculate(){throw new Error("Not implemented")}}customElements.define("qti-expression",ne);class re extends ne{calculate(){const e=this.getAttribute("identifier"),t=this.closest("qti-assessment-item").getResponse(e);if(!t)return this.err(`Response ${e} can not be found`),null;const s=t.mapping,i=t.value;let n=0;if(Array.isArray(i)){for(let e=0;e<i.length;e++)n+=oe(s,i[e],t.baseType);return n}return n+=oe(s,i,t.baseType),n}}function oe(e,t,s){let i=0;for(const n of e.entries()){const{entryTyped:e,valueTyped:r}=ae(s,n,t);e===r&&(i+=n[1])}return i}function ae(e,t,s){let i,n;switch(e){case g.string:case g.identifier:case g.directedPair:i=""+t[0],n=""+s;break;case g.float:i=parseFloat(t[0].replace(",",".")),n=parseFloat(s.replace(",","."));break;default:console.warn("no base-type identifier")}return{entryTyped:i,valueTyped:n}}customElements.define("qti-map-response",re);class le extends Z{process(){const e=this.getAttribute("identifier"),t=this.firstElementChild,s=t?t.calculate():null;this.closest("qti-assessment-item").setOutcomeValue(e,s)}}customElements.define("qti-set-outcome-value",le);class ce extends ne{render(){return t``}calculate(){const e=this.getAttribute("identifier"),t=this.closest("qti-assessment-item").getResponse(e);if(!t)return this.err(`Can not find qti-response-identifier: ${e}`),null;return t.correctResponse}}customElements.define("qti-correct",ce);class de extends ne{render(){return t``}calculate(){const e=this.getAttribute("identifier");return this.closest("qti-assessment-item").getVariableValue(e)}}customElements.define("qti-variable",de);class he extends ne{calculate(){const e=this.firstElementChild.calculate(),t=this.lastElementChild.calculate();let s=!0;return s=e instanceof Array?e.length===t.length&&e.filter(((e,s)=>e===t[s])).length===e.length:e==t,s}}customElements.define("qti-match",he);class pe extends ne{calculate(){return pe.calculate(this.textContent,this.getAttribute("base-type"))}static calculate(e,t){let s;if(t===g.directedPair){const t=e.split(" ");s={destination:t[1],source:t[0]}}else s=e;return s}}customElements.define("qti-base-value",pe);class ue extends ne{calculate(){const e=this.firstElementChild,t=this.lastElementChild;return ue.calculate(e,t)}static calculate(e,t){const s=e.calculate(),i=t.calculate(),n=s.map((e=>e.source+" "+e.destination)),r=i.map((e=>e.source+" "+e.destination));return n.filter((e=>r.includes(e))).length>0}}customElements.define("qti-contains",ue);class me extends ne{calculate(){return 2===this.children.length?me.calculate(this.children[0],this.children[1]):(this.err("unexpected number of children in qte"),null)}static calculate(e,t){return+e.calculate()>=+t.calculate()}}customElements.define("qti-gte",me);class ge extends ne{calculate(){return Array.from(this.children).map((e=>e.calculate()))}}customElements.define("qti-multiple",ge);class be extends ne{render(){return t``}calculate(){return be.calculate(Array.from(this.children))}static calculate(e){return e.every((e=>e.calculate()))}}customElements.define("qti-and",be);class fe extends ne{render(){return t``}calculate(){return fe.calculate(Array.from(this.children))}static calculate(e){return!!e.find((e=>e.calculate()))}}customElements.define("qti-or",fe);class ye extends ne{calculate(){return 1===this.children.length?ye.calculate(this.children[0]):(this.err("unexpected number of children in qte"),null)}static calculate(e){const t=e.calculate();return null==t||null==t||""===t}}customElements.define("qti-is-null",ye);class ve extends _{constructor(){super(...arguments),this._errorMessage=null}static get properties(){return{responseIdentifier:{type:String,attribute:"response-identifier"},module:{type:String,attribute:"module"},customInteractionTypeIdentifier:{type:String,attribute:"custom-interaction-type-identifier"},baseUrl:{type:String,attribute:"base-url"},_errorMessage:{type:String,state:!0}}}getTAOConfig(e){const t=e.querySelectorAll("properties");let s={};const i=e=>{const t={},s=e.getAttribute("key");if(s){const i=Array.from(e.children),r=i.map((e=>e.getAttribute("key"))),o=r.length>0&&!r.find((e=>!Number.isInteger(+e)));t[s]=o?i.map((e=>n(e))):e.textContent}return t},n=e=>{if(e){let t={};for(const s of e.children)t=Object.assign(Object.assign({},t),i(s));return t}};for(const e of t){return e.getAttribute("key")||(s=Object.assign(Object.assign({},s),n(e))),s}this.err("Can not find qti-custom-interaction config")}register(e){const t="QTI-CUSTOM-INTERACTION"===this.parentElement.tagName?"TAO":"IMS",s="IMS"==t?this.querySelector("qti-interaction-markup"):this.querySelector("markup");s.classList.add("qti-customInteraction"),"TAO"==t&&this.querySelector("properties")&&(this.querySelector("properties").style.display="none");const i="IMS"==t?{properties:this.dataset}:this.getTAOConfig(this);if("IMS"==t?e.getInstance(s,i,void 0):e.initialize(this.customInteractionTypeIdentifier,s.firstElementChild,i),"TAO"==t){Array.from(this.querySelectorAll("link")).map((e=>e.getAttribute("href"))).forEach((e=>{const t=document.createElement("link");t.rel="stylesheet",t.type="text/css",t.media="screen",t.href=e,s.appendChild(t)}))}}connectedCallback(){super.connectedCallback();const e={context:this.customInteractionTypeIdentifier,baseUrl:this.baseUrl,catchError:!0};window.requirePaths&&window.requireShim&&(e.paths=window.requirePaths,e.shim=window.requireShim);requirejs.config(e)(["require"],(e=>{define("qtiCustomInteractionContext",(()=>({register:e=>{this.register(e)},notifyReady:()=>{}}))),e([this.module],(()=>{}),(e=>{console.log("WAH",e),this._errorMessage=e}))}),(e=>{console.log("BAH",e),this._errorMessage=e}))}render(){return t`<slot></slot>${this._errorMessage&&t`<div style="color:red"><h1>Error</h1>${this._errorMessage}</div>`}`}}customElements.define("qti-portable-custom-interaction",ve);const Ee=(e,t)=>class extends e{connectedCallback(){if(super.connectedCallback(),this.classList.contains("qti-match-tabular"))return;Array.from(this.querySelectorAll(t)).forEach((e=>{e.addEventListener("dragstart",(t=>{t.dataTransfer.setData("text",t.currentTarget.getAttribute("identifier")),e.setAttribute("dragging","")})),e.addEventListener("dragend",(t=>{t.preventDefault(),e.removeAttribute("over"),e.removeAttribute("dragging")})),e.setAttribute("draggable","true")}))}},_e=(e,t)=>class extends e{static get properties(){return{disabled:{type:Boolean,reflect:!0}}}firstUpdated(e){if(this.classList.contains("qti-match-tabular"))return;super.firstUpdated(e);const s=Array.from(this.querySelectorAll(t));this.dragoverHandler=this.dragoverHandler.bind(this),this.dragleaveHandler=this.dragleaveHandler.bind(this),this.dropHandler=this.dropHandler.bind(this),s.forEach((e=>{e.setAttribute("dropzone","move"),e.addEventListener("dragleave",this.dragleaveHandler),this.attachHandler(e)}));for(const e of s)this.observer=new MutationObserver((t=>{t.forEach((t=>{if("attributes"===t.type){switch(t.attributeName){case"disabled":e.hasAttribute("disabled")?this.removeHandler(e):this.attachHandler(e);break}}}))})),this.observer.observe(e,{attributes:!0})}attachHandler(e){e.addEventListener("dragover",this.dragoverHandler),e.addEventListener("drop",this.dropHandler)}removeHandler(e){e.removeEventListener("dragover",this.dragoverHandler),e.removeEventListener("drop",this.dropHandler)}disconnectedCallback(){var e;this.classList.contains("qti-match-tabular")||(super.disconnectedCallback(),null===(e=this.observer)||void 0===e||e.disconnect())}dragoverHandler(e){e.preventDefault();return e.currentTarget.setAttribute("active",""),e.dataTransfer.dropEffect="move",!1}dropHandler(e){e.preventDefault();const t=e.currentTarget,s=this.querySelector(`[identifier=${e.dataTransfer.getData("text")}`);return t?s.parentElement.getAttribute("identifier")!==t.getAttribute("identifier")&&t.appendChild(s):console.error(`cannot find droppable, target: ${e.target?JSON.stringify(e.target):"null"}`),t.removeAttribute("active"),!1}dragleaveHandler(e){e.preventDefault();return e.currentTarget.removeAttribute("active"),!1}},qe=(e,t,s)=>class extends e{constructor(){super(...arguments),this.state=new Map,this.animateMe=()=>{this.state.forEach(((e,t)=>{const{left:s,top:i,width:n,height:r}=t.getBoundingClientRect();null==this.state.get(t)&&this.state.set(t,{left:s,top:i,width:n,height:r});const o=this.state.get(t),a=o.left-s,l=o.top-i,c=o.width/n,d=o.height/r;this.state.set(t,{left:s,top:i,width:n,height:r});const{duration:h,easing:p}={duration:350,easing:"cubic-bezier(0.26, 0.86, 0.44, 0.985)"};t.animate([{transformOrigin:"top left",transform:`\n translate(${a}px, ${l}px)\n scale(${c}, ${d})\n `},{transformOrigin:"top left",transform:"none"}],{duration:h,easing:p})}))}}firstUpdated(e){const i=Object.create(null,{firstUpdated:{get:()=>super.firstUpdated}});return S(this,void 0,void 0,(function*(){if(this.classList.contains("qti-match-tabular"))return;yield this.updateComplete;Array.from(this.querySelectorAll(s)).forEach((e=>{const{left:t,top:s,width:i,height:n}=e.getBoundingClientRect();this.state.set(e,{left:t,top:s,width:i,height:n})})),this.observer=new MutationObserver(this.animateMe);Array.from(this.querySelectorAll(t)).forEach((e=>{this.observer.observe(e,{childList:!0})})),this.observer.observe(this,{childList:!0}),i.firstUpdated.call(this,e)}))}disconnectedCallback(){this.classList.contains("qti-match-tabular")||(super.disconnectedCallback(),this.observer.disconnect())}},Ce=(e,s,i)=>{class n extends(qe(_e(Ee(e,s),i),i,s)){constructor(){if(super(),this.draggables=new Map,this.disabled=!1,this.readonly=!1,this.minAssociations=1,this.maxAssociations=1,this.classList.contains("qti-match-tabular"))return;Array.from(this.querySelectorAll(s)).forEach((e=>{this.draggables.set(e,{parent:e.parentElement,index:Array.from(e.parentNode.children).indexOf(e)}),e.addEventListener("dragend",(e=>{if("none"===e.dataTransfer.dropEffect){const t=e.currentTarget,s=this.draggables.get(t),i=s.index<s.parent.children.length?s.index:s.parent.children.length-1,n=s.parent,r=s.parent.children[i];n.insertBefore(t,r)}e.dataTransfer.dropEffect,this.saveResponse(),this.checkMaxMatchAssociations()}))}))}static get properties(){return{responseIdentifier:{type:String,value:"",attribute:"response-identifier"},disabled:{type:Boolean,reflect:!0},readonly:{type:Boolean,reflect:!0},minAssociations:{type:Number,reflect:!0,attribute:"min-associations"},maxAssociations:{type:Number,reflect:!0,attribute:"max-associations"}}}render(){return t` <slot></slot> `}checkMaxMatchAssociations(){const e=Array.from(this.querySelectorAll(i));if(e.filter((e=>e.childElementCount>0)).length>=this.maxAssociations)e.forEach((e=>this.setDisableStateDroppable(e,!0)));else for(const t of e){const e=+(t.getAttribute("match-max")||1)<=(t.children.length||0);this.setDisableStateDroppable(t,e)}}setDisableStateDroppable(e,t){t?(e.setAttribute("disabled",""),e.removeAttribute("dropzone")):(e.removeAttribute("disabled"),e.setAttribute("dropzone","move"))}updated(e){this.classList.contains("qti-match-tabular")||e.forEach(((e,t)=>{switch(t){case"disabled":this.draggables.forEach(((e,t)=>{this.disabled?t.setAttribute("disabled",""):t.removeAttribute("disabled"),this.disabled?t.removeAttribute("draggable"):t.setAttribute("draggable","true")}));break;case"readonly":this.draggables.forEach(((e,t)=>{this.readonly?t.setAttribute("readonly",""):t.removeAttribute("readonly"),this.readonly?t.removeAttribute("draggable"):t.setAttribute("draggable","true")}))}}))}reset(e=!0){this.draggables.forEach(((e,t)=>{const s=e.index<e.parent.children.length?e.index:e.parent.children.length;e.parent.insertBefore(t,e.parent.children[s])})),e&&this.saveResponse()}set response(e){this.classList.contains("qti-match-tabular")||(this.reset(!1),null!==e&&Array.isArray(e)&&e.forEach((e=>{const[t,s]=e.split(" ");if(s){const e=this.querySelector(`[identifier=${s}]`),i=this.querySelector(`[identifier=${t}]`);e?i?(e.appendChild(i),this.checkMaxMatchAssociations()):console.error(`cannot find draggable with identifier: ${t}`):console.error(`cannot find droppable with identifier: ${s}`)}})))}validate(){const e=Array.from(this.querySelectorAll(i)).filter((e=>e.childElementCount>0)).length;return this.minAssociations<=0||this.minAssociations<=e}saveResponse(){const e={list:{pair:Array.from(this.querySelectorAll(i)).map((e=>Array.from(e.children).map((e=>e.getAttribute("identifier")+" "))+e.getAttribute("identifier")))}};this.dispatchEvent(new CustomEvent(f.ON_INTERACTION_RESPONSE,{bubbles:!0,composed:!0,detail:{responseIdentifier:this.responseIdentifier,responses:e}}))}connectedCallback(){super.connectedCallback(),this.dispatchEvent(new CustomEvent(f.ON_REGISTER_INTERACTION,{bubbles:!0,composed:!0,detail:this}))}}return n},xe=s`
|
|
177
177
|
.notification {
|
|
178
178
|
position: absolute;
|
|
@@ -204,12 +204,12 @@ import{LitElement as e,html as t,css as s,render as i}from"lit";import{customEle
|
|
|
204
204
|
</div>`))}
|
|
205
205
|
`,this),super.firstUpdated(e)}connectedCallback(){super.connectedCallback(),this.childrenMap=Array.from(this.querySelectorAll("qti-simple-associable-choice"))}}Oe.styles=[xe],customElements.define("qti-associate-interaction",Oe);class Se extends e{render(){return t`
|
|
206
206
|
<slot></slot>
|
|
207
|
-
`}}customElements.define("qti-simple-associable-choice",Se);class Re extends(Ce(e,"qti-gap-text","qti-gap")){render(){return t`<slot></slot>`}}Re.styles=[xe],customElements.define("qti-gap-match-interaction",Re);class ke extends HTMLElement{}customElements.define("qti-gap-text",ke);class Ae extends HTMLElement{}function
|
|
207
|
+
`}}customElements.define("qti-simple-associable-choice",Se);class Re extends(Ce(e,"qti-gap-text","qti-gap")){render(){return t`<slot></slot>`}}Re.styles=[xe],customElements.define("qti-gap-match-interaction",Re);class ke extends HTMLElement{}customElements.define("qti-gap-text",ke);class Ae extends HTMLElement{}function we(e,t,s,i){switch(e){case"circle":{const[e,n,r]=t,o=e/s.width*100,a=n/s.height*100,l=r/s.width*100;i.style.left=o-l+"%",i.style.top=a-l+"%",i.style.width=i.style.height=4*l+"px",i.style.clipPath="circle(50% at 50% 50%)"}break;case"rect":{const[e,n,r,o]=t,a=e/s.width*100,l=n/s.height*100,c=r/s.width*100,d=o/s.height*100;i.style.left=a+"%",i.style.top=l+"%",i.style.width=c-a+"%",i.style.height=d-l+"%"}break;case"poly":{const e=t.reduce(((e,t,s,i)=>{if(s%2==1){const t=e.pop();e[e.length]={x:t,y:i[s]}}else e.push(t);return e}),[]),n=Math.min(...e.map((e=>e.x))),r=Math.max(...e.map((e=>e.x))),o=Math.min(...e.map((e=>e.y))),a=Math.max(...e.map((e=>e.y))),l=n/s.width*100,c=o/s.height*100,d=r/s.width*100,h=a/s.height*100;i.style.left=n/s.width*100+"%",i.style.top=o/s.height*100+"%",i.style.width=d-l+"%",i.style.height=h-c+"%";const p=e.map((e=>({x:(e.x-n)/(r-n)*100,y:(e.y-o)/(a-o)*100}))).map((e=>Math.round(e.x)+"% "+Math.round(e.y)+"%")).join(",");i.style.clipPath=`polygon(${p})`}}}customElements.define("qti-gap",Ae);class Ie extends W{render(){return t`
|
|
208
208
|
<slot name="prompt"></slot>
|
|
209
209
|
<!-- slot for the prompt -->
|
|
210
210
|
<slot></slot>
|
|
211
211
|
<!-- slot for the image and hotspots -->
|
|
212
|
-
`}positionHotspotOnRegister(e){const t=this.querySelector("img"),s=e.target,i=s.getAttribute("coords");
|
|
212
|
+
`}positionHotspotOnRegister(e){const t=this.querySelector("img"),s=e.target,i=s.getAttribute("coords");we(s.getAttribute("shape"),i.split(",").map((e=>parseInt(e))),t,s)}connectedCallback(){super.connectedCallback(),this.addEventListener(f.ON_REGISTER_CHOICE,this.positionHotspotOnRegister)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener(f.ON_REGISTER_CHOICE,this.positionHotspotOnRegister)}}Ie.styles=[s`
|
|
213
213
|
slot:not([name='prompt']) {
|
|
214
214
|
position: relative; /* qti-hotspot-choice relative to the slot */
|
|
215
215
|
display: block;
|
|
@@ -220,7 +220,7 @@ import{LitElement as e,html as t,css as s,render as i}from"lit";import{customEle
|
|
|
220
220
|
pointer-events: none;
|
|
221
221
|
user-select: none;
|
|
222
222
|
}
|
|
223
|
-
`],customElements.define("qti-graphic-associate-interaction",
|
|
223
|
+
`],customElements.define("qti-graphic-associate-interaction",Ie);class Ne extends(Ce(_,"qti-gap-img","qti-associable-hotspot")){render(){return t` <slot></slot>
|
|
224
224
|
<slot name="qti-gap-img"></slot>`}positionHotspotOnRegister(e){const t=e.target,s=t.getAttribute("coords"),i=t.getAttribute("shape"),n=s.split(",").map((e=>parseInt(e)));switch(i){case"circle":{const[e,s,i]=n;t.style.left=e-i+"px",t.style.top=s-i+"px",t.style.width=t.style.height=2*i+"px"}break;case"rect":{const[e,s,i,r]=n;t.style.left=e+"px",t.style.top=s+"px",t.style.width=i-e+"px",t.style.height=r-s+"px"}}}connectedCallback(){super.connectedCallback(),this.addEventListener(f.ON_REGISTER_HOTSPOT,this.positionHotspotOnRegister)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener(f.ON_REGISTER_HOTSPOT,this.positionHotspotOnRegister)}}Ne.styles=s`
|
|
225
225
|
slot[name="qti-gap-img"] {
|
|
226
226
|
display: flex;
|
|
@@ -231,7 +231,7 @@ import{LitElement as e,html as t,css as s,render as i}from"lit";import{customEle
|
|
|
231
231
|
<!-- slot for the prompt -->
|
|
232
232
|
<slot></slot>
|
|
233
233
|
<!-- slot for the image and hotspots -->
|
|
234
|
-
`}setHotspotOrder(e){const{identifier:t}=e.detail,s=this._choiceElements.find((e=>e.getAttribute("identifier")===t)),i=this._choiceElements.length;if(!this.choiceOrdering){if(this.choiceOrdering=!0,null==s.order)return this._choiceElements.filter((e=>e.order>0)).length>=i||(s.order=this._choiceElements.filter((e=>!!e.order)).length+1),void(this.choiceOrdering=!1);this._choiceElements.forEach((e=>(e.order>e.order&&e.order--,e))),s.order=null,this.choiceOrdering=!1}}positionHotspotOnRegister(e){const t=this.querySelector("img"),s=e.target,i=s.getAttribute("coords");
|
|
234
|
+
`}setHotspotOrder(e){const{identifier:t}=e.detail,s=this._choiceElements.find((e=>e.getAttribute("identifier")===t)),i=this._choiceElements.length;if(!this.choiceOrdering){if(this.choiceOrdering=!0,null==s.order)return this._choiceElements.filter((e=>e.order>0)).length>=i||(s.order=this._choiceElements.filter((e=>!!e.order)).length+1),void(this.choiceOrdering=!1);this._choiceElements.forEach((e=>(e.order>e.order&&e.order--,e))),s.order=null,this.choiceOrdering=!1}}positionHotspotOnRegister(e){const t=this.querySelector("img"),s=e.target,i=s.getAttribute("coords");we(s.getAttribute("shape"),i.split(",").map((e=>parseInt(e))),t,s)}connectedCallback(){super.connectedCallback(),this.addEventListener(f.ON_CHOICE_ELEMENT_SELECTED,this.setHotspotOrder),this.addEventListener(f.ON_REGISTER_CHOICE,this.positionHotspotOnRegister)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener(f.ON_CHOICE_ELEMENT_SELECTED,this.setHotspotOrder),this.removeEventListener(f.ON_REGISTER_CHOICE,this.positionHotspotOnRegister)}}Te.styles=[s`
|
|
235
235
|
slot:not([name='prompt']) {
|
|
236
236
|
position: relative; /* qti-hotspot-choice relative to the slot */
|
|
237
237
|
display: block;
|
|
@@ -247,7 +247,7 @@ import{LitElement as e,html as t,css as s,render as i}from"lit";import{customEle
|
|
|
247
247
|
<!-- slot for the prompt -->
|
|
248
248
|
<slot></slot>
|
|
249
249
|
<!-- slot for the image and hotspots -->
|
|
250
|
-
`}positionHotspotOnRegister(e){const t=this.querySelector("img"),s=e.target,i=s.getAttribute("coords");
|
|
250
|
+
`}positionHotspotOnRegister(e){const t=this.querySelector("img"),s=e.target,i=s.getAttribute("coords");we(s.getAttribute("shape"),i.split(",").map((e=>parseInt(e))),t,s)}connectedCallback(){super.connectedCallback(),this.addEventListener(f.ON_REGISTER_CHOICE,this.positionHotspotOnRegister)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener(f.ON_REGISTER_CHOICE,this.positionHotspotOnRegister)}}Le.styles=[s`
|
|
251
251
|
slot:not([name='prompt']) {
|
|
252
252
|
position: relative; /* qti-hotspot-choice relative to the slot */
|
|
253
253
|
display: block;
|
|
@@ -258,7 +258,7 @@ import{LitElement as e,html as t,css as s,render as i}from"lit";import{customEle
|
|
|
258
258
|
pointer-events: none;
|
|
259
259
|
user-select: none;
|
|
260
260
|
}
|
|
261
|
-
`],customElements.define("qti-hotspot-interaction",Le);class Me extends
|
|
261
|
+
`],customElements.define("qti-hotspot-interaction",Le);class Me extends I{}Me.styles=s`
|
|
262
262
|
:host {
|
|
263
263
|
position: absolute;
|
|
264
264
|
}
|
|
@@ -314,7 +314,7 @@ import{LitElement as e,html as t,css as s,render as i}from"lit";import{customEle
|
|
|
314
314
|
`],customElements.define("qti-order-interaction",je);class De extends W{constructor(){super()}render(){return t`<slot></slot>
|
|
315
315
|
<div class="notification"></div>`}connectedCallback(){super.connectedCallback()}disconnectedCallback(){super.disconnectedCallback()}}De.styles=[xe],customElements.define("qti-select-point-interaction",De);const Ue=37,Pe=38,Fe=39,Be=40,Ge=33,Ve=34,ze=35,We=36;class Ke extends F{constructor(){super(),this.addEventListener("keydown",this._onKeyDown.bind(this))}reset(){}validate(){return!0}set response(e){}set min(e){this._min=e,this.style.setProperty("--qti-slider-interaction-lower-bounds",`${this._min}`)}get min(){return this._min}set max(e){this._max=e,this.style.setProperty("--qti-slider-interaction-upper-bounds",`${this._max}`)}get max(){return this._max}set step(e){this._step=e,this.style.setProperty("--qti-slider-interaction-step",`${this._step}`)}get step(){return this._step}render(){return t`
|
|
316
316
|
<slot name="prompt"></slot>
|
|
317
|
-
<slot></slot>`}firstUpdated(){this.addEventListener("mousedown",this._onMouseDown.bind(this)),this.style.setProperty("--qti-slider-interaction-step",this.step?this.step.toString():"10");const e=this.getAttribute("value");this._moveSliderTo(e)}connectedCallback(){super.connectedCallback(),this.setAttribute("tabindex","0"),this.setAttribute("role","slider")}get RAIL_WIDTH(){return this.offsetWidth}_onKeyDown(e){let t=!1;const s=this.value;switch(e.keyCode){case Ue:case Be:this._moveSliderTo(s-this.step),t=!0;break;case Fe:case Pe:this._moveSliderTo(s+this.step),t=!0;break;case Ve:this._moveSliderTo(s-this.step),t=!0;break;case Ge:this._moveSliderTo(s+this.step),t=!0;break;case We:this._moveSliderTo(this.min),t=!0;break;case ze:this._moveSliderTo(this.max),t=!0}t&&(e.preventDefault(),e.stopPropagation())}_onMouseDown(e){const t=e.target,s=this.min,i=this.max,n=e=>{const n=e.pageX-t.offsetLeft,r=s+(i-s)*n/this.RAIL_WIDTH;this._moveSliderTo(r),e.preventDefault(),e.stopPropagation()},r=()=>{document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",r),this.saveResponse({base:{float:this.value}})};document.addEventListener("mousemove",n),document.addEventListener("mouseup",r),e.preventDefault(),e.stopPropagation(),e.target.focus();const o=e.pageX-t.offsetLeft,a=s+(i-s)*o/this.RAIL_WIDTH;this._moveSliderTo(a)}_moveSliderTo(e){const t=this.min,s=this.max;let i=Number(e);i<t&&(i=t),i>s&&(i=s);const n=(i-t)/(s-t)*100;this.style.setProperty("--qti-slider-interaction-aria-valuenow",`${n}%`)}}Ke.styles=[xe,s``],x([r({type:Number,attribute:"lower-bound"}),O("design:type",Number),O("design:paramtypes",[Number])],Ke.prototype,"min",null),x([r({type:Number,attribute:"upper-bound"}),O("design:type",Number),O("design:paramtypes",[Number])],Ke.prototype,"max",null),x([r({type:Number,attribute:"step"}),O("design:type",Number),O("design:paramtypes",[Number])],Ke.prototype,"step",null),customElements.define("qti-slider-interaction",Ke);class Qe extends e{constructor(){super(...arguments),this.render=()=>t`${this.value}`}levenshtein(e,t){let s;if(0===e.length)return t.length;if(0===t.length)return e.length;e.length>t.length&&(s=e,e=t,t=s);const i=e.length,n=t.length,r=Array(i);let o,a,l;for(o=0;o<=i;o++)r[o]=o;for(o=1;o<=n;o++){for(l=o,a=1;a<=i;a++)s=r[a-1],r[a-1]=l,l=Math.min(s+(t[o-1]!==e[a-1]),l+1,r[a]+1);r[a-1]=l}return l}calculate(){const e=this.firstElementChild,t=this.lastElementChild,s=e.calculate(),i=t.calculate();return this.value=100-this.levenshtein(s.toString().trim(),i.toString().trim())/i.toString().length*100,this.value}}Qe.properties={value:{}},customElements.define("qti-custom-operator-levenshtein",Qe);class Ye extends e{render(){return t``}calculate(){var e;const t=null===(e=this.firstElementChild.calculate())||void 0===e?void 0:e.toString();return t?t.replace(/[^0-9$.,]/g,""):""}}customElements.define("qti-custom-operator-numeric",Ye);class Xe extends e{constructor(){super(...arguments),this.render=()=>t`${this.value}`}calculate(){var e;const t=null===(e=this.firstElementChild.calculate())||void 0===e?void 0:e.toString();return this.value=t?this.parseNumber(t,undefined):"",this.value}parseNumber(e,t=navigator.languages){const s=Intl.NumberFormat(t).format(1.1),i=new RegExp(`[^-+0-9${s.charAt(1)}]`,"g"),n=e.replace(i,"").replace(s.charAt(1),".");return parseFloat(n)}}Xe.properties={value:{}},customElements.define("qti-custom-operator-parse-numeric-nl",Xe);class Je extends e{render(){return t``}calculate(){var e;const t=null===(e=this.firstElementChild.calculate())||void 0===e?void 0:e.toString();return t?t.replace(/ /g,""):""}}customElements.define("qti-custom-operator-remove-spaces",Je);class Ze extends e{render(){return t``}calculate(){return this.firstElementChild.calculate().toString().trim()}}customElements.define("qti-custom-operator-trim",Ze);const et=(e,t)=>class extends e{_dispatch(){this.dispatchEvent(new CustomEvent(t,{composed:!0,bubbles:!0,detail:+this.getAttribute("index")}))}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this._dispatch)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this._dispatch)}};customElements.define("qti-test-next",class extends(et(e,"on-next-item")){constructor(){super(...arguments),this.render=()=>t`<slot></slot>`}}),customElements.define("qti-test-item",class extends(et(e,"on-request-item")){constructor(){super(...arguments),this.render=()=>t`<slot></slot>`}}),customElements.define("qti-test-prev",class extends(et(e,"on-prev-item")){constructor(){super(...arguments),this.render=()=>t`<slot></slot>`}}),customElements.define("qti-test-check",class extends(et(e,"on-check-item")){constructor(){super(...arguments),this.render=()=>t`<slot></slot>`}}),customElements.define("qti-test-score",class extends(et(e,"on-score-item")){constructor(){super(...arguments),this.render=()=>t`<slot></slot>`}});const tt={ON_ITEM_WAS_FINISHED:"onItemWasFinished",ON_NO_RESPONSE_ON_SUBMIT:"onNoResponseOnSubmit",ON_REQUEST_ITEM:"onRequestItem",ON_TEST_FINISHED:"onTestFinished",ON_ITEM_READY:"onItemReady"};var st,it;!function(e){e.linear="linear",e.nonlinear="nonlinear"}(st||(st={})),function(e){e.individual="individual",e.simultaneous="simultaneous"}(it||(it={}));let nt=class extends e{constructor(){super(...arguments),this.disabled=!1,this.readonly=!1,this._navigationMode=st.nonlinear,this._submissionMode=it.simultaneous,this.items=[],this.itemIndex=0,this.provider=new h(this,H,{log:e=>{console.log(`[my-app] ${e}`)},view:"candidate"})}handleNavigationModeChange(e,t){this.prevButton.style.visibility=t===st.linear?"hidden":"visible"}handleItemIndexChange(e,t){this.emit(tt.ON_REQUEST_ITEM,{detail:t})}set qtiContext(e){this.provider.value.view=e.view,this.provider.updateObservers()}set itemXML(e){this._itemRef&&this._itemRef.remove(),this.insertAdjacentHTML("afterbegin",e)}set manualOutcomeValue(e){this._itemRef.setOutcomeValue("SCORE",e)}set itemResponse(e){this._itemRef&&(this._itemRef.responses=e,this._navigationMode===st.linear&&(this._itemRef.style.filter="blur(5px)",this._itemRef.setAttribute("disabled",""),this.dispatchEvent(new CustomEvent(tt.ON_ITEM_WAS_FINISHED))))}_onCheckItem(){return!!this._itemRef.validateResponses()&&(this._itemRef.processResponse(),!0)}_onScoreItem(){this._onCheckItem()&&this._itemRef.processResponse()}_onPrevItem(){this.itemIndex>0&&this.emit(tt.ON_REQUEST_ITEM,{detail:this.itemIndex-1})}_onNextItem(){this._navigationMode!==st.linear||this._itemRef.validateResponses()?this.itemIndex<this.items.length-1?this.emit(tt.ON_REQUEST_ITEM,{detail:this.itemIndex+1}):this.dispatchEvent(new CustomEvent(tt.ON_TEST_FINISHED)):this.dispatchEvent(new CustomEvent(tt.ON_NO_RESPONSE_ON_SUBMIT))}_onRequestItem({detail:e}){this.emit(tt.ON_REQUEST_ITEM,{detail:e})}_handleSlotchange(e){const t=this.querySelector("qti-assessment-item");t&&(this._itemRef=t,this.disabled&&this._itemRef.setAttribute("disabled",""),this.readonly&&this._itemRef.setAttribute("readonly",""),this.emit(tt.ON_ITEM_READY,{detail:t}))}render(){return t`
|
|
317
|
+
<slot></slot>`}firstUpdated(){this.addEventListener("mousedown",this._onMouseDown.bind(this)),this.style.setProperty("--qti-slider-interaction-step",this.step?this.step.toString():"10");const e=this.getAttribute("value");this._moveSliderTo(e)}connectedCallback(){super.connectedCallback(),this.setAttribute("tabindex","0"),this.setAttribute("role","slider")}get RAIL_WIDTH(){return this.offsetWidth}_onKeyDown(e){let t=!1;const s=this.value;switch(e.keyCode){case Ue:case Be:this._moveSliderTo(s-this.step),t=!0;break;case Fe:case Pe:this._moveSliderTo(s+this.step),t=!0;break;case Ve:this._moveSliderTo(s-this.step),t=!0;break;case Ge:this._moveSliderTo(s+this.step),t=!0;break;case We:this._moveSliderTo(this.min),t=!0;break;case ze:this._moveSliderTo(this.max),t=!0}t&&(e.preventDefault(),e.stopPropagation())}_onMouseDown(e){const t=e.target,s=this.min,i=this.max,n=e=>{const n=e.pageX-t.offsetLeft,r=s+(i-s)*n/this.RAIL_WIDTH;this._moveSliderTo(r),e.preventDefault(),e.stopPropagation()},r=()=>{document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",r),this.saveResponse({base:{float:this.value}})};document.addEventListener("mousemove",n),document.addEventListener("mouseup",r),e.preventDefault(),e.stopPropagation(),e.target.focus();const o=e.pageX-t.offsetLeft,a=s+(i-s)*o/this.RAIL_WIDTH;this._moveSliderTo(a)}_moveSliderTo(e){const t=this.min,s=this.max;let i=Number(e);i<t&&(i=t),i>s&&(i=s);const n=(i-t)/(s-t)*100;this.style.setProperty("--qti-slider-interaction-aria-valuenow",`${n}%`)}}Ke.styles=[xe,s``],x([r({type:Number,attribute:"lower-bound"}),O("design:type",Number),O("design:paramtypes",[Number])],Ke.prototype,"min",null),x([r({type:Number,attribute:"upper-bound"}),O("design:type",Number),O("design:paramtypes",[Number])],Ke.prototype,"max",null),x([r({type:Number,attribute:"step"}),O("design:type",Number),O("design:paramtypes",[Number])],Ke.prototype,"step",null),customElements.define("qti-slider-interaction",Ke);class Qe extends e{constructor(){super(...arguments),this.render=()=>t`${this.value}`}levenshtein(e,t){let s;if(0===e.length)return t.length;if(0===t.length)return e.length;e.length>t.length&&(s=e,e=t,t=s);const i=e.length,n=t.length,r=Array(i);let o,a,l;for(o=0;o<=i;o++)r[o]=o;for(o=1;o<=n;o++){for(l=o,a=1;a<=i;a++)s=r[a-1],r[a-1]=l,l=Math.min(s+(t[o-1]!==e[a-1]),l+1,r[a]+1);r[a-1]=l}return l}calculate(){const e=this.firstElementChild,t=this.lastElementChild,s=e.calculate(),i=t.calculate();return this.value=100-this.levenshtein(s.toString().trim(),i.toString().trim())/i.toString().length*100,this.value}}Qe.properties={value:{}},customElements.define("qti-custom-operator-levenshtein",Qe);class Ye extends e{render(){return t``}calculate(){var e;const t=null===(e=this.firstElementChild.calculate())||void 0===e?void 0:e.toString();return t?t.replace(/[^0-9$.,]/g,""):""}}customElements.define("qti-custom-operator-numeric",Ye);class Xe extends e{constructor(){super(...arguments),this.render=()=>t`${this.value}`}calculate(){var e;const t=null===(e=this.firstElementChild.calculate())||void 0===e?void 0:e.toString();return this.value=t?this.parseNumber(t,undefined):"",this.value}parseNumber(e,t=navigator.languages){const s=Intl.NumberFormat(t).format(1.1),i=new RegExp(`[^-+0-9${s.charAt(1)}]`,"g"),n=e.replace(i,"").replace(s.charAt(1),".");return parseFloat(n)}}Xe.properties={value:{}},customElements.define("qti-custom-operator-parse-numeric-nl",Xe);class Je extends e{render(){return t``}calculate(){var e;const t=null===(e=this.firstElementChild.calculate())||void 0===e?void 0:e.toString();return t?t.replace(/ /g,""):""}}customElements.define("qti-custom-operator-remove-spaces",Je);class Ze extends e{render(){return t``}calculate(){return this.firstElementChild.calculate().toString().trim()}}customElements.define("qti-custom-operator-trim",Ze);const et=(e,t)=>class extends e{_dispatch(){this.dispatchEvent(new CustomEvent(t,{composed:!0,bubbles:!0,detail:+this.getAttribute("index")}))}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this._dispatch)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this._dispatch)}};customElements.define("qti-test-next",class extends(et(e,"on-next-item")){constructor(){super(...arguments),this.render=()=>t`<slot></slot>`}}),customElements.define("qti-test-item",class extends(et(e,"on-request-item")){constructor(){super(...arguments),this.render=()=>t`<slot></slot>`}}),customElements.define("qti-test-prev",class extends(et(e,"on-prev-item")){constructor(){super(...arguments),this.render=()=>t`<slot></slot>`}}),customElements.define("qti-test-check",class extends(et(e,"on-check-item")){constructor(){super(...arguments),this.render=()=>t`<slot></slot>`}}),customElements.define("qti-test-score",class extends(et(e,"on-score-item")){constructor(){super(...arguments),this.render=()=>t`<slot></slot>`}}),customElements.define("qti-test-show-correct",class extends(et(e,"on-show-correct")){constructor(){super(...arguments),this.render=()=>t`<slot></slot>`}});const tt={ON_ITEM_WAS_FINISHED:"onItemWasFinished",ON_NO_RESPONSE_ON_SUBMIT:"onNoResponseOnSubmit",ON_REQUEST_ITEM:"onRequestItem",ON_TEST_FINISHED:"onTestFinished",ON_ITEM_READY:"onItemReady"};var st,it;!function(e){e.linear="linear",e.nonlinear="nonlinear"}(st||(st={})),function(e){e.individual="individual",e.simultaneous="simultaneous"}(it||(it={}));let nt=class extends e{constructor(){super(...arguments),this.disabled=!1,this.readonly=!1,this._navigationMode=st.nonlinear,this._submissionMode=it.simultaneous,this.items=[],this.itemIndex=0,this.provider=new h(this,H,{log:e=>{console.log(`[my-app] ${e}`)},view:"candidate"})}handleNavigationModeChange(e,t){this.prevButton.style.visibility=t===st.linear?"hidden":"visible"}handleItemIndexChange(e,t){this.emit(tt.ON_REQUEST_ITEM,{detail:t})}set qtiContext(e){this.provider.value.view=e.view,this.provider.updateObservers()}set itemXML(e){this._itemRef&&this._itemRef.remove(),this.insertAdjacentHTML("afterbegin",e)}set manualOutcomeValue(e){this._itemRef.setOutcomeValue("SCORE",e)}set itemResponse(e){this._itemRef&&(this._itemRef.responses=e,this._navigationMode===st.linear&&(this._itemRef.style.filter="blur(5px)",this._itemRef.setAttribute("disabled",""),this.dispatchEvent(new CustomEvent(tt.ON_ITEM_WAS_FINISHED))))}_onCheckItem(){return!!this._itemRef.validateResponses()&&(this._itemRef.processResponse(),!0)}_onScoreItem(){this._onCheckItem()&&this._itemRef.processResponse()}_onPrevItem(){this.itemIndex>0&&this.emit(tt.ON_REQUEST_ITEM,{detail:this.itemIndex-1})}_onNextItem(){this._navigationMode!==st.linear||this._itemRef.validateResponses()?this.itemIndex<this.items.length-1?this.emit(tt.ON_REQUEST_ITEM,{detail:this.itemIndex+1}):this.dispatchEvent(new CustomEvent(tt.ON_TEST_FINISHED)):this.dispatchEvent(new CustomEvent(tt.ON_NO_RESPONSE_ON_SUBMIT))}_onShowCorrect(){this._itemRef.showCorrectResponse()}_onRequestItem({detail:e}){this.emit(tt.ON_REQUEST_ITEM,{detail:e})}_handleSlotchange(e){const t=this.querySelector("qti-assessment-item");t&&(this._itemRef=t,this.disabled&&this._itemRef.setAttribute("disabled",""),this.readonly&&this._itemRef.setAttribute("readonly",""),this.emit(tt.ON_ITEM_READY,{detail:t}))}render(){return t`
|
|
318
318
|
<slot
|
|
319
319
|
@slotchange=${this._handleSlotchange}
|
|
320
320
|
@on-prev-item=${this._onPrevItem}
|
|
@@ -322,6 +322,7 @@ import{LitElement as e,html as t,css as s,render as i}from"lit";import{customEle
|
|
|
322
322
|
@on-check-item=${this._onCheckItem}
|
|
323
323
|
@on-score-item=${this._onScoreItem}
|
|
324
324
|
@on-request-item=${this._onRequestItem}
|
|
325
|
+
@on-show-correct=${this._onShowCorrect}
|
|
325
326
|
>
|
|
326
327
|
</slot>
|
|
327
328
|
`}emit(e,t){const s=new CustomEvent(e,Object.assign({bubbles:!0,cancelable:!1,composed:!0,detail:{}},t));this.dispatchEvent(s)}};x([o("qti-test-prev"),O("design:type",HTMLElement)],nt.prototype,"prevButton",void 0),x([o("qti-test-next"),O("design:type",HTMLElement)],nt.prototype,"nextButton",void 0),x([r({type:Boolean}),O("design:type",Object)],nt.prototype,"disabled",void 0),x([r({type:Boolean}),O("design:type",Object)],nt.prototype,"readonly",void 0),x([r({type:String,attribute:"navigation-mode"}),O("design:type",Object)],nt.prototype,"_navigationMode",void 0),x([A("_navigationMode",{waitUntilFirstUpdate:!0}),O("design:type",Function),O("design:paramtypes",[Object,String]),O("design:returntype",void 0)],nt.prototype,"handleNavigationModeChange",null),x([r({type:String,attribute:"submission-mode"}),O("design:type",Object)],nt.prototype,"_submissionMode",void 0),x([r(),O("design:type",Array)],nt.prototype,"items",void 0),x([r({type:Number,attribute:"item-index",reflect:!0}),O("design:type",Object)],nt.prototype,"itemIndex",void 0),x([A("itemIndex",{waitUntilFirstUpdate:!0}),O("design:type",Function),O("design:paramtypes",[Object,Number]),O("design:returntype",void 0)],nt.prototype,"handleItemIndexChange",null),x([a(),O("design:type",q)],nt.prototype,"_itemRef",void 0),nt=x([n("qti-test")],nt);const rt=(e,t)=>class extends e{constructor(){super(...arguments),this.scale=1,this.ro=new ResizeObserver((e=>{for(const t of e)this.fitToParent(t.contentRect.width)}))}connectedCallback(){super.connectedCallback(),this.ro.observe(this),this.fitToParent()}static get properties(){return{scales:{type:Boolean,reflect:!0}}}updated(e){e.forEach(((e,t)=>{if("scales"===t)this.scales&&this.fitToParent()}))}fitToParent(e=this.clientWidth){const s=this.querySelector(t);if(s){const t=e/s.clientWidth;this.scale=t,this.marginY=-s.clientHeight*(1-t)+"px",requestAnimationFrame((()=>{s.style.transform=`scale(${this.scale})`,s.style.margin=`0 0 ${this.marginY} 0`}))}}};class ot extends(rt(e,"qti-assessment-item")){constructor(){super(...arguments),this.disabled=!1,this.readonly=!1,this.processResponse=()=>{var e;return null===(e=this._item)||void 0===e?void 0:e.processResponse()},this.validateResponses=()=>!!this._item&&this._item.validateResponses(),this.resetInteractions=()=>{var e;return null===(e=this._item)||void 0===e?void 0:e.resetInteractions()},this.render=()=>t`<slot @slotchange=${this.handleSlotchange}></slot>`}handleDisabledChange(e,t){var s,i;t&&(null===(s=this._item)||void 0===s||s.setAttribute("disabled","")),!t&&(null===(i=this._item)||void 0===i||i.removeAttribute("disabled"))}handleReadonlyChange(e,t){var s,i;t&&(null===(s=this._item)||void 0===s||s.setAttribute("readonly","")),!t&&(null===(i=this._item)||void 0===i||i.removeAttribute("readonly"))}handleResponsesChange(e,t){this._item&&(this._item.responses=t)}handleSlotchange(e){const t=e.target.assignedNodes({flatten:!0});this._item=null,t.forEach((e=>{"QTI-ASSESSMENT-ITEM"==e.nodeName&&(this._item=e,this.disabled&&this._item.setAttribute("disabled",""),this.readonly&&this._item.setAttribute("readonly",""),this.responses&&(this._item.responses=this.responses))}))}}ot.styles=s`
|
|
@@ -345,15 +346,15 @@ import{LitElement as e,html as t,css as s,render as i}from"lit";import{customEle
|
|
|
345
346
|
type="number"
|
|
346
347
|
spellcheck="false"
|
|
347
348
|
autocomplete="off"
|
|
348
|
-
@keyup
|
|
349
|
-
@change
|
|
349
|
+
@keyup=${this.textChanged}
|
|
350
|
+
@change=${this.textChanged}
|
|
350
351
|
placeholder="score"
|
|
351
|
-
.value
|
|
352
|
+
.value=${this.value}
|
|
352
353
|
size="10"
|
|
353
|
-
?disabled
|
|
354
|
-
?readonly
|
|
354
|
+
?disabled=${this.disabled}
|
|
355
|
+
?readonly=${this.readonly}
|
|
355
356
|
/>`}};at.styles=s`
|
|
356
357
|
:host {
|
|
357
358
|
display: none;
|
|
358
359
|
}
|
|
359
|
-
`,x([r({type:Boolean}),O("design:type",Object)],at.prototype,"disabled",void 0),x([r({type:Boolean}),O("design:type",Object)],at.prototype,"readonly",void 0),x([r({type:Number}),O("design:type",String)],at.prototype,"value",void 0),at=x([n("qti-manual-scoring")],at);export{g as BaseType,b as Cardinality,W as Choices,f as Events,st as NavigationMode,E as OutcomeVariable,be as QtiAnd,q as QtiAssessmentItem,Oe as QtiAssociateInteraction,pe as QtiBaseValue,
|
|
360
|
+
`,x([r({type:Boolean}),O("design:type",Object)],at.prototype,"disabled",void 0),x([r({type:Boolean}),O("design:type",Object)],at.prototype,"readonly",void 0),x([r({type:Number}),O("design:type",String)],at.prototype,"value",void 0),at=x([n("qti-manual-scoring")],at);export{g as BaseType,b as Cardinality,W as Choices,f as Events,st as NavigationMode,E as OutcomeVariable,be as QtiAnd,q as QtiAssessmentItem,Oe as QtiAssociateInteraction,pe as QtiBaseValue,I as QtiChoice,Y as QtiChoiceInteraction,M as QtiCompanionMaterialsInfo,ue as QtiContains,ce as QtiCorrect,Qe as QtiCustomOperatorLevenshtein,Ye as QtiCustomOperatorNumericOnly,Xe as QtiCustomOperatorParseNumberLocalNl,Je as QtiCustomOperatorRemoveAllSpaces,Ze as QtiCustomOperatorTrim,ne as QtiExpression,V as QtiExtendedTextInteraction,U as QtiFeedbackInline,Ae as QtiGap,Re as QtiGapMatchInteraction,ke as QtiGapText,Ie as QtiGraphicAssociateInteraction,Ne as QtiGraphicGapMatchInteraction,Te as QtiGraphicOrderInteraction,me as QtiGte,Me as QtiHotspotChoice,Le as QtiHotspotInteraction,z as QtiHottext,K as QtiHottextInteraction,Q as QtiInlineChoiceInteraction,ye as QtiIsNull,ot as QtiItem,R as QtiItemBody,at as QtiManualScoring,re as QtiMapResponse,he as QtiMatch,He as QtiMatchInteraction,$e as QtiMediaInteraction,P as QtiModalFeedback,ge as QtiMultiple,fe as QtiOr,je as QtiOrderInteraction,L as QtiOutcomeDeclaration,ve as QtiPortableCustomInteraction,k as QtiPrompt,ee as QtiResponseCondition,T as QtiResponseDeclaration,te as QtiResponseElse,ie as QtiResponseElseIf,se as QtiResponseIf,J as QtiResponseProcessing,De as QtiSelectPointInteraction,le as QtiSetOutcomeValue,X as QtiSimpleChoice,Ke as QtiSliderInteraction,C as QtiStylesheet,nt as QtiTest,G as QtiTextEntryInteraction,de as QtiVariable,v as ResponseVariable,y as Status,it as SubmissionMode,tt as TestEvents,j as qtiContentBody,$ as qtiRubricBlock,Se as qtiSimpleAssociableChoice};
|
package/index.umd.css
CHANGED
|
@@ -3692,6 +3692,7 @@ qti-test qti-test-nav {
|
|
|
3692
3692
|
qti-test qti-test-nav qti-test-check,
|
|
3693
3693
|
qti-test qti-test-nav qti-test-score,
|
|
3694
3694
|
qti-test qti-test-nav qti-test-prev,
|
|
3695
|
+
qti-test qti-test-nav qti-test-show-correct,
|
|
3695
3696
|
qti-test qti-test-nav qti-test-next {
|
|
3696
3697
|
display: flex;
|
|
3697
3698
|
align-items: center;
|
|
@@ -3712,6 +3713,7 @@ qti-test qti-test-nav qti-test-next {
|
|
|
3712
3713
|
qti-test qti-test-nav qti-test-check:hover,
|
|
3713
3714
|
qti-test qti-test-nav qti-test-score:hover,
|
|
3714
3715
|
qti-test qti-test-nav qti-test-prev:hover,
|
|
3716
|
+
qti-test qti-test-nav qti-test-show-correct:hover,
|
|
3715
3717
|
qti-test qti-test-nav qti-test-next:hover {
|
|
3716
3718
|
background: #dadada;
|
|
3717
3719
|
transition: all 0.3s ease;
|
|
@@ -3719,6 +3721,7 @@ qti-test qti-test-nav qti-test-next:hover {
|
|
|
3719
3721
|
qti-test qti-test-nav qti-test-check:active,
|
|
3720
3722
|
qti-test qti-test-nav qti-test-score:active,
|
|
3721
3723
|
qti-test qti-test-nav qti-test-prev:active,
|
|
3724
|
+
qti-test qti-test-nav qti-test-show-correct:active,
|
|
3722
3725
|
qti-test qti-test-nav qti-test-next:active {
|
|
3723
3726
|
background: #aeaeae;
|
|
3724
3727
|
}
|
package/index.umd.js
CHANGED
|
@@ -426,7 +426,7 @@ const De=2;
|
|
|
426
426
|
`],customElements.define("qti-order-interaction",Vt);class zt extends it{constructor(){super()}render(){return U`<slot></slot>
|
|
427
427
|
<div class="notification"></div>`}connectedCallback(){super.connectedCallback()}disconnectedCallback(){super.disconnectedCallback()}}zt.styles=[Tt],customElements.define("qti-select-point-interaction",zt);const Wt=37,Kt=38,Yt=39,Xt=40,Jt=33,Zt=34,ei=35,ti=36;class ii extends Ue{constructor(){super(),this.addEventListener("keydown",this._onKeyDown.bind(this))}reset(){}validate(){return!0}set response(e){}set min(e){this._min=e,this.style.setProperty("--qti-slider-interaction-lower-bounds",`${this._min}`)}get min(){return this._min}set max(e){this._max=e,this.style.setProperty("--qti-slider-interaction-upper-bounds",`${this._max}`)}get max(){return this._max}set step(e){this._step=e,this.style.setProperty("--qti-slider-interaction-step",`${this._step}`)}get step(){return this._step}render(){return U`
|
|
428
428
|
<slot name="prompt"></slot>
|
|
429
|
-
<slot></slot>`}firstUpdated(){this.addEventListener("mousedown",this._onMouseDown.bind(this)),this.style.setProperty("--qti-slider-interaction-step",this.step?this.step.toString():"10");const e=this.getAttribute("value");this._moveSliderTo(e)}connectedCallback(){super.connectedCallback(),this.setAttribute("tabindex","0"),this.setAttribute("role","slider")}get RAIL_WIDTH(){return this.offsetWidth}_onKeyDown(e){let t=!1;const i=this.value;switch(e.keyCode){case Wt:case Xt:this._moveSliderTo(i-this.step),t=!0;break;case Yt:case Kt:this._moveSliderTo(i+this.step),t=!0;break;case Zt:this._moveSliderTo(i-this.step),t=!0;break;case Jt:this._moveSliderTo(i+this.step),t=!0;break;case ti:this._moveSliderTo(this.min),t=!0;break;case ei:this._moveSliderTo(this.max),t=!0}t&&(e.preventDefault(),e.stopPropagation())}_onMouseDown(e){const t=e.target,i=this.min,s=this.max,n=e=>{const n=e.pageX-t.offsetLeft,r=i+(s-i)*n/this.RAIL_WIDTH;this._moveSliderTo(r),e.preventDefault(),e.stopPropagation()},r=()=>{document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",r),this.saveResponse({base:{float:this.value}})};document.addEventListener("mousemove",n),document.addEventListener("mouseup",r),e.preventDefault(),e.stopPropagation(),e.target.focus();const o=e.pageX-t.offsetLeft,a=i+(s-i)*o/this.RAIL_WIDTH;this._moveSliderTo(a)}_moveSliderTo(e){const t=this.min,i=this.max;let s=Number(e);s<t&&(s=t),s>i&&(s=i);const n=(s-t)/(i-t)*100;this.style.setProperty("--qti-slider-interaction-aria-valuenow",`${n}%`)}}ii.styles=[Tt,h``],he([be({type:Number,attribute:"lower-bound"}),pe("design:type",Number),pe("design:paramtypes",[Number])],ii.prototype,"min",null),he([be({type:Number,attribute:"upper-bound"}),pe("design:type",Number),pe("design:paramtypes",[Number])],ii.prototype,"max",null),he([be({type:Number,attribute:"step"}),pe("design:type",Number),pe("design:paramtypes",[Number])],ii.prototype,"step",null),customElements.define("qti-slider-interaction",ii);class si extends oe{constructor(){super(...arguments),this.render=()=>U`${this.value}`}levenshtein(e,t){let i;if(0===e.length)return t.length;if(0===t.length)return e.length;e.length>t.length&&(i=e,e=t,t=i);const s=e.length,n=t.length,r=Array(s);let o,a,l;for(o=0;o<=s;o++)r[o]=o;for(o=1;o<=n;o++){for(l=o,a=1;a<=s;a++)i=r[a-1],r[a-1]=l,l=Math.min(i+(t[o-1]!==e[a-1]),l+1,r[a]+1);r[a-1]=l}return l}calculate(){const e=this.firstElementChild,t=this.lastElementChild,i=e.calculate(),s=t.calculate();return this.value=100-this.levenshtein(i.toString().trim(),s.toString().trim())/s.toString().length*100,this.value}}si.properties={value:{}},customElements.define("qti-custom-operator-levenshtein",si);class ni extends oe{render(){return U``}calculate(){var e;const t=null===(e=this.firstElementChild.calculate())||void 0===e?void 0:e.toString();return t?t.replace(/[^0-9$.,]/g,""):""}}customElements.define("qti-custom-operator-numeric",ni);class ri extends oe{constructor(){super(...arguments),this.render=()=>U`${this.value}`}calculate(){var e;const t=null===(e=this.firstElementChild.calculate())||void 0===e?void 0:e.toString();return this.value=t?this.parseNumber(t,undefined):"",this.value}parseNumber(e,t=navigator.languages){const i=Intl.NumberFormat(t).format(1.1),s=new RegExp(`[^-+0-9${i.charAt(1)}]`,"g"),n=e.replace(s,"").replace(i.charAt(1),".");return parseFloat(n)}}ri.properties={value:{}},customElements.define("qti-custom-operator-parse-numeric-nl",ri);class oi extends oe{render(){return U``}calculate(){var e;const t=null===(e=this.firstElementChild.calculate())||void 0===e?void 0:e.toString();return t?t.replace(/ /g,""):""}}customElements.define("qti-custom-operator-remove-spaces",oi);class ai extends oe{render(){return U``}calculate(){return this.firstElementChild.calculate().toString().trim()}}customElements.define("qti-custom-operator-trim",ai);const li=(e,t)=>class extends e{_dispatch(){this.dispatchEvent(new CustomEvent(t,{composed:!0,bubbles:!0,detail:+this.getAttribute("index")}))}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this._dispatch)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this._dispatch)}};customElements.define("qti-test-next",class extends(li(oe,"on-next-item")){constructor(){super(...arguments),this.render=()=>U`<slot></slot>`}}),customElements.define("qti-test-item",class extends(li(oe,"on-request-item")){constructor(){super(...arguments),this.render=()=>U`<slot></slot>`}}),customElements.define("qti-test-prev",class extends(li(oe,"on-prev-item")){constructor(){super(...arguments),this.render=()=>U`<slot></slot>`}}),customElements.define("qti-test-check",class extends(li(oe,"on-check-item")){constructor(){super(...arguments),this.render=()=>U`<slot></slot>`}}),customElements.define("qti-test-score",class extends(li(oe,"on-score-item")){constructor(){super(...arguments),this.render=()=>U`<slot></slot>`}});const ci={ON_ITEM_WAS_FINISHED:"onItemWasFinished",ON_NO_RESPONSE_ON_SUBMIT:"onNoResponseOnSubmit",ON_REQUEST_ITEM:"onRequestItem",ON_TEST_FINISHED:"onTestFinished",ON_ITEM_READY:"onItemReady"};var di,hi;e.NavigationMode=void 0,(di=e.NavigationMode||(e.NavigationMode={})).linear="linear",di.nonlinear="nonlinear",e.SubmissionMode=void 0,(hi=e.SubmissionMode||(e.SubmissionMode={})).individual="individual",hi.simultaneous="simultaneous",e.QtiTest=class extends oe{constructor(){super(...arguments),this.disabled=!1,this.readonly=!1,this._navigationMode=e.NavigationMode.nonlinear,this._submissionMode=e.SubmissionMode.simultaneous,this.items=[],this.itemIndex=0,this.provider=new Ne(this,Me,{log:e=>{console.log(`[my-app] ${e}`)},view:"candidate"})}handleNavigationModeChange(t,i){this.prevButton.style.visibility=i===e.NavigationMode.linear?"hidden":"visible"}handleItemIndexChange(e,t){this.emit(ci.ON_REQUEST_ITEM,{detail:t})}set qtiContext(e){this.provider.value.view=e.view,this.provider.updateObservers()}set itemXML(e){this._itemRef&&this._itemRef.remove(),this.insertAdjacentHTML("afterbegin",e)}set manualOutcomeValue(e){this._itemRef.setOutcomeValue("SCORE",e)}set itemResponse(t){this._itemRef&&(this._itemRef.responses=t,this._navigationMode===e.NavigationMode.linear&&(this._itemRef.style.filter="blur(5px)",this._itemRef.setAttribute("disabled",""),this.dispatchEvent(new CustomEvent(ci.ON_ITEM_WAS_FINISHED))))}_onCheckItem(){return!!this._itemRef.validateResponses()&&(this._itemRef.processResponse(),!0)}_onScoreItem(){this._onCheckItem()&&this._itemRef.processResponse()}_onPrevItem(){this.itemIndex>0&&this.emit(ci.ON_REQUEST_ITEM,{detail:this.itemIndex-1})}_onNextItem(){this._navigationMode!==e.NavigationMode.linear||this._itemRef.validateResponses()?this.itemIndex<this.items.length-1?this.emit(ci.ON_REQUEST_ITEM,{detail:this.itemIndex+1}):this.dispatchEvent(new CustomEvent(ci.ON_TEST_FINISHED)):this.dispatchEvent(new CustomEvent(ci.ON_NO_RESPONSE_ON_SUBMIT))}_onRequestItem({detail:e}){this.emit(ci.ON_REQUEST_ITEM,{detail:e})}_handleSlotchange(e){const t=this.querySelector("qti-assessment-item");t&&(this._itemRef=t,this.disabled&&this._itemRef.setAttribute("disabled",""),this.readonly&&this._itemRef.setAttribute("readonly",""),this.emit(ci.ON_ITEM_READY,{detail:t}))}render(){return U`
|
|
429
|
+
<slot></slot>`}firstUpdated(){this.addEventListener("mousedown",this._onMouseDown.bind(this)),this.style.setProperty("--qti-slider-interaction-step",this.step?this.step.toString():"10");const e=this.getAttribute("value");this._moveSliderTo(e)}connectedCallback(){super.connectedCallback(),this.setAttribute("tabindex","0"),this.setAttribute("role","slider")}get RAIL_WIDTH(){return this.offsetWidth}_onKeyDown(e){let t=!1;const i=this.value;switch(e.keyCode){case Wt:case Xt:this._moveSliderTo(i-this.step),t=!0;break;case Yt:case Kt:this._moveSliderTo(i+this.step),t=!0;break;case Zt:this._moveSliderTo(i-this.step),t=!0;break;case Jt:this._moveSliderTo(i+this.step),t=!0;break;case ti:this._moveSliderTo(this.min),t=!0;break;case ei:this._moveSliderTo(this.max),t=!0}t&&(e.preventDefault(),e.stopPropagation())}_onMouseDown(e){const t=e.target,i=this.min,s=this.max,n=e=>{const n=e.pageX-t.offsetLeft,r=i+(s-i)*n/this.RAIL_WIDTH;this._moveSliderTo(r),e.preventDefault(),e.stopPropagation()},r=()=>{document.removeEventListener("mousemove",n),document.removeEventListener("mouseup",r),this.saveResponse({base:{float:this.value}})};document.addEventListener("mousemove",n),document.addEventListener("mouseup",r),e.preventDefault(),e.stopPropagation(),e.target.focus();const o=e.pageX-t.offsetLeft,a=i+(s-i)*o/this.RAIL_WIDTH;this._moveSliderTo(a)}_moveSliderTo(e){const t=this.min,i=this.max;let s=Number(e);s<t&&(s=t),s>i&&(s=i);const n=(s-t)/(i-t)*100;this.style.setProperty("--qti-slider-interaction-aria-valuenow",`${n}%`)}}ii.styles=[Tt,h``],he([be({type:Number,attribute:"lower-bound"}),pe("design:type",Number),pe("design:paramtypes",[Number])],ii.prototype,"min",null),he([be({type:Number,attribute:"upper-bound"}),pe("design:type",Number),pe("design:paramtypes",[Number])],ii.prototype,"max",null),he([be({type:Number,attribute:"step"}),pe("design:type",Number),pe("design:paramtypes",[Number])],ii.prototype,"step",null),customElements.define("qti-slider-interaction",ii);class si extends oe{constructor(){super(...arguments),this.render=()=>U`${this.value}`}levenshtein(e,t){let i;if(0===e.length)return t.length;if(0===t.length)return e.length;e.length>t.length&&(i=e,e=t,t=i);const s=e.length,n=t.length,r=Array(s);let o,a,l;for(o=0;o<=s;o++)r[o]=o;for(o=1;o<=n;o++){for(l=o,a=1;a<=s;a++)i=r[a-1],r[a-1]=l,l=Math.min(i+(t[o-1]!==e[a-1]),l+1,r[a]+1);r[a-1]=l}return l}calculate(){const e=this.firstElementChild,t=this.lastElementChild,i=e.calculate(),s=t.calculate();return this.value=100-this.levenshtein(i.toString().trim(),s.toString().trim())/s.toString().length*100,this.value}}si.properties={value:{}},customElements.define("qti-custom-operator-levenshtein",si);class ni extends oe{render(){return U``}calculate(){var e;const t=null===(e=this.firstElementChild.calculate())||void 0===e?void 0:e.toString();return t?t.replace(/[^0-9$.,]/g,""):""}}customElements.define("qti-custom-operator-numeric",ni);class ri extends oe{constructor(){super(...arguments),this.render=()=>U`${this.value}`}calculate(){var e;const t=null===(e=this.firstElementChild.calculate())||void 0===e?void 0:e.toString();return this.value=t?this.parseNumber(t,undefined):"",this.value}parseNumber(e,t=navigator.languages){const i=Intl.NumberFormat(t).format(1.1),s=new RegExp(`[^-+0-9${i.charAt(1)}]`,"g"),n=e.replace(s,"").replace(i.charAt(1),".");return parseFloat(n)}}ri.properties={value:{}},customElements.define("qti-custom-operator-parse-numeric-nl",ri);class oi extends oe{render(){return U``}calculate(){var e;const t=null===(e=this.firstElementChild.calculate())||void 0===e?void 0:e.toString();return t?t.replace(/ /g,""):""}}customElements.define("qti-custom-operator-remove-spaces",oi);class ai extends oe{render(){return U``}calculate(){return this.firstElementChild.calculate().toString().trim()}}customElements.define("qti-custom-operator-trim",ai);const li=(e,t)=>class extends e{_dispatch(){this.dispatchEvent(new CustomEvent(t,{composed:!0,bubbles:!0,detail:+this.getAttribute("index")}))}connectedCallback(){super.connectedCallback(),this.addEventListener("click",this._dispatch)}disconnectedCallback(){super.disconnectedCallback(),this.removeEventListener("click",this._dispatch)}};customElements.define("qti-test-next",class extends(li(oe,"on-next-item")){constructor(){super(...arguments),this.render=()=>U`<slot></slot>`}}),customElements.define("qti-test-item",class extends(li(oe,"on-request-item")){constructor(){super(...arguments),this.render=()=>U`<slot></slot>`}}),customElements.define("qti-test-prev",class extends(li(oe,"on-prev-item")){constructor(){super(...arguments),this.render=()=>U`<slot></slot>`}}),customElements.define("qti-test-check",class extends(li(oe,"on-check-item")){constructor(){super(...arguments),this.render=()=>U`<slot></slot>`}}),customElements.define("qti-test-score",class extends(li(oe,"on-score-item")){constructor(){super(...arguments),this.render=()=>U`<slot></slot>`}}),customElements.define("qti-test-show-correct",class extends(li(oe,"on-show-correct")){constructor(){super(...arguments),this.render=()=>U`<slot></slot>`}});const ci={ON_ITEM_WAS_FINISHED:"onItemWasFinished",ON_NO_RESPONSE_ON_SUBMIT:"onNoResponseOnSubmit",ON_REQUEST_ITEM:"onRequestItem",ON_TEST_FINISHED:"onTestFinished",ON_ITEM_READY:"onItemReady"};var di,hi;e.NavigationMode=void 0,(di=e.NavigationMode||(e.NavigationMode={})).linear="linear",di.nonlinear="nonlinear",e.SubmissionMode=void 0,(hi=e.SubmissionMode||(e.SubmissionMode={})).individual="individual",hi.simultaneous="simultaneous",e.QtiTest=class extends oe{constructor(){super(...arguments),this.disabled=!1,this.readonly=!1,this._navigationMode=e.NavigationMode.nonlinear,this._submissionMode=e.SubmissionMode.simultaneous,this.items=[],this.itemIndex=0,this.provider=new Ne(this,Me,{log:e=>{console.log(`[my-app] ${e}`)},view:"candidate"})}handleNavigationModeChange(t,i){this.prevButton.style.visibility=i===e.NavigationMode.linear?"hidden":"visible"}handleItemIndexChange(e,t){this.emit(ci.ON_REQUEST_ITEM,{detail:t})}set qtiContext(e){this.provider.value.view=e.view,this.provider.updateObservers()}set itemXML(e){this._itemRef&&this._itemRef.remove(),this.insertAdjacentHTML("afterbegin",e)}set manualOutcomeValue(e){this._itemRef.setOutcomeValue("SCORE",e)}set itemResponse(t){this._itemRef&&(this._itemRef.responses=t,this._navigationMode===e.NavigationMode.linear&&(this._itemRef.style.filter="blur(5px)",this._itemRef.setAttribute("disabled",""),this.dispatchEvent(new CustomEvent(ci.ON_ITEM_WAS_FINISHED))))}_onCheckItem(){return!!this._itemRef.validateResponses()&&(this._itemRef.processResponse(),!0)}_onScoreItem(){this._onCheckItem()&&this._itemRef.processResponse()}_onPrevItem(){this.itemIndex>0&&this.emit(ci.ON_REQUEST_ITEM,{detail:this.itemIndex-1})}_onNextItem(){this._navigationMode!==e.NavigationMode.linear||this._itemRef.validateResponses()?this.itemIndex<this.items.length-1?this.emit(ci.ON_REQUEST_ITEM,{detail:this.itemIndex+1}):this.dispatchEvent(new CustomEvent(ci.ON_TEST_FINISHED)):this.dispatchEvent(new CustomEvent(ci.ON_NO_RESPONSE_ON_SUBMIT))}_onShowCorrect(){this._itemRef.showCorrectResponse()}_onRequestItem({detail:e}){this.emit(ci.ON_REQUEST_ITEM,{detail:e})}_handleSlotchange(e){const t=this.querySelector("qti-assessment-item");t&&(this._itemRef=t,this.disabled&&this._itemRef.setAttribute("disabled",""),this.readonly&&this._itemRef.setAttribute("readonly",""),this.emit(ci.ON_ITEM_READY,{detail:t}))}render(){return U`
|
|
430
430
|
<slot
|
|
431
431
|
@slotchange=${this._handleSlotchange}
|
|
432
432
|
@on-prev-item=${this._onPrevItem}
|
|
@@ -434,6 +434,7 @@ const De=2;
|
|
|
434
434
|
@on-check-item=${this._onCheckItem}
|
|
435
435
|
@on-score-item=${this._onScoreItem}
|
|
436
436
|
@on-request-item=${this._onRequestItem}
|
|
437
|
+
@on-show-correct=${this._onShowCorrect}
|
|
437
438
|
>
|
|
438
439
|
</slot>
|
|
439
440
|
`}emit(e,t){const i=new CustomEvent(e,Object.assign({bubbles:!0,cancelable:!1,composed:!0,detail:{}},t));this.dispatchEvent(i)}},he([ve("qti-test-prev"),pe("design:type",HTMLElement)],e.QtiTest.prototype,"prevButton",void 0),he([ve("qti-test-next"),pe("design:type",HTMLElement)],e.QtiTest.prototype,"nextButton",void 0),he([be({type:Boolean}),pe("design:type",Object)],e.QtiTest.prototype,"disabled",void 0),he([be({type:Boolean}),pe("design:type",Object)],e.QtiTest.prototype,"readonly",void 0),he([be({type:String,attribute:"navigation-mode"}),pe("design:type",Object)],e.QtiTest.prototype,"_navigationMode",void 0),he([xe("_navigationMode",{waitUntilFirstUpdate:!0}),pe("design:type",Function),pe("design:paramtypes",[Object,String]),pe("design:returntype",void 0)],e.QtiTest.prototype,"handleNavigationModeChange",null),he([be({type:String,attribute:"submission-mode"}),pe("design:type",Object)],e.QtiTest.prototype,"_submissionMode",void 0),he([be(),pe("design:type",Array)],e.QtiTest.prototype,"items",void 0),he([be({type:Number,attribute:"item-index",reflect:!0}),pe("design:type",Object)],e.QtiTest.prototype,"itemIndex",void 0),he([xe("itemIndex",{waitUntilFirstUpdate:!0}),pe("design:type",Function),pe("design:paramtypes",[Object,Number]),pe("design:returntype",void 0)],e.QtiTest.prototype,"handleItemIndexChange",null),he([fe(),pe("design:type",ce)],e.QtiTest.prototype,"_itemRef",void 0),e.QtiTest=he([me("qti-test")],e.QtiTest);const pi=(e,t)=>class extends e{constructor(){super(...arguments),this.scale=1,this.ro=new ResizeObserver((e=>{for(const t of e)this.fitToParent(t.contentRect.width)}))}connectedCallback(){super.connectedCallback(),this.ro.observe(this),this.fitToParent()}static get properties(){return{scales:{type:Boolean,reflect:!0}}}updated(e){e.forEach(((e,t)=>{if("scales"===t)this.scales&&this.fitToParent()}))}fitToParent(e=this.clientWidth){const i=this.querySelector(t);if(i){const t=e/i.clientWidth;this.scale=t,this.marginY=-i.clientHeight*(1-t)+"px",requestAnimationFrame((()=>{i.style.transform=`scale(${this.scale})`,i.style.margin=`0 0 ${this.marginY} 0`}))}}};class ui extends(pi(oe,"qti-assessment-item")){constructor(){super(...arguments),this.disabled=!1,this.readonly=!1,this.processResponse=()=>{var e;return null===(e=this._item)||void 0===e?void 0:e.processResponse()},this.validateResponses=()=>!!this._item&&this._item.validateResponses(),this.resetInteractions=()=>{var e;return null===(e=this._item)||void 0===e?void 0:e.resetInteractions()},this.render=()=>U`<slot @slotchange=${this.handleSlotchange}></slot>`}handleDisabledChange(e,t){var i,s;t&&(null===(i=this._item)||void 0===i||i.setAttribute("disabled","")),!t&&(null===(s=this._item)||void 0===s||s.removeAttribute("disabled"))}handleReadonlyChange(e,t){var i,s;t&&(null===(i=this._item)||void 0===i||i.setAttribute("readonly","")),!t&&(null===(s=this._item)||void 0===s||s.removeAttribute("readonly"))}handleResponsesChange(e,t){this._item&&(this._item.responses=t)}handleSlotchange(e){const t=e.target.assignedNodes({flatten:!0});this._item=null,t.forEach((e=>{"QTI-ASSESSMENT-ITEM"==e.nodeName&&(this._item=e,this.disabled&&this._item.setAttribute("disabled",""),this.readonly&&this._item.setAttribute("readonly",""),this.responses&&(this._item.responses=this.responses))}))}}ui.styles=h`
|
|
@@ -457,13 +458,13 @@ const De=2;
|
|
|
457
458
|
type="number"
|
|
458
459
|
spellcheck="false"
|
|
459
460
|
autocomplete="off"
|
|
460
|
-
@keyup
|
|
461
|
-
@change
|
|
461
|
+
@keyup=${this.textChanged}
|
|
462
|
+
@change=${this.textChanged}
|
|
462
463
|
placeholder="score"
|
|
463
|
-
.value
|
|
464
|
+
.value=${this.value}
|
|
464
465
|
size="10"
|
|
465
|
-
?disabled
|
|
466
|
-
?readonly
|
|
466
|
+
?disabled=${this.disabled}
|
|
467
|
+
?readonly=${this.readonly}
|
|
467
468
|
/>`}},e.QtiManualScoring.styles=h`
|
|
468
469
|
:host {
|
|
469
470
|
display: none;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@citolab/qti-components",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.52",
|
|
4
4
|
"repository": "@citolab/qti-components",
|
|
5
5
|
"author": "Patrick de Klein",
|
|
6
6
|
"license": "MIT",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"lit": "2.4.1",
|
|
15
15
|
"@storybook/addon-actions": "6.5.13",
|
|
16
16
|
"lit-html": "2.4.0",
|
|
17
|
-
"@citolab/qti-transform": "0.0.
|
|
17
|
+
"@citolab/qti-transform": "0.0.7"
|
|
18
18
|
},
|
|
19
19
|
"peerDependencies": {}
|
|
20
20
|
}
|