"}return r}function gn(t){const e=Object.keys(t);for(let t=0;t0&&e.processEntities)for(const n in e.entities){const i=e.entities[n];t=t.replace(i.regex,i.val)}return t}xn=function(t,e){return _n(t,e,"",0)};const yn={attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,cdataPropName:!1,format:!1,indentBy:" ",suppressEmptyNode:!1,suppressBooleanAttributes:!0,tagValueProcessor:function(t,e){return e},attributeValueProcessor:function(t,e){return e},preserveOrder:!1,commentPropName:!1,unpairedTags:[],entities:{">":{regex:new RegExp(">","g"),val:">"},"<":{regex:new RegExp("<","g"),val:"<"},sQuot:{regex:new RegExp("'","g"),val:"'"},dQuot:{regex:new RegExp('"',"g"),val:"""}},processEntities:!0,stopNodes:[]};function kn(t){this.options=Object.assign({},yn,t),this.options.ignoreAttributes||this.options.attributesGroupName?this.isAttribute=function(){return!1}:(this.attrPrefixLen=this.options.attributeNamePrefix.length,this.isAttribute=Tn),this.processTextOrObjNode=zn,this.options.format?(this.indentate=jn,this.tagEndChar=">\n",this.newLine="\n"):(this.indentate=function(){return""},this.tagEndChar=">",this.newLine=""),this.options.suppressEmptyNode?(this.buildTextNode=Dn,this.buildObjNode=Sn):(this.buildTextNode=Un,this.buildObjNode=En),this.buildTextValNode=Un,this.buildObjectNode=En,this.replaceEntitiesValue=Fn,this.buildAttrPairStr=An}function An(t,e){return e=this.options.attributeValueProcessor(t,""+e),e=this.replaceEntitiesValue(e),this.options.suppressBooleanAttributes&&"true"===e?" "+t:" "+t+'="'+e+'"'}function zn(t,e,n){const i=this.j2x(t,n+1);return void 0!==t[this.options.textNodeName]&&1===Object.keys(t).length?this.buildTextNode(i.val,e,i.attrStr,n):this.buildObjNode(i.val,e,i.attrStr,n)}function En(t,e,n,i){let r=""+e+this.tagEndChar,a="";return"?"===e[0]&&(a="?",r=""),n&&-1===t.indexOf("<")?this.indentate(i)+"<"+e+n+a+">"+t+r:this.indentate(i)+"<"+e+n+a+this.tagEndChar+t+this.indentate(i)+r}function Sn(t,e,n,i){return""!==t?this.buildObjectNode(t,e,n,i):"?"===e[0]?this.indentate(i)+"<"+e+n+"?"+this.tagEndChar:this.indentate(i)+"<"+e+n+"/"+this.tagEndChar}function Un(t,e,n,i){let r=this.options.tagValueProcessor(e,t);return r=this.replaceEntitiesValue(r),this.indentate(i)+"<"+e+n+">"+r+""+e+this.tagEndChar}function Fn(t){if(t&&t.length>0&&this.options.processEntities)for(const e in this.options.entities){const n=this.options.entities[e];t=t.replace(n.regex,n.val)}return t}function Dn(t,e,n,i){return""===t&&-1!==this.options.unpairedTags.indexOf(e)?this.indentate(i)+"<"+e+n+this.tagEndChar:""!==t?this.buildTextValNode(t,e,n,i):"?"===e[0]?this.indentate(i)+"<"+e+n+"?"+this.tagEndChar:this.indentate(i)+"<"+e+n+"/"+this.tagEndChar}function jn(t){return this.options.indentBy.repeat(t)}function Tn(t){return!!t.startsWith(this.options.attributeNamePrefix)&&t.substr(this.attrPrefixLen)}function Nn(t){return new ye.XMLParser({ignoreAttributes:!1}).parse(t)}function Cn(t,e){var n=t=>`${t}`.length;let i=n(t);for(let r=0;rt.filename.match(/.+\.opf/i)));try{a=await s.getData(new zt)}catch(n){return"application/epub+zip"===t.type?Mn(`❌ Error: Can't find the .opf file in ${t.name}. If your epub file is ocf/ops, it not support yet.`,e):Mn(`❌ Error: [${t.name}] may not be an epub file. Please check it.`,e),-1}var o=Nn(a),l=o.package.spine.itemref.map((t=>o.package.manifest.item.filter((e=>e["@_id"]===t["@_idref"])).pop()["@_href"]));Mn("Looking into ncx file",e);var d=n.find((t=>t.filename.match(/.+\.ncx/i))),c=d.filename.split("/").slice(0,-1).join("/"),f=Nn(await d.getData(new zt)),u=f?.ncx?.navMap?.navPoint?.map?f?.ncx?.navMap?.navPoint?.map((t=>In([c,t.content?.["@_src"]].join("/")))):[];l=l.length>u.length?l:u,Mn("Loading index of ["+t.name+"]...",e);var p=[];try{for(var h of l){var m=n.find((t=>t.filename===h)),x=await m.getData(new zt),_=m.filename.split("/").slice(0,-1).join("/");if(x.indexOf("
=0){var g=x.split('
t)).join("/")),p.push(g)}}}catch(t){Mn("❌ Error: Something wrong during getting Image List. Please press F12 to check console.",e),console.error(t)}p=p.filter((t=>t));for(var w=new St("application/x-cbz"),b=new te(w),v=[],y=0,k=0;kt.filename===p[k])),z=A.filename.split(".").pop(),E=new Promise((function(n,i){var r=k;A.getData(new St(`image/${z.toLocaleLowerCase()}`)).then((i=>{b.add(`${Cn(r,p.length)}.${z}`,new Et(i)).then((()=>{Mn(`Processing [${t.name}]: ${y++}/${p.length}`,e),n()}))}))}));v.push(E)}await Promise.all(v),Mn(`building [${i}.cbz], it will auto download after building finish...`,e),b.close(),r.close(),pe.saveAs(w.getData(),`${i}.cbz`)}function Mn(t,e){var n=document.querySelector("#"+e);n||((n=document.createElement("div")).setAttribute("id",e),document.querySelector("#log").append(n)),n.innerHTML=""+t+"
"}kn.prototype.build=function(t){return this.options.preserveOrder?xn(t,this.options):(Array.isArray(t)&&this.options.arrayNodeName&&this.options.arrayNodeName.length>1&&(t={[this.options.arrayNodeName]:t}),this.j2x(t,0).val)},kn.prototype.j2x=function(t,e){let n="",i="";for(let r in t)if(void 0===t[r]);else if(null===t[r])"?"===r[0]?i+=this.indentate(e)+"<"+r+"?"+this.tagEndChar:i+=this.indentate(e)+"<"+r+"/"+this.tagEndChar;else if(t[r]instanceof Date)i+=this.buildTextNode(t[r],r,"",e);else if("object"!=typeof t[r]){const a=this.isAttribute(r);if(a)n+=this.buildAttrPairStr(a,""+t[r]);else if(r===this.options.textNodeName){let e=this.options.tagValueProcessor(r,""+t[r]);i+=this.replaceEntitiesValue(e)}else i+=this.buildTextNode(t[r],r,"",e)}else if(Array.isArray(t[r])){const n=t[r].length;for(let a=0;aMn(`Waiting ${t.name} ....`,`_${e}`)));for(let t=0;t