@openread/mcp 0.0.1-test.1 → 0.0.1-test.3
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.
- package/dist/cli.mjs +5 -3
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import{createRequire as __createRequire}from"module";const require=__createRequire(import.meta.url);
|
|
2
3
|
if(typeof globalThis.DOMMatrix==="undefined"){globalThis.DOMMatrix=class DOMMatrix{constructor(init){const v=init||[];this.a=v[0]??1;this.b=v[1]??0;this.c=v[2]??0;this.d=v[3]??1;this.e=v[4]??0;this.f=v[5]??0;this.m11=this.a;this.m12=this.b;this.m21=this.c;this.m22=this.d;this.m41=this.e;this.m42=this.f;this.is2D=true;this.isIdentity=this.a===1&&this.b===0&&this.c===0&&this.d===1&&this.e===0&&this.f===0;}static fromMatrix(o){return new DOMMatrix([o.a,o.b,o.c,o.d,o.e,o.f]);}static fromFloat64Array(a){return new DOMMatrix(Array.from(a));}static fromFloat32Array(a){return new DOMMatrix(Array.from(a));}inverse(){return new DOMMatrix();}multiply(){return new DOMMatrix();}scale(){return new DOMMatrix();}translate(){return new DOMMatrix();}transformPoint(p){return p||{x:0,y:0};}}}
|
|
3
4
|
if(typeof globalThis.Path2D==="undefined"){globalThis.Path2D=class Path2D{constructor(){}addPath(){}closePath(){}moveTo(){}lineTo(){}bezierCurveTo(){}quadraticCurveTo(){}arc(){}arcTo(){}rect(){}}}
|
|
4
5
|
if(typeof globalThis.ImageData==="undefined"){globalThis.ImageData=class ImageData{constructor(w,h){this.width=w;this.height=h;this.data=new Uint8ClampedArray(w*h*4);}}}
|
|
6
|
+
try{const __M=require("module"),__orig=__M._resolveFilename;__M._resolveFilename=function(r,...a){if(r==="@napi-rs/canvas")return r;return __orig.call(this,r,...a)};require.cache["@napi-rs/canvas"]={id:"@napi-rs/canvas",filename:"@napi-rs/canvas",loaded:true,exports:{createCanvas:()=>({})}}}catch(e){}
|
|
5
7
|
var Z_=Object.create;var Qm=Object.defineProperty;var J_=Object.getOwnPropertyDescriptor;var eC=Object.getOwnPropertyNames;var tC=Object.getPrototypeOf,rC=Object.prototype.hasOwnProperty;var Ue=(r=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(r,{get:(e,t)=>(typeof require<"u"?require:e)[t]}):r)(function(r){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+r+'" is not supported')});var j=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports);var nC=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of eC(e))!rC.call(r,i)&&i!==t&&Qm(r,i,{get:()=>e[i],enumerable:!(n=J_(e,i))||n.enumerable});return r};var Sh=(r,e,t)=>(t=r!=null?Z_(tC(r)):{},nC(e||!r||!r.__esModule?Qm(t,"default",{value:r,enumerable:!0}):t,r));var kh=j((BF,ob)=>{"use strict";var Ps=r=>r&&typeof r.message=="string",Ch=r=>{if(!r)return;let e=r.cause;if(typeof e=="function"){let t=r.cause();return Ps(t)?t:void 0}else return Ps(e)?e:void 0},sb=(r,e)=>{if(!Ps(r))return"";let t=r.stack||"";if(e.has(r))return t+`
|
|
6
8
|
causes have become circular...`;let n=Ch(r);return n?(e.add(r),t+`
|
|
7
9
|
caused by: `+sb(n,e)):t},dC=r=>sb(r,new Set),ab=(r,e,t)=>{if(!Ps(r))return"";let n=t?"":r.message||"";if(e.has(r))return n+": ...";let i=Ch(r);if(i){e.add(r);let s=typeof r.cause=="function";return n+(s?"":": ")+ab(i,e,s)}else return n},fC=r=>ab(r,new Set);ob.exports={isErrorLike:Ps,getErrorCause:Ch,stackWithCauses:dC,messageWithCauses:fC}});var Ih=j((DF,lb)=>{"use strict";var pC=Symbol("circular-ref-tag"),Vo=Symbol("pino-raw-err-ref"),ub=Object.create({},{type:{enumerable:!0,writable:!0,value:void 0},message:{enumerable:!0,writable:!0,value:void 0},stack:{enumerable:!0,writable:!0,value:void 0},aggregateErrors:{enumerable:!0,writable:!0,value:void 0},raw:{enumerable:!1,get:function(){return this[Vo]},set:function(r){this[Vo]=r}}});Object.defineProperty(ub,Vo,{writable:!0,value:{}});lb.exports={pinoErrProto:ub,pinoErrorSymbols:{seen:pC,rawSymbol:Vo}}});var db=j((FF,hb)=>{"use strict";hb.exports=Ph;var{messageWithCauses:gC,stackWithCauses:mC,isErrorLike:cb}=kh(),{pinoErrProto:bC,pinoErrorSymbols:yC}=Ih(),{seen:Rh}=yC,{toString:vC}=Object.prototype;function Ph(r){if(!cb(r))return r;r[Rh]=void 0;let e=Object.create(bC);e.type=vC.call(r.constructor)==="[object Function]"?r.constructor.name:r.name,e.message=gC(r),e.stack=mC(r),Array.isArray(r.errors)&&(e.aggregateErrors=r.errors.map(t=>Ph(t)));for(let t in r)if(e[t]===void 0){let n=r[t];cb(n)?t!=="cause"&&!Object.prototype.hasOwnProperty.call(n,Rh)&&(e[t]=Ph(n)):e[t]=n}return delete r[Rh],e.raw=r,e}});var pb=j(($F,fb)=>{"use strict";fb.exports=qo;var{isErrorLike:Oh}=kh(),{pinoErrProto:wC,pinoErrorSymbols:xC}=Ih(),{seen:Go}=xC,{toString:SC}=Object.prototype;function qo(r){if(!Oh(r))return r;r[Go]=void 0;let e=Object.create(wC);e.type=SC.call(r.constructor)==="[object Function]"?r.constructor.name:r.name,e.message=r.message,e.stack=r.stack,Array.isArray(r.errors)&&(e.aggregateErrors=r.errors.map(t=>qo(t))),Oh(r.cause)&&!Object.prototype.hasOwnProperty.call(r.cause,Go)&&(e.cause=qo(r.cause));for(let t in r)if(e[t]===void 0){let n=r[t];Oh(n)?Object.prototype.hasOwnProperty.call(n,Go)||(e[t]=qo(n)):e[t]=n}return delete r[Go],e.raw=r,e}});var yb=j((UF,bb)=>{"use strict";bb.exports={mapHttpRequest:EC,reqSerializer:mb};var Lh=Symbol("pino-raw-req-ref"),gb=Object.create({},{id:{enumerable:!0,writable:!0,value:""},method:{enumerable:!0,writable:!0,value:""},url:{enumerable:!0,writable:!0,value:""},query:{enumerable:!0,writable:!0,value:""},params:{enumerable:!0,writable:!0,value:""},headers:{enumerable:!0,writable:!0,value:{}},remoteAddress:{enumerable:!0,writable:!0,value:""},remotePort:{enumerable:!0,writable:!0,value:""},raw:{enumerable:!1,get:function(){return this[Lh]},set:function(r){this[Lh]=r}}});Object.defineProperty(gb,Lh,{writable:!0,value:{}});function mb(r){let e=r.info||r.socket,t=Object.create(gb);if(t.id=typeof r.id=="function"?r.id():r.id||(r.info?r.info.id:void 0),t.method=r.method,r.originalUrl)t.url=r.originalUrl;else{let n=r.path;t.url=typeof n=="string"?n:r.url?r.url.path||r.url:void 0}return r.query&&(t.query=r.query),r.params&&(t.params=r.params),t.headers=r.headers,t.remoteAddress=e&&e.remoteAddress,t.remotePort=e&&e.remotePort,t.raw=r.raw||r,t}function EC(r){return{req:mb(r)}}});var Sb=j((zF,xb)=>{"use strict";xb.exports={mapHttpResponse:AC,resSerializer:wb};var Nh=Symbol("pino-raw-res-ref"),vb=Object.create({},{statusCode:{enumerable:!0,writable:!0,value:0},headers:{enumerable:!0,writable:!0,value:""},raw:{enumerable:!1,get:function(){return this[Nh]},set:function(r){this[Nh]=r}}});Object.defineProperty(vb,Nh,{writable:!0,value:{}});function wb(r){let e=Object.create(vb);return e.statusCode=r.headersSent?r.statusCode:null,e.headers=r.getHeaders?r.getHeaders():r._headers,e.raw=r,e}function AC(r){return{res:wb(r)}}});var Bh=j((jF,Eb)=>{"use strict";var Mh=db(),TC=pb(),Ko=yb(),Xo=Sb();Eb.exports={err:Mh,errWithCause:TC,mapHttpRequest:Ko.mapHttpRequest,mapHttpResponse:Xo.mapHttpResponse,req:Ko.reqSerializer,res:Xo.resSerializer,wrapErrorSerializer:function(e){return e===Mh?e:function(n){return e(Mh(n))}},wrapRequestSerializer:function(e){return e===Ko.reqSerializer?e:function(n){return e(Ko.reqSerializer(n))}},wrapResponseSerializer:function(e){return e===Xo.resSerializer?e:function(n){return e(Xo.resSerializer(n))}}}});var Dh=j((HF,Ab)=>{"use strict";function _C(r,e){return e}Ab.exports=function(){let e=Error.prepareStackTrace;Error.prepareStackTrace=_C;let t=new Error().stack;if(Error.prepareStackTrace=e,!Array.isArray(t))return;let n=t.slice(2),i=[];for(let s of n)s&&i.push(s.getFileName());return i}});var _b=j((WF,Tb)=>{"use strict";Tb.exports=CC;function CC(r={}){let{ERR_PATHS_MUST_BE_STRINGS:e=()=>"fast-redact - Paths must be (non-empty) strings",ERR_INVALID_PATH:t=n=>`fast-redact \u2013 Invalid path (${n})`}=r;return function({paths:i}){i.forEach(s=>{if(typeof s!="string")throw Error(e());try{if(/〇/.test(s))throw Error();let a=(s[0]==="["?"":".")+s.replace(/^\*/,"\u3007").replace(/\.\*/g,".\u3007").replace(/\[\*\]/g,"[\u3007]");if(/\n|\r|;/.test(a)||/\/\*/.test(a))throw Error();Function(`
|
|
@@ -107,7 +109,7 @@ ${y}`),g.pop(),`{${S}}`}case"number":return isFinite(p)?String(p):e?e(p):"null";
|
|
|
107
109
|
\0`,A+=Be(_,2),A+=o.magic,A+=Be(b,2),A+=Be(m,2),A+=Be(E.crc32,4),A+=Be(E.compressedSize,4),A+=Be(E.uncompressedSize,4),A+=Be(l.length,2),A+=Be(y.length,2);var B=Ku.LOCAL_FILE_HEADER+A+l+y,D=Ku.CENTRAL_FILE_HEADER+Be(k,2)+A+Be(d.length,2)+"\0\0\0\0"+Be(T,4)+Be(n,4)+l+y+d;return{fileRecord:B,dirRecord:D}},iL=function(r,e,t,n,i){var s="",a=ji.transformTo("string",i(n));return s=Ku.CENTRAL_DIRECTORY_END+"\0\0\0\0"+Be(r,2)+Be(r,2)+Be(e,4)+Be(t,4)+Be(a.length,2)+a,s},sL=function(r){var e="";return e=Ku.DATA_DESCRIPTOR+Be(r.crc32,4)+Be(r.compressedSize,4)+Be(r.uncompressedSize,4),e};function br(r,e,t,n){Hi.call(this,"ZipFileWorker"),this.bytesWritten=0,this.zipComment=e,this.zipPlatform=t,this.encodeFileName=n,this.streamFiles=r,this.accumulate=!1,this.contentBuffer=[],this.dirRecords=[],this.currentSourceOffset=0,this.entriesCount=0,this.currentFile=null,this._sources=[]}ji.inherits(br,Hi);br.prototype.push=function(r){var e=r.meta.percent||0,t=this.entriesCount,n=this._sources.length;this.accumulate?this.contentBuffer.push(r):(this.bytesWritten+=r.data.length,Hi.prototype.push.call(this,{data:r.data,meta:{currentFile:this.currentFile,percent:t?(e+100*(t-n-1))/t:100}}))};br.prototype.openedSource=function(r){this.currentSourceOffset=this.bytesWritten,this.currentFile=r.file.name;var e=this.streamFiles&&!r.file.dir;if(e){var t=Ux(r,e,!1,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);this.push({data:t.fileRecord,meta:{percent:0}})}else this.accumulate=!0};br.prototype.closedSource=function(r){this.accumulate=!1;var e=this.streamFiles&&!r.file.dir,t=Ux(r,e,!0,this.currentSourceOffset,this.zipPlatform,this.encodeFileName);if(this.dirRecords.push(t.dirRecord),e)this.push({data:sL(r),meta:{percent:100}});else for(this.push({data:t.fileRecord,meta:{percent:0}});this.contentBuffer.length;)this.push(this.contentBuffer.shift());this.currentFile=null};br.prototype.flush=function(){for(var r=this.bytesWritten,e=0;e<this.dirRecords.length;e++)this.push({data:this.dirRecords[e],meta:{percent:100}});var t=this.bytesWritten-r,n=iL(this.dirRecords.length,t,r,this.zipComment,this.encodeFileName);this.push({data:n,meta:{percent:100}})};br.prototype.prepareNextSource=function(){this.previous=this._sources.shift(),this.openedSource(this.previous.streamInfo),this.isPaused?this.previous.pause():this.previous.resume()};br.prototype.registerPrevious=function(r){this._sources.push(r);var e=this;return r.on("data",function(t){e.processChunk(t)}),r.on("end",function(){e.closedSource(e.previous.streamInfo),e._sources.length?e.prepareNextSource():e.end()}),r.on("error",function(t){e.error(t)}),this};br.prototype.resume=function(){if(!Hi.prototype.resume.call(this))return!1;if(!this.previous&&this._sources.length)return this.prepareNextSource(),!0;if(!this.previous&&!this._sources.length&&!this.generatedError)return this.end(),!0};br.prototype.error=function(r){var e=this._sources;if(!Hi.prototype.error.call(this,r))return!1;for(var t=0;t<e.length;t++)try{e[t].error(r)}catch{}return!0};br.prototype.lock=function(){Hi.prototype.lock.call(this);for(var r=this._sources,e=0;e<r.length;e++)r[e].lock()};zx.exports=br});var Wx=j(Hx=>{"use strict";var aL=tp(),oL=jx(),uL=function(r,e){var t=r||e,n=aL[t];if(!n)throw new Error(t+" is not a valid compression method !");return n};Hx.generateWorker=function(r,e,t){var n=new oL(e.streamFiles,t,e.platform,e.encodeFileName),i=0;try{r.forEach(function(s,a){i++;var o=uL(a.options.compression,e.compression),u=a.options.compressionOptions||e.compressionOptions||{},l=a.dir,c=a.date;a._compressWorker(o,u).withStreamInfo("file",{name:s,dir:l,date:c,comment:a.comment||"",unixPermissions:a.unixPermissions,dosPermissions:a.dosPermissions}).pipe(n)}),n.entriesCount=i}catch(s){n.error(s)}return n}});var Gx=j((R7,Vx)=>{"use strict";var lL=je(),Xu=Ht();function pa(r,e){Xu.call(this,"Nodejs stream input adapter for "+r),this._upstreamEnded=!1,this._bindStream(e)}lL.inherits(pa,Xu);pa.prototype._bindStream=function(r){var e=this;this._stream=r,r.pause(),r.on("data",function(t){e.push({data:t,meta:{percent:0}})}).on("error",function(t){e.isPaused?this.generatedError=t:e.error(t)}).on("end",function(){e.isPaused?e._upstreamEnded=!0:e.end()})};pa.prototype.pause=function(){return Xu.prototype.pause.call(this)?(this._stream.pause(),!0):!1};pa.prototype.resume=function(){return Xu.prototype.resume.call(this)?(this._upstreamEnded?this.end():this._stream.resume(),!0):!1};Vx.exports=pa});var r2=j((P7,t2)=>{"use strict";var cL=Ri(),ga=je(),Yx=Ht(),hL=uf(),Qx=lf(),qx=ku(),dL=Kv(),fL=Wx(),Kx=Ws(),pL=Gx(),Zx=function(r,e,t){var n=ga.getTypeOf(e),i,s=ga.extend(t||{},Qx);s.date=s.date||new Date,s.compression!==null&&(s.compression=s.compression.toUpperCase()),typeof s.unixPermissions=="string"&&(s.unixPermissions=parseInt(s.unixPermissions,8)),s.unixPermissions&&s.unixPermissions&16384&&(s.dir=!0),s.dosPermissions&&s.dosPermissions&16&&(s.dir=!0),s.dir&&(r=Jx(r)),s.createFolders&&(i=gL(r))&&e2.call(this,i,!0);var a=n==="string"&&s.binary===!1&&s.base64===!1;(!t||typeof t.binary>"u")&&(s.binary=!a);var o=e instanceof qx&&e.uncompressedSize===0;(o||s.dir||!e||e.length===0)&&(s.base64=!1,s.binary=!0,e="",s.compression="STORE",n="string");var u=null;e instanceof qx||e instanceof Yx?u=e:Kx.isNode&&Kx.isStream(e)?u=new pL(r,e):u=ga.prepareContent(r,e,s.binary,s.optimizedBinaryString,s.base64);var l=new dL(r,u,s);this.files[r]=l},gL=function(r){r.slice(-1)==="/"&&(r=r.substring(0,r.length-1));var e=r.lastIndexOf("/");return e>0?r.substring(0,e):""},Jx=function(r){return r.slice(-1)!=="/"&&(r+="/"),r},e2=function(r,e){return e=typeof e<"u"?e:Qx.createFolders,r=Jx(r),this.files[r]||Zx.call(this,r,null,{dir:!0,createFolders:e}),this.files[r]};function Xx(r){return Object.prototype.toString.call(r)==="[object RegExp]"}var mL={load:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},forEach:function(r){var e,t,n;for(e in this.files)n=this.files[e],t=e.slice(this.root.length,e.length),t&&e.slice(0,this.root.length)===this.root&&r(t,n)},filter:function(r){var e=[];return this.forEach(function(t,n){r(t,n)&&e.push(n)}),e},file:function(r,e,t){if(arguments.length===1)if(Xx(r)){var n=r;return this.filter(function(s,a){return!a.dir&&n.test(s)})}else{var i=this.files[this.root+r];return i&&!i.dir?i:null}else r=this.root+r,Zx.call(this,r,e,t);return this},folder:function(r){if(!r)return this;if(Xx(r))return this.filter(function(i,s){return s.dir&&r.test(i)});var e=this.root+r,t=e2.call(this,e),n=this.clone();return n.root=t.name,n},remove:function(r){r=this.root+r;var e=this.files[r];if(e||(r.slice(-1)!=="/"&&(r+="/"),e=this.files[r]),e&&!e.dir)delete this.files[r];else for(var t=this.filter(function(i,s){return s.name.slice(0,r.length)===r}),n=0;n<t.length;n++)delete this.files[t[n].name];return this},generate:function(){throw new Error("This method has been removed in JSZip 3.0, please check the upgrade guide.")},generateInternalStream:function(r){var e,t={};try{if(t=ga.extend(r||{},{streamFiles:!1,compression:"STORE",compressionOptions:null,type:"",platform:"DOS",comment:null,mimeType:"application/zip",encodeFileName:cL.utf8encode}),t.type=t.type.toLowerCase(),t.compression=t.compression.toUpperCase(),t.type==="binarystring"&&(t.type="string"),!t.type)throw new Error("No output type specified.");ga.checkSupport(t.type),(t.platform==="darwin"||t.platform==="freebsd"||t.platform==="linux"||t.platform==="sunos")&&(t.platform="UNIX"),t.platform==="win32"&&(t.platform="DOS");var n=t.comment||this.comment||"";e=fL.generateWorker(this,t,n)}catch(i){e=new Yx("error"),e.error(i)}return new hL(e,t.type||"string",t.mimeType)},generateAsync:function(r,e){return this.generateInternalStream(r).accumulate(e)},generateNodeStream:function(r,e){return r=r||{},r.type||(r.type="nodebuffer"),this.generateInternalStream(r).toNodejsStream(e)}};t2.exports=mL});var ip=j((O7,i2)=>{"use strict";var bL=je();function n2(r){this.data=r,this.length=r.length,this.index=0,this.zero=0}n2.prototype={checkOffset:function(r){this.checkIndex(this.index+r)},checkIndex:function(r){if(this.length<this.zero+r||r<0)throw new Error("End of data reached (data length = "+this.length+", asked index = "+r+"). Corrupted zip ?")},setIndex:function(r){this.checkIndex(r),this.index=r},skip:function(r){this.setIndex(this.index+r)},byteAt:function(){},readInt:function(r){var e=0,t;for(this.checkOffset(r),t=this.index+r-1;t>=this.index;t--)e=(e<<8)+this.byteAt(t);return this.index+=r,e},readString:function(r){return bL.transformTo("string",this.readData(r))},readData:function(){},lastIndexOfSignature:function(){},readAndCheckSignature:function(){},readDate:function(){var r=this.readInt(4);return new Date(Date.UTC((r>>25&127)+1980,(r>>21&15)-1,r>>16&31,r>>11&31,r>>5&63,(r&31)<<1))}};i2.exports=n2});var sp=j((L7,a2)=>{"use strict";var s2=ip(),yL=je();function Wi(r){s2.call(this,r);for(var e=0;e<this.data.length;e++)r[e]=r[e]&255}yL.inherits(Wi,s2);Wi.prototype.byteAt=function(r){return this.data[this.zero+r]};Wi.prototype.lastIndexOfSignature=function(r){for(var e=r.charCodeAt(0),t=r.charCodeAt(1),n=r.charCodeAt(2),i=r.charCodeAt(3),s=this.length-4;s>=0;--s)if(this.data[s]===e&&this.data[s+1]===t&&this.data[s+2]===n&&this.data[s+3]===i)return s-this.zero;return-1};Wi.prototype.readAndCheckSignature=function(r){var e=r.charCodeAt(0),t=r.charCodeAt(1),n=r.charCodeAt(2),i=r.charCodeAt(3),s=this.readData(4);return e===s[0]&&t===s[1]&&n===s[2]&&i===s[3]};Wi.prototype.readData=function(r){if(this.checkOffset(r),r===0)return[];var e=this.data.slice(this.zero+this.index,this.zero+this.index+r);return this.index+=r,e};a2.exports=Wi});var l2=j((N7,u2)=>{"use strict";var o2=ip(),vL=je();function Vi(r){o2.call(this,r)}vL.inherits(Vi,o2);Vi.prototype.byteAt=function(r){return this.data.charCodeAt(this.zero+r)};Vi.prototype.lastIndexOfSignature=function(r){return this.data.lastIndexOf(r)-this.zero};Vi.prototype.readAndCheckSignature=function(r){var e=this.readData(4);return r===e};Vi.prototype.readData=function(r){this.checkOffset(r);var e=this.data.slice(this.zero+this.index,this.zero+this.index+r);return this.index+=r,e};u2.exports=Vi});var op=j((M7,h2)=>{"use strict";var c2=sp(),wL=je();function ap(r){c2.call(this,r)}wL.inherits(ap,c2);ap.prototype.readData=function(r){if(this.checkOffset(r),r===0)return new Uint8Array(0);var e=this.data.subarray(this.zero+this.index,this.zero+this.index+r);return this.index+=r,e};h2.exports=ap});var p2=j((B7,f2)=>{"use strict";var d2=op(),xL=je();function up(r){d2.call(this,r)}xL.inherits(up,d2);up.prototype.readData=function(r){this.checkOffset(r);var e=this.data.slice(this.zero+this.index,this.zero+this.index+r);return this.index+=r,e};f2.exports=up});var lp=j((D7,m2)=>{"use strict";var Yu=je(),g2=Wr(),SL=sp(),EL=l2(),AL=p2(),TL=op();m2.exports=function(r){var e=Yu.getTypeOf(r);return Yu.checkSupport(e),e==="string"&&!g2.uint8array?new EL(r):e==="nodebuffer"?new AL(r):g2.uint8array?new TL(Yu.transformTo("uint8array",r)):new SL(Yu.transformTo("array",r))}});var w2=j((F7,v2)=>{"use strict";var cp=lp(),wn=je(),_L=ku(),b2=Cu(),Qu=Ri(),Zu=tp(),CL=Wr(),kL=0,IL=3,RL=function(r){for(var e in Zu)if(Object.prototype.hasOwnProperty.call(Zu,e)&&Zu[e].magic===r)return Zu[e];return null};function y2(r,e){this.options=r,this.loadOptions=e}y2.prototype={isEncrypted:function(){return(this.bitFlag&1)===1},useUTF8:function(){return(this.bitFlag&2048)===2048},readLocalPart:function(r){var e,t;if(r.skip(22),this.fileNameLength=r.readInt(2),t=r.readInt(2),this.fileName=r.readData(this.fileNameLength),r.skip(t),this.compressedSize===-1||this.uncompressedSize===-1)throw new Error("Bug or corrupted zip : didn't get enough information from the central directory (compressedSize === -1 || uncompressedSize === -1)");if(e=RL(this.compressionMethod),e===null)throw new Error("Corrupted zip : compression "+wn.pretty(this.compressionMethod)+" unknown (inner file : "+wn.transformTo("string",this.fileName)+")");this.decompressed=new _L(this.compressedSize,this.uncompressedSize,this.crc32,e,r.readData(this.compressedSize))},readCentralPart:function(r){this.versionMadeBy=r.readInt(2),r.skip(2),this.bitFlag=r.readInt(2),this.compressionMethod=r.readString(2),this.date=r.readDate(),this.crc32=r.readInt(4),this.compressedSize=r.readInt(4),this.uncompressedSize=r.readInt(4);var e=r.readInt(2);if(this.extraFieldsLength=r.readInt(2),this.fileCommentLength=r.readInt(2),this.diskNumberStart=r.readInt(2),this.internalFileAttributes=r.readInt(2),this.externalFileAttributes=r.readInt(4),this.localHeaderOffset=r.readInt(4),this.isEncrypted())throw new Error("Encrypted zip are not supported");r.skip(e),this.readExtraFields(r),this.parseZIP64ExtraField(r),this.fileComment=r.readData(this.fileCommentLength)},processAttributes:function(){this.unixPermissions=null,this.dosPermissions=null;var r=this.versionMadeBy>>8;this.dir=!!(this.externalFileAttributes&16),r===kL&&(this.dosPermissions=this.externalFileAttributes&63),r===IL&&(this.unixPermissions=this.externalFileAttributes>>16&65535),!this.dir&&this.fileNameStr.slice(-1)==="/"&&(this.dir=!0)},parseZIP64ExtraField:function(){if(this.extraFields[1]){var r=cp(this.extraFields[1].value);this.uncompressedSize===wn.MAX_VALUE_32BITS&&(this.uncompressedSize=r.readInt(8)),this.compressedSize===wn.MAX_VALUE_32BITS&&(this.compressedSize=r.readInt(8)),this.localHeaderOffset===wn.MAX_VALUE_32BITS&&(this.localHeaderOffset=r.readInt(8)),this.diskNumberStart===wn.MAX_VALUE_32BITS&&(this.diskNumberStart=r.readInt(4))}},readExtraFields:function(r){var e=r.index+this.extraFieldsLength,t,n,i;for(this.extraFields||(this.extraFields={});r.index+4<e;)t=r.readInt(2),n=r.readInt(2),i=r.readData(n),this.extraFields[t]={id:t,length:n,value:i};r.setIndex(e)},handleUTF8:function(){var r=CL.uint8array?"uint8array":"array";if(this.useUTF8())this.fileNameStr=Qu.utf8decode(this.fileName),this.fileCommentStr=Qu.utf8decode(this.fileComment);else{var e=this.findExtraFieldUnicodePath();if(e!==null)this.fileNameStr=e;else{var t=wn.transformTo(r,this.fileName);this.fileNameStr=this.loadOptions.decodeFileName(t)}var n=this.findExtraFieldUnicodeComment();if(n!==null)this.fileCommentStr=n;else{var i=wn.transformTo(r,this.fileComment);this.fileCommentStr=this.loadOptions.decodeFileName(i)}}},findExtraFieldUnicodePath:function(){var r=this.extraFields[28789];if(r){var e=cp(r.value);return e.readInt(1)!==1||b2(this.fileName)!==e.readInt(4)?null:Qu.utf8decode(e.readData(r.length-5))}return null},findExtraFieldUnicodeComment:function(){var r=this.extraFields[25461];if(r){var e=cp(r.value);return e.readInt(1)!==1||b2(this.fileComment)!==e.readInt(4)?null:Qu.utf8decode(e.readData(r.length-5))}return null}};v2.exports=y2});var E2=j(($7,S2)=>{"use strict";var PL=lp(),Yr=je(),yr=rp(),OL=w2(),LL=Wr();function x2(r){this.files=[],this.loadOptions=r}x2.prototype={checkSignature:function(r){if(!this.reader.readAndCheckSignature(r)){this.reader.index-=4;var e=this.reader.readString(4);throw new Error("Corrupted zip or bug: unexpected signature ("+Yr.pretty(e)+", expected "+Yr.pretty(r)+")")}},isSignature:function(r,e){var t=this.reader.index;this.reader.setIndex(r);var n=this.reader.readString(4),i=n===e;return this.reader.setIndex(t),i},readBlockEndOfCentral:function(){this.diskNumber=this.reader.readInt(2),this.diskWithCentralDirStart=this.reader.readInt(2),this.centralDirRecordsOnThisDisk=this.reader.readInt(2),this.centralDirRecords=this.reader.readInt(2),this.centralDirSize=this.reader.readInt(4),this.centralDirOffset=this.reader.readInt(4),this.zipCommentLength=this.reader.readInt(2);var r=this.reader.readData(this.zipCommentLength),e=LL.uint8array?"uint8array":"array",t=Yr.transformTo(e,r);this.zipComment=this.loadOptions.decodeFileName(t)},readBlockZip64EndOfCentral:function(){this.zip64EndOfCentralSize=this.reader.readInt(8),this.reader.skip(4),this.diskNumber=this.reader.readInt(4),this.diskWithCentralDirStart=this.reader.readInt(4),this.centralDirRecordsOnThisDisk=this.reader.readInt(8),this.centralDirRecords=this.reader.readInt(8),this.centralDirSize=this.reader.readInt(8),this.centralDirOffset=this.reader.readInt(8),this.zip64ExtensibleData={};for(var r=this.zip64EndOfCentralSize-44,e=0,t,n,i;e<r;)t=this.reader.readInt(2),n=this.reader.readInt(4),i=this.reader.readData(n),this.zip64ExtensibleData[t]={id:t,length:n,value:i}},readBlockZip64EndOfCentralLocator:function(){if(this.diskWithZip64CentralDirStart=this.reader.readInt(4),this.relativeOffsetEndOfZip64CentralDir=this.reader.readInt(8),this.disksCount=this.reader.readInt(4),this.disksCount>1)throw new Error("Multi-volumes zip are not supported")},readLocalFiles:function(){var r,e;for(r=0;r<this.files.length;r++)e=this.files[r],this.reader.setIndex(e.localHeaderOffset),this.checkSignature(yr.LOCAL_FILE_HEADER),e.readLocalPart(this.reader),e.handleUTF8(),e.processAttributes()},readCentralDir:function(){var r;for(this.reader.setIndex(this.centralDirOffset);this.reader.readAndCheckSignature(yr.CENTRAL_FILE_HEADER);)r=new OL({zip64:this.zip64},this.loadOptions),r.readCentralPart(this.reader),this.files.push(r);if(this.centralDirRecords!==this.files.length&&this.centralDirRecords!==0&&this.files.length===0)throw new Error("Corrupted zip or bug: expected "+this.centralDirRecords+" records in central dir, got "+this.files.length)},readEndOfCentral:function(){var r=this.reader.lastIndexOfSignature(yr.CENTRAL_DIRECTORY_END);if(r<0){var e=!this.isSignature(0,yr.LOCAL_FILE_HEADER);throw e?new Error("Can't find end of central directory : is this a zip file ? If it is, see https://stuk.github.io/jszip/documentation/howto/read_zip.html"):new Error("Corrupted zip: can't find end of central directory")}this.reader.setIndex(r);var t=r;if(this.checkSignature(yr.CENTRAL_DIRECTORY_END),this.readBlockEndOfCentral(),this.diskNumber===Yr.MAX_VALUE_16BITS||this.diskWithCentralDirStart===Yr.MAX_VALUE_16BITS||this.centralDirRecordsOnThisDisk===Yr.MAX_VALUE_16BITS||this.centralDirRecords===Yr.MAX_VALUE_16BITS||this.centralDirSize===Yr.MAX_VALUE_32BITS||this.centralDirOffset===Yr.MAX_VALUE_32BITS){if(this.zip64=!0,r=this.reader.lastIndexOfSignature(yr.ZIP64_CENTRAL_DIRECTORY_LOCATOR),r<0)throw new Error("Corrupted zip: can't find the ZIP64 end of central directory locator");if(this.reader.setIndex(r),this.checkSignature(yr.ZIP64_CENTRAL_DIRECTORY_LOCATOR),this.readBlockZip64EndOfCentralLocator(),!this.isSignature(this.relativeOffsetEndOfZip64CentralDir,yr.ZIP64_CENTRAL_DIRECTORY_END)&&(this.relativeOffsetEndOfZip64CentralDir=this.reader.lastIndexOfSignature(yr.ZIP64_CENTRAL_DIRECTORY_END),this.relativeOffsetEndOfZip64CentralDir<0))throw new Error("Corrupted zip: can't find the ZIP64 end of central directory");this.reader.setIndex(this.relativeOffsetEndOfZip64CentralDir),this.checkSignature(yr.ZIP64_CENTRAL_DIRECTORY_END),this.readBlockZip64EndOfCentral()}var n=this.centralDirOffset+this.centralDirSize;this.zip64&&(n+=20,n+=12+this.zip64EndOfCentralSize);var i=t-n;if(i>0)this.isSignature(t,yr.CENTRAL_FILE_HEADER)||(this.reader.zero=i);else if(i<0)throw new Error("Corrupted zip: missing "+Math.abs(i)+" bytes.")},prepareReader:function(r){this.reader=PL(r)},load:function(r){this.prepareReader(r),this.readEndOfCentral(),this.readCentralDir(),this.readLocalFiles()}};S2.exports=x2});var _2=j((U7,T2)=>{"use strict";var hp=je(),Ju=Ci(),NL=Ri(),ML=E2(),BL=df(),A2=Ws();function DL(r){return new Ju.Promise(function(e,t){var n=r.decompressed.getContentWorker().pipe(new BL);n.on("error",function(i){t(i)}).on("end",function(){n.streamInfo.crc32!==r.decompressed.crc32?t(new Error("Corrupted zip : CRC32 mismatch")):e()}).resume()})}T2.exports=function(r,e){var t=this;return e=hp.extend(e||{},{base64:!1,checkCRC32:!1,optimizedBinaryString:!1,createFolders:!1,decodeFileName:NL.utf8decode}),A2.isNode&&A2.isStream(r)?Ju.Promise.reject(new Error("JSZip can't accept a stream when loading a zip file.")):hp.prepareContent("the loaded zip file",r,!0,e.optimizedBinaryString,e.base64).then(function(n){var i=new ML(e);return i.load(n),i}).then(function(i){var s=[Ju.Promise.resolve(i)],a=i.files;if(e.checkCRC32)for(var o=0;o<a.length;o++)s.push(DL(a[o]));return Ju.Promise.all(s)}).then(function(i){for(var s=i.shift(),a=s.files,o=0;o<a.length;o++){var u=a[o],l=u.fileNameStr,c=hp.resolve(u.fileNameStr);t.file(c,u.decompressed,{binary:!0,optimizedBinaryString:!0,date:u.date,dir:u.dir,comment:u.fileCommentStr.length?u.fileCommentStr:null,unixPermissions:u.unixPermissions,dosPermissions:u.dosPermissions,createFolders:e.createFolders}),u.dir||(t.file(c).unsafeOriginalName=l)}return s.zipComment.length&&(t.comment=s.zipComment),t})}});var k2=j((z7,C2)=>{"use strict";function nr(){if(!(this instanceof nr))return new nr;if(arguments.length)throw new Error("The constructor with parameters has been removed in JSZip 3.0, please check the upgrade guide.");this.files=Object.create(null),this.comment=null,this.root="",this.clone=function(){var r=new nr;for(var e in this)typeof this[e]!="function"&&(r[e]=this[e]);return r}}nr.prototype=r2();nr.prototype.loadAsync=_2();nr.support=Wr();nr.defaults=lf();nr.version="3.10.1";nr.loadAsync=function(r,e){return new nr().loadAsync(r,e)};nr.external=Ci();C2.exports=nr});var WS=j((VU,HS)=>{"use strict";var ZN=function(e){return JN(e)&&!eM(e)};function JN(r){return!!r&&typeof r=="object"}function eM(r){var e=Object.prototype.toString.call(r);return e==="[object RegExp]"||e==="[object Date]"||nM(r)}var tM=typeof Symbol=="function"&&Symbol.for,rM=tM?Symbol.for("react.element"):60103;function nM(r){return r.$$typeof===rM}function iM(r){return Array.isArray(r)?[]:{}}function Ba(r,e){return e.clone!==!1&&e.isMergeableObject(r)?ss(iM(r),r,e):r}function sM(r,e,t){return r.concat(e).map(function(n){return Ba(n,t)})}function aM(r,e){if(!e.customMerge)return ss;var t=e.customMerge(r);return typeof t=="function"?t:ss}function oM(r){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(r).filter(function(e){return Object.propertyIsEnumerable.call(r,e)}):[]}function zS(r){return Object.keys(r).concat(oM(r))}function jS(r,e){try{return e in r}catch{return!1}}function uM(r,e){return jS(r,e)&&!(Object.hasOwnProperty.call(r,e)&&Object.propertyIsEnumerable.call(r,e))}function lM(r,e,t){var n={};return t.isMergeableObject(r)&&zS(r).forEach(function(i){n[i]=Ba(r[i],t)}),zS(e).forEach(function(i){uM(r,i)||(jS(r,i)&&t.isMergeableObject(e[i])?n[i]=aM(i,t)(r[i],e[i],t):n[i]=Ba(e[i],t))}),n}function ss(r,e,t){t=t||{},t.arrayMerge=t.arrayMerge||sM,t.isMergeableObject=t.isMergeableObject||ZN,t.cloneUnlessOtherwiseSpecified=Ba;var n=Array.isArray(e),i=Array.isArray(r),s=n===i;return s?n?t.arrayMerge(r,e,t):lM(r,e,t):Ba(e,t)}ss.all=function(e,t){if(!Array.isArray(e))throw new Error("first argument should be an array");return e.reduce(function(n,i){return ss(n,i,t)},{})};var cM=ss;HS.exports=cM});import{StdioServerTransport as yF}from"@modelcontextprotocol/sdk/server/stdio.js";import{McpServer as iC}from"@modelcontextprotocol/sdk/server/mcp.js";var ge=class extends Error{constructor(t,n){super(n);this.code=t;this.name="McpError"}};function Zm(r){let e=r instanceof ge?r.code:"INTERNAL_ERROR",t=r.message;return{content:[{type:"text",text:JSON.stringify({error:e,message:t})}],isError:!0}}function Jm(r){return async(e,t)=>{try{let n=await r(e,t);return{content:[{type:"text",text:typeof n=="string"?n:JSON.stringify(n)}]}}catch(n){if(n instanceof ge)return Zm(n);let i=n instanceof Error?n.message:String(n);return console.error("Unhandled error in MCP tool:",n),Zm(new ge("INTERNAL_ERROR",i))}}}function Ie(r,e){let t={book:"BOOK_NOT_FOUND",chapter:"CHAPTER_NOT_FOUND",section:"SECTION_NOT_FOUND"};throw new ge(t[r],`${r} not found: ${e}`)}var sC="1.0.0";function aC(){return new iC({name:"openread",version:sC})}var Eh=null;function gi(){return Eh||(Eh=aC()),Eh}function ke(r,e,t,n){let i=gi(),s=async(a,o)=>{let u=_e(),l=await Jm(n)(a,u);return{content:l.content,isError:l.isError}};i.registerTool(r,{description:e,inputSchema:t},s)}var Ah=null;function eb(r){Ah=r}function _e(){if(!Ah)throw new Error("MCP context not set. Call setContext() before handling requests.");return Ah}import{createClient as oC}from"@supabase/supabase-js";var Sr=class extends Error{constructor(t,n=!1){super(t);this.recoverable=n;this.name="AuthError"}},uC="https://app.openread.ai",tb=300*1e3,Th=3,lC=1e3,rb=3,cC=1e4,Wo=class{constructor(e,t){this.apiKey=e;this.apiUrl=t??process.env.OPENREAD_API_URL??uC}jwt=null;userId=null;expiresAt=0;supabaseClient=null;refreshTimer=null;refreshPromise=null;apiUrl;async initialize(){await this.exchangeToken(),this.scheduleRefresh()}getJwt(){if(!this.jwt)throw new Sr("Not authenticated. Call initialize() first.");let e=Date.now();if(e>=this.expiresAt)throw new Sr("JWT expired. Please restart the server.",!1);return e>=this.expiresAt-tb&&!this.refreshPromise&&this.triggerBackgroundRefresh(),this.jwt}getUserId(){if(!this.userId)throw new Sr("Not authenticated. Call initialize() first.");return this.userId}getSupabaseClient(){if(!this.supabaseClient)throw new Sr("Not authenticated. Call initialize() first.");return this.supabaseClient}getApiUrl(){return this.apiUrl}destroy(){this.refreshTimer&&(clearTimeout(this.refreshTimer),this.refreshTimer=null)}async exchangeToken(){let e=null;for(let t=0;t<Th;t++)try{let n=await fetch(`${this.apiUrl}/api/mcp/auth`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:this.apiKey})});if(n.status===401)throw new Sr("API key is invalid or has been revoked. Generate a new key at Settings > API Keys.",!1);if(n.status===429)throw new Sr("Rate limited. Too many authentication attempts.",!0);if(!n.ok)throw new Error(`Auth endpoint returned ${n.status}: ${await n.text()}`);let i=await n.json();this.jwt=i.jwt,this.userId=i.userId,this.expiresAt=i.expiresAt,this.supabaseClient=oC(i.supabaseUrl,i.supabaseAnonKey,{global:{headers:{Authorization:`Bearer ${i.jwt}`}},auth:{persistSession:!1}});return}catch(n){if(n instanceof Sr&&!n.recoverable)throw n;if(e=n instanceof Error?n:new Error(String(n)),t<Th-1){let i=lC*Math.pow(2,t);await new Promise(s=>setTimeout(s,i))}}throw new Sr(`Failed to authenticate after ${Th} attempts. Last error: ${e?.message}. Check your network connection and verify your API key is valid.`,!1)}scheduleRefresh(){this.refreshTimer&&clearTimeout(this.refreshTimer);let e=Math.max(0,this.expiresAt-tb-Date.now());this.refreshTimer=setTimeout(()=>{this.triggerBackgroundRefresh()},e)}triggerBackgroundRefresh(e=0){this.refreshPromise||(this.refreshPromise=this.exchangeToken().then(()=>{this.refreshPromise=null,this.scheduleRefresh()}).catch(t=>{let n=t instanceof Error?t.message:String(t);if(process.stderr.write(`[openread-mcp] JWT refresh failed (attempt ${e+1}/${rb}): ${n}
|
|
108
110
|
`),e+1<rb&&Date.now()<this.expiresAt){let i=cC*Math.pow(2,e);process.stderr.write(`[openread-mcp] Retrying refresh in ${i/1e3}s...
|
|
109
111
|
`),this.refreshTimer=setTimeout(()=>{this.refreshPromise=null,this.triggerBackgroundRefresh(e+1)},i)}else process.stderr.write(`[openread-mcp] JWT refresh exhausted retries. Server will need restart when token expires.
|
|
110
|
-
`),this.refreshPromise=null}))}};import{promises as Tt}from"node:fs";import zo from"node:path";import oD from"env-paths";var OF=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date;var _h=typeof process=="object"&&process?process:{},hC=(r,e,t,n)=>{typeof _h.emitWarning=="function"?_h.emitWarning(r,e,t,n):console.error(`[${t}] ${e}: ${r}`)},nb=globalThis.AbortController,ib=globalThis.AbortSignal;if(typeof nb>"u"){ib=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(n,i){this._onabort.push(i)}},nb=class{constructor(){e()}signal=new ib;abort(n){if(!this.signal.aborted){this.signal.reason=n,this.signal.aborted=!0;for(let i of this.signal._onabort)i(n);this.signal.onabort?.(n)}}};let r=_h.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{r&&(r=!1,hC("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e))}}var uu=Sh(p1(),1),g1
|
|
112
|
+
`),this.refreshPromise=null}))}};import{promises as Tt}from"node:fs";import zo from"node:path";import oD from"env-paths";var OF=typeof performance=="object"&&performance&&typeof performance.now=="function"?performance:Date;var _h=typeof process=="object"&&process?process:{},hC=(r,e,t,n)=>{typeof _h.emitWarning=="function"?_h.emitWarning(r,e,t,n):console.error(`[${t}] ${e}: ${r}`)},nb=globalThis.AbortController,ib=globalThis.AbortSignal;if(typeof nb>"u"){ib=class{onabort;_onabort=[];reason;aborted=!1;addEventListener(n,i){this._onabort.push(i)}},nb=class{constructor(){e()}signal=new ib;abort(n){if(!this.signal.aborted){this.signal.reason=n,this.signal.aborted=!0;for(let i of this.signal._onabort)i(n);this.signal.onabort?.(n)}}};let r=_h.env?.LRU_CACHE_IGNORE_AC_WARNING!=="1",e=()=>{r&&(r=!1,hC("AbortController is not defined. If using lru-cache in node 14, load an AbortController polyfill from the `node-abort-controller` package. A minimal polyfill is provided for use by LRUCache.fetch(), but it should not be relied upon in other contexts (eg, passing it to other APIs that use AbortController/AbortSignal might have undesirable effects). You may disable this with LRU_CACHE_IGNORE_AC_WARNING=1 in the env.","NO_ABORT_CONTROLLER","ENOTSUP",e))}}var uu=Sh(p1(),1),g1=!1,nR={level:process.env.LOG_LEVEL||(g1?"debug":"info"),transport:g1?{target:"pino-pretty",options:{colorize:!0,translateTime:"SYS:standard",ignore:"pid,hostname"}}:void 0,timestamp:uu.stdTimeFunctions.isoTime,base:{env:"production",service:"openread-api"},redact:["req.headers.authorization","password","token","secret"]},iR=(0,uu.pino)(nR);function m1(r){return iR.child(r)}var w9=m1({module:"retry"});var T9={epub:100*1024*1024,pdf:200*1024*1024,mobi:100*1024*1024,azw:100*1024*1024,azw3:100*1024*1024,fb2:50*1024*1024,fbz:50*1024*1024,cbz:500*1024*1024,txt:50*1024*1024,md:50*1024*1024};var aE=Sh(k2(),1);var I2=":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",FL=I2+"\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",$L="["+I2+"]["+FL+"]*",UL=new RegExp("^"+$L+"$");function el(r,e){let t=[],n=e.exec(r);for(;n;){let i=[];i.startIndex=e.lastIndex-n[0].length;let s=n.length;for(let a=0;a<s;a++)i.push(n[a]);t.push(i),n=e.exec(r)}return t}var Gi=function(r){let e=UL.exec(r);return!(e===null||typeof e>"u")};function R2(r){return typeof r<"u"}var zL={allowBooleanAttributes:!1,unpairedTags:[]};function M2(r,e){e=Object.assign({},zL,e);let t=[],n=!1,i=!1;r[0]==="\uFEFF"&&(r=r.substr(1));for(let s=0;s<r.length;s++)if(r[s]==="<"&&r[s+1]==="?"){if(s+=2,s=O2(r,s),s.err)return s}else if(r[s]==="<"){let a=s;if(s++,r[s]==="!"){s=L2(r,s);continue}else{let o=!1;r[s]==="/"&&(o=!0,s++);let u="";for(;s<r.length&&r[s]!==">"&&r[s]!==" "&&r[s]!==" "&&r[s]!==`
|
|
111
113
|
`&&r[s]!=="\r";s++)u+=r[s];if(u=u.trim(),u[u.length-1]==="/"&&(u=u.substring(0,u.length-1),s--),!XL(u)){let h;return u.trim().length===0?h="Invalid space after '<'.":h="Tag '"+u+"' is an invalid name.",Ze("InvalidTag",h,It(r,s))}let l=WL(r,s);if(l===!1)return Ze("InvalidAttr","Attributes for '"+u+"' have open quote.",It(r,s));let c=l.value;if(s=l.index,c[c.length-1]==="/"){let h=s-c.length;c=c.substring(0,c.length-1);let d=N2(c,e);if(d===!0)n=!0;else return Ze(d.err.code,d.err.msg,It(r,h+d.err.line))}else if(o)if(l.tagClosed){if(c.trim().length>0)return Ze("InvalidTag","Closing tag '"+u+"' can't have attributes or invalid starting.",It(r,a));if(t.length===0)return Ze("InvalidTag","Closing tag '"+u+"' has not been opened.",It(r,a));{let h=t.pop();if(u!==h.tagName){let d=It(r,h.tagStartPos);return Ze("InvalidTag","Expected closing tag '"+h.tagName+"' (opened in line "+d.line+", col "+d.col+") instead of closing tag '"+u+"'.",It(r,a))}t.length==0&&(i=!0)}}else return Ze("InvalidTag","Closing tag '"+u+"' doesn't have proper closing.",It(r,s));else{let h=N2(c,e);if(h!==!0)return Ze(h.err.code,h.err.msg,It(r,s-c.length+h.err.line));if(i===!0)return Ze("InvalidXml","Multiple possible root nodes found.",It(r,s));e.unpairedTags.indexOf(u)!==-1||t.push({tagName:u,tagStartPos:a}),n=!0}for(s++;s<r.length;s++)if(r[s]==="<")if(r[s+1]==="!"){s++,s=L2(r,s);continue}else if(r[s+1]==="?"){if(s=O2(r,++s),s.err)return s}else break;else if(r[s]==="&"){let h=qL(r,s);if(h==-1)return Ze("InvalidChar","char '&' is not expected.",It(r,s));s=h}else if(i===!0&&!P2(r[s]))return Ze("InvalidXml","Extra text at the end",It(r,s));r[s]==="<"&&s--}}else{if(P2(r[s]))continue;return Ze("InvalidChar","char '"+r[s]+"' is not expected.",It(r,s))}if(n){if(t.length==1)return Ze("InvalidTag","Unclosed tag '"+t[0].tagName+"'.",It(r,t[0].tagStartPos));if(t.length>0)return Ze("InvalidXml","Invalid '"+JSON.stringify(t.map(s=>s.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1})}else return Ze("InvalidXml","Start tag expected.",1);return!0}function P2(r){return r===" "||r===" "||r===`
|
|
112
114
|
`||r==="\r"}function O2(r,e){let t=e;for(;e<r.length;e++)if(r[e]=="?"||r[e]==" "){let n=r.substr(t,e-t);if(e>5&&n==="xml")return Ze("InvalidXml","XML declaration allowed only at the start of the document.",It(r,e));if(r[e]=="?"&&r[e+1]==">"){e++;break}else continue}return e}function L2(r,e){if(r.length>e+5&&r[e+1]==="-"&&r[e+2]==="-"){for(e+=3;e<r.length;e++)if(r[e]==="-"&&r[e+1]==="-"&&r[e+2]===">"){e+=2;break}}else if(r.length>e+8&&r[e+1]==="D"&&r[e+2]==="O"&&r[e+3]==="C"&&r[e+4]==="T"&&r[e+5]==="Y"&&r[e+6]==="P"&&r[e+7]==="E"){let t=1;for(e+=8;e<r.length;e++)if(r[e]==="<")t++;else if(r[e]===">"&&(t--,t===0))break}else if(r.length>e+9&&r[e+1]==="["&&r[e+2]==="C"&&r[e+3]==="D"&&r[e+4]==="A"&&r[e+5]==="T"&&r[e+6]==="A"&&r[e+7]==="["){for(e+=8;e<r.length;e++)if(r[e]==="]"&&r[e+1]==="]"&&r[e+2]===">"){e+=2;break}}return e}var jL='"',HL="'";function WL(r,e){let t="",n="",i=!1;for(;e<r.length;e++){if(r[e]===jL||r[e]===HL)n===""?n=r[e]:n!==r[e]||(n="");else if(r[e]===">"&&n===""){i=!0;break}t+=r[e]}return n!==""?!1:{value:t,index:e,tagClosed:i}}var VL=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function N2(r,e){let t=el(r,VL),n={};for(let i=0;i<t.length;i++){if(t[i][1].length===0)return Ze("InvalidAttr","Attribute '"+t[i][2]+"' has no space in starting.",ma(t[i]));if(t[i][3]!==void 0&&t[i][4]===void 0)return Ze("InvalidAttr","Attribute '"+t[i][2]+"' is without value.",ma(t[i]));if(t[i][3]===void 0&&!e.allowBooleanAttributes)return Ze("InvalidAttr","boolean attribute '"+t[i][2]+"' is not allowed.",ma(t[i]));let s=t[i][2];if(!KL(s))return Ze("InvalidAttr","Attribute '"+s+"' is an invalid name.",ma(t[i]));if(!n.hasOwnProperty(s))n[s]=1;else return Ze("InvalidAttr","Attribute '"+s+"' is repeated.",ma(t[i]))}return!0}function GL(r,e){let t=/\d/;for(r[e]==="x"&&(e++,t=/[\da-fA-F]/);e<r.length;e++){if(r[e]===";")return e;if(!r[e].match(t))break}return-1}function qL(r,e){if(e++,r[e]===";")return-1;if(r[e]==="#")return e++,GL(r,e);let t=0;for(;e<r.length;e++,t++)if(!(r[e].match(/\w/)&&t<20)){if(r[e]===";")break;return-1}return e}function Ze(r,e,t){return{err:{code:r,msg:e,line:t.line||t,col:t.col}}}function KL(r){return Gi(r)}function XL(r){return Gi(r)}function It(r,e){let t=r.substring(0,e).split(/\r?\n/);return{line:t.length,col:t[t.length-1].length+1}}function ma(r){return r.startIndex+r[1].length}var YL={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function(r,e){return e},attributeValueProcessor:function(r,e){return e},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function(r,e,t){return r},captureMetaData:!1};function B2(r){return typeof r=="boolean"?{enabled:r,maxEntitySize:1e4,maxExpansionDepth:10,maxTotalExpansions:1e3,maxExpandedLength:1e5,allowedTags:null,tagFilter:null}:typeof r=="object"&&r!==null?{enabled:r.enabled!==!1,maxEntitySize:r.maxEntitySize??1e4,maxExpansionDepth:r.maxExpansionDepth??10,maxTotalExpansions:r.maxTotalExpansions??1e3,maxExpandedLength:r.maxExpandedLength??1e5,allowedTags:r.allowedTags??null,tagFilter:r.tagFilter??null}:B2(!0)}var D2=function(r){let e=Object.assign({},YL,r);return e.processEntities=B2(e.processEntities),e};var tl;typeof Symbol!="function"?tl="@@xmlMetadata":tl=Symbol("XML Node Metadata");var Vt=class{constructor(e){this.tagname=e,this.child=[],this[":@"]={}}add(e,t){e==="__proto__"&&(e="#__proto__"),this.child.push({[e]:t})}addChild(e,t){e.tagname==="__proto__"&&(e.tagname="#__proto__"),e[":@"]&&Object.keys(e[":@"]).length>0?this.child.push({[e.tagname]:e.child,":@":e[":@"]}):this.child.push({[e.tagname]:e.child}),t!==void 0&&(this.child[this.child.length-1][tl]={startIndex:t})}static getMetaDataSymbol(){return tl}};var ya=class{constructor(e){this.suppressValidationErr=!e,this.options=e}readDocType(e,t){let n={};if(e[t+3]==="O"&&e[t+4]==="C"&&e[t+5]==="T"&&e[t+6]==="Y"&&e[t+7]==="P"&&e[t+8]==="E"){t=t+9;let i=1,s=!1,a=!1,o="";for(;t<e.length;t++)if(e[t]==="<"&&!a){if(s&&Xn(e,"!ENTITY",t)){t+=7;let u,l;if([u,l,t]=this.readEntityExp(e,t+1,this.suppressValidationErr),l.indexOf("&")===-1){let c=u.replace(/[.\-+*:]/g,"\\.");n[u]={regx:RegExp(`&${c};`,"g"),val:l}}}else if(s&&Xn(e,"!ELEMENT",t)){t+=8;let{index:u}=this.readElementExp(e,t+1);t=u}else if(s&&Xn(e,"!ATTLIST",t))t+=8;else if(s&&Xn(e,"!NOTATION",t)){t+=9;let{index:u}=this.readNotationExp(e,t+1,this.suppressValidationErr);t=u}else if(Xn(e,"!--",t))a=!0;else throw new Error("Invalid DOCTYPE");i++,o=""}else if(e[t]===">"){if(a?e[t-1]==="-"&&e[t-2]==="-"&&(a=!1,i--):i--,i===0)break}else e[t]==="["?s=!0:o+=e[t];if(i!==0)throw new Error("Unclosed DOCTYPE")}else throw new Error("Invalid Tag instead of DOCTYPE");return{entities:n,i:t}}readEntityExp(e,t){t=Bt(e,t);let n="";for(;t<e.length&&!/\s/.test(e[t])&&e[t]!=='"'&&e[t]!=="'";)n+=e[t],t++;if(ba(n),t=Bt(e,t),!this.suppressValidationErr){if(e.substring(t,t+6).toUpperCase()==="SYSTEM")throw new Error("External entities are not supported");if(e[t]==="%")throw new Error("Parameter entities are not supported")}let i="";if([t,i]=this.readIdentifierVal(e,t,"entity"),this.options.enabled!==!1&&this.options.maxEntitySize&&i.length>this.options.maxEntitySize)throw new Error(`Entity "${n}" size (${i.length}) exceeds maximum allowed size (${this.options.maxEntitySize})`);return t--,[n,i,t]}readNotationExp(e,t){t=Bt(e,t);let n="";for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;!this.suppressValidationErr&&ba(n),t=Bt(e,t);let i=e.substring(t,t+6).toUpperCase();if(!this.suppressValidationErr&&i!=="SYSTEM"&&i!=="PUBLIC")throw new Error(`Expected SYSTEM or PUBLIC, found "${i}"`);t+=i.length,t=Bt(e,t);let s=null,a=null;if(i==="PUBLIC")[t,s]=this.readIdentifierVal(e,t,"publicIdentifier"),t=Bt(e,t),(e[t]==='"'||e[t]==="'")&&([t,a]=this.readIdentifierVal(e,t,"systemIdentifier"));else if(i==="SYSTEM"&&([t,a]=this.readIdentifierVal(e,t,"systemIdentifier"),!this.suppressValidationErr&&!a))throw new Error("Missing mandatory system identifier for SYSTEM notation");return{notationName:n,publicIdentifier:s,systemIdentifier:a,index:--t}}readIdentifierVal(e,t,n){let i="",s=e[t];if(s!=='"'&&s!=="'")throw new Error(`Expected quoted string, found "${s}"`);for(t++;t<e.length&&e[t]!==s;)i+=e[t],t++;if(e[t]!==s)throw new Error(`Unterminated ${n} value`);return t++,[t,i]}readElementExp(e,t){t=Bt(e,t);let n="";for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;if(!this.suppressValidationErr&&!Gi(n))throw new Error(`Invalid element name: "${n}"`);t=Bt(e,t);let i="";if(e[t]==="E"&&Xn(e,"MPTY",t))t+=4;else if(e[t]==="A"&&Xn(e,"NY",t))t+=2;else if(e[t]==="("){for(t++;t<e.length&&e[t]!==")";)i+=e[t],t++;if(e[t]!==")")throw new Error("Unterminated content model")}else if(!this.suppressValidationErr)throw new Error(`Invalid Element Expression, found "${e[t]}"`);return{elementName:n,contentModel:i.trim(),index:t}}readAttlistExp(e,t){t=Bt(e,t);let n="";for(;t<e.length&&!/\s/.test(e[t]);)n+=e[t],t++;ba(n),t=Bt(e,t);let i="";for(;t<e.length&&!/\s/.test(e[t]);)i+=e[t],t++;if(!ba(i))throw new Error(`Invalid attribute name: "${i}"`);t=Bt(e,t);let s="";if(e.substring(t,t+8).toUpperCase()==="NOTATION"){if(s="NOTATION",t+=8,t=Bt(e,t),e[t]!=="(")throw new Error(`Expected '(', found "${e[t]}"`);t++;let o=[];for(;t<e.length&&e[t]!==")";){let u="";for(;t<e.length&&e[t]!=="|"&&e[t]!==")";)u+=e[t],t++;if(u=u.trim(),!ba(u))throw new Error(`Invalid notation name: "${u}"`);o.push(u),e[t]==="|"&&(t++,t=Bt(e,t))}if(e[t]!==")")throw new Error("Unterminated list of notations");t++,s+=" ("+o.join("|")+")"}else{for(;t<e.length&&!/\s/.test(e[t]);)s+=e[t],t++;let o=["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"];if(!this.suppressValidationErr&&!o.includes(s.toUpperCase()))throw new Error(`Invalid attribute type: "${s}"`)}t=Bt(e,t);let a="";return e.substring(t,t+8).toUpperCase()==="#REQUIRED"?(a="#REQUIRED",t+=8):e.substring(t,t+7).toUpperCase()==="#IMPLIED"?(a="#IMPLIED",t+=7):[t,a]=this.readIdentifierVal(e,t,"ATTLIST"),{elementName:n,attributeName:i,attributeType:s,defaultValue:a,index:t}}},Bt=(r,e)=>{for(;e<r.length&&/\s/.test(r[e]);)e++;return e};function Xn(r,e,t){for(let n=0;n<e.length;n++)if(e[n]!==r[t+n+1])return!1;return!0}function ba(r){if(Gi(r))return r;throw new Error(`Invalid entity name ${r}`)}var QL=/^[-+]?0x[a-fA-F0-9]+$/,ZL=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,JL={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function dp(r,e={}){if(e=Object.assign({},JL,e),!r||typeof r!="string")return r;let t=r.trim();if(e.skipLike!==void 0&&e.skipLike.test(t))return r;if(r==="0")return 0;if(e.hex&&QL.test(t))return n8(t,16);if(t.includes("e")||t.includes("E"))return t8(r,t,e);{let n=ZL.exec(t);if(n){let i=n[1]||"",s=n[2],a=r8(n[3]),o=i?r[s.length+1]===".":r[s.length]===".";if(!e.leadingZeros&&(s.length>1||s.length===1&&!o))return r;{let u=Number(t),l=String(u);if(u===0)return u;if(l.search(/[eE]/)!==-1)return e.eNotation?u:r;if(t.indexOf(".")!==-1)return l==="0"||l===a||l===`${i}${a}`?u:r;let c=s?a:t;return s?c===l||i+c===l?u:r:c===l||c===i+l?u:r}}else return r}}var e8=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function t8(r,e,t){if(!t.eNotation)return r;let n=e.match(e8);if(n){let i=n[1]||"",s=n[3].indexOf("e")===-1?"E":"e",a=n[2],o=i?r[a.length+1]===s:r[a.length]===s;return a.length>1&&o?r:a.length===1&&(n[3].startsWith(`.${s}`)||n[3][0]===s)?Number(e):t.leadingZeros&&!o?(e=(n[1]||"")+n[3],Number(e)):r}else return r}function r8(r){return r&&r.indexOf(".")!==-1&&(r=r.replace(/0+$/,""),r==="."?r="0":r[0]==="."?r="0"+r:r[r.length-1]==="."&&(r=r.substring(0,r.length-1))),r}function n8(r,e){if(parseInt)return parseInt(r,e);if(Number.parseInt)return Number.parseInt(r,e);if(window&&window.parseInt)return window.parseInt(r,e);throw new Error("parseInt, Number.parseInt, window.parseInt are not supported")}function fp(r){return typeof r=="function"?r:Array.isArray(r)?e=>{for(let t of r)if(typeof t=="string"&&e===t||t instanceof RegExp&&t.test(e))return!0}:()=>!1}var va=class{constructor(e){if(this.options=e,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"\xA2"},pound:{regex:/&(pound|#163);/g,val:"\xA3"},yen:{regex:/&(yen|#165);/g,val:"\xA5"},euro:{regex:/&(euro|#8364);/g,val:"\u20AC"},copyright:{regex:/&(copy|#169);/g,val:"\xA9"},reg:{regex:/&(reg|#174);/g,val:"\xAE"},inr:{regex:/&(inr|#8377);/g,val:"\u20B9"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(t,n)=>F2(n,10,"&#")},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(t,n)=>F2(n,16,"&#x")}},this.addExternalEntities=i8,this.parseXml=l8,this.parseTextData=s8,this.resolveNameSpace=a8,this.buildAttributesMap=u8,this.isItStopNode=f8,this.replaceEntitiesValue=h8,this.readStopNodeData=g8,this.saveTextToParentTag=d8,this.addChild=c8,this.ignoreAttributesFn=fp(this.options.ignoreAttributes),this.entityExpansionCount=0,this.currentExpandedLength=0,this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodesExact=new Set,this.stopNodesWildcard=new Set;for(let t=0;t<this.options.stopNodes.length;t++){let n=this.options.stopNodes[t];typeof n=="string"&&(n.startsWith("*.")?this.stopNodesWildcard.add(n.substring(2)):this.stopNodesExact.add(n))}}}};function i8(r){let e=Object.keys(r);for(let t=0;t<e.length;t++){let n=e[t],i=n.replace(/[.\-+*:]/g,"\\.");this.lastEntities[n]={regex:new RegExp("&"+i+";","g"),val:r[n]}}}function s8(r,e,t,n,i,s,a){if(r!==void 0&&(this.options.trimValues&&!n&&(r=r.trim()),r.length>0)){a||(r=this.replaceEntitiesValue(r,e,t));let o=this.options.tagValueProcessor(e,r,t,i,s);return o==null?r:typeof o!=typeof r||o!==r?o:this.options.trimValues?gp(r,this.options.parseTagValue,this.options.numberParseOptions):r.trim()===r?gp(r,this.options.parseTagValue,this.options.numberParseOptions):r}}function a8(r){if(this.options.removeNSPrefix){let e=r.split(":"),t=r.charAt(0)==="/"?"/":"";if(e[0]==="xmlns")return"";e.length===2&&(r=t+e[1])}return r}var o8=new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,"gm");function u8(r,e,t){if(this.options.ignoreAttributes!==!0&&typeof r=="string"){let n=el(r,o8),i=n.length,s={};for(let a=0;a<i;a++){let o=this.resolveNameSpace(n[a][1]);if(this.ignoreAttributesFn(o,e))continue;let u=n[a][4],l=this.options.attributeNamePrefix+o;if(o.length)if(this.options.transformAttributeName&&(l=this.options.transformAttributeName(l)),l==="__proto__"&&(l="#__proto__"),u!==void 0){this.options.trimValues&&(u=u.trim()),u=this.replaceEntitiesValue(u,t,e);let c=this.options.attributeValueProcessor(o,u,e);c==null?s[l]=u:typeof c!=typeof u||c!==u?s[l]=c:s[l]=gp(u,this.options.parseAttributeValue,this.options.numberParseOptions)}else this.options.allowBooleanAttributes&&(s[l]=!0)}if(!Object.keys(s).length)return;if(this.options.attributesGroupName){let a={};return a[this.options.attributesGroupName]=s,a}return s}}var l8=function(r){r=r.replace(/\r\n?/g,`
|
|
113
115
|
`);let e=new Vt("!xml"),t=e,n="",i="";this.entityExpansionCount=0,this.currentExpandedLength=0;let s=new ya(this.options.processEntities);for(let a=0;a<r.length;a++)if(r[a]==="<")if(r[a+1]==="/"){let u=Yn(r,">",a,"Closing Tag is not closed."),l=r.substring(a+2,u).trim();if(this.options.removeNSPrefix){let d=l.indexOf(":");d!==-1&&(l=l.substr(d+1))}this.options.transformTagName&&(l=this.options.transformTagName(l)),t&&(n=this.saveTextToParentTag(n,t,i));let c=i.substring(i.lastIndexOf(".")+1);if(l&&this.options.unpairedTags.indexOf(l)!==-1)throw new Error(`Unpaired tag can not be used as closing tag: </${l}>`);let h=0;c&&this.options.unpairedTags.indexOf(c)!==-1?(h=i.lastIndexOf(".",i.lastIndexOf(".")-1),this.tagsNodeStack.pop()):h=i.lastIndexOf("."),i=i.substring(0,h),t=this.tagsNodeStack.pop(),n="",a=u}else if(r[a+1]==="?"){let u=pp(r,a,!1,"?>");if(!u)throw new Error("Pi Tag is not closed.");if(n=this.saveTextToParentTag(n,t,i),!(this.options.ignoreDeclaration&&u.tagName==="?xml"||this.options.ignorePiTags)){let l=new Vt(u.tagName);l.add(this.options.textNodeName,""),u.tagName!==u.tagExp&&u.attrExpPresent&&(l[":@"]=this.buildAttributesMap(u.tagExp,i,u.tagName)),this.addChild(t,l,i,a)}a=u.closeIndex+1}else if(r.substr(a+1,3)==="!--"){let u=Yn(r,"-->",a+4,"Comment is not closed.");if(this.options.commentPropName){let l=r.substring(a+4,u-2);n=this.saveTextToParentTag(n,t,i),t.add(this.options.commentPropName,[{[this.options.textNodeName]:l}])}a=u}else if(r.substr(a+1,2)==="!D"){let u=s.readDocType(r,a);this.docTypeEntities=u.entities,a=u.i}else if(r.substr(a+1,2)==="!["){let u=Yn(r,"]]>",a,"CDATA is not closed.")-2,l=r.substring(a+9,u);n=this.saveTextToParentTag(n,t,i);let c=this.parseTextData(l,t.tagname,i,!0,!1,!0,!0);c==null&&(c=""),this.options.cdataPropName?t.add(this.options.cdataPropName,[{[this.options.textNodeName]:l}]):t.add(this.options.textNodeName,c),a=u+2}else{let u=pp(r,a,this.options.removeNSPrefix),l=u.tagName,c=u.rawTagName,h=u.tagExp,d=u.attrExpPresent,f=u.closeIndex;if(this.options.transformTagName){let b=this.options.transformTagName(l);h===l&&(h=b),l=b}t&&n&&t.tagname!=="!xml"&&(n=this.saveTextToParentTag(n,t,i,!1));let p=t;p&&this.options.unpairedTags.indexOf(p.tagname)!==-1&&(t=this.tagsNodeStack.pop(),i=i.substring(0,i.lastIndexOf("."))),l!==e.tagname&&(i+=i?"."+l:l);let g=a;if(this.isItStopNode(this.stopNodesExact,this.stopNodesWildcard,i,l)){let b="";if(h.length>0&&h.lastIndexOf("/")===h.length-1)l[l.length-1]==="/"?(l=l.substr(0,l.length-1),i=i.substr(0,i.length-1),h=l):h=h.substr(0,h.length-1),a=u.closeIndex;else if(this.options.unpairedTags.indexOf(l)!==-1)a=u.closeIndex;else{let y=this.readStopNodeData(r,c,f+1);if(!y)throw new Error(`Unexpected end of ${c}`);a=y.i,b=y.tagContent}let m=new Vt(l);l!==h&&d&&(m[":@"]=this.buildAttributesMap(h,i,l)),b&&(b=this.parseTextData(b,l,i,!0,d,!0,!0)),i=i.substr(0,i.lastIndexOf(".")),m.add(this.options.textNodeName,b),this.addChild(t,m,i,g)}else{if(h.length>0&&h.lastIndexOf("/")===h.length-1){if(l[l.length-1]==="/"?(l=l.substr(0,l.length-1),i=i.substr(0,i.length-1),h=l):h=h.substr(0,h.length-1),this.options.transformTagName){let m=this.options.transformTagName(l);h===l&&(h=m),l=m}let b=new Vt(l);l!==h&&d&&(b[":@"]=this.buildAttributesMap(h,i,l)),this.addChild(t,b,i,g),i=i.substr(0,i.lastIndexOf("."))}else{let b=new Vt(l);this.tagsNodeStack.push(t),l!==h&&d&&(b[":@"]=this.buildAttributesMap(h,i,l)),this.addChild(t,b,i,g),t=b}n="",a=f}}else n+=r[a];return e.child};function c8(r,e,t,n){this.options.captureMetaData||(n=void 0);let i=this.options.updateTag(e.tagname,t,e[":@"]);i===!1||(typeof i=="string"&&(e.tagname=i),r.addChild(e,n))}var h8=function(r,e,t){if(r.indexOf("&")===-1)return r;let n=this.options.processEntities;if(!n.enabled||n.allowedTags&&!n.allowedTags.includes(e)||n.tagFilter&&!n.tagFilter(e,t))return r;for(let i in this.docTypeEntities){let s=this.docTypeEntities[i],a=r.match(s.regx);if(a){if(this.entityExpansionCount+=a.length,n.maxTotalExpansions&&this.entityExpansionCount>n.maxTotalExpansions)throw new Error(`Entity expansion limit exceeded: ${this.entityExpansionCount} > ${n.maxTotalExpansions}`);let o=r.length;if(r=r.replace(s.regx,s.val),n.maxExpandedLength&&(this.currentExpandedLength+=r.length-o,this.currentExpandedLength>n.maxExpandedLength))throw new Error(`Total expanded content size exceeded: ${this.currentExpandedLength} > ${n.maxExpandedLength}`)}}if(r.indexOf("&")===-1)return r;for(let i in this.lastEntities){let s=this.lastEntities[i];r=r.replace(s.regex,s.val)}if(r.indexOf("&")===-1)return r;if(this.options.htmlEntities)for(let i in this.htmlEntities){let s=this.htmlEntities[i];r=r.replace(s.regex,s.val)}return r=r.replace(this.ampEntity.regex,this.ampEntity.val),r};function d8(r,e,t,n){return r&&(n===void 0&&(n=e.child.length===0),r=this.parseTextData(r,e.tagname,t,!1,e[":@"]?Object.keys(e[":@"]).length!==0:!1,n),r!==void 0&&r!==""&&e.add(this.options.textNodeName,r),r=""),r}function f8(r,e,t,n){return!!(e&&e.has(n)||r&&r.has(t))}function p8(r,e,t=">"){let n,i="";for(let s=e;s<r.length;s++){let a=r[s];if(n)a===n&&(n="");else if(a==='"'||a==="'")n=a;else if(a===t[0])if(t[1]){if(r[s+1]===t[1])return{data:i,index:s}}else return{data:i,index:s};else a===" "&&(a=" ");i+=a}}function Yn(r,e,t,n){let i=r.indexOf(e,t);if(i===-1)throw new Error(n);return i+e.length-1}function pp(r,e,t,n=">"){let i=p8(r,e+1,n);if(!i)return;let s=i.data,a=i.index,o=s.search(/\s/),u=s,l=!0;o!==-1&&(u=s.substring(0,o),s=s.substring(o+1).trimStart());let c=u;if(t){let h=u.indexOf(":");h!==-1&&(u=u.substr(h+1),l=u!==i.data.substr(h+1))}return{tagName:u,tagExp:s,closeIndex:a,attrExpPresent:l,rawTagName:c}}function g8(r,e,t){let n=t,i=1;for(;t<r.length;t++)if(r[t]==="<")if(r[t+1]==="/"){let s=Yn(r,">",t,`${e} is not closed`);if(r.substring(t+2,s).trim()===e&&(i--,i===0))return{tagContent:r.substring(n,t),i:s};t=s}else if(r[t+1]==="?")t=Yn(r,"?>",t+1,"StopNode is not closed.");else if(r.substr(t+1,3)==="!--")t=Yn(r,"-->",t+3,"StopNode is not closed.");else if(r.substr(t+1,2)==="![")t=Yn(r,"]]>",t,"StopNode is not closed.")-2;else{let s=pp(r,t,">");s&&((s&&s.tagName)===e&&s.tagExp[s.tagExp.length-1]!=="/"&&i++,t=s.closeIndex)}}function gp(r,e,t){if(e&&typeof r=="string"){let n=r.trim();return n==="true"?!0:n==="false"?!1:dp(r,t)}else return R2(r)?r:""}function F2(r,e,t){let n=Number.parseInt(r,e);return n>=0&&n<=1114111?String.fromCodePoint(n):t+r+";"}var mp=Vt.getMetaDataSymbol();function bp(r,e){return $2(r,e)}function $2(r,e,t){let n,i={};for(let s=0;s<r.length;s++){let a=r[s],o=m8(a),u="";if(t===void 0?u=o:u=t+"."+o,o===e.textNodeName)n===void 0?n=a[o]:n+=""+a[o];else{if(o===void 0)continue;if(a[o]){let l=$2(a[o],e,u),c=y8(l,e);a[mp]!==void 0&&(l[mp]=a[mp]),a[":@"]?b8(l,a[":@"],u,e):Object.keys(l).length===1&&l[e.textNodeName]!==void 0&&!e.alwaysCreateTextNode?l=l[e.textNodeName]:Object.keys(l).length===0&&(e.alwaysCreateTextNode?l[e.textNodeName]="":l=""),i[o]!==void 0&&i.hasOwnProperty(o)?(Array.isArray(i[o])||(i[o]=[i[o]]),i[o].push(l)):e.isArray(o,u,c)?i[o]=[l]:i[o]=l}}}return typeof n=="string"?n.length>0&&(i[e.textNodeName]=n):n!==void 0&&(i[e.textNodeName]=n),i}function m8(r){let e=Object.keys(r);for(let t=0;t<e.length;t++){let n=e[t];if(n!==":@")return n}}function b8(r,e,t,n){if(e){let i=Object.keys(e),s=i.length;for(let a=0;a<s;a++){let o=i[a];n.isArray(o,t+"."+o,!0,!0)?r[o]=[e[o]]:r[o]=e[o]}}}function y8(r,e){let{textNodeName:t}=e,n=Object.keys(r).length;return!!(n===0||n===1&&(r[t]||typeof r[t]=="boolean"||r[t]===0))}var qi=class{constructor(e){this.externalEntities={},this.options=D2(e)}parse(e,t){if(typeof e!="string"&&e.toString)e=e.toString();else if(typeof e!="string")throw new Error("XML data is accepted in String or Bytes[] form.");if(t){t===!0&&(t={});let s=M2(e,t);if(s!==!0)throw Error(`${s.err.msg}:${s.err.line}:${s.err.col}`)}let n=new va(this.options);n.addExternalEntities(this.externalEntities);let i=n.parseXml(e);return this.options.preserveOrder||i===void 0?i:bp(i,this.options)}addEntity(e,t){if(t.indexOf("&")!==-1)throw new Error("Entity value can't have '&'");if(e.indexOf("&")!==-1||e.indexOf(";")!==-1)throw new Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");if(t==="&")throw new Error("An entity with value '&' is not permitted");this.externalEntities[e]=t}static getMetaDataSymbol(){return Vt.getMetaDataSymbol()}};var Ee;(function(r){r.Root="root",r.Text="text",r.Directive="directive",r.Comment="comment",r.Script="script",r.Style="style",r.Tag="tag",r.CDATA="cdata",r.Doctype="doctype"})(Ee||(Ee={}));function U2(r){return r.type===Ee.Tag||r.type===Ee.Script||r.type===Ee.Style}var z2=Ee.Root,j2=Ee.Text,H2=Ee.Directive,W2=Ee.Comment,V2=Ee.Script,G2=Ee.Style,q2=Ee.Tag,K2=Ee.CDATA,X2=Ee.Doctype;var rl=class{constructor(){this.parent=null,this.prev=null,this.next=null,this.startIndex=null,this.endIndex=null}get parentNode(){return this.parent}set parentNode(e){this.parent=e}get previousSibling(){return this.prev}set previousSibling(e){this.prev=e}get nextSibling(){return this.next}set nextSibling(e){this.next=e}cloneNode(e=!1){return Z2(this,e)}},wa=class extends rl{constructor(e){super(),this.data=e}get nodeValue(){return this.data}set nodeValue(e){this.data=e}},Ki=class extends wa{constructor(){super(...arguments),this.type=Ee.Text}get nodeType(){return 3}},xa=class extends wa{constructor(){super(...arguments),this.type=Ee.Comment}get nodeType(){return 8}},Sa=class extends wa{constructor(e,t){super(t),this.name=e,this.type=Ee.Directive}get nodeType(){return 1}},Ea=class extends rl{constructor(e){super(),this.children=e}get firstChild(){var e;return(e=this.children[0])!==null&&e!==void 0?e:null}get lastChild(){return this.children.length>0?this.children[this.children.length-1]:null}get childNodes(){return this.children}set childNodes(e){this.children=e}},Aa=class extends Ea{constructor(){super(...arguments),this.type=Ee.CDATA}get nodeType(){return 4}},Xi=class extends Ea{constructor(){super(...arguments),this.type=Ee.Root}get nodeType(){return 9}},Ta=class extends Ea{constructor(e,t,n=[],i=e==="script"?Ee.Script:e==="style"?Ee.Style:Ee.Tag){super(n),this.name=e,this.attribs=t,this.type=i}get nodeType(){return 1}get tagName(){return this.name}set tagName(e){this.name=e}get attributes(){return Object.keys(this.attribs).map(e=>{var t,n;return{name:e,value:this.attribs[e],namespace:(t=this["x-attribsNamespace"])===null||t===void 0?void 0:t[e],prefix:(n=this["x-attribsPrefix"])===null||n===void 0?void 0:n[e]}})}};function Qr(r){return U2(r)}function vp(r){return r.type===Ee.CDATA}function nl(r){return r.type===Ee.Text}function wp(r){return r.type===Ee.Comment}function v8(r){return r.type===Ee.Directive}function Q2(r){return r.type===Ee.Root}function Z2(r,e=!1){let t;if(nl(r))t=new Ki(r.data);else if(wp(r))t=new xa(r.data);else if(Qr(r)){let n=e?yp(r.children):[],i=new Ta(r.name,{...r.attribs},n);n.forEach(s=>s.parent=i),r.namespace!=null&&(i.namespace=r.namespace),r["x-attribsNamespace"]&&(i["x-attribsNamespace"]={...r["x-attribsNamespace"]}),r["x-attribsPrefix"]&&(i["x-attribsPrefix"]={...r["x-attribsPrefix"]}),t=i}else if(vp(r)){let n=e?yp(r.children):[],i=new Aa(n);n.forEach(s=>s.parent=i),t=i}else if(Q2(r)){let n=e?yp(r.children):[],i=new Xi(n);n.forEach(s=>s.parent=i),r["x-mode"]&&(i["x-mode"]=r["x-mode"]),t=i}else if(v8(r)){let n=new Sa(r.name,r.data);r["x-name"]!=null&&(n["x-name"]=r["x-name"],n["x-publicId"]=r["x-publicId"],n["x-systemId"]=r["x-systemId"]),t=n}else throw new Error(`Not implemented yet: ${r.type}`);return t.startIndex=r.startIndex,t.endIndex=r.endIndex,r.sourceCodeLocation!=null&&(t.sourceCodeLocation=r.sourceCodeLocation),t}function yp(r){let e=r.map(t=>Z2(t,!0));for(let t=1;t<e.length;t++)e[t].prev=e[t-1],e[t-1].next=e[t];return e}var J2={withStartIndices:!1,withEndIndices:!1,xmlMode:!1},Yi=class{constructor(e,t,n){this.dom=[],this.root=new Xi(this.dom),this.done=!1,this.tagStack=[this.root],this.lastNode=null,this.parser=null,typeof t=="function"&&(n=t,t=J2),typeof e=="object"&&(t=e,e=void 0),this.callback=e??null,this.options=t??J2,this.elementCB=n??null}onparserinit(e){this.parser=e}onreset(){this.dom=[],this.root=new Xi(this.dom),this.done=!1,this.tagStack=[this.root],this.lastNode=null,this.parser=null}onend(){this.done||(this.done=!0,this.parser=null,this.handleCallback(null))}onerror(e){this.handleCallback(e)}onclosetag(){this.lastNode=null;let e=this.tagStack.pop();this.options.withEndIndices&&(e.endIndex=this.parser.endIndex),this.elementCB&&this.elementCB(e)}onopentag(e,t){let n=this.options.xmlMode?Ee.Tag:void 0,i=new Ta(e,t,void 0,n);this.addNode(i),this.tagStack.push(i)}ontext(e){let{lastNode:t}=this;if(t&&t.type===Ee.Text)t.data+=e,this.options.withEndIndices&&(t.endIndex=this.parser.endIndex);else{let n=new Ki(e);this.addNode(n),this.lastNode=n}}oncomment(e){if(this.lastNode&&this.lastNode.type===Ee.Comment){this.lastNode.data+=e;return}let t=new xa(e);this.addNode(t),this.lastNode=t}oncommentend(){this.lastNode=null}oncdatastart(){let e=new Ki(""),t=new Aa([e]);this.addNode(t),e.parent=t,this.lastNode=e}oncdataend(){this.lastNode=null}onprocessinginstruction(e,t){let n=new Sa(e,t);this.addNode(n)}handleCallback(e){if(typeof this.callback=="function")this.callback(e,this.dom);else if(e)throw e}addNode(e){let t=this.tagStack[this.tagStack.length-1],n=t.children[t.children.length-1];this.options.withStartIndices&&(e.startIndex=this.parser.startIndex),this.options.withEndIndices&&(e.endIndex=this.parser.endIndex),t.children.push(e),n&&(e.prev=n,n.next=e),e.parent=t,this.lastNode=null}};var w8=/\n/g;function x8(r){let e=[...r.matchAll(w8)].map((n=>n.index||0));e.unshift(-1);let t=xp(e,0,e.length);return n=>tS(t,n)}function xp(r,e,t){if(t-e==1)return{offset:r[e],index:e+1};let n=Math.ceil((e+t)/2),i=xp(r,e,n),s=xp(r,n,t);return{offset:i.offset,low:i,high:s}}function tS(r,e){return(function(t){return Object.prototype.hasOwnProperty.call(t,"index")})(r)?{line:r.index,column:e-r.offset}:tS(r.high.offset<e?r.high:r.low,e)}function Sp(r,e="",t={}){let n=typeof e!="string"?e:t,i=typeof e=="string"?e:"",s=r.map(S8),a=!!n.lineNumbers;return function(o,u=0){let l=a?x8(o):()=>({line:0,column:0}),c=u,h=[];e:for(;c<o.length;){let d=!1;for(let f of s){f.regex.lastIndex=c;let p=f.regex.exec(o);if(p&&p[0].length>0){if(!f.discard){let g=l(c),b=typeof f.replace=="string"?p[0].replace(new RegExp(f.regex.source,f.regex.flags),f.replace):p[0];h.push({state:i,name:f.name,text:b,offset:c,len:p[0].length,line:g.line,column:g.column})}if(c=f.regex.lastIndex,d=!0,f.push){let g=f.push(o,c);h.push(...g.tokens),c=g.offset}if(f.pop)break e;break}}if(!d)break}return{tokens:h,offset:c,complete:o.length<=c}}}function S8(r,e){return{...r,regex:E8(r,e)}}function E8(r,e){if(r.name.length===0)throw new Error(`Rule #${e} has empty name, which is not allowed.`);if((function(t){return Object.prototype.hasOwnProperty.call(t,"regex")})(r))return(function(t){if(t.global)throw new Error(`Regular expression /${t.source}/${t.flags} contains the global flag, which is not allowed.`);return t.sticky?t:new RegExp(t.source,t.flags+"y")})(r.regex);if((function(t){return Object.prototype.hasOwnProperty.call(t,"str")})(r)){if(r.str.length===0)throw new Error(`Rule #${e} ("${r.name}") has empty "str" property, which is not allowed.`);return new RegExp(eS(r.str),"y")}return new RegExp(eS(r.name),"y")}function eS(r){return r.replace(/[-[\]{}()*+!<=:?./\\^$|#\s,]/g,"\\$&")}function Lr(r,e){return(t,n)=>{let i=n,s;return n<t.tokens.length?(s=r(t.tokens[n],t,n),s!==void 0&&i++):e?.(t,n),s===void 0?{matched:!1}:{matched:!0,position:i,value:s}}}function Ep(r,e){return r.matched?{matched:!0,position:r.position,value:e(r.value,r.position)}:r}function il(r,e){return r.matched?e(r):r}function pt(r,e){return(t,n)=>Ep(r(t,n),(i,s)=>e(i,t,n,s))}function _a(r,e){return(t,n)=>{let i=r(t,n);return i.matched?i:{matched:!0,position:n,value:e}}}function Qi(...r){return(e,t)=>{for(let n of r){let i=n(e,t);if(i.matched)return i}return{matched:!1}}}function xn(r,e){return(t,n)=>{let i=r(t,n);return i.matched?i:e(t,n)}}function A8(r,e){return(t,n)=>{let i=[],s=!0;do{let a=r(t,n);a.matched&&e(a.value,i.length+1,t,n,a.position)?(i.push(a.value),n=a.position):s=!1}while(s);return{matched:!0,position:n,value:i}}}function sl(r){return A8(r,()=>!0)}function rS(r){return wt(r,sl(r),(e,t)=>[e,...t])}function wt(r,e,t){return(n,i)=>il(r(n,i),s=>Ep(e(n,s.position),(a,o)=>t(s.value,a,n,i,o)))}function nS(r,e){return wt(r,e,t=>t)}function Ap(r,e){return wt(r,e,(t,n)=>n)}function al(r,e,t,n){return(i,s)=>il(r(i,s),a=>il(e(i,a.position),o=>Ep(t(i,o.position),(u,l)=>n(a.value,o.value,u,i,s,l))))}function Tp(r,e,t){return al(r,e,t,(n,i)=>i)}function T8(...r){return(e,t)=>{let n=[],i=t;for(let s of r){let a=s(e,i);if(a.matched)n.push(a.value),i=a.position;else return{matched:!1}}return{matched:!0,position:i,value:n}}}function iS(...r){return _8(T8(...r))}function _8(r){return pt(r,e=>e.flatMap(t=>t))}function C8(r,e){return(t,n)=>{let i=!0,s=r,a=n;do{let o=e(s,t,a)(t,a);o.matched?(s=o.value,a=o.position):i=!1}while(i);return{matched:!0,position:a,value:s}}}function k8(r,e,t){return C8(r,n=>pt(e,(i,s,a,o)=>t(n,i,s,a,o)))}function _p(r,e,t){return I8(r,n=>k8(n,wt(e,t,(i,s)=>[i,s]),(i,[s,a])=>s(i,a)))}function I8(r,e){return(t,n)=>il(r(t,n),i=>e(i.value,t,n,i.position)(t,i.position))}var P8="(?:[ \\t\\r\\n\\f]*)",cS="(?:\\n|\\r\\n|\\r|\\f)",ll="[^\\x00-\\x7F]",Ia="(?:\\\\[0-9a-f]{1,6}(?:\\r\\n|[ \\n\\r\\t\\f])?)",Ra="(?:\\\\[^\\n\\r\\f0-9a-f])",O8=`(?:[_a-z]|${ll}|${Ia}|${Ra})`,hS=`(?:[_a-z0-9-]|${ll}|${Ia}|${Ra})`,L8=`(?:${hS}+)`,N8=`(?:[-]?${O8}${hS}*)`,M8=`'([^\\n\\r\\f\\\\']|\\\\${cS}|${ll}|${Ia}|${Ra})*'`,B8=`"([^\\n\\r\\f\\\\"]|\\\\${cS}|${ll}|${Ia}|${Ra})*"`,D8=Sp([{name:"ws",regex:new RegExp(P8)},{name:"hash",regex:new RegExp(`#${L8}`,"i")},{name:"ident",regex:new RegExp(N8,"i")},{name:"str1",regex:new RegExp(M8,"i")},{name:"str2",regex:new RegExp(B8,"i")},{name:"*"},{name:"."},{name:","},{name:"["},{name:"]"},{name:"="},{name:">"},{name:"|"},{name:"+"},{name:"~"},{name:"^"},{name:"$"}]),F8=Sp([{name:"unicode",regex:new RegExp(Ia,"i")},{name:"escape",regex:new RegExp(Ra,"i")},{name:"any",regex:new RegExp("[\\s\\S]","i")}]);function dS([r,e,t],[n,i,s]){return[r+n,e+i,t+s]}function $8(r){return r.reduce(dS,[0,0,0])}var U8=Lr(r=>r.name==="unicode"?String.fromCodePoint(parseInt(r.text.slice(1),16)):void 0),z8=Lr(r=>r.name==="escape"?r.text.slice(1):void 0),j8=Lr(r=>r.name==="any"?r.text:void 0),H8=pt(sl(Qi(U8,z8,j8)),r=>r.join(""));function Ip(r){let e=F8(r);return H8({tokens:e.tokens,options:void 0},0).value}function $e(r){return Lr(e=>e.name===r?!0:void 0)}var Rp=Lr(r=>r.name==="ws"?null:void 0),Cp=_a(Rp,null);function Ji(r){return Tp(Cp,r,Cp)}var ka=Lr(r=>r.name==="ident"?Ip(r.text):void 0),W8=Lr(r=>r.name==="hash"?Ip(r.text.slice(1)):void 0),V8=Lr(r=>r.name.startsWith("str")?Ip(r.text.slice(1,-1)):void 0),fS=nS(_a(ka,""),$e("|")),Pp=xn(wt(fS,ka,(r,e)=>({name:e,namespace:r})),pt(ka,r=>({name:r,namespace:null}))),G8=xn(wt(fS,$e("*"),r=>({type:"universal",namespace:r,specificity:[0,0,0]})),pt($e("*"),()=>({type:"universal",namespace:null,specificity:[0,0,0]}))),q8=pt(Pp,({name:r,namespace:e})=>({type:"tag",name:r,namespace:e,specificity:[0,0,1]})),K8=wt($e("."),ka,(r,e)=>({type:"class",name:e,specificity:[0,1,0]})),X8=pt(W8,r=>({type:"id",name:r,specificity:[1,0,0]})),sS=Lr(r=>{if(r.name==="ident"){if(r.text==="i"||r.text==="I")return"i";if(r.text==="s"||r.text==="S")return"s"}}),Y8=xn(wt(V8,_a(Ap(Cp,sS),null),(r,e)=>({value:r,modifier:e})),wt(ka,_a(Ap(Rp,sS),null),(r,e)=>({value:r,modifier:e}))),Q8=Qi(pt($e("="),()=>"="),wt($e("~"),$e("="),()=>"~="),wt($e("|"),$e("="),()=>"|="),wt($e("^"),$e("="),()=>"^="),wt($e("$"),$e("="),()=>"$="),wt($e("*"),$e("="),()=>"*=")),Z8=al($e("["),Ji(Pp),$e("]"),(r,{name:e,namespace:t})=>({type:"attrPresence",name:e,namespace:t,specificity:[0,1,0]})),J8=Tp($e("["),al(Ji(Pp),Q8,Ji(Y8),({name:r,namespace:e},t,{value:n,modifier:i})=>({type:"attrValue",name:r,namespace:e,matcher:t,value:n,modifier:i,specificity:[0,1,0]})),$e("]")),eN=xn(Z8,J8),tN=xn(G8,q8),aS=Qi(X8,K8,eN),oS=pt(xn(iS(tN,sl(aS)),rS(aS)),r=>({type:"compound",list:r,specificity:$8(r.map(e=>e.specificity))})),rN=Qi(pt($e(">"),()=>">"),pt($e("+"),()=>"+"),pt($e("~"),()=>"~"),wt($e("|"),$e("|"),()=>"||")),nN=xn(Ji(rN),pt(Rp,()=>" ")),kp=_p(oS,pt(nN,r=>(e,t)=>({type:"compound",list:[...t.list,{type:"combinator",combinator:r,left:e,specificity:e.specificity}],specificity:dS(e.specificity,t.specificity)})),oS),x$=_p(pt(kp,r=>({type:"list",list:[r]})),pt(Ji($e(",")),()=>(r,e)=>({type:"list",list:[...r.list,e]})),kp);function iN(r,e){if(!(typeof e=="string"||e instanceof String))throw new Error("Expected a selector string. Actual input is not a string!");let t=D8(e);if(!t.complete)throw new Error(`The input "${e}" was only partially tokenized, stopped at offset ${t.offset}!
|
|
@@ -225,5 +227,5 @@ ${m||" (No matches found)"}`}).join(`
|
|
|
225
227
|
===
|
|
226
228
|
|
|
227
229
|
`)}`,g=await _s({content:p,systemPrompt:pF,maxTokens:2048});if(g)return{queries:i,booksSearched:l,samplingUsed:!0,comparison:g}}return{queries:i,booksSearched:l,samplingUsed:!1,results:c}}function s_(){ke("compare_across_books","Compare how different books discuss the same topics. Provide 1-5 queries and optionally limit to specific books. With sampling: returns AI-synthesized comparison. Without sampling: returns match counts and top passages per query per book.",gF,bF)}var vF=/^orsk-[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;function Me(r){process.stderr.write(`[openread-mcp] ${r}
|
|
228
|
-
`)}function wF(){Me(""),Me("ERROR: OPENREAD_API_KEY environment variable is not set."),Me(""),Me("To get your API key:"),Me(" 1. Open Openread (app.openread.ai)"),Me(" 2. Go to Settings > API Keys"),Me(' 3. Click "Create API Key"'),Me(" 4. Copy the orsk-... key"),Me(""),Me("Then set it in your AI client config:"),Me(" {"),Me(' "mcpServers": {'),Me(' "openread": {'),Me(' "command": "npx",'),Me(' "args": ["-y", "@openread/mcp"],'),Me(' "env": { "OPENREAD_API_KEY": "orsk-..." }'),Me(" }"),Me(" }"),Me(" }"),Me("")}function xF(){let r=process.env.OPENREAD_API_KEY;return r||(wF(),process.exit(1)),vF.test(r)||(Me(`ERROR: Invalid API key format. Expected "orsk-{uuid}", got a ${r.length}-character string starting with "${r.slice(0,5)}..."`),process.exit(1)),r}function SF(){kT(),IT(),RT(),LT(),NT(),UT(),GT(),KT(),XT(),YT(),QT(),ZT(),t_(),n_(),s_()}async function EF(){
|
|
229
|
-
`),process.exit(0)
|
|
230
|
+
`)}function wF(){Me(""),Me("ERROR: OPENREAD_API_KEY environment variable is not set."),Me(""),Me("To get your API key:"),Me(" 1. Open Openread (app.openread.ai)"),Me(" 2. Go to Settings > API Keys"),Me(' 3. Click "Create API Key"'),Me(" 4. Copy the orsk-... key"),Me(""),Me("Then set it in your AI client config:"),Me(" {"),Me(' "mcpServers": {'),Me(' "openread": {'),Me(' "command": "npx",'),Me(' "args": ["-y", "@openread/mcp"],'),Me(' "env": { "OPENREAD_API_KEY": "orsk-..." }'),Me(" }"),Me(" }"),Me(" }"),Me("")}function xF(){let r=process.env.OPENREAD_API_KEY;return r||(wF(),process.exit(1)),vF.test(r)||(Me(`ERROR: Invalid API key format. Expected "orsk-{uuid}", got a ${r.length}-character string starting with "${r.slice(0,5)}..."`),process.exit(1)),r}function SF(){kT(),IT(),RT(),LT(),NT(),UT(),GT(),KT(),XT(),YT(),QT(),ZT(),t_(),n_(),s_()}async function EF(){(process.argv.includes("--version")||process.argv.includes("-v"))&&(process.stdout.write(`0.0.1-test.3
|
|
231
|
+
`),process.exit(0));let r=xF();Me("Starting OpenRead MCP server..."),Me("Authenticating...");let e=new Wo(r);try{await e.initialize(),Me(`Authenticated as ${e.getUserId()}`)}catch(o){o instanceof Error&&Me(`Authentication failed: ${o.message}`),process.exit(1)}let t=new uh,n=new ch(e,t),i=new hh(e.getSupabaseClient());eb({userId:e.getUserId(),bookData:i,loadBook:(o,u,l)=>n.loadBook(o,l??"epub"),requestId:"cli"}),SF();let s=gi(),a=new yF;await s.connect(a),ET({authManager:e,diskCache:t,transport:a}),Me("MCP server ready. Waiting for requests...")}var AF=typeof process<"u"&&!process.env.VITEST;AF&&EF().catch(r=>{Me(`Fatal error: ${r instanceof Error?r.message:String(r)}`),process.exit(1)});export{vF as API_KEY_PATTERN,Me as log,EF as main,wF as printSetupInstructions,SF as registerAllTools,xF as validateApiKey};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openread/mcp",
|
|
3
|
-
"version": "0.0.1-test.
|
|
3
|
+
"version": "0.0.1-test.3",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "MCP server for Openread - access your book library from AI assistants",
|
|
6
6
|
"keywords": ["mcp", "openread", "books", "ebook", "ai", "claude", "cursor"],
|