text: var CrosswordsJS=function(e){"use strict";function t(e){for(var t=e.width,r=e.height,l=new Array(t),s=0;r>s;s++){l[s]=new Array(r);for(var o=0;r>o;o++)l[s][o]={crossword:e,x:s,y:o}}return l}function r(e){if(!e)throw new Error("The Crossword must be initialised with a crossword definition.");if(this.width=e.width,this.height=e.height,this.acrossClues=[],this.downClues=[],this.cells=t(this),void 0===this.width||null===this.width||this.width<0||void 0===this.height||null===this.height||this.height<0)throw new Error("The crossword bounds are invalid.");for(var r=e.acrossClues.concat(e.downClues),l=0;l<r.length;l++){var s=r[l],o=l<e.acrossClues.length,n={number:s.number,code:s.number+(o?"a":"d"),answer:s.answer,x:s.x-1,y:s.y-1,across:o,length:[],totalLength:0,clue:s.clue,cells:[]};if(this[o?"acrossClues":"downClues"].push(n),n.x<0||n.x>=this.width||n.y<0||n.y>=this.height)throw new Error("Clue "+n.code+" doesn't start in the bounds.");for(var a=0;a<s.length.length;a++)n.length.push(s.length[a]),n.totalLength+=s.length[a];if(o){if(n.x+n.totalLength>this.width)throw new Error("Clue "+n.code+" exceeds horizontal bounds.")}else if(n.y+n.totalLength>this.height)throw new Error("Clue "+n.code+" exceeds vertical bounds.");for(var c=n.x,u=n.y,i=0;i<n.totalLength;i++){var d=this.cells[c][u];if(d.light=!0,d[o?"acrossClue":"downClue"]=n,d[o?"acrossClueLetterIndex":"downClueLetterIndex"]=i,n.cells.push(d),n.answer){if(void 0!==d.answer&&" "!==d.answer&&d.answer!==n.answer[i])throw new Error("Clue "+n.code+" answer at ("+(c+1)+", "+(u+1)+") is not coherent with previous clue ("+d.acrossClue.code+") answer.");d.answer=n.answer[i]}if(0===i){if(d.clueLabel&&d.clueLabel!==n.number)throw new Error("Clue "+n.code+" has a label which is inconsistent with another clue ("+d.acrossClue.code+").");d.clueLabel=n.number}o?c++:u++}}}return e.Crossword=r,e}(CrosswordsJS||{},window,document),CrosswordsJS=function(e,t,r){"use strict";function l(e,t){var r=new RegExp("(?:^|\\s)"+t+"(?!\\S)","g");e.className=e.className.replace(r,"")}function s(e,t){e.className+=" "+t}function o(){this.map=[]}function n(e,t){this.crossword=e,this.parentElement=t;var l=r.createElement("div");l.className="crossword";for(var s=0;s<e.height;s++){var o=r.createElement("div");o.className="cwrow",l.appendChild(o);for(var n=0;n<e.width;n++){var c=e.cells[n][s],u=this._createCellDOM(c);o.appendChild(u),a.add(c,u)}}t.appendChild(l),this.crosswordElement=l}o.prototype.add=function(e,t){this.map.push({cell:e,cellElement:t})},o.prototype.getCellElement=function(e){for(var t=0;t<this.map.length;t++)if(this.map[t].cell===e)return this.map[t].cellElement;return null},o.prototype.getCell=function(e){for(var t=0;t<this.map.length;t++)if(this.map[t].cellElement===e)return this.map[t].cell;return null},o.prototype.removeCrosswordCells=function(e){for(var t=0;t<this.map.length;t++)this.map[t].cell.crossword===e&&this.map.splice(t,1)};n.prototype.selectClue=function(e){this.currentClue=e,this._updateDOM(),a.getCellElement(e.cells[0]).focus(),this._stateChange("clueSelected")},n.prototype.destroy=function(){a.removeCrosswordCells(this.crossword),this.parentElement.removeChild(this.crosswordElement),this.onStateChanged=null},n.prototype._stateChange=function(e,t){var r=this.onStateChanged;r&&r({message:e,data:t})},n.prototype._createCellDOM=function(e){var t=this,l=r.createElement("div");if(l.className="cwcell",e.cellElement=l,l.className+=e.light?" light":" dark",!e.light)return l;var s=r.createElement("input");if(s.maxLength=1,e.answer&&(s.value=e.answer),l.appendChild(s),e.clueLabel){var o=r.createElement("div");o.className="cwcluelabel",o.innerHTML=e.clueLabel,l.appendChild(o)}return s.addEventListener("focus",function(e){var r=e.target.parentNode,l=a.getCell(r),s=(l.crossword,l.acrossClue),o=l.downClue;(!t.currentClue||t.currentClue!==s&&t.currentClue!==o)&&(t.currentClue=s&&!o||!s&&o?s||o:0===l.downClueLetterIndex&&0!==l.acrossClueLetterIndex?o:s,t._updateDOM(),t._stateChange("clueSelected"))}),l.addEventListener("keydown",function(e){if(8===e.keyCode){e.preventDefault(),e.target.value="";var r=e.target.parentNode,l=a.getCell(r),s=l.acrossClue===t.currentClue?l.acrossClueLetterIndex:l.downClueLetterIndex,o=s-1;o>=0&&t.currentClue.cells[o].cellElement.querySelector("input").focus()}else if(9===e.keyCode){e.preventDefault();for(var r=e.target.parentNode,l=a.getCell(r),n=l.crossword,c=t.currentClue,u=c.across?n.acrossClues:n.downClues,i=0;i<u.length;i++)if(c===u[i]){var d=null;d=e.shiftKey?i>0?u[i-1]:c.across?n.downClues[n.downClues.length-1]:n.acrossClues[n.acrossClues.length-1]:i<u.length-1?u[i+1]:c.across?n.downClues[0]:n.acrossClues[0],t.currentClue=d,t._updateDOM(),a.getCellElement(d.cells[0]).querySelector("input").focus();break}}else if(13===e.keyCode){e.preventDefault();var r=e.target.parentNode,l=a.getCell(r),n=l.crossword;l.acrossClue&&l.downClue&&(t.currentClue=l.acrossClue===t.currentClue?l.downClue:l.acrossClue,t._updateDOM())}}),l.addEventListener("keypress",function(e){function r(e,t,r){for(var l=null===e||void 0===e?"":e,s="";l.length<=t;)l+=" ";for(var o=Math.max(t,l.length),n=0;o>n;n++)s+=n==t?r:l[n];return s}32===e.keyCode&&e.preventDefault(),e.target.value="";var l=e.target.parentNode,s=a.getCell(l),o=(s.crossword,t.currentClue),n=String.fromCharCode(e.keyCode);s.acrossClue&&(s.acrossClue.answer=r(s.acrossClue.answer,s.acrossClueLetterIndex,n)),s.downClue&&(s.downClue.answer=r(s.downClue.answer,s.downClueLetterIndex,n));var c=s.acrossClue===o?s.acrossClueLetterIndex:s.downClueLetterIndex,u=c+1;u<o.cells.length&&o.cells[u].cellElement.querySelector("input").focus()}),l.addEventListener("keyup",function(e){switch(e.keyCode){case 37:var t=e.target.parentNode,r=a.getCell(t),l=r.x,s=r.y;r.x>0&&r.crossword.cells[l-1][s].light===!0&&a.getCellElement(r.crossword.cells[l-1][s]).querySelector("input").focus();break;case 38:var t=e.target.parentNode,r=a.getCell(t),l=r.x,s=r.y;r.y>0&&r.crossword.cells[l][s-1].light===!0&&a.getCellElement(r.crossword.cells[l][s-1]).querySelector("input").focus();break;case 39:var t=e.target.parentNode,r=a.getCell(t),o=r.crossword.width,l=r.x,s=r.y;r.x+1<o&&r.crossword.cells[l+1][s].light===!0&&a.getCellElement(r.crossword.cells[l+1][s]).querySelector("input").focus();break;case 40:var t=e.target.parentNode,r=a.getCell(t),n=r.crossword.height,l=r.x,s=r.y;r.y+1<n&&r.crossword.cells[l][s+1].light===!0&&a.getCellElement(r.crossword.cells[l][s+1]).querySelector("input").focus();break;case 9:}}),l},n.prototype._updateDOM=function(){for(var e=this.currentClue,t=this.crossword,r=0;r<t.cells.length;r++)for(var o=0;o<t.cells[r].length;o++){var n=t.cells[r][o];n.light===!0&&(n.acrossClue===e||n.downClue===e?s(a.getCellElement(n).querySelector("input"),"active"):l(a.getCellElement(n).querySelector("input"),"active"))}};var a=new o;return e.CrosswordDOM=n,e}(CrosswordsJS||{},window,document);
  //# sourceMappingURL=crosswords.min.js.map