diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/epub.js/dist/epub.js | 136 | ||||
| -rw-r--r-- | lib/epub.js/src/managers/default/index.js | 18 |
2 files changed, 97 insertions, 57 deletions
diff --git a/lib/epub.js/dist/epub.js b/lib/epub.js/dist/epub.js index 7f433f7..d9b571c 100644 --- a/lib/epub.js/dist/epub.js +++ b/lib/epub.js/dist/epub.js @@ -600,14 +600,14 @@ NodeList.prototype = { * The number of nodes in the list. The range of valid child node indices is 0 to length-1 inclusive. * @standard level1 */ - length:0, + length:0, /** * Returns the indexth item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null. * @standard level1 - * @param index unsigned long + * @param index unsigned long * Index into the collection. * @return Node - * The node at the indexth position in the NodeList, or null if that is not a valid index. + * The node at the indexth position in the NodeList, or null if that is not a valid index. */ item: function(index) { return this[index] || null; @@ -651,7 +651,7 @@ _extends(LiveNodeList,NodeList); * but this is simply to allow convenient enumeration of the contents of a NamedNodeMap, * and does not imply that the DOM specifies an order to these Nodes. * NamedNodeMap objects in the DOM are live. - * used for attributes or DocumentType entities + * used for attributes or DocumentType entities */ function NamedNodeMap() { }; @@ -740,10 +740,10 @@ NamedNodeMap.prototype = { var attr = this.getNamedItem(key); _removeNamedNode(this._ownerElement,this,attr); return attr; - - + + },// raises: NOT_FOUND_ERR,NO_MODIFICATION_ALLOWED_ERR - + //for level2 removeNamedItemNS:function(namespaceURI,localName){ var attr = this.getNamedItemNS(namespaceURI,localName); @@ -889,10 +889,10 @@ Node.prototype = { prefix : null, localName : null, // Modified in DOM Level 2: - insertBefore:function(newChild, refChild){//raises + insertBefore:function(newChild, refChild){//raises return _insertBefore(this,newChild,refChild); }, - replaceChild:function(newChild, oldChild){//raises + replaceChild:function(newChild, oldChild){//raises this.insertBefore(newChild,oldChild); if(oldChild){ this.removeChild(oldChild); @@ -1058,7 +1058,7 @@ function _onUpdateChild(doc,el,newChild){ /** * attributes; * children; - * + * * writeable properties: * nodeValue,Attr:value,CharacterData:data * prefix @@ -1100,8 +1100,8 @@ function _insertBefore(parentNode,newChild,nextChild){ newFirst.previousSibling = pre; newLast.nextSibling = nextChild; - - + + if(pre){ pre.nextSibling = newFirst; }else{ @@ -1365,7 +1365,7 @@ Element.prototype = { var attr = this.getAttributeNode(name) attr && this.removeAttributeNode(attr); }, - + //four real opeartion method appendChild:function(newChild){ if(newChild.nodeType === DOCUMENT_FRAGMENT_NODE){ @@ -1389,7 +1389,7 @@ Element.prototype = { var old = this.getAttributeNodeNS(namespaceURI, localName); old && this.removeAttributeNode(old); }, - + hasAttributeNS : function(namespaceURI, localName){ return this.getAttributeNodeNS(namespaceURI, localName)!=null; }, @@ -1405,7 +1405,7 @@ Element.prototype = { getAttributeNodeNS : function(namespaceURI, localName){ return this.attributes.getNamedItemNS(namespaceURI, localName); }, - + getElementsByTagName : function(tagName){ return new LiveNodeList(this,function(base){ var ls = []; @@ -1426,7 +1426,7 @@ Element.prototype = { } }); return ls; - + }); } }; @@ -1455,7 +1455,7 @@ CharacterData.prototype = { }, insertData: function(offset,text) { this.replaceData(offset,0,text); - + }, appendChild:function(newChild){ throw new Error(ExceptionMessage[HIERARCHY_REQUEST_ERR]) @@ -1549,7 +1549,7 @@ function nodeSerializeToString(isHtml,nodeFilter){ var refNode = this.nodeType == 9 && this.documentElement || this; var prefix = refNode.prefix; var uri = refNode.namespaceURI; - + if(uri && prefix == null){ //console.log(prefix) var prefix = refNode.lookupPrefix(uri); @@ -1582,8 +1582,8 @@ function needNamespaceDefine(node, isHTML, visibleNamespaces) { if (prefix === "xml" && uri === NAMESPACE.XML || uri === NAMESPACE.XMLNS) { return false; } - - var i = visibleNamespaces.length + + var i = visibleNamespaces.length while (i--) { var ns = visibleNamespaces[i]; // get namespace prefix @@ -1627,7 +1627,7 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){ var len = attrs.length; var child = node.firstChild; var nodeName = node.tagName; - + isHTML = NAMESPACE.isHTML(node.namespaceURI) || isHTML var prefixedNodeName = nodeName @@ -1686,14 +1686,14 @@ function serializeToString(node,buf,isHTML,nodeFilter,visibleNamespaces){ serializeToString(attr,buf,isHTML,nodeFilter,visibleNamespaces); } - // add namespace for current node + // add namespace for current node if (nodeName === prefixedNodeName && needNamespaceDefine(node, isHTML, visibleNamespaces)) { var prefix = node.prefix||''; var uri = node.namespaceURI; addSerializedAttribute(buf, prefix ? 'xmlns:' + prefix : "xmlns", uri); visibleNamespaces.push({ prefix: prefix, namespace:uri }); } - + if(child || isHTML && !/^(?:meta|link|img|br|hr|input)$/i.test(nodeName)){ buf.push('>'); //if is cdata child node @@ -1906,7 +1906,7 @@ try{ } } }) - + function getTextContent(node){ switch(node.nodeType){ case ELEMENT_NODE: @@ -2255,7 +2255,7 @@ var tagNamePattern = new RegExp('^'+nameStartChar.source+nameChar.source+'*(?:\: //S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE //S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE var S_TAG = 0;//tag name offerring -var S_ATTR = 1;//attr name offerring +var S_ATTR = 1;//attr name offerring var S_ATTR_SPACE=2;//attr name end and space offer var S_EQ = 3;//=space? var S_ATTR_NOQUOT_VALUE = 4;//attr value(no quot value only) @@ -2279,7 +2279,7 @@ ParseError.prototype = new Error(); ParseError.prototype.name = ParseError.name function XMLReader(){ - + } XMLReader.prototype = { @@ -2309,7 +2309,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){ function entityReplacer(a){ var k = a.slice(1,-1); if(k in entityMap){ - return entityMap[k]; + return entityMap[k]; }else if(k.charAt(0) === '#'){ return fixedFromCharCode(parseInt(k.substr(1).replace('x','0x'))) }else{ @@ -2338,7 +2338,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){ var lineEnd = 0; var linePattern = /.*(?:\r\n?|\n)|.*$/g var locator = domBuilder.locator; - + var parseStack = [{currentNSMap:defaultNSMapCopy}] var closeMap = {}; var start = 0; @@ -2363,7 +2363,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){ var tagName = source.substring(tagStart + 2, end).replace(/[ \t\n\r]+$/g, ''); var config = parseStack.pop(); if(end<0){ - + tagName = source.substring(tagStart+2).replace(/[\s<].*/,''); errorHandler.error("end tag name: "+tagName+' is not complete:'+config.tagName); end = tagStart+1+tagName.length; @@ -2388,7 +2388,7 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){ }else{ parseStack.push(config) } - + end++; break; // end elment @@ -2407,8 +2407,8 @@ function parse(source,defaultNSMapCopy,entityMap,domBuilder,errorHandler){ //elStartEnd var end = parseElementStartPart(source,tagStart,el,currentNSMap,entityReplacer,errorHandler); var len = el.length; - - + + if(!el.closed && fixSelfClosed(source,end,el.tagName,closeMap)){ el.closed = true; if(!entityMap.nbsp){ @@ -2672,7 +2672,7 @@ function appendElement(el,domBuilder,currentNSMap){ } //can not set prefix,because prefix !== '' a.localName = localName ; - //prefix == null for no ns prefix attribute + //prefix == null for no ns prefix attribute if(nsPrefix !== false){//hack!! if(localNSMap == null){ localNSMap = {} @@ -2682,7 +2682,7 @@ function appendElement(el,domBuilder,currentNSMap){ } currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value; a.uri = NAMESPACE.XMLNS - domBuilder.startPrefixMapping(nsPrefix, value) + domBuilder.startPrefixMapping(nsPrefix, value) } } var i = el.length; @@ -2694,7 +2694,7 @@ function appendElement(el,domBuilder,currentNSMap){ a.uri = NAMESPACE.XML; }if(prefix !== 'xmlns'){ a.uri = currentNSMap[prefix || ''] - + //{console.log('###'+a.qName,domBuilder.locator.systemId+'',currentNSMap,a.uri)} } } @@ -2716,7 +2716,7 @@ function appendElement(el,domBuilder,currentNSMap){ domBuilder.endElement(ns,localName,tagName); if(localNSMap){ for(prefix in localNSMap){ - domBuilder.endPrefixMapping(prefix) + domBuilder.endPrefixMapping(prefix) } } }else{ @@ -2743,7 +2743,7 @@ function parseHtmlSpecialContent(source,elStartEnd,tagName,entityReplacer,domBui domBuilder.characters(text,0,text.length); return elEndStart; //} - + } } return elStartEnd+1; @@ -2760,7 +2760,7 @@ function fixSelfClosed(source,elStartEnd,tagName,closeMap){ closeMap[tagName] =pos } return pos<elStartEnd; - //} + //} } function _copy(source,target){ for(var n in source){target[n] = source[n]} @@ -2788,11 +2788,11 @@ function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!' var end = source.indexOf(']]>',start+9); domBuilder.startCDATA(); domBuilder.characters(source,start+9,end-start-9); - domBuilder.endCDATA() + domBuilder.endCDATA() return end+3; } //<!DOCTYPE - //startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId) + //startDTD(java.lang.String name, java.lang.String publicId, java.lang.String systemId) var matchs = split(source,start); var len = matchs.length; if(len>1 && /!doctype/i.test(matchs[0][0])){ @@ -2810,7 +2810,7 @@ function parseDCC(source,start,domBuilder,errorHandler){//sure start with '<!' var lastMatch = matchs[len-1] domBuilder.startDTD(name, pubid, sysid); domBuilder.endDTD(); - + return lastMatch.index+lastMatch[0].length } } @@ -2859,7 +2859,7 @@ ElementAttributes.prototype = { getValue:function(i){return this[i].value} // ,getIndex:function(uri, localName)){ // if(localName){ -// +// // }else{ // var qName = uri // } @@ -8004,7 +8004,7 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__838__; /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; -/******/ +/******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache @@ -8018,14 +8018,14 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__838__; /******/ // no module.loaded needed /******/ exports: {} /******/ }; -/******/ +/******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); -/******/ +/******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } -/******/ +/******/ /************************************************************************/ /******/ /* webpack/runtime/compat get default export */ /******/ (() => { @@ -8038,7 +8038,7 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__838__; /******/ return getter; /******/ }; /******/ })(); -/******/ +/******/ /******/ /* webpack/runtime/define property getters */ /******/ (() => { /******/ // define getter functions for harmony exports @@ -8050,7 +8050,7 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__838__; /******/ } /******/ }; /******/ })(); -/******/ +/******/ /******/ /* webpack/runtime/global */ /******/ (() => { /******/ __webpack_require__.g = (function() { @@ -8062,12 +8062,12 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__838__; /******/ } /******/ })(); /******/ })(); -/******/ +/******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ (() => { /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) /******/ })(); -/******/ +/******/ /******/ /* webpack/runtime/make namespace object */ /******/ (() => { /******/ // define __esModule on exports @@ -8078,7 +8078,7 @@ module.exports = __WEBPACK_EXTERNAL_MODULE__838__; /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ })(); -/******/ +/******/ /************************************************************************/ var __webpack_exports__ = {}; // This entry needs to be wrapped in an IIFE because it needs to be in strict mode. @@ -13305,8 +13305,8 @@ class Themes { /** * Register a theme by passing its css as string - * @param {string} name - * @param {string} css + * @param {string} name + * @param {string} css */ registerCss(name, css) { this._themes[name] = { @@ -17184,7 +17184,22 @@ class DefaultViewManager { } return visible; } - scrollBy(x, y, silent) { + smoothScrollTo(x, y) { + this.container.scrollTo({left: this.container.scrollLeft + x, top: 0, behavior: 'smooth'}); + + const failed = setTimeout(() => { + reject(); + }, 2000); + + return new Promise((resolve, reject) => { + this.container.addEventListener('scrollend', (evt) => { + clearTimeout(failed); + + resolve(); + }, { once: true }) + }); + } + async scrollBy(x, y, silent) { let dir = this.settings.direction === "rtl" ? -1 : 1; if (silent) { this.ignore = true; @@ -17196,7 +17211,16 @@ class DefaultViewManager { // this.container.scrollTop might become 99.xxx! // Without compensation, this error increases after each scroll operation! if (x) { - this.container.scrollLeft += x * dir; + console.log('scroll delta', x * dir, 'spread', this.layout.props.spread); + + if (1) { + await this.smoothScrollTo(x * dir, y, silent); + } else { + this.container.scrollLeft += x * dir; + } + + // this.container.scrollTo({left: this.container.scrollLeft + (x * dir), top: 0, behavior: 'smooth'}); + const absX = Math.abs(x); const remainder = this.container.scrollLeft % absX; if (Math.abs(absX - remainder) >= 1) { @@ -20464,4 +20488,4 @@ __webpack_exports__ = __webpack_exports__["default"]; /******/ })() ; }); -//# sourceMappingURL=epub.js.map \ No newline at end of file +//# sourceMappingURL=epub.js.map diff --git a/lib/epub.js/src/managers/default/index.js b/lib/epub.js/src/managers/default/index.js index 8a71695..f5c13b1 100644 --- a/lib/epub.js/src/managers/default/index.js +++ b/lib/epub.js/src/managers/default/index.js @@ -852,7 +852,23 @@ class DefaultViewManager { return visible; } - scrollBy(x, y, silent) { + smoothScrollTo(x, y) { + this.container.scrollTo({left: this.container.scrollLeft + x, top: 0, behavior: 'smooth'}); + + const failed = setTimeout(() => { + reject(); + }, 2000); + + return new Promise((resolve, reject) => { + this.container.addEventListener('scrollend', (evt) => { + clearTimeout(failed); + + resolve(); + }, { once: true }) + }); + } + + scrollBy(x, y, silent) { let dir = this.settings.direction === "rtl" ? -1 : 1; if (silent) { |
