diff --git a/README.md b/README.md index c055539d2c85ec5e814b3a6c670a9a6515d1f9d1..16a960d566c7848c95b579c44f71a2bae794e902 100644 --- a/README.md +++ b/README.md @@ -48,3 +48,4 @@ Contributions are always welcome! Fork the repo to another git service, make you - PDF.js: https://mozilla.github.io/pdf.js/ (Apache 2.0) - JSZip: https://stuk.github.io/jszip/ (MIT or GPLv3) - EPUB.js: https://github.com/futurepress/epub.js (BSD) +- EPUB.js Reader: https://github.com/futurepress/epubjs-reader (MIT) diff --git a/reader/static/css/epubjs_reader/annotations.css b/reader/static/css/epubjs_reader/annotations.css new file mode 100644 index 0000000000000000000000000000000000000000..bf7fcf9d11e36c40bcb7378f61932fd5c11eeb5f --- /dev/null +++ b/reader/static/css/epubjs_reader/annotations.css @@ -0,0 +1,3 @@ +.annotator-adder { + width: 80px; +} \ No newline at end of file diff --git a/reader/static/css/epubjs_reader/main.css b/reader/static/css/epubjs_reader/main.css new file mode 100644 index 0000000000000000000000000000000000000000..e4c93133343f873df9eb97ee915b50542d58cae0 --- /dev/null +++ b/reader/static/css/epubjs_reader/main.css @@ -0,0 +1,817 @@ +@font-face { + font-family: 'fontello'; + src: url('../fonts/fontello.eot?60518104'); + src: url('../fonts/fontello.eot?60518104#iefix') format('embedded-opentype'), + url('../fonts/fontello.woff?60518104') format('woff'), + url('../fonts/fontello.ttf?60518104') format('truetype'), + url('../fonts/fontello.svg?60518104#fontello') format('svg'); + font-weight: normal; + font-style: normal; +} + +body { + background: #4e4e4e; + overflow: hidden; +} + +#main { + /* height: 500px; */ + position: absolute; + width: 100%; + height: 100%; + right: 0; + /* left: 40px; */ +/* -webkit-transform: translate(40px, 0); + -moz-transform: translate(40px, 0); */ + + /* border-radius: 5px 0px 0px 5px; */ + border-radius: 5px; + background: #fff; + overflow: hidden; + -webkit-transition: -webkit-transform .4s, width .2s; + -moz-transition: -webkit-transform .4s, width .2s; + -ms-transition: -webkit-transform .4s, width .2s; + + -moz-box-shadow: inset 0 0 50px rgba(0,0,0,.1); + -webkit-box-shadow: inset 0 0 50px rgba(0,0,0,.1); + -ms-box-shadow: inset 0 0 50px rgba(0,0,0,.1); + box-shadow: inset 0 0 50px rgba(0,0,0,.1); +} + + +#titlebar { + height: 8%; + min-height: 20px; + padding: 10px; + /* margin: 0 50px 0 50px; */ + position: relative; + color: #4f4f4f; + font-weight: 100; + font-family: Georgia, "Times New Roman", Times, serif; + opacity: .5; + text-align: center; + -webkit-transition: opacity .5s; + -moz-transition: opacity .5s; + -ms-transition: opacity .5s; + z-index: 10; +} + +#titlebar:hover { + opacity: 1; +} + +#titlebar a { + width: 18px; + height: 19px; + line-height: 20px; + overflow: hidden; + display: inline-block; + opacity: .5; + padding: 4px; + border-radius: 4px; +} + +#titlebar a::before { + visibility: visible; +} + +#titlebar a:hover { + opacity: .8; + border: 1px rgba(0,0,0,.2) solid; + padding: 3px; +} + +#titlebar a:active { + opacity: 1; + color: rgba(0,0,0,.6); + /* margin: 1px -1px -1px 1px; */ + -moz-box-shadow: inset 0 0 6px rgba(155,155,155,.8); + -webkit-box-shadow: inset 0 0 6px rgba(155,155,155,.8); + -ms-box-shadow: inset 0 0 6px rgba(155,155,155,.8); + box-shadow: inset 0 0 6px rgba(155,155,155,.8); +} + +#book-title { + font-weight: 600; +} + +#title-seperator { + display: none; +} + +#viewer { + width: 80%; + height: 80%; + /* margin-left: 10%; */ + margin: 0 auto; + max-width: 1250px; + z-index: 2; + position: relative; + overflow: hidden; +} + +#viewer iframe { + border: none; +} + +#prev { + left: 40px; +} + +#next { + right: 40px; +} + +.arrow { + position: absolute; + top: 50%; + margin-top: -32px; + font-size: 64px; + color: #E2E2E2; + font-family: arial, sans-serif; + font-weight: bold; + cursor: pointer; + -webkit-user-select: none; + -khtml-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.arrow:hover { + color: #777; +} + +.arrow:active, +.arrow.active { + color: #000; +} + +#sidebar { + background: #6b6b6b; + position: absolute; + /* left: -260px; */ + /* -webkit-transform: translate(-260px, 0); + -moz-transform: translate(-260px, 0); */ + top: 0; + min-width: 300px; + width: 25%; + height: 100%; + -webkit-transition: -webkit-transform .5s; + -moz-transition: -moz-transform .5s; + -ms-transition: -moz-transform .5s; + + overflow: hidden; +} + +#sidebar.open { + /* left: 0; */ + /* -webkit-transform: translate(0, 0); + -moz-transform: translate(0, 0); */ +} + +#main.closed { + /* left: 300px; */ + -webkit-transform: translate(300px, 0); + -moz-transform: translate(300px, 0); + -ms-transform: translate(300px, 0); +} + +#main.single { + width: 75%; +} + +#main.single #viewer { + /* width: 60%; + margin-left: 20%; */ +} + +#panels { + background: #4e4e4e; + position: absolute; + left: 0; + top: 0; + width: 100%; + padding: 13px 0; + height: 14px; + -moz-box-shadow: 0px 1px 3px rgba(0,0,0,.6); + -webkit-box-shadow: 0px 1px 3px rgba(0,0,0,.6); + -ms-box-shadow: 0px 1px 3px rgba(0,0,0,.6); + box-shadow: 0px 1px 3px rgba(0,0,0,.6); +} + +#opener { + /* padding: 10px 10px; */ + float: left; +} + +/* #opener #slider { + width: 25px; +} */ + +#metainfo { + display: inline-block; + text-align: center; + max-width: 80%; +} + +#title-controls { + float: right; +} + +#panels a { + visibility: hidden; + width: 18px; + height: 20px; + overflow: hidden; + display: inline-block; + color: #ccc; + margin-left: 6px; +} + +#panels a::before { + visibility: visible; +} + +#panels a:hover { + color: #AAA; +} + +#panels a:active { + color: #AAA; + margin: 1px 0 -1px 6px; +} + +#panels a.active, +#panels a.active:hover { + color: #AAA; +} + +#searchBox { + width: 165px; + float: left; + margin-left: 10px; + margin-top: -1px; + /* + border-radius: 5px; + background: #9b9b9b; + float: left; + margin-left: 5px; + margin-top: -5px; + padding: 3px 10px; + color: #000; + border: none; + outline: none; */ + +} + +input::-webkit-input-placeholder { + color: #454545; +} +input:-moz-placeholder { + color: #454545; +} +input:-ms-placeholder { + color: #454545; +} + +#divider { + position: absolute; + width: 1px; + border-right: 1px #000 solid; + height: 80%; + z-index: 1; + left: 50%; + margin-left: -1px; + top: 10%; + opacity: .15; + box-shadow: -2px 0 15px rgba(0, 0, 0, 1); + display: none; +} + +#divider.show { + display: block; +} + +#loader { + position: absolute; + z-index: 10; + left: 50%; + top: 50%; + margin: -33px 0 0 -33px; +} + +#tocView, +#bookmarksView { + overflow-x: hidden; + overflow-y: hidden; + min-width: 300px; + width: 25%; + height: 100%; + visibility: hidden; + -webkit-transition: visibility 0 ease .5s; + -moz-transition: visibility 0 ease .5s; + -ms-transition: visibility 0 ease .5s; +} + + + +#sidebar.open #tocView, +#sidebar.open #bookmarksView { + overflow-y: auto; + visibility: visible; + -webkit-transition: visibility 0 ease 0; + -moz-transition: visibility 0 ease 0; + -ms-transition: visibility 0 ease 0; +} + +#sidebar.open #tocView { + display: block; +} + +#tocView > ul, +#bookmarksView > ul { + margin-top: 15px; + margin-bottom: 50px; + padding-left: 20px; + display: block; +} + +#tocView li, +#bookmarksView li { + margin-bottom:10px; + width: 225px; + font-family: Georgia, "Times New Roman", Times, serif; + list-style: none; + text-transform: capitalize; +} + +#tocView li:active, +#tocView li.currentChapter +{ + list-style: none; +} + +.list_item a { + color: #AAA; + text-decoration: none; +} + +.list_item a.chapter { + font-size: 1em; +} + +.list_item a.section { + font-size: .8em; +} + +.list_item.currentChapter > a, +.list_item a:hover { + color: #f1f1f1 +} + +/* #tocView li.openChapter > a, */ +.list_item a:hover { + color: #E2E2E2; +} + +.list_item ul { + padding-left:10px; + margin-top: 8px; + display: none; +} + +.list_item.currentChapter > ul, +.list_item.openChapter > ul { + display: block; +} + +#tocView.hidden { + display: none; +} + +.toc_toggle { + display: inline-block; + width: 14px; + cursor: pointer; + -webkit-user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none; +} + +.toc_toggle:before { + content: '▸'; + color: #fff; + margin-right: -4px; +} + +.currentChapter > .toc_toggle:before, +.openChapter > .toc_toggle:before { + content: '▾'; +} + +.view { + width: 300px; + height: 100%; + display: none; + padding-top: 50px; + overflow-y: auto; +} + +#searchResults { + margin-bottom: 50px; + padding-left: 20px; + display: block; +} + +#searchResults li { + margin-bottom:10px; + width: 225px; + font-family: Georgia, "Times New Roman", Times, serif; + list-style: none; +} + +#searchResults a { + color: #AAA; + text-decoration: none; +} + +#searchResults p { + text-decoration: none; + font-size: 12px; + line-height: 16px; +} + +#searchResults p .match { + background: #ccc; + color: #000; +} + +#searchResults li > p { + color: #AAA; +} + +#searchResults li a:hover { + color: #E2E2E2; +} + +#searchView.shown { + display: block; + overflow-y: scroll; +} + +#notes { + padding: 0 0 0 34px; +} + +#notes li { + color: #eee; + font-size: 12px; + width: 240px; + border-top: 1px #fff solid; + padding-top: 6px; + margin-bottom: 6px; +} + +#notes li a { + color: #fff; + display: inline-block; + margin-left: 6px; +} + +#notes li a:hover { + text-decoration: underline; +} + +#notes li img { + max-width: 240px; +} + +#note-text { + display: block; + width: 260px; + height: 80px; + margin: 0 auto; + padding: 5px; + border-radius: 5px; +} + +#note-text[disabled], #note-text[disabled="disabled"]{ + opacity: .5; +} + +#note-anchor { + margin-left: 218px; + margin-top: 5px; +} + +#settingsPanel { + display:none; +} + +#settingsPanel h3 { + color:#f1f1f1; + font-family:Georgia, "Times New Roman", Times, serif; + margin-bottom:10px; +} + +#settingsPanel ul { + margin-top:60px; + list-style-type:none; +} + +#settingsPanel li { + font-size:1em; + color:#f1f1f1; +} + +#settingsPanel .xsmall { font-size:x-small; } +#settingsPanel .small { font-size:small; } +#settingsPanel .medium { font-size:medium; } +#settingsPanel .large { font-size:large; } +#settingsPanel .xlarge { font-size:x-large; } + +.highlight { background-color: yellow } + +.modal { + position: fixed; + top: 50%; + left: 50%; + width: 50%; + width: 630px; + + height: auto; + z-index: 2000; + visibility: hidden; + margin-left: -320px; + margin-top: -160px; + +} + +.overlay { + position: fixed; + width: 100%; + height: 100%; + visibility: hidden; + top: 0; + left: 0; + z-index: 1000; + opacity: 0; + background: rgba(255,255,255,0.8); + -webkit-transition: all 0.3s; + -moz-transition: all 0.3s; + -ms-transition: all 0.3s; + transition: all 0.3s; +} + +.md-show { + visibility: visible; +} + +.md-show ~ .overlay { + opacity: 1; + visibility: visible; +} + +/* Content styles */ +.md-content { + color: #fff; + background: #6b6b6b; + position: relative; + border-radius: 3px; + margin: 0 auto; + height: 320px; +} + +.md-content h3 { + margin: 0; + padding: 6px; + text-align: center; + font-size: 22px; + font-weight: 300; + opacity: 0.8; + background: rgba(0,0,0,0.1); + border-radius: 3px 3px 0 0; +} + +.md-content > div { + padding: 15px 40px 30px; + margin: 0; + font-weight: 300; + font-size: 14px; +} + +.md-content > div p { + margin: 0; + padding: 10px 0; +} + +.md-content > div ul { + margin: 0; + padding: 0 0 30px 20px; +} + +.md-content > div ul li { + padding: 5px 0; +} + +.md-content button { + display: block; + margin: 0 auto; + font-size: 0.8em; +} + +/* Effect 1: Fade in and scale up */ +.md-effect-1 .md-content { + -webkit-transform: scale(0.7); + -moz-transform: scale(0.7); + -ms-transform: scale(0.7); + transform: scale(0.7); + opacity: 0; + -webkit-transition: all 0.3s; + -moz-transition: all 0.3s; + -ms-transition: all 0.3s; + transition: all 0.3s; +} + +.md-show.md-effect-1 .md-content { + -webkit-transform: scale(1); + -moz-transform: scale(1); + -ms-transform: scale(1); + transform: scale(1); + opacity: 1; +} + +.md-content > .closer { + font-size: 18px; + position: absolute; + right: 0; + top: 0; + font-size: 24px; + padding: 4px; +} + +@media only screen and (max-width: 1040px) { + #viewer{ + width: 50%; + margin-left: 25%; + } + + #divider, + #divider.show { + display: none; + } +} + +@media only screen and (max-width: 900px) { + #viewer{ + width: 60%; + margin-left: 20%; + } + + #prev { + left: 20px; + } + + #next { + right: 20px; + } +} + +@media only screen and (max-width: 550px) { + #viewer{ + width: 80%; + margin-left: 10%; + } + + #prev { + left: 0; + } + + #next { + right: 0; + } + + .arrow { + height: 100%; + top: 45px; + width: 10%; + text-indent: -10000px; + } + + #main { + -webkit-transform: translate(0, 0); + -moz-transform: translate(0, 0); + -ms-transform: translate(0, 0); + -webkit-transition: -webkit-transform .3s; + -moz-transition: -moz-transform .3s; + -ms-transition: -moz-transform .3s; + } + + #main.closed { + -webkit-transform: translate(260px, 0); + -moz-transform: translate(260px, 0); + -ms-transform: translate(260px, 0); + } + + #titlebar { + /* font-size: 16px; */ + /* margin: 0 50px 0 50px; */ + } + + #metainfo { + font-size: 10px; + } + + #tocView { + width: 260px; + } + + #tocView li { + font-size: 12px; + } + + #tocView > ul{ + padding-left: 10px; + } +} + + +/* For iPad portrait layouts only */ +@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation: portrait) { + #viewer iframe { + width: 460px; + height: 740px; + } +} + /*For iPad landscape layouts only */ +@media only screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation: landscape) { + #viewer iframe { + width: 460px; + height: 415px; + } +} +/* For iPhone portrait layouts only */ +@media only screen and (max-device-width: 480px) and (orientation: portrait) { + #viewer { + width: 256px; + height: 432px; + } + #viewer iframe { + width: 256px; + height: 432px; + } +} +/* For iPhone landscape layouts only */ +@media only screen and (max-device-width: 480px) and (orientation: landscape) { + #viewer iframe { + width: 256px; + height: 124px; + } +} + +[class^="icon-"]:before, [class*=" icon-"]:before { + font-family: "fontello"; + font-style: normal; + font-weight: normal; + speak: none; + + display: inline-block; + text-decoration: inherit; + width: 1em; + margin-right: .2em; + text-align: center; + /* opacity: .8; */ + + /* For safety - reset parent styles, that can break glyph codes*/ + font-variant: normal; + text-transform: none; + + /* you can be more comfortable with increased icons size */ + font-size: 112%; +} + + +.icon-search:before { content: '\e807'; } /* '' */ +.icon-resize-full-1:before { content: '\e804'; } /* '' */ +.icon-cancel-circled2:before { content: '\e80f'; } /* '' */ +.icon-link:before { content: '\e80d'; } /* '' */ +.icon-bookmark:before { content: '\e805'; } /* '' */ +.icon-bookmark-empty:before { content: '\e806'; } /* '' */ +.icon-download-cloud:before { content: '\e811'; } /* '' */ +.icon-edit:before { content: '\e814'; } /* '' */ +.icon-menu:before { content: '\e802'; } /* '' */ +.icon-cog:before { content: '\e813'; } /* '' */ +.icon-resize-full:before { content: '\e812'; } /* '' */ +.icon-cancel-circled:before { content: '\e80e'; } /* '' */ +.icon-up-dir:before { content: '\e80c'; } /* '' */ +.icon-right-dir:before { content: '\e80b'; } /* '' */ +.icon-angle-right:before { content: '\e809'; } /* '' */ +.icon-angle-down:before { content: '\e80a'; } /* '' */ +.icon-right:before { content: '\e815'; } /* '' */ +.icon-list-1:before { content: '\e803'; } /* '' */ +.icon-list-numbered:before { content: '\e801'; } /* '' */ +.icon-columns:before { content: '\e810'; } /* '' */ +.icon-list:before { content: '\e800'; } /* '' */ +.icon-resize-small:before { content: '\e808'; } /* '' */ diff --git a/reader/static/css/epubjs_reader/normalize.css b/reader/static/css/epubjs_reader/normalize.css new file mode 100755 index 0000000000000000000000000000000000000000..c3e014d95765d306354290e99b6e438d8b3096f8 --- /dev/null +++ b/reader/static/css/epubjs_reader/normalize.css @@ -0,0 +1,505 @@ +/*! normalize.css v1.0.1 | MIT License | git.io/normalize */ + +/* ========================================================================== + HTML5 display definitions + ========================================================================== */ + +/* + * Corrects `block` display not defined in IE 6/7/8/9 and Firefox 3. + */ + +article, +aside, +details, +figcaption, +figure, +footer, +header, +hgroup, +nav, +section, +summary { + display: block; +} + +/* + * Corrects `inline-block` display not defined in IE 6/7/8/9 and Firefox 3. + */ + +audio, +canvas, +video { + display: inline-block; + *display: inline; + *zoom: 1; +} + +/* + * Prevents modern browsers from displaying `audio` without controls. + * Remove excess height in iOS 5 devices. + */ + +audio:not([controls]) { + display: none; + height: 0; +} + +/* + * Addresses styling for `hidden` attribute not present in IE 7/8/9, Firefox 3, + * and Safari 4. + * Known issue: no IE 6 support. + */ + +[hidden] { + display: none; +} + +/* ========================================================================== + Base + ========================================================================== */ + +/* + * 1. Corrects text resizing oddly in IE 6/7 when body `font-size` is set using + * `em` units. + * 2. Prevents iOS text size adjust after orientation change, without disabling + * user zoom. + */ + +html { + font-size: 100%; /* 1 */ + -webkit-text-size-adjust: 100%; /* 2 */ + -ms-text-size-adjust: 100%; /* 2 */ +} + +/* + * Addresses `font-family` inconsistency between `textarea` and other form + * elements. + */ + +html, +button, +input, +select, +textarea { + font-family: sans-serif; +} + +/* + * Addresses margins handled incorrectly in IE 6/7. + */ + +body { + margin: 0; +} + +/* ========================================================================== + Links + ========================================================================== */ + +/* + * Addresses `outline` inconsistency between Chrome and other browsers. + */ + +a:focus { + outline: thin dotted; +} + +/* + * Improves readability when focused and also mouse hovered in all browsers. + */ + +a:active, +a:hover { + outline: 0; +} + +/* ========================================================================== + Typography + ========================================================================== */ + +/* + * Addresses font sizes and margins set differently in IE 6/7. + * Addresses font sizes within `section` and `article` in Firefox 4+, Safari 5, + * and Chrome. + */ + +h1 { + font-size: 2em; + margin: 0.67em 0; +} + +h2 { + font-size: 1.5em; + margin: 0.83em 0; +} + +h3 { + font-size: 1.17em; + margin: 1em 0; +} + +h4 { + font-size: 1em; + margin: 1.33em 0; +} + +h5 { + font-size: 0.83em; + margin: 1.67em 0; +} + +h6 { + font-size: 0.75em; + margin: 2.33em 0; +} + +/* + * Addresses styling not present in IE 7/8/9, Safari 5, and Chrome. + */ + +abbr[title] { + border-bottom: 1px dotted; +} + +/* + * Addresses style set to `bolder` in Firefox 3+, Safari 4/5, and Chrome. + */ + +b, +strong { + font-weight: bold; +} + +blockquote { + margin: 1em 40px; +} + +/* + * Addresses styling not present in Safari 5 and Chrome. + */ + +dfn { + font-style: italic; +} + +/* + * Addresses styling not present in IE 6/7/8/9. + */ + +mark { + background: #ff0; + color: #000; +} + +/* + * Addresses margins set differently in IE 6/7. + */ + +p, +pre { + margin: 1em 0; +} + +/* + * Corrects font family set oddly in IE 6, Safari 4/5, and Chrome. + */ + +code, +kbd, +pre, +samp { + font-family: monospace, serif; + _font-family: 'courier new', monospace; + font-size: 1em; +} + +/* + * Improves readability of pre-formatted text in all browsers. + */ + +pre { + white-space: pre; + white-space: pre-wrap; + word-wrap: break-word; +} + +/* + * Addresses CSS quotes not supported in IE 6/7. + */ + +q { + quotes: none; +} + +/* + * Addresses `quotes` property not supported in Safari 4. + */ + +q:before, +q:after { + content: ''; + content: none; +} + +/* + * Addresses inconsistent and variable font size in all browsers. + */ + +small { + font-size: 80%; +} + +/* + * Prevents `sub` and `sup` affecting `line-height` in all browsers. + */ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sup { + top: -0.5em; +} + +sub { + bottom: -0.25em; +} + +/* ========================================================================== + Lists + ========================================================================== */ + +/* + * Addresses margins set differently in IE 6/7. + */ + +dl, +menu, +ol, +ul { + margin: 1em 0; +} + +dd { + margin: 0 0 0 40px; +} + +/* + * Addresses paddings set differently in IE 6/7. + */ + +menu, +ol, +ul { + padding: 0 0 0 40px; +} + +/* + * Corrects list images handled incorrectly in IE 7. + */ + +nav ul, +nav ol { + list-style: none; + list-style-image: none; +} + +/* ========================================================================== + Embedded content + ========================================================================== */ + +/* + * 1. Removes border when inside `a` element in IE 6/7/8/9 and Firefox 3. + * 2. Improves image quality when scaled in IE 7. + */ + +img { + border: 0; /* 1 */ + -ms-interpolation-mode: bicubic; /* 2 */ +} + +/* + * Corrects overflow displayed oddly in IE 9. + */ + +svg:not(:root) { + overflow: hidden; +} + +/* ========================================================================== + Figures + ========================================================================== */ + +/* + * Addresses margin not present in IE 6/7/8/9, Safari 5, and Opera 11. + */ + +figure { + margin: 0; +} + +/* ========================================================================== + Forms + ========================================================================== */ + +/* + * Corrects margin displayed oddly in IE 6/7. + */ + +form { + margin: 0; +} + +/* + * Define consistent border, margin, and padding. + */ + +fieldset { + border: 1px solid #c0c0c0; + margin: 0 2px; + padding: 0.35em 0.625em 0.75em; +} + +/* + * 1. Corrects color not being inherited in IE 6/7/8/9. + * 2. Corrects text not wrapping in Firefox 3. + * 3. Corrects alignment displayed oddly in IE 6/7. + */ + +legend { + border: 0; /* 1 */ + padding: 0; + white-space: normal; /* 2 */ + *margin-left: -7px; /* 3 */ +} + +/* + * 1. Corrects font size not being inherited in all browsers. + * 2. Addresses margins set differently in IE 6/7, Firefox 3+, Safari 5, + * and Chrome. + * 3. Improves appearance and consistency in all browsers. + */ + +button, +input, +select, +textarea { + font-size: 100%; /* 1 */ + margin: 0; /* 2 */ + vertical-align: baseline; /* 3 */ + *vertical-align: middle; /* 3 */ +} + +/* + * Addresses Firefox 3+ setting `line-height` on `input` using `!important` in + * the UA stylesheet. + */ + +button, +input { + line-height: normal; +} + +/* + * 1. Avoid the WebKit bug in Android 4.0.* where (2) destroys native `audio` + * and `video` controls. + * 2. Corrects inability to style clickable `input` types in iOS. + * 3. Improves usability and consistency of cursor style between image-type + * `input` and others. + * 4. Removes inner spacing in IE 7 without affecting normal text inputs. + * Known issue: inner spacing remains in IE 6. + */ + +button, +html input[type="button"], /* 1 */ +input[type="reset"], +input[type="submit"] { + -webkit-appearance: button; /* 2 */ + cursor: pointer; /* 3 */ + *overflow: visible; /* 4 */ +} + +/* + * Re-set default cursor for disabled elements. + */ + +button[disabled], +input[disabled] { + cursor: default; +} + +/* + * 1. Addresses box sizing set to content-box in IE 8/9. + * 2. Removes excess padding in IE 8/9. + * 3. Removes excess padding in IE 7. + * Known issue: excess padding remains in IE 6. + */ + +input[type="checkbox"], +input[type="radio"] { + box-sizing: border-box; /* 1 */ + padding: 0; /* 2 */ + *height: 13px; /* 3 */ + *width: 13px; /* 3 */ +} + +/* + * 1. Addresses `appearance` set to `searchfield` in Safari 5 and Chrome. + * 2. Addresses `box-sizing` set to `border-box` in Safari 5 and Chrome + * (include `-moz` to future-proof). + */ +/* +input[type="search"] { + -webkit-appearance: textfield; + -moz-box-sizing: content-box; + -webkit-box-sizing: content-box; + box-sizing: content-box; +} +*/ + +/* + * Removes inner padding and search cancel button in Safari 5 and Chrome + * on OS X. + */ + +/* input[type="search"]::-webkit-search-cancel-button, +input[type="search"]::-webkit-search-decoration { + -webkit-appearance: none; +} */ + +/* + * Removes inner padding and border in Firefox 3+. + */ + +button::-moz-focus-inner, +input::-moz-focus-inner { + border: 0; + padding: 0; +} + +/* + * 1. Removes default vertical scrollbar in IE 6/7/8/9. + * 2. Improves readability and alignment in all browsers. + */ + +textarea { + overflow: auto; /* 1 */ + vertical-align: top; /* 2 */ +} + +/* ========================================================================== + Tables + ========================================================================== */ + +/* + * Remove most spacing between table cells. + */ + +table { + border-collapse: collapse; + border-spacing: 0; +} diff --git a/reader/static/css/epubjs_reader/popup.css b/reader/static/css/epubjs_reader/popup.css new file mode 100644 index 0000000000000000000000000000000000000000..c41aac71616c0b064e499c67f3a3cd13ea5f6115 --- /dev/null +++ b/reader/static/css/epubjs_reader/popup.css @@ -0,0 +1,96 @@ +/* http://davidwalsh.name/css-tooltips */ +/* base CSS element */ +.popup { + background: #eee; + border: 1px solid #ccc; + padding: 10px; + border-radius: 8px; + box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2); + position: fixed; + max-width: 300px; + font-size: 12px; + + display: none; + margin-left: 2px; + + margin-top: 30px; +} + +.popup.above { + margin-top: -10px; +} + +.popup.left { + margin-left: -20px; +} + +.popup.right { + margin-left: 40px; +} + +.pop_content { + max-height: 225px; + overflow-y: auto; +} + +.pop_content > p { + margin-top: 0; +} + +/* below */ +.popup:before { + position: absolute; + display: inline-block; + border-bottom: 10px solid #eee; + border-right: 10px solid transparent; + border-left: 10px solid transparent; + border-bottom-color: rgba(0, 0, 0, 0.2); + left: 50%; + top: -10px; + margin-left: -6px; + content: ''; +} + +.popup:after { + position: absolute; + display: inline-block; + border-bottom: 9px solid #eee; + border-right: 9px solid transparent; + border-left: 9px solid transparent; + left: 50%; + top: -9px; + margin-left: -5px; + content: ''; +} + +/* above */ +.popup.above:before { + border-bottom: none; + border-top: 10px solid #eee; + border-top-color: rgba(0, 0, 0, 0.2); + top: 100%; +} + +.popup.above:after { + border-bottom: none; + border-top: 9px solid #eee; + top: 100%; +} + +.popup.left:before, +.popup.left:after +{ + left: 20px; +} + +.popup.right:before, +.popup.right:after +{ + left: auto; + right: 20px; +} + + +.popup.show, .popup.on { + display: block; +} \ No newline at end of file diff --git a/reader/static/css/fonts/fontello.eot b/reader/static/css/fonts/fontello.eot new file mode 100644 index 0000000000000000000000000000000000000000..f63ffa043ea29008e7f5b161b87c44ce567d15fc Binary files /dev/null and b/reader/static/css/fonts/fontello.eot differ diff --git a/reader/static/css/fonts/fontello.svg b/reader/static/css/fonts/fontello.svg new file mode 100644 index 0000000000000000000000000000000000000000..2db13984a48de3f3607b864c0b5b3afb8a16a74b --- /dev/null +++ b/reader/static/css/fonts/fontello.svg @@ -0,0 +1,33 @@ +<?xml version="1.0" standalone="no"?> +<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"> +<svg xmlns="http://www.w3.org/2000/svg"> +<metadata>Copyright (C) 2013 by original authors @ fontello.com</metadata> +<defs> +<font id="fontello" horiz-adv-x="1000" > +<font-face font-family="fontello" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" /> +<missing-glyph horiz-adv-x="1000" /> +<glyph glyph-name="search" unicode="" d="m643 386q0 103-74 176t-176 74t-177-74t-73-176t73-177t177-73t176 73t74 177z m286-465q0-29-22-50t-50-21q-30 0-50 21l-191 191q-100-69-223-69q-80 0-153 31t-125 84t-84 125t-31 153t31 152t84 126t125 84t153 31t152-31t126-84t84-126t31-152q0-123-69-223l191-191q21-21 21-51z" horiz-adv-x="928.6" /> +<glyph glyph-name="resize-full-1" unicode="" d="m784 111l127 128l0-336l-335 0l128 130l-128 127l79 79z m-431 686l-129-127l128-127l-80-80l-126 128l-128-129l0 335l335 0z m0-637l-129-127l129-130l-335 0l0 336l128-128l128 128z m558 637l0-335l-127 129l-128-128l-79 80l127 127l-128 127l335 0z" horiz-adv-x="928" /> +<glyph glyph-name="cancel-circled2" unicode="" d="m612 248l-81-82q-6-5-13-5t-13 5l-76 77l-77-77q-5-5-13-5t-13 5l-81 82q-6 5-6 13t6 13l76 76l-76 76q-6 6-6 13t6 13l81 82q6 5 13 5t13-5l77-77l76 77q6 5 13 5t13-5l81-82q6-5 6-13t-6-13l-76-76l76-76q6-6 6-13t-6-13z m120 102q0 83-41 152t-110 111t-152 41t-153-41t-110-111t-41-152t41-152t110-111t153-41t152 41t110 111t41 152z m125 0q0-117-57-215t-156-156t-215-58t-216 58t-155 156t-58 215t58 215t155 156t216 58t215-58t156-156t57-215z" horiz-adv-x="857.1" /> +<glyph glyph-name="link" unicode="" d="m812 171q0 23-15 38l-116 116q-16 16-38 16q-24 0-40-18q1-1 10-10t12-12t9-11t7-14t2-15q0-23-16-38t-38-16q-8 0-15 2t-14 7t-11 9t-12 12t-10 10q-19-17-19-40q0-23 16-38l115-116q15-15 38-15q22 0 38 15l82 81q15 16 15 37z m-392 394q0 22-15 38l-115 115q-16 16-38 16q-22 0-38-15l-82-82q-16-15-16-37q0-22 16-38l116-116q15-15 38-15q23 0 40 17q-2 2-11 11t-12 12t-8 10t-7 14t-2 16q0 22 15 38t38 15q9 0 16-2t14-7t10-8t12-12t11-11q18 17 18 41z m500-394q0-67-48-113l-82-81q-46-47-113-47q-68 0-114 48l-115 115q-46 47-46 114q0 68 49 116l-49 49q-48-49-116-49q-67 0-114 47l-116 116q-47 47-47 114t47 113l82 82q47 46 114 46q67 0 114-47l114-116q47-46 47-113q0-69-49-117l49-49q48 49 116 49q67 0 114-47l116-116q47-47 47-114z" horiz-adv-x="928.6" /> +<glyph glyph-name="bookmark" unicode="" d="m650 779q12 0 24-5q19-8 29-23t11-35v-719q0-19-11-35t-29-23q-10-4-24-4q-27 0-47 18l-246 236l-246-236q-20-19-46-19q-13 0-25 5q-18 7-29 23t-11 35v719q0 19 11 35t29 23q12 5 25 5h585z" horiz-adv-x="714.3" /> +<glyph glyph-name="bookmark-empty" unicode="" d="m643 707h-572v-693l237 227l49 47l50-47l236-227v693z m7 72q12 0 24-5q19-8 29-23t11-35v-719q0-19-11-35t-29-23q-10-4-24-4q-27 0-47 18l-246 236l-246-236q-20-19-46-19q-13 0-25 5q-18 7-29 23t-11 35v719q0 19 11 35t29 23q12 5 25 5h585z" horiz-adv-x="714.3" /> +<glyph glyph-name="download-cloud" unicode="" d="m714 332q0 8-5 13t-13 5h-125v196q0 8-5 13t-12 5h-108q-7 0-12-5t-5-13v-196h-125q-8 0-13-5t-5-13q0-8 5-13l196-196q5-5 13-5t13 5l196 196q5 6 5 13z m357-125q0-89-62-151t-152-63h-607q-103 0-177 73t-73 177q0 72 39 134t105 92q-1 17-1 24q0 118 84 202t202 84q87 0 159-49t105-129q40 35 93 35q59 0 101-42t42-101q0-43-23-77q72-17 119-76t46-133z" horiz-adv-x="1071.4" /> +<glyph glyph-name="edit" unicode="" d="m496 189l64 65l-85 85l-64-65v-31h53v-54h32z m245 402q-9 9-18 0l-196-196q-9-9 0-18t18 0l196 196q9 9 0 18z m45-331v-106q0-67-47-114t-114-47h-464q-67 0-114 47t-47 114v464q0 66 47 113t114 48h464q35 0 65-14q9-4 10-13q2-10-5-16l-27-28q-8-8-18-4q-13 3-25 3h-464q-37 0-63-26t-27-63v-464q0-37 27-63t63-27h464q37 0 63 27t26 63v70q0 7 5 12l36 36q8 8 20 4t11-16z m-54 411l161-160l-375-375h-161v160z m248-73l-51-52l-161 161l51 51q16 16 38 16t38-16l85-84q16-16 16-38t-16-38z" horiz-adv-x="1000" /> +<glyph glyph-name="menu" unicode="" d="m857 100v-71q0-15-10-25t-26-11h-785q-15 0-25 11t-11 25v71q0 15 11 25t25 11h785q15 0 26-11t10-25z m0 286v-72q0-14-10-25t-26-10h-785q-15 0-25 10t-11 25v72q0 14 11 25t25 10h785q15 0 26-10t10-25z m0 285v-71q0-15-10-25t-26-11h-785q-15 0-25 11t-11 25v71q0 15 11 26t25 10h785q15 0 26-10t10-26z" horiz-adv-x="857.1" /> +<glyph glyph-name="cog" unicode="" d="m571 350q0 59-41 101t-101 42t-101-42t-42-101t42-101t101-42t101 42t41 101z m286 61v-124q0-7-4-13t-11-7l-104-16q-10-30-21-51q19-27 59-77q6-6 6-13t-5-13q-15-21-55-61t-53-39q-7 0-14 5l-77 60q-25-13-51-21q-9-76-16-104q-4-16-20-16h-124q-8 0-14 5t-6 12l-16 103q-27 9-50 21l-79-60q-6-5-14-5q-8 0-14 6q-70 64-92 94q-4 5-4 13q0 6 5 12q8 12 28 37t30 40q-15 28-23 55l-102 15q-7 1-11 7t-5 13v124q0 7 5 13t10 7l104 16q8 25 22 51q-23 32-60 77q-6 7-6 14q0 5 5 12q15 20 55 60t53 40q7 0 15-5l77-60q24 13 50 21q9 76 17 104q3 15 20 15h124q7 0 13-4t7-12l15-103q28-9 50-21l80 60q5 5 13 5q7 0 14-5q72-67 92-95q4-5 4-13q0-6-4-12q-9-12-29-38t-30-39q14-28 23-55l102-15q7-1 12-7t4-13z" horiz-adv-x="857.1" /> +<glyph glyph-name="resize-full" unicode="" d="m421 261q0-8-5-13l-185-185l80-81q10-10 10-25t-10-25t-25-11h-250q-15 0-25 11t-11 25v250q0 15 11 25t25 11t25-11l80-80l185 185q6 6 13 6t13-6l64-63q5-6 5-13z m436 482v-250q0-15-10-25t-26-11t-25 11l-80 80l-185-185q-6-6-13-6t-13 6l-64 63q-5 6-5 13t5 13l186 185l-81 81q-10 10-10 25t10 25t25 11h250q15 0 26-11t10-25z" horiz-adv-x="857.1" /> +<glyph glyph-name="cancel-circled" unicode="" d="m641 224q0 14-10 25l-101 101l101 101q10 11 10 25q0 15-10 26l-51 50q-10 11-25 11q-15 0-25-11l-101-101l-101 101q-11 11-26 11q-15 0-25-11l-50-50q-11-11-11-26q0-14 11-25l101-101l-101-101q-11-11-11-25q0-15 11-26l50-50q10-11 25-11q15 0 26 11l101 101l101-101q10-11 25-11q15 0 25 11l51 50q10 11 10 26z m216 126q0-117-57-215t-156-156t-215-58t-216 58t-155 156t-58 215t58 215t155 156t216 58t215-58t156-156t57-215z" horiz-adv-x="857.1" /> +<glyph glyph-name="up-dir" unicode="" d="m571 171q0-14-10-25t-25-10h-500q-15 0-25 10t-11 25t11 26l250 250q10 10 25 10t25-10l250-250q10-11 10-26z" horiz-adv-x="571.4" /> +<glyph glyph-name="right-dir" unicode="" d="m321 350q0-14-10-25l-250-250q-11-11-25-11t-25 11t-11 25v500q0 15 11 25t25 11t25-11l250-250q10-10 10-25z" horiz-adv-x="357.1" /> +<glyph glyph-name="angle-right" unicode="" d="m332 314q0-7-6-13l-260-260q-5-5-12-5t-13 5l-28 28q-6 6-6 13t6 13l219 219l-219 220q-6 5-6 12t6 13l28 28q5 6 13 6t12-6l260-260q6-5 6-13z" horiz-adv-x="357.1" /> +<glyph glyph-name="angle-down" unicode="" d="m600 439q0-7-6-13l-260-260q-5-5-13-5t-12 5l-260 260q-6 6-6 13t6 13l27 28q6 6 13 6t13-6l219-219l220 219q5 6 13 6t12-6l28-28q6-5 6-13z" horiz-adv-x="642.9" /> +<glyph glyph-name="right" unicode="" d="m1000 404v-108q0-7-5-12t-13-5h-696v-125q0-12-11-17t-19 3l-215 196q-5 5-5 12q0 8 5 14l215 197q9 8 19 4q11-5 11-17v-125h696q8 0 13-5t5-12z" horiz-adv-x="1000" /> +<glyph glyph-name="list-1" unicode="" d="m143 118v-107q0-7-5-13t-13-5h-107q-7 0-13 5t-5 13v107q0 7 5 12t13 6h107q7 0 13-6t5-12z m0 214v-107q0-7-5-13t-13-5h-107q-7 0-13 5t-5 13v107q0 7 5 13t13 5h107q7 0 13-5t5-13z m0 214v-107q0-7-5-12t-13-6h-107q-7 0-13 6t-5 12v107q0 8 5 13t13 5h107q7 0 13-5t5-13z m857-428v-107q0-7-5-13t-13-5h-750q-7 0-12 5t-6 13v107q0 7 6 12t12 6h750q7 0 13-6t5-12z m-857 643v-107q0-8-5-13t-13-5h-107q-7 0-13 5t-5 13v107q0 7 5 12t13 6h107q7 0 13-6t5-12z m857-429v-107q0-7-5-13t-13-5h-750q-7 0-12 5t-6 13v107q0 7 6 13t12 5h750q7 0 13-5t5-13z m0 214v-107q0-7-5-12t-13-6h-750q-7 0-12 6t-6 12v107q0 8 6 13t12 5h750q7 0 13-5t5-13z m0 215v-107q0-8-5-13t-13-5h-750q-7 0-12 5t-6 13v107q0 7 6 12t12 6h750q7 0 13-6t5-12z" horiz-adv-x="1000" /> +<glyph glyph-name="list-numbered" unicode="" d="m213-54q0-45-31-70t-75-26q-60 0-96 37l31 49q28-25 60-25q16 0 28 8t12 24q0 35-59 31l-14 31q4 6 18 24t24 31t20 21v1q-9 0-27-1t-27 0v-30h-59v85h186v-49l-53-65q28-6 45-27t17-49z m1 350v-89h-202q-4 20-4 30q0 29 14 52t31 38t37 27t31 24t14 25q0 14-9 22t-22 7q-25 0-45-32l-47 33q13 28 40 44t59 16q40 0 68-23t28-63q0-28-19-51t-42-36t-42-28t-20-30h71v34h59z m786-178v-107q0-8-5-13t-13-5h-678q-8 0-13 5t-5 13v107q0 8 5 13t13 5h678q7 0 13-6t5-12z m-786 502v-56h-187v56h60q0 22 0 68t1 67v7h-1q-5-10-28-30l-40 42l76 71h59v-225h60z m786-216v-108q0-7-5-12t-13-5h-678q-8 0-13 5t-5 12v108q0 7 5 12t13 5h678q7 0 13-5t5-12z m0 285v-107q0-7-5-12t-13-6h-678q-8 0-13 6t-5 12v107q0 8 5 13t13 5h678q7 0 13-5t5-13z" horiz-adv-x="1000" /> +<glyph glyph-name="columns" unicode="" d="m89-7h340v643h-358v-625q0-8 6-13t12-5z m768 18v625h-357v-643h339q8 0 13 5t5 13z m72 678v-678q0-37-27-63t-63-27h-750q-36 0-63 27t-26 63v678q0 37 26 63t63 27h750q37 0 63-27t27-63z" horiz-adv-x="928.6" /> +<glyph glyph-name="list" unicode="" d="m100 200q20 0 35-15t15-35t-15-35t-35-15l-50 0q-20 0-35 15t-15 35t14 35t36 15l50 0z m0 200q20 0 35-15t15-35t-15-35t-35-15l-50 0q-20 0-35 15t-15 35t14 35t36 15l50 0z m0 200q20 0 35-15t15-35t-15-35t-35-15l-50 0q-20 0-35 15t-15 35t14 35t36 15l50 0z m200-100q-20 0-35 15t-15 35t15 35t35 15l350 0q22 0 36-15t14-35t-15-35t-35-15l-350 0z m350-100q22 0 36-15t14-35t-15-35t-35-15l-350 0q-20 0-35 15t-15 35t15 35t35 15l350 0z m0-200q22 0 36-15t14-35t-15-35t-35-15l-350 0q-20 0-35 15t-15 35t15 35t35 15l350 0z" horiz-adv-x="700" /> +<glyph glyph-name="resize-small" unicode="" d="m429 314v-250q0-14-11-25t-25-10t-25 10l-81 81l-185-186q-5-5-13-5t-13 5l-63 64q-6 5-6 13t6 13l185 185l-80 80q-11 11-11 25t11 25t25 11h250q14 0 25-11t11-25z m421 375q0-7-6-13l-185-185l80-80q11-11 11-25t-11-25t-25-11h-250q-14 0-25 11t-10 25v250q0 14 10 25t25 10t25-10l81-81l185 186q6 5 13 5t13-5l63-64q6-5 6-13z" horiz-adv-x="857.1" /> +</font> +</defs> +</svg> \ No newline at end of file diff --git a/reader/static/css/fonts/fontello.ttf b/reader/static/css/fonts/fontello.ttf new file mode 100644 index 0000000000000000000000000000000000000000..95715f86629cdbe17012ceb0595caaf61c8c15cb Binary files /dev/null and b/reader/static/css/fonts/fontello.ttf differ diff --git a/reader/static/css/fonts/fontello.woff b/reader/static/css/fonts/fontello.woff new file mode 100644 index 0000000000000000000000000000000000000000..084f0c55cc955458bd6c75c6ad0800a0850ab710 Binary files /dev/null and b/reader/static/css/fonts/fontello.woff differ diff --git a/reader/static/img/epubjs_reader/annotator-glyph-sprite.png b/reader/static/img/epubjs_reader/annotator-glyph-sprite.png new file mode 100644 index 0000000000000000000000000000000000000000..5bb11cd84602e862e0b0542fd9b31da9719e0554 Binary files /dev/null and b/reader/static/img/epubjs_reader/annotator-glyph-sprite.png differ diff --git a/reader/static/img/epubjs_reader/annotator-icon-sprite.png b/reader/static/img/epubjs_reader/annotator-icon-sprite.png new file mode 100644 index 0000000000000000000000000000000000000000..3058651c59f19f4055c287959b1bd44909dffa39 Binary files /dev/null and b/reader/static/img/epubjs_reader/annotator-icon-sprite.png differ diff --git a/reader/static/img/epubjs_reader/apple-touch-icon.png b/reader/static/img/epubjs_reader/apple-touch-icon.png new file mode 100755 index 0000000000000000000000000000000000000000..efc5c5a612e513f2d96d47ba86905f4524052bbe Binary files /dev/null and b/reader/static/img/epubjs_reader/apple-touch-icon.png differ diff --git a/reader/static/img/epubjs_reader/cancelfullscreen.png b/reader/static/img/epubjs_reader/cancelfullscreen.png new file mode 100644 index 0000000000000000000000000000000000000000..bcf409e78ed24bb9f949fd7e64efc40997077fd0 Binary files /dev/null and b/reader/static/img/epubjs_reader/cancelfullscreen.png differ diff --git a/reader/static/img/epubjs_reader/close.png b/reader/static/img/epubjs_reader/close.png new file mode 100644 index 0000000000000000000000000000000000000000..46189e543b173b456c5169506cfb2545714e29a3 Binary files /dev/null and b/reader/static/img/epubjs_reader/close.png differ diff --git a/reader/static/img/epubjs_reader/fullscreen.png b/reader/static/img/epubjs_reader/fullscreen.png new file mode 100644 index 0000000000000000000000000000000000000000..2f8d48ded612d908e983248496f51560c15fe110 Binary files /dev/null and b/reader/static/img/epubjs_reader/fullscreen.png differ diff --git a/reader/static/img/epubjs_reader/loader.gif b/reader/static/img/epubjs_reader/loader.gif new file mode 100644 index 0000000000000000000000000000000000000000..68005bcbe63e2924bc8f6eccf5175db07490d3a7 Binary files /dev/null and b/reader/static/img/epubjs_reader/loader.gif differ diff --git a/reader/static/img/epubjs_reader/menu-icon.png b/reader/static/img/epubjs_reader/menu-icon.png new file mode 100644 index 0000000000000000000000000000000000000000..5f40e0e9c728d71076246e8d22e58cda45033b49 Binary files /dev/null and b/reader/static/img/epubjs_reader/menu-icon.png differ diff --git a/reader/static/img/epubjs_reader/save.png b/reader/static/img/epubjs_reader/save.png new file mode 100644 index 0000000000000000000000000000000000000000..5a5bc0e091d7484a77b130f4e5498a012a481a4f Binary files /dev/null and b/reader/static/img/epubjs_reader/save.png differ diff --git a/reader/static/img/epubjs_reader/saved.png b/reader/static/img/epubjs_reader/saved.png new file mode 100644 index 0000000000000000000000000000000000000000..0f1981bddb26c3840f0287c284edd422e132198a Binary files /dev/null and b/reader/static/img/epubjs_reader/saved.png differ diff --git a/reader/static/img/epubjs_reader/settings-s.png b/reader/static/img/epubjs_reader/settings-s.png new file mode 100644 index 0000000000000000000000000000000000000000..fc21e7873b6f366cf73b6f019f3ee3ba64f02db8 Binary files /dev/null and b/reader/static/img/epubjs_reader/settings-s.png differ diff --git a/reader/static/img/epubjs_reader/settings.png b/reader/static/img/epubjs_reader/settings.png new file mode 100644 index 0000000000000000000000000000000000000000..be20cba08f05008a93dcc1f69194a8dab55a41fe Binary files /dev/null and b/reader/static/img/epubjs_reader/settings.png differ diff --git a/reader/static/img/epubjs_reader/star.png b/reader/static/img/epubjs_reader/star.png new file mode 100644 index 0000000000000000000000000000000000000000..451089359b60136873f0abb4fd5545c27abd7c94 Binary files /dev/null and b/reader/static/img/epubjs_reader/star.png differ diff --git a/reader/static/js/epubjs_reader/reader.js b/reader/static/js/epubjs_reader/reader.js new file mode 100644 index 0000000000000000000000000000000000000000..6456af8a679b42f22b299ec1ccf4b6e022cbb059 --- /dev/null +++ b/reader/static/js/epubjs_reader/reader.js @@ -0,0 +1,4372 @@ +/*! + * @overview RSVP - a tiny implementation of Promises/A+. + * @copyright Copyright (c) 2016 Yehuda Katz, Tom Dale, Stefan Penner and contributors + * @license Licensed under MIT license + * See https://raw.githubusercontent.com/tildeio/rsvp.js/master/LICENSE + * @version 3.6.2 + */ + +(function (global, factory) { + typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : + typeof define === 'function' && define.amd ? define(['exports'], factory) : + (factory((global.RSVP = global.RSVP || {}))); +}(this, (function (exports) { 'use strict'; + +function indexOf(callbacks, callback) { + for (var i = 0, l = callbacks.length; i < l; i++) { + if (callbacks[i] === callback) { + return i; + } + } + + return -1; +} + +function callbacksFor(object) { + var callbacks = object._promiseCallbacks; + + if (!callbacks) { + callbacks = object._promiseCallbacks = {}; + } + + return callbacks; +} + +/** + @class RSVP.EventTarget +*/ +var EventTarget = { + + /** + `RSVP.EventTarget.mixin` extends an object with EventTarget methods. For + Example: + ```javascript + let object = {}; + RSVP.EventTarget.mixin(object); + object.on('finished', function(event) { + // handle event + }); + object.trigger('finished', { detail: value }); + ``` + `EventTarget.mixin` also works with prototypes: + ```javascript + let Person = function() {}; + RSVP.EventTarget.mixin(Person.prototype); + let yehuda = new Person(); + let tom = new Person(); + yehuda.on('poke', function(event) { + console.log('Yehuda says OW'); + }); + tom.on('poke', function(event) { + console.log('Tom says OW'); + }); + yehuda.trigger('poke'); + tom.trigger('poke'); + ``` + @method mixin + @for RSVP.EventTarget + @private + @param {Object} object object to extend with EventTarget methods + */ + mixin: function (object) { + object['on'] = this['on']; + object['off'] = this['off']; + object['trigger'] = this['trigger']; + object._promiseCallbacks = undefined; + return object; + }, + + + /** + Registers a callback to be executed when `eventName` is triggered + ```javascript + object.on('event', function(eventInfo){ + // handle the event + }); + object.trigger('event'); + ``` + @method on + @for RSVP.EventTarget + @private + @param {String} eventName name of the event to listen for + @param {Function} callback function to be called when the event is triggered. + */ + on: function (eventName, callback) { + if (typeof callback !== 'function') { + throw new TypeError('Callback must be a function'); + } + + var allCallbacks = callbacksFor(this), + callbacks = void 0; + + callbacks = allCallbacks[eventName]; + + if (!callbacks) { + callbacks = allCallbacks[eventName] = []; + } + + if (indexOf(callbacks, callback) === -1) { + callbacks.push(callback); + } + }, + + + /** + You can use `off` to stop firing a particular callback for an event: + ```javascript + function doStuff() { // do stuff! } + object.on('stuff', doStuff); + object.trigger('stuff'); // doStuff will be called + // Unregister ONLY the doStuff callback + object.off('stuff', doStuff); + object.trigger('stuff'); // doStuff will NOT be called + ``` + If you don't pass a `callback` argument to `off`, ALL callbacks for the + event will not be executed when the event fires. For example: + ```javascript + let callback1 = function(){}; + let callback2 = function(){}; + object.on('stuff', callback1); + object.on('stuff', callback2); + object.trigger('stuff'); // callback1 and callback2 will be executed. + object.off('stuff'); + object.trigger('stuff'); // callback1 and callback2 will not be executed! + ``` + @method off + @for RSVP.EventTarget + @private + @param {String} eventName event to stop listening to + @param {Function} callback optional argument. If given, only the function + given will be removed from the event's callback queue. If no `callback` + argument is given, all callbacks will be removed from the event's callback + queue. + */ + off: function (eventName, callback) { + var allCallbacks = callbacksFor(this), + callbacks = void 0, + index = void 0; + + if (!callback) { + allCallbacks[eventName] = []; + return; + } + + callbacks = allCallbacks[eventName]; + + index = indexOf(callbacks, callback); + + if (index !== -1) { + callbacks.splice(index, 1); + } + }, + + + /** + Use `trigger` to fire custom events. For example: + ```javascript + object.on('foo', function(){ + console.log('foo event happened!'); + }); + object.trigger('foo'); + // 'foo event happened!' logged to the console + ``` + You can also pass a value as a second argument to `trigger` that will be + passed as an argument to all event listeners for the event: + ```javascript + object.on('foo', function(value){ + console.log(value.name); + }); + object.trigger('foo', { name: 'bar' }); + // 'bar' logged to the console + ``` + @method trigger + @for RSVP.EventTarget + @private + @param {String} eventName name of the event to be triggered + @param {*} options optional value to be passed to any event handlers for + the given `eventName` + */ + trigger: function (eventName, options, label) { + var allCallbacks = callbacksFor(this), + callbacks = void 0, + callback = void 0; + + if (callbacks = allCallbacks[eventName]) { + // Don't cache the callbacks.length since it may grow + for (var i = 0; i < callbacks.length; i++) { + callback = callbacks[i]; + + callback(options, label); + } + } + } +}; + +var config = { + instrument: false +}; + +EventTarget['mixin'](config); + +function configure(name, value) { + if (arguments.length === 2) { + config[name] = value; + } else { + return config[name]; + } +} + +function objectOrFunction(x) { + var type = typeof x; + return x !== null && (type === 'object' || type === 'function'); +} + +function isFunction(x) { + return typeof x === 'function'; +} + +function isObject(x) { + return x !== null && typeof x === 'object'; +} + +function isMaybeThenable(x) { + return x !== null && typeof x === 'object'; +} + +var _isArray = void 0; +if (Array.isArray) { + _isArray = Array.isArray; +} else { + _isArray = function (x) { + return Object.prototype.toString.call(x) === '[object Array]'; + }; +} + +var isArray = _isArray; + +// Date.now is not available in browsers < IE9 +// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#Compatibility +var now = Date.now || function () { + return new Date().getTime(); +}; + +var queue = []; + +function scheduleFlush() { + setTimeout(function () { + for (var i = 0; i < queue.length; i++) { + var entry = queue[i]; + + var payload = entry.payload; + + payload.guid = payload.key + payload.id; + payload.childGuid = payload.key + payload.childId; + if (payload.error) { + payload.stack = payload.error.stack; + } + + config['trigger'](entry.name, entry.payload); + } + queue.length = 0; + }, 50); +} + +function instrument(eventName, promise, child) { + if (1 === queue.push({ + name: eventName, + payload: { + key: promise._guidKey, + id: promise._id, + eventName: eventName, + detail: promise._result, + childId: child && child._id, + label: promise._label, + timeStamp: now(), + error: config["instrument-with-stack"] ? new Error(promise._label) : null + } })) { + scheduleFlush(); + } +} + +/** + `RSVP.Promise.resolve` returns a promise that will become resolved with the + passed `value`. It is shorthand for the following: + + ```javascript + let promise = new RSVP.Promise(function(resolve, reject){ + resolve(1); + }); + + promise.then(function(value){ + // value === 1 + }); + ``` + + Instead of writing the above, your code now simply becomes the following: + + ```javascript + let promise = RSVP.Promise.resolve(1); + + promise.then(function(value){ + // value === 1 + }); + ``` + + @method resolve + @static + @param {*} object value that the returned promise will be resolved with + @param {String} label optional string for identifying the returned promise. + Useful for tooling. + @return {Promise} a promise that will become fulfilled with the given + `value` +*/ +function resolve$1(object, label) { + /*jshint validthis:true */ + var Constructor = this; + + if (object && typeof object === 'object' && object.constructor === Constructor) { + return object; + } + + var promise = new Constructor(noop, label); + resolve(promise, object); + return promise; +} + +function withOwnPromise() { + return new TypeError('A promises callback cannot return that same promise.'); +} + +function noop() {} + +var PENDING = void 0; +var FULFILLED = 1; +var REJECTED = 2; + +var GET_THEN_ERROR = new ErrorObject(); + +function getThen(promise) { + try { + return promise.then; + } catch (error) { + GET_THEN_ERROR.error = error; + return GET_THEN_ERROR; + } +} + +function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) { + try { + then$$1.call(value, fulfillmentHandler, rejectionHandler); + } catch (e) { + return e; + } +} + +function handleForeignThenable(promise, thenable, then$$1) { + config.async(function (promise) { + var sealed = false; + var error = tryThen(then$$1, thenable, function (value) { + if (sealed) { + return; + } + sealed = true; + if (thenable !== value) { + resolve(promise, value, undefined); + } else { + fulfill(promise, value); + } + }, function (reason) { + if (sealed) { + return; + } + sealed = true; + + reject(promise, reason); + }, 'Settle: ' + (promise._label || ' unknown promise')); + + if (!sealed && error) { + sealed = true; + reject(promise, error); + } + }, promise); +} + +function handleOwnThenable(promise, thenable) { + if (thenable._state === FULFILLED) { + fulfill(promise, thenable._result); + } else if (thenable._state === REJECTED) { + thenable._onError = null; + reject(promise, thenable._result); + } else { + subscribe(thenable, undefined, function (value) { + if (thenable !== value) { + resolve(promise, value, undefined); + } else { + fulfill(promise, value); + } + }, function (reason) { + return reject(promise, reason); + }); + } +} + +function handleMaybeThenable(promise, maybeThenable, then$$1) { + var isOwnThenable = maybeThenable.constructor === promise.constructor && then$$1 === then && promise.constructor.resolve === resolve$1; + + if (isOwnThenable) { + handleOwnThenable(promise, maybeThenable); + } else if (then$$1 === GET_THEN_ERROR) { + reject(promise, GET_THEN_ERROR.error); + GET_THEN_ERROR.error = null; + } else if (isFunction(then$$1)) { + handleForeignThenable(promise, maybeThenable, then$$1); + } else { + fulfill(promise, maybeThenable); + } +} + +function resolve(promise, value) { + if (promise === value) { + fulfill(promise, value); + } else if (objectOrFunction(value)) { + handleMaybeThenable(promise, value, getThen(value)); + } else { + fulfill(promise, value); + } +} + +function publishRejection(promise) { + if (promise._onError) { + promise._onError(promise._result); + } + + publish(promise); +} + +function fulfill(promise, value) { + if (promise._state !== PENDING) { + return; + } + + promise._result = value; + promise._state = FULFILLED; + + if (promise._subscribers.length === 0) { + if (config.instrument) { + instrument('fulfilled', promise); + } + } else { + config.async(publish, promise); + } +} + +function reject(promise, reason) { + if (promise._state !== PENDING) { + return; + } + promise._state = REJECTED; + promise._result = reason; + config.async(publishRejection, promise); +} + +function subscribe(parent, child, onFulfillment, onRejection) { + var subscribers = parent._subscribers; + var length = subscribers.length; + + parent._onError = null; + + subscribers[length] = child; + subscribers[length + FULFILLED] = onFulfillment; + subscribers[length + REJECTED] = onRejection; + + if (length === 0 && parent._state) { + config.async(publish, parent); + } +} + +function publish(promise) { + var subscribers = promise._subscribers; + var settled = promise._state; + + if (config.instrument) { + instrument(settled === FULFILLED ? 'fulfilled' : 'rejected', promise); + } + + if (subscribers.length === 0) { + return; + } + + var child = void 0, + callback = void 0, + result = promise._result; + + for (var i = 0; i < subscribers.length; i += 3) { + child = subscribers[i]; + callback = subscribers[i + settled]; + + if (child) { + invokeCallback(settled, child, callback, result); + } else { + callback(result); + } + } + + promise._subscribers.length = 0; +} + +function ErrorObject() { + this.error = null; +} + +var TRY_CATCH_ERROR = new ErrorObject(); + +function tryCatch(callback, result) { + try { + return callback(result); + } catch (e) { + TRY_CATCH_ERROR.error = e; + return TRY_CATCH_ERROR; + } +} + +function invokeCallback(state, promise, callback, result) { + var hasCallback = isFunction(callback); + var value = void 0, + error = void 0; + + if (hasCallback) { + value = tryCatch(callback, result); + + if (value === TRY_CATCH_ERROR) { + error = value.error; + value.error = null; // release + } else if (value === promise) { + reject(promise, withOwnPromise()); + return; + } + } else { + value = result; + } + + if (promise._state !== PENDING) { + // noop + } else if (hasCallback && error === undefined) { + resolve(promise, value); + } else if (error !== undefined) { + reject(promise, error); + } else if (state === FULFILLED) { + fulfill(promise, value); + } else if (state === REJECTED) { + reject(promise, value); + } +} + +function initializePromise(promise, resolver) { + var resolved = false; + try { + resolver(function (value) { + if (resolved) { + return; + } + resolved = true; + resolve(promise, value); + }, function (reason) { + if (resolved) { + return; + } + resolved = true; + reject(promise, reason); + }); + } catch (e) { + reject(promise, e); + } +} + +function then(onFulfillment, onRejection, label) { + var parent = this; + var state = parent._state; + + if (state === FULFILLED && !onFulfillment || state === REJECTED && !onRejection) { + config.instrument && instrument('chained', parent, parent); + return parent; + } + + parent._onError = null; + + var child = new parent.constructor(noop, label); + var result = parent._result; + + config.instrument && instrument('chained', parent, child); + + if (state === PENDING) { + subscribe(parent, child, onFulfillment, onRejection); + } else { + var callback = state === FULFILLED ? onFulfillment : onRejection; + config.async(function () { + return invokeCallback(state, child, callback, result); + }); + } + + return child; +} + +var Enumerator = function () { + function Enumerator(Constructor, input, abortOnReject, label) { + this._instanceConstructor = Constructor; + this.promise = new Constructor(noop, label); + this._abortOnReject = abortOnReject; + + this._init.apply(this, arguments); + } + + Enumerator.prototype._init = function _init(Constructor, input) { + var len = input.length || 0; + this.length = len; + this._remaining = len; + this._result = new Array(len); + + this._enumerate(input); + if (this._remaining === 0) { + fulfill(this.promise, this._result); + } + }; + + Enumerator.prototype._enumerate = function _enumerate(input) { + var length = this.length; + var promise = this.promise; + + for (var i = 0; promise._state === PENDING && i < length; i++) { + this._eachEntry(input[i], i); + } + }; + + Enumerator.prototype._settleMaybeThenable = function _settleMaybeThenable(entry, i) { + var c = this._instanceConstructor; + var resolve$$1 = c.resolve; + + if (resolve$$1 === resolve$1) { + var then$$1 = getThen(entry); + + if (then$$1 === then && entry._state !== PENDING) { + entry._onError = null; + this._settledAt(entry._state, i, entry._result); + } else if (typeof then$$1 !== 'function') { + this._remaining--; + this._result[i] = this._makeResult(FULFILLED, i, entry); + } else if (c === Promise) { + var promise = new c(noop); + handleMaybeThenable(promise, entry, then$$1); + this._willSettleAt(promise, i); + } else { + this._willSettleAt(new c(function (resolve$$1) { + return resolve$$1(entry); + }), i); + } + } else { + this._willSettleAt(resolve$$1(entry), i); + } + }; + + Enumerator.prototype._eachEntry = function _eachEntry(entry, i) { + if (isMaybeThenable(entry)) { + this._settleMaybeThenable(entry, i); + } else { + this._remaining--; + this._result[i] = this._makeResult(FULFILLED, i, entry); + } + }; + + Enumerator.prototype._settledAt = function _settledAt(state, i, value) { + var promise = this.promise; + + if (promise._state === PENDING) { + if (this._abortOnReject && state === REJECTED) { + reject(promise, value); + } else { + this._remaining--; + this._result[i] = this._makeResult(state, i, value); + if (this._remaining === 0) { + fulfill(promise, this._result); + } + } + } + }; + + Enumerator.prototype._makeResult = function _makeResult(state, i, value) { + return value; + }; + + Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) { + var enumerator = this; + + subscribe(promise, undefined, function (value) { + return enumerator._settledAt(FULFILLED, i, value); + }, function (reason) { + return enumerator._settledAt(REJECTED, i, reason); + }); + }; + + return Enumerator; +}(); + +function makeSettledResult(state, position, value) { + if (state === FULFILLED) { + return { + state: 'fulfilled', + value: value + }; + } else { + return { + state: 'rejected', + reason: value + }; + } +} + +/** + `RSVP.Promise.all` accepts an array of promises, and returns a new promise which + is fulfilled with an array of fulfillment values for the passed promises, or + rejected with the reason of the first passed promise to be rejected. It casts all + elements of the passed iterable to promises as it runs this algorithm. + + Example: + + ```javascript + let promise1 = RSVP.resolve(1); + let promise2 = RSVP.resolve(2); + let promise3 = RSVP.resolve(3); + let promises = [ promise1, promise2, promise3 ]; + + RSVP.Promise.all(promises).then(function(array){ + // The array here would be [ 1, 2, 3 ]; + }); + ``` + + If any of the `promises` given to `RSVP.all` are rejected, the first promise + that is rejected will be given as an argument to the returned promises's + rejection handler. For example: + + Example: + + ```javascript + let promise1 = RSVP.resolve(1); + let promise2 = RSVP.reject(new Error("2")); + let promise3 = RSVP.reject(new Error("3")); + let promises = [ promise1, promise2, promise3 ]; + + RSVP.Promise.all(promises).then(function(array){ + // Code here never runs because there are rejected promises! + }, function(error) { + // error.message === "2" + }); + ``` + + @method all + @static + @param {Array} entries array of promises + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} promise that is fulfilled when all `promises` have been + fulfilled, or rejected if any of them become rejected. + @static +*/ +function all(entries, label) { + if (!isArray(entries)) { + return this.reject(new TypeError("Promise.all must be called with an array"), label); + } + return new Enumerator(this, entries, true /* abort on reject */, label).promise; +} + +/** + `RSVP.Promise.race` returns a new promise which is settled in the same way as the + first passed promise to settle. + + Example: + + ```javascript + let promise1 = new RSVP.Promise(function(resolve, reject){ + setTimeout(function(){ + resolve('promise 1'); + }, 200); + }); + + let promise2 = new RSVP.Promise(function(resolve, reject){ + setTimeout(function(){ + resolve('promise 2'); + }, 100); + }); + + RSVP.Promise.race([promise1, promise2]).then(function(result){ + // result === 'promise 2' because it was resolved before promise1 + // was resolved. + }); + ``` + + `RSVP.Promise.race` is deterministic in that only the state of the first + settled promise matters. For example, even if other promises given to the + `promises` array argument are resolved, but the first settled promise has + become rejected before the other promises became fulfilled, the returned + promise will become rejected: + + ```javascript + let promise1 = new RSVP.Promise(function(resolve, reject){ + setTimeout(function(){ + resolve('promise 1'); + }, 200); + }); + + let promise2 = new RSVP.Promise(function(resolve, reject){ + setTimeout(function(){ + reject(new Error('promise 2')); + }, 100); + }); + + RSVP.Promise.race([promise1, promise2]).then(function(result){ + // Code here never runs + }, function(reason){ + // reason.message === 'promise 2' because promise 2 became rejected before + // promise 1 became fulfilled + }); + ``` + + An example real-world use case is implementing timeouts: + + ```javascript + RSVP.Promise.race([ajax('foo.json'), timeout(5000)]) + ``` + + @method race + @static + @param {Array} entries array of promises to observe + @param {String} label optional string for describing the promise returned. + Useful for tooling. + @return {Promise} a promise which settles in the same way as the first passed + promise to settle. +*/ +function race(entries, label) { + /*jshint validthis:true */ + var Constructor = this; + + var promise = new Constructor(noop, label); + + if (!isArray(entries)) { + reject(promise, new TypeError('Promise.race must be called with an array')); + return promise; + } + + for (var i = 0; promise._state === PENDING && i < entries.length; i++) { + subscribe(Constructor.resolve(entries[i]), undefined, function (value) { + return resolve(promise, value); + }, function (reason) { + return reject(promise, reason); + }); + } + + return promise; +} + +/** + `RSVP.Promise.reject` returns a promise rejected with the passed `reason`. + It is shorthand for the following: + + ```javascript + let promise = new RSVP.Promise(function(resolve, reject){ + reject(new Error('WHOOPS')); + }); + + promise.then(function(value){ + // Code here doesn't run because the promise is rejected! + }, function(reason){ + // reason.message === 'WHOOPS' + }); + ``` + + Instead of writing the above, your code now simply becomes the following: + + ```javascript + let promise = RSVP.Promise.reject(new Error('WHOOPS')); + + promise.then(function(value){ + // Code here doesn't run because the promise is rejected! + }, function(reason){ + // reason.message === 'WHOOPS' + }); + ``` + + @method reject + @static + @param {*} reason value that the returned promise will be rejected with. + @param {String} label optional string for identifying the returned promise. + Useful for tooling. + @return {Promise} a promise rejected with the given `reason`. +*/ +function reject$1(reason, label) { + /*jshint validthis:true */ + var Constructor = this; + var promise = new Constructor(noop, label); + reject(promise, reason); + return promise; +} + +var guidKey = 'rsvp_' + now() + '-'; +var counter = 0; + +function needsResolver() { + throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); +} + +function needsNew() { + throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function."); +} + +/** + Promise objects represent the eventual result of an asynchronous operation. The + primary way of interacting with a promise is through its `then` method, which + registers callbacks to receive either a promise’s eventual value or the reason + why the promise cannot be fulfilled. + + Terminology + ----------- + + - `promise` is an object or function with a `then` method whose behavior conforms to this specification. + - `thenable` is an object or function that defines a `then` method. + - `value` is any legal JavaScript value (including undefined, a thenable, or a promise). + - `exception` is a value that is thrown using the throw statement. + - `reason` is a value that indicates why a promise was rejected. + - `settled` the final resting state of a promise, fulfilled or rejected. + + A promise can be in one of three states: pending, fulfilled, or rejected. + + Promises that are fulfilled have a fulfillment value and are in the fulfilled + state. Promises that are rejected have a rejection reason and are in the + rejected state. A fulfillment value is never a thenable. + + Promises can also be said to *resolve* a value. If this value is also a + promise, then the original promise's settled state will match the value's + settled state. So a promise that *resolves* a promise that rejects will + itself reject, and a promise that *resolves* a promise that fulfills will + itself fulfill. + + + Basic Usage: + ------------ + + ```js + let promise = new Promise(function(resolve, reject) { + // on success + resolve(value); + + // on failure + reject(reason); + }); + + promise.then(function(value) { + // on fulfillment + }, function(reason) { + // on rejection + }); + ``` + + Advanced Usage: + --------------- + + Promises shine when abstracting away asynchronous interactions such as + `XMLHttpRequest`s. + + ```js + function getJSON(url) { + return new Promise(function(resolve, reject){ + let xhr = new XMLHttpRequest(); + + xhr.open('GET', url); + xhr.onreadystatechange = handler; + xhr.responseType = 'json'; + xhr.setRequestHeader('Accept', 'application/json'); + xhr.send(); + + function handler() { + if (this.readyState === this.DONE) { + if (this.status === 200) { + resolve(this.response); + } else { + reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']')); + } + } + }; + }); + } + + getJSON('/posts.json').then(function(json) { + // on fulfillment + }, function(reason) { + // on rejection + }); + ``` + + Unlike callbacks, promises are great composable primitives. + + ```js + Promise.all([ + getJSON('/posts'), + getJSON('/comments') + ]).then(function(values){ + values[0] // => postsJSON + values[1] // => commentsJSON + + return values; + }); + ``` + + @class RSVP.Promise + @param {function} resolver + @param {String} label optional string for labeling the promise. + Useful for tooling. + @constructor +*/ + +var Promise = function () { + function Promise(resolver, label) { + this._id = counter++; + this._label = label; + this._state = undefined; + this._result = undefined; + this._subscribers = []; + + config.instrument && instrument('created', this); + + if (noop !== resolver) { + typeof resolver !== 'function' && needsResolver(); + this instanceof Promise ? initializePromise(this, resolver) : needsNew(); + } + } + + Promise.prototype._onError = function _onError(reason) { + var _this = this; + + config.after(function () { + if (_this._onError) { + config.trigger('error', reason, _this._label); + } + }); + }; + + /** + `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same + as the catch block of a try/catch statement. + + ```js + function findAuthor(){ + throw new Error('couldn\'t find that author'); + } + + // synchronous + try { + findAuthor(); + } catch(reason) { + // something went wrong + } + + // async with promises + findAuthor().catch(function(reason){ + // something went wrong + }); + ``` + + @method catch + @param {Function} onRejection + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} + */ + + + Promise.prototype.catch = function _catch(onRejection, label) { + return this.then(undefined, onRejection, label); + }; + + /** + `finally` will be invoked regardless of the promise's fate just as native + try/catch/finally behaves + + Synchronous example: + + ```js + findAuthor() { + if (Math.random() > 0.5) { + throw new Error(); + } + return new Author(); + } + + try { + return findAuthor(); // succeed or fail + } catch(error) { + return findOtherAuthor(); + } finally { + // always runs + // doesn't affect the return value + } + ``` + + Asynchronous example: + + ```js + findAuthor().catch(function(reason){ + return findOtherAuthor(); + }).finally(function(){ + // author was either found, or not + }); + ``` + + @method finally + @param {Function} callback + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} + */ + + + Promise.prototype.finally = function _finally(callback, label) { + var promise = this; + var constructor = promise.constructor; + + return promise.then(function (value) { + return constructor.resolve(callback()).then(function () { + return value; + }); + }, function (reason) { + return constructor.resolve(callback()).then(function () { + throw reason; + }); + }, label); + }; + + return Promise; +}(); + + + +Promise.cast = resolve$1; // deprecated +Promise.all = all; +Promise.race = race; +Promise.resolve = resolve$1; +Promise.reject = reject$1; + +Promise.prototype._guidKey = guidKey; + +/** + The primary way of interacting with a promise is through its `then` method, + which registers callbacks to receive either a promise's eventual value or the + reason why the promise cannot be fulfilled. + + ```js + findUser().then(function(user){ + // user is available + }, function(reason){ + // user is unavailable, and you are given the reason why + }); + ``` + + Chaining + -------- + + The return value of `then` is itself a promise. This second, 'downstream' + promise is resolved with the return value of the first promise's fulfillment + or rejection handler, or rejected if the handler throws an exception. + + ```js + findUser().then(function (user) { + return user.name; + }, function (reason) { + return 'default name'; + }).then(function (userName) { + // If `findUser` fulfilled, `userName` will be the user's name, otherwise it + // will be `'default name'` + }); + + findUser().then(function (user) { + throw new Error('Found user, but still unhappy'); + }, function (reason) { + throw new Error('`findUser` rejected and we\'re unhappy'); + }).then(function (value) { + // never reached + }, function (reason) { + // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. + // If `findUser` rejected, `reason` will be '`findUser` rejected and we\'re unhappy'. + }); + ``` + If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. + + ```js + findUser().then(function (user) { + throw new PedagogicalException('Upstream error'); + }).then(function (value) { + // never reached + }).then(function (value) { + // never reached + }, function (reason) { + // The `PedgagocialException` is propagated all the way down to here + }); + ``` + + Assimilation + ------------ + + Sometimes the value you want to propagate to a downstream promise can only be + retrieved asynchronously. This can be achieved by returning a promise in the + fulfillment or rejection handler. The downstream promise will then be pending + until the returned promise is settled. This is called *assimilation*. + + ```js + findUser().then(function (user) { + return findCommentsByAuthor(user); + }).then(function (comments) { + // The user's comments are now available + }); + ``` + + If the assimliated promise rejects, then the downstream promise will also reject. + + ```js + findUser().then(function (user) { + return findCommentsByAuthor(user); + }).then(function (comments) { + // If `findCommentsByAuthor` fulfills, we'll have the value here + }, function (reason) { + // If `findCommentsByAuthor` rejects, we'll have the reason here + }); + ``` + + Simple Example + -------------- + + Synchronous Example + + ```javascript + let result; + + try { + result = findResult(); + // success + } catch(reason) { + // failure + } + ``` + + Errback Example + + ```js + findResult(function(result, err){ + if (err) { + // failure + } else { + // success + } + }); + ``` + + Promise Example; + + ```javascript + findResult().then(function(result){ + // success + }, function(reason){ + // failure + }); + ``` + + Advanced Example + -------------- + + Synchronous Example + + ```javascript + let author, books; + + try { + author = findAuthor(); + books = findBooksByAuthor(author); + // success + } catch(reason) { + // failure + } + ``` + + Errback Example + + ```js + + function foundBooks(books) { + + } + + function failure(reason) { + + } + + findAuthor(function(author, err){ + if (err) { + failure(err); + // failure + } else { + try { + findBoooksByAuthor(author, function(books, err) { + if (err) { + failure(err); + } else { + try { + foundBooks(books); + } catch(reason) { + failure(reason); + } + } + }); + } catch(error) { + failure(err); + } + // success + } + }); + ``` + + Promise Example; + + ```javascript + findAuthor(). + then(findBooksByAuthor). + then(function(books){ + // found books + }).catch(function(reason){ + // something went wrong + }); + ``` + + @method then + @param {Function} onFulfillment + @param {Function} onRejection + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} +*/ +Promise.prototype.then = then; + +function Result() { + this.value = undefined; +} + +var ERROR = new Result(); +var GET_THEN_ERROR$1 = new Result(); + +function getThen$1(obj) { + try { + return obj.then; + } catch (error) { + ERROR.value = error; + return ERROR; + } +} + +function tryApply(f, s, a) { + try { + f.apply(s, a); + } catch (error) { + ERROR.value = error; + return ERROR; + } +} + +function makeObject(_, argumentNames) { + var obj = {}; + var length = _.length; + var args = new Array(length); + + for (var x = 0; x < length; x++) { + args[x] = _[x]; + } + + for (var i = 0; i < argumentNames.length; i++) { + var name = argumentNames[i]; + obj[name] = args[i + 1]; + } + + return obj; +} + +function arrayResult(_) { + var length = _.length; + var args = new Array(length - 1); + + for (var i = 1; i < length; i++) { + args[i - 1] = _[i]; + } + + return args; +} + +function wrapThenable(then, promise) { + return { + then: function (onFulFillment, onRejection) { + return then.call(promise, onFulFillment, onRejection); + } + }; +} + +/** + `RSVP.denodeify` takes a 'node-style' function and returns a function that + will return an `RSVP.Promise`. You can use `denodeify` in Node.js or the + browser when you'd prefer to use promises over using callbacks. For example, + `denodeify` transforms the following: + + ```javascript + let fs = require('fs'); + + fs.readFile('myfile.txt', function(err, data){ + if (err) return handleError(err); + handleData(data); + }); + ``` + + into: + + ```javascript + let fs = require('fs'); + let readFile = RSVP.denodeify(fs.readFile); + + readFile('myfile.txt').then(handleData, handleError); + ``` + + If the node function has multiple success parameters, then `denodeify` + just returns the first one: + + ```javascript + let request = RSVP.denodeify(require('request')); + + request('http://example.com').then(function(res) { + // ... + }); + ``` + + However, if you need all success parameters, setting `denodeify`'s + second parameter to `true` causes it to return all success parameters + as an array: + + ```javascript + let request = RSVP.denodeify(require('request'), true); + + request('http://example.com').then(function(result) { + // result[0] -> res + // result[1] -> body + }); + ``` + + Or if you pass it an array with names it returns the parameters as a hash: + + ```javascript + let request = RSVP.denodeify(require('request'), ['res', 'body']); + + request('http://example.com').then(function(result) { + // result.res + // result.body + }); + ``` + + Sometimes you need to retain the `this`: + + ```javascript + let app = require('express')(); + let render = RSVP.denodeify(app.render.bind(app)); + ``` + + The denodified function inherits from the original function. It works in all + environments, except IE 10 and below. Consequently all properties of the original + function are available to you. However, any properties you change on the + denodeified function won't be changed on the original function. Example: + + ```javascript + let request = RSVP.denodeify(require('request')), + cookieJar = request.jar(); // <- Inheritance is used here + + request('http://example.com', {jar: cookieJar}).then(function(res) { + // cookieJar.cookies holds now the cookies returned by example.com + }); + ``` + + Using `denodeify` makes it easier to compose asynchronous operations instead + of using callbacks. For example, instead of: + + ```javascript + let fs = require('fs'); + + fs.readFile('myfile.txt', function(err, data){ + if (err) { ... } // Handle error + fs.writeFile('myfile2.txt', data, function(err){ + if (err) { ... } // Handle error + console.log('done') + }); + }); + ``` + + you can chain the operations together using `then` from the returned promise: + + ```javascript + let fs = require('fs'); + let readFile = RSVP.denodeify(fs.readFile); + let writeFile = RSVP.denodeify(fs.writeFile); + + readFile('myfile.txt').then(function(data){ + return writeFile('myfile2.txt', data); + }).then(function(){ + console.log('done') + }).catch(function(error){ + // Handle error + }); + ``` + + @method denodeify + @static + @for RSVP + @param {Function} nodeFunc a 'node-style' function that takes a callback as + its last argument. The callback expects an error to be passed as its first + argument (if an error occurred, otherwise null), and the value from the + operation as its second argument ('function(err, value){ }'). + @param {Boolean|Array} [options] An optional paramter that if set + to `true` causes the promise to fulfill with the callback's success arguments + as an array. This is useful if the node function has multiple success + paramters. If you set this paramter to an array with names, the promise will + fulfill with a hash with these names as keys and the success parameters as + values. + @return {Function} a function that wraps `nodeFunc` to return an + `RSVP.Promise` + @static +*/ +function denodeify(nodeFunc, options) { + var fn = function () { + var self = this; + var l = arguments.length; + var args = new Array(l + 1); + var promiseInput = false; + + for (var i = 0; i < l; ++i) { + var arg = arguments[i]; + + if (!promiseInput) { + // TODO: clean this up + promiseInput = needsPromiseInput(arg); + if (promiseInput === GET_THEN_ERROR$1) { + var p = new Promise(noop); + reject(p, GET_THEN_ERROR$1.value); + return p; + } else if (promiseInput && promiseInput !== true) { + arg = wrapThenable(promiseInput, arg); + } + } + args[i] = arg; + } + + var promise = new Promise(noop); + + args[l] = function (err, val) { + if (err) reject(promise, err);else if (options === undefined) resolve(promise, val);else if (options === true) resolve(promise, arrayResult(arguments));else if (isArray(options)) resolve(promise, makeObject(arguments, options));else resolve(promise, val); + }; + + if (promiseInput) { + return handlePromiseInput(promise, args, nodeFunc, self); + } else { + return handleValueInput(promise, args, nodeFunc, self); + } + }; + + fn.__proto__ = nodeFunc; + + return fn; +} + +function handleValueInput(promise, args, nodeFunc, self) { + var result = tryApply(nodeFunc, self, args); + if (result === ERROR) { + reject(promise, result.value); + } + return promise; +} + +function handlePromiseInput(promise, args, nodeFunc, self) { + return Promise.all(args).then(function (args) { + var result = tryApply(nodeFunc, self, args); + if (result === ERROR) { + reject(promise, result.value); + } + return promise; + }); +} + +function needsPromiseInput(arg) { + if (arg && typeof arg === 'object') { + if (arg.constructor === Promise) { + return true; + } else { + return getThen$1(arg); + } + } else { + return false; + } +} + +/** + This is a convenient alias for `RSVP.Promise.all`. + + @method all + @static + @for RSVP + @param {Array} array Array of promises. + @param {String} label An optional label. This is useful + for tooling. +*/ +function all$1(array, label) { + return Promise.all(array, label); +} + +function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var AllSettled = function (_Enumerator) { + _inherits(AllSettled, _Enumerator); + + function AllSettled(Constructor, entries, label) { + return _possibleConstructorReturn(this, _Enumerator.call(this, Constructor, entries, false /* don't abort on reject */, label)); + } + + return AllSettled; +}(Enumerator); + +AllSettled.prototype._makeResult = makeSettledResult; + +/** +`RSVP.allSettled` is similar to `RSVP.all`, but instead of implementing +a fail-fast method, it waits until all the promises have returned and +shows you all the results. This is useful if you want to handle multiple +promises' failure states together as a set. + Returns a promise that is fulfilled when all the given promises have been +settled. The return promise is fulfilled with an array of the states of +the promises passed into the `promises` array argument. + Each state object will either indicate fulfillment or rejection, and +provide the corresponding value or reason. The states will take one of +the following formats: + ```javascript +{ state: 'fulfilled', value: value } + or +{ state: 'rejected', reason: reason } +``` + Example: + ```javascript +let promise1 = RSVP.Promise.resolve(1); +let promise2 = RSVP.Promise.reject(new Error('2')); +let promise3 = RSVP.Promise.reject(new Error('3')); +let promises = [ promise1, promise2, promise3 ]; + RSVP.allSettled(promises).then(function(array){ + // array == [ + // { state: 'fulfilled', value: 1 }, + // { state: 'rejected', reason: Error }, + // { state: 'rejected', reason: Error } + // ] + // Note that for the second item, reason.message will be '2', and for the + // third item, reason.message will be '3'. +}, function(error) { + // Not run. (This block would only be called if allSettled had failed, + // for instance if passed an incorrect argument type.) +}); +``` + @method allSettled +@static +@for RSVP +@param {Array} entries +@param {String} label - optional string that describes the promise. +Useful for tooling. +@return {Promise} promise that is fulfilled with an array of the settled +states of the constituent promises. +*/ + +function allSettled(entries, label) { + if (!isArray(entries)) { + return Promise.reject(new TypeError("Promise.allSettled must be called with an array"), label); + } + + return new AllSettled(Promise, entries, label).promise; +} + +/** + This is a convenient alias for `RSVP.Promise.race`. + + @method race + @static + @for RSVP + @param {Array} array Array of promises. + @param {String} label An optional label. This is useful + for tooling. + */ +function race$1(array, label) { + return Promise.race(array, label); +} + +function _possibleConstructorReturn$1(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits$1(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var hasOwnProperty = Object.prototype.hasOwnProperty; + +var PromiseHash = function (_Enumerator) { + _inherits$1(PromiseHash, _Enumerator); + + function PromiseHash(Constructor, object) { + var abortOnReject = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; + var label = arguments[3]; + return _possibleConstructorReturn$1(this, _Enumerator.call(this, Constructor, object, abortOnReject, label)); + } + + PromiseHash.prototype._init = function _init(Constructor, object) { + this._result = {}; + + this._enumerate(object); + if (this._remaining === 0) { + fulfill(this.promise, this._result); + } + }; + + PromiseHash.prototype._enumerate = function _enumerate(input) { + var promise = this.promise; + var results = []; + + for (var key in input) { + if (hasOwnProperty.call(input, key)) { + results.push({ + position: key, + entry: input[key] + }); + } + } + + var length = results.length; + this._remaining = length; + var result = void 0; + + for (var i = 0; promise._state === PENDING && i < length; i++) { + result = results[i]; + this._eachEntry(result.entry, result.position); + } + }; + + return PromiseHash; +}(Enumerator); + +/** + `RSVP.hash` is similar to `RSVP.all`, but takes an object instead of an array + for its `promises` argument. + + Returns a promise that is fulfilled when all the given promises have been + fulfilled, or rejected if any of them become rejected. The returned promise + is fulfilled with a hash that has the same key names as the `promises` object + argument. If any of the values in the object are not promises, they will + simply be copied over to the fulfilled object. + + Example: + + ```javascript + let promises = { + myPromise: RSVP.resolve(1), + yourPromise: RSVP.resolve(2), + theirPromise: RSVP.resolve(3), + notAPromise: 4 + }; + + RSVP.hash(promises).then(function(hash){ + // hash here is an object that looks like: + // { + // myPromise: 1, + // yourPromise: 2, + // theirPromise: 3, + // notAPromise: 4 + // } + }); + ```` + + If any of the `promises` given to `RSVP.hash` are rejected, the first promise + that is rejected will be given as the reason to the rejection handler. + + Example: + + ```javascript + let promises = { + myPromise: RSVP.resolve(1), + rejectedPromise: RSVP.reject(new Error('rejectedPromise')), + anotherRejectedPromise: RSVP.reject(new Error('anotherRejectedPromise')), + }; + + RSVP.hash(promises).then(function(hash){ + // Code here never runs because there are rejected promises! + }, function(reason) { + // reason.message === 'rejectedPromise' + }); + ``` + + An important note: `RSVP.hash` is intended for plain JavaScript objects that + are just a set of keys and values. `RSVP.hash` will NOT preserve prototype + chains. + + Example: + + ```javascript + function MyConstructor(){ + this.example = RSVP.resolve('Example'); + } + + MyConstructor.prototype = { + protoProperty: RSVP.resolve('Proto Property') + }; + + let myObject = new MyConstructor(); + + RSVP.hash(myObject).then(function(hash){ + // protoProperty will not be present, instead you will just have an + // object that looks like: + // { + // example: 'Example' + // } + // + // hash.hasOwnProperty('protoProperty'); // false + // 'undefined' === typeof hash.protoProperty + }); + ``` + + @method hash + @static + @for RSVP + @param {Object} object + @param {String} label optional string that describes the promise. + Useful for tooling. + @return {Promise} promise that is fulfilled when all properties of `promises` + have been fulfilled, or rejected if any of them become rejected. +*/ +function hash(object, label) { + if (!isObject(object)) { + return Promise.reject(new TypeError("Promise.hash must be called with an object"), label); + } + + return new PromiseHash(Promise, object, label).promise; +} + +function _possibleConstructorReturn$2(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } + +function _inherits$2(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + +var HashSettled = function (_PromiseHash) { + _inherits$2(HashSettled, _PromiseHash); + + function HashSettled(Constructor, object, label) { + return _possibleConstructorReturn$2(this, _PromiseHash.call(this, Constructor, object, false, label)); + } + + return HashSettled; +}(PromiseHash); + +HashSettled.prototype._makeResult = makeSettledResult; + +/** + `RSVP.hashSettled` is similar to `RSVP.allSettled`, but takes an object + instead of an array for its `promises` argument. + + Unlike `RSVP.all` or `RSVP.hash`, which implement a fail-fast method, + but like `RSVP.allSettled`, `hashSettled` waits until all the + constituent promises have returned and then shows you all the results + with their states and values/reasons. This is useful if you want to + handle multiple promises' failure states together as a set. + + Returns a promise that is fulfilled when all the given promises have been + settled, or rejected if the passed parameters are invalid. + + The returned promise is fulfilled with a hash that has the same key names as + the `promises` object argument. If any of the values in the object are not + promises, they will be copied over to the fulfilled object and marked with state + 'fulfilled'. + + Example: + + ```javascript + let promises = { + myPromise: RSVP.Promise.resolve(1), + yourPromise: RSVP.Promise.resolve(2), + theirPromise: RSVP.Promise.resolve(3), + notAPromise: 4 + }; + + RSVP.hashSettled(promises).then(function(hash){ + // hash here is an object that looks like: + // { + // myPromise: { state: 'fulfilled', value: 1 }, + // yourPromise: { state: 'fulfilled', value: 2 }, + // theirPromise: { state: 'fulfilled', value: 3 }, + // notAPromise: { state: 'fulfilled', value: 4 } + // } + }); + ``` + + If any of the `promises` given to `RSVP.hash` are rejected, the state will + be set to 'rejected' and the reason for rejection provided. + + Example: + + ```javascript + let promises = { + myPromise: RSVP.Promise.resolve(1), + rejectedPromise: RSVP.Promise.reject(new Error('rejection')), + anotherRejectedPromise: RSVP.Promise.reject(new Error('more rejection')), + }; + + RSVP.hashSettled(promises).then(function(hash){ + // hash here is an object that looks like: + // { + // myPromise: { state: 'fulfilled', value: 1 }, + // rejectedPromise: { state: 'rejected', reason: Error }, + // anotherRejectedPromise: { state: 'rejected', reason: Error }, + // } + // Note that for rejectedPromise, reason.message == 'rejection', + // and for anotherRejectedPromise, reason.message == 'more rejection'. + }); + ``` + + An important note: `RSVP.hashSettled` is intended for plain JavaScript objects that + are just a set of keys and values. `RSVP.hashSettled` will NOT preserve prototype + chains. + + Example: + + ```javascript + function MyConstructor(){ + this.example = RSVP.Promise.resolve('Example'); + } + + MyConstructor.prototype = { + protoProperty: RSVP.Promise.resolve('Proto Property') + }; + + let myObject = new MyConstructor(); + + RSVP.hashSettled(myObject).then(function(hash){ + // protoProperty will not be present, instead you will just have an + // object that looks like: + // { + // example: { state: 'fulfilled', value: 'Example' } + // } + // + // hash.hasOwnProperty('protoProperty'); // false + // 'undefined' === typeof hash.protoProperty + }); + ``` + + @method hashSettled + @for RSVP + @param {Object} object + @param {String} label optional string that describes the promise. + Useful for tooling. + @return {Promise} promise that is fulfilled when when all properties of `promises` + have been settled. + @static +*/ + +function hashSettled(object, label) { + if (!isObject(object)) { + return Promise.reject(new TypeError("RSVP.hashSettled must be called with an object"), label); + } + + return new HashSettled(Promise, object, false, label).promise; +} + +/** + `RSVP.rethrow` will rethrow an error on the next turn of the JavaScript event + loop in order to aid debugging. + + Promises A+ specifies that any exceptions that occur with a promise must be + caught by the promises implementation and bubbled to the last handler. For + this reason, it is recommended that you always specify a second rejection + handler function to `then`. However, `RSVP.rethrow` will throw the exception + outside of the promise, so it bubbles up to your console if in the browser, + or domain/cause uncaught exception in Node. `rethrow` will also throw the + error again so the error can be handled by the promise per the spec. + + ```javascript + function throws(){ + throw new Error('Whoops!'); + } + + let promise = new RSVP.Promise(function(resolve, reject){ + throws(); + }); + + promise.catch(RSVP.rethrow).then(function(){ + // Code here doesn't run because the promise became rejected due to an + // error! + }, function (err){ + // handle the error here + }); + ``` + + The 'Whoops' error will be thrown on the next turn of the event loop + and you can watch for it in your console. You can also handle it using a + rejection handler given to `.then` or `.catch` on the returned promise. + + @method rethrow + @static + @for RSVP + @param {Error} reason reason the promise became rejected. + @throws Error + @static +*/ +function rethrow(reason) { + setTimeout(function () { + throw reason; + }); + throw reason; +} + +/** + `RSVP.defer` returns an object similar to jQuery's `$.Deferred`. + `RSVP.defer` should be used when porting over code reliant on `$.Deferred`'s + interface. New code should use the `RSVP.Promise` constructor instead. + + The object returned from `RSVP.defer` is a plain object with three properties: + + * promise - an `RSVP.Promise`. + * reject - a function that causes the `promise` property on this object to + become rejected + * resolve - a function that causes the `promise` property on this object to + become fulfilled. + + Example: + + ```javascript + let deferred = RSVP.defer(); + + deferred.resolve("Success!"); + + deferred.promise.then(function(value){ + // value here is "Success!" + }); + ``` + + @method defer + @static + @for RSVP + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Object} + */ + +function defer(label) { + var deferred = { resolve: undefined, reject: undefined }; + + deferred.promise = new Promise(function (resolve, reject) { + deferred.resolve = resolve; + deferred.reject = reject; + }, label); + + return deferred; +} + +/** + `RSVP.map` is similar to JavaScript's native `map` method, except that it + waits for all promises to become fulfilled before running the `mapFn` on + each item in given to `promises`. `RSVP.map` returns a promise that will + become fulfilled with the result of running `mapFn` on the values the promises + become fulfilled with. + + For example: + + ```javascript + + let promise1 = RSVP.resolve(1); + let promise2 = RSVP.resolve(2); + let promise3 = RSVP.resolve(3); + let promises = [ promise1, promise2, promise3 ]; + + let mapFn = function(item){ + return item + 1; + }; + + RSVP.map(promises, mapFn).then(function(result){ + // result is [ 2, 3, 4 ] + }); + ``` + + If any of the `promises` given to `RSVP.map` are rejected, the first promise + that is rejected will be given as an argument to the returned promise's + rejection handler. For example: + + ```javascript + let promise1 = RSVP.resolve(1); + let promise2 = RSVP.reject(new Error('2')); + let promise3 = RSVP.reject(new Error('3')); + let promises = [ promise1, promise2, promise3 ]; + + let mapFn = function(item){ + return item + 1; + }; + + RSVP.map(promises, mapFn).then(function(array){ + // Code here never runs because there are rejected promises! + }, function(reason) { + // reason.message === '2' + }); + ``` + + `RSVP.map` will also wait if a promise is returned from `mapFn`. For example, + say you want to get all comments from a set of blog posts, but you need + the blog posts first because they contain a url to those comments. + + ```javscript + + let mapFn = function(blogPost){ + // getComments does some ajax and returns an RSVP.Promise that is fulfilled + // with some comments data + return getComments(blogPost.comments_url); + }; + + // getBlogPosts does some ajax and returns an RSVP.Promise that is fulfilled + // with some blog post data + RSVP.map(getBlogPosts(), mapFn).then(function(comments){ + // comments is the result of asking the server for the comments + // of all blog posts returned from getBlogPosts() + }); + ``` + + @method map + @static + @for RSVP + @param {Array} promises + @param {Function} mapFn function to be called on each fulfilled promise. + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} promise that is fulfilled with the result of calling + `mapFn` on each fulfilled promise or value when they become fulfilled. + The promise will be rejected if any of the given `promises` become rejected. + @static +*/ +function map(promises, mapFn, label) { + if (!isArray(promises)) { + return Promise.reject(new TypeError("RSVP.map must be called with an array"), label); + } + + if (!isFunction(mapFn)) { + return Promise.reject(new TypeError("RSVP.map expects a function as a second argument"), label); + } + + return Promise.all(promises, label).then(function (values) { + var length = values.length; + var results = new Array(length); + + for (var i = 0; i < length; i++) { + results[i] = mapFn(values[i]); + } + + return Promise.all(results, label); + }); +} + +/** + This is a convenient alias for `RSVP.Promise.resolve`. + + @method resolve + @static + @for RSVP + @param {*} value value that the returned promise will be resolved with + @param {String} label optional string for identifying the returned promise. + Useful for tooling. + @return {Promise} a promise that will become fulfilled with the given + `value` +*/ +function resolve$2(value, label) { + return Promise.resolve(value, label); +} + +/** + This is a convenient alias for `RSVP.Promise.reject`. + + @method reject + @static + @for RSVP + @param {*} reason value that the returned promise will be rejected with. + @param {String} label optional string for identifying the returned promise. + Useful for tooling. + @return {Promise} a promise rejected with the given `reason`. +*/ +function reject$2(reason, label) { + return Promise.reject(reason, label); +} + +/** + `RSVP.filter` is similar to JavaScript's native `filter` method, except that it + waits for all promises to become fulfilled before running the `filterFn` on + each item in given to `promises`. `RSVP.filter` returns a promise that will + become fulfilled with the result of running `filterFn` on the values the + promises become fulfilled with. + + For example: + + ```javascript + + let promise1 = RSVP.resolve(1); + let promise2 = RSVP.resolve(2); + let promise3 = RSVP.resolve(3); + + let promises = [promise1, promise2, promise3]; + + let filterFn = function(item){ + return item > 1; + }; + + RSVP.filter(promises, filterFn).then(function(result){ + // result is [ 2, 3 ] + }); + ``` + + If any of the `promises` given to `RSVP.filter` are rejected, the first promise + that is rejected will be given as an argument to the returned promise's + rejection handler. For example: + + ```javascript + let promise1 = RSVP.resolve(1); + let promise2 = RSVP.reject(new Error('2')); + let promise3 = RSVP.reject(new Error('3')); + let promises = [ promise1, promise2, promise3 ]; + + let filterFn = function(item){ + return item > 1; + }; + + RSVP.filter(promises, filterFn).then(function(array){ + // Code here never runs because there are rejected promises! + }, function(reason) { + // reason.message === '2' + }); + ``` + + `RSVP.filter` will also wait for any promises returned from `filterFn`. + For instance, you may want to fetch a list of users then return a subset + of those users based on some asynchronous operation: + + ```javascript + + let alice = { name: 'alice' }; + let bob = { name: 'bob' }; + let users = [ alice, bob ]; + + let promises = users.map(function(user){ + return RSVP.resolve(user); + }); + + let filterFn = function(user){ + // Here, Alice has permissions to create a blog post, but Bob does not. + return getPrivilegesForUser(user).then(function(privs){ + return privs.can_create_blog_post === true; + }); + }; + RSVP.filter(promises, filterFn).then(function(users){ + // true, because the server told us only Alice can create a blog post. + users.length === 1; + // false, because Alice is the only user present in `users` + users[0] === bob; + }); + ``` + + @method filter + @static + @for RSVP + @param {Array} promises + @param {Function} filterFn - function to be called on each resolved value to + filter the final results. + @param {String} label optional string describing the promise. Useful for + tooling. + @return {Promise} +*/ + +function resolveAll(promises, label) { + return Promise.all(promises, label); +} + +function resolveSingle(promise, label) { + return Promise.resolve(promise, label).then(function (promises) { + return resolveAll(promises, label); + }); +} + +function filter(promises, filterFn, label) { + if (!isArray(promises) && !(isObject(promises) && promises.then !== undefined)) { + return Promise.reject(new TypeError("RSVP.filter must be called with an array or promise"), label); + } + + if (!isFunction(filterFn)) { + return Promise.reject(new TypeError("RSVP.filter expects function as a second argument"), label); + } + + var promise = isArray(promises) ? resolveAll(promises, label) : resolveSingle(promises, label); + return promise.then(function (values) { + var length = values.length; + var filtered = new Array(length); + + for (var i = 0; i < length; i++) { + filtered[i] = filterFn(values[i]); + } + + return resolveAll(filtered, label).then(function (filtered) { + var results = new Array(length); + var newLength = 0; + + for (var _i = 0; _i < length; _i++) { + if (filtered[_i]) { + results[newLength] = values[_i]; + newLength++; + } + } + + results.length = newLength; + + return results; + }); + }); +} + +var len = 0; +var vertxNext = void 0; +function asap(callback, arg) { + queue$1[len] = callback; + queue$1[len + 1] = arg; + len += 2; + if (len === 2) { + // If len is 1, that means that we need to schedule an async flush. + // If additional callbacks are queued before the queue is flushed, they + // will be processed by this flush that we are scheduling. + scheduleFlush$1(); + } +} + +var browserWindow = typeof window !== 'undefined' ? window : undefined; +var browserGlobal = browserWindow || {}; +var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; +var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]'; + +// test for web worker but not in IE10 +var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined'; + +// node +function useNextTick() { + var nextTick = process.nextTick; + // node version 0.10.x displays a deprecation warning when nextTick is used recursively + // setImmediate should be used instead instead + var version = process.versions.node.match(/^(?:(\d+)\.)?(?:(\d+)\.)?(\*|\d+)$/); + if (Array.isArray(version) && version[1] === '0' && version[2] === '10') { + nextTick = setImmediate; + } + return function () { + return nextTick(flush); + }; +} + +// vertx +function useVertxTimer() { + if (typeof vertxNext !== 'undefined') { + return function () { + vertxNext(flush); + }; + } + return useSetTimeout(); +} + +function useMutationObserver() { + var iterations = 0; + var observer = new BrowserMutationObserver(flush); + var node = document.createTextNode(''); + observer.observe(node, { characterData: true }); + + return function () { + return node.data = iterations = ++iterations % 2; + }; +} + +// web worker +function useMessageChannel() { + var channel = new MessageChannel(); + channel.port1.onmessage = flush; + return function () { + return channel.port2.postMessage(0); + }; +} + +function useSetTimeout() { + return function () { + return setTimeout(flush, 1); + }; +} + +var queue$1 = new Array(1000); + +function flush() { + for (var i = 0; i < len; i += 2) { + var callback = queue$1[i]; + var arg = queue$1[i + 1]; + + callback(arg); + + queue$1[i] = undefined; + queue$1[i + 1] = undefined; + } + + len = 0; +} + +function attemptVertex() { + try { + var r = require; + var vertx = r('vertx'); + vertxNext = vertx.runOnLoop || vertx.runOnContext; + return useVertxTimer(); + } catch (e) { + return useSetTimeout(); + } +} + +var scheduleFlush$1 = void 0; +// Decide what async method to use to triggering processing of queued callbacks: +if (isNode) { + scheduleFlush$1 = useNextTick(); +} else if (BrowserMutationObserver) { + scheduleFlush$1 = useMutationObserver(); +} else if (isWorker) { + scheduleFlush$1 = useMessageChannel(); +} else if (browserWindow === undefined && typeof require === 'function') { + scheduleFlush$1 = attemptVertex(); +} else { + scheduleFlush$1 = useSetTimeout(); +} + +var platform = void 0; + +/* global self */ +if (typeof self === 'object') { + platform = self; + + /* global global */ +} else if (typeof global === 'object') { + platform = global; +} else { + throw new Error('no global: `self` or `global` found'); +} + +var _asap$cast$Promise$Ev; + +function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } + +// defaults +config.async = asap; +config.after = function (cb) { + return setTimeout(cb, 0); +}; +var cast = resolve$2; + +var async = function (callback, arg) { + return config.async(callback, arg); +}; + +function on() { + config['on'].apply(config, arguments); +} + +function off() { + config['off'].apply(config, arguments); +} + +// Set up instrumentation through `window.__PROMISE_INTRUMENTATION__` +if (typeof window !== 'undefined' && typeof window['__PROMISE_INSTRUMENTATION__'] === 'object') { + var callbacks = window['__PROMISE_INSTRUMENTATION__']; + configure('instrument', true); + for (var eventName in callbacks) { + if (callbacks.hasOwnProperty(eventName)) { + on(eventName, callbacks[eventName]); + } + } +} + +// the default export here is for backwards compat: +// https://github.com/tildeio/rsvp.js/issues/434 +var rsvp = (_asap$cast$Promise$Ev = { + asap: asap, + cast: cast, + Promise: Promise, + EventTarget: EventTarget, + all: all$1, + allSettled: allSettled, + race: race$1, + hash: hash, + hashSettled: hashSettled, + rethrow: rethrow, + defer: defer, + denodeify: denodeify, + configure: configure, + on: on, + off: off, + resolve: resolve$2, + reject: reject$2, + map: map +}, _defineProperty(_asap$cast$Promise$Ev, 'async', async), _defineProperty(_asap$cast$Promise$Ev, 'filter', filter), _asap$cast$Promise$Ev); + +exports['default'] = rsvp; +exports.asap = asap; +exports.cast = cast; +exports.Promise = Promise; +exports.EventTarget = EventTarget; +exports.all = all$1; +exports.allSettled = allSettled; +exports.race = race$1; +exports.hash = hash; +exports.hashSettled = hashSettled; +exports.rethrow = rethrow; +exports.defer = defer; +exports.denodeify = denodeify; +exports.configure = configure; +exports.on = on; +exports.off = off; +exports.resolve = resolve$2; +exports.reject = reject$2; +exports.map = map; +exports.async = async; +exports.filter = filter; + +Object.defineProperty(exports, '__esModule', { value: true }); + +}))); + +// + +var EPUBJS = EPUBJS || {}; +EPUBJS.core = {}; + +var ELEMENT_NODE = 1; +var TEXT_NODE = 3; +var COMMENT_NODE = 8; +var DOCUMENT_NODE = 9; + +//-- Get a element for an id +EPUBJS.core.getEl = function(elem) { + return document.getElementById(elem); +}; + +//-- Get all elements for a class +EPUBJS.core.getEls = function(classes) { + return document.getElementsByClassName(classes); +}; + +EPUBJS.core.request = function(url, type, withCredentials) { + var supportsURL = window.URL; + var BLOB_RESPONSE = supportsURL ? "blob" : "arraybuffer"; + var deferred = new RSVP.defer(); + var xhr = new XMLHttpRequest(); + var uri; + + //-- Check from PDF.js: + // https://github.com/mozilla/pdf.js/blob/master/web/compatibility.js + var xhrPrototype = XMLHttpRequest.prototype; + + var handler = function() { + var r; + + if (this.readyState != this.DONE) return; + + if ((this.status === 200 || this.status === 0) && this.response) { // Android & Firefox reporting 0 for local & blob urls + if (type == 'xml'){ + // If this.responseXML wasn't set, try to parse using a DOMParser from text + if(!this.responseXML) { + r = new DOMParser().parseFromString(this.response, "application/xml"); + } else { + r = this.responseXML; + } + } else if (type == 'xhtml') { + if (!this.responseXML){ + r = new DOMParser().parseFromString(this.response, "application/xhtml+xml"); + } else { + r = this.responseXML; + } + } else if (type == 'html') { + if (!this.responseXML){ + r = new DOMParser().parseFromString(this.response, "text/html"); + } else { + r = this.responseXML; + } + } else if (type == 'json') { + r = JSON.parse(this.response); + } else if (type == 'blob') { + if (supportsURL) { + r = this.response; + } else { + //-- Safari doesn't support responseType blob, so create a blob from arraybuffer + r = new Blob([this.response]); + } + } else { + r = this.response; + } + + deferred.resolve(r); + } else { + deferred.reject({ + message : this.response, + stack : new Error().stack + }); + } + }; + + if (!('overrideMimeType' in xhrPrototype)) { + // IE10 might have response, but not overrideMimeType + Object.defineProperty(xhrPrototype, 'overrideMimeType', { + value: function xmlHttpRequestOverrideMimeType(mimeType) {} + }); + } + + xhr.onreadystatechange = handler; + xhr.open("GET", url, true); + + if(withCredentials) { + xhr.withCredentials = true; + } + + // If type isn't set, determine it from the file extension + if(!type) { + uri = EPUBJS.core.uri(url); + type = uri.extension; + type = { + 'htm': 'html' + }[type] || type; + } + + if(type == 'blob'){ + xhr.responseType = BLOB_RESPONSE; + } + + if(type == "json") { + xhr.setRequestHeader("Accept", "application/json"); + } + + if(type == 'xml') { + xhr.responseType = "document"; + xhr.overrideMimeType('text/xml'); // for OPF parsing + } + + if(type == 'xhtml') { + xhr.responseType = "document"; + } + + if(type == 'html') { + xhr.responseType = "document"; + } + + if(type == "binary") { + xhr.responseType = "arraybuffer"; + } + + xhr.send(); + + return deferred.promise; +}; + +EPUBJS.core.toArray = function(obj) { + var arr = []; + + for (var member in obj) { + var newitm; + if ( obj.hasOwnProperty(member) ) { + newitm = obj[member]; + newitm.ident = member; + arr.push(newitm); + } + } + + return arr; +}; + +//-- Parse the different parts of a url, returning a object +EPUBJS.core.uri = function(url){ + var uri = { + protocol : '', + host : '', + path : '', + origin : '', + directory : '', + base : '', + filename : '', + extension : '', + fragment : '', + href : url + }, + blob = url.indexOf('blob:'), + doubleSlash = url.indexOf('://'), + search = url.indexOf('?'), + fragment = url.indexOf("#"), + withoutProtocol, + dot, + firstSlash; + + if(blob === 0) { + uri.protocol = "blob"; + uri.base = url.indexOf(0, fragment); + return uri; + } + + if(fragment != -1) { + uri.fragment = url.slice(fragment + 1); + url = url.slice(0, fragment); + } + + if(search != -1) { + uri.search = url.slice(search + 1); + url = url.slice(0, search); + href = uri.href; + } + + if(doubleSlash != -1) { + uri.protocol = url.slice(0, doubleSlash); + withoutProtocol = url.slice(doubleSlash+3); + firstSlash = withoutProtocol.indexOf('/'); + + if(firstSlash === -1) { + uri.host = uri.path; + uri.path = ""; + } else { + uri.host = withoutProtocol.slice(0, firstSlash); + uri.path = withoutProtocol.slice(firstSlash); + } + + + uri.origin = uri.protocol + "://" + uri.host; + + uri.directory = EPUBJS.core.folder(uri.path); + + uri.base = uri.origin + uri.directory; + // return origin; + } else { + uri.path = url; + uri.directory = EPUBJS.core.folder(url); + uri.base = uri.directory; + } + + //-- Filename + uri.filename = url.replace(uri.base, ''); + dot = uri.filename.lastIndexOf('.'); + if(dot != -1) { + uri.extension = uri.filename.slice(dot+1); + } + return uri; +}; + +//-- Parse out the folder, will return everything before the last slash + +EPUBJS.core.folder = function(url){ + + var lastSlash = url.lastIndexOf('/'); + + if(lastSlash == -1) var folder = ''; + + folder = url.slice(0, lastSlash + 1); + + return folder; + +}; + +//-- https://github.com/ebidel/filer.js/blob/master/src/filer.js#L128 +EPUBJS.core.dataURLToBlob = function(dataURL) { + var BASE64_MARKER = ';base64,', + parts, contentType, raw, rawLength, uInt8Array; + + if (dataURL.indexOf(BASE64_MARKER) == -1) { + parts = dataURL.split(','); + contentType = parts[0].split(':')[1]; + raw = parts[1]; + + return new Blob([raw], {type: contentType}); + } + + parts = dataURL.split(BASE64_MARKER); + contentType = parts[0].split(':')[1]; + raw = window.atob(parts[1]); + rawLength = raw.length; + + uInt8Array = new Uint8Array(rawLength); + + for (var i = 0; i < rawLength; ++i) { + uInt8Array[i] = raw.charCodeAt(i); + } + + return new Blob([uInt8Array], {type: contentType}); +}; + +//-- Load scripts async: http://stackoverflow.com/questions/7718935/load-scripts-asynchronously +EPUBJS.core.addScript = function(src, callback, target) { + var s, r; + r = false; + s = document.createElement('script'); + s.type = 'text/javascript'; + s.async = false; + s.src = src; + s.onload = s.onreadystatechange = function() { + if ( !r && (!this.readyState || this.readyState == 'complete') ) { + r = true; + if(callback) callback(); + } + }; + target = target || document.body; + target.appendChild(s); +}; + +EPUBJS.core.addScripts = function(srcArr, callback, target) { + var total = srcArr.length, + curr = 0, + cb = function(){ + curr++; + if(total == curr){ + if(callback) callback(); + }else{ + EPUBJS.core.addScript(srcArr[curr], cb, target); + } + }; + + EPUBJS.core.addScript(srcArr[curr], cb, target); +}; + +EPUBJS.core.addCss = function(src, callback, target) { + var s, r; + r = false; + s = document.createElement('link'); + s.type = 'text/css'; + s.rel = "stylesheet"; + s.href = src; + s.onload = s.onreadystatechange = function() { + if ( !r && (!this.readyState || this.readyState == 'complete') ) { + r = true; + if(callback) callback(); + } + }; + target = target || document.body; + target.appendChild(s); +}; + +EPUBJS.core.prefixed = function(unprefixed) { + var vendors = ["Webkit", "Moz", "O", "ms" ], + prefixes = ['-Webkit-', '-moz-', '-o-', '-ms-'], + upper = unprefixed[0].toUpperCase() + unprefixed.slice(1), + length = vendors.length; + + if (typeof(document.documentElement.style[unprefixed]) != 'undefined') { + return unprefixed; + } + + for ( var i=0; i < length; i++ ) { + if (typeof(document.documentElement.style[vendors[i] + upper]) != 'undefined') { + return vendors[i] + upper; + } + } + + return unprefixed; +}; + +EPUBJS.core.resolveUrl = function(base, path) { + var url, + segments = [], + uri = EPUBJS.core.uri(path), + folders = base.split("/"), + paths; + + if(uri.host) { + return path; + } + + folders.pop(); + + paths = path.split("/"); + paths.forEach(function(p){ + if(p === ".."){ + folders.pop(); + }else{ + segments.push(p); + } + }); + + url = folders.concat(segments); + + return url.join("/"); +}; + +// http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript +EPUBJS.core.uuid = function() { + var d = new Date().getTime(); + var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { + var r = (d + Math.random()*16)%16 | 0; + d = Math.floor(d/16); + return (c=='x' ? r : (r&0x7|0x8)).toString(16); + }); + return uuid; +}; + +// Fast quicksort insert for sorted array -- based on: +// http://stackoverflow.com/questions/1344500/efficient-way-to-insert-a-number-into-a-sorted-array-of-numbers +EPUBJS.core.insert = function(item, array, compareFunction) { + var location = EPUBJS.core.locationOf(item, array, compareFunction); + array.splice(location, 0, item); + + return location; +}; + +EPUBJS.core.locationOf = function(item, array, compareFunction, _start, _end) { + var start = _start || 0; + var end = _end || array.length; + var pivot = parseInt(start + (end - start) / 2); + var compared; + if(!compareFunction){ + compareFunction = function(a, b) { + if(a > b) return 1; + if(a < b) return -1; + if(a = b) return 0; + }; + } + if(end-start <= 0) { + return pivot; + } + + compared = compareFunction(array[pivot], item); + if(end-start === 1) { + return compared > 0 ? pivot : pivot + 1; + } + + if(compared === 0) { + return pivot; + } + if(compared === -1) { + return EPUBJS.core.locationOf(item, array, compareFunction, pivot, end); + } else{ + return EPUBJS.core.locationOf(item, array, compareFunction, start, pivot); + } +}; + +EPUBJS.core.indexOfSorted = function(item, array, compareFunction, _start, _end) { + var start = _start || 0; + var end = _end || array.length; + var pivot = parseInt(start + (end - start) / 2); + var compared; + if(!compareFunction){ + compareFunction = function(a, b) { + if(a > b) return 1; + if(a < b) return -1; + if(a = b) return 0; + }; + } + if(end-start <= 0) { + return -1; // Not found + } + + compared = compareFunction(array[pivot], item); + if(end-start === 1) { + return compared === 0 ? pivot : -1; + } + if(compared === 0) { + return pivot; // Found + } + if(compared === -1) { + return EPUBJS.core.indexOfSorted(item, array, compareFunction, pivot, end); + } else{ + return EPUBJS.core.indexOfSorted(item, array, compareFunction, start, pivot); + } +}; + + +EPUBJS.core.queue = function(_scope){ + var _q = []; + var scope = _scope; + // Add an item to the queue + var enqueue = function(funcName, args, context) { + _q.push({ + "funcName" : funcName, + "args" : args, + "context" : context + }); + return _q; + }; + // Run one item + var dequeue = function(){ + var inwait; + if(_q.length) { + inwait = _q.shift(); + // Defer to any current tasks + // setTimeout(function(){ + scope[inwait.funcName].apply(inwait.context || scope, inwait.args); + // }, 0); + } + }; + + // Run All + var flush = function(){ + while(_q.length) { + dequeue(); + } + }; + // Clear all items in wait + var clear = function(){ + _q = []; + }; + + var length = function(){ + return _q.length; + }; + + return { + "enqueue" : enqueue, + "dequeue" : dequeue, + "flush" : flush, + "clear" : clear, + "length" : length + }; +}; + +// From: https://code.google.com/p/fbug/source/browse/branches/firebug1.10/content/firebug/lib/xpath.js +/** + * Gets an XPath for an element which describes its hierarchical location. + */ +EPUBJS.core.getElementXPath = function(element) { + if (element && element.id) { + return '//*[@id="' + element.id + '"]'; + } else { + return EPUBJS.core.getElementTreeXPath(element); + } +}; + +EPUBJS.core.getElementTreeXPath = function(element) { + var paths = []; + var isXhtml = (element.ownerDocument.documentElement.getAttribute('xmlns') === "http://www.w3.org/1999/xhtml"); + var index, nodeName, tagName, pathIndex; + + if(element.nodeType === Node.TEXT_NODE){ + // index = Array.prototype.indexOf.call(element.parentNode.childNodes, element) + 1; + index = EPUBJS.core.indexOfTextNode(element) + 1; + + paths.push("text()["+index+"]"); + element = element.parentNode; + } + + // Use nodeName (instead of localName) so namespace prefix is included (if any). + for (; element && element.nodeType == 1; element = element.parentNode) + { + index = 0; + for (var sibling = element.previousSibling; sibling; sibling = sibling.previousSibling) + { + // Ignore document type declaration. + if (sibling.nodeType == Node.DOCUMENT_TYPE_NODE) { + continue; + } + if (sibling.nodeName == element.nodeName) { + ++index; + } + } + nodeName = element.nodeName.toLowerCase(); + tagName = (isXhtml ? "xhtml:" + nodeName : nodeName); + pathIndex = (index ? "[" + (index+1) + "]" : ""); + paths.splice(0, 0, tagName + pathIndex); + } + + return paths.length ? "./" + paths.join("/") : null; +}; + +EPUBJS.core.nsResolver = function(prefix) { + var ns = { + 'xhtml' : 'http://www.w3.org/1999/xhtml', + 'epub': 'http://www.idpf.org/2007/ops' + }; + return ns[prefix] || null; +}; + +//https://stackoverflow.com/questions/13482352/xquery-looking-for-text-with-single-quote/13483496#13483496 +EPUBJS.core.cleanStringForXpath = function(str) { + var parts = str.match(/[^'"]+|['"]/g); + parts = parts.map(function(part){ + if (part === "'") { + return '\"\'\"'; // output "'" + } + + if (part === '"') { + return "\'\"\'"; // output '"' + } + return "\'" + part + "\'"; + }); + return "concat(\'\'," + parts.join(",") + ")"; +}; + +EPUBJS.core.indexOfTextNode = function(textNode){ + var parent = textNode.parentNode; + var children = parent.childNodes; + var sib; + var index = -1; + for (var i = 0; i < children.length; i++) { + sib = children[i]; + if(sib.nodeType === Node.TEXT_NODE){ + index++; + } + if(sib == textNode) break; + } + + return index; +}; + +// Underscore +EPUBJS.core.defaults = function(obj) { + for (var i = 1, length = arguments.length; i < length; i++) { + var source = arguments[i]; + for (var prop in source) { + if (obj[prop] === void 0) obj[prop] = source[prop]; + } + } + return obj; +}; + +EPUBJS.core.extend = function(target) { + var sources = [].slice.call(arguments, 1); + sources.forEach(function (source) { + if(!source) return; + Object.getOwnPropertyNames(source).forEach(function(propName) { + Object.defineProperty(target, propName, Object.getOwnPropertyDescriptor(source, propName)); + }); + }); + return target; +}; + +EPUBJS.core.clone = function(obj) { + return EPUBJS.core.isArray(obj) ? obj.slice() : EPUBJS.core.extend({}, obj); +}; + +EPUBJS.core.isElement = function(obj) { + return !!(obj && obj.nodeType == 1); +}; + +EPUBJS.core.isNumber = function(n) { + return !isNaN(parseFloat(n)) && isFinite(n); +}; + +EPUBJS.core.isString = function(str) { + return (typeof str === 'string' || str instanceof String); +}; + +EPUBJS.core.isArray = Array.isArray || function(obj) { + return Object.prototype.toString.call(obj) === '[object Array]'; +}; + +// Lodash +EPUBJS.core.values = function(object) { + var index = -1; + var props, length, result; + + if(!object) return []; + + props = Object.keys(object); + length = props.length; + result = Array(length); + + while (++index < length) { + result[index] = object[props[index]]; + } + return result; +}; + +EPUBJS.core.indexOfNode = function(node, typeId) { + var parent = node.parentNode; + var children = parent.childNodes; + var sib; + var index = -1; + for (var i = 0; i < children.length; i++) { + sib = children[i]; + if (sib.nodeType === typeId) { + index++; + } + if (sib == node) break; + } + + return index; +} + +EPUBJS.core.indexOfTextNode = function(textNode) { + return EPUBJS.core.indexOfNode(textNode, TEXT_NODE); +} + +EPUBJS.core.indexOfElementNode = function(elementNode) { + return EPUBJS.core.indexOfNode(elementNode, ELEMENT_NODE); +} + +var EPUBJS = EPUBJS || {}; +EPUBJS.reader = {}; +EPUBJS.reader.plugins = {}; //-- Attach extra Controllers as plugins (like search?) + +(function(root, $) { + + var previousReader = root.ePubReader || {}; + + var ePubReader = root.ePubReader = function(path, options) { + return new EPUBJS.Reader(path, options); + }; + + //exports to multiple environments + if (typeof define === 'function' && define.amd) { + //AMD + define(function(){ return Reader; }); + } else if (typeof module != "undefined" && module.exports) { + //Node + module.exports = ePubReader; + } + +})(window, jQuery); + +EPUBJS.Reader = function(bookPath, _options) { + var reader = this; + var book; + var plugin; + var $viewer = $("#viewer"); + var search = window.location.search; + var parameters; + + this.settings = EPUBJS.core.defaults(_options || {}, { + bookPath : bookPath, + restore : false, + reload : false, + bookmarks : undefined, + annotations : undefined, + contained : undefined, + bookKey : undefined, + styles : undefined, + sidebarReflow: false, + generatePagination: false, + history: true + }); + + // Overide options with search parameters + if(search) { + parameters = search.slice(1).split("&"); + parameters.forEach(function(p){ + var split = p.split("="); + var name = split[0]; + var value = split[1] || ''; + reader.settings[name] = decodeURIComponent(value); + }); + } + + this.setBookKey(this.settings.bookPath); //-- This could be username + path or any unique string + + if(this.settings.restore && this.isSaved()) { + this.applySavedSettings(); + } + + this.settings.styles = this.settings.styles || { + fontSize : "100%" + }; + + this.book = book = new ePub(this.settings.bookPath, this.settings); + + this.offline = false; + this.sidebarOpen = false; + if(!this.settings.bookmarks) { + this.settings.bookmarks = []; + } + + if(!this.settings.annotations) { + this.settings.annotations = []; + } + + if(this.settings.generatePagination) { + book.generatePagination($viewer.width(), $viewer.height()); + } + + this.rendition = book.renderTo("viewer", { + ignoreClass: "annotator-hl", + width: "100%", + height: "100%" + }); + + if(this.settings.previousLocationCfi) { + this.displayed = this.rendition.display(this.settings.previousLocationCfi); + } else { + this.displayed = this.rendition.display(); + } + + book.ready.then(function () { + reader.ReaderController = EPUBJS.reader.ReaderController.call(reader, book); + reader.SettingsController = EPUBJS.reader.SettingsController.call(reader, book); + reader.ControlsController = EPUBJS.reader.ControlsController.call(reader, book); + reader.SidebarController = EPUBJS.reader.SidebarController.call(reader, book); + reader.BookmarksController = EPUBJS.reader.BookmarksController.call(reader, book); + reader.NotesController = EPUBJS.reader.NotesController.call(reader, book); + + window.addEventListener("hashchange", this.hashChanged.bind(this), false); + + document.addEventListener('keydown', this.adjustFontSize.bind(this), false); + + this.rendition.on("keydown", this.adjustFontSize.bind(this)); + this.rendition.on("keydown", reader.ReaderController.arrowKeys.bind(this)); + + this.rendition.on("selected", this.selectedRange.bind(this)); + }.bind(this)).then(function() { + reader.ReaderController.hideLoader(); + }.bind(this)); + + // Call Plugins + for(plugin in EPUBJS.reader.plugins) { + if(EPUBJS.reader.plugins.hasOwnProperty(plugin)) { + reader[plugin] = EPUBJS.reader.plugins[plugin].call(reader, book); + } + } + + book.loaded.metadata.then(function(meta) { + reader.MetaController = EPUBJS.reader.MetaController.call(reader, meta); + }); + + book.loaded.navigation.then(function(navigation) { + reader.TocController = EPUBJS.reader.TocController.call(reader, navigation); + }); + + window.addEventListener("beforeunload", this.unload.bind(this), false); + + return this; +}; + +EPUBJS.Reader.prototype.adjustFontSize = function(e) { + var fontSize; + var interval = 2; + var PLUS = 187; + var MINUS = 189; + var ZERO = 48; + var MOD = (e.ctrlKey || e.metaKey ); + + if(!this.settings.styles) return; + + if(!this.settings.styles.fontSize) { + this.settings.styles.fontSize = "100%"; + } + + fontSize = parseInt(this.settings.styles.fontSize.slice(0, -1)); + + if(MOD && e.keyCode == PLUS) { + e.preventDefault(); + this.book.setStyle("fontSize", (fontSize + interval) + "%"); + + } + + if(MOD && e.keyCode == MINUS){ + + e.preventDefault(); + this.book.setStyle("fontSize", (fontSize - interval) + "%"); + } + + if(MOD && e.keyCode == ZERO){ + e.preventDefault(); + this.book.setStyle("fontSize", "100%"); + } +}; + +EPUBJS.Reader.prototype.addBookmark = function(cfi) { + var present = this.isBookmarked(cfi); + if(present > -1 ) return; + + this.settings.bookmarks.push(cfi); + + this.trigger("reader:bookmarked", cfi); +}; + +EPUBJS.Reader.prototype.removeBookmark = function(cfi) { + var bookmark = this.isBookmarked(cfi); + if( bookmark === -1 ) return; + + this.settings.bookmarks.splice(bookmark, 1); + + this.trigger("reader:unbookmarked", bookmark); +}; + +EPUBJS.Reader.prototype.isBookmarked = function(cfi) { + var bookmarks = this.settings.bookmarks; + + return bookmarks.indexOf(cfi); +}; + +/* +EPUBJS.Reader.prototype.searchBookmarked = function(cfi) { + var bookmarks = this.settings.bookmarks, + len = bookmarks.length, + i; + + for(i = 0; i < len; i++) { + if (bookmarks[i]['cfi'] === cfi) return i; + } + return -1; +}; +*/ + +EPUBJS.Reader.prototype.clearBookmarks = function() { + this.settings.bookmarks = []; +}; + +//-- Notes +EPUBJS.Reader.prototype.addNote = function(note) { + this.settings.annotations.push(note); +}; + +EPUBJS.Reader.prototype.removeNote = function(note) { + var index = this.settings.annotations.indexOf(note); + if( index === -1 ) return; + + delete this.settings.annotations[index]; + +}; + +EPUBJS.Reader.prototype.clearNotes = function() { + this.settings.annotations = []; +}; + +//-- Settings +EPUBJS.Reader.prototype.setBookKey = function(identifier){ + if(!this.settings.bookKey) { + this.settings.bookKey = "epubjsreader:" + EPUBJS.VERSION + ":" + window.location.host + ":" + identifier; + } + return this.settings.bookKey; +}; + +//-- Checks if the book setting can be retrieved from localStorage +EPUBJS.Reader.prototype.isSaved = function(bookPath) { + var storedSettings; + + if(!localStorage) { + return false; + } + + storedSettings = localStorage.getItem(this.settings.bookKey); + + if(storedSettings === null) { + return false; + } else { + return true; + } +}; + +EPUBJS.Reader.prototype.removeSavedSettings = function() { + if(!localStorage) { + return false; + } + + localStorage.removeItem(this.settings.bookKey); +}; + +EPUBJS.Reader.prototype.applySavedSettings = function() { + var stored; + + if(!localStorage) { + return false; + } + + try { + stored = JSON.parse(localStorage.getItem(this.settings.bookKey)); + } catch (e) { // parsing error of localStorage + return false; + } + + if(stored) { + // Merge styles + if(stored.styles) { + this.settings.styles = EPUBJS.core.defaults(this.settings.styles || {}, stored.styles); + } + // Merge the rest + this.settings = EPUBJS.core.defaults(this.settings, stored); + return true; + } else { + return false; + } +}; + +EPUBJS.Reader.prototype.saveSettings = function(){ + if(this.book) { + this.settings.previousLocationCfi = this.rendition.currentLocation().start.cfi; + } + + if(!localStorage) { + return false; + } + + localStorage.setItem(this.settings.bookKey, JSON.stringify(this.settings)); +}; + +EPUBJS.Reader.prototype.unload = function(){ + if(this.settings.restore && localStorage) { + this.saveSettings(); + } +}; + + +EPUBJS.Reader.prototype.hashChanged = function(){ + var hash = window.location.hash.slice(1); + this.rendition.display(hash); +}; + +EPUBJS.Reader.prototype.selectedRange = function(cfiRange){ + var cfiFragment = "#"+cfiRange; + + // Update the History Location + if(this.settings.history && + window.location.hash != cfiFragment) { + // Add CFI fragment to the history + history.pushState({}, '', cfiFragment); + this.currentLocationCfi = cfiRange; + } +}; + +//-- Enable binding events to reader +RSVP.EventTarget.mixin(EPUBJS.Reader.prototype); + +EPUBJS.reader.BookmarksController = function() { + var reader = this; + var book = this.book; + var rendition = this.rendition; + + var $bookmarks = $("#bookmarksView"), + $list = $bookmarks.find("#bookmarks"); + + var docfrag = document.createDocumentFragment(); + + var show = function() { + $bookmarks.show(); + }; + + var hide = function() { + $bookmarks.hide(); + }; + + var counter = 0; + + var createBookmarkItem = function(cfi) { + var listitem = document.createElement("li"), + link = document.createElement("a"); + + listitem.id = "bookmark-"+counter; + listitem.classList.add('list_item'); + + var spineItem = book.spine.get(cfi); + var tocItem; + if (spineItem.index in book.navigation.toc) { + tocItem = book.navigation.toc[spineItem.index]; + link.textContent = tocItem.label; + } else { + link.textContent = cfi; + } + + link.href = cfi; + + link.classList.add('bookmark_link'); + + link.addEventListener("click", function(event){ + var cfi = this.getAttribute('href'); + rendition.display(cfi); + event.preventDefault(); + }, false); + + listitem.appendChild(link); + + counter++; + + return listitem; + }; + + this.settings.bookmarks.forEach(function(cfi) { + var bookmark = createBookmarkItem(cfi); + docfrag.appendChild(bookmark); + }); + + $list.append(docfrag); + + this.on("reader:bookmarked", function(cfi) { + var item = createBookmarkItem(cfi); + $list.append(item); + }); + + this.on("reader:unbookmarked", function(index) { + var $item = $("#bookmark-"+index); + $item.remove(); + }); + + return { + "show" : show, + "hide" : hide + }; +}; + +EPUBJS.reader.ControlsController = function(book) { + var reader = this; + var rendition = this.rendition; + + var $store = $("#store"), + $fullscreen = $("#fullscreen"), + $fullscreenicon = $("#fullscreenicon"), + $cancelfullscreenicon = $("#cancelfullscreenicon"), + $slider = $("#slider"), + $main = $("#main"), + $sidebar = $("#sidebar"), + $settings = $("#setting"), + $bookmark = $("#bookmark"); + /* + var goOnline = function() { + reader.offline = false; + // $store.attr("src", $icon.data("save")); + }; + + var goOffline = function() { + reader.offline = true; + // $store.attr("src", $icon.data("saved")); + }; + + var fullscreen = false; + + book.on("book:online", goOnline); + book.on("book:offline", goOffline); + */ + $slider.on("click", function () { + if(reader.sidebarOpen) { + reader.SidebarController.hide(); + $slider.addClass("icon-menu"); + $slider.removeClass("icon-right"); + } else { + reader.SidebarController.show(); + $slider.addClass("icon-right"); + $slider.removeClass("icon-menu"); + } + }); + + if(typeof screenfull !== 'undefined') { + $fullscreen.on("click", function() { + screenfull.toggle($('#container')[0]); + }); + if(screenfull.raw) { + document.addEventListener(screenfull.raw.fullscreenchange, function() { + fullscreen = screenfull.isFullscreen; + if(fullscreen) { + $fullscreen + .addClass("icon-resize-small") + .removeClass("icon-resize-full"); + } else { + $fullscreen + .addClass("icon-resize-full") + .removeClass("icon-resize-small"); + } + }); + } + } + + $settings.on("click", function() { + reader.SettingsController.show(); + }); + + $bookmark.on("click", function() { + var cfi = reader.rendition.currentLocation().start.cfi; + var bookmarked = reader.isBookmarked(cfi); + + if(bookmarked === -1) { //-- Add bookmark + reader.addBookmark(cfi); + $bookmark + .addClass("icon-bookmark") + .removeClass("icon-bookmark-empty"); + } else { //-- Remove Bookmark + reader.removeBookmark(cfi); + $bookmark + .removeClass("icon-bookmark") + .addClass("icon-bookmark-empty"); + } + + }); + + rendition.on('relocated', function(location){ + var cfi = location.start.cfi; + var cfiFragment = "#" + cfi; + //-- Check if bookmarked + var bookmarked = reader.isBookmarked(cfi); + if(bookmarked === -1) { //-- Not bookmarked + $bookmark + .removeClass("icon-bookmark") + .addClass("icon-bookmark-empty"); + } else { //-- Bookmarked + $bookmark + .addClass("icon-bookmark") + .removeClass("icon-bookmark-empty"); + } + + reader.currentLocationCfi = cfi; + + // Update the History Location + if(reader.settings.history && + window.location.hash != cfiFragment) { + // Add CFI fragment to the history + history.pushState({}, '', cfiFragment); + } + }); + + return { + + }; +}; + +EPUBJS.reader.MetaController = function(meta) { + var title = meta.title, + author = meta.creator; + + var $title = $("#book-title"), + $author = $("#chapter-title"), + $dash = $("#title-seperator"); + + document.title = title+" – "+author; + + $title.html(title); + $author.html(author); + $dash.show(); +}; + +EPUBJS.reader.NotesController = function() { + var book = this.book; + var rendition = this.rendition; + var reader = this; + var $notesView = $("#notesView"); + var $notes = $("#notes"); + var $text = $("#note-text"); + var $anchor = $("#note-anchor"); + var annotations = reader.settings.annotations; + var renderer = book.renderer; + var popups = []; + var epubcfi = new ePub.CFI(); + + var show = function() { + $notesView.show(); + }; + + var hide = function() { + $notesView.hide(); + } + + var insertAtPoint = function(e) { + var range; + var textNode; + var offset; + var doc = book.renderer.doc; + var cfi; + var annotation; + + // standard + if (doc.caretPositionFromPoint) { + range = doc.caretPositionFromPoint(e.clientX, e.clientY); + textNode = range.offsetNode; + offset = range.offset; + // WebKit + } else if (doc.caretRangeFromPoint) { + range = doc.caretRangeFromPoint(e.clientX, e.clientY); + textNode = range.startContainer; + offset = range.startOffset; + } + + if (textNode.nodeType !== 3) { + for (var i=0; i < textNode.childNodes.length; i++) { + if (textNode.childNodes[i].nodeType == 3) { + textNode = textNode.childNodes[i]; + break; + } + } + } + + // Find the end of the sentance + offset = textNode.textContent.indexOf(".", offset); + if(offset === -1){ + offset = textNode.length; // Last item + } else { + offset += 1; // After the period + } + + cfi = epubcfi.generateCfiFromTextNode(textNode, offset, book.renderer.currentChapter.cfiBase); + + annotation = { + annotatedAt: new Date(), + anchor: cfi, + body: $text.val() + } + + // add to list + reader.addNote(annotation); + + // attach + addAnnotation(annotation); + placeMarker(annotation); + + // clear + $text.val(''); + $anchor.text("Attach"); + $text.prop("disabled", false); + + rendition.off("click", insertAtPoint); + + }; + + var addAnnotation = function(annotation){ + var note = document.createElement("li"); + var link = document.createElement("a"); + + note.innerHTML = annotation.body; + // note.setAttribute("ref", annotation.anchor); + link.innerHTML = " context »"; + link.href = "#"+annotation.anchor; + link.onclick = function(){ + rendition.display(annotation.anchor); + return false; + }; + + note.appendChild(link); + $notes.append(note); + + }; + + var placeMarker = function(annotation){ + var doc = book.renderer.doc; + var marker = document.createElement("span"); + var mark = document.createElement("a"); + marker.classList.add("footnotesuperscript", "reader_generated"); + + marker.style.verticalAlign = "super"; + marker.style.fontSize = ".75em"; + // marker.style.position = "relative"; + marker.style.lineHeight = "1em"; + + // mark.style.display = "inline-block"; + mark.style.padding = "2px"; + mark.style.backgroundColor = "#fffa96"; + mark.style.borderRadius = "5px"; + mark.style.cursor = "pointer"; + + marker.id = "note-"+EPUBJS.core.uuid(); + mark.innerHTML = annotations.indexOf(annotation) + 1 + "[Reader]"; + + marker.appendChild(mark); + epubcfi.addMarker(annotation.anchor, doc, marker); + + markerEvents(marker, annotation.body); + } + + var markerEvents = function(item, txt){ + var id = item.id; + + var showPop = function(){ + var poppos, + iheight = renderer.height, + iwidth = renderer.width, + tip, + pop, + maxHeight = 225, + itemRect, + left, + top, + pos; + + + //-- create a popup with endnote inside of it + if(!popups[id]) { + popups[id] = document.createElement("div"); + popups[id].setAttribute("class", "popup"); + + pop_content = document.createElement("div"); + + popups[id].appendChild(pop_content); + + pop_content.innerHTML = txt; + pop_content.setAttribute("class", "pop_content"); + + renderer.render.document.body.appendChild(popups[id]); + + //-- TODO: will these leak memory? - Fred + popups[id].addEventListener("mouseover", onPop, false); + popups[id].addEventListener("mouseout", offPop, false); + + //-- Add hide on page change + rendition.on("locationChanged", hidePop, this); + rendition.on("locationChanged", offPop, this); + // chapter.book.on("renderer:chapterDestroy", hidePop, this); + } + + pop = popups[id]; + + + //-- get location of item + itemRect = item.getBoundingClientRect(); + left = itemRect.left; + top = itemRect.top; + + //-- show the popup + pop.classList.add("show"); + + //-- locations of popup + popRect = pop.getBoundingClientRect(); + + //-- position the popup + pop.style.left = left - popRect.width / 2 + "px"; + pop.style.top = top + "px"; + + + //-- Adjust max height + if(maxHeight > iheight / 2.5) { + maxHeight = iheight / 2.5; + pop_content.style.maxHeight = maxHeight + "px"; + } + + //-- switch above / below + if(popRect.height + top >= iheight - 25) { + pop.style.top = top - popRect.height + "px"; + pop.classList.add("above"); + }else{ + pop.classList.remove("above"); + } + + //-- switch left + if(left - popRect.width <= 0) { + pop.style.left = left + "px"; + pop.classList.add("left"); + }else{ + pop.classList.remove("left"); + } + + //-- switch right + if(left + popRect.width / 2 >= iwidth) { + //-- TEMP MOVE: 300 + pop.style.left = left - 300 + "px"; + + popRect = pop.getBoundingClientRect(); + pop.style.left = left - popRect.width + "px"; + //-- switch above / below again + if(popRect.height + top >= iheight - 25) { + pop.style.top = top - popRect.height + "px"; + pop.classList.add("above"); + }else{ + pop.classList.remove("above"); + } + + pop.classList.add("right"); + }else{ + pop.classList.remove("right"); + } + + } + + var onPop = function(){ + popups[id].classList.add("on"); + } + + var offPop = function(){ + popups[id].classList.remove("on"); + } + + var hidePop = function(){ + setTimeout(function(){ + popups[id].classList.remove("show"); + }, 100); + } + + var openSidebar = function(){ + reader.ReaderController.slideOut(); + show(); + }; + + item.addEventListener("mouseover", showPop, false); + item.addEventListener("mouseout", hidePop, false); + item.addEventListener("click", openSidebar, false); + + } + $anchor.on("click", function(e){ + + $anchor.text("Cancel"); + $text.prop("disabled", "true"); + // listen for selection + rendition.on("click", insertAtPoint); + + }); + + annotations.forEach(function(note) { + addAnnotation(note); + }); + + /* + renderer.registerHook("beforeChapterDisplay", function(callback, renderer){ + var chapter = renderer.currentChapter; + annotations.forEach(function(note) { + var cfi = epubcfi.parse(note.anchor); + if(cfi.spinePos === chapter.spinePos) { + try { + placeMarker(note); + } catch(e) { + console.log("anchoring failed", note.anchor); + } + } + }); + callback(); + }, true); + */ + + return { + "show" : show, + "hide" : hide + }; +}; + +EPUBJS.reader.ReaderController = function(book) { + var $main = $("#main"), + $divider = $("#divider"), + $loader = $("#loader"), + $next = $("#next"), + $prev = $("#prev"); + var reader = this; + var book = this.book; + var rendition = this.rendition; + var slideIn = function() { + var currentPosition = rendition.currentLocation().start.cfi; + if (reader.settings.sidebarReflow){ + $main.removeClass('single'); + $main.one("transitionend", function(){ + rendition.resize(); + }); + } else { + $main.removeClass("closed"); + } + }; + + var slideOut = function() { + var location = rendition.currentLocation(); + if (!location) { + return; + } + var currentPosition = location.start.cfi; + if (reader.settings.sidebarReflow){ + $main.addClass('single'); + $main.one("transitionend", function(){ + rendition.resize(); + }); + } else { + $main.addClass("closed"); + } + }; + + var showLoader = function() { + $loader.show(); + hideDivider(); + }; + + var hideLoader = function() { + $loader.hide(); + + //-- If the book is using spreads, show the divider + // if(book.settings.spreads) { + // showDivider(); + // } + }; + + var showDivider = function() { + $divider.addClass("show"); + }; + + var hideDivider = function() { + $divider.removeClass("show"); + }; + + var keylock = false; + + var arrowKeys = function(e) { + if(e.keyCode == 37) { + + if(book.package.metadata.direction === "rtl") { + rendition.next(); + } else { + rendition.prev(); + } + + $prev.addClass("active"); + + keylock = true; + setTimeout(function(){ + keylock = false; + $prev.removeClass("active"); + }, 100); + + e.preventDefault(); + } + if(e.keyCode == 39) { + + if(book.package.metadata.direction === "rtl") { + rendition.prev(); + } else { + rendition.next(); + } + + $next.addClass("active"); + + keylock = true; + setTimeout(function(){ + keylock = false; + $next.removeClass("active"); + }, 100); + + e.preventDefault(); + } + } + + document.addEventListener('keydown', arrowKeys, false); + + $next.on("click", function(e){ + + if(book.package.metadata.direction === "rtl") { + rendition.prev(); + } else { + rendition.next(); + } + + e.preventDefault(); + }); + + $prev.on("click", function(e){ + + if(book.package.metadata.direction === "rtl") { + rendition.next(); + } else { + rendition.prev(); + } + + e.preventDefault(); + }); + + rendition.on("layout", function(props){ + if(props.spread === true) { + showDivider(); + } else { + hideDivider(); + } + }); + + rendition.on('relocated', function(location){ + if (location.atStart) { + $prev.addClass("disabled"); + } + if (location.atEnd) { + $next.addClass("disabled"); + } + }); + + return { + "slideOut" : slideOut, + "slideIn" : slideIn, + "showLoader" : showLoader, + "hideLoader" : hideLoader, + "showDivider" : showDivider, + "hideDivider" : hideDivider, + "arrowKeys" : arrowKeys + }; +}; + +EPUBJS.reader.SettingsController = function() { + var book = this.book; + var reader = this; + var $settings = $("#settings-modal"), + $overlay = $(".overlay"); + + var show = function() { + $settings.addClass("md-show"); + }; + + var hide = function() { + $settings.removeClass("md-show"); + }; + + var $sidebarReflowSetting = $('#sidebarReflow'); + + $sidebarReflowSetting.on('click', function() { + reader.settings.sidebarReflow = !reader.settings.sidebarReflow; + }); + + $settings.find(".closer").on("click", function() { + hide(); + }); + + $overlay.on("click", function() { + hide(); + }); + + return { + "show" : show, + "hide" : hide + }; +}; +EPUBJS.reader.SidebarController = function(book) { + var reader = this; + + var $sidebar = $("#sidebar"), + $panels = $("#panels"); + + var activePanel = "Toc"; + + var changePanelTo = function(viewName) { + var controllerName = viewName + "Controller"; + + if(activePanel == viewName || typeof reader[controllerName] === 'undefined' ) return; + reader[activePanel+ "Controller"].hide(); + reader[controllerName].show(); + activePanel = viewName; + + $panels.find('.active').removeClass("active"); + $panels.find("#show-" + viewName ).addClass("active"); + }; + + var getActivePanel = function() { + return activePanel; + }; + + var show = function() { + reader.sidebarOpen = true; + reader.ReaderController.slideOut(); + $sidebar.addClass("open"); + } + + var hide = function() { + reader.sidebarOpen = false; + reader.ReaderController.slideIn(); + $sidebar.removeClass("open"); + } + + $panels.find(".show_view").on("click", function(event) { + var view = $(this).data("view"); + + changePanelTo(view); + event.preventDefault(); + }); + + return { + 'show' : show, + 'hide' : hide, + 'getActivePanel' : getActivePanel, + 'changePanelTo' : changePanelTo + }; +}; +EPUBJS.reader.TocController = function(toc) { + var book = this.book; + var rendition = this.rendition; + + var $list = $("#tocView"), + docfrag = document.createDocumentFragment(); + + var currentChapter = false; + + var generateTocItems = function(toc, level) { + var container = document.createElement("ul"); + + if(!level) level = 1; + + toc.forEach(function(chapter) { + var listitem = document.createElement("li"), + link = document.createElement("a"); + toggle = document.createElement("a"); + + var subitems; + + listitem.id = "toc-"+chapter.id; + listitem.classList.add('list_item'); + + link.textContent = chapter.label; + link.href = chapter.href; + + link.classList.add('toc_link'); + + listitem.appendChild(link); + + if(chapter.subitems && chapter.subitems.length > 0) { + level++; + subitems = generateTocItems(chapter.subitems, level); + toggle.classList.add('toc_toggle'); + + listitem.insertBefore(toggle, link); + listitem.appendChild(subitems); + } + + + container.appendChild(listitem); + + }); + + return container; + }; + + var onShow = function() { + $list.show(); + }; + + var onHide = function() { + $list.hide(); + }; + + var chapterChange = function(e) { + var id = e.id, + $item = $list.find("#toc-"+id), + $current = $list.find(".currentChapter"), + $open = $list.find('.openChapter'); + + if($item.length){ + + if($item != $current && $item.has(currentChapter).length > 0) { + $current.removeClass("currentChapter"); + } + + $item.addClass("currentChapter"); + + // $open.removeClass("openChapter"); + $item.parents('li').addClass("openChapter"); + } + }; + + rendition.on('renderered', chapterChange); + + var tocitems = generateTocItems(toc); + + docfrag.appendChild(tocitems); + + $list.append(docfrag); + $list.find(".toc_link").on("click", function(event){ + var url = this.getAttribute('href'); + + event.preventDefault(); + + //-- Provide the Book with the url to show + // The Url must be found in the books manifest + rendition.display(url); + + $list.find(".currentChapter") + .addClass("openChapter") + .removeClass("currentChapter"); + + $(this).parent('li').addClass("currentChapter"); + + }); + + $list.find(".toc_toggle").on("click", function(event){ + var $el = $(this).parent('li'), + open = $el.hasClass("openChapter"); + + event.preventDefault(); + if(open){ + $el.removeClass("openChapter"); + } else { + $el.addClass("openChapter"); + } + }); + + return { + "show" : onShow, + "hide" : onHide + }; +}; + +//# sourceMappingURL=reader.js.map \ No newline at end of file diff --git a/reader/static/js/epubjs_reader/reader.js.map b/reader/static/js/epubjs_reader/reader.js.map new file mode 100644 index 0000000000000000000000000000000000000000..bee76df97a834f9f58b66a06e986a0e4d3e0040b --- /dev/null +++ b/reader/static/js/epubjs_reader/reader.js.map @@ -0,0 +1,89 @@ +{ + "version": 3, + "file": "reader.js", + "sources": [ + "node_modules/rsvp/dist/config/versionTemplate.txt", + "node_modules/rsvp/dist/lib/rsvp/events.js", + "node_modules/rsvp/dist/lib/rsvp/config.js", + "node_modules/rsvp/dist/lib/rsvp/utils.js", + "node_modules/rsvp/dist/lib/rsvp/instrument.js", + "node_modules/rsvp/dist/lib/rsvp/promise/resolve.js", + "node_modules/rsvp/dist/lib/rsvp/-internal.js", + "node_modules/rsvp/dist/lib/rsvp/then.js", + "node_modules/rsvp/dist/lib/rsvp/enumerator.js", + "node_modules/rsvp/dist/lib/rsvp/promise/all.js", + "node_modules/rsvp/dist/lib/rsvp/promise/race.js", + "node_modules/rsvp/dist/lib/rsvp/promise/reject.js", + "node_modules/rsvp/dist/lib/rsvp/promise.js", + "node_modules/rsvp/dist/lib/rsvp/node.js", + "node_modules/rsvp/dist/lib/rsvp/all.js", + "node_modules/rsvp/dist/lib/rsvp/all-settled.js", + "node_modules/rsvp/dist/lib/rsvp/race.js", + "node_modules/rsvp/dist/lib/rsvp/promise-hash.js", + "node_modules/rsvp/dist/lib/rsvp/hash.js", + "node_modules/rsvp/dist/lib/rsvp/hash-settled.js", + "node_modules/rsvp/dist/lib/rsvp/rethrow.js", + "node_modules/rsvp/dist/lib/rsvp/defer.js", + "node_modules/rsvp/dist/lib/rsvp/map.js", + "node_modules/rsvp/dist/lib/rsvp/resolve.js", + "node_modules/rsvp/dist/lib/rsvp/reject.js", + "node_modules/rsvp/dist/lib/rsvp/filter.js", + "node_modules/rsvp/dist/lib/rsvp/asap.js", + "node_modules/rsvp/dist/lib/rsvp/platform.js", + "node_modules/rsvp/dist/lib/rsvp.js", + "src/core.js", + "src/reader.js", + "src/controllers/bookmarks_controller.js", + "src/controllers/controls_controller.js", + "src/controllers/meta_controller.js", + "src/controllers/notes_controller.js", + "src/controllers/reader_controller.js", + "src/controllers/settings_controller.js", + "src/controllers/sidebar_controller.js", + "src/controllers/toc_controller.js" + ], + "names": [], + "mappings": "AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACNA;AAAsC;AACc;AACjB;AACpB;AACV;AACF;AAAA;AAES;AACX;AAED;AAA8B;AACa;AAAA;AAEzB;AAC4B;AAC3C;AAAA;AAEgB;AAClB;AAAA;AAAA;AAAA;AAKD;AAAe;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCY;AACG;AACE;AACQ;AACC;AACvB;AACf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBkC;AACG;AACiB;AACpD;AAAA;AAEoC;AACd;AAAA;AAEa;AAAA;AAEpB;AAC2B;AAC1C;AAAA;AAEwC;AACd;AAC1B;AACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCmC;AACG;AACf;AACH;AAAA;AAEJ;AACgB;AACtB;AACR;AAAA;AAEmC;AAAA;AAEC;AAAA;AAEnB;AACW;AAC5B;AACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4B6C;AACP;AACf;AACA;AAAA;AAEmB;AAAA;AAEI;AACjB;AAAA;AAEC;AAC1B;AACF;AACF;AACF;AC1LD;AAAa;AACM;AACjB;AAEF;AAA6B;AAE7B;AAAgC;AACF;AACL;AAChB;AACe;AACrB;AAGH;AChBO;AAA6B;AACd;AAC4C;AACjE;AAED;AAA8B;AACG;AAChC;AAEM;AAAqB;AACiB;AAC5C;AAED;AAAmC;AACU;AAC5C;AAED;AACA;AAAmB;AACQ;AACpB;AACmB;AACwC;AAC9D;AACH;AAED;AAA8B;AAAA;AAAA;AAI9B;AAAyC;AACX;AAC7B;AC7BD;AAAe;AAEf;AAAyB;AACA;AACkB;AAChB;AAAA;AAEO;AAAA;AAEY;AACU;AAC/B;AACmB;AACrC;AAAA;AAE4C;AAC9C;AACgB;AACZ;AACR;AAED;AAA8D;AACvC;AACJ;AACN;AACc;AACN;AACK;AACG;AACI;AACN;AACL;AACyD;AACrE;AACU;AACjB;AAAA;ACpCH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgCA;AAA+C;AAAA;AAEtB;AAAA;AAEyD;AAChE;AACf;AAAA;AAE0C;AACjB;AACX;AAAA;ACpCjB;AAA0B;AACqD;AAC9E;AAEM;AAAkB;AAEzB;AACA;AACO;AAAiB;AAExB;AAAuC;AAEvC;AAAiC;AAC3B;AACkB;AACN;AACe;AACP;AACvB;AACF;AAED;AAAoE;AAC9D;AACqD;AAC7C;AACD;AACV;AACF;AAED;AAAwD;AACtB;AACX;AACkC;AACvC;AACH;AACR;AACa;AACU;AACa;AAC9B;AACmB;AACzB;AACkB;AACP;AACH;AACR;AACa;AAAA;AAEU;AAC8B;AAAA;AAElC;AACN;AACS;AACxB;AACS;AACb;AAED;AAA8C;AACT;AACE;AACI;AACd;AACS;AAC7B;AAC2C;AACtB;AACa;AAC9B;AACmB;AACzB;AACkB;AACY;AAC9B;AACJ;AACF;AAED;AAAkE;AACkF;AAAA;AAE/H;AACyB;AACR;AACI;AACV;AACD;AACyB;AAC/C;AAC2B;AACjC;AACF;AAED;AAAwC;AACf;AACG;AACU;AACkB;AAC/C;AACmB;AACzB;AACF;AAEM;AAAmC;AAClB;AACc;AACnC;AAAA;AAEgB;AAClB;AAED;AAAwC;AACN;AACvB;AACR;AAAA;AAEuB;AACG;AAAA;AAEY;AACd;AACY;AAClC;AACI;AAC0B;AAChC;AACF;AAEM;AAAiC;AACN;AACvB;AACR;AACyB;AACD;AACe;AACzC;AAED;AAAqE;AAC7B;AACN;AAAA;AAET;AAAA;AAEK;AACoB;AACH;AAAA;AAEV;AACH;AAC/B;AACF;AAED;AAAiC;AACQ;AACV;AAAA;AAEN;AACiD;AACvE;AAAA;AAE6B;AACrB;AACR;AAAA;AAEiB;AACG;AACQ;AAAA;AAEmB;AACvB;AACa;AAAA;AAEzB;AACwC;AAC5C;AACY;AAClB;AACF;AAAA;AAE+B;AACjC;AAED;AAAuB;AACH;AACnB;AAED;AAAwC;AAExC;AAAoC;AAC9B;AACsB;AACd;AACgB;AACH;AACxB;AACF;AAED;AAAiE;AACxB;AACrB;AACC;AAAA;AAEF;AACoB;AAAA;AAEJ;AACT;AACD;AACS;AACM;AAC3B;AACR;AACI;AACU;AAChB;AAAA;AAE+B;AAAA;AAEe;AACrB;AACM;AACP;AACO;AACN;AACK;AACN;AACxB;AACF;AAEM;AAA8C;AAC9B;AACjB;AACwB;AACV;AACL;AACR;AACe;AACQ;AACL;AACL;AACL;AACR;AACe;AACQ;AACvB;AACO;AACS;AACpB;AAAA;AC1PY;AAAiD;AAC5C;AACQ;AAAA;AAEuD;AACpB;AAC7C;AACf;AAAA;AAEsB;AAAA;AAEyB;AACpB;AAAA;AAE8B;AAAA;AAEnC;AACgC;AAChD;AAC4D;AACxC;AAC+B;AACrD;AACJ;AAAA;AAEY;AAAA;ACnBf;AAA6B;AACmC;AACpB;AACI;AACR;AAAA;AAEF;AACnC;AAAA;AAE+D;AAClC;AACV;AACI;AACQ;AAAA;AAEP;AACI;AACW;AACrC;AACD;AAAA;AAE2D;AAClC;AACE;AAAA;AAEoC;AAChC;AAC9B;AACD;AAAA;AAEkF;AAChD;AACV;AAAA;AAES;AACL;AAAA;AAE6B;AAC/B;AAC0B;AACX;AACnB;AACsC;AAChC;AACE;AACgB;AACX;AAC1B;AACuC;AACpB;AACjB;AACR;AACI;AACiC;AACvC;AACD;AAAA;AAE8D;AAClC;AACU;AAC/B;AACa;AACsC;AACzD;AACD;AAAA;AAEqE;AAC1C;AAAA;AAEK;AACiB;AACtB;AAClB;AACa;AACkC;AACzB;AACM;AAChC;AACF;AACF;AACD;AAAA;AAEuE;AAC1D;AACb;AAAA;AAEsE;AAChD;AAAA;AAEyB;AACK;AAC/B;AAC+B;AACjD;AACH;AAAA;AAEgB;AAChB;AAKJ;AAA0D;AAC/B;AAChB;AACa;AACN;AACZ;AACG;AACE;AACY;AACJ;AACb;AACH;AAAA;ACxHH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+Ce;AAA6B;AACnB;AACgE;AACtF;AAC+E;AAAA;AClDlF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkEe;AAA8B;AAAA;AAEpB;AAAA;AAEoB;AAAA;AAEpB;AACuD;AAC7D;AAChB;AAAA;AAEsE;AACE;AACtC;AACZ;AACY;AAC9B;AACJ;AAAA;AAEc;AAAA;ACvFjB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAmCA;AAA8C;AAAA;AAErB;AACoB;AAClB;AACV;AAAA;AC5BjB;AACA;AAAgB;AAEhB;AAAyB;AACmF;AAC3G;AAED;AAAoB;AAC2H;AAC9I;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA2GD;AAA0B;AACU;AACX;AACD;AACI;AACC;AACF;AAAA;AAE0B;AAAA;AAE1B;AAC6B;AACuB;AAC1E;AACF;AAAA;AAEsD;AACpC;AAAA;AAEQ;AACH;AAC4B;AAC/C;AACA;AACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgC4D;AACZ;AAChD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA4C6D;AAC1C;AACmB;AAAA;AAED;AACqB;AACzC;AACZ;AACgB;AACqC;AACzC;AACZ;AACK;AACV;AAAA;AAEa;AACb;AAEH;AAAA;AAED;AACA;AACA;AACA;AACA;AAAwB;AAExB;AAAqC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAoMrC;AAEA;ACpcA;AAAkB;AACO;AACxB;AAED;AACA;AAAkC;AAElC;AAAsB;AAChB;AACc;AACF;AACM;AACP;AACd;AACF;AAED;AAA2B;AACrB;AACY;AACA;AACM;AACP;AACd;AACF;AAED;AAAsC;AACvB;AACS;AACO;AAAA;AAEI;AAChB;AAChB;AAAA;AAE8C;AACjB;AACJ;AACzB;AAAA;AAEU;AACZ;AAED;AAAwB;AACA;AACW;AAAA;AAEA;AACZ;AACpB;AAAA;AAEW;AACb;AAED;AAAqC;AAC5B;AACuC;AACY;AACvD;AACD;AACH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAkIc;AAAsC;AAC9B;AACH;AACS;AACG;AACH;AAAA;AAEG;AACH;AAAA;AAEJ;AAAA;AAEqB;AACD;AACT;AACM;AACvB;AACuC;AACV;AACvC;AACF;AACa;AACf;AAAA;AAE+B;AAAA;AAEF;AACmO;AAC/P;AAAA;AAEgB;AACyC;AACpD;AACkD;AACxD;AACD;AAAA;AAEsB;AAAA;AAEd;AACX;AAED;AAAyD;AACX;AACtB;AACU;AAC/B;AACc;AAChB;AAED;AAA2D;AACX;AACA;AACtB;AACU;AAC/B;AACc;AACd;AACJ;AAED;AAAgC;AACM;AACD;AACnB;AACP;AACe;AACrB;AACI;AACQ;AACd;AAAA;ACpQH;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA;AAA0C;AACP;AAAA;ACXnC;AAAgP;AAEhP;AAA8e;AAI9e;AAEwC;AACH;AAAA;AAEc;AACiF;AACjI;AAAA;AAEiB;AACN;AAEd;AAAqD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA+CtC;AAAoC;AAC1B;AAC0E;AAChG;AAAA;AAEsD;AAAA;ACtEzD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAUe;AAA4B;AACP;AAAA;ACXpC;AAAgP;AAEhP;AAA8e;AAG9e;AAEqD;AAErD;AAAyC;AACH;AAAA;AAEM;AACqD;AACpE;AACkF;AAC5G;AAAA;AAEiE;AAC9C;AAAA;AAEM;AACG;AACW;AACrC;AACD;AAAA;AAE4D;AACjC;AACV;AAAA;AAEM;AACgB;AACtB;AACE;AACI;AAChB;AACJ;AACF;AAAA;AAE2B;AACH;AACL;AAAA;AAE2C;AACzC;AAC2B;AAChD;AACD;AAAA;AAEiB;AAGrB;ACnDA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwFA;AAA4C;AACnB;AACqE;AAC3F;AAAA;AAEsD;AAAA;AC/FzD;AAAgP;AAEhP;AAA8e;AAO9e;AAA0C;AACH;AAAA;AAEY;AACqD;AACrG;AAAA;AAEkB;AACN;AAEf;AAAsD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwGtD;AAAmD;AAC1B;AACyE;AAC/F;AAAA;AAE6D;AAAA;AClIhE;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAwCe;AAAyB;AACf;AACR;AACZ;AACU;AAAA;AC1Cf;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiCA;AAAqC;AACsB;AAAA;AAEC;AAC7B;AACF;AACjB;AAAA;AAEM;AAAA;ACvClB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA8EA;AAAoD;AAC1B;AAC+D;AACtF;AAAA;AAEuB;AAC0E;AACjG;AAAA;AAE0D;AAC9B;AACK;AAAA;AAEC;AACD;AAC/B;AAAA;AAEkC;AAClC;AAAA;AClGL;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYA;AAA8C;AACP;AAAA;ACbvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWe;AAA+B;AACP;AAAA;ACXvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAsFA;AAAqC;AACC;AACrC;AAED;AAAuC;AAC2B;AAC3B;AAClC;AACJ;AAED;AAA0D;AACwB;AACqB;AACpG;AAAA;AAE0B;AACwE;AAClG;AAAA;AAE8F;AACzD;AACT;AACM;AAAA;AAEA;AACG;AACnC;AAAA;AAE2D;AAC1B;AACd;AAAA;AAEkB;AAChB;AACgB;AACpB;AACb;AACF;AAAA;AAE0B;AAAA;AAEZ;AACd;AACF;AAAA;ACpIL;AACA;AACe;AAA6B;AACpB;AACD;AACZ;AACM;AAAA;AAAA;AAAA;AAIG;AACjB;AACF;AAED;AACA;AACA;AACA;AAA+H;AAAA;AAG/H;AAAyI;AAAA;AAGzI;AAAuB;AACW;AAAA;AAAA;AAGgD;AACP;AAC/C;AACzB;AACkB;AACM;AACvB;AACH;AAAA;AAGD;AAAyB;AACe;AACjB;AACA;AACjB;AACH;AACsB;AACxB;AAED;AAA+B;AACV;AAC+B;AACX;AACS;AAAA;AAE7B;AACgC;AACjD;AACH;AAAA;AAGD;AAA6B;AACQ;AACH;AACb;AACmB;AACpC;AACH;AAED;AAAyB;AACJ;AACW;AAC5B;AACH;AAED;AAA4B;AAE5B;AAAiB;AACkB;AACP;AACD;AAAA;AAET;AAAA;AAEO;AACI;AAC1B;AAAA;AAEO;AACT;AAED;AAAyB;AACnB;AACc;AACO;AAC2B;AAC3B;AACb;AACa;AACxB;AACF;AAED;AAA2B;AAE3B;AAAY;AACoB;AACI;AACI;AACnB;AACiB;AACmC;AACvC;AAC3B;AAC2B;AAAA;AC9GlC;AAAsB;AAAA;AAGtB;AAA8B;AACZ;AAAA;AAAA;AAGqB;AACnB;AACb;AACkD;AAGzD;ACbA;AAA0B;AAE1B;AAAiN;AASjN;AAWA;AACA;AAA6B;AACF;AAE3B;AAAmB;AAEnB;AAAqC;AACA;AACnC;AAEF;AAAc;AAC0B;AACvC;AAED;AAAe;AAC0B;AACxC;AAAA;AAGD;AAAgG;AACxC;AACxB;AACG;AACU;AACH;AACrC;AACF;AACF;AAED;AACA;AAEA;AAAwC;AAC5B;AACA;AACM;AACQ;AAChB;AACc;AACZ;AACA;AACc;AACR;AACJ;AACQ;AACA;AACd;AACE;AACQ;AACF;AACN;AAGV;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;A;AC3EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A;AC9oBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A;AClUA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A;AC1EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A;AC/GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A;ACbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A;AC/RA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A;ACtJA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,E;AChCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,E;ACjDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A", + "sourceRoot": "../", + "sourcesContent": [ + "/*!\n * @overview RSVP - a tiny implementation of Promises/A+.\n * @copyright Copyright (c) 2016 Yehuda Katz, Tom Dale, Stefan Penner and contributors\n * @license Licensed under MIT license\n * See https://raw.githubusercontent.com/tildeio/rsvp.js/master/LICENSE\n * @version 3.6.2\n */\n", + "function indexOf(callbacks, callback) {\n for (var i = 0, l = callbacks.length; i < l; i++) {\n if (callbacks[i] === callback) {\n return i;\n }\n }\n\n return -1;\n}\n\nfunction callbacksFor(object) {\n var callbacks = object._promiseCallbacks;\n\n if (!callbacks) {\n callbacks = object._promiseCallbacks = {};\n }\n\n return callbacks;\n}\n\n/**\n @class RSVP.EventTarget\n*/\nexport default {\n\n /**\n `RSVP.EventTarget.mixin` extends an object with EventTarget methods. For\n Example:\n ```javascript\n let object = {};\n RSVP.EventTarget.mixin(object);\n object.on('finished', function(event) {\n // handle event\n });\n object.trigger('finished', { detail: value });\n ```\n `EventTarget.mixin` also works with prototypes:\n ```javascript\n let Person = function() {};\n RSVP.EventTarget.mixin(Person.prototype);\n let yehuda = new Person();\n let tom = new Person();\n yehuda.on('poke', function(event) {\n console.log('Yehuda says OW');\n });\n tom.on('poke', function(event) {\n console.log('Tom says OW');\n });\n yehuda.trigger('poke');\n tom.trigger('poke');\n ```\n @method mixin\n @for RSVP.EventTarget\n @private\n @param {Object} object object to extend with EventTarget methods\n */\n mixin: function (object) {\n object['on'] = this['on'];\n object['off'] = this['off'];\n object['trigger'] = this['trigger'];\n object._promiseCallbacks = undefined;\n return object;\n },\n\n\n /**\n Registers a callback to be executed when `eventName` is triggered\n ```javascript\n object.on('event', function(eventInfo){\n // handle the event\n });\n object.trigger('event');\n ```\n @method on\n @for RSVP.EventTarget\n @private\n @param {String} eventName name of the event to listen for\n @param {Function} callback function to be called when the event is triggered.\n */\n on: function (eventName, callback) {\n if (typeof callback !== 'function') {\n throw new TypeError('Callback must be a function');\n }\n\n var allCallbacks = callbacksFor(this),\n callbacks = void 0;\n\n callbacks = allCallbacks[eventName];\n\n if (!callbacks) {\n callbacks = allCallbacks[eventName] = [];\n }\n\n if (indexOf(callbacks, callback) === -1) {\n callbacks.push(callback);\n }\n },\n\n\n /**\n You can use `off` to stop firing a particular callback for an event:\n ```javascript\n function doStuff() { // do stuff! }\n object.on('stuff', doStuff);\n object.trigger('stuff'); // doStuff will be called\n // Unregister ONLY the doStuff callback\n object.off('stuff', doStuff);\n object.trigger('stuff'); // doStuff will NOT be called\n ```\n If you don't pass a `callback` argument to `off`, ALL callbacks for the\n event will not be executed when the event fires. For example:\n ```javascript\n let callback1 = function(){};\n let callback2 = function(){};\n object.on('stuff', callback1);\n object.on('stuff', callback2);\n object.trigger('stuff'); // callback1 and callback2 will be executed.\n object.off('stuff');\n object.trigger('stuff'); // callback1 and callback2 will not be executed!\n ```\n @method off\n @for RSVP.EventTarget\n @private\n @param {String} eventName event to stop listening to\n @param {Function} callback optional argument. If given, only the function\n given will be removed from the event's callback queue. If no `callback`\n argument is given, all callbacks will be removed from the event's callback\n queue.\n */\n off: function (eventName, callback) {\n var allCallbacks = callbacksFor(this),\n callbacks = void 0,\n index = void 0;\n\n if (!callback) {\n allCallbacks[eventName] = [];\n return;\n }\n\n callbacks = allCallbacks[eventName];\n\n index = indexOf(callbacks, callback);\n\n if (index !== -1) {\n callbacks.splice(index, 1);\n }\n },\n\n\n /**\n Use `trigger` to fire custom events. For example:\n ```javascript\n object.on('foo', function(){\n console.log('foo event happened!');\n });\n object.trigger('foo');\n // 'foo event happened!' logged to the console\n ```\n You can also pass a value as a second argument to `trigger` that will be\n passed as an argument to all event listeners for the event:\n ```javascript\n object.on('foo', function(value){\n console.log(value.name);\n });\n object.trigger('foo', { name: 'bar' });\n // 'bar' logged to the console\n ```\n @method trigger\n @for RSVP.EventTarget\n @private\n @param {String} eventName name of the event to be triggered\n @param {*} options optional value to be passed to any event handlers for\n the given `eventName`\n */\n trigger: function (eventName, options, label) {\n var allCallbacks = callbacksFor(this),\n callbacks = void 0,\n callback = void 0;\n\n if (callbacks = allCallbacks[eventName]) {\n // Don't cache the callbacks.length since it may grow\n for (var i = 0; i < callbacks.length; i++) {\n callback = callbacks[i];\n\n callback(options, label);\n }\n }\n }\n};", + "import EventTarget from './events';\n\nvar config = {\n instrument: false\n};\n\nEventTarget['mixin'](config);\n\nfunction configure(name, value) {\n if (arguments.length === 2) {\n config[name] = value;\n } else {\n return config[name];\n }\n}\n\nexport { config, configure };", + "export function objectOrFunction(x) {\n var type = typeof x;\n return x !== null && (type === 'object' || type === 'function');\n}\n\nexport function isFunction(x) {\n return typeof x === 'function';\n}\n\nexport function isObject(x) {\n return x !== null && typeof x === 'object';\n}\n\nexport function isMaybeThenable(x) {\n return x !== null && typeof x === 'object';\n}\n\nvar _isArray = void 0;\nif (Array.isArray) {\n _isArray = Array.isArray;\n} else {\n _isArray = function (x) {\n return Object.prototype.toString.call(x) === '[object Array]';\n };\n}\n\nexport var isArray = _isArray;\n\n// Date.now is not available in browsers < IE9\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#Compatibility\nexport var now = Date.now || function () {\n return new Date().getTime();\n};", + "import { config } from './config';\nimport { now } from './utils';\n\nvar queue = [];\n\nfunction scheduleFlush() {\n setTimeout(function () {\n for (var i = 0; i < queue.length; i++) {\n var entry = queue[i];\n\n var payload = entry.payload;\n\n payload.guid = payload.key + payload.id;\n payload.childGuid = payload.key + payload.childId;\n if (payload.error) {\n payload.stack = payload.error.stack;\n }\n\n config['trigger'](entry.name, entry.payload);\n }\n queue.length = 0;\n }, 50);\n}\n\nexport default function instrument(eventName, promise, child) {\n if (1 === queue.push({\n name: eventName,\n payload: {\n key: promise._guidKey,\n id: promise._id,\n eventName: eventName,\n detail: promise._result,\n childId: child && child._id,\n label: promise._label,\n timeStamp: now(),\n error: config[\"instrument-with-stack\"] ? new Error(promise._label) : null\n } })) {\n scheduleFlush();\n }\n}", + "import { noop, resolve as _resolve } from '../-internal';\n\n/**\n `RSVP.Promise.resolve` returns a promise that will become resolved with the\n passed `value`. It is shorthand for the following:\n\n ```javascript\n let promise = new RSVP.Promise(function(resolve, reject){\n resolve(1);\n });\n\n promise.then(function(value){\n // value === 1\n });\n ```\n\n Instead of writing the above, your code now simply becomes the following:\n\n ```javascript\n let promise = RSVP.Promise.resolve(1);\n\n promise.then(function(value){\n // value === 1\n });\n ```\n\n @method resolve\n @static\n @param {*} object value that the returned promise will be resolved with\n @param {String} label optional string for identifying the returned promise.\n Useful for tooling.\n @return {Promise} a promise that will become fulfilled with the given\n `value`\n*/\nexport default function resolve(object, label) {\n /*jshint validthis:true */\n var Constructor = this;\n\n if (object && typeof object === 'object' && object.constructor === Constructor) {\n return object;\n }\n\n var promise = new Constructor(noop, label);\n _resolve(promise, object);\n return promise;\n}", + "import { objectOrFunction, isFunction } from './utils';\nimport originalThen from './then';\nimport originalResolve from './promise/resolve';\nimport instrument from './instrument';\n\nimport { config } from './config';\nimport Promise from './promise';\n\nfunction withOwnPromise() {\n return new TypeError('A promises callback cannot return that same promise.');\n}\n\nexport function noop() {}\n\nexport var PENDING = void 0;\nexport var FULFILLED = 1;\nexport var REJECTED = 2;\n\nvar GET_THEN_ERROR = new ErrorObject();\n\nexport function getThen(promise) {\n try {\n return promise.then;\n } catch (error) {\n GET_THEN_ERROR.error = error;\n return GET_THEN_ERROR;\n }\n}\n\nfunction tryThen(then, value, fulfillmentHandler, rejectionHandler) {\n try {\n then.call(value, fulfillmentHandler, rejectionHandler);\n } catch (e) {\n return e;\n }\n}\n\nfunction handleForeignThenable(promise, thenable, then) {\n config.async(function (promise) {\n var sealed = false;\n var error = tryThen(then, thenable, function (value) {\n if (sealed) {\n return;\n }\n sealed = true;\n if (thenable !== value) {\n resolve(promise, value, undefined);\n } else {\n fulfill(promise, value);\n }\n }, function (reason) {\n if (sealed) {\n return;\n }\n sealed = true;\n\n reject(promise, reason);\n }, 'Settle: ' + (promise._label || ' unknown promise'));\n\n if (!sealed && error) {\n sealed = true;\n reject(promise, error);\n }\n }, promise);\n}\n\nfunction handleOwnThenable(promise, thenable) {\n if (thenable._state === FULFILLED) {\n fulfill(promise, thenable._result);\n } else if (thenable._state === REJECTED) {\n thenable._onError = null;\n reject(promise, thenable._result);\n } else {\n subscribe(thenable, undefined, function (value) {\n if (thenable !== value) {\n resolve(promise, value, undefined);\n } else {\n fulfill(promise, value);\n }\n }, function (reason) {\n return reject(promise, reason);\n });\n }\n}\n\nexport function handleMaybeThenable(promise, maybeThenable, then) {\n var isOwnThenable = maybeThenable.constructor === promise.constructor && then === originalThen && promise.constructor.resolve === originalResolve;\n\n if (isOwnThenable) {\n handleOwnThenable(promise, maybeThenable);\n } else if (then === GET_THEN_ERROR) {\n reject(promise, GET_THEN_ERROR.error);\n GET_THEN_ERROR.error = null;\n } else if (isFunction(then)) {\n handleForeignThenable(promise, maybeThenable, then);\n } else {\n fulfill(promise, maybeThenable);\n }\n}\n\nexport function resolve(promise, value) {\n if (promise === value) {\n fulfill(promise, value);\n } else if (objectOrFunction(value)) {\n handleMaybeThenable(promise, value, getThen(value));\n } else {\n fulfill(promise, value);\n }\n}\n\nexport function publishRejection(promise) {\n if (promise._onError) {\n promise._onError(promise._result);\n }\n\n publish(promise);\n}\n\nexport function fulfill(promise, value) {\n if (promise._state !== PENDING) {\n return;\n }\n\n promise._result = value;\n promise._state = FULFILLED;\n\n if (promise._subscribers.length === 0) {\n if (config.instrument) {\n instrument('fulfilled', promise);\n }\n } else {\n config.async(publish, promise);\n }\n}\n\nexport function reject(promise, reason) {\n if (promise._state !== PENDING) {\n return;\n }\n promise._state = REJECTED;\n promise._result = reason;\n config.async(publishRejection, promise);\n}\n\nexport function subscribe(parent, child, onFulfillment, onRejection) {\n var subscribers = parent._subscribers;\n var length = subscribers.length;\n\n parent._onError = null;\n\n subscribers[length] = child;\n subscribers[length + FULFILLED] = onFulfillment;\n subscribers[length + REJECTED] = onRejection;\n\n if (length === 0 && parent._state) {\n config.async(publish, parent);\n }\n}\n\nexport function publish(promise) {\n var subscribers = promise._subscribers;\n var settled = promise._state;\n\n if (config.instrument) {\n instrument(settled === FULFILLED ? 'fulfilled' : 'rejected', promise);\n }\n\n if (subscribers.length === 0) {\n return;\n }\n\n var child = void 0,\n callback = void 0,\n result = promise._result;\n\n for (var i = 0; i < subscribers.length; i += 3) {\n child = subscribers[i];\n callback = subscribers[i + settled];\n\n if (child) {\n invokeCallback(settled, child, callback, result);\n } else {\n callback(result);\n }\n }\n\n promise._subscribers.length = 0;\n}\n\nfunction ErrorObject() {\n this.error = null;\n}\n\nvar TRY_CATCH_ERROR = new ErrorObject();\n\nfunction tryCatch(callback, result) {\n try {\n return callback(result);\n } catch (e) {\n TRY_CATCH_ERROR.error = e;\n return TRY_CATCH_ERROR;\n }\n}\n\nexport function invokeCallback(state, promise, callback, result) {\n var hasCallback = isFunction(callback);\n var value = void 0,\n error = void 0;\n\n if (hasCallback) {\n value = tryCatch(callback, result);\n\n if (value === TRY_CATCH_ERROR) {\n error = value.error;\n value.error = null; // release\n } else if (value === promise) {\n reject(promise, withOwnPromise());\n return;\n }\n } else {\n value = result;\n }\n\n if (promise._state !== PENDING) {\n // noop\n } else if (hasCallback && error === undefined) {\n resolve(promise, value);\n } else if (error !== undefined) {\n reject(promise, error);\n } else if (state === FULFILLED) {\n fulfill(promise, value);\n } else if (state === REJECTED) {\n reject(promise, value);\n }\n}\n\nexport function initializePromise(promise, resolver) {\n var resolved = false;\n try {\n resolver(function (value) {\n if (resolved) {\n return;\n }\n resolved = true;\n resolve(promise, value);\n }, function (reason) {\n if (resolved) {\n return;\n }\n resolved = true;\n reject(promise, reason);\n });\n } catch (e) {\n reject(promise, e);\n }\n}", + "import { config } from './config';\nimport instrument from './instrument';\nimport { noop, subscribe, FULFILLED, REJECTED, PENDING, invokeCallback } from './-internal';\n\nexport default function then(onFulfillment, onRejection, label) {\n var parent = this;\n var state = parent._state;\n\n if (state === FULFILLED && !onFulfillment || state === REJECTED && !onRejection) {\n config.instrument && instrument('chained', parent, parent);\n return parent;\n }\n\n parent._onError = null;\n\n var child = new parent.constructor(noop, label);\n var result = parent._result;\n\n config.instrument && instrument('chained', parent, child);\n\n if (state === PENDING) {\n subscribe(parent, child, onFulfillment, onRejection);\n } else {\n var callback = state === FULFILLED ? onFulfillment : onRejection;\n config.async(function () {\n return invokeCallback(state, child, callback, result);\n });\n }\n\n return child;\n}", + "function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nimport { isArray, isMaybeThenable } from './utils';\n\nimport { noop, resolve, handleMaybeThenable, reject, fulfill, subscribe, FULFILLED, REJECTED, PENDING, getThen } from './-internal';\n\nimport Promise from './promise';\nimport originalThen from './then';\nimport originalResolve from './promise/resolve';\n\nvar Enumerator = function () {\n function Enumerator(Constructor, input, abortOnReject, label) {\n this._instanceConstructor = Constructor;\n this.promise = new Constructor(noop, label);\n this._abortOnReject = abortOnReject;\n\n this._init.apply(this, arguments);\n }\n\n Enumerator.prototype._init = function _init(Constructor, input) {\n var len = input.length || 0;\n this.length = len;\n this._remaining = len;\n this._result = new Array(len);\n\n this._enumerate(input);\n if (this._remaining === 0) {\n fulfill(this.promise, this._result);\n }\n };\n\n Enumerator.prototype._enumerate = function _enumerate(input) {\n var length = this.length;\n var promise = this.promise;\n\n for (var i = 0; promise._state === PENDING && i < length; i++) {\n this._eachEntry(input[i], i);\n }\n };\n\n Enumerator.prototype._settleMaybeThenable = function _settleMaybeThenable(entry, i) {\n var c = this._instanceConstructor;\n var resolve = c.resolve;\n\n if (resolve === originalResolve) {\n var then = getThen(entry);\n\n if (then === originalThen && entry._state !== PENDING) {\n entry._onError = null;\n this._settledAt(entry._state, i, entry._result);\n } else if (typeof then !== 'function') {\n this._remaining--;\n this._result[i] = this._makeResult(FULFILLED, i, entry);\n } else if (c === Promise) {\n var promise = new c(noop);\n handleMaybeThenable(promise, entry, then);\n this._willSettleAt(promise, i);\n } else {\n this._willSettleAt(new c(function (resolve) {\n return resolve(entry);\n }), i);\n }\n } else {\n this._willSettleAt(resolve(entry), i);\n }\n };\n\n Enumerator.prototype._eachEntry = function _eachEntry(entry, i) {\n if (isMaybeThenable(entry)) {\n this._settleMaybeThenable(entry, i);\n } else {\n this._remaining--;\n this._result[i] = this._makeResult(FULFILLED, i, entry);\n }\n };\n\n Enumerator.prototype._settledAt = function _settledAt(state, i, value) {\n var promise = this.promise;\n\n if (promise._state === PENDING) {\n if (this._abortOnReject && state === REJECTED) {\n reject(promise, value);\n } else {\n this._remaining--;\n this._result[i] = this._makeResult(state, i, value);\n if (this._remaining === 0) {\n fulfill(promise, this._result);\n }\n }\n }\n };\n\n Enumerator.prototype._makeResult = function _makeResult(state, i, value) {\n return value;\n };\n\n Enumerator.prototype._willSettleAt = function _willSettleAt(promise, i) {\n var enumerator = this;\n\n subscribe(promise, undefined, function (value) {\n return enumerator._settledAt(FULFILLED, i, value);\n }, function (reason) {\n return enumerator._settledAt(REJECTED, i, reason);\n });\n };\n\n return Enumerator;\n}();\n\nexport default Enumerator;\n\n\nexport function makeSettledResult(state, position, value) {\n if (state === FULFILLED) {\n return {\n state: 'fulfilled',\n value: value\n };\n } else {\n return {\n state: 'rejected',\n reason: value\n };\n }\n}", + "import Enumerator from '../enumerator';\nimport { isArray } from '../utils';\n\n/**\n `RSVP.Promise.all` accepts an array of promises, and returns a new promise which\n is fulfilled with an array of fulfillment values for the passed promises, or\n rejected with the reason of the first passed promise to be rejected. It casts all\n elements of the passed iterable to promises as it runs this algorithm.\n\n Example:\n\n ```javascript\n let promise1 = RSVP.resolve(1);\n let promise2 = RSVP.resolve(2);\n let promise3 = RSVP.resolve(3);\n let promises = [ promise1, promise2, promise3 ];\n\n RSVP.Promise.all(promises).then(function(array){\n // The array here would be [ 1, 2, 3 ];\n });\n ```\n\n If any of the `promises` given to `RSVP.all` are rejected, the first promise\n that is rejected will be given as an argument to the returned promises's\n rejection handler. For example:\n\n Example:\n\n ```javascript\n let promise1 = RSVP.resolve(1);\n let promise2 = RSVP.reject(new Error(\"2\"));\n let promise3 = RSVP.reject(new Error(\"3\"));\n let promises = [ promise1, promise2, promise3 ];\n\n RSVP.Promise.all(promises).then(function(array){\n // Code here never runs because there are rejected promises!\n }, function(error) {\n // error.message === \"2\"\n });\n ```\n\n @method all\n @static\n @param {Array} entries array of promises\n @param {String} label optional string for labeling the promise.\n Useful for tooling.\n @return {Promise} promise that is fulfilled when all `promises` have been\n fulfilled, or rejected if any of them become rejected.\n @static\n*/\nexport default function all(entries, label) {\n if (!isArray(entries)) {\n return this.reject(new TypeError(\"Promise.all must be called with an array\"), label);\n }\n return new Enumerator(this, entries, true /* abort on reject */, label).promise;\n}", + "import { isArray } from \"../utils\";\n\nimport { noop, resolve, reject, subscribe, PENDING } from '../-internal';\n\n/**\n `RSVP.Promise.race` returns a new promise which is settled in the same way as the\n first passed promise to settle.\n\n Example:\n\n ```javascript\n let promise1 = new RSVP.Promise(function(resolve, reject){\n setTimeout(function(){\n resolve('promise 1');\n }, 200);\n });\n\n let promise2 = new RSVP.Promise(function(resolve, reject){\n setTimeout(function(){\n resolve('promise 2');\n }, 100);\n });\n\n RSVP.Promise.race([promise1, promise2]).then(function(result){\n // result === 'promise 2' because it was resolved before promise1\n // was resolved.\n });\n ```\n\n `RSVP.Promise.race` is deterministic in that only the state of the first\n settled promise matters. For example, even if other promises given to the\n `promises` array argument are resolved, but the first settled promise has\n become rejected before the other promises became fulfilled, the returned\n promise will become rejected:\n\n ```javascript\n let promise1 = new RSVP.Promise(function(resolve, reject){\n setTimeout(function(){\n resolve('promise 1');\n }, 200);\n });\n\n let promise2 = new RSVP.Promise(function(resolve, reject){\n setTimeout(function(){\n reject(new Error('promise 2'));\n }, 100);\n });\n\n RSVP.Promise.race([promise1, promise2]).then(function(result){\n // Code here never runs\n }, function(reason){\n // reason.message === 'promise 2' because promise 2 became rejected before\n // promise 1 became fulfilled\n });\n ```\n\n An example real-world use case is implementing timeouts:\n\n ```javascript\n RSVP.Promise.race([ajax('foo.json'), timeout(5000)])\n ```\n\n @method race\n @static\n @param {Array} entries array of promises to observe\n @param {String} label optional string for describing the promise returned.\n Useful for tooling.\n @return {Promise} a promise which settles in the same way as the first passed\n promise to settle.\n*/\nexport default function race(entries, label) {\n /*jshint validthis:true */\n var Constructor = this;\n\n var promise = new Constructor(noop, label);\n\n if (!isArray(entries)) {\n reject(promise, new TypeError('Promise.race must be called with an array'));\n return promise;\n }\n\n for (var i = 0; promise._state === PENDING && i < entries.length; i++) {\n subscribe(Constructor.resolve(entries[i]), undefined, function (value) {\n return resolve(promise, value);\n }, function (reason) {\n return reject(promise, reason);\n });\n }\n\n return promise;\n}", + "import { noop, reject as _reject } from '../-internal';\n\n/**\n `RSVP.Promise.reject` returns a promise rejected with the passed `reason`.\n It is shorthand for the following:\n\n ```javascript\n let promise = new RSVP.Promise(function(resolve, reject){\n reject(new Error('WHOOPS'));\n });\n\n promise.then(function(value){\n // Code here doesn't run because the promise is rejected!\n }, function(reason){\n // reason.message === 'WHOOPS'\n });\n ```\n\n Instead of writing the above, your code now simply becomes the following:\n\n ```javascript\n let promise = RSVP.Promise.reject(new Error('WHOOPS'));\n\n promise.then(function(value){\n // Code here doesn't run because the promise is rejected!\n }, function(reason){\n // reason.message === 'WHOOPS'\n });\n ```\n\n @method reject\n @static\n @param {*} reason value that the returned promise will be rejected with.\n @param {String} label optional string for identifying the returned promise.\n Useful for tooling.\n @return {Promise} a promise rejected with the given `reason`.\n*/\nexport default function reject(reason, label) {\n /*jshint validthis:true */\n var Constructor = this;\n var promise = new Constructor(noop, label);\n _reject(promise, reason);\n return promise;\n}", + "function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nimport { config } from './config';\nimport instrument from './instrument';\nimport then from './then';\nimport { isFunction, now } from './utils';\n\nimport { noop, initializePromise } from './-internal';\n\nimport all from './promise/all';\nimport race from './promise/race';\nimport Resolve from './promise/resolve';\nimport Reject from './promise/reject';\n\nvar guidKey = 'rsvp_' + now() + '-';\nvar counter = 0;\n\nfunction needsResolver() {\n throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');\n}\n\nfunction needsNew() {\n throw new TypeError(\"Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.\");\n}\n\n/**\n Promise objects represent the eventual result of an asynchronous operation. The\n primary way of interacting with a promise is through its `then` method, which\n registers callbacks to receive either a promise’s eventual value or the reason\n why the promise cannot be fulfilled.\n\n Terminology\n -----------\n\n - `promise` is an object or function with a `then` method whose behavior conforms to this specification.\n - `thenable` is an object or function that defines a `then` method.\n - `value` is any legal JavaScript value (including undefined, a thenable, or a promise).\n - `exception` is a value that is thrown using the throw statement.\n - `reason` is a value that indicates why a promise was rejected.\n - `settled` the final resting state of a promise, fulfilled or rejected.\n\n A promise can be in one of three states: pending, fulfilled, or rejected.\n\n Promises that are fulfilled have a fulfillment value and are in the fulfilled\n state. Promises that are rejected have a rejection reason and are in the\n rejected state. A fulfillment value is never a thenable.\n\n Promises can also be said to *resolve* a value. If this value is also a\n promise, then the original promise's settled state will match the value's\n settled state. So a promise that *resolves* a promise that rejects will\n itself reject, and a promise that *resolves* a promise that fulfills will\n itself fulfill.\n\n\n Basic Usage:\n ------------\n\n ```js\n let promise = new Promise(function(resolve, reject) {\n // on success\n resolve(value);\n\n // on failure\n reject(reason);\n });\n\n promise.then(function(value) {\n // on fulfillment\n }, function(reason) {\n // on rejection\n });\n ```\n\n Advanced Usage:\n ---------------\n\n Promises shine when abstracting away asynchronous interactions such as\n `XMLHttpRequest`s.\n\n ```js\n function getJSON(url) {\n return new Promise(function(resolve, reject){\n let xhr = new XMLHttpRequest();\n\n xhr.open('GET', url);\n xhr.onreadystatechange = handler;\n xhr.responseType = 'json';\n xhr.setRequestHeader('Accept', 'application/json');\n xhr.send();\n\n function handler() {\n if (this.readyState === this.DONE) {\n if (this.status === 200) {\n resolve(this.response);\n } else {\n reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));\n }\n }\n };\n });\n }\n\n getJSON('/posts.json').then(function(json) {\n // on fulfillment\n }, function(reason) {\n // on rejection\n });\n ```\n\n Unlike callbacks, promises are great composable primitives.\n\n ```js\n Promise.all([\n getJSON('/posts'),\n getJSON('/comments')\n ]).then(function(values){\n values[0] // => postsJSON\n values[1] // => commentsJSON\n\n return values;\n });\n ```\n\n @class RSVP.Promise\n @param {function} resolver\n @param {String} label optional string for labeling the promise.\n Useful for tooling.\n @constructor\n*/\n\nvar Promise = function () {\n function Promise(resolver, label) {\n this._id = counter++;\n this._label = label;\n this._state = undefined;\n this._result = undefined;\n this._subscribers = [];\n\n config.instrument && instrument('created', this);\n\n if (noop !== resolver) {\n typeof resolver !== 'function' && needsResolver();\n this instanceof Promise ? initializePromise(this, resolver) : needsNew();\n }\n }\n\n Promise.prototype._onError = function _onError(reason) {\n var _this = this;\n\n config.after(function () {\n if (_this._onError) {\n config.trigger('error', reason, _this._label);\n }\n });\n };\n\n /**\n `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same\n as the catch block of a try/catch statement.\n \n ```js\n function findAuthor(){\n throw new Error('couldn\\'t find that author');\n }\n \n // synchronous\n try {\n findAuthor();\n } catch(reason) {\n // something went wrong\n }\n \n // async with promises\n findAuthor().catch(function(reason){\n // something went wrong\n });\n ```\n \n @method catch\n @param {Function} onRejection\n @param {String} label optional string for labeling the promise.\n Useful for tooling.\n @return {Promise}\n */\n\n\n Promise.prototype.catch = function _catch(onRejection, label) {\n return this.then(undefined, onRejection, label);\n };\n\n /**\n `finally` will be invoked regardless of the promise's fate just as native\n try/catch/finally behaves\n \n Synchronous example:\n \n ```js\n findAuthor() {\n if (Math.random() > 0.5) {\n throw new Error();\n }\n return new Author();\n }\n \n try {\n return findAuthor(); // succeed or fail\n } catch(error) {\n return findOtherAuthor();\n } finally {\n // always runs\n // doesn't affect the return value\n }\n ```\n \n Asynchronous example:\n \n ```js\n findAuthor().catch(function(reason){\n return findOtherAuthor();\n }).finally(function(){\n // author was either found, or not\n });\n ```\n \n @method finally\n @param {Function} callback\n @param {String} label optional string for labeling the promise.\n Useful for tooling.\n @return {Promise}\n */\n\n\n Promise.prototype.finally = function _finally(callback, label) {\n var promise = this;\n var constructor = promise.constructor;\n\n return promise.then(function (value) {\n return constructor.resolve(callback()).then(function () {\n return value;\n });\n }, function (reason) {\n return constructor.resolve(callback()).then(function () {\n throw reason;\n });\n }, label);\n };\n\n return Promise;\n}();\n\n;\n\nPromise.cast = Resolve; // deprecated\nPromise.all = all;\nPromise.race = race;\nPromise.resolve = Resolve;\nPromise.reject = Reject;\n\nPromise.prototype._guidKey = guidKey;\n\n/**\n The primary way of interacting with a promise is through its `then` method,\n which registers callbacks to receive either a promise's eventual value or the\n reason why the promise cannot be fulfilled.\n\n ```js\n findUser().then(function(user){\n // user is available\n }, function(reason){\n // user is unavailable, and you are given the reason why\n });\n ```\n\n Chaining\n --------\n\n The return value of `then` is itself a promise. This second, 'downstream'\n promise is resolved with the return value of the first promise's fulfillment\n or rejection handler, or rejected if the handler throws an exception.\n\n ```js\n findUser().then(function (user) {\n return user.name;\n }, function (reason) {\n return 'default name';\n }).then(function (userName) {\n // If `findUser` fulfilled, `userName` will be the user's name, otherwise it\n // will be `'default name'`\n });\n\n findUser().then(function (user) {\n throw new Error('Found user, but still unhappy');\n }, function (reason) {\n throw new Error('`findUser` rejected and we\\'re unhappy');\n }).then(function (value) {\n // never reached\n }, function (reason) {\n // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.\n // If `findUser` rejected, `reason` will be '`findUser` rejected and we\\'re unhappy'.\n });\n ```\n If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.\n\n ```js\n findUser().then(function (user) {\n throw new PedagogicalException('Upstream error');\n }).then(function (value) {\n // never reached\n }).then(function (value) {\n // never reached\n }, function (reason) {\n // The `PedgagocialException` is propagated all the way down to here\n });\n ```\n\n Assimilation\n ------------\n\n Sometimes the value you want to propagate to a downstream promise can only be\n retrieved asynchronously. This can be achieved by returning a promise in the\n fulfillment or rejection handler. The downstream promise will then be pending\n until the returned promise is settled. This is called *assimilation*.\n\n ```js\n findUser().then(function (user) {\n return findCommentsByAuthor(user);\n }).then(function (comments) {\n // The user's comments are now available\n });\n ```\n\n If the assimliated promise rejects, then the downstream promise will also reject.\n\n ```js\n findUser().then(function (user) {\n return findCommentsByAuthor(user);\n }).then(function (comments) {\n // If `findCommentsByAuthor` fulfills, we'll have the value here\n }, function (reason) {\n // If `findCommentsByAuthor` rejects, we'll have the reason here\n });\n ```\n\n Simple Example\n --------------\n\n Synchronous Example\n\n ```javascript\n let result;\n\n try {\n result = findResult();\n // success\n } catch(reason) {\n // failure\n }\n ```\n\n Errback Example\n\n ```js\n findResult(function(result, err){\n if (err) {\n // failure\n } else {\n // success\n }\n });\n ```\n\n Promise Example;\n\n ```javascript\n findResult().then(function(result){\n // success\n }, function(reason){\n // failure\n });\n ```\n\n Advanced Example\n --------------\n\n Synchronous Example\n\n ```javascript\n let author, books;\n\n try {\n author = findAuthor();\n books = findBooksByAuthor(author);\n // success\n } catch(reason) {\n // failure\n }\n ```\n\n Errback Example\n\n ```js\n\n function foundBooks(books) {\n\n }\n\n function failure(reason) {\n\n }\n\n findAuthor(function(author, err){\n if (err) {\n failure(err);\n // failure\n } else {\n try {\n findBoooksByAuthor(author, function(books, err) {\n if (err) {\n failure(err);\n } else {\n try {\n foundBooks(books);\n } catch(reason) {\n failure(reason);\n }\n }\n });\n } catch(error) {\n failure(err);\n }\n // success\n }\n });\n ```\n\n Promise Example;\n\n ```javascript\n findAuthor().\n then(findBooksByAuthor).\n then(function(books){\n // found books\n }).catch(function(reason){\n // something went wrong\n });\n ```\n\n @method then\n @param {Function} onFulfillment\n @param {Function} onRejection\n @param {String} label optional string for labeling the promise.\n Useful for tooling.\n @return {Promise}\n*/\nPromise.prototype.then = then;\n\nexport default Promise;", + "import Promise from './promise';\nimport { noop, resolve, reject } from './-internal';\nimport { isArray } from './utils';\n\nfunction Result() {\n this.value = undefined;\n}\n\nvar ERROR = new Result();\nvar GET_THEN_ERROR = new Result();\n\nfunction getThen(obj) {\n try {\n return obj.then;\n } catch (error) {\n ERROR.value = error;\n return ERROR;\n }\n}\n\nfunction tryApply(f, s, a) {\n try {\n f.apply(s, a);\n } catch (error) {\n ERROR.value = error;\n return ERROR;\n }\n}\n\nfunction makeObject(_, argumentNames) {\n var obj = {};\n var length = _.length;\n var args = new Array(length);\n\n for (var x = 0; x < length; x++) {\n args[x] = _[x];\n }\n\n for (var i = 0; i < argumentNames.length; i++) {\n var name = argumentNames[i];\n obj[name] = args[i + 1];\n }\n\n return obj;\n}\n\nfunction arrayResult(_) {\n var length = _.length;\n var args = new Array(length - 1);\n\n for (var i = 1; i < length; i++) {\n args[i - 1] = _[i];\n }\n\n return args;\n}\n\nfunction wrapThenable(then, promise) {\n return {\n then: function (onFulFillment, onRejection) {\n return then.call(promise, onFulFillment, onRejection);\n }\n };\n}\n\n/**\n `RSVP.denodeify` takes a 'node-style' function and returns a function that\n will return an `RSVP.Promise`. You can use `denodeify` in Node.js or the\n browser when you'd prefer to use promises over using callbacks. For example,\n `denodeify` transforms the following:\n\n ```javascript\n let fs = require('fs');\n\n fs.readFile('myfile.txt', function(err, data){\n if (err) return handleError(err);\n handleData(data);\n });\n ```\n\n into:\n\n ```javascript\n let fs = require('fs');\n let readFile = RSVP.denodeify(fs.readFile);\n\n readFile('myfile.txt').then(handleData, handleError);\n ```\n\n If the node function has multiple success parameters, then `denodeify`\n just returns the first one:\n\n ```javascript\n let request = RSVP.denodeify(require('request'));\n\n request('http://example.com').then(function(res) {\n // ...\n });\n ```\n\n However, if you need all success parameters, setting `denodeify`'s\n second parameter to `true` causes it to return all success parameters\n as an array:\n\n ```javascript\n let request = RSVP.denodeify(require('request'), true);\n\n request('http://example.com').then(function(result) {\n // result[0] -> res\n // result[1] -> body\n });\n ```\n\n Or if you pass it an array with names it returns the parameters as a hash:\n\n ```javascript\n let request = RSVP.denodeify(require('request'), ['res', 'body']);\n\n request('http://example.com').then(function(result) {\n // result.res\n // result.body\n });\n ```\n\n Sometimes you need to retain the `this`:\n\n ```javascript\n let app = require('express')();\n let render = RSVP.denodeify(app.render.bind(app));\n ```\n\n The denodified function inherits from the original function. It works in all\n environments, except IE 10 and below. Consequently all properties of the original\n function are available to you. However, any properties you change on the\n denodeified function won't be changed on the original function. Example:\n\n ```javascript\n let request = RSVP.denodeify(require('request')),\n cookieJar = request.jar(); // <- Inheritance is used here\n\n request('http://example.com', {jar: cookieJar}).then(function(res) {\n // cookieJar.cookies holds now the cookies returned by example.com\n });\n ```\n\n Using `denodeify` makes it easier to compose asynchronous operations instead\n of using callbacks. For example, instead of:\n\n ```javascript\n let fs = require('fs');\n\n fs.readFile('myfile.txt', function(err, data){\n if (err) { ... } // Handle error\n fs.writeFile('myfile2.txt', data, function(err){\n if (err) { ... } // Handle error\n console.log('done')\n });\n });\n ```\n\n you can chain the operations together using `then` from the returned promise:\n\n ```javascript\n let fs = require('fs');\n let readFile = RSVP.denodeify(fs.readFile);\n let writeFile = RSVP.denodeify(fs.writeFile);\n\n readFile('myfile.txt').then(function(data){\n return writeFile('myfile2.txt', data);\n }).then(function(){\n console.log('done')\n }).catch(function(error){\n // Handle error\n });\n ```\n\n @method denodeify\n @static\n @for RSVP\n @param {Function} nodeFunc a 'node-style' function that takes a callback as\n its last argument. The callback expects an error to be passed as its first\n argument (if an error occurred, otherwise null), and the value from the\n operation as its second argument ('function(err, value){ }').\n @param {Boolean|Array} [options] An optional paramter that if set\n to `true` causes the promise to fulfill with the callback's success arguments\n as an array. This is useful if the node function has multiple success\n paramters. If you set this paramter to an array with names, the promise will\n fulfill with a hash with these names as keys and the success parameters as\n values.\n @return {Function} a function that wraps `nodeFunc` to return an\n `RSVP.Promise`\n @static\n*/\nexport default function denodeify(nodeFunc, options) {\n var fn = function () {\n var self = this;\n var l = arguments.length;\n var args = new Array(l + 1);\n var promiseInput = false;\n\n for (var i = 0; i < l; ++i) {\n var arg = arguments[i];\n\n if (!promiseInput) {\n // TODO: clean this up\n promiseInput = needsPromiseInput(arg);\n if (promiseInput === GET_THEN_ERROR) {\n var p = new Promise(noop);\n reject(p, GET_THEN_ERROR.value);\n return p;\n } else if (promiseInput && promiseInput !== true) {\n arg = wrapThenable(promiseInput, arg);\n }\n }\n args[i] = arg;\n }\n\n var promise = new Promise(noop);\n\n args[l] = function (err, val) {\n if (err) reject(promise, err);else if (options === undefined) resolve(promise, val);else if (options === true) resolve(promise, arrayResult(arguments));else if (isArray(options)) resolve(promise, makeObject(arguments, options));else resolve(promise, val);\n };\n\n if (promiseInput) {\n return handlePromiseInput(promise, args, nodeFunc, self);\n } else {\n return handleValueInput(promise, args, nodeFunc, self);\n }\n };\n\n fn.__proto__ = nodeFunc;\n\n return fn;\n}\n\nfunction handleValueInput(promise, args, nodeFunc, self) {\n var result = tryApply(nodeFunc, self, args);\n if (result === ERROR) {\n reject(promise, result.value);\n }\n return promise;\n}\n\nfunction handlePromiseInput(promise, args, nodeFunc, self) {\n return Promise.all(args).then(function (args) {\n var result = tryApply(nodeFunc, self, args);\n if (result === ERROR) {\n reject(promise, result.value);\n }\n return promise;\n });\n}\n\nfunction needsPromiseInput(arg) {\n if (arg && typeof arg === 'object') {\n if (arg.constructor === Promise) {\n return true;\n } else {\n return getThen(arg);\n }\n } else {\n return false;\n }\n}", + "import Promise from \"./promise\";\n\n/**\n This is a convenient alias for `RSVP.Promise.all`.\n\n @method all\n @static\n @for RSVP\n @param {Array} array Array of promises.\n @param {String} label An optional label. This is useful\n for tooling.\n*/\nexport default function all(array, label) {\n return Promise.all(array, label);\n}", + "function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nimport { default as Enumerator, makeSettledResult } from './enumerator';\nimport Promise from './promise';\nimport { isArray } from './utils';\n\nvar AllSettled = function (_Enumerator) {\n _inherits(AllSettled, _Enumerator);\n\n function AllSettled(Constructor, entries, label) {\n return _possibleConstructorReturn(this, _Enumerator.call(this, Constructor, entries, false /* don't abort on reject */, label));\n }\n\n return AllSettled;\n}(Enumerator);\n\nAllSettled.prototype._makeResult = makeSettledResult;\n\n/**\n`RSVP.allSettled` is similar to `RSVP.all`, but instead of implementing\na fail-fast method, it waits until all the promises have returned and\nshows you all the results. This is useful if you want to handle multiple\npromises' failure states together as a set.\n Returns a promise that is fulfilled when all the given promises have been\nsettled. The return promise is fulfilled with an array of the states of\nthe promises passed into the `promises` array argument.\n Each state object will either indicate fulfillment or rejection, and\nprovide the corresponding value or reason. The states will take one of\nthe following formats:\n ```javascript\n{ state: 'fulfilled', value: value }\n or\n{ state: 'rejected', reason: reason }\n```\n Example:\n ```javascript\nlet promise1 = RSVP.Promise.resolve(1);\nlet promise2 = RSVP.Promise.reject(new Error('2'));\nlet promise3 = RSVP.Promise.reject(new Error('3'));\nlet promises = [ promise1, promise2, promise3 ];\n RSVP.allSettled(promises).then(function(array){\n // array == [\n // { state: 'fulfilled', value: 1 },\n // { state: 'rejected', reason: Error },\n // { state: 'rejected', reason: Error }\n // ]\n // Note that for the second item, reason.message will be '2', and for the\n // third item, reason.message will be '3'.\n}, function(error) {\n // Not run. (This block would only be called if allSettled had failed,\n // for instance if passed an incorrect argument type.)\n});\n```\n @method allSettled\n@static\n@for RSVP\n@param {Array} entries\n@param {String} label - optional string that describes the promise.\nUseful for tooling.\n@return {Promise} promise that is fulfilled with an array of the settled\nstates of the constituent promises.\n*/\n\nexport default function allSettled(entries, label) {\n if (!isArray(entries)) {\n return Promise.reject(new TypeError(\"Promise.allSettled must be called with an array\"), label);\n }\n\n return new AllSettled(Promise, entries, label).promise;\n}", + "import Promise from './promise';\n\n/**\n This is a convenient alias for `RSVP.Promise.race`.\n\n @method race\n @static\n @for RSVP\n @param {Array} array Array of promises.\n @param {String} label An optional label. This is useful\n for tooling.\n */\nexport default function race(array, label) {\n return Promise.race(array, label);\n}", + "function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nimport Enumerator from './enumerator';\nimport { PENDING, FULFILLED, fulfill } from './-internal';\n\nvar hasOwnProperty = Object.prototype.hasOwnProperty;\n\nvar PromiseHash = function (_Enumerator) {\n _inherits(PromiseHash, _Enumerator);\n\n function PromiseHash(Constructor, object) {\n var abortOnReject = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;\n var label = arguments[3];\n return _possibleConstructorReturn(this, _Enumerator.call(this, Constructor, object, abortOnReject, label));\n }\n\n PromiseHash.prototype._init = function _init(Constructor, object) {\n this._result = {};\n\n this._enumerate(object);\n if (this._remaining === 0) {\n fulfill(this.promise, this._result);\n }\n };\n\n PromiseHash.prototype._enumerate = function _enumerate(input) {\n var promise = this.promise;\n var results = [];\n\n for (var key in input) {\n if (hasOwnProperty.call(input, key)) {\n results.push({\n position: key,\n entry: input[key]\n });\n }\n }\n\n var length = results.length;\n this._remaining = length;\n var result = void 0;\n\n for (var i = 0; promise._state === PENDING && i < length; i++) {\n result = results[i];\n this._eachEntry(result.entry, result.position);\n }\n };\n\n return PromiseHash;\n}(Enumerator);\n\nexport default PromiseHash;", + "import Promise from './promise';\nimport PromiseHash from './promise-hash';\nimport { isObject } from './utils';\n\n/**\n `RSVP.hash` is similar to `RSVP.all`, but takes an object instead of an array\n for its `promises` argument.\n\n Returns a promise that is fulfilled when all the given promises have been\n fulfilled, or rejected if any of them become rejected. The returned promise\n is fulfilled with a hash that has the same key names as the `promises` object\n argument. If any of the values in the object are not promises, they will\n simply be copied over to the fulfilled object.\n\n Example:\n\n ```javascript\n let promises = {\n myPromise: RSVP.resolve(1),\n yourPromise: RSVP.resolve(2),\n theirPromise: RSVP.resolve(3),\n notAPromise: 4\n };\n\n RSVP.hash(promises).then(function(hash){\n // hash here is an object that looks like:\n // {\n // myPromise: 1,\n // yourPromise: 2,\n // theirPromise: 3,\n // notAPromise: 4\n // }\n });\n ````\n\n If any of the `promises` given to `RSVP.hash` are rejected, the first promise\n that is rejected will be given as the reason to the rejection handler.\n\n Example:\n\n ```javascript\n let promises = {\n myPromise: RSVP.resolve(1),\n rejectedPromise: RSVP.reject(new Error('rejectedPromise')),\n anotherRejectedPromise: RSVP.reject(new Error('anotherRejectedPromise')),\n };\n\n RSVP.hash(promises).then(function(hash){\n // Code here never runs because there are rejected promises!\n }, function(reason) {\n // reason.message === 'rejectedPromise'\n });\n ```\n\n An important note: `RSVP.hash` is intended for plain JavaScript objects that\n are just a set of keys and values. `RSVP.hash` will NOT preserve prototype\n chains.\n\n Example:\n\n ```javascript\n function MyConstructor(){\n this.example = RSVP.resolve('Example');\n }\n\n MyConstructor.prototype = {\n protoProperty: RSVP.resolve('Proto Property')\n };\n\n let myObject = new MyConstructor();\n\n RSVP.hash(myObject).then(function(hash){\n // protoProperty will not be present, instead you will just have an\n // object that looks like:\n // {\n // example: 'Example'\n // }\n //\n // hash.hasOwnProperty('protoProperty'); // false\n // 'undefined' === typeof hash.protoProperty\n });\n ```\n\n @method hash\n @static\n @for RSVP\n @param {Object} object\n @param {String} label optional string that describes the promise.\n Useful for tooling.\n @return {Promise} promise that is fulfilled when all properties of `promises`\n have been fulfilled, or rejected if any of them become rejected.\n*/\nexport default function hash(object, label) {\n if (!isObject(object)) {\n return Promise.reject(new TypeError(\"Promise.hash must be called with an object\"), label);\n }\n\n return new PromiseHash(Promise, object, label).promise;\n}", + "function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nfunction _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError(\"this hasn't been initialised - super() hasn't been called\"); } return call && (typeof call === \"object\" || typeof call === \"function\") ? call : self; }\n\nfunction _inherits(subClass, superClass) { if (typeof superClass !== \"function\" && superClass !== null) { throw new TypeError(\"Super expression must either be null or a function, not \" + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }\n\nimport Promise from './promise';\nimport PromiseHash from './promise-hash';\nimport { isObject } from './utils';\nimport { makeSettledResult } from './enumerator';\n\nvar HashSettled = function (_PromiseHash) {\n _inherits(HashSettled, _PromiseHash);\n\n function HashSettled(Constructor, object, label) {\n return _possibleConstructorReturn(this, _PromiseHash.call(this, Constructor, object, false, label));\n }\n\n return HashSettled;\n}(PromiseHash);\n\nHashSettled.prototype._makeResult = makeSettledResult;\n\n/**\n `RSVP.hashSettled` is similar to `RSVP.allSettled`, but takes an object\n instead of an array for its `promises` argument.\n\n Unlike `RSVP.all` or `RSVP.hash`, which implement a fail-fast method,\n but like `RSVP.allSettled`, `hashSettled` waits until all the\n constituent promises have returned and then shows you all the results\n with their states and values/reasons. This is useful if you want to\n handle multiple promises' failure states together as a set.\n\n Returns a promise that is fulfilled when all the given promises have been\n settled, or rejected if the passed parameters are invalid.\n\n The returned promise is fulfilled with a hash that has the same key names as\n the `promises` object argument. If any of the values in the object are not\n promises, they will be copied over to the fulfilled object and marked with state\n 'fulfilled'.\n\n Example:\n\n ```javascript\n let promises = {\n myPromise: RSVP.Promise.resolve(1),\n yourPromise: RSVP.Promise.resolve(2),\n theirPromise: RSVP.Promise.resolve(3),\n notAPromise: 4\n };\n\n RSVP.hashSettled(promises).then(function(hash){\n // hash here is an object that looks like:\n // {\n // myPromise: { state: 'fulfilled', value: 1 },\n // yourPromise: { state: 'fulfilled', value: 2 },\n // theirPromise: { state: 'fulfilled', value: 3 },\n // notAPromise: { state: 'fulfilled', value: 4 }\n // }\n });\n ```\n\n If any of the `promises` given to `RSVP.hash` are rejected, the state will\n be set to 'rejected' and the reason for rejection provided.\n\n Example:\n\n ```javascript\n let promises = {\n myPromise: RSVP.Promise.resolve(1),\n rejectedPromise: RSVP.Promise.reject(new Error('rejection')),\n anotherRejectedPromise: RSVP.Promise.reject(new Error('more rejection')),\n };\n\n RSVP.hashSettled(promises).then(function(hash){\n // hash here is an object that looks like:\n // {\n // myPromise: { state: 'fulfilled', value: 1 },\n // rejectedPromise: { state: 'rejected', reason: Error },\n // anotherRejectedPromise: { state: 'rejected', reason: Error },\n // }\n // Note that for rejectedPromise, reason.message == 'rejection',\n // and for anotherRejectedPromise, reason.message == 'more rejection'.\n });\n ```\n\n An important note: `RSVP.hashSettled` is intended for plain JavaScript objects that\n are just a set of keys and values. `RSVP.hashSettled` will NOT preserve prototype\n chains.\n\n Example:\n\n ```javascript\n function MyConstructor(){\n this.example = RSVP.Promise.resolve('Example');\n }\n\n MyConstructor.prototype = {\n protoProperty: RSVP.Promise.resolve('Proto Property')\n };\n\n let myObject = new MyConstructor();\n\n RSVP.hashSettled(myObject).then(function(hash){\n // protoProperty will not be present, instead you will just have an\n // object that looks like:\n // {\n // example: { state: 'fulfilled', value: 'Example' }\n // }\n //\n // hash.hasOwnProperty('protoProperty'); // false\n // 'undefined' === typeof hash.protoProperty\n });\n ```\n\n @method hashSettled\n @for RSVP\n @param {Object} object\n @param {String} label optional string that describes the promise.\n Useful for tooling.\n @return {Promise} promise that is fulfilled when when all properties of `promises`\n have been settled.\n @static\n*/\n\nexport default function hashSettled(object, label) {\n if (!isObject(object)) {\n return Promise.reject(new TypeError(\"RSVP.hashSettled must be called with an object\"), label);\n }\n\n return new HashSettled(Promise, object, false, label).promise;\n}", + "/**\n `RSVP.rethrow` will rethrow an error on the next turn of the JavaScript event\n loop in order to aid debugging.\n\n Promises A+ specifies that any exceptions that occur with a promise must be\n caught by the promises implementation and bubbled to the last handler. For\n this reason, it is recommended that you always specify a second rejection\n handler function to `then`. However, `RSVP.rethrow` will throw the exception\n outside of the promise, so it bubbles up to your console if in the browser,\n or domain/cause uncaught exception in Node. `rethrow` will also throw the\n error again so the error can be handled by the promise per the spec.\n\n ```javascript\n function throws(){\n throw new Error('Whoops!');\n }\n\n let promise = new RSVP.Promise(function(resolve, reject){\n throws();\n });\n\n promise.catch(RSVP.rethrow).then(function(){\n // Code here doesn't run because the promise became rejected due to an\n // error!\n }, function (err){\n // handle the error here\n });\n ```\n\n The 'Whoops' error will be thrown on the next turn of the event loop\n and you can watch for it in your console. You can also handle it using a\n rejection handler given to `.then` or `.catch` on the returned promise.\n\n @method rethrow\n @static\n @for RSVP\n @param {Error} reason reason the promise became rejected.\n @throws Error\n @static\n*/\nexport default function rethrow(reason) {\n setTimeout(function () {\n throw reason;\n });\n throw reason;\n}", + "import Promise from \"./promise\";\n\n/**\n `RSVP.defer` returns an object similar to jQuery's `$.Deferred`.\n `RSVP.defer` should be used when porting over code reliant on `$.Deferred`'s\n interface. New code should use the `RSVP.Promise` constructor instead.\n\n The object returned from `RSVP.defer` is a plain object with three properties:\n\n * promise - an `RSVP.Promise`.\n * reject - a function that causes the `promise` property on this object to\n become rejected\n * resolve - a function that causes the `promise` property on this object to\n become fulfilled.\n\n Example:\n\n ```javascript\n let deferred = RSVP.defer();\n\n deferred.resolve(\"Success!\");\n\n deferred.promise.then(function(value){\n // value here is \"Success!\"\n });\n ```\n\n @method defer\n @static\n @for RSVP\n @param {String} label optional string for labeling the promise.\n Useful for tooling.\n @return {Object}\n */\n\nexport default function defer(label) {\n var deferred = { resolve: undefined, reject: undefined };\n\n deferred.promise = new Promise(function (resolve, reject) {\n deferred.resolve = resolve;\n deferred.reject = reject;\n }, label);\n\n return deferred;\n}", + "import Promise from './promise';\n\nimport { isFunction, isArray } from './utils';\n\n/**\n `RSVP.map` is similar to JavaScript's native `map` method, except that it\n waits for all promises to become fulfilled before running the `mapFn` on\n each item in given to `promises`. `RSVP.map` returns a promise that will\n become fulfilled with the result of running `mapFn` on the values the promises\n become fulfilled with.\n\n For example:\n\n ```javascript\n\n let promise1 = RSVP.resolve(1);\n let promise2 = RSVP.resolve(2);\n let promise3 = RSVP.resolve(3);\n let promises = [ promise1, promise2, promise3 ];\n\n let mapFn = function(item){\n return item + 1;\n };\n\n RSVP.map(promises, mapFn).then(function(result){\n // result is [ 2, 3, 4 ]\n });\n ```\n\n If any of the `promises` given to `RSVP.map` are rejected, the first promise\n that is rejected will be given as an argument to the returned promise's\n rejection handler. For example:\n\n ```javascript\n let promise1 = RSVP.resolve(1);\n let promise2 = RSVP.reject(new Error('2'));\n let promise3 = RSVP.reject(new Error('3'));\n let promises = [ promise1, promise2, promise3 ];\n\n let mapFn = function(item){\n return item + 1;\n };\n\n RSVP.map(promises, mapFn).then(function(array){\n // Code here never runs because there are rejected promises!\n }, function(reason) {\n // reason.message === '2'\n });\n ```\n\n `RSVP.map` will also wait if a promise is returned from `mapFn`. For example,\n say you want to get all comments from a set of blog posts, but you need\n the blog posts first because they contain a url to those comments.\n\n ```javscript\n\n let mapFn = function(blogPost){\n // getComments does some ajax and returns an RSVP.Promise that is fulfilled\n // with some comments data\n return getComments(blogPost.comments_url);\n };\n\n // getBlogPosts does some ajax and returns an RSVP.Promise that is fulfilled\n // with some blog post data\n RSVP.map(getBlogPosts(), mapFn).then(function(comments){\n // comments is the result of asking the server for the comments\n // of all blog posts returned from getBlogPosts()\n });\n ```\n\n @method map\n @static\n @for RSVP\n @param {Array} promises\n @param {Function} mapFn function to be called on each fulfilled promise.\n @param {String} label optional string for labeling the promise.\n Useful for tooling.\n @return {Promise} promise that is fulfilled with the result of calling\n `mapFn` on each fulfilled promise or value when they become fulfilled.\n The promise will be rejected if any of the given `promises` become rejected.\n @static\n*/\nexport default function map(promises, mapFn, label) {\n if (!isArray(promises)) {\n return Promise.reject(new TypeError(\"RSVP.map must be called with an array\"), label);\n }\n\n if (!isFunction(mapFn)) {\n return Promise.reject(new TypeError(\"RSVP.map expects a function as a second argument\"), label);\n }\n\n return Promise.all(promises, label).then(function (values) {\n var length = values.length;\n var results = new Array(length);\n\n for (var i = 0; i < length; i++) {\n results[i] = mapFn(values[i]);\n }\n\n return Promise.all(results, label);\n });\n}", + "import Promise from './promise';\n\n/**\n This is a convenient alias for `RSVP.Promise.resolve`.\n\n @method resolve\n @static\n @for RSVP\n @param {*} value value that the returned promise will be resolved with\n @param {String} label optional string for identifying the returned promise.\n Useful for tooling.\n @return {Promise} a promise that will become fulfilled with the given\n `value`\n*/\nexport default function resolve(value, label) {\n return Promise.resolve(value, label);\n}", + "import Promise from './promise';\n\n/**\n This is a convenient alias for `RSVP.Promise.reject`.\n\n @method reject\n @static\n @for RSVP\n @param {*} reason value that the returned promise will be rejected with.\n @param {String} label optional string for identifying the returned promise.\n Useful for tooling.\n @return {Promise} a promise rejected with the given `reason`.\n*/\nexport default function reject(reason, label) {\n return Promise.reject(reason, label);\n}", + "import Promise from './promise';\nimport { isFunction, isArray, isObject } from './utils';\n\n/**\n `RSVP.filter` is similar to JavaScript's native `filter` method, except that it\n waits for all promises to become fulfilled before running the `filterFn` on\n each item in given to `promises`. `RSVP.filter` returns a promise that will\n become fulfilled with the result of running `filterFn` on the values the\n promises become fulfilled with.\n\n For example:\n\n ```javascript\n\n let promise1 = RSVP.resolve(1);\n let promise2 = RSVP.resolve(2);\n let promise3 = RSVP.resolve(3);\n\n let promises = [promise1, promise2, promise3];\n\n let filterFn = function(item){\n return item > 1;\n };\n\n RSVP.filter(promises, filterFn).then(function(result){\n // result is [ 2, 3 ]\n });\n ```\n\n If any of the `promises` given to `RSVP.filter` are rejected, the first promise\n that is rejected will be given as an argument to the returned promise's\n rejection handler. For example:\n\n ```javascript\n let promise1 = RSVP.resolve(1);\n let promise2 = RSVP.reject(new Error('2'));\n let promise3 = RSVP.reject(new Error('3'));\n let promises = [ promise1, promise2, promise3 ];\n\n let filterFn = function(item){\n return item > 1;\n };\n\n RSVP.filter(promises, filterFn).then(function(array){\n // Code here never runs because there are rejected promises!\n }, function(reason) {\n // reason.message === '2'\n });\n ```\n\n `RSVP.filter` will also wait for any promises returned from `filterFn`.\n For instance, you may want to fetch a list of users then return a subset\n of those users based on some asynchronous operation:\n\n ```javascript\n\n let alice = { name: 'alice' };\n let bob = { name: 'bob' };\n let users = [ alice, bob ];\n\n let promises = users.map(function(user){\n return RSVP.resolve(user);\n });\n\n let filterFn = function(user){\n // Here, Alice has permissions to create a blog post, but Bob does not.\n return getPrivilegesForUser(user).then(function(privs){\n return privs.can_create_blog_post === true;\n });\n };\n RSVP.filter(promises, filterFn).then(function(users){\n // true, because the server told us only Alice can create a blog post.\n users.length === 1;\n // false, because Alice is the only user present in `users`\n users[0] === bob;\n });\n ```\n\n @method filter\n @static\n @for RSVP\n @param {Array} promises\n @param {Function} filterFn - function to be called on each resolved value to\n filter the final results.\n @param {String} label optional string describing the promise. Useful for\n tooling.\n @return {Promise}\n*/\n\nfunction resolveAll(promises, label) {\n return Promise.all(promises, label);\n}\n\nfunction resolveSingle(promise, label) {\n return Promise.resolve(promise, label).then(function (promises) {\n return resolveAll(promises, label);\n });\n}\n\nexport default function filter(promises, filterFn, label) {\n if (!isArray(promises) && !(isObject(promises) && promises.then !== undefined)) {\n return Promise.reject(new TypeError(\"RSVP.filter must be called with an array or promise\"), label);\n }\n\n if (!isFunction(filterFn)) {\n return Promise.reject(new TypeError(\"RSVP.filter expects function as a second argument\"), label);\n }\n\n var promise = isArray(promises) ? resolveAll(promises, label) : resolveSingle(promises, label);\n return promise.then(function (values) {\n var length = values.length;\n var filtered = new Array(length);\n\n for (var i = 0; i < length; i++) {\n filtered[i] = filterFn(values[i]);\n }\n\n return resolveAll(filtered, label).then(function (filtered) {\n var results = new Array(length);\n var newLength = 0;\n\n for (var _i = 0; _i < length; _i++) {\n if (filtered[_i]) {\n results[newLength] = values[_i];\n newLength++;\n }\n }\n\n results.length = newLength;\n\n return results;\n });\n });\n}", + "var len = 0;\nvar vertxNext = void 0;\nexport default function asap(callback, arg) {\n queue[len] = callback;\n queue[len + 1] = arg;\n len += 2;\n if (len === 2) {\n // If len is 1, that means that we need to schedule an async flush.\n // If additional callbacks are queued before the queue is flushed, they\n // will be processed by this flush that we are scheduling.\n scheduleFlush();\n }\n}\n\nvar browserWindow = typeof window !== 'undefined' ? window : undefined;\nvar browserGlobal = browserWindow || {};\nvar BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;\nvar isNode = typeof self === 'undefined' && typeof process !== 'undefined' && {}.toString.call(process) === '[object process]';\n\n// test for web worker but not in IE10\nvar isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';\n\n// node\nfunction useNextTick() {\n var nextTick = process.nextTick;\n // node version 0.10.x displays a deprecation warning when nextTick is used recursively\n // setImmediate should be used instead instead\n var version = process.versions.node.match(/^(?:(\\d+)\\.)?(?:(\\d+)\\.)?(\\*|\\d+)$/);\n if (Array.isArray(version) && version[1] === '0' && version[2] === '10') {\n nextTick = setImmediate;\n }\n return function () {\n return nextTick(flush);\n };\n}\n\n// vertx\nfunction useVertxTimer() {\n if (typeof vertxNext !== 'undefined') {\n return function () {\n vertxNext(flush);\n };\n }\n return useSetTimeout();\n}\n\nfunction useMutationObserver() {\n var iterations = 0;\n var observer = new BrowserMutationObserver(flush);\n var node = document.createTextNode('');\n observer.observe(node, { characterData: true });\n\n return function () {\n return node.data = iterations = ++iterations % 2;\n };\n}\n\n// web worker\nfunction useMessageChannel() {\n var channel = new MessageChannel();\n channel.port1.onmessage = flush;\n return function () {\n return channel.port2.postMessage(0);\n };\n}\n\nfunction useSetTimeout() {\n return function () {\n return setTimeout(flush, 1);\n };\n}\n\nvar queue = new Array(1000);\n\nfunction flush() {\n for (var i = 0; i < len; i += 2) {\n var callback = queue[i];\n var arg = queue[i + 1];\n\n callback(arg);\n\n queue[i] = undefined;\n queue[i + 1] = undefined;\n }\n\n len = 0;\n}\n\nfunction attemptVertex() {\n try {\n var r = require;\n var vertx = r('vertx');\n vertxNext = vertx.runOnLoop || vertx.runOnContext;\n return useVertxTimer();\n } catch (e) {\n return useSetTimeout();\n }\n}\n\nvar scheduleFlush = void 0;\n// Decide what async method to use to triggering processing of queued callbacks:\nif (isNode) {\n scheduleFlush = useNextTick();\n} else if (BrowserMutationObserver) {\n scheduleFlush = useMutationObserver();\n} else if (isWorker) {\n scheduleFlush = useMessageChannel();\n} else if (browserWindow === undefined && typeof require === 'function') {\n scheduleFlush = attemptVertex();\n} else {\n scheduleFlush = useSetTimeout();\n}", + "var platform = void 0;\n\n/* global self */\nif (typeof self === 'object') {\n platform = self;\n\n /* global global */\n} else if (typeof global === 'object') {\n platform = global;\n} else {\n throw new Error('no global: `self` or `global` found');\n}\n\nexport default platform;", + "var _asap$cast$Promise$Ev;\n\nfunction _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }\n\nimport Promise from './rsvp/promise';\nimport EventTarget from './rsvp/events';\nimport denodeify from './rsvp/node';\nimport all from './rsvp/all';\nimport allSettled from './rsvp/all-settled';\nimport race from './rsvp/race';\nimport hash from './rsvp/hash';\nimport hashSettled from './rsvp/hash-settled';\nimport rethrow from './rsvp/rethrow';\nimport defer from './rsvp/defer';\nimport { config, configure } from './rsvp/config';\nimport map from './rsvp/map';\nimport resolve from './rsvp/resolve';\nimport reject from './rsvp/reject';\nimport filter from './rsvp/filter';\nimport asap from './rsvp/asap';\n\n// defaults\nconfig.async = asap;\nconfig.after = function (cb) {\n return setTimeout(cb, 0);\n};\nvar cast = resolve;\n\nvar async = function (callback, arg) {\n return config.async(callback, arg);\n};\n\nfunction on() {\n config['on'].apply(config, arguments);\n}\n\nfunction off() {\n config['off'].apply(config, arguments);\n}\n\n// Set up instrumentation through `window.__PROMISE_INTRUMENTATION__`\nif (typeof window !== 'undefined' && typeof window['__PROMISE_INSTRUMENTATION__'] === 'object') {\n var callbacks = window['__PROMISE_INSTRUMENTATION__'];\n configure('instrument', true);\n for (var eventName in callbacks) {\n if (callbacks.hasOwnProperty(eventName)) {\n on(eventName, callbacks[eventName]);\n }\n }\n}\n\nimport platform from './rsvp/platform';\n// the default export here is for backwards compat:\n// https://github.com/tildeio/rsvp.js/issues/434\nexport default (_asap$cast$Promise$Ev = {\n asap: asap,\n cast: cast,\n Promise: Promise,\n EventTarget: EventTarget,\n all: all,\n allSettled: allSettled,\n race: race,\n hash: hash,\n hashSettled: hashSettled,\n rethrow: rethrow,\n defer: defer,\n denodeify: denodeify,\n configure: configure,\n on: on,\n off: off,\n resolve: resolve,\n reject: reject,\n map: map\n}, _defineProperty(_asap$cast$Promise$Ev, 'async', async), _defineProperty(_asap$cast$Promise$Ev, 'filter', filter), _asap$cast$Promise$Ev);\n\nexport { asap, cast, Promise, EventTarget, all, allSettled, race, hash, hashSettled, rethrow, defer, denodeify, configure, on, off, resolve, reject, map, async, filter };", + null, + null, + null, + null, + null, + null, + null, + null, + null, + null + ] +} \ No newline at end of file diff --git a/reader/static/js/screenfull.min.js b/reader/static/js/screenfull.min.js new file mode 100644 index 0000000000000000000000000000000000000000..6f5eaf3369c30601bd065204a83c3a0403721ab2 --- /dev/null +++ b/reader/static/js/screenfull.min.js @@ -0,0 +1,7 @@ +/*! +* screenfull +* v1.1.0 - 2013-09-06 +* https://github.com/sindresorhus/screenfull.js +* (c) Sindre Sorhus; MIT License +*/ +!function(a,b){"use strict";var c="undefined"!=typeof Element&&"ALLOW_KEYBOARD_INPUT"in Element,d=function(){for(var a,c,d=[["requestFullscreen","exitFullscreen","fullscreenElement","fullscreenEnabled","fullscreenchange","fullscreenerror"],["webkitRequestFullscreen","webkitExitFullscreen","webkitFullscreenElement","webkitFullscreenEnabled","webkitfullscreenchange","webkitfullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitCurrentFullScreenElement","webkitCancelFullScreen","webkitfullscreenchange","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozFullScreenElement","mozFullScreenEnabled","mozfullscreenchange","mozfullscreenerror"],["msRequestFullscreen","msExitFullscreen","msFullscreenElement","msFullscreenEnabled","MSFullscreenchange","MSFullscreenerror"]],e=0,f=d.length,g={};f>e;e++)if(a=d[e],a&&a[1]in b){for(e=0,c=a.length;c>e;e++)g[d[0][e]]=a[e];return g}return!1}(),e={request:function(a){var e=d.requestFullscreen;a=a||b.documentElement,/5\.1[\.\d]* Safari/.test(navigator.userAgent)?a[e]():a[e](c&&Element.ALLOW_KEYBOARD_INPUT)},exit:function(){b[d.exitFullscreen]()},toggle:function(a){this.isFullscreen?this.exit():this.request(a)},onchange:function(){},onerror:function(){},raw:d};return d?(Object.defineProperties(e,{isFullscreen:{get:function(){return!!b[d.fullscreenElement]}},element:{enumerable:!0,get:function(){return b[d.fullscreenElement]}},enabled:{enumerable:!0,get:function(){return!!b[d.fullscreenEnabled]}}}),b.addEventListener(d.fullscreenchange,function(a){e.onchange.call(e,a)}),b.addEventListener(d.fullscreenerror,function(a){e.onerror.call(e,a)}),a.screenfull=e,void 0):(a.screenfull=!1,void 0)}(window,document); \ No newline at end of file diff --git a/reader/templates/reader/book_read/epub_viewer.html b/reader/templates/reader/book_read/epub_viewer.html index 568fb00707b4e1dc0519782daa460f0c8d26b92c..8f316d7a520b449ed5e8ea78dd88fd0cd6c9b0e4 100644 --- a/reader/templates/reader/book_read/epub_viewer.html +++ b/reader/templates/reader/book_read/epub_viewer.html @@ -1,108 +1,148 @@ {% load static %} <!DOCTYPE html> -<html lang="en"> -<head> - <meta charset="UTF-8"> - <title>Read Book: {{ book.title }}</title> - <link rel="stylesheet" href="{% static "css/reader_epub.css" %}"> - <link rel="stylesheet" href="{% static "css/reader_toolbar.css" %}"> - <script src="{% static "js/jquery-3.7.1.min.js" %}"></script> - <script src="{% static "js/jszip.min.js" %}"></script> - <script src="{% static "js/epub.min.js" %}"></script> -</head> -<body> - <div class="reading-toolbar-top"> - <table> - <tbody> - <tr> - <td class="ta-left"> - <span class="ta-text">Now reading: {{ book.title }}</span> - </td> - <td> - <span class="ta-text" id="lastsaved"></span> - </td> - <td class="ta-right"> - <span class="ta-text"><a href="{% url 'view_book' book.id %}" class="btn btn-primary">Back to book</a></span> - </td> - </tr> - </tbody> - </table> - </div> - <div id="outerContainer"> - <div id="viewer"></div> - </div> - <div id="prev" class="epr-arrow">‹</div> - <div id="next" class="epr-arrow">›</div> +<html class="no-js"> + <head> + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> + <title>Read Book: {{ book.title }}</title> + <meta name="description" content=""> + <meta name="viewport" content="width=device-width, user-scalable=no"> + <meta name="apple-mobile-web-app-capable" content="yes"> - <script> - let partial_md5 = "{{ book.partial_md5 }}"; - let book = ePub("{{ book.original_file.url }}"); - let rendition = book.renderTo("viewer", { - manager: "continuous", - flow: "paginated", - width: "100%", - height: "100%", - snap: true - }); - {% if cfi_ref %} - let displayed = rendition.display("{{ cfi_ref }}"); - {% else %} - let displayed = rendition.display(); - {% endif %} + <link rel="stylesheet" href="{% static "css/epubjs_reader/normalize.css" %}"> + <link rel="stylesheet" href="{% static "css/epubjs_reader/main.css" %}"> + <link rel="stylesheet" href="{% static "css/epubjs_reader/popup.css" %}"> + <link rel="stylesheet" href="{% static "css/reader_toolbar.css" %}"> - // Generate locations - book.ready.then(function(){ - const stored = localStorage.getItem(partial_md5 + "-locations"); - if (stored) { - return book.locations.load(stored); - } else { - return book.locations.generate(300); - } - }).then(function(location) { - localStorage.setItem(partial_md5 + "-locations", book.locations.save()); - console.log("Locations generated"); - }); + <script src="{% static "js/jquery-3.7.1.min.js" %}"></script> + <script src="{% static "js/jszip.min.js" %}"></script> + <script src="{% static "js/epub.min.js" %}"></script> - {% include "reader/book_read/bookreader_save.js" %} + <!-- Full Screen --> + <script src="{% static "js/screenfull.min.js" %}"></script> - rendition.on("relocated", function(location){ - console.log(location); - let percentage = location.start.percentage; - if (location.atEnd) percentage = 1; // Fix for last page - saveProgress(location.start.cfi, percentage); - }); + <!-- Render --> + <script src="{% static "js/epub.min.js" %}"></script> - displayed.then(function(renderer){ - // -- do stuff - }); + <!-- Reader --> + <script src="{% static "js/epubjs_reader/reader.js" %}"></script> - // Navigation loaded - book.loaded.navigation.then(function(toc){ - // console.log(toc); - }); + <!-- Highlights --> + <!-- <script src="js/libs/jquery.highlight.js"></script> --> + <!-- <script src="js/hooks/extensions/highlight.js"></script> --> + </head> + <body> + <div class="reading-toolbar-top"> + <table> + <tbody> + <tr> + <td class="ta-left"> + <span class="ta-text">Now reading: {{ book.title }}</span> + </td> + <td> + <span class="ta-text" id="lastsaved"></span> + </td> + <td class="ta-right"> + <span class="ta-text"><a href="{% url 'view_book' book.id %}" class="btn btn-primary">Back to book</a></span> + </td> + </tr> + </tbody> + </table> + </div> + <div id="outerContainer"> + <div id="sidebar"> + <div id="panels"> + <a id="show-Toc" class="show_view icon-list-1 active" data-view="Toc">TOC</a> + <a id="show-Bookmarks" class="show_view icon-bookmark" data-view="Bookmarks">Bookmarks</a> + </div> + <div id="tocView" class="view"> + </div> + <div id="searchView" class="view"> + <ul id="searchResults"></ul> + </div> + <div id="bookmarksView" class="view"> + <ul id="bookmarks"></ul> + </div> + <div id="notesView" class="view"> + <div id="new-note"> + <textarea id="note-text"></textarea> + <button id="note-anchor">Anchor</button> + </div> + <ol id="notes"></ol> + </div> + </div> + <div id="main"> - var next = document.getElementById("next"); - next.addEventListener("click", function(){ - rendition.next(); - }, false); + <div id="titlebar"> + <div id="opener"> + <a id="slider" class="icon-menu">Menu</a> + </div> + <div id="metainfo"> + <span id="book-title"></span> + <span id="title-seperator"> – </span> + <span id="chapter-title"></span> + </div> + <div id="title-controls"> + <a id="bookmark" class="icon-bookmark-empty">Bookmark</a> + <a id="setting" class="icon-cog">Settings</a> + <a id="fullscreen" class="icon-resize-full">Fullscreen</a> + </div> + </div> - var prev = document.getElementById("prev"); - prev.addEventListener("click", function(){ - rendition.prev(); - }, false); + <div id="divider"></div> + <div id="prev" class="arrow">‹</div> + <div id="viewer"></div> + <div id="next" class="arrow">›</div> - rendition.on("keyup", event => { - let kc = event.keyCode || event.which; - if (kc === 37) rendition.prev(); - if (kc === 39) rendition.next(); - }); + <div id="loader"><img src="{% static "img/epubjs_reader/loader.gif" %}"></div> + </div> + <div class="modal md-effect-1" id="settings-modal"> + <div class="md-content"> + <h3>Settings</h3> + <div> + <p> + <input type="checkbox" id="sidebarReflow" name="sidebarReflow">Reflow text when sidebars are open. + </p> + </div> + <div class="closer icon-cancel-circled"></div> + </div> + </div> + <div class="overlay"></div> + </div> + <script> + let partial_md5 = "{{ book.partial_md5 }}"; + window.reader = ePubReader("{{ book.original_file.url }}", {}); + {% if cfi_ref %} + let displayed = window.reader.rendition.display("{{ cfi_ref }}"); + {% else %} + let displayed = window.reader.rendition.display(); + {% endif %} - $(window).on( "swipeleft", function( event ) { - rendition.next(); - }); - $(window).on( "swiperight", function( event ) { - rendition.prev(); - }); - </script> -</body> -</html> \ No newline at end of file + // Generate locations + window.reader.book.ready.then(function(){ + const stored = localStorage.getItem(partial_md5 + "-locations"); + if (stored) { + return window.reader.book.locations.load(stored); + } else { + return window.reader.book.locations.generate(300); + } + }).then(function(location) { + localStorage.setItem(partial_md5 + "-locations", window.reader.book.locations.save()); + console.log("Locations generated"); + }); + + {% include "reader/book_read/bookreader_save.js" %} + + window.reader.rendition.on("relocated", function(location){ + console.log(location); + let percentage = location.start.percentage; + if (location.atEnd) percentage = 1; // Fix for last page + saveProgress(location.start.cfi, percentage); + }); + + displayed.then(function(renderer){ + // -- do stuff + }); + </script> + </body> +</html> diff --git a/reader/templates/reader/book_read/old_epub_viewer.html b/reader/templates/reader/book_read/old_epub_viewer.html new file mode 100644 index 0000000000000000000000000000000000000000..568fb00707b4e1dc0519782daa460f0c8d26b92c --- /dev/null +++ b/reader/templates/reader/book_read/old_epub_viewer.html @@ -0,0 +1,108 @@ +{% load static %} +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="UTF-8"> + <title>Read Book: {{ book.title }}</title> + <link rel="stylesheet" href="{% static "css/reader_epub.css" %}"> + <link rel="stylesheet" href="{% static "css/reader_toolbar.css" %}"> + <script src="{% static "js/jquery-3.7.1.min.js" %}"></script> + <script src="{% static "js/jszip.min.js" %}"></script> + <script src="{% static "js/epub.min.js" %}"></script> +</head> +<body> + <div class="reading-toolbar-top"> + <table> + <tbody> + <tr> + <td class="ta-left"> + <span class="ta-text">Now reading: {{ book.title }}</span> + </td> + <td> + <span class="ta-text" id="lastsaved"></span> + </td> + <td class="ta-right"> + <span class="ta-text"><a href="{% url 'view_book' book.id %}" class="btn btn-primary">Back to book</a></span> + </td> + </tr> + </tbody> + </table> + </div> + <div id="outerContainer"> + <div id="viewer"></div> + </div> + <div id="prev" class="epr-arrow">‹</div> + <div id="next" class="epr-arrow">›</div> + + <script> + let partial_md5 = "{{ book.partial_md5 }}"; + let book = ePub("{{ book.original_file.url }}"); + let rendition = book.renderTo("viewer", { + manager: "continuous", + flow: "paginated", + width: "100%", + height: "100%", + snap: true + }); + {% if cfi_ref %} + let displayed = rendition.display("{{ cfi_ref }}"); + {% else %} + let displayed = rendition.display(); + {% endif %} + + // Generate locations + book.ready.then(function(){ + const stored = localStorage.getItem(partial_md5 + "-locations"); + if (stored) { + return book.locations.load(stored); + } else { + return book.locations.generate(300); + } + }).then(function(location) { + localStorage.setItem(partial_md5 + "-locations", book.locations.save()); + console.log("Locations generated"); + }); + + {% include "reader/book_read/bookreader_save.js" %} + + rendition.on("relocated", function(location){ + console.log(location); + let percentage = location.start.percentage; + if (location.atEnd) percentage = 1; // Fix for last page + saveProgress(location.start.cfi, percentage); + }); + + displayed.then(function(renderer){ + // -- do stuff + }); + + // Navigation loaded + book.loaded.navigation.then(function(toc){ + // console.log(toc); + }); + + var next = document.getElementById("next"); + next.addEventListener("click", function(){ + rendition.next(); + }, false); + + var prev = document.getElementById("prev"); + prev.addEventListener("click", function(){ + rendition.prev(); + }, false); + + rendition.on("keyup", event => { + let kc = event.keyCode || event.which; + if (kc === 37) rendition.prev(); + if (kc === 39) rendition.next(); + }); + + $(window).on( "swipeleft", function( event ) { + rendition.next(); + }); + $(window).on( "swiperight", function( event ) { + rendition.prev(); + }); + </script> +</body> +</html> \ No newline at end of file