rmapi-js 2.3.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -8,6 +8,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
 
9
9
  ## [Unreleased]
10
10
 
11
+ ## [3.0.0] - 2023-01-03
12
+
13
+ ### Added
14
+
15
+ - The ability to call `getEntries` without a hash to implicitely fetch the root
16
+ hash.
17
+ - `getJson` and `putJson` methods that use stable hashing.
18
+
19
+ ### Changed
20
+
21
+ - Caching behavior: You can no longer customize the caching behavior with a
22
+ custom `CacheLike` object, but instead specify the maximum size of objects to
23
+ cache. This both cleans up the caching code, and makes it easier to remove
24
+ most redundant calls from higher level interfaces.
25
+ - Changed `FetchLike` interfaces to be promises instead of awaitable.
26
+
27
+ ### Removed
28
+
29
+ - Removed deprecated versions of `create` and `move`.
30
+
11
31
  ## [2.3.0] - 2022-12-31
12
32
 
13
33
  ### Added
@@ -1,4 +1,12 @@
1
- var Pt=Object.create;var z=Object.defineProperty;var Et=Object.getOwnPropertyDescriptor;var Tt=Object.getOwnPropertyNames;var Ot=Object.getPrototypeOf,At=Object.prototype.hasOwnProperty;var p=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),Mt=(e,t)=>{for(var r in t)z(e,r,{get:t[r],enumerable:!0})},Ce=(e,t,r,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Tt(t))!At.call(e,i)&&i!==r&&z(e,i,{get:()=>t[i],enumerable:!(n=Et(t,i))||n.enumerable});return e};var ge=(e,t,r)=>(r=e!=null?Pt(Ot(e)):{},Ce(t||!e||!e.__esModule?z(r,"default",{value:e,enumerable:!0}):r,e)),St=e=>Ce(z({},"__esModule",{value:!0}),e);var Ie=p(G=>{"use strict";G.byteLength=Ct;G.toByteArray=Rt;G.fromByteArray=Ut;var P=[],x=[],kt=typeof Uint8Array<"u"?Uint8Array:Array,he="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(S=0,Fe=he.length;S<Fe;++S)P[S]=he[S],x[he.charCodeAt(S)]=S;var S,Fe;x["-".charCodeAt(0)]=62;x["_".charCodeAt(0)]=63;function Re(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 Ct(e){var t=Re(e),r=t[0],n=t[1];return(r+n)*3/4-n}function Ft(e,t,r){return(t+r)*3/4-r}function Rt(e){var t,r=Re(e),n=r[0],i=r[1],a=new kt(Ft(e,n,i)),o=0,s=i>0?n-4:n,f;for(f=0;f<s;f+=4)t=x[e.charCodeAt(f)]<<18|x[e.charCodeAt(f+1)]<<12|x[e.charCodeAt(f+2)]<<6|x[e.charCodeAt(f+3)],a[o++]=t>>16&255,a[o++]=t>>8&255,a[o++]=t&255;return i===2&&(t=x[e.charCodeAt(f)]<<2|x[e.charCodeAt(f+1)]>>4,a[o++]=t&255),i===1&&(t=x[e.charCodeAt(f)]<<10|x[e.charCodeAt(f+1)]<<4|x[e.charCodeAt(f+2)]>>2,a[o++]=t>>8&255,a[o++]=t&255),a}function It(e){return P[e>>18&63]+P[e>>12&63]+P[e>>6&63]+P[e&63]}function Dt(e,t,r){for(var n,i=[],a=t;a<r;a+=3)n=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(e[a+2]&255),i.push(It(n));return i.join("")}function Ut(e){for(var t,r=e.length,n=r%3,i=[],a=16383,o=0,s=r-n;o<s;o+=a)i.push(Dt(e,o,o+a>s?s:o+a));return n===1?(t=e[r-1],i.push(P[t>>2]+P[t<<4&63]+"==")):n===2&&(t=(e[r-2]<<8)+e[r-1],i.push(P[t>>10]+P[t>>4&63]+P[t<<2&63]+"=")),i.join("")}});var be=p(ve=>{"use strict";Object.defineProperty(ve,"__esModule",{value:!0});ve.default=$t;var qt=Lt(require("crypto"));function Lt(e){return e&&e.__esModule?e:{default:e}}var Y=new Uint8Array(256),V=Y.length;function $t(){return V>Y.length-16&&(qt.default.randomFillSync(Y),V=0),Y.slice(V,V+=16)}});var De=p(Z=>{"use strict";Object.defineProperty(Z,"__esModule",{value:!0});Z.default=void 0;var Nt=/^(?:[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;Z.default=Nt});var N=p(W=>{"use strict";Object.defineProperty(W,"__esModule",{value:!0});W.default=void 0;var Bt=Ht(De());function Ht(e){return e&&e.__esModule?e:{default:e}}function jt(e){return typeof e=="string"&&Bt.default.test(e)}var Jt=jt;W.default=Jt});var H=p(B=>{"use strict";Object.defineProperty(B,"__esModule",{value:!0});B.default=void 0;B.unsafeStringify=Ue;var zt=Gt(N());function Gt(e){return e&&e.__esModule?e:{default:e}}var m=[];for(let e=0;e<256;++e)m.push((e+256).toString(16).slice(1));function Ue(e,t=0){return(m[e[t+0]]+m[e[t+1]]+m[e[t+2]]+m[e[t+3]]+"-"+m[e[t+4]]+m[e[t+5]]+"-"+m[e[t+6]]+m[e[t+7]]+"-"+m[e[t+8]]+m[e[t+9]]+"-"+m[e[t+10]]+m[e[t+11]]+m[e[t+12]]+m[e[t+13]]+m[e[t+14]]+m[e[t+15]]).toLowerCase()}function Vt(e,t=0){let r=Ue(e,t);if(!(0,zt.default)(r))throw TypeError("Stringified UUID is invalid");return r}var Yt=Vt;B.default=Yt});var Le=p(K=>{"use strict";Object.defineProperty(K,"__esModule",{value:!0});K.default=void 0;var Zt=Kt(be()),Wt=H();function Kt(e){return e&&e.__esModule?e:{default:e}}var qe,xe,we=0,_e=0;function Qt(e,t,r){let n=t&&r||0,i=t||new Array(16);e=e||{};let a=e.node||qe,o=e.clockseq!==void 0?e.clockseq:xe;if(a==null||o==null){let c=e.random||(e.rng||Zt.default)();a==null&&(a=qe=[c[0]|1,c[1],c[2],c[3],c[4],c[5]]),o==null&&(o=xe=(c[6]<<8|c[7])&16383)}let s=e.msecs!==void 0?e.msecs:Date.now(),f=e.nsecs!==void 0?e.nsecs:_e+1,u=s-we+(f-_e)/1e4;if(u<0&&e.clockseq===void 0&&(o=o+1&16383),(u<0||s>we)&&e.nsecs===void 0&&(f=0),f>=1e4)throw new Error("uuid.v1(): Can't create more than 10M uuids/sec");we=s,_e=f,xe=o,s+=122192928e5;let l=((s&268435455)*1e4+f)%4294967296;i[n++]=l>>>24&255,i[n++]=l>>>16&255,i[n++]=l>>>8&255,i[n++]=l&255;let y=s/4294967296*1e4&268435455;i[n++]=y>>>8&255,i[n++]=y&255,i[n++]=y>>>24&15|16,i[n++]=y>>>16&255,i[n++]=o>>>8|128,i[n++]=o&255;for(let c=0;c<6;++c)i[n+c]=a[c];return t||(0,Wt.unsafeStringify)(i)}var Xt=Qt;K.default=Xt});var Pe=p(Q=>{"use strict";Object.defineProperty(Q,"__esModule",{value:!0});Q.default=void 0;var er=tr(N());function tr(e){return e&&e.__esModule?e:{default:e}}function rr(e){if(!(0,er.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 nr=rr;Q.default=nr});var Ee=p(k=>{"use strict";Object.defineProperty(k,"__esModule",{value:!0});k.URL=k.DNS=void 0;k.default=fr;var ir=H(),ar=or(Pe());function or(e){return e&&e.__esModule?e:{default:e}}function sr(e){e=unescape(encodeURIComponent(e));let t=[];for(let r=0;r<e.length;++r)t.push(e.charCodeAt(r));return t}var $e="6ba7b810-9dad-11d1-80b4-00c04fd430c8";k.DNS=$e;var Ne="6ba7b811-9dad-11d1-80b4-00c04fd430c8";k.URL=Ne;function fr(e,t,r){function n(i,a,o,s){var f;if(typeof i=="string"&&(i=sr(i)),typeof a=="string"&&(a=(0,ar.default)(a)),((f=a)===null||f===void 0?void 0:f.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let u=new Uint8Array(16+i.length);if(u.set(a),u.set(i,a.length),u=r(u),u[6]=u[6]&15|t,u[8]=u[8]&63|128,o){s=s||0;for(let l=0;l<16;++l)o[s+l]=u[l];return o}return(0,ir.unsafeStringify)(u)}try{n.name=e}catch{}return n.DNS=$e,n.URL=Ne,n}});var Be=p(X=>{"use strict";Object.defineProperty(X,"__esModule",{value:!0});X.default=void 0;var ur=lr(require("crypto"));function lr(e){return e&&e.__esModule?e:{default:e}}function dr(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),ur.default.createHash("md5").update(e).digest()}var cr=dr;X.default=cr});var je=p(ee=>{"use strict";Object.defineProperty(ee,"__esModule",{value:!0});ee.default=void 0;var pr=He(Ee()),yr=He(Be());function He(e){return e&&e.__esModule?e:{default:e}}var mr=(0,pr.default)("v3",48,yr.default),gr=mr;ee.default=gr});var Je=p(te=>{"use strict";Object.defineProperty(te,"__esModule",{value:!0});te.default=void 0;var hr=vr(require("crypto"));function vr(e){return e&&e.__esModule?e:{default:e}}var br={randomUUID:hr.default.randomUUID};te.default=br});var Ve=p(re=>{"use strict";Object.defineProperty(re,"__esModule",{value:!0});re.default=void 0;var ze=Ge(Je()),xr=Ge(be()),wr=H();function Ge(e){return e&&e.__esModule?e:{default:e}}function _r(e,t,r){if(ze.default.randomUUID&&!t&&!e)return ze.default.randomUUID();e=e||{};let n=e.random||(e.rng||xr.default)();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(0,wr.unsafeStringify)(n)}var Pr=_r;re.default=Pr});var Ye=p(ne=>{"use strict";Object.defineProperty(ne,"__esModule",{value:!0});ne.default=void 0;var Er=Tr(require("crypto"));function Tr(e){return e&&e.__esModule?e:{default:e}}function Or(e){return Array.isArray(e)?e=Buffer.from(e):typeof e=="string"&&(e=Buffer.from(e,"utf8")),Er.default.createHash("sha1").update(e).digest()}var Ar=Or;ne.default=Ar});var We=p(ie=>{"use strict";Object.defineProperty(ie,"__esModule",{value:!0});ie.default=void 0;var Mr=Ze(Ee()),Sr=Ze(Ye());function Ze(e){return e&&e.__esModule?e:{default:e}}var kr=(0,Mr.default)("v5",80,Sr.default),Cr=kr;ie.default=Cr});var Ke=p(ae=>{"use strict";Object.defineProperty(ae,"__esModule",{value:!0});ae.default=void 0;var Fr="00000000-0000-0000-0000-000000000000";ae.default=Fr});var Qe=p(oe=>{"use strict";Object.defineProperty(oe,"__esModule",{value:!0});oe.default=void 0;var Rr=Ir(N());function Ir(e){return e&&e.__esModule?e:{default:e}}function Dr(e){if(!(0,Rr.default)(e))throw TypeError("Invalid UUID");return parseInt(e.slice(14,15),16)}var Ur=Dr;oe.default=Ur});var Xe=p(_=>{"use strict";Object.defineProperty(_,"__esModule",{value:!0});Object.defineProperty(_,"NIL",{enumerable:!0,get:function(){return Br.default}});Object.defineProperty(_,"parse",{enumerable:!0,get:function(){return zr.default}});Object.defineProperty(_,"stringify",{enumerable:!0,get:function(){return Jr.default}});Object.defineProperty(_,"v1",{enumerable:!0,get:function(){return qr.default}});Object.defineProperty(_,"v3",{enumerable:!0,get:function(){return Lr.default}});Object.defineProperty(_,"v4",{enumerable:!0,get:function(){return $r.default}});Object.defineProperty(_,"v5",{enumerable:!0,get:function(){return Nr.default}});Object.defineProperty(_,"validate",{enumerable:!0,get:function(){return jr.default}});Object.defineProperty(_,"version",{enumerable:!0,get:function(){return Hr.default}});var qr=O(Le()),Lr=O(je()),$r=O(Ve()),Nr=O(We()),Br=O(Ke()),Hr=O(Qe()),jr=O(N()),Jr=O(H()),zr=O(Pe());function O(e){return e&&e.__esModule?e:{default:e}}});var Ae=p(d=>{"use strict";var rt=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 Gr(e){let{definitions:t,nullable:r,metadata:n}=e,i=rt(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=Gr;function nt(e){return"ref"in e}d.isRefForm=nt;function Vr(e){return"type"in e}d.isTypeForm=Vr;function it(e){return"enum"in e}d.isEnumForm=it;function at(e){return"elements"in e}d.isElementsForm=at;function Oe(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=Oe;function ot(e){return"values"in e}d.isValuesForm=ot;function st(e){return"discriminator"in e}d.isDiscriminatorForm=st;function C(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(!C(r,t))return!1}if(nt(e)&&!(e.ref in(t.definitions||{}))||it(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(at(e))return C(e.elements,t);if(Oe(e)){for(let r of Object.values(e.properties||{}))if(!C(r,t))return!1;for(let r of Object.values(e.optionalProperties||{}))if(!C(r,t))return!1;for(let r of Object.keys(e.properties||{}))if(r in(e.optionalProperties||{}))return!1}if(ot(e))return C(e.values,t);if(st(e)){for(let r of Object.values(e.mapping))if(!C(r,t)||!Oe(r)||r.nullable||e.discriminator in(r.properties||{})||e.discriminator in(r.optionalProperties||{}))return!1}return!0}d.isValidSchema=C;var Yr=[[!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]],Zr=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function F(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:a=void 0,type:o=void 0,enum:s=void 0,elements:f=void 0,properties:u=void 0,optionalProperties:l=void 0,additionalProperties:y=void 0,values:c=void 0,discriminator:$=void 0,mapping:T=void 0}=t,pe=rt(t,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),ye=[a!==void 0,o!==void 0,s!==void 0,f!==void 0,u!==void 0,l!==void 0,y!==void 0,c!==void 0,$!==void 0,T!==void 0],w=!1;for(let b of Yr)w=w||b.every((J,ke)=>J===ye[ke]);if(!w)return!1;if(r!==void 0){if(typeof r!="object"||Array.isArray(r)||r===null)return!1;for(let b of Object.values(r))if(!F(b))return!1}if(n!==void 0&&typeof n!="boolean"||i!==void 0&&(typeof i!="object"||Array.isArray(i)||i===null)||a!==void 0&&typeof a!="string"||o!==void 0&&(typeof o!="string"||!Zr.includes(o))||s!==void 0&&(!Array.isArray(s)||!s.every(b=>typeof b=="string"))||f!==void 0&&!F(f))return!1;if(u!==void 0){if(typeof u!="object"||Array.isArray(u)||u===null)return!1;for(let b of Object.values(u))if(!F(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(!F(b))return!1}if(y!==void 0&&typeof y!="boolean"||c!==void 0&&!F(c)||$!==void 0&&typeof $!="string")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(!F(b))return!1}return Object.keys(pe).length===0}d.isSchema=F});var ft=p(Me=>{"use strict";Object.defineProperty(Me,"__esModule",{value:!0});var Wr=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Kr(e){let t=e.match(Wr);if(t===null)return!1;let r=parseInt(t[1],10),n=parseInt(t[2],10),i=parseInt(t[3],10),a=parseInt(t[4],10),o=parseInt(t[5],10),s=parseInt(t[6],10);return!(n>12||i>Qr(r,n)||a>23||o>59||s>60)}Me.default=Kr;function Qr(e,t){return t===2?Xr(e)?29:28:en[t]}function Xr(e){return e%4===0&&(e%100!==0||e%400===0)}var en=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var ut=p(A=>{"use strict";var tn=A&&A.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(A,"__esModule",{value:!0});A.validate=A.MaxDepthExceededError=void 0;var rn=tn(ft()),R=Ae(),fe=class extends Error{};A.MaxDepthExceededError=fe;var ue=class extends Error{};function nn(e,t,r){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:r||{maxDepth:0,maxErrors:0}};try{U(n,e,t)}catch(i){if(!(i instanceof ue))throw i}return n.errors}A.validate=nn;function U(e,t,r,n){if(!(t.nullable&&r===null)){if(R.isRefForm(t)){if(e.schemaTokens.length===e.config.maxDepth)throw new fe;e.schemaTokens.push(["definitions",t.ref]),U(e,e.root.definitions[t.ref],r),e.schemaTokens.pop()}else if(R.isTypeForm(t)){switch(g(e,"type"),t.type){case"boolean":typeof r!="boolean"&&h(e);break;case"float32":case"float64":typeof r!="number"&&h(e);break;case"int8":L(e,r,-128,127);break;case"uint8":L(e,r,0,255);break;case"int16":L(e,r,-32768,32767);break;case"uint16":L(e,r,0,65535);break;case"int32":L(e,r,-2147483648,2147483647);break;case"uint32":L(e,r,0,4294967295);break;case"string":typeof r!="string"&&h(e);break;case"timestamp":typeof r!="string"?h(e):rn.default(r)||h(e);break}v(e)}else if(R.isEnumForm(t))g(e,"enum"),(typeof r!="string"||!t.enum.includes(r))&&h(e),v(e);else if(R.isElementsForm(t)){if(g(e,"elements"),Array.isArray(r))for(let[i,a]of r.entries())I(e,i.toString()),U(e,t.elements,a),D(e);else h(e);v(e)}else if(R.isPropertiesForm(t))if(typeof r=="object"&&r!==null&&!Array.isArray(r)){if(t.properties!==void 0){g(e,"properties");for(let[i,a]of Object.entries(t.properties))g(e,i),r.hasOwnProperty(i)?(I(e,i),U(e,a,r[i]),D(e)):h(e),v(e);v(e)}if(t.optionalProperties!==void 0){g(e,"optionalProperties");for(let[i,a]of Object.entries(t.optionalProperties))g(e,i),r.hasOwnProperty(i)&&(I(e,i),U(e,a,r[i]),D(e)),v(e);v(e)}if(t.additionalProperties!==!0)for(let i of Object.keys(r)){let a=t.properties&&i in t.properties,o=t.optionalProperties&&i in t.optionalProperties;!a&&!o&&i!==n&&(I(e,i),h(e),D(e))}}else t.properties!==void 0?g(e,"properties"):g(e,"optionalProperties"),h(e),v(e);else if(R.isValuesForm(t)){if(g(e,"values"),typeof r=="object"&&r!==null&&!Array.isArray(r))for(let[i,a]of Object.entries(r))I(e,i),U(e,t.values,a),D(e);else h(e);v(e)}else if(R.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?(g(e,"mapping"),g(e,i),U(e,t.mapping[i],r,t.discriminator),v(e),v(e)):(g(e,"mapping"),I(e,t.discriminator),h(e),D(e),v(e)):(g(e,"discriminator"),I(e,t.discriminator),h(e),D(e),v(e))}else g(e,"discriminator"),h(e),v(e);else g(e,"discriminator"),h(e),v(e)}}function L(e,t,r,n){(typeof t!="number"||!Number.isInteger(t)||t<r||t>n)&&h(e)}function I(e,t){e.instanceTokens.push(t)}function D(e){e.instanceTokens.pop()}function g(e,t){e.schemaTokens[e.schemaTokens.length-1].push(t)}function v(e){e.schemaTokens[e.schemaTokens.length-1].pop()}function h(e){if(e.errors.push({instancePath:[...e.instanceTokens],schemaPath:[...e.schemaTokens[e.schemaTokens.length-1]]}),e.errors.length===e.config.maxErrors)throw new ue}});var dt=p(M=>{"use strict";var an=M&&M.__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]}),lt=M&&M.__exportStar||function(e,t){for(var r in e)r!=="default"&&!t.hasOwnProperty(r)&&an(t,e,r)};Object.defineProperty(M,"__esModule",{value:!0});lt(Ae(),M);lt(ut(),M)});var hn={};Mt(hn,{GenerationError:()=>ce,ResponseError:()=>q,builtinFontNames:()=>ln,builtinLineHeights:()=>xt,builtinMargins:()=>bt,builtinTextScales:()=>vt,builtinTools:()=>un,formatEntry:()=>wt,parseEntry:()=>_t,register:()=>mn,remarkable:()=>gn});module.exports=St(hn);var gt=ge(Ie());var E=ge(Xe(),1),Un=E.default.v1,qn=E.default.v3,se=E.default.v4,Ln=E.default.v5,$n=E.default.NIL,Nn=E.default.version,Bn=E.default.validate,Hn=E.default.stringify,jn=E.default.parse;function Te(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 tt(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 ct=ge(dt());function j(e,t){if((0,ct.validate)(e,t).length)throw new Error(`couldn't validate schema: ${JSON.stringify(t)} didn't match schema ${JSON.stringify(e)}`)}var pt="3",ht="https://webapp-prod.cloud.remarkable.engineering",on="https://internal.cloud.remarkable.com",yt="x-goog-generation",sn="x-goog-if-generation-match",fn="x-goog-content-length-range",un=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],ln=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],vt={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},bt={sm:50,md:125,rr:180,lg:200},xt={df:-1,md:100,lg:150,xl:200},dn={properties:{docID:{type:"string"},hash:{type:"string"}}},cn={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},le={visibleName:{type:"string"},lastModified:{type:"string"}},de={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},pn={discriminator:"type",mapping:{CollectionType:{properties:le,optionalProperties:de},DocumentType:{properties:le,optionalProperties:{...de,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},mt={id:{type:"string"},hash:{type:"string"}},yn={discriminator:"type",mapping:{CollectionType:{properties:{...le,...mt},optionalProperties:de},DocumentType:{properties:{...le,...mt,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...de,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},q=class extends Error{constructor(r,n,i){super(i);this.status=r,this.statusText=n}},ce=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 mn(e,{deviceDesc:t="browser-chrome",uuid:r=se(),authHost:n=ht,fetch:i=globalThis.fetch}={}){if(e.length!==8)throw new Error(`code should be length 8, but was ${e.length}`);let a=await i(`${n}/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 q(a.status,a.statusText,"couldn't register api")}function wt({hash:e,type:t,documentId:r,subfiles:n,size:i}){return`${e}:${t}:${r}:${n}:${i}
2
- `}function _t(e){let[t,r,n,i,a]=e.split(":");if(t===void 0||r===void 0||n===void 0||i===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:n,subfiles:parseInt(i),size:BigInt(a)};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(a)}}else throw new Error(`entries line contained invalid type: ${r}`)}var Se=class{#f;#o;#s;#t;#r;#e=null;constructor(t,r,n,i,a){this.#f=t,this.#o=r,this.#r=n,this.#s=i,this.#t=a}async#a(t,{body:r,method:n="POST",headers:i={}}){let a=await this.#o(t,{method:n,headers:{Authorization:`Bearer ${this.#f}`,...i},body:r});if(a.ok)return a;{let o=await a.text();throw new q(a.status,a.statusText,`failed reMarkable request: ${o}`)}}async#n({url:t,method:r,maxuploadsize_bytes:n},i,a={}){let o=n?{...a,[fn]:`0,${n}`}:a,s=await this.#o(t,{method:r,body:i,headers:o});if(s.ok)return s;{let f=await s.text();throw new q(s.status,s.statusText,f)}}async#i(t,r,n){let i=r===void 0?"downloads":"uploads",a=n?`{ "http_method": "PUT", "relative_path": "${t}", "root_schema": "${n}", "generation": ${r} }`:JSON.stringify({http_method:"GET",relative_path:t}),s=await(await this.#a(`${this.#t}/sync/v2/signed-urls/${i}`,{body:a})).text(),f=JSON.parse(s);return j(cn,f),f}async getRootHash({cache:t=!0}={}){if(t)for(;this.#e;)try{let[a,o]=await this.#e;return[a,o]}catch{}let r=(async()=>{try{let a=await this.#i("root"),o=await this.#n(a),s=o.headers.get(yt);if(s)return[await o.text(),BigInt(s)];throw new Error("no generation header in root hash")}catch(a){throw this.#e=null,a}})();this.#e=r;let[n,i]=await r;return[n,i]}async putRootHash(t,r){let n=await this.#i("root",r,t),i;try{i=await this.#n(n,t,{[sn]:`${r}`})}catch(s){throw s instanceof q&&s.status===412?(this.#e=null,new ce):s}let a=i.headers.get(yt);if(!a)throw new Error("no generation header in root hash");let o=BigInt(a);return this.#e=Promise.resolve([t,o]),o}async getBuffer(t){let r=await this.#i(t);return await(await this.#n(r)).arrayBuffer()}async getText(t){let r=await this.#r?.get(t);if(r)return r;{let n=await this.#i(t),a=await(await this.#n(n)).text();return await this.#r?.set(t,a),a}}async getMetadata(t){let r=await this.getText(t),n=JSON.parse(r);return j(pn,n),n}async getEntries(t){let r=await this.getText(t),[n,...i]=r.slice(0,-1).split(`
3
- `);if(n!==pt)throw new Error(`got unexpected schema version: ${n}`);return i.map(_t)}async#u(t,r){let n=await this.#i(t,null);await this.#n(n,r)}async putEntries(t,r){let n=new TextEncoder;r.sort((l,y)=>l.documentId.localeCompare(y.documentId));let i=tt(r.map(l=>et(l.hash))),a=await this.#s.digest("SHA-256",i),o=Te(a),s=r.map(wt).join(""),f=`${pt}
4
- ${s}`,u=n.encode(f);return await this.#u(o,u),await this.#r?.set(o,f),{hash:o,type:"80000000",documentId:t,subfiles:r.length,size:0n}}async putBuffer(t,r){let n=await this.#s.digest("SHA-256",r),i=Te(n);return await this.#u(i,r),{hash:i,type:"0",documentId:t,subfiles:0,size:BigInt(r.length)}}async putText(t,r){let n=new TextEncoder,i=await this.putBuffer(t,n.encode(r));return await this.#r?.set(i.hash,r),i}async putMetadata(t,r){return await this.putText(`${t}.metadata`,JSON.stringify(r))}async putCollection(t,r=""){let n=se(),i=`${new Date().valueOf()}`,a=[],o={type:"CollectionType",visibleName:t,version:0,parent:r,synced:!0,lastModified:i};a.push(this.putMetadata(n,o)),a.push(this.putText(`${n}.content`,"{}"));let s=await Promise.all(a);return await this.putEntries(n,s)}async#l(t,r,n,i,a){if(a.fileType!==n)throw new Error(`internal error: fileTypes don't match: ${n}, ${a.fileType}`);let o=se(),s=`${new Date().valueOf()}`,f=[];f.push(this.putBuffer(`${o}.${n}`,r));let u={type:"DocumentType",visibleName:t,version:0,parent:i,synced:!0,lastModified:s};f.push(this.putMetadata(o,u)),f.push(this.putText(`${o}.content`,JSON.stringify(a)));let l=await Promise.all(f);return await this.putEntries(o,l)}async putEpub(t,r,{parent:n="",margins:i=125,orientation:a,textAlignment:o,textScale:s=1,lineHeight:f=-1,fontName:u="",cover:l="visited",lastTool:y}={}){let c={dummyDocument:!1,extraMetadata:{LastTool:y},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof f=="string"?xt[f]:f,margins:typeof i=="string"?bt[i]:i,textScale:typeof s=="string"?vt[s]:s,pages:[],coverPageNumber:l==="first"?0:-1,formatVersion:1,orientation:a,textAlignment:o,fontName:u};return await this.#l(t,r,"epub",n,c)}async putPdf(t,r,{parent:n="",orientation:i,cover:a="first",lastTool:o}={}){let s={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:i};return await this.#l(t,r,"pdf",n,s)}async syncComplete(t){let r=`{ "generation": ${t} }`;await this.#a(`${this.#t}/sync/v2/sync-complete`,{body:r})}async#d(t,r,n){let{hash:i}=await this.putEntries("",r),a=await this.putRootHash(i,t);if(n)try{return await this.syncComplete(a),!0}catch{return!1}else return!1}async create(t,r={}){let{cache:n=!0,sync:i=!0}=typeof r=="boolean"?{cache:!1,sync:r}:r,[a,o]=await this.getRootHash({cache:n}),s=await this.getEntries(a);return s.push(t),await this.#d(o,s,i)}async move(t,r,n={}){let{cache:i=!0,sync:a=!0}=typeof n=="boolean"?{cache:!1,sync:n}:n,[o,s]=await this.getRootHash({cache:i}),f=await this.getEntries(o);if(!(!r||r==="trash")){let w=f.find(me=>me.documentId===r);if(w){if(w.type!=="80000000")throw new Error(`destination id was a raw file: ${r}`)}else throw new Error(`destination id not found: ${r}`);let b=await this.getEntries(w.hash),[J]=b.filter(me=>me.documentId===`${r}.metadata`);if(!J)throw new Error(`destination id didn't have metadata: ${r}`);if((await this.getMetadata(J.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${r}`)}let u=f.findIndex(w=>w.documentId===t);if(u===-1)throw new Error(`document not found: ${t}`);let[l]=f.splice(u,1);if(l.type!=="80000000")throw new Error(`document was a raw file: ${t}`);let y=await this.getEntries(l.hash),c=y.findIndex(w=>w.documentId===`${t}.metadata`);if(c===-1)throw new Error(`document didn't have metadata: ${t}`);let[$]=y.splice(c,1),T=await this.getMetadata($.hash);T.parent=r;let pe=await this.putMetadata(t,T);y.push(pe);let ye=await this.putEntries(t,y);return f.push(ye),await this.#d(s,f,a)}async getEntriesMetadata(){let r=await(await this.#a(`${this.#t}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),n=JSON.parse(r);return j({elements:yn},n),n}async#c(t,r,n){let a=new TextEncoder().encode(JSON.stringify({file_name:t})),s=await(await this.#a(`${this.#t}/doc/v2/files`,{body:r,headers:{"content-type":n,"rm-meta":(0,gt.fromByteArray)(a),"rm-source":"RoR-Browser"}})).text(),f=JSON.parse(s);return j(dn,f),f}async uploadEpub(t,r){return await this.#c(t,r,"application/epub+zip")}async uploadPdf(t,r){return await this.#c(t,r,"application/pdf")}};async function gn(e,{fetch:t=globalThis.fetch,cache:r,subtle:n=globalThis.crypto?.subtle,authHost:i=ht,syncHost:a=on}={}){let o=await t(`${i}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!o.ok)throw new Error(`couldn't fetch auth token: ${o.statusText}`);let s=await o.text();return new Se(s,t,r,n,a)}0&&(module.exports={GenerationError,ResponseError,builtinFontNames,builtinLineHeights,builtinMargins,builtinTextScales,builtinTools,formatEntry,parseEntry,register,remarkable});
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,4 +1,12 @@
1
- var He=Object.create;var ye=Object.defineProperty;var Je=Object.getOwnPropertyDescriptor;var Ve=Object.getOwnPropertyNames;var qe=Object.getPrototypeOf,Ge=Object.prototype.hasOwnProperty;var j=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports);var ze=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Ve(r))!Ge.call(e,i)&&i!==t&&ye(e,i,{get:()=>r[i],enumerable:!(n=Je(r,i))||n.enumerable});return e};var he=(e,r,t)=>(t=e!=null?He(qe(e)):{},ze(r||!e||!e.__esModule?ye(t,"default",{value:e,enumerable:!0}):t,e));var we=j(W=>{"use strict";W.byteLength=Ye;W.toByteArray=Ke;W.fromByteArray=et;var O=[],A=[],We=typeof Uint8Array<"u"?Uint8Array:Array,ie="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(F=0,ge=ie.length;F<ge;++F)O[F]=ie[F],A[ie.charCodeAt(F)]=F;var F,ge;A["-".charCodeAt(0)]=62;A["_".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 Ye(e){var r=be(e),t=r[0],n=r[1];return(t+n)*3/4-n}function Ze(e,r,t){return(r+t)*3/4-t}function Ke(e){var r,t=be(e),n=t[0],i=t[1],o=new We(Ze(e,n,i)),s=0,a=i>0?n-4:n,f;for(f=0;f<a;f+=4)r=A[e.charCodeAt(f)]<<18|A[e.charCodeAt(f+1)]<<12|A[e.charCodeAt(f+2)]<<6|A[e.charCodeAt(f+3)],o[s++]=r>>16&255,o[s++]=r>>8&255,o[s++]=r&255;return i===2&&(r=A[e.charCodeAt(f)]<<2|A[e.charCodeAt(f+1)]>>4,o[s++]=r&255),i===1&&(r=A[e.charCodeAt(f)]<<10|A[e.charCodeAt(f+1)]<<4|A[e.charCodeAt(f+2)]>>2,o[s++]=r>>8&255,o[s++]=r&255),o}function Xe(e){return O[e>>18&63]+O[e>>12&63]+O[e>>6&63]+O[e&63]}function Qe(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(Xe(n));return i.join("")}function et(e){for(var r,t=e.length,n=t%3,i=[],o=16383,s=0,a=t-n;s<a;s+=o)i.push(Qe(e,s,s+o>a?a:s+o));return n===1?(r=e[t-1],i.push(O[r>>2]+O[r<<4&63]+"==")):n===2&&(r=(e[t-2]<<8)+e[t-1],i.push(O[r>>10]+O[r>>4&63]+O[r<<2&63]+"=")),i.join("")}});var ue=j(d=>{"use strict";var ke=d&&d.__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(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 ht(e){let{definitions:r,nullable:t,metadata:n}=e,i=ke(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=ht;function Oe(e){return"ref"in e}d.isRefForm=Oe;function gt(e){return"type"in e}d.isTypeForm=gt;function Se(e){return"enum"in e}d.isEnumForm=Se;function Ce(e){return"elements"in e}d.isElementsForm=Ce;function le(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=le;function Me(e){return"values"in e}d.isValuesForm=Me;function Fe(e){return"discriminator"in e}d.isDiscriminatorForm=Fe;function U(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(!U(t,r))return!1}if(Oe(e)&&!(e.ref in(r.definitions||{}))||Se(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Ce(e))return U(e.elements,r);if(le(e)){for(let t of Object.values(e.properties||{}))if(!U(t,r))return!1;for(let t of Object.values(e.optionalProperties||{}))if(!U(t,r))return!1;for(let t of Object.keys(e.properties||{}))if(t in(e.optionalProperties||{}))return!1}if(Me(e))return U(e.values,r);if(Fe(e)){for(let t of Object.values(e.mapping))if(!U(t,r)||!le(t)||t.nullable||e.discriminator in(t.properties||{})||e.discriminator in(t.optionalProperties||{}))return!1}return!0}d.isValidSchema=U;var bt=[[!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]],wt=["boolean","float32","float64","int8","uint8","int16","uint16","int32","uint32","string","timestamp"];function I(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:s=void 0,enum:a=void 0,elements:f=void 0,properties:l=void 0,optionalProperties:u=void 0,additionalProperties:p=void 0,values:P=void 0,discriminator:c=void 0,mapping:T=void 0}=r,B=ke(r,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),re=[o!==void 0,s!==void 0,a!==void 0,f!==void 0,l!==void 0,u!==void 0,p!==void 0,P!==void 0,c!==void 0,T!==void 0],k=!1;for(let v of bt)k=k||v.every((z,me)=>z===re[me]);if(!k)return!1;if(t!==void 0){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;for(let v of Object.values(t))if(!I(v))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"||s!==void 0&&(typeof s!="string"||!wt.includes(s))||a!==void 0&&(!Array.isArray(a)||!a.every(v=>typeof v=="string"))||f!==void 0&&!I(f))return!1;if(l!==void 0){if(typeof l!="object"||Array.isArray(l)||l===null)return!1;for(let v of Object.values(l))if(!I(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(!I(v))return!1}if(p!==void 0&&typeof p!="boolean"||P!==void 0&&!I(P)||c!==void 0&&typeof c!="string")return!1;if(T!==void 0){if(typeof T!="object"||Array.isArray(T)||T===null)return!1;for(let v of Object.values(T))if(!I(v))return!1}return Object.keys(B).length===0}d.isSchema=I});var Ue=j(de=>{"use strict";Object.defineProperty(de,"__esModule",{value:!0});var xt=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function Et(e){let r=e.match(xt);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),s=parseInt(r[5],10),a=parseInt(r[6],10);return!(n>12||i>vt(t,n)||o>23||s>59||a>60)}de.default=Et;function vt(e,r){return r===2?Pt(e)?29:28:Tt[r]}function Pt(e){return e%4===0&&(e%100!==0||e%400===0)}var Tt=[0,31,0,31,30,31,30,31,31,30,31,30,31]});var Ie=j(C=>{"use strict";var At=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 kt=At(Ue()),R=ue(),X=class extends Error{};C.MaxDepthExceededError=X;var Q=class extends Error{};function Ot(e,r,t){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:t||{maxDepth:0,maxErrors:0}};try{L(n,e,r)}catch(i){if(!(i instanceof Q))throw i}return n.errors}C.validate=Ot;function L(e,r,t,n){if(!(r.nullable&&t===null)){if(R.isRefForm(r)){if(e.schemaTokens.length===e.config.maxDepth)throw new X;e.schemaTokens.push(["definitions",r.ref]),L(e,e.root.definitions[r.ref],t),e.schemaTokens.pop()}else if(R.isTypeForm(r)){switch(w(e,"type"),r.type){case"boolean":typeof t!="boolean"&&x(e);break;case"float32":case"float64":typeof t!="number"&&x(e);break;case"int8":D(e,t,-128,127);break;case"uint8":D(e,t,0,255);break;case"int16":D(e,t,-32768,32767);break;case"uint16":D(e,t,0,65535);break;case"int32":D(e,t,-2147483648,2147483647);break;case"uint32":D(e,t,0,4294967295);break;case"string":typeof t!="string"&&x(e);break;case"timestamp":typeof t!="string"?x(e):kt.default(t)||x(e);break}E(e)}else if(R.isEnumForm(r))w(e,"enum"),(typeof t!="string"||!r.enum.includes(t))&&x(e),E(e);else if(R.isElementsForm(r)){if(w(e,"elements"),Array.isArray(t))for(let[i,o]of t.entries())_(e,i.toString()),L(e,r.elements,o),$(e);else x(e);E(e)}else if(R.isPropertiesForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t)){if(r.properties!==void 0){w(e,"properties");for(let[i,o]of Object.entries(r.properties))w(e,i),t.hasOwnProperty(i)?(_(e,i),L(e,o,t[i]),$(e)):x(e),E(e);E(e)}if(r.optionalProperties!==void 0){w(e,"optionalProperties");for(let[i,o]of Object.entries(r.optionalProperties))w(e,i),t.hasOwnProperty(i)&&(_(e,i),L(e,o,t[i]),$(e)),E(e);E(e)}if(r.additionalProperties!==!0)for(let i of Object.keys(t)){let o=r.properties&&i in r.properties,s=r.optionalProperties&&i in r.optionalProperties;!o&&!s&&i!==n&&(_(e,i),x(e),$(e))}}else r.properties!==void 0?w(e,"properties"):w(e,"optionalProperties"),x(e),E(e);else if(R.isValuesForm(r)){if(w(e,"values"),typeof t=="object"&&t!==null&&!Array.isArray(t))for(let[i,o]of Object.entries(t))_(e,i),L(e,r.values,o),$(e);else x(e);E(e)}else if(R.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?(w(e,"mapping"),w(e,i),L(e,r.mapping[i],t,r.discriminator),E(e),E(e)):(w(e,"mapping"),_(e,r.discriminator),x(e),$(e),E(e)):(w(e,"discriminator"),_(e,r.discriminator),x(e),$(e),E(e))}else w(e,"discriminator"),x(e),E(e);else w(e,"discriminator"),x(e),E(e)}}function D(e,r,t,n){(typeof r!="number"||!Number.isInteger(r)||r<t||r>n)&&x(e)}function _(e,r){e.instanceTokens.push(r)}function $(e){e.instanceTokens.pop()}function w(e,r){e.schemaTokens[e.schemaTokens.length-1].push(r)}function E(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 Q}});var _e=j(M=>{"use strict";var St=M&&M.__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]}),Re=M&&M.__exportStar||function(e,r){for(var t in e)t!=="default"&&!r.hasOwnProperty(t)&&St(r,e,t)};Object.defineProperty(M,"__esModule",{value:!0});Re(ue(),M);Re(Ie(),M)});var Be=he(we());var Y,tt=new Uint8Array(16);function Z(){if(!Y&&(Y=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Y))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Y(tt)}var xe=/^(?:[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 rt(e){return typeof e=="string"&&xe.test(e)}var H=rt;var m=[];for(let e=0;e<256;++e)m.push((e+256).toString(16).slice(1));function J(e,r=0){return(m[e[r+0]]+m[e[r+1]]+m[e[r+2]]+m[e[r+3]]+"-"+m[e[r+4]]+m[e[r+5]]+"-"+m[e[r+6]]+m[e[r+7]]+"-"+m[e[r+8]]+m[e[r+9]]+"-"+m[e[r+10]]+m[e[r+11]]+m[e[r+12]]+m[e[r+13]]+m[e[r+14]]+m[e[r+15]]).toLowerCase()}function nt(e){if(!H(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 oe=nt;function it(e){e=unescape(encodeURIComponent(e));let r=[];for(let t=0;t<e.length;++t)r.push(e.charCodeAt(t));return r}var ot="6ba7b810-9dad-11d1-80b4-00c04fd430c8",st="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function V(e,r,t){function n(i,o,s,a){var f;if(typeof i=="string"&&(i=it(i)),typeof o=="string"&&(o=oe(o)),((f=o)===null||f===void 0?void 0:f.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+i.length);if(l.set(o),l.set(i,o.length),l=t(l),l[6]=l[6]&15|r,l[8]=l[8]&63|128,s){a=a||0;for(let u=0;u<16;++u)s[a+u]=l[u];return s}return J(l)}try{n.name=e}catch{}return n.DNS=ot,n.URL=st,n}function at(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 ft(lt(ut(e),e.length*8))}function ft(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,s=parseInt(n.charAt(o>>>4&15)+n.charAt(o&15),16);r.push(s)}return r}function Ee(e){return(e+64>>>9<<4)+14+1}function lt(e,r){e[r>>5]|=128<<r%32,e[Ee(r)-1]=r;let t=1732584193,n=-271733879,i=-1732584194,o=271733878;for(let s=0;s<e.length;s+=16){let a=t,f=n,l=i,u=o;t=y(t,n,i,o,e[s],7,-680876936),o=y(o,t,n,i,e[s+1],12,-389564586),i=y(i,o,t,n,e[s+2],17,606105819),n=y(n,i,o,t,e[s+3],22,-1044525330),t=y(t,n,i,o,e[s+4],7,-176418897),o=y(o,t,n,i,e[s+5],12,1200080426),i=y(i,o,t,n,e[s+6],17,-1473231341),n=y(n,i,o,t,e[s+7],22,-45705983),t=y(t,n,i,o,e[s+8],7,1770035416),o=y(o,t,n,i,e[s+9],12,-1958414417),i=y(i,o,t,n,e[s+10],17,-42063),n=y(n,i,o,t,e[s+11],22,-1990404162),t=y(t,n,i,o,e[s+12],7,1804603682),o=y(o,t,n,i,e[s+13],12,-40341101),i=y(i,o,t,n,e[s+14],17,-1502002290),n=y(n,i,o,t,e[s+15],22,1236535329),t=h(t,n,i,o,e[s+1],5,-165796510),o=h(o,t,n,i,e[s+6],9,-1069501632),i=h(i,o,t,n,e[s+11],14,643717713),n=h(n,i,o,t,e[s],20,-373897302),t=h(t,n,i,o,e[s+5],5,-701558691),o=h(o,t,n,i,e[s+10],9,38016083),i=h(i,o,t,n,e[s+15],14,-660478335),n=h(n,i,o,t,e[s+4],20,-405537848),t=h(t,n,i,o,e[s+9],5,568446438),o=h(o,t,n,i,e[s+14],9,-1019803690),i=h(i,o,t,n,e[s+3],14,-187363961),n=h(n,i,o,t,e[s+8],20,1163531501),t=h(t,n,i,o,e[s+13],5,-1444681467),o=h(o,t,n,i,e[s+2],9,-51403784),i=h(i,o,t,n,e[s+7],14,1735328473),n=h(n,i,o,t,e[s+12],20,-1926607734),t=g(t,n,i,o,e[s+5],4,-378558),o=g(o,t,n,i,e[s+8],11,-2022574463),i=g(i,o,t,n,e[s+11],16,1839030562),n=g(n,i,o,t,e[s+14],23,-35309556),t=g(t,n,i,o,e[s+1],4,-1530992060),o=g(o,t,n,i,e[s+4],11,1272893353),i=g(i,o,t,n,e[s+7],16,-155497632),n=g(n,i,o,t,e[s+10],23,-1094730640),t=g(t,n,i,o,e[s+13],4,681279174),o=g(o,t,n,i,e[s],11,-358537222),i=g(i,o,t,n,e[s+3],16,-722521979),n=g(n,i,o,t,e[s+6],23,76029189),t=g(t,n,i,o,e[s+9],4,-640364487),o=g(o,t,n,i,e[s+12],11,-421815835),i=g(i,o,t,n,e[s+15],16,530742520),n=g(n,i,o,t,e[s+2],23,-995338651),t=b(t,n,i,o,e[s],6,-198630844),o=b(o,t,n,i,e[s+7],10,1126891415),i=b(i,o,t,n,e[s+14],15,-1416354905),n=b(n,i,o,t,e[s+5],21,-57434055),t=b(t,n,i,o,e[s+12],6,1700485571),o=b(o,t,n,i,e[s+3],10,-1894986606),i=b(i,o,t,n,e[s+10],15,-1051523),n=b(n,i,o,t,e[s+1],21,-2054922799),t=b(t,n,i,o,e[s+8],6,1873313359),o=b(o,t,n,i,e[s+15],10,-30611744),i=b(i,o,t,n,e[s+6],15,-1560198380),n=b(n,i,o,t,e[s+13],21,1309151649),t=b(t,n,i,o,e[s+4],6,-145523070),o=b(o,t,n,i,e[s+11],10,-1120210379),i=b(i,o,t,n,e[s+2],15,718787259),n=b(n,i,o,t,e[s+9],21,-343485551),t=S(t,a),n=S(n,f),i=S(i,l),o=S(o,u)}return[t,n,i,o]}function ut(e){if(e.length===0)return[];let r=e.length*8,t=new Uint32Array(Ee(r));for(let n=0;n<r;n+=8)t[n>>5]|=(e[n/8]&255)<<n%32;return t}function S(e,r){let t=(e&65535)+(r&65535);return(e>>16)+(r>>16)+(t>>16)<<16|t&65535}function dt(e,r){return e<<r|e>>>32-r}function K(e,r,t,n,i,o){return S(dt(S(S(r,e),S(n,o)),i),t)}function y(e,r,t,n,i,o,s){return K(r&t|~r&n,e,r,i,o,s)}function h(e,r,t,n,i,o,s){return K(r&n|t&~n,e,r,i,o,s)}function g(e,r,t,n,i,o,s){return K(r^t^n,e,r,i,o,s)}function b(e,r,t,n,i,o,s){return K(t^(r|~n),e,r,i,o,s)}var ve=at;var sr=V("v3",48,ve);var ct=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),se={randomUUID:ct};function pt(e,r,t){if(se.randomUUID&&!r&&!e)return se.randomUUID();e=e||{};let n=e.random||(e.rng||Z)();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 J(n)}var q=pt;function mt(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 yt(e){let r=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){let s=unescape(encodeURIComponent(e));e=[];for(let a=0;a<s.length;++a)e.push(s.charCodeAt(a))}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 s=0;s<i;++s){let a=new Uint32Array(16);for(let f=0;f<16;++f)a[f]=e[s*64+f*4]<<24|e[s*64+f*4+1]<<16|e[s*64+f*4+2]<<8|e[s*64+f*4+3];o[s]=a}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 s=0;s<i;++s){let a=new Uint32Array(80);for(let c=0;c<16;++c)a[c]=o[s][c];for(let c=16;c<80;++c)a[c]=ae(a[c-3]^a[c-8]^a[c-14]^a[c-16],1);let f=t[0],l=t[1],u=t[2],p=t[3],P=t[4];for(let c=0;c<80;++c){let T=Math.floor(c/20),B=ae(f,5)+mt(T,l,u,p)+P+r[T]+a[c]>>>0;P=p,p=u,u=ae(l,30)>>>0,l=f,f=B}t[0]=t[0]+f>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+u>>>0,t[3]=t[3]+p>>>0,t[4]=t[4]+P>>>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 Pe=yt;var hr=V("v5",80,Pe);function fe(e){return[...new Uint8Array(e)].map(r=>r.toString(16).padStart(2,"0")).join("")}function Te(e){return new Uint8Array((e.match(/../g)??[]).map(r=>parseInt(r,16)))}function Ae(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 $e=he(_e());function G(e,r){if((0,$e.validate)(e,r).length)throw new Error(`couldn't validate schema: ${JSON.stringify(r)} didn't match schema ${JSON.stringify(e)}`)}var Le="3",je="https://webapp-prod.cloud.remarkable.engineering",Ct="https://internal.cloud.remarkable.com",De="x-goog-generation",Mt="x-goog-if-generation-match",Ft="x-goog-content-length-range",zr=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Wr=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Ut={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},It={sm:50,md:125,rr:180,lg:200},Rt={df:-1,md:100,lg:150,xl:200},_t={properties:{docID:{type:"string"},hash:{type:"string"}}},$t={properties:{relative_path:{type:"string"},url:{type:"string"},expires:{type:"timestamp"},method:{enum:["POST","GET","PUT","DELETE"]}},optionalProperties:{maxuploadsize_bytes:{type:"float64"}}},ee={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"}},Lt={discriminator:"type",mapping:{CollectionType:{properties:ee,optionalProperties:te},DocumentType:{properties:ee,optionalProperties:{...te,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},Ne={id:{type:"string"},hash:{type:"string"}},Dt={discriminator:"type",mapping:{CollectionType:{properties:{...ee,...Ne},optionalProperties:te},DocumentType:{properties:{...ee,...Ne,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...te,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},N=class extends Error{constructor(t,n,i){super(i);this.status=t,this.statusText=n}},ce=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 Yr(e,{deviceDesc:r="browser-chrome",uuid:t=q(),authHost:n=je,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 N(o.status,o.statusText,"couldn't register api")}function Nt({hash:e,type:r,documentId:t,subfiles:n,size:i}){return`${e}:${r}:${t}:${n}:${i}
2
- `}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 pe=class{#f;#s;#a;#t;#r;#e=null;constructor(r,t,n,i,o){this.#f=r,this.#s=t,this.#r=n,this.#a=i,this.#t=o}async#o(r,{body:t,method:n="POST",headers:i={}}){let o=await this.#s(r,{method:n,headers:{Authorization:`Bearer ${this.#f}`,...i},body:t});if(o.ok)return o;{let s=await o.text();throw new N(o.status,o.statusText,`failed reMarkable request: ${s}`)}}async#n({url:r,method:t,maxuploadsize_bytes:n},i,o={}){let s=n?{...o,[Ft]:`0,${n}`}:o,a=await this.#s(r,{method:t,body:i,headers:s});if(a.ok)return a;{let f=await a.text();throw new N(a.status,a.statusText,f)}}async#i(r,t,n){let i=t===void 0?"downloads":"uploads",o=n?`{ "http_method": "PUT", "relative_path": "${r}", "root_schema": "${n}", "generation": ${t} }`:JSON.stringify({http_method:"GET",relative_path:r}),a=await(await this.#o(`${this.#t}/sync/v2/signed-urls/${i}`,{body:o})).text(),f=JSON.parse(a);return G($t,f),f}async getRootHash({cache:r=!0}={}){if(r)for(;this.#e;)try{let[o,s]=await this.#e;return[o,s]}catch{}let t=(async()=>{try{let o=await this.#i("root"),s=await this.#n(o),a=s.headers.get(De);if(a)return[await s.text(),BigInt(a)];throw new Error("no generation header in root hash")}catch(o){throw this.#e=null,o}})();this.#e=t;let[n,i]=await t;return[n,i]}async putRootHash(r,t){let n=await this.#i("root",t,r),i;try{i=await this.#n(n,r,{[Mt]:`${t}`})}catch(a){throw a instanceof N&&a.status===412?(this.#e=null,new ce):a}let o=i.headers.get(De);if(!o)throw new Error("no generation header in root hash");let s=BigInt(o);return this.#e=Promise.resolve([r,s]),s}async getBuffer(r){let t=await this.#i(r);return await(await this.#n(t)).arrayBuffer()}async getText(r){let t=await this.#r?.get(r);if(t)return t;{let n=await this.#i(r),o=await(await this.#n(n)).text();return await this.#r?.set(r,o),o}}async getMetadata(r){let t=await this.getText(r),n=JSON.parse(t);return G(Lt,n),n}async getEntries(r){let t=await this.getText(r),[n,...i]=t.slice(0,-1).split(`
3
- `);if(n!==Le)throw new Error(`got unexpected schema version: ${n}`);return i.map(Bt)}async#l(r,t){let n=await this.#i(r,null);await this.#n(n,t)}async putEntries(r,t){let n=new TextEncoder;t.sort((u,p)=>u.documentId.localeCompare(p.documentId));let i=Ae(t.map(u=>Te(u.hash))),o=await this.#a.digest("SHA-256",i),s=fe(o),a=t.map(Nt).join(""),f=`${Le}
4
- ${a}`,l=n.encode(f);return await this.#l(s,l),await this.#r?.set(s,f),{hash:s,type:"80000000",documentId:r,subfiles:t.length,size:0n}}async putBuffer(r,t){let n=await this.#a.digest("SHA-256",t),i=fe(n);return await this.#l(i,t),{hash:i,type:"0",documentId:r,subfiles:0,size:BigInt(t.length)}}async putText(r,t){let n=new TextEncoder,i=await this.putBuffer(r,n.encode(t));return await this.#r?.set(i.hash,t),i}async putMetadata(r,t){return await this.putText(`${r}.metadata`,JSON.stringify(t))}async putCollection(r,t=""){let n=q(),i=`${new Date().valueOf()}`,o=[],s={type:"CollectionType",visibleName:r,version:0,parent:t,synced:!0,lastModified:i};o.push(this.putMetadata(n,s)),o.push(this.putText(`${n}.content`,"{}"));let a=await Promise.all(o);return await this.putEntries(n,a)}async#u(r,t,n,i,o){if(o.fileType!==n)throw new Error(`internal error: fileTypes don't match: ${n}, ${o.fileType}`);let s=q(),a=`${new Date().valueOf()}`,f=[];f.push(this.putBuffer(`${s}.${n}`,t));let l={type:"DocumentType",visibleName:r,version:0,parent:i,synced:!0,lastModified:a};f.push(this.putMetadata(s,l)),f.push(this.putText(`${s}.content`,JSON.stringify(o)));let u=await Promise.all(f);return await this.putEntries(s,u)}async putEpub(r,t,{parent:n="",margins:i=125,orientation:o,textAlignment:s,textScale:a=1,lineHeight:f=-1,fontName:l="",cover:u="visited",lastTool:p}={}){let P={dummyDocument:!1,extraMetadata:{LastTool:p},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof f=="string"?Rt[f]:f,margins:typeof i=="string"?It[i]:i,textScale:typeof a=="string"?Ut[a]:a,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:s,fontName:l};return await this.#u(r,t,"epub",n,P)}async putPdf(r,t,{parent:n="",orientation:i,cover:o="first",lastTool:s}={}){let a={dummyDocument:!1,extraMetadata:{LastTool:s},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.#u(r,t,"pdf",n,a)}async syncComplete(r){let t=`{ "generation": ${r} }`;await this.#o(`${this.#t}/sync/v2/sync-complete`,{body:t})}async#d(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,t={}){let{cache:n=!0,sync:i=!0}=typeof t=="boolean"?{cache:!1,sync:t}:t,[o,s]=await this.getRootHash({cache:n}),a=await this.getEntries(o);return a.push(r),await this.#d(s,a,i)}async move(r,t,n={}){let{cache:i=!0,sync:o=!0}=typeof n=="boolean"?{cache:!1,sync:n}:n,[s,a]=await this.getRootHash({cache:i}),f=await this.getEntries(s);if(!(!t||t==="trash")){let k=f.find(ne=>ne.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 v=await this.getEntries(k.hash),[z]=v.filter(ne=>ne.documentId===`${t}.metadata`);if(!z)throw new Error(`destination id didn't have metadata: ${t}`);if((await this.getMetadata(z.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${t}`)}let l=f.findIndex(k=>k.documentId===r);if(l===-1)throw new Error(`document not found: ${r}`);let[u]=f.splice(l,1);if(u.type!=="80000000")throw new Error(`document was a raw file: ${r}`);let p=await this.getEntries(u.hash),P=p.findIndex(k=>k.documentId===`${r}.metadata`);if(P===-1)throw new Error(`document didn't have metadata: ${r}`);let[c]=p.splice(P,1),T=await this.getMetadata(c.hash);T.parent=t;let B=await this.putMetadata(r,T);p.push(B);let re=await this.putEntries(r,p);return f.push(re),await this.#d(a,f,o)}async getEntriesMetadata(){let t=await(await this.#o(`${this.#t}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),n=JSON.parse(t);return G({elements:Dt},n),n}async#c(r,t,n){let o=new TextEncoder().encode(JSON.stringify({file_name:r})),a=await(await this.#o(`${this.#t}/doc/v2/files`,{body:t,headers:{"content-type":n,"rm-meta":(0,Be.fromByteArray)(o),"rm-source":"RoR-Browser"}})).text(),f=JSON.parse(a);return G(_t,f),f}async uploadEpub(r,t){return await this.#c(r,t,"application/epub+zip")}async uploadPdf(r,t){return await this.#c(r,t,"application/pdf")}};async function Zr(e,{fetch:r=globalThis.fetch,cache:t,subtle:n=globalThis.crypto?.subtle,authHost:i=je,syncHost:o=Ct}={}){let s=await r(`${i}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!s.ok)throw new Error(`couldn't fetch auth token: ${s.statusText}`);let a=await s.text();return new pe(a,r,t,n,o)}export{ce as GenerationError,N as ResponseError,Wr as builtinFontNames,Rt as builtinLineHeights,It as builtinMargins,Ut as builtinTextScales,zr as builtinTools,Nt as formatEntry,Bt as parseEntry,Yr as register,Zr as remarkable};
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,4 +1,12 @@
1
- var rmapi=(()=>{var We=Object.create;var W=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var Ze=Object.getOwnPropertyNames;var Ke=Object.getPrototypeOf,Xe=Object.prototype.hasOwnProperty;var j=(e,r)=>()=>(r||e((r={exports:{}}).exports,r),r.exports),Qe=(e,r)=>{for(var t in r)W(e,t,{get:r[t],enumerable:!0})},he=(e,r,t,n)=>{if(r&&typeof r=="object"||typeof r=="function")for(let i of Ze(r))!Xe.call(e,i)&&i!==t&&W(e,i,{get:()=>r[i],enumerable:!(n=Ye(r,i))||n.enumerable});return e};var ge=(e,r,t)=>(t=e!=null?We(Ke(e)):{},he(r||!e||!e.__esModule?W(t,"default",{value:e,enumerable:!0}):t,e)),et=e=>he(W({},"__esModule",{value:!0}),e);var xe=j(Y=>{"use strict";Y.byteLength=rt;Y.toByteArray=it;Y.fromByteArray=at;var O=[],A=[],tt=typeof Uint8Array<"u"?Uint8Array:Array,se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";for(F=0,be=se.length;F<be;++F)O[F]=se[F],A[se.charCodeAt(F)]=F;var F,be;A["-".charCodeAt(0)]=62;A["_".charCodeAt(0)]=63;function we(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 rt(e){var r=we(e),t=r[0],n=r[1];return(t+n)*3/4-n}function nt(e,r,t){return(r+t)*3/4-t}function it(e){var r,t=we(e),n=t[0],i=t[1],o=new tt(nt(e,n,i)),s=0,a=i>0?n-4:n,f;for(f=0;f<a;f+=4)r=A[e.charCodeAt(f)]<<18|A[e.charCodeAt(f+1)]<<12|A[e.charCodeAt(f+2)]<<6|A[e.charCodeAt(f+3)],o[s++]=r>>16&255,o[s++]=r>>8&255,o[s++]=r&255;return i===2&&(r=A[e.charCodeAt(f)]<<2|A[e.charCodeAt(f+1)]>>4,o[s++]=r&255),i===1&&(r=A[e.charCodeAt(f)]<<10|A[e.charCodeAt(f+1)]<<4|A[e.charCodeAt(f+2)]>>2,o[s++]=r>>8&255,o[s++]=r&255),o}function ot(e){return O[e>>18&63]+O[e>>12&63]+O[e>>6&63]+O[e&63]}function st(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(ot(n));return i.join("")}function at(e){for(var r,t=e.length,n=t%3,i=[],o=16383,s=0,a=t-n;s<a;s+=o)i.push(st(e,s,s+o>a?a:s+o));return n===1?(r=e[t-1],i.push(O[r>>2]+O[r<<4&63]+"==")):n===2&&(r=(e[t-2]<<8)+e[t-1],i.push(O[r>>10]+O[r>>4&63]+O[r<<2&63]+"=")),i.join("")}});var ce=j(d=>{"use strict";var Oe=d&&d.__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(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 Pt(e){let{definitions:r,nullable:t,metadata:n}=e,i=Oe(e,["definitions","nullable","metadata"]);return Object.keys(i).length===0}d.isEmptyForm=Pt;function Se(e){return"ref"in e}d.isRefForm=Se;function Tt(e){return"type"in e}d.isTypeForm=Tt;function Ce(e){return"enum"in e}d.isEnumForm=Ce;function Me(e){return"elements"in e}d.isElementsForm=Me;function de(e){return"properties"in e||"optionalProperties"in e}d.isPropertiesForm=de;function Fe(e){return"values"in e}d.isValuesForm=Fe;function Ue(e){return"discriminator"in e}d.isDiscriminatorForm=Ue;function U(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(!U(t,r))return!1}if(Se(e)&&!(e.ref in(r.definitions||{}))||Ce(e)&&(e.enum.length===0||e.enum.length!==new Set(e.enum).size))return!1;if(Me(e))return U(e.elements,r);if(de(e)){for(let t of Object.values(e.properties||{}))if(!U(t,r))return!1;for(let t of Object.values(e.optionalProperties||{}))if(!U(t,r))return!1;for(let t of Object.keys(e.properties||{}))if(t in(e.optionalProperties||{}))return!1}if(Fe(e))return U(e.values,r);if(Ue(e)){for(let t of Object.values(e.mapping))if(!U(t,r)||!de(t)||t.nullable||e.discriminator in(t.properties||{})||e.discriminator in(t.optionalProperties||{}))return!1}return!0}d.isValidSchema=U;var At=[[!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 I(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:s=void 0,enum:a=void 0,elements:f=void 0,properties:l=void 0,optionalProperties:u=void 0,additionalProperties:p=void 0,values:P=void 0,discriminator:c=void 0,mapping:T=void 0}=r,B=Oe(r,["definitions","nullable","metadata","ref","type","enum","elements","properties","optionalProperties","additionalProperties","values","discriminator","mapping"]),ie=[o!==void 0,s!==void 0,a!==void 0,f!==void 0,l!==void 0,u!==void 0,p!==void 0,P!==void 0,c!==void 0,T!==void 0],k=!1;for(let v of At)k=k||v.every((z,ye)=>z===ie[ye]);if(!k)return!1;if(t!==void 0){if(typeof t!="object"||Array.isArray(t)||t===null)return!1;for(let v of Object.values(t))if(!I(v))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"||s!==void 0&&(typeof s!="string"||!kt.includes(s))||a!==void 0&&(!Array.isArray(a)||!a.every(v=>typeof v=="string"))||f!==void 0&&!I(f))return!1;if(l!==void 0){if(typeof l!="object"||Array.isArray(l)||l===null)return!1;for(let v of Object.values(l))if(!I(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(!I(v))return!1}if(p!==void 0&&typeof p!="boolean"||P!==void 0&&!I(P)||c!==void 0&&typeof c!="string")return!1;if(T!==void 0){if(typeof T!="object"||Array.isArray(T)||T===null)return!1;for(let v of Object.values(T))if(!I(v))return!1}return Object.keys(B).length===0}d.isSchema=I});var Ie=j(pe=>{"use strict";Object.defineProperty(pe,"__esModule",{value:!0});var Ot=/^(\d{4})-(\d{2})-(\d{2})[tT](\d{2}):(\d{2}):(\d{2})(\.\d+)?([zZ]|((\+|-)(\d{2}):(\d{2})))$/;function St(e){let r=e.match(Ot);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),s=parseInt(r[5],10),a=parseInt(r[6],10);return!(n>12||i>Ct(t,n)||o>23||s>59||a>60)}pe.default=St;function Ct(e,r){return r===2?Mt(e)?29:28:Ft[r]}function Mt(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 Re=j(C=>{"use strict";var Ut=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 It=Ut(Ie()),R=ce(),Q=class extends Error{};C.MaxDepthExceededError=Q;var ee=class extends Error{};function Rt(e,r,t){let n={errors:[],instanceTokens:[],schemaTokens:[[]],root:e,config:t||{maxDepth:0,maxErrors:0}};try{L(n,e,r)}catch(i){if(!(i instanceof ee))throw i}return n.errors}C.validate=Rt;function L(e,r,t,n){if(!(r.nullable&&t===null)){if(R.isRefForm(r)){if(e.schemaTokens.length===e.config.maxDepth)throw new Q;e.schemaTokens.push(["definitions",r.ref]),L(e,e.root.definitions[r.ref],t),e.schemaTokens.pop()}else if(R.isTypeForm(r)){switch(w(e,"type"),r.type){case"boolean":typeof t!="boolean"&&x(e);break;case"float32":case"float64":typeof t!="number"&&x(e);break;case"int8":N(e,t,-128,127);break;case"uint8":N(e,t,0,255);break;case"int16":N(e,t,-32768,32767);break;case"uint16":N(e,t,0,65535);break;case"int32":N(e,t,-2147483648,2147483647);break;case"uint32":N(e,t,0,4294967295);break;case"string":typeof t!="string"&&x(e);break;case"timestamp":typeof t!="string"?x(e):It.default(t)||x(e);break}E(e)}else if(R.isEnumForm(r))w(e,"enum"),(typeof t!="string"||!r.enum.includes(t))&&x(e),E(e);else if(R.isElementsForm(r)){if(w(e,"elements"),Array.isArray(t))for(let[i,o]of t.entries())_(e,i.toString()),L(e,r.elements,o),$(e);else x(e);E(e)}else if(R.isPropertiesForm(r))if(typeof t=="object"&&t!==null&&!Array.isArray(t)){if(r.properties!==void 0){w(e,"properties");for(let[i,o]of Object.entries(r.properties))w(e,i),t.hasOwnProperty(i)?(_(e,i),L(e,o,t[i]),$(e)):x(e),E(e);E(e)}if(r.optionalProperties!==void 0){w(e,"optionalProperties");for(let[i,o]of Object.entries(r.optionalProperties))w(e,i),t.hasOwnProperty(i)&&(_(e,i),L(e,o,t[i]),$(e)),E(e);E(e)}if(r.additionalProperties!==!0)for(let i of Object.keys(t)){let o=r.properties&&i in r.properties,s=r.optionalProperties&&i in r.optionalProperties;!o&&!s&&i!==n&&(_(e,i),x(e),$(e))}}else r.properties!==void 0?w(e,"properties"):w(e,"optionalProperties"),x(e),E(e);else if(R.isValuesForm(r)){if(w(e,"values"),typeof t=="object"&&t!==null&&!Array.isArray(t))for(let[i,o]of Object.entries(t))_(e,i),L(e,r.values,o),$(e);else x(e);E(e)}else if(R.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?(w(e,"mapping"),w(e,i),L(e,r.mapping[i],t,r.discriminator),E(e),E(e)):(w(e,"mapping"),_(e,r.discriminator),x(e),$(e),E(e)):(w(e,"discriminator"),_(e,r.discriminator),x(e),$(e),E(e))}else w(e,"discriminator"),x(e),E(e);else w(e,"discriminator"),x(e),E(e)}}function N(e,r,t,n){(typeof r!="number"||!Number.isInteger(r)||r<t||r>n)&&x(e)}function _(e,r){e.instanceTokens.push(r)}function $(e){e.instanceTokens.pop()}function w(e,r){e.schemaTokens[e.schemaTokens.length-1].push(r)}function E(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 $e=j(M=>{"use strict";var _t=M&&M.__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]}),_e=M&&M.__exportStar||function(e,r){for(var t in e)t!=="default"&&!r.hasOwnProperty(t)&&_t(r,e,t)};Object.defineProperty(M,"__esModule",{value:!0});_e(ce(),M);_e(Re(),M)});var zt={};Qe(zt,{GenerationError:()=>ne,ResponseError:()=>D,builtinFontNames:()=>Bt,builtinLineHeights:()=>qe,builtinMargins:()=>Ve,builtinTextScales:()=>Je,builtinTools:()=>Nt,formatEntry:()=>Ge,parseEntry:()=>ze,register:()=>qt,remarkable:()=>Gt});var je=ge(xe());var Z,ft=new Uint8Array(16);function K(){if(!Z&&(Z=typeof crypto<"u"&&crypto.getRandomValues&&crypto.getRandomValues.bind(crypto),!Z))throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");return Z(ft)}var Ee=/^(?:[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 lt(e){return typeof e=="string"&&Ee.test(e)}var H=lt;var m=[];for(let e=0;e<256;++e)m.push((e+256).toString(16).slice(1));function J(e,r=0){return(m[e[r+0]]+m[e[r+1]]+m[e[r+2]]+m[e[r+3]]+"-"+m[e[r+4]]+m[e[r+5]]+"-"+m[e[r+6]]+m[e[r+7]]+"-"+m[e[r+8]]+m[e[r+9]]+"-"+m[e[r+10]]+m[e[r+11]]+m[e[r+12]]+m[e[r+13]]+m[e[r+14]]+m[e[r+15]]).toLowerCase()}function ut(e){if(!H(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 ae=ut;function dt(e){e=unescape(encodeURIComponent(e));let r=[];for(let t=0;t<e.length;++t)r.push(e.charCodeAt(t));return r}var ct="6ba7b810-9dad-11d1-80b4-00c04fd430c8",pt="6ba7b811-9dad-11d1-80b4-00c04fd430c8";function V(e,r,t){function n(i,o,s,a){var f;if(typeof i=="string"&&(i=dt(i)),typeof o=="string"&&(o=ae(o)),((f=o)===null||f===void 0?void 0:f.length)!==16)throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");let l=new Uint8Array(16+i.length);if(l.set(o),l.set(i,o.length),l=t(l),l[6]=l[6]&15|r,l[8]=l[8]&63|128,s){a=a||0;for(let u=0;u<16;++u)s[a+u]=l[u];return s}return J(l)}try{n.name=e}catch{}return n.DNS=ct,n.URL=pt,n}function mt(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 yt(ht(gt(e),e.length*8))}function yt(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,s=parseInt(n.charAt(o>>>4&15)+n.charAt(o&15),16);r.push(s)}return r}function ve(e){return(e+64>>>9<<4)+14+1}function ht(e,r){e[r>>5]|=128<<r%32,e[ve(r)-1]=r;let t=1732584193,n=-271733879,i=-1732584194,o=271733878;for(let s=0;s<e.length;s+=16){let a=t,f=n,l=i,u=o;t=y(t,n,i,o,e[s],7,-680876936),o=y(o,t,n,i,e[s+1],12,-389564586),i=y(i,o,t,n,e[s+2],17,606105819),n=y(n,i,o,t,e[s+3],22,-1044525330),t=y(t,n,i,o,e[s+4],7,-176418897),o=y(o,t,n,i,e[s+5],12,1200080426),i=y(i,o,t,n,e[s+6],17,-1473231341),n=y(n,i,o,t,e[s+7],22,-45705983),t=y(t,n,i,o,e[s+8],7,1770035416),o=y(o,t,n,i,e[s+9],12,-1958414417),i=y(i,o,t,n,e[s+10],17,-42063),n=y(n,i,o,t,e[s+11],22,-1990404162),t=y(t,n,i,o,e[s+12],7,1804603682),o=y(o,t,n,i,e[s+13],12,-40341101),i=y(i,o,t,n,e[s+14],17,-1502002290),n=y(n,i,o,t,e[s+15],22,1236535329),t=h(t,n,i,o,e[s+1],5,-165796510),o=h(o,t,n,i,e[s+6],9,-1069501632),i=h(i,o,t,n,e[s+11],14,643717713),n=h(n,i,o,t,e[s],20,-373897302),t=h(t,n,i,o,e[s+5],5,-701558691),o=h(o,t,n,i,e[s+10],9,38016083),i=h(i,o,t,n,e[s+15],14,-660478335),n=h(n,i,o,t,e[s+4],20,-405537848),t=h(t,n,i,o,e[s+9],5,568446438),o=h(o,t,n,i,e[s+14],9,-1019803690),i=h(i,o,t,n,e[s+3],14,-187363961),n=h(n,i,o,t,e[s+8],20,1163531501),t=h(t,n,i,o,e[s+13],5,-1444681467),o=h(o,t,n,i,e[s+2],9,-51403784),i=h(i,o,t,n,e[s+7],14,1735328473),n=h(n,i,o,t,e[s+12],20,-1926607734),t=g(t,n,i,o,e[s+5],4,-378558),o=g(o,t,n,i,e[s+8],11,-2022574463),i=g(i,o,t,n,e[s+11],16,1839030562),n=g(n,i,o,t,e[s+14],23,-35309556),t=g(t,n,i,o,e[s+1],4,-1530992060),o=g(o,t,n,i,e[s+4],11,1272893353),i=g(i,o,t,n,e[s+7],16,-155497632),n=g(n,i,o,t,e[s+10],23,-1094730640),t=g(t,n,i,o,e[s+13],4,681279174),o=g(o,t,n,i,e[s],11,-358537222),i=g(i,o,t,n,e[s+3],16,-722521979),n=g(n,i,o,t,e[s+6],23,76029189),t=g(t,n,i,o,e[s+9],4,-640364487),o=g(o,t,n,i,e[s+12],11,-421815835),i=g(i,o,t,n,e[s+15],16,530742520),n=g(n,i,o,t,e[s+2],23,-995338651),t=b(t,n,i,o,e[s],6,-198630844),o=b(o,t,n,i,e[s+7],10,1126891415),i=b(i,o,t,n,e[s+14],15,-1416354905),n=b(n,i,o,t,e[s+5],21,-57434055),t=b(t,n,i,o,e[s+12],6,1700485571),o=b(o,t,n,i,e[s+3],10,-1894986606),i=b(i,o,t,n,e[s+10],15,-1051523),n=b(n,i,o,t,e[s+1],21,-2054922799),t=b(t,n,i,o,e[s+8],6,1873313359),o=b(o,t,n,i,e[s+15],10,-30611744),i=b(i,o,t,n,e[s+6],15,-1560198380),n=b(n,i,o,t,e[s+13],21,1309151649),t=b(t,n,i,o,e[s+4],6,-145523070),o=b(o,t,n,i,e[s+11],10,-1120210379),i=b(i,o,t,n,e[s+2],15,718787259),n=b(n,i,o,t,e[s+9],21,-343485551),t=S(t,a),n=S(n,f),i=S(i,l),o=S(o,u)}return[t,n,i,o]}function gt(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 S(e,r){let t=(e&65535)+(r&65535);return(e>>16)+(r>>16)+(t>>16)<<16|t&65535}function bt(e,r){return e<<r|e>>>32-r}function X(e,r,t,n,i,o){return S(bt(S(S(r,e),S(n,o)),i),t)}function y(e,r,t,n,i,o,s){return X(r&t|~r&n,e,r,i,o,s)}function h(e,r,t,n,i,o,s){return X(r&n|t&~n,e,r,i,o,s)}function g(e,r,t,n,i,o,s){return X(r^t^n,e,r,i,o,s)}function b(e,r,t,n,i,o,s){return X(t^(r|~n),e,r,i,o,s)}var Pe=mt;var pr=V("v3",48,Pe);var wt=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),fe={randomUUID:wt};function xt(e,r,t){if(fe.randomUUID&&!r&&!e)return fe.randomUUID();e=e||{};let n=e.random||(e.rng||K)();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 J(n)}var q=xt;function Et(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 le(e,r){return e<<r|e>>>32-r}function vt(e){let r=[1518500249,1859775393,2400959708,3395469782],t=[1732584193,4023233417,2562383102,271733878,3285377520];if(typeof e=="string"){let s=unescape(encodeURIComponent(e));e=[];for(let a=0;a<s.length;++a)e.push(s.charCodeAt(a))}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 s=0;s<i;++s){let a=new Uint32Array(16);for(let f=0;f<16;++f)a[f]=e[s*64+f*4]<<24|e[s*64+f*4+1]<<16|e[s*64+f*4+2]<<8|e[s*64+f*4+3];o[s]=a}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 s=0;s<i;++s){let a=new Uint32Array(80);for(let c=0;c<16;++c)a[c]=o[s][c];for(let c=16;c<80;++c)a[c]=le(a[c-3]^a[c-8]^a[c-14]^a[c-16],1);let f=t[0],l=t[1],u=t[2],p=t[3],P=t[4];for(let c=0;c<80;++c){let T=Math.floor(c/20),B=le(f,5)+Et(T,l,u,p)+P+r[T]+a[c]>>>0;P=p,p=u,u=le(l,30)>>>0,l=f,f=B}t[0]=t[0]+f>>>0,t[1]=t[1]+l>>>0,t[2]=t[2]+u>>>0,t[3]=t[3]+p>>>0,t[4]=t[4]+P>>>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 Te=vt;var Pr=V("v5",80,Te);function ue(e){return[...new Uint8Array(e)].map(r=>r.toString(16).padStart(2,"0")).join("")}function Ae(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 Le=ge($e());function G(e,r){if((0,Le.validate)(e,r).length)throw new Error(`couldn't validate schema: ${JSON.stringify(r)} didn't match schema ${JSON.stringify(e)}`)}var De="3",He="https://webapp-prod.cloud.remarkable.engineering",$t="https://internal.cloud.remarkable.com",Ne="x-goog-generation",Lt="x-goog-if-generation-match",Dt="x-goog-content-length-range",Nt=["Ballpoint","Ballpointv2","Brush","Calligraphy","ClearPage","EraseSection","Eraser","Fineliner","Finelinerv2","Highlighter","Highlighterv2","Marker","Markerv2","Paintbrush","Paintbrushv2","Pencilv2","SharpPencil","SharpPencilv2","SolidPen","ZoomTool"],Bt=["Maison Neue","EB Garamond","Noto Sans","Noto Serif","Noto Mono","Noto Sans UI"],Je={xs:.7,sm:.8,md:1,lg:1.2,xl:1.5,xx:2},Ve={sm:50,md:125,rr:180,lg:200},qe={df:-1,md:100,lg:150,xl:200},jt={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"}}},te={visibleName:{type:"string"},lastModified:{type:"string"}},re={version:{type:"int32"},pinned:{type:"boolean"},synced:{type:"boolean"},modified:{type:"boolean"},deleted:{type:"boolean"},metadatamodified:{type:"boolean"},parent:{type:"string"}},Jt={discriminator:"type",mapping:{CollectionType:{properties:te,optionalProperties:re},DocumentType:{properties:te,optionalProperties:{...re,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},Be={id:{type:"string"},hash:{type:"string"}},Vt={discriminator:"type",mapping:{CollectionType:{properties:{...te,...Be},optionalProperties:re},DocumentType:{properties:{...te,...Be,fileType:{enum:["notebook","epub","pdf",""]}},optionalProperties:{...re,lastOpened:{type:"string"},lastOpenedPage:{type:"int32"}}}}},D=class extends Error{constructor(t,n,i){super(i);this.status=t,this.statusText=n}},ne=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 qt(e,{deviceDesc:r="browser-chrome",uuid:t=q(),authHost:n=He,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 D(o.status,o.statusText,"couldn't register api")}function Ge({hash:e,type:r,documentId:t,subfiles:n,size:i}){return`${e}:${r}:${t}:${n}:${i}
2
- `}function ze(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{#f;#s;#a;#t;#r;#e=null;constructor(r,t,n,i,o){this.#f=r,this.#s=t,this.#r=n,this.#a=i,this.#t=o}async#o(r,{body:t,method:n="POST",headers:i={}}){let o=await this.#s(r,{method:n,headers:{Authorization:`Bearer ${this.#f}`,...i},body:t});if(o.ok)return o;{let s=await o.text();throw new D(o.status,o.statusText,`failed reMarkable request: ${s}`)}}async#n({url:r,method:t,maxuploadsize_bytes:n},i,o={}){let s=n?{...o,[Dt]:`0,${n}`}:o,a=await this.#s(r,{method:t,body:i,headers:s});if(a.ok)return a;{let f=await a.text();throw new D(a.status,a.statusText,f)}}async#i(r,t,n){let i=t===void 0?"downloads":"uploads",o=n?`{ "http_method": "PUT", "relative_path": "${r}", "root_schema": "${n}", "generation": ${t} }`:JSON.stringify({http_method:"GET",relative_path:r}),a=await(await this.#o(`${this.#t}/sync/v2/signed-urls/${i}`,{body:o})).text(),f=JSON.parse(a);return G(Ht,f),f}async getRootHash({cache:r=!0}={}){if(r)for(;this.#e;)try{let[o,s]=await this.#e;return[o,s]}catch{}let t=(async()=>{try{let o=await this.#i("root"),s=await this.#n(o),a=s.headers.get(Ne);if(a)return[await s.text(),BigInt(a)];throw new Error("no generation header in root hash")}catch(o){throw this.#e=null,o}})();this.#e=t;let[n,i]=await t;return[n,i]}async putRootHash(r,t){let n=await this.#i("root",t,r),i;try{i=await this.#n(n,r,{[Lt]:`${t}`})}catch(a){throw a instanceof D&&a.status===412?(this.#e=null,new ne):a}let o=i.headers.get(Ne);if(!o)throw new Error("no generation header in root hash");let s=BigInt(o);return this.#e=Promise.resolve([r,s]),s}async getBuffer(r){let t=await this.#i(r);return await(await this.#n(t)).arrayBuffer()}async getText(r){let t=await this.#r?.get(r);if(t)return t;{let n=await this.#i(r),o=await(await this.#n(n)).text();return await this.#r?.set(r,o),o}}async getMetadata(r){let t=await this.getText(r),n=JSON.parse(t);return G(Jt,n),n}async getEntries(r){let t=await this.getText(r),[n,...i]=t.slice(0,-1).split(`
3
- `);if(n!==De)throw new Error(`got unexpected schema version: ${n}`);return i.map(ze)}async#l(r,t){let n=await this.#i(r,null);await this.#n(n,t)}async putEntries(r,t){let n=new TextEncoder;t.sort((u,p)=>u.documentId.localeCompare(p.documentId));let i=ke(t.map(u=>Ae(u.hash))),o=await this.#a.digest("SHA-256",i),s=ue(o),a=t.map(Ge).join(""),f=`${De}
4
- ${a}`,l=n.encode(f);return await this.#l(s,l),await this.#r?.set(s,f),{hash:s,type:"80000000",documentId:r,subfiles:t.length,size:0n}}async putBuffer(r,t){let n=await this.#a.digest("SHA-256",t),i=ue(n);return await this.#l(i,t),{hash:i,type:"0",documentId:r,subfiles:0,size:BigInt(t.length)}}async putText(r,t){let n=new TextEncoder,i=await this.putBuffer(r,n.encode(t));return await this.#r?.set(i.hash,t),i}async putMetadata(r,t){return await this.putText(`${r}.metadata`,JSON.stringify(t))}async putCollection(r,t=""){let n=q(),i=`${new Date().valueOf()}`,o=[],s={type:"CollectionType",visibleName:r,version:0,parent:t,synced:!0,lastModified:i};o.push(this.putMetadata(n,s)),o.push(this.putText(`${n}.content`,"{}"));let a=await Promise.all(o);return await this.putEntries(n,a)}async#u(r,t,n,i,o){if(o.fileType!==n)throw new Error(`internal error: fileTypes don't match: ${n}, ${o.fileType}`);let s=q(),a=`${new Date().valueOf()}`,f=[];f.push(this.putBuffer(`${s}.${n}`,t));let l={type:"DocumentType",visibleName:r,version:0,parent:i,synced:!0,lastModified:a};f.push(this.putMetadata(s,l)),f.push(this.putText(`${s}.content`,JSON.stringify(o)));let u=await Promise.all(f);return await this.putEntries(s,u)}async putEpub(r,t,{parent:n="",margins:i=125,orientation:o,textAlignment:s,textScale:a=1,lineHeight:f=-1,fontName:l="",cover:u="visited",lastTool:p}={}){let P={dummyDocument:!1,extraMetadata:{LastTool:p},fileType:"epub",pageCount:0,lastOpenedPage:0,lineHeight:typeof f=="string"?qe[f]:f,margins:typeof i=="string"?Ve[i]:i,textScale:typeof a=="string"?Je[a]:a,pages:[],coverPageNumber:u==="first"?0:-1,formatVersion:1,orientation:o,textAlignment:s,fontName:l};return await this.#u(r,t,"epub",n,P)}async putPdf(r,t,{parent:n="",orientation:i,cover:o="first",lastTool:s}={}){let a={dummyDocument:!1,extraMetadata:{LastTool:s},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.#u(r,t,"pdf",n,a)}async syncComplete(r){let t=`{ "generation": ${r} }`;await this.#o(`${this.#t}/sync/v2/sync-complete`,{body:t})}async#d(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,t={}){let{cache:n=!0,sync:i=!0}=typeof t=="boolean"?{cache:!1,sync:t}:t,[o,s]=await this.getRootHash({cache:n}),a=await this.getEntries(o);return a.push(r),await this.#d(s,a,i)}async move(r,t,n={}){let{cache:i=!0,sync:o=!0}=typeof n=="boolean"?{cache:!1,sync:n}:n,[s,a]=await this.getRootHash({cache:i}),f=await this.getEntries(s);if(!(!t||t==="trash")){let k=f.find(oe=>oe.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 v=await this.getEntries(k.hash),[z]=v.filter(oe=>oe.documentId===`${t}.metadata`);if(!z)throw new Error(`destination id didn't have metadata: ${t}`);if((await this.getMetadata(z.hash)).type!=="CollectionType")throw new Error(`destination id wasn't a collection: ${t}`)}let l=f.findIndex(k=>k.documentId===r);if(l===-1)throw new Error(`document not found: ${r}`);let[u]=f.splice(l,1);if(u.type!=="80000000")throw new Error(`document was a raw file: ${r}`);let p=await this.getEntries(u.hash),P=p.findIndex(k=>k.documentId===`${r}.metadata`);if(P===-1)throw new Error(`document didn't have metadata: ${r}`);let[c]=p.splice(P,1),T=await this.getMetadata(c.hash);T.parent=t;let B=await this.putMetadata(r,T);p.push(B);let ie=await this.putEntries(r,p);return f.push(ie),await this.#d(a,f,o)}async getEntriesMetadata(){let t=await(await this.#o(`${this.#t}/doc/v2/files`,{method:"GET",headers:{"rm-source":"RoR-Browser"}})).text(),n=JSON.parse(t);return G({elements:Vt},n),n}async#c(r,t,n){let o=new TextEncoder().encode(JSON.stringify({file_name:r})),a=await(await this.#o(`${this.#t}/doc/v2/files`,{body:t,headers:{"content-type":n,"rm-meta":(0,je.fromByteArray)(o),"rm-source":"RoR-Browser"}})).text(),f=JSON.parse(a);return G(jt,f),f}async uploadEpub(r,t){return await this.#c(r,t,"application/epub+zip")}async uploadPdf(r,t){return await this.#c(r,t,"application/pdf")}};async function Gt(e,{fetch:r=globalThis.fetch,cache:t,subtle:n=globalThis.crypto?.subtle,authHost:i=He,syncHost:o=$t}={}){let s=await r(`${i}/token/json/2/user/new`,{method:"POST",headers:{Authorization:`Bearer ${e}`}});if(!s.ok)throw new Error(`couldn't fetch auth token: ${s.statusText}`);let a=await s.text();return new me(a,r,t,n,o)}return et(zt);})();
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);})();
package/dist/index.d.ts CHANGED
@@ -188,8 +188,6 @@ export interface Content {
188
188
  /** text alignment */
189
189
  textAlignment?: TextAlignment;
190
190
  }
191
- /** anything that can be awaited */
192
- export type Awaitable<T> = T | PromiseLike<T>;
193
191
  /** stripped down version of RequestInit */
194
192
  export interface RequestInitLike {
195
193
  /** request method */
@@ -215,20 +213,20 @@ export interface ResponseLike {
215
213
  /** headers in response */
216
214
  headers: HeadersLike;
217
215
  /** get response body as text */
218
- text(): Awaitable<string>;
216
+ text(): Promise<string>;
219
217
  /** get response body as an array buffer */
220
- arrayBuffer(): Awaitable<ArrayBuffer>;
218
+ arrayBuffer(): Promise<ArrayBuffer>;
221
219
  }
222
220
  /** stripped down version of fetch */
223
221
  export interface FetchLike {
224
- (url: string, options?: RequestInitLike | undefined): Awaitable<ResponseLike>;
222
+ (url: string, options?: RequestInitLike | undefined): Promise<ResponseLike>;
225
223
  }
226
224
  /** async storage, map like */
227
225
  export interface CacheLike {
228
226
  /** get value for key or undefined if missing */
229
- get(key: string): Awaitable<string | undefined>;
227
+ get(key: string): Promise<string | undefined>;
230
228
  /** set value for key */
231
- set(key: string, value: string): Awaitable<void>;
229
+ set(key: string, value: string): Promise<void>;
232
230
  }
233
231
  /** stripped down version of subtle crypto */
234
232
  export interface SubtleCryptoLike {
@@ -385,28 +383,41 @@ export interface RemarkableApi {
385
383
  /**
386
384
  * get text content associated with hash
387
385
  *
388
- * This call uses the cache if provided since contents of a specific hash
389
- * should never change. This isn't atomic so calling with the same hash in
390
- * quick succession could result in two requests being fired instead of the
391
- * second waiting for the first.
392
- *
393
386
  * @param hash - the hash to get text data from
394
387
  */
395
388
  getText(hash: string): Promise<string>;
389
+ /**
390
+ * get a json object associated with a hash
391
+ *
392
+ * This is identical to `getText(hash).then(JSON.parse)` and is only provided
393
+ * for consistency with {@link RemarkableApi.putJson | `putJson`}.
394
+ */
395
+ getJson(hash: string): Promise<unknown>;
396
396
  /** get metadata from hash */
397
397
  getMetadata(hash: string): Promise<Metadata>;
398
- /** get entries from a collection hash */
399
- getEntries(hash: string): Promise<Entry[]>;
398
+ /**
399
+ * get entries from a collection hash
400
+ *
401
+ * If omitted, this will use `getRootHash()`.
402
+ */
403
+ getEntries(hash?: string): Promise<Entry[]>;
400
404
  /** put a reference to a set of entries into the cloud */
401
405
  putEntries(documentId: string, entries: Entry[]): Promise<CollectionEntry>;
402
406
  /** put a raw buffer in the cloud */
403
- putBuffer(documentId: string, buffer: Uint8Array): Promise<FileEntry>;
407
+ putBuffer(documentId: string, buffer: ArrayBuffer): Promise<FileEntry>;
404
408
  /**
405
- * put a raw text in the cloud
409
+ * put a raw text in the cloud encoded as utf-8
406
410
  *
407
- * This is similar to `putBuffer` but will also cache the upload.
411
+ * this is no different than using `putBuffer(..., new TextEncoder().encode(contents))`
408
412
  */
409
413
  putText(documentId: string, contents: string): Promise<FileEntry>;
414
+ /**
415
+ * put json into the cloud
416
+ *
417
+ * This uses a stable (sorted keys) json serilization to preserve consistent
418
+ * hashes.
419
+ */
420
+ putJson(documentId: string, contents: object): Promise<FileEntry>;
410
421
  /**
411
422
  * put metadata into the cloud
412
423
  *
@@ -446,7 +457,7 @@ export interface RemarkableApi {
446
457
  * @param buffer - the epub contents
447
458
  * @param opts - extra options you can specify at upload
448
459
  */
449
- putEpub(visibleName: string, buffer: Uint8Array, opts?: PutEpubOptions): Promise<CollectionEntry>;
460
+ putEpub(visibleName: string, buffer: ArrayBuffer, opts?: PutEpubOptions): Promise<CollectionEntry>;
450
461
  /**
451
462
  * upload a pdf
452
463
  *
@@ -469,7 +480,7 @@ export interface RemarkableApi {
469
480
  * @param buffer - the pdf contents
470
481
  * @param opts - extra options you can specify at upload
471
482
  */
472
- putPdf(visibleName: string, buffer: Uint8Array, opts?: PutPdfOptions): Promise<CollectionEntry>;
483
+ putPdf(visibleName: string, buffer: ArrayBuffer, opts?: PutPdfOptions): Promise<CollectionEntry>;
473
484
  /**
474
485
  * indicate that a sync is complete and push updates to other devices
475
486
  *
@@ -496,6 +507,10 @@ export interface RemarkableApi {
496
507
  * 2. It includes no handling of concurrent modification or other networking
497
508
  * errors, requiring repeat network requests if anything fails.
498
509
  *
510
+ * However, with recent changes in the way this library caches results, it
511
+ * won't be terribly inefficient to just do multiple retries of create after
512
+ * uploading the file itself.
513
+ *
499
514
  * @example
500
515
  * ```ts
501
516
  * const entry = await api.putEpub(...);
@@ -509,13 +524,6 @@ export interface RemarkableApi {
509
524
  * changed
510
525
  */
511
526
  create(entry: CollectionEntry, options?: CreateMoveOptions): Promise<boolean>;
512
- /**
513
- * deprecated variant without the ability to specify caching behavior
514
- *
515
- * @deprecated in favor of the options syntax: replace `create(entry, sync)`
516
- * with `create(entry, { cache: false, sync: sync })`
517
- */
518
- create(entry: CollectionEntry, sync: boolean): Promise<boolean>;
519
527
  /**
520
528
  * high level api to move a document / collection
521
529
  *
@@ -531,6 +539,9 @@ export interface RemarkableApi {
531
539
  * 2. It includes no handling of concurrent modification or other networking
532
540
  * errors, requiring repeat network requests if anything fails.
533
541
  *
542
+ * However, with changes to the way this caches results, it won't be terribly
543
+ * inefficient to just retry calling `move` if there's a failure.
544
+ *
534
545
  * @example
535
546
  * ```ts
536
547
  * const [root] = await api.getRootHash();
@@ -549,14 +560,6 @@ export interface RemarkableApi {
549
560
  * changed
550
561
  */
551
562
  move(documentId: string, dest: string, opts?: CreateMoveOptions): Promise<boolean>;
552
- /**
553
- * deprecated variant without the ability to specify caching behavior
554
- *
555
- * @deprecated in favor of the options syntax: replace
556
- * `move(docid, dest, sync)` with
557
- * `move(docid, dest, { cache: false, sync: sync })`
558
- */
559
- move(documentId: string, dest: string, sync: boolean): Promise<boolean>;
560
563
  /**
561
564
  * get metadata on all entries
562
565
  *
@@ -579,7 +582,7 @@ export interface RemarkableApi {
579
582
  * @param visibleName - the name to show for the uploaded epub
580
583
  * @param buffer - the epub contents
581
584
  */
582
- uploadEpub(visibleName: string, buffer: Uint8Array): Promise<UploadEntry>;
585
+ uploadEpub(visibleName: string, buffer: ArrayBuffer): Promise<UploadEntry>;
583
586
  /**
584
587
  * upload a pdf
585
588
  *
@@ -599,7 +602,14 @@ export interface RemarkableApi {
599
602
  * @param buffer - the epub contents
600
603
  * @experimental
601
604
  */
602
- uploadPdf(visibleName: string, buffer: Uint8Array): Promise<UploadEntry>;
605
+ uploadPdf(visibleName: string, buffer: ArrayBuffer): Promise<UploadEntry>;
606
+ /**
607
+ * get the current state of the cache for persisting
608
+ *
609
+ * This won't include items that weren't cached because they were too big,
610
+ * meaning it won't prevent duplicate puts of large content across sessions.
611
+ */
612
+ getCache(): Promise<Map<string, ArrayBuffer>>;
603
613
  }
604
614
  /** format an entry */
605
615
  export declare function formatEntry({ hash, type, documentId, subfiles, size, }: Entry): string;
@@ -616,20 +626,10 @@ export interface RemarkableOptions {
616
626
  *
617
627
  * In node you can either use `"node-fetch"`, or `node --experimental-fetch`
618
628
  * for node 17.5 or higher.
619
- */
620
- fetch?: FetchLike;
621
- /**
622
- * an optional cache for text requests
623
629
  *
624
- * If you're using the api to sync between a local copy and the cloud, you'll
625
- * want to keep a cache so that as long as a file's hash doesn't change you
626
- * don't need to request another copy.
627
- *
628
- * @remarks currently there are no mechanisms that actually clear the cache,
629
- * so be warned if the cache doesn't have an auto clearning mechansim that
630
- * some old files may stay around for quite a while
630
+ * @defaultValue globalThis.fetch
631
631
  */
632
- cache?: CacheLike;
632
+ fetch?: FetchLike;
633
633
  /**
634
634
  * a subtle-crypto-like object
635
635
  *
@@ -637,14 +637,43 @@ export interface RemarkableOptions {
637
637
  * default value. In node try
638
638
  * `import { webcrypto } from "crypto"; global.crypto = webcrypto` or pass in
639
639
  * `webcrypto.subtle`.
640
+ *
641
+ * @defaultValue globalThis.crypto.subtle
640
642
  */
641
643
  subtle?: SubtleCryptoLike;
642
- /** the url for making authorization requests */
644
+ /**
645
+ * the url for making authorization requests
646
+ *
647
+ * @defaultValue "https://webapp-prod.cloud.remarkable.engineering"
648
+ */
643
649
  authHost?: string;
644
- /** the url for making raw document requests */
645
- docHost?: string;
646
- /** the url for making synchronization requests */
650
+ /**
651
+ * the url for making synchronization requests
652
+ *
653
+ * @defaultValue "https://internal.cloud.remarkable.com"
654
+ */
647
655
  syncHost?: string;
656
+ /**
657
+ * the maximum size in bytes to cache the value of a stored object
658
+ *
659
+ * Since the remarkableApi is based around hashes, the value of a hash should
660
+ * never change (barring collisions in ASH256). Any known hash value that's
661
+ * less than this amount will be cached locally to prevent future network
662
+ * requests. In addition, all successful puts and gets will be cached to
663
+ * prevent duplicate puts in the future.
664
+ *
665
+ * To save memory and disable fetch caching, set to 0.
666
+ *
667
+ * @defaultValue 1 MiB
668
+ */
669
+ cacheLimitBytes?: number;
670
+ /**
671
+ * a set of values to use to initialize the cache
672
+ *
673
+ * If this is inaccurate, then you could encounter errors with other methods.
674
+ * Often this will come from {@link RemarkableApi.getCache | `getCache`}.
675
+ */
676
+ initCache?: Iterable<readonly [string, ArrayBuffer]>;
648
677
  }
649
678
  /**
650
679
  * create an instance of the api
@@ -656,4 +685,4 @@ export interface RemarkableOptions {
656
685
  * registered. Create one with {@link register}.
657
686
  * @returns an api instance
658
687
  */
659
- export declare function remarkable(deviceToken: string, { fetch, cache, subtle, authHost, syncHost, }?: RemarkableOptions): Promise<RemarkableApi>;
688
+ export declare function remarkable(deviceToken: string, { fetch, subtle, authHost, syncHost, cacheLimitBytes, initCache, }?: RemarkableOptions): Promise<RemarkableApi>;
package/dist/index.js CHANGED
@@ -15,9 +15,8 @@
15
15
  * const token = await register(code)
16
16
  * // persist token
17
17
  * const api = await remarkable(token);
18
- * const [root] = await api.getRootHash();
19
- * const fileEntries = await api.getEntries(root);
20
- * for (const entry of fileEntries) {
18
+ * const rootEntries = await api.getEntries();
19
+ * for (const entry of rootEntries) {
21
20
  * const children = await api.getEntries(entry.hash);
22
21
  * for (const { hash, documentId } of children) {
23
22
  * if (documentId.endsWith(".metadata")) {
@@ -42,6 +41,7 @@
42
41
  * @packageDocumentation
43
42
  */
44
43
  import { fromByteArray } from "base64-js";
44
+ import stringify from "json-stable-stringify";
45
45
  import { v4 as uuid4 } from "uuid";
46
46
  import { concatBuffers, fromHex, toHex } from "./utils";
47
47
  import { validate } from "./validate";
@@ -298,14 +298,19 @@ class Remarkable {
298
298
  #subtle;
299
299
  #syncHost;
300
300
  // caches
301
- #cache;
301
+ #cacheLimitBytes;
302
+ #cache = new Map();
302
303
  #rootCache = null;
303
- constructor(userToken, fetch, cache, subtle, syncHost) {
304
+ constructor(userToken, fetch, subtle, syncHost, cacheLimitBytes, initCache) {
304
305
  this.#userToken = userToken;
305
306
  this.#fetch = fetch;
306
- this.#cache = cache;
307
307
  this.#subtle = subtle;
308
308
  this.#syncHost = syncHost;
309
+ this.#cacheLimitBytes = cacheLimitBytes;
310
+ // set cache
311
+ for (const [hash, val] of initCache) {
312
+ this.#cache.set(hash, Promise.resolve(val));
313
+ }
309
314
  }
310
315
  /** make an authorized request to remarkable */
311
316
  async #authedFetch(url, { body, method = "POST", headers = {}, }) {
@@ -350,7 +355,7 @@ class Remarkable {
350
355
  async #getUrl(relativePath, gen, rootHash) {
351
356
  const key = gen === undefined ? "downloads" : "uploads";
352
357
  // NOTE this is done manually to serialize the bigints appropriately
353
- const body = rootHash
358
+ const body = rootHash && gen !== null && gen !== undefined
354
359
  ? `{ "http_method": "PUT", "relative_path": "${relativePath}", "root_schema": "${rootHash}", "generation": ${gen} }`
355
360
  : JSON.stringify({ http_method: "GET", relative_path: relativePath });
356
361
  const resp = await this.#authedFetch(`${this.#syncHost}/sync/v2/signed-urls/${key}`, { body });
@@ -423,43 +428,77 @@ class Remarkable {
423
428
  this.#rootCache = Promise.resolve([hash, gen]);
424
429
  return gen;
425
430
  }
431
+ /**
432
+ * get content associated with hash
433
+ */
434
+ async #getHash(hash) {
435
+ let cached = this.#cache.get(hash);
436
+ while (cached) {
437
+ try {
438
+ const val = await cached;
439
+ if (val) {
440
+ return val;
441
+ }
442
+ else {
443
+ cached = undefined; // break
444
+ }
445
+ }
446
+ catch {
447
+ // try again if promise rejected
448
+ cached = this.#cache.get(hash);
449
+ }
450
+ }
451
+ const prom = (async () => {
452
+ const signed = await this.#getUrl(hash);
453
+ const resp = await this.#signedFetch(signed);
454
+ return await resp.arrayBuffer();
455
+ })();
456
+ // set cache with appropriate promise that cleans up on rejection
457
+ this.#cache.set(hash, prom.then((buff) => (buff.byteLength < this.#cacheLimitBytes ? buff : null), (ex) => {
458
+ this.#cache.delete(hash);
459
+ throw ex;
460
+ }));
461
+ return await prom;
462
+ }
426
463
  /**
427
464
  * get text content associated with hash
428
465
  */
429
466
  async getBuffer(hash) {
430
- const signed = await this.#getUrl(hash);
431
- const resp = await this.#signedFetch(signed);
432
- return await resp.arrayBuffer();
467
+ const buff = await this.#getHash(hash);
468
+ // copy if it is long enough to be cached to preven mutations
469
+ return buff.byteLength < this.#cacheLimitBytes ? buff.slice(0) : buff;
433
470
  }
434
471
  /**
435
472
  * get text content associated with hash
436
473
  */
437
474
  async getText(hash) {
438
- const cached = await this.#cache?.get(hash);
439
- if (cached) {
440
- return cached;
441
- }
442
- else {
443
- const signed = await this.#getUrl(hash);
444
- const resp = await this.#signedFetch(signed);
445
- const raw = await resp.text();
446
- await this.#cache?.set(hash, raw);
447
- return raw;
448
- }
475
+ const buff = await this.#getHash(hash);
476
+ const decoder = new TextDecoder();
477
+ return decoder.decode(buff);
478
+ }
479
+ /**
480
+ * get json content associated with hash
481
+ */
482
+ async getJson(hash) {
483
+ const str = await this.getText(hash);
484
+ return JSON.parse(str);
449
485
  }
450
486
  /**
451
487
  * get metadata from hash
452
488
  */
453
489
  async getMetadata(hash) {
454
- const raw = await this.getText(hash);
455
- const parsed = JSON.parse(raw);
456
- validate(metadataSchema, parsed);
457
- return parsed;
490
+ const raw = await this.getJson(hash);
491
+ validate(metadataSchema, raw);
492
+ return raw;
458
493
  }
459
494
  /**
460
495
  * get entries from a collection hash
461
496
  */
462
497
  async getEntries(hash) {
498
+ if (hash === undefined) {
499
+ const [newHash] = await this.getRootHash({ cache: true });
500
+ hash = newHash;
501
+ }
463
502
  const raw = await this.getText(hash);
464
503
  // slice for trailing new line
465
504
  const [schema, ...lines] = raw.slice(0, -1).split("\n");
@@ -470,8 +509,31 @@ class Remarkable {
470
509
  }
471
510
  /** upload data to hash */
472
511
  async #putHash(hash, body) {
473
- const signed = await this.#getUrl(hash, null);
474
- await this.#signedFetch(signed, body);
512
+ // try cached version
513
+ const cached = this.#cache.get(hash);
514
+ if (cached) {
515
+ try {
516
+ await cached;
517
+ return;
518
+ }
519
+ catch {
520
+ // noop
521
+ }
522
+ }
523
+ // if missing or rejected then put for real
524
+ const prom = (async () => {
525
+ try {
526
+ const signed = await this.#getUrl(hash, null);
527
+ await this.#signedFetch(signed, body);
528
+ return body.byteLength < this.#cacheLimitBytes ? body : null;
529
+ }
530
+ catch (ex) {
531
+ this.#cache.delete(hash);
532
+ throw ex;
533
+ }
534
+ })();
535
+ this.#cache.set(hash, prom);
536
+ await prom;
475
537
  }
476
538
  /** put a reference to a set of entries into the cloud */
477
539
  async putEntries(documentId, entries) {
@@ -485,7 +547,6 @@ class Remarkable {
485
547
  const contents = `${SCHEMA_VERSION}\n${entryContents}`;
486
548
  const buffer = enc.encode(contents);
487
549
  await this.#putHash(hash, buffer);
488
- await this.#cache?.set(hash, contents);
489
550
  return {
490
551
  hash,
491
552
  type: "80000000",
@@ -504,19 +565,21 @@ class Remarkable {
504
565
  type: "0",
505
566
  documentId,
506
567
  subfiles: 0,
507
- size: BigInt(buffer.length),
568
+ size: BigInt(buffer.byteLength),
508
569
  };
509
570
  }
510
- /** put cached text in the cloud */
571
+ /** put text in the cloud */
511
572
  async putText(documentId, contents) {
512
573
  const enc = new TextEncoder();
513
- const entry = await this.putBuffer(documentId, enc.encode(contents));
514
- await this.#cache?.set(entry.hash, contents);
515
- return entry;
574
+ return await this.putBuffer(documentId, enc.encode(contents));
575
+ }
576
+ /** put json in the cloud */
577
+ async putJson(documentId, contents) {
578
+ return await this.putText(documentId, stringify(contents));
516
579
  }
517
580
  /** put metadata into the cloud */
518
581
  async putMetadata(documentId, metadata) {
519
- return await this.putText(`${documentId}.metadata`, JSON.stringify(metadata));
582
+ return await this.putJson(`${documentId}.metadata`, metadata);
520
583
  }
521
584
  /** put a new collection (folder) */
522
585
  async putCollection(visibleName, parent = "") {
@@ -639,16 +702,14 @@ class Remarkable {
639
702
  }
640
703
  }
641
704
  /** high level api to create an entry */
642
- async create(entry, opts = {}) {
643
- const { cache = true, sync = true } = typeof opts === "boolean" ? { cache: false, sync: opts } : opts;
705
+ async create(entry, { cache = true, sync = true } = {}) {
644
706
  const [root, gen] = await this.getRootHash({ cache });
645
707
  const rootEntries = await this.getEntries(root);
646
708
  rootEntries.push(entry);
647
709
  return await this.#tryPutRootEntries(gen, rootEntries, sync);
648
710
  }
649
711
  /** high level api to move a document / collection */
650
- async move(documentId, dest, opts = {}) {
651
- const { cache = true, sync = true } = typeof opts === "boolean" ? { cache: false, sync: opts } : opts;
712
+ async move(documentId, dest, { cache = true, sync = true } = {}) {
652
713
  const [root, gen] = await this.getRootHash({ cache });
653
714
  const rootEntries = await this.getEntries(root);
654
715
  // check if destination is a collection
@@ -742,6 +803,20 @@ class Remarkable {
742
803
  // TODO why doesn't this work
743
804
  return await this.#uploadFile(visibleName, buffer, "application/pdf");
744
805
  }
806
+ async getCache() {
807
+ const promises = [];
808
+ for (const [hash, prom] of this.#cache) {
809
+ promises.push(prom.then((val) => [hash, val], () => [hash, null]));
810
+ }
811
+ const entries = await Promise.all(promises);
812
+ const cache = new Map();
813
+ for (const [hash, val] of entries) {
814
+ if (val) {
815
+ cache.set(hash, val);
816
+ }
817
+ }
818
+ return cache;
819
+ }
745
820
  }
746
821
  /**
747
822
  * create an instance of the api
@@ -753,7 +828,10 @@ class Remarkable {
753
828
  * registered. Create one with {@link register}.
754
829
  * @returns an api instance
755
830
  */
756
- export async function remarkable(deviceToken, { fetch = globalThis.fetch, cache, subtle = globalThis.crypto?.subtle, authHost = AUTH_HOST, syncHost = SYNC_HOST, } = {}) {
831
+ export async function remarkable(deviceToken, { fetch = globalThis.fetch, subtle = globalThis.crypto?.subtle, authHost = AUTH_HOST, syncHost = SYNC_HOST, cacheLimitBytes = 1048576, initCache = [], } = {}) {
832
+ if (!subtle) {
833
+ throw new Error("subtle was missing, try specifying it manually");
834
+ }
757
835
  const resp = await fetch(`${authHost}/token/json/2/user/new`, {
758
836
  method: "POST",
759
837
  headers: {
@@ -764,5 +842,5 @@ export async function remarkable(deviceToken, { fetch = globalThis.fetch, cache,
764
842
  throw new Error(`couldn't fetch auth token: ${resp.statusText}`);
765
843
  }
766
844
  const userToken = await resp.text();
767
- return new Remarkable(userToken, fetch, cache, subtle, syncHost);
845
+ return new Remarkable(userToken, fetch, subtle, syncHost, cacheLimitBytes, initCache);
768
846
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rmapi-js",
3
- "version": "2.3.0",
3
+ "version": "3.0.0",
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>",
@@ -21,14 +21,17 @@
21
21
  "scripts": {
22
22
  "doc": "typedoc",
23
23
  "fmt": "prettier --cache --write 'src/*.ts' '*.json' bundle.mjs",
24
- "lint": "tsc && eslint --cache 'src/*.ts' bundle.mjs && typedoc --emit none",
24
+ "lint:es": "eslint --cache 'src/*.ts'",
25
+ "lint:doc": "typedoc --emit none",
26
+ "lint": "tsc && yarn lint:es && yarn lint:doc",
25
27
  "test": "jest --coverage",
26
- "build": "tsc -p tsconfig.build.json && yarn node bundle.mjs",
28
+ "build": "tsc -p tsconfig.build.json && node bundle.mjs",
27
29
  "prepack": "yarn lint && yarn test && yarn build"
28
30
  },
29
31
  "dependencies": {
30
32
  "ajv": "^8.11.2",
31
33
  "base64-js": "^1.5.1",
34
+ "json-stable-stringify": "^1.0.2",
32
35
  "jtd": "^0.1.1",
33
36
  "uuid": "^9.0.0"
34
37
  },
@@ -38,7 +41,8 @@
38
41
  "@babel/preset-typescript": "^7.18.6",
39
42
  "@types/babel__core": "^7.1.20",
40
43
  "@types/babel__preset-env": "^7.9.2",
41
- "@types/jest": "^29.2.4",
44
+ "@types/jest": "^29.2.5",
45
+ "@types/json-stable-stringify": "^1.0.34",
42
46
  "@types/node": "^18.11.18",
43
47
  "@types/uuid": "^9.0.0",
44
48
  "@typescript-eslint/eslint-plugin": "^5.47.1",
@@ -46,10 +50,10 @@
46
50
  "@yarnpkg/esbuild-plugin-pnp": "^3.0.0-rc.15",
47
51
  "babel-jest": "^29.3.1",
48
52
  "chalk": "^5.2.0",
49
- "esbuild": "^0.16.10",
50
- "eslint": "^8.30.0",
53
+ "esbuild": "^0.16.12",
54
+ "eslint": "^8.31.0",
51
55
  "eslint-config-prettier": "^8.5.0",
52
- "eslint-plugin-jest": "^27.1.7",
56
+ "eslint-plugin-jest": "^27.2.0",
53
57
  "eslint-plugin-spellcheck": "^0.0.20",
54
58
  "eslint-plugin-tsdoc": "^0.2.17",
55
59
  "jest": "^29.3.1",
@@ -88,9 +92,15 @@
88
92
  "extends": [
89
93
  "eslint:recommended",
90
94
  "plugin:@typescript-eslint/recommended",
95
+ "plugin:@typescript-eslint/recommended-requiring-type-checking",
91
96
  "plugin:jest/recommended",
92
97
  "prettier"
93
98
  ],
99
+ "parserOptions": {
100
+ "project": [
101
+ "./tsconfig.json"
102
+ ]
103
+ },
94
104
  "env": {
95
105
  "node": true
96
106
  },