1
0
Fork 0
mirror of https://github.com/futurepress/epub.js.git synced 2025-10-03 14:59:18 +02:00

Switched from URIjs to URL and Node Path

This commit is contained in:
Fred Chasen 2016-10-30 22:14:01 +01:00
parent 869a170564
commit 315650006e
22 changed files with 1060 additions and 3614 deletions

3880
dist/epub.js vendored

File diff suppressed because it is too large Load diff

2
dist/epub.js.map vendored

File diff suppressed because one or more lines are too long

64
dist/epub.min.js vendored

File diff suppressed because one or more lines are too long

386
dist/polyfills.js vendored
View file

@ -44,7 +44,7 @@ return /******/ (function(modules) { // webpackBootstrap
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ __webpack_require__.p = "/dist/";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
@ -55,12 +55,199 @@ return /******/ (function(modules) { // webpackBootstrap
/***/ 0:
/***/ function(module, exports, __webpack_require__) {
module.exports = __webpack_require__(47);
module.exports = __webpack_require__(44);
/***/ },
/***/ 47:
/***/ 18:
/***/ function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ },
/***/ 44:
/***/ function(module, exports, __webpack_require__) {
var require;/* WEBPACK VAR INJECTION */(function(process, global) {/*!
@ -199,7 +386,7 @@ return /******/ (function(modules) { // webpackBootstrap
function attemptVertx() {
try {
var r = require;
var vertx = __webpack_require__(49);
var vertx = __webpack_require__(45);
vertxNext = vertx.runOnLoop || vertx.runOnContext;
return useVertxTimer();
} catch (e) {
@ -1222,198 +1409,11 @@ return /******/ (function(modules) { // webpackBootstrap
ES6Promise.polyfill();
//# sourceMappingURL=es6-promise.auto.map
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(48), (function() { return this; }())))
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(18), (function() { return this; }())))
/***/ },
/***/ 48:
/***/ function(module, exports) {
// shim for using process in browser
var process = module.exports = {};
// cached from whatever global is present so that test runners that stub it
// don't break things. But we need to wrap it in a try catch in case it is
// wrapped in strict mode code which doesn't define any globals. It's inside a
// function because try/catches deoptimize in certain engines.
var cachedSetTimeout;
var cachedClearTimeout;
function defaultSetTimout() {
throw new Error('setTimeout has not been defined');
}
function defaultClearTimeout () {
throw new Error('clearTimeout has not been defined');
}
(function () {
try {
if (typeof setTimeout === 'function') {
cachedSetTimeout = setTimeout;
} else {
cachedSetTimeout = defaultSetTimout;
}
} catch (e) {
cachedSetTimeout = defaultSetTimout;
}
try {
if (typeof clearTimeout === 'function') {
cachedClearTimeout = clearTimeout;
} else {
cachedClearTimeout = defaultClearTimeout;
}
} catch (e) {
cachedClearTimeout = defaultClearTimeout;
}
} ())
function runTimeout(fun) {
if (cachedSetTimeout === setTimeout) {
//normal enviroments in sane situations
return setTimeout(fun, 0);
}
// if setTimeout wasn't available but was latter defined
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
cachedSetTimeout = setTimeout;
return setTimeout(fun, 0);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedSetTimeout(fun, 0);
} catch(e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedSetTimeout.call(null, fun, 0);
} catch(e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
return cachedSetTimeout.call(this, fun, 0);
}
}
}
function runClearTimeout(marker) {
if (cachedClearTimeout === clearTimeout) {
//normal enviroments in sane situations
return clearTimeout(marker);
}
// if clearTimeout wasn't available but was latter defined
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
cachedClearTimeout = clearTimeout;
return clearTimeout(marker);
}
try {
// when when somebody has screwed with setTimeout but no I.E. maddness
return cachedClearTimeout(marker);
} catch (e){
try {
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
return cachedClearTimeout.call(null, marker);
} catch (e){
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
return cachedClearTimeout.call(this, marker);
}
}
}
var queue = [];
var draining = false;
var currentQueue;
var queueIndex = -1;
function cleanUpNextTick() {
if (!draining || !currentQueue) {
return;
}
draining = false;
if (currentQueue.length) {
queue = currentQueue.concat(queue);
} else {
queueIndex = -1;
}
if (queue.length) {
drainQueue();
}
}
function drainQueue() {
if (draining) {
return;
}
var timeout = runTimeout(cleanUpNextTick);
draining = true;
var len = queue.length;
while(len) {
currentQueue = queue;
queue = [];
while (++queueIndex < len) {
if (currentQueue) {
currentQueue[queueIndex].run();
}
}
queueIndex = -1;
len = queue.length;
}
currentQueue = null;
draining = false;
runClearTimeout(timeout);
}
process.nextTick = function (fun) {
var args = new Array(arguments.length - 1);
if (arguments.length > 1) {
for (var i = 1; i < arguments.length; i++) {
args[i - 1] = arguments[i];
}
}
queue.push(new Item(fun, args));
if (queue.length === 1 && !draining) {
runTimeout(drainQueue);
}
};
// v8 likes predictible objects
function Item(fun, array) {
this.fun = fun;
this.array = array;
}
Item.prototype.run = function () {
this.fun.apply(null, this.array);
};
process.title = 'browser';
process.browser = true;
process.env = {};
process.argv = [];
process.version = ''; // empty string to avoid regexp issues
process.versions = {};
function noop() {}
process.on = noop;
process.addListener = noop;
process.once = noop;
process.off = noop;
process.removeListener = noop;
process.removeAllListeners = noop;
process.emit = noop;
process.binding = function (name) {
throw new Error('process.binding is not supported');
};
process.cwd = function () { return '/' };
process.chdir = function (dir) {
throw new Error('process.chdir is not supported');
};
process.umask = function() { return 0; };
/***/ },
/***/ 49:
/***/ 45:
/***/ function(module, exports) {
/* (ignored) */

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -72,7 +72,8 @@ gulp.task('minify', ['bundle'], function(){
// Watch Our Files
gulp.task('watch', function(cb) {
webpack(webpackConfig, function(err, stats) {
watchCompiler.watch({}, function(err, stats) {
if(err) {
throw new gutil.PluginError("webpack", err);
}

View file

@ -1,5 +1,5 @@
var EventEmitter = require('event-emitter');
var URI = require('urijs');
var path = require('path');
var core = require('./core');
var Spine = require('./spine');
var Locations = require('./locations');
@ -73,14 +73,14 @@ function Book(_url, options){
};
Book.prototype.open = function(_url, options){
var uri;
var url;
var pathname;
var parse = new Parser();
var epubPackage;
var epubContainer;
var book = this;
var containerPath = "META-INF/container.xml";
var location;
var absoluteUri;
var isArrayBuffer = false;
var isBase64 = options && options.base64;
@ -98,13 +98,14 @@ Book.prototype.open = function(_url, options){
if (_url instanceof ArrayBuffer || isBase64) {
isArrayBuffer = true;
this.url = '/';
} else {
uri = URI(_url);
}
if (window && window.location && uri) {
absoluteUri = uri.absoluteTo(window.location.href);
this.url = absoluteUri.toString();
if (window && window.location && !isArrayBuffer) {
// absoluteUri = uri.absoluteTo(window.location.href);
url = new URL(_url, window.location.href);
pathname = url.pathname;
// this.url = absoluteUri.toString();
this.url = url.toString();
} else if (window && window.location) {
this.url = window.location.href;
} else {
@ -112,18 +113,20 @@ Book.prototype.open = function(_url, options){
}
// Find path to the Container
if(uri && uri.suffix() === "opf") {
// if(uri && uri.suffix() === "opf") {
if(url && core.extension(pathname) === "opf") {
// Direct link to package, no container
this.packageUrl = _url;
this.containerUrl = '';
if(uri.origin()) {
this.baseUrl = uri.origin() + "/" + uri.directory() + "/";
} else if(absoluteUri){
this.baseUrl = absoluteUri.origin();
this.baseUrl += absoluteUri.directory() + "/";
if(url.origin) {
// this.baseUrl = uri.origin() + uri.directory() + "/";
this.baseUrl = url.origin + "/" + path.dirname(pathname) + "/";
// } else if(absoluteUri){
// this.baseUrl = absoluteUri.origin();
// this.baseUrl += absoluteUri.directory() + "/";
} else {
this.baseUrl = uri.directory() + "/";
this.baseUrl = path.dirname(pathname) + "/";
}
epubPackage = this.request(this.packageUrl)
@ -131,10 +134,11 @@ Book.prototype.open = function(_url, options){
book.opening.reject(error);
});
} else if(isArrayBuffer || isBase64 || this.isArchivedUrl(uri)) {
} else if(isArrayBuffer || isBase64 || this.isArchivedUrl(_url)) {
// Book is archived
this.url = '/';
this.containerUrl = URI(containerPath).absoluteTo(this.url).toString();
this.url = '';
// this.containerUrl = URI(containerPath).absoluteTo(this.url).toString();
this.containerUrl = path.resolve("", containerPath);
epubContainer = this.unarchive(_url, isBase64).
then(function() {
@ -145,7 +149,7 @@ Book.prototype.open = function(_url, options){
});
}
// Find the path to the Package from the container
else if (!uri.suffix()) {
else if (!core.extension(pathname)) {
this.containerUrl = this.url + containerPath;
@ -162,21 +166,29 @@ Book.prototype.open = function(_url, options){
return parse.container(containerXml); // Container has path to content
}).
then(function(paths){
var packageUri = URI(paths.packagePath);
var absPackageUri = packageUri.absoluteTo(book.url);
var absWindowUri;
// var packageUri = URI(paths.packagePath);
// var absPackageUri = packageUri.absoluteTo(book.url);
var packageUrl;
book.packageUrl = absPackageUri.toString();
if (book.url) {
packageUrl = new URL(paths.packagePath, book.url);
book.packageUrl = packageUrl.toString();
} else {
book.packageUrl = "/" + paths.packagePath;
}
book.packagePath = paths.packagePath;
book.encoding = paths.encoding;
// Set Url relative to the content
if(absPackageUri.origin()) {
book.baseUrl = absPackageUri.origin() + absPackageUri.directory() + "/";
if(packageUrl && packageUrl.origin) {
book.baseUrl = book.url + path.dirname(paths.packagePath) + "/";
} else {
if(packageUri.directory()) {
book.baseUrl = "/" + packageUri.directory() + "/";
if(path.dirname(paths.packagePath)) {
book.baseUrl = ""
book.basePath = "/" + path.dirname(paths.packagePath) + "/";
} else {
book.baseUrl = "/"
book.basePath = "/"
}
}
@ -228,6 +240,7 @@ Book.prototype.unpack = function(packageXml){
}
book.package.baseUrl = book.baseUrl; // Provides a url base for resolving paths
book.package.basePath = book.basePath; // Provides a url base for resolving paths
this.spine.load(book.package);
@ -240,8 +253,11 @@ Book.prototype.unpack = function(packageXml){
// //-- Set Global Layout setting based on metadata
// MOVE TO RENDER
// book.globalLayoutProperties = book.parseLayoutProperties(book.package.metadata);
book.cover = URI(book.package.coverPath).absoluteTo(book.baseUrl).toString();
if (book.baseUrl) {
book.cover = new URL(book.package.coverPath, book.baseUrl).toString();
} else {
book.cover = path.resolve(book.baseUrl, book.package.coverPath);
}
};
// Alias for book.spine.get
@ -286,7 +302,6 @@ Book.prototype.unarchive = function(bookUrl, isBase64){
//-- Checks if url has a .epub or .zip extension, or is ArrayBuffer (of zip/epub)
Book.prototype.isArchivedUrl = function(bookUrl){
var uri;
var extension;
if (bookUrl instanceof ArrayBuffer) {
@ -299,8 +314,8 @@ Book.prototype.isArchivedUrl = function(bookUrl){
// } else {
// uri = core.uri(bookUrl);
// }
uri = URI(bookUrl);
extension = uri.suffix();
// uri = URI(bookUrl);
extension = core.extension(bookUrl);
if(extension && (extension == "epub" || extension == "zip")){
return true;

View file

@ -303,7 +303,13 @@ Contents.prototype.mediaQueryListeners = function() {
}.bind(this);
for (var i = 0; i < sheets.length; i += 1) {
var rules = sheets[i].cssRules;
var rules;
// Firefox errors if we access cssRules cross-domain
try {
rules = sheets[i].cssRules;
} catch (e) {
return;
}
if(!rules) return; // Stylesheets changed
for (var j = 0; j < rules.length; j += 1) {
//if (rules[j].constructor === CSSMediaRule) {

View file

@ -1,4 +1,5 @@
var base64 = require('base64-js');
var path = require('path');
var requestAnimationFrame = (typeof window != 'undefined') ? (window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame) : false;
/*
@ -82,6 +83,42 @@ function folder(url){
};
*/
function extension(_url) {
var url;
var pathname;
var ext;
try {
url = new Url(url);
pathname = url.pathname;
} catch (e) {
pathname = _url;
}
ext = path.extname(pathname);
if (ext) {
return ext.slice(1);
}
return '';
}
function directory(_url) {
var url;
var pathname;
var ext;
try {
url = new Url(url);
pathname = url.pathname;
} catch (e) {
pathname = _url;
}
return path.dirname(pathname);
}
function isElement(obj) {
return !!(obj && obj.nodeType == 1);
};
@ -537,6 +574,8 @@ function defer() {
module.exports = {
// 'uri': uri,
// 'folder': folder,
'extension' : extension,
'directory' : directory,
'isElement': isElement,
'uuid': uuid,
'values': values,

View file

@ -1,4 +1,3 @@
var URI = require('urijs');
var core = require('./core');
/**

View file

@ -162,6 +162,7 @@ IframeView.prototype.render = function(request, show) {
}.bind(this))
.catch(function(e){
console.error(e);
this.emit("loaderror", e);
}.bind(this));

View file

@ -2,7 +2,7 @@ var EventEmitter = require('event-emitter');
var core = require('../../core');
var EpubCFI = require('../../epubcfi');
var Contents = require('../../contents');
var URI = require('urijs');
// var URI = require('urijs');
function InlineView(section, options) {
this.settings = core.extend({

View file

@ -1,6 +1,6 @@
var core = require('./core');
var Parser = require('./parser');
var URI = require('urijs');
var path = require('path');
function Navigation(_package, _request){
var navigation = this;
@ -13,7 +13,11 @@ function Navigation(_package, _request){
this.tocById = {};
if(_package.navPath) {
this.navUrl = URI(_package.navPath).absoluteTo(_package.baseUrl).toString();
if (_package.baseUrl) {
this.navUrl = new URL(_package.navPath, _package.baseUrl).toString();
} else {
this.navUrl = path.resolve(_package.basePath, _package.navPath);
}
this.nav = {};
this.nav.load = function(_request){
@ -32,7 +36,12 @@ function Navigation(_package, _request){
}
if(_package.ncxPath) {
this.ncxUrl = URI(_package.ncxPath).absoluteTo(_package.baseUrl).toString();
if (_package.baseUrl) {
this.ncxUrl = new URL(_package.ncxPath, _package.baseUrl).toString();
} else {
this.ncxUrl = path.resolve(_package.basePath, _package.ncxPath);
}
this.ncx = {};
this.ncx.load = function(_request){

View file

@ -1,4 +1,4 @@
var URI = require('urijs');
var path = require('path');
var core = require('./core');
var EpubCFI = require('./epubcfi');
@ -22,7 +22,7 @@ Parser.prototype.container = function(containerXml){
}
fullpath = rootfile.getAttribute('full-path');
folder = URI(fullpath).directory();
folder = path.dirname(fullpath);
encoding = containerXml.xmlEncoding;
//-- Now that we have the path we can parse the contents

View file

@ -1,5 +1,5 @@
var EventEmitter = require('event-emitter');
var URI = require('urijs');
var path = require('path');
var core = require('./core');
var replace = require('./replacements');
var Hook = require('./hook');
@ -440,7 +440,8 @@ Rendition.prototype.replacements = function(){
// Create blob urls for all the assets
var processing = urls.
map(function(url) {
var absolute = URI(url).absoluteTo(this.book.baseUrl).toString();
// var absolute = new URL(url, this.book.baseUrl).toString();
var absolute = path.resolve(this.book.basePath, url);
// Full url from archive base
return this.book.unarchived.createUrl(absolute, {"base64": this.settings.useBase64});
}.bind(this));
@ -483,15 +484,43 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
var indexInUrls;
// Find the absolute url of the css file
var fileUri = URI(href);
var absolute = fileUri.absoluteTo(this.book.baseUrl).toString();
// var fileUri = URI(href);
// var absolute = fileUri.absoluteTo(this.book.baseUrl).toString();
if (path.isAbsolute(href)) {
return new Promise(function(resolve, reject){
resolve(urls, replacementUrls);
});
}
var fileUri;
var absolute;
if (this.book.baseUrl) {
fileUri = new URL(href, this.book.baseUrl);
absolute = fileUri.toString();
} else {
absolute = path.resolve(this.book.basePath, href);
}
// Get the text of the css file from the archive
var textResponse = this.book.unarchived.getText(absolute);
// Get asset links relative to css file
var relUrls = urls.
map(function(assetHref) {
var assetUri = URI(assetHref).absoluteTo(this.book.baseUrl);
var relative = assetUri.relativeTo(absolute).toString();
// var assetUri = URI(assetHref).absoluteTo(this.book.baseUrl);
// var relative = assetUri.relativeTo(absolute).toString();
var assetUrl;
var relativeUrl;
if (this.book.baseUrl) {
assetUrl = new URL(assetHref, this.book.baseUrl);
relative = path.relative(path.dirname(fileUri.pathname), assetUrl.pathname);
} else {
assetUrl = path.resolve(this.book.basePath, assetHref);
relative = path.relative(path.dirname(absolute), assetUrl);
}
return relative;
}.bind(this));
@ -521,12 +550,32 @@ Rendition.prototype.replaceCss = function(href, urls, replacementUrls){
};
Rendition.prototype.replaceAssets = function(section, urls, replacementUrls){
var fileUri = URI(section.url);
// var fileUri = URI(section.url);
var fileUri;
var absolute;
if (this.book.baseUrl) {
fileUri = new URL(section.url, this.book.baseUrl);
absolute = fileUri.toString();
} else {
absolute = path.resolve(this.book.basePath, section.url);
}
// Get Urls relative to current sections
var relUrls = urls.
map(function(href) {
var assetUri = URI(href).absoluteTo(this.book.baseUrl);
var relative = assetUri.relativeTo(fileUri).toString();
// var assetUri = URI(href).absoluteTo(this.book.baseUrl);
// var relative = assetUri.relativeTo(fileUri).toString();
var assetUrl;
var relativeUrl;
if (this.book.baseUrl) {
assetUrl = new URL(href, this.book.baseUrl);
relative = path.relative(path.dirname(fileUri.pathname), assetUrl.pathname);
} else {
assetUrl = path.resolve(this.book.basePath, href);
relative = path.relative(path.dirname(absolute), assetUrl);
}
return relative;
}.bind(this));

View file

@ -1,4 +1,4 @@
var URI = require('urijs');
// var URI = require('urijs');
var core = require('./core');
function base(doc, section){
@ -54,11 +54,22 @@ function links(view, renderer) {
return;
}
var linkUri = URI(href);
var absolute = linkUri.absoluteTo(view.section.url);
var relative = absolute.relativeTo(this.book.baseUrl).toString();
// var linkUri = URI(href);
// var absolute = linkUri.absoluteTo(view.section.url);
// var relative = absolute.relativeTo(this.book.baseUrl).toString();
var linkUrl;
var linkPath;
var relative;
if(linkUri.protocol()){
if (this.book.baseUrl) {
linkUrl = new URL(href, this.book.baseUrl);
relative = path.relative(path.dirname(linkUrl.pathname), this.book.packagePath);
} else {
linkPath = path.resolve(this.book.basePath, href);
relative = path.relative(this.book.packagePath, linkPath);
}
if(linkUrl && linkUrl.protocol){
link.setAttribute("target", "_blank");
@ -79,14 +90,14 @@ function links(view, renderer) {
}
*/
if(linkUri.fragment()) {
// if(linkUri.fragment()) {
// do nothing with fragment yet
} else {
// } else {
link.onclick = function(){
renderer.display(relative);
return false;
};
}
// }
}
}.bind(this);

View file

@ -1,4 +1,3 @@
var URI = require('urijs');
var core = require('./core');
function request(url, type, withCredentials, headers) {
@ -41,8 +40,9 @@ function request(url, type, withCredentials, headers) {
// If type isn't set, determine it from the file extension
if(!type) {
uri = URI(url);
type = uri.suffix();
// uri = new URI(url);
// type = uri.suffix();
type = core.extension(url);
}
if(type == 'blob'){

View file

@ -1,4 +1,3 @@
var URI = require('urijs');
var core = require('./core');
var EpubCFI = require('./epubcfi');
var Hook = require('./hook');
@ -37,7 +36,7 @@ Section.prototype.load = function(_request){
request(this.url)
.then(function(xml){
var base;
var directory = URI(this.url).directory();
var directory = core.directory(this.url);
this.document = xml;
this.contents = xml.documentElement;

View file

@ -28,7 +28,7 @@ Spine.prototype.load = function(_package) {
this.items = _package.spine;
this.manifest = _package.manifest;
this.spineNodeIndex = _package.spineNodeIndex;
this.baseUrl = _package.baseUrl || '';
this.baseUrl = _package.baseUrl || _package.basePath || '';
this.length = this.items.length;
this.items.forEach(function(item, index){

View file

@ -1,4 +1,3 @@
var URI = require('urijs');
var core = require('./core');
var request = require('./request');
var mime = require('../libs/mime/mime');
@ -41,8 +40,7 @@ Unarchive.prototype.request = function(url, type){
// If type isn't set, determine it from the file extension
if(!type) {
uri = URI(url);
type = uri.suffix();
type = core.extension(url);
}
if(type == 'blob'){

View file

@ -16,7 +16,8 @@ module.exports = {
filename: "[name].js",
sourceMapFilename: "[name].js.map",
library: "ePub",
libraryTarget: "umd"
libraryTarget: "umd",
publicPath: "/dist/"
},
externals: {
"jszip": "JSZip",