text: /**
   * @license jq-crossword v1.2.2
   * (c) 2018 Finsi, Inc.
   */
  
  !function(e,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports,require("crossword-definition")):"function"==typeof define&&define.amd?define(["exports","crossword-definition"],s):s((e.$=e.$||{},e.$.crossword={}),e.crosswordDefinition)}(this,function(e,s){"use strict";var t;(e.CrosswordFeedback||(e.CrosswordFeedback={})).clue="clue",(t=e.CrosswordEvents||(e.CrosswordEvents={})).onClueCompleted="crossword:clue",t.onSolved="crossword:solved";var i=function(){return function(){}}(),o=function(){function e(){this.cellsElements=[],this.fieldsElements=[],this.cellsRegistries=[],this.currentAnswer=[],this.isCompleted=!1}return Object.defineProperty(e.prototype,"cellsAsJquery",{get:function(){return this._$cells||(this._$cells=$($.map(this.cellsElements,function(e){return e.get(0)}))),this._$cells},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"fieldsAsJquery",{get:function(){return this._$fields||(this._$fields=$($.map(this.fieldsElements,function(e){return e.get(0)}))),this._$fields},enumerable:!0,configurable:!0}),e}(),r=function(){return function(){}}(),l=function(){function t(){this.cluesRegistry={}}return t.prototype.destroy=function(){this.element.removeClass(this.options.classes.disabled+" "+this.options.classes.root),this.element.off("."+this.options.namespace),this.board.remove(),this.acrossCluesContainer.remove(),this.acrossCluesList.remove(),this.downCluesContainer.remove(),this.downCluesList.remove(),this._super()},t.prototype.disable=function(){this._super(),this.element.addClass(this.options.classes.disabled);var e=this.cluesRegistry;for(var s in e){e[s].fieldsAsJquery.prop("disabled",!0)}},t.prototype.enable=function(){this._super(),this.element.removeClass(this.options.classes.disabled);var e=this.cluesRegistry;for(var s in e){e[s].fieldsAsJquery.prop("disabled",!1)}},t.prototype.goToCell=function(e,s){var t,i,o;if("number"==(typeof e).toLowerCase()){var r=this.rowsRegistry[e];r&&(i=(t=r.cellsRegistry[s]).definition)}else i=(t=e).definition;return t&&i.light&&t!=this.registryCellActive&&(i.acrossClue&&i.downClue&&(0==i.acrossClueLetterIndex?o=i.acrossClue:0==i.downClueLetterIndex&&(o=i.downClue)),this.registryActive?(this.registryCellActive.element.removeClass(this.options.classes.cellActive),o=this.registryActive.definition==i.acrossClue?i.acrossClue:this.registryActive.definition==i.downClue?i.downClue:this._getDefinitionForClosestToFirstLetter(t.definition)):o=this._getDefinitionForClosestToFirstLetter(t.definition),this.registryCellActive=t,t.element.addClass(this.options.classes.cellActive),this._activateClue(o),t.field.is(":focus")||t.field.trigger("focus")),t},t.prototype.clearActive=function(){this.registryActive&&(this.registryActive=null,this.element.find("."+this.options.classes.clueActive).removeClass(this.options.classes.clueActive),this.acrossCluesList.find("."+this.options.classes.clueActive).removeClass(this.options.classes.clueActive),this.downCluesList.find("."+this.options.classes.clueActive).removeClass(this.options.classes.clueActive),this.registryCellActive.element.removeClass(this.options.classes.cellActive),this.registryCellActive=null)},t.prototype.goToCellAbove=function(){if(this.registryCellActive){var e=this._getCellFor(this.registryCellActive,!0,!1);e&&this.goToCell(e)}},t.prototype.goToCellBelow=function(){if(this.registryCellActive){var e=this._getCellFor(this.registryCellActive,!0,!0);e&&this.goToCell(e)}},t.prototype.goToCellRight=function(){if(this.registryCellActive){var e=this._getCellFor(this.registryCellActive,!1,!0);e&&this.goToCell(e)}},t.prototype.goToCellLeft=function(){if(this.registryCellActive){var e=this._getCellFor(this.registryCellActive,!1,!1);e&&this.goToCell(e)}},t.prototype.goToNextWord=function(){if(this.registryCellActive){var e=this._getNextOrPrevClueFrom(this.registryCellActive,!0);this.cluesRegistry[e.code].fieldsElements[0].trigger("focus")}},t.prototype.goToPrevWord=function(){if(this.registryCellActive){var e=this._getNextOrPrevClueFrom(this.registryCellActive,!1);this.cluesRegistry[e.code].fieldsElements[0].trigger("focus")}},t.prototype.checkClue=function(s){var t;if(s=s||this.registryActive){var i=s.isCompleted;if(s.isCompleted=s.currentAnswer.join("").length===s.definition.answer.length,s.isCompleted){for(var o=0,r=s.cellsRegistries,l=0,n=r;l<n.length;l++){var c=n[l];this._checkCellAnswer(c)&&o++}s.isCorrect=o==r.length,this._updateClueStateClass(s),t=s.isCorrect}else s.isCorrect=!1,this._updateClueStateClass(s);i!=s.isCompleted&&this.element.trigger(e.CrosswordEvents.onClueCompleted,[{instance:this,isCorrect:s.isCorrect,isCompleted:!1,definition:s.definition}])}return t},t.prototype.check=function(){var s=this.cluesRegistry,t=0;for(var i in s){if(!s[i].isCorrect)break;t++}t==Object.keys(s).length&&this.element.trigger(e.CrosswordEvents.onSolved,[this])},t.prototype.solve=function(){var s=this.cluesRegistry;for(var t in s)for(var i=0,o=s[t].cellsRegistries;i<o.length;i++){var r=o[i];r.field.val(r.definition.answer)}this.element.trigger(e.CrosswordEvents.onSolved,[this])},t.prototype._getCreateOptions=function(){return{namespace:"jq-crossword",classes:{root:"c-crossword",board:"c-crossword__board",row:"c-crossword__row",cell:"c-crossword__cell",cellActive:"c-crossword__cell--active",cellCorrect:"c-crossword__cell--correct",cellIncorrect:"c-crossword__cell--incorrect",clue:"c-crossword__clue",clueActive:"c-crossword__clue--active",clueCorrect:"c-crossword__clue--correct",clueIncorrect:"c-crossword__clue--incorrect",light:"c-crossword__clue--light",hint:"c-crossword__clue--hint",field:"c-crossword__clue__field",firstLetter:"c-crossword__cell--first-letter",firstLetterAcross:"c-crossword__cell--first-letter-across",firstLetterDown:"c-crossword__cell--first-letter-down",listItem:"c-crossword__list-item",cluesListContainer:"c-crossword__clues",cluesListTitle:"c-crossword__clues__title",clueList:"c-crossword__clues__list",disabled:"c-crossword--disabled"},downListTitle:"Down clues",acrossListTitle:"Across clues",ignoreCase:!0,feedback:e.CrosswordFeedback.clue}},t.prototype._checkCellAnswer=function(e){return e.field.val()&&(this.options.ignoreCase?e.isCorrect=new RegExp(e.definition.answer,"i").test(e.currentAnswer):e.isCorrect=e.currentAnswer==e.definition.answer),e.isCorrect},t.prototype._create=function(){this.element.addClass(this.options.classes.root),this._createDefinition(),this.cluesRegistry=this._createClueRegistry(),this._construct(),this._createCluesLists(),this._addEventsListeners()},t.prototype._addEventsListeners=function(){this.element.on("focus."+this.options.namespace,"."+this.options.classes.field,this._onFieldFocus.bind(this)),this.element.on("blur."+this.options.namespace,"."+this.options.classes.field,this._onFieldBlur.bind(this)),this.element.on("input."+this.options.namespace,"."+this.options.classes.field,this._onFieldChange.bind(this)),this.element.on("keydown."+this.options.namespace,"."+this.options.classes.field,this._onFieldKey.bind(this)),this.acrossCluesList.on("click."+this.options.namespace,"."+this.options.classes.listItem,this._onListItemClick.bind(this)),this.downCluesList.on("click."+this.options.namespace,"."+this.options.classes.listItem,this._onListItemClick.bind(this))},t.prototype._updateClueStateClass=function(e){if(e.isCompleted){var s=e.isCorrect?this.options.classes.clueCorrect:this.options.classes.clueIncorrect,t=e.isCorrect?this.options.classes.clueIncorrect:this.options.classes.clueCorrect;e.listItem.removeClass(t).addClass(s),e.cellsAsJquery.removeClass(t).addClass(s)}else{for(var i=0,o=e.cellsRegistries;i<o.length;i++){var r=o[i];r.acrossClueRegistry&&r.downClueRegistry&&(r.acrossClueRegistry.isCompleted||r.downClueRegistry.isCompleted)||r.element.removeClass(this.options.classes.clueCorrect+" "+this.options.classes.clueIncorrect)}e.listItem.removeClass(this.options.classes.clueCorrect+" "+this.options.classes.clueIncorrect)}},t.prototype._onListItemClick=function(e){if(this.options.disabled)e.preventDefault();else{this.interaction=!0;var s=$(e.target),t=s.data("down"),i=s.data("across"),o=void 0;o=t?this.cluesRegistry[t+"d"].cellsRegistries[0]:this.cluesRegistry[i+"a"].cellsRegistries[0],this.goToCell(o),this.interaction=!1}},t.prototype._getDefinitionForClosestToFirstLetter=function(e){return e.acrossClue&&e.downClue?e.acrossClueLetterIndex<=e.downClueLetterIndex?e.acrossClue:e.downClue:e.acrossClue||e.downClue},t.prototype._onFieldFocus=function(e){if(this.options.disabled)e.preventDefault();else{this.interaction=!0;var s=$(e.target).parents("."+this.options.classes.cell).first(),t=s.data("x"),i=s.data("y");this.goToCell(i,t),this.interaction=!1}},t.prototype._onFieldBlur=function(e){this.interaction||this.clearActive()},t.prototype._storeAndCheckAnswer=function(s,t){if(t.currentAnswer=s,t.definition.acrossClue){var i=this.cluesRegistry[t.definition.acrossClue.code],o=t.definition.acrossClueLetterIndex;i.currentAnswer[o]=s,this.options.feedback===e.CrosswordFeedback.clue&&this.checkClue(i)}if(t.definition.downClue){i=this.cluesRegistry[t.definition.downClue.code],o=t.definition.downClueLetterIndex;i.currentAnswer[o]=s,this.options.feedback===e.CrosswordFeedback.clue&&this.checkClue(i)}this.check()},t.prototype._onFieldChange=function(e){if(this.options.disabled)e.preventDefault();else{this.interaction=!0;var s=this.registryCellActive.field.val();if(!this.registryActive){var t=$(e.target).parents("."+this.options.classes.cell).first(),i=t.data("x"),o=t.data("y");this.goToCell(o,i)}this._storeAndCheckAnswer(s,this.registryCellActive),s?this.registryActive.definition.across?this.goToCellRight():this.goToCellBelow():this.registryActive.definition.across?this.goToCellLeft():this.goToCellAbove(),this.interaction=!1}},t.prototype._activateClue=function(e){var s=this.cluesRegistry[e.code];s&&s!=this.registryActive&&(this.registryActive=s,this.board.find("."+this.options.classes.clueActive).removeClass(this.options.classes.clueActive),this.acrossCluesList.find("."+this.options.classes.clueActive).removeClass(this.options.classes.clueActive),this.downCluesList.find("."+this.options.classes.clueActive).removeClass(this.options.classes.clueActive),s.cellsAsJquery.addClass(this.options.classes.clueActive),s.listItem.addClass(this.options.classes.clueActive))},t.prototype._getNextOrPrevClueFrom=function(e,s){var t,i,o,r,l,n,c=e.definition;if(c.acrossClue&&c.downClue){var a=this._getDefinitionForClosestToFirstLetter(e.definition);i=a.across,o=a}else i=void 0!=c.acrossClue,o=i?c.acrossClue:c.downClue;if(r=i?c.crossword.acrossClues:c.crossword.downClues,l=i?c.crossword.downClues:c.crossword.acrossClues,-1!=(n=r.findIndex(function(e){return e.number===o.number}))){n+=s?1:-1;t=s&&n<r.length||!s&&n>=0?r[n]:s?l[0]:l.slice(-1)[0]}return t},t.prototype._getCellFor=function(e,s,t){var i,o=e.definition,r=o.x,l=o.y,n=s?t?l+1:l-1:l,c=s?r:t?r+1:r-1,a=this.rowsRegistry[n];if(a){var d=a.cellsRegistry[c];d&&d.definition.light&&(i=d.definition.hint?this._getCellFor(d,s,t):d)}return i},t.prototype._onFieldKey=function(e){if(this.options.disabled)e.preventDefault();else{this.interaction=!0;var s=$(e.target).parents("."+this.options.classes.cell).first(),t=s.data("x"),i=s.data("y"),o=this.rowsRegistry[i].cellsRegistry[t];switch(e.which){case $.ui.keyCode.SPACE:e.preventDefault();break;case $.ui.keyCode.ENTER:case $.ui.keyCode.TAB:e.preventDefault(),e.shiftKey?this.goToPrevWord():this.goToNextWord();break;case $.ui.keyCode.UP:this.goToCellAbove();break;case $.ui.keyCode.RIGHT:this.goToCellRight();break;case $.ui.keyCode.DOWN:this.goToCellBelow();break;case $.ui.keyCode.LEFT:this.goToCellLeft();break;case $.ui.keyCode.BACKSPACE:e.preventDefault(),o.field.val("").trigger("input");break;default:1==e.key.length&&(e.preventDefault(),o.field.val(e.key).trigger("input"))}this.interaction=!1}},t.prototype._createBoard=function(){return"function"==(typeof this.options.createBoard).toLowerCase()?this.options.createBoard.apply(this,arguments):$('<table class="'+this.options.classes.board+'"></table>')},t.prototype._createRow=function(e){return"function"==(typeof this.options.createRow).toLowerCase()?this.options.createRow.apply(this,arguments):$('<tr class="'+this.options.classes.row+'" data-row="'+e+'"></tr>')},t.prototype._createCell=function(e){return"function"==(typeof this.options.createCell).toLowerCase()?this.options.createCell.apply(this,arguments):$("<td></td>")},t.prototype._createCellField=function(e){return"function"==(typeof this.options.createCellField).toLowerCase()?this.options.createCellField.apply(this,arguments):$('<input maxlength="1" tabindex="-1">')},t.prototype._createCluesListContainer=function(e){return"function"==(typeof this.options.createCluesListContainer).toLowerCase()?this.options.createCluesListContainer.apply(this,arguments):$('\n                <div class="'+this.options.classes.cluesListContainer+'">\n                    <p class="'+this.options.classes.cluesListTitle+'">'+(e?this.options.acrossListTitle:this.options.downListTitle)+"</p>\n                </div>\n            ")},t.prototype._createCluesList=function(e){return"function"==(typeof this.options.createCluesList).toLowerCase()?this.options.createCluesList.apply(this,arguments):$('<ul class="'+this.options.classes.clueList+'"></ul>')},t.prototype._createCluesListItem=function(e){return"function"==(typeof this.options.createCluesListItem).toLowerCase()?this.options.createCluesListItem.apply(this,arguments):$("<li></li>")},t.prototype._createDownCluesList=function(){var e=this.definition.downClues;this.downCluesContainer=this._createCluesListContainer(!1),this.downCluesList=this._createCluesList(!1);for(var s=0,t=e;s<t.length;s++){var i=t[s],o=this._createCluesListItem(i);this._addInfoToListElement(o,i),this.downCluesList.append(o),this.cluesRegistry[i.code].listItem=o}this.downCluesContainer&&this.downCluesContainer.append(this.downCluesList)},t.prototype._createAcrossCluesList=function(){var e=this.definition.acrossClues;this.acrossCluesContainer=this._createCluesListContainer(!0),this.acrossCluesList=this._createCluesList(!0);for(var s=0,t=e;s<t.length;s++){var i=t[s],o=this._createCluesListItem(i);this._addInfoToListElement(o,i),this.acrossCluesList.append(o),this.cluesRegistry[i.code].listItem=o}this.acrossCluesContainer&&this.acrossCluesContainer.append(this.acrossCluesList)},t.prototype._createCluesLists=function(){this._createAcrossCluesList(),this._createDownCluesList();var e=this.options.acrossListAppendTo?$(this.options.acrossListAppendTo):null,s=this.options.downListAppendTo?$(this.options.downListAppendTo):null;e&&e.length>0?this.acrossCluesContainer?e.append(this.acrossCluesContainer):e.append(this.acrossCluesList):this.element.append(this.acrossCluesContainer),s&&s.length>0?this.downCluesContainer?s.append(this.downCluesContainer):s.append(this.downCluesList):this.element.append(this.downCluesContainer)},t.prototype._addInfoToListElement=function(e,s){e.addClass(this.options.classes.listItem),s.across?(e.addClass(this.options.classes.clue+"--"+s.code),e.attr("data-across",s.number)):(e.addClass(this.options.classes.clue+"--"+s.code),e.attr("data-down",s.number)),e.text(s.clue)},t.prototype._addInfoToCellElement=function(e,s){e.attr({"data-x":s.x,"data-y":s.y}),(s.acrossClue||s.downClue)&&e.addClass(this.options.classes.clue),s.clueLabel&&(e.addClass(this.options.classes.firstLetter),0==s.acrossClueLetterIndex&&e.addClass(this.options.classes.firstLetterAcross),0==s.downClueLetterIndex&&e.addClass(this.options.classes.firstLetterDown)),s.acrossClue&&(e.addClass(this.options.classes.clue+"--"+s.acrossClue.code),e.attr("data-across",s.acrossClue.number)),s.downClue&&(e.addClass(this.options.classes.clue+"--"+s.downClue.code),e.attr("data-down",s.downClue.number)),s.light&&(e.addClass(this.options.classes.light),s.hint&&e.addClass(this.options.classes.hint))},t.prototype._createClueRegistry=function(){for(var e={},s=this.definition,t=s.acrossClues.concat(s.downClues),i=0,r=t.length;i<r;i++){var l=t[i],n=new o;n.definition=l,n.currentAnswer=new Array(l.answer.length),e[l.code]=n}return e},t.prototype._construct=function(){if(this.definition){var e=this.definition.matrix,s=this._createBoard(),t=[],o=this.cluesRegistry;this.board=s;for(var l=0,n=e.length;l<n;l++){var c=e[l],a=void 0,d=[],u=[],h=new r;h.cellsRegistry=u;for(var p=0,C=c.length;p<C;p++){var f=c[p],g=this._createCell(f).addClass(this.options.classes.cell),w=new i,v=void 0;if(w.rowRegistry=h,this._addInfoToCellElement(g,f),w.definition=f,w.element=g,f.light)if(f.hint){if(g.text(f.answer),f.acrossClue)(y=o[f.acrossClue.code]).currentAnswer[f.acrossClueLetterIndex]=f.answer;if(f.downClue)(y=o[f.downClue.code]).currentAnswer[f.downClueLetterIndex]=f.answer}else{var y;if((v=this._createCellField(f)).addClass(this.options.classes.field),w.field=v,g.append(v),f.acrossClue)(y=o[f.acrossClue.code]).cellsElements.push(g),y.fieldsElements.push(v),y.cellsRegistries.push(w),w.acrossClueRegistry=y;if(f.downClue)(y=o[f.downClue.code]).cellsElements.push(g),y.fieldsElements.push(v),y.cellsRegistries.push(w),w.downClueRegistry=y}d.push(g),u[p]=w}(a=this._createRow(l))?(h.element=a,a.append(d),s.append(a)):s.append(d),t.push(h)}this.rowsRegistry=t,this.element.append(s)}},t.prototype._createDefinition=function(){var e=this.options.definition;e&&(e instanceof s.CrosswordDefinition!=!0&&(e=new s.CrosswordDefinition(e)),this.definition=e)},t}();if(Object.hasOwnProperty("getOwnPropertyDescriptors")){for(var n={},c=Object.getOwnPropertyNames(l.prototype),a=0,d=c.length;a<d;a++){var u=c[a];n[u]=Object.getOwnPropertyDescriptor(l.prototype,u).value}$.widget("ui.crossword",n)}else $.widget("ui.crossword",l.prototype);e.CrosswordCellRegistry=i,e.CrosswordClueRegistry=o,e.CrosswordRowRegistry=r,e.CrosswordGame=l,Object.defineProperty(e,"__esModule",{value:!0})});
  