rmapi-js 3.0.0 → 3.0.1

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.
@@ -1,12 +1,12 @@
1
- var Yt=Object.create;var ee=Object.defineProperty;var Zt=Object.getOwnPropertyDescriptor;var Kt=Object.getOwnPropertyNames;var Wt=Object.getPrototypeOf,Qt=Object.prototype.hasOwnProperty;var y=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Xt=(e,t)=>{for(var r in t)ee(e,r,{get:t[r],enumerable:!0})},ze=(e,t,r,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of Kt(t))!Qt.call(e,n)&&n!==r&&ee(e,n,{get:()=>t[n],enumerable:!(i=Zt(t,n))||i.enumerable});return e};var te=(e,t,r)=>(r=e!=null?Yt(Wt(e)):{},ze(t||!e||!e.__esModule?ee(r,"default",{value:e,enumerable:!0}):r,e)),er=e=>ze(ee({},"__esModule",{value:!0}),e);var Ye=y(re=>{"use strict";re.byteLength=rr;re.toByteArray=ir;re.fromByteArray=sr;var M=[],O=[],tr=typeof Uint8Array<"u"?Uint8Array:Array,Me="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(D=0,Ge=Me.length;D<Ge;++D)M[D]=Me[D],O[Me.charCodeAt(D)]=D;var D,Ge;O["-".charCodeAt(0)]=62;O["_".charCodeAt(0)]=63;function Ve(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var i=r===t?0:4-r%4;return[r,i]}function rr(e){var t=Ve(e),r=t[0],i=t[1];return(r+i)*3/4-i}function nr(e,t,r){return(t+r)*3/4-r}function ir(e){var t,r=Ve(e),i=r[0],n=r[1],a=new tr(nr(e,i,n)),o=0,f=n>0?i-4:i,s;for(s=0;s<f;s+=4)t=O[e.charCodeAt(s)]<<18|O[e.charCodeAt(s+1)]<<12|O[e.charCodeAt(s+2)]<<6|O[e.charCodeAt(s+3)],a[o++]=t>>16&255,a[o++]=t>>8&255,a[o++]=t&255;return n===2&&(t=O[e.charCodeAt(s)]<<2|O[e.charCodeAt(s+1)]>>4,a[o++]=t&255),n===1&&(t=O[e.charCodeAt(s)]<<10|O[e.charCodeAt(s+1)]<<4|O[e.charCodeAt(s+2)]>>2,a[o++]=t>>8&255,a[o++]=t&255),a}function ar(e){return M[e>>18&63]+M[e>>12&63]+M[e>>6&63]+M[e&63]}function or(e,t,r){for(var i,n=[],a=t;a<r;a+=3)i=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),n.push(ar(i));return n.join("")}function sr(e){for(var t,r=e.length,i=r%3,n=[],a=16383,o=0,f=r-i;o<f;o+=a)n.push(or(e,o,o+a>f?f:o+a));return i===1?(t=e[r-1],n.push(M[t>>2]+M[t<<4&63]+"==")):i===2&&(t=(e[r-2]<<8)+e[r-1],n.push(M[t>>10]+M[t>>4&63]+M[t<<2&63]+"=")),n.join("")}});var Xe=y((Wn,Qe)=>{"use strict";var ne,l,Ze={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
2
- `,r:"\r",t:" "},Se;function B(e){throw{name:"SyntaxError",message:e,at:ne,text:Se}}function d(e){return e&&e!==l&&B("Expected '"+e+"' instead of '"+l+"'"),l=Se.charAt(ne),ne+=1,l}function Ke(){var e,t="";for(l==="-"&&(t="-",d("-"));l>="0"&&l<="9";)t+=l,d();if(l===".")for(t+=".";d()&&l>="0"&&l<="9";)t+=l;if(l==="e"||l==="E")for(t+=l,d(),(l==="-"||l==="+")&&(t+=l,d());l>="0"&&l<="9";)t+=l,d();return e=Number(t),isFinite(e)||B("Bad number"),e}function We(){var e,t,r="",i;if(l==='"')for(;d();){if(l==='"')return d(),r;if(l==="\\")if(d(),l==="u"){for(i=0,t=0;t<4&&(e=parseInt(d(),16),!!isFinite(e));t+=1)i=i*16+e;r+=String.fromCharCode(i)}else if(typeof Ze[l]=="string")r+=Ze[l];else break;else r+=l}B("Bad string")}function k(){for(;l&&l<=" ";)d()}function fr(){switch(l){case"t":return d("t"),d("r"),d("u"),d("e"),!0;case"f":return d("f"),d("a"),d("l"),d("s"),d("e"),!1;case"n":return d("n"),d("u"),d("l"),d("l"),null;default:B("Unexpected '"+l+"'")}}function ur(){var e=[];if(l==="["){if(d("["),k(),l==="]")return d("]"),e;for(;l;){if(e.push(ie()),k(),l==="]")return d("]"),e;d(","),k()}}B("Bad array")}function lr(){var e,t={};if(l==="{"){if(d("{"),k(),l==="}")return d("}"),t;for(;l;){if(e=We(),k(),d(":"),Object.prototype.hasOwnProperty.call(t,e)&&B('Duplicate key "'+e+'"'),t[e]=ie(),k(),l==="}")return d("}"),t;d(","),k()}}B("Bad object")}function ie(){switch(k(),l){case"{":return lr();case"[":return ur();case'"':return We();case"-":return Ke();default:return l>="0"&&l<="9"?Ke():fr()}}Qe.exports=function(e,t){var r;return Se=e,ne=0,l=" ",r=ie(),k(),l&&B("Syntax error"),typeof t=="function"?function i(n,a){var o,f,s=n[a];if(s&&typeof s=="object")for(o in ie)Object.prototype.hasOwnProperty.call(s,o)&&(f=i(s,o),typeof f>"u"?delete s[o]:s[o]=f);return t.call(n,a,s)}({"":r},""):r}});var tt=y((Qn,et)=>{"use strict";var ke=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,_,ae,cr={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},q;function Fe(e){return ke.lastIndex=0,ke.test(e)?'"'+e.replace(ke,function(t){var r=cr[t];return typeof r=="string"?r:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function oe(e,t){var r,i,n,a,o=_,f,s=t[e];switch(s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON(e)),typeof q=="function"&&(s=q.call(t,e,s)),typeof s){case"string":return Fe(s);case"number":return isFinite(s)?String(s):"null";case"boolean":case"null":return String(s);case"object":if(!s)return"null";if(_+=ae,f=[],Object.prototype.toString.apply(s)==="[object Array]"){for(a=s.length,r=0;r<a;r+=1)f[r]=oe(r,s)||"null";return n=f.length===0?"[]":_?`[
3
- `+_+f.join(`,
4
- `+_)+`
5
- `+o+"]":"["+f.join(",")+"]",_=o,n}if(q&&typeof q=="object")for(a=q.length,r=0;r<a;r+=1)i=q[r],typeof i=="string"&&(n=oe(i,s),n&&f.push(Fe(i)+(_?": ":":")+n));else for(i in s)Object.prototype.hasOwnProperty.call(s,i)&&(n=oe(i,s),n&&f.push(Fe(i)+(_?": ":":")+n));return n=f.length===0?"{}":_?`{
6
- `+_+f.join(`,
7
- `+_)+`
8
- `+o+"}":"{"+f.join(",")+"}",_=o,n;default:}}et.exports=function(e,t,r){var i;if(_="",ae="",typeof r=="number")for(i=0;i<r;i+=1)ae+=" ";else typeof r=="string"&&(ae=r);if(q=t,t&&typeof t!="function"&&(typeof t!="object"||typeof t.length!="number"))throw new Error("JSON.stringify");return oe("",{"":e})}});var rt=y(Ce=>{"use strict";Ce.parse=Xe();Ce.stringify=tt()});var it=y((ei,nt)=>{"use strict";var se=typeof JSON<"u"?JSON:rt(),dr=Array.isArray||function(e){return{}.toString.call(e)==="[object Array]"},pr=Object.keys||function(e){var t=Object.prototype.hasOwnProperty||function(){return!0},r=[];for(var i in e)t.call(e,i)&&r.push(i);return r};nt.exports=function(e,t){t||(t={}),typeof t=="function"&&(t={cmp:t});var r=t.space||"";typeof r=="number"&&(r=Array(r+1).join(" "));var i=typeof t.cycles=="boolean"?t.cycles:!1,n=t.replacer||function(f,s){return s},a=t.cmp&&function(f){return function(s){return function(c,u){var g={key:c,value:s[c]},p={key:u,value:s[u]};return f(g,p)}}}(t.cmp),o=[];return function f(s,c,u,g){var p=r?`
9
- `+new Array(g+1).join(r):"",C=r?": ":":";if(u&&u.toJSON&&typeof u.toJSON=="function"&&(u=u.toJSON()),u=n.call(s,c,u),u!==void 0){if(typeof u!="object"||u===null)return se.stringify(u);if(dr(u)){for(var T=[],h=0;h<u.length;h++){var V=f(u,h,u[h],g+1)||se.stringify(null);T.push(p+r+V)}return"["+T.join(",")+p+"]"}if(o.indexOf(u)!==-1){if(i)return se.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}else o.push(u);for(var E=pr(u).sort(a&&a(u)),T=[],h=0;h<E.length;h++){var c=E[h],v=f(u,c,u[c],g+1);if(v){var X=se.stringify(c)+C+v;T.push(p+r+X)}}return o.splice(o.indexOf(u),1),"{"+T.join(",")+p+"}"}}({"":e},"",e,0)}});var Re=y(Be=>{"use strict";Object.defineProperty(Be,"__esModule",{value:!0});Be.default=gr;var yr=mr(require("crypto"));function mr(e){return e&&e.__esModule?e:{default:e}}var ue=new Uint8Array(256),fe=ue.length;function gr(){return fe>ue.length-16&&(yr.default.randomFillSync(ue),fe=0),ue.slice(fe,fe+=16)}});var at=y(le=>{"use strict";Object.defineProperty(le,"__esModule",{value:!0});le.default=void 0;var hr=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;le.default=hr});var Z=y(ce=>{"use strict";Object.defineProperty(ce,"__esModule",{value:!0});ce.default=void 0;var vr=br(at());function br(e){return e&&e.__esModule?e:{default:e}}function wr(e){return typeof e=="string"&&vr.default.test(e)}var xr=wr;ce.default=xr});var W=y(K=>{"use strict";Object.defineProperty(K,"__esModule",{value:!0});K.default=void 0;K.unsafeStringify=ot;var Pr=_r(Z());function _r(e){return e&&e.__esModule?e:{default:e}}var b=[];for(let e=0;e<256;++e)b.push((e+256).toString(16).slice(1));function ot(e,t=0){return(b[e[t+0]]+b[e[t+1]]+b[e[t+2]]+b[e[t+3]]+"-"+b[e[t+4]]+b[e[t+5]]+"-"+b[e[t+6]]+b[e[t+7]]+"-"+b[e[t+8]]+b[e[t+9]]+"-"+b[e[t+10]]+b[e[t+11]]+b[e[t+12]]+b[e[t+13]]+b[e[t+14]]+b[e[t+15]]).toLowerCase()}function Er(e,t=0){let r=ot(e,t);if(!(0,Pr.default)(r))throw TypeError("Stringified UUID is invalid");return r}var Or=Er;K.default=Or});var ft=y(de=>{"use strict";Object.defineProperty(de,"__esModule",{value:!0});de.default=void 0;var Tr=Mr(Re()),Ar=W();function Mr(e){return e&&e.__esModule?e:{default:e}}var st,Ie,De=0,qe=0;function Sr(e,t,r){let i=t&&r||0,n=t||new Array(16);e=e||{};let a=e.node||st,o=e.clockseq!==void 0?e.clockseq:Ie;if(a==null||o==null){let p=e.random||(e.rng||Tr.default)();a==null&&(a=st=[p[0]|1,p[1],p[2],p[3],p[4],p[5]]),o==null&&(o=Ie=(p[6]<<8|p[7])&16383)}let f=e.msecs!==void 0?e.msecs:Date.now(),s=e.nsecs!==void 0?e.nsecs:qe+1,c=f-De+(s-qe)/1e4;if(c<0&&e.clockseq===void 0&&(o=o+1&16383),(c<0||f>De)&&e.nsecs===void 0&&(s=0),s>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");De=f,qe=s,Ie=o,f+=122192928e5;let u=((f&268435455)*1e4+s)%4294967296;n[i++]=u>>>24&255,n[i++]=u>>>16&255,n[i++]=u>>>8&255,n[i++]=u&255;let g=f/4294967296*1e4&268435455;n[i++]=g>>>8&255,n[i++]=g&255,n[i++]=g>>>24&15|16,n[i++]=g>>>16&255,n[i++]=o>>>8|128,n[i++]=o&255;for(let p=0;p<6;++p)n[i+p]=a[p];return t||(0,Ar.unsafeStringify)(n)}var kr=Sr;de.default=kr});var Ne=y(pe=>{"use strict";Object.defineProperty(pe,"__esModule",{value:!0});pe.default=void 0;var Fr=Cr(Z());function Cr(e){return e&&e.__esModule?e:{default:e}}function Br(e){if(!(0,Fr.default)(e))throw TypeError("Invalid UUID");let t,r=new Uint8Array(16);return r[0]=(t=parseInt(e.slice(0,8),16))>>>24,r[1]=t>>>16&255,r[2]=t>>>8&255,r[3]=t&255,r[4]=(t=parseInt(e.slice(9,13),16))>>>8,r[5]=t&255,r[6]=(t=parseInt(e.slice(14,18),16))>>>8,r[7]=t&255,r[8]=(t=parseInt(e.slice(19,23),16))>>>8,r[9]=t&255,r[10]=(t=parseInt(e.slice(24,36),16))/1099511627776&255,r[11]=t/4294967296&255,r[12]=t>>>24&255,r[13]=t>>>16&255,r[14]=t>>>8&255,r[15]=t&255,r}var Rr=Br;pe.default=Rr});var je=y(N=>{"use strict";Object.defineProperty(N,"__esModule",{value:!0});N.URL=N.DNS=void 0;N.default=jr;var Ir=W(),Dr=qr(Ne());function qr(e){return e&&e.__esModule?e:{default:e}}function Nr(e){e=unescape(encodeURIComponent(e));let t=[];for(let r=0;r<e.length;++r)t.push(e.charCodeAt(r));return t}var ut="6ba7b810-9dad-11d1-80b4-00c04fd430c8";N.DNS=ut;var lt="6ba7b811-9dad-11d1-80b4-00c04fd430c8";N.URL=lt;function jr(e,t,r){function i(n,a,o,f){var s;if(typeof n=="string"&&(n=Nr(n)),typeof a=="string"&&(a=(0,Dr.default)(a)),((s=a)===null||s===void 0?void 0:s.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+n.length);if(c.set(a),c.set(n,a.length),c=r(c),c[6]=c[6]&15|t,c[8]=c[8]&63|128,o){f=f||0;for(let u=0;u<16;++u)o[f+u]=c[u];return o}return(0,Ir.unsafeStringify)(c)}try{i.name=e}catch{}return i.DNS=ut,i.URL=lt,i}});var ct=y(ye=>{"use strict";Object.defineProperty(ye,"__esModule",{value:!0});ye.default=void 0;var Lr=$r(require("crypto"));function $r(e){return e&&e.__esModule?e:{default:e}}function Ur(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),Lr.default.createHash("md5").update(e).digest()}var Hr=Ur;ye.default=Hr});var pt=y(me=>{"use strict";Object.defineProperty(me,"__esModule",{value:!0});me.default=void 0;var Jr=dt(je()),zr=dt(ct());function dt(e){return e&&e.__esModule?e:{default:e}}var Gr=(0,Jr.default)("v3",48,zr.default),Vr=Gr;me.default=Vr});var yt=y(ge=>{"use strict";Object.defineProperty(ge,"__esModule",{value:!0});ge.default=void 0;var Yr=Zr(require("crypto"));function Zr(e){return e&&e.__esModule?e:{default:e}}var Kr={randomUUID:Yr.default.randomUUID};ge.default=Kr});var ht=y(he=>{"use strict";Object.defineProperty(he,"__esModule",{value:!0});he.default=void 0;var mt=gt(yt()),Wr=gt(Re()),Qr=W();function gt(e){return e&&e.__esModule?e:{default:e}}function Xr(e,t,r){if(mt.default.randomUUID&&!t&&!e)return mt.default.randomUUID();e=e||{};let i=e.random||(e.rng||Wr.default)();if(i[6]=i[6]&15|64,i[8]=i[8]&63|128,t){r=r||0;for(let n=0;n<16;++n)t[r+n]=i[n];return t}return(0,Qr.unsafeStringify)(i)}var en=Xr;he.default=en});var vt=y(ve=>{"use strict";Object.defineProperty(ve,"__esModule",{value:!0});ve.default=void 0;var tn=rn(require("crypto"));function rn(e){return e&&e.__esModule?e:{default:e}}function nn(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),tn.default.createHash("sha1").update(e).digest()}var an=nn;ve.default=an});var wt=y(be=>{"use strict";Object.defineProperty(be,"__esModule",{value:!0});be.default=void 0;var on=bt(je()),sn=bt(vt());function bt(e){return e&&e.__esModule?e:{default:e}}var fn=(0,on.default)("v5",80,sn.default),un=fn;be.default=un});var xt=y(we=>{"use strict";Object.defineProperty(we,"__esModule",{value:!0});we.default=void 0;var ln="00000000-0000-0000-0000-000000000000";we.default=ln});var Pt=y(xe=>{"use strict";Object.defineProperty(xe,"__esModule",{value:!0});xe.default=void 0;var cn=dn(Z());function dn(e){return e&&e.__esModule?e:{default:e}}function pn(e){if(!(0,cn.default)(e))throw TypeError("Invalid UUID");return parseInt(e.slice(14,15),16)}var yn=pn;xe.default=yn});var _t=y(A=>{"use strict";Object.defineProperty(A,"__esModule",{value:!0});Object.defineProperty(A,"NIL",{enumerable:!0,get:function(){return bn.default}});Object.defineProperty(A,"parse",{enumerable:!0,get:function(){return _n.default}});Object.defineProperty(A,"stringify",{enumerable:!0,get:function(){return Pn.default}});Object.defineProperty(A,"v1",{enumerable:!0,get:function(){return mn.default}});Object.defineProperty(A,"v3",{enumerable:!0,get:function(){return gn.default}});Object.defineProperty(A,"v4",{enumerable:!0,get:function(){return hn.default}});Object.defineProperty(A,"v5",{enumerable:!0,get:function(){return vn.default}});Object.defineProperty(A,"validate",{enumerable:!0,get:function(){return xn.default}});Object.defineProperty(A,"version",{enumerable:!0,get:function(){return wn.default}});var mn=F(ft()),gn=F(pt()),hn=F(ht()),vn=F(wt()),bn=F(xt()),wn=F(Pt()),xn=F(Z()),Pn=F(W()),_n=F(Ne());function F(e){return e&&e.__esModule?e:{default:e}}});var Ue=y(m=>{"use strict";var Tt=m&&m.__rest||function(e,t){var r={};for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&t.indexOf(i)<0&&(r[i]=e[i]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,i=Object.getOwnPropertySymbols(e);n<i.length;n++)t.indexOf(i[n])<0&&Object.prototype.propertyIsEnumerable.call(e,i[n])&&(r[i[n]]=e[i[n]]);return r};Object.defineProperty(m,"__esModule",{value:!0});m.isSchema=m.isValidSchema=m.isDiscriminatorForm=m.isValuesForm=m.isPropertiesForm=m.isElementsForm=m.isEnumForm=m.isTypeForm=m.isRefForm=m.isEmptyForm=void 0;function En(e){let{definitions:t,nullable:r,metadata:i}=e,n=Tt(e,["definitions","nullable","metadata"]);return Object.keys(n).length===0}m.isEmptyForm=En;function At(e){return"ref"in e}m.isRefForm=At;function On(e){return"type"in e}m.isTypeForm=On;function Mt(e){return"enum"in e}m.isEnumForm=Mt;function St(e){return"elements"in e}m.isElementsForm=St;function $e(e){return"properties"in e||"optionalProperties"in e}m.isPropertiesForm=$e;function kt(e){return"values"in e}m.isValuesForm=kt;function Ft(e){return"discriminator"in e}m.isDiscriminatorForm=Ft;function j(e,t){if(t===void 0&&(t=e),e.definitions!==void 0){if(t!==e)return!1;for(let r of Object.values(e.definitions))if(!j(r,t))return!1}if(At(e)&&!(e.ref in(t.definitions||{}))||Mt(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(St(e))return j(e.elements,t);if($e(e)){for(let r of Object.values(e.properties||{}))if(!j(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!j(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(kt(e))return j(e.values,t);if(Ft(e)){for(let r of Object.values(e.mapping))if(!j(r,t)||!$e(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}m.isValidSchema=j;var Tn=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],An=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function L(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let t=e,{definitions:r=void 0,nullable:i=void 0,metadata:n=void 0,ref:a=void 0,type:o=void 0,enum:f=void 0,elements:s=void 0,properties:c=void 0,optionalProperties:u=void 0,additionalProperties:g=void 0,values:p=void 0,discriminator:C=void 0,mapping:h=void 0}=t,V=Tt(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),E=[a!==void 0,o!==void 0,f!==void 0,s!==void 0,c!==void 0,u!==void 0,g!==void 0,p!==void 0,C!==void 0,h!==void 0],T=!1;for(let v of Tn)T=T||v.every((X,Y)=>X===E[Y]);if(!T)return!1;if(r!==void 0){if(typeof r!="object"||Array.isArray(r)||r===null)return!1;for(let v of Object.values(r))if(!L(v))return!1}if(i!==void 0&&typeof i!="boolean"||n!==void 0&&(typeof n!="object"||Array.isArray(n)||n===null)||a!==void 0&&typeof a!="string"||o!==void 0&&(typeof o!="string"||!An.includes(o))||f!==void 0&&(!Array.isArray(f)||!f.every(v=>typeof v=="string"))||s!==void 0&&!L(s))return!1;if(c!==void 0){if(typeof c!="object"||Array.isArray(c)||c===null)return!1;for(let v of Object.values(c))if(!L(v))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let v of Object.values(u))if(!L(v))return!1}if(g!==void 0&&typeof g!="boolean"||p!==void 0&&!L(p)||C!==void 0&&typeof C!="string")return!1;if(h!==void 0){if(typeof h!="object"||Array.isArray(h)||h===null)return!1;for(let v of Object.values(h))if(!L(v))return!1}return Object.keys(V).length===0}m.isSchema=L});var Ct=y(He=>{"use strict";Object.defineProperty(He,"__esModule",{value:!0});var Mn=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Sn(e){let t=e.match(Mn);if(t===null)return!1;let r=parseInt(t[1],10),i=parseInt(t[2],10),n=parseInt(t[3],10),a=parseInt(t[4],10),o=parseInt(t[5],10),f=parseInt(t[6],10);return!(i>12||n>kn(r,i)||a>23||o>59||f>60)}He.default=Sn;function kn(e,t){return t===2?Fn(e)?29:28:Cn[t]}function Fn(e){return e%4===0&&(e%100!==0||e%400===0)}var Cn=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Bt=y(R=>{"use strict";var Bn=R&&R.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(R,"__esModule",{value:!0});R.validate=R.MaxDepthExceededError=void 0;var Rn=Bn(Ct()),$=Ue(),_e=class extends Error{};R.MaxDepthExceededError=_e;var Ee=class extends Error{};function In(e,t,r){let i={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{J(i,e,t)}catch(n){if(!(n instanceof Ee))throw n}return i.errors}R.validate=In;function J(e,t,r,i){if(!(t.nullable&&r===null)){if($.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new _e;e.schemaTokens.push(["definitions",t.ref]),J(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if($.isTypeForm(t)){switch(w(e,"type"),t.type){case"boolean":typeof r!="boolean"&&x(e);break;case"float32":case"float64":typeof r!="number"&&x(e);break;case"int8":G(e,r,-128,127);break;case"uint8":G(e,r,0,255);break;case"int16":G(e,r,-32768,32767);break;case"uint16":G(e,r,0,65535);break;case"int32":G(e,r,-2147483648,2147483647);break;case"uint32":G(e,r,0,4294967295);break;case"string":typeof r!="string"&&x(e);break;case"timestamp":typeof r!="string"?x(e):Rn.default(r)||x(e);break}P(e)}else if($.isEnumForm(t))w(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&x(e),P(e);else if($.isElementsForm(t)){if(w(e,"elements"),Array.isArray(r))for(let[n,a]of r.entries())U(e,n.toString()),J(e,t.elements,a),H(e);else x(e);P(e)}else if($.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){w(e,"properties");for(let[n,a]of Object.entries(t.properties))w(e,n),r.hasOwnProperty(n)?(U(e,n),J(e,a,r[n]),H(e)):x(e),P(e);P(e)}if(t.optionalProperties!==void 0){w(e,"optionalProperties");for(let[n,a]of Object.entries(t.optionalProperties))w(e,n),r.hasOwnProperty(n)&&(U(e,n),J(e,a,r[n]),H(e)),P(e);P(e)}if(t.additionalProperties!==!0)for(let n of Object.keys(r)){let a=t.properties&&n in t.properties,o=t.optionalProperties&&n in t.optionalProperties;!a&&!o&&n!==i&&(U(e,n),x(e),H(e))}}else t.properties!==void 0?w(e,"properties"):w(e,"optionalProperties"),x(e),P(e);else if($.isValuesForm(t)){if(w(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[n,a]of Object.entries(r))U(e,n),J(e,t.values,a),H(e);else x(e);P(e)}else if($.isDiscriminatorForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r))if(r.hasOwnProperty(t.discriminator)){let n=r[t.discriminator];typeof n=="string"?n in t.mapping?(w(e,"mapping"),w(e,n),J(e,t.mapping[n],r,t.discriminator),P(e),P(e)):(w(e,"mapping"),U(e,t.discriminator),x(e),H(e),P(e)):(w(e,"discriminator"),U(e,t.discriminator),x(e),H(e),P(e))}else w(e,"discriminator"),x(e),P(e);else w(e,"discriminator"),x(e),P(e)}}function G(e,t,r,i){(typeof t!="number"||!Number.isInteger(t)||t<r||t>i)&&x(e)}function U(e,t){e.instanceTokens.push(t)}function H(e){e.instanceTokens.pop()}function w(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function P(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function x(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new Ee}});var It=y(I=>{"use strict";var Dn=I&&I.__createBinding||(Object.create?function(e,t,r,i){i===void 0&&(i=r),Object.defineProperty(e,i,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,i){i===void 0&&(i=r),e[i]=t[r]}),Rt=I&&I.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&Dn(t,e,r)};Object.defineProperty(I,"__esModule",{value:!0});Rt(Ue(),I);Rt(Bt(),I)});var Yn={};Xt(Yn,{GenerationError:()=>Ae,ResponseError:()=>z,builtinFontNames:()=>$n,builtinLineHeights:()=>zt,builtinMargins:()=>Jt,builtinTextScales:()=>Ht,builtinTools:()=>Ln,formatEntry:()=>Gt,parseEntry:()=>Vt,register:()=>Gn,remarkable:()=>Vn});module.exports=er(Yn);var Lt=te(Ye()),$t=te(it());var S=te(_t(),1),hi=S.default.v1,vi=S.default.v3,Pe=S.default.v4,bi=S.default.v5,wi=S.default.NIL,xi=S.default.version,Pi=S.default.validate,_i=S.default.stringify,Ei=S.default.parse;function Le(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}function Et(e){return new Uint8Array((e.match(/../g)??[]).map(t=>parseInt(t,16)))}function Ot(e){let t=0;for(let n of e)t+=n.length;let r=new Uint8Array(t),i=0;for(let n of e)r.set(n,i),i+=n.length;return r}var Dt=te(It());function Q(e,t){if((0,Dt.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var qt="3",Ut="https://webapp-prod.cloud.remarkable.engineering",qn="https://internal.cloud.remarkable.com",Nt="x-goog-generation",Nn="x-goog-if-generation-match",jn="x-goog-content-length-range",Ln=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],$n=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Ht={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},Jt={sm:50,md:125,rr:180,lg:200},zt={df:-1,md:100,lg:150,xl:200},Un={properties:{docID:{type:"string"},hash:{type:"string"}}},Hn={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},Oe={visibleName:{type:"string"},lastModified:{type:"string"}},Te={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},Jn={discriminator:"type",mapping:{CollectionType:{properties:Oe,optionalProperties:Te},DocumentType:{properties:Oe,optionalProperties:{...Te,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},jt={id:{type:"string"},hash:{type:"string"}},zn={discriminator:"type",mapping:{CollectionType:{properties:{...Oe,...jt},optionalProperties:Te},DocumentType:{properties:{...Oe,...jt,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...Te,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},z=class extends Error{constructor(r,i,n){super(n);this.status=r,this.statusText=i}},Ae=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function Gn(e,{deviceDesc:t="browser-chrome",uuid:r=Pe(),authHost:i=Ut,fetch:n=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let a=await n(`${i}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:t,deviceID:r})});if(a.ok)return await a.text();throw new z(a.status,a.statusText,"couldn't register api")}function Gt({hash:e,type:t,documentId:r,subfiles:i,size:n}){return`${e}:${t}:${r}:${i}:${n}
10
- `}function Vt(e){let[t,r,i,n,a]=e.split(":");if(t===void 0||r===void 0||i===void 0||n===void 0||a===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(r==="80000000")return{hash:t,type:r,documentId:i,subfiles:parseInt(n),size:BigInt(a)};if(r==="0"){if(n!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${n}`);return{hash:t,type:r,documentId:i,subfiles:0,size:BigInt(a)}}else throw new Error(`entries line contained invalid type: ${r}`)}var Je=class{#u;#s;#f;#r;#n;#e=new Map;#t=null;constructor(t,r,i,n,a,o){this.#u=t,this.#s=r,this.#f=i,this.#r=n,this.#n=a;for(let[f,s]of o)this.#e.set(f,Promise.resolve(s))}async#i(t,{body:r,method:i="POST",headers:n={}}){let a=await this.#s(t,{method:i,headers:{Authorization:`Bearer ${this.#u}`,...n},body:r});if(a.ok)return a;{let o=await a.text();throw new z(a.status,a.statusText,`failed reMarkable request: ${o}`)}}async#a({url:t,method:r,maxuploadsize_bytes:i},n,a={}){let o=i?{...a,[jn]:`0,${i}`}:a,f=await this.#s(t,{method:r,body:n,headers:o});if(f.ok)return f;{let s=await f.text();throw new z(f.status,f.statusText,s)}}async#o(t,r,i){let n=r===void 0?"downloads":"uploads",a=i&&r!==null&&r!==void 0?`{ "http_method": "PUT", "relative_path": "${t}", "root_schema": "${i}", "generation": ${r} }`:JSON.stringify({http_method:"GET",relative_path:t}),f=await(await this.#i(`${this.#r}/sync/v2/signed-urls/${n}`,{body:a})).text(),s=JSON.parse(f);return Q(Hn,s),s}async getRootHash({cache:t=!0}={}){if(t)for(;this.#t;)try{let[a,o]=await this.#t;return[a,o]}catch{}let r=(async()=>{try{let a=await this.#o("root"),o=await this.#a(a),f=o.headers.get(Nt);if(f)return[await o.text(),BigInt(f)];throw new Error("no generation header in root hash")}catch(a){throw this.#t=null,a}})();this.#t=r;let[i,n]=await r;return[i,n]}async putRootHash(t,r){let i=await this.#o("root",r,t),n;try{n=await this.#a(i,t,{[Nn]:`${r}`})}catch(f){throw f instanceof z&&f.status===412?(this.#t=null,new Ae):f}let a=n.headers.get(Nt);if(!a)throw new Error("no generation header in root hash");let o=BigInt(a);return this.#t=Promise.resolve([t,o]),o}async#l(t){let r=this.#e.get(t);for(;r;)try{let n=await r;if(n)return n;r=void 0}catch{r=this.#e.get(t)}let i=(async()=>{let n=await this.#o(t);return await(await this.#a(n)).arrayBuffer()})();return this.#e.set(t,i.then(n=>n.byteLength<this.#n?n:null,n=>{throw this.#e.delete(t),n})),await i}async getBuffer(t){let r=await this.#l(t);return r.byteLength<this.#n?r.slice(0):r}async getText(t){let r=await this.#l(t);return new TextDecoder().decode(r)}async getJson(t){let r=await this.getText(t);return JSON.parse(r)}async getMetadata(t){let r=await this.getJson(t);return Q(Jn,r),r}async getEntries(t){if(t===void 0){let[a]=await this.getRootHash({cache:!0});t=a}let r=await this.getText(t),[i,...n]=r.slice(0,-1).split(`
11
- `);if(i!==qt)throw new Error(`got unexpected schema version: ${i}`);return n.map(Vt)}async#c(t,r){let i=this.#e.get(t);if(i)try{await i;return}catch{}let n=(async()=>{try{let a=await this.#o(t,null);return await this.#a(a,r),r.byteLength<this.#n?r:null}catch(a){throw this.#e.delete(t),a}})();this.#e.set(t,n),await n}async putEntries(t,r){let i=new TextEncoder;r.sort((u,g)=>u.documentId.localeCompare(g.documentId));let n=Ot(r.map(u=>Et(u.hash))),a=await this.#f.digest("SHA-256",n),o=Le(a),f=r.map(Gt).join(""),s=`${qt}
12
- ${f}`,c=i.encode(s);return await this.#c(o,c),{hash:o,type:"80000000",documentId:t,subfiles:r.length,size:0n}}async putBuffer(t,r){let i=await this.#f.digest("SHA-256",r),n=Le(i);return await this.#c(n,r),{hash:n,type:"0",documentId:t,subfiles:0,size:BigInt(r.byteLength)}}async putText(t,r){let i=new TextEncoder;return await this.putBuffer(t,i.encode(r))}async putJson(t,r){return await this.putText(t,(0,$t.default)(r))}async putMetadata(t,r){return await this.putJson(`${t}.metadata`,r)}async putCollection(t,r=""){let i=Pe(),n=`${new Date().valueOf()}`,a=[],o={type:"CollectionType",visibleName:t,version:0,parent:r,synced:!0,lastModified:n};a.push(this.putMetadata(i,o)),a.push(this.putText(`${i}.content`,"{}"));let f=await Promise.all(a);return await this.putEntries(i,f)}async#d(t,r,i,n,a){if(a.fileType!==i)throw new Error(`internal error: fileTypes don't match: ${i}, ${a.fileType}`);let o=Pe(),f=`${new Date().valueOf()}`,s=[];s.push(this.putBuffer(`${o}.${i}`,r));let c={type:"DocumentType",visibleName:t,version:0,parent:n,synced:!0,lastModified:f};s.push(this.putMetadata(o,c)),s.push(this.putText(`${o}.content`,JSON.stringify(a)));let u=await Promise.all(s);return await this.putEntries(o,u)}async putEpub(t,r,{parent:i="",margins:n=125,orientation:a,textAlignment:o,textScale:f=1,lineHeight:s=-1,fontName:c="",cover:u="visited",lastTool:g}={}){let p={dummyDocument:!1,extraMetadata:{LastTool:g},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof s=="string"?zt[s]:s,margins:typeof n=="string"?Jt[n]:n,textScale:typeof f=="string"?Ht[f]:f,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:a,textAlignment:o,fontName:c};return await this.#d(t,r,"epub",i,p)}async putPdf(t,r,{parent:i="",orientation:n,cover:a="first",lastTool:o}={}){let f={dummyDocument:!1,extraMetadata:{LastTool:o},fileType:"pdf",pageCount:0,lastOpenedPage:0,lineHeight:-1,margins:125,textScale:1,pages:[],coverPageNumber:a==="first"?0:-1,formatVersion:1,orientation:n};return await this.#d(t,r,"pdf",i,f)}async syncComplete(t){let r=`{ "generation": ${t} }`;await this.#i(`${this.#r}/sync/v2/sync-complete`,{body:r})}async#p(t,r,i){let{hash:n}=await this.putEntries("",r),a=await this.putRootHash(n,t);if(i)try{return await this.syncComplete(a),!0}catch{return!1}else return!1}async create(t,{cache:r=!0,sync:i=!0}={}){let[n,a]=await this.getRootHash({cache:r}),o=await this.getEntries(n);return o.push(t),await this.#p(a,o,i)}async move(t,r,{cache:i=!0,sync:n=!0}={}){let[a,o]=await this.getRootHash({cache:i}),f=await this.getEntries(a);if(!(!r||r==="trash")){let E=f.find(Y=>Y.documentId===r);if(E){if(E.type!=="80000000")throw new Error(`destination id was a raw file: ${r}`)}else throw new Error(`destination id not found: ${r}`);let T=await this.getEntries(E.hash),[v]=T.filter(Y=>Y.documentId===`${r}.metadata`);if(!v)throw new Error(`destination id didn't have metadata: ${r}`);if((await this.getMetadata(v.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${r}`)}let s=f.findIndex(E=>E.documentId===t);if(s===-1)throw new Error(`document not found: ${t}`);let[c]=f.splice(s,1);if(c.type!=="80000000")throw new Error(`document was a raw file: ${t}`);let u=await this.getEntries(c.hash),g=u.findIndex(E=>E.documentId===`${t}.metadata`);if(g===-1)throw new Error(`document didn't have metadata: ${t}`);let[p]=u.splice(g,1),C=await this.getMetadata(p.hash);C.parent=r;let h=await this.putMetadata(t,C);u.push(h);let V=await this.putEntries(t,u);return f.push(V),await this.#p(o,f,n)}async getEntriesMetadata(){let r=await(await this.#i(`${this.#r}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),i=JSON.parse(r);return Q({elements:zn},i),i}async#y(t,r,i){let a=new TextEncoder().encode(JSON.stringify({file_name:t})),f=await(await this.#i(`${this.#r}/doc/v2/files`,{body:r,headers:{"content-type":i,"rm-meta":(0,Lt.fromByteArray)(a),"rm-source":"RoR-Browser"}})).text(),s=JSON.parse(f);return Q(Un,s),s}async uploadEpub(t,r){return await this.#y(t,r,"application/epub+zip")}async uploadPdf(t,r){return await this.#y(t,r,"application/pdf")}async getCache(){let t=[];for(let[n,a]of this.#e)t.push(a.then(o=>[n,o],()=>[n,null]));let r=await Promise.all(t),i=new Map;for(let[n,a]of r)a&&i.set(n,a);return i}};async function Vn(e,{fetch:t=globalThis.fetch,subtle:r=globalThis.crypto?.subtle,authHost:i=Ut,syncHost:n=qn,cacheLimitBytes:a=1048576,initCache:o=[]}={}){if(!r)throw new Error("subtle was missing, try specifying it manually");let f=await t(`${i}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!f.ok)throw new Error(`couldn't fetch auth token: ${f.statusText}`);let s=await f.text();return new Je(s,t,r,n,a,o)}0&&(module.exports={GenerationError,ResponseError,builtinFontNames,builtinLineHeights,builtinMargins,builtinTextScales,builtinTools,formatEntry,parseEntry,register,remarkable});
1
+ "use strict";var ft=Object.create;var Z=Object.defineProperty;var ut=Object.getOwnPropertyDescriptor;var lt=Object.getOwnPropertyNames;var ct=Object.getPrototypeOf,pt=Object.prototype.hasOwnProperty;var S=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),dt=(e,t)=>{for(var r in t)Z(e,r,{get:t[r],enumerable:!0})},xe=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of lt(t))!pt.call(e,i)&&i!==r&&Z(e,i,{get:()=>t[i],enumerable:!(n=ut(t,i))||n.enumerable});return e};var z=(e,t,r)=>(r=e!=null?ft(ct(e)):{},xe(t||!e||!e.__esModule?Z(r,"default",{value:e,enumerable:!0}):r,e)),yt=e=>xe(Z({},"__esModule",{value:!0}),e);var Te=S(K=>{"use strict";K.byteLength=ht;K.toByteArray=bt;K.fromByteArray=xt;var O=[],T=[],mt=typeof Uint8Array<"u"?Uint8Array:Array,ue="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(B=0,Ee=ue.length;B<Ee;++B)O[B]=ue[B],T[ue.charCodeAt(B)]=B;var B,Ee;T["-".charCodeAt(0)]=62;T["_".charCodeAt(0)]=63;function Pe(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function ht(e){var t=Pe(e),r=t[0],n=t[1];return(r+n)*3/4-n}function gt(e,t,r){return(t+r)*3/4-r}function bt(e){var t,r=Pe(e),n=r[0],i=r[1],o=new mt(gt(e,n,i)),a=0,f=i>0?n-4:n,s;for(s=0;s<f;s+=4)t=T[e.charCodeAt(s)]<<18|T[e.charCodeAt(s+1)]<<12|T[e.charCodeAt(s+2)]<<6|T[e.charCodeAt(s+3)],o[a++]=t>>16&255,o[a++]=t>>8&255,o[a++]=t&255;return i===2&&(t=T[e.charCodeAt(s)]<<2|T[e.charCodeAt(s+1)]>>4,o[a++]=t&255),i===1&&(t=T[e.charCodeAt(s)]<<10|T[e.charCodeAt(s+1)]<<4|T[e.charCodeAt(s+2)]>>2,o[a++]=t>>8&255,o[a++]=t&255),o}function vt(e){return O[e>>18&63]+O[e>>12&63]+O[e>>6&63]+O[e&63]}function wt(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(vt(n));return i.join("")}function xt(e){for(var t,r=e.length,n=r%3,i=[],o=16383,a=0,f=r-n;a<f;a+=o)i.push(wt(e,a,a+o>f?f:a+o));return n===1?(t=e[r-1],i.push(O[t>>2]+O[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(O[t>>10]+O[t>>4&63]+O[t<<2&63]+"=")),i.join("")}});var Fe=S((rr,ke)=>{"use strict";var W,l,Ae={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
2
+ `,r:"\r",t:" "},le;function M(e){throw{name:"SyntaxError",message:e,at:W,text:le}}function c(e){return e&&e!==l&&M("Expected '"+e+"' instead of '"+l+"'"),l=le.charAt(W),W+=1,l}function Oe(){var e,t="";for(l==="-"&&(t="-",c("-"));l>="0"&&l<="9";)t+=l,c();if(l===".")for(t+=".";c()&&l>="0"&&l<="9";)t+=l;if(l==="e"||l==="E")for(t+=l,c(),(l==="-"||l==="+")&&(t+=l,c());l>="0"&&l<="9";)t+=l,c();return e=Number(t),isFinite(e)||M("Bad number"),e}function Se(){var e,t,r="",n;if(l==='"')for(;c();){if(l==='"')return c(),r;if(l==="\\")if(c(),l==="u"){for(n=0,t=0;t<4&&(e=parseInt(c(),16),!!isFinite(e));t+=1)n=n*16+e;r+=String.fromCharCode(n)}else if(typeof Ae[l]=="string")r+=Ae[l];else break;else r+=l}M("Bad string")}function k(){for(;l&&l<=" ";)c()}function Et(){switch(l){case"t":return c("t"),c("r"),c("u"),c("e"),!0;case"f":return c("f"),c("a"),c("l"),c("s"),c("e"),!1;case"n":return c("n"),c("u"),c("l"),c("l"),null;default:M("Unexpected '"+l+"'")}}function Pt(){var e=[];if(l==="["){if(c("["),k(),l==="]")return c("]"),e;for(;l;){if(e.push(Q()),k(),l==="]")return c("]"),e;c(","),k()}}M("Bad array")}function Tt(){var e,t={};if(l==="{"){if(c("{"),k(),l==="}")return c("}"),t;for(;l;){if(e=Se(),k(),c(":"),Object.prototype.hasOwnProperty.call(t,e)&&M('Duplicate key "'+e+'"'),t[e]=Q(),k(),l==="}")return c("}"),t;c(","),k()}}M("Bad object")}function Q(){switch(k(),l){case"{":return Tt();case"[":return Pt();case'"':return Se();case"-":return Oe();default:return l>="0"&&l<="9"?Oe():Et()}}ke.exports=function(e,t){var r;return le=e,W=0,l=" ",r=Q(),k(),l&&M("Syntax error"),typeof t=="function"?function n(i,o){var a,f,s=i[o];if(s&&typeof s=="object")for(a in Q)Object.prototype.hasOwnProperty.call(s,a)&&(f=n(s,a),typeof f>"u"?delete s[a]:s[a]=f);return t.call(i,o,s)}({"":r},""):r}});var Ce=S((nr,Me)=>{"use strict";var ce=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,E,X,At={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},I;function pe(e){return ce.lastIndex=0,ce.test(e)?'"'+e.replace(ce,function(t){var r=At[t];return typeof r=="string"?r:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function ee(e,t){var r,n,i,o,a=E,f,s=t[e];switch(s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON(e)),typeof I=="function"&&(s=I.call(t,e,s)),typeof s){case"string":return pe(s);case"number":return isFinite(s)?String(s):"null";case"boolean":case"null":return String(s);case"object":if(!s)return"null";if(E+=X,f=[],Object.prototype.toString.apply(s)==="[object Array]"){for(o=s.length,r=0;r<o;r+=1)f[r]=ee(r,s)||"null";return i=f.length===0?"[]":E?`[
3
+ `+E+f.join(`,
4
+ `+E)+`
5
+ `+a+"]":"["+f.join(",")+"]",E=a,i}if(I&&typeof I=="object")for(o=I.length,r=0;r<o;r+=1)n=I[r],typeof n=="string"&&(i=ee(n,s),i&&f.push(pe(n)+(E?": ":":")+i));else for(n in s)Object.prototype.hasOwnProperty.call(s,n)&&(i=ee(n,s),i&&f.push(pe(n)+(E?": ":":")+i));return i=f.length===0?"{}":E?`{
6
+ `+E+f.join(`,
7
+ `+E)+`
8
+ `+a+"}":"{"+f.join(",")+"}",E=a,i;default:}}Me.exports=function(e,t,r){var n;if(E="",X="",typeof r=="number")for(n=0;n<r;n+=1)X+=" ";else typeof r=="string"&&(X=r);if(I=t,t&&typeof t!="function"&&(typeof t!="object"||typeof t.length!="number"))throw new Error("JSON.stringify");return ee("",{"":e})}});var je=S(de=>{"use strict";de.parse=Fe();de.stringify=Ce()});var Ie=S((or,Be)=>{"use strict";var te=typeof JSON<"u"?JSON:je(),Ot=Array.isArray||function(e){return{}.toString.call(e)==="[object Array]"},St=Object.keys||function(e){var t=Object.prototype.hasOwnProperty||function(){return!0},r=[];for(var n in e)t.call(e,n)&&r.push(n);return r};Be.exports=function(e,t){t||(t={}),typeof t=="function"&&(t={cmp:t});var r=t.space||"";typeof r=="number"&&(r=Array(r+1).join(" "));var n=typeof t.cycles=="boolean"?t.cycles:!1,i=t.replacer||function(f,s){return s},o=t.cmp&&function(f){return function(s){return function(p,u){var g={key:p,value:s[p]},x={key:u,value:s[u]};return f(g,x)}}}(t.cmp),a=[];return function f(s,p,u,g){var x=r?`
9
+ `+new Array(g+1).join(r):"",F=r?": ":":";if(u&&u.toJSON&&typeof u.toJSON=="function"&&(u=u.toJSON()),u=i.call(s,p,u),u!==void 0){if(typeof u!="object"||u===null)return te.stringify(u);if(Ot(u)){for(var A=[],y=0;y<u.length;y++){var J=f(u,y,u[y],g+1)||te.stringify(null);A.push(x+r+J)}return"["+A.join(",")+x+"]"}if(a.indexOf(u)!==-1){if(n)return te.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}else a.push(u);for(var P=St(u).sort(o&&o(u)),A=[],y=0;y<P.length;y++){var p=P[y],m=f(u,p,u[p],g+1);if(m){var Y=te.stringify(p)+F+m;A.push(x+r+Y)}}return a.splice(a.indexOf(u),1),"{"+A.join(",")+x+"}"}}({"":e},"",e,0)}});var be=S(d=>{"use strict";var De=d&&d.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r};Object.defineProperty(d,"__esModule",{value:!0});d.isSchema=d.isValidSchema=d.isDiscriminatorForm=d.isValuesForm=d.isPropertiesForm=d.isElementsForm=d.isEnumForm=d.isTypeForm=d.isRefForm=d.isEmptyForm=void 0;function Ft(e){let{definitions:t,nullable:r,metadata:n}=e,i=De(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=Ft;function He(e){return"ref"in e}d.isRefForm=He;function Mt(e){return"type"in e}d.isTypeForm=Mt;function Ue(e){return"enum"in e}d.isEnumForm=Ue;function Je(e){return"elements"in e}d.isElementsForm=Je;function ge(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=ge;function qe(e){return"values"in e}d.isValuesForm=qe;function ze(e){return"discriminator"in e}d.isDiscriminatorForm=ze;function R(e,t){if(t===void 0&&(t=e),e.definitions!==void 0){if(t!==e)return!1;for(let r of Object.values(e.definitions))if(!R(r,t))return!1}if(He(e)&&!(e.ref in(t.definitions||{}))||Ue(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Je(e))return R(e.elements,t);if(ge(e)){for(let r of Object.values(e.properties||{}))if(!R(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!R(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(qe(e))return R(e.values,t);if(ze(e)){for(let r of Object.values(e.mapping))if(!R(r,t)||!ge(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}d.isValidSchema=R;var Ct=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],jt=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function _(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let t=e,{definitions:r=void 0,nullable:n=void 0,metadata:i=void 0,ref:o=void 0,type:a=void 0,enum:f=void 0,elements:s=void 0,properties:p=void 0,optionalProperties:u=void 0,additionalProperties:g=void 0,values:x=void 0,discriminator:F=void 0,mapping:y=void 0}=t,J=De(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),P=[o!==void 0,a!==void 0,f!==void 0,s!==void 0,p!==void 0,u!==void 0,g!==void 0,x!==void 0,F!==void 0,y!==void 0],A=!1;for(let m of Ct)A=A||m.every((Y,q)=>Y===P[q]);if(!A)return!1;if(r!==void 0){if(typeof r!="object"||Array.isArray(r)||r===null)return!1;for(let m of Object.values(r))if(!_(m))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||o!==void 0&&typeof o!="string"||a!==void 0&&(typeof a!="string"||!jt.includes(a))||f!==void 0&&(!Array.isArray(f)||!f.every(m=>typeof m=="string"))||s!==void 0&&!_(s))return!1;if(p!==void 0){if(typeof p!="object"||Array.isArray(p)||p===null)return!1;for(let m of Object.values(p))if(!_(m))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let m of Object.values(u))if(!_(m))return!1}if(g!==void 0&&typeof g!="boolean"||x!==void 0&&!_(x)||F!==void 0&&typeof F!="string")return!1;if(y!==void 0){if(typeof y!="object"||Array.isArray(y)||y===null)return!1;for(let m of Object.values(y))if(!_(m))return!1}return Object.keys(J).length===0}d.isSchema=_});var Ge=S(ve=>{"use strict";Object.defineProperty(ve,"__esModule",{value:!0});var Bt=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function It(e){let t=e.match(Bt);if(t===null)return!1;let r=parseInt(t[1],10),n=parseInt(t[2],10),i=parseInt(t[3],10),o=parseInt(t[4],10),a=parseInt(t[5],10),f=parseInt(t[6],10);return!(n>12||i>Rt(r,n)||o>23||a>59||f>60)}ve.default=It;function Rt(e,t){return t===2?_t(e)?29:28:Nt[t]}function _t(e){return e%4===0&&(e%100!==0||e%400===0)}var Nt=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Ve=S(C=>{"use strict";var $t=C&&C.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(C,"__esModule",{value:!0});C.validate=C.MaxDepthExceededError=void 0;var Lt=$t(Ge()),N=be(),ie=class extends Error{};C.MaxDepthExceededError=ie;var oe=class extends Error{};function Dt(e,t,r){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{D(n,e,t)}catch(i){if(!(i instanceof oe))throw i}return n.errors}C.validate=Dt;function D(e,t,r,n){if(!(t.nullable&&r===null)){if(N.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new ie;e.schemaTokens.push(["definitions",t.ref]),D(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if(N.isTypeForm(t)){switch(b(e,"type"),t.type){case"boolean":typeof r!="boolean"&&v(e);break;case"float32":case"float64":typeof r!="number"&&v(e);break;case"int8":U(e,r,-128,127);break;case"uint8":U(e,r,0,255);break;case"int16":U(e,r,-32768,32767);break;case"uint16":U(e,r,0,65535);break;case"int32":U(e,r,-2147483648,2147483647);break;case"uint32":U(e,r,0,4294967295);break;case"string":typeof r!="string"&&v(e);break;case"timestamp":typeof r!="string"?v(e):Lt.default(r)||v(e);break}w(e)}else if(N.isEnumForm(t))b(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&v(e),w(e);else if(N.isElementsForm(t)){if(b(e,"elements"),Array.isArray(r))for(let[i,o]of r.entries())$(e,i.toString()),D(e,t.elements,o),L(e);else v(e);w(e)}else if(N.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){b(e,"properties");for(let[i,o]of Object.entries(t.properties))b(e,i),r.hasOwnProperty(i)?($(e,i),D(e,o,r[i]),L(e)):v(e),w(e);w(e)}if(t.optionalProperties!==void 0){b(e,"optionalProperties");for(let[i,o]of Object.entries(t.optionalProperties))b(e,i),r.hasOwnProperty(i)&&($(e,i),D(e,o,r[i]),L(e)),w(e);w(e)}if(t.additionalProperties!==!0)for(let i of Object.keys(r)){let o=t.properties&&i in t.properties,a=t.optionalProperties&&i in t.optionalProperties;!o&&!a&&i!==n&&($(e,i),v(e),L(e))}}else t.properties!==void 0?b(e,"properties"):b(e,"optionalProperties"),v(e),w(e);else if(N.isValuesForm(t)){if(b(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[i,o]of Object.entries(r))$(e,i),D(e,t.values,o),L(e);else v(e);w(e)}else if(N.isDiscriminatorForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r))if(r.hasOwnProperty(t.discriminator)){let i=r[t.discriminator];typeof i=="string"?i in t.mapping?(b(e,"mapping"),b(e,i),D(e,t.mapping[i],r,t.discriminator),w(e),w(e)):(b(e,"mapping"),$(e,t.discriminator),v(e),L(e),w(e)):(b(e,"discriminator"),$(e,t.discriminator),v(e),L(e),w(e))}else b(e,"discriminator"),v(e),w(e);else b(e,"discriminator"),v(e),w(e)}}function U(e,t,r,n){(typeof t!="number"||!Number.isInteger(t)||t<r||t>n)&&v(e)}function $(e,t){e.instanceTokens.push(t)}function L(e){e.instanceTokens.pop()}function b(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function w(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function v(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new oe}});var Ze=S(j=>{"use strict";var Ht=j&&j.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),Ye=j&&j.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&Ht(t,e,r)};Object.defineProperty(j,"__esModule",{value:!0});Ye(be(),j);Ye(Ve(),j)});var Xt={};dt(Xt,{GenerationError:()=>fe,ResponseError:()=>H,builtinFontNames:()=>Gt,builtinLineHeights:()=>ot,builtinMargins:()=>it,builtinTextScales:()=>nt,builtinTools:()=>zt,formatEntry:()=>st,parseEntry:()=>at,register:()=>Wt,remarkable:()=>Qt});module.exports=yt(Xt);var et=z(Te()),tt=z(Ie());var Re=z(require("crypto")),ne=new Uint8Array(256),re=ne.length;function ye(){return re>ne.length-16&&(Re.default.randomFillSync(ne),re=0),ne.slice(re,re+=16)}var h=[];for(let e=0;e<256;++e)h.push((e+256).toString(16).slice(1));function _e(e,t=0){return(h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]).toLowerCase()}var Ne=z(require("crypto")),me={randomUUID:Ne.default.randomUUID};function kt(e,t,r){if(me.randomUUID&&!t&&!e)return me.randomUUID();e=e||{};let n=e.random||(e.rng||ye)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){r=r||0;for(let i=0;i<16;++i)t[r+i]=n[i];return t}return _e(n)}var G=kt;function he(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}function $e(e){return new Uint8Array((e.match(/../g)??[]).map(t=>parseInt(t,16)))}function Le(e){let t=0;for(let i of e)t+=i.length;let r=new Uint8Array(t),n=0;for(let i of e)r.set(i,n),n+=i.length;return r}var Ke=z(Ze());function V(e,t){if((0,Ke.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var We="3",rt="https://webapp-prod.cloud.remarkable.engineering",Ut="https://internal.cloud.remarkable.com",Qe="x-goog-generation",Jt="x-goog-if-generation-match",qt="x-goog-content-length-range",zt=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Gt=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],nt={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},it={sm:50,md:125,rr:180,lg:200},ot={df:-1,md:100,lg:150,xl:200},Vt={properties:{docID:{type:"string"},hash:{type:"string"}}},Yt={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},se={visibleName:{type:"string"},lastModified:{type:"string"}},ae={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},Zt={discriminator:"type",mapping:{CollectionType:{properties:se,optionalProperties:ae},DocumentType:{properties:se,optionalProperties:{...ae,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},Xe={id:{type:"string"},hash:{type:"string"}},Kt={discriminator:"type",mapping:{CollectionType:{properties:{...se,...Xe},optionalProperties:ae},DocumentType:{properties:{...se,...Xe,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...ae,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},H=class extends Error{status;statusText;constructor(t,r,n){super(n),this.status=t,this.statusText=r}},fe=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function Wt(e,{deviceDesc:t="browser-chrome",uuid:r=G(),authHost:n=rt,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:t,deviceID:r})});if(o.ok)return await o.text();throw new H(o.status,o.statusText,"couldn't register api")}function st({hash:e,type:t,documentId:r,subfiles:n,size:i}){return`${e}:${t}:${r}:${n}:${i}
10
+ `}function at(e){let[t,r,n,i,o]=e.split(":");if(t===void 0||r===void 0||n===void 0||i===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(r==="80000000")return{hash:t,type:r,documentId:n,subfiles:parseInt(i),size:BigInt(o)};if(r==="0"){if(i!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${i}`);return{hash:t,type:r,documentId:n,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${r}`)}var we=class{#u;#a;#f;#r;#n;#e=new Map;#t=null;constructor(t,r,n,i,o,a){this.#u=t,this.#a=r,this.#f=n,this.#r=i,this.#n=o;for(let[f,s]of a)this.#e.set(f,Promise.resolve(s))}async#i(t,{body:r,method:n="POST",headers:i={}}){let o=await this.#a(t,{method:n,headers:{Authorization:`Bearer ${this.#u}`,...i},body:r});if(o.ok)return o;{let a=await o.text();throw new H(o.status,o.statusText,`failed reMarkable request: ${a}`)}}async#o({url:t,method:r,maxuploadsize_bytes:n},i,o={}){let a=n?{...o,[qt]:`0,${n}`}:o,f=await this.#a(t,{method:r,body:i,headers:a});if(f.ok)return f;{let s=await f.text();throw new H(f.status,f.statusText,s)}}async#s(t,r,n){let i=r===void 0?"downloads":"uploads",o=n&&r!==null&&r!==void 0?`{ "http_method": "PUT", "relative_path": "${t}", "root_schema": "${n}", "generation": ${r} }`:JSON.stringify({http_method:"GET",relative_path:t}),f=await(await this.#i(`${this.#r}/sync/v2/signed-urls/${i}`,{body:o})).text(),s=JSON.parse(f);return V(Yt,s),s}async getRootHash({cache:t=!0}={}){if(t)for(;this.#t;)try{let[o,a]=await this.#t;return[o,a]}catch{}let r=(async()=>{try{let o=await this.#s("root"),a=await this.#o(o),f=a.headers.get(Qe);if(f)return[await a.text(),BigInt(f)];throw new Error("no generation header in root hash")}catch(o){throw this.#t=null,o}})();this.#t=r;let[n,i]=await r;return[n,i]}async putRootHash(t,r){let n=await this.#s("root",r,t),i;try{i=await this.#o(n,t,{[Jt]:`${r}`})}catch(f){throw f instanceof H&&f.status===412?(this.#t=null,new fe):f}let o=i.headers.get(Qe);if(!o)throw new Error("no generation header in root hash");let a=BigInt(o);return this.#t=Promise.resolve([t,a]),a}async#l(t){let r=this.#e.get(t);for(;r;)try{let i=await r;if(i)return i;r=void 0}catch{r=this.#e.get(t)}let n=(async()=>{let i=await this.#s(t);return await(await this.#o(i)).arrayBuffer()})();return this.#e.set(t,n.then(i=>i.byteLength<this.#n?i:null,i=>{throw this.#e.delete(t),i})),await n}async getBuffer(t){let r=await this.#l(t);return r.byteLength<this.#n?r.slice(0):r}async getText(t){let r=await this.#l(t);return new TextDecoder().decode(r)}async getJson(t){let r=await this.getText(t);return JSON.parse(r)}async getMetadata(t){let r=await this.getJson(t);return V(Zt,r),r}async getEntries(t){if(t===void 0){let[o]=await this.getRootHash({cache:!0});t=o}let r=await this.getText(t),[n,...i]=r.slice(0,-1).split(`
11
+ `);if(n!==We)throw new Error(`got unexpected schema version: ${n}`);return i.map(at)}async#c(t,r){let n=this.#e.get(t);if(n)try{await n;return}catch{}let i=(async()=>{try{let o=await this.#s(t,null);return await this.#o(o,r),r.byteLength<this.#n?r:null}catch(o){throw this.#e.delete(t),o}})();this.#e.set(t,i),await i}async putEntries(t,r){let n=new TextEncoder;r.sort((u,g)=>u.documentId.localeCompare(g.documentId));let i=Le(r.map(u=>$e(u.hash))),o=await this.#f.digest("SHA-256",i),a=he(o),f=r.map(st).join(""),s=`${We}
12
+ ${f}`,p=n.encode(s);return await this.#c(a,p),{hash:a,type:"80000000",documentId:t,subfiles:r.length,size:0n}}async putBuffer(t,r){let n=await this.#f.digest("SHA-256",r),i=he(n);return await this.#c(i,r),{hash:i,type:"0",documentId:t,subfiles:0,size:BigInt(r.byteLength)}}async putText(t,r){let n=new TextEncoder;return await this.putBuffer(t,n.encode(r))}async putJson(t,r){return await this.putText(t,(0,tt.default)(r))}async putMetadata(t,r){return await this.putJson(`${t}.metadata`,r)}async putCollection(t,r=""){let n=G(),i=`${new Date().valueOf()}`,o=[],a={type:"CollectionType",visibleName:t,version:0,parent:r,synced:!0,lastModified:i};o.push(this.putMetadata(n,a)),o.push(this.putText(`${n}.content`,"{}"));let f=await Promise.all(o);return await this.putEntries(n,f)}async#p(t,r,n,i,o){if(o.fileType!==n)throw new Error(`internal error: fileTypes don't match: ${n}, ${o.fileType}`);let a=G(),f=`${new Date().valueOf()}`,s=[];s.push(this.putBuffer(`${a}.${n}`,r));let p={type:"DocumentType",visibleName:t,version:0,parent:i,synced:!0,lastModified:f};s.push(this.putMetadata(a,p)),s.push(this.putText(`${a}.content`,JSON.stringify(o)));let u=await Promise.all(s);return await this.putEntries(a,u)}async putEpub(t,r,{parent:n="",margins:i=125,orientation:o,textAlignment:a,textScale:f=1,lineHeight:s=-1,fontName:p="",cover:u="visited",lastTool:g}={}){let x={dummyDocument:!1,extraMetadata:{LastTool:g},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof s=="string"?ot[s]:s,margins:typeof i=="string"?it[i]:i,textScale:typeof f=="string"?nt[f]:f,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:a,fontName:p};return await this.#p(t,r,"epub",n,x)}async putPdf(t,r,{parent:n="",orientation:i,cover:o="first",lastTool:a}={}){let f={dummyDocument:!1,extraMetadata:{LastTool:a},fileType:"pdf",pageCount:0,lastOpenedPage:0,lineHeight:-1,margins:125,textScale:1,pages:[],coverPageNumber:o==="first"?0:-1,formatVersion:1,orientation:i};return await this.#p(t,r,"pdf",n,f)}async syncComplete(t){let r=`{ "generation": ${t} }`;await this.#i(`${this.#r}/sync/v2/sync-complete`,{body:r})}async#d(t,r,n){let{hash:i}=await this.putEntries("",r),o=await this.putRootHash(i,t);if(n)try{return await this.syncComplete(o),!0}catch{return!1}else return!1}async create(t,{cache:r=!0,sync:n=!0}={}){let[i,o]=await this.getRootHash({cache:r}),a=await this.getEntries(i);return a.push(t),await this.#d(o,a,n)}async move(t,r,{cache:n=!0,sync:i=!0}={}){let[o,a]=await this.getRootHash({cache:n}),f=await this.getEntries(o);if(!(!r||r==="trash")){let P=f.find(q=>q.documentId===r);if(P){if(P.type!=="80000000")throw new Error(`destination id was a raw file: ${r}`)}else throw new Error(`destination id not found: ${r}`);let A=await this.getEntries(P.hash),[m]=A.filter(q=>q.documentId===`${r}.metadata`);if(!m)throw new Error(`destination id didn't have metadata: ${r}`);if((await this.getMetadata(m.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${r}`)}let s=f.findIndex(P=>P.documentId===t);if(s===-1)throw new Error(`document not found: ${t}`);let[p]=f.splice(s,1);if(p.type!=="80000000")throw new Error(`document was a raw file: ${t}`);let u=await this.getEntries(p.hash),g=u.findIndex(P=>P.documentId===`${t}.metadata`);if(g===-1)throw new Error(`document didn't have metadata: ${t}`);let[x]=u.splice(g,1),F=await this.getMetadata(x.hash);F.parent=r;let y=await this.putMetadata(t,F);u.push(y);let J=await this.putEntries(t,u);return f.push(J),await this.#d(a,f,i)}async getEntriesMetadata(){let r=await(await this.#i(`${this.#r}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),n=JSON.parse(r);return V({elements:Kt},n),n}async#y(t,r,n){let o=new TextEncoder().encode(JSON.stringify({file_name:t})),f=await(await this.#i(`${this.#r}/doc/v2/files`,{body:r,headers:{"content-type":n,"rm-meta":(0,et.fromByteArray)(o),"rm-source":"RoR-Browser"}})).text(),s=JSON.parse(f);return V(Vt,s),s}async uploadEpub(t,r){return await this.#y(t,r,"application/epub+zip")}async uploadPdf(t,r){return await this.#y(t,r,"application/pdf")}async getCache(){let t=[];for(let[i,o]of this.#e)t.push(o.then(a=>[i,a],()=>[i,null]));let r=await Promise.all(t),n=new Map;for(let[i,o]of r)o&&n.set(i,o);return n}};async function Qt(e,{fetch:t=globalThis.fetch,subtle:r=globalThis.crypto?.subtle,authHost:n=rt,syncHost:i=Ut,cacheLimitBytes:o=1048576,initCache:a=[]}={}){if(!r)throw new Error("subtle was missing, try specifying it manually");let f=await t(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!f.ok)throw new Error(`couldn't fetch auth token: ${f.statusText}`);let s=await f.text();return new we(s,t,r,i,o,a)}0&&(module.exports={GenerationError,ResponseError,builtinFontNames,builtinLineHeights,builtinMargins,builtinTextScales,builtinTools,formatEntry,parseEntry,register,remarkable});
@@ -1,12 +1,12 @@
1
- var pt=Object.create;var Ce=Object.defineProperty;var yt=Object.getOwnPropertyDescriptor;var mt=Object.getOwnPropertyNames;var ht=Object.getPrototypeOf,gt=Object.prototype.hasOwnProperty;var j=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var bt=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of mt(r))!gt.call(e,i)&&i!==t&&Ce(e,i,{get:()=>r[i],enumerable:!(n=yt(r,i))||n.enumerable});return e};var me=(e,r,t)=>(t=e!=null?pt(ht(e)):{},bt(r||!e||!e.__esModule?Ce(t,"default",{value:e,enumerable:!0}):t,e));var Be=j(re=>{"use strict";re.byteLength=vt;re.toByteArray=Et;re.fromByteArray=At;var F=[],M=[],wt=typeof Uint8Array<"u"?Uint8Array:Array,he="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(L=0,Fe=he.length;L<Fe;++L)F[L]=he[L],M[he.charCodeAt(L)]=L;var L,Fe;M["-".charCodeAt(0)]=62;M["_".charCodeAt(0)]=63;function je(e){var r=e.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=e.indexOf("=");t===-1&&(t=r);var n=t===r?0:4-t%4;return[t,n]}function vt(e){var r=je(e),t=r[0],n=r[1];return(t+n)*3/4-n}function xt(e,r,t){return(r+t)*3/4-t}function Et(e){var r,t=je(e),n=t[0],i=t[1],o=new wt(xt(e,n,i)),a=0,f=i>0?n-4:n,s;for(s=0;s<f;s+=4)r=M[e.charCodeAt(s)]<<18|M[e.charCodeAt(s+1)]<<12|M[e.charCodeAt(s+2)]<<6|M[e.charCodeAt(s+3)],o[a++]=r>>16&255,o[a++]=r>>8&255,o[a++]=r&255;return i===2&&(r=M[e.charCodeAt(s)]<<2|M[e.charCodeAt(s+1)]>>4,o[a++]=r&255),i===1&&(r=M[e.charCodeAt(s)]<<10|M[e.charCodeAt(s+1)]<<4|M[e.charCodeAt(s+2)]>>2,o[a++]=r>>8&255,o[a++]=r&255),o}function Pt(e){return F[e>>18&63]+F[e>>12&63]+F[e>>6&63]+F[e&63]}function Tt(e,r,t){for(var n,i=[],o=r;o<t;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(Pt(n));return i.join("")}function At(e){for(var r,t=e.length,n=t%3,i=[],o=16383,a=0,f=t-n;a<f;a+=o)i.push(Tt(e,a,a+o>f?f:a+o));return n===1?(r=e[t-1],i.push(F[r>>2]+F[r<<4&63]+"==")):n===2&&(r=(e[t-2]<<8)+e[t-1],i.push(F[r>>10]+F[r>>4&63]+F[r<<2&63]+"=")),i.join("")}});var Ue=j((vr,Ne)=>{"use strict";var ne,u,Ie={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
2
- `,r:"\r",t:" "},ge;function I(e){throw{name:"SyntaxError",message:e,at:ne,text:ge}}function d(e){return e&&e!==u&&I("Expected '"+e+"' instead of '"+u+"'"),u=ge.charAt(ne),ne+=1,u}function Re(){var e,r="";for(u==="-"&&(r="-",d("-"));u>="0"&&u<="9";)r+=u,d();if(u===".")for(r+=".";d()&&u>="0"&&u<="9";)r+=u;if(u==="e"||u==="E")for(r+=u,d(),(u==="-"||u==="+")&&(r+=u,d());u>="0"&&u<="9";)r+=u,d();return e=Number(r),isFinite(e)||I("Bad number"),e}function _e(){var e,r,t="",n;if(u==='"')for(;d();){if(u==='"')return d(),t;if(u==="\\")if(d(),u==="u"){for(n=0,r=0;r<4&&(e=parseInt(d(),16),!!isFinite(e));r+=1)n=n*16+e;t+=String.fromCharCode(n)}else if(typeof Ie[u]=="string")t+=Ie[u];else break;else t+=u}I("Bad string")}function B(){for(;u&&u<=" ";)d()}function Ot(){switch(u){case"t":return d("t"),d("r"),d("u"),d("e"),!0;case"f":return d("f"),d("a"),d("l"),d("s"),d("e"),!1;case"n":return d("n"),d("u"),d("l"),d("l"),null;default:I("Unexpected '"+u+"'")}}function St(){var e=[];if(u==="["){if(d("["),B(),u==="]")return d("]"),e;for(;u;){if(e.push(ie()),B(),u==="]")return d("]"),e;d(","),B()}}I("Bad array")}function kt(){var e,r={};if(u==="{"){if(d("{"),B(),u==="}")return d("}"),r;for(;u;){if(e=_e(),B(),d(":"),Object.prototype.hasOwnProperty.call(r,e)&&I('Duplicate key "'+e+'"'),r[e]=ie(),B(),u==="}")return d("}"),r;d(","),B()}}I("Bad object")}function ie(){switch(B(),u){case"{":return kt();case"[":return St();case'"':return _e();case"-":return Re();default:return u>="0"&&u<="9"?Re():Ot()}}Ne.exports=function(e,r){var t;return ge=e,ne=0,u=" ",t=ie(),B(),u&&I("Syntax error"),typeof r=="function"?function n(i,o){var a,f,s=i[o];if(s&&typeof s=="object")for(a in ie)Object.prototype.hasOwnProperty.call(s,a)&&(f=n(s,a),typeof f>"u"?delete s[a]:s[a]=f);return r.call(i,o,s)}({"":t},""):t}});var De=j((xr,Le)=>{"use strict";var be=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,S,oe,Mt={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},D;function we(e){return be.lastIndex=0,be.test(e)?'"'+e.replace(be,function(r){var t=Mt[r];return typeof t=="string"?t:"\\u"+("0000"+r.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function ae(e,r){var t,n,i,o,a=S,f,s=r[e];switch(s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON(e)),typeof D=="function"&&(s=D.call(r,e,s)),typeof s){case"string":return we(s);case"number":return isFinite(s)?String(s):"null";case"boolean":case"null":return String(s);case"object":if(!s)return"null";if(S+=oe,f=[],Object.prototype.toString.apply(s)==="[object Array]"){for(o=s.length,t=0;t<o;t+=1)f[t]=ae(t,s)||"null";return i=f.length===0?"[]":S?`[
3
- `+S+f.join(`,
4
- `+S)+`
5
- `+a+"]":"["+f.join(",")+"]",S=a,i}if(D&&typeof D=="object")for(o=D.length,t=0;t<o;t+=1)n=D[t],typeof n=="string"&&(i=ae(n,s),i&&f.push(we(n)+(S?": ":":")+i));else for(n in s)Object.prototype.hasOwnProperty.call(s,n)&&(i=ae(n,s),i&&f.push(we(n)+(S?": ":":")+i));return i=f.length===0?"{}":S?`{
6
- `+S+f.join(`,
7
- `+S)+`
8
- `+a+"}":"{"+f.join(",")+"}",S=a,i;default:}}Le.exports=function(e,r,t){var n;if(S="",oe="",typeof t=="number")for(n=0;n<t;n+=1)oe+=" ";else typeof t=="string"&&(oe=t);if(D=r,r&&typeof r!="function"&&(typeof r!="object"||typeof r.length!="number"))throw new Error("JSON.stringify");return ae("",{"":e})}});var $e=j(ve=>{"use strict";ve.parse=Ue();ve.stringify=De()});var Je=j((Pr,He)=>{"use strict";var se=typeof JSON<"u"?JSON:$e(),Ct=Array.isArray||function(e){return{}.toString.call(e)==="[object Array]"},Ft=Object.keys||function(e){var r=Object.prototype.hasOwnProperty||function(){return!0},t=[];for(var n in e)r.call(e,n)&&t.push(n);return t};He.exports=function(e,r){r||(r={}),typeof r=="function"&&(r={cmp:r});var t=r.space||"";typeof t=="number"&&(t=Array(t+1).join(" "));var n=typeof r.cycles=="boolean"?r.cycles:!1,i=r.replacer||function(f,s){return s},o=r.cmp&&function(f){return function(s){return function(c,l){var m={key:c,value:s[c]},g={key:l,value:s[l]};return f(m,g)}}}(r.cmp),a=[];return function f(s,c,l,m){var g=t?`
9
- `+new Array(m+1).join(t):"",p=t?": ":":";if(l&&l.toJSON&&typeof l.toJSON=="function"&&(l=l.toJSON()),l=i.call(s,c,l),l!==void 0){if(typeof l!="object"||l===null)return se.stringify(l);if(Ct(l)){for(var C=[],h=0;h<l.length;h++){var U=f(l,h,l[h],m+1)||se.stringify(null);C.push(g+t+U)}return"["+C.join(",")+g+"]"}if(a.indexOf(l)!==-1){if(n)return se.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}else a.push(l);for(var k=Ft(l).sort(o&&o(l)),C=[],h=0;h<k.length;h++){var c=k[h],b=f(l,c,l[c],m+1);if(b){var te=se.stringify(c)+p+b;C.push(g+t+te)}}return a.splice(a.indexOf(l),1),"{"+C.join(",")+g+"}"}}({"":e},"",e,0)}});var Oe=j(y=>{"use strict";var Ke=y&&y.__rest||function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)r.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(t[n[i]]=e[n[i]]);return t};Object.defineProperty(y,"__esModule",{value:!0});y.isSchema=y.isValidSchema=y.isDiscriminatorForm=y.isValuesForm=y.isPropertiesForm=y.isElementsForm=y.isEnumForm=y.isTypeForm=y.isRefForm=y.isEmptyForm=void 0;function zt(e){let{definitions:r,nullable:t,metadata:n}=e,i=Ke(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}y.isEmptyForm=zt;function Ze(e){return"ref"in e}y.isRefForm=Ze;function Wt(e){return"type"in e}y.isTypeForm=Wt;function Xe(e){return"enum"in e}y.isEnumForm=Xe;function Qe(e){return"elements"in e}y.isElementsForm=Qe;function Ae(e){return"properties"in e||"optionalProperties"in e}y.isPropertiesForm=Ae;function et(e){return"values"in e}y.isValuesForm=et;function tt(e){return"discriminator"in e}y.isDiscriminatorForm=tt;function $(e,r){if(r===void 0&&(r=e),e.definitions!==void 0){if(r!==e)return!1;for(let t of Object.values(e.definitions))if(!$(t,r))return!1}if(Ze(e)&&!(e.ref in(r.definitions||{}))||Xe(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Qe(e))return $(e.elements,r);if(Ae(e)){for(let t of Object.values(e.properties||{}))if(!$(t,r))return!1;for(let t of Object.values(e.optionalProperties||{}))if(!$(t,r))return!1;for(let t of Object.keys(e.properties||{}))if(t in(e.optionalProperties||{}))return!1}if(et(e))return $(e.values,r);if(tt(e)){for(let t of Object.values(e.mapping))if(!$(t,r)||!Ae(t)||t.nullable||e.discriminator in(t.properties||{})||e.discriminator in(t.optionalProperties||{}))return!1}return!0}y.isValidSchema=$;var Yt=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],Kt=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function H(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let r=e,{definitions:t=void 0,nullable:n=void 0,metadata:i=void 0,ref:o=void 0,type:a=void 0,enum:f=void 0,elements:s=void 0,properties:c=void 0,optionalProperties:l=void 0,additionalProperties:m=void 0,values:g=void 0,discriminator:p=void 0,mapping:h=void 0}=r,U=Ke(r,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),k=[o!==void 0,a!==void 0,f!==void 0,s!==void 0,c!==void 0,l!==void 0,m!==void 0,g!==void 0,p!==void 0,h!==void 0],C=!1;for(let b of Yt)C=C||b.every((te,Y)=>te===k[Y]);if(!C)return!1;if(t!==void 0){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;for(let b of Object.values(t))if(!H(b))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||o!==void 0&&typeof o!="string"||a!==void 0&&(typeof a!="string"||!Kt.includes(a))||f!==void 0&&(!Array.isArray(f)||!f.every(b=>typeof b=="string"))||s!==void 0&&!H(s))return!1;if(c!==void 0){if(typeof c!="object"||Array.isArray(c)||c===null)return!1;for(let b of Object.values(c))if(!H(b))return!1}if(l!==void 0){if(typeof l!="object"||Array.isArray(l)||l===null)return!1;for(let b of Object.values(l))if(!H(b))return!1}if(m!==void 0&&typeof m!="boolean"||g!==void 0&&!H(g)||p!==void 0&&typeof p!="string")return!1;if(h!==void 0){if(typeof h!="object"||Array.isArray(h)||h===null)return!1;for(let b of Object.values(h))if(!H(b))return!1}return Object.keys(U).length===0}y.isSchema=H});var rt=j(Se=>{"use strict";Object.defineProperty(Se,"__esModule",{value:!0});var Zt=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Xt(e){let r=e.match(Zt);if(r===null)return!1;let t=parseInt(r[1],10),n=parseInt(r[2],10),i=parseInt(r[3],10),o=parseInt(r[4],10),a=parseInt(r[5],10),f=parseInt(r[6],10);return!(n>12||i>Qt(t,n)||o>23||a>59||f>60)}Se.default=Xt;function Qt(e,r){return r===2?er(e)?29:28:tr[r]}function er(e){return e%4===0&&(e%100!==0||e%400===0)}var tr=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var nt=j(_=>{"use strict";var rr=_&&_.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(_,"__esModule",{value:!0});_.validate=_.MaxDepthExceededError=void 0;var nr=rr(rt()),J=Oe(),ce=class extends Error{};_.MaxDepthExceededError=ce;var de=class extends Error{};function ir(e,r,t){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:t||{maxDepth:0,maxErrors:0}};try{G(n,e,r)}catch(i){if(!(i instanceof de))throw i}return n.errors}_.validate=ir;function G(e,r,t,n){if(!(r.nullable&&t===null)){if(J.isRefForm(r)){if(e.schemaTokens.length===e.config.maxDepth)throw new ce;e.schemaTokens.push(["definitions",r.ref]),G(e,e.root.definitions[r.ref],t),e.schemaTokens.pop()}else if(J.isTypeForm(r)){switch(T(e,"type"),r.type){case"boolean":typeof t!="boolean"&&A(e);break;case"float32":case"float64":typeof t!="number"&&A(e);break;case"int8":z(e,t,-128,127);break;case"uint8":z(e,t,0,255);break;case"int16":z(e,t,-32768,32767);break;case"uint16":z(e,t,0,65535);break;case"int32":z(e,t,-2147483648,2147483647);break;case"uint32":z(e,t,0,4294967295);break;case"string":typeof t!="string"&&A(e);break;case"timestamp":typeof t!="string"?A(e):nr.default(t)||A(e);break}O(e)}else if(J.isEnumForm(r))T(e,"enum"),(typeof t!="string"||!r.enum.includes(t))&&A(e),O(e);else if(J.isElementsForm(r)){if(T(e,"elements"),Array.isArray(t))for(let[i,o]of t.entries())q(e,i.toString()),G(e,r.elements,o),V(e);else A(e);O(e)}else if(J.isPropertiesForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t)){if(r.properties!==void 0){T(e,"properties");for(let[i,o]of Object.entries(r.properties))T(e,i),t.hasOwnProperty(i)?(q(e,i),G(e,o,t[i]),V(e)):A(e),O(e);O(e)}if(r.optionalProperties!==void 0){T(e,"optionalProperties");for(let[i,o]of Object.entries(r.optionalProperties))T(e,i),t.hasOwnProperty(i)&&(q(e,i),G(e,o,t[i]),V(e)),O(e);O(e)}if(r.additionalProperties!==!0)for(let i of Object.keys(t)){let o=r.properties&&i in r.properties,a=r.optionalProperties&&i in r.optionalProperties;!o&&!a&&i!==n&&(q(e,i),A(e),V(e))}}else r.properties!==void 0?T(e,"properties"):T(e,"optionalProperties"),A(e),O(e);else if(J.isValuesForm(r)){if(T(e,"values"),typeof t=="object"&&t!==null&&!Array.isArray(t))for(let[i,o]of Object.entries(t))q(e,i),G(e,r.values,o),V(e);else A(e);O(e)}else if(J.isDiscriminatorForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t))if(t.hasOwnProperty(r.discriminator)){let i=t[r.discriminator];typeof i=="string"?i in r.mapping?(T(e,"mapping"),T(e,i),G(e,r.mapping[i],t,r.discriminator),O(e),O(e)):(T(e,"mapping"),q(e,r.discriminator),A(e),V(e),O(e)):(T(e,"discriminator"),q(e,r.discriminator),A(e),V(e),O(e))}else T(e,"discriminator"),A(e),O(e);else T(e,"discriminator"),A(e),O(e)}}function z(e,r,t,n){(typeof r!="number"||!Number.isInteger(r)||r<t||r>n)&&A(e)}function q(e,r){e.instanceTokens.push(r)}function V(e){e.instanceTokens.pop()}function T(e,r){e.schemaTokens[e.schemaTokens.length-1].push(r)}function O(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function A(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new de}});var ot=j(N=>{"use strict";var or=N&&N.__createBinding||(Object.create?function(e,r,t,n){n===void 0&&(n=t),Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,n){n===void 0&&(n=t),e[n]=r[t]}),it=N&&N.__exportStar||function(e,r){for(var t in e)t!=="default"&&!r.hasOwnProperty(t)&&or(r,e,t)};Object.defineProperty(N,"__esModule",{value:!0});it(Oe(),N);it(nt(),N)});var ut=me(Be()),ct=me(Je());var fe,jt=new Uint8Array(16);function le(){if(!fe&&(fe=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!fe))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return fe(jt)}var qe=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Bt(e){return typeof e=="string"&&qe.test(e)}var K=Bt;var w=[];for(let e=0;e<256;++e)w.push((e+256).toString(16).slice(1));function Z(e,r=0){return(w[e[r+0]]+w[e[r+1]]+w[e[r+2]]+w[e[r+3]]+"-"+w[e[r+4]]+w[e[r+5]]+"-"+w[e[r+6]]+w[e[r+7]]+"-"+w[e[r+8]]+w[e[r+9]]+"-"+w[e[r+10]]+w[e[r+11]]+w[e[r+12]]+w[e[r+13]]+w[e[r+14]]+w[e[r+15]]).toLowerCase()}function It(e){if(!K(e))throw TypeError("Invalid UUID");let r,t=new Uint8Array(16);return t[0]=(r=parseInt(e.slice(0,8),16))>>>24,t[1]=r>>>16&255,t[2]=r>>>8&255,t[3]=r&255,t[4]=(r=parseInt(e.slice(9,13),16))>>>8,t[5]=r&255,t[6]=(r=parseInt(e.slice(14,18),16))>>>8,t[7]=r&255,t[8]=(r=parseInt(e.slice(19,23),16))>>>8,t[9]=r&255,t[10]=(r=parseInt(e.slice(24,36),16))/1099511627776&255,t[11]=r/4294967296&255,t[12]=r>>>24&255,t[13]=r>>>16&255,t[14]=r>>>8&255,t[15]=r&255,t}var xe=It;function Rt(e){e=unescape(encodeURIComponent(e));let r=[];for(let t=0;t<e.length;++t)r.push(e.charCodeAt(t));return r}var _t="6ba7b810-9dad-11d1-80b4-00c04fd430c8",Nt="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function X(e,r,t){function n(i,o,a,f){var s;if(typeof i=="string"&&(i=Rt(i)),typeof o=="string"&&(o=xe(o)),((s=o)===null||s===void 0?void 0:s.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+i.length);if(c.set(o),c.set(i,o.length),c=t(c),c[6]=c[6]&15|r,c[8]=c[8]&63|128,a){f=f||0;for(let l=0;l<16;++l)a[f+l]=c[l];return a}return Z(c)}try{n.name=e}catch{}return n.DNS=_t,n.URL=Nt,n}function Ut(e){if(typeof e=="string"){let r=unescape(encodeURIComponent(e));e=new Uint8Array(r.length);for(let t=0;t<r.length;++t)e[t]=r.charCodeAt(t)}return Lt(Dt($t(e),e.length*8))}function Lt(e){let r=[],t=e.length*32,n="0123456789abcdef";for(let i=0;i<t;i+=8){let o=e[i>>5]>>>i%32&255,a=parseInt(n.charAt(o>>>4&15)+n.charAt(o&15),16);r.push(a)}return r}function Ve(e){return(e+64>>>9<<4)+14+1}function Dt(e,r){e[r>>5]|=128<<r%32,e[Ve(r)-1]=r;let t=1732584193,n=-271733879,i=-1732584194,o=271733878;for(let a=0;a<e.length;a+=16){let f=t,s=n,c=i,l=o;t=v(t,n,i,o,e[a],7,-680876936),o=v(o,t,n,i,e[a+1],12,-389564586),i=v(i,o,t,n,e[a+2],17,606105819),n=v(n,i,o,t,e[a+3],22,-1044525330),t=v(t,n,i,o,e[a+4],7,-176418897),o=v(o,t,n,i,e[a+5],12,1200080426),i=v(i,o,t,n,e[a+6],17,-1473231341),n=v(n,i,o,t,e[a+7],22,-45705983),t=v(t,n,i,o,e[a+8],7,1770035416),o=v(o,t,n,i,e[a+9],12,-1958414417),i=v(i,o,t,n,e[a+10],17,-42063),n=v(n,i,o,t,e[a+11],22,-1990404162),t=v(t,n,i,o,e[a+12],7,1804603682),o=v(o,t,n,i,e[a+13],12,-40341101),i=v(i,o,t,n,e[a+14],17,-1502002290),n=v(n,i,o,t,e[a+15],22,1236535329),t=x(t,n,i,o,e[a+1],5,-165796510),o=x(o,t,n,i,e[a+6],9,-1069501632),i=x(i,o,t,n,e[a+11],14,643717713),n=x(n,i,o,t,e[a],20,-373897302),t=x(t,n,i,o,e[a+5],5,-701558691),o=x(o,t,n,i,e[a+10],9,38016083),i=x(i,o,t,n,e[a+15],14,-660478335),n=x(n,i,o,t,e[a+4],20,-405537848),t=x(t,n,i,o,e[a+9],5,568446438),o=x(o,t,n,i,e[a+14],9,-1019803690),i=x(i,o,t,n,e[a+3],14,-187363961),n=x(n,i,o,t,e[a+8],20,1163531501),t=x(t,n,i,o,e[a+13],5,-1444681467),o=x(o,t,n,i,e[a+2],9,-51403784),i=x(i,o,t,n,e[a+7],14,1735328473),n=x(n,i,o,t,e[a+12],20,-1926607734),t=E(t,n,i,o,e[a+5],4,-378558),o=E(o,t,n,i,e[a+8],11,-2022574463),i=E(i,o,t,n,e[a+11],16,1839030562),n=E(n,i,o,t,e[a+14],23,-35309556),t=E(t,n,i,o,e[a+1],4,-1530992060),o=E(o,t,n,i,e[a+4],11,1272893353),i=E(i,o,t,n,e[a+7],16,-155497632),n=E(n,i,o,t,e[a+10],23,-1094730640),t=E(t,n,i,o,e[a+13],4,681279174),o=E(o,t,n,i,e[a],11,-358537222),i=E(i,o,t,n,e[a+3],16,-722521979),n=E(n,i,o,t,e[a+6],23,76029189),t=E(t,n,i,o,e[a+9],4,-640364487),o=E(o,t,n,i,e[a+12],11,-421815835),i=E(i,o,t,n,e[a+15],16,530742520),n=E(n,i,o,t,e[a+2],23,-995338651),t=P(t,n,i,o,e[a],6,-198630844),o=P(o,t,n,i,e[a+7],10,1126891415),i=P(i,o,t,n,e[a+14],15,-1416354905),n=P(n,i,o,t,e[a+5],21,-57434055),t=P(t,n,i,o,e[a+12],6,1700485571),o=P(o,t,n,i,e[a+3],10,-1894986606),i=P(i,o,t,n,e[a+10],15,-1051523),n=P(n,i,o,t,e[a+1],21,-2054922799),t=P(t,n,i,o,e[a+8],6,1873313359),o=P(o,t,n,i,e[a+15],10,-30611744),i=P(i,o,t,n,e[a+6],15,-1560198380),n=P(n,i,o,t,e[a+13],21,1309151649),t=P(t,n,i,o,e[a+4],6,-145523070),o=P(o,t,n,i,e[a+11],10,-1120210379),i=P(i,o,t,n,e[a+2],15,718787259),n=P(n,i,o,t,e[a+9],21,-343485551),t=R(t,f),n=R(n,s),i=R(i,c),o=R(o,l)}return[t,n,i,o]}function $t(e){if(e.length===0)return[];let r=e.length*8,t=new Uint32Array(Ve(r));for(let n=0;n<r;n+=8)t[n>>5]|=(e[n/8]&255)<<n%32;return t}function R(e,r){let t=(e&65535)+(r&65535);return(e>>16)+(r>>16)+(t>>16)<<16|t&65535}function Ht(e,r){return e<<r|e>>>32-r}function ue(e,r,t,n,i,o){return R(Ht(R(R(r,e),R(n,o)),i),t)}function v(e,r,t,n,i,o,a){return ue(r&t|~r&n,e,r,i,o,a)}function x(e,r,t,n,i,o,a){return ue(r&n|t&~n,e,r,i,o,a)}function E(e,r,t,n,i,o,a){return ue(r^t^n,e,r,i,o,a)}function P(e,r,t,n,i,o,a){return ue(t^(r|~n),e,r,i,o,a)}var Ge=Ut;var $r=X("v3",48,Ge);var Jt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Ee={randomUUID:Jt};function qt(e,r,t){if(Ee.randomUUID&&!r&&!e)return Ee.randomUUID();e=e||{};let n=e.random||(e.rng||le)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,r){t=t||0;for(let i=0;i<16;++i)r[t+i]=n[i];return r}return Z(n)}var Q=qt;function Vt(e,r,t,n){switch(e){case 0:return r&t^~r&n;case 1:return r^t^n;case 2:return r&t^r&n^t&n;case 3:return r^t^n}}function Pe(e,r){return e<<r|e>>>32-r}function Gt(e){let r=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){let a=unescape(encodeURIComponent(e));e=[];for(let f=0;f<a.length;++f)e.push(a.charCodeAt(f))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);let n=e.length/4+2,i=Math.ceil(n/16),o=new Array(i);for(let a=0;a<i;++a){let f=new Uint32Array(16);for(let s=0;s<16;++s)f[s]=e[a*64+s*4]<<24|e[a*64+s*4+1]<<16|e[a*64+s*4+2]<<8|e[a*64+s*4+3];o[a]=f}o[i-1][14]=(e.length-1)*8/Math.pow(2,32),o[i-1][14]=Math.floor(o[i-1][14]),o[i-1][15]=(e.length-1)*8&4294967295;for(let a=0;a<i;++a){let f=new Uint32Array(80);for(let p=0;p<16;++p)f[p]=o[a][p];for(let p=16;p<80;++p)f[p]=Pe(f[p-3]^f[p-8]^f[p-14]^f[p-16],1);let s=t[0],c=t[1],l=t[2],m=t[3],g=t[4];for(let p=0;p<80;++p){let h=Math.floor(p/20),U=Pe(s,5)+Vt(h,c,l,m)+g+r[h]+f[p]>>>0;g=m,m=l,l=Pe(c,30)>>>0,c=s,s=U}t[0]=t[0]+s>>>0,t[1]=t[1]+c>>>0,t[2]=t[2]+l>>>0,t[3]=t[3]+m>>>0,t[4]=t[4]+g>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}var ze=Gt;var Zr=X("v5",80,ze);function Te(e){return[...new Uint8Array(e)].map(r=>r.toString(16).padStart(2,"0")).join("")}function We(e){return new Uint8Array((e.match(/../g)??[]).map(r=>parseInt(r,16)))}function Ye(e){let r=0;for(let i of e)r+=i.length;let t=new Uint8Array(r),n=0;for(let i of e)t.set(i,n),n+=i.length;return t}var at=me(ot());function ee(e,r){if((0,at.validate)(e,r).length)throw new Error(`couldn't validate schema: ${JSON.stringify(r)} didn't match schema ${JSON.stringify(e)}`)}var st="3",dt="https://webapp-prod.cloud.remarkable.engineering",ar="https://internal.cloud.remarkable.com",ft="x-goog-generation",sr="x-goog-if-generation-match",fr="x-goog-content-length-range",Mn=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Cn=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],lr={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},ur={sm:50,md:125,rr:180,lg:200},cr={df:-1,md:100,lg:150,xl:200},dr={properties:{docID:{type:"string"},hash:{type:"string"}}},pr={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},pe={visibleName:{type:"string"},lastModified:{type:"string"}},ye={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},yr={discriminator:"type",mapping:{CollectionType:{properties:pe,optionalProperties:ye},DocumentType:{properties:pe,optionalProperties:{...ye,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},lt={id:{type:"string"},hash:{type:"string"}},mr={discriminator:"type",mapping:{CollectionType:{properties:{...pe,...lt},optionalProperties:ye},DocumentType:{properties:{...pe,...lt,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...ye,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},W=class extends Error{constructor(t,n,i){super(i);this.status=t,this.statusText=n}},ke=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function Fn(e,{deviceDesc:r="browser-chrome",uuid:t=Q(),authHost:n=dt,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:r,deviceID:t})});if(o.ok)return await o.text();throw new W(o.status,o.statusText,"couldn't register api")}function hr({hash:e,type:r,documentId:t,subfiles:n,size:i}){return`${e}:${r}:${t}:${n}:${i}
10
- `}function gr(e){let[r,t,n,i,o]=e.split(":");if(r===void 0||t===void 0||n===void 0||i===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(t==="80000000")return{hash:r,type:t,documentId:n,subfiles:parseInt(i),size:BigInt(o)};if(t==="0"){if(i!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${i}`);return{hash:r,type:t,documentId:n,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${t}`)}var Me=class{#l;#s;#f;#r;#n;#e=new Map;#t=null;constructor(r,t,n,i,o,a){this.#l=r,this.#s=t,this.#f=n,this.#r=i,this.#n=o;for(let[f,s]of a)this.#e.set(f,Promise.resolve(s))}async#i(r,{body:t,method:n="POST",headers:i={}}){let o=await this.#s(r,{method:n,headers:{Authorization:`Bearer ${this.#l}`,...i},body:t});if(o.ok)return o;{let a=await o.text();throw new W(o.status,o.statusText,`failed reMarkable request: ${a}`)}}async#o({url:r,method:t,maxuploadsize_bytes:n},i,o={}){let a=n?{...o,[fr]:`0,${n}`}:o,f=await this.#s(r,{method:t,body:i,headers:a});if(f.ok)return f;{let s=await f.text();throw new W(f.status,f.statusText,s)}}async#a(r,t,n){let i=t===void 0?"downloads":"uploads",o=n&&t!==null&&t!==void 0?`{ "http_method": "PUT", "relative_path": "${r}", "root_schema": "${n}", "generation": ${t} }`:JSON.stringify({http_method:"GET",relative_path:r}),f=await(await this.#i(`${this.#r}/sync/v2/signed-urls/${i}`,{body:o})).text(),s=JSON.parse(f);return ee(pr,s),s}async getRootHash({cache:r=!0}={}){if(r)for(;this.#t;)try{let[o,a]=await this.#t;return[o,a]}catch{}let t=(async()=>{try{let o=await this.#a("root"),a=await this.#o(o),f=a.headers.get(ft);if(f)return[await a.text(),BigInt(f)];throw new Error("no generation header in root hash")}catch(o){throw this.#t=null,o}})();this.#t=t;let[n,i]=await t;return[n,i]}async putRootHash(r,t){let n=await this.#a("root",t,r),i;try{i=await this.#o(n,r,{[sr]:`${t}`})}catch(f){throw f instanceof W&&f.status===412?(this.#t=null,new ke):f}let o=i.headers.get(ft);if(!o)throw new Error("no generation header in root hash");let a=BigInt(o);return this.#t=Promise.resolve([r,a]),a}async#u(r){let t=this.#e.get(r);for(;t;)try{let i=await t;if(i)return i;t=void 0}catch{t=this.#e.get(r)}let n=(async()=>{let i=await this.#a(r);return await(await this.#o(i)).arrayBuffer()})();return this.#e.set(r,n.then(i=>i.byteLength<this.#n?i:null,i=>{throw this.#e.delete(r),i})),await n}async getBuffer(r){let t=await this.#u(r);return t.byteLength<this.#n?t.slice(0):t}async getText(r){let t=await this.#u(r);return new TextDecoder().decode(t)}async getJson(r){let t=await this.getText(r);return JSON.parse(t)}async getMetadata(r){let t=await this.getJson(r);return ee(yr,t),t}async getEntries(r){if(r===void 0){let[o]=await this.getRootHash({cache:!0});r=o}let t=await this.getText(r),[n,...i]=t.slice(0,-1).split(`
11
- `);if(n!==st)throw new Error(`got unexpected schema version: ${n}`);return i.map(gr)}async#c(r,t){let n=this.#e.get(r);if(n)try{await n;return}catch{}let i=(async()=>{try{let o=await this.#a(r,null);return await this.#o(o,t),t.byteLength<this.#n?t:null}catch(o){throw this.#e.delete(r),o}})();this.#e.set(r,i),await i}async putEntries(r,t){let n=new TextEncoder;t.sort((l,m)=>l.documentId.localeCompare(m.documentId));let i=Ye(t.map(l=>We(l.hash))),o=await this.#f.digest("SHA-256",i),a=Te(o),f=t.map(hr).join(""),s=`${st}
12
- ${f}`,c=n.encode(s);return await this.#c(a,c),{hash:a,type:"80000000",documentId:r,subfiles:t.length,size:0n}}async putBuffer(r,t){let n=await this.#f.digest("SHA-256",t),i=Te(n);return await this.#c(i,t),{hash:i,type:"0",documentId:r,subfiles:0,size:BigInt(t.byteLength)}}async putText(r,t){let n=new TextEncoder;return await this.putBuffer(r,n.encode(t))}async putJson(r,t){return await this.putText(r,(0,ct.default)(t))}async putMetadata(r,t){return await this.putJson(`${r}.metadata`,t)}async putCollection(r,t=""){let n=Q(),i=`${new Date().valueOf()}`,o=[],a={type:"CollectionType",visibleName:r,version:0,parent:t,synced:!0,lastModified:i};o.push(this.putMetadata(n,a)),o.push(this.putText(`${n}.content`,"{}"));let f=await Promise.all(o);return await this.putEntries(n,f)}async#d(r,t,n,i,o){if(o.fileType!==n)throw new Error(`internal error: fileTypes don't match: ${n}, ${o.fileType}`);let a=Q(),f=`${new Date().valueOf()}`,s=[];s.push(this.putBuffer(`${a}.${n}`,t));let c={type:"DocumentType",visibleName:r,version:0,parent:i,synced:!0,lastModified:f};s.push(this.putMetadata(a,c)),s.push(this.putText(`${a}.content`,JSON.stringify(o)));let l=await Promise.all(s);return await this.putEntries(a,l)}async putEpub(r,t,{parent:n="",margins:i=125,orientation:o,textAlignment:a,textScale:f=1,lineHeight:s=-1,fontName:c="",cover:l="visited",lastTool:m}={}){let g={dummyDocument:!1,extraMetadata:{LastTool:m},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof s=="string"?cr[s]:s,margins:typeof i=="string"?ur[i]:i,textScale:typeof f=="string"?lr[f]:f,pages:[],coverPageNumber:l==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:a,fontName:c};return await this.#d(r,t,"epub",n,g)}async putPdf(r,t,{parent:n="",orientation:i,cover:o="first",lastTool:a}={}){let f={dummyDocument:!1,extraMetadata:{LastTool:a},fileType:"pdf",pageCount:0,lastOpenedPage:0,lineHeight:-1,margins:125,textScale:1,pages:[],coverPageNumber:o==="first"?0:-1,formatVersion:1,orientation:i};return await this.#d(r,t,"pdf",n,f)}async syncComplete(r){let t=`{ "generation": ${r} }`;await this.#i(`${this.#r}/sync/v2/sync-complete`,{body:t})}async#p(r,t,n){let{hash:i}=await this.putEntries("",t),o=await this.putRootHash(i,r);if(n)try{return await this.syncComplete(o),!0}catch{return!1}else return!1}async create(r,{cache:t=!0,sync:n=!0}={}){let[i,o]=await this.getRootHash({cache:t}),a=await this.getEntries(i);return a.push(r),await this.#p(o,a,n)}async move(r,t,{cache:n=!0,sync:i=!0}={}){let[o,a]=await this.getRootHash({cache:n}),f=await this.getEntries(o);if(!(!t||t==="trash")){let k=f.find(Y=>Y.documentId===t);if(k){if(k.type!=="80000000")throw new Error(`destination id was a raw file: ${t}`)}else throw new Error(`destination id not found: ${t}`);let C=await this.getEntries(k.hash),[b]=C.filter(Y=>Y.documentId===`${t}.metadata`);if(!b)throw new Error(`destination id didn't have metadata: ${t}`);if((await this.getMetadata(b.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${t}`)}let s=f.findIndex(k=>k.documentId===r);if(s===-1)throw new Error(`document not found: ${r}`);let[c]=f.splice(s,1);if(c.type!=="80000000")throw new Error(`document was a raw file: ${r}`);let l=await this.getEntries(c.hash),m=l.findIndex(k=>k.documentId===`${r}.metadata`);if(m===-1)throw new Error(`document didn't have metadata: ${r}`);let[g]=l.splice(m,1),p=await this.getMetadata(g.hash);p.parent=t;let h=await this.putMetadata(r,p);l.push(h);let U=await this.putEntries(r,l);return f.push(U),await this.#p(a,f,i)}async getEntriesMetadata(){let t=await(await this.#i(`${this.#r}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),n=JSON.parse(t);return ee({elements:mr},n),n}async#y(r,t,n){let o=new TextEncoder().encode(JSON.stringify({file_name:r})),f=await(await this.#i(`${this.#r}/doc/v2/files`,{body:t,headers:{"content-type":n,"rm-meta":(0,ut.fromByteArray)(o),"rm-source":"RoR-Browser"}})).text(),s=JSON.parse(f);return ee(dr,s),s}async uploadEpub(r,t){return await this.#y(r,t,"application/epub+zip")}async uploadPdf(r,t){return await this.#y(r,t,"application/pdf")}async getCache(){let r=[];for(let[i,o]of this.#e)r.push(o.then(a=>[i,a],()=>[i,null]));let t=await Promise.all(r),n=new Map;for(let[i,o]of t)o&&n.set(i,o);return n}};async function jn(e,{fetch:r=globalThis.fetch,subtle:t=globalThis.crypto?.subtle,authHost:n=dt,syncHost:i=ar,cacheLimitBytes:o=1048576,initCache:a=[]}={}){if(!t)throw new Error("subtle was missing, try specifying it manually");let f=await r(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!f.ok)throw new Error(`couldn't fetch auth token: ${f.statusText}`);let s=await f.text();return new Me(s,r,t,i,o,a)}export{ke as GenerationError,W as ResponseError,Cn as builtinFontNames,cr as builtinLineHeights,ur as builtinMargins,lr as builtinTextScales,Mn as builtinTools,hr as formatEntry,gr as parseEntry,Fn as register,jn as remarkable};
1
+ var Xe=Object.create;var we=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty;var S=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var it=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of tt(t))!nt.call(e,i)&&i!==r&&we(e,i,{get:()=>t[i],enumerable:!(n=et(t,i))||n.enumerable});return e};var oe=(e,t,r)=>(r=e!=null?Xe(rt(e)):{},it(t||!e||!e.__esModule?we(r,"default",{value:e,enumerable:!0}):r,e));var Ee=S(Y=>{"use strict";Y.byteLength=st;Y.toByteArray=ft;Y.fromByteArray=ct;var O=[],T=[],ot=typeof Uint8Array<"u"?Uint8Array:Array,se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(B=0,ve=se.length;B<ve;++B)O[B]=se[B],T[se.charCodeAt(B)]=B;var B,ve;T["-".charCodeAt(0)]=62;T["_".charCodeAt(0)]=63;function xe(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function st(e){var t=xe(e),r=t[0],n=t[1];return(r+n)*3/4-n}function at(e,t,r){return(t+r)*3/4-r}function ft(e){var t,r=xe(e),n=r[0],i=r[1],o=new ot(at(e,n,i)),a=0,f=i>0?n-4:n,s;for(s=0;s<f;s+=4)t=T[e.charCodeAt(s)]<<18|T[e.charCodeAt(s+1)]<<12|T[e.charCodeAt(s+2)]<<6|T[e.charCodeAt(s+3)],o[a++]=t>>16&255,o[a++]=t>>8&255,o[a++]=t&255;return i===2&&(t=T[e.charCodeAt(s)]<<2|T[e.charCodeAt(s+1)]>>4,o[a++]=t&255),i===1&&(t=T[e.charCodeAt(s)]<<10|T[e.charCodeAt(s+1)]<<4|T[e.charCodeAt(s+2)]>>2,o[a++]=t>>8&255,o[a++]=t&255),o}function ut(e){return O[e>>18&63]+O[e>>12&63]+O[e>>6&63]+O[e&63]}function lt(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(ut(n));return i.join("")}function ct(e){for(var t,r=e.length,n=r%3,i=[],o=16383,a=0,f=r-n;a<f;a+=o)i.push(lt(e,a,a+o>f?f:a+o));return n===1?(t=e[r-1],i.push(O[t>>2]+O[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(O[t>>10]+O[t>>4&63]+O[t<<2&63]+"=")),i.join("")}});var Se=S((Yt,Oe)=>{"use strict";var Z,l,Pe={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
2
+ `,r:"\r",t:" "},ae;function M(e){throw{name:"SyntaxError",message:e,at:Z,text:ae}}function c(e){return e&&e!==l&&M("Expected '"+e+"' instead of '"+l+"'"),l=ae.charAt(Z),Z+=1,l}function Te(){var e,t="";for(l==="-"&&(t="-",c("-"));l>="0"&&l<="9";)t+=l,c();if(l===".")for(t+=".";c()&&l>="0"&&l<="9";)t+=l;if(l==="e"||l==="E")for(t+=l,c(),(l==="-"||l==="+")&&(t+=l,c());l>="0"&&l<="9";)t+=l,c();return e=Number(t),isFinite(e)||M("Bad number"),e}function Ae(){var e,t,r="",n;if(l==='"')for(;c();){if(l==='"')return c(),r;if(l==="\\")if(c(),l==="u"){for(n=0,t=0;t<4&&(e=parseInt(c(),16),!!isFinite(e));t+=1)n=n*16+e;r+=String.fromCharCode(n)}else if(typeof Pe[l]=="string")r+=Pe[l];else break;else r+=l}M("Bad string")}function k(){for(;l&&l<=" ";)c()}function pt(){switch(l){case"t":return c("t"),c("r"),c("u"),c("e"),!0;case"f":return c("f"),c("a"),c("l"),c("s"),c("e"),!1;case"n":return c("n"),c("u"),c("l"),c("l"),null;default:M("Unexpected '"+l+"'")}}function dt(){var e=[];if(l==="["){if(c("["),k(),l==="]")return c("]"),e;for(;l;){if(e.push(K()),k(),l==="]")return c("]"),e;c(","),k()}}M("Bad array")}function yt(){var e,t={};if(l==="{"){if(c("{"),k(),l==="}")return c("}"),t;for(;l;){if(e=Ae(),k(),c(":"),Object.prototype.hasOwnProperty.call(t,e)&&M('Duplicate key "'+e+'"'),t[e]=K(),k(),l==="}")return c("}"),t;c(","),k()}}M("Bad object")}function K(){switch(k(),l){case"{":return yt();case"[":return dt();case'"':return Ae();case"-":return Te();default:return l>="0"&&l<="9"?Te():pt()}}Oe.exports=function(e,t){var r;return ae=e,Z=0,l=" ",r=K(),k(),l&&M("Syntax error"),typeof t=="function"?function n(i,o){var a,f,s=i[o];if(s&&typeof s=="object")for(a in K)Object.prototype.hasOwnProperty.call(s,a)&&(f=n(s,a),typeof f>"u"?delete s[a]:s[a]=f);return t.call(i,o,s)}({"":r},""):r}});var Fe=S((Zt,ke)=>{"use strict";var fe=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,E,W,mt={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},R;function ue(e){return fe.lastIndex=0,fe.test(e)?'"'+e.replace(fe,function(t){var r=mt[t];return typeof r=="string"?r:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function Q(e,t){var r,n,i,o,a=E,f,s=t[e];switch(s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON(e)),typeof R=="function"&&(s=R.call(t,e,s)),typeof s){case"string":return ue(s);case"number":return isFinite(s)?String(s):"null";case"boolean":case"null":return String(s);case"object":if(!s)return"null";if(E+=W,f=[],Object.prototype.toString.apply(s)==="[object Array]"){for(o=s.length,r=0;r<o;r+=1)f[r]=Q(r,s)||"null";return i=f.length===0?"[]":E?`[
3
+ `+E+f.join(`,
4
+ `+E)+`
5
+ `+a+"]":"["+f.join(",")+"]",E=a,i}if(R&&typeof R=="object")for(o=R.length,r=0;r<o;r+=1)n=R[r],typeof n=="string"&&(i=Q(n,s),i&&f.push(ue(n)+(E?": ":":")+i));else for(n in s)Object.prototype.hasOwnProperty.call(s,n)&&(i=Q(n,s),i&&f.push(ue(n)+(E?": ":":")+i));return i=f.length===0?"{}":E?`{
6
+ `+E+f.join(`,
7
+ `+E)+`
8
+ `+a+"}":"{"+f.join(",")+"}",E=a,i;default:}}ke.exports=function(e,t,r){var n;if(E="",W="",typeof r=="number")for(n=0;n<r;n+=1)W+=" ";else typeof r=="string"&&(W=r);if(R=t,t&&typeof t!="function"&&(typeof t!="object"||typeof t.length!="number"))throw new Error("JSON.stringify");return Q("",{"":e})}});var Me=S(le=>{"use strict";le.parse=Se();le.stringify=Fe()});var je=S((Wt,Ce)=>{"use strict";var X=typeof JSON<"u"?JSON:Me(),ht=Array.isArray||function(e){return{}.toString.call(e)==="[object Array]"},gt=Object.keys||function(e){var t=Object.prototype.hasOwnProperty||function(){return!0},r=[];for(var n in e)t.call(e,n)&&r.push(n);return r};Ce.exports=function(e,t){t||(t={}),typeof t=="function"&&(t={cmp:t});var r=t.space||"";typeof r=="number"&&(r=Array(r+1).join(" "));var n=typeof t.cycles=="boolean"?t.cycles:!1,i=t.replacer||function(f,s){return s},o=t.cmp&&function(f){return function(s){return function(p,u){var g={key:p,value:s[p]},x={key:u,value:s[u]};return f(g,x)}}}(t.cmp),a=[];return function f(s,p,u,g){var x=r?`
9
+ `+new Array(g+1).join(r):"",F=r?": ":":";if(u&&u.toJSON&&typeof u.toJSON=="function"&&(u=u.toJSON()),u=i.call(s,p,u),u!==void 0){if(typeof u!="object"||u===null)return X.stringify(u);if(ht(u)){for(var A=[],y=0;y<u.length;y++){var J=f(u,y,u[y],g+1)||X.stringify(null);A.push(x+r+J)}return"["+A.join(",")+x+"]"}if(a.indexOf(u)!==-1){if(n)return X.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}else a.push(u);for(var P=gt(u).sort(o&&o(u)),A=[],y=0;y<P.length;y++){var p=P[y],m=f(u,p,u[p],g+1);if(m){var G=X.stringify(p)+F+m;A.push(x+r+G)}}return a.splice(a.indexOf(u),1),"{"+A.join(",")+x+"}"}}({"":e},"",e,0)}});var me=S(d=>{"use strict";var _e=d&&d.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r};Object.defineProperty(d,"__esModule",{value:!0});d.isSchema=d.isValidSchema=d.isDiscriminatorForm=d.isValuesForm=d.isPropertiesForm=d.isElementsForm=d.isEnumForm=d.isTypeForm=d.isRefForm=d.isEmptyForm=void 0;function xt(e){let{definitions:t,nullable:r,metadata:n}=e,i=_e(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=xt;function Ne(e){return"ref"in e}d.isRefForm=Ne;function Et(e){return"type"in e}d.isTypeForm=Et;function $e(e){return"enum"in e}d.isEnumForm=$e;function Le(e){return"elements"in e}d.isElementsForm=Le;function ye(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=ye;function De(e){return"values"in e}d.isValuesForm=De;function He(e){return"discriminator"in e}d.isDiscriminatorForm=He;function I(e,t){if(t===void 0&&(t=e),e.definitions!==void 0){if(t!==e)return!1;for(let r of Object.values(e.definitions))if(!I(r,t))return!1}if(Ne(e)&&!(e.ref in(t.definitions||{}))||$e(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Le(e))return I(e.elements,t);if(ye(e)){for(let r of Object.values(e.properties||{}))if(!I(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!I(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(De(e))return I(e.values,t);if(He(e)){for(let r of Object.values(e.mapping))if(!I(r,t)||!ye(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}d.isValidSchema=I;var Pt=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],Tt=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function _(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let t=e,{definitions:r=void 0,nullable:n=void 0,metadata:i=void 0,ref:o=void 0,type:a=void 0,enum:f=void 0,elements:s=void 0,properties:p=void 0,optionalProperties:u=void 0,additionalProperties:g=void 0,values:x=void 0,discriminator:F=void 0,mapping:y=void 0}=t,J=_e(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),P=[o!==void 0,a!==void 0,f!==void 0,s!==void 0,p!==void 0,u!==void 0,g!==void 0,x!==void 0,F!==void 0,y!==void 0],A=!1;for(let m of Pt)A=A||m.every((G,V)=>G===P[V]);if(!A)return!1;if(r!==void 0){if(typeof r!="object"||Array.isArray(r)||r===null)return!1;for(let m of Object.values(r))if(!_(m))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||o!==void 0&&typeof o!="string"||a!==void 0&&(typeof a!="string"||!Tt.includes(a))||f!==void 0&&(!Array.isArray(f)||!f.every(m=>typeof m=="string"))||s!==void 0&&!_(s))return!1;if(p!==void 0){if(typeof p!="object"||Array.isArray(p)||p===null)return!1;for(let m of Object.values(p))if(!_(m))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let m of Object.values(u))if(!_(m))return!1}if(g!==void 0&&typeof g!="boolean"||x!==void 0&&!_(x)||F!==void 0&&typeof F!="string")return!1;if(y!==void 0){if(typeof y!="object"||Array.isArray(y)||y===null)return!1;for(let m of Object.values(y))if(!_(m))return!1}return Object.keys(J).length===0}d.isSchema=_});var Ue=S(he=>{"use strict";Object.defineProperty(he,"__esModule",{value:!0});var At=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Ot(e){let t=e.match(At);if(t===null)return!1;let r=parseInt(t[1],10),n=parseInt(t[2],10),i=parseInt(t[3],10),o=parseInt(t[4],10),a=parseInt(t[5],10),f=parseInt(t[6],10);return!(n>12||i>St(r,n)||o>23||a>59||f>60)}he.default=Ot;function St(e,t){return t===2?kt(e)?29:28:Ft[t]}function kt(e){return e%4===0&&(e%100!==0||e%400===0)}var Ft=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Je=S(C=>{"use strict";var Mt=C&&C.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(C,"__esModule",{value:!0});C.validate=C.MaxDepthExceededError=void 0;var Ct=Mt(Ue()),N=me(),te=class extends Error{};C.MaxDepthExceededError=te;var re=class extends Error{};function jt(e,t,r){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{D(n,e,t)}catch(i){if(!(i instanceof re))throw i}return n.errors}C.validate=jt;function D(e,t,r,n){if(!(t.nullable&&r===null)){if(N.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new te;e.schemaTokens.push(["definitions",t.ref]),D(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if(N.isTypeForm(t)){switch(b(e,"type"),t.type){case"boolean":typeof r!="boolean"&&w(e);break;case"float32":case"float64":typeof r!="number"&&w(e);break;case"int8":H(e,r,-128,127);break;case"uint8":H(e,r,0,255);break;case"int16":H(e,r,-32768,32767);break;case"uint16":H(e,r,0,65535);break;case"int32":H(e,r,-2147483648,2147483647);break;case"uint32":H(e,r,0,4294967295);break;case"string":typeof r!="string"&&w(e);break;case"timestamp":typeof r!="string"?w(e):Ct.default(r)||w(e);break}v(e)}else if(N.isEnumForm(t))b(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&w(e),v(e);else if(N.isElementsForm(t)){if(b(e,"elements"),Array.isArray(r))for(let[i,o]of r.entries())$(e,i.toString()),D(e,t.elements,o),L(e);else w(e);v(e)}else if(N.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){b(e,"properties");for(let[i,o]of Object.entries(t.properties))b(e,i),r.hasOwnProperty(i)?($(e,i),D(e,o,r[i]),L(e)):w(e),v(e);v(e)}if(t.optionalProperties!==void 0){b(e,"optionalProperties");for(let[i,o]of Object.entries(t.optionalProperties))b(e,i),r.hasOwnProperty(i)&&($(e,i),D(e,o,r[i]),L(e)),v(e);v(e)}if(t.additionalProperties!==!0)for(let i of Object.keys(r)){let o=t.properties&&i in t.properties,a=t.optionalProperties&&i in t.optionalProperties;!o&&!a&&i!==n&&($(e,i),w(e),L(e))}}else t.properties!==void 0?b(e,"properties"):b(e,"optionalProperties"),w(e),v(e);else if(N.isValuesForm(t)){if(b(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[i,o]of Object.entries(r))$(e,i),D(e,t.values,o),L(e);else w(e);v(e)}else if(N.isDiscriminatorForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r))if(r.hasOwnProperty(t.discriminator)){let i=r[t.discriminator];typeof i=="string"?i in t.mapping?(b(e,"mapping"),b(e,i),D(e,t.mapping[i],r,t.discriminator),v(e),v(e)):(b(e,"mapping"),$(e,t.discriminator),w(e),L(e),v(e)):(b(e,"discriminator"),$(e,t.discriminator),w(e),L(e),v(e))}else b(e,"discriminator"),w(e),v(e);else b(e,"discriminator"),w(e),v(e)}}function H(e,t,r,n){(typeof t!="number"||!Number.isInteger(t)||t<r||t>n)&&w(e)}function $(e,t){e.instanceTokens.push(t)}function L(e){e.instanceTokens.pop()}function b(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function v(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function w(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new re}});var qe=S(j=>{"use strict";var Bt=j&&j.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),Ve=j&&j.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&Bt(t,e,r)};Object.defineProperty(j,"__esModule",{value:!0});Ve(me(),j);Ve(Je(),j)});var Ke=oe(Ee()),We=oe(je());var ee,bt=new Uint8Array(16);function ce(){if(!ee&&(ee=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ee))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ee(bt)}var h=[];for(let e=0;e<256;++e)h.push((e+256).toString(16).slice(1));function Be(e,t=0){return(h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]).toLowerCase()}var wt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),pe={randomUUID:wt};function vt(e,t,r){if(pe.randomUUID&&!t&&!e)return pe.randomUUID();e=e||{};let n=e.random||(e.rng||ce)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){r=r||0;for(let i=0;i<16;++i)t[r+i]=n[i];return t}return Be(n)}var q=vt;function de(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}function Re(e){return new Uint8Array((e.match(/../g)??[]).map(t=>parseInt(t,16)))}function Ie(e){let t=0;for(let i of e)t+=i.length;let r=new Uint8Array(t),n=0;for(let i of e)r.set(i,n),n+=i.length;return r}var ze=oe(qe());function z(e,t){if((0,ze.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var Ge="3",Qe="https://webapp-prod.cloud.remarkable.engineering",Rt="https://internal.cloud.remarkable.com",Ye="x-goog-generation",It="x-goog-if-generation-match",_t="x-goog-content-length-range",gr=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],br=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Nt={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},$t={sm:50,md:125,rr:180,lg:200},Lt={df:-1,md:100,lg:150,xl:200},Dt={properties:{docID:{type:"string"},hash:{type:"string"}}},Ht={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},ne={visibleName:{type:"string"},lastModified:{type:"string"}},ie={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},Ut={discriminator:"type",mapping:{CollectionType:{properties:ne,optionalProperties:ie},DocumentType:{properties:ne,optionalProperties:{...ie,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},Ze={id:{type:"string"},hash:{type:"string"}},Jt={discriminator:"type",mapping:{CollectionType:{properties:{...ne,...Ze},optionalProperties:ie},DocumentType:{properties:{...ne,...Ze,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...ie,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},U=class extends Error{status;statusText;constructor(t,r,n){super(n),this.status=t,this.statusText=r}},ge=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function wr(e,{deviceDesc:t="browser-chrome",uuid:r=q(),authHost:n=Qe,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:t,deviceID:r})});if(o.ok)return await o.text();throw new U(o.status,o.statusText,"couldn't register api")}function Vt({hash:e,type:t,documentId:r,subfiles:n,size:i}){return`${e}:${t}:${r}:${n}:${i}
10
+ `}function qt(e){let[t,r,n,i,o]=e.split(":");if(t===void 0||r===void 0||n===void 0||i===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(r==="80000000")return{hash:t,type:r,documentId:n,subfiles:parseInt(i),size:BigInt(o)};if(r==="0"){if(i!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${i}`);return{hash:t,type:r,documentId:n,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${r}`)}var be=class{#u;#a;#f;#r;#n;#e=new Map;#t=null;constructor(t,r,n,i,o,a){this.#u=t,this.#a=r,this.#f=n,this.#r=i,this.#n=o;for(let[f,s]of a)this.#e.set(f,Promise.resolve(s))}async#i(t,{body:r,method:n="POST",headers:i={}}){let o=await this.#a(t,{method:n,headers:{Authorization:`Bearer ${this.#u}`,...i},body:r});if(o.ok)return o;{let a=await o.text();throw new U(o.status,o.statusText,`failed reMarkable request: ${a}`)}}async#o({url:t,method:r,maxuploadsize_bytes:n},i,o={}){let a=n?{...o,[_t]:`0,${n}`}:o,f=await this.#a(t,{method:r,body:i,headers:a});if(f.ok)return f;{let s=await f.text();throw new U(f.status,f.statusText,s)}}async#s(t,r,n){let i=r===void 0?"downloads":"uploads",o=n&&r!==null&&r!==void 0?`{ "http_method": "PUT", "relative_path": "${t}", "root_schema": "${n}", "generation": ${r} }`:JSON.stringify({http_method:"GET",relative_path:t}),f=await(await this.#i(`${this.#r}/sync/v2/signed-urls/${i}`,{body:o})).text(),s=JSON.parse(f);return z(Ht,s),s}async getRootHash({cache:t=!0}={}){if(t)for(;this.#t;)try{let[o,a]=await this.#t;return[o,a]}catch{}let r=(async()=>{try{let o=await this.#s("root"),a=await this.#o(o),f=a.headers.get(Ye);if(f)return[await a.text(),BigInt(f)];throw new Error("no generation header in root hash")}catch(o){throw this.#t=null,o}})();this.#t=r;let[n,i]=await r;return[n,i]}async putRootHash(t,r){let n=await this.#s("root",r,t),i;try{i=await this.#o(n,t,{[It]:`${r}`})}catch(f){throw f instanceof U&&f.status===412?(this.#t=null,new ge):f}let o=i.headers.get(Ye);if(!o)throw new Error("no generation header in root hash");let a=BigInt(o);return this.#t=Promise.resolve([t,a]),a}async#l(t){let r=this.#e.get(t);for(;r;)try{let i=await r;if(i)return i;r=void 0}catch{r=this.#e.get(t)}let n=(async()=>{let i=await this.#s(t);return await(await this.#o(i)).arrayBuffer()})();return this.#e.set(t,n.then(i=>i.byteLength<this.#n?i:null,i=>{throw this.#e.delete(t),i})),await n}async getBuffer(t){let r=await this.#l(t);return r.byteLength<this.#n?r.slice(0):r}async getText(t){let r=await this.#l(t);return new TextDecoder().decode(r)}async getJson(t){let r=await this.getText(t);return JSON.parse(r)}async getMetadata(t){let r=await this.getJson(t);return z(Ut,r),r}async getEntries(t){if(t===void 0){let[o]=await this.getRootHash({cache:!0});t=o}let r=await this.getText(t),[n,...i]=r.slice(0,-1).split(`
11
+ `);if(n!==Ge)throw new Error(`got unexpected schema version: ${n}`);return i.map(qt)}async#c(t,r){let n=this.#e.get(t);if(n)try{await n;return}catch{}let i=(async()=>{try{let o=await this.#s(t,null);return await this.#o(o,r),r.byteLength<this.#n?r:null}catch(o){throw this.#e.delete(t),o}})();this.#e.set(t,i),await i}async putEntries(t,r){let n=new TextEncoder;r.sort((u,g)=>u.documentId.localeCompare(g.documentId));let i=Ie(r.map(u=>Re(u.hash))),o=await this.#f.digest("SHA-256",i),a=de(o),f=r.map(Vt).join(""),s=`${Ge}
12
+ ${f}`,p=n.encode(s);return await this.#c(a,p),{hash:a,type:"80000000",documentId:t,subfiles:r.length,size:0n}}async putBuffer(t,r){let n=await this.#f.digest("SHA-256",r),i=de(n);return await this.#c(i,r),{hash:i,type:"0",documentId:t,subfiles:0,size:BigInt(r.byteLength)}}async putText(t,r){let n=new TextEncoder;return await this.putBuffer(t,n.encode(r))}async putJson(t,r){return await this.putText(t,(0,We.default)(r))}async putMetadata(t,r){return await this.putJson(`${t}.metadata`,r)}async putCollection(t,r=""){let n=q(),i=`${new Date().valueOf()}`,o=[],a={type:"CollectionType",visibleName:t,version:0,parent:r,synced:!0,lastModified:i};o.push(this.putMetadata(n,a)),o.push(this.putText(`${n}.content`,"{}"));let f=await Promise.all(o);return await this.putEntries(n,f)}async#p(t,r,n,i,o){if(o.fileType!==n)throw new Error(`internal error: fileTypes don't match: ${n}, ${o.fileType}`);let a=q(),f=`${new Date().valueOf()}`,s=[];s.push(this.putBuffer(`${a}.${n}`,r));let p={type:"DocumentType",visibleName:t,version:0,parent:i,synced:!0,lastModified:f};s.push(this.putMetadata(a,p)),s.push(this.putText(`${a}.content`,JSON.stringify(o)));let u=await Promise.all(s);return await this.putEntries(a,u)}async putEpub(t,r,{parent:n="",margins:i=125,orientation:o,textAlignment:a,textScale:f=1,lineHeight:s=-1,fontName:p="",cover:u="visited",lastTool:g}={}){let x={dummyDocument:!1,extraMetadata:{LastTool:g},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof s=="string"?Lt[s]:s,margins:typeof i=="string"?$t[i]:i,textScale:typeof f=="string"?Nt[f]:f,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:a,fontName:p};return await this.#p(t,r,"epub",n,x)}async putPdf(t,r,{parent:n="",orientation:i,cover:o="first",lastTool:a}={}){let f={dummyDocument:!1,extraMetadata:{LastTool:a},fileType:"pdf",pageCount:0,lastOpenedPage:0,lineHeight:-1,margins:125,textScale:1,pages:[],coverPageNumber:o==="first"?0:-1,formatVersion:1,orientation:i};return await this.#p(t,r,"pdf",n,f)}async syncComplete(t){let r=`{ "generation": ${t} }`;await this.#i(`${this.#r}/sync/v2/sync-complete`,{body:r})}async#d(t,r,n){let{hash:i}=await this.putEntries("",r),o=await this.putRootHash(i,t);if(n)try{return await this.syncComplete(o),!0}catch{return!1}else return!1}async create(t,{cache:r=!0,sync:n=!0}={}){let[i,o]=await this.getRootHash({cache:r}),a=await this.getEntries(i);return a.push(t),await this.#d(o,a,n)}async move(t,r,{cache:n=!0,sync:i=!0}={}){let[o,a]=await this.getRootHash({cache:n}),f=await this.getEntries(o);if(!(!r||r==="trash")){let P=f.find(V=>V.documentId===r);if(P){if(P.type!=="80000000")throw new Error(`destination id was a raw file: ${r}`)}else throw new Error(`destination id not found: ${r}`);let A=await this.getEntries(P.hash),[m]=A.filter(V=>V.documentId===`${r}.metadata`);if(!m)throw new Error(`destination id didn't have metadata: ${r}`);if((await this.getMetadata(m.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${r}`)}let s=f.findIndex(P=>P.documentId===t);if(s===-1)throw new Error(`document not found: ${t}`);let[p]=f.splice(s,1);if(p.type!=="80000000")throw new Error(`document was a raw file: ${t}`);let u=await this.getEntries(p.hash),g=u.findIndex(P=>P.documentId===`${t}.metadata`);if(g===-1)throw new Error(`document didn't have metadata: ${t}`);let[x]=u.splice(g,1),F=await this.getMetadata(x.hash);F.parent=r;let y=await this.putMetadata(t,F);u.push(y);let J=await this.putEntries(t,u);return f.push(J),await this.#d(a,f,i)}async getEntriesMetadata(){let r=await(await this.#i(`${this.#r}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),n=JSON.parse(r);return z({elements:Jt},n),n}async#y(t,r,n){let o=new TextEncoder().encode(JSON.stringify({file_name:t})),f=await(await this.#i(`${this.#r}/doc/v2/files`,{body:r,headers:{"content-type":n,"rm-meta":(0,Ke.fromByteArray)(o),"rm-source":"RoR-Browser"}})).text(),s=JSON.parse(f);return z(Dt,s),s}async uploadEpub(t,r){return await this.#y(t,r,"application/epub+zip")}async uploadPdf(t,r){return await this.#y(t,r,"application/pdf")}async getCache(){let t=[];for(let[i,o]of this.#e)t.push(o.then(a=>[i,a],()=>[i,null]));let r=await Promise.all(t),n=new Map;for(let[i,o]of r)o&&n.set(i,o);return n}};async function vr(e,{fetch:t=globalThis.fetch,subtle:r=globalThis.crypto?.subtle,authHost:n=Qe,syncHost:i=Rt,cacheLimitBytes:o=1048576,initCache:a=[]}={}){if(!r)throw new Error("subtle was missing, try specifying it manually");let f=await t(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!f.ok)throw new Error(`couldn't fetch auth token: ${f.statusText}`);let s=await f.text();return new be(s,t,r,i,o,a)}export{ge as GenerationError,U as ResponseError,br as builtinFontNames,Lt as builtinLineHeights,$t as builtinMargins,Nt as builtinTextScales,gr as builtinTools,Vt as formatEntry,qt as parseEntry,wr as register,vr as remarkable};
@@ -1,12 +1,12 @@
1
- var rmapi=(()=>{var wt=Object.create;var re=Object.defineProperty;var vt=Object.getOwnPropertyDescriptor;var xt=Object.getOwnPropertyNames;var Et=Object.getPrototypeOf,Pt=Object.prototype.hasOwnProperty;var j=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Tt=(e,r)=>{for(var t in r)re(e,t,{get:r[t],enumerable:!0})},Fe=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of xt(r))!Pt.call(e,i)&&i!==t&&re(e,i,{get:()=>r[i],enumerable:!(n=vt(r,i))||n.enumerable});return e};var ge=(e,r,t)=>(t=e!=null?wt(Et(e)):{},Fe(r||!e||!e.__esModule?re(t,"default",{value:e,enumerable:!0}):t,e)),At=e=>Fe(re({},"__esModule",{value:!0}),e);var Ie=j(ne=>{"use strict";ne.byteLength=St;ne.toByteArray=Mt;ne.fromByteArray=jt;var F=[],M=[],Ot=typeof Uint8Array<"u"?Uint8Array:Array,be="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(L=0,je=be.length;L<je;++L)F[L]=be[L],M[be.charCodeAt(L)]=L;var L,je;M["-".charCodeAt(0)]=62;M["_".charCodeAt(0)]=63;function Be(e){var r=e.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var t=e.indexOf("=");t===-1&&(t=r);var n=t===r?0:4-t%4;return[t,n]}function St(e){var r=Be(e),t=r[0],n=r[1];return(t+n)*3/4-n}function kt(e,r,t){return(r+t)*3/4-t}function Mt(e){var r,t=Be(e),n=t[0],i=t[1],o=new Ot(kt(e,n,i)),a=0,f=i>0?n-4:n,s;for(s=0;s<f;s+=4)r=M[e.charCodeAt(s)]<<18|M[e.charCodeAt(s+1)]<<12|M[e.charCodeAt(s+2)]<<6|M[e.charCodeAt(s+3)],o[a++]=r>>16&255,o[a++]=r>>8&255,o[a++]=r&255;return i===2&&(r=M[e.charCodeAt(s)]<<2|M[e.charCodeAt(s+1)]>>4,o[a++]=r&255),i===1&&(r=M[e.charCodeAt(s)]<<10|M[e.charCodeAt(s+1)]<<4|M[e.charCodeAt(s+2)]>>2,o[a++]=r>>8&255,o[a++]=r&255),o}function Ct(e){return F[e>>18&63]+F[e>>12&63]+F[e>>6&63]+F[e&63]}function Ft(e,r,t){for(var n,i=[],o=r;o<t;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(Ct(n));return i.join("")}function jt(e){for(var r,t=e.length,n=t%3,i=[],o=16383,a=0,f=t-n;a<f;a+=o)i.push(Ft(e,a,a+o>f?f:a+o));return n===1?(r=e[t-1],i.push(F[r>>2]+F[r<<4&63]+"==")):n===2&&(r=(e[t-2]<<8)+e[t-1],i.push(F[r>>10]+F[r>>4&63]+F[r<<2&63]+"=")),i.join("")}});var Le=j((Sr,Ue)=>{"use strict";var ie,u,Re={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
2
- `,r:"\r",t:" "},we;function I(e){throw{name:"SyntaxError",message:e,at:ie,text:we}}function d(e){return e&&e!==u&&I("Expected '"+e+"' instead of '"+u+"'"),u=we.charAt(ie),ie+=1,u}function _e(){var e,r="";for(u==="-"&&(r="-",d("-"));u>="0"&&u<="9";)r+=u,d();if(u===".")for(r+=".";d()&&u>="0"&&u<="9";)r+=u;if(u==="e"||u==="E")for(r+=u,d(),(u==="-"||u==="+")&&(r+=u,d());u>="0"&&u<="9";)r+=u,d();return e=Number(r),isFinite(e)||I("Bad number"),e}function Ne(){var e,r,t="",n;if(u==='"')for(;d();){if(u==='"')return d(),t;if(u==="\\")if(d(),u==="u"){for(n=0,r=0;r<4&&(e=parseInt(d(),16),!!isFinite(e));r+=1)n=n*16+e;t+=String.fromCharCode(n)}else if(typeof Re[u]=="string")t+=Re[u];else break;else t+=u}I("Bad string")}function B(){for(;u&&u<=" ";)d()}function Bt(){switch(u){case"t":return d("t"),d("r"),d("u"),d("e"),!0;case"f":return d("f"),d("a"),d("l"),d("s"),d("e"),!1;case"n":return d("n"),d("u"),d("l"),d("l"),null;default:I("Unexpected '"+u+"'")}}function It(){var e=[];if(u==="["){if(d("["),B(),u==="]")return d("]"),e;for(;u;){if(e.push(oe()),B(),u==="]")return d("]"),e;d(","),B()}}I("Bad array")}function Rt(){var e,r={};if(u==="{"){if(d("{"),B(),u==="}")return d("}"),r;for(;u;){if(e=Ne(),B(),d(":"),Object.prototype.hasOwnProperty.call(r,e)&&I('Duplicate key "'+e+'"'),r[e]=oe(),B(),u==="}")return d("}"),r;d(","),B()}}I("Bad object")}function oe(){switch(B(),u){case"{":return Rt();case"[":return It();case'"':return Ne();case"-":return _e();default:return u>="0"&&u<="9"?_e():Bt()}}Ue.exports=function(e,r){var t;return we=e,ie=0,u=" ",t=oe(),B(),u&&I("Syntax error"),typeof r=="function"?function n(i,o){var a,f,s=i[o];if(s&&typeof s=="object")for(a in oe)Object.prototype.hasOwnProperty.call(s,a)&&(f=n(s,a),typeof f>"u"?delete s[a]:s[a]=f);return r.call(i,o,s)}({"":t},""):t}});var $e=j((kr,De)=>{"use strict";var ve=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,S,ae,_t={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},D;function xe(e){return ve.lastIndex=0,ve.test(e)?'"'+e.replace(ve,function(r){var t=_t[r];return typeof t=="string"?t:"\\u"+("0000"+r.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function se(e,r){var t,n,i,o,a=S,f,s=r[e];switch(s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON(e)),typeof D=="function"&&(s=D.call(r,e,s)),typeof s){case"string":return xe(s);case"number":return isFinite(s)?String(s):"null";case"boolean":case"null":return String(s);case"object":if(!s)return"null";if(S+=ae,f=[],Object.prototype.toString.apply(s)==="[object Array]"){for(o=s.length,t=0;t<o;t+=1)f[t]=se(t,s)||"null";return i=f.length===0?"[]":S?`[
3
- `+S+f.join(`,
4
- `+S)+`
5
- `+a+"]":"["+f.join(",")+"]",S=a,i}if(D&&typeof D=="object")for(o=D.length,t=0;t<o;t+=1)n=D[t],typeof n=="string"&&(i=se(n,s),i&&f.push(xe(n)+(S?": ":":")+i));else for(n in s)Object.prototype.hasOwnProperty.call(s,n)&&(i=se(n,s),i&&f.push(xe(n)+(S?": ":":")+i));return i=f.length===0?"{}":S?`{
6
- `+S+f.join(`,
7
- `+S)+`
8
- `+a+"}":"{"+f.join(",")+"}",S=a,i;default:}}De.exports=function(e,r,t){var n;if(S="",ae="",typeof t=="number")for(n=0;n<t;n+=1)ae+=" ";else typeof t=="string"&&(ae=t);if(D=r,r&&typeof r!="function"&&(typeof r!="object"||typeof r.length!="number"))throw new Error("JSON.stringify");return se("",{"":e})}});var He=j(Ee=>{"use strict";Ee.parse=Le();Ee.stringify=$e()});var qe=j((Cr,Je)=>{"use strict";var fe=typeof JSON<"u"?JSON:He(),Nt=Array.isArray||function(e){return{}.toString.call(e)==="[object Array]"},Ut=Object.keys||function(e){var r=Object.prototype.hasOwnProperty||function(){return!0},t=[];for(var n in e)r.call(e,n)&&t.push(n);return t};Je.exports=function(e,r){r||(r={}),typeof r=="function"&&(r={cmp:r});var t=r.space||"";typeof t=="number"&&(t=Array(t+1).join(" "));var n=typeof r.cycles=="boolean"?r.cycles:!1,i=r.replacer||function(f,s){return s},o=r.cmp&&function(f){return function(s){return function(c,l){var m={key:c,value:s[c]},g={key:l,value:s[l]};return f(m,g)}}}(r.cmp),a=[];return function f(s,c,l,m){var g=t?`
9
- `+new Array(m+1).join(t):"",p=t?": ":":";if(l&&l.toJSON&&typeof l.toJSON=="function"&&(l=l.toJSON()),l=i.call(s,c,l),l!==void 0){if(typeof l!="object"||l===null)return fe.stringify(l);if(Nt(l)){for(var C=[],h=0;h<l.length;h++){var U=f(l,h,l[h],m+1)||fe.stringify(null);C.push(g+t+U)}return"["+C.join(",")+g+"]"}if(a.indexOf(l)!==-1){if(n)return fe.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}else a.push(l);for(var k=Ut(l).sort(o&&o(l)),C=[],h=0;h<k.length;h++){var c=k[h],b=f(l,c,l[c],m+1);if(b){var te=fe.stringify(c)+p+b;C.push(g+t+te)}}return a.splice(a.indexOf(l),1),"{"+C.join(",")+g+"}"}}({"":e},"",e,0)}});var ke=j(y=>{"use strict";var Ze=y&&y.__rest||function(e,r){var t={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&r.indexOf(n)<0&&(t[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)r.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(t[n[i]]=e[n[i]]);return t};Object.defineProperty(y,"__esModule",{value:!0});y.isSchema=y.isValidSchema=y.isDiscriminatorForm=y.isValuesForm=y.isPropertiesForm=y.isElementsForm=y.isEnumForm=y.isTypeForm=y.isRefForm=y.isEmptyForm=void 0;function er(e){let{definitions:r,nullable:t,metadata:n}=e,i=Ze(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}y.isEmptyForm=er;function Xe(e){return"ref"in e}y.isRefForm=Xe;function tr(e){return"type"in e}y.isTypeForm=tr;function Qe(e){return"enum"in e}y.isEnumForm=Qe;function et(e){return"elements"in e}y.isElementsForm=et;function Se(e){return"properties"in e||"optionalProperties"in e}y.isPropertiesForm=Se;function tt(e){return"values"in e}y.isValuesForm=tt;function rt(e){return"discriminator"in e}y.isDiscriminatorForm=rt;function $(e,r){if(r===void 0&&(r=e),e.definitions!==void 0){if(r!==e)return!1;for(let t of Object.values(e.definitions))if(!$(t,r))return!1}if(Xe(e)&&!(e.ref in(r.definitions||{}))||Qe(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(et(e))return $(e.elements,r);if(Se(e)){for(let t of Object.values(e.properties||{}))if(!$(t,r))return!1;for(let t of Object.values(e.optionalProperties||{}))if(!$(t,r))return!1;for(let t of Object.keys(e.properties||{}))if(t in(e.optionalProperties||{}))return!1}if(tt(e))return $(e.values,r);if(rt(e)){for(let t of Object.values(e.mapping))if(!$(t,r)||!Se(t)||t.nullable||e.discriminator in(t.properties||{})||e.discriminator in(t.optionalProperties||{}))return!1}return!0}y.isValidSchema=$;var rr=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],nr=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function H(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let r=e,{definitions:t=void 0,nullable:n=void 0,metadata:i=void 0,ref:o=void 0,type:a=void 0,enum:f=void 0,elements:s=void 0,properties:c=void 0,optionalProperties:l=void 0,additionalProperties:m=void 0,values:g=void 0,discriminator:p=void 0,mapping:h=void 0}=r,U=Ze(r,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),k=[o!==void 0,a!==void 0,f!==void 0,s!==void 0,c!==void 0,l!==void 0,m!==void 0,g!==void 0,p!==void 0,h!==void 0],C=!1;for(let b of rr)C=C||b.every((te,Y)=>te===k[Y]);if(!C)return!1;if(t!==void 0){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;for(let b of Object.values(t))if(!H(b))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||o!==void 0&&typeof o!="string"||a!==void 0&&(typeof a!="string"||!nr.includes(a))||f!==void 0&&(!Array.isArray(f)||!f.every(b=>typeof b=="string"))||s!==void 0&&!H(s))return!1;if(c!==void 0){if(typeof c!="object"||Array.isArray(c)||c===null)return!1;for(let b of Object.values(c))if(!H(b))return!1}if(l!==void 0){if(typeof l!="object"||Array.isArray(l)||l===null)return!1;for(let b of Object.values(l))if(!H(b))return!1}if(m!==void 0&&typeof m!="boolean"||g!==void 0&&!H(g)||p!==void 0&&typeof p!="string")return!1;if(h!==void 0){if(typeof h!="object"||Array.isArray(h)||h===null)return!1;for(let b of Object.values(h))if(!H(b))return!1}return Object.keys(U).length===0}y.isSchema=H});var nt=j(Me=>{"use strict";Object.defineProperty(Me,"__esModule",{value:!0});var ir=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function or(e){let r=e.match(ir);if(r===null)return!1;let t=parseInt(r[1],10),n=parseInt(r[2],10),i=parseInt(r[3],10),o=parseInt(r[4],10),a=parseInt(r[5],10),f=parseInt(r[6],10);return!(n>12||i>ar(t,n)||o>23||a>59||f>60)}Me.default=or;function ar(e,r){return r===2?sr(e)?29:28:fr[r]}function sr(e){return e%4===0&&(e%100!==0||e%400===0)}var fr=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var it=j(_=>{"use strict";var lr=_&&_.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(_,"__esModule",{value:!0});_.validate=_.MaxDepthExceededError=void 0;var ur=lr(nt()),J=ke(),de=class extends Error{};_.MaxDepthExceededError=de;var pe=class extends Error{};function cr(e,r,t){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:t||{maxDepth:0,maxErrors:0}};try{G(n,e,r)}catch(i){if(!(i instanceof pe))throw i}return n.errors}_.validate=cr;function G(e,r,t,n){if(!(r.nullable&&t===null)){if(J.isRefForm(r)){if(e.schemaTokens.length===e.config.maxDepth)throw new de;e.schemaTokens.push(["definitions",r.ref]),G(e,e.root.definitions[r.ref],t),e.schemaTokens.pop()}else if(J.isTypeForm(r)){switch(T(e,"type"),r.type){case"boolean":typeof t!="boolean"&&A(e);break;case"float32":case"float64":typeof t!="number"&&A(e);break;case"int8":W(e,t,-128,127);break;case"uint8":W(e,t,0,255);break;case"int16":W(e,t,-32768,32767);break;case"uint16":W(e,t,0,65535);break;case"int32":W(e,t,-2147483648,2147483647);break;case"uint32":W(e,t,0,4294967295);break;case"string":typeof t!="string"&&A(e);break;case"timestamp":typeof t!="string"?A(e):ur.default(t)||A(e);break}O(e)}else if(J.isEnumForm(r))T(e,"enum"),(typeof t!="string"||!r.enum.includes(t))&&A(e),O(e);else if(J.isElementsForm(r)){if(T(e,"elements"),Array.isArray(t))for(let[i,o]of t.entries())q(e,i.toString()),G(e,r.elements,o),V(e);else A(e);O(e)}else if(J.isPropertiesForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t)){if(r.properties!==void 0){T(e,"properties");for(let[i,o]of Object.entries(r.properties))T(e,i),t.hasOwnProperty(i)?(q(e,i),G(e,o,t[i]),V(e)):A(e),O(e);O(e)}if(r.optionalProperties!==void 0){T(e,"optionalProperties");for(let[i,o]of Object.entries(r.optionalProperties))T(e,i),t.hasOwnProperty(i)&&(q(e,i),G(e,o,t[i]),V(e)),O(e);O(e)}if(r.additionalProperties!==!0)for(let i of Object.keys(t)){let o=r.properties&&i in r.properties,a=r.optionalProperties&&i in r.optionalProperties;!o&&!a&&i!==n&&(q(e,i),A(e),V(e))}}else r.properties!==void 0?T(e,"properties"):T(e,"optionalProperties"),A(e),O(e);else if(J.isValuesForm(r)){if(T(e,"values"),typeof t=="object"&&t!==null&&!Array.isArray(t))for(let[i,o]of Object.entries(t))q(e,i),G(e,r.values,o),V(e);else A(e);O(e)}else if(J.isDiscriminatorForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t))if(t.hasOwnProperty(r.discriminator)){let i=t[r.discriminator];typeof i=="string"?i in r.mapping?(T(e,"mapping"),T(e,i),G(e,r.mapping[i],t,r.discriminator),O(e),O(e)):(T(e,"mapping"),q(e,r.discriminator),A(e),V(e),O(e)):(T(e,"discriminator"),q(e,r.discriminator),A(e),V(e),O(e))}else T(e,"discriminator"),A(e),O(e);else T(e,"discriminator"),A(e),O(e)}}function W(e,r,t,n){(typeof r!="number"||!Number.isInteger(r)||r<t||r>n)&&A(e)}function q(e,r){e.instanceTokens.push(r)}function V(e){e.instanceTokens.pop()}function T(e,r){e.schemaTokens[e.schemaTokens.length-1].push(r)}function O(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function A(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new pe}});var at=j(N=>{"use strict";var dr=N&&N.__createBinding||(Object.create?function(e,r,t,n){n===void 0&&(n=t),Object.defineProperty(e,n,{enumerable:!0,get:function(){return r[t]}})}:function(e,r,t,n){n===void 0&&(n=t),e[n]=r[t]}),ot=N&&N.__exportStar||function(e,r){for(var t in e)t!=="default"&&!r.hasOwnProperty(t)&&dr(r,e,t)};Object.defineProperty(N,"__esModule",{value:!0});ot(ke(),N);ot(it(),N)});var Tr={};Tt(Tr,{GenerationError:()=>he,ResponseError:()=>z,builtinFontNames:()=>gr,builtinLineHeights:()=>ht,builtinMargins:()=>mt,builtinTextScales:()=>yt,builtinTools:()=>hr,formatEntry:()=>gt,parseEntry:()=>bt,register:()=>Er,remarkable:()=>Pr});var ct=ge(Ie()),dt=ge(qe());var le,Lt=new Uint8Array(16);function ue(){if(!le&&(le=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!le))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return le(Lt)}var Ve=/^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;function Dt(e){return typeof e=="string"&&Ve.test(e)}var K=Dt;var w=[];for(let e=0;e<256;++e)w.push((e+256).toString(16).slice(1));function Z(e,r=0){return(w[e[r+0]]+w[e[r+1]]+w[e[r+2]]+w[e[r+3]]+"-"+w[e[r+4]]+w[e[r+5]]+"-"+w[e[r+6]]+w[e[r+7]]+"-"+w[e[r+8]]+w[e[r+9]]+"-"+w[e[r+10]]+w[e[r+11]]+w[e[r+12]]+w[e[r+13]]+w[e[r+14]]+w[e[r+15]]).toLowerCase()}function $t(e){if(!K(e))throw TypeError("Invalid UUID");let r,t=new Uint8Array(16);return t[0]=(r=parseInt(e.slice(0,8),16))>>>24,t[1]=r>>>16&255,t[2]=r>>>8&255,t[3]=r&255,t[4]=(r=parseInt(e.slice(9,13),16))>>>8,t[5]=r&255,t[6]=(r=parseInt(e.slice(14,18),16))>>>8,t[7]=r&255,t[8]=(r=parseInt(e.slice(19,23),16))>>>8,t[9]=r&255,t[10]=(r=parseInt(e.slice(24,36),16))/1099511627776&255,t[11]=r/4294967296&255,t[12]=r>>>24&255,t[13]=r>>>16&255,t[14]=r>>>8&255,t[15]=r&255,t}var Pe=$t;function Ht(e){e=unescape(encodeURIComponent(e));let r=[];for(let t=0;t<e.length;++t)r.push(e.charCodeAt(t));return r}var Jt="6ba7b810-9dad-11d1-80b4-00c04fd430c8",qt="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function X(e,r,t){function n(i,o,a,f){var s;if(typeof i=="string"&&(i=Ht(i)),typeof o=="string"&&(o=Pe(o)),((s=o)===null||s===void 0?void 0:s.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let c=new Uint8Array(16+i.length);if(c.set(o),c.set(i,o.length),c=t(c),c[6]=c[6]&15|r,c[8]=c[8]&63|128,a){f=f||0;for(let l=0;l<16;++l)a[f+l]=c[l];return a}return Z(c)}try{n.name=e}catch{}return n.DNS=Jt,n.URL=qt,n}function Vt(e){if(typeof e=="string"){let r=unescape(encodeURIComponent(e));e=new Uint8Array(r.length);for(let t=0;t<r.length;++t)e[t]=r.charCodeAt(t)}return Gt(zt(Wt(e),e.length*8))}function Gt(e){let r=[],t=e.length*32,n="0123456789abcdef";for(let i=0;i<t;i+=8){let o=e[i>>5]>>>i%32&255,a=parseInt(n.charAt(o>>>4&15)+n.charAt(o&15),16);r.push(a)}return r}function Ge(e){return(e+64>>>9<<4)+14+1}function zt(e,r){e[r>>5]|=128<<r%32,e[Ge(r)-1]=r;let t=1732584193,n=-271733879,i=-1732584194,o=271733878;for(let a=0;a<e.length;a+=16){let f=t,s=n,c=i,l=o;t=v(t,n,i,o,e[a],7,-680876936),o=v(o,t,n,i,e[a+1],12,-389564586),i=v(i,o,t,n,e[a+2],17,606105819),n=v(n,i,o,t,e[a+3],22,-1044525330),t=v(t,n,i,o,e[a+4],7,-176418897),o=v(o,t,n,i,e[a+5],12,1200080426),i=v(i,o,t,n,e[a+6],17,-1473231341),n=v(n,i,o,t,e[a+7],22,-45705983),t=v(t,n,i,o,e[a+8],7,1770035416),o=v(o,t,n,i,e[a+9],12,-1958414417),i=v(i,o,t,n,e[a+10],17,-42063),n=v(n,i,o,t,e[a+11],22,-1990404162),t=v(t,n,i,o,e[a+12],7,1804603682),o=v(o,t,n,i,e[a+13],12,-40341101),i=v(i,o,t,n,e[a+14],17,-1502002290),n=v(n,i,o,t,e[a+15],22,1236535329),t=x(t,n,i,o,e[a+1],5,-165796510),o=x(o,t,n,i,e[a+6],9,-1069501632),i=x(i,o,t,n,e[a+11],14,643717713),n=x(n,i,o,t,e[a],20,-373897302),t=x(t,n,i,o,e[a+5],5,-701558691),o=x(o,t,n,i,e[a+10],9,38016083),i=x(i,o,t,n,e[a+15],14,-660478335),n=x(n,i,o,t,e[a+4],20,-405537848),t=x(t,n,i,o,e[a+9],5,568446438),o=x(o,t,n,i,e[a+14],9,-1019803690),i=x(i,o,t,n,e[a+3],14,-187363961),n=x(n,i,o,t,e[a+8],20,1163531501),t=x(t,n,i,o,e[a+13],5,-1444681467),o=x(o,t,n,i,e[a+2],9,-51403784),i=x(i,o,t,n,e[a+7],14,1735328473),n=x(n,i,o,t,e[a+12],20,-1926607734),t=E(t,n,i,o,e[a+5],4,-378558),o=E(o,t,n,i,e[a+8],11,-2022574463),i=E(i,o,t,n,e[a+11],16,1839030562),n=E(n,i,o,t,e[a+14],23,-35309556),t=E(t,n,i,o,e[a+1],4,-1530992060),o=E(o,t,n,i,e[a+4],11,1272893353),i=E(i,o,t,n,e[a+7],16,-155497632),n=E(n,i,o,t,e[a+10],23,-1094730640),t=E(t,n,i,o,e[a+13],4,681279174),o=E(o,t,n,i,e[a],11,-358537222),i=E(i,o,t,n,e[a+3],16,-722521979),n=E(n,i,o,t,e[a+6],23,76029189),t=E(t,n,i,o,e[a+9],4,-640364487),o=E(o,t,n,i,e[a+12],11,-421815835),i=E(i,o,t,n,e[a+15],16,530742520),n=E(n,i,o,t,e[a+2],23,-995338651),t=P(t,n,i,o,e[a],6,-198630844),o=P(o,t,n,i,e[a+7],10,1126891415),i=P(i,o,t,n,e[a+14],15,-1416354905),n=P(n,i,o,t,e[a+5],21,-57434055),t=P(t,n,i,o,e[a+12],6,1700485571),o=P(o,t,n,i,e[a+3],10,-1894986606),i=P(i,o,t,n,e[a+10],15,-1051523),n=P(n,i,o,t,e[a+1],21,-2054922799),t=P(t,n,i,o,e[a+8],6,1873313359),o=P(o,t,n,i,e[a+15],10,-30611744),i=P(i,o,t,n,e[a+6],15,-1560198380),n=P(n,i,o,t,e[a+13],21,1309151649),t=P(t,n,i,o,e[a+4],6,-145523070),o=P(o,t,n,i,e[a+11],10,-1120210379),i=P(i,o,t,n,e[a+2],15,718787259),n=P(n,i,o,t,e[a+9],21,-343485551),t=R(t,f),n=R(n,s),i=R(i,c),o=R(o,l)}return[t,n,i,o]}function Wt(e){if(e.length===0)return[];let r=e.length*8,t=new Uint32Array(Ge(r));for(let n=0;n<r;n+=8)t[n>>5]|=(e[n/8]&255)<<n%32;return t}function R(e,r){let t=(e&65535)+(r&65535);return(e>>16)+(r>>16)+(t>>16)<<16|t&65535}function Yt(e,r){return e<<r|e>>>32-r}function ce(e,r,t,n,i,o){return R(Yt(R(R(r,e),R(n,o)),i),t)}function v(e,r,t,n,i,o,a){return ce(r&t|~r&n,e,r,i,o,a)}function x(e,r,t,n,i,o,a){return ce(r&n|t&~n,e,r,i,o,a)}function E(e,r,t,n,i,o,a){return ce(r^t^n,e,r,i,o,a)}function P(e,r,t,n,i,o,a){return ce(t^(r|~n),e,r,i,o,a)}var ze=Vt;var Wr=X("v3",48,ze);var Kt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Te={randomUUID:Kt};function Zt(e,r,t){if(Te.randomUUID&&!r&&!e)return Te.randomUUID();e=e||{};let n=e.random||(e.rng||ue)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,r){t=t||0;for(let i=0;i<16;++i)r[t+i]=n[i];return r}return Z(n)}var Q=Zt;function Xt(e,r,t,n){switch(e){case 0:return r&t^~r&n;case 1:return r^t^n;case 2:return r&t^r&n^t&n;case 3:return r^t^n}}function Ae(e,r){return e<<r|e>>>32-r}function Qt(e){let r=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){let a=unescape(encodeURIComponent(e));e=[];for(let f=0;f<a.length;++f)e.push(a.charCodeAt(f))}else Array.isArray(e)||(e=Array.prototype.slice.call(e));e.push(128);let n=e.length/4+2,i=Math.ceil(n/16),o=new Array(i);for(let a=0;a<i;++a){let f=new Uint32Array(16);for(let s=0;s<16;++s)f[s]=e[a*64+s*4]<<24|e[a*64+s*4+1]<<16|e[a*64+s*4+2]<<8|e[a*64+s*4+3];o[a]=f}o[i-1][14]=(e.length-1)*8/Math.pow(2,32),o[i-1][14]=Math.floor(o[i-1][14]),o[i-1][15]=(e.length-1)*8&4294967295;for(let a=0;a<i;++a){let f=new Uint32Array(80);for(let p=0;p<16;++p)f[p]=o[a][p];for(let p=16;p<80;++p)f[p]=Ae(f[p-3]^f[p-8]^f[p-14]^f[p-16],1);let s=t[0],c=t[1],l=t[2],m=t[3],g=t[4];for(let p=0;p<80;++p){let h=Math.floor(p/20),U=Ae(s,5)+Xt(h,c,l,m)+g+r[h]+f[p]>>>0;g=m,m=l,l=Ae(c,30)>>>0,c=s,s=U}t[0]=t[0]+s>>>0,t[1]=t[1]+c>>>0,t[2]=t[2]+l>>>0,t[3]=t[3]+m>>>0,t[4]=t[4]+g>>>0}return[t[0]>>24&255,t[0]>>16&255,t[0]>>8&255,t[0]&255,t[1]>>24&255,t[1]>>16&255,t[1]>>8&255,t[1]&255,t[2]>>24&255,t[2]>>16&255,t[2]>>8&255,t[2]&255,t[3]>>24&255,t[3]>>16&255,t[3]>>8&255,t[3]&255,t[4]>>24&255,t[4]>>16&255,t[4]>>8&255,t[4]&255]}var We=Qt;var on=X("v5",80,We);function Oe(e){return[...new Uint8Array(e)].map(r=>r.toString(16).padStart(2,"0")).join("")}function Ye(e){return new Uint8Array((e.match(/../g)??[]).map(r=>parseInt(r,16)))}function Ke(e){let r=0;for(let i of e)r+=i.length;let t=new Uint8Array(r),n=0;for(let i of e)t.set(i,n),n+=i.length;return t}var st=ge(at());function ee(e,r){if((0,st.validate)(e,r).length)throw new Error(`couldn't validate schema: ${JSON.stringify(r)} didn't match schema ${JSON.stringify(e)}`)}var ft="3",pt="https://webapp-prod.cloud.remarkable.engineering",pr="https://internal.cloud.remarkable.com",lt="x-goog-generation",yr="x-goog-if-generation-match",mr="x-goog-content-length-range",hr=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],gr=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],yt={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},mt={sm:50,md:125,rr:180,lg:200},ht={df:-1,md:100,lg:150,xl:200},br={properties:{docID:{type:"string"},hash:{type:"string"}}},wr={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},ye={visibleName:{type:"string"},lastModified:{type:"string"}},me={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},vr={discriminator:"type",mapping:{CollectionType:{properties:ye,optionalProperties:me},DocumentType:{properties:ye,optionalProperties:{...me,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},ut={id:{type:"string"},hash:{type:"string"}},xr={discriminator:"type",mapping:{CollectionType:{properties:{...ye,...ut},optionalProperties:me},DocumentType:{properties:{...ye,...ut,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...me,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},z=class extends Error{constructor(t,n,i){super(i);this.status=t,this.statusText=n}},he=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function Er(e,{deviceDesc:r="browser-chrome",uuid:t=Q(),authHost:n=pt,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:r,deviceID:t})});if(o.ok)return await o.text();throw new z(o.status,o.statusText,"couldn't register api")}function gt({hash:e,type:r,documentId:t,subfiles:n,size:i}){return`${e}:${r}:${t}:${n}:${i}
10
- `}function bt(e){let[r,t,n,i,o]=e.split(":");if(r===void 0||t===void 0||n===void 0||i===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(t==="80000000")return{hash:r,type:t,documentId:n,subfiles:parseInt(i),size:BigInt(o)};if(t==="0"){if(i!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${i}`);return{hash:r,type:t,documentId:n,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${t}`)}var Ce=class{#l;#s;#f;#r;#n;#e=new Map;#t=null;constructor(r,t,n,i,o,a){this.#l=r,this.#s=t,this.#f=n,this.#r=i,this.#n=o;for(let[f,s]of a)this.#e.set(f,Promise.resolve(s))}async#i(r,{body:t,method:n="POST",headers:i={}}){let o=await this.#s(r,{method:n,headers:{Authorization:`Bearer ${this.#l}`,...i},body:t});if(o.ok)return o;{let a=await o.text();throw new z(o.status,o.statusText,`failed reMarkable request: ${a}`)}}async#o({url:r,method:t,maxuploadsize_bytes:n},i,o={}){let a=n?{...o,[mr]:`0,${n}`}:o,f=await this.#s(r,{method:t,body:i,headers:a});if(f.ok)return f;{let s=await f.text();throw new z(f.status,f.statusText,s)}}async#a(r,t,n){let i=t===void 0?"downloads":"uploads",o=n&&t!==null&&t!==void 0?`{ "http_method": "PUT", "relative_path": "${r}", "root_schema": "${n}", "generation": ${t} }`:JSON.stringify({http_method:"GET",relative_path:r}),f=await(await this.#i(`${this.#r}/sync/v2/signed-urls/${i}`,{body:o})).text(),s=JSON.parse(f);return ee(wr,s),s}async getRootHash({cache:r=!0}={}){if(r)for(;this.#t;)try{let[o,a]=await this.#t;return[o,a]}catch{}let t=(async()=>{try{let o=await this.#a("root"),a=await this.#o(o),f=a.headers.get(lt);if(f)return[await a.text(),BigInt(f)];throw new Error("no generation header in root hash")}catch(o){throw this.#t=null,o}})();this.#t=t;let[n,i]=await t;return[n,i]}async putRootHash(r,t){let n=await this.#a("root",t,r),i;try{i=await this.#o(n,r,{[yr]:`${t}`})}catch(f){throw f instanceof z&&f.status===412?(this.#t=null,new he):f}let o=i.headers.get(lt);if(!o)throw new Error("no generation header in root hash");let a=BigInt(o);return this.#t=Promise.resolve([r,a]),a}async#u(r){let t=this.#e.get(r);for(;t;)try{let i=await t;if(i)return i;t=void 0}catch{t=this.#e.get(r)}let n=(async()=>{let i=await this.#a(r);return await(await this.#o(i)).arrayBuffer()})();return this.#e.set(r,n.then(i=>i.byteLength<this.#n?i:null,i=>{throw this.#e.delete(r),i})),await n}async getBuffer(r){let t=await this.#u(r);return t.byteLength<this.#n?t.slice(0):t}async getText(r){let t=await this.#u(r);return new TextDecoder().decode(t)}async getJson(r){let t=await this.getText(r);return JSON.parse(t)}async getMetadata(r){let t=await this.getJson(r);return ee(vr,t),t}async getEntries(r){if(r===void 0){let[o]=await this.getRootHash({cache:!0});r=o}let t=await this.getText(r),[n,...i]=t.slice(0,-1).split(`
11
- `);if(n!==ft)throw new Error(`got unexpected schema version: ${n}`);return i.map(bt)}async#c(r,t){let n=this.#e.get(r);if(n)try{await n;return}catch{}let i=(async()=>{try{let o=await this.#a(r,null);return await this.#o(o,t),t.byteLength<this.#n?t:null}catch(o){throw this.#e.delete(r),o}})();this.#e.set(r,i),await i}async putEntries(r,t){let n=new TextEncoder;t.sort((l,m)=>l.documentId.localeCompare(m.documentId));let i=Ke(t.map(l=>Ye(l.hash))),o=await this.#f.digest("SHA-256",i),a=Oe(o),f=t.map(gt).join(""),s=`${ft}
12
- ${f}`,c=n.encode(s);return await this.#c(a,c),{hash:a,type:"80000000",documentId:r,subfiles:t.length,size:0n}}async putBuffer(r,t){let n=await this.#f.digest("SHA-256",t),i=Oe(n);return await this.#c(i,t),{hash:i,type:"0",documentId:r,subfiles:0,size:BigInt(t.byteLength)}}async putText(r,t){let n=new TextEncoder;return await this.putBuffer(r,n.encode(t))}async putJson(r,t){return await this.putText(r,(0,dt.default)(t))}async putMetadata(r,t){return await this.putJson(`${r}.metadata`,t)}async putCollection(r,t=""){let n=Q(),i=`${new Date().valueOf()}`,o=[],a={type:"CollectionType",visibleName:r,version:0,parent:t,synced:!0,lastModified:i};o.push(this.putMetadata(n,a)),o.push(this.putText(`${n}.content`,"{}"));let f=await Promise.all(o);return await this.putEntries(n,f)}async#d(r,t,n,i,o){if(o.fileType!==n)throw new Error(`internal error: fileTypes don't match: ${n}, ${o.fileType}`);let a=Q(),f=`${new Date().valueOf()}`,s=[];s.push(this.putBuffer(`${a}.${n}`,t));let c={type:"DocumentType",visibleName:r,version:0,parent:i,synced:!0,lastModified:f};s.push(this.putMetadata(a,c)),s.push(this.putText(`${a}.content`,JSON.stringify(o)));let l=await Promise.all(s);return await this.putEntries(a,l)}async putEpub(r,t,{parent:n="",margins:i=125,orientation:o,textAlignment:a,textScale:f=1,lineHeight:s=-1,fontName:c="",cover:l="visited",lastTool:m}={}){let g={dummyDocument:!1,extraMetadata:{LastTool:m},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof s=="string"?ht[s]:s,margins:typeof i=="string"?mt[i]:i,textScale:typeof f=="string"?yt[f]:f,pages:[],coverPageNumber:l==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:a,fontName:c};return await this.#d(r,t,"epub",n,g)}async putPdf(r,t,{parent:n="",orientation:i,cover:o="first",lastTool:a}={}){let f={dummyDocument:!1,extraMetadata:{LastTool:a},fileType:"pdf",pageCount:0,lastOpenedPage:0,lineHeight:-1,margins:125,textScale:1,pages:[],coverPageNumber:o==="first"?0:-1,formatVersion:1,orientation:i};return await this.#d(r,t,"pdf",n,f)}async syncComplete(r){let t=`{ "generation": ${r} }`;await this.#i(`${this.#r}/sync/v2/sync-complete`,{body:t})}async#p(r,t,n){let{hash:i}=await this.putEntries("",t),o=await this.putRootHash(i,r);if(n)try{return await this.syncComplete(o),!0}catch{return!1}else return!1}async create(r,{cache:t=!0,sync:n=!0}={}){let[i,o]=await this.getRootHash({cache:t}),a=await this.getEntries(i);return a.push(r),await this.#p(o,a,n)}async move(r,t,{cache:n=!0,sync:i=!0}={}){let[o,a]=await this.getRootHash({cache:n}),f=await this.getEntries(o);if(!(!t||t==="trash")){let k=f.find(Y=>Y.documentId===t);if(k){if(k.type!=="80000000")throw new Error(`destination id was a raw file: ${t}`)}else throw new Error(`destination id not found: ${t}`);let C=await this.getEntries(k.hash),[b]=C.filter(Y=>Y.documentId===`${t}.metadata`);if(!b)throw new Error(`destination id didn't have metadata: ${t}`);if((await this.getMetadata(b.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${t}`)}let s=f.findIndex(k=>k.documentId===r);if(s===-1)throw new Error(`document not found: ${r}`);let[c]=f.splice(s,1);if(c.type!=="80000000")throw new Error(`document was a raw file: ${r}`);let l=await this.getEntries(c.hash),m=l.findIndex(k=>k.documentId===`${r}.metadata`);if(m===-1)throw new Error(`document didn't have metadata: ${r}`);let[g]=l.splice(m,1),p=await this.getMetadata(g.hash);p.parent=t;let h=await this.putMetadata(r,p);l.push(h);let U=await this.putEntries(r,l);return f.push(U),await this.#p(a,f,i)}async getEntriesMetadata(){let t=await(await this.#i(`${this.#r}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),n=JSON.parse(t);return ee({elements:xr},n),n}async#y(r,t,n){let o=new TextEncoder().encode(JSON.stringify({file_name:r})),f=await(await this.#i(`${this.#r}/doc/v2/files`,{body:t,headers:{"content-type":n,"rm-meta":(0,ct.fromByteArray)(o),"rm-source":"RoR-Browser"}})).text(),s=JSON.parse(f);return ee(br,s),s}async uploadEpub(r,t){return await this.#y(r,t,"application/epub+zip")}async uploadPdf(r,t){return await this.#y(r,t,"application/pdf")}async getCache(){let r=[];for(let[i,o]of this.#e)r.push(o.then(a=>[i,a],()=>[i,null]));let t=await Promise.all(r),n=new Map;for(let[i,o]of t)o&&n.set(i,o);return n}};async function Pr(e,{fetch:r=globalThis.fetch,subtle:t=globalThis.crypto?.subtle,authHost:n=pt,syncHost:i=pr,cacheLimitBytes:o=1048576,initCache:a=[]}={}){if(!t)throw new Error("subtle was missing, try specifying it manually");let f=await r(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!f.ok)throw new Error(`couldn't fetch auth token: ${f.statusText}`);let s=await f.text();return new Ce(s,r,t,i,o,a)}return At(Tr);})();
1
+ "use strict";(()=>{var Xe=Object.create;var we=Object.defineProperty;var et=Object.getOwnPropertyDescriptor;var tt=Object.getOwnPropertyNames;var rt=Object.getPrototypeOf,nt=Object.prototype.hasOwnProperty;var S=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);var it=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of tt(t))!nt.call(e,i)&&i!==r&&we(e,i,{get:()=>t[i],enumerable:!(n=et(t,i))||n.enumerable});return e};var oe=(e,t,r)=>(r=e!=null?Xe(rt(e)):{},it(t||!e||!e.__esModule?we(r,"default",{value:e,enumerable:!0}):r,e));var Ee=S(Y=>{"use strict";Y.byteLength=st;Y.toByteArray=ft;Y.fromByteArray=ct;var O=[],T=[],ot=typeof Uint8Array<"u"?Uint8Array:Array,se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(B=0,ve=se.length;B<ve;++B)O[B]=se[B],T[se.charCodeAt(B)]=B;var B,ve;T["-".charCodeAt(0)]=62;T["_".charCodeAt(0)]=63;function xe(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");r===-1&&(r=t);var n=r===t?0:4-r%4;return[r,n]}function st(e){var t=xe(e),r=t[0],n=t[1];return(r+n)*3/4-n}function at(e,t,r){return(t+r)*3/4-r}function ft(e){var t,r=xe(e),n=r[0],i=r[1],o=new ot(at(e,n,i)),a=0,f=i>0?n-4:n,s;for(s=0;s<f;s+=4)t=T[e.charCodeAt(s)]<<18|T[e.charCodeAt(s+1)]<<12|T[e.charCodeAt(s+2)]<<6|T[e.charCodeAt(s+3)],o[a++]=t>>16&255,o[a++]=t>>8&255,o[a++]=t&255;return i===2&&(t=T[e.charCodeAt(s)]<<2|T[e.charCodeAt(s+1)]>>4,o[a++]=t&255),i===1&&(t=T[e.charCodeAt(s)]<<10|T[e.charCodeAt(s+1)]<<4|T[e.charCodeAt(s+2)]>>2,o[a++]=t>>8&255,o[a++]=t&255),o}function ut(e){return O[e>>18&63]+O[e>>12&63]+O[e>>6&63]+O[e&63]}function lt(e,t,r){for(var n,i=[],o=t;o<r;o+=3)n=(e[o]<<16&16711680)+(e[o+1]<<8&65280)+(e[o+2]&255),i.push(ut(n));return i.join("")}function ct(e){for(var t,r=e.length,n=r%3,i=[],o=16383,a=0,f=r-n;a<f;a+=o)i.push(lt(e,a,a+o>f?f:a+o));return n===1?(t=e[r-1],i.push(O[t>>2]+O[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(O[t>>10]+O[t>>4&63]+O[t<<2&63]+"=")),i.join("")}});var Se=S((Yt,Oe)=>{"use strict";var Z,l,Pe={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
2
+ `,r:"\r",t:" "},ae;function M(e){throw{name:"SyntaxError",message:e,at:Z,text:ae}}function c(e){return e&&e!==l&&M("Expected '"+e+"' instead of '"+l+"'"),l=ae.charAt(Z),Z+=1,l}function Te(){var e,t="";for(l==="-"&&(t="-",c("-"));l>="0"&&l<="9";)t+=l,c();if(l===".")for(t+=".";c()&&l>="0"&&l<="9";)t+=l;if(l==="e"||l==="E")for(t+=l,c(),(l==="-"||l==="+")&&(t+=l,c());l>="0"&&l<="9";)t+=l,c();return e=Number(t),isFinite(e)||M("Bad number"),e}function Ae(){var e,t,r="",n;if(l==='"')for(;c();){if(l==='"')return c(),r;if(l==="\\")if(c(),l==="u"){for(n=0,t=0;t<4&&(e=parseInt(c(),16),!!isFinite(e));t+=1)n=n*16+e;r+=String.fromCharCode(n)}else if(typeof Pe[l]=="string")r+=Pe[l];else break;else r+=l}M("Bad string")}function k(){for(;l&&l<=" ";)c()}function pt(){switch(l){case"t":return c("t"),c("r"),c("u"),c("e"),!0;case"f":return c("f"),c("a"),c("l"),c("s"),c("e"),!1;case"n":return c("n"),c("u"),c("l"),c("l"),null;default:M("Unexpected '"+l+"'")}}function dt(){var e=[];if(l==="["){if(c("["),k(),l==="]")return c("]"),e;for(;l;){if(e.push(K()),k(),l==="]")return c("]"),e;c(","),k()}}M("Bad array")}function yt(){var e,t={};if(l==="{"){if(c("{"),k(),l==="}")return c("}"),t;for(;l;){if(e=Ae(),k(),c(":"),Object.prototype.hasOwnProperty.call(t,e)&&M('Duplicate key "'+e+'"'),t[e]=K(),k(),l==="}")return c("}"),t;c(","),k()}}M("Bad object")}function K(){switch(k(),l){case"{":return yt();case"[":return dt();case'"':return Ae();case"-":return Te();default:return l>="0"&&l<="9"?Te():pt()}}Oe.exports=function(e,t){var r;return ae=e,Z=0,l=" ",r=K(),k(),l&&M("Syntax error"),typeof t=="function"?function n(i,o){var a,f,s=i[o];if(s&&typeof s=="object")for(a in K)Object.prototype.hasOwnProperty.call(s,a)&&(f=n(s,a),typeof f>"u"?delete s[a]:s[a]=f);return t.call(i,o,s)}({"":r},""):r}});var Fe=S((Zt,ke)=>{"use strict";var fe=/[\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,E,W,mt={"\b":"\\b"," ":"\\t","\n":"\\n","\f":"\\f","\r":"\\r",'"':'\\"',"\\":"\\\\"},R;function ue(e){return fe.lastIndex=0,fe.test(e)?'"'+e.replace(fe,function(t){var r=mt[t];return typeof r=="string"?r:"\\u"+("0000"+t.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+e+'"'}function Q(e,t){var r,n,i,o,a=E,f,s=t[e];switch(s&&typeof s=="object"&&typeof s.toJSON=="function"&&(s=s.toJSON(e)),typeof R=="function"&&(s=R.call(t,e,s)),typeof s){case"string":return ue(s);case"number":return isFinite(s)?String(s):"null";case"boolean":case"null":return String(s);case"object":if(!s)return"null";if(E+=W,f=[],Object.prototype.toString.apply(s)==="[object Array]"){for(o=s.length,r=0;r<o;r+=1)f[r]=Q(r,s)||"null";return i=f.length===0?"[]":E?`[
3
+ `+E+f.join(`,
4
+ `+E)+`
5
+ `+a+"]":"["+f.join(",")+"]",E=a,i}if(R&&typeof R=="object")for(o=R.length,r=0;r<o;r+=1)n=R[r],typeof n=="string"&&(i=Q(n,s),i&&f.push(ue(n)+(E?": ":":")+i));else for(n in s)Object.prototype.hasOwnProperty.call(s,n)&&(i=Q(n,s),i&&f.push(ue(n)+(E?": ":":")+i));return i=f.length===0?"{}":E?`{
6
+ `+E+f.join(`,
7
+ `+E)+`
8
+ `+a+"}":"{"+f.join(",")+"}",E=a,i;default:}}ke.exports=function(e,t,r){var n;if(E="",W="",typeof r=="number")for(n=0;n<r;n+=1)W+=" ";else typeof r=="string"&&(W=r);if(R=t,t&&typeof t!="function"&&(typeof t!="object"||typeof t.length!="number"))throw new Error("JSON.stringify");return Q("",{"":e})}});var Me=S(le=>{"use strict";le.parse=Se();le.stringify=Fe()});var je=S((Wt,Ce)=>{"use strict";var X=typeof JSON<"u"?JSON:Me(),ht=Array.isArray||function(e){return{}.toString.call(e)==="[object Array]"},gt=Object.keys||function(e){var t=Object.prototype.hasOwnProperty||function(){return!0},r=[];for(var n in e)t.call(e,n)&&r.push(n);return r};Ce.exports=function(e,t){t||(t={}),typeof t=="function"&&(t={cmp:t});var r=t.space||"";typeof r=="number"&&(r=Array(r+1).join(" "));var n=typeof t.cycles=="boolean"?t.cycles:!1,i=t.replacer||function(f,s){return s},o=t.cmp&&function(f){return function(s){return function(p,u){var g={key:p,value:s[p]},x={key:u,value:s[u]};return f(g,x)}}}(t.cmp),a=[];return function f(s,p,u,g){var x=r?`
9
+ `+new Array(g+1).join(r):"",F=r?": ":":";if(u&&u.toJSON&&typeof u.toJSON=="function"&&(u=u.toJSON()),u=i.call(s,p,u),u!==void 0){if(typeof u!="object"||u===null)return X.stringify(u);if(ht(u)){for(var A=[],y=0;y<u.length;y++){var J=f(u,y,u[y],g+1)||X.stringify(null);A.push(x+r+J)}return"["+A.join(",")+x+"]"}if(a.indexOf(u)!==-1){if(n)return X.stringify("__cycle__");throw new TypeError("Converting circular structure to JSON")}else a.push(u);for(var P=gt(u).sort(o&&o(u)),A=[],y=0;y<P.length;y++){var p=P[y],m=f(u,p,u[p],g+1);if(m){var G=X.stringify(p)+F+m;A.push(x+r+G)}}return a.splice(a.indexOf(u),1),"{"+A.join(",")+x+"}"}}({"":e},"",e,0)}});var me=S(d=>{"use strict";var _e=d&&d.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var i=0,n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]]);return r};Object.defineProperty(d,"__esModule",{value:!0});d.isSchema=d.isValidSchema=d.isDiscriminatorForm=d.isValuesForm=d.isPropertiesForm=d.isElementsForm=d.isEnumForm=d.isTypeForm=d.isRefForm=d.isEmptyForm=void 0;function xt(e){let{definitions:t,nullable:r,metadata:n}=e,i=_e(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=xt;function Ne(e){return"ref"in e}d.isRefForm=Ne;function Et(e){return"type"in e}d.isTypeForm=Et;function $e(e){return"enum"in e}d.isEnumForm=$e;function Le(e){return"elements"in e}d.isElementsForm=Le;function ye(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=ye;function De(e){return"values"in e}d.isValuesForm=De;function He(e){return"discriminator"in e}d.isDiscriminatorForm=He;function I(e,t){if(t===void 0&&(t=e),e.definitions!==void 0){if(t!==e)return!1;for(let r of Object.values(e.definitions))if(!I(r,t))return!1}if(Ne(e)&&!(e.ref in(t.definitions||{}))||$e(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Le(e))return I(e.elements,t);if(ye(e)){for(let r of Object.values(e.properties||{}))if(!I(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!I(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(De(e))return I(e.values,t);if(He(e)){for(let r of Object.values(e.mapping))if(!I(r,t)||!ye(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}d.isValidSchema=I;var Pt=[[!1,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!0,!1,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!0,!1,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!0,!1,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!0,!1,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!1,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!1,!1,!1,!1],[!1,!1,!1,!1,!0,!1,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!0,!0,!0,!1,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!0,!1,!1],[!1,!1,!1,!1,!1,!1,!1,!1,!0,!0]],Tt=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function _(e){if(typeof e!="object"||Array.isArray(e)||e===null)return!1;let t=e,{definitions:r=void 0,nullable:n=void 0,metadata:i=void 0,ref:o=void 0,type:a=void 0,enum:f=void 0,elements:s=void 0,properties:p=void 0,optionalProperties:u=void 0,additionalProperties:g=void 0,values:x=void 0,discriminator:F=void 0,mapping:y=void 0}=t,J=_e(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),P=[o!==void 0,a!==void 0,f!==void 0,s!==void 0,p!==void 0,u!==void 0,g!==void 0,x!==void 0,F!==void 0,y!==void 0],A=!1;for(let m of Pt)A=A||m.every((G,V)=>G===P[V]);if(!A)return!1;if(r!==void 0){if(typeof r!="object"||Array.isArray(r)||r===null)return!1;for(let m of Object.values(r))if(!_(m))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||o!==void 0&&typeof o!="string"||a!==void 0&&(typeof a!="string"||!Tt.includes(a))||f!==void 0&&(!Array.isArray(f)||!f.every(m=>typeof m=="string"))||s!==void 0&&!_(s))return!1;if(p!==void 0){if(typeof p!="object"||Array.isArray(p)||p===null)return!1;for(let m of Object.values(p))if(!_(m))return!1}if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let m of Object.values(u))if(!_(m))return!1}if(g!==void 0&&typeof g!="boolean"||x!==void 0&&!_(x)||F!==void 0&&typeof F!="string")return!1;if(y!==void 0){if(typeof y!="object"||Array.isArray(y)||y===null)return!1;for(let m of Object.values(y))if(!_(m))return!1}return Object.keys(J).length===0}d.isSchema=_});var Ue=S(he=>{"use strict";Object.defineProperty(he,"__esModule",{value:!0});var At=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Ot(e){let t=e.match(At);if(t===null)return!1;let r=parseInt(t[1],10),n=parseInt(t[2],10),i=parseInt(t[3],10),o=parseInt(t[4],10),a=parseInt(t[5],10),f=parseInt(t[6],10);return!(n>12||i>St(r,n)||o>23||a>59||f>60)}he.default=Ot;function St(e,t){return t===2?kt(e)?29:28:Ft[t]}function kt(e){return e%4===0&&(e%100!==0||e%400===0)}var Ft=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Je=S(C=>{"use strict";var Mt=C&&C.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(C,"__esModule",{value:!0});C.validate=C.MaxDepthExceededError=void 0;var Ct=Mt(Ue()),N=me(),te=class extends Error{};C.MaxDepthExceededError=te;var re=class extends Error{};function jt(e,t,r){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{D(n,e,t)}catch(i){if(!(i instanceof re))throw i}return n.errors}C.validate=jt;function D(e,t,r,n){if(!(t.nullable&&r===null)){if(N.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new te;e.schemaTokens.push(["definitions",t.ref]),D(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if(N.isTypeForm(t)){switch(b(e,"type"),t.type){case"boolean":typeof r!="boolean"&&w(e);break;case"float32":case"float64":typeof r!="number"&&w(e);break;case"int8":H(e,r,-128,127);break;case"uint8":H(e,r,0,255);break;case"int16":H(e,r,-32768,32767);break;case"uint16":H(e,r,0,65535);break;case"int32":H(e,r,-2147483648,2147483647);break;case"uint32":H(e,r,0,4294967295);break;case"string":typeof r!="string"&&w(e);break;case"timestamp":typeof r!="string"?w(e):Ct.default(r)||w(e);break}v(e)}else if(N.isEnumForm(t))b(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&w(e),v(e);else if(N.isElementsForm(t)){if(b(e,"elements"),Array.isArray(r))for(let[i,o]of r.entries())$(e,i.toString()),D(e,t.elements,o),L(e);else w(e);v(e)}else if(N.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){b(e,"properties");for(let[i,o]of Object.entries(t.properties))b(e,i),r.hasOwnProperty(i)?($(e,i),D(e,o,r[i]),L(e)):w(e),v(e);v(e)}if(t.optionalProperties!==void 0){b(e,"optionalProperties");for(let[i,o]of Object.entries(t.optionalProperties))b(e,i),r.hasOwnProperty(i)&&($(e,i),D(e,o,r[i]),L(e)),v(e);v(e)}if(t.additionalProperties!==!0)for(let i of Object.keys(r)){let o=t.properties&&i in t.properties,a=t.optionalProperties&&i in t.optionalProperties;!o&&!a&&i!==n&&($(e,i),w(e),L(e))}}else t.properties!==void 0?b(e,"properties"):b(e,"optionalProperties"),w(e),v(e);else if(N.isValuesForm(t)){if(b(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[i,o]of Object.entries(r))$(e,i),D(e,t.values,o),L(e);else w(e);v(e)}else if(N.isDiscriminatorForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r))if(r.hasOwnProperty(t.discriminator)){let i=r[t.discriminator];typeof i=="string"?i in t.mapping?(b(e,"mapping"),b(e,i),D(e,t.mapping[i],r,t.discriminator),v(e),v(e)):(b(e,"mapping"),$(e,t.discriminator),w(e),L(e),v(e)):(b(e,"discriminator"),$(e,t.discriminator),w(e),L(e),v(e))}else b(e,"discriminator"),w(e),v(e);else b(e,"discriminator"),w(e),v(e)}}function H(e,t,r,n){(typeof t!="number"||!Number.isInteger(t)||t<r||t>n)&&w(e)}function $(e,t){e.instanceTokens.push(t)}function L(e){e.instanceTokens.pop()}function b(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function v(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function w(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new re}});var qe=S(j=>{"use strict";var Bt=j&&j.__createBinding||(Object.create?function(e,t,r,n){n===void 0&&(n=r),Object.defineProperty(e,n,{enumerable:!0,get:function(){return t[r]}})}:function(e,t,r,n){n===void 0&&(n=r),e[n]=t[r]}),Ve=j&&j.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&Bt(t,e,r)};Object.defineProperty(j,"__esModule",{value:!0});Ve(me(),j);Ve(Je(),j)});var Ke=oe(Ee()),We=oe(je());var ee,bt=new Uint8Array(16);function ce(){if(!ee&&(ee=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!ee))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return ee(bt)}var h=[];for(let e=0;e<256;++e)h.push((e+256).toString(16).slice(1));function Be(e,t=0){return(h[e[t+0]]+h[e[t+1]]+h[e[t+2]]+h[e[t+3]]+"-"+h[e[t+4]]+h[e[t+5]]+"-"+h[e[t+6]]+h[e[t+7]]+"-"+h[e[t+8]]+h[e[t+9]]+"-"+h[e[t+10]]+h[e[t+11]]+h[e[t+12]]+h[e[t+13]]+h[e[t+14]]+h[e[t+15]]).toLowerCase()}var wt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),pe={randomUUID:wt};function vt(e,t,r){if(pe.randomUUID&&!t&&!e)return pe.randomUUID();e=e||{};let n=e.random||(e.rng||ce)();if(n[6]=n[6]&15|64,n[8]=n[8]&63|128,t){r=r||0;for(let i=0;i<16;++i)t[r+i]=n[i];return t}return Be(n)}var q=vt;function de(e){return[...new Uint8Array(e)].map(t=>t.toString(16).padStart(2,"0")).join("")}function Re(e){return new Uint8Array((e.match(/../g)??[]).map(t=>parseInt(t,16)))}function Ie(e){let t=0;for(let i of e)t+=i.length;let r=new Uint8Array(t),n=0;for(let i of e)r.set(i,n),n+=i.length;return r}var ze=oe(qe());function z(e,t){if((0,ze.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var Ge="3",Qe="https://webapp-prod.cloud.remarkable.engineering",Rt="https://internal.cloud.remarkable.com",Ye="x-goog-generation",It="x-goog-if-generation-match",_t="x-goog-content-length-range",gr=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],br=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Nt={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},$t={sm:50,md:125,rr:180,lg:200},Lt={df:-1,md:100,lg:150,xl:200},Dt={properties:{docID:{type:"string"},hash:{type:"string"}}},Ht={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},ne={visibleName:{type:"string"},lastModified:{type:"string"}},ie={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},Ut={discriminator:"type",mapping:{CollectionType:{properties:ne,optionalProperties:ie},DocumentType:{properties:ne,optionalProperties:{...ie,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},Ze={id:{type:"string"},hash:{type:"string"}},Jt={discriminator:"type",mapping:{CollectionType:{properties:{...ne,...Ze},optionalProperties:ie},DocumentType:{properties:{...ne,...Ze,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...ie,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},U=class extends Error{status;statusText;constructor(t,r,n){super(n),this.status=t,this.statusText=r}},ge=class extends Error{constructor(){super("Generation preconditions failed. This means the current state is out of date with the cloud and needs to be re-synced.")}};async function wr(e,{deviceDesc:t="browser-chrome",uuid:r=q(),authHost:n=Qe,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let o=await i(`${n}/token/json/2/device/new`,{method:"POST",headers:{Authorization:"Bearer"},body:JSON.stringify({code:e,deviceDesc:t,deviceID:r})});if(o.ok)return await o.text();throw new U(o.status,o.statusText,"couldn't register api")}function Vt({hash:e,type:t,documentId:r,subfiles:n,size:i}){return`${e}:${t}:${r}:${n}:${i}
10
+ `}function qt(e){let[t,r,n,i,o]=e.split(":");if(t===void 0||r===void 0||n===void 0||i===void 0||o===void 0)throw new Error(`entries line didn't contain five fields: '${e}'`);if(r==="80000000")return{hash:t,type:r,documentId:n,subfiles:parseInt(i),size:BigInt(o)};if(r==="0"){if(i!=="0")throw new Error(`file type entry had nonzero number of subfiles: ${i}`);return{hash:t,type:r,documentId:n,subfiles:0,size:BigInt(o)}}else throw new Error(`entries line contained invalid type: ${r}`)}var be=class{#u;#a;#f;#r;#n;#e=new Map;#t=null;constructor(t,r,n,i,o,a){this.#u=t,this.#a=r,this.#f=n,this.#r=i,this.#n=o;for(let[f,s]of a)this.#e.set(f,Promise.resolve(s))}async#i(t,{body:r,method:n="POST",headers:i={}}){let o=await this.#a(t,{method:n,headers:{Authorization:`Bearer ${this.#u}`,...i},body:r});if(o.ok)return o;{let a=await o.text();throw new U(o.status,o.statusText,`failed reMarkable request: ${a}`)}}async#o({url:t,method:r,maxuploadsize_bytes:n},i,o={}){let a=n?{...o,[_t]:`0,${n}`}:o,f=await this.#a(t,{method:r,body:i,headers:a});if(f.ok)return f;{let s=await f.text();throw new U(f.status,f.statusText,s)}}async#s(t,r,n){let i=r===void 0?"downloads":"uploads",o=n&&r!==null&&r!==void 0?`{ "http_method": "PUT", "relative_path": "${t}", "root_schema": "${n}", "generation": ${r} }`:JSON.stringify({http_method:"GET",relative_path:t}),f=await(await this.#i(`${this.#r}/sync/v2/signed-urls/${i}`,{body:o})).text(),s=JSON.parse(f);return z(Ht,s),s}async getRootHash({cache:t=!0}={}){if(t)for(;this.#t;)try{let[o,a]=await this.#t;return[o,a]}catch{}let r=(async()=>{try{let o=await this.#s("root"),a=await this.#o(o),f=a.headers.get(Ye);if(f)return[await a.text(),BigInt(f)];throw new Error("no generation header in root hash")}catch(o){throw this.#t=null,o}})();this.#t=r;let[n,i]=await r;return[n,i]}async putRootHash(t,r){let n=await this.#s("root",r,t),i;try{i=await this.#o(n,t,{[It]:`${r}`})}catch(f){throw f instanceof U&&f.status===412?(this.#t=null,new ge):f}let o=i.headers.get(Ye);if(!o)throw new Error("no generation header in root hash");let a=BigInt(o);return this.#t=Promise.resolve([t,a]),a}async#l(t){let r=this.#e.get(t);for(;r;)try{let i=await r;if(i)return i;r=void 0}catch{r=this.#e.get(t)}let n=(async()=>{let i=await this.#s(t);return await(await this.#o(i)).arrayBuffer()})();return this.#e.set(t,n.then(i=>i.byteLength<this.#n?i:null,i=>{throw this.#e.delete(t),i})),await n}async getBuffer(t){let r=await this.#l(t);return r.byteLength<this.#n?r.slice(0):r}async getText(t){let r=await this.#l(t);return new TextDecoder().decode(r)}async getJson(t){let r=await this.getText(t);return JSON.parse(r)}async getMetadata(t){let r=await this.getJson(t);return z(Ut,r),r}async getEntries(t){if(t===void 0){let[o]=await this.getRootHash({cache:!0});t=o}let r=await this.getText(t),[n,...i]=r.slice(0,-1).split(`
11
+ `);if(n!==Ge)throw new Error(`got unexpected schema version: ${n}`);return i.map(qt)}async#c(t,r){let n=this.#e.get(t);if(n)try{await n;return}catch{}let i=(async()=>{try{let o=await this.#s(t,null);return await this.#o(o,r),r.byteLength<this.#n?r:null}catch(o){throw this.#e.delete(t),o}})();this.#e.set(t,i),await i}async putEntries(t,r){let n=new TextEncoder;r.sort((u,g)=>u.documentId.localeCompare(g.documentId));let i=Ie(r.map(u=>Re(u.hash))),o=await this.#f.digest("SHA-256",i),a=de(o),f=r.map(Vt).join(""),s=`${Ge}
12
+ ${f}`,p=n.encode(s);return await this.#c(a,p),{hash:a,type:"80000000",documentId:t,subfiles:r.length,size:0n}}async putBuffer(t,r){let n=await this.#f.digest("SHA-256",r),i=de(n);return await this.#c(i,r),{hash:i,type:"0",documentId:t,subfiles:0,size:BigInt(r.byteLength)}}async putText(t,r){let n=new TextEncoder;return await this.putBuffer(t,n.encode(r))}async putJson(t,r){return await this.putText(t,(0,We.default)(r))}async putMetadata(t,r){return await this.putJson(`${t}.metadata`,r)}async putCollection(t,r=""){let n=q(),i=`${new Date().valueOf()}`,o=[],a={type:"CollectionType",visibleName:t,version:0,parent:r,synced:!0,lastModified:i};o.push(this.putMetadata(n,a)),o.push(this.putText(`${n}.content`,"{}"));let f=await Promise.all(o);return await this.putEntries(n,f)}async#p(t,r,n,i,o){if(o.fileType!==n)throw new Error(`internal error: fileTypes don't match: ${n}, ${o.fileType}`);let a=q(),f=`${new Date().valueOf()}`,s=[];s.push(this.putBuffer(`${a}.${n}`,r));let p={type:"DocumentType",visibleName:t,version:0,parent:i,synced:!0,lastModified:f};s.push(this.putMetadata(a,p)),s.push(this.putText(`${a}.content`,JSON.stringify(o)));let u=await Promise.all(s);return await this.putEntries(a,u)}async putEpub(t,r,{parent:n="",margins:i=125,orientation:o,textAlignment:a,textScale:f=1,lineHeight:s=-1,fontName:p="",cover:u="visited",lastTool:g}={}){let x={dummyDocument:!1,extraMetadata:{LastTool:g},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof s=="string"?Lt[s]:s,margins:typeof i=="string"?$t[i]:i,textScale:typeof f=="string"?Nt[f]:f,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:a,fontName:p};return await this.#p(t,r,"epub",n,x)}async putPdf(t,r,{parent:n="",orientation:i,cover:o="first",lastTool:a}={}){let f={dummyDocument:!1,extraMetadata:{LastTool:a},fileType:"pdf",pageCount:0,lastOpenedPage:0,lineHeight:-1,margins:125,textScale:1,pages:[],coverPageNumber:o==="first"?0:-1,formatVersion:1,orientation:i};return await this.#p(t,r,"pdf",n,f)}async syncComplete(t){let r=`{ "generation": ${t} }`;await this.#i(`${this.#r}/sync/v2/sync-complete`,{body:r})}async#d(t,r,n){let{hash:i}=await this.putEntries("",r),o=await this.putRootHash(i,t);if(n)try{return await this.syncComplete(o),!0}catch{return!1}else return!1}async create(t,{cache:r=!0,sync:n=!0}={}){let[i,o]=await this.getRootHash({cache:r}),a=await this.getEntries(i);return a.push(t),await this.#d(o,a,n)}async move(t,r,{cache:n=!0,sync:i=!0}={}){let[o,a]=await this.getRootHash({cache:n}),f=await this.getEntries(o);if(!(!r||r==="trash")){let P=f.find(V=>V.documentId===r);if(P){if(P.type!=="80000000")throw new Error(`destination id was a raw file: ${r}`)}else throw new Error(`destination id not found: ${r}`);let A=await this.getEntries(P.hash),[m]=A.filter(V=>V.documentId===`${r}.metadata`);if(!m)throw new Error(`destination id didn't have metadata: ${r}`);if((await this.getMetadata(m.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${r}`)}let s=f.findIndex(P=>P.documentId===t);if(s===-1)throw new Error(`document not found: ${t}`);let[p]=f.splice(s,1);if(p.type!=="80000000")throw new Error(`document was a raw file: ${t}`);let u=await this.getEntries(p.hash),g=u.findIndex(P=>P.documentId===`${t}.metadata`);if(g===-1)throw new Error(`document didn't have metadata: ${t}`);let[x]=u.splice(g,1),F=await this.getMetadata(x.hash);F.parent=r;let y=await this.putMetadata(t,F);u.push(y);let J=await this.putEntries(t,u);return f.push(J),await this.#d(a,f,i)}async getEntriesMetadata(){let r=await(await this.#i(`${this.#r}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),n=JSON.parse(r);return z({elements:Jt},n),n}async#y(t,r,n){let o=new TextEncoder().encode(JSON.stringify({file_name:t})),f=await(await this.#i(`${this.#r}/doc/v2/files`,{body:r,headers:{"content-type":n,"rm-meta":(0,Ke.fromByteArray)(o),"rm-source":"RoR-Browser"}})).text(),s=JSON.parse(f);return z(Dt,s),s}async uploadEpub(t,r){return await this.#y(t,r,"application/epub+zip")}async uploadPdf(t,r){return await this.#y(t,r,"application/pdf")}async getCache(){let t=[];for(let[i,o]of this.#e)t.push(o.then(a=>[i,a],()=>[i,null]));let r=await Promise.all(t),n=new Map;for(let[i,o]of r)o&&n.set(i,o);return n}};async function vr(e,{fetch:t=globalThis.fetch,subtle:r=globalThis.crypto?.subtle,authHost:n=Qe,syncHost:i=Rt,cacheLimitBytes:o=1048576,initCache:a=[]}={}){if(!r)throw new Error("subtle was missing, try specifying it manually");let f=await t(`${n}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!f.ok)throw new Error(`couldn't fetch auth token: ${f.statusText}`);let s=await f.text();return new be(s,t,r,i,o,a)}})();
package/dist/index.d.ts CHANGED
@@ -219,6 +219,7 @@ export interface ResponseLike {
219
219
  }
220
220
  /** stripped down version of fetch */
221
221
  export interface FetchLike {
222
+ /** the rough interface to fetch */
222
223
  (url: string, options?: RequestInitLike | undefined): Promise<ResponseLike>;
223
224
  }
224
225
  /** async storage, map like */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rmapi-js",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "JavaScript implementation of the reMarkable 1.5 api",
5
5
  "repository": "git@github.com:erikbrinkman/rmapi-js.git",
6
6
  "author": "Erik Brinkman <erik.brinkman@gmail.com>",
@@ -19,48 +19,47 @@
19
19
  ],
20
20
  "packageManager": "yarn@3.3.1",
21
21
  "scripts": {
22
- "doc": "typedoc",
23
- "fmt": "prettier --cache --write 'src/*.ts' '*.json' bundle.mjs",
24
- "lint:es": "eslint --cache 'src/*.ts'",
25
- "lint:doc": "typedoc --emit none",
26
- "lint": "tsc && yarn lint:es && yarn lint:doc",
22
+ "doc": "pnpify typedoc",
23
+ "fmt": "pnpify prettier --cache --write 'src/*.ts' '*.json'",
24
+ "lint:es": "pnpify eslint --cache 'src/*.ts'",
25
+ "lint:doc": "pnpify typedoc --emit none",
26
+ "lint": "pnpify tsc && yarn lint:es && yarn lint:doc",
27
27
  "test": "jest --coverage",
28
- "build": "tsc -p tsconfig.build.json && node bundle.mjs",
28
+ "build": "pnpify tsc -p tsconfig.build.json && esbuild src/index.ts --bundle --minify --platform=node --outfile=bundle/rmapi-js.cjs.min.js && yarn esbuild src/index.ts --bundle --minify --platform=browser --outfile=bundle/rmapi-js.iife.min.js && yarn esbuild src/index.ts --bundle --minify --platform=neutral --outfile=bundle/rmapi-js.esm.min.js --main-fields=module,main",
29
29
  "prepack": "yarn lint && yarn test && yarn build"
30
30
  },
31
31
  "dependencies": {
32
- "ajv": "^8.11.2",
32
+ "ajv": "^8.12.0",
33
33
  "base64-js": "^1.5.1",
34
34
  "json-stable-stringify": "^1.0.2",
35
35
  "jtd": "^0.1.1",
36
36
  "uuid": "^9.0.0"
37
37
  },
38
38
  "devDependencies": {
39
- "@babel/core": "^7.20.7",
40
- "@babel/preset-env": "^7.20.2",
41
- "@babel/preset-typescript": "^7.18.6",
42
- "@types/babel__core": "^7.1.20",
39
+ "@babel/core": "^7.22.8",
40
+ "@babel/preset-env": "^7.22.7",
41
+ "@babel/preset-typescript": "^7.22.5",
42
+ "@types/babel__core": "^7.20.1",
43
43
  "@types/babel__preset-env": "^7.9.2",
44
- "@types/jest": "^29.2.5",
44
+ "@types/jest": "^29.5.3",
45
45
  "@types/json-stable-stringify": "^1.0.34",
46
- "@types/node": "^18.11.18",
47
- "@types/uuid": "^9.0.0",
48
- "@typescript-eslint/eslint-plugin": "^5.47.1",
49
- "@typescript-eslint/parser": "^5.47.1",
50
- "@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.15",
51
- "babel-jest": "^29.3.1",
52
- "chalk": "^5.2.0",
53
- "esbuild": "^0.16.12",
54
- "eslint": "^8.31.0",
55
- "eslint-config-prettier": "^8.5.0",
56
- "eslint-plugin-jest": "^27.2.0",
46
+ "@types/node": "^20.4.1",
47
+ "@types/uuid": "^9.0.2",
48
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
49
+ "@typescript-eslint/parser": "^6.0.0",
50
+ "@yarnpkg/pnpify": "^4.0.0-rc.48",
51
+ "babel-jest": "^29.6.1",
52
+ "esbuild": "^0.18.11",
53
+ "eslint": "^8.44.0",
54
+ "eslint-config-prettier": "^8.8.0",
55
+ "eslint-plugin-jest": "^27.2.2",
57
56
  "eslint-plugin-spellcheck": "^0.0.20",
58
57
  "eslint-plugin-tsdoc": "^0.2.17",
59
- "jest": "^29.3.1",
60
- "prettier": "^2.8.1",
61
- "prettier-plugin-organize-imports": "^3.2.1",
62
- "typedoc": "^0.23.23",
63
- "typescript": "^4.9.4"
58
+ "jest": "^29.6.1",
59
+ "prettier": "^3.0.0",
60
+ "prettier-plugin-organize-imports": "^3.2.2",
61
+ "typedoc": "^0.24.8",
62
+ "typescript": "^5.1.6"
64
63
  },
65
64
  "prettier": {
66
65
  "plugins": [