@prose-reader/streamer 0.0.24 → 0.0.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,6 @@ import { Archive } from "./types";
2
2
  /**
3
3
  * Useful to create archive from txt content
4
4
  */
5
- export declare const createArchiveFromText: (content: string | Blob | File, options?: {
5
+ export declare const createArchiveFromText: (content: string | Blob, options?: {
6
6
  direction: `ltr` | `rtl`;
7
7
  } | undefined) => Promise<Archive>;
@@ -0,0 +1,10 @@
1
+ import { Manifest } from '@prose-reader/shared';
2
+ import { Archive } from '../../archives/types';
3
+ /**
4
+ * Handle archive which contains ComicInfo.xml. This is a meta file
5
+ * used to define cbz, etc. I believe it comes from some sites or apps.
6
+ */
7
+ export declare const comicInfoGenerator: ({ archive, baseUrl }: {
8
+ archive: Archive;
9
+ baseUrl: string;
10
+ }) => (manifest: Manifest) => Promise<Manifest>;
@@ -0,0 +1,6 @@
1
+ import { Manifest } from '@prose-reader/shared';
2
+ import { Archive } from '../../archives/types';
3
+ export declare const defaultGenerator: ({ archive, baseUrl }: {
4
+ archive: Archive;
5
+ baseUrl: string;
6
+ }) => (manifest: Manifest) => Promise<Manifest>;
@@ -0,0 +1,12 @@
1
+ import xmldoc from 'xmldoc';
2
+ import type { Manifest } from '@prose-reader/shared';
3
+ import { Archive } from '../..';
4
+ export declare const getItemsFromDoc: (doc: xmldoc.XmlDocument) => {
5
+ href: string;
6
+ id: string;
7
+ mediaType: string | undefined;
8
+ }[];
9
+ export declare const epubGenerator: ({ archive, baseUrl }: {
10
+ archive: Archive;
11
+ baseUrl: string;
12
+ }) => (manifest: Manifest) => Promise<Manifest>;
@@ -0,0 +1,4 @@
1
+ import { Archive } from '../..';
2
+ export declare const getManifestFromArchive: (archive: Archive, { baseUrl }?: {
3
+ baseUrl?: string | undefined;
4
+ }) => Promise<Response>;
package/dist/index.js CHANGED
@@ -1,8 +1,2 @@
1
- export { getResourceFromArchive } from './generators/resources';
2
- export { getManifestFromArchive } from './generators/manifest';
3
- export { Report } from './report';
4
- export { getArchiveOpfInfo } from './archives/getArchiveOpfInfo';
5
- export { createArchiveFromUrls } from './archives/createArchiveFromUrls';
6
- export { createArchiveFromText } from './archives/createArchiveFromText';
7
- export { createArchiveFromJszip } from './archives/createArchiveFromJszip';
8
- export { createArchiveFromArrayBufferList } from './archives/createArchiveFromArrayBufferList';
1
+ /*! For license information please see index.js.LICENSE.txt */
2
+ (()=>{var t={766:(t,e)=>{"use strict";e.byteLength=function(t){var e=u(t),n=e[0],r=e[1];return 3*(n+r)/4-r},e.toByteArray=function(t){var e,n,o=u(t),a=o[0],s=o[1],c=new i(function(t,e,n){return 3*(e+n)/4-n}(0,a,s)),f=0,l=s>0?a-4:a;for(n=0;n<l;n+=4)e=r[t.charCodeAt(n)]<<18|r[t.charCodeAt(n+1)]<<12|r[t.charCodeAt(n+2)]<<6|r[t.charCodeAt(n+3)],c[f++]=e>>16&255,c[f++]=e>>8&255,c[f++]=255&e;return 2===s&&(e=r[t.charCodeAt(n)]<<2|r[t.charCodeAt(n+1)]>>4,c[f++]=255&e),1===s&&(e=r[t.charCodeAt(n)]<<10|r[t.charCodeAt(n+1)]<<4|r[t.charCodeAt(n+2)]>>2,c[f++]=e>>8&255,c[f++]=255&e),c},e.fromByteArray=function(t){for(var e,r=t.length,i=r%3,o=[],a=16383,s=0,u=r-i;s<u;s+=a)o.push(c(t,s,s+a>u?u:s+a));return 1===i?(e=t[r-1],o.push(n[e>>2]+n[e<<4&63]+"==")):2===i&&(e=(t[r-2]<<8)+t[r-1],o.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"=")),o.join("")};for(var n=[],r=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,s=o.length;a<s;++a)n[a]=o[a],r[o.charCodeAt(a)]=a;function u(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var n=t.indexOf("=");return-1===n&&(n=e),[n,n===e?0:4-n%4]}function c(t,e,r){for(var i,o,a=[],s=e;s<r;s+=3)i=(t[s]<<16&16711680)+(t[s+1]<<8&65280)+(255&t[s+2]),a.push(n[(o=i)>>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return a.join("")}r["-".charCodeAt(0)]=62,r["_".charCodeAt(0)]=63},834:(t,e,n)=>{"use strict";const r=n(766),i=n(333),o="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e.Buffer=u,e.SlowBuffer=function(t){return+t!=t&&(t=0),u.alloc(+t)},e.INSPECT_MAX_BYTES=50;const a=2147483647;function s(t){if(t>a)throw new RangeError('The value "'+t+'" is invalid for option "size"');const e=new Uint8Array(t);return Object.setPrototypeOf(e,u.prototype),e}function u(t,e,n){if("number"==typeof t){if("string"==typeof e)throw new TypeError('The "string" argument must be of type string. Received type number');return l(t)}return c(t,e,n)}function c(t,e,n){if("string"==typeof t)return function(t,e){if("string"==typeof e&&""!==e||(e="utf8"),!u.isEncoding(e))throw new TypeError("Unknown encoding: "+e);const n=0|g(t,e);let r=s(n);const i=r.write(t,e);return i!==n&&(r=r.slice(0,i)),r}(t,e);if(ArrayBuffer.isView(t))return function(t){if(H(t,Uint8Array)){const e=new Uint8Array(t);return p(e.buffer,e.byteOffset,e.byteLength)}return h(t)}(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(H(t,ArrayBuffer)||t&&H(t.buffer,ArrayBuffer))return p(t,e,n);if("undefined"!=typeof SharedArrayBuffer&&(H(t,SharedArrayBuffer)||t&&H(t.buffer,SharedArrayBuffer)))return p(t,e,n);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');const r=t.valueOf&&t.valueOf();if(null!=r&&r!==t)return u.from(r,e,n);const i=function(t){if(u.isBuffer(t)){const e=0|d(t.length),n=s(e);return 0===n.length||t.copy(n,0,0,e),n}return void 0!==t.length?"number"!=typeof t.length||Q(t.length)?s(0):h(t):"Buffer"===t.type&&Array.isArray(t.data)?h(t.data):void 0}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return u.from(t[Symbol.toPrimitive]("string"),e,n);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function f(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function l(t){return f(t),s(t<0?0:0|d(t))}function h(t){const e=t.length<0?0:0|d(t.length),n=s(e);for(let r=0;r<e;r+=1)n[r]=255&t[r];return n}function p(t,e,n){if(e<0||t.byteLength<e)throw new RangeError('"offset" is outside of buffer bounds');if(t.byteLength<e+(n||0))throw new RangeError('"length" is outside of buffer bounds');let r;return r=void 0===e&&void 0===n?new Uint8Array(t):void 0===n?new Uint8Array(t,e):new Uint8Array(t,e,n),Object.setPrototypeOf(r,u.prototype),r}function d(t){if(t>=a)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a.toString(16)+" bytes");return 0|t}function g(t,e){if(u.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||H(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);const n=t.length,r=arguments.length>2&&!0===arguments[2];if(!r&&0===n)return 0;let i=!1;for(;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":return X(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return q(t).length;default:if(i)return r?-1:X(t).length;e=(""+e).toLowerCase(),i=!0}}function m(t,e,n){let r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if((n>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return S(this,e,n);case"utf8":case"utf-8":return _(this,e,n);case"ascii":return C(this,e,n);case"latin1":case"binary":return O(this,e,n);case"base64":return I(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}function y(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function v(t,e,n,r,i){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),Q(n=+n)&&(n=i?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(i)return-1;n=t.length-1}else if(n<0){if(!i)return-1;n=0}if("string"==typeof e&&(e=u.from(e,r)),u.isBuffer(e))return 0===e.length?-1:b(t,e,n,r,i);if("number"==typeof e)return e&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):b(t,[e],n,r,i);throw new TypeError("val must be string, number or Buffer")}function b(t,e,n,r,i){let o,a=1,s=t.length,u=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;a=2,s/=2,u/=2,n/=2}function c(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(i){let r=-1;for(o=n;o<s;o++)if(c(t,o)===c(e,-1===r?0:o-r)){if(-1===r&&(r=o),o-r+1===u)return r*a}else-1!==r&&(o-=o-r),r=-1}else for(n+u>s&&(n=s-u),o=n;o>=0;o--){let n=!0;for(let r=0;r<u;r++)if(c(t,o+r)!==c(e,r)){n=!1;break}if(n)return o}return-1}function E(t,e,n,r){n=Number(n)||0;const i=t.length-n;r?(r=Number(r))>i&&(r=i):r=i;const o=e.length;let a;for(r>o/2&&(r=o/2),a=0;a<r;++a){const r=parseInt(e.substr(2*a,2),16);if(Q(r))return a;t[n+a]=r}return a}function T(t,e,n,r){return z(X(e,t.length-n),t,n,r)}function w(t,e,n,r){return z(function(t){const e=[];for(let n=0;n<t.length;++n)e.push(255&t.charCodeAt(n));return e}(e),t,n,r)}function N(t,e,n,r){return z(q(e),t,n,r)}function A(t,e,n,r){return z(function(t,e){let n,r,i;const o=[];for(let a=0;a<t.length&&!((e-=2)<0);++a)n=t.charCodeAt(a),r=n>>8,i=n%256,o.push(i),o.push(r);return o}(e,t.length-n),t,n,r)}function I(t,e,n){return 0===e&&n===t.length?r.fromByteArray(t):r.fromByteArray(t.slice(e,n))}function _(t,e,n){n=Math.min(t.length,n);const r=[];let i=e;for(;i<n;){const e=t[i];let o=null,a=e>239?4:e>223?3:e>191?2:1;if(i+a<=n){let n,r,s,u;switch(a){case 1:e<128&&(o=e);break;case 2:n=t[i+1],128==(192&n)&&(u=(31&e)<<6|63&n,u>127&&(o=u));break;case 3:n=t[i+1],r=t[i+2],128==(192&n)&&128==(192&r)&&(u=(15&e)<<12|(63&n)<<6|63&r,u>2047&&(u<55296||u>57343)&&(o=u));break;case 4:n=t[i+1],r=t[i+2],s=t[i+3],128==(192&n)&&128==(192&r)&&128==(192&s)&&(u=(15&e)<<18|(63&n)<<12|(63&r)<<6|63&s,u>65535&&u<1114112&&(o=u))}}null===o?(o=65533,a=1):o>65535&&(o-=65536,r.push(o>>>10&1023|55296),o=56320|1023&o),r.push(o),i+=a}return function(t){const e=t.length;if(e<=B)return String.fromCharCode.apply(String,t);let n="",r=0;for(;r<e;)n+=String.fromCharCode.apply(String,t.slice(r,r+=B));return n}(r)}e.kMaxLength=a,u.TYPED_ARRAY_SUPPORT=function(){try{const t=new Uint8Array(1),e={foo:function(){return 42}};return Object.setPrototypeOf(e,Uint8Array.prototype),Object.setPrototypeOf(t,e),42===t.foo()}catch(t){return!1}}(),u.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(u.prototype,"parent",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.buffer}}),Object.defineProperty(u.prototype,"offset",{enumerable:!0,get:function(){if(u.isBuffer(this))return this.byteOffset}}),u.poolSize=8192,u.from=function(t,e,n){return c(t,e,n)},Object.setPrototypeOf(u.prototype,Uint8Array.prototype),Object.setPrototypeOf(u,Uint8Array),u.alloc=function(t,e,n){return function(t,e,n){return f(t),t<=0?s(t):void 0!==e?"string"==typeof n?s(t).fill(e,n):s(t).fill(e):s(t)}(t,e,n)},u.allocUnsafe=function(t){return l(t)},u.allocUnsafeSlow=function(t){return l(t)},u.isBuffer=function(t){return null!=t&&!0===t._isBuffer&&t!==u.prototype},u.compare=function(t,e){if(H(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),H(e,Uint8Array)&&(e=u.from(e,e.offset,e.byteLength)),!u.isBuffer(t)||!u.isBuffer(e))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(t===e)return 0;let n=t.length,r=e.length;for(let i=0,o=Math.min(n,r);i<o;++i)if(t[i]!==e[i]){n=t[i],r=e[i];break}return n<r?-1:r<n?1:0},u.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},u.concat=function(t,e){if(!Array.isArray(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return u.alloc(0);let n;if(void 0===e)for(e=0,n=0;n<t.length;++n)e+=t[n].length;const r=u.allocUnsafe(e);let i=0;for(n=0;n<t.length;++n){let e=t[n];if(H(e,Uint8Array))i+e.length>r.length?(u.isBuffer(e)||(e=u.from(e)),e.copy(r,i)):Uint8Array.prototype.set.call(r,e,i);else{if(!u.isBuffer(e))throw new TypeError('"list" argument must be an Array of Buffers');e.copy(r,i)}i+=e.length}return r},u.byteLength=g,u.prototype._isBuffer=!0,u.prototype.swap16=function(){const t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(let e=0;e<t;e+=2)y(this,e,e+1);return this},u.prototype.swap32=function(){const t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(let e=0;e<t;e+=4)y(this,e,e+3),y(this,e+1,e+2);return this},u.prototype.swap64=function(){const t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(let e=0;e<t;e+=8)y(this,e,e+7),y(this,e+1,e+6),y(this,e+2,e+5),y(this,e+3,e+4);return this},u.prototype.toString=function(){const t=this.length;return 0===t?"":0===arguments.length?_(this,0,t):m.apply(this,arguments)},u.prototype.toLocaleString=u.prototype.toString,u.prototype.equals=function(t){if(!u.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===u.compare(this,t)},u.prototype.inspect=function(){let t="";const n=e.INSPECT_MAX_BYTES;return t=this.toString("hex",0,n).replace(/(.{2})/g,"$1 ").trim(),this.length>n&&(t+=" ... "),"<Buffer "+t+">"},o&&(u.prototype[o]=u.prototype.inspect),u.prototype.compare=function(t,e,n,r,i){if(H(t,Uint8Array)&&(t=u.from(t,t.offset,t.byteLength)),!u.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===i&&(i=this.length),e<0||n>t.length||r<0||i>this.length)throw new RangeError("out of range index");if(r>=i&&e>=n)return 0;if(r>=i)return-1;if(e>=n)return 1;if(this===t)return 0;let o=(i>>>=0)-(r>>>=0),a=(n>>>=0)-(e>>>=0);const s=Math.min(o,a),c=this.slice(r,i),f=t.slice(e,n);for(let t=0;t<s;++t)if(c[t]!==f[t]){o=c[t],a=f[t];break}return o<a?-1:a<o?1:0},u.prototype.includes=function(t,e,n){return-1!==this.indexOf(t,e,n)},u.prototype.indexOf=function(t,e,n){return v(this,t,e,n,!0)},u.prototype.lastIndexOf=function(t,e,n){return v(this,t,e,n,!1)},u.prototype.write=function(t,e,n,r){if(void 0===e)r="utf8",n=this.length,e=0;else if(void 0===n&&"string"==typeof e)r=e,n=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e>>>=0,isFinite(n)?(n>>>=0,void 0===r&&(r="utf8")):(r=n,n=void 0)}const i=this.length-e;if((void 0===n||n>i)&&(n=i),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");let o=!1;for(;;)switch(r){case"hex":return E(this,t,e,n);case"utf8":case"utf-8":return T(this,t,e,n);case"ascii":case"latin1":case"binary":return w(this,t,e,n);case"base64":return N(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,e,n);default:if(o)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),o=!0}},u.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};const B=4096;function C(t,e,n){let r="";n=Math.min(t.length,n);for(let i=e;i<n;++i)r+=String.fromCharCode(127&t[i]);return r}function O(t,e,n){let r="";n=Math.min(t.length,n);for(let i=e;i<n;++i)r+=String.fromCharCode(t[i]);return r}function S(t,e,n){const r=t.length;(!e||e<0)&&(e=0),(!n||n<0||n>r)&&(n=r);let i="";for(let r=e;r<n;++r)i+=Z[t[r]];return i}function U(t,e,n){const r=t.slice(e,n);let i="";for(let t=0;t<r.length-1;t+=2)i+=String.fromCharCode(r[t]+256*r[t+1]);return i}function x(t,e,n){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>n)throw new RangeError("Trying to access beyond buffer length")}function D(t,e,n,r,i,o){if(!u.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>i||e<o)throw new RangeError('"value" argument is out of bounds');if(n+r>t.length)throw new RangeError("Index out of range")}function P(t,e,n,r,i){k(e,r,i,t,n,7);let o=Number(e&BigInt(4294967295));t[n++]=o,o>>=8,t[n++]=o,o>>=8,t[n++]=o,o>>=8,t[n++]=o;let a=Number(e>>BigInt(32)&BigInt(4294967295));return t[n++]=a,a>>=8,t[n++]=a,a>>=8,t[n++]=a,a>>=8,t[n++]=a,n}function R(t,e,n,r,i){k(e,r,i,t,n,7);let o=Number(e&BigInt(4294967295));t[n+7]=o,o>>=8,t[n+6]=o,o>>=8,t[n+5]=o,o>>=8,t[n+4]=o;let a=Number(e>>BigInt(32)&BigInt(4294967295));return t[n+3]=a,a>>=8,t[n+2]=a,a>>=8,t[n+1]=a,a>>=8,t[n]=a,n+8}function L(t,e,n,r,i,o){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function F(t,e,n,r,o){return e=+e,n>>>=0,o||L(t,0,n,4),i.write(t,e,n,r,23,4),n+4}function M(t,e,n,r,o){return e=+e,n>>>=0,o||L(t,0,n,8),i.write(t,e,n,r,52,8),n+8}u.prototype.slice=function(t,e){const n=this.length;(t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t);const r=this.subarray(t,e);return Object.setPrototypeOf(r,u.prototype),r},u.prototype.readUintLE=u.prototype.readUIntLE=function(t,e,n){t>>>=0,e>>>=0,n||x(t,e,this.length);let r=this[t],i=1,o=0;for(;++o<e&&(i*=256);)r+=this[t+o]*i;return r},u.prototype.readUintBE=u.prototype.readUIntBE=function(t,e,n){t>>>=0,e>>>=0,n||x(t,e,this.length);let r=this[t+--e],i=1;for(;e>0&&(i*=256);)r+=this[t+--e]*i;return r},u.prototype.readUint8=u.prototype.readUInt8=function(t,e){return t>>>=0,e||x(t,1,this.length),this[t]},u.prototype.readUint16LE=u.prototype.readUInt16LE=function(t,e){return t>>>=0,e||x(t,2,this.length),this[t]|this[t+1]<<8},u.prototype.readUint16BE=u.prototype.readUInt16BE=function(t,e){return t>>>=0,e||x(t,2,this.length),this[t]<<8|this[t+1]},u.prototype.readUint32LE=u.prototype.readUInt32LE=function(t,e){return t>>>=0,e||x(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u.prototype.readUint32BE=u.prototype.readUInt32BE=function(t,e){return t>>>=0,e||x(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u.prototype.readBigUInt64LE=J((function(t){W(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||V(t,this.length-8);const r=e+256*this[++t]+65536*this[++t]+this[++t]*2**24,i=this[++t]+256*this[++t]+65536*this[++t]+n*2**24;return BigInt(r)+(BigInt(i)<<BigInt(32))})),u.prototype.readBigUInt64BE=J((function(t){W(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||V(t,this.length-8);const r=e*2**24+65536*this[++t]+256*this[++t]+this[++t],i=this[++t]*2**24+65536*this[++t]+256*this[++t]+n;return(BigInt(r)<<BigInt(32))+BigInt(i)})),u.prototype.readIntLE=function(t,e,n){t>>>=0,e>>>=0,n||x(t,e,this.length);let r=this[t],i=1,o=0;for(;++o<e&&(i*=256);)r+=this[t+o]*i;return i*=128,r>=i&&(r-=Math.pow(2,8*e)),r},u.prototype.readIntBE=function(t,e,n){t>>>=0,e>>>=0,n||x(t,e,this.length);let r=e,i=1,o=this[t+--r];for(;r>0&&(i*=256);)o+=this[t+--r]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*e)),o},u.prototype.readInt8=function(t,e){return t>>>=0,e||x(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u.prototype.readInt16LE=function(t,e){t>>>=0,e||x(t,2,this.length);const n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt16BE=function(t,e){t>>>=0,e||x(t,2,this.length);const n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},u.prototype.readInt32LE=function(t,e){return t>>>=0,e||x(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u.prototype.readInt32BE=function(t,e){return t>>>=0,e||x(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u.prototype.readBigInt64LE=J((function(t){W(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||V(t,this.length-8);const r=this[t+4]+256*this[t+5]+65536*this[t+6]+(n<<24);return(BigInt(r)<<BigInt(32))+BigInt(e+256*this[++t]+65536*this[++t]+this[++t]*2**24)})),u.prototype.readBigInt64BE=J((function(t){W(t>>>=0,"offset");const e=this[t],n=this[t+7];void 0!==e&&void 0!==n||V(t,this.length-8);const r=(e<<24)+65536*this[++t]+256*this[++t]+this[++t];return(BigInt(r)<<BigInt(32))+BigInt(this[++t]*2**24+65536*this[++t]+256*this[++t]+n)})),u.prototype.readFloatLE=function(t,e){return t>>>=0,e||x(t,4,this.length),i.read(this,t,!0,23,4)},u.prototype.readFloatBE=function(t,e){return t>>>=0,e||x(t,4,this.length),i.read(this,t,!1,23,4)},u.prototype.readDoubleLE=function(t,e){return t>>>=0,e||x(t,8,this.length),i.read(this,t,!0,52,8)},u.prototype.readDoubleBE=function(t,e){return t>>>=0,e||x(t,8,this.length),i.read(this,t,!1,52,8)},u.prototype.writeUintLE=u.prototype.writeUIntLE=function(t,e,n,r){t=+t,e>>>=0,n>>>=0,r||D(this,t,e,n,Math.pow(2,8*n)-1,0);let i=1,o=0;for(this[e]=255&t;++o<n&&(i*=256);)this[e+o]=t/i&255;return e+n},u.prototype.writeUintBE=u.prototype.writeUIntBE=function(t,e,n,r){t=+t,e>>>=0,n>>>=0,r||D(this,t,e,n,Math.pow(2,8*n)-1,0);let i=n-1,o=1;for(this[e+i]=255&t;--i>=0&&(o*=256);)this[e+i]=t/o&255;return e+n},u.prototype.writeUint8=u.prototype.writeUInt8=function(t,e,n){return t=+t,e>>>=0,n||D(this,t,e,1,255,0),this[e]=255&t,e+1},u.prototype.writeUint16LE=u.prototype.writeUInt16LE=function(t,e,n){return t=+t,e>>>=0,n||D(this,t,e,2,65535,0),this[e]=255&t,this[e+1]=t>>>8,e+2},u.prototype.writeUint16BE=u.prototype.writeUInt16BE=function(t,e,n){return t=+t,e>>>=0,n||D(this,t,e,2,65535,0),this[e]=t>>>8,this[e+1]=255&t,e+2},u.prototype.writeUint32LE=u.prototype.writeUInt32LE=function(t,e,n){return t=+t,e>>>=0,n||D(this,t,e,4,4294967295,0),this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t,e+4},u.prototype.writeUint32BE=u.prototype.writeUInt32BE=function(t,e,n){return t=+t,e>>>=0,n||D(this,t,e,4,4294967295,0),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},u.prototype.writeBigUInt64LE=J((function(t,e=0){return P(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),u.prototype.writeBigUInt64BE=J((function(t,e=0){return R(this,t,e,BigInt(0),BigInt("0xffffffffffffffff"))})),u.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e>>>=0,!r){const r=Math.pow(2,8*n-1);D(this,t,e,n,r-1,-r)}let i=0,o=1,a=0;for(this[e]=255&t;++i<n&&(o*=256);)t<0&&0===a&&0!==this[e+i-1]&&(a=1),this[e+i]=(t/o>>0)-a&255;return e+n},u.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e>>>=0,!r){const r=Math.pow(2,8*n-1);D(this,t,e,n,r-1,-r)}let i=n-1,o=1,a=0;for(this[e+i]=255&t;--i>=0&&(o*=256);)t<0&&0===a&&0!==this[e+i+1]&&(a=1),this[e+i]=(t/o>>0)-a&255;return e+n},u.prototype.writeInt8=function(t,e,n){return t=+t,e>>>=0,n||D(this,t,e,1,127,-128),t<0&&(t=255+t+1),this[e]=255&t,e+1},u.prototype.writeInt16LE=function(t,e,n){return t=+t,e>>>=0,n||D(this,t,e,2,32767,-32768),this[e]=255&t,this[e+1]=t>>>8,e+2},u.prototype.writeInt16BE=function(t,e,n){return t=+t,e>>>=0,n||D(this,t,e,2,32767,-32768),this[e]=t>>>8,this[e+1]=255&t,e+2},u.prototype.writeInt32LE=function(t,e,n){return t=+t,e>>>=0,n||D(this,t,e,4,2147483647,-2147483648),this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24,e+4},u.prototype.writeInt32BE=function(t,e,n){return t=+t,e>>>=0,n||D(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t,e+4},u.prototype.writeBigInt64LE=J((function(t,e=0){return P(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),u.prototype.writeBigInt64BE=J((function(t,e=0){return R(this,t,e,-BigInt("0x8000000000000000"),BigInt("0x7fffffffffffffff"))})),u.prototype.writeFloatLE=function(t,e,n){return F(this,t,e,!0,n)},u.prototype.writeFloatBE=function(t,e,n){return F(this,t,e,!1,n)},u.prototype.writeDoubleLE=function(t,e,n){return M(this,t,e,!0,n)},u.prototype.writeDoubleBE=function(t,e,n){return M(this,t,e,!1,n)},u.prototype.copy=function(t,e,n,r){if(!u.isBuffer(t))throw new TypeError("argument should be a Buffer");if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r<n&&(r=n),r===n)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(n<0||n>=this.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e<r-n&&(r=t.length-e+n);const i=r-n;return this===t&&"function"==typeof Uint8Array.prototype.copyWithin?this.copyWithin(e,n,r):Uint8Array.prototype.set.call(t,this.subarray(n,r),e),i},u.prototype.fill=function(t,e,n,r){if("string"==typeof t){if("string"==typeof e?(r=e,e=0,n=this.length):"string"==typeof n&&(r=n,n=this.length),void 0!==r&&"string"!=typeof r)throw new TypeError("encoding must be a string");if("string"==typeof r&&!u.isEncoding(r))throw new TypeError("Unknown encoding: "+r);if(1===t.length){const e=t.charCodeAt(0);("utf8"===r&&e<128||"latin1"===r)&&(t=e)}}else"number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(e<0||this.length<e||this.length<n)throw new RangeError("Out of range index");if(n<=e)return this;let i;if(e>>>=0,n=void 0===n?this.length:n>>>0,t||(t=0),"number"==typeof t)for(i=e;i<n;++i)this[i]=t;else{const o=u.isBuffer(t)?t:u.from(t,r),a=o.length;if(0===a)throw new TypeError('The value "'+t+'" is invalid for argument "value"');for(i=0;i<n-e;++i)this[i+e]=o[i%a]}return this};const $={};function j(t,e,n){$[t]=class extends n{constructor(){super(),Object.defineProperty(this,"message",{value:e.apply(this,arguments),writable:!0,configurable:!0}),this.name=`${this.name} [${t}]`,this.stack,delete this.name}get code(){return t}set code(t){Object.defineProperty(this,"code",{configurable:!0,enumerable:!0,value:t,writable:!0})}toString(){return`${this.name} [${t}]: ${this.message}`}}}function G(t){let e="",n=t.length;const r="-"===t[0]?1:0;for(;n>=r+4;n-=3)e=`_${t.slice(n-3,n)}${e}`;return`${t.slice(0,n)}${e}`}function k(t,e,n,r,i,o){if(t>n||t<e){const r="bigint"==typeof e?"n":"";let i;throw i=o>3?0===e||e===BigInt(0)?`>= 0${r} and < 2${r} ** ${8*(o+1)}${r}`:`>= -(2${r} ** ${8*(o+1)-1}${r}) and < 2 ** ${8*(o+1)-1}${r}`:`>= ${e}${r} and <= ${n}${r}`,new $.ERR_OUT_OF_RANGE("value",i,t)}!function(t,e,n){W(e,"offset"),void 0!==t[e]&&void 0!==t[e+n]||V(e,t.length-(n+1))}(r,i,o)}function W(t,e){if("number"!=typeof t)throw new $.ERR_INVALID_ARG_TYPE(e,"number",t)}function V(t,e,n){if(Math.floor(t)!==t)throw W(t,n),new $.ERR_OUT_OF_RANGE(n||"offset","an integer",t);if(e<0)throw new $.ERR_BUFFER_OUT_OF_BOUNDS;throw new $.ERR_OUT_OF_RANGE(n||"offset",`>= ${n?1:0} and <= ${e}`,t)}j("ERR_BUFFER_OUT_OF_BOUNDS",(function(t){return t?`${t} is outside of buffer bounds`:"Attempt to access memory outside buffer bounds"}),RangeError),j("ERR_INVALID_ARG_TYPE",(function(t,e){return`The "${t}" argument must be of type number. Received type ${typeof e}`}),TypeError),j("ERR_OUT_OF_RANGE",(function(t,e,n){let r=`The value of "${t}" is out of range.`,i=n;return Number.isInteger(n)&&Math.abs(n)>2**32?i=G(String(n)):"bigint"==typeof n&&(i=String(n),(n>BigInt(2)**BigInt(32)||n<-(BigInt(2)**BigInt(32)))&&(i=G(i)),i+="n"),r+=` It must be ${e}. Received ${i}`,r}),RangeError);const Y=/[^+/0-9A-Za-z-_]/g;function X(t,e){let n;e=e||1/0;const r=t.length;let i=null;const o=[];for(let a=0;a<r;++a){if(n=t.charCodeAt(a),n>55295&&n<57344){if(!i){if(n>56319){(e-=3)>-1&&o.push(239,191,189);continue}if(a+1===r){(e-=3)>-1&&o.push(239,191,189);continue}i=n;continue}if(n<56320){(e-=3)>-1&&o.push(239,191,189),i=n;continue}n=65536+(i-55296<<10|n-56320)}else i&&(e-=3)>-1&&o.push(239,191,189);if(i=null,n<128){if((e-=1)<0)break;o.push(n)}else if(n<2048){if((e-=2)<0)break;o.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;o.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;o.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return o}function q(t){return r.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(Y,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function z(t,e,n,r){let i;for(i=0;i<r&&!(i+n>=e.length||i>=t.length);++i)e[i+n]=t[i];return i}function H(t,e){return t instanceof e||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===e.name}function Q(t){return t!=t}const Z=function(){const t="0123456789abcdef",e=new Array(256);for(let n=0;n<16;++n){const r=16*n;for(let i=0;i<16;++i)e[r+i]=t[n]+t[i]}return e}();function J(t){return"undefined"==typeof BigInt?K:t}function K(){throw new Error("BigInt not supported")}},333:(t,e)=>{e.read=function(t,e,n,r,i){var o,a,s=8*i-r-1,u=(1<<s)-1,c=u>>1,f=-7,l=n?i-1:0,h=n?-1:1,p=t[e+l];for(l+=h,o=p&(1<<-f)-1,p>>=-f,f+=s;f>0;o=256*o+t[e+l],l+=h,f-=8);for(a=o&(1<<-f)-1,o>>=-f,f+=r;f>0;a=256*a+t[e+l],l+=h,f-=8);if(0===o)o=1-c;else{if(o===u)return a?NaN:1/0*(p?-1:1);a+=Math.pow(2,r),o-=c}return(p?-1:1)*a*Math.pow(2,o-r)},e.write=function(t,e,n,r,i,o){var a,s,u,c=8*o-i-1,f=(1<<c)-1,l=f>>1,h=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,p=r?0:o-1,d=r?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(s=isNaN(e)?1:0,a=f):(a=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-a))<1&&(a--,u*=2),(e+=a+l>=1?h/u:h*Math.pow(2,1-l))*u>=2&&(a++,u/=2),a+l>=f?(s=0,a=f):a+l>=1?(s=(e*u-1)*Math.pow(2,i),a+=l):(s=e*Math.pow(2,l-1)*Math.pow(2,i),a=0));i>=8;t[n+p]=255&s,p+=d,s/=256,i-=8);for(a=a<<i|s,c+=i;c>0;t[n+p]=255&a,p+=d,a/=256,c-=8);t[n+p-d]|=128*g}},480:(t,e,n)=>{!function(t){t.parser=function(t,e){return new i(t,e)},t.SAXParser=i,t.SAXStream=a,t.createStream=function(t,e){return new a(t,e)},t.MAX_BUFFER_LENGTH=65536;var e,r=["comment","sgmlDecl","textNode","tagName","doctype","procInstName","procInstBody","entity","attribName","attribValue","cdata","script"];function i(e,n){if(!(this instanceof i))return new i(e,n);var o=this;!function(t){for(var e=0,n=r.length;e<n;e++)t[r[e]]=""}(o),o.q=o.c="",o.bufferCheckPosition=t.MAX_BUFFER_LENGTH,o.opt=n||{},o.opt.lowercase=o.opt.lowercase||o.opt.lowercasetags,o.looseCase=o.opt.lowercase?"toLowerCase":"toUpperCase",o.tags=[],o.closed=o.closedRoot=o.sawRoot=!1,o.tag=o.error=null,o.strict=!!e,o.noscript=!(!e&&!o.opt.noscript),o.state=w.BEGIN,o.strictEntities=o.opt.strictEntities,o.ENTITIES=o.strictEntities?Object.create(t.XML_ENTITIES):Object.create(t.ENTITIES),o.attribList=[],o.opt.xmlns&&(o.ns=Object.create(c)),o.trackPosition=!1!==o.opt.position,o.trackPosition&&(o.position=o.line=o.column=0),A(o,"onready")}t.EVENTS=["text","processinginstruction","sgmldeclaration","doctype","comment","opentagstart","attribute","opentag","closetag","opencdata","cdata","closecdata","error","end","ready","script","opennamespace","closenamespace"],Object.create||(Object.create=function(t){function e(){}return e.prototype=t,new e}),Object.keys||(Object.keys=function(t){var e=[];for(var n in t)t.hasOwnProperty(n)&&e.push(n);return e}),i.prototype={end:function(){O(this)},write:function(e){var n=this;if(this.error)throw this.error;if(n.closed)return C(n,"Cannot write after close. Assign an onready handler.");if(null===e)return O(n);"object"==typeof e&&(e=e.toString());for(var i=0,o="";o=M(e,i++),n.c=o,o;)switch(n.trackPosition&&(n.position++,"\n"===o?(n.line++,n.column=0):n.column++),n.state){case w.BEGIN:if(n.state=w.BEGIN_WHITESPACE,"\ufeff"===o)continue;F(n,o);continue;case w.BEGIN_WHITESPACE:F(n,o);continue;case w.TEXT:if(n.sawRoot&&!n.closedRoot){for(var a=i-1;o&&"<"!==o&&"&"!==o;)(o=M(e,i++))&&n.trackPosition&&(n.position++,"\n"===o?(n.line++,n.column=0):n.column++);n.textNode+=e.substring(a,i-1)}"<"!==o||n.sawRoot&&n.closedRoot&&!n.strict?(d(o)||n.sawRoot&&!n.closedRoot||S(n,"Text data outside of root node."),"&"===o?n.state=w.TEXT_ENTITY:n.textNode+=o):(n.state=w.OPEN_WAKA,n.startTagPosition=n.position);continue;case w.SCRIPT:"<"===o?n.state=w.SCRIPT_ENDING:n.script+=o;continue;case w.SCRIPT_ENDING:"/"===o?n.state=w.CLOSE_TAG:(n.script+="<"+o,n.state=w.SCRIPT);continue;case w.OPEN_WAKA:if("!"===o)n.state=w.SGML_DECL,n.sgmlDecl="";else if(d(o));else if(y(f,o))n.state=w.OPEN_TAG,n.tagName=o;else if("/"===o)n.state=w.CLOSE_TAG,n.tagName="";else if("?"===o)n.state=w.PROC_INST,n.procInstName=n.procInstBody="";else{if(S(n,"Unencoded <"),n.startTagPosition+1<n.position){var s=n.position-n.startTagPosition;o=new Array(s).join(" ")+o}n.textNode+="<"+o,n.state=w.TEXT}continue;case w.SGML_DECL:"[CDATA["===(n.sgmlDecl+o).toUpperCase()?(I(n,"onopencdata"),n.state=w.CDATA,n.sgmlDecl="",n.cdata=""):n.sgmlDecl+o==="--"?(n.state=w.COMMENT,n.comment="",n.sgmlDecl=""):"DOCTYPE"===(n.sgmlDecl+o).toUpperCase()?(n.state=w.DOCTYPE,(n.doctype||n.sawRoot)&&S(n,"Inappropriately located doctype declaration"),n.doctype="",n.sgmlDecl=""):">"===o?(I(n,"onsgmldeclaration",n.sgmlDecl),n.sgmlDecl="",n.state=w.TEXT):g(o)?(n.state=w.SGML_DECL_QUOTED,n.sgmlDecl+=o):n.sgmlDecl+=o;continue;case w.SGML_DECL_QUOTED:o===n.q&&(n.state=w.SGML_DECL,n.q=""),n.sgmlDecl+=o;continue;case w.DOCTYPE:">"===o?(n.state=w.TEXT,I(n,"ondoctype",n.doctype),n.doctype=!0):(n.doctype+=o,"["===o?n.state=w.DOCTYPE_DTD:g(o)&&(n.state=w.DOCTYPE_QUOTED,n.q=o));continue;case w.DOCTYPE_QUOTED:n.doctype+=o,o===n.q&&(n.q="",n.state=w.DOCTYPE);continue;case w.DOCTYPE_DTD:n.doctype+=o,"]"===o?n.state=w.DOCTYPE:g(o)&&(n.state=w.DOCTYPE_DTD_QUOTED,n.q=o);continue;case w.DOCTYPE_DTD_QUOTED:n.doctype+=o,o===n.q&&(n.state=w.DOCTYPE_DTD,n.q="");continue;case w.COMMENT:"-"===o?n.state=w.COMMENT_ENDING:n.comment+=o;continue;case w.COMMENT_ENDING:"-"===o?(n.state=w.COMMENT_ENDED,n.comment=B(n.opt,n.comment),n.comment&&I(n,"oncomment",n.comment),n.comment=""):(n.comment+="-"+o,n.state=w.COMMENT);continue;case w.COMMENT_ENDED:">"!==o?(S(n,"Malformed comment"),n.comment+="--"+o,n.state=w.COMMENT):n.state=w.TEXT;continue;case w.CDATA:"]"===o?n.state=w.CDATA_ENDING:n.cdata+=o;continue;case w.CDATA_ENDING:"]"===o?n.state=w.CDATA_ENDING_2:(n.cdata+="]"+o,n.state=w.CDATA);continue;case w.CDATA_ENDING_2:">"===o?(n.cdata&&I(n,"oncdata",n.cdata),I(n,"onclosecdata"),n.cdata="",n.state=w.TEXT):"]"===o?n.cdata+="]":(n.cdata+="]]"+o,n.state=w.CDATA);continue;case w.PROC_INST:"?"===o?n.state=w.PROC_INST_ENDING:d(o)?n.state=w.PROC_INST_BODY:n.procInstName+=o;continue;case w.PROC_INST_BODY:if(!n.procInstBody&&d(o))continue;"?"===o?n.state=w.PROC_INST_ENDING:n.procInstBody+=o;continue;case w.PROC_INST_ENDING:">"===o?(I(n,"onprocessinginstruction",{name:n.procInstName,body:n.procInstBody}),n.procInstName=n.procInstBody="",n.state=w.TEXT):(n.procInstBody+="?"+o,n.state=w.PROC_INST_BODY);continue;case w.OPEN_TAG:y(l,o)?n.tagName+=o:(U(n),">"===o?P(n):"/"===o?n.state=w.OPEN_TAG_SLASH:(d(o)||S(n,"Invalid character in tag name"),n.state=w.ATTRIB));continue;case w.OPEN_TAG_SLASH:">"===o?(P(n,!0),R(n)):(S(n,"Forward-slash in opening tag not followed by >"),n.state=w.ATTRIB);continue;case w.ATTRIB:if(d(o))continue;">"===o?P(n):"/"===o?n.state=w.OPEN_TAG_SLASH:y(f,o)?(n.attribName=o,n.attribValue="",n.state=w.ATTRIB_NAME):S(n,"Invalid attribute name");continue;case w.ATTRIB_NAME:"="===o?n.state=w.ATTRIB_VALUE:">"===o?(S(n,"Attribute without value"),n.attribValue=n.attribName,D(n),P(n)):d(o)?n.state=w.ATTRIB_NAME_SAW_WHITE:y(l,o)?n.attribName+=o:S(n,"Invalid attribute name");continue;case w.ATTRIB_NAME_SAW_WHITE:if("="===o)n.state=w.ATTRIB_VALUE;else{if(d(o))continue;S(n,"Attribute without value"),n.tag.attributes[n.attribName]="",n.attribValue="",I(n,"onattribute",{name:n.attribName,value:""}),n.attribName="",">"===o?P(n):y(f,o)?(n.attribName=o,n.state=w.ATTRIB_NAME):(S(n,"Invalid attribute name"),n.state=w.ATTRIB)}continue;case w.ATTRIB_VALUE:if(d(o))continue;g(o)?(n.q=o,n.state=w.ATTRIB_VALUE_QUOTED):(S(n,"Unquoted attribute value"),n.state=w.ATTRIB_VALUE_UNQUOTED,n.attribValue=o);continue;case w.ATTRIB_VALUE_QUOTED:if(o!==n.q){"&"===o?n.state=w.ATTRIB_VALUE_ENTITY_Q:n.attribValue+=o;continue}D(n),n.q="",n.state=w.ATTRIB_VALUE_CLOSED;continue;case w.ATTRIB_VALUE_CLOSED:d(o)?n.state=w.ATTRIB:">"===o?P(n):"/"===o?n.state=w.OPEN_TAG_SLASH:y(f,o)?(S(n,"No whitespace between attributes"),n.attribName=o,n.attribValue="",n.state=w.ATTRIB_NAME):S(n,"Invalid attribute name");continue;case w.ATTRIB_VALUE_UNQUOTED:if(!m(o)){"&"===o?n.state=w.ATTRIB_VALUE_ENTITY_U:n.attribValue+=o;continue}D(n),">"===o?P(n):n.state=w.ATTRIB;continue;case w.CLOSE_TAG:if(n.tagName)">"===o?R(n):y(l,o)?n.tagName+=o:n.script?(n.script+="</"+n.tagName,n.tagName="",n.state=w.SCRIPT):(d(o)||S(n,"Invalid tagname in closing tag"),n.state=w.CLOSE_TAG_SAW_WHITE);else{if(d(o))continue;v(f,o)?n.script?(n.script+="</"+o,n.state=w.SCRIPT):S(n,"Invalid tagname in closing tag."):n.tagName=o}continue;case w.CLOSE_TAG_SAW_WHITE:if(d(o))continue;">"===o?R(n):S(n,"Invalid characters in closing tag");continue;case w.TEXT_ENTITY:case w.ATTRIB_VALUE_ENTITY_Q:case w.ATTRIB_VALUE_ENTITY_U:var u,c;switch(n.state){case w.TEXT_ENTITY:u=w.TEXT,c="textNode";break;case w.ATTRIB_VALUE_ENTITY_Q:u=w.ATTRIB_VALUE_QUOTED,c="attribValue";break;case w.ATTRIB_VALUE_ENTITY_U:u=w.ATTRIB_VALUE_UNQUOTED,c="attribValue"}";"===o?(n[c]+=L(n),n.entity="",n.state=u):y(n.entity.length?p:h,o)?n.entity+=o:(S(n,"Invalid character in entity name"),n[c]+="&"+n.entity+o,n.entity="",n.state=u);continue;default:throw new Error(n,"Unknown state: "+n.state)}return n.position>=n.bufferCheckPosition&&function(e){for(var n=Math.max(t.MAX_BUFFER_LENGTH,10),i=0,o=0,a=r.length;o<a;o++){var s=e[r[o]].length;if(s>n)switch(r[o]){case"textNode":_(e);break;case"cdata":I(e,"oncdata",e.cdata),e.cdata="";break;case"script":I(e,"onscript",e.script),e.script="";break;default:C(e,"Max buffer length exceeded: "+r[o])}i=Math.max(i,s)}var u=t.MAX_BUFFER_LENGTH-i;e.bufferCheckPosition=u+e.position}(n),n},resume:function(){return this.error=null,this},close:function(){return this.write(null)},flush:function(){var t;_(t=this),""!==t.cdata&&(I(t,"oncdata",t.cdata),t.cdata=""),""!==t.script&&(I(t,"onscript",t.script),t.script="")}};try{e=n(761).F}catch(t){e=function(){}}var o=t.EVENTS.filter((function(t){return"error"!==t&&"end"!==t}));function a(t,n){if(!(this instanceof a))return new a(t,n);e.apply(this),this._parser=new i(t,n),this.writable=!0,this.readable=!0;var r=this;this._parser.onend=function(){r.emit("end")},this._parser.onerror=function(t){r.emit("error",t),r._parser.error=null},this._decoder=null,o.forEach((function(t){Object.defineProperty(r,"on"+t,{get:function(){return r._parser["on"+t]},set:function(e){if(!e)return r.removeAllListeners(t),r._parser["on"+t]=e,e;r.on(t,e)},enumerable:!0,configurable:!1})}))}a.prototype=Object.create(e.prototype,{constructor:{value:a}}),a.prototype.write=function(t){if("function"==typeof Buffer&&"function"==typeof Buffer.isBuffer&&Buffer.isBuffer(t)){if(!this._decoder){var e=n(214).s;this._decoder=new e("utf8")}t=this._decoder.write(t)}return this._parser.write(t.toString()),this.emit("data",t),!0},a.prototype.end=function(t){return t&&t.length&&this.write(t),this._parser.end(),!0},a.prototype.on=function(t,n){var r=this;return r._parser["on"+t]||-1===o.indexOf(t)||(r._parser["on"+t]=function(){var e=1===arguments.length?[arguments[0]]:Array.apply(null,arguments);e.splice(0,0,t),r.emit.apply(r,e)}),e.prototype.on.call(r,t,n)};var s="http://www.w3.org/XML/1998/namespace",u="http://www.w3.org/2000/xmlns/",c={xml:s,xmlns:u},f=/[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/,l=/[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/,h=/[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/,p=/[#:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040.\d-]/;function d(t){return" "===t||"\n"===t||"\r"===t||"\t"===t}function g(t){return'"'===t||"'"===t}function m(t){return">"===t||d(t)}function y(t,e){return t.test(e)}function v(t,e){return!y(t,e)}var b,E,T,w=0;for(var N in t.STATE={BEGIN:w++,BEGIN_WHITESPACE:w++,TEXT:w++,TEXT_ENTITY:w++,OPEN_WAKA:w++,SGML_DECL:w++,SGML_DECL_QUOTED:w++,DOCTYPE:w++,DOCTYPE_QUOTED:w++,DOCTYPE_DTD:w++,DOCTYPE_DTD_QUOTED:w++,COMMENT_STARTING:w++,COMMENT:w++,COMMENT_ENDING:w++,COMMENT_ENDED:w++,CDATA:w++,CDATA_ENDING:w++,CDATA_ENDING_2:w++,PROC_INST:w++,PROC_INST_BODY:w++,PROC_INST_ENDING:w++,OPEN_TAG:w++,OPEN_TAG_SLASH:w++,ATTRIB:w++,ATTRIB_NAME:w++,ATTRIB_NAME_SAW_WHITE:w++,ATTRIB_VALUE:w++,ATTRIB_VALUE_QUOTED:w++,ATTRIB_VALUE_CLOSED:w++,ATTRIB_VALUE_UNQUOTED:w++,ATTRIB_VALUE_ENTITY_Q:w++,ATTRIB_VALUE_ENTITY_U:w++,CLOSE_TAG:w++,CLOSE_TAG_SAW_WHITE:w++,SCRIPT:w++,SCRIPT_ENDING:w++},t.XML_ENTITIES={amp:"&",gt:">",lt:"<",quot:'"',apos:"'"},t.ENTITIES={amp:"&",gt:">",lt:"<",quot:'"',apos:"'",AElig:198,Aacute:193,Acirc:194,Agrave:192,Aring:197,Atilde:195,Auml:196,Ccedil:199,ETH:208,Eacute:201,Ecirc:202,Egrave:200,Euml:203,Iacute:205,Icirc:206,Igrave:204,Iuml:207,Ntilde:209,Oacute:211,Ocirc:212,Ograve:210,Oslash:216,Otilde:213,Ouml:214,THORN:222,Uacute:218,Ucirc:219,Ugrave:217,Uuml:220,Yacute:221,aacute:225,acirc:226,aelig:230,agrave:224,aring:229,atilde:227,auml:228,ccedil:231,eacute:233,ecirc:234,egrave:232,eth:240,euml:235,iacute:237,icirc:238,igrave:236,iuml:239,ntilde:241,oacute:243,ocirc:244,ograve:242,oslash:248,otilde:245,ouml:246,szlig:223,thorn:254,uacute:250,ucirc:251,ugrave:249,uuml:252,yacute:253,yuml:255,copy:169,reg:174,nbsp:160,iexcl:161,cent:162,pound:163,curren:164,yen:165,brvbar:166,sect:167,uml:168,ordf:170,laquo:171,not:172,shy:173,macr:175,deg:176,plusmn:177,sup1:185,sup2:178,sup3:179,acute:180,micro:181,para:182,middot:183,cedil:184,ordm:186,raquo:187,frac14:188,frac12:189,frac34:190,iquest:191,times:215,divide:247,OElig:338,oelig:339,Scaron:352,scaron:353,Yuml:376,fnof:402,circ:710,tilde:732,Alpha:913,Beta:914,Gamma:915,Delta:916,Epsilon:917,Zeta:918,Eta:919,Theta:920,Iota:921,Kappa:922,Lambda:923,Mu:924,Nu:925,Xi:926,Omicron:927,Pi:928,Rho:929,Sigma:931,Tau:932,Upsilon:933,Phi:934,Chi:935,Psi:936,Omega:937,alpha:945,beta:946,gamma:947,delta:948,epsilon:949,zeta:950,eta:951,theta:952,iota:953,kappa:954,lambda:955,mu:956,nu:957,xi:958,omicron:959,pi:960,rho:961,sigmaf:962,sigma:963,tau:964,upsilon:965,phi:966,chi:967,psi:968,omega:969,thetasym:977,upsih:978,piv:982,ensp:8194,emsp:8195,thinsp:8201,zwnj:8204,zwj:8205,lrm:8206,rlm:8207,ndash:8211,mdash:8212,lsquo:8216,rsquo:8217,sbquo:8218,ldquo:8220,rdquo:8221,bdquo:8222,dagger:8224,Dagger:8225,bull:8226,hellip:8230,permil:8240,prime:8242,Prime:8243,lsaquo:8249,rsaquo:8250,oline:8254,frasl:8260,euro:8364,image:8465,weierp:8472,real:8476,trade:8482,alefsym:8501,larr:8592,uarr:8593,rarr:8594,darr:8595,harr:8596,crarr:8629,lArr:8656,uArr:8657,rArr:8658,dArr:8659,hArr:8660,forall:8704,part:8706,exist:8707,empty:8709,nabla:8711,isin:8712,notin:8713,ni:8715,prod:8719,sum:8721,minus:8722,lowast:8727,radic:8730,prop:8733,infin:8734,ang:8736,and:8743,or:8744,cap:8745,cup:8746,int:8747,there4:8756,sim:8764,cong:8773,asymp:8776,ne:8800,equiv:8801,le:8804,ge:8805,sub:8834,sup:8835,nsub:8836,sube:8838,supe:8839,oplus:8853,otimes:8855,perp:8869,sdot:8901,lceil:8968,rceil:8969,lfloor:8970,rfloor:8971,lang:9001,rang:9002,loz:9674,spades:9824,clubs:9827,hearts:9829,diams:9830},Object.keys(t.ENTITIES).forEach((function(e){var n=t.ENTITIES[e],r="number"==typeof n?String.fromCharCode(n):n;t.ENTITIES[e]=r})),t.STATE)t.STATE[t.STATE[N]]=N;function A(t,e,n){t[e]&&t[e](n)}function I(t,e,n){t.textNode&&_(t),A(t,e,n)}function _(t){t.textNode=B(t.opt,t.textNode),t.textNode&&A(t,"ontext",t.textNode),t.textNode=""}function B(t,e){return t.trim&&(e=e.trim()),t.normalize&&(e=e.replace(/\s+/g," ")),e}function C(t,e){return _(t),t.trackPosition&&(e+="\nLine: "+t.line+"\nColumn: "+t.column+"\nChar: "+t.c),e=new Error(e),t.error=e,A(t,"onerror",e),t}function O(t){return t.sawRoot&&!t.closedRoot&&S(t,"Unclosed root tag"),t.state!==w.BEGIN&&t.state!==w.BEGIN_WHITESPACE&&t.state!==w.TEXT&&C(t,"Unexpected end"),_(t),t.c="",t.closed=!0,A(t,"onend"),i.call(t,t.strict,t.opt),t}function S(t,e){if("object"!=typeof t||!(t instanceof i))throw new Error("bad call to strictFail");t.strict&&C(t,e)}function U(t){t.strict||(t.tagName=t.tagName[t.looseCase]());var e=t.tags[t.tags.length-1]||t,n=t.tag={name:t.tagName,attributes:{}};t.opt.xmlns&&(n.ns=e.ns),t.attribList.length=0,I(t,"onopentagstart",n)}function x(t,e){var n=t.indexOf(":")<0?["",t]:t.split(":"),r=n[0],i=n[1];return e&&"xmlns"===t&&(r="xmlns",i=""),{prefix:r,local:i}}function D(t){if(t.strict||(t.attribName=t.attribName[t.looseCase]()),-1!==t.attribList.indexOf(t.attribName)||t.tag.attributes.hasOwnProperty(t.attribName))t.attribName=t.attribValue="";else{if(t.opt.xmlns){var e=x(t.attribName,!0),n=e.prefix,r=e.local;if("xmlns"===n)if("xml"===r&&t.attribValue!==s)S(t,"xml: prefix must be bound to "+s+"\nActual: "+t.attribValue);else if("xmlns"===r&&t.attribValue!==u)S(t,"xmlns: prefix must be bound to "+u+"\nActual: "+t.attribValue);else{var i=t.tag,o=t.tags[t.tags.length-1]||t;i.ns===o.ns&&(i.ns=Object.create(o.ns)),i.ns[r]=t.attribValue}t.attribList.push([t.attribName,t.attribValue])}else t.tag.attributes[t.attribName]=t.attribValue,I(t,"onattribute",{name:t.attribName,value:t.attribValue});t.attribName=t.attribValue=""}}function P(t,e){if(t.opt.xmlns){var n=t.tag,r=x(t.tagName);n.prefix=r.prefix,n.local=r.local,n.uri=n.ns[r.prefix]||"",n.prefix&&!n.uri&&(S(t,"Unbound namespace prefix: "+JSON.stringify(t.tagName)),n.uri=r.prefix);var i=t.tags[t.tags.length-1]||t;n.ns&&i.ns!==n.ns&&Object.keys(n.ns).forEach((function(e){I(t,"onopennamespace",{prefix:e,uri:n.ns[e]})}));for(var o=0,a=t.attribList.length;o<a;o++){var s=t.attribList[o],u=s[0],c=s[1],f=x(u,!0),l=f.prefix,h=f.local,p=""===l?"":n.ns[l]||"",d={name:u,value:c,prefix:l,local:h,uri:p};l&&"xmlns"!==l&&!p&&(S(t,"Unbound namespace prefix: "+JSON.stringify(l)),d.uri=l),t.tag.attributes[u]=d,I(t,"onattribute",d)}t.attribList.length=0}t.tag.isSelfClosing=!!e,t.sawRoot=!0,t.tags.push(t.tag),I(t,"onopentag",t.tag),e||(t.noscript||"script"!==t.tagName.toLowerCase()?t.state=w.TEXT:t.state=w.SCRIPT,t.tag=null,t.tagName=""),t.attribName=t.attribValue="",t.attribList.length=0}function R(t){if(!t.tagName)return S(t,"Weird empty close tag."),t.textNode+="</>",void(t.state=w.TEXT);if(t.script){if("script"!==t.tagName)return t.script+="</"+t.tagName+">",t.tagName="",void(t.state=w.SCRIPT);I(t,"onscript",t.script),t.script=""}var e=t.tags.length,n=t.tagName;t.strict||(n=n[t.looseCase]());for(var r=n;e--&&t.tags[e].name!==r;)S(t,"Unexpected close tag");if(e<0)return S(t,"Unmatched closing tag: "+t.tagName),t.textNode+="</"+t.tagName+">",void(t.state=w.TEXT);t.tagName=n;for(var i=t.tags.length;i-- >e;){var o=t.tag=t.tags.pop();t.tagName=t.tag.name,I(t,"onclosetag",t.tagName);var a={};for(var s in o.ns)a[s]=o.ns[s];var u=t.tags[t.tags.length-1]||t;t.opt.xmlns&&o.ns!==u.ns&&Object.keys(o.ns).forEach((function(e){var n=o.ns[e];I(t,"onclosenamespace",{prefix:e,uri:n})}))}0===e&&(t.closedRoot=!0),t.tagName=t.attribValue=t.attribName="",t.attribList.length=0,t.state=w.TEXT}function L(t){var e,n=t.entity,r=n.toLowerCase(),i="";return t.ENTITIES[n]?t.ENTITIES[n]:t.ENTITIES[r]?t.ENTITIES[r]:("#"===(n=r).charAt(0)&&("x"===n.charAt(1)?(n=n.slice(2),i=(e=parseInt(n,16)).toString(16)):(n=n.slice(1),i=(e=parseInt(n,10)).toString(10))),n=n.replace(/^0+/,""),isNaN(e)||i.toLowerCase()!==n?(S(t,"Invalid character entity"),"&"+t.entity+";"):String.fromCodePoint(e))}function F(t,e){"<"===e?(t.state=w.OPEN_WAKA,t.startTagPosition=t.position):d(e)||(S(t,"Non-whitespace before first tag."),t.textNode=e,t.state=w.TEXT)}function M(t,e){var n="";return e<t.length&&(n=t.charAt(e)),n}w=t.STATE,String.fromCodePoint||(b=String.fromCharCode,E=Math.floor,T=function(){var t,e,n=16384,r=[],i=-1,o=arguments.length;if(!o)return"";for(var a="";++i<o;){var s=Number(arguments[i]);if(!isFinite(s)||s<0||s>1114111||E(s)!==s)throw RangeError("Invalid code point: "+s);s<=65535?r.push(s):(t=55296+((s-=65536)>>10),e=s%1024+56320,r.push(t,e)),(i+1===o||r.length>n)&&(a+=b.apply(null,r),r.length=0)}return a},Object.defineProperty?Object.defineProperty(String,"fromCodePoint",{value:T,configurable:!0,writable:!0}):String.fromCodePoint=T)}(e)},214:(t,e,n)=>{"use strict";var r=n(805).Buffer,i=r.isEncoding||function(t){switch((t=""+t)&&t.toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":case"raw":return!0;default:return!1}};function o(t){var e;switch(this.encoding=function(t){var e=function(t){if(!t)return"utf8";for(var e;;)switch(t){case"utf8":case"utf-8":return"utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return"utf16le";case"latin1":case"binary":return"latin1";case"base64":case"ascii":case"hex":return t;default:if(e)return;t=(""+t).toLowerCase(),e=!0}}(t);if("string"!=typeof e&&(r.isEncoding===i||!i(t)))throw new Error("Unknown encoding: "+t);return e||t}(t),this.encoding){case"utf16le":this.text=u,this.end=c,e=4;break;case"utf8":this.fillLast=s,e=4;break;case"base64":this.text=f,this.end=l,e=3;break;default:return this.write=h,void(this.end=p)}this.lastNeed=0,this.lastTotal=0,this.lastChar=r.allocUnsafe(e)}function a(t){return t<=127?0:t>>5==6?2:t>>4==14?3:t>>3==30?4:t>>6==2?-1:-2}function s(t){var e=this.lastTotal-this.lastNeed,n=function(t,e,n){if(128!=(192&e[0]))return t.lastNeed=0,"�";if(t.lastNeed>1&&e.length>1){if(128!=(192&e[1]))return t.lastNeed=1,"�";if(t.lastNeed>2&&e.length>2&&128!=(192&e[2]))return t.lastNeed=2,"�"}}(this,t);return void 0!==n?n:this.lastNeed<=t.length?(t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(t.copy(this.lastChar,e,0,t.length),void(this.lastNeed-=t.length))}function u(t,e){if((t.length-e)%2==0){var n=t.toString("utf16le",e);if(n){var r=n.charCodeAt(n.length-1);if(r>=55296&&r<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],n.slice(0,-1)}return n}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function c(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var n=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,n)}return e}function f(t,e){var n=(t.length-e)%3;return 0===n?t.toString("base64",e):(this.lastNeed=3-n,this.lastTotal=3,1===n?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-n))}function l(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function h(t){return t.toString(this.encoding)}function p(t){return t&&t.length?this.write(t):""}e.s=o,o.prototype.write=function(t){if(0===t.length)return"";var e,n;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return"";n=this.lastNeed,this.lastNeed=0}else n=0;return n<t.length?e?e+this.text(t,n):this.text(t,n):e||""},o.prototype.end=function(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+"�":e},o.prototype.text=function(t,e){var n=function(t,e,n){var r=e.length-1;if(r<n)return 0;var i=a(e[r]);return i>=0?(i>0&&(t.lastNeed=i-1),i):--r<n||-2===i?0:(i=a(e[r]))>=0?(i>0&&(t.lastNeed=i-2),i):--r<n||-2===i?0:(i=a(e[r]))>=0?(i>0&&(2===i?i=0:t.lastNeed=i-3),i):0}(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=n;var r=t.length-(n-this.lastNeed);return t.copy(this.lastChar,0,r),t.toString("utf8",e,r)},o.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length}},805:(t,e,n)=>{var r=n(834),i=r.Buffer;function o(t,e){for(var n in t)e[n]=t[n]}function a(t,e,n){return i(t,e,n)}i.from&&i.alloc&&i.allocUnsafe&&i.allocUnsafeSlow?t.exports=r:(o(r,e),e.Buffer=a),o(i,a),a.from=function(t,e,n){if("number"==typeof t)throw new TypeError("Argument must not be a number");return i(t,e,n)},a.alloc=function(t,e,n){if("number"!=typeof t)throw new TypeError("Argument must be a number");var r=i(t);return void 0!==e?"string"==typeof n?r.fill(e,n):r.fill(e):r.fill(0),r},a.allocUnsafe=function(t){if("number"!=typeof t)throw new TypeError("Argument must be a number");return i(t)},a.allocUnsafeSlow=function(t){if("number"!=typeof t)throw new TypeError("Argument must be a number");return r.SlowBuffer(t)}},668:(t,e,n)=>{t.exports=n(983)},983:(t,e,n)=>{!function(){var e;if(t.exports&&!n.g.xmldocAssumeBrowser)e=n(480);else if(!(e=this.sax))throw new Error("Expected sax to be defined. Make sure you're including sax.js before this file.");function r(t){var e=u[u.length-1].parser;this.name=t.name,this.attr=t.attributes,this.val="",this.children=[],this.firstChild=null,this.lastChild=null,this.line=e.line,this.column=e.column,this.position=e.position,this.startTagPosition=e.startTagPosition}function i(t){this.text=t}function o(t){this.cdata=t}function a(t){this.comment=t}function s(t){if(t&&(t=t.toString().trim()),!t)throw new Error("No XML to parse!");var n;this.doctype="",this.parser=e.parser(!0),(n=this.parser).onopentag=c,n.onclosetag=f,n.ontext=l,n.oncdata=h,n.oncomment=p,n.ondoctype=d,n.onerror=g,u=[this],this.parser.write(t),delete this.parser}r.prototype._addChild=function(t){this.children.push(t),this.firstChild||(this.firstChild=t),this.lastChild=t},r.prototype._opentag=function(t){var e=new r(t);this._addChild(e),u.unshift(e)},r.prototype._closetag=function(){u.shift()},r.prototype._text=function(t){void 0!==this.children&&(this.val+=t,this._addChild(new i(t)))},r.prototype._cdata=function(t){this.val+=t,this._addChild(new o(t))},r.prototype._comment=function(t){void 0!==this.children&&this._addChild(new a(t))},r.prototype._error=function(t){throw t},r.prototype.eachChild=function(t,e){for(var n=0,r=this.children.length;n<r;n++)if("element"===this.children[n].type&&!1===t.call(e,this.children[n],n,this.children))return},r.prototype.childNamed=function(t){for(var e=0,n=this.children.length;e<n;e++){var r=this.children[e];if(r.name===t)return r}},r.prototype.childrenNamed=function(t){for(var e=[],n=0,r=this.children.length;n<r;n++)this.children[n].name===t&&e.push(this.children[n]);return e},r.prototype.childWithAttribute=function(t,e){for(var n=0,r=this.children.length;n<r;n++){var i=this.children[n];if("element"===i.type&&(e&&i.attr[t]===e||!e&&i.attr[t]))return i}},r.prototype.descendantWithPath=function(t){for(var e=this,n=t.split("."),r=0,i=n.length;r<i;r++){if(!e||"element"!==e.type)return;e=e.childNamed(n[r])}return e},r.prototype.valueWithPath=function(t){var e=t.split("@"),n=this.descendantWithPath(e[0]);return n?e.length>1?n.attr[e[1]]:n.val:void 0},r.prototype.toString=function(t){return this.toStringWithIndent("",t)},r.prototype.toStringWithIndent=function(t,e){var n=t+"<"+this.name,r=e&&e.compressed?"":"\n";for(var i in e&&e.preserveWhitespace,this.attr)Object.prototype.hasOwnProperty.call(this.attr,i)&&(n+=" "+i+'="'+m(this.attr[i])+'"');if(1===this.children.length&&"element"!==this.children[0].type)n+=">"+this.children[0].toString(e)+"</"+this.name+">";else if(this.children.length){n+=">"+r;for(var o=t+(e&&e.compressed?"":" "),a=0,s=this.children.length;a<s;a++)n+=this.children[a].toStringWithIndent(o,e)+r;n+=t+"</"+this.name+">"}else e&&e.html?-1!==["area","base","br","col","embed","frame","hr","img","input","keygen","link","menuitem","meta","param","source","track","wbr"].indexOf(this.name)?n+="/>":n+="></"+this.name+">":n+="/>";return n},i.prototype.toString=function(t){return y(m(this.text),t)},i.prototype.toStringWithIndent=function(t,e){return t+this.toString(e)},o.prototype.toString=function(t){return"<![CDATA["+y(this.cdata,t)+"]]>"},o.prototype.toStringWithIndent=function(t,e){return t+this.toString(e)},a.prototype.toString=function(t){return"\x3c!--"+y(m(this.comment),t)+"--\x3e"},a.prototype.toStringWithIndent=function(t,e){return t+this.toString(e)},r.prototype.type="element",i.prototype.type="text",o.prototype.type="cdata",a.prototype.type="comment",function(t,e){for(var n in e)e.hasOwnProperty(n)&&(t[n]=e[n])}(s.prototype,r.prototype),s.prototype._opentag=function(t){void 0===this.children?r.call(this,t):r.prototype._opentag.apply(this,arguments)},s.prototype._doctype=function(t){this.doctype+=t};var u=null;function c(){u[0]&&u[0]._opentag.apply(u[0],arguments)}function f(){u[0]&&u[0]._closetag.apply(u[0],arguments)}function l(){u[0]&&u[0]._text.apply(u[0],arguments)}function h(){u[0]&&u[0]._cdata.apply(u[0],arguments)}function p(){u[0]&&u[0]._comment.apply(u[0],arguments)}function d(){u[0]&&u[0]._doctype.apply(u[0],arguments)}function g(){u[0]&&u[0]._error.apply(u[0],arguments)}function m(t){return t.toString().replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/'/g,"&apos;").replace(/"/g,"&quot;")}function y(t,e){var n=t;return e&&e.trimmed&&t.length>25&&(n=n.substring(0,25).trim()+"…"),e&&e.preserveWhitespace||(n=n.trim()),n}t.exports&&!n.g.xmldocAssumeBrowser?t.exports.XmlDocument=s:this.XmlDocument=s}()},761:(t,e,n)=>{"use strict";n.d(e,{F:()=>r});const r=function(){}}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var o=e[r]={exports:{}};return t[r](o,o.exports,n),o.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.g=function(){if("object"==typeof globalThis)return globalThis;try{return this||new Function("return this")()}catch(t){if("object"==typeof window)return window}}(),n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var r={};(()=>{"use strict";n.r(r),n.d(r,{Report:()=>c,createArchiveFromArrayBufferList:()=>S,createArchiveFromJszip:()=>C,createArchiveFromText:()=>_,createArchiveFromUrls:()=>A,getArchiveOpfInfo:()=>T,getManifestFromArchive:()=>E,getResourceFromArchive:()=>p});var t=n(668),e=n.n(t),i=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function a(t){try{u(r.next(t))}catch(t){o(t)}}function s(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const o=(t,{opfBasePath:e,baseUrl:n})=>{const r={contents:[],path:"",href:"",title:""};let i=t.childNamed("span")||t.childNamed("a");r.title=(null==i?void 0:i.attr.title)||(null==i?void 0:i.val.trim())||r.title;let a=null==i?void 0:i.name;"a"!==a&&(i=t.descendantWithPath(`${a}.a`),i&&(a=i.name.toLowerCase())),"a"===a&&(null==i?void 0:i.attr.href)&&(r.path=e?`${e}/${i.attr.href}`:`${i.attr.href}`,r.href=e?`${n}/${e}/${i.attr.href}`:`${n}/${i.attr.href}`);const s=t.childNamed("ol");if(s){const t=s.childrenNamed("li");t&&t.length>0&&(r.contents=t.map((t=>o(t,{opfBasePath:e,baseUrl:n}))))}return r},a=(t,{opfBasePath:e,baseUrl:n,prefix:r})=>{var i,o;const s=(null===(i=null==t?void 0:t.childNamed(`${r}content`))||void 0===i?void 0:i.attr.src)||"",u={title:(null===(o=null==t?void 0:t.descendantWithPath(`${r}navLabel.${r}text`))||void 0===o?void 0:o.val)||"",path:e?`${e}/${s}`:`${s}`,href:e?`${n}/${e}/${s}`:`${n}/${s}`,contents:[]},c=t.childrenNamed(`${r}navPoint`);return c&&c.length>0&&(u.contents=c.map((t=>a(t,{opfBasePath:e,baseUrl:n,prefix:r})))),u};var s=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function a(t){try{u(r.next(t))}catch(t){o(t)}}function s(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};let u=!1;const c={enable:t=>{u=t},log:(...t)=>{u&&console.log("[prose-reader-streamer]",...t)},warn:(...t)=>{u&&console.warn("[prose-reader-streamer]",...t)},error:(...t)=>{console.error(...t)},time:t=>{u&&console.time(`[prose-reader-streamer] [metric] ${t}`)},timeEnd:t=>{u&&console.timeEnd(`[prose-reader-streamer] [metric] ${t}`)},metric:(t,e=1/0)=>{const n="number"==typeof t?t:t.duration;u&&(t.duration<=e?console.log("[prose-reader-streamer] [metric] ",`${t.name} took ${n}ms`):console.warn("[prose-reader-streamer] [metric] ",`${t.name} took ${t.duration}ms which is above the ${e}ms target for this function`))},measurePerformance:(t,e=10,n)=>(...r)=>{const i=performance.now(),o=n(...r);if(o&&o.then)return o.then((n=>{const r=performance.now();return c.metric({name:t,duration:r-i},e),n}));const a=performance.now();return c.metric({name:t,duration:a-i},e),o}};const f=t=>{var e;const n=t.childNamed("manifest");return(null===(e=null==n?void 0:n.childrenNamed("item"))||void 0===e?void 0:e.map((t=>({href:t.attr.href||"",id:t.attr.id||"",mediaType:t.attr["media-type"]}))))||[]},l=({archive:t,baseUrl:n})=>r=>{return u=void 0,l=void 0,p=function*(){var u;const{data:l,basePath:h}=T(t)||{},p=yield(t=>s(void 0,void 0,void 0,(function*(){const n={renditionLayout:void 0};return yield Promise.all(t.files.map((t=>s(void 0,void 0,void 0,(function*(){var r,i;if(t.uri.endsWith("com.kobobooks.display-options.xml")){const o=null===(r=new(e().XmlDocument)(yield t.string()).childNamed("platform"))||void 0===r?void 0:r.childNamed("option");"fixed-layout"===(null===(i=null==o?void 0:o.attr)||void 0===i?void 0:i.name)&&"true"===o.val&&(n.renditionLayout="pre-paginated")}}))))),n})))(t);if(!l)return r;const d=yield l.string();c.log(d,p);const g=new(e().XmlDocument)(d),m=(yield((t,n,{baseUrl:r})=>i(void 0,void 0,void 0,(function*(){const{basePath:s}=T(n)||{};return(yield(({opfData:t,opfBasePath:n,baseUrl:r,archive:o})=>i(void 0,void 0,void 0,(function*(){var i;const s=t.childNamed("spine"),u=s&&s.attr.toc;if(u){const s=null===(i=t.childNamed("manifest"))||void 0===i?void 0:i.childrenNamed("item").find((t=>t.attr.id===u));if(s){const t=`${n}${""===n?"":"/"}${s.attr.href}`,i=Object.values(o.files).find((e=>e.uri.endsWith(t)));if(i)return((t,{opfBasePath:e,baseUrl:n})=>{var r;const i=[],o=t.name;let s="";return-1!==o.indexOf(":")&&(s=o.split(":")[0]+":"),null===(r=t.childNamed(`${s}navMap`))||void 0===r||r.childrenNamed(`${s}navPoint`).forEach((t=>i.push(a(t,{opfBasePath:e,baseUrl:n,prefix:s})))),i})(new(e().XmlDocument)(yield i.string()),{opfBasePath:n,baseUrl:r})}}})))({opfData:t,opfBasePath:s,archive:n,baseUrl:r}))||(yield((t,n,{opfBasePath:r,baseUrl:a})=>i(void 0,void 0,void 0,(function*(){var i;const s=null===(i=t.childNamed("manifest"))||void 0===i?void 0:i.childrenNamed("item").find((t=>"nav"===t.attr.properties));if(s){const t=Object.values(n.files).find((t=>t.uri.endsWith(s.attr.href||"")));if(t)return((t,{opfBasePath:e,baseUrl:n})=>{var r,i;const a=[];let s;return t.descendantWithPath("body.nav.ol")?s=null===(r=t.descendantWithPath("body.nav.ol"))||void 0===r?void 0:r.children:t.descendantWithPath("body.section.nav.ol")&&(s=null===(i=t.descendantWithPath("body.section.nav.ol"))||void 0===i?void 0:i.children),s&&s.length>0&&s.filter((t=>"li"===t.name)).forEach((t=>a.push(o(t,{opfBasePath:e,baseUrl:n})))),a})(new(e().XmlDocument)(yield t.string()),{opfBasePath:r,baseUrl:a})}})))(t,n,{opfBasePath:s,baseUrl:r}))})))(g,t,{baseUrl:n}))||[],y=g.childNamed("metadata"),v=g.childNamed("manifest"),b=g.childNamed("spine"),E=g.childNamed("guide"),w=null==y?void 0:y.childNamed("dc:title"),N=(null==y?void 0:y.childrenNamed("meta"))||[],A=N.find((t=>"rendition:layout"===t.attr.property)),I=N.find((t=>"rendition:flow"===t.attr.property)),_=N.find((t=>"rendition:spread"===t.attr.property)),B=null==A?void 0:A.val,C=null==I?void 0:I.val,O=null==_?void 0:_.val,S=(null==w?void 0:w.val)||(null===(u=t.files.find((({dir:t})=>t)))||void 0===u?void 0:u.basename)||"",U=null==b?void 0:b.attr["page-progression-direction"],x=null==b?void 0:b.childrenNamed("itemref").map((t=>t.attr.idref)),D=(null==v?void 0:v.childrenNamed("item").filter((t=>x.includes(t.attr.id||""))))||[],P=t.files.filter((t=>D.find((e=>h?`${h}/${e.attr.href}`===t.uri:`${e.attr.href}`===t.uri)))).reduce(((t,e)=>e.size+t),1);return{filename:t.filename,nav:{toc:m},renditionLayout:B||p.renditionLayout||"reflowable",renditionFlow:C||"auto",renditionSpread:O,title:S,readingDirection:U||"ltr",spineItems:(null==b?void 0:b.childrenNamed("itemref").map((e=>{var r,i;const o=null==v?void 0:v.childrenNamed("item").find((t=>t.attr.id===(null==e?void 0:e.attr.idref))),a=(null==o?void 0:o.attr.href)||"",s=(null===(r=null==e?void 0:e.attr.properties)||void 0===r?void 0:r.split(" "))||[],u=(null===(i=t.files.find((t=>t.uri.endsWith(a))))||void 0===i?void 0:i.size)||0;return Object.assign(Object.assign({id:(null==o?void 0:o.attr.id)||"",path:h?`${h}/${null==o?void 0:o.attr.href}`:`${null==o?void 0:o.attr.href}`,href:h?`${n}/${h}/${null==o?void 0:o.attr.href}`:`${n}/${null==o?void 0:o.attr.href}`,renditionLayout:B||"reflowable"},s.find((t=>"rendition:layout-reflowable"===t))&&{renditionLayout:"reflowable"}),{progressionWeight:u/P,pageSpreadLeft:s.some((t=>"page-spread-left"===t))||void 0,pageSpreadRight:s.some((t=>"page-spread-right"===t))||void 0,mediaType:null==o?void 0:o.attr["media-type"]})})))||[],items:f(g),guide:null==E?void 0:E.childrenNamed("reference").map((t=>({href:t.attr.href||"",title:t.attr.title||"",type:t.attr.type})))}},new((h=void 0)||(h=Promise))((function(t,e){function n(t){try{i(p.next(t))}catch(t){e(t)}}function r(t){try{i(p.throw(t))}catch(t){e(t)}}function i(e){var i;e.done?t(e.value):(i=e.value,i instanceof h?i:new h((function(t){t(i)}))).then(n,r)}i((p=p.apply(u,l||[])).next())}));var u,l,h,p};var h=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function a(t){try{u(r.next(t))}catch(t){o(t)}}function s(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const p=(t,e)=>h(void 0,void 0,void 0,(function*(){const n=Object.values(t.files).find((t=>t.uri===e)),r=yield d(t,e);if(!n)throw new Error("no file found");const i=yield n.blob();return new Response(i,{headers:Object.assign(Object.assign(Object.assign({},i.type&&{"Content-Type":i.type}),n.encodingFormat&&{"Content-Type":n.encodingFormat}),r.mediaType&&{"Content-Type":r.mediaType})})})),d=(t,n)=>h(void 0,void 0,void 0,(function*(){var r,i;const o=T(t),a=yield null===(r=o.data)||void 0===r?void 0:r.string();if(a){const t=new(e().XmlDocument)(a);return{mediaType:null===(i=f(t).find((t=>n.endsWith(t.href))))||void 0===i?void 0:i.mediaType}}return{mediaType:g(n)}})),g=t=>t.endsWith(".css")?"text/css; charset=UTF-8":t.endsWith(".jpg")?"image/jpg":t.endsWith(".xhtml")?"application/xhtml+xml":t.endsWith(".mp4")?"video/mp4":t.endsWith(".svg")?"image/svg+xml":void 0;const m=({archive:t,baseUrl:n})=>n=>{return r=void 0,i=void 0,a=function*(){var r;const i=t.files.find((t=>"comicinfo.xml"===t.basename.toLowerCase()));if(!i)return n;const o=yield i.string(),a=(null===(r=new(e().XmlDocument)(o).childNamed("Manga"))||void 0===r?void 0:r.val)||"unknown";return Object.assign(Object.assign({},n),{spineItems:n.spineItems.filter((t=>"comicinfo.xml"!==t.id.toLowerCase())),readingDirection:"YesAndRightToLeft"===a?"rtl":"ltr"})},new((o=void 0)||(o=Promise))((function(t,e){function n(t){try{u(a.next(t))}catch(t){e(t)}}function s(t){try{u(a.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof o?r:new o((function(t){t(r)}))).then(n,s)}u((a=a.apply(r,i||[])).next())}));var r,i,o,a};const y=({archive:t,baseUrl:e})=>n=>{return r=void 0,i=void 0,a=function*(){var n;const r=Object.values(t.files).filter((t=>!t.dir));return{filename:t.filename,nav:{toc:[]},title:(null===(n=t.files.find((({dir:t})=>t)))||void 0===n?void 0:n.basename.replace(/\/$/,""))||"",renditionLayout:"pre-paginated",renditionSpread:"auto",readingDirection:"ltr",spineItems:r.map((t=>({id:t.basename,path:`${t.uri}`,href:e?`${e}/${t.uri}`:t.uri,renditionLayout:"pre-paginated",progressionWeight:1/r.length,pageSpreadLeft:void 0,pageSpreadRight:void 0}))),items:r.map((t=>({id:t.basename,href:e?`${e}/${t.uri}`:t.uri})))}},new((o=void 0)||(o=Promise))((function(t,e){function n(t){try{u(a.next(t))}catch(t){e(t)}}function s(t){try{u(a.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof o?r:new o((function(t){t(r)}))).then(n,s)}u((a=a.apply(r,i||[])).next())}));var r,i,o,a};var v=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function a(t){try{u(r.next(t))}catch(t){o(t)}}function s(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const b={filename:"",items:[],nav:{toc:[]},readingDirection:"ltr",renditionLayout:"pre-paginated",renditionSpread:"auto",spineItems:[],title:""},E=(t,{baseUrl:e=""}={})=>v(void 0,void 0,void 0,(function*(){var n;const r=[y({archive:t,baseUrl:e}),l({archive:t,baseUrl:e}),m({archive:t,baseUrl:e})];try{const t=yield r.reduce(((t,e)=>v(void 0,void 0,void 0,(function*(){return yield e(yield t)}))),Promise.resolve(b)),e=JSON.stringify(t);return new Response(e,{status:200})}catch(t){return c.error(t),new Response(null===(n=t)||void 0===n?void 0:n.message,{status:500})}})),T=t=>{const e=Object.values(t.files).filter((t=>!t.dir)),n=e.find((t=>t.uri.endsWith(".opf")));return{data:n,basePath:(null==n?void 0:n.uri.substring(0,n.uri.lastIndexOf("/")))||""}},w=t=>t.substring(t.lastIndexOf("/")+1)||t;var N=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function a(t){try{u(r.next(t))}catch(t){o(t)}}function s(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const A=t=>N(void 0,void 0,void 0,(function*(){return{filename:"",files:t.map((e=>({dir:!1,basename:w(e),uri:e,size:100/t.length,base64:()=>N(void 0,void 0,void 0,(function*(){return""})),blob:()=>N(void 0,void 0,void 0,(function*(){return new Blob})),string:()=>N(void 0,void 0,void 0,(function*(){return""}))})))}}));var I=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function a(t){try{u(r.next(t))}catch(t){o(t)}}function s(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const _=(t,e)=>I(void 0,void 0,void 0,(function*(){const n=`\n <?xml version="1.0" encoding="UTF-8"?>\n <package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"\n unique-identifier="ootuya-id">\n <metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/"\n xmlns:dcterms="http://purl.org/dc/terms/">\n <meta property="rendition:layout">reflowable</meta>\n </metadata>\n <manifest>\n <item id="p01" href="p01.txt" media-type="text/plain"/>\n </manifest>\n <spine page-progression-direction="${(null==e?void 0:e.direction)||"ltr"}">\n <itemref idref="p01" />\n </spine>\n </package>\n `;return{filename:"content.txt",files:[{dir:!1,basename:w("generated.opf"),uri:"generated.opf",blob:()=>I(void 0,void 0,void 0,(function*(){return new Blob([n])})),string:()=>I(void 0,void 0,void 0,(function*(){return n})),base64:()=>I(void 0,void 0,void 0,(function*(){return btoa(n)})),size:0},{dir:!1,basename:w("p01.txt"),uri:"p01.txt",blob:()=>I(void 0,void 0,void 0,(function*(){return"string"==typeof t?new Blob([t]):t})),string:()=>I(void 0,void 0,void 0,(function*(){return"string"==typeof t?t:t.text()})),base64:()=>I(void 0,void 0,void 0,(function*(){return"string"==typeof t?btoa(t):(o=t,e=void 0,n=void 0,i=function*(){return new Promise((t=>{const e=new FileReader;e.readAsDataURL(o),e.onloadend=function(){const n=e.result;t(n)}}))},new((r=void 0)||(r=Promise))((function(t,o){function a(t){try{u(i.next(t))}catch(t){o(t)}}function s(t){try{u(i.throw(t))}catch(t){o(t)}}function u(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r((function(t){t(n)}))).then(a,s)}u((i=i.apply(e,n||[])).next())})));var e,n,r,i,o})),size:"string"==typeof t?t.length:t.size,encodingFormat:"text/plain"}]}})),B=(t,e)=>{var n;const r=t.split(/(\d+)/),i=e.split(/(\d+)/);r.slice(-1)===[""]&&r.pop(),i.slice(-1)===[""]&&i.pop();for(let t=0,e=r.length;t<e;t++)if(r[t]!==i[t])return(null===(n=r[t])||void 0===n?void 0:n.match(/\d/))?+(r[t]||"")-+(i[t]||""):(r[t]||"").localeCompare(i[t]||"");return 1};const C=(t,{orderByAlpha:e,name:n}={})=>{return r=void 0,i=void 0,a=function*(){let r=Object.values(t.files);return e&&(r=r.sort(((t,e)=>B(t.name,e.name)))),{filename:n||"",files:r.map((t=>Object.assign(Object.assign({dir:t.dir,basename:w(t.name),uri:t.name,blob:()=>t.async("blob"),string:()=>t.async("string"),base64:()=>t.async("base64")},t.internalStream&&{stream:t.internalStream}),{size:t._data.uncompressedSize})))}},new((o=void 0)||(o=Promise))((function(t,e){function n(t){try{u(a.next(t))}catch(t){e(t)}}function s(t){try{u(a.throw(t))}catch(t){e(t)}}function u(e){var r;e.done?t(e.value):(r=e.value,r instanceof o?r:new o((function(t){t(r)}))).then(n,s)}u((a=a.apply(r,i||[])).next())}));var r,i,o,a};var O=function(t,e,n,r){return new(n||(n=Promise))((function(i,o){function a(t){try{u(r.next(t))}catch(t){o(t)}}function s(t){try{u(r.throw(t))}catch(t){o(t)}}function u(t){var e;t.done?i(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}u((r=r.apply(t,e||[])).next())}))};const S=(t,{orderByAlpha:e,name:n}={})=>O(void 0,void 0,void 0,(function*(){let r=t;return e&&(r=r.sort(((t,e)=>B(t.name,e.name)))),{filename:n||"",files:r.map((t=>({dir:t.isDir,basename:w(t.name),uri:t.name,blob:()=>O(void 0,void 0,void 0,(function*(){return new Blob([yield t.data()])})),string:()=>O(void 0,void 0,void 0,(function*(){const e=yield t.data();return String.fromCharCode.apply(null,Array.from(new Uint16Array(e)))})),base64:()=>O(void 0,void 0,void 0,(function*(){return""})),size:t.size})))}}))})();var i=exports;for(var o in r)i[o]=r[o];r.__esModule&&Object.defineProperty(i,"__esModule",{value:!0})})();
package/dist/report.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare const Report: {
5
5
  error: (...data: any[]) => void;
6
6
  time: (label?: string | undefined) => void;
7
7
  timeEnd: (label?: string | undefined) => void;
8
- metric: (performanceEntry: PerformanceEntry | {
8
+ metric: (performanceEntry: {
9
9
  name: string;
10
10
  duration: number;
11
11
  }, targetDuration?: number) => void;
@@ -1 +1 @@
1
- export declare const blobToBase64: (blob: Blob | File) => Promise<string>;
1
+ export declare const blobToBase64: (blob: Blob) => Promise<string>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prose-reader/streamer",
3
- "version": "0.0.24",
3
+ "version": "0.0.28",
4
4
  "main": "dist/index.js",
5
5
  "license": "MIT",
6
6
  "files": [
@@ -37,5 +37,5 @@
37
37
  "webpack-cli": "^4.9.1",
38
38
  "webpack-dev-server": "^4.6.0"
39
39
  },
40
- "gitHead": "e9a6689e2a95a7e15db1acee46a713fffb3a801e"
40
+ "gitHead": "09308ddf45d3232af6b0b90007272d1d4f1699c3"
41
41
  }
@@ -1,35 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { sortByTitleComparator } from "../utils/sortByTitleComparator";
11
- import { getUriBasename } from "../utils/uri";
12
- export const createArchiveFromArrayBufferList = (list, { orderByAlpha, name } = {}) => __awaiter(void 0, void 0, void 0, function* () {
13
- let files = list;
14
- if (orderByAlpha) {
15
- files = files.sort((a, b) => sortByTitleComparator(a.name, b.name));
16
- }
17
- return {
18
- filename: name || ``,
19
- files: files.map(file => ({
20
- dir: file.isDir,
21
- basename: getUriBasename(file.name),
22
- uri: file.name,
23
- blob: () => __awaiter(void 0, void 0, void 0, function* () { return new Blob([yield file.data()]); }),
24
- string: () => __awaiter(void 0, void 0, void 0, function* () {
25
- const data = yield file.data();
26
- return String.fromCharCode.apply(null, Array.from(new Uint16Array(data)));
27
- }),
28
- base64: () => __awaiter(void 0, void 0, void 0, function* () {
29
- // @todo not used for now, lets implement it later if needed
30
- return ``;
31
- }),
32
- size: file.size
33
- }))
34
- };
35
- });
@@ -1,26 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { sortByTitleComparator } from "../utils/sortByTitleComparator";
11
- import { getUriBasename } from "../utils/uri";
12
- export const createArchiveFromJszip = (jszip, { orderByAlpha, name } = {}) => __awaiter(void 0, void 0, void 0, function* () {
13
- let files = Object.values(jszip.files);
14
- if (orderByAlpha) {
15
- files = files.sort((a, b) => sortByTitleComparator(a.name, b.name));
16
- }
17
- return {
18
- filename: name || ``,
19
- files: files.map(file => (Object.assign(Object.assign({ dir: file.dir, basename: getUriBasename(file.name), uri: file.name, blob: () => file.async(`blob`), string: () => file.async(`string`), base64: () => file.async(`base64`) }, file.internalStream && {
20
- stream: file.internalStream
21
- }), {
22
- // this is private API
23
- // @ts-ignore
24
- size: file._data.uncompressedSize })))
25
- };
26
- });
@@ -1,67 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { blobToBase64 } from "../utils/blobToBAse64";
11
- import { getUriBasename } from "../utils/uri";
12
- /**
13
- * Useful to create archive from txt content
14
- */
15
- export const createArchiveFromText = (content, options) => __awaiter(void 0, void 0, void 0, function* () {
16
- const txtOpfContent = `
17
- <?xml version="1.0" encoding="UTF-8"?>
18
- <package xmlns="http://www.idpf.org/2007/opf" version="3.0" xml:lang="ja" prefix="rendition: http://www.idpf.org/vocab/rendition/#"
19
- unique-identifier="ootuya-id">
20
- <metadata xmlns:opf="http://www.idpf.org/2007/opf" xmlns:dc="http://purl.org/dc/elements/1.1/"
21
- xmlns:dcterms="http://purl.org/dc/terms/">
22
- <meta property="rendition:layout">reflowable</meta>
23
- </metadata>
24
- <manifest>
25
- <item id="p01" href="p01.txt" media-type="text/plain"/>
26
- </manifest>
27
- <spine page-progression-direction="${(options === null || options === void 0 ? void 0 : options.direction) || `ltr`}">
28
- <itemref idref="p01" />
29
- </spine>
30
- </package>
31
- `;
32
- const archive = {
33
- filename: `content.txt`,
34
- files: [{
35
- dir: false,
36
- basename: getUriBasename(`generated.opf`),
37
- uri: `generated.opf`,
38
- blob: () => __awaiter(void 0, void 0, void 0, function* () { return new Blob([txtOpfContent]); }),
39
- string: () => __awaiter(void 0, void 0, void 0, function* () { return txtOpfContent; }),
40
- base64: () => __awaiter(void 0, void 0, void 0, function* () { return btoa(txtOpfContent); }),
41
- size: 0
42
- },
43
- {
44
- dir: false,
45
- basename: getUriBasename(`p01.txt`),
46
- uri: `p01.txt`,
47
- blob: () => __awaiter(void 0, void 0, void 0, function* () {
48
- if (typeof content === `string`)
49
- return new Blob([content]);
50
- return content;
51
- }),
52
- string: () => __awaiter(void 0, void 0, void 0, function* () {
53
- if (typeof content === `string`)
54
- return content;
55
- return content.text();
56
- }),
57
- base64: () => __awaiter(void 0, void 0, void 0, function* () {
58
- if (typeof content === `string`)
59
- return btoa(content);
60
- return blobToBase64(content);
61
- }),
62
- size: typeof content === `string` ? content.length : content.size,
63
- encodingFormat: `text/plain`
64
- }]
65
- };
66
- return archive;
67
- });
@@ -1,29 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import { getUriBasename } from "../utils/uri";
11
- /**
12
- * @important
13
- * Make sure the urls are on the same origin or the cors header is set otherwise
14
- * the resource cannot be consumed as it is on the web.
15
- */
16
- export const createArchiveFromUrls = (urls) => __awaiter(void 0, void 0, void 0, function* () {
17
- return {
18
- filename: ``,
19
- files: urls.map(url => ({
20
- dir: false,
21
- basename: getUriBasename(url),
22
- uri: url,
23
- size: 100 / urls.length,
24
- base64: () => __awaiter(void 0, void 0, void 0, function* () { return ``; }),
25
- blob: () => __awaiter(void 0, void 0, void 0, function* () { return new Blob(); }),
26
- string: () => __awaiter(void 0, void 0, void 0, function* () { return ``; })
27
- }))
28
- };
29
- });
@@ -1,8 +0,0 @@
1
- export const getArchiveOpfInfo = (archive) => {
2
- const filesAsArray = Object.values(archive.files).filter(file => !file.dir);
3
- const file = filesAsArray.find(file => file.uri.endsWith(`.opf`));
4
- return {
5
- data: file,
6
- basePath: (file === null || file === void 0 ? void 0 : file.uri.substring(0, file.uri.lastIndexOf(`/`))) || ``
7
- };
8
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- import xmldoc from 'xmldoc';
2
- import { Archive } from '..';
3
- export declare const getManifestFromArchive: (archive: Archive, { baseUrl }?: {
4
- baseUrl?: string | undefined;
5
- }) => Promise<Response>;
6
- export declare const getItemsFromDoc: (doc: xmldoc.XmlDocument) => {
7
- href: string;
8
- id: string;
9
- mediaType: string | undefined;
10
- }[];
@@ -1,141 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import xmldoc from 'xmldoc';
11
- import { parseToc } from '../parsers/nav';
12
- import { extractKoboInformationFromArchive } from '../parsers/kobo';
13
- import { Report } from '../report';
14
- import { getArchiveOpfInfo } from '..';
15
- const generateManifestFromEpub = (archive, baseUrl) => __awaiter(void 0, void 0, void 0, function* () {
16
- var _a;
17
- const { data: opsFile, basePath: opfBasePath } = getArchiveOpfInfo(archive) || {};
18
- const koboInformation = yield extractKoboInformationFromArchive(archive);
19
- if (!opsFile) {
20
- throw new Error(`No opf content`);
21
- }
22
- const data = yield opsFile.string();
23
- Report.log(data, koboInformation);
24
- const opfXmlDoc = new xmldoc.XmlDocument(data);
25
- const toc = (yield parseToc(opfXmlDoc, archive, { baseUrl })) || [];
26
- const metadataElm = opfXmlDoc.childNamed(`metadata`);
27
- const manifestElm = opfXmlDoc.childNamed(`manifest`);
28
- const spineElm = opfXmlDoc.childNamed(`spine`);
29
- const guideElm = opfXmlDoc.childNamed(`guide`);
30
- const titleElm = metadataElm === null || metadataElm === void 0 ? void 0 : metadataElm.childNamed(`dc:title`);
31
- const metaElmChildren = (metadataElm === null || metadataElm === void 0 ? void 0 : metadataElm.childrenNamed(`meta`)) || [];
32
- const metaElmWithRendition = metaElmChildren.find(meta => meta.attr.property === `rendition:layout`);
33
- const metaElmWithRenditionFlow = metaElmChildren.find(meta => meta.attr.property === `rendition:flow`);
34
- const metaElmWithRenditionSpread = metaElmChildren.find(meta => meta.attr.property === `rendition:spread`);
35
- const publisherRenditionLayout = metaElmWithRendition === null || metaElmWithRendition === void 0 ? void 0 : metaElmWithRendition.val;
36
- const publisherRenditionFlow = metaElmWithRenditionFlow === null || metaElmWithRenditionFlow === void 0 ? void 0 : metaElmWithRenditionFlow.val;
37
- const renditionSpread = metaElmWithRenditionSpread === null || metaElmWithRenditionSpread === void 0 ? void 0 : metaElmWithRenditionSpread.val;
38
- const title = (titleElm === null || titleElm === void 0 ? void 0 : titleElm.val) || ((_a = archive.files.find(({ dir }) => dir)) === null || _a === void 0 ? void 0 : _a.basename) || ``;
39
- const pageProgressionDirection = spineElm === null || spineElm === void 0 ? void 0 : spineElm.attr[`page-progression-direction`];
40
- const spineItemIds = spineElm === null || spineElm === void 0 ? void 0 : spineElm.childrenNamed(`itemref`).map((item) => item.attr.idref);
41
- const manifestItemsFromSpine = (manifestElm === null || manifestElm === void 0 ? void 0 : manifestElm.childrenNamed(`item`).filter((item) => spineItemIds.includes(item.attr.id || ``))) || [];
42
- const archiveSpineItems = archive.files.filter(file => {
43
- return manifestItemsFromSpine.find(item => {
44
- if (!opfBasePath)
45
- return `${item.attr.href}` === file.uri;
46
- return `${opfBasePath}/${item.attr.href}` === file.uri;
47
- });
48
- });
49
- const totalSize = archiveSpineItems.reduce((size, file) => file.size + size, 1);
50
- return {
51
- filename: archive.filename,
52
- nav: {
53
- toc
54
- },
55
- renditionLayout: publisherRenditionLayout || koboInformation.renditionLayout || `reflowable`,
56
- renditionFlow: publisherRenditionFlow || `auto`,
57
- renditionSpread,
58
- title,
59
- readingDirection: pageProgressionDirection || `ltr`,
60
- spineItems: (spineElm === null || spineElm === void 0 ? void 0 : spineElm.childrenNamed(`itemref`).map((itemrefElm) => {
61
- var _a, _b;
62
- const manifestItem = manifestElm === null || manifestElm === void 0 ? void 0 : manifestElm.childrenNamed(`item`).find((item) => item.attr.id === (itemrefElm === null || itemrefElm === void 0 ? void 0 : itemrefElm.attr.idref));
63
- const href = (manifestItem === null || manifestItem === void 0 ? void 0 : manifestItem.attr.href) || ``;
64
- const properties = (((_a = itemrefElm === null || itemrefElm === void 0 ? void 0 : itemrefElm.attr.properties) === null || _a === void 0 ? void 0 : _a.split(` `)) || []);
65
- const itemSize = ((_b = archive.files.find(file => file.uri.endsWith(href))) === null || _b === void 0 ? void 0 : _b.size) || 0;
66
- return Object.assign(Object.assign({ id: (manifestItem === null || manifestItem === void 0 ? void 0 : manifestItem.attr.id) || ``, path: opfBasePath ? `${opfBasePath}/${manifestItem === null || manifestItem === void 0 ? void 0 : manifestItem.attr.href}` : `${manifestItem === null || manifestItem === void 0 ? void 0 : manifestItem.attr.href}`,
67
- // href: opfBasePath ? `${baseUrl}/${opfBasePath}/${manifestItem?.attr['href']}` : `${baseUrl}/${manifestItem?.attr['href']}`,
68
- href: opfBasePath ? `${baseUrl}/${opfBasePath}/${manifestItem === null || manifestItem === void 0 ? void 0 : manifestItem.attr.href}` : `${baseUrl}/${manifestItem === null || manifestItem === void 0 ? void 0 : manifestItem.attr.href}`, renditionLayout: publisherRenditionLayout || `reflowable` }, properties.find(property => property === `rendition:layout-reflowable`) && {
69
- renditionLayout: `reflowable`
70
- }), { progressionWeight: itemSize / totalSize, pageSpreadLeft: properties.some(property => property === `page-spread-left`) || undefined, pageSpreadRight: properties.some(property => property === `page-spread-right`) || undefined,
71
- // size: itemSize
72
- mediaType: manifestItem === null || manifestItem === void 0 ? void 0 : manifestItem.attr[`media-type`] });
73
- })) || [],
74
- items: getItemsFromDoc(opfXmlDoc),
75
- guide: guideElm === null || guideElm === void 0 ? void 0 : guideElm.childrenNamed(`reference`).map(elm => {
76
- return {
77
- href: elm.attr.href || ``,
78
- title: elm.attr.title || ``,
79
- type: elm.attr.type
80
- };
81
- })
82
- };
83
- });
84
- /**
85
- * Create a manifest from a generic archive.
86
- * Will use direct
87
- */
88
- const generateManifestFromArchive = (archive, baseUrl) => __awaiter(void 0, void 0, void 0, function* () {
89
- var _b;
90
- const files = Object.values(archive.files).filter(file => !file.dir);
91
- return {
92
- filename: archive.filename,
93
- nav: {
94
- toc: []
95
- },
96
- title: ((_b = archive.files.find(({ dir }) => dir)) === null || _b === void 0 ? void 0 : _b.basename.replace(/\/$/, ``)) || ``,
97
- renditionLayout: `pre-paginated`,
98
- renditionSpread: `auto`,
99
- readingDirection: `ltr`,
100
- spineItems: files.map((file) => ({
101
- id: file.basename,
102
- path: `${file.uri}`,
103
- href: baseUrl ? `${baseUrl}/${file.uri}` : file.uri,
104
- renditionLayout: `pre-paginated`,
105
- progressionWeight: (1 / files.length),
106
- pageSpreadLeft: undefined,
107
- pageSpreadRight: undefined
108
- })),
109
- items: files.map((file) => ({
110
- id: file.basename,
111
- href: baseUrl ? `${baseUrl}/${file.uri}` : file.uri
112
- }))
113
- };
114
- });
115
- export const getManifestFromArchive = (archive, { baseUrl = `` } = {}) => __awaiter(void 0, void 0, void 0, function* () {
116
- var _c;
117
- const { data: opsFile } = getArchiveOpfInfo(archive) || {};
118
- try {
119
- if (opsFile) {
120
- const manifest = yield generateManifestFromEpub(archive, baseUrl);
121
- const data = JSON.stringify(manifest);
122
- return new Response(data, { status: 200 });
123
- }
124
- const manifest = yield generateManifestFromArchive(archive, baseUrl);
125
- const data = JSON.stringify(manifest);
126
- return new Response(data, { status: 200 });
127
- }
128
- catch (e) {
129
- Report.error(e);
130
- return new Response((_c = e) === null || _c === void 0 ? void 0 : _c.message, { status: 500 });
131
- }
132
- });
133
- export const getItemsFromDoc = (doc) => {
134
- var _a;
135
- const manifestElm = doc.childNamed(`manifest`);
136
- return ((_a = manifestElm === null || manifestElm === void 0 ? void 0 : manifestElm.childrenNamed(`item`)) === null || _a === void 0 ? void 0 : _a.map((el) => ({
137
- href: el.attr.href || ``,
138
- id: el.attr.id || ``,
139
- mediaType: el.attr[`media-type`]
140
- }))) || [];
141
- };
@@ -1,95 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import xmldoc from 'xmldoc';
11
- import { getArchiveOpfInfo } from '..';
12
- import { getItemsFromDoc } from "./manifest";
13
- export const getResourceFromArchive = (archive, resourcePath) => __awaiter(void 0, void 0, void 0, function* () {
14
- const file = Object.values(archive.files).find(file => file.uri === resourcePath);
15
- const metadata = yield getMetadata(archive, resourcePath);
16
- if (!file) {
17
- throw new Error(`no file found`);
18
- }
19
- const blob = yield file.blob();
20
- // if (file.stream) {
21
- // const stream = file.stream()
22
- // console.log(file, stream)
23
- // stream.on(`data`, data => {
24
- // console.log(`data`, data)
25
- // })
26
- // stream.on(`error`, data => {
27
- // console.error(`error`, data)
28
- // })
29
- // stream.on(`end`, () => {
30
- // console.log(`end`)
31
- // })
32
- // }
33
- // const stream = file.stream!()
34
- // const readableStream = new ReadableStream({
35
- // start(controller) {
36
- // function push() {
37
- // stream.on(`data`, data => {
38
- // controller.enqueue(data)
39
- // })
40
- // stream.on(`error`, data => {
41
- // console.error(`error`, data)
42
- // })
43
- // stream.on(`end`, () => {
44
- // controller.close()
45
- // })
46
- // stream.resume()
47
- // }
48
- // push();
49
- // }
50
- // })
51
- const response = new Response(blob, {
52
- headers: Object.assign(Object.assign(Object.assign({}, blob.type && {
53
- 'Content-Type': blob.type
54
- }), file.encodingFormat && {
55
- 'Content-Type': file.encodingFormat
56
- }), metadata.mediaType && {
57
- 'Content-Type': metadata.mediaType
58
- }
59
- // 'Cache-Control': `no-cache, no-store, no-transform`
60
- )
61
- });
62
- return response;
63
- });
64
- const getMetadata = (archive, resourcePath) => __awaiter(void 0, void 0, void 0, function* () {
65
- var _a, _b;
66
- const opfInfo = getArchiveOpfInfo(archive);
67
- const data = yield ((_a = opfInfo.data) === null || _a === void 0 ? void 0 : _a.string());
68
- if (data) {
69
- const opfXmlDoc = new xmldoc.XmlDocument(data);
70
- const items = getItemsFromDoc(opfXmlDoc);
71
- return {
72
- mediaType: (_b = items.find((item) => resourcePath.endsWith(item.href))) === null || _b === void 0 ? void 0 : _b.mediaType
73
- };
74
- }
75
- return {
76
- mediaType: getContentTypeFromExtension(resourcePath)
77
- };
78
- });
79
- const getContentTypeFromExtension = (uri) => {
80
- if (uri.endsWith(`.css`)) {
81
- return `text/css; charset=UTF-8`;
82
- }
83
- if (uri.endsWith(`.jpg`)) {
84
- return `image/jpg`;
85
- }
86
- if (uri.endsWith(`.xhtml`)) {
87
- return `application/xhtml+xml`;
88
- }
89
- if (uri.endsWith(`.mp4`)) {
90
- return `video/mp4`;
91
- }
92
- if (uri.endsWith(`.svg`)) {
93
- return `image/svg+xml`;
94
- }
95
- };
@@ -1,26 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import xmldoc from 'xmldoc';
11
- export const extractKoboInformationFromArchive = (archive) => __awaiter(void 0, void 0, void 0, function* () {
12
- const koboInformation = {
13
- renditionLayout: undefined
14
- };
15
- yield Promise.all(archive.files.map((file) => __awaiter(void 0, void 0, void 0, function* () {
16
- var _a, _b;
17
- if (file.uri.endsWith(`com.kobobooks.display-options.xml`)) {
18
- const opfXmlDoc = new xmldoc.XmlDocument(yield file.string());
19
- const optionElement = (_a = opfXmlDoc.childNamed(`platform`)) === null || _a === void 0 ? void 0 : _a.childNamed(`option`);
20
- if (((_b = optionElement === null || optionElement === void 0 ? void 0 : optionElement.attr) === null || _b === void 0 ? void 0 : _b.name) === `fixed-layout` && optionElement.val === `true`) {
21
- koboInformation.renditionLayout = `pre-paginated`;
22
- }
23
- }
24
- })));
25
- return koboInformation;
26
- });
@@ -1,121 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- import xmldoc from 'xmldoc';
11
- import { getArchiveOpfInfo } from '..';
12
- const extractNavChapter = (li, { opfBasePath, baseUrl }) => {
13
- const chp = {
14
- contents: [],
15
- path: ``,
16
- href: ``,
17
- title: ``
18
- };
19
- let contentNode = li.childNamed(`span`) || li.childNamed(`a`);
20
- chp.title = (contentNode === null || contentNode === void 0 ? void 0 : contentNode.attr.title) || (contentNode === null || contentNode === void 0 ? void 0 : contentNode.val.trim()) || chp.title;
21
- let node = contentNode === null || contentNode === void 0 ? void 0 : contentNode.name;
22
- if (node !== `a`) {
23
- contentNode = li.descendantWithPath(`${node}.a`);
24
- if (contentNode) {
25
- node = contentNode.name.toLowerCase();
26
- }
27
- }
28
- if (node === `a` && (contentNode === null || contentNode === void 0 ? void 0 : contentNode.attr.href)) {
29
- chp.path = opfBasePath ? `${opfBasePath}/${contentNode.attr.href}` : `${contentNode.attr.href}`;
30
- chp.href = opfBasePath ? `${baseUrl}/${opfBasePath}/${contentNode.attr.href}` : `${baseUrl}/${contentNode.attr.href}`;
31
- }
32
- const sublistNode = li.childNamed(`ol`);
33
- if (sublistNode) {
34
- const children = sublistNode.childrenNamed(`li`);
35
- if (children && children.length > 0) {
36
- chp.contents = children.map((child) => extractNavChapter(child, { opfBasePath, baseUrl }));
37
- }
38
- }
39
- return chp;
40
- };
41
- const buildTOCFromNav = (doc, { opfBasePath, baseUrl }) => {
42
- var _a, _b;
43
- const toc = [];
44
- let navDataChildren;
45
- if (doc.descendantWithPath(`body.nav.ol`)) {
46
- navDataChildren = (_a = doc.descendantWithPath(`body.nav.ol`)) === null || _a === void 0 ? void 0 : _a.children;
47
- }
48
- else if (doc.descendantWithPath(`body.section.nav.ol`)) {
49
- navDataChildren = (_b = doc.descendantWithPath(`body.section.nav.ol`)) === null || _b === void 0 ? void 0 : _b.children;
50
- }
51
- if (navDataChildren && navDataChildren.length > 0) {
52
- navDataChildren
53
- .filter((li) => li.name === `li`)
54
- .forEach((li) => toc.push(extractNavChapter(li, { opfBasePath, baseUrl })));
55
- }
56
- return toc;
57
- };
58
- const parseTocFromNavPath = (opfXmlDoc, archive, { opfBasePath, baseUrl }) => __awaiter(void 0, void 0, void 0, function* () {
59
- var _a;
60
- // Try to detect if there is a nav item
61
- const navItem = (_a = opfXmlDoc.childNamed(`manifest`)) === null || _a === void 0 ? void 0 : _a.childrenNamed(`item`).find((child) => child.attr.properties === `nav`);
62
- if (navItem) {
63
- const tocFile = Object.values(archive.files).find(item => item.uri.endsWith(navItem.attr.href || ``));
64
- if (tocFile) {
65
- const doc = new xmldoc.XmlDocument(yield tocFile.string());
66
- return buildTOCFromNav(doc, { opfBasePath, baseUrl });
67
- }
68
- }
69
- });
70
- const mapNcxChapter = (point, { opfBasePath, baseUrl, prefix }) => {
71
- var _a, _b;
72
- const src = ((_a = point === null || point === void 0 ? void 0 : point.childNamed(`${prefix}content`)) === null || _a === void 0 ? void 0 : _a.attr.src) || ``;
73
- const out = {
74
- title: ((_b = point === null || point === void 0 ? void 0 : point.descendantWithPath(`${prefix}navLabel.${prefix}text`)) === null || _b === void 0 ? void 0 : _b.val) || ``,
75
- path: opfBasePath ? `${opfBasePath}/${src}` : `${src}`,
76
- href: opfBasePath ? `${baseUrl}/${opfBasePath}/${src}` : `${baseUrl}/${src}`,
77
- contents: []
78
- };
79
- const children = point.childrenNamed(`${prefix}navPoint`);
80
- if (children && children.length > 0) {
81
- out.contents = children.map((pt) => mapNcxChapter(pt, { opfBasePath, baseUrl, prefix }));
82
- }
83
- return out;
84
- };
85
- const buildTOCFromNCX = (ncxData, { opfBasePath, baseUrl }) => {
86
- var _a;
87
- const toc = [];
88
- const rootTagName = ncxData.name;
89
- let prefix = ``;
90
- if (rootTagName.indexOf(`:`) !== -1) {
91
- prefix = rootTagName.split(`:`)[0] + `:`;
92
- }
93
- (_a = ncxData
94
- .childNamed(`${prefix}navMap`)) === null || _a === void 0 ? void 0 : _a.childrenNamed(`${prefix}navPoint`).forEach((point) => toc.push(mapNcxChapter(point, { opfBasePath, baseUrl, prefix })));
95
- return toc;
96
- };
97
- const parseTocFromNcx = ({ opfData, opfBasePath, baseUrl, archive }) => __awaiter(void 0, void 0, void 0, function* () {
98
- var _b;
99
- const spine = opfData.childNamed(`spine`);
100
- const ncxId = spine && spine.attr.toc;
101
- if (ncxId) {
102
- const ncxItem = (_b = opfData
103
- .childNamed(`manifest`)) === null || _b === void 0 ? void 0 : _b.childrenNamed(`item`).find((item) => item.attr.id === ncxId);
104
- if (ncxItem) {
105
- const ncxPath = `${opfBasePath}${opfBasePath === `` ? `` : `/`}${ncxItem.attr.href}`;
106
- const file = Object.values(archive.files).find(item => item.uri.endsWith(ncxPath));
107
- if (file) {
108
- const ncxData = new xmldoc.XmlDocument(yield file.string());
109
- return buildTOCFromNCX(ncxData, { opfBasePath, baseUrl });
110
- }
111
- }
112
- }
113
- });
114
- export const parseToc = (opfXmlDoc, archive, { baseUrl }) => __awaiter(void 0, void 0, void 0, function* () {
115
- const { basePath: opfBasePath } = getArchiveOpfInfo(archive) || {};
116
- const tocFromNcx = yield parseTocFromNcx({ opfData: opfXmlDoc, opfBasePath, archive, baseUrl });
117
- if (tocFromNcx) {
118
- return tocFromNcx;
119
- }
120
- return yield parseTocFromNavPath(opfXmlDoc, archive, { opfBasePath, baseUrl });
121
- });
package/dist/report.js DELETED
@@ -1,68 +0,0 @@
1
- let enabled = false;
2
- export const Report = {
3
- enable: (enable) => {
4
- enabled = enable;
5
- },
6
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
- log: (...data) => {
8
- if (enabled) {
9
- // eslint-disable-next-line no-console
10
- console.log(`[prose-reader-streamer]`, ...data);
11
- }
12
- },
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
- warn: (...data) => {
15
- if (enabled) {
16
- // eslint-disable-next-line no-console
17
- console.warn(`[prose-reader-streamer]`, ...data);
18
- }
19
- },
20
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
- error: (...data) => {
22
- // eslint-disable-next-line no-console
23
- console.error(...data);
24
- },
25
- time: (label) => {
26
- if (enabled) {
27
- // eslint-disable-next-line no-console
28
- console.time(`[prose-reader-streamer] [metric] ${label}`);
29
- }
30
- },
31
- timeEnd: (label) => {
32
- if (enabled) {
33
- // eslint-disable-next-line no-console
34
- console.timeEnd(`[prose-reader-streamer] [metric] ${label}`);
35
- }
36
- },
37
- metric: (performanceEntry, targetDuration = Infinity) => {
38
- const duration = typeof performanceEntry === `number` ? performanceEntry : performanceEntry.duration;
39
- if (enabled) {
40
- if (performanceEntry.duration <= targetDuration) {
41
- // eslint-disable-next-line no-console
42
- console.log(`[prose-reader-streamer] [metric] `, `${performanceEntry.name} took ${duration}ms`);
43
- }
44
- else {
45
- // eslint-disable-next-line no-console
46
- console.warn(`[prose-reader-streamer] [metric] `, `${performanceEntry.name} took ${performanceEntry.duration}ms which is above the ${targetDuration}ms target for this function`);
47
- }
48
- }
49
- },
50
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
- measurePerformance: (name, targetDuration = 10, functionToMeasure) => {
52
- return (...args) => {
53
- const t0 = performance.now();
54
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
55
- const response = functionToMeasure(...args);
56
- if (response && response.then) {
57
- return response.then((res) => {
58
- const t1 = performance.now();
59
- Report.metric({ name, duration: t1 - t0 }, targetDuration);
60
- return res;
61
- });
62
- }
63
- const t1 = performance.now();
64
- Report.metric({ name, duration: t1 - t0 }, targetDuration);
65
- return response;
66
- };
67
- }
68
- };
@@ -1,19 +0,0 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- export const blobToBase64 = (blob) => __awaiter(void 0, void 0, void 0, function* () {
11
- return new Promise(resolve => {
12
- const reader = new FileReader();
13
- reader.readAsDataURL(blob);
14
- reader.onloadend = function () {
15
- const base64data = reader.result;
16
- resolve(base64data);
17
- };
18
- });
19
- });
@@ -1,18 +0,0 @@
1
- export const sortByTitleComparator = (a, b) => {
2
- var _a;
3
- const alist = a.split(/(\d+)/);
4
- const blist = b.split(/(\d+)/);
5
- alist.slice(-1) === [``] && alist.pop();
6
- blist.slice(-1) === [``] && blist.pop();
7
- for (let i = 0, len = alist.length; i < len; i++) {
8
- if (alist[i] !== blist[i]) {
9
- if ((_a = alist[i]) === null || _a === void 0 ? void 0 : _a.match(/\d/)) {
10
- return +(alist[i] || ``) - +(blist[i] || ``);
11
- }
12
- else {
13
- return (alist[i] || ``).localeCompare((blist[i] || ``));
14
- }
15
- }
16
- }
17
- return 1;
18
- };
package/dist/utils/uri.js DELETED
@@ -1 +0,0 @@
1
- export const getUriBasename = (uri) => uri.substring(uri.lastIndexOf(`/`) + 1) || uri;