define(["exports"],function(_exports){function _createForOfIteratorHelper(r,e){var o,a,u,n,t="undefined"!=typeof Symbol&&r[Symbol.iterator]||r["@@iterator"];if(t)return u=!(a=!0),{s:function(){t=t.call(r)},n:function(){var r=t.next();return a=r.done,r},e:function(r){u=!0,o=r},f:function(){try{a||null==t.return||t.return()}finally{if(u)throw o}}};if(Array.isArray(r)||(t=function(r,a){{var t;if(r)return"string"==typeof r?_arrayLikeToArray(r,a):"Map"===(t="Object"===(t={}.toString.call(r).slice(8,-1))&&r.constructor?r.constructor.name:t)||"Set"===t?Array.from(r):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?_arrayLikeToArray(r,a):void 0}}(r))||e&&r&&"number"==typeof r.length)return t&&(r=t),n=0,{s:e=function(){},n:function(){return n>=r.length?{done:!0}:{done:!1,value:r[n++]}},e:function(r){throw r},f:e};throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _arrayLikeToArray(r,a){(null==a||a>r.length)&&(a=r.length);for(var e=0,n=Array(a);e img, section > img {\n display: block;\n margin: auto;\n}\n.title h1 {\n text-align: center;\n}\nbody > section > .title, body.notesBodyType > .title {\n margin: 3em 0;\n}\nbody.notesBodyType > section .title h1 {\n text-align: start;\n}\nbody.notesBodyType > section .title {\n margin: 1em 0;\n}\np {\n text-indent: 1em;\n margin: 0;\n}\n:not(p) + p, p:first-child {\n text-indent: 0;\n}\n.poem p {\n text-indent: 0;\n margin: 1em 0;\n}\n.text-author, .date {\n text-align: end;\n}\n.text-author:before {\n content: "—";\n}\ntable {\n border-collapse: collapse;\n}\ntd, th {\n padding: .25em;\n}\na[epub|type~="noteref"] {\n font-size: .75em;\n vertical-align: super;\n}\nbody:not(.notesBodyType) > .title, body:not(.notesBodyType) > .epigraph {\n margin: 3em 0;\n}\n'],{type:"text/css"})),dataID="data-foliate-id";_exports.makeFB2=async function(blob){function $(x){return doc.querySelector(x)}function $$(x){return babelHelpers.toConsumableArray(doc.querySelectorAll(x))}function getPerson(el){var middle,nick=getElementText(el.querySelector("nickname"));return nick||{name:[nick=getElementText(el.querySelector("first-name")),middle=getElementText(el.querySelector("middle-name")),el=getElementText(el.querySelector("last-name"))].filter(function(x){return x}).join(" "),sortAs:el?[el,[nick,middle].filter(function(x){return x}).join(" ")].join(", "):null}}function getDate(el){var _el$getAttribute;return null!=(_el$getAttribute=null==el?void 0:el.getAttribute("value"))?_el$getAttribute:getElementText(el)}var src,book={},doc=await async function(blob){var blob=await blob.arrayBuffer(),str=new TextDecoder("utf-8").decode(blob),parser=new DOMParser,doc=parser.parseFromString(str,MIME.XML),str=doc.xmlEncoding||(null==(str=str.match(/^<\?xml\s+version\s*=\s*["']1.\d+"\s+encoding\s*=\s*["']([A-Za-z0-9._-]*)["']/))?void 0:str[1]);return str&&"utf-8"!==str.toLowerCase()?(str=new TextDecoder(str).decode(blob),parser.parseFromString(str,MIME.XML)):doc}(blob),converter=new FB2Converter(doc),blob=$("title-info annotation"),blob=(book.metadata={title:getElementText($("title-info book-title")),identifier:getElementText($("document-info id")),language:getElementText($("title-info lang")),author:$$("title-info author").map(getPerson),translator:$$("title-info translator").map(getPerson),contributor:$$("document-info author").map(getPerson).concat($$("document-info program-used").map(getElementText)).map(function(x){return Object.assign("string"==typeof x?{name:x}:x,{role:"bkp"})}),publisher:getElementText($("publish-info publisher")),published:getDate($("title-info date")),modified:getDate($("document-info date")),description:blob?converter.convert(blob,{annotation:["div",SECTION]}).innerHTML:null,subject:$$("title-info genre").map(getElementText)},$("coverpage image")?(src=converter.getImageSrc($("coverpage image")),book.getCover=function(){return fetch(src).then(function(res){return res.blob()})}):book.getCover=function(){return null},Array.from(doc.querySelectorAll("body"),function(body){body=converter.convert(body,{body:["body",BODY]});return[Array.from(body.children,function(el){var ids=[el].concat(babelHelpers.toConsumableArray(el.querySelectorAll("[id]"))).map(function(el){return el.id});return{el:el,ids:ids}}),body]})),urls=[],blob=blob[0][0].map(function(_ref){var el=_ref.el;return{ids:_ref.ids,titles:Array.from(el.querySelectorAll(":scope > section > .title"),function(el,index){return el.setAttribute(dataID,index),{title:getElementText(el),index:index}}),el:el}}).concat(blob.slice(1).map(function(_ref2){var _ref2=babelHelpers.slicedToArray(_ref2,2),sections=_ref2[0],_ref2=_ref2[1],sections=sections.map(function(s){return s.ids}).flat();return _ref2.classList.add("notesBodyType"),{ids:sections,el:_ref2,linear:"no"}})).map(function(_ref4){var ids=_ref4.ids,titles=_ref4.titles,el=_ref4.el,_ref4=_ref4.linear,str=(html=el.outerHTML,'\n\n \n ').concat(html,"\n")),html=new Blob([str],{type:MIME.XHTML}),url=URL.createObjectURL(html);return urls.push(url),{ids:ids,title:normalizeWhitespace(null!=(ids=null==(ids=el.querySelector(".title, .subtitle, p"))?void 0:ids.textContent)?ids:el.classList.contains("title")?el.textContent:""),titles:titles,load:function(){return url},createDocument:function(){return(new DOMParser).parseFromString(str,MIME.XHTML)},size:html.size-Array.from(el.querySelectorAll("[src]"),function(el){return null!=(el=null==(el=el.getAttribute("src"))?void 0:el.length)?el:0}).reduce(function(a,b){return a+b},0),linear:_ref4}}),idMap=new Map;return book.sections=blob.map(function(section,index){var _step3,ids=section.ids,load=section.load,createDocument=section.createDocument,size=section.size,section=section.linear,_iterator3=_createForOfIteratorHelper(ids);try{for(_iterator3.s();!(_step3=_iterator3.n()).done;){var id=_step3.value;id&&idMap.set(id,index)}}catch(err){_iterator3.e(err)}finally{_iterator3.f()}return{id:index,load:load,createDocument:createDocument,size:size,linear:section}}),book.toc=blob.map(function(_ref5,index){var title=_ref5.title,_ref5=_ref5.titles,id=index.toString();return{label:title,href:id,subitems:null!=_ref5&&_ref5.length?_ref5.map(function(_ref6){var title=_ref6.title,_ref6=_ref6.index;return{label:title,href:"".concat(id,"#").concat(_ref6)}}):null}}).filter(function(item){return item}),book.resolveHref=function(href){var href=href.split("#"),href=babelHelpers.slicedToArray(href,2),a=href[0],b=href[1];return a?{index:Number(a),anchor:function(doc){return doc.querySelector("[".concat(dataID,'="').concat(b,'"]'))}}:{index:idMap.get(b),anchor:function(doc){return doc.getElementById(b)}}},book.splitTOCHref=function(href){return null!=(href=null==href||null==(href=href.split("#"))?void 0:href.map(function(x){return Number(x)}))?href:[]},book.getTOCFragment=function(doc,id){return doc.querySelector("[".concat(dataID,'="').concat(id,'"]'))},book.destroy=function(){for(var _i=0,_urls=urls;_i<_urls.length;_i++)URL.revokeObjectURL(_urls[_i])},book}});