', {
'class': 'h5p-question-explanation-text',
html: feedback.text,
appendTo: $explanationItem
});
}
}
};
createHTML();
/**
* Return the container HTMLElement
*
* @return {HTMLElement}
*/
self.getElement = function () {
return self.$explanation;
};
}
return Explainer;
})(H5P.jQuery);
;
(function (Question) {
/**
* Makes it easy to add animated score points for your question type.
*
* @class H5P.Question.ScorePoints
*/
Question.ScorePoints = function () {
var self = this;
var elements = [];
var showElementsTimer;
/**
* Create the element that displays the score point element for questions.
*
* @param {boolean} isCorrect
* @return {HTMLElement}
*/
self.getElement = function (isCorrect) {
var element = document.createElement('div');
element.classList.add(isCorrect ? 'h5p-question-plus-one' : 'h5p-question-minus-one');
element.classList.add('h5p-question-hidden-one');
elements.push(element);
// Schedule display animation of all added elements
if (showElementsTimer) {
clearTimeout(showElementsTimer);
}
showElementsTimer = setTimeout(showElements, 0);
return element;
};
/**
* @private
*/
var showElements = function () {
// Determine delay between triggering animations
var delay = 0;
var increment = 150;
var maxTime = 1000;
if (elements.length && elements.length > Math.ceil(maxTime / increment)) {
// Animations will run for more than ~1 second, reduce it.
increment = maxTime / elements.length;
}
for (var i = 0; i < elements.length; i++) {
// Use timer to trigger show
setTimeout(showElement(elements[i]), delay);
// Increse delay for next element
delay += increment;
}
};
/**
* Trigger transition animation for the given element
*
* @private
* @param {HTMLElement} element
* @return {function}
*/
var showElement = function (element) {
return function () {
element.classList.remove('h5p-question-hidden-one');
};
};
};
})(H5P.Question);
;
var H5P = H5P || {};
/**
* Constructor.
*
* @param {Object} params Options for this library.
* @param {Number} id Content identifier
* @returns {undefined}
*/
(function ($) {
H5P.Image = function (params, id, extras) {
H5P.EventDispatcher.call(this);
this.extras = extras;
if (params.file === undefined || !(params.file instanceof Object)) {
this.placeholder = true;
}
else {
this.source = H5P.getPath(params.file.path, id);
this.width = params.file.width;
this.height = params.file.height;
}
this.alt = (!params.decorative && params.alt !== undefined) ?
this.stripHTML(this.htmlDecode(params.alt)) :
'';
if (params.title !== undefined) {
this.title = this.stripHTML(this.htmlDecode(params.title));
}
};
H5P.Image.prototype = Object.create(H5P.EventDispatcher.prototype);
H5P.Image.prototype.constructor = H5P.Image;
/**
* Wipe out the content of the wrapper and put our HTML in it.
*
* @param {jQuery} $wrapper
* @returns {undefined}
*/
H5P.Image.prototype.attach = function ($wrapper) {
var self = this;
var source = this.source;
if (self.$img === undefined) {
if(self.placeholder) {
self.$img = $('
', {
width: '100%',
height: '100%',
class: 'h5p-placeholder',
title: this.title === undefined ? '' : this.title,
on: {
load: function () {
self.trigger('loaded');
}
}
});
} else {
self.$img = $('
', {
width: '100%',
height: '100%',
src: source,
alt: this.alt,
title: this.title === undefined ? '' : this.title,
on: {
load: function () {
self.trigger('loaded');
}
}
});
}
}
$wrapper.addClass('h5p-image').html(self.$img);
};
/**
* Retrieve decoded HTML encoded string.
*
* @param {string} input HTML encoded string.
* @returns {string} Decoded string.
*/
H5P.Image.prototype.htmlDecode = function (input) {
const dparser = new DOMParser().parseFromString(input, 'text/html');
return dparser.documentElement.textContent;
};
/**
* Retrieve string without HTML tags.
*
* @param {string} input Input string.
* @returns {string} Output string.
*/
H5P.Image.prototype.stripHTML = function (html) {
const div = document.createElement('div');
div.innerHTML = html;
return div.textContent || div.innerText || '';
};
return H5P.Image;
}(H5P.jQuery));
;
!function(){"use strict";let t=function(){function t(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;this.params=t,this.callbacks=e||{},this.content=document.createElement("div"),this.content.classList.add("h5p-crossword-clue-announcer"),this.clueId=document.createElement("span"),this.clueId.classList.add("h5p-crossword-clue-announcer-clue-id"),this.content.appendChild(this.clueId),this.clue=document.createElement("span"),this.clue.classList.add("h5p-crossword-clue-announcer-clue"),this.content.appendChild(this.clue),this.answerLength=document.createElement("span"),this.answerLength.classList.add("h5p-crossword-clue-announcer-answer-length"),this.content.appendChild(this.answerLength)}var e=t.prototype;return e.getDOM=function(){return this.content},e.setClue=function(t){t.orientation&&t.clueId&&t.clue&&t.answerLength&&(this.clueId.innerText=`${t.clueId} ${t.orientation}`,this.clue.innerText=t.clue,this.answerLength.innerText=`(${t.answerLength})`)},e.show=function(){this.content.classList.remove("h5p-crossword-display-none")},e.hide=function(){this.content.classList.add("h5p-crossword-display-none")},e.reset=function(){this.clueId.innerText="",this.clue.innerText="",this.answerLength.innerText=""},t}(),e=function(){function t(){}return t.extend=function(){for(let t=1;t
1){const n=Array.prototype.slice.call(arguments,1);for(;o--;)s[e-1-o]=t.createArray.apply(this,n)}return s},t.shuffleArray=function(t){let e,s,o;for(o=t.length-1;o>0;o--)e=Math.floor(Math.random()*(o+1)),s=t[o],t[o]=t[e],t[e]=s;return t},t.formatLanguageCode=function(t){if("string"!=typeof t)return t;const e=t.split("-");return e[0]=e[0].toLowerCase(),e.length>1&&(e[1]=e[1].toUpperCase()),t=e.join("-")},t.toUpperCase=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];return"string"!=typeof t?null:("string"==typeof e&&(e=e.split("").map((t=>({lowerCase:t,upperCase:t})))),Array.isArray(e)||(e=[]),e=e.filter((t=>"string"==typeof t.lowerCase&&1===t.lowerCase.length&&"string"==typeof t.upperCase&&1===t.upperCase.length)),e.forEach(((e,s)=>{for(;-1!==t.indexOf(e.lowerCase);)t=t.replace(e.lowerCase,`[CROSSWORDPLACEHOLDER${s}]`)})),t=t.toUpperCase(),e.forEach(((e,s)=>{for(;-1!==t.indexOf(`[CROSSWORDPLACEHOLDER${s}]`);)t=t.replace(`[CROSSWORDPLACEHOLDER${s}]`,e.upperCase)})),t)},t.waitForDOM=function(t,e){let s=arguments.length>2&&void 0!==arguments[2]?arguments[2]:()=>{},o=arguments.length>3&&void 0!==arguments[3]?arguments[3]:50,n=arguments.length>4&&void 0!==arguments[4]?arguments[4]:100;if(0===o||!t||"function"!=typeof e||"function"!=typeof s)return void s();n=Math.max(n,50);document.querySelector(t)?e():setTimeout((()=>{this.waitForDOM(t,e,s,o<0?-1:o-1,n)}),n)},t}();e.CONTROL_KEY_CODES=[8,9,13,16,17,18,19,20,27,33,34,35,36,37,38,39,40,45,46,91,92,93,112,113,114,115,116,117,118,119,120,121,122,123,144,145],e.UPPERCASE_EXCEPTIONS=[{lowerCase:"ß",upperCase:"ẞ"}],e.CHARACTER_PLACEHOLDER="_";var s=e;let o=function(){function t(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.params=s.extend({container:document.body,content:document.createElement("div"),styleBase:"h5p-crossword-overlay",position:{offsetHorizontal:0,offsetVertical:0},l10n:{closeWindow:"Close"}},t),this.callbacks=e,this.callbacks.onClose=e.onClose||(()=>{}),this.callbacks.onRead=e.onRead||(()=>{}),this.isVisible=!1,this.focusableElements=[],this.overlay=document.createElement("div"),this.overlay.classList.add(`${this.params.styleBase}-outer-wrapper`),this.overlay.classList.add("h5p-crossword-invisible"),this.overlay.setAttribute("role","dialog"),this.params.l10n.title&&this.overlay.setAttribute("aria-label",this.params.l10n.title),this.overlay.setAttribute("aria-modal","true"),this.content=document.createElement("div"),this.content.classList.add(`${this.params.styleBase}-content`),this.content.appendChild(this.params.content),this.buttonClose=document.createElement("button"),this.buttonClose.classList.add(`${this.params.styleBase}-button-close`),this.buttonClose.setAttribute("title",this.params.l10n.closeWindow),this.buttonClose.addEventListener("click",(()=>{this.callbacks.onClose()})),this.overlay.appendChild(this.buttonClose),this.overlay.appendChild(this.content),document.addEventListener("focus",(t=>{this.isVisible&&0!==this.focusableElements.length&&this.trapFocus(t)}),!0),this.blocker=document.createElement("div"),this.blocker.classList.add("h5p-crossword-overlay-blocker"),this.blocker.classList.add("h5p-crossword-display-none")}var e=t.prototype;return e.getDOM=function(){return this.overlay},e.setContent=function(t){for(;this.content.firstChild;)this.content.removeChild(this.content.firstChild);this.content.appendChild(t),this.content.scrollTop=0},e.trapFocus=function(t){this.isChild(t.target)?this.currentFocusElement=t.target:(this.currentFocusElement===this.focusableElements[0]?this.currentFocusElement=this.focusableElements[this.focusableElements.length-1]:this.currentFocusElement=this.focusableElements[0],this.currentFocusElement.focus())},e.isChild=function(t){const e=t.parentNode;return!!e&&(e===this.overlay||this.isChild(e))},e.updateFocusableElements=function(){this.focusableElements=[].slice.call(this.overlay.querySelectorAll('video, audio, button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])')).filter((t=>"true"!==t.getAttribute("disabled")&&!0!==t.getAttribute("disabled")))},e.show=function(){this.blockerAppended||(this.container=document.body.querySelector(".h5p-container"),this.container.appendChild(this.blocker)),this.blockerAppended=!0,this.overlay.classList.remove("h5p-crossword-invisible"),this.blocker.classList.remove("h5p-crossword-display-none"),setTimeout((()=>{this.updateFocusableElements(),this.focusableElements.length>0&&this.focusableElements[0].focus();const t=this.overlay.querySelector(".h5p-advanced-text");let e;t?this.callbacks.onRead(t.innerText):e=this.overlay.querySelector(".h5p-image > img"),e&&this.callbacks.onRead(e.getAttribute("alt")||""),this.isVisible=!0,this.resize()}),0)},e.hide=function(){this.isVisible=!1,this.overlay.classList.add("h5p-crossword-invisible"),this.blocker.classList.add("h5p-crossword-display-none")},e.resize=function(){this.container&&(this.content.style.maxHeight=`calc(${this.container.offsetHeight}px - ${t.CONTENT_MARGIN})`)},t}();o.CONTENT_MARGIN="7em";let n=function(){function t(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.params=s.extend({a11y:{listLabel:""}},t),this.charMarked=null,this.content=this.buildListContainer({listLabel:this.params.a11y.listLabel})}var e=t.prototype;return e.getDOM=function(){return this.content},e.buildListContainer=function(t){const e=document.createElement("div");e.classList.add("h5p-crossword-input-fields-group-solution-container"),e.classList.add("h5p-crossword-display-none");const s=document.createElement("div");return s.classList.add("h5p-crossword-input-fields-group-solution-inner"),e.appendChild(s),this.list=document.createElement("div"),this.list.classList.add("h5p-crossword-input-fields-group-solution-word"),this.list.setAttribute("role","list"),this.list.setAttribute("aria-label",t.listLabel),this.list.setAttribute("aria-expanded","false"),this.list.setAttribute("tabindex","0"),s.appendChild(this.list),this.list.addEventListener("keydown",(t=>{const e=this.charMarked||this.list.firstChild,s=this.list.getAttribute("aria-expanded");switch(t.code){case"Enter":case"Space":if(t.target!==t.currentTarget)return;"false"===s?(this.list.setAttribute("aria-expanded","true"),e&&(e.setAttribute("tabindex","0"),e.focus())):(this.list.setAttribute("aria-expanded","false"),e&&e.setAttribute("tabindex","-1"))}})),e},e.buildListItem=function(t){const e=document.createElement("span");e.classList.add("h5p-crossword-input-fields-group-solution-char-wrapper"),e.setAttribute("role","listitem"),e.setAttribute("tabindex","-1"),e.setAttribute("aria-label",t.ariaLabel),"neutral"===t.result?(e.classList.add("h5p-crossword-solution-no-input")," "!==t.char&&t.char!==s.CHARACTER_PLACEHOLDER||e.classList.add("h5p-crossword-solution-no-char")):"correct"===t.result?e.classList.add("h5p-crossword-solution-correct"):e.classList.add("h5p-crossword-solution-wrong"),t.scoreExplanation&&e.appendChild(t.scoreExplanation),e.addEventListener("focus",(t=>{this.charMarked=t.target})),e.addEventListener("keydown",(t=>{const e=t.target.parentNode.firstChild,s=t.target.parentNode.lastChild;switch(t.keyCode){case 37:case 38:t.preventDefault(),t.target.previousSibling&&(t.target.setAttribute("tabindex","-1"),t.target.previousSibling.setAttribute("tabindex","0"),t.target.previousSibling.focus());break;case 39:case 40:t.preventDefault(),t.target.nextSibling&&(t.target.setAttribute("tabindex","-1"),t.target.nextSibling.setAttribute("tabindex","0"),t.target.nextSibling.focus());break;case 36:t.preventDefault(),t.target!==e&&(t.target.setAttribute("tabindex","-1"),e.setAttribute("tabindex","0"),e.focus());break;case 35:t.preventDefault(),t.target!==s&&(t.target.setAttribute("tabindex","-1"),s.setAttribute("tabindex","0"),s.focus())}}));const o=document.createElement("span");return o.classList.add("h5p-crossword-input-fields-group-solution-char"),o.innerHTML=t.char&&" "!==t.char.trim()?s.toUpperCase(t.char,s.UPPERCASE_EXCEPTIONS):" ",e.appendChild(o),e},e.setChars=function(t){this.reset(),t.forEach((t=>{this.list.appendChild(this.buildListItem(t))}))},e.show=function(){this.content.classList.remove("h5p-crossword-display-none")},e.hide=function(){this.content.classList.add("h5p-crossword-display-none")},e.enable=function(){if(this.tabindexState&&this.tabindexState.list&&this.list.setAttribute("tabindex",this.tabindexState.list),this.tabindexState&&this.tabindexState.listItems){const t=this.list.children;for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;this.params=s.extend({l10n:{extraClue:"Extra clue",closeWindow:"Close Window"}},t),this.callbacks=e||{},this.callbacks.onFieldInput=this.callbacks.onFieldInput||(()=>{}),this.callbacks.onRead=e.onRead||(()=>{}),this.inputFields=[],this.extraClues=[],this.content=document.createElement("div"),this.content.classList.add("h5p-crossword-input-container");const n=this.buildInputFieldsGroup({words:this.params.words.filter((t=>"across"===t.orientation)),title:t.l10n.across});this.content.appendChild(n);const i=this.buildInputFieldsGroup({words:this.params.words.filter((t=>"down"===t.orientation)),title:t.l10n.down});this.content.appendChild(i),this.overlay=new o({l10n:{closeWindow:this.params.l10n.closeWindow}},{onClose:()=>{this.handleOverlayClosed()},onRead:t=>{this.callbacks.onRead(t)}}),t.overlayContainer.appendChild(this.overlay.getDOM())}var e=t.prototype;return e.getDOM=function(){return this.content},e.buildInputFieldsGroup=function(t){t.words=t.words.sort(((t,e)=>t.clueId-e.clueId));const e=document.createElement("div");e.classList.add("h5p-crossword-input-fields-group");const o=document.createElement("div");return o.classList.add("h5p-crossword-input-fields-group-title"),o.innerText=t.title,e.appendChild(o),t.words.forEach((t=>{const o=document.createElement("div");o.classList.add("h5p-crossword-input-fields-group-wrapper");const i=document.createElement("div");i.classList.add("h5p-crossword-input-fields-group-wrapper-clue"),o.appendChild(i);const r=document.createElement("div");r.classList.add("h5p-crossword-input-fields-group-clue-id"),r.innerText=t.clueId,i.appendChild(r);const l=document.createElement("div");l.classList.add("h5p-crossword-input-fields-group-clue-content"),i.appendChild(l);const a=document.createElement("span");a.classList.add("h5p-crossword-input-fields-group-clue"),a.innerText=t.clue,l.appendChild(a);const c=document.createElement("span");if(c.classList.add("h5p-crossword-input-fields-group-answer-length"),c.innerText=`(${t.answer.split(" ").map((t=>t.length)).join(",")})`,l.appendChild(c),t.extraClue){const e=t.extraClue.library?t.extraClue.library.split(" ")[0]:null;if(e){const s=document.createElement("div");s.classList.add("h5p-crossword-extra-clue-instance-wrapper");const o=document.createElement("button");o.classList.add("h5p-crossword-input-fields-group-extra-clue");const n={clueId:t.clueId,orientation:t.orientation,clue:t.clue};o.setAttribute("aria-label",this.params.a11y.extraClueFor.replace("@clue",this.buildAriaLabel(n))),o.setAttribute("title",this.params.l10n.extraClue),l.appendChild(o),o.addEventListener("click",(()=>{this.disabled||(this.disable(),"H5P.Video"===e?t.extraClue.params.fit=!1:"H5P.Audio"===e&&(t.extraClue.params.playerMode="full",t.extraClue.params.fitToWrapper=!0),this.overlay.setContent(s),this.previousFocus=o,this.overlay.show(),this.extraClueInstance=H5P.newRunnable(t.extraClue,this.params.contentId,H5P.jQuery(s)))})),this.extraClues.push(o)}}const h=document.createElement("input");h.classList.add("h5p-crossword-input-fields-group-input");const u={clueId:t.clueId,orientation:t.orientation,clue:t.clue,length:t.answer.length};h.setAttribute("aria-label",this.buildAriaLabel(u)),h.setAttribute("autocomplete","off"),h.setAttribute("autocorrect","off"),h.setAttribute("maxLength",t.answer.length),h.setAttribute("spellcheck","false"),this.setInputFieldValue(h,""),o.appendChild(h),h.addEventListener("focus",(()=>{this.disabled||setTimeout((()=>{this.callbacks.onFieldInput({clueId:t.clueId,orientation:t.orientation,cursorPosition:Math.min(h.selectionStart,t.answer.length-1),text:h.value,readOffset:-1})}),0)})),h.addEventListener("keydown",(e=>{if(-1!==s.CONTROL_KEY_CODES.indexOf(e.keyCode))return;const o=h.selectionStart;h.value=`${h.value.substr(0,o+1)}${h.value.substr(o+1)}`,h.selectionEnd=o+1;const n=s.toUpperCase(h.value,s.UPPERCASE_EXCEPTIONS);clearTimeout(this.tableUpdateTimeout),this.tableUpdateTimeout=setTimeout((()=>{const e=this.applySamsungWorkaround(n,s.toUpperCase(h.value,s.UPPERCASE_EXCEPTIONS));this.setInputFieldValue(h,e),h.setSelectionRange(o+1,o+1),this.callbacks.onFieldInput({clueId:t.clueId,orientation:t.orientation,cursorPosition:Math.min(o+1,t.answer.length-1),text:e,readOffset:-1})}),0)}),!1),h.addEventListener("keyup",(e=>{if(229===e.keyCode)return;if(-1!==s.CONTROL_KEY_CODES.indexOf(e.keyCode)&&-1===[8,35,36,37,38,39,40,46].indexOf(e.keyCode))return;let o=h.selectionStart;"Home"===e.code||"ArrowUp"===e.code?o=0:"End"!==e.code&&"ArrowDown"!==e.code||(o=Math.min(h.value.length,h.getAttribute("maxLength")-1)),this.setInputFieldValue(h,h.value),h.setSelectionRange(o,o),this.callbacks.onFieldInput({clueId:t.clueId,orientation:t.orientation,cursorPosition:o,text:h.value,readOffset:-1===[8,37,38,39,40,46].indexOf(e.keyCode)?1:0})})),h.addEventListener("paste",(t=>{if(this.disabled)return;t.preventDefault();const e=t.clipboardData.getData("text");this.setInputFieldValue(h,e.substr(0,h.getAttribute("maxLength")))}));const d=this.params.a11y.resultFor.replace("@clue",`${t.clueId} ${this.params.a11y[t.orientation]}. ${t.clue} .`),p=new n({a11y:{listLabel:d}});o.appendChild(p.getDOM()),this.inputFields.push({clue:i,inputField:h,orientation:t.orientation,clueId:t.clueId,solution:p}),e.appendChild(o)})),e},e.applySamsungWorkaround=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"",e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"";for(;t.length=0;n--)t[n]===e[n]?o[n]=s.CHARACTER_PLACEHOLDER:n+1=0;e--){let r;o[e]!==s.CHARACTER_PLACEHOLDER&&(i=s.CHARACTER_PLACEHOLDER),r=o[e]!==s.CHARACTER_PLACEHOLDER?o[e]:t[e]!==s.CHARACTER_PLACEHOLDER?t[e]:i,n[e]=r}return n.join("").trimRight()},e.setInputFieldValue=function(t,e){let o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{forceValue:!0};e=s.toUpperCase(e,s.UPPERCASE_EXCEPTIONS);let n="";if(o.forceValue){n=e;const o=new Array(t.maxLength+1).join(s.CHARACTER_PLACEHOLDER);n=o.split("").map(((t,e)=>n.length>e&&" "!==n[e]?n[e]:t)).join("")}else for(let t of e.split("")){if(" "===t)break;n=`${n}${t}`}t.value=s.toUpperCase(n,s.UPPERCASE_EXCEPTIONS)},e.buildAriaLabel=function(t){const e=[`${t.clueId} ${this.params.a11y[t.orientation]}. ${t.clue}`];return t.length&&e.push(this.params.a11y.lettersWord.replace("@length",t.length)),e.join(", ")},e.fillFields=function(t){t.forEach((t=>{const e=this.inputFields.filter((e=>e.orientation===t.orientation&&e.clueId===t.clueId));e.length>0&&this.setInputFieldValue(e[0].inputField,t.text)}))},e.focusClue=function(t){this.inputFields.forEach((t=>{t.clue.classList.remove("h5p-crossword-input-fields-group-clue-highlight-focus")}));const e=this.inputFields.filter((e=>e.orientation===t.orientation&&e.clueId===t.clueId));e.length>0&&e[0].clue.classList.add("h5p-crossword-input-fields-group-clue-highlight-focus")},e.checkAnswerWords=function(t){this.scorePoints=this.scorePoints||new H5P.Question.ScorePoints,this.inputFields.forEach((e=>{e.solution.show();const o=t.filter((t=>t.clueId===e.clueId&&t.orientation===e.orientation)).shift();let n,i;const r=[];r.push(o.answer),-1===o.score?(n=this.scorePoints.getElement(!1),i="wrong",r.push(this.params.a11y.wrong),r.push(`-1 ${this.params.a11y.point}`)):1===o.score?(n=this.scorePoints.getElement(!0),i="correct",r.push(this.params.a11y.correct),r.push(`1 ${this.params.a11y.point}`)):i="neutral",e.solution.setChars([{ariaLabel:`${r.join(". ")}.`,char:e.inputField.value.replace(s.CHARACTER_PLACEHOLDER," "),result:i,scoreExplanation:n}])}))},e.checkAnswer=function(t){this.scorePoints=this.scorePoints||new H5P.Question.ScorePoints;const e=[];this.inputFields.forEach((o=>{o.solution.show();const n=t.filter((t=>"across"===o.orientation?t.clueIdAcross===o.clueId:"down"===o.orientation&&t.clueIdDown===o.clueId));let i=s.toUpperCase(o.inputField.value,s.UPPERCASE_EXCEPTIONS).split(""),r=[];n.forEach(((t,o)=>{const l=e.some((e=>e.row===t.position.row&&e.column===t.position.column));e.push(t.position);const a=i.length>o?i[o]:" ";let c,h;t.answer&&""!==t.answer.trim()&&t.answer!==s.CHARACTER_PLACEHOLDER?t.answer===t.solution?(c="correct",l||(h=this.scorePoints.getElement(!0))):this.params.applyPenalties?(c="wrong",l||(h=this.scorePoints.getElement(!1))):c="neutral":c="neutral";const u=[];u.push(`${this.params.a11y.letterSevenOfNine.replace("@position",o+1).replace("@length",n.length)}`),u.push(t.answer&&""!==t.answer.trim()?t.answer:this.params.a11y.empty),"correct"===c?(u.push(this.params.a11y.correct),u.push(`1 ${this.params.a11y.point}`)):"wrong"===c&&(u.push(this.params.a11y.wrong),u.push(`-1 ${this.params.a11y.point}`)),r.push({ariaLabel:`${u.join(". ")}.`,char:a.replace(s.CHARACTER_PLACEHOLDER," ")||" ",result:c,scoreExplanation:h})})),o.solution.setChars(r)}))},e.showSolutions=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];this.inputFields.forEach((e=>{let s=t.filter((t=>t.clueId===e.clueId&&t.orientation===e.orientation));if(!s||0===s.length)return;s=s[0],this.setInputFieldValue(e.inputField,s.answer),e.inputField.readOnly=!0,e.inputField.removeAttribute("disabled");const o=this.params.a11y.solutionFor.replace("@clue",`${s.clueId} ${this.params.a11y[s.orientation]}. ${s.clue} .`).replace("@solution",s.answer);e.inputField.setAttribute("aria-label",o),e.solution.disable()}))},e.reset=function(){this.inputFields.forEach((t=>{this.setInputFieldValue(t.inputField,""),t.inputField.readOnly=!1,t.clue.classList.remove("h5p-crossword-input-fields-group-clue-highlight-focus"),t.solution.hide(),t.solution.reset()}))},e.resize=function(){this.extraClueInstance&&this.extraClueInstance.trigger("resize"),this.overlay.resize()},e.enable=function(){this.inputFields.forEach((t=>{t.inputField.removeAttribute("disabled")})),this.extraClues.forEach((t=>{t.removeAttribute("disabled")})),this.content.classList.remove("h5p-crossword-disabled"),this.disabled=!1},e.disable=function(){this.disabled=!0,this.extraClues.forEach((t=>{t.setAttribute("disabled",!0)})),this.content.classList.add("h5p-crossword-disabled"),this.inputFields.forEach((t=>{t.inputField.setAttribute("disabled",!0)}))},e.unhighlight=function(){this.inputFields.forEach((t=>{t.clue.classList.remove("h5p-crossword-input-fields-group-clue-highlight-focus")}))},e.handleOverlayClosed=function(){this.extraClueInstance&&"function"==typeof this.extraClueInstance.pause&&this.extraClueInstance.pause(),this.overlay.hide(),this.enable(),this.previousFocus&&this.previousFocus.focus(),this.previousFocus=null},t}(),r=function(){function t(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};this.params=s.extend({instantFeedback:!1,clueIdMarker:null,solution:null},t),this.callbacks=e||{},this.callbacks.onClick=e.onClick||(()=>{}),this.callbacks.onFocus=e.onFocus||(()=>{}),this.callbacks.onKeyup=e.onKeyup||(()=>{}),this.callbacks.onRead=e.onRead||(()=>{}),this.enabled=!0,this.previousTabIndex=null,this.position={row:t.row,column:t.column},this.solutionWordId=null,this.cell=this.buildCell(t);const o=this.buildCellContentWrapper();if(this.cell.appendChild(o),this.params.solution?(this.cellInput=this.buildCellInput(t),o.appendChild(this.cellInput),this.cellCanvas=this.buildCellCanvas(),o.appendChild(this.cellCanvas),this.cell.addEventListener("click",(()=>{this.enabled&&(this.callbacks.onClick(this.position),this.focus())}))):(this.cell.classList.add("h5p-crossword-cell-empty"),this.cell.setAttribute("aria-label",this.params.a11y.empty),this.params.hasBackgroundImage||(this.cell.style.backgroundColor=this.params.theme.backgroundColor)),this.params.clueIdMarker){const t=document.createElement("div");t.classList.add("h5p-crossword-cell-clue-id-marker"),t.innerText=this.params.clueIdMarker,o.appendChild(t)}}var e=t.prototype;return e.getDOM=function(){return this.cell},e.buildCell=function(t){const e=document.createElement("td");return e.classList.add("h5p-crossword-cell"),e.style.width=`${t.width}%`,e.setAttribute("role","gridcell"),e.dataset.col=t.column,e.dataset.row=t.row,e},e.buildCellContentWrapper=function(){const t=document.createElement("div");return t.classList.add("h5p-crossword-cell-content-wrapper"),t},e.buildCellCanvas=function(){const t=document.createElement("div");return t.classList.add("h5p-crossword-cell-canvas"),t},e.buildCellInput=function(){const t=document.createElement("input");return t.classList.add("h5p-crossword-cell-content"),t.setAttribute("type","text"),t.setAttribute("maxLength",1),t.setAttribute("autocomplete","new-password"),t.setAttribute("autocorrect","off"),t.setAttribute("spellcheck","false"),t.setAttribute("tabindex","-1"),t.addEventListener("input",(t=>{if(!this.enabled)return;this.setAnswer(s.toUpperCase(t.data,s.UPPERCASE_EXCEPTIONS),!0),this.cellInput.value="";const e=this.getInformation();this.callbacks.onKeyup(e),t.preventDefault()})),t.addEventListener("change",(t=>{t.preventDefault()})),t.addEventListener("keydown",(t=>{if(this.enabled)if(t.repeat)t.preventDefault();else if(t.key&&"Unidentified"!==t.key&&("Delete"===t.key||"Backspace"===t.key)){const t=this.getAnswer()?0:-1;this.setAnswer("");const e=this.getInformation();e.keepPosition=!0,e.nextPositionOffset=t,this.cellInput.value="",this.callbacks.onKeyup(e)}})),t.addEventListener("keyup",(t=>{if(this.enabled&&(!t.key||"Unidentified"===t.key))if(t.repeat)t.preventDefault();else if(-1!==s.CONTROL_KEY_CODES.indexOf(t.keyCode)&&(8===t.keyCode||46===t.keyCode)){const t=this.getAnswer()?0:-1;this.setAnswer("");const e=this.getInformation();e.keepPosition=!0,e.nextPositionOffset=t,this.cellInput.value="",this.callbacks.onKeyup(e)}})),t.addEventListener("focus",(t=>{this.callbacks.onFocus(this.position,t)})),t},e.getSolution=function(){return this.params.solution},e.getCurrentAnswer=function(){return this.cell.innerText.substr(0,1)},e.getInformation=function(){return{answer:this.answer?s.toUpperCase(this.answer,s.UPPERCASE_EXCEPTIONS):this.answer,clueIdAcross:this.params.clueIdAcross,clueIdDown:this.params.clueIdDown,position:this.position,score:this.getScore(),solution:this.params.solution,solutionWordId:this.solutionWordId||null}},e.getPosition=function(){return this.position},e.getClueId=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"across";return"down"===t?this.params.clueIdDown:"across"===t?this.params.clueIdAcross:null},e.getAnswer=function(){return this.answer},e.getScore=function(){if(this.params.solution&&(" "!==this.params.solution||this.answer&&""!==this.answer.trim()&&this.answer!==s.CHARACTER_PLACEHOLDER))return this.answer&&""!==this.answer.trim()?this.answer!==this.params.solution?this.params.applyPenalties?-1:0:1:0},e.isFilled=function(){return this.params.solution?" "===this.params.solution?null:!(!this.answer||" "===this.answer):null},e.setTabIndex=function(t){isNaN(parseInt(t))||(this.cellInput?this.cellInput.setAttribute("tabindex",t):this.cell.setAttribute("tabindex",t))},e.setAriaLabel=function(t){this.cellInput.setAttribute("aria-label",t)},e.setSolutionState=function(t){if(this.cell.classList.remove("h5p-crossword-solution-correct"),this.cell.classList.remove("h5p-crossword-solution-wrong"),this.cell.classList.remove("h5p-crossword-solution-neutral"),t){const e="h5p-crossword-solution"+(t?`-${t}`:"");this.cell.classList.add(e)}},e.setAnswer=function(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.cellInput&&(""===t?(this.cellCanvas.innerText="",this.answer=void 0):(this.cellCanvas.innerText=s.toUpperCase(t.replace(new RegExp(s.CHARACTER_PLACEHOLDER,"g")," "),s.UPPERCASE_EXCEPTIONS),this.answer=s.toUpperCase(t,s.UPPERCASE_EXCEPTIONS)),this.params.instantFeedback&&this.checkAnswer(e))},e.setWidth=function(t){"number"!=typeof t||t<=0||(this.cell.style.width=`${t}px`)},e.focus=function(){setTimeout((()=>{this.cellInput?this.cellInput.focus():this.cell.focus()}),0)},e.highlight=function(t){if(!this.getSolution()&&"focus"!==t)return;const e="h5p-crossword-highlight"+(t?`-${t}`:"");this.cell.classList.add(e)},e.unhighlight=function(t){if(t){const e="h5p-crossword-highlight"+(t?`-${t}`:"");this.cell.classList.remove(e)}else this.cell.classList.remove("h5p-crossword-highlight-normal"),this.cell.classList.remove("h5p-crossword-highlight-focus")},e.showSolutions=function(){this.params.solution&&(this.setAnswer(this.params.solution),this.setSolutionState())},e.checkAnswer=function(){let t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];const e=(this.answer||"").trim();e===this.params.solution&&""!==e?(this.setSolutionState("correct"),t&&this.callbacks.onRead(this.params.a11y.correct)):""===e||e===s.CHARACTER_PLACEHOLDER?this.setSolutionState():this.params.applyPenalties?(this.setSolutionState("wrong"),t&&this.callbacks.onRead(this.params.a11y.wrong)):(this.setSolutionState("neutral"),t&&this.callbacks.onRead(this.params.a11y.wrong))},e.reset=function(){this.setAnswer("",!1),this.unhighlight(),this.setSolutionState()},e.enable=function(){this.cellInput&&(this.previousTabIndex&&this.cell.setAttribute("tabindex",this.previousTabIndex),this.cellInput.removeAttribute("disabled")),this.enabled=!0},e.disable=function(){this.enabled=!1,this.cellInput&&this.cellInput.setAttribute("disabled","disabled"),this.previousTabIndex=this.cell.getAttribute("tabindex"),this.cell.removeAttribute("tabindex")},e.addSolutionWordIdMarker=function(t){t&&(this.solutionWordMarker=document.createElement("div"),this.solutionWordMarker.classList.add("h5p-crossword-cell-solution-word-marker"),this.solutionWordMarker.innerText=t,this.cell.insertBefore(this.solutionWordMarker,this.cell.firstChild),this.solutionWordCircle=document.createElement("div"),this.solutionWordCircle.classList.add("h5p-crossword-cell-solution-word-circle"),this.cell.insertBefore(this.solutionWordCircle,this.cell.firstChild),this.solutionWordId=t)},t}(),l=function(){function t(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1?arguments[1]:void 0;this.params=s.extend({},t),this.params.theme.backgroundImage=this.params.theme.backgroundImage||null,this.callbacks=e||{},this.callbacks.onInput=this.callbacks.onInput||(()=>{}),this.callbacks.onFocus=this.callbacks.onFocus||(()=>{}),this.callbacks.onRead=e.onRead||(()=>{}),this.currentPosition={},this.currentOrientation="across",this.maxScore=null,this.cells=this.buildCells(this.params.dimensions,this.params.words),this.content=this.buildGrid(this.params),[].concat(...this.cells).filter((t=>null!==t.getSolution()))[0].setTabIndex("0"),this.content.addEventListener("keydown",(t=>{if(this.disabled)return;let e,s,o=t.target;switch(t.target.classList.contains("h5p-crossword-cell-content")&&(o=t.target.parentNode.parentNode),t.key){case"ArrowRight":t.preventDefault(),this.setcurrentOrientation("across",{row:parseInt(o.dataset.row),column:parseInt(o.dataset.col)+1}),this.moveTo({row:parseInt(o.dataset.row),column:parseInt(o.dataset.col)+1});break;case"ArrowLeft":t.preventDefault(),this.setcurrentOrientation("across",{row:parseInt(o.dataset.row),column:parseInt(o.dataset.col)-1}),this.moveTo({row:parseInt(o.dataset.row),column:parseInt(o.dataset.col)-1});break;case"ArrowDown":t.preventDefault(),this.setcurrentOrientation("across",{row:parseInt(o.dataset.row)+1,column:parseInt(o.dataset.col)}),this.moveTo({row:parseInt(o.dataset.row)+1,column:parseInt(o.dataset.col)});break;case"ArrowUp":t.preventDefault(),this.setcurrentOrientation("across",{row:parseInt(o.dataset.row)-1,column:parseInt(o.dataset.col)}),this.moveTo({row:parseInt(o.dataset.row)-1,column:parseInt(o.dataset.col)});break;case"Home":t.preventDefault(),t.ctrlKey?this.moveTo({row:0,column:0}):this.moveTo({row:parseInt(o.dataset.row),column:0});break;case"End":t.preventDefault(),t.ctrlKey?this.moveTo({row:this.params.dimensions.rows-1,column:this.params.dimensions.columns-1}):this.moveTo({row:parseInt(o.dataset.row),column:document.querySelector('[data-row="'+o.dataset.row+'"]:last-of-type').dataset.col});break;case"PageUp":t.preventDefault(),e=0;do{s=this.moveTo({row:e,column:o.dataset.col}),e++}while(!1===s);break;case"PageDown":t.preventDefault(),e=this.params.dimensions.rows-1;do{s=this.moveTo({row:e,column:o.dataset.col}),e--}while(!1===s)}}))}var e=t.prototype;return e.getDOM=function(){return this.content},e.buildCells=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];const o=s.createArray(t.rows,t.columns);for(let e=0;e{let e=t.starty-1,s=t.startx-1;for(let n=0;n{n[e.row][e.column]=new r({row:e.row,column:e.column,solution:e.solution,solutionIndex:e.solutionIndex,solutionLength:e.solutionLength,width:100/t.columns,clueIdMarker:e.clueIdMarker,clue:e.clue,clueIdAcross:e.clueIdAcross,clueIdDown:e.clueIdDown,instantFeedback:this.params.instantFeedback,applyPenalties:this.params.applyPenalties,hasBackgroundImage:!!this.params.theme.backgroundImage,theme:this.params.theme,a11y:{correct:this.params.a11y.correct,wrong:this.params.a11y.wrong,empty:this.params.a11y.empty}},{onClick:t=>{this.handleCellClick(t)},onFocus:(t,e)=>{this.handleCellFocus(t,e)},onKeyup:t=>{this.handleCellKeyup(t)},onRead:t=>{this.callbacks.onRead(t)}})})),n},e.findSolutionWordCells=function(t){if(!t||""===t)return[];const e=[];let o=!0,n=[].concat(...this.cells).filter((t=>null!==t.getSolution()));return t.split("").forEach((t=>{if(!1===o)return;const i=s.shuffleArray(n.filter((s=>s.getSolution()===t&&-1===e.indexOf(s))));0!==i.length?e.push(i[0]):o=!1})),e.length===t.length?e:[]},e.addSolutionWord=function(t){if(!t||""===t)return!1;const e=this.findSolutionWordCells(t);return e.forEach(((t,e)=>{t.addSolutionWordIdMarker(e+1)})),e.length>0},e.buildGrid=function(t){const e=document.createElement("table");if(e.classList.add("h5p-crossword-grid"),e.style.backgroundColor=t.theme.backgroundColor,e.style.maxWidth=`calc(2 * ${t.dimensions.columns} * 32px)`,t.theme.backgroundImage){e.classList.add("h5p-crossword-grid-background-image");const s=document.createElement("img");H5P.setSource(s,t.theme.backgroundImage,t.contentId),e.style.backgroundImage=`url('${s.src}')`}e.setAttribute("role","grid"),e.setAttribute("aria-label",this.params.a11y.crosswordGrid);const s=document.createElement("tbody");s.setAttribute("role","rowgroup");for(let e=0;e0&&void 0!==arguments[0]?arguments[0]:{},e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(t.row<0||t.row>this.params.dimensions.rows-1)return!1;if(t.column<0||t.column>this.params.dimensions.columns-1)return!1;if(null===this.cells[t.row][t.column].getSolution())return!1;const s=this.cells[t.row][t.column];return!!s&&([].concat(...this.cells).forEach((t=>{t.setTabIndex("-1")})),s.setTabIndex("0"),this.currentPosition=t,this.focusCell(t,e),!0)},e.getUpdates=function(t){const e=[],s="across"===this.currentOrientation?"down":"across",o=this.cells[t.row][t.column].getClueId(s);if(o){const t=[].concat(...this.cells).filter((t=>t.getClueId(s)===o)).reduce(((t,e)=>t+(e.answer||" ")),"").replace(/[\s\uFEFF\xA0]+$/g,"");e.push({clueId:o,orientation:s,text:t})}const n=this.cells[t.row][t.column].getClueId(this.currentOrientation),i=[].concat(...this.cells).filter((t=>t.getClueId(this.currentOrientation)===n)).reduce(((t,e)=>t+(e.answer||" ")),"").replace(/[\s\uFEFF\xA0]+$/g,"");return e.push({clueId:n,orientation:this.currentOrientation,text:i}),e},e.getAnswers=function(){return[].concat(...this.cells).map((t=>t.getAnswer()))},e.setAnswers=function(t){[].concat(...this.cells).forEach(((e,s)=>{if(e.setAnswer(t[s]||""),e.getSolution()){const t=e.getInformation();this.callbacks.onInput({answer:t.answer,inputFieldUpdates:this.getUpdates(t.position),clueId:t.clueId,solutionWordId:t.solutionWordId||null,checkFilled:!0})}}))},e.getScore=function(){let t;return t=this.params.scoreWords?this.params.words.reduce(((t,e)=>t+this.getWordScore(e.clueId,e.orientation)),0):[].concat(...this.cells).reduce(((t,e)=>t+(e.getScore()||0)),0),Math.max(0,t)},e.getMaxScore=function(){return this.params.scoreWords?this.maxScore=this.params.words.length:this.maxScore=this.maxScore||[].concat(...this.cells).reduce(((t,e)=>t+(void 0!==e.getScore()?1:0)),0),this.maxScore},e.getWordScore=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"across";const s=this.getWordInformation(t,e),o=s.reduce(((t,e)=>{if(-1===t||-1===e.score)return-1;return t+(1===e.score||void 0===e.score?1:0)}),0);return-1===o?-1:o===s.length?1:0},e.setcurrentOrientation=function(t,e){if("across"!==t&&"down"!==t)return;if("number"!=typeof(e=e||this.currentPosition).row||"number"!=typeof e.column)return;if(e.row<0||e.row>this.params.dimensions.rows-1)return;if(e.column<0||e.column>this.params.dimensions.columns-1)return;if(!this.cells[e.row][e.column].getSolution())return;const s=e.column>0&&this.cells[e.row][e.column-1].getSolution(),o=e.column0&&this.cells[e.row-1][e.column].getSolution(),i=e.row{t.reset()})),this.currentPosition={},this.currentOrientation="across",this.maxScore=null},e.resize=function(){const t=this.content.clientWidth/this.params.dimensions.columns;this.content.style.fontSize=t/2+"px"},e.handleCellClick=function(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];if(this.ignoreNextClick)return void(this.ignoreNextClick=!1);const s=this.cells[t.row][t.column];s.getSolution()&&(e||(s.getClueId("across")?this.currentPosition.row===t.row&&this.currentPosition.column===t.column&&"across"===this.currentOrientation?this.setcurrentOrientation("down",t):this.setcurrentOrientation("across",t):this.setcurrentOrientation("down",t)),this.currentPosition=t,this.moveTo(t,!0))},e.handleCellFocus=function(t,e){this.cells[t.row][t.column].getSolution()&&(e.relatedTarget&&(e.relatedTarget.classList.contains("h5p-crossword-cell")||e.relatedTarget.classList.contains("h5p-crossword-cell-content"))||(this.setcurrentOrientation(this.currentOrientation,t),this.handleCellClick(t,!0),this.ignoreNextClick="boolean"!=typeof this.ignoreNextClick||this.ignoreNextClick))},e.handleCellKeyup=function(t){void 0===t.nextPositionOffset&&(t.nextPositionOffset=1),(!this.currentOrientation||"across"===this.currentOrientation)&&t.position.column+t.nextPositionOffset>=0&&t.position.column+t.nextPositionOffset=0&&t.position.row+t.nextPositionOffset{t.showSolutions()}))},e.checkAnswerWords=function(){const t=this.params.words.map((t=>({clueId:t.clueId,orientation:t.orientation,answer:t.answer,score:this.getWordScore(t.clueId,t.orientation)})));return[].concat(...this.cells).forEach((t=>{t.checkAnswer()})),t},e.checkAnswer=function(){const t=[];return[].concat(...this.cells).forEach((e=>{e.checkAnswer();const s=e.getInformation();s.solution&&t.push(s)})),t},e.highlightWord=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"across";const s=this.cells[t.row][t.column].getClueId(e);if(!s)return;const o=this.params.words.filter((t=>t.clueId===s&&t.orientation===e))[0];[].concat(...this.cells).filter((t=>t.getClueId(e)===s)).forEach(((t,n)=>{const i=t.getPosition(),r={row:i.row,column:i.column,clueId:s,orientation:e,clue:o.clue,position:n,length:o.answer.length};t.setAriaLabel(this.buildAriaLabel(r)),t.highlight("normal")}))},e.buildAriaLabel=function(t){return`${`${this.params.a11y.row} ${t.row+1}, ${this.params.a11y.column} ${t.column+1}`}. ${`${t.clueId} ${this.params.a11y[t.orientation]}. ${t.clue}`}, ${`${this.params.a11y.letterSevenOfNine.replace("@position",t.position+1).replace("@length",t.length)}`}.`},e.getFocus=function(){return{position:this.currentPosition,orientation:this.currentOrientation}},e.getWordInformation=function(t){let e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"across";return t?[].concat(...this.cells).filter((s=>s.getClueId(e)===t)).map((t=>t.getInformation())):""},e.focusCell=function(t){let e=arguments.length>1&&void 0!==arguments[1]&&arguments[1];this.clearCellHighlights(),this.setcurrentOrientation(this.currentOrientation,t),this.highlightWord(t,this.currentOrientation),this.cells[t.row][t.column].highlight("focus"),this.callbacks.onFocus({clueId:this.cells[t.row][t.column].getClueId(this.currentOrientation),orientation:this.currentOrientation}),e||this.cells[t.row][t.column].focus()},e.clearCellHighlights=function(){[].concat(...this.cells).forEach((t=>{t.unhighlight()}))},e.fillGrid=function(t){const e=[].concat(...this.cells).filter((e=>e.getClueId(t.orientation)===t.clueId));if(e.forEach(((e,s)=>{if(e.setAnswer(t.text[s]||"",-1!==t.readOffset&&s===t.cursorPosition-t.readOffset),e.getClueId("down")&&e.getClueId("across")){const s="across"===t.orientation?this.getWordInformation(e.getClueId("down"),"down"):this.getWordInformation(e.getClueId("across"),"across"),o=[{clueId:"across"===t.orientation?e.getClueId("down"):e.getClueId("across"),orientation:"across"===t.orientation?"down":"across",text:s.reduce(((t,e)=>`${t}${e.answer||" "}`),"")}];this.callbacks.onInput({inputFieldUpdates:o})}const o=e.getInformation();o.solutionWordId&&this.callbacks.onInput(o)})),t.cursorPosition{t.enable()})),this.disabled=!1},e.disable=function(){this.disabled=!0,[].concat(...this.cells).forEach((t=>{t.disable()}))},e.isFilled=function(){return![].concat(...this.cells).some((t=>!1===t.isFilled()))},e.unhighlight=function(){[].concat(...this.cells).forEach((t=>{t.unhighlight("focus"),t.unhighlight("normal"),this.params.instantFeedback||t.setSolutionState()}))},e.getXAPICorrectResponsesPattern=function(){return[`{case_matters=false}${this.params.words.map((t=>{const e=this.getWordInformation(t.clueId,t.orientation).map((t=>t.solution));return this.params.scoreWords?e.join(""):e.join("[,]")})).join("[,]")}`]},e.getXAPIResponse=function(){return this.params.words.map((t=>{const e=this.getWordInformation(t.clueId,t.orientation);return this.params.scoreWords?e.map((t=>t.answer||" ")).join(""):e.map((t=>t.answer||"")).join("[,]")})).join("[,]")},e.getXAPIDescription=function(){return this.params.words.map((e=>{const s=`${e.clueId} ${this.params.l10n[e.orientation]}: ${e.clue.replaceAll(/_{10,}/gi,"_________")}`,o=[];if(this.params.scoreWords)o.push(t.XAPI_PLACEHOLDER);else for(;o.length${s} br>${o.join(" ")}`})).join("")},t}();l.XAPI_PLACEHOLDER="__________";let a=function(){function t(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.solutionWord=s.toUpperCase(t.solutionWord.replace(/\s/g,""),s.UPPERCASE_EXCEPTIONS),this.scaleWidth=Math.max(t.tableWidth,this.solutionWord.length),this.cells=this.createCells(this.solutionWord),this.content=this.createSolution(this.cells)}var e=t.prototype;return e.getDOM=function(){return this.content},e.createSolution=function(t){const e=document.createElement("div");e.classList.add("h5p-crossword-solution-word-wrapper");const s=document.createElement("table");s.classList.add("h5p-crossword-solution-word"),s.setAttribute("aria-hidden",!0),e.appendChild(s);const o=document.createElement("tr");return t.forEach((t=>{o.appendChild(t.getDOM())})),s.appendChild(o),e},e.createCells=function(t){const e=s.createArray(t.length);return t.split("").forEach(((s,o)=>{e[o]=new r({width:100/t.length,solution:t[o],clueIdMarker:o+1}),e[o].disable()})),e},e.setCell=function(t,e){this.cells[t].setAnswer(e||"")},e.showSolutions=function(){this.cells.forEach((t=>{t.showSolutions()}))},e.reset=function(){this.cells.forEach((t=>{t.reset()}))},e.resize=function(){const t=this.content.clientWidth/this.scaleWidth;this.content.style.fontSize=t/2+"px",this.cells.forEach((e=>{e.setWidth(t)}))},t}(),c=function(){function t(e){this.params=s.extend({words:[{answer:"BAT",clue:"BAT"},{answer:"CAT",clue:"CAT"}],config:{poolSize:0}},e||{}),this.params.words=this.params.words.filter((t=>t.answer&&t.clue)).map((t=>{const e={answer:s.toUpperCase(t.answer,s.UPPERCASE_EXCEPTIONS),clue:t.clue,extraClue:t.extraClue};return t.fixWord&&void 0!==t.row&&void 0!==t.column&&void 0!==t.orientation&&(e.row=t.row-1,e.column=t.column-1,e.orientation=t.orientation),e})),this.indexChar={},this.badWords=[],this.cells=s.createArray(t.GRID_ROWS,t.GRID_COLUMNS),this.wordElements=this.createWordElements(this.params.words,this.params.config.poolSize)}var e=t.prototype;return e.getSquareGrid=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10,e=null,s=0;for(let o=0;os&&(e=t,s=o),1===s)break}return e},e.getGrid=function(){let t,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:10;for(let s=0;svoid 0!==t.row));if(e.length>0){if(e.forEach((t=>{if(!1===this.canPlaceAnswerAt(t.answer,{row:t.row,column:t.column,orientation:t.orientation})){return this.badWords.some((e=>Object.keys(e).every((s=>e[s]===t[s]))))||this.badWords.push(t),null}this.placeAnswerAt(t,{row:t.row,column:t.column,orientation:t.orientation})})),e.length>=this.params.config.poolSize||e.length===this.wordElements.length)return this.minimizeGrid()}else{let t=Math.floor(this.cells.length/2),e=Math.floor(this.cells[0].length/2);const s=this.wordElements[0],o=this.getRandomOrientation();if("across"===o?e-=Math.floor(s.answer.length/2):t-=Math.floor(s.answer.length/2),!1===this.canPlaceAnswerAt(s.answer,{row:t,column:e,orientation:o})){return this.badWords.some((t=>Object.keys(t).every((e=>t[e]===s[e]))))||this.badWords.push(s),null}this.placeAnswerAt(s,{row:t,column:e,orientation:o})}this.groups=[],e.length>0?this.groups.push(this.wordElements.slice(e.length)):this.groups.push(this.wordElements.slice(1));for(let e=0;eo&&(o=s),ri&&(i=r))}const r=o-e+1,l=i-n+1,a=s.createArray(r,l);for(let t=e,s=0;s=this.cells.length||e.column<0||e.column>=this.cells[e.row].length)return!1;if("across"===e.orientation){for(let s=0;sthis.cells[e.row].length)return!1;if(e.column-1>=0&&null!==this.cells[e.row][e.column-1])return!1;if(e.column+t.length=0&&othis.cells.length)return!1;if(e.row-1>=0&&null!==this.cells[e.row-1][e.column])return!1;if(e.row+t.length=0&&o(t.index=e,t)));if(e){const t=o.filter((t=>void 0!==t.row)),n=s.shuffleArray(o.filter((t=>void 0===t.row)));n.splice(Math.max(0,e-t.length),n.length),o=t.concat(n)}return o.sort(((t,e)=>{const s=void 0!==t.row?1:0,o=void 0!==e.row?1:0;return so?-1:e.answer.length-t.answer.length}))},e.getWordElement=function(t,e){if("number"!=typeof t)return null;const s=this.wordElements.filter((e=>e.index===t));return s.length<1?null:"string"!=typeof e?s[0]:s[0][e]},e.export=function(t){const e=t.length,s=t[0].length,o=[];let n=1;for(let i=0;i0&&void 0!==arguments[0]?arguments[0]:{},o=arguments.length>1?arguments[1]:void 0;if(this.params=s,this.contentId=s.contentId,this.content=document.createElement("div"),this.content.classList.add("h5p-crossword-content"),this.callbacks=o||{},this.callbacks.onInitialized=o.onInitialized||(()=>{}),this.callbacks.onRead=o.onRead||(()=>{}),this.callbacks.onTableFilled=o.onTableFilled||(()=>{}),this.answerGiven=!1,this.params.previousState&&this.params.previousState.crosswordLayout)this.crosswordLayout=this.params.previousState.crosswordLayout;else{const t=[];let o,n;s.words.length<2?t.push(s.l10n.couldNotGenerateCrosswordTooFewWords):(o=new c({words:s.words,config:{poolSize:s.poolSize}}),n=o.getSquareGrid(e.MAXIMUM_TRIES),n||t.push(s.l10n.couldNotGenerateCrossword));let i=o?.getBadWords();if(i?.length&&(i=i.map((t=>`${t.answer}`)).join(", "),t.push(s.l10n.problematicWords.replace(/@words/g,i))),t.length,!n){const e=document.createElement("div");return e.classList.add("h5p-crossword-message"),e.innerText=t.join(" "),this.content.appendChild(e),this.couldNotGenerateCrossword=!0,void this.callbacks.onInitialized(!1)}this.crosswordLayout=o.export(n)}const n=document.createElement("div");n.classList.add("h5p-crossword-table-wrapper"),this.clueAnnouncer=new t,n.appendChild(this.clueAnnouncer.getDOM()),this.table=new l({scoreWords:this.params.scoreWords,applyPenalties:this.params.applyPenalties,theme:this.params.theme,contentId:this.contentId,dimensions:{rows:this.crosswordLayout.rows,columns:this.crosswordLayout.cols},instantFeedback:this.params.instantFeedback,solutionWord:this.params.solutionWord,words:this.crosswordLayout.result,a11y:this.params.a11y,l10n:{across:this.params.l10n.across,down:this.params.l10n.down}},{onInput:t=>{this.handleTableInput(t)},onFocus:t=>{this.handleTableFocus(t)},onRead:t=>{this.callbacks.onRead(t)}}),n.appendChild(this.table.getDOM()),this.content.appendChild(n);const r=this.table.addSolutionWord(this.params.solutionWord);""!==this.params.solutionWord&&r&&(this.solutionWord=new a({solutionWord:this.params.solutionWord,tableWidth:this.crosswordLayout.cols}),n.appendChild(this.solutionWord.getDOM())),this.inputarea=new i({words:this.crosswordLayout.result.filter((t=>"none"!==t.orientation)),contentId:this.contentId,overlayContainer:this.content,applyPenalties:this.params.applyPenalties,l10n:{across:this.params.l10n.across,down:this.params.l10n.down,extraClue:this.params.l10n.extraClue,closeWindow:this.params.l10n.closeWindow},a11y:this.params.a11y},{onFieldInput:t=>{this.handleFieldInput(t)},onRead:t=>{this.callbacks.onRead(t)}}),this.content.appendChild(this.inputarea.getDOM()),this.params.previousState.cells&&(this.table.setAnswers(this.params.previousState.cells),this.answerGiven=!0),this.params.previousState.focus&&this.params.previousState.focus.position&&this.params.previousState.focus.position.row&&(this.table.setcurrentOrientation(this.params.previousState.focus.orientation,this.params.previousState.focus.position),this.table.focusCell(this.params.previousState.focus.position)),this.overrideCSS(this.params.theme),this.callbacks.onInitialized(!0)}var s=e.prototype;return s.getDOM=function(){return this.content},s.resize=function(){this.table&&(this.table.resize(),this.inputarea.resize(),this.solutionWord&&this.solutionWord.resize())},s.getXAPICorrectResponsesPattern=function(){return this.table.getXAPICorrectResponsesPattern()},s.getXAPIResponse=function(){return this.table.getXAPIResponse()},s.getXAPIDescription=function(){return this.table.getXAPIDescription()},s.reset=function(){this.params.words.length<2||(this.table.reset(),this.solutionWord&&this.solutionWord.reset(),this.inputarea.reset(),this.answerGiven=!1)},s.getAnswerGiven=function(){return this.answerGiven},s.getScore=function(){return this.params.words.length<2?0:this.table.getScore()},s.getMaxScore=function(){return this.params.words.length<2?0:this.table.getMaxScore()},s.getCurrentState=function(){if(this.params.words.length<2||!this.table)return;const t=this.table.getAnswers(),e=this.table.getFocus();return t.some((t=>void 0!==t))||void 0!==e.position.row?{crosswordLayout:this.crosswordLayout,cells:t,focus:e}:void 0},s.checkAnswer=function(){if(this.disable(),this.params.scoreWords){const t=this.table.checkAnswerWords();this.inputarea.checkAnswerWords(t)}else{const t=this.table.checkAnswer();this.inputarea.checkAnswer(t)}},s.isTableFilled=function(){return this.table&&this.table.isFilled()},s.showSolutions=function(){this.params.words.length<2||(this.disable(),this.table.showSolutions(),this.solutionWord&&this.solutionWord.showSolutions(),this.inputarea.showSolutions(this.crosswordLayout.result))},s.handleFieldInput=function(t){this.table.fillGrid(t),this.answerGiven=!0},s.handleTableInput=function(t){this.solutionWord&&t.solutionWordId&&this.solutionWord.setCell(t.solutionWordId-1,t.answer),t.inputFieldUpdates&&this.inputarea.fillFields(t.inputFieldUpdates),this.answerGiven=!0,t.checkFilled&&this.isTableFilled()&&this.callbacks.onTableFilled()},s.handleTableFocus=function(t){const e=this.crosswordLayout.result.filter((t=>"none"!==t.orientation)).filter((e=>e.orientation===t.orientation&&e.clueId===t.clueId));e.length>0&&this.clueAnnouncer.setClue({clue:e[0].clue,orientation:this.params.l10n[e[0].orientation],clueId:e[0].clueId,answerLength:e[0].answer.length}),this.inputarea.focusClue(t)},s.enable=function(){this.table.enable(),this.inputarea.enable()},s.disable=function(){this.table.disable(),this.table.unhighlight(),this.inputarea.disable(),this.inputarea.unhighlight(),this.clueAnnouncer.reset()},s.overrideCSS=function(){let t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};t.gridColor&&this.addStyle(`.h5p-crossword .h5p-crossword-grid th, .h5p-crossword .h5p-crossword-grid td,.h5p-crossword .h5p-crossword-grid{border-color:${t.gridColor}};`),t.cellBackgroundColor&&(this.addStyle(`.h5p-crossword .h5p-crossword-cell{background-color:${t.cellBackgroundColor}};`),this.addStyle(`.h5p-crossword .h5p-crossword-cell-clue-id-marker{background-color:${t.cellBackgroundColor}};`)),t.clueIdColor&&this.addStyle(`.h5p-crossword .h5p-crossword-cell-clue-id-marker{color:${t.clueIdColor}};`),t.cellColor&&this.addStyle(`.h5p-crossword .h5p-crossword-cell-canvas{color:${t.cellColor}};`),t.cellBackgroundColorHighlight&&(this.addStyle(`.h5p-crossword .h5p-crossword-cell:not(.h5p-crossword-solution-correct):not(.h5p-crossword-solution-wrong):not(.h5p-crossword-solution-neutral).h5p-crossword-highlight-normal{background-color:${t.cellBackgroundColorHighlight}};`),this.addStyle(`.h5p-crossword .h5p-crossword-cell.h5p-crossword-highlight-normal .h5p-crossword-cell-clue-id-marker, .h5p-crossword .h5p-crossword-cell.h5p-crossword-highlight-normal .h5p-crossword-cell-solution-word-marker{background-color:${t.cellBackgroundColorHighlight}}`),this.addStyle(`.h5p-crossword .h5p-crossword-input-fields-group-wrapper-clue.h5p-crossword-input-fields-group-clue-highlight-focus .h5p-crossword-input-fields-group-clue-id{background-color:${t.cellBackgroundColorHighlight}}`)),t.clueIdColorHighlight&&this.addStyle(`.h5p-crossword .h5p-crossword-cell.h5p-crossword-highlight-normal .h5p-crossword-cell-clue-id-marker, .h5p-crossword .h5p-crossword-cell.h5p-crossword-highlight-normal .h5p-crossword-cell-solution-word-marker{color:${t.clueIdColorHighlight}}`),t.cellColorHighlight&&(this.addStyle(`.h5p-crossword .h5p-crossword-cell.h5p-crossword-highlight-normal .h5p-crossword-cell-canvas{color:${t.cellColorHighlight}};`),this.addStyle(`.h5p-crossword .h5p-crossword-input-fields-group-wrapper-clue.h5p-crossword-input-fields-group-clue-highlight-focus .h5p-crossword-input-fields-group-clue-id{color:${t.cellColorHighlight}}`))},s.addStyle=function(t){const e=document.createElement("style");e.appendChild(document.createTextNode(t)),document.querySelector("head").appendChild(e)},e}();function u(t,e){return u=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},u(t,e)}h.MAXIMUM_TRIES=20;let d=function(t){var e,o;function n(e,o){var n;let i=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};(n=t.call(this,"crossword")||this).params=e,n.contentId=o,n.extras=i,n.params=s.extend({solutionWord:"",theme:{backgroundColor:"#173354"},behaviour:{enableSolutionsButton:!0,enableRetry:!0,enableInstantFeedback:!1,scoreWords:!0,applyPenalties:!1},l10n:{across:"across",down:"down",checkAnswer:"Check answer",couldNotGenerateCrossword:"Could not generate a crossword with the given words. Please try again with fewer words or words that have more characters in common.",couldNotGenerateCrosswordTooFewWords:"Could not generate a crossword. You need at least two words.",problematicWords:"Some words could not be placed. If you are using fixed words, please make sure that their position doesn't prevent other words from being placed. Words with the same alignment may not be placed touching each other. Problematic word(s): @words",showSolution:"Show solution",tryAgain:"Retry",extraClue:"Extra clue",closeWindow:"Close window",submitAnswer:"Submit"},a11y:{crosswordGrid:"Crossword grid. Use arrow keys to navigate and the keyboard to enter characters. Alternatively, use Tab to navigate to type the answers in Fill in the Blanks style fields instead of the grid.",column:"column",row:"row",across:"across",down:"down",empty:"Empty",resultFor:"Result for: @clue",correct:"Correct",wrong:"Wrong",point:"Point",solutionFor:"The solution for @clue is: @solution",extraClueFor:"Open extra clue for @clue",letterSevenOfNine:"Letter @position of @length",lettersWord:"@length letter word",check:"Check the characters. The responses will be marked as correct, incorrect, or unanswered.",showSolution:"Show the solution. The crossword will be filled with its correct solution.",retry:"Retry the task. Reset all responses and start the task over again.",yourResult:"You got @score out of @total points"}},n.params),n.params.theme=n.getDifference(n.params.theme,{gridColor:"#000000",cellBackgroundColor:"#ffffff",cellColor:"#000000",clueIdColor:"#606060",cellBackgroundColorHighlight:"#3e8de8",cellColorHighlight:"#ffffff",clueIdColorHighlight:"#e0e0e0"}),n.initialButtons={check:!n.params.behaviour.enableInstantFeedback,showSolution:n.params.behaviour.enableSolutionsButton,retry:n.params.behaviour.enableRetry};const r=i.metadata&&i.metadata.defaultLanguage||"en";n.languageTag=s.formatLanguageCode(r);for(let t in n.params.l10n)n.params.l10n[t]=s.stripHTML(s.htmlDecode(n.params.l10n[t]));return n.params.a11y.yourResult=n.params.a11y.yourResult.replace(/\.$/,""),n.previousState=n.extras.previousState||{},n.previousState.crosswordLayout&&n.previousState.cells||(n.previousState={}),n.params.words=(n.params.words||[]).filter((t=>void 0!==t.answer&&void 0!==t.clue)).map((t=>(t.answer=s.stripHTML(s.htmlDecode(s.toUpperCase(t.answer,s.UPPERCASE_EXCEPTIONS))),t.clue=s.stripHTML(s.htmlDecode(t.clue)),t))),n}o=t,(e=n).prototype=Object.create(o.prototype),e.prototype.constructor=e,u(e,o);var i=n.prototype;return i.registerDomElements=function(){this.params.taskDescription&&""!==this.params.taskDescription&&(this.introduction=document.createElement("div"),this.introduction.innerHTML=this.params.taskDescription,this.setIntroduction(this.introduction)),this.content=new h({scoreWords:this.params.behaviour.scoreWords,applyPenalties:this.params.behaviour.applyPenalties,theme:this.params.theme,contentId:this.contentId,instantFeedback:this.params.behaviour.enableInstantFeedback,l10n:{couldNotGenerateCrossword:this.params.l10n.couldNotGenerateCrossword,couldNotGenerateCrosswordTooFewWords:this.params.l10n.couldNotGenerateCrosswordTooFewWords,problematicWords:this.params.l10n.problematicWords,across:this.params.l10n.across,down:this.params.l10n.down,extraClue:this.params.l10n.extraClue,closeWindow:this.params.l10n.closeWindow},a11y:this.params.a11y,poolSize:this.params.behaviour.poolSize,solutionWord:s.toUpperCase(this.params.solutionWord.replace(/'\s'/g,""),s.UPPERCASE_EXCEPTIONS),words:this.params.words,previousState:this.previousState},{onTableFilled:()=>{this.handleContentFilled()},onInitialized:t=>{this.handleContentInitialized(t)},onRead:t=>{this.handleRead(t)}}),this.setContent(this.content.getDOM()),this.params.behaviour.enableInstantFeedback&&this.content.isTableFilled()&&this.checkAnswer(),s.waitForDOM(".h5p-crossword-input-container",(()=>{setTimeout((()=>{this.trigger("resize")}),100)}))},i.handleContentInitialized=function(t){t&&this.addButtons(),this.on("resize",(()=>{this.content.resize()}))},i.addButtons=function(){this.addButton("check-answer",this.params.l10n.checkAnswer,(()=>{this.checkAnswer(),this.trigger(this.getXAPIAnswerEvent())}),this.initialButtons.check,{"aria-label":this.params.a11y.check},{contentData:this.extras,textIfSubmitting:this.params.l10n.submitAnswer}),this.addButton("show-solution",this.params.l10n.showSolution,(()=>{this.showSolutions()}),this.initialButtons.showSolution,{"aria-label":this.params.a11y.showSolution},{}),this.addButton("try-again",this.params.l10n.tryAgain,(()=>{this.resetTask()}),this.initialButtons.retry,{"aria-label":this.params.a11y.retry},{})},i.checkAnswer=function(){if(!this.content)return;this.content.checkAnswer(),this.hideButton("check-answer");const t=this.getScore(),e=this.getMaxScore(),s=H5P.Question.determineOverallFeedback(this.params.overallFeedback,t/e),o=this.params.a11y.yourResult.replace("@score",":num").replace("@total",":total");this.setFeedback(s,t,e,o),this.params.behaviour.enableSolutionsButton&&this.showButton("show-solution"),this.params.behaviour.enableRetry&&this.showButton("try-again")},i.handleRead=function(t){this.read(t)},i.handleContentFilled=function(){this.getMaxScore()>0&&this.getScore()===this.getMaxScore()?(this.checkAnswer(),this.trigger(this.getXAPIAnswerEvent())):this.showButton("check-answer")},i.getAnswerGiven=function(){return!!this.content&&this.content.getAnswerGiven()},i.getScore=function(){return this.content?this.content.getScore():0},i.getMaxScore=function(){return this.content?this.content.getMaxScore():0},i.showSolutions=function(){this.content&&(this.hideButton("check-answer"),this.hideButton("show-solution"),this.content.showSolutions(),this.trigger("resize"))},i.resetTask=function(){this.content&&(this.contentWasReset=!0,this.initialButtons.check?this.showButton("check-answer"):this.hideButton("check-answer"),this.initialButtons.showSolution?this.showButton("show-solution"):this.hideButton("show-solution"),this.initialButtons.retry?this.showButton("try-again"):this.hideButton("try-again"),this.trigger("resize"),this.removeFeedback(),this.content.reset(),this.content.enable())},i.getXAPIData=function(){return{statement:this.getXAPIAnswerEvent().data.statement}},i.getXAPIAnswerEvent=function(){const t=this.createXAPIEvent("answered");return t.setScoredResult(this.getScore(),this.getMaxScore(),this,!0,this.isPassed()),t.data.statement.result.response=this.content.getXAPIResponse(),t},i.createXAPIEvent=function(t){const e=this.createXAPIEventTemplate(t);return s.extend(e.getVerifiedStatementValue(["object","definition"]),this.getxAPIDefinition()),e},i.getxAPIDefinition=function(){const t={name:{}};return t.name[this.languageTag]=this.getTitle(),t.name["en-US"]=t.name[this.languageTag],t.description={},t.description[this.languageTag]=`${this.getDescription()}`,t.description["en-US"]=t.description[this.languageTag],t.type="http://adlnet.gov/expapi/activities/cmi.interaction",t.interactionType="fill-in",t.correctResponsesPattern=this.content.getXAPICorrectResponsesPattern(),t},i.isPassed=function(){return this.getScore()>=this.getMaxScore()||!this.getMaxScore()||0===this.getMaxScore()},i.getTitle=function(){let t;return this.extras.metadata&&(t=this.extras.metadata.title),t=t||n.DEFAULT_DESCRIPTION,H5P.createTitle(t)},i.getDescription=function(){return`${this.params.taskDescription.replaceAll(/_{10,}/gi,"_________")||n.DEFAULT_DESCRIPTION}${this.content.getXAPIDescription()}`},i.getCurrentState=function(){return this.getAnswerGiven()?this.content.getCurrentState():this.contentWasReset?{}:void 0},i.getDifference=function(t,e){for(let s in e)t[s]===e[s]&&delete t[s];return t},n}(H5P.Question);d.DEFAULT_DESCRIPTION="Crossword",H5P.Crossword=d}();;