diff --git a/API.js b/API.js
index 002baea..e450688 100644
--- a/API.js
+++ b/API.js
@@ -116,4 +116,15 @@ section.find("query");
epub.on("noAuth", function(){
-});
\ No newline at end of file
+});
+
+rendition = epub.renderTo("elementID", {});
+
+pagination = rendition.paginate({});
+pagination = new EPUBJS.Paginate(rendition, {spreads: true, minwidth: 800, layout: {} });
+ layout = new EPUBJS.Layout(global);
+
+pagination.next();
+pagination.prev();
+pagination.page();
+pagination.map();
\ No newline at end of file
diff --git a/dist/epub.js b/dist/epub.js
index 1a5048f..b2bceee 100644
--- a/dist/epub.js
+++ b/dist/epub.js
@@ -4401,9 +4401,9 @@ EPUBJS.Book.prototype.section = function(target) {
// Sugar to render a book
EPUBJS.Book.prototype.renderTo = function(element, options) {
- var rendition = new EPUBJS.Renderer(this, options);
- rendition.attachTo(element);
- return rendition;
+ this.rendition = new EPUBJS.Renderer(this, options);
+ this.rendition.attachTo(element);
+ return this.rendition;
};
EPUBJS.Book.prototype.requestMethod = function(_url) {
@@ -4744,7 +4744,37 @@ EPUBJS.core.documentHeight = function() {
EPUBJS.core.isNumber = function(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
-}
+};
+
+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.body.style[unprefixed]) != 'undefined') {
+ return unprefixed;
+ }
+
+ for ( var i=0; i < length; i++ ) {
+ if (typeof(document.body.style[vendors[i] + upper]) != 'undefined') {
+ return vendors[i] + upper;
+ }
+ }
+
+ return unprefixed;
+};
+
+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.EpubCFI = function(cfiStr){
if(cfiStr) return this.parse(cfiStr);
};
@@ -5291,16 +5321,17 @@ EPUBJS.Hook.prototype.trigger = function(){
return executing;
};
-EPUBJS.Infinite = function(container, renderer){
+EPUBJS.Infinite = function(container, axis){
this.container = container;
this.windowHeight = window.innerHeight;
this.tick = window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame;
this.scrolled = false;
this.ignore = false;
this.displaying = false;
- this.offset = 350;
+ this.offset = 900;
this.views = [];
- this.renderer = renderer;
+ this.axis = axis;
+ // this.renderer = renderer;
this.prevScrollTop = 0;
};
@@ -5342,12 +5373,25 @@ EPUBJS.Infinite.prototype.check = function(){
if(this.scrolled && !this.displaying) {
+ if(this.axis === "vertical") {
+ this.checkTop();
+ } else {
+ this.checkLeft();
+ }
+
+ this.scrolled = false;
+ } else {
+ this.displaying = false;
+ this.scrolled = false;
+ }
+
+ this.tick.call(window, this.check.bind(this));
+}
+
+EPUBJS.Infinite.prototype.checkTop = function(){
+
var scrollTop = this.container.scrollTop;
- var scrollLeft = this.container.scrollLeft;
-
var scrollHeight = this.container.scrollHeight;
- var scrollWidth = this.container.scrollWidth;
-
var direction = scrollTop - this.prevScrollTop;
var height = this.container.getBoundingClientRect().height;
@@ -5366,14 +5410,36 @@ EPUBJS.Infinite.prototype.check = function(){
// console.log(scrollTop)
this.prevScrollTop = scrollTop;
- this.scrolled = false;
- } else {
- this.displaying = false;
- this.scrolled = false;
- }
+ return scrollTop;
+};
- this.tick.call(window, this.check.bind(this));
-}
+EPUBJS.Infinite.prototype.checkLeft = function(){
+
+ var scrollLeft = this.container.scrollLeft;
+
+ var scrollWidth = this.container.scrollWidth;
+
+ var direction = scrollLeft - this.prevscrollLeft;
+
+ var width = this.container.getBoundingClientRect().width;
+
+ var right = scrollLeft + this.offset > scrollWidth-width;
+ var left = scrollLeft < this.offset;
+
+ // Add to bottom
+ if(right && direction > 0) {
+ this.forwards();
+ }
+ // Add to top
+ else if(left && direction < 0) {
+ this.backwards();
+ }
+
+ // console.log(scrollTop)
+ this.prevscrollLeft = scrollLeft;
+
+ return scrollLeft;
+};
EPUBJS.Infinite.prototype.scrollBy = function(x, y, silent){
if(silent) {
@@ -5381,6 +5447,9 @@ EPUBJS.Infinite.prototype.scrollBy = function(x, y, silent){
}
this.container.scrollLeft += x;
this.container.scrollTop += y;
+
+ this.scrolled = true;
+ this.check();
};
EPUBJS.Infinite.prototype.scroll = function(x, y, silent){
@@ -5389,106 +5458,189 @@ EPUBJS.Infinite.prototype.scroll = function(x, y, silent){
}
this.container.scrollLeft = x;
this.container.scrollTop = y;
+
+ this.scrolled = true;
+ this.check();
};
RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype);
-EPUBJS.Layout = function(){};
+EPUBJS.Layout = EPUBJS.Layout || {};
-/**
-* Reconciles the current chapters layout properies with
-* the global layout properities.
-* Takes: global layout settings object, chapter properties string
-* Returns: Object with layout properties
-*/
-EPUBJS.Layout.prototype.reconcileLayoutSettings = function(global, chapter){
- var settings = {};
+EPUBJS.Layout.Reflowable = function(){
+ this.documentElement = null;
+ this.spreadWidth = null;
+};
- //-- Get the global defaults
- for (var attr in global) {
- if (global.hasOwnProperty(attr)){
- settings[attr] = global[attr];
+EPUBJS.Layout.Reflowable.prototype.format = function(documentElement, _width, _height, _gap){
+ // Get the prefixed CSS commands
+ var columnAxis = EPUBJS.core.prefixed('columnAxis');
+ var columnGap = EPUBJS.core.prefixed('columnGap');
+ var columnWidth = EPUBJS.core.prefixed('columnWidth');
+ var columnFill = EPUBJS.core.prefixed('columnFill');
+
+ //-- Check the width and create even width columns
+ var width = Math.floor(_width);
+ // var width = (fullWidth % 2 === 0) ? fullWidth : fullWidth - 0; // Not needed for single
+ var section = Math.floor(width / 8);
+ var gap = (_gap >= 0) ? _gap : ((section % 2 === 0) ? section : section - 1);
+ this.documentElement = documentElement;
+ //-- Single Page
+ this.spreadWidth = (width + gap);
+
+
+ documentElement.style.overflow = "hidden";
+
+ // Must be set to the new calculated width or the columns will be off
+ documentElement.style.width = width + "px";
+
+ //-- Adjust height
+ documentElement.style.height = _height + "px";
+
+ //-- Add columns
+ documentElement.style[columnAxis] = "horizontal";
+ documentElement.style[columnFill] = "auto";
+ documentElement.style[columnWidth] = width+"px";
+ documentElement.style[columnGap] = gap+"px";
+ this.colWidth = width;
+ this.gap = gap;
+
+ return {
+ pageWidth : this.spreadWidth,
+ pageHeight : _height
+ };
+};
+
+EPUBJS.Layout.Reflowable.prototype.calculatePages = function() {
+ var totalWidth, displayedPages;
+ this.documentElement.style.width = "auto"; //-- reset width for calculations
+ totalWidth = this.documentElement.scrollWidth;
+ displayedPages = Math.ceil(totalWidth / this.spreadWidth);
+
+ return {
+ displayedPages : displayedPages,
+ pageCount : displayedPages
+ };
+};
+
+EPUBJS.Layout.ReflowableSpreads = function(){
+ this.documentElement = null;
+ this.spreadWidth = null;
+};
+
+EPUBJS.Layout.ReflowableSpreads.prototype.format = function(view, _width, _height, _gap){
+ var columnAxis = EPUBJS.core.prefixed('columnAxis');
+ var columnGap = EPUBJS.core.prefixed('columnGap');
+ var columnWidth = EPUBJS.core.prefixed('columnWidth');
+ var columnFill = EPUBJS.core.prefixed('columnFill');
+
+ var divisor = 2,
+ cutoff = 800;
+
+ //-- Check the width and create even width columns
+ var fullWidth = Math.floor(_width);
+ var width = (fullWidth % 2 === 0) ? fullWidth : fullWidth - 1;
+
+ var section = Math.floor(width / 8);
+ var gap = (_gap >= 0) ? _gap : ((section % 2 === 0) ? section : section - 1);
+
+ //-- Double Page
+ var colWidth = Math.floor((width - gap) / divisor);
+
+ this.spreadWidth = (colWidth + gap) * divisor;
+
+
+ view.document.documentElement.style.overflow = "hidden";
+
+ // Must be set to the new calculated width or the columns will be off
+ view.document.body.style.width = width + "px";
+
+ //-- Adjust height
+ view.document.body.style.height = _height + "px";
+
+ //-- Add columns
+ view.document.body.style[columnAxis] = "horizontal";
+ view.document.body.style[columnFill] = "auto";
+ view.document.body.style[columnGap] = gap+"px";
+ view.document.body.style[columnWidth] = colWidth+"px";
+
+ this.colWidth = colWidth;
+ this.gap = gap;
+
+ view.iframe.style.width = colWidth+"px";
+ view.iframe.style.paddingRight = gap+"px";
+
+ return {
+ pageWidth : this.spreadWidth,
+ pageHeight : _height
+ };
+};
+
+EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages = function() {
+ var totalWidth = this.documentElement.scrollWidth;
+ var displayedPages = Math.ceil(totalWidth / this.spreadWidth);
+
+ //-- Add a page to the width of the document to account an for odd number of pages
+ this.documentElement.style.width = totalWidth + this.spreadWidth + "px";
+ return {
+ displayedPages : displayedPages,
+ pageCount : displayedPages * 2
+ };
+};
+
+EPUBJS.Layout.Fixed = function(){
+ this.documentElement = null;
+};
+
+EPUBJS.Layout.Fixed = function(documentElement, _width, _height, _gap){
+ var columnWidth = EPUBJS.core.prefixed('columnWidth');
+ var viewport = documentElement.querySelector("[name=viewport");
+ var content;
+ var contents;
+ var width, height;
+
+ this.documentElement = documentElement;
+ /**
+ * check for the viewport size
+ *
+ */
+ if(viewport && viewport.hasAttribute("content")) {
+ content = viewport.getAttribute("content");
+ contents = content.split(',');
+ if(contents[0]){
+ width = contents[0].replace("width=", '');
+ }
+ if(contents[1]){
+ height = contents[1].replace("height=", '');
}
}
- //-- Get the chapter's display type
- chapter.forEach(function(prop){
- var rendition = prop.replace("rendition:", '');
- var split = rendition.indexOf("-");
- var property, value;
- if(split != -1){
- property = rendition.slice(0, split);
- value = rendition.slice(split+1);
+ //-- Adjust width and height
+ documentElement.style.width = width + "px" || "auto";
+ documentElement.style.height = height + "px" || "auto";
+
+ //-- Remove columns
+ documentElement.style[columnWidth] = "auto";
+
+ //-- Scroll
+ documentElement.style.overflow = "auto";
+
+ this.colWidth = width;
+ this.gap = 0;
+
+ return {
+ pageWidth : width,
+ pageHeight : height
+ };
- settings[property] = value;
- }
- });
- return settings;
};
-/**
-* Uses the settings to determine which Layout Method is needed
-* Triggers events based on the method choosen
-* Takes: Layout settings object
-* Returns: String of appropriate for EPUBJS.Layout function
-*/
-EPUBJS.Layout.prototype.determineLayout = function(settings){
- // Default is layout: reflowable & spread: auto
- var spreads = this.determineSpreads(this.minSpreadWidth);
- var layoutMethod = spreads ? "ReflowableSpreads" : "Reflowable";
- var scroll = false;
-
- if(settings.layout === "pre-paginated") {
- layoutMethod = "Fixed";
- scroll = true;
- spreads = false;
- }
-
- if(settings.layout === "reflowable" && settings.spread === "none") {
- layoutMethod = "Reflowable";
- scroll = false;
- spreads = false;
- }
-
- if(settings.layout === "reflowable" && settings.spread === "both") {
- layoutMethod = "ReflowableSpreads";
- scroll = false;
- spreads = true;
- }
-
- this.spreads = spreads;
- this.render.scroll(scroll);
- this.trigger("renderer:spreads", spreads);
- return layoutMethod;
+EPUBJS.Layout.Fixed.prototype.calculatePages = function(){
+ return {
+ displayedPages : 1,
+ pageCount : 1
+ };
};
-//-- STYLES
-
-EPUBJS.Layout.prototype.applyStyles = function(styles) {
- for (var style in styles) {
- for (var view in this.views) {
- view.setStyle(style, styles[style]);
- }
- }
-};
-
-EPUBJS.Layout.prototype.setStyle = function(style, val, prefixed){
- for (var view in this.views) {
- view.setStyle(style, val, prefixed);
- }
-};
-
-EPUBJS.Layout.prototype.removeStyle = function(style){
- for (var view in this.views) {
- view.removeStyle(style);
- }
-};
-
-//-- HEAD TAGS
-EPUBJS.Layout.prototype.applyHeadTags = function(headTags) {
- for ( var headTag in headTags ) {
- this.render.addHeadTag(headTag, headTags[headTag]);
- }
-};
/*
EPUBJS.Renderer.prototype.listeners = function(){
// Dom events to listen for
@@ -5656,6 +5808,146 @@ EPUBJS.Navigation.prototype.get = function(target) {
return this.toc[index];
};
+EPUBJS.Paginate = function(renderer, _options) {
+ var options = _options || {};
+ var defaults = {
+ width: 600,
+ height: 400,
+ forceSingle: false,
+ minSpreadWidth: 800, //-- overridden by spread: none (never) / both (always)
+ gap: "auto", //-- "auto" or int
+ layoutOveride : null // Default: { spread: 'reflowable', layout: 'auto', orientation: 'auto'}
+ };
+
+ this.settings = EPUBJS.core.defaults(options, defaults);
+ this.renderer = renderer;
+
+ this.isForcedSingle = false;
+
+ this.initialize();
+};
+
+EPUBJS.Paginate.prototype.determineSpreads = function(cutoff){
+ if(this.isForcedSingle || !cutoff || this.width < cutoff) {
+ return false; //-- Single Page
+ }else{
+ return true; //-- Double Page
+ }
+};
+
+EPUBJS.Paginate.prototype.forceSingle = function(bool){
+ if(bool) {
+ this.isForcedSingle = true;
+ // this.spreads = false;
+ } else {
+ this.isForcedSingle = false;
+ // this.spreads = this.determineSpreads(this.minSpreadWidth);
+ }
+};
+
+/**
+* Uses the settings to determine which Layout Method is needed
+* Triggers events based on the method choosen
+* Takes: Layout settings object
+* Returns: String of appropriate for EPUBJS.Layout function
+*/
+EPUBJS.Paginate.prototype.determineLayout = function(settings){
+ // Default is layout: reflowable & spread: auto
+ var spreads = this.determineSpreads(this.settings.minSpreadWidth);
+ var layoutMethod = spreads ? "ReflowableSpreads" : "Reflowable";
+ var scroll = false;
+
+ if(settings.layout === "pre-paginated") {
+ layoutMethod = "Fixed";
+ scroll = true;
+ spreads = false;
+ }
+
+ if(settings.layout === "reflowable" && settings.spread === "none") {
+ layoutMethod = "Reflowable";
+ scroll = false;
+ spreads = false;
+ }
+
+ if(settings.layout === "reflowable" && settings.spread === "both") {
+ layoutMethod = "ReflowableSpreads";
+ scroll = false;
+ spreads = true;
+ }
+
+ this.spreads = spreads;
+ // this.render.scroll(scroll);
+
+ return layoutMethod;
+};
+
+/**
+* Reconciles the current chapters layout properies with
+* the global layout properities.
+* Takes: global layout settings object, chapter properties string
+* Returns: Object with layout properties
+*/
+EPUBJS.Paginate.prototype.reconcileLayoutSettings = function(global, chapter){
+ var settings = {};
+
+ //-- Get the global defaults
+ for (var attr in global) {
+ if (global.hasOwnProperty(attr)){
+ settings[attr] = global[attr];
+ }
+ }
+ //-- Get the chapter's display type
+ chapter.forEach(function(prop){
+ var rendition = prop.replace("rendition:", '');
+ var split = rendition.indexOf("-");
+ var property, value;
+
+ if(split != -1){
+ property = rendition.slice(0, split);
+ value = rendition.slice(split+1);
+
+ settings[property] = value;
+ }
+ });
+ return settings;
+};
+
+EPUBJS.Paginate.prototype.initialize = function(){
+ // On display
+ // this.layoutSettings = this.reconcileLayoutSettings(globalLayout, chapter.properties);
+ // this.layoutMethod = this.determineLayout(this.layoutSettings);
+ // this.layout = new EPUBJS.Layout[this.layoutMethod]();
+ this.renderer.hooks.display.register(this.registerLayoutMethod.bind(this));
+};
+
+EPUBJS.Paginate.prototype.registerLayoutMethod = function(view) {
+ var task = new RSVP.defer();
+
+ this.layoutMethod = this.determineLayout({});
+ this.layout = new EPUBJS.Layout[this.layoutMethod]();
+ this.formated = this.layout.format(view, this.settings.width, this.settings.height, this.settings.gap);
+
+ task.resolve();
+ return task.promise;
+};
+
+EPUBJS.Paginate.prototype.page = function(pg){
+
+
+ //-- Return false if page is greater than the total
+ return false;
+};
+
+EPUBJS.Paginate.prototype.next = function(){
+ // return this.page(this.chapterPos + 1);
+ console.log("next", this.formated.pageWidth)
+ this.renderer.infinite.scrollBy(this.formated.pageWidth, 0);
+};
+
+EPUBJS.Paginate.prototype.prev = function(){
+ console.log("prev", this.formated.pageWidth)
+ this.renderer.infinite.scrollBy(-this.formated.pageWidth, 0);
+};
EPUBJS.Parser = function(){};
EPUBJS.Parser.prototype.container = function(containerXml){
@@ -6025,10 +6317,12 @@ EPUBJS.Parser.prototype.ncx = function(tocXml){
EPUBJS.Renderer = function(book, _options) {
var options = _options || {};
this.settings = {
- hidden: options.hidden || false,
- viewsLimit: 6,
- width: options.width || false,
- height: options.height || false,
+ infinite: typeof(options.infinite) === "undefined" ? true : options.infinite,
+ hidden: typeof(options.hidden) === "undefined" ? false : options.hidden,
+ axis: options.axis || "vertical",
+ viewsLimit: options.viewsLimit || 5,
+ width: typeof(options.width) === "undefined" ? false : options.width,
+ height: typeof(options.height) === "undefined" ? false : options.height,
};
this.book = book;
@@ -6057,6 +6351,11 @@ EPUBJS.Renderer = function(book, _options) {
this.hooks.display = new EPUBJS.Hook(this);
this.hooks.replacements = new EPUBJS.Hook(this);
+ if(!this.settings.infinite) {
+ this.settings.viewsLimit = 1;
+ }
+
+
};
/**
@@ -6065,12 +6364,29 @@ EPUBJS.Renderer = function(book, _options) {
*/
EPUBJS.Renderer.prototype.initialize = function(_options){
var options = _options || {};
- var height = options.height ? options.height + "px" : "100%";
- var width = options.width ? options.width + "px" : "100%";
+ var height = options.height !== false ? options.height : "100%";
+ var width = options.width !== false ? options.width : "100%";
var hidden = options.hidden || false;
+ if(options.height && EPUBJS.core.isNumber(options.height)) {
+ height = options.height + "px";
+ }
+
+ if(options.width && EPUBJS.core.isNumber(options.width)) {
+ width = options.width + "px";
+ }
+
this.container = document.createElement("div");
- this.infinite = new EPUBJS.Infinite(this.container, this);
+
+ if(this.settings.infinite) {
+ this.infinite = new EPUBJS.Infinite(this.container, this.settings.axis);
+ }
+
+ if(this.settings.axis === "horizontal") {
+ // this.container.style.display = "flex";
+ // this.container.style.flexWrap = "nowrap";
+ this.container.style.whiteSpace = "nowrap";
+ }
this.container.style.width = width;
this.container.style.height = height;
@@ -6140,26 +6456,29 @@ EPUBJS.Renderer.prototype.attachTo = function(_element){
this.resize(bounds.width, bounds.height);
}
- this.infinite.start();
+ if(this.settings.infinite) {
- this.infinite.on("forwards", function(){
- var next = this.last().section.index + 1;
-
- if(!this.rendering && next < this.book.spine.length){
- this.forwards();
- }
-
- }.bind(this));
+ this.infinite.start();
- this.infinite.on("backwards", function(){
- var prev = this.first().section.index - 1;
+ this.infinite.on("forwards", function(){
+ var next = this.last().section.index + 1;
- if(!this.rendering && prev > 0){
- this.backwards();
- }
+ if(!this.rendering && next < this.book.spine.length){
+ this.forwards();
+ }
- }.bind(this));
+ }.bind(this));
+
+ this.infinite.on("backwards", function(){
+ var prev = this.first().section.index - 1;
+ if(!this.rendering && prev > 0){
+ this.backwards();
+ }
+
+ }.bind(this));
+
+ }
window.addEventListener("resize", this.onResized.bind(this), false);
this.hooks.replacements.register(this.replacements.bind(this));
@@ -6188,11 +6507,14 @@ EPUBJS.Renderer.prototype.display = function(what){
if(section){
rendered = this.render(section);
- rendered
- .then(this.fill.bind(this))
- .then(function(){
- displaying.resolve(this);
- }.bind(this));
+ if(this.settings.infinite) {
+ rendered.then(this.fill.bind(this))
+ }
+
+ rendered.then(function(){
+ displaying.resolve(this);
+ }.bind(this));
+
} else {
displaying.reject(new Error("No Section Found"));
}
@@ -6226,6 +6548,9 @@ EPUBJS.Renderer.prototype.render = function(section){
.then(function(){
return this.hooks.replacements.trigger(view, this);
}.bind(this))
+ .then(function(){
+ return view.expand();
+ }.bind(this))
.then(function(){
this.rendering = false;
view.show();
@@ -6259,16 +6584,24 @@ EPUBJS.Renderer.prototype.forwards = function(){
rendered.then(function(){
var first = this.first();
var bounds = first.bounds();
- var prev = this.container.scrollTop;
+ var prevTop = this.container.scrollTop;
+ var prevLeft = this.container.scrollLeft;
+
if(this.views.length > this.settings.viewsLimit) {
// Remove the item
this.remove(first);
- // Reset Position
- this.infinite.scroll(0, prev - bounds.height, true)
-
+ if(this.settings.infinite) {
+ // Reset Position
+ if(this.settings.axis === "vertical") {
+ this.infinite.scroll(0, prevTop - bounds.height, true)
+ } else {
+ this.infinite.scroll(prevLeft - bounds.width, true);
+ }
+ }
}
+
}.bind(this));
@@ -6296,11 +6629,23 @@ EPUBJS.Renderer.prototype.backwards = function(view){
rendered = this.render(section);
rendered.then(function(){
- // this.container.scrollTop += this.first().height;
+ var last;
- this.infinite.scrollBy(0, this.first().height, true);
+ if(this.settings.infinite) {
+
+ // this.container.scrollTop += this.first().height;
+ if(this.settings.axis === "vertical") {
+ this.infinite.scrollBy(0, this.first().bounds().height, true);
+ } else {
+ this.infinite.scrollBy(this.first().bounds().width, 0, true);
+ }
+
+ }
if(this.views.length > this.settings.viewsLimit) {
+
+
+
last = this.last();
this.remove(last);
}
@@ -6314,21 +6659,15 @@ EPUBJS.Renderer.prototype.backwards = function(view){
// -- this might want to be in infinite
EPUBJS.Renderer.prototype.fill = function() {
- var height = this.container.getBoundingClientRect().height;
- var next = function(){
- var bottom = this.last().bounds().bottom;
- var defer = new RSVP.defer();
-
- if (height && bottom && (bottom < height)) { //&& (this.last().section.index + 1 < this.book.spine.length)) {
- return this.forwards().then(next);
- } else {
- this.rendering = false;
- defer.resolve();
- return defer.promise;
- }
- }.bind(this);
+
var prev = this.first().section.index - 1;
- var filling = next();
+ var filling = this.forwards();
+
+ if(this.settings.axis === "vertical") {
+ filling.then(this.fillVertical.bind(this));
+ } else {
+ filling.then(this.fillHorizontal.bind(this));
+ }
if(prev > 0){
filling.then(this.backwards.bind(this));
@@ -6343,6 +6682,34 @@ EPUBJS.Renderer.prototype.fill = function() {
};
+EPUBJS.Renderer.prototype.fillVertical = function() {
+ var height = this.container.getBoundingClientRect().height;
+ var bottom = this.last().bounds().bottom;
+ var defer = new RSVP.defer();
+
+ if (height && bottom && (bottom < height)) { //&& (this.last().section.index + 1 < this.book.spine.length)) {
+ return this.forwards().then(this.fillVertical.bind(this));
+ } else {
+ this.rendering = false;
+ defer.resolve();
+ return defer.promise;
+ }
+};
+
+EPUBJS.Renderer.prototype.fillHorizontal = function() {
+ var width = this.container.getBoundingClientRect().width;
+ var right = this.last().bounds().right;
+ var defer = new RSVP.defer();
+
+ if (width && right && (right <= width)) { //&& (this.last().section.index + 1 < this.book.spine.length)) {
+ return this.forwards().then(this.fillHorizontal.bind(this));
+ } else {
+ this.rendering = false;
+ defer.resolve();
+ return defer.promise;
+ }
+};
+
EPUBJS.Renderer.prototype.append = function(view){
var first, prevTop, prevHeight, offset;
@@ -6422,6 +6789,14 @@ EPUBJS.Renderer.prototype.replacements = function(view, renderer) {
return task.promise;
};
+EPUBJS.Renderer.prototype.paginate = function(options) {
+ this.pagination = new EPUBJS.Paginate(this, {
+ width: this.settings.width,
+ height: this.settings.height
+ });
+ return this.pagination;
+};
+
//-- Enable binding events to Renderer
RSVP.EventTarget.mixin(EPUBJS.Renderer.prototype);
EPUBJS.Section = function(item){
@@ -6615,20 +6990,18 @@ EPUBJS.View.prototype.create = function() {
this.iframe.style.border = "none";
this.resizing = true;
- this.iframe.width = "100%";
+ this.iframe.style.width = "100%";
this.iframe.style.height = "100%";
this.iframe.style.display = "none";
this.iframe.style.visibility = "hidden";
-
-
return this.iframe;
};
EPUBJS.View.prototype.resized = function(e) {
if (!this.resizing) {
- this.layout();
+ this.expand();
} else {
this.resizing = false;
}
@@ -6653,7 +7026,6 @@ EPUBJS.View.prototype.load = function(contents) {
this.document = this.iframe.contentDocument;
this.iframe.addEventListener("load", function(event) {
- var layout;
this.window = this.iframe.contentWindow;
this.document = this.iframe.contentDocument;
@@ -6675,56 +7047,62 @@ EPUBJS.View.prototype.display = function(contents) {
var displaying = new RSVP.defer();
var displayed = displaying.promise;
- this.iframe.style.display = "block";
+ // this.iframe.style.display = "block";
+ this.iframe.style.display = "inline-block";
+
// Reset Body Styles
this.document.body.style.margin = "0";
- this.document.body.style.display = "inline-block";
-
- // Set Padding -> TODO: apply these from a function
- this.document.body.style.padding = "0 20px 20px 20px";
+ // this.document.body.style.display = "inline-block";
+ this.document.documentElement.style.width = "auto";
-
setTimeout(function(){
this.window.addEventListener("resize", this.resized.bind(this), false);
}.bind(this), 10); // Wait to listen for resize events
- if(this.document.fonts.status !== "loading") {
- this.layout();
+ if(!this.document.fonts || this.document.fonts.status !== "loading") {
+ this.expand();
displaying.resolve(this);
} else {
this.document.fonts.onloading = function(){
- this.layout();
+ this.expand();
displaying.resolve(this);
}.bind(this);
}
- // this.observer = this.observe(this.document);
+ // this.observer = this.observe(this.document.body);
return displayed
};
-EPUBJS.View.prototype.layout = function() {
+EPUBJS.View.prototype.expand = function() {
var bounds;
+ var width, height;
// Check bounds
bounds = this.document.body.getBoundingClientRect();
-
- if(!bounds || (bounds.height == 0 && bounds.width == 0)) {
+ if(!bounds || (bounds.height === 0 && bounds.width === 0)) {
console.error("View not shown");
}
// Apply Changes
this.resizing = true;
- this.iframe.style.height = bounds.height + "px";
- // this.iframe.style.width = bounds.width + "px";
- this.width = bounds.width;
- this.height = bounds.height;
+ height = bounds.height; //this.document.documentElement.scrollHeight;
+ this.iframe.style.height = height + "px";
+ width = this.document.documentElement.scrollWidth;
+ this.iframe.style.width = width + "px";
+
+
+
+ // this.width = width;
+ // this.height = height;
+
+ return bounds;
};
EPUBJS.View.prototype.observe = function(target) {
@@ -6732,9 +7110,10 @@ EPUBJS.View.prototype.observe = function(target) {
// create an observer instance
var observer = new MutationObserver(function(mutations) {
- mutations.forEach(function(mutation) {
- renderer.layout();
- });
+ renderer.expand();
+ // mutations.forEach(function(mutation) {
+ // console.log(mutation)
+ // });
});
// configuration of the observer:
@@ -6756,12 +7135,9 @@ EPUBJS.View.prototype.prependTo = function(element) {
element.insertBefore(this.iframe, element.firstChild);
};
-EPUBJS.View.prototype.bounds = function() {
- return this.iframe.getBoundingClientRect();
-};
-
EPUBJS.View.prototype.show = function() {
- this.iframe.style.display = "block";
+ // this.iframe.style.display = "block";
+ this.iframe.style.display = "inline-block";
this.iframe.style.visibility = "visible";
};
@@ -6770,6 +7146,10 @@ EPUBJS.View.prototype.hide = function() {
this.iframe.style.visibility = "hidden";
};
+EPUBJS.View.prototype.bounds = function() {
+ return this.iframe.getBoundingClientRect();
+};
+
EPUBJS.View.prototype.destroy = function() {
// Stop observing
// this.observer.disconnect();
diff --git a/dist/epub.min.js b/dist/epub.min.js
index a741c44..e5c92b1 100644
--- a/dist/epub.min.js
+++ b/dist/epub.min.js
@@ -1,3 +1,3 @@
-"undefined"==typeof EPUBJS&&(("undefined"!=typeof window?window:this).EPUBJS={}),EPUBJS.VERSION="0.3.0",EPUBJS.Render={},function(e){"use strict";var t=function(e){return new EPUBJS.Book(e)};t.Render={register:function(e,r){t.Render[e]=r}},"object"==typeof exports?(e.RSVP=require("rsvp"),module.exports=t):"function"==typeof define&&define.amd?define(t):e.ePub=t}(this),function(e){var t,r;!function(){var e={},n={};t=function(t,r,n){e[t]={deps:r,callback:n}},r=function(t){function i(e){if("."!==e.charAt(0))return e;for(var r=e.split("/"),n=t.split("/").slice(0,-1),i=0,s=r.length;s>i;i++){var o=r[i];if(".."===o)n.pop();else{if("."===o)continue;n.push(o)}}return n.join("/")}if(n[t])return n[t];if(n[t]={},!e[t])throw new Error("Could not find module "+t);for(var s,o=e[t],a=o.deps,u=o.callback,h=[],c=0,p=a.length;p>c;c++)h.push("exports"===a[c]?s={}:r(i(a[c])));var l=u.apply(this,h);return n[t]=s||l},r.entries=e}(),t("rsvp/-internal",["./utils","./instrument","./config","exports"],function(e,t,r,n){"use strict";function i(){}function s(e){try{return e.then}catch(t){return U.error=t,U}}function o(e,t,r,n){try{e.call(t,r,n)}catch(i){return i}}function a(e,t,r){E.async(function(e){var n=!1,i=o(r,t,function(r){n||(n=!0,t!==r?c(e,r):l(e,r))},function(t){n||(n=!0,d(e,t))},"Settle: "+(e._label||" unknown promise"));!n&&i&&(n=!0,d(e,i))},e)}function u(e,t){e._onerror=null,t._state===x?l(e,t._result):e._state===B?d(e,t._result):f(t,void 0,function(r){t!==r?c(e,r):l(e,r)},function(t){d(e,t)})}function h(e,t){if(t instanceof e.constructor)u(e,t);else{var r=s(t);r===U?d(e,U.error):void 0===r?l(e,t):_(r)?a(e,t,r):l(e,t)}}function c(e,t){e===t?l(e,t):S(t)?h(e,t):l(e,t)}function p(e){e._onerror&&e._onerror(e._result),m(e)}function l(e,t){e._state===w&&(e._result=t,e._state=x,0===e._subscribers.length?E.instrument&&P("fulfilled",e):E.async(m,e))}function d(e,t){e._state===w&&(e._state=B,e._result=t,E.async(p,e))}function f(e,t,r,n){var i=e._subscribers,s=i.length;e._onerror=null,i[s]=t,i[s+x]=r,i[s+B]=n,0===s&&e._state&&E.async(m,e)}function m(e){var t=e._subscribers,r=e._state;if(E.instrument&&P(r===x?"fulfilled":"rejected",e),0!==t.length){for(var n,i,s=e._result,o=0;oe;e+=2){var t=p[e],r=p[e+1];t(r),p[e]=void 0,p[e+1]=void 0}o=0}var o=0;e["default"]=function(e,t){p[o]=e,p[o+1]=t,o+=2,2===o&&a()};var a,u="undefined"!=typeof window?window:{},h=u.MutationObserver||u.WebKitMutationObserver,c="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,p=new Array(1e3);a="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?t():h?r():c?n():i()}),t("rsvp/config",["./events","exports"],function(e,t){"use strict";function r(e,t){return"onerror"===e?void i.on("error",t):2!==arguments.length?i[e]:void(i[e]=t)}var n=e["default"],i={instrument:!1};n.mixin(i),t.config=i,t.configure=r}),t("rsvp/defer",["./promise","exports"],function(e,t){"use strict";var r=e["default"];t["default"]=function(e){var t={};return t.promise=new r(function(e,r){t.resolve=e,t.reject=r},e),t}}),t("rsvp/enumerator",["./utils","./-internal","exports"],function(e,t,r){"use strict";function n(e,t,r){return e===p?{state:"fulfilled",value:r}:{state:"rejected",reason:r}}function i(e,t,r,n){this._instanceConstructor=e,this.promise=new e(a,n),this._abortOnReject=r,this._validateInput(t)?(this._input=t,this.length=t.length,this._remaining=t.length,this._init(),0===this.length?h(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&h(this.promise,this._result))):u(this.promise,this._validationError())}var s=e.isArray,o=e.isMaybeThenable,a=t.noop,u=t.reject,h=t.fulfill,c=t.subscribe,p=t.FULFILLED,l=t.REJECTED,d=t.PENDING,f=!0;r.ABORT_ON_REJECTION=f,r.makeSettledResult=n,i.prototype._validateInput=function(e){return s(e)},i.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},i.prototype._init=function(){this._result=new Array(this.length)},r["default"]=i,i.prototype._enumerate=function(){for(var e=this.length,t=this.promise,r=this._input,n=0;t._state===d&&e>n;n++)this._eachEntry(r[n],n)},i.prototype._eachEntry=function(e,t){var r=this._instanceConstructor;o(e)?e.constructor===r&&e._state!==d?(e._onerror=null,this._settledAt(e._state,t,e._result)):this._willSettleAt(r.resolve(e),t):(this._remaining--,this._result[t]=this._makeResult(p,t,e))},i.prototype._settledAt=function(e,t,r){var n=this.promise;n._state===d&&(this._remaining--,this._abortOnReject&&e===l?u(n,r):this._result[t]=this._makeResult(e,t,r)),0===this._remaining&&h(n,this._result)},i.prototype._makeResult=function(e,t,r){return r},i.prototype._willSettleAt=function(e,t){var r=this;c(e,void 0,function(e){r._settledAt(p,t,e)},function(e){r._settledAt(l,t,e)})}}),t("rsvp/events",["exports"],function(e){"use strict";function t(e,t){for(var r=0,n=e.length;n>r;r++)if(e[r]===t)return r;return-1}function r(e){var t=e._promiseCallbacks;return t||(t=e._promiseCallbacks={}),t}e["default"]={mixin:function(e){return e.on=this.on,e.off=this.off,e.trigger=this.trigger,e._promiseCallbacks=void 0,e},on:function(e,n){var i,s=r(this);i=s[e],i||(i=s[e]=[]),-1===t(i,n)&&i.push(n)},off:function(e,n){var i,s,o=r(this);return n?(i=o[e],s=t(i,n),void(-1!==s&&i.splice(s,1))):void(o[e]=[])},trigger:function(e,t){var n,i,s=r(this);if(n=s[e])for(var o=0;oa;a++)o[a]=t(e[a]);return n.all(o,r).then(function(t){for(var r=new Array(s),n=0,i=0;s>i;i++)t[i]&&(r[n]=e[i],n++);return r.length=n,r})})}}),t("rsvp/hash-settled",["./promise","./enumerator","./promise-hash","./utils","exports"],function(e,t,r,n,i){"use strict";function s(e,t,r){this._superConstructor(e,t,!1,r)}var o=e["default"],a=t.makeSettledResult,u=r["default"],h=t["default"],c=n.o_create;s.prototype=c(u.prototype),s.prototype._superConstructor=h,s.prototype._makeResult=a,s.prototype._validationError=function(){return new Error("hashSettled must be called with an object")},i["default"]=function(e,t){return new s(o,e,t).promise}}),t("rsvp/hash",["./promise","./promise-hash","./enumerator","exports"],function(e,t,r,n){"use strict";{var i=e["default"],s=t["default"];r.ABORT_ON_REJECTION}n["default"]=function(e,t){return new s(i,e,t).promise}}),t("rsvp/instrument",["./config","./utils","exports"],function(e,t,r){"use strict";var n=e.config,i=t.now,s=[];r["default"]=function(e,t,r){1===s.push({name:e,payload:{guid:t._guidKey+t._id,eventName:e,detail:t._result,childGuid:r&&t._guidKey+r._id,label:t._label,timeStamp:i(),stack:new Error(t._label).stack}})&&setTimeout(function(){for(var e,t=0;ta;a++)o[a]=t(e[a]);return n.all(o,r)})}}),t("rsvp/node",["./promise","./utils","exports"],function(e,t,r){"use strict";var n=e["default"],i=t.isArray;r["default"]=function(e,t){function r(){for(var r=arguments.length,i=new Array(r),a=0;r>a;a++)i[a]=arguments[a];var u;return s||o||!t?u=this:("object"==typeof console&&console.warn('Deprecation: RSVP.denodeify() doesn\'t allow setting the "this" binding anymore. Use yourFunction.bind(yourThis) instead.'),u=t),n.all(i).then(function(r){function i(n,i){function a(){for(var e=arguments.length,r=new Array(e),a=0;e>a;a++)r[a]=arguments[a];var u=r[0],h=r[1];if(u)i(u);else if(s)n(r.slice(1));else if(o){var c,p,l={},d=r.slice(1);for(p=0;pa;a++)s=r[a],this._eachEntry(s.entry,s.position)}}),t("rsvp/promise",["./config","./events","./instrument","./utils","./-internal","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(e,t,r,n,i,s,o,a,u,h,c){"use strict";function p(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function l(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function d(e,t){this._id=R++,this._label=t,this._subscribers=[],f.instrument&&m("created",this),v!==e&&(g(e)||p(),this instanceof d||l(),S(this,e))}var f=e.config,m=(t["default"],r["default"]),g=(n.objectOrFunction,n.isFunction),y=n.now,v=i.noop,b=(i.resolve,i.reject,i.fulfill,i.subscribe),S=i.initializePromise,_=i.invokeCallback,P=i.FULFILLED,E=s["default"],w=o["default"],x=a["default"],B=u["default"],U=h["default"],J="rsvp_"+y()+"-",R=0;c["default"]=d,d.cast=E,d.all=w,d.race=x,d.resolve=B,d.reject=U,d.prototype={constructor:d,_id:void 0,_guidKey:J,_label:void 0,_state:void 0,_result:void 0,_subscribers:void 0,_onerror:function(e){f.trigger("error",e)},then:function(e,t,r){var n=this;n._onerror=null;var i=new this.constructor(v,r),s=n._state,o=n._result;return f.instrument&&m("chained",n,i),s===P&&e?f.async(function(){_(s,i,e,o)}):b(n,i,e,t),i},"catch":function(e,t){return this.then(null,e,t)},"finally":function(e,t){var r=this.constructor;return this.then(function(t){return r.resolve(e()).then(function(){return t})},function(t){return r.resolve(e()).then(function(){throw t})},t)}}}),t("rsvp/promise/all",["../enumerator","exports"],function(e,t){"use strict";var r=e["default"];t["default"]=function(e,t){return new r(this,e,!0,t).promise}}),t("rsvp/promise/cast",["./resolve","exports"],function(e,t){"use strict";var r=e["default"];t["default"]=r}),t("rsvp/promise/race",["../utils","../-internal","exports"],function(e,t,r){"use strict";var n=e.isArray,i=(e.isFunction,e.isMaybeThenable,t.noop),s=t.resolve,o=t.reject,a=t.subscribe,u=t.PENDING;r["default"]=function(e,t){function r(e){s(p,e)}function h(e){o(p,e)}var c=this,p=new c(i,t);if(!n(e))return o(p,new TypeError("You must pass an array to race.")),p;for(var l=e.length,d=0;p._state===u&&l>d;d++)a(c.resolve(e[d]),void 0,r,h);return p}}),t("rsvp/promise/reject",["../-internal","exports"],function(e,t){"use strict";var r=e.noop,n=e.reject;t["default"]=function(e,t){var i=this,s=new i(r,t);return n(s,e),s}}),t("rsvp/promise/resolve",["../-internal","exports"],function(e,t){"use strict";var r=e.noop,n=e.resolve;t["default"]=function(e,t){var i=this;if(e&&"object"==typeof e&&e.constructor===i)return e;var s=new i(r,t);return n(s,e),s}}),t("rsvp/race",["./promise","exports"],function(e,t){"use strict";var r=e["default"];t["default"]=function(e,t){return r.race(e,t)}}),t("rsvp/reject",["./promise","exports"],function(e,t){"use strict";var r=e["default"];t["default"]=function(e,t){return r.reject(e,t)}}),t("rsvp/resolve",["./promise","exports"],function(e,t){"use strict";var r=e["default"];t["default"]=function(e,t){return r.resolve(e,t)}}),t("rsvp/rethrow",["exports"],function(e){"use strict";e["default"]=function(e){throw setTimeout(function(){throw e}),e}}),t("rsvp/utils",["exports"],function(e){"use strict";function t(e){return"function"==typeof e||"object"==typeof e&&null!==e}function r(e){return"function"==typeof e}function n(e){return"object"==typeof e&&null!==e}e.objectOrFunction=t,e.isFunction=r,e.isMaybeThenable=n;var i;i=Array.isArray?Array.isArray:function(e){return"[object Array]"===Object.prototype.toString.call(e)};var s=i;e.isArray=s;var o=Date.now||function(){return(new Date).getTime()};e.now=o;var a=Object.create||function(e){var t=function(){};return t.prototype=e,t};e.o_create=a}),t("rsvp",["./rsvp/promise","./rsvp/events","./rsvp/node","./rsvp/all","./rsvp/all-settled","./rsvp/race","./rsvp/hash","./rsvp/hash-settled","./rsvp/rethrow","./rsvp/defer","./rsvp/config","./rsvp/map","./rsvp/resolve","./rsvp/reject","./rsvp/filter","./rsvp/asap","exports"],function(e,t,r,n,i,s,o,a,u,h,c,p,l,d,f,m,g){"use strict";function y(e,t){A.async(e,t)}function v(){A.on.apply(A,arguments)}function b(){A.off.apply(A,arguments)}var S=e["default"],_=t["default"],P=r["default"],E=n["default"],w=i["default"],x=s["default"],B=o["default"],U=a["default"],J=u["default"],R=h["default"],A=c.config,I=c.configure,C=p["default"],T=l["default"],k=d["default"],F=f["default"],N=m["default"];if(A.async=N,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var q=window.__PROMISE_INSTRUMENTATION__;I("instrument",!0);for(var O in q)q.hasOwnProperty(O)&&v(O,q[O])}g.Promise=S,g.EventTarget=_,g.all=E,g.allSettled=w,g.race=x,g.hash=B,g.hashSettled=U,g.rethrow=J,g.defer=R,g.denodeify=P,g.configure=I,g.on=v,g.off=b,g.resolve=T,g.reject=k,g.async=y,g.map=C,g.filter=F}),e.RSVP=r("rsvp")}(self),function(e,t){"use strict";"object"==typeof exports?module.exports=t(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"==typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],t):e.URI=t(e.punycode,e.IPv6,e.SecondLevelDomains,e)}(this,function(e,t,r,n){"use strict";function i(e,t){return this instanceof i?(void 0===e&&(e="undefined"!=typeof location?location.href+"":""),this.href(e),void 0!==t?this.absoluteTo(t):this):new i(e,t)}function s(e){return e.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function o(e){return void 0===e?"Undefined":String(Object.prototype.toString.call(e)).slice(8,-1)}function a(e){return"Array"===o(e)}function u(e,t){var r,n,i={};if(a(t))for(r=0,n=t.length;n>r;r++)i[t[r]]=!0;else i[t]=!0;for(r=0,n=e.length;n>r;r++)void 0!==i[e[r]]&&(e.splice(r,1),n--,r--);return e}function h(e,t){var r,n;if(a(t)){for(r=0,n=t.length;n>r;r++)if(!h(e,t[r]))return!1;return!0}var i=o(t);for(r=0,n=e.length;n>r;r++)if("RegExp"===i){if("string"==typeof e[r]&&e[r].match(t))return!0}else if(e[r]===t)return!0;return!1}function c(e,t){if(!a(e)||!a(t))return!1;if(e.length!==t.length)return!1;e.sort(),t.sort();for(var r=0,n=e.length;n>r;r++)if(e[r]!==t[r])return!1;return!0}function p(e){return escape(e)}function l(e){return encodeURIComponent(e).replace(/[!'()*]/g,p).replace(/\*/g,"%2A")}var d=n&&n.URI;i.version="1.13.2";var f=i.prototype,m=Object.prototype.hasOwnProperty;i._parts=function(){return{protocol:null,username:null,password:null,hostname:null,urn:null,port:null,path:null,query:null,fragment:null,duplicateQueryParameters:i.duplicateQueryParameters,escapeQuerySpace:i.escapeQuerySpace}},i.duplicateQueryParameters=!1,i.escapeQuerySpace=!0,i.protocol_expression=/^[a-z][a-z0-9.+-]*$/i,i.idn_expression=/[^a-z0-9\.-]/i,i.punycode_expression=/(xn--)/i,i.ip4_expression=/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/,i.ip6_expression=/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/,i.find_uri_expression=/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,i.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?«»“”„‘’]+$/},i.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},i.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,i.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src"},i.getDomAttribute=function(e){if(!e||!e.nodeName)return void 0;var t=e.nodeName.toLowerCase();return"input"===t&&"image"!==e.type?void 0:i.domAttributes[t]},i.encode=l,i.decode=decodeURIComponent,i.iso8859=function(){i.encode=escape,i.decode=unescape},i.unicode=function(){i.encode=l,i.decode=decodeURIComponent},i.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}}},i.encodeQuery=function(e,t){var r=i.encode(e+"");return void 0===t&&(t=i.escapeQuerySpace),t?r.replace(/%20/g,"+"):r},i.decodeQuery=function(e,t){e+="",void 0===t&&(t=i.escapeQuerySpace);try{return i.decode(t?e.replace(/\+/g,"%20"):e)}catch(r){return e}},i.recodePath=function(e){for(var t=(e+"").split("/"),r=0,n=t.length;n>r;r++)t[r]=i.encodePathSegment(i.decode(t[r]));return t.join("/")},i.decodePath=function(e){for(var t=(e+"").split("/"),r=0,n=t.length;n>r;r++)t[r]=i.decodePathSegment(t[r]);return t.join("/")};var g,y={encode:"encode",decode:"decode"},v=function(e,t){return function(r){return i[t](r+"").replace(i.characters[e][t].expression,function(r){return i.characters[e][t].map[r]})}};for(g in y)i[g+"PathSegment"]=v("pathname",y[g]);i.encodeReserved=v("reserved","encode"),i.parse=function(e,t){var r;return t||(t={}),r=e.indexOf("#"),r>-1&&(t.fragment=e.substring(r+1)||null,e=e.substring(0,r)),r=e.indexOf("?"),r>-1&&(t.query=e.substring(r+1)||null,e=e.substring(0,r)),"//"===e.substring(0,2)?(t.protocol=null,e=e.substring(2),e=i.parseAuthority(e,t)):(r=e.indexOf(":"),r>-1&&(t.protocol=e.substring(0,r)||null,t.protocol&&!t.protocol.match(i.protocol_expression)?t.protocol=void 0:"file"===t.protocol?e=e.substring(r+3):"//"===e.substring(r+1,r+3)?(e=e.substring(r+3),e=i.parseAuthority(e,t)):(e=e.substring(r+1),t.urn=!0))),t.path=e,t},i.parseHost=function(e,t){var r,n,i=e.indexOf("/");return-1===i&&(i=e.length),"["===e.charAt(0)?(r=e.indexOf("]"),t.hostname=e.substring(1,r)||null,t.port=e.substring(r+2,i)||null,"/"===t.port&&(t.port=null)):e.indexOf(":")!==e.lastIndexOf(":")?(t.hostname=e.substring(0,i)||null,t.port=null):(n=e.substring(0,i).split(":"),t.hostname=n[0]||null,t.port=n[1]||null),t.hostname&&"/"!==e.substring(i).charAt(0)&&(i++,e="/"+e),e.substring(i)||"/"},i.parseAuthority=function(e,t){return e=i.parseUserinfo(e,t),i.parseHost(e,t)},i.parseUserinfo=function(e,t){var r,n=e.indexOf("/"),s=n>-1?e.lastIndexOf("@",n):e.indexOf("@");return s>-1&&(-1===n||n>s)?(r=e.substring(0,s).split(":"),t.username=r[0]?i.decode(r[0]):null,r.shift(),t.password=r[0]?i.decode(r.join(":")):null,e=e.substring(s+1)):(t.username=null,t.password=null),e},i.parseQuery=function(e,t){if(!e)return{};if(e=e.replace(/&+/g,"&").replace(/^\?*&*|&+$/g,""),!e)return{};for(var r,n,s,o={},a=e.split("&"),u=a.length,h=0;u>h;h++)r=a[h].split("="),n=i.decodeQuery(r.shift(),t),s=r.length?i.decodeQuery(r.join("="),t):null,o[n]?("string"==typeof o[n]&&(o[n]=[o[n]]),o[n].push(s)):o[n]=s;return o},i.build=function(e){var t="";return e.protocol&&(t+=e.protocol+":"),e.urn||!t&&!e.hostname||(t+="//"),t+=i.buildAuthority(e)||"","string"==typeof e.path&&("/"!==e.path.charAt(0)&&"string"==typeof e.hostname&&(t+="/"),t+=e.path),"string"==typeof e.query&&e.query&&(t+="?"+e.query),"string"==typeof e.fragment&&e.fragment&&(t+="#"+e.fragment),t},i.buildHost=function(e){var t="";return e.hostname?(t+=i.ip6_expression.test(e.hostname)?"["+e.hostname+"]":e.hostname,e.port&&(t+=":"+e.port),t):""},i.buildAuthority=function(e){return i.buildUserinfo(e)+i.buildHost(e)},i.buildUserinfo=function(e){var t="";return e.username&&(t+=i.encode(e.username),e.password&&(t+=":"+i.encode(e.password)),t+="@"),t},i.buildQuery=function(e,t,r){var n,s,o,u,h="";for(s in e)if(m.call(e,s)&&s)if(a(e[s]))for(n={},o=0,u=e[s].length;u>o;o++)void 0!==e[s][o]&&void 0===n[e[s][o]+""]&&(h+="&"+i.buildQueryParameter(s,e[s][o],r),t!==!0&&(n[e[s][o]+""]=!0));else void 0!==e[s]&&(h+="&"+i.buildQueryParameter(s,e[s],r));return h.substring(1)},i.buildQueryParameter=function(e,t,r){return i.encodeQuery(e,r)+(null!==t?"="+i.encodeQuery(t,r):"")},i.addQuery=function(e,t,r){if("object"==typeof t)for(var n in t)m.call(t,n)&&i.addQuery(e,n,t[n]);else{if("string"!=typeof t)throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");if(void 0===e[t])return void(e[t]=r);"string"==typeof e[t]&&(e[t]=[e[t]]),a(r)||(r=[r]),e[t]=e[t].concat(r)}},i.removeQuery=function(e,t,r){var n,s,o;if(a(t))for(n=0,s=t.length;s>n;n++)e[t[n]]=void 0;else if("object"==typeof t)for(o in t)m.call(t,o)&&i.removeQuery(e,o,t[o]);else{if("string"!=typeof t)throw new TypeError("URI.addQuery() accepts an object, string as the first parameter");void 0!==r?e[t]===r?e[t]=void 0:a(e[t])&&(e[t]=u(e[t],r)):e[t]=void 0}},i.hasQuery=function(e,t,r,n){if("object"==typeof t){for(var s in t)if(m.call(t,s)&&!i.hasQuery(e,s,t[s]))return!1;return!0}if("string"!=typeof t)throw new TypeError("URI.hasQuery() accepts an object, string as the name parameter");switch(o(r)){case"Undefined":return t in e;case"Boolean":var u=Boolean(a(e[t])?e[t].length:e[t]);return r===u;case"Function":return!!r(e[t],t,e);case"Array":if(!a(e[t]))return!1;var p=n?h:c;return p(e[t],r);case"RegExp":return a(e[t])?n?h(e[t],r):!1:Boolean(e[t]&&e[t].match(r));case"Number":r=String(r);case"String":return a(e[t])?n?h(e[t],r):!1:e[t]===r;default:throw new TypeError("URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter")}},i.commonPath=function(e,t){var r,n=Math.min(e.length,t.length);for(r=0;n>r;r++)if(e.charAt(r)!==t.charAt(r)){r--;break}return 1>r?e.charAt(0)===t.charAt(0)&&"/"===e.charAt(0)?"/":"":(("/"!==e.charAt(r)||"/"!==t.charAt(r))&&(r=e.substring(0,r).lastIndexOf("/")),e.substring(0,r+1))},i.withinString=function(e,t,r){r||(r={});var n=r.start||i.findUri.start,s=r.end||i.findUri.end,o=r.trim||i.findUri.trim,a=/[a-z0-9-]=["']?$/i;for(n.lastIndex=0;;){var u=n.exec(e);if(!u)break;var h=u.index;if(r.ignoreHtml){var c=e.slice(Math.max(h-3,0),h);if(c&&a.test(c))continue}var p=h+e.slice(h).search(s),l=e.slice(h,p).replace(o,"");if(!r.ignore||!r.ignore.test(l)){p=h+l.length;var d=t(l,h,p,e);e=e.slice(0,h)+d+e.slice(p),n.lastIndex=h+d.length}}return n.lastIndex=0,e},i.ensureValidHostname=function(t){if(t.match(i.invalid_hostname_characters)){if(!e)throw new TypeError('Hostname "'+t+'" contains characters other than [A-Z0-9.-] and Punycode.js is not available');if(e.toASCII(t).match(i.invalid_hostname_characters))throw new TypeError('Hostname "'+t+'" contains characters other than [A-Z0-9.-]')}},i.noConflict=function(e){if(e){var t={URI:this.noConflict()};return n.URITemplate&&"function"==typeof n.URITemplate.noConflict&&(t.URITemplate=n.URITemplate.noConflict()),n.IPv6&&"function"==typeof n.IPv6.noConflict&&(t.IPv6=n.IPv6.noConflict()),n.SecondLevelDomains&&"function"==typeof n.SecondLevelDomains.noConflict&&(t.SecondLevelDomains=n.SecondLevelDomains.noConflict()),t}return n.URI===this&&(n.URI=d),this},f.build=function(e){return e===!0?this._deferred_build=!0:(void 0===e||this._deferred_build)&&(this._string=i.build(this._parts),this._deferred_build=!1),this},f.clone=function(){return new i(this)},f.valueOf=f.toString=function(){return this.build(!1)._string},y={protocol:"protocol",username:"username",password:"password",hostname:"hostname",port:"port"},v=function(e){return function(t,r){return void 0===t?this._parts[e]||"":(this._parts[e]=t||null,this.build(!r),this)}};for(g in y)f[g]=v(y[g]);y={query:"?",fragment:"#"},v=function(e,t){return function(r,n){return void 0===r?this._parts[e]||"":(null!==r&&(r+="",r.charAt(0)===t&&(r=r.substring(1))),this._parts[e]=r,this.build(!n),this)}};for(g in y)f[g]=v(g,y[g]);y={search:["?","query"],hash:["#","fragment"]},v=function(e,t){return function(r,n){var i=this[e](r,n);return"string"==typeof i&&i.length?t+i:i}};for(g in y)f[g]=v(y[g][1],y[g][0]);f.pathname=function(e,t){if(void 0===e||e===!0){var r=this._parts.path||(this._parts.hostname?"/":"");return e?i.decodePath(r):r}return this._parts.path=e?i.recodePath(e):"/",this.build(!t),this},f.path=f.pathname,f.href=function(e,t){var r;if(void 0===e)return this.toString();this._string="",this._parts=i._parts();var n=e instanceof i,s="object"==typeof e&&(e.hostname||e.path||e.pathname);if(e.nodeName){var o=i.getDomAttribute(e);e=e[o]||"",s=!1}if(!n&&s&&void 0!==e.pathname&&(e=e.toString()),"string"==typeof e)this._parts=i.parse(e,this._parts);else{if(!n&&!s)throw new TypeError("invalid input");var a=n?e._parts:e;for(r in a)m.call(this._parts,r)&&(this._parts[r]=a[r])}return this.build(!t),this},f.is=function(e){var t=!1,n=!1,s=!1,o=!1,a=!1,u=!1,h=!1,c=!this._parts.urn;switch(this._parts.hostname&&(c=!1,n=i.ip4_expression.test(this._parts.hostname),s=i.ip6_expression.test(this._parts.hostname),t=n||s,o=!t,a=o&&r&&r.has(this._parts.hostname),u=o&&i.idn_expression.test(this._parts.hostname),h=o&&i.punycode_expression.test(this._parts.hostname)),e.toLowerCase()){case"relative":return c;case"absolute":return!c;case"domain":case"name":return o;case"sld":return a;case"ip":return t;case"ip4":case"ipv4":case"inet4":return n;case"ip6":case"ipv6":case"inet6":return s;case"idn":return u;case"url":return!this._parts.urn;case"urn":return!!this._parts.urn;case"punycode":return h}return null};var b=f.protocol,S=f.port,_=f.hostname;f.protocol=function(e,t){if(void 0!==e&&e&&(e=e.replace(/:(\/\/)?$/,""),!e.match(i.protocol_expression)))throw new TypeError('Protocol "'+e+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return b.call(this,e,t)},f.scheme=f.protocol,f.port=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0!==e&&(0===e&&(e=null),e&&(e+="",":"===e.charAt(0)&&(e=e.substring(1)),e.match(/[^0-9]/))))throw new TypeError('Port "'+e+'" contains characters other than [0-9]');return S.call(this,e,t)},f.hostname=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0!==e){var r={};i.parseHost(e,r),e=r.hostname}return _.call(this,e,t)},f.host=function(e,t){return this._parts.urn?void 0===e?"":this:void 0===e?this._parts.hostname?i.buildHost(this._parts):"":(i.parseHost(e,this._parts),this.build(!t),this)},f.authority=function(e,t){return this._parts.urn?void 0===e?"":this:void 0===e?this._parts.hostname?i.buildAuthority(this._parts):"":(i.parseAuthority(e,this._parts),this.build(!t),this)},f.userinfo=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e){if(!this._parts.username)return"";var r=i.buildUserinfo(this._parts);return r.substring(0,r.length-1)}return"@"!==e[e.length-1]&&(e+="@"),i.parseUserinfo(e,this._parts),this.build(!t),this},f.resource=function(e,t){var r;return void 0===e?this.path()+this.search()+this.hash():(r=i.parse(e),this._parts.path=r.path,this._parts.query=r.query,this._parts.fragment=r.fragment,this.build(!t),this)},f.subdomain=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,r)||""}var n=this._parts.hostname.length-this.domain().length,o=this._parts.hostname.substring(0,n),a=new RegExp("^"+s(o));return e&&"."!==e.charAt(e.length-1)&&(e+="."),e&&i.ensureValidHostname(e),this._parts.hostname=this._parts.hostname.replace(a,e),this.build(!t),this},f.domain=function(e,t){if(this._parts.urn)return void 0===e?"":this;if("boolean"==typeof e&&(t=e,e=void 0),void 0===e){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.match(/\./g);if(r&&r.length<2)return this._parts.hostname;var n=this._parts.hostname.length-this.tld(t).length-1;return n=this._parts.hostname.lastIndexOf(".",n-1)+1,this._parts.hostname.substring(n)||""}if(!e)throw new TypeError("cannot set domain empty");if(i.ensureValidHostname(e),!this._parts.hostname||this.is("IP"))this._parts.hostname=e;else{var o=new RegExp(s(this.domain())+"$");this._parts.hostname=this._parts.hostname.replace(o,e)}return this.build(!t),this},f.tld=function(e,t){if(this._parts.urn)return void 0===e?"":this;if("boolean"==typeof e&&(t=e,e=void 0),void 0===e){if(!this._parts.hostname||this.is("IP"))return"";var n=this._parts.hostname.lastIndexOf("."),i=this._parts.hostname.substring(n+1);return t!==!0&&r&&r.list[i.toLowerCase()]?r.get(this._parts.hostname)||i:i}var o;if(!e)throw new TypeError("cannot set TLD empty");
-if(e.match(/[^a-zA-Z0-9-]/)){if(!r||!r.is(e))throw new TypeError('TLD "'+e+'" contains characters other than [A-Z0-9]');o=new RegExp(s(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(o,e)}else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");o=new RegExp(s(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(o,e)}return this.build(!t),this},f.directory=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e||e===!0){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var r=this._parts.path.length-this.filename().length-1,n=this._parts.path.substring(0,r)||(this._parts.hostname?"/":"");return e?i.decodePath(n):n}var o=this._parts.path.length-this.filename().length,a=this._parts.path.substring(0,o),u=new RegExp("^"+s(a));return this.is("relative")||(e||(e="/"),"/"!==e.charAt(0)&&(e="/"+e)),e&&"/"!==e.charAt(e.length-1)&&(e+="/"),e=i.recodePath(e),this._parts.path=this._parts.path.replace(u,e),this.build(!t),this},f.filename=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e||e===!0){if(!this._parts.path||"/"===this._parts.path)return"";var r=this._parts.path.lastIndexOf("/"),n=this._parts.path.substring(r+1);return e?i.decodePathSegment(n):n}var o=!1;"/"===e.charAt(0)&&(e=e.substring(1)),e.match(/\.?\//)&&(o=!0);var a=new RegExp(s(this.filename())+"$");return e=i.recodePath(e),this._parts.path=this._parts.path.replace(a,e),o?this.normalizePath(t):this.build(!t),this},f.suffix=function(e,t){if(this._parts.urn)return void 0===e?"":this;if(void 0===e||e===!0){if(!this._parts.path||"/"===this._parts.path)return"";var r,n,o=this.filename(),a=o.lastIndexOf(".");return-1===a?"":(r=o.substring(a+1),n=/^[a-z0-9%]+$/i.test(r)?r:"",e?i.decodePathSegment(n):n)}"."===e.charAt(0)&&(e=e.substring(1));var u,h=this.suffix();if(h)u=new RegExp(e?s(h)+"$":s("."+h)+"$");else{if(!e)return this;this._parts.path+="."+i.recodePath(e)}return u&&(e=i.recodePath(e),this._parts.path=this._parts.path.replace(u,e)),this.build(!t),this},f.segment=function(e,t,r){var n=this._parts.urn?":":"/",i=this.path(),s="/"===i.substring(0,1),o=i.split(n);if(void 0!==e&&"number"!=typeof e&&(r=t,t=e,e=void 0),void 0!==e&&"number"!=typeof e)throw new Error('Bad segment "'+e+'", must be 0-based integer');if(s&&o.shift(),0>e&&(e=Math.max(o.length+e,0)),void 0===t)return void 0===e?o:o[e];if(null===e||void 0===o[e])if(a(t)){o=[];for(var u=0,h=t.length;h>u;u++)(t[u].length||o.length&&o[o.length-1].length)&&(o.length&&!o[o.length-1].length&&o.pop(),o.push(t[u]))}else(t||"string"==typeof t)&&(""===o[o.length-1]?o[o.length-1]=t:o.push(t));else t||"string"==typeof t&&t.length?o[e]=t:o.splice(e,1);return s&&o.unshift(""),this.path(o.join(n),r)},f.segmentCoded=function(e,t,r){var n,s,o;if("number"!=typeof e&&(r=t,t=e,e=void 0),void 0===t){if(n=this.segment(e,t,r),a(n))for(s=0,o=n.length;o>s;s++)n[s]=i.decode(n[s]);else n=void 0!==n?i.decode(n):void 0;return n}if(a(t))for(s=0,o=t.length;o>s;s++)t[s]=i.decode(t[s]);else t="string"==typeof t?i.encode(t):t;return this.segment(e,t,r)};var P=f.query;return f.query=function(e,t){if(e===!0)return i.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if("function"==typeof e){var r=i.parseQuery(this._parts.query,this._parts.escapeQuerySpace),n=e.call(this,r);return this._parts.query=i.buildQuery(n||r,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!t),this}return void 0!==e&&"string"!=typeof e?(this._parts.query=i.buildQuery(e,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!t),this):P.call(this,e,t)},f.setQuery=function(e,t,r){var n=i.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if("object"==typeof e)for(var s in e)m.call(e,s)&&(n[s]=e[s]);else{if("string"!=typeof e)throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");n[e]=void 0!==t?t:null}return this._parts.query=i.buildQuery(n,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof e&&(r=t),this.build(!r),this},f.addQuery=function(e,t,r){var n=i.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return i.addQuery(n,e,void 0===t?null:t),this._parts.query=i.buildQuery(n,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof e&&(r=t),this.build(!r),this},f.removeQuery=function(e,t,r){var n=i.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return i.removeQuery(n,e,t),this._parts.query=i.buildQuery(n,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof e&&(r=t),this.build(!r),this},f.hasQuery=function(e,t,r){var n=i.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return i.hasQuery(n,e,t,r)},f.setSearch=f.setQuery,f.addSearch=f.addQuery,f.removeSearch=f.removeQuery,f.hasSearch=f.hasQuery,f.normalize=function(){return this._parts.urn?this.normalizeProtocol(!1).normalizeQuery(!1).normalizeFragment(!1).build():this.normalizeProtocol(!1).normalizeHostname(!1).normalizePort(!1).normalizePath(!1).normalizeQuery(!1).normalizeFragment(!1).build()},f.normalizeProtocol=function(e){return"string"==typeof this._parts.protocol&&(this._parts.protocol=this._parts.protocol.toLowerCase(),this.build(!e)),this},f.normalizeHostname=function(r){return this._parts.hostname&&(this.is("IDN")&&e?this._parts.hostname=e.toASCII(this._parts.hostname):this.is("IPv6")&&t&&(this._parts.hostname=t.best(this._parts.hostname)),this._parts.hostname=this._parts.hostname.toLowerCase(),this.build(!r)),this},f.normalizePort=function(e){return"string"==typeof this._parts.protocol&&this._parts.port===i.defaultPorts[this._parts.protocol]&&(this._parts.port=null,this.build(!e)),this},f.normalizePath=function(e){if(this._parts.urn)return this;if(!this._parts.path||"/"===this._parts.path)return this;var t,r,n,s=this._parts.path,o="";for("/"!==s.charAt(0)&&(t=!0,s="/"+s),s=s.replace(/(\/(\.\/)+)|(\/\.$)/g,"/").replace(/\/{2,}/g,"/"),t&&(o=s.substring(1).match(/^(\.\.\/)+/)||"",o&&(o=o[0]));;){if(r=s.indexOf("/.."),-1===r)break;0!==r?(n=s.substring(0,r).lastIndexOf("/"),-1===n&&(n=r),s=s.substring(0,n)+s.substring(r+3)):s=s.substring(3)}return t&&this.is("relative")&&(s=o+s.substring(1)),s=i.recodePath(s),this._parts.path=s,this.build(!e),this},f.normalizePathname=f.normalizePath,f.normalizeQuery=function(e){return"string"==typeof this._parts.query&&(this._parts.query.length?this.query(i.parseQuery(this._parts.query,this._parts.escapeQuerySpace)):this._parts.query=null,this.build(!e)),this},f.normalizeFragment=function(e){return this._parts.fragment||(this._parts.fragment=null,this.build(!e)),this},f.normalizeSearch=f.normalizeQuery,f.normalizeHash=f.normalizeFragment,f.iso8859=function(){var e=i.encode,t=i.decode;return i.encode=escape,i.decode=decodeURIComponent,this.normalize(),i.encode=e,i.decode=t,this},f.unicode=function(){var e=i.encode,t=i.decode;return i.encode=l,i.decode=unescape,this.normalize(),i.encode=e,i.decode=t,this},f.readable=function(){var t=this.clone();t.username("").password("").normalize();var r="";if(t._parts.protocol&&(r+=t._parts.protocol+"://"),t._parts.hostname&&(t.is("punycode")&&e?(r+=e.toUnicode(t._parts.hostname),t._parts.port&&(r+=":"+t._parts.port)):r+=t.host()),t._parts.hostname&&t._parts.path&&"/"!==t._parts.path.charAt(0)&&(r+="/"),r+=t.path(!0),t._parts.query){for(var n="",s=0,o=t._parts.query.split("&"),a=o.length;a>s;s++){var u=(o[s]||"").split("=");n+="&"+i.decodeQuery(u[0],this._parts.escapeQuerySpace).replace(/&/g,"%26"),void 0!==u[1]&&(n+="="+i.decodeQuery(u[1],this._parts.escapeQuerySpace).replace(/&/g,"%26"))}r+="?"+n.substring(1)}return r+=i.decodeQuery(t.hash(),!0)},f.absoluteTo=function(e){var t,r,n,s=this.clone(),o=["protocol","username","password","hostname","port"];if(this._parts.urn)throw new Error("URNs do not have any generally defined hierarchical components");if(e instanceof i||(e=new i(e)),s._parts.protocol||(s._parts.protocol=e._parts.protocol),this._parts.hostname)return s;for(r=0;n=o[r];r++)s._parts[n]=e._parts[n];return s._parts.path?".."===s._parts.path.substring(-2)&&(s._parts.path+="/"):(s._parts.path=e._parts.path,s._parts.query||(s._parts.query=e._parts.query)),"/"!==s.path().charAt(0)&&(t=e.directory(),s._parts.path=(t?t+"/":"")+s._parts.path,s.normalizePath()),s.build(),s},f.relativeTo=function(e){var t,r,n,s,o,a=this.clone().normalize();if(a._parts.urn)throw new Error("URNs do not have any generally defined hierarchical components");if(e=new i(e).normalize(),t=a._parts,r=e._parts,s=a.path(),o=e.path(),"/"!==s.charAt(0))throw new Error("URI is already relative");if("/"!==o.charAt(0))throw new Error("Cannot calculate a URI relative to another relative URI");if(t.protocol===r.protocol&&(t.protocol=null),t.username!==r.username||t.password!==r.password)return a.build();if(null!==t.protocol||null!==t.username||null!==t.password)return a.build();if(t.hostname!==r.hostname||t.port!==r.port)return a.build();if(t.hostname=null,t.port=null,s===o)return t.path="",a.build();if(n=i.commonPath(a.path(),e.path()),!n)return a.build();var u=r.path.substring(n.length).replace(/[^\/]*$/,"").replace(/.*?\//g,"../");return t.path=u+t.path.substring(n.length),a.build()},f.equals=function(e){var t,r,n,s=this.clone(),o=new i(e),u={},h={},p={};if(s.normalize(),o.normalize(),s.toString()===o.toString())return!0;if(t=s.query(),r=o.query(),s.query(""),o.query(""),s.toString()!==o.toString())return!1;if(t.length!==r.length)return!1;u=i.parseQuery(t,this._parts.escapeQuerySpace),h=i.parseQuery(r,this._parts.escapeQuerySpace);for(n in u)if(m.call(u,n)){if(a(u[n])){if(!c(u[n],h[n]))return!1}else if(u[n]!==h[n])return!1;p[n]=!0}for(n in h)if(m.call(h,n)&&!p[n])return!1;return!0},f.duplicateQueryParameters=function(e){return this._parts.duplicateQueryParameters=!!e,this},f.escapeQuerySpace=function(e){return this._parts.escapeQuerySpace=!!e,this},i}),EPUBJS.Book=function(e){this.opening=new RSVP.defer,this.opened=this.opening.promise,this.isOpen=!1,this.url=void 0,this.spine=new EPUBJS.Spine(this.request),this.loading={manifest:new RSVP.defer,spine:new RSVP.defer,metadata:new RSVP.defer,cover:new RSVP.defer,navigation:new RSVP.defer,pageList:new RSVP.defer},this.loaded={manifest:this.loading.manifest.promise,spine:this.loading.spine.promise,metadata:this.loading.metadata.promise,cover:this.loading.cover.promise,navigation:this.loading.navigation.promise,pageList:this.loading.pageList.promise},this.ready=RSVP.hash(this.loaded),this.isRendered=!1,this._q=EPUBJS.core.queue(this),this.request=this.requestMethod.bind(this),e&&this.open(e)},EPUBJS.Book.prototype.open=function(e){var t,r,n,i=new EPUBJS.Parser,s=this,o="META-INF/container.xml";return e?(t="object"==typeof e?e:EPUBJS.core.uri(e),"opf"===t.extension?(this.packageUrl=t.href,this.containerUrl="",t.origin?this.url=t.origin+"/"+t.directory:window?(n=EPUBJS.core.uri(window.location.href),this.url=EPUBJS.core.resolveUrl(n.base,t.directory)):this.url=t.directory,r=this.request(this.packageUrl)):"epub"===t.extension||"zip"===t.extension?(this.archived=!0,this.url=""):t.extension||(this.containerUrl=e+o,r=this.request(this.containerUrl).then(function(e){return i.container(e)}).then(function(t){var r=EPUBJS.core.uri(t.packagePath);return s.packageUrl=e+t.packagePath,s.url=e+r.directory,s.encoding=t.encoding,s.request(s.packageUrl)}).catch(function(e){console.error("Could not load book at: "+(this.packageUrl||this.containerPath)),s.trigger("book:loadFailed",this.packageUrl||this.containerPath),s.opening.reject(e)})),r.then(function(e){s.unpack(e),s.loading.manifest.resolve(s.package.manifest),s.loading.metadata.resolve(s.package.metadata),s.loading.spine.resolve(s.spine),s.loading.cover.resolve(s.cover),this.isOpen=!0,s.opening.resolve(s)}).catch(function(e){console.error(e.message,e.stack),s.opening.reject(e)}),this.opened):(this.opening.resolve(this),this.opened)},EPUBJS.Book.prototype.unpack=function(e){var t=this,r=new EPUBJS.Parser;t.package=r.packageContents(e),t.package.baseUrl=t.url,this.spine.load(t.package),t.navigation=new EPUBJS.Navigation(t.package,this.request),t.navigation.load().then(function(e){t.toc=e,t.loading.navigation.resolve(t.toc)}),t.cover=t.url+t.package.coverPath},EPUBJS.Book.prototype.section=function(e){return this.spine.get(e)},EPUBJS.Book.prototype.renderTo=function(e,t){var r=new EPUBJS.Renderer(this,t);return r.attachTo(e),r},EPUBJS.Book.prototype.requestMethod=function(e){return this.archived?void 0:EPUBJS.core.request(e,"xml",this.requestCredentials,this.requestHeaders)},EPUBJS.Book.prototype.setRequestCredentials=function(e){this.requestCredentials=e},EPUBJS.Book.prototype.setRequestHeaders=function(e){this.requestHeaders=e},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(e){console.error(e.detail.message,e.detail.stack)}),EPUBJS.core={},EPUBJS.core.request=function(e,t,r,n){function i(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var e;e="xml"==t?this.responseXML:"json"==t?JSON.parse(this.response):"blob"==t?o?this.response:new Blob([this.response]):this.response,u.resolve(e)}else u.reject({status:this.status,message:this.response,stack:(new Error).stack})}var s,o=window.URL,a=o?"blob":"arraybuffer",u=new RSVP.defer,h=new XMLHttpRequest,c=XMLHttpRequest.prototype;"overrideMimeType"in c||Object.defineProperty(c,"overrideMimeType",{value:function(){}}),r&&(h.withCredentials=!0),h.open("GET",e,!0);for(s in n)h.setRequestHeader(s,n[s]);return h.onreadystatechange=i,"blob"==t&&(h.responseType=a),"json"==t&&h.setRequestHeader("Accept","application/json"),"xml"==t&&h.overrideMimeType("text/xml"),h.send(),u.promise},EPUBJS.core.uri=function(e){var t,r,n,i={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:e},s=e.indexOf("://"),o=e.indexOf("?"),a=e.indexOf("#");return-1!=a&&(i.fragment=e.slice(a+1),e=e.slice(0,a)),-1!=o&&(i.search=e.slice(o+1),e=e.slice(0,o),href=e),-1!=s?(i.protocol=e.slice(0,s),t=e.slice(s+3),n=t.indexOf("/"),-1===n?(i.host=i.path,i.path=""):(i.host=t.slice(0,n),i.path=t.slice(n)),i.origin=i.protocol+"://"+i.host,i.directory=EPUBJS.core.folder(i.path),i.base=i.origin+i.directory):(i.path=e,i.directory=EPUBJS.core.folder(e),i.base=i.directory),i.filename=e.replace(i.base,""),r=i.filename.lastIndexOf("."),-1!=r&&(i.extension=i.filename.slice(r+1)),i},EPUBJS.core.folder=function(e){var t=e.lastIndexOf("/");if(-1==t)var r="";return r=e.slice(0,t+1)},EPUBJS.core.queue=function(e){var t=[],r=e,n=function(e,r,n){return t.push({funcName:e,args:r,context:n}),t},i=function(){var e;t.length&&(e=t.shift(),r[e.funcName].apply(e.context||r,e.args))},s=function(){for(;t.length;)i()},o=function(){t=[]},a=function(){return t.length};return{enqueue:n,dequeue:i,flush:s,clear:o,length:a}},EPUBJS.core.isElement=function(e){return!(!e||1!=e.nodeType)},EPUBJS.core.uuid=function(){var e=(new Date).getTime(),t="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){var r=(e+16*Math.random())%16|0;return e=Math.floor(e/16),("x"==t?r:7&r|8).toString(16)});return t},EPUBJS.core.values=function(e){for(var t=-1,r=Object.keys(e),n=r.length,i=Array(n);++t0;){if(r=n.shift(),"text"===r.type?(i=o.childNodes[r.index],o=i.parentNode||o):o=r.id?s.getElementById(r.id):a[r.index],"undefined"==typeof o)return console.error("No Element For",r,e.str),!1;a=Array.prototype.slice.call(o.children)}return o},EPUBJS.EpubCFI.prototype.compare=function(e,t){if("string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),"string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),e.spinePos>t.spinePos)return 1;if(e.spinePost.steps[r].index)return 1;if(e.steps[r].indext.characterOffset?1:e.characterOffset=0?(s=i.length,e.characterOffsetr?this.hooks[r].apply(this.context,i):void 0}.bind(this))):(e=n.promise,n.resolve()),e},EPUBJS.Infinite=function(e,t){this.container=e,this.windowHeight=window.innerHeight,this.tick=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,this.scrolled=!1,this.ignore=!1,this.displaying=!1,this.offset=350,this.views=[],this.renderer=t,this.prevScrollTop=0},EPUBJS.Infinite.prototype.start=function(){this.container.addEventListener("scroll",function(){this.ignore?this.ignore=!1:this.scrolled=!0}.bind(this)),window.addEventListener("unload",function(){this.ignore=!0}),this.tick.call(window,this.check.bind(this)),this.scrolled=!1},EPUBJS.Infinite.prototype.forwards=function(){this.trigger("forwards")},EPUBJS.Infinite.prototype.backwards=function(){this.trigger("backwards")},EPUBJS.Infinite.prototype.check=function(){if(this.scrolled&&!this.displaying){var e=this.container.scrollTop,t=(this.container.scrollLeft,this.container.scrollHeight),r=(this.container.scrollWidth,e-this.prevScrollTop),n=this.container.getBoundingClientRect().height,i=e+this.offset>t-n,s=e0?this.forwards():s&&0>r&&this.backwards(),this.prevScrollTop=e,this.scrolled=!1}else this.displaying=!1,this.scrolled=!1;this.tick.call(window,this.check.bind(this))},EPUBJS.Infinite.prototype.scrollBy=function(e,t,r){r&&(this.displaying=!0),this.container.scrollLeft+=e,this.container.scrollTop+=t},EPUBJS.Infinite.prototype.scroll=function(e,t,r){r&&(this.displaying=!0),this.container.scrollLeft=e,this.container.scrollTop=t},RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype),EPUBJS.Layout=function(){},EPUBJS.Layout.prototype.reconcileLayoutSettings=function(e,t){var r={};for(var n in e)e.hasOwnProperty(n)&&(r[n]=e[n]);return t.forEach(function(e){var t,n,i=e.replace("rendition:",""),s=i.indexOf("-");-1!=s&&(t=i.slice(0,s),n=i.slice(s+1),r[t]=n)}),r},EPUBJS.Layout.prototype.determineLayout=function(e){var t=this.determineSpreads(this.minSpreadWidth),r=t?"ReflowableSpreads":"Reflowable",n=!1;return"pre-paginated"===e.layout&&(r="Fixed",n=!0,t=!1),"reflowable"===e.layout&&"none"===e.spread&&(r="Reflowable",n=!1,t=!1),"reflowable"===e.layout&&"both"===e.spread&&(r="ReflowableSpreads",n=!1,t=!0),this.spreads=t,this.render.scroll(n),this.trigger("renderer:spreads",t),r},EPUBJS.Layout.prototype.applyStyles=function(e){for(var t in e)for(var r in this.views)r.setStyle(t,e[t])},EPUBJS.Layout.prototype.setStyle=function(e,t,r){for(var n in this.views)n.setStyle(e,t,r)},EPUBJS.Layout.prototype.removeStyle=function(e){for(var t in this.views)t.removeStyle(e)},EPUBJS.Layout.prototype.applyHeadTags=function(e){for(var t in e)this.render.addHeadTag(t,e[t])},EPUBJS.Navigation=function(e,t){var r=this,n=new EPUBJS.Parser,i=t||EPUBJS.core.request;this.package=e,this.toc=[],this.tocByHref={},this.tocById={},e.navPath&&(this.navUrl=e.baseUrl+e.navPath,this.nav={},this.nav.load=function(){var e=new RSVP.defer,t=e.promise;return i(r.navUrl,"xml").then(function(t){r.toc=n.nav(t),r.loaded(r.toc),e.resolve(r.toc)}),t}),e.ncxPath&&(this.ncxUrl=e.baseUrl+e.ncxPath,this.ncx={},this.ncx.load=function(){var e=new RSVP.defer,t=e.promise;return i(r.ncxUrl,"xml").then(function(t){r.toc=n.ncx(t),r.loaded(r.toc),e.resolve(r.toc)}),t})},EPUBJS.Navigation.prototype.load=function(e){{var t,r;e||EPUBJS.core.request}return this.nav?t=this.nav.load():this.ncx?t=this.ncx.load():(r=new RSVP.defer,r.resolve([]),t=r.promise),t},EPUBJS.Navigation.prototype.loaded=function(e){for(var t,r=0;r=0;o--){var a=i.snapshotItem(o),u=a.getAttribute("id")||!1,h=a.querySelector("content"),c=h.getAttribute("src"),p=a.querySelector("navLabel"),l=p.textContent?p.textContent:"",d=c.split("#"),f=(d[0],t(a));n.unshift({id:u,href:c,label:l,subitems:f,parent:r?r.getAttribute("id"):null})}return n}var r=e.querySelector("navMap");return r?t(r):[]},EPUBJS.Renderer=function(e,t){var r=t||{};this.settings={hidden:r.hidden||!1,viewsLimit:6,width:r.width||!1,height:r.height||!1},this.book=e,this.epubcfi=new EPUBJS.EpubCFI,this.layoutSettings={},this._q=EPUBJS.core.queue(this),this.position=1,this.initialize({width:this.settings.width,height:this.settings.height}),this.rendering=!1,this.views=[],this.positions=[],this.hooks={},this.hooks.display=new EPUBJS.Hook(this),this.hooks.replacements=new EPUBJS.Hook(this)},EPUBJS.Renderer.prototype.initialize=function(e){{var t=e||{},r=t.height?t.height+"px":"100%",n=t.width?t.width+"px":"100%";t.hidden||!1}return this.container=document.createElement("div"),this.infinite=new EPUBJS.Infinite(this.container,this),this.container.style.width=n,this.container.style.height=r,this.container.style.overflow="scroll",t.hidden?(this.wrapper=document.createElement("div"),this.wrapper.style.visibility="hidden",this.wrapper.style.overflow="hidden",this.wrapper.style.width="0",this.wrapper.style.height="0",this.wrapper.appendChild(this.container),this.wrapper):this.container},EPUBJS.Renderer.prototype.resize=function(e,t){var r=e,n=t;
-e||(r=window.innerWidth),t||(n=window.innerHeight),this.container.style.width=r+"px",this.container.style.height=n+"px",this.trigger("resized",{width:this.width,height:this.height})},EPUBJS.Renderer.prototype.onResized=function(){var e=this.element.getBoundingClientRect();this.resize(e.width,e.height)},EPUBJS.Renderer.prototype.attachTo=function(e){var t;return EPUBJS.core.isElement(e)?this.element=e:"string"==typeof e&&(this.element=document.getElementById(e)),this.element?(this.element.appendChild(this.container),this.settings.height||this.settings.width||(t=this.element.getBoundingClientRect(),this.resize(t.width,t.height)),this.infinite.start(),this.infinite.on("forwards",function(){var e=this.last().section.index+1;!this.rendering&&e0&&this.backwards()}.bind(this)),window.addEventListener("resize",this.onResized.bind(this),!1),void this.hooks.replacements.register(this.replacements.bind(this))):void console.error("Not an Element")},EPUBJS.Renderer.prototype.clear=function(){this.views.forEach(function(e){e.destroy()}),this.views=[]},EPUBJS.Renderer.prototype.display=function(e){var t=new RSVP.defer,r=t.promise;return this.clear(),this.book.opened.then(function(){var r,n=this.book.spine.get(e);n?(r=this.render(n),r.then(this.fill.bind(this)).then(function(){t.resolve(this)}.bind(this))):t.reject(new Error("No Section Found"))}.bind(this)),r},EPUBJS.Renderer.prototype.render=function(e){var t,r;return e?(r=new EPUBJS.View(e),this.insert(r,e.index),t=r.render(this.book.request),t.then(function(){return this.hooks.display.trigger(r)}.bind(this)).then(function(){return this.hooks.replacements.trigger(r,this)}.bind(this)).then(function(){return this.rendering=!1,r.show(),r}.bind(this)).catch(function(e){this.trigger("loaderror",e)}.bind(this))):(t=new RSVP.defer,t.reject(new Error("No Section Provided")),t.promise)},EPUBJS.Renderer.prototype.forwards=function(){var e,t,r;return e=this.last().section.index+1,this.rendering||e===this.book.spine.length?(t=new RSVP.defer,t.reject(new Error("Reject Forwards")),t.promise):(this.rendering=!0,r=this.book.spine.get(e),t=this.render(r),t.then(function(){var e=this.first(),t=e.bounds(),r=this.container.scrollTop;this.views.length>this.settings.viewsLimit&&(this.remove(e),this.infinite.scroll(0,r-t.height,!0))}.bind(this)),t)},EPUBJS.Renderer.prototype.backwards=function(){var e,t,r;return e=this.first().section.index-1,this.rendering||0>e?(t=new RSVP.defer,t.reject(new Error("Reject Backwards")),t.promise):(this.rendering=!0,r=this.book.spine.get(e),t=this.render(r),t.then(function(){this.infinite.scrollBy(0,this.first().height,!0),this.views.length>this.settings.viewsLimit&&(last=this.last(),this.remove(last))}.bind(this)),t)},EPUBJS.Renderer.prototype.fill=function(){var e=this.container.getBoundingClientRect().height,t=function(){var r=this.last().bounds().bottom,n=new RSVP.defer;return e&&r&&e>r?this.forwards().then(t):(this.rendering=!1,n.resolve(),n.promise)}.bind(this),r=this.first().section.index-1,n=t();return r>0&&n.then(this.backwards.bind(this)),n.then(function(){this.rendering=!1}.bind(this))},EPUBJS.Renderer.prototype.append=function(e){this.views.push(e),e.appendTo(this.container)},EPUBJS.Renderer.prototype.prepend=function(e){this.views.unshift(e),e.prependTo(this.container)},EPUBJS.Renderer.prototype.insert=function(e,t){this.first()?t-this.first().section.index>=0?this.append(e):t-this.last().section.index<=0&&this.prepend(e):this.append(e)},EPUBJS.Renderer.prototype.remove=function(e){var t=this.views.indexOf(e);e.destroy(),t>-1&&this.views.splice(t,1)},EPUBJS.Renderer.prototype.first=function(){return this.views[0]},EPUBJS.Renderer.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Renderer.prototype.replacements=function(e,t){for(var r=new RSVP.defer,n=e.document.querySelectorAll("a[href]"),i=function(e){var r=e.getAttribute("href"),n=r.search("://");-1!=n?e.setAttribute("target","_blank"):e.onclick=function(){return t.display(r),!1}},s=0;s-1?(delete this.spineByHref[e.href],delete this.spineById[e.idref],this.spineItems.splice(t,1)):void 0},EPUBJS.View=function(e){this.id="epubjs-view:"+EPUBJS.core.uuid(),this.rendering=new RSVP.defer,this.rendered=this.rendering.promise,this.iframe=this.create(),this.section=e},EPUBJS.View.prototype.create=function(){return this.iframe=document.createElement("iframe"),this.iframe.id=this.id,this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.resizing=!0,this.iframe.width="100%",this.iframe.style.height="100%",this.iframe.style.display="none",this.iframe.style.visibility="hidden",this.iframe},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:this.layout()},EPUBJS.View.prototype.render=function(e){return this.section.render(e).then(function(e){return this.load(e)}.bind(this)).then(this.display.bind(this)).then(function(){this.rendering.resolve(this)}.bind(this))},EPUBJS.View.prototype.load=function(e){var t=new RSVP.defer,r=t.promise;return this.document=this.iframe.contentDocument,this.iframe.addEventListener("load",function(){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,t.resolve(this)}.bind(this)),this.document.open(),this.document.write(e),this.document.close(),r},EPUBJS.View.prototype.display=function(){var e=new RSVP.defer,t=e.promise;return this.iframe.style.display="block",this.document.body.style.margin="0",this.document.body.style.display="inline-block",this.document.body.style.padding="0 20px 20px 20px",setTimeout(function(){this.window.addEventListener("resize",this.resized.bind(this),!1)}.bind(this),10),"loading"!==this.document.fonts.status?(this.layout(),e.resolve(this)):this.document.fonts.onloading=function(){this.layout(),e.resolve(this)}.bind(this),t},EPUBJS.View.prototype.layout=function(){var e;e=this.document.body.getBoundingClientRect(),(!e||0==e.height&&0==e.width)&&console.error("View not shown"),this.resizing=!0,this.iframe.style.height=e.height+"px",this.width=e.width,this.height=e.height},EPUBJS.View.prototype.observe=function(e){var t=this,r=new MutationObserver(function(e){e.forEach(function(){t.layout()})}),n={attributes:!0,childList:!0,characterData:!0,subtree:!0};return r.observe(e,n),r},EPUBJS.View.prototype.appendTo=function(e){this.element=e,this.element.appendChild(this.iframe)},EPUBJS.View.prototype.prependTo=function(e){this.element=e,e.insertBefore(this.iframe,e.firstChild)},EPUBJS.View.prototype.bounds=function(){return this.iframe.getBoundingClientRect()},EPUBJS.View.prototype.show=function(){this.iframe.style.display="block",this.iframe.style.visibility="visible"},EPUBJS.View.prototype.hide=function(){this.iframe.style.display="none",this.iframe.style.visibility="hidden"},EPUBJS.View.prototype.destroy=function(){this.element.removeChild(this.iframe)};
\ No newline at end of file
+"undefined"==typeof EPUBJS&&(("undefined"!=typeof window?window:this).EPUBJS={}),EPUBJS.VERSION="0.3.0",EPUBJS.Render={},function(t){"use strict";var e=function(t){return new EPUBJS.Book(t)};e.Render={register:function(t,r){e.Render[t]=r}},"object"==typeof exports?(t.RSVP=require("rsvp"),module.exports=e):"function"==typeof define&&define.amd?define(e):t.ePub=e}(this),function(t){var e,r;!function(){var t={},i={};e=function(e,r,i){t[e]={deps:r,callback:i}},r=function(e){function n(t){if("."!==t.charAt(0))return t;for(var r=t.split("/"),i=e.split("/").slice(0,-1),n=0,s=r.length;s>n;n++){var o=r[n];if(".."===o)i.pop();else{if("."===o)continue;i.push(o)}}return i.join("/")}if(i[e])return i[e];if(i[e]={},!t[e])throw new Error("Could not find module "+e);for(var s,o=t[e],a=o.deps,h=o.callback,u=[],c=0,p=a.length;p>c;c++)u.push("exports"===a[c]?s={}:r(n(a[c])));var l=h.apply(this,u);return i[e]=s||l},r.entries=t}(),e("rsvp/-internal",["./utils","./instrument","./config","exports"],function(t,e,r,i){"use strict";function n(){}function s(t){try{return t.then}catch(e){return U.error=e,U}}function o(t,e,r,i){try{t.call(e,r,i)}catch(n){return n}}function a(t,e,r){w.async(function(t){var i=!1,n=o(r,e,function(r){i||(i=!0,e!==r?c(t,r):l(t,r))},function(e){i||(i=!0,d(t,e))},"Settle: "+(t._label||" unknown promise"));!i&&n&&(i=!0,d(t,n))},t)}function h(t,e){t._onerror=null,e._state===x?l(t,e._result):t._state===B?d(t,e._result):f(e,void 0,function(r){e!==r?c(t,r):l(t,r)},function(e){d(t,e)})}function u(t,e){if(e instanceof t.constructor)h(t,e);else{var r=s(e);r===U?d(t,U.error):void 0===r?l(t,e):S(r)?a(t,e,r):l(t,e)}}function c(t,e){t===e?l(t,e):P(e)?u(t,e):l(t,e)}function p(t){t._onerror&&t._onerror(t._result),m(t)}function l(t,e){t._state===_&&(t._result=e,t._state=x,0===t._subscribers.length?w.instrument&&E("fulfilled",t):w.async(m,t))}function d(t,e){t._state===_&&(t._state=B,t._result=e,w.async(p,t))}function f(t,e,r,i){var n=t._subscribers,s=n.length;t._onerror=null,n[s]=e,n[s+x]=r,n[s+B]=i,0===s&&t._state&&w.async(m,t)}function m(t){var e=t._subscribers,r=t._state;if(w.instrument&&E(r===x?"fulfilled":"rejected",t),0!==e.length){for(var i,n,s=t._result,o=0;ot;t+=2){var e=p[t],r=p[t+1];e(r),p[t]=void 0,p[t+1]=void 0}o=0}var o=0;t["default"]=function(t,e){p[o]=t,p[o+1]=e,o+=2,2===o&&a()};var a,h="undefined"!=typeof window?window:{},u=h.MutationObserver||h.WebKitMutationObserver,c="undefined"!=typeof Uint8ClampedArray&&"undefined"!=typeof importScripts&&"undefined"!=typeof MessageChannel,p=new Array(1e3);a="undefined"!=typeof process&&"[object process]"==={}.toString.call(process)?e():u?r():c?i():n()}),e("rsvp/config",["./events","exports"],function(t,e){"use strict";function r(t,e){return"onerror"===t?void n.on("error",e):2!==arguments.length?n[t]:void(n[t]=e)}var i=t["default"],n={instrument:!1};i.mixin(n),e.config=n,e.configure=r}),e("rsvp/defer",["./promise","exports"],function(t,e){"use strict";var r=t["default"];e["default"]=function(t){var e={};return e.promise=new r(function(t,r){e.resolve=t,e.reject=r},t),e}}),e("rsvp/enumerator",["./utils","./-internal","exports"],function(t,e,r){"use strict";function i(t,e,r){return t===p?{state:"fulfilled",value:r}:{state:"rejected",reason:r}}function n(t,e,r,i){this._instanceConstructor=t,this.promise=new t(a,i),this._abortOnReject=r,this._validateInput(e)?(this._input=e,this.length=e.length,this._remaining=e.length,this._init(),0===this.length?u(this.promise,this._result):(this.length=this.length||0,this._enumerate(),0===this._remaining&&u(this.promise,this._result))):h(this.promise,this._validationError())}var s=t.isArray,o=t.isMaybeThenable,a=e.noop,h=e.reject,u=e.fulfill,c=e.subscribe,p=e.FULFILLED,l=e.REJECTED,d=e.PENDING,f=!0;r.ABORT_ON_REJECTION=f,r.makeSettledResult=i,n.prototype._validateInput=function(t){return s(t)},n.prototype._validationError=function(){return new Error("Array Methods must be provided an Array")},n.prototype._init=function(){this._result=new Array(this.length)},r["default"]=n,n.prototype._enumerate=function(){for(var t=this.length,e=this.promise,r=this._input,i=0;e._state===d&&t>i;i++)this._eachEntry(r[i],i)},n.prototype._eachEntry=function(t,e){var r=this._instanceConstructor;o(t)?t.constructor===r&&t._state!==d?(t._onerror=null,this._settledAt(t._state,e,t._result)):this._willSettleAt(r.resolve(t),e):(this._remaining--,this._result[e]=this._makeResult(p,e,t))},n.prototype._settledAt=function(t,e,r){var i=this.promise;i._state===d&&(this._remaining--,this._abortOnReject&&t===l?h(i,r):this._result[e]=this._makeResult(t,e,r)),0===this._remaining&&u(i,this._result)},n.prototype._makeResult=function(t,e,r){return r},n.prototype._willSettleAt=function(t,e){var r=this;c(t,void 0,function(t){r._settledAt(p,e,t)},function(t){r._settledAt(l,e,t)})}}),e("rsvp/events",["exports"],function(t){"use strict";function e(t,e){for(var r=0,i=t.length;i>r;r++)if(t[r]===e)return r;return-1}function r(t){var e=t._promiseCallbacks;return e||(e=t._promiseCallbacks={}),e}t["default"]={mixin:function(t){return t.on=this.on,t.off=this.off,t.trigger=this.trigger,t._promiseCallbacks=void 0,t},on:function(t,i){var n,s=r(this);n=s[t],n||(n=s[t]=[]),-1===e(n,i)&&n.push(i)},off:function(t,i){var n,s,o=r(this);return i?(n=o[t],s=e(n,i),void(-1!==s&&n.splice(s,1))):void(o[t]=[])},trigger:function(t,e){var i,n,s=r(this);if(i=s[t])for(var o=0;oa;a++)o[a]=e(t[a]);return i.all(o,r).then(function(e){for(var r=new Array(s),i=0,n=0;s>n;n++)e[n]&&(r[i]=t[n],i++);return r.length=i,r})})}}),e("rsvp/hash-settled",["./promise","./enumerator","./promise-hash","./utils","exports"],function(t,e,r,i,n){"use strict";function s(t,e,r){this._superConstructor(t,e,!1,r)}var o=t["default"],a=e.makeSettledResult,h=r["default"],u=e["default"],c=i.o_create;s.prototype=c(h.prototype),s.prototype._superConstructor=u,s.prototype._makeResult=a,s.prototype._validationError=function(){return new Error("hashSettled must be called with an object")},n["default"]=function(t,e){return new s(o,t,e).promise}}),e("rsvp/hash",["./promise","./promise-hash","./enumerator","exports"],function(t,e,r,i){"use strict";{var n=t["default"],s=e["default"];r.ABORT_ON_REJECTION}i["default"]=function(t,e){return new s(n,t,e).promise}}),e("rsvp/instrument",["./config","./utils","exports"],function(t,e,r){"use strict";var i=t.config,n=e.now,s=[];r["default"]=function(t,e,r){1===s.push({name:t,payload:{guid:e._guidKey+e._id,eventName:t,detail:e._result,childGuid:r&&e._guidKey+r._id,label:e._label,timeStamp:n(),stack:new Error(e._label).stack}})&&setTimeout(function(){for(var t,e=0;ea;a++)o[a]=e(t[a]);return i.all(o,r)})}}),e("rsvp/node",["./promise","./utils","exports"],function(t,e,r){"use strict";var i=t["default"],n=e.isArray;r["default"]=function(t,e){function r(){for(var r=arguments.length,n=new Array(r),a=0;r>a;a++)n[a]=arguments[a];var h;return s||o||!e?h=this:("object"==typeof console&&console.warn('Deprecation: RSVP.denodeify() doesn\'t allow setting the "this" binding anymore. Use yourFunction.bind(yourThis) instead.'),h=e),i.all(n).then(function(r){function n(i,n){function a(){for(var t=arguments.length,r=new Array(t),a=0;t>a;a++)r[a]=arguments[a];var h=r[0],u=r[1];if(h)n(h);else if(s)i(r.slice(1));else if(o){var c,p,l={},d=r.slice(1);for(p=0;pa;a++)s=r[a],this._eachEntry(s.entry,s.position)}}),e("rsvp/promise",["./config","./events","./instrument","./utils","./-internal","./promise/cast","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"],function(t,e,r,i,n,s,o,a,h,u,c){"use strict";function p(){throw new TypeError("You must pass a resolver function as the first argument to the promise constructor")}function l(){throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.")}function d(t,e){this._id=R++,this._label=e,this._subscribers=[],f.instrument&&m("created",this),v!==t&&(g(t)||p(),this instanceof d||l(),P(this,t))}var f=t.config,m=(e["default"],r["default"]),g=(i.objectOrFunction,i.isFunction),y=i.now,v=n.noop,b=(n.resolve,n.reject,n.fulfill,n.subscribe),P=n.initializePromise,S=n.invokeCallback,E=n.FULFILLED,w=s["default"],_=o["default"],x=a["default"],B=h["default"],U=u["default"],J="rsvp_"+y()+"-",R=0;c["default"]=d,d.cast=w,d.all=_,d.race=x,d.resolve=B,d.reject=U,d.prototype={constructor:d,_id:void 0,_guidKey:J,_label:void 0,_state:void 0,_result:void 0,_subscribers:void 0,_onerror:function(t){f.trigger("error",t)},then:function(t,e,r){var i=this;i._onerror=null;var n=new this.constructor(v,r),s=i._state,o=i._result;return f.instrument&&m("chained",i,n),s===E&&t?f.async(function(){S(s,n,t,o)}):b(i,n,t,e),n},"catch":function(t,e){return this.then(null,t,e)},"finally":function(t,e){var r=this.constructor;return this.then(function(e){return r.resolve(t()).then(function(){return e})},function(e){return r.resolve(t()).then(function(){throw e})},e)}}}),e("rsvp/promise/all",["../enumerator","exports"],function(t,e){"use strict";var r=t["default"];e["default"]=function(t,e){return new r(this,t,!0,e).promise}}),e("rsvp/promise/cast",["./resolve","exports"],function(t,e){"use strict";var r=t["default"];e["default"]=r}),e("rsvp/promise/race",["../utils","../-internal","exports"],function(t,e,r){"use strict";var i=t.isArray,n=(t.isFunction,t.isMaybeThenable,e.noop),s=e.resolve,o=e.reject,a=e.subscribe,h=e.PENDING;r["default"]=function(t,e){function r(t){s(p,t)}function u(t){o(p,t)}var c=this,p=new c(n,e);if(!i(t))return o(p,new TypeError("You must pass an array to race.")),p;for(var l=t.length,d=0;p._state===h&&l>d;d++)a(c.resolve(t[d]),void 0,r,u);return p}}),e("rsvp/promise/reject",["../-internal","exports"],function(t,e){"use strict";var r=t.noop,i=t.reject;e["default"]=function(t,e){var n=this,s=new n(r,e);return i(s,t),s}}),e("rsvp/promise/resolve",["../-internal","exports"],function(t,e){"use strict";var r=t.noop,i=t.resolve;e["default"]=function(t,e){var n=this;if(t&&"object"==typeof t&&t.constructor===n)return t;var s=new n(r,e);return i(s,t),s}}),e("rsvp/race",["./promise","exports"],function(t,e){"use strict";var r=t["default"];e["default"]=function(t,e){return r.race(t,e)}}),e("rsvp/reject",["./promise","exports"],function(t,e){"use strict";var r=t["default"];e["default"]=function(t,e){return r.reject(t,e)}}),e("rsvp/resolve",["./promise","exports"],function(t,e){"use strict";var r=t["default"];e["default"]=function(t,e){return r.resolve(t,e)}}),e("rsvp/rethrow",["exports"],function(t){"use strict";t["default"]=function(t){throw setTimeout(function(){throw t}),t}}),e("rsvp/utils",["exports"],function(t){"use strict";function e(t){return"function"==typeof t||"object"==typeof t&&null!==t}function r(t){return"function"==typeof t}function i(t){return"object"==typeof t&&null!==t}t.objectOrFunction=e,t.isFunction=r,t.isMaybeThenable=i;var n;n=Array.isArray?Array.isArray:function(t){return"[object Array]"===Object.prototype.toString.call(t)};var s=n;t.isArray=s;var o=Date.now||function(){return(new Date).getTime()};t.now=o;var a=Object.create||function(t){var e=function(){};return e.prototype=t,e};t.o_create=a}),e("rsvp",["./rsvp/promise","./rsvp/events","./rsvp/node","./rsvp/all","./rsvp/all-settled","./rsvp/race","./rsvp/hash","./rsvp/hash-settled","./rsvp/rethrow","./rsvp/defer","./rsvp/config","./rsvp/map","./rsvp/resolve","./rsvp/reject","./rsvp/filter","./rsvp/asap","exports"],function(t,e,r,i,n,s,o,a,h,u,c,p,l,d,f,m,g){"use strict";function y(t,e){A.async(t,e)}function v(){A.on.apply(A,arguments)}function b(){A.off.apply(A,arguments)}var P=t["default"],S=e["default"],E=r["default"],w=i["default"],_=n["default"],x=s["default"],B=o["default"],U=a["default"],J=h["default"],R=u["default"],A=c.config,I=c.configure,C=p["default"],k=l["default"],F=d["default"],T=f["default"],N=m["default"];if(A.async=N,"undefined"!=typeof window&&"object"==typeof window.__PROMISE_INSTRUMENTATION__){var q=window.__PROMISE_INSTRUMENTATION__;I("instrument",!0);for(var O in q)q.hasOwnProperty(O)&&v(O,q[O])}g.Promise=P,g.EventTarget=S,g.all=w,g.allSettled=_,g.race=x,g.hash=B,g.hashSettled=U,g.rethrow=J,g.defer=R,g.denodeify=E,g.configure=I,g.on=v,g.off=b,g.resolve=k,g.reject=F,g.async=y,g.map=C,g.filter=T}),t.RSVP=r("rsvp")}(self),function(t,e){"use strict";"object"==typeof exports?module.exports=e(require("./punycode"),require("./IPv6"),require("./SecondLevelDomains")):"function"==typeof define&&define.amd?define(["./punycode","./IPv6","./SecondLevelDomains"],e):t.URI=e(t.punycode,t.IPv6,t.SecondLevelDomains,t)}(this,function(t,e,r,i){"use strict";function n(t,e){return this instanceof n?(void 0===t&&(t="undefined"!=typeof location?location.href+"":""),this.href(t),void 0!==e?this.absoluteTo(e):this):new n(t,e)}function s(t){return t.replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")}function o(t){return void 0===t?"Undefined":String(Object.prototype.toString.call(t)).slice(8,-1)}function a(t){return"Array"===o(t)}function h(t,e){var r,i,n={};if(a(e))for(r=0,i=e.length;i>r;r++)n[e[r]]=!0;else n[e]=!0;for(r=0,i=t.length;i>r;r++)void 0!==n[t[r]]&&(t.splice(r,1),i--,r--);return t}function u(t,e){var r,i;if(a(e)){for(r=0,i=e.length;i>r;r++)if(!u(t,e[r]))return!1;return!0}var n=o(e);for(r=0,i=t.length;i>r;r++)if("RegExp"===n){if("string"==typeof t[r]&&t[r].match(e))return!0}else if(t[r]===e)return!0;return!1}function c(t,e){if(!a(t)||!a(e))return!1;if(t.length!==e.length)return!1;t.sort(),e.sort();for(var r=0,i=t.length;i>r;r++)if(t[r]!==e[r])return!1;return!0}function p(t){return escape(t)}function l(t){return encodeURIComponent(t).replace(/[!'()*]/g,p).replace(/\*/g,"%2A")}var d=i&&i.URI;n.version="1.13.2";var f=n.prototype,m=Object.prototype.hasOwnProperty;n._parts=function(){return{protocol:null,username:null,password:null,hostname:null,urn:null,port:null,path:null,query:null,fragment:null,duplicateQueryParameters:n.duplicateQueryParameters,escapeQuerySpace:n.escapeQuerySpace}},n.duplicateQueryParameters=!1,n.escapeQuerySpace=!0,n.protocol_expression=/^[a-z][a-z0-9.+-]*$/i,n.idn_expression=/[^a-z0-9\.-]/i,n.punycode_expression=/(xn--)/i,n.ip4_expression=/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/,n.ip6_expression=/^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))(%.+)?\s*$/,n.find_uri_expression=/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/gi,n.findUri={start:/\b(?:([a-z][a-z0-9.+-]*:\/\/)|www\.)/gi,end:/[\s\r\n]|$/,trim:/[`!()\[\]{};:'".,<>?«»“”„‘’]+$/},n.defaultPorts={http:"80",https:"443",ftp:"21",gopher:"70",ws:"80",wss:"443"},n.invalid_hostname_characters=/[^a-zA-Z0-9\.-]/,n.domAttributes={a:"href",blockquote:"cite",link:"href",base:"href",script:"src",form:"action",img:"src",area:"href",iframe:"src",embed:"src",source:"src",track:"src",input:"src"},n.getDomAttribute=function(t){if(!t||!t.nodeName)return void 0;var e=t.nodeName.toLowerCase();return"input"===e&&"image"!==t.type?void 0:n.domAttributes[e]},n.encode=l,n.decode=decodeURIComponent,n.iso8859=function(){n.encode=escape,n.decode=unescape},n.unicode=function(){n.encode=l,n.decode=decodeURIComponent},n.characters={pathname:{encode:{expression:/%(24|26|2B|2C|3B|3D|3A|40)/gi,map:{"%24":"$","%26":"&","%2B":"+","%2C":",","%3B":";","%3D":"=","%3A":":","%40":"@"}},decode:{expression:/[\/\?#]/g,map:{"/":"%2F","?":"%3F","#":"%23"}}},reserved:{encode:{expression:/%(21|23|24|26|27|28|29|2A|2B|2C|2F|3A|3B|3D|3F|40|5B|5D)/gi,map:{"%3A":":","%2F":"/","%3F":"?","%23":"#","%5B":"[","%5D":"]","%40":"@","%21":"!","%24":"$","%26":"&","%27":"'","%28":"(","%29":")","%2A":"*","%2B":"+","%2C":",","%3B":";","%3D":"="}}}},n.encodeQuery=function(t,e){var r=n.encode(t+"");return void 0===e&&(e=n.escapeQuerySpace),e?r.replace(/%20/g,"+"):r},n.decodeQuery=function(t,e){t+="",void 0===e&&(e=n.escapeQuerySpace);try{return n.decode(e?t.replace(/\+/g,"%20"):t)}catch(r){return t}},n.recodePath=function(t){for(var e=(t+"").split("/"),r=0,i=e.length;i>r;r++)e[r]=n.encodePathSegment(n.decode(e[r]));return e.join("/")},n.decodePath=function(t){for(var e=(t+"").split("/"),r=0,i=e.length;i>r;r++)e[r]=n.decodePathSegment(e[r]);return e.join("/")};var g,y={encode:"encode",decode:"decode"},v=function(t,e){return function(r){return n[e](r+"").replace(n.characters[t][e].expression,function(r){return n.characters[t][e].map[r]})}};for(g in y)n[g+"PathSegment"]=v("pathname",y[g]);n.encodeReserved=v("reserved","encode"),n.parse=function(t,e){var r;return e||(e={}),r=t.indexOf("#"),r>-1&&(e.fragment=t.substring(r+1)||null,t=t.substring(0,r)),r=t.indexOf("?"),r>-1&&(e.query=t.substring(r+1)||null,t=t.substring(0,r)),"//"===t.substring(0,2)?(e.protocol=null,t=t.substring(2),t=n.parseAuthority(t,e)):(r=t.indexOf(":"),r>-1&&(e.protocol=t.substring(0,r)||null,e.protocol&&!e.protocol.match(n.protocol_expression)?e.protocol=void 0:"file"===e.protocol?t=t.substring(r+3):"//"===t.substring(r+1,r+3)?(t=t.substring(r+3),t=n.parseAuthority(t,e)):(t=t.substring(r+1),e.urn=!0))),e.path=t,e},n.parseHost=function(t,e){var r,i,n=t.indexOf("/");return-1===n&&(n=t.length),"["===t.charAt(0)?(r=t.indexOf("]"),e.hostname=t.substring(1,r)||null,e.port=t.substring(r+2,n)||null,"/"===e.port&&(e.port=null)):t.indexOf(":")!==t.lastIndexOf(":")?(e.hostname=t.substring(0,n)||null,e.port=null):(i=t.substring(0,n).split(":"),e.hostname=i[0]||null,e.port=i[1]||null),e.hostname&&"/"!==t.substring(n).charAt(0)&&(n++,t="/"+t),t.substring(n)||"/"},n.parseAuthority=function(t,e){return t=n.parseUserinfo(t,e),n.parseHost(t,e)},n.parseUserinfo=function(t,e){var r,i=t.indexOf("/"),s=i>-1?t.lastIndexOf("@",i):t.indexOf("@");return s>-1&&(-1===i||i>s)?(r=t.substring(0,s).split(":"),e.username=r[0]?n.decode(r[0]):null,r.shift(),e.password=r[0]?n.decode(r.join(":")):null,t=t.substring(s+1)):(e.username=null,e.password=null),t},n.parseQuery=function(t,e){if(!t)return{};if(t=t.replace(/&+/g,"&").replace(/^\?*&*|&+$/g,""),!t)return{};for(var r,i,s,o={},a=t.split("&"),h=a.length,u=0;h>u;u++)r=a[u].split("="),i=n.decodeQuery(r.shift(),e),s=r.length?n.decodeQuery(r.join("="),e):null,o[i]?("string"==typeof o[i]&&(o[i]=[o[i]]),o[i].push(s)):o[i]=s;return o},n.build=function(t){var e="";return t.protocol&&(e+=t.protocol+":"),t.urn||!e&&!t.hostname||(e+="//"),e+=n.buildAuthority(t)||"","string"==typeof t.path&&("/"!==t.path.charAt(0)&&"string"==typeof t.hostname&&(e+="/"),e+=t.path),"string"==typeof t.query&&t.query&&(e+="?"+t.query),"string"==typeof t.fragment&&t.fragment&&(e+="#"+t.fragment),e},n.buildHost=function(t){var e="";return t.hostname?(e+=n.ip6_expression.test(t.hostname)?"["+t.hostname+"]":t.hostname,t.port&&(e+=":"+t.port),e):""},n.buildAuthority=function(t){return n.buildUserinfo(t)+n.buildHost(t)},n.buildUserinfo=function(t){var e="";return t.username&&(e+=n.encode(t.username),t.password&&(e+=":"+n.encode(t.password)),e+="@"),e},n.buildQuery=function(t,e,r){var i,s,o,h,u="";for(s in t)if(m.call(t,s)&&s)if(a(t[s]))for(i={},o=0,h=t[s].length;h>o;o++)void 0!==t[s][o]&&void 0===i[t[s][o]+""]&&(u+="&"+n.buildQueryParameter(s,t[s][o],r),e!==!0&&(i[t[s][o]+""]=!0));else void 0!==t[s]&&(u+="&"+n.buildQueryParameter(s,t[s],r));return u.substring(1)},n.buildQueryParameter=function(t,e,r){return n.encodeQuery(t,r)+(null!==e?"="+n.encodeQuery(e,r):"")},n.addQuery=function(t,e,r){if("object"==typeof e)for(var i in e)m.call(e,i)&&n.addQuery(t,i,e[i]);else{if("string"!=typeof e)throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");if(void 0===t[e])return void(t[e]=r);"string"==typeof t[e]&&(t[e]=[t[e]]),a(r)||(r=[r]),t[e]=t[e].concat(r)}},n.removeQuery=function(t,e,r){var i,s,o;if(a(e))for(i=0,s=e.length;s>i;i++)t[e[i]]=void 0;else if("object"==typeof e)for(o in e)m.call(e,o)&&n.removeQuery(t,o,e[o]);else{if("string"!=typeof e)throw new TypeError("URI.addQuery() accepts an object, string as the first parameter");void 0!==r?t[e]===r?t[e]=void 0:a(t[e])&&(t[e]=h(t[e],r)):t[e]=void 0}},n.hasQuery=function(t,e,r,i){if("object"==typeof e){for(var s in e)if(m.call(e,s)&&!n.hasQuery(t,s,e[s]))return!1;return!0}if("string"!=typeof e)throw new TypeError("URI.hasQuery() accepts an object, string as the name parameter");switch(o(r)){case"Undefined":return e in t;case"Boolean":var h=Boolean(a(t[e])?t[e].length:t[e]);return r===h;case"Function":return!!r(t[e],e,t);case"Array":if(!a(t[e]))return!1;var p=i?u:c;return p(t[e],r);case"RegExp":return a(t[e])?i?u(t[e],r):!1:Boolean(t[e]&&t[e].match(r));case"Number":r=String(r);case"String":return a(t[e])?i?u(t[e],r):!1:t[e]===r;default:throw new TypeError("URI.hasQuery() accepts undefined, boolean, string, number, RegExp, Function as the value parameter")}},n.commonPath=function(t,e){var r,i=Math.min(t.length,e.length);for(r=0;i>r;r++)if(t.charAt(r)!==e.charAt(r)){r--;break}return 1>r?t.charAt(0)===e.charAt(0)&&"/"===t.charAt(0)?"/":"":(("/"!==t.charAt(r)||"/"!==e.charAt(r))&&(r=t.substring(0,r).lastIndexOf("/")),t.substring(0,r+1))},n.withinString=function(t,e,r){r||(r={});var i=r.start||n.findUri.start,s=r.end||n.findUri.end,o=r.trim||n.findUri.trim,a=/[a-z0-9-]=["']?$/i;for(i.lastIndex=0;;){var h=i.exec(t);if(!h)break;var u=h.index;if(r.ignoreHtml){var c=t.slice(Math.max(u-3,0),u);if(c&&a.test(c))continue}var p=u+t.slice(u).search(s),l=t.slice(u,p).replace(o,"");if(!r.ignore||!r.ignore.test(l)){p=u+l.length;var d=e(l,u,p,t);t=t.slice(0,u)+d+t.slice(p),i.lastIndex=u+d.length}}return i.lastIndex=0,t},n.ensureValidHostname=function(e){if(e.match(n.invalid_hostname_characters)){if(!t)throw new TypeError('Hostname "'+e+'" contains characters other than [A-Z0-9.-] and Punycode.js is not available');if(t.toASCII(e).match(n.invalid_hostname_characters))throw new TypeError('Hostname "'+e+'" contains characters other than [A-Z0-9.-]')}},n.noConflict=function(t){if(t){var e={URI:this.noConflict()};return i.URITemplate&&"function"==typeof i.URITemplate.noConflict&&(e.URITemplate=i.URITemplate.noConflict()),i.IPv6&&"function"==typeof i.IPv6.noConflict&&(e.IPv6=i.IPv6.noConflict()),i.SecondLevelDomains&&"function"==typeof i.SecondLevelDomains.noConflict&&(e.SecondLevelDomains=i.SecondLevelDomains.noConflict()),e}return i.URI===this&&(i.URI=d),this},f.build=function(t){return t===!0?this._deferred_build=!0:(void 0===t||this._deferred_build)&&(this._string=n.build(this._parts),this._deferred_build=!1),this},f.clone=function(){return new n(this)},f.valueOf=f.toString=function(){return this.build(!1)._string},y={protocol:"protocol",username:"username",password:"password",hostname:"hostname",port:"port"},v=function(t){return function(e,r){return void 0===e?this._parts[t]||"":(this._parts[t]=e||null,this.build(!r),this)}};for(g in y)f[g]=v(y[g]);y={query:"?",fragment:"#"},v=function(t,e){return function(r,i){return void 0===r?this._parts[t]||"":(null!==r&&(r+="",r.charAt(0)===e&&(r=r.substring(1))),this._parts[t]=r,this.build(!i),this)}};for(g in y)f[g]=v(g,y[g]);y={search:["?","query"],hash:["#","fragment"]},v=function(t,e){return function(r,i){var n=this[t](r,i);return"string"==typeof n&&n.length?e+n:n}};for(g in y)f[g]=v(y[g][1],y[g][0]);f.pathname=function(t,e){if(void 0===t||t===!0){var r=this._parts.path||(this._parts.hostname?"/":"");return t?n.decodePath(r):r}return this._parts.path=t?n.recodePath(t):"/",this.build(!e),this},f.path=f.pathname,f.href=function(t,e){var r;if(void 0===t)return this.toString();this._string="",this._parts=n._parts();var i=t instanceof n,s="object"==typeof t&&(t.hostname||t.path||t.pathname);if(t.nodeName){var o=n.getDomAttribute(t);t=t[o]||"",s=!1}if(!i&&s&&void 0!==t.pathname&&(t=t.toString()),"string"==typeof t)this._parts=n.parse(t,this._parts);else{if(!i&&!s)throw new TypeError("invalid input");var a=i?t._parts:t;for(r in a)m.call(this._parts,r)&&(this._parts[r]=a[r])}return this.build(!e),this},f.is=function(t){var e=!1,i=!1,s=!1,o=!1,a=!1,h=!1,u=!1,c=!this._parts.urn;switch(this._parts.hostname&&(c=!1,i=n.ip4_expression.test(this._parts.hostname),s=n.ip6_expression.test(this._parts.hostname),e=i||s,o=!e,a=o&&r&&r.has(this._parts.hostname),h=o&&n.idn_expression.test(this._parts.hostname),u=o&&n.punycode_expression.test(this._parts.hostname)),t.toLowerCase()){case"relative":return c;case"absolute":return!c;case"domain":case"name":return o;case"sld":return a;case"ip":return e;case"ip4":case"ipv4":case"inet4":return i;case"ip6":case"ipv6":case"inet6":return s;case"idn":return h;case"url":return!this._parts.urn;case"urn":return!!this._parts.urn;case"punycode":return u}return null};var b=f.protocol,P=f.port,S=f.hostname;f.protocol=function(t,e){if(void 0!==t&&t&&(t=t.replace(/:(\/\/)?$/,""),!t.match(n.protocol_expression)))throw new TypeError('Protocol "'+t+"\" contains characters other than [A-Z0-9.+-] or doesn't start with [A-Z]");return b.call(this,t,e)},f.scheme=f.protocol,f.port=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0!==t&&(0===t&&(t=null),t&&(t+="",":"===t.charAt(0)&&(t=t.substring(1)),t.match(/[^0-9]/))))throw new TypeError('Port "'+t+'" contains characters other than [0-9]');return P.call(this,t,e)},f.hostname=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0!==t){var r={};n.parseHost(t,r),t=r.hostname}return S.call(this,t,e)},f.host=function(t,e){return this._parts.urn?void 0===t?"":this:void 0===t?this._parts.hostname?n.buildHost(this._parts):"":(n.parseHost(t,this._parts),this.build(!e),this)},f.authority=function(t,e){return this._parts.urn?void 0===t?"":this:void 0===t?this._parts.hostname?n.buildAuthority(this._parts):"":(n.parseAuthority(t,this._parts),this.build(!e),this)},f.userinfo=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t){if(!this._parts.username)return"";var r=n.buildUserinfo(this._parts);return r.substring(0,r.length-1)}return"@"!==t[t.length-1]&&(t+="@"),n.parseUserinfo(t,this._parts),this.build(!e),this},f.resource=function(t,e){var r;return void 0===t?this.path()+this.search()+this.hash():(r=n.parse(t),this._parts.path=r.path,this._parts.query=r.query,this._parts.fragment=r.fragment,this.build(!e),this)},f.subdomain=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.length-this.domain().length-1;return this._parts.hostname.substring(0,r)||""}var i=this._parts.hostname.length-this.domain().length,o=this._parts.hostname.substring(0,i),a=new RegExp("^"+s(o));return t&&"."!==t.charAt(t.length-1)&&(t+="."),t&&n.ensureValidHostname(t),this._parts.hostname=this._parts.hostname.replace(a,t),this.build(!e),this},f.domain=function(t,e){if(this._parts.urn)return void 0===t?"":this;if("boolean"==typeof t&&(e=t,t=void 0),void 0===t){if(!this._parts.hostname||this.is("IP"))return"";var r=this._parts.hostname.match(/\./g);if(r&&r.length<2)return this._parts.hostname;var i=this._parts.hostname.length-this.tld(e).length-1;return i=this._parts.hostname.lastIndexOf(".",i-1)+1,this._parts.hostname.substring(i)||""}if(!t)throw new TypeError("cannot set domain empty");if(n.ensureValidHostname(t),!this._parts.hostname||this.is("IP"))this._parts.hostname=t;else{var o=new RegExp(s(this.domain())+"$");this._parts.hostname=this._parts.hostname.replace(o,t)}return this.build(!e),this},f.tld=function(t,e){if(this._parts.urn)return void 0===t?"":this;if("boolean"==typeof t&&(e=t,t=void 0),void 0===t){if(!this._parts.hostname||this.is("IP"))return"";var i=this._parts.hostname.lastIndexOf("."),n=this._parts.hostname.substring(i+1);return e!==!0&&r&&r.list[n.toLowerCase()]?r.get(this._parts.hostname)||n:n}var o;if(!t)throw new TypeError("cannot set TLD empty");
+if(t.match(/[^a-zA-Z0-9-]/)){if(!r||!r.is(t))throw new TypeError('TLD "'+t+'" contains characters other than [A-Z0-9]');o=new RegExp(s(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(o,t)}else{if(!this._parts.hostname||this.is("IP"))throw new ReferenceError("cannot set TLD on non-domain host");o=new RegExp(s(this.tld())+"$"),this._parts.hostname=this._parts.hostname.replace(o,t)}return this.build(!e),this},f.directory=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t||t===!0){if(!this._parts.path&&!this._parts.hostname)return"";if("/"===this._parts.path)return"/";var r=this._parts.path.length-this.filename().length-1,i=this._parts.path.substring(0,r)||(this._parts.hostname?"/":"");return t?n.decodePath(i):i}var o=this._parts.path.length-this.filename().length,a=this._parts.path.substring(0,o),h=new RegExp("^"+s(a));return this.is("relative")||(t||(t="/"),"/"!==t.charAt(0)&&(t="/"+t)),t&&"/"!==t.charAt(t.length-1)&&(t+="/"),t=n.recodePath(t),this._parts.path=this._parts.path.replace(h,t),this.build(!e),this},f.filename=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t||t===!0){if(!this._parts.path||"/"===this._parts.path)return"";var r=this._parts.path.lastIndexOf("/"),i=this._parts.path.substring(r+1);return t?n.decodePathSegment(i):i}var o=!1;"/"===t.charAt(0)&&(t=t.substring(1)),t.match(/\.?\//)&&(o=!0);var a=new RegExp(s(this.filename())+"$");return t=n.recodePath(t),this._parts.path=this._parts.path.replace(a,t),o?this.normalizePath(e):this.build(!e),this},f.suffix=function(t,e){if(this._parts.urn)return void 0===t?"":this;if(void 0===t||t===!0){if(!this._parts.path||"/"===this._parts.path)return"";var r,i,o=this.filename(),a=o.lastIndexOf(".");return-1===a?"":(r=o.substring(a+1),i=/^[a-z0-9%]+$/i.test(r)?r:"",t?n.decodePathSegment(i):i)}"."===t.charAt(0)&&(t=t.substring(1));var h,u=this.suffix();if(u)h=new RegExp(t?s(u)+"$":s("."+u)+"$");else{if(!t)return this;this._parts.path+="."+n.recodePath(t)}return h&&(t=n.recodePath(t),this._parts.path=this._parts.path.replace(h,t)),this.build(!e),this},f.segment=function(t,e,r){var i=this._parts.urn?":":"/",n=this.path(),s="/"===n.substring(0,1),o=n.split(i);if(void 0!==t&&"number"!=typeof t&&(r=e,e=t,t=void 0),void 0!==t&&"number"!=typeof t)throw new Error('Bad segment "'+t+'", must be 0-based integer');if(s&&o.shift(),0>t&&(t=Math.max(o.length+t,0)),void 0===e)return void 0===t?o:o[t];if(null===t||void 0===o[t])if(a(e)){o=[];for(var h=0,u=e.length;u>h;h++)(e[h].length||o.length&&o[o.length-1].length)&&(o.length&&!o[o.length-1].length&&o.pop(),o.push(e[h]))}else(e||"string"==typeof e)&&(""===o[o.length-1]?o[o.length-1]=e:o.push(e));else e||"string"==typeof e&&e.length?o[t]=e:o.splice(t,1);return s&&o.unshift(""),this.path(o.join(i),r)},f.segmentCoded=function(t,e,r){var i,s,o;if("number"!=typeof t&&(r=e,e=t,t=void 0),void 0===e){if(i=this.segment(t,e,r),a(i))for(s=0,o=i.length;o>s;s++)i[s]=n.decode(i[s]);else i=void 0!==i?n.decode(i):void 0;return i}if(a(e))for(s=0,o=e.length;o>s;s++)e[s]=n.decode(e[s]);else e="string"==typeof e?n.encode(e):e;return this.segment(t,e,r)};var E=f.query;return f.query=function(t,e){if(t===!0)return n.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if("function"==typeof t){var r=n.parseQuery(this._parts.query,this._parts.escapeQuerySpace),i=t.call(this,r);return this._parts.query=n.buildQuery(i||r,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!e),this}return void 0!==t&&"string"!=typeof t?(this._parts.query=n.buildQuery(t,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),this.build(!e),this):E.call(this,t,e)},f.setQuery=function(t,e,r){var i=n.parseQuery(this._parts.query,this._parts.escapeQuerySpace);if("object"==typeof t)for(var s in t)m.call(t,s)&&(i[s]=t[s]);else{if("string"!=typeof t)throw new TypeError("URI.addQuery() accepts an object, string as the name parameter");i[t]=void 0!==e?e:null}return this._parts.query=n.buildQuery(i,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof t&&(r=e),this.build(!r),this},f.addQuery=function(t,e,r){var i=n.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return n.addQuery(i,t,void 0===e?null:e),this._parts.query=n.buildQuery(i,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof t&&(r=e),this.build(!r),this},f.removeQuery=function(t,e,r){var i=n.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return n.removeQuery(i,t,e),this._parts.query=n.buildQuery(i,this._parts.duplicateQueryParameters,this._parts.escapeQuerySpace),"string"!=typeof t&&(r=e),this.build(!r),this},f.hasQuery=function(t,e,r){var i=n.parseQuery(this._parts.query,this._parts.escapeQuerySpace);return n.hasQuery(i,t,e,r)},f.setSearch=f.setQuery,f.addSearch=f.addQuery,f.removeSearch=f.removeQuery,f.hasSearch=f.hasQuery,f.normalize=function(){return this._parts.urn?this.normalizeProtocol(!1).normalizeQuery(!1).normalizeFragment(!1).build():this.normalizeProtocol(!1).normalizeHostname(!1).normalizePort(!1).normalizePath(!1).normalizeQuery(!1).normalizeFragment(!1).build()},f.normalizeProtocol=function(t){return"string"==typeof this._parts.protocol&&(this._parts.protocol=this._parts.protocol.toLowerCase(),this.build(!t)),this},f.normalizeHostname=function(r){return this._parts.hostname&&(this.is("IDN")&&t?this._parts.hostname=t.toASCII(this._parts.hostname):this.is("IPv6")&&e&&(this._parts.hostname=e.best(this._parts.hostname)),this._parts.hostname=this._parts.hostname.toLowerCase(),this.build(!r)),this},f.normalizePort=function(t){return"string"==typeof this._parts.protocol&&this._parts.port===n.defaultPorts[this._parts.protocol]&&(this._parts.port=null,this.build(!t)),this},f.normalizePath=function(t){if(this._parts.urn)return this;if(!this._parts.path||"/"===this._parts.path)return this;var e,r,i,s=this._parts.path,o="";for("/"!==s.charAt(0)&&(e=!0,s="/"+s),s=s.replace(/(\/(\.\/)+)|(\/\.$)/g,"/").replace(/\/{2,}/g,"/"),e&&(o=s.substring(1).match(/^(\.\.\/)+/)||"",o&&(o=o[0]));;){if(r=s.indexOf("/.."),-1===r)break;0!==r?(i=s.substring(0,r).lastIndexOf("/"),-1===i&&(i=r),s=s.substring(0,i)+s.substring(r+3)):s=s.substring(3)}return e&&this.is("relative")&&(s=o+s.substring(1)),s=n.recodePath(s),this._parts.path=s,this.build(!t),this},f.normalizePathname=f.normalizePath,f.normalizeQuery=function(t){return"string"==typeof this._parts.query&&(this._parts.query.length?this.query(n.parseQuery(this._parts.query,this._parts.escapeQuerySpace)):this._parts.query=null,this.build(!t)),this},f.normalizeFragment=function(t){return this._parts.fragment||(this._parts.fragment=null,this.build(!t)),this},f.normalizeSearch=f.normalizeQuery,f.normalizeHash=f.normalizeFragment,f.iso8859=function(){var t=n.encode,e=n.decode;return n.encode=escape,n.decode=decodeURIComponent,this.normalize(),n.encode=t,n.decode=e,this},f.unicode=function(){var t=n.encode,e=n.decode;return n.encode=l,n.decode=unescape,this.normalize(),n.encode=t,n.decode=e,this},f.readable=function(){var e=this.clone();e.username("").password("").normalize();var r="";if(e._parts.protocol&&(r+=e._parts.protocol+"://"),e._parts.hostname&&(e.is("punycode")&&t?(r+=t.toUnicode(e._parts.hostname),e._parts.port&&(r+=":"+e._parts.port)):r+=e.host()),e._parts.hostname&&e._parts.path&&"/"!==e._parts.path.charAt(0)&&(r+="/"),r+=e.path(!0),e._parts.query){for(var i="",s=0,o=e._parts.query.split("&"),a=o.length;a>s;s++){var h=(o[s]||"").split("=");i+="&"+n.decodeQuery(h[0],this._parts.escapeQuerySpace).replace(/&/g,"%26"),void 0!==h[1]&&(i+="="+n.decodeQuery(h[1],this._parts.escapeQuerySpace).replace(/&/g,"%26"))}r+="?"+i.substring(1)}return r+=n.decodeQuery(e.hash(),!0)},f.absoluteTo=function(t){var e,r,i,s=this.clone(),o=["protocol","username","password","hostname","port"];if(this._parts.urn)throw new Error("URNs do not have any generally defined hierarchical components");if(t instanceof n||(t=new n(t)),s._parts.protocol||(s._parts.protocol=t._parts.protocol),this._parts.hostname)return s;for(r=0;i=o[r];r++)s._parts[i]=t._parts[i];return s._parts.path?".."===s._parts.path.substring(-2)&&(s._parts.path+="/"):(s._parts.path=t._parts.path,s._parts.query||(s._parts.query=t._parts.query)),"/"!==s.path().charAt(0)&&(e=t.directory(),s._parts.path=(e?e+"/":"")+s._parts.path,s.normalizePath()),s.build(),s},f.relativeTo=function(t){var e,r,i,s,o,a=this.clone().normalize();if(a._parts.urn)throw new Error("URNs do not have any generally defined hierarchical components");if(t=new n(t).normalize(),e=a._parts,r=t._parts,s=a.path(),o=t.path(),"/"!==s.charAt(0))throw new Error("URI is already relative");if("/"!==o.charAt(0))throw new Error("Cannot calculate a URI relative to another relative URI");if(e.protocol===r.protocol&&(e.protocol=null),e.username!==r.username||e.password!==r.password)return a.build();if(null!==e.protocol||null!==e.username||null!==e.password)return a.build();if(e.hostname!==r.hostname||e.port!==r.port)return a.build();if(e.hostname=null,e.port=null,s===o)return e.path="",a.build();if(i=n.commonPath(a.path(),t.path()),!i)return a.build();var h=r.path.substring(i.length).replace(/[^\/]*$/,"").replace(/.*?\//g,"../");return e.path=h+e.path.substring(i.length),a.build()},f.equals=function(t){var e,r,i,s=this.clone(),o=new n(t),h={},u={},p={};if(s.normalize(),o.normalize(),s.toString()===o.toString())return!0;if(e=s.query(),r=o.query(),s.query(""),o.query(""),s.toString()!==o.toString())return!1;if(e.length!==r.length)return!1;h=n.parseQuery(e,this._parts.escapeQuerySpace),u=n.parseQuery(r,this._parts.escapeQuerySpace);for(i in h)if(m.call(h,i)){if(a(h[i])){if(!c(h[i],u[i]))return!1}else if(h[i]!==u[i])return!1;p[i]=!0}for(i in u)if(m.call(u,i)&&!p[i])return!1;return!0},f.duplicateQueryParameters=function(t){return this._parts.duplicateQueryParameters=!!t,this},f.escapeQuerySpace=function(t){return this._parts.escapeQuerySpace=!!t,this},n}),EPUBJS.Book=function(t){this.opening=new RSVP.defer,this.opened=this.opening.promise,this.isOpen=!1,this.url=void 0,this.spine=new EPUBJS.Spine(this.request),this.loading={manifest:new RSVP.defer,spine:new RSVP.defer,metadata:new RSVP.defer,cover:new RSVP.defer,navigation:new RSVP.defer,pageList:new RSVP.defer},this.loaded={manifest:this.loading.manifest.promise,spine:this.loading.spine.promise,metadata:this.loading.metadata.promise,cover:this.loading.cover.promise,navigation:this.loading.navigation.promise,pageList:this.loading.pageList.promise},this.ready=RSVP.hash(this.loaded),this.isRendered=!1,this._q=EPUBJS.core.queue(this),this.request=this.requestMethod.bind(this),t&&this.open(t)},EPUBJS.Book.prototype.open=function(t){var e,r,i,n=new EPUBJS.Parser,s=this,o="META-INF/container.xml";return t?(e="object"==typeof t?t:EPUBJS.core.uri(t),"opf"===e.extension?(this.packageUrl=e.href,this.containerUrl="",e.origin?this.url=e.origin+"/"+e.directory:window?(i=EPUBJS.core.uri(window.location.href),this.url=EPUBJS.core.resolveUrl(i.base,e.directory)):this.url=e.directory,r=this.request(this.packageUrl)):"epub"===e.extension||"zip"===e.extension?(this.archived=!0,this.url=""):e.extension||(this.containerUrl=t+o,r=this.request(this.containerUrl).then(function(t){return n.container(t)}).then(function(e){var r=EPUBJS.core.uri(e.packagePath);return s.packageUrl=t+e.packagePath,s.url=t+r.directory,s.encoding=e.encoding,s.request(s.packageUrl)}).catch(function(t){console.error("Could not load book at: "+(this.packageUrl||this.containerPath)),s.trigger("book:loadFailed",this.packageUrl||this.containerPath),s.opening.reject(t)})),r.then(function(t){s.unpack(t),s.loading.manifest.resolve(s.package.manifest),s.loading.metadata.resolve(s.package.metadata),s.loading.spine.resolve(s.spine),s.loading.cover.resolve(s.cover),this.isOpen=!0,s.opening.resolve(s)}).catch(function(t){console.error(t.message,t.stack),s.opening.reject(t)}),this.opened):(this.opening.resolve(this),this.opened)},EPUBJS.Book.prototype.unpack=function(t){var e=this,r=new EPUBJS.Parser;e.package=r.packageContents(t),e.package.baseUrl=e.url,this.spine.load(e.package),e.navigation=new EPUBJS.Navigation(e.package,this.request),e.navigation.load().then(function(t){e.toc=t,e.loading.navigation.resolve(e.toc)}),e.cover=e.url+e.package.coverPath},EPUBJS.Book.prototype.section=function(t){return this.spine.get(t)},EPUBJS.Book.prototype.renderTo=function(t,e){return this.rendition=new EPUBJS.Renderer(this,e),this.rendition.attachTo(t),this.rendition},EPUBJS.Book.prototype.requestMethod=function(t){return this.archived?void 0:EPUBJS.core.request(t,"xml",this.requestCredentials,this.requestHeaders)},EPUBJS.Book.prototype.setRequestCredentials=function(t){this.requestCredentials=t},EPUBJS.Book.prototype.setRequestHeaders=function(t){this.requestHeaders=t},RSVP.EventTarget.mixin(EPUBJS.Book.prototype),RSVP.on("error",function(){}),RSVP.configure("instrument",!0),RSVP.on("rejected",function(t){console.error(t.detail.message,t.detail.stack)}),EPUBJS.core={},EPUBJS.core.request=function(t,e,r,i){function n(){if(this.readyState===this.DONE)if(200===this.status||this.responseXML){var t;t="xml"==e?this.responseXML:"json"==e?JSON.parse(this.response):"blob"==e?o?this.response:new Blob([this.response]):this.response,h.resolve(t)}else h.reject({status:this.status,message:this.response,stack:(new Error).stack})}var s,o=window.URL,a=o?"blob":"arraybuffer",h=new RSVP.defer,u=new XMLHttpRequest,c=XMLHttpRequest.prototype;"overrideMimeType"in c||Object.defineProperty(c,"overrideMimeType",{value:function(){}}),r&&(u.withCredentials=!0),u.open("GET",t,!0);for(s in i)u.setRequestHeader(s,i[s]);return u.onreadystatechange=n,"blob"==e&&(u.responseType=a),"json"==e&&u.setRequestHeader("Accept","application/json"),"xml"==e&&u.overrideMimeType("text/xml"),u.send(),h.promise},EPUBJS.core.uri=function(t){var e,r,i,n={protocol:"",host:"",path:"",origin:"",directory:"",base:"",filename:"",extension:"",fragment:"",href:t},s=t.indexOf("://"),o=t.indexOf("?"),a=t.indexOf("#");return-1!=a&&(n.fragment=t.slice(a+1),t=t.slice(0,a)),-1!=o&&(n.search=t.slice(o+1),t=t.slice(0,o),href=t),-1!=s?(n.protocol=t.slice(0,s),e=t.slice(s+3),i=e.indexOf("/"),-1===i?(n.host=n.path,n.path=""):(n.host=e.slice(0,i),n.path=e.slice(i)),n.origin=n.protocol+"://"+n.host,n.directory=EPUBJS.core.folder(n.path),n.base=n.origin+n.directory):(n.path=t,n.directory=EPUBJS.core.folder(t),n.base=n.directory),n.filename=t.replace(n.base,""),r=n.filename.lastIndexOf("."),-1!=r&&(n.extension=n.filename.slice(r+1)),n},EPUBJS.core.folder=function(t){var e=t.lastIndexOf("/");if(-1==e)var r="";return r=t.slice(0,e+1)},EPUBJS.core.queue=function(t){var e=[],r=t,i=function(t,r,i){return e.push({funcName:t,args:r,context:i}),e},n=function(){var t;e.length&&(t=e.shift(),r[t.funcName].apply(t.context||r,t.args))},s=function(){for(;e.length;)n()},o=function(){e=[]},a=function(){return e.length};return{enqueue:i,dequeue:n,flush:s,clear:o,length:a}},EPUBJS.core.isElement=function(t){return!(!t||1!=t.nodeType)},EPUBJS.core.uuid=function(){var t=(new Date).getTime(),e="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(e){var r=(t+16*Math.random())%16|0;return t=Math.floor(t/16),("x"==e?r:7&r|8).toString(16)});return e},EPUBJS.core.values=function(t){for(var e=-1,r=Object.keys(t),i=r.length,n=Array(i);++en;n++)if("undefined"!=typeof document.body.style[e[n]+r])return e[n]+r;return t},EPUBJS.core.defaults=function(t){for(var e=1,r=arguments.length;r>e;e++){var i=arguments[e];for(var n in i)void 0===t[n]&&(t[n]=i[n])}return t},EPUBJS.EpubCFI=function(t){return t?this.parse(t):void 0},EPUBJS.EpubCFI.prototype.generateChapterComponent=function(t,e,r){var i=parseInt(e),n=t+1,s="/"+n+"/";return s+=2*(i+1),r&&(s+="["+r+"]"),s},EPUBJS.EpubCFI.prototype.generatePathComponent=function(t){var e=[];return t.forEach(function(t){var r="";r+=2*(t.index+1),t.id&&(r+="["+t.id+"]"),e.push(r)}),e.join("/")},EPUBJS.EpubCFI.prototype.generateCfiFromElement=function(t,e){var r=this.pathTo(t),i=this.generatePathComponent(r);return i.length?"epubcfi("+e+"!"+i+"/1:0)":"epubcfi("+e+"!/4/)"},EPUBJS.EpubCFI.prototype.pathTo=function(t){for(var e,r=[];t&&null!==t.parentNode&&9!=t.parentNode.nodeType;)e=t.parentNode.children,r.unshift({id:t.id,tagName:t.tagName,index:e?Array.prototype.indexOf.call(e,t):0}),t=t.parentNode;return r},EPUBJS.EpubCFI.prototype.getChapterComponent=function(t){var e=t.split("!");return e[0]},EPUBJS.EpubCFI.prototype.getPathComponent=function(t){var e=t.split("!"),r=e[1]?e[1].split(":"):"";return r[0]},EPUBJS.EpubCFI.prototype.getCharecterOffsetComponent=function(t){var e=t.split(":");return e[1]||""},EPUBJS.EpubCFI.prototype.parse=function(t){var e,r,i,n,s,o,a,h,u,c={},p=function(t){var e,r,i,n;return e="element",r=parseInt(t)/2-1,i=t.match(/\[(.*)\]/),i&&i[1]&&(n=i[1]),{type:e,index:r,id:n||!1}};return"string"!=typeof t?{spinePos:-1}:(c.str=t,0===t.indexOf("epubcfi(")&&")"===t[t.length-1]&&(t=t.slice(8,t.length-1)),r=this.getChapterComponent(t),i=this.getPathComponent(t)||"",n=this.getCharecterOffsetComponent(t),r&&(e=r.split("/")[2]||"")?(c.spinePos=parseInt(e)/2-1||0,o=e.match(/\[(.*)\]/),c.spineId=o?o[1]:!1,-1!=i.indexOf(",")&&console.warn("CFI Ranges are not supported"),a=i.split("/"),h=a.pop(),c.steps=[],a.forEach(function(t){var e;t&&(e=p(t),c.steps.push(e))}),u=parseInt(h),isNaN(u)||c.steps.push(u%2===0?p(h):{type:"text",index:(u-1)/2}),s=n.match(/\[(.*)\]/),s&&s[1]?(c.characterOffset=parseInt(n.split("[")[0]),c.textLocationAssertion=s[1]):c.characterOffset=parseInt(n),c):{spinePos:-1})},EPUBJS.EpubCFI.prototype.addMarker=function(t,e,r){var i,n,s,o,a=e||document,h=r||this.createMarker(a);return"string"==typeof t&&(t=this.parse(t)),n=t.steps[t.steps.length-1],-1===t.spinePos?!1:(i=this.findParent(t,a))?(n&&"text"===n.type?(s=i.childNodes[n.index],t.characterOffset?(o=s.splitText(t.characterOffset),h.classList.add("EPUBJS-CFI-SPLIT"),i.insertBefore(h,o)):i.insertBefore(h,s)):i.insertBefore(h,i.firstChild),h):!1},EPUBJS.EpubCFI.prototype.createMarker=function(t){var e=t||document,r=e.createElement("span");return r.id="EPUBJS-CFI-MARKER:"+EPUBJS.core.uuid(),r.classList.add("EPUBJS-CFI-MARKER"),r},EPUBJS.EpubCFI.prototype.removeMarker=function(t,e){t.classList.contains("EPUBJS-CFI-SPLIT")?(nextSib=t.nextSibling,prevSib=t.previousSibling,nextSib&&prevSib&&3===nextSib.nodeType&&3===prevSib.nodeType&&(prevSib.textContent+=nextSib.textContent,t.parentNode.removeChild(nextSib)),t.parentNode.removeChild(t)):t.classList.contains("EPUBJS-CFI-MARKER")&&t.parentNode.removeChild(t)},EPUBJS.EpubCFI.prototype.findParent=function(t,e){var r,i,n,s=e||document,o=s.getElementsByTagName("html")[0],a=Array.prototype.slice.call(o.children);if("string"==typeof t&&(t=this.parse(t)),i=t.steps.slice(0),!i.length)return s.getElementsByTagName("body")[0];for(;i&&i.length>0;){if(r=i.shift(),"text"===r.type?(n=o.childNodes[r.index],o=n.parentNode||o):o=r.id?s.getElementById(r.id):a[r.index],"undefined"==typeof o)return console.error("No Element For",r,t.str),!1;a=Array.prototype.slice.call(o.children)}return o},EPUBJS.EpubCFI.prototype.compare=function(t,e){if("string"==typeof t&&(t=new EPUBJS.EpubCFI(t)),"string"==typeof e&&(e=new EPUBJS.EpubCFI(e)),t.spinePos>e.spinePos)return 1;if(t.spinePose.steps[r].index)return 1;if(t.steps[r].indexe.characterOffset?1:t.characterOffset=0?(s=n.length,t.characterOffsetr?this.hooks[r].apply(this.context,n):void 0}.bind(this))):(t=i.promise,i.resolve()),t},EPUBJS.Infinite=function(t,e){this.container=t,this.windowHeight=window.innerHeight,this.tick=window.requestAnimationFrame||window.mozRequestAnimationFrame||window.webkitRequestAnimationFrame||window.msRequestAnimationFrame,this.scrolled=!1,this.ignore=!1,this.displaying=!1,this.offset=900,this.views=[],this.axis=e,this.prevScrollTop=0},EPUBJS.Infinite.prototype.start=function(){this.container.addEventListener("scroll",function(){this.ignore?this.ignore=!1:this.scrolled=!0}.bind(this)),window.addEventListener("unload",function(){this.ignore=!0}),this.tick.call(window,this.check.bind(this)),this.scrolled=!1},EPUBJS.Infinite.prototype.forwards=function(){this.trigger("forwards")},EPUBJS.Infinite.prototype.backwards=function(){this.trigger("backwards")},EPUBJS.Infinite.prototype.check=function(){this.scrolled&&!this.displaying?("vertical"===this.axis?this.checkTop():this.checkLeft(),this.scrolled=!1):(this.displaying=!1,this.scrolled=!1),this.tick.call(window,this.check.bind(this))},EPUBJS.Infinite.prototype.checkTop=function(){var t=this.container.scrollTop,e=this.container.scrollHeight,r=t-this.prevScrollTop,i=this.container.getBoundingClientRect().height,n=t+this.offset>e-i,s=t0?this.forwards():s&&0>r&&this.backwards(),this.prevScrollTop=t,t},EPUBJS.Infinite.prototype.checkLeft=function(){var t=this.container.scrollLeft,e=this.container.scrollWidth,r=t-this.prevscrollLeft,i=this.container.getBoundingClientRect().width,n=t+this.offset>e-i,s=t0?this.forwards():s&&0>r&&this.backwards(),this.prevscrollLeft=t,t},EPUBJS.Infinite.prototype.scrollBy=function(t,e,r){r&&(this.displaying=!0),this.container.scrollLeft+=t,this.container.scrollTop+=e,this.scrolled=!0,this.check()},EPUBJS.Infinite.prototype.scroll=function(t,e,r){r&&(this.displaying=!0),this.container.scrollLeft=t,this.container.scrollTop=e,this.scrolled=!0,this.check()},RSVP.EventTarget.mixin(EPUBJS.Infinite.prototype),EPUBJS.Layout=EPUBJS.Layout||{},EPUBJS.Layout.Reflowable=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.Reflowable.prototype.format=function(t,e,r,i){var n=EPUBJS.core.prefixed("columnAxis"),s=EPUBJS.core.prefixed("columnGap"),o=EPUBJS.core.prefixed("columnWidth"),a=EPUBJS.core.prefixed("columnFill"),h=Math.floor(e),u=Math.floor(h/8),c=i>=0?i:u%2===0?u:u-1;return this.documentElement=t,this.spreadWidth=h+c,t.style.overflow="hidden",t.style.width=h+"px",t.style.height=r+"px",t.style[n]="horizontal",t.style[a]="auto",t.style[o]=h+"px",t.style[s]=c+"px",this.colWidth=h,this.gap=c,{pageWidth:this.spreadWidth,pageHeight:r}},EPUBJS.Layout.Reflowable.prototype.calculatePages=function(){var t,e;return this.documentElement.style.width="auto",t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth),{displayedPages:e,pageCount:e}},EPUBJS.Layout.ReflowableSpreads=function(){this.documentElement=null,this.spreadWidth=null},EPUBJS.Layout.ReflowableSpreads.prototype.format=function(t,e,r,i){var n=EPUBJS.core.prefixed("columnAxis"),s=EPUBJS.core.prefixed("columnGap"),o=EPUBJS.core.prefixed("columnWidth"),a=EPUBJS.core.prefixed("columnFill"),h=2,u=Math.floor(e),c=u%2===0?u:u-1,p=Math.floor(c/8),l=i>=0?i:p%2===0?p:p-1,d=Math.floor((c-l)/h);return this.spreadWidth=(d+l)*h,t.document.documentElement.style.overflow="hidden",t.document.body.style.width=c+"px",t.document.body.style.height=r+"px",t.document.body.style[n]="horizontal",t.document.body.style[a]="auto",t.document.body.style[s]=l+"px",t.document.body.style[o]=d+"px",this.colWidth=d,this.gap=l,t.iframe.style.width=d+"px",t.iframe.style.paddingRight=l+"px",{pageWidth:this.spreadWidth,pageHeight:r}},EPUBJS.Layout.ReflowableSpreads.prototype.calculatePages=function(){var t=this.documentElement.scrollWidth,e=Math.ceil(t/this.spreadWidth);return this.documentElement.style.width=t+this.spreadWidth+"px",{displayedPages:e,pageCount:2*e}},EPUBJS.Layout.Fixed=function(){this.documentElement=null},EPUBJS.Layout.Fixed=function(t){var e,r,i,n,s=EPUBJS.core.prefixed("columnWidth"),o=t.querySelector("[name=viewport");return this.documentElement=t,o&&o.hasAttribute("content")&&(e=o.getAttribute("content"),r=e.split(","),r[0]&&(i=r[0].replace("width=","")),r[1]&&(n=r[1].replace("height=",""))),t.style.width=i+"px"||"auto",t.style.height=n+"px"||"auto",t.style[s]="auto",t.style.overflow="auto",this.colWidth=i,this.gap=0,{pageWidth:i,pageHeight:n}},EPUBJS.Layout.Fixed.prototype.calculatePages=function(){return{displayedPages:1,pageCount:1}},EPUBJS.Navigation=function(t,e){var r=this,i=new EPUBJS.Parser,n=e||EPUBJS.core.request;this.package=t,this.toc=[],this.tocByHref={},this.tocById={},t.navPath&&(this.navUrl=t.baseUrl+t.navPath,this.nav={},this.nav.load=function(){var t=new RSVP.defer,e=t.promise;return n(r.navUrl,"xml").then(function(e){r.toc=i.nav(e),r.loaded(r.toc),t.resolve(r.toc)}),e}),t.ncxPath&&(this.ncxUrl=t.baseUrl+t.ncxPath,this.ncx={},this.ncx.load=function(){var t=new RSVP.defer,e=t.promise;return n(r.ncxUrl,"xml").then(function(e){r.toc=i.ncx(e),r.loaded(r.toc),t.resolve(r.toc)}),e})},EPUBJS.Navigation.prototype.load=function(t){{var e,r;t||EPUBJS.core.request}return this.nav?e=this.nav.load():this.ncx?e=this.ncx.load():(r=new RSVP.defer,r.resolve([]),e=r.promise),e},EPUBJS.Navigation.prototype.loaded=function(t){for(var e,r=0;r=0;o--){var a=n.snapshotItem(o),h=a.getAttribute("id")||!1,u=a.querySelector("content"),c=u.getAttribute("src"),p=a.querySelector("navLabel"),l=p.textContent?p.textContent:"",d=c.split("#"),f=(d[0],e(a));i.unshift({id:h,href:c,label:l,subitems:f,parent:r?r.getAttribute("id"):null})}return i}var r=t.querySelector("navMap");return r?e(r):[]},EPUBJS.Renderer=function(t,e){var r=e||{};this.settings={infinite:"undefined"==typeof r.infinite?!0:r.infinite,hidden:"undefined"==typeof r.hidden?!1:r.hidden,axis:r.axis||"vertical",viewsLimit:r.viewsLimit||5,width:"undefined"==typeof r.width?!1:r.width,height:"undefined"==typeof r.height?!1:r.height},this.book=t,this.epubcfi=new EPUBJS.EpubCFI,this.layoutSettings={},this._q=EPUBJS.core.queue(this),this.position=1,this.initialize({width:this.settings.width,height:this.settings.height}),this.rendering=!1,this.views=[],this.positions=[],this.hooks={},this.hooks.display=new EPUBJS.Hook(this),this.hooks.replacements=new EPUBJS.Hook(this),this.settings.infinite||(this.settings.viewsLimit=1)},EPUBJS.Renderer.prototype.initialize=function(t){{var e=t||{},r=e.height!==!1?e.height:"100%",i=e.width!==!1?e.width:"100%";e.hidden||!1}return e.height&&EPUBJS.core.isNumber(e.height)&&(r=e.height+"px"),e.width&&EPUBJS.core.isNumber(e.width)&&(i=e.width+"px"),this.container=document.createElement("div"),this.settings.infinite&&(this.infinite=new EPUBJS.Infinite(this.container,this.settings.axis)),"horizontal"===this.settings.axis&&(this.container.style.whiteSpace="nowrap"),this.container.style.width=i,this.container.style.height=r,this.container.style.overflow="scroll",e.hidden?(this.wrapper=document.createElement("div"),this.wrapper.style.visibility="hidden",this.wrapper.style.overflow="hidden",this.wrapper.style.width="0",this.wrapper.style.height="0",this.wrapper.appendChild(this.container),this.wrapper):this.container},EPUBJS.Renderer.prototype.resize=function(t,e){var r=t,i=e;t||(r=window.innerWidth),e||(i=window.innerHeight),this.container.style.width=r+"px",this.container.style.height=i+"px",this.trigger("resized",{width:this.width,height:this.height})},EPUBJS.Renderer.prototype.onResized=function(){var t=this.element.getBoundingClientRect();this.resize(t.width,t.height)},EPUBJS.Renderer.prototype.attachTo=function(t){var e;return EPUBJS.core.isElement(t)?this.element=t:"string"==typeof t&&(this.element=document.getElementById(t)),this.element?(this.element.appendChild(this.container),this.settings.height||this.settings.width||(e=this.element.getBoundingClientRect(),this.resize(e.width,e.height)),this.settings.infinite&&(this.infinite.start(),this.infinite.on("forwards",function(){var t=this.last().section.index+1;!this.rendering&&t0&&this.backwards()}.bind(this))),window.addEventListener("resize",this.onResized.bind(this),!1),void this.hooks.replacements.register(this.replacements.bind(this))):void console.error("Not an Element")},EPUBJS.Renderer.prototype.clear=function(){this.views.forEach(function(t){t.destroy()}),this.views=[]},EPUBJS.Renderer.prototype.display=function(t){var e=new RSVP.defer,r=e.promise;return this.clear(),this.book.opened.then(function(){var r,i=this.book.spine.get(t);i?(r=this.render(i),this.settings.infinite&&r.then(this.fill.bind(this)),r.then(function(){e.resolve(this)}.bind(this))):e.reject(new Error("No Section Found"))}.bind(this)),r},EPUBJS.Renderer.prototype.render=function(t){var e,r;return t?(r=new EPUBJS.View(t),this.insert(r,t.index),e=r.render(this.book.request),e.then(function(){return this.hooks.display.trigger(r)}.bind(this)).then(function(){return this.hooks.replacements.trigger(r,this)}.bind(this)).then(function(){return r.expand()}.bind(this)).then(function(){return this.rendering=!1,r.show(),r}.bind(this)).catch(function(t){this.trigger("loaderror",t)}.bind(this))):(e=new RSVP.defer,e.reject(new Error("No Section Provided")),e.promise)},EPUBJS.Renderer.prototype.forwards=function(){var t,e,r;return t=this.last().section.index+1,this.rendering||t===this.book.spine.length?(e=new RSVP.defer,e.reject(new Error("Reject Forwards")),e.promise):(this.rendering=!0,r=this.book.spine.get(t),e=this.render(r),e.then(function(){var t=this.first(),e=t.bounds(),r=this.container.scrollTop,i=this.container.scrollLeft;this.views.length>this.settings.viewsLimit&&(this.remove(t),this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scroll(0,r-e.height,!0):this.infinite.scroll(i-e.width,!0)))}.bind(this)),e)},EPUBJS.Renderer.prototype.backwards=function(){var t,e,r;return t=this.first().section.index-1,this.rendering||0>t?(e=new RSVP.defer,e.reject(new Error("Reject Backwards")),e.promise):(this.rendering=!0,r=this.book.spine.get(t),e=this.render(r),e.then(function(){var t;this.settings.infinite&&("vertical"===this.settings.axis?this.infinite.scrollBy(0,this.first().bounds().height,!0):this.infinite.scrollBy(this.first().bounds().width,0,!0)),this.views.length>this.settings.viewsLimit&&(t=this.last(),this.remove(t))}.bind(this)),e)},EPUBJS.Renderer.prototype.fill=function(){var t=this.first().section.index-1,e=this.forwards();return e.then("vertical"===this.settings.axis?this.fillVertical.bind(this):this.fillHorizontal.bind(this)),t>0&&e.then(this.backwards.bind(this)),e.then(function(){this.rendering=!1}.bind(this))},EPUBJS.Renderer.prototype.fillVertical=function(){var t=this.container.getBoundingClientRect().height,e=this.last().bounds().bottom,r=new RSVP.defer;return t&&e&&t>e?this.forwards().then(this.fillVertical.bind(this)):(this.rendering=!1,r.resolve(),r.promise)},EPUBJS.Renderer.prototype.fillHorizontal=function(){var t=this.container.getBoundingClientRect().width,e=this.last().bounds().right,r=new RSVP.defer;return t&&e&&t>=e?this.forwards().then(this.fillHorizontal.bind(this)):(this.rendering=!1,r.resolve(),r.promise)},EPUBJS.Renderer.prototype.append=function(t){this.views.push(t),t.appendTo(this.container)},EPUBJS.Renderer.prototype.prepend=function(t){this.views.unshift(t),t.prependTo(this.container)},EPUBJS.Renderer.prototype.insert=function(t,e){this.first()?e-this.first().section.index>=0?this.append(t):e-this.last().section.index<=0&&this.prepend(t):this.append(t)},EPUBJS.Renderer.prototype.remove=function(t){var e=this.views.indexOf(t);t.destroy(),e>-1&&this.views.splice(e,1)},EPUBJS.Renderer.prototype.first=function(){return this.views[0]},EPUBJS.Renderer.prototype.last=function(){return this.views[this.views.length-1]},EPUBJS.Renderer.prototype.replacements=function(t,e){for(var r=new RSVP.defer,i=t.document.querySelectorAll("a[href]"),n=function(t){var r=t.getAttribute("href"),i=r.search("://");-1!=i?t.setAttribute("target","_blank"):t.onclick=function(){return e.display(r),!1}},s=0;s-1?(delete this.spineByHref[t.href],delete this.spineById[t.idref],this.spineItems.splice(e,1)):void 0},EPUBJS.View=function(t){this.id="epubjs-view:"+EPUBJS.core.uuid(),this.rendering=new RSVP.defer,this.rendered=this.rendering.promise,this.iframe=this.create(),this.section=t},EPUBJS.View.prototype.create=function(){return this.iframe=document.createElement("iframe"),this.iframe.id=this.id,this.iframe.scrolling="no",this.iframe.seamless="seamless",this.iframe.style.border="none",this.resizing=!0,this.iframe.style.width="100%",this.iframe.style.height="100%",this.iframe.style.display="none",this.iframe.style.visibility="hidden",this.iframe},EPUBJS.View.prototype.resized=function(){this.resizing?this.resizing=!1:this.expand()},EPUBJS.View.prototype.render=function(t){return this.section.render(t).then(function(t){return this.load(t)}.bind(this)).then(this.display.bind(this)).then(function(){this.rendering.resolve(this)}.bind(this))},EPUBJS.View.prototype.load=function(t){var e=new RSVP.defer,r=e.promise;return this.document=this.iframe.contentDocument,this.iframe.addEventListener("load",function(){this.window=this.iframe.contentWindow,this.document=this.iframe.contentDocument,e.resolve(this)}.bind(this)),this.document.open(),this.document.write(t),this.document.close(),r},EPUBJS.View.prototype.display=function(){var t=new RSVP.defer,e=t.promise;return this.iframe.style.display="inline-block",this.document.body.style.margin="0",this.document.documentElement.style.width="auto",setTimeout(function(){this.window.addEventListener("resize",this.resized.bind(this),!1)}.bind(this),10),this.document.fonts&&"loading"===this.document.fonts.status?this.document.fonts.onloading=function(){this.expand(),t.resolve(this)}.bind(this):(this.expand(),t.resolve(this)),e},EPUBJS.View.prototype.expand=function(){var t,e,r;return t=this.document.body.getBoundingClientRect(),(!t||0===t.height&&0===t.width)&&console.error("View not shown"),this.resizing=!0,r=t.height,this.iframe.style.height=r+"px",e=this.document.documentElement.scrollWidth,this.iframe.style.width=e+"px",t},EPUBJS.View.prototype.observe=function(t){var e=this,r=new MutationObserver(function(){e.expand()}),i={attributes:!0,childList:!0,characterData:!0,subtree:!0};return r.observe(t,i),r},EPUBJS.View.prototype.appendTo=function(t){this.element=t,this.element.appendChild(this.iframe)},EPUBJS.View.prototype.prependTo=function(t){this.element=t,t.insertBefore(this.iframe,t.firstChild)},EPUBJS.View.prototype.show=function(){this.iframe.style.display="inline-block",this.iframe.style.visibility="visible"},EPUBJS.View.prototype.hide=function(){this.iframe.style.display="none",this.iframe.style.visibility="hidden"},EPUBJS.View.prototype.bounds=function(){return this.iframe.getBoundingClientRect()},EPUBJS.View.prototype.destroy=function(){this.element.removeChild(this.iframe)};
\ No newline at end of file
diff --git a/examples/basic.html b/examples/basic.html
index da3d262..7b95ed0 100644
--- a/examples/basic.html
+++ b/examples/basic.html
@@ -17,15 +17,17 @@
#viewer {
display: block;
margin: 0;
- width: 100%;
+ width: 60%;
height: 100%;
+ margin: 0 auto;
}
#viewer iframe {
background: white;
box-shadow: 0 0 4px #ccc;
- width: 590px;
- margin: 10px auto;
+ margin: 10px;
+ width: calc(100% - 60px) !important;
+ padding: 20px;
}
@@ -72,7 +74,7 @@
+
+
+
+
+
+ ‹
+ ›
+
+
+
+