epubjs
Version:
Parse and Render Epubs
1,963 lines (1,685 loc) • 872 kB
JavaScript
(function webpackUniversalModuleDefinition(root, factory) {
if(typeof exports === 'object' && typeof module === 'object')
module.exports = factory(require("xmldom"), (function webpackLoadOptionalExternalModule() { try { return require("jszip"); } catch(e) {} }()));
else if(typeof define === 'function' && define.amd)
define(["xmldom", "jszip"], factory);
else if(typeof exports === 'object')
exports["ePub"] = factory(require("xmldom"), (function webpackLoadOptionalExternalModule() { try { return require("jszip"); } catch(e) {} }()));
else
root["ePub"] = factory(root["xmldom"], root["jszip"]);
})(typeof self !== 'undefined' ? self : this, function(__WEBPACK_EXTERNAL_MODULE_371__, __WEBPACK_EXTERNAL_MODULE_401__) {
return /******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ i: moduleId,
/******/ l: false,
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Flag the module as loaded
/******/ module.l = true;
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/******/
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/
/******/ // define getter function for harmony exports
/******/ __webpack_require__.d = function(exports, name, getter) {
/******/ if(!__webpack_require__.o(exports, name)) {
/******/ Object.defineProperty(exports, name, {
/******/ configurable: false,
/******/ enumerable: true,
/******/ get: getter
/******/ });
/******/ }
/******/ };
/******/
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = function(module) {
/******/ var getter = module && module.__esModule ?
/******/ function getDefault() { return module['default']; } :
/******/ function getModuleExports() { return module; };
/******/ __webpack_require__.d(getter, 'a', getter);
/******/ return getter;
/******/ };
/******/
/******/ // Object.prototype.hasOwnProperty.call
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
/******/
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "/dist/";
/******/
/******/ // Load entry module and return exports
/******/ return __webpack_require__(__webpack_require__.s = 148);
/******/ })
/************************************************************************/
/******/ ([
/* 0 */
/***/ (function(module, exports, __webpack_require__) {
var global = __webpack_require__(2);
var core = __webpack_require__(24);
var hide = __webpack_require__(13);
var redefine = __webpack_require__(14);
var ctx = __webpack_require__(19);
var PROTOTYPE = 'prototype';
var $export = function (type, name, source) {
var IS_FORCED = type & $export.F;
var IS_GLOBAL = type & $export.G;
var IS_STATIC = type & $export.S;
var IS_PROTO = type & $export.P;
var IS_BIND = type & $export.B;
var target = IS_GLOBAL ? global : IS_STATIC ? global[name] || (global[name] = {}) : (global[name] || {})[PROTOTYPE];
var exports = IS_GLOBAL ? core : core[name] || (core[name] = {});
var expProto = exports[PROTOTYPE] || (exports[PROTOTYPE] = {});
var key, own, out, exp;
if (IS_GLOBAL) source = name;
for (key in source) {
// contains in native
own = !IS_FORCED && target && target[key] !== undefined;
// export native or passed
out = (own ? target : source)[key];
// bind timers to global for call from export context
exp = IS_BIND && own ? ctx(out, global) : IS_PROTO && typeof out == 'function' ? ctx(Function.call, out) : out;
// extend global
if (target) redefine(target, key, out, type & $export.U);
// export
if (exports[key] != out) hide(exports, key, exp);
if (IS_PROTO && expProto[key] != out) expProto[key] = out;
}
};
global.core = core;
// type bitmap
$export.F = 1; // forced
$export.G = 2; // global
$export.S = 4; // static
$export.P = 8; // proto
$export.B = 16; // bind
$export.W = 32; // wrap
$export.U = 64; // safe
$export.R = 128; // real proto method for `library`
module.exports = $export;
/***/ }),
/* 1 */
/***/ (function(module, exports, __webpack_require__) {
var isObject = __webpack_require__(4);
module.exports = function (it) {
if (!isObject(it)) throw TypeError(it + ' is not an object!');
return it;
};
/***/ }),
/* 2 */
/***/ (function(module, exports) {
// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
var global = module.exports = typeof window != 'undefined' && window.Math == Math
? window : typeof self != 'undefined' && self.Math == Math ? self
// eslint-disable-next-line no-new-func
: Function('return this')();
if (typeof __g == 'number') __g = global; // eslint-disable-line no-undef
/***/ }),
/* 3 */
/***/ (function(module, exports) {
module.exports = function (exec) {
try {
return !!exec();
} catch (e) {
return true;
}
};
/***/ }),
/* 4 */
/***/ (function(module, exports) {
module.exports = function (it) {
return typeof it === 'object' ? it !== null : typeof it === 'function';
};
/***/ }),
/* 5 */
/***/ (function(module, exports, __webpack_require__) {
var store = __webpack_require__(55)('wks');
var uid = __webpack_require__(37);
var Symbol = __webpack_require__(2).Symbol;
var USE_SYMBOL = typeof Symbol == 'function';
var $exports = module.exports = function (name) {
return store[name] || (store[name] =
USE_SYMBOL && Symbol[name] || (USE_SYMBOL ? Symbol : uid)('Symbol.' + name));
};
$exports.store = store;
/***/ }),
/* 6 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
exports.uuid = uuid;
exports.documentHeight = documentHeight;
exports.isElement = isElement;
exports.isNumber = isNumber;
exports.isFloat = isFloat;
exports.prefixed = prefixed;
exports.defaults = defaults;
exports.extend = extend;
exports.insert = insert;
exports.locationOf = locationOf;
exports.indexOfSorted = indexOfSorted;
exports.bounds = bounds;
exports.borders = borders;
exports.nodeBounds = nodeBounds;
exports.windowBounds = windowBounds;
exports.indexOfNode = indexOfNode;
exports.indexOfTextNode = indexOfTextNode;
exports.indexOfElementNode = indexOfElementNode;
exports.isXml = isXml;
exports.createBlob = createBlob;
exports.createBlobUrl = createBlobUrl;
exports.revokeBlobUrl = revokeBlobUrl;
exports.createBase64Url = createBase64Url;
exports.type = type;
exports.parse = parse;
exports.qs = qs;
exports.qsa = qsa;
exports.qsp = qsp;
exports.sprint = sprint;
exports.treeWalker = treeWalker;
exports.walk = walk;
exports.blob2base64 = blob2base64;
exports.defer = defer;
exports.querySelectorByType = querySelectorByType;
exports.findChildren = findChildren;
exports.parents = parents;
exports.filterChildren = filterChildren;
exports.getParentByTagName = getParentByTagName;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
/**
* Core Utilities and Helpers
* @module Core
*/
/**
* Vendor prefixed requestAnimationFrame
* @returns {function} requestAnimationFrame
* @memberof Core
*/
var requestAnimationFrame = exports.requestAnimationFrame = typeof window != "undefined" ? window.requestAnimationFrame || window.mozRequestAnimationFrame || window.webkitRequestAnimationFrame || window.msRequestAnimationFrame : false;
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var COMMENT_NODE = 8;
var DOCUMENT_NODE = 9;
var _URL = typeof URL != "undefined" ? URL : typeof window != "undefined" ? window.URL || window.webkitURL || window.mozURL : undefined;
/**
* Generates a UUID
* based on: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript
* @returns {string} uuid
* @memberof Core
*/
function uuid() {
var d = new Date().getTime();
var uuid = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == "x" ? r : r & 0x7 | 0x8).toString(16);
});
return uuid;
}
/**
* Gets the height of a document
* @returns {number} height
* @memberof Core
*/
function documentHeight() {
return Math.max(document.documentElement.clientHeight, document.body.scrollHeight, document.documentElement.scrollHeight, document.body.offsetHeight, document.documentElement.offsetHeight);
}
/**
* Checks if a node is an element
* @param {object} obj
* @returns {boolean}
* @memberof Core
*/
function isElement(obj) {
return !!(obj && obj.nodeType == 1);
}
/**
* @param {any} n
* @returns {boolean}
* @memberof Core
*/
function isNumber(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
/**
* @param {any} n
* @returns {boolean}
* @memberof Core
*/
function isFloat(n) {
var f = parseFloat(n);
if (isNumber(n) === false) {
return false;
}
if (typeof n === "string" && n.indexOf(".") > -1) {
return true;
}
return Math.floor(f) !== f;
}
/**
* Get a prefixed css property
* @param {string} unprefixed
* @returns {string}
* @memberof Core
*/
function prefixed(unprefixed) {
var vendors = ["Webkit", "webkit", "Moz", "O", "ms"];
var prefixes = ["-webkit-", "-webkit-", "-moz-", "-o-", "-ms-"];
var upper = unprefixed[0].toUpperCase() + unprefixed.slice(1);
var length = vendors.length;
if (typeof document === "undefined" || 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 prefixes[i] + unprefixed;
}
}
return unprefixed;
}
/**
* Apply defaults to an object
* @param {object} obj
* @returns {object}
* @memberof Core
*/
function defaults(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;
}
/**
* Extend properties of an object
* @param {object} target
* @returns {object}
* @memberof Core
*/
function extend(target) {
var sources = [].slice.call(arguments, 1);
sources.forEach(function (source) {
if (!source) return;
Object.getOwnPropertyNames(source).forEach(function (propName) {
Object.defineProperty(target, propName, Object.getOwnPropertyDescriptor(source, propName));
});
});
return target;
}
/**
* Fast quicksort insert for sorted array -- based on:
* http://stackoverflow.com/questions/1344500/efficient-way-to-insert-a-number-into-a-sorted-array-of-numbers
* @param {any} item
* @param {array} array
* @param {function} [compareFunction]
* @returns {number} location (in array)
* @memberof Core
*/
function insert(item, array, compareFunction) {
var location = locationOf(item, array, compareFunction);
array.splice(location, 0, item);
return location;
}
/**
* Finds where something would fit into a sorted array
* @param {any} item
* @param {array} array
* @param {function} [compareFunction]
* @param {function} [_start]
* @param {function} [_end]
* @returns {number} location (in array)
* @memberof Core
*/
function locationOf(item, array, compareFunction, _start, _end) {
var start = _start || 0;
var end = _end || array.length;
var pivot = parseInt(start + (end - start) / 2);
var compared;
if (!compareFunction) {
compareFunction = function compareFunction(a, b) {
if (a > b) return 1;
if (a < b) return -1;
if (a == b) return 0;
};
}
if (end - start <= 0) {
return pivot;
}
compared = compareFunction(array[pivot], item);
if (end - start === 1) {
return compared >= 0 ? pivot : pivot + 1;
}
if (compared === 0) {
return pivot;
}
if (compared === -1) {
return locationOf(item, array, compareFunction, pivot, end);
} else {
return locationOf(item, array, compareFunction, start, pivot);
}
}
/**
* Finds index of something in a sorted array
* Returns -1 if not found
* @param {any} item
* @param {array} array
* @param {function} [compareFunction]
* @param {function} [_start]
* @param {function} [_end]
* @returns {number} index (in array) or -1
* @memberof Core
*/
function indexOfSorted(item, array, compareFunction, _start, _end) {
var start = _start || 0;
var end = _end || array.length;
var pivot = parseInt(start + (end - start) / 2);
var compared;
if (!compareFunction) {
compareFunction = function compareFunction(a, b) {
if (a > b) return 1;
if (a < b) return -1;
if (a == b) return 0;
};
}
if (end - start <= 0) {
return -1; // Not found
}
compared = compareFunction(array[pivot], item);
if (end - start === 1) {
return compared === 0 ? pivot : -1;
}
if (compared === 0) {
return pivot; // Found
}
if (compared === -1) {
return indexOfSorted(item, array, compareFunction, pivot, end);
} else {
return indexOfSorted(item, array, compareFunction, start, pivot);
}
}
/**
* Find the bounds of an element
* taking padding and margin into account
* @param {element} el
* @returns {{ width: Number, height: Number}}
* @memberof Core
*/
function bounds(el) {
var style = window.getComputedStyle(el);
var widthProps = ["width", "paddingRight", "paddingLeft", "marginRight", "marginLeft", "borderRightWidth", "borderLeftWidth"];
var heightProps = ["height", "paddingTop", "paddingBottom", "marginTop", "marginBottom", "borderTopWidth", "borderBottomWidth"];
var width = 0;
var height = 0;
widthProps.forEach(function (prop) {
width += parseFloat(style[prop]) || 0;
});
heightProps.forEach(function (prop) {
height += parseFloat(style[prop]) || 0;
});
return {
height: height,
width: width
};
}
/**
* Find the bounds of an element
* taking padding, margin and borders into account
* @param {element} el
* @returns {{ width: Number, height: Number}}
* @memberof Core
*/
function borders(el) {
var style = window.getComputedStyle(el);
var widthProps = ["paddingRight", "paddingLeft", "marginRight", "marginLeft", "borderRightWidth", "borderLeftWidth"];
var heightProps = ["paddingTop", "paddingBottom", "marginTop", "marginBottom", "borderTopWidth", "borderBottomWidth"];
var width = 0;
var height = 0;
widthProps.forEach(function (prop) {
width += parseFloat(style[prop]) || 0;
});
heightProps.forEach(function (prop) {
height += parseFloat(style[prop]) || 0;
});
return {
height: height,
width: width
};
}
/**
* Find the bounds of any node
* allows for getting bounds of text nodes by wrapping them in a range
* @param {node} node
* @returns {BoundingClientRect}
* @memberof Core
*/
function nodeBounds(node) {
var elPos = void 0;
var doc = node.ownerDocument;
if (node.nodeType == Node.TEXT_NODE) {
var elRange = doc.createRange();
elRange.selectNodeContents(node);
elPos = elRange.getBoundingClientRect();
} else {
elPos = node.getBoundingClientRect();
}
return elPos;
}
/**
* Find the equivelent of getBoundingClientRect of a browser window
* @returns {{ width: Number, height: Number, top: Number, left: Number, right: Number, bottom: Number }}
* @memberof Core
*/
function windowBounds() {
var width = window.innerWidth;
var height = window.innerHeight;
return {
top: 0,
left: 0,
right: width,
bottom: height,
width: width,
height: height
};
}
/**
* Gets the index of a node in its parent
* @param {Node} node
* @param {string} typeId
* @return {number} index
* @memberof Core
*/
function indexOfNode(node, typeId) {
var parent = node.parentNode;
var children = parent.childNodes;
var sib;
var index = -1;
for (var i = 0; i < children.length; i++) {
sib = children[i];
if (sib.nodeType === typeId) {
index++;
}
if (sib == node) break;
}
return index;
}
/**
* Gets the index of a text node in its parent
* @param {node} textNode
* @returns {number} index
* @memberof Core
*/
function indexOfTextNode(textNode) {
return indexOfNode(textNode, TEXT_NODE);
}
/**
* Gets the index of an element node in its parent
* @param {element} elementNode
* @returns {number} index
* @memberof Core
*/
function indexOfElementNode(elementNode) {
return indexOfNode(elementNode, ELEMENT_NODE);
}
/**
* Check if extension is xml
* @param {string} ext
* @returns {boolean}
* @memberof Core
*/
function isXml(ext) {
return ["xml", "opf", "ncx"].indexOf(ext) > -1;
}
/**
* Create a new blob
* @param {any} content
* @param {string} mime
* @returns {Blob}
* @memberof Core
*/
function createBlob(content, mime) {
return new Blob([content], { type: mime });
}
/**
* Create a new blob url
* @param {any} content
* @param {string} mime
* @returns {string} url
* @memberof Core
*/
function createBlobUrl(content, mime) {
var tempUrl;
var blob = createBlob(content, mime);
tempUrl = _URL.createObjectURL(blob);
return tempUrl;
}
/**
* Remove a blob url
* @param {string} url
* @memberof Core
*/
function revokeBlobUrl(url) {
return _URL.revokeObjectURL(url);
}
/**
* Create a new base64 encoded url
* @param {any} content
* @param {string} mime
* @returns {string} url
* @memberof Core
*/
function createBase64Url(content, mime) {
var data;
var datauri;
if (typeof content !== "string") {
// Only handles strings
return;
}
data = btoa(encodeURIComponent(content));
datauri = "data:" + mime + ";base64," + data;
return datauri;
}
/**
* Get type of an object
* @param {object} obj
* @returns {string} type
* @memberof Core
*/
function type(obj) {
return Object.prototype.toString.call(obj).slice(8, -1);
}
/**
* Parse xml (or html) markup
* @param {string} markup
* @param {string} mime
* @param {boolean} forceXMLDom force using xmlDom to parse instead of native parser
* @returns {document} document
* @memberof Core
*/
function parse(markup, mime, forceXMLDom) {
var doc;
var Parser;
if (typeof DOMParser === "undefined" || forceXMLDom) {
Parser = __webpack_require__(371).DOMParser;
} else {
Parser = DOMParser;
}
// Remove byte order mark before parsing
// https://www.w3.org/International/questions/qa-byte-order-mark
if (markup.charCodeAt(0) === 0xFEFF) {
markup = markup.slice(1);
}
doc = new Parser().parseFromString(markup, mime);
return doc;
}
/**
* querySelector polyfill
* @param {element} el
* @param {string} sel selector string
* @returns {element} element
* @memberof Core
*/
function qs(el, sel) {
var elements;
if (!el) {
throw new Error("No Element Provided");
}
if (typeof el.querySelector != "undefined") {
return el.querySelector(sel);
} else {
elements = el.getElementsByTagName(sel);
if (elements.length) {
return elements[0];
}
}
}
/**
* querySelectorAll polyfill
* @param {element} el
* @param {string} sel selector string
* @returns {element[]} elements
* @memberof Core
*/
function qsa(el, sel) {
if (typeof el.querySelector != "undefined") {
return el.querySelectorAll(sel);
} else {
return el.getElementsByTagName(sel);
}
}
/**
* querySelector by property
* @param {element} el
* @param {string} sel selector string
* @param {object[]} props
* @returns {element[]} elements
* @memberof Core
*/
function qsp(el, sel, props) {
var q, filtered;
if (typeof el.querySelector != "undefined") {
sel += "[";
for (var prop in props) {
sel += prop + "~='" + props[prop] + "'";
}
sel += "]";
return el.querySelector(sel);
} else {
q = el.getElementsByTagName(sel);
filtered = Array.prototype.slice.call(q, 0).filter(function (el) {
for (var prop in props) {
if (el.getAttribute(prop) === props[prop]) {
return true;
}
}
return false;
});
if (filtered) {
return filtered[0];
}
}
}
/**
* Sprint through all text nodes in a document
* @memberof Core
* @param {element} root element to start with
* @param {function} func function to run on each element
*/
function sprint(root, func) {
var doc = root.ownerDocument || root;
if (typeof doc.createTreeWalker !== "undefined") {
treeWalker(root, func, NodeFilter.SHOW_TEXT);
} else {
walk(root, function (node) {
if (node && node.nodeType === 3) {
// Node.TEXT_NODE
func(node);
}
}, true);
}
}
/**
* Create a treeWalker
* @memberof Core
* @param {element} root element to start with
* @param {function} func function to run on each element
* @param {function | object} filter funtion or object to filter with
*/
function treeWalker(root, func, filter) {
var treeWalker = document.createTreeWalker(root, filter, null, false);
var node = void 0;
while (node = treeWalker.nextNode()) {
func(node);
}
}
/**
* @memberof Core
* @param {node} node
* @param {callback} return false for continue,true for break inside callback
*/
function walk(node, callback) {
if (callback(node)) {
return true;
}
node = node.firstChild;
if (node) {
do {
var walked = walk(node, callback);
if (walked) {
return true;
}
node = node.nextSibling;
} while (node);
}
}
/**
* Convert a blob to a base64 encoded string
* @param {Blog} blob
* @returns {string}
* @memberof Core
*/
function blob2base64(blob) {
return new Promise(function (resolve, reject) {
var reader = new FileReader();
reader.readAsDataURL(blob);
reader.onloadend = function () {
resolve(reader.result);
};
});
}
/**
* Creates a new pending promise and provides methods to resolve or reject it.
* From: https://developer.mozilla.org/en-US/docs/Mozilla/JavaScript_code_modules/Promise.jsm/Deferred#backwards_forwards_compatible
* @memberof Core
*/
function defer() {
var _this = this;
/* A method to resolve the associated Promise with the value passed.
* If the promise is already settled it does nothing.
*
* @param {anything} value : This value is used to resolve the promise
* If the value is a Promise then the associated promise assumes the state
* of Promise passed as value.
*/
this.resolve = null;
/* A method to reject the assocaited Promise with the value passed.
* If the promise is already settled it does nothing.
*
* @param {anything} reason: The reason for the rejection of the Promise.
* Generally its an Error object. If however a Promise is passed, then the Promise
* itself will be the reason for rejection no matter the state of the Promise.
*/
this.reject = null;
this.id = uuid();
/* A newly created Pomise object.
* Initially in pending state.
*/
this.promise = new Promise(function (resolve, reject) {
_this.resolve = resolve;
_this.reject = reject;
});
Object.freeze(this);
}
/**
* querySelector with filter by epub type
* @param {element} html
* @param {string} element element type to find
* @param {string} type epub type to find
* @returns {element[]} elements
* @memberof Core
*/
function querySelectorByType(html, element, type) {
var query;
if (typeof html.querySelector != "undefined") {
query = html.querySelector(element + "[*|type=\"" + type + "\"]");
}
// Handle IE not supporting namespaced epub:type in querySelector
if (!query || query.length === 0) {
query = qsa(html, element);
for (var i = 0; i < query.length; i++) {
if (query[i].getAttributeNS("http://www.idpf.org/2007/ops", "type") === type || query[i].getAttribute("epub:type") === type) {
return query[i];
}
}
} else {
return query;
}
}
/**
* Find direct decendents of an element
* @param {element} el
* @returns {element[]} children
* @memberof Core
*/
function findChildren(el) {
var result = [];
var childNodes = el.childNodes;
for (var i = 0; i < childNodes.length; i++) {
var node = childNodes[i];
if (node.nodeType === 1) {
result.push(node);
}
}
return result;
}
/**
* Find all parents (ancestors) of an element
* @param {element} node
* @returns {element[]} parents
* @memberof Core
*/
function parents(node) {
var nodes = [node];
for (; node; node = node.parentNode) {
nodes.unshift(node);
}
return nodes;
}
/**
* Find all direct decendents of a specific type
* @param {element} el
* @param {string} nodeName
* @param {boolean} [single]
* @returns {element[]} children
* @memberof Core
*/
function filterChildren(el, nodeName, single) {
var result = [];
var childNodes = el.childNodes;
for (var i = 0; i < childNodes.length; i++) {
var node = childNodes[i];
if (node.nodeType === 1 && node.nodeName.toLowerCase() === nodeName) {
if (single) {
return node;
} else {
result.push(node);
}
}
}
if (!single) {
return result;
}
}
/**
* Filter all parents (ancestors) with tag name
* @param {element} node
* @param {string} tagname
* @returns {element[]} parents
* @memberof Core
*/
function getParentByTagName(node, tagname) {
var parent = void 0;
if (node === null || tagname === '') return;
parent = node.parentNode;
while (parent.nodeType === 1) {
if (parent.tagName.toLowerCase() === tagname) {
return parent;
}
parent = parent.parentNode;
}
}
/**
* Lightweight Polyfill for DOM Range
* @class
* @memberof Core
*/
var RangeObject = exports.RangeObject = function () {
function RangeObject() {
_classCallCheck(this, RangeObject);
this.collapsed = false;
this.commonAncestorContainer = undefined;
this.endContainer = undefined;
this.endOffset = undefined;
this.startContainer = undefined;
this.startOffset = undefined;
}
_createClass(RangeObject, [{
key: "setStart",
value: function setStart(startNode, startOffset) {
this.startContainer = startNode;
this.startOffset = startOffset;
if (!this.endContainer) {
this.collapse(true);
} else {
this.commonAncestorContainer = this._commonAncestorContainer();
}
this._checkCollapsed();
}
}, {
key: "setEnd",
value: function setEnd(endNode, endOffset) {
this.endContainer = endNode;
this.endOffset = endOffset;
if (!this.startContainer) {
this.collapse(false);
} else {
this.collapsed = false;
this.commonAncestorContainer = this._commonAncestorContainer();
}
this._checkCollapsed();
}
}, {
key: "collapse",
value: function collapse(toStart) {
this.collapsed = true;
if (toStart) {
this.endContainer = this.startContainer;
this.endOffset = this.startOffset;
this.commonAncestorContainer = this.startContainer.parentNode;
} else {
this.startContainer = this.endContainer;
this.startOffset = this.endOffset;
this.commonAncestorContainer = this.endOffset.parentNode;
}
}
}, {
key: "selectNode",
value: function selectNode(referenceNode) {
var parent = referenceNode.parentNode;
var index = Array.prototype.indexOf.call(parent.childNodes, referenceNode);
this.setStart(parent, index);
this.setEnd(parent, index + 1);
}
}, {
key: "selectNodeContents",
value: function selectNodeContents(referenceNode) {
var end = referenceNode.childNodes[referenceNode.childNodes - 1];
var endIndex = referenceNode.nodeType === 3 ? referenceNode.textContent.length : parent.childNodes.length;
this.setStart(referenceNode, 0);
this.setEnd(referenceNode, endIndex);
}
}, {
key: "_commonAncestorContainer",
value: function _commonAncestorContainer(startContainer, endContainer) {
var startParents = parents(startContainer || this.startContainer);
var endParents = parents(endContainer || this.endContainer);
if (startParents[0] != endParents[0]) return undefined;
for (var i = 0; i < startParents.length; i++) {
if (startParents[i] != endParents[i]) {
return startParents[i - 1];
}
}
}
}, {
key: "_checkCollapsed",
value: function _checkCollapsed() {
if (this.startContainer === this.endContainer && this.startOffset === this.endOffset) {
this.collapsed = true;
} else {
this.collapsed = false;
}
}
}, {
key: "toString",
value: function toString() {
// TODO: implement walking between start and end to find text
}
}]);
return RangeObject;
}();
/***/ }),
/* 7 */
/***/ (function(module, exports, __webpack_require__) {
// Thank's IE8 for his funny defineProperty
module.exports = !__webpack_require__(3)(function () {
return Object.defineProperty({}, 'a', { get: function () { return 7; } }).a != 7;
});
/***/ }),
/* 8 */
/***/ (function(module, exports, __webpack_require__) {
var anObject = __webpack_require__(1);
var IE8_DOM_DEFINE = __webpack_require__(107);
var toPrimitive = __webpack_require__(25);
var dP = Object.defineProperty;
exports.f = __webpack_require__(7) ? Object.defineProperty : function defineProperty(O, P, Attributes) {
anObject(O);
P = toPrimitive(P, true);
anObject(Attributes);
if (IE8_DOM_DEFINE) try {
return dP(O, P, Attributes);
} catch (e) { /* empty */ }
if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported!');
if ('value' in Attributes) O[P] = Attributes.value;
return O;
};
/***/ }),
/* 9 */
/***/ (function(module, exports, __webpack_require__) {
// 7.1.15 ToLength
var toInteger = __webpack_require__(27);
var min = Math.min;
module.exports = function (it) {
return it > 0 ? min(toInteger(it), 0x1fffffffffffff) : 0; // pow(2, 53) - 1 == 9007199254740991
};
/***/ }),
/* 10 */
/***/ (function(module, exports, __webpack_require__) {
// 7.1.13 ToObject(argument)
var defined = __webpack_require__(26);
module.exports = function (it) {
return Object(defined(it));
};
/***/ }),
/* 11 */
/***/ (function(module, exports) {
module.exports = function (it) {
if (typeof it != 'function') throw TypeError(it + ' is not a function!');
return it;
};
/***/ }),
/* 12 */
/***/ (function(module, exports) {
var hasOwnProperty = {}.hasOwnProperty;
module.exports = function (it, key) {
return hasOwnProperty.call(it, key);
};
/***/ }),
/* 13 */
/***/ (function(module, exports, __webpack_require__) {
var dP = __webpack_require__(8);
var createDesc = __webpack_require__(36);
module.exports = __webpack_require__(7) ? function (object, key, value) {
return dP.f(object, key, createDesc(1, value));
} : function (object, key, value) {
object[key] = value;
return object;
};
/***/ }),
/* 14 */
/***/ (function(module, exports, __webpack_require__) {
var global = __webpack_require__(2);
var hide = __webpack_require__(13);
var has = __webpack_require__(12);
var SRC = __webpack_require__(37)('src');
var TO_STRING = 'toString';
var $toString = Function[TO_STRING];
var TPL = ('' + $toString).split(TO_STRING);
__webpack_require__(24).inspectSource = function (it) {
return $toString.call(it);
};
(module.exports = function (O, key, val, safe) {
var isFunction = typeof val == 'function';
if (isFunction) has(val, 'name') || hide(val, 'name', key);
if (O[key] === val) return;
if (isFunction) has(val, SRC) || hide(val, SRC, O[key] ? '' + O[key] : TPL.join(String(key)));
if (O === global) {
O[key] = val;
} else if (!safe) {
delete O[key];
hide(O, key, val);
} else if (O[key]) {
O[key] = val;
} else {
hide(O, key, val);
}
// add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
})(Function.prototype, TO_STRING, function toString() {
return typeof this == 'function' && this[SRC] || $toString.call(this);
});
/***/ }),
/* 15 */
/***/ (function(module, exports, __webpack_require__) {
// to indexed object, toObject with fallback for non-array-like ES3 strings
var IObject = __webpack_require__(52);
var defined = __webpack_require__(26);
module.exports = function (it) {
return IObject(defined(it));
};
/***/ }),
/* 16 */
/***/ (function(module, exports, __webpack_require__) {
var $export = __webpack_require__(0);
var fails = __webpack_require__(3);
var defined = __webpack_require__(26);
var quot = /"/g;
// B.2.3.2.1 CreateHTML(string, tag, attribute, value)
var createHTML = function (string, tag, attribute, value) {
var S = String(defined(string));
var p1 = '<' + tag;
if (attribute !== '') p1 += ' ' + attribute + '="' + String(value).replace(quot, '"') + '"';
return p1 + '>' + S + '</' + tag + '>';
};
module.exports = function (NAME, exec) {
var O = {};
O[NAME] = exec(createHTML);
$export($export.P + $export.F * fails(function () {
var test = ''[NAME]('"');
return test !== test.toLowerCase() || test.split('"').length > 3;
}), 'String', O);
};
/***/ }),
/* 17 */
/***/ (function(module, exports, __webpack_require__) {
var pIE = __webpack_require__(53);
var createDesc = __webpack_require__(36);
var toIObject = __webpack_require__(15);
var toPrimitive = __webpack_require__(25);
var has = __webpack_require__(12);
var IE8_DOM_DEFINE = __webpack_require__(107);
var gOPD = Object.getOwnPropertyDescriptor;
exports.f = __webpack_require__(7) ? gOPD : function getOwnPropertyDescriptor(O, P) {
O = toIObject(O);
P = toPrimitive(P, true);
if (IE8_DOM_DEFINE) try {
return gOPD(O, P);
} catch (e) { /* empty */ }
if (has(O, P)) return createDesc(!pIE.f.call(O, P), O[P]);
};
/***/ }),
/* 18 */
/***/ (function(module, exports, __webpack_require__) {
// 19.1.2.9 / 15.2.3.2 Object.getPrototypeOf(O)
var has = __webpack_require__(12);
var toObject = __webpack_require__(10);
var IE_PROTO = __webpack_require__(76)('IE_PROTO');
var ObjectProto = Object.prototype;
module.exports = Object.getPrototypeOf || function (O) {
O = toObject(O);
if (has(O, IE_PROTO)) return O[IE_PROTO];
if (typeof O.constructor == 'function' && O instanceof O.constructor) {
return O.constructor.prototype;
} return O instanceof Object ? ObjectProto : null;
};
/***/ }),
/* 19 */
/***/ (function(module, exports, __webpack_require__) {
// optional / simple context binding
var aFunction = __webpack_require__(11);
module.exports = function (fn, that, length) {
aFunction(fn);
if (that === undefined) return fn;
switch (length) {
case 1: return function (a) {
return fn.call(that, a);
};
case 2: return function (a, b) {
return fn.call(that, a, b);
};
case 3: return function (a, b, c) {
return fn.call(that, a, b, c);
};
}
return function (/* ...args */) {
return fn.apply(that, arguments);
};
};
/***/ }),
/* 20 */
/***/ (function(module, exports) {
var toString = {}.toString;
module.exports = function (it) {
return toString.call(it).slice(8, -1);
};
/***/ }),
/* 21 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
var fails = __webpack_require__(3);
module.exports = function (method, arg) {
return !!method && fails(function () {
// eslint-disable-next-line no-useless-call
arg ? method.call(null, function () { /* empty */ }, 1) : method.call(null);
});
};
/***/ }),
/* 22 */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
var _core = __webpack_require__(6);
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var COMMENT_NODE = 8;
var DOCUMENT_NODE = 9;
/**
* Parsing and creation of EpubCFIs: http://www.idpf.org/epub/linking/cfi/epub-cfi.html
* Implements:
* - Character Offset: epubcfi(/6/4[chap01ref]!/4[body01]/10[para05]/2/1:3)
* - Simple Ranges : epubcfi(/6/4[chap01ref]!/4[body01]/10[para05],/2/1:1,/3:4)
* Does Not Implement:
* - Temporal Offset (~)
* - Spatial Offset (@)
* - Temporal-Spatial Offset (~ + @)
* - Text Location Assertion ([)
* @class
@param {string | Range | Node } [cfiFrom]
@param {string | object} [base]
@param {string} [ignoreClass] class to ignore when parsing DOM
*/
var EpubCFI = function () {
function EpubCFI(cfiFrom, base, ignoreClass) {
_classCallCheck(this, EpubCFI);
var type;
this.str = "";
this.base = {};
this.spinePos = 0; // For compatibility
this.range = false; // true || false;
this.path = {};
this.start = null;
this.end = null;
// Allow instantiation without the "new" keyword
if (!(this instanceof EpubCFI)) {
return new EpubCFI(cfiFrom, base, ignoreClass);
}
if (typeof base === "string") {
this.base = this.parseComponent(base);
} else if ((typeof base === "undefined" ? "undefined" : _typeof(base)) === "object" && base.steps) {
this.base = base;
}
type = this.checkType(cfiFrom);
if (type === "string") {
this.str = cfiFrom;
return (0, _core.extend)(this, this.parse(cfiFrom));
} else if (type === "range") {
return (0, _core.extend)(this, this.fromRange(cfiFrom, this.base, ignoreClass));
} else if (type === "node") {
return (0, _core.extend)(this, this.fromNode(cfiFrom, this.base, ignoreClass));
} else if (type === "EpubCFI" && cfiFrom.path) {
return cfiFrom;
} else if (!cfiFrom) {
return this;
} else {
throw new TypeError("not a valid argument for EpubCFI");
}
}
/**
* Check the type of constructor input
* @private
*/
_createClass(EpubCFI, [{
key: "checkType",
value: function checkType(cfi) {
if (this.isCfiString(cfi)) {
return "string";
// Is a range object
} else if (cfi && (typeof cfi === "undefined" ? "undefined" : _typeof(cfi)) === "object" && ((0, _core.type)(cfi) === "Range" || typeof cfi.startContainer != "undefined")) {
return "range";
} else if (cfi && (typeof cfi === "undefined" ? "undefined" : _typeof(cfi)) === "object" && typeof cfi.nodeType != "undefined") {
// || typeof cfi === "function"
return "node";
} else if (cfi && (typeof cfi === "undefined" ? "undefined" : _typeof(cfi)) === "object" && cfi instanceof EpubCFI) {
return "EpubCFI";
} else {
return false;
}
}
/**
* Parse a cfi string to a CFI object representation
* @param {string} cfiStr
* @returns {object} cfi
*/
}, {
key: "parse",
value: function parse(cfiStr) {
var cfi = {
spinePos: -1,
range: false,
base: {},
path: {},
start: null,
end: null
};
var baseComponent, pathComponent, range;
if (typeof cfiStr !== "string") {
return { spinePos: -1 };
}
if (cfiStr.indexOf("epubcfi(") === 0 && cfiStr[cfiStr.length - 1] === ")") {
// Remove intial epubcfi( and ending )
cfiStr = cfiStr.slice(8, cfiStr.length - 1);
}
baseComponent = this.getChapterComponent(cfiStr);
// Make sure this is a valid cfi or return
if (!baseComponent) {
return { spinePos: -1 };
}
cfi.base = this.parseComponent(baseComponent);
pathComponent = this.getPathComponent(cfiStr);
cfi.path = this.parseComponent(pathComponent);
range = this.getRange(cfiStr);
if (range) {
cfi.range = true;
cfi.start = this.parseComponent(range[0]);
cfi.end = this.parseComponent(range[1]);
}
// Get spine node position
// cfi.spineSegment = cfi.base.steps[1];
// Chapter segment is always the second step
cfi.spinePos = cfi.base.steps[1].index;
return cfi;
}
}, {
key: "parseComponent",
value: function parseComponent(componentStr) {
var component = {
steps: [],
terminal: {
offset: null,
assertion: null
}
};
var parts = componentStr.split(":");
var steps = parts[0].split("/");
var terminal;
if (parts.length > 1) {
terminal = parts[1];
component.terminal = this.parseTerminal(terminal);
}
if (steps[0] === "") {
steps.shift(); // Ignore the first slash
}
component.steps = steps.map(function (step) {
return this.parseStep(step);
}.bind(this));
return component;
}
}, {
key: "parseStep",
value: function parseStep(stepStr) {
var type, num, index, has_brackets, id;
has_brackets = stepStr.match(/\[(.*)\]/);
if (has_brackets && has_brackets[1]) {
id = has_brackets[1];
}
//-- Check if step is a text node or element
num = parseInt(stepStr);
if (isNaN(num)) {
return;
}
if (num % 2 === 0) {
// Even = is an element
type = "element";
index = num / 2 - 1;
} else {
type = "text";
index = (num - 1) / 2;
}
return {
"type": type,
"index": index,
"id": id || null
};
}
}, {
key: "parseTerminal",
value: function parseTerminal(termialStr) {
var characterOffset, textLocationAssertion;
var assertion = termialStr.match(/\[(.*)\]/);
if (assertion && assertion[1]) {
characterOffset = parseInt(termialStr.split("[")[0]);
textLocationAssertion = assertion[1];
} else {
characterOffset = parseInt(termialStr);
}
if (!(0, _core.isNumber)(characterOffset)) {
characterOffset = null;
}
return {
"offset": characterOffset,
"assertion": textLocationAssertion
};
}
}, {
key: "getChapterComponent",
value: function getChapterComponent(cfiStr) {
var indirection = cfiStr.split("!");
return indirection[0];
}
}, {
key: "getPathComponent",
value: function getPathComponent(cfiStr) {
var indirection = cfiStr.split("!");
if (indirection[1]) {
var ranges = indirection[1].split(",");
return ranges[0];
}
}
}, {
key: "getRange",
value: function getRange(cfiStr) {
var ranges = cfiStr.split(",");
if (ranges.length === 3) {
return [ranges[1], ranges[2]];
}
return false;
}
}, {
key: "getCharecterOffsetComponent",
value: function getCharecterOffsetComponent(cfiStr) {
var splitStr = cfiStr.split(":");
return splitStr[1] || "";
}
}, {
key: "joinSteps",
value: function joinSteps(steps) {
if (!steps) {
return "";
}
return steps.map(function (part) {
var segment = "";
if (part.type === "element") {
segment += (part.index + 1) * 2;
}
if (part.type === "text") {
segment += 1 + 2 * part.index; // TODO: double check that this is odd
}
if (part.id) {
segment += "[" + part.id + "]";
}
return segment;
}).join("/");
}
}, {
key: "segmentString",
value: function segmentString(segment) {
var segmentString = "/";
segmentString += this.joinSteps(segment.steps);
if (segment.terminal && segment.terminal.offset != null) {
segmentString += ":" + segment.terminal.offset;
}
if (segment.terminal && segment.terminal.assertion != null) {
segmentString += "[" + segment.terminal.assertion + "]";
}
return segmentString;
}
/**
* Convert CFI to a epubcfi(...) string
* @returns {string} epubcfi
*/
}, {
key: "toString",
value: function toString() {
var cfiString = "epubcfi(";
cfiString += this.segmentString(this.base);
cfiString += "!";
cfiString += this.segmentString(this.path);
// Add Range, if present
if (this.range && this.start) {
cfiString += ",";
cfiString += this.segmentString(this.start);
}
if (this.range && this.end) {
cfiString += ",";
cfiString += this.segmentString(this.end);
}
cfiString += ")";
return cfiString;
}
/**
* Compare which of two CFIs is earlier in the text
* @returns {number} First is earlier = -1, Second is earlier = 1, They are equal = 0
*/
}, {
key: "compare",
value: function compare(cfiOne, cfiTwo) {
var stepsA, stepsB;
var terminalA, terminalB;
var rangeAStartSteps, rangeAEndSteps;
var rangeBEndSteps, rangeBEndSteps;
var rangeAStartTerminal, rangeAEndTerminal;
var rangeBStartTerminal, rangeBEndTerminal;
if (typeof cfiOne === "string") {
cfiOne = new EpubCFI(cfiOne);
}
if (typeof cfiTwo === "string") {
cfiTwo = new EpubCFI(cfiTwo);
}
// Compare Spine Positions
if (cfiOne.spinePos > cfiTwo.spinePos) {
return 1;
}
if (cfiOne.spinePos < cfiTwo.spinePos) {
return -1;
}
if (cfiOne.range) {
stepsA = cfiOne.path.steps.concat(cfiOne.start.steps);
terminalA = cfiOne.start.terminal;
} else {
stepsA = cfiOne.path.steps;
terminalA = cfiOne.path.terminal;
}
if (cfiTwo.range) {
stepsB = cfiTwo.path.steps.concat(cfiTwo.start.steps);
terminalB = cfiTwo.start.terminal;
} else {
stepsB = cfiTwo.path.steps;
terminalB = cfiTwo.path.terminal;
}
// Compare Each Step in the First item
for (var i = 0; i < stepsA.length; i++) {
if (!stepsA[i]) {
return -1;
}
if (!stepsB[i]) {
return 1;
}
if (stepsA[i].index > stepsB[i].index) {
return 1;
}
if (stepsA[i].index < stepsB[i].index) {
return -1;
}
// Otherwise continue checking
}
// All steps in First equal to Second and First is Less Specific
if (stepsA.length < stepsB.length) {
return 1;
}
// Compare the charecter offset of the text node
if (terminalA.offset > terminalB.offset) {
return 1;
}
if (terminalA.offset < terminalB.offset) {
return -1;
}
// CFI's are equal
return 0;
}
}, {
key: "step",
value: function step(node) {
var nodeType = node.nodeType === TEXT_NODE ? "text" : "element";
return {
"id": node.id,
"tagName": node.tagName,
"type": nodeType,
"index": this.position(node)
};
}
}, {
key: "filteredStep",
value: function filteredStep(node, ignoreClass) {
var filteredNode = this.filter(node, ignoreClass);
var nodeType;
// Node filtered, so ignore
if (!filteredNode) {
return;
}
// Otherwise add the filter node in
nodeType = filteredNode.nodeType === TEXT_NODE ? "text" : "element";
return {
"id": filteredNode.id,
"tagName": filteredNode.tagName,
"type": nodeType,
"index": this.filteredPosition(filteredNode, ignoreClass)
};
}
}, {
key: "pathTo",
value: function pathTo(node, offset, ignoreClass) {
var segment = {
steps: [],
terminal: {
offset: null,
assertion: null
}
};
var currentNode = node;
var step;
while (currentNode && currentNode.parentNode && currentNode.parentNode.nodeType != DOCUMENT_NODE) {
if (ignoreClass) {
step = this.filteredStep(currentNode, ignoreClass);
} else {
step = this.step(currentNode);
}
if (step) {
segment.steps.unshift(step);
}
currentNode = currentNode.parentNode;
}
if (offset != null && offset >= 0) {
segment.terminal.offset = offset;
// Make sure we are getting to a textNode if there is an offset
if (segment.steps[segment.steps.length - 1].type != "text") {
segment.steps.push({
"type": "text",
"index": 0
});
}
}
return segment;
}
}, {
key: "equalStep",
value: function equalStep(stepA, stepB) {
if (!stepA || !stepB) {
return false;
}
if (stepA.index === stepB.index && stepA.id === stepB.id && stepA.type === stepB.type) {
return true;
}
return false;
}
/**
* Create a CFI object from a Range
* @param {Range} range
* @param {string | object} base
* @param {string} [ignoreClass]
* @returns {object} cfi
*/
}, {
key: "fromRange",
value: function fromRange(range, base, ignoreClass) {
var cfi = {
range: false,
base: {},
path: {},
start: null,
end: null
};
var start = range.startContainer;
var end = range.endContainer;
var startOffset = range.startOffset;
var endOffset = range.endOffset;
var needsIgnoring = false;
if (ignoreClass) {
// Tell pathTo if / what to ignore
needsIgnoring = start.ownerDocument.querySelector("." + ignoreClass) != null;
}
if (typeof base === "string") {
cfi.base = this.parseComponent(base);
cfi.spinePos = cfi.base.steps[1].index;
} else if ((typeof base === "undefined" ? "undefined" : _typeof(base)) === "object") {
cfi.base = base;
}
if (range.collapsed) {
if (needsIgnoring) {
startOffset = this.patchOffset(start, startOffset, ignoreClass);
}
cfi.path = this.pathTo(start, startOffset, ignoreClass);
} else {
cfi.range = true;
if (needsIgnoring) {
startOffset = this.patchOffset(start, startOffset, ignoreClass);
}
cfi.start = this.pathTo(start, startOffset, ignoreClass);
if (needsIgn