UNPKG

swordjs

Version:

swordjs - access modules from crosswire.org/sword in JS

2 lines 384 kB
!function(e){function t(a){if(n[a])return n[a].exports;var s=n[a]={exports:{},id:a,loaded:!1};return e[a].call(s.exports,s,s.exports,t),s.loaded=!0,s.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){"use strict";var a=n(1),s=n(2),r=n(3),i=n(4),o=n(5),u={installMgr:a,dataMgr:s,moduleMgr:r,verseKey:o,versificationMgr:i};e.exports=u},function(e,t,n){"use strict";function a(e,t){e instanceof Function&&(t=e,e="http://crosswire.org/ftpmirror/pub/sword/masterRepoList.conf"),i(e,"text",function(e,n){if(""!==n||e)if(e)t(e);else{var a=[],s=null,r="",i="";n.split(/[\r\n]+/g).forEach(function(e){if(s=e.split("|"),s.length>1&&-1!==s[0].search("CrossWire")){switch(i=s[0].split("=")[2]){case"CrossWire":r="main";break;case"CrossWire Beta":r="beta";break;case"CrossWire av11n":r="av";break;case"CrossWire Attic":r="attic";break;case"CrossWire Wycliffe":r="wycliffe";break;case"CrossWire av11n Attic":r="avattic"}a.push({name:i,type:r,url:s[1]+s[2],confUrl:"http://crosswire.org/ftpmirror"+s[2]+"/mods.d"})}}),t(e,a)}else t("Couldn't download master repo list!")})}function s(e,t){r(e,t)}function r(e,t,n){var a=!0;t instanceof Function&&(n=t,a=!1),a?(t=t+"?modUrl="+e.url,console.log(t),i(t,"json",function(e,t){console.log(t),n(e,w.cleanArray(t).sort(w.dynamicSortMultiple("Lang","moduleKey")))})):i(e.confUrl,"document",function(t,a){if(t)n(t);else{for(var s=[],r="",o=a.getElementsByTagName("a"),u=0;u<o.length;u++)-1!==o[u].href.search(".conf")&&(r=o[u].baseURI+"/"+o[u].textContent,s.push(function(t){return function(n){i(t,"text",function(t,a){var s=w.readConf(a);"zText"===s.ModDrv?(s.url="http://www.crosswire.org/sword/servlet/SwordMod.Verify?modName="+s.moduleKey+"&"+e.type+"=true&pkgType=raw",n(t,s)):n(t)})}}(r)));y.parallel(s,function(e,t){n(e,w.cleanArray(t).sort(w.dynamicSortMultiple("Lang","moduleKey")))})}})}function i(e,t,n,a){var s=new XMLHttpRequest({mozSystem:!0,mozAnon:!0});s.open("GET",e,!0),s.responseType=t,s.onreadystatechange=function(e){4==s.readyState&&(200===s.status?n(null,s.response):n({message:"Couldn't download module.",error:s.status}))},s.onprogress=a,s.onerror=function(e){n(e)},s.send(null)}function o(e,t,n){"string"==typeof e?i(e,"document",function(e,a){if(e)t(e);else{var s=a.getElementsByTagName("a")[0].href;i(s,"blob",function(e,n){e?t(e):u(n,t)},n)}}):u(e,t)}function u(e,t){var n=new FileReader;n.onload=function(e){var n=new m(e.target.result);for(var a in n.files)-1!==a.search(".conf")&&v.saveConfig(new Blob([n.files[a].asArrayBuffer()]),function(e,a){e?t(e):l(n,a.v11n,a,t)})},n.onerror=function(e){t(e)},n.readAsArrayBuffer(e)}function h(e,t){"string"==typeof e?v.removeModule(e,t):t({message:"inModuleKey must be a string!"})}function l(e,t,n,a){var s={};s.bin=[];for(var r in e.files)"zText"===n.modDrv||"zCom"===n.modDrv?-1!==r.search(/nt.[bc]zs/)?s.ntB=r:-1!==r.search(/nt.[bc]zv/)?s.ntCV=r:-1!==r.search(/ot.[bc]zs/)?s.otB=r:-1!==r.search(/ot.[bc]zv/)?s.otCV=r:-1===r.search(".conf")&&s.bin.push({blob:new Blob([e.files[r].asUint8Array()]),name:r}):"RawCom"===n.modDrv&&(-1!==r.search("nt.vss")?s.ntIdx=r:-1!==r.search("ot.vss")?s.otIdx=r:-1===r.search(".conf")&&s.bin.push({blob:new Blob([e.files[r].asUint8Array()]),name:r}));y.series([function(e){v.saveModule(s.bin,n,function(t,n){e(t?t:null)})},function(a){var r=null,i=null,o=null,u=null;s.otB&&(r=c(e.files[s.otB].asUint8Array()),u=d(e.files[s.otCV].asUint8Array(),r,"ot",t)),s.ntB&&(i=c(e.files[s.ntB].asUint8Array()),o=d(e.files[s.ntCV].asUint8Array(),i,"nt",t)),"RawCom"===n.modDrv&&s.otIdx&&(u=p(e.files[s.otIdx].asUint8Array(),"ot")),"RawCom"===n.modDrv&&s.ntIdx&&(o=p(e.files[s.ntIdx].asUint8Array(),"nt")),v.saveBCVPos(u,o,n,function(e,t){a(e?e:null)})}],function(e,t){e?(v.remove(n.id,function(e){}),a(e)):a(null,n.id)})}function c(e,t){var n=0,a=0,s=0,r=null,i=!1,o=[];for(k=0;!i;)if(r=g(e),n=r[0],i=r[1],!i&&(r=g(e),a=r[0],i=r[1],!i)){if(r=g(e),s=r[0],i=r[1])break;o.push({startPos:n,length:a,unused:s})}return o}function f(e){k=0;for(var t=0;4>t;t++)b(e),_(e),b(e)}function d(e,t,n,a){f(e);for(var s="ot"===n?0:x.getBooksInOT(a),r="ot"===n?x.getBooksInOT(a):x.getBooksInOT(a)+x.getBooksInNT(a),i=0,o=0,u=0,h=0,l=0,c=0,d=0,p=null,g=0,m={},v=0,y={},w=s;r>w;w++){p=x.getBook(w,a),y[p.abbrev]=[],v=0;for(var k=0;k<p.maxChapter;k++){i=0,o=0,m={},m.verses=[],u=0,d=x.getVersesInChapter(w,k+1,a);for(var E=0;d>E;E++)c=b(e)[0],g=_(e)[0],0!==g&&(o=g),u=b(e)[0],0===E&&(i=g,l=0,c<t.length&&(l=t[c].startPos),m.startPos=i,m.booknum=w,m.bookStartPos=l),0===c&&0===g&&0===u?m!=={}&&m.verses.push({startPos:0,length:0}):m!=={}&&m.verses.push({startPos:g-i,length:u});m!={}&&(h=o-i+u,m.length=h,y[p.abbrev].push(m),(isNaN(h)||0===h)&&v++),b(e),_(e),b(e)}v===p.maxChapter&&delete y[p.abbrev],b(e),_(e),b(e)}return y}function p(e,t,n){k=0,_(e),_(e);for(var a="ot"===t?0:x.getBooksInOT(n),s="ot"===t?x.getBooksInOT(n):x.getBooksInOT(n)+x.getBooksInNT(n),r=0,i=0,o=null,u=0,h={},l="",c=a;s>c;c++){o=x.getBook(c,n),g(e),b(e);for(var f=0;f<o.maxChapter;f++){i=x.getVersesInChapter(c,f+1,n),g(e),b(e);for(var d=0;i>d;d++)u=g(e)[0],r=b(e)[0],0!==r&&(l=o.abbrev+"."+parseInt(f+1,10)+"."+parseInt(d+1,10),h[l]={startPos:u,length:r})}}return h}function g(e,t){return E=e.subarray(k,k+4),C=!1,k+=4,4!==E.length&&(C=!0),t&&t(1048576*E[3]+65536*E[2]+256*E[1]+E[0],C),[1048576*E[3]+65536*E[2]+256*E[1]+E[0],C]}function b(e,t){return E=e.subarray(k,k+2),C=!1,k+=2,2!==E.length&&(C=!0),t&&t(256*E[1]+E[0],C),[256*E[1]+E[0],C]}function _(e,t){return E=e.subarray(k,k+6),C=!1,k+=6,6!==E.length&&(C=!0),t&&t(17592186044416*E[1]+4294967296*E[0]+16777216*E[5]+65536*E[4]+256*E[3]+E[2],C),[17592186044416*E[1]+4294967296*E[0]+16777216*E[5]+65536*E[4]+256*E[3]+E[2],C]}var m=n(13),v=n(2),x=n(4),y=n(14),w=n(6),k=0,E=null,C=!1,A={getRepositories:a,getModules:s,getRemoteModules:r,installModule:o,removeModule:h};e.exports=A},function(e,t,n){"use strict";function a(e,t){g.getDB(function(n,a){n?t(n):a.get(e,function(e){t(null,e)},function(e){t(e)})})}function s(e,t){var n=new FileReader;n.readAsText(e),n.onload=function(e){var n=b.readConf(e.target.result);g.getDB(function(e,a){e?console.log(e):a.put(n,function(e){t(null,{id:e,modKey:n.moduleKey,modDrv:n.ModDrv,v11n:n.Versification})},function(e){t(e)})})}}function r(e,t,n){var a=(e.length,{});a.docId=t.id,p.eachSeries(e,function(e,s){var r=e.name.split("/"),i=r[r.length-3];g.getDB(function(o,u){o?n(o):u.put({fileName:r[r.length-1],modKey:t.modKey,driver:i,blob:e.blob},function(e){a[r[r.length-1].split(".")[0]]=e,s(null)},function(e){s(e)})})},function(e){e?n(e):i(a,n)})}function i(e,t){g.getDB(function(n,a){n?t(n):a.get(e.docId,function(n){n.nt=e.nt,n.ot=e.ot,a.put(n,function(e){t(null)},function(e){t(e)})},function(e){t(e)})})}function o(e,t){g.getDB(function(n,a){n?t(n):a.get(e,function(e){t(null,e.blob)},function(e){t(e)})})}function u(e,t,n,a){g.getDB(function(s,r){s?a(s):r.put({modKey:n.modKey,ot:e,nt:t},function(e){r.get(n.id,function(t){t.bcvPosID=e,r.put(t,function(e){a(null)},function(e){a(e)})},function(e){a(e)})},function(e){a(e)})})}function h(e){g.getDB(function(t,n){t?e(t):n.query(function(t){e(null,t)},{onError:function(t){e(t)},index:"modules"})})}function l(e,t){g.getDB(function(n,a){n?t(n):a.remove(e,t(null),function(e){t(e)})})}function c(e,t){g.getDB(function(n,a){n?t&&t(n):h(function(n,s){if(n)t&&t(n);else{var r=!1;s.forEach(function(n){if(n.moduleKey===e){r=!0;var s=n.blobIds?b.convertObject(n.blobIds):[n.bcvPosID,n.nt,n.ot,n.id];s=s.filter(function(e){return e}),a.removeBatch(s,function(){t&&t(null)},function(e){t&&t(e)})}}),r||t({message:"Couldn't find the module."})}})})}function f(){g.getDB(function(e,t){e?inCallback(e):t.clear(function(){},function(e){console.log(e)})})}function d(){return g.getIDBWrapper()}var p=(n(13),n(14)),g=n(7),b=n(6),_={clearDatabase:f,saveConfig:s,saveModule:r,saveBCVPos:u,getBlob:o,get:a,remove:l,removeModule:c,getModules:h,getIDBWrapper:d};e.exports=_},function(e,t,n){"use strict";function a(e){var t=[];r.getModules(function(n,a){n?e(n):(a.forEach(function(e){t.push(new i(e.moduleKey,e.id,{id:e.id,Versification:e.Versification,Encoding:e.Encoding,Direction:e.Direction,SourceType:e.SourceType,bcvPosID:e.bcvPosID,description:e.Description,language:e.Lang,ot:e.ot,nt:e.nt,moduleKey:e.moduleKey,modDrv:e.ModDrv,conf:e}))}),e(null,t))})}function s(e,t){r.get(e,function(n,a){n?t(null):t(null,new i(a.moduleKey,e,a))})}var r=n(2),i=n(8),o={getModule:s,getModules:a};e.exports=o},function(e,t,n){"use strict";function a(e){return void 0!==e&&p[e]?p[e].ot.length:p.kjv.ot.length}function s(e){return void 0!==e&&p[e]?p[e].nt.length:p.kjv.nt.length}function r(e,t){e=0>e?0:e;var n=a(t),s=n>e?"ot":"nt";return e=n>e?e:e-n,void 0!==t&&p[t]?p[t][s][e].maxChapter:p.kjv[s][e].maxChapter}function i(e,t,n){return void 0!==n&&p[n]?p[n].versesInChapter[e][parseInt(t,10)-1]:p.kjv.versesInChapter[e][parseInt(t,10)-1]}function o(e,t){e=0>e?0:e;var n=a(t),s=n>e?"ot":"nt";return e=n>e?e:e-n,void 0!==t&&p[t]?p[t][s][e]:p.kjv[s][e]}function u(e,t){return void 0!==t&&p[t]?p[t].osisToBookNum[e]:p.kjv.osisToBookNum[e]}function h(e,t,n){var s=[],r=t&&p[t]?p[t]:p.kjv;l.get(e,function(e,i){if(e)n&&n(e);else{if(i.hasOwnProperty("ot")){var o=0;for(var u in i.ot)o=i.ot[u][0].booknum,r.ot[o].bookNum=o,s.push(r.ot[o])}if(i.hasOwnProperty("nt")){var h=a(t),l=0;for(var c in i.nt)l=i.nt[c][0].booknum-h,r.nt[l].bookNum=l+h,s.push(r.nt[l])}n&&n(null,s)}})}var l=n(2),c=n(10),f=n(11),d=n(12),p={};p.kjv=c,f.nt=c.nt,f.osisToBookNum=c.osisToBookNum,p.german=f,p.vulg=d,e.exports={getBooksInOT:a,getBooksInNT:s,getChapterMax:r,getVersesInChapter:i,getBook:o,getBookNum:u,getAllBooks:h}},function(e,t,n){"use strict";function a(e,t){var n={};n.osisRef=h.parse(e).osis(),""===n.osisRef&&(n.osisRef="Matt.1");var a=n.osisRef.split("-")[0].split(".");return n.book=a[0],n.chapter=isNaN(parseInt(a[1],10))?1:parseInt(a[1],10),n.verse=parseInt(a[2],10),n.bookNum=o.getBookNum(n.book,t),n}function s(e,t){var n=[],s=e;if("string"==typeof e&&(s=a(e)),-1!==s.osisRef.search("-")){var r=s.osisRef.split("-"),i=(r[0].split("."),r[1].split("."));if(!isNaN(s.verse)&&3===i.length)for(var u=s.verse;u<parseInt(i[2],10)+1;u++)n.push({osis:s.book+"."+s.chapter+"."+u,book:s.book,bookNum:h,chapter:s.chapter,verse:u})}else if(isNaN(s.verse))for(var h=o.getBookNum(s.book),l=o.getVersesInChapter(h,s.chapter,t),c=0;l>c;c++)n.push({osis:s.book+"."+s.chapter+"."+(c+1),book:s.book,bookNum:h,chapter:s.chapter,verse:c+1});else n.push(s);return n}function r(e,t){var n=a(e,t),s=o.getChapterMax(n.bookNum,t);return n.chapter<s?n.chapter++:(n.bookNum=n.bookNum<65?++n.bookNum:65,n.chapter=n.bookNum<65?1:s,n.book=o.getBook(n.bookNum,t).abbrev),n.osisRef=n.book+"."+n.chapter,n}function i(e,t){var n=a(e,t),s=o.getChapterMax(n.bookNum-1,t);return n.chapter>1?--n.chapter:(n.chapter=0===n.bookNum?1:s,n.bookNum=n.bookNum>0?--n.bookNum:0,n.book=o.getBook(n.bookNum,t).abbrev),n.osisRef=n.book+"."+n.chapter,n}var o=n(4),u=n(9),h=new u.bcv_parser,l={parse:a,parseVerseList:s,next:r,previous:i};e.exports=l},function(e,t,n){"use strict";function a(e){var t=e.split(/[\r\n]+/g),n={},a=null;return n.GlobalOptionFilter=[],n.Feature=[],t.forEach(function(e,t){a=e.split(/=(.+)/),""!==a[0]&&(-1!==a[0].search(/\[.*\]/)?n.moduleKey=a[0].replace("[","").replace("]",""):"GlobalOptionFilter"===a[0]?n[a[0]].push(a[1]):"Feature"===a[0]?n[a[0]].push(a[1]):n[a[0]]="Versification"===a[0]?a[1].toLowerCase():a[1])}),n}function s(e){return function(t,n){return t[e]>n[e]?1:t[e]<n[e]?-1:0}}function r(){var e=arguments;return function(t,n){for(var a=0,r=0,i=e.length;0===r&&i>a;)r=s(e[a])(t,n),a++;return r}}function i(e){for(var t=[],n=0;n<e.length;n++)e[n]&&t.push(e[n]);return t}function o(e){var t={};return e.forEach(function(e){e&&(t[e.book]=e.id)}),t}function u(e){var t=[];for(var n in e)t.push(e[n]);return t}var h={readConf:a,dynamicSort:s,dynamicSortMultiple:r,cleanArray:i,convertArray:o,convertObject:u};e.exports=h},function(e,t,n){function a(e){i?e(null,o):o=new r({storeName:"swordjs",dbVersion:4,autoIncrement:!0,indexes:[{name:"modules",keyPath:"moduleKey",unique:!0}],onStoreReady:function(){i=!0,e&&e(null,o)},onError:function(t){i=!1,e&&e(t)}})}function s(){return r}var r=n(28),i=!1,o=null,u={getDB:a,getIDBWrapper:s};e.exports=u},function(e,t,n){"use strict";function a(e,t,n){if(!(this instanceof a))throw new TypeError("Module constructor cannot be called as a function.");this.modKey=e,this.language=n.language,this.id=t,this.config=n}function s(e,t){r.getBlob(e,t)}var r=n(2),i=n(5),o=n(15),u=n(16),h=n(17),l=n(4);a.create=function(e,t,n){return new a(e,t,n)},a.prototype={constructor:a,self:this,renderText:function(e,t,n){var a=null,l=null,c=this;"function"==typeof t&&(n=t);var f=i.parseVerseList(e,this.config.Versification);0!==f.length&&""!==f[0].osisRef?r.get(c.config.bcvPosID,function(e,r){e?n(e):(r.nt&&(r.nt.hasOwnProperty(f[0].book)||r.nt.hasOwnProperty(f[0].osisRef))?(a=r.nt[f[0].book]||r.nt[f[0].osisRef],l=c.config.nt):r.ot&&(r.ot.hasOwnProperty(f[0].book)||r.ot.hasOwnProperty(f[0].osisRef))&&(a=r.ot[f[0].book]||r.ot[f[0].osisRef],l=c.config.ot),null===a?n({message:"The requested chapter is not available in this module."}):s(l,function(e,s){e?n(e):"zText"===c.config.modDrv||"zCom"===c.config.modDrv?o.getRawEntry(s,a,f,c.config.Encoding,t.intro?t.intro:!1,function(e,a){if(e)n(e);else{var s=h.processText(a,c.config.SourceType,c.config.Direction,t);n(null,s)}}):"RawCom"===c.config.modDrv&&u.getRawEntry(s,a,f,c.config.Encoding,t.intro?t.intro:!1,function(e,a){if(e)n(e);else{var s=h.processText(a,c.config.SourceType,c.config.Direction,t);n(null,s)}})}))}):n({message:"Wrong passage. The requested chapter is not available in this module."})},getAllBooks:function(e){l.getAllBooks(this.config.bcvPosID,this.config.Versification,function(t,n){e(t,n)})},getVersesInChapter:function(e){return l.getVersesInChapter(l.getBookNum(e.split(".")[0],this.config.Versification),e.split(".")[1],this.config.Versification)}},e.exports=a},function(e,t,n){(function(){var e,t,n,a={}.hasOwnProperty;this.bcv_parser=e=function(){function e(){var t,n,s;this.options={},n=e.prototype.options;for(t in n)a.call(n,t)&&(s=n[t],this.options[t]=s);this.versification_system(this.options.versification_system)}return e.prototype.s="",e.prototype.entities=[],e.prototype.passage=null,e.prototype.regexps={},e.prototype.options={consecutive_combination_strategy:"combine",osis_compaction_strategy:"b",book_sequence_strategy:"ignore",invalid_sequence_strategy:"ignore",sequence_combination_strategy:"combine",invalid_passage_strategy:"ignore",non_latin_digits_strategy:"ignore",passage_existence_strategy:"bcv",zero_chapter_strategy:"error",zero_verse_strategy:"error",book_alone_strategy:"ignore",book_range_strategy:"ignore",captive_end_digits_strategy:"delete",end_range_digits_strategy:"verse",include_apocrypha:!1,ps151_strategy:"c",versification_system:"default",case_sensitive:"none"},e.prototype.parse=function(e){var t;return this.reset(),this.s=e,e=this.replace_control_characters(e),t=this.match_books(e),e=t[0],this.passage.books=t[1],this.entities=this.match_passages(e)[0],this},e.prototype.parse_with_context=function(e,t){var n;return this.reset(),n=this.match_books(this.replace_control_characters(t)),t=n[0],this.passage.books=n[1],t=this.match_passages(t)[1],this.reset(),this.s=e,e=this.replace_control_characters(e),n=this.match_books(e),e=n[0],this.passage.books=n[1],this.passage.books.push({value:"",parsed:[],start_index:0,type:"context",context:t}),e=""+(this.passage.books.length-1)+"/9"+e,this.entities=this.match_passages(e)[0],this},e.prototype.reset=function(){return this.s="",this.entities=[],this.passage?(this.passage.books=[],this.passage.indices={}):(this.passage=new t,this.passage.options=this.options,this.passage.translations=this.translations)},e.prototype.set_options=function(e){var t,n;for(t in e)a.call(e,t)&&(n=e[t],"include_apocrypha"===t||"versification_system"===t||"case_sensitive"===t?this[t](n):this.options[t]=n);return this},e.prototype.include_apocrypha=function(e){var t,s,r,i;if(null==e||!0!==e&&!1!==e)return this;this.options.include_apocrypha=e,this.regexps.books=this.regexps.get_books(e,this.options.case_sensitive),r=this.translations;for(i in r)a.call(r,i)&&"aliases"!==i&&"alternates"!==i&&(null==(t=this.translations[i]).chapters&&(t.chapters={}),null==(s=this.translations[i].chapters).Ps&&(s.Ps=n.shallow_clone_array(this.translations["default"].chapters.Ps)),!0===e?(t=null!=this.translations[i].chapters.Ps151?this.translations[i].chapters.Ps151[0]:this.translations["default"].chapters.Ps151[0],this.translations[i].chapters.Ps[150]=t):151===this.translations[i].chapters.Ps.length&&this.translations[i].chapters.Ps.pop());return this},e.prototype.versification_system=function(e){var t,s,r,i,o;if(null==e||null==this.translations[e])return this;if(null!=this.translations.alternates["default"])if("default"===e)for(i in null!=this.translations.alternates["default"].order&&(this.translations["default"].order=n.shallow_clone(this.translations.alternates["default"].order)),o=this.translations.alternates["default"].chapters)a.call(o,i)&&(s=o[i],this.translations["default"].chapters[i]=n.shallow_clone_array(s));else this.versification_system("default");if(null==(t=this.translations.alternates)["default"]&&(t["default"]={order:null,chapters:{}}),"default"!==e&&null!=this.translations[e].order&&(null==(s=this.translations.alternates["default"]).order&&(s.order=n.shallow_clone(this.translations["default"].order)),this.translations["default"].order=n.shallow_clone(this.translations[e].order)),"default"!==e&&null!=this.translations[e].chapters)for(i in t=this.translations[e].chapters)a.call(t,i)&&(s=t[i],null==(r=this.translations.alternates["default"].chapters)[i]&&(r[i]=n.shallow_clone_array(this.translations["default"].chapters[i])),this.translations["default"].chapters[i]=n.shallow_clone_array(s));return this.options.versification_system=e,this.include_apocrypha(this.options.include_apocrypha),this},e.prototype.case_sensitive=function(e){return null==e||"none"!==e&&"books"!==e||e===this.options.case_sensitive?this:(this.options.case_sensitive=e,this.regexps.books=this.regexps.get_books(this.options.include_apocrypha,e),this)},e.prototype.translation_info=function(e){var t,s,r,i,o;null==e&&(e="default"),null!=e&&null!=(null!=(r=this.translations.aliases[e])?r.alias:void 0)&&(e=this.translations.aliases[e].alias),(null==e||null==this.translations[e])&&(e="default"),r=this.options.versification_system,e!==r&&this.versification_system(e),i={order:n.shallow_clone(this.translations["default"].order),books:[],chapters:{}},o=this.translations["default"].chapters;for(t in o)a.call(o,t)&&(s=o[t],i.chapters[t]=n.shallow_clone_array(s));o=i.order;for(t in o)a.call(o,t)&&(s=o[t],i.books[s-1]=t);return e!==r&&this.versification_system(r),i},e.prototype.replace_control_characters=function(e){return e=e.replace(this.regexps.control," "),"replace"===this.options.non_latin_digits_strategy&&(e=e.replace(/[\u0660\u06f0\u07c0\u0966\u09e6\u0a66\u0ae6\u0b660\u0c66\u0ce6\u0d66\u0e50\u0ed0\u0f20\u1040\u1090\u17e0\u1810\u1946\u19d0\u1a80\u1a90\u1b50\u1bb0\u1c40\u1c50\ua620\ua8d0\ua900\ua9d0\uaa50\uabf0\uff10]/g,"0"),e=e.replace(/[\u0661\u06f1\u07c1\u0967\u09e7\u0a67\u0ae7\u0b67\u0be7\u0c67\u0ce7\u0d67\u0e51\u0ed1\u0f21\u1041\u1091\u17e1\u1811\u1947\u19d1\u1a81\u1a91\u1b51\u1bb1\u1c41\u1c51\ua621\ua8d1\ua901\ua9d1\uaa51\uabf1\uff11]/g,"1"),e=e.replace(/[\u0662\u06f2\u07c2\u0968\u09e8\u0a68\u0ae8\u0b68\u0be8\u0c68\u0ce8\u0d68\u0e52\u0ed2\u0f22\u1042\u1092\u17e2\u1812\u1948\u19d2\u1a82\u1a92\u1b52\u1bb2\u1c42\u1c52\ua622\ua8d2\ua902\ua9d2\uaa52\uabf2\uff12]/g,"2"),e=e.replace(/[\u0663\u06f3\u07c3\u0969\u09e9\u0a69\u0ae9\u0b69\u0be9\u0c69\u0ce9\u0d69\u0e53\u0ed3\u0f23\u1043\u1093\u17e3\u1813\u1949\u19d3\u1a83\u1a93\u1b53\u1bb3\u1c43\u1c53\ua623\ua8d3\ua903\ua9d3\uaa53\uabf3\uff13]/g,"3"),e=e.replace(/[\u0664\u06f4\u07c4\u096a\u09ea\u0a6a\u0aea\u0b6a\u0bea\u0c6a\u0cea\u0d6a\u0e54\u0ed4\u0f24\u1044\u1094\u17e4\u1814\u194a\u19d4\u1a84\u1a94\u1b54\u1bb4\u1c44\u1c54\ua624\ua8d4\ua904\ua9d4\uaa54\uabf4\uff14]/g,"4"),e=e.replace(/[\u0665\u06f5\u07c5\u096b\u09eb\u0a6b\u0aeb\u0b6b\u0beb\u0c6b\u0ceb\u0d6b\u0e55\u0ed5\u0f25\u1045\u1095\u17e5\u1815\u194b\u19d5\u1a85\u1a95\u1b55\u1bb5\u1c45\u1c55\ua625\ua8d5\ua905\ua9d5\uaa55\uabf5\uff15]/g,"5"),e=e.replace(/[\u0666\u06f6\u07c6\u096c\u09ec\u0a6c\u0aec\u0b6c\u0bec\u0c6c\u0cec\u0d6c\u0e56\u0ed6\u0f26\u1046\u1096\u17e6\u1816\u194c\u19d6\u1a86\u1a96\u1b56\u1bb6\u1c46\u1c56\ua626\ua8d6\ua906\ua9d6\uaa56\uabf6\uff16]/g,"6"),e=e.replace(/[\u0667\u06f7\u07c7\u096d\u09ed\u0a6d\u0aed\u0b6d\u0bed\u0c6d\u0ced\u0d6d\u0e57\u0ed7\u0f27\u1047\u1097\u17e7\u1817\u194d\u19d7\u1a87\u1a97\u1b57\u1bb7\u1c47\u1c57\ua627\ua8d7\ua907\ua9d7\uaa57\uabf7\uff17]/g,"7"),e=e.replace(/[\u0668\u06f8\u07c8\u096e\u09ee\u0a6e\u0aee\u0b6e\u0bee\u0c6e\u0cee\u0d6e\u0e58\u0ed8\u0f28\u1048\u1098\u17e8\u1818\u194e\u19d8\u1a88\u1a98\u1b58\u1bb8\u1c48\u1c58\ua628\ua8d8\ua908\ua9d8\uaa58\uabf8\uff18]/g,"8"),e=e.replace(/[\u0669\u06f9\u07c9\u096f\u09ef\u0a6f\u0aef\u0b6f\u0bef\u0c6f\u0cef\u0d6f\u0e59\u0ed9\u0f29\u1049\u1099\u17e9\u1819\u194f\u19d9\u1a89\u1a99\u1b59\u1bb9\u1c49\u1c59\ua629\ua8d9\ua909\ua9d9\uaa59\uabf9\uff19]/g,"9")),e},e.prototype.match_books=function(e){var t,n,a,s,r;for(n=[],r=this.regexps.books,a=0,s=r.length;s>a;a++)t=r[a],e=e.replace(t.regexp,function(e,a,s){return n.push({value:s,parsed:t.osis,type:"book"}),a+""+(n.length-1)+(null!=t.extra?"/"+t.extra:"")+""});return e=e.replace(this.regexps.translations,function(e){return n.push({value:e,parsed:e.toLowerCase(),type:"translation"}),""+(n.length-1)+""}),[e,this.get_book_indices(n,e)]},e.prototype.get_book_indices=function(e,t){var n,a,s;for(n=0,s=/([\x1f\x1e])(\d+)(?:\/\d+)?\1/g;a=s.exec(t);)e[a[2]].start_index=a.index+n,n+=e[a[2]].value.length-a[0].length;return e},e.prototype.match_passages=function(e){var t,n,a,r,i,o;for(a=[],n={};t=this.regexps.escaped_passage.exec(e);)r=t[0],o=t[1],n=t[2],i=o.length,t.index+=r.length-i,/\s[2-9]\d\d\s*$|\s\d{4,}\s*$/.test(o)&&(r=/\s+\d+\s*$/,o=o.replace(r,"")),/[\d\x1f\x1e)]$/.test(o)||(o=this.replace_match_end(o)),"delete"===this.options.captive_end_digits_strategy&&(t=t.index+o.length,e.length>t&&/^\w/.test(e.substr(t,1))&&(o=o.replace(/[\s*]+\d+$/,"")),o=o.replace(/(\x1e[)\]]?)[\s*]*\d+$/,"$1")),o=o.replace(/[A-Z]+/g,function(e){return e.toLowerCase()}),r=""===o.substr(0,1)?0:o.split("")[0].length,t={value:s.parse(o),type:"base",start_index:this.passage.books[n].start_index-r,match:o},"full"===this.options.book_alone_strategy&&"include"===this.options.book_range_strategy&&"b"===t.value[0].type&&(1===t.value.length||1<t.value.length&&"translation_sequence"===t.value[1].type)&&0===r&&(1===this.passage.books[n].parsed.length||1<this.passage.books[n].parsed.length&&"translation"===this.passage.books[n].parsed[1].type)&&/^[234]/.test(this.passage.books[n].parsed[0])&&this.create_book_range(e,t,n),n=this.passage.handle_obj(t),t=n[0],n=n[1],a=a.concat(t),i=this.adjust_regexp_end(t,i,o.length),i>0&&(this.regexps.escaped_passage.lastIndex-=i);return[a,n]},e.prototype.adjust_regexp_end=function(e,t,n){var a;return a=0,0<e.length?a=t-e[e.length-1].indices[1]-1:t!==n&&(a=t-n),a},e.prototype.replace_match_end=function(e){var t,n;for(n=e.length;t=this.regexps.match_end_split.exec(e);)n=t.index+t[0].length;return n<e.length&&(e=e.substr(0,n)),e},e.prototype.create_book_range=function(t,n,a){var s,r,i,o,u;for(s=[e.prototype.regexps.first,e.prototype.regexps.second,e.prototype.regexps.third],o=parseInt(this.passage.books[a].parsed[0].substr(0,1),10),r=i=1;o>=1?o>i:i>o;r=o>=1?++i:--i)if(u=r===o-1?e.prototype.regexps.range_and:e.prototype.regexps.range_only,u=t.match(RegExp("(?:^|\\W)("+s[r-1]+"\\s*"+u+"\\s*)\\x1f"+a+"\\x1f","i")),null!=u)return this.add_book_range_object(n,u,r);return!1},e.prototype.add_book_range_object=function(e,t,n){var a,s,r,i;if(a=t[1].length,e.value[0]={type:"b_range_pre",value:[{type:"b_pre",value:n.toString(),indices:[t.index,t.index+a]},e.value[0]],indices:[0,e.value[0].indices[1]+a]},e.value[0].value[1].indices[0]+=a,e.value[0].value[1].indices[1]+=a,e.start_index-=a,e.match=t[1]+e.match,1!==e.value.length){for(i=[],t=n=1,s=e.value.length;s>=1?s>n:n>s;t=s>=1?++n:--n)null!=e.value[t].value&&(null!=(null!=(r=e.value[t].value[0])?r.indices:void 0)&&(e.value[t].value[0].indices[0]+=a,e.value[t].value[0].indices[1]+=a),e.value[t].indices[0]+=a,i.push(e.value[t].indices[1]+=a));return i}},e.prototype.osis=function(){var e,t,n,a,s;for(a=[],s=this.parsed_entities(),e=0,t=s.length;t>e;e++)n=s[e],0<n.osis.length&&a.push(n.osis);return a.join(",")},e.prototype.osis_and_translations=function(){var e,t,n,a,s;for(a=[],s=this.parsed_entities(),e=0,t=s.length;t>e;e++)n=s[e],0<n.osis.length&&a.push([n.osis,n.translations.join(",")]);return a},e.prototype.osis_and_indices=function(){var e,t,n,a,s;for(a=[],s=this.parsed_entities(),e=0,t=s.length;t>e;e++)n=s[e],0<n.osis.length&&a.push({osis:n.osis,translations:n.translations,indices:n.indices});return a},e.prototype.parsed_entities=function(){var e,t,n,a,s,r,i,o,u,h,l,c,f,d;for(o=[],t=a=0,h=this.entities.length;h>=0?h>a:a>h;t=h>=0?++a:--a)if(e=this.entities[t],e.type&&"translation_sequence"===e.type&&0<o.length&&t===o[o.length-1].entity_id+1&&(o[o.length-1].indices[1]=e.absolute_indices[1]),null!=e.passages&&!("b"===e.type&&"ignore"===this.options.book_alone_strategy||"b_range"===e.type&&"ignore"===this.options.book_range_strategy||"context"===e.type)){if(d=[],f=null,null!=e.passages[0].translations)for(r=e.passages[0].translations,s=0,n=r.length;n>s;s++)i=r[s],u=0<(null!=(l=i.osis)?l.length:void 0)?i.osis:"",null==f&&(f=i.alias),d.push(u);else d=[""],f="default";for(s=[],r=e.passages.length,n=i=0,c=r;c>=0?c>i:i>c;n=c>=0?++i:--i)u=e.passages[n],null==u.type&&(u.type=e.type),(!1!==u.valid.valid||("ignore"===this.options.invalid_sequence_strategy&&"sequence"===e.type&&this.snap_sequence("ignore",e,s,n,r),"ignore"!==this.options.invalid_passage_strategy))&&("b"!==u.type&&"b_range"!==u.type||"ignore"!==this.options.book_sequence_strategy||"sequence"!==e.type?("b_range_start"!==u.type&&"range_end_b"!==u.type||"ignore"!==this.options.book_range_strategy||this.snap_range(e,n),null==u.absolute_indices&&(u.absolute_indices=e.absolute_indices),s.push({osis:u.valid.valid?this.to_osis(u.start,u.end,f):"",type:u.type,indices:u.absolute_indices,translations:d,start:u.start,end:u.end,enclosed_indices:u.enclosed_absolute_indices,entity_id:t,entities:[u]})):this.snap_sequence("book",e,s,n,r));if(0!==s.length)if(1<s.length&&"combine"===this.options.consecutive_combination_strategy&&(s=this.combine_consecutive_passages(s,f)),"separate"===this.options.sequence_combination_strategy)o=o.concat(s);else{for(f=[],n=s.length-1,null!=s[n].enclosed_indices&&0<=s[n].enclosed_indices[1]&&(e.absolute_indices[1]=s[n].enclosed_indices[1]),r=0,n=s.length;n>r;r++)i=s[r],0<i.osis.length&&f.push(i.osis);o.push({osis:f.join(","),indices:e.absolute_indices,translations:d,entity_id:t,entities:s})}}return o},e.prototype.to_osis=function(e,t,n){var a;return null==t.c&&null==t.v&&e.b===t.b&&null==e.c&&null==e.v&&"first_chapter"===this.options.book_alone_strategy&&(t.c=1),null==e.c&&(e.c=1),null==e.v&&(e.v=1),null==t.c&&(t.c=0<=this.options.passage_existence_strategy.indexOf("c")||null!=this.passage.translations[n].chapters[t.b]&&1===this.passage.translations[n].chapters[t.b].length?this.passage.translations[n].chapters[t.b].length:999),null==t.v&&(t.v=null!=this.passage.translations[n].chapters[t.b][t.c-1]&&0<=this.options.passage_existence_strategy.indexOf("v")?this.passage.translations[n].chapters[t.b][t.c-1]:999),this.options.include_apocrypha&&"b"===this.options.ps151_strategy&&(151===e.c&&"Ps"===e.b||151===t.c&&"Ps"===t.b)&&this.fix_ps151(e,t,n),"b"===this.options.osis_compaction_strategy&&1===e.c&&1===e.v&&t.c===this.passage.translations[n].chapters[t.b].length&&t.v===this.passage.translations[n].chapters[t.b][t.c-1]?(n=e.b,a=t.b):2>=this.options.osis_compaction_strategy.length&&1===e.v&&(999===t.v||t.v===this.passage.translations[n].chapters[t.b][t.c-1])?(n=e.b+"."+e.c.toString(),a=t.b+"."+t.c.toString()):(n=e.b+"."+e.c.toString()+"."+e.v.toString(),a=t.b+"."+t.c.toString()+"."+t.v.toString()),n=n===a?n:n+"-"+a,null!=e.extra&&(n=e.extra+","+n),null!=t.extra&&(n+=","+t.extra),n},e.prototype.fix_ps151=function(e,t,n){var a;return"default"!==n&&null==(null!=(a=this.translations[n])?a.chapters.Ps151:void 0)&&this.passage.promote_book_to_translation("Ps151",n),151===e.c&&"Ps"===e.b?151===t.c&&"Ps"===t.b?(e.b="Ps151",e.c=1,t.b="Ps151",t.c=1):(e.extra=this.to_osis({b:"Ps151",c:1,v:e.v},{b:"Ps151",c:1,v:this.passage.translations[n].chapters.Ps151[0]},n),e.b="Prov",e.c=1,e.v=1):(t.extra=this.to_osis({b:"Ps151",c:1,v:1},{b:"Ps151",c:1,v:t.v},n),t.c=150,t.v=this.passage.translations[n].chapters.Ps[149])},e.prototype.combine_consecutive_passages=function(e,t){var n,a,s,r,i,o,u,h,l,c;for(h=[],l={},o=e.length-1,n=-1,a=!1,s=i=0;o>=0?o>=i:i>=o;s=o>=0?++i:--i)u=e[s],0<u.osis.length?(c=h.length-1,r=!1,u.enclosed_indices[0]!==n&&(n=u.enclosed_indices[0]),n>=0&&(s===o||e[s+1].enclosed_indices[0]!==u.enclosed_indices[0])&&(a=r=!0),this.is_verse_consecutive(l,u.start,t)?(h[c].end=u.end,h[c].is_enclosed_last=r,h[c].indices[1]=u.indices[1],h[c].enclosed_indices[1]=u.enclosed_indices[1],h[c].osis=this.to_osis(h[c].start,u.end,t)):h.push(u),l={b:u.end.b,c:u.end.c,v:u.end.v}):(h.push(u),l={});return a&&this.snap_enclosed_indices(h),h},e.prototype.snap_enclosed_indices=function(e){var t,n,a;for(t=0,n=e.length;n>t;t++)a=e[t],null!=a.is_enclosed_last&&(0>a.enclosed_indices[0]&&a.is_enclosed_last&&(a.indices[1]=a.enclosed_indices[1]),delete a.is_enclosed_last);return e},e.prototype.is_verse_consecutive=function(e,t,n){var a;if(null==e.b)return!1;if(a=null!=this.passage.translations[n].order?this.passage.translations[n].order:this.passage.translations["default"].order,e.b===t.b){if(e.c===t.c){if(e.v===t.v-1)return!0}else if(1===t.v&&e.c===t.c-1&&e.v===this.passage.translations[n].chapters[e.b][e.c-1])return!0}else if(1===t.c&&1===t.v&&a[e.b]===a[t.b]-1&&e.c===this.passage.translations[n].chapters[e.b].length&&e.v===this.passage.translations[n].chapters[e.b][e.c-1])return!0;return!1},e.prototype.snap_range=function(e,t){var n,s,r,i,o,u;"b_range_start"===e.type||"sequence"===e.type&&"b_range_start"===e.passages[t].type?(n=1,i="end",u="b_range_start"):(n=0,i="start",u="range_end_b"),o="end"===i?"start":"end",r=e.passages[t][o];for(s in r)a.call(r,s)&&(e.passages[t][o][s]=e.passages[t][i][s]);return"sequence"===e.type?(t>=e.value.length&&(t=e.value.length-1),n=this.passage.pluck(u,e.value[t]),null!=n&&(n=this.snap_range(n,0),0===t?e.absolute_indices[0]=n.absolute_indices[0]:e.absolute_indices[1]=n.absolute_indices[1])):(e.original_type=e.type,e.type=e.value[n].type,e.absolute_indices=[e.value[n].absolute_indices[0],e.value[n].absolute_indices[1]]),e},e.prototype.snap_sequence=function(e,t,n,a,s){var r;return r=t.passages[a],r.absolute_indices[0]===t.absolute_indices[0]&&s-1>a&&this.get_snap_sequence_i(t.passages,a,s)!==a?(t.absolute_indices[0]=t.passages[a+1].absolute_indices[0],this.remove_absolute_indices(t.passages,a+1)):r.absolute_indices[1]===t.absolute_indices[1]&&a>0?t.absolute_indices[1]=0<n.length?n[n.length-1].indices[1]:t.passages[a-1].absolute_indices[1]:"book"===e&&s-1>a&&!this.starts_with_book(t.passages[a+1])&&(t.passages[a+1].absolute_indices[0]=r.absolute_indices[0]),t},e.prototype.get_snap_sequence_i=function(e,t,n){var a,s,r;for(a=s=r=t+1;n>=r?n>s:s>n;a=n>=r?++s:--s){if(this.starts_with_book(e[a]))return a;if(e[a].valid.valid)break}return t},e.prototype.starts_with_book=function(e){return"b"===e.type.substr(0,1)||("range"===e.type||"ff"===e.type)&&"b"===e.start.type.substr(0,1)?!0:!1},e.prototype.remove_absolute_indices=function(e,t){var n,a,s,r,i,o;if(0>e[t].enclosed_absolute_indices[0])return!1;for(n=e[t].enclosed_absolute_indices,o=n[0],n=n[1],i=e.slice(t),a=0,s=i.length;s>a&&(r=i[a], r.enclosed_absolute_indices[0]===o&&r.enclosed_absolute_indices[1]===n);a++)r.enclosed_absolute_indices=[-1,-1];return!0},e}(),t=function(){function e(){}return e.prototype.books=[],e.prototype.indices={},e.prototype.options={},e.prototype.translations={},e.prototype.handle_array=function(e,t,n){var a,s,r;for(null==t&&(t=[]),null==n&&(n={}),a=0,s=e.length;s>a;a++)if(r=e[a],null!=r){if("stop"===r.type)break;n=this.handle_obj(r,t,n),t=n[0],n=n[1]}return[t,n]},e.prototype.handle_obj=function(e,t,n){return null!=e.type&&null!=this[e.type]?this[e.type](e,t,n):[t,n]},e.prototype.b=function(e,t,a){var s,r,i,o,u;for(e.start_context=n.shallow_clone(a),e.passages=[],a=[],o=this.books[e.value].parsed,r=0,i=o.length;i>r;r++)s=o[r],u=this.validate_ref(e.start_context.translations,{b:s}),s={start:{b:s},end:{b:s},valid:u},0===e.passages.length&&u.valid?e.passages.push(s):a.push(s);return 0===e.passages.length&&e.passages.push(a.shift()),0<a.length&&(e.passages[0].alternates=a),null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),t.push(e),a={b:e.passages[0].start.b},null!=e.start_context.translations&&(a.translations=e.start_context.translations),[t,a]},e.prototype.b_range=function(e,t,n){return this.range(e,t,n)},e.prototype.b_range_pre=function(e,t,a){var s,r;return e.start_context=n.shallow_clone(a),e.passages=[],s=this.pluck("b",e.value),a=this.b(s,[],a),s=a[0][0],a=a[1],null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),r={b:e.value[0].value+s.passages[0].start.b.substr(1),type:"b"},e.passages=[{start:r,end:s.passages[0].end,valid:s.passages[0].valid}],null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),t.push(e),[t,a]},e.prototype.b_range_start=function(e,t,n){return this.range(e,t,n)},e.prototype.base=function(e,t,n){return this.indices=this.calculate_indices(e.match,e.start_index),this.handle_array(e.value,t,n)},e.prototype.bc=function(e,t,a){var s,r,i,o,u,h,l,c,f;for(e.start_context=n.shallow_clone(a),e.passages=[],this.reset_context(a,["b","c","v"]),i=this.pluck("c",e.value).value,s=[],c=this.books[this.pluck("b",e.value).value].parsed,u=0,h=c.length;h>u;u++)r=c[u],o="c",f=this.validate_ref(e.start_context.translations,{b:r,c:i}),l={start:{b:r},end:{b:r},valid:f},f.messages.start_chapter_not_exist_in_single_chapter_book&&(l.valid=this.validate_ref(e.start_context.translations,{b:r,v:i}),l.valid.messages.start_chapter_not_exist_in_single_chapter_book=1,l.start.c=1,l.end.c=1,o="v"),l.start[o]=i,r=this.fix_start_zeroes(l.valid,l.start.c,l.start.v),l.start.c=r[0],l.start.v=r[1],null==l.start.v&&delete l.start.v,l.end[o]=l.start[o],0===e.passages.length&&l.valid.valid?e.passages.push(l):s.push(l);return 0===e.passages.length&&e.passages.push(s.shift()),0<s.length&&(e.passages[0].alternates=s),null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),this.set_context_from_object(a,["b","c","v"],e.passages[0].start),t.push(e),[t,a]},e.prototype.bc_title=function(e,t,a){var s,r,i,o;if(e.start_context=n.shallow_clone(a),a=this.bc(this.pluck("bc",e.value),[],a),s=a[0][0],a=a[1],"Ps"!==s.passages[0].start.b.substr(0,2)&&null!=s.passages[0].alternates)for(r=i=0,o=s.passages[0].alternates.length;o>=0?o>i:i>o;r=o>=0?++i:--i)if("Ps"===s.passages[0].alternates[r].start.b.substr(0,2)){s.passages[0]=s.passages[0].alternates[r];break}return"Ps"!==s.passages[0].start.b.substr(0,2)?(t.push(s),[t,a]):(this.books[this.pluck("b",s.value).value].parsed=["Ps"],s=this.pluck("title",e.value),null==s&&(s=this.pluck("v",e.value)),e.value[1]={type:"v",value:[{type:"integer",value:1,indices:s.indices}],indices:s.indices},e.type="bcv",this.bcv(e,t,e.start_context))},e.prototype.bcv=function(e,t,a){var s,r,i,o,u,h,l,c;for(e.start_context=n.shallow_clone(a),e.passages=[],this.reset_context(a,["b","c","v"]),i=this.pluck("bc",e.value),o=this.pluck("c",i.value).value,l=this.pluck("v",e.value).value,s=[],h=this.books[this.pluck("b",i.value).value].parsed,i=0,u=h.length;u>i;i++)r=h[i],c=this.validate_ref(e.start_context.translations,{b:r,c:o,v:l}),l=this.fix_start_zeroes(c,o,l),o=l[0],l=l[1],r={start:{b:r,c:o,v:l},end:{b:r,c:o,v:l},valid:c},0===e.passages.length&&c.valid?e.passages.push(r):s.push(r);return 0===e.passages.length&&e.passages.push(s.shift()),0<s.length&&(e.passages[0].alternates=s),null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),this.set_context_from_object(a,["b","c","v"],e.passages[0].start),t.push(e),[t,a]},e.prototype.bv=function(e,t,a){var s;return e.start_context=n.shallow_clone(a),s=e.value,s={indices:e.indices,value:[{type:"bc",value:[s[0],{type:"c",value:[{type:"integer",value:1}]}]},s[1]]},a=this.bcv(s,[],a),s=a[0][0],a=a[1],e.passages=s.passages,null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),t.push(e),[t,a]},e.prototype.c=function(e,t,a){var s,r;return e.start_context=n.shallow_clone(a),s="integer"===e.type?e.value:this.pluck("integer",e.value).value,r=this.validate_ref(e.start_context.translations,{b:a.b,c:s}),!r.valid&&r.messages.start_chapter_not_exist_in_single_chapter_book?this.v(e,t,a):(s=this.fix_start_zeroes(r,s)[0],e.passages=[{start:{b:a.b,c:s},end:{b:a.b,c:s},valid:r}],null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),t.push(e),a.c=s,this.reset_context(a,["v"]),null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),[t,a])},e.prototype.c_psalm=function(e,t,n){var a;return e.type="bc",a=parseInt(this.books[e.value].value.match(/^\d+/)[0],10),e.value=[{type:"b",value:e.value,indices:e.indices},{type:"c",value:[{type:"integer",value:a,indices:e.indices}],indices:e.indices}],this.bc(e,t,n)},e.prototype.c_title=function(e,t,a){return e.start_context=n.shallow_clone(a),"Ps"!==a.b?this.c(e.value[0],t,a):(a=this.pluck("title",e.value),e.value[1]={type:"v",value:[{type:"integer",value:1,indices:a.indices}],indices:a.indices},e.type="cv",this.cv(e,t,e.start_context))},e.prototype.cv=function(e,t,a){var s,r,i;return e.start_context=n.shallow_clone(a),s=this.pluck("c",e.value).value,r=this.pluck("v",e.value).value,i=this.validate_ref(e.start_context.translations,{b:a.b,c:s,v:r}),r=this.fix_start_zeroes(i,s,r),s=r[0],r=r[1],e.passages=[{start:{b:a.b,c:s,v:r},end:{b:a.b,c:s,v:r},valid:i}],null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),t.push(e),a.c=s,a.v=r,null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),[t,a]},e.prototype.cb_range=function(e,t,n){var a,s,r;return e.type="range",s=e.value,a=s[0],r=s[1],s=s[2],e.value=[{type:"bc",value:[a,r],indices:e.indices},s],s.indices[1]=e.indices[1],this.range(e,t,n)},e.prototype.context=function(e,t,s){var r,i;e.start_context=n.shallow_clone(s),e.passages=[],i=this.books[e.value].context;for(r in i)a.call(i,r)&&(s[r]=this.books[e.value].context[r]);return t.push(e),[t,s]},e.prototype.cv_psalm=function(e,t,a){var s,r;return e.start_context=n.shallow_clone(a),e.type="bcv",r=e.value,s=r[0],r=r[1],s=this.c_psalm(s,[],e.start_context)[0][0],e.value=[s,r],this.bcv(e,t,a)},e.prototype.ff=function(e,t,a){return e.start_context=n.shallow_clone(a),e.value.push({type:"integer",indices:e.indices,value:999}),a=this.range(e,[],e.start_context),e=a[0][0],a=a[1],e.value[0].indices=e.value[1].indices,e.value[0].absolute_indices=e.value[1].absolute_indices,e.value.pop(),null!=e.passages[0].valid.messages.end_verse_not_exist&&delete e.passages[0].valid.messages.end_verse_not_exist,null!=e.passages[0].valid.messages.end_chapter_not_exist&&delete e.passages[0].valid.messages.end_chapter_not_exist,null!=e.passages[0].end.original_c&&delete e.passages[0].end.original_c,t.push(e),[t,a]},e.prototype.integer_title=function(e,t,a){return e.start_context=n.shallow_clone(a),"Ps"!==a.b?this.integer(e.value[0],t,a):(e.value[0]={type:"c",value:[e.value[0]],indices:[e.value[0].indices[0],e.value[0].indices[1]]},a=[e.indices[1]-5,e.indices[1]],e.value[1]={type:"v",value:[{type:"integer",value:1,indices:a}],indices:a},e.type="cv",this.cv(e,t,e.start_context))},e.prototype.integer=function(e,t,n){return null!=n.v?this.v(e,t,n):this.c(e,t,n)},e.prototype.sequence=function(e,t,a){var s,r,i,o,u,h,l,c;for(e.start_context=n.shallow_clone(a),e.passages=[],h=e.value,s=0,i=h.length;i>s;s++)for(u=h[s],a=this.handle_array(u,[],a),u=a[0],u=u[0],a=a[1],l=u.passages,r=0,o=l.length;o>r;r++)c=l[r],null==c.type&&(c.type=u.type),null==c.absolute_indices&&(c.absolute_indices=u.absolute_indices),null!=u.start_context.translations&&(c.translations=u.start_context.translations),c.enclosed_absolute_indices="sequence_post_enclosed"===u.type?u.absolute_indices:[-1,-1],e.passages.push(c);return null==e.absolute_indices&&(e.absolute_indices=0<e.passages.length&&"sequence"===e.type?[e.passages[0].absolute_indices[0],e.passages[e.passages.length-1].absolute_indices[1]]:this.get_absolute_indices(e.indices)),t.push(e),[t,a]},e.prototype.sequence_post_enclosed=function(e,t,n){return this.sequence(e,t,n)},e.prototype.v=function(e,t,a){var s,r,i;return r="integer"===e.type?e.value:this.pluck("integer",e.value).value,e.start_context=n.shallow_clone(a),s=null!=a.c?a.c:1,i=this.validate_ref(e.start_context.translations,{b:a.b,c:s,v:r}),r=this.fix_start_zeroes(i,0,r)[1],e.passages=[{start:{b:a.b,c:s,v:r},end:{b:a.b,c:s,v:r},valid:i}],null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),t.push(e),a.v=r,[t,a]},e.prototype.range=function(e,t,a){var s,r,i,o,u,h;return e.start_context=n.shallow_clone(a),s=e.value,h=s[0],s=s[1],a=this.handle_obj(h,[],a),h=a[0][0],a=a[1],"v"!==s.type||("bc"!==h.type||null!=(r=h.passages)&&null!=(i=r[0])&&null!=(o=i.valid)&&null!=(u=o.messages)&&u.start_chapter_not_exist_in_single_chapter_book)&&"c"!==h.type||"verse"!==this.options.end_range_digits_strategy?(a=this.handle_obj(s,[],a),s=a[0][0],a=a[1],e.value=[h,s],e.indices=[h.indices[0],s.indices[1]],delete e.absolute_indices,i={b:h.passages[0].start.b,c:h.passages[0].start.c,v:h.passages[0].start.v,type:h.type},r={b:s.passages[0].end.b,c:s.passages[0].end.c,v:s.passages[0].end.v,type:s.type},s.passages[0].valid.messages.start_chapter_is_zero&&(r.c=0),s.passages[0].valid.messages.start_verse_is_zero&&(r.v=0),o=this.validate_ref(e.start_context.translations,i,r),o.valid?(s=this.range_handle_valid(o,e,h,i,s,r,t),h=s[0],s=s[1],h?s:(null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),e.passages=[{start:i,end:r,valid:o}],null!=e.start_context.translations&&(e.passages[0].translations=e.start_context.translations),"b"===i.type?e.type="b"===r.type?"b_range":"b_range_start":"b"===r.type&&(e.type="range_end_b"),t.push(e),[t,a])):this.range_handle_invalid(o,e,h,i,s,r,t)):(e.value[0]=h,this.range_change_integer_end(e,t))},e.prototype.range_change_end=function(e,t,n){var a;return a=e.value[1],"integer"===a.type?(a.original_value=a.value,a.value=n):"v"===a.type?(a=this.pluck("integer",a.value),a.original_value=a.value,a.value=n):"cv"===a.type&&(a=this.pluck("c",a.value),a.original_value=a.value,a.value=n),this.handle_obj(e,t,e.start_context)},e.prototype.range_change_integer_end=function(e,t){var n,a;return n=e.value,a=n[0],n=n[1],null==e.original_type&&(e.original_type=e.type),null==e.original_value&&(e.original_value=[a,n]),e.type="integer"===a.type?"cv":a.type+"v","integer"===a.type&&(e.value[0]={type:"c",value:[a],indices:a.indices}),"integer"===n.type&&(e.value[1]={type:"v",value:[n],indices:n.indices}),this.handle_obj(e,t,e.start_context)},e.prototype.range_check_new_end=function(e,t,n,a){var s,r;return s=0,r=null,a.messages.end_chapter_before_start?r="c":a.messages.end_verse_before_start&&(r="v"),null!=r&&(s=this.range_get_new_end_value(t,n,a,r)),s>0&&(t={b:n.b,c:n.c,v:n.v},t[r]=s,e=this.validate_ref(e,t),e.valid||(s=0)),s},e.prototype.range_end_b=function(e,t,n){return this.range(e,t,n)},e.prototype.range_get_new_end_value=function(e,t,n,a){var s;return s=0,"c"===a&&n.messages.end_chapter_is_zero||"v"===a&&n.messages.end_verse_is_zero?s:(10<=e[a]&&10>t[a]&&e[a]-10*Math.floor(e[a]/10)<t[a]?s=t[a]+10*Math.floor(e[a]/10):100<=e[a]&&100>t[a]&&e[a]-100<t[a]&&(s=t[a]+100),s)},e.prototype.range_handle_invalid=function(e,t,n,a,s,r,i){return(!1===e.valid&&(e.messages.end_chapter_before_start||e.messages.end_verse_before_start)&&("integer"===s.type||"v"===s.type)||!1===e.valid&&e.messages.end_chapter_before_start&&"cv"===s.type)&&(e=this.range_check_new_end(t.start_context.translations,a,r,e),e>0)?this.range_change_end(t,i,e):"verse"!==this.options.end_range_digits_strategy||null!=a.v||"integer"!==s.type&&"v"!==s.type||(e="v"===s.type?this.pluck("integer",s.value):s.value,a=this.validate_ref(t.start_context.translations,{b:a.b,c:a.c,v:e}),!a.valid)?(null==t.original_type&&(t.original_type=t.type),t.type="sequence",n=[[n,s],[[n],[s]]],t.original_value=n[0],t.value=n[1],this.sequence(t,i,t.start_context)):this.range_change_integer_end(t,i)},e.prototype.range_handle_valid=function(e,t,n,a,s,r,i){return e.messages.end_chapter_not_exist&&"verse"===this.options.end_range_digits_strategy&&null==a.v&&("integer"===s.type||"v"===s.type)&&0<=this.options.passage_existence_strategy.indexOf("v")&&(n="v"===s.type?this.pluck("integer",s.value):s.value,n=this.validate_ref(t.start_context.translations,{b:a.b,c:a.c,v:n}),n.valid)?[!0,this.range_change_integer_end(t,i)]:(this.range_validate(e,a,r,t),[!1,null])},e.prototype.range_validate=function(e,t,n,a){return e.messages.end_chapter_not_exist||e.messages.end_chapter_not_exist_in_single_chapter_book?(n.original_c=n.c,n.c=e.messages.end_chapter_not_exist?e.messages.end_chapter_not_exist:e.messages.end_chapter_not_exist_in_single_chapter_book,null!=n.v&&(n.v=this.validate_ref(a.start_context.translations,{b:n.b,c:n.c,v:999}).messages.end_verse_not_exist,delete e.messages.end_verse_is_zero)):e.messages.end_verse_not_exist&&(n.original_v=n.v,n.v=e.messages.end_verse_not_exist),e.messages.end_verse_is_zero&&"allow"!==this.options.zero_verse_strategy&&(n.v=e.messages.end_verse_is_zero),e.messages.end_chapter_is_zero&&(n.c=e.messages.end_chapter_is_zero),e=this.fix_start_zeroes(e,t.c,t.v),t.c=e[0],t.v=e[1],!0},e.prototype.translation_sequence=function(e,t,a){var s,r,i,o,u;for(e.start_context=n.shallow_clone(a),o=[],o.push({translation:this.books[e.value[0].value].parsed}),i=e.value[1],s=0,r=i.length;r>s;s++)u=i[s],u=this.books[this.pluck("translation",u).value].parsed,null!=u&&o.push({translation:u});for(s=0,r=o.length;r>s;s++)i=o[s],null!=this.translations.aliases[i.translation]?(i.alias=this.translations.aliases[i.translation].alias,i.osis=this.translations.aliases[i.translation].osis||""):(i.alias="default",i.osis=i.translation.toUpperCase());return 0<t.length&&(a=this.translation_sequence_apply(t,o)),null==e.absolute_indices&&(e.absolute_indices=this.get_absolute_indices(e.indices)),t.push(e),this.reset_context(a,["translations"]),[t,a]},e.prototype.translation_sequence_apply=function(e,t){var a,s,r,i;for(i=0,a=s=r=e.length-1;0>=r?0>=s:s>=0;a=0>=r?++s:--s)if(null!=e[a].original_type&&(e[a].type=e[a].original_type),null!=e[a].original_value&&(e[a].value=e[a].original_value),"translation_sequence"===e[a].type){i=a+1;break}return i<e.length?(e[i].start_context.translations=t,a=this.handle_array(e.slice(i),[],e[i].start_context),a=a[1]):a=n.shallow_clone(e[e.length-1].start_context),a},e.prototype.pluck=function(e,t){var n,a,s;for(n=0,a=t.length;a>n;n++)if(s=t[n],null!=s&&null!=s.type&&s.type===e)return"c"===e||"v"===e?this.pluck("integer",s.value):s;return null},e.prototype.set_context_from_object=function(e,t,n){var a,s,r,i;for(r=[],a=0,s=t.length;s>a;a++)i=t[a],null!=n[i]&&r.push(e[i]=n[i]);return r},e.prototype.reset_context=function(e,t){var n,a,s,r;for(s=[],n=0,a=t.length;a>n;n++)r=t[n],s.push(delete e[r]);return s},e.prototype.fix_start_zeroes=function(e,t,n){return e.messages.start_chapter_is_zero&&"upgrade"===this.options.zero_chapter_strategy&&(t=e.messages.start_chapter_is_zero),e.messages.start_verse_is_zero&&"upgrade"===this.options.zero_verse_strategy&&(n=e.messages.start_verse_is_zero),[t,n]},e.prototype.calculate_indices=function(e,t){var n,a,s,r,i,o,u,h,l,c,f,d;for(f="book",a=[],u=0,t=parseInt(t,10),l=[e],c=["",""],s=0,i=c.length;i>s;s++){for(n=c[s],d=[],r=0,o=l.length;o>r;r++)h=l[r],d=d.concat(h.split(n));l=d}for(r=0,s=l.length;s>r;r++)h=l[r],f="book"===f?"rest":"book",i=h.length,0!==i&&("book"===f?(h=h.replace(/\/\d+$/,""),n=u+i,0<a.length&&a[a.length-1].index===t?a[a.length-1].end=n:a.push({start:u,end:n,index:t}),u+=i+2,t=this.books[h].start_index+this.books[h].value.length-u,a.push({start:n+1,end:n+1,index:t})):(n=u+i-1,0<a.length&&a[a.length-1].index===t?a[a.length-1].end=n:a.push({start:u,end:n,index:t}),u+=i));return a},e.prototype.get_absolute_indices=function(e){var t,n,a,s,r,i,o;for(i=e[0],e=e[1],t=o=null,r=this.indices,a=0,s=r.length;s>a;a++)if(n=r[a],null===o&&n.start<=i&&i<=n.end&&(o=i+n.index),n.start<=e&&e<=n.end){t=e+n.index+1;break}return[o,t]},e.prototype.validate_ref=function(e,t,n){var a,s,r,i,o,u;for(null!=e&&0<e.length||(e=[{translation:"default",osis:"",alias:"default"}]),u=!1,r={},a=0,s=e.length;s>a;a++)o=e[a],null==o.alias&&(o.alias="default"),null==o.alias?(null==r.translation_invalid&&(r.translation_invalid=[]),r.translation_invalid.push(o)):(null==this.translations.aliases[o.alias]&&(o.alias="default",null==r.translation_unknown&&(r.translation_unknown=[]),r.translation_unknown.push(o)),i=this.validate_start_ref(o.alias,t,r)[0],n&&(i=this.validate_end_ref(o.alias,t,n,i,r)